bf5f0ca2 |
1 | // Copyright (c) 2019 OPEN CASCADE SAS |
2 | // |
3 | // This file is part of Open CASCADE Technology software library. |
4 | // |
5 | // This library is free software; you can redistribute it and/or modify it under |
6 | // the terms of the GNU Lesser General Public License version 2.1 as published |
7 | // by the Free Software Foundation, with special exception defined in the file |
8 | // OCCT_LGPL_EXCEPTION.txt. Consult the file LICENSE_LGPL_21.txt included in OCCT |
9 | // distribution for complete text of the license and disclaimer of any warranty. |
10 | // |
11 | // Alternatively, this file may be used under the terms of Open CASCADE |
12 | // commercial license or contractual agreement. |
13 | |
14 | #ifndef _OpenGl_Aspects_Header |
15 | #define _OpenGl_Aspects_Header |
16 | |
17 | #include <OpenGl_Element.hxx> |
18 | #include <OpenGl_AspectsProgram.hxx> |
19 | #include <OpenGl_AspectsTextureSet.hxx> |
20 | #include <OpenGl_AspectsSprite.hxx> |
21 | #include <Graphic3d_Aspects.hxx> |
22 | #include <Graphic3d_BSDF.hxx> |
23 | |
24 | //! The element holding Graphic3d_Aspects. |
25 | class OpenGl_Aspects : public OpenGl_Element |
26 | { |
27 | public: |
28 | |
29 | //! Empty constructor. |
30 | Standard_EXPORT OpenGl_Aspects(); |
31 | |
32 | //! Create and assign parameters. |
33 | Standard_EXPORT OpenGl_Aspects (const Handle(Graphic3d_Aspects)& theAspect); |
34 | |
35 | //! Return aspect. |
36 | const Handle(Graphic3d_Aspects)& Aspect() const { return myAspect; } |
37 | |
38 | //! Assign parameters. |
39 | Standard_EXPORT void SetAspect (const Handle(Graphic3d_Aspects)& theAspect); |
40 | |
41 | //! Returns Shading Model. |
42 | Graphic3d_TypeOfShadingModel ShadingModel() const { return myShadingModel; } |
43 | |
44 | //! Set if lighting should be disabled or not. |
45 | void SetNoLighting() { myShadingModel = Graphic3d_TOSM_UNLIT; } |
46 | |
47 | //! Returns textures map. |
737e9a8d |
48 | const Handle(OpenGl_TextureSet)& TextureSet (const Handle(OpenGl_Context)& theCtx, |
49 | bool theToHighlight = false) const |
bf5f0ca2 |
50 | { |
737e9a8d |
51 | const Handle(OpenGl_PointSprite)& aSprite = myResSprite.Sprite (theCtx, myAspect, false); |
52 | const Handle(OpenGl_PointSprite)& aSpriteA = myResSprite.Sprite (theCtx, myAspect, true); |
53 | return myResTextureSet.TextureSet (theCtx, myAspect, aSprite, aSpriteA, theToHighlight); |
bf5f0ca2 |
54 | } |
55 | |
56 | //! Init and return OpenGl shader program resource. |
57 | //! @return shader program resource. |
58 | const Handle(OpenGl_ShaderProgram)& ShaderProgramRes (const Handle(OpenGl_Context)& theCtx) const |
59 | { |
60 | return myResProgram.ShaderProgram (theCtx, myAspect->ShaderProgram()); |
61 | } |
62 | |
63 | //! @return marker size |
64 | Standard_ShortReal MarkerSize() const { return myResSprite.MarkerSize(); } |
65 | |
737e9a8d |
66 | //! Return TRUE if OpenGl point sprite resource defines texture. |
67 | bool HasPointSprite (const Handle(OpenGl_Context)& theCtx) const |
bf5f0ca2 |
68 | { |
737e9a8d |
69 | return myResSprite.HasPointSprite (theCtx, myAspect); |
bf5f0ca2 |
70 | } |
71 | |
737e9a8d |
72 | //! Return TRUE if OpenGl point sprite resource defined by obsolete Display List (bitmap). |
73 | bool IsDisplayListSprite (const Handle(OpenGl_Context)& theCtx) const |
74 | { |
75 | return myResSprite.IsDisplayListSprite (theCtx, myAspect); |
76 | } |
77 | |
78 | //! Init and return OpenGl point sprite resource. |
79 | //! @return point sprite texture. |
80 | const Handle(OpenGl_PointSprite)& SpriteRes (const Handle(OpenGl_Context)& theCtx, |
81 | bool theIsAlphaSprite) const |
bf5f0ca2 |
82 | { |
737e9a8d |
83 | return myResSprite.Sprite (theCtx, myAspect, theIsAlphaSprite); |
bf5f0ca2 |
84 | } |
85 | |
86 | Standard_EXPORT virtual void Render (const Handle(OpenGl_Workspace)& theWorkspace) const Standard_OVERRIDE; |
87 | Standard_EXPORT virtual void Release (OpenGl_Context* theContext) Standard_OVERRIDE; |
88 | |
89 | //! Update presentation aspects parameters after their modification. |
90 | virtual void SynchronizeAspects() Standard_OVERRIDE { SetAspect (myAspect); } |
91 | |
0904aa63 |
92 | //! Dumps the content of me into the stream |
93 | Standard_EXPORT void DumpJson (Standard_OStream& theOStream, const Standard_Integer theDepth = -1) const; |
94 | |
bf5f0ca2 |
95 | protected: |
96 | |
97 | //! OpenGl resources |
98 | mutable OpenGl_AspectsProgram myResProgram; |
99 | mutable OpenGl_AspectsTextureSet myResTextureSet; |
100 | mutable OpenGl_AspectsSprite myResSprite; |
101 | |
102 | Handle(Graphic3d_Aspects) myAspect; |
103 | Graphic3d_TypeOfShadingModel myShadingModel; |
104 | |
105 | public: |
106 | |
107 | DEFINE_STANDARD_ALLOC |
108 | |
109 | }; |
110 | |
111 | #endif // _OpenGl_Aspects_Header |