From c26b6cdf59f9300dd9e1d805501e2f6b4bf63c39 Mon Sep 17 00:00:00 2001 From: Christoph Oelckers Date: Sun, 31 May 2020 21:25:52 +0200 Subject: [PATCH] - backend sync with GZDoom. --- source/build/src/engine.cpp | 1 + source/common/rendering/gl/gl_framebuffer.cpp | 12 ++++++------ source/common/rendering/gl/gl_framebuffer.h | 2 +- source/common/rendering/gl/gl_postprocess.cpp | 4 ++-- source/common/rendering/gl/gl_renderbuffers.cpp | 8 ++++---- source/common/rendering/gl/gl_samplers.h | 1 + source/common/rendering/gl/gl_shader.cpp | 8 +++++--- source/common/rendering/gl/gl_shader.h | 2 +- .../polyrenderer/backend/poly_framebuffer.cpp | 2 +- .../polyrenderer/backend/poly_framebuffer.h | 2 +- .../polyrenderer/drawers/poly_vertex_shader.h | 6 +++--- source/common/rendering/v_framebuffer.cpp | 1 - source/common/rendering/v_video.cpp | 13 ++++++++----- source/common/rendering/v_video.h | 6 +----- .../common/rendering/vulkan/shaders/vk_shader.cpp | 5 ++++- .../rendering/vulkan/system/vk_framebuffer.cpp | 7 +------ .../common/rendering/vulkan/system/vk_framebuffer.h | 3 +-- .../rendering/vulkan/textures/vk_hwtexture.cpp | 3 ++- source/common/textures/animtexture.cpp | 2 +- 19 files changed, 44 insertions(+), 44 deletions(-) diff --git a/source/build/src/engine.cpp b/source/build/src/engine.cpp index aaa84183b..af5b439ab 100644 --- a/source/build/src/engine.cpp +++ b/source/build/src/engine.cpp @@ -5346,6 +5346,7 @@ void rotatesprite_(int32_t sx, int32_t sy, int32_t z, int16_t a, int16_t picnum, void videoInit() { + lookups.postLoadLookups(); V_Init2(); videoSetGameMode(vid_fullscreen, SCREENWIDTH, SCREENHEIGHT, 32, 1); diff --git a/source/common/rendering/gl/gl_framebuffer.cpp b/source/common/rendering/gl/gl_framebuffer.cpp index 9088bc6dc..b1a13e1b5 100644 --- a/source/common/rendering/gl/gl_framebuffer.cpp +++ b/source/common/rendering/gl/gl_framebuffer.cpp @@ -91,7 +91,6 @@ OpenGLFrameBuffer::OpenGLFrameBuffer(void *hMonitor, bool fullscreen) : FHardwareTexture::InitGlobalState(); // Make sure all global variables tracking OpenGL context state are reset.. - gl_RenderState.Reset(); GLRenderer = nullptr; @@ -266,6 +265,7 @@ void OpenGLFrameBuffer::Swap() Finish.Unclock(); camtexcount = 0; FHardwareTexture::UnbindAll(); + gl_RenderState.ClearLastMaterial(); mDebug->Update(); mVertexData->Reset(); } @@ -296,16 +296,15 @@ void OpenGLFrameBuffer::SetVSync(bool vsync) // //=========================================================================== -IHardwareTexture *OpenGLFrameBuffer::CreateHardwareTexture(int numchannels) -{ - return new FHardwareTexture(numchannels); -} - void OpenGLFrameBuffer::SetTextureFilterMode() { if (GLRenderer != nullptr && GLRenderer->mSamplerManager != nullptr) GLRenderer->mSamplerManager->SetTextureFilterMode(); } +IHardwareTexture *OpenGLFrameBuffer::CreateHardwareTexture(int numchannels) +{ + return new FHardwareTexture(numchannels); +} void OpenGLFrameBuffer::PrecacheMaterial(FMaterial *mat, int translation) { @@ -326,6 +325,7 @@ void OpenGLFrameBuffer::PrecacheMaterial(FMaterial *mat, int translation) } // unbind everything. FHardwareTexture::UnbindAll(); + gl_RenderState.ClearLastMaterial(); } IVertexBuffer *OpenGLFrameBuffer::CreateVertexBuffer() diff --git a/source/common/rendering/gl/gl_framebuffer.h b/source/common/rendering/gl/gl_framebuffer.h index dc906bbf2..aaebbfeb3 100644 --- a/source/common/rendering/gl/gl_framebuffer.h +++ b/source/common/rendering/gl/gl_framebuffer.h @@ -40,8 +40,8 @@ public: FRenderState* RenderState() override; void UpdatePalette() override; const char* DeviceName() const override; - IHardwareTexture *CreateHardwareTexture(int numchannels) override; void SetTextureFilterMode() override; + IHardwareTexture *CreateHardwareTexture(int numchannels) override; void PrecacheMaterial(FMaterial *mat, int translation) override; void BeginFrame() override; void SetViewportRects(IntRect *bounds) override; diff --git a/source/common/rendering/gl/gl_postprocess.cpp b/source/common/rendering/gl/gl_postprocess.cpp index 2003bb1c6..2ac2db313 100644 --- a/source/common/rendering/gl/gl_postprocess.cpp +++ b/source/common/rendering/gl/gl_postprocess.cpp @@ -91,7 +91,7 @@ void FGLRenderer::BlurScene(float gameinfobluramount) int eyeCount = vrmode->mEyeCount; for (int i = 0; i < eyeCount; ++i) { - hw_postprocess.bloom.RenderBlur(&renderstate, sceneWidth, sceneHeight, gameinfobluramount); + hw_postprocess.bloom.RenderBlur(&renderstate, sceneWidth, sceneHeight, gameinfobluramount); if (eyeCount - i > 1) mBuffers->NextEye(eyeCount); } } @@ -112,7 +112,7 @@ void FGLRenderer::Flush() auto vrmode = VRMode::GetVRMode(true); if (vrmode->mEyeCount == 1) { - CopyToBackbuffer(nullptr, true); + CopyToBackbuffer(nullptr, true); } else { diff --git a/source/common/rendering/gl/gl_renderbuffers.cpp b/source/common/rendering/gl/gl_renderbuffers.cpp index abf412bc7..a1d8899bb 100644 --- a/source/common/rendering/gl/gl_renderbuffers.cpp +++ b/source/common/rendering/gl/gl_renderbuffers.cpp @@ -78,10 +78,10 @@ void FGLRenderBuffers::ClearScene() } else { - DeleteRenderBuffer(mSceneMultisampleBuf); - DeleteRenderBuffer(mSceneFogBuf); - DeleteRenderBuffer(mSceneNormalBuf); - DeleteRenderBuffer(mSceneDepthStencilBuf); + DeleteRenderBuffer(mSceneMultisampleBuf); + DeleteRenderBuffer(mSceneFogBuf); + DeleteRenderBuffer(mSceneNormalBuf); + DeleteRenderBuffer(mSceneDepthStencilBuf); } } diff --git a/source/common/rendering/gl/gl_samplers.h b/source/common/rendering/gl/gl_samplers.h index f22e40cdb..109f910a5 100644 --- a/source/common/rendering/gl/gl_samplers.h +++ b/source/common/rendering/gl/gl_samplers.h @@ -1,6 +1,7 @@ #ifndef __GL_SAMPLERS_H #define __GL_SAMPLERS_H +#include "gl_hwtexture.h" #include "textures.h" namespace OpenGLRenderer diff --git a/source/common/rendering/gl/gl_shader.cpp b/source/common/rendering/gl/gl_shader.cpp index c00ab0911..51f3fb3eb 100644 --- a/source/common/rendering/gl/gl_shader.cpp +++ b/source/common/rendering/gl/gl_shader.cpp @@ -379,14 +379,16 @@ bool FShader::Load(const char * name, const char * vert_prog_lump, const char * vp_comb << "#define SUPPORTS_SHADOWMAPS\n"; } - vp_comb << defines << i_data.GetChars(); FString fp_comb = vp_comb; + vp_comb << defines << i_data.GetChars(); + fp_comb << "$placeholder$\n" << defines << i_data.GetChars(); vp_comb << "#line 1\n"; fp_comb << "#line 1\n"; vp_comb << RemoveLayoutLocationDecl(vp_data.GetString(), "out").GetChars() << "\n"; fp_comb << RemoveLayoutLocationDecl(fp_data.GetString(), "in").GetChars() << "\n"; + FString placeholder = "\n"; if (proc_prog_lump != NULL) { @@ -448,9 +450,8 @@ bool FShader::Load(const char * name, const char * vert_prog_lump, const char * if (pp_data.GetString().IndexOf("ProcessMaterial") >= 0 && pp_data.GetString().IndexOf("SetupMaterial") < 0) { // This reactivates the old logic and disables all features that cannot be supported with that method. - fp_comb.Insert(0, "#define LEGACY_USER_SHADER\n"); + placeholder << "#define LEGACY_USER_SHADER\n"; } - } else { @@ -458,6 +459,7 @@ bool FShader::Load(const char * name, const char * vert_prog_lump, const char * fp_comb << proc_prog_lump + 1; } } + fp_comb.Substitute("$placeholder$", placeholder); if (light_fragprog) { diff --git a/source/common/rendering/gl/gl_shader.h b/source/common/rendering/gl/gl_shader.h index 3027376d5..fef8372cd 100644 --- a/source/common/rendering/gl/gl_shader.h +++ b/source/common/rendering/gl/gl_shader.h @@ -305,8 +305,8 @@ public: FShader *BindEffect(int effect, EPassType passType); FShader *Get(unsigned int eff, bool alphateston, EPassType passType); -private: void SetActiveShader(FShader *sh); +private: FShader *mActiveShader = nullptr; TArray mPassShaders; diff --git a/source/common/rendering/polyrenderer/backend/poly_framebuffer.cpp b/source/common/rendering/polyrenderer/backend/poly_framebuffer.cpp index a43b867d2..d1dbd63db 100644 --- a/source/common/rendering/polyrenderer/backend/poly_framebuffer.cpp +++ b/source/common/rendering/polyrenderer/backend/poly_framebuffer.cpp @@ -305,7 +305,7 @@ void PolyFrameBuffer::PrecacheMaterial(FMaterial *mat, int translation) } } -IHardwareTexture *PolyFrameBuffer::CreateHardwareTexture(int) +IHardwareTexture *PolyFrameBuffer::CreateHardwareTexture(int numchannels) { return new PolyHardwareTexture(); } diff --git a/source/common/rendering/polyrenderer/backend/poly_framebuffer.h b/source/common/rendering/polyrenderer/backend/poly_framebuffer.h index d549e9656..84982d9d5 100644 --- a/source/common/rendering/polyrenderer/backend/poly_framebuffer.h +++ b/source/common/rendering/polyrenderer/backend/poly_framebuffer.h @@ -43,7 +43,7 @@ public: void AmbientOccludeScene(float m5) override; //void SetSceneRenderTarget(bool useSSAO) override; - IHardwareTexture *CreateHardwareTexture(int) override; + IHardwareTexture *CreateHardwareTexture(int numchannels) override; IVertexBuffer *CreateVertexBuffer() override; IIndexBuffer *CreateIndexBuffer() override; IDataBuffer *CreateDataBuffer(int bindingpoint, bool ssbo, bool needsresize) override; diff --git a/source/common/rendering/polyrenderer/drawers/poly_vertex_shader.h b/source/common/rendering/polyrenderer/drawers/poly_vertex_shader.h index 8ae178127..aaf613d98 100644 --- a/source/common/rendering/polyrenderer/drawers/poly_vertex_shader.h +++ b/source/common/rendering/polyrenderer/drawers/poly_vertex_shader.h @@ -104,7 +104,7 @@ public: FVector3 u = normalize3(eyeCoordPos); FVector3 n = normalize3(mul(Viewpoint->mNormalViewMatrix, FVector4(parmTexCoord.X, 0.0f, parmTexCoord.Y, 0.0f))); FVector3 r = reflect(u, n); - float m = 2.0f * sqrt(r.X*r.X + r.Y*r.Y + (r.Z + 1.0f)*(r.Z + 1.0f)); + float m = 2.0f * sqrtf(r.X*r.X + r.Y*r.Y + (r.Z + 1.0f)*(r.Z + 1.0f)); vTexCoord.X = r.X / m + 0.5f; vTexCoord.Y = r.Y / m + 0.5f; } @@ -138,13 +138,13 @@ public: private: static FVector3 normalize(const FVector3 &a) { - float rcplen = 1.0f / sqrt(a.X * a.X + a.Y * a.Y + a.Z * a.Z); + float rcplen = 1.0f / sqrtf(a.X * a.X + a.Y * a.Y + a.Z * a.Z); return FVector3(a.X * rcplen, a.Y * rcplen, a.Z * rcplen); } static FVector3 normalize3(const FVector4 &a) { - float rcplen = 1.0f / sqrt(a.X * a.X + a.Y * a.Y + a.Z * a.Z); + float rcplen = 1.0f / sqrtf(a.X * a.X + a.Y * a.Y + a.Z * a.Z); return FVector3(a.X * rcplen, a.Y * rcplen, a.Z * rcplen); } diff --git a/source/common/rendering/v_framebuffer.cpp b/source/common/rendering/v_framebuffer.cpp index 1568fa61f..4d55989c3 100644 --- a/source/common/rendering/v_framebuffer.cpp +++ b/source/common/rendering/v_framebuffer.cpp @@ -72,7 +72,6 @@ EXTERN_CVAR(Int, screenblocks) DFrameBuffer::DFrameBuffer (int width, int height) { - twod = &m2DDrawer; SetSize(width, height); } diff --git a/source/common/rendering/v_video.cpp b/source/common/rendering/v_video.cpp index 47697c655..ce4dab80a 100644 --- a/source/common/rendering/v_video.cpp +++ b/source/common/rendering/v_video.cpp @@ -62,7 +62,6 @@ #include "i_interface.h" #include "v_draw.h" #include "templates.h" -#include "palette.h" EXTERN_CVAR(Int, menu_resolution_custom_width) EXTERN_CVAR(Int, menu_resolution_custom_height) @@ -168,7 +167,7 @@ CUSTOM_CVAR (Bool, vid_vsync, false, CVAR_ARCHIVE|CVAR_GLOBALCONFIG) } // [RH] Set true when vid_setmode command has been executed -bool setmodeneeded = false; +bool setmodeneeded = false; bool setsizeneeded = false; //========================================================================== @@ -290,6 +289,9 @@ void V_UpdateModeSize (int width, int height) void V_OutputResized (int width, int height) { V_UpdateModeSize(width, height); + // set new resolution in 2D drawer + twod->Begin(screen->GetWidth(), screen->GetHeight()); + twod->End(); setsizeneeded = true; C_NewModeAdjust(); if (sysCallbacks && sysCallbacks->OnScreenSizeChanged) @@ -358,8 +360,6 @@ void V_InitScreen() void V_Init2() { - lookups.postLoadLookups(); - float gamma = static_cast(screen)->Gamma; { @@ -396,7 +396,10 @@ CUSTOM_CVAR (Int, vid_aspect, 0, CVAR_GLOBALCONFIG|CVAR_ARCHIVE) sysCallbacks->OnScreenSizeChanged(); } - +DEFINE_ACTION_FUNCTION(_Screen, GetAspectRatio) +{ + ACTION_RETURN_FLOAT(ActiveRatio(screen->GetWidth(), screen->GetHeight(), nullptr)); +} CCMD(vid_setsize) { diff --git a/source/common/rendering/v_video.h b/source/common/rendering/v_video.h index 44769dd79..ac61291dd 100644 --- a/source/common/rendering/v_video.h +++ b/source/common/rendering/v_video.h @@ -120,14 +120,11 @@ protected: }; class IHardwareTexture; -class FGameTexture; +class FTexture; class DFrameBuffer { -protected: - - F2DDrawer m2DDrawer; private: int Width = 0; int Height = 0; @@ -202,7 +199,6 @@ public: virtual void SetTextureFilterMode() {} virtual IHardwareTexture *CreateHardwareTexture(int numchannels) { return nullptr; } virtual void PrecacheMaterial(FMaterial *mat, int translation) {} - virtual FModelRenderer *CreateModelRenderer(int mli) { return nullptr; } virtual FMaterial* CreateMaterial(FGameTexture* tex, int scaleflags); virtual void BeginFrame() {} virtual void SetWindowSize(int w, int h) {} diff --git a/source/common/rendering/vulkan/shaders/vk_shader.cpp b/source/common/rendering/vulkan/shaders/vk_shader.cpp index 8162cf7b3..092a20e69 100644 --- a/source/common/rendering/vulkan/shaders/vk_shader.cpp +++ b/source/common/rendering/vulkan/shaders/vk_shader.cpp @@ -284,8 +284,10 @@ std::unique_ptr VkShaderManager::LoadFragShader(FString shadername { FString code = GetTargetGlslVersion(); code << defines; + code << "\n$placeholder$"; // here the code can later add more needed #defines. code << "\n#define MAX_STREAM_DATA " << std::to_string(MAX_STREAM_DATA).c_str() << "\n"; code << shaderBindings; + FString placeholder = "\n"; if (!device->UsedDeviceFeatures.shaderClipDistance) code << "#define NO_CLIPDISTANCE_SUPPORT\n"; if (!alphatest) code << "#define NO_ALPHATEST\n"; @@ -342,7 +344,7 @@ std::unique_ptr VkShaderManager::LoadFragShader(FString shadername if (pp_code.IndexOf("ProcessMaterial") >= 0 && pp_code.IndexOf("SetupMaterial") < 0) { // This reactivates the old logic and disables all features that cannot be supported with that method. - code.Insert(0, "#define LEGACY_USER_SHADER\n"); + placeholder << "#define LEGACY_USER_SHADER\n"; } } else @@ -351,6 +353,7 @@ std::unique_ptr VkShaderManager::LoadFragShader(FString shadername code << (material_lump + 1) << "\n"; } } + code.Substitute("$placeholder$", placeholder); if (light_lump) { diff --git a/source/common/rendering/vulkan/system/vk_framebuffer.cpp b/source/common/rendering/vulkan/system/vk_framebuffer.cpp index 8cc0046ea..602d628b1 100644 --- a/source/common/rendering/vulkan/system/vk_framebuffer.cpp +++ b/source/common/rendering/vulkan/system/vk_framebuffer.cpp @@ -379,7 +379,7 @@ void VulkanFrameBuffer::PrecacheMaterial(FMaterial *mat, int translation) } } -IHardwareTexture *VulkanFrameBuffer::CreateHardwareTexture() +IHardwareTexture *VulkanFrameBuffer::CreateHardwareTexture(int numchannels) { return new VkHardwareTexture(); } @@ -419,11 +419,6 @@ IDataBuffer *VulkanFrameBuffer::CreateDataBuffer(int bindingpoint, bool ssbo, bo } void VulkanFrameBuffer::SetTextureFilterMode() -{ - TextureFilterChanged(); -} - -void VulkanFrameBuffer::TextureFilterChanged() { if (mSamplerManager) { diff --git a/source/common/rendering/vulkan/system/vk_framebuffer.h b/source/common/rendering/vulkan/system/vk_framebuffer.h index 537879e6a..b1a776452 100644 --- a/source/common/rendering/vulkan/system/vk_framebuffer.h +++ b/source/common/rendering/vulkan/system/vk_framebuffer.h @@ -77,7 +77,6 @@ public: const char* DeviceName() const override; int Backend() override { return 1; } void SetTextureFilterMode() override; - void TextureFilterChanged() override; void StartPrecaching() override; void BeginFrame() override; void BlurScene(float amount) override; @@ -89,7 +88,7 @@ public: void ImageTransitionScene(bool unknown) override; void SetActiveRenderTarget() override; - IHardwareTexture *CreateHardwareTexture() override; + IHardwareTexture *CreateHardwareTexture(int numchannels) override; FMaterial* CreateMaterial(FGameTexture* tex, int scaleflags) override; IVertexBuffer *CreateVertexBuffer() override; IIndexBuffer *CreateIndexBuffer() override; diff --git a/source/common/rendering/vulkan/textures/vk_hwtexture.cpp b/source/common/rendering/vulkan/textures/vk_hwtexture.cpp index cac4985ef..0a30a76e4 100644 --- a/source/common/rendering/vulkan/textures/vk_hwtexture.cpp +++ b/source/common/rendering/vulkan/textures/vk_hwtexture.cpp @@ -369,7 +369,8 @@ VulkanDescriptorSet* VkMaterial::GetDescriptorSet(const FMaterialState& state) int translation = state.mTranslation; auto remap = translation <= 0 ? nullptr : GPalette.TranslationToTable(translation); - if (remap) translation = remap->Index; + if (remap) + translation = remap->Index; clampmode = base->GetClampMode(clampmode); diff --git a/source/common/textures/animtexture.cpp b/source/common/textures/animtexture.cpp index e8635e404..2d06eccab 100644 --- a/source/common/textures/animtexture.cpp +++ b/source/common/textures/animtexture.cpp @@ -71,7 +71,7 @@ FBitmap AnimTexture::GetBgraBitmap(const PalEntry* remap, int* trans) { int p = i * 4; int index = spix[i]; - dpix[p + 0] = Palette[index*3+2]; + dpix[p + 0] = Palette[index * 3 + 2]; dpix[p + 1] = Palette[index * 3 + 1]; dpix[p + 2] = Palette[index * 3]; dpix[p + 3] = 255;