• Announcements

    • khawk

      Download the Game Design and Indie Game Marketing Freebook   07/19/17

      GameDev.net and CRC Press have teamed up to bring a free ebook of content curated from top titles published by CRC Press. The freebook, Practices of Game Design & Indie Game Marketing, includes chapters from The Art of Game Design: A Book of Lenses, A Practical Guide to Indie Game Marketing, and An Architectural Approach to Level Design. The GameDev.net FreeBook is relevant to game designers, developers, and those interested in learning more about the challenges in game development. We know game development can be a tough discipline and business, so we picked several chapters from CRC Press titles that we thought would be of interest to you, the GameDev.net audience, in your journey to design, develop, and market your next game. The free ebook is available through CRC Press by clicking here. The Curated Books The Art of Game Design: A Book of Lenses, Second Edition, by Jesse Schell Presents 100+ sets of questions, or different lenses, for viewing a game’s design, encompassing diverse fields such as psychology, architecture, music, film, software engineering, theme park design, mathematics, anthropology, and more. Written by one of the world's top game designers, this book describes the deepest and most fundamental principles of game design, demonstrating how tactics used in board, card, and athletic games also work in video games. It provides practical instruction on creating world-class games that will be played again and again. View it here. A Practical Guide to Indie Game Marketing, by Joel Dreskin Marketing is an essential but too frequently overlooked or minimized component of the release plan for indie games. A Practical Guide to Indie Game Marketing provides you with the tools needed to build visibility and sell your indie games. With special focus on those developers with small budgets and limited staff and resources, this book is packed with tangible recommendations and techniques that you can put to use immediately. As a seasoned professional of the indie game arena, author Joel Dreskin gives you insight into practical, real-world experiences of marketing numerous successful games and also provides stories of the failures. View it here. An Architectural Approach to Level Design This is one of the first books to integrate architectural and spatial design theory with the field of level design. The book presents architectural techniques and theories for level designers to use in their own work. It connects architecture and level design in different ways that address the practical elements of how designers construct space and the experiential elements of how and why humans interact with this space. Throughout the text, readers learn skills for spatial layout, evoking emotion through gamespaces, and creating better levels through architectural theory. View it here. Learn more and download the ebook by clicking here. Did you know? GameDev.net and CRC Press also recently teamed up to bring GDNet+ Members up to a 20% discount on all CRC Press books. Learn more about this and other benefits here.
Sign in to follow this  
Followers 0
fread

sampling a depth cubemap FBO texture results in gl error

11 posts in this topic

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
0

Share this post


Link to post
Share on other sites

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
0

Share this post


Link to post
Share on other sites

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

Share this post


Link to post
Share on other sites

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.

 

 

 

0

Share this post


Link to post
Share on other sites

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
0

Share this post


Link to post
Share on other sites

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
2

Share this post


Link to post
Share on other sites

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
0

Share this post


Link to post
Share on other sites

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.

0

Share this post


Link to post
Share on other sites

Create an account or sign in to comment

You need to be a member in order to leave a comment

Create an account

Sign up for a new account in our community. It's easy!


Register a new account

Sign in

Already have an account? Sign in here.


Sign In Now
Sign in to follow this  
Followers 0