0023415: OSD_FontMgr can't idenify aspect for fonts with names dependant on system...
[occt.git] / src / OpenGl / OpenGl_AspectFace.cxx
CommitLineData
b311480e 1// Created on: 2011-07-13
2// Created by: Sergey ZERCHANINOV
3// Copyright (c) 2011-2012 OPEN CASCADE SAS
4//
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.
9//
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.
12//
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.
19
2166f0fa
SK
20
21#include <OpenGl_AspectFace.hxx>
22
23#include <InterfaceGraphic_Graphic3d.hxx>
24#include <Aspect_PolygonOffsetMode.hxx>
25
26/*----------------------------------------------------------------------*/
27
28static const TEL_CONTEXT_FACE myDefaultAspectFace =
29{
30 Aspect_IS_SOLID,
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 */
34 0, /* isphysic */
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 */
41 },
42 { 0.2F, 0.8F, 0.1F, 0.0F, /* amb, diff, spec, emsv */
43 1.0F, 10.0F, 0.0F, /* trans, shine, env_reflexion */
44 0, /* isphysic */
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 */
51 },
52 0, -1, { Aspect_POM_Fill, 1.0F, 0.0F }
53};
54
55/*----------------------------------------------------------------------*/
56
57static void ConvertMaterial (const CALL_DEF_MATERIAL &material, OPENGL_SURF_PROP &surface)
58{
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;
64
65 /* type de materiel */
66 surface.isphysic = material.IsPhysic? 1 : 0;
67
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;
78
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;
84
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;
90
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;
96
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;
102
103 surface.shine = ( float )128 * material.Shininess;
104 surface.env_reflexion = material.EnvReflexion;
105
106 /* Dans la couche C++ :
107 * prop->trans = 0. => opaque
108 * prop->trans = 1. => transparent
109 * in OpenGl it is opposite.
110 */
111 surface.trans = 1.0F - material.Transparency;
112}
113
114/*----------------------------------------------------------------------*/
115
116OpenGl_AspectFace::OpenGl_AspectFace ()
117 : myContext(myDefaultAspectFace)
118{}
119
120/*----------------------------------------------------------------------*/
121
122void OpenGl_AspectFace::SetContext (const CALL_DEF_CONTEXTFILLAREA &AContext)
123{
124 //TelInteriorStyle
125 myContext.InteriorStyle = (Aspect_InteriorStyle) AContext.Style;
126
127 //TelEdgeFlag
128 myContext.Edge = AContext.Edge ? TOn : TOff;
129
130 //TelInteriorStyleIndex
131 switch( AContext.Hatch )
132 {
133 case 0 : /* Aspect_HS_HORIZONTAL */
134 myContext.Hatch = TEL_HS_HORIZONTAL;
135 break;
136 case 1 : /* Aspect_HS_HORIZONTAL_WIDE */
137 myContext.Hatch = TEL_HS_HORIZONTAL_SPARSE;
138 break;
139 case 2 : /* Aspect_HS_VERTICAL */
140 myContext.Hatch = TEL_HS_VERTICAL;
141 break;
142 case 3 : /* Aspect_HS_VERTICAL_WIDE */
143 myContext.Hatch = TEL_HS_VERTICAL_SPARSE;
144 break;
145 case 4 : /* Aspect_HS_DIAGONAL_45 */
146 myContext.Hatch = TEL_HS_DIAG_45;
147 break;
148 case 5 : /* Aspect_HS_DIAGONAL_45_WIDE */
149 myContext.Hatch = TEL_HS_DIAG_45_SPARSE;
150 break;
151 case 6 : /* Aspect_HS_DIAGONAL_135 */
152 myContext.Hatch = TEL_HS_DIAG_135;
153 break;
154 case 7 : /* Aspect_HS_DIAGONAL_135_WIDE */
155 myContext.Hatch = TEL_HS_DIAG_135_SPARSE;
156 break;
157 case 8 : /* Aspect_HS_GRID */
158 myContext.Hatch = TEL_HS_GRID;
159 break;
160 case 9 : /* Aspect_HS_GRID_WIDE */
161 myContext.Hatch = TEL_HS_GRID_SPARSE;
162 break;
163 case 10 : /* Aspect_HS_GRID_DIAGONAL */
164 myContext.Hatch = TEL_HS_CROSS;
165 break;
166 case 11 : /* Aspect_HS_GRID_DIAGONAL_WIDE */
167 myContext.Hatch = TEL_HS_CROSS_SPARSE;
168 break;
169 default :
170 myContext.Hatch = 0;
171 break;
172 }
173
174 //TelFaceDistinguishingMode
175 myContext.DistinguishingMode = AContext.Distinguish ? TOn : TOff;
176
177 //TelFaceCullingMode
178 myContext.CullingMode = AContext.BackFace ? TelCullBack : TelCullNone;
179
180 //TelSurfaceAreaProperties
181 ConvertMaterial(AContext.Front,myContext.IntFront);
182
183 //TelBackSurfaceAreaProperties
184 ConvertMaterial(AContext.Back,myContext.IntBack);
185
186 //TelInteriorColour
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;
191
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;
197
198 //TelDoTextureMap
199 myContext.doTextureMap = AContext.Texture.doTextureMap;
200
201 //TelTextureId
202 myContext.TexId = AContext.Texture.TexId;
203
204 //TelPolygonOffset
205 myContext.PolygonOffset.mode = (Aspect_PolygonOffsetMode) AContext.PolygonOffsetMode;
206 myContext.PolygonOffset.factor = AContext.PolygonOffsetFactor;
207 myContext.PolygonOffset.units = AContext.PolygonOffsetUnits;
208
209 CALL_DEF_CONTEXTLINE anEdgeContext;
210
211 //TelEdgeColour
212 anEdgeContext.Color.r = (float) AContext.EdgeColor.r;
213 anEdgeContext.Color.g = (float) AContext.EdgeColor.g;
214 anEdgeContext.Color.b = (float) AContext.EdgeColor.b;
215
216 //TelEdgeType
217 anEdgeContext.LineType = (Aspect_TypeOfLine) AContext.LineType;
218
219 //TelEdgeWidth
220 anEdgeContext.Width = (float) AContext.Width;
221
222 myAspectEdge.SetContext(anEdgeContext);
223}
224
225/*----------------------------------------------------------------------*/
226
5e27df78 227void OpenGl_AspectFace::Render (const Handle(OpenGl_Workspace)& theWorkspace) const
2166f0fa 228{
5e27df78 229 theWorkspace->SetAspectFace (this);
2166f0fa
SK
230}
231
5e27df78 232void OpenGl_AspectFace::Release (const Handle(OpenGl_Context)& theContext)
233{
234 //
235}