0029570: Visualization, Graphic3d_Aspect - merge Graphic3d_Group aspects
[occt.git] / src / OpenGl / OpenGl_AspectsSprite.hxx
CommitLineData
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_AspectsSprite_Header
15#define _OpenGl_AspectsSprite_Header
16
17#include <Graphic3d_Aspects.hxx>
18#include <Graphic3d_TextureMap.hxx>
19
20class OpenGl_Context;
21class OpenGl_TextureSet;
22
23//! OpenGl resources for custom point sprites.
24class OpenGl_AspectsSprite
25{
26public:
27 DEFINE_STANDARD_ALLOC
28public:
29 //! Empty constructor.
30 OpenGl_AspectsSprite() : myMarkerSize (1.0f), myIsSpriteReady (Standard_False) {}
31
32 Standard_ShortReal MarkerSize() const { return myMarkerSize; }
33
34 //! Return RGB sprite.
35 const Handle(OpenGl_TextureSet)& Sprite (const Handle(OpenGl_Context)& theCtx,
36 const Handle(Graphic3d_Aspects)& theAspecta)
37 {
38 if (!myIsSpriteReady)
39 {
40 build (theCtx, theAspecta->MarkerImage(), theAspecta->MarkerType(), theAspecta->MarkerScale(), theAspecta->ColorRGBA(), myMarkerSize);
41 myIsSpriteReady = true;
42 }
43 return mySprite;
44 }
45
46 //! Return Alpha sprite.
47 const Handle(OpenGl_TextureSet)& SpriteA (const Handle(OpenGl_Context)& theCtx,
48 const Handle(Graphic3d_Aspects)& theAspecta)
49 {
50 if (!myIsSpriteReady)
51 {
52 build (theCtx, theAspecta->MarkerImage(), theAspecta->MarkerType(), theAspecta->MarkerScale(), theAspecta->ColorRGBA(), myMarkerSize);
53 myIsSpriteReady = true;
54 }
55 return mySpriteA;
56 }
57
58 //! Update texture resource up-to-date state.
59 Standard_EXPORT void UpdateRediness (const Handle(Graphic3d_Aspects)& theAspect);
60
61 //! Release texture resource.
62 Standard_EXPORT void Release (OpenGl_Context* theCtx);
63
64private:
65
66 //! Build texture resources.
67 Standard_EXPORT void build (const Handle(OpenGl_Context)& theCtx,
68 const Handle(Graphic3d_MarkerImage)& theMarkerImage,
69 Aspect_TypeOfMarker theType,
70 Standard_ShortReal theScale,
71 const Graphic3d_Vec4& theColor,
72 Standard_ShortReal& theMarkerSize);
73
74 //! Generate resource keys for a sprite.
75 static void spriteKeys (const Handle(Graphic3d_MarkerImage)& theMarkerImage,
76 Aspect_TypeOfMarker theType,
77 Standard_ShortReal theScale,
78 const Graphic3d_Vec4& theColor,
79 TCollection_AsciiString& theKey,
80 TCollection_AsciiString& theKeyA);
81
82private:
83
84 Handle(OpenGl_TextureSet) mySprite;
85 Handle(OpenGl_TextureSet) mySpriteA;
86 Standard_ShortReal myMarkerSize;
87 Standard_Boolean myIsSpriteReady;
88
89};
90
91#endif // _OpenGl_Aspects_Header