From 14cff2bdb88f2c41b6b3c6ec51df73a32068c13b Mon Sep 17 00:00:00 2001 From: =?UTF-8?q?Vladim=C3=ADr=20Vondru=C5=A1?= Date: Sun, 17 Nov 2013 19:00:47 +0100 Subject: [PATCH] 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. --- src/DefaultFramebuffer.cpp | 13 ++++--------- src/Framebuffer.cpp | 13 ++++--------- 2 files changed, 8 insertions(+), 18 deletions(-) diff --git a/src/DefaultFramebuffer.cpp b/src/DefaultFramebuffer.cpp index 9f165a1bc..b0f9e7995 100644 --- a/src/DefaultFramebuffer.cpp +++ b/src/DefaultFramebuffer.cpp @@ -45,37 +45,32 @@ DefaultFramebuffer& DefaultFramebuffer::mapForDraw(std::initializer_list::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 attachments) { /** @todo C++14: use VLA to avoid heap allocation */ - GLenum* _attachments = new GLenum[attachments.size()]; + Containers::Array _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 attachments, const Rectanglei& rectangle) { /** @todo C++14: use VLA to avoid heap allocation */ - GLenum* _attachments = new GLenum[attachments.size()]; + Containers::Array _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) { diff --git a/src/Framebuffer.cpp b/src/Framebuffer.cpp index 189319243..265cf91d6 100644 --- a/src/Framebuffer.cpp +++ b/src/Framebuffer.cpp @@ -94,36 +94,31 @@ Framebuffer& Framebuffer::mapForDraw(std::initializer_list::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 attachments) { /** @todo C++14: use VLA to avoid heap allocation */ - GLenum* _attachments = new GLenum[attachments.size()]; + Containers::Array _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 attachments, const Rectanglei& rectangle) { /** @todo C++14: use VLA to avoid heap allocation */ - GLenum* _attachments = new GLenum[attachments.size()]; + Containers::Array _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) {