From ae800eb59cf95adf13967a25edae2faf7cd25b35 Mon Sep 17 00:00:00 2001 From: Dominic Masters Date: Sun, 12 Nov 2023 19:28:01 -0600 Subject: [PATCH] Removed RenderTarget event pointer. --- src/dawn/display/RenderTarget.hpp | 6 +++++- src/dawn/scene/components/display/Camera.cpp | 12 ++++++++++-- .../components/display/SimpleRenderTargetQuad.cpp | 6 +++++- .../scene/components/scene/SubSceneCameraAlign.cpp | 6 +++++- src/dawn/util/UsageLock.cpp | 9 ++------- src/dawn/util/UsageLock.hpp | 10 +--------- src/dawnopengl/display/BackBufferRenderTarget.cpp | 2 +- src/dawnopengl/display/TextureRenderTarget.cpp | 2 +- 8 files changed, 30 insertions(+), 23 deletions(-) diff --git a/src/dawn/display/RenderTarget.hpp b/src/dawn/display/RenderTarget.hpp index 420b6e23..ab816c2d 100644 --- a/src/dawn/display/RenderTarget.hpp +++ b/src/dawn/display/RenderTarget.hpp @@ -14,7 +14,11 @@ namespace Dawn { class RenderTarget { public: - StateEvent eventRenderTargetResized; + StateEvent< + RenderTarget&, + const float_t, + const float_t + > eventRenderTargetResized; /** * Return the width of the render target. diff --git a/src/dawn/scene/components/display/Camera.cpp b/src/dawn/scene/components/display/Camera.cpp index d8aa856d..d2f9a0c7 100644 --- a/src/dawn/scene/components/display/Camera.cpp +++ b/src/dawn/scene/components/display/Camera.cpp @@ -84,7 +84,11 @@ void Camera::onStart() { this->eventRenderTargetResized.invoke(rt->getWidth(), rt->getHeight()); // Subscribe to new render target resized. - return evtResized = useEvent([&](RenderTarget *rt, float_t w, float_t h){ + return evtResized = useEvent([&]( + RenderTarget &rt, + const float_t w, + const float_t h + ) { this->projectionNeedsUpdating = true; this->eventRenderTargetResized.invoke(w, h); }, rt->eventRenderTargetResized); @@ -102,7 +106,11 @@ void Camera::onStart() { // Sub to evt legacy, we don't invoke the useTeardown to avoid invoking // the state event for this camera when we don't need to. if(!this->getRenderTarget()) return; - evtResized = useEvent([&](RenderTarget *rt, float_t w, float_t h){ + evtResized = useEvent([&]( + RenderTarget &rt, + const float_t w, + const float_t h + ) { this->projectionNeedsUpdating = true; this->eventRenderTargetResized.invoke(w, h); }, getRenderTarget()->eventRenderTargetResized); diff --git a/src/dawn/scene/components/display/SimpleRenderTargetQuad.cpp b/src/dawn/scene/components/display/SimpleRenderTargetQuad.cpp index 29624b9b..45a6520d 100644 --- a/src/dawn/scene/components/display/SimpleRenderTargetQuad.cpp +++ b/src/dawn/scene/components/display/SimpleRenderTargetQuad.cpp @@ -43,7 +43,11 @@ void SimpleRenderTargetQuad::onStart() { ); // Subscribe to resize event. - evtResized = useEvent([&](RenderTarget *target, float_t w, float_t h){ + evtResized = useEvent([&]( + RenderTarget &target, + const float_t w, + const float_t h + ) { QuadMesh::bufferQuadMesh( &this->meshHost->mesh, glm::vec2(0, 0), glm::vec2(0, 0), diff --git a/src/dawn/scene/components/scene/SubSceneCameraAlign.cpp b/src/dawn/scene/components/scene/SubSceneCameraAlign.cpp index 9a7898ca..4809d296 100644 --- a/src/dawn/scene/components/scene/SubSceneCameraAlign.cpp +++ b/src/dawn/scene/components/scene/SubSceneCameraAlign.cpp @@ -58,7 +58,11 @@ void SubSceneCameraAlign::onStart() { this->realign(); - return evtRenderResized = useEvent([&](RenderTarget *t, float_t w, float_t h) { + return evtRenderResized = useEvent([&]( + RenderTarget &rt, + const float_t w, + const float_t h + ) { this->realign(); }, renderTarget->eventRenderTargetResized); }, this->renderTarget); diff --git a/src/dawn/util/UsageLock.cpp b/src/dawn/util/UsageLock.cpp index 81181a7e..c43d0b41 100644 --- a/src/dawn/util/UsageLock.cpp +++ b/src/dawn/util/UsageLock.cpp @@ -7,18 +7,13 @@ using namespace Dawn; -UsageLock::UsageLock() : UsageLock(&this->internalPool) { -} - -UsageLock::UsageLock(usagelockid_t *lockPool) { - assertNotNull(lockPool, "Lock pool cannot be null"); - this->pool = lockPool; +UsageLock::UsageLock() { this->onEmpty = []() {}; this->onFirstLock = []() {}; } usagelockid_t UsageLock::createLock() { - usagelockid_t lock = (*this->pool)++; + usagelockid_t lock = this->pool++; this->locks.push_back(lock); if(this->locks.size() == 1) this->onFirstLock(); return lock; diff --git a/src/dawn/util/UsageLock.hpp b/src/dawn/util/UsageLock.hpp index 9fa0aa53..b956c247 100644 --- a/src/dawn/util/UsageLock.hpp +++ b/src/dawn/util/UsageLock.hpp @@ -10,8 +10,7 @@ namespace Dawn { class UsageLock { protected: - usagelockid_t internalPool = 0; - usagelockid_t *pool = nullptr; + usagelockid_t pool = 0; std::vector locks; public: @@ -24,13 +23,6 @@ namespace Dawn { */ UsageLock(); - /** - * Construct a new Usage Lock object - * - * @param lockPool Pool that will be used to create locks. - */ - UsageLock(usagelockid_t *lockPool); - /** * Creates a new lock. * diff --git a/src/dawnopengl/display/BackBufferRenderTarget.cpp b/src/dawnopengl/display/BackBufferRenderTarget.cpp index 3e150554..ecb74f79 100644 --- a/src/dawnopengl/display/BackBufferRenderTarget.cpp +++ b/src/dawnopengl/display/BackBufferRenderTarget.cpp @@ -33,7 +33,7 @@ void BackBufferRenderTarget::setSize(float_t width, float_t height) { this->width = width; this->height = height; - this->eventRenderTargetResized.invoke(this, width, height); + this->eventRenderTargetResized.invoke(*this, width, height); } void BackBufferRenderTarget::setClearColor(struct Color color) { diff --git a/src/dawnopengl/display/TextureRenderTarget.cpp b/src/dawnopengl/display/TextureRenderTarget.cpp index 9d33a37b..6ba367d6 100644 --- a/src/dawnopengl/display/TextureRenderTarget.cpp +++ b/src/dawnopengl/display/TextureRenderTarget.cpp @@ -30,7 +30,7 @@ void TextureRenderTarget::setSize(float_t width, float_t height) { // Resize texture this->texture.setSize((int32_t)width, (int32_t)height, TEXTURE_FORMAT_RGBA, TEXTURE_DATA_FORMAT_FLOAT); - this->eventRenderTargetResized.invoke(this, width, height); + this->eventRenderTargetResized.invoke(*this, width, height); // Create Frame Buffer glGenFramebuffers(1, &this->fboId);