Remove GHOST API functions for OpenGL offscreen blitting soc-2019-openxr
authorJulian Eisel <eiseljulian@gmail.com>
Wed, 21 Aug 2019 18:36:40 +0000 (20:36 +0200)
committerJulian Eisel <eiseljulian@gmail.com>
Wed, 21 Aug 2019 18:36:40 +0000 (20:36 +0200)
These were previously used to blit from a offscreen (non-OpenGL)
context, into an onscreen one. We do this differently, and only within
GHOST_XrGraphicsBinding now, so this can be removed.

intern/ghost/GHOST_C-api.h
intern/ghost/GHOST_IContext.h
intern/ghost/GHOST_IWindow.h
intern/ghost/intern/GHOST_C-api.cpp
intern/ghost/intern/GHOST_Context.h
intern/ghost/intern/GHOST_ContextD3D.cpp
intern/ghost/intern/GHOST_ContextD3D.h
intern/ghost/intern/GHOST_Window.cpp
intern/ghost/intern/GHOST_Window.h
intern/ghost/intern/GHOST_XrGraphicsBinding.cpp

index 84bad87e654401bfbc3c8b8bad6972026ccb2e5b..03cf3a1c7a06673bff9d764e1053f1c8e1822c3d 100644 (file)
@@ -197,15 +197,6 @@ GHOST_TSuccess GHOST_DisposeDirectXContext(GHOST_SystemHandle systemhandle,
                                            GHOST_ContextHandle contexthandle);
 #endif
 
-GHOST_TSuccess GHOST_BlitOpenGLOffscreenContext(GHOST_WindowHandle windowhandle,
-                                                GHOST_ContextHandle offscreen_contexthandle);
-
-extern GHOST_TSuccess GHOST_ContextBlitOpenGLOffscreenContext(
-    GHOST_ContextHandle onscreen_contexthandle,
-    GHOST_ContextHandle offscreen_contexthandle,
-    GHOST_TInt32 width,
-    GHOST_TInt32 height);
-
 extern GHOST_ContextHandle GHOST_GetWindowContext(GHOST_WindowHandle windowhandle);
 
 /**
index 3bad8db115f0ef047ccffa671b4a5ad71d846bf5..d114df428b0372b553055149f129e2ddae000893 100644 (file)
@@ -56,10 +56,6 @@ class GHOST_IContext {
    */
   virtual GHOST_TSuccess releaseDrawingContext() = 0;
 
-  virtual GHOST_TSuccess blitOpenGLOffscreenContext(class GHOST_Context *offscreen,
-                                                    GHOST_TInt32 width,
-                                                    GHOST_TInt32 height) = 0;
-
   virtual unsigned int getDefaultFramebuffer() = 0;
 
   virtual GHOST_TSuccess swapBuffers() = 0;
