NAP
cubedepthrendertarget.h
1 /* This Source Code Form is subject to the terms of the Mozilla Public
2  * License, v. 2.0. If a copy of the MPL was not distributed with this
3  * file, You can obtain one at https://mozilla.org/MPL/2.0/. */
4 
5 #pragma once
6 
7 // Local Includes
8 #include "irendertarget.h"
9 #include "rendertexturecube.h"
10 
11 // External Includes
12 #include <nap/resource.h>
13 #include <nap/resourceptr.h>
14 #include <vulkan/vulkan_core.h>
15 
16 namespace nap
17 {
18  // Forward Declares
19  class DepthRenderTextureCube;
20  class CubeDepthRenderTarget;
21  class RenderService;
22  class PerspCameraComponentInstance;
23 
24  // Called when rendering a cube depth texture layer
25  using CubeDepthRenderTargetCallback = std::function<void(CubeDepthRenderTarget& target, const glm::mat4& projection, const glm::mat4& view)>;
26 
27 
29  // CubeDepthRenderTarget
31 
40  class NAPAPI CubeDepthRenderTarget : public Resource, public IRenderTarget
41  {
42  RTTI_ENABLE(Resource)
43  public:
49 
54 
60  virtual bool init(utility::ErrorState& errorState) override;
61 
65  virtual void beginRendering() override;
66 
70  virtual void endRendering() override;
71 
75  virtual const glm::ivec2 getBufferSize() const override { return mSize; }
76 
81  virtual void setClearColor(const RGBAColorFloat& color) override { mClearValue = color.getRed(); }
82 
86  virtual const RGBAColorFloat& getClearColor() const override { return mClearColor; }
87 
91  virtual ECullWindingOrder getWindingOrder() const override { return ECullWindingOrder::Clockwise; }
92 
96  virtual VkRenderPass getRenderPass() const override { return mRenderPass; }
97 
101  virtual VkFormat getColorFormat() const override { return VK_FORMAT_UNDEFINED; }
102 
106  virtual VkFormat getDepthFormat() const override { return mVulkanDepthFormat; }
107 
112  virtual VkSampleCountFlagBits getSampleCount() const override { return VK_SAMPLE_COUNT_1_BIT; }
113 
117  virtual bool getSampleShadingEnabled() const override { return mSampleShading; }
118 
122  glm::ivec2 getSize() const { return mSize; }
123 
141  void render(CubeDepthRenderTargetCallback renderCallback);
142 
160  void render(PerspCameraComponentInstance& camera, CubeDepthRenderTargetCallback renderCallback);
161 
162  bool mSampleShading = true;
163  float mClearValue = 1.0f;
166 
168 
169  private:
173  void renderInternal(const glm::vec3& camPosition, const glm::mat4& projectionMatrix, CubeDepthRenderTargetCallback renderCallback);
174 
178  void setLayerIndex(uint index);
179 
180  RenderService* mRenderService;
181  VkRenderPass mRenderPass = VK_NULL_HANDLE;
182  VkFormat mVulkanDepthFormat = VK_FORMAT_UNDEFINED;
183 
184  std::array<VkFramebuffer, TextureCube::layerCount> mFramebuffers = { VK_NULL_HANDLE };
185 
186  glm::ivec2 mSize;
187  RGBAColorFloat mClearColor = { 1.0f, 1.0f, 1.0f, 1.0f };
188  uint mLayerIndex = 0U;
189  bool mIsFirstPass = true;
190  };
191 }
nap::ECullWindingOrder::Clockwise
@ Clockwise
nap::uint
unsigned int uint
Definition: numeric.h:23
nap::CubeDepthRenderTarget::getSampleCount
virtual VkSampleCountFlagBits getSampleCount() const override
Definition: cubedepthrendertarget.h:112
nap::CubeDepthRenderTarget::getSampleShadingEnabled
virtual bool getSampleShadingEnabled() const override
Definition: cubedepthrendertarget.h:117
nap::IRenderTarget
Definition: irendertarget.h:21
nap::CubeDepthRenderTarget::getRenderPass
virtual VkRenderPass getRenderPass() const override
Definition: cubedepthrendertarget.h:96
nap::ERasterizationSamples::One
@ One
nap::ERasterizationSamples
ERasterizationSamples
Definition: renderutils.h:25
nap::DepthRenderTextureCube::EDepthFormat
EDepthFormat
Definition: rendertexturecube.h:99
nap::RGBAColor< float >
nap::rtti::ObjectPtr
Definition: objectptr.h:154
nap::ECullWindingOrder
ECullWindingOrder
Definition: materialcommon.h:30
nap::utility::ErrorState
Definition: errorstate.h:19
nap::CubeDepthRenderTarget::getBufferSize
virtual const glm::ivec2 getBufferSize() const override
Definition: cubedepthrendertarget.h:75
nap::CubeDepthRenderTarget::getSize
glm::ivec2 getSize() const
Definition: cubedepthrendertarget.h:122
nap::CubeDepthRenderTargetCallback
std::function< void(CubeDepthRenderTarget &target, const glm::mat4 &projection, const glm::mat4 &view)> CubeDepthRenderTargetCallback
Definition: cubedepthrendertarget.h:25
nap::RenderService
Definition: renderservice.h:275
nap::Core
Definition: core.h:82
nap::CubeDepthRenderTarget::mCubeDepthTexture
ResourcePtr< DepthRenderTextureCube > mCubeDepthTexture
Property: 'CubeDepthTexture' Cube depth texture to render to.
Definition: cubedepthrendertarget.h:167
nap::DepthRenderTextureCube::EDepthFormat::D32
@ D32
32 bit float, 1 component
nap::PerspCameraComponentInstance
Definition: perspcameracomponent.h:46
nap::CubeDepthRenderTarget::setClearColor
virtual void setClearColor(const RGBAColorFloat &color) override
Definition: cubedepthrendertarget.h:81
nap
Definition: templateapp.h:17
nap::CubeDepthRenderTarget::getColorFormat
virtual VkFormat getColorFormat() const override
Definition: cubedepthrendertarget.h:101
nap::CubeDepthRenderTarget::getClearColor
virtual const RGBAColorFloat & getClearColor() const override
Definition: cubedepthrendertarget.h:86
nap::Resource
Definition: resource.h:19
nap::CubeDepthRenderTarget::getDepthFormat
virtual VkFormat getDepthFormat() const override
Definition: cubedepthrendertarget.h:106
nap::CubeDepthRenderTarget::getWindingOrder
virtual ECullWindingOrder getWindingOrder() const override
Definition: cubedepthrendertarget.h:91
nap::CubeDepthRenderTarget
Definition: cubedepthrendertarget.h:40