OSX Framebuffer Depth Attachments

This topic contains 6 replies, has 2 voices, and was last updated by  ROm 3 years, 1 month ago.

Viewing 7 posts - 1 through 7 (of 7 total)
  • Author
    Posts
  • #31854

    ROm
    Member

    In earlier version of the simulator (on OSX ES2) the FBO depth attachments were as expected black and white, in the latest version they look like this:

    Am I missing something or? What explains the reddish in both 16bits and 24bits mode?

    TIA!

    #39079

    chris
    Moderator

    Hi ROm

    That’s interesting! I will file a bug against this issue and try to reproduce it here. Can I ask what method you are using to render the depth buffers?

    #39080

    ROm
    Member
    	GLuint texture_id = 0;

    glGenTexture( &texture_id );

    glBindTexture( GL_TEXTURE_2D, texture_id );

    /* Same problem with internal format=GL_DEPTH_COMPONENT16 or GL_DEPTH_COMPONENT24
    and also when format and internal format is set to GL_DEPTH_STENCIL and type=GL_UNSIGNED_INT_24_8.
    The bug seems to affect all depth texture regardless of the type that is initialized POT and NPOT. */
    GLint internal_format = GL_DEPTH_COMPONENT;

    GLenum format = GL_DEPTH_COMPONENT,
    type;

    if( GL.extension.version == 20 && // ES 2.0 with depth texture extension
    GL.extension.depth_texture )
    {
    internal_format =
    format = GL_DEPTH_COMPONENT;
    }
    else if( Gfx.extension.version > 20 ) // ES 3.x
    {
    internal_format = ( flags & is16bits ) ?
    GL_DEPTH_COMPONENT16:
    GL_DEPTH_COMPONENT24;

    format = GL_DEPTH_COMPONENT;
    }

    type = !( flags & is16bits ) ?
    GL_UNSIGNED_INT :
    GL_UNSIGNED_SHORT;

    glTexImage2D( GL_TEXTURE_2D,
    0,
    internal_format,
    256,
    128,
    0,
    format,
    type,
    NULL );

    GLuint framebuffer_id = 0;

    glGenFramebuffer( &framebuffer_id );

    glBindFramebuffer( framebuffer_id );

    glFramebufferTexture2D( GL_FRAMEBUFFER,
    GL_DEPTH_ATTACHMENT,
    GL_TEXTURE_2D,
    texture_id,
    0 );
    #39081

    chris
    Moderator

    Hi ROm

    How are you rendering the resulting depth texture to the screen? In a fragment shader I believe the values are placed only in the red channel, so for a black and white image you need to do something like:


    uniform sampler2D tex;
    in highp vec2 texture_coords;
    out highp vec4 color;

    void main()
    {
    color = texture(tex, texture_coords);
    color = vec4(color.r, color.r, color.r, 1.0);
    }

    At this stage I am not sure what has changed in the emulator as I can’t reproduce the black-and-white behaviour in the previous version without explicitly reading from only the red channel as above, but perhaps my test is too simple.

    #39082

    ROm
    Member

    I believe that is because in OpenGL 3.x GL_LUMINANCE is removed, and they are now storing the depth value as GL_RED. I thought the emulator would still support the format/internal format in order to be compliant with GLES3.

    #39083

    chris
    Moderator

    Ah, I didn’t realise that this behaviour is dependent on the version of ES. In ES 2.0 the depth value should be stored in only GL_RED, whereas in ES 3.x it’s stored in RGB.

    At the moment the emulator always uses the ES 2.0 behaviour, which should be easy to fix. In the meantime as a workaround you could apply your own texture swizzle to get the value into all three channels.

    #39084

    ROm
    Member

    If this the case GL_ALPHA, GL_LUMINANCE and GL_LUMINANCE_ALPHA will also cause problem in the simulator… In order to be more compatible with a real GLES3 context maybe add in the emulator code theses swizzle:

    [ GL_ALPHA -> GL_R ]

    GfxTexParameteri( target, GL_TEXTURE_SWIZZLE_R, GL_ZERO );
    GfxTexParameteri( target, GL_TEXTURE_SWIZZLE_G, GL_ZERO );
    GfxTexParameteri( target, GL_TEXTURE_SWIZZLE_B, GL_ZERO );
    GfxTexParameteri( target, GL_TEXTURE_SWIZZLE_A, GL_RED );

    [ GL_LUMINANCE -> GL_R ]

    GfxTexParameteri( target, GL_TEXTURE_SWIZZLE_R, GL_RED );
    GfxTexParameteri( target, GL_TEXTURE_SWIZZLE_G, GL_RED );
    GfxTexParameteri( target, GL_TEXTURE_SWIZZLE_B, GL_RED );
    GfxTexParameteri( target, GL_TEXTURE_SWIZZLE_A, GL_ONE );

    [ GL_LUMINANCE_ALPHA -> GL_RG ]

    GfxTexParameteri( target, GL_TEXTURE_SWIZZLE_R, GL_RED );
    GfxTexParameteri( target, GL_TEXTURE_SWIZZLE_G, GL_RED );
    GfxTexParameteri( target, GL_TEXTURE_SWIZZLE_B, GL_RED );
    GfxTexParameteri( target, GL_TEXTURE_SWIZZLE_A, GL_GREEN );

    [ GL_DEPTH_COMPONENT / GL_DEPTH_COMPONENT16 / GL_DEPTH_COMPONENT24 / GL_DEPTH_STENCIL ]

    GfxTexParameteri( target, GL_TEXTURE_SWIZZLE_R, GL_RED );
    GfxTexParameteri( target, GL_TEXTURE_SWIZZLE_G, GL_RED );
    GfxTexParameteri( target, GL_TEXTURE_SWIZZLE_B, GL_RED );
    GfxTexParameteri( target, GL_TEXTURE_SWIZZLE_A, GL_ONE );

Viewing 7 posts - 1 through 7 (of 7 total)
You must be logged in to reply to this topic.