Module: Mesa
Branch: main
Commit: 0f533b3640e97da51357d6844846786c9a9d4850
URL:    
http://cgit.freedesktop.org/mesa/mesa/commit/?id=0f533b3640e97da51357d6844846786c9a9d4850

Author: Jesse Natalie <[email protected]>
Date:   Fri Sep 17 18:54:19 2021 -0700

egl/wgl: Implement bind/release texture buffer

Acked-by: Daniel Stone <[email protected]>
Acked-by: Mike Blumenkrantz <[email protected]>
Acked-by: Sidney Just <[email protected]>
Acked-by: Jason Ekstrand <[email protected]>
Tested-by: Yonggang Luo <[email protected]>
Part-of: <https://gitlab.freedesktop.org/mesa/mesa/-/merge_requests/12964>

---

 src/egl/drivers/wgl/egl_wgl.c              | 58 ++++++++++++++++++++++++++++++
 src/gallium/targets/wgl/gallium_wgl.def.in |  1 +
 2 files changed, 59 insertions(+)

diff --git a/src/egl/drivers/wgl/egl_wgl.c b/src/egl/drivers/wgl/egl_wgl.c
index a6f938fbcb7..d6832fe7a1a 100644
--- a/src/egl/drivers/wgl/egl_wgl.c
+++ b/src/egl/drivers/wgl/egl_wgl.c
@@ -37,6 +37,7 @@
 #include <GL/wglext.h>
 
 #include <pipe/p_screen.h>
+#include <pipe/p_state.h>
 
 #include <mapi/glapi/glapi.h>
 
@@ -742,6 +743,61 @@ wgl_query_surface(_EGLDisplay *disp, _EGLSurface *surf,
    return _eglQuerySurface(disp, surf, attribute, value);
 }
 
+static EGLBoolean
+wgl_bind_tex_image(_EGLDisplay *disp, _EGLSurface *surf, EGLint buffer)
+{
+   struct wgl_egl_surface *wgl_surf = wgl_egl_surface(surf);
+   enum st_attachment_type target = ST_TEXTURE_2D;
+
+   _EGLContext *ctx = _eglGetCurrentContext();
+   struct wgl_egl_context *wgl_ctx = wgl_egl_context(ctx);
+
+   if (!_eglBindTexImage(disp, surf, buffer))
+      return EGL_FALSE;
+
+   struct pipe_resource *pres = 
stw_get_framebuffer_resource(wgl_surf->fb->stfb, ST_ATTACHMENT_FRONT_LEFT);
+   enum pipe_format format = pres->format;
+
+   switch (surf->TextureFormat) {
+   case EGL_TEXTURE_RGB:
+      switch (format) {
+      case PIPE_FORMAT_R16G16B16A16_FLOAT:
+         format = PIPE_FORMAT_R16G16B16X16_FLOAT;
+         break;
+      case PIPE_FORMAT_B10G10R10A2_UNORM:
+         format = PIPE_FORMAT_B10G10R10X2_UNORM;
+         break;
+      case PIPE_FORMAT_R10G10B10A2_UNORM:
+         format = PIPE_FORMAT_R10G10B10X2_UNORM;
+         break;
+      case PIPE_FORMAT_BGRA8888_UNORM:
+         format = PIPE_FORMAT_BGRX8888_UNORM;
+         break;
+      case PIPE_FORMAT_ARGB8888_UNORM:
+         format = PIPE_FORMAT_XRGB8888_UNORM;
+         break;
+      default:
+         break;
+      }
+      break;
+   case EGL_TEXTURE_RGBA:
+      break;
+   default:
+      assert(!"Unexpected texture format in wgl_bind_tex_image()");
+   }
+
+   switch (surf->TextureTarget) {
+   case EGL_TEXTURE_2D:
+      break;
+   default:
+      assert(!"Unexpected texture target in wgl_bind_tex_image()");
+   }
+
+   wgl_ctx->ctx->st->teximage(wgl_ctx->ctx->st, target, 0, format, pres, 
false);
+
+   return EGL_TRUE;
+}
+
 static EGLBoolean
 wgl_swap_buffers(_EGLDisplay *disp, _EGLSurface *draw)
 {
@@ -766,6 +822,8 @@ struct _egl_driver _eglDriver = {
    .CreatePbufferSurface = wgl_create_pbuffer_surface,
    .DestroySurface = wgl_destroy_surface,
    .QuerySurface = wgl_query_surface,
+   .BindTexImage = wgl_bind_tex_image,
+   .ReleaseTexImage = _eglReleaseTexImage,
    .GetProcAddress = _glapi_get_proc_address,
    .SwapBuffers = wgl_swap_buffers,
 };
diff --git a/src/gallium/targets/wgl/gallium_wgl.def.in 
b/src/gallium/targets/wgl/gallium_wgl.def.in
index 109016b4cc7..49e0963f727 100644
--- a/src/gallium/targets/wgl/gallium_wgl.def.in
+++ b/src/gallium/targets/wgl/gallium_wgl.def.in
@@ -37,4 +37,5 @@ stw_framebuffer_create
 stw_framebuffer_release_locked
 stw_framebuffer_unlock
 stw_framebuffer_swap_locked
+stw_get_framebuffer_resource
 stw_pbuffer_create

Reply via email to