简体   繁体   中英

Reading from a texture in OpenGL ES 2.0

I am currently rendering the depth of a scene to a texture. I want to get the value of the texture arbitrarily at any given points x, y. I tried to use glReadPixels but it doesn't seem to work and it also doesn't seem to be the optimum solution. I am thinking about a way of reading the texture data directly from the memory, if possible. Any idea of getting that value for any given x, y apart from actually rendering a quad with the depth texture on the framebuffer?

By the way, I am using Java on Android with OpenGL ES 2.0.

GLES20.glGetIntegerv(GLES20.GL_FRAMEBUFFER_BINDING, mainBufferHandle, 0);
if(mainBufferHandle[0] < 0) mainBufferHandle[0] = 0;

GLES20.glBindFramebuffer(GLES20.GL_FRAMEBUFFER, depthBufferHandle[0]);

GLES20.glFramebufferTexture2D(GLES20.GL_FRAMEBUFFER, GLES20.GL_DEPTH_ATTACHMENT, GLES20.GL_TEXTURE_2D, depthTextureHandle[0], 0);

GLES20.glReadPixels(x, y, 1, 1, GLES20.GL_RGB, GLES20.GL_FLOAT, floatBuffer);

我想我只是要将深度渲染到FBO,然后使用glReadPixel来获取深度值。

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