aboutsummaryrefslogtreecommitdiff
path: root/include
diff options
context:
space:
mode:
authordec05eba <dec05eba@protonmail.com>2021-10-22 03:35:27 +0200
committerdec05eba <dec05eba@protonmail.com>2021-10-22 03:35:27 +0200
commitfaa74e2c942102a9b1aa215a913fddf422714d7e (patch)
treeea037970d5fec74586f1a8a637d84f696b3c48be /include
parentf02a283c06c51cb29f79e89754b31ffd6952d2e6 (diff)
Add shader
Diffstat (limited to 'include')
-rw-r--r--include/mgl/gl.h15
-rw-r--r--include/mgl/gl_macro.h15
-rw-r--r--include/mgl/graphics/shader.h30
3 files changed, 58 insertions, 2 deletions
diff --git a/include/mgl/gl.h b/include/mgl/gl.h
index 8a09e3e..a13406e 100644
--- a/include/mgl/gl.h
+++ b/include/mgl/gl.h
@@ -52,6 +52,21 @@ typedef struct {
void (*glVertexPointer)(int size, unsigned int type, int stride, const void *ptr);
void (*glColorPointer)(int size, unsigned int type, int stride, const void *ptr);
void (*glTexCoordPointer)(int size, unsigned int type, int stride, const void *ptr);
+ void (*glCompileShader)(unsigned int shader);
+ unsigned int (*glCreateProgram)(void);
+ unsigned int (*glCreateShader)(unsigned int type);
+ void (*glDeleteProgram)(unsigned int program);
+ void (*glDeleteShader)(unsigned int shader);
+ void (*glGetShaderiv)(unsigned int shader, unsigned int pname, int *params);
+ void (*glGetShaderInfoLog)(unsigned int shader, int bufSize, int *length, char *infoLog);
+ void (*glGetProgramiv)(unsigned int program, unsigned int pname, int *params);
+ void (*glGetProgramInfoLog)(unsigned int program, int bufSize, int *length, char *infoLog);
+ void (*glLinkProgram)(unsigned int program);
+ void (*glShaderSource)(unsigned int shader, int count, const char *const*string, const int *length);
+ void (*glUseProgram)(unsigned int program);
+ void (*glAttachShader)(unsigned int program, unsigned int shader);
+ int (*glGetUniformLocation)(unsigned int program, const char *name);
+ void (*glUniform2fv)(int location, int count, const float *value);
/* Optional*/
void (*glXSwapIntervalEXT)(Display * dpy, GLXDrawable drawable, int interval);
diff --git a/include/mgl/gl_macro.h b/include/mgl/gl_macro.h
index a3be960..c47c8fb 100644
--- a/include/mgl/gl_macro.h
+++ b/include/mgl/gl_macro.h
@@ -1,7 +1,6 @@
#ifndef MGL_GL_MACRO_H
#define MGL_GL_MACRO_H
-/* Copied from GL/glx.h */
#define GLX_USE_GL 1
#define GLX_BUFFER_SIZE 2
#define GLX_LEVEL 3
@@ -20,7 +19,6 @@
#define GLX_ACCUM_BLUE_SIZE 16
#define GLX_ACCUM_ALPHA_SIZE 17
-/* Copied from GL/gl.h */
#define GL_COLOR_BUFFER_BIT 0x00004000
#define GL_BLEND 0x0BE2
#define GL_SRC_ALPHA 0x0302
@@ -73,4 +71,17 @@
#define GL_COLOR_ARRAY 0x8076
#define GL_TEXTURE_COORD_ARRAY 0x8078
+#define GL_FRAGMENT_SHADER 0x8B30
+#define GL_VERTEX_SHADER 0x8B31
+#define GL_GEOMETRY_SHADER 0x8DD9
+
+#define GL_INFO_LOG_LENGTH 0x8B84
+
+#define GL_LINK_STATUS 0x8B82
+#define GL_COMPILE_STATUS 0x8B81
+
+#define GL_FALSE 0
+#define GL_TRUE 1
+
+
#endif /* MGL_GL_MACRO_H */
diff --git a/include/mgl/graphics/shader.h b/include/mgl/graphics/shader.h
new file mode 100644
index 0000000..fb00066
--- /dev/null
+++ b/include/mgl/graphics/shader.h
@@ -0,0 +1,30 @@
+#ifndef MGL_SHADER_H
+#define MGL_SHADER_H
+
+#include "../system/vec.h"
+
+typedef struct mgl_texture mgl_texture;
+
+typedef struct {
+ unsigned int id;
+} mgl_shader_program;
+
+typedef enum {
+ MGL_SHADER_VERTEX,
+ MGL_SHADER_FRAGMENT,
+ MGL_SHADER_GEOMETRY
+} mgl_shader_type;
+
+int mgl_shader_program_init(mgl_shader_program *self);
+void mgl_shader_program_deinit(mgl_shader_program *self);
+
+int mgl_shader_program_add_shader_from_file(mgl_shader_program *self, const char *filepath, mgl_shader_type shader_type);
+int mgl_shader_program_add_shader_from_memory(mgl_shader_program *self, unsigned char *shader_data, int shader_size, mgl_shader_type shader_type);
+int mgl_shader_program_finalize(mgl_shader_program *self);
+
+int mgl_shader_program_set_uniform_vec2f(mgl_shader_program *self, const char *uniform_name, mgl_vec2f value);
+
+/* If |shader_program| is NULL then no shader is used */
+void mgl_shader_program_use(mgl_shader_program *shader_program);
+
+#endif /* MGL_SHADER_H */