0025132: Visualization - treat any TopoDS_Solid as closed volume
[occt.git] / src / OpenGl / OpenGl_AspectText.cxx
CommitLineData
b311480e 1// Created on: 2011-07-13
2// Created by: Sergey ZERCHANINOV
a174a3c5 3// Copyright (c) 2011-2013 OPEN CASCADE SAS
b311480e 4//
973c2be1 5// This file is part of Open CASCADE Technology software library.
b311480e 6//
d5f74e42 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
973c2be1 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.
b311480e 12//
973c2be1 13// Alternatively, this file may be used under the terms of Open CASCADE
14// commercial license or contractual agreement.
b311480e 15
30f0ad28 16#include <Graphic3d_ShaderProgram.hxx>
17
2166f0fa 18#include <OpenGl_AspectText.hxx>
30f0ad28 19#include <OpenGl_Context.hxx>
bf75be98 20#include <OpenGl_Workspace.hxx>
30f0ad28 21#include <OpenGl_ShaderManager.hxx>
22#include <OpenGl_ShaderProgram.hxx>
2166f0fa 23
a174a3c5 24namespace
25{
26 static const TEL_COLOUR TheDefaultColor = {{ 1.0F, 1.0F, 1.0F, 1.0F }};
30f0ad28 27 static const TCollection_AsciiString THE_EMPTY_KEY;
a174a3c5 28};
2166f0fa 29
a174a3c5 30// =======================================================================
31// function : OpenGl_AspectText
32// purpose :
33// =======================================================================
34OpenGl_AspectText::OpenGl_AspectText()
35: myFont ("Courier") ,
36 myColor (TheDefaultColor),
37 mySubtitleColor (TheDefaultColor),
38 myAngle (0.0f),
39 myStyleType (Aspect_TOST_NORMAL),
40 myDisplayType (Aspect_TODT_NORMAL),
41 myFontAspect (Font_FA_Regular),
30f0ad28 42 myZoomable (false),
43 myShaderProgram()
2166f0fa 44{
a174a3c5 45 //
2166f0fa
SK
46}
47
a174a3c5 48// =======================================================================
49// function : ~OpenGl_AspectText
50// purpose :
51// =======================================================================
52OpenGl_AspectText::~OpenGl_AspectText()
2166f0fa 53{
a174a3c5 54 //
2166f0fa
SK
55}
56
a174a3c5 57// =======================================================================
fd4a6963 58// function : SetAspect
a174a3c5 59// purpose :
60// =======================================================================
fd4a6963 61void OpenGl_AspectText::SetAspect (const CALL_DEF_CONTEXTTEXT& theAspect)
2166f0fa 62{
fd4a6963 63 myFont = theAspect.Font;
30f0ad28 64
fd4a6963 65 myColor.rgb[0] = (float )theAspect.Color.r;
66 myColor.rgb[1] = (float )theAspect.Color.g;
67 myColor.rgb[2] = (float )theAspect.Color.b;
2166f0fa 68 myColor.rgb[3] = 1.0f;
fd4a6963 69 mySubtitleColor.rgb[0] = (float )theAspect.ColorSubTitle.r;
70 mySubtitleColor.rgb[1] = (float )theAspect.ColorSubTitle.g;
71 mySubtitleColor.rgb[2] = (float )theAspect.ColorSubTitle.b;
2166f0fa 72 mySubtitleColor.rgb[3] = 1.0f;
30f0ad28 73
fd4a6963 74 myAngle = (float )theAspect.TextAngle;
75 myStyleType = (Aspect_TypeOfStyleText )theAspect.Style;
76 myDisplayType = (Aspect_TypeOfDisplayText )theAspect.DisplayType;
77 myFontAspect = (Font_FontAspect )theAspect.TextFontAspect;
78 myZoomable = (theAspect.TextZoomable != 0);
30f0ad28 79
80 // update resource bindings
81 myShaderProgram = theAspect.ShaderProgram;
82
83 const TCollection_AsciiString& aShaderKey = myShaderProgram.IsNull() ? THE_EMPTY_KEY : myShaderProgram->GetId();
84
85 if (aShaderKey.IsEmpty() || myResources.ShaderProgramId != aShaderKey)
86 {
f85399e5 87 myResources.ResetShaderReadiness();
30f0ad28 88 }
2166f0fa
SK
89}
90
a174a3c5 91// =======================================================================
92// function : Render
93// purpose :
94// =======================================================================
5e27df78 95void OpenGl_AspectText::Render (const Handle(OpenGl_Workspace)& theWorkspace) const
2166f0fa 96{
5e27df78 97 theWorkspace->SetAspectText (this);
98}
99
a174a3c5 100// =======================================================================
101// function : Release
102// purpose :
103// =======================================================================
30f0ad28 104void OpenGl_AspectText::Release (const Handle(OpenGl_Context)& theContext)
5e27df78 105{
392ac980 106 if (!myResources.ShaderProgram.IsNull()
107 && !theContext.IsNull())
30f0ad28 108 {
392ac980 109 theContext->ShaderManager()->Unregister (myResources.ShaderProgramId,
110 myResources.ShaderProgram);
30f0ad28 111 }
112 myResources.ShaderProgramId.Clear();
f85399e5 113 myResources.ResetShaderReadiness();
30f0ad28 114}
115
116// =======================================================================
117// function : BuildShader
118// purpose :
119// =======================================================================
392ac980 120void OpenGl_AspectText::Resources::BuildShader (const Handle(OpenGl_Workspace)& theWS,
30f0ad28 121 const Handle(Graphic3d_ShaderProgram)& theShader)
122{
123 const Handle(OpenGl_Context)& aContext = theWS->GetGlContext();
30f0ad28 124 if (!aContext->IsGlGreaterEqual (2, 0))
392ac980 125 {
30f0ad28 126 return;
392ac980 127 }
30f0ad28 128
129 // release old shader program resources
130 if (!ShaderProgram.IsNull())
131 {
392ac980 132 aContext->ShaderManager()->Unregister (ShaderProgramId, ShaderProgram);
f85399e5 133 ShaderProgramId.Clear();
134 ShaderProgram.Nullify();
30f0ad28 135 }
392ac980 136 if (theShader.IsNull())
30f0ad28 137 {
392ac980 138 return;
30f0ad28 139 }
392ac980 140
141 aContext->ShaderManager()->Create (theShader, ShaderProgramId, ShaderProgram);
2166f0fa 142}