From fd59283a7b69e7568271fe59860b8175f741c945 Mon Sep 17 00:00:00 2001 From: kgv Date: Fri, 24 Jun 2016 11:36:57 +0300 Subject: [PATCH] 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. --- data/images/marker_kr.png | Bin 0 -> 1051 bytes samples/tcl/markers.tcl | 74 +++++++++++++++++++++++ src/OpenGl/OpenGl_Context.cxx | 23 +++++++ src/OpenGl/OpenGl_Context.hxx | 7 +++ src/OpenGl/OpenGl_PrimitiveArray.cxx | 1 + src/OpenGl/OpenGl_ShaderManager.cxx | 64 ++++++++++++-------- src/OpenGl/OpenGl_ShaderManager.hxx | 2 +- src/OpenGl/OpenGl_Workspace.cxx | 1 - tests/bugs/vis/bug23654_MarkersRecompute | 70 +++------------------ tests/bugs/vis/bug24131_markers | 67 -------------------- tests/bugs/vis/bug24131_markers_bitmap | 8 +++ tests/bugs/vis/bug24131_markers_core | 8 +++ tests/bugs/vis/bug24131_markers_glsl | 8 +++ tests/bugs/vis/bug24131_markers_sprites | 8 +++ 14 files changed, 184 insertions(+), 157 deletions(-) create mode 100644 data/images/marker_kr.png create mode 100644 samples/tcl/markers.tcl delete mode 100644 tests/bugs/vis/bug24131_markers create mode 100644 tests/bugs/vis/bug24131_markers_bitmap create mode 100644 tests/bugs/vis/bug24131_markers_core create mode 100644 tests/bugs/vis/bug24131_markers_glsl create mode 100644 tests/bugs/vis/bug24131_markers_sprites diff --git a/data/images/marker_kr.png b/data/images/marker_kr.png new file mode 100644 index 0000000000000000000000000000000000000000..ede395a6586bc7ce637d63ca293ccca4138ed03c GIT binary patch literal 1051 zcmV+$1mydPP)y{{x5*-aJ1Q%mnB*8Fm@M2+P z)hjhRuS^VEGz0O^F3fgCxG`$z41?-YyaA(Tnk+=YV9g8_P%}s1Vq^)8ZnMMi#~Q*$ zTMplOy|CHZQrnJp(ThD-=e*DRyzg_qeD8NYxQqW7su)E?WGAp6Z~)&brT$9dYJp~8 z5%^9iCB^8O-27gx^;|3#+la^GdTD8Cy}iACUxIsDYaLx(U5$%~jEs!@3>e9JBV*Ou z!()q!iw`z5G(_9l+WbzZ)8TM9z7!Fqwf<;waY}h`bk%$IZsZ#v5yEYfcdnuh%Q{^YdO2d9|vlsuifd69y2G6Q*hEKp>#qZub!p z*()LvjYef`Y%Cm!M68L4i7WiGPwt2TRbO9!G7^bw4i676O;1lhA|f&{Fd#s8AQ140 zh`8PEcan7l?*S2M7Li_`&$lBK3cYE!+kY=FFL!!8p1oRY%Przd-REK9?tt%o5;F6emD>(T>kDCFR}&nIO`K*YzlGg`?RM)p3r7 z{n;||S%FK4dOa;xN0}VYsWcePostd0Rm3{TO1KZjY#R4Ar*=J@RbP4Ea$yE+>Ulc; zxIz~eqPkN!MJa|ll|{YI3l}#EGoZM6z2<26EO0(8qlNxmhyF#K*Y!L9DNqPPcLwGI zPVT-x?>cF?H3g!sqqva5YAf}O@3{6g{ncN9s!Mi8sd)%E4NQYde3ayvkh}Pw;BR8K Veuc2yRglPointParameteri (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