sampling a depth cubemap FBO texture results in gl error

Started by
10 comments, last by JohnnyCode 9 years, 10 months ago
Hi guys. I'm getting GL_INVALID_OPERATION when my depth cubemap is sampled in lighting shader. What's wrong? specs says that I didn't unbind the framebuffer before using it's texture, but I'm 100% sure that I did. Isnt "glBindFramebuffer(GL_FRAMEBUFFER, 0);" enough? I'd appreciate any help
Advertisement

Which gl version are you targeting? on what hardware?

Detach it from the framebuffer via glFramebufferTexture2D().


L. Spiro

I restore Nintendo 64 video-game OST’s into HD! https://www.youtube.com/channel/UCCtX_wedtZ5BoyQBXEhnVZw/playlists?view=1&sort=lad&flow=grid

Detach it from the framebuffer via glFramebufferTexture2D().


L. Spiro

What? How? I didn't use it! I guess you must be right, now I'm gonna try...

i've tried that way, but it doesnt work:


for (int i = 0 ; i < 6 ; i++) {
glFramebufferTexture2D(GL_FRAMEBUFFER, GL_DEPTH_ATTACHMENT, GL_TEXTURE_CUBE_MAP_POSITIVE_X+i, 0, 0);
}
Why don’t you post the actual code and the point where the error occurs?


L. Spiro

I restore Nintendo 64 video-game OST’s into HD! https://www.youtube.com/channel/UCCtX_wedtZ5BoyQBXEhnVZw/playlists?view=1&sort=lad&flow=grid

my code is pretty big and it worked in old gl mode.

Then I ported code to GL 3,0 and I'm getting this error every glDrawElements call within the light pass. The scene is partially shadow correctly, and partially occluded in black. The depth values in cubemap are correct (I've tested them with glDebugger).

Here is my cubemap stuff:


		
	void CreateShadowMapCubeDepthFBO()
	{
		// Create the FBO
		glGenFramebuffers(1, &m_fbo);

		// Create the depth buffer
		glGenTextures(1, &m_depth);
		glBindTexture(GL_TEXTURE_CUBE_MAP, m_depth);
	    
		for (int i = 0 ; i < 6 ; i++)
		{
			glTexImage2D(GL_TEXTURE_CUBE_MAP_POSITIVE_X + i, 0, GL_DEPTH_COMPONENT32, size, size, 0, GL_DEPTH_COMPONENT, GL_FLOAT, NULL);
			glTexParameteri(GL_TEXTURE_CUBE_MAP, GL_TEXTURE_MIN_FILTER, GL_LINEAR);
			glTexParameteri(GL_TEXTURE_CUBE_MAP, GL_TEXTURE_MAG_FILTER, GL_LINEAR);
			glTexParameteri(GL_TEXTURE_CUBE_MAP, GL_TEXTURE_WRAP_S, GL_CLAMP_TO_EDGE);
			glTexParameteri(GL_TEXTURE_CUBE_MAP, GL_TEXTURE_WRAP_T, GL_CLAMP_TO_EDGE);
			glTexParameteri(GL_TEXTURE_CUBE_MAP, GL_TEXTURE_WRAP_R, GL_CLAMP_TO_EDGE);
		}
		glBindTexture(GL_TEXTURE_CUBE_MAP, 0);

		glBindFramebuffer(GL_FRAMEBUFFER, m_fbo);
		for (int i = 0 ; i < 6 ; i++)
		{
			glFramebufferTexture2D(GL_FRAMEBUFFER, GL_DEPTH_ATTACHMENT, GL_TEXTURE_CUBE_MAP_POSITIVE_X+i, m_depth, 0);
		}

		GLenum Status = glCheckFramebufferStatus(GL_FRAMEBUFFER);

		if (Status != GL_FRAMEBUFFER_COMPLETE) 
		{
			// print stuff
		}
		glBindFramebuffer(GL_FRAMEBUFFER, 0);
	}


	void BindFBOCubeMapFace(int index)
	{
		glBindFramebuffer(GL_FRAMEBUFFER, m_fbo);
		glFramebufferTexture2D(GL_FRAMEBUFFER, GL_DEPTH_ATTACHMENT, GL_TEXTURE_CUBE_MAP_POSITIVE_X+index, m_depth, 0);
	}
	 void StopUsingFBO()
	 {
		for (u32 i = 0 ; i < 6 ; i++) 
		{
			glFramebufferTexture2D(GL_FRAMEBUFFER, GL_DEPTH_ATTACHMENT, GL_TEXTURE_CUBE_MAP_POSITIVE_X+i, 0, 0);
		}
		glBindFramebuffer(GL_FRAMEBUFFER, 0);
	}

