From 0d1a4a5d46d134df0728c172598af6a9320ab5a2 Mon Sep 17 00:00:00 2001 From: Michael Pollind Date: Sun, 2 Apr 2023 22:23:35 -0700 Subject: [PATCH] bugfix: general post processing fixes - correctly support BGR --> RGB - fix color conv - fix memory leak with tweaks to TextureManager - move queue events to a seperate special handler Signed-off-by: Michael Pollind --- .../include/graphics/ImmediateDrawBatch.h | 10 +- .../graphics/PostEffect_ColorConvTex.h | 10 +- HPL2/core/include/graphics/Renderer.h | 16 +- HPL2/core/include/graphics/RendererDeferred.h | 2 - HPL2/core/include/scene/Viewport.h | 15 +- .../core/resource/fs_posteffect_color_conv.sc | 1 - HPL2/core/sources/graphics/GraphicsContex.cpp | 5 +- HPL2/core/sources/graphics/Image.cpp | 34 +- .../sources/graphics/ImmediateDrawBatch.cpp | 16 +- .../graphics/PostEffect_ColorConvTex.cpp | 21 +- .../graphics/PostEffect_ImageTrail.cpp | 4 +- HPL2/core/sources/graphics/Renderer.cpp | 74 +-- .../sources/graphics/RendererDeferred.cpp | 183 +++--- .../core/sources/resources/TextureManager.cpp | 16 +- HPL2/core/sources/system/Bootstrap.cpp | 1 - HPL2/core/sources/system/Container.cpp | 48 -- HPL2/core/sources/system/Platform.cpp | 5 - .../editors/common/EditorWindowViewport.cpp | 50 +- .../ModelEditorWindowPhysicsTest.cpp | 2 +- HPL2/tools/mapview/MapView.cpp | 4 +- HPL2/tools/modelview/ModelView.cpp | 2 +- HPL2/tools/particleview/ParticleView.cpp | 2 +- amnesia/src/game/LuxEffectRenderer.cpp | 583 +++++++++--------- amnesia/src/game/LuxEffectRenderer.h | 6 +- amnesia/src/game/LuxHandObject_Melee.h | 3 - amnesia/src/game/LuxMainMenu_Options.cpp | 9 - amnesia/src/game/LuxMapHandler.cpp | 22 +- amnesia/src/game/LuxPlayer.cpp | 13 +- amnesia/src/game/LuxPlayer.h | 4 +- amnesia/src/game/LuxPlayerHands.cpp | 8 - amnesia/src/game/LuxPlayerHands.h | 7 +- amnesia/src/game/LuxPlayerState.h | 8 +- .../src/game/LuxPlayerState_InteractGrab.cpp | 12 +- .../src/game/LuxPlayerState_InteractGrab.h | 2 +- .../src/game/LuxPlayerState_InteractLever.cpp | 15 +- .../src/game/LuxPlayerState_InteractLever.h | 2 +- .../LuxPlayerState_InteractRotateBase.cpp | 2 +- .../game/LuxPlayerState_InteractRotateBase.h | 2 +- .../src/game/LuxPlayerState_InteractSlide.cpp | 11 +- .../src/game/LuxPlayerState_InteractSlide.h | 2 +- .../src/game/LuxPlayerState_InteractWheel.cpp | 10 +- .../src/game/LuxPlayerState_InteractWheel.h | 2 +- amnesia/src/game/LuxProp.cpp | 23 - amnesia/src/game/LuxProp.h | 2 - amnesia/src/game/LuxTypes.h | 11 +- 45 files changed, 609 insertions(+), 671 deletions(-) delete mode 100644 HPL2/core/sources/system/Container.cpp diff --git a/HPL2/core/include/graphics/ImmediateDrawBatch.h b/HPL2/core/include/graphics/ImmediateDrawBatch.h index b95880fc6..bf02c2629 100644 --- a/HPL2/core/include/graphics/ImmediateDrawBatch.h +++ b/HPL2/core/include/graphics/ImmediateDrawBatch.h @@ -8,9 +8,7 @@ namespace hpl { -class ImmediateDrawBatch; - - class ImmediateDrawBatch { +class ImmediateDrawBatch { public: struct DebugDrawOptions { public: @@ -24,8 +22,7 @@ class ImmediateDrawBatch; inline GraphicsContext& GetContext() const { return m_context; } ImmediateDrawBatch(GraphicsContext& context, RenderTarget& target, const cMatrixf& view, const cMatrixf& projection); - - + // takes 3 points and the other 1 is calculated [[deprecated("Use DrawQuad with Eigen")]] void DrawQuad(const cVector3f& v1, const cVector3f& v2, const cVector3f& v3, const cVector3f& v4, const cVector2f& uv0,const cVector2f& uv1, hpl::Image* image , const cColor& aTint, const DebugDrawOptions& options = DebugDrawOptions()); @@ -111,12 +108,11 @@ class ImmediateDrawBatch; }; // Orthgraphic projection std::vector m_line2DSegments; - - // Perspective projection std::vector m_uvQuads; std::vector m_colorQuads; std::vector m_lineSegments; std::vector m_colorTriangles; + cMatrixf m_view; cMatrixf m_projection; diff --git a/HPL2/core/include/graphics/PostEffect_ColorConvTex.h b/HPL2/core/include/graphics/PostEffect_ColorConvTex.h index b87cc8a8c..75b0b6a32 100644 --- a/HPL2/core/include/graphics/PostEffect_ColorConvTex.h +++ b/HPL2/core/include/graphics/PostEffect_ColorConvTex.h @@ -68,15 +68,15 @@ namespace hpl { public: virtual void RenderEffect(cPostEffectComposite& compositor, cViewport& viewport, GraphicsContext& context, Image& input, RenderTarget& target) override; cPostEffect_ColorConvTex(cGraphics *apGraphics, cResources *apResources, iPostEffectType *apType); - ~cPostEffect_ColorConvTex(); + virtual ~cPostEffect_ColorConvTex(); private: - void OnSetParams(); - iPostEffectParams *GetTypeSpecificParams() { return &mParams; } + virtual void OnSetParams() override; + virtual iPostEffectParams *GetTypeSpecificParams() override { return &mParams; } - Image* mpColorConvTex; + Image* mpColorConvTex = nullptr; - cPostEffectType_ColorConvTex* mpSpecificType; + cPostEffectType_ColorConvTex* mpSpecificType = nullptr; cPostEffectParams_ColorConvTex mParams; }; diff --git a/HPL2/core/include/graphics/Renderer.h b/HPL2/core/include/graphics/Renderer.h index 36007df6e..12f51da38 100644 --- a/HPL2/core/include/graphics/Renderer.h +++ b/HPL2/core/include/graphics/Renderer.h @@ -57,6 +57,7 @@ namespace hpl { class iRenderableContainerNode; class cVisibleRCNodeTracker; class RenderCallbackMessage; + class iRenderer; namespace rendering::detail { eShadowMapResolution GetShadowMapResolution(eShadowMapResolution aWanted, eShadowMapResolution aMax); @@ -67,6 +68,14 @@ namespace hpl { * @param occlusionPlanes The planes to check against. */ bool IsObjectVisible(iRenderable *apObject, tRenderableFlag alNeededFlags, std::span occlusionPlanes); + + void RenderableMaterialIter( + iRenderer* renderer, + std::span iter, + cViewport& viewport, + eMaterialRenderMode mode, + std::function handler); + } class cNodeOcclusionPair @@ -110,7 +119,6 @@ namespace hpl { }; - class iRenderer; class cRenderSettings { public: @@ -325,8 +333,6 @@ namespace hpl { cShadowMapData* GetShadowMapData(eShadowMapResolution aResolution, iLight *apLight); bool ShadowMapNeedsUpdate(iLight *apLight, cShadowMapData *apShadowData); - void DestroyShadowMaps(); - void RenderZObject(GraphicsContext& context, iRenderable *apObject, cFrustum *apCustomFrustum); @@ -359,9 +365,7 @@ namespace hpl { void GetShadowCasters(iRenderableContainer *apContainer, tRenderableVec& avObjectVec, cFrustum *apLightFrustum); bool SetupShadowMapRendering(iLight *apLight); - bool RenderShadowCasterCHC(iRenderable *apObject); - void RenderShadowCaster(iRenderable *apObject, cFrustum *apLightFrustum); - + /** * Only depth is needed for framebuffer. All objects needs to be added to renderlist! */ diff --git a/HPL2/core/include/graphics/RendererDeferred.h b/HPL2/core/include/graphics/RendererDeferred.h index 9aa293be4..f5d9bf40d 100644 --- a/HPL2/core/include/graphics/RendererDeferred.h +++ b/HPL2/core/include/graphics/RendererDeferred.h @@ -279,8 +279,6 @@ namespace hpl { // takes the contents of the gbuffer and renders the lights void RenderLightPass(GraphicsContext& context, cViewport& viewport, RenderTarget& rt); void RenderDiffusePass(GraphicsContext& context, cViewport& viewport, RenderTarget& rt); - void RenderDecalPass(GraphicsContext& context, cViewport& viewport, RenderTarget& rt); - void RenderIlluminationPass(GraphicsContext& context, cViewport& viewport, RenderTarget& rt); void RenderFogPass(GraphicsContext& context, cViewport& viewport, RenderTarget& rt); void RenderFullScreenFogPass(GraphicsContext& context, cViewport& viewport, RenderTarget& rt); void RenderEdgeSmoothPass(GraphicsContext& context, cViewport& viewport, RenderTarget& rt); diff --git a/HPL2/core/include/scene/Viewport.h b/HPL2/core/include/scene/Viewport.h index 4a7e894ed..1e38b9250 100644 --- a/HPL2/core/include/scene/Viewport.h +++ b/HPL2/core/include/scene/Viewport.h @@ -63,13 +63,16 @@ namespace hpl { cFrustum* m_frustum; GraphicsContext* m_context; RenderTarget* m_outputTarget; + cViewport* m_viewport; + cRenderSettings* m_renderSettings; + ImmediateDrawBatch* m_immediateDrawBatch; }; - struct PostSolidDrawPayload : public DrawPayloadCommon { + struct PostSolidDrawPacket : public DrawPayloadCommon { }; - struct PostTranslucenceDrawPayload : public DrawPayloadCommon { + struct PostTranslucenceDrawPacket : public DrawPayloadCommon { }; - using PostSolidDraw = hpl::Event; - using PostTranslucenceDraw = hpl::Event; + using PostSolidDraw = hpl::Event; + using PostTranslucenceDraw = hpl::Event; cViewport(cScene* apScene); @@ -159,8 +162,8 @@ namespace hpl { inline void ConnectDraw(PostSolidDraw::Handler& handler) { handler.Connect(m_postSolidDraw); } inline void ConnectDraw(PostTranslucenceDraw::Handler& handler) { handler.Connect(m_postTranslucenceDraw); } - inline void SignalDraw(PostSolidDrawPayload& payload) { m_postSolidDraw.Signal(payload);} - inline void SignalDraw(PostTranslucenceDrawPayload& payload) { m_postTranslucenceDraw.Signal(payload);} + inline void SignalDraw(PostSolidDrawPacket& payload) { m_postSolidDraw.Signal(payload);} + inline void SignalDraw(PostTranslucenceDrawPacket& payload) { m_postTranslucenceDraw.Signal(payload);} private: diff --git a/HPL2/core/resource/fs_posteffect_color_conv.sc b/HPL2/core/resource/fs_posteffect_color_conv.sc index 14804ff7b..f6fba57d0 100644 --- a/HPL2/core/resource/fs_posteffect_color_conv.sc +++ b/HPL2/core/resource/fs_posteffect_color_conv.sc @@ -12,7 +12,6 @@ uniform vec4 u_params; void main() { vec3 diffuseColor = texture2D(s_diffuseMap, v_texcoord0).xyz; - vec3 outputColor = vec3(texture2D(s_convMap, vec2(diffuseColor.x, 0)).x, texture2D(s_convMap, vec2(diffuseColor.y, 0)).y, texture2D(s_convMap, vec2(diffuseColor.z, 0)).z); diff --git a/HPL2/core/sources/graphics/GraphicsContex.cpp b/HPL2/core/sources/graphics/GraphicsContex.cpp index 94f253f9f..1f1d37468 100644 --- a/HPL2/core/sources/graphics/GraphicsContex.cpp +++ b/HPL2/core/sources/graphics/GraphicsContex.cpp @@ -10,7 +10,8 @@ #include "graphics/Enum.h" #include "graphics/ShaderUtil.h" -#include +#include "graphics/Layouts.h" +#include "graphics/GraphicsTypes.h" #include "bx/math.h" #include @@ -26,7 +27,6 @@ #include #include -#include "graphics/Layouts.h" namespace hpl { @@ -70,7 +70,6 @@ namespace hpl { void GraphicsContext::Frame() { m_current = 0; - // m_windowEvent.Process(); bgfx::frame(); } diff --git a/HPL2/core/sources/graphics/Image.cpp b/HPL2/core/sources/graphics/Image.cpp index 15b9e0597..20257ef37 100644 --- a/HPL2/core/sources/graphics/Image.cpp +++ b/HPL2/core/sources/graphics/Image.cpp @@ -327,14 +327,12 @@ namespace hpl return bgfx::TextureFormat::R32F; case ePixelFormat_LuminanceAlpha32: return bgfx::TextureFormat::RG32F; - case ePixelFormat_RGB32: - break; case ePixelFormat_RGBA32: return bgfx::TextureFormat::RGBA32F; case ePixelFormat_RGB16: return bgfx::TextureFormat::BC6H; case ePixelFormat_BGR: - return bgfx::TextureFormat::RGB8; + return bgfx::TextureFormat::RGB8; // this is not supported by bgfx so we swap it under Image::InitializeFromBitmap default: BX_ASSERT(false, "Unsupported texture format: %d", format) break; @@ -378,6 +376,21 @@ namespace hpl } void Image::InitializeFromBitmap(Image& image, cBitmap& bitmap, const ImageDescriptor& desc) { + + auto copyDataToChunk = [&](unsigned char* m_begin, unsigned char* m_end, unsigned char* dest) { + + // BGR is not supported by bgfx, so we need to convert it to RGB + if(bitmap.GetPixelFormat() == ePixelFormat_BGR) { + for(auto* src = m_begin; src < m_end; src += 3) { + *(dest++) = src[2]; + *(dest++) = src[1]; + *(dest++) = src[0]; + } + } else { + std::copy(m_begin, m_end, dest); + } + }; + if(desc.m_isCubeMap) { BX_ASSERT(bitmap.GetNumOfImages() == 6, "Cube map must have 6 images"); @@ -398,14 +411,16 @@ namespace hpl for(auto imageIdx = 0; imageIdx < bitmap.GetNumOfImages(); ++imageIdx) { for(auto mipIndex = 0; mipIndex < bitmap.GetNumOfMipMaps(); ++mipIndex) { auto data = bitmap.GetData(imageIdx, mipIndex); - std::copy(data->mpData, data->mpData + data->mlSize, memory->data + offset); + // std::copy(data->mpData, data->mpData + data->mlSize, memory->data + offset); + copyDataToChunk(data->mpData, data->mpData + data->mlSize, memory->data + offset); offset += data->mlSize; } } } else { for(auto i = 0; i < bitmap.GetNumOfImages(); ++i) { auto data = bitmap.GetData(i, 0); - std::copy(data->mpData, data->mpData + data->mlSize, memory->data + offset); + // std::copy(data->mpData, data->mpData + data->mlSize, memory->data + offset); + copyDataToChunk(data->mpData, data->mpData + data->mlSize, memory->data + offset); offset += data->mlSize; } } @@ -425,15 +440,18 @@ namespace hpl size_t offset = 0; for(auto i = 0; i < bitmap.GetNumOfMipMaps(); ++i) { auto data = bitmap.GetData(0, i); - std::copy(data->mpData, data->mpData + data->mlSize, memory->data + offset); + // std::copy(data->mpData, data->mpData + data->mlSize, memory->data + offset); + copyDataToChunk(data->mpData, data->mpData + data->mlSize, memory->data + offset); offset += data->mlSize; } image.Initialize(desc, memory); return; } - + auto data = bitmap.GetData(0, 0); - image.Initialize(desc, bgfx::copy(data->mpData, data->mlSize)); + auto* memory = bgfx::alloc(data->mlSize); + copyDataToChunk(data->mpData, data->mpData + data->mlSize, memory->data); + image.Initialize(desc, memory); } bgfx::TextureHandle Image::GetHandle() const diff --git a/HPL2/core/sources/graphics/ImmediateDrawBatch.cpp b/HPL2/core/sources/graphics/ImmediateDrawBatch.cpp index 102f8e57f..35e744175 100644 --- a/HPL2/core/sources/graphics/ImmediateDrawBatch.cpp +++ b/HPL2/core/sources/graphics/ImmediateDrawBatch.cpp @@ -381,7 +381,11 @@ namespace hpl { void ImmediateDrawBatch::flush() { - if (m_lineSegments.empty() && m_colorQuads.empty() && m_uvQuads.empty() && m_colorTriangles.empty() && m_line2DSegments.empty()) { + if (m_line2DSegments.empty() && + m_uvQuads.empty() && + m_colorQuads.empty() && + m_lineSegments.empty() && + m_colorTriangles.empty()) { return; } @@ -719,9 +723,11 @@ namespace hpl { m_context.Submit(m_perspectiveView, request); } } - m_colorTriangles.clear(); - m_lineSegments.clear(); - m_colorQuads.clear(); - m_uvQuads.clear(); + m_line2DSegments.clear(); + m_uvQuads.clear(); + m_colorQuads.clear(); + m_lineSegments.clear(); + m_colorTriangles.clear(); + } } // namespace hpl \ No newline at end of file diff --git a/HPL2/core/sources/graphics/PostEffect_ColorConvTex.cpp b/HPL2/core/sources/graphics/PostEffect_ColorConvTex.cpp index 92f5d7e1c..44973fdd3 100644 --- a/HPL2/core/sources/graphics/PostEffect_ColorConvTex.cpp +++ b/HPL2/core/sources/graphics/PostEffect_ColorConvTex.cpp @@ -46,7 +46,7 @@ namespace hpl : iPostEffectType("ColorConvTex", apGraphics, apResources) { m_colorConv = hpl::loadProgram("vs_post_effect", "fs_posteffect_color_conv"); - m_u_param = bgfx::createUniform("u_param", bgfx::UniformType::Vec4); + m_u_param = bgfx::createUniform("u_params", bgfx::UniformType::Vec4); m_u_colorConvTex = bgfx::createUniform("s_convMap", bgfx::UniformType::Sampler); m_u_diffuseTex = bgfx::createUniform("s_diffuseMap", bgfx::UniformType::Sampler); } @@ -79,14 +79,17 @@ namespace hpl void cPostEffect_ColorConvTex::OnSetParams() { - if (mParams.msTextureFile == "") + if (mParams.msTextureFile == "") { return; + } - if (mpColorConvTex) - { + if (mpColorConvTex) { mpResources->GetTextureManager()->Destroy(mpColorConvTex); } - mpColorConvTex = mpResources->GetTextureManager()->Create1DImage(mParams.msTextureFile, false); + cTextureManager::ImageOptions options; + options.m_UWrap = WrapMode::Clamp; + options.m_VWrap = WrapMode::Clamp; + mpColorConvTex = mpResources->GetTextureManager()->Create1DImage(mParams.msTextureFile, false, eTextureUsage_Normal, 0, options); } void cPostEffect_ColorConvTex::RenderEffect(cPostEffectComposite& compositor, cViewport& viewport, GraphicsContext& context, Image& input, RenderTarget& target) @@ -105,14 +108,20 @@ namespace hpl GraphicsContext::ShaderProgram shaderProgram; // shaderProgram.m_projection = projMtx; shaderProgram.m_handle = mpSpecificType->m_colorConv; + struct { float u_alphaFade; float pad; float pad1; float pad2; - } uniform = { cMath::Min(1.0f, cMath::Max(mParams.mfFadeAlpha, 0.0f)), 0, 0, 0 }; + } uniform = { + cMath::Clamp(mParams.mfFadeAlpha, 0.0f, 1.0f), + 0, + 0, + 0 }; shaderProgram.m_uniforms.push_back({ mpSpecificType->m_u_param, &uniform, 1 }); + shaderProgram.m_textures.push_back({ mpSpecificType->m_u_colorConvTex, mpColorConvTex->GetHandle(), 0 }); shaderProgram.m_textures.push_back({ mpSpecificType->m_u_diffuseTex, input.GetHandle(), 1 }); diff --git a/HPL2/core/sources/graphics/PostEffect_ImageTrail.cpp b/HPL2/core/sources/graphics/PostEffect_ImageTrail.cpp index b2991bc32..26459a4fa 100644 --- a/HPL2/core/sources/graphics/PostEffect_ImageTrail.cpp +++ b/HPL2/core/sources/graphics/PostEffect_ImageTrail.cpp @@ -66,7 +66,7 @@ namespace hpl { cPostEffect_ImageTrail::cPostEffect_ImageTrail(cGraphics* apGraphics, cResources* apResources, iPostEffectType* apType) : iPostEffect(apGraphics, apResources, apType) { m_boundImageTrailData = UniqueViewportData([&](cViewport& viewport) { - auto desc = ImageDescriptor::CreateTexture2D(viewport.GetSize().x / 4.0f, viewport.GetSize().y/ 4.0f , false, bgfx::TextureFormat::Enum::RGBA8); + auto desc = ImageDescriptor::CreateTexture2D(viewport.GetSize().x, viewport.GetSize().y , false, bgfx::TextureFormat::Enum::RGBA8); desc.m_configuration.m_rt = RTType::RT_Write; auto image = std::make_shared(); image->Initialize(desc); @@ -103,7 +103,7 @@ namespace hpl { void cPostEffect_ImageTrail::RenderEffect( cPostEffectComposite& compositor, cViewport& viewport, GraphicsContext& context, Image& input, RenderTarget& target) { cVector2l vRenderTargetSize = viewport.GetSize(); - auto& imageTrailData = m_boundImageTrailData.resolve(viewport); + auto& imageTrailData = m_boundImageTrailData.resolve(viewport); GraphicsContext::LayoutStream layoutStream; diff --git a/HPL2/core/sources/graphics/Renderer.cpp b/HPL2/core/sources/graphics/Renderer.cpp index d9d405380..451bbade9 100644 --- a/HPL2/core/sources/graphics/Renderer.cpp +++ b/HPL2/core/sources/graphics/Renderer.cpp @@ -114,6 +114,39 @@ namespace hpl } return true; } + + void RenderableMaterialIter( + iRenderer* renderer, + std::span iter, + cViewport& viewport, + eMaterialRenderMode mode, + std::function handler) { + for (auto& obj : iter) + { + GraphicsContext::LayoutStream layoutStream; + GraphicsContext::ShaderProgram shaderProgram; + + cMaterial* pMaterial = obj->GetMaterial(); + iMaterialType* materialType = pMaterial->GetType(); + // iGpuProgram* program = pMaterial->GetProgram(0, mode); + iVertexBuffer* vertexBuffer = obj->GetVertexBuffer(); + if (vertexBuffer == nullptr || materialType == nullptr) + { + continue; + } + vertexBuffer->GetLayoutStream(layoutStream); + materialType->ResolveShaderProgram( + mode, + viewport, + pMaterial, + obj, + renderer, + [&](GraphicsContext::ShaderProgram& program) + { + handler(obj, layoutStream, program); + }); + } + } } // namespace rendering::detail bool cRendererNodeSortFunc::operator()(const iRenderableContainerNode* apNodeA, const iRenderableContainerNode* apNodeB) const @@ -455,8 +488,7 @@ namespace hpl bgfx::destroy(m_nullShader); } - DestroyShadowMaps(); - + if (mpShapeBox) hplDelete(mpShapeBox); @@ -723,14 +755,6 @@ namespace hpl return bValid ? false : true; } - //----------------------------------------------------------------------- - - void iRenderer::DestroyShadowMaps() - { - } - - //----------------------------------------------------------------------- - void iRenderer::RenderZObject(GraphicsContext& context, iRenderable* apObject, cFrustum* apCustomFrustum) { } @@ -1474,36 +1498,6 @@ namespace hpl static cFrustum* gpTempLightFrustum = NULL; - bool iRenderer::RenderShadowCasterCHC(iRenderable* apObject) - { - cMaterial* pMaterial = apObject->GetMaterial(); - - // Check so it is a solid object - if (pMaterial == NULL || pMaterial->GetType()->IsTranslucent()) - { - return false; - } - - // Check so it affects the view frustum - if (CheckShadowCasterContributesToView(apObject) == false) - return false; - - // mvShadowCasters.push_back(apObject); //Debug. Only to see what object are rendered. - - // Render the object - // RenderShadowCaster(apObject,gpTempLightFrustum); - - return true; - } - - //----------------------------------------------------------------------- - - void iRenderer::RenderShadowCaster(iRenderable* apObject, cFrustum* apLightFrustum) - { - GraphicsContext contx; - RenderZObject(contx, apObject, apLightFrustum); - } - static bool SortFunc_OcclusionObject(cOcclusionQueryObject* apObjectA, cOcclusionQueryObject* apObjectB) { ////////////////////////// diff --git a/HPL2/core/sources/graphics/RendererDeferred.cpp b/HPL2/core/sources/graphics/RendererDeferred.cpp index c9ab771be..4944b9136 100644 --- a/HPL2/core/sources/graphics/RendererDeferred.cpp +++ b/HPL2/core/sources/graphics/RendererDeferred.cpp @@ -22,6 +22,7 @@ #include "bgfx/bgfx.h" #include "engine/Event.h" #include "engine/Interface.h" +#include "graphics/ImmediateDrawBatch.h" #include "scene/Viewport.h" #include "windowing/NativeWindow.h" #include @@ -359,7 +360,7 @@ namespace hpl { ///////////////////////// //Shadow textures - DestroyShadowMaps(); + // DestroyShadowMaps(); // if(mpShadowJitterTexture) mpGraphics->DestroyTexture(mpShadowJitterTexture); @@ -543,33 +544,6 @@ namespace hpl { context.Submit(view, drawRequest); } - void cRendererDeferred::RenderIlluminationPass(GraphicsContext& context, cViewport& viewport, RenderTarget& rt) { - if(!mpCurrentRenderList->ArrayHasObjects(eRenderListType_Illumination)) { - return; - } - auto& sharedData = m_boundViewportData.resolve(viewport); - - GraphicsContext::ViewConfiguration viewConfig {rt}; - viewConfig.m_projection = mpCurrentFrustum->GetProjectionMatrix().GetTranspose(); - viewConfig.m_view = mpCurrentFrustum->GetViewMatrix().GetTranspose(); - viewConfig.m_viewRect = cRect2l(0, 0, sharedData.m_size.x, sharedData.m_size.y); - bgfx::ViewId view = context.StartPass("RenderIllumination", viewConfig); - RenderableHelper(eRenderListType_Illumination, viewport, eMaterialRenderMode_Illumination, [&](iRenderable* obj, GraphicsContext::LayoutStream& layoutInput, GraphicsContext::ShaderProgram& shaderInput) { - shaderInput.m_configuration.m_depthTest = DepthTest::Equal; - shaderInput.m_configuration.m_write = Write::RGBA; - - shaderInput.m_configuration.m_rgbBlendFunc = CreateBlendFunction(BlendOperator::Add, BlendOperand::One, BlendOperand::One); - shaderInput.m_configuration.m_alphaBlendFunc = CreateBlendFunction(BlendOperator::Add, BlendOperand::One, BlendOperand::One); - - // shaderInput.m_projection = mpCurrentFrustum->GetProjectionMatrix().GetTranspose(); - // shaderInput.m_view = mpCurrentFrustum->GetViewMatrix().GetTranspose(); - shaderInput.m_modelTransform = obj->GetModelMatrixPtr() ? obj->GetModelMatrixPtr()->GetTranspose() : cMatrixf::Identity.GetTranspose(); - - GraphicsContext::DrawRequest drawRequest {layoutInput, shaderInput}; - context.Submit(view, drawRequest); - }); - } - void cRendererDeferred::RenderEdgeSmoothPass(GraphicsContext& context, cViewport& viewport, RenderTarget& rt) { GraphicsContext::ViewConfiguration viewConfig {m_edgeSmooth_LinearDepth}; @@ -604,7 +578,7 @@ namespace hpl { viewConfig.m_view = mpCurrentFrustum->GetViewMatrix().GetTranspose(); viewConfig.m_viewRect = {0, 0, sharedData.m_size.x, sharedData.m_size.y}; auto view = context.StartPass("Diffuse", viewConfig); - RenderableHelper(eRenderListType_Diffuse, viewport, eMaterialRenderMode_Diffuse, [&](iRenderable* obj, GraphicsContext::LayoutStream& layoutInput, GraphicsContext::ShaderProgram& shaderInput) { + rendering::detail::RenderableMaterialIter(this, mpCurrentRenderList->GetRenderableItems(eRenderListType_Diffuse), viewport, eMaterialRenderMode_Diffuse, [&](iRenderable* obj, GraphicsContext::LayoutStream& layoutInput, GraphicsContext::ShaderProgram& shaderInput) { shaderInput.m_configuration.m_depthTest = DepthTest::LessEqual; shaderInput.m_configuration.m_write = Write::RGBA; shaderInput.m_configuration.m_cull = Cull::CounterClockwise; @@ -617,35 +591,6 @@ namespace hpl { }); } - void cRendererDeferred::RenderDecalPass(GraphicsContext& context, cViewport& viewport, RenderTarget& rt) { - BX_ASSERT(rt.IsValid(), "Invalid render target"); - BX_ASSERT(rt.GetImages().size() >= 1, "expected atleast 1 image Color(0)"); - if(!mpCurrentRenderList->ArrayHasObjects(eRenderListType_Decal)) { - return; - } - auto& sharedData = m_boundViewportData.resolve(viewport); - - GraphicsContext::ViewConfiguration viewConfig {rt}; - viewConfig.m_projection = mpCurrentFrustum->GetProjectionMatrix().GetTranspose(); - viewConfig.m_view = mpCurrentFrustum->GetViewMatrix().GetTranspose(); - viewConfig.m_viewRect = {0, 0, sharedData.m_size.x, sharedData.m_size.y}; - auto view = context.StartPass("RenderDecals", viewConfig); - RenderableHelper(eRenderListType_Decal, viewport, eMaterialRenderMode_Diffuse, [&](iRenderable* obj, GraphicsContext::LayoutStream& layoutInput, GraphicsContext::ShaderProgram& shaderInput) { - shaderInput.m_configuration.m_depthTest = DepthTest::LessEqual; - shaderInput.m_configuration.m_write = Write::RGBA; - - cMaterial *pMaterial = obj->GetMaterial(); - shaderInput.m_configuration.m_rgbBlendFunc = CreateFromMaterialBlendMode(pMaterial->GetBlendMode()); - shaderInput.m_configuration.m_alphaBlendFunc = CreateFromMaterialBlendMode(pMaterial->GetBlendMode()); - - shaderInput.m_modelTransform = obj->GetModelMatrixPtr() ? obj->GetModelMatrixPtr()->GetTranspose() : cMatrixf::Identity.GetTranspose(); - - GraphicsContext::DrawRequest drawRequest {layoutInput, shaderInput}; - context.Submit(view, drawRequest); - }); - } - - void rendering::detail::RenderZPassObject(bgfx::ViewId view, GraphicsContext& context, cViewport& viewport, iRenderer* renderer, iRenderable* object, Cull cull) { eMaterialRenderMode renderMode = object->GetCoverageAmount() >= 1 ? eMaterialRenderMode_Z : eMaterialRenderMode_Z_Dissolve; cMaterial *pMaterial = object->GetMaterial(); @@ -656,7 +601,6 @@ namespace hpl { } GraphicsContext::LayoutStream layoutInput; - // GraphicsContext::ShaderProgram shaderInput; vertexBuffer->GetLayoutStream(layoutInput); materialType->ResolveShaderProgram(renderMode, viewport, pMaterial, object, renderer, [&](GraphicsContext::ShaderProgram& shaderInput) { shaderInput.m_configuration.m_write = Write::Depth; @@ -833,6 +777,9 @@ namespace hpl { mpCurrentRenderList->Setup(mfCurrentFrameTime,mpCurrentFrustum); + const cMatrixf frustumView = mpCurrentFrustum->GetViewMatrix().GetTranspose(); + const cMatrixf frustumProj = mpCurrentFrustum->GetProjectionMatrix().GetTranspose(); + //Setup far plane coordinates m_farPlane = mpCurrentFrustum->GetFarPlane(); m_farTop = -tan(mpCurrentFrustum->GetFOV()*0.5f) * m_farPlane; @@ -843,7 +790,7 @@ namespace hpl { cRendererCallbackFunctions handler(context, viewport, this); auto& sharedData = m_boundViewportData.resolve(viewport); - + [&]{ GraphicsContext::ViewConfiguration viewConfig {sharedData.m_gBuffer_full}; viewConfig.m_viewRect = {0, 0, sharedData.m_size.x, sharedData.m_size.y}; @@ -928,27 +875,97 @@ namespace hpl { // Render GBuffer to m_gBuffer_full old method is RenderGbuffer(context); RenderDiffusePass(context, viewport, sharedData.m_gBuffer_full); - RenderDecalPass(context, viewport, sharedData.m_gBuffer_colorAndDepth); + // ------------------------------------------------------------------------------------ + // Render Decal Pass render to color and depth + // ------------------------------------------------------------------------------------ + ([&]() { + BX_ASSERT(sharedData.m_gBuffer_colorAndDepth.IsValid(), "Invalid render target"); + BX_ASSERT(sharedData.m_gBuffer_colorAndDepth.GetImages().size() >= 1, "expected atleast 1 image Color(0)"); + auto decalSpan = mpCurrentRenderList->GetRenderableItems(eRenderListType_Decal); + if(decalSpan.empty()) { + return; + } + + GraphicsContext::ViewConfiguration viewConfig {sharedData.m_gBuffer_colorAndDepth}; + viewConfig.m_projection = mpCurrentFrustum->GetProjectionMatrix().GetTranspose(); + viewConfig.m_view = mpCurrentFrustum->GetViewMatrix().GetTranspose(); + viewConfig.m_viewRect = {0, 0, sharedData.m_size.x, sharedData.m_size.y}; + auto view = context.StartPass("RenderDecals", viewConfig); + rendering::detail::RenderableMaterialIter(this, + decalSpan, + viewport, + eMaterialRenderMode_Diffuse, + [&](iRenderable* obj, GraphicsContext::LayoutStream& layoutInput, GraphicsContext::ShaderProgram& shaderInput) { + shaderInput.m_configuration.m_depthTest = DepthTest::LessEqual; + shaderInput.m_configuration.m_write = Write::RGBA; + + cMaterial *pMaterial = obj->GetMaterial(); + shaderInput.m_configuration.m_rgbBlendFunc = CreateFromMaterialBlendMode(pMaterial->GetBlendMode()); + shaderInput.m_configuration.m_alphaBlendFunc = CreateFromMaterialBlendMode(pMaterial->GetBlendMode()); + shaderInput.m_modelTransform = obj->GetModelMatrixPtr() ? obj->GetModelMatrixPtr()->GetTranspose() : cMatrixf::Identity.GetTranspose(); + + GraphicsContext::DrawRequest drawRequest {layoutInput, shaderInput}; + context.Submit(view, drawRequest); + }); + })(); + + RunCallback(eRendererMessage_PostGBuffer, handler); RenderLightPass(context, viewport, sharedData.m_output_target); - // render illumination into gbuffer color RenderIllumination - RenderIlluminationPass(context, viewport, sharedData.m_output_target); + // ------------------------------------------------------------------------ + // Render Illumination Pass --> renders to output target + // ------------------------------------------------------------------------ + ([&]() { + auto illuminationSpan = mpCurrentRenderList->GetRenderableItems(eRenderListType_Illumination); + if(illuminationSpan.empty()) { + return; + } + + GraphicsContext::ViewConfiguration viewConfig {sharedData.m_output_target}; + viewConfig.m_projection = mpCurrentFrustum->GetProjectionMatrix().GetTranspose(); + viewConfig.m_view = mpCurrentFrustum->GetViewMatrix().GetTranspose(); + viewConfig.m_viewRect = cRect2l(0, 0, sharedData.m_size.x, sharedData.m_size.y); + bgfx::ViewId view = context.StartPass("RenderIllumination", viewConfig); + rendering::detail::RenderableMaterialIter(this, + illuminationSpan, + viewport, + eMaterialRenderMode_Illumination, [&](iRenderable* obj, GraphicsContext::LayoutStream& layoutInput, GraphicsContext::ShaderProgram& shaderInput) { + shaderInput.m_configuration.m_depthTest = DepthTest::Equal; + shaderInput.m_configuration.m_write = Write::RGBA; + + shaderInput.m_configuration.m_rgbBlendFunc = CreateBlendFunction(BlendOperator::Add, BlendOperand::One, BlendOperand::One); + shaderInput.m_configuration.m_alphaBlendFunc = CreateBlendFunction(BlendOperator::Add, BlendOperand::One, BlendOperand::One); + + // shaderInput.m_projection = mpCurrentFrustum->GetProjectionMatrix().GetTranspose(); + // shaderInput.m_view = mpCurrentFrustum->GetViewMatrix().GetTranspose(); + shaderInput.m_modelTransform = obj->GetModelMatrixPtr() ? obj->GetModelMatrixPtr()->GetTranspose() : cMatrixf::Identity.GetTranspose(); + + GraphicsContext::DrawRequest drawRequest {layoutInput, shaderInput}; + context.Submit(view, drawRequest); + }); + })(); + // TODO: MP need to implement this RenderFogPass(context, viewport, sharedData.m_output_target); if(mpCurrentWorld->GetFogActive()) { RenderFullScreenFogPass(context, viewport, sharedData.m_output_target); } - - { - cViewport::PostSolidDrawPayload event; - event.m_frustum = mpCurrentFrustum; - event.m_context = &context; - event.m_outputTarget = &sharedData.m_output_target; - viewport.SignalDraw(event); - } + + // notify post draw listeners + ImmediateDrawBatch postSolidBatch(context, sharedData.m_output_target, frustumView, frustumProj); + cViewport::PostSolidDrawPacket postSolidEvent = cViewport::PostSolidDrawPacket({ + .m_frustum = mpCurrentFrustum, + .m_context = &context, + .m_outputTarget = &sharedData.m_output_target, + .m_viewport = &viewport, + .m_renderSettings = mpCurrentSettings, + .m_immediateDrawBatch = &postSolidBatch, + }); + viewport.SignalDraw(postSolidEvent); + postSolidBatch.flush(); RunCallback(eRendererMessage_PostSolid, handler); // not going to even try. @@ -956,20 +973,22 @@ namespace hpl { RenderTranslucentPass(context, viewport, sharedData.m_output_target); RunCallback(eRendererMessage_PostTranslucent, handler); - { - cViewport::PostTranslucenceDrawPayload event; - cMatrixf view = mpCurrentFrustum->GetViewMatrix().GetTranspose(); - cMatrixf proj = mpCurrentFrustum->GetProjectionMatrix().GetTranspose(); - - event.m_frustum = mpCurrentFrustum; - event.m_context = &context; - event.m_outputTarget = &sharedData.m_output_target; - viewport.SignalDraw(event); - } + + ImmediateDrawBatch postTransBatch(context, sharedData.m_output_target, frustumView, frustumProj); + cViewport::PostTranslucenceDrawPacket translucenceEvent = cViewport::PostTranslucenceDrawPacket({ + .m_frustum = mpCurrentFrustum, + .m_context = &context, + .m_outputTarget = &sharedData.m_output_target, + .m_viewport = &viewport, + .m_renderSettings = mpCurrentSettings, + .m_immediateDrawBatch = &postTransBatch, + }); + viewport.SignalDraw(translucenceEvent); + postTransBatch.flush(); + } - void cRendererDeferred::RenderShadowPass(GraphicsContext& context, cViewport& viewport, const cDeferredLight& apLightData, RenderTarget& rt) { BX_ASSERT(apLightData.mpLight->GetLightType() == eLightType_Spot, "Only spot lights are supported for shadow rendering") cVector2l size = rt.GetImage()->GetImageSize(); diff --git a/HPL2/core/sources/resources/TextureManager.cpp b/HPL2/core/sources/resources/TextureManager.cpp index 3d82b38a8..bbe416a25 100644 --- a/HPL2/core/sources/resources/TextureManager.cpp +++ b/HPL2/core/sources/resources/TextureManager.cpp @@ -113,7 +113,8 @@ namespace hpl { { auto* resource = new Image(asName, path); ImageDescriptor desc = ImageDescriptor::CreateFromBitmap(*pBmp); - auto* image = new Image(); + desc.m_name = asName.c_str(); + // auto* image = new Image(); desc.m_configuration.m_UWrap = options.m_UWrap; desc.m_configuration.m_VWrap = options.m_VWrap; @@ -124,8 +125,9 @@ namespace hpl { desc.m_configuration.m_magFilter = options.m_magFilter; desc.m_configuration.m_mipFilter = options.m_mipFilter; - auto data = pBmp->GetData(0, 0); - resource->Initialize(desc, bgfx::copy(data->mpData, data->mlSize)); + // auto data = pBmp->GetData(0, 0); + Image::InitializeFromBitmap(*resource, *pBmp, desc); + // resource->Initialize(desc, bgfx::copy(data->mpData, data->mlSize)); return resource; }); } @@ -140,7 +142,7 @@ namespace hpl { auto* resource = new Image(asName, path); ImageDescriptor desc = ImageDescriptor::CreateFromBitmap(*pBmp); desc.m_name = asName.c_str(); - auto* image = new Image(); + // auto* image = new Image(); desc.m_configuration.m_UWrap = options.m_UWrap; desc.m_configuration.m_VWrap = options.m_VWrap; @@ -151,7 +153,7 @@ namespace hpl { desc.m_configuration.m_magFilter = options.m_magFilter; desc.m_configuration.m_mipFilter = options.m_mipFilter; - auto data = pBmp->GetData(0, 0); + // auto data = pBmp->GetData(0, 0); Image::InitializeFromBitmap(*resource, *pBmp, desc); return resource; }); @@ -169,7 +171,7 @@ namespace hpl { auto* resource = new Image(asName, path); ImageDescriptor desc = ImageDescriptor::CreateFromBitmap(*pBmp); desc.m_name = asName.c_str(); - auto* image = new Image(); + // auto* image = new Image(); desc.m_configuration.m_UWrap = options.m_UWrap; desc.m_configuration.m_VWrap = options.m_VWrap; @@ -181,7 +183,7 @@ namespace hpl { desc.m_configuration.m_mipFilter = options.m_mipFilter; desc.m_isCubeMap = true; - auto data = pBmp->GetData(0, 0); + // auto data = pBmp->GetData(0, 0); Image::InitializeFromBitmap(*resource, *pBmp, desc); return resource; }); diff --git a/HPL2/core/sources/system/Bootstrap.cpp b/HPL2/core/sources/system/Bootstrap.cpp index 1a11e4869..b788f8085 100644 --- a/HPL2/core/sources/system/Bootstrap.cpp +++ b/HPL2/core/sources/system/Bootstrap.cpp @@ -54,7 +54,6 @@ namespace hpl { m_window.Process(); bgfx::renderFrame(); } - } void Bootstrap::Initialize(BootstrapConfiguration configuration) { diff --git a/HPL2/core/sources/system/Container.cpp b/HPL2/core/sources/system/Container.cpp deleted file mode 100644 index 362c1760d..000000000 --- a/HPL2/core/sources/system/Container.cpp +++ /dev/null @@ -1,48 +0,0 @@ -/* - * Copyright © 2009-2020 Frictional Games - * - * This file is part of Amnesia: The Dark Descent. - * - * Amnesia: The Dark Descent is free software: you can redistribute it and/or modify - * it under the terms of the GNU General Public License as published by - * the Free Software Foundation, either version 3 of the License, or - * (at your option) any later version. - - * Amnesia: The Dark Descent is distributed in the hope that it will be useful, - * but WITHOUT ANY WARRANTY; without even the implied warranty of - * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the - * GNU General Public License for more details. - * - * You should have received a copy of the GNU General Public License - * along with Amnesia: The Dark Descent. If not, see . - */ - -#include "system/Container.h" - -namespace hpl { - - ////////////////////////////////////////////////////////////////////////// - // CONSTRUCTORS - ////////////////////////////////////////////////////////////////////////// - - //----------------------------------------------------------------------- - - //----------------------------------------------------------------------- - - ////////////////////////////////////////////////////////////////////////// - // PUBLIC METHODS - ////////////////////////////////////////////////////////////////////////// - - //----------------------------------------------------------------------- - - //----------------------------------------------------------------------- - - ////////////////////////////////////////////////////////////////////////// - // PRIVATE METHODS - ////////////////////////////////////////////////////////////////////////// - - //----------------------------------------------------------------------- - - //----------------------------------------------------------------------- - -} diff --git a/HPL2/core/sources/system/Platform.cpp b/HPL2/core/sources/system/Platform.cpp index 05022f247..205bd7bf0 100644 --- a/HPL2/core/sources/system/Platform.cpp +++ b/HPL2/core/sources/system/Platform.cpp @@ -28,11 +28,6 @@ namespace hpl { - //--------------------------------------------------------------- - - ///////////////////////////////////////////////////////////////// - // Predicate for sorting video mode lists - bool VideoComp::operator() (const cVideoMode& aVM1, const cVideoMode& aVM2) const { //Log("Comparing video mode (1) %dx%d/%d-%d to (2) %dx%d/%d-%d\n", aVM1.mvScreenSize.x, aVM1.mvScreenSize.y, diff --git a/HPL2/tools/editors/common/EditorWindowViewport.cpp b/HPL2/tools/editors/common/EditorWindowViewport.cpp index bfe81c2e7..17bf315f8 100644 --- a/HPL2/tools/editors/common/EditorWindowViewport.cpp +++ b/HPL2/tools/editors/common/EditorWindowViewport.cpp @@ -39,18 +39,19 @@ cEditorWindowViewport::cEditorWindowViewport(iEditorBase* apEditor, apEditor->GetEditorWorld()->GetWorld()) { - m_postSolidDraw = cViewport::PostSolidDraw::Handler([&](cViewport::PostSolidDrawPayload& payload) { - if(mpEditor == nullptr) return; - - cMatrixf view = payload.m_frustum->GetViewMatrix().GetTranspose(); - cMatrixf proj = payload.m_frustum->GetProjectionMatrix().GetTranspose(); - ImmediateDrawBatch batch(*payload.m_context, *payload.m_outputTarget,view, proj); + m_postSolidDraw = cViewport::PostSolidDraw::Handler([&](cViewport::PostSolidDrawPacket& payload) { + if(mpEditor == nullptr) { + return; + } - this->mpEditor->GetEditorWorld()->GetSurfacePicker()->DrawDebug(&batch); + + this->mpEditor->GetEditorWorld()->GetSurfacePicker()->DrawDebug(payload.m_immediateDrawBatch); if(GetDrawGrid()) { cEditorGrid* pGrid = GetGrid(); - if(pGrid) pGrid->Draw(&batch, GetGridCenter()); + if(pGrid) { + pGrid->Draw(payload.m_immediateDrawBatch, GetGridCenter()); + } } if(GetDrawAxes()) { @@ -64,16 +65,16 @@ cEditorWindowViewport::cEditorWindowViewport(iEditorBase* apEditor, cVector3f vAxisEnd = 0; vAxisStart.v[i] = vCenter.v[i] -1000.0f; vAxisEnd.v[i] = vCenter.v[i] +1000.0f; - batch.DebugDrawLine(vAxisStart, vAxisEnd, col); + payload.m_immediateDrawBatch->DebugDrawLine(vAxisStart, vAxisEnd, col); } } tEditorClipPlaneVec& vClipPlanes = mpEditor->GetEditorWorld()->GetClipPlanes(); for(int i=0;i<(int)vClipPlanes.size();++i) { - vClipPlanes[i]->Draw(&batch, 0); + vClipPlanes[i]->Draw(payload.m_immediateDrawBatch, 0); } - batch.DebugDrawSphere(GetVCamera()->GetTargetPosition(),0.1f, cColor(0,1,1,1)); + payload.m_immediateDrawBatch->DebugDrawSphere(GetVCamera()->GetTargetPosition(),0.1f, cColor(0,1,1,1)); const cVector3f& vRefMousePos = GetVCamera()->GetTrackRefMousePos(); const cVector3f& vMouseNewPos = GetVCamera()->GetTrackNewMousePos(); @@ -87,34 +88,31 @@ cEditorWindowViewport::cEditorWindowViewport(iEditorBase* apEditor, cVector3f& vGridPos = vDebugGridPos; cVector3f& vSnapPos = vDebugSnappedGridPos; - batch.DebugDrawLine(vPos1,vPos2,cColor(0,0,1,1)); - batch.DebugDrawSphere(vPos1, 0.01f, cColor(0,1,0,1)); - batch.DebugDrawSphere(vPos2, 0.2f, cColor(0,1,0,1)); - batch.DebugDrawSphere(vGridPos, 0.3f, cColor(1,0,0,1)); + payload.m_immediateDrawBatch->DebugDrawLine(vPos1,vPos2,cColor(0,0,1,1)); + payload.m_immediateDrawBatch->DebugDrawSphere(vPos1, 0.01f, cColor(0,1,0,1)); + payload.m_immediateDrawBatch->DebugDrawSphere(vPos2, 0.2f, cColor(0,1,0,1)); + payload.m_immediateDrawBatch->DebugDrawSphere(vGridPos, 0.3f, cColor(1,0,0,1)); } - batch.flush(); }); - m_postTranslucenceDraw = cViewport::PostTranslucenceDraw::Handler([&](cViewport::PostTranslucenceDrawPayload& payload) { - if(mpEditor == nullptr) return; - - cMatrixf view = payload.m_frustum->GetViewMatrix().GetTranspose(); - cMatrixf proj = payload.m_frustum->GetProjectionMatrix().GetTranspose(); - ImmediateDrawBatch batch(*payload.m_context, *payload.m_outputTarget,view, proj); - + m_postTranslucenceDraw = cViewport::PostTranslucenceDraw::Handler([&](cViewport::PostTranslucenceDrawPacket& payload) { + if(mpEditor == nullptr) { + return; + } + cVector3f& vMousePos = mpEditor->GetPosOnGridFromMousePos(); iEditorEditMode* pEditMode = mpEditor->GetCurrentEditMode(); if(pEditMode) - pEditMode->DrawPreGrid(this, &batch, vMousePos); + pEditMode->DrawPreGrid(this, payload.m_immediateDrawBatch, vMousePos); // apFunctions->SetBlendMode(eMaterialBlendMode_None); if(pEditMode) - pEditMode->DrawPostGrid(this, &batch, vMousePos); + pEditMode->DrawPostGrid(this, payload.m_immediateDrawBatch, vMousePos); - batch.flush(); + // batch.flush(); }); mpEngineViewport->ConnectDraw(m_postTranslucenceDraw); diff --git a/HPL2/tools/editors/modeleditor/ModelEditorWindowPhysicsTest.cpp b/HPL2/tools/editors/modeleditor/ModelEditorWindowPhysicsTest.cpp index 27cee171e..772c6ca60 100644 --- a/HPL2/tools/editors/modeleditor/ModelEditorWindowPhysicsTest.cpp +++ b/HPL2/tools/editors/modeleditor/ModelEditorWindowPhysicsTest.cpp @@ -84,7 +84,7 @@ cModelEditorWindowPhysicsTest::cModelEditorWindowPhysicsTest(iEditorBase* apEdit mbViewMode = false; - m_postSolidDraw = cViewport::PostSolidDraw::Handler([&](cViewport::PostSolidDrawPayload& payload) { + m_postSolidDraw = cViewport::PostSolidDraw::Handler([&](cViewport::PostSolidDrawPacket& payload) { cMatrixf view = payload.m_frustum->GetViewMatrix().GetTranspose(); cMatrixf proj = payload.m_frustum->GetProjectionMatrix().GetTranspose(); hpl::ImmediateDrawBatch batch(*payload.m_context, *payload.m_outputTarget,view, proj); diff --git a/HPL2/tools/mapview/MapView.cpp b/HPL2/tools/mapview/MapView.cpp index 41665b9be..9764ddf74 100644 --- a/HPL2/tools/mapview/MapView.cpp +++ b/HPL2/tools/mapview/MapView.cpp @@ -289,7 +289,7 @@ class cSimpleUpdate : public iUpdateable mpAmbientBox = NULL; } - m_postSolidDraw = cViewport::PostSolidDraw::Handler([&](cViewport::PostSolidDrawPayload& payload) { + m_postSolidDraw = cViewport::PostSolidDraw::Handler([&](cViewport::PostSolidDrawPacket& payload) { // apFunctions->SetDepthTest(false); // apFunctions->SetDepthWrite(false); @@ -547,7 +547,7 @@ class cSimpleUpdate : public iUpdateable }); - m_postTestSolidDraw = cViewport::PostSolidDraw::Handler([&](cViewport::PostSolidDrawPayload& payload) { + m_postTestSolidDraw = cViewport::PostSolidDraw::Handler([&](cViewport::PostSolidDrawPacket& payload) { cMatrixf view = payload.m_frustum->GetViewMatrix().GetTranspose(); cMatrixf proj = payload.m_frustum->GetProjectionMatrix().GetTranspose(); ImmediateDrawBatch batch(*payload.m_context, *payload.m_outputTarget,view, proj); diff --git a/HPL2/tools/modelview/ModelView.cpp b/HPL2/tools/modelview/ModelView.cpp index 538c85a25..c6fccb4b6 100644 --- a/HPL2/tools/modelview/ModelView.cpp +++ b/HPL2/tools/modelview/ModelView.cpp @@ -197,7 +197,7 @@ class cSimpleUpdate : public iUpdateable mpWorld->SetSkyBoxColor(cColor(0.0f, 1.0f)); mpWorld->SetSkyBoxActive(true); - m_postSolidDraw = cViewport::PostSolidDraw::Handler([&](cViewport::PostSolidDrawPayload& payload) { + m_postSolidDraw = cViewport::PostSolidDraw::Handler([&](cViewport::PostSolidDrawPacket& payload) { cMatrixf view = payload.m_frustum->GetViewMatrix().GetTranspose(); cMatrixf proj = payload.m_frustum->GetProjectionMatrix().GetTranspose(); diff --git a/HPL2/tools/particleview/ParticleView.cpp b/HPL2/tools/particleview/ParticleView.cpp index 11b1d6fb7..e03265e7f 100644 --- a/HPL2/tools/particleview/ParticleView.cpp +++ b/HPL2/tools/particleview/ParticleView.cpp @@ -95,7 +95,7 @@ class cSimpleUpdate : public iUpdateable //////////////////////////////// // Render callback - m_postSolidDraw = cViewport::PostSolidDraw::Handler([&](hpl::cViewport::PostSolidDrawPayload& payload) { + m_postSolidDraw = cViewport::PostSolidDraw::Handler([&](hpl::cViewport::PostSolidDrawPacket& payload) { cMatrixf view = payload.m_frustum->GetViewMatrix().GetTranspose(); cMatrixf proj = payload.m_frustum->GetProjectionMatrix().GetTranspose(); ImmediateDrawBatch batch(*payload.m_context, *payload.m_outputTarget,view, proj); diff --git a/amnesia/src/game/LuxEffectRenderer.cpp b/amnesia/src/game/LuxEffectRenderer.cpp index 6a353f6aa..4d1e37a1d 100644 --- a/amnesia/src/game/LuxEffectRenderer.cpp +++ b/amnesia/src/game/LuxEffectRenderer.cpp @@ -165,24 +165,299 @@ void cLuxEffectRenderer::Update(float afTimeStep) //----------------------------------------------------------------------- -void cLuxEffectRenderer::RenderSolid(cRendererCallbackFunctions* apFunctions) +void cLuxEffectRenderer::RenderSolid(cViewport::PostSolidDrawPacket& input) { - if (apFunctions->GetSettings()->mbIsReflection) - return; } -void cLuxEffectRenderer::RenderTrans(cRendererCallbackFunctions* apFunctions) +void cLuxEffectRenderer::RenderTrans(cViewport::PostTranslucenceDrawPacket& input) { ///////////////////////////////////// // Normal and Reflection - RenderFlashObjects(apFunctions); - RenderEnemyGlow(apFunctions); + // Render Flashing Objects + auto graphicsContext = input.m_context; + auto currentFrustum = input.m_frustum; + // render Flashing objects --------------------------------------------------------------------------------------------------- + ([&](){ + if (mvFlashObjects.empty()) + return; + + auto& postEffectData = m_boundPostEffectData.resolve(*input.m_viewport); + // auto& graphicsContext = apFunctions->GetGraphicsContext(); + if(!postEffectData.m_outputImage || + !postEffectData.m_gBufferDepthStencil) { + return; + } + + // auto currentFrustum = apFunctions->GetFrustum(); + float fGlobalAlpha = (0.5f + mFlashOscill.val * 0.5f); + auto imageSize = postEffectData.m_outputImage->GetImageSize(); + + GraphicsContext::ViewConfiguration viewConfiguration {postEffectData.m_outputTarget}; + viewConfiguration.m_viewRect = cRect2l(0, 0, imageSize.x, imageSize.y); + viewConfiguration.m_projection = currentFrustum->GetProjectionMatrix().GetTranspose(); + viewConfiguration.m_view = currentFrustum->GetViewMatrix().GetTranspose(); + const auto view = graphicsContext->StartPass("Render Flash Object", viewConfiguration); + for (auto& flashObject : mvFlashObjects) + { + auto* pObject = flashObject.mpObject; + if (!pObject->CollidesWithFrustum(currentFrustum)) + { + continue; + } - ///////////////////////////////////// - // Only Normal - if (apFunctions->GetSettings()->mbIsReflection == false) - { - RenderOutline(apFunctions); + GraphicsContext::LayoutStream layoutInput; + GraphicsContext::ShaderProgram shaderInput; + struct + { + float m_colorMul; + float pad[3]; + } params = { 0 }; + params.m_colorMul = flashObject.mfAlpha * fGlobalAlpha; + shaderInput.m_handle = m_objectFlashProgram; + + shaderInput.m_uniforms.push_back({ m_u_param, ¶ms }); + shaderInput.m_textures.push_back({ m_s_diffuseMap, pObject->GetMaterial()->GetImage(eMaterialTexture_Diffuse)->GetHandle(), 0 }); + + shaderInput.m_configuration.m_write = Write::RGBA; + shaderInput.m_configuration.m_depthTest = DepthTest::LessEqual; + shaderInput.m_configuration.m_alphaBlendFunc = CreateBlendFunction(BlendOperator::Add, BlendOperand::One, BlendOperand::One); + shaderInput.m_configuration.m_rgbBlendFunc = CreateBlendFunction(BlendOperator::Add, BlendOperand::One, BlendOperand::One); + + // shaderInput.m_projection = currentFrustum->GetProjectionMatrix().GetTranspose(); + // shaderInput.m_view = currentFrustum->GetViewMatrix().GetTranspose(); + shaderInput.m_modelTransform = pObject->GetModelMatrixPtr() ? pObject->GetModelMatrixPtr()->GetTranspose() : cMatrixf::Identity; + pObject->GetVertexBuffer()->GetLayoutStream(layoutInput); + + GraphicsContext::DrawRequest drawRequest{ layoutInput, shaderInput }; + for (int i = 0; i < 2; ++i) + { + input.m_context->Submit(view, drawRequest); + } + } + })(); + // Render Enemy Glow --------------------------------------------------------------------------------------------------- + ([&] () { + if (mvEnemyGlowObjects.empty()) { + return; + } + + auto& postEffectData = m_boundPostEffectData.resolve(*input.m_viewport); + if(!postEffectData.m_outputImage || + !postEffectData.m_gBufferDepthStencil) { + return; + } + auto imageSize = postEffectData.m_outputImage->GetImageSize(); + + GraphicsContext::ViewConfiguration viewConfiguration {postEffectData.m_outputTarget}; + viewConfiguration.m_viewRect = cRect2l(0, 0, imageSize.x, imageSize.y); + viewConfiguration.m_projection = currentFrustum->GetProjectionMatrix().GetTranspose(); + viewConfiguration.m_view = currentFrustum->GetViewMatrix().GetTranspose(); + + const auto view = input.m_context->StartPass("Render Enemy Glow", viewConfiguration); + for (auto& enemyGlow : mvEnemyGlowObjects) + { + auto* pObject = enemyGlow.mpObject; + if (!pObject->CollidesWithFrustum(currentFrustum)) + { + continue; + } + GraphicsContext::LayoutStream layoutInput; + GraphicsContext::ShaderProgram shaderInput; + struct + { + float m_colorMul; + float pad[3]; + } params = { 0 }; + params.m_colorMul = enemyGlow.mfAlpha; + + shaderInput.m_handle = m_enemyGlowProgram; + + shaderInput.m_uniforms.push_back({ m_u_param, ¶ms }); + shaderInput.m_textures.push_back({ m_s_diffuseMap, pObject->GetMaterial()->GetImage(eMaterialTexture_Diffuse)->GetHandle(), 0 }); + + shaderInput.m_configuration.m_write = Write::RGBA; + shaderInput.m_configuration.m_depthTest = DepthTest::Equal; + shaderInput.m_configuration.m_alphaBlendFunc = CreateBlendFunction(BlendOperator::Add, BlendOperand::One, BlendOperand::One); + shaderInput.m_configuration.m_rgbBlendFunc = CreateBlendFunction(BlendOperator::Add, BlendOperand::One, BlendOperand::One); + + // shaderInput.m_projection = currentFrustum->GetProjectionMatrix().GetTranspose(); + // shaderInput.m_view = currentFrustum->GetViewMatrix().GetTranspose(); + shaderInput.m_modelTransform = pObject->GetModelMatrixPtr() ? pObject->GetModelMatrixPtr()->GetTranspose() : cMatrixf::Identity; + pObject->GetVertexBuffer()->GetLayoutStream(layoutInput); + + GraphicsContext::DrawRequest drawRequest{ layoutInput, shaderInput }; + input.m_context->Submit(view, drawRequest); + } + })(); + + if (input.m_renderSettings->mbIsReflection == false) { + // Render Enemy Outlines --------------------------------------------------------------------------------------------------- + ([&]() { + if (mvOutlineObjects.empty()) { + return; + } + + auto& postEffectData = m_boundPostEffectData.resolve(*input.m_viewport); + if (!postEffectData.m_outputImage || !postEffectData.m_gBufferDepthStencil) { + return; + } + auto imageSize = postEffectData.m_outputImage->GetImageSize(); + + ///////////////////////////// + // Setup vars + cGraphics* pGraphics = gpBase->mpEngine->GetGraphics(); + // cVector2l vScreenSize = pGraphics->GetLowLevel()->GetScreenSizeInt(); + + float fScaleAdd = 0.02f; + + //////////////////////////////////// + // Get entities to be rendered + // cFrustum* pFrustum = apFunctions->GetFrustum(); + absl::InlinedVector lstObjects; + for (size_t i = 0; i < mvOutlineObjects.size(); ++i) { + iRenderable* pObject = mvOutlineObjects[i]; + + if (pObject->CollidesWithFrustum(input.m_frustum)) { + lstObjects.push_back(pObject); + } + } + + //////////////////////////////////// + // Build AABB from all objects + cBoundingVolume totalBV; + cVector3f vTotalMin = 100000.0f; + cVector3f vTotalMax = -100000.0f; + for (auto& object : lstObjects) { + cBoundingVolume* pBV = object->GetBoundingVolume(); + cMath::ExpandAABB(vTotalMin, vTotalMax, pBV->GetMin(), pBV->GetMax()); + } + + // Need to scale so the outline is contained. + cVector3f vTotalSize = vTotalMax - vTotalMin; + cVector3f vTotalAdd = vTotalSize * (cVector3f(1.0f) / vTotalSize) * (fScaleAdd * 2); + + totalBV.SetLocalMinMax(vTotalMin - vTotalAdd, vTotalMax + vTotalAdd); + + // TODO: use clip rect to avoid rendering to the entire framebuffer + cRect2l clipRect; + cMath::GetClipRectFromBV(clipRect, totalBV, input.m_frustum, imageSize, -1); + + { + GraphicsContext::ViewConfiguration viewConfiguration{ postEffectData.m_outlineTarget }; + viewConfiguration.m_viewRect = { 0, 0, static_cast(imageSize.x), static_cast(imageSize.y) }; + viewConfiguration.m_clear = { 0, 1.0, 0, ClearOp::Stencil | ClearOp::Color }; + bgfx::touch(input.m_context->StartPass("Clear Outline And Stencil", viewConfiguration)); + } + + { + GraphicsContext::ViewConfiguration viewConfiguration{ postEffectData.m_outlineTarget }; + viewConfiguration.m_projection = currentFrustum->GetProjectionMatrix().GetTranspose(); + viewConfiguration.m_view = currentFrustum->GetViewMatrix().GetTranspose(); + viewConfiguration.m_viewRect = { 0, 0, static_cast(imageSize.x), static_cast(imageSize.y) }; + const auto view = input.m_context->StartPass("Render Outline Stencil", viewConfiguration); + for (auto& object : lstObjects) { + GraphicsContext::LayoutStream layoutInput; + GraphicsContext::ShaderProgram shaderInput; + struct { + float m_alpha; + float pad[3]; + } params = { 0 }; + + shaderInput.m_handle = m_alphaRejectProgram; + auto alphaImage = object->GetMaterial()->GetImage(eMaterialTexture_Alpha); + if (alphaImage) { + shaderInput.m_textures.push_back({ m_s_diffuseMap, alphaImage->GetHandle(), 0 }); + params.m_alpha = 0.5f; + } + shaderInput.m_configuration.m_depthTest = DepthTest::LessEqual; + shaderInput.m_uniforms.push_back({ m_u_param, ¶ms }); + shaderInput.m_handle = m_alphaRejectProgram; + shaderInput.m_configuration.m_frontStencilTest = CreateStencilTest( + StencilFunction::Always, StencilFail::Keep, StencilDepthFail::Keep, StencilDepthPass::Replace, 0xff, 0xff); + // shaderInput.m_projection = currentFrustum->GetProjectionMatrix().GetTranspose(); + // shaderInput.m_view = currentFrustum->GetViewMatrix().GetTranspose(); + shaderInput.m_modelTransform = + object->GetModelMatrixPtr() ? object->GetModelMatrixPtr()->GetTranspose() : cMatrixf::Identity; + object->GetVertexBuffer()->GetLayoutStream(layoutInput); + + GraphicsContext::DrawRequest drawRequest{ layoutInput, shaderInput }; + input.m_context->Submit(view, drawRequest); + } + } + + { + GraphicsContext::ViewConfiguration viewConfiguration{ postEffectData.m_outlineTarget }; + viewConfiguration.m_viewRect = { 0, 0, imageSize.x, imageSize.y }; + viewConfiguration.m_projection = currentFrustum->GetProjectionMatrix().GetTranspose(); + viewConfiguration.m_view = currentFrustum->GetViewMatrix().GetTranspose(); + const auto view = input.m_context->StartPass("Render Outline", viewConfiguration); + for (auto& object : lstObjects) { + GraphicsContext::LayoutStream layoutInput; + GraphicsContext::ShaderProgram shaderInput; + struct { + float color[3]; + float useAlpha; + } params = { { 0, 0, 0.5f }, 0 }; + + shaderInput.m_handle = m_outlineProgram; + auto alphaImage = object->GetMaterial()->GetImage(eMaterialTexture_Alpha); + if (alphaImage) { + shaderInput.m_textures.push_back({ m_s_diffuseMap, alphaImage->GetHandle(), 0 }); + params.useAlpha = 1.0f; + } + shaderInput.m_configuration.m_write = Write::RGBA; + shaderInput.m_configuration.m_depthTest = DepthTest::LessEqual; + shaderInput.m_uniforms.push_back({ m_u_param, ¶ms }); + shaderInput.m_configuration.m_frontStencilTest = CreateStencilTest( + StencilFunction::NotEqual, StencilFail::Keep, StencilDepthFail::Keep, StencilDepthPass::Keep, 0xff, 0xff); + + cBoundingVolume* pBV = object->GetBoundingVolume(); + cVector3f vLocalSize = pBV->GetLocalMax() - pBV->GetLocalMin(); + cVector3f vScale = (cVector3f(1.0f) / vLocalSize) * fScaleAdd + cVector3f(1.0f); + + cMatrixf mtxScale = cMath::MatrixMul(cMath::MatrixScale(vScale), cMath::MatrixTranslate(pBV->GetLocalCenter() * -1)); + mtxScale.SetTranslation(mtxScale.GetTranslation() + pBV->GetLocalCenter()); + + // shaderInput.m_projection = currentFrustum->GetProjectionMatrix().GetTranspose(); + // shaderInput.m_view = currentFrustum->GetViewMatrix().GetTranspose(); + shaderInput.m_modelTransform = cMath::MatrixMul(object->GetWorldMatrix(), mtxScale).GetTranspose(); + object->GetVertexBuffer()->GetLayoutStream(layoutInput); + + GraphicsContext::DrawRequest drawRequest{ layoutInput, shaderInput }; + input.m_context->Submit(view, drawRequest); + } + } + + RenderBlurPass(*input.m_context, postEffectData.m_blurTarget, *postEffectData.m_outlineTarget.GetImage()); + for (size_t i = 0; i < 2; ++i) { + RenderBlurPass(*input.m_context, postEffectData.m_blurTarget, *postEffectData.m_blurTarget[1].GetImage()); + } + + { + auto imageSize = postEffectData.m_blurTarget[1].GetImage()->GetImageSize(); + GraphicsContext::LayoutStream layoutStream; + cMatrixf projMtx; + input.m_context->ScreenSpaceQuad(layoutStream, projMtx, imageSize.x, imageSize.y); + + GraphicsContext::ViewConfiguration viewConfiguration{ postEffectData.m_outputTarget }; + viewConfiguration.m_projection = projMtx; + const auto view = input.m_context->StartPass("Additive Outline", viewConfiguration); + auto outlineOutputImage = postEffectData.m_blurTarget[1].GetImage(); + + GraphicsContext::ShaderProgram shaderProgram; + GraphicsContext::ShaderProgram program; + program.m_handle = m_copyProgram; + program.m_configuration.m_write = Write::RGBA; + // program.m_projection = projMtx; + program.m_configuration.m_alphaBlendFunc = CreateBlendFunction(BlendOperator::Add, BlendOperand::One, BlendOperand::One); + program.m_configuration.m_rgbBlendFunc = CreateBlendFunction(BlendOperator::Add, BlendOperand::One, BlendOperand::One); + + program.m_textures.push_back({ m_s_diffuseMap, outlineOutputImage->GetHandle(), 0 }); + + GraphicsContext::DrawRequest request = { layoutStream, program }; + input.m_context->Submit(view, request); + } + })(); } } @@ -212,63 +487,7 @@ void cLuxEffectRenderer::AddEnemyGlow(iRenderable* apObject, float afAlpha) void cLuxEffectRenderer::RenderFlashObjects(cRendererCallbackFunctions* apFunctions) { - if (mvFlashObjects.empty()) - return; - - - auto& postEffectData = m_boundPostEffectData.resolve(apFunctions->GetViewport()); - auto& graphicsContext = apFunctions->GetGraphicsContext(); - if(!postEffectData.m_outputImage || - !postEffectData.m_gBufferDepthStencil) { - return; - } - - auto currentFrustum = apFunctions->GetFrustum(); - float fGlobalAlpha = (0.5f + mFlashOscill.val * 0.5f); - auto imageSize = postEffectData.m_outputImage->GetImageSize(); - GraphicsContext::ViewConfiguration viewConfiguration {postEffectData.m_outputTarget}; - viewConfiguration.m_viewRect = cRect2l(0, 0, imageSize.x, imageSize.y); - viewConfiguration.m_projection = currentFrustum->GetProjectionMatrix().GetTranspose(); - viewConfiguration.m_view = currentFrustum->GetViewMatrix().GetTranspose(); - const auto view = apFunctions->GetGraphicsContext().StartPass("Render Flash Object", viewConfiguration); - for (auto& flashObject : mvFlashObjects) - { - auto* pObject = flashObject.mpObject; - if (!pObject->CollidesWithFrustum(currentFrustum)) - { - continue; - } - - GraphicsContext::LayoutStream layoutInput; - GraphicsContext::ShaderProgram shaderInput; - struct - { - float m_colorMul; - float pad[3]; - } params = { 0 }; - params.m_colorMul = flashObject.mfAlpha * fGlobalAlpha; - shaderInput.m_handle = m_objectFlashProgram; - - shaderInput.m_uniforms.push_back({ m_u_param, ¶ms }); - shaderInput.m_textures.push_back({ m_s_diffuseMap, pObject->GetMaterial()->GetImage(eMaterialTexture_Diffuse)->GetHandle(), 0 }); - - shaderInput.m_configuration.m_write = Write::RGBA; - shaderInput.m_configuration.m_depthTest = DepthTest::LessEqual; - shaderInput.m_configuration.m_alphaBlendFunc = CreateBlendFunction(BlendOperator::Add, BlendOperand::One, BlendOperand::One); - shaderInput.m_configuration.m_rgbBlendFunc = CreateBlendFunction(BlendOperator::Add, BlendOperand::One, BlendOperand::One); - - // shaderInput.m_projection = currentFrustum->GetProjectionMatrix().GetTranspose(); - // shaderInput.m_view = currentFrustum->GetViewMatrix().GetTranspose(); - shaderInput.m_modelTransform = pObject->GetModelMatrixPtr() ? pObject->GetModelMatrixPtr()->GetTranspose() : cMatrixf::Identity; - pObject->GetVertexBuffer()->GetLayoutStream(layoutInput); - - GraphicsContext::DrawRequest drawRequest{ layoutInput, shaderInput }; - for (int i = 0; i < 2; ++i) - { - graphicsContext.Submit(view, drawRequest); - } - } } //----------------------------------------------------------------------- @@ -276,240 +495,12 @@ void cLuxEffectRenderer::RenderFlashObjects(cRendererCallbackFunctions* apFuncti void cLuxEffectRenderer::RenderEnemyGlow(cRendererCallbackFunctions* apFunctions) { - if (mvEnemyGlowObjects.empty()) - return; - auto& postEffectData = m_boundPostEffectData.resolve(apFunctions->GetViewport()); - auto& graphicsContext = apFunctions->GetGraphicsContext(); - if(!postEffectData.m_outputImage || - !postEffectData.m_gBufferDepthStencil) { - return; - } - auto imageSize = postEffectData.m_outputImage->GetImageSize(); - auto currentFrustum = apFunctions->GetFrustum(); - - GraphicsContext::ViewConfiguration viewConfiguration {postEffectData.m_outputTarget}; - viewConfiguration.m_viewRect = cRect2l(0, 0, imageSize.x, imageSize.y); - viewConfiguration.m_projection = currentFrustum->GetProjectionMatrix().GetTranspose(); - viewConfiguration.m_view = currentFrustum->GetViewMatrix().GetTranspose(); - - const auto view = apFunctions->GetGraphicsContext().StartPass("Render Enemy Glow", viewConfiguration); - for (auto& enemyGlow : mvEnemyGlowObjects) - { - auto* pObject = enemyGlow.mpObject; - if (!pObject->CollidesWithFrustum(currentFrustum)) - { - continue; - } - GraphicsContext::LayoutStream layoutInput; - GraphicsContext::ShaderProgram shaderInput; - struct - { - float m_colorMul; - float pad[3]; - } params = { 0 }; - params.m_colorMul = enemyGlow.mfAlpha; - - shaderInput.m_handle = m_enemyGlowProgram; - - shaderInput.m_uniforms.push_back({ m_u_param, ¶ms }); - shaderInput.m_textures.push_back({ m_s_diffuseMap, pObject->GetMaterial()->GetImage(eMaterialTexture_Diffuse)->GetHandle(), 0 }); - - shaderInput.m_configuration.m_write = Write::RGBA; - shaderInput.m_configuration.m_depthTest = DepthTest::Equal; - shaderInput.m_configuration.m_alphaBlendFunc = CreateBlendFunction(BlendOperator::Add, BlendOperand::One, BlendOperand::One); - shaderInput.m_configuration.m_rgbBlendFunc = CreateBlendFunction(BlendOperator::Add, BlendOperand::One, BlendOperand::One); - - // shaderInput.m_projection = currentFrustum->GetProjectionMatrix().GetTranspose(); - // shaderInput.m_view = currentFrustum->GetViewMatrix().GetTranspose(); - shaderInput.m_modelTransform = pObject->GetModelMatrixPtr() ? pObject->GetModelMatrixPtr()->GetTranspose() : cMatrixf::Identity; - pObject->GetVertexBuffer()->GetLayoutStream(layoutInput); - - GraphicsContext::DrawRequest drawRequest{ layoutInput, shaderInput }; - graphicsContext.Submit(view, drawRequest); - } } void cLuxEffectRenderer::RenderOutline(cRendererCallbackFunctions* apFunctions) { - if (mvOutlineObjects.empty()) - return; - - auto& graphicsContext = apFunctions->GetGraphicsContext(); - auto& postEffectData = m_boundPostEffectData.resolve(apFunctions->GetViewport()); - auto currentFrustum = apFunctions->GetFrustum(); - if(!postEffectData.m_outputImage || - !postEffectData.m_gBufferDepthStencil) { - return; - } - auto imageSize = postEffectData.m_outputImage->GetImageSize(); - - ///////////////////////////// - // Setup vars - cGraphics* pGraphics = gpBase->mpEngine->GetGraphics(); - // cVector2l vScreenSize = pGraphics->GetLowLevel()->GetScreenSizeInt(); - - float fScaleAdd = 0.02f; - - //////////////////////////////////// - // Get entities to be rendered - cFrustum* pFrustum = apFunctions->GetFrustum(); - absl::InlinedVector lstObjects; - for (size_t i = 0; i < mvOutlineObjects.size(); ++i) - { - iRenderable* pObject = mvOutlineObjects[i]; - - if (pObject->CollidesWithFrustum(pFrustum)) - { - lstObjects.push_back(pObject); - } - } - - //////////////////////////////////// - // Build AABB from all objects - cBoundingVolume totalBV; - cVector3f vTotalMin = 100000.0f; - cVector3f vTotalMax = -100000.0f; - for (auto& object : lstObjects) - { - cBoundingVolume* pBV = object->GetBoundingVolume(); - cMath::ExpandAABB(vTotalMin, vTotalMax, pBV->GetMin(), pBV->GetMax()); - } - - // Need to scale so the outline is contained. - cVector3f vTotalSize = vTotalMax - vTotalMin; - cVector3f vTotalAdd = vTotalSize * (cVector3f(1.0f) / vTotalSize) * (fScaleAdd * 2); - - totalBV.SetLocalMinMax(vTotalMin - vTotalAdd, vTotalMax + vTotalAdd); - - // TODO: use clip rect to avoid rendering to the entire framebuffer - cRect2l clipRect; - cMath::GetClipRectFromBV(clipRect, totalBV, apFunctions->GetFrustum(), imageSize, -1); - - { - GraphicsContext::ViewConfiguration viewConfiguration {postEffectData.m_outlineTarget}; - viewConfiguration.m_viewRect = { 0, 0, static_cast(imageSize.x), static_cast(imageSize.y) }; - viewConfiguration.m_clear = { 0, 1.0, 0, ClearOp::Stencil | ClearOp::Color }; - bgfx::touch(graphicsContext.StartPass("Clear Outline And Stencil", viewConfiguration)); - } - - { - - GraphicsContext::ViewConfiguration viewConfiguration {postEffectData.m_outlineTarget}; - viewConfiguration.m_projection = currentFrustum->GetProjectionMatrix().GetTranspose(); - viewConfiguration.m_view = currentFrustum->GetViewMatrix().GetTranspose(); - viewConfiguration.m_viewRect = { 0, 0, static_cast(imageSize.x), static_cast(imageSize.y) }; - const auto view = graphicsContext.StartPass("Render Outline Stencil", viewConfiguration); - for (auto& object : lstObjects) - { - GraphicsContext::LayoutStream layoutInput; - GraphicsContext::ShaderProgram shaderInput; - struct - { - float m_alpha; - float pad[3]; - } params = { 0 }; - - shaderInput.m_handle = m_alphaRejectProgram; - auto alphaImage = object->GetMaterial()->GetImage(eMaterialTexture_Alpha); - if (alphaImage) - { - shaderInput.m_textures.push_back({ m_s_diffuseMap, alphaImage->GetHandle(), 0 }); - params.m_alpha = 0.5f; - } - shaderInput.m_configuration.m_depthTest = DepthTest::LessEqual; - shaderInput.m_uniforms.push_back({ m_u_param, ¶ms }); - shaderInput.m_handle = m_alphaRejectProgram; - shaderInput.m_configuration.m_frontStencilTest = CreateStencilTest( - StencilFunction::Always, StencilFail::Keep, StencilDepthFail::Keep, StencilDepthPass::Replace, 0xff, 0xff); - // shaderInput.m_projection = currentFrustum->GetProjectionMatrix().GetTranspose(); - // shaderInput.m_view = currentFrustum->GetViewMatrix().GetTranspose(); - shaderInput.m_modelTransform = object->GetModelMatrixPtr() ? object->GetModelMatrixPtr()->GetTranspose() : cMatrixf::Identity; - object->GetVertexBuffer()->GetLayoutStream(layoutInput); - - GraphicsContext::DrawRequest drawRequest{ layoutInput, shaderInput }; - graphicsContext.Submit(view, drawRequest); - } - } - - { - - GraphicsContext::ViewConfiguration viewConfiguration {postEffectData.m_outlineTarget}; - viewConfiguration.m_viewRect = {0, 0, imageSize.x, imageSize.y}; - viewConfiguration.m_projection = currentFrustum->GetProjectionMatrix().GetTranspose(); - viewConfiguration.m_view = currentFrustum->GetViewMatrix().GetTranspose(); - const auto view = graphicsContext.StartPass("Render Outline", viewConfiguration); - for (auto& object : lstObjects) - { - GraphicsContext::LayoutStream layoutInput; - GraphicsContext::ShaderProgram shaderInput; - struct - { - float color[3]; - float useAlpha; - } params = { { 0, 0, 0.5f }, 0 }; - - shaderInput.m_handle = m_outlineProgram; - auto alphaImage = object->GetMaterial()->GetImage(eMaterialTexture_Alpha); - if (alphaImage) - { - shaderInput.m_textures.push_back({ m_s_diffuseMap, alphaImage->GetHandle(), 0 }); - params.useAlpha = 1.0f; - } - shaderInput.m_configuration.m_write = Write::RGBA; - shaderInput.m_configuration.m_depthTest = DepthTest::LessEqual; - shaderInput.m_uniforms.push_back({ m_u_param, ¶ms }); - shaderInput.m_configuration.m_frontStencilTest = - CreateStencilTest(StencilFunction::NotEqual, StencilFail::Keep, StencilDepthFail::Keep, StencilDepthPass::Keep, 0xff, 0xff); - - cBoundingVolume* pBV = object->GetBoundingVolume(); - cVector3f vLocalSize = pBV->GetLocalMax() - pBV->GetLocalMin(); - cVector3f vScale = (cVector3f(1.0f) / vLocalSize) * fScaleAdd + cVector3f(1.0f); - - cMatrixf mtxScale = cMath::MatrixMul(cMath::MatrixScale(vScale), cMath::MatrixTranslate(pBV->GetLocalCenter() * -1)); - mtxScale.SetTranslation(mtxScale.GetTranslation() + pBV->GetLocalCenter()); - - // shaderInput.m_projection = currentFrustum->GetProjectionMatrix().GetTranspose(); - // shaderInput.m_view = currentFrustum->GetViewMatrix().GetTranspose(); - shaderInput.m_modelTransform = cMath::MatrixMul(object->GetWorldMatrix(), mtxScale).GetTranspose(); - object->GetVertexBuffer()->GetLayoutStream(layoutInput); - - GraphicsContext::DrawRequest drawRequest{ layoutInput, shaderInput }; - graphicsContext.Submit(view, drawRequest); - } - } - - RenderBlurPass(graphicsContext, postEffectData.m_blurTarget, *postEffectData.m_outlineTarget.GetImage()); - for (size_t i = 0; i < 2; ++i) - { - RenderBlurPass(graphicsContext, postEffectData.m_blurTarget, *postEffectData.m_blurTarget[1].GetImage()); - } - - { - - auto imageSize = postEffectData.m_blurTarget[1].GetImage()->GetImageSize(); - GraphicsContext::LayoutStream layoutStream; - cMatrixf projMtx; - graphicsContext.ScreenSpaceQuad(layoutStream, projMtx, imageSize.x, imageSize.y); - - GraphicsContext::ViewConfiguration viewConfiguration {postEffectData.m_outputTarget}; - viewConfiguration.m_projection = projMtx; - const auto view = apFunctions->GetGraphicsContext().StartPass("Additive Outline", viewConfiguration); - auto outlineOutputImage = postEffectData.m_blurTarget[1].GetImage(); - - GraphicsContext::ShaderProgram shaderProgram; - GraphicsContext::ShaderProgram program; - program.m_handle = m_copyProgram; - program.m_configuration.m_write = Write::RGBA; - // program.m_projection = projMtx; - program.m_configuration.m_alphaBlendFunc = CreateBlendFunction(BlendOperator::Add, BlendOperand::One, BlendOperand::One); - program.m_configuration.m_rgbBlendFunc = CreateBlendFunction(BlendOperator::Add, BlendOperand::One, BlendOperand::One); - - program.m_textures.push_back({ m_s_diffuseMap, outlineOutputImage->GetHandle(), 0 }); - - GraphicsContext::DrawRequest request = { layoutStream, program }; - graphicsContext.Submit(view, request); - } + } void cLuxEffectRenderer::RenderBlurPass(GraphicsContext& context, std::span blurTargets, Image& input) diff --git a/amnesia/src/game/LuxEffectRenderer.h b/amnesia/src/game/LuxEffectRenderer.h index c348b9878..522ae8048 100644 --- a/amnesia/src/game/LuxEffectRenderer.h +++ b/amnesia/src/game/LuxEffectRenderer.h @@ -86,12 +86,12 @@ class cLuxEffectRenderer : public iLuxUpdateable void Reset(); - void Update(float afTimeStep); + virtual void Update(float afTimeStep) override; void ClearRenderLists(); - void RenderSolid(cRendererCallbackFunctions* apFunctions); - void RenderTrans(cRendererCallbackFunctions* apFunctions); + void RenderSolid(cViewport::PostSolidDrawPacket& input); + void RenderTrans(cViewport::PostTranslucenceDrawPacket& input); void AddOutlineObject(iRenderable* apObject); void ClearOutlineObjects(); diff --git a/amnesia/src/game/LuxHandObject_Melee.h b/amnesia/src/game/LuxHandObject_Melee.h index 490d1cc2f..b7ac1f185 100644 --- a/amnesia/src/game/LuxHandObject_Melee.h +++ b/amnesia/src/game/LuxHandObject_Melee.h @@ -38,9 +38,6 @@ class cLuxHandObject_Melee : public iLuxHandObject void ImplementedCreateEntity(cLuxMap *apMap); void ImplementedDestroyEntity(cLuxMap *apMap); - // void RenderSolid(cRendererCallbackFunctions* apFunctions); - // void RenderTrans(cRendererCallbackFunctions* apFunctions); - void ImplementedReset(); void Update(float afTimeStep); diff --git a/amnesia/src/game/LuxMainMenu_Options.cpp b/amnesia/src/game/LuxMainMenu_Options.cpp index cf9d3a1b7..d2f84605b 100644 --- a/amnesia/src/game/LuxMainMenu_Options.cpp +++ b/amnesia/src/game/LuxMainMenu_Options.cpp @@ -218,19 +218,10 @@ void cLuxMainMenu_Options::CreateMainGui() pTabFrame->AddCallback(eGuiMessage_SelectionChange, this, kGuiCallback(TabFrame_OnPageChange)); - - -#ifdef USE_ONLIVE - mpTabGame = pTabFrame->AddTab(kTranslate("MainMenu","OptionsGame")); - mpTabInput = pTabFrame->AddTab(kTranslate("MainMenu","OptionsInput")); - mpTabGraphics = NULL; - mpTabSound = NULL; -#else mpTabGame = pTabFrame->AddTab(kTranslate("MainMenu","OptionsGame")); mpTabGraphics = pTabFrame->AddTab(kTranslate("MainMenu","OptionsGraphics")); mpTabInput = pTabFrame->AddTab(kTranslate("MainMenu","OptionsInput")); mpTabSound = pTabFrame->AddTab(kTranslate("MainMenu","OptionsSound")); -#endif #if USE_GAMEPAD /////////////////// diff --git a/amnesia/src/game/LuxMapHandler.cpp b/amnesia/src/game/LuxMapHandler.cpp index 38843331a..555e211bd 100644 --- a/amnesia/src/game/LuxMapHandler.cpp +++ b/amnesia/src/game/LuxMapHandler.cpp @@ -103,26 +103,26 @@ void cMapHandlerSoundCallback::OnStart(cSoundEntity *apSoundEntity) cLuxMapHandler::cLuxMapHandler() : iLuxUpdateable("LuxMapHandler") { - m_postDebugSolidDrawHandler = cViewport::PostSolidDraw::Handler([&](cViewport::PostSolidDrawPayload& payload) { - // cMatrixf view = payload.m_frustum->GetViewMatrix().GetTranspose(); - // cMatrixf proj = payload.m_frustum->GetProjectionMatrix().GetTranspose(); - // hpl::ImmediateDrawBatch batch(*payload.m_context, *payload.m_outputTarget,view, proj); + m_postDebugSolidDrawHandler = cViewport::PostSolidDraw::Handler([&](cViewport::PostSolidDrawPacket& payload) { + cMatrixf view = payload.m_frustum->GetViewMatrix().GetTranspose(); + cMatrixf proj = payload.m_frustum->GetProjectionMatrix().GetTranspose(); + hpl::ImmediateDrawBatch batch(*payload.m_context, *payload.m_outputTarget,view, proj); // if(mpCurrentMap && mpCurrentMap->GetPhysicsWorld()) // { // // mpCurrentMap->GetPhysicsWorld()->RenderDebugGeometry(&batch, cColor(1,1,1,1)); // } - // // gpBase->mpDebugHandler->RenderSolid(&batch); - // // gpBase->mpMapHandler->RenderSolid(&batch); - // // gpBase->mpPlayer->RenderSolid(&batch); - // // gpBase->mpEffectRenderer->RenderSolid(&batch); - // batch.flush(); + // gpBase->mpDebugHandler->RenderSolid(&batch); + // gpBase->mpMapHandler->RenderSolid(&batch); + // gpBase->mpPlayer->RenderSolid(&batch); + // gpBase->mpEffectRenderer->RenderSolid(&batch); + batch.flush(); }); - m_postDebugTranslucentDrawHandler = cViewport::PostTranslucenceDraw::Handler([&](cViewport::PostTranslucenceDrawPayload& payload) { + m_postDebugTranslucentDrawHandler = cViewport::PostTranslucenceDraw::Handler([&](cViewport::PostTranslucenceDrawPacket& packet) { // gpBase->mpPlayer->RenderTrans(apFunctions); - // gpBase->mpEffectRenderer->RenderTrans(apFunctions); + gpBase->mpEffectRenderer->RenderTrans(packet); }); ////////////////////////// diff --git a/amnesia/src/game/LuxPlayer.cpp b/amnesia/src/game/LuxPlayer.cpp index a5e414eb0..f8737a2b4 100644 --- a/amnesia/src/game/LuxPlayer.cpp +++ b/amnesia/src/game/LuxPlayer.cpp @@ -568,21 +568,18 @@ void cLuxPlayer::OnLeaveContainer(const tString& asNewContainer) //----------------------------------------------------------------------- -void cLuxPlayer::RenderSolid(cRendererCallbackFunctions* apFunctions) +void cLuxPlayer::RenderSolid(hpl::ImmediateDrawBatch* apFunctions) { - mvStates[mState]->RenderSolid(apFunctions); + mvStates[mState]->DebugRenderSolid(apFunctions); - for(size_t i=0; iRenderSolid(apFunctions); + // for(size_t i=0; iRenderSolid(apFunctions); } -void cLuxPlayer::RenderTrans(cRendererCallbackFunctions* apFunctions) +void cLuxPlayer::RenderTrans(hpl::ImmediateDrawBatch* apFunctions) { - mvStates[mState]->RenderTrans(apFunctions); + mvStates[mState]->DebugRenderTrans(apFunctions); } - -//----------------------------------------------------------------------- - void cLuxPlayer::GiveDamage(float afAmount, int alStrength, eLuxDamageType aType, bool abSpinHead, bool abLethal) { if(mfHealth <=0) return; diff --git a/amnesia/src/game/LuxPlayer.h b/amnesia/src/game/LuxPlayer.h index 97958216f..d8754aa8f 100644 --- a/amnesia/src/game/LuxPlayer.h +++ b/amnesia/src/game/LuxPlayer.h @@ -87,8 +87,8 @@ friend class cLuxHelpFuncs; void OnEnterContainer(const tString& asOldContainer); void OnLeaveContainer(const tString& asNewContainer); - void RenderSolid(cRendererCallbackFunctions* apFunctions); - void RenderTrans(cRendererCallbackFunctions* apFunctions); + void RenderSolid(hpl::ImmediateDrawBatch* apFunctions); + void RenderTrans(hpl::ImmediateDrawBatch* apFunctions); //////////////////// // Actions diff --git a/amnesia/src/game/LuxPlayerHands.cpp b/amnesia/src/game/LuxPlayerHands.cpp index 56b14076d..52c343c45 100644 --- a/amnesia/src/game/LuxPlayerHands.cpp +++ b/amnesia/src/game/LuxPlayerHands.cpp @@ -307,15 +307,7 @@ void cLuxPlayerHands::DestroyWorldEntities(cLuxMap *apMap) //----------------------------------------------------------------------- -void cLuxPlayerHands::RenderSolid(cRendererCallbackFunctions* apFunctions) -{ - // if(mpCurrentHandObject) mpCurrentHandObject->RenderSolid(apFunctions); -} -void cLuxPlayerHands::RenderTrans(cRendererCallbackFunctions* apFunctions) -{ - // if(mpCurrentHandObject) mpCurrentHandObject->RenderTrans(apFunctions); -} //----------------------------------------------------------------------- diff --git a/amnesia/src/game/LuxPlayerHands.h b/amnesia/src/game/LuxPlayerHands.h index 096f9f1fa..6accfd0d1 100644 --- a/amnesia/src/game/LuxPlayerHands.h +++ b/amnesia/src/game/LuxPlayerHands.h @@ -24,6 +24,10 @@ #include "LuxBase.h" +namespace hpl { + class ImmediateDrawBatch; +} + //---------------------------------------------- class cLuxPlayer; @@ -80,9 +84,6 @@ friend class cLuxPlayerHandsLoader; void CreateWorldEntities(cLuxMap *apMap); void DestroyWorldEntities(cLuxMap *apMap); - void RenderSolid(cRendererCallbackFunctions* apFunctions); - void RenderTrans(cRendererCallbackFunctions* apFunctions); - /////////////////////////////// // Actions void PlayAnim(const tString& asAnim, bool abLoop); diff --git a/amnesia/src/game/LuxPlayerState.h b/amnesia/src/game/LuxPlayerState.h index e8a33be32..4be6c3732 100644 --- a/amnesia/src/game/LuxPlayerState.h +++ b/amnesia/src/game/LuxPlayerState.h @@ -33,6 +33,10 @@ class cLuxMap; class cLuxInventory_Item; class cLuxArea_Ladder; +namespace hpl +{ + class ImmediateDrawBatch; +} //---------------------------------------------- class cLuxPlayerStateVars @@ -118,8 +122,8 @@ class iLuxPlayerState virtual bool AllowPlayerMenus(){ return true;} virtual bool AllowLantern(){ return true;} - virtual void RenderSolid(cRendererCallbackFunctions* apFunctions){} - virtual void RenderTrans(cRendererCallbackFunctions* apFunctions){} + virtual void DebugRenderSolid(hpl::ImmediateDrawBatch* apFunctions){} + virtual void DebugRenderTrans(hpl::ImmediateDrawBatch* apFunctions){} void SetPreviousState(eLuxPlayerState aState) { mPreviousState = aState; } diff --git a/amnesia/src/game/LuxPlayerState_InteractGrab.cpp b/amnesia/src/game/LuxPlayerState_InteractGrab.cpp index 26e49df81..457c91f58 100644 --- a/amnesia/src/game/LuxPlayerState_InteractGrab.cpp +++ b/amnesia/src/game/LuxPlayerState_InteractGrab.cpp @@ -563,10 +563,10 @@ float cLuxPlayerState_InteractGrab::DrawDebug(cGuiSet *apSet,iFontData *apFont, return afStartY; } -void cLuxPlayerState_InteractGrab::RenderSolid(cRendererCallbackFunctions* apFunctions) +void cLuxPlayerState_InteractGrab::DebugRenderSolid(ImmediateDrawBatch* batch) { return; - apFunctions->SetMatrix(NULL); + // apFunctions->SetMatrix(NULL); cCamera *pCam = mpPlayer->GetCamera(); @@ -588,11 +588,11 @@ void cLuxPlayerState_InteractGrab::RenderSolid(cRendererCallbackFunctions* apFun cVector3f vRight = mtxBodyInv.GetRight(); cVector3f vPos = mpCurrentBody->GetLocalPosition(); - apFunctions->GetLowLevelGfx()->DrawLine(vPos, vPos+vWantedUp, cColor(0,1,0,1)); - apFunctions->GetLowLevelGfx()->DrawLine(vPos, vPos+vUp, cColor(0,1,1,1)); + batch->DebugDrawLine(vPos, vPos+vWantedUp, cColor(0,1,0,1)); + batch->DebugDrawLine(vPos, vPos+vUp, cColor(0,1,1,1)); - apFunctions->GetLowLevelGfx()->DrawLine(vPos, vPos+vWantedRight, cColor(1,0,0,1)); - apFunctions->GetLowLevelGfx()->DrawLine(vPos, vPos+vRight, cColor(1,0,1,1)); + batch->DebugDrawLine(vPos, vPos+vWantedRight, cColor(1,0,0,1)); + batch->DebugDrawLine(vPos, vPos+vRight, cColor(1,0,1,1)); } diff --git a/amnesia/src/game/LuxPlayerState_InteractGrab.h b/amnesia/src/game/LuxPlayerState_InteractGrab.h index 6ff2b8b50..ba98dd188 100644 --- a/amnesia/src/game/LuxPlayerState_InteractGrab.h +++ b/amnesia/src/game/LuxPlayerState_InteractGrab.h @@ -89,7 +89,7 @@ typedef iLuxPlayerState_Interact super_class; float DrawDebug(cGuiSet *apSet,iFontData *apFont, float afStartY); - void RenderSolid(cRendererCallbackFunctions* apFunctions); + virtual void DebugRenderSolid(ImmediateDrawBatch* apFunctions) override; ///////////////////////////////// //Save data stuff diff --git a/amnesia/src/game/LuxPlayerState_InteractLever.cpp b/amnesia/src/game/LuxPlayerState_InteractLever.cpp index 521179c41..84d34db56 100644 --- a/amnesia/src/game/LuxPlayerState_InteractLever.cpp +++ b/amnesia/src/game/LuxPlayerState_InteractLever.cpp @@ -53,19 +53,14 @@ cLuxPlayerState_InteractLever::~cLuxPlayerState_InteractLever() //----------------------------------------------------------------------- -void cLuxPlayerState_InteractLever::RenderSolid(cRendererCallbackFunctions* apFunctions) +void cLuxPlayerState_InteractLever::DebugRenderSolid(ImmediateDrawBatch* batch) { return; cCamera *pCam = mpPlayer->GetCamera(); - apFunctions->SetBlendMode(eMaterialBlendMode_None); - apFunctions->SetProgram(NULL); - apFunctions->SetMatrix(NULL); - cVector3f vBodyCenter = cMath::MatrixMul(mpCurrentBody->GetLocalMatrix(), mpCurrentBody->GetMassCentre()); cVector3f vJointToBody = cMath::Vector3Normalize(vBodyCenter - mpCurrentJoint->GetPivotPoint()); - //cVector3f vJointMoveDir = cMath::Vector3Cross(vJointToBody, mpCurrentJoint->GetPinDir()); cVector3f vUp = pCam->GetUp(); cVector3f vRight = pCam->GetRight(); @@ -83,10 +78,10 @@ void cLuxPlayerState_InteractLever::RenderSolid(cRendererCallbackFunctions* apFu cVector3f vPushRotateDir = cMath::Vector3Cross(vJointToBody, vPushAmount); cVector3f vPivot = mpCurrentJoint->GetPivotPoint(); - apFunctions->GetLowLevelGfx()->DrawLine(vPivot, vPivot+vPushAmount*30, cColor(1,0,0,1)); - apFunctions->GetLowLevelGfx()->DrawLine(vPivot, vPivot+vUpJointForward, cColor(1,0,1,1)); - apFunctions->GetLowLevelGfx()->DrawLine(vPivot, vPivot+vJointToBody, cColor(0,1,0,1)); - apFunctions->GetLowLevelGfx()->DrawLine(vPivot, vPivot+mpCurrentJoint->GetPinDir(), cColor(0,0,1,1)); + batch->DebugDrawLine(vPivot, vPivot+vPushAmount*30, cColor(1,0,0,1)); + batch->DebugDrawLine(vPivot, vPivot+vUpJointForward, cColor(1,0,1,1)); + batch->DebugDrawLine(vPivot, vPivot+vJointToBody, cColor(0,1,0,1)); + batch->DebugDrawLine(vPivot, vPivot+mpCurrentJoint->GetPinDir(), cColor(0,0,1,1)); } diff --git a/amnesia/src/game/LuxPlayerState_InteractLever.h b/amnesia/src/game/LuxPlayerState_InteractLever.h index e2dbdd2ac..c481703a3 100644 --- a/amnesia/src/game/LuxPlayerState_InteractLever.h +++ b/amnesia/src/game/LuxPlayerState_InteractLever.h @@ -45,7 +45,7 @@ typedef iLuxPlayerState_InteractRotateBase super_class; cLuxPlayerState_InteractLever(cLuxPlayer *apPlayer); virtual ~cLuxPlayerState_InteractLever(); - void RenderSolid(cRendererCallbackFunctions* apFunctions); + virtual void DebugRenderSolid(ImmediateDrawBatch* apFunctions) override; ///////////////////////////////// //Save data stuff diff --git a/amnesia/src/game/LuxPlayerState_InteractRotateBase.cpp b/amnesia/src/game/LuxPlayerState_InteractRotateBase.cpp index d6004cbd3..9f832570a 100644 --- a/amnesia/src/game/LuxPlayerState_InteractRotateBase.cpp +++ b/amnesia/src/game/LuxPlayerState_InteractRotateBase.cpp @@ -401,7 +401,7 @@ float iLuxPlayerState_InteractRotateBase::DrawDebug(cGuiSet *apSet,iFontData *ap //----------------------------------------------------------------------- -void iLuxPlayerState_InteractRotateBase::RenderSolid(cRendererCallbackFunctions* apFunctions) +void iLuxPlayerState_InteractRotateBase::DebugRenderSolid(ImmediateDrawBatch* apFunctions) { /*cCamera *pCam = mpPlayer->GetCamera(); cVector3f vJointPos = mpCurrentBody->GetLocalPosition();//mpCurrentJoint->GetPivotPoint(); diff --git a/amnesia/src/game/LuxPlayerState_InteractRotateBase.h b/amnesia/src/game/LuxPlayerState_InteractRotateBase.h index 6b2a0503e..8af0a9b28 100644 --- a/amnesia/src/game/LuxPlayerState_InteractRotateBase.h +++ b/amnesia/src/game/LuxPlayerState_InteractRotateBase.h @@ -68,7 +68,7 @@ class iLuxPlayerState_InteractRotateBase : public iLuxPlayerState_Interact float DrawDebug(cGuiSet *apSet,iFontData *apFont, float afStartY); - virtual void RenderSolid(cRendererCallbackFunctions* apFunctions); + virtual void DebugRenderSolid(ImmediateDrawBatch* apFunctions) override; virtual bool IsSaved(){ return false; } diff --git a/amnesia/src/game/LuxPlayerState_InteractSlide.cpp b/amnesia/src/game/LuxPlayerState_InteractSlide.cpp index 413f955d1..49d574647 100644 --- a/amnesia/src/game/LuxPlayerState_InteractSlide.cpp +++ b/amnesia/src/game/LuxPlayerState_InteractSlide.cpp @@ -297,10 +297,9 @@ float cLuxPlayerState_InteractSlide::DrawDebug(cGuiSet *apSet,iFontData *apFont, return afStartY; } -void cLuxPlayerState_InteractSlide::RenderSolid(cRendererCallbackFunctions* apFunctions) +void cLuxPlayerState_InteractSlide::DebugRenderSolid(ImmediateDrawBatch* batch) { return; - apFunctions->SetMatrix(NULL); cCamera *pCam = mpPlayer->GetCamera(); cVector3f vUp = pCam->GetUp(); @@ -313,15 +312,15 @@ void cLuxPlayerState_InteractSlide::RenderSolid(cRendererCallbackFunctions* apFu cVector3f vWorldInteractPos = cMath::MatrixMul(mpCurrentBody->GetLocalMatrix(), mvLocalInteractPos); - apFunctions->GetLowLevelGfx()->DrawSphere(vWorldInteractPos, 0.1f, cColor(0,1,0,1)); + batch->DebugDrawSphere(vWorldInteractPos, 0.1f, cColor(0,1,0,1)); cVector3f vMouseCamDir = vUp * mvLastMouseAdd.y + vRight * -mvLastMouseAdd.x; float fSpeedAdd = cMath::Vector3Dot(vMouseCamDir, mpCurrentJoint->GetPinDir()); - apFunctions->GetLowLevelGfx()->DrawLine(vWorldInteractPos, vWorldInteractPos+vMouseCamDir*50, cColor(1,0,0,1)); + batch->DebugDrawLine(vWorldInteractPos, vWorldInteractPos+vMouseCamDir*50, cColor(1,0,0,1)); - apFunctions->GetLowLevelGfx()->DrawLine(vWorldInteractPos, vWorldInteractPos+mpCurrentJoint->GetPinDir(),cColor(0,0,0.3f,1)); - apFunctions->GetLowLevelGfx()->DrawLine(vWorldInteractPos, vWorldInteractPos+mpCurrentJoint->GetPinDir()*fSpeedAdd*50,cColor(0,0,1,1)); + batch->DebugDrawLine(vWorldInteractPos, vWorldInteractPos+mpCurrentJoint->GetPinDir(),cColor(0,0,0.3f,1)); + batch->DebugDrawLine(vWorldInteractPos, vWorldInteractPos+mpCurrentJoint->GetPinDir()*fSpeedAdd*50,cColor(0,0,1,1)); //apFunctions->GetLowLevelGfx()->DrawLine(vPos, vPos+vRight, cColor(1,0,1,1)); diff --git a/amnesia/src/game/LuxPlayerState_InteractSlide.h b/amnesia/src/game/LuxPlayerState_InteractSlide.h index 748dd54e9..d77d6fdeb 100644 --- a/amnesia/src/game/LuxPlayerState_InteractSlide.h +++ b/amnesia/src/game/LuxPlayerState_InteractSlide.h @@ -67,7 +67,7 @@ typedef iLuxPlayerState_Interact super_class; float DrawDebug(cGuiSet *apSet,iFontData *apFont, float afStartY); - void RenderSolid(cRendererCallbackFunctions* apFunctions); + virtual void DebugRenderSolid(ImmediateDrawBatch* apFunctions) override; ///////////////////////////////// //Save data stuff diff --git a/amnesia/src/game/LuxPlayerState_InteractWheel.cpp b/amnesia/src/game/LuxPlayerState_InteractWheel.cpp index 354c86479..e96a396f9 100644 --- a/amnesia/src/game/LuxPlayerState_InteractWheel.cpp +++ b/amnesia/src/game/LuxPlayerState_InteractWheel.cpp @@ -55,14 +55,14 @@ cLuxPlayerState_InteractWheel::~cLuxPlayerState_InteractWheel() //----------------------------------------------------------------------- -void cLuxPlayerState_InteractWheel::RenderSolid(cRendererCallbackFunctions* apFunctions) +void cLuxPlayerState_InteractWheel::DebugRenderSolid(ImmediateDrawBatch* apFunctions) { return; cCamera *pCam = mpPlayer->GetCamera(); - apFunctions->SetBlendMode(eMaterialBlendMode_None); - apFunctions->SetProgram(NULL); - apFunctions->SetMatrix(NULL); + // apFunctions->SetBlendMode(eMaterialBlendMode_None); + // apFunctions->SetProgram(NULL); + // apFunctions->SetMatrix(NULL); cVector3f vAxes(1,1,1); @@ -76,7 +76,7 @@ void cLuxPlayerState_InteractWheel::RenderSolid(cRendererCallbackFunctions* apFu //apFunctions->GetLowLevelGfx()->DrawLine(vPivot, vPivot+cVector3f(0,1,0)*vAxes.y*10, cColor(0,1,0,1)); //apFunctions->GetLowLevelGfx()->DrawLine(vPivot, vPivot+cVector3f(0,0,1)*vAxes.z*-10, cColor(0,0,1,1)); - apFunctions->GetLowLevelGfx()->DrawLine(vPivot, vPivot+vPinDir*10, cColor(0,0,1,1)); + apFunctions->DebugDrawLine(vPivot, vPivot+vPinDir*10, cColor(0,0,1,1)); //apFunctions->GetLowLevelGfx()->DrawLine(vPivot, vPivot+mpCurrentJoint->GetPinDir(), cColor(0,0,1,1)); //apFunctions->GetLowLevelGfx()->DrawLine(mpCurrentBody->GetLocalPosition(), diff --git a/amnesia/src/game/LuxPlayerState_InteractWheel.h b/amnesia/src/game/LuxPlayerState_InteractWheel.h index b63c6779d..19f8ef8f8 100644 --- a/amnesia/src/game/LuxPlayerState_InteractWheel.h +++ b/amnesia/src/game/LuxPlayerState_InteractWheel.h @@ -45,7 +45,7 @@ typedef iLuxPlayerState_InteractRotateBase super_class; cLuxPlayerState_InteractWheel(cLuxPlayer *apPlayer); virtual ~cLuxPlayerState_InteractWheel(); - void RenderSolid(cRendererCallbackFunctions* apFunctions); + virtual void DebugRenderSolid(ImmediateDrawBatch* apFunctions) override; ///////////////////////////////// //Save data stuff diff --git a/amnesia/src/game/LuxProp.cpp b/amnesia/src/game/LuxProp.cpp index 260817485..ca3ae0f49 100644 --- a/amnesia/src/game/LuxProp.cpp +++ b/amnesia/src/game/LuxProp.cpp @@ -328,14 +328,6 @@ iLuxProp::~iLuxProp() } } -//----------------------------------------------------------------------- - -////////////////////////////////////////////////////////////////////////// -// PUBLIC METHODS -////////////////////////////////////////////////////////////////////////// - -//----------------------------------------------------------------------- - void iLuxProp::SetupAfterLoad(cWorld *apWorld) { ////////////////////// @@ -400,8 +392,6 @@ void iLuxProp::OnUpdate(float afTimeStep) // Specific update UpdatePropSpecific(afTimeStep); - //if(mvLights.size() > 0) - // Log("End Color: %s\n", mvLights[0]->GetDiffuseColor().ToString().c_str()); } //----------------------------------------------------------------------- @@ -416,19 +406,6 @@ void iLuxProp::BeforeEntityDestruction() BeforePropDestruction(); } -//----------------------------------------------------------------------- - -void iLuxProp::OnRenderSolid(cRendererCallbackFunctions* apFunctions) -{ - return; - if(mvBodies.size()<=0) return; - - cBoundingVolume* pBV = mvBodies[0]->GetBoundingVolume(); - apFunctions->GetLowLevelGfx()->DrawBoxMinMax(pBV->GetMin(), pBV->GetMax(),cColor(1,1,1,1)); -} - -//----------------------------------------------------------------------- - void iLuxProp::SetEffectsActive(bool abActive, bool abFadeAndPlaySounds) { if(abActive == mbEffectsActive) return; diff --git a/amnesia/src/game/LuxProp.h b/amnesia/src/game/LuxProp.h index e044fcac6..65563f27e 100644 --- a/amnesia/src/game/LuxProp.h +++ b/amnesia/src/game/LuxProp.h @@ -244,8 +244,6 @@ friend class cLuxProp_WorldCollisionCallback; void BeforeEntityDestruction(); - virtual void OnRenderSolid(cRendererCallbackFunctions* apFunctions); - ////////////////////// //Actions void GiveDamage(float afAmount, int alStrength); diff --git a/amnesia/src/game/LuxTypes.h b/amnesia/src/game/LuxTypes.h index 55fc0663c..52c65b594 100644 --- a/amnesia/src/game/LuxTypes.h +++ b/amnesia/src/game/LuxTypes.h @@ -28,6 +28,11 @@ using namespace hpl; + +namespace hpl { + class ImmediateDrawBatch; +} + //---------------------------------------------- //---------------------------------------------- @@ -51,7 +56,7 @@ enum eLuxAxis enum eLuxAchievement { - eLuxAchievement_Insanity = 0, // Platinum ¡DO NOT USE THIS! + eLuxAchievement_Insanity = 0, // Platinum �DO NOT USE THIS! // tdd eLuxAchievement_Alchemist, @@ -634,8 +639,8 @@ class iLuxPlayerHelper : public iLuxUpdateable iLuxPlayerHelper(cLuxPlayer *apPlayer, const tString& asName) : mpPlayer(apPlayer) ,iLuxUpdateable(asName){} virtual ~iLuxPlayerHelper(){} - virtual void RenderSolid(cRendererCallbackFunctions* apFunctions){} - virtual void RenderTrans(cRendererCallbackFunctions* apFunctions){} + // virtual void RenderSolid(hpl::ImmediateDrawBatch* apFunctions){} + // virtual void RenderTrans(hpl::ImmediateDrawBatch* apFunctions){} protected: cLuxPlayer *mpPlayer;