0b0320e7 |
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 | |
189f85a3 |
56 | //! Returns color of gradient background for the given index. |
57 | const OpenGl_Vec4& GradientColor (const Standard_Integer theIndex) const { return (&myGradientParams.color1)[theIndex]; } |
58 | |
0b0320e7 |
59 | //! Sets type of gradient fill method |
60 | Standard_EXPORT void SetGradientFillMethod (const Aspect_GradientFillMethod theType); |
61 | |
62 | //! Sets background gradient parameters |
63 | Standard_EXPORT void SetGradientParameters (const Quantity_Color& theColor1, |
64 | const Quantity_Color& theColor2, |
65 | const Aspect_GradientFillMethod theType); |
66 | |
67 | //! Shows if array parameters were changed |
68 | Standard_Boolean IsDataChanged() const { return myToUpdate; } |
69 | |
70 | //! Shows if view sizes were changed |
71 | //! (texture coordinates is no be changed) |
72 | Standard_Boolean IsViewSizeChanged (const Handle(OpenGl_Workspace)& theWorkspace) const |
73 | { |
74 | return myType == Graphic3d_TOB_TEXTURE |
75 | && (myViewWidth != theWorkspace->Width() |
76 | || myViewHeight != theWorkspace->Height()); |
77 | } |
78 | |
79 | protected: //! @name Internal structure for storing gradient parameters |
80 | |
81 | struct OpenGl_GradientParameters |
82 | { |
83 | OpenGl_Vec4 color1; |
84 | OpenGl_Vec4 color2; |
85 | Aspect_GradientFillMethod type; |
86 | }; |
87 | |
88 | protected: |
89 | |
90 | //! Initializes gradient arrays. |
91 | Standard_EXPORT Standard_Boolean createGradientArray(); |
92 | |
93 | //! Initializes texture arrays. |
94 | //! @param theWorkspace OpenGl workspace that stores texture in the current enabled face aspect. |
95 | Standard_EXPORT Standard_Boolean createTextureArray (const Handle(OpenGl_Workspace)& theWorkspace); |
96 | |
97 | //! Marks array parameters as changed, |
98 | //! on next rendering stage array data is to be updated. |
99 | Standard_EXPORT void invalidateData(); |
100 | |
101 | protected: |
102 | |
103 | Standard_Boolean myToUpdate; //!< Shows if array parameters were changed and data (myAttribs storage) is to be updated |
104 | Graphic3d_TypeOfBackground myType; //!< Type of background: texture or gradient. |
105 | Standard_Integer myViewWidth; //!< view width used for array initialization |
106 | Standard_Integer myViewHeight; //!< view height used for array initialization |
107 | Aspect_FillMethod myFillMethod; //!< Texture parameters |
108 | OpenGl_GradientParameters myGradientParams; //!< Gradient parameters |
109 | |
110 | }; |
111 | |
112 | #endif // OpenGl_BackgroundArray_Header |