mirror of
https://git.dev.opencascade.org/repos/occt.git
synced 2025-08-14 13:30:48 +03:00
0026165: Visualization, TKOpenGl - fix FBO blitting on some mobile devices
OpenGl_Texture::Init() - initialize FBO textures with GL_TEXTURE_WRAP_ set to GL_CLAMP_TO_EDGE, since some devices do not support GL_REPEAT (which is default) in such combination. OpenGl_Font::createTexture() - define texture parameters explicitly. OpenGl_FrameBuffer::Init() create Depth render buffer object instead of texture on devices which do not support GL_DEPTH24_STENCIL8.
This commit is contained in:
@@ -69,26 +69,56 @@ Standard_Boolean OpenGl_FrameBuffer::Init (const Handle(OpenGl_Context)& theGlCo
|
||||
myVPSizeY = theViewportSizeY;
|
||||
|
||||
// Create the textures (will be used as color buffer and depth-stencil buffer)
|
||||
if (!initTrashTextures (theGlContext))
|
||||
if (!myColorTexture->Init (theGlContext, myTextFormat,
|
||||
GL_RGBA, GL_UNSIGNED_BYTE,
|
||||
myVPSizeX, myVPSizeY, Graphic3d_TOT_2D))
|
||||
{
|
||||
Release (theGlContext.operator->());
|
||||
return Standard_False;
|
||||
}
|
||||
|
||||
// extensions (GL_OES_packed_depth_stencil, GL_OES_depth_texture) + GL version might be used to determine supported formats
|
||||
// instead of just trying to create such texture
|
||||
if (!myDepthStencilTexture->Init (theGlContext, GL_DEPTH24_STENCIL8,
|
||||
GL_DEPTH_STENCIL, GL_UNSIGNED_INT_24_8,
|
||||
myVPSizeX, myVPSizeY, Graphic3d_TOT_2D))
|
||||
{
|
||||
TCollection_ExtendedString aMsg = TCollection_ExtendedString()
|
||||
+ "Warning! Depth textures are not supported by hardware!";
|
||||
theGlContext->PushMessage (GL_DEBUG_SOURCE_APPLICATION_ARB,
|
||||
GL_DEBUG_TYPE_PORTABILITY_ARB,
|
||||
0,
|
||||
GL_DEBUG_SEVERITY_HIGH_ARB,
|
||||
aMsg);
|
||||
|
||||
theGlContext->arbFBO->glGenRenderbuffers (1, &myGlDepthRBufferId);
|
||||
theGlContext->arbFBO->glBindRenderbuffer (GL_RENDERBUFFER, myGlDepthRBufferId);
|
||||
theGlContext->arbFBO->glRenderbufferStorage (GL_RENDERBUFFER, GL_DEPTH_COMPONENT16, myVPSizeX, myVPSizeY);
|
||||
theGlContext->arbFBO->glBindRenderbuffer (GL_RENDERBUFFER, NO_RENDERBUFFER);
|
||||
}
|
||||
|
||||
// Build FBO and setup it as texture
|
||||
theGlContext->arbFBO->glGenFramebuffers (1, &myGlFBufferId);
|
||||
theGlContext->arbFBO->glBindFramebuffer (GL_FRAMEBUFFER, myGlFBufferId);
|
||||
theGlContext->arbFBO->glFramebufferTexture2D (GL_FRAMEBUFFER, GL_COLOR_ATTACHMENT0,
|
||||
GL_TEXTURE_2D, myColorTexture->TextureId(), 0);
|
||||
#ifdef GL_DEPTH_STENCIL_ATTACHMENT
|
||||
theGlContext->arbFBO->glFramebufferTexture2D (GL_FRAMEBUFFER, GL_DEPTH_STENCIL_ATTACHMENT,
|
||||
GL_TEXTURE_2D, myDepthStencilTexture->TextureId(), 0);
|
||||
#else
|
||||
theGlContext->arbFBO->glFramebufferTexture2D (GL_FRAMEBUFFER, GL_DEPTH_ATTACHMENT,
|
||||
GL_TEXTURE_2D, myDepthStencilTexture->TextureId(), 0);
|
||||
theGlContext->arbFBO->glFramebufferTexture2D (GL_FRAMEBUFFER, GL_STENCIL_ATTACHMENT,
|
||||
GL_TEXTURE_2D, myDepthStencilTexture->TextureId(), 0);
|
||||
#endif
|
||||
if (myDepthStencilTexture->IsValid())
|
||||
{
|
||||
#ifdef GL_DEPTH_STENCIL_ATTACHMENT
|
||||
theGlContext->arbFBO->glFramebufferTexture2D (GL_FRAMEBUFFER, GL_DEPTH_STENCIL_ATTACHMENT,
|
||||
GL_TEXTURE_2D, myDepthStencilTexture->TextureId(), 0);
|
||||
#else
|
||||
theGlContext->arbFBO->glFramebufferTexture2D (GL_FRAMEBUFFER, GL_DEPTH_ATTACHMENT,
|
||||
GL_TEXTURE_2D, myDepthStencilTexture->TextureId(), 0);
|
||||
theGlContext->arbFBO->glFramebufferTexture2D (GL_FRAMEBUFFER, GL_STENCIL_ATTACHMENT,
|
||||
GL_TEXTURE_2D, myDepthStencilTexture->TextureId(), 0);
|
||||
#endif
|
||||
}
|
||||
else if (myGlDepthRBufferId != NO_RENDERBUFFER)
|
||||
{
|
||||
theGlContext->arbFBO->glFramebufferRenderbuffer (GL_FRAMEBUFFER, GL_DEPTH_ATTACHMENT,
|
||||
GL_RENDERBUFFER, myGlDepthRBufferId);
|
||||
}
|
||||
if (theGlContext->arbFBO->glCheckFramebufferStatus (GL_FRAMEBUFFER) != GL_FRAMEBUFFER_COMPLETE)
|
||||
{
|
||||
Release (theGlContext.operator->());
|
||||
@@ -287,20 +317,6 @@ void OpenGl_FrameBuffer::Release (OpenGl_Context* theGlCtx)
|
||||
myDepthStencilTexture->Release (theGlCtx);
|
||||
}
|
||||
|
||||
// =======================================================================
|
||||
// function : initTrashTexture
|
||||
// purpose :
|
||||
// =======================================================================
|
||||
Standard_Boolean OpenGl_FrameBuffer::initTrashTextures (const Handle(OpenGl_Context)& theGlContext)
|
||||
{
|
||||
return myColorTexture->Init (theGlContext, myTextFormat,
|
||||
GL_RGBA, GL_UNSIGNED_BYTE,
|
||||
myVPSizeX, myVPSizeY, Graphic3d_TOT_2D)
|
||||
&& myDepthStencilTexture->Init (theGlContext, GL_DEPTH24_STENCIL8,
|
||||
GL_DEPTH_STENCIL, GL_UNSIGNED_INT_24_8,
|
||||
myVPSizeX, myVPSizeY, Graphic3d_TOT_2D);
|
||||
}
|
||||
|
||||
// =======================================================================
|
||||
// function : SetupViewport
|
||||
// purpose :
|
||||
|
Reference in New Issue
Block a user