Skip to content
This repository has been archived by the owner on Feb 11, 2021. It is now read-only.

Commit

Permalink
WinRT: added texture channel color-modulation support for D3D 11.1
Browse files Browse the repository at this point in the history
  • Loading branch information
DavidLudwig committed Apr 8, 2013
1 parent 50bf5ed commit 699e3da
Show file tree
Hide file tree
Showing 6 changed files with 44 additions and 20 deletions.
2 changes: 1 addition & 1 deletion VisualC-WinPhone/SDL/SDL_VS2012-WinPhone.vcxproj
Expand Up @@ -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>
Expand Down
6 changes: 3 additions & 3 deletions VisualC-WinPhone/SDL/SDL_VS2012-WinPhone.vcxproj.filters
Expand Up @@ -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>
4 changes: 1 addition & 3 deletions VisualC-WinRT/SDL/SDL_VS2012-WinRT.vcxproj
Expand Up @@ -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>
Expand All @@ -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>
Expand Down
6 changes: 3 additions & 3 deletions VisualC-WinRT/SDL/SDL_VS2012-WinRT.vcxproj.filters
@@ -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">
Expand Down
Expand Up @@ -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;
}
44 changes: 35 additions & 9 deletions src/render/direct3d11/SDL_render_d3d11.cpp
Expand Up @@ -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;
Expand Down Expand Up @@ -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;
Expand Down Expand Up @@ -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;
Expand All @@ -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;
Expand Down

0 comments on commit 699e3da

Please sign in to comment.