Commit | Line | Data |
---|---|---|
b311480e | 1 | // Created on: 2011-07-13 |
2 | // Created by: Sergey ZERCHANINOV | |
973c2be1 | 3 | // Copyright (c) 2011-2014 OPEN CASCADE SAS |
b311480e | 4 | // |
973c2be1 | 5 | // This file is part of Open CASCADE Technology software library. |
b311480e | 6 | // |
973c2be1 | 7 | // This library is free software; you can redistribute it and / or modify it |
8 | // under the terms of the GNU Lesser General Public version 2.1 as published | |
9 | // by the Free Software Foundation, with special exception defined in the file | |
10 | // OCCT_LGPL_EXCEPTION.txt. Consult the file LICENSE_LGPL_21.txt included in OCCT | |
11 | // distribution for complete text of the license and disclaimer of any warranty. | |
b311480e | 12 | // |
973c2be1 | 13 | // Alternatively, this file may be used under the terms of Open CASCADE |
14 | // commercial license or contractual agreement. | |
b311480e | 15 | |
30f0ad28 | 16 | #include <Aspect_PolygonOffsetMode.hxx> |
17 | #include <NCollection_Vec3.hxx> | |
18 | ||
2166f0fa | 19 | #include <OpenGl_AspectFace.hxx> |
30f0ad28 | 20 | #include <OpenGl_Context.hxx> |
21 | #include <OpenGl_ShaderManager.hxx> | |
22 | #include <OpenGl_ShaderProgram.hxx> | |
bf75be98 | 23 | #include <OpenGl_Texture.hxx> |
24 | #include <OpenGl_Workspace.hxx> | |
2166f0fa | 25 | |
bf75be98 | 26 | #include <Graphic3d_CGroup.hxx> |
30f0ad28 | 27 | #include <Graphic3d_ShaderProgram.hxx> |
bf75be98 | 28 | #include <Graphic3d_TextureMap.hxx> |
4269bd1b | 29 | #include <Graphic3d_TypeOfReflection.hxx> |
30 | #include <Graphic3d_MaterialAspect.hxx> | |
31 | ||
bf75be98 | 32 | namespace |
2166f0fa | 33 | { |
bf75be98 | 34 | static OPENGL_SURF_PROP THE_DEFAULT_MATERIAL = |
35 | { | |
36 | 0.2F, 0.8F, 0.1F, 0.0F, // amb, diff, spec, emsv | |
37 | 1.0F, 10.0F, 0.0F, // trans, shine, env_reflexion | |
38 | 0, // isphysic | |
39 | (OPENGL_AMBIENT_MASK | OPENGL_DIFFUSE_MASK | OPENGL_SPECULAR_MASK), // color_mask | |
40 | {{ 1.0F, 1.0F, 1.0F, 1.0F }}, // ambient color | |
41 | {{ 1.0F, 1.0F, 1.0F, 1.0F }}, // diffuse color | |
42 | {{ 1.0F, 1.0F, 1.0F, 1.0F }}, // specular color | |
43 | {{ 1.0F, 1.0F, 1.0F, 1.0F }}, // emissive color | |
44 | {{ 1.0F, 1.0F, 1.0F, 1.0F }} // material color | |
45 | }; | |
46 | ||
47 | static TEL_POFFSET_PARAM THE_DEFAULT_POFFSET = { Aspect_POM_Fill, 1.0F, 0.0F }; | |
fd4a6963 | 48 | static const TCollection_AsciiString THE_EMPTY_KEY; |
bf75be98 | 49 | }; |
2166f0fa | 50 | |
bf75be98 | 51 | // ======================================================================= |
52 | // function : convertMaterial | |
53 | // purpose : | |
54 | // ======================================================================= | |
55 | void OpenGl_AspectFace::convertMaterial (const CALL_DEF_MATERIAL& theMat, | |
56 | OPENGL_SURF_PROP& theSurf) | |
2166f0fa | 57 | { |
bf75be98 | 58 | theSurf.amb = theMat.IsAmbient ? theMat.Ambient : 0.0f; |
59 | theSurf.diff = theMat.IsDiffuse ? theMat.Diffuse : 0.0f; | |
60 | theSurf.spec = theMat.IsSpecular ? theMat.Specular : 0.0f; | |
61 | theSurf.emsv = theMat.IsEmission ? theMat.Emission : 0.0f; | |
2166f0fa | 62 | |
bf75be98 | 63 | theSurf.isphysic = theMat.IsPhysic ? 1 : 0; // type of material |
2166f0fa | 64 | |
bf75be98 | 65 | // color of material |
66 | theSurf.color_mask = 0; | |
67 | if (theMat.IsAmbient) | |
68 | { | |
69 | theSurf.color_mask |= OPENGL_AMBIENT_MASK; | |
70 | } | |
71 | if (theMat.IsDiffuse) | |
72 | { | |
73 | theSurf.color_mask |= OPENGL_DIFFUSE_MASK; | |
74 | } | |
75 | if (theMat.IsSpecular) | |
76 | { | |
77 | theSurf.color_mask |= OPENGL_SPECULAR_MASK; | |
78 | } | |
79 | if (theMat.IsEmission) | |
80 | { | |
81 | theSurf.color_mask |= OPENGL_EMISSIVE_MASK; | |
82 | } | |
2166f0fa | 83 | |
bf75be98 | 84 | // ambient color |
85 | theSurf.ambcol.rgb[0] = theMat.ColorAmb.r; | |
86 | theSurf.ambcol.rgb[1] = theMat.ColorAmb.g; | |
87 | theSurf.ambcol.rgb[2] = theMat.ColorAmb.b; | |
88 | theSurf.ambcol.rgb[3] = 1.0f; | |
89 | ||
90 | // diffuse color | |
91 | theSurf.difcol.rgb[0] = theMat.ColorDif.r; | |
92 | theSurf.difcol.rgb[1] = theMat.ColorDif.g; | |
93 | theSurf.difcol.rgb[2] = theMat.ColorDif.b; | |
94 | theSurf.difcol.rgb[3] = 1.0f; | |
95 | ||
96 | // specular color | |
97 | theSurf.speccol.rgb[0] = theMat.ColorSpec.r; | |
98 | theSurf.speccol.rgb[1] = theMat.ColorSpec.g; | |
99 | theSurf.speccol.rgb[2] = theMat.ColorSpec.b; | |
100 | theSurf.speccol.rgb[3] = 1.0f; | |
101 | ||
102 | // emission color | |
103 | theSurf.emscol.rgb[0] = theMat.ColorEms.r; | |
104 | theSurf.emscol.rgb[1] = theMat.ColorEms.g; | |
105 | theSurf.emscol.rgb[2] = theMat.ColorEms.b; | |
106 | theSurf.emscol.rgb[3] = 1.0f; | |
107 | ||
108 | theSurf.shine = 128.0f * float(theMat.Shininess); | |
109 | theSurf.env_reflexion = theMat.EnvReflexion; | |
110 | ||
111 | // trans = 0. => opaque | |
112 | // trans = 1. => transparent | |
113 | // in OpenGl it is opposite. | |
114 | theSurf.trans = 1.0f - theMat.Transparency; | |
115 | } | |
2166f0fa | 116 | |
bf75be98 | 117 | // ======================================================================= |
118 | // function : OpenGl_AspectFace | |
119 | // purpose : | |
120 | // ======================================================================= | |
121 | OpenGl_AspectFace::OpenGl_AspectFace() | |
fd4a6963 | 122 | : myInteriorStyle (Aspect_IS_SOLID), |
123 | myEdge (TOff), | |
124 | myHatch (TEL_HS_SOLID), | |
125 | myDistinguishingMode (TOff), | |
126 | myCullingMode (TelCullNone), | |
127 | myIntFront (THE_DEFAULT_MATERIAL), | |
128 | myIntBack (THE_DEFAULT_MATERIAL), | |
129 | myPolygonOffset (THE_DEFAULT_POFFSET), | |
30f0ad28 | 130 | myDoTextureMap (false) |
fd4a6963 | 131 | {} |
2166f0fa | 132 | |
bf75be98 | 133 | // ======================================================================= |
fd4a6963 | 134 | // function : SetAspect |
bf75be98 | 135 | // purpose : |
136 | // ======================================================================= | |
fd4a6963 | 137 | void OpenGl_AspectFace::SetAspect (const CALL_DEF_CONTEXTFILLAREA& theAspect) |
bf75be98 | 138 | { |
fd4a6963 | 139 | myInteriorStyle = (Aspect_InteriorStyle )theAspect.Style; |
140 | myEdge = theAspect.Edge ? TOn : TOff; | |
2166f0fa SK |
141 | |
142 | //TelInteriorStyleIndex | |
bf75be98 | 143 | switch (theAspect.Hatch) |
2166f0fa | 144 | { |
bf75be98 | 145 | case 0: /* Aspect_HS_HORIZONTAL */ |
fd4a6963 | 146 | myHatch = TEL_HS_HORIZONTAL; |
2166f0fa | 147 | break; |
bf75be98 | 148 | case 1: /* Aspect_HS_HORIZONTAL_WIDE */ |
fd4a6963 | 149 | myHatch = TEL_HS_HORIZONTAL_SPARSE; |
2166f0fa | 150 | break; |
bf75be98 | 151 | case 2: /* Aspect_HS_VERTICAL */ |
fd4a6963 | 152 | myHatch = TEL_HS_VERTICAL; |
2166f0fa | 153 | break; |
bf75be98 | 154 | case 3: /* Aspect_HS_VERTICAL_WIDE */ |
fd4a6963 | 155 | myHatch = TEL_HS_VERTICAL_SPARSE; |
2166f0fa | 156 | break; |
bf75be98 | 157 | case 4: /* Aspect_HS_DIAGONAL_45 */ |
fd4a6963 | 158 | myHatch = TEL_HS_DIAG_45; |
2166f0fa | 159 | break; |
bf75be98 | 160 | case 5: /* Aspect_HS_DIAGONAL_45_WIDE */ |
fd4a6963 | 161 | myHatch = TEL_HS_DIAG_45_SPARSE; |
2166f0fa | 162 | break; |
bf75be98 | 163 | case 6: /* Aspect_HS_DIAGONAL_135 */ |
fd4a6963 | 164 | myHatch = TEL_HS_DIAG_135; |
2166f0fa | 165 | break; |
bf75be98 | 166 | case 7: /* Aspect_HS_DIAGONAL_135_WIDE */ |
fd4a6963 | 167 | myHatch = TEL_HS_DIAG_135_SPARSE; |
2166f0fa | 168 | break; |
bf75be98 | 169 | case 8: /* Aspect_HS_GRID */ |
fd4a6963 | 170 | myHatch = TEL_HS_GRID; |
2166f0fa | 171 | break; |
bf75be98 | 172 | case 9: /* Aspect_HS_GRID_WIDE */ |
fd4a6963 | 173 | myHatch = TEL_HS_GRID_SPARSE; |
2166f0fa | 174 | break; |
bf75be98 | 175 | case 10: /* Aspect_HS_GRID_DIAGONAL */ |
fd4a6963 | 176 | myHatch = TEL_HS_CROSS; |
2166f0fa | 177 | break; |
bf75be98 | 178 | case 11: /* Aspect_HS_GRID_DIAGONAL_WIDE */ |
fd4a6963 | 179 | myHatch = TEL_HS_CROSS_SPARSE; |
2166f0fa | 180 | break; |
bf75be98 | 181 | default: |
fd4a6963 | 182 | myHatch = 0; |
2166f0fa SK |
183 | break; |
184 | } | |
185 | ||
fd4a6963 | 186 | myDistinguishingMode = theAspect.Distinguish ? TOn : TOff; |
187 | myCullingMode = theAspect.BackFace ? TelCullBack : TelCullNone; | |
2166f0fa | 188 | |
fd4a6963 | 189 | convertMaterial (theAspect.Front, myIntFront); |
190 | convertMaterial (theAspect.Back, myIntBack); | |
2166f0fa SK |
191 | |
192 | //TelInteriorColour | |
fd4a6963 | 193 | myIntFront.matcol.rgb[0] = (float )theAspect.IntColor.r; |
194 | myIntFront.matcol.rgb[1] = (float )theAspect.IntColor.g; | |
195 | myIntFront.matcol.rgb[2] = (float )theAspect.IntColor.b; | |
196 | myIntFront.matcol.rgb[3] = 1.0f; | |
2166f0fa SK |
197 | |
198 | //TelBackInteriorColour | |
fd4a6963 | 199 | myIntBack.matcol.rgb[0] = (float )theAspect.BackIntColor.r; |
200 | myIntBack.matcol.rgb[1] = (float )theAspect.BackIntColor.g; | |
201 | myIntBack.matcol.rgb[2] = (float )theAspect.BackIntColor.b; | |
202 | myIntBack.matcol.rgb[3] = 1.0f; | |
bf75be98 | 203 | |
2166f0fa | 204 | //TelPolygonOffset |
fd4a6963 | 205 | myPolygonOffset.mode = (Aspect_PolygonOffsetMode )theAspect.PolygonOffsetMode; |
206 | myPolygonOffset.factor = theAspect.PolygonOffsetFactor; | |
207 | myPolygonOffset.units = theAspect.PolygonOffsetUnits; | |
208 | ||
209 | CALL_DEF_CONTEXTLINE anEdgeAspect; | |
210 | anEdgeAspect.Color.r = (float )theAspect.EdgeColor.r; | |
211 | anEdgeAspect.Color.g = (float )theAspect.EdgeColor.g; | |
212 | anEdgeAspect.Color.b = (float )theAspect.EdgeColor.b; | |
213 | anEdgeAspect.LineType = (Aspect_TypeOfLine )theAspect.LineType; | |
214 | anEdgeAspect.Width = (float )theAspect.Width; | |
215 | myAspectEdge.SetAspect (anEdgeAspect); | |
30f0ad28 | 216 | |
217 | myDoTextureMap = (theAspect.Texture.doTextureMap != 0); | |
218 | ||
219 | // update texture binding | |
220 | myTexture = theAspect.Texture.TextureMap; | |
221 | ||
222 | const TCollection_AsciiString& aTextureKey = myTexture.IsNull() ? THE_EMPTY_KEY : myTexture->GetId(); | |
30f0ad28 | 223 | if (aTextureKey.IsEmpty() || myResources.TextureId != aTextureKey) |
224 | { | |
f85399e5 | 225 | myResources.ResetTextureReadiness(); |
30f0ad28 | 226 | } |
227 | ||
228 | // update shader program binding | |
229 | myShaderProgram = theAspect.ShaderProgram; | |
230 | ||
231 | const TCollection_AsciiString& aShaderKey = myShaderProgram.IsNull() ? THE_EMPTY_KEY : myShaderProgram->GetId(); | |
30f0ad28 | 232 | if (aShaderKey.IsEmpty() || myResources.ShaderProgramId != aShaderKey) |
233 | { | |
f85399e5 | 234 | myResources.ResetShaderReadiness(); |
30f0ad28 | 235 | } |
2166f0fa SK |
236 | } |
237 | ||
4269bd1b | 238 | // ======================================================================= |
fd4a6963 | 239 | // function : SetAspect |
4269bd1b | 240 | // purpose : |
241 | // ======================================================================= | |
fd4a6963 | 242 | void OpenGl_AspectFace::SetAspect (const Handle(Graphic3d_AspectFillArea3d)& theAspect) |
4269bd1b | 243 | { |
fd4a6963 | 244 | CALL_DEF_CONTEXTFILLAREA aFaceContext; |
4269bd1b | 245 | Standard_Real aWidth; |
246 | Quantity_Color aBackIntColor; | |
247 | Quantity_Color aEdgeColor; | |
248 | Aspect_TypeOfLine aLType; | |
249 | Quantity_Color aIntColor; | |
250 | Aspect_InteriorStyle aIntStyle; | |
251 | NCollection_Vec3<Standard_Real> aColor; | |
252 | ||
253 | theAspect->Values (aIntStyle, aIntColor, aBackIntColor, aEdgeColor, aLType, aWidth); | |
254 | aIntColor.Values (aColor.r(), aColor.g(), aColor.b(), Quantity_TOC_RGB); | |
255 | ||
fd4a6963 | 256 | aFaceContext.Style = int (aIntStyle); |
257 | aFaceContext.IntColor.r = float (aColor.r()); | |
258 | aFaceContext.IntColor.g = float (aColor.g()); | |
259 | aFaceContext.IntColor.b = float (aColor.b()); | |
4269bd1b | 260 | |
261 | if (theAspect->Distinguish()) | |
262 | { | |
263 | aBackIntColor.Values (aColor.r(), aColor.g(), aColor.b(), Quantity_TOC_RGB); | |
264 | } | |
265 | ||
fd4a6963 | 266 | aFaceContext.BackIntColor.r = float (aColor.r()); |
267 | aFaceContext.BackIntColor.g = float (aColor.g()); | |
268 | aFaceContext.BackIntColor.b = float (aColor.b()); | |
4269bd1b | 269 | |
fd4a6963 | 270 | aFaceContext.Edge = theAspect->Edge () ? 1:0; |
4269bd1b | 271 | aEdgeColor.Values (aColor.r(), aColor.g(), aColor.b(), Quantity_TOC_RGB); |
272 | ||
fd4a6963 | 273 | aFaceContext.EdgeColor.r = float (aColor.r()); |
274 | aFaceContext.EdgeColor.g = float (aColor.g()); | |
275 | aFaceContext.EdgeColor.b = float (aColor.b()); | |
276 | aFaceContext.LineType = int (aLType); | |
277 | aFaceContext.Width = float (aWidth); | |
278 | aFaceContext.Hatch = int (theAspect->HatchStyle ()); | |
4269bd1b | 279 | |
fd4a6963 | 280 | aFaceContext.Distinguish = theAspect->Distinguish () ? 1:0; |
281 | aFaceContext.BackFace = theAspect->BackFace () ? 1:0; | |
4269bd1b | 282 | |
fd4a6963 | 283 | aFaceContext.Back.Shininess = float ((theAspect->BackMaterial ()).Shininess ()); |
284 | aFaceContext.Back.Ambient = float ((theAspect->BackMaterial ()).Ambient ()); | |
285 | aFaceContext.Back.Diffuse = float ((theAspect->BackMaterial ()).Diffuse ()); | |
286 | aFaceContext.Back.Specular = float ((theAspect->BackMaterial ()).Specular ()); | |
287 | aFaceContext.Back.Transparency = float ((theAspect->BackMaterial ()).Transparency ()); | |
288 | aFaceContext.Back.Emission = float ((theAspect->BackMaterial ()).Emissive ()); | |
4269bd1b | 289 | |
290 | // Reflection mode | |
fd4a6963 | 291 | aFaceContext.Back.IsAmbient = ((theAspect->BackMaterial ()).ReflectionMode (Graphic3d_TOR_AMBIENT) ? 1 : 0 ); |
292 | aFaceContext.Back.IsDiffuse = ((theAspect->BackMaterial ()).ReflectionMode (Graphic3d_TOR_DIFFUSE) ? 1 : 0 ); | |
293 | aFaceContext.Back.IsSpecular = ((theAspect->BackMaterial ()).ReflectionMode (Graphic3d_TOR_SPECULAR) ? 1 : 0 ); | |
294 | aFaceContext.Back.IsEmission = ((theAspect->BackMaterial ()).ReflectionMode (Graphic3d_TOR_EMISSION) ? 1 : 0 ); | |
4269bd1b | 295 | |
296 | // Material type | |
297 | const Graphic3d_MaterialAspect aBackMat = theAspect->BackMaterial (); | |
298 | Standard_Boolean isBackPhys = aBackMat.MaterialType (Graphic3d_MATERIAL_PHYSIC); | |
fd4a6963 | 299 | aFaceContext.Back.IsPhysic = (isBackPhys ? 1 : 0 ); |
4269bd1b | 300 | |
301 | // Specular Color | |
fd4a6963 | 302 | aFaceContext.Back.ColorSpec.r = float (((theAspect->BackMaterial ()).SpecularColor ()).Red ()); |
303 | aFaceContext.Back.ColorSpec.g = float (((theAspect->BackMaterial ()).SpecularColor ()).Green ()); | |
304 | aFaceContext.Back.ColorSpec.b = float (((theAspect->BackMaterial ()).SpecularColor ()).Blue ()); | |
4269bd1b | 305 | |
306 | // Ambient color | |
fd4a6963 | 307 | aFaceContext.Back.ColorAmb.r = float (((theAspect->BackMaterial ()).AmbientColor ()).Red ()); |
308 | aFaceContext.Back.ColorAmb.g = float (((theAspect->BackMaterial ()).AmbientColor ()).Green ()); | |
309 | aFaceContext.Back.ColorAmb.b = float (((theAspect->BackMaterial ()).AmbientColor ()).Blue ()); | |
4269bd1b | 310 | |
311 | // Diffuse color | |
fd4a6963 | 312 | aFaceContext.Back.ColorDif.r = float (((theAspect->BackMaterial ()).DiffuseColor ()).Red ()); |
313 | aFaceContext.Back.ColorDif.g = float (((theAspect->BackMaterial ()).DiffuseColor ()).Green ()); | |
314 | aFaceContext.Back.ColorDif.b = float (((theAspect->BackMaterial ()).DiffuseColor ()).Blue ()); | |
4269bd1b | 315 | |
316 | // Emissive color | |
fd4a6963 | 317 | aFaceContext.Back.ColorEms.r = float (((theAspect->BackMaterial ()).EmissiveColor ()).Red ()); |
318 | aFaceContext.Back.ColorEms.g = float (((theAspect->BackMaterial ()).EmissiveColor ()).Green ()); | |
319 | aFaceContext.Back.ColorEms.b = float (((theAspect->BackMaterial ()).EmissiveColor ()).Blue ()); | |
4269bd1b | 320 | |
fd4a6963 | 321 | aFaceContext.Back.EnvReflexion = float ((theAspect->BackMaterial ()).EnvReflexion()); |
4269bd1b | 322 | |
fd4a6963 | 323 | aFaceContext.Front.Shininess = float ((theAspect->FrontMaterial ()).Shininess ()); |
324 | aFaceContext.Front.Ambient = float ((theAspect->FrontMaterial ()).Ambient ()); | |
325 | aFaceContext.Front.Diffuse = float ((theAspect->FrontMaterial ()).Diffuse ()); | |
326 | aFaceContext.Front.Specular = float ((theAspect->FrontMaterial ()).Specular ()); | |
327 | aFaceContext.Front.Transparency = float ((theAspect->FrontMaterial ()).Transparency ()); | |
328 | aFaceContext.Front.Emission = float ((theAspect->FrontMaterial ()).Emissive ()); | |
4269bd1b | 329 | |
330 | // Reflection mode | |
fd4a6963 | 331 | aFaceContext.Front.IsAmbient = ((theAspect->FrontMaterial ()).ReflectionMode (Graphic3d_TOR_AMBIENT) ? 1 : 0); |
332 | aFaceContext.Front.IsDiffuse = ((theAspect->FrontMaterial ()).ReflectionMode (Graphic3d_TOR_DIFFUSE) ? 1 : 0); | |
333 | aFaceContext.Front.IsSpecular = ((theAspect->FrontMaterial ()).ReflectionMode (Graphic3d_TOR_SPECULAR) ? 1 : 0); | |
334 | aFaceContext.Front.IsEmission = ((theAspect->FrontMaterial ()).ReflectionMode (Graphic3d_TOR_EMISSION) ? 1 : 0); | |
4269bd1b | 335 | |
fd4a6963 | 336 | // Material type |
4269bd1b | 337 | const Graphic3d_MaterialAspect aFrontMat = theAspect->FrontMaterial (); |
338 | Standard_Boolean isFrontPhys = aFrontMat.MaterialType (Graphic3d_MATERIAL_PHYSIC); | |
fd4a6963 | 339 | aFaceContext.Front.IsPhysic = (isFrontPhys ? 1 : 0 ); |
4269bd1b | 340 | |
341 | // Specular Color | |
fd4a6963 | 342 | aFaceContext.Front.ColorSpec.r = float (((theAspect->FrontMaterial ()).SpecularColor ()).Red ()); |
343 | aFaceContext.Front.ColorSpec.g = float (((theAspect->FrontMaterial ()).SpecularColor ()).Green ()); | |
344 | aFaceContext.Front.ColorSpec.b = float (((theAspect->FrontMaterial ()).SpecularColor ()).Blue ()); | |
4269bd1b | 345 | |
346 | // Ambient color | |
fd4a6963 | 347 | aFaceContext.Front.ColorAmb.r = float (((theAspect->FrontMaterial ()).AmbientColor ()).Red ()); |
348 | aFaceContext.Front.ColorAmb.g = float (((theAspect->FrontMaterial ()).AmbientColor ()).Green ()); | |
349 | aFaceContext.Front.ColorAmb.b = float (((theAspect->FrontMaterial ()).AmbientColor ()).Blue ()); | |
4269bd1b | 350 | |
351 | // Diffuse color | |
fd4a6963 | 352 | aFaceContext.Front.ColorDif.r = float (((theAspect->FrontMaterial ()).DiffuseColor ()).Red ()); |
353 | aFaceContext.Front.ColorDif.g = float (((theAspect->FrontMaterial ()).DiffuseColor ()).Green ()); | |
354 | aFaceContext.Front.ColorDif.b = float (((theAspect->FrontMaterial ()).DiffuseColor ()).Blue ()); | |
4269bd1b | 355 | |
356 | // Emissive color | |
fd4a6963 | 357 | aFaceContext.Front.ColorEms.r = float (((theAspect->FrontMaterial ()).EmissiveColor ()).Red ()); |
358 | aFaceContext.Front.ColorEms.g = float (((theAspect->FrontMaterial ()).EmissiveColor ()).Green ()); | |
359 | aFaceContext.Front.ColorEms.b = float (((theAspect->FrontMaterial ()).EmissiveColor ()).Blue ()); | |
4269bd1b | 360 | |
fd4a6963 | 361 | aFaceContext.Front.EnvReflexion = float ((theAspect->FrontMaterial ()).EnvReflexion()); |
362 | aFaceContext.IsDef = 1; | |
363 | aFaceContext.Texture.TextureMap = theAspect->TextureMap(); | |
364 | aFaceContext.Texture.doTextureMap = theAspect->TextureMapState() ? 1 : 0; | |
4269bd1b | 365 | |
366 | Standard_Integer aPolyMode; | |
367 | Standard_ShortReal aPolyFactor, aPolyUnits; | |
368 | theAspect->PolygonOffsets (aPolyMode, aPolyFactor, aPolyUnits); | |
fd4a6963 | 369 | aFaceContext.PolygonOffsetMode = aPolyMode; |
370 | aFaceContext.PolygonOffsetFactor = (Standard_ShortReal)aPolyFactor; | |
371 | aFaceContext.PolygonOffsetUnits = (Standard_ShortReal)aPolyUnits; | |
4269bd1b | 372 | |
30f0ad28 | 373 | aFaceContext.ShaderProgram = theAspect->ShaderProgram(); |
374 | ||
fd4a6963 | 375 | SetAspect (aFaceContext); |
4269bd1b | 376 | } |
377 | ||
bf75be98 | 378 | // ======================================================================= |
379 | // function : Render | |
380 | // purpose : | |
381 | // ======================================================================= | |
5e27df78 | 382 | void OpenGl_AspectFace::Render (const Handle(OpenGl_Workspace)& theWorkspace) const |
2166f0fa | 383 | { |
5e27df78 | 384 | theWorkspace->SetAspectFace (this); |
2166f0fa SK |
385 | } |
386 | ||
bf75be98 | 387 | // ======================================================================= |
388 | // function : Release | |
389 | // purpose : | |
390 | // ======================================================================= | |
5e27df78 | 391 | void OpenGl_AspectFace::Release (const Handle(OpenGl_Context)& theContext) |
392 | { | |
30f0ad28 | 393 | if (!myResources.Texture.IsNull()) |
bf75be98 | 394 | { |
395 | if (!theContext.IsNull()) | |
396 | { | |
30f0ad28 | 397 | if (myResources.TextureId.IsEmpty()) |
bf75be98 | 398 | { |
30f0ad28 | 399 | theContext->DelayedRelease (myResources.Texture); |
bf75be98 | 400 | } |
401 | else | |
402 | { | |
30f0ad28 | 403 | myResources.Texture.Nullify(); // we need nullify all handles before ReleaseResource() call |
05dd08ce | 404 | theContext->ReleaseResource (myResources.TextureId, Standard_True); |
bf75be98 | 405 | } |
406 | } | |
30f0ad28 | 407 | myResources.Texture.Nullify(); |
bf75be98 | 408 | } |
30f0ad28 | 409 | myResources.TextureId.Clear(); |
f85399e5 | 410 | myResources.ResetTextureReadiness(); |
30f0ad28 | 411 | |
392ac980 | 412 | if (!myResources.ShaderProgram.IsNull() |
413 | && !theContext.IsNull()) | |
30f0ad28 | 414 | { |
392ac980 | 415 | theContext->ShaderManager()->Unregister (myResources.ShaderProgramId, |
416 | myResources.ShaderProgram); | |
30f0ad28 | 417 | } |
418 | myResources.ShaderProgramId.Clear(); | |
f85399e5 | 419 | myResources.ResetShaderReadiness(); |
5e27df78 | 420 | } |
fd4a6963 | 421 | |
422 | // ======================================================================= | |
30f0ad28 | 423 | // function : BuildTexture |
fd4a6963 | 424 | // purpose : |
425 | // ======================================================================= | |
30f0ad28 | 426 | void OpenGl_AspectFace::Resources::BuildTexture (const Handle(OpenGl_Workspace)& theWS, |
427 | const Handle(Graphic3d_TextureMap)& theTexture) | |
fd4a6963 | 428 | { |
30f0ad28 | 429 | const Handle(OpenGl_Context)& aContext = theWS->GetGlContext(); |
fd4a6963 | 430 | |
30f0ad28 | 431 | // release old texture resource |
432 | if (!Texture.IsNull()) | |
fd4a6963 | 433 | { |
30f0ad28 | 434 | if (TextureId.IsEmpty()) |
435 | { | |
436 | aContext->DelayedRelease (Texture); | |
437 | Texture.Nullify(); | |
438 | } | |
439 | else | |
fd4a6963 | 440 | { |
30f0ad28 | 441 | Texture.Nullify(); // we need nullify all handles before ReleaseResource() call |
95eef64d | 442 | aContext->ReleaseResource (TextureId, Standard_True); |
30f0ad28 | 443 | } |
444 | } | |
445 | ||
446 | TextureId = theTexture.IsNull() ? THE_EMPTY_KEY : theTexture->GetId(); | |
447 | ||
448 | if (!theTexture.IsNull()) | |
449 | { | |
450 | if (TextureId.IsEmpty() || !aContext->GetResource<Handle(OpenGl_Texture)> (TextureId, Texture)) | |
451 | { | |
452 | Texture = new OpenGl_Texture (theTexture->GetParams()); | |
453 | Handle(Image_PixMap) anImage = theTexture->GetImage(); | |
454 | if (!anImage.IsNull()) | |
fd4a6963 | 455 | { |
30f0ad28 | 456 | Texture->Init (aContext, *anImage.operator->(), theTexture->Type()); |
fd4a6963 | 457 | } |
30f0ad28 | 458 | if (!TextureId.IsEmpty()) |
fd4a6963 | 459 | { |
30f0ad28 | 460 | aContext->ShareResource (TextureId, Texture); |
fd4a6963 | 461 | } |
462 | } | |
30f0ad28 | 463 | } |
464 | } | |
fd4a6963 | 465 | |
30f0ad28 | 466 | // ======================================================================= |
467 | // function : BuildShader | |
468 | // purpose : | |
469 | // ======================================================================= | |
392ac980 | 470 | void OpenGl_AspectFace::Resources::BuildShader (const Handle(OpenGl_Workspace)& theWS, |
30f0ad28 | 471 | const Handle(Graphic3d_ShaderProgram)& theShader) |
472 | { | |
473 | const Handle(OpenGl_Context)& aContext = theWS->GetGlContext(); | |
30f0ad28 | 474 | if (!aContext->IsGlGreaterEqual (2, 0)) |
392ac980 | 475 | { |
30f0ad28 | 476 | return; |
392ac980 | 477 | } |
30f0ad28 | 478 | |
479 | // release old shader program resources | |
480 | if (!ShaderProgram.IsNull()) | |
481 | { | |
392ac980 | 482 | aContext->ShaderManager()->Unregister (ShaderProgramId, ShaderProgram); |
f85399e5 | 483 | ShaderProgramId.Clear(); |
484 | ShaderProgram.Nullify(); | |
30f0ad28 | 485 | } |
392ac980 | 486 | if (theShader.IsNull()) |
30f0ad28 | 487 | { |
392ac980 | 488 | return; |
30f0ad28 | 489 | } |
392ac980 | 490 | |
491 | aContext->ShaderManager()->Create (theShader, ShaderProgramId, ShaderProgram); | |
fd4a6963 | 492 | } |