Cube Envoirement Map OpengGl es 2.0

i have read many tutorials about envoirement mapping for reflections, in some of them they are creating for every side of the cube one frame buffer in others they use one for the whole cube. Which is the right approach?

I am using java and Android 4.0.

I have follwing code and I am getting the glError 1282 on setting follwing:

glFramebufferTexture2D( GL_FRAMEBUFFER, GL_COLOR_ATTACHMENT0, GL_TEXTURE_CUBE_MAP_POSITIVE_X + p_face, m_cubeMap[0], 0 );       

The code for cube map generation is:

        m_cubeMap = new int[1];
	m_cubeFB  = new int[1];
	m_cubeDB  = new int[1];
	// create the cube map
	glGenTextures  ( 1, m_cubeMap, 0 );
        glBindTexture  ( GL_TEXTURE_CUBE_MAP, m_cubeMap[0] );

        glGenFramebuffers( 1, m_cubeFB, 0 );        
        glBindFramebuffer( GL_FRAMEBUFFER, m_cubeFB[0] );
        for( int i = 0; i < 6; i++ ) {
        	glTexImage2D( GL_TEXTURE_CUBE_MAP_POSITIVE_X + i, 0, GL_RGB, m_cubeMapSize, m_cubeMapSize, 0, GL_RGB, GL_UNSIGNED_BYTE, null );
        glGenRenderbuffers   ( 1, m_cubeDB, 0 );
        glBindRenderbuffer	 ( GL_RENDERBUFFER, m_cubeDB[0] );
        glRenderbufferStorage( GL_RENDERBUFFER, GL_DEPTH_COMPONENT16, m_cubeMapSize, m_cubeMapSize );

        glFramebufferRenderbuffer( GL_FRAMEBUFFER, GL_DEPTH_ATTACHMENT,  GL_RENDERBUFFER, m_cubeFB[0] );
        glFramebufferTexture2D   ( GL_FRAMEBUFFER, GL_COLOR_ATTACHMENT0, GL_TEXTURE_CUBE_MAP_POSITIVE_X, m_cubeMap[0], 0 );
        glBindFramebuffer ( GL_FRAMEBUFFER,	     0 );    
        glBindRenderbuffer( GL_RENDERBUFFER,     0 );
        glBindTexture	  ( GL_TEXTURE_CUBE_MAP, 0 );
        if( LoggerConfig.ON )
        	checkGlError( "InitRefCubeMap()" );

Before I iterate through all faces I set follwing state:

glBindFramebuffer( GL_FRAMEBUFFER, m_cubeFB[0] );
glViewport( 0, 0, m_cubeMapSize, m_cubeMapSize );

For drawing every Face i, and where the Error will happen:

  glFramebufferTexture2D( GL_FRAMEBUFFER, GL_COLOR_ATTACHMENT0, GL_TEXTURE_CUBE_MAP_POSITIVE_X + p_face, m_cubeMap[0], 0 );       
        if( LoggerConfig.ON )
        	checkGlError( "DrawRefCubeMap() Face " + p_face );

It would be great if you can help me. Thanks!

I already answered this on another site, but just to avoid keeping the question open here: The last argument to glFrameBufferRenderbuffer() is wrong. It should be m_cubeDB[0] instead of m_cubeFB[0].

Hi, Thank you. But the same error is still there. If I am accessing the texture for writing (glFramebufferTexture2D) the glError 1282 will happen. The interessting thing is, that the error will happen after the first face. So GL_TEXTURE_CUBE_MAP_POSITIVE_X is fine, but GL_TEXTURE_CUBE_MAP_POSITIVE_X + 1 will throw the error.

Do I need maybe one Framebuffer for every side of the cube?

you need to bind same FBO for every side of the cube. it would be somewhat like:

for (face = 1; face < 6; face++) {
    glFramebufferTexture2D(GL_FRAMEBUFFER, GL_COLOR_ATTACHMENT0, GL_TEXTURE_CUBE_MAP_POSITIVE_X + face, textureObject, 0);

Another device shows better debug information. On rendering I am getting following shader error:
06-18 17:58:53.093: V/ShaderHelper(11910): Log:Validate: Sampler ‘u_CubeMap’ and ‘u_ShadowMap’ are of different types, but share texture unit 0.
But I am using different texture units for every different texture? If I remove all shadow map code, it will show the same error with another loaded texture.

check your glActiveTexture() and glUniform() calls for samplers when you attach it to both the textures.

I am not setting the cube_map for every material. So the uniform is 0, when not set. But i am controling the usage with other uniforms, so no acces without setting the proper uniforms. Could this be a problem?

If I am using the texture units beginning from 1. Zero will never used and the warning from shader validation will not apear. But the problem still exists.

The Problem was, that i a have used the same shader for rendering the cube map and for displaying it. Even if the uniform of the cube map was not set and checked with another boolean uniform before usage, the fragment shader crashed. After using a simple phong shader the problem is gone.