Take the 2-minute tour ×
Game Development Stack Exchange is a question and answer site for professional and independent game developers. It's 100% free, no registration required.

I'm wondering if opengl can automatically manage offscreen rendering. I mean if it can detect and ignore sprites and textures if they are rendered out of screen.

if it makes any difference i'm targeting opengl-es 2.

share|improve this question

3 Answers 3

up vote 2 down vote accepted

To bind a texture in OpenGL-ES 2.0, the texture must be in memory. Whether or not the texture gets used depends on whether an object remaining in the viewable scene uses that texture. So, yes, it can ignore the texture for rasterization, however, to your point of a 2048x2048 texture on a 480x320 screen, as the Apple "OpenGL ES Programming Guide for iOS" states on page 71:

Reduce Texture Memory Usage

Reducing the amount of memory your iOS application uses is always an important part of tuning your application. However, an OpenGL ES application is also constrained in the total amount of memory it can use to load textures.

And on page 72:

Use Properly Sized Textures

The images that an iOS-based device displays are very small. Your application does not need to provide large textures to present acceptable images to the screen. Halving both dimensions of a texture reduces the amount of memory needed for that texture to one-quarter that of the original texture.

Before shrinking your textures, attempt to compress the texture or use a lower-precision color format first. A texture compressed with the PVRTC format usually provides higher image quality than shrinking the texture—and it uses less memory too!

You can apply the same logic to most OpenGL-ES 2.0 devices, since they each have limited memory.

share|improve this answer

If an object, when translated to the 2D display, is not within the buffer's dimensions then OpnGL will do nothing with the data.. However it still has to do a bit of processing to get to that point so it is still considered better practice to only send things to OpenGL that actually have a chance of being seen on the screen in one manner or another.

Scene Graphs are the constructs that are commonly used to determine which objects to send down the graphics pipeline for processing or not.

Hope this helps.

share|improve this answer
    
I'm wondering what would happen if I've got an object let's say 2048x2048 pixels, while my render output is a 480x320 display. should I clip texture or can I rely on opengl to skip rendering in offscreen spaces? –  Ali.S Sep 14 '11 at 18:07
    
Any manual culling you attempt to do would only be to try and avoid the overhead of state changes, draw calls, and other application-side processing. Otherwise, the graphics hardware is probably going to be much better at clipping triangles than anything you can do at the app level. –  Neverender Sep 14 '11 at 18:30
    
Ah, when its an object as large as that, and you know 480x320 of it will be rendered then yes, it will only spend the time 'copying' the part that is seen and ignore the rest, once its determined what that is. I would suggest however breaking the large ?texture? up into 256x256 blocks and then send whatever combination of 4 of them would actually be needed. –  James Sep 14 '11 at 18:34
1  
@James: I disagree with James's suggestion of breaking the texture into 256x256 blocks. Unless you are targeting ancient hardware, there's no need to. It would increase the complexity of your rendering logic for no measurable gain. –  Nicol Bolas Sep 14 '11 at 18:55
    
@Nicol Bolas The target is a portable device of some kind (OpenGL ES2). Now I think its pretty spiffy how powerful and capable they are, but they are not known for high speed bandwidth buses for data transfer. sending 327680 instead of 4194304 bytes to render 153600 of them is going to be faster no matter which way you look at it. –  James Sep 14 '11 at 19:01

I mean if it can detect and ignore sprites and textures if they are rendered out of screen.

In general, if you're thinking solely in terms of 2D graphics, "sprites and textures", rendering performance is not going to be a concern. Not on any hardware you can actually have bought in the last 8 years.

You might be drawing, what, a few hundred quads every frame? Maybe a thousand, tops? You could do that on a Voodoo 1 at 60fps no problem, and that was with software T&L.

You don't need to concern yourself too much with parts of quads that happen to be off-screen. GPUs aren't stupid; they will not do work that will not have a visible effect. Remember: hardware makers make money based on how fast their cards go. And spending time on the part of a triangle that's off-screen is time that could have gone to stuff that's on-screen.

Now, that being said, it's not a bad idea to do some simple visibility checks to see if a quad is actually on screen or not. But the key word is "simple". At no time should you modify a quad so that you're only rendering the visible portion; just let the GPU do its job.

share|improve this answer

Your Answer

 
discard

By posting your answer, you agree to the privacy policy and terms of service.

Not the answer you're looking for? Browse other questions tagged or ask your own question.