1
0
mirror of https://git.dev.opencascade.org/repos/occt.git synced 2025-04-03 17:56:21 +03:00

0027633: Visualization, TKOpenGl - point sprites are inconsistent within Core and Compatible Profiles

OpenGl_ShaderManager::pointSpriteAlphaSrc() now does not return alpha from Red channel
for RGBA marker texture in Core profile.
OpenGl_ShaderManager::prepareStdProgramFlat() - restored code for drawing points without texture.

Built-in GLSL programs now flip .y in shaders instead of
relying on GL_POINT_SPRITE_COORD_ORIGIN unavailable on OpenGL ES.

Added sample markers.tcl (moved from test cases).
Sample now includes marker_kr.png for testing marker orientation.
This commit is contained in:
kgv 2016-06-24 11:36:57 +03:00 committed by bugmaster
parent 1d92133e83
commit fd59283a7b
14 changed files with 184 additions and 157 deletions

BIN
data/images/marker_kr.png Normal file

Binary file not shown.

After

Width:  |  Height:  |  Size: 1.0 KiB

74
samples/tcl/markers.tcl Normal file
View File

@ -0,0 +1,74 @@
# Markers demo
#
# It shows the various marker types supported by OCCT.
#Category: Visualization
#Title: Markers in 3d viewer
pload MODELING VISUALIZATION
# reflects Aspect_TypeOfMarker enumeration
set aMarkerTypeNames {
Aspect_TOM_POINT
Aspect_TOM_PLUS
Aspect_TOM_STAR
Aspect_TOM_X
Aspect_TOM_O
Aspect_TOM_O_POINT
Aspect_TOM_O_PLUS
Aspect_TOM_O_STAR
Aspect_TOM_O_X
Aspect_TOM_RING1
Aspect_TOM_RING2
Aspect_TOM_RING3
Aspect_TOM_BALL
Aspect_TOM_USERDEFINED
}
# custom marker
set aCustom1 [locate_data_file images/marker_box1.png]
set aCustom2 [locate_data_file images/marker_box2.png]
set aCustom3 [locate_data_file images/marker_kr.png]
set aCustom4 [locate_data_file images/marker_dot.png]
set aFontFile [locate_data_file DejaVuSans.ttf]
set aLabelFont "Arial"
if { "$aFontFile" != "" } {
vfont add "$aFontFile" SansFont
set aLabelFont "SansFont"
}
# reset the viewer
vclear
vclose ALL
vinit name=View1 l=32 t=32 w=512 h=512
puts "Draw box in advance which should fit all our markers"
box b -8 -8 0 16 16 2
vbottom
vdisplay -noupdate -dispmode 0 b
vfit
vremove -noupdate b
puts "Draw markers of different type and size"
for { set aMarkerType 0 } { $aMarkerType <= 13 } { incr aMarkerType } {
set aRow [expr $aMarkerType - 7]
set aCol 5
set aName [lindex $aMarkerTypeNames $aMarkerType]
vdrawtext "$aName" "$aName" -pos 0 [expr $aRow + 0.5] 0 -color 0.5 1.0 1.0 -halign center -valign center -angle 000 -zoom 0 -height 12 -aspect bold -font $aLabelFont
if { $aMarkerType == 13 } {
vmarkerstest m${aMarkerType}_${aCol} $aCol $aRow 0 PointsOnSide=1 FileName=$aCustom1
set aCol [expr $aCol - 1]
vmarkerstest m${aMarkerType}_${aCol} $aCol $aRow 0 PointsOnSide=1 FileName=$aCustom2
set aCol [expr $aCol - 1]
vmarkerstest m${aMarkerType}_${aCol} $aCol $aRow 0 PointsOnSide=1 FileName=$aCustom3
set aCol [expr $aCol - 1]
vmarkerstest m${aMarkerType}_${aCol} $aCol $aRow 0 PointsOnSide=1 FileName=$aCustom4
} else {
for { set aMarkerScale 1.0 } { $aMarkerScale <= 7 } { set aMarkerScale [expr $aMarkerScale + 0.5] } {
vmarkerstest m${aMarkerType}_${aCol} $aCol $aRow 0 MarkerType=$aMarkerType Scale=$aMarkerScale PointsOnSide=1
set aCol [expr $aCol - 1]
}
}
}
puts "All markers have been displayed"

