1 // Created on: 2011-07-13
2 // Created by: Sergey ZERCHANINOV
3 // Copyright (c) 2011-2012 OPEN CASCADE SAS
5 // The content of this file is subject to the Open CASCADE Technology Public
6 // License Version 6.5 (the "License"). You may not use the content of this file
7 // except in compliance with the License. Please obtain a copy of the License
8 // at http://www.opencascade.org and read it completely before using this file.
10 // The Initial Developer of the Original Code is Open CASCADE S.A.S., having its
11 // main offices at: 1, place des Freres Montgolfier, 78280 Guyancourt, France.
13 // The Original Code and all software distributed under the License is
14 // distributed on an "AS IS" basis, without warranty of any kind, and the
15 // Initial Developer hereby disclaims all such warranties, including without
16 // limitation, any warranties of merchantability, fitness for a particular
17 // purpose or non-infringement. Please see the License for the specific terms
18 // and conditions governing the rights and limitations under the License.
21 #include <OpenGl_AspectFace.hxx>
23 #include <InterfaceGraphic_Graphic3d.hxx>
24 #include <Aspect_PolygonOffsetMode.hxx>
26 /*----------------------------------------------------------------------*/
28 static const TEL_CONTEXT_FACE myDefaultAspectFace =
31 TOn, TEL_HS_SOLID, TOn, TelCullNone,
32 { 0.2F, 0.8F, 0.1F, 0.0F, /* amb, diff, spec, emsv */
33 1.0F, 10.0F, 0.0F, /* trans, shine, env_reflexion */
35 (OPENGL_AMBIENT_MASK | OPENGL_DIFFUSE_MASK | OPENGL_SPECULAR_MASK), /* color_mask */
36 {{ 1.0F, 1.0F, 1.0F, 1.0F }}, /* ambient color */
37 {{ 1.0F, 1.0F, 1.0F, 1.0F }}, /* diffuse color */
38 {{ 1.0F, 1.0F, 1.0F, 1.0F }}, /* specular color */
39 {{ 1.0F, 1.0F, 1.0F, 1.0F }}, /* emissive color */
40 {{ 1.0F, 1.0F, 1.0F, 1.0F }} /* material color */
42 { 0.2F, 0.8F, 0.1F, 0.0F, /* amb, diff, spec, emsv */
43 1.0F, 10.0F, 0.0F, /* trans, shine, env_reflexion */
45 (OPENGL_AMBIENT_MASK | OPENGL_DIFFUSE_MASK | OPENGL_SPECULAR_MASK), /* color_mask */
46 {{ 1.0F, 1.0F, 1.0F, 1.0F }}, /* ambient color */
47 {{ 1.0F, 1.0F, 1.0F, 1.0F }}, /* diffuse color */
48 {{ 1.0F, 1.0F, 1.0F, 1.0F }}, /* specular color */
49 {{ 1.0F, 1.0F, 1.0F, 1.0F }}, /* emissive color */
50 {{ 1.0F, 1.0F, 1.0F, 1.0F }} /* material color */
52 0, -1, { Aspect_POM_Fill, 1.0F, 0.0F }
55 /*----------------------------------------------------------------------*/
57 static void ConvertMaterial (const CALL_DEF_MATERIAL &material, OPENGL_SURF_PROP &surface)
59 /* Cas par cas pour l evaluation */
60 surface.amb = material.IsAmbient? material.Ambient : 0.F;
61 surface.diff = material.IsDiffuse? material.Diffuse : 0.F;
62 surface.spec = material.IsSpecular? material.Specular : 0.F;
63 surface.emsv = material.IsEmission? material.Emission : 0.F;
65 /* type de materiel */
66 surface.isphysic = material.IsPhysic? 1 : 0;
68 /* Couleur du materiel */
69 surface.color_mask = 0;
70 if ( material.IsAmbient )
71 surface.color_mask |= OPENGL_AMBIENT_MASK;
72 if ( material.IsDiffuse )
73 surface.color_mask |= OPENGL_DIFFUSE_MASK;
74 if ( material.IsSpecular )
75 surface.color_mask |= OPENGL_SPECULAR_MASK;
76 if ( material.IsEmission )
77 surface.color_mask |= OPENGL_EMISSIVE_MASK;
79 /* Couleur eclairage ambient */
80 surface.ambcol.rgb[0] = material.ColorAmb.r;
81 surface.ambcol.rgb[1] = material.ColorAmb.g;
82 surface.ambcol.rgb[2] = material.ColorAmb.b;
83 surface.ambcol.rgb[3] = 1.F;
85 /* Couleur eclairage diffus */
86 surface.difcol.rgb[0] = material.ColorDif.r;
87 surface.difcol.rgb[1] = material.ColorDif.g;
88 surface.difcol.rgb[2] = material.ColorDif.b;
89 surface.difcol.rgb[3] = 1.F;
91 /* Couleur eclairage speculaire */
92 surface.speccol.rgb[0] = material.ColorSpec.r;
93 surface.speccol.rgb[1] = material.ColorSpec.g;
94 surface.speccol.rgb[2] = material.ColorSpec.b;
95 surface.speccol.rgb[3] = 1.F;
97 /* Couleur d emission */
98 surface.emscol.rgb[0] = material.ColorEms.r;
99 surface.emscol.rgb[1] = material.ColorEms.g;
100 surface.emscol.rgb[2] = material.ColorEms.b;
101 surface.emscol.rgb[3] = 1.F;
103 surface.shine = ( float )128 * material.Shininess;
104 surface.env_reflexion = material.EnvReflexion;
106 /* Dans la couche C++ :
107 * prop->trans = 0. => opaque
108 * prop->trans = 1. => transparent
109 * in OpenGl it is opposite.
111 surface.trans = 1.0F - material.Transparency;
114 /*----------------------------------------------------------------------*/
116 OpenGl_AspectFace::OpenGl_AspectFace ()
117 : myContext(myDefaultAspectFace)
120 /*----------------------------------------------------------------------*/
122 void OpenGl_AspectFace::SetContext (const CALL_DEF_CONTEXTFILLAREA &AContext)
125 myContext.InteriorStyle = (Aspect_InteriorStyle) AContext.Style;
128 myContext.Edge = AContext.Edge ? TOn : TOff;
130 //TelInteriorStyleIndex
131 switch( AContext.Hatch )
133 case 0 : /* Aspect_HS_HORIZONTAL */
134 myContext.Hatch = TEL_HS_HORIZONTAL;
136 case 1 : /* Aspect_HS_HORIZONTAL_WIDE */
137 myContext.Hatch = TEL_HS_HORIZONTAL_SPARSE;
139 case 2 : /* Aspect_HS_VERTICAL */
140 myContext.Hatch = TEL_HS_VERTICAL;
142 case 3 : /* Aspect_HS_VERTICAL_WIDE */
143 myContext.Hatch = TEL_HS_VERTICAL_SPARSE;
145 case 4 : /* Aspect_HS_DIAGONAL_45 */
146 myContext.Hatch = TEL_HS_DIAG_45;
148 case 5 : /* Aspect_HS_DIAGONAL_45_WIDE */
149 myContext.Hatch = TEL_HS_DIAG_45_SPARSE;
151 case 6 : /* Aspect_HS_DIAGONAL_135 */
152 myContext.Hatch = TEL_HS_DIAG_135;
154 case 7 : /* Aspect_HS_DIAGONAL_135_WIDE */
155 myContext.Hatch = TEL_HS_DIAG_135_SPARSE;
157 case 8 : /* Aspect_HS_GRID */
158 myContext.Hatch = TEL_HS_GRID;
160 case 9 : /* Aspect_HS_GRID_WIDE */
161 myContext.Hatch = TEL_HS_GRID_SPARSE;
163 case 10 : /* Aspect_HS_GRID_DIAGONAL */
164 myContext.Hatch = TEL_HS_CROSS;
166 case 11 : /* Aspect_HS_GRID_DIAGONAL_WIDE */
167 myContext.Hatch = TEL_HS_CROSS_SPARSE;
174 //TelFaceDistinguishingMode
175 myContext.DistinguishingMode = AContext.Distinguish ? TOn : TOff;
178 myContext.CullingMode = AContext.BackFace ? TelCullBack : TelCullNone;
180 //TelSurfaceAreaProperties
181 ConvertMaterial(AContext.Front,myContext.IntFront);
183 //TelBackSurfaceAreaProperties
184 ConvertMaterial(AContext.Back,myContext.IntBack);
187 myContext.IntFront.matcol.rgb[0] = (float) AContext.IntColor.r;
188 myContext.IntFront.matcol.rgb[1] = (float) AContext.IntColor.g;
189 myContext.IntFront.matcol.rgb[2] = (float) AContext.IntColor.b;
190 myContext.IntFront.matcol.rgb[3] = 1.f;
192 //TelBackInteriorColour
193 myContext.IntBack.matcol.rgb[0] = (float) AContext.BackIntColor.r;
194 myContext.IntBack.matcol.rgb[1] = (float) AContext.BackIntColor.g;
195 myContext.IntBack.matcol.rgb[2] = (float) AContext.BackIntColor.b;
196 myContext.IntBack.matcol.rgb[3] = 1.f;
199 myContext.doTextureMap = AContext.Texture.doTextureMap;
202 myContext.TexId = AContext.Texture.TexId;
205 myContext.PolygonOffset.mode = (Aspect_PolygonOffsetMode) AContext.PolygonOffsetMode;
206 myContext.PolygonOffset.factor = AContext.PolygonOffsetFactor;
207 myContext.PolygonOffset.units = AContext.PolygonOffsetUnits;
209 CALL_DEF_CONTEXTLINE anEdgeContext;
212 anEdgeContext.Color.r = (float) AContext.EdgeColor.r;
213 anEdgeContext.Color.g = (float) AContext.EdgeColor.g;
214 anEdgeContext.Color.b = (float) AContext.EdgeColor.b;
217 anEdgeContext.LineType = (Aspect_TypeOfLine) AContext.LineType;
220 anEdgeContext.Width = (float) AContext.Width;
222 myAspectEdge.SetContext(anEdgeContext);
225 /*----------------------------------------------------------------------*/
227 void OpenGl_AspectFace::Render (const Handle(OpenGl_Workspace)& theWorkspace) const
229 theWorkspace->SetAspectFace (this);
232 void OpenGl_AspectFace::Release (const Handle(OpenGl_Context)& theContext)