Adjusting test cases at current state of OCCT master
[occt.git] / src / OpenGl / OpenGl_View.cxx
CommitLineData
b311480e 1// Created on: 2011-09-20
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 <NCollection_Mat4.hxx>
5f8b738e 17
bf75be98 18#include <OpenGl_Context.hxx>
30f0ad28 19#include <OpenGl_GlCore11.hxx>
20#include <OpenGl_GraduatedTrihedron.hxx>
392ac980 21#include <OpenGl_GraphicDriver.hxx>
30f0ad28 22#include <OpenGl_ShaderManager.hxx>
bf75be98 23#include <OpenGl_Texture.hxx>
2166f0fa 24#include <OpenGl_Trihedron.hxx>
30f0ad28 25#include <OpenGl_View.hxx>
26#include <OpenGl_Workspace.hxx>
2166f0fa 27
bf75be98 28#include <Graphic3d_TextureEnv.hxx>
197ac94e 29#include <Graphic3d_Mat4d.hxx>
bf75be98 30
2166f0fa
SK
31
32/*----------------------------------------------------------------------*/
33
f8ae3605 34namespace
c34dba32 35{
f8ae3605 36 static const OPENGL_ZCLIP myDefaultZClip = { { Standard_True, 0.F }, { Standard_True, 1.F } };
f8ae3605 37 static const OPENGL_FOG myDefaultFog = { Standard_False, 0.F, 1.F, { { 0.F, 0.F, 0.F, 1.F } } };
f8ae3605 38}
2166f0fa
SK
39
40/*----------------------------------------------------------------------*/
41
392ac980 42OpenGl_View::OpenGl_View (const CALL_DEF_VIEWCONTEXT &AContext,
43 OpenGl_StateCounter* theCounter)
a6964ce6 44: mySurfaceDetail(Visual3d_TOD_ALL),
2166f0fa 45 myBackfacing(0),
2166f0fa
SK
46 //shield_indicator = TOn,
47 //shield_colour = { { 0.F, 0.F, 0.F, 1.F } },
48 //border_indicator = TOff,
49 //border_colour = { { 0.F, 0.F, 0.F, 1.F } },
50 //active_status = TOn,
51 myZClip(myDefaultZClip),
b5ac8292 52 myCamera(AContext.Camera),
2166f0fa 53 myFog(myDefaultFog),
536d98e2 54 myToShowTrihedron (false),
55 myToShowGradTrihedron (false),
2166f0fa 56 myVisualization(AContext.Visualization),
8625ef7e 57 myShadingModel ((Visual3d_TypeOfModel )AContext.Model),
2166f0fa 58 myAntiAliasing(Standard_False),
825aa485 59 myWorldViewProjState(),
392ac980 60 myStateCounter (theCounter),
0b0320e7 61 myLastLightSourceState (0, 0),
0b0320e7 62 myTextureParams (new OpenGl_AspectFace()),
63 myBgGradientArray (new OpenGl_BackgroundArray (Graphic3d_TOB_GRADIENT)),
91c60b57 64 myBgTextureArray (new OpenGl_BackgroundArray (Graphic3d_TOB_TEXTURE)),
65 // ray-tracing fields initialization
66 myRaytraceInitStatus (OpenGl_RT_NONE),
67 myIsRaytraceDataValid (Standard_False),
68 myIsRaytraceWarnTextures (Standard_False),
69 myToUpdateEnvironmentMap (Standard_False),
189f85a3 70 myLayerListState (0)
2166f0fa 71{
392ac980 72 myCurrLightSourceState = myStateCounter->Increment();
2166f0fa
SK
73}
74
75/*----------------------------------------------------------------------*/
76
0b0320e7 77OpenGl_View::~OpenGl_View()
2166f0fa 78{
bf75be98 79 ReleaseGlResources (NULL); // ensure ReleaseGlResources() was called within valid context
0b0320e7 80 OpenGl_Element::Destroy (NULL, myBgGradientArray);
81 OpenGl_Element::Destroy (NULL, myBgTextureArray);
82 OpenGl_Element::Destroy (NULL, myTextureParams);
bf75be98 83}
84
85void OpenGl_View::ReleaseGlResources (const Handle(OpenGl_Context)& theCtx)
86{
536d98e2 87 myTrihedron .Release (theCtx.operator->());
88 myGraduatedTrihedron.Release (theCtx.operator->());
30f0ad28 89
bf75be98 90 if (!myTextureEnv.IsNull())
91 {
92 theCtx->DelayedRelease (myTextureEnv);
93 myTextureEnv.Nullify();
94 }
0b0320e7 95
96 if (myTextureParams != NULL)
97 {
98 myTextureParams->Release (theCtx.operator->());
99 }
100 if (myBgGradientArray != NULL)
101 {
102 myBgGradientArray->Release (theCtx.operator->());
103 }
104 if (myBgTextureArray != NULL)
bf75be98 105 {
0b0320e7 106 myBgTextureArray->Release (theCtx.operator->());
bf75be98 107 }
91c60b57 108
109 releaseRaytraceResources (theCtx);
bf75be98 110}
2166f0fa 111
bf75be98 112void OpenGl_View::SetTextureEnv (const Handle(OpenGl_Context)& theCtx,
113 const Handle(Graphic3d_TextureEnv)& theTexture)
114{
115 if (!myTextureEnv.IsNull())
116 {
117 theCtx->DelayedRelease (myTextureEnv);
118 myTextureEnv.Nullify();
119 }
120
121 if (theTexture.IsNull())
122 {
123 return;
124 }
125
126 myTextureEnv = new OpenGl_Texture (theTexture->GetParams());
127 Handle(Image_PixMap) anImage = theTexture->GetImage();
e276548b 128 if (!anImage.IsNull())
da0e82aa 129 myTextureEnv->Init (theCtx, *anImage.operator->(), theTexture->Type());
e276548b 130
91c60b57 131 myToUpdateEnvironmentMap = Standard_True;
e276548b 132}
133
134void OpenGl_View::SetSurfaceDetail (const Visual3d_TypeOfSurfaceDetail theMode)
135{
136 mySurfaceDetail = theMode;
137
91c60b57 138 myToUpdateEnvironmentMap = Standard_True;
2166f0fa
SK
139}
140
12381341 141// =======================================================================
142// function : SetBackfacing
143// purpose :
144// =======================================================================
de75ed09 145void OpenGl_View::SetBackfacing (const Standard_Integer theMode)
2166f0fa 146{
de75ed09 147 myBackfacing = theMode;
2166f0fa
SK
148}
149
12381341 150// =======================================================================
151// function : SetLights
152// purpose :
153// =======================================================================
154void OpenGl_View::SetLights (const CALL_DEF_VIEWCONTEXT& theViewCtx)
2166f0fa
SK
155{
156 myLights.Clear();
12381341 157 for (Standard_Integer aLightIt = 0; aLightIt < theViewCtx.NbActiveLight; ++aLightIt)
2166f0fa 158 {
12381341 159 myLights.Append (theViewCtx.ActiveLight[aLightIt]);
2166f0fa 160 }
392ac980 161 myCurrLightSourceState = myStateCounter->Increment();
2166f0fa
SK
162}
163
164/*----------------------------------------------------------------------*/
165
2166f0fa
SK
166//call_togl_setvisualisation
167void OpenGl_View::SetVisualisation (const CALL_DEF_VIEWCONTEXT &AContext)
168{
169 myVisualization = AContext.Visualization;
8625ef7e 170 myShadingModel = (Visual3d_TypeOfModel )AContext.Model;
2166f0fa
SK
171}
172
173/*----------------------------------------------------------------------*/
174
175//call_togl_cliplimit
bf75be98 176void OpenGl_View::SetClipLimit (const Graphic3d_CView& theCView)
2166f0fa 177{
b5ac8292 178 myZClip.Back.Limit = theCView.Context.ZClipBackPlane;
179 myZClip.Front.Limit = theCView.Context.ZClipFrontPlane;
2166f0fa 180
bf75be98 181 myZClip.Back.IsOn = (theCView.Context.BackZClipping != 0);
182 myZClip.Front.IsOn = (theCView.Context.FrontZClipping != 0);
2166f0fa
SK
183}
184
185/*----------------------------------------------------------------------*/
186
bf75be98 187void OpenGl_View::SetFog (const Graphic3d_CView& theCView,
188 const Standard_Boolean theFlag)
2166f0fa 189{
bf75be98 190 if (!theFlag)
2166f0fa
SK
191 {
192 myFog.IsOn = Standard_False;
193 }
194 else
195 {
196 myFog.IsOn = Standard_True;
197
b5ac8292 198 myFog.Front = theCView.Context.DepthFrontPlane;
199 myFog.Back = theCView.Context.DepthBackPlane;
2166f0fa 200
bf75be98 201 myFog.Color.rgb[0] = theCView.DefWindow.Background.r;
202 myFog.Color.rgb[1] = theCView.DefWindow.Background.g;
203 myFog.Color.rgb[2] = theCView.DefWindow.Background.b;
204 myFog.Color.rgb[3] = 1.0f;
2166f0fa
SK
205 }
206}
207
208/*----------------------------------------------------------------------*/
209
536d98e2 210void OpenGl_View::TriedronDisplay (const Aspect_TypeOfTriedronPosition thePosition,
a174a3c5 211 const Quantity_NameOfColor theColor,
212 const Standard_Real theScale,
213 const Standard_Boolean theAsWireframe)
2166f0fa 214{
536d98e2 215 myToShowTrihedron = true;
216 myTrihedron.SetWireframe (theAsWireframe);
217 myTrihedron.SetPosition (thePosition);
218 myTrihedron.SetScale (theScale);
219 myTrihedron.SetLabelsColor (theColor);
2166f0fa
SK
220}
221
222/*----------------------------------------------------------------------*/
223
a174a3c5 224void OpenGl_View::TriedronErase (const Handle(OpenGl_Context)& theCtx)
2166f0fa 225{
536d98e2 226 myToShowTrihedron = false;
227 myTrihedron.Release (theCtx.operator->());
2166f0fa
SK
228}
229
230/*----------------------------------------------------------------------*/
231
536d98e2 232void OpenGl_View::GraduatedTrihedronDisplay (const Handle(OpenGl_Context)& theCtx,
a79f67f8 233 const Graphic3d_GraduatedTrihedron& theData)
2166f0fa 234{
536d98e2 235 myToShowGradTrihedron = true;
236 myGraduatedTrihedron.SetValues (theCtx, theData);
2166f0fa
SK
237}
238
239/*----------------------------------------------------------------------*/
240
a174a3c5 241void OpenGl_View::GraduatedTrihedronErase (const Handle(OpenGl_Context)& theCtx)
2166f0fa 242{
536d98e2 243 myToShowGradTrihedron = false;
244 myGraduatedTrihedron.Release (theCtx.operator->());
2166f0fa 245}