Skip to content

Commit

Permalink
Adds an additional layer of uniform caching
Browse files Browse the repository at this point in the history
  • Loading branch information
JujuAdams committed Sep 4, 2022
1 parent 1bfb495 commit afe04b5
Show file tree
Hide file tree
Showing 3 changed files with 80 additions and 43 deletions.
114 changes: 73 additions & 41 deletions scripts/__scribble_class_element/__scribble_class_element.gml
Original file line number Diff line number Diff line change
Expand Up @@ -1392,32 +1392,49 @@ function __scribble_class_element(_string, _unique_id) constructor
shader_set_uniform_f(global.__scribble_u_fTime, __animation_time);

//TODO - Optimise
shader_set_uniform_f(global.__scribble_u_vColourBlend, colour_get_red( __blend_colour)/255,
colour_get_green(__blend_colour)/255,
colour_get_blue( __blend_colour)/255,
var _blend_colour = __blend_colour;
shader_set_uniform_f(global.__scribble_u_vColourBlend, colour_get_red( _blend_colour)/255,
colour_get_green(_blend_colour)/255,
colour_get_blue( _blend_colour)/255,
__blend_alpha);

shader_set_uniform_f(global.__scribble_u_vGradient, colour_get_red( __gradient_colour)/255,
colour_get_green(__gradient_colour)/255,
colour_get_blue( __gradient_colour)/255,
__gradient_alpha);

shader_set_uniform_f(global.__scribble_u_vSkew, __skew_x, __skew_y);

shader_set_uniform_f(global.__scribble_u_vFlash, colour_get_red( __flash_colour)/255,
colour_get_green(__flash_colour)/255,
colour_get_blue( __flash_colour)/255,
__flash_alpha);

shader_set_uniform_f(global.__scribble_u_vRegionActive, __region_glyph_start, __region_glyph_end);

shader_set_uniform_f(global.__scribble_u_vRegionColour, colour_get_red( __region_colour)/255,
colour_get_green(__region_colour)/255,
colour_get_blue( __region_colour)/255,
__region_blend);

shader_set_uniform_f(global.__scribble_u_fBlinkState, __animation_blink_state);

if ((__gradient_alpha != 0) || (__skew_x != 0) || (__skew_y != 0) || (__flash_alpha != 0) || (__region_blend != 0))
{
global.__scribble_standard_shader_uniforms_dirty = true;

shader_set_uniform_f(global.__scribble_u_vGradient, colour_get_red( __gradient_colour)/255,
colour_get_green(__gradient_colour)/255,
colour_get_blue( __gradient_colour)/255,
__gradient_alpha);

shader_set_uniform_f(global.__scribble_u_vSkew, __skew_x, __skew_y);

shader_set_uniform_f(global.__scribble_u_vFlash, colour_get_red( __flash_colour)/255,
colour_get_green(__flash_colour)/255,
colour_get_blue( __flash_colour)/255,
__flash_alpha);

shader_set_uniform_f(global.__scribble_u_vRegionActive, __region_glyph_start, __region_glyph_end);

shader_set_uniform_f(global.__scribble_u_vRegionColour, colour_get_red( __region_colour)/255,
colour_get_green(__region_colour)/255,
colour_get_blue( __region_colour)/255,
__region_blend);

}
else if (global.__scribble_standard_shader_uniforms_dirty)
{
global.__scribble_standard_shader_uniforms_dirty = false;

shader_set_uniform_f(global.__scribble_u_vGradient, 0, 0, 0, 0);
shader_set_uniform_f(global.__scribble_u_vSkew, 0, 0);
shader_set_uniform_f(global.__scribble_u_vFlash, 0, 0, 0, 0);
shader_set_uniform_f(global.__scribble_u_vRegionActive, 0, 0);
shader_set_uniform_f(global.__scribble_u_vRegionColour, 0, 0, 0, 0);
}

//Update the animation properties for this shader if they've changed since the last time we drew an element
if (global.__scribble_anim_shader_desync)
{
Expand Down Expand Up @@ -1480,27 +1497,42 @@ function __scribble_class_element(_string, _unique_id) constructor
colour_get_blue( __blend_colour)/255,
__blend_alpha);

shader_set_uniform_f(global.__scribble_msdf_u_vGradient, colour_get_red( __gradient_colour)/255,
colour_get_green(__gradient_colour)/255,
colour_get_blue( __gradient_colour)/255,
__gradient_alpha);

shader_set_uniform_f(global.__scribble_msdf_u_vSkew, __skew_x, __skew_y);

shader_set_uniform_f(global.__scribble_msdf_u_vFlash, colour_get_red( __flash_colour)/255,
colour_get_green(__flash_colour)/255,
colour_get_blue( __flash_colour)/255,
__flash_alpha);

shader_set_uniform_f(global.__scribble_msdf_u_vRegionActive, __region_glyph_start, __region_glyph_end);

shader_set_uniform_f(global.__scribble_msdf_u_vRegionColour, colour_get_red( __region_colour)/255,
colour_get_green(__region_colour)/255,
colour_get_blue( __region_colour)/255,
__region_blend);

shader_set_uniform_f(global.__scribble_msdf_u_fBlinkState, __animation_blink_state);

if ((__gradient_alpha != 0) || (__skew_x != 0) || (__skew_y != 0) || (__flash_alpha != 0) || (__region_blend != 0))
{
global.__scribble_msdf_shader_uniforms_dirty = true;

shader_set_uniform_f(global.__scribble_msdf_u_vGradient, colour_get_red( __gradient_colour)/255,
colour_get_green(__gradient_colour)/255,
colour_get_blue( __gradient_colour)/255,
__gradient_alpha);

shader_set_uniform_f(global.__scribble_msdf_u_vSkew, __skew_x, __skew_y);

shader_set_uniform_f(global.__scribble_msdf_u_vFlash, colour_get_red( __flash_colour)/255,
colour_get_green(__flash_colour)/255,
colour_get_blue( __flash_colour)/255,
__flash_alpha);

shader_set_uniform_f(global.__scribble_msdf_u_vRegionActive, __region_glyph_start, __region_glyph_end);

shader_set_uniform_f(global.__scribble_msdf_u_vRegionColour, colour_get_red( __region_colour)/255,
colour_get_green(__region_colour)/255,
colour_get_blue( __region_colour)/255,
__region_blend);
}
else if (global.__scribble_msdf_shader_uniforms_dirty)
{
global.__scribble_msdf_shader_uniforms_dirty = false;

shader_set_uniform_f(global.__scribble_msdf_u_vGradient, 0, 0, 0, 0);
shader_set_uniform_f(global.__scribble_msdf_u_vSkew, 0, 0);
shader_set_uniform_f(global.__scribble_msdf_u_vFlash, 0, 0, 0, 0);
shader_set_uniform_f(global.__scribble_msdf_u_vRegionActive, 0, 0);
shader_set_uniform_f(global.__scribble_msdf_u_vRegionColour, 0, 0, 0, 0);
}

//Update the animation properties for this shader if they've changed since the last time we drew an element
if (global.__scribble_anim_shader_msdf_desync)
{
Expand Down
6 changes: 4 additions & 2 deletions scripts/__scribble_gc_collect/__scribble_gc_collect.gml
Original file line number Diff line number Diff line change
Expand Up @@ -8,8 +8,10 @@ function __scribble_gc_collect()
{
global.__scribble_os_is_paused = os_is_paused();

global.__scribble_anim_shader_desync = true;
global.__scribble_anim_shader_msdf_desync = true;
global.__scribble_anim_shader_desync = true;
global.__scribble_anim_shader_msdf_desync = true;
global.__scribble_standard_shader_uniforms_dirty = true;
global.__scribble_msdf_shader_uniforms_dirty = true;
}


Expand Down
3 changes: 3 additions & 0 deletions scripts/__scribble_system/__scribble_system.gml
Original file line number Diff line number Diff line change
Expand Up @@ -286,6 +286,9 @@ global.__scribble_anim_shader_msdf_desync = false;
global.__scribble_anim_shader_msdf_desync_to_default = false;
global.__scribble_anim_shader_msdf_default = false;

global.__scribble_standard_shader_uniforms_dirty = true;
global.__scribble_msdf_shader_uniforms_dirty = true;

global.__scribble_anim_properties = array_create(__SCRIBBLE_ANIM.__SIZE);
scribble_anim_reset();

Expand Down

0 comments on commit afe04b5

Please sign in to comment.