| | |
| | | /* |
| | | Simple DirectMedia Layer |
| | | Copyright (C) 1997-2014 Sam Lantinga <slouken@libsdl.org> |
| | | Copyright (C) 1997-2018 Sam Lantinga <slouken@libsdl.org> |
| | | |
| | | This software is provided 'as-is', without any express or implied |
| | | warranty. In no event will the authors be held liable for any damages |
| | |
| | | |
| | | #include <d3d11_1.h> |
| | | |
| | | #include "SDL_shaders_d3d11.h" |
| | | |
| | | #ifdef __WINRT__ |
| | | |
| | | #if NTDDI_VERSION > NTDDI_WIN8 |
| | | #include <DXGI1_3.h> |
| | | #endif |
| | | |
| | | #include "SDL_render_winrt.h" |
| | | |
| | |
| | | |
| | | #endif /* __WINRT__ */ |
| | | |
| | | |
| | | #define SDL_COMPOSE_ERROR(str) SDL_STRINGIFY_ARG(__FUNCTION__) ", " str |
| | | |
| | | #define SAFE_RELEASE(X) if ((X)) { IUnknown_Release(SDL_static_cast(IUnknown*, X)); X = NULL; } |
| | | |
| | |
| | | ID3D11ShaderResourceView *mainTextureResourceViewU; |
| | | ID3D11Texture2D *mainTextureV; |
| | | ID3D11ShaderResourceView *mainTextureResourceViewV; |
| | | |
| | | /* NV12 texture support */ |
| | | SDL_bool nv12; |
| | | ID3D11Texture2D *mainTextureNV; |
| | | ID3D11ShaderResourceView *mainTextureResourceViewNV; |
| | | |
| | | Uint8 *pixels; |
| | | int pitch; |
| | | SDL_Rect locked_rect; |
| | | } D3D11_TextureData; |
| | | |
| | | /* Blend mode data */ |
| | | typedef struct |
| | | { |
| | | SDL_BlendMode blendMode; |
| | | ID3D11BlendState *blendState; |
| | | } D3D11_BlendMode; |
| | | |
| | | /* Private renderer data */ |
| | | typedef struct |
| | |
| | | ID3D11InputLayout *inputLayout; |
| | | ID3D11Buffer *vertexBuffer; |
| | | ID3D11VertexShader *vertexShader; |
| | | ID3D11PixelShader *colorPixelShader; |
| | | ID3D11PixelShader *texturePixelShader; |
| | | ID3D11PixelShader *yuvPixelShader; |
| | | ID3D11BlendState *blendModeBlend; |
| | | ID3D11BlendState *blendModeAdd; |
| | | ID3D11BlendState *blendModeMod; |
| | | ID3D11PixelShader *pixelShaders[NUM_SHADERS]; |
| | | int blendModesCount; |
| | | D3D11_BlendMode *blendModes; |
| | | ID3D11SamplerState *nearestPixelSampler; |
| | | ID3D11SamplerState *linearSampler; |
| | | D3D_FEATURE_LEVEL featureLevel; |
| | |
| | | } D3D11_RenderData; |
| | | |
| | | |
| | | /* Defined here so we don't have to include uuid.lib */ |
| | | static const GUID IID_IDXGIFactory2 = { 0x50c83a1c, 0xe072, 0x4c48, { 0x87, 0xb0, 0x36, 0x30, 0xfa, 0x36, 0xa6, 0xd0 } }; |
| | | static const GUID IID_IDXGIDevice1 = { 0x77db970f, 0x6276, 0x48ba, { 0xba, 0x28, 0x07, 0x01, 0x43, 0xb4, 0x39, 0x2c } }; |
| | | static const GUID IID_ID3D11Texture2D = { 0x6f15aaf2, 0xd208, 0x4e89, { 0x9a, 0xb4, 0x48, 0x95, 0x35, 0xd3, 0x4f, 0x9c } }; |
| | | static const GUID IID_ID3D11Device1 = { 0xa04bfb29, 0x08ef, 0x43d6, { 0xa4, 0x9c, 0xa9, 0xbd, 0xbd, 0xcb, 0xe6, 0x86 } }; |
| | | static const GUID IID_ID3D11DeviceContext1 = { 0xbb2c6faa, 0xb5fb, 0x4082, { 0x8e, 0x6b, 0x38, 0x8b, 0x8c, 0xfa, 0x90, 0xe1 } }; |
| | | static const GUID IID_ID3D11Debug = { 0x79cf2233, 0x7536, 0x4948, { 0x9d, 0x36, 0x1e, 0x46, 0x92, 0xdc, 0x57, 0x60 } }; |
| | | /* Define D3D GUIDs here so we don't have to include uuid.lib. |
| | | * |
| | | * Fix for SDL bug https://bugzilla.libsdl.org/show_bug.cgi?id=3437: |
| | | * The extra 'SDL_' was added to the start of each IID's name, in order |
| | | * to prevent build errors on both MinGW-w64 and WinRT/UWP. |
| | | * (SDL bug https://bugzilla.libsdl.org/show_bug.cgi?id=3336 led to |
| | | * linker errors in WinRT/UWP builds.) |
| | | */ |
| | | |
| | | /* Direct3D 11.x shaders |
| | | |
| | | SDL's shaders are compiled into SDL itself, to simplify distribution. |
| | | |
| | | All Direct3D 11.x shaders were compiled with the following: |
| | | |
| | | fxc /E"main" /T "<TYPE>" /Fo"<OUTPUT FILE>" "<INPUT FILE>" |
| | | |
| | | Variables: |
| | | - <TYPE>: the type of shader. A table of utilized shader types is |
| | | listed below. |
| | | - <OUTPUT FILE>: where to store compiled output |
| | | - <INPUT FILE>: where to read shader source code from |
| | | |
| | | Shader types: |
| | | - ps_4_0_level_9_1: Pixel shader for Windows 8+, including Windows RT |
| | | - vs_4_0_level_9_1: Vertex shader for Windows 8+, including Windows RT |
| | | - ps_4_0_level_9_3: Pixel shader for Windows Phone 8 |
| | | - vs_4_0_level_9_3: Vertex shader for Windows Phone 8 |
| | | |
| | | |
| | | Shader object code was converted to a list of DWORDs via the following |
| | | *nix style command (available separately from Windows + MSVC): |
| | | |
| | | hexdump -v -e '6/4 "0x%08.8x, " "\n"' <FILE> |
| | | */ |
| | | #if WINAPI_FAMILY == WINAPI_FAMILY_PHONE_APP |
| | | #define D3D11_USE_SHADER_MODEL_4_0_level_9_3 |
| | | #else |
| | | #define D3D11_USE_SHADER_MODEL_4_0_level_9_1 |
| | | #ifdef __GNUC__ |
| | | #pragma GCC diagnostic push |
| | | #pragma GCC diagnostic ignored "-Wunused-const-variable" |
| | | #endif |
| | | |
| | | /* The color-only-rendering pixel shader: |
| | | static const GUID SDL_IID_IDXGIFactory2 = { 0x50c83a1c, 0xe072, 0x4c48, { 0x87, 0xb0, 0x36, 0x30, 0xfa, 0x36, 0xa6, 0xd0 } }; |
| | | static const GUID SDL_IID_IDXGIDevice1 = { 0x77db970f, 0x6276, 0x48ba, { 0xba, 0x28, 0x07, 0x01, 0x43, 0xb4, 0x39, 0x2c } }; |
| | | static const GUID SDL_IID_IDXGIDevice3 = { 0x6007896c, 0x3244, 0x4afd, { 0xbf, 0x18, 0xa6, 0xd3, 0xbe, 0xda, 0x50, 0x23 } }; |
| | | static const GUID SDL_IID_ID3D11Texture2D = { 0x6f15aaf2, 0xd208, 0x4e89, { 0x9a, 0xb4, 0x48, 0x95, 0x35, 0xd3, 0x4f, 0x9c } }; |
| | | static const GUID SDL_IID_ID3D11Device1 = { 0xa04bfb29, 0x08ef, 0x43d6, { 0xa4, 0x9c, 0xa9, 0xbd, 0xbd, 0xcb, 0xe6, 0x86 } }; |
| | | static const GUID SDL_IID_ID3D11DeviceContext1 = { 0xbb2c6faa, 0xb5fb, 0x4082, { 0x8e, 0x6b, 0x38, 0x8b, 0x8c, 0xfa, 0x90, 0xe1 } }; |
| | | static const GUID SDL_IID_ID3D11Debug = { 0x79cf2233, 0x7536, 0x4948, { 0x9d, 0x36, 0x1e, 0x46, 0x92, 0xdc, 0x57, 0x60 } }; |
| | | |
| | | --- D3D11_PixelShader_Colors.hlsl --- |
| | | struct PixelShaderInput |
| | | { |
| | | float4 pos : SV_POSITION; |
| | | float2 tex : TEXCOORD0; |
| | | float4 color : COLOR0; |
| | | }; |
| | | |
| | | float4 main(PixelShaderInput input) : SV_TARGET |
| | | { |
| | | return input.color; |
| | | } |
| | | */ |
| | | #if defined(D3D11_USE_SHADER_MODEL_4_0_level_9_1) |
| | | static const DWORD D3D11_PixelShader_Colors[] = { |
| | | 0x43425844, 0xd74c28fe, 0xa1eb8804, 0x269d512a, 0x7699723d, 0x00000001, |
| | | 0x00000240, 0x00000006, 0x00000038, 0x00000084, 0x000000c4, 0x00000140, |
| | | 0x00000198, 0x0000020c, 0x396e6f41, 0x00000044, 0x00000044, 0xffff0200, |
| | | 0x00000020, 0x00000024, 0x00240000, 0x00240000, 0x00240000, 0x00240000, |
| | | 0x00240000, 0xffff0200, 0x0200001f, 0x80000000, 0xb00f0001, 0x02000001, |
| | | 0x800f0800, 0xb0e40001, 0x0000ffff, 0x52444853, 0x00000038, 0x00000040, |
| | | 0x0000000e, 0x03001062, 0x001010f2, 0x00000002, 0x03000065, 0x001020f2, |
| | | 0x00000000, 0x05000036, 0x001020f2, 0x00000000, 0x00101e46, 0x00000002, |
| | | 0x0100003e, 0x54415453, 0x00000074, 0x00000002, 0x00000000, 0x00000000, |
| | | 0x00000002, 0x00000000, 0x00000000, 0x00000000, 0x00000001, 0x00000000, |
| | | 0x00000000, 0x00000000, 0x00000000, 0x00000000, 0x00000000, 0x00000000, |
| | | 0x00000000, 0x00000000, 0x00000000, 0x00000000, 0x00000002, 0x00000000, |
| | | 0x00000000, 0x00000000, 0x00000000, 0x00000000, 0x00000000, 0x00000000, |
| | | 0x00000000, 0x00000000, 0x46454452, 0x00000050, 0x00000000, 0x00000000, |
| | | 0x00000000, 0x0000001c, 0xffff0400, 0x00000100, 0x0000001c, 0x7263694d, |
| | | 0x666f736f, 0x52282074, 0x4c482029, 0x53204c53, 0x65646168, 0x6f432072, |
| | | 0x6c69706d, 0x39207265, 0x2e30332e, 0x30303239, 0x3336312e, 0xab003438, |
| | | 0x4e475349, 0x0000006c, 0x00000003, 0x00000008, 0x00000050, 0x00000000, |
| | | 0x00000001, 0x00000003, 0x00000000, 0x0000000f, 0x0000005c, 0x00000000, |
| | | 0x00000000, 0x00000003, 0x00000001, 0x00000003, 0x00000065, 0x00000000, |
| | | 0x00000000, 0x00000003, 0x00000002, 0x00000f0f, 0x505f5653, 0x5449534f, |
| | | 0x004e4f49, 0x43584554, 0x44524f4f, 0x4c4f4300, 0xab00524f, 0x4e47534f, |
| | | 0x0000002c, 0x00000001, 0x00000008, 0x00000020, 0x00000000, 0x00000000, |
| | | 0x00000003, 0x00000000, 0x0000000f, 0x545f5653, 0x45475241, 0xabab0054 |
| | | }; |
| | | #elif defined(D3D11_USE_SHADER_MODEL_4_0_level_9_3) |
| | | static const DWORD D3D11_PixelShader_Colors[] = { |
| | | 0x43425844, 0x93f6ccfc, 0x5f919270, 0x7a11aa4f, 0x9148e931, 0x00000001, |
| | | 0x00000240, 0x00000006, 0x00000038, 0x00000084, 0x000000c4, 0x00000140, |
| | | 0x00000198, 0x0000020c, 0x396e6f41, 0x00000044, 0x00000044, 0xffff0200, |
| | | 0x00000020, 0x00000024, 0x00240000, 0x00240000, 0x00240000, 0x00240000, |
| | | 0x00240000, 0xffff0201, 0x0200001f, 0x80000000, 0xb00f0001, 0x02000001, |
| | | 0x800f0800, 0xb0e40001, 0x0000ffff, 0x52444853, 0x00000038, 0x00000040, |
| | | 0x0000000e, 0x03001062, 0x001010f2, 0x00000002, 0x03000065, 0x001020f2, |
| | | 0x00000000, 0x05000036, 0x001020f2, 0x00000000, 0x00101e46, 0x00000002, |
| | | 0x0100003e, 0x54415453, 0x00000074, 0x00000002, 0x00000000, 0x00000000, |
| | | 0x00000002, 0x00000000, 0x00000000, 0x00000000, 0x00000001, 0x00000000, |
| | | 0x00000000, 0x00000000, 0x00000000, 0x00000000, 0x00000000, 0x00000000, |
| | | 0x00000000, 0x00000000, 0x00000000, 0x00000000, 0x00000002, 0x00000000, |
| | | 0x00000000, 0x00000000, 0x00000000, 0x00000000, 0x00000000, 0x00000000, |
| | | 0x00000000, 0x00000000, 0x46454452, 0x00000050, 0x00000000, 0x00000000, |
| | | 0x00000000, 0x0000001c, 0xffff0400, 0x00000100, 0x0000001c, 0x7263694d, |
| | | 0x666f736f, 0x52282074, 0x4c482029, 0x53204c53, 0x65646168, 0x6f432072, |
| | | 0x6c69706d, 0x39207265, 0x2e30332e, 0x30303239, 0x3336312e, 0xab003438, |
| | | 0x4e475349, 0x0000006c, 0x00000003, 0x00000008, 0x00000050, 0x00000000, |
| | | 0x00000001, 0x00000003, 0x00000000, 0x0000000f, 0x0000005c, 0x00000000, |
| | | 0x00000000, 0x00000003, 0x00000001, 0x00000003, 0x00000065, 0x00000000, |
| | | 0x00000000, 0x00000003, 0x00000002, 0x00000f0f, 0x505f5653, 0x5449534f, |
| | | 0x004e4f49, 0x43584554, 0x44524f4f, 0x4c4f4300, 0xab00524f, 0x4e47534f, |
| | | 0x0000002c, 0x00000001, 0x00000008, 0x00000020, 0x00000000, 0x00000000, |
| | | 0x00000003, 0x00000000, 0x0000000f, 0x545f5653, 0x45475241, 0xabab0054 |
| | | }; |
| | | #else |
| | | #error "An appropriate 'colors' pixel shader is not defined." |
| | | #endif |
| | | |
| | | /* The texture-rendering pixel shader: |
| | | |
| | | --- D3D11_PixelShader_Textures.hlsl --- |
| | | Texture2D theTexture : register(t0); |
| | | SamplerState theSampler : register(s0); |
| | | |
| | | struct PixelShaderInput |
| | | { |
| | | float4 pos : SV_POSITION; |
| | | float2 tex : TEXCOORD0; |
| | | float4 color : COLOR0; |
| | | }; |
| | | |
| | | float4 main(PixelShaderInput input) : SV_TARGET |
| | | { |
| | | return theTexture.Sample(theSampler, input.tex) * input.color; |
| | | } |
| | | */ |
| | | #if defined(D3D11_USE_SHADER_MODEL_4_0_level_9_1) |
| | | static const DWORD D3D11_PixelShader_Textures[] = { |
| | | 0x43425844, 0x6299b59f, 0x155258f2, 0x873ab86a, 0xfcbb6dcd, 0x00000001, |
| | | 0x00000330, 0x00000006, 0x00000038, 0x000000c0, 0x0000015c, 0x000001d8, |
| | | 0x00000288, 0x000002fc, 0x396e6f41, 0x00000080, 0x00000080, 0xffff0200, |
| | | 0x00000058, 0x00000028, 0x00280000, 0x00280000, 0x00280000, 0x00240001, |
| | | 0x00280000, 0x00000000, 0xffff0200, 0x0200001f, 0x80000000, 0xb0030000, |
| | | 0x0200001f, 0x80000000, 0xb00f0001, 0x0200001f, 0x90000000, 0xa00f0800, |
| | | 0x03000042, 0x800f0000, 0xb0e40000, 0xa0e40800, 0x03000005, 0x800f0000, |
| | | 0x80e40000, 0xb0e40001, 0x02000001, 0x800f0800, 0x80e40000, 0x0000ffff, |
| | | 0x52444853, 0x00000094, 0x00000040, 0x00000025, 0x0300005a, 0x00106000, |
| | | 0x00000000, 0x04001858, 0x00107000, 0x00000000, 0x00005555, 0x03001062, |
| | | 0x00101032, 0x00000001, 0x03001062, 0x001010f2, 0x00000002, 0x03000065, |
| | | 0x001020f2, 0x00000000, 0x02000068, 0x00000001, 0x09000045, 0x001000f2, |
| | | 0x00000000, 0x00101046, 0x00000001, 0x00107e46, 0x00000000, 0x00106000, |
| | | 0x00000000, 0x07000038, 0x001020f2, 0x00000000, 0x00100e46, 0x00000000, |
| | | 0x00101e46, 0x00000002, 0x0100003e, 0x54415453, 0x00000074, 0x00000003, |
| | | 0x00000001, 0x00000000, 0x00000003, 0x00000001, 0x00000000, 0x00000000, |
| | | 0x00000001, 0x00000000, 0x00000000, 0x00000000, 0x00000000, 0x00000000, |
| | | 0x00000000, 0x00000001, 0x00000000, 0x00000000, 0x00000000, 0x00000000, |
| | | 0x00000001, 0x00000000, 0x00000000, 0x00000000, 0x00000000, 0x00000000, |
| | | 0x00000000, 0x00000000, 0x00000000, 0x00000000, 0x46454452, 0x000000a8, |
| | | 0x00000000, 0x00000000, 0x00000002, 0x0000001c, 0xffff0400, 0x00000100, |
| | | 0x00000072, 0x0000005c, 0x00000003, 0x00000000, 0x00000000, 0x00000000, |
| | | 0x00000000, 0x00000001, 0x00000001, 0x00000067, 0x00000002, 0x00000005, |
| | | 0x00000004, 0xffffffff, 0x00000000, 0x00000001, 0x0000000d, 0x53656874, |
| | | 0x6c706d61, 0x74007265, 0x65546568, 0x72757478, 0x694d0065, 0x736f7263, |
| | | 0x2074666f, 0x20295228, 0x4c534c48, 0x61685320, 0x20726564, 0x706d6f43, |
| | | 0x72656c69, 0x332e3920, 0x32392e30, 0x312e3030, 0x34383336, 0xababab00, |
| | | 0x4e475349, 0x0000006c, 0x00000003, 0x00000008, 0x00000050, 0x00000000, |
| | | 0x00000001, 0x00000003, 0x00000000, 0x0000000f, 0x0000005c, 0x00000000, |
| | | 0x00000000, 0x00000003, 0x00000001, 0x00000303, 0x00000065, 0x00000000, |
| | | 0x00000000, 0x00000003, 0x00000002, 0x00000f0f, 0x505f5653, 0x5449534f, |
| | | 0x004e4f49, 0x43584554, 0x44524f4f, 0x4c4f4300, 0xab00524f, 0x4e47534f, |
| | | 0x0000002c, 0x00000001, 0x00000008, 0x00000020, 0x00000000, 0x00000000, |
| | | 0x00000003, 0x00000000, 0x0000000f, 0x545f5653, 0x45475241, 0xabab0054 |
| | | }; |
| | | #elif defined(D3D11_USE_SHADER_MODEL_4_0_level_9_3) |
| | | static const DWORD D3D11_PixelShader_Textures[] = { |
| | | 0x43425844, 0x5876569a, 0x01b6c87e, 0x8447454f, 0xc7f3ef10, 0x00000001, |
| | | 0x00000330, 0x00000006, 0x00000038, 0x000000c0, 0x0000015c, 0x000001d8, |
| | | 0x00000288, 0x000002fc, 0x396e6f41, 0x00000080, 0x00000080, 0xffff0200, |
| | | 0x00000058, 0x00000028, 0x00280000, 0x00280000, 0x00280000, 0x00240001, |
| | | 0x00280000, 0x00000000, 0xffff0201, 0x0200001f, 0x80000000, 0xb0030000, |
| | | 0x0200001f, 0x80000000, 0xb00f0001, 0x0200001f, 0x90000000, 0xa00f0800, |
| | | 0x03000042, 0x800f0000, 0xb0e40000, 0xa0e40800, 0x03000005, 0x800f0000, |
| | | 0x80e40000, 0xb0e40001, 0x02000001, 0x800f0800, 0x80e40000, 0x0000ffff, |
| | | 0x52444853, 0x00000094, 0x00000040, 0x00000025, 0x0300005a, 0x00106000, |
| | | 0x00000000, 0x04001858, 0x00107000, 0x00000000, 0x00005555, 0x03001062, |
| | | 0x00101032, 0x00000001, 0x03001062, 0x001010f2, 0x00000002, 0x03000065, |
| | | 0x001020f2, 0x00000000, 0x02000068, 0x00000001, 0x09000045, 0x001000f2, |
| | | 0x00000000, 0x00101046, 0x00000001, 0x00107e46, 0x00000000, 0x00106000, |
| | | 0x00000000, 0x07000038, 0x001020f2, 0x00000000, 0x00100e46, 0x00000000, |
| | | 0x00101e46, 0x00000002, 0x0100003e, 0x54415453, 0x00000074, 0x00000003, |
| | | 0x00000001, 0x00000000, 0x00000003, 0x00000001, 0x00000000, 0x00000000, |
| | | 0x00000001, 0x00000000, 0x00000000, 0x00000000, 0x00000000, 0x00000000, |
| | | 0x00000000, 0x00000001, 0x00000000, 0x00000000, 0x00000000, 0x00000000, |
| | | 0x00000001, 0x00000000, 0x00000000, 0x00000000, 0x00000000, 0x00000000, |
| | | 0x00000000, 0x00000000, 0x00000000, 0x00000000, 0x46454452, 0x000000a8, |
| | | 0x00000000, 0x00000000, 0x00000002, 0x0000001c, 0xffff0400, 0x00000100, |
| | | 0x00000072, 0x0000005c, 0x00000003, 0x00000000, 0x00000000, 0x00000000, |
| | | 0x00000000, 0x00000001, 0x00000001, 0x00000067, 0x00000002, 0x00000005, |
| | | 0x00000004, 0xffffffff, 0x00000000, 0x00000001, 0x0000000d, 0x53656874, |
| | | 0x6c706d61, 0x74007265, 0x65546568, 0x72757478, 0x694d0065, 0x736f7263, |
| | | 0x2074666f, 0x20295228, 0x4c534c48, 0x61685320, 0x20726564, 0x706d6f43, |
| | | 0x72656c69, 0x332e3920, 0x32392e30, 0x312e3030, 0x34383336, 0xababab00, |
| | | 0x4e475349, 0x0000006c, 0x00000003, 0x00000008, 0x00000050, 0x00000000, |
| | | 0x00000001, 0x00000003, 0x00000000, 0x0000000f, 0x0000005c, 0x00000000, |
| | | 0x00000000, 0x00000003, 0x00000001, 0x00000303, 0x00000065, 0x00000000, |
| | | 0x00000000, 0x00000003, 0x00000002, 0x00000f0f, 0x505f5653, 0x5449534f, |
| | | 0x004e4f49, 0x43584554, 0x44524f4f, 0x4c4f4300, 0xab00524f, 0x4e47534f, |
| | | 0x0000002c, 0x00000001, 0x00000008, 0x00000020, 0x00000000, 0x00000000, |
| | | 0x00000003, 0x00000000, 0x0000000f, 0x545f5653, 0x45475241, 0xabab0054 |
| | | }; |
| | | #else |
| | | #error "An appropriate 'textures' pixel shader is not defined" |
| | | #endif |
| | | |
| | | /* The yuv-rendering pixel shader: |
| | | |
| | | --- D3D11_PixelShader_YUV.hlsl --- |
| | | Texture2D theTextureY : register(t0); |
| | | Texture2D theTextureU : register(t1); |
| | | Texture2D theTextureV : register(t2); |
| | | SamplerState theSampler : register(s0); |
| | | |
| | | struct PixelShaderInput |
| | | { |
| | | float4 pos : SV_POSITION; |
| | | float2 tex : TEXCOORD0; |
| | | float4 color : COLOR0; |
| | | }; |
| | | |
| | | float4 main(PixelShaderInput input) : SV_TARGET |
| | | { |
| | | const float3 offset = {-0.0625, -0.5, -0.5}; |
| | | const float3 Rcoeff = {1.164, 0.000, 1.596}; |
| | | const float3 Gcoeff = {1.164, -0.391, -0.813}; |
| | | const float3 Bcoeff = {1.164, 2.018, 0.000}; |
| | | |
| | | float4 Output; |
| | | |
| | | float3 yuv; |
| | | yuv.x = theTextureY.Sample(theSampler, input.tex).r; |
| | | yuv.y = theTextureU.Sample(theSampler, input.tex).r; |
| | | yuv.z = theTextureV.Sample(theSampler, input.tex).r; |
| | | |
| | | yuv += offset; |
| | | Output.r = dot(yuv, Rcoeff); |
| | | Output.g = dot(yuv, Gcoeff); |
| | | Output.b = dot(yuv, Bcoeff); |
| | | Output.a = 1.0f; |
| | | |
| | | return Output * input.color; |
| | | } |
| | | |
| | | */ |
| | | #if defined(D3D11_USE_SHADER_MODEL_4_0_level_9_1) |
| | | static const DWORD D3D11_PixelShader_YUV[] = { |
| | | 0x43425844, 0x04e69cba, 0x74ce6dd2, 0x7fcf84cb, 0x3003d677, 0x00000001, |
| | | 0x000005e8, 0x00000006, 0x00000038, 0x000001dc, 0x000003bc, 0x00000438, |
| | | 0x00000540, 0x000005b4, 0x396e6f41, 0x0000019c, 0x0000019c, 0xffff0200, |
| | | 0x0000016c, 0x00000030, 0x00300000, 0x00300000, 0x00300000, 0x00240003, |
| | | 0x00300000, 0x00000000, 0x00010001, 0x00020002, 0xffff0200, 0x05000051, |
| | | 0xa00f0000, 0xbd800000, 0xbf000000, 0xbf000000, 0x3f800000, 0x05000051, |
| | | 0xa00f0001, 0x3f94fdf4, 0x3fcc49ba, 0x00000000, 0x00000000, 0x05000051, |
| | | 0xa00f0002, 0x3f94fdf4, 0xbec83127, 0xbf5020c5, 0x00000000, 0x05000051, |
| | | 0xa00f0003, 0x3f94fdf4, 0x400126e9, 0x00000000, 0x00000000, 0x0200001f, |
| | | 0x80000000, 0xb0030000, 0x0200001f, 0x80000000, 0xb00f0001, 0x0200001f, |
| | | 0x90000000, 0xa00f0800, 0x0200001f, 0x90000000, 0xa00f0801, 0x0200001f, |
| | | 0x90000000, 0xa00f0802, 0x03000042, 0x800f0000, 0xb0e40000, 0xa0e40800, |
| | | 0x03000042, 0x800f0001, 0xb0e40000, 0xa0e40801, 0x03000042, 0x800f0002, |
| | | 0xb0e40000, 0xa0e40802, 0x02000001, 0x80020000, 0x80000001, 0x02000001, |
| | | 0x80040000, 0x80000002, 0x03000002, 0x80070000, 0x80e40000, 0xa0e40000, |
| | | 0x03000005, 0x80080000, 0x80000000, 0xa0000001, 0x04000004, 0x80010001, |
| | | 0x80aa0000, 0xa0550001, 0x80ff0000, 0x03000008, 0x80020001, 0x80e40000, |
| | | 0xa0e40002, 0x0400005a, 0x80040001, 0x80e40000, 0xa0e40003, 0xa0aa0003, |
| | | 0x02000001, 0x80080001, 0xa0ff0000, 0x03000005, 0x800f0000, 0x80e40001, |
| | | 0xb0e40001, 0x02000001, 0x800f0800, 0x80e40000, 0x0000ffff, 0x52444853, |
| | | 0x000001d8, 0x00000040, 0x00000076, 0x0300005a, 0x00106000, 0x00000000, |
| | | 0x04001858, 0x00107000, 0x00000000, 0x00005555, 0x04001858, 0x00107000, |
| | | 0x00000001, 0x00005555, 0x04001858, 0x00107000, 0x00000002, 0x00005555, |
| | | 0x03001062, 0x00101032, 0x00000001, 0x03001062, 0x001010f2, 0x00000002, |
| | | 0x03000065, 0x001020f2, 0x00000000, 0x02000068, 0x00000002, 0x09000045, |
| | | 0x001000f2, 0x00000000, 0x00101046, 0x00000001, 0x00107e46, 0x00000000, |
| | | 0x00106000, 0x00000000, 0x09000045, 0x001000f2, 0x00000001, 0x00101046, |
| | | 0x00000001, 0x00107e46, 0x00000001, 0x00106000, 0x00000000, 0x05000036, |
| | | 0x00100022, 0x00000000, 0x0010000a, 0x00000001, 0x09000045, 0x001000f2, |
| | | 0x00000001, 0x00101046, 0x00000001, 0x00107e46, 0x00000002, 0x00106000, |
| | | 0x00000000, 0x05000036, 0x00100042, 0x00000000, 0x0010000a, 0x00000001, |
| | | 0x0a000000, 0x00100072, 0x00000000, 0x00100246, 0x00000000, 0x00004002, |
| | | 0xbd800000, 0xbf000000, 0xbf000000, 0x00000000, 0x0a00000f, 0x00100012, |
| | | 0x00000001, 0x00100086, 0x00000000, 0x00004002, 0x3f94fdf4, 0x3fcc49ba, |
| | | 0x00000000, 0x00000000, 0x0a000010, 0x00100022, 0x00000001, 0x00100246, |
| | | 0x00000000, 0x00004002, 0x3f94fdf4, 0xbec83127, 0xbf5020c5, 0x00000000, |
| | | 0x0a00000f, 0x00100042, 0x00000001, 0x00100046, 0x00000000, 0x00004002, |
| | | 0x3f94fdf4, 0x400126e9, 0x00000000, 0x00000000, 0x05000036, 0x00100082, |
| | | 0x00000001, 0x00004001, 0x3f800000, 0x07000038, 0x001020f2, 0x00000000, |
| | | 0x00100e46, 0x00000001, 0x00101e46, 0x00000002, 0x0100003e, 0x54415453, |
| | | 0x00000074, 0x0000000c, 0x00000002, 0x00000000, 0x00000003, 0x00000005, |
| | | 0x00000000, 0x00000000, 0x00000001, 0x00000000, 0x00000000, 0x00000000, |
| | | 0x00000000, 0x00000000, 0x00000000, 0x00000003, 0x00000000, 0x00000000, |
| | | 0x00000000, 0x00000000, 0x00000003, 0x00000000, 0x00000000, 0x00000000, |
| | | 0x00000000, 0x00000000, 0x00000000, 0x00000000, 0x00000000, 0x00000000, |
| | | 0x46454452, 0x00000100, 0x00000000, 0x00000000, 0x00000004, 0x0000001c, |
| | | 0xffff0400, 0x00000100, 0x000000cb, 0x0000009c, 0x00000003, 0x00000000, |
| | | 0x00000000, 0x00000000, 0x00000000, 0x00000001, 0x00000001, 0x000000a7, |
| | | 0x00000002, 0x00000005, 0x00000004, 0xffffffff, 0x00000000, 0x00000001, |
| | | 0x0000000d, 0x000000b3, 0x00000002, 0x00000005, 0x00000004, 0xffffffff, |
| | | 0x00000001, 0x00000001, 0x0000000d, 0x000000bf, 0x00000002, 0x00000005, |
| | | 0x00000004, 0xffffffff, 0x00000002, 0x00000001, 0x0000000d, 0x53656874, |
| | | 0x6c706d61, 0x74007265, 0x65546568, 0x72757478, 0x74005965, 0x65546568, |
| | | 0x72757478, 0x74005565, 0x65546568, 0x72757478, 0x4d005665, 0x6f726369, |
| | | 0x74666f73, 0x29522820, 0x534c4820, 0x6853204c, 0x72656461, 0x6d6f4320, |
| | | 0x656c6970, 0x2e362072, 0x36392e33, 0x312e3030, 0x34383336, 0xababab00, |
| | | 0x4e475349, 0x0000006c, 0x00000003, 0x00000008, 0x00000050, 0x00000000, |
| | | 0x00000001, 0x00000003, 0x00000000, 0x0000000f, 0x0000005c, 0x00000000, |
| | | 0x00000000, 0x00000003, 0x00000001, 0x00000303, 0x00000065, 0x00000000, |
| | | 0x00000000, 0x00000003, 0x00000002, 0x00000f0f, 0x505f5653, 0x5449534f, |
| | | 0x004e4f49, 0x43584554, 0x44524f4f, 0x4c4f4300, 0xab00524f, 0x4e47534f, |
| | | 0x0000002c, 0x00000001, 0x00000008, 0x00000020, 0x00000000, 0x00000000, |
| | | 0x00000003, 0x00000000, 0x0000000f, 0x545f5653, 0x45475241, 0xabab0054 |
| | | }; |
| | | #elif defined(D3D11_USE_SHADER_MODEL_4_0_level_9_3) |
| | | static const DWORD D3D11_PixelShader_YUV[] = { |
| | | 0x43425844, 0xe6d969fc, 0x63cac33c, 0xa4926502, 0x5d788135, 0x00000001, |
| | | 0x000005c0, 0x00000006, 0x00000038, 0x000001b4, 0x00000394, 0x00000410, |
| | | 0x00000518, 0x0000058c, 0x396e6f41, 0x00000174, 0x00000174, 0xffff0200, |
| | | 0x00000144, 0x00000030, 0x00300000, 0x00300000, 0x00300000, 0x00240003, |
| | | 0x00300000, 0x00000000, 0x00010001, 0x00020002, 0xffff0201, 0x05000051, |
| | | 0xa00f0000, 0xbd800000, 0xbf000000, 0x3f800000, 0x00000000, 0x05000051, |
| | | 0xa00f0001, 0x3f94fdf4, 0x3fcc49ba, 0x00000000, 0x400126e9, 0x05000051, |
| | | 0xa00f0002, 0x3f94fdf4, 0xbec83127, 0xbf5020c5, 0x00000000, 0x0200001f, |
| | | 0x80000000, 0xb0030000, 0x0200001f, 0x80000000, 0xb00f0001, 0x0200001f, |
| | | 0x90000000, 0xa00f0800, 0x0200001f, 0x90000000, 0xa00f0801, 0x0200001f, |
| | | 0x90000000, 0xa00f0802, 0x03000042, 0x800f0000, 0xb0e40000, 0xa0e40801, |
| | | 0x03000042, 0x800f0001, 0xb0e40000, 0xa0e40800, 0x02000001, 0x80020001, |
| | | 0x80000000, 0x03000042, 0x800f0000, 0xb0e40000, 0xa0e40802, 0x02000001, |
| | | 0x80040001, 0x80000000, 0x03000002, 0x80070000, 0x80e40001, 0xa0d40000, |
| | | 0x0400005a, 0x80010001, 0x80e80000, 0xa0e40001, 0xa0aa0001, 0x03000008, |
| | | 0x80020001, 0x80e40000, 0xa0e40002, 0x0400005a, 0x80040001, 0x80e40000, |
| | | 0xa0ec0001, 0xa0aa0001, 0x02000001, 0x80080001, 0xa0aa0000, 0x03000005, |
| | | 0x800f0000, 0x80e40001, 0xb0e40001, 0x02000001, 0x800f0800, 0x80e40000, |
| | | 0x0000ffff, 0x52444853, 0x000001d8, 0x00000040, 0x00000076, 0x0300005a, |
| | | 0x00106000, 0x00000000, 0x04001858, 0x00107000, 0x00000000, 0x00005555, |
| | | 0x04001858, 0x00107000, 0x00000001, 0x00005555, 0x04001858, 0x00107000, |
| | | 0x00000002, 0x00005555, 0x03001062, 0x00101032, 0x00000001, 0x03001062, |
| | | 0x001010f2, 0x00000002, 0x03000065, 0x001020f2, 0x00000000, 0x02000068, |
| | | 0x00000002, 0x09000045, 0x001000f2, 0x00000000, 0x00101046, 0x00000001, |
| | | 0x00107e46, 0x00000000, 0x00106000, 0x00000000, 0x09000045, 0x001000f2, |
| | | 0x00000001, 0x00101046, 0x00000001, 0x00107e46, 0x00000001, 0x00106000, |
| | | 0x00000000, 0x05000036, 0x00100022, 0x00000000, 0x0010000a, 0x00000001, |
| | | 0x09000045, 0x001000f2, 0x00000001, 0x00101046, 0x00000001, 0x00107e46, |
| | | 0x00000002, 0x00106000, 0x00000000, 0x05000036, 0x00100042, 0x00000000, |
| | | 0x0010000a, 0x00000001, 0x0a000000, 0x00100072, 0x00000000, 0x00100246, |
| | | 0x00000000, 0x00004002, 0xbd800000, 0xbf000000, 0xbf000000, 0x00000000, |
| | | 0x0a00000f, 0x00100012, 0x00000001, 0x00100086, 0x00000000, 0x00004002, |
| | | 0x3f94fdf4, 0x3fcc49ba, 0x00000000, 0x00000000, 0x0a000010, 0x00100022, |
| | | 0x00000001, 0x00100246, 0x00000000, 0x00004002, 0x3f94fdf4, 0xbec83127, |
| | | 0xbf5020c5, 0x00000000, 0x0a00000f, 0x00100042, 0x00000001, 0x00100046, |
| | | 0x00000000, 0x00004002, 0x3f94fdf4, 0x400126e9, 0x00000000, 0x00000000, |
| | | 0x05000036, 0x00100082, 0x00000001, 0x00004001, 0x3f800000, 0x07000038, |
| | | 0x001020f2, 0x00000000, 0x00100e46, 0x00000001, 0x00101e46, 0x00000002, |
| | | 0x0100003e, 0x54415453, 0x00000074, 0x0000000c, 0x00000002, 0x00000000, |
| | | 0x00000003, 0x00000005, 0x00000000, 0x00000000, 0x00000001, 0x00000000, |
| | | 0x00000000, 0x00000000, 0x00000000, 0x00000000, 0x00000000, 0x00000003, |
| | | 0x00000000, 0x00000000, 0x00000000, 0x00000000, 0x00000003, 0x00000000, |
| | | 0x00000000, 0x00000000, 0x00000000, 0x00000000, 0x00000000, 0x00000000, |
| | | 0x00000000, 0x00000000, 0x46454452, 0x00000100, 0x00000000, 0x00000000, |
| | | 0x00000004, 0x0000001c, 0xffff0400, 0x00000100, 0x000000cb, 0x0000009c, |
| | | 0x00000003, 0x00000000, 0x00000000, 0x00000000, 0x00000000, 0x00000001, |
| | | 0x00000001, 0x000000a7, 0x00000002, 0x00000005, 0x00000004, 0xffffffff, |
| | | 0x00000000, 0x00000001, 0x0000000d, 0x000000b3, 0x00000002, 0x00000005, |
| | | 0x00000004, 0xffffffff, 0x00000001, 0x00000001, 0x0000000d, 0x000000bf, |
| | | 0x00000002, 0x00000005, 0x00000004, 0xffffffff, 0x00000002, 0x00000001, |
| | | 0x0000000d, 0x53656874, 0x6c706d61, 0x74007265, 0x65546568, 0x72757478, |
| | | 0x74005965, 0x65546568, 0x72757478, 0x74005565, 0x65546568, 0x72757478, |
| | | 0x4d005665, 0x6f726369, 0x74666f73, 0x29522820, 0x534c4820, 0x6853204c, |
| | | 0x72656461, 0x6d6f4320, 0x656c6970, 0x2e362072, 0x36392e33, 0x312e3030, |
| | | 0x34383336, 0xababab00, 0x4e475349, 0x0000006c, 0x00000003, 0x00000008, |
| | | 0x00000050, 0x00000000, 0x00000001, 0x00000003, 0x00000000, 0x0000000f, |
| | | 0x0000005c, 0x00000000, 0x00000000, 0x00000003, 0x00000001, 0x00000303, |
| | | 0x00000065, 0x00000000, 0x00000000, 0x00000003, 0x00000002, 0x00000f0f, |
| | | 0x505f5653, 0x5449534f, 0x004e4f49, 0x43584554, 0x44524f4f, 0x4c4f4300, |
| | | 0xab00524f, 0x4e47534f, 0x0000002c, 0x00000001, 0x00000008, 0x00000020, |
| | | 0x00000000, 0x00000000, 0x00000003, 0x00000000, 0x0000000f, 0x545f5653, |
| | | 0x45475241, 0xabab0054 |
| | | }; |
| | | #else |
| | | #error "An appropriate 'yuv' pixel shader is not defined." |
| | | #endif |
| | | |
| | | /* The sole vertex shader: |
| | | |
| | | --- D3D11_VertexShader.hlsl --- |
| | | #pragma pack_matrix( row_major ) |
| | | |
| | | cbuffer VertexShaderConstants : register(b0) |
| | | { |
| | | matrix model; |
| | | matrix projectionAndView; |
| | | }; |
| | | |
| | | struct VertexShaderInput |
| | | { |
| | | float3 pos : POSITION; |
| | | float2 tex : TEXCOORD0; |
| | | float4 color : COLOR0; |
| | | }; |
| | | |
| | | struct VertexShaderOutput |
| | | { |
| | | float4 pos : SV_POSITION; |
| | | float2 tex : TEXCOORD0; |
| | | float4 color : COLOR0; |
| | | }; |
| | | |
| | | VertexShaderOutput main(VertexShaderInput input) |
| | | { |
| | | VertexShaderOutput output; |
| | | float4 pos = float4(input.pos, 1.0f); |
| | | |
| | | // Transform the vertex position into projected space. |
| | | pos = mul(pos, model); |
| | | pos = mul(pos, projectionAndView); |
| | | output.pos = pos; |
| | | |
| | | // Pass through texture coordinates and color values without transformation |
| | | output.tex = input.tex; |
| | | output.color = input.color; |
| | | |
| | | return output; |
| | | } |
| | | */ |
| | | #if defined(D3D11_USE_SHADER_MODEL_4_0_level_9_1) |
| | | static const DWORD D3D11_VertexShader[] = { |
| | | 0x43425844, 0x62dfae5f, 0x3e8bd8df, 0x9ec97127, 0x5044eefb, 0x00000001, |
| | | 0x00000598, 0x00000006, 0x00000038, 0x0000016c, 0x00000334, 0x000003b0, |
| | | 0x000004b4, 0x00000524, 0x396e6f41, 0x0000012c, 0x0000012c, 0xfffe0200, |
| | | 0x000000f8, 0x00000034, 0x00240001, 0x00300000, 0x00300000, 0x00240000, |
| | | 0x00300001, 0x00000000, 0x00010008, 0x00000000, 0x00000000, 0xfffe0200, |
| | | 0x0200001f, 0x80000005, 0x900f0000, 0x0200001f, 0x80010005, 0x900f0001, |
| | | 0x0200001f, 0x80020005, 0x900f0002, 0x03000005, 0x800f0000, 0x90550000, |
| | | 0xa0e40002, 0x04000004, 0x800f0000, 0x90000000, 0xa0e40001, 0x80e40000, |
| | | 0x04000004, 0x800f0000, 0x90aa0000, 0xa0e40003, 0x80e40000, 0x03000002, |
| | | 0x800f0000, 0x80e40000, 0xa0e40004, 0x03000005, 0x800f0001, 0x80550000, |
| | | 0xa0e40006, 0x04000004, 0x800f0001, 0x80000000, 0xa0e40005, 0x80e40001, |
| | | 0x04000004, 0x800f0001, 0x80aa0000, 0xa0e40007, 0x80e40001, 0x04000004, |
| | | 0x800f0000, 0x80ff0000, 0xa0e40008, 0x80e40001, 0x04000004, 0xc0030000, |
| | | 0x80ff0000, 0xa0e40000, 0x80e40000, 0x02000001, 0xc00c0000, 0x80e40000, |
| | | 0x02000001, 0xe0030000, 0x90e40001, 0x02000001, 0xe00f0001, 0x90e40002, |
| | | 0x0000ffff, 0x52444853, 0x000001c0, 0x00010040, 0x00000070, 0x04000059, |
| | | 0x00208e46, 0x00000000, 0x00000008, 0x0300005f, 0x00101072, 0x00000000, |
| | | 0x0300005f, 0x00101032, 0x00000001, 0x0300005f, 0x001010f2, 0x00000002, |
| | | 0x04000067, 0x001020f2, 0x00000000, 0x00000001, 0x03000065, 0x00102032, |
| | | 0x00000001, 0x03000065, 0x001020f2, 0x00000002, 0x02000068, 0x00000002, |
| | | 0x08000038, 0x001000f2, 0x00000000, 0x00101556, 0x00000000, 0x00208e46, |
| | | 0x00000000, 0x00000001, 0x0a000032, 0x001000f2, 0x00000000, 0x00101006, |
| | | 0x00000000, 0x00208e46, 0x00000000, 0x00000000, 0x00100e46, 0x00000000, |
| | | 0x0a000032, 0x001000f2, 0x00000000, 0x00101aa6, 0x00000000, 0x00208e46, |
| | | 0x00000000, 0x00000002, 0x00100e46, 0x00000000, 0x08000000, 0x001000f2, |
| | | 0x00000000, 0x00100e46, 0x00000000, 0x00208e46, 0x00000000, 0x00000003, |
| | | 0x08000038, 0x001000f2, 0x00000001, 0x00100556, 0x00000000, 0x00208e46, |
| | | 0x00000000, 0x00000005, 0x0a000032, 0x001000f2, 0x00000001, 0x00100006, |
| | | 0x00000000, 0x00208e46, 0x00000000, 0x00000004, 0x00100e46, 0x00000001, |
| | | 0x0a000032, 0x001000f2, 0x00000001, 0x00100aa6, 0x00000000, 0x00208e46, |
| | | 0x00000000, 0x00000006, 0x00100e46, 0x00000001, 0x0a000032, 0x001020f2, |
| | | 0x00000000, 0x00100ff6, 0x00000000, 0x00208e46, 0x00000000, 0x00000007, |
| | | 0x00100e46, 0x00000001, 0x05000036, 0x00102032, 0x00000001, 0x00101046, |
| | | 0x00000001, 0x05000036, 0x001020f2, 0x00000002, 0x00101e46, 0x00000002, |
| | | 0x0100003e, 0x54415453, 0x00000074, 0x0000000b, 0x00000002, 0x00000000, |
| | | 0x00000006, 0x00000003, 0x00000000, 0x00000000, 0x00000001, 0x00000000, |
| | | 0x00000000, 0x00000000, 0x00000000, 0x00000000, 0x00000000, 0x00000000, |
| | | 0x00000000, 0x00000000, 0x00000000, 0x00000000, 0x00000003, 0x00000000, |
| | | 0x00000000, 0x00000000, 0x00000000, 0x00000000, 0x00000000, 0x00000000, |
| | | 0x00000000, 0x00000000, 0x46454452, 0x000000fc, 0x00000001, 0x00000054, |
| | | 0x00000001, 0x0000001c, 0xfffe0400, 0x00000100, 0x000000c6, 0x0000003c, |
| | | 0x00000000, 0x00000000, 0x00000000, 0x00000000, 0x00000000, 0x00000001, |
| | | 0x00000001, 0x74726556, 0x68537865, 0x72656461, 0x736e6f43, 0x746e6174, |
| | | 0xabab0073, 0x0000003c, 0x00000002, 0x0000006c, 0x00000080, 0x00000000, |
| | | 0x00000000, 0x0000009c, 0x00000000, 0x00000040, 0x00000002, 0x000000a4, |
| | | 0x00000000, 0x000000b4, 0x00000040, 0x00000040, 0x00000002, 0x000000a4, |
| | | 0x00000000, 0x65646f6d, 0xabab006c, 0x00030002, 0x00040004, 0x00000000, |
| | | 0x00000000, 0x6a6f7270, 0x69746365, 0x6e416e6f, 0x65695664, 0x694d0077, |
| | | 0x736f7263, 0x2074666f, 0x20295228, 0x4c534c48, 0x61685320, 0x20726564, |
| | | 0x706d6f43, 0x72656c69, 0x332e3920, 0x32392e30, 0x312e3030, 0x34383336, |
| | | 0xababab00, 0x4e475349, 0x00000068, 0x00000003, 0x00000008, 0x00000050, |
| | | 0x00000000, 0x00000000, 0x00000003, 0x00000000, 0x00000707, 0x00000059, |
| | | 0x00000000, 0x00000000, 0x00000003, 0x00000001, 0x00000303, 0x00000062, |
| | | 0x00000000, 0x00000000, 0x00000003, 0x00000002, 0x00000f0f, 0x49534f50, |
| | | 0x4e4f4954, 0x58455400, 0x524f4f43, 0x4f430044, 0x00524f4c, 0x4e47534f, |
| | | 0x0000006c, 0x00000003, 0x00000008, 0x00000050, 0x00000000, 0x00000001, |
| | | 0x00000003, 0x00000000, 0x0000000f, 0x0000005c, 0x00000000, 0x00000000, |
| | | 0x00000003, 0x00000001, 0x00000c03, 0x00000065, 0x00000000, 0x00000000, |
| | | 0x00000003, 0x00000002, 0x0000000f, 0x505f5653, 0x5449534f, 0x004e4f49, |
| | | 0x43584554, 0x44524f4f, 0x4c4f4300, 0xab00524f |
| | | }; |
| | | #elif defined(D3D11_USE_SHADER_MODEL_4_0_level_9_3) |
| | | static const DWORD D3D11_VertexShader[] = { |
| | | 0x43425844, 0x01a24e41, 0x696af551, 0x4b2a87d1, 0x82ea03f6, 0x00000001, |
| | | 0x00000598, 0x00000006, 0x00000038, 0x0000016c, 0x00000334, 0x000003b0, |
| | | 0x000004b4, 0x00000524, 0x396e6f41, 0x0000012c, 0x0000012c, 0xfffe0200, |
| | | 0x000000f8, 0x00000034, 0x00240001, 0x00300000, 0x00300000, 0x00240000, |
| | | 0x00300001, 0x00000000, 0x00010008, 0x00000000, 0x00000000, 0xfffe0201, |
| | | 0x0200001f, 0x80000005, 0x900f0000, 0x0200001f, 0x80010005, 0x900f0001, |
| | | 0x0200001f, 0x80020005, 0x900f0002, 0x03000005, 0x800f0000, 0x90550000, |
| | | 0xa0e40002, 0x04000004, 0x800f0000, 0x90000000, 0xa0e40001, 0x80e40000, |
| | | 0x04000004, 0x800f0000, 0x90aa0000, 0xa0e40003, 0x80e40000, 0x03000002, |
| | | 0x800f0000, 0x80e40000, 0xa0e40004, 0x03000005, 0x800f0001, 0x80550000, |
| | | 0xa0e40006, 0x04000004, 0x800f0001, 0x80000000, 0xa0e40005, 0x80e40001, |
| | | 0x04000004, 0x800f0001, 0x80aa0000, 0xa0e40007, 0x80e40001, 0x04000004, |
| | | 0x800f0000, 0x80ff0000, 0xa0e40008, 0x80e40001, 0x04000004, 0xc0030000, |
| | | 0x80ff0000, 0xa0e40000, 0x80e40000, 0x02000001, 0xc00c0000, 0x80e40000, |
| | | 0x02000001, 0xe0030000, 0x90e40001, 0x02000001, 0xe00f0001, 0x90e40002, |
| | | 0x0000ffff, 0x52444853, 0x000001c0, 0x00010040, 0x00000070, 0x04000059, |
| | | 0x00208e46, 0x00000000, 0x00000008, 0x0300005f, 0x00101072, 0x00000000, |
| | | 0x0300005f, 0x00101032, 0x00000001, 0x0300005f, 0x001010f2, 0x00000002, |
| | | 0x04000067, 0x001020f2, 0x00000000, 0x00000001, 0x03000065, 0x00102032, |
| | | 0x00000001, 0x03000065, 0x001020f2, 0x00000002, 0x02000068, 0x00000002, |
| | | 0x08000038, 0x001000f2, 0x00000000, 0x00101556, 0x00000000, 0x00208e46, |
| | | 0x00000000, 0x00000001, 0x0a000032, 0x001000f2, 0x00000000, 0x00101006, |
| | | 0x00000000, 0x00208e46, 0x00000000, 0x00000000, 0x00100e46, 0x00000000, |
| | | 0x0a000032, 0x001000f2, 0x00000000, 0x00101aa6, 0x00000000, 0x00208e46, |
| | | 0x00000000, 0x00000002, 0x00100e46, 0x00000000, 0x08000000, 0x001000f2, |
| | | 0x00000000, 0x00100e46, 0x00000000, 0x00208e46, 0x00000000, 0x00000003, |
| | | 0x08000038, 0x001000f2, 0x00000001, 0x00100556, 0x00000000, 0x00208e46, |
| | | 0x00000000, 0x00000005, 0x0a000032, 0x001000f2, 0x00000001, 0x00100006, |
| | | 0x00000000, 0x00208e46, 0x00000000, 0x00000004, 0x00100e46, 0x00000001, |
| | | 0x0a000032, 0x001000f2, 0x00000001, 0x00100aa6, 0x00000000, 0x00208e46, |
| | | 0x00000000, 0x00000006, 0x00100e46, 0x00000001, 0x0a000032, 0x001020f2, |
| | | 0x00000000, 0x00100ff6, 0x00000000, 0x00208e46, 0x00000000, 0x00000007, |
| | | 0x00100e46, 0x00000001, 0x05000036, 0x00102032, 0x00000001, 0x00101046, |
| | | 0x00000001, 0x05000036, 0x001020f2, 0x00000002, 0x00101e46, 0x00000002, |
| | | 0x0100003e, 0x54415453, 0x00000074, 0x0000000b, 0x00000002, 0x00000000, |
| | | 0x00000006, 0x00000003, 0x00000000, 0x00000000, 0x00000001, 0x00000000, |
| | | 0x00000000, 0x00000000, 0x00000000, 0x00000000, 0x00000000, 0x00000000, |
| | | 0x00000000, 0x00000000, 0x00000000, 0x00000000, 0x00000003, 0x00000000, |
| | | 0x00000000, 0x00000000, 0x00000000, 0x00000000, 0x00000000, 0x00000000, |
| | | 0x00000000, 0x00000000, 0x46454452, 0x000000fc, 0x00000001, 0x00000054, |
| | | 0x00000001, 0x0000001c, 0xfffe0400, 0x00000100, 0x000000c6, 0x0000003c, |
| | | 0x00000000, 0x00000000, 0x00000000, 0x00000000, 0x00000000, 0x00000001, |
| | | 0x00000001, 0x74726556, 0x68537865, 0x72656461, 0x736e6f43, 0x746e6174, |
| | | 0xabab0073, 0x0000003c, 0x00000002, 0x0000006c, 0x00000080, 0x00000000, |
| | | 0x00000000, 0x0000009c, 0x00000000, 0x00000040, 0x00000002, 0x000000a4, |
| | | 0x00000000, 0x000000b4, 0x00000040, 0x00000040, 0x00000002, 0x000000a4, |
| | | 0x00000000, 0x65646f6d, 0xabab006c, 0x00030002, 0x00040004, 0x00000000, |
| | | 0x00000000, 0x6a6f7270, 0x69746365, 0x6e416e6f, 0x65695664, 0x694d0077, |
| | | 0x736f7263, 0x2074666f, 0x20295228, 0x4c534c48, 0x61685320, 0x20726564, |
| | | 0x706d6f43, 0x72656c69, 0x332e3920, 0x32392e30, 0x312e3030, 0x34383336, |
| | | 0xababab00, 0x4e475349, 0x00000068, 0x00000003, 0x00000008, 0x00000050, |
| | | 0x00000000, 0x00000000, 0x00000003, 0x00000000, 0x00000707, 0x00000059, |
| | | 0x00000000, 0x00000000, 0x00000003, 0x00000001, 0x00000303, 0x00000062, |
| | | 0x00000000, 0x00000000, 0x00000003, 0x00000002, 0x00000f0f, 0x49534f50, |
| | | 0x4e4f4954, 0x58455400, 0x524f4f43, 0x4f430044, 0x00524f4c, 0x4e47534f, |
| | | 0x0000006c, 0x00000003, 0x00000008, 0x00000050, 0x00000000, 0x00000001, |
| | | 0x00000003, 0x00000000, 0x0000000f, 0x0000005c, 0x00000000, 0x00000000, |
| | | 0x00000003, 0x00000001, 0x00000c03, 0x00000065, 0x00000000, 0x00000000, |
| | | 0x00000003, 0x00000002, 0x0000000f, 0x505f5653, 0x5449534f, 0x004e4f49, |
| | | 0x43584554, 0x44524f4f, 0x4c4f4300, 0xab00524f |
| | | }; |
| | | #else |
| | | #error "An appropriate vertex shader is not defined." |
| | | #ifdef __GNUC__ |
| | | #pragma GCC diagnostic pop |
| | | #endif |
| | | |
| | | |
| | |
| | | static SDL_Renderer *D3D11_CreateRenderer(SDL_Window * window, Uint32 flags); |
| | | static void D3D11_WindowEvent(SDL_Renderer * renderer, |
| | | const SDL_WindowEvent *event); |
| | | static SDL_bool D3D11_SupportsBlendMode(SDL_Renderer * renderer, SDL_BlendMode blendMode); |
| | | static int D3D11_CreateTexture(SDL_Renderer * renderer, SDL_Texture * texture); |
| | | static int D3D11_UpdateTexture(SDL_Renderer * renderer, SDL_Texture * texture, |
| | | const SDL_Rect * rect, const void *srcPixels, |
| | |
| | | SDL_RENDERER_PRESENTVSYNC | |
| | | SDL_RENDERER_TARGETTEXTURE |
| | | ), /* flags. see SDL_RendererFlags */ |
| | | 4, /* num_texture_formats */ |
| | | 6, /* num_texture_formats */ |
| | | { /* texture_formats */ |
| | | SDL_PIXELFORMAT_ARGB8888, |
| | | SDL_PIXELFORMAT_RGB888, |
| | | SDL_PIXELFORMAT_YV12, |
| | | SDL_PIXELFORMAT_IYUV |
| | | SDL_PIXELFORMAT_IYUV, |
| | | SDL_PIXELFORMAT_NV12, |
| | | SDL_PIXELFORMAT_NV21 |
| | | }, |
| | | 0, /* max_texture_width: will be filled in later */ |
| | | 0 /* max_texture_height: will be filled in later */ |
| | |
| | | }; |
| | | |
| | | |
| | | static Uint32 |
| | | DXGIFormatToSDLPixelFormat(DXGI_FORMAT dxgiFormat) { |
| | | Uint32 |
| | | D3D11_DXGIFormatToSDLPixelFormat(DXGI_FORMAT dxgiFormat) |
| | | { |
| | | switch (dxgiFormat) { |
| | | case DXGI_FORMAT_B8G8R8A8_UNORM: |
| | | return SDL_PIXELFORMAT_ARGB8888; |
| | |
| | | return DXGI_FORMAT_B8G8R8X8_UNORM; |
| | | case SDL_PIXELFORMAT_YV12: |
| | | case SDL_PIXELFORMAT_IYUV: |
| | | case SDL_PIXELFORMAT_NV12: /* For the Y texture */ |
| | | case SDL_PIXELFORMAT_NV21: /* For the Y texture */ |
| | | return DXGI_FORMAT_R8_UNORM; |
| | | default: |
| | | return DXGI_FORMAT_UNKNOWN; |
| | |
| | | } |
| | | |
| | | renderer->WindowEvent = D3D11_WindowEvent; |
| | | renderer->SupportsBlendMode = D3D11_SupportsBlendMode; |
| | | renderer->CreateTexture = D3D11_CreateTexture; |
| | | renderer->UpdateTexture = D3D11_UpdateTexture; |
| | | renderer->UpdateTextureYUV = D3D11_UpdateTextureYUV; |
| | |
| | | renderer->info.flags = (SDL_RENDERER_ACCELERATED | SDL_RENDERER_TARGETTEXTURE); |
| | | renderer->driverdata = data; |
| | | |
| | | #if WINAPI_FAMILY == WINAPI_FAMILY_PHONE_APP |
| | | /* VSync is required in Windows Phone, at least for Win Phone 8.0 and 8.1. |
| | | * Failure to use it seems to either result in: |
| | | * |
| | | * - with the D3D11 debug runtime turned OFF, vsync seemingly gets turned |
| | | * off (framerate doesn't get capped), but nothing appears on-screen |
| | | * |
| | | * - with the D3D11 debug runtime turned ON, vsync gets automatically |
| | | * turned back on, and the following gets output to the debug console: |
| | | * |
| | | * DXGI ERROR: IDXGISwapChain::Present: Interval 0 is not supported, changed to Interval 1. [ UNKNOWN ERROR #1024: ] |
| | | */ |
| | | renderer->info.flags |= SDL_RENDERER_PRESENTVSYNC; |
| | | #else |
| | | if ((flags & SDL_RENDERER_PRESENTVSYNC)) { |
| | | renderer->info.flags |= SDL_RENDERER_PRESENTVSYNC; |
| | | } |
| | | #endif |
| | | |
| | | /* HACK: make sure the SDL_Renderer references the SDL_Window data now, in |
| | | * order to give init functions access to the underlying window handle: |
| | |
| | | } |
| | | |
| | | static void |
| | | D3D11_DestroyRenderer(SDL_Renderer * renderer) |
| | | D3D11_ReleaseAll(SDL_Renderer * renderer) |
| | | { |
| | | D3D11_RenderData *data = (D3D11_RenderData *) renderer->driverdata; |
| | | SDL_Texture *texture = NULL; |
| | | |
| | | /* Release all textures */ |
| | | for (texture = renderer->textures; texture; texture = texture->next) { |
| | | D3D11_DestroyTexture(renderer, texture); |
| | | } |
| | | |
| | | /* Release/reset everything else */ |
| | | if (data) { |
| | | int i; |
| | | |
| | | SAFE_RELEASE(data->dxgiFactory); |
| | | SAFE_RELEASE(data->dxgiAdapter); |
| | | SAFE_RELEASE(data->d3dDevice); |
| | |
| | | SAFE_RELEASE(data->inputLayout); |
| | | SAFE_RELEASE(data->vertexBuffer); |
| | | SAFE_RELEASE(data->vertexShader); |
| | | SAFE_RELEASE(data->colorPixelShader); |
| | | SAFE_RELEASE(data->texturePixelShader); |
| | | SAFE_RELEASE(data->yuvPixelShader); |
| | | SAFE_RELEASE(data->blendModeBlend); |
| | | SAFE_RELEASE(data->blendModeAdd); |
| | | SAFE_RELEASE(data->blendModeMod); |
| | | for (i = 0; i < SDL_arraysize(data->pixelShaders); ++i) { |
| | | SAFE_RELEASE(data->pixelShaders[i]); |
| | | } |
| | | if (data->blendModesCount > 0) { |
| | | for (i = 0; i < data->blendModesCount; ++i) { |
| | | SAFE_RELEASE(data->blendModes[i].blendState); |
| | | } |
| | | SDL_free(data->blendModes); |
| | | |
| | | data->blendModesCount = 0; |
| | | } |
| | | SAFE_RELEASE(data->nearestPixelSampler); |
| | | SAFE_RELEASE(data->linearSampler); |
| | | SAFE_RELEASE(data->mainRasterizer); |
| | | SAFE_RELEASE(data->clippedRasterizer); |
| | | SAFE_RELEASE(data->vertexShaderConstants); |
| | | |
| | | data->swapEffect = (DXGI_SWAP_EFFECT) 0; |
| | | data->rotation = DXGI_MODE_ROTATION_UNSPECIFIED; |
| | | data->currentRenderTargetView = NULL; |
| | | data->currentRasterizerState = NULL; |
| | | data->currentBlendState = NULL; |
| | | data->currentShader = NULL; |
| | | data->currentShaderResource = NULL; |
| | | data->currentSampler = NULL; |
| | | |
| | | /* Unload the D3D libraries. This should be done last, in order |
| | | * to prevent IUnknown::Release() calls from crashing. |
| | | */ |
| | | if (data->hD3D11Mod) { |
| | | SDL_UnloadObject(data->hD3D11Mod); |
| | | data->hD3D11Mod = NULL; |
| | | } |
| | | if (data->hDXGIMod) { |
| | | SDL_UnloadObject(data->hDXGIMod); |
| | | data->hDXGIMod = NULL; |
| | | } |
| | | } |
| | | } |
| | | |
| | | static void |
| | | D3D11_DestroyRenderer(SDL_Renderer * renderer) |
| | | { |
| | | D3D11_RenderData *data = (D3D11_RenderData *) renderer->driverdata; |
| | | D3D11_ReleaseAll(renderer); |
| | | if (data) { |
| | | SDL_free(data); |
| | | } |
| | | SDL_free(renderer); |
| | | } |
| | | |
| | | static HRESULT |
| | | D3D11_CreateBlendMode(SDL_Renderer * renderer, |
| | | BOOL enableBlending, |
| | | D3D11_BLEND srcBlend, |
| | | D3D11_BLEND destBlend, |
| | | D3D11_BLEND srcBlendAlpha, |
| | | D3D11_BLEND destBlendAlpha, |
| | | ID3D11BlendState ** blendStateOutput) |
| | | static D3D11_BLEND GetBlendFunc(SDL_BlendFactor factor) |
| | | { |
| | | switch (factor) { |
| | | case SDL_BLENDFACTOR_ZERO: |
| | | return D3D11_BLEND_ZERO; |
| | | case SDL_BLENDFACTOR_ONE: |
| | | return D3D11_BLEND_ONE; |
| | | case SDL_BLENDFACTOR_SRC_COLOR: |
| | | return D3D11_BLEND_SRC_COLOR; |
| | | case SDL_BLENDFACTOR_ONE_MINUS_SRC_COLOR: |
| | | return D3D11_BLEND_INV_SRC_COLOR; |
| | | case SDL_BLENDFACTOR_SRC_ALPHA: |
| | | return D3D11_BLEND_SRC_ALPHA; |
| | | case SDL_BLENDFACTOR_ONE_MINUS_SRC_ALPHA: |
| | | return D3D11_BLEND_INV_SRC_ALPHA; |
| | | case SDL_BLENDFACTOR_DST_COLOR: |
| | | return D3D11_BLEND_DEST_COLOR; |
| | | case SDL_BLENDFACTOR_ONE_MINUS_DST_COLOR: |
| | | return D3D11_BLEND_INV_DEST_COLOR; |
| | | case SDL_BLENDFACTOR_DST_ALPHA: |
| | | return D3D11_BLEND_DEST_ALPHA; |
| | | case SDL_BLENDFACTOR_ONE_MINUS_DST_ALPHA: |
| | | return D3D11_BLEND_INV_DEST_ALPHA; |
| | | default: |
| | | return (D3D11_BLEND)0; |
| | | } |
| | | } |
| | | |
| | | static D3D11_BLEND_OP GetBlendEquation(SDL_BlendOperation operation) |
| | | { |
| | | switch (operation) { |
| | | case SDL_BLENDOPERATION_ADD: |
| | | return D3D11_BLEND_OP_ADD; |
| | | case SDL_BLENDOPERATION_SUBTRACT: |
| | | return D3D11_BLEND_OP_SUBTRACT; |
| | | case SDL_BLENDOPERATION_REV_SUBTRACT: |
| | | return D3D11_BLEND_OP_REV_SUBTRACT; |
| | | case SDL_BLENDOPERATION_MINIMUM: |
| | | return D3D11_BLEND_OP_MIN; |
| | | case SDL_BLENDOPERATION_MAXIMUM: |
| | | return D3D11_BLEND_OP_MAX; |
| | | default: |
| | | return (D3D11_BLEND_OP)0; |
| | | } |
| | | } |
| | | |
| | | static SDL_bool |
| | | D3D11_CreateBlendState(SDL_Renderer * renderer, SDL_BlendMode blendMode) |
| | | { |
| | | D3D11_RenderData *data = (D3D11_RenderData *) renderer->driverdata; |
| | | SDL_BlendFactor srcColorFactor = SDL_GetBlendModeSrcColorFactor(blendMode); |
| | | SDL_BlendFactor srcAlphaFactor = SDL_GetBlendModeSrcAlphaFactor(blendMode); |
| | | SDL_BlendOperation colorOperation = SDL_GetBlendModeColorOperation(blendMode); |
| | | SDL_BlendFactor dstColorFactor = SDL_GetBlendModeDstColorFactor(blendMode); |
| | | SDL_BlendFactor dstAlphaFactor = SDL_GetBlendModeDstAlphaFactor(blendMode); |
| | | SDL_BlendOperation alphaOperation = SDL_GetBlendModeAlphaOperation(blendMode); |
| | | ID3D11BlendState *blendState = NULL; |
| | | D3D11_BlendMode *blendModes; |
| | | HRESULT result = S_OK; |
| | | |
| | | D3D11_BLEND_DESC blendDesc; |
| | | SDL_zero(blendDesc); |
| | | blendDesc.AlphaToCoverageEnable = FALSE; |
| | | blendDesc.IndependentBlendEnable = FALSE; |
| | | blendDesc.RenderTarget[0].BlendEnable = enableBlending; |
| | | blendDesc.RenderTarget[0].SrcBlend = srcBlend; |
| | | blendDesc.RenderTarget[0].DestBlend = destBlend; |
| | | blendDesc.RenderTarget[0].BlendOp = D3D11_BLEND_OP_ADD; |
| | | blendDesc.RenderTarget[0].SrcBlendAlpha = srcBlendAlpha; |
| | | blendDesc.RenderTarget[0].DestBlendAlpha = destBlendAlpha; |
| | | blendDesc.RenderTarget[0].BlendOpAlpha = D3D11_BLEND_OP_ADD; |
| | | blendDesc.RenderTarget[0].BlendEnable = TRUE; |
| | | blendDesc.RenderTarget[0].SrcBlend = GetBlendFunc(srcColorFactor); |
| | | blendDesc.RenderTarget[0].DestBlend = GetBlendFunc(dstColorFactor); |
| | | blendDesc.RenderTarget[0].BlendOp = GetBlendEquation(colorOperation); |
| | | blendDesc.RenderTarget[0].SrcBlendAlpha = GetBlendFunc(srcAlphaFactor); |
| | | blendDesc.RenderTarget[0].DestBlendAlpha = GetBlendFunc(dstAlphaFactor); |
| | | blendDesc.RenderTarget[0].BlendOpAlpha = GetBlendEquation(alphaOperation); |
| | | blendDesc.RenderTarget[0].RenderTargetWriteMask = D3D11_COLOR_WRITE_ENABLE_ALL; |
| | | result = ID3D11Device_CreateBlendState(data->d3dDevice, &blendDesc, blendStateOutput); |
| | | result = ID3D11Device_CreateBlendState(data->d3dDevice, &blendDesc, &blendState); |
| | | if (FAILED(result)) { |
| | | WIN_SetErrorFromHRESULT(__FUNCTION__ ", ID3D11Device1::CreateBlendState", result); |
| | | return result; |
| | | WIN_SetErrorFromHRESULT(SDL_COMPOSE_ERROR("ID3D11Device1::CreateBlendState"), result); |
| | | return SDL_FALSE; |
| | | } |
| | | |
| | | return S_OK; |
| | | blendModes = (D3D11_BlendMode *)SDL_realloc(data->blendModes, (data->blendModesCount + 1) * sizeof(*blendModes)); |
| | | if (!blendModes) { |
| | | SAFE_RELEASE(blendState); |
| | | SDL_OutOfMemory(); |
| | | return SDL_FALSE; |
| | | } |
| | | blendModes[data->blendModesCount].blendMode = blendMode; |
| | | blendModes[data->blendModesCount].blendState = blendState; |
| | | data->blendModes = blendModes; |
| | | ++data->blendModesCount; |
| | | |
| | | return SDL_TRUE; |
| | | } |
| | | |
| | | /* Create resources that depend on the device. */ |
| | |
| | | PFN_CREATE_DXGI_FACTORY CreateDXGIFactoryFunc; |
| | | D3D11_RenderData *data = (D3D11_RenderData *) renderer->driverdata; |
| | | PFN_D3D11_CREATE_DEVICE D3D11CreateDeviceFunc; |
| | | IDXGIAdapter *d3dAdapter = NULL; |
| | | ID3D11Device *d3dDevice = NULL; |
| | | ID3D11DeviceContext *d3dContext = NULL; |
| | | IDXGIDevice1 *dxgiDevice = NULL; |
| | | HRESULT result = S_OK; |
| | | UINT creationFlags; |
| | | const char *hint; |
| | | int i; |
| | | |
| | | /* This array defines the set of DirectX hardware feature levels this app will support. |
| | | * Note the ordering should be preserved. |
| | |
| | | D3D_FEATURE_LEVEL_9_3, |
| | | D3D_FEATURE_LEVEL_9_2, |
| | | D3D_FEATURE_LEVEL_9_1 |
| | | }; |
| | | |
| | | /* Declare how the input layout for SDL's vertex shader will be setup: */ |
| | | const D3D11_INPUT_ELEMENT_DESC vertexDesc[] = |
| | | { |
| | | { "POSITION", 0, DXGI_FORMAT_R32G32B32_FLOAT, 0, 0, D3D11_INPUT_PER_VERTEX_DATA, 0 }, |
| | | { "TEXCOORD", 0, DXGI_FORMAT_R32G32_FLOAT, 0, 12, D3D11_INPUT_PER_VERTEX_DATA, 0 }, |
| | | { "COLOR", 0, DXGI_FORMAT_R32G32B32A32_FLOAT, 0, 20, D3D11_INPUT_PER_VERTEX_DATA, 0 }, |
| | | }; |
| | | |
| | | D3D11_BUFFER_DESC constantBufferDesc; |
| | |
| | | } |
| | | #endif /* __WINRT__ */ |
| | | |
| | | result = CreateDXGIFactoryFunc(&IID_IDXGIFactory2, &data->dxgiFactory); |
| | | result = CreateDXGIFactoryFunc(&SDL_IID_IDXGIFactory2, (void **)&data->dxgiFactory); |
| | | if (FAILED(result)) { |
| | | WIN_SetErrorFromHRESULT(__FUNCTION__ ", CreateDXGIFactory", result); |
| | | WIN_SetErrorFromHRESULT(SDL_COMPOSE_ERROR("CreateDXGIFactory"), result); |
| | | goto done; |
| | | } |
| | | |
| | | /* FIXME: Should we use the default adapter? */ |
| | | result = IDXGIFactory2_EnumAdapters(data->dxgiFactory, 0, &data->dxgiAdapter); |
| | | if (FAILED(result)) { |
| | | WIN_SetErrorFromHRESULT(__FUNCTION__ ", D3D11CreateDevice", result); |
| | | WIN_SetErrorFromHRESULT(SDL_COMPOSE_ERROR("D3D11CreateDevice"), result); |
| | | goto done; |
| | | } |
| | | |
| | |
| | | creationFlags = D3D11_CREATE_DEVICE_BGRA_SUPPORT; |
| | | |
| | | /* Make sure Direct3D's debugging feature gets used, if the app requests it. */ |
| | | hint = SDL_GetHint(SDL_HINT_RENDER_DIRECT3D11_DEBUG); |
| | | if (hint && SDL_atoi(hint) > 0) { |
| | | if (SDL_GetHintBoolean(SDL_HINT_RENDER_DIRECT3D11_DEBUG, SDL_FALSE)) { |
| | | creationFlags |= D3D11_CREATE_DEVICE_DEBUG; |
| | | } |
| | | |
| | |
| | | &d3dContext /* Returns the device immediate context. */ |
| | | ); |
| | | if (FAILED(result)) { |
| | | WIN_SetErrorFromHRESULT(__FUNCTION__ ", D3D11CreateDevice", result); |
| | | WIN_SetErrorFromHRESULT(SDL_COMPOSE_ERROR("D3D11CreateDevice"), result); |
| | | goto done; |
| | | } |
| | | |
| | | result = ID3D11Device_QueryInterface(d3dDevice, &IID_ID3D11Device1, &data->d3dDevice); |
| | | result = ID3D11Device_QueryInterface(d3dDevice, &SDL_IID_ID3D11Device1, (void **)&data->d3dDevice); |
| | | if (FAILED(result)) { |
| | | WIN_SetErrorFromHRESULT(__FUNCTION__ ", ID3D11Device to ID3D11Device1", result); |
| | | WIN_SetErrorFromHRESULT(SDL_COMPOSE_ERROR("ID3D11Device to ID3D11Device1"), result); |
| | | goto done; |
| | | } |
| | | |
| | | result = ID3D11DeviceContext_QueryInterface(d3dContext, &IID_ID3D11DeviceContext1, &data->d3dContext); |
| | | result = ID3D11DeviceContext_QueryInterface(d3dContext, &SDL_IID_ID3D11DeviceContext1, (void **)&data->d3dContext); |
| | | if (FAILED(result)) { |
| | | WIN_SetErrorFromHRESULT(__FUNCTION__ ", ID3D11DeviceContext to ID3D11DeviceContext1", result); |
| | | WIN_SetErrorFromHRESULT(SDL_COMPOSE_ERROR("ID3D11DeviceContext to ID3D11DeviceContext1"), result); |
| | | goto done; |
| | | } |
| | | |
| | | result = ID3D11Device_QueryInterface(d3dDevice, &IID_IDXGIDevice1, &dxgiDevice); |
| | | result = ID3D11Device_QueryInterface(d3dDevice, &SDL_IID_IDXGIDevice1, (void **)&dxgiDevice); |
| | | if (FAILED(result)) { |
| | | WIN_SetErrorFromHRESULT(__FUNCTION__ ", ID3D11Device to IDXGIDevice1", result); |
| | | WIN_SetErrorFromHRESULT(SDL_COMPOSE_ERROR("ID3D11Device to IDXGIDevice1"), result); |
| | | goto done; |
| | | } |
| | | |
| | |
| | | */ |
| | | result = IDXGIDevice1_SetMaximumFrameLatency(dxgiDevice, 1); |
| | | if (FAILED(result)) { |
| | | WIN_SetErrorFromHRESULT(__FUNCTION__ ", IDXGIDevice1::SetMaximumFrameLatency", result); |
| | | WIN_SetErrorFromHRESULT(SDL_COMPOSE_ERROR("IDXGIDevice1::SetMaximumFrameLatency"), result); |
| | | goto done; |
| | | } |
| | | |
| | |
| | | break; |
| | | |
| | | default: |
| | | SDL_SetError(__FUNCTION__ ", Unexpected feature level: %d", data->featureLevel); |
| | | SDL_SetError("%s, Unexpected feature level: %d", __FUNCTION__, data->featureLevel); |
| | | result = E_FAIL; |
| | | goto done; |
| | | } |
| | | |
| | | /* Load in SDL's one and only vertex shader: */ |
| | | result = ID3D11Device_CreateVertexShader(data->d3dDevice, |
| | | D3D11_VertexShader, |
| | | sizeof(D3D11_VertexShader), |
| | | NULL, |
| | | &data->vertexShader |
| | | ); |
| | | if (FAILED(result)) { |
| | | WIN_SetErrorFromHRESULT(__FUNCTION__ ", ID3D11Device1::CreateVertexShader", result); |
| | | if (D3D11_CreateVertexShader(data->d3dDevice, &data->vertexShader, &data->inputLayout) < 0) { |
| | | goto done; |
| | | } |
| | | |
| | | /* Create an input layout for SDL's vertex shader: */ |
| | | result = ID3D11Device_CreateInputLayout(data->d3dDevice, |
| | | vertexDesc, |
| | | ARRAYSIZE(vertexDesc), |
| | | D3D11_VertexShader, |
| | | sizeof(D3D11_VertexShader), |
| | | &data->inputLayout |
| | | ); |
| | | if (FAILED(result)) { |
| | | WIN_SetErrorFromHRESULT(__FUNCTION__ ", ID3D11Device1::CreateInputLayout", result); |
| | | goto done; |
| | | } |
| | | |
| | | /* Load in SDL's pixel shaders */ |
| | | result = ID3D11Device_CreatePixelShader(data->d3dDevice, |
| | | D3D11_PixelShader_Colors, |
| | | sizeof(D3D11_PixelShader_Colors), |
| | | NULL, |
| | | &data->colorPixelShader |
| | | ); |
| | | if (FAILED(result)) { |
| | | WIN_SetErrorFromHRESULT(__FUNCTION__ ", ID3D11Device1::CreatePixelShader ['color' shader]", result); |
| | | goto done; |
| | | } |
| | | |
| | | result = ID3D11Device_CreatePixelShader(data->d3dDevice, |
| | | D3D11_PixelShader_Textures, |
| | | sizeof(D3D11_PixelShader_Textures), |
| | | NULL, |
| | | &data->texturePixelShader |
| | | ); |
| | | if (FAILED(result)) { |
| | | WIN_SetErrorFromHRESULT(__FUNCTION__ ", ID3D11Device1::CreatePixelShader ['textures' shader]", result); |
| | | goto done; |
| | | } |
| | | |
| | | result = ID3D11Device_CreatePixelShader(data->d3dDevice, |
| | | D3D11_PixelShader_YUV, |
| | | sizeof(D3D11_PixelShader_YUV), |
| | | NULL, |
| | | &data->yuvPixelShader |
| | | ); |
| | | if (FAILED(result)) { |
| | | WIN_SetErrorFromHRESULT(__FUNCTION__ ", ID3D11Device1::CreatePixelShader ['yuv' shader]", result); |
| | | goto done; |
| | | for (i = 0; i < SDL_arraysize(data->pixelShaders); ++i) { |
| | | if (D3D11_CreatePixelShader(data->d3dDevice, (D3D11_Shader)i, &data->pixelShaders[i]) < 0) { |
| | | goto done; |
| | | } |
| | | } |
| | | |
| | | /* Setup space to hold vertex shader constants: */ |
| | |
| | | &data->vertexShaderConstants |
| | | ); |
| | | if (FAILED(result)) { |
| | | WIN_SetErrorFromHRESULT(__FUNCTION__ ", ID3D11Device1::CreateBuffer [vertex shader constants]", result); |
| | | WIN_SetErrorFromHRESULT(SDL_COMPOSE_ERROR("ID3D11Device1::CreateBuffer [vertex shader constants]"), result); |
| | | goto done; |
| | | } |
| | | |
| | |
| | | &data->nearestPixelSampler |
| | | ); |
| | | if (FAILED(result)) { |
| | | WIN_SetErrorFromHRESULT(__FUNCTION__ ", ID3D11Device1::CreateSamplerState [nearest-pixel filter]", result); |
| | | WIN_SetErrorFromHRESULT(SDL_COMPOSE_ERROR("ID3D11Device1::CreateSamplerState [nearest-pixel filter]"), result); |
| | | goto done; |
| | | } |
| | | |
| | |
| | | &data->linearSampler |
| | | ); |
| | | if (FAILED(result)) { |
| | | WIN_SetErrorFromHRESULT(__FUNCTION__ ", ID3D11Device1::CreateSamplerState [linear filter]", result); |
| | | WIN_SetErrorFromHRESULT(SDL_COMPOSE_ERROR("ID3D11Device1::CreateSamplerState [linear filter]"), result); |
| | | goto done; |
| | | } |
| | | |
| | |
| | | rasterDesc.SlopeScaledDepthBias = 0.0f; |
| | | result = ID3D11Device_CreateRasterizerState(data->d3dDevice, &rasterDesc, &data->mainRasterizer); |
| | | if (FAILED(result)) { |
| | | WIN_SetErrorFromHRESULT(__FUNCTION__ ", ID3D11Device1::CreateRasterizerState [main rasterizer]", result); |
| | | WIN_SetErrorFromHRESULT(SDL_COMPOSE_ERROR("ID3D11Device1::CreateRasterizerState [main rasterizer]"), result); |
| | | goto done; |
| | | } |
| | | |
| | | rasterDesc.ScissorEnable = TRUE; |
| | | result = ID3D11Device_CreateRasterizerState(data->d3dDevice, &rasterDesc, &data->clippedRasterizer); |
| | | if (FAILED(result)) { |
| | | WIN_SetErrorFromHRESULT(__FUNCTION__ ", ID3D11Device1::CreateRasterizerState [clipped rasterizer]", result); |
| | | WIN_SetErrorFromHRESULT(SDL_COMPOSE_ERROR("ID3D11Device1::CreateRasterizerState [clipped rasterizer]"), result); |
| | | goto done; |
| | | } |
| | | |
| | | /* Create blending states: */ |
| | | result = D3D11_CreateBlendMode( |
| | | renderer, |
| | | TRUE, |
| | | D3D11_BLEND_SRC_ALPHA, /* srcBlend */ |
| | | D3D11_BLEND_INV_SRC_ALPHA, /* destBlend */ |
| | | D3D11_BLEND_ONE, /* srcBlendAlpha */ |
| | | D3D11_BLEND_INV_SRC_ALPHA, /* destBlendAlpha */ |
| | | &data->blendModeBlend); |
| | | if (FAILED(result)) { |
| | | /* D3D11_CreateBlendMode will set the SDL error, if it fails */ |
| | | goto done; |
| | | } |
| | | |
| | | result = D3D11_CreateBlendMode( |
| | | renderer, |
| | | TRUE, |
| | | D3D11_BLEND_SRC_ALPHA, /* srcBlend */ |
| | | D3D11_BLEND_ONE, /* destBlend */ |
| | | D3D11_BLEND_ZERO, /* srcBlendAlpha */ |
| | | D3D11_BLEND_ONE, /* destBlendAlpha */ |
| | | &data->blendModeAdd); |
| | | if (FAILED(result)) { |
| | | /* D3D11_CreateBlendMode will set the SDL error, if it fails */ |
| | | goto done; |
| | | } |
| | | |
| | | result = D3D11_CreateBlendMode( |
| | | renderer, |
| | | TRUE, |
| | | D3D11_BLEND_ZERO, /* srcBlend */ |
| | | D3D11_BLEND_SRC_COLOR, /* destBlend */ |
| | | D3D11_BLEND_ZERO, /* srcBlendAlpha */ |
| | | D3D11_BLEND_ONE, /* destBlendAlpha */ |
| | | &data->blendModeMod); |
| | | if (FAILED(result)) { |
| | | if (!D3D11_CreateBlendState(renderer, SDL_BLENDMODE_BLEND) || |
| | | !D3D11_CreateBlendState(renderer, SDL_BLENDMODE_ADD) || |
| | | !D3D11_CreateBlendState(renderer, SDL_BLENDMODE_MOD)) { |
| | | /* D3D11_CreateBlendMode will set the SDL error, if it fails */ |
| | | goto done; |
| | | } |
| | |
| | | } |
| | | |
| | | static int |
| | | D3D11_GetViewportAlignedD3DRect(SDL_Renderer * renderer, const SDL_Rect * sdlRect, D3D11_RECT * outRect) |
| | | D3D11_GetRotationForCurrentRenderTarget(SDL_Renderer * renderer) |
| | | { |
| | | D3D11_RenderData *data = (D3D11_RenderData *) renderer->driverdata; |
| | | switch (data->rotation) { |
| | | D3D11_RenderData *data = (D3D11_RenderData *)renderer->driverdata; |
| | | if (data->currentOffscreenRenderTargetView) { |
| | | return DXGI_MODE_ROTATION_IDENTITY; |
| | | } else { |
| | | return data->rotation; |
| | | } |
| | | } |
| | | |
| | | static int |
| | | D3D11_GetViewportAlignedD3DRect(SDL_Renderer * renderer, const SDL_Rect * sdlRect, D3D11_RECT * outRect, BOOL includeViewportOffset) |
| | | { |
| | | const int rotation = D3D11_GetRotationForCurrentRenderTarget(renderer); |
| | | switch (rotation) { |
| | | case DXGI_MODE_ROTATION_IDENTITY: |
| | | outRect->left = sdlRect->x; |
| | | outRect->right = sdlRect->x + sdlRect->w; |
| | | outRect->top = sdlRect->y; |
| | | outRect->bottom = sdlRect->y + sdlRect->h; |
| | | if (includeViewportOffset) { |
| | | outRect->left += renderer->viewport.x; |
| | | outRect->right += renderer->viewport.x; |
| | | outRect->top += renderer->viewport.y; |
| | | outRect->bottom += renderer->viewport.y; |
| | | } |
| | | break; |
| | | case DXGI_MODE_ROTATION_ROTATE270: |
| | | outRect->left = sdlRect->y; |
| | |
| | | #if WINAPI_FAMILY == WINAPI_FAMILY_PHONE_APP |
| | | swapChainDesc.Scaling = DXGI_SCALING_STRETCH; /* On phone, only stretch and aspect-ratio stretch scaling are allowed. */ |
| | | swapChainDesc.SwapEffect = DXGI_SWAP_EFFECT_DISCARD; /* On phone, no swap effects are supported. */ |
| | | /* TODO, WinRT: see if Win 8.x DXGI_SWAP_CHAIN_DESC1 settings are available on Windows Phone 8.1, and if there's any advantage to having them on */ |
| | | #else |
| | | if (usingXAML) { |
| | | swapChainDesc.Scaling = DXGI_SCALING_STRETCH; |
| | |
| | | &data->swapChain |
| | | ); |
| | | if (FAILED(result)) { |
| | | WIN_SetErrorFromHRESULT(__FUNCTION__ ", IDXGIFactory2::CreateSwapChainForCoreWindow", result); |
| | | WIN_SetErrorFromHRESULT(SDL_COMPOSE_ERROR("IDXGIFactory2::CreateSwapChainForCoreWindow"), result); |
| | | goto done; |
| | | } |
| | | } else if (usingXAML) { |
| | |
| | | NULL, |
| | | &data->swapChain); |
| | | if (FAILED(result)) { |
| | | WIN_SetErrorFromHRESULT(__FUNCTION__ ", IDXGIFactory2::CreateSwapChainForComposition", result); |
| | | WIN_SetErrorFromHRESULT(SDL_COMPOSE_ERROR("IDXGIFactory2::CreateSwapChainForComposition"), result); |
| | | goto done; |
| | | } |
| | | |
| | | #if WINAPI_FAMILY == WINAPI_FAMILY_APP |
| | | result = ISwapChainBackgroundPanelNative_SetSwapChain(WINRT_GlobalSwapChainBackgroundPanelNative, (IDXGISwapChain *) data->swapChain); |
| | | if (FAILED(result)) { |
| | | WIN_SetErrorFromHRESULT(__FUNCTION__ ", ISwapChainBackgroundPanelNative::SetSwapChain", result); |
| | | WIN_SetErrorFromHRESULT(SDL_COMPOSE_ERROR("ISwapChainBackgroundPanelNative::SetSwapChain"), result); |
| | | goto done; |
| | | } |
| | | #else |
| | | SDL_SetError(__FUNCTION__ ", XAML support is not yet available for Windows Phone"); |
| | | SDL_SetError(SDL_COMPOSE_ERROR("XAML support is not yet available for Windows Phone")); |
| | | result = E_FAIL; |
| | | goto done; |
| | | #endif |
| | |
| | | &data->swapChain |
| | | ); |
| | | if (FAILED(result)) { |
| | | WIN_SetErrorFromHRESULT(__FUNCTION__ ", IDXGIFactory2::CreateSwapChainForHwnd", result); |
| | | WIN_SetErrorFromHRESULT(SDL_COMPOSE_ERROR("IDXGIFactory2::CreateSwapChainForHwnd"), result); |
| | | goto done; |
| | | } |
| | | |
| | | IDXGIFactory_MakeWindowAssociation(data->dxgiFactory, windowinfo.info.win.window, DXGI_MWA_NO_WINDOW_CHANGES); |
| | | #else |
| | | SDL_SetError(__FUNCTION__", Unable to find something to attach a swap chain to"); |
| | | goto done; |
| | |
| | | */ |
| | | SDL_GetWindowSize(renderer->window, &w, &h); |
| | | data->rotation = D3D11_GetCurrentRotation(); |
| | | /* SDL_Log("%s: windowSize={%d,%d}, orientation=%d\n", __FUNCTION__, w, h, (int)data->rotation); */ |
| | | if (D3D11_IsDisplayRotated90Degrees(data->rotation)) { |
| | | int tmp = w; |
| | | w = h; |
| | |
| | | DXGI_FORMAT_UNKNOWN, |
| | | 0 |
| | | ); |
| | | if (FAILED(result)) { |
| | | WIN_SetErrorFromHRESULT(__FUNCTION__ ", IDXGISwapChain::ResizeBuffers", result); |
| | | if (result == DXGI_ERROR_DEVICE_REMOVED) { |
| | | /* If the device was removed for any reason, a new device and swap chain will need to be created. */ |
| | | D3D11_HandleDeviceLost(renderer); |
| | | |
| | | /* Everything is set up now. Do not continue execution of this method. HandleDeviceLost will reenter this method |
| | | * and correctly set up the new device. |
| | | */ |
| | | goto done; |
| | | } else if (FAILED(result)) { |
| | | WIN_SetErrorFromHRESULT(SDL_COMPOSE_ERROR("IDXGISwapChain::ResizeBuffers"), result); |
| | | goto done; |
| | | } |
| | | #endif |
| | |
| | | } |
| | | |
| | | #if WINAPI_FAMILY != WINAPI_FAMILY_PHONE_APP |
| | | /* Set the proper rotation for the swap chain, and generate the |
| | | * 3D matrix transformation for rendering to the rotated swap chain. |
| | | /* Set the proper rotation for the swap chain. |
| | | * |
| | | * To note, the call for this, IDXGISwapChain1::SetRotation, is not necessary |
| | | * on Windows Phone, nor is it supported there. It's only needed in Windows 8/RT. |
| | | * on Windows Phone 8.0, nor is it supported there. |
| | | * |
| | | * IDXGISwapChain1::SetRotation does seem to be available on Windows Phone 8.1, |
| | | * however I've yet to find a way to make it work. It might have something to |
| | | * do with IDXGISwapChain::ResizeBuffers appearing to not being available on |
| | | * Windows Phone 8.1 (it wasn't on Windows Phone 8.0), but I'm not 100% sure of this. |
| | | * The call doesn't appear to be entirely necessary though, and is a performance-related |
| | | * call, at least according to the following page on MSDN: |
| | | * http://code.msdn.microsoft.com/windowsapps/DXGI-swap-chain-rotation-21d13d71 |
| | | * -- David L. |
| | | * |
| | | * TODO, WinRT: reexamine the docs for IDXGISwapChain1::SetRotation, see if might be available, usable, and prudent-to-call on WinPhone 8.1 |
| | | */ |
| | | if (data->swapEffect == DXGI_SWAP_EFFECT_FLIP_SEQUENTIAL) { |
| | | result = IDXGISwapChain1_SetRotation(data->swapChain, data->rotation); |
| | | if (FAILED(result)) { |
| | | WIN_SetErrorFromHRESULT(__FUNCTION__ ", IDXGISwapChain1::SetRotation", result); |
| | | WIN_SetErrorFromHRESULT(SDL_COMPOSE_ERROR("IDXGISwapChain1::SetRotation"), result); |
| | | goto done; |
| | | } |
| | | } |
| | |
| | | |
| | | result = IDXGISwapChain_GetBuffer(data->swapChain, |
| | | 0, |
| | | &IID_ID3D11Texture2D, |
| | | &backBuffer |
| | | &SDL_IID_ID3D11Texture2D, |
| | | (void **)&backBuffer |
| | | ); |
| | | if (FAILED(result)) { |
| | | WIN_SetErrorFromHRESULT(__FUNCTION__ ", IDXGISwapChain::GetBuffer [back-buffer]", result); |
| | | WIN_SetErrorFromHRESULT(SDL_COMPOSE_ERROR("IDXGISwapChain::GetBuffer [back-buffer]"), result); |
| | | goto done; |
| | | } |
| | | |
| | |
| | | &data->mainRenderTargetView |
| | | ); |
| | | if (FAILED(result)) { |
| | | WIN_SetErrorFromHRESULT(__FUNCTION__ ", ID3D11Device::CreateRenderTargetView", result); |
| | | WIN_SetErrorFromHRESULT(SDL_COMPOSE_ERROR("ID3D11Device::CreateRenderTargetView"), result); |
| | | goto done; |
| | | } |
| | | |
| | |
| | | static HRESULT |
| | | D3D11_UpdateForWindowSizeChange(SDL_Renderer * renderer) |
| | | { |
| | | D3D11_RenderData *data = (D3D11_RenderData *)renderer->driverdata; |
| | | return D3D11_CreateWindowSizeDependentResources(renderer); |
| | | } |
| | | |
| | | HRESULT |
| | | D3D11_HandleDeviceLost(SDL_Renderer * renderer) |
| | | { |
| | | D3D11_RenderData *data = (D3D11_RenderData *) renderer->driverdata; |
| | | HRESULT result = S_OK; |
| | | |
| | | /* FIXME: Need to release all resources - all textures are invalid! */ |
| | | D3D11_ReleaseAll(renderer); |
| | | |
| | | result = D3D11_CreateDeviceResources(renderer); |
| | | if (FAILED(result)) { |
| | |
| | | return result; |
| | | } |
| | | |
| | | /* Let the application know that the device has been reset */ |
| | | { |
| | | SDL_Event event; |
| | | event.type = SDL_RENDER_DEVICE_RESET; |
| | | SDL_PushEvent(&event); |
| | | } |
| | | |
| | | return S_OK; |
| | | } |
| | | |
| | | void |
| | | D3D11_Trim(SDL_Renderer * renderer) |
| | | { |
| | | #ifdef __WINRT__ |
| | | #if NTDDI_VERSION > NTDDI_WIN8 |
| | | D3D11_RenderData *data = (D3D11_RenderData *)renderer->driverdata; |
| | | HRESULT result = S_OK; |
| | | IDXGIDevice3 *dxgiDevice = NULL; |
| | | |
| | | result = ID3D11Device_QueryInterface(data->d3dDevice, &SDL_IID_IDXGIDevice3, &dxgiDevice); |
| | | if (FAILED(result)) { |
| | | //WIN_SetErrorFromHRESULT(__FUNCTION__ ", ID3D11Device to IDXGIDevice3", result); |
| | | return; |
| | | } |
| | | |
| | | IDXGIDevice3_Trim(dxgiDevice); |
| | | SAFE_RELEASE(dxgiDevice); |
| | | #endif |
| | | #endif |
| | | } |
| | | |
| | | static void |
| | |
| | | } |
| | | } |
| | | |
| | | static D3D11_FILTER |
| | | GetScaleQuality(void) |
| | | static SDL_bool |
| | | D3D11_SupportsBlendMode(SDL_Renderer * renderer, SDL_BlendMode blendMode) |
| | | { |
| | | const char *hint = SDL_GetHint(SDL_HINT_RENDER_SCALE_QUALITY); |
| | | if (!hint || *hint == '0' || SDL_strcasecmp(hint, "nearest") == 0) { |
| | | return D3D11_FILTER_MIN_MAG_MIP_POINT; |
| | | } else /* if (*hint == '1' || SDL_strcasecmp(hint, "linear") == 0) */ { |
| | | return D3D11_FILTER_MIN_MAG_MIP_LINEAR; |
| | | SDL_BlendFactor srcColorFactor = SDL_GetBlendModeSrcColorFactor(blendMode); |
| | | SDL_BlendFactor srcAlphaFactor = SDL_GetBlendModeSrcAlphaFactor(blendMode); |
| | | SDL_BlendOperation colorOperation = SDL_GetBlendModeColorOperation(blendMode); |
| | | SDL_BlendFactor dstColorFactor = SDL_GetBlendModeDstColorFactor(blendMode); |
| | | SDL_BlendFactor dstAlphaFactor = SDL_GetBlendModeDstAlphaFactor(blendMode); |
| | | SDL_BlendOperation alphaOperation = SDL_GetBlendModeAlphaOperation(blendMode); |
| | | |
| | | if (!GetBlendFunc(srcColorFactor) || !GetBlendFunc(srcAlphaFactor) || |
| | | !GetBlendEquation(colorOperation) || |
| | | !GetBlendFunc(dstColorFactor) || !GetBlendFunc(dstAlphaFactor) || |
| | | !GetBlendEquation(alphaOperation)) { |
| | | return SDL_FALSE; |
| | | } |
| | | return SDL_TRUE; |
| | | } |
| | | |
| | | static int |
| | |
| | | D3D11_TEXTURE2D_DESC textureDesc; |
| | | D3D11_SHADER_RESOURCE_VIEW_DESC resourceViewDesc; |
| | | |
| | | if (textureFormat == SDL_PIXELFORMAT_UNKNOWN) { |
| | | if (textureFormat == DXGI_FORMAT_UNKNOWN) { |
| | | return SDL_SetError("%s, An unsupported SDL pixel format (0x%x) was specified", |
| | | __FUNCTION__, texture->format); |
| | | } |
| | |
| | | SDL_OutOfMemory(); |
| | | return -1; |
| | | } |
| | | textureData->scaleMode = GetScaleQuality(); |
| | | textureData->scaleMode = (texture->scaleMode == SDL_ScaleModeNearest) ? D3D11_FILTER_MIN_MAG_MIP_POINT : D3D11_FILTER_MIN_MAG_MIP_LINEAR; |
| | | |
| | | texture->driverdata = textureData; |
| | | |
| | |
| | | ); |
| | | if (FAILED(result)) { |
| | | D3D11_DestroyTexture(renderer, texture); |
| | | WIN_SetErrorFromHRESULT(__FUNCTION__ ", ID3D11Device1::CreateTexture2D", result); |
| | | WIN_SetErrorFromHRESULT(SDL_COMPOSE_ERROR("ID3D11Device1::CreateTexture2D"), result); |
| | | return -1; |
| | | } |
| | | |
| | |
| | | texture->format == SDL_PIXELFORMAT_IYUV) { |
| | | textureData->yuv = SDL_TRUE; |
| | | |
| | | textureDesc.Width /= 2; |
| | | textureDesc.Height /= 2; |
| | | textureDesc.Width = (textureDesc.Width + 1) / 2; |
| | | textureDesc.Height = (textureDesc.Height + 1) / 2; |
| | | |
| | | result = ID3D11Device_CreateTexture2D(rendererData->d3dDevice, |
| | | &textureDesc, |
| | |
| | | ); |
| | | if (FAILED(result)) { |
| | | D3D11_DestroyTexture(renderer, texture); |
| | | WIN_SetErrorFromHRESULT(__FUNCTION__ ", ID3D11Device1::CreateTexture2D", result); |
| | | WIN_SetErrorFromHRESULT(SDL_COMPOSE_ERROR("ID3D11Device1::CreateTexture2D"), result); |
| | | return -1; |
| | | } |
| | | |
| | |
| | | ); |
| | | if (FAILED(result)) { |
| | | D3D11_DestroyTexture(renderer, texture); |
| | | WIN_SetErrorFromHRESULT(__FUNCTION__ ", ID3D11Device1::CreateTexture2D", result); |
| | | WIN_SetErrorFromHRESULT(SDL_COMPOSE_ERROR("ID3D11Device1::CreateTexture2D"), result); |
| | | return -1; |
| | | } |
| | | } |
| | | |
| | | if (texture->format == SDL_PIXELFORMAT_NV12 || |
| | | texture->format == SDL_PIXELFORMAT_NV21) { |
| | | D3D11_TEXTURE2D_DESC nvTextureDesc = textureDesc; |
| | | |
| | | textureData->nv12 = SDL_TRUE; |
| | | |
| | | nvTextureDesc.Format = DXGI_FORMAT_R8G8_UNORM; |
| | | nvTextureDesc.Width = (textureDesc.Width + 1) / 2; |
| | | nvTextureDesc.Height = (textureDesc.Height + 1) / 2; |
| | | |
| | | result = ID3D11Device_CreateTexture2D(rendererData->d3dDevice, |
| | | &nvTextureDesc, |
| | | NULL, |
| | | &textureData->mainTextureNV |
| | | ); |
| | | if (FAILED(result)) { |
| | | D3D11_DestroyTexture(renderer, texture); |
| | | WIN_SetErrorFromHRESULT(SDL_COMPOSE_ERROR("ID3D11Device1::CreateTexture2D"), result); |
| | | return -1; |
| | | } |
| | | } |
| | |
| | | ); |
| | | if (FAILED(result)) { |
| | | D3D11_DestroyTexture(renderer, texture); |
| | | WIN_SetErrorFromHRESULT(__FUNCTION__ "ID3D11Device1::CreateShaderResourceView", result); |
| | | WIN_SetErrorFromHRESULT(SDL_COMPOSE_ERROR("ID3D11Device1::CreateShaderResourceView"), result); |
| | | return -1; |
| | | } |
| | | |
| | |
| | | ); |
| | | if (FAILED(result)) { |
| | | D3D11_DestroyTexture(renderer, texture); |
| | | WIN_SetErrorFromHRESULT(__FUNCTION__ "ID3D11Device1::CreateShaderResourceView", result); |
| | | WIN_SetErrorFromHRESULT(SDL_COMPOSE_ERROR("ID3D11Device1::CreateShaderResourceView"), result); |
| | | return -1; |
| | | } |
| | | result = ID3D11Device_CreateShaderResourceView(rendererData->d3dDevice, |
| | |
| | | ); |
| | | if (FAILED(result)) { |
| | | D3D11_DestroyTexture(renderer, texture); |
| | | WIN_SetErrorFromHRESULT(__FUNCTION__ "ID3D11Device1::CreateShaderResourceView", result); |
| | | WIN_SetErrorFromHRESULT(SDL_COMPOSE_ERROR("ID3D11Device1::CreateShaderResourceView"), result); |
| | | return -1; |
| | | } |
| | | } |
| | | |
| | | if (textureData->nv12) { |
| | | D3D11_SHADER_RESOURCE_VIEW_DESC nvResourceViewDesc = resourceViewDesc; |
| | | |
| | | nvResourceViewDesc.Format = DXGI_FORMAT_R8G8_UNORM; |
| | | |
| | | result = ID3D11Device_CreateShaderResourceView(rendererData->d3dDevice, |
| | | (ID3D11Resource *)textureData->mainTextureNV, |
| | | &nvResourceViewDesc, |
| | | &textureData->mainTextureResourceViewNV |
| | | ); |
| | | if (FAILED(result)) { |
| | | D3D11_DestroyTexture(renderer, texture); |
| | | WIN_SetErrorFromHRESULT(SDL_COMPOSE_ERROR("ID3D11Device1::CreateShaderResourceView"), result); |
| | | return -1; |
| | | } |
| | | } |
| | |
| | | &textureData->mainTextureRenderTargetView); |
| | | if (FAILED(result)) { |
| | | D3D11_DestroyTexture(renderer, texture); |
| | | WIN_SetErrorFromHRESULT(__FUNCTION__ ", ID3D11Device1::CreateRenderTargetView", result); |
| | | WIN_SetErrorFromHRESULT(SDL_COMPOSE_ERROR("ID3D11Device1::CreateRenderTargetView"), result); |
| | | return -1; |
| | | } |
| | | } |
| | |
| | | } |
| | | |
| | | static int |
| | | D3D11_UpdateTextureInternal(D3D11_RenderData *rendererData, ID3D11Texture2D *texture, Uint32 format, int x, int y, int w, int h, const void *pixels, int pitch) |
| | | D3D11_UpdateTextureInternal(D3D11_RenderData *rendererData, ID3D11Texture2D *texture, int bpp, int x, int y, int w, int h, const void *pixels, int pitch) |
| | | { |
| | | ID3D11Texture2D *stagingTexture; |
| | | const Uint8 *src; |
| | |
| | | NULL, |
| | | &stagingTexture); |
| | | if (FAILED(result)) { |
| | | WIN_SetErrorFromHRESULT(__FUNCTION__ ", ID3D11Device1::CreateTexture2D [create staging texture]", result); |
| | | WIN_SetErrorFromHRESULT(SDL_COMPOSE_ERROR("ID3D11Device1::CreateTexture2D [create staging texture]"), result); |
| | | return -1; |
| | | } |
| | | |
| | |
| | | &textureMemory |
| | | ); |
| | | if (FAILED(result)) { |
| | | WIN_SetErrorFromHRESULT(__FUNCTION__ ", ID3D11DeviceContext1::Map [map staging texture]", result); |
| | | WIN_SetErrorFromHRESULT(SDL_COMPOSE_ERROR("ID3D11DeviceContext1::Map [map staging texture]"), result); |
| | | SAFE_RELEASE(stagingTexture); |
| | | return -1; |
| | | } |
| | | |
| | | src = (const Uint8 *)pixels; |
| | | dst = textureMemory.pData; |
| | | length = w * SDL_BYTESPERPIXEL(format); |
| | | length = w * bpp; |
| | | if (length == pitch && length == textureMemory.RowPitch) { |
| | | SDL_memcpy(dst, src, length*h); |
| | | } else { |
| | |
| | | return -1; |
| | | } |
| | | |
| | | if (D3D11_UpdateTextureInternal(rendererData, textureData->mainTexture, texture->format, rect->x, rect->y, rect->w, rect->h, srcPixels, srcPitch) < 0) { |
| | | if (D3D11_UpdateTextureInternal(rendererData, textureData->mainTexture, SDL_BYTESPERPIXEL(texture->format), rect->x, rect->y, rect->w, rect->h, srcPixels, srcPitch) < 0) { |
| | | return -1; |
| | | } |
| | | |
| | |
| | | /* Skip to the correct offset into the next texture */ |
| | | srcPixels = (const void*)((const Uint8*)srcPixels + rect->h * srcPitch); |
| | | |
| | | 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) { |
| | | if (D3D11_UpdateTextureInternal(rendererData, texture->format == SDL_PIXELFORMAT_YV12 ? textureData->mainTextureV : textureData->mainTextureU, SDL_BYTESPERPIXEL(texture->format), rect->x / 2, rect->y / 2, (rect->w + 1) / 2, (rect->h + 1) / 2, srcPixels, (srcPitch + 1) / 2) < 0) { |
| | | return -1; |
| | | } |
| | | |
| | | /* Skip to the correct offset into the next texture */ |
| | | srcPixels = (const void*)((const Uint8*)srcPixels + (rect->h * srcPitch) / 4); |
| | | 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) { |
| | | srcPixels = (const void*)((const Uint8*)srcPixels + ((rect->h + 1) / 2) * ((srcPitch + 1) / 2)); |
| | | if (D3D11_UpdateTextureInternal(rendererData, texture->format == SDL_PIXELFORMAT_YV12 ? textureData->mainTextureU : textureData->mainTextureV, SDL_BYTESPERPIXEL(texture->format), rect->x / 2, rect->y / 2, (rect->w + 1) / 2, (rect->h + 1) / 2, srcPixels, (srcPitch + 1) / 2) < 0) { |
| | | return -1; |
| | | } |
| | | } |
| | | |
| | | if (textureData->nv12) { |
| | | /* Skip to the correct offset into the next texture */ |
| | | srcPixels = (const void*)((const Uint8*)srcPixels + rect->h * srcPitch); |
| | | |
| | | if (D3D11_UpdateTextureInternal(rendererData, textureData->mainTextureNV, 2, rect->x / 2, rect->y / 2, ((rect->w + 1) / 2), (rect->h + 1) / 2, srcPixels, 2*((srcPitch + 1) / 2)) < 0) { |
| | | return -1; |
| | | } |
| | | } |
| | |
| | | return -1; |
| | | } |
| | | |
| | | if (D3D11_UpdateTextureInternal(rendererData, textureData->mainTexture, texture->format, rect->x, rect->y, rect->w, rect->h, Yplane, Ypitch) < 0) { |
| | | if (D3D11_UpdateTextureInternal(rendererData, textureData->mainTexture, SDL_BYTESPERPIXEL(texture->format), rect->x, rect->y, rect->w, rect->h, Yplane, Ypitch) < 0) { |
| | | return -1; |
| | | } |
| | | if (D3D11_UpdateTextureInternal(rendererData, textureData->mainTextureU, texture->format, rect->x / 2, rect->y / 2, rect->w / 2, rect->h / 2, Uplane, Upitch) < 0) { |
| | | if (D3D11_UpdateTextureInternal(rendererData, textureData->mainTextureU, SDL_BYTESPERPIXEL(texture->format), rect->x / 2, rect->y / 2, rect->w / 2, rect->h / 2, Uplane, Upitch) < 0) { |
| | | return -1; |
| | | } |
| | | if (D3D11_UpdateTextureInternal(rendererData, textureData->mainTextureV, texture->format, rect->x / 2, rect->y / 2, rect->w / 2, rect->h / 2, Vplane, Vpitch) < 0) { |
| | | if (D3D11_UpdateTextureInternal(rendererData, textureData->mainTextureV, SDL_BYTESPERPIXEL(texture->format), rect->x / 2, rect->y / 2, rect->w / 2, rect->h / 2, Vplane, Vpitch) < 0) { |
| | | return -1; |
| | | } |
| | | return 0; |
| | |
| | | return -1; |
| | | } |
| | | |
| | | if (textureData->yuv) { |
| | | if (textureData->yuv || textureData->nv12) { |
| | | /* It's more efficient to upload directly... */ |
| | | if (!textureData->pixels) { |
| | | textureData->pitch = texture->w; |
| | |
| | | NULL, |
| | | &textureData->stagingTexture); |
| | | if (FAILED(result)) { |
| | | WIN_SetErrorFromHRESULT(__FUNCTION__ ", ID3D11Device1::CreateTexture2D [create staging texture]", result); |
| | | WIN_SetErrorFromHRESULT(SDL_COMPOSE_ERROR("ID3D11Device1::CreateTexture2D [create staging texture]"), result); |
| | | return -1; |
| | | } |
| | | |
| | |
| | | &textureMemory |
| | | ); |
| | | if (FAILED(result)) { |
| | | WIN_SetErrorFromHRESULT(__FUNCTION__ ", ID3D11DeviceContext1::Map [map staging texture]", result); |
| | | WIN_SetErrorFromHRESULT(SDL_COMPOSE_ERROR("ID3D11DeviceContext1::Map [map staging texture]"), result); |
| | | SAFE_RELEASE(textureData->stagingTexture); |
| | | return -1; |
| | | } |
| | |
| | | return; |
| | | } |
| | | |
| | | if (textureData->yuv) { |
| | | if (textureData->yuv || textureData->nv12) { |
| | | const SDL_Rect *rect = &textureData->locked_rect; |
| | | void *pixels = |
| | | (void *) ((Uint8 *) textureData->pixels + rect->y * textureData->pitch + |
| | |
| | | SDL_FRect orientationAlignedViewport; |
| | | BOOL swapDimensions; |
| | | D3D11_VIEWPORT viewport; |
| | | const int rotation = D3D11_GetRotationForCurrentRenderTarget(renderer); |
| | | |
| | | if (renderer->viewport.w == 0 || renderer->viewport.h == 0) { |
| | | /* If the viewport is empty, assume that it is because |
| | | * SDL_CreateRenderer is calling it, and will call it again later |
| | | * with a non-empty viewport. |
| | | */ |
| | | /* SDL_Log("%s, no viewport was set!\n", __FUNCTION__); */ |
| | | return 0; |
| | | } |
| | | |
| | |
| | | * default coordinate system) so rotations will be done in the opposite |
| | | * direction of the DXGI_MODE_ROTATION enumeration. |
| | | */ |
| | | switch (data->rotation) { |
| | | switch (rotation) { |
| | | case DXGI_MODE_ROTATION_IDENTITY: |
| | | projection = MatrixIdentity(); |
| | | break; |
| | |
| | | * a landscape mode, for all Windows 8/RT devices, or a portrait mode, |
| | | * for Windows Phone devices. |
| | | */ |
| | | swapDimensions = D3D11_IsDisplayRotated90Degrees(data->rotation); |
| | | swapDimensions = D3D11_IsDisplayRotated90Degrees(rotation); |
| | | if (swapDimensions) { |
| | | orientationAlignedViewport.x = (float) renderer->viewport.y; |
| | | orientationAlignedViewport.y = (float) renderer->viewport.x; |
| | |
| | | viewport.Height = orientationAlignedViewport.h; |
| | | viewport.MinDepth = 0.0f; |
| | | viewport.MaxDepth = 1.0f; |
| | | /* SDL_Log("%s: D3D viewport = {%f,%f,%f,%f}\n", __FUNCTION__, viewport.TopLeftX, viewport.TopLeftY, viewport.Width, viewport.Height); */ |
| | | ID3D11DeviceContext_RSSetViewports(data->d3dContext, 1, &viewport); |
| | | |
| | | return 0; |
| | |
| | | D3D11_UpdateClipRect(SDL_Renderer * renderer) |
| | | { |
| | | D3D11_RenderData *data = (D3D11_RenderData *) renderer->driverdata; |
| | | const SDL_Rect *rect = &renderer->clip_rect; |
| | | |
| | | if (SDL_RectEmpty(rect)) { |
| | | if (!renderer->clipping_enabled) { |
| | | ID3D11DeviceContext_RSSetScissorRects(data->d3dContext, 0, NULL); |
| | | } else { |
| | | D3D11_RECT scissorRect; |
| | | if (D3D11_GetViewportAlignedD3DRect(renderer, rect, &scissorRect) != 0) { |
| | | if (D3D11_GetViewportAlignedD3DRect(renderer, &renderer->clip_rect, &scissorRect, TRUE) != 0) { |
| | | /* D3D11_GetViewportAlignedD3DRect will have set the SDL error */ |
| | | return -1; |
| | | } |
| | |
| | | &mappedResource |
| | | ); |
| | | if (FAILED(result)) { |
| | | WIN_SetErrorFromHRESULT(__FUNCTION__ ", ID3D11DeviceContext1::Map [vertex buffer]", result); |
| | | WIN_SetErrorFromHRESULT(SDL_COMPOSE_ERROR("ID3D11DeviceContext1::Map [vertex buffer]"), result); |
| | | return -1; |
| | | } |
| | | SDL_memcpy(mappedResource.pData, vertexData, dataSizeInBytes); |
| | |
| | | } else { |
| | | SAFE_RELEASE(rendererData->vertexBuffer); |
| | | |
| | | vertexBufferDesc.ByteWidth = dataSizeInBytes; |
| | | vertexBufferDesc.ByteWidth = (UINT) dataSizeInBytes; |
| | | vertexBufferDesc.Usage = D3D11_USAGE_DYNAMIC; |
| | | vertexBufferDesc.BindFlags = D3D11_BIND_VERTEX_BUFFER; |
| | | vertexBufferDesc.CPUAccessFlags = D3D11_CPU_ACCESS_WRITE; |
| | |
| | | &rendererData->vertexBuffer |
| | | ); |
| | | if (FAILED(result)) { |
| | | WIN_SetErrorFromHRESULT(__FUNCTION__ ", ID3D11Device1::CreateBuffer [vertex buffer]", result); |
| | | WIN_SetErrorFromHRESULT(SDL_COMPOSE_ERROR("ID3D11Device1::CreateBuffer [vertex buffer]"), result); |
| | | return -1; |
| | | } |
| | | |
| | |
| | | rendererData->currentRenderTargetView = renderTargetView; |
| | | } |
| | | |
| | | if (SDL_RectEmpty(&renderer->clip_rect)) { |
| | | if (!renderer->clipping_enabled) { |
| | | rasterizerState = rendererData->mainRasterizer; |
| | | } else { |
| | | rasterizerState = rendererData->clippedRasterizer; |
| | |
| | | { |
| | | D3D11_RenderData *rendererData = (D3D11_RenderData *)renderer->driverdata; |
| | | ID3D11BlendState *blendState = NULL; |
| | | switch (blendMode) { |
| | | case SDL_BLENDMODE_BLEND: |
| | | blendState = rendererData->blendModeBlend; |
| | | break; |
| | | case SDL_BLENDMODE_ADD: |
| | | blendState = rendererData->blendModeAdd; |
| | | break; |
| | | case SDL_BLENDMODE_MOD: |
| | | blendState = rendererData->blendModeMod; |
| | | break; |
| | | case SDL_BLENDMODE_NONE: |
| | | blendState = NULL; |
| | | break; |
| | | if (blendMode != SDL_BLENDMODE_NONE) { |
| | | int i; |
| | | for (i = 0; i < rendererData->blendModesCount; ++i) { |
| | | if (blendMode == rendererData->blendModes[i].blendMode) { |
| | | blendState = rendererData->blendModes[i].blendState; |
| | | break; |
| | | } |
| | | } |
| | | if (!blendState) { |
| | | if (D3D11_CreateBlendState(renderer, blendMode)) { |
| | | /* Successfully created the blend state, try again */ |
| | | D3D11_RenderSetBlendMode(renderer, blendMode); |
| | | } |
| | | return; |
| | | } |
| | | } |
| | | if (blendState != rendererData->currentBlendState) { |
| | | ID3D11DeviceContext_OMSetBlendState(rendererData->d3dContext, blendState, 0, 0xFFFFFFFF); |
| | |
| | | a = (float)(renderer->a / 255.0f); |
| | | |
| | | vertices = SDL_stack_alloc(VertexPositionColor, count); |
| | | for (i = 0; i < min(count, 128); ++i) { |
| | | const VertexPositionColor v = { { points[i].x, points[i].y, 0.0f }, { 0.0f, 0.0f }, { r, g, b, a } }; |
| | | for (i = 0; i < count; ++i) { |
| | | const VertexPositionColor v = { { points[i].x + 0.5f, points[i].y + 0.5f, 0.0f }, { 0.0f, 0.0f }, { r, g, b, a } }; |
| | | vertices[i] = v; |
| | | } |
| | | |
| | |
| | | |
| | | D3D11_SetPixelShader( |
| | | renderer, |
| | | rendererData->colorPixelShader, |
| | | rendererData->pixelShaders[SHADER_SOLID], |
| | | 0, |
| | | NULL, |
| | | NULL); |
| | |
| | | |
| | | vertices = SDL_stack_alloc(VertexPositionColor, count); |
| | | for (i = 0; i < count; ++i) { |
| | | const VertexPositionColor v = { { points[i].x, points[i].y, 0.0f }, { 0.0f, 0.0f }, { r, g, b, a } }; |
| | | const VertexPositionColor v = { { points[i].x + 0.5f, points[i].y + 0.5f, 0.0f }, { 0.0f, 0.0f }, { r, g, b, a } }; |
| | | vertices[i] = v; |
| | | } |
| | | |
| | |
| | | |
| | | D3D11_SetPixelShader( |
| | | renderer, |
| | | rendererData->colorPixelShader, |
| | | rendererData->pixelShaders[SHADER_SOLID], |
| | | 0, |
| | | NULL, |
| | | NULL); |
| | | |
| | | D3D11_RenderFinishDrawOp(renderer, D3D11_PRIMITIVE_TOPOLOGY_LINESTRIP, count); |
| | | |
| | | if (points[0].x != points[count - 1].x || points[0].y != points[count - 1].y) { |
| | | ID3D11DeviceContext_IASetPrimitiveTopology(rendererData->d3dContext, D3D11_PRIMITIVE_TOPOLOGY_POINTLIST); |
| | | ID3D11DeviceContext_Draw(rendererData->d3dContext, 1, count - 1); |
| | | } |
| | | |
| | | SDL_stack_free(vertices); |
| | | return 0; |
| | | } |
| | |
| | | |
| | | D3D11_SetPixelShader( |
| | | renderer, |
| | | rendererData->colorPixelShader, |
| | | rendererData->pixelShaders[SHADER_SOLID], |
| | | 0, |
| | | NULL, |
| | | NULL); |
| | |
| | | return 0; |
| | | } |
| | | |
| | | static ID3D11SamplerState * |
| | | D3D11_RenderGetSampler(SDL_Renderer * renderer, SDL_Texture * texture) |
| | | static int |
| | | D3D11_RenderSetupSampler(SDL_Renderer * renderer, SDL_Texture * texture) |
| | | { |
| | | D3D11_RenderData *rendererData = (D3D11_RenderData *) renderer->driverdata; |
| | | D3D11_TextureData *textureData = (D3D11_TextureData *) texture->driverdata; |
| | | ID3D11SamplerState *textureSampler; |
| | | |
| | | switch (textureData->scaleMode) { |
| | | case D3D11_FILTER_MIN_MAG_MIP_POINT: |
| | | return rendererData->nearestPixelSampler; |
| | | textureSampler = rendererData->nearestPixelSampler; |
| | | break; |
| | | case D3D11_FILTER_MIN_MAG_MIP_LINEAR: |
| | | return rendererData->linearSampler; |
| | | textureSampler = rendererData->linearSampler; |
| | | break; |
| | | default: |
| | | return NULL; |
| | | return SDL_SetError("Unknown scale mode: %d\n", textureData->scaleMode); |
| | | } |
| | | |
| | | if (textureData->yuv) { |
| | | ID3D11ShaderResourceView *shaderResources[] = { |
| | | textureData->mainTextureResourceView, |
| | | textureData->mainTextureResourceViewU, |
| | | textureData->mainTextureResourceViewV |
| | | }; |
| | | D3D11_Shader shader; |
| | | |
| | | switch (SDL_GetYUVConversionModeForResolution(texture->w, texture->h)) { |
| | | case SDL_YUV_CONVERSION_JPEG: |
| | | shader = SHADER_YUV_JPEG; |
| | | break; |
| | | case SDL_YUV_CONVERSION_BT601: |
| | | shader = SHADER_YUV_BT601; |
| | | break; |
| | | case SDL_YUV_CONVERSION_BT709: |
| | | shader = SHADER_YUV_BT709; |
| | | break; |
| | | default: |
| | | return SDL_SetError("Unsupported YUV conversion mode"); |
| | | } |
| | | |
| | | D3D11_SetPixelShader( |
| | | renderer, |
| | | rendererData->pixelShaders[shader], |
| | | SDL_arraysize(shaderResources), |
| | | shaderResources, |
| | | textureSampler); |
| | | |
| | | } else if (textureData->nv12) { |
| | | ID3D11ShaderResourceView *shaderResources[] = { |
| | | textureData->mainTextureResourceView, |
| | | textureData->mainTextureResourceViewNV, |
| | | }; |
| | | D3D11_Shader shader; |
| | | |
| | | switch (SDL_GetYUVConversionModeForResolution(texture->w, texture->h)) { |
| | | case SDL_YUV_CONVERSION_JPEG: |
| | | shader = texture->format == SDL_PIXELFORMAT_NV12 ? SHADER_NV12_JPEG : SHADER_NV21_JPEG; |
| | | break; |
| | | case SDL_YUV_CONVERSION_BT601: |
| | | shader = texture->format == SDL_PIXELFORMAT_NV12 ? SHADER_NV12_BT601 : SHADER_NV21_BT601; |
| | | break; |
| | | case SDL_YUV_CONVERSION_BT709: |
| | | shader = texture->format == SDL_PIXELFORMAT_NV12 ? SHADER_NV12_BT709 : SHADER_NV21_BT709; |
| | | break; |
| | | default: |
| | | return SDL_SetError("Unsupported YUV conversion mode"); |
| | | } |
| | | |
| | | D3D11_SetPixelShader( |
| | | renderer, |
| | | rendererData->pixelShaders[shader], |
| | | SDL_arraysize(shaderResources), |
| | | shaderResources, |
| | | textureSampler); |
| | | |
| | | } else { |
| | | D3D11_SetPixelShader( |
| | | renderer, |
| | | rendererData->pixelShaders[SHADER_RGB], |
| | | 1, |
| | | &textureData->mainTextureResourceView, |
| | | textureSampler); |
| | | } |
| | | |
| | | return 0; |
| | | } |
| | | |
| | | static int |
| | | D3D11_RenderCopy(SDL_Renderer * renderer, SDL_Texture * texture, |
| | | const SDL_Rect * srcrect, const SDL_FRect * dstrect) |
| | | { |
| | | D3D11_RenderData *rendererData = (D3D11_RenderData *) renderer->driverdata; |
| | | D3D11_TextureData *textureData = (D3D11_TextureData *) texture->driverdata; |
| | | float minu, maxu, minv, maxv; |
| | | Float4 color; |
| | | VertexPositionColor vertices[4]; |
| | | ID3D11SamplerState *textureSampler; |
| | | |
| | | D3D11_RenderStartDrawOp(renderer); |
| | | D3D11_RenderSetBlendMode(renderer, texture->blendMode); |
| | |
| | | return -1; |
| | | } |
| | | |
| | | textureSampler = D3D11_RenderGetSampler(renderer, texture); |
| | | if (textureData->yuv) { |
| | | ID3D11ShaderResourceView *shaderResources[] = { |
| | | textureData->mainTextureResourceView, |
| | | textureData->mainTextureResourceViewU, |
| | | textureData->mainTextureResourceViewV |
| | | }; |
| | | D3D11_SetPixelShader( |
| | | renderer, |
| | | rendererData->yuvPixelShader, |
| | | SDL_arraysize(shaderResources), |
| | | shaderResources, |
| | | textureSampler); |
| | | } else { |
| | | D3D11_SetPixelShader( |
| | | renderer, |
| | | rendererData->texturePixelShader, |
| | | 1, |
| | | &textureData->mainTextureResourceView, |
| | | textureSampler); |
| | | if (D3D11_RenderSetupSampler(renderer, texture) < 0) { |
| | | return -1; |
| | | } |
| | | |
| | | D3D11_RenderFinishDrawOp(renderer, D3D11_PRIMITIVE_TOPOLOGY_TRIANGLESTRIP, sizeof(vertices) / sizeof(VertexPositionColor)); |
| | |
| | | const SDL_Rect * srcrect, const SDL_FRect * dstrect, |
| | | const double angle, const SDL_FPoint * center, const SDL_RendererFlip flip) |
| | | { |
| | | D3D11_RenderData *rendererData = (D3D11_RenderData *) renderer->driverdata; |
| | | D3D11_TextureData *textureData = (D3D11_TextureData *) texture->driverdata; |
| | | float minu, maxu, minv, maxv; |
| | | Float4 color; |
| | | Float4X4 modelMatrix; |
| | | float minx, maxx, miny, maxy; |
| | | VertexPositionColor vertices[4]; |
| | | ID3D11SamplerState *textureSampler; |
| | | |
| | | D3D11_RenderStartDrawOp(renderer); |
| | | D3D11_RenderSetBlendMode(renderer, texture->blendMode); |
| | |
| | | return -1; |
| | | } |
| | | |
| | | textureSampler = D3D11_RenderGetSampler(renderer, texture); |
| | | if (textureData->yuv) { |
| | | ID3D11ShaderResourceView *shaderResources[] = { |
| | | textureData->mainTextureResourceView, |
| | | textureData->mainTextureResourceViewU, |
| | | textureData->mainTextureResourceViewV |
| | | }; |
| | | D3D11_SetPixelShader( |
| | | renderer, |
| | | rendererData->yuvPixelShader, |
| | | SDL_arraysize(shaderResources), |
| | | shaderResources, |
| | | textureSampler); |
| | | } else { |
| | | D3D11_SetPixelShader( |
| | | renderer, |
| | | rendererData->texturePixelShader, |
| | | 1, |
| | | &textureData->mainTextureResourceView, |
| | | textureSampler); |
| | | if (D3D11_RenderSetupSampler(renderer, texture) < 0) { |
| | | return -1; |
| | | } |
| | | |
| | | D3D11_RenderFinishDrawOp(renderer, D3D11_PRIMITIVE_TOPOLOGY_TRIANGLESTRIP, sizeof(vertices) / sizeof(VertexPositionColor)); |
| | |
| | | HRESULT result; |
| | | int status = -1; |
| | | D3D11_TEXTURE2D_DESC stagingTextureDesc; |
| | | D3D11_RECT srcRect; |
| | | D3D11_RECT srcRect = {0, 0, 0, 0}; |
| | | D3D11_BOX srcBox; |
| | | D3D11_MAPPED_SUBRESOURCE textureMemory; |
| | | |
| | | /* Retrieve a pointer to the back buffer: */ |
| | | result = IDXGISwapChain_GetBuffer(data->swapChain, |
| | | 0, |
| | | &IID_ID3D11Texture2D, |
| | | &backBuffer |
| | | &SDL_IID_ID3D11Texture2D, |
| | | (void **)&backBuffer |
| | | ); |
| | | if (FAILED(result)) { |
| | | WIN_SetErrorFromHRESULT(__FUNCTION__ ", IDXGISwapChain1::GetBuffer [get back buffer]", result); |
| | | WIN_SetErrorFromHRESULT(SDL_COMPOSE_ERROR("IDXGISwapChain1::GetBuffer [get back buffer]"), result); |
| | | goto done; |
| | | } |
| | | |
| | |
| | | NULL, |
| | | &stagingTexture); |
| | | if (FAILED(result)) { |
| | | WIN_SetErrorFromHRESULT(__FUNCTION__ ", ID3D11Device1::CreateTexture2D [create staging texture]", result); |
| | | WIN_SetErrorFromHRESULT(SDL_COMPOSE_ERROR("ID3D11Device1::CreateTexture2D [create staging texture]"), result); |
| | | goto done; |
| | | } |
| | | |
| | | /* Copy the desired portion of the back buffer to the staging texture: */ |
| | | if (D3D11_GetViewportAlignedD3DRect(renderer, rect, &srcRect) != 0) { |
| | | if (D3D11_GetViewportAlignedD3DRect(renderer, rect, &srcRect, FALSE) != 0) { |
| | | /* D3D11_GetViewportAlignedD3DRect will have set the SDL error */ |
| | | goto done; |
| | | } |
| | |
| | | 0, |
| | | &textureMemory); |
| | | if (FAILED(result)) { |
| | | WIN_SetErrorFromHRESULT(__FUNCTION__ ", ID3D11DeviceContext1::Map [map staging texture]", result); |
| | | WIN_SetErrorFromHRESULT(SDL_COMPOSE_ERROR("ID3D11DeviceContext1::Map [map staging texture]"), result); |
| | | goto done; |
| | | } |
| | | |
| | |
| | | */ |
| | | if (SDL_ConvertPixels( |
| | | rect->w, rect->h, |
| | | DXGIFormatToSDLPixelFormat(stagingTextureDesc.Format), |
| | | D3D11_DXGIFormatToSDLPixelFormat(stagingTextureDesc.Format), |
| | | textureMemory.pData, |
| | | textureMemory.RowPitch, |
| | | format, |
| | |
| | | * Get the error message, and attach some extra data to it. |
| | | */ |
| | | char errorMessage[1024]; |
| | | SDL_snprintf(errorMessage, sizeof(errorMessage), __FUNCTION__ ", Convert Pixels failed: %s", SDL_GetError()); |
| | | SDL_SetError(errorMessage); |
| | | SDL_snprintf(errorMessage, sizeof(errorMessage), "%s, Convert Pixels failed: %s", __FUNCTION__, SDL_GetError()); |
| | | SDL_SetError("%s", errorMessage); |
| | | goto done; |
| | | } |
| | | |
| | |
| | | HRESULT result; |
| | | DXGI_PRESENT_PARAMETERS parameters; |
| | | |
| | | SDL_zero(parameters); |
| | | |
| | | #if WINAPI_FAMILY == WINAPI_FAMILY_PHONE_APP |
| | | syncInterval = 1; |
| | | presentFlags = 0; |
| | |
| | | * rects to improve efficiency in certain scenarios. |
| | | * This option is not available on Windows Phone 8, to note. |
| | | */ |
| | | SDL_zero(parameters); |
| | | result = IDXGISwapChain1_Present1(data->swapChain, syncInterval, presentFlags, ¶meters); |
| | | #endif |
| | | |
| | |
| | | /* We probably went through a fullscreen <-> windowed transition */ |
| | | D3D11_CreateWindowSizeDependentResources(renderer); |
| | | } else { |
| | | WIN_SetErrorFromHRESULT(__FUNCTION__ ", IDXGISwapChain::Present", result); |
| | | WIN_SetErrorFromHRESULT(SDL_COMPOSE_ERROR("IDXGISwapChain::Present"), result); |
| | | } |
| | | } |
| | | } |