From 6dd72e5439fbe8863e719beac3651892440952b1 Mon Sep 17 00:00:00 2001 From: Magnus Norddahl Date: Sat, 14 Oct 2023 14:23:58 +0200 Subject: [PATCH] Begin code for drawing the level mesh --- src/common/rendering/v_video.h | 2 + .../rendering/vulkan/vk_renderdevice.cpp | 6 ++- src/common/rendering/vulkan/vk_renderdevice.h | 2 + src/rendering/hwrenderer/hw_entrypoint.cpp | 42 +++++++++++++++++-- 4 files changed, 47 insertions(+), 5 deletions(-) diff --git a/src/common/rendering/v_video.h b/src/common/rendering/v_video.h index 8dc23f33d..b4361c517 100644 --- a/src/common/rendering/v_video.h +++ b/src/common/rendering/v_video.h @@ -225,6 +225,8 @@ public: virtual void PostProcessScene(bool swscene, int fixedcm, float flash, const std::function &afterBloomDrawEndScene2D) { if (afterBloomDrawEndScene2D) afterBloomDrawEndScene2D(); } + virtual void DrawLevelMesh(const FVector3& pos, const VSMatrix& proj) { } + void ScaleCoordsFromWindow(int16_t &x, int16_t &y); virtual void Draw2D() {} diff --git a/src/common/rendering/vulkan/vk_renderdevice.cpp b/src/common/rendering/vulkan/vk_renderdevice.cpp index 2b3591723..51509f815 100644 --- a/src/common/rendering/vulkan/vk_renderdevice.cpp +++ b/src/common/rendering/vulkan/vk_renderdevice.cpp @@ -605,4 +605,8 @@ int VulkanRenderDevice::GetBindlessTextureIndex(FMaterial* material, int clampmo materialState.mClampMode = clampmode; materialState.mTranslation = translation; return static_cast(material)->GetBindlessIndex(materialState); -} \ No newline at end of file +} + +void VulkanRenderDevice::DrawLevelMesh(const FVector3& pos, const VSMatrix& proj) +{ +} diff --git a/src/common/rendering/vulkan/vk_renderdevice.h b/src/common/rendering/vulkan/vk_renderdevice.h index 7761789cb..3bea6fdd3 100644 --- a/src/common/rendering/vulkan/vk_renderdevice.h +++ b/src/common/rendering/vulkan/vk_renderdevice.h @@ -89,6 +89,8 @@ public: int GetBindlessTextureIndex(FMaterial* material, int clampmode, int translation) override; + void DrawLevelMesh(const FVector3& pos, const VSMatrix& proj) override; + private: void RenderTextureView(FCanvasTexture* tex, std::function renderFunc) override; void PrintStartupLog(); diff --git a/src/rendering/hwrenderer/hw_entrypoint.cpp b/src/rendering/hwrenderer/hw_entrypoint.cpp index 2b4851178..367945b57 100644 --- a/src/rendering/hwrenderer/hw_entrypoint.cpp +++ b/src/rendering/hwrenderer/hw_entrypoint.cpp @@ -54,6 +54,8 @@ EXTERN_CVAR(Bool, cl_capfps) extern bool NoInterpolateView; +CVAR(Bool, gl_levelmesh, true, 0/*CVAR_ARCHIVE | CVAR_GLOBALCONFIG*/) + static SWSceneDrawer *swdrawer; void CleanSWDrawer() @@ -123,16 +125,48 @@ sector_t* RenderViewpoint(FRenderViewpoint& mainvp, AActor* camera, IntRect* bou screen->mShadowMap->SetCollectLights(nullptr); } + // Update the attenuation flag of all light defaults for each viewpoint. + // This function will only do something if the setting differs. + FLightDefaults::SetAttenuationForLevel(!!(camera->Level->flags3 & LEVEL3_ATTENUATE)); + + if (gl_levelmesh) + { + screen->SetViewportRects(bounds); + + auto vrmode = VRMode::GetVRMode(mainview && toscreen); + const int eyeCount = vrmode->mEyeCount; + screen->FirstEye(); + + FRenderViewpoint vp = mainvp; + const auto& eye = vrmode->mEyes[0]; + vp.Pos += eye.GetViewShift(vp.HWAngles.Yaw.Degrees()); + + screen->DrawLevelMesh(FVector3((float)vp.Pos.X, (float)vp.Pos.Y, (float)vp.Pos.Z), eye.GetProjection(fov, ratio, fovratio)); + + PostProcess.Clock(); + //if (toscreen) di->EndDrawScene(mainvp.sector, RenderState); // do not call this for camera textures. + + if (RenderState.GetPassType() == GBUFFER_PASS) // Turn off ssao draw buffers + { + RenderState.SetPassType(NORMAL_PASS); + RenderState.EnableDrawBuffers(1); + } + + auto cm = CM_DEFAULT; // di->SetFullbrightFlags(mainview ? vp.camera->player : nullptr); + float flash = 1.f; + + screen->PostProcessScene(false, cm, flash, [&]() { /* di->DrawEndScene2D(mainvp.sector, RenderState); */ }); + PostProcess.Unclock(); + + return mainvp.sector; + } + static HWDrawContext mainthread_drawctx; hw_ClearFakeFlat(&mainthread_drawctx); meshcache.Update(&mainthread_drawctx, mainvp); - // Update the attenuation flag of all light defaults for each viewpoint. - // This function will only do something if the setting differs. - FLightDefaults::SetAttenuationForLevel(!!(camera->Level->flags3 & LEVEL3_ATTENUATE)); - // Render (potentially) multiple views for stereo 3d // Fixme. The view offsetting should be done with a static table and not require setup of the entire render state for the mode. auto vrmode = VRMode::GetVRMode(mainview && toscreen);