microsoft / angle

ANGLE: OpenGL ES to DirectX translation
Other
615 stars 166 forks source link

Using d3d11 shared handle in opengl results with black texture #141

Closed ChrisTanev closed 5 years ago

ChrisTanev commented 6 years ago

Just wanna start by saying that i am following your example https://github.com/Microsoft/angle/wiki/Interop-with-other-DirectX-code and i created eglSurface successfully - surface = eglCreatePbufferFromClientBuffer(egl_display, EGL_D3D_TEXTURE_2D_SHARE_HANDLE_ANGLE, reinterpret_cast<HANDLE>(handle), egl_config, pBufferAttributes);

Gen and bind a texture

    glGenTextures(1, &glTex);
    glBindTexture(GL_TEXTURE_2D, glTex);
    eglBindTexImage(mEglDisplay, surface, EGL_BACK_BUFFER);
    glTexParameteri(GL_TEXTURE_2D, GL_TEXTURE_MIN_FILTER, GL_NEAREST);
    glTexParameteri(GL_TEXTURE_2D, GL_TEXTURE_MAG_FILTER, GL_NEAREST);

Render

glBegin(GL_QUADS);   

    glTexCoord2d( srcX, srcY ); glVertex3d( -r.width/2, -r.height/2, 0);
    glTexCoord2d( srcW, srcY ); glVertex3d( r.width/2, -r.height/2, 0);
    glTexCoord2d( srcW, srcH); glVertex3d( r.width/2, r.height/2, 0);
    glTexCoord2d( srcX, srcH); glVertex3d( -r.width/2, r.height/2, 0);

glEnd()

The problem is that using shared handle always yields black texture result. Is there anything
that i'm missing ? I checked on your example EGLPresentPathD3D11Test.cpp , but it doesnt show any usage of eglBindTexImage(mEglDisplay, surface, EGL_BACK_BUFFER);

Also im a little confused with step # 4 from https://github.com/Microsoft/angle/wiki/Interop-with-other-DirectX-code - "Write your DirectX code to render onto 'd3dTex', and your GL code to use 'glTex'. " The only thing i need is to use the shared handle from d3d11 device(which has a texture , but doesnt need to render it , just share it) and render into gl with help of eglCreatePbufferFromClientBuffer.

Im not an EGL expert , but the example doesnt show how to do it in existing opengl context?

EDIT : How do i access the EGL_BACK_BUFFER from gl context ? eglBindTexImage(egl_display, surface, EGL_BACK_BUFFER);

austinkinross commented 6 years ago

Hi,

The problem is that using shared handle always yields black texture result.

Are you using D3D11 or GL to read back the contents of the texture?

If you want to access the texture (via the shared handle) in D3D11 code after performing GL rendering then you'll need to call glFlush() first. The texture will be uninitialized if you don't do this.

ChrisTanev commented 6 years ago

Hello @austinkinross and thanks for your response !

I would like to read the content of the share handle(the texture) in GL and use it in the already existing GL content to render it in scene. I create the texture in d3d11 and render to it , then get a shared handle and created l surface successfully - eglCreatePbufferFromClientBuffer(egl_display, EGL_D3D_TEXTURE_2D_SHARE_HANDLE_ANGLE, reinterpret_cast<HANDLE>(handle), egl_config, pBufferAttributes); , but i dont know how to get the pixels from it/render it to GL texture.

dforsten commented 5 years ago

I am running into the same issue following the example at https://github.com/Microsoft/angle/wiki/Interop-with-other-DirectX-code, the texture stays black on the OpenGL ES side.

austinkinross commented 5 years ago

Hi everyone, apologies for the delay here. If you are still having problems in this area (or have any other questions) then I suggest asking over on the master ANGLE project's mailing list: https://groups.google.com/forum/#!forum/angleproject

Thanks Austin