~ use glClear instead of allocating pixels for FBOs creation

Signed-off-by: Alexis Maiquez <almamu@almamu.com>
This commit is contained in:
Alexis Maiquez 2021-10-01 15:46:04 +02:00
parent 4744304a3d
commit 332507351f

View File

@ -8,8 +8,6 @@ CFBO::CFBO (std::string name, ITexture::TextureFormat format, float scale, uint3
m_scale (scale)
{
// create an empty texture that'll be free'd so the FBO is transparent
uint32_t* pixels = new uint32_t [textureWidth * textureHeight] {0xFFFFFFFF};
GLenum drawBuffers [1] = {GL_COLOR_ATTACHMENT0};
// create the main framebuffer
glGenFramebuffers (1, &this->m_framebuffer);
@ -19,9 +17,7 @@ CFBO::CFBO (std::string name, ITexture::TextureFormat format, float scale, uint3
// bind the new texture to set settings on it
glBindTexture (GL_TEXTURE_2D, this->m_texture);
// give OpenGL an empty image
glTexImage2D (GL_TEXTURE_2D, 0, GL_RGBA8, textureWidth, textureHeight, 0, GL_RGBA, GL_UNSIGNED_BYTE, pixels);
delete pixels;
glTexImage2D (GL_TEXTURE_2D, 0, GL_RGBA8, textureWidth, textureHeight, 0, GL_RGBA, GL_UNSIGNED_BYTE, nullptr);
// set filtering parameters, otherwise the texture is not rendered
glTexParameteri (GL_TEXTURE_2D, GL_TEXTURE_MAG_FILTER, GL_NEAREST);
@ -39,6 +35,9 @@ CFBO::CFBO (std::string name, ITexture::TextureFormat format, float scale, uint3
if (glCheckFramebufferStatus (GL_FRAMEBUFFER) != GL_FRAMEBUFFER_COMPLETE)
throw std::runtime_error ("Framebuffers are not properly set");
// clear the framebuffer
glClear (GL_COLOR_BUFFER_BIT);
this->m_resolution = {
textureWidth, textureHeight,
realWidth, realHeight