-
Notifications
You must be signed in to change notification settings - Fork 434
/
DefaultFramebuffer.cpp
147 lines (118 loc) · 5.9 KB
/
DefaultFramebuffer.cpp
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
65
66
67
68
69
70
71
72
73
74
75
76
77
78
79
80
81
82
83
84
85
86
87
88
89
90
91
92
93
94
95
96
97
98
99
100
101
102
103
104
105
106
107
108
109
110
111
112
113
114
115
116
117
118
119
120
121
122
123
124
125
126
127
128
129
130
131
132
133
134
135
136
137
138
139
140
141
142
143
144
145
146
147
/*
This file is part of Magnum.
Copyright © 2010, 2011, 2012, 2013, 2014, 2015, 2016, 2017, 2018, 2019,
2020, 2021, 2022, 2023 Vladimír Vondruš <mosra@centrum.cz>
Permission is hereby granted, free of charge, to any person obtaining a
copy of this software and associated documentation files (the "Software"),
to deal in the Software without restriction, including without limitation
the rights to use, copy, modify, merge, publish, distribute, sublicense,
and/or sell copies of the Software, and to permit persons to whom the
Software is furnished to do so, subject to the following conditions:
The above copyright notice and this permission notice shall be included
in all copies or substantial portions of the Software.
THE SOFTWARE IS PROVIDED "AS IS", WITHOUT WARRANTY OF ANY KIND, EXPRESS OR
IMPLIED, INCLUDING BUT NOT LIMITED TO THE WARRANTIES OF MERCHANTABILITY,
FITNESS FOR A PARTICULAR PURPOSE AND NONINFRINGEMENT. IN NO EVENT SHALL
THE AUTHORS OR COPYRIGHT HOLDERS BE LIABLE FOR ANY CLAIM, DAMAGES OR OTHER
LIABILITY, WHETHER IN AN ACTION OF CONTRACT, TORT OR OTHERWISE, ARISING
FROM, OUT OF OR IN CONNECTION WITH THE SOFTWARE OR THE USE OR OTHER
DEALINGS IN THE SOFTWARE.
*/
#include "DefaultFramebuffer.h"
#include <Corrade/Containers/Array.h>
#include "Magnum/GL/Context.h"
#include "Magnum/GL/Extensions.h"
#include "Magnum/GL/Implementation/State.h"
#include "Magnum/GL/Implementation/FramebufferState.h"
#ifndef MAGNUM_TARGET_GLES2
#include "Magnum/Math/Color.h"
#endif
namespace Magnum { namespace GL {
DefaultFramebuffer defaultFramebuffer;
DefaultFramebuffer::Status DefaultFramebuffer::checkStatus(const FramebufferTarget target) {
return Status(Context::current().state().framebuffer.checkStatusImplementation(*this, target));
}
#ifndef MAGNUM_TARGET_GLES2
DefaultFramebuffer& DefaultFramebuffer::clearColor(const Color4& color) {
Context::current().state().framebuffer.clearFImplementation(*this, GL_COLOR, 0, color.data());
return *this;
}
DefaultFramebuffer& DefaultFramebuffer::clearColor(const Vector4i& color) {
Context::current().state().framebuffer.clearIImplementation(*this, GL_COLOR, 0, color.data());
return *this;
}
DefaultFramebuffer& DefaultFramebuffer::clearColor(const Vector4ui& color) {
Context::current().state().framebuffer.clearUIImplementation(*this, GL_COLOR, 0, color.data());
return *this;
}
#endif
DefaultFramebuffer& DefaultFramebuffer::mapForDraw(const Containers::ArrayView<const Containers::Pair<UnsignedInt, DrawAttachment>> attachments) {
/* Max attachment location */
std::size_t max = 0;
for(const auto& attachment: attachments)
if(attachment.first() > max) max = attachment.first();
/* Create linear array from associative */
/** @todo C++14: use VLA to avoid heap allocation */
static_assert(GL_NONE == 0, "Expecting zero GL_NONE for zero-initialization");
Containers::Array<GLenum> _attachments{ValueInit, max+1};
for(const auto& attachment: attachments)
_attachments[attachment.first()] = GLenum(attachment.second());
Context::current().state().framebuffer.drawBuffersImplementation(*this, max+1, _attachments);
return *this;
}
DefaultFramebuffer& DefaultFramebuffer::mapForDraw(std::initializer_list<Containers::Pair<UnsignedInt, DrawAttachment>> attachments) {
return mapForDraw(Containers::arrayView(attachments));
}
DefaultFramebuffer& DefaultFramebuffer::mapForDraw(const DrawAttachment attachment) {
#ifndef MAGNUM_TARGET_GLES
Context::current().state().framebuffer.drawBufferImplementation(*this, GLenum(attachment));
#else
Context::current().state().framebuffer.drawBuffersImplementation(*this, 1, reinterpret_cast<const GLenum*>(&attachment));
#endif
return *this;
}
#if !(defined(MAGNUM_TARGET_WEBGL) && defined(MAGNUM_TARGET_GLES2))
DefaultFramebuffer& DefaultFramebuffer::mapForRead(const ReadAttachment attachment) {
Context::current().state().framebuffer.readBufferImplementation(*this, GLenum(attachment));
return *this;
}
void DefaultFramebuffer::invalidate(Containers::ArrayView<const InvalidationAttachment> attachments) {
/** @todo C++14: use VLA to avoid heap allocation */
Containers::Array<GLenum> _attachments(attachments.size());
for(std::size_t i = 0; i != attachments.size(); ++i)
_attachments[i] = GLenum(*(attachments.begin()+i));
Context::current().state().framebuffer.invalidateImplementation(*this, attachments.size(), _attachments);
}
void DefaultFramebuffer::invalidate(std::initializer_list<InvalidationAttachment> attachments) {
invalidate(Containers::arrayView(attachments));
}
#endif
#ifndef MAGNUM_TARGET_GLES2
void DefaultFramebuffer::invalidate(const Containers::ArrayView<const InvalidationAttachment> attachments, const Range2Di& rectangle) {
/** @todo C++14: use VLA to avoid heap allocation */
Containers::Array<GLenum> _attachments(attachments.size());
for(std::size_t i = 0; i != attachments.size(); ++i)
_attachments[i] = GLenum(*(attachments.begin()+i));
Context::current().state().framebuffer.invalidateSubImplementation(*this, attachments.size(), _attachments, rectangle);
}
void DefaultFramebuffer::invalidate(std::initializer_list<InvalidationAttachment> attachments, const Range2Di& rectangle) {
invalidate(Containers::arrayView(attachments), rectangle);
}
#endif
#ifndef DOXYGEN_GENERATING_OUTPUT
Debug& operator<<(Debug& debug, const DefaultFramebuffer::Status value) {
debug << "GL::DefaultFramebuffer::Status" << Debug::nospace;
switch(value) {
/* LCOV_EXCL_START */
#define _c(value) case DefaultFramebuffer::Status::value: return debug << "::" #value;
_c(Complete)
#ifndef MAGNUM_TARGET_WEBGL
_c(Undefined)
#endif
#undef _c
/* LCOV_EXCL_STOP */
}
return debug << "(" << Debug::nospace << Debug::hex << GLenum(value) << Debug::nospace << ")";
}
#endif
}}