add custom shader support classes (based off the "standard" shader types)

This commit is contained in:
Gered 2013-08-18 12:53:18 -04:00
parent b48a13757b
commit d53ed4147e
5 changed files with 125 additions and 0 deletions

View file

@ -126,6 +126,10 @@
<Compile Include="Support\StringExtensions.cs" />
<Compile Include="Graphics\ImageFormat.cs" />
<Compile Include="Graphics\IPlatformBitmap.cs" />
<Compile Include="Graphics\CustomShaders\CustomSpriteShader.cs" />
<Compile Include="Graphics\CustomShaders\CustomStandardShader.cs" />
<Compile Include="Graphics\CustomShaders\CustomVertexLerpShader.cs" />
<Compile Include="Graphics\CustomShaders\CustomVertexSkinningShader.cs" />
</ItemGroup>
<Import Project="$(MSBuildExtensionsPath32)\Microsoft\Portable\$(TargetFrameworkVersion)\Microsoft.Portable.CSharp.targets" />
<ItemGroup>
@ -138,6 +142,7 @@
<Folder Include="Resources\Shaders\" />
<Folder Include="Graphics\BuiltinShaders\" />
<Folder Include="Support\" />
<Folder Include="Graphics\CustomShaders\" />
</ItemGroup>
<ItemGroup>
<EmbeddedResource Include="Resources\Fonts\Vera.ttf" />

View file

@ -0,0 +1,30 @@
using System;
using System.IO;
namespace Blarg.GameFramework.Graphics.CustomShaders
{
public class CustomSpriteShader : SpriteShader
{
public CustomSpriteShader(GraphicsDevice graphicsDevice, string vertexShaderSource, string fragmentShaderSource)
: base(graphicsDevice, vertexShaderSource, fragmentShaderSource)
{
if (!HasUniform(ModelViewMatrixUniformName))
throw new InvalidOperationException(String.Format("Missing \"{0}\" uniform.", ModelViewMatrixUniformName));
if (!HasUniform(ProjectionMatrixUniformName))
throw new InvalidOperationException(String.Format("Missing \"{0}\" uniform.", ProjectionMatrixUniformName));
if (!HasUniform(TextureHasAlphaOnlyUniformName))
throw new InvalidOperationException(String.Format("Missing \"{0}\" uniform.", TextureHasAlphaOnlyUniformName));
}
public CustomSpriteShader(GraphicsDevice graphicsDevice, TextReader vertexShaderSourceReader, TextReader fragmentShaderSourceReader)
: base(graphicsDevice, vertexShaderSourceReader, fragmentShaderSourceReader)
{
if (!HasUniform(ModelViewMatrixUniformName))
throw new InvalidOperationException(String.Format("Missing \"{0}\" uniform.", ModelViewMatrixUniformName));
if (!HasUniform(ProjectionMatrixUniformName))
throw new InvalidOperationException(String.Format("Missing \"{0}\" uniform.", ProjectionMatrixUniformName));
if (!HasUniform(TextureHasAlphaOnlyUniformName))
throw new InvalidOperationException(String.Format("Missing \"{0}\" uniform.", TextureHasAlphaOnlyUniformName));
}
}
}

View file

@ -0,0 +1,26 @@
using System;
using System.IO;
namespace Blarg.GameFramework.Graphics.CustomShaders
{
public class CustomStandardShader : StandardShader
{
public CustomStandardShader(GraphicsDevice graphicsDevice, string vertexShaderSource, string fragmentShaderSource)
: base(graphicsDevice, vertexShaderSource, fragmentShaderSource)
{
if (!HasUniform(ModelViewMatrixUniformName))
throw new InvalidOperationException(String.Format("Missing \"{0}\" uniform.", ModelViewMatrixUniformName));
if (!HasUniform(ProjectionMatrixUniformName))
throw new InvalidOperationException(String.Format("Missing \"{0}\" uniform.", ProjectionMatrixUniformName));
}
public CustomStandardShader(GraphicsDevice graphicsDevice, TextReader vertexShaderSourceReader, TextReader fragmentShaderSourceReader)
: base(graphicsDevice, vertexShaderSourceReader, fragmentShaderSourceReader)
{
if (!HasUniform(ModelViewMatrixUniformName))
throw new InvalidOperationException(String.Format("Missing \"{0}\" uniform.", ModelViewMatrixUniformName));
if (!HasUniform(ProjectionMatrixUniformName))
throw new InvalidOperationException(String.Format("Missing \"{0}\" uniform.", ProjectionMatrixUniformName));
}
}
}

