Skip to content

Commit

Permalink
cache the window size in pixels
Browse files Browse the repository at this point in the history
  • Loading branch information
thatcosmonaut committed Sep 29, 2024
1 parent 66b92c0 commit efb2302
Show file tree
Hide file tree
Showing 3 changed files with 11 additions and 4 deletions.
4 changes: 4 additions & 0 deletions src/render/SDL_render.c
Original file line number Diff line number Diff line change
Expand Up @@ -2564,6 +2564,10 @@ static void UpdateLogicalPresentation(SDL_Renderer *renderer)

int iwidth, iheight;
SDL_GetRenderOutputSize(renderer, &iwidth, &iheight);

renderer->window_pixel_w = iwidth;
renderer->window_pixel_h = iheight;

const float output_w = (float)iwidth;
const float output_h = (float)iheight;
const float logical_w = renderer->logical_w;
Expand Down
3 changes: 3 additions & 0 deletions src/render/SDL_sysrender.h
Original file line number Diff line number Diff line change
Expand Up @@ -250,6 +250,9 @@ struct SDL_Renderer
SDL_RenderViewState *view;
SDL_RenderViewState main_view;

// Cache the window size in pixels
int window_pixel_w, window_pixel_h;

// The window pixel to point coordinate scale
SDL_FPoint dpi_scale;

Expand Down
8 changes: 4 additions & 4 deletions src/render/gpu/SDL_render_gpu.c
Original file line number Diff line number Diff line change
Expand Up @@ -976,16 +976,16 @@ static bool GPU_RenderPresent(SDL_Renderer *renderer)
blit_info.source.w = data->backbuffer.width;
blit_info.source.h = data->backbuffer.height;
blit_info.destination.texture = swapchain;
blit_info.destination.w = renderer->main_view.pixel_w;
blit_info.destination.h = renderer->main_view.pixel_h;
blit_info.destination.w = renderer->window_pixel_w;
blit_info.destination.h = renderer->window_pixel_h;
blit_info.load_op = SDL_GPU_LOADOP_DONT_CARE;
blit_info.filter = SDL_GPU_FILTER_LINEAR;

SDL_BlitGPUTexture(data->state.command_buffer, &blit_info);

if (renderer->main_view.pixel_w != data->backbuffer.width || renderer->main_view.pixel_h != data->backbuffer.height || swapchain_fmt != data->backbuffer.format) {
if (renderer->window_pixel_w != data->backbuffer.width || renderer->window_pixel_h != data->backbuffer.height || swapchain_fmt != data->backbuffer.format) {
SDL_ReleaseGPUTexture(data->device, data->backbuffer.texture);
CreateBackbuffer(data, renderer->main_view.pixel_w, renderer->main_view.pixel_h, swapchain_fmt);
CreateBackbuffer(data, renderer->window_pixel_w, renderer->window_pixel_h, swapchain_fmt);
}

// *** FIXME ***
Expand Down

0 comments on commit efb2302

Please sign in to comment.