views:

1834

answers:

3

I am trying to use glScissor to isolate only the parts of the screen that need updating. I have a game area where I need to update every frame, but the UI area needs to be updated much less frequently. The game area is fine but the UI area is constantly flickering with what seems like old buffer data.

What am I missing?

Here is my rendering code:

 [EAGLContext setCurrentContext:context];

glBindFramebufferOES(GL_FRAMEBUFFER_OES, viewFramebuffer);

if (needsUIUpdate) {

// clear entire screen glScissor(0, 0, 320, 480);

glClear(GL_COLOR_BUFFER_BIT);

needsUIUpdate = NO; [self updateUI]; } else { glScissor(0, 80, 320, 400); glClear(GL_COLOR_BUFFER_BIT); }

for (Cell* c in allCells) [c animate];

glBindRenderbufferOES(GL_RENDERBUFFER_OES, viewRenderbuffer); [context presentRenderbuffer:GL_RENDERBUFFER_OES];

+1  A: 

You are absolutely missing:

glEnable(GL_SCISSOR_TEST);

Although I'm not sure if that is enough to explain the artifacts you're seeing, just wanted to point it out. According to the documentation the scissor test is not enabled by default.

unwind
The scissor test is enabled in my setup code, so I didn't post it. I will be more clear next time.
hyn
+3  A: 

Are you using kEAGLDrawablePropertyRetainedBacking in your CAEAGLLayer? If you don't set this to YES, then the contents of your buffer aren't guaranteed to be preserved after you render it. In other words, they're doing double-buffered rendering: there are 2 separate buffers. One is being displayed, one is being rendered to. When you render one frame and display it, the next frame is rendered to the other buffer, so the contents aren't preserved. (Which explains why you see garbage if you don't clear that chunk of the screen.) If you use this flag, the graphics system is probably copying the data over during the flip so the contents are preserved.

Using this flag will make your app take more memory and more time to render, so it might not be worth it for the optimization you have above. You'll have to profile it and see. (See the Apple docs for more about that.)

You might also take a look at the GLPaint demo - it uses this property to avoid redrawing the screen every time.

Jesse Rusak
Thank you! My kEAGLDrawablePropertyRetainedBacking was set to NO, and changing this to YES solved the problem. I suspect that the GPU is not the bottleneck in my app, and I wanted to avoid the floating point calculations involved in displaying the UI assets. Rendering is still as fast as before.
hyn
Thanks - this solved my problem as well.
Ben Gotow
A: 

Aslam o alkum,

Can you tell me that What is Scissor test do in openg es.. b/c I am new in using oepngl es.. and I am facing many problems.. If any buddy know about these things then tell it to my mail id..

[email protected]

JazakAllah

thnx