Improve ImGui shader string literals

Remove all useless indentation characters, change to static char array, use sizeof operator instead of strlen.
This commit is contained in:
Kawe Mazidjatari 2023-06-16 23:11:42 +02:00
parent f6e6f834ce
commit 2ad72b9f8f

View File

@ -383,37 +383,35 @@ bool ImGui_ImplDX11_CreateDeviceObjects()
// Create the vertex shader // Create the vertex shader
// Shader taken from https://github.com/ocornut/imgui/issues/1724 // Shader taken from https://github.com/ocornut/imgui/issues/1724
{ {
static const char* vertexShader = static const char vertexShader[] =
"cbuffer vertexBuffer : register(b0) \ "cbuffer vertexBuffer : register(b0)\n"
{\ "{\n"
float4x4 ProjectionMatrix; \ " float4x4 ProjectionMatrix;\n"
};\ "};\n"
struct VS_INPUT\ "struct VS_INPUT\n"
{\ "{\n"
float2 pos : POSITION;\ " float2 pos : POSITION;\n"
float4 col : COLOR0;\ " float4 col : COLOR0;\n"
float2 uv : TEXCOORD0;\ " float2 uv : TEXCOORD0;\n"
};\ "};\n"
\ "struct PS_INPUT\n"
struct PS_INPUT\ "{\n"
{\ " float4 pos : SV_POSITION;\n"
float4 pos : SV_POSITION;\ " float4 col : COLOR0;\n"
float4 col : COLOR0;\ " float2 uv : TEXCOORD0;\n"
float2 uv : TEXCOORD0;\ "};\n"
};\ "PS_INPUT main(VS_INPUT input)\n"
\ "{\n"
PS_INPUT main(VS_INPUT input)\ " PS_INPUT output;\n"
{\ " output.pos = mul(ProjectionMatrix, float4(input.pos.xy, 0.0f, 1.0f));\n"
PS_INPUT output;\ " output.col.xyz = pow(abs(input.col.xyz), 2.2f);\n"
output.pos = mul( ProjectionMatrix, float4(input.pos.xy, 0.f, 1.f));\ " output.col.w = input.col.w;\n"
output.col.xyz = pow(abs(input.col.xyz), 2.2f);\ " output.uv = input.uv;\n"
output.col.w = input.col.w;\ " return output;\n"
output.uv = input.uv;\ "}\n";
return output;\
}";
ID3DBlob* vertexShaderBlob; ID3DBlob* vertexShaderBlob;
if (FAILED(D3DCompile(vertexShader, strlen(vertexShader), nullptr, nullptr, nullptr, "main", "vs_4_0", 0, 0, &vertexShaderBlob, nullptr))) if (FAILED(D3DCompile(vertexShader, sizeof(vertexShader)-1, nullptr, nullptr, nullptr, "main", "vs_4_0", 0, 0, &vertexShaderBlob, nullptr)))
return false; // NB: Pass ID3DBlob* pErrorBlob to D3DCompile() to get error showing in (const char*)pErrorBlob->GetBufferPointer(). Make sure to Release() the blob! return false; // NB: Pass ID3DBlob* pErrorBlob to D3DCompile() to get error showing in (const char*)pErrorBlob->GetBufferPointer(). Make sure to Release() the blob!
if (bd->pd3dDevice->CreateVertexShader(vertexShaderBlob->GetBufferPointer(), vertexShaderBlob->GetBufferSize(), nullptr, &bd->pVertexShader) != S_OK) if (bd->pd3dDevice->CreateVertexShader(vertexShaderBlob->GetBufferPointer(), vertexShaderBlob->GetBufferSize(), nullptr, &bd->pVertexShader) != S_OK)
{ {
@ -449,24 +447,23 @@ bool ImGui_ImplDX11_CreateDeviceObjects()
// Create the pixel shader // Create the pixel shader
{ {
static const char* pixelShader = static const char pixelShader[] =
"struct PS_INPUT\ "struct PS_INPUT\n"
{\ "{\n"
float4 pos : SV_POSITION;\ " float4 pos : SV_POSITION;\n"
float4 col : COLOR0;\ " float4 col : COLOR0;\n"
float2 uv : TEXCOORD0;\ " float2 uv : TEXCOORD0;\n"
};\ "};\n"
sampler sampler0;\ "sampler sampler0;\n"
Texture2D texture0;\ "Texture2D texture0;\n"
\ "float4 main(PS_INPUT input) : SV_Target\n"
float4 main(PS_INPUT input) : SV_Target\ "{\n"
{\ " float4 output = input.col * texture0.Sample(sampler0, input.uv);\n"
float4 out_col = input.col * texture0.Sample(sampler0, input.uv); \ " return output;\n"
return out_col; \ "}\n";
}";
ID3DBlob* pixelShaderBlob; ID3DBlob* pixelShaderBlob;
if (FAILED(D3DCompile(pixelShader, strlen(pixelShader), nullptr, nullptr, nullptr, "main", "ps_4_0", 0, 0, &pixelShaderBlob, nullptr))) if (FAILED(D3DCompile(pixelShader, sizeof(pixelShader)-1, nullptr, nullptr, nullptr, "main", "ps_4_0", 0, 0, &pixelShaderBlob, nullptr)))
return false; // NB: Pass ID3DBlob* pErrorBlob to D3DCompile() to get error showing in (const char*)pErrorBlob->GetBufferPointer(). Make sure to Release() the blob! return false; // NB: Pass ID3DBlob* pErrorBlob to D3DCompile() to get error showing in (const char*)pErrorBlob->GetBufferPointer(). Make sure to Release() the blob!
if (bd->pd3dDevice->CreatePixelShader(pixelShaderBlob->GetBufferPointer(), pixelShaderBlob->GetBufferSize(), nullptr, &bd->pPixelShader) != S_OK) if (bd->pd3dDevice->CreatePixelShader(pixelShaderBlob->GetBufferPointer(), pixelShaderBlob->GetBufferSize(), nullptr, &bd->pPixelShader) != S_OK)
{ {