user1075940
user1075940

Reputation: 1125

Front to back rendering vs shaders swapping

Lets consider such situation. The scene contains given objects: ABCDE

Where order from camera (from nearest to farthest) AEBDC

And objects AC use shader1,ED shader 2,B shader3

Objects AC use shame shader but different texture.

Now what to deal with such situation?

Does instructions like glUniform,glBindTexture etc. to change value in already in use program cause overhead?

Upvotes: 2

Views: 668

Answers (2)

fen
fen

Reputation: 10105

Profile, profile and even more profile :)

I would like to add one thing though:

In your situation you can use idea of a rendering queue. It is some sort of manager for drawing objects. Instead of drawing an object you call renderQueue.add(myObject). Then, when you add() all the needed objects you can call renderQueue.renderAll(). This method can handle all the sorting (by the distance, by the shader, by material, etc) and that way it can be more useful when profiling (and then changing the way you render).

Of course this is only a rough idea.

Upvotes: 1

Nicol Bolas
Nicol Bolas

Reputation: 473272

There is no one answer to this question. Does changing OpenGL state "cause overhead"? Of course they do; nothing is free. The question is whether the overhead caused by state change will be worse than the less effective depth test support.

That cannot be answered, because the answer depends on how much overdraw there is, how costly your fragment shaders are, how many state changes a particular sequence of draw calls will require, and numerous other intangibles that cannot be known beforehand.

That's why profiling before optimization is important.

Upvotes: 4

Related Questions