From 8f48fd4e1d5690add6a5bfe04c23da82e7374203 Mon Sep 17 00:00:00 2001 From: Pavel Rojtberg Date: Sat, 8 Feb 2025 18:26:05 +0100 Subject: [PATCH 1/4] Main: Texture::getBuffer - const correctness --- OgreMain/include/OgreTexture.h | 2 +- OgreMain/include/OgreTextureManager.h | 2 +- OgreMain/src/OgreTexture.cpp | 2 +- 3 files changed, 3 insertions(+), 3 deletions(-) diff --git a/OgreMain/include/OgreTexture.h b/OgreMain/include/OgreTexture.h index b95a0bebd33..fd450cdcec7 100644 --- a/OgreMain/include/OgreTexture.h +++ b/OgreMain/include/OgreTexture.h @@ -400,7 +400,7 @@ namespace Ogre { @remarks The buffer is invalidated when the resource is unloaded or destroyed. Do not use it after the lifetime of the containing texture. */ - virtual const HardwarePixelBufferSharedPtr& getBuffer(size_t face=0, size_t mipmap=0); + virtual const HardwarePixelBufferSharedPtr& getBuffer(size_t face=0, size_t mipmap=0) const; /** Populate an Image with the contents of this texture. diff --git a/OgreMain/include/OgreTextureManager.h b/OgreMain/include/OgreTextureManager.h index a0ed4f40934..4a91d2df9dd 100644 --- a/OgreMain/include/OgreTextureManager.h +++ b/OgreMain/include/OgreTextureManager.h @@ -435,7 +435,7 @@ namespace Ogre { : Texture(creator, name, handle, group) { } - const HardwarePixelBufferSharedPtr& getBuffer(size_t, size_t) override + const HardwarePixelBufferSharedPtr& getBuffer(size_t, size_t) const override { static HardwarePixelBufferSharedPtr nullBuffer; return nullBuffer; diff --git a/OgreMain/src/OgreTexture.cpp b/OgreMain/src/OgreTexture.cpp index 796fb3cfc92..17eedd41829 100644 --- a/OgreMain/src/OgreTexture.cpp +++ b/OgreMain/src/OgreTexture.cpp @@ -376,7 +376,7 @@ namespace Ogre { } } } - const HardwarePixelBufferSharedPtr& Texture::getBuffer(size_t face, size_t mipmap) + const HardwarePixelBufferSharedPtr& Texture::getBuffer(size_t face, size_t mipmap) const { OgreAssert(face < getNumFaces(), "out of range"); OgreAssert(mipmap <= mNumMipmaps, "out of range"); From 4633f9bd6c3d8aa93b1f4ff7029a4d400828de2b Mon Sep 17 00:00:00 2001 From: Pavel Rojtberg Date: Sat, 8 Feb 2025 18:44:13 +0100 Subject: [PATCH 2/4] Main: Viewport - add Rect based overloads & regroup methods --- OgreMain/include/OgreRenderTarget.h | 18 ++++----- OgreMain/include/OgreViewport.h | 62 +++++++++++------------------ OgreMain/src/OgreRenderTarget.cpp | 5 +-- OgreMain/src/OgreViewport.cpp | 4 +- 4 files changed, 37 insertions(+), 52 deletions(-) diff --git a/OgreMain/include/OgreRenderTarget.h b/OgreMain/include/OgreRenderTarget.h index b1e397adffa..fe3be22c715 100644 --- a/OgreMain/include/OgreRenderTarget.h +++ b/OgreMain/include/OgreRenderTarget.h @@ -170,16 +170,16 @@ namespace Ogre { viewports i.e. picture-in-picture). Higher Z-orders are on top of lower ones. The actual number is irrelevant, only the relative Z-order matters (you can leave gaps in the numbering) @param - left The relative position of the left of the viewport on the target, as a value between 0 and 1. - @param - top The relative position of the top of the viewport on the target, as a value between 0 and 1. - @param - width The relative width of the viewport on the target, as a value between 0 and 1. - @param - height The relative height of the viewport on the target, as a value between 0 and 1. + rect The relative position of the viewport on the target, as a value between 0 and 1. */ - Viewport* addViewport(Camera* cam, int ZOrder = 0, float left = 0.0f, float top = 0.0f , - float width = 1.0f, float height = 1.0f); + Viewport* addViewport(Camera* cam, int ZOrder = 0, FloatRect rect = {0.0f, 0.0f, 1.0f, 1.0f}); + + /// @overload + Viewport* addViewport(Camera* cam, int ZOrder, float left, float top = 0.0f, float width = 1.0f, + float height = 1.0f) + { + return addViewport(cam, ZOrder, {left, top, left + width, top + height}); + } /** Returns the number of viewports attached to this target.*/ unsigned short getNumViewports(void) const { return static_cast(mViewportList.size()); } diff --git a/OgreMain/include/OgreViewport.h b/OgreMain/include/OgreViewport.h index 5d97732192b..6355742ff72 100644 --- a/OgreMain/include/OgreViewport.h +++ b/OgreMain/include/OgreViewport.h @@ -87,7 +87,13 @@ namespace Ogre { Relative Z-order on the target. Lower = further to the front. */ - Viewport(Camera* camera, RenderTarget* target, float left, float top, float width, float height, int ZOrder); + Viewport(Camera* camera, RenderTarget* target, float left, float top, float width, float height, int ZOrder) + : Viewport(camera, target, {left, top, left + width, top + height}, ZOrder) + { + } + + /// @overload + Viewport(Camera* camera, RenderTarget* target, FloatRect relRect, int ZOrder); /** Default destructor. */ @@ -134,43 +140,17 @@ namespace Ogre { /** Gets the Z-Order of this viewport. */ int getZOrder(void) const { return mZOrder; } - /** Gets one of the relative dimensions of the viewport, - a value between 0.0 and 1.0. - */ - float getLeft(void) const { return mRelRect.left; } - /** Gets one of the relative dimensions of the viewport, a value - between 0.0 and 1.0. - */ + /// @name Relative dimensions + /// These methods return the relative dimensions of the viewport, which are + /// expressed as a value between 0.0 and 1.0. + /// @{ + float getLeft(void) const { return mRelRect.left; } float getTop(void) const { return mRelRect.top; } - - /** Gets one of the relative dimensions of the viewport, a value - between 0.0 and 1.0. - */ float getWidth(void) const { return mRelRect.width(); } - /** Gets one of the relative dimensions of the viewport, a value - between 0.0 and 1.0. - */ float getHeight(void) const { return mRelRect.height(); } - /** Gets one of the actual dimensions of the viewport, a value in - pixels. - */ - - int getActualLeft(void) const { return mActRect.left; } - /** Gets one of the actual dimensions of the viewport, a value in - pixels. - */ - - int getActualTop(void) const { return mActRect.top; } - /** Gets one of the actual dimensions of the viewport, a value in - pixels. - */ - int getActualWidth(void) const { return mActRect.width(); } - /** Gets one of the actual dimensions of the viewport, a value in - pixels. - */ - - int getActualHeight(void) const { return mActRect.height(); } + FloatRect getDimensions(void) const { return mRelRect; } + /// @} /** Sets the dimensions (after creation). @param @@ -187,6 +167,16 @@ namespace Ogre { */ void setDimensions(float left, float top, float width, float height); + /// @name Actual dimensions + /// These methods return the actual dimensions of the viewport in pixels. + /// @{ + int getActualLeft(void) const { return mActRect.left; } + int getActualTop(void) const { return mActRect.top; } + int getActualWidth(void) const { return mActRect.width(); } + int getActualHeight(void) const { return mActRect.height(); } + Rect getActualDimensions() const { return mActRect; } + /// @} + /** Sets the initial background colour of the viewport (before rendering). */ @@ -255,10 +245,6 @@ namespace Ogre { const String& getMaterialScheme(void) const { return mMaterialSchemeName; } - /** Access to actual dimensions (based on target size). - */ - Rect getActualDimensions() const { return mActRect; } - /// @deprecated OGRE_DEPRECATED void getActualDimensions(int& left, int& top, int& width, int& height) const; diff --git a/OgreMain/src/OgreRenderTarget.cpp b/OgreMain/src/OgreRenderTarget.cpp index b1ec55a9cb4..baae9c7ac27 100644 --- a/OgreMain/src/OgreRenderTarget.cpp +++ b/OgreMain/src/OgreRenderTarget.cpp @@ -169,8 +169,7 @@ namespace Ogre { fireViewportPostUpdate(viewport); } - Viewport* RenderTarget::addViewport(Camera* cam, int ZOrder, float left, float top , - float width , float height) + Viewport* RenderTarget::addViewport(Camera* cam, int ZOrder, FloatRect rect) { // Check no existing viewport with this Z-order ViewportList::iterator it = mViewportList.find(ZOrder); @@ -185,7 +184,7 @@ namespace Ogre { } // Add viewport to list // Order based on Z-order - Viewport* vp = OGRE_NEW Viewport(cam, this, left, top, width, height, ZOrder); + Viewport* vp = OGRE_NEW Viewport(cam, this, rect, ZOrder); mViewportList.emplace(ZOrder, vp); diff --git a/OgreMain/src/OgreViewport.cpp b/OgreMain/src/OgreViewport.cpp index ea73bda4741..baa8f42eafd 100644 --- a/OgreMain/src/OgreViewport.cpp +++ b/OgreMain/src/OgreViewport.cpp @@ -30,10 +30,10 @@ THE SOFTWARE. namespace Ogre { //--------------------------------------------------------------------- - Viewport::Viewport(Camera* cam, RenderTarget* target, float left, float top, float width, float height, int ZOrder) + Viewport::Viewport(Camera* cam, RenderTarget* target, FloatRect relRect, int ZOrder) : mCamera(cam) , mTarget(target) - , mRelRect(left, top, left + width, top + height) + , mRelRect(relRect) // Actual dimensions will update later , mZOrder(ZOrder) , mBackColour(ColourValue::Black) From 68974d9673bd6aff38b7c740cfb52c7c084c4e67 Mon Sep 17 00:00:00 2001 From: Pavel Rojtberg Date: Sun, 9 Feb 2025 19:46:44 +0100 Subject: [PATCH 3/4] Main: use inline methods for passing geometry counters --- OgreMain/include/OgreCamera.h | 8 ++++---- OgreMain/include/OgreRenderSystem.h | 8 ++++---- OgreMain/src/OgreCamera.cpp | 22 ---------------------- OgreMain/src/OgreRenderSystem.cpp | 16 ---------------- 4 files changed, 8 insertions(+), 46 deletions(-) diff --git a/OgreMain/include/OgreCamera.h b/OgreMain/include/OgreCamera.h index 9eb263680e1..c073dc01d16 100644 --- a/OgreMain/include/OgreCamera.h +++ b/OgreMain/include/OgreCamera.h @@ -397,19 +397,19 @@ namespace Ogre { /** Internal method to notify camera of the visible faces in the last render. */ - void _notifyRenderedFaces(unsigned int numfaces); + void _notifyRenderedFaces(unsigned int numfaces) { mVisFacesLastRender = numfaces; } /** Internal method to notify camera of the visible batches in the last render. */ - void _notifyRenderedBatches(unsigned int numbatches); + void _notifyRenderedBatches(unsigned int numbatches) { mVisBatchesLastRender = numbatches; } /** Internal method to retrieve the number of visible faces in the last render. */ - unsigned int _getNumRenderedFaces(void) const; + unsigned int _getNumRenderedFaces(void) const { return mVisFacesLastRender; } /** Internal method to retrieve the number of visible batches in the last render. */ - unsigned int _getNumRenderedBatches(void) const; + unsigned int _getNumRenderedBatches(void) const { return mVisBatchesLastRender; } /** Gets the derived orientation of the camera, including any rotation inherited from a node attachment and reflection matrix. */ diff --git a/OgreMain/include/OgreRenderSystem.h b/OgreMain/include/OgreRenderSystem.h index 6488b1b046d..9ae0292242e 100644 --- a/OgreMain/include/OgreRenderSystem.h +++ b/OgreMain/include/OgreRenderSystem.h @@ -716,13 +716,13 @@ namespace Ogre virtual void _setDepthClamp(bool enable) {} /** The RenderSystem will keep a count of tris rendered, this resets the count. */ - virtual void _beginGeometryCount(void); + void _beginGeometryCount(void); /** Reports the number of tris rendered since the last _beginGeometryCount call. */ - virtual unsigned int _getFaceCount(void) const; + unsigned int _getFaceCount(void) const { return static_cast(mFaceCount); } /** Reports the number of batches rendered since the last _beginGeometryCount call. */ - virtual unsigned int _getBatchCount(void) const; + unsigned int _getBatchCount(void) const { return static_cast(mBatchCount); } /** Reports the number of vertices passed to the renderer since the last _beginGeometryCount call. */ - virtual unsigned int _getVertexCount(void) const; + unsigned int _getVertexCount(void) const { return static_cast(mVertexCount); } /// @deprecated use ColourValue::getAsBYTE() OGRE_DEPRECATED static void convertColourValue(const ColourValue& colour, uint32* pDest) diff --git a/OgreMain/src/OgreCamera.cpp b/OgreMain/src/OgreCamera.cpp index d896233fccb..5ba29dafbeb 100644 --- a/OgreMain/src/OgreCamera.cpp +++ b/OgreMain/src/OgreCamera.cpp @@ -541,28 +541,6 @@ namespace Ogre { return o; } //----------------------------------------------------------------------- - void Camera::_notifyRenderedFaces(unsigned int numfaces) - { - mVisFacesLastRender = numfaces; - } - - //----------------------------------------------------------------------- - void Camera::_notifyRenderedBatches(unsigned int numbatches) - { - mVisBatchesLastRender = numbatches; - } - - //----------------------------------------------------------------------- - unsigned int Camera::_getNumRenderedFaces(void) const - { - return mVisFacesLastRender; - } - //----------------------------------------------------------------------- - unsigned int Camera::_getNumRenderedBatches(void) const - { - return mVisBatchesLastRender; - } - //----------------------------------------------------------------------- const Quaternion& Camera::getDerivedOrientation(void) const { updateView(); diff --git a/OgreMain/src/OgreRenderSystem.cpp b/OgreMain/src/OgreRenderSystem.cpp index 9349be8653b..0cba970704f 100644 --- a/OgreMain/src/OgreRenderSystem.cpp +++ b/OgreMain/src/OgreRenderSystem.cpp @@ -606,22 +606,6 @@ namespace Ogre { void RenderSystem::_beginGeometryCount(void) { mBatchCount = mFaceCount = mVertexCount = 0; - - } - //----------------------------------------------------------------------- - unsigned int RenderSystem::_getFaceCount(void) const - { - return static_cast< unsigned int >( mFaceCount ); - } - //----------------------------------------------------------------------- - unsigned int RenderSystem::_getBatchCount(void) const - { - return static_cast< unsigned int >( mBatchCount ); - } - //----------------------------------------------------------------------- - unsigned int RenderSystem::_getVertexCount(void) const - { - return static_cast< unsigned int >( mVertexCount ); } //----------------------------------------------------------------------- void RenderSystem::_render(const RenderOperation& op) From 53b9c26ff86dec1c4038ab8de2559cca64a91fbb Mon Sep 17 00:00:00 2001 From: Pavel Rojtberg Date: Sun, 9 Feb 2025 20:14:16 +0100 Subject: [PATCH 4/4] Main: MultiRenderTarget - devirtualize bindSurface --- OgreMain/include/OgreRenderTexture.h | 3 +-- .../Direct3D11/src/OgreD3D11MultiRenderTarget.cpp | 5 +---- .../Direct3D9/src/OgreD3D9MultiRenderTarget.cpp | 12 +++--------- .../Metal/src/OgreMetalMultiRenderTarget.mm | 4 +--- 4 files changed, 6 insertions(+), 18 deletions(-) diff --git a/OgreMain/include/OgreRenderTexture.h b/OgreMain/include/OgreRenderTexture.h index 0aa0fe89174..89eedd4ef3f 100644 --- a/OgreMain/include/OgreRenderTexture.h +++ b/OgreMain/include/OgreRenderTexture.h @@ -80,8 +80,7 @@ namespace Ogre - Not all bound surfaces have the same size - Not all bound surfaces have the same internal format */ - - virtual void bindSurface(size_t attachment, RenderTexture *target); + void bindSurface(size_t attachment, RenderTexture *target); /** Unbind attachment. */ diff --git a/RenderSystems/Direct3D11/src/OgreD3D11MultiRenderTarget.cpp b/RenderSystems/Direct3D11/src/OgreD3D11MultiRenderTarget.cpp index d672abb0645..30e35a6cacc 100644 --- a/RenderSystems/Direct3D11/src/OgreD3D11MultiRenderTarget.cpp +++ b/RenderSystems/Direct3D11/src/OgreD3D11MultiRenderTarget.cpp @@ -66,10 +66,7 @@ namespace Ogre if(mRenderTargets[y]->getWidth() != target->getWidth() || mRenderTargets[y]->getHeight() != target->getHeight()) { - OGRE_EXCEPT(Exception::ERR_INVALIDPARAMS, - "MultiRenderTarget surfaces are not of same size", - "D3D11MultiRenderTarget::bindSurface" - ); + OGRE_EXCEPT(Exception::ERR_INVALIDPARAMS, "MultiRenderTarget surfaces are not of same size"); } } diff --git a/RenderSystems/Direct3D9/src/OgreD3D9MultiRenderTarget.cpp b/RenderSystems/Direct3D9/src/OgreD3D9MultiRenderTarget.cpp index 4a6e4fdfc79..a41ce7caf91 100755 --- a/RenderSystems/Direct3D9/src/OgreD3D9MultiRenderTarget.cpp +++ b/RenderSystems/Direct3D9/src/OgreD3D9MultiRenderTarget.cpp @@ -70,21 +70,15 @@ namespace Ogre if (mRenderTargets[y]->getWidth() != buffer->getWidth() || mRenderTargets[y]->getHeight() != buffer->getHeight()) { - OGRE_EXCEPT( - Exception::ERR_INVALIDPARAMS, - "MultiRenderTarget surfaces are not of same size", - "D3D9MultiRenderTarget::bindSurface"); + OGRE_EXCEPT(Exception::ERR_INVALIDPARAMS, "MultiRenderTarget surfaces are not of same size"); } if (Root::getSingleton().getRenderSystem()->getCapabilities()->hasCapability(RSC_MRT_SAME_BIT_DEPTHS) && (PixelUtil::getNumElemBits(mRenderTargets[y]->getFormat()) != PixelUtil::getNumElemBits(buffer->getFormat()))) { - OGRE_EXCEPT( - Exception::ERR_INVALIDPARAMS, - "MultiRenderTarget surfaces are not of same bit depth and hardware requires it", - "D3D9MultiRenderTarget::bindSurface" - ); + OGRE_EXCEPT(Exception::ERR_INVALIDPARAMS, + "MultiRenderTarget surfaces are not of same bit depth and hardware requires it"); } } diff --git a/RenderSystems/Metal/src/OgreMetalMultiRenderTarget.mm b/RenderSystems/Metal/src/OgreMetalMultiRenderTarget.mm index bd2e677ea20..89b1bf15c8a 100644 --- a/RenderSystems/Metal/src/OgreMetalMultiRenderTarget.mm +++ b/RenderSystems/Metal/src/OgreMetalMultiRenderTarget.mm @@ -62,9 +62,7 @@ of this software and associated documentation files (the "Software"), to deal if( mWidth != target->getWidth() && mHeight != target->getHeight() && mFSAA != target->getFSAA() ) { - OGRE_EXCEPT( Exception::ERR_INVALIDPARAMS, - "MultiRenderTarget surfaces are not of same size", - "MetalMultiRenderTarget::bindSurface" ); + OGRE_EXCEPT(Exception::ERR_INVALIDPARAMS, "MultiRenderTarget surfaces are not of same size"); } }