aboutsummaryrefslogtreecommitdiff
diff options
context:
space:
mode:
-rw-r--r--include/mgl/graphics/shader.h2
-rw-r--r--include/mgl/graphics/texture.h2
-rw-r--r--include/mgl/graphics/vertex.h2
-rw-r--r--include/mgl/graphics/vertex_buffer.h4
-rw-r--r--src/graphics/shader.c4
-rw-r--r--src/graphics/texture.c2
-rw-r--r--src/graphics/vertex_buffer.c8
-rw-r--r--tests/main.c13
8 files changed, 18 insertions, 19 deletions
diff --git a/include/mgl/graphics/shader.h b/include/mgl/graphics/shader.h
index fb00066..ec89df7 100644
--- a/include/mgl/graphics/shader.h
+++ b/include/mgl/graphics/shader.h
@@ -19,7 +19,7 @@ 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_add_shader_from_memory(mgl_shader_program *self, const 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);
diff --git a/include/mgl/graphics/texture.h b/include/mgl/graphics/texture.h
index 3aec07d..7891dab 100644
--- a/include/mgl/graphics/texture.h
+++ b/include/mgl/graphics/texture.h
@@ -28,7 +28,7 @@ typedef struct {
/* |load_options| can be null, in which case the default options are used */
int mgl_texture_load_from_file(mgl_texture *self, const char *filepath, mgl_texture_load_options *load_options);
/* |load_options| can be null, in which case the default options are used */
-int mgl_texture_load_from_image(mgl_texture *self, mgl_image *image, mgl_texture_load_options *load_options);
+int mgl_texture_load_from_image(mgl_texture *self, const mgl_image *image, mgl_texture_load_options *load_options);
/* |load_options| can be null, in which case the default options are used */
int mgl_texture_load_from_memory(mgl_texture *self, const unsigned char *data, int width, int height, mgl_image_format format, mgl_texture_load_options *load_options);
void mgl_texture_unload(mgl_texture *self);
diff --git a/include/mgl/graphics/vertex.h b/include/mgl/graphics/vertex.h
index b4a5830..69400b4 100644
--- a/include/mgl/graphics/vertex.h
+++ b/include/mgl/graphics/vertex.h
@@ -6,8 +6,8 @@
typedef struct {
mgl_vec2f position;
- mgl_color color;
mgl_vec2f texcoords;
+ mgl_color color;
} mgl_vertex;
#endif /* MGL_VERTEX_H */
diff --git a/include/mgl/graphics/vertex_buffer.h b/include/mgl/graphics/vertex_buffer.h
index c1e4af1..2a32d3d 100644
--- a/include/mgl/graphics/vertex_buffer.h
+++ b/include/mgl/graphics/vertex_buffer.h
@@ -37,8 +37,8 @@ int mgl_vertex_buffer_init(mgl_vertex_buffer *self, mgl_primitive_type primitive
void mgl_vertex_buffer_deinit(mgl_vertex_buffer *self);
void mgl_vertex_buffer_set_position(mgl_vertex_buffer *self, mgl_vec2f position);
-int mgl_vertex_buffer_update(mgl_vertex_buffer *self, mgl_vertex *vertices, size_t vertex_count);
+int mgl_vertex_buffer_update(mgl_vertex_buffer *self, const mgl_vertex *vertices, size_t vertex_count);
/* |texture| can be NULL to not use any texture */
-void mgl_vertex_buffer_draw(mgl_context *context, mgl_vertex_buffer *self, mgl_texture *texture);
+void mgl_vertex_buffer_draw(mgl_context *context, mgl_vertex_buffer *self, const mgl_texture *texture);
#endif /* MGL_VERTEX_BUFFER_H */
diff --git a/src/graphics/shader.c b/src/graphics/shader.c
index 3d8a204..4aedb87 100644
--- a/src/graphics/shader.c
+++ b/src/graphics/shader.c
@@ -40,7 +40,7 @@ static void print_compile_log(mgl_context *context, unsigned int shader_id, cons
static void mgl_shader_unload(mgl_shader *self);
-static int mgl_shader_load_from_memory(mgl_shader *self, unsigned char *shader_data, int shader_size, mgl_shader_type shader_type) {
+static int mgl_shader_load_from_memory(mgl_shader *self, const unsigned char *shader_data, int shader_size, mgl_shader_type shader_type) {
self->id = 0;
self->shader_type = shader_type;
@@ -127,7 +127,7 @@ int mgl_shader_program_add_shader_from_file(mgl_shader_program *self, const char
return 0;
}
-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_add_shader_from_memory(mgl_shader_program *self, const unsigned char *shader_data, int shader_size, mgl_shader_type shader_type){
mgl_shader shader;
if(mgl_shader_load_from_memory(&shader, shader_data, shader_size, shader_type) != 0)
return -1;
diff --git a/src/graphics/texture.c b/src/graphics/texture.c
index 1427e6b..c70c0f9 100644
--- a/src/graphics/texture.c
+++ b/src/graphics/texture.c
@@ -63,7 +63,7 @@ int mgl_texture_load_from_file(mgl_texture *self, const char *filepath, mgl_text
return result;
}
-int mgl_texture_load_from_image(mgl_texture *self, mgl_image *image, mgl_texture_load_options *load_options) {
+int mgl_texture_load_from_image(mgl_texture *self, const mgl_image *image, mgl_texture_load_options *load_options) {
return mgl_texture_load_from_memory(self, image->data, image->width, image->height, image->format, load_options);
}
diff --git a/src/graphics/vertex_buffer.c b/src/graphics/vertex_buffer.c
index df2c139..746cfeb 100644
--- a/src/graphics/vertex_buffer.c
+++ b/src/graphics/vertex_buffer.c
@@ -60,12 +60,12 @@ void mgl_vertex_buffer_deinit(mgl_vertex_buffer *self) {
static void mgl_vertex_buffer_set_gl_buffer_pointers(mgl_context *context) {
context->gl.glVertexPointer(2, GL_FLOAT, sizeof(mgl_vertex), (void*)offsetof(mgl_vertex, position));
- context->gl.glColorPointer(4, GL_UNSIGNED_BYTE, sizeof(mgl_vertex), (void*)offsetof(mgl_vertex, color));
context->gl.glTexCoordPointer(2, GL_FLOAT, sizeof(mgl_vertex), (void*)offsetof(mgl_vertex, texcoords));
+ context->gl.glColorPointer(4, GL_UNSIGNED_BYTE, sizeof(mgl_vertex), (void*)offsetof(mgl_vertex, color));
}
/* TODO: Check for glBufferData error */
-static int mgl_vertex_buffer_resize(mgl_vertex_buffer *self, mgl_vertex *vertices, size_t vertex_count) {
+static int mgl_vertex_buffer_resize(mgl_vertex_buffer *self, const mgl_vertex *vertices, size_t vertex_count) {
mgl_context *context = mgl_get_context();
context->gl.glBindBuffer(GL_ARRAY_BUFFER, self->id);
context->gl.glBufferData(GL_ARRAY_BUFFER, sizeof(mgl_vertex) * vertex_count, vertices, mgl_vertex_buffer_usage_to_gl_usage(self->usage));
@@ -80,7 +80,7 @@ void mgl_vertex_buffer_set_position(mgl_vertex_buffer *self, mgl_vec2f position)
}
/* TODO: Check for glBufferSubData error */
-int mgl_vertex_buffer_update(mgl_vertex_buffer *self, mgl_vertex *vertices, size_t vertex_count) {
+int mgl_vertex_buffer_update(mgl_vertex_buffer *self, const mgl_vertex *vertices, size_t vertex_count) {
if(vertex_count != self->vertex_count)
return mgl_vertex_buffer_resize(self, vertices, vertex_count);
@@ -93,7 +93,7 @@ int mgl_vertex_buffer_update(mgl_vertex_buffer *self, mgl_vertex *vertices, size
}
/* TODO: Optimize bind texture */
-void mgl_vertex_buffer_draw(mgl_context *context, mgl_vertex_buffer *self, mgl_texture *texture) {
+void mgl_vertex_buffer_draw(mgl_context *context, mgl_vertex_buffer *self, const mgl_texture *texture) {
if(self->vertex_count == 0 || self->id == 0)
return;
diff --git a/tests/main.c b/tests/main.c
index 0e6e199..0001288 100644
--- a/tests/main.c
+++ b/tests/main.c
@@ -28,7 +28,6 @@ static void draw(mgl_window *window, void *userdata) {
};
mgl_rectangle_draw(context, &rect);
- /*mgl_shader_program_set_uniform_texture2d(u->shader_program, "texture", u->texture);*/
mgl_shader_program_set_uniform_vec2f(u->shader_program, "resolution", (mgl_vec2f){ window->size.x, window->size.y });
mgl_sprite sprite;
@@ -87,23 +86,23 @@ int main(int argc, char **argv) {
mgl_vertex vertices[4] = {
(mgl_vertex){
.position = {0.0f, 0.0f},
- .color = {255, 0, 0, 100},
- .texcoords = {0.0f, 0.0f}
+ .texcoords = {0.0f, 0.0f},
+ .color = {255, 0, 0, 100}
},
(mgl_vertex){
.position = {font.texture.width, 0.0f},
+ .texcoords = {1.0f, 0.0f},
.color = {0, 255, 0, 100},
- .texcoords = {1.0f, 0.0f}
},
(mgl_vertex){
.position = {font.texture.width, font.texture.height},
+ .texcoords = {1.0f, 1.0f},
.color = {0, 0, 255, 100},
- .texcoords = {1.0f, 1.0f}
},
(mgl_vertex){
.position = {0.0f, font.texture.height},
- .color = {255, 0, 255, 100},
- .texcoords = {0.0f, 1.0f}
+ .texcoords = {0.0f, 1.0f},
+ .color = {255, 0, 255, 100}
}
};