GLState: Add bound shader program to managed state

Squishes a handful of redundant binds per frame.
This commit is contained in:
Jonas Kulla 2014-01-20 00:57:40 +01:00
parent b729da249b
commit 87c1e376b9
3 changed files with 15 additions and 2 deletions

View File

@ -20,6 +20,7 @@
*/
#include "glstate.h"
#include "shader.h"
#include "etc.h"
#include <glew.h>
@ -95,6 +96,11 @@ void GLViewport::apply(const IntRect &value)
glViewport(value.x, value.y, value.w, value.h);
}
void GLProgram::apply(const unsigned int &value)
{
glUseProgram(value);
}
GLState::Caps::Caps()
{
glGetIntegerv(GL_MAX_TEXTURE_SIZE, &maxTexSize);
@ -110,4 +116,5 @@ GLState::GLState()
scissorTest.init(false);
scissorBox.init(IntRect(0, 0, 640, 480));
texture2D.init(true);
program.init(0);
}

View File

@ -99,6 +99,11 @@ class GLViewport : public GLProperty<IntRect>
void apply(const IntRect &value);
};
class GLProgram : public GLProperty<unsigned int> /* GLuint */
{
void apply(const unsigned int &value);
};
class GLState
{
@ -109,6 +114,7 @@ public:
GLTexture2D texture2D;
GLBlendMode blendMode;
GLViewport viewport;
GLProgram program;
struct Caps
{

View File

@ -99,13 +99,13 @@ Shader::~Shader()
void Shader::bind()
{
glUseProgram(program);
glState.program.set(program);
}
void Shader::unbind()
{
glActiveTexture(GL_TEXTURE0);
glUseProgram(0);
glState.program.set(0);
}
void Shader::init(const unsigned char *vert, int vertSize,