you are attaching the cubemap faces to GL_DEPTH_ATTACHMENT, not the GL_COLOR_ATTACHMENTx

It is rather rare to have gpu the support for sampling depth attachment storage of a frame object. You must query the "depth texture" extension availability if you will ever want to.

But I would encourage you to not do so, but instead, attach cube faces to COLORx storage and encode your depth values to those. Then, by a simple

glBindFramebuffer(GL_FRAMEBUFFER, 0);

all your color storage textrues of unbound frame will be available for setting as a sampling slot.

You can use MRT (multiple render targets) so you will save up processing of your cube generation and store the z values along with the rendering of yours that performs z values in depth buffer you wish to sample.

First, you didn’t post the draw call or the location of the error.
Did you clear the error flag before you actually called glDrawElements()? This is (mainly) what I wanted to see in the first place.


Second:


		
		for (int i = 0 ; i < 6 ; i++)
		{
			glFramebufferTexture2D(GL_FRAMEBUFFER, GL_DEPTH_ATTACHMENT, GL_TEXTURE_CUBE_MAP_POSITIVE_X+i, m_depth, 0);
		}

Whaaaaa-
There can only be one depth attachment. This loop is meaningless. Remove it.
If you need to check the framebuffer status, put the first cubemap face as the depth texture.


And this:


	 void StopUsingFBO()
	 {
		for (u32 i = 0 ; i < 6 ; i++) 
		{
			glFramebufferTexture2D(GL_FRAMEBUFFER, GL_DEPTH_ATTACHMENT, GL_TEXTURE_CUBE_MAP_POSITIVE_X+i, 0, 0);
		}
		glBindFramebuffer(GL_FRAMEBUFFER, 0);
	}

Should be:


	 void StopUsingFBO()
	 {
		glBindFramebuffer(GL_FRAMEBUFFER, 0);
	}



L. Spiro

I restore Nintendo 64 video-game OST’s into HD! https://www.youtube.com/channel/UCCtX_wedtZ5BoyQBXEhnVZw/playlists?view=1&sort=lad&flow=grid

Thank you for pointing this stuff, but my shadows still aren't working.

I think I cleared error flag before glDrawElements, I am calling glGetError very often.

Anyway, here is the entire log of my OpenGL calls, starting from unbinding the FBO (after I have drawn six views to it), and ending with gl error.

Please take a look:

11tv0qa.jpg

EDIT: just note that my old code with the same shadow map cubemap code but for old openGL (without compatilibity mode) is working on the same PC...

specs says that I didn't unbind the framebuffer before using it's texture

Where in the specifications does it say glDrawElements() throws GL_INVALID_OPERATION in relation to a framebuffer?

OpenGL X (really wish they would specify the OpenGL version on their reference pages…) doesn’t: http://www.opengl.org/sdk/docs/man/html/glDrawElements.xhtml
OpenGL 3.0 doesn’t: http://www.opengl.org/sdk/docs/man3/xhtml/glDrawElements.xml
OpenGL 4.0 doesn’t: http://www.opengl.org/sdk/docs/man4/html/glDrawElements.xhtml

You don’t have a framebuffer bound so that isn’t the problem.


L. Spiro

I restore Nintendo 64 video-game OST’s into HD! https://www.youtube.com/channel/UCCtX_wedtZ5BoyQBXEhnVZw/playlists?view=1&sort=lad&flow=grid

This topic is closed to new replies.

Advertisement