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.SetAmbientColor (Quantity_Color (Graphic3d_Vec3 (0.2f)));
29 aMat.SetDiffuseColor (Quantity_Color (Graphic3d_Vec3 (0.8f)));
30 aMat.SetEmissiveColor(Quantity_Color (Graphic3d_Vec3 (0.1f)));
31 aMat.SetSpecularColor(Quantity_NOC_BLACK);
32 aMat.SetShininess (10.0f / 128.0f);
33 aMat.SetRefractionIndex (1.0f);
37 static const Graphic3d_MaterialAspect THE_DEFAULT_MATERIAL = initDefaultMaterial();
40 // =======================================================================
41 // function : OpenGl_Aspects
43 // =======================================================================
44 OpenGl_Aspects::OpenGl_Aspects()
45 : myAspect (new Graphic3d_Aspects()),
46 myShadingModel (Graphic3d_TOSM_UNLIT)
48 myAspect->SetInteriorStyle (Aspect_IS_SOLID);
49 myAspect->SetInteriorColor (Quantity_NOC_WHITE);
50 myAspect->SetEdgeColor (Quantity_NOC_WHITE);
51 myAspect->SetFrontMaterial (THE_DEFAULT_MATERIAL);
52 myAspect->SetBackMaterial (THE_DEFAULT_MATERIAL);
53 myAspect->SetShadingModel (myShadingModel);
54 myAspect->SetHatchStyle (Handle(Graphic3d_HatchStyle)());
57 // =======================================================================
58 // function : OpenGl_Aspects
60 // =======================================================================
61 OpenGl_Aspects::OpenGl_Aspects (const Handle(Graphic3d_Aspects)& theAspect)
62 : myShadingModel (Graphic3d_TOSM_DEFAULT)
64 SetAspect (theAspect);
67 // =======================================================================
68 // function : SetAspect
70 // =======================================================================
71 void OpenGl_Aspects::SetAspect (const Handle(Graphic3d_Aspects)& theAspect)
75 const Graphic3d_MaterialAspect& aMat = theAspect->FrontMaterial();
76 myShadingModel = theAspect->ShadingModel() != Graphic3d_TOSM_UNLIT
77 && (aMat.ReflectionMode (Graphic3d_TOR_AMBIENT)
78 || aMat.ReflectionMode (Graphic3d_TOR_DIFFUSE)
79 || aMat.ReflectionMode (Graphic3d_TOR_SPECULAR)
80 || aMat.ReflectionMode (Graphic3d_TOR_EMISSION))
81 ? theAspect->ShadingModel()
82 : Graphic3d_TOSM_UNLIT;
84 // invalidate resources
85 myResTextureSet.UpdateRediness (myAspect);
86 myResSprite.UpdateRediness (myAspect);
87 myResProgram.UpdateRediness (myAspect);
88 if (!myResSprite.IsReady())
90 myResTextureSet.Invalidate();
94 // =======================================================================
97 // =======================================================================
98 void OpenGl_Aspects::Render (const Handle(OpenGl_Workspace)& theWorkspace) const
100 theWorkspace->SetAspects (this);
103 // =======================================================================
104 // function : Release
106 // =======================================================================
107 void OpenGl_Aspects::Release (OpenGl_Context* theContext)
109 myResTextureSet.Release (theContext);
110 myResSprite.Release (theContext);
111 myResProgram.Release (theContext);
114 // =======================================================================
115 // function : DumpJson
117 // =======================================================================
118 void OpenGl_Aspects::DumpJson (Standard_OStream& theOStream, const Standard_Integer theDepth) const
120 OCCT_DUMP_CLASS_BEGIN (theOStream, OpenGl_Aspects);
122 OCCT_DUMP_FIELD_VALUES_DUMPED (theOStream, theDepth, myAspect.get());
123 OCCT_DUMP_FIELD_VALUE_NUMERICAL (theOStream, myShadingModel);