21 #include "../../SDL_internal.h"
23 #if SDL_VIDEO_RENDER_D3D11 && !SDL_RENDER_DISABLED
26 #include "../../core/windows/SDL_windows.h"
30 #include "../SDL_sysrender.h"
31 #include "../SDL_d3dmath.h"
39 #if NTDDI_VERSION > NTDDI_WIN8
45 #if WINAPI_FAMILY == WINAPI_FAMILY_APP
46 #include <windows.ui.xaml.media.dxinterop.h>
54 #define SDL_COMPOSE_ERROR(str) SDL_STRINGIFY_ARG(__FUNCTION__) ", " str
56 #define SAFE_RELEASE(X) if ((X)) { IUnknown_Release(SDL_static_cast(IUnknown*, X)); X = NULL; }
63 Float4X4 projectionAndView;
64 } VertexShaderConstants;
72 } VertexPositionColor;
77 ID3D11Texture2D *mainTexture;
78 ID3D11ShaderResourceView *mainTextureResourceView;
79 ID3D11RenderTargetView *mainTextureRenderTargetView;
80 ID3D11Texture2D *stagingTexture;
81 int lockedTexturePositionX;
82 int lockedTexturePositionY;
83 D3D11_FILTER scaleMode;
87 ID3D11Texture2D *mainTextureU;
88 ID3D11ShaderResourceView *mainTextureResourceViewU;
89 ID3D11Texture2D *mainTextureV;
90 ID3D11ShaderResourceView *mainTextureResourceViewV;
94 ID3D11Texture2D *mainTextureNV;
95 ID3D11ShaderResourceView *mainTextureResourceViewNV;
106 ID3D11BlendState *blendState;
114 IDXGIFactory2 *dxgiFactory;
115 IDXGIAdapter *dxgiAdapter;
116 ID3D11Device1 *d3dDevice;
117 ID3D11DeviceContext1 *d3dContext;
118 IDXGISwapChain1 *swapChain;
119 DXGI_SWAP_EFFECT swapEffect;
120 ID3D11RenderTargetView *mainRenderTargetView;
121 ID3D11RenderTargetView *currentOffscreenRenderTargetView;
122 ID3D11InputLayout *inputLayout;
123 ID3D11Buffer *vertexBuffer;
124 ID3D11VertexShader *vertexShader;
127 D3D11_BlendMode *blendModes;
128 ID3D11SamplerState *nearestPixelSampler;
129 ID3D11SamplerState *linearSampler;
130 D3D_FEATURE_LEVEL featureLevel;
133 ID3D11RasterizerState *mainRasterizer;
134 ID3D11RasterizerState *clippedRasterizer;
137 VertexShaderConstants vertexShaderConstantsData;
138 ID3D11Buffer *vertexShaderConstants;
141 DXGI_MODE_ROTATION rotation;
142 ID3D11RenderTargetView *currentRenderTargetView;
143 ID3D11RasterizerState *currentRasterizerState;
144 ID3D11BlendState *currentBlendState;
145 ID3D11PixelShader *currentShader;
146 ID3D11ShaderResourceView *currentShaderResource;
147 ID3D11SamplerState *currentSampler;
161 #pragma GCC diagnostic push
162 #pragma GCC diagnostic ignored "-Wunused-const-variable"
165 static const GUID SDL_IID_IDXGIFactory2 = { 0x50c83a1c, 0xe072, 0x4c48, { 0x87, 0xb0, 0x36, 0x30, 0xfa, 0x36, 0xa6, 0xd0 } };
166 static const GUID SDL_IID_IDXGIDevice1 = { 0x77db970f, 0x6276, 0x48ba, { 0xba, 0x28, 0x07, 0x01, 0x43, 0xb4, 0x39, 0x2c } };
167 static const GUID SDL_IID_IDXGIDevice3 = { 0x6007896c, 0x3244, 0x4afd, { 0xbf, 0x18, 0xa6, 0xd3, 0xbe, 0xda, 0x50, 0x23 } };
168 static const GUID SDL_IID_ID3D11Texture2D = { 0x6f15aaf2, 0xd208, 0x4e89, { 0x9a, 0xb4, 0x48, 0x95, 0x35, 0xd3, 0x4f, 0x9c } };
169 static const GUID SDL_IID_ID3D11Device1 = { 0xa04bfb29, 0x08ef, 0x43d6, { 0xa4, 0x9c, 0xa9, 0xbd, 0xbd, 0xcb, 0xe6, 0x86 } };
170 static const GUID SDL_IID_ID3D11DeviceContext1 = { 0xbb2c6faa, 0xb5fb, 0x4082, { 0x8e, 0x6b, 0x38, 0x8b, 0x8c, 0xfa, 0x90, 0xe1 } };
171 static const GUID SDL_IID_ID3D11Debug = { 0x79cf2233, 0x7536, 0x4948, { 0x9d, 0x36, 0x1e, 0x46, 0x92, 0xdc, 0x57, 0x60 } };
174 #pragma GCC diagnostic pop
189 const Uint8 *Yplane,
int Ypitch,
190 const Uint8 *Uplane,
int Upitch,
191 const Uint8 *Vplane,
int Vpitch);
225 D3D11_CreateRenderer,
249 D3D11_DXGIFormatToSDLPixelFormat(DXGI_FORMAT dxgiFormat)
251 switch (dxgiFormat) {
252 case DXGI_FORMAT_B8G8R8A8_UNORM:
254 case DXGI_FORMAT_B8G8R8X8_UNORM:
262 SDLPixelFormatToDXGIFormat(
Uint32 sdlFormat)
266 return DXGI_FORMAT_B8G8R8A8_UNORM;
268 return DXGI_FORMAT_B8G8R8X8_UNORM;
273 return DXGI_FORMAT_R8_UNORM;
275 return DXGI_FORMAT_UNKNOWN;
283 D3D11_RenderData *
data;
321 #if WINAPI_FAMILY == WINAPI_FAMILY_PHONE_APP
373 SAFE_RELEASE(
data->dxgiFactory);
374 SAFE_RELEASE(
data->dxgiAdapter);
375 SAFE_RELEASE(
data->d3dDevice);
376 SAFE_RELEASE(
data->d3dContext);
377 SAFE_RELEASE(
data->swapChain);
378 SAFE_RELEASE(
data->mainRenderTargetView);
379 SAFE_RELEASE(
data->currentOffscreenRenderTargetView);
380 SAFE_RELEASE(
data->inputLayout);
381 SAFE_RELEASE(
data->vertexBuffer);
382 SAFE_RELEASE(
data->vertexShader);
384 SAFE_RELEASE(
data->pixelShaders[
i]);
386 if (
data->blendModesCount > 0) {
387 for (
i = 0;
i <
data->blendModesCount; ++
i) {
388 SAFE_RELEASE(
data->blendModes[
i].blendState);
392 data->blendModesCount = 0;
394 SAFE_RELEASE(
data->nearestPixelSampler);
395 SAFE_RELEASE(
data->linearSampler);
396 SAFE_RELEASE(
data->mainRasterizer);
397 SAFE_RELEASE(
data->clippedRasterizer);
398 SAFE_RELEASE(
data->vertexShaderConstants);
400 data->swapEffect = (DXGI_SWAP_EFFECT) 0;
401 data->rotation = DXGI_MODE_ROTATION_UNSPECIFIED;
402 data->currentRenderTargetView =
NULL;
403 data->currentRasterizerState =
NULL;
412 if (
data->hD3D11Mod) {
416 if (
data->hDXGIMod) {
438 return D3D11_BLEND_ZERO;
440 return D3D11_BLEND_ONE;
442 return D3D11_BLEND_SRC_COLOR;
444 return D3D11_BLEND_INV_SRC_COLOR;
446 return D3D11_BLEND_SRC_ALPHA;
448 return D3D11_BLEND_INV_SRC_ALPHA;
450 return D3D11_BLEND_DEST_COLOR;
452 return D3D11_BLEND_INV_DEST_COLOR;
454 return D3D11_BLEND_DEST_ALPHA;
456 return D3D11_BLEND_INV_DEST_ALPHA;
458 return (D3D11_BLEND)0;
466 return D3D11_BLEND_OP_ADD;
468 return D3D11_BLEND_OP_SUBTRACT;
470 return D3D11_BLEND_OP_REV_SUBTRACT;
472 return D3D11_BLEND_OP_MIN;
474 return D3D11_BLEND_OP_MAX;
476 return (D3D11_BLEND_OP)0;
490 ID3D11BlendState *blendState =
NULL;
491 D3D11_BlendMode *blendModes;
494 D3D11_BLEND_DESC blendDesc;
496 blendDesc.AlphaToCoverageEnable =
FALSE;
497 blendDesc.IndependentBlendEnable =
FALSE;
498 blendDesc.RenderTarget[0].BlendEnable =
TRUE;
499 blendDesc.RenderTarget[0].SrcBlend = GetBlendFunc(srcColorFactor);
500 blendDesc.RenderTarget[0].DestBlend = GetBlendFunc(dstColorFactor);
501 blendDesc.RenderTarget[0].BlendOp = GetBlendEquation(colorOperation);
502 blendDesc.RenderTarget[0].SrcBlendAlpha = GetBlendFunc(srcAlphaFactor);
503 blendDesc.RenderTarget[0].DestBlendAlpha = GetBlendFunc(dstAlphaFactor);
504 blendDesc.RenderTarget[0].BlendOpAlpha = GetBlendEquation(alphaOperation);
505 blendDesc.RenderTarget[0].RenderTargetWriteMask = D3D11_COLOR_WRITE_ENABLE_ALL;
506 result = ID3D11Device_CreateBlendState(
data->d3dDevice, &blendDesc, &blendState);
512 blendModes = (D3D11_BlendMode *)
SDL_realloc(
data->blendModes, (
data->blendModesCount + 1) *
sizeof(*blendModes));
514 SAFE_RELEASE(blendState);
519 blendModes[
data->blendModesCount].blendState = blendState;
520 data->blendModes = blendModes;
521 ++
data->blendModesCount;
530 typedef HRESULT(WINAPI *PFN_CREATE_DXGI_FACTORY)(REFIID riid,
void **ppFactory);
531 PFN_CREATE_DXGI_FACTORY CreateDXGIFactoryFunc;
533 PFN_D3D11_CREATE_DEVICE D3D11CreateDeviceFunc;
534 ID3D11Device *d3dDevice =
NULL;
535 ID3D11DeviceContext *d3dContext =
NULL;
536 IDXGIDevice1 *dxgiDevice =
NULL;
546 D3D_FEATURE_LEVEL featureLevels[] =
548 D3D_FEATURE_LEVEL_11_1,
549 D3D_FEATURE_LEVEL_11_0,
550 D3D_FEATURE_LEVEL_10_1,
551 D3D_FEATURE_LEVEL_10_0,
552 D3D_FEATURE_LEVEL_9_3,
553 D3D_FEATURE_LEVEL_9_2,
554 D3D_FEATURE_LEVEL_9_1
557 D3D11_BUFFER_DESC constantBufferDesc;
558 D3D11_SAMPLER_DESC samplerDesc;
559 D3D11_RASTERIZER_DESC rasterDesc;
562 CreateDXGIFactoryFunc = CreateDXGIFactory1;
563 D3D11CreateDeviceFunc = D3D11CreateDevice;
566 if (!
data->hDXGIMod) {
571 CreateDXGIFactoryFunc = (PFN_CREATE_DXGI_FACTORY)
SDL_LoadFunction(
data->hDXGIMod,
"CreateDXGIFactory");
572 if (!CreateDXGIFactoryFunc) {
578 if (!
data->hD3D11Mod) {
583 D3D11CreateDeviceFunc = (PFN_D3D11_CREATE_DEVICE)
SDL_LoadFunction(
data->hD3D11Mod,
"D3D11CreateDevice");
584 if (!D3D11CreateDeviceFunc) {
590 result = CreateDXGIFactoryFunc(&SDL_IID_IDXGIFactory2, (
void **)&
data->dxgiFactory);
597 result = IDXGIFactory2_EnumAdapters(
data->dxgiFactory, 0, &
data->dxgiAdapter);
606 creationFlags = D3D11_CREATE_DEVICE_BGRA_SUPPORT;
610 creationFlags |= D3D11_CREATE_DEVICE_DEBUG;
614 result = D3D11CreateDeviceFunc(
616 D3D_DRIVER_TYPE_UNKNOWN,
631 result = ID3D11Device_QueryInterface(d3dDevice, &SDL_IID_ID3D11Device1, (
void **)&
data->d3dDevice);
637 result = ID3D11DeviceContext_QueryInterface(d3dContext, &SDL_IID_ID3D11DeviceContext1, (
void **)&
data->d3dContext);
643 result = ID3D11Device_QueryInterface(d3dDevice, &SDL_IID_IDXGIDevice1, (
void **)&dxgiDevice);
652 result = IDXGIDevice1_SetMaximumFrameLatency(dxgiDevice, 1);
662 switch (
data->featureLevel) {
663 case D3D_FEATURE_LEVEL_11_1:
664 case D3D_FEATURE_LEVEL_11_0:
668 case D3D_FEATURE_LEVEL_10_1:
669 case D3D_FEATURE_LEVEL_10_0:
673 case D3D_FEATURE_LEVEL_9_3:
677 case D3D_FEATURE_LEVEL_9_2:
678 case D3D_FEATURE_LEVEL_9_1:
683 SDL_SetError(
"%s, Unexpected feature level: %d", __FUNCTION__,
data->featureLevel);
700 constantBufferDesc.ByteWidth =
sizeof(VertexShaderConstants);
701 constantBufferDesc.Usage = D3D11_USAGE_DEFAULT;
702 constantBufferDesc.BindFlags = D3D11_BIND_CONSTANT_BUFFER;
703 result = ID3D11Device_CreateBuffer(
data->d3dDevice,
706 &
data->vertexShaderConstants
715 samplerDesc.Filter = D3D11_FILTER_MIN_MAG_MIP_POINT;
716 samplerDesc.AddressU = D3D11_TEXTURE_ADDRESS_CLAMP;
717 samplerDesc.AddressV = D3D11_TEXTURE_ADDRESS_CLAMP;
718 samplerDesc.AddressW = D3D11_TEXTURE_ADDRESS_CLAMP;
719 samplerDesc.MipLODBias = 0.0f;
720 samplerDesc.MaxAnisotropy = 1;
721 samplerDesc.ComparisonFunc = D3D11_COMPARISON_ALWAYS;
722 samplerDesc.MinLOD = 0.0f;
723 samplerDesc.MaxLOD = D3D11_FLOAT32_MAX;
724 result = ID3D11Device_CreateSamplerState(
data->d3dDevice,
726 &
data->nearestPixelSampler
733 samplerDesc.Filter = D3D11_FILTER_MIN_MAG_MIP_LINEAR;
734 result = ID3D11Device_CreateSamplerState(
data->d3dDevice,
745 rasterDesc.AntialiasedLineEnable =
FALSE;
746 rasterDesc.CullMode = D3D11_CULL_NONE;
747 rasterDesc.DepthBias = 0;
748 rasterDesc.DepthBiasClamp = 0.0f;
749 rasterDesc.DepthClipEnable =
TRUE;
750 rasterDesc.FillMode = D3D11_FILL_SOLID;
751 rasterDesc.FrontCounterClockwise =
FALSE;
752 rasterDesc.MultisampleEnable =
FALSE;
753 rasterDesc.ScissorEnable =
FALSE;
754 rasterDesc.SlopeScaledDepthBias = 0.0f;
755 result = ID3D11Device_CreateRasterizerState(
data->d3dDevice, &rasterDesc, &
data->mainRasterizer);
761 rasterDesc.ScissorEnable =
TRUE;
762 result = ID3D11Device_CreateRasterizerState(
data->d3dDevice, &rasterDesc, &
data->clippedRasterizer);
777 ID3D11DeviceContext_IASetInputLayout(
data->d3dContext,
data->inputLayout);
778 ID3D11DeviceContext_VSSetShader(
data->d3dContext,
data->vertexShader,
NULL, 0);
779 ID3D11DeviceContext_VSSetConstantBuffers(
data->d3dContext, 0, 1, &
data->vertexShaderConstants);
782 SAFE_RELEASE(d3dDevice);
783 SAFE_RELEASE(d3dContext);
784 SAFE_RELEASE(dxgiDevice);
790 static DXGI_MODE_ROTATION
791 D3D11_GetCurrentRotation()
794 return DXGI_MODE_ROTATION_IDENTITY;
800 D3D11_IsDisplayRotated90Degrees(DXGI_MODE_ROTATION rotation)
803 case DXGI_MODE_ROTATION_ROTATE90:
804 case DXGI_MODE_ROTATION_ROTATE270:
815 if (
data->currentOffscreenRenderTargetView) {
816 return DXGI_MODE_ROTATION_IDENTITY;
818 return data->rotation;
825 const int rotation = D3D11_GetRotationForCurrentRenderTarget(
renderer);
827 case DXGI_MODE_ROTATION_IDENTITY:
828 outRect->left = sdlRect->
x;
829 outRect->right = sdlRect->
x + sdlRect->
w;
830 outRect->top = sdlRect->
y;
831 outRect->bottom = sdlRect->
y + sdlRect->
h;
832 if (includeViewportOffset) {
839 case DXGI_MODE_ROTATION_ROTATE270:
840 outRect->left = sdlRect->
y;
841 outRect->right = sdlRect->
y + sdlRect->
h;
845 case DXGI_MODE_ROTATION_ROTATE180:
851 case DXGI_MODE_ROTATION_ROTATE90:
854 outRect->top = sdlRect->
x;
855 outRect->bottom = sdlRect->
x + sdlRect->
h;
858 return SDL_SetError(
"The physical display is in an unknown or unsupported rotation");
868 IUnknown *coreWindow = D3D11_GetCoreWindowFromSDLRenderer(
renderer);
869 const BOOL usingXAML = (coreWindow ==
NULL);
871 IUnknown *coreWindow =
NULL;
872 const BOOL usingXAML =
FALSE;
877 DXGI_SWAP_CHAIN_DESC1 swapChainDesc;
879 swapChainDesc.Width =
w;
880 swapChainDesc.Height =
h;
881 swapChainDesc.Format = DXGI_FORMAT_B8G8R8A8_UNORM;
882 swapChainDesc.Stereo =
FALSE;
883 swapChainDesc.SampleDesc.Count = 1;
884 swapChainDesc.SampleDesc.Quality = 0;
885 swapChainDesc.BufferUsage = DXGI_USAGE_RENDER_TARGET_OUTPUT;
886 swapChainDesc.BufferCount = 2;
887 #if WINAPI_FAMILY == WINAPI_FAMILY_PHONE_APP
888 swapChainDesc.Scaling = DXGI_SCALING_STRETCH;
889 swapChainDesc.SwapEffect = DXGI_SWAP_EFFECT_DISCARD;
893 swapChainDesc.Scaling = DXGI_SCALING_STRETCH;
895 swapChainDesc.Scaling = DXGI_SCALING_NONE;
897 swapChainDesc.SwapEffect = DXGI_SWAP_EFFECT_FLIP_SEQUENTIAL;
899 swapChainDesc.Flags = 0;
902 result = IDXGIFactory2_CreateSwapChainForCoreWindow(
data->dxgiFactory,
903 (IUnknown *)
data->d3dDevice,
913 }
else if (usingXAML) {
914 result = IDXGIFactory2_CreateSwapChainForComposition(
data->dxgiFactory,
915 (IUnknown *)
data->d3dDevice,
924 #if WINAPI_FAMILY == WINAPI_FAMILY_APP
931 SDL_SetError(SDL_COMPOSE_ERROR(
"XAML support is not yet available for Windows Phone"));
941 result = IDXGIFactory2_CreateSwapChainForHwnd(
data->dxgiFactory,
942 (IUnknown *)
data->d3dDevice,
954 IDXGIFactory_MakeWindowAssociation(
data->dxgiFactory, windowinfo.
info.win.
window, DXGI_MWA_NO_WINDOW_CHANGES);
956 SDL_SetError(__FUNCTION__
", Unable to find something to attach a swap chain to");
960 data->swapEffect = swapChainDesc.SwapEffect;
963 SAFE_RELEASE(coreWindow);
973 ID3D11Texture2D *backBuffer =
NULL;
978 D3D11_ReleaseMainRenderTargetView(
renderer);
984 data->rotation = D3D11_GetCurrentRotation();
986 if (D3D11_IsDisplayRotated90Degrees(
data->rotation)) {
992 if (
data->swapChain) {
994 #if !defined(__WINRT__) || (WINAPI_FAMILY != WINAPI_FAMILY_PHONE_APP)
996 result = IDXGISwapChain_ResizeBuffers(
data->swapChain,
1002 if (
result == DXGI_ERROR_DEVICE_REMOVED) {
1022 #if WINAPI_FAMILY != WINAPI_FAMILY_PHONE_APP
1039 if (
data->swapEffect == DXGI_SWAP_EFFECT_FLIP_SEQUENTIAL) {
1040 result = IDXGISwapChain1_SetRotation(
data->swapChain,
data->rotation);
1048 result = IDXGISwapChain_GetBuffer(
data->swapChain,
1050 &SDL_IID_ID3D11Texture2D,
1051 (
void **)&backBuffer
1059 result = ID3D11Device_CreateRenderTargetView(
data->d3dDevice,
1060 (ID3D11Resource *)backBuffer,
1062 &
data->mainRenderTargetView
1069 if (D3D11_UpdateViewport(
renderer) != 0) {
1076 SAFE_RELEASE(backBuffer);
1084 return D3D11_CreateWindowSizeDependentResources(
renderer);
1120 #if NTDDI_VERSION > NTDDI_WIN8
1123 IDXGIDevice3 *dxgiDevice =
NULL;
1125 result = ID3D11Device_QueryInterface(
data->d3dDevice, &SDL_IID_IDXGIDevice3, &dxgiDevice);
1131 IDXGIDevice3_Trim(dxgiDevice);
1132 SAFE_RELEASE(dxgiDevice);
1141 D3D11_UpdateForWindowSizeChange(
renderer);
1155 if (!GetBlendFunc(srcColorFactor) || !GetBlendFunc(srcAlphaFactor) ||
1156 !GetBlendEquation(colorOperation) ||
1157 !GetBlendFunc(dstColorFactor) || !GetBlendFunc(dstAlphaFactor) ||
1158 !GetBlendEquation(alphaOperation)) {
1168 D3D11_TextureData *textureData;
1170 DXGI_FORMAT textureFormat = SDLPixelFormatToDXGIFormat(
texture->format);
1171 D3D11_TEXTURE2D_DESC textureDesc;
1172 D3D11_SHADER_RESOURCE_VIEW_DESC resourceViewDesc;
1174 if (textureFormat == DXGI_FORMAT_UNKNOWN) {
1175 return SDL_SetError(
"%s, An unsupported SDL pixel format (0x%x) was specified",
1176 __FUNCTION__,
texture->format);
1179 textureData = (D3D11_TextureData*)
SDL_calloc(1,
sizeof(*textureData));
1184 textureData->scaleMode = (
texture->scaleMode ==
SDL_ScaleModeNearest) ? D3D11_FILTER_MIN_MAG_MIP_POINT : D3D11_FILTER_MIN_MAG_MIP_LINEAR;
1186 texture->driverdata = textureData;
1189 textureDesc.Width =
texture->w;
1190 textureDesc.Height =
texture->h;
1191 textureDesc.MipLevels = 1;
1192 textureDesc.ArraySize = 1;
1193 textureDesc.Format = textureFormat;
1194 textureDesc.SampleDesc.Count = 1;
1195 textureDesc.SampleDesc.Quality = 0;
1196 textureDesc.MiscFlags = 0;
1199 textureDesc.Usage = D3D11_USAGE_DYNAMIC;
1200 textureDesc.CPUAccessFlags = D3D11_CPU_ACCESS_WRITE;
1202 textureDesc.Usage = D3D11_USAGE_DEFAULT;
1203 textureDesc.CPUAccessFlags = 0;
1207 textureDesc.BindFlags = D3D11_BIND_SHADER_RESOURCE | D3D11_BIND_RENDER_TARGET;
1209 textureDesc.BindFlags = D3D11_BIND_SHADER_RESOURCE;
1212 result = ID3D11Device_CreateTexture2D(rendererData->d3dDevice,
1215 &textureData->mainTexture
1227 textureDesc.Width = (textureDesc.Width + 1) / 2;
1228 textureDesc.Height = (textureDesc.Height + 1) / 2;
1230 result = ID3D11Device_CreateTexture2D(rendererData->d3dDevice,
1233 &textureData->mainTextureU
1241 result = ID3D11Device_CreateTexture2D(rendererData->d3dDevice,
1244 &textureData->mainTextureV
1255 D3D11_TEXTURE2D_DESC nvTextureDesc = textureDesc;
1259 nvTextureDesc.Format = DXGI_FORMAT_R8G8_UNORM;
1260 nvTextureDesc.Width = (textureDesc.Width + 1) / 2;
1261 nvTextureDesc.Height = (textureDesc.Height + 1) / 2;
1263 result = ID3D11Device_CreateTexture2D(rendererData->d3dDevice,
1266 &textureData->mainTextureNV
1275 resourceViewDesc.Format = textureDesc.Format;
1276 resourceViewDesc.ViewDimension = D3D11_SRV_DIMENSION_TEXTURE2D;
1277 resourceViewDesc.Texture2D.MostDetailedMip = 0;
1278 resourceViewDesc.Texture2D.MipLevels = textureDesc.MipLevels;
1279 result = ID3D11Device_CreateShaderResourceView(rendererData->d3dDevice,
1280 (ID3D11Resource *)textureData->mainTexture,
1282 &textureData->mainTextureResourceView
1290 if (textureData->yuv) {
1291 result = ID3D11Device_CreateShaderResourceView(rendererData->d3dDevice,
1292 (ID3D11Resource *)textureData->mainTextureU,
1294 &textureData->mainTextureResourceViewU
1301 result = ID3D11Device_CreateShaderResourceView(rendererData->d3dDevice,
1302 (ID3D11Resource *)textureData->mainTextureV,
1304 &textureData->mainTextureResourceViewV
1313 if (textureData->nv12) {
1314 D3D11_SHADER_RESOURCE_VIEW_DESC nvResourceViewDesc = resourceViewDesc;
1316 nvResourceViewDesc.Format = DXGI_FORMAT_R8G8_UNORM;
1318 result = ID3D11Device_CreateShaderResourceView(rendererData->d3dDevice,
1319 (ID3D11Resource *)textureData->mainTextureNV,
1320 &nvResourceViewDesc,
1321 &textureData->mainTextureResourceViewNV
1331 D3D11_RENDER_TARGET_VIEW_DESC renderTargetViewDesc;
1332 renderTargetViewDesc.Format = textureDesc.Format;
1333 renderTargetViewDesc.ViewDimension = D3D11_RTV_DIMENSION_TEXTURE2D;
1334 renderTargetViewDesc.Texture2D.MipSlice = 0;
1336 result = ID3D11Device_CreateRenderTargetView(rendererData->d3dDevice,
1337 (ID3D11Resource *)textureData->mainTexture,
1338 &renderTargetViewDesc,
1339 &textureData->mainTextureRenderTargetView);
1354 D3D11_TextureData *
data = (D3D11_TextureData *)
texture->driverdata;
1360 SAFE_RELEASE(
data->mainTexture);
1361 SAFE_RELEASE(
data->mainTextureResourceView);
1362 SAFE_RELEASE(
data->mainTextureRenderTargetView);
1363 SAFE_RELEASE(
data->stagingTexture);
1364 SAFE_RELEASE(
data->mainTextureU);
1365 SAFE_RELEASE(
data->mainTextureResourceViewU);
1366 SAFE_RELEASE(
data->mainTextureV);
1367 SAFE_RELEASE(
data->mainTextureResourceViewV);
1374 D3D11_UpdateTextureInternal(D3D11_RenderData *rendererData, ID3D11Texture2D *
texture,
int bpp,
int x,
int y,
int w,
int h,
const void *
pixels,
int pitch)
1376 ID3D11Texture2D *stagingTexture;
1382 D3D11_TEXTURE2D_DESC stagingTextureDesc;
1383 D3D11_MAPPED_SUBRESOURCE textureMemory;
1386 ID3D11Texture2D_GetDesc(
texture, &stagingTextureDesc);
1387 stagingTextureDesc.Width =
w;
1388 stagingTextureDesc.Height =
h;
1389 stagingTextureDesc.BindFlags = 0;
1390 stagingTextureDesc.MiscFlags = 0;
1391 stagingTextureDesc.CPUAccessFlags = D3D11_CPU_ACCESS_WRITE;
1392 stagingTextureDesc.Usage = D3D11_USAGE_STAGING;
1393 result = ID3D11Device_CreateTexture2D(rendererData->d3dDevice,
1394 &stagingTextureDesc,
1403 result = ID3D11DeviceContext_Map(rendererData->d3dContext,
1404 (ID3D11Resource *)stagingTexture,
1412 SAFE_RELEASE(stagingTexture);
1417 dst = textureMemory.pData;
1419 if (
length == pitch &&
length == textureMemory.RowPitch) {
1422 if (
length > (UINT)pitch) {
1425 if (
length > textureMemory.RowPitch) {
1426 length = textureMemory.RowPitch;
1431 dst += textureMemory.RowPitch;
1436 ID3D11DeviceContext_Unmap(rendererData->d3dContext,
1437 (ID3D11Resource *)stagingTexture,
1441 ID3D11DeviceContext_CopySubresourceRegion(rendererData->d3dContext,
1447 (ID3D11Resource *)stagingTexture,
1451 SAFE_RELEASE(stagingTexture);
1462 D3D11_TextureData *textureData = (D3D11_TextureData *)
texture->driverdata;
1473 if (textureData->yuv) {
1475 srcPixels = (
const void*)((
const Uint8*)srcPixels +
rect->
h * srcPitch);
1482 srcPixels = (
const void*)((
const Uint8*)srcPixels + ((
rect->
h + 1) / 2) * ((srcPitch + 1) / 2));
1488 if (textureData->nv12) {
1490 srcPixels = (
const void*)((
const Uint8*)srcPixels +
rect->
h * srcPitch);
1492 if (D3D11_UpdateTextureInternal(rendererData, textureData->mainTextureNV, 2,
rect->
x / 2,
rect->
y / 2, ((
rect->
w + 1) / 2), (
rect->
h + 1) / 2, srcPixels, 2*((srcPitch + 1) / 2)) < 0) {
1502 const Uint8 *Yplane,
int Ypitch,
1503 const Uint8 *Uplane,
int Upitch,
1504 const Uint8 *Vplane,
int Vpitch)
1507 D3D11_TextureData *textureData = (D3D11_TextureData *)
texture->driverdata;
1531 D3D11_TextureData *textureData = (D3D11_TextureData *)
texture->driverdata;
1533 D3D11_TEXTURE2D_DESC stagingTextureDesc;
1534 D3D11_MAPPED_SUBRESOURCE textureMemory;
1541 if (textureData->yuv || textureData->nv12) {
1543 if (!textureData->pixels) {
1544 textureData->pitch =
texture->w;
1546 if (!textureData->pixels) {
1550 textureData->locked_rect = *
rect;
1552 (
void *)((
Uint8 *)textureData->pixels +
rect->
y * textureData->pitch +
1554 *pitch = textureData->pitch;
1558 if (textureData->stagingTexture) {
1570 ID3D11Texture2D_GetDesc(textureData->mainTexture, &stagingTextureDesc);
1571 stagingTextureDesc.Width =
rect->
w;
1572 stagingTextureDesc.Height =
rect->
h;
1573 stagingTextureDesc.BindFlags = 0;
1574 stagingTextureDesc.MiscFlags = 0;
1575 stagingTextureDesc.CPUAccessFlags = D3D11_CPU_ACCESS_WRITE;
1576 stagingTextureDesc.Usage = D3D11_USAGE_STAGING;
1577 result = ID3D11Device_CreateTexture2D(rendererData->d3dDevice,
1578 &stagingTextureDesc,
1580 &textureData->stagingTexture);
1587 result = ID3D11DeviceContext_Map(rendererData->d3dContext,
1588 (ID3D11Resource *)textureData->stagingTexture,
1596 SAFE_RELEASE(textureData->stagingTexture);
1603 textureData->lockedTexturePositionX =
rect->
x;
1604 textureData->lockedTexturePositionY =
rect->
y;
1609 *
pixels = textureMemory.pData;
1610 *pitch = textureMemory.RowPitch;
1618 D3D11_TextureData *textureData = (D3D11_TextureData *)
texture->driverdata;
1624 if (textureData->yuv || textureData->nv12) {
1627 (
void *) ((
Uint8 *) textureData->pixels +
rect->
y * textureData->pitch +
1634 ID3D11DeviceContext_Unmap(rendererData->d3dContext,
1635 (ID3D11Resource *)textureData->stagingTexture,
1639 ID3D11DeviceContext_CopySubresourceRegion(rendererData->d3dContext,
1640 (ID3D11Resource *)textureData->mainTexture,
1642 textureData->lockedTexturePositionX,
1643 textureData->lockedTexturePositionY,
1645 (ID3D11Resource *)textureData->stagingTexture,
1649 SAFE_RELEASE(textureData->stagingTexture);
1656 D3D11_TextureData *textureData =
NULL;
1659 rendererData->currentOffscreenRenderTargetView =
NULL;
1663 textureData = (D3D11_TextureData *)
texture->driverdata;
1665 if (!textureData->mainTextureRenderTargetView) {
1666 return SDL_SetError(
"specified texture is not a render target");
1669 rendererData->currentOffscreenRenderTargetView = textureData->mainTextureRenderTargetView;
1680 data->vertexShaderConstantsData.model = *
matrix;
1682 data->vertexShaderConstantsData.model = MatrixIdentity();
1685 ID3D11DeviceContext_UpdateSubresource(
data->d3dContext,
1686 (ID3D11Resource *)
data->vertexShaderConstants,
1689 &
data->vertexShaderConstantsData,
1699 Float4X4 projection;
1702 BOOL swapDimensions;
1704 const int rotation = D3D11_GetRotationForCurrentRenderTarget(
renderer);
1721 case DXGI_MODE_ROTATION_IDENTITY:
1722 projection = MatrixIdentity();
1724 case DXGI_MODE_ROTATION_ROTATE270:
1727 case DXGI_MODE_ROTATION_ROTATE180:
1730 case DXGI_MODE_ROTATION_ROTATE90:
1734 return SDL_SetError(
"An unknown DisplayOrientation is being used");
1739 view.m[0][1] = 0.0f;
1740 view.m[0][2] = 0.0f;
1741 view.m[0][3] = 0.0f;
1742 view.m[1][0] = 0.0f;
1744 view.m[1][2] = 0.0f;
1745 view.m[1][3] = 0.0f;
1746 view.m[2][0] = 0.0f;
1747 view.m[2][1] = 0.0f;
1748 view.m[2][2] = 1.0f;
1749 view.m[2][3] = 0.0f;
1750 view.m[3][0] = -1.0f;
1751 view.m[3][1] = 1.0f;
1752 view.m[3][2] = 0.0f;
1753 view.m[3][3] = 1.0f;
1759 data->vertexShaderConstantsData.projectionAndView = MatrixMultiply(
1771 swapDimensions = D3D11_IsDisplayRotated90Degrees(rotation);
1772 if (swapDimensions) {
1785 viewport.TopLeftX = orientationAlignedViewport.
x;
1786 viewport.TopLeftY = orientationAlignedViewport.
y;
1787 viewport.Width = orientationAlignedViewport.
w;
1788 viewport.Height = orientationAlignedViewport.
h;
1792 ID3D11DeviceContext_RSSetViewports(
data->d3dContext, 1, &
viewport);
1803 ID3D11DeviceContext_RSSetScissorRects(
data->d3dContext, 0,
NULL);
1805 D3D11_RECT scissorRect;
1810 ID3D11DeviceContext_RSSetScissorRects(
data->d3dContext, 1, &scissorRect);
1820 ID3D11DeviceContext_OMSetRenderTargets(
data->d3dContext, 0,
NULL,
NULL);
1821 SAFE_RELEASE(
data->mainRenderTargetView);
1824 static ID3D11RenderTargetView *
1828 if (
data->currentOffscreenRenderTargetView) {
1829 return data->currentOffscreenRenderTargetView;
1831 return data->mainRenderTargetView;
1839 const float colorRGBA[] = {
1845 ID3D11DeviceContext_ClearRenderTargetView(
data->d3dContext,
1846 D3D11_GetCurrentRenderTargetView(
renderer),
1854 const void * vertexData,
size_t dataSizeInBytes)
1857 D3D11_BUFFER_DESC vertexBufferDesc;
1859 D3D11_SUBRESOURCE_DATA vertexBufferData;
1860 const UINT
stride =
sizeof(VertexPositionColor);
1863 if (rendererData->vertexBuffer) {
1864 ID3D11Buffer_GetDesc(rendererData->vertexBuffer, &vertexBufferDesc);
1869 if (rendererData->vertexBuffer && vertexBufferDesc.ByteWidth >= dataSizeInBytes) {
1870 D3D11_MAPPED_SUBRESOURCE mappedResource;
1871 result = ID3D11DeviceContext_Map(rendererData->d3dContext,
1872 (ID3D11Resource *)rendererData->vertexBuffer,
1874 D3D11_MAP_WRITE_DISCARD,
1882 SDL_memcpy(mappedResource.pData, vertexData, dataSizeInBytes);
1883 ID3D11DeviceContext_Unmap(rendererData->d3dContext, (ID3D11Resource *)rendererData->vertexBuffer, 0);
1885 SAFE_RELEASE(rendererData->vertexBuffer);
1887 vertexBufferDesc.ByteWidth = (UINT) dataSizeInBytes;
1888 vertexBufferDesc.Usage = D3D11_USAGE_DYNAMIC;
1889 vertexBufferDesc.BindFlags = D3D11_BIND_VERTEX_BUFFER;
1890 vertexBufferDesc.CPUAccessFlags = D3D11_CPU_ACCESS_WRITE;
1893 vertexBufferData.pSysMem = vertexData;
1894 vertexBufferData.SysMemPitch = 0;
1895 vertexBufferData.SysMemSlicePitch = 0;
1897 result = ID3D11Device_CreateBuffer(rendererData->d3dDevice,
1900 &rendererData->vertexBuffer
1907 ID3D11DeviceContext_IASetVertexBuffers(rendererData->d3dContext,
1910 &rendererData->vertexBuffer,
1923 ID3D11RasterizerState *rasterizerState;
1924 ID3D11RenderTargetView *renderTargetView = D3D11_GetCurrentRenderTargetView(
renderer);
1925 if (renderTargetView != rendererData->currentRenderTargetView) {
1926 ID3D11DeviceContext_OMSetRenderTargets(rendererData->d3dContext,
1931 rendererData->currentRenderTargetView = renderTargetView;
1935 rasterizerState = rendererData->mainRasterizer;
1937 rasterizerState = rendererData->clippedRasterizer;
1939 if (rasterizerState != rendererData->currentRasterizerState) {
1940 ID3D11DeviceContext_RSSetState(rendererData->d3dContext, rasterizerState);
1941 rendererData->currentRasterizerState = rasterizerState;
1949 ID3D11BlendState *blendState =
NULL;
1952 for (
i = 0;
i < rendererData->blendModesCount; ++
i) {
1953 if (
blendMode == rendererData->blendModes[
i].blendMode) {
1954 blendState = rendererData->blendModes[
i].blendState;
1966 if (blendState != rendererData->currentBlendState) {
1967 ID3D11DeviceContext_OMSetBlendState(rendererData->d3dContext, blendState, 0, 0xFFFFFFFF);
1968 rendererData->currentBlendState = blendState;
1974 ID3D11PixelShader *
shader,
1975 int numShaderResources,
1976 ID3D11ShaderResourceView ** shaderResources,
1980 ID3D11ShaderResourceView *shaderResource;
1981 if (
shader != rendererData->currentShader) {
1982 ID3D11DeviceContext_PSSetShader(rendererData->d3dContext,
shader,
NULL, 0);
1983 rendererData->currentShader =
shader;
1985 if (numShaderResources > 0) {
1986 shaderResource = shaderResources[0];
1988 shaderResource =
NULL;
1990 if (shaderResource != rendererData->currentShaderResource) {
1991 ID3D11DeviceContext_PSSetShaderResources(rendererData->d3dContext, 0, numShaderResources, shaderResources);
1992 rendererData->currentShaderResource = shaderResource;
1994 if (
sampler != rendererData->currentSampler) {
1995 ID3D11DeviceContext_PSSetSamplers(rendererData->d3dContext, 0, 1, &
sampler);
1996 rendererData->currentSampler =
sampler;
2002 D3D11_PRIMITIVE_TOPOLOGY primitiveTopology,
2007 ID3D11DeviceContext_IASetPrimitiveTopology(rendererData->d3dContext, primitiveTopology);
2008 ID3D11DeviceContext_Draw(rendererData->d3dContext, vertexCount, 0);
2017 VertexPositionColor *vertices;
2027 const VertexPositionColor
v = { {
points[
i].x + 0.5f,
points[
i].y + 0.5f, 0.0f }, { 0.0f, 0.0f }, {
r,
g,
b,
a } };
2033 if (D3D11_UpdateVertexBuffer(
renderer, vertices, (
unsigned int)
count *
sizeof(VertexPositionColor)) != 0) {
2038 D3D11_SetPixelShader(
2045 D3D11_RenderFinishDrawOp(
renderer, D3D11_PRIMITIVE_TOPOLOGY_POINTLIST,
count);
2056 VertexPositionColor *vertices;
2066 const VertexPositionColor
v = { {
points[
i].x + 0.5f,
points[
i].y + 0.5f, 0.0f }, { 0.0f, 0.0f }, {
r,
g,
b,
a } };
2072 if (D3D11_UpdateVertexBuffer(
renderer, vertices, (
unsigned int)
count *
sizeof(VertexPositionColor)) != 0) {
2077 D3D11_SetPixelShader(
2084 D3D11_RenderFinishDrawOp(
renderer, D3D11_PRIMITIVE_TOPOLOGY_LINESTRIP,
count);
2087 ID3D11DeviceContext_IASetPrimitiveTopology(rendererData->d3dContext, D3D11_PRIMITIVE_TOPOLOGY_POINTLIST);
2088 ID3D11DeviceContext_Draw(rendererData->d3dContext, 1,
count - 1);
2109 VertexPositionColor vertices[] = {
2118 if (D3D11_UpdateVertexBuffer(
renderer, vertices,
sizeof(vertices)) != 0) {
2122 D3D11_SetPixelShader(
2129 D3D11_RenderFinishDrawOp(
renderer, D3D11_PRIMITIVE_TOPOLOGY_TRIANGLESTRIP,
SDL_arraysize(vertices));
2139 D3D11_TextureData *textureData = (D3D11_TextureData *)
texture->driverdata;
2140 ID3D11SamplerState *textureSampler;
2142 switch (textureData->scaleMode) {
2143 case D3D11_FILTER_MIN_MAG_MIP_POINT:
2144 textureSampler = rendererData->nearestPixelSampler;
2146 case D3D11_FILTER_MIN_MAG_MIP_LINEAR:
2147 textureSampler = rendererData->linearSampler;
2150 return SDL_SetError(
"Unknown scale mode: %d\n", textureData->scaleMode);
2153 if (textureData->yuv) {
2154 ID3D11ShaderResourceView *shaderResources[] = {
2155 textureData->mainTextureResourceView,
2156 textureData->mainTextureResourceViewU,
2157 textureData->mainTextureResourceViewV
2172 return SDL_SetError(
"Unsupported YUV conversion mode");
2175 D3D11_SetPixelShader(
2177 rendererData->pixelShaders[
shader],
2182 }
else if (textureData->nv12) {
2183 ID3D11ShaderResourceView *shaderResources[] = {
2184 textureData->mainTextureResourceView,
2185 textureData->mainTextureResourceViewNV,
2200 return SDL_SetError(
"Unsupported YUV conversion mode");
2203 D3D11_SetPixelShader(
2205 rendererData->pixelShaders[
shader],
2211 D3D11_SetPixelShader(
2215 &textureData->mainTextureResourceView,
2226 float minu, maxu, minv, maxv;
2228 VertexPositionColor vertices[4];
2233 minu = (float) srcrect->
x /
texture->w;
2234 maxu = (
float) (srcrect->
x + srcrect->
w) /
texture->w;
2235 minv = (
float) srcrect->
y /
texture->h;
2236 maxv = (float) (srcrect->
y + srcrect->
h) /
texture->h;
2251 vertices[0].pos.x = dstrect->
x;
2252 vertices[0].pos.y = dstrect->
y;
2253 vertices[0].pos.z = 0.0f;
2254 vertices[0].tex.x = minu;
2255 vertices[0].tex.y = minv;
2256 vertices[0].color =
color;
2258 vertices[1].pos.x = dstrect->
x;
2259 vertices[1].pos.y = dstrect->
y + dstrect->
h;
2260 vertices[1].pos.z = 0.0f;
2261 vertices[1].tex.x = minu;
2262 vertices[1].tex.y = maxv;
2263 vertices[1].color =
color;
2265 vertices[2].pos.x = dstrect->
x + dstrect->
w;
2266 vertices[2].pos.y = dstrect->
y;
2267 vertices[2].pos.z = 0.0f;
2268 vertices[2].tex.x = maxu;
2269 vertices[2].tex.y = minv;
2270 vertices[2].color =
color;
2272 vertices[3].pos.x = dstrect->
x + dstrect->
w;
2273 vertices[3].pos.y = dstrect->
y + dstrect->
h;
2274 vertices[3].pos.z = 0.0f;
2275 vertices[3].tex.x = maxu;
2276 vertices[3].tex.y = maxv;
2277 vertices[3].color =
color;
2279 if (D3D11_UpdateVertexBuffer(
renderer, vertices,
sizeof(vertices)) != 0) {
2287 D3D11_RenderFinishDrawOp(
renderer, D3D11_PRIMITIVE_TOPOLOGY_TRIANGLESTRIP,
sizeof(vertices) /
sizeof(VertexPositionColor));
2297 float minu, maxu, minv, maxv;
2299 Float4X4 modelMatrix;
2300 float minx, maxx, miny, maxy;
2301 VertexPositionColor vertices[4];
2306 minu = (float) srcrect->
x /
texture->w;
2307 maxu = (
float) (srcrect->
x + srcrect->
w) /
texture->w;
2308 minv = (
float) srcrect->
y /
texture->h;
2309 maxv = (float) (srcrect->
y + srcrect->
h) /
texture->h;
2335 modelMatrix = MatrixMultiply(
2336 MatrixRotationZ((
float)(M_PI * (
float)
angle / 180.0
f)),
2337 MatrixTranslation(dstrect->
x + center->
x, dstrect->
y + center->
y, 0)
2339 D3D11_SetModelMatrix(
renderer, &modelMatrix);
2342 maxx = dstrect->
w - center->
x;
2344 maxy = dstrect->
h - center->
y;
2346 vertices[0].pos.x = minx;
2347 vertices[0].pos.y = miny;
2348 vertices[0].pos.z = 0.0f;
2349 vertices[0].tex.x = minu;
2350 vertices[0].tex.y = minv;
2351 vertices[0].color =
color;
2353 vertices[1].pos.x = minx;
2354 vertices[1].pos.y = maxy;
2355 vertices[1].pos.z = 0.0f;
2356 vertices[1].tex.x = minu;
2357 vertices[1].tex.y = maxv;
2358 vertices[1].color =
color;
2360 vertices[2].pos.x = maxx;
2361 vertices[2].pos.y = miny;
2362 vertices[2].pos.z = 0.0f;
2363 vertices[2].tex.x = maxu;
2364 vertices[2].tex.y = minv;
2365 vertices[2].color =
color;
2367 vertices[3].pos.x = maxx;
2368 vertices[3].pos.y = maxy;
2369 vertices[3].pos.z = 0.0f;
2370 vertices[3].tex.x = maxu;
2371 vertices[3].tex.y = maxv;
2372 vertices[3].color =
color;
2374 if (D3D11_UpdateVertexBuffer(
renderer, vertices,
sizeof(vertices)) != 0) {
2382 D3D11_RenderFinishDrawOp(
renderer, D3D11_PRIMITIVE_TOPOLOGY_TRIANGLESTRIP,
sizeof(vertices) /
sizeof(VertexPositionColor));
2394 ID3D11Texture2D *backBuffer =
NULL;
2395 ID3D11Texture2D *stagingTexture =
NULL;
2398 D3D11_TEXTURE2D_DESC stagingTextureDesc;
2399 D3D11_RECT srcRect = {0, 0, 0, 0};
2401 D3D11_MAPPED_SUBRESOURCE textureMemory;
2404 result = IDXGISwapChain_GetBuffer(
data->swapChain,
2406 &SDL_IID_ID3D11Texture2D,
2407 (
void **)&backBuffer
2415 ID3D11Texture2D_GetDesc(backBuffer, &stagingTextureDesc);
2416 stagingTextureDesc.Width =
rect->
w;
2417 stagingTextureDesc.Height =
rect->
h;
2418 stagingTextureDesc.BindFlags = 0;
2419 stagingTextureDesc.MiscFlags = 0;
2420 stagingTextureDesc.CPUAccessFlags = D3D11_CPU_ACCESS_READ;
2421 stagingTextureDesc.Usage = D3D11_USAGE_STAGING;
2422 result = ID3D11Device_CreateTexture2D(
data->d3dDevice,
2423 &stagingTextureDesc,
2437 srcBox.left = srcRect.left;
2438 srcBox.right = srcRect.right;
2439 srcBox.top = srcRect.top;
2440 srcBox.bottom = srcRect.bottom;
2443 ID3D11DeviceContext_CopySubresourceRegion(
data->d3dContext,
2444 (ID3D11Resource *)stagingTexture,
2447 (ID3D11Resource *)backBuffer,
2452 result = ID3D11DeviceContext_Map(
data->d3dContext,
2453 (ID3D11Resource *)stagingTexture,
2468 D3D11_DXGIFormatToSDLPixelFormat(stagingTextureDesc.Format),
2469 textureMemory.pData,
2470 textureMemory.RowPitch,
2477 char errorMessage[1024];
2484 ID3D11DeviceContext_Unmap(
data->d3dContext,
2485 (ID3D11Resource *)stagingTexture,
2491 SAFE_RELEASE(backBuffer);
2492 SAFE_RELEASE(stagingTexture);
2503 DXGI_PRESENT_PARAMETERS parameters;
2507 #if WINAPI_FAMILY == WINAPI_FAMILY_PHONE_APP
2510 result = IDXGISwapChain_Present(
data->swapChain, syncInterval, presentFlags);
2517 presentFlags = DXGI_PRESENT_DO_NOT_WAIT;
2524 result = IDXGISwapChain1_Present1(
data->swapChain, syncInterval, presentFlags, ¶meters);
2531 ID3D11DeviceContext1_DiscardView(
data->d3dContext, (ID3D11View*)
data->mainRenderTargetView);
2534 data->currentRenderTargetView =
NULL;
2542 if (
result == DXGI_ERROR_DEVICE_REMOVED ) {
2544 }
else if (
result == DXGI_ERROR_INVALID_CALL) {
2546 D3D11_CreateWindowSizeDependentResources(
renderer);