commit 7a3fd90e0983dc745ae363effcea117aa6a5e511
parent 6757aaea5e61f0d3abf8d2548203fef7051fe0e7
Author: rexim <reximkut@gmail.com>
Date: Mon, 9 Jan 2023 02:26:27 +0700
Merge uniforms translation unit into simple_renderer
Diffstat:
5 files changed, 42 insertions(+), 81 deletions(-)
diff --git a/build.sh b/build.sh
@@ -6,7 +6,7 @@ CC="${CXX:-cc}"
PKGS="sdl2 glew freetype2"
CFLAGS="-Wall -Wextra -std=c11 -pedantic -ggdb"
LIBS=-lm
-SRC="src/main.c src/la.c src/editor.c src/sdl_extra.c src/file.c src/gl_extra.c src/free_glyph.c src/uniforms.c src/simple_renderer.c"
+SRC="src/main.c src/la.c src/editor.c src/sdl_extra.c src/file.c src/gl_extra.c src/free_glyph.c src/simple_renderer.c"
if [ `uname` = "Darwin" ]; then
CFLAGS+=" -framework OpenGL"
diff --git a/src/simple_renderer.c b/src/simple_renderer.c
@@ -4,6 +4,31 @@
#include "./simple_renderer.h"
#include "./gl_extra.h"
+typedef struct {
+ Uniform_Slot slot;
+ const char *name;
+} Uniform_Def;
+
+static_assert(COUNT_UNIFORM_SLOTS == 4, "The amount of the shader uniforms have change. Please update the definition table accordingly");
+static const Uniform_Def uniform_defs[COUNT_UNIFORM_SLOTS] = {
+ [UNIFORM_SLOT_TIME] = {
+ .slot = UNIFORM_SLOT_TIME,
+ .name = "time",
+ },
+ [UNIFORM_SLOT_RESOLUTION] = {
+ .slot = UNIFORM_SLOT_RESOLUTION,
+ .name = "resolution",
+ },
+ [UNIFORM_SLOT_CAMERA_POS] = {
+ .slot = UNIFORM_SLOT_CAMERA_POS,
+ .name = "camera_pos",
+ },
+ [UNIFORM_SLOT_CAMERA_SCALE] = {
+ .slot = UNIFORM_SLOT_CAMERA_SCALE,
+ .name = "camera_scale",
+ },
+};
+
#define UNIMPLEMENTED(...) \
do { \
printf("%s:%d: UNIMPLEMENTED: %s \n", __FILE__, __LINE__, __VA_ARGS__); \
@@ -11,6 +36,13 @@
} while(0)
#define UNUSED(x) (void)(x)
+static void get_uniform_location(GLuint program, GLint locations[COUNT_UNIFORM_SLOTS])
+{
+ for (Uniform_Slot slot = 0; slot < COUNT_UNIFORM_SLOTS; ++slot) {
+ locations[slot] = glGetUniformLocation(program, uniform_defs[slot].name);
+ }
+}
+
void simple_renderer_init(Simple_Renderer *sr,
const char *vert_file_path,
const char *color_frag_file_path,
diff --git a/src/simple_renderer.h b/src/simple_renderer.h
@@ -8,7 +8,14 @@
#include <SDL2/SDL_opengl.h>
#include "./la.h"
-#include "./uniforms.h"
+
+typedef enum {
+ UNIFORM_SLOT_TIME = 0,
+ UNIFORM_SLOT_RESOLUTION,
+ UNIFORM_SLOT_CAMERA_POS,
+ UNIFORM_SLOT_CAMERA_SCALE,
+ COUNT_UNIFORM_SLOTS,
+} Uniform_Slot;
typedef enum {
SIMPLE_VERTEX_ATTR_POSITION = 0,
@@ -27,7 +34,7 @@ typedef struct {
typedef enum {
SHADER_FOR_COLOR = 0,
SHADER_FOR_IMAGE,
- SHADER_FOR_EPICNESS,
+ SHADER_FOR_EPICNESS, // This is the one that does that cool rainbowish animation
COUNT_SIMPLE_SHADERS,
} Simple_Shader;
diff --git a/src/uniforms.c b/src/uniforms.c
@@ -1,48 +0,0 @@
-#include <assert.h>
-#include "./uniforms.h"
-
-static_assert(COUNT_UNIFORM_SLOTS == 7, "The amount of the shader uniforms have change. Please update the definition table accordingly");
-static const Uniform_Def uniform_defs[COUNT_UNIFORM_SLOTS] = {
- [UNIFORM_SLOT_TIME] = {
- .slot = UNIFORM_SLOT_TIME,
- .name = "time",
- },
- [UNIFORM_SLOT_RESOLUTION] = {
- .slot = UNIFORM_SLOT_RESOLUTION,
- .name = "resolution",
- },
- [UNIFORM_SLOT_CAMERA_POS] = {
- .slot = UNIFORM_SLOT_CAMERA_POS,
- .name = "camera_pos",
- },
- [UNIFORM_SLOT_CAMERA_SCALE] = {
- .slot = UNIFORM_SLOT_CAMERA_SCALE,
- .name = "camera_scale",
- },
- [UNIFORM_SLOT_CURSOR_POS] = {
- .slot = UNIFORM_SLOT_CURSOR_POS,
- .name = "cursor_pos",
- },
- [UNIFORM_SLOT_CURSOR_HEIGHT] = {
- .slot = UNIFORM_SLOT_CURSOR_HEIGHT,
- .name = "cursor_height",
- },
- [UNIFORM_SLOT_LAST_STROKE] = {
- .slot = UNIFORM_SLOT_LAST_STROKE,
- .name = "last_stroke",
- },
-};
-
-const Uniform_Def *get_uniform_def(Uniform_Slot slot)
-{
- assert(0 <= slot);
- assert(slot < COUNT_UNIFORM_SLOTS);
- return &uniform_defs[slot];
-}
-
-void get_uniform_location(GLuint program, GLint locations[COUNT_UNIFORM_SLOTS])
-{
- for (Uniform_Slot slot = 0; slot < COUNT_UNIFORM_SLOTS; ++slot) {
- locations[slot] = glGetUniformLocation(program, uniform_defs[slot].name);
- }
-}
diff --git a/src/uniforms.h b/src/uniforms.h
@@ -1,30 +0,0 @@
-#ifndef UNIFORMS_H_
-#define UNIFORMS_H_
-
-#define GLEW_STATIC
-#include <GL/glew.h>
-
-#define GL_GLEXT_PROTOTYPES
-#include <SDL2/SDL_opengl.h>
-
-typedef enum {
- UNIFORM_SLOT_TIME = 0,
- UNIFORM_SLOT_RESOLUTION,
- UNIFORM_SLOT_CAMERA_POS,
- UNIFORM_SLOT_CAMERA_SCALE,
-
- UNIFORM_SLOT_CURSOR_POS,
- UNIFORM_SLOT_CURSOR_HEIGHT,
- UNIFORM_SLOT_LAST_STROKE,
- COUNT_UNIFORM_SLOTS,
-} Uniform_Slot;
-
-typedef struct {
- Uniform_Slot slot;
- const char *name;
-} Uniform_Def;
-
-const Uniform_Def *get_uniform_def(Uniform_Slot slot);
-void get_uniform_location(GLuint program, GLint locations[COUNT_UNIFORM_SLOTS]);
-
-#endif // UNIFORMS_H_