Advertisement

I don't understand render queues

Started by October 07, 2021 04:41 AM
0 comments, last by orange1 3 years, 1 month ago

So render queues sort objects in a way as to minimize the amount of state changes. Say each object has a shader, texture and vbo associated with it. And say we sort the objects to draw based on these three parameters.

struct Object {
    //
    Shader* shader;
    Texture* texture;
    Vbo* vbo;
};

void SetStates(Object* object) {
    SetShader(object->shader);
    SetTexture(object->texture);
    SetVbo(object->vbo);
    Draw(object);
}

Now if we sort the objects based on shader, texture and vbo in that order. And call SetStates och each object. Won't we now have state call redundancies when two objects have the same state? If two objects objectA and objectB use the same shader and we run the below code, we have one redundant SetShader call. And in OpenGL at least redundant calls are not guaranteed to be optimized away.

SetStates(objectA);
SetStates(objectB);

Am I misunderstanding how render queues actually work?

Isn't it better to structure the rendering like below instead? That way we avoid redundant calls.

   for shader in shaders
      set shader
      for texture in textures
          set texture
          for vbo in vbos
             set vbo
             for object in objects:
                  draw object

This topic is closed to new replies.

Advertisement