Warning: file_get_contents(/data/phpspider/zhask/data//catemap/3/android/179.json): failed to open stream: No such file or directory in /data/phpspider/zhask/libs/function.php on line 167

Warning: Invalid argument supplied for foreach() in /data/phpspider/zhask/libs/tag.function.php on line 1116

Notice: Undefined index: in /data/phpspider/zhask/libs/function.php on line 180

Warning: array_chunk() expects parameter 1 to be array, null given in /data/phpspider/zhask/libs/function.php on line 181
Java OpenGL ES 2.0对帧缓冲区创建的操作无效_Java_Android_Opengl Es 2.0 - Fatal编程技术网

Java OpenGL ES 2.0对帧缓冲区创建的操作无效

Java OpenGL ES 2.0对帧缓冲区创建的操作无效,java,android,opengl-es-2.0,Java,Android,Opengl Es 2.0,我尝试渲染到纹理,然后将纹理绘制到正方形中。在创建帧缓冲区时,在调用glFramebufferRenderbuffer和glFramebufferTexture2D之后,我得到了无效的操作。以下是创建帧缓冲区的函数: private void createFrameBuffer() { final int[] texture = new int[1]; frameTextureID = texture[0]; GLES20.glGenTextures(1,texture,

我尝试渲染到纹理,然后将纹理绘制到正方形中。在创建帧缓冲区时,在调用glFramebufferRenderbuffer和glFramebufferTexture2D之后,我得到了无效的操作。以下是创建帧缓冲区的函数:

private void createFrameBuffer()
{
    final int[] texture = new int[1];
    frameTextureID = texture[0];
    GLES20.glGenTextures(1,texture,0);
    GLES20.glBindTexture(GLES20.GL_TEXTURE_2D, frameTextureID);

    GLES20.glTexParameteri(GLES20.GL_TEXTURE_2D, GLES20.GL_TEXTURE_MAG_FILTER,GLES20.GL_NEAREST);
    GLES20.glTexParameteri(GLES20.GL_TEXTURE_2D, GLES20.GL_TEXTURE_MIN_FILTER,GLES20.GL_NEAREST);
    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.glTexImage2D(GLES20.GL_TEXTURE_2D, 0, GLES20.GL_RGBA, width, height, 0, GLES20.GL_RGBA, GLES20.GL_UNSIGNED_BYTE, null);

    final int[] depthBuffer = new int[1];
    GLES20.glGenRenderbuffers(1, depthBuffer, 0);
    renderBufferID = depthBuffer[0];

    GLES20.glBindRenderbuffer(GLES20.GL_RENDERBUFFER, depthBuffer[0]);
    GLES20.glRenderbufferStorage(GLES20.GL_RENDERBUFFER, GLES20.GL_DEPTH_COMPONENT16, width, height);

    final int[] frameBuffer = new int[1];
    GLES20.glGenFramebuffers(1,frameBuffer,0);
    frameBufferID = frameBuffer[0];
    GLES20.glBindFramebuffer(GLES20.GL_FRAMEBUFFER,frameBufferID);

    GLES20.glFramebufferTexture2D(GLES20.GL_FRAMEBUFFER, GLES20.GL_COLOR_ATTACHMENT0, GLES20.GL_TEXTURE_2D, frameTextureID, 0);
    error("glFramebufferTexture2D");
    GLES20.glFramebufferRenderbuffer(GLES20.GL_FRAMEBUFFER, GLES20.GL_DEPTH_ATTACHMENT  , GLES20.GL_RENDERBUFFER, renderBufferID);
    error("glFramebufferRenderbuffer");

    frameBufferComplete("createFrameBuffer");

    GLES20.glBindFramebuffer(GLES20.GL_FRAMEBUFFER,0);
    GLES20.glBindTexture(GLES20.GL_TEXTURE_2D, 0);
}
我不明白这有什么不对


ps:当我在函数末尾检查时,帧缓冲区已完成。

前几条语句的顺序错误:

final int[] texture = new int[1];
frameTextureID = texture[0];
GLES20.glGenTextures(1,texture,0);
在由glGenTextures设置纹理[0]之前,先获得该纹理的值。因此frameTextureID将始终为0

相反,这应该是:

final int[] texture = new int[1];
GLES20.glGenTextures(1,texture,0);
frameTextureID = texture[0];
还请注意,带有8位组件的RGBA8 RGBA不能保证在ES 2.0中是可渲染格式。这是您使用GL_RGBA和GL_UNSIGNED_BYTE组合的纹理。许多实现都支持使用。但是,如果您想完全确保您的代码在所有设备上都有效,则需要使用受支持的格式之一,如RGB565:

GLES20.glTexImage2D(GLES20.GL_TEXTURE_2D, 0, GLES20.GL_RGBA, width, height, 0,
                    GLES20.GL_RGBA, GLES20.GL_UNSIGNED_SHORT_5_6_5, null);