1 // Copyright (c) 2019 OPEN CASCADE SAS
3 // This file is part of Open CASCADE Technology software library.
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.
11 // Alternatively, this file may be used under the terms of Open CASCADE
12 // commercial license or contractual agreement.
14 #include <OpenGl_Aspects.hxx>
15 #include <OpenGl_Context.hxx>
16 #include <OpenGl_Workspace.hxx>
18 #include <Graphic3d_TypeOfReflection.hxx>
19 #include <Graphic3d_MaterialAspect.hxx>
23 //! Initialize default material in this way for backward compatibility.
24 inline Graphic3d_MaterialAspect initDefaultMaterial()
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);
41 static const Graphic3d_MaterialAspect THE_DEFAULT_MATERIAL = initDefaultMaterial();
44 // =======================================================================
45 // function : OpenGl_Aspects
47 // =======================================================================
48 OpenGl_Aspects::OpenGl_Aspects()
49 : myAspect (new Graphic3d_Aspects()),
50 myShadingModel (Graphic3d_TOSM_UNLIT)
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)());
61 // =======================================================================
62 // function : OpenGl_Aspects
64 // =======================================================================
65 OpenGl_Aspects::OpenGl_Aspects (const Handle(Graphic3d_Aspects)& theAspect)
66 : myShadingModel (Graphic3d_TOSM_DEFAULT)
68 SetAspect (theAspect);
71 // =======================================================================
72 // function : SetAspect
74 // =======================================================================
75 void OpenGl_Aspects::SetAspect (const Handle(Graphic3d_Aspects)& theAspect)
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;
88 // invalidate resources
89 myResTextureSet.UpdateRediness (myAspect);
90 myResSprite.UpdateRediness (myAspect);
91 myResProgram.UpdateRediness (myAspect);
92 if (!myResSprite.IsReady())
94 myResTextureSet.Invalidate();
98 // =======================================================================
101 // =======================================================================
102 void OpenGl_Aspects::Render (const Handle(OpenGl_Workspace)& theWorkspace) const
104 theWorkspace->SetAspects (this);
107 // =======================================================================
108 // function : Release
110 // =======================================================================
111 void OpenGl_Aspects::Release (OpenGl_Context* theContext)
113 myResTextureSet.Release (theContext);
114 myResSprite.Release (theContext);
115 myResProgram.Release (theContext);