PDA

View Full Version : How to draw a curve and points together?



sam_thedancer
07-22-2013, 03:10 AM
Greetings:
I have a GL 4.3 tessellation shader program which draws a Bezier curve just fine. Now, I want to draw the control points as well. Obviously, I have to turn off the TCS and TES and switch from glDrawArrays(GL_PATCHES, 0, 4) to glDrawArrays(GL_POINTS, 0, 4) (right?). So, how to do this in one program?

I have tried glGenProgramPipelines(); glBindProgramPipeline(), etc. to bind two separate pipelines, one to draw the curve the other the points, but for the life of me couldn't get the VS-TCS-TES-FS pipeline working to draw the curve.

Is there some other way to do this in GL 4.3 core?
Thanks,
Sam

thokra
07-22-2013, 03:42 AM
glDrawArrays(GL_PATCHES, 0, 4) to glDrawArrays(GL_POINTS, 0, 4) (right?).

Only if you're going to turn off tessellation:


Tessellation is considered active if and only if there is an active tessellation control or tessellation evaluation program object.

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.

An INVALID_OPERATION error is generated by any command that transfers vertices to the GL if the primitive mode is PATCHES and there is no active tessellation evaluation program.

So the spec basically states, a little verbosely IMHO, that if tessellation is active, you need GL_PATCHES. If tessellation isn't active, you cannot use GL_PATCHES. In essence, you can, of course, use a program pipeline to draw you control points or control polygon. You have to throw out the TCS and TES, however, because existence of any of those shaders implies tessellation is active.

EDIT: On second thought, one might add to the spec that it is an error to say that there exists a TCS without a TES because it will lead to an invalid operation no matter how you proceed.

sam_thedancer
07-23-2013, 03:04 AM
Only if you're going to turn off tessellation:

Okay, so how do I turn off tessellation and just let the points go through VS-FS? Precisely, I want tessellation on for the curve then turn it off for the points.

thokra
07-23-2013, 03:14 AM
how do I turn off tessellation

I already said: throw the TCS and TES out of your program pipeline. It's as simple as drawing n points. Of course, if your vertex and fragment shader doesn't work for rendering the points, you'll have to use different programs. However, for the purpose of simply drawing a curve and some control points and/or a control polygon, I don't see why they couldn't work.

sam_thedancer
07-23-2013, 07:23 AM
I already said: throw the TCS and TES out of your program pipeline. It's as simple as drawing n points. ...

Obviously, I am missing something here. I want the same program to draw the curve and control points. So I have to throw the TCS and TES out in its drawing routine (after the curve is drawn). How does one do that is my question.

I couldn't get glDetachShader() to work in the drawing routine. If that's the way I would appreciate a snippet of code. Or please explain how else to turn off the TCS and TES after they have been used to draw the curve.
Thanks.

thokra
07-23-2013, 07:36 AM
glUseProgramStages(pipeline, GL_TESS_CONTROL_SHADER_BIT | GL_TESS_EVALUATION_SHADER_BIT, 0);

should do.

sam_thedancer
07-23-2013, 08:55 AM
Thanks. Your suggestion obviously requires the shaders to be bound to a pipeline created with glGenProgramPipelines(1, &pipeline), etc. Unfortunately, I have simply been unable to do this. The program works fine with the shaders attached with glCreateProgram(), glAttachShader(), etc. (no pipeline). But if I try to bind separate shader objects to a pipeline, no dice.

If you would be so kind as to look I have got the program boiled down to the basics here (http://www.opengl.org/discussion_boards/attachment.php?attachmentid=1078&d=1374159517). It's pretty short and, hopefully, won't take you more than a few mins. to understand. The main program has two blocks of statements, one without pipeline and one with. The one without works fine.

If you could tell me how to get the pipeline working then I am sure the glUseProgramStages() command you suggest will work. But, first, I need the pipeline going!! Thanks again.

thokra
07-23-2013, 09:27 AM
Doh! I thought we were talking separable programs all the time... :doh:


I couldn't get glDetachShader() to work in the drawing routine.

This alone will do nothing to the executable. If you want a different program, you'd have to relink the program. So, detach -> link. However, this is simply nonsense performance-wise. Either create two programs, one for curve tessellation, one for control points. The latter will not attach a TCS/TES in the first place. If you want to mix-and-match existing programs, you'll need to go separable. Please read the wiki (http://www.opengl.org/wiki/Shader_Compilation). I'm afraid I can't make time to look at the code.