WinRT: added texture channel color-modulation support for D3D 11.1
authorDavid Ludwig <dludwig@pobox.com>
Sun, 07 Apr 2013 22:35:58 -0400
changeset 8458 9b25393568f3
parent 8457 e0a74ebf9aba
child 8459 1178e27580c7
WinRT: added texture channel color-modulation support for D3D 11.1
VisualC-WinPhone/SDL/SDL_VS2012-WinPhone.vcxproj
VisualC-WinPhone/SDL/SDL_VS2012-WinPhone.vcxproj.filters
VisualC-WinRT/SDL/SDL_VS2012-WinRT.vcxproj
VisualC-WinRT/SDL/SDL_VS2012-WinRT.vcxproj.filters
src/render/direct3d11/SDL_D3D11_PixelShader_TextureColored.hlsl
src/render/direct3d11/SDL_D3D11_PixelShader_TextureCopy.hlsl
src/render/direct3d11/SDL_render_d3d11.cpp
--- a/VisualC-WinPhone/SDL/SDL_VS2012-WinPhone.vcxproj	Tue Apr 02 00:21:01 2013 -0400
+++ b/VisualC-WinPhone/SDL/SDL_VS2012-WinPhone.vcxproj	Sun Apr 07 22:35:58 2013 -0400
@@ -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>
--- a/VisualC-WinPhone/SDL/SDL_VS2012-WinPhone.vcxproj.filters	Tue Apr 02 00:21:01 2013 -0400
+++ b/VisualC-WinPhone/SDL/SDL_VS2012-WinPhone.vcxproj.filters	Sun Apr 07 22:35:58 2013 -0400
@@ -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>
\ No newline at end of file
--- a/VisualC-WinRT/SDL/SDL_VS2012-WinRT.vcxproj	Tue Apr 02 00:21:01 2013 -0400
+++ b/VisualC-WinRT/SDL/SDL_VS2012-WinRT.vcxproj	Sun Apr 07 22:35:58 2013 -0400
@@ -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>
--- a/VisualC-WinRT/SDL/SDL_VS2012-WinRT.vcxproj.filters	Tue Apr 02 00:21:01 2013 -0400
+++ b/VisualC-WinRT/SDL/SDL_VS2012-WinRT.vcxproj.filters	Sun Apr 07 22:35:58 2013 -0400
@@ -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">
--- /dev/null	Thu Jan 01 00:00:00 1970 +0000
+++ b/src/render/direct3d11/SDL_D3D11_PixelShader_TextureColored.hlsl	Sun Apr 07 22:35:58 2013 -0400
@@ -0,0 +1,14 @@
+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;
+}
--- a/src/render/direct3d11/SDL_D3D11_PixelShader_TextureCopy.hlsl	Tue Apr 02 00:21:01 2013 -0400
+++ /dev/null	Thu Jan 01 00:00:00 1970 +0000
@@ -1,14 +0,0 @@
-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);
-}
--- a/src/render/direct3d11/SDL_render_d3d11.cpp	Tue Apr 02 00:21:01 2013 -0400
+++ b/src/render/direct3d11/SDL_render_d3d11.cpp	Sun Apr 07 22:35:58 2013 -0400
@@ -436,7 +436,7 @@
     //
     // 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 @@
     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 @@
     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 @@
     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;