Jump to content

  • Log In with Google      Sign In   
  • Create Account


sampling a depth cubemap FBO texture results in gl error


Old topic!
Guest, the last post of this topic is over 60 days old and at this point you may not reply in this topic. If you wish to continue this conversation start a new topic.

  • You cannot reply to this topic
11 replies to this topic

#1 fread   Members   -  Reputation: 230

Like
0Likes
Like

Posted 02 June 2014 - 04:46 PM

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

Sponsor:

#2 NumberXaero   Prime Members   -  Reputation: 1365

Like
0Likes
Like

Posted 02 June 2014 - 05:17 PM

Which gl version are you targeting? on what hardware?


Edited by NumberXaero, 02 June 2014 - 05:20 PM.


#3 L. Spiro   Crossbones+   -  Reputation: 12978

Like
2Likes
Like

Posted 02 June 2014 - 09:04 PM

Detach it from the framebuffer via glFramebufferTexture2D().


L. Spiro
It is amazing how often people try to be unique, and yet they are always trying to make others be like them. - L. Spiro 2011
I spent most of my life learning the courage it takes to go out and get what I want. Now that I have it, I am not sure exactly what it is that I want. - L. Spiro 2013
I went to my local Subway once to find some guy yelling at the staff. When someone finally came to take my order and asked, “May I help you?”, I replied, “Yeah, I’ll have one asshole to go.”
L. Spiro Engine: http://lspiroengine.com
L. Spiro Engine Forums: http://lspiroengine.com/forums

#4 fread   Members   -  Reputation: 230

Like
0Likes
Like

Posted 03 June 2014 - 04:42 AM

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);
}

Edited by fread, 03 June 2014 - 06:53 AM.


#5 L. Spiro   Crossbones+   -  Reputation: 12978

Like
0Likes
Like

Posted 04 June 2014 - 03:22 AM

Why don’t you post the actual code and the point where the error occurs?


L. Spiro
It is amazing how often people try to be unique, and yet they are always trying to make others be like them. - L. Spiro 2011
I spent most of my life learning the courage it takes to go out and get what I want. Now that I have it, I am not sure exactly what it is that I want. - L. Spiro 2013
I went to my local Subway once to find some guy yelling at the staff. When someone finally came to take my order and asked, “May I help you?”, I replied, “Yeah, I’ll have one asshole to go.”
L. Spiro Engine: http://lspiroengine.com
L. Spiro Engine Forums: http://lspiroengine.com/forums

#6 fread   Members   -  Reputation: 230

Like
0Likes
Like

Posted 04 June 2014 - 08:16 AM

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);
	}


#7 JohnnyCode   Members   -  Reputation: 205

Like
0Likes
Like

Posted 04 June 2014 - 12:14 PM

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.

 

 

 



#8 L. Spiro   Crossbones+   -  Reputation: 12978

Like
3Likes
Like

Posted 04 June 2014 - 03:14 PM

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


Edited by L. Spiro, 04 June 2014 - 03:17 PM.

It is amazing how often people try to be unique, and yet they are always trying to make others be like them. - L. Spiro 2011
I spent most of my life learning the courage it takes to go out and get what I want. Now that I have it, I am not sure exactly what it is that I want. - L. Spiro 2013
I went to my local Subway once to find some guy yelling at the staff. When someone finally came to take my order and asked, “May I help you?”, I replied, “Yeah, I’ll have one asshole to go.”
L. Spiro Engine: http://lspiroengine.com
L. Spiro Engine Forums: http://lspiroengine.com/forums

#9 fread   Members   -  Reputation: 230

Like
0Likes
Like

Posted 05 June 2014 - 02:53 AM

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...


Edited by fread, 05 June 2014 - 02:57 AM.


#10 L. Spiro   Crossbones+   -  Reputation: 12978

Like
2Likes
Like

Posted 05 June 2014 - 05:14 AM

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
It is amazing how often people try to be unique, and yet they are always trying to make others be like them. - L. Spiro 2011
I spent most of my life learning the courage it takes to go out and get what I want. Now that I have it, I am not sure exactly what it is that I want. - L. Spiro 2013
I went to my local Subway once to find some guy yelling at the staff. When someone finally came to take my order and asked, “May I help you?”, I replied, “Yeah, I’ll have one asshole to go.”
L. Spiro Engine: http://lspiroengine.com
L. Spiro Engine Forums: http://lspiroengine.com/forums

#11 fread   Members   -  Reputation: 230

Like
0Likes
Like

Posted 05 June 2014 - 08:30 AM

It happens only if I enable a shadow mapping.

 

And I read that:

 

 

GL_INVALID_OPERATION is generated if a non-zero buffer object name is bound to an enabled array or the element array and the buffer object's data store is currently mapped.

buffer object = frame buffer.

currently maped = frame buffer bound for writing

This ain't right?

 

So what is wrong, then? Why is cubemap sampler read giving me invalid operation error and strange shadows?

If I comment out cubemap reading in lighting shader everything is OK. Any ideas?

 

EDIT:
To put it straight, take a look:

 

this code causes this error:


float ShadowMapValue = texture(Sampler_ShadowCubeMap,Vec3ShadowDir).x;

and this code works OK:


float ShadowMapValue = 1.0; //////////*texture(Sampler_ShadowCubeMap,Vec3ShadowDir).x;*/

so something must be related to "texture" function call and Shadow CubeMap sampling


Edited by fread, 05 June 2014 - 09:14 AM.


#12 JohnnyCode   Members   -  Reputation: 205

Like
0Likes
Like

Posted 05 June 2014 - 10:35 AM

try this function just before the draw call and see what it returns

http://www.opengl.org/sdk/docs/man3/xhtml/glCheckFramebufferStatus.xml

 

Other than that, you create texture storage as

 

 

glTexParameteri(GL_TEXTURE_CUBE_MAP, GL_TEXTURE_MIN_FILTER, GL_LINEAR);
glTexParameteri(GL_TEXTURE_CUBE_MAP, GL_TEXTURE_MAG_FILTER, GL_LINEAR);

 

this means it is a filtered bilinear texture. Do not count on mipmap levels being build automaticly, you should call

glGenerateMipMaps after binding the rendered textures, or, much better - not use a filtered texture at all,  (use GL_NEAREST instead).

 

And state what OGL version you target, since Opengl ES does not support sampling depth attachments of a FBO, whather bound or not, unless you try to query the extension wheather it is available.






Old topic!
Guest, the last post of this topic is over 60 days old and at this point you may not reply in this topic. If you wish to continue this conversation start a new topic.



PARTNERS