Part of the Khronos Group
OpenGL.org

The Industry's Foundation for High Performance Graphics

from games to virtual reality, mobile phones to supercomputers

Results 1 to 8 of 8

Thread: How to draw a curve and points together?

  1. #1
    Intern Contributor
    Join Date
    Sep 2012
    Posts
    76

    How to draw a curve and points together?

    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

  2. #2
    Senior Member OpenGL Pro
    Join Date
    Apr 2010
    Location
    Germany
    Posts
    1,099
    glDrawArrays(GL_PATCHES, 0, 4) to glDrawArrays(GL_POINTS, 0, 4) (right?).
    Only if you're going to turn off tessellation:

    Quote Originally Posted by The GL Spec
    Tessellation is considered active if and only if there is an active tessellation control or tessellation evaluation program object.
    Quote Originally Posted by The GL Spec
    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.
    Quote Originally Posted by The GL Spec
    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.
    Last edited by thokra; 07-22-2013 at 02:49 AM.

  3. #3
    Intern Contributor
    Join Date
    Sep 2012
    Posts
    76
    Quote Originally Posted by thokra View Post
    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.

  4. #4
    Senior Member OpenGL Pro
    Join Date
    Apr 2010
    Location
    Germany
    Posts
    1,099
    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.

  5. #5
    Intern Contributor
    Join Date
    Sep 2012
    Posts
    76
    Quote Originally Posted by thokra View Post
    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.

  6. #6
    Senior Member OpenGL Pro
    Join Date
    Apr 2010
    Location
    Germany
    Posts
    1,099
    Code :
    glUseProgramStages(pipeline, GL_TESS_CONTROL_SHADER_BIT | GL_TESS_EVALUATION_SHADER_BIT, 0);

    should do.

  7. #7
    Intern Contributor
    Join Date
    Sep 2012
    Posts
    76
    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. 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.

  8. #8
    Senior Member OpenGL Pro
    Join Date
    Apr 2010
    Location
    Germany
    Posts
    1,099
    Doh! I thought we were talking separable programs all the time...

    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. I'm afraid I can't make time to look at the code.

Posting Permissions

  • You may not post new threads
  • You may not post replies
  • You may not post attachments
  • You may not edit your posts
  •