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; }
66 Float4X4 projectionAndView;
67 } VertexShaderConstants;
75 } VertexPositionColor;
80 ID3D11Texture2D *mainTexture;
81 ID3D11ShaderResourceView *mainTextureResourceView;
82 ID3D11RenderTargetView *mainTextureRenderTargetView;
83 ID3D11Texture2D *stagingTexture;
84 int lockedTexturePositionX;
85 int lockedTexturePositionY;
86 D3D11_FILTER scaleMode;
90 ID3D11Texture2D *mainTextureU;
91 ID3D11ShaderResourceView *mainTextureResourceViewU;
92 ID3D11Texture2D *mainTextureV;
93 ID3D11ShaderResourceView *mainTextureResourceViewV;
97 ID3D11Texture2D *mainTextureNV;
98 ID3D11ShaderResourceView *mainTextureResourceViewNV;
109 ID3D11BlendState *blendState;
117 IDXGIFactory2 *dxgiFactory;
118 IDXGIAdapter *dxgiAdapter;
119 ID3D11Device1 *d3dDevice;
120 ID3D11DeviceContext1 *d3dContext;
121 IDXGISwapChain1 *swapChain;
122 DXGI_SWAP_EFFECT swapEffect;
123 ID3D11RenderTargetView *mainRenderTargetView;
124 ID3D11RenderTargetView *currentOffscreenRenderTargetView;
125 ID3D11InputLayout *inputLayout;
126 ID3D11Buffer *vertexBuffers[8];
127 size_t vertexBufferSizes[8];
128 ID3D11VertexShader *vertexShader;
131 D3D11_BlendMode *blendModes;
132 ID3D11SamplerState *nearestPixelSampler;
133 ID3D11SamplerState *linearSampler;
134 D3D_FEATURE_LEVEL featureLevel;
137 ID3D11RasterizerState *mainRasterizer;
138 ID3D11RasterizerState *clippedRasterizer;
141 VertexShaderConstants vertexShaderConstantsData;
142 ID3D11Buffer *vertexShaderConstants;
145 DXGI_MODE_ROTATION rotation;
146 ID3D11RenderTargetView *currentRenderTargetView;
147 ID3D11RasterizerState *currentRasterizerState;
148 ID3D11BlendState *currentBlendState;
149 ID3D11PixelShader *currentShader;
150 ID3D11ShaderResourceView *currentShaderResource;
151 ID3D11SamplerState *currentSampler;
156 int currentViewportRotation;
159 int currentVertexBuffer;
173 #pragma GCC diagnostic push
174 #pragma GCC diagnostic ignored "-Wunused-const-variable"
177 static const GUID SDL_IID_IDXGIFactory2 = { 0x50c83a1c, 0xe072, 0x4c48, { 0x87, 0xb0, 0x36, 0x30, 0xfa, 0x36, 0xa6, 0xd0 } };
178 static const GUID SDL_IID_IDXGIDevice1 = { 0x77db970f, 0x6276, 0x48ba, { 0xba, 0x28, 0x07, 0x01, 0x43, 0xb4, 0x39, 0x2c } };
179 static const GUID SDL_IID_IDXGIDevice3 = { 0x6007896c, 0x3244, 0x4afd, { 0xbf, 0x18, 0xa6, 0xd3, 0xbe, 0xda, 0x50, 0x23 } };
180 static const GUID SDL_IID_ID3D11Texture2D = { 0x6f15aaf2, 0xd208, 0x4e89, { 0x9a, 0xb4, 0x48, 0x95, 0x35, 0xd3, 0x4f, 0x9c } };
181 static const GUID SDL_IID_ID3D11Device1 = { 0xa04bfb29, 0x08ef, 0x43d6, { 0xa4, 0x9c, 0xa9, 0xbd, 0xbd, 0xcb, 0xe6, 0x86 } };
182 static const GUID SDL_IID_ID3D11DeviceContext1 = { 0xbb2c6faa, 0xb5fb, 0x4082, { 0x8e, 0x6b, 0x38, 0x8b, 0x8c, 0xfa, 0x90, 0xe1 } };
183 static const GUID SDL_IID_ID3D11Debug = { 0x79cf2233, 0x7536, 0x4948, { 0x9d, 0x36, 0x1e, 0x46, 0x92, 0xdc, 0x57, 0x60 } };
186 #pragma GCC diagnostic pop
192 D3D11_DXGIFormatToSDLPixelFormat(DXGI_FORMAT dxgiFormat)
194 switch (dxgiFormat) {
195 case DXGI_FORMAT_B8G8R8A8_UNORM:
197 case DXGI_FORMAT_B8G8R8X8_UNORM:
205 SDLPixelFormatToDXGIFormat(
Uint32 sdlFormat)
209 return DXGI_FORMAT_B8G8R8A8_UNORM;
211 return DXGI_FORMAT_B8G8R8X8_UNORM;
216 return DXGI_FORMAT_R8_UNORM;
218 return DXGI_FORMAT_UNKNOWN;
239 SAFE_RELEASE(
data->dxgiFactory);
240 SAFE_RELEASE(
data->dxgiAdapter);
241 SAFE_RELEASE(
data->d3dDevice);
242 SAFE_RELEASE(
data->d3dContext);
243 SAFE_RELEASE(
data->swapChain);
244 SAFE_RELEASE(
data->mainRenderTargetView);
245 SAFE_RELEASE(
data->currentOffscreenRenderTargetView);
246 SAFE_RELEASE(
data->inputLayout);
248 SAFE_RELEASE(
data->vertexBuffers[
i]);
250 SAFE_RELEASE(
data->vertexShader);
252 SAFE_RELEASE(
data->pixelShaders[
i]);
254 if (
data->blendModesCount > 0) {
255 for (
i = 0;
i <
data->blendModesCount; ++
i) {
256 SAFE_RELEASE(
data->blendModes[
i].blendState);
260 data->blendModesCount = 0;
262 SAFE_RELEASE(
data->nearestPixelSampler);
263 SAFE_RELEASE(
data->linearSampler);
264 SAFE_RELEASE(
data->mainRasterizer);
265 SAFE_RELEASE(
data->clippedRasterizer);
266 SAFE_RELEASE(
data->vertexShaderConstants);
268 data->swapEffect = (DXGI_SWAP_EFFECT) 0;
269 data->rotation = DXGI_MODE_ROTATION_UNSPECIFIED;
270 data->currentRenderTargetView =
NULL;
271 data->currentRasterizerState =
NULL;
280 if (
data->hD3D11Mod) {
284 if (
data->hDXGIMod) {
306 return D3D11_BLEND_ZERO;
308 return D3D11_BLEND_ONE;
310 return D3D11_BLEND_SRC_COLOR;
312 return D3D11_BLEND_INV_SRC_COLOR;
314 return D3D11_BLEND_SRC_ALPHA;
316 return D3D11_BLEND_INV_SRC_ALPHA;
318 return D3D11_BLEND_DEST_COLOR;
320 return D3D11_BLEND_INV_DEST_COLOR;
322 return D3D11_BLEND_DEST_ALPHA;
324 return D3D11_BLEND_INV_DEST_ALPHA;
326 return (D3D11_BLEND)0;
334 return D3D11_BLEND_OP_ADD;
336 return D3D11_BLEND_OP_SUBTRACT;
338 return D3D11_BLEND_OP_REV_SUBTRACT;
340 return D3D11_BLEND_OP_MIN;
342 return D3D11_BLEND_OP_MAX;
344 return (D3D11_BLEND_OP)0;
348 static ID3D11BlendState *
358 ID3D11BlendState *blendState =
NULL;
359 D3D11_BlendMode *blendModes;
362 D3D11_BLEND_DESC blendDesc;
364 blendDesc.AlphaToCoverageEnable =
FALSE;
365 blendDesc.IndependentBlendEnable =
FALSE;
366 blendDesc.RenderTarget[0].BlendEnable =
TRUE;
367 blendDesc.RenderTarget[0].SrcBlend = GetBlendFunc(srcColorFactor);
368 blendDesc.RenderTarget[0].DestBlend = GetBlendFunc(dstColorFactor);
369 blendDesc.RenderTarget[0].BlendOp = GetBlendEquation(colorOperation);
370 blendDesc.RenderTarget[0].SrcBlendAlpha = GetBlendFunc(srcAlphaFactor);
371 blendDesc.RenderTarget[0].DestBlendAlpha = GetBlendFunc(dstAlphaFactor);
372 blendDesc.RenderTarget[0].BlendOpAlpha = GetBlendEquation(alphaOperation);
373 blendDesc.RenderTarget[0].RenderTargetWriteMask = D3D11_COLOR_WRITE_ENABLE_ALL;
374 result = ID3D11Device_CreateBlendState(
data->d3dDevice, &blendDesc, &blendState);
380 blendModes = (D3D11_BlendMode *)
SDL_realloc(
data->blendModes, (
data->blendModesCount + 1) *
sizeof(*blendModes));
382 SAFE_RELEASE(blendState);
387 blendModes[
data->blendModesCount].blendState = blendState;
388 data->blendModes = blendModes;
389 ++
data->blendModesCount;
398 typedef HRESULT(WINAPI *PFN_CREATE_DXGI_FACTORY)(REFIID riid,
void **ppFactory);
399 PFN_CREATE_DXGI_FACTORY CreateDXGIFactoryFunc;
401 PFN_D3D11_CREATE_DEVICE D3D11CreateDeviceFunc;
402 ID3D11Device *d3dDevice =
NULL;
403 ID3D11DeviceContext *d3dContext =
NULL;
404 IDXGIDevice1 *dxgiDevice =
NULL;
414 D3D_FEATURE_LEVEL featureLevels[] =
416 D3D_FEATURE_LEVEL_11_1,
417 D3D_FEATURE_LEVEL_11_0,
418 D3D_FEATURE_LEVEL_10_1,
419 D3D_FEATURE_LEVEL_10_0,
420 D3D_FEATURE_LEVEL_9_3,
421 D3D_FEATURE_LEVEL_9_2,
422 D3D_FEATURE_LEVEL_9_1
425 D3D11_BUFFER_DESC constantBufferDesc;
426 D3D11_SAMPLER_DESC samplerDesc;
427 D3D11_RASTERIZER_DESC rasterDesc;
430 CreateDXGIFactoryFunc = CreateDXGIFactory1;
431 D3D11CreateDeviceFunc = D3D11CreateDevice;
434 if (!
data->hDXGIMod) {
439 CreateDXGIFactoryFunc = (PFN_CREATE_DXGI_FACTORY)
SDL_LoadFunction(
data->hDXGIMod,
"CreateDXGIFactory");
440 if (!CreateDXGIFactoryFunc) {
446 if (!
data->hD3D11Mod) {
451 D3D11CreateDeviceFunc = (PFN_D3D11_CREATE_DEVICE)
SDL_LoadFunction(
data->hD3D11Mod,
"D3D11CreateDevice");
452 if (!D3D11CreateDeviceFunc) {
458 result = CreateDXGIFactoryFunc(&SDL_IID_IDXGIFactory2, (
void **)&
data->dxgiFactory);
465 result = IDXGIFactory2_EnumAdapters(
data->dxgiFactory, 0, &
data->dxgiAdapter);
474 creationFlags = D3D11_CREATE_DEVICE_BGRA_SUPPORT;
478 creationFlags |= D3D11_CREATE_DEVICE_DEBUG;
482 result = D3D11CreateDeviceFunc(
484 D3D_DRIVER_TYPE_UNKNOWN,
499 result = ID3D11Device_QueryInterface(d3dDevice, &SDL_IID_ID3D11Device1, (
void **)&
data->d3dDevice);
505 result = ID3D11DeviceContext_QueryInterface(d3dContext, &SDL_IID_ID3D11DeviceContext1, (
void **)&
data->d3dContext);
511 result = ID3D11Device_QueryInterface(d3dDevice, &SDL_IID_IDXGIDevice1, (
void **)&dxgiDevice);
520 result = IDXGIDevice1_SetMaximumFrameLatency(dxgiDevice, 1);
530 switch (
data->featureLevel) {
531 case D3D_FEATURE_LEVEL_11_1:
532 case D3D_FEATURE_LEVEL_11_0:
536 case D3D_FEATURE_LEVEL_10_1:
537 case D3D_FEATURE_LEVEL_10_0:
541 case D3D_FEATURE_LEVEL_9_3:
545 case D3D_FEATURE_LEVEL_9_2:
546 case D3D_FEATURE_LEVEL_9_1:
551 SDL_SetError(
"%s, Unexpected feature level: %d", __FUNCTION__,
data->featureLevel);
568 constantBufferDesc.ByteWidth =
sizeof(VertexShaderConstants);
569 constantBufferDesc.Usage = D3D11_USAGE_DEFAULT;
570 constantBufferDesc.BindFlags = D3D11_BIND_CONSTANT_BUFFER;
571 result = ID3D11Device_CreateBuffer(
data->d3dDevice,
574 &
data->vertexShaderConstants
583 samplerDesc.Filter = D3D11_FILTER_MIN_MAG_MIP_POINT;
584 samplerDesc.AddressU = D3D11_TEXTURE_ADDRESS_CLAMP;
585 samplerDesc.AddressV = D3D11_TEXTURE_ADDRESS_CLAMP;
586 samplerDesc.AddressW = D3D11_TEXTURE_ADDRESS_CLAMP;
587 samplerDesc.MipLODBias = 0.0f;
588 samplerDesc.MaxAnisotropy = 1;
589 samplerDesc.ComparisonFunc = D3D11_COMPARISON_ALWAYS;
590 samplerDesc.MinLOD = 0.0f;
591 samplerDesc.MaxLOD = D3D11_FLOAT32_MAX;
592 result = ID3D11Device_CreateSamplerState(
data->d3dDevice,
594 &
data->nearestPixelSampler
601 samplerDesc.Filter = D3D11_FILTER_MIN_MAG_MIP_LINEAR;
602 result = ID3D11Device_CreateSamplerState(
data->d3dDevice,
613 rasterDesc.AntialiasedLineEnable =
FALSE;
614 rasterDesc.CullMode = D3D11_CULL_NONE;
615 rasterDesc.DepthBias = 0;
616 rasterDesc.DepthBiasClamp = 0.0f;
617 rasterDesc.DepthClipEnable =
TRUE;
618 rasterDesc.FillMode = D3D11_FILL_SOLID;
619 rasterDesc.FrontCounterClockwise =
FALSE;
620 rasterDesc.MultisampleEnable =
FALSE;
621 rasterDesc.ScissorEnable =
FALSE;
622 rasterDesc.SlopeScaledDepthBias = 0.0f;
623 result = ID3D11Device_CreateRasterizerState(
data->d3dDevice, &rasterDesc, &
data->mainRasterizer);
629 rasterDesc.ScissorEnable =
TRUE;
630 result = ID3D11Device_CreateRasterizerState(
data->d3dDevice, &rasterDesc, &
data->clippedRasterizer);
646 ID3D11DeviceContext_IASetInputLayout(
data->d3dContext,
data->inputLayout);
647 ID3D11DeviceContext_VSSetShader(
data->d3dContext,
data->vertexShader,
NULL, 0);
648 ID3D11DeviceContext_VSSetConstantBuffers(
data->d3dContext, 0, 1, &
data->vertexShaderConstants);
651 SAFE_RELEASE(d3dDevice);
652 SAFE_RELEASE(d3dContext);
653 SAFE_RELEASE(dxgiDevice);
659 static DXGI_MODE_ROTATION
660 D3D11_GetCurrentRotation()
663 return DXGI_MODE_ROTATION_IDENTITY;
669 D3D11_IsDisplayRotated90Degrees(DXGI_MODE_ROTATION rotation)
672 case DXGI_MODE_ROTATION_ROTATE90:
673 case DXGI_MODE_ROTATION_ROTATE270:
684 if (
data->currentOffscreenRenderTargetView) {
685 return DXGI_MODE_ROTATION_IDENTITY;
687 return data->rotation;
694 const int rotation = D3D11_GetRotationForCurrentRenderTarget(
renderer);
696 case DXGI_MODE_ROTATION_IDENTITY:
697 outRect->left = sdlRect->
x;
698 outRect->right = sdlRect->
x + sdlRect->
w;
699 outRect->top = sdlRect->
y;
700 outRect->bottom = sdlRect->
y + sdlRect->
h;
701 if (includeViewportOffset) {
708 case DXGI_MODE_ROTATION_ROTATE270:
709 outRect->left = sdlRect->
y;
710 outRect->right = sdlRect->
y + sdlRect->
h;
714 case DXGI_MODE_ROTATION_ROTATE180:
720 case DXGI_MODE_ROTATION_ROTATE90:
723 outRect->top = sdlRect->
x;
724 outRect->bottom = sdlRect->
x + sdlRect->
h;
727 return SDL_SetError(
"The physical display is in an unknown or unsupported rotation");
737 IUnknown *coreWindow = D3D11_GetCoreWindowFromSDLRenderer(
renderer);
738 const BOOL usingXAML = (coreWindow ==
NULL);
740 IUnknown *coreWindow =
NULL;
741 const BOOL usingXAML =
FALSE;
746 DXGI_SWAP_CHAIN_DESC1 swapChainDesc;
748 swapChainDesc.Width =
w;
749 swapChainDesc.Height =
h;
750 swapChainDesc.Format = DXGI_FORMAT_B8G8R8A8_UNORM;
751 swapChainDesc.Stereo =
FALSE;
752 swapChainDesc.SampleDesc.Count = 1;
753 swapChainDesc.SampleDesc.Quality = 0;
754 swapChainDesc.BufferUsage = DXGI_USAGE_RENDER_TARGET_OUTPUT;
755 swapChainDesc.BufferCount = 2;
756 #if WINAPI_FAMILY == WINAPI_FAMILY_PHONE_APP
757 swapChainDesc.Scaling = DXGI_SCALING_STRETCH;
758 swapChainDesc.SwapEffect = DXGI_SWAP_EFFECT_DISCARD;
762 swapChainDesc.Scaling = DXGI_SCALING_STRETCH;
764 swapChainDesc.Scaling = DXGI_SCALING_NONE;
766 swapChainDesc.SwapEffect = DXGI_SWAP_EFFECT_FLIP_SEQUENTIAL;
768 swapChainDesc.Flags = 0;
771 result = IDXGIFactory2_CreateSwapChainForCoreWindow(
data->dxgiFactory,
772 (IUnknown *)
data->d3dDevice,
782 }
else if (usingXAML) {
783 result = IDXGIFactory2_CreateSwapChainForComposition(
data->dxgiFactory,
784 (IUnknown *)
data->d3dDevice,
793 #if WINAPI_FAMILY == WINAPI_FAMILY_APP
800 SDL_SetError(SDL_COMPOSE_ERROR(
"XAML support is not yet available for Windows Phone"));
810 result = IDXGIFactory2_CreateSwapChainForHwnd(
data->dxgiFactory,
811 (IUnknown *)
data->d3dDevice,
823 IDXGIFactory_MakeWindowAssociation(
data->dxgiFactory, windowinfo.
info.win.
window, DXGI_MWA_NO_WINDOW_CHANGES);
825 SDL_SetError(__FUNCTION__
", Unable to find something to attach a swap chain to");
829 data->swapEffect = swapChainDesc.SwapEffect;
832 SAFE_RELEASE(coreWindow);
840 ID3D11DeviceContext_OMSetRenderTargets(
data->d3dContext, 0,
NULL,
NULL);
841 SAFE_RELEASE(
data->mainRenderTargetView);
881 ID3D11Texture2D *backBuffer =
NULL;
886 D3D11_ReleaseMainRenderTargetView(
renderer);
892 data->rotation = D3D11_GetCurrentRotation();
894 if (D3D11_IsDisplayRotated90Degrees(
data->rotation)) {
900 if (
data->swapChain) {
902 #if !defined(__WINRT__) || (WINAPI_FAMILY != WINAPI_FAMILY_PHONE_APP)
904 result = IDXGISwapChain_ResizeBuffers(
data->swapChain,
910 if (
result == DXGI_ERROR_DEVICE_REMOVED) {
930 #if WINAPI_FAMILY != WINAPI_FAMILY_PHONE_APP
947 if (
data->swapEffect == DXGI_SWAP_EFFECT_FLIP_SEQUENTIAL) {
948 result = IDXGISwapChain1_SetRotation(
data->swapChain,
data->rotation);
956 result = IDXGISwapChain_GetBuffer(
data->swapChain,
958 &SDL_IID_ID3D11Texture2D,
967 result = ID3D11Device_CreateRenderTargetView(
data->d3dDevice,
968 (ID3D11Resource *)backBuffer,
970 &
data->mainRenderTargetView
980 SAFE_RELEASE(backBuffer);
988 return D3D11_CreateWindowSizeDependentResources(
renderer);
995 #if NTDDI_VERSION > NTDDI_WIN8
998 IDXGIDevice3 *dxgiDevice =
NULL;
1000 result = ID3D11Device_QueryInterface(
data->d3dDevice, &SDL_IID_IDXGIDevice3, &dxgiDevice);
1006 IDXGIDevice3_Trim(dxgiDevice);
1007 SAFE_RELEASE(dxgiDevice);
1016 D3D11_UpdateForWindowSizeChange(
renderer);
1030 if (!GetBlendFunc(srcColorFactor) || !GetBlendFunc(srcAlphaFactor) ||
1031 !GetBlendEquation(colorOperation) ||
1032 !GetBlendFunc(dstColorFactor) || !GetBlendFunc(dstAlphaFactor) ||
1033 !GetBlendEquation(alphaOperation)) {
1043 D3D11_TextureData *textureData;
1045 DXGI_FORMAT textureFormat = SDLPixelFormatToDXGIFormat(
texture->format);
1046 D3D11_TEXTURE2D_DESC textureDesc;
1047 D3D11_SHADER_RESOURCE_VIEW_DESC resourceViewDesc;
1049 if (textureFormat == DXGI_FORMAT_UNKNOWN) {
1050 return SDL_SetError(
"%s, An unsupported SDL pixel format (0x%x) was specified",
1051 __FUNCTION__,
texture->format);
1054 textureData = (D3D11_TextureData*)
SDL_calloc(1,
sizeof(*textureData));
1059 textureData->scaleMode = (
texture->scaleMode ==
SDL_ScaleModeNearest) ? D3D11_FILTER_MIN_MAG_MIP_POINT : D3D11_FILTER_MIN_MAG_MIP_LINEAR;
1061 texture->driverdata = textureData;
1064 textureDesc.Width =
texture->w;
1065 textureDesc.Height =
texture->h;
1066 textureDesc.MipLevels = 1;
1067 textureDesc.ArraySize = 1;
1068 textureDesc.Format = textureFormat;
1069 textureDesc.SampleDesc.Count = 1;
1070 textureDesc.SampleDesc.Quality = 0;
1071 textureDesc.MiscFlags = 0;
1074 textureDesc.Usage = D3D11_USAGE_DYNAMIC;
1075 textureDesc.CPUAccessFlags = D3D11_CPU_ACCESS_WRITE;
1077 textureDesc.Usage = D3D11_USAGE_DEFAULT;
1078 textureDesc.CPUAccessFlags = 0;
1082 textureDesc.BindFlags = D3D11_BIND_SHADER_RESOURCE | D3D11_BIND_RENDER_TARGET;
1084 textureDesc.BindFlags = D3D11_BIND_SHADER_RESOURCE;
1087 result = ID3D11Device_CreateTexture2D(rendererData->d3dDevice,
1090 &textureData->mainTexture
1102 textureDesc.Width = (textureDesc.Width + 1) / 2;
1103 textureDesc.Height = (textureDesc.Height + 1) / 2;
1105 result = ID3D11Device_CreateTexture2D(rendererData->d3dDevice,
1108 &textureData->mainTextureU
1116 result = ID3D11Device_CreateTexture2D(rendererData->d3dDevice,
1119 &textureData->mainTextureV
1130 D3D11_TEXTURE2D_DESC nvTextureDesc = textureDesc;
1134 nvTextureDesc.Format = DXGI_FORMAT_R8G8_UNORM;
1135 nvTextureDesc.Width = (textureDesc.Width + 1) / 2;
1136 nvTextureDesc.Height = (textureDesc.Height + 1) / 2;
1138 result = ID3D11Device_CreateTexture2D(rendererData->d3dDevice,
1141 &textureData->mainTextureNV
1150 resourceViewDesc.Format = textureDesc.Format;
1151 resourceViewDesc.ViewDimension = D3D11_SRV_DIMENSION_TEXTURE2D;
1152 resourceViewDesc.Texture2D.MostDetailedMip = 0;
1153 resourceViewDesc.Texture2D.MipLevels = textureDesc.MipLevels;
1154 result = ID3D11Device_CreateShaderResourceView(rendererData->d3dDevice,
1155 (ID3D11Resource *)textureData->mainTexture,
1157 &textureData->mainTextureResourceView
1165 if (textureData->yuv) {
1166 result = ID3D11Device_CreateShaderResourceView(rendererData->d3dDevice,
1167 (ID3D11Resource *)textureData->mainTextureU,
1169 &textureData->mainTextureResourceViewU
1176 result = ID3D11Device_CreateShaderResourceView(rendererData->d3dDevice,
1177 (ID3D11Resource *)textureData->mainTextureV,
1179 &textureData->mainTextureResourceViewV
1188 if (textureData->nv12) {
1189 D3D11_SHADER_RESOURCE_VIEW_DESC nvResourceViewDesc = resourceViewDesc;
1191 nvResourceViewDesc.Format = DXGI_FORMAT_R8G8_UNORM;
1193 result = ID3D11Device_CreateShaderResourceView(rendererData->d3dDevice,
1194 (ID3D11Resource *)textureData->mainTextureNV,
1195 &nvResourceViewDesc,
1196 &textureData->mainTextureResourceViewNV
1206 D3D11_RENDER_TARGET_VIEW_DESC renderTargetViewDesc;
1207 renderTargetViewDesc.Format = textureDesc.Format;
1208 renderTargetViewDesc.ViewDimension = D3D11_RTV_DIMENSION_TEXTURE2D;
1209 renderTargetViewDesc.Texture2D.MipSlice = 0;
1211 result = ID3D11Device_CreateRenderTargetView(rendererData->d3dDevice,
1212 (ID3D11Resource *)textureData->mainTexture,
1213 &renderTargetViewDesc,
1214 &textureData->mainTextureRenderTargetView);
1229 D3D11_TextureData *
data = (D3D11_TextureData *)
texture->driverdata;
1235 SAFE_RELEASE(
data->mainTexture);
1236 SAFE_RELEASE(
data->mainTextureResourceView);
1237 SAFE_RELEASE(
data->mainTextureRenderTargetView);
1238 SAFE_RELEASE(
data->stagingTexture);
1239 SAFE_RELEASE(
data->mainTextureU);
1240 SAFE_RELEASE(
data->mainTextureResourceViewU);
1241 SAFE_RELEASE(
data->mainTextureV);
1242 SAFE_RELEASE(
data->mainTextureResourceViewV);
1249 D3D11_UpdateTextureInternal(D3D11_RenderData *rendererData, ID3D11Texture2D *
texture,
int bpp,
int x,
int y,
int w,
int h,
const void *
pixels,
int pitch)
1251 ID3D11Texture2D *stagingTexture;
1257 D3D11_TEXTURE2D_DESC stagingTextureDesc;
1258 D3D11_MAPPED_SUBRESOURCE textureMemory;
1261 ID3D11Texture2D_GetDesc(
texture, &stagingTextureDesc);
1262 stagingTextureDesc.Width =
w;
1263 stagingTextureDesc.Height =
h;
1264 stagingTextureDesc.BindFlags = 0;
1265 stagingTextureDesc.MiscFlags = 0;
1266 stagingTextureDesc.CPUAccessFlags = D3D11_CPU_ACCESS_WRITE;
1267 stagingTextureDesc.Usage = D3D11_USAGE_STAGING;
1268 result = ID3D11Device_CreateTexture2D(rendererData->d3dDevice,
1269 &stagingTextureDesc,
1278 result = ID3D11DeviceContext_Map(rendererData->d3dContext,
1279 (ID3D11Resource *)stagingTexture,
1287 SAFE_RELEASE(stagingTexture);
1292 dst = textureMemory.pData;
1294 if (
length == pitch &&
length == textureMemory.RowPitch) {
1297 if (
length > (UINT)pitch) {
1300 if (
length > textureMemory.RowPitch) {
1301 length = textureMemory.RowPitch;
1306 dst += textureMemory.RowPitch;
1311 ID3D11DeviceContext_Unmap(rendererData->d3dContext,
1312 (ID3D11Resource *)stagingTexture,
1316 ID3D11DeviceContext_CopySubresourceRegion(rendererData->d3dContext,
1322 (ID3D11Resource *)stagingTexture,
1326 SAFE_RELEASE(stagingTexture);
1337 D3D11_TextureData *textureData = (D3D11_TextureData *)
texture->driverdata;
1348 if (textureData->yuv) {
1350 srcPixels = (
const void*)((
const Uint8*)srcPixels +
rect->
h * srcPitch);
1357 srcPixels = (
const void*)((
const Uint8*)srcPixels + ((
rect->
h + 1) / 2) * ((srcPitch + 1) / 2));
1363 if (textureData->nv12) {
1365 srcPixels = (
const void*)((
const Uint8*)srcPixels +
rect->
h * srcPitch);
1367 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) {
1377 const Uint8 *Yplane,
int Ypitch,
1378 const Uint8 *Uplane,
int Upitch,
1379 const Uint8 *Vplane,
int Vpitch)
1382 D3D11_TextureData *textureData = (D3D11_TextureData *)
texture->driverdata;
1406 D3D11_TextureData *textureData = (D3D11_TextureData *)
texture->driverdata;
1408 D3D11_TEXTURE2D_DESC stagingTextureDesc;
1409 D3D11_MAPPED_SUBRESOURCE textureMemory;
1416 if (textureData->yuv || textureData->nv12) {
1418 if (!textureData->pixels) {
1419 textureData->pitch =
texture->w;
1421 if (!textureData->pixels) {
1425 textureData->locked_rect = *
rect;
1427 (
void *)((
Uint8 *)textureData->pixels +
rect->
y * textureData->pitch +
1429 *pitch = textureData->pitch;
1433 if (textureData->stagingTexture) {
1445 ID3D11Texture2D_GetDesc(textureData->mainTexture, &stagingTextureDesc);
1446 stagingTextureDesc.Width =
rect->
w;
1447 stagingTextureDesc.Height =
rect->
h;
1448 stagingTextureDesc.BindFlags = 0;
1449 stagingTextureDesc.MiscFlags = 0;
1450 stagingTextureDesc.CPUAccessFlags = D3D11_CPU_ACCESS_WRITE;
1451 stagingTextureDesc.Usage = D3D11_USAGE_STAGING;
1452 result = ID3D11Device_CreateTexture2D(rendererData->d3dDevice,
1453 &stagingTextureDesc,
1455 &textureData->stagingTexture);
1462 result = ID3D11DeviceContext_Map(rendererData->d3dContext,
1463 (ID3D11Resource *)textureData->stagingTexture,
1471 SAFE_RELEASE(textureData->stagingTexture);
1478 textureData->lockedTexturePositionX =
rect->
x;
1479 textureData->lockedTexturePositionY =
rect->
y;
1484 *
pixels = textureMemory.pData;
1485 *pitch = textureMemory.RowPitch;
1493 D3D11_TextureData *textureData = (D3D11_TextureData *)
texture->driverdata;
1499 if (textureData->yuv || textureData->nv12) {
1502 (
void *) ((
Uint8 *) textureData->pixels +
rect->
y * textureData->pitch +
1509 ID3D11DeviceContext_Unmap(rendererData->d3dContext,
1510 (ID3D11Resource *)textureData->stagingTexture,
1514 ID3D11DeviceContext_CopySubresourceRegion(rendererData->d3dContext,
1515 (ID3D11Resource *)textureData->mainTexture,
1517 textureData->lockedTexturePositionX,
1518 textureData->lockedTexturePositionY,
1520 (ID3D11Resource *)textureData->stagingTexture,
1524 SAFE_RELEASE(textureData->stagingTexture);
1530 D3D11_TextureData *textureData = (D3D11_TextureData *)
texture->driverdata;
1536 textureData->scaleMode = (scaleMode ==
SDL_ScaleModeNearest) ? D3D11_FILTER_MIN_MAG_MIP_POINT : D3D11_FILTER_MIN_MAG_MIP_LINEAR;
1543 D3D11_TextureData *textureData =
NULL;
1546 rendererData->currentOffscreenRenderTargetView =
NULL;
1550 textureData = (D3D11_TextureData *)
texture->driverdata;
1552 if (!textureData->mainTextureRenderTargetView) {
1553 return SDL_SetError(
"specified texture is not a render target");
1556 rendererData->currentOffscreenRenderTargetView = textureData->mainTextureRenderTargetView;
1571 const float r = (float)(cmd->
data.
draw.r / 255.0f);
1572 const float g = (float)(cmd->
data.
draw.g / 255.0f);
1573 const float b = (float)(cmd->
data.
draw.b / 255.0f);
1574 const float a = (float)(cmd->
data.
draw.a / 255.0f);
1584 verts->pos.x =
points[
i].x + 0.5f;
1585 verts->pos.y =
points[
i].y + 0.5f;
1586 verts->pos.z = 0.0f;
1587 verts->tex.x = 0.0f;
1588 verts->tex.y = 0.0f;
1603 const float r = (float)(cmd->
data.
draw.r / 255.0f);
1604 const float g = (float)(cmd->
data.
draw.g / 255.0f);
1605 const float b = (float)(cmd->
data.
draw.b / 255.0f);
1606 const float a = (float)(cmd->
data.
draw.a / 255.0f);
1616 verts->pos.x =
rects[
i].x;
1617 verts->pos.y =
rects[
i].y;
1618 verts->pos.z = 0.0f;
1619 verts->tex.x = 0.0f;
1620 verts->tex.y = 0.0f;
1627 verts->pos.x =
rects[
i].x;
1629 verts->pos.z = 0.0f;
1630 verts->tex.x = 0.0f;
1631 verts->tex.y = 0.0f;
1639 verts->pos.y =
rects[
i].y;
1640 verts->pos.z = 0.0f;
1641 verts->tex.x = 0.0f;
1642 verts->tex.y = 0.0f;
1651 verts->pos.z = 0.0f;
1652 verts->tex.x = 0.0f;
1653 verts->tex.y = 0.0f;
1669 const float r = (float)(cmd->
data.
draw.r / 255.0f);
1670 const float g = (float)(cmd->
data.
draw.g / 255.0f);
1671 const float b = (float)(cmd->
data.
draw.b / 255.0f);
1672 const float a = (float)(cmd->
data.
draw.a / 255.0f);
1673 const float minu = (float) srcrect->
x /
texture->w;
1674 const float maxu = (
float) (srcrect->
x + srcrect->
w) /
texture->w;
1675 const float minv = (
float) srcrect->
y /
texture->h;
1676 const float maxv = (float) (srcrect->
y + srcrect->
h) /
texture->h;
1684 verts->pos.x = dstrect->
x;
1685 verts->pos.y = dstrect->
y;
1686 verts->pos.z = 0.0f;
1687 verts->tex.x = minu;
1688 verts->tex.y = minv;
1695 verts->pos.x = dstrect->
x;
1696 verts->pos.y = dstrect->
y + dstrect->
h;
1697 verts->pos.z = 0.0f;
1698 verts->tex.x = minu;
1699 verts->tex.y = maxv;
1706 verts->pos.x = dstrect->
x + dstrect->
w;
1707 verts->pos.y = dstrect->
y;
1708 verts->pos.z = 0.0f;
1709 verts->tex.x = maxu;
1710 verts->tex.y = minv;
1717 verts->pos.x = dstrect->
x + dstrect->
w;
1718 verts->pos.y = dstrect->
y + dstrect->
h;
1719 verts->pos.z = 0.0f;
1720 verts->tex.x = maxu;
1721 verts->tex.y = maxv;
1737 const float r = (float)(cmd->
data.
draw.r / 255.0f);
1738 const float g = (float)(cmd->
data.
draw.g / 255.0f);
1739 const float b = (float)(cmd->
data.
draw.b / 255.0f);
1740 const float a = (float)(cmd->
data.
draw.a / 255.0f);
1741 float minx, miny, maxx, maxy;
1742 float minu, maxu, minv, maxv;
1751 maxx = dstrect->
w - center->
x;
1753 maxy = dstrect->
h - center->
y;
1756 minu = (float) (srcrect->
x + srcrect->
w) /
texture->w;
1757 maxu = (float) srcrect->
x /
texture->w;
1759 minu = (float) srcrect->
x /
texture->w;
1760 maxu = (
float) (srcrect->
x + srcrect->
w) /
texture->w;
1764 minv = (float) (srcrect->
y + srcrect->
h) /
texture->h;
1765 maxv = (float) srcrect->
y /
texture->h;
1767 minv = (float) srcrect->
y /
texture->h;
1768 maxv = (
float) (srcrect->
y + srcrect->
h) /
texture->h;
1773 verts->pos.x = minx;
1774 verts->pos.y = miny;
1775 verts->pos.z = 0.0f;
1780 verts->tex.x = minu;
1781 verts->tex.y = minv;
1784 verts->pos.x = minx;
1785 verts->pos.y = maxy;
1786 verts->pos.z = 0.0f;
1791 verts->tex.x = minu;
1792 verts->tex.y = maxv;
1795 verts->pos.x = maxx;
1796 verts->pos.y = miny;
1797 verts->pos.z = 0.0f;
1802 verts->tex.x = maxu;
1803 verts->tex.y = minv;
1806 verts->pos.x = maxx;
1807 verts->pos.y = maxy;
1808 verts->pos.z = 0.0f;
1813 verts->tex.x = maxu;
1814 verts->tex.y = maxv;
1817 verts->pos.x = dstrect->
x + center->
x;
1818 verts->pos.y = dstrect->
y + center->
y;
1819 verts->pos.z = (float)(M_PI * (
float)
angle / 180.0f);
1824 verts->tex.x = 0.0f;
1825 verts->tex.y = 0.0f;
1834 const void * vertexData,
size_t dataSizeInBytes)
1838 const int vbidx = rendererData->currentVertexBuffer;
1839 const UINT
stride =
sizeof(VertexPositionColor);
1842 if (dataSizeInBytes == 0) {
1846 if (rendererData->vertexBuffers[vbidx] && rendererData->vertexBufferSizes[vbidx] >= dataSizeInBytes) {
1847 D3D11_MAPPED_SUBRESOURCE mappedResource;
1848 result = ID3D11DeviceContext_Map(rendererData->d3dContext,
1849 (ID3D11Resource *)rendererData->vertexBuffers[vbidx],
1851 D3D11_MAP_WRITE_DISCARD,
1859 SDL_memcpy(mappedResource.pData, vertexData, dataSizeInBytes);
1860 ID3D11DeviceContext_Unmap(rendererData->d3dContext, (ID3D11Resource *)rendererData->vertexBuffers[vbidx], 0);
1862 D3D11_BUFFER_DESC vertexBufferDesc;
1863 D3D11_SUBRESOURCE_DATA vertexBufferData;
1865 SAFE_RELEASE(rendererData->vertexBuffers[vbidx]);
1868 vertexBufferDesc.ByteWidth = (UINT) dataSizeInBytes;
1869 vertexBufferDesc.Usage = D3D11_USAGE_DYNAMIC;
1870 vertexBufferDesc.BindFlags = D3D11_BIND_VERTEX_BUFFER;
1871 vertexBufferDesc.CPUAccessFlags = D3D11_CPU_ACCESS_WRITE;
1874 vertexBufferData.pSysMem = vertexData;
1875 vertexBufferData.SysMemPitch = 0;
1876 vertexBufferData.SysMemSlicePitch = 0;
1878 result = ID3D11Device_CreateBuffer(rendererData->d3dDevice,
1881 &rendererData->vertexBuffers[vbidx]
1888 rendererData->vertexBufferSizes[vbidx] = dataSizeInBytes;
1891 ID3D11DeviceContext_IASetVertexBuffers(rendererData->d3dContext,
1894 &rendererData->vertexBuffers[vbidx],
1899 rendererData->currentVertexBuffer++;
1900 if (rendererData->currentVertexBuffer >=
SDL_arraysize(rendererData->vertexBuffers)) {
1901 rendererData->currentVertexBuffer = 0;
1912 Float4X4 projection;
1915 BOOL swapDimensions;
1916 D3D11_VIEWPORT d3dviewport;
1917 const int rotation = D3D11_GetRotationForCurrentRenderTarget(
renderer);
1934 case DXGI_MODE_ROTATION_IDENTITY:
1935 projection = MatrixIdentity();
1937 case DXGI_MODE_ROTATION_ROTATE270:
1940 case DXGI_MODE_ROTATION_ROTATE180:
1943 case DXGI_MODE_ROTATION_ROTATE90:
1947 return SDL_SetError(
"An unknown DisplayOrientation is being used");
1954 view.m[2][2] = 1.0f;
1955 view.m[3][0] = -1.0f;
1956 view.m[3][1] = 1.0f;
1957 view.m[3][3] = 1.0f;
1963 data->vertexShaderConstantsData.projectionAndView = MatrixMultiply(
1972 swapDimensions = D3D11_IsDisplayRotated90Degrees(rotation);
1973 if (swapDimensions) {
1974 orientationAlignedViewport.x = (float)
viewport->
y;
1975 orientationAlignedViewport.y = (
float)
viewport->
x;
1976 orientationAlignedViewport.w = (float)
viewport->
h;
1977 orientationAlignedViewport.h = (
float)
viewport->
w;
1979 orientationAlignedViewport.x = (float)
viewport->
x;
1980 orientationAlignedViewport.y = (
float)
viewport->
y;
1981 orientationAlignedViewport.w = (float)
viewport->
w;
1982 orientationAlignedViewport.h = (
float)
viewport->
h;
1986 d3dviewport.TopLeftX = orientationAlignedViewport.x;
1987 d3dviewport.TopLeftY = orientationAlignedViewport.y;
1988 d3dviewport.Width = orientationAlignedViewport.w;
1989 d3dviewport.Height = orientationAlignedViewport.h;
1990 d3dviewport.MinDepth = 0.0f;
1991 d3dviewport.MaxDepth = 1.0f;
1993 ID3D11DeviceContext_RSSetViewports(
data->d3dContext, 1, &d3dviewport);
2000 static ID3D11RenderTargetView *
2004 if (
data->currentOffscreenRenderTargetView) {
2005 return data->currentOffscreenRenderTargetView;
2008 return data->mainRenderTargetView;
2014 const int numShaderResources, ID3D11ShaderResourceView ** shaderResources,
2019 const Float4X4 *newmatrix =
matrix ?
matrix : &rendererData->identity;
2020 ID3D11RasterizerState *rasterizerState;
2021 ID3D11RenderTargetView *renderTargetView = D3D11_GetCurrentRenderTargetView(
renderer);
2022 ID3D11ShaderResourceView *shaderResource;
2024 ID3D11BlendState *blendState =
NULL;
2027 if (renderTargetView != rendererData->currentRenderTargetView) {
2028 ID3D11DeviceContext_OMSetRenderTargets(rendererData->d3dContext,
2033 rendererData->currentRenderTargetView = renderTargetView;
2036 if (rendererData->viewportDirty) {
2037 if (D3D11_UpdateViewport(
renderer) == 0) {
2043 if (rendererData->cliprectDirty) {
2044 if (!rendererData->currentCliprectEnabled) {
2045 ID3D11DeviceContext_RSSetScissorRects(rendererData->d3dContext, 0,
NULL);
2047 D3D11_RECT scissorRect;
2048 if (D3D11_GetViewportAlignedD3DRect(
renderer, &rendererData->currentCliprect, &scissorRect,
TRUE) != 0) {
2052 ID3D11DeviceContext_RSSetScissorRects(rendererData->d3dContext, 1, &scissorRect);
2054 rendererData->cliprectDirty =
SDL_FALSE;
2057 if (!rendererData->currentCliprectEnabled) {
2058 rasterizerState = rendererData->mainRasterizer;
2060 rasterizerState = rendererData->clippedRasterizer;
2062 if (rasterizerState != rendererData->currentRasterizerState) {
2063 ID3D11DeviceContext_RSSetState(rendererData->d3dContext, rasterizerState);
2064 rendererData->currentRasterizerState = rasterizerState;
2069 for (
i = 0;
i < rendererData->blendModesCount; ++
i) {
2070 if (
blendMode == rendererData->blendModes[
i].blendMode) {
2071 blendState = rendererData->blendModes[
i].blendState;
2082 if (blendState != rendererData->currentBlendState) {
2083 ID3D11DeviceContext_OMSetBlendState(rendererData->d3dContext, blendState, 0, 0xFFFFFFFF);
2084 rendererData->currentBlendState = blendState;
2087 if (
shader != rendererData->currentShader) {
2088 ID3D11DeviceContext_PSSetShader(rendererData->d3dContext,
shader,
NULL, 0);
2089 rendererData->currentShader =
shader;
2091 if (numShaderResources > 0) {
2092 shaderResource = shaderResources[0];
2094 shaderResource =
NULL;
2096 if (shaderResource != rendererData->currentShaderResource) {
2097 ID3D11DeviceContext_PSSetShaderResources(rendererData->d3dContext, 0, numShaderResources, shaderResources);
2098 rendererData->currentShaderResource = shaderResource;
2100 if (
sampler != rendererData->currentSampler) {
2101 ID3D11DeviceContext_PSSetSamplers(rendererData->d3dContext, 0, 1, &
sampler);
2102 rendererData->currentSampler =
sampler;
2105 if (updateSubresource ==
SDL_TRUE ||
SDL_memcmp(&rendererData->vertexShaderConstantsData.model, newmatrix, sizeof (*newmatrix)) != 0) {
2106 SDL_memcpy(&rendererData->vertexShaderConstantsData.model, newmatrix, sizeof (*newmatrix));
2107 ID3D11DeviceContext_UpdateSubresource(rendererData->d3dContext,
2108 (ID3D11Resource *)rendererData->vertexShaderConstants,
2111 &rendererData->vertexShaderConstantsData,
2125 D3D11_TextureData *textureData = (D3D11_TextureData *)
texture->driverdata;
2126 ID3D11SamplerState *textureSampler;
2128 switch (textureData->scaleMode) {
2129 case D3D11_FILTER_MIN_MAG_MIP_POINT:
2130 textureSampler = rendererData->nearestPixelSampler;
2132 case D3D11_FILTER_MIN_MAG_MIP_LINEAR:
2133 textureSampler = rendererData->linearSampler;
2136 return SDL_SetError(
"Unknown scale mode: %d\n", textureData->scaleMode);
2139 if (textureData->yuv) {
2140 ID3D11ShaderResourceView *shaderResources[] = {
2141 textureData->mainTextureResourceView,
2142 textureData->mainTextureResourceViewU,
2143 textureData->mainTextureResourceViewV
2158 return SDL_SetError(
"Unsupported YUV conversion mode");
2161 return D3D11_SetDrawState(
renderer, cmd, rendererData->pixelShaders[
shader],
2164 }
else if (textureData->nv12) {
2165 ID3D11ShaderResourceView *shaderResources[] = {
2166 textureData->mainTextureResourceView,
2167 textureData->mainTextureResourceViewNV,
2182 return SDL_SetError(
"Unsupported YUV conversion mode");
2185 return D3D11_SetDrawState(
renderer, cmd, rendererData->pixelShaders[
shader],
2191 1, &textureData->mainTextureResourceView, textureSampler,
matrix);
2195 D3D11_DrawPrimitives(
SDL_Renderer *
renderer, D3D11_PRIMITIVE_TOPOLOGY primitiveTopology,
const size_t vertexStart,
const size_t vertexCount)
2198 ID3D11DeviceContext_IASetPrimitiveTopology(rendererData->d3dContext, primitiveTopology);
2199 ID3D11DeviceContext_Draw(rendererData->d3dContext, (UINT) vertexCount, (UINT) vertexStart);
2206 const int viewportRotation = D3D11_GetRotationForCurrentRenderTarget(
renderer);
2209 if (rendererData->currentViewportRotation != viewportRotation) {
2210 rendererData->currentViewportRotation = viewportRotation;
2211 rendererData->viewportDirty =
SDL_TRUE;
2214 if (D3D11_UpdateVertexBuffer(
renderer, vertices, vertsize) < 0) {
2228 rendererData->viewportDirty =
SDL_TRUE;
2235 if (rendererData->currentCliprectEnabled != cmd->
data.
cliprect.enabled) {
2236 rendererData->currentCliprectEnabled = cmd->
data.
cliprect.enabled;
2237 rendererData->cliprectDirty =
SDL_TRUE;
2241 rendererData->cliprectDirty =
SDL_TRUE;
2247 const float colorRGBA[] = {
2253 ID3D11DeviceContext_ClearRenderTargetView(rendererData->d3dContext, D3D11_GetCurrentRenderTargetView(
renderer), colorRGBA);
2260 const size_t start =
first /
sizeof (VertexPositionColor);
2269 const size_t start =
first /
sizeof (VertexPositionColor);
2270 const VertexPositionColor *verts = (VertexPositionColor *) (((
Uint8 *) vertices) +
first);
2273 if (verts[0].pos.x != verts[
count - 1].pos.x || verts[0].pos.y != verts[
count - 1].pos.y) {
2274 D3D11_DrawPrimitives(
renderer, D3D11_PRIMITIVE_TOPOLOGY_POINTLIST,
start + (
count-1), 1);
2282 const size_t start =
first /
sizeof (VertexPositionColor);
2286 D3D11_DrawPrimitives(
renderer, D3D11_PRIMITIVE_TOPOLOGY_TRIANGLESTRIP,
start +
offset, 4);
2293 const size_t start =
first /
sizeof (VertexPositionColor);
2295 D3D11_DrawPrimitives(
renderer, D3D11_PRIMITIVE_TOPOLOGY_TRIANGLESTRIP,
start, 4);
2301 const size_t start =
first /
sizeof (VertexPositionColor);
2302 const VertexPositionColor *verts = (VertexPositionColor *) (((
Uint8 *) vertices) +
first);
2303 const VertexPositionColor *transvert = verts + 4;
2304 const float translatex = transvert->pos.x;
2305 const float translatey = transvert->pos.y;
2306 const float rotation = transvert->pos.z;
2307 const Float4X4
matrix = MatrixMultiply(MatrixRotationZ(rotation), MatrixTranslation(translatex, translatey, 0));
2309 D3D11_DrawPrimitives(
renderer, D3D11_PRIMITIVE_TOPOLOGY_TRIANGLESTRIP,
start, 4);
2328 ID3D11RenderTargetView *renderTargetView =
NULL;
2329 ID3D11Texture2D *backBuffer =
NULL;
2330 ID3D11Texture2D *stagingTexture =
NULL;
2333 D3D11_TEXTURE2D_DESC stagingTextureDesc;
2334 D3D11_RECT srcRect = {0, 0, 0, 0};
2336 D3D11_MAPPED_SUBRESOURCE textureMemory;
2338 ID3D11DeviceContext_OMGetRenderTargets(
data->d3dContext, 1, &renderTargetView,
NULL);
2339 if (renderTargetView ==
NULL) {
2340 SDL_SetError(
"%s, ID3D11DeviceContext::OMGetRenderTargets failed", __FUNCTION__);
2344 ID3D11View_GetResource(renderTargetView, (ID3D11Resource**)&backBuffer);
2345 if (backBuffer ==
NULL) {
2346 SDL_SetError(
"%s, ID3D11View::GetResource failed", __FUNCTION__);
2351 ID3D11Texture2D_GetDesc(backBuffer, &stagingTextureDesc);
2352 stagingTextureDesc.Width =
rect->
w;
2353 stagingTextureDesc.Height =
rect->
h;
2354 stagingTextureDesc.BindFlags = 0;
2355 stagingTextureDesc.MiscFlags = 0;
2356 stagingTextureDesc.CPUAccessFlags = D3D11_CPU_ACCESS_READ;
2357 stagingTextureDesc.Usage = D3D11_USAGE_STAGING;
2358 result = ID3D11Device_CreateTexture2D(
data->d3dDevice,
2359 &stagingTextureDesc,
2373 srcBox.left = srcRect.left;
2374 srcBox.right = srcRect.right;
2375 srcBox.top = srcRect.top;
2376 srcBox.bottom = srcRect.bottom;
2379 ID3D11DeviceContext_CopySubresourceRegion(
data->d3dContext,
2380 (ID3D11Resource *)stagingTexture,
2383 (ID3D11Resource *)backBuffer,
2388 result = ID3D11DeviceContext_Map(
data->d3dContext,
2389 (ID3D11Resource *)stagingTexture,
2404 D3D11_DXGIFormatToSDLPixelFormat(stagingTextureDesc.Format),
2405 textureMemory.pData,
2406 textureMemory.RowPitch,
2413 char errorMessage[1024];
2420 ID3D11DeviceContext_Unmap(
data->d3dContext,
2421 (ID3D11Resource *)stagingTexture,
2427 SAFE_RELEASE(backBuffer);
2428 SAFE_RELEASE(stagingTexture);
2439 DXGI_PRESENT_PARAMETERS parameters;
2443 #if WINAPI_FAMILY == WINAPI_FAMILY_PHONE_APP
2446 result = IDXGISwapChain_Present(
data->swapChain, syncInterval, presentFlags);
2453 presentFlags = DXGI_PRESENT_DO_NOT_WAIT;
2460 result = IDXGISwapChain1_Present1(
data->swapChain, syncInterval, presentFlags, ¶meters);
2467 ID3D11DeviceContext1_DiscardView(
data->d3dContext, (ID3D11View*)
data->mainRenderTargetView);
2470 data->currentRenderTargetView =
NULL;
2478 if (
result == DXGI_ERROR_DEVICE_REMOVED ) {
2480 }
else if (
result == DXGI_ERROR_INVALID_CALL) {
2482 D3D11_CreateWindowSizeDependentResources(
renderer);
2493 D3D11_RenderData *
data;
2507 data->identity = MatrixIdentity();
2534 #if WINAPI_FAMILY == WINAPI_FAMILY_PHONE_APP
2563 if (
FAILED(D3D11_CreateWindowSizeDependentResources(
renderer))) {
2572 D3D11_CreateRenderer,
SDL_BlendOperation
The blend operation used when combining source and destination pixel components.
@ SDL_BLENDOPERATION_MAXIMUM
@ SDL_BLENDOPERATION_MINIMUM
@ SDL_BLENDOPERATION_REV_SUBTRACT
@ SDL_BLENDOPERATION_SUBTRACT
SDL_BlendFactor
The normalized factor used to multiply pixel components.
@ SDL_BLENDFACTOR_ONE_MINUS_SRC_COLOR
@ SDL_BLENDFACTOR_SRC_COLOR
@ SDL_BLENDFACTOR_SRC_ALPHA
@ SDL_BLENDFACTOR_ONE_MINUS_DST_COLOR
@ SDL_BLENDFACTOR_ONE_MINUS_DST_ALPHA
@ SDL_BLENDFACTOR_ONE_MINUS_SRC_ALPHA
@ SDL_BLENDFACTOR_DST_ALPHA
@ SDL_BLENDFACTOR_DST_COLOR
SDL_BlendMode
The blend mode used in SDL_RenderCopy() and drawing operations.
#define SDL_GetWindowSize
#define SDL_GetYUVConversionModeForResolution
#define SDL_GetHintBoolean
#define SDL_ConvertPixels
#define SDL_GetWindowWMInfo
#define SDL_OutOfMemory()
@ SDL_RENDER_DEVICE_RESET
#define SDL_HINT_RENDER_DIRECT3D11_DEBUG
A variable controlling whether to enable Direct3D 11+'s Debug Layer.
void * SDL_LoadFunction(void *handle, const char *name)
GLint GLint GLint GLint GLint GLint y
GLuint GLuint GLsizei count
GLint GLint GLsizei GLsizei GLsizei GLint GLenum GLenum const GLvoid * pixels
GLint GLenum GLsizei GLsizei GLsizei GLint GLsizei const GLvoid * data
GLdouble GLdouble GLdouble r
GLint GLint GLint GLint GLint x
GLint GLint GLsizei GLsizei GLsizei GLint GLenum format
GLboolean GLboolean GLboolean b
GLfixed GLfixed GLint GLint GLfixed points
GLboolean GLboolean GLboolean GLboolean a
GLenum GLenum GLuint texture
GLuint GLsizei GLsizei * length
GLfloat GLfloat GLfloat GLfloat h
GLubyte GLubyte GLubyte GLubyte w
#define SDL_BYTESPERPIXEL(X)
@ SDL_PIXELFORMAT_ARGB8888
@ SDL_PIXELFORMAT_UNKNOWN
SDL_BlendFactor SDL_GetBlendModeDstColorFactor(SDL_BlendMode blendMode)
SDL_BlendFactor SDL_GetBlendModeSrcColorFactor(SDL_BlendMode blendMode)
void * SDL_AllocateRenderVertices(SDL_Renderer *renderer, const size_t numbytes, const size_t alignment, size_t *offset)
SDL_BlendFactor SDL_GetBlendModeDstAlphaFactor(SDL_BlendMode blendMode)
SDL_BlendFactor SDL_GetBlendModeSrcAlphaFactor(SDL_BlendMode blendMode)
SDL_BlendOperation SDL_GetBlendModeAlphaOperation(SDL_BlendMode blendMode)
SDL_BlendOperation SDL_GetBlendModeColorOperation(SDL_BlendMode blendMode)
@ SDL_RENDERER_ACCELERATED
@ SDL_RENDERER_PRESENTVSYNC
@ SDL_RENDERER_TARGETTEXTURE
SDL_RendererFlip
Flip constants for SDL_RenderCopyEx.
@ SDL_TEXTUREACCESS_STREAMING
@ SDL_TEXTUREACCESS_TARGET
SDL_ScaleMode
The scaling mode for a texture.
int D3D11_CreateVertexShader(ID3D11Device1 *d3dDevice, ID3D11VertexShader **vertexShader, ID3D11InputLayout **inputLayout)
int D3D11_CreatePixelShader(ID3D11Device1 *d3dDevice, D3D11_Shader shader, ID3D11PixelShader **pixelShader)
#define SDL_arraysize(array)
#define SDL_static_cast(type, expression)
@ SDL_YUV_CONVERSION_BT601
@ SDL_YUV_CONVERSION_JPEG
@ SDL_YUV_CONVERSION_BT709
SDL_RenderDriver D3D11_RenderDriver
@ SDL_RENDERCMD_SETCLIPRECT
@ SDL_RENDERCMD_DRAW_LINES
@ SDL_RENDERCMD_SETVIEWPORT
@ SDL_RENDERCMD_DRAW_POINTS
@ SDL_RENDERCMD_FILL_RECTS
@ SDL_RENDERCMD_SETDRAWCOLOR
#define SDL_VERSION(x)
Macro to determine SDL version program was compiled against.
@ SDL_WINDOWEVENT_SIZE_CHANGED
int WIN_SetErrorFromHRESULT(const char *prefix, HRESULT hr)
ISwapChainBackgroundPanelNative * WINRT_GlobalSwapChainBackgroundPanelNative
return Display return Display Bool Bool int int int return Display XEvent Bool(*) XPointer return Display return Display Drawable _Xconst char unsigned int unsigned int return Display Pixmap Pixmap XColor XColor unsigned int unsigned int return Display _Xconst char char int char return Display Visual unsigned int int int char unsigned int unsigned int in i)
EGLSurface EGLNativeWindowType * window
EGLSurface EGLint * rects
set set set set set set set macro pixldst1 abits if abits op else op endif endm macro pixldst2 abits if abits op else op endif endm macro pixldst4 abits if abits op else op endif endm macro pixldst0 abits op endm macro pixldst3 mem_operand op endm macro pixldst30 mem_operand op endm macro pixldst abits if abits elseif abits elseif abits elseif abits elseif abits pixldst0 abits else pixldst0 abits pixldst0 abits pixldst0 abits pixldst0 abits endif elseif abits else pixldst0 abits pixldst0 abits endif elseif abits else error unsupported bpp *numpix else pixst endif endm macro pixld1_s mem_operand if asr adds SRC_WIDTH_FIXED bpl add asl mov asr adds SRC_WIDTH_FIXED bpl add asl mov asr adds SRC_WIDTH_FIXED bpl add asl mov asr adds SRC_WIDTH_FIXED bpl add asl elseif asr adds SRC_WIDTH_FIXED bpl add asl mov asr adds SRC_WIDTH_FIXED bpl add asl else error unsupported endif endm macro pixld2_s mem_operand if mov asr add asl add asl mov asr sub UNIT_X add asl mov asr add asl add asl mov asr add UNIT_X add asl else pixld1_s mem_operand pixld1_s mem_operand endif endm macro pixld0_s mem_operand if asr adds SRC_WIDTH_FIXED bpl add asl elseif asr adds SRC_WIDTH_FIXED bpl add asl endif endm macro pixld_s_internal mem_operand if mem_operand pixld2_s mem_operand pixdeinterleave basereg elseif mem_operand elseif mem_operand elseif mem_operand elseif mem_operand pixld0_s mem_operand else pixld0_s mem_operand pixld0_s mem_operand pixld0_s mem_operand pixld0_s mem_operand endif elseif mem_operand else pixld0_s mem_operand pixld0_s mem_operand endif elseif mem_operand else error unsupported mem_operand if bpp mem_operand endif endm macro vuzp8 reg2 vuzp d d ®2 endm macro vzip8 reg2 vzip d d ®2 endm macro pixdeinterleave basereg basereg basereg basereg basereg endif endm macro pixinterleave basereg basereg basereg basereg basereg endif endm macro PF boost_increment endif if endif PF tst PF addne PF subne PF cmp ORIG_W if endif if endif if endif PF subge ORIG_W PF subges if endif if endif if endif endif endm macro cache_preload_simple endif if dst_r_bpp pld[DST_R, #(PREFETCH_DISTANCE_SIMPLE *dst_r_bpp/8)] endif if mask_bpp pld if[MASK, #(PREFETCH_DISTANCE_SIMPLE *mask_bpp/8)] endif endif endm macro fetch_mask_pixblock pixld mask_basereg pixblock_size MASK endm macro ensure_destination_ptr_alignment process_pixblock_tail_head if beq irp skip1(dst_w_bpp<=(lowbit *8)) &&((lowbit *8)<(pixblock_size *dst_w_bpp)) .if lowbit< 16 tst DST_R
set set set set set set set macro pixldst1 abits if abits op else op endif endm macro pixldst2 abits if abits op else op endif endm macro pixldst4 abits if abits op else op endif endm macro pixldst0 abits op endm macro pixldst3 mem_operand op endm macro pixldst30 mem_operand op endm macro pixldst abits if abits elseif abits elseif abits elseif abits elseif abits pixldst0 abits else pixldst0 abits pixldst0 abits pixldst0 abits pixldst0 abits endif elseif abits else pixldst0 abits pixldst0 abits endif elseif abits else error unsupported bpp
The structure that defines a point (floating point)
A rectangle, with the origin at the upper left (floating point).
A rectangle, with the origin at the upper left (integer).
struct SDL_RenderCommand::@38::@42 color
struct SDL_RenderCommand * next
struct SDL_RenderCommand::@38::@39 viewport
struct SDL_RenderCommand::@38::@41 draw
SDL_RenderCommandType command
union SDL_RenderCommand::@38 data
struct SDL_RenderCommand::@38::@40 cliprect
int(* QueueCopy)(SDL_Renderer *renderer, SDL_RenderCommand *cmd, SDL_Texture *texture, const SDL_Rect *srcrect, const SDL_FRect *dstrect)
int(* LockTexture)(SDL_Renderer *renderer, SDL_Texture *texture, const SDL_Rect *rect, void **pixels, int *pitch)
int(* UpdateTextureYUV)(SDL_Renderer *renderer, SDL_Texture *texture, const SDL_Rect *rect, const Uint8 *Yplane, int Ypitch, const Uint8 *Uplane, int Upitch, const Uint8 *Vplane, int Vpitch)
int(* QueueDrawLines)(SDL_Renderer *renderer, SDL_RenderCommand *cmd, const SDL_FPoint *points, int count)
void(* SetTextureScaleMode)(SDL_Renderer *renderer, SDL_Texture *texture, SDL_ScaleMode scaleMode)
void(* UnlockTexture)(SDL_Renderer *renderer, SDL_Texture *texture)
int(* UpdateTexture)(SDL_Renderer *renderer, SDL_Texture *texture, const SDL_Rect *rect, const void *pixels, int pitch)
int(* SetRenderTarget)(SDL_Renderer *renderer, SDL_Texture *texture)
void(* DestroyRenderer)(SDL_Renderer *renderer)
void(* DestroyTexture)(SDL_Renderer *renderer, SDL_Texture *texture)
SDL_bool(* SupportsBlendMode)(SDL_Renderer *renderer, SDL_BlendMode blendMode)
void(* RenderPresent)(SDL_Renderer *renderer)
int(* RenderReadPixels)(SDL_Renderer *renderer, const SDL_Rect *rect, Uint32 format, void *pixels, int pitch)
int(* QueueDrawPoints)(SDL_Renderer *renderer, SDL_RenderCommand *cmd, const SDL_FPoint *points, int count)
int(* QueueFillRects)(SDL_Renderer *renderer, SDL_RenderCommand *cmd, const SDL_FRect *rects, int count)
void(* WindowEvent)(SDL_Renderer *renderer, const SDL_WindowEvent *event)
int(* RunCommandQueue)(SDL_Renderer *renderer, SDL_RenderCommand *cmd, void *vertices, size_t vertsize)
int(* QueueCopyEx)(SDL_Renderer *renderer, SDL_RenderCommand *cmd, SDL_Texture *texture, const SDL_Rect *srcquad, const SDL_FRect *dstrect, const double angle, const SDL_FPoint *center, const SDL_RendererFlip flip)
int(* CreateTexture)(SDL_Renderer *renderer, SDL_Texture *texture)
int(* QueueSetViewport)(SDL_Renderer *renderer, SDL_RenderCommand *cmd)
int(* QueueSetDrawColor)(SDL_Renderer *renderer, SDL_RenderCommand *cmd)
union SDL_SysWMinfo::@10 info
Window state change event data (event.window.*)
The type used to identify a window.
static SDL_Renderer * renderer
static SDL_BlendMode blendMode