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