diff --git a/include/ignition/rendering/Camera.hh b/include/ignition/rendering/Camera.hh index f39108262..0d04cfb24 100644 --- a/include/ignition/rendering/Camera.hh +++ b/include/ignition/rendering/Camera.hh @@ -317,6 +317,14 @@ namespace ignition /// \return Texture Id of type GLuint. public: virtual unsigned int RenderTextureGLId() const = 0; + /// \brief Get the Metal texture id associated with the render texture + /// used by this camera. A valid Id is obtained only if the underlying + /// render engine is Metal based. + /// The pointer set by this function must be released to an + /// id using CFBridgingRelease. + /// \param[out] _textureIdPtr the address of a void* pointer. + public: virtual void RenderTextureMetalId(void *_textureIdPtr) const = 0; + /// \brief Add a render pass to the camera /// \param[in] _pass New render pass to add public: virtual void AddRenderPass(const RenderPassPtr &_pass) = 0; diff --git a/include/ignition/rendering/RenderTarget.hh b/include/ignition/rendering/RenderTarget.hh index 8a37987a1..532129d99 100644 --- a/include/ignition/rendering/RenderTarget.hh +++ b/include/ignition/rendering/RenderTarget.hh @@ -109,6 +109,13 @@ namespace ignition /// \brief Returns the OpenGL texture Id. A valid Id is returned only // if this is an OpenGL render texture public: virtual unsigned int GLId() const = 0; + + /// \brief Gets the Metal texture id. A valid Id is obtained only + /// if this is an Metal render texture. + /// The pointer set by this function must be released to an + /// id using CFBridgingRelease. + /// \param[out] _textureIdPtr the address of a void* pointer. + public: virtual void MetalId(void *_textureIdPtr) const = 0; }; /* \class RenderWindow RenderWindow.hh \ diff --git a/include/ignition/rendering/base/BaseCamera.hh b/include/ignition/rendering/base/BaseCamera.hh index e48fe887e..531a22147 100644 --- a/include/ignition/rendering/base/BaseCamera.hh +++ b/include/ignition/rendering/base/BaseCamera.hh @@ -179,6 +179,10 @@ namespace ignition // Documentation inherited. public: virtual unsigned int RenderTextureGLId() const override; + // Documentation inherited. + public: virtual void RenderTextureMetalId(void *_textureIdPtr) + const override; + // Documentation inherited. public: virtual void AddRenderPass(const RenderPassPtr &_pass) override; @@ -804,6 +808,14 @@ namespace ignition return 0u; } + ////////////////////////////////////////////////// + template + void BaseCamera::RenderTextureMetalId(void */*_textureIdPtr*/) const + { + ignerr << "RenderTextureMetalId is not supported by current render" + << " engine" << std::endl; + } + ////////////////////////////////////////////////// template void BaseCamera::AddRenderPass(const RenderPassPtr &_pass) diff --git a/include/ignition/rendering/base/BaseRenderTarget.hh b/include/ignition/rendering/base/BaseRenderTarget.hh index c0c795c79..c1311cef1 100644 --- a/include/ignition/rendering/base/BaseRenderTarget.hh +++ b/include/ignition/rendering/base/BaseRenderTarget.hh @@ -105,6 +105,9 @@ namespace ignition // Documentation inherited. public: virtual unsigned int GLId() const override; + + // Documentation inherited. + public: virtual void MetalId(void *_textureIdPtr) const override; }; template @@ -291,6 +294,12 @@ namespace ignition return 0u; } + ////////////////////////////////////////////////// + template + void BaseRenderTexture::MetalId(void */*_textureIdPtr*/) const + { + } + ////////////////////////////////////////////////// // BaseRenderWindow ////////////////////////////////////////////////// diff --git a/ogre2/include/ignition/rendering/ogre2/Ogre2Camera.hh b/ogre2/include/ignition/rendering/ogre2/Ogre2Camera.hh index e5b7a0436..e7bd02c11 100644 --- a/ogre2/include/ignition/rendering/ogre2/Ogre2Camera.hh +++ b/ogre2/include/ignition/rendering/ogre2/Ogre2Camera.hh @@ -114,6 +114,10 @@ namespace ignition // Documentation inherited. public: virtual unsigned int RenderTextureGLId() const override; + // Documentation inherited. + public: virtual void RenderTextureMetalId(void *_textureIdPtr) + const override; + // Documentation inherited. public: void SetShadowsDirty() override; diff --git a/ogre2/include/ignition/rendering/ogre2/Ogre2RenderTarget.hh b/ogre2/include/ignition/rendering/ogre2/Ogre2RenderTarget.hh index 229157378..e4df31750 100644 --- a/ogre2/include/ignition/rendering/ogre2/Ogre2RenderTarget.hh +++ b/ogre2/include/ignition/rendering/ogre2/Ogre2RenderTarget.hh @@ -136,6 +136,9 @@ namespace ignition // Documentation inherited public: unsigned int GLIdImpl() const; + // Documentation inherited + public: void MetalIdImpl(void *_textureIdPtr) const; + /// \brief Destroy the render texture protected: void DestroyTargetImpl(); @@ -253,6 +256,9 @@ namespace ignition // Documentation inherited public: virtual unsigned int GLId() const override; + // Documentation inherited + public: virtual void MetalId(void *_textureIdPtr) const override; + // Documentation inherited // TODO(anyone): this function should be removed. // We didn't do it to preserve ABI. diff --git a/ogre2/src/Ogre2Camera.cc b/ogre2/src/Ogre2Camera.cc index 86d1d7b96..ada411d69 100644 --- a/ogre2/src/Ogre2Camera.cc +++ b/ogre2/src/Ogre2Camera.cc @@ -207,6 +207,21 @@ unsigned int Ogre2Camera::RenderTextureGLId() const return rt->GLId(); } +////////////////////////////////////////////////// +void Ogre2Camera::RenderTextureMetalId(void *_textureIdPtr) const +{ + if (!this->renderTexture) + return; + + Ogre2RenderTexturePtr rt = + std::dynamic_pointer_cast(this->renderTexture); + + if (!rt) + return; + + rt->MetalId(_textureIdPtr); +} + ////////////////////////////////////////////////// void Ogre2Camera::SetShadowsDirty() { diff --git a/ogre2/src/Ogre2RenderTarget.cc b/ogre2/src/Ogre2RenderTarget.cc index 88b4679f2..7abd56e1a 100644 --- a/ogre2/src/Ogre2RenderTarget.cc +++ b/ogre2/src/Ogre2RenderTarget.cc @@ -547,6 +547,16 @@ unsigned int Ogre2RenderTarget::GLIdImpl() const return static_cast(texId); } +////////////////////////////////////////////////// +void Ogre2RenderTarget::MetalIdImpl(void *_textureIdPtr) const +{ + if (!this->dataPtr->ogreTexture[0]) + return; + + this->dataPtr->ogreTexture[1]-> + getCustomAttribute("msFinalTextureBuffer", _textureIdPtr); +} + ////////////////////////////////////////////////// uint8_t Ogre2RenderTarget::TargetFSAA() const { @@ -883,6 +893,12 @@ unsigned int Ogre2RenderTexture::GLId() const return Ogre2RenderTarget::GLIdImpl(); } +////////////////////////////////////////////////// +void Ogre2RenderTexture::MetalId(void *_textureIdPtr) const +{ + Ogre2RenderTarget::MetalIdImpl(_textureIdPtr); +} + ////////////////////////////////////////////////// void Ogre2RenderTexture::PreRender() {