update all shader subclasses to use Initialize() methods for all complex initialization instead of the constructor

This commit is contained in:
Gered 2013-04-01 19:32:11 -04:00
parent 6a5444abe0
commit 543e6bf409
28 changed files with 321 additions and 228 deletions

View file

@ -1,45 +1,40 @@
#include "../debug.h" #include "../debug.h"
#include "customspriteshader.h" #include "customspriteshader.h"
#include "../support/text.h"
CustomSpriteShader::CustomSpriteShader(const char *vertexShaderSource, const char *fragmentShaderSource) CustomSpriteShader::CustomSpriteShader()
: SpriteShader()
{ {
STACK_TRACE; 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() CustomSpriteShader::~CustomSpriteShader()
{ {
STACK_TRACE; 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;
}

View file

@ -3,6 +3,7 @@
#include "spriteshader.h" #include "spriteshader.h"
class GraphicsDevice;
class Text; class Text;
/** /**
@ -12,23 +13,28 @@ class Text;
class CustomSpriteShader : public SpriteShader class CustomSpriteShader : public SpriteShader
{ {
public: public:
/** CustomSpriteShader();
* 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);
virtual ~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 #endif

View file

@ -1,43 +1,37 @@
#include "../debug.h" #include "../debug.h"
#include "customstandardshader.h" #include "customstandardshader.h"
#include "../support/text.h"
CustomStandardShader::CustomStandardShader(const char *vertexShaderSource, const char *fragmentShaderSource) CustomStandardShader::CustomStandardShader()
: StandardShader()
{ {
STACK_TRACE; 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() CustomStandardShader::~CustomStandardShader()
{ {
STACK_TRACE; 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;
}

View file

@ -3,6 +3,7 @@
#include "standardshader.h" #include "standardshader.h"
class GraphicsDevice;
class Text; class Text;
/** /**
@ -11,23 +12,28 @@ class Text;
class CustomStandardShader : public StandardShader class CustomStandardShader : public StandardShader
{ {
public: public:
/** CustomStandardShader();
* 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);
virtual ~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 #endif

View file

@ -1,45 +1,39 @@
#include "../debug.h" #include "../debug.h"
#include "customvertexlerpshader.h" #include "customvertexlerpshader.h"
#include "../support/text.h"
CustomVertexLerpShader::CustomVertexLerpShader(const char *vertexShaderSource, const char *fragmentShaderSource) CustomVertexLerpShader::CustomVertexLerpShader()
: VertexLerpShader()
{ {
STACK_TRACE; 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() CustomVertexLerpShader::~CustomVertexLerpShader()
{ {
STACK_TRACE; 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;
}

View file

@ -3,16 +3,17 @@
#include "vertexlerpshader.h" #include "vertexlerpshader.h"
class GraphicsDevice;
class Text; class Text;
class CustomVertexLerpShader : public VertexLerpShader class CustomVertexLerpShader : public VertexLerpShader
{ {
public: public:
CustomVertexLerpShader(const char *vertexShaderSource, const char *fragmentShaderSource); CustomVertexLerpShader();
CustomVertexLerpShader(const Text *vertexShaderSource, const Text *fragmentShaderSource);
virtual ~CustomVertexLerpShader(); virtual ~CustomVertexLerpShader();
BOOL Initialize(GraphicsDevice *graphicsDevice, const char *vertexShaderSource, const char *fragmentShaderSource);
BOOL Initialize(GraphicsDevice *graphicsDevice, const Text *vertexShaderSource, const Text *fragmentShaderSource);
}; };
#endif #endif

View file

@ -3,45 +3,40 @@
#include "customvertexskinningshader.h" #include "customvertexskinningshader.h"
#include "../support/text.h" #include "../support/text.h"
CustomVertexSkinningShader::CustomVertexSkinningShader(const char *vertexShaderSource, const char *fragmentShaderSource) CustomVertexSkinningShader::CustomVertexSkinningShader()
: VertexSkinningShader()
{ {
STACK_TRACE; 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() CustomVertexSkinningShader::~CustomVertexSkinningShader()
{ {
STACK_TRACE; 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;
}

View file

@ -3,16 +3,17 @@
#include "vertexskinningshader.h" #include "vertexskinningshader.h"
class GraphicsDevice;
class Text; class Text;
class CustomVertexSkinningShader : public VertexSkinningShader class CustomVertexSkinningShader : public VertexSkinningShader
{ {
public: public:
CustomVertexSkinningShader(const char *vertexShaderSource, const char *fragmentShaderSource); CustomVertexSkinningShader();
CustomVertexSkinningShader(const Text *vertexShaderSource, const Text *fragmentShaderSource);
virtual ~CustomVertexSkinningShader(); virtual ~CustomVertexSkinningShader();
BOOL Initialize(GraphicsDevice *graphicsDevice, const char *vertexShaderSource, const char *fragmentShaderSource);
BOOL Initialize(GraphicsDevice *graphicsDevice, const Text *vertexShaderSource, const Text *fragmentShaderSource);
}; };
#endif #endif

View file

@ -31,17 +31,26 @@ const char* DebugShader::m_fragmentShaderSource =
"}\n"; "}\n";
DebugShader::DebugShader() DebugShader::DebugShader()
: StandardShader()
{ {
STACK_TRACE; 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() DebugShader::~DebugShader()
{ {
STACK_TRACE; 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;
}

View file

@ -3,6 +3,8 @@
#include "standardshader.h" #include "standardshader.h"
class GraphicsDevice;
/** /**
* Shader for rendering debug geometry. Will render using solid colors * Shader for rendering debug geometry. Will render using solid colors
* with thicker lines and larger point sizes. * with thicker lines and larger point sizes.
@ -12,6 +14,8 @@ class DebugShader : public StandardShader
public: public:
DebugShader(); DebugShader();
virtual ~DebugShader(); virtual ~DebugShader();
BOOL Initialize(GraphicsDevice *graphicsDevice);
private: private:
static const char *m_vertexShaderSource; static const char *m_vertexShaderSource;

View file

@ -30,17 +30,26 @@ const char* SimpleColorShader::m_fragmentShaderSource =
"}\n"; "}\n";
SimpleColorShader::SimpleColorShader() SimpleColorShader::SimpleColorShader()
: StandardShader()
{ {
STACK_TRACE; 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() SimpleColorShader::~SimpleColorShader()
{ {
STACK_TRACE; 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;
}

View file

@ -3,6 +3,8 @@
#include "standardshader.h" #include "standardshader.h"
class GraphicsDevice;
/** /**
* Shader which renders geometry with vertex colors but no textures. * Shader which renders geometry with vertex colors but no textures.
*/ */
@ -11,6 +13,8 @@ class SimpleColorShader : public StandardShader
public: public:
SimpleColorShader(); SimpleColorShader();
virtual ~SimpleColorShader(); virtual ~SimpleColorShader();
BOOL Initialize(GraphicsDevice *graphicsDevice);
private: private:
static const char *m_vertexShaderSource; static const char *m_vertexShaderSource;

View file

@ -35,18 +35,27 @@ const char* SimpleColorTextureShader::m_fragmentShaderSource =
"}\n"; "}\n";
SimpleColorTextureShader::SimpleColorTextureShader() SimpleColorTextureShader::SimpleColorTextureShader()
: StandardShader()
{ {
STACK_TRACE; 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() SimpleColorTextureShader::~SimpleColorTextureShader()
{ {
STACK_TRACE; 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;
}

View file

@ -3,6 +3,8 @@
#include "standardshader.h" #include "standardshader.h"
class GraphicsDevice;
/** /**
* Shader which renders geometry using vertex colors modulated with a texture. * Shader which renders geometry using vertex colors modulated with a texture.
*/ */
@ -11,6 +13,8 @@ class SimpleColorTextureShader : public StandardShader
public: public:
SimpleColorTextureShader(); SimpleColorTextureShader();
virtual ~SimpleColorTextureShader(); virtual ~SimpleColorTextureShader();
BOOL Initialize(GraphicsDevice *graphicsDevice);
private: private:
static const char *m_vertexShaderSource; static const char *m_vertexShaderSource;

View file

@ -28,18 +28,28 @@ const char* SimpleTextureShader::m_fragmentShaderSource =
" gl_FragColor = texture2D(u_texture, v_texCoords);\n" " gl_FragColor = texture2D(u_texture, v_texCoords);\n"
"}\n"; "}\n";
SimpleTextureShader::SimpleTextureShader() SimpleTextureShader::SimpleTextureShader()
: StandardShader()
{ {
STACK_TRACE; 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() SimpleTextureShader::~SimpleTextureShader()
{ {
STACK_TRACE; 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;
}

View file

@ -3,6 +3,8 @@
#include "standardshader.h" #include "standardshader.h"
class GraphicsDevice;
/** /**
* Shader which renders geometry with texturing but no vertex colors. * Shader which renders geometry with texturing but no vertex colors.
*/ */
@ -11,6 +13,8 @@ class SimpleTextureShader : public StandardShader
public: public:
SimpleTextureShader(); SimpleTextureShader();
virtual ~SimpleTextureShader(); virtual ~SimpleTextureShader();
BOOL Initialize(GraphicsDevice *graphicsDevice);
private: private:
static const char *m_vertexShaderSource; static const char *m_vertexShaderSource;

View file

@ -31,18 +31,27 @@ const char* SimpleTextureVertexLerpShader::m_fragmentShaderSource =
"}\n"; "}\n";
SimpleTextureVertexLerpShader::SimpleTextureVertexLerpShader() SimpleTextureVertexLerpShader::SimpleTextureVertexLerpShader()
: VertexLerpShader()
{ {
STACK_TRACE; 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() SimpleTextureVertexLerpShader::~SimpleTextureVertexLerpShader()
{ {
STACK_TRACE; 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;
}

View file

@ -3,11 +3,15 @@
#include "vertexlerpshader.h" #include "vertexlerpshader.h"
class GraphicsDevice;
class SimpleTextureVertexLerpShader : public VertexLerpShader class SimpleTextureVertexLerpShader : public VertexLerpShader
{ {
public: public:
SimpleTextureVertexLerpShader(); SimpleTextureVertexLerpShader();
virtual ~SimpleTextureVertexLerpShader(); virtual ~SimpleTextureVertexLerpShader();
BOOL Initialize(GraphicsDevice *graphicsDevice);
private: private:
static const char *m_vertexShaderSource; static const char *m_vertexShaderSource;

View file

@ -49,18 +49,27 @@ const char* SimpleTextureVertexSkinningShader::m_fragmentShaderSource =
"}\n"; "}\n";
SimpleTextureVertexSkinningShader::SimpleTextureVertexSkinningShader() SimpleTextureVertexSkinningShader::SimpleTextureVertexSkinningShader()
: VertexSkinningShader()
{ {
STACK_TRACE; 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() SimpleTextureVertexSkinningShader::~SimpleTextureVertexSkinningShader()
{ {
STACK_TRACE; 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;
}

View file

@ -3,12 +3,16 @@
#include "vertexskinningshader.h" #include "vertexskinningshader.h"
class GraphicsDevice;
class SimpleTextureVertexSkinningShader : public VertexSkinningShader class SimpleTextureVertexSkinningShader : public VertexSkinningShader
{ {
public: public:
SimpleTextureVertexSkinningShader(); SimpleTextureVertexSkinningShader();
virtual ~SimpleTextureVertexSkinningShader(); virtual ~SimpleTextureVertexSkinningShader();
BOOL Initialize(GraphicsDevice *graphicsDevice);
private: private:
static const char *m_vertexShaderSource; static const char *m_vertexShaderSource;
static const char *m_fragmentShaderSource; static const char *m_fragmentShaderSource;

View file

@ -41,18 +41,27 @@ const char* Sprite2DShader::m_fragmentShaderSource =
"}\n"; "}\n";
Sprite2DShader::Sprite2DShader() Sprite2DShader::Sprite2DShader()
: SpriteShader()
{ {
STACK_TRACE; 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() Sprite2DShader::~Sprite2DShader()
{ {
STACK_TRACE; 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;
}

View file

@ -3,6 +3,8 @@
#include "spriteshader.h" #include "spriteshader.h"
class GraphicsDevice;
/** /**
* Shader for rendering 2D sprites with vertex color modulation. Includes * Shader for rendering 2D sprites with vertex color modulation. Includes
* special support for color modulation using RGB, RGBA, and alpha-only * special support for color modulation using RGB, RGBA, and alpha-only
@ -13,6 +15,8 @@ class Sprite2DShader : public SpriteShader
public: public:
Sprite2DShader(); Sprite2DShader();
virtual ~Sprite2DShader(); virtual ~Sprite2DShader();
BOOL Initialize(GraphicsDevice *graphicsDevice);
private: private:
static const char *m_vertexShaderSource; static const char *m_vertexShaderSource;

View file

@ -47,18 +47,27 @@ const char* Sprite3DShader::m_fragmentShaderSource =
"}\n"; "}\n";
Sprite3DShader::Sprite3DShader() Sprite3DShader::Sprite3DShader()
: SpriteShader()
{ {
STACK_TRACE; 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() Sprite3DShader::~Sprite3DShader()
{ {
STACK_TRACE; 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;
}

View file

@ -3,6 +3,8 @@
#include "spriteshader.h" #include "spriteshader.h"
class GraphicsDevice;
/** /**
* Shader for rendering 3D billboard sprites with vertex color modulation. * Shader for rendering 3D billboard sprites with vertex color modulation.
* Includes special support for color modulation using RGB, RGBA, and * Includes special support for color modulation using RGB, RGBA, and
@ -14,6 +16,8 @@ class Sprite3DShader : public SpriteShader
public: public:
Sprite3DShader(); Sprite3DShader();
virtual ~Sprite3DShader(); virtual ~Sprite3DShader();
BOOL Initialize(GraphicsDevice *graphicsDevice);
private: private:
static const char *m_vertexShaderSource; static const char *m_vertexShaderSource;

View file

@ -3,7 +3,6 @@
#include "spriteshader.h" #include "spriteshader.h"
SpriteShader::SpriteShader() SpriteShader::SpriteShader()
: StandardShader()
{ {
STACK_TRACE; STACK_TRACE;
SetTextureHasAlphaOnlyUniform("u_textureHasAlphaOnly"); SetTextureHasAlphaOnlyUniform("u_textureHasAlphaOnly");

View file

@ -4,7 +4,6 @@
#include "../math/matrix4x4.h" #include "../math/matrix4x4.h"
StandardShader::StandardShader() StandardShader::StandardShader()
: Shader()
{ {
STACK_TRACE; STACK_TRACE;
m_inlineVertexShaderSource = NULL; m_inlineVertexShaderSource = NULL;

View file

@ -3,7 +3,6 @@
#include "vertexlerpshader.h" #include "vertexlerpshader.h"
VertexLerpShader::VertexLerpShader() VertexLerpShader::VertexLerpShader()
: StandardShader()
{ {
STACK_TRACE; STACK_TRACE;
SetLerpUniform("u_lerp"); SetLerpUniform("u_lerp");

View file

@ -5,7 +5,6 @@
#include "../math/vector3.h" #include "../math/vector3.h"
VertexSkinningShader::VertexSkinningShader() VertexSkinningShader::VertexSkinningShader()
: StandardShader()
{ {
STACK_TRACE; STACK_TRACE;
SetJointPositionsUniform("u_jointPositions"); SetJointPositionsUniform("u_jointPositions");