What I am proposing here, is the creation of two generic extensions that will be useful for current and future OpenGL: ARB_Async_Value and ARB_If_Command.
(I don’t like either of the names but I am going to use them in this proposal).
ARB_Async_Value
This extension is useful for values that we will need to be referenced in other extensions (for example, values that are set in one extension and used in another one), even if, when defining the extension that sets the value, we can not predict its use in other future extensions for its own purposes.
With this extension we can query for a number of values that can be accessed by different extensions that change the value of a variable (for example, Fence, Occlusion_Query, …)
The function for querying those values can be:
glGenAsyncVal(GLsizei nvalueswanted, GLvoid *pHandlearray, , GLEnum arraytype)
with arraytype=GLfloat, GLbool, … (they can be always GLfloat without loss of generality)
For example:
Glhandle handleval;
glGenAsyncVal(1, &handleval, GLbool)
And this value, can be useful for extensions like FenceARBX, so it can change the state of this value and can be used as a query from other extension (vertex_program, the proposed arb_if_command, etc). For example, using it with a Fence extension and Vertex_Program you can build and async performance bar at the end of the frame to view the amount of time the GPU is idle waiting for the CPU…
Another example,
glBeginOcclusionQueryARBX(GL_PERCENTAGE_DRAWN, handleval);
… draw commands
glEndOcclusionQueryARBX()
(Note that the FenceARBX and OcclusionQueryARBX don’t currently exist, that is why I marked them as ARBX)
This way, the OcclusionQuery extension is setting the value referenced by handleval with the result of the percentage of pixels draw/total pixels.
Also there can be the typical glGet functions to obtain the value reference by its handle but, as with all the glGet functions you will lose parallelism. (glGetAsyncValf(handleval, &floatval));
I know that this extension is very general but it allows future connectivity between extensions based on values (something that can be very useful if they are integrated with future vertex_program and fragment_program extensions. And allows extensions like Occlusion_Query, Fences and future ideas to be connected with vertex or fragment programs or other extensions that can be produced in the future)
ARB_If_Command
With this extension, OpenGL can determine if it has to execute the commands that lie inside the BeginIf, EndIf par.
The syntax can be something like:
glBeginIf(ConditionArray, nConditions)
The conditions should be two values (or handles to values) with a condition (GL_GREATER, GL_LEQUAL, …). The amount of conditions supported can be hw dependent.
Here, we can use handles to values generated with the previously proposed extension (ARB_Async_Value).
For example:
At the beginning of the program
GLint occlrefvalhandle;
glGenRefVal(&occlrefvalhandle, 1)
In the render loop:
glBeginOcclusionQuery(GL_PERCENTAGE_DRAWN, occlrefvalhandle)
…DrawBoundingVolume
glEndOcclusionQuery()
GLconditionArray cond;
cond.val0=occrefvalhandle;
cond.comp=GL_LOWER;
cond.val1=0.25f;
glBeginIf(&cond, 1);
...SetStates
...BindTextures
...SetArrays
...DrawElements…
glEndIf();
The commands inside glBeginIf and glEndIf are executed only if the conditions are passed.
It can be made complicated with things like glElseIf and others like it. But I think the idea is clear.
What do you guys think about these ideas?