Color Cube Map No Depth Test

Hello,

I recently decided to switch my point lights from using PCF to VSM. So, I now need a color cube map instead of just a depth cube map. I create the FBO like so:


{
#ifdef DEBUG
    int result;
    glGetIntegerv(GL_MAX_TEXTURE_SIZE, &result);
    size_t uResult = static_cast<unsigned>(result);
    assert(resolution > 0 && resolution <= uResult);
#endif


    m_resolution = resolution;


    glGenTextures(1, &m_cubeMapID);


    glBindTexture(GL_TEXTURE_CUBE_MAP, m_cubeMapID);
    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);
    glTexParameteri(GL_TEXTURE_CUBE_MAP, GL_TEXTURE_MAG_FILTER, GL_LINEAR);
    glTexParameteri(GL_TEXTURE_CUBE_MAP, GL_TEXTURE_MIN_FILTER, GL_LINEAR);


    glGenFramebuffers(1, &m_fboID);
    glBindFramebuffer(GL_FRAMEBUFFER, m_fboID);


    // Create all faces
    for(unsigned int i = 0; i < 6; i++)
        glTexImage2D(GL_TEXTURE_CUBE_MAP_POSITIVE_X + i, 0, internalFormat, m_resolution, m_resolution, 0, textureFormat, dataType, NULL);
        
    glBindTexture(GL_TEXTURE_CUBE_MAP, 0);


    // Render buffer creation for depth buffer
    glGenRenderbuffers(1, &m_depthID);
    glBindRenderbuffer(GL_RENDERBUFFER, m_depthID);
    glRenderbufferStorage(GL_RENDERBUFFER, GL_DEPTH_COMPONENT, m_resolution, m_resolution);
    glFramebufferRenderbuffer(GL_FRAMEBUFFER, GL_DEPTH_ATTACHMENT, GL_RENDERBUFFER, m_depthID);


    // Check that the buffer was properly created
#ifdef DEBUG
    if(glCheckFramebufferStatus(GL_FRAMEBUFFER) != GL_FRAMEBUFFER_COMPLETE)
        std::cerr << "Could not create cube map FBO!" << std::endl;
#endif


    // Unbind
    glBindRenderbuffer(GL_RENDERBUFFER, 0);
    glBindFramebuffer(GL_FRAMEBUFFER, 0);

However, I can’t seem to get the depth test to work anymore. I made sure that glDepthMask, glDepthFunc, and GL_DEPTH_TEST where all properly set. Geometry is rendering out of order!
What am I doing wrong?

Thank you for any help you can offer!

Where are you attaching your color attachment to FBO?
Also, if problem is related to only depth test, post your full code where you are making glDepth calls…

exactly. glFramebufferTexture should do it.


    // Create all faces
    for(unsigned int i = 0; i < 6; i++)
    {
        glTexImage2D(GL_TEXTURE_CUBE_MAP_POSITIVE_X + i, 0, internalFormat, m_resolution, m_resolution, 0, textureFormat, dataType, NULL);
        glFrameBufferTexture2D(GL_FRAMEBUFFER, GL_COLOR_ATTACHMENT + i, GL_TEXTURE_CUBE_MAP_POSITIVE_X + i, m_cubeMapID, 0);
    }

,

I attach it when I render, like so:


glBindFramebuffer(GL_FRAMEBUFFER, m_fboID);


	// Same projection every time
	glMatrixMode(GL_PROJECTION);
	Matrix4x4f::PerspectiveMatrix(pif_over_2, 1.0f, zNear, zFar).GL_Load();
	glMatrixMode(GL_MODELVIEW);


	SetViewport();


	// Temporarily move the camera
	Vec3f oldPosition(pScene->m_camera.m_position);


	pScene->m_camera.m_position = position;


	for(unsigned int i = 0; i < 6; i++)
	{	
		Matrix4x4f viewMatrix(m_baseViews[i] * Matrix4x4f::TranslateMatrix(-position));
		pScene->SetCustomViewMatrix(viewMatrix);
		
		pScene->ExtractFrustum(Matrix4x4f::GL_Get_Projection() * viewMatrix);


		pScene->SetWorldMatrix(Matrix4x4f::IdentityMatrix());


		glFramebufferTexture2D(GL_FRAMEBUFFER, GL_COLOR_ATTACHMENT0, GL_TEXTURE_CUBE_MAP_POSITIVE_X + i, m_cubeMapID, 0);


		glClear(GL_COLOR_BUFFER_BIT | GL_DEPTH_BUFFER_BIT);


		pScene->Render_Distance(distance);
	}


	// Revert
	pScene->m_camera.m_position = oldPosition;


	// Reset projection
	pScene->m_pWin->SetViewport();
	pScene->m_pWin->SetPerspective();


	// Reset view matrix
	pScene->SetWorldMatrix(Matrix4x4f::IdentityMatrix());


	glBindFramebuffer(GL_FRAMEBUFFER, 0);

What do you mean by out of order? You can’t see anything rendered or what?
Also in your last post, i cant see


 glBindRenderbuffer(GL_RENDERBUFFER, m_depthID);

call.

For depth test generally i use these calls,


				glEnable(GL_DEPTH_TEST);
				
				glDepthFunc(GL_LEQUAL); 					
			
				glClearDepth(1.0f);
		
				glClear(GL_DEPTH_BUFFER_BIT);

AFAIK, you don’t have to bind the render buffer when rendering. I never bind it for 2D FBO’s, and it works there.
With out of order, I mean that the shadow maps show objects through walls (their shadows are on walls).

Bumping…

NVM, I figured it out. It was a really stupid mistake. The Render_Distance function improperly culled away objects with large AABB radii. Thanks for the help anyways though!