0027961: Visualization - remove unused and no more working OpenGl_AVIWriter
[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{
30f0ad28 26 static const TCollection_AsciiString THE_EMPTY_KEY;
a3f6f591 27}
2166f0fa 28
a174a3c5 29// =======================================================================
30// function : OpenGl_AspectText
31// purpose :
32// =======================================================================
33OpenGl_AspectText::OpenGl_AspectText()
b6472664 34: myAspect (new Graphic3d_AspectText3d (Quantity_Color (Quantity_NOC_WHITE), "Courier", 1.0, 0.0))
2166f0fa 35{
a174a3c5 36 //
2166f0fa
SK
37}
38
a174a3c5 39// =======================================================================
b6472664 40// function : OpenGl_AspectText
41// purpose :
42// =======================================================================
43OpenGl_AspectText::OpenGl_AspectText (const Handle(Graphic3d_AspectText3d)& theAspect)
44{
45 SetAspect (theAspect);
46}
47
48// =======================================================================
a174a3c5 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// =======================================================================
b6472664 61void OpenGl_AspectText::SetAspect (const Handle(Graphic3d_AspectText3d)& theAspect)
2166f0fa 62{
b6472664 63 myAspect = theAspect;
64 const TCollection_AsciiString& aShaderKey = myAspect->ShaderProgram().IsNull() ? THE_EMPTY_KEY : myAspect->ShaderProgram()->GetId();
30f0ad28 65 if (aShaderKey.IsEmpty() || myResources.ShaderProgramId != aShaderKey)
66 {
f85399e5 67 myResources.ResetShaderReadiness();
30f0ad28 68 }
2166f0fa
SK
69}
70
a174a3c5 71// =======================================================================
72// function : Render
73// purpose :
74// =======================================================================
5e27df78 75void OpenGl_AspectText::Render (const Handle(OpenGl_Workspace)& theWorkspace) const
2166f0fa 76{
5e27df78 77 theWorkspace->SetAspectText (this);
78}
79
a174a3c5 80// =======================================================================
81// function : Release
82// purpose :
83// =======================================================================
10b9c7df 84void OpenGl_AspectText::Release (OpenGl_Context* theContext)
5e27df78 85{
392ac980 86 if (!myResources.ShaderProgram.IsNull()
10b9c7df 87 && theContext)
30f0ad28 88 {
392ac980 89 theContext->ShaderManager()->Unregister (myResources.ShaderProgramId,
90 myResources.ShaderProgram);
30f0ad28 91 }
92 myResources.ShaderProgramId.Clear();
f85399e5 93 myResources.ResetShaderReadiness();
30f0ad28 94}
95
96// =======================================================================
97// function : BuildShader
98// purpose :
99// =======================================================================
8625ef7e 100void OpenGl_AspectText::Resources::BuildShader (const Handle(OpenGl_Context)& theCtx,
30f0ad28 101 const Handle(Graphic3d_ShaderProgram)& theShader)
102{
4e1523ef 103 if (theCtx->core20fwd == NULL)
392ac980 104 {
30f0ad28 105 return;
392ac980 106 }
30f0ad28 107
108 // release old shader program resources
109 if (!ShaderProgram.IsNull())
110 {
8625ef7e 111 theCtx->ShaderManager()->Unregister (ShaderProgramId, ShaderProgram);
f85399e5 112 ShaderProgramId.Clear();
113 ShaderProgram.Nullify();
30f0ad28 114 }
392ac980 115 if (theShader.IsNull())
30f0ad28 116 {
392ac980 117 return;
30f0ad28 118 }
392ac980 119
8625ef7e 120 theCtx->ShaderManager()->Create (theShader, ShaderProgramId, ShaderProgram);
2166f0fa 121}