I’m trying to make a depth-mapped cube map but it doesn’t work well.
Here’s some part of code:
/* cube map setup part... */
glTexParameteri(GL_TEXTURE_CUBE_MAP_ARB, GL_TEXTURE_WRAP_S, GL_CLAMP_TO_EDGE_SGIS);
glTexParameteri(GL_TEXTURE_CUBE_MAP_ARB, GL_TEXTURE_WRAP_T, GL_CLAMP_TO_EDGE_SGIS);
glTexParameteri(GL_TEXTURE_CUBE_MAP_ARB, GL_TEXTURE_WRAP_R, GL_CLAMP_TO_EDGE_SGIS);
glTexParameteri(GL_TEXTURE_CUBE_MAP_ARB, GL_TEXTURE_MAG_FILTER, GL_LINEAR);
glTexParameteri(GL_TEXTURE_CUBE_MAP_ARB, GL_TEXTURE_MIN_FILTER, GL_LINEAR);
glTexEnvi(GL_TEXTURE_ENV, GL_TEXTURE_ENV_MODE, GL_MODULATE);
for (int face=0; face<6; face++)
glTexImage2D(g_RenderTarget[face], 0, GL_DEPTH_COMPONENT, CUBE_MAP_SIZE,
CUBE_MAP_SIZE, 0, GL_DEPTH_COMPONENT, GL_UNSIGNED_BYTE, NULL);
/* cube map generation part... */
glCopyTexSubImage2D(g_RenderTarget[face], 0, 0, 0, 0, 0, CUBE_MAP_SIZE, CUBE_MAP_SIZE);
I heard that GL_DEPTH_COMPONENT format is available for the GL_TEXTURE_CUBE_MAP_ARB,
but looks like both glTexImage2D() and glCopyTexSubImage2D don’t support it.
Anyone give me a hint please?
AFAIK that is not possible. GL_DEPTH_COMPONENT can only be used for 2D textures, because it uses the r-texture-coordinate for some comparison-stuff, which makes it impossible to use it with cubemaps (which need the r-component for texture-accesses).
Someone told me, the solution would be to use float-textures (cubemaps) and do the depth-comparison manually in a fragment program. However this is still a pain in the butt, since for rendering to float textures you need to use pbuffers, etc.
That´s the reason, why i didn´t do that yet, still waiting for the EXT_render_target extension to make my life easier.
Oh, GL_DEPTH_COMPONENT is only for 2D textures!?
And thx for your info.
Which is really kind of stupid, since the R coord stuff should be a part of the shadow extension, not the texture extension. Since the depth texture extension itself doesn’t do the actual compare.
I see nothing in the OpenGL 1.5 spec in either the section on TexImage2D (page 145 of the PDF) or the section on depth component textures (page 156 of the PDF) to indicate that depth textures cannot be used with cubic texturing. That said,
I have a couple questions.
[ul]Are any of the GL calls in your code generating an error (returned by glGetError)? Are you trying to use the cubic texture for shadow operations or normal texturing?What is the behavior you are seeing? “Doesn’t work well” is pretty vague. Have you tried querying the textures’s parameters to see what the internal format is (i.e., query GL_DEPTH_BITS)?[*]Are you sure the texture has non-zero data? You don’t say if the texture is copied from your depth buffer, read from disk, etc.[/ul]
Originally posted by idr:
I see nothing in the OpenGL 1.5 spec in either the section on TexImage2D (page 145 of the PDF) or the section on depth component textures (page 156 of the PDF) to indicate that depth textures cannot be used with cubic texturing.
(5) What about 1D, 3D and cube maps textures? Should depth textures
RESOLVED: For 1D textures, yes, for orthogonality. For 3D and cube map
textures, no. In both cases, the R coordinate that would be ordinarily
be used for a shadow comparison is needed for texture lookup and won't
contain a useful value. In theory, the shadow functionality could be
extended to provide useful behavior for such targets, but this
enhancement is left to a future extension.
From <a href=“http://oss.sgi.com/projects/ogl-sample/registry/ARB/depth_texture.txt” target=“_blank”>GL_ARB_depth_texture
Textures with a base internal format of DEPTH COMPONENT are supported by
texture image specification commands only if target is TEXTURE 1D, TEXTURE 2D,
PROXY TEXTURE 1D or PROXY TEXTURE 2D. Using this format in conjunction
with any other target will result in an INVALID OPERATION error.
(from OpenGL 1.5 spec, pg 127)
You were a minute too late (literaly)
Ah. So, then the calls to glTexImage2D should generate an INVALID_OPERATION error. The moral of that story is, if your code isn’t working, add calls to glGetError.