Browse Source

shaders can set vectors

Kajetan Johannes Hammerle 3 năm trước cách đây
mục cha
commit
26bdee18ce
2 tập tin đã thay đổi với 17 bổ sung0 xóa
  1. 12 0
      wrapper/Shader.cpp
  2. 5 0
      wrapper/Shader.h

+ 12 - 0
wrapper/Shader.cpp

@@ -89,4 +89,16 @@ void Shader::setInt(const GLchar* name, GLint data) {
 
 void Shader::setFloat(const GLchar* name, GLfloat data) {
     glUniform1f(glGetUniformLocation(program, name), data);
+}
+
+void Shader::setVector(const GLchar* name, const Vector2& v) {
+    glUniform2fv(glGetUniformLocation(program, name), 1, &(v[0]));
+}
+
+void Shader::setVector(const GLchar* name, const Vector3& v) {
+    glUniform3fv(glGetUniformLocation(program, name), 1, &(v[0]));
+}
+
+void Shader::setVector(const GLchar* name, const Vector4& v) {
+    glUniform4fv(glGetUniformLocation(program, name), 1, &(v[0]));
 }

+ 5 - 0
wrapper/Shader.h

@@ -3,6 +3,7 @@
 
 #include <GL/glew.h>
 
+#include "math/Vector.h"
 #include "utils/Array.h"
 
 class Shader final {
@@ -25,6 +26,10 @@ public:
     void setInt(const GLchar* name, GLint data);
     void setFloat(const GLchar* name, GLfloat data);
 
+    void setVector(const GLchar* name, const Vector2& v);
+    void setVector(const GLchar* name, const Vector3& v);
+    void setVector(const GLchar* name, const Vector4& v);
+
 private:
     typedef Array<GLchar, 1024 * 128> Code;
     typedef Array<GLchar, 1024> ErrorLog;