GL: Eliminiate most redundant state setting calls at draw time

This commit is contained in:
Connor McLaughlin
2019-10-04 22:10:43 +10:00
parent 8987fa93c2
commit 4fa79f1503
7 changed files with 118 additions and 52 deletions

View File

@ -6,6 +6,7 @@
Log_SetChannel(GL);
static u32 s_next_bad_shader_id = 1;
static GLuint s_last_program_id = 0;
namespace GL {
@ -63,6 +64,11 @@ GLuint Program::CompileShader(GLenum type, const char* source)
return id;
}
void Program::ResetLastProgram()
{
s_last_program_id = 0;
}
bool Program::Compile(const char* vertex_shader, const char* fragment_shader)
{
GLuint vertex_shader_id = CompileShader(GL_VERTEX_SHADER, vertex_shader);
@ -138,7 +144,11 @@ bool Program::Link()
void Program::Bind() const
{
if (s_last_program_id == m_program_id)
return;
glUseProgram(m_program_id);
s_last_program_id = m_program_id;
}
void Program::Destroy()

View File

@ -11,6 +11,7 @@ public:
~Program();
static GLuint CompileShader(GLenum type, const char* source);
static void ResetLastProgram();
bool IsVaild() const { return m_program_id != 0; }