1 // Created on: 2015-01-16
2 // Created by: Anastasia BORISOVA
3 // Copyright (c) 2015 OPEN CASCADE SAS
5 // This file is part of Open CASCADE Technology software library.
7 // This library is free software; you can redistribute it and/or modify it under
8 // the terms of the GNU Lesser General Public License version 2.1 as published
9 // by the Free Software Foundation, with special exception defined in the file
10 // OCCT_LGPL_EXCEPTION.txt. Consult the file LICENSE_LGPL_21.txt included in OCCT
11 // distribution for complete text of the license and disclaimer of any warranty.
13 // Alternatively, this file may be used under the terms of Open CASCADE
14 // commercial license or contractual agreement.
16 #ifndef OpenGl_BackgroundArray_Header
17 #define OpenGl_BackgroundArray_Header
19 #include <Aspect_GradientFillMethod.hxx>
20 #include <Aspect_FillMethod.hxx>
21 #include <Graphic3d_TypeOfBackground.hxx>
22 #include <OpenGl_Aspects.hxx>
23 #include <OpenGl_PrimitiveArray.hxx>
24 #include <OpenGl_Vec.hxx>
25 #include <OpenGl_Workspace.hxx>
27 //! Tool class for generating reusable data for
28 //! gradient or texture background rendering.
29 class OpenGl_BackgroundArray : public OpenGl_PrimitiveArray
34 Standard_EXPORT OpenGl_BackgroundArray (const Graphic3d_TypeOfBackground theType);
36 //! Render primitives to the window
37 Standard_EXPORT virtual void Render (const Handle(OpenGl_Workspace)& theWorkspace) const Standard_OVERRIDE;
39 //! Check if background parameters are set properly
40 Standard_EXPORT bool IsDefined() const;
42 //! Sets background texture parameters
43 Standard_EXPORT void SetTextureParameters (const Aspect_FillMethod theFillMethod);
45 //! Sets texture fill method
46 Standard_EXPORT void SetTextureFillMethod (const Aspect_FillMethod theFillMethod);
48 //! Gets background texture fill method
49 Aspect_FillMethod TextureFillMethod() const { return myFillMethod; }
51 //! Gets background gradient fill method
52 Aspect_GradientFillMethod GradientFillMethod() const { return myGradientParams.type; }
54 //! Returns color of gradient background for the given index.
55 const OpenGl_Vec4& GradientColor (const Standard_Integer theIndex) const { return (&myGradientParams.color1)[theIndex]; }
57 //! Sets type of gradient fill method
58 Standard_EXPORT void SetGradientFillMethod (const Aspect_GradientFillMethod theType);
60 //! Sets background gradient parameters
61 Standard_EXPORT void SetGradientParameters (const Quantity_Color& theColor1,
62 const Quantity_Color& theColor2,
63 const Aspect_GradientFillMethod theType);
65 protected: //! @name Internal structure for storing gradient parameters
67 struct OpenGl_GradientParameters
71 Aspect_GradientFillMethod type;
76 //! Fill attributes arrays for background array according to its type:
77 //! - for gradient background its attributes consist of colors and gradient coordinates
78 //! - for texture one its attributes consist of position and texture coordinates.
79 Standard_EXPORT Standard_Boolean init (const Handle(OpenGl_Workspace)& theWorkspace) const;
81 //! Initializes gradient arrays.
82 Standard_EXPORT Standard_Boolean createGradientArray (const Handle(OpenGl_Context)& theCtx) const;
84 //! Initializes texture arrays.
85 //! @param theWorkspace OpenGl workspace that stores texture in the current enabled face aspect.
86 Standard_EXPORT Standard_Boolean createTextureArray (const Handle(OpenGl_Workspace)& theWorkspace) const;
88 //! Initializes cubemap arrays.
89 Standard_EXPORT Standard_Boolean createCubeMapArray() const;
91 //! Marks array parameters as changed,
92 //! on next rendering stage array data is to be updated.
93 Standard_EXPORT void invalidateData();
97 Graphic3d_TransformPers myTrsfPers; //!< transformation persistence
98 Graphic3d_TypeOfBackground myType; //!< Type of background: texture or gradient.
99 Aspect_FillMethod myFillMethod; //!< Texture parameters
100 mutable OpenGl_GradientParameters myGradientParams; //!< Gradient parameters
101 mutable Standard_Integer myViewWidth; //!< view width used for array initialization
102 mutable Standard_Integer myViewHeight; //!< view height used for array initialization
103 mutable Standard_Boolean myToUpdate; //!< Shows if array parameters were changed and data (myAttribs storage) is to be updated
107 #endif // OpenGl_BackgroundArray_Header