PDA

View Full Version : Best Substitute for glDrawPixels Under OpenGL ES



asymmetric
08-16-2009, 02:49 PM
Hello,

Sorry if this is not the correct forum for this question. There doesn't seem to be an OGLES-specific forum.

I'm developing an OGLES application for iPhone for which dynamic textures are crucial. I am trying to implement these using a framebuffer bound to a texture, since according to the Gold Book, this should provide better performance than editing the texture using glCopyTexSubImage2D (which works, but seems to run very slowly on iPhone hardware).

Unlike render-to-texture or similar effects, I need to be able to rewrite specific arbitrary texels in the buffer. This is where I am running into problems. According to the OGL FAQ, there isn't any generic means of obtaining the address of a framebuffer in memory:-

http://www.opengl.org/resources/faq/technical/rasterization.htm

14.010 How do I obtain the address of the OpenGL framebuffer, so I can write directly to it?

OpenGL doesn't provide a standard mechanism to let an application obtain the address of the framebuffer. If an implementation allows this, it's through an extension.

Typically, programmers who write graphics programs for a single standard graphics hardware format, such as the VGA standard under Microsoft Windows, will want the framebuffer's address. The programmers need to understand that OpenGL is designed to run on a wide variety of graphics hardware, many of which don't run on Microsoft Windows and therefore, don't support any kind of standard framebuffer format. Because a programmer will likely be unfamiliar with this proprietary framebuffer layout, writing directly to it would produce unpredictable results. Furthermore, some OpenGL devices might not have a framebuffer that the CPU can address.

You can read the contents of the color, depth, and stencil buffers with the glReadPixels() command. Likewise, glDrawPixels() and glCopyPixels() are available for sending images to and BLTing images around in the OpenGL buffers.[/B]

This rationale makes sense for standard OGL, but ES doesn't implement glDrawPixels() or glCopyPixels()!

So what I'm asking is, is there are any kind of replacement for this functionality in ES? Or does anybody know of an extension for iPhone which does allow direct framebuffer access?

Thanks in advance.

martinsm
08-16-2009, 03:11 PM
Well you could use glTexSubImage2D to update some of pixels of texture, and then render texture to framebuffer.

Simon Arbon
08-16-2009, 06:18 PM
The OGLES forums are here:
http://www.khronos.org/message_boards/

and its specs/info is here:
http://www.khronos.org/opengles/

scratt
08-16-2009, 08:57 PM
What the Gold Book is telling you is correct. The fastest way to upload textures is to write to a texture bound to an FBO. But what you need to do is generate your pixels as geometry (optimised as much as possible) and then draw them to the FBO using an Orth matrix, GL_POINTS and glDrawArrays.

For plain old glTexSubImage2D consider different texture formats.. You'll get a speed increase if you go for one of the compressed formats like the 565 one. The iPhone has an extension for GL_BGRA which will avoid "swizzling" if you use glTexSubImage2D, and give you a small performance increase over GL_RGBA texture upload.

On the 2G iPhone you'll find texture upload still very limited even with all those tricks. It's my understanding that writing to any texture with glTexSubImage2D actually involves a lot of background operations, including copying the entire texture... which the method I describe in the first paragraph bypasses. It's also solves any "swizzling" problems on the GPU-end. Going back to glTexSubImage2D I have also been told that it's better to have several small textures, rather than one large atlas *if* you are going to use glTexSubImage2D as that will reduce the copy overheads in any updates.

Brolingstanz
08-17-2009, 12:49 AM
This rationale makes sense for standard OGL, but ES doesn't implement glDrawPixels() or glCopyPixels()!

Yep, and strictly speaking neither does GL 3.2.

asymmetric
08-23-2009, 04:57 AM
The OGLES forums are here:
http://www.khronos.org/message_boards/

and its specs/info is here:
http://www.khronos.org/opengles/

Thanks.


What the Gold Book is telling you is correct. The fastest way to upload textures is to write to a texture bound to an FBO. But what you need to do is generate your pixels as geometry (optimised as much as possible) and then draw them to the FBO using an Orth matrix, GL_POINTS and glDrawArrays.

This sounds like a good solution. Thanks very much!