Engine Rendering pipeline : Making shaders generic

后端 未结 4 1968
广开言路
广开言路 2021-01-23 19:57

I am trying to make a 2D game engine using OpenGL ES 2.0 (iOS for now). I\'ve written Application layer in Objective C and a separate self contained RendererGLES20 in C++. No GL

4条回答
  •  孤街浪徒
    2021-01-23 20:23

    I'm not claiming to be an expert (I'm in the exact same stage of learning to use OpenGL as you) but here is what I would try:

    Maybe you can make an abstract RenderEffect class and pass a (list of) of these to RendererGLES20::render(). From it you would derive classes such as RippleEffect and BloomEffect. A RenderEffect object would contain all the information your renderer needs to make the necessary ogl state adjustments specific to your shader. It would essentially be a container class of:

    • A list of 'UniformInfo' objects containing uniform name/id, transpose bool and (a pointer to) the value. Type and component count can be queried so no need to store it here.
    • A list of 'VertexAttribInfo' objects containing all necessary info for glVertexAttribPointer*() just like UniformInfo. Again, some things like component count can be queried.

    Derived classes can declare a constructor with arguments that match the info needed for that specific effect and would store it in the lists defined by their parent class. So the constructor of RippleEffect might have parameters for delta t and diameter and when it is called it creates and stores a UniformInfo object for each.

    Finally, you can make all of this data-driven and specify all of the info in a text file. That would be just one step short of creating a scripting-system like thecoshman proposed.

    PS: UniformInfo objects and VertexAttribInfo objects would store or reference values of different types. To deal with this you could make different classes for each type but I recommend storing just a void* or the likes. Another option is using templates but I don't know anything about objective-c so I don't know if that is possible.

提交回复
热议问题