summaryrefslogtreecommitdiff
path: root/frontend/_wasm/intro/Shader.h
diff options
context:
space:
mode:
authorMatthew Kosarek <mattkae@protonmail.com>2021-03-22 20:54:51 -0400
committerMatthew Kosarek <mattkae@protonmail.com>2021-03-22 20:54:51 -0400
commitc36d05d5aed2f8f7c6342b174692146e2d11c386 (patch)
tree8e54047d7b6db7e3d21ccfad6b8c4965d42c09fa /frontend/_wasm/intro/Shader.h
parentc29a911cd1a3f23f66478f205cace14487aadc56 (diff)
Refactored frontend, beginnings of general cpp layer, and beginning roadmap
Diffstat (limited to 'frontend/_wasm/intro/Shader.h')
-rw-r--r--frontend/_wasm/intro/Shader.h63
1 files changed, 63 insertions, 0 deletions
diff --git a/frontend/_wasm/intro/Shader.h b/frontend/_wasm/intro/Shader.h
new file mode 100644
index 0000000..6ee9981
--- /dev/null
+++ b/frontend/_wasm/intro/Shader.h
@@ -0,0 +1,63 @@
+#pragma once
+
+#include <GL/glew.h>
+#include <string>
+#include <vector>
+#include "mathlib.h"
+
+typedef GLuint Shader;
+
+Shader loadShader(const GLchar* vertexShader, const GLchar* fragmentShader);
+
+inline GLint getShaderUniform(const Shader& shader, const GLchar *name) {
+ GLint uid = glGetUniformLocation(shader, name);
+ if (uid < 0) {
+ return -1;
+ }
+ return uid;
+}
+
+inline GLint getShaderAttribute(const Shader& shader, const GLchar *name) {
+ printf("Getting attribute for shader, name: %d, %s\n", shader, name);
+ GLint uid = glGetAttribLocation(shader, name);
+ if (uid < 0) {
+ return -1;
+ }
+ return uid;
+}
+
+inline void useShader(const Shader& shader) {
+ glUseProgram(shader);
+}
+
+inline void setShaderFloat(GLint location, GLfloat value) {
+ glUniform1f(location, value);
+}
+
+inline void setShaderInt(GLint location, GLint value) {
+ glUniform1i(location, value);
+}
+
+inline void setShaderUint(GLint location, GLuint value) {
+ glUniform1ui(location, value);
+}
+
+inline void setShaderVec2(GLint location, const Vector2& value) {
+ glUniform2f(location, value.x, value.y);
+}
+
+inline void setShaderMat4(GLint location, const Mat4x4& matrix) {
+ glUniformMatrix4fv(location, 1, GL_FALSE, matrix.m);
+}
+
+inline void setShaderBVec3(GLint location, bool first, bool second, bool third) {
+ glUniform3i(location, first, second, third);
+}
+
+inline void setShaderBVec4(GLint location, bool first, bool second, bool third, bool fourth) {
+ glUniform4i(location, first, second, third, fourth);
+}
+
+inline void setShaderBool(GLint location, bool value) {
+ glUniform1i(location, value);
+} \ No newline at end of file