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