Atlas - SDL_shaders_d3d11.c
Home / ext / SDL / src / render / direct3d11 Lines: 1 | Size: 4247 bytes [Download] [Show on GitHub] [Search similar files] [Raw] [Raw (proxy)][FILE BEGIN]1/* 2 Simple DirectMedia Layer 3 Copyright (C) 1997-2026 Sam Lantinga <[email protected]> 4 5 This software is provided 'as-is', without any express or implied 6 warranty. In no event will the authors be held liable for any damages 7 arising from the use of this software. 8 9 Permission is granted to anyone to use this software for any purpose, 10 including commercial applications, and to alter it and redistribute it 11 freely, subject to the following restrictions: 12 13 1. The origin of this software must not be misrepresented; you must not 14 claim that you wrote the original software. If you use this software 15 in a product, an acknowledgment in the product documentation would be 16 appreciated but is not required. 17 2. Altered source versions must be plainly marked as such, and must not be 18 misrepresented as being the original software. 19 3. This notice may not be removed or altered from any source distribution. 20*/ 21#include "SDL_internal.h" 22 23#ifdef SDL_VIDEO_RENDER_D3D11 24 25#define COBJMACROS 26#include "../../core/windows/SDL_windows.h" 27#include <d3d11_1.h> 28 29#include "SDL_shaders_d3d11.h" 30 31#if SDL_WINAPI_FAMILY_PHONE 32#error Need to build shaders with level_9_3 33#endif 34 35// The shaders here were compiled with compile_shaders.bat 36 37#define g_main D3D11_PixelShader_Colors 38#include "D3D11_PixelShader_Colors.h" 39#undef g_main 40 41#define g_main D3D11_PixelShader_Textures 42#include "D3D11_PixelShader_Textures.h" 43#undef g_main 44 45#define g_main D3D11_PixelShader_Advanced 46#include "D3D11_PixelShader_Advanced.h" 47#undef g_main 48 49#define g_main D3D11_VertexShader 50#include "D3D11_VertexShader.h" 51#undef g_main 52 53 54static struct 55{ 56 const void *shader_data; 57 SIZE_T shader_size; 58} D3D11_shaders[] = { 59 { NULL, 0 }, 60 { D3D11_PixelShader_Colors, sizeof(D3D11_PixelShader_Colors) }, 61 { D3D11_PixelShader_Textures, sizeof(D3D11_PixelShader_Textures) }, 62 { D3D11_PixelShader_Advanced, sizeof(D3D11_PixelShader_Advanced) }, 63}; 64SDL_COMPILE_TIME_ASSERT(D3D11_shaders, SDL_arraysize(D3D11_shaders) == NUM_SHADERS); 65 66bool D3D11_CreateVertexShader(ID3D11Device1 *d3dDevice, ID3D11VertexShader **vertexShader, ID3D11InputLayout **inputLayout) 67{ 68 // Declare how the input layout for SDL's vertex shader will be setup: 69 const D3D11_INPUT_ELEMENT_DESC vertexDesc[] = { 70 { "POSITION", 0, DXGI_FORMAT_R32G32_FLOAT, 0, 0, D3D11_INPUT_PER_VERTEX_DATA, 0 }, 71 { "TEXCOORD", 0, DXGI_FORMAT_R32G32_FLOAT, 0, 8, D3D11_INPUT_PER_VERTEX_DATA, 0 }, 72 { "COLOR", 0, DXGI_FORMAT_R32G32B32A32_FLOAT, 0, 16, D3D11_INPUT_PER_VERTEX_DATA, 0 }, 73 }; 74 HRESULT result; 75 76 // Load in SDL's one and only vertex shader: 77 result = ID3D11Device_CreateVertexShader(d3dDevice, 78 D3D11_VertexShader, 79 sizeof(D3D11_VertexShader), 80 NULL, 81 vertexShader); 82 if (FAILED(result)) { 83 return WIN_SetErrorFromHRESULT("ID3D11Device1::CreateVertexShader", result); 84 } 85 86 // Create an input layout for SDL's vertex shader: 87 result = ID3D11Device_CreateInputLayout(d3dDevice, 88 vertexDesc, 89 ARRAYSIZE(vertexDesc), 90 D3D11_VertexShader, 91 sizeof(D3D11_VertexShader), 92 inputLayout); 93 if (FAILED(result)) { 94 return WIN_SetErrorFromHRESULT("ID3D11Device1::CreateInputLayout", result); 95 } 96 return true; 97} 98 99bool D3D11_CreatePixelShader(ID3D11Device1 *d3dDevice, D3D11_Shader shader, ID3D11PixelShader **pixelShader) 100{ 101 HRESULT result; 102 103 result = ID3D11Device_CreatePixelShader(d3dDevice, 104 D3D11_shaders[shader].shader_data, 105 D3D11_shaders[shader].shader_size, 106 NULL, 107 pixelShader); 108 if (FAILED(result)) { 109 return WIN_SetErrorFromHRESULT("ID3D11Device1::CreatePixelShader", result); 110 } 111 return true; 112} 113 114#endif // SDL_VIDEO_RENDER_D3D11 115[FILE END](C) 2025 0x4248 (C) 2025 4248 Media and 4248 Systems, All part of 0x4248 See LICENCE files for more information. Not all files are by 0x4248 always check Licencing.