From 047f52e7cbde3ddbd3647083ab75ffcfb75f7f73 Mon Sep 17 00:00:00 2001 From: decimad Date: Thu, 22 Dec 2016 15:26:31 +0100 Subject: [PATCH] Move builtin font resources out of opengl_gal translation unit --- common/CMakeLists.txt | 1 + common/gal/opengl/bitmap_font_desc.c | 20 ++---------- common/gal/opengl/bitmap_font_img.c | 7 +---- common/gal/opengl/gl_resources.cpp | 41 +++++++++++++++++++++++++ common/gal/opengl/gl_resources.h | 46 ++++++++++++++++++++++++++++ common/gal/opengl/opengl_gal.cpp | 39 +++++------------------ include/gal/opengl/opengl_gal.h | 2 -- 7 files changed, 99 insertions(+), 57 deletions(-) create mode 100644 common/gal/opengl/gl_resources.cpp create mode 100644 common/gal/opengl/gl_resources.h diff --git a/common/CMakeLists.txt b/common/CMakeLists.txt index 210f7545a9..bdb4451c2a 100644 --- a/common/CMakeLists.txt +++ b/common/CMakeLists.txt @@ -55,6 +55,7 @@ set( GAL_SRCS # OpenGL GAL gal/opengl/opengl_gal.cpp + gal/opengl/gl_resources.cpp gal/opengl/shader.cpp gal/opengl/vertex_item.cpp gal/opengl/vertex_container.cpp diff --git a/common/gal/opengl/bitmap_font_desc.c b/common/gal/opengl/bitmap_font_desc.c index daae309726..7b1a00f618 100644 --- a/common/gal/opengl/bitmap_font_desc.c +++ b/common/gal/opengl/bitmap_font_desc.c @@ -1,19 +1,11 @@ // Generated by msdf-atlasgen, do not modify. -static const struct { - unsigned int smooth_pixels; - float min_y; - float max_y; -} font_information = { +FONT_INFO_TYPE font_information = { 1, -8.16f, 39.84f }; -static const struct bitmap_span { - unsigned int start; - unsigned int end; - unsigned int cumulative; -} font_codepoint_spans[] = { +FONT_SPAN_TYPE font_codepoint_spans[] = { { 33, 127, 0 }, { 161, 592, 94 }, { 658, 659, 525 }, @@ -105,13 +97,7 @@ static const struct bitmap_span { { 65533, 65534, 1216 } }; -static const struct bitmap_glyph { - unsigned int atlas_x, atlas_y; - unsigned int atlas_w, atlas_h; - float minx, maxx; - float miny, maxy; - float advance; -} font_codepoint_infos[] = { +FONT_GLYPH_TYPE font_codepoint_infos[] = { { 129, 991, 9, 33, 8.6880f, 15.1200f, -0.5760f, 29.7120f, 24.0000f }, { 77, 440, 14, 14, 6.1920f, 17.8080f, 20.6400f, 32.5920f, 24.0000f }, { 763, 479, 24, 32, 1.2960f, 22.7040f, 0.0000f, 29.7120f, 24.0000f }, diff --git a/common/gal/opengl/bitmap_font_img.c b/common/gal/opengl/bitmap_font_img.c index 9ecef1790c..2a9d9e0a70 100644 --- a/common/gal/opengl/bitmap_font_img.c +++ b/common/gal/opengl/bitmap_font_img.c @@ -1,11 +1,6 @@ // Generated by msdf-atlasgen, do not modify. -static const struct { - unsigned int width, height; - unsigned int char_border; - unsigned int spacing; - unsigned char pixels[1024*1024*3]; -} font_image = { +FONT_IMAGE_TYPE font_image = { 1024, 1024, 1, 1, { 86,86,86,169,86,86,253,86,86,239,86,86,156,86,86,73,86,73,0,0,0,0,86,0,0,86,0,0,86,0,0,86,0,0,86,0,0,86,0,0,86,0,0,86,0,0,86,0,0,86,0,79,86,79,163,86,86,246,86,86,246,86,86,163,86,86,79,86,79,0,0,0,86,86,86,86,86,169,86,86,253,86,86,239,86,86,156,73,86,73,0,86,0,0,86,0,0,86,0,0,86,0,0,86,0,0,86,0,0,86,0,0,86,0,0,86,0,0,86,0,0,0,0,86,86,86,86,169,86,86,159,86,86,75,75,107,86,86,191,86,86,137,86,86,54,54,86,86,86,129,86,86,199,86,86,116,67,67,86,86,150,86,86,178,86,86,95,86,88,86,86,171,86,86,157,86,86,73,73,86,86,86,109,86,86,193,86,86,135,52,86,52,86,131,86,86,169,86,86,86,86,0,0,0,0,255,0,0,255,0,0,255,0,0,255,0,0,255,0,0,255,0,0,255,0,0,255,0,0,255,0,10,255,10,46,255,46,70,255,70,83,255,83,85,255,85,77,191,77,59,107,59,38,24,24,17,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,124,4,4,205,27,27,255,46,46,255,62,62,255,73,73,255,80,80,255,85,85,255,86,86,255,83,83,255,77,77,255,66,66,255,50,50,255,29,29,255,2,2,255,0,0,255,0,0,255,0,0,255,0,0,255,0,0,255,0,0,255,0,0,0,0,0,58,0,0,133,0,0,208,22,22,246,59,59,171,96,97,96,21,135,21,0,0,0,0,0,0,0,0,0,0,2,2,255,6,6,255,3,3,255,0,0,255,0,0,255,0,0,255,0,0,255,0,0,255,0,0,255,0,0,255,0,0,255,0,0,255,0,0,255,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,32,0,0,102,0,0,171,0,0,240,18,18,231,42,42,163,67,67,95,91,91,26,115,26,0,140,0,0,164,0,0,0,0,0,86,0,0,169,0,0,253,0,0,251,0,0,168,0,0,85,0,0,0,86,0,0,86,0,0,86,0,0,86,0,0,86,0,0,86,0,0,86,53,53,86,86,137,86,86,220,86,86,255,86,86,197,86,86,113,86,86,30,30,0,0,0,0,255,0,0,255,0,0,255,0,0,255,0,0,255,0,0,255,0,0,255,0,0,255,0,0,255,0,10,255,10,46,255,46,70,255,70,83,255,83,85,255,85,77,191,77,59,107,59,38,24,24,17,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,255,0,0,255,0,0,255,0,0,255,0,0,255,0,7,255,7,37,255,37,59,255,59,74,255,74,82,255,82,86,255,86,84,255,84,78,255,78,65,255,65,46,255,46,20,255,20,0,255,0,0,255,0,0,255,0,0,255,0,0,255,0,0,255,0,0,0,0,0,255,0,0,255,0,0,255,0,0,255,0,0,255,0,7,255,7,37,255,37,59,255,59,74,255,74,82,255,82,86,255,86,84,255,84,78,255,78,65,255,65,46,255,46,20,255,20,0,255,0,0,255,0,0,255,0,0,255,0,0,255,0,0,255,0,0,0,0,98,86,86,178,86,86,255,86,86,243,86,86,162,86,86,80,80,86,0,0,86,0,0,86,0,0,86,0,0,86,0,0,86,0,0,86,0,0,0,86,0,0,86,0,0,86,0,0,86,0,0,86,0,0,86,0,0,86,81,81,86,162,86,86,243,86,86,255,86,86,189,86,86,109,86,86,28,28,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,18,0,0,99,27,27,181,55,55,255,72,72,255,82,82,255,86,86,255,82,82,255,68,68,255,39,39,255,0,0,255,0,0,255,0,0,255,0,0,255,0,0,255,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,13,0,0,29,46,68,46,62,150,62,76,233,76,85,255,85,85,255,85,77,255,77,59,255,59,29,255,29,0,255,0,0,255,0,0,255,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,11,10,10,33,55,93,55,74,177,74,85,255,85,84,255,84,73,255,73,51,255,51,16,255,16,0,255,0,0,255,0,0,255,0,0,255,0,0,255,0,0,255,0,0,255,0,0,0,0,0,0,86,0,0,86,0,0,86,0,0,86,0,0,86,0,0,86,0,0,86,17,17,86,86,101,86,86,184,86,86,255,86,86,217,86,86,133,86,86,50,50,86,0,0,86,0,0,86,0,0,86,0,0,86,0,0,86,0,0,86,0,0,0,0,39,0,0,0,255,0,0,255,0,0,255,0,0,255,0,0,255,3,3,255,31,31,255,52,52,255,67,67,255,77,77,255,83,83,255,86,86,255,85,85,255,81,81,255,75,75,255,67,67,255,56,56,255,44,44,249,31,31,165,18,18,82,4,4,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,8,8,8,38,38,38,62,62,62,77,77,77,85,85,85,85,85,85,78,78,78,64,64,64,42,42,42,12,12,12,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,8,8,8,38,38,38,62,62,62,77,77,77,85,85,85,85,85,85,78,78,78,64,64,64,42,42,42,12,12,12,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,19,0,19,44,255,44,63,255,63,76,255,76,83,255,83,86,255,86,84,255,84,79,255,79,70,255,70,57,255,57,38,255,38,17,223,17,0,141,0,0,58,0,0,0,0,0,0,0,86,0,0,86,0,0,86,0,0,86,33,33,86,86,114,86,86,195,86,86,189,86,86,113,37,86,37,0,86,0,0,86,0,0,86,0,86,0,0,86,0,0,86,0,0,86,30,30,86,107,86,86,183,86,86,202,86,86,121,86,39,39,86,0,0,86,0,0,86,0,0,86,0,0,86,0,0,0,255,0,0,255,0,0,255,0,0,255,0,0,255,3,3,255,31,31,255,52,52,255,67,67,255,77,77,255,83,83,255,86,86,255,85,85,255,81,81,255,75,75,255,67,67,255,56,56,255,44,44,249,31,31,165,18,18,82,4,4,0,0,0,255,0,0,255,0,0,255,0,0,255,0,0,255,0,0,255,27,27,255,53,53,255,70,70,255,81,81,255,85,85,255,85,85,255,83,83,255,78,78,255,71,71,255,60,60,255,46,46,255,30,30,197,13,13,113,0,0,30,0,0,0,0,0,255,0,0,255,0,0,255,0,0,255,0,0,255,3,3,255,31,31,255,52,52,255,67,67,255,77,77,255,83,83,255,86,86,255,85,85,255,81,81,255,75,75,255,67,67,255,56,56,255,44,44,249,31,31,165,18,18,82,4,4,0,0,0,0,255,0,0,255,0,0,255,0,0,255,0,0,255,0,31,255,31,56,255,56,73,255,73,83,255,83,86,255,86,83,255,83,75,255,75,58,255,58,33,255,33,0,255,0,0,255,0,0,255,0,0,255,0,0,255,0,0,255,0,0,0,0,86,86,86,86,169,86,86,253,86,86,251,86,86,168,86,86,85,85,86,1,1,86,0,0,86,0,0,86,0,0,0,0,86,0,0,86,0,0,86,53,53,86,86,137,86,86,220,86,86,255,86,86,197,86,86,113,86,86,30,30,0,0,0,0,255,0,0,255,0,0,255,0,0,255,0,13,255,13,50,255,50,74,255,74,85,255,85,83,255,83,68,255,68,40,255,40,1,255,1,0,0,0,0,0,0,0,0,34,0,0,34,23,23,34,34,107,34,34,190,34,34,255,34,34,211,34,34,127,34,34,44,34,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,31,31,31,56,56,56,73,73,73,83,83,83,86,86,86,82,82,82,71,71,71,53,53,53,28,28,28,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,34,86,34,34,169,34,34,253,34,34,231,34,34,148,34,34,65,34,34,0,0,34,0,0,0,0,0,0,0,0,0,255,0,28,255,28,60,255,60,80,255,80,86,255,86,79,255,79,59,255,59,27,255,27,0,255,0,0,255,0,0,255,0,0,255,0,0,255,0,0,0,0,0,86,0,0,86,0,0,86,0,0,86,0,0,86,0,0,86,0,0,86,0,17,86,17,101,86,86,184,86,86,255,86,86,255,86,86,255,86,86,255,86,86,255,86,86,255,86,86,255,86,86,255,86,86,255,86,86,255,86,86,255,86,86,255,86,86,255,86,86,193,86,86,109,86,86,26,26,86,0,0,0,0,86,0,0,169,0,0,253,0,0,251,0,0,168,0,0,85,0,0,0,86,0,0,86,0,0,86,0,0,86,0,0,86,0,0,86,0,0,86,53,53,86,86,137,86,86,220,86,86,255,86,86,197,86,86,113,86,86,30,30,0,0,0,107,45,45,86,86,128,62,62,211,33,33,255,0,0,255,0,0,255,0,0,255,0,0,0,0,0,0,0,0,0,0,31,0,15,115,15,37,198,37,55,255,55,68,255,68,76,255,76,78,20,78,72,0,72,57,0,57,32,0,32,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,108,21,21,189,49,49,255,68,68,255,81,81,255,86,86,255,83,83,255,73,73,255,56,56,255,30,30,0,0,0,0,0,0,0,0,0,0,0,0,26,0,0,100,0,0,173,0,0,247,0,0,255,0,0,255,0,0,255,0,0,255,0,0,255,0,0,255,0,0,0,0,0,86,86,86,86,86,169,86,86,253,86,86,251,86,86,168,85,86,85,1,86,1,0,86,0,0,86,0,0,86,0,0,86,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,29,0,0,101,0,0,173,0,0,245,0,0,198,0,0,0,0,86,0,0,86,0,0,86,0,0,86,0,0,86,0,0,86,0,0,86,0,0,86,0,0,86,0,0,86,0,0,86,0,0,86,0,0,86,0,0,86,0,0,86,0,0,86,0,0,86,59,59,86,86,143,86,86,226,86,86,255,86,86,255,86,86,255,86,86,255,86,86,255,86,86,255,86,86,255,86,86,255,86,86,255,86,86,255,86,86,255,86,86,255,86,86,255,86,86,255,86,86,255,86,86,172,86,86,89,5,86,5,0,0,0,0,86,0,0,86,0,0,86,0,0,86,0,0,86,0,0,86,0,0,86,0,0,86,0,0,86,0,0,86,0,0,86,0,0,86,0,0,86,0,0,86,0,0,86,0,52,86,52,135,86,86,219,86,86,255,86,86,255,86,86,255,86,86,255,86,86,255,86,86,255,86,86,255,86,86,255,86,86,255,86,86,255,86,86,255,86,86,255,86,86,241,86,86,158,86,86,75,75,86,0,0,0,50,0,0,50,0,0,50,0,0,50,0,0,50,0,0,50,0,0,50,0,0,50,0,0,50,0,0,50,0,0,50,0,0,50,1,1,50,50,83,50,50,166,50,50,248,50,50,224,50,50,141,50,50,59,0,50,0,0,50,0,0,50,0,0,50,0,0,50,0,0,50,0,52,50,50,134,50,50,217,50,50,255,50,50,184,50,50,102,50,50,20,20,50,0,0,0,0,8,8,255,41,41,255,65,65,181,79,79,99,88,88,17,95,17,0,0,0,0,86,0,0,86,0,0,86,0,53,86,53,134,86,86,214,86,86,255,86,86,207,86,86,125,86,86,44,44,86,0,0,86,0,0,86,0,0,86,0,0,86,0,0,86,0,0,86,86,0,0,86,0,0,86,0,0,86,0,0,86,0,0,86,0,0,86,36,36,86,117,86,86,198,86,86,255,86,86,234,86,86,153,86,86,72,72,0,0,0,0,255,0,0,255,0,12,255,12,47,255,47,71,255,71,84,255,84,85,255,85,76,186,76,58,103,58,37,19,19,16,0,0,0,0,66,0,0,66,53,53,66,66,137,66,66,220,66,66,255,66,66,197,66,66,113,66,66,30,30,0,0,0,86,86,86,169,86,86,253,86,86,247,86,86,164,86,86,81,81,86,0,0,86,0,0,86,0,0,86,0,0,86,0,0,86,86,0,0,86,0,0,86,0,0,86,0,0,86,0,0,86,11,11,86,86,88,86,86,165,86,86,242,86,86,255,86,86,202,86,86,125,47,86,47,0,0,0,86,107,86,86,183,86,86,255,86,86,224,86,86,146,86,86,69,69,86,0,0,86,0,0,0,0,86,12,12,86,86,95,86,86,179,86,86,255,86,86,202,86,86,119,86,86,35,35,86,0,0,0,0,86,0,0,86,51,51,86,86,128,86,86,206,86,86,255,86,86,200,86,86,124,86,86,48,48,0,0,0,0,55,0,0,136,0,7,218,7,26,255,26,43,255,43,58,255,58,70,255,70,79,255,79,84,255,84,86,255,86,83,255,83,77,255,77,65,255,65,48,255,48,25,255,25,0,255,0,0,255,0,0,255,0,0,255,0,0,255,0,0,255,0, 86,169,86,169,169,169,253,169,169,239,169,169,156,169,156,73,169,73,0,0,0,0,169,0,0,169,0,0,169,0,0,169,0,0,169,0,0,169,0,0,169,0,0,169,0,0,169,0,0,169,0,79,169,79,163,169,163,246,169,169,246,169,169,163,169,163,79,169,79,0,0,0,169,86,86,169,169,169,169,169,253,169,169,239,156,169,156,73,169,73,0,169,0,0,169,0,0,169,0,0,169,0,0,169,0,0,169,0,0,169,0,0,169,0,0,169,0,0,169,0,0,0,0,86,86,169,169,169,169,169,159,159,73,75,75,107,169,107,191,169,169,137,137,169,73,54,73,169,129,129,169,169,199,116,169,116,67,73,73,150,150,169,169,178,169,169,95,95,88,73,88,171,169,169,157,157,169,73,73,73,169,109,109,169,169,193,135,169,135,52,73,73,131,131,169,169,169,169,169,86,86,0,0,0,0,255,0,0,255,0,0,255,0,0,255,0,0,255,0,0,255,0,0,255,0,0,255,0,28,255,28,80,255,80,122,255,122,151,255,151,166,255,166,169,255,169,159,191,159,139,107,107,118,24,24,97,0,0,76,0,0,55,0,0,34,0,0,13,0,0,0,0,0,0,0,0,50,50,104,83,83,184,108,108,255,128,128,255,144,144,255,156,156,255,164,164,255,168,168,255,169,169,255,167,167,255,160,160,255,148,148,255,131,131,255,108,108,255,80,80,255,45,45,255,4,4,255,0,0,255,0,0,255,0,0,255,0,0,255,0,0,0,0,0,22,20,20,97,58,58,172,96,96,247,134,134,207,132,171,132,57,209,57,0,31,31,0,56,56,0,75,75,255,85,85,255,89,89,255,86,86,255,77,77,255,60,60,255,35,35,255,4,4,255,0,0,255,0,0,255,0,0,255,0,0,255,0,0,255,0,0,255,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,24,0,55,49,49,125,73,73,194,98,98,255,122,122,211,146,146,141,171,141,70,195,70,0,219,0,0,244,0,0,0,0,0,86,0,0,169,0,0,253,0,0,251,0,0,168,0,0,85,0,0,1,0,0,0,169,0,0,169,0,0,169,0,0,169,0,0,169,0,0,169,53,53,169,137,137,169,169,220,169,169,255,169,169,197,169,169,113,113,169,30,30,0,0,0,0,255,0,0,255,0,0,255,0,0,255,0,0,255,0,0,255,0,0,255,0,0,255,0,28,255,28,80,255,80,122,255,122,151,255,151,166,255,166,169,255,169,159,191,159,139,107,107,118,24,24,97,0,0,76,0,0,55,0,0,34,0,0,13,0,0,0,0,0,0,0,0,0,255,0,0,255,0,0,255,0,0,255,0,43,255,43,83,255,83,116,255,116,140,255,140,156,255,156,166,255,166,169,255,169,168,255,168,161,255,161,147,255,147,126,255,126,97,255,97,60,255,60,15,255,15,0,255,0,0,255,0,0,255,0,0,255,0,0,0,0,0,255,0,0,255,0,0,255,0,0,255,0,43,255,43,83,255,83,116,255,116,140,255,140,156,255,156,166,255,166,169,255,169,168,255,168,161,255,161,147,255,147,126,255,126,97,255,97,60,255,60,15,255,15,0,255,0,0,255,0,0,255,0,0,255,0,0,0,0,77,169,77,157,169,157,238,169,169,255,169,169,180,169,169,98,98,169,17,17,169,0,0,169,0,0,169,0,0,169,0,0,169,0,0,169,0,0,0,169,0,0,169,0,0,169,0,0,169,0,0,169,0,0,169,18,18,169,99,99,169,181,169,169,255,169,169,249,169,169,168,168,169,88,88,169,7,7,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,34,0,1,68,1,83,103,83,165,135,135,247,154,154,255,165,165,255,169,169,255,165,165,255,148,148,255,114,114,255,66,66,255,6,6,255,0,0,255,0,0,255,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,13,0,0,29,0,0,46,0,0,62,0,0,78,0,0,95,0,0,111,58,58,128,141,141,144,158,224,158,168,255,168,168,255,168,159,255,159,138,255,138,103,255,103,54,255,54,0,255,0,0,255,0,0,0,0,0,0,0,0,0,4,0,0,26,0,0,48,0,0,70,0,0,92,10,10,114,93,93,136,156,177,156,168,255,168,167,255,167,155,255,155,128,255,128,88,255,88,38,255,38,0,255,0,0,255,0,0,255,0,0,255,0,0,255,0,0,255,0,0,0,0,86,0,0,0,0,0,0,0,169,0,0,169,0,0,169,0,0,169,0,0,169,17,17,169,101,101,169,169,184,169,169,255,169,169,217,169,169,133,133,169,50,50,169,0,0,169,0,0,169,0,0,169,0,0,169,0,0,0,0,0,0,0,123,0,0,39,0,0,0,255,0,0,255,0,0,255,0,0,255,42,42,255,80,80,255,111,111,255,134,134,255,149,149,255,160,160,255,167,167,255,169,169,255,168,168,255,165,165,255,159,159,255,150,150,255,138,138,255,126,126,249,113,113,165,100,100,82,86,82,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,43,43,43,83,83,83,117,117,117,142,142,142,160,160,160,168,168,168,168,168,168,161,161,161,145,145,145,120,120,120,88,88,88,49,49,49,4,4,4,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,43,43,43,83,83,83,117,117,117,142,142,142,160,160,160,168,168,168,168,168,168,161,161,161,145,145,145,120,120,120,88,88,88,49,49,49,4,4,4,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,25,0,25,64,0,64,97,0,97,124,0,124,145,255,145,158,255,158,166,255,166,169,255,169,168,255,168,162,255,162,153,255,153,138,255,138,119,255,119,96,210,96,67,128,67,29,45,29,0,0,0,0,0,0,169,0,0,169,0,0,169,0,0,169,51,51,169,132,132,169,169,214,169,169,223,146,169,146,70,169,70,0,169,0,0,169,0,0,169,0,0,0,0,169,0,0,169,0,0,169,64,64,169,140,140,169,217,169,169,220,169,139,139,169,58,58,169,0,0,169,0,0,169,0,0,169,0,0,169,0,0,0,255,0,0,255,0,0,255,0,0,255,42,42,255,80,80,255,111,111,255,134,134,255,149,149,255,160,160,255,167,167,255,169,169,255,168,168,255,165,165,255,159,159,255,150,150,255,138,138,255,126,126,249,113,113,165,100,100,82,86,82,0,0,0,255,0,0,255,0,0,255,0,0,255,20,20,255,65,65,255,104,104,255,133,133,255,152,152,255,164,164,255,169,169,255,169,169,255,166,166,255,162,162,255,154,154,255,143,143,255,128,128,255,112,112,197,95,95,113,75,75,30,30,54,0,0,0,255,0,0,255,0,0,255,0,0,255,42,42,255,80,80,255,111,111,255,134,134,255,149,149,255,160,160,255,167,167,255,169,169,255,168,168,255,165,165,255,159,159,255,150,150,255,138,138,255,126,126,249,113,113,165,100,100,82,86,82,0,0,0,0,255,0,0,255,0,0,255,0,22,255,22,69,255,69,108,255,108,137,255,137,156,255,156,166,255,166,169,255,169,166,255,166,157,255,157,139,255,139,111,255,111,72,255,72,26,255,26,0,255,0,0,255,0,0,255,0,0,255,0,0,0,0,86,86,169,169,169,169,169,253,169,169,251,169,169,168,168,169,85,85,169,1,1,169,0,0,169,0,0,0,0,0,0,0,169,0,0,169,0,0,169,53,53,169,137,137,169,169,220,169,169,255,169,169,197,169,169,113,113,169,30,30,0,0,0,0,255,0,0,255,0,0,255,0,30,255,30,83,255,83,126,255,126,155,255,155,168,255,168,166,255,166,148,255,148,115,255,115,70,255,70,15,255,15,0,0,0,0,0,0,0,0,117,23,23,117,107,107,117,117,190,117,117,255,117,117,211,117,117,127,117,117,44,44,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,32,32,32,74,74,74,109,109,109,136,136,136,155,155,155,166,166,166,169,169,169,165,165,165,153,153,153,133,133,133,105,105,105,70,70,70,27,27,27,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,86,86,117,117,169,117,117,253,117,117,231,117,117,148,117,117,65,65,117,0,0,117,0,0,0,0,0,0,0,0,51,255,51,100,255,100,139,255,139,162,255,162,169,255,169,161,255,161,137,255,137,99,255,99,50,255,50,0,255,0,0,255,0,0,255,0,0,255,0,0,0,0,0,169,0,0,169,0,0,169,0,0,169,0,0,169,0,0,169,0,0,169,0,17,169,17,101,169,101,184,169,169,255,169,169,255,169,169,255,169,169,255,169,169,255,169,169,255,169,169,255,169,169,255,169,169,255,169,169,255,169,169,255,169,169,255,169,169,255,169,169,193,169,169,109,109,169,26,26,169,0,0,0,0,86,0,0,169,0,0,253,0,0,251,0,0,168,0,0,85,0,0,1,0,0,0,169,0,0,169,0,0,169,0,0,169,0,0,169,0,0,169,53,53,169,137,137,169,169,220,169,169,255,169,169,197,169,169,113,113,169,30,30,0,0,0,187,56,56,166,138,138,141,141,221,110,110,255,71,71,255,25,25,255,0,0,255,0,0,0,21,0,0,46,0,0,70,31,31,95,115,95,118,198,118,136,255,136,151,255,151,159,103,159,161,20,161,155,0,155,138,0,138,109,0,109,68,0,68,18,0,18,0,0,0,0,0,0,0,0,0,0,0,0,90,96,90,171,129,129,253,149,149,255,164,164,255,169,169,255,166,166,255,155,155,255,136,136,255,107,107,0,70,70,0,24,24,0,0,0,0,0,0,65,0,0,139,0,0,212,0,0,255,0,0,255,0,0,255,0,0,255,0,0,255,0,0,255,0,0,255,0,0,0,0,0,169,86,86,169,169,169,169,169,253,169,169,251,168,169,168,85,169,85,1,169,1,0,169,0,0,169,0,0,169,0,0,0,0,0,0,68,0,0,27,0,0,0,0,0,0,0,0,0,0,71,0,0,143,0,0,215,0,0,228,0,0,156,0,0,0,0,169,0,0,169,0,0,169,0,0,169,0,0,169,0,0,169,0,0,169,0,0,169,0,0,169,0,0,169,0,0,169,0,0,169,0,0,169,0,0,169,0,0,169,0,0,169,0,0,169,59,59,169,143,143,169,169,226,169,169,255,169,169,255,169,169,255,169,169,255,169,169,255,169,169,255,169,169,255,169,169,255,169,169,255,169,169,255,169,169,255,169,169,255,169,169,255,169,169,255,169,169,255,169,169,172,89,169,89,5,169,5,0,0,0,0,169,0,0,169,0,0,169,0,0,169,0,0,169,0,0,169,0,0,169,0,0,169,0,0,169,0,0,169,0,0,169,0,0,169,0,0,169,0,0,169,0,0,169,0,52,169,52,135,169,135,219,169,169,255,169,169,255,169,169,255,169,169,255,169,169,255,169,169,255,169,169,255,169,169,255,169,169,255,169,169,255,169,169,255,169,169,255,169,169,241,169,169,158,158,169,75,75,169,0,0,0,133,0,0,133,0,0,133,0,0,133,0,0,133,0,0,133,0,0,133,0,0,133,0,0,133,0,0,133,0,0,133,0,0,133,0,0,133,70,70,133,133,152,133,133,234,133,133,235,133,133,152,70,133,70,0,133,0,0,133,0,0,133,0,0,133,0,0,133,0,0,133,0,63,133,63,146,133,133,228,133,133,253,133,133,170,133,133,88,88,133,6,6,133,0,30,30,0,80,80,255,119,119,255,146,146,194,162,162,112,171,112,30,178,30,0,0,0,0,169,0,0,169,0,0,169,0,32,169,32,113,169,113,194,169,169,255,169,169,225,169,169,143,143,169,62,62,169,0,0,169,0,0,169,0,0,169,0,0,169,0,0,169,0,0,169,0,0,0,169,0,0,169,0,0,169,0,0,169,0,0,169,0,0,169,55,55,169,136,136,169,217,169,169,255,169,169,213,169,169,132,132,169,52,52,0,0,0,0,255,0,31,255,31,83,255,83,124,255,124,152,255,152,167,255,167,168,255,168,158,186,158,138,103,103,117,19,19,96,0,0,0,0,149,0,0,149,53,53,149,137,137,149,149,220,149,149,255,149,149,197,149,149,113,113,149,30,30,0,0,0,86,169,86,169,169,169,253,169,169,247,169,169,164,164,169,81,81,169,0,0,169,0,0,169,0,0,169,0,0,169,0,0,169,0,0,0,169,0,0,169,0,0,169,0,0,169,0,0,169,44,44,169,120,120,169,169,197,169,169,255,169,169,248,169,169,171,94,169,94,16,169,16,0,0,0,72,72,169,148,148,169,169,223,169,169,254,169,169,177,169,169,99,99,169,23,23,169,0,0,0,0,0,12,12,169,95,95,169,169,179,169,169,255,169,169,202,169,169,119,119,169,35,35,169,0,0,0,0,0,5,5,169,82,82,169,159,159,169,169,236,169,169,241,169,169,165,165,169,90,90,169,14,14,0,0,0,24,37,24,62,119,62,88,200,88,107,255,107,125,255,125,140,255,140,153,255,153,162,255,162,168,255,168,169,255,169,167,255,167,160,255,160,147,255,147,129,255,129,104,255,104,71,255,71,31,255,31,0,255,0,0,255,0,0,255,0,0,255,0, diff --git a/common/gal/opengl/gl_resources.cpp b/common/gal/opengl/gl_resources.cpp new file mode 100644 index 0000000000..42a0646abe --- /dev/null +++ b/common/gal/opengl/gl_resources.cpp @@ -0,0 +1,41 @@ +// The current font is "Ubuntu Mono" available under Ubuntu Font Licence 1.0 +// (see ubuntu-font-licence-1.0.txt for details) +#include +#include "gl_resources.h" + +#define BITMAP_FONT_USE_SPANS + +namespace KIGFX { + namespace BUILTIN_FONT { + +#include "bitmap_font_img.c" +#include "bitmap_font_desc.c" + + const FONT_GLYPH_TYPE* LookupGlyph( unsigned int aCodepoint ) + { +#ifdef BITMAP_FONT_USE_SPANS + auto *end = font_codepoint_spans + + sizeof( font_codepoint_spans ) / sizeof(FONT_SPAN_TYPE); + auto ptr = std::upper_bound( font_codepoint_spans, end, aCodepoint, + []( unsigned int codepoint, const FONT_SPAN_TYPE& span ) + { + return codepoint < span.end; + } + ); + + if( ptr != end && ptr->start <= aCodepoint ) + { + unsigned int index = aCodepoint - ptr->start + ptr->cumulative; + return &font_codepoint_infos[ index ]; + } + else + { + return nullptr; + } +#else + return &bitmap_chars[codepoint]; +#endif + } + + } +} diff --git a/common/gal/opengl/gl_resources.h b/common/gal/opengl/gl_resources.h new file mode 100644 index 0000000000..1f219d3b5c --- /dev/null +++ b/common/gal/opengl/gl_resources.h @@ -0,0 +1,46 @@ +#ifndef GAL_OPENGL_RESOURCES_H___ +#define GAL_OPENGL_RESOURCES_H___ + +#define BITMAP_FONT_USE_SPANS + +namespace KIGFX { + + namespace BUILTIN_FONT { + + struct FONT_IMAGE_TYPE { + unsigned int width, height; + unsigned int char_border; + unsigned int spacing; + unsigned char pixels[1024 * 1024 * 3]; + }; + + struct FONT_INFO_TYPE { + unsigned int smooth_pixels; + float min_y; + float max_y; + }; + + struct FONT_SPAN_TYPE { + unsigned int start; + unsigned int end; + unsigned int cumulative; + }; + + struct FONT_GLYPH_TYPE { + unsigned int atlas_x, atlas_y; + unsigned int atlas_w, atlas_h; + float minx, maxx; + float miny, maxy; + float advance; + }; + + extern FONT_IMAGE_TYPE font_image; + extern FONT_INFO_TYPE font_information; + + const FONT_GLYPH_TYPE* LookupGlyph( unsigned int aCodePoint ); + + } + +} + +#endif diff --git a/common/gal/opengl/opengl_gal.cpp b/common/gal/opengl/opengl_gal.cpp index 5596a86ff5..ad2f3bb2b0 100644 --- a/common/gal/opengl/opengl_gal.cpp +++ b/common/gal/opengl/opengl_gal.cpp @@ -45,11 +45,11 @@ using namespace std::placeholders; using namespace KIGFX; + // The current font is "Ubuntu Mono" available under Ubuntu Font Licence 1.0 // (see ubuntu-font-licence-1.0.txt for details) -#define BITMAP_FONT_USE_SPANS -#include "bitmap_font_img.c" -#include "bitmap_font_desc.c" +#include "gl_resources.h" +using namespace KIGFX::BUILTIN_FONT; static void InitTesselatorCallbacks( GLUtesselator* aTesselator ); static const int glAttributes[] = { WX_GL_RGBA, WX_GL_DOUBLEBUFFER, WX_GL_DEPTH_SIZE, 8, 0 }; @@ -808,7 +808,7 @@ void OPENGL_GAL::BitmapText( const wxString& aText, const VECTOR2D& aPosition, { const unsigned int c = aText[ii]; - wxASSERT_MSG( lookupGlyph(c) != nullptr, wxT( "Missing character in bitmap font atlas." ) ); + wxASSERT_MSG( LookupGlyph(c) != nullptr, wxT( "Missing character in bitmap font atlas." ) ); wxASSERT_MSG( c != '\n' && c != '\r', wxT( "No support for multiline bitmap text yet" ) ); // Handle overbar @@ -1317,7 +1317,7 @@ int OPENGL_GAL::drawBitmapChar( unsigned long aChar ) const float TEX_X = font_image.width; const float TEX_Y = font_image.height; - const bitmap_glyph* glyph = lookupGlyph(aChar); + const FONT_GLYPH_TYPE* glyph = LookupGlyph(aChar); if( !glyph ) return 0; const float X = glyph->atlas_x + font_information.smooth_pixels; @@ -1371,7 +1371,7 @@ int OPENGL_GAL::drawBitmapChar( unsigned long aChar ) void OPENGL_GAL::drawBitmapOverbar( double aLength, double aHeight ) { // To draw an overbar, simply draw an overbar - const bitmap_glyph* glyph = lookupGlyph( '_' ); + const FONT_GLYPH_TYPE* glyph = LookupGlyph( '_' ); const float H = glyph->maxy - glyph->miny; Save(); @@ -1394,31 +1394,6 @@ void OPENGL_GAL::drawBitmapOverbar( double aLength, double aHeight ) Restore(); } -const bitmap_glyph* OPENGL_GAL::lookupGlyph( unsigned int aCodepoint ) const -{ -#ifdef BITMAP_FONT_USE_SPANS - auto *end = font_codepoint_spans + sizeof( font_codepoint_spans ) / sizeof( bitmap_span ); - auto ptr = std::upper_bound( font_codepoint_spans, end, aCodepoint, - []( unsigned int codepoint, const bitmap_span& span ) - { - return codepoint < span.end; - } - ); - - if( ptr != end && ptr->start <= aCodepoint ) - { - unsigned int index = aCodepoint - ptr->start + ptr->cumulative; - return &font_codepoint_infos[index]; - } - else - { - return nullptr; - } -#else - return &bitmap_chars[codepoint]; -#endif -} - std::pair OPENGL_GAL::computeBitmapTextSize( const wxString& aText ) const { VECTOR2D textSize( 0, 0 ); @@ -1444,7 +1419,7 @@ std::pair OPENGL_GAL::computeBitmapTextSize( const wxString& aT } } - const bitmap_glyph* glyph = lookupGlyph(aText[i]); + const FONT_GLYPH_TYPE* glyph = LookupGlyph(aText[i]); if( glyph ) { textSize.x += glyph->advance; textSize.y = std::max( textSize.y, font_information.max_y - glyph->miny ); diff --git a/include/gal/opengl/opengl_gal.h b/include/gal/opengl/opengl_gal.h index 571f0a05e0..35dfbd4007 100644 --- a/include/gal/opengl/opengl_gal.h +++ b/include/gal/opengl/opengl_gal.h @@ -380,8 +380,6 @@ private: */ std::pair computeBitmapTextSize( const wxString& aText ) const; - const bitmap_glyph* lookupGlyph( unsigned int aCodepoint ) const; - // Event handling /** * @brief This is the OnPaint event handler.