NAP
rendertarget.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 "rendertexture2d.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 RenderTexture2D;
20  class RenderService;
21 
53  class NAPAPI RenderTarget : public Resource, public IRenderTarget
54  {
55  RTTI_ENABLE(Resource)
56  public:
61  RenderTarget(Core& core);
62 
66  ~RenderTarget();
67 
73  virtual bool init(utility::ErrorState& errorState) override;
74 
93  virtual void beginRendering() override;
94 
112  virtual void endRendering() override;
113 
117  virtual const glm::ivec2 getBufferSize() const override;
118 
123  virtual void setClearColor(const RGBAColorFloat& color) override { mClearColor = color; }
124 
128  virtual const RGBAColorFloat& getClearColor() const override { return mClearColor; }
129 
134 
138  virtual VkRenderPass getRenderPass() const override { return mRenderPass; }
139 
143  bool hasDepthTexture() const { return mHasDepthTexture; }
144 
148  RenderTexture2D& getColorTexture();
149 
155  DepthRenderTexture2D& getDepthTexture();
156 
160  virtual VkFormat getColorFormat() const override;
161 
165  virtual VkFormat getDepthFormat() const override;
166 
170  virtual VkSampleCountFlagBits getSampleCount() const override;
171 
175  virtual bool getSampleShadingEnabled() const override;
176 
177  public:
178  bool mSampleShading = true;
179  RGBAColorFloat mClearColor = { 0.0f, 0.0f, 0.0f, 0.0f };
183 
184  private:
185  RenderService* mRenderService;
186  VkFramebuffer mFramebuffer = VK_NULL_HANDLE;
187  VkRenderPass mRenderPass = VK_NULL_HANDLE;
188  VkSampleCountFlagBits mRasterizationSamples = VK_SAMPLE_COUNT_1_BIT;
189  ImageData mDepthImage;
190  ImageData mColorImage;
191  bool mHasDepthTexture = false;
192  };
193 }
nap::ECullWindingOrder::Clockwise
@ Clockwise
nap::IRenderTarget
Definition: irendertarget.h:21
nap::DepthRenderTexture2D
Definition: rendertexture2d.h:69
nap::ERasterizationSamples::One
@ One
nap::ERasterizationSamples
ERasterizationSamples
Definition: renderutils.h:25
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::RenderTarget::hasDepthTexture
bool hasDepthTexture() const
Definition: rendertarget.h:143
nap::RenderTarget::setClearColor
virtual void setClearColor(const RGBAColorFloat &color) override
Definition: rendertarget.h:123
nap::RenderTarget::mDepthTexture
ResourcePtr< DepthRenderTexture2D > mDepthTexture
Property: 'DepthTexture' optional depth texture to render to.
Definition: rendertarget.h:182
nap::ImageData
Definition: imagedata.h:23
nap::RenderService
Definition: renderservice.h:275
nap::Core
Definition: core.h:82
nap::RenderTarget::getRenderPass
virtual VkRenderPass getRenderPass() const override
Definition: rendertarget.h:138
nap::RenderTarget
Definition: rendertarget.h:53
nap
Definition: templateapp.h:17
nap::Resource
Definition: resource.h:19
nap::RenderTarget::mColorTexture
ResourcePtr< RenderTexture2D > mColorTexture
Property: 'ColorTexture' texture to render to.
Definition: rendertarget.h:181
nap::RenderTarget::getClearColor
virtual const RGBAColorFloat & getClearColor() const override
Definition: rendertarget.h:128
nap::RenderTexture2D
Definition: rendertexture2d.h:24
nap::RenderTarget::getWindingOrder
virtual ECullWindingOrder getWindingOrder() const override
Definition: rendertarget.h:133