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