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;
100 ID3D11BlendState *blendState;
108 IDXGIFactory2 *dxgiFactory;
109 IDXGIAdapter *dxgiAdapter;
110 ID3D11Device1 *d3dDevice;
111 ID3D11DeviceContext1 *d3dContext;
112 IDXGISwapChain1 *swapChain;
113 DXGI_SWAP_EFFECT swapEffect;
114 ID3D11RenderTargetView *mainRenderTargetView;
115 ID3D11RenderTargetView *currentOffscreenRenderTargetView;
116 ID3D11InputLayout *inputLayout;
117 ID3D11Buffer *vertexBuffer;
118 ID3D11VertexShader *vertexShader;
119 ID3D11PixelShader *colorPixelShader;
120 ID3D11PixelShader *texturePixelShader;
121 ID3D11PixelShader *yuvPixelShader;
123 D3D11_BlendMode *blendModes;
124 ID3D11SamplerState *nearestPixelSampler;
125 ID3D11SamplerState *linearSampler;
126 D3D_FEATURE_LEVEL featureLevel;
129 ID3D11RasterizerState *mainRasterizer;
130 ID3D11RasterizerState *clippedRasterizer;
133 VertexShaderConstants vertexShaderConstantsData;
134 ID3D11Buffer *vertexShaderConstants;
137 DXGI_MODE_ROTATION rotation;
138 ID3D11RenderTargetView *currentRenderTargetView;
139 ID3D11RasterizerState *currentRasterizerState;
140 ID3D11BlendState *currentBlendState;
141 ID3D11PixelShader *currentShader;
142 ID3D11ShaderResourceView *currentShaderResource;
143 ID3D11SamplerState *currentSampler;
157 #pragma GCC diagnostic push 158 #pragma GCC diagnostic ignored "-Wunused-const-variable" 161 static const GUID SDL_IID_IDXGIFactory2 = { 0x50c83a1c, 0xe072, 0x4c48, { 0x87, 0xb0, 0x36, 0x30, 0xfa, 0x36, 0xa6, 0xd0 } };
162 static const GUID SDL_IID_IDXGIDevice1 = { 0x77db970f, 0x6276, 0x48ba, { 0xba, 0x28, 0x07, 0x01, 0x43, 0xb4, 0x39, 0x2c } };
163 static const GUID SDL_IID_IDXGIDevice3 = { 0x6007896c, 0x3244, 0x4afd, { 0xbf, 0x18, 0xa6, 0xd3, 0xbe, 0xda, 0x50, 0x23 } };
164 static const GUID SDL_IID_ID3D11Texture2D = { 0x6f15aaf2, 0xd208, 0x4e89, { 0x9a, 0xb4, 0x48, 0x95, 0x35, 0xd3, 0x4f, 0x9c } };
165 static const GUID SDL_IID_ID3D11Device1 = { 0xa04bfb29, 0x08ef, 0x43d6, { 0xa4, 0x9c, 0xa9, 0xbd, 0xbd, 0xcb, 0xe6, 0x86 } };
166 static const GUID SDL_IID_ID3D11DeviceContext1 = { 0xbb2c6faa, 0xb5fb, 0x4082, { 0x8e, 0x6b, 0x38, 0x8b, 0x8c, 0xfa, 0x90, 0xe1 } };
167 static const GUID SDL_IID_ID3D11Debug = { 0x79cf2233, 0x7536, 0x4948, { 0x9d, 0x36, 0x1e, 0x46, 0x92, 0xdc, 0x57, 0x60 } };
170 #pragma GCC diagnostic pop 199 #if WINAPI_FAMILY == WINAPI_FAMILY_PHONE_APP 200 #define D3D11_USE_SHADER_MODEL_4_0_level_9_3 202 #define D3D11_USE_SHADER_MODEL_4_0_level_9_1 220 #if defined(D3D11_USE_SHADER_MODEL_4_0_level_9_1) 221 static const DWORD D3D11_PixelShader_Colors[] = {
222 0x43425844, 0xd74c28fe, 0xa1eb8804, 0x269d512a, 0x7699723d, 0x00000001,
223 0x00000240, 0x00000006, 0x00000038, 0x00000084, 0x000000c4, 0x00000140,
224 0x00000198, 0x0000020c, 0x396e6f41, 0x00000044, 0x00000044, 0xffff0200,
225 0x00000020, 0x00000024, 0x00240000, 0x00240000, 0x00240000, 0x00240000,
226 0x00240000, 0xffff0200, 0x0200001f, 0x80000000, 0xb00f0001, 0x02000001,
227 0x800f0800, 0xb0e40001, 0x0000ffff, 0x52444853, 0x00000038, 0x00000040,
228 0x0000000e, 0x03001062, 0x001010f2, 0x00000002, 0x03000065, 0x001020f2,
229 0x00000000, 0x05000036, 0x001020f2, 0x00000000, 0x00101e46, 0x00000002,
230 0x0100003e, 0x54415453, 0x00000074, 0x00000002, 0x00000000, 0x00000000,
231 0x00000002, 0x00000000, 0x00000000, 0x00000000, 0x00000001, 0x00000000,
232 0x00000000, 0x00000000, 0x00000000, 0x00000000, 0x00000000, 0x00000000,
233 0x00000000, 0x00000000, 0x00000000, 0x00000000, 0x00000002, 0x00000000,
234 0x00000000, 0x00000000, 0x00000000, 0x00000000, 0x00000000, 0x00000000,
235 0x00000000, 0x00000000, 0x46454452, 0x00000050, 0x00000000, 0x00000000,
236 0x00000000, 0x0000001c, 0xffff0400, 0x00000100, 0x0000001c, 0x7263694d,
237 0x666f736f, 0x52282074, 0x4c482029, 0x53204c53, 0x65646168, 0x6f432072,
238 0x6c69706d, 0x39207265, 0x2e30332e, 0x30303239, 0x3336312e, 0xab003438,
239 0x4e475349, 0x0000006c, 0x00000003, 0x00000008, 0x00000050, 0x00000000,
240 0x00000001, 0x00000003, 0x00000000, 0x0000000f, 0x0000005c, 0x00000000,
241 0x00000000, 0x00000003, 0x00000001, 0x00000003, 0x00000065, 0x00000000,
242 0x00000000, 0x00000003, 0x00000002, 0x00000f0f, 0x505f5653, 0x5449534f,
243 0x004e4f49, 0x43584554, 0x44524f4f, 0x4c4f4300, 0xab00524f, 0x4e47534f,
244 0x0000002c, 0x00000001, 0x00000008, 0x00000020, 0x00000000, 0x00000000,
245 0x00000003, 0x00000000, 0x0000000f, 0x545f5653, 0x45475241, 0xabab0054
247 #elif defined(D3D11_USE_SHADER_MODEL_4_0_level_9_3) 248 static const DWORD D3D11_PixelShader_Colors[] = {
249 0x43425844, 0x93f6ccfc, 0x5f919270, 0x7a11aa4f, 0x9148e931, 0x00000001,
250 0x00000240, 0x00000006, 0x00000038, 0x00000084, 0x000000c4, 0x00000140,
251 0x00000198, 0x0000020c, 0x396e6f41, 0x00000044, 0x00000044, 0xffff0200,
252 0x00000020, 0x00000024, 0x00240000, 0x00240000, 0x00240000, 0x00240000,
253 0x00240000, 0xffff0201, 0x0200001f, 0x80000000, 0xb00f0001, 0x02000001,
254 0x800f0800, 0xb0e40001, 0x0000ffff, 0x52444853, 0x00000038, 0x00000040,
255 0x0000000e, 0x03001062, 0x001010f2, 0x00000002, 0x03000065, 0x001020f2,
256 0x00000000, 0x05000036, 0x001020f2, 0x00000000, 0x00101e46, 0x00000002,
257 0x0100003e, 0x54415453, 0x00000074, 0x00000002, 0x00000000, 0x00000000,
258 0x00000002, 0x00000000, 0x00000000, 0x00000000, 0x00000001, 0x00000000,
259 0x00000000, 0x00000000, 0x00000000, 0x00000000, 0x00000000, 0x00000000,
260 0x00000000, 0x00000000, 0x00000000, 0x00000000, 0x00000002, 0x00000000,
261 0x00000000, 0x00000000, 0x00000000, 0x00000000, 0x00000000, 0x00000000,
262 0x00000000, 0x00000000, 0x46454452, 0x00000050, 0x00000000, 0x00000000,
263 0x00000000, 0x0000001c, 0xffff0400, 0x00000100, 0x0000001c, 0x7263694d,
264 0x666f736f, 0x52282074, 0x4c482029, 0x53204c53, 0x65646168, 0x6f432072,
265 0x6c69706d, 0x39207265, 0x2e30332e, 0x30303239, 0x3336312e, 0xab003438,
266 0x4e475349, 0x0000006c, 0x00000003, 0x00000008, 0x00000050, 0x00000000,
267 0x00000001, 0x00000003, 0x00000000, 0x0000000f, 0x0000005c, 0x00000000,
268 0x00000000, 0x00000003, 0x00000001, 0x00000003, 0x00000065, 0x00000000,
269 0x00000000, 0x00000003, 0x00000002, 0x00000f0f, 0x505f5653, 0x5449534f,
270 0x004e4f49, 0x43584554, 0x44524f4f, 0x4c4f4300, 0xab00524f, 0x4e47534f,
271 0x0000002c, 0x00000001, 0x00000008, 0x00000020, 0x00000000, 0x00000000,
272 0x00000003, 0x00000000, 0x0000000f, 0x545f5653, 0x45475241, 0xabab0054
275 #error "An appropriate 'colors' pixel shader is not defined." 296 #if defined(D3D11_USE_SHADER_MODEL_4_0_level_9_1) 297 static const DWORD D3D11_PixelShader_Textures[] = {
298 0x43425844, 0x6299b59f, 0x155258f2, 0x873ab86a, 0xfcbb6dcd, 0x00000001,
299 0x00000330, 0x00000006, 0x00000038, 0x000000c0, 0x0000015c, 0x000001d8,
300 0x00000288, 0x000002fc, 0x396e6f41, 0x00000080, 0x00000080, 0xffff0200,
301 0x00000058, 0x00000028, 0x00280000, 0x00280000, 0x00280000, 0x00240001,
302 0x00280000, 0x00000000, 0xffff0200, 0x0200001f, 0x80000000, 0xb0030000,
303 0x0200001f, 0x80000000, 0xb00f0001, 0x0200001f, 0x90000000, 0xa00f0800,
304 0x03000042, 0x800f0000, 0xb0e40000, 0xa0e40800, 0x03000005, 0x800f0000,
305 0x80e40000, 0xb0e40001, 0x02000001, 0x800f0800, 0x80e40000, 0x0000ffff,
306 0x52444853, 0x00000094, 0x00000040, 0x00000025, 0x0300005a, 0x00106000,
307 0x00000000, 0x04001858, 0x00107000, 0x00000000, 0x00005555, 0x03001062,
308 0x00101032, 0x00000001, 0x03001062, 0x001010f2, 0x00000002, 0x03000065,
309 0x001020f2, 0x00000000, 0x02000068, 0x00000001, 0x09000045, 0x001000f2,
310 0x00000000, 0x00101046, 0x00000001, 0x00107e46, 0x00000000, 0x00106000,
311 0x00000000, 0x07000038, 0x001020f2, 0x00000000, 0x00100e46, 0x00000000,
312 0x00101e46, 0x00000002, 0x0100003e, 0x54415453, 0x00000074, 0x00000003,
313 0x00000001, 0x00000000, 0x00000003, 0x00000001, 0x00000000, 0x00000000,
314 0x00000001, 0x00000000, 0x00000000, 0x00000000, 0x00000000, 0x00000000,
315 0x00000000, 0x00000001, 0x00000000, 0x00000000, 0x00000000, 0x00000000,
316 0x00000001, 0x00000000, 0x00000000, 0x00000000, 0x00000000, 0x00000000,
317 0x00000000, 0x00000000, 0x00000000, 0x00000000, 0x46454452, 0x000000a8,
318 0x00000000, 0x00000000, 0x00000002, 0x0000001c, 0xffff0400, 0x00000100,
319 0x00000072, 0x0000005c, 0x00000003, 0x00000000, 0x00000000, 0x00000000,
320 0x00000000, 0x00000001, 0x00000001, 0x00000067, 0x00000002, 0x00000005,
321 0x00000004, 0xffffffff, 0x00000000, 0x00000001, 0x0000000d, 0x53656874,
322 0x6c706d61, 0x74007265, 0x65546568, 0x72757478, 0x694d0065, 0x736f7263,
323 0x2074666f, 0x20295228, 0x4c534c48, 0x61685320, 0x20726564, 0x706d6f43,
324 0x72656c69, 0x332e3920, 0x32392e30, 0x312e3030, 0x34383336, 0xababab00,
325 0x4e475349, 0x0000006c, 0x00000003, 0x00000008, 0x00000050, 0x00000000,
326 0x00000001, 0x00000003, 0x00000000, 0x0000000f, 0x0000005c, 0x00000000,
327 0x00000000, 0x00000003, 0x00000001, 0x00000303, 0x00000065, 0x00000000,
328 0x00000000, 0x00000003, 0x00000002, 0x00000f0f, 0x505f5653, 0x5449534f,
329 0x004e4f49, 0x43584554, 0x44524f4f, 0x4c4f4300, 0xab00524f, 0x4e47534f,
330 0x0000002c, 0x00000001, 0x00000008, 0x00000020, 0x00000000, 0x00000000,
331 0x00000003, 0x00000000, 0x0000000f, 0x545f5653, 0x45475241, 0xabab0054
333 #elif defined(D3D11_USE_SHADER_MODEL_4_0_level_9_3) 334 static const DWORD D3D11_PixelShader_Textures[] = {
335 0x43425844, 0x5876569a, 0x01b6c87e, 0x8447454f, 0xc7f3ef10, 0x00000001,
336 0x00000330, 0x00000006, 0x00000038, 0x000000c0, 0x0000015c, 0x000001d8,
337 0x00000288, 0x000002fc, 0x396e6f41, 0x00000080, 0x00000080, 0xffff0200,
338 0x00000058, 0x00000028, 0x00280000, 0x00280000, 0x00280000, 0x00240001,
339 0x00280000, 0x00000000, 0xffff0201, 0x0200001f, 0x80000000, 0xb0030000,
340 0x0200001f, 0x80000000, 0xb00f0001, 0x0200001f, 0x90000000, 0xa00f0800,
341 0x03000042, 0x800f0000, 0xb0e40000, 0xa0e40800, 0x03000005, 0x800f0000,
342 0x80e40000, 0xb0e40001, 0x02000001, 0x800f0800, 0x80e40000, 0x0000ffff,
343 0x52444853, 0x00000094, 0x00000040, 0x00000025, 0x0300005a, 0x00106000,
344 0x00000000, 0x04001858, 0x00107000, 0x00000000, 0x00005555, 0x03001062,
345 0x00101032, 0x00000001, 0x03001062, 0x001010f2, 0x00000002, 0x03000065,
346 0x001020f2, 0x00000000, 0x02000068, 0x00000001, 0x09000045, 0x001000f2,
347 0x00000000, 0x00101046, 0x00000001, 0x00107e46, 0x00000000, 0x00106000,
348 0x00000000, 0x07000038, 0x001020f2, 0x00000000, 0x00100e46, 0x00000000,
349 0x00101e46, 0x00000002, 0x0100003e, 0x54415453, 0x00000074, 0x00000003,
350 0x00000001, 0x00000000, 0x00000003, 0x00000001, 0x00000000, 0x00000000,
351 0x00000001, 0x00000000, 0x00000000, 0x00000000, 0x00000000, 0x00000000,
352 0x00000000, 0x00000001, 0x00000000, 0x00000000, 0x00000000, 0x00000000,
353 0x00000001, 0x00000000, 0x00000000, 0x00000000, 0x00000000, 0x00000000,
354 0x00000000, 0x00000000, 0x00000000, 0x00000000, 0x46454452, 0x000000a8,
355 0x00000000, 0x00000000, 0x00000002, 0x0000001c, 0xffff0400, 0x00000100,
356 0x00000072, 0x0000005c, 0x00000003, 0x00000000, 0x00000000, 0x00000000,
357 0x00000000, 0x00000001, 0x00000001, 0x00000067, 0x00000002, 0x00000005,
358 0x00000004, 0xffffffff, 0x00000000, 0x00000001, 0x0000000d, 0x53656874,
359 0x6c706d61, 0x74007265, 0x65546568, 0x72757478, 0x694d0065, 0x736f7263,
360 0x2074666f, 0x20295228, 0x4c534c48, 0x61685320, 0x20726564, 0x706d6f43,
361 0x72656c69, 0x332e3920, 0x32392e30, 0x312e3030, 0x34383336, 0xababab00,
362 0x4e475349, 0x0000006c, 0x00000003, 0x00000008, 0x00000050, 0x00000000,
363 0x00000001, 0x00000003, 0x00000000, 0x0000000f, 0x0000005c, 0x00000000,
364 0x00000000, 0x00000003, 0x00000001, 0x00000303, 0x00000065, 0x00000000,
365 0x00000000, 0x00000003, 0x00000002, 0x00000f0f, 0x505f5653, 0x5449534f,
366 0x004e4f49, 0x43584554, 0x44524f4f, 0x4c4f4300, 0xab00524f, 0x4e47534f,
367 0x0000002c, 0x00000001, 0x00000008, 0x00000020, 0x00000000, 0x00000000,
368 0x00000003, 0x00000000, 0x0000000f, 0x545f5653, 0x45475241, 0xabab0054
371 #error "An appropriate 'textures' pixel shader is not defined" 413 #if defined(D3D11_USE_SHADER_MODEL_4_0_level_9_1) 414 static const DWORD D3D11_PixelShader_YUV[] = {
415 0x43425844, 0x2321c6c6, 0xf14df2d1, 0xc79d068d, 0x8e672abf, 0x00000001,
416 0x000005e8, 0x00000006, 0x00000038, 0x000001dc, 0x000003bc, 0x00000438,
417 0x00000540, 0x000005b4, 0x396e6f41, 0x0000019c, 0x0000019c, 0xffff0200,
418 0x0000016c, 0x00000030, 0x00300000, 0x00300000, 0x00300000, 0x00240003,
419 0x00300000, 0x00000000, 0x00010001, 0x00020002, 0xffff0200, 0x05000051,
420 0xa00f0000, 0xbd808081, 0xbf008081, 0xbf008081, 0x3f800000, 0x05000051,
421 0xa00f0001, 0x3f94fdf4, 0x3fcc49ba, 0x00000000, 0x00000000, 0x05000051,
422 0xa00f0002, 0x3f94fdf4, 0xbec83127, 0xbf5020c5, 0x00000000, 0x05000051,
423 0xa00f0003, 0x3f94fdf4, 0x400126e9, 0x00000000, 0x00000000, 0x0200001f,
424 0x80000000, 0xb0030000, 0x0200001f, 0x80000000, 0xb00f0001, 0x0200001f,
425 0x90000000, 0xa00f0800, 0x0200001f, 0x90000000, 0xa00f0801, 0x0200001f,
426 0x90000000, 0xa00f0802, 0x03000042, 0x800f0000, 0xb0e40000, 0xa0e40800,
427 0x03000042, 0x800f0001, 0xb0e40000, 0xa0e40801, 0x03000042, 0x800f0002,
428 0xb0e40000, 0xa0e40802, 0x02000001, 0x80020000, 0x80000001, 0x02000001,
429 0x80040000, 0x80000002, 0x03000002, 0x80070000, 0x80e40000, 0xa0e40000,
430 0x03000005, 0x80080000, 0x80000000, 0xa0000001, 0x04000004, 0x80010001,
431 0x80aa0000, 0xa0550001, 0x80ff0000, 0x03000008, 0x80020001, 0x80e40000,
432 0xa0e40002, 0x0400005a, 0x80040001, 0x80e40000, 0xa0e40003, 0xa0aa0003,
433 0x02000001, 0x80080001, 0xa0ff0000, 0x03000005, 0x800f0000, 0x80e40001,
434 0xb0e40001, 0x02000001, 0x800f0800, 0x80e40000, 0x0000ffff, 0x52444853,
435 0x000001d8, 0x00000040, 0x00000076, 0x0300005a, 0x00106000, 0x00000000,
436 0x04001858, 0x00107000, 0x00000000, 0x00005555, 0x04001858, 0x00107000,
437 0x00000001, 0x00005555, 0x04001858, 0x00107000, 0x00000002, 0x00005555,
438 0x03001062, 0x00101032, 0x00000001, 0x03001062, 0x001010f2, 0x00000002,
439 0x03000065, 0x001020f2, 0x00000000, 0x02000068, 0x00000002, 0x09000045,
440 0x001000f2, 0x00000000, 0x00101046, 0x00000001, 0x00107e46, 0x00000000,
441 0x00106000, 0x00000000, 0x09000045, 0x001000f2, 0x00000001, 0x00101046,
442 0x00000001, 0x00107e46, 0x00000001, 0x00106000, 0x00000000, 0x05000036,
443 0x00100022, 0x00000000, 0x0010000a, 0x00000001, 0x09000045, 0x001000f2,
444 0x00000001, 0x00101046, 0x00000001, 0x00107e46, 0x00000002, 0x00106000,
445 0x00000000, 0x05000036, 0x00100042, 0x00000000, 0x0010000a, 0x00000001,
446 0x0a000000, 0x00100072, 0x00000000, 0x00100246, 0x00000000, 0x00004002,
447 0xbd808081, 0xbf008081, 0xbf008081, 0x00000000, 0x0a00000f, 0x00100012,
448 0x00000001, 0x00100086, 0x00000000, 0x00004002, 0x3f94fdf4, 0x3fcc49ba,
449 0x00000000, 0x00000000, 0x0a000010, 0x00100022, 0x00000001, 0x00100246,
450 0x00000000, 0x00004002, 0x3f94fdf4, 0xbec83127, 0xbf5020c5, 0x00000000,
451 0x0a00000f, 0x00100042, 0x00000001, 0x00100046, 0x00000000, 0x00004002,
452 0x3f94fdf4, 0x400126e9, 0x00000000, 0x00000000, 0x05000036, 0x00100082,
453 0x00000001, 0x00004001, 0x3f800000, 0x07000038, 0x001020f2, 0x00000000,
454 0x00100e46, 0x00000001, 0x00101e46, 0x00000002, 0x0100003e, 0x54415453,
455 0x00000074, 0x0000000c, 0x00000002, 0x00000000, 0x00000003, 0x00000005,
456 0x00000000, 0x00000000, 0x00000001, 0x00000000, 0x00000000, 0x00000000,
457 0x00000000, 0x00000000, 0x00000000, 0x00000003, 0x00000000, 0x00000000,
458 0x00000000, 0x00000000, 0x00000003, 0x00000000, 0x00000000, 0x00000000,
459 0x00000000, 0x00000000, 0x00000000, 0x00000000, 0x00000000, 0x00000000,
460 0x46454452, 0x00000100, 0x00000000, 0x00000000, 0x00000004, 0x0000001c,
461 0xffff0400, 0x00000100, 0x000000cb, 0x0000009c, 0x00000003, 0x00000000,
462 0x00000000, 0x00000000, 0x00000000, 0x00000001, 0x00000001, 0x000000a7,
463 0x00000002, 0x00000005, 0x00000004, 0xffffffff, 0x00000000, 0x00000001,
464 0x0000000d, 0x000000b3, 0x00000002, 0x00000005, 0x00000004, 0xffffffff,
465 0x00000001, 0x00000001, 0x0000000d, 0x000000bf, 0x00000002, 0x00000005,
466 0x00000004, 0xffffffff, 0x00000002, 0x00000001, 0x0000000d, 0x53656874,
467 0x6c706d61, 0x74007265, 0x65546568, 0x72757478, 0x74005965, 0x65546568,
468 0x72757478, 0x74005565, 0x65546568, 0x72757478, 0x4d005665, 0x6f726369,
469 0x74666f73, 0x29522820, 0x534c4820, 0x6853204c, 0x72656461, 0x6d6f4320,
470 0x656c6970, 0x2e362072, 0x36392e33, 0x312e3030, 0x34383336, 0xababab00,
471 0x4e475349, 0x0000006c, 0x00000003, 0x00000008, 0x00000050, 0x00000000,
472 0x00000001, 0x00000003, 0x00000000, 0x0000000f, 0x0000005c, 0x00000000,
473 0x00000000, 0x00000003, 0x00000001, 0x00000303, 0x00000065, 0x00000000,
474 0x00000000, 0x00000003, 0x00000002, 0x00000f0f, 0x505f5653, 0x5449534f,
475 0x004e4f49, 0x43584554, 0x44524f4f, 0x4c4f4300, 0xab00524f, 0x4e47534f,
476 0x0000002c, 0x00000001, 0x00000008, 0x00000020, 0x00000000, 0x00000000,
477 0x00000003, 0x00000000, 0x0000000f, 0x545f5653, 0x45475241, 0xabab0054
479 #elif defined(D3D11_USE_SHADER_MODEL_4_0_level_9_3) 480 static const DWORD D3D11_PixelShader_YUV[] = {
481 0x43425844, 0x6ede7360, 0x45ff5f8a, 0x34ac92ba, 0xb865f5e0, 0x00000001,
482 0x000005c0, 0x00000006, 0x00000038, 0x000001b4, 0x00000394, 0x00000410,
483 0x00000518, 0x0000058c, 0x396e6f41, 0x00000174, 0x00000174, 0xffff0200,
484 0x00000144, 0x00000030, 0x00300000, 0x00300000, 0x00300000, 0x00240003,
485 0x00300000, 0x00000000, 0x00010001, 0x00020002, 0xffff0201, 0x05000051,
486 0xa00f0000, 0xbd808081, 0xbf008081, 0x3f800000, 0x00000000, 0x05000051,
487 0xa00f0001, 0x3f94fdf4, 0x3fcc49ba, 0x00000000, 0x400126e9, 0x05000051,
488 0xa00f0002, 0x3f94fdf4, 0xbec83127, 0xbf5020c5, 0x00000000, 0x0200001f,
489 0x80000000, 0xb0030000, 0x0200001f, 0x80000000, 0xb00f0001, 0x0200001f,
490 0x90000000, 0xa00f0800, 0x0200001f, 0x90000000, 0xa00f0801, 0x0200001f,
491 0x90000000, 0xa00f0802, 0x03000042, 0x800f0000, 0xb0e40000, 0xa0e40801,
492 0x03000042, 0x800f0001, 0xb0e40000, 0xa0e40800, 0x02000001, 0x80020001,
493 0x80000000, 0x03000042, 0x800f0000, 0xb0e40000, 0xa0e40802, 0x02000001,
494 0x80040001, 0x80000000, 0x03000002, 0x80070000, 0x80e40001, 0xa0d40000,
495 0x0400005a, 0x80010001, 0x80e80000, 0xa0e40001, 0xa0aa0001, 0x03000008,
496 0x80020001, 0x80e40000, 0xa0e40002, 0x0400005a, 0x80040001, 0x80e40000,
497 0xa0ec0001, 0xa0aa0001, 0x02000001, 0x80080001, 0xa0aa0000, 0x03000005,
498 0x800f0000, 0x80e40001, 0xb0e40001, 0x02000001, 0x800f0800, 0x80e40000,
499 0x0000ffff, 0x52444853, 0x000001d8, 0x00000040, 0x00000076, 0x0300005a,
500 0x00106000, 0x00000000, 0x04001858, 0x00107000, 0x00000000, 0x00005555,
501 0x04001858, 0x00107000, 0x00000001, 0x00005555, 0x04001858, 0x00107000,
502 0x00000002, 0x00005555, 0x03001062, 0x00101032, 0x00000001, 0x03001062,
503 0x001010f2, 0x00000002, 0x03000065, 0x001020f2, 0x00000000, 0x02000068,
504 0x00000002, 0x09000045, 0x001000f2, 0x00000000, 0x00101046, 0x00000001,
505 0x00107e46, 0x00000000, 0x00106000, 0x00000000, 0x09000045, 0x001000f2,
506 0x00000001, 0x00101046, 0x00000001, 0x00107e46, 0x00000001, 0x00106000,
507 0x00000000, 0x05000036, 0x00100022, 0x00000000, 0x0010000a, 0x00000001,
508 0x09000045, 0x001000f2, 0x00000001, 0x00101046, 0x00000001, 0x00107e46,
509 0x00000002, 0x00106000, 0x00000000, 0x05000036, 0x00100042, 0x00000000,
510 0x0010000a, 0x00000001, 0x0a000000, 0x00100072, 0x00000000, 0x00100246,
511 0x00000000, 0x00004002, 0xbd808081, 0xbf008081, 0xbf008081, 0x00000000,
512 0x0a00000f, 0x00100012, 0x00000001, 0x00100086, 0x00000000, 0x00004002,
513 0x3f94fdf4, 0x3fcc49ba, 0x00000000, 0x00000000, 0x0a000010, 0x00100022,
514 0x00000001, 0x00100246, 0x00000000, 0x00004002, 0x3f94fdf4, 0xbec83127,
515 0xbf5020c5, 0x00000000, 0x0a00000f, 0x00100042, 0x00000001, 0x00100046,
516 0x00000000, 0x00004002, 0x3f94fdf4, 0x400126e9, 0x00000000, 0x00000000,
517 0x05000036, 0x00100082, 0x00000001, 0x00004001, 0x3f800000, 0x07000038,
518 0x001020f2, 0x00000000, 0x00100e46, 0x00000001, 0x00101e46, 0x00000002,
519 0x0100003e, 0x54415453, 0x00000074, 0x0000000c, 0x00000002, 0x00000000,
520 0x00000003, 0x00000005, 0x00000000, 0x00000000, 0x00000001, 0x00000000,
521 0x00000000, 0x00000000, 0x00000000, 0x00000000, 0x00000000, 0x00000003,
522 0x00000000, 0x00000000, 0x00000000, 0x00000000, 0x00000003, 0x00000000,
523 0x00000000, 0x00000000, 0x00000000, 0x00000000, 0x00000000, 0x00000000,
524 0x00000000, 0x00000000, 0x46454452, 0x00000100, 0x00000000, 0x00000000,
525 0x00000004, 0x0000001c, 0xffff0400, 0x00000100, 0x000000cb, 0x0000009c,
526 0x00000003, 0x00000000, 0x00000000, 0x00000000, 0x00000000, 0x00000001,
527 0x00000001, 0x000000a7, 0x00000002, 0x00000005, 0x00000004, 0xffffffff,
528 0x00000000, 0x00000001, 0x0000000d, 0x000000b3, 0x00000002, 0x00000005,
529 0x00000004, 0xffffffff, 0x00000001, 0x00000001, 0x0000000d, 0x000000bf,
530 0x00000002, 0x00000005, 0x00000004, 0xffffffff, 0x00000002, 0x00000001,
531 0x0000000d, 0x53656874, 0x6c706d61, 0x74007265, 0x65546568, 0x72757478,
532 0x74005965, 0x65546568, 0x72757478, 0x74005565, 0x65546568, 0x72757478,
533 0x4d005665, 0x6f726369, 0x74666f73, 0x29522820, 0x534c4820, 0x6853204c,
534 0x72656461, 0x6d6f4320, 0x656c6970, 0x2e362072, 0x36392e33, 0x312e3030,
535 0x34383336, 0xababab00, 0x4e475349, 0x0000006c, 0x00000003, 0x00000008,
536 0x00000050, 0x00000000, 0x00000001, 0x00000003, 0x00000000, 0x0000000f,
537 0x0000005c, 0x00000000, 0x00000000, 0x00000003, 0x00000001, 0x00000303,
538 0x00000065, 0x00000000, 0x00000000, 0x00000003, 0x00000002, 0x00000f0f,
539 0x505f5653, 0x5449534f, 0x004e4f49, 0x43584554, 0x44524f4f, 0x4c4f4300,
540 0xab00524f, 0x4e47534f, 0x0000002c, 0x00000001, 0x00000008, 0x00000020,
541 0x00000000, 0x00000000, 0x00000003, 0x00000000, 0x0000000f, 0x545f5653,
542 0x45475241, 0xabab0054
545 #error "An appropriate 'yuv' pixel shader is not defined." 590 #if defined(D3D11_USE_SHADER_MODEL_4_0_level_9_1) 591 static const DWORD D3D11_VertexShader[] = {
592 0x43425844, 0x62dfae5f, 0x3e8bd8df, 0x9ec97127, 0x5044eefb, 0x00000001,
593 0x00000598, 0x00000006, 0x00000038, 0x0000016c, 0x00000334, 0x000003b0,
594 0x000004b4, 0x00000524, 0x396e6f41, 0x0000012c, 0x0000012c, 0xfffe0200,
595 0x000000f8, 0x00000034, 0x00240001, 0x00300000, 0x00300000, 0x00240000,
596 0x00300001, 0x00000000, 0x00010008, 0x00000000, 0x00000000, 0xfffe0200,
597 0x0200001f, 0x80000005, 0x900f0000, 0x0200001f, 0x80010005, 0x900f0001,
598 0x0200001f, 0x80020005, 0x900f0002, 0x03000005, 0x800f0000, 0x90550000,
599 0xa0e40002, 0x04000004, 0x800f0000, 0x90000000, 0xa0e40001, 0x80e40000,
600 0x04000004, 0x800f0000, 0x90aa0000, 0xa0e40003, 0x80e40000, 0x03000002,
601 0x800f0000, 0x80e40000, 0xa0e40004, 0x03000005, 0x800f0001, 0x80550000,
602 0xa0e40006, 0x04000004, 0x800f0001, 0x80000000, 0xa0e40005, 0x80e40001,
603 0x04000004, 0x800f0001, 0x80aa0000, 0xa0e40007, 0x80e40001, 0x04000004,
604 0x800f0000, 0x80ff0000, 0xa0e40008, 0x80e40001, 0x04000004, 0xc0030000,
605 0x80ff0000, 0xa0e40000, 0x80e40000, 0x02000001, 0xc00c0000, 0x80e40000,
606 0x02000001, 0xe0030000, 0x90e40001, 0x02000001, 0xe00f0001, 0x90e40002,
607 0x0000ffff, 0x52444853, 0x000001c0, 0x00010040, 0x00000070, 0x04000059,
608 0x00208e46, 0x00000000, 0x00000008, 0x0300005f, 0x00101072, 0x00000000,
609 0x0300005f, 0x00101032, 0x00000001, 0x0300005f, 0x001010f2, 0x00000002,
610 0x04000067, 0x001020f2, 0x00000000, 0x00000001, 0x03000065, 0x00102032,
611 0x00000001, 0x03000065, 0x001020f2, 0x00000002, 0x02000068, 0x00000002,
612 0x08000038, 0x001000f2, 0x00000000, 0x00101556, 0x00000000, 0x00208e46,
613 0x00000000, 0x00000001, 0x0a000032, 0x001000f2, 0x00000000, 0x00101006,
614 0x00000000, 0x00208e46, 0x00000000, 0x00000000, 0x00100e46, 0x00000000,
615 0x0a000032, 0x001000f2, 0x00000000, 0x00101aa6, 0x00000000, 0x00208e46,
616 0x00000000, 0x00000002, 0x00100e46, 0x00000000, 0x08000000, 0x001000f2,
617 0x00000000, 0x00100e46, 0x00000000, 0x00208e46, 0x00000000, 0x00000003,
618 0x08000038, 0x001000f2, 0x00000001, 0x00100556, 0x00000000, 0x00208e46,
619 0x00000000, 0x00000005, 0x0a000032, 0x001000f2, 0x00000001, 0x00100006,
620 0x00000000, 0x00208e46, 0x00000000, 0x00000004, 0x00100e46, 0x00000001,
621 0x0a000032, 0x001000f2, 0x00000001, 0x00100aa6, 0x00000000, 0x00208e46,
622 0x00000000, 0x00000006, 0x00100e46, 0x00000001, 0x0a000032, 0x001020f2,
623 0x00000000, 0x00100ff6, 0x00000000, 0x00208e46, 0x00000000, 0x00000007,
624 0x00100e46, 0x00000001, 0x05000036, 0x00102032, 0x00000001, 0x00101046,
625 0x00000001, 0x05000036, 0x001020f2, 0x00000002, 0x00101e46, 0x00000002,
626 0x0100003e, 0x54415453, 0x00000074, 0x0000000b, 0x00000002, 0x00000000,
627 0x00000006, 0x00000003, 0x00000000, 0x00000000, 0x00000001, 0x00000000,
628 0x00000000, 0x00000000, 0x00000000, 0x00000000, 0x00000000, 0x00000000,
629 0x00000000, 0x00000000, 0x00000000, 0x00000000, 0x00000003, 0x00000000,
630 0x00000000, 0x00000000, 0x00000000, 0x00000000, 0x00000000, 0x00000000,
631 0x00000000, 0x00000000, 0x46454452, 0x000000fc, 0x00000001, 0x00000054,
632 0x00000001, 0x0000001c, 0xfffe0400, 0x00000100, 0x000000c6, 0x0000003c,
633 0x00000000, 0x00000000, 0x00000000, 0x00000000, 0x00000000, 0x00000001,
634 0x00000001, 0x74726556, 0x68537865, 0x72656461, 0x736e6f43, 0x746e6174,
635 0xabab0073, 0x0000003c, 0x00000002, 0x0000006c, 0x00000080, 0x00000000,
636 0x00000000, 0x0000009c, 0x00000000, 0x00000040, 0x00000002, 0x000000a4,
637 0x00000000, 0x000000b4, 0x00000040, 0x00000040, 0x00000002, 0x000000a4,
638 0x00000000, 0x65646f6d, 0xabab006c, 0x00030002, 0x00040004, 0x00000000,
639 0x00000000, 0x6a6f7270, 0x69746365, 0x6e416e6f, 0x65695664, 0x694d0077,
640 0x736f7263, 0x2074666f, 0x20295228, 0x4c534c48, 0x61685320, 0x20726564,
641 0x706d6f43, 0x72656c69, 0x332e3920, 0x32392e30, 0x312e3030, 0x34383336,
642 0xababab00, 0x4e475349, 0x00000068, 0x00000003, 0x00000008, 0x00000050,
643 0x00000000, 0x00000000, 0x00000003, 0x00000000, 0x00000707, 0x00000059,
644 0x00000000, 0x00000000, 0x00000003, 0x00000001, 0x00000303, 0x00000062,
645 0x00000000, 0x00000000, 0x00000003, 0x00000002, 0x00000f0f, 0x49534f50,
646 0x4e4f4954, 0x58455400, 0x524f4f43, 0x4f430044, 0x00524f4c, 0x4e47534f,
647 0x0000006c, 0x00000003, 0x00000008, 0x00000050, 0x00000000, 0x00000001,
648 0x00000003, 0x00000000, 0x0000000f, 0x0000005c, 0x00000000, 0x00000000,
649 0x00000003, 0x00000001, 0x00000c03, 0x00000065, 0x00000000, 0x00000000,
650 0x00000003, 0x00000002, 0x0000000f, 0x505f5653, 0x5449534f, 0x004e4f49,
651 0x43584554, 0x44524f4f, 0x4c4f4300, 0xab00524f
653 #elif defined(D3D11_USE_SHADER_MODEL_4_0_level_9_3) 654 static const DWORD D3D11_VertexShader[] = {
655 0x43425844, 0x01a24e41, 0x696af551, 0x4b2a87d1, 0x82ea03f6, 0x00000001,
656 0x00000598, 0x00000006, 0x00000038, 0x0000016c, 0x00000334, 0x000003b0,
657 0x000004b4, 0x00000524, 0x396e6f41, 0x0000012c, 0x0000012c, 0xfffe0200,
658 0x000000f8, 0x00000034, 0x00240001, 0x00300000, 0x00300000, 0x00240000,
659 0x00300001, 0x00000000, 0x00010008, 0x00000000, 0x00000000, 0xfffe0201,
660 0x0200001f, 0x80000005, 0x900f0000, 0x0200001f, 0x80010005, 0x900f0001,
661 0x0200001f, 0x80020005, 0x900f0002, 0x03000005, 0x800f0000, 0x90550000,
662 0xa0e40002, 0x04000004, 0x800f0000, 0x90000000, 0xa0e40001, 0x80e40000,
663 0x04000004, 0x800f0000, 0x90aa0000, 0xa0e40003, 0x80e40000, 0x03000002,
664 0x800f0000, 0x80e40000, 0xa0e40004, 0x03000005, 0x800f0001, 0x80550000,
665 0xa0e40006, 0x04000004, 0x800f0001, 0x80000000, 0xa0e40005, 0x80e40001,
666 0x04000004, 0x800f0001, 0x80aa0000, 0xa0e40007, 0x80e40001, 0x04000004,
667 0x800f0000, 0x80ff0000, 0xa0e40008, 0x80e40001, 0x04000004, 0xc0030000,
668 0x80ff0000, 0xa0e40000, 0x80e40000, 0x02000001, 0xc00c0000, 0x80e40000,
669 0x02000001, 0xe0030000, 0x90e40001, 0x02000001, 0xe00f0001, 0x90e40002,
670 0x0000ffff, 0x52444853, 0x000001c0, 0x00010040, 0x00000070, 0x04000059,
671 0x00208e46, 0x00000000, 0x00000008, 0x0300005f, 0x00101072, 0x00000000,
672 0x0300005f, 0x00101032, 0x00000001, 0x0300005f, 0x001010f2, 0x00000002,
673 0x04000067, 0x001020f2, 0x00000000, 0x00000001, 0x03000065, 0x00102032,
674 0x00000001, 0x03000065, 0x001020f2, 0x00000002, 0x02000068, 0x00000002,
675 0x08000038, 0x001000f2, 0x00000000, 0x00101556, 0x00000000, 0x00208e46,
676 0x00000000, 0x00000001, 0x0a000032, 0x001000f2, 0x00000000, 0x00101006,
677 0x00000000, 0x00208e46, 0x00000000, 0x00000000, 0x00100e46, 0x00000000,
678 0x0a000032, 0x001000f2, 0x00000000, 0x00101aa6, 0x00000000, 0x00208e46,
679 0x00000000, 0x00000002, 0x00100e46, 0x00000000, 0x08000000, 0x001000f2,
680 0x00000000, 0x00100e46, 0x00000000, 0x00208e46, 0x00000000, 0x00000003,
681 0x08000038, 0x001000f2, 0x00000001, 0x00100556, 0x00000000, 0x00208e46,
682 0x00000000, 0x00000005, 0x0a000032, 0x001000f2, 0x00000001, 0x00100006,
683 0x00000000, 0x00208e46, 0x00000000, 0x00000004, 0x00100e46, 0x00000001,
684 0x0a000032, 0x001000f2, 0x00000001, 0x00100aa6, 0x00000000, 0x00208e46,
685 0x00000000, 0x00000006, 0x00100e46, 0x00000001, 0x0a000032, 0x001020f2,
686 0x00000000, 0x00100ff6, 0x00000000, 0x00208e46, 0x00000000, 0x00000007,
687 0x00100e46, 0x00000001, 0x05000036, 0x00102032, 0x00000001, 0x00101046,
688 0x00000001, 0x05000036, 0x001020f2, 0x00000002, 0x00101e46, 0x00000002,
689 0x0100003e, 0x54415453, 0x00000074, 0x0000000b, 0x00000002, 0x00000000,
690 0x00000006, 0x00000003, 0x00000000, 0x00000000, 0x00000001, 0x00000000,
691 0x00000000, 0x00000000, 0x00000000, 0x00000000, 0x00000000, 0x00000000,
692 0x00000000, 0x00000000, 0x00000000, 0x00000000, 0x00000003, 0x00000000,
693 0x00000000, 0x00000000, 0x00000000, 0x00000000, 0x00000000, 0x00000000,
694 0x00000000, 0x00000000, 0x46454452, 0x000000fc, 0x00000001, 0x00000054,
695 0x00000001, 0x0000001c, 0xfffe0400, 0x00000100, 0x000000c6, 0x0000003c,
696 0x00000000, 0x00000000, 0x00000000, 0x00000000, 0x00000000, 0x00000001,
697 0x00000001, 0x74726556, 0x68537865, 0x72656461, 0x736e6f43, 0x746e6174,
698 0xabab0073, 0x0000003c, 0x00000002, 0x0000006c, 0x00000080, 0x00000000,
699 0x00000000, 0x0000009c, 0x00000000, 0x00000040, 0x00000002, 0x000000a4,
700 0x00000000, 0x000000b4, 0x00000040, 0x00000040, 0x00000002, 0x000000a4,
701 0x00000000, 0x65646f6d, 0xabab006c, 0x00030002, 0x00040004, 0x00000000,
702 0x00000000, 0x6a6f7270, 0x69746365, 0x6e416e6f, 0x65695664, 0x694d0077,
703 0x736f7263, 0x2074666f, 0x20295228, 0x4c534c48, 0x61685320, 0x20726564,
704 0x706d6f43, 0x72656c69, 0x332e3920, 0x32392e30, 0x312e3030, 0x34383336,
705 0xababab00, 0x4e475349, 0x00000068, 0x00000003, 0x00000008, 0x00000050,
706 0x00000000, 0x00000000, 0x00000003, 0x00000000, 0x00000707, 0x00000059,
707 0x00000000, 0x00000000, 0x00000003, 0x00000001, 0x00000303, 0x00000062,
708 0x00000000, 0x00000000, 0x00000003, 0x00000002, 0x00000f0f, 0x49534f50,
709 0x4e4f4954, 0x58455400, 0x524f4f43, 0x4f430044, 0x00524f4c, 0x4e47534f,
710 0x0000006c, 0x00000003, 0x00000008, 0x00000050, 0x00000000, 0x00000001,
711 0x00000003, 0x00000000, 0x0000000f, 0x0000005c, 0x00000000, 0x00000000,
712 0x00000003, 0x00000001, 0x00000c03, 0x00000065, 0x00000000, 0x00000000,
713 0x00000003, 0x00000002, 0x0000000f, 0x505f5653, 0x5449534f, 0x004e4f49,
714 0x43584554, 0x44524f4f, 0x4c4f4300, 0xab00524f
717 #error "An appropriate vertex shader is not defined." 732 const Uint8 *Yplane,
int Ypitch,
733 const Uint8 *Uplane,
int Upitch,
734 const Uint8 *Vplane,
int Vpitch);
768 D3D11_CreateRenderer,
790 D3D11_DXGIFormatToSDLPixelFormat(DXGI_FORMAT dxgiFormat) {
791 switch (dxgiFormat) {
792 case DXGI_FORMAT_B8G8R8A8_UNORM:
794 case DXGI_FORMAT_B8G8R8X8_UNORM:
802 SDLPixelFormatToDXGIFormat(
Uint32 sdlFormat)
806 return DXGI_FORMAT_B8G8R8A8_UNORM;
808 return DXGI_FORMAT_B8G8R8X8_UNORM;
811 return DXGI_FORMAT_R8_UNORM;
813 return DXGI_FORMAT_UNKNOWN;
821 D3D11_RenderData *
data;
829 data = (D3D11_RenderData *)
SDL_calloc(1,
sizeof(*data));
855 renderer->
info = D3D11_RenderDriver.
info;
859 #if WINAPI_FAMILY == WINAPI_FAMILY_PHONE_APP 884 if (
FAILED(D3D11_CreateDeviceResources(renderer))) {
885 D3D11_DestroyRenderer(renderer);
888 if (
FAILED(D3D11_CreateWindowSizeDependentResources(renderer))) {
889 D3D11_DestroyRenderer(renderer);
899 D3D11_RenderData *data = (D3D11_RenderData *) renderer->
driverdata;
904 D3D11_DestroyTexture(renderer,
texture);
911 SAFE_RELEASE(data->dxgiFactory);
912 SAFE_RELEASE(data->dxgiAdapter);
913 SAFE_RELEASE(data->d3dDevice);
914 SAFE_RELEASE(data->d3dContext);
915 SAFE_RELEASE(data->swapChain);
916 SAFE_RELEASE(data->mainRenderTargetView);
917 SAFE_RELEASE(data->currentOffscreenRenderTargetView);
918 SAFE_RELEASE(data->inputLayout);
919 SAFE_RELEASE(data->vertexBuffer);
920 SAFE_RELEASE(data->vertexShader);
921 SAFE_RELEASE(data->colorPixelShader);
922 SAFE_RELEASE(data->texturePixelShader);
923 SAFE_RELEASE(data->yuvPixelShader);
924 if (data->blendModesCount > 0) {
925 for (i = 0; i < data->blendModesCount; ++
i) {
926 SAFE_RELEASE(data->blendModes[i].blendState);
930 data->blendModesCount = 0;
932 SAFE_RELEASE(data->nearestPixelSampler);
933 SAFE_RELEASE(data->linearSampler);
934 SAFE_RELEASE(data->mainRasterizer);
935 SAFE_RELEASE(data->clippedRasterizer);
936 SAFE_RELEASE(data->vertexShaderConstants);
938 data->swapEffect = (DXGI_SWAP_EFFECT) 0;
939 data->rotation = DXGI_MODE_ROTATION_UNSPECIFIED;
940 data->currentRenderTargetView =
NULL;
941 data->currentRasterizerState =
NULL;
942 data->currentBlendState =
NULL;
943 data->currentShader =
NULL;
944 data->currentShaderResource =
NULL;
945 data->currentSampler =
NULL;
950 if (data->hD3D11Mod) {
952 data->hD3D11Mod =
NULL;
954 if (data->hDXGIMod) {
956 data->hDXGIMod =
NULL;
964 D3D11_RenderData *data = (D3D11_RenderData *) renderer->
driverdata;
965 D3D11_ReleaseAll(renderer);
976 return D3D11_BLEND_ZERO;
978 return D3D11_BLEND_ONE;
980 return D3D11_BLEND_SRC_COLOR;
982 return D3D11_BLEND_INV_SRC_COLOR;
984 return D3D11_BLEND_SRC_ALPHA;
986 return D3D11_BLEND_INV_SRC_ALPHA;
988 return D3D11_BLEND_DEST_COLOR;
990 return D3D11_BLEND_INV_DEST_COLOR;
992 return D3D11_BLEND_DEST_ALPHA;
994 return D3D11_BLEND_INV_DEST_ALPHA;
996 return (D3D11_BLEND)0;
1002 switch (operation) {
1004 return D3D11_BLEND_OP_ADD;
1006 return D3D11_BLEND_OP_SUBTRACT;
1008 return D3D11_BLEND_OP_REV_SUBTRACT;
1010 return D3D11_BLEND_OP_MIN;
1012 return D3D11_BLEND_OP_MAX;
1014 return (D3D11_BLEND_OP)0;
1021 D3D11_RenderData *data = (D3D11_RenderData *) renderer->
driverdata;
1028 ID3D11BlendState *blendState =
NULL;
1029 D3D11_BlendMode *blendModes;
1032 D3D11_BLEND_DESC blendDesc;
1034 blendDesc.AlphaToCoverageEnable =
FALSE;
1035 blendDesc.IndependentBlendEnable =
FALSE;
1036 blendDesc.RenderTarget[0].BlendEnable =
TRUE;
1037 blendDesc.RenderTarget[0].SrcBlend = GetBlendFunc(srcColorFactor);
1038 blendDesc.RenderTarget[0].DestBlend = GetBlendFunc(dstColorFactor);
1039 blendDesc.RenderTarget[0].BlendOp = GetBlendEquation(colorOperation);
1040 blendDesc.RenderTarget[0].SrcBlendAlpha = GetBlendFunc(srcAlphaFactor);
1041 blendDesc.RenderTarget[0].DestBlendAlpha = GetBlendFunc(dstAlphaFactor);
1042 blendDesc.RenderTarget[0].BlendOpAlpha = GetBlendEquation(alphaOperation);
1043 blendDesc.RenderTarget[0].RenderTargetWriteMask = D3D11_COLOR_WRITE_ENABLE_ALL;
1044 result = ID3D11Device_CreateBlendState(data->d3dDevice, &blendDesc, &blendState);
1050 blendModes = (D3D11_BlendMode *)
SDL_realloc(data->blendModes, (data->blendModesCount + 1) *
sizeof(*blendModes));
1052 SAFE_RELEASE(blendState);
1056 blendModes[data->blendModesCount].blendMode =
blendMode;
1057 blendModes[data->blendModesCount].blendState = blendState;
1058 data->blendModes = blendModes;
1059 ++data->blendModesCount;
1068 typedef HRESULT(WINAPI *PFN_CREATE_DXGI_FACTORY)(REFIID riid,
void **ppFactory);
1069 PFN_CREATE_DXGI_FACTORY CreateDXGIFactoryFunc;
1070 D3D11_RenderData *data = (D3D11_RenderData *) renderer->
driverdata;
1071 PFN_D3D11_CREATE_DEVICE D3D11CreateDeviceFunc;
1072 ID3D11Device *d3dDevice =
NULL;
1073 ID3D11DeviceContext *d3dContext =
NULL;
1074 IDXGIDevice1 *dxgiDevice =
NULL;
1075 HRESULT result =
S_OK;
1083 D3D_FEATURE_LEVEL featureLevels[] =
1085 D3D_FEATURE_LEVEL_11_1,
1086 D3D_FEATURE_LEVEL_11_0,
1087 D3D_FEATURE_LEVEL_10_1,
1088 D3D_FEATURE_LEVEL_10_0,
1089 D3D_FEATURE_LEVEL_9_3,
1090 D3D_FEATURE_LEVEL_9_2,
1091 D3D_FEATURE_LEVEL_9_1
1095 const D3D11_INPUT_ELEMENT_DESC vertexDesc[] =
1097 {
"POSITION", 0, DXGI_FORMAT_R32G32B32_FLOAT, 0, 0, D3D11_INPUT_PER_VERTEX_DATA, 0 },
1098 {
"TEXCOORD", 0, DXGI_FORMAT_R32G32_FLOAT, 0, 12, D3D11_INPUT_PER_VERTEX_DATA, 0 },
1099 {
"COLOR", 0, DXGI_FORMAT_R32G32B32A32_FLOAT, 0, 20, D3D11_INPUT_PER_VERTEX_DATA, 0 },
1102 D3D11_BUFFER_DESC constantBufferDesc;
1103 D3D11_SAMPLER_DESC samplerDesc;
1104 D3D11_RASTERIZER_DESC rasterDesc;
1107 CreateDXGIFactoryFunc = CreateDXGIFactory1;
1108 D3D11CreateDeviceFunc = D3D11CreateDevice;
1111 if (!data->hDXGIMod) {
1116 CreateDXGIFactoryFunc = (PFN_CREATE_DXGI_FACTORY)
SDL_LoadFunction(data->hDXGIMod,
"CreateDXGIFactory");
1117 if (!CreateDXGIFactoryFunc) {
1123 if (!data->hD3D11Mod) {
1128 D3D11CreateDeviceFunc = (PFN_D3D11_CREATE_DEVICE)
SDL_LoadFunction(data->hD3D11Mod,
"D3D11CreateDevice");
1129 if (!D3D11CreateDeviceFunc) {
1135 result = CreateDXGIFactoryFunc(&SDL_IID_IDXGIFactory2, (
void **)&data->dxgiFactory);
1142 result = IDXGIFactory2_EnumAdapters(data->dxgiFactory, 0, &data->dxgiAdapter);
1151 creationFlags = D3D11_CREATE_DEVICE_BGRA_SUPPORT;
1155 creationFlags |= D3D11_CREATE_DEVICE_DEBUG;
1159 result = D3D11CreateDeviceFunc(
1161 D3D_DRIVER_TYPE_UNKNOWN,
1168 &data->featureLevel,
1176 result = ID3D11Device_QueryInterface(d3dDevice, &SDL_IID_ID3D11Device1, (
void **)&data->d3dDevice);
1182 result = ID3D11DeviceContext_QueryInterface(d3dContext, &SDL_IID_ID3D11DeviceContext1, (
void **)&data->d3dContext);
1188 result = ID3D11Device_QueryInterface(d3dDevice, &SDL_IID_IDXGIDevice1, (
void **)&dxgiDevice);
1197 result = IDXGIDevice1_SetMaximumFrameLatency(dxgiDevice, 1);
1207 switch (data->featureLevel) {
1208 case D3D_FEATURE_LEVEL_11_1:
1209 case D3D_FEATURE_LEVEL_11_0:
1213 case D3D_FEATURE_LEVEL_10_1:
1214 case D3D_FEATURE_LEVEL_10_0:
1218 case D3D_FEATURE_LEVEL_9_3:
1222 case D3D_FEATURE_LEVEL_9_2:
1223 case D3D_FEATURE_LEVEL_9_1:
1228 SDL_SetError(
"%s, Unexpected feature level: %d", __FUNCTION__, data->featureLevel);
1234 result = ID3D11Device_CreateVertexShader(data->d3dDevice,
1236 sizeof(D3D11_VertexShader),
1246 result = ID3D11Device_CreateInputLayout(data->d3dDevice,
1248 ARRAYSIZE(vertexDesc),
1250 sizeof(D3D11_VertexShader),
1259 result = ID3D11Device_CreatePixelShader(data->d3dDevice,
1260 D3D11_PixelShader_Colors,
1261 sizeof(D3D11_PixelShader_Colors),
1263 &data->colorPixelShader
1270 result = ID3D11Device_CreatePixelShader(data->d3dDevice,
1271 D3D11_PixelShader_Textures,
1272 sizeof(D3D11_PixelShader_Textures),
1274 &data->texturePixelShader
1281 result = ID3D11Device_CreatePixelShader(data->d3dDevice,
1282 D3D11_PixelShader_YUV,
1283 sizeof(D3D11_PixelShader_YUV),
1285 &data->yuvPixelShader
1294 constantBufferDesc.ByteWidth =
sizeof(VertexShaderConstants);
1295 constantBufferDesc.Usage = D3D11_USAGE_DEFAULT;
1296 constantBufferDesc.BindFlags = D3D11_BIND_CONSTANT_BUFFER;
1297 result = ID3D11Device_CreateBuffer(data->d3dDevice,
1298 &constantBufferDesc,
1300 &data->vertexShaderConstants
1309 samplerDesc.Filter = D3D11_FILTER_MIN_MAG_MIP_POINT;
1310 samplerDesc.AddressU = D3D11_TEXTURE_ADDRESS_CLAMP;
1311 samplerDesc.AddressV = D3D11_TEXTURE_ADDRESS_CLAMP;
1312 samplerDesc.AddressW = D3D11_TEXTURE_ADDRESS_CLAMP;
1313 samplerDesc.MipLODBias = 0.0f;
1314 samplerDesc.MaxAnisotropy = 1;
1315 samplerDesc.ComparisonFunc = D3D11_COMPARISON_ALWAYS;
1316 samplerDesc.MinLOD = 0.0f;
1317 samplerDesc.MaxLOD = D3D11_FLOAT32_MAX;
1318 result = ID3D11Device_CreateSamplerState(data->d3dDevice,
1320 &data->nearestPixelSampler
1323 WIN_SetErrorFromHRESULT(SDL_COMPOSE_ERROR(
"ID3D11Device1::CreateSamplerState [nearest-pixel filter]"), result);
1327 samplerDesc.Filter = D3D11_FILTER_MIN_MAG_MIP_LINEAR;
1328 result = ID3D11Device_CreateSamplerState(data->d3dDevice,
1330 &data->linearSampler
1339 rasterDesc.AntialiasedLineEnable =
FALSE;
1340 rasterDesc.CullMode = D3D11_CULL_NONE;
1341 rasterDesc.DepthBias = 0;
1342 rasterDesc.DepthBiasClamp = 0.0f;
1343 rasterDesc.DepthClipEnable =
TRUE;
1344 rasterDesc.FillMode = D3D11_FILL_SOLID;
1345 rasterDesc.FrontCounterClockwise =
FALSE;
1346 rasterDesc.MultisampleEnable =
FALSE;
1347 rasterDesc.ScissorEnable =
FALSE;
1348 rasterDesc.SlopeScaledDepthBias = 0.0f;
1349 result = ID3D11Device_CreateRasterizerState(data->d3dDevice, &rasterDesc, &data->mainRasterizer);
1355 rasterDesc.ScissorEnable =
TRUE;
1356 result = ID3D11Device_CreateRasterizerState(data->d3dDevice, &rasterDesc, &data->clippedRasterizer);
1358 WIN_SetErrorFromHRESULT(SDL_COMPOSE_ERROR(
"ID3D11Device1::CreateRasterizerState [clipped rasterizer]"), result);
1371 ID3D11DeviceContext_IASetInputLayout(data->d3dContext, data->inputLayout);
1372 ID3D11DeviceContext_VSSetShader(data->d3dContext, data->vertexShader,
NULL, 0);
1373 ID3D11DeviceContext_VSSetConstantBuffers(data->d3dContext, 0, 1, &data->vertexShaderConstants);
1376 SAFE_RELEASE(d3dDevice);
1377 SAFE_RELEASE(d3dContext);
1378 SAFE_RELEASE(dxgiDevice);
1384 static DXGI_MODE_ROTATION
1385 D3D11_GetCurrentRotation()
1388 return DXGI_MODE_ROTATION_IDENTITY;
1394 D3D11_IsDisplayRotated90Degrees(DXGI_MODE_ROTATION rotation)
1397 case DXGI_MODE_ROTATION_ROTATE90:
1398 case DXGI_MODE_ROTATION_ROTATE270:
1406 D3D11_GetRotationForCurrentRenderTarget(
SDL_Renderer * renderer)
1408 D3D11_RenderData *data = (D3D11_RenderData *)renderer->
driverdata;
1409 if (data->currentOffscreenRenderTargetView) {
1410 return DXGI_MODE_ROTATION_IDENTITY;
1412 return data->rotation;
1417 D3D11_GetViewportAlignedD3DRect(
SDL_Renderer * renderer,
const SDL_Rect * sdlRect, D3D11_RECT * outRect, BOOL includeViewportOffset)
1419 const int rotation = D3D11_GetRotationForCurrentRenderTarget(renderer);
1421 case DXGI_MODE_ROTATION_IDENTITY:
1422 outRect->left = sdlRect->
x;
1423 outRect->right = sdlRect->
x + sdlRect->
w;
1424 outRect->top = sdlRect->
y;
1425 outRect->bottom = sdlRect->
y + sdlRect->
h;
1426 if (includeViewportOffset) {
1430 outRect->bottom += renderer->
viewport.
y;
1433 case DXGI_MODE_ROTATION_ROTATE270:
1434 outRect->left = sdlRect->
y;
1435 outRect->right = sdlRect->
y + sdlRect->
h;
1436 outRect->top = renderer->
viewport.
w - sdlRect->
x - sdlRect->
w;
1437 outRect->bottom = renderer->
viewport.
w - sdlRect->
x;
1439 case DXGI_MODE_ROTATION_ROTATE180:
1440 outRect->left = renderer->
viewport.
w - sdlRect->
x - sdlRect->
w;
1441 outRect->right = renderer->
viewport.
w - sdlRect->
x;
1442 outRect->top = renderer->
viewport.
h - sdlRect->
y - sdlRect->
h;
1443 outRect->bottom = renderer->
viewport.
h - sdlRect->
y;
1445 case DXGI_MODE_ROTATION_ROTATE90:
1446 outRect->left = renderer->
viewport.
h - sdlRect->
y - sdlRect->
h;
1447 outRect->right = renderer->
viewport.
h - sdlRect->
y;
1448 outRect->top = sdlRect->
x;
1449 outRect->bottom = sdlRect->
x + sdlRect->
h;
1452 return SDL_SetError(
"The physical display is in an unknown or unsupported rotation");
1460 D3D11_RenderData *data = (D3D11_RenderData *)renderer->
driverdata;
1462 IUnknown *coreWindow = D3D11_GetCoreWindowFromSDLRenderer(renderer);
1463 const BOOL usingXAML = (coreWindow ==
NULL);
1465 IUnknown *coreWindow =
NULL;
1466 const BOOL usingXAML =
FALSE;
1468 HRESULT result =
S_OK;
1471 DXGI_SWAP_CHAIN_DESC1 swapChainDesc;
1473 swapChainDesc.Width =
w;
1474 swapChainDesc.Height =
h;
1475 swapChainDesc.Format = DXGI_FORMAT_B8G8R8A8_UNORM;
1476 swapChainDesc.Stereo =
FALSE;
1477 swapChainDesc.SampleDesc.Count = 1;
1478 swapChainDesc.SampleDesc.Quality = 0;
1479 swapChainDesc.BufferUsage = DXGI_USAGE_RENDER_TARGET_OUTPUT;
1480 swapChainDesc.BufferCount = 2;
1481 #if WINAPI_FAMILY == WINAPI_FAMILY_PHONE_APP 1482 swapChainDesc.Scaling = DXGI_SCALING_STRETCH;
1483 swapChainDesc.SwapEffect = DXGI_SWAP_EFFECT_DISCARD;
1487 swapChainDesc.Scaling = DXGI_SCALING_STRETCH;
1489 swapChainDesc.Scaling = DXGI_SCALING_NONE;
1491 swapChainDesc.SwapEffect = DXGI_SWAP_EFFECT_FLIP_SEQUENTIAL;
1493 swapChainDesc.Flags = 0;
1496 result = IDXGIFactory2_CreateSwapChainForCoreWindow(data->dxgiFactory,
1497 (IUnknown *)data->d3dDevice,
1507 }
else if (usingXAML) {
1508 result = IDXGIFactory2_CreateSwapChainForComposition(data->dxgiFactory,
1509 (IUnknown *)data->d3dDevice,
1518 #if WINAPI_FAMILY == WINAPI_FAMILY_APP 1525 SDL_SetError(SDL_COMPOSE_ERROR(
"XAML support is not yet available for Windows Phone"));
1535 result = IDXGIFactory2_CreateSwapChainForHwnd(data->dxgiFactory,
1536 (IUnknown *)data->d3dDevice,
1548 IDXGIFactory_MakeWindowAssociation(data->dxgiFactory, windowinfo.
info.win.
window, DXGI_MWA_NO_WINDOW_CHANGES);
1550 SDL_SetError(__FUNCTION__
", Unable to find something to attach a swap chain to");
1554 data->swapEffect = swapChainDesc.SwapEffect;
1557 SAFE_RELEASE(coreWindow);
1564 D3D11_CreateWindowSizeDependentResources(
SDL_Renderer * renderer)
1566 D3D11_RenderData *data = (D3D11_RenderData *)renderer->
driverdata;
1567 ID3D11Texture2D *backBuffer =
NULL;
1568 HRESULT result =
S_OK;
1572 D3D11_ReleaseMainRenderTargetView(renderer);
1578 data->rotation = D3D11_GetCurrentRotation();
1580 if (D3D11_IsDisplayRotated90Degrees(data->rotation)) {
1586 if (data->swapChain) {
1588 #if !defined(__WINRT__) || (WINAPI_FAMILY != WINAPI_FAMILY_PHONE_APP) 1590 result = IDXGISwapChain_ResizeBuffers(data->swapChain,
1593 DXGI_FORMAT_UNKNOWN,
1596 if (result == DXGI_ERROR_DEVICE_REMOVED) {
1598 D3D11_HandleDeviceLost(renderer);
1604 }
else if (
FAILED(result)) {
1610 result = D3D11_CreateSwapChain(renderer, w, h);
1616 #if WINAPI_FAMILY != WINAPI_FAMILY_PHONE_APP 1633 if (data->swapEffect == DXGI_SWAP_EFFECT_FLIP_SEQUENTIAL) {
1634 result = IDXGISwapChain1_SetRotation(data->swapChain, data->rotation);
1642 result = IDXGISwapChain_GetBuffer(data->swapChain,
1644 &SDL_IID_ID3D11Texture2D,
1645 (
void **)&backBuffer
1653 result = ID3D11Device_CreateRenderTargetView(data->d3dDevice,
1654 (ID3D11Resource *)backBuffer,
1656 &data->mainRenderTargetView
1663 if (D3D11_UpdateViewport(renderer) != 0) {
1670 SAFE_RELEASE(backBuffer);
1676 D3D11_UpdateForWindowSizeChange(
SDL_Renderer * renderer)
1678 return D3D11_CreateWindowSizeDependentResources(renderer);
1684 HRESULT result =
S_OK;
1686 D3D11_ReleaseAll(renderer);
1688 result = D3D11_CreateDeviceResources(renderer);
1694 result = D3D11_UpdateForWindowSizeChange(renderer);
1714 #if NTDDI_VERSION > NTDDI_WIN8 1715 D3D11_RenderData *data = (D3D11_RenderData *)renderer->
driverdata;
1716 HRESULT result =
S_OK;
1717 IDXGIDevice3 *dxgiDevice =
NULL;
1719 result = ID3D11Device_QueryInterface(data->d3dDevice, &SDL_IID_IDXGIDevice3, &dxgiDevice);
1725 IDXGIDevice3_Trim(dxgiDevice);
1726 SAFE_RELEASE(dxgiDevice);
1735 D3D11_UpdateForWindowSizeChange(renderer);
1749 if (!GetBlendFunc(srcColorFactor) || !GetBlendFunc(srcAlphaFactor) ||
1750 !GetBlendEquation(colorOperation) ||
1751 !GetBlendFunc(dstColorFactor) || !GetBlendFunc(dstAlphaFactor) ||
1752 !GetBlendEquation(alphaOperation)) {
1762 if (!hint || *hint ==
'0' ||
SDL_strcasecmp(hint,
"nearest") == 0) {
1763 return D3D11_FILTER_MIN_MAG_MIP_POINT;
1765 return D3D11_FILTER_MIN_MAG_MIP_LINEAR;
1772 D3D11_RenderData *rendererData = (D3D11_RenderData *) renderer->
driverdata;
1773 D3D11_TextureData *textureData;
1775 DXGI_FORMAT textureFormat = SDLPixelFormatToDXGIFormat(texture->
format);
1776 D3D11_TEXTURE2D_DESC textureDesc;
1777 D3D11_SHADER_RESOURCE_VIEW_DESC resourceViewDesc;
1779 if (textureFormat == DXGI_FORMAT_UNKNOWN) {
1780 return SDL_SetError(
"%s, An unsupported SDL pixel format (0x%x) was specified",
1781 __FUNCTION__, texture->
format);
1784 textureData = (D3D11_TextureData*)
SDL_calloc(1,
sizeof(*textureData));
1794 textureDesc.Width = texture->
w;
1795 textureDesc.Height = texture->
h;
1796 textureDesc.MipLevels = 1;
1797 textureDesc.ArraySize = 1;
1798 textureDesc.Format = textureFormat;
1799 textureDesc.SampleDesc.Count = 1;
1800 textureDesc.SampleDesc.Quality = 0;
1801 textureDesc.MiscFlags = 0;
1804 textureDesc.Usage = D3D11_USAGE_DYNAMIC;
1805 textureDesc.CPUAccessFlags = D3D11_CPU_ACCESS_WRITE;
1807 textureDesc.Usage = D3D11_USAGE_DEFAULT;
1808 textureDesc.CPUAccessFlags = 0;
1812 textureDesc.BindFlags = D3D11_BIND_SHADER_RESOURCE | D3D11_BIND_RENDER_TARGET;
1814 textureDesc.BindFlags = D3D11_BIND_SHADER_RESOURCE;
1817 result = ID3D11Device_CreateTexture2D(rendererData->d3dDevice,
1820 &textureData->mainTexture
1823 D3D11_DestroyTexture(renderer, texture);
1832 textureDesc.Width /= 2;
1833 textureDesc.Height /= 2;
1835 result = ID3D11Device_CreateTexture2D(rendererData->d3dDevice,
1838 &textureData->mainTextureU
1841 D3D11_DestroyTexture(renderer, texture);
1846 result = ID3D11Device_CreateTexture2D(rendererData->d3dDevice,
1849 &textureData->mainTextureV
1852 D3D11_DestroyTexture(renderer, texture);
1858 resourceViewDesc.Format = textureDesc.Format;
1859 resourceViewDesc.ViewDimension = D3D11_SRV_DIMENSION_TEXTURE2D;
1860 resourceViewDesc.Texture2D.MostDetailedMip = 0;
1861 resourceViewDesc.Texture2D.MipLevels = textureDesc.MipLevels;
1862 result = ID3D11Device_CreateShaderResourceView(rendererData->d3dDevice,
1863 (ID3D11Resource *)textureData->mainTexture,
1865 &textureData->mainTextureResourceView
1868 D3D11_DestroyTexture(renderer, texture);
1873 if (textureData->yuv) {
1874 result = ID3D11Device_CreateShaderResourceView(rendererData->d3dDevice,
1875 (ID3D11Resource *)textureData->mainTextureU,
1877 &textureData->mainTextureResourceViewU
1880 D3D11_DestroyTexture(renderer, texture);
1884 result = ID3D11Device_CreateShaderResourceView(rendererData->d3dDevice,
1885 (ID3D11Resource *)textureData->mainTextureV,
1887 &textureData->mainTextureResourceViewV
1890 D3D11_DestroyTexture(renderer, texture);
1897 D3D11_RENDER_TARGET_VIEW_DESC renderTargetViewDesc;
1898 renderTargetViewDesc.Format = textureDesc.Format;
1899 renderTargetViewDesc.ViewDimension = D3D11_RTV_DIMENSION_TEXTURE2D;
1900 renderTargetViewDesc.Texture2D.MipSlice = 0;
1902 result = ID3D11Device_CreateRenderTargetView(rendererData->d3dDevice,
1903 (ID3D11Resource *)textureData->mainTexture,
1904 &renderTargetViewDesc,
1905 &textureData->mainTextureRenderTargetView);
1907 D3D11_DestroyTexture(renderer, texture);
1920 D3D11_TextureData *data = (D3D11_TextureData *)texture->
driverdata;
1926 SAFE_RELEASE(data->mainTexture);
1927 SAFE_RELEASE(data->mainTextureResourceView);
1928 SAFE_RELEASE(data->mainTextureRenderTargetView);
1929 SAFE_RELEASE(data->stagingTexture);
1930 SAFE_RELEASE(data->mainTextureU);
1931 SAFE_RELEASE(data->mainTextureResourceViewU);
1932 SAFE_RELEASE(data->mainTextureV);
1933 SAFE_RELEASE(data->mainTextureResourceViewV);
1940 D3D11_UpdateTextureInternal(D3D11_RenderData *rendererData, ID3D11Texture2D *texture,
Uint32 format,
int x,
int y,
int w,
int h,
const void *
pixels,
int pitch)
1942 ID3D11Texture2D *stagingTexture;
1948 D3D11_TEXTURE2D_DESC stagingTextureDesc;
1949 D3D11_MAPPED_SUBRESOURCE textureMemory;
1952 ID3D11Texture2D_GetDesc(texture, &stagingTextureDesc);
1953 stagingTextureDesc.Width =
w;
1954 stagingTextureDesc.Height =
h;
1955 stagingTextureDesc.BindFlags = 0;
1956 stagingTextureDesc.MiscFlags = 0;
1957 stagingTextureDesc.CPUAccessFlags = D3D11_CPU_ACCESS_WRITE;
1958 stagingTextureDesc.Usage = D3D11_USAGE_STAGING;
1959 result = ID3D11Device_CreateTexture2D(rendererData->d3dDevice,
1960 &stagingTextureDesc,
1964 WIN_SetErrorFromHRESULT(SDL_COMPOSE_ERROR(
"ID3D11Device1::CreateTexture2D [create staging texture]"), result);
1969 result = ID3D11DeviceContext_Map(rendererData->d3dContext,
1970 (ID3D11Resource *)stagingTexture,
1978 SAFE_RELEASE(stagingTexture);
1982 src = (
const Uint8 *)pixels;
1983 dst = textureMemory.pData;
1985 if (length == pitch && length == textureMemory.RowPitch) {
1988 if (length > (UINT)pitch) {
1991 if (length > textureMemory.RowPitch) {
1992 length = textureMemory.RowPitch;
1994 for (row = 0; row <
h; ++
row) {
1997 dst += textureMemory.RowPitch;
2002 ID3D11DeviceContext_Unmap(rendererData->d3dContext,
2003 (ID3D11Resource *)stagingTexture,
2007 ID3D11DeviceContext_CopySubresourceRegion(rendererData->d3dContext,
2008 (ID3D11Resource *)texture,
2013 (ID3D11Resource *)stagingTexture,
2017 SAFE_RELEASE(stagingTexture);
2027 D3D11_RenderData *rendererData = (D3D11_RenderData *)renderer->
driverdata;
2028 D3D11_TextureData *textureData = (D3D11_TextureData *)texture->
driverdata;
2035 if (D3D11_UpdateTextureInternal(rendererData, textureData->mainTexture, texture->
format, rect->
x, rect->
y, rect->
w, rect->
h, srcPixels, srcPitch) < 0) {
2039 if (textureData->yuv) {
2041 srcPixels = (
const void*)((
const Uint8*)srcPixels + rect->
h * srcPitch);
2043 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) {
2048 srcPixels = (
const void*)((
const Uint8*)srcPixels + (rect->
h * srcPitch) / 4);
2049 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) {
2059 const Uint8 *Yplane,
int Ypitch,
2060 const Uint8 *Uplane,
int Upitch,
2061 const Uint8 *Vplane,
int Vpitch)
2063 D3D11_RenderData *rendererData = (D3D11_RenderData *)renderer->
driverdata;
2064 D3D11_TextureData *textureData = (D3D11_TextureData *)texture->
driverdata;
2071 if (D3D11_UpdateTextureInternal(rendererData, textureData->mainTexture, texture->
format, rect->
x, rect->
y, rect->
w, rect->
h, Yplane, Ypitch) < 0) {
2074 if (D3D11_UpdateTextureInternal(rendererData, textureData->mainTextureU, texture->
format, rect->
x / 2, rect->
y / 2, rect->
w / 2, rect->
h / 2, Uplane, Upitch) < 0) {
2077 if (D3D11_UpdateTextureInternal(rendererData, textureData->mainTextureV, texture->
format, rect->
x / 2, rect->
y / 2, rect->
w / 2, rect->
h / 2, Vplane, Vpitch) < 0) {
2085 const SDL_Rect * rect,
void **pixels,
int *pitch)
2087 D3D11_RenderData *rendererData = (D3D11_RenderData *) renderer->
driverdata;
2088 D3D11_TextureData *textureData = (D3D11_TextureData *) texture->
driverdata;
2089 HRESULT result =
S_OK;
2090 D3D11_TEXTURE2D_DESC stagingTextureDesc;
2091 D3D11_MAPPED_SUBRESOURCE textureMemory;
2098 if (textureData->yuv) {
2100 if (!textureData->pixels) {
2101 textureData->pitch = texture->
w;
2102 textureData->pixels = (
Uint8 *)
SDL_malloc((texture->
h * textureData->pitch * 3) / 2);
2103 if (!textureData->pixels) {
2107 textureData->locked_rect = *
rect;
2109 (
void *)((
Uint8 *)textureData->pixels + rect->
y * textureData->pitch +
2111 *pitch = textureData->pitch;
2115 if (textureData->stagingTexture) {
2127 ID3D11Texture2D_GetDesc(textureData->mainTexture, &stagingTextureDesc);
2128 stagingTextureDesc.Width = rect->
w;
2129 stagingTextureDesc.Height = rect->
h;
2130 stagingTextureDesc.BindFlags = 0;
2131 stagingTextureDesc.MiscFlags = 0;
2132 stagingTextureDesc.CPUAccessFlags = D3D11_CPU_ACCESS_WRITE;
2133 stagingTextureDesc.Usage = D3D11_USAGE_STAGING;
2134 result = ID3D11Device_CreateTexture2D(rendererData->d3dDevice,
2135 &stagingTextureDesc,
2137 &textureData->stagingTexture);
2139 WIN_SetErrorFromHRESULT(SDL_COMPOSE_ERROR(
"ID3D11Device1::CreateTexture2D [create staging texture]"), result);
2144 result = ID3D11DeviceContext_Map(rendererData->d3dContext,
2145 (ID3D11Resource *)textureData->stagingTexture,
2153 SAFE_RELEASE(textureData->stagingTexture);
2160 textureData->lockedTexturePositionX = rect->
x;
2161 textureData->lockedTexturePositionY = rect->
y;
2166 *pixels = textureMemory.pData;
2167 *pitch = textureMemory.RowPitch;
2174 D3D11_RenderData *rendererData = (D3D11_RenderData *) renderer->
driverdata;
2175 D3D11_TextureData *textureData = (D3D11_TextureData *) texture->
driverdata;
2181 if (textureData->yuv) {
2182 const SDL_Rect *rect = &textureData->locked_rect;
2184 (
void *) ((
Uint8 *) textureData->pixels + rect->
y * textureData->pitch +
2186 D3D11_UpdateTexture(renderer, texture, rect, pixels, textureData->pitch);
2191 ID3D11DeviceContext_Unmap(rendererData->d3dContext,
2192 (ID3D11Resource *)textureData->stagingTexture,
2196 ID3D11DeviceContext_CopySubresourceRegion(rendererData->d3dContext,
2197 (ID3D11Resource *)textureData->mainTexture,
2199 textureData->lockedTexturePositionX,
2200 textureData->lockedTexturePositionY,
2202 (ID3D11Resource *)textureData->stagingTexture,
2206 SAFE_RELEASE(textureData->stagingTexture);
2212 D3D11_RenderData *rendererData = (D3D11_RenderData *) renderer->
driverdata;
2213 D3D11_TextureData *textureData =
NULL;
2215 if (texture ==
NULL) {
2216 rendererData->currentOffscreenRenderTargetView =
NULL;
2220 textureData = (D3D11_TextureData *) texture->
driverdata;
2222 if (!textureData->mainTextureRenderTargetView) {
2223 return SDL_SetError(
"specified texture is not a render target");
2226 rendererData->currentOffscreenRenderTargetView = textureData->mainTextureRenderTargetView;
2234 D3D11_RenderData *data = (D3D11_RenderData *)renderer->
driverdata;
2237 data->vertexShaderConstantsData.model = *
matrix;
2239 data->vertexShaderConstantsData.model = MatrixIdentity();
2242 ID3D11DeviceContext_UpdateSubresource(data->d3dContext,
2243 (ID3D11Resource *)data->vertexShaderConstants,
2246 &data->vertexShaderConstantsData,
2255 D3D11_RenderData *data = (D3D11_RenderData *) renderer->
driverdata;
2256 Float4X4 projection;
2259 BOOL swapDimensions;
2261 const int rotation = D3D11_GetRotationForCurrentRenderTarget(renderer);
2278 case DXGI_MODE_ROTATION_IDENTITY:
2279 projection = MatrixIdentity();
2281 case DXGI_MODE_ROTATION_ROTATE270:
2284 case DXGI_MODE_ROTATION_ROTATE180:
2287 case DXGI_MODE_ROTATION_ROTATE90:
2291 return SDL_SetError(
"An unknown DisplayOrientation is being used");
2295 view.m[0][0] = 2.0f / renderer->
viewport.
w;
2296 view.m[0][1] = 0.0f;
2297 view.m[0][2] = 0.0f;
2298 view.m[0][3] = 0.0f;
2299 view.m[1][0] = 0.0f;
2300 view.m[1][1] = -2.0f / renderer->
viewport.
h;
2301 view.m[1][2] = 0.0f;
2302 view.m[1][3] = 0.0f;
2303 view.m[2][0] = 0.0f;
2304 view.m[2][1] = 0.0f;
2305 view.m[2][2] = 1.0f;
2306 view.m[2][3] = 0.0f;
2307 view.m[3][0] = -1.0f;
2308 view.m[3][1] = 1.0f;
2309 view.m[3][2] = 0.0f;
2310 view.m[3][3] = 1.0f;
2316 data->vertexShaderConstantsData.projectionAndView = MatrixMultiply(
2321 D3D11_SetModelMatrix(renderer,
NULL);
2328 swapDimensions = D3D11_IsDisplayRotated90Degrees(rotation);
2329 if (swapDimensions) {
2330 orientationAlignedViewport.x = (float) renderer->
viewport.
y;
2331 orientationAlignedViewport.y = (
float) renderer->
viewport.
x;
2332 orientationAlignedViewport.w = (float) renderer->
viewport.
h;
2333 orientationAlignedViewport.h = (
float) renderer->
viewport.
w;
2335 orientationAlignedViewport.x = (float) renderer->
viewport.
x;
2336 orientationAlignedViewport.y = (
float) renderer->
viewport.
y;
2337 orientationAlignedViewport.w = (float) renderer->
viewport.
w;
2338 orientationAlignedViewport.h = (
float) renderer->
viewport.
h;
2342 viewport.TopLeftX = orientationAlignedViewport.
x;
2343 viewport.TopLeftY = orientationAlignedViewport.
y;
2344 viewport.Width = orientationAlignedViewport.
w;
2345 viewport.Height = orientationAlignedViewport.
h;
2349 ID3D11DeviceContext_RSSetViewports(data->d3dContext, 1, &
viewport);
2357 D3D11_RenderData *data = (D3D11_RenderData *) renderer->
driverdata;
2360 ID3D11DeviceContext_RSSetScissorRects(data->d3dContext, 0,
NULL);
2362 D3D11_RECT scissorRect;
2363 if (D3D11_GetViewportAlignedD3DRect(renderer, &renderer->
clip_rect, &scissorRect,
TRUE) != 0) {
2367 ID3D11DeviceContext_RSSetScissorRects(data->d3dContext, 1, &scissorRect);
2374 D3D11_ReleaseMainRenderTargetView(
SDL_Renderer * renderer)
2376 D3D11_RenderData *data = (D3D11_RenderData *)renderer->
driverdata;
2377 ID3D11DeviceContext_OMSetRenderTargets(data->d3dContext, 0,
NULL,
NULL);
2378 SAFE_RELEASE(data->mainRenderTargetView);
2381 static ID3D11RenderTargetView *
2382 D3D11_GetCurrentRenderTargetView(
SDL_Renderer * renderer)
2384 D3D11_RenderData *data = (D3D11_RenderData *) renderer->
driverdata;
2385 if (data->currentOffscreenRenderTargetView) {
2386 return data->currentOffscreenRenderTargetView;
2388 return data->mainRenderTargetView;
2395 D3D11_RenderData *data = (D3D11_RenderData *) renderer->
driverdata;
2396 const float colorRGBA[] = {
2397 (renderer->
r / 255.0f),
2398 (renderer->
g / 255.0f),
2399 (renderer->
b / 255.0f),
2400 (renderer->
a / 255.0f)
2402 ID3D11DeviceContext_ClearRenderTargetView(data->d3dContext,
2403 D3D11_GetCurrentRenderTargetView(renderer),
2411 const void * vertexData,
size_t dataSizeInBytes)
2413 D3D11_RenderData *rendererData = (D3D11_RenderData *) renderer->
driverdata;
2414 D3D11_BUFFER_DESC vertexBufferDesc;
2415 HRESULT result =
S_OK;
2416 D3D11_SUBRESOURCE_DATA vertexBufferData;
2417 const UINT
stride =
sizeof(VertexPositionColor);
2420 if (rendererData->vertexBuffer) {
2421 ID3D11Buffer_GetDesc(rendererData->vertexBuffer, &vertexBufferDesc);
2426 if (rendererData->vertexBuffer && vertexBufferDesc.ByteWidth >= dataSizeInBytes) {
2427 D3D11_MAPPED_SUBRESOURCE mappedResource;
2428 result = ID3D11DeviceContext_Map(rendererData->d3dContext,
2429 (ID3D11Resource *)rendererData->vertexBuffer,
2431 D3D11_MAP_WRITE_DISCARD,
2439 SDL_memcpy(mappedResource.pData, vertexData, dataSizeInBytes);
2440 ID3D11DeviceContext_Unmap(rendererData->d3dContext, (ID3D11Resource *)rendererData->vertexBuffer, 0);
2442 SAFE_RELEASE(rendererData->vertexBuffer);
2444 vertexBufferDesc.ByteWidth = (UINT) dataSizeInBytes;
2445 vertexBufferDesc.Usage = D3D11_USAGE_DYNAMIC;
2446 vertexBufferDesc.BindFlags = D3D11_BIND_VERTEX_BUFFER;
2447 vertexBufferDesc.CPUAccessFlags = D3D11_CPU_ACCESS_WRITE;
2450 vertexBufferData.pSysMem = vertexData;
2451 vertexBufferData.SysMemPitch = 0;
2452 vertexBufferData.SysMemSlicePitch = 0;
2454 result = ID3D11Device_CreateBuffer(rendererData->d3dDevice,
2457 &rendererData->vertexBuffer
2464 ID3D11DeviceContext_IASetVertexBuffers(rendererData->d3dContext,
2467 &rendererData->vertexBuffer,
2479 D3D11_RenderData *rendererData = (D3D11_RenderData *)renderer->
driverdata;
2480 ID3D11RasterizerState *rasterizerState;
2481 ID3D11RenderTargetView *renderTargetView = D3D11_GetCurrentRenderTargetView(renderer);
2482 if (renderTargetView != rendererData->currentRenderTargetView) {
2483 ID3D11DeviceContext_OMSetRenderTargets(rendererData->d3dContext,
2488 rendererData->currentRenderTargetView = renderTargetView;
2492 rasterizerState = rendererData->mainRasterizer;
2494 rasterizerState = rendererData->clippedRasterizer;
2496 if (rasterizerState != rendererData->currentRasterizerState) {
2497 ID3D11DeviceContext_RSSetState(rendererData->d3dContext, rasterizerState);
2498 rendererData->currentRasterizerState = rasterizerState;
2505 D3D11_RenderData *rendererData = (D3D11_RenderData *)renderer->
driverdata;
2506 ID3D11BlendState *blendState =
NULL;
2509 for (i = 0; i < rendererData->blendModesCount; ++
i) {
2510 if (blendMode == rendererData->blendModes[i].blendMode) {
2511 blendState = rendererData->blendModes[
i].blendState;
2516 if (D3D11_CreateBlendState(renderer, blendMode)) {
2518 D3D11_RenderSetBlendMode(renderer, blendMode);
2523 if (blendState != rendererData->currentBlendState) {
2524 ID3D11DeviceContext_OMSetBlendState(rendererData->d3dContext, blendState, 0, 0xFFFFFFFF);
2525 rendererData->currentBlendState = blendState;
2531 ID3D11PixelShader *
shader,
2532 int numShaderResources,
2533 ID3D11ShaderResourceView ** shaderResources,
2536 D3D11_RenderData *rendererData = (D3D11_RenderData *) renderer->
driverdata;
2537 ID3D11ShaderResourceView *shaderResource;
2538 if (shader != rendererData->currentShader) {
2539 ID3D11DeviceContext_PSSetShader(rendererData->d3dContext, shader,
NULL, 0);
2540 rendererData->currentShader =
shader;
2542 if (numShaderResources > 0) {
2543 shaderResource = shaderResources[0];
2545 shaderResource =
NULL;
2547 if (shaderResource != rendererData->currentShaderResource) {
2548 ID3D11DeviceContext_PSSetShaderResources(rendererData->d3dContext, 0, numShaderResources, shaderResources);
2549 rendererData->currentShaderResource = shaderResource;
2551 if (sampler != rendererData->currentSampler) {
2552 ID3D11DeviceContext_PSSetSamplers(rendererData->d3dContext, 0, 1, &sampler);
2553 rendererData->currentSampler =
sampler;
2559 D3D11_PRIMITIVE_TOPOLOGY primitiveTopology,
2562 D3D11_RenderData *rendererData = (D3D11_RenderData *) renderer->
driverdata;
2564 ID3D11DeviceContext_IASetPrimitiveTopology(rendererData->d3dContext, primitiveTopology);
2565 ID3D11DeviceContext_Draw(rendererData->d3dContext, vertexCount, 0);
2572 D3D11_RenderData *rendererData = (D3D11_RenderData *) renderer->
driverdata;
2574 VertexPositionColor *vertices;
2577 r = (
float)(renderer->
r / 255.0f);
2578 g = (float)(renderer->
g / 255.0f);
2579 b = (float)(renderer->
b / 255.0f);
2580 a = (float)(renderer->
a / 255.0f);
2583 for (i = 0; i <
count; ++
i) {
2584 const VertexPositionColor
v = { { points[
i].
x + 0.5f, points[
i].
y + 0.5f, 0.0f }, { 0.0f, 0.0f }, {
r,
g,
b,
a } };
2588 D3D11_RenderStartDrawOp(renderer);
2589 D3D11_RenderSetBlendMode(renderer, renderer->
blendMode);
2590 if (D3D11_UpdateVertexBuffer(renderer, vertices, (
unsigned int)count *
sizeof(VertexPositionColor)) != 0) {
2595 D3D11_SetPixelShader(
2597 rendererData->colorPixelShader,
2602 D3D11_RenderFinishDrawOp(renderer, D3D11_PRIMITIVE_TOPOLOGY_POINTLIST, count);
2611 D3D11_RenderData *rendererData = (D3D11_RenderData *) renderer->
driverdata;
2613 VertexPositionColor *vertices;
2616 r = (
float)(renderer->
r / 255.0f);
2617 g = (float)(renderer->
g / 255.0f);
2618 b = (float)(renderer->
b / 255.0f);
2619 a = (float)(renderer->
a / 255.0f);
2622 for (i = 0; i <
count; ++
i) {
2623 const VertexPositionColor
v = { { points[
i].
x + 0.5f, points[
i].
y + 0.5f, 0.0f }, { 0.0f, 0.0f }, {
r,
g,
b,
a } };
2627 D3D11_RenderStartDrawOp(renderer);
2628 D3D11_RenderSetBlendMode(renderer, renderer->
blendMode);
2629 if (D3D11_UpdateVertexBuffer(renderer, vertices, (
unsigned int)count *
sizeof(VertexPositionColor)) != 0) {
2634 D3D11_SetPixelShader(
2636 rendererData->colorPixelShader,
2641 D3D11_RenderFinishDrawOp(renderer, D3D11_PRIMITIVE_TOPOLOGY_LINESTRIP, count);
2643 if (points[0].x != points[count - 1].x || points[0].y != points[count - 1].y) {
2644 ID3D11DeviceContext_IASetPrimitiveTopology(rendererData->d3dContext, D3D11_PRIMITIVE_TOPOLOGY_POINTLIST);
2645 ID3D11DeviceContext_Draw(rendererData->d3dContext, 1, count - 1);
2656 D3D11_RenderData *rendererData = (D3D11_RenderData *) renderer->
driverdata;
2660 r = (
float)(renderer->
r / 255.0f);
2661 g = (float)(renderer->
g / 255.0f);
2662 b = (float)(renderer->
b / 255.0f);
2663 a = (float)(renderer->
a / 255.0f);
2665 for (i = 0; i <
count; ++
i) {
2666 VertexPositionColor vertices[] = {
2667 { { rects[
i].
x, rects[
i].
y, 0.0f }, { 0.0f, 0.0f}, {
r,
g,
b,
a} },
2668 { { rects[
i].
x, rects[
i].
y + rects[
i].
h, 0.0f }, { 0.0f, 0.0f }, {
r,
g,
b, a } },
2669 { { rects[
i].
x + rects[
i].
w, rects[
i].
y, 0.0f }, { 0.0f, 0.0f }, {
r,
g,
b, a } },
2670 { { rects[
i].
x + rects[
i].
w, rects[
i].
y + rects[
i].
h, 0.0f }, { 0.0f, 0.0f }, {
r,
g,
b, a } },
2673 D3D11_RenderStartDrawOp(renderer);
2674 D3D11_RenderSetBlendMode(renderer, renderer->
blendMode);
2675 if (D3D11_UpdateVertexBuffer(renderer, vertices,
sizeof(vertices)) != 0) {
2679 D3D11_SetPixelShader(
2681 rendererData->colorPixelShader,
2686 D3D11_RenderFinishDrawOp(renderer, D3D11_PRIMITIVE_TOPOLOGY_TRIANGLESTRIP,
SDL_arraysize(vertices));
2692 static ID3D11SamplerState *
2695 D3D11_RenderData *rendererData = (D3D11_RenderData *) renderer->
driverdata;
2696 D3D11_TextureData *textureData = (D3D11_TextureData *) texture->
driverdata;
2698 switch (textureData->scaleMode) {
2699 case D3D11_FILTER_MIN_MAG_MIP_POINT:
2700 return rendererData->nearestPixelSampler;
2701 case D3D11_FILTER_MIN_MAG_MIP_LINEAR:
2702 return rendererData->linearSampler;
2712 D3D11_RenderData *rendererData = (D3D11_RenderData *) renderer->
driverdata;
2713 D3D11_TextureData *textureData = (D3D11_TextureData *) texture->
driverdata;
2714 float minu, maxu, minv, maxv;
2716 VertexPositionColor vertices[4];
2717 ID3D11SamplerState *textureSampler;
2719 D3D11_RenderStartDrawOp(renderer);
2720 D3D11_RenderSetBlendMode(renderer, texture->
blendMode);
2722 minu = (float) srcrect->
x / texture->
w;
2723 maxu = (
float) (srcrect->
x + srcrect->
w) / texture->
w;
2724 minv = (
float) srcrect->
y / texture->
h;
2725 maxv = (float) (srcrect->
y + srcrect->
h) / texture->
h;
2732 color.x = (float)(texture->
r / 255.0f);
2733 color.y = (float)(texture->
g / 255.0f);
2734 color.z = (float)(texture->
b / 255.0f);
2737 color.w = (float)(texture->
a / 255.0f);
2740 vertices[0].pos.x = dstrect->
x;
2741 vertices[0].pos.y = dstrect->
y;
2742 vertices[0].pos.z = 0.0f;
2743 vertices[0].tex.x = minu;
2744 vertices[0].tex.y = minv;
2745 vertices[0].color =
color;
2747 vertices[1].pos.x = dstrect->
x;
2748 vertices[1].pos.y = dstrect->
y + dstrect->
h;
2749 vertices[1].pos.z = 0.0f;
2750 vertices[1].tex.x = minu;
2751 vertices[1].tex.y = maxv;
2752 vertices[1].color =
color;
2754 vertices[2].pos.x = dstrect->
x + dstrect->
w;
2755 vertices[2].pos.y = dstrect->
y;
2756 vertices[2].pos.z = 0.0f;
2757 vertices[2].tex.x = maxu;
2758 vertices[2].tex.y = minv;
2759 vertices[2].color =
color;
2761 vertices[3].pos.x = dstrect->
x + dstrect->
w;
2762 vertices[3].pos.y = dstrect->
y + dstrect->
h;
2763 vertices[3].pos.z = 0.0f;
2764 vertices[3].tex.x = maxu;
2765 vertices[3].tex.y = maxv;
2766 vertices[3].color =
color;
2768 if (D3D11_UpdateVertexBuffer(renderer, vertices,
sizeof(vertices)) != 0) {
2772 textureSampler = D3D11_RenderGetSampler(renderer, texture);
2773 if (textureData->yuv) {
2774 ID3D11ShaderResourceView *shaderResources[] = {
2775 textureData->mainTextureResourceView,
2776 textureData->mainTextureResourceViewU,
2777 textureData->mainTextureResourceViewV
2779 D3D11_SetPixelShader(
2781 rendererData->yuvPixelShader,
2786 D3D11_SetPixelShader(
2788 rendererData->texturePixelShader,
2790 &textureData->mainTextureResourceView,
2794 D3D11_RenderFinishDrawOp(renderer, D3D11_PRIMITIVE_TOPOLOGY_TRIANGLESTRIP,
sizeof(vertices) /
sizeof(VertexPositionColor));
2804 D3D11_RenderData *rendererData = (D3D11_RenderData *) renderer->
driverdata;
2805 D3D11_TextureData *textureData = (D3D11_TextureData *) texture->
driverdata;
2806 float minu, maxu, minv, maxv;
2808 Float4X4 modelMatrix;
2809 float minx, maxx, miny, maxy;
2810 VertexPositionColor vertices[4];
2811 ID3D11SamplerState *textureSampler;
2813 D3D11_RenderStartDrawOp(renderer);
2814 D3D11_RenderSetBlendMode(renderer, texture->
blendMode);
2816 minu = (float) srcrect->
x / texture->
w;
2817 maxu = (
float) (srcrect->
x + srcrect->
w) / texture->
w;
2818 minv = (
float) srcrect->
y / texture->
h;
2819 maxv = (float) (srcrect->
y + srcrect->
h) / texture->
h;
2826 color.x = (float)(texture->
r / 255.0f);
2827 color.y = (float)(texture->
g / 255.0f);
2828 color.z = (float)(texture->
b / 255.0f);
2831 color.w = (float)(texture->
a / 255.0f);
2845 modelMatrix = MatrixMultiply(
2846 MatrixRotationZ((
float)(M_PI * (
float) angle / 180.0
f)),
2847 MatrixTranslation(dstrect->
x + center->
x, dstrect->
y + center->
y, 0)
2849 D3D11_SetModelMatrix(renderer, &modelMatrix);
2852 maxx = dstrect->
w - center->
x;
2854 maxy = dstrect->
h - center->
y;
2856 vertices[0].pos.x = minx;
2857 vertices[0].pos.y = miny;
2858 vertices[0].pos.z = 0.0f;
2859 vertices[0].tex.x = minu;
2860 vertices[0].tex.y = minv;
2861 vertices[0].color =
color;
2863 vertices[1].pos.x = minx;
2864 vertices[1].pos.y = maxy;
2865 vertices[1].pos.z = 0.0f;
2866 vertices[1].tex.x = minu;
2867 vertices[1].tex.y = maxv;
2868 vertices[1].color =
color;
2870 vertices[2].pos.x = maxx;
2871 vertices[2].pos.y = miny;
2872 vertices[2].pos.z = 0.0f;
2873 vertices[2].tex.x = maxu;
2874 vertices[2].tex.y = minv;
2875 vertices[2].color =
color;
2877 vertices[3].pos.x = maxx;
2878 vertices[3].pos.y = maxy;
2879 vertices[3].pos.z = 0.0f;
2880 vertices[3].tex.x = maxu;
2881 vertices[3].tex.y = maxv;
2882 vertices[3].color =
color;
2884 if (D3D11_UpdateVertexBuffer(renderer, vertices,
sizeof(vertices)) != 0) {
2888 textureSampler = D3D11_RenderGetSampler(renderer, texture);
2889 if (textureData->yuv) {
2890 ID3D11ShaderResourceView *shaderResources[] = {
2891 textureData->mainTextureResourceView,
2892 textureData->mainTextureResourceViewU,
2893 textureData->mainTextureResourceViewV
2895 D3D11_SetPixelShader(
2897 rendererData->yuvPixelShader,
2902 D3D11_SetPixelShader(
2904 rendererData->texturePixelShader,
2906 &textureData->mainTextureResourceView,
2910 D3D11_RenderFinishDrawOp(renderer, D3D11_PRIMITIVE_TOPOLOGY_TRIANGLESTRIP,
sizeof(vertices) /
sizeof(VertexPositionColor));
2912 D3D11_SetModelMatrix(renderer,
NULL);
2919 Uint32 format,
void * pixels,
int pitch)
2921 D3D11_RenderData * data = (D3D11_RenderData *) renderer->
driverdata;
2922 ID3D11Texture2D *backBuffer =
NULL;
2923 ID3D11Texture2D *stagingTexture =
NULL;
2926 D3D11_TEXTURE2D_DESC stagingTextureDesc;
2927 D3D11_RECT srcRect = {0, 0, 0, 0};
2929 D3D11_MAPPED_SUBRESOURCE textureMemory;
2932 result = IDXGISwapChain_GetBuffer(data->swapChain,
2934 &SDL_IID_ID3D11Texture2D,
2935 (
void **)&backBuffer
2943 ID3D11Texture2D_GetDesc(backBuffer, &stagingTextureDesc);
2944 stagingTextureDesc.Width = rect->
w;
2945 stagingTextureDesc.Height = rect->
h;
2946 stagingTextureDesc.BindFlags = 0;
2947 stagingTextureDesc.MiscFlags = 0;
2948 stagingTextureDesc.CPUAccessFlags = D3D11_CPU_ACCESS_READ;
2949 stagingTextureDesc.Usage = D3D11_USAGE_STAGING;
2950 result = ID3D11Device_CreateTexture2D(data->d3dDevice,
2951 &stagingTextureDesc,
2955 WIN_SetErrorFromHRESULT(SDL_COMPOSE_ERROR(
"ID3D11Device1::CreateTexture2D [create staging texture]"), result);
2960 if (D3D11_GetViewportAlignedD3DRect(renderer, rect, &srcRect,
FALSE) != 0) {
2965 srcBox.left = srcRect.left;
2966 srcBox.right = srcRect.right;
2967 srcBox.top = srcRect.top;
2968 srcBox.bottom = srcRect.bottom;
2971 ID3D11DeviceContext_CopySubresourceRegion(data->d3dContext,
2972 (ID3D11Resource *)stagingTexture,
2975 (ID3D11Resource *)backBuffer,
2980 result = ID3D11DeviceContext_Map(data->d3dContext,
2981 (ID3D11Resource *)stagingTexture,
2996 D3D11_DXGIFormatToSDLPixelFormat(stagingTextureDesc.Format),
2997 textureMemory.pData,
2998 textureMemory.RowPitch,
3005 char errorMessage[1024];
3012 ID3D11DeviceContext_Unmap(data->d3dContext,
3013 (ID3D11Resource *)stagingTexture,
3019 SAFE_RELEASE(backBuffer);
3020 SAFE_RELEASE(stagingTexture);
3027 D3D11_RenderData *data = (D3D11_RenderData *) renderer->
driverdata;
3031 DXGI_PRESENT_PARAMETERS parameters;
3035 #if WINAPI_FAMILY == WINAPI_FAMILY_PHONE_APP 3038 result = IDXGISwapChain_Present(data->swapChain, syncInterval, presentFlags);
3040 if (renderer->
info.
flags & SDL_RENDERER_PRESENTVSYNC) {
3045 presentFlags = DXGI_PRESENT_DO_NOT_WAIT;
3052 result = IDXGISwapChain1_Present1(data->swapChain, syncInterval, presentFlags, ¶meters);
3059 ID3D11DeviceContext1_DiscardView(data->d3dContext, (ID3D11View*)data->mainRenderTargetView);
3062 data->currentRenderTargetView =
NULL;
3064 if (
FAILED(result) && result != DXGI_ERROR_WAS_STILL_DRAWING) {
3070 if ( result == DXGI_ERROR_DEVICE_REMOVED ) {
3071 D3D11_HandleDeviceLost(renderer);
3072 }
else if (result == DXGI_ERROR_INVALID_CALL) {
3074 D3D11_CreateWindowSizeDependentResources(renderer);
SDL_BlendFactor SDL_GetBlendModeSrcColorFactor(SDL_BlendMode blendMode)
SDL_BlendFactor
The normalized factor used to multiply pixel components.
int(* RenderDrawLines)(SDL_Renderer *renderer, const SDL_FPoint *points, int count)
GLdouble GLdouble GLdouble r
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)
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.
SDL_bool(* SupportsBlendMode)(SDL_Renderer *renderer, SDL_BlendMode blendMode)
GLuint GLuint GLsizei count
#define SDL_HINT_RENDER_SCALE_QUALITY
A variable controlling the scaling quality.
SDL_RenderDriver D3D11_RenderDriver
GLfloat GLfloat GLfloat GLfloat h
int WIN_SetErrorFromHRESULT(const char *prefix, HRESULT hr)
SDL_BlendFactor SDL_GetBlendModeDstAlphaFactor(SDL_BlendMode blendMode)
SDL_BlendOperation SDL_GetBlendModeColorOperation(SDL_BlendMode blendMode)
#define SDL_BYTESPERPIXEL(X)
GLint GLenum GLsizei GLsizei GLsizei GLint GLsizei const GLvoid * data
int(* RenderFillRects)(SDL_Renderer *renderer, const SDL_FRect *rects, int count)
SDL_BlendOperation
The blend operation used when combining source and destination pixel components.
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
GLint GLint GLsizei GLsizei GLsizei GLint GLenum format
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
GLenum GLenum GLuint texture
void * SDL_calloc(size_t nmemb, size_t size)
SDL_BlendOperation SDL_GetBlendModeAlphaOperation(SDL_BlendMode blendMode)
static int GetScaleQuality(void)
static SDL_Renderer * renderer
#define SDL_stack_alloc(type, count)
#define SDL_static_cast(type, expression)
GLubyte GLubyte GLubyte GLubyte w
void(* UnlockTexture)(SDL_Renderer *renderer, SDL_Texture *texture)
GLint GLint GLint GLint GLint GLint y
int(* SetRenderTarget)(SDL_Renderer *renderer, SDL_Texture *texture)
int(* UpdateViewport)(SDL_Renderer *renderer)
GLint GLint GLsizei GLsizei GLsizei GLint GLenum GLenum const GLvoid * pixels
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()
SDL_BlendFactor SDL_GetBlendModeSrcAlphaFactor(SDL_BlendMode blendMode)
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)
EGLSurface EGLNativeWindowType * window
The type used to identify a window.
SDL_BlendFactor SDL_GetBlendModeDstColorFactor(SDL_BlendMode blendMode)
void(* WindowEvent)(SDL_Renderer *renderer, const SDL_WindowEvent *event)
union SDL_SysWMinfo::@18 info
#define SDL_arraysize(array)
#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)
EGLSurface EGLint * rects
#define SDL_stack_free(data)
GLuint GLsizei GLsizei * length
GLboolean GLboolean GLboolean GLboolean a
int(* UpdateClipRect)(SDL_Renderer *renderer)
GLboolean GLboolean GLboolean b
SDL_bool clipping_enabled
A rectangle, with the origin at the upper left.