WinRT: added texture channel color-modulation support for D3D 11.1

--HG--
rename : src/render/direct3d11/SDL_D3D11_PixelShader_TextureCopy.hlsl => src/render/direct3d11/SDL_D3D11_PixelShader_TextureColored.hlsl
This commit is contained in:
David Ludwig 2013-04-07 22:35:58 -04:00
parent b1b2ba3f09
commit b74856f7b7
6 changed files with 44 additions and 20 deletions

View file

@ -382,7 +382,7 @@
<ShaderType Condition="'$(Configuration)|$(Platform)'=='Debug|Win32'">Pixel</ShaderType>
<ShaderType Condition="'$(Configuration)|$(Platform)'=='Release|Win32'">Pixel</ShaderType>
</FxCompile>
<FxCompile Include="..\..\src\render\direct3d11\SDL_D3D11_PixelShader_TextureCopy.hlsl">
<FxCompile Include="..\..\src\render\direct3d11\SDL_D3D11_PixelShader_TextureColored.hlsl">
<ShaderType Condition="'$(Configuration)|$(Platform)'=='Debug|ARM'">Pixel</ShaderType>
<ShaderType Condition="'$(Configuration)|$(Platform)'=='Release|ARM'">Pixel</ShaderType>
<ShaderType Condition="'$(Configuration)|$(Platform)'=='Debug|Win32'">Pixel</ShaderType>

View file

@ -592,14 +592,14 @@
</ClCompile>
</ItemGroup>
<ItemGroup>
<FxCompile Include="..\..\src\render\direct3d11\SDL_D3D11_PixelShader_TextureCopy.hlsl">
<Filter>GPU Shaders</Filter>
</FxCompile>
<FxCompile Include="..\..\src\render\direct3d11\SDL_D3D11_PixelShader_FixedColor.hlsl">
<Filter>GPU Shaders</Filter>
</FxCompile>
<FxCompile Include="..\..\src\render\direct3d11\SDL_D3D11_VertexShader_Default.hlsl">
<Filter>GPU Shaders</Filter>
</FxCompile>
<FxCompile Include="..\..\src\render\direct3d11\SDL_D3D11_PixelShader_TextureColored.hlsl">
<Filter>GPU Shaders</Filter>
</FxCompile>
</ItemGroup>
</Project>

View file

@ -293,7 +293,7 @@
<ShaderModel Condition="'$(Configuration)|$(Platform)'=='Debug|ARM'">4.0_level_9_1</ShaderModel>
<ShaderModel Condition="'$(Configuration)|$(Platform)'=='Release|ARM'">4.0_level_9_1</ShaderModel>
</FxCompile>
<FxCompile Include="..\..\src\render\direct3d11\SDL_D3D11_PixelShader_TextureCopy.hlsl">
<FxCompile Include="..\..\src\render\direct3d11\SDL_D3D11_PixelShader_TextureColored.hlsl">
<ShaderType Condition="'$(Configuration)|$(Platform)'=='Debug|ARM'">Pixel</ShaderType>
<ShaderType Condition="'$(Configuration)|$(Platform)'=='Release|ARM'">Pixel</ShaderType>
<ShaderType Condition="'$(Configuration)|$(Platform)'=='Debug|Win32'">Pixel</ShaderType>
@ -304,8 +304,6 @@
<ShaderModel Condition="'$(Configuration)|$(Platform)'=='Release|Win32'">4.0_level_9_1</ShaderModel>
<ShaderModel Condition="'$(Configuration)|$(Platform)'=='Debug|x64'">4.0_level_9_1</ShaderModel>
<ShaderModel Condition="'$(Configuration)|$(Platform)'=='Release|x64'">4.0_level_9_1</ShaderModel>
<ShaderModel Condition="'$(Configuration)|$(Platform)'=='Debug|ARM'">4.0_level_9_1</ShaderModel>
<ShaderModel Condition="'$(Configuration)|$(Platform)'=='Release|ARM'">4.0_level_9_1</ShaderModel>
</FxCompile>
<FxCompile Include="..\..\src\render\direct3d11\SDL_D3D11_VertexShader_Default.hlsl">
<ShaderType Condition="'$(Configuration)|$(Platform)'=='Debug|ARM'">Vertex</ShaderType>

View file

@ -1,15 +1,15 @@
<?xml version="1.0" encoding="utf-8"?>
<Project ToolsVersion="4.0" xmlns="http://schemas.microsoft.com/developer/msbuild/2003">
<ItemGroup>
<FxCompile Include="..\..\src\render\direct3d11\SDL_D3D11_PixelShader_TextureCopy.hlsl">
<Filter>GPU Shaders</Filter>
</FxCompile>
<FxCompile Include="..\..\src\render\direct3d11\SDL_D3D11_PixelShader_FixedColor.hlsl">
<Filter>GPU Shaders</Filter>
</FxCompile>
<FxCompile Include="..\..\src\render\direct3d11\SDL_D3D11_VertexShader_Default.hlsl">
<Filter>GPU Shaders</Filter>
</FxCompile>
<FxCompile Include="..\..\src\render\direct3d11\SDL_D3D11_PixelShader_TextureColored.hlsl">
<Filter>GPU Shaders</Filter>
</FxCompile>
</ItemGroup>
<ItemGroup>
<ClCompile Include="..\..\src\SDL.c">

View file

@ -10,5 +10,5 @@ struct PixelShaderInput
float4 main(PixelShaderInput input) : SV_TARGET
{
return theTexture.Sample(theSampler, input.tex);
return theTexture.Sample(theSampler, input.tex) * input.color;
}

View file

