luboslenco 2 hafta önce
ebeveyn
işleme
ce9eb4824a

+ 5 - 5
base/sources/backends/direct3d12_gpu.c

@@ -368,13 +368,13 @@ void gpu_init_internal(int depth_buffer_bits, bool vsync) {
 	device->lpVtbl->CreateCommandList(device, 0, D3D12_COMMAND_LIST_TYPE_DIRECT, command_allocator, NULL, &IID_ID3D12CommandList, &command_list);
 }
 
-void gpu_begin_internal(gpu_texture_t **targets, int count, gpu_texture_t *depth_buffer, unsigned flags, unsigned color, float depth) {
+void gpu_begin_internal(unsigned flags, unsigned color, float depth) {
 	for (int i = 0; i < current_render_targets_count; ++i) {
 		current_render_targets[i]->impl.rtv_descriptor_heap->lpVtbl->GetCPUDescriptorHandleForHeapStart(current_render_targets[i]->impl.rtv_descriptor_heap, &target_descriptors[i]);
 	}
 
-	if (depth_buffer != NULL) {
-		depth_buffer->impl.rtv_descriptor_heap->lpVtbl->GetCPUDescriptorHandleForHeapStart(depth_buffer->impl.rtv_descriptor_heap, &depth_handle);
+	if (current_depth_buffer != NULL) {
+		current_depth_buffer->impl.rtv_descriptor_heap->lpVtbl->GetCPUDescriptorHandleForHeapStart(current_depth_buffer->impl.rtv_descriptor_heap, &depth_handle);
 		current_depth_handle = &depth_handle;
 	}
 	else {
@@ -397,9 +397,9 @@ void gpu_begin_internal(gpu_texture_t **targets, int count, gpu_texture_t *depth
 		target->impl.rtv_descriptor_heap->lpVtbl->GetCPUDescriptorHandleForHeapStart(target->impl.rtv_descriptor_heap, &handle);
 		command_list->lpVtbl->ClearRenderTargetView(command_list, handle, clear_color, 0, NULL);
 	}
-	if (flags & GPU_CLEAR_DEPTH && depth_buffer != NULL) {
+	if (flags & GPU_CLEAR_DEPTH && current_depth_buffer != NULL) {
 		D3D12_CPU_DESCRIPTOR_HANDLE handle;
-		depth_buffer->impl.rtv_descriptor_heap->lpVtbl->GetCPUDescriptorHandleForHeapStart(depth_buffer->impl.rtv_descriptor_heap, &handle);
+		current_depth_buffer->impl.rtv_descriptor_heap->lpVtbl->GetCPUDescriptorHandleForHeapStart(current_depth_buffer->impl.rtv_descriptor_heap, &handle);
 		command_list->lpVtbl->ClearDepthStencilView(command_list, handle, D3D12_CLEAR_FLAG_DEPTH, depth, 0, 0, NULL);
 	}
 }

+ 3 - 3
base/sources/backends/metal_gpu.m

@@ -179,7 +179,7 @@ void gpu_init_internal(int depth_buffer_bits, bool vsync) {
 	next_drawable();
 }
 
-void gpu_begin_internal(gpu_texture_t **targets, int count, gpu_texture_t *depth_buffer, unsigned flags, unsigned color, float depth) {
+void gpu_begin_internal(unsigned flags, unsigned color, float depth) {
 	render_pass_desc = [MTLRenderPassDescriptor renderPassDescriptor];
 	for (int i = 0; i < current_render_targets_count; ++i) {
 		render_pass_desc.colorAttachments[i].texture = (__bridge id<MTLTexture>)current_render_targets[i]->impl._tex;
@@ -197,8 +197,8 @@ void gpu_begin_internal(gpu_texture_t **targets, int count, gpu_texture_t *depth
 		}
 	}
 
-	if (depth_buffer != NULL) {
-		render_pass_desc.depthAttachment.texture = (__bridge id<MTLTexture>)depth_buffer->impl._tex;
+	if (current_depth_buffer != NULL) {
+		render_pass_desc.depthAttachment.texture = (__bridge id<MTLTexture>)current_depth_buffer->impl._tex;
 	}
 
 	if (flags & GPU_CLEAR_DEPTH) {

+ 6 - 6
base/sources/backends/vulkan_gpu.c

@@ -1023,7 +1023,7 @@ bool iron_vulkan_get_size(int *width, int *height) {
 	return false;
 }
 
-void gpu_begin_internal(gpu_texture_t **targets, int count, gpu_texture_t * depth_buffer, unsigned flags, unsigned color, float depth) {
+void gpu_begin_internal(unsigned flags, unsigned color, float depth) {
 	if (!framebuffer_acquired) {
 		acquire_next_image();
 		framebuffer_acquired = true;
@@ -1057,10 +1057,10 @@ void gpu_begin_internal(gpu_texture_t **targets, int count, gpu_texture_t * dept
 		};
 	}
 
-	if (depth_buffer != NULL) {
+	if (current_depth_buffer != NULL) {
 		current_depth_attachment_info = (VkRenderingAttachmentInfo) {
 			.sType              = VK_STRUCTURE_TYPE_RENDERING_ATTACHMENT_INFO,
-			.imageView          = depth_buffer->impl.view,
+			.imageView          = current_depth_buffer->impl.view,
 			.imageLayout        = VK_IMAGE_LAYOUT_DEPTH_ATTACHMENT_OPTIMAL,
 			.resolveMode        = VK_RESOLVE_MODE_NONE,
 			.resolveImageLayout = VK_IMAGE_LAYOUT_SHADER_READ_ONLY_OPTIMAL,
@@ -1077,7 +1077,7 @@ void gpu_begin_internal(gpu_texture_t **targets, int count, gpu_texture_t * dept
 		.viewMask             = 0,
 		.colorAttachmentCount = (uint32_t)current_render_targets_count,
 		.pColorAttachments    = current_color_attachment_infos,
-		.pDepthAttachment     = depth_buffer == NULL ? VK_NULL_HANDLE : &current_depth_attachment_info,
+		.pDepthAttachment     = current_depth_buffer == NULL ? VK_NULL_HANDLE : &current_depth_attachment_info,
 	};
 	vkCmdBeginRendering(command_buffer, &current_rendering_info);
 
@@ -1107,8 +1107,8 @@ void gpu_begin_internal(gpu_texture_t **targets, int count, gpu_texture_t * dept
 		VkClearRect clear_rect = {
 			.rect.offset.x = 0,
 			.rect.offset.y = 0,
-			.rect.extent.width = targets[0]->width,
-			.rect.extent.height = targets[0]->height,
+			.rect.extent.width = current_render_targets[0]->width,
+			.rect.extent.height = current_render_targets[0]->height,
 			.baseArrayLayer = 0,
 			.layerCount = 1,
 		};

+ 1 - 1
base/sources/backends/webgpu_gpu.c

@@ -50,7 +50,7 @@ void gpu_init_internal(int depth_bits, bool vsync) {
 	swapChain = wgpuDeviceCreateSwapChain(device, surface, &scDesc);
 }
 
-void gpu_begin_internal(struct gpu_texture **targets, int count, gpu_texture_t *depth_buffer, unsigned flags, unsigned color, float depth) {
+void gpu_begin_internal(unsigned flags, unsigned color, float depth) {
 	WGPUCommandEncoderDescriptor ceDesc;
 	memset(&ceDesc, 0, sizeof(ceDesc));
 	encoder = wgpuDeviceCreateCommandEncoder(device, &ceDesc);

+ 14 - 14
base/sources/iron.h

@@ -428,7 +428,7 @@ void _update(void *data) {
 	#endif
 
 	iron_update();
-	ui_end_frame();
+	if (ui_get_current()) ui_end_frame();
 	gpu_present();
 }
 
@@ -471,7 +471,7 @@ void _shutdown(void *data) {
 
 void _key_down(int code, void *data) {
 	iron_key_down(code);
-	ui_key_down(ui_get_current(), code);
+	if (ui_get_current()) ui_key_down(ui_get_current(), code);
 
 	#ifdef IDLE_SLEEP
 	input_down = true;
@@ -481,7 +481,7 @@ void _key_down(int code, void *data) {
 
 void _key_up(int code, void *data) {
 	iron_key_up(code);
-	ui_key_up(ui_get_current(), code);
+	if (ui_get_current()) ui_key_up(ui_get_current(), code);
 
 	#ifdef IDLE_SLEEP
 	input_down = false;
@@ -491,7 +491,7 @@ void _key_up(int code, void *data) {
 
 void _key_press(unsigned int character, void *data) {
 	iron_key_press(character);
-	ui_key_press(ui_get_current(), character);
+	if (ui_get_current()) ui_key_press(ui_get_current(), character);
 
 	#ifdef IDLE_SLEEP
 	paused_frames = 0;
@@ -500,7 +500,7 @@ void _key_press(unsigned int character, void *data) {
 
 void _mouse_down(int button, int x, int y, void *data) {
 	iron_mouse_down(button, x, y);
-	ui_mouse_down(ui_get_current(), button, x, y);
+	if (ui_get_current()) ui_mouse_down(ui_get_current(), button, x, y);
 
 	#ifdef IDLE_SLEEP
 	input_down = true;
@@ -510,7 +510,7 @@ void _mouse_down(int button, int x, int y, void *data) {
 
 void _mouse_up(int button, int x, int y, void *data) {
 	iron_mouse_up(button, x, y);
-	ui_mouse_up(ui_get_current(), button, x, y);
+	if (ui_get_current()) ui_mouse_up(ui_get_current(), button, x, y);
 
 	#ifdef IDLE_SLEEP
 	input_down = false;
@@ -520,7 +520,7 @@ void _mouse_up(int button, int x, int y, void *data) {
 
 void _mouse_move(int x, int y, int mx, int my, void *data) {
 	iron_mouse_move(x, y, mx, my);
-	ui_mouse_move(ui_get_current(), x, y, mx, my);
+	if (ui_get_current()) ui_mouse_move(ui_get_current(), x, y, mx, my);
 
 	#ifdef IDLE_SLEEP
 	paused_frames = 0;
@@ -529,7 +529,7 @@ void _mouse_move(int x, int y, int mx, int my, void *data) {
 
 void _mouse_wheel(int delta, void *data) {
 	iron_mouse_wheel(delta);
-	ui_mouse_wheel(ui_get_current(), delta);
+	if (ui_get_current()) ui_mouse_wheel(ui_get_current(), delta);
 
 	#ifdef IDLE_SLEEP
 	paused_frames = 0;
@@ -540,7 +540,7 @@ void _touch_move(int index, int x, int y) {
 	iron_touch_move(index, x, y);
 
 	#if defined(IRON_ANDROID) || defined(IRON_IOS)
-	ui_touch_move(ui_get_current(), index, x, y);
+	if (ui_get_current()) ui_touch_move(ui_get_current(), index, x, y);
 	#endif
 
 	#ifdef IDLE_SLEEP
@@ -552,7 +552,7 @@ void _touch_down(int index, int x, int y) {
 	iron_touch_down(index, x, y);
 
 	#if defined(IRON_ANDROID) || defined(IRON_IOS)
-	ui_touch_down(ui_get_current(), index, x, y);
+	if (ui_get_current()) ui_touch_down(ui_get_current(), index, x, y);
 	#endif
 
 	#ifdef IDLE_SLEEP
@@ -565,7 +565,7 @@ void _touch_up(int index, int x, int y) {
 	iron_touch_up(index, x, y);
 
 	#if defined(IRON_ANDROID) || defined(IRON_IOS)
-	ui_touch_up(ui_get_current(), index, x, y);
+	if (ui_get_current()) ui_touch_up(ui_get_current(), index, x, y);
 	#endif
 
 	#ifdef IDLE_SLEEP
@@ -576,7 +576,7 @@ void _touch_up(int index, int x, int y) {
 
 void _pen_down(int x, int y, float pressure) {
 	iron_pen_down(x, y, pressure);
-	ui_pen_down(ui_get_current(), x, y, pressure);
+	if (ui_get_current()) ui_pen_down(ui_get_current(), x, y, pressure);
 
 	#ifdef IDLE_SLEEP
 	input_down = true;
@@ -586,7 +586,7 @@ void _pen_down(int x, int y, float pressure) {
 
 void _pen_up(int x, int y, float pressure) {
 	iron_pen_up(x, y, pressure);
-	ui_pen_up(ui_get_current(), x, y, pressure);
+	if (ui_get_current()) ui_pen_up(ui_get_current(), x, y, pressure);
 
 	#ifdef IDLE_SLEEP
 	input_down = false;
@@ -596,7 +596,7 @@ void _pen_up(int x, int y, float pressure) {
 
 void _pen_move(int x, int y, float pressure) {
 	iron_pen_move(x, y, pressure);
-	ui_pen_move(ui_get_current(), x, y, pressure);
+	if (ui_get_current()) ui_pen_move(ui_get_current(), x, y, pressure);
 
 	#ifdef IDLE_SLEEP
 	paused_frames = 0;

+ 1 - 1
base/sources/iron_gpu.c

@@ -62,7 +62,7 @@ void gpu_begin(gpu_texture_t **targets, int count, gpu_texture_t *depth_buffer,
 		gpu_barrier(current_depth_buffer, GPU_TEXTURE_STATE_RENDER_TARGET_DEPTH);
 	}
 
-	gpu_begin_internal(targets, count, depth_buffer, flags, color, depth);
+	gpu_begin_internal(flags, color, depth);
 }
 
 void gpu_draw() {

+ 2 - 1
base/sources/iron_gpu.h

@@ -145,7 +145,7 @@ typedef struct gpu_raytrace_acceleration_structure {
 
 int gpu_max_bound_textures(void);
 void gpu_begin(gpu_texture_t **targets, int count, gpu_texture_t *depth_buffer, unsigned flags, unsigned color, float depth);
-void gpu_begin_internal(gpu_texture_t **targets, int count, gpu_texture_t *depth_buffer, unsigned flags, unsigned color, float depth);
+void gpu_begin_internal(unsigned flags, unsigned color, float depth);
 void gpu_end(void);
 void gpu_end_internal(void);
 void gpu_execute_and_wait(void);
@@ -232,6 +232,7 @@ extern bool gpu_transpose_mat;
 extern bool gpu_in_use;
 extern gpu_texture_t *current_render_targets[8];
 extern int current_render_targets_count;
+extern gpu_texture_t *current_depth_buffer;
 extern int constant_buffer_index;
 extern gpu_texture_t framebuffers[GPU_FRAMEBUFFER_COUNT];
 extern gpu_texture_t framebuffer_depth;

+ 2 - 2
base/sources/ts/iron/iron.ts

@@ -959,7 +959,7 @@ declare function UI_ELEMENT_W(): f32;
 declare function UI_ELEMENT_H(): f32;
 declare function UI_OUTPUTS_H(sockets_count: i32, length: i32 = -1): f32;
 
-function ui_MENUBAR_H(): f32 {
+function ui_MENUBAR_H(ui: ui_t): f32 {
 	let button_offset_y: f32 = (ui.ops.theme.ELEMENT_H * UI_SCALE() - ui.ops.theme.BUTTON_H * UI_SCALE()) / 2;
 	return ui.ops.theme.BUTTON_H * UI_SCALE() * 1.1 + 2 + button_offset_y;
 }
@@ -1031,7 +1031,7 @@ function ui_get_socket(nodes: ui_node_t[], id: i32): ui_node_socket_t {
 	return null;
 }
 
-function ui_set_font(font: draw_font_t) {
+function ui_set_font(ui: ui_t, font: draw_font_t) {
 	draw_font_init(font); // Make sure font is ready
 	ui.ops.font = font;
 }

+ 2 - 2
base/sources/ts/tab_console.ts

@@ -56,13 +56,13 @@ function tab_console_draw(htab: ui_handle_t) {
 		let _font: draw_font_t = ui.ops.font;
 		let _font_size: i32 = ui.font_size;
 		let f: draw_font_t = data_get_font("font_mono.ttf");
-		ui_set_font(f);
+		ui_set_font(ui, f);
 		ui.font_size = math_floor(15 * UI_SCALE());
 		for (let i: i32 = 0; i < console_last_traces.length; ++i) {
 			let t: string = console_last_traces[i];
 			ui_text(t);
 		}
-		ui_set_font(_font);
+		ui_set_font(ui, _font);
 		ui.font_size = _font_size;
 	}
 }

+ 2 - 2
base/sources/ts/tab_meshes.ts

@@ -330,12 +330,12 @@ function tab_meshes_draw(htab: ui_handle_t) {
 					let _font: draw_font_t = ui.ops.font;
 					let _font_size: i32 = ui.font_size;
 					let fmono: draw_font_t = data_get_font("font_mono.ttf");
-					ui_set_font(fmono);
+					ui_set_font(ui, fmono);
 					ui.font_size = math_floor(15 * UI_SCALE());
 					ui_text_area_coloring = tab_scripts_get_text_coloring();
 					ui_text_area(hscript);
 					ui_text_area_coloring = null;
-					ui_set_font(_font);
+					ui_set_font(ui, _font);
 					ui.font_size = _font_size;
 
 					script = hscript.text;

+ 2 - 2
base/sources/ts/tab_scripts.ts

@@ -53,7 +53,7 @@ function tab_scripts_draw(htab: ui_handle_t) {
 		let _font: draw_font_t = ui.ops.font;
 		let _font_size: i32 = ui.font_size;
 		let f: draw_font_t = data_get_font("font_mono.ttf");
-		ui_set_font(f);
+		ui_set_font(ui, f);
 		ui.font_size = math_floor(15 * UI_SCALE());
 		ui_text_area_line_numbers = true;
 		ui_text_area_scroll_past_end = true;
@@ -62,7 +62,7 @@ function tab_scripts_draw(htab: ui_handle_t) {
 		ui_text_area_line_numbers = false;
 		ui_text_area_scroll_past_end = false;
 		ui_text_area_coloring = null;
-		ui_set_font(_font);
+		ui_set_font(ui, _font);
 		ui.font_size = _font_size;
 	}
 }

+ 1 - 1
base/sources/ts/translator.ts

@@ -167,7 +167,7 @@ function translator_init_font(cjk: bool, font_path: string, font_scale: f32) {
 		base_theme.FONT_SIZE = math_floor(base_default_font_size * font_scale);
 		base_theme.ELEMENT_W = math_floor(base_default_element_w * (config_raw.locale != "en" ? 1.4 : 1.0));
 
-		ui_set_font(f);
+		ui_set_font(ui, f);
 		ui_set_scale(UI_SCALE());
 	});
 }

+ 1 - 1
base/sources/ts/ui_menubar.ts

@@ -728,7 +728,7 @@ function ui_menubar_show_menu(category: i32) {
 	let panel_x: i32 = ui_menu_panel_x();
 	let panel_y: i32 = ui_menu_panel_y();
 	ui_menu_x = math_floor(ui._x - ui._w) + panel_x;
-	ui_menu_y = math_floor(ui_MENUBAR_H()) + panel_y;
+	ui_menu_y = math_floor(ui_MENUBAR_H(ui)) + panel_y;
 	if (config_raw.touch_ui) {
 		let menu_w: i32 = math_floor(base_default_element_w * UI_SCALE() * 2.0);
 		ui_menu_x -= math_floor((menu_w - ui._w) / 2) + math_floor(ui_header_h / 2);