From d53ed4147e491fb4b9b5ca694a7105ed731f6788 Mon Sep 17 00:00:00 2001 From: gered Date: Sun, 18 Aug 2013 12:53:18 -0400 Subject: [PATCH] add custom shader support classes (based off the "standard" shader types) --- .../Blarg.GameFramework.csproj | 5 +++ .../CustomShaders/CustomSpriteShader.cs | 30 ++++++++++++++++ .../CustomShaders/CustomStandardShader.cs | 26 ++++++++++++++ .../CustomShaders/CustomVertexLerpShader.cs | 30 ++++++++++++++++ .../CustomVertexSkinningShader.cs | 34 +++++++++++++++++++ 5 files changed, 125 insertions(+) create mode 100644 Blarg.GameFramework/Graphics/CustomShaders/CustomSpriteShader.cs create mode 100644 Blarg.GameFramework/Graphics/CustomShaders/CustomStandardShader.cs create mode 100644 Blarg.GameFramework/Graphics/CustomShaders/CustomVertexLerpShader.cs create mode 100644 Blarg.GameFramework/Graphics/CustomShaders/CustomVertexSkinningShader.cs diff --git a/Blarg.GameFramework/Blarg.GameFramework.csproj b/Blarg.GameFramework/Blarg.GameFramework.csproj index 99a9cb3..9a67281 100644 --- a/Blarg.GameFramework/Blarg.GameFramework.csproj +++ b/Blarg.GameFramework/Blarg.GameFramework.csproj @@ -126,6 +126,10 @@ + + + + @@ -138,6 +142,7 @@ + diff --git a/Blarg.GameFramework/Graphics/CustomShaders/CustomSpriteShader.cs b/Blarg.GameFramework/Graphics/CustomShaders/CustomSpriteShader.cs new file mode 100644 index 0000000..7246440 --- /dev/null +++ b/Blarg.GameFramework/Graphics/CustomShaders/CustomSpriteShader.cs @@ -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)); + } + } +} diff --git a/Blarg.GameFramework/Graphics/CustomShaders/CustomStandardShader.cs b/Blarg.GameFramework/Graphics/CustomShaders/CustomStandardShader.cs new file mode 100644 index 0000000..b0b2043 --- /dev/null +++ b/Blarg.GameFramework/Graphics/CustomShaders/CustomStandardShader.cs @@ -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)); + } + } +} diff --git a/Blarg.GameFramework/Graphics/CustomShaders/CustomVertexLerpShader.cs b/Blarg.GameFramework/Graphics/CustomShaders/CustomVertexLerpShader.cs new file mode 100644 index 0000000..bf3672a --- /dev/null +++ b/Blarg.GameFramework/Graphics/CustomShaders/CustomVertexLerpShader.cs @@ -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)); + } + } +} diff --git a/Blarg.GameFramework/Graphics/CustomShaders/CustomVertexSkinningShader.cs b/Blarg.GameFramework/Graphics/CustomShaders/CustomVertexSkinningShader.cs new file mode 100644 index 0000000..5506c04 --- /dev/null +++ b/Blarg.GameFramework/Graphics/CustomShaders/CustomVertexSkinningShader.cs @@ -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)); + } + } +}