diff --git a/armorforge/sources/tab_object.ts b/armorforge/sources/tab_object.ts index d645f0b4..db573b29 100644 --- a/armorforge/sources/tab_object.ts +++ b/armorforge/sources/tab_object.ts @@ -179,9 +179,9 @@ function tab_object_draw(htab: ui_handle_t) { let hscript: ui_handle_t = ui_handle(__ID__); hscript.text = script; - let _font: g2_font_t = ui.ops.font; + let _font: draw_font_t = ui.ops.font; let _font_size: i32 = ui.font_size; - let fmono: g2_font_t = data_get_font("font_mono.ttf"); + let fmono: draw_font_t = data_get_font("font_mono.ttf"); ui_set_font(ui, fmono); ui.font_size = math_floor(15 * ui_SCALE(ui)); ui_text_area_coloring = tab_script_get_text_coloring(); diff --git a/armorforge/sources/tab_scene.ts b/armorforge/sources/tab_scene.ts index ee157c95..037617a9 100644 --- a/armorforge/sources/tab_scene.ts +++ b/armorforge/sources/tab_scene.ts @@ -57,14 +57,14 @@ function tab_scene_draw_list(ui: ui_t, list_handle: ui_handle_t, current_object: // Highlight every other line if (tab_scene_line_counter % 2 == 0) { draw_set_color(ui.ops.theme.SEPARATOR_COL); - g2_fill_rect(0, ui._y, ui._window_w, ui_ELEMENT_H(ui)); + draw_filled_rect(0, ui._y, ui._window_w, ui_ELEMENT_H(ui)); draw_set_color(0xffffffff); } // Highlight selected line if (current_object == context_raw.selected_object) { draw_set_color(0xff205d9c); - g2_fill_rect(0, ui._y, ui._window_w, ui_ELEMENT_H(ui)); + draw_filled_rect(0, ui._y, ui._window_w, ui_ELEMENT_H(ui)); draw_set_color(0xffffffff); } @@ -83,7 +83,7 @@ function tab_scene_draw_list(ui: ui_t, list_handle: ui_handle_t, current_object: // Draw line that shows parent relations draw_set_color(ui.ops.theme.BUTTON_COL); - g2_draw_line(ui._x - 10, ui._y + ui_ELEMENT_H(ui) / 2, ui._x, ui._y + ui_ELEMENT_H(ui) / 2); + draw_line(ui._x - 10, ui._y + ui_ELEMENT_H(ui) / 2, ui._x, ui._y + ui_ELEMENT_H(ui) / 2); draw_set_color(0xffffffff); ui_text(current_object.name); @@ -122,7 +122,7 @@ function tab_scene_draw_list(ui: ui_t, list_handle: ui_handle_t, current_object: // Draw line that shows parent relations draw_set_color(ui.ops.theme.BUTTON_COL); - g2_draw_line(ui._x + 14, current_y, ui._x + 14, ui._y - ui_ELEMENT_H(ui) / 2); + draw_line(ui._x + 14, current_y, ui._x + 14, ui._y - ui_ELEMENT_H(ui) / 2); draw_set_color(0xffffffff); } } diff --git a/armorlab/sources/nodes/inpaint_node.ts b/armorlab/sources/nodes/inpaint_node.ts index 3362d409..f5e376b9 100644 --- a/armorlab/sources/nodes/inpaint_node.ts +++ b/armorlab/sources/nodes/inpaint_node.ts @@ -93,7 +93,7 @@ function inpaint_node_get_cached_image(self: inpaint_node_t): kinc_g5_texture_t iron_g4_set_texture(pipes_texa_inpaint_preview, inpaint_node_mask); kinc_g4_set_vertex_buffer(const_data_screen_aligned_vb); kinc_g4_set_index_buffer(const_data_screen_aligned_ib); - g4_draw(); + iron_g4_draw_indexed_vertices(); iron_g4_end(); }, self); return inpaint_node_image; @@ -112,7 +112,7 @@ function inpaint_node_texsynth_inpaint(image: kinc_g5_texture_t, tiling: bool, m let bytes_out: buffer_t = buffer_create(w * h * 4); texsynth_inpaint(w, h, bytes_out.buffer, bytes_img.buffer, bytes_mask.buffer, tiling); - inpaint_node_result = image_from_bytes(bytes_out, w, h); + inpaint_node_result = iron_g4_create_texture_from_bytes(bytes_out, w, h); return inpaint_node_result; } diff --git a/armorlab/sources/nodes/photo_to_pbr_node.ts b/armorlab/sources/nodes/photo_to_pbr_node.ts index 5472ebb0..b146ddbb 100644 --- a/armorlab/sources/nodes/photo_to_pbr_node.ts +++ b/armorlab/sources/nodes/photo_to_pbr_node.ts @@ -153,7 +153,7 @@ function photo_to_pbr_node_get_as_image(self: photo_to_pbr_node_t, from: i32): k } ///end - let temp2: kinc_g5_texture_t = image_from_bytes(u8a, photo_to_pbr_node_tile_w, photo_to_pbr_node_tile_w); + let temp2: kinc_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_image(temp2, x * photo_to_pbr_node_tile_w, y * photo_to_pbr_node_tile_w); g2_end(); diff --git a/armorlab/sources/nodes/rgb_node.ts b/armorlab/sources/nodes/rgb_node.ts index b0bdf3ab..ed3811ed 100644 --- a/armorlab/sources/nodes/rgb_node.ts +++ b/armorlab/sources/nodes/rgb_node.ts @@ -29,7 +29,7 @@ function rgb_node_get_as_image(self: rgb_node_t, from: i32): kinc_g5_texture_t { f32a[2] = default_value[2]; f32a[3] = default_value[3]; let buf: buffer_t = buffer_create_from_raw(f32a.buffer, f32a.length * 4); - self.image = image_from_bytes(buf, 1, 1, tex_format_t.RGBA128); + self.image = iron_g4_create_texture_from_bytes(buf, 1, 1, tex_format_t.RGBA128); return self.image; } diff --git a/armorlab/sources/nodes/text_to_photo_node.ts b/armorlab/sources/nodes/text_to_photo_node.ts index 6b8f1388..d4438140 100644 --- a/armorlab/sources/nodes/text_to_photo_node.ts +++ b/armorlab/sources/nodes/text_to_photo_node.ts @@ -267,7 +267,7 @@ function text_to_photo_node_vae_decoder(latents: f32_array_t, upscale: bool): ki u8a[i * 4 + 2] = math_floor(pyimage[i + 512 * 512 * 2] * 255); u8a[i * 4 + 3] = 255; } - let image: kinc_g5_texture_t = image_from_bytes(u8a, 512, 512); + let image: kinc_g5_texture_t = iron_g4_create_texture_from_bytes(u8a, 512, 512); if (text_to_photo_node_tiling) { tiling_node_prompt = text_to_photo_node_prompt; diff --git a/armorlab/sources/nodes/tiling_node.ts b/armorlab/sources/nodes/tiling_node.ts index 760c99be..e6d137e6 100644 --- a/armorlab/sources/nodes/tiling_node.ts +++ b/armorlab/sources/nodes/tiling_node.ts @@ -92,7 +92,7 @@ function tiling_node_sd_tiling(image: kinc_g5_texture_t, seed: i32): kinc_g5_tex // u8a[y * 512 + x] = 0; // } // } - let mask: kinc_g5_texture_t = image_from_bytes(u8a, 512, 512, tex_format_t.R8); + let mask: kinc_g5_texture_t = iron_g4_create_texture_from_bytes(u8a, 512, 512, tex_format_t.R8); inpaint_node_prompt = tiling_node_prompt; inpaint_node_strength = tiling_node_strength; diff --git a/armorlab/sources/nodes/upscale_node.ts b/armorlab/sources/nodes/upscale_node.ts index b3ba5423..496e5f02 100644 --- a/armorlab/sources/nodes/upscale_node.ts +++ b/armorlab/sources/nodes/upscale_node.ts @@ -87,7 +87,7 @@ function upscale_node_do_tile(source: kinc_g5_texture_t): kinc_g5_texture_t { u8a[i * 4 + 3] = 255; } - result = image_from_bytes(u8a, size2w, size2h); + result = iron_g4_create_texture_from_bytes(u8a, size2w, size2h); return result; } diff --git a/armorlab/sources/render_path_paint.ts b/armorlab/sources/render_path_paint.ts index 7b7098a1..3e94757c 100644 --- a/armorlab/sources/render_path_paint.ts +++ b/armorlab/sources/render_path_paint.ts @@ -213,7 +213,7 @@ function render_path_paint_draw_cursor(mx: f32, my: f32, radius: f32, tint_r: f3 kinc_g4_set_vertex_buffer(geom._.vertex_buffer); ///end kinc_g4_set_index_buffer(geom._.index_buffers[0]); - g4_draw(); + iron_g4_draw_indexed_vertices(); kinc_g4_disable_scissor(); render_path_end(); diff --git a/armorlab/sources/ui_nodes_ext.ts b/armorlab/sources/ui_nodes_ext.ts index cffe466a..659659fd 100644 --- a/armorlab/sources/ui_nodes_ext.ts +++ b/armorlab/sources/ui_nodes_ext.ts @@ -83,7 +83,7 @@ function ui_nodes_ext_run() { iron_g4_set_texture(pipes_copy_a_tex, texheight); kinc_g4_set_vertex_buffer(const_data_screen_aligned_vb); kinc_g4_set_index_buffer(const_data_screen_aligned_ib); - g4_draw(); + iron_g4_draw_indexed_vertices(); iron_g4_end(); let is_float_node: bool = context_raw.brush_output_node_inst.base.inputs[channel_type_t.HEIGHT].node.base.get == float_node_get; diff --git a/armorpaint/plugins/io_svg/nanosvg.c b/armorpaint/plugins/io_svg/nanosvg.c index 0ed48f5c..eb3afa21 100644 --- a/armorpaint/plugins/io_svg/nanosvg.c +++ b/armorpaint/plugins/io_svg/nanosvg.c @@ -9,7 +9,7 @@ #include "nanosvgrast.h" #include "iron_array.h" -void *image_from_bytes(void *buffer, int width, int height, int format); +void *iron_g4_create_texture_from_bytes(void *buffer, int width, int height, int format); void *io_svg_parse(char *buf) { NSVGimage *image = nsvgParse(buf, "px", 96.0f); @@ -24,5 +24,5 @@ void *io_svg_parse(char *buf) { buffer_t *b = malloc(sizeof(buffer_t)); b->buffer = pixels; b->length = b->capacity = w * h * 4; - return image_from_bytes(b, w, h, 0); + return iron_g4_create_texture_from_bytes(b, w, h, 0); } diff --git a/armorpaint/sources/layers_ext.ts b/armorpaint/sources/layers_ext.ts index e8c21e58..48f8a6c4 100644 --- a/armorpaint/sources/layers_ext.ts +++ b/armorpaint/sources/layers_ext.ts @@ -74,7 +74,7 @@ function layers_ext_flatten(height_to_normal: bool = false, layers: slot_layer_t iron_g4_set_int(pipes_blending, layers.length > 1 ? l1.blending : 0); kinc_g4_set_vertex_buffer(const_data_screen_aligned_vb); kinc_g4_set_index_buffer(const_data_screen_aligned_ib); - g4_draw(); + iron_g4_draw_indexed_vertices(); iron_g4_end(); ///end } @@ -96,7 +96,7 @@ function layers_ext_flatten(height_to_normal: bool = false, layers: slot_layer_t iron_g4_set_int(pipes_blending, l1.paint_nor_blend ? -2 : -1); kinc_g4_set_vertex_buffer(const_data_screen_aligned_vb); kinc_g4_set_index_buffer(const_data_screen_aligned_ib); - g4_draw(); + iron_g4_draw_indexed_vertices(); iron_g4_end(); } @@ -159,7 +159,7 @@ function layers_ext_flatten(height_to_normal: bool = false, layers: slot_layer_t iron_g4_set_int(pipes_blending, -4); kinc_g4_set_vertex_buffer(const_data_screen_aligned_vb); kinc_g4_set_index_buffer(const_data_screen_aligned_ib); - g4_draw(); + iron_g4_draw_indexed_vertices(); iron_g4_end(); } diff --git a/armorpaint/sources/render_path_paint.ts b/armorpaint/sources/render_path_paint.ts index 0474ebdd..c1444632 100644 --- a/armorpaint/sources/render_path_paint.ts +++ b/armorpaint/sources/render_path_paint.ts @@ -465,7 +465,7 @@ function render_path_paint_draw_cursor(mx: f32, my: f32, radius: f32, tint_r: f3 kinc_g4_set_vertex_buffer(geom._.vertex_buffer); ///end kinc_g4_set_index_buffer(geom._.index_buffers[0]); - g4_draw(); + iron_g4_draw_indexed_vertices(); kinc_g4_disable_scissor(); render_path_end(); diff --git a/armorpaint/sources/ui_header_ext.ts b/armorpaint/sources/ui_header_ext.ts index 8041f732..1620c049 100644 --- a/armorpaint/sources/ui_header_ext.ts +++ b/armorpaint/sources/ui_header_ext.ts @@ -59,7 +59,7 @@ function ui_header_draw_tool_properties(ui: ui_t) { iron_g4_set_texture(pipes_tex_colorid, project_get_image(project_assets[context_raw.colorid_handle.position])); kinc_g4_set_vertex_buffer(const_data_screen_aligned_vb); kinc_g4_set_index_buffer(const_data_screen_aligned_ib); - g4_draw(); + iron_g4_draw_indexed_vertices(); iron_g4_end(); context_raw.colorid_picked = false; ui_toolbar_handle.redraws = 1; diff --git a/armorsculpt/sources/import_mesh.ts b/armorsculpt/sources/import_mesh.ts index 6720ddcc..2c5bc095 100644 --- a/armorsculpt/sources/import_mesh.ts +++ b/armorsculpt/sources/import_mesh.ts @@ -230,7 +230,7 @@ function import_mesh_pack_to_texture(mesh: raw_mesh_t) { buffer_set_f32(b, 4 * i * 4 + 3 * 4, 1.0); } - let imgmesh: kinc_g5_texture_t = image_from_bytes(b, config_get_texture_res_x(), config_get_texture_res_y(), tex_format_t.RGBA128); + let imgmesh: kinc_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: kinc_g5_texture_t = project_layers[0].texpaint; g2_begin(texpaint); draw_set_pipeline(pipes_copy128); diff --git a/armorsculpt/sources/render_path_sculpt.ts b/armorsculpt/sources/render_path_sculpt.ts index 898083d4..5f09156f 100644 --- a/armorsculpt/sources/render_path_sculpt.ts +++ b/armorsculpt/sources/render_path_sculpt.ts @@ -35,7 +35,7 @@ function render_path_sculpt_commands() { uniforms_set_material_consts(cc_context, material_contexts[0]); kinc_g4_set_vertex_buffer(const_data_screen_aligned_vb); kinc_g4_set_index_buffer(const_data_screen_aligned_ib); - g4_draw(); + iron_g4_draw_indexed_vertices(); render_path_end(); } diff --git a/base/assets/plugins/import_tiff.js b/base/assets/plugins/import_tiff.js index 70caf50b..e905ed56 100644 --- a/base/assets/plugins/import_tiff.js +++ b/base/assets/plugins/import_tiff.js @@ -8,7 +8,7 @@ function import_tiff(path) { let ifds = UTIF.decode(b); UTIF.decodeImage(b, ifds[0]); let rgba = UTIF.toRGBA8(ifds[0]); - let image = image_from_bytes(rgba.buffer, ifds[0].width, ifds[0].height); + let image = iron_g4_create_texture_from_bytes(rgba.buffer, ifds[0].width, ifds[0].height); return image; } diff --git a/base/plugins/plugin_api.c b/base/plugins/plugin_api.c index 43636fe1..e3252a78 100644 --- a/base/plugins/plugin_api.c +++ b/base/plugins/plugin_api.c @@ -449,8 +449,8 @@ FN(node_shader_add_uniform) { VOID_FN_PTR_STR(node_shader_write) -void *image_from_bytes(void *p, int w, int h, int format); -FN(image_from_bytes) { +void *iron_g4_create_texture_from_bytes(void *p, int w, int h, int format); +FN(iron_g4_create_texture_from_bytes) { size_t len; void *ab = JS_GetArrayBuffer(ctx, &len, argv[0]); buffer_t b = { .buffer = ab, .length = len, .capacity = len }; @@ -458,7 +458,7 @@ FN(image_from_bytes) { JS_ToInt64(ctx, &w, argv[1]); int64_t h; JS_ToInt64(ctx, &h, argv[2]); - int64_t result = (int64_t)image_from_bytes(&b, w, h, 0); + int64_t result = (int64_t)iron_g4_create_texture_from_bytes(&b, w, h, 0); return JS_NewInt64(ctx, result); } @@ -810,7 +810,7 @@ void plugin_api_init() { BIND(context_set_viewport_shader, 1); BIND(node_shader_add_uniform, 3); BIND(node_shader_write, 2); - BIND(image_from_bytes, 3); + BIND(iron_g4_create_texture_from_bytes, 3); BIND(project_filepath_get, 0); BIND(project_save, 0); diff --git a/base/sources/backends/direct3d12_gpu.c b/base/sources/backends/direct3d12_gpu.c index b6a2e3ec..65f894b9 100644 --- a/base/sources/backends/direct3d12_gpu.c +++ b/base/sources/backends/direct3d12_gpu.c @@ -49,14 +49,32 @@ #include #include #include "d3d12mini.h" +#include +#include +#include +#include +#include +#include "g5_commandlist.h" +#include "g5_pipeline.h" +#include "g5_buffer.h" +#include +#include +#undef CreateWindow +#include +#include +#include "g5_pipeline.h" +#include +#include +#include +#include "g5_texture.h" +#include +#include ID3D12Device *device = NULL; static ID3D12RootSignature *globalRootSignature = NULL; static ID3D12RootSignature *globalComputeRootSignature = NULL; // extern ID3D12GraphicsCommandList* commandList; -#include - #define MAXIMUM_WINDOWS 1 struct dx_ctx { @@ -71,22 +89,6 @@ inline struct dx_window *kinc_dx_current_window() { static bool compute_pipeline_set = false; -#include -#include -#include - -#include "g5_commandlist.h" -#include "g5_pipeline.h" -#include "g5_buffer.h" - -#include -#include -#include -#undef CreateWindow -#include -#include -#include - ID3D12CommandQueue *commandQueue; struct RenderEnvironment { @@ -553,20 +555,6 @@ bool kinc_g5_raytrace_supported() { return false; } - - - - - - - - - - - -#include -#include - void createHeaps(kinc_g5_command_list_t *list); static int formatSize(DXGI_FORMAT format) { @@ -1075,19 +1063,6 @@ void kinc_g5_command_list_set_texture_from_render_target_depth(kinc_g5_command_l list->impl.currentTextures[texture->impl.stage_depth] = texture; } - - - - - - - - - -#include -#include -#include - void kinc_g5_compute_shader_init(kinc_g5_compute_shader *shader, void *_data, int length) { unsigned index = 0; uint8_t *data = (uint8_t *)_data; @@ -1248,21 +1223,6 @@ kinc_g5_texture_unit_t kinc_g5_compute_shader_get_texture_unit(kinc_g5_compute_s return unit; } - - - - - - - - - -#include "g5_pipeline.h" - -#include -#include -#include - void kinc_g5_internal_setConstants(kinc_g5_command_list_t *commandList, kinc_g5_pipeline_t *pipeline) { commandList->impl._commandList->lpVtbl->SetGraphicsRootSignature(commandList->impl._commandList, globalRootSignature); @@ -1790,18 +1750,6 @@ uint32_t kinc_internal_hash_name(unsigned char *str) { return hash; } - - - - -#include "g5_texture.h" - -#include -#include -#include -#include -#include - static const int heapSize = 1024; void kinc_g5_internal_reset_textures(struct kinc_g5_command_list *list) { @@ -2462,15 +2410,6 @@ void kinc_g5_render_target_set_depth_from(kinc_g5_texture_t *render_target, kinc render_target->impl.depthStencilTexture = source->impl.depthStencilTexture; } - - - - - -#include "g5_buffer.h" -#include -#include - kinc_g5_vertex_buffer_t *_current_vertex_buffer = NULL; void kinc_g5_vertex_buffer_init(kinc_g5_vertex_buffer_t *buffer, int count, kinc_g5_vertex_structure_t *structure, bool gpuMemory) { @@ -2756,15 +2695,6 @@ int kinc_g5_index_buffer_count(kinc_g5_index_buffer_t *buffer) { return buffer->impl.count; } - - - - - - -#include -#include - static const wchar_t *hit_group_name = L"hitgroup"; static const wchar_t *raygen_shader_name = L"raygeneration"; static const wchar_t *closesthit_shader_name = L"closesthit"; @@ -3658,5 +3588,3 @@ void kinc_g5_raytrace_dispatch_rays(kinc_g5_command_list_t *command_list) { dxrCommandList->lpVtbl->SetPipelineState1(dxrCommandList, pipeline->impl.dxr_state); dxrCommandList->lpVtbl->DispatchRays(dxrCommandList, &dispatchDesc); } - - diff --git a/base/sources/backends/metal_gpu.m b/base/sources/backends/metal_gpu.m index 8c10fe89..0d40441d 100644 --- a/base/sources/backends/metal_gpu.m +++ b/base/sources/backends/metal_gpu.m @@ -1,5 +1,14 @@ #import #import +#include "metal.h" +#include +#include +#include +#include +#include +#include +#include + static id command_buffer = nil; static id render_command_encoder = nil; @@ -8,27 +17,6 @@ static id compute_command_encoder = nil; static void start_render_pass(void); static void end_render_pass(void); - - - - - - - - - - - - - - -#include "metal.h" -#include -#include -#include -#import -#import - id getMetalLayer(void); id getMetalDevice(void); id getMetalQueue(void); @@ -233,26 +221,6 @@ int kinc_g5_max_bound_textures(void) { return 16; } - - - - - - - - - - - - -#include -#include -#import -#import -#include -#include -#include - id getMetalDevice(void); id getMetalQueue(void); id getMetalEncoder(void); @@ -555,32 +523,6 @@ void kinc_g5_command_list_compute(kinc_g5_command_list_t *list, int x, int y, in start_render_pass(); } - - - - - - - - - - - - - - - - - - - - - - -#include -#include -#include - id getMetalDevice(void); id getMetalLibrary(void); @@ -688,25 +630,6 @@ kinc_g5_texture_unit_t kinc_g5_compute_shader_get_texture_unit(kinc_g5_compute_s return unit; } - - - - - - - - - - - -#include -#include -#include -#import -#include -#include -#include - id getMetalDevice(void); id getMetalEncoder(void); @@ -1152,22 +1075,6 @@ void kinc_g5_shader_init(kinc_g5_shader_t *shader, const void *source, size_t le } - - - - - - - - - - - - - -#include -#include - static kinc_g5_raytrace_acceleration_structure_t *accel; static kinc_g5_raytrace_pipeline_t *pipeline; static kinc_g5_texture_t *output = NULL; @@ -1428,34 +1335,6 @@ void kinc_g5_raytrace_dispatch_rays(kinc_g5_command_list_t *command_list) { } - - - - - - - - - - - - - - - - - - - - - - - - -#include -#include -#import - id getMetalDevice(void); id getMetalEncoder(void); @@ -1723,20 +1602,6 @@ void kinc_g5_render_target_set_depth_from(kinc_g5_texture_t *target, kinc_g5_tex } - - - - - - - - - - - -#include -#import - id getMetalDevice(void); id getMetalEncoder(void); @@ -1896,4 +1761,3 @@ void kinc_g5_index_buffer_unlock(kinc_g5_index_buffer_t *buffer, int count) { int kinc_g5_index_buffer_count(kinc_g5_index_buffer_t *buffer) { return buffer->impl.count; } - diff --git a/base/sources/backends/vulkan_gpu.c b/base/sources/backends/vulkan_gpu.c index e8a8838d..d366c131 100644 --- a/base/sources/backends/vulkan_gpu.c +++ b/base/sources/backends/vulkan_gpu.c @@ -23,6 +23,81 @@ static void command_list_should_wait_for_framebuffer(void); static VkDescriptorSetLayout compute_descriptor_layout; static int framebuffer_count = 0; +extern kinc_g5_texture_t *vulkan_textures[16]; +VkDescriptorSet getDescriptorSet(void); +static VkDescriptorSet get_compute_descriptor_set(void); +void setImageLayout(VkCommandBuffer _buffer, VkImage image, VkImageAspectFlags aspectMask, VkImageLayout oldImageLayout, VkImageLayout newImageLayout); + +VkRenderPassBeginInfo currentRenderPassBeginInfo; +VkPipeline currentVulkanPipeline; +kinc_g5_texture_t *currentRenderTargets[8] = {NULL, NULL, NULL, NULL, NULL, NULL, NULL, NULL}; + +static bool onBackBuffer = false; +static uint32_t lastVertexConstantBufferOffset = 0; +static uint32_t lastFragmentConstantBufferOffset = 0; +static uint32_t lastComputeConstantBufferOffset = 0; +static kinc_g5_pipeline_t *current_pipeline = NULL; +static kinc_g5_compute_shader *current_compute_shader = NULL; +static int mrtIndex = 0; +static VkFramebuffer mrtFramebuffer[16]; +static VkRenderPass mrtRenderPass[16]; + +static bool in_render_pass = false; +static bool wait_for_framebuffer = false; + +static void parse_shader(uint32_t *shader_source, int shader_length, kinc_internal_named_number *locations, kinc_internal_named_number *textureBindings, kinc_internal_named_number *uniformOffsets); +static VkShaderModule create_shader_module(const void *code, size_t size); +static VkDescriptorPool compute_descriptor_pool; + +VkDescriptorSetLayout desc_layout; +extern kinc_g5_texture_t *vulkan_textures[16]; +extern uint32_t swapchainImageCount; +extern uint32_t current_buffer; + +static VkDescriptorPool descriptor_pool; + +struct indexed_name { + uint32_t id; + char *name; +}; + +struct indexed_index { + uint32_t id; + uint32_t value; +}; + +#define MAX_THINGS 256 +static struct indexed_name names[MAX_THINGS]; +static uint32_t names_size = 0; +static struct indexed_name memberNames[MAX_THINGS]; +static uint32_t memberNames_size = 0; +static struct indexed_index locs[MAX_THINGS]; +static uint32_t locs_size = 0; +static struct indexed_index bindings[MAX_THINGS]; +static uint32_t bindings_size = 0; +static struct indexed_index offsets[MAX_THINGS]; +static uint32_t offsets_size = 0; + +#define MAX_DESCRIPTOR_SETS 1024 + +struct descriptor_set { + int id; + bool in_use; + VkDescriptorImageInfo tex_desc[16]; + VkDescriptorSet set; +}; + +static struct descriptor_set descriptor_sets[MAX_DESCRIPTOR_SETS] = {0}; +static int descriptor_sets_count = 0; + +static struct descriptor_set compute_descriptor_sets[MAX_DESCRIPTOR_SETS] = {0}; +static int compute_descriptor_sets_count = 0; + +bool use_staging_buffer = false; + +void set_image_layout(VkImage image, VkImageAspectFlags aspectMask, VkImageLayout old_image_layout, VkImageLayout new_image_layout); + + // djb2 uint32_t kinc_internal_hash_name(unsigned char *str) { unsigned long hash = 5381; @@ -1157,44 +1232,6 @@ int kinc_g5_max_bound_textures(void) { } - - - - - - - - - - - - - - - - -extern kinc_g5_texture_t *vulkan_textures[16]; -VkDescriptorSet getDescriptorSet(void); -static VkDescriptorSet get_compute_descriptor_set(void); -bool memory_type_from_properties(uint32_t typeBits, VkFlags requirements_mask, uint32_t *typeIndex); -void setImageLayout(VkCommandBuffer _buffer, VkImage image, VkImageAspectFlags aspectMask, VkImageLayout oldImageLayout, VkImageLayout newImageLayout); - -VkRenderPassBeginInfo currentRenderPassBeginInfo; -VkPipeline currentVulkanPipeline; -kinc_g5_texture_t *currentRenderTargets[8] = {NULL, NULL, NULL, NULL, NULL, NULL, NULL, NULL}; - -static bool onBackBuffer = false; -static uint32_t lastVertexConstantBufferOffset = 0; -static uint32_t lastFragmentConstantBufferOffset = 0; -static uint32_t lastComputeConstantBufferOffset = 0; -static kinc_g5_pipeline_t *current_pipeline = NULL; -static kinc_g5_compute_shader *current_compute_shader = NULL; -static int mrtIndex = 0; -static VkFramebuffer mrtFramebuffer[16]; -static VkRenderPass mrtRenderPass[16]; - -static bool in_render_pass = false; - static void endPass(kinc_g5_command_list_t *list) { if (in_render_pass) { vkCmdEndRenderPass(list->impl._buffer); @@ -1960,8 +1997,6 @@ void kinc_g5_command_list_set_compute_constant_buffer(kinc_g5_command_list_t *li offsets); } -static bool wait_for_framebuffer = false; - static void command_list_should_wait_for_framebuffer(void) { wait_for_framebuffer = true; } @@ -2061,29 +2096,6 @@ void kinc_g5_command_list_compute(kinc_g5_command_list_t *list, int x, int y, in } } - - - - - - - - - - - - - - - - - - - -static void parse_shader(uint32_t *shader_source, int shader_length, kinc_internal_named_number *locations, kinc_internal_named_number *textureBindings, kinc_internal_named_number *uniformOffsets); -static VkShaderModule create_shader_module(const void *code, size_t size); -static VkDescriptorPool compute_descriptor_pool; - static void create_compute_descriptor_layout(void) { VkDescriptorSetLayoutBinding layoutBindings[18]; memset(layoutBindings, 0, sizeof(layoutBindings)); @@ -2208,40 +2220,6 @@ kinc_g5_texture_unit_t kinc_g5_compute_shader_get_texture_unit(kinc_g5_compute_s return unit; } - - - - - - - - - - - - - - - - - - - - - - - - - - -VkDescriptorSetLayout desc_layout; -extern kinc_g5_texture_t *vulkan_textures[16]; -extern uint32_t swapchainImageCount; -extern uint32_t current_buffer; -bool memory_type_from_properties(uint32_t typeBits, VkFlags requirements_mask, uint32_t *typeIndex); - -static VkDescriptorPool descriptor_pool; - static bool has_number(kinc_internal_named_number *named_numbers, const char *name) { for (int i = 0; i < KINC_INTERNAL_NAMED_NUMBER_COUNT; ++i) { if (strcmp(named_numbers[i].name, name) == 0) { @@ -2279,28 +2257,6 @@ static void set_number(kinc_internal_named_number *named_numbers, const char *na assert(false); } -struct indexed_name { - uint32_t id; - char *name; -}; - -struct indexed_index { - uint32_t id; - uint32_t value; -}; - -#define MAX_THINGS 256 -static struct indexed_name names[MAX_THINGS]; -static uint32_t names_size = 0; -static struct indexed_name memberNames[MAX_THINGS]; -static uint32_t memberNames_size = 0; -static struct indexed_index locs[MAX_THINGS]; -static uint32_t locs_size = 0; -static struct indexed_index bindings[MAX_THINGS]; -static uint32_t bindings_size = 0; -static struct indexed_index offsets[MAX_THINGS]; -static uint32_t offsets_size = 0; - static void add_name(uint32_t id, char *name) { names[names_size].id = id; names[names_size].name = name; @@ -2970,18 +2926,6 @@ int calc_compute_descriptor_id(void) { return 1 | (texture_count << 1) | ((uniform_buffer ? 1 : 0) << 8); } -#define MAX_DESCRIPTOR_SETS 1024 - -struct destriptor_set { - int id; - bool in_use; - VkDescriptorImageInfo tex_desc[16]; - VkDescriptorSet set; -}; - -static struct destriptor_set descriptor_sets[MAX_DESCRIPTOR_SETS] = {0}; -static int descriptor_sets_count = 0; - static int write_tex_descs(VkDescriptorImageInfo *tex_descs) { memset(tex_descs, 0, sizeof(VkDescriptorImageInfo) * 16); @@ -3003,7 +2947,7 @@ static int write_tex_descs(VkDescriptorImageInfo *tex_descs) { return texture_count; } -static bool textures_changed(struct destriptor_set *set) { +static bool textures_changed(struct descriptor_set *set) { VkDescriptorImageInfo tex_desc[16]; write_tex_descs(tex_desc); @@ -3011,7 +2955,7 @@ static bool textures_changed(struct destriptor_set *set) { return memcmp(&tex_desc, &set->tex_desc, sizeof(tex_desc)) != 0; } -static void update_textures(struct destriptor_set *set) { +static void update_textures(struct descriptor_set *set) { memset(&set->tex_desc, 0, sizeof(set->tex_desc)); int texture_count = write_tex_descs(set->tex_desc); @@ -3151,9 +3095,6 @@ VkDescriptorSet getDescriptorSet() { return descriptor_set; } -static struct destriptor_set compute_descriptor_sets[MAX_DESCRIPTOR_SETS] = {0}; -static int compute_descriptor_sets_count = 0; - static int write_compute_tex_descs(VkDescriptorImageInfo *tex_descs) { memset(tex_descs, 0, sizeof(VkDescriptorImageInfo) * 16); @@ -3175,7 +3116,7 @@ static int write_compute_tex_descs(VkDescriptorImageInfo *tex_descs) { return texture_count; } -static bool compute_textures_changed(struct destriptor_set *set) { +static bool compute_textures_changed(struct descriptor_set *set) { VkDescriptorImageInfo tex_desc[16]; write_compute_tex_descs(tex_desc); @@ -3183,7 +3124,7 @@ static bool compute_textures_changed(struct destriptor_set *set) { return memcmp(&tex_desc, &set->tex_desc, sizeof(tex_desc)) != 0; } -static void update_compute_textures(struct destriptor_set *set) { +static void update_compute_textures(struct descriptor_set *set) { memset(&set->tex_desc, 0, sizeof(set->tex_desc)); int texture_count = write_compute_tex_descs(set->tex_desc); @@ -3412,69 +3353,6 @@ void kinc_g5_sampler_destroy(kinc_g5_sampler_t *sampler) { vkDestroySampler(vk_ctx.device, sampler->impl.sampler, NULL); } - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - -bool use_staging_buffer = false; - -bool memory_type_from_properties(uint32_t typeBits, VkFlags requirements_mask, uint32_t *typeIndex); -void set_image_layout(VkImage image, VkImageAspectFlags aspectMask, VkImageLayout old_image_layout, VkImageLayout new_image_layout); - static void prepare_texture_image(uint8_t *tex_colors, uint32_t width, uint32_t height, Texture5Impl *tex_obj, VkImageTiling tiling, VkImageUsageFlags usage, VkFlags required_props, VkDeviceSize *deviceSize, VkFormat tex_format) { VkResult err; @@ -3874,8 +3752,6 @@ int kinc_g5_texture_stride(kinc_g5_texture_t *texture) { void kinc_g5_texture_generate_mipmaps(kinc_g5_texture_t *texture, int levels) {} -extern kinc_g5_command_list_t commandList; - void kinc_g5_texture_set_mipmap(kinc_g5_texture_t *texture, kinc_g5_texture_t *mipmap, int level) { // VkBuffer staging_buffer; // VkDeviceMemory staging_buffer_mem; @@ -3948,9 +3824,6 @@ void kinc_g5_texture_set_mipmap(kinc_g5_texture_t *texture, kinc_g5_texture_t *m // texture->_uploaded = true; } -extern uint32_t swapchainImageCount; -extern kinc_g5_texture_t *vulkan_textures[16]; - void setup_init_cmd(); void setImageLayout(VkCommandBuffer _buffer, VkImage image, VkImageAspectFlags aspectMask, VkImageLayout oldImageLayout, VkImageLayout newImageLayout) { @@ -4230,39 +4103,6 @@ void kinc_g5_render_target_set_depth_from(kinc_g5_texture_t *target, kinc_g5_tex } } - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - -bool memory_type_from_properties(uint32_t typeBits, VkFlags requirements_mask, uint32_t *typeIndex); - void kinc_g5_vertex_buffer_init(kinc_g5_vertex_buffer_t *buffer, int vertexCount, kinc_g5_vertex_structure_t *structure, bool gpuMemory) { buffer->impl.myCount = vertexCount; buffer->impl.myStride = 0; @@ -4535,52 +4375,11 @@ int kinc_g5_index_buffer_count(kinc_g5_index_buffer_t *buffer) { } - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - #ifndef KINC_ANDROID extern VkRenderPassBeginInfo currentRenderPassBeginInfo; extern VkFramebuffer *framebuffers; extern uint32_t current_buffer; -bool memory_type_from_properties(uint32_t typeBits, VkFlags requirements_mask, uint32_t *typeIndex); static const int INDEX_RAYGEN = 0; static const int INDEX_MISS = 1; diff --git a/base/sources/backends/vulkan_gpu.h b/base/sources/backends/vulkan_gpu.h index ad251395..1a6c7dfb 100644 --- a/base/sources/backends/vulkan_gpu.h +++ b/base/sources/backends/vulkan_gpu.h @@ -72,7 +72,7 @@ struct vk_window { struct vk_depth depth; }; -#define MAXIMUM_WINDOWS 16 +#define MAXIMUM_WINDOWS 1 struct vk_context { VkInstance instance; @@ -120,8 +120,6 @@ typedef struct kinc_g5_compute_shader_impl { VkShaderModule shader_module; } kinc_g5_compute_shader_impl; -struct kinc_g5_shader; - typedef struct PipelineState5Impl_s { const char **textures; int *textureValues; @@ -244,7 +242,6 @@ typedef struct { VkDeviceMemory top_level_mem; VkBuffer instances_buffer; VkDeviceMemory instances_mem; - } kinc_g5_raytrace_acceleration_structure_impl_t; #endif diff --git a/base/sources/backends/webgpu_gpu.c b/base/sources/backends/webgpu_gpu.c index 88cf24ec..241a927a 100644 --- a/base/sources/backends/webgpu_gpu.c +++ b/base/sources/backends/webgpu_gpu.c @@ -6,6 +6,8 @@ #include #include #include +#include +#include int renderTargetWidth; int renderTargetHeight; @@ -63,17 +65,6 @@ bool kinc_g5_raytrace_supported() { return false; } - - - - - - -#include -#include -#include -#include - extern WGPUDevice device; kinc_g5_vertex_buffer_t *kinc_g5_internal_current_vertex_buffer = NULL; @@ -186,22 +177,7 @@ int kinc_g5_index_buffer_count(kinc_g5_index_buffer_t *buffer) { return buffer->impl.count; } - - - - - - - - - - - - -#include - void kinc_g5_texture_init(kinc_g5_texture_t *texture, int width, int height, kinc_image_format_t format) { - // WGPUExtent3D size = {}; // size.width = kinc_width(); // size.height = kinc_height(); @@ -254,15 +230,6 @@ void kinc_g5_render_target_set_depth_from(kinc_g5_texture_t *renderTarget, kinc_ void kinc_g5_render_target_get_pixels(kinc_g5_texture_t *renderTarget, uint8_t *data) {} - - - - - -#include -#include -#include - extern WGPUDevice device; void kinc_g5_pipeline_init(kinc_g5_pipeline_t *pipe) { @@ -528,15 +495,6 @@ void kinc_g5_command_list_set_compute_shader(kinc_g5_command_list_t *list, kinc_ void kinc_g5_command_list_compute(kinc_g5_command_list_t *list, int x, int y, int z) {} - - - - - - -#include -#include - void kinc_g5_compute_shader_init(kinc_g5_compute_shader *shader, void *source, int length) {} void kinc_g5_compute_shader_destroy(kinc_g5_compute_shader *shader) {} @@ -550,5 +508,3 @@ kinc_g5_texture_unit_t kinc_g5_compute_shader_get_texture_unit(kinc_g5_compute_s kinc_g5_texture_unit_t unit = {0}; return unit; } - - diff --git a/base/sources/iron.h b/base/sources/iron.h index ab314b26..4866fedc 100644 --- a/base/sources/iron.h +++ b/base/sources/iron.h @@ -981,6 +981,7 @@ kinc_g5_shader_t *iron_g4_create_shader(buffer_t *data, i32 shader_type) { } kinc_g5_shader_t *iron_g4_create_shader_from_source(string_t *source, kinc_g5_shader_type_t shader_type) { + kinc_g5_shader_t *shader = NULL; char *temp_string_s = shader_type == KINC_G5_SHADER_TYPE_VERTEX ? temp_string_vs : temp_string_fs; #ifdef WITH_D3DCOMPILER @@ -1105,7 +1106,7 @@ kinc_g5_shader_t *iron_g4_create_shader_from_source(string_t *source, kinc_g5_sh shader_buffer->lpVtbl->Release(shader_buffer); reflector->lpVtbl->Release(reflector); - kinc_g5_shader_t *shader = (kinc_g5_shader_t *)malloc(sizeof(kinc_g5_shader_t)); + shader = (kinc_g5_shader_t *)malloc(sizeof(kinc_g5_shader_t)); kinc_g5_shader_init(shader, file, (int)output_len, shader_type); free(file); @@ -1113,7 +1114,7 @@ kinc_g5_shader_t *iron_g4_create_shader_from_source(string_t *source, kinc_g5_sh strcpy(temp_string_s, "// my_main\n"); strcat(temp_string_s, source); - kinc_g5_shader_t *shader = (kinc_g5_shader_t *)malloc(sizeof(kinc_g5_shader_t)); + shader = (kinc_g5_shader_t *)malloc(sizeof(kinc_g5_shader_t)); kinc_g5_shader_init(shader, temp_string_s, strlen(temp_string_s), shader_type); #elif defined(KINC_VULKAN) && defined(KRAFIX_LIBRARY) @@ -1121,7 +1122,7 @@ kinc_g5_shader_t *iron_g4_create_shader_from_source(string_t *source, kinc_g5_sh char *output = malloc(1024 * 1024); int length; krafix_compile(source, output, &length, "spirv", "windows", shader_type == KINC_G5_SHADER_TYPE_VERTEX ? "vert" : "frag", -1); - kinc_g5_shader_t *shader = (kinc_g5_shader_t *)malloc(sizeof(kinc_g5_shader_t)); + shader = (kinc_g5_shader_t *)malloc(sizeof(kinc_g5_shader_t)); kinc_g5_shader_init(shader, output, length, shader_type); #endif @@ -1333,8 +1334,8 @@ void iron_g4_set_float4(kinc_g5_constant_location_t *location, f32 value1, f32 v kinc_g4_set_float4(*location, value1, value2, value3, value4); } -void iron_g4_set_floats(kinc_g5_constant_location_t *location, buffer_t *values) { - kinc_g4_set_floats(*location, (float *)values->buffer, (int)(values->length / 4)); +void iron_g4_set_floats(kinc_g5_constant_location_t *location, f32_array_t *values) { + kinc_g4_set_floats(*location, (float *)values->buffer, values->length); } void iron_g4_set_matrix4(kinc_g5_constant_location_t *location, mat4_t m) { @@ -1391,13 +1392,6 @@ kinc_g5_texture_t *iron_g4_create_render_target(i32 width, i32 height, i32 forma return render_target; } -kinc_g5_texture_t *iron_g4_create_texture(i32 width, i32 height, i32 format) { - kinc_g5_texture_t *texture = (kinc_g5_texture_t *)malloc(sizeof(kinc_g5_texture_t)); - kinc_g5_texture_init(texture, width, height, (kinc_image_format_t)format); - texture->buffer = NULL; - return texture; -} - kinc_g5_texture_t *iron_g4_create_texture_from_bytes(buffer_t *data, i32 width, i32 height, i32 format, bool readable) { kinc_g5_texture_t *texture = (kinc_g5_texture_t *)malloc(sizeof(kinc_g5_texture_t)); texture->buffer = NULL; diff --git a/base/sources/iron_gpu.c b/base/sources/iron_gpu.c index 96e8184f..b245cb26 100644 --- a/base/sources/iron_gpu.c +++ b/base/sources/iron_gpu.c @@ -1,17 +1,17 @@ #include "iron_gpu.h" #include #include -#include -#include -#include #include +#include "iron_system.h" +#include "iron_math.h" +#include "iron_file.h" #define CONSTANT_BUFFER_SIZE 4096 #define CONSTANT_BUFFER_MULTIPLY 100 #define FRAMEBUFFER_COUNT 2 #define MAX_TEXTURES 16 - #define MAX_SAMPLERS_PER_STAGE 16 +#define MAX_SAMPLER_CACHE_SIZE 256 static kinc_g5_sampler_options_t sampler_options[KINC_G5_SHADER_TYPE_COUNT][MAX_SAMPLERS_PER_STAGE]; @@ -20,11 +20,11 @@ struct sampler_cache_entry { kinc_g5_sampler_t sampler; }; -#define MAX_SAMPLER_CACHE_SIZE 256 static struct sampler_cache_entry sampler_cache[MAX_SAMPLER_CACHE_SIZE]; static int sampler_cache_size = 0; void kinc_internal_samplers_reset(void); +kinc_g5_sampler_t *kinc_internal_get_current_sampler(int stage, int unit); kinc_g5_command_list_t commandList; bool waitAfterNextDraw = false; @@ -113,8 +113,6 @@ void kinc_g4_internal_init_window(int depthBufferBits, bool vsync) { kinc_g5_command_list_begin(&commandList); } -kinc_g5_sampler_t *kinc_internal_get_current_sampler(int stage, int unit); - void kinc_g5_internal_set_samplers(int count, kinc_g5_texture_unit_t *texture_units) { for (int i = 0; i < count; ++i) { for (int j = 0; j < KINC_G5_SHADER_TYPE_COUNT; ++j) { @@ -622,8 +620,6 @@ void kinc_g5_vertex_structure_add(kinc_g5_vertex_structure_t *structure, const c structure->size++; } -extern bool waitAfterNextDraw; - void kinc_g4_vertex_buffer_init(kinc_g4_vertex_buffer_t *buffer, int count, kinc_g5_vertex_structure_t *structure, kinc_g4_usage_t usage) { buffer->impl._multiple = usage == KINC_G4_USAGE_STATIC ? 1 : 2; buffer->impl._currentIndex = 0; diff --git a/base/sources/iron_system.c b/base/sources/iron_system.c index 2c730801..b241b590 100644 --- a/base/sources/iron_system.c +++ b/base/sources/iron_system.c @@ -472,6 +472,9 @@ bool kinc_mouse_is_locked(void) { } void kinc_mouse_lock() { + if (kinc_mouse_is_locked()) { + return; + } if (!kinc_mouse_can_lock()) { return; } @@ -484,6 +487,9 @@ void kinc_mouse_lock() { } void kinc_mouse_unlock(void) { + if (!kinc_mouse_is_locked()) { + return; + } if (!kinc_mouse_can_lock()) { return; } diff --git a/base/sources/ts/export_texture.ts b/base/sources/ts/export_texture.ts index 745953c6..fed9f40c 100644 --- a/base/sources/ts/export_texture.ts +++ b/base/sources/ts/export_texture.ts @@ -258,7 +258,7 @@ function export_texture_run_layers(path: string, layers: slot_layer_t[], object_ iron_g4_set_int(pipes_blending, layers.length > 1 ? l1.blending : 0); kinc_g4_set_vertex_buffer(const_data_screen_aligned_vb); kinc_g4_set_index_buffer(const_data_screen_aligned_ib); - g4_draw(); + iron_g4_draw_indexed_vertices(); iron_g4_end(); } @@ -279,7 +279,7 @@ function export_texture_run_layers(path: string, layers: slot_layer_t[], object_ iron_g4_set_int(pipes_blending, l1.paint_nor_blend ? -2 : -1); kinc_g4_set_vertex_buffer(const_data_screen_aligned_vb); kinc_g4_set_index_buffer(const_data_screen_aligned_ib); - g4_draw(); + iron_g4_draw_indexed_vertices(); iron_g4_end(); } @@ -464,7 +464,7 @@ function export_texture_write_texture(file: string, pixels: buffer_t, type: i32 } if (context_raw.layers_destination == export_destination_t.PACKED) { - let image: kinc_g5_texture_t = image_from_bytes(pixels, res_x, res_y); + let image: kinc_g5_texture_t = iron_g4_create_texture_from_bytes(pixels, res_x, res_y); map_set(data_cached_images, file, image); let ar: string[] = string_split(file, path_sep); let name: string = ar[ar.length - 1]; diff --git a/base/sources/ts/import_arm.ts b/base/sources/ts/import_arm.ts index 39cef31a..de0a3a7c 100644 --- a/base/sources/ts/import_arm.ts +++ b/base/sources/ts/import_arm.ts @@ -243,7 +243,7 @@ function import_arm_run_project(path: string) { let _texpaint_pack: kinc_g5_texture_t = null; if (is_mask) { - _texpaint = image_from_bytes(lz4_decode(ld.texpaint, ld.res * ld.res * 4), ld.res, ld.res, tex_format_t.RGBA32); + _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_set_pipeline(pipes_copy8); draw_set_pipeline(project.is_bgra ? pipes_copy_bgra : pipes_copy); // Full bits for undo support, R8 is used @@ -253,7 +253,7 @@ function import_arm_run_project(path: string) { } else { // Layer // TODO: create render target from bytes - _texpaint = image_from_bytes(lz4_decode(ld.texpaint, ld.res * ld.res * 4 * bytes_per_pixel), ld.res, ld.res, format); + _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_set_pipeline(project.is_bgra ? pipes_copy_bgra : pipes_copy); draw_image(_texpaint, 0, 0); @@ -261,14 +261,14 @@ function import_arm_run_project(path: string) { g2_end(); ///if is_paint - _texpaint_nor = image_from_bytes(lz4_decode(ld.texpaint_nor, ld.res * ld.res * 4 * bytes_per_pixel), ld.res, ld.res, format); + _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_set_pipeline(project.is_bgra ? pipes_copy_bgra : pipes_copy); draw_image(_texpaint_nor, 0, 0); draw_set_pipeline(null); g2_end(); - _texpaint_pack = image_from_bytes(lz4_decode(ld.texpaint_pack, ld.res * ld.res * 4 * bytes_per_pixel), ld.res, ld.res, format); + _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_set_pipeline(project.is_bgra ? pipes_copy_bgra : pipes_copy); draw_image(_texpaint_pack, 0, 0); @@ -633,7 +633,7 @@ function import_arm_make_pink(abs: string) { b[1] = 0; b[2] = 255; b[3] = 255; - let pink: kinc_g5_texture_t = image_from_bytes(b, 1, 1); + let pink: kinc_g5_texture_t = iron_g4_create_texture_from_bytes(b, 1, 1); map_set(data_cached_images, abs, pink); } @@ -674,7 +674,7 @@ function import_arm_unpack_asset(project: project_format_t, abs: string, file: s if (!project_packed_asset_exists(project_raw.packed_assets, pa.name)) { array_push(project_raw.packed_assets, pa); } - let image: kinc_g5_texture_t = image_from_encoded_bytes(pa.bytes, ends_with(pa.name, ".jpg") ? ".jpg" : ".png"); + let image: kinc_g5_texture_t = iron_g4_create_texture_from_encoded_bytes(pa.bytes, ends_with(pa.name, ".jpg") ? ".jpg" : ".png"); map_set(data_cached_images, abs, image); break; } diff --git a/base/sources/ts/import_envmap.ts b/base/sources/ts/import_envmap.ts index 6bcc03b7..2ab9689b 100644 --- a/base/sources/ts/import_envmap.ts +++ b/base/sources/ts/import_envmap.ts @@ -1,9 +1,9 @@ let import_envmap_pipeline: kinc_g5_pipeline_t = null; -let import_envmap_params_loc: kinc_const_loc_t; +let import_envmap_params_loc: kinc_g5_constant_location_t; let import_envmap_params: vec4_t = vec4_create(); let import_envmap_n: vec4_t = vec4_create(); -let import_envmap_radiance_loc: kinc_tex_unit_t; +let import_envmap_radiance_loc: kinc_g5_texture_unit_t; let import_envmap_radiance: kinc_g5_texture_t = null; let import_envmap_radiance_cpu: kinc_g5_texture_t = null; let import_envmap_mips: kinc_g5_texture_t[] = null; @@ -48,7 +48,7 @@ function import_envmap_run(path: string, image: kinc_g5_texture_t) { iron_unload_image(_radiance_cpu); }, _radiance_cpu); } - import_envmap_radiance_cpu = image_from_bytes(radiance_pixels, import_envmap_radiance.width, import_envmap_radiance.height, tex_format_t.RGBA128); + import_envmap_radiance_cpu = iron_g4_create_texture_from_bytes(radiance_pixels, import_envmap_radiance.width, import_envmap_radiance.height, tex_format_t.RGBA128); // Radiance if (import_envmap_mips_cpu != null) { @@ -64,7 +64,7 @@ function import_envmap_run(path: string, image: kinc_g5_texture_t) { import_envmap_mips_cpu = []; for (let i: i32 = 0; i < import_envmap_mips.length; ++i) { import_envmap_get_radiance_mip(import_envmap_mips[i], i, import_envmap_radiance); - array_push(import_envmap_mips_cpu, image_from_bytes(iron_g4_get_texture_pixels(import_envmap_mips[i]), import_envmap_mips[i].width, import_envmap_mips[i].height, tex_format_t.RGBA128)); + array_push(import_envmap_mips_cpu, iron_g4_create_texture_from_bytes(iron_g4_get_texture_pixels(import_envmap_mips[i]), import_envmap_mips[i].width, import_envmap_mips[i].height, tex_format_t.RGBA128)); } iron_g4_set_mipmaps(import_envmap_radiance_cpu, import_envmap_mips_cpu); @@ -94,7 +94,7 @@ function import_envmap_get_radiance_mip(mip: kinc_g5_texture_t, level: i32, radi import_envmap_params.x = 0.1 + level / 8; iron_g4_set_float4(import_envmap_params_loc, import_envmap_params.x, import_envmap_params.y, import_envmap_params.z, import_envmap_params.w); iron_g4_set_texture(import_envmap_radiance_loc, radiance); - g4_draw(); + iron_g4_draw_indexed_vertices(); iron_g4_end(); } diff --git a/base/sources/ts/iron/g4.ts b/base/sources/ts/iron/g4.ts deleted file mode 100644 index 996302bd..00000000 --- a/base/sources/ts/iron/g4.ts +++ /dev/null @@ -1,208 +0,0 @@ - -function g4_vertex_struct_create(): kinc_g5_vertex_structure_t { - let raw: kinc_g5_vertex_structure_t = {}; - return raw; -} - -function g4_vertex_struct_add(raw: kinc_g5_vertex_structure_t, name: string, data: vertex_data_t) { - let e: kinc_g5_vertex_element_t = ADDRESS(ARRAY_ACCESS(raw.elements, raw.size)); - e.name = name; - e.data = data; - raw.size++; -} - -function g4_vertex_struct_byte_size(raw: kinc_g5_vertex_structure_t): i32 { - let byte_size: i32 = 0; - for (let i: i32 = 0; i < raw.size; ++i) { - let elem: kinc_g5_vertex_element_t = ADDRESS(ARRAY_ACCESS(raw.elements, i)); - byte_size += g4_vertex_struct_data_byte_size(elem.data); - } - return byte_size; -} - -function g4_vertex_struct_data_byte_size(data: vertex_data_t): i32 { - if (data == vertex_data_t.F32_1X) { - return 1 * 4; - } - if (data == vertex_data_t.F32_2X) { - return 2 * 4; - } - if (data == vertex_data_t.F32_3X) { - return 3 * 4; - } - if (data == vertex_data_t.F32_4X) { - return 4 * 4; - } - if (data == vertex_data_t.U8_4X_NORM) { - return 4 * 1; - } - if (data == vertex_data_t.I16_2X_NORM) { - return 2 * 2; - } - if (data == vertex_data_t.I16_4X_NORM) { - return 4 * 2; - } - return 0; -} - -function g4_set_floats(loc: kinc_const_loc_t, values: f32_array_t) { - let b: buffer_t = { - buffer: values.buffer, - length: values.length * 4 - }; - iron_g4_set_floats(loc, b); -} - -function g4_set_vec3(loc: kinc_const_loc_t, v: vec4_t) { - iron_g4_set_float3(loc, v.x, v.y, v.z); -} - -function g4_draw(start: i32 = 0, count: i32 = -1) { - iron_g4_draw_indexed_vertices(start, count); -} - -function image_from_bytes(buffer: buffer_t, width: i32, height: i32, format: tex_format_t = tex_format_t.RGBA32): kinc_g5_texture_t { - return iron_g4_create_texture_from_bytes(buffer, width, height, format, true); -} - -function image_from_encoded_bytes(buffer: buffer_t, format: string, readable: bool = false): kinc_g5_texture_t { - return iron_g4_create_texture_from_encoded_bytes(buffer, format, readable); -} - -function image_create(width: i32, height: i32, format: tex_format_t = tex_format_t.RGBA32): kinc_g5_texture_t { - return iron_g4_create_texture(width, height, format); -} - -declare type kinc_g5_pipeline_t = { - input_layout?: any; - vertex_shader?: any; - fragment_shader?: any; - - cull_mode?: cull_mode_t; - depth_write?: bool; - depth_mode?: compare_mode_t; - - blend_source?: blend_factor_t; - blend_destination?: blend_factor_t; - alpha_blend_source?: blend_factor_t; - alpha_blend_destination?: blend_factor_t; - - color_write_mask_red?: any; - color_write_mask_green?: any; - color_write_mask_blue?: any; - color_write_mask_alpha?: any; - - color_attachment?: any; - color_attachment_count?: i32; - depth_attachment_bits?: i32; - - impl?: any; -}; - -declare type kinc_g5_shader_t = { - impl?: any; -}; - -declare type kinc_g5_vertex_element_t = { - name?: string; - data?: vertex_data_t; -}; - -declare type kinc_g5_vertex_structure_t = { - elements?: any; // kinc_g5_vertex_element_t[KINC_G5_MAX_VERTEX_ELEMENTS]; - size?: i32; -}; - -declare type kinc_g5_index_buffer_t = { - impl?: any; -}; - -declare type kinc_g5_vertex_buffer_t = { - impl?: any; -}; - -type kinc_const_loc_t = any; -type kinc_tex_unit_t = any; - -enum clear_flag_t { - COLOR = 1, - DEPTH = 2, -} - -enum tex_filter_t { - POINT, - LINEAR, - ANISOTROPIC, -} - -enum mip_map_filter_t { - NONE, - POINT, - LINEAR, -} - -enum tex_addressing_t { - REPEAT, - MIRROR, - CLAMP, -} - -enum usage_t { - STATIC, - DYNAMIC, - READABLE, -} - -enum tex_format_t { - RGBA32, - RGBA64, - RGBA128, - R8, - R16, - R32, -} - -enum vertex_data_t { - F32_1X, - F32_2X, - F32_3X, - F32_4X, - U8_4X_NORM, - I16_2X_NORM, - I16_4X_NORM, -} - -enum blend_factor_t { - BLEND_ONE, - BLEND_ZERO, - SOURCE_ALPHA, - DEST_ALPHA, - INV_SOURCE_ALPHA, - INV_DEST_ALPHA, - SOURCE_COLOR, - DEST_COLOR, - INV_SOURCE_COLOR, - INV_DEST_COLOR, -} - -enum compare_mode_t { - ALWAYS, - NEVER, - EQUAL, - NOT_EQUAL, - LESS, - LESS_EQUAL, - GREATER, - GREATER_EQUAL, -} - -enum cull_mode_t { - CLOCKWISE, - COUNTER_CLOCKWISE, - NONE, -} - -enum shader_type_t { - FRAGMENT, - VERTEX, -} diff --git a/base/sources/ts/iron/input.ts b/base/sources/ts/iron/input.ts index fe45f6ba..45837eae 100644 --- a/base/sources/ts/iron/input.ts +++ b/base/sources/ts/iron/input.ts @@ -95,7 +95,7 @@ function mouse_released(button: string = "left"): bool { function mouse_lock() { if (kinc_mouse_can_lock()) { - sys_lock_mouse(); + kinc_mouse_lock(); mouse_locked = true; mouse_hidden = true; } @@ -103,19 +103,19 @@ function mouse_lock() { function mouse_unlock() { if (kinc_mouse_can_lock()) { - sys_unlock_mouse(); + kinc_mouse_unlock(); mouse_locked = false; mouse_hidden = false; } } function mouse_hide() { - sys_hide_system_cursor(); + iron_show_mouse(false); mouse_hidden = true; } function mouse_show() { - sys_show_system_cursor(); + iron_show_mouse(true); mouse_hidden = false; } diff --git a/base/sources/ts/iron/iron.ts b/base/sources/ts/iron/iron.ts index ecb5be88..5f1633e7 100644 --- a/base/sources/ts/iron/iron.ts +++ b/base/sources/ts/iron/iron.ts @@ -221,7 +221,7 @@ declare function iron_g4_delete_vertex_buffer(buffer: any): void; declare function iron_g4_lock_vertex_buffer(buffer: any): buffer_t; declare function kinc_g4_vertex_buffer_unlock_all(buffer: any): void; declare function kinc_g4_set_vertex_buffer(buffer: any): void; -declare function iron_g4_draw_indexed_vertices(start: i32, count: i32): void; +declare function iron_g4_draw_indexed_vertices(start: i32 = 0, count: i32 = -1): void; declare function iron_g4_create_shader(data: buffer_t, type: i32): kinc_g5_shader_t; declare function iron_g4_create_shader_from_source(source: string, shader_type: shader_type_t): kinc_g5_shader_t; declare function kinc_g5_shader_destroy(shader: kinc_g5_shader_t): void; @@ -251,7 +251,7 @@ declare function iron_g4_set_float(location: any, value: f32): void; declare function iron_g4_set_float2(location: any, value1: f32, value2: f32): void; declare function iron_g4_set_float3(location: any, value1: f32, value2: f32, value3: f32): void; declare function iron_g4_set_float4(location: any, value1: f32, value2: f32, value3: f32, value4: f32): void; -declare function iron_g4_set_floats(location: any, values: buffer_t): void; +declare function iron_g4_set_floats(location: any, values: f32_array_t): void; declare function iron_g4_set_matrix4(location: any, matrix: mat4_t): void; declare function iron_g4_set_matrix3(location: any, matrix: mat3_t): void; @@ -275,9 +275,8 @@ declare function iron_display_frequency(index: i32): i32; declare function iron_display_is_primary(index: i32): bool; declare function iron_g4_create_render_target(width: i32, height: i32, format: i32 = tex_format_t.RGBA32, depth_buffer_bits: i32 = 0): any; -declare function iron_g4_create_texture(width: i32, height: i32, format: i32): any; -declare function iron_g4_create_texture_from_bytes(data: buffer_t, width: i32, height: i32, format: i32, readable: bool): any; -declare function iron_g4_create_texture_from_encoded_bytes(data: buffer_t, format: string, readable: bool): any; +declare function iron_g4_create_texture_from_bytes(data: buffer_t, width: i32, height: i32, format: i32 = tex_format_t.RGBA32, readable: bool = true): any; +declare function iron_g4_create_texture_from_encoded_bytes(data: buffer_t, format: string, readable: bool = false): any; declare function iron_g4_get_texture_pixels(texture: any): buffer_t; declare function kinc_g5_texture_generate_mipmaps(texture: any, levels: i32): void; declare function iron_g4_set_mipmaps(texture: any, mipmaps: kinc_g5_texture_t[]): void; @@ -567,3 +566,184 @@ type vec4_box_t = { declare function f32_nan(): f32; declare function f32_isnan(f: f32): bool; + + +function g4_vertex_struct_create(): kinc_g5_vertex_structure_t { + let raw: kinc_g5_vertex_structure_t = {}; + return raw; +} + +function g4_vertex_struct_add(raw: kinc_g5_vertex_structure_t, name: string, data: vertex_data_t) { + let e: kinc_g5_vertex_element_t = ADDRESS(ARRAY_ACCESS(raw.elements, raw.size)); + e.name = name; + e.data = data; + raw.size++; +} + +function g4_vertex_struct_byte_size(raw: kinc_g5_vertex_structure_t): i32 { + let byte_size: i32 = 0; + for (let i: i32 = 0; i < raw.size; ++i) { + let elem: kinc_g5_vertex_element_t = ADDRESS(ARRAY_ACCESS(raw.elements, i)); + byte_size += g4_vertex_struct_data_byte_size(elem.data); + } + return byte_size; +} + +function g4_vertex_struct_data_byte_size(data: vertex_data_t): i32 { + if (data == vertex_data_t.F32_1X) { + return 1 * 4; + } + if (data == vertex_data_t.F32_2X) { + return 2 * 4; + } + if (data == vertex_data_t.F32_3X) { + return 3 * 4; + } + if (data == vertex_data_t.F32_4X) { + return 4 * 4; + } + if (data == vertex_data_t.U8_4X_NORM) { + return 4 * 1; + } + if (data == vertex_data_t.I16_2X_NORM) { + return 2 * 2; + } + if (data == vertex_data_t.I16_4X_NORM) { + return 4 * 2; + } + return 0; +} + +declare type kinc_g5_pipeline_t = { + input_layout?: any; + vertex_shader?: any; + fragment_shader?: any; + + cull_mode?: cull_mode_t; + depth_write?: bool; + depth_mode?: compare_mode_t; + + blend_source?: blend_factor_t; + blend_destination?: blend_factor_t; + alpha_blend_source?: blend_factor_t; + alpha_blend_destination?: blend_factor_t; + + color_write_mask_red?: any; + color_write_mask_green?: any; + color_write_mask_blue?: any; + color_write_mask_alpha?: any; + + color_attachment?: any; + color_attachment_count?: i32; + depth_attachment_bits?: i32; + + impl?: any; +}; + +declare type kinc_g5_shader_t = { + impl?: any; +}; + +declare type kinc_g5_vertex_element_t = { + name?: string; + data?: vertex_data_t; +}; + +declare type kinc_g5_vertex_structure_t = { + elements?: any; // kinc_g5_vertex_element_t[KINC_G5_MAX_VERTEX_ELEMENTS]; + size?: i32; +}; + +declare type kinc_g5_index_buffer_t = { + impl?: any; +}; + +declare type kinc_g5_vertex_buffer_t = { + impl?: any; +}; + +declare type kinc_g5_constant_location_t = any; +declare type kinc_g5_texture_unit_t = any; + +enum clear_flag_t { + COLOR = 1, + DEPTH = 2, +} + +enum tex_filter_t { + POINT, + LINEAR, + ANISOTROPIC, +} + +enum mip_map_filter_t { + NONE, + POINT, + LINEAR, +} + +enum tex_addressing_t { + REPEAT, + MIRROR, + CLAMP, +} + +enum usage_t { + STATIC, + DYNAMIC, + READABLE, +} + +enum tex_format_t { + RGBA32, + RGBA64, + RGBA128, + R8, + R16, + R32, +} + +enum vertex_data_t { + F32_1X, + F32_2X, + F32_3X, + F32_4X, + U8_4X_NORM, + I16_2X_NORM, + I16_4X_NORM, +} + +enum blend_factor_t { + BLEND_ONE, + BLEND_ZERO, + SOURCE_ALPHA, + DEST_ALPHA, + INV_SOURCE_ALPHA, + INV_DEST_ALPHA, + SOURCE_COLOR, + DEST_COLOR, + INV_SOURCE_COLOR, + INV_DEST_COLOR, +} + +enum compare_mode_t { + ALWAYS, + NEVER, + EQUAL, + NOT_EQUAL, + LESS, + LESS_EQUAL, + GREATER, + GREATER_EQUAL, +} + +enum cull_mode_t { + CLOCKWISE, + COUNTER_CLOCKWISE, + NONE, +} + +enum shader_type_t { + FRAGMENT, + VERTEX, +} diff --git a/base/sources/ts/iron/mesh_object.ts b/base/sources/ts/iron/mesh_object.ts index 7a18aeb6..2bc047a3 100644 --- a/base/sources/ts/iron/mesh_object.ts +++ b/base/sources/ts/iron/mesh_object.ts @@ -183,7 +183,7 @@ function mesh_object_render(raw: mesh_object_t, context: string, bind_params: st kinc_g4_set_vertex_buffer(mesh_data_get(raw.data, elems)); kinc_g4_set_index_buffer(raw.data._.index_buffers[i]); - g4_draw(); + iron_g4_draw_indexed_vertices(); } raw.prev_matrix = mat4_clone(raw.base.transform.world_unpack); diff --git a/base/sources/ts/iron/render_path.ts b/base/sources/ts/iron/render_path.ts index 871f3828..57531a39 100644 --- a/base/sources/ts/iron/render_path.ts +++ b/base/sources/ts/iron/render_path.ts @@ -218,7 +218,7 @@ function render_path_draw_skydome(handle: string) { uniforms_set_obj_consts(cc.context, null); // External hosek kinc_g4_set_vertex_buffer(const_data_skydome_vb); kinc_g4_set_index_buffer(const_data_skydome_ib); - g4_draw(); + iron_g4_draw_indexed_vertices(); render_path_end(); } @@ -244,7 +244,7 @@ function render_path_draw_shader(handle: string) { uniforms_set_obj_consts(cc.context, null); kinc_g4_set_vertex_buffer(const_data_screen_aligned_vb); kinc_g4_set_index_buffer(const_data_screen_aligned_ib); - g4_draw(); + iron_g4_draw_indexed_vertices(); render_path_end(); } diff --git a/base/sources/ts/iron/scene.ts b/base/sources/ts/iron/scene.ts index c9d3daf8..f67859bd 100644 --- a/base/sources/ts/iron/scene.ts +++ b/base/sources/ts/iron/scene.ts @@ -600,8 +600,8 @@ type shader_context_t = { type shader_context_runtime_t = { pipe_state?: kinc_g5_pipeline_t; - constants?: kinc_const_loc_t[]; - tex_units?: kinc_tex_unit_t[]; + constants?: kinc_g5_constant_location_t[]; + tex_units?: kinc_g5_texture_unit_t[]; override_context?: _shader_override_t; structure?: kinc_g5_vertex_structure_t; }; diff --git a/base/sources/ts/iron/sys.ts b/base/sources/ts/iron/sys.ts index b9833c40..72c615d7 100644 --- a/base/sources/ts/iron/sys.ts +++ b/base/sources/ts/iron/sys.ts @@ -14,9 +14,6 @@ let _sys_pause_listeners: sys_callback_t[] = []; let _sys_background_listeners: sys_callback_t[] = []; let _sys_shutdown_listeners: sys_callback_t[] = []; let _sys_drop_files_listeners: sys_string_callback_t[] = []; -let _sys_cut_listener: ()=>string = null; -let _sys_copy_listener: ()=>string = null; -let _sys_paste_listener: (data: string)=>void = null; let _sys_start_time: f32; let _sys_window_title: string; @@ -55,7 +52,6 @@ function sys_start(ops: kinc_window_options_t) { ); iron_set_update_callback(sys_render_callback); iron_set_drop_files_callback(sys_drop_files_callback); - iron_set_cut_copy_paste_callback(sys_cut_callback, sys_copy_callback, sys_paste_callback); iron_set_application_state_callback(sys_foreground_callback, sys_resume_callback, sys_pause_callback, sys_background_callback, sys_shutdown_callback); iron_set_keyboard_down_callback(sys_keyboard_down_callback); iron_set_keyboard_up_callback(sys_keyboard_up_callback); @@ -109,12 +105,6 @@ function sys_notify_on_drop_files(drop_files_listener: (s: string)=>void) { array_push(_sys_drop_files_listeners, cb); } -function sys_notify_on_cut_copy_paste(on_cut: ()=>string, on_copy: ()=>string, on_paste: (data: string)=>void) { - _sys_cut_listener = on_cut; - _sys_copy_listener = on_copy; - _sys_paste_listener = on_paste; -} - function sys_foreground() { for (let i: i32 = 0; i < _sys_foreground_listeners.length; ++i) { _sys_foreground_listeners[i].f(); @@ -165,26 +155,6 @@ function sys_drop_files_callback(file_path: string) { sys_drop_files(file_path); } -function sys_copy_callback(): string { - if (_sys_copy_listener != null) { - return _sys_copy_listener(); - } - return null; -} - -function sys_cut_callback(): string { - if (_sys_cut_listener != null) { - return _sys_cut_listener(); - } - return null; -} - -function sys_paste_callback(data: string) { - if (_sys_paste_listener != null) { - _sys_paste_listener(data); - } -} - function sys_foreground_callback() { sys_foreground(); } @@ -271,26 +241,6 @@ function sys_gamepad_button_callback(gamepad: i32, button: i32, value: f32) { gamepad_button_listener(gamepad, button, value); } -function sys_lock_mouse() { - if (!kinc_mouse_is_locked()) { - kinc_mouse_lock(); - } -} - -function sys_unlock_mouse() { - if (kinc_mouse_is_locked()) { - kinc_mouse_unlock(); - } -} - -function sys_hide_system_cursor() { - iron_show_mouse(false); -} - -function sys_show_system_cursor() { - iron_show_mouse(true); -} - function sys_title(): string { return _sys_window_title; } diff --git a/base/sources/ts/iron/uniforms.ts b/base/sources/ts/iron/uniforms.ts index 0c9c71e4..96f18db2 100644 --- a/base/sources/ts/iron/uniforms.ts +++ b/base/sources/ts/iron/uniforms.ts @@ -153,7 +153,7 @@ function uniforms_bind_render_target(rt: render_target_t, context: shader_contex } } -function uniforms_set_context_const(location: kinc_const_loc_t, c: shader_const_t): bool { +function uniforms_set_context_const(location: kinc_g5_constant_location_t, c: shader_const_t): bool { if (c.link == null) { return true; } @@ -323,7 +323,7 @@ function uniforms_set_context_const(location: kinc_const_loc_t, c: shader_const_ } if (fa != null) { - g4_set_floats(location, fa); + iron_g4_set_floats(location, fa); return true; } } @@ -344,7 +344,7 @@ function uniforms_set_context_const(location: kinc_const_loc_t, c: shader_const_ return false; } -function uniforms_set_obj_const(obj: object_t, loc: kinc_const_loc_t, c: shader_const_t) { +function uniforms_set_obj_const(obj: object_t, loc: kinc_g5_constant_location_t, c: shader_const_t) { if (c.link == null) { return; } @@ -488,7 +488,7 @@ function uniforms_set_obj_const(obj: object_t, loc: kinc_const_loc_t, c: shader_ if (fa == null) { return; } - g4_set_floats(loc, fa); + iron_g4_set_floats(loc, fa); } else if (c.type == "int") { let i: i32 = INT_MAX; @@ -556,7 +556,7 @@ function current_material(object: object_t): material_data_t { return null; } -function uniforms_set_material_const(location: kinc_const_loc_t, shader_const: shader_const_t, material_const: bind_const_t) { +function uniforms_set_material_const(location: kinc_g5_constant_location_t, shader_const: shader_const_t, material_const: bind_const_t) { if (shader_const.type == "vec4") { iron_g4_set_float4(location, material_const.vec[0], material_const.vec[1], material_const.vec[2], material_const.vec[3]); } diff --git a/base/sources/ts/layers.ts b/base/sources/ts/layers.ts index 71dd3446..e058c4db 100644 --- a/base/sources/ts/layers.ts +++ b/base/sources/ts/layers.ts @@ -261,7 +261,7 @@ function layers_apply_mask(l: slot_layer_t, m: slot_layer_t) { iron_g4_set_texture(pipes_texa_mask, m.texpaint); kinc_g4_set_vertex_buffer(const_data_screen_aligned_vb); kinc_g4_set_index_buffer(const_data_screen_aligned_ib); - g4_draw(); + iron_g4_draw_indexed_vertices(); iron_g4_end(); } @@ -276,7 +276,7 @@ function layers_commands_merge_pack(pipe: kinc_g5_pipeline_t, i0: kinc_g5_textur iron_g4_set_int(pipes_blending, i1blending); kinc_g4_set_vertex_buffer(const_data_screen_aligned_vb); kinc_g4_set_index_buffer(const_data_screen_aligned_ib); - g4_draw(); + iron_g4_draw_indexed_vertices(); iron_g4_end(); } @@ -737,7 +737,7 @@ function layers_merge_layer(l0 : slot_layer_t, l1: slot_layer_t, use_mask: bool iron_g4_set_int(pipes_blending_merge_mask, l1.blending); kinc_g4_set_vertex_buffer(const_data_screen_aligned_vb); kinc_g4_set_index_buffer(const_data_screen_aligned_ib); - g4_draw(); + iron_g4_draw_indexed_vertices(); iron_g4_end(); } @@ -753,7 +753,7 @@ function layers_merge_layer(l0 : slot_layer_t, l1: slot_layer_t, use_mask: bool iron_g4_set_int(pipes_blending, l1.blending); kinc_g4_set_vertex_buffer(const_data_screen_aligned_vb); kinc_g4_set_index_buffer(const_data_screen_aligned_ib); - g4_draw(); + iron_g4_draw_indexed_vertices(); iron_g4_end(); } @@ -775,7 +775,7 @@ function layers_merge_layer(l0 : slot_layer_t, l1: slot_layer_t, use_mask: bool iron_g4_set_int(pipes_blending, l1.paint_nor_blend ? -2 : -1); kinc_g4_set_vertex_buffer(const_data_screen_aligned_vb); kinc_g4_set_index_buffer(const_data_screen_aligned_ib); - g4_draw(); + iron_g4_draw_indexed_vertices(); iron_g4_end(); } } diff --git a/base/sources/ts/line_draw.ts b/base/sources/ts/line_draw.ts index 46f78553..bd204973 100644 --- a/base/sources/ts/line_draw.ts +++ b/base/sources/ts/line_draw.ts @@ -10,8 +10,8 @@ let line_draw_pipeline: kinc_g5_pipeline_t = null; let line_draw_overlay_pipeline: kinc_g5_pipeline_t = null; let line_draw_vp: mat4_t; -let line_draw_vp_loc: kinc_const_loc_t; -let line_draw_color_loc: kinc_const_loc_t; +let line_draw_vp_loc: kinc_g5_constant_location_t; +let line_draw_color_loc: kinc_g5_constant_location_t; let line_draw_vb_data: buffer_t; let line_draw_ib_data: u32_array_t; @@ -237,12 +237,12 @@ function line_draw_end(overlay: bool = false) { line_draw_vp = mat4_clone(camera.v); line_draw_vp = mat4_mult_mat(line_draw_vp, camera.p); iron_g4_set_matrix4(line_draw_vp_loc, line_draw_vp); - g4_set_vec3(line_draw_color_loc, vec4_create( + iron_g4_set_float3(line_draw_color_loc, color_get_rb(line_draw_color) / 255, color_get_gb(line_draw_color) / 255, color_get_bb(line_draw_color) / 255 - )); - g4_draw(0, line_draw_lines * 6); + ); + iron_g4_draw_indexed_vertices(0, line_draw_lines * 6); } let _shape_draw_sphere_vb: kinc_g5_vertex_buffer_t = null; @@ -279,10 +279,10 @@ function shape_draw_sphere(mat: mat4_t) { line_draw_vp = mat4_mult_mat(line_draw_vp, camera.v); line_draw_vp = mat4_mult_mat(line_draw_vp, camera.p); iron_g4_set_matrix4(line_draw_vp_loc, line_draw_vp); - g4_set_vec3(line_draw_color_loc, vec4_create( + iron_g4_set_float3(line_draw_color_loc, color_get_rb(line_draw_color) / 255, color_get_gb(line_draw_color) / 255, color_get_bb(line_draw_color) / 255 - )); - g4_draw(); + ); + iron_g4_draw_indexed_vertices(); } \ No newline at end of file diff --git a/base/sources/ts/nodes/color_node.ts b/base/sources/ts/nodes/color_node.ts index a39ace2a..e133b467 100644 --- a/base/sources/ts/nodes/color_node.ts +++ b/base/sources/ts/nodes/color_node.ts @@ -41,7 +41,7 @@ function color_node_get_as_image(self: color_node_t, from: i32): kinc_g5_texture buffer_set_f32(b, 4, self.value.y); buffer_set_f32(b, 8, self.value.z); buffer_set_f32(b, 12, self.value.w); - self.image = image_from_bytes(b, 1, 1, tex_format_t.RGBA128); + self.image = iron_g4_create_texture_from_bytes(b, 1, 1, tex_format_t.RGBA128); return self.image; } diff --git a/base/sources/ts/nodes/float_node.ts b/base/sources/ts/nodes/float_node.ts index 7e44df0e..13622b18 100644 --- a/base/sources/ts/nodes/float_node.ts +++ b/base/sources/ts/nodes/float_node.ts @@ -37,7 +37,7 @@ function float_node_get_as_image(self: float_node_t, from: i32): kinc_g5_texture buffer_set_f32(b, 4, self.value); buffer_set_f32(b, 8, self.value); buffer_set_f32(b, 12, 1.0); - self.image = image_from_bytes(b, 1, 1, tex_format_t.RGBA128); + self.image = iron_g4_create_texture_from_bytes(b, 1, 1, tex_format_t.RGBA128); return self.image; } diff --git a/base/sources/ts/nodes/vector_node.ts b/base/sources/ts/nodes/vector_node.ts index ca3d7cf4..9248b917 100644 --- a/base/sources/ts/nodes/vector_node.ts +++ b/base/sources/ts/nodes/vector_node.ts @@ -48,7 +48,7 @@ function vector_node_get_as_image(self: vector_node_t, from: i32): kinc_g5_textu buffer_set_f32(b, 4, n1.value); buffer_set_f32(b, 8, n2.value); buffer_set_f32(b, 12, 1.0); - self.image = image_from_bytes(b, 1, 1, tex_format_t.RGBA128); + self.image = iron_g4_create_texture_from_bytes(b, 1, 1, tex_format_t.RGBA128); return self.image; } diff --git a/base/sources/ts/pipes.ts b/base/sources/ts/pipes.ts index 87cce9ec..0e622650 100644 --- a/base/sources/ts/pipes.ts +++ b/base/sources/ts/pipes.ts @@ -7,7 +7,7 @@ let pipes_copy_rgb: kinc_g5_pipeline_t = null; let pipes_copy_r: kinc_g5_pipeline_t; let pipes_copy_g: kinc_g5_pipeline_t; let pipes_copy_a: kinc_g5_pipeline_t; -let pipes_copy_a_tex: kinc_tex_unit_t; +let pipes_copy_a_tex: kinc_g5_texture_unit_t; let pipes_merge: kinc_g5_pipeline_t = null; let pipes_merge_r: kinc_g5_pipeline_t = null; @@ -19,35 +19,35 @@ let pipes_invert8: kinc_g5_pipeline_t; let pipes_apply_mask: kinc_g5_pipeline_t; let pipes_colorid_to_mask: kinc_g5_pipeline_t; -let pipes_tex0: kinc_tex_unit_t; -let pipes_tex1: kinc_tex_unit_t; -let pipes_texmask: kinc_tex_unit_t; -let pipes_texa: kinc_tex_unit_t; -let pipes_opac: kinc_const_loc_t; -let pipes_blending: kinc_const_loc_t; -let pipes_tex0_mask: kinc_tex_unit_t; -let pipes_texa_mask: kinc_tex_unit_t; -let pipes_tex0_merge_mask: kinc_tex_unit_t; -let pipes_texa_merge_mask: kinc_tex_unit_t; -let pipes_tex_colorid: kinc_tex_unit_t; -let pipes_texpaint_colorid: kinc_tex_unit_t; -let pipes_opac_merge_mask: kinc_const_loc_t; -let pipes_blending_merge_mask: kinc_const_loc_t; +let pipes_tex0: kinc_g5_texture_unit_t; +let pipes_tex1: kinc_g5_texture_unit_t; +let pipes_texmask: kinc_g5_texture_unit_t; +let pipes_texa: kinc_g5_texture_unit_t; +let pipes_opac: kinc_g5_constant_location_t; +let pipes_blending: kinc_g5_constant_location_t; +let pipes_tex0_mask: kinc_g5_texture_unit_t; +let pipes_texa_mask: kinc_g5_texture_unit_t; +let pipes_tex0_merge_mask: kinc_g5_texture_unit_t; +let pipes_texa_merge_mask: kinc_g5_texture_unit_t; +let pipes_tex_colorid: kinc_g5_texture_unit_t; +let pipes_texpaint_colorid: kinc_g5_texture_unit_t; +let pipes_opac_merge_mask: kinc_g5_constant_location_t; +let pipes_blending_merge_mask: kinc_g5_constant_location_t; let pipes_temp_mask_image: kinc_g5_texture_t = null; let pipes_inpaint_preview: kinc_g5_pipeline_t; -let pipes_tex0_inpaint_preview: kinc_tex_unit_t; -let pipes_texa_inpaint_preview: kinc_tex_unit_t; +let pipes_tex0_inpaint_preview: kinc_g5_texture_unit_t; +let pipes_texa_inpaint_preview: kinc_g5_texture_unit_t; let pipes_cursor: kinc_g5_pipeline_t; -let pipes_cursor_vp: kinc_const_loc_t; -let pipes_cursor_inv_vp: kinc_const_loc_t; -let pipes_cursor_mouse: kinc_const_loc_t; -let pipes_cursor_tex_step: kinc_const_loc_t; -let pipes_cursor_radius: kinc_const_loc_t; -let pipes_cursor_camera_right: kinc_const_loc_t; -let pipes_cursor_tint: kinc_const_loc_t; -let pipes_cursor_gbufferd: kinc_tex_unit_t; +let pipes_cursor_vp: kinc_g5_constant_location_t; +let pipes_cursor_inv_vp: kinc_g5_constant_location_t; +let pipes_cursor_mouse: kinc_g5_constant_location_t; +let pipes_cursor_tex_step: kinc_g5_constant_location_t; +let pipes_cursor_radius: kinc_g5_constant_location_t; +let pipes_cursor_camera_right: kinc_g5_constant_location_t; +let pipes_cursor_tint: kinc_g5_constant_location_t; +let pipes_cursor_gbufferd: kinc_g5_texture_unit_t; function _pipes_make_merge(red: bool, green: bool, blue: bool, alpha: bool): kinc_g5_pipeline_t { let pipe: kinc_g5_pipeline_t = iron_g4_create_pipeline(); diff --git a/base/sources/ts/render_path_deferred.ts b/base/sources/ts/render_path_deferred.ts index dc593e62..bac97f4e 100644 --- a/base/sources/ts/render_path_deferred.ts +++ b/base/sources/ts/render_path_deferred.ts @@ -89,7 +89,7 @@ function render_path_deferred_init() { t.format = "R8"; let b: buffer_t = buffer_create(1); buffer_set_u8(b, 0, 255); - t._image = image_from_bytes(b, t.width, t.height, tex_format_t.R8); + t._image = iron_g4_create_texture_from_bytes(b, t.width, t.height, tex_format_t.R8); map_set(render_path_render_targets, t.name, t); } { @@ -103,7 +103,7 @@ function render_path_deferred_init() { buffer_set_u8(b, 1, 0); buffer_set_u8(b, 2, 0); buffer_set_u8(b, 3, 0); - t._image = image_from_bytes(b, t.width, t.height, tex_format_t.RGBA32); + t._image = iron_g4_create_texture_from_bytes(b, t.width, t.height, tex_format_t.RGBA32); map_set(render_path_render_targets, t.name, t); } diff --git a/base/sources/ts/tab_swatches.ts b/base/sources/ts/tab_swatches.ts index 7eab7b7c..cbce67b7 100644 --- a/base/sources/ts/tab_swatches.ts +++ b/base/sources/ts/tab_swatches.ts @@ -14,7 +14,7 @@ function tab_swatches_empty_get(): kinc_g5_texture_t { b[1] = 255; b[2] = 255; b[3] = 255; - _tab_swatches_empty = image_from_bytes(b, 1, 1); + _tab_swatches_empty = iron_g4_create_texture_from_bytes(b, 1, 1); } return _tab_swatches_empty; } diff --git a/base/sources/ts/ui_base.ts b/base/sources/ts/ui_base.ts index 480e9944..e85282c9 100644 --- a/base/sources/ts/ui_base.ts +++ b/base/sources/ts/ui_base.ts @@ -131,7 +131,7 @@ function ui_base_init() { b[1] = 0; b[2] = 0; b[3] = 255; - context_raw.preview_envmap = image_from_bytes(b, 1, 1); + context_raw.preview_envmap = iron_g4_create_texture_from_bytes(b, 1, 1); } let world: world_data_t = scene_world; @@ -1579,7 +1579,7 @@ function ui_base_make_empty_envmap(col: i32) { b[1] = color_get_gb(col); b[2] = color_get_bb(col); b[3] = 255; - context_raw.empty_envmap = image_from_bytes(b, 1, 1); + context_raw.empty_envmap = iron_g4_create_texture_from_bytes(b, 1, 1); } function ui_base_set_viewport_col(col: i32) { diff --git a/base/sources/ts/ui_files.ts b/base/sources/ts/ui_files.ts index b7950892..f6b6d5f6 100644 --- a/base/sources/ts/ui_files.ts +++ b/base/sources/ts/ui_files.ts @@ -266,21 +266,21 @@ function ui_files_file_browser(ui: ui_t, handle: ui_handle_t, drag_files: bool = let raw: project_format_t = armpack_decode(buffer); if (raw.material_icons != null) { let bytes_icon: any = raw.material_icons[0]; - icon = image_from_bytes(lz4_decode(bytes_icon, 256 * 256 * 4), 256, 256); + icon = iron_g4_create_texture_from_bytes(lz4_decode(bytes_icon, 256 * 256 * 4), 256, 256); } else if (raw.mesh_icons != null) { let bytes_icon: any = raw.mesh_icons[0]; - icon = image_from_bytes(lz4_decode(bytes_icon, 256 * 256 * 4), 256, 256); + icon = iron_g4_create_texture_from_bytes(lz4_decode(bytes_icon, 256 * 256 * 4), 256, 256); } else if (raw.brush_icons != null) { let bytes_icon: any = raw.brush_icons[0]; - icon = image_from_bytes(lz4_decode(bytes_icon, 256 * 256 * 4), 256, 256); + icon = iron_g4_create_texture_from_bytes(lz4_decode(bytes_icon, 256 * 256 * 4), 256, 256); } ///if is_lab if (raw.mesh_icon != null) { let bytes_icon: buffer_t = raw.mesh_icon; - icon = image_from_bytes(lz4_decode(bytes_icon, 256 * 256 * 4), 256, 256); + icon = iron_g4_create_texture_from_bytes(lz4_decode(bytes_icon, 256 * 256 * 4), 256, 256); } ///end diff --git a/base/sources/ts/ui_view2d.ts b/base/sources/ts/ui_view2d.ts index 605d28c7..b5d55c4f 100644 --- a/base/sources/ts/ui_view2d.ts +++ b/base/sources/ts/ui_view2d.ts @@ -1,6 +1,6 @@ let ui_view2d_pipe: kinc_g5_pipeline_t; -let ui_view2d_channel_loc: kinc_const_loc_t; +let ui_view2d_channel_loc: kinc_g5_constant_location_t; let ui_view2d_text_input_hover: bool = false; let ui_view2d_uvmap_show: bool = false; let ui_view2d_tex_type: paint_tex_t = paint_tex_t.BASE; diff --git a/base/sources/ts/util_render.ts b/base/sources/ts/util_render.ts index f29fa310..095fcc31 100644 --- a/base/sources/ts/util_render.ts +++ b/base/sources/ts/util_render.ts @@ -410,7 +410,7 @@ function util_render_make_node_preview(canvas: ui_node_canvas_t, node: ui_node_t uniforms_set_material_consts(res.scon, res.mcon); kinc_g4_set_vertex_buffer(util_render_screen_aligned_full_vb); kinc_g4_set_index_buffer(util_render_screen_aligned_full_ib); - g4_draw(); + iron_g4_draw_indexed_vertices(); iron_g4_end(); context_raw.paint_object.base.transform.scale_world = _scale_world; diff --git a/base/sources/ts/util_uv.ts b/base/sources/ts/util_uv.ts index 98a0f874..27a31cff 100644 --- a/base/sources/ts/util_uv.ts +++ b/base/sources/ts/util_uv.ts @@ -145,7 +145,7 @@ function util_uv_cache_dilate_map() { kinc_g4_set_vertex_buffer(geom._.vertex_buffer); ///end kinc_g4_set_index_buffer(geom._.index_buffers[0]); - g4_draw(); + iron_g4_draw_indexed_vertices(); iron_g4_end(); util_uv_dilatemap_cached = true; util_uv_dilate_bytes = null; @@ -200,6 +200,6 @@ function util_uv_cache_uv_island_map() { if (util_uv_uvislandmap != null) { iron_unload_image(util_uv_uvislandmap); } - util_uv_uvislandmap = image_from_bytes(bytes, w, h, tex_format_t.R8); + util_uv_uvislandmap = iron_g4_create_texture_from_bytes(bytes, w, h, tex_format_t.R8); util_uv_uvislandmap_cached = true; } diff --git a/base/tools/pad/sources/main.ts b/base/tools/pad/sources/main.ts index 5ef293d7..1fe954d9 100644 --- a/base/tools/pad/sources/main.ts +++ b/base/tools/pad/sources/main.ts @@ -91,7 +91,7 @@ function main() { }; sys_start(ops); - let font: g2_font_t = data_get_font("font_mono.ttf"); + let font: draw_font_t = data_get_font("font_mono.ttf"); g2_font_init(font); theme = {}; @@ -341,7 +341,7 @@ function draw_minimap() { let x: i32 = 0; for (let j: i32 = 0; j < words.length; ++j) { let word: string = words[j]; - g2_fill_rect(x, i * 2, word.length, 2); + draw_filled_rect(x, i * 2, word.length, 2); x += word.length + 1; } } @@ -350,7 +350,7 @@ function draw_minimap() { let visible_area: i32 = out_of_screen > 0 ? minimap_h : minimap_full_h; draw_set_color(0x11ffffff); minimap_box_h = math_floor((kinc_window_height() - window_header_h) / UI_ELEMENT_H() * 2); - g2_fill_rect(0, scroll_progress * visible_area, minimap_w, minimap_box_h); + draw_filled_rect(0, scroll_progress * visible_area, minimap_w, minimap_box_h); g2_end(); }