0030729: Visualization - TKOpenGl reports OpenGL 4.5 loading functions error on Intel...
[occt.git] / src / OpenGl / OpenGl_AspectsTextureSet.hxx
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_AspectsTextureSet_Header
15 #define _OpenGl_AspectsTextureSet_Header
16
17 #include <Graphic3d_Aspects.hxx>
18 #include <Graphic3d_TextureMap.hxx>
19 #include <Graphic3d_TextureSet.hxx>
20
21 class OpenGl_Context;
22 class OpenGl_TextureSet;
23 class OpenGl_PointSprite;
24
25 //! OpenGl resources for custom textures.
26 class OpenGl_AspectsTextureSet
27 {
28 public:
29   DEFINE_STANDARD_ALLOC
30 public:
31   //! Empty constructor.
32   OpenGl_AspectsTextureSet() : myIsTextureReady (Standard_False) {}
33
34   //! Return TRUE if resource is up-to-date.
35   bool IsReady() const { return myIsTextureReady; }
36
37   //! Invalidate resource state.
38   void Invalidate() { myIsTextureReady = false; }
39
40   //! Return textures array.
41   const Handle(OpenGl_TextureSet)& TextureSet (const Handle(OpenGl_Context)& theCtx,
42                                                const Handle(Graphic3d_Aspects)& theAspect,
43                                                const Handle(OpenGl_PointSprite)& theSprite,
44                                                const Handle(OpenGl_PointSprite)& theSpriteA,
45                                                bool theToHighlight)
46   {
47     if (!myIsTextureReady)
48     {
49       build (theCtx, theAspect, theSprite, theSpriteA);
50       myIsTextureReady = true;
51     }
52     return theToHighlight && !myTextures[1].IsNull()
53          ? myTextures[1]
54          : myTextures[0];
55   }
56
57   //! Update texture resource up-to-date state.
58   Standard_EXPORT void UpdateRediness (const Handle(Graphic3d_Aspects)& theAspect);
59
60   //! Release texture resource.
61   Standard_EXPORT void Release (OpenGl_Context* theCtx);
62
63 private:
64
65   //! Build texture resource.
66   Standard_EXPORT void build (const Handle(OpenGl_Context)& theCtx,
67                               const Handle(Graphic3d_Aspects)& theAspect,
68                               const Handle(OpenGl_PointSprite)& theSprite,
69                               const Handle(OpenGl_PointSprite)& theSpriteA);
70
71 private:
72
73   Handle(OpenGl_TextureSet) myTextures[2];
74   Standard_Boolean          myIsTextureReady;
75
76 };
77
78 #endif // _OpenGl_AspectsTextureSet_Header