0025442: Visualization, TKOpenGl - prevent inclusion of system header glxext.h
[occt.git] / src / OpenGl / OpenGl_AspectLine.cxx
CommitLineData
b311480e 1// Created on: 2011-07-13
2// Created by: Sergey ZERCHANINOV
973c2be1 3// Copyright (c) 2011-2014 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_AspectLine.hxx>
30f0ad28 19#include <OpenGl_Context.hxx>
20#include <OpenGl_ShaderManager.hxx>
21#include <OpenGl_ShaderProgram.hxx>
bf75be98 22#include <OpenGl_Workspace.hxx>
2166f0fa 23
30f0ad28 24namespace
25{
26 static const TEL_COLOUR myDefaultColor = {{ 1.0F, 1.0F, 1.0F, 1.0F }};
27 static const TCollection_AsciiString THE_EMPTY_KEY;
28};
2166f0fa 29
30f0ad28 30// =======================================================================
31// function : OpenGl_AspectLine
32// purpose :
33// =======================================================================
2166f0fa
SK
34OpenGl_AspectLine::OpenGl_AspectLine ()
35 : myColor(myDefaultColor),
36 myType(Aspect_TOL_SOLID),
37 myWidth(1.0F)
38{}
39
30f0ad28 40// =======================================================================
41// function : OpenGl_AspectLine
42// purpose :
43// =======================================================================
2166f0fa
SK
44OpenGl_AspectLine::OpenGl_AspectLine (const OpenGl_AspectLine &AnOther)
45 : myColor(AnOther.myColor),
46 myType(AnOther.myType),
47 myWidth(AnOther.myWidth)
48{}
49
30f0ad28 50// =======================================================================
51// function : SetAspect
52// purpose :
53// =======================================================================
fd4a6963 54void OpenGl_AspectLine::SetAspect (const CALL_DEF_CONTEXTLINE &theAspect)
2166f0fa 55{
fd4a6963 56 myColor.rgb[0] = (float) theAspect.Color.r;
57 myColor.rgb[1] = (float) theAspect.Color.g;
58 myColor.rgb[2] = (float) theAspect.Color.b;
2166f0fa 59 myColor.rgb[3] = 1.0f;
fd4a6963 60 myType = (Aspect_TypeOfLine) theAspect.LineType;
61 myWidth = (float) theAspect.Width;
2166f0fa 62
30f0ad28 63 // update resource bindings
64 myShaderProgram = theAspect.ShaderProgram;
65
66 const TCollection_AsciiString& aShaderKey = myShaderProgram.IsNull() ? THE_EMPTY_KEY : myShaderProgram->GetId();
30f0ad28 67 if (aShaderKey.IsEmpty() || myResources.ShaderProgramId != aShaderKey)
68 {
f85399e5 69 myResources.ResetShaderReadiness();
30f0ad28 70 }
71}
2166f0fa 72
30f0ad28 73// =======================================================================
74// function : Render
75// purpose :
76// =======================================================================
5e27df78 77void OpenGl_AspectLine::Render (const Handle(OpenGl_Workspace) &theWorkspace) const
2166f0fa 78{
5e27df78 79 theWorkspace->SetAspectLine (this);
2166f0fa
SK
80}
81
30f0ad28 82// =======================================================================
83// function : Release
84// purpose :
85// =======================================================================
10b9c7df 86void OpenGl_AspectLine::Release (OpenGl_Context* theContext)
30f0ad28 87{
392ac980 88 if (!myResources.ShaderProgram.IsNull()
10b9c7df 89 && theContext)
30f0ad28 90 {
392ac980 91 theContext->ShaderManager()->Unregister (myResources.ShaderProgramId,
92 myResources.ShaderProgram);
30f0ad28 93 }
94 myResources.ShaderProgramId.Clear();
f85399e5 95 myResources.ResetShaderReadiness();
30f0ad28 96}
97
98// =======================================================================
99// function : BuildShader
100// purpose :
101// =======================================================================
8625ef7e 102void OpenGl_AspectLine::Resources::BuildShader (const Handle(OpenGl_Context)& theCtx,
30f0ad28 103 const Handle(Graphic3d_ShaderProgram)& theShader)
5e27df78 104{
8625ef7e 105 if (!theCtx->IsGlGreaterEqual (2, 0))
392ac980 106 {
30f0ad28 107 return;
392ac980 108 }
30f0ad28 109
110 // release old shader program resources
111 if (!ShaderProgram.IsNull())
112 {
8625ef7e 113 theCtx->ShaderManager()->Unregister (ShaderProgramId, ShaderProgram);
f85399e5 114 ShaderProgramId.Clear();
115 ShaderProgram.Nullify();
30f0ad28 116 }
392ac980 117 if (theShader.IsNull())
30f0ad28 118 {
392ac980 119 return;
30f0ad28 120 }
392ac980 121
8625ef7e 122 theCtx->ShaderManager()->Create (theShader, ShaderProgramId, ShaderProgram);
5e27df78 123}