index 212e7ff8d1386b77560e34bfb49596c8f29a33cb..547ae1d3ec3c9a29d3bc3c162a7cef1df8404883 100644 (file)
@@ -79,8 +79,6 @@ class GHOST_IWindow {
 
   virtual class GHOST_IContext *getDrawingContext() = 0;
 
-  virtual GHOST_TSuccess blitOpenGLOffscreenContext(GHOST_IContext *offscreen) = 0;
-
   /**
    * Sets the title displayed in the title bar.
    * \param title The title to display in the title bar.
index 778daf83d3270b445b05d554819a7d398caa7f7c..898378460c6f9f420e777fc26f1b72b09c1bd391 100644 (file)
@@ -150,25 +150,6 @@ GHOST_TSuccess GHOST_DisposeDirectXContext(GHOST_SystemHandle systemhandle,
 
 #endif
 
-GHOST_TSuccess GHOST_BlitOpenGLOffscreenContext(GHOST_WindowHandle windowhandle,
-                                                GHOST_ContextHandle offscreen_contexthandle)
-{
-  GHOST_IWindow *window = (GHOST_IWindow *)windowhandle;
-
-  return window->blitOpenGLOffscreenContext((GHOST_IContext *)offscreen_contexthandle);
-}
-
-GHOST_TSuccess GHOST_ContextBlitOpenGLOffscreenContext(GHOST_ContextHandle onscreen_contexthandle,
-                                                       GHOST_ContextHandle offscreen_contexthandle,
-                                                       GHOST_TInt32 width,
-                                                       GHOST_TInt32 height)
-{
-  GHOST_IContext *context = (GHOST_IContext *)onscreen_contexthandle;
-
-  return context->blitOpenGLOffscreenContext(
-      (class GHOST_Context *)offscreen_contexthandle, width, height);
-}
-
 GHOST_ContextHandle GHOST_GetWindowContext(GHOST_WindowHandle windowhandle)
 {
   GHOST_IWindow *window = (GHOST_IWindow *)windowhandle;
index 0bc2aa21119295be913ad34500f28d9b770bef75..af801112bdac36c6d938a0851fa8915761724e00 100644 (file)
@@ -146,9 +146,9 @@ class GHOST_Context : public GHOST_IContext {
     return GHOST_kFailure;
   }
 
-  GHOST_TSuccess blitOpenGLOffscreenContext(GHOST_Context *offscreen,
-                                            GHOST_TInt32 width,
-                                            GHOST_TInt32 height);
+  virtual GHOST_TSuccess blitOpenGLOffscreenContext(GHOST_Context *offscreen,
+                                                    GHOST_TInt32 width,
+                                                    GHOST_TInt32 height);
 
  protected:
   void initContextGLEW();
index f5fc36a483181ed59304f8bdca981eeb77c622d5..e9253216d9ac9a5c8af59b23a800ade30870445d 100644 (file)
@@ -210,29 +210,19 @@ GHOST_TSuccess GHOST_ContextD3D::releaseNativeHandles()
   return GHOST_kFailure;
 }
 
-GHOST_TSuccess GHOST_ContextD3D::blitOpenGLOffscreenContext(GHOST_Context *offscreen_ctx,
-                                                            ID3D11RenderTargetView *render_target,
-                                                            GHOST_TInt32 width,
-                                                            GHOST_TInt32 height)
-{
-  GHOST_SharedOpenGLResource *shared_res = createSharedOpenGLResource(
-      width, height, render_target);
-
-  if (shared_res) {
-    GHOST_TSuccess ret = blitFromOpenGLContext(shared_res, width, height);
-    disposeSharedOpenGLResource(shared_res);
-    return ret;
-  }
-
-  return GHOST_kFailure;
-}
-
-GHOST_TSuccess GHOST_ContextD3D::blitOpenGLOffscreenContext(GHOST_Context *offscreen_ctx,
+GHOST_TSuccess GHOST_ContextD3D::blitOpenGLOffscreenContext(GHOST_Context * /*offscreen_ctx*/,
                                                             GHOST_TInt32 width,
                                                             GHOST_TInt32 height)
 {
   if (updateSwapchain(width, height) == GHOST_kSuccess) {
-    return blitOpenGLOffscreenContext(offscreen_ctx, m_backbuffer_view, width, height);
+    GHOST_SharedOpenGLResource *shared_res = createSharedOpenGLResource(
+        width, height, m_backbuffer_view);
+
+    if (shared_res) {
+      GHOST_TSuccess ret = blitFromOpenGLContext(shared_res, width, height);
+      disposeSharedOpenGLResource(shared_res);
+      return ret;
+    }
   }
 
   return GHOST_kFailure;
@@ -274,11 +264,12 @@ class GHOST_SharedOpenGLResource {
       renderTargetViewDesc.ViewDimension = D3D11_RTV_DIMENSION_TEXTURE2D;
       renderTargetViewDesc.Texture2D.MipSlice = 0;
 
-      device->CreateRenderTargetView(tex, &renderTargetViewDesc, &m_render_target);
+      device->CreateRenderTargetView(tex, &renderTargetViewDesc, &render_target);
 
       tex->Release();
     }
 
+    m_render_target = render_target;
     m_render_target->GetResource(&backbuffer_res);
     backbuffer_res->QueryInterface<ID3D11Texture2D>(&m_render_target_tex);
     backbuffer_res->Release();
index ed3e0331f17c1663b7475f8f33c394782d68b157..d282d3978ed847e9613ffb6ff939bb02df3d65b2 100644 (file)
@@ -111,10 +111,6 @@ class GHOST_ContextD3D : public GHOST_Context {
   GHOST_TSuccess blitOpenGLOffscreenContext(GHOST_Context *offscreen_ctx,
                                             GHOST_TInt32 width,
                                             GHOST_TInt32 height);
-  GHOST_TSuccess blitOpenGLOffscreenContext(GHOST_Context *offscreen_ctx,
-                                            ID3D11RenderTargetView *render_target,
-                                            GHOST_TInt32 width,
-                                            GHOST_TInt32 height);
 
   class GHOST_SharedOpenGLResource *createSharedOpenGLResource(
       unsigned int width, unsigned int height, ID3D11RenderTargetView *render_target);
index e639562f96e92ee13ebf54b94b9966777ca5aa7c..cc4f871ea265d78e446bc88e4f218d9c54a0ed33 100644 (file)
@@ -114,16 +114,6 @@ unsigned int GHOST_Window::getDefaultFramebuffer()
   return (m_context) ? m_context->getDefaultFramebuffer() : 0;
 }
 
-GHOST_TSuccess GHOST_Window::blitOpenGLOffscreenContext(GHOST_IContext *offscreen_ctx)
-{
-  GHOST_Rect rect;
-
-  getWindowBounds(rect);
-
-  return m_context->blitOpenGLOffscreenContext(
-      (GHOST_Context *)offscreen_ctx, rect.getWidth(), rect.getHeight());
-}
-
 bool GHOST_Window::isUpsideDown() const
 {
   return m_context->isUpsideDown();
index 64515d9e5eeac1bd8d1f616e4167aacbf8cd4997..59784abbae3a403927fb361e028acc736756cc32 100644 (file)
@@ -266,8 +266,6 @@ class GHOST_Window : public GHOST_IWindow {
    */
   virtual unsigned int getDefaultFramebuffer();
 
-  virtual GHOST_TSuccess blitOpenGLOffscreenContext(class GHOST_IContext *offscreen_ctx);
-
   /**
    * Returns the window user data.
    * \return The window user data.
index 194f33fcccc9ab21525afd547881aaf4a2935218..2732af49c129f33fae022788cac0a74da9a19070 100644 (file)
@@ -258,23 +258,25 @@ class GHOST_XrGraphicsBindingD3D : public GHOST_IXrGraphicsBinding {
         swapchain_image);
 
     ogl_ctx->activateDrawingContext();
+    ogl_ctx->setDefaultFramebufferSize(draw_info->width, draw_info->height);
 
 #  if 0
     /* Ideally we'd just create a render target view for the OpenXR swapchain image texture and
      * blit from the OpenGL context into it. The NV_DX_interop extension doesn't want to work with
      * this though. At least not with Optimus hardware. See:
      * https://github.com/mpv-player/mpv/issues/2949#issuecomment-197262807.
-     * Note: Even if this worked, the blitting code only supports one shared resource by now, we'd
-     * need at least two (for each eye). We could also entirely re-register shared resources all
-     * the time. Also, the runtime might recreate the swapchain image so the shared resource would
-     * have to be re-registered then as well. */
+     */
 
     ID3D11RenderTargetView *rtv;
     CD3D11_RENDER_TARGET_VIEW_DESC rtv_desc(D3D11_RTV_DIMENSION_TEXTURE2D,
                                             DXGI_FORMAT_R8G8B8A8_UNORM);
 
     m_ghost_ctx->m_device->CreateRenderTargetView(d3d_swapchain_image->texture, &rtv_desc, &rtv);
-    m_ghost_ctx->blitOpenGLOffscreenContext(ogl_ctx, rtv, draw_info->width, draw_info->height);
+    if (!m_shared_resource) {
+      m_shared_resource = m_ghost_ctx->createSharedOpenGLResource(
+          draw_info->width, draw_info->height, rtv);
+    }
+    m_ghost_ctx->blitFromOpenGLContext(m_shared_resource, draw_info->width, draw_info->height);
 #  else
     if (!m_shared_resource) {
       m_shared_resource = m_ghost_ctx->createSharedOpenGLResource(draw_info->width,