From 9af0d66b849ddce139dad856da170ce53db7b1e2 Mon Sep 17 00:00:00 2001 From: achesnok Date: Tue, 21 Sep 2021 18:42:21 +0300 Subject: [PATCH] 0031039: Visualization - add elliptical gradient background style Added new elliptical gradient fill method and updated vbackground command. Renamed enum values of Aspect_GradientFillMethod and defined aliases for old ones. Changed draw mode in OpenGl_BackgroundArray from triangle-strip to GL_TRIANGLES. --- src/Aspect/Aspect_GradientBackground.cxx | 2 +- src/Aspect/Aspect_GradientBackground.hxx | 59 +++------ src/Aspect/Aspect_GradientFillMethod.hxx | 33 +++-- src/OpenGl/OpenGl_BackgroundArray.cxx | 125 +++++++++++++++---- src/OpenGl/OpenGl_View.cxx | 2 +- src/V3d/V3d_View.hxx | 4 +- src/V3d/V3d_Viewer.hxx | 2 +- src/ViewerTest/ViewerTest_OpenGlCommands.cxx | 2 +- src/ViewerTest/ViewerTest_ViewerCommands.cxx | 41 +++--- tests/opengl/data/background/bug25775 | 3 + tests/opengl/data/background/elliptical | 10 ++ 11 files changed, 182 insertions(+), 101 deletions(-) create mode 100644 tests/opengl/data/background/elliptical diff --git a/src/Aspect/Aspect_GradientBackground.cxx b/src/Aspect/Aspect_GradientBackground.cxx index 6bbfc67a34..ae3a2754c9 100644 --- a/src/Aspect/Aspect_GradientBackground.cxx +++ b/src/Aspect/Aspect_GradientBackground.cxx @@ -22,7 +22,7 @@ Aspect_GradientBackground::Aspect_GradientBackground () { SetColor( Black ); MyColor2 = Black; - MyGradientMethod = Aspect_GFM_NONE; + MyGradientMethod = Aspect_GradientFillMethod_None; } diff --git a/src/Aspect/Aspect_GradientBackground.hxx b/src/Aspect/Aspect_GradientBackground.hxx index 2bc111e731..c204ea32d2 100644 --- a/src/Aspect/Aspect_GradientBackground.hxx +++ b/src/Aspect/Aspect_GradientBackground.hxx @@ -16,68 +16,45 @@ #ifndef _Aspect_GradientBackground_HeaderFile #define _Aspect_GradientBackground_HeaderFile -#include -#include -#include - -#include #include #include -class Quantity_Color; - -//! This class allows the definition of -//! a window gradient background. +//! This class allows the definition of a window gradient background. class Aspect_GradientBackground : public Aspect_Background { public: DEFINE_STANDARD_ALLOC - //! Creates a window gradient background. - //! Default colors : Quantity_NOC_BLACK. - //! Default fill method : Aspect_GFM_NONE + //! Default color is Quantity_NOC_BLACK. + //! Default fill method is Aspect_GradientFillMethod_None. Standard_EXPORT Aspect_GradientBackground(); - - //! Creates a window gradient background with colours . - Standard_EXPORT Aspect_GradientBackground(const Quantity_Color& AColor1, const Quantity_Color& AColor2, const Aspect_GradientFillMethod AMethod = Aspect_GFM_HOR); - - //! Modifies the colours of the window gradient background . - Standard_EXPORT void SetColors (const Quantity_Color& AColor1, const Quantity_Color& AColor2, const Aspect_GradientFillMethod AMethod = Aspect_GFM_HOR); - - //! Returns colours of the window gradient background . - Standard_EXPORT void Colors (Quantity_Color& AColor1, Quantity_Color& AColor2) const; - + + //! Creates a window gradient background with two colours. + Standard_EXPORT Aspect_GradientBackground (const Quantity_Color& theColor1, + const Quantity_Color& theColor2, + const Aspect_GradientFillMethod theMethod = Aspect_GradientFillMethod_Horizontal); + + //! Modifies the colours of the window gradient background. + Standard_EXPORT void SetColors (const Quantity_Color& theColor1, + const Quantity_Color& theColor2, + const Aspect_GradientFillMethod theMethod = Aspect_GradientFillMethod_Horizontal); + + //! Returns colours of the window gradient background. + Standard_EXPORT void Colors (Quantity_Color& theColor1, Quantity_Color& theColor2) const; + //! Returns the current gradient background fill mode. Standard_EXPORT Aspect_GradientFillMethod BgGradientFillMethod() const; - + //! Dumps the content of me into the stream Standard_EXPORT void DumpJson (Standard_OStream& theOStream, Standard_Integer theDepth = -1) const; - - - -protected: - - - - - private: - - Quantity_Color MyColor2; Aspect_GradientFillMethod MyGradientMethod; - }; - - - - - - #endif // _Aspect_GradientBackground_HeaderFile diff --git a/src/Aspect/Aspect_GradientFillMethod.hxx b/src/Aspect/Aspect_GradientFillMethod.hxx index cb6315defb..a3231c8898 100644 --- a/src/Aspect/Aspect_GradientFillMethod.hxx +++ b/src/Aspect/Aspect_GradientFillMethod.hxx @@ -16,19 +16,30 @@ #ifndef _Aspect_GradientFillMethod_HeaderFile #define _Aspect_GradientFillMethod_HeaderFile -//! Defines the fill methods to -//! write gradient background in a window. +//! Defines the fill methods to write gradient background in a window. enum Aspect_GradientFillMethod { -Aspect_GFM_NONE, -Aspect_GFM_HOR, -Aspect_GFM_VER, -Aspect_GFM_DIAG1, -Aspect_GFM_DIAG2, -Aspect_GFM_CORNER1, -Aspect_GFM_CORNER2, -Aspect_GFM_CORNER3, -Aspect_GFM_CORNER4 + Aspect_GradientFillMethod_None, //!< fill method not specified + Aspect_GradientFillMethod_Horizontal, //!< gradient directed from left (Color1) to right (Color2) + Aspect_GradientFillMethod_Vertical, //!< gradient directed from top (Color1) to bottom (Color2) + Aspect_GradientFillMethod_Diagonal1, //!< gradient directed from upper left corner (Color1) to lower right (Color2) + Aspect_GradientFillMethod_Diagonal2, //!< gradient directed from upper right corner (Color1) to lower left (Color2) + Aspect_GradientFillMethod_Corner1, //!< highlights upper left corner with Color1 + Aspect_GradientFillMethod_Corner2, //!< highlights upper right corner with Color1 + Aspect_GradientFillMethod_Corner3, //!< highlights lower right corner with Color1 + Aspect_GradientFillMethod_Corner4, //!< highlights lower left corner with Color1 + Aspect_GradientFillMethod_Elliptical, //!< gradient directed from center (Color1) in all directions forming an elliptic shape (Color2) + + // obsolete aliases + Aspect_GFM_NONE = Aspect_GradientFillMethod_None, + Aspect_GFM_HOR = Aspect_GradientFillMethod_Horizontal, + Aspect_GFM_VER = Aspect_GradientFillMethod_Vertical, + Aspect_GFM_DIAG1 = Aspect_GradientFillMethod_Diagonal1, + Aspect_GFM_DIAG2 = Aspect_GradientFillMethod_Diagonal2, + Aspect_GFM_CORNER1 = Aspect_GradientFillMethod_Corner1, + Aspect_GFM_CORNER2 = Aspect_GradientFillMethod_Corner2, + Aspect_GFM_CORNER3 = Aspect_GradientFillMethod_Corner3, + Aspect_GFM_CORNER4 = Aspect_GradientFillMethod_Corner4 }; #endif // _Aspect_GradientFillMethod_HeaderFile diff --git a/src/OpenGl/OpenGl_BackgroundArray.cxx b/src/OpenGl/OpenGl_BackgroundArray.cxx index 6bd9193068..cceff8f511 100644 --- a/src/OpenGl/OpenGl_BackgroundArray.cxx +++ b/src/OpenGl/OpenGl_BackgroundArray.cxx @@ -25,19 +25,19 @@ // purpose : // ======================================================================= OpenGl_BackgroundArray::OpenGl_BackgroundArray (const Graphic3d_TypeOfBackground theType) -: OpenGl_PrimitiveArray (NULL, Graphic3d_TOPA_TRIANGLESTRIPS, NULL, NULL, NULL), +: OpenGl_PrimitiveArray (NULL, Graphic3d_TOPA_TRIANGLES, NULL, NULL, NULL), myType (theType), myFillMethod (Aspect_FM_NONE), myViewWidth (0), myViewHeight (0), myToUpdate (Standard_False) { - myDrawMode = GL_TRIANGLE_STRIP; + myDrawMode = GL_TRIANGLES; myIsFillType = true; myGradientParams.color1 = OpenGl_Vec4 (0.0f, 0.0f, 0.0f, 1.0f); myGradientParams.color2 = OpenGl_Vec4 (0.0f, 0.0f, 0.0f, 1.0f); - myGradientParams.type = Aspect_GFM_NONE; + myGradientParams.type = Aspect_GradientFillMethod_None; } // ======================================================================= @@ -112,7 +112,7 @@ bool OpenGl_BackgroundArray::IsDefined() const { switch (myType) { - case Graphic3d_TOB_GRADIENT: return myGradientParams.type != Aspect_GFM_NONE; + case Graphic3d_TOB_GRADIENT: return myGradientParams.type != Aspect_GradientFillMethod_None; case Graphic3d_TOB_TEXTURE: return myFillMethod != Aspect_FM_NONE; case Graphic3d_TOB_CUBEMAP: return Standard_True; case Graphic3d_TOB_NONE: return Standard_False; @@ -136,6 +136,16 @@ void OpenGl_BackgroundArray::invalidateData() Standard_Boolean OpenGl_BackgroundArray::init (const Handle(OpenGl_Workspace)& theWorkspace) const { const Handle(OpenGl_Context)& aCtx = theWorkspace->GetGlContext(); + + if (myIndices.IsNull()) + { + myIndices = new Graphic3d_IndexBuffer (Graphic3d_Buffer::DefaultAllocator()); + } + if (myAttribs.IsNull()) + { + myAttribs = new Graphic3d_Buffer (Graphic3d_Buffer::DefaultAllocator()); + } + switch (myType) { case Graphic3d_TOB_GRADIENT: @@ -195,10 +205,6 @@ Standard_Boolean OpenGl_BackgroundArray::createGradientArray (const Handle(OpenG { Graphic3d_TOA_COLOR, Graphic3d_TOD_VEC3 } }; - if (myAttribs.IsNull()) - { - myAttribs = new Graphic3d_Buffer (Graphic3d_Buffer::DefaultAllocator()); - } if (!myAttribs->Init (4, aGragientAttribInfo, 2)) { return Standard_False; @@ -218,7 +224,7 @@ Standard_Boolean OpenGl_BackgroundArray::createGradientArray (const Handle(OpenG switch (myGradientParams.type) { - case Aspect_GFM_HOR: + case Aspect_GradientFillMethod_Horizontal: { aCorners[0] = myGradientParams.color2.ChangeData(); aCorners[1] = myGradientParams.color2.ChangeData(); @@ -226,7 +232,7 @@ Standard_Boolean OpenGl_BackgroundArray::createGradientArray (const Handle(OpenG aCorners[3] = myGradientParams.color1.ChangeData(); break; } - case Aspect_GFM_VER: + case Aspect_GradientFillMethod_Vertical: { aCorners[0] = myGradientParams.color2.ChangeData(); aCorners[1] = myGradientParams.color1.ChangeData(); @@ -234,7 +240,7 @@ Standard_Boolean OpenGl_BackgroundArray::createGradientArray (const Handle(OpenG aCorners[3] = myGradientParams.color1.ChangeData(); break; } - case Aspect_GFM_DIAG1: + case Aspect_GradientFillMethod_Diagonal1: { aCorners[0] = myGradientParams.color2.ChangeData(); aCorners[3] = myGradientParams.color1.ChangeData(); @@ -245,7 +251,7 @@ Standard_Boolean OpenGl_BackgroundArray::createGradientArray (const Handle(OpenG aCorners[2] = aDiagCorner2; break; } - case Aspect_GFM_DIAG2: + case Aspect_GradientFillMethod_Diagonal2: { aCorners[1] = myGradientParams.color1.ChangeData(); aCorners[2] = myGradientParams.color2.ChangeData(); @@ -256,7 +262,7 @@ Standard_Boolean OpenGl_BackgroundArray::createGradientArray (const Handle(OpenG aCorners[3] = aDiagCorner2; break; } - case Aspect_GFM_CORNER1: + case Aspect_GradientFillMethod_Corner1: { aVertices[0] = OpenGl_Vec2(float(myViewWidth), float(myViewHeight)); aVertices[1] = OpenGl_Vec2(0.0f, float(myViewHeight)); @@ -269,7 +275,7 @@ Standard_Boolean OpenGl_BackgroundArray::createGradientArray (const Handle(OpenG aCorners[3] = myGradientParams.color2.ChangeData(); break; } - case Aspect_GFM_CORNER2: + case Aspect_GradientFillMethod_Corner2: { aCorners[0] = myGradientParams.color2.ChangeData(); aCorners[1] = myGradientParams.color1.ChangeData(); @@ -277,7 +283,7 @@ Standard_Boolean OpenGl_BackgroundArray::createGradientArray (const Handle(OpenG aCorners[3] = myGradientParams.color2.ChangeData(); break; } - case Aspect_GFM_CORNER3: + case Aspect_GradientFillMethod_Corner3: { aVertices[0] = OpenGl_Vec2(float(myViewWidth), float(myViewHeight)); aVertices[1] = OpenGl_Vec2(0.0f, float(myViewHeight)); @@ -290,7 +296,7 @@ Standard_Boolean OpenGl_BackgroundArray::createGradientArray (const Handle(OpenG aCorners[3] = myGradientParams.color2.ChangeData(); break; } - case Aspect_GFM_CORNER4: + case Aspect_GradientFillMethod_Corner4: { aCorners[0] = myGradientParams.color2.ChangeData(); aCorners[1] = myGradientParams.color2.ChangeData(); @@ -298,7 +304,53 @@ Standard_Boolean OpenGl_BackgroundArray::createGradientArray (const Handle(OpenG aCorners[3] = myGradientParams.color2.ChangeData(); break; } - case Aspect_GFM_NONE: + case Aspect_GradientFillMethod_Elliptical: + { + // construction of a circle circumscribed about a view rectangle + // using parametric equation (scaled by aspect ratio and centered) + const Standard_Integer aSubdiv = 64; + if (!myAttribs->Init (aSubdiv + 2, aGragientAttribInfo, 2)) + { + return Standard_False; + } + + OpenGl_Vec2 anEllipVerts[aSubdiv + 2]; + anEllipVerts[0] = OpenGl_Vec2 (float (myViewWidth) / 2.0f, float (myViewHeight) / 2.0f); + Standard_Real aTetta = (M_PI * 2.0) / aSubdiv; + Standard_Real aParam = 0.0; + for (Standard_Integer anIt = 1; anIt < aSubdiv + 2; ++anIt) + { + anEllipVerts[anIt] = OpenGl_Vec2 (float (Cos (aParam) * Sqrt (2.0) * myViewWidth / 2.0 + myViewWidth / 2.0f), + float (Sin (aParam) * Sqrt (2.0) * myViewHeight / 2.0 + myViewHeight / 2.0f)); + + aParam += aTetta; + } + for (Standard_Integer anIt = 0; anIt < aSubdiv + 2; ++anIt) + { + OpenGl_Vec2* aVertData = reinterpret_cast(myAttribs->changeValue (anIt)); + *aVertData = anEllipVerts[anIt]; + + OpenGl_Vec3* aColorData = reinterpret_cast(myAttribs->changeValue (anIt) + myAttribs->AttributeOffset (1)); + *aColorData = myGradientParams.color2.rgb(); + } + // the central vertex is colored in different way + OpenGl_Vec3* aColorData = reinterpret_cast(myAttribs->changeValue (0) + myAttribs->AttributeOffset (1)); + *aColorData = myGradientParams.color1.rgb(); + + if (!myIndices->Init (3 * aSubdiv)) + { + return Standard_False; + } + for (Standard_Integer aCurTri = 0; aCurTri < aSubdiv; aCurTri++) + { + myIndices->SetIndex (aCurTri * 3 + 0, 0); + myIndices->SetIndex (aCurTri * 3 + 1, aCurTri + 1); + myIndices->SetIndex (aCurTri * 3 + 2, aCurTri + 2); + } + + return Standard_True; + } + case Aspect_GradientFillMethod_None: { break; } @@ -313,6 +365,15 @@ Standard_Boolean OpenGl_BackgroundArray::createGradientArray (const Handle(OpenG *aColorData = theCtx->Vec4FromQuantityColor (OpenGl_Vec4(aCorners[anIt][0], aCorners[anIt][1], aCorners[anIt][2], 1.0f)).rgb(); } + if (!myIndices->Init(6)) + { + return Standard_False; + } + const unsigned short THE_FS_QUAD_TRIS[6] = {0, 1, 2, 1, 3, 2}; + for (unsigned int aVertIter = 0; aVertIter < 6; ++aVertIter) + { + myIndices->SetIndex (aVertIter, THE_FS_QUAD_TRIS[aVertIter]); + } return Standard_True; } @@ -328,10 +389,6 @@ Standard_Boolean OpenGl_BackgroundArray::createTextureArray (const Handle(OpenGl { Graphic3d_TOA_UV, Graphic3d_TOD_VEC2 } }; - if (myAttribs.IsNull()) - { - myAttribs = new Graphic3d_Buffer (Graphic3d_Buffer::DefaultAllocator()); - } if (!myAttribs->Init (4, aTextureAttribInfo, 2)) { return Standard_False; @@ -386,6 +443,16 @@ Standard_Boolean OpenGl_BackgroundArray::createTextureArray (const Handle(OpenGl aData[0] = OpenGl_Vec2 (-anOffsetX, aCoef * anOffsetY); aData[1] = OpenGl_Vec2 (0.0f, aCoef * aTexRangeY); + if (!myIndices->Init(6)) + { + return Standard_False; + } + const unsigned short THE_FS_QUAD_TRIS[6] = {0, 1, 2, 1, 3, 2}; + for (unsigned int aVertIter = 0; aVertIter < 6; ++aVertIter) + { + myIndices->SetIndex (aVertIter, THE_FS_QUAD_TRIS[aVertIter]); + } + return Standard_True; } @@ -406,7 +473,7 @@ Standard_Boolean OpenGl_BackgroundArray::createCubeMapArray() const myIndices = new Graphic3d_IndexBuffer (Graphic3d_Buffer::DefaultAllocator()); } if (!myAttribs->Init (8, aCubeMapAttribInfo, 1) - || !myIndices->Init (14)) + || !myIndices->Init (6 * 3 * 2)) { return Standard_False; } @@ -423,10 +490,18 @@ Standard_Boolean OpenGl_BackgroundArray::createCubeMapArray() const aData[7].SetValues ( 1.0, 1.0, -1.0); } { - const unsigned short THE_BOX_TRISTRIP[14] = { 0, 1, 2, 3, 7, 1, 5, 4, 7, 6, 2, 4, 0, 1 }; - for (unsigned int aVertIter = 0; aVertIter < 14; ++aVertIter) + const unsigned short THE_BOX_TRIS[] = { - myIndices->SetIndex (aVertIter, THE_BOX_TRISTRIP[aVertIter]); + 0, 1, 2, 2, 1, 3, // top face + 1, 5, 7, 1, 7, 3, // right face + 0, 6, 4, 0, 2, 6, // left face + 4, 6, 5, 6, 7, 5, // bottom face + 0, 5, 1, 0, 4, 5, // front face + 2, 7, 6, 2, 3, 7 // back face + }; + for (unsigned int aVertIter = 0; aVertIter < 6 * 3 * 2; ++aVertIter) + { + myIndices->SetIndex (aVertIter, THE_BOX_TRIS[aVertIter]); } } diff --git a/src/OpenGl/OpenGl_View.cxx b/src/OpenGl/OpenGl_View.cxx index 0fd648c30c..ed411f2fc4 100644 --- a/src/OpenGl/OpenGl_View.cxx +++ b/src/OpenGl/OpenGl_View.cxx @@ -967,7 +967,7 @@ void OpenGl_View::drawBackground (const Handle(OpenGl_Workspace)& theWorkspace, || myBackgroundType == Graphic3d_TOB_TEXTURE) { // Drawing background gradient if: - // - gradient fill type is not Aspect_GFM_NONE and + // - gradient fill type is not Aspect_GradientFillMethod_None and // - either background texture is no specified or it is drawn in Aspect_FM_CENTERED mode if (myBackgrounds[Graphic3d_TOB_GRADIENT]->IsDefined() && (!myTextureParams->Aspect()->ToMapTexture() diff --git a/src/V3d/V3d_View.hxx b/src/V3d/V3d_View.hxx index 22beabcc7e..e48a255d26 100644 --- a/src/V3d/V3d_View.hxx +++ b/src/V3d/V3d_View.hxx @@ -188,11 +188,11 @@ public: //! and the fill method (horizontal by default). Standard_EXPORT void SetBgGradientColors (const Quantity_Color& theColor1, const Quantity_Color& theColor2, - const Aspect_GradientFillMethod theFillStyle = Aspect_GFM_HOR, + const Aspect_GradientFillMethod theFillStyle = Aspect_GradientFillMethod_Horizontal, const Standard_Boolean theToUpdate = Standard_False); //! Defines the gradient background fill method of the view. - Standard_EXPORT void SetBgGradientStyle (const Aspect_GradientFillMethod theMethod = Aspect_GFM_HOR, + Standard_EXPORT void SetBgGradientStyle (const Aspect_GradientFillMethod theMethod = Aspect_GradientFillMethod_Horizontal, const Standard_Boolean theToUpdate = Standard_False); //! Defines the background texture of the view by supplying the texture image file name diff --git a/src/V3d/V3d_Viewer.hxx b/src/V3d/V3d_Viewer.hxx index 2e368f82db..4e8aa7d8cd 100644 --- a/src/V3d/V3d_Viewer.hxx +++ b/src/V3d/V3d_Viewer.hxx @@ -130,7 +130,7 @@ public: //! attached to the viewer by supplying the colour objects void SetDefaultBgGradientColors (const Quantity_Color& theColor1, const Quantity_Color& theColor2, - const Aspect_GradientFillMethod theFillStyle = Aspect_GFM_HOR) + const Aspect_GradientFillMethod theFillStyle = Aspect_GradientFillMethod_Horizontal) { myGradientBackground.SetColors (theColor1, theColor2, theFillStyle); } diff --git a/src/ViewerTest/ViewerTest_OpenGlCommands.cxx b/src/ViewerTest/ViewerTest_OpenGlCommands.cxx index dd42d4a8f5..7f4af79439 100644 --- a/src/ViewerTest/ViewerTest_OpenGlCommands.cxx +++ b/src/ViewerTest/ViewerTest_OpenGlCommands.cxx @@ -926,7 +926,7 @@ static Standard_Integer VListColors (Draw_Interpretor& theDI, ViewerTest::ViewerInit (0, 0, anImgParams.Width, anImgParams.Height, "TmpDriver/TmpViewer/TmpView"); aView = ViewerTest::CurrentView(); aView->SetImmediateUpdate (false); - aView->SetBgGradientStyle (Aspect_GFM_NONE, false); + aView->SetBgGradientStyle (Aspect_GradientFillMethod_None, false); } if (!aDumpFile.IsEmpty()) diff --git a/src/ViewerTest/ViewerTest_ViewerCommands.cxx b/src/ViewerTest/ViewerTest_ViewerCommands.cxx index 8200867aab..6a3a1f74a9 100644 --- a/src/ViewerTest/ViewerTest_ViewerCommands.cxx +++ b/src/ViewerTest/ViewerTest_ViewerCommands.cxx @@ -214,7 +214,7 @@ static struct } } -} ViewerTest_DefaultBackground = { Quantity_NOC_BLACK, Quantity_NOC_BLACK, Quantity_NOC_BLACK, Aspect_GFM_NONE }; +} ViewerTest_DefaultBackground = { Quantity_NOC_BLACK, Quantity_NOC_BLACK, Quantity_NOC_BLACK, Aspect_GradientFillMethod_None }; //============================================================================== // EVENT GLOBAL VARIABLES @@ -2613,46 +2613,51 @@ static bool parseGradientMode (const TCollection_AsciiString& theName, aName.LowerCase(); if (aName == "none") { - theMode = Aspect_GFM_NONE; + theMode = Aspect_GradientFillMethod_None; } else if (aName == "hor" || aName == "horizontal") { - theMode = Aspect_GFM_HOR; + theMode = Aspect_GradientFillMethod_Horizontal; } else if (aName == "ver" || aName == "vert" || aName == "vertical") { - theMode = Aspect_GFM_VER; + theMode = Aspect_GradientFillMethod_Vertical; } else if (aName == "diag" || aName == "diagonal" || aName == "diag1" || aName == "diagonal1") { - theMode = Aspect_GFM_DIAG1; + theMode = Aspect_GradientFillMethod_Diagonal1; } else if (aName == "diag2" || aName == "diagonal2") { - theMode = Aspect_GFM_DIAG2; + theMode = Aspect_GradientFillMethod_Diagonal2; } else if (aName == "corner1") { - theMode = Aspect_GFM_CORNER1; + theMode = Aspect_GradientFillMethod_Corner1; } else if (aName == "corner2") { - theMode = Aspect_GFM_CORNER2; + theMode = Aspect_GradientFillMethod_Corner2; } else if (aName == "corner3") { - theMode = Aspect_GFM_CORNER3; + theMode = Aspect_GradientFillMethod_Corner3; } else if (aName == "corner4") { - theMode = Aspect_GFM_CORNER4; + theMode = Aspect_GradientFillMethod_Corner4; + } + else if (aName == "ellip" + || aName == "elliptical") + { + theMode = Aspect_GradientFillMethod_Elliptical; } else { @@ -2680,7 +2685,7 @@ static int VBackground (Draw_Interpretor& theDI, Standard_Integer aNbColors = 0; Quantity_ColorRGBA aColors[2]; - Aspect_GradientFillMethod aGradientMode = Aspect_GFM_NONE; + Aspect_GradientFillMethod aGradientMode = Aspect_GradientFillMethod_None; bool hasGradientMode = false; TCollection_AsciiString anImagePath; @@ -2891,14 +2896,14 @@ static int VBackground (Draw_Interpretor& theDI, { ViewerTest_DefaultBackground.GradientColor1 = Quantity_Color(); ViewerTest_DefaultBackground.GradientColor2 = Quantity_Color(); - ViewerTest_DefaultBackground.FillMethod = Aspect_GFM_NONE; + ViewerTest_DefaultBackground.FillMethod = Aspect_GradientFillMethod_None; ViewerTest_DefaultBackground.FlatColor = aColors[0].GetRGB(); ViewerTest_DefaultBackground.SetDefaultGradient(); ViewerTest_DefaultBackground.SetDefaultColor(); } else { - aView->SetBgGradientStyle (hasGradientMode ? aGradientMode : Aspect_GFM_NONE); + aView->SetBgGradientStyle (hasGradientMode ? aGradientMode : Aspect_GradientFillMethod_None); aView->SetBackgroundColor (aColors[0].GetRGB()); } } @@ -2912,9 +2917,9 @@ static int VBackground (Draw_Interpretor& theDI, { ViewerTest_DefaultBackground.FillMethod = aGradientMode; } - else if (ViewerTest_DefaultBackground.FillMethod == Aspect_GFM_NONE) + else if (ViewerTest_DefaultBackground.FillMethod == Aspect_GradientFillMethod_None) { - ViewerTest_DefaultBackground.FillMethod = Aspect_GFM_VER; + ViewerTest_DefaultBackground.FillMethod = Aspect_GradientFillMethod_Vertical; } ViewerTest_DefaultBackground.SetDefaultGradient(); } @@ -2923,9 +2928,9 @@ static int VBackground (Draw_Interpretor& theDI, if (!hasGradientMode) { aGradientMode = aView->GradientBackground().BgGradientFillMethod(); - if (aGradientMode == Aspect_GFM_NONE) + if (aGradientMode == Aspect_GradientFillMethod_None) { - aGradientMode = Aspect_GFM_VER; + aGradientMode = Aspect_GradientFillMethod_Vertical; } } aView->SetBgGradientColors (aColors[0].GetRGB(), aColors[1].GetRGB(), aGradientMode); @@ -13654,7 +13659,7 @@ void ViewerTest::ViewerCommands(Draw_Interpretor& theCommands) theCommands.Add ("vbackground", "vbackground [-color Color [-default]]" "\n\t\t: [-gradient Color1 Color2 [-default]" - "\n\t\t: [-gradientMode {NONE|HORIZONTAL|VERTICAL|DIAG1|DIAG2|CORNER1|CORNER2|CORNER3}]=VERT]" + "\n\t\t: [-gradientMode {NONE|HORIZONTAL|VERTICAL|DIAG1|DIAG2|CORNER1|CORNER2|CORNER3|ELLIPTICAL}]=VERT]" "\n\t\t: [-imageFile ImageFile [-imageMode {CENTERED|TILED|STRETCH|NONE}]=CENTERED [-srgb {0|1}]=1]" "\n\t\t: [-cubemap CubemapFile1 [CubeMapFiles2-5] [-order TilesIndexes1-6] [-invertedz]=0 [-pbrEnv {0|1}]=1]" "\n\t\t: Changes background or some background settings." diff --git a/tests/opengl/data/background/bug25775 b/tests/opengl/data/background/bug25775 index 66c0cea0c9..7e8828bdc8 100644 --- a/tests/opengl/data/background/bug25775 +++ b/tests/opengl/data/background/bug25775 @@ -7,10 +7,13 @@ pload VISUALIZATION vbackground -default -gradient BLACK GRAY25 -gradientMode HORIZONTAL vinit View1 w=400 h=400 if { [vreadpixel 399 100 -rgb -name] != "GRAY25" } { puts "Error: bug with default gradient color is reproduced." } +vdump $imagedir/${casename}_v1.png vinit View2 w=400 h=400 if { [vreadpixel 399 100 -rgb -name] != "GRAY25" } { puts "Error: bug with default gradient color is reproduced." } +vdump $imagedir/${casename}_v2.png vbackground -default -color GRAY50 vinit View3 if { [vreadpixel 100 100 -rgb -name] != "GRAY50" } { puts "Error: bug with default background color is reproduced." } +vdump $imagedir/${casename}_v3.png diff --git a/tests/opengl/data/background/elliptical b/tests/opengl/data/background/elliptical new file mode 100644 index 0000000000..771bf591b3 --- /dev/null +++ b/tests/opengl/data/background/elliptical @@ -0,0 +1,10 @@ +puts "============" +puts "0031039: Visualization - add elliptical gradient background style" +puts "============" +puts "" + +pload VISUALIZATION +vinit View1 + +vbackground -gradient WHITE BLACK -gradientMode ELLIPTICAL +vdump $imagedir/${casename}.png