@ -40,8 +40,10 @@ AbstractFramebuffer::DrawBuffersImplementation AbstractFramebuffer::drawBuffersI
AbstractFramebuffer : : DrawBufferImplementation AbstractFramebuffer : : drawBufferImplementation = & AbstractFramebuffer : : drawBufferImplementationDefault ;
AbstractFramebuffer : : ReadBufferImplementation AbstractFramebuffer : : readBufferImplementation = & AbstractFramebuffer : : readBufferImplementationDefault ;
# ifdef MAGNUM_TARGET_GLES2
FramebufferTarget AbstractFramebuffer : : readTarget = FramebufferTarget : : ReadDraw ;
FramebufferTarget AbstractFramebuffer : : drawTarget = FramebufferTarget : : ReadDraw ;
# endif
AbstractFramebuffer : : ~ AbstractFramebuffer ( ) { }
@ -81,10 +83,15 @@ FramebufferTarget AbstractFramebuffer::bindInternal() {
/* Or bind it, if not already */
state - > readBinding = _id ;
if ( readTarget = = FramebufferTarget : : ReadDraw ) state - > drawBinding = _id ;
# ifndef MAGNUM_TARGET_GLES2
glBindFramebuffer ( GLenum ( FramebufferTarget : : Read ) , _id ) ;
return FramebufferTarget : : Read ;
# else
if ( readTarget = = FramebufferTarget : : ReadDraw ) state - > drawBinding = _id ;
glBindFramebuffer ( GLenum ( readTarget ) , _id ) ;
return readTarget ;
# endif
}
void AbstractFramebuffer : : blit ( AbstractFramebuffer & source , AbstractFramebuffer & destination , const Rectanglei & sourceRectangle , const Rectanglei & destinationRectangle , FramebufferBlitMask mask , FramebufferBlitFilter filter ) {
@ -126,12 +133,20 @@ void AbstractFramebuffer::setViewportInternal() {
}
void AbstractFramebuffer : : clear ( FramebufferClearMask mask ) {
# ifndef MAGNUM_TARGET_GLES2
bindInternal ( FramebufferTarget : : Draw ) ;
# else
bindInternal ( drawTarget ) ;
# endif
glClear ( static_cast < GLbitfield > ( mask ) ) ;
}
void AbstractFramebuffer : : read ( const Vector2i & offset , const Vector2i & size , Image2D * image ) {
# ifndef MAGNUM_TARGET_GLES2
bindInternal ( FramebufferTarget : : Read ) ;
# else
bindInternal ( readTarget ) ;
# endif
const std : : size_t dataSize = image - > pixelSize ( ) * size . product ( ) ;
char * const data = new char [ dataSize ] ;
readImplementation ( offset , size , image - > format ( ) , image - > type ( ) , dataSize , data ) ;
@ -140,7 +155,11 @@ void AbstractFramebuffer::read(const Vector2i& offset, const Vector2i& size, Ima
# ifndef MAGNUM_TARGET_GLES2
void AbstractFramebuffer : : read ( const Vector2i & offset , const Vector2i & size , BufferImage2D * image , Buffer : : Usage usage ) {
# ifndef MAGNUM_TARGET_GLES2
bindInternal ( FramebufferTarget : : Read ) ;
# else
bindInternal ( readTarget ) ;
# endif
/* If the buffer doesn't have sufficient size, resize it */
/** @todo Explicitly reset also when buffer usage changes */
if ( image - > size ( ) ! = size )
@ -177,13 +196,6 @@ void AbstractFramebuffer::invalidateImplementation(GLsizei count, GLenum* attach
void AbstractFramebuffer : : initializeContextBasedFunctionality ( Context * context ) {
# ifndef MAGNUM_TARGET_GLES
if ( context - > isExtensionSupported < Extensions : : GL : : EXT : : framebuffer_blit > ( ) ) {
Debug ( ) < < " AbstractFramebuffer: using " < < Extensions : : GL : : EXT : : framebuffer_blit : : string ( ) < < " features " ;
readTarget = FramebufferTarget : : Read ;
drawTarget = FramebufferTarget : : Draw ;
}
if ( context - > isExtensionSupported < Extensions : : GL : : EXT : : direct_state_access > ( ) ) {
Debug ( ) < < " AbstractFramebuffer: using " < < Extensions : : GL : : EXT : : direct_state_access : : string ( ) < < " features " ;
@ -193,6 +205,32 @@ void AbstractFramebuffer::initializeContextBasedFunctionality(Context* context)
}
# endif
# ifdef MAGNUM_TARGET_GLES2
/* Optimistically set separate binding targets and check if one of the
extensions providing them is available */
readTarget = FramebufferTarget : : Read ;
drawTarget = FramebufferTarget : : Draw ;
if ( context - > isExtensionSupported < Extensions : : GL : : ANGLE : : framebuffer_blit > ( ) )
Debug ( ) < < " AbstractFramebuffer: using " < < Extensions : : GL : : ANGLE : : framebuffer_blit : : string ( ) < < " features " ;
else if ( context - > isExtensionSupported < Extensions : : GL : : APPLE : : framebuffer_multisample > ( ) )
Debug ( ) < < " AbstractFramebuffer: using " < < Extensions : : GL : : APPLE : : framebuffer_multisample : : string ( ) < < " features " ;
else if ( context - > isExtensionSupported < Extensions : : GL : : NV : : framebuffer_blit > ( ) )
Debug ( ) < < " AbstractFramebuffer: using " < < Extensions : : GL : : NV : : framebuffer_blit : : string ( ) < < " features " ;
/* NV_framebuffer_multisample requires NV_framebuffer_blit, which has these
enums . However , on my system only NV_framebuffer_multisample is
supported , but NV_framebuffer_blit isn ' t . I will hold my breath and
assume these enums are available . */
else if ( context - > isExtensionSupported < Extensions : : GL : : NV : : framebuffer_multisample > ( ) )
Debug ( ) < < " AbstractFramebuffer: using " < < Extensions : : GL : : NV : : framebuffer_multisample : : string ( ) < < " features " ;
/* If no such extension is available, reset back to unified target */
else readTarget = drawTarget = FramebufferTarget : : ReadDraw ;
# endif
# ifndef MAGNUM_TARGET_GLES3
# ifndef MAGNUM_TARGET_GLES
if ( context - > isExtensionSupported < Extensions : : GL : : ARB : : robustness > ( ) )
@ -219,7 +257,11 @@ void AbstractFramebuffer::initializeContextBasedFunctionality(Context* context)
void AbstractFramebuffer : : drawBuffersImplementationDefault ( GLsizei count , const GLenum * buffers ) {
/** @todo Re-enable when extension wrangler is available for ES2 */
# ifndef MAGNUM_TARGET_GLES2
# ifndef MAGNUM_TARGET_GLES2
bindInternal ( FramebufferTarget : : Draw ) ;
# else
bindInternal ( drawTarget ) ;
# endif
glDrawBuffers ( count , buffers ) ;
# else
static_cast < void > ( count ) ;
@ -236,7 +278,11 @@ void AbstractFramebuffer::drawBuffersImplementationDSA(GLsizei count, const GLen
void AbstractFramebuffer : : drawBufferImplementationDefault ( GLenum buffer ) {
/** @todo Re-enable when extension wrangler is available for ES2 */
# ifndef MAGNUM_TARGET_GLES2
# ifndef MAGNUM_TARGET_GLES2
bindInternal ( FramebufferTarget : : Draw ) ;
# else
bindInternal ( drawTarget ) ;
# endif
# ifndef MAGNUM_TARGET_GLES3
glDrawBuffer ( buffer ) ;
# else
@ -256,7 +302,11 @@ void AbstractFramebuffer::drawBufferImplementationDSA(GLenum buffer) {
void AbstractFramebuffer : : readBufferImplementationDefault ( GLenum buffer ) {
/** @todo Get some extension wrangler instead to avoid undeclared glReadBuffer() on ES2 */
# ifndef MAGNUM_TARGET_GLES2
# ifndef MAGNUM_TARGET_GLES2
bindInternal ( FramebufferTarget : : Read ) ;
# else
bindInternal ( readTarget ) ;
# endif
glReadBuffer ( buffer ) ;
# else
static_cast < void > ( buffer ) ;