Results 1 to 4 of 4

Thread: recreate shader or reuse shader

  1. #1
    Member Contributor
    Join Date
    Jun 2015
    Posts
    60

    recreate shader or reuse shader

    I am having trouble deciding if the normal mechanism is the required mechanism.

    I am looking at the freetype example on their site. In the example, they only render to the screen once so they create and destroy the shader after the context has been made current. I have the example working, but my question is this.

    What parts of the shader creation/destruction process need to be executed every loop execution and what portion can be kept around across multiple render cycles?

    The sample program is helpful to show how to generate text in a glx context, but it seems wasteful to recompile and link the shader every time through the loop.

    Also, the example loads one character/glyph in a loop and uploads the texture for each character one at a time. Could I upload the entire alphabet once and just reference the correct char/glyph?

    I will be generating overlays on one of the output screens every cycle and do not want to waste any time.

    I am just ignorant about the scope of the functions being executed. I will include the source for the program so it can be discussed.
    Attached Files Attached Files

  2. #2
    Senior Member OpenGL Guru
    Join Date
    Jun 2013
    Posts
    3,103
    Quote Originally Posted by advorak View Post
    What parts of the shader creation/destruction process need to be executed every loop execution and what portion can be kept around across multiple render cycles?
    Once created, the compiled shader can be retained for the lifetime of the program.

    Quote Originally Posted by advorak View Post
    Also, the example loads one character/glyph in a loop and uploads the texture for each character one at a time. Could I upload the entire alphabet once and just reference the correct char/glyph?
    Yes.

  3. #3
    Senior Member OpenGL Lord
    Join Date
    Mar 2015
    Posts
    6,673
    OK, before I answer your specific questions, let me say this.

    That example code you found? Never do anything it does. Wipe the entire thing from your mind. If you're interested in doing text rendering with FreeType and OpenGL, look elsewhere.

    In fact, as a general rule, if the code you're looking at does a glTexImage call that is immediately followed by some form of rendering command (like glDrawArrays), abandon that tutorial and go elsewhere. There is nothing that you could learn there which you couldn't learn somewhere else.

    Yes, the tutorial immediately after the one you found (assuming that was what you were talking about) tells you the right way to handle it, but it's generally not a good idea to introduce the wrong way first.

    Quote Originally Posted by advorak View Post
    What parts of the shader creation/destruction process need to be executed every loop execution
    If you're talking about what is done in "init_resources", none of that should be done per-frame.

    Quote Originally Posted by advorak View Post
    Also, the example loads one character/glyph in a loop and uploads the texture for each character one at a time. Could I upload the entire alphabet once and just reference the correct char/glyph?
    Not only could you do what you suggest, it is the proper way to handle it. The example code is doing things in pretty much the worst possible way, which again is why you should look elsewhere. You are smarter than the tutorial you read, which says nothing good about the quality of the tutorial you're using, since you're still a beginner.

    On the plus side, it proves you have good instincts

  4. #4
    Member Contributor
    Join Date
    Jun 2015
    Posts
    60
    Thank guys. I appreciate the quick responses. I will go and read the second tutorial and use it.

Similar Threads

  1. Replies: 4
    Last Post: 08-03-2017, 01:01 PM
  2. Replies: 3
    Last Post: 05-03-2017, 08:37 AM
  3. Replies: 5
    Last Post: 06-23-2013, 01:13 AM
  4. Replies: 4
    Last Post: 12-30-2003, 10:49 AM
  5. GLslang: no reuse of shader objects in other program objects?
    By Ostsol in forum OpenGL: Advanced Coding
    Replies: 1
    Last Post: 12-29-2003, 11:22 PM

Posting Permissions

  • You may not post new threads
  • You may not post replies
  • You may not post attachments
  • You may not edit your posts
  •  
Proudly hosted by Digital Ocean