|
|
@@ -1,46 +1,94 @@
|
|
|
-#ifndef TILE_GLYPH_H
|
|
|
-#define TILE_GLYPH_H
|
|
|
+#ifndef FREE_GLYPH_H
|
|
|
+#define FREE_GLYPH_H
|
|
|
|
|
|
#include "glyph_attr.h"
|
|
|
|
|
|
+
|
|
|
struct free_glyph {
|
|
|
struct vec2f pos;
|
|
|
struct vec2f size;
|
|
|
- int32_t ch;
|
|
|
+ int32_t c;
|
|
|
struct vec4f fg_color;
|
|
|
struct vec4f bg_color;
|
|
|
};
|
|
|
|
|
|
DA_DEF_STRUCT(struct free_glyph, free_glyph_da);
|
|
|
|
|
|
+struct free_glyph_render {
|
|
|
+ struct free_glyph_da glyphs;
|
|
|
+ struct {
|
|
|
+ uint32_t vert;
|
|
|
+ uint32_t frag;
|
|
|
+ } shaders;
|
|
|
+ uint32_t prog;
|
|
|
+ struct {
|
|
|
+ int32_t resolution;
|
|
|
+ int32_t time;
|
|
|
+ int32_t camera;
|
|
|
+ } uniforms;
|
|
|
+ uint32_t vao;
|
|
|
+ uint32_t vbo;
|
|
|
+};
|
|
|
+
|
|
|
+
|
|
|
enum free_glyph_attr_enum {
|
|
|
FREE_GLYPH_ATTR_POS = 0,
|
|
|
- FREE_GLYPH_ATTR_SIZE = 0,
|
|
|
+ FREE_GLYPH_ATTR_SIZE,
|
|
|
FREE_GLYPH_ATTR_C,
|
|
|
FREE_GLYPH_ATTR_FG_COLOR,
|
|
|
FREE_GLYPH_ATTR_BG_COLOR,
|
|
|
FREE_GLYPH_ATTR_TOTAL
|
|
|
};
|
|
|
|
|
|
+struct free_glyph_render free_glyph_render_create(const char *font_path,
|
|
|
+ const char *vert_path,
|
|
|
+ const char *frag_path);
|
|
|
+
|
|
|
struct free_glyph_da free_glyph_da_create(void);
|
|
|
const struct glyph_attr* free_glyph_get_attrs(void);
|
|
|
|
|
|
-struct free_glyph_da free_glyph_da_calc(struct app app,
|
|
|
- struct free_glyph_da glys,
|
|
|
- const char *cstr, size_t cstr_size,
|
|
|
- struct vec2f pos,
|
|
|
- struct vec2f size,
|
|
|
- struct vec4f fg_color,
|
|
|
- struct vec4f bg_color);
|
|
|
-struct free_glyph_da free_glyph_da_calc_buffer(struct app app,
|
|
|
- struct free_glyph_da glys,
|
|
|
- struct vec2f pos,
|
|
|
- struct vec2f size);
|
|
|
-void free_glyph_da_sync(struct app app, struct free_glyph_da glys);
|
|
|
-uint32_t tile_glyph_gen_buffer(struct free_glyph_da glys);
|
|
|
+struct free_glyph_render free_glyph_render_calc(
|
|
|
+ struct free_glyph_render fgr, const char *cstr, size_t cstr_size,
|
|
|
+ struct vec2f pos, struct vec2f size,
|
|
|
+ struct vec4f fg_color, struct vec4f bg_color);
|
|
|
+struct free_glyph_render free_glyph_render_calc_buffer(
|
|
|
+ struct free_glyph_render fgr, struct app app,
|
|
|
+ struct vec2f pos, struct vec2f size);
|
|
|
+
|
|
|
+void free_glyph_render_sync(struct free_glyph_render fgr);
|
|
|
+struct free_glyph_render free_glyph_render_gen_buffer(
|
|
|
+ struct free_glyph_render fgr);
|
|
|
|
|
|
#if defined(FREE_GLYPH_IMP) || defined(IMP)
|
|
|
|
|
|
+#include "gl_util.h"
|
|
|
+
|
|
|
+struct free_glyph_render
|
|
|
+free_glyph_render_create(const char *font_path, const char *vert_path,
|
|
|
+ const char *frag_path)
|
|
|
+{
|
|
|
+ (void) font_path;
|
|
|
+ struct free_glyph_render fgr = {0};
|
|
|
+ /* fgr = free_glyph_render_load_texture_atlas_or_exit(fgr, font_path); */
|
|
|
+ fgr.glyphs = free_glyph_da_create();
|
|
|
+
|
|
|
+ fgr.shaders.vert = shader_compile_file_or_exit(
|
|
|
+ vert_path, GL_VERTEX_SHADER);
|
|
|
+ fgr.shaders.frag = shader_compile_file_or_exit(
|
|
|
+ frag_path, GL_FRAGMENT_SHADER);
|
|
|
+ fgr.prog = program_link_or_exit(fgr.shaders.vert, fgr.shaders.frag);
|
|
|
+
|
|
|
+ glUseProgram(fgr.prog);
|
|
|
+
|
|
|
+ fgr.uniforms.resolution = get_uniform/* _or_exit */(fgr.prog, "resolution");
|
|
|
+ fgr.uniforms.time = get_uniform/* _or_exit */(fgr.prog, "time");
|
|
|
+ fgr.uniforms.camera = get_uniform/* _or_exit */(fgr.prog, "camera");
|
|
|
+
|
|
|
+ fgr = free_glyph_render_gen_buffer(fgr);
|
|
|
+
|
|
|
+ return fgr;
|
|
|
+}
|
|
|
+
|
|
|
struct free_glyph_da
|
|
|
free_glyph_da_create(void)
|
|
|
{
|
|
|
@@ -48,7 +96,7 @@ free_glyph_da_create(void)
|
|
|
glys.cap = 1024 * 1024;
|
|
|
glys.size = 0;
|
|
|
glys.items = calloc(glys.cap, sizeof(struct free_glyph));
|
|
|
- return gly;
|
|
|
+ return glys;
|
|
|
}
|
|
|
|
|
|
const struct glyph_attr *
|
|
|
@@ -96,13 +144,12 @@ free_glyph_get_attrs(void)
|
|
|
return free_glyph_attr;
|
|
|
}
|
|
|
|
|
|
-struct free_glyph_da
|
|
|
-free_glyph_da_calc(struct app app, struct free_glyph_da glys,
|
|
|
- const char *cstr, size_t cstr_size,
|
|
|
- struct vec2f pos, struct vec2f size,
|
|
|
- struct vec4f fg_color, struct vec4f bg_color)
|
|
|
+struct free_glyph_render
|
|
|
+free_glyph_render_calc(struct free_glyph_render fgr,
|
|
|
+ const char *cstr, size_t cstr_size,
|
|
|
+ struct vec2f pos, struct vec2f size,
|
|
|
+ struct vec4f fg_color, struct vec4f bg_color)
|
|
|
{
|
|
|
- (void) app;
|
|
|
for ( size_t i = 0; i < cstr_size; ++i ) {
|
|
|
char c = cstr[i];
|
|
|
if ( c == '\n' ) {
|
|
|
@@ -115,44 +162,44 @@ free_glyph_da_calc(struct app app, struct free_glyph_da glys,
|
|
|
.fg_color = fg_color,
|
|
|
.bg_color = bg_color
|
|
|
};
|
|
|
- DA_APPEND(glys, gly);
|
|
|
+ DA_APPEND(fgr.glyphs, gly);
|
|
|
}
|
|
|
- return glys;
|
|
|
+ return fgr;
|
|
|
}
|
|
|
|
|
|
-struct free_glyph_da
|
|
|
-free_glyph_da_calc_buffer(struct app app, struct free_glyph_da glys,
|
|
|
- struct vec2f pos, struct vec2f size)
|
|
|
+struct free_glyph_render
|
|
|
+free_glyph_render_calc_buffer(struct free_glyph_render fgr, struct app app,
|
|
|
+ struct vec2f pos, struct vec2f size)
|
|
|
{
|
|
|
- return free_glyph_da_calc(app, glys,
|
|
|
- app.buf.data.items, app.buf.data.size,
|
|
|
- pos, size, vec4fs(1), vec4fs(0));
|
|
|
+ return free_glyph_render_calc(fgr,
|
|
|
+ app.buf.data.items, app.buf.data.size,
|
|
|
+ pos, size, vec4fs(1), vec4fs(0));
|
|
|
}
|
|
|
|
|
|
void
|
|
|
-free_glyph_da_sync(struct app app, struct free_glyph_da glys)
|
|
|
+free_glyph_render_sync(struct free_glyph_render fgr)
|
|
|
{
|
|
|
- (void) app;
|
|
|
glBufferSubData(GL_ARRAY_BUFFER, 0,
|
|
|
- (ssize_t) (glys.size * sizeof(struct free_glyph)),
|
|
|
- glys.items);
|
|
|
+ (ssize_t) (fgr.glyphs.size * sizeof(struct free_glyph)),
|
|
|
+ fgr.glyphs.items);
|
|
|
}
|
|
|
|
|
|
-uint32_t
|
|
|
-free_glyph_gen_buffer(struct free_glyph_da glys)
|
|
|
+struct free_glyph_render
|
|
|
+free_glyph_render_gen_buffer(struct free_glyph_render fgr)
|
|
|
{
|
|
|
- uint32_t id = 0;
|
|
|
- glGenBuffers(1, &id);
|
|
|
- glBindBuffer(GL_ARRAY_BUFFER, id);
|
|
|
+ glGenVertexArrays(1, &fgr.vao);
|
|
|
+ glBindVertexArray(fgr.vao);
|
|
|
+
|
|
|
+ glGenBuffers(1, &fgr.vbo);
|
|
|
+ glBindBuffer(GL_ARRAY_BUFFER, fgr.vbo);
|
|
|
glBufferData(GL_ARRAY_BUFFER,
|
|
|
- (ssize_t)(glys.cap * sizeof(struct tile_glyph)),
|
|
|
- glys.items,
|
|
|
+ (ssize_t)(fgr.glyphs.cap * sizeof(struct free_glyph)),
|
|
|
+ fgr.glyphs.items,
|
|
|
GL_DYNAMIC_DRAW);
|
|
|
glyph_attr_declare(free_glyph_get_attrs(), FREE_GLYPH_ATTR_TOTAL);
|
|
|
- return id;
|
|
|
+ return fgr;
|
|
|
}
|
|
|
|
|
|
-
|
|
|
#endif /* defined(FREE_GLYPH_IMP) || defined(IMP) */
|
|
|
|
|
|
#endif
|