简体   繁体   中英

Opengl-es Drawing to texture

In opengl-es 2.0 can a fbo rendering to a texture, use a texture target that is larger than the screen? If so, is it possible to draw a textured quad, filling up the fbo-texture corner to corner? If not possible is it possible to do this in another way in opengl-es? I have some layered procedurally generated graphics at load time that I would like to combine into single textures in order to save on performance at draw time.

Yes, absolutely. As long as the texture has a color-renderable format (which in ES 2.0 are only RGBA4 , RGB5_A1 and RGB565 ), it can be used as a render target. Depending on the limits of your GPU, this can be significantly larger than the display resolution.

This means that you are primarily limited by the maximum texture size. You can query that value with glGetIntegerv(GL_MAX_TEXTURE_SIZE, ...) .

There is another limit that comes into play. GL_MAX_VIEWPORT_DIMS defines the maximum viewport size you can set. You can't render to a surface larger than these values.

Putting these two together, this would give the maximum size of a texture you can render to:

GLint maxTexSize = 0;
glGetIntegerv(GL_MAX_TEXTURE_SIZE, &maxTexSize);

GLint maxViewportSize[2] = {0};
glGetIntegerv(GL_MAX_VIEWPORT_DIMS, maxViewportSize);

GLint maxRenderWidth = maxTexSize;
if (maxRenderWidth > maxViewportSize[0]) {
    maxRenderWidth = maxViewportSize[0];
}

GLint maxRenderHeight = maxTexSize;
if (maxRenderHeight > maxViewportSize[1]) {
    maxRenderHeight = maxViewportSize[1];
}

Using these values, you can create a texture of size maxRenderWidth x maxRenderHeight , and use it as an FBO attachment. Remember to set the viewport to the same size as well before you start rendering.

I checked the limits on a couple of tablets with GPUs from two different major vendors. On both of them, the maximum texture size and maximum viewport size were the same (4096 on one, 8192 on the other). It wouldn't surprise me if this is very common, but it's definitely not guaranteed by the spec.

ES 2.0 allows the maximum texture size to be as small as 64. But you will find the limit to be much larger on anything halfway recent. 2048 is at the lower end of what you see on any reasonably current GPU, and 4096/8192 is common. The maximum viewport dimensions are guaranteed to be at least as large as the display.

The technical post webpages of this site follow the CC BY-SA 4.0 protocol. If you need to reprint, please indicate the site URL or the original address.Any question please contact:yoyou2525@163.com.

 
粤ICP备18138465号  © 2020-2024 STACKOOM.COM