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;
101 IDXGIFactory2 *dxgiFactory;
102 IDXGIAdapter *dxgiAdapter;
103 ID3D11Device1 *d3dDevice;
104 ID3D11DeviceContext1 *d3dContext;
105 IDXGISwapChain1 *swapChain;
106 DXGI_SWAP_EFFECT swapEffect;
107 ID3D11RenderTargetView *mainRenderTargetView;
108 ID3D11RenderTargetView *currentOffscreenRenderTargetView;
109 ID3D11InputLayout *inputLayout;
110 ID3D11Buffer *vertexBuffer;
111 ID3D11VertexShader *vertexShader;
112 ID3D11PixelShader *colorPixelShader;
113 ID3D11PixelShader *texturePixelShader;
114 ID3D11PixelShader *yuvPixelShader;
115 ID3D11BlendState *blendModeBlend;
116 ID3D11BlendState *blendModeAdd;
117 ID3D11BlendState *blendModeMod;
118 ID3D11SamplerState *nearestPixelSampler;
119 ID3D11SamplerState *linearSampler;
120 D3D_FEATURE_LEVEL featureLevel;
123 ID3D11RasterizerState *mainRasterizer;
124 ID3D11RasterizerState *clippedRasterizer;
127 VertexShaderConstants vertexShaderConstantsData;
128 ID3D11Buffer *vertexShaderConstants;
131 DXGI_MODE_ROTATION rotation;
132 ID3D11RenderTargetView *currentRenderTargetView;
133 ID3D11RasterizerState *currentRasterizerState;
134 ID3D11BlendState *currentBlendState;
135 ID3D11PixelShader *currentShader;
136 ID3D11ShaderResourceView *currentShaderResource;
137 ID3D11SamplerState *currentSampler;
151 #pragma GCC diagnostic push 152 #pragma GCC diagnostic ignored "-Wunused-const-variable" 155 static const GUID SDL_IID_IDXGIFactory2 = { 0x50c83a1c, 0xe072, 0x4c48, { 0x87, 0xb0, 0x36, 0x30, 0xfa, 0x36, 0xa6, 0xd0 } };
156 static const GUID SDL_IID_IDXGIDevice1 = { 0x77db970f, 0x6276, 0x48ba, { 0xba, 0x28, 0x07, 0x01, 0x43, 0xb4, 0x39, 0x2c } };
157 static const GUID SDL_IID_IDXGIDevice3 = { 0x6007896c, 0x3244, 0x4afd, { 0xbf, 0x18, 0xa6, 0xd3, 0xbe, 0xda, 0x50, 0x23 } };
158 static const GUID SDL_IID_ID3D11Texture2D = { 0x6f15aaf2, 0xd208, 0x4e89, { 0x9a, 0xb4, 0x48, 0x95, 0x35, 0xd3, 0x4f, 0x9c } };
159 static const GUID SDL_IID_ID3D11Device1 = { 0xa04bfb29, 0x08ef, 0x43d6, { 0xa4, 0x9c, 0xa9, 0xbd, 0xbd, 0xcb, 0xe6, 0x86 } };
160 static const GUID SDL_IID_ID3D11DeviceContext1 = { 0xbb2c6faa, 0xb5fb, 0x4082, { 0x8e, 0x6b, 0x38, 0x8b, 0x8c, 0xfa, 0x90, 0xe1 } };
161 static const GUID SDL_IID_ID3D11Debug = { 0x79cf2233, 0x7536, 0x4948, { 0x9d, 0x36, 0x1e, 0x46, 0x92, 0xdc, 0x57, 0x60 } };
164 #pragma GCC diagnostic pop 193 #if WINAPI_FAMILY == WINAPI_FAMILY_PHONE_APP 194 #define D3D11_USE_SHADER_MODEL_4_0_level_9_3 196 #define D3D11_USE_SHADER_MODEL_4_0_level_9_1 214 #if defined(D3D11_USE_SHADER_MODEL_4_0_level_9_1) 215 static const DWORD D3D11_PixelShader_Colors[] = {
216 0x43425844, 0xd74c28fe, 0xa1eb8804, 0x269d512a, 0x7699723d, 0x00000001,
217 0x00000240, 0x00000006, 0x00000038, 0x00000084, 0x000000c4, 0x00000140,
218 0x00000198, 0x0000020c, 0x396e6f41, 0x00000044, 0x00000044, 0xffff0200,
219 0x00000020, 0x00000024, 0x00240000, 0x00240000, 0x00240000, 0x00240000,
220 0x00240000, 0xffff0200, 0x0200001f, 0x80000000, 0xb00f0001, 0x02000001,
221 0x800f0800, 0xb0e40001, 0x0000ffff, 0x52444853, 0x00000038, 0x00000040,
222 0x0000000e, 0x03001062, 0x001010f2, 0x00000002, 0x03000065, 0x001020f2,
223 0x00000000, 0x05000036, 0x001020f2, 0x00000000, 0x00101e46, 0x00000002,
224 0x0100003e, 0x54415453, 0x00000074, 0x00000002, 0x00000000, 0x00000000,
225 0x00000002, 0x00000000, 0x00000000, 0x00000000, 0x00000001, 0x00000000,
226 0x00000000, 0x00000000, 0x00000000, 0x00000000, 0x00000000, 0x00000000,
227 0x00000000, 0x00000000, 0x00000000, 0x00000000, 0x00000002, 0x00000000,
228 0x00000000, 0x00000000, 0x00000000, 0x00000000, 0x00000000, 0x00000000,
229 0x00000000, 0x00000000, 0x46454452, 0x00000050, 0x00000000, 0x00000000,
230 0x00000000, 0x0000001c, 0xffff0400, 0x00000100, 0x0000001c, 0x7263694d,
231 0x666f736f, 0x52282074, 0x4c482029, 0x53204c53, 0x65646168, 0x6f432072,
232 0x6c69706d, 0x39207265, 0x2e30332e, 0x30303239, 0x3336312e, 0xab003438,
233 0x4e475349, 0x0000006c, 0x00000003, 0x00000008, 0x00000050, 0x00000000,
234 0x00000001, 0x00000003, 0x00000000, 0x0000000f, 0x0000005c, 0x00000000,
235 0x00000000, 0x00000003, 0x00000001, 0x00000003, 0x00000065, 0x00000000,
236 0x00000000, 0x00000003, 0x00000002, 0x00000f0f, 0x505f5653, 0x5449534f,
237 0x004e4f49, 0x43584554, 0x44524f4f, 0x4c4f4300, 0xab00524f, 0x4e47534f,
238 0x0000002c, 0x00000001, 0x00000008, 0x00000020, 0x00000000, 0x00000000,
239 0x00000003, 0x00000000, 0x0000000f, 0x545f5653, 0x45475241, 0xabab0054
241 #elif defined(D3D11_USE_SHADER_MODEL_4_0_level_9_3) 242 static const DWORD D3D11_PixelShader_Colors[] = {
243 0x43425844, 0x93f6ccfc, 0x5f919270, 0x7a11aa4f, 0x9148e931, 0x00000001,
244 0x00000240, 0x00000006, 0x00000038, 0x00000084, 0x000000c4, 0x00000140,
245 0x00000198, 0x0000020c, 0x396e6f41, 0x00000044, 0x00000044, 0xffff0200,
246 0x00000020, 0x00000024, 0x00240000, 0x00240000, 0x00240000, 0x00240000,
247 0x00240000, 0xffff0201, 0x0200001f, 0x80000000, 0xb00f0001, 0x02000001,
248 0x800f0800, 0xb0e40001, 0x0000ffff, 0x52444853, 0x00000038, 0x00000040,
249 0x0000000e, 0x03001062, 0x001010f2, 0x00000002, 0x03000065, 0x001020f2,
250 0x00000000, 0x05000036, 0x001020f2, 0x00000000, 0x00101e46, 0x00000002,
251 0x0100003e, 0x54415453, 0x00000074, 0x00000002, 0x00000000, 0x00000000,
252 0x00000002, 0x00000000, 0x00000000, 0x00000000, 0x00000001, 0x00000000,
253 0x00000000, 0x00000000, 0x00000000, 0x00000000, 0x00000000, 0x00000000,
254 0x00000000, 0x00000000, 0x00000000, 0x00000000, 0x00000002, 0x00000000,
255 0x00000000, 0x00000000, 0x00000000, 0x00000000, 0x00000000, 0x00000000,
256 0x00000000, 0x00000000, 0x46454452, 0x00000050, 0x00000000, 0x00000000,
257 0x00000000, 0x0000001c, 0xffff0400, 0x00000100, 0x0000001c, 0x7263694d,
258 0x666f736f, 0x52282074, 0x4c482029, 0x53204c53, 0x65646168, 0x6f432072,
259 0x6c69706d, 0x39207265, 0x2e30332e, 0x30303239, 0x3336312e, 0xab003438,
260 0x4e475349, 0x0000006c, 0x00000003, 0x00000008, 0x00000050, 0x00000000,
261 0x00000001, 0x00000003, 0x00000000, 0x0000000f, 0x0000005c, 0x00000000,
262 0x00000000, 0x00000003, 0x00000001, 0x00000003, 0x00000065, 0x00000000,
263 0x00000000, 0x00000003, 0x00000002, 0x00000f0f, 0x505f5653, 0x5449534f,
264 0x004e4f49, 0x43584554, 0x44524f4f, 0x4c4f4300, 0xab00524f, 0x4e47534f,
265 0x0000002c, 0x00000001, 0x00000008, 0x00000020, 0x00000000, 0x00000000,
266 0x00000003, 0x00000000, 0x0000000f, 0x545f5653, 0x45475241, 0xabab0054
269 #error "An appropriate 'colors' pixel shader is not defined." 290 #if defined(D3D11_USE_SHADER_MODEL_4_0_level_9_1) 291 static const DWORD D3D11_PixelShader_Textures[] = {
292 0x43425844, 0x6299b59f, 0x155258f2, 0x873ab86a, 0xfcbb6dcd, 0x00000001,
293 0x00000330, 0x00000006, 0x00000038, 0x000000c0, 0x0000015c, 0x000001d8,
294 0x00000288, 0x000002fc, 0x396e6f41, 0x00000080, 0x00000080, 0xffff0200,
295 0x00000058, 0x00000028, 0x00280000, 0x00280000, 0x00280000, 0x00240001,
296 0x00280000, 0x00000000, 0xffff0200, 0x0200001f, 0x80000000, 0xb0030000,
297 0x0200001f, 0x80000000, 0xb00f0001, 0x0200001f, 0x90000000, 0xa00f0800,
298 0x03000042, 0x800f0000, 0xb0e40000, 0xa0e40800, 0x03000005, 0x800f0000,
299 0x80e40000, 0xb0e40001, 0x02000001, 0x800f0800, 0x80e40000, 0x0000ffff,
300 0x52444853, 0x00000094, 0x00000040, 0x00000025, 0x0300005a, 0x00106000,
301 0x00000000, 0x04001858, 0x00107000, 0x00000000, 0x00005555, 0x03001062,
302 0x00101032, 0x00000001, 0x03001062, 0x001010f2, 0x00000002, 0x03000065,
303 0x001020f2, 0x00000000, 0x02000068, 0x00000001, 0x09000045, 0x001000f2,
304 0x00000000, 0x00101046, 0x00000001, 0x00107e46, 0x00000000, 0x00106000,
305 0x00000000, 0x07000038, 0x001020f2, 0x00000000, 0x00100e46, 0x00000000,
306 0x00101e46, 0x00000002, 0x0100003e, 0x54415453, 0x00000074, 0x00000003,
307 0x00000001, 0x00000000, 0x00000003, 0x00000001, 0x00000000, 0x00000000,
308 0x00000001, 0x00000000, 0x00000000, 0x00000000, 0x00000000, 0x00000000,
309 0x00000000, 0x00000001, 0x00000000, 0x00000000, 0x00000000, 0x00000000,
310 0x00000001, 0x00000000, 0x00000000, 0x00000000, 0x00000000, 0x00000000,
311 0x00000000, 0x00000000, 0x00000000, 0x00000000, 0x46454452, 0x000000a8,
312 0x00000000, 0x00000000, 0x00000002, 0x0000001c, 0xffff0400, 0x00000100,
313 0x00000072, 0x0000005c, 0x00000003, 0x00000000, 0x00000000, 0x00000000,
314 0x00000000, 0x00000001, 0x00000001, 0x00000067, 0x00000002, 0x00000005,
315 0x00000004, 0xffffffff, 0x00000000, 0x00000001, 0x0000000d, 0x53656874,
316 0x6c706d61, 0x74007265, 0x65546568, 0x72757478, 0x694d0065, 0x736f7263,
317 0x2074666f, 0x20295228, 0x4c534c48, 0x61685320, 0x20726564, 0x706d6f43,
318 0x72656c69, 0x332e3920, 0x32392e30, 0x312e3030, 0x34383336, 0xababab00,
319 0x4e475349, 0x0000006c, 0x00000003, 0x00000008, 0x00000050, 0x00000000,
320 0x00000001, 0x00000003, 0x00000000, 0x0000000f, 0x0000005c, 0x00000000,
321 0x00000000, 0x00000003, 0x00000001, 0x00000303, 0x00000065, 0x00000000,
322 0x00000000, 0x00000003, 0x00000002, 0x00000f0f, 0x505f5653, 0x5449534f,
323 0x004e4f49, 0x43584554, 0x44524f4f, 0x4c4f4300, 0xab00524f, 0x4e47534f,
324 0x0000002c, 0x00000001, 0x00000008, 0x00000020, 0x00000000, 0x00000000,
325 0x00000003, 0x00000000, 0x0000000f, 0x545f5653, 0x45475241, 0xabab0054
327 #elif defined(D3D11_USE_SHADER_MODEL_4_0_level_9_3) 328 static const DWORD D3D11_PixelShader_Textures[] = {
329 0x43425844, 0x5876569a, 0x01b6c87e, 0x8447454f, 0xc7f3ef10, 0x00000001,
330 0x00000330, 0x00000006, 0x00000038, 0x000000c0, 0x0000015c, 0x000001d8,
331 0x00000288, 0x000002fc, 0x396e6f41, 0x00000080, 0x00000080, 0xffff0200,
332 0x00000058, 0x00000028, 0x00280000, 0x00280000, 0x00280000, 0x00240001,
333 0x00280000, 0x00000000, 0xffff0201, 0x0200001f, 0x80000000, 0xb0030000,
334 0x0200001f, 0x80000000, 0xb00f0001, 0x0200001f, 0x90000000, 0xa00f0800,
335 0x03000042, 0x800f0000, 0xb0e40000, 0xa0e40800, 0x03000005, 0x800f0000,
336 0x80e40000, 0xb0e40001, 0x02000001, 0x800f0800, 0x80e40000, 0x0000ffff,
337 0x52444853, 0x00000094, 0x00000040, 0x00000025, 0x0300005a, 0x00106000,
338 0x00000000, 0x04001858, 0x00107000, 0x00000000, 0x00005555, 0x03001062,
339 0x00101032, 0x00000001, 0x03001062, 0x001010f2, 0x00000002, 0x03000065,
340 0x001020f2, 0x00000000, 0x02000068, 0x00000001, 0x09000045, 0x001000f2,
341 0x00000000, 0x00101046, 0x00000001, 0x00107e46, 0x00000000, 0x00106000,
342 0x00000000, 0x07000038, 0x001020f2, 0x00000000, 0x00100e46, 0x00000000,
343 0x00101e46, 0x00000002, 0x0100003e, 0x54415453, 0x00000074, 0x00000003,
344 0x00000001, 0x00000000, 0x00000003, 0x00000001, 0x00000000, 0x00000000,
345 0x00000001, 0x00000000, 0x00000000, 0x00000000, 0x00000000, 0x00000000,
346 0x00000000, 0x00000001, 0x00000000, 0x00000000, 0x00000000, 0x00000000,
347 0x00000001, 0x00000000, 0x00000000, 0x00000000, 0x00000000, 0x00000000,
348 0x00000000, 0x00000000, 0x00000000, 0x00000000, 0x46454452, 0x000000a8,
349 0x00000000, 0x00000000, 0x00000002, 0x0000001c, 0xffff0400, 0x00000100,
350 0x00000072, 0x0000005c, 0x00000003, 0x00000000, 0x00000000, 0x00000000,
351 0x00000000, 0x00000001, 0x00000001, 0x00000067, 0x00000002, 0x00000005,
352 0x00000004, 0xffffffff, 0x00000000, 0x00000001, 0x0000000d, 0x53656874,
353 0x6c706d61, 0x74007265, 0x65546568, 0x72757478, 0x694d0065, 0x736f7263,
354 0x2074666f, 0x20295228, 0x4c534c48, 0x61685320, 0x20726564, 0x706d6f43,
355 0x72656c69, 0x332e3920, 0x32392e30, 0x312e3030, 0x34383336, 0xababab00,
356 0x4e475349, 0x0000006c, 0x00000003, 0x00000008, 0x00000050, 0x00000000,
357 0x00000001, 0x00000003, 0x00000000, 0x0000000f, 0x0000005c, 0x00000000,
358 0x00000000, 0x00000003, 0x00000001, 0x00000303, 0x00000065, 0x00000000,
359 0x00000000, 0x00000003, 0x00000002, 0x00000f0f, 0x505f5653, 0x5449534f,
360 0x004e4f49, 0x43584554, 0x44524f4f, 0x4c4f4300, 0xab00524f, 0x4e47534f,
361 0x0000002c, 0x00000001, 0x00000008, 0x00000020, 0x00000000, 0x00000000,
362 0x00000003, 0x00000000, 0x0000000f, 0x545f5653, 0x45475241, 0xabab0054
365 #error "An appropriate 'textures' pixel shader is not defined" 407 #if defined(D3D11_USE_SHADER_MODEL_4_0_level_9_1) 408 static const DWORD D3D11_PixelShader_YUV[] = {
409 0x43425844, 0x2321c6c6, 0xf14df2d1, 0xc79d068d, 0x8e672abf, 0x00000001,
410 0x000005e8, 0x00000006, 0x00000038, 0x000001dc, 0x000003bc, 0x00000438,
411 0x00000540, 0x000005b4, 0x396e6f41, 0x0000019c, 0x0000019c, 0xffff0200,
412 0x0000016c, 0x00000030, 0x00300000, 0x00300000, 0x00300000, 0x00240003,
413 0x00300000, 0x00000000, 0x00010001, 0x00020002, 0xffff0200, 0x05000051,
414 0xa00f0000, 0xbd808081, 0xbf008081, 0xbf008081, 0x3f800000, 0x05000051,
415 0xa00f0001, 0x3f94fdf4, 0x3fcc49ba, 0x00000000, 0x00000000, 0x05000051,
416 0xa00f0002, 0x3f94fdf4, 0xbec83127, 0xbf5020c5, 0x00000000, 0x05000051,
417 0xa00f0003, 0x3f94fdf4, 0x400126e9, 0x00000000, 0x00000000, 0x0200001f,
418 0x80000000, 0xb0030000, 0x0200001f, 0x80000000, 0xb00f0001, 0x0200001f,
419 0x90000000, 0xa00f0800, 0x0200001f, 0x90000000, 0xa00f0801, 0x0200001f,
420 0x90000000, 0xa00f0802, 0x03000042, 0x800f0000, 0xb0e40000, 0xa0e40800,
421 0x03000042, 0x800f0001, 0xb0e40000, 0xa0e40801, 0x03000042, 0x800f0002,
422 0xb0e40000, 0xa0e40802, 0x02000001, 0x80020000, 0x80000001, 0x02000001,
423 0x80040000, 0x80000002, 0x03000002, 0x80070000, 0x80e40000, 0xa0e40000,
424 0x03000005, 0x80080000, 0x80000000, 0xa0000001, 0x04000004, 0x80010001,
425 0x80aa0000, 0xa0550001, 0x80ff0000, 0x03000008, 0x80020001, 0x80e40000,
426 0xa0e40002, 0x0400005a, 0x80040001, 0x80e40000, 0xa0e40003, 0xa0aa0003,
427 0x02000001, 0x80080001, 0xa0ff0000, 0x03000005, 0x800f0000, 0x80e40001,
428 0xb0e40001, 0x02000001, 0x800f0800, 0x80e40000, 0x0000ffff, 0x52444853,
429 0x000001d8, 0x00000040, 0x00000076, 0x0300005a, 0x00106000, 0x00000000,
430 0x04001858, 0x00107000, 0x00000000, 0x00005555, 0x04001858, 0x00107000,
431 0x00000001, 0x00005555, 0x04001858, 0x00107000, 0x00000002, 0x00005555,
432 0x03001062, 0x00101032, 0x00000001, 0x03001062, 0x001010f2, 0x00000002,
433 0x03000065, 0x001020f2, 0x00000000, 0x02000068, 0x00000002, 0x09000045,
434 0x001000f2, 0x00000000, 0x00101046, 0x00000001, 0x00107e46, 0x00000000,
435 0x00106000, 0x00000000, 0x09000045, 0x001000f2, 0x00000001, 0x00101046,
436 0x00000001, 0x00107e46, 0x00000001, 0x00106000, 0x00000000, 0x05000036,
437 0x00100022, 0x00000000, 0x0010000a, 0x00000001, 0x09000045, 0x001000f2,
438 0x00000001, 0x00101046, 0x00000001, 0x00107e46, 0x00000002, 0x00106000,
439 0x00000000, 0x05000036, 0x00100042, 0x00000000, 0x0010000a, 0x00000001,
440 0x0a000000, 0x00100072, 0x00000000, 0x00100246, 0x00000000, 0x00004002,
441 0xbd808081, 0xbf008081, 0xbf008081, 0x00000000, 0x0a00000f, 0x00100012,
442 0x00000001, 0x00100086, 0x00000000, 0x00004002, 0x3f94fdf4, 0x3fcc49ba,
443 0x00000000, 0x00000000, 0x0a000010, 0x00100022, 0x00000001, 0x00100246,
444 0x00000000, 0x00004002, 0x3f94fdf4, 0xbec83127, 0xbf5020c5, 0x00000000,
445 0x0a00000f, 0x00100042, 0x00000001, 0x00100046, 0x00000000, 0x00004002,
446 0x3f94fdf4, 0x400126e9, 0x00000000, 0x00000000, 0x05000036, 0x00100082,
447 0x00000001, 0x00004001, 0x3f800000, 0x07000038, 0x001020f2, 0x00000000,
448 0x00100e46, 0x00000001, 0x00101e46, 0x00000002, 0x0100003e, 0x54415453,
449 0x00000074, 0x0000000c, 0x00000002, 0x00000000, 0x00000003, 0x00000005,
450 0x00000000, 0x00000000, 0x00000001, 0x00000000, 0x00000000, 0x00000000,
451 0x00000000, 0x00000000, 0x00000000, 0x00000003, 0x00000000, 0x00000000,
452 0x00000000, 0x00000000, 0x00000003, 0x00000000, 0x00000000, 0x00000000,
453 0x00000000, 0x00000000, 0x00000000, 0x00000000, 0x00000000, 0x00000000,
454 0x46454452, 0x00000100, 0x00000000, 0x00000000, 0x00000004, 0x0000001c,
455 0xffff0400, 0x00000100, 0x000000cb, 0x0000009c, 0x00000003, 0x00000000,
456 0x00000000, 0x00000000, 0x00000000, 0x00000001, 0x00000001, 0x000000a7,
457 0x00000002, 0x00000005, 0x00000004, 0xffffffff, 0x00000000, 0x00000001,
458 0x0000000d, 0x000000b3, 0x00000002, 0x00000005, 0x00000004, 0xffffffff,
459 0x00000001, 0x00000001, 0x0000000d, 0x000000bf, 0x00000002, 0x00000005,
460 0x00000004, 0xffffffff, 0x00000002, 0x00000001, 0x0000000d, 0x53656874,
461 0x6c706d61, 0x74007265, 0x65546568, 0x72757478, 0x74005965, 0x65546568,
462 0x72757478, 0x74005565, 0x65546568, 0x72757478, 0x4d005665, 0x6f726369,
463 0x74666f73, 0x29522820, 0x534c4820, 0x6853204c, 0x72656461, 0x6d6f4320,
464 0x656c6970, 0x2e362072, 0x36392e33, 0x312e3030, 0x34383336, 0xababab00,
465 0x4e475349, 0x0000006c, 0x00000003, 0x00000008, 0x00000050, 0x00000000,
466 0x00000001, 0x00000003, 0x00000000, 0x0000000f, 0x0000005c, 0x00000000,
467 0x00000000, 0x00000003, 0x00000001, 0x00000303, 0x00000065, 0x00000000,
468 0x00000000, 0x00000003, 0x00000002, 0x00000f0f, 0x505f5653, 0x5449534f,
469 0x004e4f49, 0x43584554, 0x44524f4f, 0x4c4f4300, 0xab00524f, 0x4e47534f,
470 0x0000002c, 0x00000001, 0x00000008, 0x00000020, 0x00000000, 0x00000000,
471 0x00000003, 0x00000000, 0x0000000f, 0x545f5653, 0x45475241, 0xabab0054
473 #elif defined(D3D11_USE_SHADER_MODEL_4_0_level_9_3) 474 static const DWORD D3D11_PixelShader_YUV[] = {
475 0x43425844, 0x6ede7360, 0x45ff5f8a, 0x34ac92ba, 0xb865f5e0, 0x00000001,
476 0x000005c0, 0x00000006, 0x00000038, 0x000001b4, 0x00000394, 0x00000410,
477 0x00000518, 0x0000058c, 0x396e6f41, 0x00000174, 0x00000174, 0xffff0200,
478 0x00000144, 0x00000030, 0x00300000, 0x00300000, 0x00300000, 0x00240003,
479 0x00300000, 0x00000000, 0x00010001, 0x00020002, 0xffff0201, 0x05000051,
480 0xa00f0000, 0xbd808081, 0xbf008081, 0x3f800000, 0x00000000, 0x05000051,
481 0xa00f0001, 0x3f94fdf4, 0x3fcc49ba, 0x00000000, 0x400126e9, 0x05000051,
482 0xa00f0002, 0x3f94fdf4, 0xbec83127, 0xbf5020c5, 0x00000000, 0x0200001f,
483 0x80000000, 0xb0030000, 0x0200001f, 0x80000000, 0xb00f0001, 0x0200001f,
484 0x90000000, 0xa00f0800, 0x0200001f, 0x90000000, 0xa00f0801, 0x0200001f,
485 0x90000000, 0xa00f0802, 0x03000042, 0x800f0000, 0xb0e40000, 0xa0e40801,
486 0x03000042, 0x800f0001, 0xb0e40000, 0xa0e40800, 0x02000001, 0x80020001,
487 0x80000000, 0x03000042, 0x800f0000, 0xb0e40000, 0xa0e40802, 0x02000001,
488 0x80040001, 0x80000000, 0x03000002, 0x80070000, 0x80e40001, 0xa0d40000,
489 0x0400005a, 0x80010001, 0x80e80000, 0xa0e40001, 0xa0aa0001, 0x03000008,
490 0x80020001, 0x80e40000, 0xa0e40002, 0x0400005a, 0x80040001, 0x80e40000,
491 0xa0ec0001, 0xa0aa0001, 0x02000001, 0x80080001, 0xa0aa0000, 0x03000005,
492 0x800f0000, 0x80e40001, 0xb0e40001, 0x02000001, 0x800f0800, 0x80e40000,
493 0x0000ffff, 0x52444853, 0x000001d8, 0x00000040, 0x00000076, 0x0300005a,
494 0x00106000, 0x00000000, 0x04001858, 0x00107000, 0x00000000, 0x00005555,
495 0x04001858, 0x00107000, 0x00000001, 0x00005555, 0x04001858, 0x00107000,
496 0x00000002, 0x00005555, 0x03001062, 0x00101032, 0x00000001, 0x03001062,
497 0x001010f2, 0x00000002, 0x03000065, 0x001020f2, 0x00000000, 0x02000068,
498 0x00000002, 0x09000045, 0x001000f2, 0x00000000, 0x00101046, 0x00000001,
499 0x00107e46, 0x00000000, 0x00106000, 0x00000000, 0x09000045, 0x001000f2,
500 0x00000001, 0x00101046, 0x00000001, 0x00107e46, 0x00000001, 0x00106000,
501 0x00000000, 0x05000036, 0x00100022, 0x00000000, 0x0010000a, 0x00000001,
502 0x09000045, 0x001000f2, 0x00000001, 0x00101046, 0x00000001, 0x00107e46,
503 0x00000002, 0x00106000, 0x00000000, 0x05000036, 0x00100042, 0x00000000,
504 0x0010000a, 0x00000001, 0x0a000000, 0x00100072, 0x00000000, 0x00100246,
505 0x00000000, 0x00004002, 0xbd808081, 0xbf008081, 0xbf008081, 0x00000000,
506 0x0a00000f, 0x00100012, 0x00000001, 0x00100086, 0x00000000, 0x00004002,
507 0x3f94fdf4, 0x3fcc49ba, 0x00000000, 0x00000000, 0x0a000010, 0x00100022,
508 0x00000001, 0x00100246, 0x00000000, 0x00004002, 0x3f94fdf4, 0xbec83127,
509 0xbf5020c5, 0x00000000, 0x0a00000f, 0x00100042, 0x00000001, 0x00100046,
510 0x00000000, 0x00004002, 0x3f94fdf4, 0x400126e9, 0x00000000, 0x00000000,
511 0x05000036, 0x00100082, 0x00000001, 0x00004001, 0x3f800000, 0x07000038,
512 0x001020f2, 0x00000000, 0x00100e46, 0x00000001, 0x00101e46, 0x00000002,
513 0x0100003e, 0x54415453, 0x00000074, 0x0000000c, 0x00000002, 0x00000000,
514 0x00000003, 0x00000005, 0x00000000, 0x00000000, 0x00000001, 0x00000000,
515 0x00000000, 0x00000000, 0x00000000, 0x00000000, 0x00000000, 0x00000003,
516 0x00000000, 0x00000000, 0x00000000, 0x00000000, 0x00000003, 0x00000000,
517 0x00000000, 0x00000000, 0x00000000, 0x00000000, 0x00000000, 0x00000000,
518 0x00000000, 0x00000000, 0x46454452, 0x00000100, 0x00000000, 0x00000000,
519 0x00000004, 0x0000001c, 0xffff0400, 0x00000100, 0x000000cb, 0x0000009c,
520 0x00000003, 0x00000000, 0x00000000, 0x00000000, 0x00000000, 0x00000001,
521 0x00000001, 0x000000a7, 0x00000002, 0x00000005, 0x00000004, 0xffffffff,
522 0x00000000, 0x00000001, 0x0000000d, 0x000000b3, 0x00000002, 0x00000005,
523 0x00000004, 0xffffffff, 0x00000001, 0x00000001, 0x0000000d, 0x000000bf,
524 0x00000002, 0x00000005, 0x00000004, 0xffffffff, 0x00000002, 0x00000001,
525 0x0000000d, 0x53656874, 0x6c706d61, 0x74007265, 0x65546568, 0x72757478,
526 0x74005965, 0x65546568, 0x72757478, 0x74005565, 0x65546568, 0x72757478,
527 0x4d005665, 0x6f726369, 0x74666f73, 0x29522820, 0x534c4820, 0x6853204c,
528 0x72656461, 0x6d6f4320, 0x656c6970, 0x2e362072, 0x36392e33, 0x312e3030,
529 0x34383336, 0xababab00, 0x4e475349, 0x0000006c, 0x00000003, 0x00000008,
530 0x00000050, 0x00000000, 0x00000001, 0x00000003, 0x00000000, 0x0000000f,
531 0x0000005c, 0x00000000, 0x00000000, 0x00000003, 0x00000001, 0x00000303,
532 0x00000065, 0x00000000, 0x00000000, 0x00000003, 0x00000002, 0x00000f0f,
533 0x505f5653, 0x5449534f, 0x004e4f49, 0x43584554, 0x44524f4f, 0x4c4f4300,
534 0xab00524f, 0x4e47534f, 0x0000002c, 0x00000001, 0x00000008, 0x00000020,
535 0x00000000, 0x00000000, 0x00000003, 0x00000000, 0x0000000f, 0x545f5653,
536 0x45475241, 0xabab0054
539 #error "An appropriate 'yuv' pixel shader is not defined." 584 #if defined(D3D11_USE_SHADER_MODEL_4_0_level_9_1) 585 static const DWORD D3D11_VertexShader[] = {
586 0x43425844, 0x62dfae5f, 0x3e8bd8df, 0x9ec97127, 0x5044eefb, 0x00000001,
587 0x00000598, 0x00000006, 0x00000038, 0x0000016c, 0x00000334, 0x000003b0,
588 0x000004b4, 0x00000524, 0x396e6f41, 0x0000012c, 0x0000012c, 0xfffe0200,
589 0x000000f8, 0x00000034, 0x00240001, 0x00300000, 0x00300000, 0x00240000,
590 0x00300001, 0x00000000, 0x00010008, 0x00000000, 0x00000000, 0xfffe0200,
591 0x0200001f, 0x80000005, 0x900f0000, 0x0200001f, 0x80010005, 0x900f0001,
592 0x0200001f, 0x80020005, 0x900f0002, 0x03000005, 0x800f0000, 0x90550000,
593 0xa0e40002, 0x04000004, 0x800f0000, 0x90000000, 0xa0e40001, 0x80e40000,
594 0x04000004, 0x800f0000, 0x90aa0000, 0xa0e40003, 0x80e40000, 0x03000002,
595 0x800f0000, 0x80e40000, 0xa0e40004, 0x03000005, 0x800f0001, 0x80550000,
596 0xa0e40006, 0x04000004, 0x800f0001, 0x80000000, 0xa0e40005, 0x80e40001,
597 0x04000004, 0x800f0001, 0x80aa0000, 0xa0e40007, 0x80e40001, 0x04000004,
598 0x800f0000, 0x80ff0000, 0xa0e40008, 0x80e40001, 0x04000004, 0xc0030000,
599 0x80ff0000, 0xa0e40000, 0x80e40000, 0x02000001, 0xc00c0000, 0x80e40000,
600 0x02000001, 0xe0030000, 0x90e40001, 0x02000001, 0xe00f0001, 0x90e40002,
601 0x0000ffff, 0x52444853, 0x000001c0, 0x00010040, 0x00000070, 0x04000059,
602 0x00208e46, 0x00000000, 0x00000008, 0x0300005f, 0x00101072, 0x00000000,
603 0x0300005f, 0x00101032, 0x00000001, 0x0300005f, 0x001010f2, 0x00000002,
604 0x04000067, 0x001020f2, 0x00000000, 0x00000001, 0x03000065, 0x00102032,
605 0x00000001, 0x03000065, 0x001020f2, 0x00000002, 0x02000068, 0x00000002,
606 0x08000038, 0x001000f2, 0x00000000, 0x00101556, 0x00000000, 0x00208e46,
607 0x00000000, 0x00000001, 0x0a000032, 0x001000f2, 0x00000000, 0x00101006,
608 0x00000000, 0x00208e46, 0x00000000, 0x00000000, 0x00100e46, 0x00000000,
609 0x0a000032, 0x001000f2, 0x00000000, 0x00101aa6, 0x00000000, 0x00208e46,
610 0x00000000, 0x00000002, 0x00100e46, 0x00000000, 0x08000000, 0x001000f2,
611 0x00000000, 0x00100e46, 0x00000000, 0x00208e46, 0x00000000, 0x00000003,
612 0x08000038, 0x001000f2, 0x00000001, 0x00100556, 0x00000000, 0x00208e46,
613 0x00000000, 0x00000005, 0x0a000032, 0x001000f2, 0x00000001, 0x00100006,
614 0x00000000, 0x00208e46, 0x00000000, 0x00000004, 0x00100e46, 0x00000001,
615 0x0a000032, 0x001000f2, 0x00000001, 0x00100aa6, 0x00000000, 0x00208e46,
616 0x00000000, 0x00000006, 0x00100e46, 0x00000001, 0x0a000032, 0x001020f2,
617 0x00000000, 0x00100ff6, 0x00000000, 0x00208e46, 0x00000000, 0x00000007,
618 0x00100e46, 0x00000001, 0x05000036, 0x00102032, 0x00000001, 0x00101046,
619 0x00000001, 0x05000036, 0x001020f2, 0x00000002, 0x00101e46, 0x00000002,
620 0x0100003e, 0x54415453, 0x00000074, 0x0000000b, 0x00000002, 0x00000000,
621 0x00000006, 0x00000003, 0x00000000, 0x00000000, 0x00000001, 0x00000000,
622 0x00000000, 0x00000000, 0x00000000, 0x00000000, 0x00000000, 0x00000000,
623 0x00000000, 0x00000000, 0x00000000, 0x00000000, 0x00000003, 0x00000000,
624 0x00000000, 0x00000000, 0x00000000, 0x00000000, 0x00000000, 0x00000000,
625 0x00000000, 0x00000000, 0x46454452, 0x000000fc, 0x00000001, 0x00000054,
626 0x00000001, 0x0000001c, 0xfffe0400, 0x00000100, 0x000000c6, 0x0000003c,
627 0x00000000, 0x00000000, 0x00000000, 0x00000000, 0x00000000, 0x00000001,
628 0x00000001, 0x74726556, 0x68537865, 0x72656461, 0x736e6f43, 0x746e6174,
629 0xabab0073, 0x0000003c, 0x00000002, 0x0000006c, 0x00000080, 0x00000000,
630 0x00000000, 0x0000009c, 0x00000000, 0x00000040, 0x00000002, 0x000000a4,
631 0x00000000, 0x000000b4, 0x00000040, 0x00000040, 0x00000002, 0x000000a4,
632 0x00000000, 0x65646f6d, 0xabab006c, 0x00030002, 0x00040004, 0x00000000,
633 0x00000000, 0x6a6f7270, 0x69746365, 0x6e416e6f, 0x65695664, 0x694d0077,
634 0x736f7263, 0x2074666f, 0x20295228, 0x4c534c48, 0x61685320, 0x20726564,
635 0x706d6f43, 0x72656c69, 0x332e3920, 0x32392e30, 0x312e3030, 0x34383336,
636 0xababab00, 0x4e475349, 0x00000068, 0x00000003, 0x00000008, 0x00000050,
637 0x00000000, 0x00000000, 0x00000003, 0x00000000, 0x00000707, 0x00000059,
638 0x00000000, 0x00000000, 0x00000003, 0x00000001, 0x00000303, 0x00000062,
639 0x00000000, 0x00000000, 0x00000003, 0x00000002, 0x00000f0f, 0x49534f50,
640 0x4e4f4954, 0x58455400, 0x524f4f43, 0x4f430044, 0x00524f4c, 0x4e47534f,
641 0x0000006c, 0x00000003, 0x00000008, 0x00000050, 0x00000000, 0x00000001,
642 0x00000003, 0x00000000, 0x0000000f, 0x0000005c, 0x00000000, 0x00000000,
643 0x00000003, 0x00000001, 0x00000c03, 0x00000065, 0x00000000, 0x00000000,
644 0x00000003, 0x00000002, 0x0000000f, 0x505f5653, 0x5449534f, 0x004e4f49,
645 0x43584554, 0x44524f4f, 0x4c4f4300, 0xab00524f
647 #elif defined(D3D11_USE_SHADER_MODEL_4_0_level_9_3) 648 static const DWORD D3D11_VertexShader[] = {
649 0x43425844, 0x01a24e41, 0x696af551, 0x4b2a87d1, 0x82ea03f6, 0x00000001,
650 0x00000598, 0x00000006, 0x00000038, 0x0000016c, 0x00000334, 0x000003b0,
651 0x000004b4, 0x00000524, 0x396e6f41, 0x0000012c, 0x0000012c, 0xfffe0200,
652 0x000000f8, 0x00000034, 0x00240001, 0x00300000, 0x00300000, 0x00240000,
653 0x00300001, 0x00000000, 0x00010008, 0x00000000, 0x00000000, 0xfffe0201,
654 0x0200001f, 0x80000005, 0x900f0000, 0x0200001f, 0x80010005, 0x900f0001,
655 0x0200001f, 0x80020005, 0x900f0002, 0x03000005, 0x800f0000, 0x90550000,
656 0xa0e40002, 0x04000004, 0x800f0000, 0x90000000, 0xa0e40001, 0x80e40000,
657 0x04000004, 0x800f0000, 0x90aa0000, 0xa0e40003, 0x80e40000, 0x03000002,
658 0x800f0000, 0x80e40000, 0xa0e40004, 0x03000005, 0x800f0001, 0x80550000,
659 0xa0e40006, 0x04000004, 0x800f0001, 0x80000000, 0xa0e40005, 0x80e40001,
660 0x04000004, 0x800f0001, 0x80aa0000, 0xa0e40007, 0x80e40001, 0x04000004,
661 0x800f0000, 0x80ff0000, 0xa0e40008, 0x80e40001, 0x04000004, 0xc0030000,
662 0x80ff0000, 0xa0e40000, 0x80e40000, 0x02000001, 0xc00c0000, 0x80e40000,
663 0x02000001, 0xe0030000, 0x90e40001, 0x02000001, 0xe00f0001, 0x90e40002,
664 0x0000ffff, 0x52444853, 0x000001c0, 0x00010040, 0x00000070, 0x04000059,
665 0x00208e46, 0x00000000, 0x00000008, 0x0300005f, 0x00101072, 0x00000000,
666 0x0300005f, 0x00101032, 0x00000001, 0x0300005f, 0x001010f2, 0x00000002,
667 0x04000067, 0x001020f2, 0x00000000, 0x00000001, 0x03000065, 0x00102032,
668 0x00000001, 0x03000065, 0x001020f2, 0x00000002, 0x02000068, 0x00000002,
669 0x08000038, 0x001000f2, 0x00000000, 0x00101556, 0x00000000, 0x00208e46,
670 0x00000000, 0x00000001, 0x0a000032, 0x001000f2, 0x00000000, 0x00101006,
671 0x00000000, 0x00208e46, 0x00000000, 0x00000000, 0x00100e46, 0x00000000,
672 0x0a000032, 0x001000f2, 0x00000000, 0x00101aa6, 0x00000000, 0x00208e46,
673 0x00000000, 0x00000002, 0x00100e46, 0x00000000, 0x08000000, 0x001000f2,
674 0x00000000, 0x00100e46, 0x00000000, 0x00208e46, 0x00000000, 0x00000003,
675 0x08000038, 0x001000f2, 0x00000001, 0x00100556, 0x00000000, 0x00208e46,
676 0x00000000, 0x00000005, 0x0a000032, 0x001000f2, 0x00000001, 0x00100006,
677 0x00000000, 0x00208e46, 0x00000000, 0x00000004, 0x00100e46, 0x00000001,
678 0x0a000032, 0x001000f2, 0x00000001, 0x00100aa6, 0x00000000, 0x00208e46,
679 0x00000000, 0x00000006, 0x00100e46, 0x00000001, 0x0a000032, 0x001020f2,
680 0x00000000, 0x00100ff6, 0x00000000, 0x00208e46, 0x00000000, 0x00000007,
681 0x00100e46, 0x00000001, 0x05000036, 0x00102032, 0x00000001, 0x00101046,
682 0x00000001, 0x05000036, 0x001020f2, 0x00000002, 0x00101e46, 0x00000002,
683 0x0100003e, 0x54415453, 0x00000074, 0x0000000b, 0x00000002, 0x00000000,
684 0x00000006, 0x00000003, 0x00000000, 0x00000000, 0x00000001, 0x00000000,
685 0x00000000, 0x00000000, 0x00000000, 0x00000000, 0x00000000, 0x00000000,
686 0x00000000, 0x00000000, 0x00000000, 0x00000000, 0x00000003, 0x00000000,
687 0x00000000, 0x00000000, 0x00000000, 0x00000000, 0x00000000, 0x00000000,
688 0x00000000, 0x00000000, 0x46454452, 0x000000fc, 0x00000001, 0x00000054,
689 0x00000001, 0x0000001c, 0xfffe0400, 0x00000100, 0x000000c6, 0x0000003c,
690 0x00000000, 0x00000000, 0x00000000, 0x00000000, 0x00000000, 0x00000001,
691 0x00000001, 0x74726556, 0x68537865, 0x72656461, 0x736e6f43, 0x746e6174,
692 0xabab0073, 0x0000003c, 0x00000002, 0x0000006c, 0x00000080, 0x00000000,
693 0x00000000, 0x0000009c, 0x00000000, 0x00000040, 0x00000002, 0x000000a4,
694 0x00000000, 0x000000b4, 0x00000040, 0x00000040, 0x00000002, 0x000000a4,
695 0x00000000, 0x65646f6d, 0xabab006c, 0x00030002, 0x00040004, 0x00000000,
696 0x00000000, 0x6a6f7270, 0x69746365, 0x6e416e6f, 0x65695664, 0x694d0077,
697 0x736f7263, 0x2074666f, 0x20295228, 0x4c534c48, 0x61685320, 0x20726564,
698 0x706d6f43, 0x72656c69, 0x332e3920, 0x32392e30, 0x312e3030, 0x34383336,
699 0xababab00, 0x4e475349, 0x00000068, 0x00000003, 0x00000008, 0x00000050,
700 0x00000000, 0x00000000, 0x00000003, 0x00000000, 0x00000707, 0x00000059,
701 0x00000000, 0x00000000, 0x00000003, 0x00000001, 0x00000303, 0x00000062,
702 0x00000000, 0x00000000, 0x00000003, 0x00000002, 0x00000f0f, 0x49534f50,
703 0x4e4f4954, 0x58455400, 0x524f4f43, 0x4f430044, 0x00524f4c, 0x4e47534f,
704 0x0000006c, 0x00000003, 0x00000008, 0x00000050, 0x00000000, 0x00000001,
705 0x00000003, 0x00000000, 0x0000000f, 0x0000005c, 0x00000000, 0x00000000,
706 0x00000003, 0x00000001, 0x00000c03, 0x00000065, 0x00000000, 0x00000000,
707 0x00000003, 0x00000002, 0x0000000f, 0x505f5653, 0x5449534f, 0x004e4f49,
708 0x43584554, 0x44524f4f, 0x4c4f4300, 0xab00524f
711 #error "An appropriate vertex shader is not defined." 725 const Uint8 *Yplane,
int Ypitch,
726 const Uint8 *Uplane,
int Upitch,
727 const Uint8 *Vplane,
int Vpitch);
761 D3D11_CreateRenderer,
783 D3D11_DXGIFormatToSDLPixelFormat(DXGI_FORMAT dxgiFormat) {
784 switch (dxgiFormat) {
785 case DXGI_FORMAT_B8G8R8A8_UNORM:
787 case DXGI_FORMAT_B8G8R8X8_UNORM:
795 SDLPixelFormatToDXGIFormat(
Uint32 sdlFormat)
799 return DXGI_FORMAT_B8G8R8A8_UNORM;
801 return DXGI_FORMAT_B8G8R8X8_UNORM;
804 return DXGI_FORMAT_R8_UNORM;
806 return DXGI_FORMAT_UNKNOWN;
814 D3D11_RenderData *
data;
822 data = (D3D11_RenderData *)
SDL_calloc(1,
sizeof(*data));
847 renderer->
info = D3D11_RenderDriver.
info;
851 #if WINAPI_FAMILY == WINAPI_FAMILY_PHONE_APP 876 if (
FAILED(D3D11_CreateDeviceResources(renderer))) {
877 D3D11_DestroyRenderer(renderer);
880 if (
FAILED(D3D11_CreateWindowSizeDependentResources(renderer))) {
881 D3D11_DestroyRenderer(renderer);
891 D3D11_RenderData *data = (D3D11_RenderData *) renderer->
driverdata;
896 D3D11_DestroyTexture(renderer,
texture);
901 SAFE_RELEASE(data->dxgiFactory);
902 SAFE_RELEASE(data->dxgiAdapter);
903 SAFE_RELEASE(data->d3dDevice);
904 SAFE_RELEASE(data->d3dContext);
905 SAFE_RELEASE(data->swapChain);
906 SAFE_RELEASE(data->mainRenderTargetView);
907 SAFE_RELEASE(data->currentOffscreenRenderTargetView);
908 SAFE_RELEASE(data->inputLayout);
909 SAFE_RELEASE(data->vertexBuffer);
910 SAFE_RELEASE(data->vertexShader);
911 SAFE_RELEASE(data->colorPixelShader);
912 SAFE_RELEASE(data->texturePixelShader);
913 SAFE_RELEASE(data->yuvPixelShader);
914 SAFE_RELEASE(data->blendModeBlend);
915 SAFE_RELEASE(data->blendModeAdd);
916 SAFE_RELEASE(data->blendModeMod);
917 SAFE_RELEASE(data->nearestPixelSampler);
918 SAFE_RELEASE(data->linearSampler);
919 SAFE_RELEASE(data->mainRasterizer);
920 SAFE_RELEASE(data->clippedRasterizer);
921 SAFE_RELEASE(data->vertexShaderConstants);
923 data->swapEffect = (DXGI_SWAP_EFFECT) 0;
924 data->rotation = DXGI_MODE_ROTATION_UNSPECIFIED;
925 data->currentRenderTargetView =
NULL;
926 data->currentRasterizerState =
NULL;
927 data->currentBlendState =
NULL;
928 data->currentShader =
NULL;
929 data->currentShaderResource =
NULL;
930 data->currentSampler =
NULL;
935 if (data->hD3D11Mod) {
937 data->hD3D11Mod =
NULL;
939 if (data->hDXGIMod) {
941 data->hDXGIMod =
NULL;
949 D3D11_RenderData *data = (D3D11_RenderData *) renderer->
driverdata;
950 D3D11_ReleaseAll(renderer);
960 D3D11_BLEND srcBlend,
961 D3D11_BLEND destBlend,
962 D3D11_BLEND srcBlendAlpha,
963 D3D11_BLEND destBlendAlpha,
964 ID3D11BlendState ** blendStateOutput)
966 D3D11_RenderData *data = (D3D11_RenderData *) renderer->
driverdata;
969 D3D11_BLEND_DESC blendDesc;
971 blendDesc.AlphaToCoverageEnable =
FALSE;
972 blendDesc.IndependentBlendEnable =
FALSE;
973 blendDesc.RenderTarget[0].BlendEnable = enableBlending;
974 blendDesc.RenderTarget[0].SrcBlend = srcBlend;
975 blendDesc.RenderTarget[0].DestBlend = destBlend;
976 blendDesc.RenderTarget[0].BlendOp = D3D11_BLEND_OP_ADD;
977 blendDesc.RenderTarget[0].SrcBlendAlpha = srcBlendAlpha;
978 blendDesc.RenderTarget[0].DestBlendAlpha = destBlendAlpha;
979 blendDesc.RenderTarget[0].BlendOpAlpha = D3D11_BLEND_OP_ADD;
980 blendDesc.RenderTarget[0].RenderTargetWriteMask = D3D11_COLOR_WRITE_ENABLE_ALL;
981 result = ID3D11Device_CreateBlendState(data->d3dDevice, &blendDesc, blendStateOutput);
994 typedef HRESULT(WINAPI *PFN_CREATE_DXGI_FACTORY)(REFIID riid,
void **ppFactory);
995 PFN_CREATE_DXGI_FACTORY CreateDXGIFactoryFunc;
996 D3D11_RenderData *data = (D3D11_RenderData *) renderer->
driverdata;
997 PFN_D3D11_CREATE_DEVICE D3D11CreateDeviceFunc;
998 ID3D11Device *d3dDevice =
NULL;
999 ID3D11DeviceContext *d3dContext =
NULL;
1000 IDXGIDevice1 *dxgiDevice =
NULL;
1009 D3D_FEATURE_LEVEL featureLevels[] =
1011 D3D_FEATURE_LEVEL_11_1,
1012 D3D_FEATURE_LEVEL_11_0,
1013 D3D_FEATURE_LEVEL_10_1,
1014 D3D_FEATURE_LEVEL_10_0,
1015 D3D_FEATURE_LEVEL_9_3,
1016 D3D_FEATURE_LEVEL_9_2,
1017 D3D_FEATURE_LEVEL_9_1
1021 const D3D11_INPUT_ELEMENT_DESC vertexDesc[] =
1023 {
"POSITION", 0, DXGI_FORMAT_R32G32B32_FLOAT, 0, 0, D3D11_INPUT_PER_VERTEX_DATA, 0 },
1024 {
"TEXCOORD", 0, DXGI_FORMAT_R32G32_FLOAT, 0, 12, D3D11_INPUT_PER_VERTEX_DATA, 0 },
1025 {
"COLOR", 0, DXGI_FORMAT_R32G32B32A32_FLOAT, 0, 20, D3D11_INPUT_PER_VERTEX_DATA, 0 },
1028 D3D11_BUFFER_DESC constantBufferDesc;
1029 D3D11_SAMPLER_DESC samplerDesc;
1030 D3D11_RASTERIZER_DESC rasterDesc;
1033 CreateDXGIFactoryFunc = CreateDXGIFactory1;
1034 D3D11CreateDeviceFunc = D3D11CreateDevice;
1037 if (!data->hDXGIMod) {
1042 CreateDXGIFactoryFunc = (PFN_CREATE_DXGI_FACTORY)
SDL_LoadFunction(data->hDXGIMod,
"CreateDXGIFactory");
1043 if (!CreateDXGIFactoryFunc) {
1049 if (!data->hD3D11Mod) {
1054 D3D11CreateDeviceFunc = (PFN_D3D11_CREATE_DEVICE)
SDL_LoadFunction(data->hD3D11Mod,
"D3D11CreateDevice");
1055 if (!D3D11CreateDeviceFunc) {
1061 result = CreateDXGIFactoryFunc(&SDL_IID_IDXGIFactory2, (
void **)&data->dxgiFactory);
1068 result = IDXGIFactory2_EnumAdapters(data->dxgiFactory, 0, &data->dxgiAdapter);
1077 creationFlags = D3D11_CREATE_DEVICE_BGRA_SUPPORT;
1081 creationFlags |= D3D11_CREATE_DEVICE_DEBUG;
1085 result = D3D11CreateDeviceFunc(
1087 D3D_DRIVER_TYPE_UNKNOWN,
1094 &data->featureLevel,
1102 result = ID3D11Device_QueryInterface(d3dDevice, &SDL_IID_ID3D11Device1, (
void **)&data->d3dDevice);
1108 result = ID3D11DeviceContext_QueryInterface(d3dContext, &SDL_IID_ID3D11DeviceContext1, (
void **)&data->d3dContext);
1114 result = ID3D11Device_QueryInterface(d3dDevice, &SDL_IID_IDXGIDevice1, (
void **)&dxgiDevice);
1123 result = IDXGIDevice1_SetMaximumFrameLatency(dxgiDevice, 1);
1133 switch (data->featureLevel) {
1134 case D3D_FEATURE_LEVEL_11_1:
1135 case D3D_FEATURE_LEVEL_11_0:
1139 case D3D_FEATURE_LEVEL_10_1:
1140 case D3D_FEATURE_LEVEL_10_0:
1144 case D3D_FEATURE_LEVEL_9_3:
1148 case D3D_FEATURE_LEVEL_9_2:
1149 case D3D_FEATURE_LEVEL_9_1:
1154 SDL_SetError(
"%s, Unexpected feature level: %d", __FUNCTION__, data->featureLevel);
1160 result = ID3D11Device_CreateVertexShader(data->d3dDevice,
1162 sizeof(D3D11_VertexShader),
1172 result = ID3D11Device_CreateInputLayout(data->d3dDevice,
1174 ARRAYSIZE(vertexDesc),
1176 sizeof(D3D11_VertexShader),
1185 result = ID3D11Device_CreatePixelShader(data->d3dDevice,
1186 D3D11_PixelShader_Colors,
1187 sizeof(D3D11_PixelShader_Colors),
1189 &data->colorPixelShader
1196 result = ID3D11Device_CreatePixelShader(data->d3dDevice,
1197 D3D11_PixelShader_Textures,
1198 sizeof(D3D11_PixelShader_Textures),
1200 &data->texturePixelShader
1207 result = ID3D11Device_CreatePixelShader(data->d3dDevice,
1208 D3D11_PixelShader_YUV,
1209 sizeof(D3D11_PixelShader_YUV),
1211 &data->yuvPixelShader
1220 constantBufferDesc.ByteWidth =
sizeof(VertexShaderConstants);
1221 constantBufferDesc.Usage = D3D11_USAGE_DEFAULT;
1222 constantBufferDesc.BindFlags = D3D11_BIND_CONSTANT_BUFFER;
1223 result = ID3D11Device_CreateBuffer(data->d3dDevice,
1224 &constantBufferDesc,
1226 &data->vertexShaderConstants
1235 samplerDesc.Filter = D3D11_FILTER_MIN_MAG_MIP_POINT;
1236 samplerDesc.AddressU = D3D11_TEXTURE_ADDRESS_CLAMP;
1237 samplerDesc.AddressV = D3D11_TEXTURE_ADDRESS_CLAMP;
1238 samplerDesc.AddressW = D3D11_TEXTURE_ADDRESS_CLAMP;
1239 samplerDesc.MipLODBias = 0.0f;
1240 samplerDesc.MaxAnisotropy = 1;
1241 samplerDesc.ComparisonFunc = D3D11_COMPARISON_ALWAYS;
1242 samplerDesc.MinLOD = 0.0f;
1243 samplerDesc.MaxLOD = D3D11_FLOAT32_MAX;
1244 result = ID3D11Device_CreateSamplerState(data->d3dDevice,
1246 &data->nearestPixelSampler
1253 samplerDesc.Filter = D3D11_FILTER_MIN_MAG_MIP_LINEAR;
1254 result = ID3D11Device_CreateSamplerState(data->d3dDevice,
1256 &data->linearSampler
1265 rasterDesc.AntialiasedLineEnable =
FALSE;
1266 rasterDesc.CullMode = D3D11_CULL_NONE;
1267 rasterDesc.DepthBias = 0;
1268 rasterDesc.DepthBiasClamp = 0.0f;
1269 rasterDesc.DepthClipEnable =
TRUE;
1270 rasterDesc.FillMode = D3D11_FILL_SOLID;
1271 rasterDesc.FrontCounterClockwise =
FALSE;
1272 rasterDesc.MultisampleEnable =
FALSE;
1273 rasterDesc.ScissorEnable =
FALSE;
1274 rasterDesc.SlopeScaledDepthBias = 0.0f;
1275 result = ID3D11Device_CreateRasterizerState(data->d3dDevice, &rasterDesc, &data->mainRasterizer);
1281 rasterDesc.ScissorEnable =
TRUE;
1282 result = ID3D11Device_CreateRasterizerState(data->d3dDevice, &rasterDesc, &data->clippedRasterizer);
1289 result = D3D11_CreateBlendMode(
1292 D3D11_BLEND_SRC_ALPHA,
1293 D3D11_BLEND_INV_SRC_ALPHA,
1295 D3D11_BLEND_INV_SRC_ALPHA,
1296 &data->blendModeBlend);
1302 result = D3D11_CreateBlendMode(
1305 D3D11_BLEND_SRC_ALPHA,
1309 &data->blendModeAdd);
1315 result = D3D11_CreateBlendMode(
1319 D3D11_BLEND_SRC_COLOR,
1322 &data->blendModeMod);
1329 ID3D11DeviceContext_IASetInputLayout(data->d3dContext, data->inputLayout);
1330 ID3D11DeviceContext_VSSetShader(data->d3dContext, data->vertexShader,
NULL, 0);
1331 ID3D11DeviceContext_VSSetConstantBuffers(data->d3dContext, 0, 1, &data->vertexShaderConstants);
1334 SAFE_RELEASE(d3dDevice);
1335 SAFE_RELEASE(d3dContext);
1336 SAFE_RELEASE(dxgiDevice);
1342 static DXGI_MODE_ROTATION
1343 D3D11_GetCurrentRotation()
1346 return DXGI_MODE_ROTATION_IDENTITY;
1352 D3D11_IsDisplayRotated90Degrees(DXGI_MODE_ROTATION rotation)
1355 case DXGI_MODE_ROTATION_ROTATE90:
1356 case DXGI_MODE_ROTATION_ROTATE270:
1364 D3D11_GetRotationForCurrentRenderTarget(
SDL_Renderer * renderer)
1366 D3D11_RenderData *data = (D3D11_RenderData *)renderer->
driverdata;
1367 if (data->currentOffscreenRenderTargetView) {
1368 return DXGI_MODE_ROTATION_IDENTITY;
1370 return data->rotation;
1375 D3D11_GetViewportAlignedD3DRect(
SDL_Renderer * renderer,
const SDL_Rect * sdlRect, D3D11_RECT * outRect, BOOL includeViewportOffset)
1377 const int rotation = D3D11_GetRotationForCurrentRenderTarget(renderer);
1379 case DXGI_MODE_ROTATION_IDENTITY:
1380 outRect->left = sdlRect->
x;
1381 outRect->right = sdlRect->
x + sdlRect->
w;
1382 outRect->top = sdlRect->
y;
1383 outRect->bottom = sdlRect->
y + sdlRect->
h;
1384 if (includeViewportOffset) {
1388 outRect->bottom += renderer->
viewport.
y;
1391 case DXGI_MODE_ROTATION_ROTATE270:
1392 outRect->left = sdlRect->
y;
1393 outRect->right = sdlRect->
y + sdlRect->
h;
1394 outRect->top = renderer->
viewport.
w - sdlRect->
x - sdlRect->
w;
1395 outRect->bottom = renderer->
viewport.
w - sdlRect->
x;
1397 case DXGI_MODE_ROTATION_ROTATE180:
1398 outRect->left = renderer->
viewport.
w - sdlRect->
x - sdlRect->
w;
1399 outRect->right = renderer->
viewport.
w - sdlRect->
x;
1400 outRect->top = renderer->
viewport.
h - sdlRect->
y - sdlRect->
h;
1401 outRect->bottom = renderer->
viewport.
h - sdlRect->
y;
1403 case DXGI_MODE_ROTATION_ROTATE90:
1404 outRect->left = renderer->
viewport.
h - sdlRect->
y - sdlRect->
h;
1405 outRect->right = renderer->
viewport.
h - sdlRect->
y;
1406 outRect->top = sdlRect->
x;
1407 outRect->bottom = sdlRect->
x + sdlRect->
h;
1410 return SDL_SetError(
"The physical display is in an unknown or unsupported rotation");
1418 D3D11_RenderData *data = (D3D11_RenderData *)renderer->
driverdata;
1420 IUnknown *coreWindow = D3D11_GetCoreWindowFromSDLRenderer(renderer);
1421 const BOOL usingXAML = (coreWindow ==
NULL);
1423 IUnknown *coreWindow =
NULL;
1424 const BOOL usingXAML =
FALSE;
1429 DXGI_SWAP_CHAIN_DESC1 swapChainDesc;
1431 swapChainDesc.Width =
w;
1432 swapChainDesc.Height =
h;
1433 swapChainDesc.Format = DXGI_FORMAT_B8G8R8A8_UNORM;
1434 swapChainDesc.Stereo =
FALSE;
1435 swapChainDesc.SampleDesc.Count = 1;
1436 swapChainDesc.SampleDesc.Quality = 0;
1437 swapChainDesc.BufferUsage = DXGI_USAGE_RENDER_TARGET_OUTPUT;
1438 swapChainDesc.BufferCount = 2;
1439 #if WINAPI_FAMILY == WINAPI_FAMILY_PHONE_APP 1440 swapChainDesc.Scaling = DXGI_SCALING_STRETCH;
1441 swapChainDesc.SwapEffect = DXGI_SWAP_EFFECT_DISCARD;
1445 swapChainDesc.Scaling = DXGI_SCALING_STRETCH;
1447 swapChainDesc.Scaling = DXGI_SCALING_NONE;
1449 swapChainDesc.SwapEffect = DXGI_SWAP_EFFECT_FLIP_SEQUENTIAL;
1451 swapChainDesc.Flags = 0;
1454 result = IDXGIFactory2_CreateSwapChainForCoreWindow(data->dxgiFactory,
1455 (IUnknown *)data->d3dDevice,
1465 }
else if (usingXAML) {
1466 result = IDXGIFactory2_CreateSwapChainForComposition(data->dxgiFactory,
1467 (IUnknown *)data->d3dDevice,
1476 #if WINAPI_FAMILY == WINAPI_FAMILY_APP 1483 SDL_SetError(SDL_COMPOSE_ERROR(
"XAML support is not yet available for Windows Phone"));
1493 result = IDXGIFactory2_CreateSwapChainForHwnd(data->dxgiFactory,
1494 (IUnknown *)data->d3dDevice,
1506 IDXGIFactory_MakeWindowAssociation(data->dxgiFactory, windowinfo.
info.win.
window, DXGI_MWA_NO_WINDOW_CHANGES);
1508 SDL_SetError(__FUNCTION__
", Unable to find something to attach a swap chain to");
1512 data->swapEffect = swapChainDesc.SwapEffect;
1515 SAFE_RELEASE(coreWindow);
1522 D3D11_CreateWindowSizeDependentResources(
SDL_Renderer * renderer)
1524 D3D11_RenderData *data = (D3D11_RenderData *)renderer->
driverdata;
1525 ID3D11Texture2D *backBuffer =
NULL;
1526 HRESULT result =
S_OK;
1530 D3D11_ReleaseMainRenderTargetView(renderer);
1536 data->rotation = D3D11_GetCurrentRotation();
1538 if (D3D11_IsDisplayRotated90Degrees(data->rotation)) {
1544 if (data->swapChain) {
1546 #if !defined(__WINRT__) || (WINAPI_FAMILY != WINAPI_FAMILY_PHONE_APP) 1548 result = IDXGISwapChain_ResizeBuffers(data->swapChain,
1551 DXGI_FORMAT_UNKNOWN,
1554 if (result == DXGI_ERROR_DEVICE_REMOVED) {
1556 D3D11_HandleDeviceLost(renderer);
1562 }
else if (
FAILED(result)) {
1568 result = D3D11_CreateSwapChain(renderer, w, h);
1574 #if WINAPI_FAMILY != WINAPI_FAMILY_PHONE_APP 1591 if (data->swapEffect == DXGI_SWAP_EFFECT_FLIP_SEQUENTIAL) {
1592 result = IDXGISwapChain1_SetRotation(data->swapChain, data->rotation);
1600 result = IDXGISwapChain_GetBuffer(data->swapChain,
1602 &SDL_IID_ID3D11Texture2D,
1603 (
void **)&backBuffer
1611 result = ID3D11Device_CreateRenderTargetView(data->d3dDevice,
1612 (ID3D11Resource *)backBuffer,
1614 &data->mainRenderTargetView
1621 if (D3D11_UpdateViewport(renderer) != 0) {
1628 SAFE_RELEASE(backBuffer);
1634 D3D11_UpdateForWindowSizeChange(
SDL_Renderer * renderer)
1636 return D3D11_CreateWindowSizeDependentResources(renderer);
1642 HRESULT result =
S_OK;
1644 D3D11_ReleaseAll(renderer);
1646 result = D3D11_CreateDeviceResources(renderer);
1652 result = D3D11_UpdateForWindowSizeChange(renderer);
1672 #if NTDDI_VERSION > NTDDI_WIN8 1673 D3D11_RenderData *data = (D3D11_RenderData *)renderer->
driverdata;
1674 HRESULT result =
S_OK;
1675 IDXGIDevice3 *dxgiDevice =
NULL;
1677 result = ID3D11Device_QueryInterface(data->d3dDevice, &SDL_IID_IDXGIDevice3, &dxgiDevice);
1683 IDXGIDevice3_Trim(dxgiDevice);
1684 SAFE_RELEASE(dxgiDevice);
1693 D3D11_UpdateForWindowSizeChange(renderer);
1701 if (!hint || *hint ==
'0' ||
SDL_strcasecmp(hint,
"nearest") == 0) {
1702 return D3D11_FILTER_MIN_MAG_MIP_POINT;
1704 return D3D11_FILTER_MIN_MAG_MIP_LINEAR;
1711 D3D11_RenderData *rendererData = (D3D11_RenderData *) renderer->
driverdata;
1712 D3D11_TextureData *textureData;
1714 DXGI_FORMAT textureFormat = SDLPixelFormatToDXGIFormat(texture->
format);
1715 D3D11_TEXTURE2D_DESC textureDesc;
1716 D3D11_SHADER_RESOURCE_VIEW_DESC resourceViewDesc;
1718 if (textureFormat == DXGI_FORMAT_UNKNOWN) {
1719 return SDL_SetError(
"%s, An unsupported SDL pixel format (0x%x) was specified",
1720 __FUNCTION__, texture->
format);
1723 textureData = (D3D11_TextureData*)
SDL_calloc(1,
sizeof(*textureData));
1733 textureDesc.Width = texture->
w;
1734 textureDesc.Height = texture->
h;
1735 textureDesc.MipLevels = 1;
1736 textureDesc.ArraySize = 1;
1737 textureDesc.Format = textureFormat;
1738 textureDesc.SampleDesc.Count = 1;
1739 textureDesc.SampleDesc.Quality = 0;
1740 textureDesc.MiscFlags = 0;
1743 textureDesc.Usage = D3D11_USAGE_DYNAMIC;
1744 textureDesc.CPUAccessFlags = D3D11_CPU_ACCESS_WRITE;
1746 textureDesc.Usage = D3D11_USAGE_DEFAULT;
1747 textureDesc.CPUAccessFlags = 0;
1751 textureDesc.BindFlags = D3D11_BIND_SHADER_RESOURCE | D3D11_BIND_RENDER_TARGET;
1753 textureDesc.BindFlags = D3D11_BIND_SHADER_RESOURCE;
1756 result = ID3D11Device_CreateTexture2D(rendererData->d3dDevice,
1759 &textureData->mainTexture
1762 D3D11_DestroyTexture(renderer, texture);
1771 textureDesc.Width /= 2;
1772 textureDesc.Height /= 2;
1774 result = ID3D11Device_CreateTexture2D(rendererData->d3dDevice,
1777 &textureData->mainTextureU
1780 D3D11_DestroyTexture(renderer, texture);
1785 result = ID3D11Device_CreateTexture2D(rendererData->d3dDevice,
1788 &textureData->mainTextureV
1791 D3D11_DestroyTexture(renderer, texture);
1797 resourceViewDesc.Format = textureDesc.Format;
1798 resourceViewDesc.ViewDimension = D3D11_SRV_DIMENSION_TEXTURE2D;
1799 resourceViewDesc.Texture2D.MostDetailedMip = 0;
1800 resourceViewDesc.Texture2D.MipLevels = textureDesc.MipLevels;
1801 result = ID3D11Device_CreateShaderResourceView(rendererData->d3dDevice,
1802 (ID3D11Resource *)textureData->mainTexture,
1804 &textureData->mainTextureResourceView
1807 D3D11_DestroyTexture(renderer, texture);
1812 if (textureData->yuv) {
1813 result = ID3D11Device_CreateShaderResourceView(rendererData->d3dDevice,
1814 (ID3D11Resource *)textureData->mainTextureU,
1816 &textureData->mainTextureResourceViewU
1819 D3D11_DestroyTexture(renderer, texture);
1823 result = ID3D11Device_CreateShaderResourceView(rendererData->d3dDevice,
1824 (ID3D11Resource *)textureData->mainTextureV,
1826 &textureData->mainTextureResourceViewV
1829 D3D11_DestroyTexture(renderer, texture);
1836 D3D11_RENDER_TARGET_VIEW_DESC renderTargetViewDesc;
1837 renderTargetViewDesc.Format = textureDesc.Format;
1838 renderTargetViewDesc.ViewDimension = D3D11_RTV_DIMENSION_TEXTURE2D;
1839 renderTargetViewDesc.Texture2D.MipSlice = 0;
1841 result = ID3D11Device_CreateRenderTargetView(rendererData->d3dDevice,
1842 (ID3D11Resource *)textureData->mainTexture,
1843 &renderTargetViewDesc,
1844 &textureData->mainTextureRenderTargetView);
1846 D3D11_DestroyTexture(renderer, texture);
1859 D3D11_TextureData *data = (D3D11_TextureData *)texture->
driverdata;
1865 SAFE_RELEASE(data->mainTexture);
1866 SAFE_RELEASE(data->mainTextureResourceView);
1867 SAFE_RELEASE(data->mainTextureRenderTargetView);
1868 SAFE_RELEASE(data->stagingTexture);
1869 SAFE_RELEASE(data->mainTextureU);
1870 SAFE_RELEASE(data->mainTextureResourceViewU);
1871 SAFE_RELEASE(data->mainTextureV);
1872 SAFE_RELEASE(data->mainTextureResourceViewV);
1879 D3D11_UpdateTextureInternal(D3D11_RenderData *rendererData, ID3D11Texture2D *texture,
Uint32 format,
int x,
int y,
int w,
int h,
const void *
pixels,
int pitch)
1881 ID3D11Texture2D *stagingTexture;
1887 D3D11_TEXTURE2D_DESC stagingTextureDesc;
1888 D3D11_MAPPED_SUBRESOURCE textureMemory;
1891 ID3D11Texture2D_GetDesc(texture, &stagingTextureDesc);
1892 stagingTextureDesc.Width =
w;
1893 stagingTextureDesc.Height =
h;
1894 stagingTextureDesc.BindFlags = 0;
1895 stagingTextureDesc.MiscFlags = 0;
1896 stagingTextureDesc.CPUAccessFlags = D3D11_CPU_ACCESS_WRITE;
1897 stagingTextureDesc.Usage = D3D11_USAGE_STAGING;
1898 result = ID3D11Device_CreateTexture2D(rendererData->d3dDevice,
1899 &stagingTextureDesc,
1903 WIN_SetErrorFromHRESULT(SDL_COMPOSE_ERROR(
"ID3D11Device1::CreateTexture2D [create staging texture]"), result);
1908 result = ID3D11DeviceContext_Map(rendererData->d3dContext,
1909 (ID3D11Resource *)stagingTexture,
1917 SAFE_RELEASE(stagingTexture);
1921 src = (
const Uint8 *)pixels;
1922 dst = textureMemory.pData;
1924 if (length == pitch && length == textureMemory.RowPitch) {
1927 if (length > (UINT)pitch) {
1930 if (length > textureMemory.RowPitch) {
1931 length = textureMemory.RowPitch;
1933 for (row = 0; row <
h; ++
row) {
1936 dst += textureMemory.RowPitch;
1941 ID3D11DeviceContext_Unmap(rendererData->d3dContext,
1942 (ID3D11Resource *)stagingTexture,
1946 ID3D11DeviceContext_CopySubresourceRegion(rendererData->d3dContext,
1947 (ID3D11Resource *)texture,
1952 (ID3D11Resource *)stagingTexture,
1956 SAFE_RELEASE(stagingTexture);
1966 D3D11_RenderData *rendererData = (D3D11_RenderData *)renderer->
driverdata;
1967 D3D11_TextureData *textureData = (D3D11_TextureData *)texture->
driverdata;
1974 if (D3D11_UpdateTextureInternal(rendererData, textureData->mainTexture, texture->
format, rect->
x, rect->
y, rect->
w, rect->
h, srcPixels, srcPitch) < 0) {
1978 if (textureData->yuv) {
1980 srcPixels = (
const void*)((
const Uint8*)srcPixels + rect->
h * srcPitch);
1982 if (D3D11_UpdateTextureInternal(rendererData, texture->
format ==
SDL_PIXELFORMAT_YV12 ? textureData->mainTextureV : textureData->mainTextureU, texture->
format, rect->
x / 2, rect->
y / 2, rect->
w / 2, rect->
h / 2, srcPixels, srcPitch / 2) < 0) {
1987 srcPixels = (
const void*)((
const Uint8*)srcPixels + (rect->
h * srcPitch) / 4);
1988 if (D3D11_UpdateTextureInternal(rendererData, texture->
format ==
SDL_PIXELFORMAT_YV12 ? textureData->mainTextureU : textureData->mainTextureV, texture->
format, rect->
x / 2, rect->
y / 2, rect->
w / 2, rect->
h / 2, srcPixels, srcPitch / 2) < 0) {
1998 const Uint8 *Yplane,
int Ypitch,
1999 const Uint8 *Uplane,
int Upitch,
2000 const Uint8 *Vplane,
int Vpitch)
2002 D3D11_RenderData *rendererData = (D3D11_RenderData *)renderer->
driverdata;
2003 D3D11_TextureData *textureData = (D3D11_TextureData *)texture->
driverdata;
2010 if (D3D11_UpdateTextureInternal(rendererData, textureData->mainTexture, texture->
format, rect->
x, rect->
y, rect->
w, rect->
h, Yplane, Ypitch) < 0) {
2013 if (D3D11_UpdateTextureInternal(rendererData, textureData->mainTextureU, texture->
format, rect->
x / 2, rect->
y / 2, rect->
w / 2, rect->
h / 2, Uplane, Upitch) < 0) {
2016 if (D3D11_UpdateTextureInternal(rendererData, textureData->mainTextureV, texture->
format, rect->
x / 2, rect->
y / 2, rect->
w / 2, rect->
h / 2, Vplane, Vpitch) < 0) {
2024 const SDL_Rect * rect,
void **pixels,
int *pitch)
2026 D3D11_RenderData *rendererData = (D3D11_RenderData *) renderer->
driverdata;
2027 D3D11_TextureData *textureData = (D3D11_TextureData *) texture->
driverdata;
2028 HRESULT result =
S_OK;
2029 D3D11_TEXTURE2D_DESC stagingTextureDesc;
2030 D3D11_MAPPED_SUBRESOURCE textureMemory;
2037 if (textureData->yuv) {
2039 if (!textureData->pixels) {
2040 textureData->pitch = texture->
w;
2041 textureData->pixels = (
Uint8 *)
SDL_malloc((texture->
h * textureData->pitch * 3) / 2);
2042 if (!textureData->pixels) {
2046 textureData->locked_rect = *
rect;
2048 (
void *)((
Uint8 *)textureData->pixels + rect->
y * textureData->pitch +
2050 *pitch = textureData->pitch;
2054 if (textureData->stagingTexture) {
2066 ID3D11Texture2D_GetDesc(textureData->mainTexture, &stagingTextureDesc);
2067 stagingTextureDesc.Width = rect->
w;
2068 stagingTextureDesc.Height = rect->
h;
2069 stagingTextureDesc.BindFlags = 0;
2070 stagingTextureDesc.MiscFlags = 0;
2071 stagingTextureDesc.CPUAccessFlags = D3D11_CPU_ACCESS_WRITE;
2072 stagingTextureDesc.Usage = D3D11_USAGE_STAGING;
2073 result = ID3D11Device_CreateTexture2D(rendererData->d3dDevice,
2074 &stagingTextureDesc,
2076 &textureData->stagingTexture);
2078 WIN_SetErrorFromHRESULT(SDL_COMPOSE_ERROR(
"ID3D11Device1::CreateTexture2D [create staging texture]"), result);
2083 result = ID3D11DeviceContext_Map(rendererData->d3dContext,
2084 (ID3D11Resource *)textureData->stagingTexture,
2092 SAFE_RELEASE(textureData->stagingTexture);
2099 textureData->lockedTexturePositionX = rect->
x;
2100 textureData->lockedTexturePositionY = rect->
y;
2105 *pixels = textureMemory.pData;
2106 *pitch = textureMemory.RowPitch;
2113 D3D11_RenderData *rendererData = (D3D11_RenderData *) renderer->
driverdata;
2114 D3D11_TextureData *textureData = (D3D11_TextureData *) texture->
driverdata;
2120 if (textureData->yuv) {
2121 const SDL_Rect *rect = &textureData->locked_rect;
2123 (
void *) ((
Uint8 *) textureData->pixels + rect->
y * textureData->pitch +
2125 D3D11_UpdateTexture(renderer, texture, rect, pixels, textureData->pitch);
2130 ID3D11DeviceContext_Unmap(rendererData->d3dContext,
2131 (ID3D11Resource *)textureData->stagingTexture,
2135 ID3D11DeviceContext_CopySubresourceRegion(rendererData->d3dContext,
2136 (ID3D11Resource *)textureData->mainTexture,
2138 textureData->lockedTexturePositionX,
2139 textureData->lockedTexturePositionY,
2141 (ID3D11Resource *)textureData->stagingTexture,
2145 SAFE_RELEASE(textureData->stagingTexture);
2151 D3D11_RenderData *rendererData = (D3D11_RenderData *) renderer->
driverdata;
2152 D3D11_TextureData *textureData =
NULL;
2154 if (texture ==
NULL) {
2155 rendererData->currentOffscreenRenderTargetView =
NULL;
2159 textureData = (D3D11_TextureData *) texture->
driverdata;
2161 if (!textureData->mainTextureRenderTargetView) {
2162 return SDL_SetError(
"specified texture is not a render target");
2165 rendererData->currentOffscreenRenderTargetView = textureData->mainTextureRenderTargetView;
2173 D3D11_RenderData *data = (D3D11_RenderData *)renderer->
driverdata;
2176 data->vertexShaderConstantsData.model = *
matrix;
2178 data->vertexShaderConstantsData.model = MatrixIdentity();
2181 ID3D11DeviceContext_UpdateSubresource(data->d3dContext,
2182 (ID3D11Resource *)data->vertexShaderConstants,
2185 &data->vertexShaderConstantsData,
2194 D3D11_RenderData *data = (D3D11_RenderData *) renderer->
driverdata;
2195 Float4X4 projection;
2198 BOOL swapDimensions;
2200 const int rotation = D3D11_GetRotationForCurrentRenderTarget(renderer);
2217 case DXGI_MODE_ROTATION_IDENTITY:
2218 projection = MatrixIdentity();
2220 case DXGI_MODE_ROTATION_ROTATE270:
2223 case DXGI_MODE_ROTATION_ROTATE180:
2226 case DXGI_MODE_ROTATION_ROTATE90:
2230 return SDL_SetError(
"An unknown DisplayOrientation is being used");
2234 view.m[0][0] = 2.0f / renderer->
viewport.
w;
2235 view.m[0][1] = 0.0f;
2236 view.m[0][2] = 0.0f;
2237 view.m[0][3] = 0.0f;
2238 view.m[1][0] = 0.0f;
2239 view.m[1][1] = -2.0f / renderer->
viewport.
h;
2240 view.m[1][2] = 0.0f;
2241 view.m[1][3] = 0.0f;
2242 view.m[2][0] = 0.0f;
2243 view.m[2][1] = 0.0f;
2244 view.m[2][2] = 1.0f;
2245 view.m[2][3] = 0.0f;
2246 view.m[3][0] = -1.0f;
2247 view.m[3][1] = 1.0f;
2248 view.m[3][2] = 0.0f;
2249 view.m[3][3] = 1.0f;
2255 data->vertexShaderConstantsData.projectionAndView = MatrixMultiply(
2260 D3D11_SetModelMatrix(renderer,
NULL);
2267 swapDimensions = D3D11_IsDisplayRotated90Degrees(rotation);
2268 if (swapDimensions) {
2269 orientationAlignedViewport.x = (float) renderer->
viewport.
y;
2270 orientationAlignedViewport.y = (
float) renderer->
viewport.
x;
2271 orientationAlignedViewport.w = (float) renderer->
viewport.
h;
2272 orientationAlignedViewport.h = (
float) renderer->
viewport.
w;
2274 orientationAlignedViewport.x = (float) renderer->
viewport.
x;
2275 orientationAlignedViewport.y = (
float) renderer->
viewport.
y;
2276 orientationAlignedViewport.w = (float) renderer->
viewport.
w;
2277 orientationAlignedViewport.h = (
float) renderer->
viewport.
h;
2281 viewport.TopLeftX = orientationAlignedViewport.
x;
2282 viewport.TopLeftY = orientationAlignedViewport.
y;
2283 viewport.Width = orientationAlignedViewport.
w;
2284 viewport.Height = orientationAlignedViewport.
h;
2288 ID3D11DeviceContext_RSSetViewports(data->d3dContext, 1, &
viewport);
2296 D3D11_RenderData *data = (D3D11_RenderData *) renderer->
driverdata;
2299 ID3D11DeviceContext_RSSetScissorRects(data->d3dContext, 0,
NULL);
2301 D3D11_RECT scissorRect;
2302 if (D3D11_GetViewportAlignedD3DRect(renderer, &renderer->
clip_rect, &scissorRect,
TRUE) != 0) {
2306 ID3D11DeviceContext_RSSetScissorRects(data->d3dContext, 1, &scissorRect);
2313 D3D11_ReleaseMainRenderTargetView(
SDL_Renderer * renderer)
2315 D3D11_RenderData *data = (D3D11_RenderData *)renderer->
driverdata;
2316 ID3D11DeviceContext_OMSetRenderTargets(data->d3dContext, 0,
NULL,
NULL);
2317 SAFE_RELEASE(data->mainRenderTargetView);
2320 static ID3D11RenderTargetView *
2321 D3D11_GetCurrentRenderTargetView(
SDL_Renderer * renderer)
2323 D3D11_RenderData *data = (D3D11_RenderData *) renderer->
driverdata;
2324 if (data->currentOffscreenRenderTargetView) {
2325 return data->currentOffscreenRenderTargetView;
2327 return data->mainRenderTargetView;
2334 D3D11_RenderData *data = (D3D11_RenderData *) renderer->
driverdata;
2335 const float colorRGBA[] = {
2336 (renderer->
r / 255.0f),
2337 (renderer->
g / 255.0f),
2338 (renderer->
b / 255.0f),
2339 (renderer->
a / 255.0f)
2341 ID3D11DeviceContext_ClearRenderTargetView(data->d3dContext,
2342 D3D11_GetCurrentRenderTargetView(renderer),
2350 const void * vertexData,
size_t dataSizeInBytes)
2352 D3D11_RenderData *rendererData = (D3D11_RenderData *) renderer->
driverdata;
2353 D3D11_BUFFER_DESC vertexBufferDesc;
2354 HRESULT result =
S_OK;
2355 D3D11_SUBRESOURCE_DATA vertexBufferData;
2356 const UINT
stride =
sizeof(VertexPositionColor);
2359 if (rendererData->vertexBuffer) {
2360 ID3D11Buffer_GetDesc(rendererData->vertexBuffer, &vertexBufferDesc);
2365 if (rendererData->vertexBuffer && vertexBufferDesc.ByteWidth >= dataSizeInBytes) {
2366 D3D11_MAPPED_SUBRESOURCE mappedResource;
2367 result = ID3D11DeviceContext_Map(rendererData->d3dContext,
2368 (ID3D11Resource *)rendererData->vertexBuffer,
2370 D3D11_MAP_WRITE_DISCARD,
2378 SDL_memcpy(mappedResource.pData, vertexData, dataSizeInBytes);
2379 ID3D11DeviceContext_Unmap(rendererData->d3dContext, (ID3D11Resource *)rendererData->vertexBuffer, 0);
2381 SAFE_RELEASE(rendererData->vertexBuffer);
2383 vertexBufferDesc.ByteWidth = (UINT) dataSizeInBytes;
2384 vertexBufferDesc.Usage = D3D11_USAGE_DYNAMIC;
2385 vertexBufferDesc.BindFlags = D3D11_BIND_VERTEX_BUFFER;
2386 vertexBufferDesc.CPUAccessFlags = D3D11_CPU_ACCESS_WRITE;
2389 vertexBufferData.pSysMem = vertexData;
2390 vertexBufferData.SysMemPitch = 0;
2391 vertexBufferData.SysMemSlicePitch = 0;
2393 result = ID3D11Device_CreateBuffer(rendererData->d3dDevice,
2396 &rendererData->vertexBuffer
2403 ID3D11DeviceContext_IASetVertexBuffers(rendererData->d3dContext,
2406 &rendererData->vertexBuffer,
2418 D3D11_RenderData *rendererData = (D3D11_RenderData *)renderer->
driverdata;
2419 ID3D11RasterizerState *rasterizerState;
2420 ID3D11RenderTargetView *renderTargetView = D3D11_GetCurrentRenderTargetView(renderer);
2421 if (renderTargetView != rendererData->currentRenderTargetView) {
2422 ID3D11DeviceContext_OMSetRenderTargets(rendererData->d3dContext,
2427 rendererData->currentRenderTargetView = renderTargetView;
2431 rasterizerState = rendererData->mainRasterizer;
2433 rasterizerState = rendererData->clippedRasterizer;
2435 if (rasterizerState != rendererData->currentRasterizerState) {
2436 ID3D11DeviceContext_RSSetState(rendererData->d3dContext, rasterizerState);
2437 rendererData->currentRasterizerState = rasterizerState;
2444 D3D11_RenderData *rendererData = (D3D11_RenderData *)renderer->
driverdata;
2445 ID3D11BlendState *blendState =
NULL;
2446 switch (blendMode) {
2448 blendState = rendererData->blendModeBlend;
2451 blendState = rendererData->blendModeAdd;
2454 blendState = rendererData->blendModeMod;
2460 if (blendState != rendererData->currentBlendState) {
2461 ID3D11DeviceContext_OMSetBlendState(rendererData->d3dContext, blendState, 0, 0xFFFFFFFF);
2462 rendererData->currentBlendState = blendState;
2468 ID3D11PixelShader *
shader,
2469 int numShaderResources,
2470 ID3D11ShaderResourceView ** shaderResources,
2473 D3D11_RenderData *rendererData = (D3D11_RenderData *) renderer->
driverdata;
2474 ID3D11ShaderResourceView *shaderResource;
2475 if (shader != rendererData->currentShader) {
2476 ID3D11DeviceContext_PSSetShader(rendererData->d3dContext, shader,
NULL, 0);
2477 rendererData->currentShader =
shader;
2479 if (numShaderResources > 0) {
2480 shaderResource = shaderResources[0];
2482 shaderResource =
NULL;
2484 if (shaderResource != rendererData->currentShaderResource) {
2485 ID3D11DeviceContext_PSSetShaderResources(rendererData->d3dContext, 0, numShaderResources, shaderResources);
2486 rendererData->currentShaderResource = shaderResource;
2488 if (sampler != rendererData->currentSampler) {
2489 ID3D11DeviceContext_PSSetSamplers(rendererData->d3dContext, 0, 1, &sampler);
2490 rendererData->currentSampler =
sampler;
2496 D3D11_PRIMITIVE_TOPOLOGY primitiveTopology,
2499 D3D11_RenderData *rendererData = (D3D11_RenderData *) renderer->
driverdata;
2501 ID3D11DeviceContext_IASetPrimitiveTopology(rendererData->d3dContext, primitiveTopology);
2502 ID3D11DeviceContext_Draw(rendererData->d3dContext, vertexCount, 0);
2509 D3D11_RenderData *rendererData = (D3D11_RenderData *) renderer->
driverdata;
2511 VertexPositionColor *vertices;
2514 r = (
float)(renderer->
r / 255.0f);
2515 g = (float)(renderer->
g / 255.0f);
2516 b = (float)(renderer->
b / 255.0f);
2517 a = (float)(renderer->
a / 255.0f);
2521 const VertexPositionColor
v = { { points[
i].
x, points[
i].
y, 0.0f }, { 0.0f, 0.0f }, {
r,
g,
b,
a } };
2525 D3D11_RenderStartDrawOp(renderer);
2526 D3D11_RenderSetBlendMode(renderer, renderer->
blendMode);
2527 if (D3D11_UpdateVertexBuffer(renderer, vertices, (
unsigned int)count *
sizeof(VertexPositionColor)) != 0) {
2532 D3D11_SetPixelShader(
2534 rendererData->colorPixelShader,
2539 D3D11_RenderFinishDrawOp(renderer, D3D11_PRIMITIVE_TOPOLOGY_POINTLIST, count);
2548 D3D11_RenderData *rendererData = (D3D11_RenderData *) renderer->
driverdata;
2550 VertexPositionColor *vertices;
2553 r = (
float)(renderer->
r / 255.0f);
2554 g = (float)(renderer->
g / 255.0f);
2555 b = (float)(renderer->
b / 255.0f);
2556 a = (float)(renderer->
a / 255.0f);
2560 const VertexPositionColor
v = { { points[
i].
x, points[
i].
y, 0.0f }, { 0.0f, 0.0f }, {
r,
g,
b,
a } };
2564 D3D11_RenderStartDrawOp(renderer);
2565 D3D11_RenderSetBlendMode(renderer, renderer->
blendMode);
2566 if (D3D11_UpdateVertexBuffer(renderer, vertices, (
unsigned int)count *
sizeof(VertexPositionColor)) != 0) {
2571 D3D11_SetPixelShader(
2573 rendererData->colorPixelShader,
2578 D3D11_RenderFinishDrawOp(renderer, D3D11_PRIMITIVE_TOPOLOGY_LINESTRIP, count);
2587 D3D11_RenderData *rendererData = (D3D11_RenderData *) renderer->
driverdata;
2591 r = (
float)(renderer->
r / 255.0f);
2592 g = (float)(renderer->
g / 255.0f);
2593 b = (float)(renderer->
b / 255.0f);
2594 a = (float)(renderer->
a / 255.0f);
2597 VertexPositionColor vertices[] = {
2598 { { rects[
i].
x, rects[
i].
y, 0.0f }, { 0.0f, 0.0f}, {
r,
g,
b,
a} },
2599 { { rects[
i].
x, rects[
i].
y + rects[
i].
h, 0.0f }, { 0.0f, 0.0f }, {
r,
g,
b, a } },
2600 { { rects[
i].
x + rects[
i].
w, rects[
i].
y, 0.0f }, { 0.0f, 0.0f }, {
r,
g,
b, a } },
2601 { { rects[
i].
x + rects[
i].
w, rects[
i].
y + rects[
i].
h, 0.0f }, { 0.0f, 0.0f }, {
r,
g,
b, a } },
2604 D3D11_RenderStartDrawOp(renderer);
2605 D3D11_RenderSetBlendMode(renderer, renderer->
blendMode);
2606 if (D3D11_UpdateVertexBuffer(renderer, vertices,
sizeof(vertices)) != 0) {
2610 D3D11_SetPixelShader(
2612 rendererData->colorPixelShader,
2617 D3D11_RenderFinishDrawOp(renderer, D3D11_PRIMITIVE_TOPOLOGY_TRIANGLESTRIP,
SDL_arraysize(vertices));
2623 static ID3D11SamplerState *
2626 D3D11_RenderData *rendererData = (D3D11_RenderData *) renderer->
driverdata;
2627 D3D11_TextureData *textureData = (D3D11_TextureData *) texture->
driverdata;
2629 switch (textureData->scaleMode) {
2630 case D3D11_FILTER_MIN_MAG_MIP_POINT:
2631 return rendererData->nearestPixelSampler;
2632 case D3D11_FILTER_MIN_MAG_MIP_LINEAR:
2633 return rendererData->linearSampler;
2643 D3D11_RenderData *rendererData = (D3D11_RenderData *) renderer->
driverdata;
2644 D3D11_TextureData *textureData = (D3D11_TextureData *) texture->
driverdata;
2645 float minu, maxu, minv, maxv;
2647 VertexPositionColor vertices[4];
2648 ID3D11SamplerState *textureSampler;
2650 D3D11_RenderStartDrawOp(renderer);
2651 D3D11_RenderSetBlendMode(renderer, texture->
blendMode);
2653 minu = (float) srcrect->
x / texture->
w;
2654 maxu = (
float) (srcrect->
x + srcrect->
w) / texture->
w;
2655 minv = (
float) srcrect->
y / texture->
h;
2656 maxv = (float) (srcrect->
y + srcrect->
h) / texture->
h;
2663 color.x = (float)(texture->
r / 255.0f);
2664 color.y = (float)(texture->
g / 255.0f);
2665 color.z = (float)(texture->
b / 255.0f);
2668 color.w = (float)(texture->
a / 255.0f);
2671 vertices[0].pos.x = dstrect->
x;
2672 vertices[0].pos.y = dstrect->
y;
2673 vertices[0].pos.z = 0.0f;
2674 vertices[0].tex.x = minu;
2675 vertices[0].tex.y = minv;
2676 vertices[0].color =
color;
2678 vertices[1].pos.x = dstrect->
x;
2679 vertices[1].pos.y = dstrect->
y + dstrect->
h;
2680 vertices[1].pos.z = 0.0f;
2681 vertices[1].tex.x = minu;
2682 vertices[1].tex.y = maxv;
2683 vertices[1].color =
color;
2685 vertices[2].pos.x = dstrect->
x + dstrect->
w;
2686 vertices[2].pos.y = dstrect->
y;
2687 vertices[2].pos.z = 0.0f;
2688 vertices[2].tex.x = maxu;
2689 vertices[2].tex.y = minv;
2690 vertices[2].color =
color;
2692 vertices[3].pos.x = dstrect->
x + dstrect->
w;
2693 vertices[3].pos.y = dstrect->
y + dstrect->
h;
2694 vertices[3].pos.z = 0.0f;
2695 vertices[3].tex.x = maxu;
2696 vertices[3].tex.y = maxv;
2697 vertices[3].color =
color;
2699 if (D3D11_UpdateVertexBuffer(renderer, vertices,
sizeof(vertices)) != 0) {
2703 textureSampler = D3D11_RenderGetSampler(renderer, texture);
2704 if (textureData->yuv) {
2705 ID3D11ShaderResourceView *shaderResources[] = {
2706 textureData->mainTextureResourceView,
2707 textureData->mainTextureResourceViewU,
2708 textureData->mainTextureResourceViewV
2710 D3D11_SetPixelShader(
2712 rendererData->yuvPixelShader,
2717 D3D11_SetPixelShader(
2719 rendererData->texturePixelShader,
2721 &textureData->mainTextureResourceView,
2725 D3D11_RenderFinishDrawOp(renderer, D3D11_PRIMITIVE_TOPOLOGY_TRIANGLESTRIP,
sizeof(vertices) /
sizeof(VertexPositionColor));
2735 D3D11_RenderData *rendererData = (D3D11_RenderData *) renderer->
driverdata;
2736 D3D11_TextureData *textureData = (D3D11_TextureData *) texture->
driverdata;
2737 float minu, maxu, minv, maxv;
2739 Float4X4 modelMatrix;
2740 float minx, maxx, miny, maxy;
2741 VertexPositionColor vertices[4];
2742 ID3D11SamplerState *textureSampler;
2744 D3D11_RenderStartDrawOp(renderer);
2745 D3D11_RenderSetBlendMode(renderer, texture->
blendMode);
2747 minu = (float) srcrect->
x / texture->
w;
2748 maxu = (
float) (srcrect->
x + srcrect->
w) / texture->
w;
2749 minv = (
float) srcrect->
y / texture->
h;
2750 maxv = (float) (srcrect->
y + srcrect->
h) / texture->
h;
2757 color.x = (float)(texture->
r / 255.0f);
2758 color.y = (float)(texture->
g / 255.0f);
2759 color.z = (float)(texture->
b / 255.0f);
2762 color.w = (float)(texture->
a / 255.0f);
2776 modelMatrix = MatrixMultiply(
2777 MatrixRotationZ((
float)(M_PI * (
float) angle / 180.0
f)),
2778 MatrixTranslation(dstrect->
x + center->
x, dstrect->
y + center->
y, 0)
2780 D3D11_SetModelMatrix(renderer, &modelMatrix);
2783 maxx = dstrect->
w - center->
x;
2785 maxy = dstrect->
h - center->
y;
2787 vertices[0].pos.x = minx;
2788 vertices[0].pos.y = miny;
2789 vertices[0].pos.z = 0.0f;
2790 vertices[0].tex.x = minu;
2791 vertices[0].tex.y = minv;
2792 vertices[0].color =
color;
2794 vertices[1].pos.x = minx;
2795 vertices[1].pos.y = maxy;
2796 vertices[1].pos.z = 0.0f;
2797 vertices[1].tex.x = minu;
2798 vertices[1].tex.y = maxv;
2799 vertices[1].color =
color;
2801 vertices[2].pos.x = maxx;
2802 vertices[2].pos.y = miny;
2803 vertices[2].pos.z = 0.0f;
2804 vertices[2].tex.x = maxu;
2805 vertices[2].tex.y = minv;
2806 vertices[2].color =
color;
2808 vertices[3].pos.x = maxx;
2809 vertices[3].pos.y = maxy;
2810 vertices[3].pos.z = 0.0f;
2811 vertices[3].tex.x = maxu;
2812 vertices[3].tex.y = maxv;
2813 vertices[3].color =
color;
2815 if (D3D11_UpdateVertexBuffer(renderer, vertices,
sizeof(vertices)) != 0) {
2819 textureSampler = D3D11_RenderGetSampler(renderer, texture);
2820 if (textureData->yuv) {
2821 ID3D11ShaderResourceView *shaderResources[] = {
2822 textureData->mainTextureResourceView,
2823 textureData->mainTextureResourceViewU,
2824 textureData->mainTextureResourceViewV
2826 D3D11_SetPixelShader(
2828 rendererData->yuvPixelShader,
2833 D3D11_SetPixelShader(
2835 rendererData->texturePixelShader,
2837 &textureData->mainTextureResourceView,
2841 D3D11_RenderFinishDrawOp(renderer, D3D11_PRIMITIVE_TOPOLOGY_TRIANGLESTRIP,
sizeof(vertices) /
sizeof(VertexPositionColor));
2843 D3D11_SetModelMatrix(renderer,
NULL);
2850 Uint32 format,
void * pixels,
int pitch)
2852 D3D11_RenderData * data = (D3D11_RenderData *) renderer->
driverdata;
2853 ID3D11Texture2D *backBuffer =
NULL;
2854 ID3D11Texture2D *stagingTexture =
NULL;
2857 D3D11_TEXTURE2D_DESC stagingTextureDesc;
2858 D3D11_RECT srcRect = {0, 0, 0, 0};
2860 D3D11_MAPPED_SUBRESOURCE textureMemory;
2863 result = IDXGISwapChain_GetBuffer(data->swapChain,
2865 &SDL_IID_ID3D11Texture2D,
2866 (
void **)&backBuffer
2874 ID3D11Texture2D_GetDesc(backBuffer, &stagingTextureDesc);
2875 stagingTextureDesc.Width = rect->
w;
2876 stagingTextureDesc.Height = rect->
h;
2877 stagingTextureDesc.BindFlags = 0;
2878 stagingTextureDesc.MiscFlags = 0;
2879 stagingTextureDesc.CPUAccessFlags = D3D11_CPU_ACCESS_READ;
2880 stagingTextureDesc.Usage = D3D11_USAGE_STAGING;
2881 result = ID3D11Device_CreateTexture2D(data->d3dDevice,
2882 &stagingTextureDesc,
2886 WIN_SetErrorFromHRESULT(SDL_COMPOSE_ERROR(
"ID3D11Device1::CreateTexture2D [create staging texture]"), result);
2891 if (D3D11_GetViewportAlignedD3DRect(renderer, rect, &srcRect,
FALSE) != 0) {
2896 srcBox.left = srcRect.left;
2897 srcBox.right = srcRect.right;
2898 srcBox.top = srcRect.top;
2899 srcBox.bottom = srcRect.bottom;
2902 ID3D11DeviceContext_CopySubresourceRegion(data->d3dContext,
2903 (ID3D11Resource *)stagingTexture,
2906 (ID3D11Resource *)backBuffer,
2911 result = ID3D11DeviceContext_Map(data->d3dContext,
2912 (ID3D11Resource *)stagingTexture,
2927 D3D11_DXGIFormatToSDLPixelFormat(stagingTextureDesc.Format),
2928 textureMemory.pData,
2929 textureMemory.RowPitch,
2936 char errorMessage[1024];
2943 ID3D11DeviceContext_Unmap(data->d3dContext,
2944 (ID3D11Resource *)stagingTexture,
2950 SAFE_RELEASE(backBuffer);
2951 SAFE_RELEASE(stagingTexture);
2958 D3D11_RenderData *data = (D3D11_RenderData *) renderer->
driverdata;
2962 DXGI_PRESENT_PARAMETERS parameters;
2966 #if WINAPI_FAMILY == WINAPI_FAMILY_PHONE_APP 2969 result = IDXGISwapChain_Present(data->swapChain, syncInterval, presentFlags);
2971 if (renderer->
info.
flags & SDL_RENDERER_PRESENTVSYNC) {
2976 presentFlags = DXGI_PRESENT_DO_NOT_WAIT;
2983 result = IDXGISwapChain1_Present1(data->swapChain, syncInterval, presentFlags, ¶meters);
2990 ID3D11DeviceContext1_DiscardView(data->d3dContext, (ID3D11View*)data->mainRenderTargetView);
2993 data->currentRenderTargetView =
NULL;
2995 if (
FAILED(result) && result != DXGI_ERROR_WAS_STILL_DRAWING) {
3001 if ( result == DXGI_ERROR_DEVICE_REMOVED ) {
3002 D3D11_HandleDeviceLost(renderer);
3003 }
else if (result == DXGI_ERROR_INVALID_CALL) {
3005 D3D11_CreateWindowSizeDependentResources(renderer);
int(* RenderDrawLines)(SDL_Renderer *renderer, const SDL_FPoint *points, int count)
GLint GLint GLsizei GLsizei GLsizei GLint GLenum format
int(* RenderDrawPoints)(SDL_Renderer *renderer, const SDL_FPoint *points, int count)
int(* LockTexture)(SDL_Renderer *renderer, SDL_Texture *texture, const SDL_Rect *rect, void **pixels, int *pitch)
GLdouble GLdouble GLdouble r
int(* RenderReadPixels)(SDL_Renderer *renderer, const SDL_Rect *rect, Uint32 format, void *pixels, int pitch)
GLint GLint GLint GLint GLint x
SDL_BlendMode
The blend mode used in SDL_RenderCopy() and drawing operations.
GLuint GLuint GLsizei count
#define SDL_HINT_RENDER_SCALE_QUALITY
A variable controlling the scaling quality.
static SDL_Window * window
GLenum GLenum GLuint texture
int WIN_SetErrorFromHRESULT(const char *prefix, HRESULT hr)
GLint GLenum GLsizei GLsizei GLsizei GLint GLsizei const GLvoid * data
#define SDL_BYTESPERPIXEL(X)
int(* RenderFillRects)(SDL_Renderer *renderer, const SDL_FRect *rects, int count)
GLint GLint GLsizei GLsizei GLsizei GLint GLenum GLenum const GLvoid * pixels
uint32_t Uint32
An unsigned 32-bit integer type.
int(* RenderClear)(SDL_Renderer *renderer)
#define SDL_HINT_RENDER_DIRECT3D11_DEBUG
A variable controlling whether to enable Direct3D 11+'s Debug Layer.
void(* DestroyRenderer)(SDL_Renderer *renderer)
GLfixed GLfixed GLint GLint GLfixed points
#define SDL_GetHintBoolean
#define SDL_VERSION(x)
Macro to determine SDL version program was compiled against.
static SDL_BlendMode blendMode
int(* UpdateTexture)(SDL_Renderer *renderer, SDL_Texture *texture, const SDL_Rect *rect, const 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)
#define SDL_GetWindowSize
void * SDL_calloc(size_t nmemb, size_t size)
GLint GLint GLint GLint GLint GLint y
static int GetScaleQuality(void)
static SDL_Renderer * renderer
uint8_t Uint8
An unsigned 8-bit integer type.
#define SDL_stack_alloc(type, count)
#define SDL_static_cast(type, expression)
void(* UnlockTexture)(SDL_Renderer *renderer, SDL_Texture *texture)
int(* SetRenderTarget)(SDL_Renderer *renderer, SDL_Texture *texture)
int(* UpdateViewport)(SDL_Renderer *renderer)
SDL_RendererFlip
Flip constants for SDL_RenderCopyEx.
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)
int(* RenderCopy)(SDL_Renderer *renderer, SDL_Texture *texture, const SDL_Rect *srcrect, const SDL_FRect *dstrect)
Window state change event data (event.window.*)
#define SDL_GetWindowWMInfo
#define SDL_OutOfMemory()
int(* RenderCopyEx)(SDL_Renderer *renderer, SDL_Texture *texture, const SDL_Rect *srcquad, const SDL_FRect *dstrect, const double angle, const SDL_FPoint *center, const SDL_RendererFlip flip)
The type used to identify a window.
SDL_Rect rects[MAX_RECTS]
void(* WindowEvent)(SDL_Renderer *renderer, const SDL_WindowEvent *event)
union SDL_SysWMinfo::@18 info
#define SDL_arraysize(array)
GLubyte GLubyte GLubyte GLubyte w
#define SDL_ConvertPixels
void(* DestroyTexture)(SDL_Renderer *renderer, SDL_Texture *texture)
void * SDL_LoadFunction(void *handle, const char *name)
int(* CreateTexture)(SDL_Renderer *renderer, SDL_Texture *texture)
void(* RenderPresent)(SDL_Renderer *renderer)
#define SDL_stack_free(data)
GLuint GLsizei GLsizei * length
GLboolean GLboolean GLboolean GLboolean a
int(* UpdateClipRect)(SDL_Renderer *renderer)
GLboolean GLboolean GLboolean b
GLfloat GLfloat GLfloat GLfloat h
SDL_bool clipping_enabled
A rectangle, with the origin at the upper left.