0030748: Visualization - Marker displayed in immediate layer ruins QT Quick view...
[occt.git] / src / OpenGl / OpenGl_Aspects.cxx
CommitLineData
bf5f0ca2 1// Copyright (c) 2019 OPEN CASCADE SAS
2//
3// This file is part of Open CASCADE Technology software library.
4//
5// This library is free software; you can redistribute it and/or modify it under
6// the terms of the GNU Lesser General Public License version 2.1 as published
7// by the Free Software Foundation, with special exception defined in the file
8// OCCT_LGPL_EXCEPTION.txt. Consult the file LICENSE_LGPL_21.txt included in OCCT
9// distribution for complete text of the license and disclaimer of any warranty.
10//
11// Alternatively, this file may be used under the terms of Open CASCADE
12// commercial license or contractual agreement.
13
14#include <OpenGl_Aspects.hxx>
15#include <OpenGl_Context.hxx>
16#include <OpenGl_Workspace.hxx>
17
18#include <Graphic3d_TypeOfReflection.hxx>
19#include <Graphic3d_MaterialAspect.hxx>
20
21namespace
22{
23 //! Initialize default material in this way for backward compatibility.
24 inline Graphic3d_MaterialAspect initDefaultMaterial()
25 {
26 Graphic3d_MaterialAspect aMat;
27 aMat.SetMaterialType (Graphic3d_MATERIAL_ASPECT);
28 aMat.SetAmbient (0.2f);
29 aMat.SetDiffuse (0.8f);
30 aMat.SetSpecular (0.1f);
31 aMat.SetEmissive (0.0f);
32 aMat.SetAmbientColor (Quantity_NOC_WHITE);
33 aMat.SetDiffuseColor (Quantity_NOC_WHITE);
34 aMat.SetEmissiveColor(Quantity_NOC_WHITE);
35 aMat.SetSpecularColor(Quantity_NOC_WHITE);
36 aMat.SetShininess (10.0f / 128.0f);
37 aMat.SetRefractionIndex (1.0f);
38 return aMat;
39 }
40
41 static const Graphic3d_MaterialAspect THE_DEFAULT_MATERIAL = initDefaultMaterial();
42}
43
44// =======================================================================
45// function : OpenGl_Aspects
46// purpose :
47// =======================================================================
48OpenGl_Aspects::OpenGl_Aspects()
49: myAspect (new Graphic3d_Aspects()),
50 myShadingModel (Graphic3d_TOSM_UNLIT)
51{
52 myAspect->SetInteriorStyle (Aspect_IS_SOLID);
53 myAspect->SetInteriorColor (Quantity_NOC_WHITE);
54 myAspect->SetEdgeColor (Quantity_NOC_WHITE);
55 myAspect->SetFrontMaterial (THE_DEFAULT_MATERIAL);
56 myAspect->SetBackMaterial (THE_DEFAULT_MATERIAL);
57 myAspect->SetShadingModel (myShadingModel);
58 myAspect->SetHatchStyle (Handle(Graphic3d_HatchStyle)());
59}
60
61// =======================================================================
62// function : OpenGl_Aspects
63// purpose :
64// =======================================================================
65OpenGl_Aspects::OpenGl_Aspects (const Handle(Graphic3d_Aspects)& theAspect)
66: myShadingModel (Graphic3d_TOSM_DEFAULT)
67{
68 SetAspect (theAspect);
69}
70
71// =======================================================================
72// function : SetAspect
73// purpose :
74// =======================================================================
75void OpenGl_Aspects::SetAspect (const Handle(Graphic3d_Aspects)& theAspect)
76{
77 myAspect = theAspect;
78
79 const Graphic3d_MaterialAspect& aMat = theAspect->FrontMaterial();
80 myShadingModel = theAspect->ShadingModel() != Graphic3d_TOSM_UNLIT
81 && (aMat.ReflectionMode (Graphic3d_TOR_AMBIENT)
82 || aMat.ReflectionMode (Graphic3d_TOR_DIFFUSE)
83 || aMat.ReflectionMode (Graphic3d_TOR_SPECULAR)
84 || aMat.ReflectionMode (Graphic3d_TOR_EMISSION))
85 ? theAspect->ShadingModel()
86 : Graphic3d_TOSM_UNLIT;
87
88 // invalidate resources
737e9a8d 89 myResTextureSet.UpdateRediness (myAspect);
bf5f0ca2 90 myResSprite.UpdateRediness (myAspect);
91 myResProgram.UpdateRediness (myAspect);
737e9a8d 92 if (!myResSprite.IsReady())
93 {
94 myResTextureSet.Invalidate();
95 }
bf5f0ca2 96}
97
98// =======================================================================
99// function : Render
100// purpose :
101// =======================================================================
102void OpenGl_Aspects::Render (const Handle(OpenGl_Workspace)& theWorkspace) const
103{
104 theWorkspace->SetAspects (this);
105}
106
107// =======================================================================
108// function : Release
109// purpose :
110// =======================================================================
111void OpenGl_Aspects::Release (OpenGl_Context* theContext)
112{
113 myResTextureSet.Release (theContext);
114 myResSprite.Release (theContext);
115 myResProgram.Release (theContext);
116}