Android 渲染到纹理:最大数量?
我在Android应用程序中有一个类,它包含一个字节数组作为纹理的数据源。我使用帧缓冲区在纹理上渲染一些东西,然后在屏幕上渲染纹理。这很好用 但是,我只能使用151个纹理来完成此操作。实例#152生成此错误:Android 渲染到纹理:最大数量?,android,framebuffer,texture2d,Android,Framebuffer,Texture2d,我在Android应用程序中有一个类,它包含一个字节数组作为纹理的数据源。我使用帧缓冲区在纹理上渲染一些东西,然后在屏幕上渲染纹理。这很好用 但是,我只能使用151个纹理来完成此操作。实例#152生成此错误: :0: PVRSRVAllocDeviceMem: Error 1 returned :0: ComputeFrameBufferCompleteness: Can't create render surface. 以下是代码片段(构造函数): // Texture image byte
:0: PVRSRVAllocDeviceMem: Error 1 returned
:0: ComputeFrameBufferCompleteness: Can't create render surface.
以下是代码片段(构造函数):
// Texture image bytes
imgBuf=ByteBuffer.allocateDirect(TEXEL_X*TEXEL_Y*3);
imgBuf.position(0);
// Fill the texture with an arbitrary color, so we see something
byte col=(byte)(System.nanoTime()%255);
for (int ii=0; ii<imgBuf.capacity(); ii+=3)
{ imgBuf.put(col);
imgBuf.put((byte)(col*3%255));
imgBuf.put((byte)(col*7%255));
}
imgBuf.rewind();
// Generate the texture
GLES20.glGenTextures(1,textureID,0);
GLES20.glBindTexture(GLES20.GL_TEXTURE_2D,textureID[0]);
GLES20.glTexParameteri(GLES20.GL_TEXTURE_2D,GLES20.GL_TEXTURE_WRAP_S,
GLES20.GL_CLAMP_TO_EDGE);
GLES20.glTexParameteri(GLES20.GL_TEXTURE_2D, GLES20.GL_TEXTURE_WRAP_T,
GLES20.GL_CLAMP_TO_EDGE);
GLES20.glTexParameteri(GLES20.GL_TEXTURE_2D,
GLES20.GL_TEXTURE_MIN_FILTER,GLES20.GL_LINEAR);
GLES20.glTexParameteri(GLES20.GL_TEXTURE_2D,GLES20.GL_TEXTURE_MAG_FILTER,
GLES20.GL_LINEAR);
// Associate a two-dimensional texture image with the byte buffer
GLES20.glTexImage2D(GLES20.GL_TEXTURE_2D,0,GLES20.GL_RGB,TEXEL_X,
TEXEL_Y,0,GLES20.GL_RGB,GLES20.GL_UNSIGNED_BYTE,imgBuf);
GLES20.glBindTexture(GLES20.GL_TEXTURE_2D,0);
// Get framebuffer for later rendering to this texture
GLES20.glGenFramebuffers(1,frameBufID,0);
我希望有人能阐明这一点。
谢谢
Ru您很可能正在使用带有PowerVR SGX540 GPU的设备,他们在android上有这个问题。iOS上没有,所以这似乎是一个驱动程序问题,尽管他们的支持在论坛上说:
如果您确实需要渲染超过152个纹理,那么您必须使用glReadPixels()读取像素,删除纹理和fbo,并通过向GLTEXAGE2D提供数据来创建一个新纹理。151 fbo听起来很高,您需要这么多做做什么?它不是151 fbo。我只使用一个(始终相同)进行屏幕外渲染。纹理被附着、渲染到纹理并分离。然后我继续下一个纹理,依此类推。我不知道有任何内存泄漏,因为纹理也存在,没有FBO,没有使用FBO也没有问题,但没有屏幕外渲染。
// Bind frame buffer and specify texture as color attachment
GLES20.glBindFramebuffer(GLES20.GL_FRAMEBUFFER,frameBufID[0]);
GLES20.glFramebufferTexture2D(GLES20.GL_FRAMEBUFFER,GLES20.GL_COLOR_ATTACHMENT0,GLES20.GL_TEXTURE_2D,textureID[0],0);
// Check status
int status=GLES20.glCheckFramebufferStatus(GLES20.GL_FRAMEBUFFER);
Log.i(TAG,texNum+":"+status);
// Render some stuff on the texture
// ......
// (It does not matter. The status check fails even without rendering anything here)
GLES20.glFramebufferTexture2D(GLES20.GL_FRAMEBUFFER,GLES20.GL_COLOR_ATTACHMENT0,GLES20.GL_TEXTURE_2D,0,0);
GLES20.glBindFramebuffer(GLES20.GL_FRAMEBUFFER,0);