0025675: Visualization - Fix problems and inefficiencies with frustum culling
[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_AspectFace.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   //! Check if background parameters are set properly
37   Standard_EXPORT bool IsDefined() const;
38
39   //! Fill attributes arrays for background array according to its type:
40   //! - for gradient background its attributes consist of colors and gradient coordinates
41   //! - for texture one its attributes consist of position and texure coordinates.
42   Standard_EXPORT Standard_Boolean Init (const Handle(OpenGl_Workspace)& theWorkspace);
43
44   //! Sets background texture parameters
45   Standard_EXPORT void SetTextureParameters (const Aspect_FillMethod theFillMethod);
46
47   //! Sets texture fill method
48   Standard_EXPORT void SetTextureFillMethod (const Aspect_FillMethod theFillMethod);
49
50   //! Gets background texture fill method
51   Aspect_FillMethod TextureFillMethod() const { return myFillMethod; }
52
53   //! Gets background gradient fill method
54   Aspect_GradientFillMethod GradientFillMethod() const { return myGradientParams.type; }
55
56   //! Sets type of gradient fill method
57   Standard_EXPORT void SetGradientFillMethod (const Aspect_GradientFillMethod theType);
58
59   //! Sets background gradient parameters
60   Standard_EXPORT void SetGradientParameters (const Quantity_Color&           theColor1,
61                                               const Quantity_Color&           theColor2,
62                                               const Aspect_GradientFillMethod theType);
63
64   //! Shows if array parameters were changed
65   Standard_Boolean IsDataChanged() const { return myToUpdate; }
66
67   //! Shows if view sizes were changed
68   //! (texture coordinates is no be changed)
69   Standard_Boolean IsViewSizeChanged (const Handle(OpenGl_Workspace)& theWorkspace) const
70   {
71     return myType == Graphic3d_TOB_TEXTURE
72        && (myViewWidth  != theWorkspace->Width()
73         || myViewHeight != theWorkspace->Height());
74   }
75
76 protected: //! @name Internal structure for storing gradient parameters
77
78   struct OpenGl_GradientParameters
79   {
80     OpenGl_Vec4 color1;
81     OpenGl_Vec4 color2;
82     Aspect_GradientFillMethod type;
83   };
84
85 protected:
86
87   //! Initializes gradient arrays.
88   Standard_EXPORT Standard_Boolean createGradientArray();
89
90   //! Initializes texture arrays.
91   //! @param theWorkspace OpenGl workspace that stores texture in the current enabled face aspect.
92   Standard_EXPORT Standard_Boolean createTextureArray (const Handle(OpenGl_Workspace)& theWorkspace);
93
94   //! Marks array parameters as changed,
95   //! on next rendering stage array data is to be updated.
96   Standard_EXPORT void invalidateData();
97
98 protected:
99
100   Standard_Boolean           myToUpdate;       //!< Shows if array parameters were changed and data (myAttribs storage) is to be updated
101   Graphic3d_TypeOfBackground myType;           //!< Type of background: texture or gradient.
102   Standard_Integer           myViewWidth;      //!< view width  used for array initialization
103   Standard_Integer           myViewHeight;     //!< view height used for array initialization
104   Aspect_FillMethod          myFillMethod;     //!< Texture parameters
105   OpenGl_GradientParameters  myGradientParams; //!< Gradient parameters
106
107 };
108
109 #endif // OpenGl_BackgroundArray_Header