View File

@ -138,8 +138,10 @@ OpenGl_Context::OpenGl_Context (const Handle(OpenGl_Caps)& theCaps)
myIsStereoBuffers (Standard_False),
myIsGlNormalizeEnabled (Standard_False),
#if !defined(GL_ES_VERSION_2_0)
myPointSpriteOrig (GL_UPPER_LEFT),
myRenderMode (GL_RENDER),
#else
myPointSpriteOrig (0),
myRenderMode (0),
#endif
myReadBuffer (0),
@ -2742,6 +2744,27 @@ void OpenGl_Context::SetPointSize (const Standard_ShortReal theSize)
#endif
}
// =======================================================================
// function : SetPointSpriteOrigin
// purpose :
// =======================================================================
void OpenGl_Context::SetPointSpriteOrigin()
{
#if !defined(GL_ES_VERSION_2_0)
if (core15fwd == NULL)
{
return;
}
const int aNewState = !myActiveProgram.IsNull() ? GL_UPPER_LEFT : GL_LOWER_LEFT;
if (myPointSpriteOrig != aNewState)
{
myPointSpriteOrig = aNewState;
core15fwd->glPointParameteri (GL_POINT_SPRITE_COORD_ORIGIN, aNewState);
}
#endif
}
// =======================================================================
// function : SetGlNormalizeEnabled
// purpose :

View File

@ -567,6 +567,12 @@ public: //! @name methods to alter or retrieve current state
//! Setup point size.
Standard_EXPORT void SetPointSize (const Standard_ShortReal theSize);
//! Setup point sprite origin using GL_POINT_SPRITE_COORD_ORIGIN state:
//! - GL_UPPER_LEFT when GLSL program is active;
//! flipping should be handled in GLSL program for compatibility with OpenGL ES
//! - GL_LOWER_LEFT for FFP
Standard_EXPORT void SetPointSpriteOrigin();
//! Setup texture matrix to active GLSL program or to FFP global state using glMatrixMode (GL_TEXTURE).
Standard_EXPORT void SetTextureMatrix (const Handle(Graphic3d_TextureParams)& theParams);
@ -716,6 +722,7 @@ private: //! @name fields tracking current state
Handle(OpenGl_ShaderProgram) myActiveProgram; //!< currently active GLSL program
Handle(OpenGl_Sampler) myTexSampler; //!< currently active sampler object
Handle(OpenGl_FrameBuffer) myDefaultFbo; //!< default Frame Buffer Object
Standard_Integer myPointSpriteOrig; //!< GL_POINT_SPRITE_COORD_ORIGIN state (GL_UPPER_LEFT by default)
Standard_Integer myRenderMode; //!< value for active rendering mode
Standard_Integer myReadBuffer; //!< current read buffer
Standard_Integer myDrawBuffer; //!< current draw buffer

View File

