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 #include "texturelink.h"
11 
12 // External Includes
13 #include <nap/resource.h>
14 #include <nap/resourceptr.h>
15 #include <vulkan/vulkan_core.h>
16 
17 namespace nap
18 {
19  // Forward Declares
20  class RenderTexture2D;
21  class RenderService;
22 
48  class NAPAPI RenderTarget : public Resource, public IRenderTarget
49  {
50  RTTI_ENABLE(Resource)
51  public:
56  RenderTarget(Core& core);
57 
61  ~RenderTarget();
62 
68  virtual bool init(utility::ErrorState& errorState) override;
69 
88  virtual void beginRendering() override;
89 
107  virtual void endRendering() override;
108 
112  virtual const glm::ivec2 getBufferSize() const override;
113 
118  virtual void setClearColor(const RGBAColorFloat& color) override { mClearColor = color; }
119 
123  virtual const RGBAColorFloat& getClearColor() const override { return mClearColor; }
124 
129 
133  virtual VkRenderPass getRenderPass() const override { return mRenderPass; }
134 
138  RenderTexture2D& getColorTexture();
139 
143  virtual VkFormat getColorFormat() const override;
144 
148  virtual VkFormat getDepthFormat() const override;
149 
153  virtual VkSampleCountFlagBits getSampleCount() const override;
154 
158  virtual bool getSampleShadingEnabled() const override;
159 
163  virtual VkImageLayout getFinalLayout() const override { return VK_IMAGE_LAYOUT_SHADER_READ_ONLY_OPTIMAL; }
164 
165  public:
166  bool mSampleShading = true;
167  RGBAColorFloat mClearColor = { 0.0f, 0.0f, 0.0f, 0.0f };
170  bool mClear = true;
171 
172  private:
173  RenderService* mRenderService;
174  VkFramebuffer mFramebuffer = VK_NULL_HANDLE;
175  VkRenderPass mRenderPass = VK_NULL_HANDLE;
176  VkSampleCountFlagBits mRasterizationSamples = VK_SAMPLE_COUNT_1_BIT;
177  ImageData mDepthImage;
178  ImageData mColorImage;
179  Texture2DTargetLink mTextureLink;
180  };
181 }
nap::ECullWindingOrder::Clockwise
@ Clockwise
nap::IRenderTarget
Definition: irendertarget.h:21
nap::ERasterizationSamples::One
@ One
nap::ERasterizationSamples
ERasterizationSamples
Definition: renderutils.h:25
nap::RGBAColor< float >
nap::rtti::ObjectPtr
Definition: objectptr.h:150
nap::ECullWindingOrder
ECullWindingOrder
Definition: materialcommon.h:30
nap::utility::ErrorState
Definition: errorstate.h:19
nap::RenderTarget::setClearColor
virtual void setClearColor(const RGBAColorFloat &color) override
Definition: rendertarget.h:118
nap::ImageData
Definition: imagedata.h:23
nap::RenderService
Definition: renderservice.h:198
nap::Core
Definition: core.h:82
nap::RenderTarget::getRenderPass
virtual VkRenderPass getRenderPass() const override
Definition: rendertarget.h:133
nap::RenderTarget
Definition: rendertarget.h:48
nap::RenderTarget::getFinalLayout
virtual VkImageLayout getFinalLayout() const override
Definition: rendertarget.h:163
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:169
nap::RenderTarget::getClearColor
virtual const RGBAColorFloat & getClearColor() const override
Definition: rendertarget.h:123
nap::RenderTexture2D
Definition: rendertexture2d.h:24
nap::RenderTarget::getWindingOrder
virtual ECullWindingOrder getWindingOrder() const override
Definition: rendertarget.h:128