Merge branch 'window-resolution-fixes' into 'master'

Fixes to HWR2 window, framebuffer resizing; scr_scale, scr_x, scr_y cvars for my personal use

See merge request KartKrew/Kart!1537
This commit is contained in:
James R 2023-10-03 23:43:20 +00:00
commit 99f816f34b
8 changed files with 65 additions and 21 deletions

View file

@ -421,6 +421,10 @@ consvar_t cv_scr_depth = Player("scr_depth", "16 bits").values({{8, "8 bits"}, {
consvar_t cv_scr_width = Player("scr_width", "640").values(CV_Unsigned);
consvar_t cv_scr_height = Player("scr_height", "400").values(CV_Unsigned);
consvar_t cv_scr_scale = Player("scr_scale", "1.0").floating_point();
consvar_t cv_scr_x = Player("scr_x", "0.0").floating_point();
consvar_t cv_scr_y = Player("scr_y", "0.0").floating_point();
consvar_t cv_seenames = Player("seenames", "On").on_off();
consvar_t cv_shadow = Player("shadow", "On").on_off();
consvar_t cv_shittyscreen = Player("televisionsignal", "Okay").flags(CV_NOSHOWHELP).values({{0, "Okay"}, {1, "Shitty"}, {2, "Extra Shitty"}}).dont_save();

View file

@ -432,7 +432,7 @@ void F_WipeEndScreen(void)
dst_region.h = std::min(dst_region.h, backbuf_deets.height);
rhi->copy_framebuffer_to_texture(ctx, hw_state->wipe_frames.end, dst_region, dst_region);
hw_state->blit_rect->set_output(dst_region.w, dst_region.h, false, true);
hw_state->blit_rect->set_output(0, 0, dst_region.w, dst_region.h, false, true);
rhi::TextureDetails start_deets = rhi->get_texture_details(hw_state->wipe_frames.start);
hw_state->blit_rect->set_texture(hw_state->wipe_frames.start, start_deets.width, start_deets.height);
hw_state->blit_rect->draw(*rhi, ctx);

View file

@ -100,7 +100,7 @@ void BlitRectPass::transfer(Rhi& rhi, Handle<GraphicsContext> ctx)
if (output_correct_aspect_)
{
aspect = static_cast<float>(texture_width_) / static_cast<float>(texture_height_);
output_aspect = static_cast<float>(output_width_) / static_cast<float>(output_height_);
output_aspect = static_cast<float>(output_position_.w) / static_cast<float>(output_position_.h);
}
bool taller = aspect > output_aspect;
@ -137,7 +137,7 @@ void BlitRectPass::transfer(Rhi& rhi, Handle<GraphicsContext> ctx)
void BlitRectPass::graphics(Rhi& rhi, Handle<GraphicsContext> ctx)
{
rhi.bind_pipeline(ctx, pipeline_);
rhi.set_viewport(ctx, {0, 0, output_width_, output_height_});
rhi.set_viewport(ctx, output_position_);
rhi.bind_uniform_set(ctx, 0, uniform_sets_[0]);
rhi.bind_uniform_set(ctx, 1, uniform_sets_[1]);
rhi.bind_binding_set(ctx, binding_set_);

View file

@ -26,8 +26,7 @@ class BlitRectPass
uint32_t texture_width_ = 0;
uint32_t texture_height_ = 0;
rhi::Handle<rhi::Texture> output_;
uint32_t output_width_ = 0;
uint32_t output_height_ = 0;
rhi::Rect output_position_;
bool output_correct_aspect_ = false;
bool output_flip_ = false;
rhi::Handle<rhi::Buffer> quad_vbo_;
@ -63,14 +62,15 @@ public:
/// @param width texture width
/// @param height texture height
void set_output(
int32_t x,
int32_t y,
uint32_t width,
uint32_t height,
bool correct_aspect,
bool flip
) noexcept
{
output_width_ = width;
output_height_ = height;
output_position_ = {x, y, width, height};
output_correct_aspect_ = correct_aspect;
output_flip_ = flip;
}

View file

@ -37,6 +37,19 @@ void UpscaleBackbuffer::begin_pass(Rhi& rhi, Handle<GraphicsContext> ctx)
remake = true;
}
auto new_renderpass = [&rhi = rhi](AttachmentLoadOp load_op, AttachmentStoreOp store_op)
{
RenderPassDesc desc {};
desc.use_depth_stencil = true;
desc.color_load_op = load_op;
desc.color_store_op = store_op;
desc.depth_load_op = load_op;
desc.depth_store_op = store_op;
desc.stencil_load_op = load_op;
desc.stencil_store_op = store_op;
return rhi.create_render_pass(desc);
};
if (remake)
{
if (color_)
@ -63,23 +76,22 @@ void UpscaleBackbuffer::begin_pass(Rhi& rhi, Handle<GraphicsContext> ctx)
depth_tex.height = vid_height;
depth_ = rhi.create_renderbuffer(depth_tex);
}
if (!renderpass_)
if (!renderpass_clear_)
{
renderpass_clear_ = new_renderpass(AttachmentLoadOp::kClear, AttachmentStoreOp::kStore);
}
}
else
{
RenderPassDesc desc {};
desc.use_depth_stencil = true;
desc.color_load_op = AttachmentLoadOp::kLoad;
desc.color_store_op = AttachmentStoreOp::kStore;
desc.depth_load_op = AttachmentLoadOp::kLoad;
desc.depth_store_op = AttachmentStoreOp::kStore;
desc.stencil_load_op = AttachmentLoadOp::kLoad;
desc.stencil_store_op = AttachmentStoreOp::kStore;
renderpass_ = rhi.create_render_pass(desc);
if (!renderpass_)
{
renderpass_ = new_renderpass(AttachmentLoadOp::kLoad, AttachmentStoreOp::kStore);
}
}
RenderPassBeginInfo begin_info {};
begin_info.render_pass = renderpass_;
begin_info.render_pass = remake ? renderpass_clear_ : renderpass_;
begin_info.clear_color = {0, 0, 0, 1};
begin_info.color_attachment = color_;
begin_info.depth_stencil_attachment = depth_;

View file

@ -20,6 +20,7 @@ class UpscaleBackbuffer
rhi::Handle<rhi::Texture> color_;
rhi::Handle<rhi::Renderbuffer> depth_;
rhi::Handle<rhi::RenderPass> renderpass_;
rhi::Handle<rhi::RenderPass> renderpass_clear_;
public:
UpscaleBackbuffer();

View file

@ -16,8 +16,10 @@
#include <imgui.h>
#include <tracy/tracy/Tracy.hpp>
#include "command.h"
#include "cxxutil.hpp"
#include "f_finale.h"
#include "m_fixed.h"
#include "m_misc.h"
#include "hwr2/hardware_state.hpp"
#include "hwr2/patch_atlas.hpp"
@ -46,6 +48,8 @@
#include "st_stuff.h"
#include "v_video.h"
extern "C" consvar_t cv_scr_scale, cv_scr_x, cv_scr_y;
using namespace srb2;
using namespace srb2::hwr2;
using namespace srb2::rhi;
@ -329,7 +333,20 @@ void I_FinishUpdate(void)
rhi->begin_default_render_pass(ctx, true);
// Upscale draw the backbuffer (with postprocessing maybe?)
g_hw_state.blit_rect->set_output(vid.realwidth, vid.realheight, true, true);
if (cv_scr_scale.value != FRACUNIT)
{
float f = std::max(FixedToFloat(cv_scr_scale.value), 0.f);
float w = vid.realwidth * f;
float h = vid.realheight * f;
float x = (vid.realwidth - w) * (0.5f + (FixedToFloat(cv_scr_x.value) * 0.5f));
float y = (vid.realheight - h) * (0.5f + (FixedToFloat(cv_scr_y.value) * 0.5f));
g_hw_state.blit_rect->set_output(x, y, w, h, true, true);
}
else
{
g_hw_state.blit_rect->set_output(0, 0, vid.realwidth, vid.realheight, true, true);
}
g_hw_state.blit_rect->set_texture(g_hw_state.backbuffer->color(), static_cast<uint32_t>(vid.width), static_cast<uint32_t>(vid.height));
g_hw_state.blit_rect->draw(*rhi, ctx);
rhi->end_render_pass(ctx);

View file

@ -235,6 +235,11 @@ static void SDLSetMode(INT32 width, INT32 height, SDL_bool fullscreen, SDL_bool
SDL_GetWindowSize(window, &width, &height);
vid.realwidth = static_cast<uint32_t>(width);
vid.realheight = static_cast<uint32_t>(height);
if (graphics_started)
{
I_UpdateNoVsync();
}
}
static INT32 Impl_SDL_Scancode_To_Keycode(SDL_Scancode code)
@ -501,6 +506,11 @@ static void Impl_HandleWindowEvent(SDL_WindowEvent evt)
case SDL_WINDOWEVENT_MOVED:
window_x = evt.data1;
window_y = evt.data2;
break;
case SDL_WINDOWEVENT_SIZE_CHANGED:
vid.realwidth = evt.data1;
vid.realheight = evt.data2;
break;
}
if (FOCUSUNION == oldfocus) // No state change
@ -1535,7 +1545,7 @@ INT32 VID_SetMode(INT32 modeNum)
static SDL_bool Impl_CreateWindow(SDL_bool fullscreen)
{
int flags = 0;
uint32_t flags = SDL_WINDOW_RESIZABLE;
if (rendermode == render_none) // dedicated
return SDL_TRUE; // Monster Iestyn -- not sure if it really matters what we return here tbh