Porting rendering logic of GUI-toolkit to OpenGL

Started by Cornix, February 18, 2016, 23:04:48

Previous topic - Next topic

Cornix

Hi everyone.

Introduction:
I am currently trying to port the renderer of a GUI-toolkit to OpenGL. It was originally implemented with AWT (abstract windowing toolkit). A naive implementation would be rather simple. I am quite certain however that the naive implementation would have horrible performance. This is why I ask here for some advice.

Problem:

  • A GUI consists of several Components. Rendering a Component means drawing a combination of potentially several colored shapes (triangles, circles, quads, lines) and pictures.
  • When rendering a Component the Components axis alinged bounding box must be taken into account. A Component is not allowed to render outside of its bounding box.
  • At any point in time the rendering logic for individual Components may change (for example when a button is pressed down).
Approach:

       
  • Circles, quads and lines can be represented as triangles. => all shapes are represented as triangles.
       
  • For text rendering I will use STB.
       
  • For the Bounding Boxes I will use glScissorTest
Naive Implementation:

       
  • For each Component (we assume they are already in correct order)
       

            
    • Do glScissor to set the scissor area (Bounding Box).
            
    • Upload as many untextured triangles as possible to a buffer and then draw it.
            
    • Upload as many textured triangles (pictures) as possible to a buffer and then draw it.
            
    • Continue with uploading textured and untextured triangle batches until everything was drawn. (We can not know in advance how many these will be!)
         
  • Alternative:
       

            
    • When a component needs to be redrawn render the entire GUI to a texture.
            
    • While nothing has changed render the texture to screen.
         
Possible Problems:

  • Several draw calls per component could be quite costly!
  • Batching must be done as an online-algorithm since we can not know how many shapes need to be drawn for the component.
  • The glScissor calls make batching multiple components together impossible.
  • An application that uses the GUI-toolkit will need to reset its own OpenGL state after each render pass.
I appreciate all advice on this. If there are any questions left unanswered please ask.
Thanks in advance.

This topic is cross-posted at: https://www.opengl.org/discussion_boards/showthread.php/198215-Porting-rendering-logic-of-GUI-toolkit-to-OpenGL?p=1281560#post1281560

abcdef

Looks like the user is a bot of some sorts that responds to links in posts.

** I think some posts have been cleaned up, if a mod reads this then you can delete this too as it doesn't make sense anymore**




abcdef

@cornix some questions

With your bounding check, do you wish to not draw the whole shape or do you wish to no draw part of a shape outside the boundary box?
Is there a maximum number of components to be drawn?

An alternative is have a VBO per shape, so only upload the data once. And then to use a model matrix to reshape, move the data to the desired spot each time. I am not a performance expert but I don't think having multiple draw calls should be an issue.(obviously depends on the number and if the CPU is going to bottleneck because of this).