View file

@ -0,0 +1,30 @@
using System;
using System.IO;
namespace Blarg.GameFramework.Graphics.CustomShaders
{
public class CustomVertexLerpShader : VertexLerpShader
{
public CustomVertexLerpShader(GraphicsDevice graphicsDevice, string vertexShaderSource, string fragmentShaderSource)
: base(graphicsDevice, vertexShaderSource, fragmentShaderSource)
{
if (!HasUniform(ModelViewMatrixUniformName))
throw new InvalidOperationException(String.Format("Missing \"{0}\" uniform.", ModelViewMatrixUniformName));
if (!HasUniform(ProjectionMatrixUniformName))
throw new InvalidOperationException(String.Format("Missing \"{0}\" uniform.", ProjectionMatrixUniformName));
if (!HasUniform(LerpUniformName))
throw new InvalidOperationException(String.Format("Missing \"{0}\" uniform.", LerpUniformName));
}
public CustomVertexLerpShader(GraphicsDevice graphicsDevice, TextReader vertexShaderSourceReader, TextReader fragmentShaderSourceReader)
: base(graphicsDevice, vertexShaderSourceReader, fragmentShaderSourceReader)
{
if (!HasUniform(ModelViewMatrixUniformName))
throw new InvalidOperationException(String.Format("Missing \"{0}\" uniform.", ModelViewMatrixUniformName));
if (!HasUniform(ProjectionMatrixUniformName))
throw new InvalidOperationException(String.Format("Missing \"{0}\" uniform.", ProjectionMatrixUniformName));
if (!HasUniform(LerpUniformName))
throw new InvalidOperationException(String.Format("Missing \"{0}\" uniform.", LerpUniformName));
}
}
}

View file

@ -0,0 +1,34 @@
using System;
using System.IO;
namespace Blarg.GameFramework.Graphics.CustomShaders
{
public class CustomVertexSkinningShader : VertexSkinningShader
{
public CustomVertexSkinningShader(GraphicsDevice graphicsDevice, string vertexShaderSource, string fragmentShaderSource)
: base(graphicsDevice, vertexShaderSource, fragmentShaderSource)
{
if (!HasUniform(ModelViewMatrixUniformName))
throw new InvalidOperationException(String.Format("Missing \"{0}\" uniform.", ModelViewMatrixUniformName));
if (!HasUniform(ProjectionMatrixUniformName))
throw new InvalidOperationException(String.Format("Missing \"{0}\" uniform.", ProjectionMatrixUniformName));
if (!HasUniform(JointPositionsUniformName))
throw new InvalidOperationException(String.Format("Missing \"{0}\" uniform.", JointPositionsUniformName));
if (!HasUniform(JointRotationsUniformName))
throw new InvalidOperationException(String.Format("Missing \"{0}\" uniform.", JointRotationsUniformName));
}
public CustomVertexSkinningShader(GraphicsDevice graphicsDevice, TextReader vertexShaderSourceReader, TextReader fragmentShaderSourceReader)
: base(graphicsDevice, vertexShaderSourceReader, fragmentShaderSourceReader)
{
if (!HasUniform(ModelViewMatrixUniformName))
throw new InvalidOperationException(String.Format("Missing \"{0}\" uniform.", ModelViewMatrixUniformName));
if (!HasUniform(ProjectionMatrixUniformName))
throw new InvalidOperationException(String.Format("Missing \"{0}\" uniform.", ProjectionMatrixUniformName));
if (!HasUniform(JointPositionsUniformName))
throw new InvalidOperationException(String.Format("Missing \"{0}\" uniform.", JointPositionsUniformName));
if (!HasUniform(JointRotationsUniformName))
throw new InvalidOperationException(String.Format("Missing \"{0}\" uniform.", JointRotationsUniformName));
}
}
}