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 necessary headers for Vulkan QML GUI backend #706

Merged
merged 7 commits into from
Oct 15, 2022
Merged
Show file tree
Hide file tree
Changes from 4 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
10 changes: 9 additions & 1 deletion include/gz/rendering/Camera.hh
Original file line number Diff line number Diff line change
Expand Up @@ -79,7 +79,9 @@ namespace gz

/// \brief Set the image pixel format
/// \param[in] _format New image pixel format
public: virtual void SetImageFormat(PixelFormat _format) = 0;
/// \param[in] _reinterpretable See RenderTarget::SetFormat
public: virtual void SetImageFormat(PixelFormat _format,
bool _reinterpretable = false) = 0;

/// \brief Get the total image memory size in bytes
/// \return The image memory size in bytes
Expand Down Expand Up @@ -332,6 +334,12 @@ namespace gz
/// \param[out] _textureIdPtr the address of a void* pointer.
public: virtual void RenderTextureMetalId(void *_textureIdPtr) const = 0;

/// \brief Right now this is Vulkan-only. This function needs to be
/// called after rendering, and before handling the texture pointer
/// (i.e. by calling RenderTextureMetalId()) so that external APIs
/// (e.g. Qt) can sample the texture.
public: virtual void PrepareForExternalSampling() = 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
61 changes: 61 additions & 0 deletions include/gz/rendering/RenderEngineVulkanExternalDeviceStructs.hh
Original file line number Diff line number Diff line change
@@ -0,0 +1,61 @@
/*
* Copyright (C) 2022 Open Source Robotics Foundation
*
* Licensed under the Apache License, Version 2.0 (the "License");
* you may not use this file except in compliance with the License.
* You may obtain a copy of the License at
*
* http://www.apache.org/licenses/LICENSE-2.0
*
* Unless required by applicable law or agreed to in writing, software
* distributed under the License is distributed on an "AS IS" BASIS,
* WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
* See the License for the specific language governing permissions and
* limitations under the License.
*
*/
#ifndef GZ_RENDERING_RENDERENGINE_VULKANEXTERNALDEVICESTRUCTS_HH_
#define GZ_RENDERING_RENDERENGINE_VULKANEXTERNALDEVICESTRUCTS_HH_

#ifndef __APPLE__

# include <vector>
# include "gz/rendering/Export.hh"
# include "gz/rendering/config.hh"

# include "vulkan/vulkan_core.h"
darksylinc marked this conversation as resolved.
Show resolved Hide resolved
darksylinc marked this conversation as resolved.
Show resolved Hide resolved

namespace gz
{
namespace rendering
{
inline namespace GZ_RENDERING_VERSION_NAMESPACE {
/// \brief Structure to encapsulate data needed by OgreNext to init Vulkan
/// from Qt.
/// Mirrors Ogre::VulkanExternalInstance without depending on OgreNext
/// directly.
struct GZ_RENDERING_VISIBLE GzVulkanExternalInstance
{
VkInstance instance;
std::vector<VkLayerProperties> instanceLayers;
std::vector<VkExtensionProperties> instanceExtensions;
};

/// \brief Structure to encapsulate data needed by OgreNext to init Vulkan
/// from Qt.
/// Mirrors Ogre::VulkanExternalDevice without depending on OgreNext
/// directly.
struct GZ_RENDERING_VISIBLE GzVulkanExternalDevice
{
VkPhysicalDevice physicalDevice;
VkDevice device;
std::vector<VkExtensionProperties> deviceExtensions;
VkQueue graphicsQueue;
VkQueue presentQueue;
};
}
}
}

#endif
#endif
10 changes: 9 additions & 1 deletion include/gz/rendering/RenderTarget.hh
Original file line number Diff line number Diff line change
Expand Up @@ -62,7 +62,15 @@ namespace gz

/// \brief Set the render target image format
/// \param[in] _format New target format
public: virtual void SetFormat(PixelFormat _format) = 0;
/// \param[in] _reinterpretable whether the RenderTarget will be
/// reinterpreted to another format (e.g.
/// from RGBA8_UNORM to/from RGBA8_UNORM_SRGB)
public: virtual void SetFormat(PixelFormat _format,
bool _reinterpretable = false) = 0;

/// \brief See SetFormat()
/// \return True if format is reinterpretable
public: virtual bool Reinterpretable() const = 0;

/// \brief Write rendered image to given Image. The RenderTarget will
/// convert the underlying image to the specified format listed in the
Expand Down
20 changes: 17 additions & 3 deletions include/gz/rendering/base/BaseCamera.hh
Original file line number Diff line number Diff line change
Expand Up @@ -61,7 +61,9 @@ namespace gz

public: virtual unsigned int ImageMemorySize() const override;

