Browse Source

Use Containers::Array instead of naked allocation in *Framebuffer.

GL_NONE is fortunately zero, so we can skip std::fill_n altogether and
replace it with zero-initialized allocation. Added just-in-case
static_assert to check that.
pull/34/head
Vladimír Vondruš 13 years ago
parent
commit
14cff2bdb8
  1. 13
      src/DefaultFramebuffer.cpp
  2. 13
      src/Framebuffer.cpp

13
src/DefaultFramebuffer.cpp

@ -45,37 +45,32 @@ DefaultFramebuffer& DefaultFramebuffer::mapForDraw(std::initializer_list<std::pa
/* Create linear array from associative */
/** @todo C++14: use VLA to avoid heap allocation */
GLenum* _attachments = new GLenum[max+1];
std::fill_n(_attachments, max, GL_NONE);
static_assert(GL_NONE == 0, "Expecting zero GL_NONE for zero-initialization");
auto _attachments = Containers::Array<GLenum>::zeroInitialized(max+1);
for(const auto& attachment: attachments)
_attachments[attachment.first] = GLenum(attachment.second);
(this->*drawBuffersImplementation)(max+1, _attachments);
delete[] _attachments;
return *this;
}
#endif
void DefaultFramebuffer::invalidate(std::initializer_list<InvalidationAttachment> attachments) {
/** @todo C++14: use VLA to avoid heap allocation */
GLenum* _attachments = new GLenum[attachments.size()];
Containers::Array<GLenum> _attachments(attachments.size());
for(std::size_t i = 0; i != attachments.size(); ++i)
_attachments[i] = GLenum(*(attachments.begin()+i));
invalidateImplementation(attachments.size(), _attachments);
delete[] _attachments;
}
void DefaultFramebuffer::invalidate(std::initializer_list<InvalidationAttachment> attachments, const Rectanglei& rectangle) {
/** @todo C++14: use VLA to avoid heap allocation */
GLenum* _attachments = new GLenum[attachments.size()];
Containers::Array<GLenum> _attachments(attachments.size());
for(std::size_t i = 0; i != attachments.size(); ++i)
_attachments[i] = GLenum(*(attachments.begin()+i));
invalidateImplementation(attachments.size(), _attachments, rectangle);
delete[] _attachments;
}
void DefaultFramebuffer::initializeContextBasedFunctionality(Context& context) {

13
src/Framebuffer.cpp

@ -94,36 +94,31 @@ Framebuffer& Framebuffer::mapForDraw(std::initializer_list<std::pair<UnsignedInt
/* Create linear array from associative */
/** @todo C++14: use VLA to avoid heap allocation */
GLenum* _attachments = new GLenum[max+1];
std::fill_n(_attachments, max, GL_NONE);
static_assert(GL_NONE == 0, "Expecting zero GL_NONE for zero-initialization");
auto _attachments = Containers::Array<GLenum>::zeroInitialized(max+1);
for(const auto& attachment: attachments)
_attachments[attachment.first] = GLenum(attachment.second);
(this->*drawBuffersImplementation)(max+1, _attachments);
delete[] _attachments;
return *this;
}
void Framebuffer::invalidate(std::initializer_list<InvalidationAttachment> attachments) {
/** @todo C++14: use VLA to avoid heap allocation */
GLenum* _attachments = new GLenum[attachments.size()];
Containers::Array<GLenum> _attachments(attachments.size());
for(std::size_t i = 0; i != attachments.size(); ++i)
_attachments[i] = GLenum(*(attachments.begin()+i));
invalidateImplementation(attachments.size(), _attachments);
delete[] _attachments;
}
void Framebuffer::invalidate(std::initializer_list<InvalidationAttachment> attachments, const Rectanglei& rectangle) {
/** @todo C++14: use VLA to avoid heap allocation */
GLenum* _attachments = new GLenum[attachments.size()];
Containers::Array<GLenum> _attachments(attachments.size());
for(std::size_t i = 0; i != attachments.size(); ++i)
_attachments[i] = GLenum(*(attachments.begin()+i));
invalidateImplementation(attachments.size(), _attachments, rectangle);
delete[] _attachments;
}
Framebuffer& Framebuffer::attachTexture2D(BufferAttachment attachment, Texture2D& texture, Int mipLevel) {

Loading…
Cancel
Save