Page 1 of 2 12 LastLast
Results 1 to 10 of 13

Thread: Is there a good way to redraw only when changed?

  1. #1
    Junior Member Newbie
    Join Date
    Jan 2011
    Location
    Houston
    Posts
    9

    Is there a good way to redraw only when changed?

    I'm developing an intensive care monitor using OpenGL ES (WinCE / PowerVR SGX) for the user interface. Mainly I just wanted OpenGL for the waveforms so we could do cool fades and whatnot on them. The rest of the interface I was just going to use Windows GDI. But our lead developer insisted that using OpenGL for everything would speed up performance because it uses the graphics accelerator.

    So that's what I've done, but the text rendering is pretty slow. Which makes sense since OpenGL has to redraw it every frame, while GDI (as far as I know) doesn't use any processor cycles unless the text changes, which is relatively infrequent. But it's annoying that redrawing all this mostly static text is causing the waveforms to render at lower fps. Is there any way to cajole OpenGL to only redraw the text when it changes?

    I've tried using FBOs and rendering each text field to texture on changed frames, then rendering from that texture on unchanged frames, but that's still a lot slower than GDI. I also tried just not doing a glClear between each frame and only rendering changed items, but that just gave weird unpredictable results.

    It seems like there should be a way to just say "hey OpenGL don't change any of this stuff on this part of the screen" and have that cost nothing, but I can't find the way to do it. Or was my old manager (he's since left the company) just wrong when he said that you can always use OpenGL to do the same thing faster than the native graphics API?

  2. #2
    Senior Member Regular Contributor
    Join Date
    Dec 2007
    Posts
    258

    Re: Is there a good way to redraw only when changed?

    How are you rendering text?

  3. #3
    Junior Member Newbie
    Join Date
    Jan 2011
    Location
    Houston
    Posts
    9

    Re: Is there a good way to redraw only when changed?

    Fairly straightforward, just bind to the texture and set the color, vertex, letter coordinate, and element data, and draw:

    glBindTexture(GL_TEXTURE_2D, _font.TextureId);
    glColorPointer(4, 0, _colors);
    glVertexPointer(3, 0, _screenPositions);
    glTexCoordPointer(2, 0, _letterTexCoords);
    glBindBuffer(GL_ELEMENT_ARRAY_BUFFER, GlyphStripElementIndexHandle);
    glDrawElements(GL_TRIANGLES, _length * 6, GL_UNSIGNED_SHORT, 0);

    Is there a more efficient way of doing this? I've tried putting the arrays in VBOs but that doesn't seem to make any difference. I haven't tried interleaving everything into a single array, but wouldn't think that would make much difference either. But it also seems to sidestep the question of, do I really need to re-render all this stuff for each frame in the first place. (Though if there was a much more efficient way of rendering it, then I guess I wouldn't mind rendering every frame).

  4. #4
    Senior Member Regular Contributor
    Join Date
    Aug 2007
    Location
    Adelaide, South Australia
    Posts
    208

    Re: Is there a good way to redraw only when changed?

    Setup a scissor box around the part of the screen that contains the waveform that you want to update every frame with:
    void glScissor( int left, int bottom, sizei width, sizei height );

    When you have drawn the GUI the first time and now only want to update the wave form, do:
    glEnable( GL_SCISSOR_TEST );

    When you need to change the GUI do:
    glDisable( GL_SCISSOR_TEST );
    glCear( GL_COLOR_BUFFER_BIT );
    glDrawElements(GL_TRIANGLES, _length * 6, GL_UNSIGNED_SHORT, 0); //Draw GUI
    glEnable( GL_SCISSOR_TEST );
    Then go back to only drawing the changing waveform until the next change to the GUI.

    P.S. If you are double-buffered and using SwapBuffers in 'swap' mode then you need to draw the GUI, SwapBuffers, then draw it again before you enable the scissor test.

  5. #5
    Senior Member OpenGL Pro Ilian Dinev's Avatar
    Join Date
    Jan 2008
    Location
    Watford, UK
    Posts
    1,294

    Re: Is there a good way to redraw only when changed?

    Try: draw the text with GDI into a window-sized DIB. Upload with glTexSubImage2D. Draw that texture with a fullscreen quad/tri. Experiment with different RGB bit-depths (888,565,888 of the DIB.

    How often does the text change? I.e every 5 frames roughly, or 500+ frames?

  6. #6
    Junior Member Newbie
    Join Date
    Jan 2011
    Location
    Houston
    Posts
    9

    Re: Is there a good way to redraw only when changed?

    @Simon Hmm, that makes sense that it should work, but it isn't working. It just makes everything transparent (i.e. I can see the desktop background) outside the scissor box. It seems like the OpenGL ES implementation must be doing an implicit glClear after each call to eglSwapBuffers. Maybe it's worth trying it out in OpenVG. That would have probably made the most sense for this app in the first place, but I was just new to graphics at the time and OpenGL seemed to have far more reference material.

  7. #7
    Senior Member Regular Contributor
    Join Date
    Aug 2007
    Location
    Adelaide, South Australia
    Posts
    208

    Re: Is there a good way to redraw only when changed?

    Did you write the GDI parts twice like i said in the P.S.?
    If by 'transparent' you mean you can see through the GUI objects then its likely that eglSwapBuffers is switching rapidly between a framebuffer with the GUI drawn and one where it isnt.
    You should have something like this:
    Code :
    if NeedToUpdateGUI
      {
      NeedToUpdateGUI = False; 
      glDisable( GL_SCISSOR_TEST );
      glClear( GL_COLOR_BUFFER_BIT );
      DrawGUI;
      eglSwapBuffers;
      glClear( GL_COLOR_BUFFER_BIT );
      DrawGUI;
      glEnable( GL_SCISSOR_TEST );
      }
    glClear( GL_COLOR_BUFFER_BIT );
    DrawWaveform;
    eglSwapBuffers;

  8. #8
    Junior Member Newbie
    Join Date
    Jan 2011
    Location
    Houston
    Posts
    9

    Re: Is there a good way to redraw only when changed?

    Yeah, that's what I'm doing. No, by transparent, I mean totally not there I have a box of waves in the middle of the screen and outside of that is just the WinCE background. However the text fields are all showing up in the first two frames of the app, so it's obviously getting written to the framebuffer at that initialization. Just seems to get cleared whenever I do a buffer swap. If I just eliminate glClear from the app entirely and only draw the text fields on the first two frames, I get the same behavior. I don't think GL ES supports single buffering.

  9. #9
    Super Moderator OpenGL Lord
    Join Date
    Dec 2003
    Location
    Grenoble - France
    Posts
    5,574

    Re: Is there a good way to redraw only when changed?

    Simon : swapbuffers can be implemented as anything, it could be a copy from a single internal buffer to front buffer, or new uninitialized memory each time. This is not robust.

    Ilian advice sound good, did you try ?

  10. #10
    Junior Member Newbie
    Join Date
    Jan 2011
    Location
    Houston
    Posts
    9

    Re: Is there a good way to redraw only when changed?

    @Ilian That should give me about the same performance as rendering to an FBO and using that texture, right? Especially for the non-changing frames it should be identical because it's just rendering from a texture in either case, right?

    Right now I'm using a different FBO for every "region" on the screen (i.e., one for ECG stuff, one for ventilator settings, etc 14 in total). Using a single fullscreen FBO was something I was considering might help, but I haven't tried it yet. I'll try messing around with RGB depths too; that's something I hadn't considered yet.

    Text will change maybe once per second overall, but some regions more frequently than others. i.e. Heart rate may change fairly often, but patient info field will stay constant through the entire treatment. Currently the framerate is about 15 on the SGX, but with text rendering removed I get 30.

Page 1 of 2 12 LastLast

Similar Threads

  1. changed colors
    By saatric in forum OpenGL: Basic Coding
    Replies: 2
    Last Post: 04-13-2005, 02:14 AM
  2. url is changed
    By cwc36 in forum OpenGL: Basic Coding
    Replies: 0
    Last Post: 02-24-2004, 10:24 PM
  3. How to redraw some objects while not redraw others?
    By ding in forum OpenGL: Advanced Coding
    Replies: 2
    Last Post: 09-28-2002, 09:25 AM
  4. How to know if projection and modelview are changed?
    By jyoung77 in forum OpenGL: Advanced Coding
    Replies: 3
    Last Post: 02-22-2002, 07:25 PM
  5. MilkShape format changed? or my bad?
    By Chiron in forum OpenGL: Basic Coding
    Replies: 2
    Last Post: 10-16-2001, 11:22 AM

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