diff options
Diffstat (limited to 'Runtime/Graphics/GfxDevice.cpp')
-rw-r--r-- | Runtime/Graphics/GfxDevice.cpp | 57 |
1 files changed, 57 insertions, 0 deletions
diff --git a/Runtime/Graphics/GfxDevice.cpp b/Runtime/Graphics/GfxDevice.cpp index dd077b8..e4747d8 100644 --- a/Runtime/Graphics/GfxDevice.cpp +++ b/Runtime/Graphics/GfxDevice.cpp @@ -64,6 +64,63 @@ void GfxDevice::Clear(int clearFlag) } +void GfxDevice::UseShader(LuaBind::State& state, Shader* shader, int idx) +{ + if (shader == NULL) + return; + + GLuint id = shader->GetID(); + if (id == 0) + return; + + glUseProgram(id); + + m_Shader.shader = shader; + m_Shader.ref.SetRef(state, idx); +} + +void GfxDevice::UnuseShader() +{ + if (m_Shader) + { + m_Shader.shader = NULL; + m_Shader.ref.UnRef(); + } + glUseProgram(0); +} + +void GfxDevice::SetUniformVec2(const char* name, Internal::Vector2 vec2) +{ + if (!m_Shader) + return; + GLint loc = glGetUniformLocation(m_Shader.GetID(), name); + glUniform2f(loc, vec2.x, vec2.y); +} + +void GfxDevice::SetUniformVec3(const char* name, Internal::Vector3 vec3) +{ + if (!m_Shader) + return; + GLint loc = glGetUniformLocation(m_Shader.GetID(), name); + glUniform3f(loc, vec3.x, vec3.y, vec3.z); +} + +void GfxDevice::SetUniformVec4(const char* name, Internal::Vector4 vec4) +{ + if (!m_Shader) + return; + GLint loc = glGetUniformLocation(m_Shader.GetID(), name); + glUniform4f(loc, vec4.x, vec4.y, vec4.z, vec4.w); +} + +void GfxDevice::SetUniformMat4(const char* name, Internal::Matrix44 mat4) +{ + if (!m_Shader) + return; + GLint loc = glGetUniformLocation(m_Shader.GetID(), name); + glUniformMatrix4fv(loc, 1, GL_TRUE, &mat4.m[0][0]); +} + void GfxDevice::BeginFrame() { m_IsInsideFrame = true; |