1
0
mirror of https://git.dev.opencascade.org/repos/occt.git synced 2025-04-04 18:06:22 +03:00

0026424: Visualization, TKOpenGl - fix text rendering in core profile

OpenGl_Context::init() - fix condition on initializing alien OpenGL context within core profile.
OpenGl_Font::renderGlyph() - use GL_RED data format in core profile.
OpenGl_Text::render() - do not use GL_ALPHA_TEST in core profile.

Test-case for issue #26424
This commit is contained in:
kgv 2015-07-20 20:58:55 +03:00 committed by bugmaster
parent c8bf1eb747
commit c6ad5e5f39
4 changed files with 62 additions and 12 deletions

View File

@ -1040,7 +1040,7 @@ void OpenGl_Context::init (const Standard_Boolean theIsCoreProfile)
isCoreProfile = (theIsCoreProfile == Standard_True);
// detect Core profile
if (isCoreProfile)
if (!isCoreProfile)
{
GLint aProfile = 0;
::glGetIntegerv (GL_CONTEXT_PROFILE_MASK, &aProfile);

View File

@ -60,13 +60,16 @@ void OpenGl_Font::Release (OpenGl_Context* theCtx)
return;
}
// application can not handle this case by exception - this is bug in code
Standard_ASSERT_RETURN (theCtx != NULL,
"OpenGl_Font destroyed without GL context! Possible GPU memory leakage...",);
for (Standard_Integer anIter = 0; anIter < myTextures.Length(); ++anIter)
{
Handle(OpenGl_Texture)& aTexture = myTextures.ChangeValue (anIter);
if (aTexture->IsValid())
{
// application can not handle this case by exception - this is bug in code
Standard_ASSERT_RETURN (theCtx != NULL,
"OpenGl_Font destroyed without GL context! Possible GPU memory leakage...",);
}
aTexture->Release (theCtx);
aTexture.Nullify();
}
@ -92,7 +95,12 @@ bool OpenGl_Font::Init (const Handle(OpenGl_Context)& theCtx)
myTileSizeY = myFont->GlyphMaxSizeY();
myLastTileId = -1;
return createTexture (theCtx);
if (!createTexture (theCtx))
{
Release (theCtx.operator->());
return false;
}
return true;
}
// =======================================================================
@ -151,6 +159,11 @@ bool OpenGl_Font::renderGlyph (const Handle(OpenGl_Context)& theCtx,
}
Handle(OpenGl_Texture)& aTexture = myTextures.ChangeLast();
if (aTexture.IsNull()
|| !aTexture->IsValid())
{
return false;
}
const Image_PixMap& anImg = myFont->GlyphImage();
const Standard_Integer aTileId = myLastTileId + 1;
@ -182,7 +195,7 @@ bool OpenGl_Font::renderGlyph (const Handle(OpenGl_Context)& theCtx,
glTexSubImage2D (GL_TEXTURE_2D, 0,
myLastTilePx.Left, myLastTilePx.Top, (GLsizei )anImg.SizeX(), (GLsizei )anImg.SizeY(),
GL_ALPHA, GL_UNSIGNED_BYTE, anImg.Data());
aTexture->GetFormat(), GL_UNSIGNED_BYTE, anImg.Data());
OpenGl_Font::Tile aTile;
aTile.uv.Left = GLfloat(myLastTilePx.Left) / GLfloat(aTexture->SizeX());

View File

@ -407,6 +407,8 @@ void OpenGl_Text::Render (const Handle(OpenGl_Workspace)& theWorkspace) const
aTextAspect->SubtitleColor());
}
aCtx->BindProgram (NULL);
// restore aspects
if (!aPrevTexture.IsNull())
{
@ -591,6 +593,7 @@ Handle(OpenGl_Font) OpenGl_Text::FindFont (const Handle(OpenGl_Context)& theCtx,
aMsg += "' - initialization of GL resources has failed!";
theCtx->PushMessage (GL_DEBUG_SOURCE_APPLICATION_ARB, GL_DEBUG_TYPE_ERROR_ARB, 0, GL_DEBUG_SEVERITY_HIGH_ARB, aMsg);
aFontFt.Nullify();
aFont->Release (theCtx.operator->());
aFont = new OpenGl_Font (aFontFt, theKey);
}
}
@ -743,14 +746,14 @@ void OpenGl_Text::render (const Handle(OpenGl_PrinterContext)& thePrintCtx,
theCtx->core15fwd->glActiveTexture (GL_TEXTURE0);
}
#if !defined(GL_ES_VERSION_2_0)
// setup alpha test
glAlphaFunc (GL_GEQUAL, 0.285f);
glEnable (GL_ALPHA_TEST);
// activate texture unit
GLint aTexEnvParam = GL_REPLACE;
if (theCtx->core11 != NULL)
{
// setup alpha test
glAlphaFunc (GL_GEQUAL, 0.285f);
glEnable (GL_ALPHA_TEST);
glDisable (GL_TEXTURE_1D);
glEnable (GL_TEXTURE_2D);
glGetTexEnviv (GL_TEXTURE_ENV, GL_TEXTURE_ENV_MODE, &aTexEnvParam);
@ -871,7 +874,10 @@ void OpenGl_Text::render (const Handle(OpenGl_PrinterContext)& thePrintCtx,
glDisable (GL_BLEND);
glDisable (GL_STENCIL_TEST);
#if !defined(GL_ES_VERSION_2_0)
if (theCtx->core11 != NULL)
{
glDisable (GL_ALPHA_TEST);
}
glDisable (GL_COLOR_LOGIC_OP);
#endif

31
tests/bugs/vis/bug26424 Normal file
View File

@ -0,0 +1,31 @@
puts "========"
puts "OCC26424"
puts "========"
puts ""
################################################################
# Text is not rendered within core profile on Windows platform
################################################################
vcaps -core
vinit View1
vclear
vaxo
vzbufftrihedron
if { [array get env os_type] != "" } {
set os $env(os_type)
}
if { [string compare $os "windows"] != 0 } {
# Linux platform
set ok_color "GRAY85"
} else {
# Windows platform
set ok_color "GRAY52"
}
set bug_info [vreadpixel 71 350 rgb name]
if {$bug_info != $ok_color} {
puts "ERROR: OCC26424 is reproduced. Trihedron does non have text labels."
}
set only_screen 1