void FrameBufferObject::deallocate() { std::fill(_attachedColorTextures, _attachedColorTextures+16, (ImageTexture2D *)0); glDeleteFramebuffersEXT(1, &_fboID); checkGLErrorsHere1(_fboName); }
bool FrameBufferObject::allocate() { glGenFramebuffersEXT(1, &_fboID); checkGLErrorsHere1(_fboName); return true; }
void ImageTexture2D::clear() { glBindTexture(_textureTarget, _textureID); glTexImage2D(_textureTarget, 0, GL_RGB, 0, 0, 0, GL_RGB, GL_UNSIGNED_BYTE, 0); checkGLErrorsHere1(_texName); }
void ImageTexture2D::deallocateID() { if (_textureID == 0) return; this->clear(); glDeleteTextures(1, &_textureID); _textureID = 0; checkGLErrorsHere1(_texName); }
void ImageTexture2D::overwriteWith(float const * pixels, int nChannels) { unsigned const format = extPixelFormat[nChannels]; unsigned const type = GL_FLOAT; glBindTexture(_textureTarget, _textureID); glTexSubImage2D(_textureTarget, 0, 0, 0, _width, _height, format, type, pixels); checkGLErrorsHere1(_texName); }
void ImageTexture2D::reserve(int width, int height, TextureSpecification const& texSpec) { _width = width; _height = height; unsigned internalFormat = texSpec.getGLInternalFormat(); unsigned format = texSpec.isDepthTexture ? GL_DEPTH_COMPONENT : GL_RGB; unsigned type = texSpec.isFloatTexture ? GL_FLOAT : GL_UNSIGNED_BYTE; glBindTexture(_textureTarget, _textureID); glTexImage2D(_textureTarget, 0, internalFormat, _width, _height, 0, format, type, 0); checkGLErrorsHere1(_texName); }
void ImageTexture2D::overwriteWith(float const * redPixels, float const * greenPixels, float const * bluePixels) { unsigned const format = extPixelFormat[3]; unsigned const type = GL_FLOAT; float * pixels = new float[3 * _width * _height]; interleavePixels(_width, _height, redPixels, greenPixels, bluePixels, pixels); glBindTexture(_textureTarget, _textureID); glTexSubImage2D(_textureTarget, 0, 0, 0, _width, _height, format, type, pixels); delete [] pixels; checkGLErrorsHere1(_texName); }
void FrameBufferObject::detach(GLenum attachment) { if (this->checkBinding("FrameBufferObject::detach()")) { if (attachment >= GL_COLOR_ATTACHMENT0_EXT && attachment <= GL_COLOR_ATTACHMENT15_EXT) { glFramebufferTexture2DEXT(GL_FRAMEBUFFER_EXT, attachment, GL_TEXTURE_2D, 0, 0); _attachedColorTextures[attachment - GL_COLOR_ATTACHMENT0_EXT] = 0; } else if (attachment == GL_DEPTH_ATTACHMENT_EXT) { glFramebufferTexture2DEXT(GL_FRAMEBUFFER_EXT, attachment, GL_TEXTURE_2D, 0, 0); _attachedDepthTexture = 0; } else raiseGLErrorHere2("Unknown/unsupported attachment specifier", _fboName.c_str()); }checkGLErrorsHere1(_fboName); }
void ImageTexture2D::overwriteWith(uchar const * redPixels, uchar const * greenPixels, uchar const * bluePixels, uchar const * alphaPixels) { unsigned const format = extPixelFormat[4]; unsigned const type = GL_UNSIGNED_BYTE; unsigned char * pixels = new unsigned char[4 * _width * _height]; interleavePixels(_width, _height, redPixels, greenPixels, bluePixels, alphaPixels, pixels); glBindTexture(_textureTarget, _textureID); glTexSubImage2D(_textureTarget, 0, 0, 0, _width, _height, format, type, pixels); delete[] pixels; checkGLErrorsHere1(_texName); }
void FrameBufferObject::attachTexture2D(ImageTexture2D& texture, GLenum attachment, int mipLevel) { if (this->checkBinding("FrameBufferObject::attachTexture2D()")) { if (attachment >= GL_COLOR_ATTACHMENT0_EXT && attachment <= GL_COLOR_ATTACHMENT15_EXT) { glFramebufferTexture2DEXT(GL_FRAMEBUFFER_EXT, attachment, texture.textureTarget(), texture.textureID(), mipLevel); _attachedColorTextures[attachment - GL_COLOR_ATTACHMENT0_EXT] = &texture; } else if (attachment == GL_DEPTH_ATTACHMENT_EXT) { glFramebufferTexture2DEXT(GL_FRAMEBUFFER_EXT, attachment, texture.textureTarget(), texture.textureID(), mipLevel); _attachedDepthTexture = &texture; } else raiseGLErrorHere2("Unknown/unsupported attachment specifier", _fboName.c_str()); }checkGLErrorsHere1(_fboName); }
void FrameBufferObject::makeCurrent() { glBindFramebufferEXT(GL_FRAMEBUFFER_EXT, _fboID); checkGLErrorsHere1(_fboName); }