Commit | Line | Data |
---|---|---|
b311480e | 1 | // Created on: 2011-07-13 |
2 | // Created by: Sergey ZERCHANINOV | |
a174a3c5 | 3 | // Copyright (c) 2011-2013 OPEN CASCADE SAS |
b311480e | 4 | // |
5 | // The content of this file is subject to the Open CASCADE Technology Public | |
6 | // License Version 6.5 (the "License"). You may not use the content of this file | |
7 | // except in compliance with the License. Please obtain a copy of the License | |
8 | // at http://www.opencascade.org and read it completely before using this file. | |
9 | // | |
10 | // The Initial Developer of the Original Code is Open CASCADE S.A.S., having its | |
11 | // main offices at: 1, place des Freres Montgolfier, 78280 Guyancourt, France. | |
12 | // | |
13 | // The Original Code and all software distributed under the License is | |
14 | // distributed on an "AS IS" basis, without warranty of any kind, and the | |
15 | // Initial Developer hereby disclaims all such warranties, including without | |
16 | // limitation, any warranties of merchantability, fitness for a particular | |
17 | // purpose or non-infringement. Please see the License for the specific terms | |
18 | // and conditions governing the rights and limitations under the License. | |
19 | ||
30f0ad28 | 20 | #include <Graphic3d_ShaderProgram.hxx> |
21 | ||
2166f0fa | 22 | #include <OpenGl_AspectText.hxx> |
30f0ad28 | 23 | #include <OpenGl_Context.hxx> |
bf75be98 | 24 | #include <OpenGl_Workspace.hxx> |
30f0ad28 | 25 | #include <OpenGl_ShaderManager.hxx> |
26 | #include <OpenGl_ShaderProgram.hxx> | |
2166f0fa | 27 | |
a174a3c5 | 28 | namespace |
29 | { | |
30 | static const TEL_COLOUR TheDefaultColor = {{ 1.0F, 1.0F, 1.0F, 1.0F }}; | |
30f0ad28 | 31 | static const TCollection_AsciiString THE_EMPTY_KEY; |
a174a3c5 | 32 | }; |
2166f0fa | 33 | |
a174a3c5 | 34 | // ======================================================================= |
35 | // function : OpenGl_AspectText | |
36 | // purpose : | |
37 | // ======================================================================= | |
38 | OpenGl_AspectText::OpenGl_AspectText() | |
39 | : myFont ("Courier") , | |
40 | myColor (TheDefaultColor), | |
41 | mySubtitleColor (TheDefaultColor), | |
42 | myAngle (0.0f), | |
43 | myStyleType (Aspect_TOST_NORMAL), | |
44 | myDisplayType (Aspect_TODT_NORMAL), | |
45 | myFontAspect (Font_FA_Regular), | |
30f0ad28 | 46 | myZoomable (false), |
47 | myShaderProgram() | |
2166f0fa | 48 | { |
a174a3c5 | 49 | // |
2166f0fa SK |
50 | } |
51 | ||
a174a3c5 | 52 | // ======================================================================= |
53 | // function : ~OpenGl_AspectText | |
54 | // purpose : | |
55 | // ======================================================================= | |
56 | OpenGl_AspectText::~OpenGl_AspectText() | |
2166f0fa | 57 | { |
a174a3c5 | 58 | // |
2166f0fa SK |
59 | } |
60 | ||
a174a3c5 | 61 | // ======================================================================= |
fd4a6963 | 62 | // function : SetAspect |
a174a3c5 | 63 | // purpose : |
64 | // ======================================================================= | |
fd4a6963 | 65 | void OpenGl_AspectText::SetAspect (const CALL_DEF_CONTEXTTEXT& theAspect) |
2166f0fa | 66 | { |
fd4a6963 | 67 | myFont = theAspect.Font; |
30f0ad28 | 68 | |
fd4a6963 | 69 | myColor.rgb[0] = (float )theAspect.Color.r; |
70 | myColor.rgb[1] = (float )theAspect.Color.g; | |
71 | myColor.rgb[2] = (float )theAspect.Color.b; | |
2166f0fa | 72 | myColor.rgb[3] = 1.0f; |
fd4a6963 | 73 | mySubtitleColor.rgb[0] = (float )theAspect.ColorSubTitle.r; |
74 | mySubtitleColor.rgb[1] = (float )theAspect.ColorSubTitle.g; | |
75 | mySubtitleColor.rgb[2] = (float )theAspect.ColorSubTitle.b; | |
2166f0fa | 76 | mySubtitleColor.rgb[3] = 1.0f; |
30f0ad28 | 77 | |
fd4a6963 | 78 | myAngle = (float )theAspect.TextAngle; |
79 | myStyleType = (Aspect_TypeOfStyleText )theAspect.Style; | |
80 | myDisplayType = (Aspect_TypeOfDisplayText )theAspect.DisplayType; | |
81 | myFontAspect = (Font_FontAspect )theAspect.TextFontAspect; | |
82 | myZoomable = (theAspect.TextZoomable != 0); | |
30f0ad28 | 83 | |
84 | // update resource bindings | |
85 | myShaderProgram = theAspect.ShaderProgram; | |
86 | ||
87 | const TCollection_AsciiString& aShaderKey = myShaderProgram.IsNull() ? THE_EMPTY_KEY : myShaderProgram->GetId(); | |
88 | ||
89 | if (aShaderKey.IsEmpty() || myResources.ShaderProgramId != aShaderKey) | |
90 | { | |
f85399e5 | 91 | myResources.ResetShaderReadiness(); |
30f0ad28 | 92 | } |
2166f0fa SK |
93 | } |
94 | ||
a174a3c5 | 95 | // ======================================================================= |
96 | // function : Render | |
97 | // purpose : | |
98 | // ======================================================================= | |
5e27df78 | 99 | void OpenGl_AspectText::Render (const Handle(OpenGl_Workspace)& theWorkspace) const |
2166f0fa | 100 | { |
5e27df78 | 101 | theWorkspace->SetAspectText (this); |
102 | } | |
103 | ||
a174a3c5 | 104 | // ======================================================================= |
105 | // function : Release | |
106 | // purpose : | |
107 | // ======================================================================= | |
30f0ad28 | 108 | void OpenGl_AspectText::Release (const Handle(OpenGl_Context)& theContext) |
5e27df78 | 109 | { |
392ac980 | 110 | if (!myResources.ShaderProgram.IsNull() |
111 | && !theContext.IsNull()) | |
30f0ad28 | 112 | { |
392ac980 | 113 | theContext->ShaderManager()->Unregister (myResources.ShaderProgramId, |
114 | myResources.ShaderProgram); | |
30f0ad28 | 115 | } |
116 | myResources.ShaderProgramId.Clear(); | |
f85399e5 | 117 | myResources.ResetShaderReadiness(); |
30f0ad28 | 118 | } |
119 | ||
120 | // ======================================================================= | |
121 | // function : BuildShader | |
122 | // purpose : | |
123 | // ======================================================================= | |
392ac980 | 124 | void OpenGl_AspectText::Resources::BuildShader (const Handle(OpenGl_Workspace)& theWS, |
30f0ad28 | 125 | const Handle(Graphic3d_ShaderProgram)& theShader) |
126 | { | |
127 | const Handle(OpenGl_Context)& aContext = theWS->GetGlContext(); | |
30f0ad28 | 128 | if (!aContext->IsGlGreaterEqual (2, 0)) |
392ac980 | 129 | { |
30f0ad28 | 130 | return; |
392ac980 | 131 | } |
30f0ad28 | 132 | |
133 | // release old shader program resources | |
134 | if (!ShaderProgram.IsNull()) | |
135 | { | |
392ac980 | 136 | aContext->ShaderManager()->Unregister (ShaderProgramId, ShaderProgram); |
f85399e5 | 137 | ShaderProgramId.Clear(); |
138 | ShaderProgram.Nullify(); | |
30f0ad28 | 139 | } |
392ac980 | 140 | if (theShader.IsNull()) |
30f0ad28 | 141 | { |
392ac980 | 142 | return; |
30f0ad28 | 143 | } |
392ac980 | 144 | |
145 | aContext->ShaderManager()->Create (theShader, ShaderProgramId, ShaderProgram); | |
2166f0fa | 146 | } |