0031682: Visualization - Prs3d_ShadingAspect::SetTransparency() has no effect with...
[occt.git] / src / OpenGl / OpenGl_BackgroundArray.hxx
1 // Created on: 2015-01-16
2 // Created by: Anastasia BORISOVA
3 // Copyright (c) 2015 OPEN CASCADE SAS
4 //
5 // This file is part of Open CASCADE Technology software library.
6 //
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.
12 //
13 // Alternatively, this file may be used under the terms of Open CASCADE
14 // commercial license or contractual agreement.
15
16 #ifndef OpenGl_BackgroundArray_Header
17 #define OpenGl_BackgroundArray_Header
18
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>
26
27 //! Tool class for generating reusable data for
28 //! gradient or texture background rendering.
29 class OpenGl_BackgroundArray : public OpenGl_PrimitiveArray
30 {
31 public:
32
33   //! Main constructor.
34   Standard_EXPORT OpenGl_BackgroundArray (const Graphic3d_TypeOfBackground theType);
35
36   //! Render primitives to the window
37   Standard_EXPORT void Render (const Handle(OpenGl_Workspace)& theWorkspace,
38                                Graphic3d_Camera::Projection theProjection) const;
39
40   //! Check if background parameters are set properly
41   Standard_EXPORT bool IsDefined() const;
42
43   //! Sets background texture parameters
44   Standard_EXPORT void SetTextureParameters (const Aspect_FillMethod theFillMethod);
45
46   //! Sets texture fill method
47   Standard_EXPORT void SetTextureFillMethod (const Aspect_FillMethod theFillMethod);
48
49   //! Gets background texture fill method
50   Aspect_FillMethod TextureFillMethod() const { return myFillMethod; }
51
52   //! Gets background gradient fill method
53   Aspect_GradientFillMethod GradientFillMethod() const { return myGradientParams.type; }
54
55   //! Returns color of gradient background for the given index.
56   const OpenGl_Vec4& GradientColor (const Standard_Integer theIndex) const { return (&myGradientParams.color1)[theIndex]; }
57
58   //! Sets type of gradient fill method
59   Standard_EXPORT void SetGradientFillMethod (const Aspect_GradientFillMethod theType);
60
61   //! Sets background gradient parameters
62   Standard_EXPORT void SetGradientParameters (const Quantity_Color&           theColor1,
63                                               const Quantity_Color&           theColor2,
64                                               const Aspect_GradientFillMethod theType);
65
66 protected: //! @name Internal structure for storing gradient parameters
67
68   struct OpenGl_GradientParameters
69   {
70     OpenGl_Vec4 color1;
71     OpenGl_Vec4 color2;
72     Aspect_GradientFillMethod type;
73   };
74
75 protected:
76
77   //! Fill attributes arrays for background array according to its type:
78   //! - for gradient background its attributes consist of colors and gradient coordinates
79   //! - for texture one its attributes consist of position and texture coordinates.
80   Standard_EXPORT Standard_Boolean init (const Handle(OpenGl_Workspace)& theWorkspace) const;
81
82   //! Initializes gradient arrays.
83   Standard_EXPORT Standard_Boolean createGradientArray (const Handle(OpenGl_Context)& theCtx) const;
84
85   //! Initializes texture arrays.
86   //! @param theWorkspace OpenGl workspace that stores texture in the current enabled face aspect.
87   Standard_EXPORT Standard_Boolean createTextureArray (const Handle(OpenGl_Workspace)& theWorkspace) const;
88
89   //! Initializes cubemap arrays.
90   Standard_EXPORT Standard_Boolean createCubeMapArray() const;
91
92   //! Marks array parameters as changed,
93   //! on next rendering stage array data is to be updated.
94   Standard_EXPORT void invalidateData();
95
96   using OpenGl_PrimitiveArray::Render;
97
98 protected:
99
100   Graphic3d_TypeOfBackground        myType;           //!< Type of background: texture or gradient.
101   Aspect_FillMethod                 myFillMethod;     //!< Texture parameters
102   mutable OpenGl_GradientParameters myGradientParams; //!< Gradient parameters
103   mutable Standard_Integer          myViewWidth;      //!< view width  used for array initialization
104   mutable Standard_Integer          myViewHeight;     //!< view height used for array initialization
105   mutable Standard_Boolean          myToUpdate;       //!< Shows if array parameters were changed and data (myAttribs storage) is to be updated
106
107 };
108
109 #endif // OpenGl_BackgroundArray_Header