Divide Framework 0.1
A free and open-source 3D Framework under heavy development
Loading...
Searching...
No Matches
glFramebuffer.h
Go to the documentation of this file.
1/*
2 Copyright (c) 2018 DIVIDE-Studio
3 Copyright (c) 2009 Ionut Cava
4
5 This file is part of DIVIDE Framework.
6
7 Permission is hereby granted, free of charge, to any person obtaining a copy
8 of this software
9 and associated documentation files (the "Software"), to deal in the Software
10 without restriction,
11 including without limitation the rights to use, copy, modify, merge, publish,
12 distribute, sublicense,
13 and/or sell copies of the Software, and to permit persons to whom the
14 Software is furnished to do so,
15 subject to the following conditions:
16
17 The above copyright notice and this permission notice shall be included in
18 all copies or substantial portions of the Software.
19
20 THE SOFTWARE IS PROVIDED "AS IS", WITHOUT WARRANTY OF ANY KIND, EXPRESS OR
21 IMPLIED,
22 INCLUDING BUT NOT LIMITED TO THE WARRANTIES OF MERCHANTABILITY, FITNESS FOR A
23 PARTICULAR PURPOSE AND NONINFRINGEMENT.
24 IN NO EVENT SHALL THE AUTHORS OR COPYRIGHT HOLDERS BE LIABLE FOR ANY CLAIM,
25 DAMAGES OR OTHER LIABILITY,
26 WHETHER IN AN ACTION OF CONTRACT, TORT OR OTHERWISE, ARISING FROM, OUT OF OR
27 IN CONNECTION WITH THE SOFTWARE
28 OR THE USE OR OTHER DEALINGS IN THE SOFTWARE.
29
30 */
31
32#pragma once
33#ifndef GL_FRAME_BUFFER_H
34#define GL_FRAME_BUFFER_H
35
39
40namespace CEGUI
41{
42 class DVDTextureTarget;
43}
44
45namespace Divide {
46
47class GL_API;
48
49namespace Attorney {
50 class GLAPIRenderTarget;
51 class CEGUIRenderTarget;
52};
53
54class glFramebuffer final : public RenderTarget {
55
58
59 public:
60 enum class AttachmentState : U8
61 {
64 COUNT
65 };
66
68 {
71 bool _layeredRendering{false};
73
74 bool operator==(const BindingState&) const = default;
75 };
76
77 public:
78 explicit glFramebuffer(GFXDevice& context, const RenderTargetDescriptor& descriptor);
79 ~glFramebuffer() override;
80
81 void setMipLevel(U16 writeLevel);
82
83 void blitFrom(RenderTarget* source, const RTBlitParams& params);
84
86 bool create() override;
87
88
89 protected:
90 bool checkStatus();
91 bool checkStatusInternal( gl46core::GLuint handle);
92
93 void prepareBuffers(const RTDrawDescriptor& drawPolicy);
94
96
97 bool toggleAttachment( U8 attachmentIdx, AttachmentState state, U16 levelOffset, DrawLayerEntry layerOffset, bool layeredRendering);
98
99 void clear(const RTClearDescriptor& descriptor);
100 void begin(const RTDrawDescriptor& drawPolicy, const RTClearDescriptor& clearPolicy);
101 void end(const RTTransitionMask& mask);
102
103 PROPERTY_R_IW(Str<128>, debugMessage, "");
104 PROPERTY_R_IW( gl46core::GLuint, framebufferHandle, GL_NULL_HANDLE);
105
106 protected:
107 void resolve(const RTTransitionMask& mask);
108 bool setMipLevelInternal( U8 attachmentIdx, U16 writeLevel);
109 static void QueueMipMapsRecomputation(const RTAttachment_uptr& attachment);
110
111 protected:
113
115 std::array<DrawLayerEntry, RT_MAX_ATTACHMENT_COUNT> _previousDrawLayers;
116
118 {
119 std::array<gl46core::GLenum, to_base( RTColourAttachmentSlot::COUNT )> _glSlot = create_array<to_base( RTColourAttachmentSlot::COUNT ), gl46core::GLenum>( gl46core::GL_NONE);
120 bool _dirty{ true };
122
123 gl46core::GLenum _activeReadBuffer = gl46core::GL_NONE;
124
125 eastl::fixed_vector<BindingState, 8 + 2, true> _attachmentState;
126
127 bool _isLayeredDepth = false;
128 bool _statusCheckQueued = false;
129 bool _activeDepthBuffer = false;
130};
131
132namespace Attorney
133{
135 {
136 static void begin(glFramebuffer& rt, const RTDrawDescriptor& drawPolicy, const RTClearDescriptor& clearPolicy)
137 {
138 rt.begin(drawPolicy, clearPolicy);
139 }
140
141 static void end( glFramebuffer& rt, const RTTransitionMask& mask )
142 {
143 rt.end( mask );
144 }
145
146 friend class Divide::GL_API;
147 };
148}; // namespace Attorney
149
150namespace Attorney
151{
153 {
154 static void clear( glFramebuffer& rt, const RTClearDescriptor& clearPolicy )
155 {
156 rt.clear(clearPolicy);
157 }
158
160 };
161}; // namespace Attorney
162}; // namespace Divide
163
164#endif //GL_FRAME_BUFFER_H
static void clear(glFramebuffer &rt, const RTClearDescriptor &clearPolicy)
static void end(glFramebuffer &rt, const RTTransitionMask &mask)
static void begin(glFramebuffer &rt, const RTDrawDescriptor &drawPolicy, const RTClearDescriptor &clearPolicy)
Rough around the edges Adapter pattern abstracting the actual rendering API and access to the GPU.
Definition: GFXDevice.h:215
OpenGL implementation of the RenderAPIWrapper.
Definition: GLWrapper.h:65
GFXDevice & context() const noexcept
bool initAttachment(RTAttachment *att, RTAttachmentType type, RTColourAttachmentSlot slot) override
RTDrawDescriptor _previousPolicy
void blitFrom(RenderTarget *source, const RTBlitParams &params)
void begin(const RTDrawDescriptor &drawPolicy, const RTClearDescriptor &clearPolicy)
eastl::fixed_vector< BindingState, 8+2, true > _attachmentState
gl46core::GLuint _framebufferResolveHandle
bool setMipLevelInternal(U8 attachmentIdx, U16 writeLevel)
void end(const RTTransitionMask &mask)
void prepareBuffers(const RTDrawDescriptor &drawPolicy)
PROPERTY_R_IW(Str< 128 >, debugMessage, "")
gl46core::GLenum _activeReadBuffer
bool create() override
Bake in all settings and attachments to Prepare it for rendering.
void clear(const RTClearDescriptor &descriptor)
static void QueueMipMapsRecomputation(const RTAttachment_uptr &attachment)
void setMipLevel(U16 writeLevel)
bool toggleAttachment(U8 attachmentIdx, AttachmentState state, U16 levelOffset, DrawLayerEntry layerOffset, bool layeredRendering)
std::array< DrawLayerEntry, RT_MAX_ATTACHMENT_COUNT > _previousDrawLayers
struct Divide::glFramebuffer::ColourBufferState _colourBuffers
void resolve(const RTTransitionMask &mask)
bool checkStatusInternal(gl46core::GLuint handle)
PROPERTY_R_IW(gl46core::GLuint, framebufferHandle, GL_NULL_HANDLE)
Handle console commands that start with a forward slash.
Definition: AIProcessor.cpp:7
eastl::fixed_vector< RTBlitEntry, MAX_BLIT_ENTRIES, false > RTBlitParams
uint8_t U8
RTAttachmentType
This enum is used when creating render targets to define the channel that the texture will attach to.
Definition: RTAttachment.h:47
constexpr gl46core::GLuint GL_NULL_HANDLE
Invalid object value. Used to compare handles and determine if they were properly created.
Definition: glResources.h:105
uint16_t U16
RTColourAttachmentSlot
std::array< RTClearEntry, RT_MAX_ATTACHMENT_COUNT > RTClearDescriptor
bool[RT_MAX_ATTACHMENT_COUNT] RTTransitionMask
constexpr auto to_base(const Type value) -> Type
bool operator==(const BindingState &) const =default
std::array< gl46core::GLenum, to_base(RTColourAttachmentSlot::COUNT)> _glSlot