From 69d7cd73debd846e1c38fe156320c885763f249d Mon Sep 17 00:00:00 2001 From: MakhamDev Date: Sun, 1 Oct 2023 16:56:10 +0700 Subject: [PATCH] - [Font load] Remove duplicate font_add calls. --- PixelComposer.resource_order | 1 + PixelComposer.yyp | 1 + objects/o_dialog_preference/Draw_64.gml | 2 +- scripts/font_loader/font_loader.gml | 33 +++++++++++++++++-- .../font_sprite_loader/font_sprite_loader.gml | 2 +- scripts/node_text/node_text.gml | 2 +- .../surface_functions/surface_functions.gml | 15 +++------ shaders/sh_draw_texture/sh_draw_texture.fsh | 9 +++++ shaders/sh_draw_texture/sh_draw_texture.vsh | 19 +++++++++++ shaders/sh_draw_texture/sh_draw_texture.yy | 10 ++++++ 10 files changed, 77 insertions(+), 17 deletions(-) create mode 100644 shaders/sh_draw_texture/sh_draw_texture.fsh create mode 100644 shaders/sh_draw_texture/sh_draw_texture.vsh create mode 100644 shaders/sh_draw_texture/sh_draw_texture.yy diff --git a/PixelComposer.resource_order b/PixelComposer.resource_order index a5621d583..5fbee45c1 100644 --- a/PixelComposer.resource_order +++ b/PixelComposer.resource_order @@ -535,6 +535,7 @@ {"name":"sh_draw_surface_part_tiled","order":1,"path":"shaders/sh_draw_surface_part_tiled/sh_draw_surface_part_tiled.yy",}, {"name":"o_dialog_add_node","order":1,"path":"objects/o_dialog_add_node/o_dialog_add_node.yy",}, {"name":"s_node_path_reverse","order":8,"path":"sprites/s_node_path_reverse/s_node_path_reverse.yy",}, + {"name":"sh_draw_texture","order":6,"path":"shaders/sh_draw_texture/sh_draw_texture.yy",}, {"name":"fd_rectangle_get_pressure_width","order":18,"path":"scripts/fd_rectangle_get_pressure_width/fd_rectangle_get_pressure_width.yy",}, {"name":"sh_blend_normal","order":1,"path":"shaders/sh_blend_normal/sh_blend_normal.yy",}, {"name":"node_feedback_output","order":2,"path":"scripts/node_feedback_output/node_feedback_output.yy",}, diff --git a/PixelComposer.yyp b/PixelComposer.yyp index f09e2a2d5..008e7f84c 100644 --- a/PixelComposer.yyp +++ b/PixelComposer.yyp @@ -1116,6 +1116,7 @@ {"id":{"name":"o_dialog_add_node","path":"objects/o_dialog_add_node/o_dialog_add_node.yy",},}, {"id":{"name":"s_node_curve_eval","path":"sprites/s_node_curve_eval/s_node_curve_eval.yy",},}, {"id":{"name":"s_node_path_reverse","path":"sprites/s_node_path_reverse/s_node_path_reverse.yy",},}, + {"id":{"name":"sh_draw_texture","path":"shaders/sh_draw_texture/sh_draw_texture.yy",},}, {"id":{"name":"fd_rectangle_get_pressure_width","path":"scripts/fd_rectangle_get_pressure_width/fd_rectangle_get_pressure_width.yy",},}, {"id":{"name":"s_node_strandSim_render","path":"sprites/s_node_strandSim_render/s_node_strandSim_render.yy",},}, {"id":{"name":"sh_blend_normal","path":"shaders/sh_blend_normal/sh_blend_normal.yy",},}, diff --git a/objects/o_dialog_preference/Draw_64.gml b/objects/o_dialog_preference/Draw_64.gml index 049aad415..52448e1c3 100644 --- a/objects/o_dialog_preference/Draw_64.gml +++ b/objects/o_dialog_preference/Draw_64.gml @@ -49,7 +49,7 @@ if !ready exit; tb_search.font = f_p1; tb_search.active = sFOCUS; tb_search.hover = sHOVER; - tb_search.draw(dialog_x + dialog_w - ui(padding - 8), dialog_y + ui(title_height) / 2, ui(200), ui(28), search_text, mouse_ui,, fa_right, fa_center); + tb_search.draw(dialog_x + dialog_w - ui(padding - 8), dialog_y + ui(title_height) / 2, ui(200), ui(28), search_text, mouse_ui, fa_right, fa_center); draw_sprite_ui_uniform(THEME.search, 0, dialog_x + dialog_w - ui(padding + 208), dialog_y + ui(title_height) / 2, 1, COLORS._main_text_sub); if(page_current == 0) { diff --git a/scripts/font_loader/font_loader.gml b/scripts/font_loader/font_loader.gml index 627cbb704..7e166ef9c 100644 --- a/scripts/font_loader/font_loader.gml +++ b/scripts/font_loader/font_loader.gml @@ -1,7 +1,35 @@ -globalvar FONT_ISLOADED, f_h1, f_h3, f_h5, f_p0, f_p0b, f_p1, f_p2, f_p3, f_code; +globalvar FONT_ISLOADED, FONT_CACHE; +globalvar f_h1, f_h3, f_h5, f_p0, f_p0b, f_p1, f_p2, f_p3, f_code; +FONT_CACHE = {}; FONT_ISLOADED = false; +function _font_add(path, size) { + var font_cache_dir = DIRECTORY + "font_cache"; + directory_verify(font_cache_dir); + + var _key = $"{filename_name_only(path)}_{size}"; + if(struct_has(FONT_CACHE, _key) && font_exists(FONT_CACHE[$ _key])) { + //print($"Add font {_key}: restore from cache"); + return FONT_CACHE[$ _key]; + } + + var _t = current_time; + var _f = font_add(path, size, false, false, 0, 0); + //font_enable_sdf(_f, true); + //font_sdf_spread(_f, 8); + //font_enable_effects(_f, true, { + // outlineEnable: true, + // outlineDistance: 0.1, + // outlineColour: c_white + //}); + + FONT_CACHE[$ _key] = _f; + //print($"Add font {_key}: {current_time - _t} ms"); + + return _f; +} + function _font_path(rel) { rel = string_replace_all(rel, "./", ""); @@ -26,8 +54,7 @@ function _font_load_from_struct(str, def) { } font_add_enable_aa(THEME_VALUE.font_aa); - var _font = font_add(path, str.size * UI_SCALE, false, false, 0, 0); - //font_enable_sdf(_font, true); + var _font = _font_add(path, str.size * UI_SCALE); return _font; } diff --git a/scripts/font_sprite_loader/font_sprite_loader.gml b/scripts/font_sprite_loader/font_sprite_loader.gml index 294f64d65..ca4b2aacd 100644 --- a/scripts/font_sprite_loader/font_sprite_loader.gml +++ b/scripts/font_sprite_loader/font_sprite_loader.gml @@ -5,7 +5,7 @@ FONT_SPRITES = ds_map_create(); function loadFontSprite(path) { if(ds_map_exists(FONT_SPRITES, path)) return; - var f = font_add(path, 32, false, false, 32, 255); + var f = _font_add(path, 32); draw_set_text(f, fa_left, fa_top, c_white); var name = "ABCabc123"; var ww = string_width(name); diff --git a/scripts/node_text/node_text.gml b/scripts/node_text/node_text.gml index d6d13ba9e..eb81af209 100644 --- a/scripts/node_text/node_text.gml +++ b/scripts/node_text/node_text.gml @@ -61,7 +61,7 @@ function Node_Text(_x, _y, _group = noone) : Node_Processor(_x, _y, _group) cons font_delete(font); font_add_enable_aa(_aa); - font = font_add(_path, _size, false, false, 0, 0); + font = _font_add(_path, _size); } static processData = function(_outSurf, _data, _output_index, _array_index) { diff --git a/scripts/surface_functions/surface_functions.gml b/scripts/surface_functions/surface_functions.gml index e124c227a..4f2ee7dc6 100644 --- a/scripts/surface_functions/surface_functions.gml +++ b/scripts/surface_functions/surface_functions.gml @@ -116,17 +116,10 @@ function surface_save_safe(surface, path) { surface_reset_shader(); surface_save(s, path); return; - case surface_r8unorm : - s = surface_create(w, h, surface_rgba8unorm); - break; - case surface_r16float : - s = surface_create(w, h, surface_rgba16float); - break; - case surface_r32float : - s = surface_create(w, h, surface_rgba32float); - break; - default: - return; + case surface_r8unorm : s = surface_create(w, h, surface_rgba8unorm); break; + case surface_r16float : s = surface_create(w, h, surface_rgba16float); break; + case surface_r32float : s = surface_create(w, h, surface_rgba32float); break; + default: return; } surface_set_shader(s, sh_draw_single_channel); diff --git a/shaders/sh_draw_texture/sh_draw_texture.fsh b/shaders/sh_draw_texture/sh_draw_texture.fsh new file mode 100644 index 000000000..bbadf2e27 --- /dev/null +++ b/shaders/sh_draw_texture/sh_draw_texture.fsh @@ -0,0 +1,9 @@ +varying vec2 v_vTexcoord; +varying vec4 v_vColour; + +uniform sampler2D texture; + +void main() { + gl_FragColor = texture2D( texture, v_vTexcoord ); + //gl_FragColor = vec4(1.); +} diff --git a/shaders/sh_draw_texture/sh_draw_texture.vsh b/shaders/sh_draw_texture/sh_draw_texture.vsh new file mode 100644 index 000000000..3900c20f4 --- /dev/null +++ b/shaders/sh_draw_texture/sh_draw_texture.vsh @@ -0,0 +1,19 @@ +// +// Simple passthrough vertex shader +// +attribute vec3 in_Position; // (x,y,z) +//attribute vec3 in_Normal; // (x,y,z) unused in this shader. +attribute vec4 in_Colour; // (r,g,b,a) +attribute vec2 in_TextureCoord; // (u,v) + +varying vec2 v_vTexcoord; +varying vec4 v_vColour; + +void main() +{ + vec4 object_space_pos = vec4( in_Position.x, in_Position.y, in_Position.z, 1.0); + gl_Position = gm_Matrices[MATRIX_WORLD_VIEW_PROJECTION] * object_space_pos; + + v_vColour = in_Colour; + v_vTexcoord = in_TextureCoord; +} diff --git a/shaders/sh_draw_texture/sh_draw_texture.yy b/shaders/sh_draw_texture/sh_draw_texture.yy new file mode 100644 index 000000000..cc0b85398 --- /dev/null +++ b/shaders/sh_draw_texture/sh_draw_texture.yy @@ -0,0 +1,10 @@ +{ + "resourceType": "GMShader", + "resourceVersion": "1.0", + "name": "sh_draw_texture", + "parent": { + "name": "misc", + "path": "folders/shader/misc.yy", + }, + "type": 1, +} \ No newline at end of file