Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Add a method to render targets and cameras to retrieve a Metal texture #478

Merged
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
8 changes: 8 additions & 0 deletions include/ignition/rendering/Camera.hh
Original file line number Diff line number Diff line change
Expand Up @@ -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<MTLTexture> 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;
Expand Down
7 changes: 7 additions & 0 deletions include/ignition/rendering/RenderTarget.hh
Original file line number Diff line number Diff line change
Expand Up @@ -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<MTLTexture> using CFBridgingRelease.
/// \param[out] _textureIdPtr the address of a void* pointer.
public: virtual void MetalId(void *_textureIdPtr) const = 0;
};

/* \class RenderWindow RenderWindow.hh \
Expand Down
12 changes: 12 additions & 0 deletions include/ignition/rendering/base/BaseCamera.hh
Original file line number Diff line number Diff line change
Expand Up @@ -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;

Expand Down Expand Up @@ -804,6 +808,14 @@ namespace ignition
return 0u;
}

//////////////////////////////////////////////////
template <class T>
void BaseCamera<T>::RenderTextureMetalId(void */*_textureIdPtr*/) const
{
ignerr << "RenderTextureMetalId is not supported by current render"
<< " engine" << std::endl;
}

//////////////////////////////////////////////////
template <class T>
void BaseCamera<T>::AddRenderPass(const RenderPassPtr &_pass)
Expand Down
9 changes: 9 additions & 0 deletions include/ignition/rendering/base/BaseRenderTarget.hh
Original file line number Diff line number Diff line change
Expand Up @@ -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 <class T>
Expand Down Expand Up @@ -291,6 +294,12 @@ namespace ignition
return 0u;
}

//////////////////////////////////////////////////
template <class T>
void BaseRenderTexture<T>::MetalId(void */*_textureIdPtr*/) const
{
}

//////////////////////////////////////////////////
// BaseRenderWindow
//////////////////////////////////////////////////
Expand Down
4 changes: 4 additions & 0 deletions ogre2/include/ignition/rendering/ogre2/Ogre2Camera.hh
Original file line number Diff line number Diff line change
Expand Up @@ -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;

Expand Down
6 changes: 6 additions & 0 deletions ogre2/include/ignition/rendering/ogre2/Ogre2RenderTarget.hh
Original file line number Diff line number Diff line change
Expand Up @@ -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();

Expand Down Expand Up @@ -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.
Expand Down
15 changes: 15 additions & 0 deletions ogre2/src/Ogre2Camera.cc
Original file line number Diff line number Diff line change
Expand Up @@ -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<Ogre2RenderTexture>(this->renderTexture);

if (!rt)
return;

rt->MetalId(_textureIdPtr);
}

//////////////////////////////////////////////////
void Ogre2Camera::SetShadowsDirty()
{
Expand Down
16 changes: 16 additions & 0 deletions ogre2/src/Ogre2RenderTarget.cc
Original file line number Diff line number Diff line change
Expand Up @@ -547,6 +547,16 @@ unsigned int Ogre2RenderTarget::GLIdImpl() const
return static_cast<unsigned int>(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
{
Expand Down Expand Up @@ -883,6 +893,12 @@ unsigned int Ogre2RenderTexture::GLId() const
return Ogre2RenderTarget::GLIdImpl();
}

//////////////////////////////////////////////////
void Ogre2RenderTexture::MetalId(void *_textureIdPtr) const
{
Ogre2RenderTarget::MetalIdImpl(_textureIdPtr);
}

//////////////////////////////////////////////////
void Ogre2RenderTexture::PreRender()
{
Expand Down