From 543e6bf4093a169f736783545ceb1e78d0969ab2 Mon Sep 17 00:00:00 2001 From: gered Date: Mon, 1 Apr 2013 19:32:11 -0400 Subject: [PATCH] update all shader subclasses to use Initialize() methods for all complex initialization instead of the constructor --- src/framework/graphics/customspriteshader.cpp | 61 +++++++++--------- src/framework/graphics/customspriteshader.h | 38 ++++++----- .../graphics/customstandardshader.cpp | 56 ++++++++--------- src/framework/graphics/customstandardshader.h | 38 ++++++----- .../graphics/customvertexlerpshader.cpp | 60 ++++++++---------- .../graphics/customvertexlerpshader.h | 9 +-- .../graphics/customvertexskinningshader.cpp | 63 +++++++++---------- .../graphics/customvertexskinningshader.h | 9 +-- src/framework/graphics/debugshader.cpp | 21 +++++-- src/framework/graphics/debugshader.h | 4 ++ src/framework/graphics/simplecolorshader.cpp | 21 +++++-- src/framework/graphics/simplecolorshader.h | 4 ++ .../graphics/simplecolortextureshader.cpp | 23 ++++--- .../graphics/simplecolortextureshader.h | 4 ++ .../graphics/simpletextureshader.cpp | 22 +++++-- src/framework/graphics/simpletextureshader.h | 4 ++ .../simpletexturevertexlerpshader.cpp | 23 ++++--- .../graphics/simpletexturevertexlerpshader.h | 4 ++ .../simpletexturevertexskinningshader.cpp | 23 ++++--- .../simpletexturevertexskinningshader.h | 4 ++ src/framework/graphics/sprite2dshader.cpp | 23 ++++--- src/framework/graphics/sprite2dshader.h | 4 ++ src/framework/graphics/sprite3dshader.cpp | 23 ++++--- src/framework/graphics/sprite3dshader.h | 4 ++ src/framework/graphics/spriteshader.cpp | 1 - src/framework/graphics/standardshader.cpp | 1 - src/framework/graphics/vertexlerpshader.cpp | 1 - .../graphics/vertexskinningshader.cpp | 1 - 28 files changed, 321 insertions(+), 228 deletions(-) diff --git a/src/framework/graphics/customspriteshader.cpp b/src/framework/graphics/customspriteshader.cpp index 3784574..8f47b3e 100644 --- a/src/framework/graphics/customspriteshader.cpp +++ b/src/framework/graphics/customspriteshader.cpp @@ -1,45 +1,40 @@ #include "../debug.h" #include "customspriteshader.h" -#include "../support/text.h" -CustomSpriteShader::CustomSpriteShader(const char *vertexShaderSource, const char *fragmentShaderSource) - : SpriteShader() +CustomSpriteShader::CustomSpriteShader() { STACK_TRACE; - ASSERT(vertexShaderSource != NULL); - ASSERT(fragmentShaderSource != NULL); - - BOOL result = LoadCompileAndLink(vertexShaderSource, fragmentShaderSource); - ASSERT(result == TRUE); - - CacheShaderSources(vertexShaderSource, fragmentShaderSource); - - ASSERT(HasUniform(GetModelViewMatrixUniform()) == TRUE); - ASSERT(HasUniform(GetProjectionMatrixUniform()) == TRUE); - ASSERT(HasUniform(GetTextureHasAlphaOnlyUniform()) == TRUE); -} - -CustomSpriteShader::CustomSpriteShader(const Text *vertexShaderSource, const Text *fragmentShaderSource) - : SpriteShader() -{ - STACK_TRACE; - ASSERT(vertexShaderSource != NULL); - ASSERT(vertexShaderSource->GetLength() > 0); - ASSERT(fragmentShaderSource != NULL); - ASSERT(fragmentShaderSource->GetLength() > 0); - - BOOL result = LoadCompileAndLink(vertexShaderSource->GetText(), fragmentShaderSource->GetText()); - ASSERT(result == TRUE); - - CacheShaderSources(vertexShaderSource->GetText(), fragmentShaderSource->GetText()); - - ASSERT(HasUniform(GetModelViewMatrixUniform()) == TRUE); - ASSERT(HasUniform(GetProjectionMatrixUniform()) == TRUE); - ASSERT(HasUniform(GetTextureHasAlphaOnlyUniform()) == TRUE); } CustomSpriteShader::~CustomSpriteShader() { STACK_TRACE; } + +BOOL CustomSpriteShader::Initialize(GraphicsDevice *graphicsDevice, const char *vertexShaderSource, const char *fragmentShaderSource) +{ + STACK_TRACE; + if (!SpriteShader::Initialize(graphicsDevice, vertexShaderSource, fragmentShaderSource)) + return FALSE; + + ASSERT(HasUniform(GetModelViewMatrixUniform()) == TRUE); + ASSERT(HasUniform(GetProjectionMatrixUniform()) == TRUE); + ASSERT(HasUniform(GetTextureHasAlphaOnlyUniform()) == TRUE); + + return TRUE; +} + +BOOL CustomSpriteShader::Initialize(GraphicsDevice *graphicsDevice, const Text *vertexShaderSource, const Text *fragmentShaderSource) +{ + STACK_TRACE; + if (!SpriteShader::Initialize(graphicsDevice, vertexShaderSource, fragmentShaderSource)) + return FALSE; + + ASSERT(HasUniform(GetModelViewMatrixUniform()) == TRUE); + ASSERT(HasUniform(GetProjectionMatrixUniform()) == TRUE); + ASSERT(HasUniform(GetTextureHasAlphaOnlyUniform()) == TRUE); + + return TRUE; +} + diff --git a/src/framework/graphics/customspriteshader.h b/src/framework/graphics/customspriteshader.h index 9bb83df..96b0096 100644 --- a/src/framework/graphics/customspriteshader.h +++ b/src/framework/graphics/customspriteshader.h @@ -3,6 +3,7 @@ #include "spriteshader.h" +class GraphicsDevice; class Text; /** @@ -12,23 +13,28 @@ class Text; class CustomSpriteShader : public SpriteShader { public: - /** - * Creates a new shader object for rendering sprites using the given vertex - * and fragment shader sources. - * @param vertexShaderSource GLSL source for a vertex shader - * @param fragmentShaderSource GLSL source for a vertex shader - */ - CustomSpriteShader(const char *vertexShaderSource, const char *fragmentShaderSource); - - /** - * Creates a new shader object for rendering sprites using the given vertex - * and fragment shader sources. - * @param vertexShaderSource GLSL source for a vertex shader - * @param fragmentShaderSource GLSL source for a vertex shader - */ - CustomSpriteShader(const Text *vertexShaderSource, const Text *fragmentShaderSource); - + CustomSpriteShader(); virtual ~CustomSpriteShader(); + + /** + * Initializes the shader object for rendering sprites using the given vertex + * and fragment shader sources. + * @param graphicsDevice the graphics device to associate this shader with + * @param vertexShaderSource GLSL source for a vertex shader + * @param fragmentShaderSource GLSL source for a vertex shader + * @return TRUE if successful, FALSE if not + */ + BOOL Initialize(GraphicsDevice *graphicsDevice, const char *vertexShaderSource, const char *fragmentShaderSource); + + /** + * Initializes the shader object for rendering sprites using the given vertex + * and fragment shader sources. + * @param graphicsDevice the graphics device to associate this shader with + * @param vertexShaderSource GLSL source for a vertex shader + * @param fragmentShaderSource GLSL source for a vertex shader + * @return TRUE if successful, FALSE if not + */ + BOOL Initialize(GraphicsDevice *graphicsDevice, const Text *vertexShaderSource, const Text *fragmentShaderSource); }; #endif diff --git a/src/framework/graphics/customstandardshader.cpp b/src/framework/graphics/customstandardshader.cpp index 1c7ead1..e00770d 100644 --- a/src/framework/graphics/customstandardshader.cpp +++ b/src/framework/graphics/customstandardshader.cpp @@ -1,43 +1,37 @@ #include "../debug.h" #include "customstandardshader.h" -#include "../support/text.h" -CustomStandardShader::CustomStandardShader(const char *vertexShaderSource, const char *fragmentShaderSource) - : StandardShader() +CustomStandardShader::CustomStandardShader() { STACK_TRACE; - ASSERT(vertexShaderSource != NULL); - ASSERT(fragmentShaderSource != NULL); - - BOOL result = LoadCompileAndLink(vertexShaderSource, fragmentShaderSource); - ASSERT(result == TRUE); - - CacheShaderSources(vertexShaderSource, fragmentShaderSource); - - ASSERT(HasUniform(GetModelViewMatrixUniform()) == TRUE); - ASSERT(HasUniform(GetProjectionMatrixUniform()) == TRUE); -} - -CustomStandardShader::CustomStandardShader(const Text *vertexShaderSource, const Text *fragmentShaderSource) - : StandardShader() -{ - STACK_TRACE; - ASSERT(vertexShaderSource != NULL); - ASSERT(vertexShaderSource->GetLength() > 0); - ASSERT(fragmentShaderSource != NULL); - ASSERT(fragmentShaderSource->GetLength() > 0); - - BOOL result = LoadCompileAndLink(vertexShaderSource->GetText(), fragmentShaderSource->GetText()); - ASSERT(result == TRUE); - - CacheShaderSources(vertexShaderSource->GetText(), fragmentShaderSource->GetText()); - - ASSERT(HasUniform(GetModelViewMatrixUniform()) == TRUE); - ASSERT(HasUniform(GetProjectionMatrixUniform()) == TRUE); } CustomStandardShader::~CustomStandardShader() { STACK_TRACE; } + +BOOL CustomStandardShader::Initialize(GraphicsDevice *graphicsDevice, const char *vertexShaderSource, const char *fragmentShaderSource) +{ + STACK_TRACE; + if (!StandardShader::Initialize(graphicsDevice, vertexShaderSource, fragmentShaderSource)) + return FALSE; + + ASSERT(HasUniform(GetModelViewMatrixUniform()) == TRUE); + ASSERT(HasUniform(GetProjectionMatrixUniform()) == TRUE); + + return TRUE; +} + +BOOL CustomStandardShader::Initialize(GraphicsDevice *graphicsDevice, const Text *vertexShaderSource, const Text *fragmentShaderSource) +{ + STACK_TRACE; + if (!StandardShader::Initialize(graphicsDevice, vertexShaderSource, fragmentShaderSource)) + return FALSE; + + ASSERT(HasUniform(GetModelViewMatrixUniform()) == TRUE); + ASSERT(HasUniform(GetProjectionMatrixUniform()) == TRUE); + + return TRUE; +} diff --git a/src/framework/graphics/customstandardshader.h b/src/framework/graphics/customstandardshader.h index 7973935..0065236 100644 --- a/src/framework/graphics/customstandardshader.h +++ b/src/framework/graphics/customstandardshader.h @@ -3,6 +3,7 @@ #include "standardshader.h" +class GraphicsDevice; class Text; /** @@ -11,23 +12,28 @@ class Text; class CustomStandardShader : public StandardShader { public: - /** - * Creates a new shader object using the given vertex and fragment shader - * sources. - * @param vertexShaderSource GLSL source for a vertex shader - * @param fragmentShaderSource GLSL source for a vertex shader - */ - CustomStandardShader(const char *vertexShaderSource, const char *fragmentShaderSource); - - /** - * Creates a new shader object using the given vertex and fragment shader - * sources. - * @param vertexShaderSource GLSL source for a vertex shader - * @param fragmentShaderSource GLSL source for a vertex shader - */ - CustomStandardShader(const Text *vertexShaderSource, const Text *fragmentShaderSource); - + CustomStandardShader(); virtual ~CustomStandardShader(); + + /** + * Initializes the shader object using the given vertex and fragment shader + * sources. + * @param graphicsDevice the graphics device to associate this shader with + * @param vertexShaderSource GLSL source for a vertex shader + * @param fragmentShaderSource GLSL source for a vertex shader + * @return TRUE if successful, FALSE if not + */ + BOOL Initialize(GraphicsDevice *graphicsDevice, const char *vertexShaderSource, const char *fragmentShaderSource); + + /** + * Initializes the shader object using the given vertex and fragment shader + * sources. + * @param graphicsDevice the graphics device to associate this shader with + * @param vertexShaderSource GLSL source for a vertex shader + * @param fragmentShaderSource GLSL source for a vertex shader + * @return TRUE if successful, FALSE if not + */ + BOOL Initialize(GraphicsDevice *graphicsDevice, const Text *vertexShaderSource, const Text *fragmentShaderSource); }; #endif diff --git a/src/framework/graphics/customvertexlerpshader.cpp b/src/framework/graphics/customvertexlerpshader.cpp index 9d3b67f..a16f6c2 100644 --- a/src/framework/graphics/customvertexlerpshader.cpp +++ b/src/framework/graphics/customvertexlerpshader.cpp @@ -1,45 +1,39 @@ #include "../debug.h" #include "customvertexlerpshader.h" -#include "../support/text.h" -CustomVertexLerpShader::CustomVertexLerpShader(const char *vertexShaderSource, const char *fragmentShaderSource) - : VertexLerpShader() +CustomVertexLerpShader::CustomVertexLerpShader() { STACK_TRACE; - ASSERT(vertexShaderSource != NULL); - ASSERT(fragmentShaderSource != NULL); - - BOOL result = LoadCompileAndLink(vertexShaderSource, fragmentShaderSource); - ASSERT(result == TRUE); - - CacheShaderSources(vertexShaderSource, fragmentShaderSource); - - ASSERT(HasUniform(GetModelViewMatrixUniform()) == TRUE); - ASSERT(HasUniform(GetProjectionMatrixUniform()) == TRUE); - ASSERT(HasUniform(GetLerpUniform()) == TRUE); -} - -CustomVertexLerpShader::CustomVertexLerpShader(const Text *vertexShaderSource, const Text *fragmentShaderSource) - : VertexLerpShader() -{ - STACK_TRACE; - ASSERT(vertexShaderSource != NULL); - ASSERT(vertexShaderSource->GetLength() > 0); - ASSERT(fragmentShaderSource != NULL); - ASSERT(fragmentShaderSource->GetLength() > 0); - - BOOL result = LoadCompileAndLink(vertexShaderSource->GetText(), fragmentShaderSource->GetText()); - ASSERT(result == TRUE); - - CacheShaderSources(vertexShaderSource->GetText(), fragmentShaderSource->GetText()); - - ASSERT(HasUniform(GetModelViewMatrixUniform()) == TRUE); - ASSERT(HasUniform(GetProjectionMatrixUniform()) == TRUE); - ASSERT(HasUniform(GetLerpUniform()) == TRUE); } CustomVertexLerpShader::~CustomVertexLerpShader() { STACK_TRACE; } + +BOOL CustomVertexLerpShader::Initialize(GraphicsDevice *graphicsDevice, const char *vertexShaderSource, const char *fragmentShaderSource) +{ + STACK_TRACE; + if (!VertexLerpShader::Initialize(graphicsDevice, vertexShaderSource, fragmentShaderSource)) + return FALSE; + + ASSERT(HasUniform(GetModelViewMatrixUniform()) == TRUE); + ASSERT(HasUniform(GetProjectionMatrixUniform()) == TRUE); + ASSERT(HasUniform(GetLerpUniform()) == TRUE); + + return TRUE; +} + +BOOL CustomVertexLerpShader::Initialize(GraphicsDevice *graphicsDevice, const Text *vertexShaderSource, const Text *fragmentShaderSource) +{ + STACK_TRACE; + if (!VertexLerpShader::Initialize(graphicsDevice, vertexShaderSource, fragmentShaderSource)) + return FALSE; + + ASSERT(HasUniform(GetModelViewMatrixUniform()) == TRUE); + ASSERT(HasUniform(GetProjectionMatrixUniform()) == TRUE); + ASSERT(HasUniform(GetLerpUniform()) == TRUE); + + return TRUE; +} diff --git a/src/framework/graphics/customvertexlerpshader.h b/src/framework/graphics/customvertexlerpshader.h index 002b906..823665e 100644 --- a/src/framework/graphics/customvertexlerpshader.h +++ b/src/framework/graphics/customvertexlerpshader.h @@ -3,16 +3,17 @@ #include "vertexlerpshader.h" +class GraphicsDevice; class Text; class CustomVertexLerpShader : public VertexLerpShader { public: - CustomVertexLerpShader(const char *vertexShaderSource, const char *fragmentShaderSource); - - CustomVertexLerpShader(const Text *vertexShaderSource, const Text *fragmentShaderSource); - + CustomVertexLerpShader(); virtual ~CustomVertexLerpShader(); + + BOOL Initialize(GraphicsDevice *graphicsDevice, const char *vertexShaderSource, const char *fragmentShaderSource); + BOOL Initialize(GraphicsDevice *graphicsDevice, const Text *vertexShaderSource, const Text *fragmentShaderSource); }; #endif diff --git a/src/framework/graphics/customvertexskinningshader.cpp b/src/framework/graphics/customvertexskinningshader.cpp index 3b10715..4e63d43 100644 --- a/src/framework/graphics/customvertexskinningshader.cpp +++ b/src/framework/graphics/customvertexskinningshader.cpp @@ -3,45 +3,40 @@ #include "customvertexskinningshader.h" #include "../support/text.h" -CustomVertexSkinningShader::CustomVertexSkinningShader(const char *vertexShaderSource, const char *fragmentShaderSource) - : VertexSkinningShader() +CustomVertexSkinningShader::CustomVertexSkinningShader() { STACK_TRACE; - ASSERT(vertexShaderSource != NULL); - ASSERT(fragmentShaderSource != NULL); - - BOOL result = LoadCompileAndLink(vertexShaderSource, fragmentShaderSource); - ASSERT(result == TRUE); - - CacheShaderSources(vertexShaderSource, fragmentShaderSource); - - ASSERT(HasUniform(GetModelViewMatrixUniform()) == TRUE); - ASSERT(HasUniform(GetProjectionMatrixUniform()) == TRUE); - ASSERT(HasUniform(GetJointPositionsUniform()) == TRUE); - ASSERT(HasUniform(GetJointRotationsUniform()) == TRUE); -} - -CustomVertexSkinningShader::CustomVertexSkinningShader(const Text *vertexShaderSource, const Text *fragmentShaderSource) - : VertexSkinningShader() -{ - STACK_TRACE; - ASSERT(vertexShaderSource != NULL); - ASSERT(vertexShaderSource->GetLength() > 0); - ASSERT(fragmentShaderSource != NULL); - ASSERT(fragmentShaderSource->GetLength() > 0); - - BOOL result = LoadCompileAndLink(vertexShaderSource->GetText(), fragmentShaderSource->GetText()); - ASSERT(result == TRUE); - - CacheShaderSources(vertexShaderSource->GetText(), fragmentShaderSource->GetText()); - - ASSERT(HasUniform(GetModelViewMatrixUniform()) == TRUE); - ASSERT(HasUniform(GetProjectionMatrixUniform()) == TRUE); - ASSERT(HasUniform(GetJointPositionsUniform()) == TRUE); - ASSERT(HasUniform(GetJointRotationsUniform()) == TRUE); } CustomVertexSkinningShader::~CustomVertexSkinningShader() { STACK_TRACE; } + +BOOL CustomVertexSkinningShader::Initialize(GraphicsDevice *graphicsDevice, const char *vertexShaderSource, const char *fragmentShaderSource) +{ + STACK_TRACE; + if (!VertexSkinningShader::Initialize(graphicsDevice, vertexShaderSource, fragmentShaderSource)) + return FALSE; + + ASSERT(HasUniform(GetModelViewMatrixUniform()) == TRUE); + ASSERT(HasUniform(GetProjectionMatrixUniform()) == TRUE); + ASSERT(HasUniform(GetJointPositionsUniform()) == TRUE); + ASSERT(HasUniform(GetJointRotationsUniform()) == TRUE); + + return TRUE; +} + +BOOL CustomVertexSkinningShader::Initialize(GraphicsDevice *graphicsDevice, const Text *vertexShaderSource, const Text *fragmentShaderSource) +{ + STACK_TRACE; + if (!VertexSkinningShader::Initialize(graphicsDevice, vertexShaderSource, fragmentShaderSource)) + return FALSE; + + ASSERT(HasUniform(GetModelViewMatrixUniform()) == TRUE); + ASSERT(HasUniform(GetProjectionMatrixUniform()) == TRUE); + ASSERT(HasUniform(GetJointPositionsUniform()) == TRUE); + ASSERT(HasUniform(GetJointRotationsUniform()) == TRUE); + + return TRUE; +} diff --git a/src/framework/graphics/customvertexskinningshader.h b/src/framework/graphics/customvertexskinningshader.h index 0a27aa8..4633d9b 100644 --- a/src/framework/graphics/customvertexskinningshader.h +++ b/src/framework/graphics/customvertexskinningshader.h @@ -3,16 +3,17 @@ #include "vertexskinningshader.h" +class GraphicsDevice; class Text; class CustomVertexSkinningShader : public VertexSkinningShader { public: - CustomVertexSkinningShader(const char *vertexShaderSource, const char *fragmentShaderSource); - - CustomVertexSkinningShader(const Text *vertexShaderSource, const Text *fragmentShaderSource); - + CustomVertexSkinningShader(); virtual ~CustomVertexSkinningShader(); + + BOOL Initialize(GraphicsDevice *graphicsDevice, const char *vertexShaderSource, const char *fragmentShaderSource); + BOOL Initialize(GraphicsDevice *graphicsDevice, const Text *vertexShaderSource, const Text *fragmentShaderSource); }; #endif diff --git a/src/framework/graphics/debugshader.cpp b/src/framework/graphics/debugshader.cpp index 475d0ff..87a6bc9 100644 --- a/src/framework/graphics/debugshader.cpp +++ b/src/framework/graphics/debugshader.cpp @@ -31,17 +31,26 @@ const char* DebugShader::m_fragmentShaderSource = "}\n"; DebugShader::DebugShader() - : StandardShader() { STACK_TRACE; - BOOL result = LoadCompileAndLinkInlineSources(m_vertexShaderSource, m_fragmentShaderSource); - ASSERT(result == TRUE); - - MapAttributeToStandardAttribType("a_position", VERTEX_STD_POS_3D); - MapAttributeToStandardAttribType("a_color", VERTEX_STD_COLOR); } DebugShader::~DebugShader() { STACK_TRACE; } + +BOOL DebugShader::Initialize(GraphicsDevice *graphicsDevice) +{ + STACK_TRACE; + if (!StandardShader::Initialize(graphicsDevice)) + return FALSE; + + BOOL result = LoadCompileAndLinkInlineSources(m_vertexShaderSource, m_fragmentShaderSource); + ASSERT(result == TRUE); + + MapAttributeToStandardAttribType("a_position", VERTEX_STD_POS_3D); + MapAttributeToStandardAttribType("a_color", VERTEX_STD_COLOR); + + return TRUE; +} diff --git a/src/framework/graphics/debugshader.h b/src/framework/graphics/debugshader.h index 8c27f71..75477bb 100644 --- a/src/framework/graphics/debugshader.h +++ b/src/framework/graphics/debugshader.h @@ -3,6 +3,8 @@ #include "standardshader.h" +class GraphicsDevice; + /** * Shader for rendering debug geometry. Will render using solid colors * with thicker lines and larger point sizes. @@ -12,6 +14,8 @@ class DebugShader : public StandardShader public: DebugShader(); virtual ~DebugShader(); + + BOOL Initialize(GraphicsDevice *graphicsDevice); private: static const char *m_vertexShaderSource; diff --git a/src/framework/graphics/simplecolorshader.cpp b/src/framework/graphics/simplecolorshader.cpp index 984b1d8..c50a1e8 100644 --- a/src/framework/graphics/simplecolorshader.cpp +++ b/src/framework/graphics/simplecolorshader.cpp @@ -30,17 +30,26 @@ const char* SimpleColorShader::m_fragmentShaderSource = "}\n"; SimpleColorShader::SimpleColorShader() - : StandardShader() { STACK_TRACE; - BOOL result = LoadCompileAndLinkInlineSources(m_vertexShaderSource, m_fragmentShaderSource); - ASSERT(result == TRUE); - - MapAttributeToStandardAttribType("a_position", VERTEX_STD_POS_3D); - MapAttributeToStandardAttribType("a_color", VERTEX_STD_COLOR); } SimpleColorShader::~SimpleColorShader() { STACK_TRACE; } + +BOOL SimpleColorShader::Initialize(GraphicsDevice *graphicsDevice) +{ + STACK_TRACE; + if (!StandardShader::Initialize(graphicsDevice)) + return FALSE; + + BOOL result = LoadCompileAndLinkInlineSources(m_vertexShaderSource, m_fragmentShaderSource); + ASSERT(result == TRUE); + + MapAttributeToStandardAttribType("a_position", VERTEX_STD_POS_3D); + MapAttributeToStandardAttribType("a_color", VERTEX_STD_COLOR); + + return TRUE; +} diff --git a/src/framework/graphics/simplecolorshader.h b/src/framework/graphics/simplecolorshader.h index 382d75f..8909448 100644 --- a/src/framework/graphics/simplecolorshader.h +++ b/src/framework/graphics/simplecolorshader.h @@ -3,6 +3,8 @@ #include "standardshader.h" +class GraphicsDevice; + /** * Shader which renders geometry with vertex colors but no textures. */ @@ -11,6 +13,8 @@ class SimpleColorShader : public StandardShader public: SimpleColorShader(); virtual ~SimpleColorShader(); + + BOOL Initialize(GraphicsDevice *graphicsDevice); private: static const char *m_vertexShaderSource; diff --git a/src/framework/graphics/simplecolortextureshader.cpp b/src/framework/graphics/simplecolortextureshader.cpp index 581bf27..f1f134f 100644 --- a/src/framework/graphics/simplecolortextureshader.cpp +++ b/src/framework/graphics/simplecolortextureshader.cpp @@ -35,18 +35,27 @@ const char* SimpleColorTextureShader::m_fragmentShaderSource = "}\n"; SimpleColorTextureShader::SimpleColorTextureShader() - : StandardShader() { STACK_TRACE; - BOOL result = LoadCompileAndLinkInlineSources(m_vertexShaderSource, m_fragmentShaderSource); - ASSERT(result == TRUE); - - MapAttributeToStandardAttribType("a_position", VERTEX_STD_POS_3D); - MapAttributeToStandardAttribType("a_color", VERTEX_STD_COLOR); - MapAttributeToStandardAttribType("a_texcoord0", VERTEX_STD_TEXCOORD); } SimpleColorTextureShader::~SimpleColorTextureShader() { STACK_TRACE; } + +BOOL SimpleColorTextureShader::Initialize(GraphicsDevice *graphicsDevice) +{ + STACK_TRACE; + if (!StandardShader::Initialize(graphicsDevice)) + return FALSE; + + BOOL result = LoadCompileAndLinkInlineSources(m_vertexShaderSource, m_fragmentShaderSource); + ASSERT(result == TRUE); + + MapAttributeToStandardAttribType("a_position", VERTEX_STD_POS_3D); + MapAttributeToStandardAttribType("a_color", VERTEX_STD_COLOR); + MapAttributeToStandardAttribType("a_texcoord0", VERTEX_STD_TEXCOORD); + + return TRUE; +} diff --git a/src/framework/graphics/simplecolortextureshader.h b/src/framework/graphics/simplecolortextureshader.h index 6bf7695..4625fcd 100644 --- a/src/framework/graphics/simplecolortextureshader.h +++ b/src/framework/graphics/simplecolortextureshader.h @@ -3,6 +3,8 @@ #include "standardshader.h" +class GraphicsDevice; + /** * Shader which renders geometry using vertex colors modulated with a texture. */ @@ -11,6 +13,8 @@ class SimpleColorTextureShader : public StandardShader public: SimpleColorTextureShader(); virtual ~SimpleColorTextureShader(); + + BOOL Initialize(GraphicsDevice *graphicsDevice); private: static const char *m_vertexShaderSource; diff --git a/src/framework/graphics/simpletextureshader.cpp b/src/framework/graphics/simpletextureshader.cpp index 9389077..32da3c9 100644 --- a/src/framework/graphics/simpletextureshader.cpp +++ b/src/framework/graphics/simpletextureshader.cpp @@ -28,18 +28,28 @@ const char* SimpleTextureShader::m_fragmentShaderSource = " gl_FragColor = texture2D(u_texture, v_texCoords);\n" "}\n"; + SimpleTextureShader::SimpleTextureShader() - : StandardShader() { STACK_TRACE; - BOOL result = LoadCompileAndLinkInlineSources(m_vertexShaderSource, m_fragmentShaderSource); - ASSERT(result == TRUE); - - MapAttributeToStandardAttribType("a_position", VERTEX_STD_POS_3D); - MapAttributeToStandardAttribType("a_texcoord0", VERTEX_STD_TEXCOORD); } SimpleTextureShader::~SimpleTextureShader() { STACK_TRACE; } + +BOOL SimpleTextureShader::Initialize(GraphicsDevice *graphicsDevice) +{ + STACK_TRACE; + if (!StandardShader::Initialize(graphicsDevice)) + return FALSE; + + BOOL result = LoadCompileAndLinkInlineSources(m_vertexShaderSource, m_fragmentShaderSource); + ASSERT(result == TRUE); + + MapAttributeToStandardAttribType("a_position", VERTEX_STD_POS_3D); + MapAttributeToStandardAttribType("a_texcoord0", VERTEX_STD_TEXCOORD); + + return TRUE; +} diff --git a/src/framework/graphics/simpletextureshader.h b/src/framework/graphics/simpletextureshader.h index 62983b9..cb3691f 100644 --- a/src/framework/graphics/simpletextureshader.h +++ b/src/framework/graphics/simpletextureshader.h @@ -3,6 +3,8 @@ #include "standardshader.h" +class GraphicsDevice; + /** * Shader which renders geometry with texturing but no vertex colors. */ @@ -11,6 +13,8 @@ class SimpleTextureShader : public StandardShader public: SimpleTextureShader(); virtual ~SimpleTextureShader(); + + BOOL Initialize(GraphicsDevice *graphicsDevice); private: static const char *m_vertexShaderSource; diff --git a/src/framework/graphics/simpletexturevertexlerpshader.cpp b/src/framework/graphics/simpletexturevertexlerpshader.cpp index 79d9930..8d207d6 100644 --- a/src/framework/graphics/simpletexturevertexlerpshader.cpp +++ b/src/framework/graphics/simpletexturevertexlerpshader.cpp @@ -31,18 +31,27 @@ const char* SimpleTextureVertexLerpShader::m_fragmentShaderSource = "}\n"; SimpleTextureVertexLerpShader::SimpleTextureVertexLerpShader() - : VertexLerpShader() { STACK_TRACE; - BOOL result = LoadCompileAndLinkInlineSources(m_vertexShaderSource, m_fragmentShaderSource); - ASSERT(result == TRUE); - - MapAttributeToVboAttribIndex("a_position1", 0); - MapAttributeToVboAttribIndex("a_position2", 1); - MapAttributeToStandardAttribType("a_texcoord0", VERTEX_STD_TEXCOORD); } SimpleTextureVertexLerpShader::~SimpleTextureVertexLerpShader() { STACK_TRACE; } + +BOOL SimpleTextureVertexLerpShader::Initialize(GraphicsDevice *graphicsDevice) +{ + STACK_TRACE; + if (!VertexLerpShader::Initialize(graphicsDevice)) + return FALSE; + + BOOL result = LoadCompileAndLinkInlineSources(m_vertexShaderSource, m_fragmentShaderSource); + ASSERT(result == TRUE); + + MapAttributeToVboAttribIndex("a_position1", 0); + MapAttributeToVboAttribIndex("a_position2", 1); + MapAttributeToStandardAttribType("a_texcoord0", VERTEX_STD_TEXCOORD); + + return TRUE; +} diff --git a/src/framework/graphics/simpletexturevertexlerpshader.h b/src/framework/graphics/simpletexturevertexlerpshader.h index 7d7f5bd..292639f 100644 --- a/src/framework/graphics/simpletexturevertexlerpshader.h +++ b/src/framework/graphics/simpletexturevertexlerpshader.h @@ -3,11 +3,15 @@ #include "vertexlerpshader.h" +class GraphicsDevice; + class SimpleTextureVertexLerpShader : public VertexLerpShader { public: SimpleTextureVertexLerpShader(); virtual ~SimpleTextureVertexLerpShader(); + + BOOL Initialize(GraphicsDevice *graphicsDevice); private: static const char *m_vertexShaderSource; diff --git a/src/framework/graphics/simpletexturevertexskinningshader.cpp b/src/framework/graphics/simpletexturevertexskinningshader.cpp index ca3a4d0..73b47b4 100644 --- a/src/framework/graphics/simpletexturevertexskinningshader.cpp +++ b/src/framework/graphics/simpletexturevertexskinningshader.cpp @@ -49,18 +49,27 @@ const char* SimpleTextureVertexSkinningShader::m_fragmentShaderSource = "}\n"; SimpleTextureVertexSkinningShader::SimpleTextureVertexSkinningShader() - : VertexSkinningShader() { STACK_TRACE; - BOOL result = LoadCompileAndLinkInlineSources(m_vertexShaderSource, m_fragmentShaderSource); - ASSERT(result == TRUE); - - MapAttributeToVboAttribIndex("a_jointIndex", 0); - MapAttributeToStandardAttribType("a_position", VERTEX_STD_POS_3D); - MapAttributeToStandardAttribType("a_texcoord0", VERTEX_STD_TEXCOORD); } SimpleTextureVertexSkinningShader::~SimpleTextureVertexSkinningShader() { STACK_TRACE; } + +BOOL SimpleTextureVertexSkinningShader::Initialize(GraphicsDevice *graphicsDevice) +{ + STACK_TRACE; + if (!VertexSkinningShader::Initialize(graphicsDevice)) + return FALSE; + + BOOL result = LoadCompileAndLinkInlineSources(m_vertexShaderSource, m_fragmentShaderSource); + ASSERT(result == TRUE); + + MapAttributeToVboAttribIndex("a_jointIndex", 0); + MapAttributeToStandardAttribType("a_position", VERTEX_STD_POS_3D); + MapAttributeToStandardAttribType("a_texcoord0", VERTEX_STD_TEXCOORD); + + return TRUE; +} diff --git a/src/framework/graphics/simpletexturevertexskinningshader.h b/src/framework/graphics/simpletexturevertexskinningshader.h index 036380f..0f1bc97 100644 --- a/src/framework/graphics/simpletexturevertexskinningshader.h +++ b/src/framework/graphics/simpletexturevertexskinningshader.h @@ -3,12 +3,16 @@ #include "vertexskinningshader.h" +class GraphicsDevice; + class SimpleTextureVertexSkinningShader : public VertexSkinningShader { public: SimpleTextureVertexSkinningShader(); virtual ~SimpleTextureVertexSkinningShader(); + BOOL Initialize(GraphicsDevice *graphicsDevice); + private: static const char *m_vertexShaderSource; static const char *m_fragmentShaderSource; diff --git a/src/framework/graphics/sprite2dshader.cpp b/src/framework/graphics/sprite2dshader.cpp index bfb439f..d945534 100644 --- a/src/framework/graphics/sprite2dshader.cpp +++ b/src/framework/graphics/sprite2dshader.cpp @@ -41,18 +41,27 @@ const char* Sprite2DShader::m_fragmentShaderSource = "}\n"; Sprite2DShader::Sprite2DShader() - : SpriteShader() { STACK_TRACE; - BOOL result = LoadCompileAndLinkInlineSources(m_vertexShaderSource, m_fragmentShaderSource); - ASSERT(result == TRUE); - - MapAttributeToStandardAttribType("a_position", VERTEX_STD_POS_2D); - MapAttributeToStandardAttribType("a_color", VERTEX_STD_COLOR); - MapAttributeToStandardAttribType("a_texcoord0", VERTEX_STD_TEXCOORD); } Sprite2DShader::~Sprite2DShader() { STACK_TRACE; } + +BOOL Sprite2DShader::Initialize(GraphicsDevice *graphicsDevice) +{ + STACK_TRACE; + if (!SpriteShader::Initialize(graphicsDevice)) + return FALSE; + + BOOL result = LoadCompileAndLinkInlineSources(m_vertexShaderSource, m_fragmentShaderSource); + ASSERT(result == TRUE); + + MapAttributeToStandardAttribType("a_position", VERTEX_STD_POS_2D); + MapAttributeToStandardAttribType("a_color", VERTEX_STD_COLOR); + MapAttributeToStandardAttribType("a_texcoord0", VERTEX_STD_TEXCOORD); + + return TRUE; +} diff --git a/src/framework/graphics/sprite2dshader.h b/src/framework/graphics/sprite2dshader.h index a8649c2..7c6155b 100644 --- a/src/framework/graphics/sprite2dshader.h +++ b/src/framework/graphics/sprite2dshader.h @@ -3,6 +3,8 @@ #include "spriteshader.h" +class GraphicsDevice; + /** * Shader for rendering 2D sprites with vertex color modulation. Includes * special support for color modulation using RGB, RGBA, and alpha-only @@ -13,6 +15,8 @@ class Sprite2DShader : public SpriteShader public: Sprite2DShader(); virtual ~Sprite2DShader(); + + BOOL Initialize(GraphicsDevice *graphicsDevice); private: static const char *m_vertexShaderSource; diff --git a/src/framework/graphics/sprite3dshader.cpp b/src/framework/graphics/sprite3dshader.cpp index c383cca..4b5a54c 100644 --- a/src/framework/graphics/sprite3dshader.cpp +++ b/src/framework/graphics/sprite3dshader.cpp @@ -47,18 +47,27 @@ const char* Sprite3DShader::m_fragmentShaderSource = "}\n"; Sprite3DShader::Sprite3DShader() - : SpriteShader() { STACK_TRACE; - BOOL result = LoadCompileAndLinkInlineSources(m_vertexShaderSource, m_fragmentShaderSource); - ASSERT(result == TRUE); - - MapAttributeToStandardAttribType("a_position", VERTEX_STD_POS_3D); - MapAttributeToStandardAttribType("a_color", VERTEX_STD_COLOR); - MapAttributeToStandardAttribType("a_texcoord0", VERTEX_STD_TEXCOORD); } Sprite3DShader::~Sprite3DShader() { STACK_TRACE; } + +BOOL Sprite3DShader::Initialize(GraphicsDevice *graphicsDevice) +{ + STACK_TRACE; + if (!SpriteShader::Initialize(graphicsDevice)) + return FALSE; + + BOOL result = LoadCompileAndLinkInlineSources(m_vertexShaderSource, m_fragmentShaderSource); + ASSERT(result == TRUE); + + MapAttributeToStandardAttribType("a_position", VERTEX_STD_POS_3D); + MapAttributeToStandardAttribType("a_color", VERTEX_STD_COLOR); + MapAttributeToStandardAttribType("a_texcoord0", VERTEX_STD_TEXCOORD); + + return TRUE; +} diff --git a/src/framework/graphics/sprite3dshader.h b/src/framework/graphics/sprite3dshader.h index 48bd82f..0f3553c 100644 --- a/src/framework/graphics/sprite3dshader.h +++ b/src/framework/graphics/sprite3dshader.h @@ -3,6 +3,8 @@ #include "spriteshader.h" +class GraphicsDevice; + /** * Shader for rendering 3D billboard sprites with vertex color modulation. * Includes special support for color modulation using RGB, RGBA, and @@ -14,6 +16,8 @@ class Sprite3DShader : public SpriteShader public: Sprite3DShader(); virtual ~Sprite3DShader(); + + BOOL Initialize(GraphicsDevice *graphicsDevice); private: static const char *m_vertexShaderSource; diff --git a/src/framework/graphics/spriteshader.cpp b/src/framework/graphics/spriteshader.cpp index f9a61d1..608ef09 100644 --- a/src/framework/graphics/spriteshader.cpp +++ b/src/framework/graphics/spriteshader.cpp @@ -3,7 +3,6 @@ #include "spriteshader.h" SpriteShader::SpriteShader() - : StandardShader() { STACK_TRACE; SetTextureHasAlphaOnlyUniform("u_textureHasAlphaOnly"); diff --git a/src/framework/graphics/standardshader.cpp b/src/framework/graphics/standardshader.cpp index 299f90f..66860c8 100644 --- a/src/framework/graphics/standardshader.cpp +++ b/src/framework/graphics/standardshader.cpp @@ -4,7 +4,6 @@ #include "../math/matrix4x4.h" StandardShader::StandardShader() - : Shader() { STACK_TRACE; m_inlineVertexShaderSource = NULL; diff --git a/src/framework/graphics/vertexlerpshader.cpp b/src/framework/graphics/vertexlerpshader.cpp index 0f2e702..0f37381 100644 --- a/src/framework/graphics/vertexlerpshader.cpp +++ b/src/framework/graphics/vertexlerpshader.cpp @@ -3,7 +3,6 @@ #include "vertexlerpshader.h" VertexLerpShader::VertexLerpShader() - : StandardShader() { STACK_TRACE; SetLerpUniform("u_lerp"); diff --git a/src/framework/graphics/vertexskinningshader.cpp b/src/framework/graphics/vertexskinningshader.cpp index 8e49221..935c3fe 100644 --- a/src/framework/graphics/vertexskinningshader.cpp +++ b/src/framework/graphics/vertexskinningshader.cpp @@ -5,7 +5,6 @@ #include "../math/vector3.h" VertexSkinningShader::VertexSkinningShader() - : StandardShader() { STACK_TRACE; SetJointPositionsUniform("u_jointPositions");