@ -436,7 +436,7 @@ D3D11_CreateDeviceResources(SDL_Renderer * renderer)
//
// Load in SDL's pixel shaders
//
result = D3D11_LoadPixelShader(renderer, L"SDL_D3D11_PixelShader_TextureCopy.cso", &data->texturePixelShader);
result = D3D11_LoadPixelShader(renderer, L"SDL_D3D11_PixelShader_TextureColored.cso", &data->texturePixelShader);
if (FAILED(result)) {
// D3D11_LoadPixelShader will have aleady set the SDL error
return result;
@ -1460,12 +1460,25 @@ D3D11_RenderCopy(SDL_Renderer * renderer, SDL_Texture * texture,
float maxu = (float) (srcrect->x + srcrect->w) / texture->w;
float minv = (float) srcrect->y / texture->h;
float maxv = (float) (srcrect->y + srcrect->h) / texture->h;
float r = 1.0f;
float g = 1.0f;
float b = 1.0f;
float a = 1.0f;
if (texture->modMode & SDL_TEXTUREMODULATE_COLOR) {
r = (float)(texture->r / 255.0f);
g = (float)(texture->g / 255.0f);
b = (float)(texture->b / 255.0f);
}
if (texture->modMode & SDL_TEXTUREMODULATE_ALPHA) {
a = (float)(texture->a / 255.0f);
}
VertexPositionColor vertices[] = {
{XMFLOAT3(dstrect->x, dstrect->y, 0.0f), XMFLOAT2(minu, minv), XMFLOAT4(1.0f, 1.0f, 1.0f, 1.0f)},
{XMFLOAT3(dstrect->x, dstrect->y + dstrect->h, 0.0f), XMFLOAT2(minu, maxv), XMFLOAT4(1.0f, 1.0f, 1.0f, 1.0f)},
{XMFLOAT3(dstrect->x + dstrect->w, dstrect->y, 0.0f), XMFLOAT2(maxu, minv), XMFLOAT4(1.0f, 1.0f, 1.0f, 1.0f)},
{XMFLOAT3(dstrect->x + dstrect->w, dstrect->y + dstrect->h, 0.0f), XMFLOAT2(maxu, maxv), XMFLOAT4(1.0f, 1.0f, 1.0f, 1.0f)},
{XMFLOAT3(dstrect->x, dstrect->y, 0.0f), XMFLOAT2(minu, minv), XMFLOAT4(r, g, b, a)},
{XMFLOAT3(dstrect->x, dstrect->y + dstrect->h, 0.0f), XMFLOAT2(minu, maxv), XMFLOAT4(r, g, b, a)},
{XMFLOAT3(dstrect->x + dstrect->w, dstrect->y, 0.0f), XMFLOAT2(maxu, minv), XMFLOAT4(r, g, b, a)},
{XMFLOAT3(dstrect->x + dstrect->w, dstrect->y + dstrect->h, 0.0f), XMFLOAT2(maxu, maxv), XMFLOAT4(r, g, b, a)},
};
if (D3D11_UpdateVertexBuffer(renderer, vertices, sizeof(vertices)) != 0) {
return -1;
@ -1498,6 +1511,19 @@ D3D11_RenderCopyEx(SDL_Renderer * renderer, SDL_Texture * texture,
float minv = (float) srcrect->y / texture->h;
float maxv = (float) (srcrect->y + srcrect->h) / texture->h;
float r = 1.0f;
float g = 1.0f;
float b = 1.0f;
float a = 1.0f;
if (texture->modMode & SDL_TEXTUREMODULATE_COLOR) {
r = (float)(texture->r / 255.0f);
g = (float)(texture->g / 255.0f);
b = (float)(texture->b / 255.0f);
}
if (texture->modMode & SDL_TEXTUREMODULATE_ALPHA) {
a = (float)(texture->a / 255.0f);
}
if (flip & SDL_FLIP_HORIZONTAL) {
float tmp = maxu;
maxu = minu;
@ -1523,10 +1549,10 @@ D3D11_RenderCopyEx(SDL_Renderer * renderer, SDL_Texture * texture,
const float maxy = dstrect->h - center->y;
VertexPositionColor vertices[] = {
{XMFLOAT3(minx, miny, 0.0f), XMFLOAT2(minu, minv), XMFLOAT4(1.0f, 1.0f, 1.0f, 1.0f)},
{XMFLOAT3(minx, maxy, 0.0f), XMFLOAT2(minu, maxv), XMFLOAT4(1.0f, 1.0f, 1.0f, 1.0f)},
{XMFLOAT3(maxx, miny, 0.0f), XMFLOAT2(maxu, minv), XMFLOAT4(1.0f, 1.0f, 1.0f, 1.0f)},
{XMFLOAT3(maxx, maxy, 0.0f), XMFLOAT2(maxu, maxv), XMFLOAT4(1.0f, 1.0f, 1.0f, 1.0f)},
{XMFLOAT3(minx, miny, 0.0f), XMFLOAT2(minu, minv), XMFLOAT4(r, g, b, a)},
{XMFLOAT3(minx, maxy, 0.0f), XMFLOAT2(minu, maxv), XMFLOAT4(r, g, b, a)},
{XMFLOAT3(maxx, miny, 0.0f), XMFLOAT2(maxu, minv), XMFLOAT4(r, g, b, a)},
{XMFLOAT3(maxx, maxy, 0.0f), XMFLOAT2(maxu, maxv), XMFLOAT4(r, g, b, a)},
};
if (D3D11_UpdateVertexBuffer(renderer, vertices, sizeof(vertices)) != 0) {
return -1;