So I'm trying to create a Multisampled depth texture and I'm seeing some oddities.
First off, this GLES2-like call works :
glTexImage2D( GL_TEXTURE_2D, 0, GL_DEPTH_COMPONENT, Width, Height, 0, GL_DEPTH_COMPONENT, GL_UNSIGNED_SHORT, NULL );
But then I can't use it for the multisampled texture :
glTexStorage2DMultisample( GL_TEXTURE_2D_MULTISAMPLE, 4, GL_DEPTH_COMPONENT, Width, Height, GL_TRUE );
It throws GL_INVALID_ENUM and reading the docs it can only be from texture target which is ok so the next wrong thing is GL_DEPTH_COMPONENT .
Then I tried creating GL_DEPTH_COMPONENT16,24 and 32 textures
glTexImage2D( GL_TEXTURE_2D, 0, GL_DEPTH_COMPONENT16, Width, Height, 0, GL_DEPTH_COMPONENT, GL_UNSIGNED_SHORT, NULL );
glTexImage2D( GL_TEXTURE_2D, 0, GL_DEPTH_COMPONENT24, Width, Height, 0, GL_DEPTH_COMPONENT, GL_UNSIGNED_INT, NULL );
glTexImage2D( GL_TEXTURE_2D, 0, GL_DEPTH_COMPONENT32F, Width, Height, 0, GL_DEPTH_COMPONENT, GL_FLOAT, NULL );
And while they all work I don't see my depth buffer based effects like depth of field so I can only assume the values are either not being saved (all 0s) or the format is wrong, like I would need an integer sampler. I am expecting in these scenarios to use a standard sampler2D and get a .r-only texture with values from 0..1 . I have the exact same issue with Qualcomm's Adreno 320, but I don't have it with Apple's A7 GPU or my AMD R9 280X.
Am I doing something wrong ?
I've implemented the GL_KHR_debug extension as follows :
PFNGLDEBUGMESSAGECALLBACKPROC glDebugMessageCallback = (PFNGLDEBUGMESSAGECALLBACKPROC)eglGetProcAddress("glDebugMessageCallback");
PFNGLDEBUGMESSAGECONTROLPROC glDebugMessageControl = (PFNGLDEBUGMESSAGECONTROLPROC)eglGetProcAddress("glDebugMessageControl");
if ( glDebugMessageCallback != NULL && glDebugMessageControl != NULL )
{
glEnable( GL_DEBUG_OUTPUT );
glDebugMessageCallback( &GLDebugCallback, NULL );
glDebugMessageControl( GL_DONT_CARE, GL_DONT_CARE, GL_DONT_CARE, 0, NULL, GL_TRUE );
glEnable( GL_DEBUG_OUTPUT_SYNCHRONOUS );
}
I'm now being told
12-13 14:37:40.628: I/com.re3.benchmark(20517): GLDebugCallback Source=OpenGL Type=Error Severity=high ID=33350 Message=Error:glTexStorage2DMultisample::<internalformat> is not an accepted value
Just as I already figured. Interestingly enough, my other issues is now gone, as in it doesn't throw GL_OUT_OF_MEMORY but some objects are still rendered incorrectly. I'm thinking to dump the depth buffer to a file and see what values it has since I don't see my effects correctly. I was thinking though that perhaps the depth buffer is saved in -1..1 for DEPTH24/32 instead of 0..1 like I'm expecting it, or maybe the 32 bit value is spread throughout the RGBA8 components needing to basically fetch the Pixel.rgba and somehow make a float value out of the 4 sub-values ?
EDIT : It seems like glReadPixels doesn't work for GL_DEPTH_COMPONENT at least on GLES 3.1 so I can't get the depth buffer to actually look at the values. I'm left to just visual debugging and trying to figure out what kind of values it has...
EDIT2 : I just made a debug shader and can confirm that the r,g,b components are 0 while a = 1 (for a DEPTH32F texture with GL_FLOAT ). I also tried doing pixel = pow(pixel,5) to see if there's anything else besides white on alpha, doesn't look like there's anything.
So, after these edits, where are you now at?
Have you successfully bound the buffer but can't write into it?
Or is it drawing to them without error but simply showing nothing in the associated texture?
Just trying to figure out what the next step is.
-Stacy
I can bind the depth buffer to be used in a framebuffer, the color buffer looks ok as in depth testing/writting is performed but accessing the buffer as a texture in a fragment shader results in black being returned.
> EDIT : It seems like glReadPixels doesn't work for GL_DEPTH_COMPONENT at least on GLES 3.1 so I can't get the depth buffer to actually look at the values. I'm left to just visual debugging and trying to figure out what kind of values it has...
Correct - glReadPixels only works for color buffers. You can always write a shader which dumps the depth value out to an RGBA target.
> EDIT2 : I just made a debug shader and can confirm that the r,g,b components are 0 while a = 1 (for a DEPTH32F texture with GL_FLOAT ). I also tried doing pixel = pow(pixel,5) to see if there's anything else besides white on alpha, doesn't look like there's anything.
Only the r component should contain anything in a depth texture, as it is a single channel format.
> DEPTH24/32 instead of 0..1 like I'm expecting it, or maybe the 32 bit value is spread throughout the RGBA8 components needing to basically fetch the Pixel.rgba and somehow make a float value out of the 4 sub-values ?
Depth stores between 0 and 1, but it isn't a linear spread of bits; it's stored in a logarithmic-type scale. Most values will be close to 1 because of this. Also remember that depth generally is a 24-bit format (for a normal D24/S8 buffer), so you'll need to load into a highp variable if you want to avoid losing precision.
There are plenty of examples of the web explaining how to linearize a depth value if you want a linear representation.