large optimization incoming
This commit is contained in:
parent
ad32cb9a2a
commit
8d78eb0417
Binary file not shown.
Binary file not shown.
@ -14,14 +14,9 @@
|
||||
struct fontapi_font_t
|
||||
{
|
||||
int init;
|
||||
int loaded;
|
||||
int error;
|
||||
|
||||
texture_font_t *font;
|
||||
texture_atlas_t *atlas;
|
||||
|
||||
char path[256];
|
||||
float size;
|
||||
};
|
||||
|
||||
texture_font_t*
|
||||
|
@ -7,5 +7,15 @@
|
||||
|
||||
#pragma once
|
||||
|
||||
#define DEBUG 0
|
||||
|
||||
#if DEBUG
|
||||
|
||||
void
|
||||
log_write(const char *format, ...);
|
||||
|
||||
#else
|
||||
|
||||
#define log_write(...)
|
||||
|
||||
#endif
|
||||
|
@ -381,7 +381,14 @@ draw_string_internal(float x, float y, const char *string, texture_font_t *fnt,
|
||||
|
||||
texture_font_load_glyphs(fnt, string);
|
||||
|
||||
for (size_t i = 0; i < strlen(string); ++i)
|
||||
int len = strlen(string);
|
||||
if (len == 0)
|
||||
return;
|
||||
|
||||
GLuint indices[6 * len];
|
||||
struct vertex_v2ft2fc4f vertices[4 * len];
|
||||
|
||||
for (size_t i = 0; i < len; ++i)
|
||||
{
|
||||
texture_glyph_t *glyph = texture_font_find_glyph(fnt, &string[i]);
|
||||
if (glyph == NULL)
|
||||
@ -402,23 +409,27 @@ draw_string_internal(float x, float y, const char *string, texture_font_t *fnt,
|
||||
float s1 = glyph->s1;
|
||||
float t1 = glyph->t1;
|
||||
|
||||
GLuint idx = dstream.next_index;
|
||||
GLuint indices[] = { idx, idx + 1, idx + 2,
|
||||
idx + 2, idx + 3, idx };
|
||||
struct vertex_v2ft2fc4f vertices[] = {
|
||||
{ (vec2){ x0, y0 }, (vec2){ s0, t0 }, color },
|
||||
{ (vec2){ x0, y1 }, (vec2){ s0, t1 }, color },
|
||||
{ (vec2){ x1, y1 }, (vec2){ s1, t1 }, color },
|
||||
{ (vec2){ x1, y0 }, (vec2){ s1, t0 }, color }
|
||||
};
|
||||
GLuint idx = dstream.next_index + i * 4;
|
||||
indices[i * 6 + 0] = idx;
|
||||
indices[i * 6 + 1] = idx + 1;
|
||||
indices[i * 6 + 2] = idx + 2;
|
||||
indices[i * 6 + 3] = idx + 2;
|
||||
indices[i * 6 + 4] = idx + 3;
|
||||
indices[i * 6 + 5] = idx;
|
||||
|
||||
dis_push_indices(6, indices);
|
||||
dis_push_vertices(4, sizeof(struct vertex_v2ft2fc4f), vertices);
|
||||
vertices[i * 4 + 0] = (struct vertex_v2ft2fc4f){ (vec2){ x0, y0 }, (vec2){ s0, t0 }, color };
|
||||
vertices[i * 4 + 1] = (struct vertex_v2ft2fc4f){ (vec2){ x0, y1 }, (vec2){ s0, t1 }, color };
|
||||
vertices[i * 4 + 2] = (struct vertex_v2ft2fc4f){ (vec2){ x1, y1 }, (vec2){ s1, t1 }, color };
|
||||
vertices[i * 4 + 3] = (struct vertex_v2ft2fc4f){ (vec2){ x1, y0 }, (vec2){ s1, t0 }, color };
|
||||
|
||||
pen_x += glyph->advance_x;
|
||||
if (glyph->height > size_y)
|
||||
size_y = glyph->height;
|
||||
}
|
||||
|
||||
dis_push_indices(6 * len, indices);
|
||||
dis_push_vertices(4 * len, sizeof(struct vertex_v2ft2fc4f), vertices);
|
||||
|
||||
if (out_x)
|
||||
*out_x = pen_x - x;
|
||||
if (out_y)
|
||||
@ -437,6 +448,7 @@ xoverlay_draw_string(float x, float y, const char *string, xoverlay_font_handle_
|
||||
if (fnt == NULL)
|
||||
{
|
||||
log_write("xoverlay_draw_string: INVALID FONT HANDLE %u\n", font);
|
||||
return;
|
||||
}
|
||||
|
||||
fnt->rendermode = RENDER_NORMAL;
|
||||
@ -459,7 +471,10 @@ xoverlay_draw_string_with_outline(float x, float y, const char *string, xoverlay
|
||||
|
||||
texture_font_t *fnt = fontapi_get(font);
|
||||
if (fnt == NULL)
|
||||
{
|
||||
log_write("xoverlay_draw_string: INVALID FONT HANDLE %u\n", font);
|
||||
return;
|
||||
}
|
||||
|
||||
fnt->rendermode = RENDER_OUTLINE_POSITIVE;
|
||||
fnt->outline_thickness = outline_width;
|
||||
|
BIN
src/drawglx.o
BIN
src/drawglx.o
Binary file not shown.
Binary file not shown.
@ -34,12 +34,21 @@ xoverlay_font_load(const char *path, float size)
|
||||
{
|
||||
struct fontapi_font_t result;
|
||||
memset(&result, 0, sizeof(result));
|
||||
strncpy(result.path, path, sizeof(result.path) - 1);
|
||||
result.size = size;
|
||||
xoverlay_font_handle_t handle = fontapi_add_font(&result);
|
||||
log_write("fontapi: init font %u: %d %d\n", handle, loaded_fonts[handle].init, result.init);
|
||||
fflush(stdout);
|
||||
return handle;
|
||||
|
||||
result.atlas = texture_atlas_new(1024, 1024, 1);
|
||||
if (result.atlas != NULL)
|
||||
{
|
||||
result.font = texture_font_new_from_file(result.atlas, size, path);
|
||||
if (result.font == NULL)
|
||||
{
|
||||
log_write("fontapi: load: could not init font\n");
|
||||
}
|
||||
}
|
||||
else
|
||||
{
|
||||
log_write("fontapi: load: could not init atlas\n");
|
||||
}
|
||||
return fontapi_add_font(&result);
|
||||
}
|
||||
|
||||
void
|
||||
@ -49,8 +58,6 @@ xoverlay_font_unload(xoverlay_font_handle_t handle)
|
||||
return;
|
||||
if (loaded_fonts[handle].init == 0)
|
||||
return;
|
||||
if (loaded_fonts[handle].loaded == 0)
|
||||
return;
|
||||
|
||||
texture_atlas_delete(loaded_fonts[handle].atlas);
|
||||
texture_font_delete(loaded_fonts[handle].font);
|
||||
@ -59,69 +66,30 @@ xoverlay_font_unload(xoverlay_font_handle_t handle)
|
||||
xoverlay_font_handle_t
|
||||
fontapi_add_font(struct fontapi_font_t *font)
|
||||
{
|
||||
for (xoverlay_font_handle_t i = 0; i < XOVERLAY_FONT_COUNT; ++i)
|
||||
for (xoverlay_font_handle_t i = 1; i < XOVERLAY_FONT_COUNT; ++i)
|
||||
{
|
||||
if (loaded_fonts[i].init == 0)
|
||||
{
|
||||
font->init = 1;
|
||||
memcpy(&loaded_fonts[i], font, sizeof(struct fontapi_font_t));
|
||||
log_write("init success: %u %p %p\n", i, font->atlas, font->font);
|
||||
return i;
|
||||
}
|
||||
}
|
||||
return XOVERLAY_FONT_INVALID_HANDLE;
|
||||
}
|
||||
|
||||
void
|
||||
fontapi_texture_load(xoverlay_font_handle_t handle)
|
||||
{
|
||||
log_write("fontapi: loading font %u\n", handle);
|
||||
struct fontapi_font_t *font = &loaded_fonts[handle];
|
||||
|
||||
font->error = 1;
|
||||
|
||||
font->atlas = texture_atlas_new(1024, 1024, 1);
|
||||
if (font->atlas != NULL)
|
||||
{
|
||||
font->font = texture_font_new_from_file(font->atlas, font->size, font->path);
|
||||
if (font->font != NULL)
|
||||
{
|
||||
font->error = 0;
|
||||
}
|
||||
else
|
||||
{
|
||||
log_write("fontapi: load: could not init font\n");
|
||||
}
|
||||
}
|
||||
else
|
||||
{
|
||||
log_write("fontapi: load: could not init atlas\n");
|
||||
}
|
||||
|
||||
font->loaded = 1;
|
||||
}
|
||||
|
||||
texture_font_t*
|
||||
fontapi_get(xoverlay_font_handle_t handle)
|
||||
{
|
||||
log_write("fontapi: finding font %u\n", handle);
|
||||
if (handle >= XOVERLAY_FONT_COUNT)
|
||||
{
|
||||
log_write("fontapi: invalid handle %u\n", handle);
|
||||
fflush(stdout);
|
||||
return NULL;
|
||||
}
|
||||
if (loaded_fonts[handle].init == 0)
|
||||
{
|
||||
log_write("fontapi: font '%s' %u not init\n", loaded_fonts[handle - 1].path, handle);
|
||||
fflush(stdout);
|
||||
return NULL;
|
||||
}
|
||||
if (loaded_fonts[handle].loaded == 0)
|
||||
fontapi_texture_load(handle);
|
||||
if (loaded_fonts[handle].error == 1)
|
||||
{
|
||||
log_write("fontapi: %u loading error\n", handle);
|
||||
fflush(stdout);
|
||||
log_write("fontapi: font %u not init\n", handle);
|
||||
return NULL;
|
||||
}
|
||||
return loaded_fonts[handle].font;
|
||||
|
BIN
src/fontapi.o
BIN
src/fontapi.o
Binary file not shown.
BIN
src/input.o
BIN
src/input.o
Binary file not shown.
@ -12,6 +12,8 @@
|
||||
|
||||
FILE *log_file = 0;
|
||||
|
||||
#if DEBUG
|
||||
|
||||
void
|
||||
log_write(const char *format, ...)
|
||||
{
|
||||
@ -34,3 +36,4 @@ log_write(const char *format, ...)
|
||||
va_end(args);
|
||||
}
|
||||
|
||||
#endif
|
||||
|
BIN
src/overlay.o
BIN
src/overlay.o
Binary file not shown.
Binary file not shown.
Binary file not shown.
Binary file not shown.
BIN
src/programs.o
BIN
src/programs.o
Binary file not shown.
BIN
src/textureapi.o
BIN
src/textureapi.o
Binary file not shown.
Loading…
x
Reference in New Issue
Block a user