summaryrefslogtreecommitdiff
path: root/Runtime/Graphics/GfxDevice.cpp
diff options
context:
space:
mode:
authorchai <chaifix@163.com>2021-10-29 13:36:49 +0800
committerchai <chaifix@163.com>2021-10-29 13:36:49 +0800
commit91c32cb173201ac8803a1e4452e8342969b8e484 (patch)
tree5e78c485b5fcfcf839a2348667597d7e10476214 /Runtime/Graphics/GfxDevice.cpp
parent1f92d4c389cceba6f90261d9cb29885c8a3ca24c (diff)
*GLSL test
Diffstat (limited to 'Runtime/Graphics/GfxDevice.cpp')
-rw-r--r--Runtime/Graphics/GfxDevice.cpp57
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;