Browse Source

Protect the Shader constructor and provide a static creation method that

will let us cache shaders.
legacy
Sam Hocevar sam 13 years ago
parent
commit
194a025bc8
3 changed files with 20 additions and 6 deletions
  1. +11
    -1
      src/shader.cpp
  2. +7
    -3
      src/shader.h
  3. +2
    -2
      src/video.cpp

+ 11
- 1
src/shader.cpp View File

@@ -44,6 +44,16 @@ private:
* Public Shader class
*/

Shader *Shader::Create(char const *vert, char const *frag)
{
return new Shader(vert, frag);
}

void Shader::Destroy(Shader *shader)
{
delete shader;
}

Shader::Shader(char const *vert, char const *frag)
: data(new ShaderData())
{
@@ -76,7 +86,7 @@ Shader::Shader(char const *vert, char const *frag)

int Shader::GetAttribLocation(char const *attr) const
{
return glGetAttribLocation(data->prog_id, attr);
return glGetAttribLocation(data->prog_id, attr);
}

int Shader::GetUniformLocation(char const *uni) const


+ 7
- 3
src/shader.h View File

@@ -10,7 +10,7 @@

//
// The Shader class
// --------------
// ----------------
//

#if !defined __DH_SHADER_H__
@@ -21,14 +21,18 @@ class ShaderData;
class Shader
{
public:
Shader(char const *vert, char const *frag);
~Shader();
static Shader *Create(char const *vert, char const *frag);
static void Destroy(Shader *shader);

int GetAttribLocation(char const *attr) const;
int GetUniformLocation(char const *uni) const;

void Bind() const;

protected:
Shader(char const *vert, char const *frag);
~Shader();

private:
ShaderData *data;
};


+ 2
- 2
src/video.cpp View File

@@ -85,7 +85,7 @@ void Video::Setup(int width, int height)
glHint(GL_PERSPECTIVE_CORRECTION_HINT, GL_NICEST);

#if LOL_EXPERIMENTAL
stdshader = new Shader(vertexshader, fragmentshader);
stdshader = Shader::Create(vertexshader, fragmentshader);
#endif
}

@@ -168,7 +168,7 @@ void Video::Clear()
void Video::Destroy()
{
#if LOL_EXPERIMENTAL
delete stdshader;
Shader::Destroy(stdshader);
#endif
}



Loading…
Cancel
Save