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