diff options
author | dec05eba <dec05eba@protonmail.com> | 2021-10-21 07:14:46 +0200 |
---|---|---|
committer | dec05eba <dec05eba@protonmail.com> | 2021-10-21 07:14:46 +0200 |
commit | f02a283c06c51cb29f79e89754b31ffd6952d2e6 (patch) | |
tree | 2eb691e105b65d3ca0464ed00628dd0b0974955a /include/mgl/graphics | |
parent | 2d4457a5ee926eca221102ee70f118b305ea2670 (diff) |
Add vertex buffer
Diffstat (limited to 'include/mgl/graphics')
-rw-r--r-- | include/mgl/graphics/vertex.h | 13 | ||||
-rw-r--r-- | include/mgl/graphics/vertex_buffer.h | 44 |
2 files changed, 57 insertions, 0 deletions
diff --git a/include/mgl/graphics/vertex.h b/include/mgl/graphics/vertex.h new file mode 100644 index 0000000..b4a5830 --- /dev/null +++ b/include/mgl/graphics/vertex.h @@ -0,0 +1,13 @@ +#ifndef MGL_VERTEX_H +#define MGL_VERTEX_H + +#include "color.h" +#include "../system/vec.h" + +typedef struct { + mgl_vec2f position; + mgl_color color; + mgl_vec2f texcoords; +} mgl_vertex; + +#endif /* MGL_VERTEX_H */ diff --git a/include/mgl/graphics/vertex_buffer.h b/include/mgl/graphics/vertex_buffer.h new file mode 100644 index 0000000..c1e4af1 --- /dev/null +++ b/include/mgl/graphics/vertex_buffer.h @@ -0,0 +1,44 @@ +#ifndef MGL_VERTEX_BUFFER_H +#define MGL_VERTEX_BUFFER_H + +#include "vertex.h" +#include <stddef.h> + +typedef struct mgl_context mgl_context; +typedef struct mgl_texture mgl_texture; + +typedef enum { + MGL_PRIMITIVE_POINTS, + MGL_PRIMITIVE_LINES, + MGL_PRIMITIVE_LINE_STRIP, + MGL_PRIMITIVE_TRIANGLES, + MGL_PRIMITIVE_TRIANGLE_STRIP, + MGL_PRIMITIVE_TRIANGLE_FAN, + MGL_PRIMITIVE_QUADS, + MGL_PRIMITIVE_QUAD_STRIP, + MGL_PRIMITIVE_POLYGON, +} mgl_primitive_type; + +typedef enum { + MGL_USAGE_STREAM, + MGL_USAGE_DYNAMIC, + MGL_USAGE_STATIC +} mgl_vertex_buffer_usage; + +typedef struct { + unsigned int id; + size_t vertex_count; + mgl_primitive_type primitive_type; + mgl_vertex_buffer_usage usage; + mgl_vec2f position; +} mgl_vertex_buffer; + +int mgl_vertex_buffer_init(mgl_vertex_buffer *self, mgl_primitive_type primitive_type, mgl_vertex_buffer_usage usage); +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); +/* |texture| can be NULL to not use any texture */ +void mgl_vertex_buffer_draw(mgl_context *context, mgl_vertex_buffer *self, mgl_texture *texture); + +#endif /* MGL_VERTEX_BUFFER_H */ |