diff --git a/data/images/marker_kr.png b/data/images/marker_kr.png new file mode 100644 index 0000000000..ede395a658 Binary files /dev/null and b/data/images/marker_kr.png differ diff --git a/samples/tcl/markers.tcl b/samples/tcl/markers.tcl new file mode 100644 index 0000000000..b2d44b52eb --- /dev/null +++ b/samples/tcl/markers.tcl @@ -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" diff --git a/src/OpenGl/OpenGl_Context.cxx b/src/OpenGl/OpenGl_Context.cxx index 048b48ce87..f84875f98b 100644 --- a/src/OpenGl/OpenGl_Context.cxx +++ b/src/OpenGl/OpenGl_Context.cxx @@ -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 : diff --git a/src/OpenGl/OpenGl_Context.hxx b/src/OpenGl/OpenGl_Context.hxx index da0fc548b5..90d06b96a1 100644 --- a/src/OpenGl/OpenGl_Context.hxx +++ b/src/OpenGl/OpenGl_Context.hxx @@ -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 diff --git a/src/OpenGl/OpenGl_PrimitiveArray.cxx b/src/OpenGl/OpenGl_PrimitiveArray.cxx index 2295e3787b..fc31b70f61 100644 --- a/src/OpenGl/OpenGl_PrimitiveArray.cxx +++ b/src/OpenGl/OpenGl_PrimitiveArray.cxx @@ -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) { diff --git a/src/OpenGl/OpenGl_ShaderManager.cxx b/src/OpenGl/OpenGl_ShaderManager.cxx index 0ff8cf6aee..c999a28735 100644 --- a/src/OpenGl/OpenGl_ShaderManager.cxx +++ b/src/OpenGl/OpenGl_ShaderManager.cxx @@ -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"}"; diff --git a/src/OpenGl/OpenGl_ShaderManager.hxx b/src/OpenGl/OpenGl_ShaderManager.hxx index 8f6cad7205..f9eaf9ffc9 100644 --- a/src/OpenGl/OpenGl_ShaderManager.hxx +++ b/src/OpenGl/OpenGl_ShaderManager.hxx @@ -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); diff --git a/src/OpenGl/OpenGl_Workspace.cxx b/src/OpenGl/OpenGl_Workspace.cxx index 58a0be673a..8604545334 100644 --- a/src/OpenGl/OpenGl_Workspace.cxx +++ b/src/OpenGl/OpenGl_Workspace.cxx @@ -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; } diff --git a/tests/bugs/vis/bug23654_MarkersRecompute b/tests/bugs/vis/bug23654_MarkersRecompute index 67f4d717c3..51aaf6784c 100644 --- a/tests/bugs/vis/bug23654_MarkersRecompute +++ b/tests/bugs/vis/bug23654_MarkersRecompute @@ -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 \ No newline at end of file +vdump $anImage2 diff --git a/tests/bugs/vis/bug24131_markers b/tests/bugs/vis/bug24131_markers deleted file mode 100644 index 0701fb5b4d..0000000000 --- a/tests/bugs/vis/bug24131_markers +++ /dev/null @@ -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 -} diff --git a/tests/bugs/vis/bug24131_markers_bitmap b/tests/bugs/vis/bug24131_markers_bitmap new file mode 100644 index 0000000000..1c5d7a1dc0 --- /dev/null +++ b/tests/bugs/vis/bug24131_markers_bitmap @@ -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 diff --git a/tests/bugs/vis/bug24131_markers_core b/tests/bugs/vis/bug24131_markers_core new file mode 100644 index 0000000000..c2c603d146 --- /dev/null +++ b/tests/bugs/vis/bug24131_markers_core @@ -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 diff --git a/tests/bugs/vis/bug24131_markers_glsl b/tests/bugs/vis/bug24131_markers_glsl new file mode 100644 index 0000000000..6a4e33b1a9 --- /dev/null +++ b/tests/bugs/vis/bug24131_markers_glsl @@ -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 diff --git a/tests/bugs/vis/bug24131_markers_sprites b/tests/bugs/vis/bug24131_markers_sprites new file mode 100644 index 0000000000..0dff22b659 --- /dev/null +++ b/tests/bugs/vis/bug24131_markers_sprites @@ -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