Skip to content

Commit

Permalink
Rewrote the compositor changes to support RenderWindows
Browse files Browse the repository at this point in the history
As a bonus this new method breaks ABI far less.
Fix leak: DestroyCompositor would often not be called

Signed-off-by: Matias N. Goldberg <[email protected]>
  • Loading branch information
darksylinc committed May 8, 2021
1 parent 400811d commit a1c1968
Show file tree
Hide file tree
Showing 3 changed files with 119 additions and 87 deletions.
54 changes: 19 additions & 35 deletions ogre2/include/ignition/rendering/ogre2/Ogre2RenderTarget.hh
Original file line number Diff line number Diff line change
Expand Up @@ -115,22 +115,12 @@ namespace ignition
/// \see Camera::SetShadowsNodeDefDirty
public: void SetShadowsNodeDefDirty();

/// \brief Get a pointer to the ogre's internal texture name
/// \param[in] _idx In range [0; 1]
/// \see Ogre2RenderTarget::renderTargetResultsIdx
public: virtual const std::string* InternalTextureName(
size_t _idx) const = 0;

/// \brief Get a pointer to the ogre render target
/// \remarks Same as calling RenderTarget(this->renderTargetResultsIdx)
/// which is most likely what's intended (i.e. access to the final
/// results of rendering)
public: virtual Ogre::RenderTarget *RenderTarget() const;
/// \brief Returns true if this is a render window
public: virtual bool isRenderWindow() const;

/// \brief Get a pointer to the ogre render target
/// \param[in] _idx In range [0; 1]
/// \see Ogre2RenderTarget::renderTargetResultsIdx
public: virtual Ogre::RenderTarget *RenderTarget(size_t _idx) const = 0;
/// \brief Get a pointer to the ogre render target containing
/// the results of the render
public: virtual Ogre::RenderTarget *RenderTarget() const;

/// \brief Get visibility mask for the viewport associated with this
/// render target
Expand All @@ -148,7 +138,9 @@ namespace ignition
const std::string &_workspaceDefName,
const std::string &_baseNode, const std::string &_finalNode,
const std::vector<RenderPassPtr> &_renderPasses,
uint8_t &_renderTargetResultsIdx, bool _recreateNodes);
bool _recreateNodes,
Ogre::Texture *(*_ogreTextures)[2],
bool _isRenderWindow);

/// \brief Update the background color
protected: virtual void UpdateBackgroundColor();
Expand Down Expand Up @@ -205,17 +197,20 @@ namespace ignition
/// \brief Helper class that applies the material to the render target
protected: Ogre2RenderTargetMaterialPtr materialApplicator[2];

/// \brief Pointer to the internal ogre render texture objects
/// There's two because we ping pong postprocessing effects
/// and the final result is always in ogreTexture[1]
/// RenderWindows may have a 3rd texture which is the
/// actual window
protected: Ogre::Texture *ogreTexture[2] = {nullptr, nullptr};

/// \brief Flag to indicate if the render target color has changed
protected: bool colorDirty = true;

/// \brief Flag to indicate if the render target background material has
/// changed
protected: bool backgroundMaterialDirty = false;

/// \brief The index to RenderTarget(_idx) where the results are being
/// stored. In range [0; 1]
protected: uint8_t renderTargetResultsIdx = 0u;

/// \brief Anti-aliasing level
protected: unsigned int antiAliasing = 4;

Expand Down Expand Up @@ -248,14 +243,6 @@ namespace ignition
// Documentation inherited
public: virtual unsigned int GLId() const override;

// Documentation inherited.
public: virtual const std::string* InternalTextureName(
size_t _idx) const override;

// Documentation inherited.
public: virtual Ogre::RenderTarget *RenderTarget(
size_t _idx) const override;

// Documentation inherited.
protected: virtual void RebuildTarget() override;

Expand All @@ -265,11 +252,6 @@ namespace ignition
/// \brief Build the render texture
protected: virtual void BuildTarget();

/// \brief Pointer to the internal ogre render texture object
/// There's two because we ping pong postprocessing effects
/// and the final result may be in either of them
protected: Ogre::Texture *ogreTexture[2] = {nullptr, nullptr};

/// \brief Make scene our friend so it can create a ogre2 render texture
private: friend class Ogre2Scene;
};
Expand All @@ -288,8 +270,10 @@ namespace ignition
public: virtual void Destroy() override;

// Documentation inherited.
public: virtual Ogre::RenderTarget *RenderTarget(
size_t _idx) const override;
public: virtual bool isRenderWindow() const override;

// Documentation inherited.
public: virtual Ogre::RenderTarget *RenderTarget() const override;

// Documentation inherited.
protected: virtual void RebuildTarget() override;
Expand Down
28 changes: 17 additions & 11 deletions ogre2/src/Ogre2DepthCamera.cc
Original file line number Diff line number Diff line change
Expand Up @@ -121,10 +121,6 @@ class ignition::rendering::Ogre2DepthCameraPrivate
/// \brief Flag to indicate if render pass need to be rebuilt
public: bool renderPassDirty = false;

/// \brief The index to ogreDepthTexture[idx] where the results are being
/// stored. In range [0; 1]
public: uint8_t renderTargetResultsIdx = 0u;

/// \brief Event used to signal rgb point cloud data
public: ignition::common::EventT<void(const float *,
unsigned int, unsigned int, unsigned int,
Expand Down Expand Up @@ -897,8 +893,6 @@ void Ogre2DepthCamera::CreateDepthTexture()
rt->setDepthBufferPool(Ogre::DepthBuffer::POOL_INVALID);
}

this->dataPtr->renderTargetResultsIdx = 1u;

CreateWorkspaceInstance();
}

Expand Down Expand Up @@ -962,15 +956,29 @@ void Ogre2DepthCamera::PreRender()
if (!this->dataPtr->ogreCompositorWorkspace)
this->CreateWorkspaceInstance();

Ogre::Texture *rawDepthTextures[2] =
{
this->dataPtr->ogreDepthTexture[0].get(),
this->dataPtr->ogreDepthTexture[1].get()
};

// update depth camera render passes
Ogre2RenderTarget::UpdateRenderPassChain(
this->dataPtr->ogreCompositorWorkspace,
this->dataPtr->ogreCompositorWorkspaceDef,
this->dataPtr->ogreCompositorBaseNodeDef,
this->dataPtr->ogreCompositorFinalNodeDef,
this->dataPtr->renderPasses,
this->dataPtr->renderTargetResultsIdx,
this->dataPtr->renderPassDirty);
this->dataPtr->renderPassDirty,
&rawDepthTextures,
false);

if (rawDepthTextures[0] != this->dataPtr->ogreDepthTexture[0].get())
{
std::swap( this->dataPtr->ogreDepthTexture[0],
this->dataPtr->ogreDepthTexture[1] );
}

for (auto &pass : this->dataPtr->renderPasses)
pass->PreRender();

Expand Down Expand Up @@ -1022,9 +1030,7 @@ void Ogre2DepthCamera::PostRender()
1, imageFormat, this->dataPtr->depthBuffer);

// blit data from gpu to cpu
auto rt = this->dataPtr->ogreDepthTexture[
this->dataPtr->renderTargetResultsIdx]->
getBuffer()->getRenderTarget();
auto rt = this->dataPtr->ogreDepthTexture[1]->getBuffer()->getRenderTarget();
rt->copyContentsToMemory(dstBox, Ogre::RenderTarget::FB_AUTO);

if (!this->dataPtr->depthImage)
Expand Down
Loading

0 comments on commit a1c1968

Please sign in to comment.