Added SDL_RenderGetD3D11Device() to get access to the device associated with the D3D11 renderer
1 2 3 4 5 6 7 8 9 10 11 12 13 14 15 16 17 18 19 20 21 22 23 24 25 26 27 28 29 30 31 32 33 34 35 36 37 38 39 40 41 42 43 44 45 46 47 48 49 50 51 52 53 54 55 56 57 58 59 60 61 62 63 64 65 66 67 68 69 70 71 72 73 74 75 76 77 78 79 80 81 82 83 84 85 86 87 88 89 90 91
diff --git a/include/SDL_system.h b/include/SDL_system.h
index d296ab1..d3a9260 100644
--- a/include/SDL_system.h
+++ b/include/SDL_system.h
@@ -59,12 +59,20 @@ extern DECLSPEC int SDLCALL SDL_Direct3D9GetAdapterIndex( int displayIndex );
typedef struct IDirect3DDevice9 IDirect3DDevice9;
/**
- \brief Returns the D3D device associated with a renderer, or NULL if it's not a D3D renderer.
+ \brief Returns the D3D9 device associated with a renderer, or NULL if it's not a D3D9 renderer.
Once you are done using the device, you should release it to avoid a resource leak.
*/
extern DECLSPEC IDirect3DDevice9* SDLCALL SDL_RenderGetD3D9Device(SDL_Renderer * renderer);
+typedef struct ID3D11Device ID3D11Device;
+/**
+ \brief Returns the D3D11 device associated with a renderer, or NULL if it's not a D3D11 renderer.
+
+ Once you are done using the device, you should release it to avoid a resource leak.
+ */
+extern DECLSPEC ID3D11Device* SDLCALL SDL_RenderGetD3D11Device(SDL_Renderer * renderer);
+
/**
\brief Returns the DXGI Adapter and Output indices for the specified display index.
diff --git a/src/dynapi/SDL_dynapi_overrides.h b/src/dynapi/SDL_dynapi_overrides.h
index 5d6eb62..94e6950 100644
--- a/src/dynapi/SDL_dynapi_overrides.h
+++ b/src/dynapi/SDL_dynapi_overrides.h
@@ -793,3 +793,4 @@
#define SDL_lround SDL_lround_REAL
#define SDL_lroundf SDL_lroundf_REAL
#define SDL_SoftStretchLinear SDL_SoftStretchLinear_REAL
+#define SDL_RenderGetD3D11Device SDL_RenderGetD3D11Device_REAL
diff --git a/src/dynapi/SDL_dynapi_procs.h b/src/dynapi/SDL_dynapi_procs.h
index 719113b..ee0269d 100644
--- a/src/dynapi/SDL_dynapi_procs.h
+++ b/src/dynapi/SDL_dynapi_procs.h
@@ -854,3 +854,6 @@ SDL_DYNAPI_PROC(float,SDL_roundf,(float a),(a),return)
SDL_DYNAPI_PROC(long,SDL_lround,(double a),(a),return)
SDL_DYNAPI_PROC(long,SDL_lroundf,(float a),(a),return)
SDL_DYNAPI_PROC(int,SDL_SoftStretchLinear,(SDL_Surface *a, const SDL_Rect *b, SDL_Surface *c, const SDL_Rect *d),(a,b,c,d),return)
+#ifdef __WIN32__
+SDL_DYNAPI_PROC(ID3D11Device*,SDL_RenderGetD3D11Device,(SDL_Renderer *a),(a),return)
+#endif
diff --git a/src/render/direct3d11/SDL_render_d3d11.c b/src/render/direct3d11/SDL_render_d3d11.c
index 3ceb1a8..060c74c 100644
--- a/src/render/direct3d11/SDL_render_d3d11.c
+++ b/src/render/direct3d11/SDL_render_d3d11.c
@@ -20,6 +20,9 @@
*/
#include "../../SDL_internal.h"
+#include "SDL_render.h"
+#include "SDL_system.h"
+
#if SDL_VIDEO_RENDER_D3D11 && !SDL_RENDER_DISABLED
#define COBJMACROS
@@ -2595,4 +2598,30 @@ SDL_RenderDriver D3D11_RenderDriver = {
#endif /* SDL_VIDEO_RENDER_D3D11 && !SDL_RENDER_DISABLED */
+#ifdef __WIN32__
+/* This function needs to always exist on Windows, for the Dynamic API. */
+ID3D11Device *
+SDL_RenderGetD3D11Device(SDL_Renderer * renderer)
+{
+ ID3D11Device *device = NULL;
+
+#if SDL_VIDEO_RENDER_D3D11 && !SDL_RENDER_DISABLED
+ D3D11_RenderData *data = (D3D11_RenderData *) renderer->driverdata;
+
+ /* Make sure that this is a D3D renderer */
+ if (renderer->DestroyRenderer != D3D11_DestroyRenderer) {
+ SDL_SetError("Renderer is not a D3D11 renderer");
+ return NULL;
+ }
+
+ device = (ID3D11Device *)data->d3dDevice;
+ if (device) {
+ ID3D11Device_AddRef(device);
+ }
+#endif /* SDL_VIDEO_RENDER_D3D11 && !SDL_RENDER_DISABLED */
+
+ return device;
+}
+#endif /* __WIN32__ */
+
/* vi: set ts=4 sw=4 expandtab: */