public: virtual void SetImageFormat(PixelFormat _format) override;
public: virtual void SetImageFormat(PixelFormat _format,
bool _reinterpretable = false)
override;

public: virtual math::Angle HFOV() const override;

Expand Down Expand Up @@ -186,6 +188,9 @@ namespace gz
public: virtual void RenderTextureMetalId(void *_textureIdPtr)
const override;

// Documentation inherited.
public: virtual void PrepareForExternalSampling() override;

// Documentation inherited.
public: virtual void AddRenderPass(const RenderPassPtr &_pass) override;

Expand Down Expand Up @@ -332,9 +337,10 @@ namespace gz

//////////////////////////////////////////////////
template <class T>
void BaseCamera<T>::SetImageFormat(PixelFormat _format)
void BaseCamera<T>::SetImageFormat(PixelFormat _format,
bool _reinterpretable)
{
this->RenderTarget()->SetFormat(_format);
this->RenderTarget()->SetFormat(_format, _reinterpretable);
}

//////////////////////////////////////////////////
Expand Down Expand Up @@ -843,6 +849,14 @@ namespace gz
<< " engine" << std::endl;
}

//////////////////////////////////////////////////
template <class T>
void BaseCamera<T>::PrepareForExternalSampling()
{
gzerr << "PrepareForExternalSampling is not supported by current render"
<< " engine" << std::endl;
}

//////////////////////////////////////////////////
template <class T>
void BaseCamera<T>::AddRenderPass(const RenderPassPtr &_pass)
Expand Down
19 changes: 17 additions & 2 deletions include/gz/rendering/base/BaseRenderTarget.hh
Original file line number Diff line number Diff line change
Expand Up @@ -56,7 +56,11 @@ namespace gz

public: virtual PixelFormat Format() const override;

public: virtual void SetFormat(PixelFormat _format) override;
public: virtual void SetFormat(PixelFormat _format,
bool _reinterpretable = false) override;

// Documentation inherited
public: virtual bool Reinterpretable() const override;

// Documentation inherited
public: virtual math::Color BackgroundColor() const override;
Expand All @@ -81,6 +85,8 @@ namespace gz

protected: PixelFormat format = PF_UNKNOWN;

protected: bool reinterpretable = false;

protected: bool targetDirty = true;

/// \brief Flag to indicate if render pass need to be rebuilt
Expand Down Expand Up @@ -218,12 +224,21 @@ namespace gz

//////////////////////////////////////////////////
template <class T>
void BaseRenderTarget<T>::SetFormat(PixelFormat _format)
void BaseRenderTarget<T>::SetFormat(PixelFormat _format,
bool _reinterpretable)
{
this->format = PixelUtil::Sanitize(_format);
this->reinterpretable = _reinterpretable;
this->targetDirty = true;
}

//////////////////////////////////////////////////
template <class T>
bool BaseRenderTarget<T>::Reinterpretable() const
{
return this->reinterpretable;
}

//////////////////////////////////////////////////
template <class T>
math::Color BaseRenderTarget<T>::BackgroundColor() const
Expand Down
3 changes: 3 additions & 0 deletions ogre2/include/gz/rendering/ogre2/Ogre2Camera.hh
Original file line number Diff line number Diff line change
Expand Up @@ -126,6 +126,9 @@ namespace gz
public: virtual void RenderTextureMetalId(void *_textureIdPtr)
const override;

// Documentation inherited.
public: virtual void PrepareForExternalSampling() override;

// Documentation inherited.
public: void SetShadowsDirty() override;

Expand Down
3 changes: 3 additions & 0 deletions ogre2/include/gz/rendering/ogre2/Ogre2RenderTarget.hh
Original file line number Diff line number Diff line change
Expand Up @@ -139,6 +139,9 @@ namespace gz
// Documentation inherited
public: void MetalIdImpl(void *_textureIdPtr) const;

/// \brief See Camera::PrepareForExternalSampling
public: void PrepareForExternalSampling();

/// \brief Destroy the render texture
protected: void DestroyTargetImpl();

Expand Down
8 changes: 8 additions & 0 deletions ogre2/src/Ogre2Camera.cc
Original file line number Diff line number Diff line change
Expand Up @@ -230,6 +230,14 @@ void Ogre2Camera::RenderTextureMetalId(void *_textureIdPtr) const
rt->MetalId(_textureIdPtr);
}

//////////////////////////////////////////////////
void Ogre2Camera::PrepareForExternalSampling()
{
if (!this->renderTexture)
return;
this->renderTexture->PrepareForExternalSampling();
}

//////////////////////////////////////////////////
void Ogre2Camera::SetShadowsDirty()
{
Expand Down
Loading