PDA

View Full Version : About tessellation shaders



Benjamin3D
10-16-2012, 06:55 AM
Hi everybody,

I'm trying to use tessellation shaders and i'm wondering if we can only use them with GL_PATCHES.

I have a simple code using vertex and fragment shaders with GL_TRIANGLE and I wanted to add tessellation shader but it's not woking when I call
glDrawArrays ( GL_TRIANGLES, offset, numTris );

Thanks

Aleksandar
10-16-2012, 07:40 AM
Of course, that's the point. Tessellation can work only on GL_PATCHES.

Benjamin3D
10-16-2012, 08:05 AM
Thank you so much,
So if I use a geometry shader beginning like this:

layout(triangles) in;
layout(triangle_strip, max_vertices = 3) out;

After fragment shader I have only one choice to draw the final result: glDrawElements or glDrawArray with GL_PATCHES? A glDrawArrays with a GL_TRIANGLES doesn't work event if last shader works on triangle?

Thanks

ps: I'm a beginner in shaders :)

thokra
10-16-2012, 08:53 AM
After fragment shader I have only one choice to draw the final result: glDrawElements or glDrawArray with GL_PATCHES? A glDrawArrays with a GL_TRIANGLES doesn't work event if last shader works on triangle?

Slow down. The primitive type on the application level has to match the shaders that are active in the current program or pipeline. If tessellation is active, you have to use GL_PATCHES with any draw command, otherwise you don't:


An INVALID_OPERATION error is generated by any command that transfers vertices to the GL if tessellation is active and the primitive mode is not PATCHES. Patch primitives are not supported by pipeline stages below the tessellation evaluation shader.

Furthermore the spec states


If a tessellation evaluation shader is active, the tessellation primitive generator subdivides a triangle or quad primitive into a collection of points, lines, or triangles according to the tessellation levels of the patch and the set of layout declarations specified in the tessellation evaluation shader text.

So, what you get after tessellation is a set of points, lines or triangles. The geometry shader input layout has to match the tess eval shader outputs. For points it's simple: you only get points out of a tess eval shader if you specify point_mode layout and the geometry shader input type should be points. If the input to you tess eval shader is isolines it should be clear as well: The geometry shader input would be lines. For tess eval inputs triangles and quads the input would be triangles.

The geometry shader can then do whatever it wants just as if there wasn't any tessellation going on and the fragment shader will also do whatever it wants as if you just rendered single points, triangles or lines. Output variables can be passed through the tessellation stages as with any other pipeline stage, the only thing to remember is that control shaders usually take arrays of input and write arrays of outputs and the evaluation stage always processes exactly one vertex that has been generated by the primitive generator.

Benjamin3D
10-17-2012, 12:01 AM
"An INVALID_OPERATION error is generated" that is actually what I have with my draw call with GL_TRIANGLES while I use tess shaders.
Thank you, it's more clear.