@ -537,6 +537,7 @@ void OpenGl_PrimitiveArray::drawMarkers (const Handle(OpenGl_Workspace)& theWork
{
// Textured markers will be drawn with the point sprites
aCtx->SetPointSize (anAspectMarker->MarkerSize());
aCtx->SetPointSpriteOrigin();
#if !defined(GL_ES_VERSION_2_0)
if (aCtx->core11 != NULL)
{

View File

@ -53,6 +53,9 @@ const char THE_VARY_TexCoord_Trsf[] =
EOL" aTex2.y = aCopy.x * aRotSin + aCopy.y * aRotCos;"
EOL" TexCoord = vec4(aTex2, occTexCoord.zw);";
//! Auxiliary function to flip gl_PointCoord vertically
#define THE_VEC2_glPointCoord "vec2 (gl_PointCoord.x, 1.0 - gl_PointCoord.y)"
//! Auxiliary function to transform normal
const char THE_FUNC_transformNormal[] =
EOL"vec3 transformNormal (in vec3 theNormal)"
@ -944,16 +947,18 @@ Standard_Boolean OpenGl_ShaderManager::prepareStdProgramFboBlit()
// function : pointSpriteAlphaSrc
// purpose :
// =======================================================================
TCollection_AsciiString OpenGl_ShaderManager::pointSpriteAlphaSrc()
TCollection_AsciiString OpenGl_ShaderManager::pointSpriteAlphaSrc (const Standard_Integer theBits)
{
TCollection_AsciiString aSrcGetAlpha = EOL"float getAlpha(void) { return occTexture2D(occActiveSampler, gl_PointCoord).a; }";
TCollection_AsciiString aSrcGetAlpha = EOL"float getAlpha(void) { return occTexture2D(occActiveSampler, " THE_VEC2_glPointCoord ").a; }";
#if !defined(GL_ES_VERSION_2_0)
if (myContext->core11 == NULL)
if (myContext->core11 == NULL
&& (theBits & OpenGl_PO_TextureA) != 0)
{
aSrcGetAlpha = EOL"float getAlpha(void) { return occTexture2D(occActiveSampler, gl_PointCoord).r; }";
aSrcGetAlpha = EOL"float getAlpha(void) { return occTexture2D(occActiveSampler, " THE_VEC2_glPointCoord ").r; }";
}
#else
(void )theBits;
#endif
return aSrcGetAlpha;
}
@ -988,30 +993,37 @@ Standard_Boolean OpenGl_ShaderManager::prepareStdProgramFlat (Handle(OpenGl_Shad
aSrcVertExtraMain += EOL" gl_PointSize = occPointSize;";
#endif
if (textureUsed (theBits))
{
aSrcGetAlpha = pointSpriteAlphaSrc();
#if !defined(GL_ES_VERSION_2_0)
if (myContext->core11 != NULL
&& myContext->IsGlGreaterEqual (2, 1))
{
aProgramSrc->SetHeader ("#version 120"); // gl_PointCoord has been added since GLSL 1.2
}
#endif
}
if ((theBits & OpenGl_PO_TextureRGB) != 0)
{
aSrcFragGetColor =
EOL"vec4 getColor(void) { return occTexture2D(occActiveSampler, gl_PointCoord); }";
EOL"vec4 getColor(void) { return occTexture2D(occActiveSampler, " THE_VEC2_glPointCoord "); }";
}
aSrcFragMainGetColor =
EOL" vec4 aColor = getColor();"
EOL" aColor.a = getAlpha();"
EOL" if (aColor.a <= 0.1) discard;"
EOL" occFragColor = aColor;";
if (textureUsed (theBits))
{
aSrcGetAlpha = pointSpriteAlphaSrc (theBits);
#if !defined(GL_ES_VERSION_2_0)
if (myContext->core11 != NULL
&& myContext->IsGlGreaterEqual (2, 1))
{
aProgramSrc->SetHeader ("#version 120"); // gl_PointCoord has been added since GLSL 1.2
}
#endif
aSrcFragMainGetColor =
EOL" vec4 aColor = getColor();"
EOL" aColor.a = getAlpha();"
EOL" if (aColor.a <= 0.1) discard;"
EOL" occFragColor = aColor;";
}
else
{
aSrcFragMainGetColor =
EOL" vec4 aColor = getColor();"
EOL" if (aColor.a <= 0.1) discard;"
EOL" occFragColor = aColor;";
}
}
else
{
@ -1162,7 +1174,7 @@ TCollection_AsciiString OpenGl_ShaderManager::pointSpriteShadingSrc (const TColl
TCollection_AsciiString aSrcFragGetColor;
if ((theBits & OpenGl_PO_TextureA) != 0)
{
aSrcFragGetColor = pointSpriteAlphaSrc() +
aSrcFragGetColor = pointSpriteAlphaSrc (theBits) +
EOL"vec4 getColor(void)"
EOL"{"
EOL" vec4 aColor = " + theBaseColorSrc + ";"
@ -1177,7 +1189,7 @@ TCollection_AsciiString OpenGl_ShaderManager::pointSpriteShadingSrc (const TColl
EOL"vec4 getColor(void)"
EOL"{"
EOL" vec4 aColor = " + theBaseColorSrc + ";"
EOL" aColor = occTexture2D(occActiveSampler, gl_PointCoord) * aColor;"
EOL" aColor = occTexture2D(occActiveSampler, " THE_VEC2_glPointCoord ") * aColor;"
EOL" if (aColor.a <= 0.1) discard;"
EOL" return aColor;"
EOL"}";

View File

@ -322,7 +322,7 @@ protected:
}
//! Prepare standard GLSL program for accessing point sprite alpha.
Standard_EXPORT TCollection_AsciiString pointSpriteAlphaSrc();
Standard_EXPORT TCollection_AsciiString pointSpriteAlphaSrc (const Standard_Integer theBits);
//! Prepare standard GLSL program for computing point sprite shading.
Standard_EXPORT TCollection_AsciiString pointSpriteShadingSrc (const TCollection_AsciiString theBaseColorSrc, const Standard_Integer theBits);

View File

@ -411,7 +411,6 @@ void OpenGl_Workspace::setTextureParams (Handle(OpenGl_Texture)&
glEnable (GL_POINT_SPRITE);
glTexEnvi (GL_POINT_SPRITE, GL_COORD_REPLACE, GL_TRUE);
anEnvMode = GL_REPLACE;
myGlContext->core15->glPointParameteri (GL_POINT_SPRITE_COORD_ORIGIN, GL_LOWER_LEFT);
}
break;
}

View File

@ -2,76 +2,22 @@ puts "========"
puts "OCC23654 Markers recompute"
puts "========"
# reflects Aspect_TypeOfMarker enumeration
set aMarkerTypeNames {
Aspect_TOM_POINT
Aspect_TOM_PLUS
Aspect_TOM_STAR
Aspect_TOM_X
Aspect_TOM_O
Aspect_TOM_O_POINT
Aspect_TOM_O_PLUS
Aspect_TOM_O_STAR
Aspect_TOM_O_X
Aspect_TOM_RING1
Aspect_TOM_RING2
Aspect_TOM_RING3
Aspect_TOM_BALL
Aspect_TOM_USERDEFINED
}
# custom marker
set aCustom1 [locate_data_file images/marker_box1.png]
set aCustom2 [locate_data_file images/marker_box2.png]
set aCustom3 [locate_data_file images/marker_dot.png]
# draw box in advance which should fit all our markers
box b -8 -8 0 16 16 2
pload VISUALIZATION
vcaps -sprites
set aV "Driver1/Viewer1/View1"
vinit name=$aV l=32 t=32 w=512 h=512
vactivate $aV
vclear
vbottom
vdisplay b
vfit
verase b
vfont add [locate_data_file DejaVuSans.ttf] SansFont
for { set aMarkerType 0 } { $aMarkerType <= 13 } { incr aMarkerType } {
set aRow [expr $aMarkerType - 7]
set aCol 5
set aName [lindex $aMarkerTypeNames $aMarkerType]
vdrawtext "$aName" "$aName" -pos 0 [expr $aRow + 0.5] 0 -color 0.5 1.0 1.0 -halign center -valign center -angle 000 -zoom 0 -height 12 -aspect bold -font SansFont
if { $aMarkerType == 13 } {
vmarkerstest m${aMarkerType}_${aCol} $aCol $aRow 0 PointsOnSide=1 FileName=$aCustom1
set aCol [expr $aCol - 1]
vmarkerstest m${aMarkerType}_${aCol} $aCol $aRow 0 PointsOnSide=1 FileName=$aCustom2
set aCol [expr $aCol - 1]
vmarkerstest m${aMarkerType}_${aCol} $aCol $aRow 0 PointsOnSide=1 FileName=$aCustom3
} else {
for { set aMarkerScale 1.0 } { $aMarkerScale <= 7 } { set aMarkerScale [expr $aMarkerScale + 0.5] } {
vmarkerstest m${aMarkerType}_${aCol} $aCol $aRow 0 MarkerType=$aMarkerType Scale=$aMarkerScale PointsOnSide=1
set aCol [expr $aCol - 1]
}
}
}
source $env(CSF_OCCTSamplesPath)/tcl/markers.tcl
set anImage1 $imagedir/${casename}_1.png
set anImage2 $imagedir/${casename}_2.png
vdump $anImage1
vclose $aV 1
vclose Driver1/Viewer1/View1 1
vinit name=$aV l=32 t=32 w=512 h=512
vactivate $aV
vinit name=View1 l=32 t=32 w=512 h=512
vactivate Driver1/Viewer1/View1
vbottom
vdisplay b
vdisplay -noupdate b
vfit
verase b
vremove b
vdump $anImage2
vdump $anImage2

View File

@ -1,67 +0,0 @@
puts "========"
puts "OCC24131 Markers using Point Sprites"
puts "========"
# reflects Aspect_TypeOfMarker enumeration
set aMarkerTypeNames {
Aspect_TOM_POINT
Aspect_TOM_PLUS
Aspect_TOM_STAR
Aspect_TOM_X
Aspect_TOM_O
Aspect_TOM_O_POINT
Aspect_TOM_O_PLUS
Aspect_TOM_O_STAR
Aspect_TOM_O_X
Aspect_TOM_RING1
Aspect_TOM_RING2
Aspect_TOM_RING3
Aspect_TOM_BALL
Aspect_TOM_USERDEFINED
}
# custom marker
set aCustom1 [locate_data_file images/marker_box1.png]
set aCustom2 [locate_data_file images/marker_box2.png]
set aCustom3 [locate_data_file images/marker_dot.png]
vfont add [locate_data_file DejaVuSans.ttf] SansFont
# draw box in advance which should fit all our markers
box b -8 -8 0 16 16 2
puts "hI"
for { set aMode 0 } { $aMode <= 1 } { incr aMode } {
set aTitle "bitmaps"
if { $aMode == 1 } { set aTitle "sprites" }
vcaps -sprites $aMode
set aV "Driver${aMode}/Viewer1/View1"
vinit name=$aV l=32 t=32 w=512 h=512
vactivate $aV
vclear
vbottom
vdisplay b
vfit
verase b
for { set aMarkerType 0 } { $aMarkerType <= 13 } { incr aMarkerType } {
set aRow [expr $aMarkerType - 7]
set aCol 5
set aName [lindex $aMarkerTypeNames $aMarkerType]
vdrawtext "$aName" "$aName" -pos 0 [expr $aRow + 0.5] 0 -color 0.5 1.0 1.0 -halign center -valign center -angle 000 -zoom 0 -height 12 -aspect bold -font SansFont
if { $aMarkerType == 13 } {
vmarkerstest m${aMarkerType}_${aCol} $aCol $aRow 0 PointsOnSide=1 FileName=$aCustom1
set aCol [expr $aCol - 1]
vmarkerstest m${aMarkerType}_${aCol} $aCol $aRow 0 PointsOnSide=1 FileName=$aCustom2
set aCol [expr $aCol - 1]
vmarkerstest m${aMarkerType}_${aCol} $aCol $aRow 0 PointsOnSide=1 FileName=$aCustom3
} else {
for { set aMarkerScale 1.0 } { $aMarkerScale <= 7 } { set aMarkerScale [expr $aMarkerScale + 0.5] } {
vmarkerstest m${aMarkerType}_${aCol} $aCol $aRow 0 MarkerType=$aMarkerType Scale=$aMarkerScale PointsOnSide=1
set aCol [expr $aCol - 1]
}
}
}
vdump $imagedir/${casename}_${aTitle}.png
}

View File

@ -0,0 +1,8 @@
puts "========"
puts "OCC24131 Markers using deprecated glBitmap"
puts "========"
pload VISUALIZATION
vcaps -sprites 0 -ffp 1
source $env(CSF_OCCTSamplesPath)/tcl/markers.tcl
vdump $imagedir/${casename}.png

View File

@ -0,0 +1,8 @@
puts "========"
puts "OCC24131 Markers using GLSL programs in Core Profile"
puts "========"
pload VISUALIZATION
vcaps -core
source $env(CSF_OCCTSamplesPath)/tcl/markers.tcl
vdump $imagedir/${casename}.png

View File

@ -0,0 +1,8 @@
puts "========"
puts "OCC24131 Markers using GLSL programs in Compatible Profile"
puts "========"
pload VISUALIZATION
vcaps -compatibleProfile -sprites 1 -ffp 0
source $env(CSF_OCCTSamplesPath)/tcl/markers.tcl
vdump $imagedir/${casename}.png

View File

@ -0,0 +1,8 @@
puts "========"
puts "OCC24131 Markers using Point Sprites and FFP"
puts "========"
pload VISUALIZATION
vcaps -sprites 1 -ffp 1
source $env(CSF_OCCTSamplesPath)/tcl/markers.tcl
vdump $imagedir/${casename}.png