天天看点

android纹理缓存,Android OpenGL ES Framebuffer对象 – 渲染深度缓冲区到纹理

好的,一个答案.使用OpenGL ES 2可以在Android 2.2上工作:

// Create a frame buffer

glGenFramebuffers( 1, &(frame_buffer ) );

// Generate a texture to hold the colour buffer

glGenTextures(1, &(colour_texture) );

glBindTexture(GL_TEXTURE_2D, colour_texture);

// Width and height do not have to be a power of two

glTexImage2D(GL_TEXTURE_2D, 0, GL_RGBA,

pixelWidth, pixelHeight,

0, GL_RGBA, GL_UNSIGNED_BYTE, NULL);

glTexParameteri(GL_TEXTURE_2D, GL_TEXTURE_WRAP_S, GL_CLAMP_TO_EDGE);

glTexParameteri(GL_TEXTURE_2D, GL_TEXTURE_WRAP_T, GL_CLAMP_TO_EDGE);

glTexParameteri(GL_TEXTURE_2D, GL_TEXTURE_MAG_FILTER, GL_NEAREST);

glTexParameteri(GL_TEXTURE_2D, GL_TEXTURE_MIN_FILTER, GL_NEAREST);

// Probably just paranoia

glBindTexture(GL_TEXTURE_2D, 0);

// Create a texture to hold the depth buffer

glGenTextures(1, &(depth_texture) );

glBindTexture(GL_TEXTURE_2D, depth_texture);

glTexImage2D(GL_TEXTURE_2D, 0, GL_DEPTH_COMPONENT,

pixelWidth, pixelHeight,

0, GL_DEPTH_COMPONENT, GL_UNSIGNED_SHORT, NULL);

glTexParameteri(GL_TEXTURE_2D, GL_TEXTURE_WRAP_S, GL_CLAMP_TO_EDGE);

glTexParameteri(GL_TEXTURE_2D, GL_TEXTURE_WRAP_T, GL_CLAMP_TO_EDGE);

glTexParameteri(GL_TEXTURE_2D, GL_TEXTURE_MAG_FILTER, GL_NEAREST);

glTexParameteri(GL_TEXTURE_2D, GL_TEXTURE_MIN_FILTER, GL_NEAREST);

glBindTexture(GL_TEXTURE_2D, 0);

glBindFramebuffer(GL_FRAMEBUFFER, frame_buffer);

// Associate the textures with the FBO.

glFramebufferTexture2D(GL_FRAMEBUFFER, GL_COLOR_ATTACHMENT0,

GL_TEXTURE_2D, colour_texture, 0);

glFramebufferTexture2D(GL_FRAMEBUFFER, GL_DEPTH_ATTACHMENT,

GL_TEXTURE_2D, depth_texture, 0);

// Check FBO status.

GLenum status = glCheckFramebufferStatus(GL_FRAMEBUFFER);

if ( status == GL_FRAMEBUFFER_COMPLETE )

{

// Success

}

真的很简单,请遵循OpenGL ES2手册,并按正确的顺序执行所有操作.

尝试使用OpenGL ES 1.1,将OES添加到必需的函数调用和_OES到常量,因为帧缓冲区对象是一个扩展.任何将深度纹理附加到帧缓冲区的尝试都会导致不完整的帧缓冲对象.

所以目前我的结论是,这并不适用于Android上的OpenGL ES 1.1,但它显然与ES 2.2兼容.

如果任何人有一个解决方案为ES 1.1,这将是有趣的看到它.