[Bf-blender-cvs] [e4fcf25fc5e] soc-2019-openxr: Don't use Microsoft::WRL::ComPtr<...> for COM types

Julian Eisel noreply at git.blender.org
Thu Jun 27 19:22:24 CEST 2019


Commit: e4fcf25fc5ee92ca33b69063eb9c945fa41f2d45
Author: Julian Eisel
Date:   Thu Jun 27 18:56:20 2019 +0200
Branches: soc-2019-openxr
https://developer.blender.org/rBe4fcf25fc5ee92ca33b69063eb9c945fa41f2d45

Don't use Microsoft::WRL::ComPtr<...> for COM types

Makes things difficult if you're not familar with COM.

===================================================================

M	intern/ghost/intern/GHOST_ContextD3D.cpp
M	intern/ghost/intern/GHOST_ContextD3D.h
M	intern/ghost/intern/GHOST_XRGraphicsBinding.cpp

===================================================================

diff --git a/intern/ghost/intern/GHOST_ContextD3D.cpp b/intern/ghost/intern/GHOST_ContextD3D.cpp
index 6a617824856..b6c2a402e5f 100644
--- a/intern/ghost/intern/GHOST_ContextD3D.cpp
+++ b/intern/ghost/intern/GHOST_ContextD3D.cpp
@@ -71,7 +71,7 @@ class SharedOpenGLContext {
 
     m_wgl_ctx->activateDrawingContext();
 
-    m_shared.device = wglDXOpenDeviceNV(m_d3d_ctx->m_device.Get());
+    m_shared.device = wglDXOpenDeviceNV(m_d3d_ctx->m_device);
     if (m_shared.device == NULL) {
       fprintf(stderr, "Error opening shared device using wglDXOpenDeviceNV()\n");
       return GHOST_kFailure;
@@ -122,6 +122,10 @@ GHOST_ContextD3D::GHOST_ContextD3D(bool stereoVisual, HWND hWnd)
 GHOST_ContextD3D::~GHOST_ContextD3D()
 {
   delete glshared;
+  m_swapchain->Release();
+  m_backbuffer_view->Release();
+  m_device->Release();
+  m_device_ctx->Release();
 }
 
 GHOST_TSuccess GHOST_ContextD3D::swapBuffers()
@@ -198,10 +202,11 @@ GHOST_TSuccess GHOST_ContextD3D::initializeDrawingContext()
                                                    &m_device_ctx);
   WIN32_CHK(hres == S_OK);
 
-  Microsoft::WRL::ComPtr<ID3D11Resource> back_buffer = nullptr;
-  m_swapchain->GetBuffer(0, __uuidof(ID3D11Resource), &back_buffer);
+  ID3D11Texture2D *back_buffer;
+  m_swapchain->GetBuffer(0, __uuidof(ID3D11Texture2D), (void **)&back_buffer);
 
-  m_device->CreateRenderTargetView(back_buffer.Get(), nullptr, &m_backbuffer_view);
+  m_device->CreateRenderTargetView(back_buffer, nullptr, &m_backbuffer_view);
+  back_buffer->Release();
 
   m_swapchain->Present(0, 0);
 
@@ -225,8 +230,8 @@ GHOST_TSuccess GHOST_ContextD3D::blitOpenGLOffscreenContext(GHOST_Context *offsc
   }
 
   // const float clear_col[] = {0.2f, 0.5f, 0.8f, 1.0f};
-  // m_device_ctx->ClearRenderTargetView(m_backbuffer_view.Get(), clear_col);
-  m_device_ctx->OMSetRenderTargets(1, m_backbuffer_view.GetAddressOf(), nullptr);
+  // m_device_ctx->ClearRenderTargetView(m_backbuffer_view, clear_col);
+  m_device_ctx->OMSetRenderTargets(1, &m_backbuffer_view, nullptr);
 
   offscreen_ctx->activateDrawingContext();
 
diff --git a/intern/ghost/intern/GHOST_ContextD3D.h b/intern/ghost/intern/GHOST_ContextD3D.h
index a4ff58a0b46..430ac12abbd 100644
--- a/intern/ghost/intern/GHOST_ContextD3D.h
+++ b/intern/ghost/intern/GHOST_ContextD3D.h
@@ -26,7 +26,6 @@
 #endif  // WIN32
 
 #include <D3D11.h>
-#include <wrl.h>  // Microsoft::WRL::ComPtr
 
 #include "GHOST_Context.h"
 
@@ -126,10 +125,10 @@ class GHOST_ContextD3D : public GHOST_Context {
 
   HWND m_hWnd;
 
-  Microsoft::WRL::ComPtr<ID3D11Device> m_device;
-  Microsoft::WRL::ComPtr<ID3D11DeviceContext> m_device_ctx;
-  Microsoft::WRL::ComPtr<IDXGISwapChain> m_swapchain;
-  Microsoft::WRL::ComPtr<ID3D11RenderTargetView> m_backbuffer_view;
+  ID3D11Device *m_device;
+  ID3D11DeviceContext *m_device_ctx;
+  IDXGISwapChain *m_swapchain;
+  ID3D11RenderTargetView *m_backbuffer_view;
 
   SharedOpenGLContext *glshared{NULL};
 };
diff --git a/intern/ghost/intern/GHOST_XRGraphicsBinding.cpp b/intern/ghost/intern/GHOST_XRGraphicsBinding.cpp
index d08940a951e..ee1655a2150 100644
--- a/intern/ghost/intern/GHOST_XRGraphicsBinding.cpp
+++ b/intern/ghost/intern/GHOST_XRGraphicsBinding.cpp
@@ -123,7 +123,7 @@ class GHOST_XrGraphicsBindingD3D : public GHOST_IXrGraphicsBinding {
     GHOST_ContextD3D *ctx_d3d = static_cast<GHOST_ContextD3D *>(ghost_ctx);
 
     oxr_binding.d3d11.type = XR_TYPE_GRAPHICS_BINDING_D3D11_KHR;
-    oxr_binding.d3d11.device = ctx_d3d->m_device.Get();
+    oxr_binding.d3d11.device = ctx_d3d->m_device;
     m_ghost_ctx = ctx_d3d;
   }
 
@@ -160,13 +160,15 @@ class GHOST_XrGraphicsBindingD3D : public GHOST_IXrGraphicsBinding {
         swapchain_image);
     const CD3D11_RENDER_TARGET_VIEW_DESC render_target_view_desc(D3D11_RTV_DIMENSION_TEXTURE2D,
                                                                  DXGI_FORMAT_R8G8B8A8_UNORM);
-    Microsoft::WRL::ComPtr<ID3D11RenderTargetView> renderTargetView;
+    ID3D11RenderTargetView *render_target_view;
     m_ghost_ctx->m_device->CreateRenderTargetView(d3d_swapchain_image->texture,
                                                   &render_target_view_desc,
-                                                  renderTargetView.ReleaseAndGetAddressOf());
+                                                  &render_target_view);
 
     const float clear_col[] = {0.2f, 0.5f, 0.8f, 1.0f};
-    m_ghost_ctx->m_device_ctx->ClearRenderTargetView(renderTargetView.Get(), clear_col);
+    m_ghost_ctx->m_device_ctx->ClearRenderTargetView(render_target_view, clear_col);
+
+    render_target_view->Release();
   }
   void drawViewEnd(XrSwapchainImageBaseHeader *swapchain_image) override
   {



More information about the Bf-blender-cvs mailing list