Is it possible to use EGL and ANGLE to render a DirectX 2D Texture on a HTML5 Canvas in Chrome?

96 Views Asked by At

I'm having truouble,here is a ready directx 2D texture handle,I want show the texture into html5 element(canvas?video?...chromium kernel).I learned WEBGL、ANGLE、EGL from ANGLE souce code:https://github.com/google/angle/blob/main/src/tests/egl_tests/EGLPresentPathD3D11Test.cpp

but i didn't meet my expectations. Is there a method for rending directx 2D Texture into html page? Thanks!

//Js webglrendingcontex
var canvas = document.querySelector("#maincanvas");
gl = canvas.getContext("webgl");

// The following code exists in C++ node extension
// Set up EGL Display
EGLint displayAttribs[] = {
    EGL_PLATFORM_ANGLE_TYPE_ANGLE,
    EGL_PLATFORM_ANGLE_TYPE_D3D11_ANGLE,
    EGL_PLATFORM_ANGLE_MAX_VERSION_MAJOR_ANGLE,
    -1,
    EGL_PLATFORM_ANGLE_MAX_VERSION_MAJOR_ANGLE,
    -1,
    EGL_EXPERIMENTAL_PRESENT_PATH_ANGLE,
    EGL_EXPERIMENTAL_PRESENT_PATH_FAST_ANGLE,
    EGL_NONE };

  egl_display_ = eglGetPlatformDisplayEXT(
    EGL_PLATFORM_ANGLE_ANGLE,
    EGL_DEFAULT_DISPLAY,
    displayAttribs);

  if (egl_display_ == EGL_NO_DISPLAY) {
    return;
  }

  EGLBoolean ret = eglInitialize(egl_display_, nullptr, nullptr);
  if (!ret) {
    return;
  }

 // Choose the EGL config
  EGLint numConfigs;
  EGLint configAttribs[] = {
      EGL_RED_SIZE, 8,
      EGL_GREEN_SIZE, 8,
      EGL_BLUE_SIZE, 8,
      EGL_ALPHA_SIZE, 8,
      EGL_CONFIG_ID, 26,
      EGL_RENDERABLE_TYPE,
      EGL_OPENGL_ES2_BIT,
      EGL_SURFACE_TYPE,
      EGL_PBUFFER_BIT,
      EGL_NONE };

  ret = eglChooseConfig(egl_display_, configAttribs, &mConfig, 1, &numConfigs);
  if (!ret) {
  }
  if (numConfigs < 1) {
    return;
  }

EGLSurface egl_surface_ = eglCreatePbufferFromClientBuffer(
    egl_display_,
    EGL_D3D_TEXTURE_2D_SHARE_HANDLE_ANGLE,
    (EGLClientBuffer)share_handle,
    mConfig,
    pBufferAttributes);
  if (egl_surface_ == EGL_NO_SURFACE) {
    EGLint err = eglGetError();
    return;
  }

EGLint contextAttribs[] = {
  EGL_CONTEXT_CLIENT_VERSION,
  2,
  EGL_NONE };
  egl_context_ = eglCreateContext(egl_display_, mConfig, nullptr, contextAttribs);
  if (egl_context_ == EGL_NO_CONTEXT) {
    EGLint err = eglGetError();
    return;
  }
  // egl_context_??? canvas webglrendingcontext???
  EGLBoolean ret = eglMakeCurrent(egl_display_, egl_surface_, egl_surface_, egl_context_);
  if (!ret) {
    EGLint err = eglGetError();
  }

I successfully create EGLSurface from directx 2D texture share handle(share_handle),but how can I render the egl_surface_ to canvas?

0

There are 0 best solutions below