From 5d2407e72966b7c561babbbb6c6eaa24a0e497d5 Mon Sep 17 00:00:00 2001 From: luboslenco Date: Thu, 6 Mar 2025 20:18:45 +0100 Subject: [PATCH] Cleanup --- armorlab/sources/nodes/inpaint_node.ts | 6 +- armorlab/sources/ui_nodes_ext.ts | 2 +- armorpaint/sources/layers_ext.ts | 20 +- armorpaint/sources/ui_header_ext.ts | 2 +- base/sources/backends/direct3d12_gpu.c | 132 ++++-------- base/sources/backends/direct3d12_gpu.h | 1 - base/sources/backends/metal_gpu.m | 55 ++--- base/sources/backends/vulkan_gpu.c | 152 +++++-------- base/sources/backends/vulkan_gpu.h | 4 - base/sources/backends/webgpu_gpu.c | 7 +- base/sources/iron.h | 211 ++++++++++--------- base/sources/iron_draw.c | 57 +---- base/sources/iron_draw.h | 8 - base/sources/iron_gpu.c | 71 ++----- base/sources/iron_gpu.h | 12 +- base/sources/iron_ui.c | 152 +++++-------- base/sources/iron_ui.h | 6 +- base/sources/iron_ui_nodes.c | 8 +- base/sources/ts/export_texture.ts | 24 +-- base/sources/ts/import_envmap.ts | 2 +- base/sources/ts/iron/g2.ts | 2 +- base/sources/ts/iron/g4.ts | 71 +------ base/sources/ts/iron/iron.ts | 7 +- base/sources/ts/iron/render_path.ts | 4 +- base/sources/ts/iron/ui.ts | 17 +- base/sources/ts/layers.ts | 26 +-- base/sources/ts/render_path_raytrace.ts | 2 +- base/sources/ts/render_path_raytrace_bake.ts | 2 +- base/sources/ts/slot_layer.ts | 14 +- base/sources/ts/ui_base.ts | 4 +- base/sources/ts/ui_files.ts | 4 +- base/sources/ts/ui_nodes.ts | 2 +- base/sources/ts/util_render.ts | 8 +- base/sources/ts/util_uv.ts | 8 +- base/tests/triangle/main.ts | 2 +- base/tools/pad/sources/main.ts | 2 +- 36 files changed, 386 insertions(+), 721 deletions(-) diff --git a/armorlab/sources/nodes/inpaint_node.ts b/armorlab/sources/nodes/inpaint_node.ts index 0286eac6..f9270973 100644 --- a/armorlab/sources/nodes/inpaint_node.ts +++ b/armorlab/sources/nodes/inpaint_node.ts @@ -33,8 +33,8 @@ function inpaint_node_init() { if (inpaint_node_mask == null) { inpaint_node_mask = image_create_render_target(config_get_texture_res_x(), config_get_texture_res_y(), tex_format_t.R8); app_notify_on_next_frame(function () { - g4_begin(inpaint_node_mask); - g4_clear(color_from_floats(1.0, 1.0, 1.0, 1.0)); + iron_g4_begin(inpaint_node_mask); + kinc_g5_clear(color_from_floats(1.0, 1.0, 1.0, 1.0)); iron_g4_end(); }); } @@ -87,7 +87,7 @@ function inpaint_node_get_as_image(self: inpaint_node_t, from: i32): image_t { function inpaint_node_get_cached_image(self: inpaint_node_t): image_t { app_notify_on_next_frame(function (self: inpaint_node_t) { let source: image_t = logic_node_input_get_as_image(self.base.inputs[0]); - g4_begin(inpaint_node_image); + iron_g4_begin(inpaint_node_image); kinc_g5_set_pipeline(pipes_inpaint_preview); g4_set_tex(pipes_tex0_inpaint_preview, source); g4_set_tex(pipes_texa_inpaint_preview, inpaint_node_mask); diff --git a/armorlab/sources/ui_nodes_ext.ts b/armorlab/sources/ui_nodes_ext.ts index f5e5d648..d6eb6a6b 100644 --- a/armorlab/sources/ui_nodes_ext.ts +++ b/armorlab/sources/ui_nodes_ext.ts @@ -78,7 +78,7 @@ function ui_nodes_ext_run() { } if (texheight != null) { - g4_begin(texpaint_pack._image); + iron_g4_begin(texpaint_pack._image); kinc_g5_set_pipeline(pipes_copy_a); g4_set_tex(pipes_copy_a_tex, texheight); kinc_g4_set_vertex_buffer(const_data_screen_aligned_vb); diff --git a/armorpaint/sources/layers_ext.ts b/armorpaint/sources/layers_ext.ts index 58ec8bd0..be66a678 100644 --- a/armorpaint/sources/layers_ext.ts +++ b/armorpaint/sources/layers_ext.ts @@ -10,14 +10,14 @@ function layers_ext_flatten(height_to_normal: bool = false, layers: slot_layer_t let empty: image_t = empty_rt._image; // Clear export layer - g4_begin(layers_expa); - g4_clear(color_from_floats(0.0, 0.0, 0.0, 0.0)); + iron_g4_begin(layers_expa); + kinc_g5_clear(color_from_floats(0.0, 0.0, 0.0, 0.0)); iron_g4_end(); - g4_begin(layers_expb); - g4_clear(color_from_floats(0.5, 0.5, 1.0, 0.0)); + iron_g4_begin(layers_expb); + kinc_g5_clear(color_from_floats(0.5, 0.5, 1.0, 0.0)); iron_g4_end(); - g4_begin(layers_expc); - g4_clear(color_from_floats(1.0, 0.0, 0.0, 0.0)); + iron_g4_begin(layers_expc); + kinc_g5_clear(color_from_floats(1.0, 0.0, 0.0, 0.0)); iron_g4_end(); // Flatten layers @@ -36,7 +36,7 @@ function layers_ext_flatten(height_to_normal: bool = false, layers: slot_layer_t if (l1masks.length > 1) { layers_make_temp_mask_img(); g2_begin(pipes_temp_mask_image); - g4_clear(0x00000000); + kinc_g5_clear(0x00000000); g2_end(); let l1: slot_layer_t = { texpaint: pipes_temp_mask_image }; for (let i: i32 = 0; i < l1masks.length; ++i) { @@ -64,7 +64,7 @@ function layers_ext_flatten(height_to_normal: bool = false, layers: slot_layer_t draw_set_pipeline(null); g2_end(); ///else - g4_begin(layers_expa); + iron_g4_begin(layers_expa); kinc_g5_set_pipeline(pipes_merge); g4_set_tex(pipes_tex0, l1.texpaint); g4_set_tex(pipes_tex1, empty); @@ -86,7 +86,7 @@ function layers_ext_flatten(height_to_normal: bool = false, layers: slot_layer_t draw_set_pipeline(null); g2_end(); - g4_begin(layers_expb); + iron_g4_begin(layers_expb); kinc_g5_set_pipeline(pipes_merge); g4_set_tex(pipes_tex0, l1.texpaint); g4_set_tex(pipes_tex1, l1.texpaint_nor); @@ -149,7 +149,7 @@ function layers_ext_flatten(height_to_normal: bool = false, layers: slot_layer_t draw_set_pipeline(null); g2_end(); - g4_begin(l0.texpaint_nor); + iron_g4_begin(l0.texpaint_nor); kinc_g5_set_pipeline(pipes_merge); g4_set_tex(pipes_tex0, layers_temp_image); g4_set_tex(pipes_tex1, l0.texpaint_pack); diff --git a/armorpaint/sources/ui_header_ext.ts b/armorpaint/sources/ui_header_ext.ts index 2bc3fa90..9ed1e137 100644 --- a/armorpaint/sources/ui_header_ext.ts +++ b/armorpaint/sources/ui_header_ext.ts @@ -52,7 +52,7 @@ function ui_header_draw_tool_properties(ui: ui_t) { } let m: slot_layer_t = layers_new_mask(false, context_raw.layer); app_notify_on_next_frame(function (m: slot_layer_t) { - g4_begin(m.texpaint); + iron_g4_begin(m.texpaint); kinc_g5_set_pipeline(pipes_colorid_to_mask); let rt: render_target_t = map_get(render_path_render_targets, "texpaint_colorid"); g4_set_tex(pipes_texpaint_colorid, rt._image); diff --git a/base/sources/backends/direct3d12_gpu.c b/base/sources/backends/direct3d12_gpu.c index def991f1..397abc9b 100644 --- a/base/sources/backends/direct3d12_gpu.c +++ b/base/sources/backends/direct3d12_gpu.c @@ -601,7 +601,6 @@ void kinc_g5_command_list_init(struct kinc_g5_command_list *list) { list->impl.current_full_scissor.left = -1; for (int i = 0; i < KINC_INTERNAL_G5_TEXTURE_COUNT; ++i) { - list->impl.currentRenderTargets[i] = NULL; list->impl.currentTextures[i] = NULL; list->impl.current_samplers[i] = NULL; } @@ -819,7 +818,6 @@ void kinc_g5_command_list_set_pipeline(struct kinc_g5_command_list *list, kinc_g compute_pipeline_set = false; for (int i = 0; i < KINC_INTERNAL_G5_TEXTURE_COUNT; ++i) { - list->impl.currentRenderTargets[i] = NULL; list->impl.currentTextures[i] = NULL; } kinc_g5_internal_setConstants(list, list->impl._currentPipeline); @@ -1031,7 +1029,6 @@ void kinc_g5_command_list_set_compute_shader(kinc_g5_command_list_t *list, kinc_ compute_pipeline_set = true; for (int i = 0; i < KINC_INTERNAL_G5_TEXTURE_COUNT; ++i) { - list->impl.currentRenderTargets[i] = NULL; list->impl.currentTextures[i] = NULL; } kinc_g5_internal_set_compute_constants(list); @@ -1042,19 +1039,6 @@ void kinc_g5_command_list_compute(kinc_g5_command_list_t *list, int x, int y, in list->impl._commandList->lpVtbl->Dispatch(list->impl._commandList, x, y, z); } -void kinc_g5_command_list_set_texture(kinc_g5_command_list_t *list, kinc_g5_texture_unit_t unit, kinc_g5_texture_t *texture) { - if (unit.stages[KINC_G5_SHADER_TYPE_FRAGMENT] >= 0) { - kinc_g5_internal_texture_set(list, texture, unit.stages[KINC_G5_SHADER_TYPE_FRAGMENT]); - } - else if (unit.stages[KINC_G5_SHADER_TYPE_VERTEX] >= 0) { - kinc_g5_internal_texture_set(list, texture, unit.stages[KINC_G5_SHADER_TYPE_VERTEX]); - } - else if (unit.stages[KINC_G5_SHADER_TYPE_COMPUTE] >= 0) { - kinc_g5_internal_texture_set(list, texture, unit.stages[KINC_G5_SHADER_TYPE_COMPUTE]); - } - kinc_g5_internal_set_textures(list); -} - void kinc_g5_internal_sampler_set(kinc_g5_command_list_t *list, kinc_g5_sampler_t *sampler, int unit); void kinc_g5_command_list_set_sampler(kinc_g5_command_list_t *list, kinc_g5_texture_unit_t unit, kinc_g5_sampler_t *sampler) { @@ -1067,32 +1051,28 @@ void kinc_g5_command_list_set_sampler(kinc_g5_command_list_t *list, kinc_g5_text kinc_g5_internal_set_textures(list); } -void kinc_g5_command_list_set_texture_from_render_target(kinc_g5_command_list_t *list, kinc_g5_texture_unit_t unit, kinc_g5_texture_t *target) { +void kinc_g5_command_list_set_texture(kinc_g5_command_list_t *list, kinc_g5_texture_unit_t unit, kinc_g5_texture_t *texture) { if (unit.stages[KINC_G5_SHADER_TYPE_FRAGMENT] >= 0) { - target->impl.stage = unit.stages[KINC_G5_SHADER_TYPE_FRAGMENT]; - list->impl.currentRenderTargets[target->impl.stage] = target; + texture->impl.stage = unit.stages[KINC_G5_SHADER_TYPE_FRAGMENT]; } else if (unit.stages[KINC_G5_SHADER_TYPE_VERTEX] >= 0) { - target->impl.stage = unit.stages[KINC_G5_SHADER_TYPE_VERTEX]; - list->impl.currentRenderTargets[target->impl.stage] = target; + texture->impl.stage = unit.stages[KINC_G5_SHADER_TYPE_VERTEX]; } - list->impl.currentTextures[target->impl.stage] = NULL; - + else if (unit.stages[KINC_G5_SHADER_TYPE_COMPUTE] >= 0) { + texture->impl.stage = unit.stages[KINC_G5_SHADER_TYPE_COMPUTE]; + } + list->impl.currentTextures[texture->impl.stage] = texture; kinc_g5_internal_set_textures(list); } -void kinc_g5_command_list_set_texture_from_render_target_depth(kinc_g5_command_list_t *list, kinc_g5_texture_unit_t unit, kinc_g5_texture_t *target) { +void kinc_g5_command_list_set_texture_from_render_target_depth(kinc_g5_command_list_t *list, kinc_g5_texture_unit_t unit, kinc_g5_texture_t *texture) { if (unit.stages[KINC_G5_SHADER_TYPE_FRAGMENT] >= 0) { - target->impl.stage_depth = unit.stages[KINC_G5_SHADER_TYPE_FRAGMENT]; - list->impl.currentRenderTargets[target->impl.stage_depth] = target; + texture->impl.stage_depth = unit.stages[KINC_G5_SHADER_TYPE_FRAGMENT]; } else if (unit.stages[KINC_G5_SHADER_TYPE_VERTEX] >= 0) { - target->impl.stage_depth = unit.stages[KINC_G5_SHADER_TYPE_VERTEX]; - list->impl.currentRenderTargets[target->impl.stage_depth] = target; + texture->impl.stage_depth = unit.stages[KINC_G5_SHADER_TYPE_VERTEX]; } - list->impl.currentTextures[target->impl.stage_depth] = NULL; - - kinc_g5_internal_set_textures(list); + list->impl.currentTextures[texture->impl.stage_depth] = texture; } @@ -1826,7 +1806,6 @@ static const int heapSize = 1024; void kinc_g5_internal_reset_textures(struct kinc_g5_command_list *list) { for (int i = 0; i < KINC_INTERNAL_G5_TEXTURE_COUNT; ++i) { - list->impl.currentRenderTargets[i] = NULL; list->impl.currentTextures[i] = NULL; list->impl.current_samplers[i] = NULL; } @@ -1878,7 +1857,7 @@ static int formatByteSize(kinc_image_format_t format) { } void kinc_g5_internal_set_textures(kinc_g5_command_list_t *list) { - if (list->impl.currentRenderTargets[0] != NULL || list->impl.currentTextures[0] != NULL) { + if (list->impl.currentTextures[0] != NULL) { int srvStep = device->lpVtbl->GetDescriptorHandleIncrementSize(device, D3D12_DESCRIPTOR_HEAP_TYPE_CBV_SRV_UAV); int samplerStep = device->lpVtbl->GetDescriptorHandleIncrementSize(device, D3D12_DESCRIPTOR_HEAP_TYPE_SAMPLER); @@ -1894,7 +1873,7 @@ void kinc_g5_internal_set_textures(kinc_g5_command_list_t *list) { samplerGpu.ptr += list->impl.heapIndex * samplerStep; for (int i = 0; i < KINC_INTERNAL_G5_TEXTURE_COUNT; ++i) { - if ((list->impl.currentRenderTargets[i] != NULL || list->impl.currentTextures[i] != NULL) && list->impl.current_samplers[i] != NULL) { + if (list->impl.currentTextures[i] != NULL && list->impl.current_samplers[i] != NULL) { ID3D12DescriptorHeap *samplerDescriptorHeap = list->impl.current_samplers[i]->impl.sampler_heap; D3D12_CPU_DESCRIPTOR_HANDLE srvCpu; @@ -1905,35 +1884,23 @@ void kinc_g5_internal_set_textures(kinc_g5_command_list_t *list) { samplerCpu.ptr += list->impl.heapIndex * samplerStep; ++list->impl.heapIndex; - if (list->impl.currentRenderTargets[i] != NULL) { - bool is_depth = list->impl.currentRenderTargets[i]->impl.stage_depth == i; - D3D12_CPU_DESCRIPTOR_HANDLE sourceCpu; + bool is_depth = list->impl.currentTextures[i]->impl.stage_depth == i; + D3D12_CPU_DESCRIPTOR_HANDLE sourceCpu; - if (is_depth) { - list->impl.currentRenderTargets[i]->impl.srvDepthDescriptorHeap->lpVtbl->GetCPUDescriptorHandleForHeapStart( - list->impl.currentRenderTargets[i]->impl.srvDepthDescriptorHeap, &sourceCpu); - } - else { - list->impl.currentRenderTargets[i]->impl.srvDescriptorHeap->lpVtbl->GetCPUDescriptorHandleForHeapStart( - list->impl.currentRenderTargets[i]->impl.srvDescriptorHeap, &sourceCpu); - } - - D3D12_CPU_DESCRIPTOR_HANDLE handle; - samplerDescriptorHeap->lpVtbl->GetCPUDescriptorHandleForHeapStart(samplerDescriptorHeap, &handle); - - device->lpVtbl->CopyDescriptorsSimple(device, 1, srvCpu, sourceCpu, D3D12_DESCRIPTOR_HEAP_TYPE_CBV_SRV_UAV); - device->lpVtbl->CopyDescriptorsSimple(device, 1, samplerCpu, handle, D3D12_DESCRIPTOR_HEAP_TYPE_SAMPLER); + if (is_depth) { + list->impl.currentTextures[i]->impl.srvDepthDescriptorHeap->lpVtbl->GetCPUDescriptorHandleForHeapStart( + list->impl.currentTextures[i]->impl.srvDepthDescriptorHeap, &sourceCpu); } else { - D3D12_CPU_DESCRIPTOR_HANDLE sourceCpu; list->impl.currentTextures[i]->impl.srvDescriptorHeap->lpVtbl->GetCPUDescriptorHandleForHeapStart( - list->impl.currentTextures[i]->impl.srvDescriptorHeap, &sourceCpu); - device->lpVtbl->CopyDescriptorsSimple(device, 1, srvCpu, sourceCpu, D3D12_DESCRIPTOR_HEAP_TYPE_CBV_SRV_UAV); - - D3D12_CPU_DESCRIPTOR_HANDLE handle; - samplerDescriptorHeap->lpVtbl->GetCPUDescriptorHandleForHeapStart(samplerDescriptorHeap, &handle); - device->lpVtbl->CopyDescriptorsSimple(device, 1, samplerCpu, handle, D3D12_DESCRIPTOR_HEAP_TYPE_SAMPLER); + list->impl.currentTextures[i]->impl.srvDescriptorHeap, &sourceCpu); } + + D3D12_CPU_DESCRIPTOR_HANDLE handle; + samplerDescriptorHeap->lpVtbl->GetCPUDescriptorHandleForHeapStart(samplerDescriptorHeap, &handle); + + device->lpVtbl->CopyDescriptorsSimple(device, 1, srvCpu, sourceCpu, D3D12_DESCRIPTOR_HEAP_TYPE_CBV_SRV_UAV); + device->lpVtbl->CopyDescriptorsSimple(device, 1, samplerCpu, handle, D3D12_DESCRIPTOR_HEAP_TYPE_SAMPLER); } } @@ -2090,6 +2057,7 @@ void create_texture(struct kinc_g5_texture *texture, int width, int height, kinc texture->impl.mipmap = true; texture->width = width; texture->height = height; + texture->data = NULL; DXGI_FORMAT d3dformat = convertImageFormat(format); @@ -2200,25 +2168,32 @@ void kinc_g5_texture_init_non_sampled_access(struct kinc_g5_texture *texture, in create_texture(texture, width, height, format, D3D12_RESOURCE_FLAG_ALLOW_UNORDERED_ACCESS); } -void kinc_g5_texture_destroy(struct kinc_g5_texture *texture) { +void kinc_g5_texture_destroy(kinc_g5_texture_t *render_target) { + if (render_target->impl.framebuffer_index >= 0) { + framebuffer_count -= 1; + } + + render_target->impl.renderTarget->lpVtbl->Release(render_target->impl.renderTarget); + render_target->impl.renderTargetDescriptorHeap->lpVtbl->Release(render_target->impl.renderTargetDescriptorHeap); + render_target->impl.srvDescriptorHeap->lpVtbl->Release(render_target->impl.srvDescriptorHeap); + if (render_target->impl.depthStencilTexture != NULL) { + render_target->impl.depthStencilTexture->lpVtbl->Release(render_target->impl.depthStencilTexture); + render_target->impl.depthStencilDescriptorHeap->lpVtbl->Release(render_target->impl.depthStencilDescriptorHeap); + render_target->impl.srvDepthDescriptorHeap->lpVtbl->Release(render_target->impl.srvDepthDescriptorHeap); + } + if (render_target->impl.renderTargetReadback != NULL) { + render_target->impl.renderTargetReadback->lpVtbl->Release(render_target->impl.renderTargetReadback); + } + texture->impl.image->lpVtbl->Release(texture->impl.image); texture->impl.uploadImage->lpVtbl->Release(texture->impl.uploadImage); - texture->impl.srvDescriptorHeap->lpVtbl->Release(texture->impl.srvDescriptorHeap); + // texture->impl.srvDescriptorHeap->lpVtbl->Release(texture->impl.srvDescriptorHeap); } void kinc_g5_internal_texture_unmipmap(struct kinc_g5_texture *texture) { texture->impl.mipmap = false; } -void kinc_g5_internal_texture_set(kinc_g5_command_list_t *list, struct kinc_g5_texture *texture, int unit) { - if (unit < 0) - return; - // context->PSSetShaderResources(unit.unit, 1, &view); - texture->impl.stage = unit; - list->impl.currentTextures[texture->impl.stage] = texture; - list->impl.currentRenderTargets[texture->impl.stage] = NULL; -} - void kinc_g5_internal_sampler_set(kinc_g5_command_list_t *list, kinc_g5_sampler_t *sampler, int unit) { if (unit < 0) return; @@ -2292,6 +2267,7 @@ static void render_target_init(kinc_g5_texture_t *render_target, int width, int render_target->impl.stage_depth = -1; render_target->impl.renderTargetReadback = NULL; render_target->impl.framebuffer_index = framebuffer_index; + render_target->data = NULL; DXGI_FORMAT dxgiFormat = convertFormat(format); @@ -2491,24 +2467,6 @@ void kinc_g5_render_target_init_framebuffer(kinc_g5_texture_t *target, int width framebuffer_count += 1; } -void kinc_g5_render_target_destroy(kinc_g5_texture_t *render_target) { - if (render_target->impl.framebuffer_index >= 0) { - framebuffer_count -= 1; - } - - render_target->impl.renderTarget->lpVtbl->Release(render_target->impl.renderTarget); - render_target->impl.renderTargetDescriptorHeap->lpVtbl->Release(render_target->impl.renderTargetDescriptorHeap); - render_target->impl.srvDescriptorHeap->lpVtbl->Release(render_target->impl.srvDescriptorHeap); - if (render_target->impl.depthStencilTexture != NULL) { - render_target->impl.depthStencilTexture->lpVtbl->Release(render_target->impl.depthStencilTexture); - render_target->impl.depthStencilDescriptorHeap->lpVtbl->Release(render_target->impl.depthStencilDescriptorHeap); - render_target->impl.srvDepthDescriptorHeap->lpVtbl->Release(render_target->impl.srvDepthDescriptorHeap); - } - if (render_target->impl.renderTargetReadback != NULL) { - render_target->impl.renderTargetReadback->lpVtbl->Release(render_target->impl.renderTargetReadback); - } -} - void kinc_g5_render_target_set_depth_from(kinc_g5_texture_t *render_target, kinc_g5_texture_t *source) { render_target->impl.depthStencilDescriptorHeap = source->impl.depthStencilDescriptorHeap; render_target->impl.srvDepthDescriptorHeap = source->impl.srvDepthDescriptorHeap; diff --git a/base/sources/backends/direct3d12_gpu.h b/base/sources/backends/direct3d12_gpu.h index ce9d2a65..511a5bda 100644 --- a/base/sources/backends/direct3d12_gpu.h +++ b/base/sources/backends/direct3d12_gpu.h @@ -65,7 +65,6 @@ typedef struct { struct ID3D12Fence *fence; HANDLE fence_event; - struct kinc_g5_texture *currentRenderTargets[KINC_INTERNAL_G5_TEXTURE_COUNT]; struct kinc_g5_texture *currentTextures[KINC_INTERNAL_G5_TEXTURE_COUNT]; struct kinc_g5_sampler *current_samplers[KINC_INTERNAL_G5_TEXTURE_COUNT]; diff --git a/base/sources/backends/metal_gpu.m b/base/sources/backends/metal_gpu.m index 06996830..ca7f051c 100644 --- a/base/sources/backends/metal_gpu.m +++ b/base/sources/backends/metal_gpu.m @@ -502,17 +502,6 @@ void kinc_g5_command_list_set_texture(kinc_g5_command_list_t *list, kinc_g5_text } } -void kinc_g5_command_list_set_texture_from_render_target(kinc_g5_command_list_t *list, kinc_g5_texture_unit_t unit, kinc_g5_texture_t *target) { - id encoder = getMetalEncoder(); - id tex = (__bridge id)target->impl._tex; - if (unit.stages[KINC_G5_SHADER_TYPE_VERTEX] >= 0) { - [encoder setVertexTexture:tex atIndex:unit.stages[KINC_G5_SHADER_TYPE_VERTEX]]; - } - if (unit.stages[KINC_G5_SHADER_TYPE_FRAGMENT] >= 0) { - [encoder setFragmentTexture:tex atIndex:unit.stages[KINC_G5_SHADER_TYPE_FRAGMENT]]; - } -} - void kinc_g5_command_list_set_texture_from_render_target_depth(kinc_g5_command_list_t *list, kinc_g5_texture_unit_t unit, kinc_g5_texture_t *target) { id encoder = getMetalEncoder(); id depth_tex = (__bridge id)target->impl._depthTex; @@ -1537,6 +1526,7 @@ void kinc_g5_texture_init(kinc_g5_texture_t *texture, int width, int height, kin texture->impl.data = malloc(width * height * (format == KINC_IMAGE_FORMAT_R8 ? 1 : 4)); create(texture, width, height, format, true); texture->_uploaded = true; + texture->data = NULL; } void kinc_g5_texture_init_from_bytes(kinc_g5_texture_t *texture, void *data, int width, int height, kinc_image_format_t format) { @@ -1564,14 +1554,26 @@ void kinc_g5_texture_init_non_sampled_access(kinc_g5_texture_t *texture, int wid create(texture, width, height, format, true); } -void kinc_g5_texture_destroy(kinc_g5_texture_t *texture) { - id tex = (__bridge_transfer id)texture->impl._tex; +void kinc_g5_texture_destroy(kinc_g5_texture_t *target) { + id tex = (__bridge_transfer id)target->impl._tex; tex = nil; - texture->impl._tex = NULL; + target->impl._tex = NULL; - if (texture->impl.data != NULL) { - free(texture->impl.data); - texture->impl.data = NULL; + id depthTex = (__bridge_transfer id)target->impl._depthTex; + depthTex = nil; + target->impl._depthTex = NULL; + + id texReadback = (__bridge_transfer id)target->impl._texReadback; + texReadback = nil; + target->impl._texReadback = NULL; + + if (target->framebuffer_index >= 0) { + framebuffer_count -= 1; + } + + if (target->impl.data != NULL) { + free(target->impl.data); + target->impl.data = NULL; } } @@ -1680,6 +1682,7 @@ static void render_target_init(kinc_g5_texture_t *target, int width, int height, target->width = width; target->height = height; + target->data = NULL; target->framebuffer_index = framebuffer_index; @@ -1730,24 +1733,6 @@ void kinc_g5_render_target_init_framebuffer(kinc_g5_texture_t *target, int width framebuffer_count += 1; } -void kinc_g5_render_target_destroy(kinc_g5_texture_t *target) { - id tex = (__bridge_transfer id)target->impl._tex; - tex = nil; - target->impl._tex = NULL; - - id depthTex = (__bridge_transfer id)target->impl._depthTex; - depthTex = nil; - target->impl._depthTex = NULL; - - id texReadback = (__bridge_transfer id)target->impl._texReadback; - texReadback = nil; - target->impl._texReadback = NULL; - - if (target->framebuffer_index >= 0) { - framebuffer_count -= 1; - } -} - void kinc_g5_render_target_set_depth_from(kinc_g5_texture_t *target, kinc_g5_texture_t *source) { target->impl._depthTex = source->impl._depthTex; } diff --git a/base/sources/backends/vulkan_gpu.c b/base/sources/backends/vulkan_gpu.c index 59cf7a9c..10930735 100644 --- a/base/sources/backends/vulkan_gpu.c +++ b/base/sources/backends/vulkan_gpu.c @@ -21,6 +21,7 @@ static VkSemaphore relay_semaphore; static bool wait_for_relay = false; static void command_list_should_wait_for_framebuffer(void); static VkDescriptorSetLayout compute_descriptor_layout; +static int framebuffer_count = 0; // djb2 uint32_t kinc_internal_hash_name(unsigned char *str) { @@ -59,11 +60,6 @@ kinc_g5_texture_t *vulkan_textures[16] = { NULL, NULL, NULL, NULL, NULL, NULL, NULL, NULL }; -kinc_g5_texture_t *vulkan_render_targets[16] = { - NULL, NULL, NULL, NULL, NULL, NULL, NULL, NULL, - NULL, NULL, NULL, NULL, NULL, NULL, NULL, NULL -}; - VkSampler vulkan_samplers[16] = { VK_NULL_HANDLE, VK_NULL_HANDLE, VK_NULL_HANDLE, VK_NULL_HANDLE, VK_NULL_HANDLE, VK_NULL_HANDLE, VK_NULL_HANDLE, VK_NULL_HANDLE, @@ -1178,7 +1174,6 @@ int kinc_g5_max_bound_textures(void) { extern kinc_g5_texture_t *vulkan_textures[16]; -extern kinc_g5_texture_t *vulkan_render_targets[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); @@ -1208,7 +1203,6 @@ static void endPass(kinc_g5_command_list_t *list) { for (int i = 0; i < 16; ++i) { vulkan_textures[i] = NULL; - vulkan_render_targets[i] = NULL; } } @@ -2013,39 +2007,32 @@ void kinc_g5_command_list_wait_for_execution_to_finish(kinc_g5_command_list_t *l assert(!err); } -void kinc_g5_command_list_set_texture(kinc_g5_command_list_t *list, kinc_g5_texture_unit_t unit, kinc_g5_texture_t *texture) { - vulkan_textures[unit.stages[KINC_G5_SHADER_TYPE_FRAGMENT]] = texture; - vulkan_render_targets[unit.stages[KINC_G5_SHADER_TYPE_FRAGMENT]] = NULL; -} - void kinc_g5_command_list_set_sampler(kinc_g5_command_list_t *list, kinc_g5_texture_unit_t unit, kinc_g5_sampler_t *sampler) { if (unit.stages[KINC_G5_SHADER_TYPE_FRAGMENT] >= 0) { vulkan_samplers[unit.stages[KINC_G5_SHADER_TYPE_FRAGMENT]] = sampler->impl.sampler; } } -void kinc_g5_command_list_set_texture_from_render_target(kinc_g5_command_list_t *list, kinc_g5_texture_unit_t unit, kinc_g5_texture_t *target) { +void kinc_g5_command_list_set_texture(kinc_g5_command_list_t *list, kinc_g5_texture_unit_t unit, kinc_g5_texture_t *texture) { if (unit.stages[KINC_G5_SHADER_TYPE_FRAGMENT] >= 0) { - target->impl.stage = unit.stages[KINC_G5_SHADER_TYPE_FRAGMENT]; - vulkan_render_targets[unit.stages[KINC_G5_SHADER_TYPE_FRAGMENT]] = target; + texture->impl.stage = unit.stages[KINC_G5_SHADER_TYPE_FRAGMENT]; + vulkan_textures[unit.stages[KINC_G5_SHADER_TYPE_FRAGMENT]] = texture; } else if (unit.stages[KINC_G5_SHADER_TYPE_VERTEX] >= 0) { - target->impl.stage = unit.stages[KINC_G5_SHADER_TYPE_VERTEX]; - vulkan_render_targets[unit.stages[KINC_G5_SHADER_TYPE_VERTEX]] = target; + texture->impl.stage = unit.stages[KINC_G5_SHADER_TYPE_VERTEX]; + vulkan_textures[unit.stages[KINC_G5_SHADER_TYPE_VERTEX]] = texture; } - vulkan_textures[target->impl.stage] = NULL; } void kinc_g5_command_list_set_texture_from_render_target_depth(kinc_g5_command_list_t *list, kinc_g5_texture_unit_t unit, kinc_g5_texture_t *target) { if (unit.stages[KINC_G5_SHADER_TYPE_FRAGMENT] >= 0) { target->impl.stage_depth = unit.stages[KINC_G5_SHADER_TYPE_FRAGMENT]; - vulkan_render_targets[unit.stages[KINC_G5_SHADER_TYPE_FRAGMENT]] = target; + vulkan_textures[unit.stages[KINC_G5_SHADER_TYPE_FRAGMENT]] = target; } else if (unit.stages[KINC_G5_SHADER_TYPE_VERTEX] >= 0) { target->impl.stage_depth = unit.stages[KINC_G5_SHADER_TYPE_VERTEX]; - vulkan_render_targets[unit.stages[KINC_G5_SHADER_TYPE_VERTEX]] = target; + vulkan_textures[unit.stages[KINC_G5_SHADER_TYPE_VERTEX]] = target; } - vulkan_textures[target->impl.stage_depth] = NULL; } void kinc_g5_command_list_set_compute_shader(kinc_g5_command_list_t *list, kinc_g5_compute_shader *shader) { @@ -2249,7 +2236,6 @@ kinc_g5_texture_unit_t kinc_g5_compute_shader_get_texture_unit(kinc_g5_compute_s VkDescriptorSetLayout desc_layout; extern kinc_g5_texture_t *vulkan_textures[16]; -extern kinc_g5_texture_t *vulkan_render_targets[16]; extern uint32_t swapchainImageCount; extern uint32_t current_buffer; bool memory_type_from_properties(uint32_t typeBits, VkFlags requirements_mask, uint32_t *typeIndex); @@ -2964,9 +2950,6 @@ int calc_descriptor_id(void) { if (vulkan_textures[i] != NULL) { texture_count++; } - else if (vulkan_render_targets[i] != NULL) { - texture_count++; - } } bool uniform_buffer = vk_ctx.vertex_uniform_buffer != NULL && vk_ctx.fragment_uniform_buffer != NULL; @@ -2980,9 +2963,6 @@ int calc_compute_descriptor_id(void) { if (vulkan_textures[i] != NULL) { texture_count++; } - else if (vulkan_render_targets[i] != NULL) { - texture_count++; - } } bool uniform_buffer = vk_ctx.compute_uniform_buffer != NULL; @@ -3009,17 +2989,12 @@ static int write_tex_descs(VkDescriptorImageInfo *tex_descs) { for (int i = 0; i < 16; ++i) { if (vulkan_textures[i] != NULL) { tex_descs[i].sampler = vulkan_samplers[i]; - tex_descs[i].imageView = vulkan_textures[i]->impl.view; - texture_count++; - } - else if (vulkan_render_targets[i] != NULL) { - tex_descs[i].sampler = vulkan_samplers[i]; - if (vulkan_render_targets[i]->impl.stage_depth == i) { - tex_descs[i].imageView = vulkan_render_targets[i]->impl.depthView; - vulkan_render_targets[i]->impl.stage_depth = -1; + if (vulkan_textures[i]->impl.stage_depth == i) { + tex_descs[i].imageView = vulkan_textures[i]->impl.depthView; + vulkan_textures[i]->impl.stage_depth = -1; } else { - tex_descs[i].imageView = vulkan_render_targets[i]->impl.view; + tex_descs[i].imageView = vulkan_textures[i]->impl.view; } texture_count++; } @@ -3053,7 +3028,7 @@ static void update_textures(struct destriptor_set *set) { writes[i].pImageInfo = &set->tex_desc[i]; } - if (vulkan_textures[0] != NULL || vulkan_render_targets[0] != NULL) { + if (vulkan_textures[0] != NULL) { vkUpdateDescriptorSets(vk_ctx.device, texture_count, writes, 0, NULL); } } @@ -3113,19 +3088,13 @@ VkDescriptorSet getDescriptorSet() { int texture_count = 0; for (int i = 0; i < 16; ++i) { if (vulkan_textures[i] != NULL) { - assert(vulkan_samplers[i] != VK_NULL_HANDLE); tex_desc[i].sampler = vulkan_samplers[i]; - tex_desc[i].imageView = vulkan_textures[i]->impl.view; - texture_count++; - } - else if (vulkan_render_targets[i] != NULL) { - tex_desc[i].sampler = vulkan_samplers[i]; - if (vulkan_render_targets[i]->impl.stage_depth == i) { - tex_desc[i].imageView = vulkan_render_targets[i]->impl.depthView; - vulkan_render_targets[i]->impl.stage_depth = -1; + if (vulkan_textures[i]->impl.stage_depth == i) { + tex_desc[i].imageView = vulkan_textures[i]->impl.depthView; + vulkan_textures[i]->impl.stage_depth = -1; } else { - tex_desc[i].imageView = vulkan_render_targets[i]->impl.view; + tex_desc[i].imageView = vulkan_textures[i]->impl.view; } texture_count++; } @@ -3158,7 +3127,7 @@ VkDescriptorSet getDescriptorSet() { writes[i].pImageInfo = &tex_desc[i - 2]; } - if (vulkan_textures[0] != NULL || vulkan_render_targets[0] != NULL) { + if (vulkan_textures[0] != NULL) { if (vk_ctx.vertex_uniform_buffer != NULL && vk_ctx.fragment_uniform_buffer != NULL) { vkUpdateDescriptorSets(vk_ctx.device, 2 + texture_count, writes, 0, NULL); } @@ -3192,17 +3161,12 @@ static int write_compute_tex_descs(VkDescriptorImageInfo *tex_descs) { for (int i = 0; i < 16; ++i) { if (vulkan_textures[i] != NULL) { tex_descs[i].sampler = vulkan_samplers[i]; - tex_descs[i].imageView = vulkan_textures[i]->impl.view; - texture_count++; - } - else if (vulkan_render_targets[i] != NULL) { - tex_descs[i].sampler = vulkan_samplers[i]; - if (vulkan_render_targets[i]->impl.stage_depth == i) { - tex_descs[i].imageView = vulkan_render_targets[i]->impl.depthView; - vulkan_render_targets[i]->impl.stage_depth = -1; + if (vulkan_textures[i]->impl.stage_depth == i) { + tex_descs[i].imageView = vulkan_textures[i]->impl.depthView; + vulkan_textures[i]->impl.stage_depth = -1; } else { - tex_descs[i].imageView = vulkan_render_targets[i]->impl.view; + tex_descs[i].imageView = vulkan_textures[i]->impl.view; } texture_count++; } @@ -3236,7 +3200,7 @@ static void update_compute_textures(struct destriptor_set *set) { writes[i].pImageInfo = &set->tex_desc[i]; } - if (vulkan_textures[0] != NULL || vulkan_render_targets[0] != NULL) { + if (vulkan_textures[0] != NULL) { vkUpdateDescriptorSets(vk_ctx.device, texture_count, writes, 0, NULL); } } @@ -3296,19 +3260,13 @@ static VkDescriptorSet get_compute_descriptor_set() { int texture_count = 0; for (int i = 0; i < 16; ++i) { if (vulkan_textures[i] != NULL) { - // assert(vulkan_samplers[i] != VK_NULL_HANDLE); - tex_desc[i].sampler = VK_NULL_HANDLE; // vulkan_samplers[i]; - tex_desc[i].imageView = vulkan_textures[i]->impl.view; - texture_count++; - } - else if (vulkan_render_targets[i] != NULL) { tex_desc[i].sampler = vulkan_samplers[i]; - if (vulkan_render_targets[i]->impl.stage_depth == i) { - tex_desc[i].imageView = vulkan_render_targets[i]->impl.depthView; - vulkan_render_targets[i]->impl.stage_depth = -1; + if (vulkan_textures[i]->impl.stage_depth == i) { + tex_desc[i].imageView = vulkan_textures[i]->impl.depthView; + vulkan_textures[i]->impl.stage_depth = -1; } else { - tex_desc[i].imageView = vulkan_render_targets[i]->impl.view; + tex_desc[i].imageView = vulkan_textures[i]->impl.view; } texture_count++; } @@ -3341,7 +3299,7 @@ static VkDescriptorSet get_compute_descriptor_set() { writes[i].pImageInfo = &tex_desc[i - 2]; } - if (vulkan_textures[0] != NULL || vulkan_render_targets[0] != NULL) { + if (vulkan_textures[0] != NULL) { if (vk_ctx.compute_uniform_buffer != NULL) { vkUpdateDescriptorSets(vk_ctx.device, 2 + texture_count, writes, 0, NULL); } @@ -3663,12 +3621,6 @@ static void prepare_texture_image(uint8_t *tex_colors, uint32_t width, uint32_t set_image_layout(tex_obj->image, VK_IMAGE_ASPECT_COLOR_BIT, VK_IMAGE_LAYOUT_UNDEFINED, tex_obj->imageLayout); } -static void destroy_texture_image(Texture5Impl *tex_obj) { - // clean up staging resources - vkDestroyImage(vk_ctx.device, tex_obj->image, NULL); - vkFreeMemory(vk_ctx.device, tex_obj->mem, NULL); -} - static VkFormat convert_image_format(kinc_image_format_t format) { switch (format) { case KINC_IMAGE_FORMAT_RGBA128: @@ -3776,7 +3728,9 @@ void kinc_g5_texture_init_from_bytes(kinc_g5_texture_t *texture, void *data, int flush_init_cmd(); - destroy_texture_image(&staging_texture); + vkDestroyImage(vk_ctx.device, staging_texture.image, NULL); + vkFreeMemory(vk_ctx.device, staging_texture.mem, NULL); + } else { assert(!"No support for B8G8R8A8_UNORM as texture image format"); @@ -3811,6 +3765,7 @@ void kinc_g5_texture_init(kinc_g5_texture_t *texture, int width, int height, kin texture->height = height; texture->_uploaded = true; texture->format = format; + texture->data = NULL; const VkFormat tex_format = convert_image_format(format); VkFormatProperties props; @@ -3890,9 +3845,25 @@ void kinc_g5_texture_init_non_sampled_access(kinc_g5_texture_t *texture, int wid assert(!err); } -void kinc_g5_texture_destroy(kinc_g5_texture_t *texture) { - vkDestroyImageView(vk_ctx.device, texture->impl.view, NULL); - destroy_texture_image(&texture->impl); +void kinc_g5_texture_destroy(kinc_g5_texture_t *target) { + if (target->framebuffer_index >= 0) { + framebuffer_count -= 1; + } + else { + + if (target->impl.framebuffer != NULL) { + vkDestroyFramebuffer(vk_ctx.device, target->impl.framebuffer, NULL); + } + + if (target->impl.depthBufferBits > 0) { + vkDestroyImageView(vk_ctx.device, target->impl.depthView, NULL); + vkDestroyImage(vk_ctx.device, target->impl.depthImage, NULL); + vkFreeMemory(vk_ctx.device, target->impl.depthMemory, NULL); + } + vkDestroyImageView(vk_ctx.device, target->impl.view, NULL); + vkDestroyImage(vk_ctx.device, target->impl.image, NULL); + vkFreeMemory(vk_ctx.device, target->impl.mem, NULL); + } } void kinc_g5_internal_texture_set(kinc_g5_texture_t *texture, int unit) {} @@ -3993,7 +3964,6 @@ void kinc_g5_texture_set_mipmap(kinc_g5_texture_t *texture, kinc_g5_texture_t *m extern uint32_t swapchainImageCount; extern kinc_g5_texture_t *vulkan_textures[16]; -extern kinc_g5_texture_t *vulkan_render_targets[16]; void setup_init_cmd(); @@ -4055,6 +4025,7 @@ static void render_target_init(kinc_g5_texture_t *target, int width, int height, target->framebuffer_index = framebuffer_index; target->width = width; target->height = height; + target->data = NULL; target->impl.format = convert_format(format); target->impl.depthBufferBits = depthBufferBits; target->impl.stage = 0; @@ -4232,30 +4203,11 @@ void kinc_g5_render_target_init(kinc_g5_texture_t *target, int width, int height target->state = KINC_INTERNAL_RENDER_TARGET_STATE_RENDER_TARGET; } -static int framebuffer_count = 0; - void kinc_g5_render_target_init_framebuffer(kinc_g5_texture_t *target, int width, int height, kinc_image_format_t format, int depthBufferBits) { render_target_init(target, width, height, format, depthBufferBits, framebuffer_count); framebuffer_count += 1; } -void kinc_g5_render_target_destroy(kinc_g5_texture_t *target) { - if (target->framebuffer_index >= 0) { - framebuffer_count -= 1; - } - else { - vkDestroyFramebuffer(vk_ctx.device, target->impl.framebuffer, NULL); - if (target->impl.depthBufferBits > 0) { - vkDestroyImageView(vk_ctx.device, target->impl.depthView, NULL); - vkDestroyImage(vk_ctx.device, target->impl.depthImage, NULL); - vkFreeMemory(vk_ctx.device, target->impl.depthMemory, NULL); - } - vkDestroyImageView(vk_ctx.device, target->impl.view, NULL); - vkDestroyImage(vk_ctx.device, target->impl.image, NULL); - vkFreeMemory(vk_ctx.device, target->impl.mem, NULL); - } -} - void kinc_g5_render_target_set_depth_from(kinc_g5_texture_t *target, kinc_g5_texture_t *source) { target->impl.depthImage = source->impl.depthImage; target->impl.depthMemory = source->impl.depthMemory; diff --git a/base/sources/backends/vulkan_gpu.h b/base/sources/backends/vulkan_gpu.h index 94eb2aad..ad251395 100644 --- a/base/sources/backends/vulkan_gpu.h +++ b/base/sources/backends/vulkan_gpu.h @@ -167,10 +167,6 @@ typedef struct kinc_g5_sampler_impl { } kinc_g5_sampler_impl_t; typedef struct { - // VkImage image; - // VkDeviceMemory mem; - // VkImageView view; - VkImageLayout imageLayout; VkDeviceSize deviceSize; int stride; diff --git a/base/sources/backends/webgpu_gpu.c b/base/sources/backends/webgpu_gpu.c index 823894df..06c3afc6 100644 --- a/base/sources/backends/webgpu_gpu.c +++ b/base/sources/backends/webgpu_gpu.c @@ -224,7 +224,7 @@ void kinc_g5_texture_init(kinc_g5_texture_t *texture, int width, int height, kin texture->_uploaded = true; texture->format = format; - + texture->data = NULL; } void kinc_g5_texture_init_from_bytes(kinc_g5_texture_t *texture, void *data, int width, int height, kinc_image_format_t format) {} @@ -251,12 +251,11 @@ void kinc_g5_render_target_init(kinc_g5_texture_t *target, int width, int height target->width = target->width = width; target->height = target->height = height; target->state = KINC_INTERNAL_RENDER_TARGET_STATE_RENDER_TARGET; + target->data = NULL; } void kinc_g5_render_target_init_framebuffer(kinc_g5_texture_t *target, int width, int height, kinc_image_format_t format, int depthBufferBits) {} -void kinc_g5_render_target_destroy(kinc_g5_texture_t *renderTarget) {} - void kinc_g5_render_target_set_depth_from(kinc_g5_texture_t *renderTarget, kinc_g5_texture_t *source) {} void kinc_g5_render_target_get_pixels(kinc_g5_texture_t *renderTarget, uint8_t *data) {} @@ -529,8 +528,6 @@ void kinc_g5_command_list_set_texture(kinc_g5_command_list_t *list, kinc_g5_text void kinc_g5_command_list_set_sampler(kinc_g5_command_list_t *list, kinc_g5_texture_unit_t unit, kinc_g5_sampler_t *sampler) {} -void kinc_g5_command_list_set_texture_from_render_target(kinc_g5_command_list_t *list, kinc_g5_texture_unit_t unit, kinc_g5_texture_t *renderTarget) {} - void kinc_g5_command_list_set_texture_from_render_target_depth(kinc_g5_command_list_t *list, kinc_g5_texture_unit_t unit, kinc_g5_texture_t *renderTarget) {} void kinc_g5_command_list_set_compute_shader(kinc_g5_command_list_t *list, kinc_g5_compute_shader *shader) {} diff --git a/base/sources/iron.h b/base/sources/iron.h index 5822ce78..c361d276 100644 --- a/base/sources/iron.h +++ b/base/sources/iron.h @@ -1245,17 +1245,10 @@ kinc_g5_texture_t *iron_load_image(string_t *file, bool readable) { } void iron_unload_image(image_t *image) { - if (image == NULL) { - return; - } - if (image->texture_ != NULL) { + if (image != NULL && image->texture_ != NULL) { kinc_g5_texture_destroy(image->texture_); free(image->texture_); } - else if (image->render_target_ != NULL) { - kinc_g5_render_target_destroy(image->render_target_); - free(image->render_target_); - } } #ifdef WITH_AUDIO @@ -1304,10 +1297,6 @@ void iron_g4_set_texture(kinc_g5_texture_unit_t *unit, kinc_g5_texture_t *textur kinc_g4_set_texture(*unit, texture); } -void iron_g4_set_render_target(kinc_g5_texture_unit_t *unit, kinc_g5_texture_t *render_target) { - kinc_g4_render_target_use_color_as_texture(render_target, *unit); -} - void iron_g4_set_texture_depth(kinc_g5_texture_unit_t *unit, kinc_g5_texture_t *render_target) { kinc_g4_render_target_use_depth_as_texture(render_target, *unit); } @@ -1398,17 +1387,20 @@ bool iron_display_is_primary(i32 index) { kinc_g5_texture_t *iron_g4_create_render_target(i32 width, i32 height, i32 format, i32 depth_buffer_bits) { kinc_g5_texture_t *render_target = (kinc_g5_texture_t *)malloc(sizeof(kinc_g5_texture_t)); kinc_g5_render_target_init(render_target, width, height, (kinc_image_format_t)format, depth_buffer_bits); + render_target->buffer = NULL; 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; void *image_data; if (readable) { image_data = malloc(data->length); @@ -1417,17 +1409,13 @@ kinc_g5_texture_t *iron_g4_create_texture_from_bytes(buffer_t *data, i32 width, else { image_data = data->buffer; } - kinc_g5_texture_init_from_bytes(texture, image_data, width, height, (kinc_image_format_t)format); - if (!readable) { - // free(image_data); - } - return texture; } kinc_g5_texture_t *iron_g4_create_texture_from_encoded_bytes(buffer_t *data, string_t *format, bool readable) { kinc_g5_texture_t *texture = (kinc_g5_texture_t *)malloc(sizeof(kinc_g5_texture_t)); + texture->buffer = NULL; unsigned char *content_data = (unsigned char *)data->buffer; int content_length = (int)data->length; @@ -1497,25 +1485,34 @@ int _format_byte_size(kinc_image_format_t format) { } buffer_t *iron_g4_get_texture_pixels(kinc_g5_texture_t *image) { - buffer_t *buffer = malloc(sizeof(buffer_t)); - buffer->buffer = image->data; - buffer->length = _format_byte_size(image->format) * image->width * image->height; - return buffer; -} + if (image->buffer == NULL) { + image->buffer = malloc(sizeof(buffer_t)); + image->buffer->buffer = NULL; + } + image->buffer->length = _format_byte_size(image->format) * image->width * image->height; -void iron_g4_get_render_target_pixels(kinc_g5_texture_t *rt, buffer_t *data) { - uint8_t *b = (uint8_t *)data->buffer; - kinc_g5_render_target_get_pixels(rt, b); + if (image->data == NULL) { + if (image->buffer->buffer == NULL) { + image->buffer->buffer = malloc(image->buffer->length); + } - // Release staging texture immediately to save memory - #ifdef KINC_DIRECT3D12 - rt->impl.renderTargetReadback->lpVtbl->Release(rt->impl.renderTargetReadback); - rt->impl.renderTargetReadback = NULL; - #elif defined(KINC_METAL) - // id texReadback = (__bridge_transfer id)rt->impl._texReadback; - // texReadback = nil; - // rt->impl._texReadback = NULL; - #endif + uint8_t *b = (uint8_t *)image->buffer->buffer; + kinc_g5_render_target_get_pixels(image, b); + + // Release staging texture immediately to save memory + #ifdef KINC_DIRECT3D12 + rt->impl.renderTargetReadback->lpVtbl->Release(rt->impl.renderTargetReadback); + rt->impl.renderTargetReadback = NULL; + #elif defined(KINC_METAL) + // id texReadback = (__bridge_transfer id)rt->impl._texReadback; + // texReadback = nil; + // rt->impl._texReadback = NULL; + #endif + } + else { + image->buffer->buffer = image->data; + } + return image->buffer; } buffer_t *iron_g4_lock_texture(kinc_g5_texture_t *texture, i32 level) { @@ -1541,7 +1538,7 @@ void iron_g4_begin(image_t *render_target, any_array_t *additional) { kinc_g4_restore_render_target(); } else { - kinc_g5_texture_t *rt = (kinc_g5_texture_t *)render_target->render_target_; + kinc_g5_texture_t *rt = (kinc_g5_texture_t *)render_target->texture_; int32_t length = 1; kinc_g5_texture_t *render_targets[8] = { rt, NULL, NULL, NULL, NULL, NULL, NULL, NULL }; if (additional != NULL) { @@ -1551,7 +1548,7 @@ void iron_g4_begin(image_t *render_target, any_array_t *additional) { } for (int32_t i = 1; i < length; ++i) { image_t *img = additional->buffer[i - 1]; - kinc_g5_texture_t *art = (kinc_g5_texture_t *)img->render_target_; + kinc_g5_texture_t *art = (kinc_g5_texture_t *)img->texture_; render_targets[i] = art; } } @@ -2285,71 +2282,75 @@ void iron_raytrace_set_textures(image_t *tex0, image_t *tex1, image_t *tex2, kin kinc_g5_texture_t *texpaint1; kinc_g5_texture_t *texpaint2; - image_t *texpaint0_image = tex0; - kinc_g5_texture_t *texpaint0_tex = texpaint0_image->texture_; - kinc_g5_texture_t *texpaint0_rt = texpaint0_image->render_target_; + // image_t *texpaint0_image = tex0; + // kinc_g5_texture_t *texpaint0_tex = texpaint0_image->texture_; + // kinc_g5_texture_t *texpaint0_rt = texpaint0_image->render_target_; - if (texpaint0_tex != NULL) { - kinc_g5_texture_t *texture = texpaint0_tex; - if (!texture->_uploaded) { - kinc_g5_command_list_upload_texture(&commandList, texture); - texture->_uploaded = true; - } - texpaint0 = (kinc_g5_texture_t *)malloc(sizeof(kinc_g5_texture_t)); - #ifdef KINC_DIRECT3D12 - texpaint0->impl.srvDescriptorHeap = texture->impl.srvDescriptorHeap; - #endif - #ifdef KINC_VULKAN - texpaint0->impl.view = texture->impl.view; - #endif - } - else { - texpaint0 = texpaint0_rt; - } + // if (texpaint0_tex != NULL) { + // kinc_g5_texture_t *texture = texpaint0_tex; + // if (!texture->_uploaded) { + // kinc_g5_command_list_upload_texture(&commandList, texture); + // texture->_uploaded = true; + // } + // texpaint0 = (kinc_g5_texture_t *)malloc(sizeof(kinc_g5_texture_t)); + // #ifdef KINC_DIRECT3D12 + // texpaint0->impl.srvDescriptorHeap = texture->impl.srvDescriptorHeap; + // #endif + // #ifdef KINC_VULKAN + // texpaint0->impl.view = texture->impl.view; + // #endif + // } + // else { + // texpaint0 = texpaint0_rt; + // } - image_t *texpaint1_image = tex1; - kinc_g5_texture_t *texpaint1_tex = texpaint1_image->texture_; - kinc_g5_texture_t *texpaint1_rt = texpaint1_image->render_target_; + // image_t *texpaint1_image = tex1; + // kinc_g5_texture_t *texpaint1_tex = texpaint1_image->texture_; + // kinc_g5_texture_t *texpaint1_rt = texpaint1_image->render_target_; - if (texpaint1_tex != NULL) { - kinc_g5_texture_t *texture = texpaint1_tex; - if (!texture->_uploaded) { - kinc_g5_command_list_upload_texture(&commandList, texture); - texture->_uploaded = true; - } - texpaint1 = (kinc_g5_texture_t *)malloc(sizeof(kinc_g5_texture_t)); - #ifdef KINC_DIRECT3D12 - texpaint1->impl.srvDescriptorHeap = texture->impl.srvDescriptorHeap; - #endif - #ifdef KINC_VULKAN - texpaint1->impl.view = texture->impl.view; - #endif - } - else { - texpaint1 = texpaint1_rt; - } + // if (texpaint1_tex != NULL) { + // kinc_g5_texture_t *texture = texpaint1_tex; + // if (!texture->_uploaded) { + // kinc_g5_command_list_upload_texture(&commandList, texture); + // texture->_uploaded = true; + // } + // texpaint1 = (kinc_g5_texture_t *)malloc(sizeof(kinc_g5_texture_t)); + // #ifdef KINC_DIRECT3D12 + // texpaint1->impl.srvDescriptorHeap = texture->impl.srvDescriptorHeap; + // #endif + // #ifdef KINC_VULKAN + // texpaint1->impl.view = texture->impl.view; + // #endif + // } + // else { + // texpaint1 = texpaint1_rt; + // } - image_t *texpaint2_image = tex2; - kinc_g5_texture_t *texpaint2_tex = texpaint2_image->texture_; - kinc_g5_texture_t *texpaint2_rt = texpaint2_image->render_target_; + // image_t *texpaint2_image = tex2; + // kinc_g5_texture_t *texpaint2_tex = texpaint2_image->texture_; + // kinc_g5_texture_t *texpaint2_rt = texpaint2_image->render_target_; - if (texpaint2_tex != NULL) { - kinc_g5_texture_t *texture = (kinc_g5_texture_t *)texpaint2_tex; - if (!texture->_uploaded) { - kinc_g5_command_list_upload_texture(&commandList, texture); - texture->_uploaded = true; - } - texpaint2 = (kinc_g5_texture_t *)malloc(sizeof(kinc_g5_texture_t)); - #ifdef KINC_DIRECT3D12 - texpaint2->impl.srvDescriptorHeap = texture->impl.srvDescriptorHeap; - #endif - #ifdef KINC_VULKAN - texpaint2->impl.view = texture->impl.view; - #endif - } - else { - texpaint2 = texpaint2_rt; - } + // if (texpaint2_tex != NULL) { + // kinc_g5_texture_t *texture = (kinc_g5_texture_t *)texpaint2_tex; + // if (!texture->_uploaded) { + // kinc_g5_command_list_upload_texture(&commandList, texture); + // texture->_uploaded = true; + // } + // texpaint2 = (kinc_g5_texture_t *)malloc(sizeof(kinc_g5_texture_t)); + // #ifdef KINC_DIRECT3D12 + // texpaint2->impl.srvDescriptorHeap = texture->impl.srvDescriptorHeap; + // #endif + // #ifdef KINC_VULKAN + // texpaint2->impl.view = texture->impl.view; + // #endif + // } + // else { + // texpaint2 = texpaint2_rt; + // } + + texpaint0 = tex0->texture_; + texpaint1 = tex1->texture_; + texpaint2 = tex2->texture_; if (!texenv->_uploaded) { kinc_g5_command_list_upload_texture(&commandList, texenv); @@ -2370,15 +2371,15 @@ void iron_raytrace_set_textures(image_t *tex0, image_t *tex1, image_t *tex2, kin kinc_g5_raytrace_set_textures(texpaint0, texpaint1, texpaint2, texenv, texsobol, texscramble, texrank); - if (texpaint0_tex != NULL) { - free(texpaint0); - } - if (texpaint1_tex != NULL) { - free(texpaint1); - } - if (texpaint2_tex != NULL) { - free(texpaint2); - } + // if (texpaint0_tex != NULL) { + // free(texpaint0); + // } + // if (texpaint1_tex != NULL) { + // free(texpaint1); + // } + // if (texpaint2_tex != NULL) { + // free(texpaint2); + // } } void iron_raytrace_dispatch_rays(kinc_g5_texture_t *render_target, buffer_t *buffer) { diff --git a/base/sources/iron_draw.c b/base/sources/iron_draw.c index c0168f73..5f66e2fd 100644 --- a/base/sources/iron_draw.c +++ b/base/sources/iron_draw.c @@ -38,7 +38,6 @@ static float *image_rect_verts = NULL; static int image_buffer_index = 0; static int image_buffer_start = 0; static kinc_g5_texture_t *image_last_texture = NULL; -static kinc_g5_texture_t *image_last_render_target = NULL; static kinc_g4_vertex_buffer_t colored_rect_vertex_buffer; static kinc_g5_index_buffer_t colored_rect_index_buffer; @@ -328,12 +327,7 @@ void draw_image_buffer(bool end) { kinc_g4_set_matrix4(image_proj_loc, &draw_projection_matrix); kinc_g4_set_vertex_buffer(&image_vertex_buffer); kinc_g4_set_index_buffer(&image_index_buffer); - if (image_last_texture != NULL) { - kinc_g4_set_texture(image_tex_unit, image_last_texture); - } - else { - kinc_g4_render_target_use_color_as_texture(image_last_render_target, image_tex_unit); - } + kinc_g4_set_texture(image_tex_unit, image_last_texture); kinc_g4_set_texture_addressing(image_tex_unit, KINC_G4_TEXTURE_DIRECTION_U, KINC_G4_TEXTURE_ADDRESSING_CLAMP); kinc_g4_set_texture_addressing(image_tex_unit, KINC_G4_TEXTURE_DIRECTION_V, KINC_G4_TEXTURE_ADDRESSING_CLAMP); // kinc_g4_set_texture_mipmap_filter(image_tex_unit, draw_bilinear_filter ? KINC_G4_MIPMAP_FILTER_LINEAR : KINC_G4_MIPMAP_FILTER_NONE); @@ -357,9 +351,7 @@ void draw_scaled_sub_texture(kinc_g5_texture_t *tex, float sx, float sy, float s draw_colored_end(); draw_text_end(); if (image_buffer_start + image_buffer_index + 1 >= DRAW_BUFFER_SIZE || - (image_last_texture != NULL && tex != image_last_texture) || - image_last_render_target != NULL) { - + (image_last_texture != NULL && tex != image_last_texture)) { draw_image_buffer(false); } @@ -371,7 +363,6 @@ void draw_scaled_sub_texture(kinc_g5_texture_t *tex, float sx, float sy, float s ++image_buffer_index; image_last_texture = tex; - image_last_render_target = NULL; } void draw_scaled_texture(kinc_g5_texture_t *tex, float dx, float dy, float dw, float dh) { @@ -386,51 +377,12 @@ void draw_texture(kinc_g5_texture_t *tex, float x, float y) { draw_scaled_sub_texture(tex, 0, 0, (float)tex->width, (float)tex->height, x, y, (float)tex->width, (float)tex->height); } -void draw_scaled_sub_render_target(kinc_g5_texture_t *rt, float sx, float sy, float sw, float sh, float dx, float dy, float dw, float dh) { - draw_colored_end(); - draw_text_end(); - if (image_buffer_start + image_buffer_index + 1 >= DRAW_BUFFER_SIZE || - (image_last_render_target != NULL && rt != image_last_render_target) || - image_last_texture != NULL) { - - draw_image_buffer(false); - } - - draw_set_image_rect_tex_coords(sx / rt->width, sy / rt->height, (sx + sw) / rt->width, (sy + sh) / rt->height); - draw_set_image_rect_colors(draw_color); - kinc_vector2_t p[4]; - draw_matrix3x3_multquad(&draw_transform, dx, dy, dw, dh, p); - draw_set_image_rect_verts(p[0].x, p[0].y, p[1].x, p[1].y, p[2].x, p[2].y, p[3].x, p[3].y); - - ++image_buffer_index; - image_last_render_target = rt; - image_last_texture = NULL; -} - -void draw_scaled_render_target(kinc_g5_texture_t *rt, float dx, float dy, float dw, float dh) { - draw_scaled_sub_render_target(rt, 0, 0, (float)rt->width, (float)rt->height, dx, dy, dw, dh); -} - -void draw_sub_render_target(kinc_g5_texture_t *rt, float sx, float sy, float sw, float sh, float x, float y) { - draw_scaled_sub_render_target(rt, sx, sy, sw, sh, x, y, sw, sh); -} - -void draw_render_target(kinc_g5_texture_t *rt, float x, float y) { - draw_scaled_sub_render_target(rt, 0, 0, (float)rt->width, (float)rt->height, x, y, (float)rt->width, (float)rt->height); -} - void draw_scaled_sub_image(image_t *image, float sx, float sy, float sw, float sh, float dx, float dy, float dw, float dh) { #ifdef KINC_DIRECT3D12 waitAfterNextDraw = true; #endif - if (image->texture_ != NULL) { - kinc_g5_texture_t *texture = (kinc_g5_texture_t *)image->texture_; - draw_scaled_sub_texture(texture, sx, sy, sw, sh, dx, dy, dw, dh); - } - else { - kinc_g5_texture_t *render_target = (kinc_g5_texture_t *)image->render_target_; - draw_scaled_sub_render_target(render_target, sx, sy, sw, sh, dx, dy, dw, dh); - } + kinc_g5_texture_t *texture = (kinc_g5_texture_t *)image->texture_; + draw_scaled_sub_texture(texture, sx, sy, sw, sh, dx, dy, dw, dh); } void draw_scaled_image(image_t *tex, float dx, float dy, float dw, float dh) { @@ -1093,7 +1045,6 @@ int draw_string_width(draw_font_t *font, int font_size, const char *text) { void draw_image_end(void) { if (image_buffer_index > 0) draw_image_buffer(true); image_last_texture = NULL; - image_last_render_target = NULL; } void draw_colored_end(void) { diff --git a/base/sources/iron_draw.h b/base/sources/iron_draw.h index e425a753..161068a7 100644 --- a/base/sources/iron_draw.h +++ b/base/sources/iron_draw.h @@ -13,13 +13,9 @@ typedef struct image { void *texture_; - void *render_target_; int format; // tex_format_t; - bool readable; - buffer_t *pixels; int width; int height; - int depth; } image_t; typedef struct draw_font_image draw_font_image_t; @@ -46,10 +42,6 @@ void draw_image(image_t *tex, float x, float y); void draw_scaled_texture(kinc_g5_texture_t *tex, float dx, float dy, float dw, float dh); void draw_sub_texture(kinc_g5_texture_t *tex, float sx, float sy, float sw, float sh, float x, float y); void draw_texture(kinc_g5_texture_t *tex, float x, float y); -void draw_scaled_sub_render_target(kinc_g5_texture_t *rt, float sx, float sy, float sw, float sh, float dx, float dy, float dw, float dh); -void draw_scaled_render_target(kinc_g5_texture_t *rt, float dx, float dy, float dw, float dh); -void draw_sub_render_target(kinc_g5_texture_t *rt, float sx, float sy, float sw, float sh, float x, float y); -void draw_render_target(kinc_g5_texture_t *rt, float x, float y); void draw_filled_triangle(float x0, float y0, float x1, float y1, float x2, float y2); void draw_filled_rect(float x, float y, float width, float height); void draw_rect(float x, float y, float width, float height, float strength); diff --git a/base/sources/iron_gpu.c b/base/sources/iron_gpu.c index 0d475fb3..96e8184f 100644 --- a/base/sources/iron_gpu.c +++ b/base/sources/iron_gpu.c @@ -65,10 +65,6 @@ typedef struct render_state { kinc_g5_texture_unit_t texture_units[MAX_TEXTURES]; int texture_count; - kinc_g5_texture_t *render_targets[MAX_TEXTURES]; - kinc_g5_texture_unit_t render_target_units[MAX_TEXTURES]; - int render_target_count; - kinc_g5_texture_t *depth_render_targets[MAX_TEXTURES]; kinc_g5_texture_unit_t depth_render_target_units[MAX_TEXTURES]; int depth_render_target_count; @@ -146,7 +142,6 @@ static void kinc_internal_start_draw(bool compute) { kinc_g5_constant_buffer_unlock(&computeConstantBuffer); kinc_g5_internal_set_samplers(current_state.texture_count, current_state.texture_units); - kinc_g5_internal_set_samplers(current_state.render_target_count, current_state.render_target_units); kinc_g5_internal_set_samplers(current_state.depth_render_target_count, current_state.depth_render_target_units); if (compute) { @@ -200,9 +195,6 @@ static void kinc_internal_end_draw(bool compute) { for (int i = 0; i < current_state.texture_count; ++i) { kinc_g5_command_list_set_texture(&commandList, current_state.texture_units[i], current_state.textures[i]); } - for (int i = 0; i < current_state.render_target_count; ++i) { - kinc_g5_command_list_set_texture_from_render_target(&commandList, current_state.render_target_units[i], current_state.render_targets[i]); - } for (int i = 0; i < current_state.depth_render_target_count; ++i) { kinc_g5_command_list_set_texture_from_render_target_depth(&commandList, current_state.depth_render_target_units[i], current_state.depth_render_targets[i]); @@ -237,7 +229,7 @@ void kinc_g5_draw_indexed_vertices_from_to(int start, int count) { kinc_internal_end_draw(false); } -void kinc_g5_clear(unsigned flags, unsigned color, float depth) { +void kinc_g5_clear(unsigned color, float depth, unsigned flags) { if (windows[0].current_render_target_count > 0) { if (windows[0].current_render_targets[0] == NULL) { kinc_g5_command_list_clear(&commandList, &windows[0].framebuffers[windows[0].currentBuffer], flags, color, depth); @@ -262,7 +254,7 @@ void kinc_g4_begin() { bool resized = windows[0].resized; if (resized) { for (int i = 0; i < FRAMEBUFFER_COUNT; ++i) { - kinc_g5_render_target_destroy(&windows[0].framebuffers[i]); + kinc_g5_texture_destroy(&windows[0].framebuffers[i]); } windows[0].currentBuffer = 0; } @@ -287,7 +279,6 @@ void kinc_g4_begin() { current_state.viewport_set = false; current_state.scissor_set = false; current_state.texture_count = 0; - current_state.render_target_count = 0; current_state.depth_render_target_count = 0; kinc_internal_samplers_reset(); @@ -529,40 +520,19 @@ void kinc_g4_set_index_buffer(kinc_g5_index_buffer_t *buffer) { kinc_g5_command_list_set_index_buffer(&commandList, buffer); } -void kinc_g4_set_texture(kinc_g5_texture_unit_t unit, kinc_g5_texture_t *texture) { - if (!texture->_uploaded) { - kinc_g5_command_list_upload_texture(&commandList, texture); - texture->_uploaded = true; - } - - kinc_g5_texture_unit_t g5_unit; - memcpy(&g5_unit.stages[0], &unit.stages[0], KINC_G5_SHADER_TYPE_COUNT * sizeof(int)); - - bool found = false; - for (int i = 0; i < current_state.texture_count; ++i) { - if (kinc_g5_texture_unit_equals(¤t_state.texture_units[i], &g5_unit)) { - current_state.textures[i] = texture; - current_state.texture_units[i] = g5_unit; - found = true; - break; - } - } - if (!found) { - assert(current_state.texture_count < MAX_TEXTURES); - current_state.textures[current_state.texture_count] = texture; - current_state.texture_units[current_state.texture_count] = g5_unit; - current_state.texture_count += 1; - } - - kinc_g5_command_list_set_texture(&commandList, g5_unit, texture); -} - void kinc_g5_set_pipeline(kinc_g5_pipeline_t *pipeline) { current_state.pipeline = pipeline; kinc_g5_command_list_set_pipeline(&commandList, pipeline); } -void kinc_g4_render_target_use_color_as_texture(kinc_g5_texture_t *render_target, kinc_g5_texture_unit_t unit) { +void kinc_g4_set_texture(kinc_g5_texture_unit_t unit, kinc_g5_texture_t *render_target) { + + if (!render_target->_uploaded) { + kinc_g5_command_list_upload_texture(&commandList, render_target); + render_target->_uploaded = true; + } + + if (render_target->state != KINC_INTERNAL_RENDER_TARGET_STATE_TEXTURE) { kinc_g5_command_list_render_target_to_texture_barrier(&commandList, render_target); render_target->state = KINC_INTERNAL_RENDER_TARGET_STATE_TEXTURE; @@ -572,22 +542,21 @@ void kinc_g4_render_target_use_color_as_texture(kinc_g5_texture_t *render_target memcpy(&g5_unit.stages[0], &unit.stages[0], KINC_G5_SHADER_TYPE_COUNT * sizeof(int)); bool found = false; - for (int i = 0; i < current_state.render_target_count; ++i) { - if (kinc_g5_texture_unit_equals(¤t_state.render_target_units[i], &g5_unit)) { - current_state.render_targets[i] = render_target; - current_state.render_target_units[i] = g5_unit; + for (int i = 0; i < current_state.texture_count; ++i) { + if (kinc_g5_texture_unit_equals(¤t_state.texture_units[i], &g5_unit)) { + current_state.textures[i] = render_target; + current_state.texture_units[i] = g5_unit; found = true; break; } } if (!found) { - assert(current_state.render_target_count < MAX_TEXTURES); - current_state.render_targets[current_state.render_target_count] = render_target; - current_state.render_target_units[current_state.render_target_count] = g5_unit; - current_state.render_target_count += 1; + current_state.textures[current_state.texture_count] = render_target; + current_state.texture_units[current_state.texture_count] = g5_unit; + current_state.texture_count += 1; } - kinc_g5_command_list_set_texture_from_render_target(&commandList, g5_unit, render_target); + kinc_g5_command_list_set_texture(&commandList, g5_unit, render_target); } void kinc_g4_render_target_use_depth_as_texture(kinc_g5_texture_t *render_target, kinc_g5_texture_unit_t unit) { @@ -633,10 +602,6 @@ void kinc_g5_render_target_get_pixels(kinc_g5_texture_t *render_target, uint8_t kinc_g5_command_list_get_render_target_pixels(&commandList, render_target, data); } -void kinc_g5_render_target_generate_mipmaps(kinc_g5_texture_t *render_target, int levels) { - -} - void kinc_g4_index_buffer_unlock_all(kinc_g5_index_buffer_t *buffer) { kinc_g5_index_buffer_unlock_all(buffer); kinc_g5_command_list_upload_index_buffer(&commandList, buffer); diff --git a/base/sources/iron_gpu.h b/base/sources/iron_gpu.h index dae5974d..3f8512d3 100644 --- a/base/sources/iron_gpu.h +++ b/base/sources/iron_gpu.h @@ -6,6 +6,7 @@ #include #include #include +#include #include BACKEND_GPU_H #define KINC_G5_CLEAR_COLOR 1 @@ -45,6 +46,8 @@ typedef struct kinc_g5_texture { bool isDepthAttachment; enum kinc_internal_render_target_state state; + buffer_t *buffer; + Texture5Impl impl; } kinc_g5_texture_t; @@ -97,7 +100,7 @@ typedef enum kinc_g4_usage { void kinc_g4_begin(); void kinc_g4_end(); -void kinc_g5_clear(unsigned flags, unsigned color, float depth); +void kinc_g5_clear(unsigned color, float depth, unsigned flags); void kinc_g4_viewport(int x, int y, int width, int height); void kinc_g4_scissor(int x, int y, int width, int height); void kinc_g4_disable_scissor(void); @@ -129,10 +132,7 @@ void kinc_g4_set_index_buffer(struct kinc_g5_index_buffer *buffer); void kinc_g4_internal_init_window(int depth_buffer_bits, bool vsync); -void kinc_g4_render_target_use_color_as_texture(struct kinc_g5_texture *renderTarget, struct kinc_g5_texture_unit unit); void kinc_g4_render_target_use_depth_as_texture(struct kinc_g5_texture *renderTarget, struct kinc_g5_texture_unit unit); -void kinc_g5_render_target_get_pixels(struct kinc_g5_texture *renderTarget, uint8_t *data); -void kinc_g5_render_target_generate_mipmaps(struct kinc_g5_texture *renderTarget, int levels); void kinc_g4_index_buffer_unlock_all(struct kinc_g5_index_buffer *buffer); void kinc_g4_index_buffer_unlock(struct kinc_g5_index_buffer *buffer, int count); @@ -196,7 +196,6 @@ struct kinc_g5_texture_unit; void kinc_g5_render_target_init(kinc_g5_texture_t *target, int width, int height, kinc_image_format_t format, int depthBufferBits); void kinc_g5_render_target_init_framebuffer(kinc_g5_texture_t *target, int width, int height, kinc_image_format_t format, int depthBufferBits); -void kinc_g5_render_target_destroy(kinc_g5_texture_t *target); void kinc_g5_render_target_set_depth_from(kinc_g5_texture_t *target, kinc_g5_texture_t *source); typedef struct kinc_g5_vertex_buffer { @@ -453,10 +452,11 @@ void kinc_g5_command_list_wait_for_execution_to_finish(kinc_g5_command_list_t *l void kinc_g5_command_list_get_render_target_pixels(kinc_g5_command_list_t *list, struct kinc_g5_texture *render_target, uint8_t *data); void kinc_g5_command_list_compute(kinc_g5_command_list_t *list, int x, int y, int z); void kinc_g5_command_list_set_texture(kinc_g5_command_list_t *list, kinc_g5_texture_unit_t unit, kinc_g5_texture_t *texture); -void kinc_g5_command_list_set_texture_from_render_target(kinc_g5_command_list_t *list, kinc_g5_texture_unit_t unit, kinc_g5_texture_t *target); void kinc_g5_command_list_set_texture_from_render_target_depth(kinc_g5_command_list_t *list, kinc_g5_texture_unit_t unit, kinc_g5_texture_t *target); void kinc_g5_command_list_set_sampler(kinc_g5_command_list_t *list, kinc_g5_texture_unit_t unit, kinc_g5_sampler_t *sampler); +void kinc_g5_render_target_get_pixels(kinc_g5_texture_t *render_target, uint8_t *data); + typedef struct kinc_g5_compute_shader { kinc_g5_compute_shader_impl impl; } kinc_g5_compute_shader; diff --git a/base/sources/iron_ui.c b/base/sources/iron_ui.c index 3a108dcd..1032490c 100644 --- a/base/sources/iron_ui.c +++ b/base/sources/iron_ui.c @@ -196,10 +196,10 @@ void ui_draw_rect(bool fill, float x, float y, float w, float h) { if (theme->ROUND_CORNERS && current->enabled && r > 0 && w >= r * 2.0) { y -= 1; // Make it pixel perfect with non-round draw h += 1; - draw_scaled_render_target(¤t->filled_round_corner_image, x, y, r, r); - draw_scaled_render_target(¤t->filled_round_corner_image, x, y + h, r, -r); - draw_scaled_render_target(¤t->filled_round_corner_image, x + w, y, -r, r); - draw_scaled_render_target(¤t->filled_round_corner_image, x + w, y + h, -r, -r); + draw_scaled_texture(¤t->filled_round_corner_image, x, y, r, r); + draw_scaled_texture(¤t->filled_round_corner_image, x, y + h, r, -r); + draw_scaled_texture(¤t->filled_round_corner_image, x + w, y, -r, r); + draw_scaled_texture(¤t->filled_round_corner_image, x + w, y + h, -r, -r); draw_filled_rect(x + r, y, w - r * 2.0, h); draw_filled_rect(x, y + r, w, h - r * 2.0); } @@ -214,10 +214,10 @@ void ui_draw_rect(bool fill, float x, float y, float w, float h) { w += 1; y -= 1; h += 1; - draw_scaled_render_target(¤t->round_corner_image, x, y, r, r); - draw_scaled_render_target(¤t->round_corner_image, x, y + h, r, -r); - draw_scaled_render_target(¤t->round_corner_image, x + w, y, -r, r); - draw_scaled_render_target(¤t->round_corner_image, x + w, y + h, -r, -r); + draw_scaled_texture(¤t->round_corner_image, x, y, r, r); + draw_scaled_texture(¤t->round_corner_image, x, y + h, r, -r); + draw_scaled_texture(¤t->round_corner_image, x + w, y, -r, r); + draw_scaled_texture(¤t->round_corner_image, x + w, y + h, -r, -r); draw_filled_rect(x + r, y, w - r * 2.0, strength); draw_filled_rect(x + r, y + h - 1, w - r * 2.0, strength); draw_filled_rect(x, y + r, strength, h - r * 2.0); @@ -236,8 +236,8 @@ void ui_draw_round_bottom(float x, float y, float w) { y -= 1; // Make it pixel perfect with non-round draw h += 1; draw_set_color(theme->SEPARATOR_COL); - draw_scaled_render_target(¤t->filled_round_corner_image, x, y + h, r, -r); - draw_scaled_render_target(¤t->filled_round_corner_image, x + w, y + h, -r, -r); + draw_scaled_texture(¤t->filled_round_corner_image, x, y + h, r, -r); + draw_scaled_texture(¤t->filled_round_corner_image, x + w, y + h, -r, -r); draw_filled_rect(x + r, y, w - r * 2.0, h); } } @@ -473,7 +473,7 @@ void ui_end_element() { void ui_resize(ui_handle_t *handle, int w, int h) { handle->redraws = 2; if (handle->texture.width != 0) { - kinc_g5_render_target_destroy(&handle->texture); + kinc_g5_texture_destroy(&handle->texture); } if (w < 1) { w = 1; @@ -592,13 +592,6 @@ void ui_draw_tooltip_text(bool bind_global_g) { } off = current->tooltip_img->height * (w / current->tooltip_img->width); } - else if (current->tooltip_rt != NULL) { - float w = current->tooltip_rt->width; - if (current->tooltip_img_max_width != 0 && w > current->tooltip_img_max_width) { - w = current->tooltip_img_max_width; - } - off = current->tooltip_rt->height * (w / current->tooltip_rt->width); - } int x = current->tooltip_x - 5; int y = current->tooltip_y + off - 5; @@ -634,25 +627,6 @@ void ui_draw_tooltip_image(bool bind_global_g) { draw_scaled_texture(current->tooltip_img, current->tooltip_x, current->tooltip_y, w, h); } -void ui_draw_tooltip_rt(bool bind_global_g) { - float w = current->tooltip_rt->width; - if (current->tooltip_img_max_width != 0 && w > current->tooltip_img_max_width) { - w = current->tooltip_img_max_width; - } - float h = current->tooltip_rt->height * (w / current->tooltip_rt->width); - current->tooltip_x = fmin(current->tooltip_x, kinc_window_width() - w - 20); - current->tooltip_y = fmin(current->tooltip_y, kinc_window_height() - h - 20); - if (bind_global_g) { - draw_restore_render_target(); - } - draw_set_color(0xff000000); - draw_filled_rect(current->tooltip_x, current->tooltip_y, w, h); - draw_set_color(0xffffffff); - current->tooltip_invert_y ? - draw_scaled_render_target(current->tooltip_rt, current->tooltip_x, current->tooltip_y + h, w, -h) : - draw_scaled_render_target(current->tooltip_rt, current->tooltip_x, current->tooltip_y, w, h); -} - void ui_draw_tooltip(bool bind_global_g) { static char temp[1024]; if (current->slider_tooltip) { @@ -686,7 +660,7 @@ void ui_draw_tooltip(bool bind_global_g) { draw_string(current->text_selected, x - x_off, y - y_off); } - if (current->tooltip_text[0] != '\0' || current->tooltip_img != NULL || current->tooltip_rt != NULL) { + if (current->tooltip_text[0] != '\0' || current->tooltip_img != NULL) { if (ui_input_changed()) { current->tooltip_shown = false; current->tooltip_wait = current->input_dx == 0 && current->input_dy == 0; // Wait for movement before showing up again @@ -700,9 +674,6 @@ void ui_draw_tooltip(bool bind_global_g) { if (current->tooltip_img != NULL) { ui_draw_tooltip_image(bind_global_g); } - else if (current->tooltip_rt != NULL) { - ui_draw_tooltip_rt(bind_global_g); - } if (current->tooltip_text[0] != '\0') { ui_draw_tooltip_text(bind_global_g); } @@ -892,24 +863,24 @@ void ui_draw_combo(bool begin /*= true*/) { void ui_bake_elements() { if (current->check_select_image.width != 0) { - kinc_g5_render_target_destroy(¤t->check_select_image); + kinc_g5_texture_destroy(¤t->check_select_image); } float r = UI_CHECK_SELECT_SIZE(); kinc_g5_render_target_init(¤t->check_select_image, r, r, KINC_IMAGE_FORMAT_RGBA32, 0); draw_set_render_target(¤t->check_select_image); - kinc_g5_clear(KINC_G5_CLEAR_COLOR, 0x00000000, 0); + kinc_g5_clear(0x00000000, 0, KINC_G5_CLEAR_COLOR); draw_set_color(0xffffffff); draw_line(0, r / 2.0, r / 2.0 - 2.0 * UI_SCALE(), r - 2.0 * UI_SCALE(), 2.0 * UI_SCALE()); draw_line(r / 2.0 - 3.0 * UI_SCALE(), r - 3.0 * UI_SCALE(), r / 2.0 + 5.0 * UI_SCALE(), r - 11.0 * UI_SCALE(), 2.0 * UI_SCALE()); draw_end(); if (current->radio_image.width != 0) { - kinc_g5_render_target_destroy(¤t->radio_image); + kinc_g5_texture_destroy(¤t->radio_image); } r = UI_CHECK_SIZE(); kinc_g5_render_target_init(¤t->radio_image, r, r, KINC_IMAGE_FORMAT_RGBA32, 0); draw_set_render_target(¤t->radio_image); - kinc_g5_clear(KINC_G5_CLEAR_COLOR, 0x00000000, 0); + kinc_g5_clear(0x00000000, 0, KINC_G5_CLEAR_COLOR); draw_set_color(0xffaaaaaa); draw_filled_circle(r / 2.0, r / 2.0, r / 2.0, 0); draw_set_color(0xffffffff); @@ -917,12 +888,12 @@ void ui_bake_elements() { draw_end(); if (current->radio_select_image.width != 0) { - kinc_g5_render_target_destroy(¤t->radio_select_image); + kinc_g5_texture_destroy(¤t->radio_select_image); } r = UI_CHECK_SELECT_SIZE(); kinc_g5_render_target_init(¤t->radio_select_image, r, r, KINC_IMAGE_FORMAT_RGBA32, 0); draw_set_render_target(¤t->radio_select_image); - kinc_g5_clear(KINC_G5_CLEAR_COLOR, 0x00000000, 0); + kinc_g5_clear(0x00000000, 0, KINC_G5_CLEAR_COLOR); draw_set_color(0xffaaaaaa); draw_filled_circle(r / 2.0, r / 2.0, 4.5 * UI_SCALE(), 0); draw_set_color(0xffffffff); @@ -931,22 +902,22 @@ void ui_bake_elements() { if (theme->ROUND_CORNERS) { if (current->filled_round_corner_image.width != 0) { - kinc_g5_render_target_destroy(¤t->filled_round_corner_image); + kinc_g5_texture_destroy(¤t->filled_round_corner_image); } r = 4.0 * UI_SCALE(); kinc_g5_render_target_init(¤t->filled_round_corner_image, r, r, KINC_IMAGE_FORMAT_RGBA32, 0); draw_set_render_target(¤t->filled_round_corner_image); - kinc_g5_clear(KINC_G5_CLEAR_COLOR, 0x00000000, 0); + kinc_g5_clear(0x00000000, 0, KINC_G5_CLEAR_COLOR); draw_set_color(0xffffffff); draw_filled_circle(r, r, r, 0); draw_end(); if (current->round_corner_image.width != 0) { - kinc_g5_render_target_destroy(¤t->round_corner_image); + kinc_g5_texture_destroy(¤t->round_corner_image); } kinc_g5_render_target_init(¤t->round_corner_image, r, r, KINC_IMAGE_FORMAT_RGBA32, 0); draw_set_render_target(¤t->round_corner_image); - kinc_g5_clear(KINC_G5_CLEAR_COLOR, 0x00000000, 0); + kinc_g5_clear(0x00000000, 0, KINC_G5_CLEAR_COLOR); draw_set_color(0xffffffff); draw_circle(r, r, r, 0, 1); draw_end(); @@ -965,7 +936,6 @@ void ui_begin_region(ui_t *ui, int x, int y, int w) { current->current_window = NULL; current->tooltip_text[0] = '\0'; current->tooltip_img = NULL; - current->tooltip_rt = NULL; current->_window_x = 0; current->_window_y = 0; current->_window_w = w; @@ -1422,7 +1392,7 @@ void ui_draw_check(bool selected, bool hover) { ui_fade_color(0.25); } int size = UI_CHECK_SELECT_SIZE(); - draw_scaled_render_target(¤t->check_select_image, x + current->check_select_offset_x, y + current->check_select_offset_y, size, size); + draw_scaled_texture(¤t->check_select_image, x + current->check_select_offset_x, y + current->check_select_offset_y, size, size); } } @@ -1430,14 +1400,14 @@ void ui_draw_radio(bool selected, bool hover) { float x = current->_x + current->radio_offset_x; float y = current->_y + current->radio_offset_y; draw_set_color(selected ? theme->HIGHLIGHT_COL : hover ? theme->HOVER_COL : theme->BUTTON_COL); - draw_render_target(¤t->radio_image, x, y); // Circle bg + draw_texture(¤t->radio_image, x, y); // Circle bg if (selected) { // Check draw_set_color(theme->LABEL_COL); if (!current->enabled) { ui_fade_color(0.25); } - draw_render_target(¤t->radio_select_image, x + current->radio_select_offset_x, y + current->radio_select_offset_y); // Circle + draw_texture(¤t->radio_select_image, x + current->radio_select_offset_x, y + current->radio_select_offset_y); // Circle } } @@ -1639,7 +1609,7 @@ void ui_end_window(bool bind_global_g) { draw_restore_render_target(); } draw_set_color(0xffffffff); - draw_render_target(&handle->texture, current->_window_x, current->_window_y); + draw_texture(&handle->texture, current->_window_x, current->_window_y); if (handle->redraws <= 0) { handle->redraws--; } @@ -1708,14 +1678,13 @@ bool _ui_window(ui_handle_t *handle, int x, int y, int w, int h, bool drag) { current->_h = h; current->tooltip_text[0] = 0; current->tooltip_img = NULL; - current->tooltip_rt = NULL; current->tab_count = 0; if (theme->FILL_WINDOW_BG) { - kinc_g5_clear(KINC_G5_CLEAR_COLOR, theme->WINDOW_BG_COL, 0); + kinc_g5_clear(theme->WINDOW_BG_COL, 0, KINC_G5_CLEAR_COLOR); } else { - kinc_g5_clear(KINC_G5_CLEAR_COLOR, 0x00000000, 0); + kinc_g5_clear(0x00000000, 0, KINC_G5_CLEAR_COLOR); draw_set_color(theme->WINDOW_BG_COL); draw_filled_rect(current->_x, current->_y - handle->scroll_offset, handle->last_max_x, handle->last_max_y); } @@ -1873,45 +1842,25 @@ bool ui_panel(ui_handle_t *handle, char *text, bool is_tree, bool filled) { return handle->selected; } -static int image_width(void *image, bool is_rt) { - if (is_rt) { - return ((kinc_g5_texture_t *)image)->width; - } - else { - return ((kinc_g5_texture_t *)image)->width; - } +static int image_width(void *image) { + return ((kinc_g5_texture_t *)image)->width; } -static int image_height(void *image, bool is_rt) { - if (is_rt) { - return ((kinc_g5_texture_t *)image)->height; - } - else { - return ((kinc_g5_texture_t *)image)->height; - } +static int image_height(void *image) { + return ((kinc_g5_texture_t *)image)->height; } -static void _draw_scaled_image(void *image, bool is_rt, float dx, float dy, float dw, float dh) { - if (is_rt) { - draw_scaled_render_target((kinc_g5_texture_t *)image, dx, dy, dw, dh); - } - else { - draw_scaled_texture((kinc_g5_texture_t *)image, dx, dy, dw, dh); - } +static void _draw_scaled_image(void *image, float dx, float dy, float dw, float dh) { + draw_scaled_texture((kinc_g5_texture_t *)image, dx, dy, dw, dh); } -static void _draw_scaled_sub_image(void *image, bool is_rt, float sx, float sy, float sw, float sh, float dx, float dy, float dw, float dh) { - if (is_rt) { - draw_scaled_sub_render_target((kinc_g5_texture_t *)image, sx, sy, sw, sh, dx, dy, dw, dh); - } - else { - draw_scaled_sub_texture((kinc_g5_texture_t *)image, sx, sy, sw, sh, dx, dy, dw, dh); - } +static void _draw_scaled_sub_image(void *image, float sx, float sy, float sw, float sh, float dx, float dy, float dw, float dh) { + draw_scaled_sub_texture((kinc_g5_texture_t *)image, sx, sy, sw, sh, dx, dy, dw, dh); } -int ui_sub_image(/*kinc_g5_texture_t kinc_g5_texture_t*/ void *image, bool is_rt, uint32_t tint, int h, int sx, int sy, int sw, int sh) { - float iw = (sw > 0 ? sw : image_width(image, is_rt)) * UI_SCALE(); - float ih = (sh > 0 ? sh : image_height(image, is_rt)) * UI_SCALE(); +int ui_sub_image(kinc_g5_texture_t *image, uint32_t tint, int h, int sx, int sy, int sw, int sh) { + float iw = (sw > 0 ? sw : image_width(image)) * UI_SCALE(); + float ih = (sh > 0 ? sh : image_height(image)) * UI_SCALE(); float w = fmin(iw, current->_w); float x = current->_x; float scroll = current->current_window != NULL ? current->current_window->scroll_enabled : false; @@ -1961,18 +1910,18 @@ int ui_sub_image(/*kinc_g5_texture_t kinc_g5_texture_t*/ void *image, bool is_rt } if (sw > 0) { // Source rect specified if (current->image_invert_y) { - _draw_scaled_sub_image(image, is_rt, sx, sy, sw, sh, x, current->_y + h, w, -h); + _draw_scaled_sub_image(image, sx, sy, sw, sh, x, current->_y + h, w, -h); } else { - _draw_scaled_sub_image(image, is_rt, sx, sy, sw, sh, x, current->_y, w, h); + _draw_scaled_sub_image(image, sx, sy, sw, sh, x, current->_y, w, h); } } else { if (current->image_invert_y) { - _draw_scaled_image(image, is_rt, x, current->_y + h, w, -h); + _draw_scaled_image(image, x, current->_y + h, w, -h); } else { - _draw_scaled_image(image, is_rt, x, current->_y, w, h); + _draw_scaled_image(image, x, current->_y, w, h); } } @@ -1980,8 +1929,8 @@ int ui_sub_image(/*kinc_g5_texture_t kinc_g5_texture_t*/ void *image, bool is_rt return started ? UI_STATE_STARTED : released ? UI_STATE_RELEASED : down ? UI_STATE_DOWN : hover ? UI_STATE_HOVERED : UI_STATE_IDLE; } -int ui_image(/*kinc_g5_texture_t kinc_g5_texture_t*/ void *image, bool is_rt, uint32_t tint, int h) { - return ui_sub_image(image, is_rt, tint, h, 0, 0, image_width(image, is_rt), image_height(image, is_rt)); +int ui_image(kinc_g5_texture_t *image, uint32_t tint, int h) { + return ui_sub_image(image, tint, h, 0, 0, image_width(image), image_height(image)); } char *ui_text_input(ui_handle_t *handle, char *label, int align, bool editable, bool live_update) { @@ -2298,13 +2247,6 @@ void ui_tooltip_image(kinc_g5_texture_t *image, int max_width) { current->tooltip_y = current->_y + current->_window_y; } -void ui_tooltip_render_target(kinc_g5_texture_t *image, int max_width) { - current->tooltip_rt = image; - current->tooltip_img_max_width = max_width; - current->tooltip_invert_y = current->image_invert_y; - current->tooltip_y = current->_y + current->_window_y; -} - void _ui_end(bool last) { if (!current->window_ended) { ui_end_window(true); @@ -2865,7 +2807,7 @@ int ui_color_wheel(ui_handle_t *handle, bool alpha, float w, float h, bool color current->_w = _w; uint32_t col = ui_color(round(cval * 255.0f), round(cval * 255.0f), round(cval * 255.0f), 255); - ui_image(current->ops->color_wheel, false, col, -1); + ui_image(current->ops->color_wheel, col, -1); // Picker float ph = current->_y - py; @@ -2888,7 +2830,7 @@ int ui_color_wheel(ui_handle_t *handle, bool alpha, float w, float h, bool color current->_x = px - (scroll ? 0 : UI_SCROLL_W() / 2.0); current->_y = py; - ui_image(current->ops->black_white_gradient, false, 0xffffffff, -1); + ui_image(current->ops->black_white_gradient, 0xffffffff, -1); draw_set_color(0xff000000); draw_filled_rect(cx - 3.0 * UI_SCALE(), cy - 3.0 * UI_SCALE(), 6.0 * UI_SCALE(), 6.0 * UI_SCALE()); diff --git a/base/sources/iron_ui.h b/base/sources/iron_ui.h index 641dd93c..e6395422 100644 --- a/base/sources/iron_ui.h +++ b/base/sources/iron_ui.h @@ -233,7 +233,6 @@ typedef struct ui { int combo_initial_value; char tooltip_text[512]; kinc_g5_texture_t *tooltip_img; - kinc_g5_texture_t *tooltip_rt; int tooltip_img_max_width; bool tooltip_invert_y; float tooltip_x; @@ -270,8 +269,8 @@ bool ui_button(char *text, int align, char *label); int ui_text(char *text, int align, int bg); bool ui_tab(ui_handle_t *handle, char *text, bool vertical, uint32_t color); bool ui_panel(ui_handle_t *handle, char *text, bool is_tree, bool filled); -int ui_sub_image(/*kinc_g5_texture_t kinc_g5_texture_t*/ void *image, bool is_rt, uint32_t tint, int h, int sx, int sy, int sw, int sh); -int ui_image(/*kinc_g5_texture_t kinc_g5_texture_t*/ void *image, bool is_rt, uint32_t tint, int h); +int ui_sub_image(kinc_g5_texture_t *image, uint32_t tint, int h, int sx, int sy, int sw, int sh); +int ui_image(kinc_g5_texture_t *image, uint32_t tint, int h); char *ui_text_input(ui_handle_t *handle, char *label, int align, bool editable, bool live_update); bool ui_check(ui_handle_t *handle, char *text, char *label); bool ui_radio(ui_handle_t *handle, int position, char *text, char *label); @@ -281,7 +280,6 @@ void ui_row(f32_array_t *ratios); void ui_separator(int h, bool fill); void ui_tooltip(char *text); void ui_tooltip_image(kinc_g5_texture_t *image, int max_width); -void ui_tooltip_render_target(kinc_g5_texture_t *image, int max_width); void _ui_end(bool last); void ui_end_window(bool bind_global_g); char *ui_hovered_tab_name(); diff --git a/base/sources/iron_ui_nodes.c b/base/sources/iron_ui_nodes.c index 152fce64..260d8f6a 100644 --- a/base/sources/iron_ui_nodes.c +++ b/base/sources/iron_ui_nodes.c @@ -236,11 +236,11 @@ int ui_get_socket_id(ui_node_array_t *nodes) { void ui_nodes_bake_elements() { if (ui_socket_image.width != 0) { - kinc_g5_render_target_destroy(&ui_socket_image); + kinc_g5_texture_destroy(&ui_socket_image); } kinc_g5_render_target_init(&ui_socket_image, 24, 24, KINC_IMAGE_FORMAT_RGBA32, 0); draw_set_render_target(&ui_socket_image); - kinc_g5_clear(KINC_G5_CLEAR_COLOR, 0x00000000, 0); + kinc_g5_clear(0x00000000, 0, KINC_G5_CLEAR_COLOR); draw_set_color(0xff111111); draw_filled_circle(12, 12, 11, 0); @@ -452,7 +452,7 @@ void ui_draw_node(ui_node_t *node, ui_node_canvas_t *canvas) { ui_node_socket_t *out = node->outputs->buffer[i]; ny += lineh; draw_set_color(out->color); - draw_scaled_render_target(&ui_socket_image, nx + w - ui_p(6), ny - ui_p(3), ui_p(12), ui_p(12)); + draw_scaled_texture(&ui_socket_image, nx + w - ui_p(6), ny - ui_p(3), ui_p(12), ui_p(12)); } ny -= lineh * node->outputs->length; draw_set_color(current->ops->theme->LABEL_COL); @@ -636,7 +636,7 @@ void ui_draw_node(ui_node_t *node, ui_node_canvas_t *canvas) { ui_node_socket_t *inp = node->inputs->buffer[i]; ny += lineh; draw_set_color(inp->color); - draw_scaled_render_target(&ui_socket_image, nx - ui_p(6), ny - ui_p(3), ui_p(12), ui_p(12)); + draw_scaled_texture(&ui_socket_image, nx - ui_p(6), ny - ui_p(3), ui_p(12), ui_p(12)); bool is_linked = ui_input_linked(canvas, node->id, i); if (!is_linked && strcmp(inp->type, "VALUE") == 0) { current->_x = nx + ui_p(6); diff --git a/base/sources/ts/export_texture.ts b/base/sources/ts/export_texture.ts index c55f4a3c..68daf039 100644 --- a/base/sources/ts/export_texture.ts +++ b/base/sources/ts/export_texture.ts @@ -190,14 +190,14 @@ function export_texture_run_layers(path: string, layers: slot_layer_t[], object_ } // Clear export layer - g4_begin(layers_expa); - g4_clear(color_from_floats(0.0, 0.0, 0.0, 0.0)); + iron_g4_begin(layers_expa); + kinc_g5_clear(color_from_floats(0.0, 0.0, 0.0, 0.0)); iron_g4_end(); - g4_begin(layers_expb); - g4_clear(color_from_floats(0.5, 0.5, 1.0, 0.0)); + iron_g4_begin(layers_expb); + kinc_g5_clear(color_from_floats(0.5, 0.5, 1.0, 0.0)); iron_g4_end(); - g4_begin(layers_expc); - g4_clear(color_from_floats(1.0, 0.0, 0.0, 0.0)); + iron_g4_begin(layers_expc); + kinc_g5_clear(color_from_floats(1.0, 0.0, 0.0, 0.0)); iron_g4_end(); // Flatten layers @@ -226,7 +226,7 @@ function export_texture_run_layers(path: string, layers: slot_layer_t[], object_ if (l1masks.length > 1) { layers_make_temp_mask_img(); g2_begin(pipes_temp_mask_image); - g4_clear(0x00000000); + kinc_g5_clear(0x00000000); g2_end(); let l1: slot_layer_t = { texpaint: pipes_temp_mask_image @@ -248,7 +248,7 @@ function export_texture_run_layers(path: string, layers: slot_layer_t[], object_ draw_set_pipeline(null); g2_end(); - g4_begin(layers_expa); + iron_g4_begin(layers_expa); kinc_g5_set_pipeline(pipes_merge); g4_set_tex(pipes_tex0, l1.texpaint); g4_set_tex(pipes_tex1, empty); @@ -269,7 +269,7 @@ function export_texture_run_layers(path: string, layers: slot_layer_t[], object_ draw_set_pipeline(null); g2_end(); - g4_begin(layers_expb); + iron_g4_begin(layers_expb); kinc_g5_set_pipeline(pipes_merge); g4_set_tex(pipes_tex0, l1.texpaint); g4_set_tex(pipes_tex1, l1.texpaint_nor); @@ -436,9 +436,9 @@ function export_texture_run_layers(path: string, layers: slot_layer_t[], object_ } // Release staging memory allocated in image_get_pixels() - texpaint.pixels = null; - texpaint_nor.pixels = null; - texpaint_pack.pixels = null; + // texpaint.pixels = null; + // texpaint_nor.pixels = null; + // texpaint_pack.pixels = null; } function export_texture_write_texture(file: string, pixels: buffer_t, type: i32 = 1, off: i32 = 0) { diff --git a/base/sources/ts/import_envmap.ts b/base/sources/ts/import_envmap.ts index 760a60d8..929dd636 100644 --- a/base/sources/ts/import_envmap.ts +++ b/base/sources/ts/import_envmap.ts @@ -87,7 +87,7 @@ function import_envmap_run(path: string, image: image_t) { } function import_envmap_get_radiance_mip(mip: image_t, level: i32, radiance: image_t) { - g4_begin(mip); + iron_g4_begin(mip); kinc_g4_set_vertex_buffer(const_data_screen_aligned_vb); kinc_g4_set_index_buffer(const_data_screen_aligned_ib); kinc_g5_set_pipeline(import_envmap_pipeline); diff --git a/base/sources/ts/iron/g2.ts b/base/sources/ts/iron/g2.ts index d2e2b4fd..6dded8c8 100644 --- a/base/sources/ts/iron/g2.ts +++ b/base/sources/ts/iron/g2.ts @@ -61,7 +61,7 @@ function g2_begin(render_target: image_t = null) { draw_begin(); if (render_target != null) { - draw_set_render_target(render_target.render_target_); + draw_set_render_target(render_target.texture_); } else { draw_restore_render_target(); diff --git a/base/sources/ts/iron/g4.ts b/base/sources/ts/iron/g4.ts index 21a4a022..fcf287bc 100644 --- a/base/sources/ts/iron/g4.ts +++ b/base/sources/ts/iron/g4.ts @@ -45,25 +45,12 @@ function g4_vertex_struct_data_byte_size(data: vertex_data_t): i32 { return 0; } -function g4_begin(render_target: image_t, additional_targets: image_t[] = null) { - iron_g4_begin(render_target, additional_targets); -} -function g4_clear(color: color_t = 0x00000000, depth: f32 = 0.0, flags: i32 = clear_flag_t.COLOR) { - kinc_g5_clear(flags, color, depth); -} - function g4_set_tex(unit: kinc_tex_unit_t, tex: image_t) { - // if (tex == null) { - // return; - // } - tex.texture_ != null ? iron_g4_set_texture(unit, tex.texture_) : iron_g4_set_render_target(unit, tex.render_target_); + iron_g4_set_texture(unit, tex.texture_); } function g4_set_tex_depth(unit: kinc_tex_unit_t, tex: image_t) { - // if (tex == null) { - // return; - // } - iron_g4_set_texture_depth(unit, tex.render_target_); + iron_g4_set_texture_depth(unit, tex.texture_); } function g4_set_tex_params(tex_unit: kinc_tex_unit_t, u_addressing: tex_addressing_t, v_addressing: tex_addressing_t, minification_filter: tex_filter_t, magnification_filter: tex_filter_t, mipmap_filter: mip_map_filter_t) { @@ -98,12 +85,6 @@ function _image_set_size_from_texture(image: image_t, _tex: any) { image.height = tex.height; } -function _image_set_size_from_render_target(image: image_t, _rt: any) { - let rt: kinc_g5_texture_t = _rt; - image.width = rt.width; - image.height = rt.height; -} - function image_from_texture(tex: any): image_t { let image: image_t = _image_create(tex); _image_set_size_from_texture(image, tex); @@ -137,37 +118,14 @@ function image_create(width: i32, height: i32, format: tex_format_t = tex_format function image_create_render_target(width: i32, height: i32, format: tex_format_t = tex_format_t.RGBA32, depth_buffer_bits: i32 = 0): image_t { let image: image_t = _image_create(null); image.format = format; - image.render_target_ = iron_g4_create_render_target(width, height, format, depth_buffer_bits); - _image_set_size_from_render_target(image, image.render_target_); + image.texture_ = iron_g4_create_render_target(width, height, format, depth_buffer_bits); + _image_set_size_from_texture(image, image.texture_); return image; } -function image_format_byte_size(format: tex_format_t): i32 { - if (format == tex_format_t.RGBA32) { - return 4; - } - if (format == tex_format_t.R8) { - return 1; - } - if (format == tex_format_t.RGBA128) { - return 16; - } - if (format == tex_format_t.RGBA64) { - return 8; - } - if (format == tex_format_t.R32) { - return 4; - } - if (format == tex_format_t.R16) { - return 2; - } - return 4; -} - function image_unload(raw: image_t) { iron_unload_image(raw); raw.texture_ = null; - raw.render_target_ = null; } function image_lock(raw: image_t, level: i32 = 0): buffer_t { @@ -179,23 +137,11 @@ function image_unlock(raw: image_t) { } function image_get_pixels(raw: image_t): buffer_t { - if (raw.render_target_ != null) { - // Minimum size of 32x32 required after https://github.com/Kode/Kinc/commit/3797ebce5f6d7d360db3331eba28a17d1be87833 - let pixels_w: i32 = raw.width < 32 ? 32 : raw.width; - let pixels_h: i32 = raw.height < 32 ? 32 : raw.height; - if (raw.pixels == null) { - raw.pixels = buffer_create(image_format_byte_size(raw.format) * pixels_w * pixels_h); - } - iron_g4_get_render_target_pixels(raw.render_target_, raw.pixels); - return raw.pixels; - } - else { - return iron_g4_get_texture_pixels(raw.texture_); - } + return iron_g4_get_texture_pixels(raw.texture_); } function image_gen_mipmaps(raw: image_t, levels: i32) { - raw.texture_ == null ? kinc_g5_render_target_generate_mipmaps(raw.render_target_, levels) : kinc_g5_texture_generate_mipmaps(raw.texture_, levels); + kinc_g5_texture_generate_mipmaps(raw.texture_, levels); } function image_set_mipmaps(raw: image_t, mipmaps: image_t[]) { @@ -203,15 +149,12 @@ function image_set_mipmaps(raw: image_t, mipmaps: image_t[]) { } function image_set_depth_from(raw: image_t, image: image_t) { - kinc_g5_render_target_set_depth_from(raw.render_target_, image.render_target_); + kinc_g5_render_target_set_depth_from(raw.texture_, image.texture_); } declare type image_t = { texture_?: any; - render_target_?: any; format?: tex_format_t; - readable?: bool; - pixels?: buffer_t; width?: i32; height?: i32; }; diff --git a/base/sources/ts/iron/iron.ts b/base/sources/ts/iron/iron.ts index 7fd4abbe..d8a0c2c5 100644 --- a/base/sources/ts/iron/iron.ts +++ b/base/sources/ts/iron/iron.ts @@ -183,7 +183,7 @@ declare function color_set_ab(c: i32, i: u8): i32; declare function iron_init(ops: kinc_window_options_t): void; declare function kinc_set_app_name(name: string): void; declare function kinc_log(v: any): void; -declare function kinc_g5_clear(flags: i32, color: i32, depth: f32): void; +declare function kinc_g5_clear(color: i32, depth: f32 = 0.0, flags: i32 = clear_flag_t.COLOR): void; declare function iron_set_update_callback(callback: ()=>void): void; declare function iron_set_drop_files_callback(callback: (file: string)=>void): void; declare function iron_set_cut_copy_paste_callback(on_cut: ()=>string, on_copy: ()=>string, on_paste: (text: string)=>void): void; @@ -243,7 +243,6 @@ declare function kinc_copy_to_clipboard(text: string): void; declare function iron_g4_get_constant_location(pipeline: any, name: string): any; declare function iron_g4_get_texture_unit(pipeline: any, name: string): any; declare function iron_g4_set_texture(stage: any, texture: any): void; -declare function iron_g4_set_render_target(stage: any, render_target: any): void; declare function iron_g4_set_texture_depth(unit: any, texture: any): void; declare function iron_g4_set_texture_parameters(tex_unit: any, u_addr: i32, v_addr: i32, min_filter: i32, mag_filter: i32, mip_filter: i32): void; declare function iron_g4_set_bool(location: any, value: bool): void; @@ -280,17 +279,15 @@ declare function iron_g4_create_texture(width: i32, height: i32, format: i32): a 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_get_texture_pixels(texture: any): buffer_t; -declare function iron_g4_get_render_target_pixels(render_target: any, data: buffer_t): void; declare function iron_g4_lock_texture(texture: any, level: i32): buffer_t; declare function kinc_g5_texture_unlock(texture: any): void; declare function kinc_g5_texture_generate_mipmaps(texture: any, levels: i32): void; -declare function kinc_g5_render_target_generate_mipmaps(render_target: any, levels: i32): void; declare function iron_g4_set_mipmaps(texture: any, mipmaps: image_t[]): void; declare function kinc_g5_render_target_set_depth_from(target: any, source: any): void; declare function kinc_g4_viewport(x: i32, y: i32, width: i32, height: i32): void; declare function kinc_g4_scissor(x: i32, y: i32, width: i32, height: i32): void; declare function kinc_g4_disable_scissor(): void; -declare function iron_g4_begin(render_target: image_t, additional: image_t[]): void; +declare function iron_g4_begin(render_target: image_t, additional: image_t[] = null): void; declare function iron_g4_end(): void; declare function iron_g4_swap_buffers(): void; declare function iron_file_save_bytes(path: string, bytes: buffer_t, length?: i32): void; diff --git a/base/sources/ts/iron/render_path.ts b/base/sources/ts/iron/render_path.ts index 063f4474..1ea2acc9 100644 --- a/base/sources/ts/iron/render_path.ts +++ b/base/sources/ts/iron/render_path.ts @@ -116,7 +116,7 @@ function render_path_begin(render_target: image_t = null, additional_targets: im render_path_end(); } _render_path_current_image = render_target; - g4_begin(render_target, additional_targets); + iron_g4_begin(render_target, additional_targets); } function render_path_end() { @@ -144,7 +144,7 @@ function render_path_set_viewport(view_w: i32, view_h: i32) { } function render_path_clear_target(color: color_t = 0x00000000, depth: f32 = 0.0, flags: i32 = clear_flag_t.COLOR) { - g4_clear(color, depth, flags); + kinc_g5_clear(color, depth, flags); } function render_path_gen_mipmaps(target: string) { diff --git a/base/sources/ts/iron/ui.ts b/base/sources/ts/iron/ui.ts index 29bc4406..4ff02fbd 100644 --- a/base/sources/ts/iron/ui.ts +++ b/base/sources/ts/iron/ui.ts @@ -123,25 +123,15 @@ function ui_nodes_PAN_Y(): f32 { } function _ui_image(image: image_t, tint: i32 = 0xffffffff, h: f32 = -1.0, sx: i32 = 0, sy: i32 = 0, sw: i32 = 0, sh: i32 = 0): ui_state_t { - if (image.texture_ != null) { - return ui_sub_image(image.texture_, false, tint, h, sx, sy, sw, sh); - } - else { - return ui_sub_image(image.render_target_, true, tint, h, sx, sy, sw, sh); - } + return ui_sub_image(image.texture_, tint, h, sx, sy, sw, sh); } function _ui_tooltip_image(image: image_t, max_width: i32 = 0) { - if (image.texture_ != null) { - return ui_tooltip_image(image.texture_, max_width); - } - else { - return ui_tooltip_render_target(image.render_target_, max_width); - } + return ui_tooltip_image(image.texture_, max_width); } function ui_window(handle: ui_handle_t, x: i32, y: i32, w: i32, h: i32, drag: bool = false): bool { - _g2_current = { render_target_: ADDRESS(handle.texture) }; + _g2_current = { texture_: ADDRESS(handle.texture) }; _g2_in_use = true; return _ui_window(handle, x, y, w, h, drag); } @@ -281,7 +271,6 @@ declare function ui_radio(handle: ui_handle_t, position: i32, text: string, labe declare function ui_start_text_edit(handle: ui_handle_t, align: ui_align_t = ui_align_t.LEFT): void; declare function ui_tooltip(s: string): void; declare function ui_tooltip_image(tex: any, max_width: i32 = 0): void; -declare function ui_tooltip_render_target(rt: any, max_width: i32 = 0): void; declare function ui_separator(h: i32 = 4, fill: bool = true): void; declare function ui_text_area(handle: ui_handle_t, align: ui_align_t = ui_align_t.LEFT, editable: bool = true, label: string = "", word_wrap: bool = false): string; declare function _ui_window(handle: ui_handle_t, x: i32, y: i32, w: i32, h: i32, drag: bool = false): bool; diff --git a/base/sources/ts/layers.ts b/base/sources/ts/layers.ts index f78d68aa..12c764c2 100644 --- a/base/sources/ts/layers.ts +++ b/base/sources/ts/layers.ts @@ -32,19 +32,19 @@ function layers_init() { g2_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(); - g4_begin(texpaint_nor._image); - g4_clear(color_from_floats(0.5, 0.5, 1.0, 0.0)); // Nor + iron_g4_begin(texpaint_nor._image); + kinc_g5_clear(color_from_floats(0.5, 0.5, 1.0, 0.0)); // Nor iron_g4_end(); - g4_begin(texpaint_pack._image); - g4_clear(color_from_floats(1.0, 0.4, 0.0, 0.0)); // Occ, rough, met + iron_g4_begin(texpaint_pack._image); + kinc_g5_clear(color_from_floats(1.0, 0.4, 0.0, 0.0)); // Occ, rough, met iron_g4_end(); let texpaint_nor_empty: render_target_t = map_get(render_path_render_targets, "texpaint_nor_empty"); let texpaint_pack_empty: render_target_t = map_get(render_path_render_targets, "texpaint_pack_empty"); - g4_begin(texpaint_nor_empty._image); - g4_clear(color_from_floats(0.5, 0.5, 1.0, 0.0)); // Nor + iron_g4_begin(texpaint_nor_empty._image); + kinc_g5_clear(color_from_floats(0.5, 0.5, 1.0, 0.0)); // Nor iron_g4_end(); - g4_begin(texpaint_pack_empty._image); - g4_clear(color_from_floats(1.0, 0.4, 0.0, 0.0)); // Occ, rough, met + iron_g4_begin(texpaint_pack_empty._image); + kinc_g5_clear(color_from_floats(1.0, 0.4, 0.0, 0.0)); // Occ, rough, met iron_g4_end(); ///end } @@ -255,7 +255,7 @@ function layers_apply_mask(l: slot_layer_t, m: slot_layer_t) { g2_end(); // Apply mask - g4_begin(l.texpaint); + iron_g4_begin(l.texpaint); kinc_g5_set_pipeline(pipes_apply_mask); g4_set_tex(pipes_tex0_mask, layers_temp_image); g4_set_tex(pipes_texa_mask, m.texpaint); @@ -266,7 +266,7 @@ function layers_apply_mask(l: slot_layer_t, m: slot_layer_t) { } function layers_commands_merge_pack(pipe: kinc_g5_pipeline_t, i0: image_t, i1: image_t, i1pack: image_t, i1mask_opacity: f32, i1texmask: image_t, i1blending: i32 = -1) { - g4_begin(i0); + iron_g4_begin(i0); kinc_g5_set_pipeline(pipe); g4_set_tex(pipes_tex0, i1); g4_set_tex(pipes_tex1, i1pack); @@ -729,7 +729,7 @@ function layers_merge_layer(l0 : slot_layer_t, l1: slot_layer_t, use_mask: bool } if (slot_layer_is_mask(l1)) { - g4_begin(l0.texpaint); + iron_g4_begin(l0.texpaint); kinc_g5_set_pipeline(pipes_merge_mask); g4_set_tex(pipes_tex0_merge_mask, l1.texpaint); g4_set_tex(pipes_texa_merge_mask, layers_temp_image); @@ -743,7 +743,7 @@ function layers_merge_layer(l0 : slot_layer_t, l1: slot_layer_t, use_mask: bool if (slot_layer_is_layer(l1)) { if (l1.paint_base) { - g4_begin(l0.texpaint); + iron_g4_begin(l0.texpaint); kinc_g5_set_pipeline(pipes_merge); g4_set_tex(pipes_tex0, l1.texpaint); g4_set_tex(pipes_tex1, empty); @@ -765,7 +765,7 @@ function layers_merge_layer(l0 : slot_layer_t, l1: slot_layer_t, use_mask: bool g2_end(); if (l1.paint_nor) { - g4_begin(l0.texpaint_nor); + iron_g4_begin(l0.texpaint_nor); kinc_g5_set_pipeline(pipes_merge); g4_set_tex(pipes_tex0, l1.texpaint); g4_set_tex(pipes_tex1, l1.texpaint_nor); diff --git a/base/sources/ts/render_path_raytrace.ts b/base/sources/ts/render_path_raytrace.ts index 80b78206..b832c059 100644 --- a/base/sources/ts/render_path_raytrace.ts +++ b/base/sources/ts/render_path_raytrace.ts @@ -118,7 +118,7 @@ function render_path_raytrace_commands(use_live_layer: bool) { ///end let framebuffer: render_target_t = map_get(render_path_render_targets, "buf"); - iron_raytrace_dispatch_rays(framebuffer._image.render_target_, render_path_raytrace_f32a); + iron_raytrace_dispatch_rays(framebuffer._image.texture_, render_path_raytrace_f32a); if (context_raw.ddirty == 1 || context_raw.pdirty == 1) { ///if arm_metal diff --git a/base/sources/ts/render_path_raytrace_bake.ts b/base/sources/ts/render_path_raytrace_bake.ts index 5e889a93..2705219a 100644 --- a/base/sources/ts/render_path_raytrace_bake.ts +++ b/base/sources/ts/render_path_raytrace_bake.ts @@ -107,7 +107,7 @@ function render_path_raytrace_bake_commands(parse_paint_material: (b?: bool)=>vo f32a[6] = context_raw.envmap_angle; let framebuffer: render_target_t = map_get(render_path_render_targets, "baketex2"); - iron_raytrace_dispatch_rays(framebuffer._image.render_target_, f32a); + iron_raytrace_dispatch_rays(framebuffer._image.texture_, f32a); let id: i32 = context_raw.layer.id; let texpaint_id: string = "texpaint" + id; diff --git a/base/sources/ts/slot_layer.ts b/base/sources/ts/slot_layer.ts index 5cca73ff..1f574d82 100644 --- a/base/sources/ts/slot_layer.ts +++ b/base/sources/ts/slot_layer.ts @@ -244,8 +244,8 @@ function slot_layer_swap(raw: slot_layer_t, other: slot_layer_t) { } function slot_layer_clear(raw: slot_layer_t, base_color: i32 = 0x00000000, base_image: image_t = null, occlusion: f32 = 1.0, roughness: f32 = layers_default_rough, metallic: f32 = 0.0) { - g4_begin(raw.texpaint); - g4_clear(base_color); // Base + iron_g4_begin(raw.texpaint); + kinc_g5_clear(base_color); // Base iron_g4_end(); if (base_image != null) { g2_begin(raw.texpaint); @@ -254,11 +254,11 @@ function slot_layer_clear(raw: slot_layer_t, base_color: i32 = 0x00000000, base_ } if (slot_layer_is_layer(raw)) { - g4_begin(raw.texpaint_nor); - g4_clear(color_from_floats(0.5, 0.5, 1.0, 0.0)); // Nor + iron_g4_begin(raw.texpaint_nor); + kinc_g5_clear(color_from_floats(0.5, 0.5, 1.0, 0.0)); // Nor iron_g4_end(); - g4_begin(raw.texpaint_pack); - g4_clear(color_from_floats(occlusion, roughness, metallic, 0.0)); // Occ, rough, met + iron_g4_begin(raw.texpaint_pack); + kinc_g5_clear(color_from_floats(occlusion, roughness, metallic, 0.0)); // Occ, rough, met iron_g4_end(); } @@ -338,7 +338,7 @@ function slot_layer_duplicate(raw: slot_layer_t): slot_layer_t { if (l.texpaint_preview != null) { g2_begin(l.texpaint_preview); - g4_clear(0x00000000); + kinc_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); diff --git a/base/sources/ts/ui_base.ts b/base/sources/ts/ui_base.ts index 00608cb3..4002781d 100644 --- a/base/sources/ts/ui_base.ts +++ b/base/sources/ts/ui_base.ts @@ -1089,7 +1089,7 @@ function ui_base_update_ui() { let source: image_t = l.texpaint; g2_begin(target); - g4_clear(0x00000000); + kinc_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); @@ -1109,7 +1109,7 @@ function ui_base_update_ui() { let source: image_t = l.texpaint; g2_begin(target); - g4_clear(0x00000000); + kinc_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); diff --git a/base/sources/ts/ui_files.ts b/base/sources/ts/ui_files.ts index d1853989..8f71a3b1 100644 --- a/base/sources/ts/ui_files.ts +++ b/base/sources/ts/ui_files.ts @@ -215,7 +215,7 @@ function ui_files_file_browser(ui: ui_t, handle: ui_handle_t, drag_files: bool = } else { g2_begin(icon); - g4_clear(0xffffffff); + kinc_g5_clear(0xffffffff); } draw_set_pipeline(pipes_copy_rgb); draw_image(data.image, 0, 0); @@ -433,7 +433,7 @@ function ui_files_make_icon (args: ui_files_make_icon_t) { let sh: i32 = image.width > image.height ? math_floor(1.0 * image.height / image.width * w) : w; let icon: image_t = image_create_render_target(sw, sh); g2_begin(icon); - g4_clear(0xffffffff); + kinc_g5_clear(0xffffffff); draw_set_pipeline(pipes_copy_rgb); draw_scaled_image(image, 0, 0, sw, sh); draw_set_pipeline(null); diff --git a/base/sources/ts/ui_nodes.ts b/base/sources/ts/ui_nodes.ts index 761decf4..1708f55c 100644 --- a/base/sources/ts/ui_nodes.ts +++ b/base/sources/ts/ui_nodes.ts @@ -738,7 +738,7 @@ function ui_nodes_draw_grid(zoom: f32): image_t { let grid: image_t = image_create_render_target(w, h); g2_begin(grid); - g4_clear(ui_nodes_ui.ops.theme.SEPARATOR_COL); + kinc_g5_clear(ui_nodes_ui.ops.theme.SEPARATOR_COL); let sep_col: i32 = ui_nodes_ui.ops.theme.SEPARATOR_COL; let line_primary: i32 = sep_col - 0x00050505; diff --git a/base/sources/ts/util_render.ts b/base/sources/ts/util_render.ts index e61b3faa..b5ca9e4e 100644 --- a/base/sources/ts/util_render.ts +++ b/base/sources/ts/util_render.ts @@ -168,7 +168,7 @@ function util_render_make_text_preview() { ///end } g2_begin(context_raw.text_tool_image); - g4_clear(0xff000000); + kinc_g5_clear(0xff000000); g2_set_font(font, font_size); draw_set_color(0xffffffff); draw_string(text, tex_w / 2 - text_w / 2, tex_w / 2 - text_h / 2); @@ -192,7 +192,7 @@ function util_render_make_font_preview() { context_raw.font.image = image_create_render_target(tex_w, tex_w, tex_format_t.RGBA32); } g2_begin(context_raw.font.image); - g4_clear(0x00000000); + kinc_g5_clear(0x00000000); g2_set_font(font, font_size); draw_set_color(0xffffffff); draw_string(text, tex_w / 2 - text_w / 2, tex_w / 2 - text_h / 2); @@ -367,7 +367,7 @@ function util_render_make_brush_preview() { l = render_path_paint_live_layer; let target: image_t = context_raw.brush.image; g2_begin(target); - g4_clear(0x00000000); + kinc_g5_clear(0x00000000); draw_set_pipeline(pipes_copy); draw_scaled_image(l.texpaint, 0, 0, target.width, target.height); draw_set_pipeline(null); @@ -402,7 +402,7 @@ function util_render_make_node_preview(canvas: ui_node_canvas_t, node: ui_node_t context_raw.paint_object.base.transform.scale_world = 3.0; transform_build_matrix(context_raw.paint_object.base.transform); - g4_begin(image); + iron_g4_begin(image); kinc_g5_set_pipeline(res.scon._.pipe_state); let empty: string[] = [""]; uniforms_set_context_consts(res.scon, empty); diff --git a/base/sources/ts/util_uv.ts b/base/sources/ts/util_uv.ts index ceaeff6a..c915ea90 100644 --- a/base/sources/ts/util_uv.ts +++ b/base/sources/ts/util_uv.ts @@ -35,7 +35,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); - g4_clear(0x00000000); + kinc_g5_clear(0x00000000); draw_set_color(0xffffffff); let strength: f32 = res_x > 2048 ? 2.0 : 1.0; let f: f32 = (1 / 32767) * util_uv_uvmap.width; @@ -74,7 +74,7 @@ function util_uv_cache_triangle_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_trianglemap); - g4_clear(0xff000000); + kinc_g5_clear(0xff000000); let f: f32 = (1 / 32767) * util_uv_trianglemap.width; let color: i32 = 0xff000001; for (let i: i32 = 0; i < math_floor(inda.length / 3); ++i) { @@ -130,8 +130,8 @@ function util_uv_cache_dilate_map() { mask = context_raw.layer_filter; } let geom: mesh_data_t = mask == 0 && context_raw.merged_object != null ? context_raw.merged_object.data : context_raw.paint_object.data; - g4_begin(util_uv_dilatemap); - g4_clear(0x00000000); + iron_g4_begin(util_uv_dilatemap); + kinc_g5_clear(0x00000000); kinc_g5_set_pipeline(util_uv_pipe_dilate); ///if (arm_metal || arm_vulkan) let vs: vertex_element_t[] = [ diff --git a/base/tests/triangle/main.ts b/base/tests/triangle/main.ts index 40fc1c9b..537a18d6 100644 --- a/base/tests/triangle/main.ts +++ b/base/tests/triangle/main.ts @@ -12,7 +12,7 @@ function render() { let flags: i32 = 0; flags |= 1; // Color flags |= 2; // Depth - kinc_g5_clear(flags, 0xff000000, 1.0); + kinc_g5_clear(0xff000000, 1.0, flags); kinc_g5_set_pipeline(pipeline); kinc_g4_set_vertex_buffer(vb); diff --git a/base/tools/pad/sources/main.ts b/base/tools/pad/sources/main.ts index d8dddc90..040815e4 100644 --- a/base/tools/pad/sources/main.ts +++ b/base/tools/pad/sources/main.ts @@ -321,7 +321,7 @@ function draw_minimap() { } g2_begin(minimap); - g4_clear(theme.SEPARATOR_COL); + kinc_g5_clear(theme.SEPARATOR_COL); draw_set_color(0xff333333); let lines: string[] = string_split(storage.text, "\n"); let minimap_full_h: i32 = lines.length * 2;