11 #ifndef hifi_gpu_Framebuffer_h
12 #define hifi_gpu_Framebuffer_h
15 #include "ResourceSwapChain.h"
22 typedef Element Format;
27 uint16 getWidth()
const {
return _width; }
28 uint16 getHeight()
const {
return _height; }
29 uint16 getNumSamples()
const {
return _numSamples; }
31 bool hasDepthStencil()
const {
return _hasDepthStencil; }
32 bool isFullscreen()
const {
return _isFullscreen; }
34 uint32 getSwapInterval()
const {
return _swapInterval; }
36 bool isStereo()
const {
return _isStereo; }
38 uint32 getFrameCount()
const {
return _frameCount; }
41 void setSwapInterval(uint32 interval);
43 void resize(uint16 width, uint16 height);
44 void setFullscreen(
bool fullscreen);
47 Swapchain(
const Swapchain& swapchain) {}
48 virtual ~Swapchain() {}
51 mutable uint32 _frameCount = 0;
56 uint16 _numSamples = 1;
57 uint16 _swapInterval = 0;
59 bool _hasDepthStencil =
false;
60 bool _isFullscreen =
false;
61 bool _isStereo =
false;
65 friend class Framebuffer;
67 typedef std::shared_ptr<Swapchain> SwapchainPointer;
81 BUFFER_COLORS = 0x000000FF,
83 BUFFER_DEPTH = 0x40000000,
84 BUFFER_STENCIL = 0x80000000,
85 BUFFER_DEPTHSTENCIL = 0xC0000000,
91 static Framebuffer* create(
const SwapchainPointer& swapchain);
92 static Framebuffer* create(
const std::string& name);
93 static Framebuffer* create(
const std::string& name,
const Format& colorBufferFormat, uint16 width, uint16 height);
94 static Framebuffer* create(
const std::string& name,
const Format& colorBufferFormat,
const Format& depthStencilBufferFormat, uint16 width, uint16 height);
95 static Framebuffer* createShadowmap(uint16 width);
97 bool isSwapchain()
const;
98 const SwapchainPointer& getSwapchain()
const {
return _swapchain; }
100 uint32 getFrameCount()
const;
103 void removeRenderBuffers();
104 uint32 getNumRenderBuffers()
const;
105 const TextureViews& getRenderBuffers()
const {
return _renderBuffers; }
107 int32 setRenderBuffer(uint32 slot,
const TexturePointer& texture, uint32 subresource = 0);
108 const TexturePointer& getRenderBuffer(uint32 slot)
const;
109 uint32 getRenderBufferSubresource(uint32 slot)
const;
111 bool setDepthBuffer(
const TexturePointer& texture,
const Format& format, uint32 subresource = 0);
112 bool setStencilBuffer(
const TexturePointer& texture,
const Format& format, uint32 subresource = 0);
113 bool setDepthStencilBuffer(
const TexturePointer& texture,
const Format& format, uint32 subresource = 0);
114 const TexturePointer& getDepthStencilBuffer()
const;
115 uint32 getDepthStencilBufferSubresource()
const;
116 Format getDepthStencilBufferFormat()
const;
120 Masks getBufferMask()
const {
return _bufferMask; }
121 bool isEmpty()
const {
return (_bufferMask == 0); }
122 bool hasColor()
const {
return (getBufferMask() & BUFFER_COLORS); }
123 bool hasDepthStencil()
const {
return (getBufferMask() & BUFFER_DEPTHSTENCIL); }
124 bool hasDepth()
const {
return (getBufferMask() & BUFFER_DEPTH); }
125 bool hasStencil()
const {
return (getBufferMask() & BUFFER_STENCIL); }
127 bool validateTargetCompatibility(
const Texture& texture, uint32 subresource = 0)
const;
129 Vec2u getSize()
const {
return Vec2u(getWidth(), getHeight()); }
130 uint16 getWidth()
const;
131 uint16 getHeight()
const;
132 uint16 getNumSamples()
const;
133 const std::string& getName()
const {
return _name; }
134 void setName(
const std::string& name) { _name = name; }
136 float getAspectRatio()
const {
return getWidth() / (float) getHeight() ; }
138 #if !defined(Q_OS_ANDROID)
139 static const uint32 MAX_NUM_RENDER_BUFFERS = 8;
141 static const uint32 MAX_NUM_RENDER_BUFFERS = 4;
143 static uint32 getMaxNumRenderBuffers() {
return MAX_NUM_RENDER_BUFFERS; }
145 const GPUObjectPointer gpuObject {};
147 Stamp getDepthStamp()
const {
return _depthStamp; }
148 const std::vector<Stamp>& getColorStamps()
const {
return _colorStamps; }
150 static glm::vec4 evalSubregionTexcoordTransformCoefficients(
const glm::ivec2& sourceSurface,
const glm::ivec2& destRegionSize,
const glm::ivec2& destRegionOffset = glm::ivec2(0));
151 static glm::vec4 evalSubregionTexcoordTransformCoefficients(
const glm::ivec2& sourceSurface,
const glm::ivec4& destViewport);
153 static Transform evalSubregionTexcoordTransform(
const glm::ivec2& sourceSurface,
const glm::ivec2& destRegionSize,
const glm::ivec2& destRegionOffset = glm::ivec2(0));
154 static Transform evalSubregionTexcoordTransform(
const glm::ivec2& sourceSurface,
const glm::ivec4& destViewport);
158 SwapchainPointer _swapchain;
160 Stamp _depthStamp { 0 };
161 std::vector<Stamp> _colorStamps;
162 TextureViews _renderBuffers;
163 TextureView _depthStencilBuffer;
165 Masks _bufferMask = 0;
167 uint32 _frameCount = 0;
171 uint16 _numSamples = 0;
173 void updateSize(
const TexturePointer& texture);
174 bool assignDepthStencilBuffer(
const TexturePointer& texture,
const Format& format, uint32 subresource);
176 friend class Serializer;
177 friend class Deserializer;
179 Framebuffer(
const Framebuffer& framebuffer) =
delete;
182 typedef std::shared_ptr<Framebuffer> FramebufferPointer;
183 typedef ResourceSwapChain<Framebuffer> FramebufferSwapChain;
184 typedef std::shared_ptr<FramebufferSwapChain> FramebufferSwapChainPointer;
A simple object wrapper for an OpenGL texture.
Definition: material-networking/src/material-networking/TextureCache.h:39