Warning: file_get_contents(/data/phpspider/zhask/data//catemap/9/java/394.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

Warning: file_get_contents(/data/phpspider/zhask/data//catemap/3/android/227.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 Android上GLES 2.0中动态立方体贴图的帧缓冲区对象 更新:原来这是Nexus S中powerVR SGX的驱动程序问题。该代码在我测试过的所有其他设备上都能流畅地工作。_Java_Android_Rendering_Opengl Es 2.0_Out Of Memory - Fatal编程技术网

Java Android上GLES 2.0中动态立方体贴图的帧缓冲区对象 更新:原来这是Nexus S中powerVR SGX的驱动程序问题。该代码在我测试过的所有其他设备上都能流畅地工作。

Java Android上GLES 2.0中动态立方体贴图的帧缓冲区对象 更新:原来这是Nexus S中powerVR SGX的驱动程序问题。该代码在我测试过的所有其他设备上都能流畅地工作。,java,android,rendering,opengl-es-2.0,out-of-memory,Java,Android,Rendering,Opengl Es 2.0,Out Of Memory,我将制作一个较小的测试用例并提交一个bug报告。。。给某人。不知道是谁 嘿,伙计们 首先,我正在使用JavaGles2.0绑定开发一个从AndAR(Android的ARToolkit)到GLES2.0的端口。如果您感到好奇,可以在这里找到我的全部代码,但我将尝试在这个问题中总结问题 我正试图实现这篇论文,以生成AR渲染,从而真实地反射和折射:。为此,确定要渲染的对象的屏幕空间边界框,然后用于为表示立方体贴图每个面的平面生成纹理坐标。这意味着为每个模型的每个帧渲染立方体贴图。我现在一次只渲染一个

我将制作一个较小的测试用例并提交一个bug报告。。。给某人。不知道是谁


嘿,伙计们

首先,我正在使用JavaGles2.0绑定开发一个从AndAR(Android的ARToolkit)到GLES2.0的端口。如果您感到好奇,可以在这里找到我的全部代码,但我将尝试在这个问题中总结问题

我正试图实现这篇论文,以生成AR渲染,从而真实地反射和折射:。为此,确定要渲染的对象的屏幕空间边界框,然后用于为表示立方体贴图每个面的平面生成纹理坐标。这意味着为每个模型的每个帧渲染立方体贴图。我现在一次只渲染一个模型。我正在尝试使用帧缓冲区对象根据本文描述的方法渲染立方体贴图

不管怎样,这是个问题

我已经基本实现了它。据我所知,至少立方体贴图的正面正确生成了顶点和UV坐标。我可以将我的正面渲染到系统为屏幕提供的帧缓冲区中,并且只要我愿意,它渲染得很好,没有问题。将其渲染到帧缓冲区对象时会出现问题

当我将立方体贴图面渲染到链接到立方体贴图纹理的帧缓冲区对象时,GL会在几秒钟内耗尽我的全部内存,并导致GLError 1285崩溃(内存不足)。如果不绑定FBO,我可以将立方体贴图面渲染到屏幕上,而不会出现任何内存问题。立方体贴图纹理大小为128像素见方,这对于移动设备来说应该是合理的。不知何故,GL正在泄漏内存

这是我做事的大致顺序。这是该帧渲染的条目。(~179行)

绘制对象的代码有点像这样:

(~36行)

(~第55行)

请注意,生成立方体贴图(顶点)朝向渲染对象的开始。这就是它的作用。屏幕空间边界框[ssbb]已从顶点计算。 (~280行)

就这样。。。下面是我如何在程序启动时初始化FBO和立方体贴图纹理。 (~128行)

//生成立方体贴图纹理
int[]cubemaptextures=新的int[1];
GLES20.glGenTextures(1,立方结构,0);
mCubeMapTexture=cubemaptexture[0];
GLES20.glActiveTexture(GLES20.GL_TEXTURE1);
GLES20.glBindTexture(GLES20.GL_纹理_立方体_贴图,mCubeMapTexture);
对于(int i=0;i<6;i++){
GLES20.glTexImage2D(GLES20.GL_纹理_立方体_贴图_正X+i,0,模式,立方体贴图大小,立方体贴图大小,0,模式,GLES20.GL_无符号字节,ByteBuffer.wrap(帧));
}
GLES20.glTexParameterf(GLES20.GL_纹理_立方体_贴图,GLES20.GL_纹理_包裹,GLES20.GL_夹紧至边缘);
GLES20.glTexParameterf(GLES20.GL_纹理_立方体_贴图,GLES20.GL_纹理_包裹,GLES20.GL_夹紧至边缘);
GLES20.glTexParameteri(GLES20.GL_纹理_立方体_贴图,GLES20.GL_纹理_最小_过滤器,GLES20.GL_最近);
GLES20.glTexParameteri(GLES20.GL_纹理_立方体_贴图,GLES20.GL_纹理_贴图过滤器,GLES20.GL_最近);
GLES20.glBindTexture(GLES20.GL_纹理_立方体_贴图,0);
//为立方体贴图创建一组帧缓冲区
mFrameBuffers=newint[6];
glGenFramebuffers(6,mFrameBuffers,0);
对于(int i=0;i<6;i++){
GLES20.glBindFramebuffer(GLES20.GL_FRAMEBUFFER,mframebuffer[i]);
GLES20.glFramebufferTexture2D(GLES20.GL_帧缓冲区、GLES20.GL_颜色_附件0、,
GLES20.GL_纹理_立方体_贴图_正X+i,mCubeMapTexture,0);
GLES20.glCheckFramebufferStatus(GLES20.GL_FRAMEBUFFER);
}
GLES20.glBindFramebuffer(GLES20.GL_FRAMEBUFFER,0);
也许我的订购错误,或者我的设置不正确

抱歉发了这么长的邮件。我真的尽了我所能使这个尽可能短,同时仍然提供足够的信息来解决这个问题。我删掉了很多特定于应用程序的额外代码。如果您感兴趣,或者您认为问题可能是由其他地方引起的,我提供了指向实际源文件的链接,以便您可以快速查看

谢谢你的时间!我在这件事上浪费了太多时间

-格里夫

编辑:澄清纹理大小

// BEGIN TO DRAW FRAME.  DRAW BACKGROUND CAMERA IMAGE TO QUAD
GLES20.glClear(GLES20.GL_COLOR_BUFFER_BIT);
GLES20.glUseProgram(mProgram);
GLES20.glActiveTexture(GLES20.GL_TEXTURE0); // Camera image is stored in Texture0
GLES20.glBindTexture(GLES20.GL_TEXTURE_2D, textureName);

//load new preview frame as a texture, if needed
GLES20.glTexSubImage2D(GLES20.GL_TEXTURE_2D, 0, 0, 0, previewFrameWidth, previewFrameHeight, mode, GLES20.GL_UNSIGNED_BYTE, frameData);

//draw camera preview frame:
squareBuffer.position(0);
GLES20.glVertexAttribPointer(maPositionHandle, 3, GLES20.GL_FLOAT, false, GraphicsUtil.TRIANGLE_VERTICES_DATA_STRIDE_BYTES, squareBuffer);
GLES20.glEnableVertexAttribArray(maPositionHandle);
textureBuffer.position(0);
GLES20.glVertexAttribPointer(maTextureHandle, 2, GLES20.GL_FLOAT, false, GraphicsUtil.TRIANGLE_VERTICES_UV_STRIDE_BYTES, textureBuffer);
GLES20.glEnableVertexAttribArray(maTextureHandle);

Matrix.multiplyMM(mMVPMatrix, 0, mProjMatrix, 0, mVMatrix, 0);
GLES20.glUniformMatrix4fv(muMVPMatrixHandle, 1, false, mMVPMatrix, 0);
GLES20.glUniform1i(mSamplerLoc, 0);

//draw camera square
GLES20.glDrawArrays(GLES20.GL_TRIANGLE_STRIP, 0, 4);

GLES20.glDisableVertexAttribArray(maPositionHandle);
GLES20.glDisableVertexAttribArray(maTextureHandle);

DRAW_OBJECTS();
// Use the new program for the object (Refract/reflect shader)
GLES20.glUseProgram( mProgram );

// Transform to where the marker is
Matrix.multiplyMM(mMVPMatrix, 0, glCameraMatrix, 0, glMatrix, 0);
GLES20.glUniformMatrix4fv(muMVPMatrixHandle, 1, false, mMVPMatrix, 0);

// Create a cubemap for this object from vertices
GENERATE_CUBEMAP( box.vertArray() );

// Feed in Verts
box.verts().position(0);
box.normals().position(0);
GLES20.glVertexAttribPointer(maPositionHandle, 3, GLES20.GL_FLOAT, false, VERTEX_NORMAL_DATA_STRIDE, box.verts());
GLES20.glEnableVertexAttribArray(maPositionHandle);

GLES20.glVertexAttribPointer(maNormalHandle, 3, GLES20.GL_FLOAT, false, VERTEX_NORMAL_DATA_STRIDE, box.normals());
GLES20.glEnableVertexAttribArray(maNormalHandle);

// Set Uniforms...
GLES20.glUniform4f(muColor, 0.0f, 1.0f, 0.0f, 1.0f);
...

// Draw the cube faces
GLES20.glDrawArrays(GLES20.GL_TRIANGLE_STRIP, 0, 4);
...

GLES20.glDisableVertexAttribArray(maPositionHandle);
GLES20.glDisableVertexAttribArray(maNormalHandle);
// Grab the current viewport and program for restoration later
int[] OldViewport = new int[4], OldProgram = new int[1];
GLES20.glGetIntegerv(GLES20.GL_VIEWPORT, OldViewport, 0);
GLES20.glGetIntegerv(GLES20.GL_CURRENT_PROGRAM, OldProgram, 0);

// Update dynamic cubemap based on screen space bounding box for this frame     
mDC.UpdateUVs( DynamicCubemap.CorrectSSBB( ssbb ), widthcorrection, heightcorrection ); 

// Set up the program used to render to the texture
GLES20.glUseProgram(mProgram);
GLES20.glActiveTexture(GLES20.GL_TEXTURE0);
GLES20.glBindTexture(GLES20.GL_TEXTURE_2D, textureName);
float[] projmatrix = new float[16]; // Projection Matrix
Matrix.orthoM(projmatrix, 0, -1.0f, 1.0f, -1.0f, 1.0f, -1.0f, 1.0f);
Matrix.multiplyMM(mMVPMatrix, 0, projmatrix, 0, mVMatrix, 0);
GLES20.glUniformMatrix4fv(muMVPMatrixHandle, 1, false, mMVPMatrix, 0);
GLES20.glUniform1i(mSamplerLoc, 0); // Use the camera texture (bound in unit zero)

// Render to the front face of the cubemap
// Note:  If I don't bind the new Framebuffer, this 
// renders the face to the screen very nicely without memory issues
GLES20.glActiveTexture(GLES20.GL_TEXTURE1);
GLES20.glBindTexture(GLES20.GL_TEXTURE_CUBE_MAP, 0); // Ensure we aren't rendering to the same texture we're using
GLES20.glBindFramebuffer(GLES20.GL_FRAMEBUFFER, mFrameBuffers[5]);
GLES20.glViewport( 0, 0, edu.dhbw.andar.Config.CUBEMAP_SIZE, edu.dhbw.andar.Config.CUBEMAP_SIZE);
GLES20.glClear( GLES20.GL_COLOR_BUFFER_BIT );
mDC.DrawFace( 5, maPositionHandle, maTextureHandle ); // Draw the front face with glDrawArrays

// Unbind the framebuffer, we no longer need to render to textures.
GLES20.glBindFramebuffer(GLES20.GL_FRAMEBUFFER, 0);

// Ensure the newly generated cubemap is bound to the correct texture unit
GLES20.glBindTexture(GLES20.GL_TEXTURE_CUBE_MAP, mCubeMapTexture);

// Bind the old program and viewport
GLES20.glUseProgram( OldProgram[0] );
GLES20.glViewport( OldViewport[0], OldViewport[1], OldViewport[2], OldViewport[3] );
// Generate Cubemap Textures
int[] cubemaptextures = new int[1];
GLES20.glGenTextures(1, cubemaptextures, 0 );
mCubeMapTexture = cubemaptextures[0];
GLES20.glActiveTexture(GLES20.GL_TEXTURE1);
GLES20.glBindTexture(GLES20.GL_TEXTURE_CUBE_MAP, mCubeMapTexture);   

for( int i = 0; i < 6; i++ ) {
    GLES20.glTexImage2D(GLES20.GL_TEXTURE_CUBE_MAP_POSITIVE_X + i, 0, mode, CUBEMAP_SIZE, CUBEMAP_SIZE, 0, mode, GLES20.GL_UNSIGNED_BYTE, ByteBuffer.wrap(frame));
}
GLES20.glTexParameterf(GLES20.GL_TEXTURE_CUBE_MAP, GLES20.GL_TEXTURE_WRAP_S, GLES20.GL_CLAMP_TO_EDGE);
GLES20.glTexParameterf(GLES20.GL_TEXTURE_CUBE_MAP, GLES20.GL_TEXTURE_WRAP_T, GLES20.GL_CLAMP_TO_EDGE);
GLES20.glTexParameteri(GLES20.GL_TEXTURE_CUBE_MAP, GLES20.GL_TEXTURE_MIN_FILTER, GLES20.GL_NEAREST);
GLES20.glTexParameteri(GLES20.GL_TEXTURE_CUBE_MAP, GLES20.GL_TEXTURE_MAG_FILTER, GLES20.GL_NEAREST);
GLES20.glBindTexture(GLES20.GL_TEXTURE_CUBE_MAP, 0);

// Create a set of FrameBuffers for the cubemap
mFrameBuffers = new int[6];
GLES20.glGenFramebuffers(6, mFrameBuffers, 0);
for( int i = 0; i < 6; i++ ) {
    GLES20.glBindFramebuffer(GLES20.GL_FRAMEBUFFER, mFrameBuffers[i]);
    GLES20.glFramebufferTexture2D( GLES20.GL_FRAMEBUFFER, GLES20.GL_COLOR_ATTACHMENT0,
GLES20.GL_TEXTURE_CUBE_MAP_POSITIVE_X + i, mCubeMapTexture, 0 );
    GLES20.glCheckFramebufferStatus( GLES20.GL_FRAMEBUFFER );
}
GLES20.glBindFramebuffer(GLES20.GL_FRAMEBUFFER, 0);