Rendering order for my objects
Hi.
At this moment the object rendering part of my GLscene::Render() function looks like this:
for(c=0;c<nr_objects;c++)
{
....
select material(with texture) for this model;
draw the vertexarray;
...
}
Would it save me a lot if I sort out the objectnumbers with the same material/texture, so I only need to select al materials/textures one time?
[Edited by - cozzie on October 14, 2004 7:39:59 AM]
yes, texture state changes are expensive, you want to minimise the changes during any perticular scene as much as you can
Related question: What's the most expensive, texture change or loading a new model view matrix?
Quote:Original post by _the_phantom_
yes, texture state changes are expensive, you want to minimise the changes during any perticular scene as much as you can
phantom .. does this include glEnable(GL_TEXTURE_2D) and glDisable? I can see how changing textures is expensive but I've heard that just doing these state changes has its own penality.
Sort by pixel shader, then by texture.
If you are fillrate limited, you might also want to consider rendering from front to back, or laying down a quick ambient pass first if you're using some expensive shaders. Modern cards do an extra early z-test near the beginning of the pipeline that can help eliminate hidden pixels.
If you are fillrate limited, you might also want to consider rendering from front to back, or laying down a quick ambient pass first if you're using some expensive shaders. Modern cards do an extra early z-test near the beginning of the pipeline that can help eliminate hidden pixels.
I don't think I have to choose if I want to alter the model or projection matrix OR select the correct texture more times.
The only thing I will do is change the object rendering loop in my GLscene::Render() function.
Now it's:
for(c=0;c<nr_objects;c++)
{
...
select material that belongs to objects[c];
draw objects[c];
...
}
And this is something like what it will be:
for(c=0;c<nr_materials;c++)
{
select materials[c];
for(c2=0;c2<nr_objects;c2++)
{
if(objects[c2].material) == c)
{
...
draw object
...
}
}
}
I wonder if this will save me a lot, because I have to go through all objects to check what the material is, and that for every material in the scene..
I wonder if there's a quicker way
The only thing I will do is change the object rendering loop in my GLscene::Render() function.
Now it's:
for(c=0;c<nr_objects;c++)
{
...
select material that belongs to objects[c];
draw objects[c];
...
}
And this is something like what it will be:
for(c=0;c<nr_materials;c++)
{
select materials[c];
for(c2=0;c2<nr_objects;c2++)
{
if(objects[c2].material) == c)
{
...
draw object
...
}
}
}
I wonder if this will save me a lot, because I have to go through all objects to check what the material is, and that for every material in the scene..
I wonder if there's a quicker way
Make something called a material group. When you render your objects, you basically just add them to the relevant material group. Then you render your material group.
eg.
The idea is that your material group keeps track of a list of pointers to objects. This list is cleared at the beginning of every frame. Then when 'rendering' your object, you're actually just adding it to the correct material group.
Then to render batched by material, you simply render the material group.
eg.
for(c=0;c<nr_objects;c++){ AddToMaterialGroup(object, object.materialID)}for (c=0;c< nr_materialgrps;c++{ if (materialgroup[c].numobjects > 0) { SetupMaterialGroup(); for (j = 0; j < materialgroup[c].numobjects; j++) { // draw object } }}
The idea is that your material group keeps track of a list of pointers to objects. This list is cleared at the beginning of every frame. Then when 'rendering' your object, you're actually just adding it to the correct material group.
Then to render batched by material, you simply render the material group.
This topic is closed to new replies.
Advertisement
Popular Topics
Advertisement