Window resize fixes

This commit is contained in:
luboslenco
2025-07-02 22:00:52 +02:00
parent 306bb80850
commit 5f0dfe9675
10 changed files with 46 additions and 17 deletions
+1 -3
View File
@@ -1070,8 +1070,6 @@ double iron_time() {
return (double)(now.tv_sec - start_sec) + (now.tv_usec / 1000000.0);
}
void gpu_internal_resize(int width, int height);
bool iron_internal_handle_messages(void) {
iron_mutex_lock(&unicode_mutex);
for (int i = 0; i < unicode_stack_index; ++i) {
@@ -1114,7 +1112,7 @@ bool iron_internal_handle_messages(void) {
activityJustResized = false;
int32_t width = iron_android_width();
int32_t height = iron_android_height();
gpu_internal_resize(width, height);
gpu_resize(width, height);
iron_internal_call_resize_callback(width, height);
}
+1 -1
View File
@@ -469,7 +469,7 @@ void gpu_present() {
command_list->lpVtbl->Reset(command_list, command_allocator, NULL);
}
void gpu_internal_resize(int width, int height) {
void gpu_resize_internal(int width, int height) {
if (fence_value == 0 || width == 0 || height == 0) {
return;
}
+1 -3
View File
@@ -112,9 +112,7 @@ void iron_internal_call_resize_callback(int width, int height);
backingWidth = self.frame.size.width * self.contentScaleFactor;
backingHeight = self.frame.size.height * self.contentScaleFactor;
CAMetalLayer *metalLayer = (CAMetalLayer *)self.layer;
metalLayer.drawableSize = CGSizeMake(backingWidth, backingHeight);
gpu_resize();
iron_internal_call_resize_callback(backingWidth, backingHeight);
}
+1 -2
View File
@@ -473,7 +473,6 @@ static char *clipboardString = NULL;
char buffer[1024];
void gpu_internal_resize(int width, int height);
static void init_pen_device(XDeviceInfo *info, struct x11_pen_device *pen, bool eraser);
static void load_lib(void **lib, const char *name) {
@@ -1198,7 +1197,7 @@ static bool _handle_messages() {
if (event.xconfigure.width != k_window->width || event.xconfigure.height != k_window->height) {
k_window->width = event.xconfigure.width;
k_window->height = event.xconfigure.height;
gpu_internal_resize(event.xconfigure.width, event.xconfigure.height);
gpu_resize(event.xconfigure.width, event.xconfigure.height);
iron_internal_call_resize_callback(event.xconfigure.width, event.xconfigure.height);
}
break;
+13 -3
View File
@@ -1308,13 +1308,23 @@ int main(int argc, char **argv) {
iron_stop();
}
void iron_internal_call_resize_callback(int width, int height) {
if (windows[0].resizeCallback != NULL) {
windows[0].resizeCallback(width, height, windows[0].resizeCallbackData);
}
}
- (void)windowDidResize:(NSNotification *)notification {
NSWindow *window = [notification object];
NSSize size = [[window contentView] frame].size;
[view resize:size];
if (windows[0].resizeCallback != NULL) {
windows[0].resizeCallback(size.width, size.height, windows[0].resizeCallbackData);
}
float scale = [window backingScaleFactor];
int w = size.width * scale;
int h = size.height * scale;
gpu_resize(w, h);
iron_internal_call_resize_callback(w, h);
}
- (void)windowWillMiniaturize:(NSNotification *)notification {
+21 -2
View File
@@ -24,6 +24,8 @@ static id<MTLSamplerState> linear_sampler;
static bool has_depth = false;
static int argument_buffer_step;
static gpu_buffer_t *current_index_buffer;
static int resize_w = 0;
static int resize_h = 0;
static MTLBlendFactor convert_blending_factor(gpu_blending_factor_t factor) {
switch (factor) {
@@ -143,7 +145,6 @@ static int format_byte_size(gpu_texture_format_t format) {
}
void gpu_render_target_init2(gpu_texture_t *target, int width, int height, gpu_texture_format_t format, int framebuffer_index) {
id<MTLDevice> device = getMetalDevice();
memset(target, 0, sizeof(gpu_texture_t));
target->width = width;
target->height = height;
@@ -171,7 +172,15 @@ void gpu_render_target_init2(gpu_texture_t *target, int width, int height, gpu_t
void gpu_destroy(void) {
}
void gpu_internal_resize(int width, int height) {
void gpu_resize_internal(int width, int height) {
if (width == 0 || height == 0) {
return;
}
if (width == framebuffers[0].width && height == framebuffers[0].height) {
return;
}
resize_w = width;
resize_h = height;
}
static void next_drawable() {
@@ -317,6 +326,16 @@ void gpu_present() {
command_buffer = nil;
command_encoder = nil;
if (resize_w > 0) {
CAMetalLayer *layer = getMetalLayer();
layer.drawableSize = CGSizeMake(resize_w, resize_h);
for (int i = 0; i < GPU_FRAMEBUFFER_COUNT; ++i) {
// gpu_texture_destroy(&framebuffers[i]);
gpu_render_target_init2(&framebuffers[i], resize_w, resize_h, GPU_TEXTURE_FORMAT_RGBA32, i);
}
resize_w = 0;
}
next_drawable();
}
+1 -1
View File
@@ -399,7 +399,7 @@ void create_descriptor_layout(void) {
vkCreateDescriptorPool(device, &pool_info, NULL, &descriptor_pool);
}
void gpu_internal_resize(int width, int height) {
void gpu_resize_internal(int width, int height) {
// vkDeviceWaitIdle(device);
// create_swapchain();
}
+1 -2
View File
@@ -408,7 +408,6 @@ void iron_mouse_get_position(int *x, int *y) {
__declspec(dllexport) unsigned long NvOptimusEnablement = 0x00000001;
__declspec(dllexport) int AmdPowerXpressRequestHighPerformance = 1;
void gpu_internal_resize(int width, int height);
typedef BOOL(WINAPI *GetPointerInfoType)(UINT32 pointerId, POINTER_INFO *pointerInfo);
static GetPointerInfoType MyGetPointerInfo = NULL;
@@ -653,7 +652,7 @@ LRESULT WINAPI IronWindowsMessageProcedure(HWND hWnd, UINT msg, WPARAM wParam, L
case WM_SIZE: {
int width = LOWORD(lParam);
int height = HIWORD(lParam);
gpu_internal_resize(width, height);
gpu_resize(width, height);
iron_internal_call_resize_callback(width, height);
break;
}
+4
View File
@@ -74,6 +74,10 @@ void gpu_end() {
gpu_end_internal();
}
void gpu_resize(int width, int height) {
gpu_resize_internal(width, height);
}
void gpu_set_int(int location, int value) {
int *ints = (int *)(&constant_buffer.data[location]);
ints[0] = value;
+2
View File
@@ -154,6 +154,8 @@ void gpu_init(int depth_buffer_bits, bool vsync);
void gpu_init_internal(int depth_buffer_bits, bool vsync);
void gpu_destroy(void);
void gpu_draw(void);
void gpu_resize(int width, int height);
void gpu_resize_internal(int width, int height);
void gpu_set_int(int location, int value);
void gpu_set_int2(int location, int value1, int value2);
void gpu_set_int3(int location, int value1, int value2, int value3);