diff --git a/armorlab/sources/nodes/inpaint_node.ts b/armorlab/sources/nodes/inpaint_node.ts index d0dee037..09cbeb15 100644 --- a/armorlab/sources/nodes/inpaint_node.ts +++ b/armorlab/sources/nodes/inpaint_node.ts @@ -72,9 +72,9 @@ function inpaint_node_get_as_image(self: inpaint_node_t, from: i32): iron_g5_tex let source: iron_g5_texture_t = logic_node_input_get_as_image(self.base.inputs[0]); console_progress(tr("Processing") + " - " + tr("Inpaint")); - g2_begin(inpaint_node_image); + draw_begin(inpaint_node_image); draw_scaled_image(source, 0, 0, config_get_texture_res_x(), config_get_texture_res_y()); - g2_end(); + draw_end(); if (inpaint_node_auto) { return inpaint_node_texsynth_inpaint(inpaint_node_image, false, inpaint_node_mask); @@ -144,10 +144,10 @@ function inpaint_node_sd_inpaint(image: iron_g5_texture_t, mask: iron_g5_texture } } - g2_begin(inpaint_node_temp); + draw_begin(inpaint_node_temp); // g2_drawImage(image, -x * 512, -y * 512); draw_scaled_image(image, 0, 0, 512, 512); - g2_end(); + draw_end(); bytes_img = iron_g4_get_texture_pixels(inpaint_node_temp); let u8a: buffer_t = bytes_img; diff --git a/armorlab/sources/nodes/photo_to_pbr_node.ts b/armorlab/sources/nodes/photo_to_pbr_node.ts index 09781a09..53bf216a 100644 --- a/armorlab/sources/nodes/photo_to_pbr_node.ts +++ b/armorlab/sources/nodes/photo_to_pbr_node.ts @@ -57,7 +57,7 @@ function photo_to_pbr_node_get_as_image(self: photo_to_pbr_node_t, from: i32): i let x: i32 = i % tiles_x; let y: i32 = math_floor(i / tiles_x); - g2_begin(photo_to_pbr_node_temp); + draw_begin(photo_to_pbr_node_temp); draw_scaled_image(source, photo_to_pbr_node_border_w - x * photo_to_pbr_node_tile_w, photo_to_pbr_node_border_w - y * photo_to_pbr_node_tile_w, -config_get_texture_res_x(), config_get_texture_res_y()); draw_scaled_image(source, photo_to_pbr_node_border_w - x * photo_to_pbr_node_tile_w, photo_to_pbr_node_border_w - y * photo_to_pbr_node_tile_w, config_get_texture_res_x(), -config_get_texture_res_y()); draw_scaled_image(source, photo_to_pbr_node_border_w - x * photo_to_pbr_node_tile_w, photo_to_pbr_node_border_w - y * photo_to_pbr_node_tile_w, -config_get_texture_res_x(), -config_get_texture_res_y()); @@ -65,7 +65,7 @@ function photo_to_pbr_node_get_as_image(self: photo_to_pbr_node_t, from: i32): i draw_scaled_image(source, photo_to_pbr_node_border_w - x * photo_to_pbr_node_tile_w + photo_to_pbr_node_tile_w, photo_to_pbr_node_border_w - y * photo_to_pbr_node_tile_w + photo_to_pbr_node_tile_w, -config_get_texture_res_x(), config_get_texture_res_y()); draw_scaled_image(source, photo_to_pbr_node_border_w - x * photo_to_pbr_node_tile_w + photo_to_pbr_node_tile_w, photo_to_pbr_node_border_w - y * photo_to_pbr_node_tile_w + photo_to_pbr_node_tile_w, config_get_texture_res_x(), -config_get_texture_res_y()); draw_scaled_image(source, photo_to_pbr_node_border_w - x * photo_to_pbr_node_tile_w, photo_to_pbr_node_border_w - y * photo_to_pbr_node_tile_w, config_get_texture_res_x(), config_get_texture_res_y()); - g2_end(); + draw_end(); let bytes_img: buffer_t = iron_g4_get_texture_pixels(photo_to_pbr_node_temp); let u8a: buffer_t = bytes_img; @@ -154,9 +154,9 @@ function photo_to_pbr_node_get_as_image(self: photo_to_pbr_node_t, from: i32): i ///end let temp2: iron_g5_texture_t = iron_g4_create_texture_from_bytes(u8a, photo_to_pbr_node_tile_w, photo_to_pbr_node_tile_w); - g2_begin(photo_to_pbr_node_images[from]); + draw_begin(photo_to_pbr_node_images[from]); draw_image(temp2, x * photo_to_pbr_node_tile_w, y * photo_to_pbr_node_tile_w); - g2_end(); + draw_end(); app_notify_on_next_frame(function(temp2: iron_g5_texture_t) { iron_unload_image(temp2); }, temp2); diff --git a/armorlab/sources/nodes/tiling_node.ts b/armorlab/sources/nodes/tiling_node.ts index 36c6790b..5c6be13b 100644 --- a/armorlab/sources/nodes/tiling_node.ts +++ b/armorlab/sources/nodes/tiling_node.ts @@ -45,9 +45,9 @@ function tiling_node_button(node_id: i32) { function tiling_node_get_as_image(self: tiling_node_t, from: i32): iron_g5_texture_t { let source: iron_g5_texture_t = logic_node_input_get_as_image(self.base.inputs[0]); - g2_begin(tiling_node_image); + draw_begin(tiling_node_image); draw_scaled_image(source, 0, 0, config_get_texture_res_x(), config_get_texture_res_y()); - g2_end(); + draw_end(); console_progress(tr("Processing") + " - " + tr("Tiling")); @@ -67,12 +67,12 @@ function tiling_node_get_cached_image(self: tiling_node_t): iron_g5_texture_t { function tiling_node_sd_tiling(image: iron_g5_texture_t, seed: i32): iron_g5_texture_t { text_to_photo_node_tiling = false; let tile: iron_g5_texture_t = iron_g4_create_render_target(512, 512); - g2_begin(tile); + draw_begin(tile); draw_scaled_image(image, -256, -256, 512, 512); draw_scaled_image(image, 256, -256, 512, 512); draw_scaled_image(image, -256, 256, 512, 512); draw_scaled_image(image, 256, 256, 512, 512); - g2_end(); + draw_end(); let u8a: u8_array_t = u8_array_create(512 * 512); for (let i: i32 = 0; i < 512 * 512; ++i) { diff --git a/armorlab/sources/nodes/upscale_node.ts b/armorlab/sources/nodes/upscale_node.ts index 6a9585a4..80a1ed82 100644 --- a/armorlab/sources/nodes/upscale_node.ts +++ b/armorlab/sources/nodes/upscale_node.ts @@ -50,9 +50,9 @@ function upscale_node_do_tile(source: iron_g5_texture_t): iron_g5_texture_t { iron_unload_image(upscale_node_temp); } upscale_node_temp = iron_g4_create_render_target(size1w, size1h); - g2_begin(upscale_node_temp); + draw_begin(upscale_node_temp); draw_scaled_image(source, 0, 0, size1w, size1h); - g2_end(); + draw_end(); let bytes_img: buffer_t = iron_g4_get_texture_pixels(upscale_node_temp); let u8a: u8_array_t = bytes_img; @@ -105,7 +105,7 @@ function upscale_node_esrgan(source: iron_g5_texture_t): iron_g5_texture_t { let tile_source: iron_g5_texture_t = iron_g4_create_render_target(tile_size + 32 * 2, tile_size + 32 * 2); for (let x: i32 = 0; x < math_floor(size1w / tile_size); ++x) { for (let y: i32 = 0; y < math_floor(size1h / tile_size); ++y) { - g2_begin(tile_source); + draw_begin(tile_source); draw_scaled_image(source, 32 - x * tile_size, 32 - y * tile_size, -source.width, source.height); draw_scaled_image(source, 32 - x * tile_size, 32 - y * tile_size, source.width, -source.height); draw_scaled_image(source, 32 - x * tile_size, 32 - y * tile_size, -source.width, -source.height); @@ -113,11 +113,11 @@ function upscale_node_esrgan(source: iron_g5_texture_t): iron_g5_texture_t { draw_scaled_image(source, 32 - x * tile_size + tile_size, 32 - y * tile_size + tile_size, -source.width, source.height); draw_scaled_image(source, 32 - x * tile_size + tile_size, 32 - y * tile_size + tile_size, source.width, -source.height); draw_scaled_image(source, 32 - x * tile_size, 32 - y * tile_size, source.width, source.height); - g2_end(); + draw_end(); let tile_result: iron_g5_texture_t = upscale_node_do_tile(tile_source); - g2_begin(result); + draw_begin(result); draw_sub_image(tile_result, x * tile_size2x, y * tile_size2x, 64, 64, tile_size2x, tile_size2x); - g2_end(); + draw_end(); iron_unload_image(tile_result); } } diff --git a/armorlab/sources/nodes/variance_node.ts b/armorlab/sources/nodes/variance_node.ts index fcad4931..d165f4bd 100644 --- a/armorlab/sources/nodes/variance_node.ts +++ b/armorlab/sources/nodes/variance_node.ts @@ -38,9 +38,9 @@ function variance_node_get_as_image(self: variance_node_t, from: i32): iron_g5_t let strength: f32 = node.value; let source: iron_g5_texture_t = logic_node_input_get_as_image(variance_node_inst.base.inputs[0]); - g2_begin(variance_node_temp); + draw_begin(variance_node_temp); draw_scaled_image(source, 0, 0, 512, 512); - g2_end(); + draw_end(); let bytes_img: buffer_t = iron_g4_get_texture_pixels(variance_node_temp); let u8a: u8_array_t = bytes_img; diff --git a/armorlab/sources/ui_nodes_ext.ts b/armorlab/sources/ui_nodes_ext.ts index 30f1e8ae..9268d1d2 100644 --- a/armorlab/sources/ui_nodes_ext.ts +++ b/armorlab/sources/ui_nodes_ext.ts @@ -47,34 +47,34 @@ function ui_nodes_ext_run() { if (texbase != null) { let texpaint: render_target_t = map_get(render_path_render_targets, "texpaint"); - g2_begin(texpaint._image); + draw_begin(texpaint._image); draw_scaled_image(texbase, 0, 0, config_get_texture_res_x(), config_get_texture_res_y()); - g2_end(); + draw_end(); } if (texnor != null) { let texpaint_nor: render_target_t = map_get(render_path_render_targets, "texpaint_nor"); - g2_begin(texpaint_nor._image); + draw_begin(texpaint_nor._image); draw_scaled_image(texnor, 0, 0, config_get_texture_res_x(), config_get_texture_res_y()); - g2_end(); + draw_end(); } let texpaint_pack: render_target_t = map_get(render_path_render_targets, "texpaint_pack"); if (texocc != null) { - g2_begin(texpaint_pack._image); + draw_begin(texpaint_pack._image); draw_set_pipeline(pipes_copy_r); draw_scaled_image(texocc, 0, 0, config_get_texture_res_x(), config_get_texture_res_y()); draw_set_pipeline(null); - g2_end(); + draw_end(); } if (texrough != null) { - g2_begin(texpaint_pack._image); + draw_begin(texpaint_pack._image); draw_set_pipeline(pipes_copy_g); draw_scaled_image(texrough, 0, 0, config_get_texture_res_x(), config_get_texture_res_y()); draw_set_pipeline(null); - g2_end(); + draw_end(); } if (texheight != null) { diff --git a/armorpaint/sources/layers_ext.ts b/armorpaint/sources/layers_ext.ts index c4dfb08c..c4cc792e 100644 --- a/armorpaint/sources/layers_ext.ts +++ b/armorpaint/sources/layers_ext.ts @@ -35,9 +35,9 @@ function layers_ext_flatten(height_to_normal: bool = false, layers: slot_layer_t if (l1masks != null) { if (l1masks.length > 1) { layers_make_temp_mask_img(); - g2_begin(pipes_temp_mask_image); + draw_begin(pipes_temp_mask_image); iron_g5_clear(0x00000000); - g2_end(); + draw_end(); let l1: slot_layer_t = { texpaint: pipes_temp_mask_image }; for (let i: i32 = 0; i < l1masks.length; ++i) { layers_merge_layer(l1, l1masks[i]); @@ -50,19 +50,19 @@ function layers_ext_flatten(height_to_normal: bool = false, layers: slot_layer_t } if (l1.paint_base) { - g2_begin(layers_temp_image); // Copy to temp + draw_begin(layers_temp_image); // Copy to temp draw_set_pipeline(pipes_copy); draw_image(layers_expa, 0, 0); draw_set_pipeline(null); - g2_end(); + draw_end(); ///if is_forge // Do not multiply basecol by alpha - g2_begin(layers_expa); // Copy to temp + draw_begin(layers_expa); // Copy to temp draw_set_pipeline(pipes_copy); draw_image(l1.texpaint, 0, 0); draw_set_pipeline(null); - g2_end(); + draw_end(); ///else _iron_g4_begin(layers_expa); iron_g5_set_pipeline(pipes_merge); @@ -80,11 +80,11 @@ function layers_ext_flatten(height_to_normal: bool = false, layers: slot_layer_t } if (l1.paint_nor) { - g2_begin(layers_temp_image); + draw_begin(layers_temp_image); draw_set_pipeline(pipes_copy); draw_image(layers_expb, 0, 0); draw_set_pipeline(null); - g2_end(); + draw_end(); _iron_g4_begin(layers_expb); iron_g5_set_pipeline(pipes_merge); @@ -101,11 +101,11 @@ function layers_ext_flatten(height_to_normal: bool = false, layers: slot_layer_t } if (l1.paint_occ || l1.paint_rough || l1.paint_met || l1.paint_height) { - g2_begin(layers_temp_image); + draw_begin(layers_temp_image); draw_set_pipeline(pipes_copy); draw_image(layers_expc, 0, 0); draw_set_pipeline(null); - g2_end(); + draw_end(); if (l1.paint_occ && l1.paint_rough && l1.paint_met && l1.paint_height) { layers_commands_merge_pack(pipes_merge, layers_expc, l1.texpaint, l1.texpaint_pack, slot_layer_get_opacity(l1), mask, l1.paint_height_blend ? -3 : -1); @@ -126,12 +126,12 @@ function layers_ext_flatten(height_to_normal: bool = false, layers: slot_layer_t ///if arm_metal // Flush command list - g2_begin(layers_expa); - g2_end(); - g2_begin(layers_expb); - g2_end(); - g2_begin(layers_expc); - g2_end(); + draw_begin(layers_expa); + draw_end(); + draw_begin(layers_expb); + draw_end(); + draw_begin(layers_expc); + draw_end(); ///end let l0: slot_layer_t = { @@ -143,11 +143,11 @@ function layers_ext_flatten(height_to_normal: bool = false, layers: slot_layer_t // Merge height map into normal map if (height_to_normal && make_material_height_used) { - g2_begin(layers_temp_image); + draw_begin(layers_temp_image); draw_set_pipeline(pipes_copy); draw_image(l0.texpaint_nor, 0, 0); draw_set_pipeline(null); - g2_end(); + draw_end(); _iron_g4_begin(l0.texpaint_nor); iron_g5_set_pipeline(pipes_merge); diff --git a/armorpaint/sources/make_material.ts b/armorpaint/sources/make_material.ts index e95e5a94..2d9c1a47 100644 --- a/armorpaint/sources/make_material.ts +++ b/armorpaint/sources/make_material.ts @@ -175,11 +175,11 @@ function make_material_parse_paint_material(bake_previews: bool = true) { } if (bake_previews) { - let current: iron_g5_texture_t = _g2_current; - let g2_in_use: bool = _g2_in_use; - if (g2_in_use) g2_end(); + let current: iron_g5_texture_t = _draw_current; + let g2_in_use: bool = _draw_in_use; + if (g2_in_use) draw_end(); make_material_bake_node_previews(); - if (g2_in_use) g2_begin(current); + if (g2_in_use) draw_begin(current); } let m: material_data_t = project_materials[0].data; @@ -367,9 +367,9 @@ function make_material_bake_node_preview(node: ui_node_t, group: ui_node_canvas_ let rts: map_t = render_path_render_targets; let texpaint_live: render_target_t = map_get(rts, "texpaint_live"); - g2_begin(image); + draw_begin(image); draw_image(texpaint_live._image, 0, 0); - g2_end(); + draw_end(); } } diff --git a/armorpaint/sources/ui_header_ext.ts b/armorpaint/sources/ui_header_ext.ts index fed302f5..4add4969 100644 --- a/armorpaint/sources/ui_header_ext.ts +++ b/armorpaint/sources/ui_header_ext.ts @@ -338,10 +338,10 @@ function ui_header_draw_tool_properties(ui: ui_t) { context_raw.brush_scale = ui_slider(brush_scale_handle, tr("UV Scale"), 0.01, 5.0, true); if (brush_scale_handle.changed) { if (context_raw.tool == workspace_tool_t.DECAL || context_raw.tool == workspace_tool_t.TEXT) { - let current: iron_g5_texture_t = _g2_current; - g2_end(); + let current: iron_g5_texture_t = _draw_current; + draw_end(); util_render_make_decal_preview(); - g2_begin(current); + draw_begin(current); } } @@ -423,11 +423,11 @@ function ui_header_draw_tool_properties(ui: ui_t) { ui._w = w; if (h.changed) { - let current: iron_g5_texture_t = _g2_current; - g2_end(); + let current: iron_g5_texture_t = _draw_current; + draw_end(); util_render_make_text_preview(); util_render_make_decal_preview(); - g2_begin(current); + draw_begin(current); } } @@ -436,11 +436,11 @@ function ui_header_draw_tool_properties(ui: ui_t) { ui_combo(context_raw.fill_type_handle, fill_mode_combo, tr("Fill Mode")); if (context_raw.fill_type_handle.changed) { if (context_raw.fill_type_handle.position == fill_type_t.FACE) { - let current: iron_g5_texture_t = _g2_current; - g2_end(); + let current: iron_g5_texture_t = _draw_current; + draw_end(); // cache_uv_map(); util_uv_cache_triangle_map(); - g2_begin(current); + draw_begin(current); // wireframe_handle.selected = draw_wireframe = true; } make_material_parse_paint_material(); diff --git a/armorsculpt/sources/import_mesh.ts b/armorsculpt/sources/import_mesh.ts index 361fd9c9..d3a6e5c4 100644 --- a/armorsculpt/sources/import_mesh.ts +++ b/armorsculpt/sources/import_mesh.ts @@ -232,9 +232,9 @@ function import_mesh_pack_to_texture(mesh: raw_mesh_t) { let imgmesh: iron_g5_texture_t = iron_g4_create_texture_from_bytes(b, config_get_texture_res_x(), config_get_texture_res_y(), tex_format_t.RGBA128); let texpaint: iron_g5_texture_t = project_layers[0].texpaint; - g2_begin(texpaint); + draw_begin(texpaint); draw_set_pipeline(pipes_copy128); draw_scaled_image(imgmesh, 0, 0, config_get_texture_res_x(), config_get_texture_res_y()); draw_set_pipeline(null); - g2_end(); + draw_end(); } diff --git a/armorsculpt/sources/make_material.ts b/armorsculpt/sources/make_material.ts index 55e1ed34..328729d9 100644 --- a/armorsculpt/sources/make_material.ts +++ b/armorsculpt/sources/make_material.ts @@ -156,11 +156,11 @@ function make_material_parse_paint_material(bake_previews: bool = true) { } if (bake_previews) { - let current: iron_g5_texture_t = _g2_current; - let g2_in_use: bool = _g2_in_use; - if (g2_in_use) g2_end(); + let current: iron_g5_texture_t = _draw_current; + let g2_in_use: bool = _draw_in_use; + if (g2_in_use) draw_end(); make_material_bake_node_previews(); - if (g2_in_use) g2_begin(current); + if (g2_in_use) draw_begin(current); } let m: material_data_t = project_materials[0].data; diff --git a/base/sources/iron_draw.c b/base/sources/iron_draw.c index 5adc3cc7..ba606803 100644 --- a/base/sources/iron_draw.c +++ b/base/sources/iron_draw.c @@ -1,14 +1,14 @@ #include "iron_draw.h" -#include "const_data.h" - #include -#include -#include -#include -#include -#include -#include +#include "const_data.h" +#include "iron_gpu.h" +#include "iron_file.h" +#include "iron_simd.h" +#include "iron_math.h" +#include "iron_system.h" +#include "iron_string.h" #include "iron_vec2.h" +#include "iron_gc.h" #ifdef IRON_DIRECT3D12 extern bool waitAfterNextDraw; #endif @@ -18,14 +18,16 @@ extern bool waitAfterNextDraw; draw_font_t *draw_font = NULL; int draw_font_size; +iron_g5_texture_t *_draw_current = NULL; +bool _draw_in_use = false; static iron_matrix4x4_t draw_projection_matrix; static bool draw_bilinear_filter = true; static uint32_t draw_color = 0; -static bool draw_is_render_target = false; static iron_g5_pipeline_t *draw_last_pipeline = NULL; static iron_g5_pipeline_t *draw_custom_pipeline = NULL; static iron_matrix3x3_t draw_transform; +static bool _draw_thrown = false; static iron_g4_vertex_buffer_t image_vertex_buffer; static iron_g5_index_buffer_t image_index_buffer; @@ -67,10 +69,9 @@ static int text_buffer_index = 0; static int text_buffer_start = 0; static iron_g5_texture_t *text_last_texture = NULL; -static int *draw_font_glyph_blocks = NULL; -static int *draw_font_glyphs = NULL; -static int draw_font_num_glyph_blocks = -1; -static int draw_font_num_glyphs = -1; +static i32_array_t *draw_font_glyph_blocks = NULL; +static i32_array_t *draw_font_glyphs = NULL; +static int draw_glyphs_version = 0; void draw_image_end(void); void draw_colored_end(void); @@ -273,10 +274,27 @@ void draw_init(buffer_t *image_vert, buffer_t *image_frag, buffer_t *colored_ver } } -void draw_begin(void) { +static void _draw_begin() { draw_set_color(0xffffffff); } +void draw_begin(iron_g5_texture_t *render_target) { + if (_draw_in_use && !_draw_thrown) { + _draw_thrown = true; + iron_log("End before you begin"); + } + _draw_in_use = true; + + _draw_begin(); + + if (render_target != NULL) { + draw_set_render_target(render_target); + } + else { + draw_restore_render_target(); + } +} + void draw_set_image_rect_verts(float btlx, float btly, float tplx, float tply, float tprx, float tpry, float btrx, float btry) { int base_idx = (image_buffer_index - image_buffer_start) * 6 * 4; image_rect_verts[base_idx + 0] = btlx; @@ -645,7 +663,7 @@ void draw_text_set_rect_colors(uint32_t color) { void draw_text_draw_buffer(bool end) { if (text_buffer_index - text_buffer_start == 0) return; iron_g4_vertex_buffer_unlock(&text_vertex_buffer, text_buffer_index * 4); - iron_g5_set_pipeline(draw_custom_pipeline != NULL ? draw_custom_pipeline : draw_is_render_target ? &text_pipeline_rt : &text_pipeline); + iron_g5_set_pipeline(draw_custom_pipeline != NULL ? draw_custom_pipeline : _draw_current != NULL ? &text_pipeline_rt : &text_pipeline); iron_g4_set_matrix4(text_proj_loc, &draw_projection_matrix); iron_g4_set_vertex_buffer(&text_vertex_buffer); iron_g4_set_index_buffer(&text_index_buffer); @@ -695,7 +713,9 @@ draw_font_image_t *draw_font_get_image_internal(draw_font_t *font, int size) { } static inline bool draw_prepare_font_load_internal(draw_font_t *font, int size) { - if (draw_font_get_image_internal(font, size) != NULL) return false; // Nothing to do + if (draw_font_get_image_internal(font, size) != NULL) { + return false; // Nothing to do + } // Resize images array if necessary if (font->m_capacity <= font->m_images_len) { @@ -765,7 +785,7 @@ bool draw_font_load(draw_font_t *font, int size) { font->m_images_len += 1; int width = 64; int height = 32; - stbtt_bakedchar *baked = (stbtt_bakedchar *)malloc(draw_font_num_glyphs * sizeof(stbtt_bakedchar)); + stbtt_bakedchar *baked = (stbtt_bakedchar *)malloc(draw_font_glyphs->length * sizeof(stbtt_bakedchar)); unsigned char *pixels = NULL; int status = -1; @@ -780,7 +800,9 @@ bool draw_font_load(draw_font_t *font, int size) { pixels = (unsigned char *)realloc(pixels, width * height); if (pixels == NULL) return false; - status = stbtt_BakeFontBitmapArr(font->blob, font->offset, (float)size, pixels, width, height, draw_font_glyphs, draw_font_num_glyphs, baked); + status = stbtt_BakeFontBitmapArr( + font->blob, font->offset, (float)size, pixels, width, height, + draw_font_glyphs->buffer, draw_font_glyphs->length, baked); } stbtt_fontinfo info; @@ -807,24 +829,24 @@ iron_g5_texture_t *draw_font_get_texture(draw_font_t *font, int size) { return img->tex; } -int draw_font_get_char_index_internal(draw_font_image_t *img, int char_index) { - if (draw_font_num_glyphs <= 0) { +int draw_font_get_char_index_internal(int char_index) { + if (draw_font_glyphs->length <= 0) { return 0; } - int offset = draw_font_glyph_blocks[0]; + int offset = draw_font_glyph_blocks->buffer[0]; if (char_index < offset) { return 0; } - for (int i = 1; i < draw_font_num_glyph_blocks / 2; ++i) { - int prev_end = draw_font_glyph_blocks[i * 2 - 1]; - int start = draw_font_glyph_blocks[i * 2]; + for (int i = 1; i < draw_font_glyph_blocks->length / 2; ++i) { + int prev_end = draw_font_glyph_blocks->buffer[i * 2 - 1]; + int start = draw_font_glyph_blocks->buffer[i * 2]; if (char_index > start - 1) { offset += start - 1 - prev_end; } } - if (char_index - offset >= draw_font_num_glyphs) { + if (char_index - offset >= draw_font_glyphs->length) { return 0; } return char_index - offset; @@ -832,8 +854,10 @@ int draw_font_get_char_index_internal(draw_font_image_t *img, int char_index) { bool draw_font_get_baked_quad(draw_font_t *font, int size, draw_font_aligned_quad_t *q, int char_code, float xpos, float ypos) { draw_font_image_t *img = draw_font_get_image_internal(font, size); - int char_index = draw_font_get_char_index_internal(img, char_code); - if (char_index >= draw_font_num_glyphs) return false; + int char_index = draw_font_get_char_index_internal(char_code); + if (char_index >= draw_font_glyphs->length) { + return false; + } float ipw = 1.0f / (float)img->width; float iph = 1.0f / (float)img->height; stbtt_bakedchar b = img->chars[char_index]; @@ -888,37 +912,34 @@ void draw_string(const char *text, float x, float y) { } } -void draw_font_default_glyphs() { - draw_font_num_glyphs = 127 - 32; - draw_font_glyphs = (int *)malloc(draw_font_num_glyphs * sizeof(int)); - for (int i = 32; i < 127; ++i) draw_font_glyphs[i - 32] = i; - draw_font_num_glyph_blocks = 2; - draw_font_glyph_blocks = (int *)malloc(draw_font_num_glyph_blocks * sizeof(int)); - draw_font_glyph_blocks[0] = 32; - draw_font_glyph_blocks[1] = 126; -} - -void draw_font_init(draw_font_t *font, void *blob, int font_index) { +void draw_font_init(draw_font_t *font) { if (draw_font_glyphs == NULL) { - draw_font_default_glyphs(); + draw_font_init_glyphs(32, 127); } - font->blob = blob; - font->images = NULL; - font->m_images_len = 0; - font->m_capacity = 0; - font->offset = stbtt_GetFontOffsetForIndex(font->blob, font_index); - if (font->offset == -1) { - font->offset = stbtt_GetFontOffsetForIndex(font->blob, 0); + if (font->glyphs_version != draw_glyphs_version) { + font->glyphs_version = draw_glyphs_version; + font->blob = font->buf->buffer; + font->images = NULL; + font->m_images_len = 0; + font->m_capacity = 0; + font->offset = stbtt_GetFontOffsetForIndex(font->blob, font->index); + if (font->offset == -1) { + font->offset = stbtt_GetFontOffsetForIndex(font->blob, 0); + } } } -void draw_font_13(draw_font_t *font, void *blob) { +void draw_font_destroy(draw_font_t *font) { + font->buf = NULL; +} + +void draw_font_13(draw_font_t *font) { if (draw_font_glyphs == NULL) { - draw_font_default_glyphs(); + draw_font_init_glyphs(32, 127); } - font->blob = blob; + font->blob = font->buf->buffer; font->images = NULL; font->m_images_len = 0; font->m_capacity = 0; @@ -950,29 +971,37 @@ void draw_font_13(draw_font_t *font, void *blob) { img->chars = baked; } -bool draw_font_has_glyph(int glyph) { - for (int i = 0; i < draw_font_num_glyphs; ++i) { - if (draw_font_glyphs[i] == glyph) { - return true; - } +void draw_font_init_glyphs(int from, int to) { + gc_unroot(draw_font_glyphs); + gc_unroot(draw_font_glyph_blocks); + + draw_font_glyphs = i32_array_create(to - from); + for (int i = from; i < to; ++i) { + draw_font_glyphs->buffer[i - from] = i; } - return false; + draw_font_glyph_blocks = i32_array_create(2); + draw_font_glyph_blocks->buffer[0] = from; + draw_font_glyph_blocks->buffer[1] = to - 1; + draw_glyphs_version++; + + gc_root(draw_font_glyphs); + gc_root(draw_font_glyph_blocks); } -void _draw_font_set_glyphs(int *glyphs, int count) { - free(draw_font_glyphs); - draw_font_num_glyphs = count; - draw_font_glyphs = (int *)malloc(draw_font_num_glyphs * sizeof(int)); +bool draw_font_has_glyph(int glyph) { + return i32_array_index_of(draw_font_glyphs, glyph) > -1; +} + +void draw_font_build_glyphs() { + i32_array_sort(draw_font_glyphs, NULL); int blocks = 1; - draw_font_glyphs[0] = glyphs[0]; - int next_char = glyphs[0] + 1; + int next_char = draw_font_glyphs->buffer[0] + 1; int pos = 1; - while (pos < count) { - draw_font_glyphs[pos] = glyphs[pos]; - if (glyphs[pos] != next_char) { + while (pos < draw_font_glyphs->length) { + if (draw_font_glyphs->buffer[pos] != next_char) { ++blocks; - next_char = glyphs[pos] + 1; + next_char = draw_font_glyphs->buffer[pos] + 1; } else { ++next_char; @@ -980,36 +1009,31 @@ void _draw_font_set_glyphs(int *glyphs, int count) { ++pos; } - draw_font_num_glyph_blocks = 2 * blocks; - draw_font_glyph_blocks = (int *)malloc(draw_font_num_glyph_blocks * sizeof(int)); - draw_font_glyph_blocks[0] = glyphs[0]; - next_char = glyphs[0] + 1; + gc_unroot(draw_font_glyph_blocks); + draw_font_glyph_blocks = i32_array_create(2 * blocks); + gc_root(draw_font_glyph_blocks); + + draw_font_glyph_blocks->buffer[0] = draw_font_glyphs->buffer[0]; + next_char = draw_font_glyphs->buffer[0] + 1; pos = 1; - for (int i = 1; i < count; ++i) { - if (glyphs[i] != next_char) { - draw_font_glyph_blocks[pos * 2 - 1] = glyphs[i - 1]; - draw_font_glyph_blocks[pos * 2] = glyphs[i]; + for (int i = 1; i < draw_font_glyphs->length; ++i) { + if (draw_font_glyphs->buffer[i] != next_char) { + draw_font_glyph_blocks->buffer[pos * 2 - 1] = draw_font_glyphs->buffer[i - 1]; + draw_font_glyph_blocks->buffer[pos * 2] = draw_font_glyphs->buffer[i]; ++pos; - next_char = glyphs[i] + 1; + next_char = draw_font_glyphs->buffer[i] + 1; } else { ++next_char; } } - draw_font_glyph_blocks[blocks * 2 - 1] = glyphs[count - 1]; -} - -void draw_font_set_glyphs(i32_array_t *glyphs) { - _draw_font_set_glyphs(glyphs->buffer, glyphs->length); + draw_font_glyph_blocks->buffer[blocks * 2 - 1] = draw_font_glyphs->buffer[draw_font_glyphs->length - 1]; + draw_glyphs_version++; } void draw_font_add_glyph(int glyph) { - // TODO: slow - draw_font_num_glyphs++; - int *font_glyphs = (int *)malloc(draw_font_num_glyphs * sizeof(int)); - for (int i = 0; i < draw_font_num_glyphs - 1; ++i) font_glyphs[i] = draw_font_glyphs[i]; - font_glyphs[draw_font_num_glyphs - 1] = glyph; - _draw_font_set_glyphs(font_glyphs, draw_font_num_glyphs); + i32_array_push(draw_font_glyphs, glyph); + draw_font_build_glyphs(); } int draw_font_count(draw_font_t *font) { @@ -1022,7 +1046,7 @@ int draw_font_height(draw_font_t *font, int font_size) { } float draw_font_get_char_width_internal(draw_font_image_t *img, int char_index) { - int i = draw_font_get_char_index_internal(img, char_index); + int i = draw_font_get_char_index_internal(char_index); return img->chars[i].xadvance; } @@ -1056,12 +1080,21 @@ void draw_text_end(void) { text_last_texture = NULL; } -void draw_end(void) { +static void _draw_end(void) { draw_image_end(); draw_colored_end(); draw_text_end(); } +void draw_end(void) { + if (!_draw_in_use && !_draw_thrown) { + _draw_thrown = true; + iron_log("Begin before you end"); + } + _draw_in_use = false; + _draw_end(); +} + void draw_set_color(uint32_t color) { draw_color = color; } @@ -1071,49 +1104,50 @@ uint32_t draw_get_color() { } void draw_set_pipeline(iron_g5_pipeline_t *pipeline) { - if (pipeline == draw_last_pipeline) return; + if (pipeline == draw_last_pipeline) { + return; + } draw_last_pipeline = pipeline; - draw_end(); // flush + _draw_end(); // flush draw_custom_pipeline = pipeline; } -void draw_set_transform(buffer_t *matrix) { - iron_matrix3x3_t *m = matrix != NULL ? (iron_matrix3x3_t *)matrix->buffer : NULL; - if (m == NULL) { +void draw_set_transform(mat3_t matrix) { + if (mat3_isnan(matrix)) { draw_transform = iron_matrix3x3_identity(); } else { - for (int i = 0; i < 3 * 3; ++i) { - draw_transform.m[i] = m->m[i]; - } + draw_transform = matrix; } } bool draw_set_font(draw_font_t *font, int size) { - draw_end(); // flush + _draw_end(); // flush draw_font = font; draw_font_size = size; return draw_font_load(font, size); } void draw_set_bilinear_filter(bool bilinear) { - if (draw_bilinear_filter == bilinear) return; - draw_end(); // flush + if (draw_bilinear_filter == bilinear) { + return; + } + _draw_end(); // flush draw_bilinear_filter = bilinear; } void draw_restore_render_target(void) { - draw_is_render_target = false; - draw_end(); - draw_begin(); + _draw_current = NULL; + _draw_end(); + _draw_begin(); iron_g4_restore_render_target(); draw_internal_set_projection_matrix(NULL); } void draw_set_render_target(iron_g5_texture_t *target) { - draw_is_render_target = true; - draw_end(); - draw_begin(); + _draw_current = target; + _draw_end(); + _draw_begin(); iron_g5_texture_t *render_targets[1] = { target }; iron_g4_set_render_targets(render_targets, 1); draw_internal_set_projection_matrix(target); diff --git a/base/sources/iron_draw.h b/base/sources/iron_draw.h index 927d77d8..44724466 100644 --- a/base/sources/iron_draw.h +++ b/base/sources/iron_draw.h @@ -5,11 +5,12 @@ #pragma once -#include -#include #include #include +#include "iron_math.h" +#include "iron_gpu.h" #include "iron_array.h" +#include "iron_mat3.h" typedef struct draw_font_image draw_font_image_t; @@ -21,12 +22,12 @@ typedef struct draw_font { int offset; buffer_t *buf; - void *glyphs; // i32_array_t + int glyphs_version; int index; } draw_font_t; void draw_init(buffer_t *image_vert, buffer_t *image_frag, buffer_t *colored_vert, buffer_t *colored_frag, buffer_t *text_vert, buffer_t *text_frag); -void draw_begin(void); +void draw_begin(iron_g5_texture_t *target); void draw_scaled_sub_image(iron_g5_texture_t *img, float sx, float sy, float sw, float sh, float dx, float dy, float dw, float dh); void draw_scaled_sub_texture(iron_g5_texture_t *tex, float sx, float sy, float sw, float sh, float dx, float dy, float dw, float dh); void draw_scaled_image(iron_g5_texture_t *tex, float dx, float dy, float dw, float dh); @@ -45,13 +46,14 @@ void draw_end(void); void draw_set_color(uint32_t color); uint32_t draw_get_color(); void draw_set_pipeline(iron_g5_pipeline_t *pipeline); -void draw_set_transform(buffer_t *matrix); +void draw_set_transform(mat3_t matrix); bool draw_set_font(draw_font_t *font, int size); -void draw_font_init(draw_font_t *font, void *blob, int font_index); -void draw_font_13(draw_font_t *font, void *blob); +void draw_font_init(draw_font_t *font); +void draw_font_destroy(draw_font_t *font); +void draw_font_13(draw_font_t *font); bool draw_font_has_glyph(int glyph); -void draw_font_set_glyphs(i32_array_t *glyphs); void draw_font_add_glyph(int glyph); +void draw_font_init_glyphs(int from, int to); int draw_font_count(draw_font_t *font); int draw_font_height(draw_font_t *font, int font_size); float draw_sub_string_width(draw_font_t *font, int font_size, const char *text, int start, int end); @@ -66,3 +68,5 @@ void draw_cubic_bezier(f32_array_t *x, f32_array_t *y, int segments, float stren extern int draw_font_size; extern draw_font_t *draw_font; +extern iron_g5_texture_t *_draw_current; +extern bool _draw_in_use; diff --git a/base/sources/ts/base.ts b/base/sources/ts/base.ts index 202cee38..246b47da 100644 --- a/base/sources/ts/base.ts +++ b/base/sources/ts/base.ts @@ -86,11 +86,10 @@ function base_init() { // Baked font for fast startup if (config_raw.locale == "en") { - draw_font_13(base_font, base_font.buf.buffer); - base_font.glyphs = _g2_font_glyphs; + draw_font_13(base_font); } else { - g2_font_init(base_font); + draw_font_init(base_font); } base_color_wheel = image_color_wheel; diff --git a/base/sources/ts/box_preferences.ts b/base/sources/ts/box_preferences.ts index 1a0a35e7..ec3fcbd6 100644 --- a/base/sources/ts/box_preferences.ts +++ b/base/sources/ts/box_preferences.ts @@ -325,8 +325,8 @@ function box_preferences_show() { config_raw.undo_steps = math_floor(context_raw.undo_handle.value = 1); } if (context_raw.undo_handle.changed) { - let current: iron_g5_texture_t = _g2_current; - g2_end(); + let current: iron_g5_texture_t = _draw_current; + draw_end(); if (history_undo_layers != null) { while (history_undo_layers.length < config_raw.undo_steps) { @@ -341,7 +341,7 @@ function box_preferences_show() { } history_reset(); - g2_begin(current); + draw_begin(current); } ///if is_paint diff --git a/base/sources/ts/box_projects.ts b/base/sources/ts/box_projects.ts index 774a6ab0..4746011e 100644 --- a/base/sources/ts/box_projects.ts +++ b/base/sources/ts/box_projects.ts @@ -209,13 +209,13 @@ function box_projects_recent_tab(ui: ui_t) { } if (ui_button(file, ui_align_t.LEFT) && file_exists(path)) { - let current: iron_g5_texture_t = _g2_current; - let g2_in_use: bool = _g2_in_use; - if (g2_in_use) g2_end(); + let current: iron_g5_texture_t = _draw_current; + let g2_in_use: bool = _draw_in_use; + if (g2_in_use) draw_end(); import_arm_run_project(path); - if (g2_in_use) g2_begin(current); + if (g2_in_use) draw_begin(current); ui_box_hide(); } if (ui.is_hovered) { diff --git a/base/sources/ts/config.ts b/base/sources/ts/config.ts index 4a95e516..e87597bd 100644 --- a/base/sources/ts/config.ts +++ b/base/sources/ts/config.ts @@ -253,11 +253,11 @@ function config_apply() { config_save(); context_raw.ddirty = 2; - let current: iron_g5_texture_t = _g2_current; - let g2_in_use: bool = _g2_in_use; - if (g2_in_use) g2_end(); + let current: iron_g5_texture_t = _draw_current; + let g2_in_use: bool = _draw_in_use; + if (g2_in_use) draw_end(); render_path_base_apply_config(); - if (g2_in_use) g2_begin(current); + if (g2_in_use) draw_begin(current); } function config_get_super_sample_quality(f: f32): i32 { diff --git a/base/sources/ts/console.ts b/base/sources/ts/console.ts index 77b181f0..44ca5eca 100644 --- a/base/sources/ts/console.ts +++ b/base/sources/ts/console.ts @@ -12,9 +12,9 @@ function console_draw_toast(s: string) { let x: f32 = iron_window_width() / 2; let y: f32 = iron_window_height() - 200 * scale; draw_filled_rect(x - 200 * scale, y, 400 * scale, 80 * scale); - g2_set_font(base_font, math_floor(22 * scale)); + draw_set_font(base_font, math_floor(22 * scale)); draw_set_color(0xffffffff); - draw_string(s, x - g2_font_width(draw_font, draw_font_size, s) / 2, y + 40 * scale - g2_font_height(draw_font, draw_font_size) / 2); + draw_string(s, x - draw_string_width(draw_font, draw_font_size, s) / 2, y + 40 * scale - draw_font_height(draw_font, draw_font_size) / 2); } function _console_toast_render(s: string) { @@ -50,9 +50,9 @@ function console_progress(s: string) { // Pass one frame to immediately show the message ///if (!arm_vulkan) // TODO ui_end_input(); - g2_end(); + draw_end(); app_render(); - g2_begin(); + draw_begin(); iron_g4_swap_buffers(); ///end } diff --git a/base/sources/ts/context.ts b/base/sources/ts/context.ts index e93aa8b0..cfabf0e8 100644 --- a/base/sources/ts/context.ts +++ b/base/sources/ts/context.ts @@ -543,15 +543,15 @@ function context_set_layer(l: slot_layer_t) { context_raw.layer = l; ui_header_handle.redraws = 2; - let current: iron_g5_texture_t = _g2_current; - let g2_in_use: bool = _g2_in_use; - if (g2_in_use) g2_end(); + let current: iron_g5_texture_t = _draw_current; + let g2_in_use: bool = _draw_in_use; + if (g2_in_use) draw_end(); layers_set_object_mask(); make_material_parse_mesh_material(); make_material_parse_paint_material(); - if (g2_in_use) g2_begin(current); + if (g2_in_use) draw_begin(current); ui_base_hwnds[tab_area_t.SIDEBAR0].redraws = 2; ui_view2d_hwnd.redraws = 2; diff --git a/base/sources/ts/export_arm.ts b/base/sources/ts/export_arm.ts index b0e0bafc..f82340ca 100644 --- a/base/sources/ts/export_arm.ts +++ b/base/sources/ts/export_arm.ts @@ -177,14 +177,14 @@ function export_arm_run_project() { let tex: iron_g5_texture_t = rt._image; let mesh_icon: iron_g5_texture_t = iron_g4_create_render_target(256, 256); let r: f32 = app_w() / app_h(); - g2_begin(mesh_icon); + draw_begin(mesh_icon); draw_scaled_image(tex, -(256 * r - 256) / 2, 0, 256 * r, 256); - g2_end(); + draw_end(); ///if arm_metal // Flush command list - g2_begin(mesh_icon); - g2_end(); + draw_begin(mesh_icon); + draw_end(); ///end let mesh_icon_pixels: buffer_t = iron_g4_get_texture_pixels(mesh_icon); @@ -488,9 +488,9 @@ function export_arm_pack_assets(raw: project_format_t, assets: asset_t[]) { if (!project_packed_asset_exists(raw.packed_assets, assets[i].file)) { let image: iron_g5_texture_t = project_get_image(assets[i]); let temp: iron_g5_texture_t = iron_g4_create_render_target(image.width, image.height); - g2_begin(temp); + draw_begin(temp); draw_image(image, 0, 0); - g2_end(); + draw_end(); array_push(temp_images, temp); let pa: packed_asset_t = { name: assets[i].file, diff --git a/base/sources/ts/export_texture.ts b/base/sources/ts/export_texture.ts index 9ad43e8d..37215708 100644 --- a/base/sources/ts/export_texture.ts +++ b/base/sources/ts/export_texture.ts @@ -225,9 +225,9 @@ function export_texture_run_layers(path: string, layers: slot_layer_t[], object_ if (l1masks != null && !bake_material) { if (l1masks.length > 1) { layers_make_temp_mask_img(); - g2_begin(pipes_temp_mask_image); + draw_begin(pipes_temp_mask_image); iron_g5_clear(0x00000000); - g2_end(); + draw_end(); let l1: slot_layer_t = { texpaint: pipes_temp_mask_image }; @@ -242,11 +242,11 @@ function export_texture_run_layers(path: string, layers: slot_layer_t[], object_ } if (l1.paint_base) { - g2_begin(layers_temp_image); // Copy to temp + draw_begin(layers_temp_image); // Copy to temp draw_set_pipeline(pipes_copy); draw_image(layers_expa, 0, 0); draw_set_pipeline(null); - g2_end(); + draw_end(); _iron_g4_begin(layers_expa); iron_g5_set_pipeline(pipes_merge); @@ -263,11 +263,11 @@ function export_texture_run_layers(path: string, layers: slot_layer_t[], object_ } if (l1.paint_nor) { - g2_begin(layers_temp_image); + draw_begin(layers_temp_image); draw_set_pipeline(pipes_copy); draw_image(layers_expb, 0, 0); draw_set_pipeline(null); - g2_end(); + draw_end(); _iron_g4_begin(layers_expb); iron_g5_set_pipeline(pipes_merge); @@ -284,11 +284,11 @@ function export_texture_run_layers(path: string, layers: slot_layer_t[], object_ } if (l1.paint_occ || l1.paint_rough || l1.paint_met || l1.paint_height) { - g2_begin(layers_temp_image); + draw_begin(layers_temp_image); draw_set_pipeline(pipes_copy); draw_image(layers_expc, 0, 0); draw_set_pipeline(null); - g2_end(); + draw_end(); if (l1.paint_occ && l1.paint_rough && l1.paint_met && l1.paint_height) { layers_commands_merge_pack(pipes_merge, layers_expc, l1.texpaint, l1.texpaint_pack, slot_layer_get_opacity(l1), mask, l1.paint_height_blend ? -3 : -1); @@ -303,12 +303,12 @@ function export_texture_run_layers(path: string, layers: slot_layer_t[], object_ ///if arm_metal // Flush command list - g2_begin(layers_expa); - g2_end(); - g2_begin(layers_expb); - g2_end(); - g2_begin(layers_expc); - g2_end(); + draw_begin(layers_expa); + draw_end(); + draw_begin(layers_expb); + draw_end(); + draw_begin(layers_expc); + draw_end(); ///end ///end diff --git a/base/sources/ts/import_arm.ts b/base/sources/ts/import_arm.ts index 8afc43bb..129fdcc5 100644 --- a/base/sources/ts/import_arm.ts +++ b/base/sources/ts/import_arm.ts @@ -244,36 +244,36 @@ function import_arm_run_project(path: string) { if (is_mask) { _texpaint = iron_g4_create_texture_from_bytes(lz4_decode(ld.texpaint, ld.res * ld.res * 4), ld.res, ld.res, tex_format_t.RGBA32); - g2_begin(l.texpaint); + draw_begin(l.texpaint); // draw_set_pipeline(pipes_copy8); draw_set_pipeline(project.is_bgra ? pipes_copy_bgra : pipes_copy); // Full bits for undo support, R8 is used draw_image(_texpaint, 0, 0); draw_set_pipeline(null); - g2_end(); + draw_end(); } else { // Layer // TODO: create render target from bytes _texpaint = iron_g4_create_texture_from_bytes(lz4_decode(ld.texpaint, ld.res * ld.res * 4 * bytes_per_pixel), ld.res, ld.res, format); - g2_begin(l.texpaint); + draw_begin(l.texpaint); draw_set_pipeline(project.is_bgra ? pipes_copy_bgra : pipes_copy); draw_image(_texpaint, 0, 0); draw_set_pipeline(null); - g2_end(); + draw_end(); ///if is_paint _texpaint_nor = iron_g4_create_texture_from_bytes(lz4_decode(ld.texpaint_nor, ld.res * ld.res * 4 * bytes_per_pixel), ld.res, ld.res, format); - g2_begin(l.texpaint_nor); + draw_begin(l.texpaint_nor); draw_set_pipeline(project.is_bgra ? pipes_copy_bgra : pipes_copy); draw_image(_texpaint_nor, 0, 0); draw_set_pipeline(null); - g2_end(); + draw_end(); _texpaint_pack = iron_g4_create_texture_from_bytes(lz4_decode(ld.texpaint_pack, ld.res * ld.res * 4 * bytes_per_pixel), ld.res, ld.res, format); - g2_begin(l.texpaint_pack); + draw_begin(l.texpaint_pack); draw_set_pipeline(project.is_bgra ? pipes_copy_bgra : pipes_copy); draw_image(_texpaint_pack, 0, 0); draw_set_pipeline(null); - g2_end(); + draw_end(); ///end } diff --git a/base/sources/ts/import_blend_material.ts b/base/sources/ts/import_blend_material.ts index e76d8f87..372c016d 100644 --- a/base/sources/ts/import_blend_material.ts +++ b/base/sources/ts/import_blend_material.ts @@ -30,13 +30,13 @@ function import_blend_material_run(path: string) { function _import_blend_material() { - let current: iron_g5_texture_t = _g2_current; - let g2_in_use: bool = _g2_in_use; - if (g2_in_use) g2_end(); + let current: iron_g5_texture_t = _draw_current; + let g2_in_use: bool = _draw_in_use; + if (g2_in_use) draw_end(); console_toast(tr("Baking material")); - if (g2_in_use) g2_begin(current); + if (g2_in_use) draw_begin(current); app_notify_on_init(function () { diff --git a/base/sources/ts/import_envmap.ts b/base/sources/ts/import_envmap.ts index 21f0364f..df7d06a9 100644 --- a/base/sources/ts/import_envmap.ts +++ b/base/sources/ts/import_envmap.ts @@ -35,11 +35,11 @@ function import_envmap_run(path: string, image: iron_g5_texture_t) { } // Down-scale to 1024x512 - g2_begin(import_envmap_radiance); + draw_begin(import_envmap_radiance); draw_set_pipeline(pipes_copy128); draw_scaled_image(image, 0, 0, 1024, 512); draw_set_pipeline(null); - g2_end(); + draw_end(); let radiance_pixels: buffer_t = iron_g4_get_texture_pixels(import_envmap_radiance); if (import_envmap_radiance_cpu != null) { diff --git a/base/sources/ts/import_font.ts b/base/sources/ts/import_font.ts index 0ae8fc6e..f0f36dc1 100644 --- a/base/sources/ts/import_font.ts +++ b/base/sources/ts/import_font.ts @@ -9,17 +9,15 @@ function import_font_run(path: string) { } let font: draw_font_t = data_get_font(path); - g2_font_init(font); // Make sure font_ is ready + draw_font_init(font); // Make sure font_ is ready let count: i32 = draw_font_count(font); let font_slots: slot_font_t[] = []; for (let i: i32 = 0; i < count; ++i) { let ar: string[] = string_split(path, path_sep); let name: string = ar[ar.length - 1]; - let f: draw_font_t = g2_font_clone(font); - g2_font_set_font_index(f, i); - - g2_font_init(f); + let f: draw_font_t = { buf: font.buf, index: font.index }; + draw_font_init(f); if (!draw_set_font(f, util_render_font_preview_size)) { console_error(tr("Error: Failed to read font data")); continue; diff --git a/base/sources/ts/iron/app.ts b/base/sources/ts/iron/app.ts index c9ab9c3d..881b5c25 100644 --- a/base/sources/ts/iron/app.ts +++ b/base/sources/ts/iron/app.ts @@ -147,9 +147,9 @@ function app_render() { function app_render_2d() { if (app_on_renders_2d.length > 0) { - g2_begin(); + draw_begin(); _app_run_callbacks(app_on_renders_2d); - g2_end(); + draw_end(); } } diff --git a/base/sources/ts/iron/data.ts b/base/sources/ts/iron/data.ts index 077a1766..bf27c056 100644 --- a/base/sources/ts/iron/data.ts +++ b/base/sources/ts/iron/data.ts @@ -147,7 +147,7 @@ function data_get_font(file: string): draw_font_t { } let blob: buffer_t = iron_load_blob(data_resolve_path(file)); - let b: draw_font_t = g2_font_create(blob); + let b: draw_font_t = { buf: blob, index: 0 }; map_set(data_cached_fonts, file, b); data_assets_loaded++; return b; @@ -207,7 +207,7 @@ function data_delete_font(handle: string) { if (font == null) { return; } - g2_font_unload(font); + draw_font_destroy(font); map_delete(data_cached_fonts, handle); } @@ -270,7 +270,7 @@ function data_delete_all() { let cached_fonts_keys: string[] = map_keys(data_cached_fonts); for (let i: i32 = 0; i < cached_fonts_keys.length; ++i) { let c: draw_font_t = map_get(data_cached_fonts, cached_fonts_keys[i]); - g2_font_unload(c); + draw_font_destroy(c); } data_cached_fonts = map_create(); } diff --git a/base/sources/ts/iron/g2.ts b/base/sources/ts/iron/g2.ts deleted file mode 100644 index 12047557..00000000 --- a/base/sources/ts/iron/g2.ts +++ /dev/null @@ -1,121 +0,0 @@ - -declare type draw_font_t = { - blob?: any; // unsigned char * - images?: any; // draw_font_image_t * - m_capacity?: i32; - m_images_len?: i32; - offset?: 32; - - buf?: buffer_t; - glyphs?: i32[]; - index?: i32; -}; - -let _g2_current: iron_g5_texture_t = null; -let _g2_in_use: bool = false; -let _g2_font_glyphs: i32[] = _g2_make_glyphs(32, 127); -let _g2_font_glyphs_last: i32[] = _g2_font_glyphs; -let _g2_thrown: bool = false; -let _g2_mat: f32_array_t = f32_array_create(9); - -function g2_set_font(f: draw_font_t, size: i32) { - g2_font_init(f); - draw_set_font(f, size); - draw_font_size = size; -} - -function g2_set_transformation(m: mat3_t) { - if (mat3_isnan(m)) { - draw_set_transform(null); - } - else { - _g2_mat[0] = m.m00; - _g2_mat[1] = m.m01; - _g2_mat[2] = m.m02; - _g2_mat[3] = m.m10; - _g2_mat[4] = m.m11; - _g2_mat[5] = m.m12; - _g2_mat[6] = m.m20; - _g2_mat[7] = m.m21; - _g2_mat[8] = m.m22; - draw_set_transform(_g2_mat); - } -} - -function _g2_make_glyphs(start: i32, end: i32): i32[] { - let ar: i32[] = []; - for (let i: i32 = start; i < end; ++i) { - array_push(ar, i); - } - return ar; -} - -function g2_begin(render_target: iron_g5_texture_t = null) { - if (_g2_in_use && !_g2_thrown) { - _g2_thrown = true; - iron_log("End before you begin"); - } - _g2_in_use = true; - _g2_current = render_target; - - draw_begin(); - - if (render_target != null) { - draw_set_render_target(render_target); - } - else { - draw_restore_render_target(); - } -} - -function g2_end() { - if (!_g2_in_use && !_g2_thrown) { - _g2_thrown = true; - iron_log("Begin before you end"); - } - _g2_in_use = false; - _g2_current = null; - - draw_end(); -} - -function g2_font_init(raw: draw_font_t) { - if (_g2_font_glyphs_last != _g2_font_glyphs) { - _g2_font_glyphs_last = _g2_font_glyphs; - draw_font_set_glyphs(_g2_font_glyphs); - } - if (raw.glyphs != _g2_font_glyphs) { - raw.glyphs = _g2_font_glyphs; - draw_font_init(raw, raw.buf.buffer, raw.index); - } -} - -function g2_font_height(raw: draw_font_t, size: i32): f32 { - g2_font_init(raw); - return draw_font_height(raw, size); -} - -function g2_font_width(raw: draw_font_t, size: i32, str: string): f32 { - g2_font_init(raw); - return draw_string_width(raw, size, str); -} - -function g2_font_unload(raw: draw_font_t) { - raw.buf = null; -} - -function g2_font_set_font_index(raw: draw_font_t, index: i32) { - raw.index = index; - _g2_font_glyphs = array_slice(_g2_font_glyphs, 0, _g2_font_glyphs.length); // Trigger atlas update -} - -function g2_font_create(buf: buffer_t, index: i32 = 0): draw_font_t { - let raw: draw_font_t = {}; - raw.buf = buf; - raw.index = index; - return raw; -} - -function g2_font_clone(raw: draw_font_t): draw_font_t { - return g2_font_create(raw.buf, raw.index); -} diff --git a/base/sources/ts/iron/iron.ts b/base/sources/ts/iron/iron.ts index 995aae30..c45648c7 100644 --- a/base/sources/ts/iron/iron.ts +++ b/base/sources/ts/iron/iron.ts @@ -296,7 +296,7 @@ declare function iron_get_files_location(): string; declare function _iron_http_request(url: string, size: i32, callback: (url: string, _: buffer_t)=>void): void; declare function draw_init(image_vert: buffer_t, image_frag: buffer_t, colored_vert: buffer_t, colored_frag: buffer_t, text_vert: buffer_t, text_frag: buffer_t): void; -declare function draw_begin(): void; +declare function draw_begin(render_target: iron_g5_texture_t = null): void; declare function draw_end(): void; declare function draw_scaled_sub_image(image: iron_g5_texture_t, sx: f32, sy: f32, sw: f32, sh: f32, dx: f32, dy: f32, dw: f32, dh: f32): void; declare function draw_sub_image(image: iron_g5_texture_t, x: f32, y: f32, sx: f32, sy: f32, sw: f32, sh: f32): void; @@ -308,25 +308,36 @@ declare function draw_rect(x: f32, y: f32, width: f32, height: f32, strength: f3 declare function draw_line(x0: f32, y0: f32, x1: f32, y1: f32, strength: f32 = 1.0): void; declare function draw_line_aa(x0: f32, y0: f32, x1: f32, y1: f32, strength: f32 = 1.0): void; declare function draw_string(text: string, x: f32, y: f32): void; -declare function draw_set_font(font: any, size: i32): bool; -declare function draw_font_init(font: any, buf: any, font_index: i32): void; -declare function draw_font_13(font: any, buf: any): any; -declare function draw_font_set_glyphs(glyphs: i32[]): void; -declare function draw_font_count(font: any): i32; -declare function draw_font_height(font: any, size: i32): i32; -declare function draw_string_width(font: any, size: i32, text: string): i32; +declare function draw_set_font(font: draw_font_t, size: i32): bool; +declare function draw_font_init(font: draw_font_t): void; +declare function draw_font_destroy(font: draw_font_t): void; +declare function draw_font_13(font: draw_font_t): any; +declare function draw_font_has_glyph(glyph: i32): bool; +declare function draw_font_add_glyph(glyph: i32): void; +declare function draw_font_init_glyphs(from: i32, to: i32): void; +declare function draw_font_count(font: draw_font_t): i32; +declare function draw_font_height(font: draw_font_t, size: i32): i32; +declare function draw_string_width(font: draw_font_t, size: i32, text: string): i32; declare function draw_set_bilinear_filter(bilinear: bool): void; -declare function draw_restore_render_target(): void; -declare function draw_set_render_target(render_target: any): void; declare function draw_set_color(color: i32): void; declare function draw_set_pipeline(pipeline: any): void; -declare function draw_set_transform(matrix: buffer_t): void; +declare function draw_set_transform(matrix: mat3_t): void; declare function draw_filled_circle(cx: f32, cy: f32, radius: f32, segments: i32 = 0): void; declare function draw_circle(cx: f32, cy: f32, radius: f32, segments: i32 = 0, strength: f32 = 1.0): void; declare function draw_cubic_bezier(x: f32[], y: f32[], segments: i32 = 20, strength: f32 = 1.0): void; declare let draw_font: draw_font_t; declare let draw_font_size: i32; +declare type draw_font_t = { + blob?: any; // unsigned char * + images?: any; // draw_font_image_t * + m_capacity?: i32; + m_images_len?: i32; + offset?: 32; + buf?: buffer_t; + index?: i32; +}; + declare function iron_set_save_and_quit_callback(callback: (save: bool)=>void): void; declare function iron_set_mouse_cursor(id: i32): void; declare function iron_delay_idle_sleep(): void; diff --git a/base/sources/ts/iron/ui.ts b/base/sources/ts/iron/ui.ts index 4465a42e..21529fd7 100644 --- a/base/sources/ts/iron/ui.ts +++ b/base/sources/ts/iron/ui.ts @@ -131,14 +131,14 @@ function _ui_tooltip_image(image: iron_g5_texture_t, max_width: i32 = 0) { } function ui_window(handle: ui_handle_t, x: i32, y: i32, w: i32, h: i32, drag: bool = false): bool { - _g2_current = ADDRESS(handle.texture); - _g2_in_use = true; + _draw_current = ADDRESS(handle.texture); + _draw_in_use = true; return _ui_window(handle, x, y, w, h, drag); } function ui_end(last: bool = true) { - _g2_current = null; - _g2_in_use = false; + _draw_current = null; + _draw_in_use = false; _ui_end(last); } @@ -228,7 +228,7 @@ function ui_get_socket(nodes: ui_node_t[], id: i32): ui_node_socket_t { } function ui_set_font(raw: ui_t, font: draw_font_t) { - g2_font_init(font); // Make sure font_ is ready + draw_font_init(font); // Make sure font is ready raw.ops.font = font; } diff --git a/base/sources/ts/layers.ts b/base/sources/ts/layers.ts index 7c0a5c83..8b5552ba 100644 --- a/base/sources/ts/layers.ts +++ b/base/sources/ts/layers.ts @@ -29,9 +29,9 @@ function layers_init() { let texpaint: render_target_t = map_get(render_path_render_targets, "texpaint"); let texpaint_nor: render_target_t = map_get(render_path_render_targets, "texpaint_nor"); let texpaint_pack: render_target_t = map_get(render_path_render_targets, "texpaint_pack"); - g2_begin(texpaint._image); + draw_begin(texpaint._image); draw_scaled_image(resource_get("placeholder.k"), 0, 0, config_get_texture_res_x(), config_get_texture_res_y()); // Base - g2_end(); + draw_end(); _iron_g4_begin(texpaint_nor._image); iron_g5_clear(color_from_floats(0.5, 0.5, 1.0, 0.0)); // Nor _iron_g4_end(); @@ -248,11 +248,11 @@ function layers_apply_mask(l: slot_layer_t, m: slot_layer_t) { layers_make_temp_img(); // Copy layer to temp - g2_begin(layers_temp_image); + draw_begin(layers_temp_image); draw_set_pipeline(pipes_copy); draw_image(l.texpaint, 0, 0); draw_set_pipeline(null); - g2_end(); + draw_end(); // Apply mask _iron_g4_begin(l.texpaint); @@ -306,8 +306,8 @@ function layers_update_fill_layers() { render_path_paint_live_layer = slot_layer_create("_live"); } - current = _g2_current; - if (current != null) g2_end(); + current = _draw_current; + if (current != null) draw_end(); context_raw.tool = workspace_tool_t.FILL; context_raw.fill_type_handle.position = fill_type_t.OBJECT; @@ -322,7 +322,7 @@ function layers_update_fill_layers() { context_raw.pdirty = 0; context_raw.rdirty = 2; - if (current != null) g2_begin(current); + if (current != null) draw_begin(current); return; } @@ -342,9 +342,9 @@ function layers_update_fill_layers() { } if (has_fill_layer || has_fill_mask) { - current = _g2_current; + current = _draw_current; if (current != null) { - g2_end(); + draw_end(); } context_raw.pdirty = 1; context_raw.tool = workspace_tool_t.FILL; @@ -389,7 +389,7 @@ function layers_update_fill_layers() { context_raw.ddirty = 2; context_raw.rdirty = 2; context_raw.layers_preview_dirty = true; // Repaint all layer previews as multiple layers might have changed. - if (current != null) g2_begin(current); + if (current != null) draw_begin(current); context_raw.layer = _layer; layers_set_object_mask(); context_raw.tool = _tool; @@ -399,9 +399,9 @@ function layers_update_fill_layers() { } function layers_update_fill_layer(parse_paint: bool = true) { - let current: iron_g5_texture_t = _g2_current; - let g2_in_use: bool = _g2_in_use; - if (g2_in_use) g2_end(); + let current: iron_g5_texture_t = _draw_current; + let g2_in_use: bool = _draw_in_use; + if (g2_in_use) draw_end(); let _tool: workspace_tool_t = context_raw.tool; let _fill_type: i32 = context_raw.fill_type_handle.position; @@ -420,7 +420,7 @@ function layers_update_fill_layer(parse_paint: bool = true) { context_raw.rdirty = 2; context_raw.tool = _tool; context_raw.fill_type_handle.position = _fill_type; - if (g2_in_use) g2_begin(current); + if (g2_in_use) draw_begin(current); } function layers_set_object_mask() { @@ -711,11 +711,11 @@ function layers_merge_layer(l0 : slot_layer_t, l1: slot_layer_t, use_mask: bool layers_make_temp_img(); - g2_begin(layers_temp_image); // Copy to temp + draw_begin(layers_temp_image); // Copy to temp draw_set_pipeline(pipes_copy); draw_image(l0.texpaint, 0, 0); draw_set_pipeline(null); - g2_end(); + draw_end(); let empty_rt: render_target_t = map_get(render_path_render_targets, "empty_white"); let empty: iron_g5_texture_t = empty_rt._image; @@ -758,11 +758,11 @@ function layers_merge_layer(l0 : slot_layer_t, l1: slot_layer_t, use_mask: bool } if (l0.texpaint_nor != null) { - g2_begin(layers_temp_image); + draw_begin(layers_temp_image); draw_set_pipeline(pipes_copy); draw_image(l0.texpaint_nor, 0, 0); draw_set_pipeline(null); - g2_end(); + draw_end(); if (l1.paint_nor) { _iron_g4_begin(l0.texpaint_nor); @@ -781,11 +781,11 @@ function layers_merge_layer(l0 : slot_layer_t, l1: slot_layer_t, use_mask: bool } if (l0.texpaint_pack != null) { - g2_begin(layers_temp_image); + draw_begin(layers_temp_image); draw_set_pipeline(pipes_copy); draw_image(l0.texpaint_pack, 0, 0); draw_set_pipeline(null); - g2_end(); + draw_end(); if (l1.paint_occ || l1.paint_rough || l1.paint_met || l1.paint_height) { if (l1.paint_occ && l1.paint_rough && l1.paint_met && l1.paint_height) { diff --git a/base/sources/ts/project.ts b/base/sources/ts/project.ts index fd280128..960f4ef3 100644 --- a/base/sources/ts/project.ts +++ b/base/sources/ts/project.ts @@ -45,13 +45,13 @@ function project_open() { return; } - let current: iron_g5_texture_t = _g2_current; - let g2_in_use: bool = _g2_in_use; - if (g2_in_use) g2_end(); + let current: iron_g5_texture_t = _draw_current; + let g2_in_use: bool = _draw_in_use; + if (g2_in_use) draw_end(); import_arm_run_project(path); - if (g2_in_use) g2_begin(current); + if (g2_in_use) draw_begin(current); }); } @@ -226,9 +226,9 @@ function project_new(reset_layers: bool = true) { let n: string = context_raw.project_type == project_model_t.ROUNDED_CUBE ? ".Cube" : "Tessellated"; let md: mesh_data_t = data_get_mesh("Scene", n); - let current: iron_g5_texture_t = _g2_current; - let g2_in_use: bool = _g2_in_use; - if (g2_in_use) g2_end(); + let current: iron_g5_texture_t = _draw_current; + let g2_in_use: bool = _draw_in_use; + if (g2_in_use) draw_end(); ///if is_paint context_raw.picker_mask_handle.position = picker_mask_t.NONE; @@ -316,7 +316,7 @@ function project_new(reset_layers: bool = true) { app_notify_on_init(layers_init); } - if (g2_in_use) g2_begin(current); + if (g2_in_use) draw_begin(current); context_raw.saved_envmap = null; context_raw.envmap_loaded = false; diff --git a/base/sources/ts/slot_layer.ts b/base/sources/ts/slot_layer.ts index 771efb51..4332dbff 100644 --- a/base/sources/ts/slot_layer.ts +++ b/base/sources/ts/slot_layer.ts @@ -248,9 +248,9 @@ function slot_layer_clear(raw: slot_layer_t, base_color: i32 = 0x00000000, base_ iron_g5_clear(base_color); // Base _iron_g4_end(); if (base_image != null) { - g2_begin(raw.texpaint); + draw_begin(raw.texpaint); draw_scaled_image(base_image, 0, 0, raw.texpaint.width, raw.texpaint.height); - g2_end(); + draw_end(); } if (slot_layer_is_layer(raw)) { @@ -268,11 +268,11 @@ function slot_layer_clear(raw: slot_layer_t, base_color: i32 = 0x00000000, base_ function slot_layer_invert_mask(raw: slot_layer_t) { let inverted: iron_g5_texture_t = iron_g4_create_render_target(raw.texpaint.width, raw.texpaint.height, tex_format_t.RGBA32); - g2_begin(inverted); + draw_begin(inverted); draw_set_pipeline(pipes_invert8); draw_image(raw.texpaint, 0, 0); draw_set_pipeline(null); - g2_end(); + draw_end(); let _texpaint: iron_g5_texture_t = raw.texpaint; app_notify_on_next_frame(function (_texpaint: iron_g5_texture_t) { iron_unload_image(_texpaint); @@ -306,43 +306,43 @@ function slot_layer_duplicate(raw: slot_layer_t): slot_layer_t { array_insert(layers, i, l); if (slot_layer_is_layer(raw)) { - g2_begin(l.texpaint); + draw_begin(l.texpaint); draw_set_pipeline(pipes_copy); draw_image(raw.texpaint, 0, 0); draw_set_pipeline(null); - g2_end(); + draw_end(); if (l.texpaint_nor != null) { - g2_begin(l.texpaint_nor); + draw_begin(l.texpaint_nor); draw_set_pipeline(pipes_copy); draw_image(raw.texpaint_nor, 0, 0); draw_set_pipeline(null); - g2_end(); + draw_end(); } if (l.texpaint_pack != null) { - g2_begin(l.texpaint_pack); + draw_begin(l.texpaint_pack); draw_set_pipeline(pipes_copy); draw_image(raw.texpaint_pack, 0, 0); draw_set_pipeline(null); - g2_end(); + draw_end(); } } else if (slot_layer_is_mask(raw)) { - g2_begin(l.texpaint); + draw_begin(l.texpaint); draw_set_pipeline(pipes_copy8); draw_image(raw.texpaint, 0, 0); draw_set_pipeline(null); - g2_end(); + draw_end(); } if (l.texpaint_preview != null) { - g2_begin(l.texpaint_preview); + draw_begin(l.texpaint_preview); iron_g5_clear(0x00000000); draw_set_pipeline(pipes_copy); draw_scaled_image(raw.texpaint_preview, 0, 0, raw.texpaint_preview.width, raw.texpaint_preview.height); draw_set_pipeline(null); - g2_end(); + draw_end(); } l.visible = raw.visible; @@ -385,32 +385,32 @@ function slot_layer_resize_and_set_bits(raw: slot_layer_t) { let _texpaint: iron_g5_texture_t = raw.texpaint; raw.texpaint = iron_g4_create_render_target(res_x, res_y, format); - g2_begin(raw.texpaint); + draw_begin(raw.texpaint); draw_set_pipeline(pipes_copy); draw_scaled_image(_texpaint, 0, 0, res_x, res_y); draw_set_pipeline(null); - g2_end(); + draw_end(); let _texpaint_nor: iron_g5_texture_t = raw.texpaint_nor; if (raw.texpaint_nor != null) { raw.texpaint_nor = iron_g4_create_render_target(res_x, res_y, format); - g2_begin(raw.texpaint_nor); + draw_begin(raw.texpaint_nor); draw_set_pipeline(pipes_copy); draw_scaled_image(_texpaint_nor, 0, 0, res_x, res_y); draw_set_pipeline(null); - g2_end(); + draw_end(); } let _texpaint_pack: iron_g5_texture_t = raw.texpaint_pack; if (raw.texpaint_pack != null) { raw.texpaint_pack = iron_g4_create_render_target(res_x, res_y, format); - g2_begin(raw.texpaint_pack); + draw_begin(raw.texpaint_pack); draw_set_pipeline(pipes_copy); draw_scaled_image(_texpaint_pack, 0, 0, res_x, res_y); draw_set_pipeline(null); - g2_end(); + draw_end(); } app_notify_on_next_frame(function (_texpaint: iron_g5_texture_t) { @@ -446,11 +446,11 @@ function slot_layer_resize_and_set_bits(raw: slot_layer_t) { let _texpaint: iron_g5_texture_t = raw.texpaint; raw.texpaint = iron_g4_create_render_target(res_x, res_y, tex_format_t.RGBA32); - g2_begin(raw.texpaint); + draw_begin(raw.texpaint); draw_set_pipeline(pipes_copy8); draw_scaled_image(_texpaint, 0, 0, res_x, res_y); draw_set_pipeline(null); - g2_end(); + draw_end(); app_notify_on_next_frame(function (_texpaint: iron_g5_texture_t) { iron_unload_image(_texpaint); diff --git a/base/sources/ts/tab_layers.ts b/base/sources/ts/tab_layers.ts index 5f8083a8..4e1191b3 100644 --- a/base/sources/ts/tab_layers.ts +++ b/base/sources/ts/tab_layers.ts @@ -668,8 +668,8 @@ function tab_layers_draw_layer_icon(l: slot_layer_t, i: i32, uix: f32, uiy: f32, if (!is_typing) { if (i < 9 && operator_shortcut(map_get(config_keymap, "select_layer"), shortcut_type_t.DOWN)) { let number: string = i32_to_string(i + 1) ; - let width: i32 = g2_font_width(ui.ops.font, ui.font_size, number) + 10; - let height: i32 = g2_font_height(ui.ops.font, ui.font_size); + let width: i32 = draw_string_width(ui.ops.font, ui.font_size, number) + 10; + let height: i32 = draw_font_height(ui.ops.font, ui.font_size); draw_set_color(ui.ops.theme.TEXT_COL); draw_filled_rect(uix, uiy, width, height); draw_set_color(ui.ops.theme.BUTTON_COL); @@ -1006,11 +1006,11 @@ function tab_layers_make_mask_preview_rgba32(l: slot_layer_t) { tab_layers_l = l; app_notify_on_init(function () { let l: slot_layer_t = tab_layers_l; - g2_begin(context_raw.mask_preview_rgba32); + draw_begin(context_raw.mask_preview_rgba32); draw_set_pipeline(ui_view2d_pipe); _iron_g4_set_int(ui_view2d_channel_loc, 1); draw_image(l.texpaint_preview, 0, 0); - g2_end(); + draw_end(); draw_set_pipeline(null); }); } diff --git a/base/sources/ts/tab_materials.ts b/base/sources/ts/tab_materials.ts index 9a0f1ef7..d87869bc 100644 --- a/base/sources/ts/tab_materials.ts +++ b/base/sources/ts/tab_materials.ts @@ -116,8 +116,8 @@ function tab_materials_draw_slots(mini: bool) { if (!is_typing) { if (i < 9 && operator_shortcut(map_get(config_keymap, "select_material"), shortcut_type_t.DOWN)) { let number: string = i32_to_string(i + 1); - let width: i32 = g2_font_width(ui.ops.font, ui.font_size, number) + 10; - let height: i32 = g2_font_height(ui.ops.font, ui.font_size); + let width: i32 = draw_string_width(ui.ops.font, ui.font_size, number) + 10; + let height: i32 = draw_font_height(ui.ops.font, ui.font_size); draw_set_color(ui.ops.theme.TEXT_COL); draw_filled_rect(uix, uiy, width, height); draw_set_color(ui.ops.theme.BUTTON_COL); diff --git a/base/sources/ts/tab_textures.ts b/base/sources/ts/tab_textures.ts index 1a7f551f..d47b1827 100644 --- a/base/sources/ts/tab_textures.ts +++ b/base/sources/ts/tab_textures.ts @@ -142,11 +142,11 @@ function tab_textures_draw(htab: ui_handle_t) { app_notify_on_next_frame(function () { let img: iron_g5_texture_t = _tab_textures_draw_img; let target: iron_g5_texture_t = iron_g4_create_render_target(tab_textures_to_pow2(img.width), tab_textures_to_pow2(img.height)); - g2_begin(target); + draw_begin(target); draw_set_pipeline(pipes_copy); draw_scaled_image(img, 0, 0, target.width, target.height); draw_set_pipeline(null); - g2_end(); + draw_end(); app_notify_on_next_frame(function (target: iron_g5_texture_t) { let path: string = _tab_textures_draw_path; let f: string = ui_files_filename; diff --git a/base/sources/ts/translator.ts b/base/sources/ts/translator.ts index 7c04f087..31c7f8b8 100644 --- a/base/sources/ts/translator.ts +++ b/base/sources/ts/translator.ts @@ -99,12 +99,9 @@ function translator_load_translations(new_locale: string) { i += l; // Assume cjk in the > 1119 range - if (codepoint > 1119 && array_index_of(_g2_font_glyphs, codepoint) == -1) { - if (!cjk) { - _g2_font_glyphs = _g2_make_glyphs(32, 127); - cjk = true; - } - array_push(_g2_font_glyphs, codepoint); + if (codepoint > 1119 && !draw_font_has_glyph(codepoint)) { + cjk = true; + draw_font_add_glyph(codepoint); } } } @@ -146,8 +143,6 @@ function translator_load_translations(new_locale: string) { } function translator_init_font(cjk: bool, font_path: string, font_scale: f32) { - i32_array_sort(_g2_font_glyphs, null); - _translator_init_font_cjk = cjk; _translator_init_font_font_path = font_path; _translator_init_font_font_scale = font_scale; @@ -161,8 +156,11 @@ function translator_init_font(cjk: bool, font_path: string, font_scale: f32) { let f: draw_font_t = data_get_font(font_path); if (cjk) { - let font_index: i32 = map_get(translator_cjk_font_indices, config_raw.locale) != -1 ? map_get(translator_cjk_font_indices, config_raw.locale) : 0; - g2_font_set_font_index(f, font_index); + let font_index: i32 = map_get(translator_cjk_font_indices, config_raw.locale) != -1 ? + map_get(translator_cjk_font_indices, config_raw.locale) : 0; + f.index = font_index; + f.glyphs_version = 0; + draw_font_init(f); } base_font = f; // Scale up the font size and elements width a bit @@ -179,14 +177,14 @@ function translator_init_font(cjk: bool, font_path: string, font_scale: f32) { function translator_extended_glyphs() { // Basic Latin + Latin-1 Supplement + Latin Extended-A - _g2_font_glyphs = _g2_make_glyphs(32, 383); + draw_font_init_glyphs(32, 383); // + Greek for (let i: i32 = 880; i < 1023; ++i) { - array_push(_g2_font_glyphs, i); + draw_font_add_glyph(i); } // + Cyrillic for (let i: i32 = 1024; i < 1119; ++i) { - array_push(_g2_font_glyphs, i); + draw_font_add_glyph(i); } } diff --git a/base/sources/ts/ui_base.ts b/base/sources/ts/ui_base.ts index a7a6d53f..171fdc92 100644 --- a/base/sources/ts/ui_base.ts +++ b/base/sources/ts/ui_base.ts @@ -1088,13 +1088,13 @@ function ui_base_update_ui() { } let source: iron_g5_texture_t = l.texpaint; - g2_begin(target); + draw_begin(target); iron_g5_clear(0x00000000); // draw_set_pipeline(l.is_mask() ? pipes_copy8 : pipes_copy); draw_set_pipeline(pipes_copy); // texpaint_preview is always RGBA32 for now draw_scaled_image(source, 0, 0, target.width, target.height); draw_set_pipeline(null); - g2_end(); + draw_end(); } ui_base_hwnds[tab_area_t.SIDEBAR0].redraws = 2; } @@ -1108,13 +1108,13 @@ function ui_base_update_ui() { if (target != null) { let source: iron_g5_texture_t = l.texpaint; - g2_begin(target); + draw_begin(target); iron_g5_clear(0x00000000); // draw_set_pipeline(raw.layer.is_mask() ? pipes_copy8 : pipes_copy); draw_set_pipeline(pipes_copy); // texpaint_preview is always RGBA32 for now draw_scaled_image(source, 0, 0, target.width, target.height); draw_set_pipeline(null); - g2_end(); + draw_end(); ui_base_hwnds[tab_area_t.SIDEBAR0].redraws = 2; } } @@ -1156,7 +1156,7 @@ function ui_base_update_ui() { function ui_base_render() { if (!ui_base_show && config_raw.touch_ui) { ui_base_ui.input_enabled = true; - g2_end(); + draw_end(); ui_begin(ui_base_ui); if (ui_window(ui_handle(__ID__), 0, 0, 150, math_floor(ui_ELEMENT_H(ui_base_ui) + ui_ELEMENT_OFFSET(ui_base_ui) + 1))) { if (ui_button(tr("Close"))) { @@ -1164,7 +1164,7 @@ function ui_base_render() { } } ui_end(); - g2_begin(null); + draw_begin(null); } if (!ui_base_show || iron_window_width() == 0 || iron_window_height() == 0) { @@ -1186,7 +1186,7 @@ function ui_base_render() { ui_base_htabs[i].position = config_raw.layout_tabs[i]; } - g2_end(); + draw_end(); ui_begin(ui_base_ui); ///if (is_paint || is_sculpt) @@ -1201,7 +1201,7 @@ function ui_base_render() { ///end ui_end(); - g2_begin(null); + draw_begin(null); } function ui_base_draw_sidebar() { @@ -1252,7 +1252,7 @@ function ui_base_draw_sidebar() { // Expand button if (config_raw.layout[layout_size_t.SIDEBAR_W] == 0) { - let width: i32 = math_floor(g2_font_width(ui_base_ui.ops.font, ui_base_ui.font_size, "<<") + 25 * ui_SCALE(ui_base_ui)); + let width: i32 = math_floor(draw_string_width(ui_base_ui.ops.font, ui_base_ui.font_size, "<<") + 25 * ui_SCALE(ui_base_ui)); if (ui_window(ui_base_hminimized, iron_window_width() - width, 0, width, math_floor(ui_ELEMENT_H(ui_base_ui) + ui_ELEMENT_OFFSET(ui_base_ui) + 1))) { ui_base_ui._w = width; let _BUTTON_H: i32 = ui_base_ui.ops.theme.BUTTON_H; @@ -1312,9 +1312,9 @@ function ui_base_render_cursor() { let angle: f32 = context_raw.brush_stencil_angle; let cx: f32 = r.x + r.w / 2; let cy: f32 = r.y + r.h / 2; - g2_set_transformation(mat3_multmat(mat3_multmat(mat3_translation(cx, cy), mat3_rotation(-angle)), mat3_translation(-cx, -cy))); + draw_set_transform(mat3_multmat(mat3_multmat(mat3_translation(cx, cy), mat3_rotation(-angle)), mat3_translation(-cx, -cy))); draw_scaled_image(context_raw.brush_stencil_image, r.x, r.y, r.w, r.h); - g2_set_transformation(mat3_nan()); + draw_set_transform(mat3_nan()); draw_set_color(0xffffffff); } let transform: bool = operator_shortcut(map_get(config_keymap, "stencil_transform"), shortcut_type_t.DOWN); @@ -1330,9 +1330,9 @@ function ui_base_render_cursor() { let angle: f32 = context_raw.brush_stencil_angle; let cx: f32 = r.x + r.w / 2; let cy: f32 = r.y + r.h / 2; - g2_set_transformation(mat3_multmat(mat3_multmat(mat3_translation(cx, cy), mat3_rotation(-angle)), mat3_translation(-cx, -cy))); + draw_set_transform(mat3_multmat(mat3_multmat(mat3_translation(cx, cy), mat3_rotation(-angle)), mat3_translation(-cx, -cy))); draw_filled_circle(r.x + r.w / 2, r.y - 4, 8); - g2_set_transformation(mat3_nan()); + draw_set_transform(mat3_nan()); } } @@ -1388,9 +1388,9 @@ function ui_base_render_cursor() { let angle: f32 = (context_raw.brush_angle + context_raw.brush_nodes_angle) * (math_pi() / 180); let cx: f32 = decalx + psizex / 2; let cy: f32 = decaly + psizey / 2; - g2_set_transformation(mat3_multmat(mat3_multmat(mat3_translation(cx, cy), mat3_rotation(angle)), mat3_translation(-cx, -cy))); + draw_set_transform(mat3_multmat(mat3_multmat(mat3_translation(cx, cy), mat3_rotation(angle)), mat3_translation(-cx, -cy))); draw_scaled_image(context_raw.decal_image, decalx, decaly, psizex, psizey); - g2_set_transformation(mat3_nan()); + draw_set_transform(mat3_nan()); draw_set_color(0xffffffff); } } diff --git a/base/sources/ts/ui_box.ts b/base/sources/ts/ui_box.ts index 94d745de..fe2cf4dd 100644 --- a/base/sources/ts/ui_box.ts +++ b/base/sources/ts/ui_box.ts @@ -53,7 +53,7 @@ function ui_box_render() { draw_filled_rect(0, 0, iron_window_width(), iron_window_height()); } - g2_end(); + draw_end(); let ui: ui_t = base_ui_box; let appw: i32 = iron_window_width(); @@ -123,7 +123,7 @@ function ui_box_render() { ui_end(); } - g2_begin(null); + draw_begin(null); ui_box_draws++; } diff --git a/base/sources/ts/ui_files.ts b/base/sources/ts/ui_files.ts index 0ca5f892..4e5b3cd0 100644 --- a/base/sources/ts/ui_files.ts +++ b/base/sources/ts/ui_files.ts @@ -207,20 +207,20 @@ function ui_files_file_browser(ui: ui_t, handle: ui_handle_t, drag_files: bool = app_notify_on_init(function (data: draw_cloud_icon_data_t) { let icon: iron_g5_texture_t = iron_g4_create_render_target(data.image.width, data.image.height); if (ends_with(data.f, ".arm")) { // Used for material sphere alpha cutout - g2_begin(icon); + draw_begin(icon); ///if (is_paint || is_sculpt) draw_image(project_materials[0].image, 0, 0); ///end } else { - g2_begin(icon); + draw_begin(icon); iron_g5_clear(0xffffffff); } draw_set_pipeline(pipes_copy_rgb); draw_image(data.image, 0, 0); draw_set_pipeline(null); - g2_end(); + draw_end(); map_set(ui_files_icon_map, _ui_files_file_browser_handle.text + path_sep + data.f, icon); ui_base_hwnds[tab_area_t.STATUS].redraws = 3; @@ -389,7 +389,7 @@ function ui_files_file_browser(ui: ui_t, handle: ui_handle_t, drag_files: bool = ui._y += slotw * 0.75; let label0: string = (ui_files_show_extensions || string_index_of(f, ".") <= 0) ? f : substring(f, 0, string_last_index_of(f, ".")); let label1: string = ""; - while (label0.length > 0 && g2_font_width(ui.ops.font, ui.font_size, label0) > ui._w - 6) { // 2 line split + while (label0.length > 0 && draw_string_width(ui.ops.font, ui.font_size, label0) > ui._w - 6) { // 2 line split label1 = char_at(label0, label0.length - 1) + label1; label0 = substring(label0, 0, label0.length - 1); } @@ -402,12 +402,12 @@ function ui_files_file_browser(ui: ui_t, handle: ui_handle_t, drag_files: bool = } if (label1 != "") { // Second line ui._x = _x; - ui._y += g2_font_height(ui.ops.font, ui.font_size); + ui._y += draw_font_height(ui.ops.font, ui.font_size); ui_text(label1, ui_align_t.CENTER); if (ui.is_hovered) { ui_tooltip(label0 + label1); } - ui._y -= g2_font_height(ui.ops.font, ui.font_size); + ui._y -= draw_font_height(ui.ops.font, ui.font_size); } ui._y -= slotw * 0.75; @@ -432,12 +432,12 @@ function ui_files_make_icon (args: ui_files_make_icon_t) { let sw: i32 = image.width > image.height ? w : math_floor(1.0 * image.width / image.height * w); let sh: i32 = image.width > image.height ? math_floor(1.0 * image.height / image.width * w) : w; let icon: iron_g5_texture_t = iron_g4_create_render_target(sw, sh); - g2_begin(icon); + draw_begin(icon); iron_g5_clear(0xffffffff); draw_set_pipeline(pipes_copy_rgb); draw_scaled_image(image, 0, 0, sw, sh); draw_set_pipeline(null); - g2_end(); + draw_end(); map_set(ui_files_icon_map, args.shandle, icon); ui_base_hwnds[tab_area_t.STATUS].redraws = 3; data_delete_image(args.shandle); // The big image is not needed anymore diff --git a/base/sources/ts/ui_menu.ts b/base/sources/ts/ui_menu.ts index f6a43af9..0a9c67b3 100644 --- a/base/sources/ts/ui_menu.ts +++ b/base/sources/ts/ui_menu.ts @@ -243,10 +243,10 @@ function ui_menu_render() { ///if (is_paint || is_sculpt) context_raw.draw_wireframe = ui_check(context_raw.wireframe_handle, " " + tr("Wireframe")); if (context_raw.wireframe_handle.changed) { - let current: iron_g5_texture_t = _g2_current; - g2_end(); + let current: iron_g5_texture_t = _draw_current; + draw_end(); util_uv_cache_uv_map(); - g2_begin(current); + draw_begin(current); make_material_parse_mesh_material(); } ///end diff --git a/base/sources/ts/ui_nodes.ts b/base/sources/ts/ui_nodes.ts index d51ca4c4..41a68305 100644 --- a/base/sources/ts/ui_nodes.ts +++ b/base/sources/ts/ui_nodes.ts @@ -737,7 +737,7 @@ function ui_nodes_draw_grid(zoom: f32): iron_g5_texture_t { } let grid: iron_g5_texture_t = iron_g4_create_render_target(w, h); - g2_begin(grid); + draw_begin(grid); iron_g5_clear(ui_nodes_ui.ops.theme.SEPARATOR_COL); let sep_col: i32 = ui_nodes_ui.ops.theme.SEPARATOR_COL; @@ -769,7 +769,7 @@ function ui_nodes_draw_grid(zoom: f32): iron_g5_texture_t { draw_line(i * step, 0, i * step, h); } - g2_end(); + draw_end(); return grid; } @@ -864,7 +864,7 @@ function ui_nodes_render() { ui_nodes_ui.input_enabled = base_ui_enabled; - g2_end(); + draw_end(); if (ui_nodes_grid_redraw) { if (ui_nodes_grid != null) { @@ -1137,7 +1137,7 @@ function ui_nodes_render() { // Editable canvas name let h: ui_handle_t = ui_handle(__ID__); h.text = c.name; - ui_nodes_ui._w = math_floor(math_min(g2_font_width(ui_nodes_ui.ops.font, ui_nodes_ui.font_size, h.text) + 15 * ui_SCALE(ui_nodes_ui), 100 * ui_SCALE(ui_nodes_ui))); + ui_nodes_ui._w = math_floor(math_min(draw_string_width(ui_nodes_ui.ops.font, ui_nodes_ui.font_size, h.text) + 15 * ui_SCALE(ui_nodes_ui), 100 * ui_SCALE(ui_nodes_ui))); let new_name: string = ui_text_input(h, ""); ui_nodes_ui._x += ui_nodes_ui._w + 3; ui_nodes_ui._y = 2 + start_y; @@ -1249,7 +1249,7 @@ function ui_nodes_render() { ui_end(!ui_nodes_show_menu); - g2_begin(null); + draw_begin(null); if (ui_nodes_show_menu) { ///if (is_paint || is_sculpt) diff --git a/base/sources/ts/ui_toolbar.ts b/base/sources/ts/ui_toolbar.ts index b6c1e45d..b9497230 100644 --- a/base/sources/ts/ui_toolbar.ts +++ b/base/sources/ts/ui_toolbar.ts @@ -130,7 +130,7 @@ function ui_toolbar_render_ui() { ui.ops.theme.ELEMENT_H = math_floor(ui.ops.theme.ELEMENT_H * 1.5); ui.ops.theme.BUTTON_H = ui.ops.theme.ELEMENT_H; ui.ops.theme.BUTTON_COL = ui.ops.theme.WINDOW_BG_COL; - let font_height: i32 = g2_font_height(ui.ops.font, ui.font_size); + let font_height: i32 = draw_font_height(ui.ops.font, ui.font_size); ui.font_offset_y = (ui_ELEMENT_H(ui) - font_height) / 2; let _w: i32 = ui._w; ui._w = ui_toolbar_w; diff --git a/base/sources/ts/ui_view2d.ts b/base/sources/ts/ui_view2d.ts index 70c528c8..4698aed8 100644 --- a/base/sources/ts/ui_view2d.ts +++ b/base/sources/ts/ui_view2d.ts @@ -89,7 +89,7 @@ function ui_view2d_render() { ui_view2d_hwnd.redraws = 2; // Paint was active } - g2_end(); + draw_end(); // Cache grid if (ui_view2d_grid_redraw) { @@ -177,18 +177,18 @@ function ui_view2d_render() { } if (ui_view2d_layer_mode == view_2d_layer_mode_t.VISIBLE) { - let current: iron_g5_texture_t = _g2_current; - let g2_in_use: bool = _g2_in_use; - if (g2_in_use) g2_end(); + let current: iron_g5_texture_t = _draw_current; + let g2_in_use: bool = _draw_in_use; + if (g2_in_use) draw_end(); layer = layers_flatten(); - if (g2_in_use) g2_begin(current); + if (g2_in_use) draw_begin(current); } else if (slot_layer_is_group(layer)) { - let current: iron_g5_texture_t = _g2_current; - let g2_in_use: bool = _g2_in_use; - if (g2_in_use) g2_end(); + let current: iron_g5_texture_t = _draw_current; + let g2_in_use: bool = _draw_in_use; + if (g2_in_use) draw_end(); layer = layers_flatten(false, slot_layer_get_children(layer)); - if (g2_in_use) g2_begin(current); + if (g2_in_use) draw_begin(current); } tex = @@ -259,9 +259,9 @@ function ui_view2d_render() { app_notify_on_next_frame(function () { let rt: render_target_t = map_get(render_path_render_targets, "texpaint_picker"); let texpaint_picker: iron_g5_texture_t = rt._image; - g2_begin(texpaint_picker); + draw_begin(texpaint_picker); draw_scaled_image(_ui_view2d_render_tex, -_ui_view2d_render_x, -_ui_view2d_render_y, _ui_view2d_render_tw, _ui_view2d_render_th); - g2_end(); + draw_end(); let a: buffer_t = iron_g4_get_texture_pixels(texpaint_picker); ///if (arm_metal || arm_vulkan) let i0: i32 = 2; @@ -309,7 +309,7 @@ function ui_view2d_render() { let text: string = h.text; ///end - ui_view2d_ui._w = math_floor(math_min(g2_font_width(ui_view2d_ui.ops.font, ui_view2d_ui.font_size, text) + 15 * ui_SCALE(ui_view2d_ui), 100 * ui_SCALE(ui_view2d_ui))); + ui_view2d_ui._w = math_floor(math_min(draw_string_width(ui_view2d_ui.ops.font, ui_view2d_ui.font_size, text) + 15 * ui_SCALE(ui_view2d_ui), 100 * ui_SCALE(ui_view2d_ui))); if (ui_view2d_type == view_2d_type_t.ASSET) { let asset: asset_t = context_raw.texture; @@ -418,7 +418,7 @@ function ui_view2d_render() { ///end } ui_end(); - g2_begin(null); + draw_begin(null); } function ui_view2d_update() { diff --git a/base/sources/ts/util_render.ts b/base/sources/ts/util_render.ts index 80b5be47..c289b420 100644 --- a/base/sources/ts/util_render.ts +++ b/base/sources/ts/util_render.ts @@ -79,9 +79,9 @@ function util_render_make_material_preview() { } function util_render_make_decal_preview() { - let current: iron_g5_texture_t = _g2_current; - let g2_in_use: bool = _g2_in_use; - if (g2_in_use) g2_end(); + let current: iron_g5_texture_t = _draw_current; + let g2_in_use: bool = _draw_in_use; + if (g2_in_use) draw_end(); if (context_raw.decal_image == null) { context_raw.decal_image = iron_g4_create_render_target(util_render_decal_preview_size, util_render_decal_preview_size); @@ -139,19 +139,19 @@ function util_render_make_decal_preview() { make_material_parse_mesh_material(); context_raw.ddirty = 1; // Refresh depth for decal paint - if (g2_in_use) g2_begin(current); + if (g2_in_use) draw_begin(current); } function util_render_make_text_preview() { - let current: iron_g5_texture_t = _g2_current; - let g2_in_use: bool = _g2_in_use; - if (g2_in_use) g2_end(); + let current: iron_g5_texture_t = _draw_current; + let g2_in_use: bool = _draw_in_use; + if (g2_in_use) draw_end(); let text: string = context_raw.text_tool_text; let font: draw_font_t = context_raw.font.font; let font_size: i32 = util_render_font_preview_size; - let text_w: i32 = math_floor(g2_font_width(font, font_size, text)); - let text_h: i32 = math_floor(g2_font_height(font, font_size)); + let text_w: i32 = math_floor(draw_string_width(font, font_size, text)); + let text_h: i32 = math_floor(draw_font_height(font, font_size)); let tex_w: i32 = text_w + 32; if (tex_w < 512) { tex_w = 512; @@ -167,39 +167,39 @@ function util_render_make_text_preview() { context_raw.text_tool_image = iron_g4_create_render_target(tex_w, tex_w, tex_format_t.R8); ///end } - g2_begin(context_raw.text_tool_image); + draw_begin(context_raw.text_tool_image); iron_g5_clear(0xff000000); - g2_set_font(font, font_size); + draw_set_font(font, font_size); draw_set_color(0xffffffff); draw_string(text, tex_w / 2 - text_w / 2, tex_w / 2 - text_h / 2); - g2_end(); + draw_end(); - if (g2_in_use) g2_begin(current); + if (g2_in_use) draw_begin(current); } function util_render_make_font_preview() { - let current: iron_g5_texture_t = _g2_current; - let g2_in_use: bool = _g2_in_use; - if (g2_in_use) g2_end(); + let current: iron_g5_texture_t = _draw_current; + let g2_in_use: bool = _draw_in_use; + if (g2_in_use) draw_end(); let text: string = "Abg"; let font: draw_font_t = context_raw.font.font; let font_size: i32 = util_render_font_preview_size; - let text_w: i32 = math_floor(g2_font_width(font, font_size, text)) + 8; - let text_h: i32 = math_floor(g2_font_height(font, font_size)) + 8; + let text_w: i32 = math_floor(draw_string_width(font, font_size, text)) + 8; + let text_h: i32 = math_floor(draw_font_height(font, font_size)) + 8; let tex_w: i32 = text_w + 32; if (context_raw.font.image == null) { context_raw.font.image = iron_g4_create_render_target(tex_w, tex_w, tex_format_t.RGBA32); } - g2_begin(context_raw.font.image); + draw_begin(context_raw.font.image); iron_g5_clear(0x00000000); - g2_set_font(font, font_size); + draw_set_font(font, font_size); draw_set_color(0xffffffff); draw_string(text, tex_w / 2 - text_w / 2, tex_w / 2 - text_h / 2); - g2_end(); + draw_end(); context_raw.font.preview_ready = true; - if (g2_in_use) g2_begin(current); + if (g2_in_use) draw_begin(current); } function util_render_make_brush_preview() { @@ -207,9 +207,9 @@ function util_render_make_brush_preview() { return; } - let current: iron_g5_texture_t = _g2_current; - let g2_in_use: bool = _g2_in_use; - if (g2_in_use) g2_end(); + let current: iron_g5_texture_t = _draw_current; + let g2_in_use: bool = _draw_in_use; + if (g2_in_use) draw_end(); context_raw.material_preview = true; @@ -366,12 +366,12 @@ function util_render_make_brush_preview() { // Scale layer down to to image preview l = render_path_paint_live_layer; let target: iron_g5_texture_t = context_raw.brush.image; - g2_begin(target); + draw_begin(target); iron_g5_clear(0x00000000); draw_set_pipeline(pipes_copy); draw_scaled_image(l.texpaint, 0, 0, target.width, target.height); draw_set_pipeline(null); - g2_end(); + draw_end(); // Scale image preview down to to icon let texpreview: render_target_t = map_get(render_path_render_targets, "texpreview"); @@ -385,7 +385,7 @@ function util_render_make_brush_preview() { context_raw.brush.preview_ready = true; context_raw.brush_blend_dirty = true; - if (g2_in_use) g2_begin(current); + if (g2_in_use) draw_begin(current); } function util_render_make_node_preview(canvas: ui_node_canvas_t, node: ui_node_t, image: iron_g5_texture_t, group: ui_node_canvas_t = null, parents: ui_node_t[] = null) { diff --git a/base/sources/ts/util_uv.ts b/base/sources/ts/util_uv.ts index 8d2e388d..fa90dd49 100644 --- a/base/sources/ts/util_uv.ts +++ b/base/sources/ts/util_uv.ts @@ -34,7 +34,7 @@ function util_uv_cache_uv_map() { let texa: i16_array_t = mesh.vertex_arrays[2].values; let inda: u32_array_t = mesh.index_arrays[0].values; - g2_begin(util_uv_uvmap); + draw_begin(util_uv_uvmap); iron_g5_clear(0x00000000); draw_set_color(0xffffffff); let strength: f32 = res_x > 2048 ? 2.0 : 1.0; @@ -50,7 +50,7 @@ function util_uv_cache_uv_map() { draw_line_aa(x2, y2, x3, y3, strength); draw_line_aa(x3, y3, x1, y1, strength); } - g2_end(); + draw_end(); } function util_uv_cache_triangle_map() { @@ -73,7 +73,7 @@ function util_uv_cache_triangle_map() { let mesh: mesh_data_t = merged; let texa: i16_array_t = mesh.vertex_arrays[2].values; let inda: u32_array_t = mesh.index_arrays[0].values; - g2_begin(util_uv_trianglemap); + draw_begin(util_uv_trianglemap); iron_g5_clear(0xff000000); let f: f32 = (1 / 32767) * util_uv_trianglemap.width; let color: i32 = 0xff000001; @@ -89,7 +89,7 @@ function util_uv_cache_triangle_map() { let y3: f32 = (texa[inda[i * 3 + 2] * 2 + 1]) * f; draw_filled_triangle(x1, y1, x2, y2, x3, y3); } - g2_end(); + draw_end(); } function util_uv_cache_dilate_map() { diff --git a/base/tools/pad/sources/main.ts b/base/tools/pad/sources/main.ts index af69ee59..a1d0a9f9 100644 --- a/base/tools/pad/sources/main.ts +++ b/base/tools/pad/sources/main.ts @@ -92,7 +92,7 @@ function main() { sys_start(ops); let font: draw_font_t = data_get_font("font_mono.ttf"); - g2_font_init(font); + draw_font_init(font); theme = {}; ui_theme_default(theme); @@ -267,9 +267,9 @@ function render() { } if (minimap != null) { - g2_begin(); + draw_begin(); draw_image(minimap, minimap_x, minimap_y); - g2_end(); + draw_end(); } if (editor_updated) { @@ -320,7 +320,7 @@ function draw_minimap() { minimap = iron_g4_create_render_target(minimap_w, minimap_h); } - g2_begin(minimap); + draw_begin(minimap); iron_g5_clear(theme.SEPARATOR_COL); draw_set_color(0xff333333); let lines: string[] = string_split(storage.text, "\n"); @@ -351,7 +351,7 @@ function draw_minimap() { draw_set_color(0x11ffffff); minimap_box_h = math_floor((iron_window_height() - window_header_h) / UI_ELEMENT_H() * 2); draw_filled_rect(0, scroll_progress * visible_area, minimap_w, minimap_box_h); - g2_end(); + draw_end(); } function hit_test(mx: f32, my: f32, x: f32, y: f32, w: f32, h: f32): bool {