aboutsummaryrefslogtreecommitdiffstatshomepage
path: root/libraries/irrlicht-1.8/source/Irrlicht/COpenGLMaterialRenderer.h
diff options
context:
space:
mode:
Diffstat (limited to 'libraries/irrlicht-1.8/source/Irrlicht/COpenGLMaterialRenderer.h')
-rw-r--r--libraries/irrlicht-1.8/source/Irrlicht/COpenGLMaterialRenderer.h756
1 files changed, 756 insertions, 0 deletions
diff --git a/libraries/irrlicht-1.8/source/Irrlicht/COpenGLMaterialRenderer.h b/libraries/irrlicht-1.8/source/Irrlicht/COpenGLMaterialRenderer.h
new file mode 100644
index 0000000..ea84a54
--- /dev/null
+++ b/libraries/irrlicht-1.8/source/Irrlicht/COpenGLMaterialRenderer.h
@@ -0,0 +1,756 @@
1// Copyright (C) 2002-2012 Nikolaus Gebhardt
2// This file is part of the "Irrlicht Engine".
3// For conditions of distribution and use, see copyright notice in irrlicht.h
4
5#ifndef __C_OPENGL_MATERIAL_RENDERER_H_INCLUDED__
6#define __C_OPENGL_MATERIAL_RENDERER_H_INCLUDED__
7
8#include "IrrCompileConfig.h"
9#ifdef _IRR_COMPILE_WITH_OPENGL_
10
11#include "COpenGLDriver.h"
12#include "IMaterialRenderer.h"
13
14namespace irr
15{
16namespace video
17{
18
19//! Base class for all internal OpenGL material renderers
20class COpenGLMaterialRenderer : public IMaterialRenderer
21{
22public:
23
24 //! Constructor
25 COpenGLMaterialRenderer(video::COpenGLDriver* driver) : Driver(driver)
26 {
27 }
28
29protected:
30
31 video::COpenGLDriver* Driver;
32};
33
34
35//! Solid material renderer
36class COpenGLMaterialRenderer_SOLID : public COpenGLMaterialRenderer
37{
38public:
39
40 COpenGLMaterialRenderer_SOLID(video::COpenGLDriver* d)
41 : COpenGLMaterialRenderer(d) {}
42
43 virtual void OnSetMaterial(const SMaterial& material, const SMaterial& lastMaterial,
44 bool resetAllRenderstates, IMaterialRendererServices* services)
45 {
46 Driver->disableTextures(1);
47 Driver->setBasicRenderStates(material, lastMaterial, resetAllRenderstates);
48
49 if (resetAllRenderstates || (material.MaterialType != lastMaterial.MaterialType))
50 {
51 // thanks to Murphy, the following line removed some
52 // bugs with several OpenGL implementations.
53 glTexEnvi(GL_TEXTURE_ENV, GL_TEXTURE_ENV_MODE, GL_MODULATE);
54 }
55 }
56};
57
58
59//! Generic Texture Blend
60class COpenGLMaterialRenderer_ONETEXTURE_BLEND : public COpenGLMaterialRenderer
61{
62public:
63
64 COpenGLMaterialRenderer_ONETEXTURE_BLEND(video::COpenGLDriver* d)
65 : COpenGLMaterialRenderer(d) {}
66
67 virtual void OnSetMaterial(const SMaterial& material, const SMaterial& lastMaterial,
68 bool resetAllRenderstates, IMaterialRendererServices* services)
69 {
70 Driver->disableTextures(1);
71 Driver->setBasicRenderStates(material, lastMaterial, resetAllRenderstates);
72
73// if (material.MaterialType != lastMaterial.MaterialType ||
74// material.MaterialTypeParam != lastMaterial.MaterialTypeParam ||
75// resetAllRenderstates)
76 {
77 E_BLEND_FACTOR srcFact,dstFact;
78 E_MODULATE_FUNC modulate;
79 u32 alphaSource;
80 unpack_textureBlendFunc(srcFact, dstFact, modulate, alphaSource, material.MaterialTypeParam);
81
82#ifdef GL_ARB_texture_env_combine
83 glTexEnvf(GL_TEXTURE_ENV, GL_TEXTURE_ENV_MODE, GL_COMBINE_ARB);
84 glTexEnvf(GL_TEXTURE_ENV, GL_COMBINE_RGB_ARB, GL_MODULATE);
85 glTexEnvf(GL_TEXTURE_ENV, GL_SOURCE0_RGB_ARB, GL_TEXTURE);
86 glTexEnvf(GL_TEXTURE_ENV, GL_SOURCE1_RGB_ARB, GL_PREVIOUS_ARB);
87 glTexEnvf(GL_TEXTURE_ENV, GL_RGB_SCALE_ARB, (f32) modulate );
88#else
89 glTexEnvf(GL_TEXTURE_ENV, GL_TEXTURE_ENV_MODE, GL_COMBINE_EXT);
90 glTexEnvf(GL_TEXTURE_ENV, GL_COMBINE_RGB_EXT, GL_MODULATE);
91 glTexEnvf(GL_TEXTURE_ENV, GL_SOURCE0_RGB_EXT, GL_TEXTURE);
92 glTexEnvf(GL_TEXTURE_ENV, GL_SOURCE1_RGB_EXT, GL_PREVIOUS_EXT);
93 glTexEnvf(GL_TEXTURE_ENV, GL_RGB_SCALE_EXT, (f32) modulate );
94#endif
95
96 glBlendFunc(Driver->getGLBlend(srcFact), Driver->getGLBlend(dstFact));
97 glEnable(GL_ALPHA_TEST);
98 glAlphaFunc(GL_GREATER, 0.f);
99 glEnable(GL_BLEND);
100
101 if ( textureBlendFunc_hasAlpha(srcFact) || textureBlendFunc_hasAlpha(dstFact) )
102 {
103 if (alphaSource==EAS_VERTEX_COLOR)
104 {
105#ifdef GL_ARB_texture_env_combine
106 glTexEnvf(GL_TEXTURE_ENV, GL_COMBINE_ALPHA_ARB, GL_REPLACE);
107 glTexEnvf(GL_TEXTURE_ENV, GL_SOURCE0_ALPHA_ARB, GL_PRIMARY_COLOR_ARB);
108#else
109 glTexEnvf(GL_TEXTURE_ENV, GL_COMBINE_ALPHA_EXT, GL_REPLACE);
110 glTexEnvf(GL_TEXTURE_ENV, GL_SOURCE0_ALPHA_EXT, GL_PRIMARY_COLOR_EXT);
111#endif
112 }
113 else if (alphaSource==EAS_TEXTURE)
114 {
115#ifdef GL_ARB_texture_env_combine
116 glTexEnvf(GL_TEXTURE_ENV, GL_COMBINE_ALPHA_ARB, GL_REPLACE);
117 glTexEnvf(GL_TEXTURE_ENV, GL_SOURCE0_ALPHA_ARB, GL_TEXTURE);
118#else
119 glTexEnvf(GL_TEXTURE_ENV, GL_COMBINE_ALPHA_EXT, GL_REPLACE);
120 glTexEnvf(GL_TEXTURE_ENV, GL_SOURCE0_ALPHA_EXT, GL_TEXTURE);
121#endif
122 }
123 else
124 {
125#ifdef GL_ARB_texture_env_combine
126 glTexEnvf(GL_TEXTURE_ENV, GL_COMBINE_ALPHA_ARB, GL_MODULATE);
127 glTexEnvf(GL_TEXTURE_ENV, GL_SOURCE0_ALPHA_ARB, GL_PRIMARY_COLOR_ARB);
128 glTexEnvf(GL_TEXTURE_ENV, GL_SOURCE1_ALPHA_ARB, GL_TEXTURE);
129#else
130 glTexEnvf(GL_TEXTURE_ENV, GL_COMBINE_ALPHA_EXT, GL_MODULATE);
131 glTexEnvf(GL_TEXTURE_ENV, GL_SOURCE0_ALPHA_EXT, GL_PRIMARY_COLOR_EXT);
132 glTexEnvf(GL_TEXTURE_ENV, GL_SOURCE1_ALPHA_EXT, GL_TEXTURE);
133#endif
134 }
135 }
136 }
137 }
138
139 virtual void OnUnsetMaterial()
140 {
141 glTexEnvi(GL_TEXTURE_ENV, GL_TEXTURE_ENV_MODE, GL_MODULATE);
142#ifdef GL_ARB_texture_env_combine
143 glTexEnvf(GL_TEXTURE_ENV, GL_COMBINE_ALPHA_ARB, GL_MODULATE);
144 glTexEnvf(GL_TEXTURE_ENV, GL_RGB_SCALE_ARB, 1.f );
145 glTexEnvf(GL_TEXTURE_ENV, GL_SOURCE1_RGB_ARB, GL_PREVIOUS_ARB);
146#else
147 glTexEnvf(GL_TEXTURE_ENV, GL_COMBINE_ALPHA_EXT, GL_MODULATE);
148 glTexEnvf(GL_TEXTURE_ENV, GL_RGB_SCALE_EXT, 1.f );
149 glTexEnvf(GL_TEXTURE_ENV, GL_SOURCE1_RGB_EXT, GL_PREVIOUS_EXT);
150#endif
151
152 glDisable(GL_BLEND);
153 glDisable(GL_ALPHA_TEST);
154 }
155
156 //! Returns if the material is transparent.
157 /** Is not always transparent, but mostly. */
158 virtual bool isTransparent() const
159 {
160 return true;
161 }
162};
163
164
165//! Solid 2 layer material renderer
166class COpenGLMaterialRenderer_SOLID_2_LAYER : public COpenGLMaterialRenderer
167{
168public:
169
170 COpenGLMaterialRenderer_SOLID_2_LAYER(video::COpenGLDriver* d)
171 : COpenGLMaterialRenderer(d) {}
172
173 virtual void OnSetMaterial(const SMaterial& material, const SMaterial& lastMaterial,
174 bool resetAllRenderstates, IMaterialRendererServices* services)
175 {
176 Driver->disableTextures(2);
177 Driver->setBasicRenderStates(material, lastMaterial, resetAllRenderstates);
178
179 if (material.MaterialType != lastMaterial.MaterialType || resetAllRenderstates)
180 {
181 if (Driver->queryFeature(EVDF_MULTITEXTURE))
182 {
183 Driver->extGlActiveTexture(GL_TEXTURE1_ARB);
184#ifdef GL_ARB_texture_env_combine
185 glTexEnvf(GL_TEXTURE_ENV, GL_TEXTURE_ENV_MODE, GL_COMBINE_ARB);
186 glTexEnvf(GL_TEXTURE_ENV, GL_COMBINE_ALPHA_ARB, GL_REPLACE);
187 glTexEnvf(GL_TEXTURE_ENV, GL_SOURCE0_ALPHA_ARB, GL_PRIMARY_COLOR_ARB);
188 glTexEnvf(GL_TEXTURE_ENV, GL_COMBINE_RGB_ARB, GL_INTERPOLATE);
189 glTexEnvf(GL_TEXTURE_ENV, GL_SOURCE0_RGB_ARB, GL_TEXTURE);
190 glTexEnvf(GL_TEXTURE_ENV, GL_SOURCE1_RGB_ARB, GL_PREVIOUS_ARB);
191 glTexEnvf(GL_TEXTURE_ENV, GL_SOURCE2_RGB_ARB, GL_PRIMARY_COLOR);
192 glTexEnvf(GL_TEXTURE_ENV, GL_OPERAND2_RGB_ARB, GL_SRC_ALPHA);
193#else
194 glTexEnvf(GL_TEXTURE_ENV, GL_TEXTURE_ENV_MODE, GL_COMBINE_EXT);
195 glTexEnvf(GL_TEXTURE_ENV, GL_COMBINE_ALPHA_EXT, GL_REPLACE);
196 glTexEnvf(GL_TEXTURE_ENV, GL_SOURCE0_ALPHA_EXT, GL_PRIMARY_COLOR_EXT);
197 glTexEnvf(GL_TEXTURE_ENV, GL_COMBINE_RGB_EXT, GL_INTERPOLATE);
198 glTexEnvf(GL_TEXTURE_ENV, GL_SOURCE0_RGB_EXT, GL_TEXTURE);
199 glTexEnvf(GL_TEXTURE_ENV, GL_SOURCE1_RGB_EXT, GL_PREVIOUS_EXT);
200 glTexEnvf(GL_TEXTURE_ENV, GL_SOURCE2_RGB_EXT, GL_PRIMARY_COLOR);
201 glTexEnvf(GL_TEXTURE_ENV, GL_OPERAND2_RGB_EXT, GL_SRC_ALPHA);
202#endif
203 }
204 }
205 }
206
207 virtual void OnUnsetMaterial()
208 {
209 if (Driver->queryFeature(EVDF_MULTITEXTURE))
210 {
211 Driver->extGlActiveTexture(GL_TEXTURE1_ARB);
212 glTexEnvi(GL_TEXTURE_ENV, GL_TEXTURE_ENV_MODE, GL_MODULATE);
213#ifdef GL_ARB_texture_env_combine
214 glTexEnvf(GL_TEXTURE_ENV, GL_OPERAND2_RGB_ARB, GL_SRC_COLOR);
215#else
216 glTexEnvf(GL_TEXTURE_ENV, GL_OPERAND2_RGB_EXT, GL_SRC_COLOR);
217#endif
218 Driver->extGlActiveTexture(GL_TEXTURE0_ARB);
219 }
220 }
221};
222
223
224//! Transparent add color material renderer
225class COpenGLMaterialRenderer_TRANSPARENT_ADD_COLOR : public COpenGLMaterialRenderer
226{
227public:
228
229 COpenGLMaterialRenderer_TRANSPARENT_ADD_COLOR(video::COpenGLDriver* d)
230 : COpenGLMaterialRenderer(d) {}
231
232 virtual void OnSetMaterial(const SMaterial& material, const SMaterial& lastMaterial,
233 bool resetAllRenderstates, IMaterialRendererServices* services)
234 {
235 Driver->disableTextures(1);
236 Driver->setBasicRenderStates(material, lastMaterial, resetAllRenderstates);
237
238 if ((material.MaterialType != lastMaterial.MaterialType) || resetAllRenderstates)
239 {
240 glBlendFunc(GL_ONE, GL_ONE_MINUS_SRC_COLOR);
241 glTexEnvi(GL_TEXTURE_ENV, GL_TEXTURE_ENV_MODE, GL_MODULATE);
242 glEnable(GL_BLEND);
243 }
244 }
245
246 virtual void OnUnsetMaterial()
247 {
248 glDisable(GL_BLEND);
249 }
250
251 //! Returns if the material is transparent.
252 virtual bool isTransparent() const
253 {
254 return true;
255 }
256};
257
258
259//! Transparent vertex alpha material renderer
260class COpenGLMaterialRenderer_TRANSPARENT_VERTEX_ALPHA : public COpenGLMaterialRenderer
261{
262public:
263
264 COpenGLMaterialRenderer_TRANSPARENT_VERTEX_ALPHA(video::COpenGLDriver* d)
265 : COpenGLMaterialRenderer(d) {}
266
267 virtual void OnSetMaterial(const SMaterial& material, const SMaterial& lastMaterial,
268 bool resetAllRenderstates, IMaterialRendererServices* services)
269 {
270 Driver->disableTextures(1);
271 Driver->setBasicRenderStates(material, lastMaterial, resetAllRenderstates);
272
273 if (material.MaterialType != lastMaterial.MaterialType || resetAllRenderstates)
274 {
275#ifdef GL_ARB_texture_env_combine
276 glTexEnvf(GL_TEXTURE_ENV, GL_TEXTURE_ENV_MODE, GL_COMBINE_ARB);
277 glTexEnvf(GL_TEXTURE_ENV, GL_COMBINE_ALPHA_ARB, GL_REPLACE);
278 glTexEnvf(GL_TEXTURE_ENV, GL_SOURCE0_ALPHA_ARB, GL_PRIMARY_COLOR_ARB);
279 glTexEnvf(GL_TEXTURE_ENV, GL_COMBINE_RGB_ARB, GL_MODULATE);
280 glTexEnvf(GL_TEXTURE_ENV, GL_SOURCE0_RGB_ARB, GL_TEXTURE);
281 glTexEnvf(GL_TEXTURE_ENV, GL_SOURCE1_RGB_ARB, GL_PREVIOUS_ARB);
282#else
283 glTexEnvf(GL_TEXTURE_ENV, GL_TEXTURE_ENV_MODE, GL_COMBINE_EXT);
284 glTexEnvf(GL_TEXTURE_ENV, GL_COMBINE_ALPHA_EXT, GL_REPLACE);
285 glTexEnvf(GL_TEXTURE_ENV, GL_SOURCE0_ALPHA_EXT, GL_PRIMARY_COLOR_EXT );
286 glTexEnvf(GL_TEXTURE_ENV, GL_COMBINE_RGB_EXT, GL_MODULATE);
287 glTexEnvf(GL_TEXTURE_ENV, GL_SOURCE0_RGB_EXT, GL_TEXTURE);
288 glTexEnvf(GL_TEXTURE_ENV, GL_SOURCE1_RGB_EXT, GL_PREVIOUS_EXT);
289#endif
290 glBlendFunc(GL_SRC_ALPHA, GL_ONE_MINUS_SRC_ALPHA);
291 glEnable(GL_BLEND);
292 }
293 }
294
295 virtual void OnUnsetMaterial()
296 {
297 // default values
298 glTexEnvi(GL_TEXTURE_ENV, GL_TEXTURE_ENV_MODE, GL_MODULATE);
299#ifdef GL_ARB_texture_env_combine
300 glTexEnvf(GL_TEXTURE_ENV, GL_COMBINE_ALPHA_ARB, GL_MODULATE );
301 glTexEnvf(GL_TEXTURE_ENV, GL_SOURCE0_ALPHA_ARB, GL_TEXTURE );
302#else
303 glTexEnvf(GL_TEXTURE_ENV, GL_COMBINE_ALPHA_EXT, GL_MODULATE );
304 glTexEnvf(GL_TEXTURE_ENV, GL_SOURCE0_ALPHA_EXT, GL_TEXTURE );
305#endif
306 glDisable(GL_BLEND);
307 }
308
309 //! Returns if the material is transparent.
310 virtual bool isTransparent() const
311 {
312 return true;
313 }
314};
315
316
317//! Transparent alpha channel material renderer
318class COpenGLMaterialRenderer_TRANSPARENT_ALPHA_CHANNEL : public COpenGLMaterialRenderer
319{
320public:
321
322 COpenGLMaterialRenderer_TRANSPARENT_ALPHA_CHANNEL(video::COpenGLDriver* d)
323 : COpenGLMaterialRenderer(d) {}
324
325 virtual void OnSetMaterial(const SMaterial& material, const SMaterial& lastMaterial,
326 bool resetAllRenderstates, IMaterialRendererServices* services)
327 {
328 Driver->disableTextures(1);
329 Driver->setBasicRenderStates(material, lastMaterial, resetAllRenderstates);
330
331 if (material.MaterialType != lastMaterial.MaterialType || resetAllRenderstates
332 || material.MaterialTypeParam != lastMaterial.MaterialTypeParam )
333 {
334#ifdef GL_ARB_texture_env_combine
335 glTexEnvf(GL_TEXTURE_ENV, GL_TEXTURE_ENV_MODE, GL_COMBINE_ARB);
336 glTexEnvf(GL_TEXTURE_ENV, GL_COMBINE_RGB_ARB, GL_MODULATE);
337 glTexEnvf(GL_TEXTURE_ENV, GL_SOURCE0_RGB_ARB, GL_TEXTURE);
338 glTexEnvf(GL_TEXTURE_ENV, GL_SOURCE1_RGB_ARB, GL_PREVIOUS_ARB);
339 glTexEnvf(GL_TEXTURE_ENV, GL_COMBINE_ALPHA_ARB, GL_REPLACE);
340 glTexEnvf(GL_TEXTURE_ENV, GL_SOURCE0_ALPHA_ARB, GL_TEXTURE);
341#else
342 glTexEnvf(GL_TEXTURE_ENV, GL_TEXTURE_ENV_MODE, GL_COMBINE_EXT);
343 glTexEnvf(GL_TEXTURE_ENV, GL_COMBINE_RGB_EXT, GL_MODULATE);
344 glTexEnvf(GL_TEXTURE_ENV, GL_SOURCE0_RGB_EXT, GL_TEXTURE);
345 glTexEnvf(GL_TEXTURE_ENV, GL_SOURCE1_RGB_EXT, GL_PREVIOUS_EXT);
346 glTexEnvf(GL_TEXTURE_ENV, GL_COMBINE_ALPHA_EXT, GL_REPLACE);
347 glTexEnvf(GL_TEXTURE_ENV, GL_SOURCE0_ALPHA_EXT, GL_TEXTURE);
348#endif
349 glBlendFunc(GL_SRC_ALPHA, GL_ONE_MINUS_SRC_ALPHA);
350 glEnable(GL_BLEND);
351 glEnable(GL_ALPHA_TEST);
352
353 glAlphaFunc(GL_GREATER, material.MaterialTypeParam);
354 }
355 }
356
357 virtual void OnUnsetMaterial()
358 {
359 glTexEnvi(GL_TEXTURE_ENV, GL_TEXTURE_ENV_MODE, GL_MODULATE);
360#ifdef GL_ARB_texture_env_combine
361 glTexEnvf(GL_TEXTURE_ENV, GL_COMBINE_ALPHA_ARB, GL_MODULATE );
362#else
363 glTexEnvf(GL_TEXTURE_ENV, GL_COMBINE_ALPHA_EXT, GL_MODULATE );
364#endif
365 glDisable(GL_ALPHA_TEST);
366 glDisable(GL_BLEND);
367 }
368
369 //! Returns if the material is transparent.
370 virtual bool isTransparent() const
371 {
372 return true;
373 }
374};
375
376
377//! Transparent alpha channel material renderer
378class COpenGLMaterialRenderer_TRANSPARENT_ALPHA_CHANNEL_REF : public COpenGLMaterialRenderer
379{
380public:
381
382 COpenGLMaterialRenderer_TRANSPARENT_ALPHA_CHANNEL_REF(video::COpenGLDriver* d)
383 : COpenGLMaterialRenderer(d) {}
384
385 virtual void OnSetMaterial(const SMaterial& material, const SMaterial& lastMaterial,
386 bool resetAllRenderstates, IMaterialRendererServices* services)
387 {
388 Driver->disableTextures(1);
389 Driver->setBasicRenderStates(material, lastMaterial, resetAllRenderstates);
390
391 if (material.MaterialType != lastMaterial.MaterialType || resetAllRenderstates)
392 {
393 glEnable(GL_ALPHA_TEST);
394 glAlphaFunc(GL_GREATER, 0.5f);
395 glTexEnvi(GL_TEXTURE_ENV, GL_TEXTURE_ENV_MODE, GL_MODULATE);
396 }
397 }
398
399 virtual void OnUnsetMaterial()
400 {
401 glDisable(GL_ALPHA_TEST);
402 }
403
404 //! Returns if the material is transparent.
405 virtual bool isTransparent() const
406 {
407 return false; // this material is not really transparent because it does no blending.
408 }
409};
410
411
412//! material renderer for all kinds of lightmaps
413class COpenGLMaterialRenderer_LIGHTMAP : public COpenGLMaterialRenderer
414{
415public:
416
417 COpenGLMaterialRenderer_LIGHTMAP(video::COpenGLDriver* d)
418 : COpenGLMaterialRenderer(d) {}
419
420 virtual void OnSetMaterial(const SMaterial& material, const SMaterial& lastMaterial,
421 bool resetAllRenderstates, IMaterialRendererServices* services)
422 {
423 Driver->disableTextures(2);
424 Driver->setBasicRenderStates(material, lastMaterial, resetAllRenderstates);
425
426 if (material.MaterialType != lastMaterial.MaterialType || resetAllRenderstates)
427 {
428 // diffuse map
429
430 switch (material.MaterialType)
431 {
432 case EMT_LIGHTMAP_LIGHTING:
433 case EMT_LIGHTMAP_LIGHTING_M2:
434 case EMT_LIGHTMAP_LIGHTING_M4:
435 glTexEnvi(GL_TEXTURE_ENV, GL_TEXTURE_ENV_MODE, GL_MODULATE);
436 break;
437 case EMT_LIGHTMAP_ADD:
438 case EMT_LIGHTMAP:
439 case EMT_LIGHTMAP_M2:
440 case EMT_LIGHTMAP_M4:
441 default:
442 glTexEnvi(GL_TEXTURE_ENV, GL_TEXTURE_ENV_MODE, GL_REPLACE);
443 break;
444 }
445
446 if (Driver->queryFeature(EVDF_MULTITEXTURE))
447 {
448 // lightmap
449
450 Driver->extGlActiveTexture(GL_TEXTURE1_ARB);
451#ifdef GL_ARB_texture_env_combine
452 glTexEnvi(GL_TEXTURE_ENV, GL_TEXTURE_ENV_MODE, GL_COMBINE_ARB);
453
454 if (material.MaterialType == EMT_LIGHTMAP_ADD)
455 glTexEnvi(GL_TEXTURE_ENV, GL_COMBINE_RGB_ARB, GL_ADD);
456 else
457 glTexEnvi(GL_TEXTURE_ENV, GL_COMBINE_RGB_ARB, GL_MODULATE);
458
459 glTexEnvi(GL_TEXTURE_ENV, GL_SOURCE0_RGB_ARB, GL_TEXTURE);
460 glTexEnvi(GL_TEXTURE_ENV, GL_SOURCE1_RGB_ARB, GL_PREVIOUS_ARB);
461 glTexEnvf(GL_TEXTURE_ENV, GL_COMBINE_ALPHA_ARB, GL_MODULATE);
462 glTexEnvi(GL_TEXTURE_ENV, GL_SOURCE0_ALPHA_ARB, GL_TEXTURE);
463 glTexEnvi(GL_TEXTURE_ENV, GL_SOURCE1_ALPHA_ARB, GL_PREVIOUS_ARB);
464#else
465 glTexEnvi(GL_TEXTURE_ENV, GL_TEXTURE_ENV_MODE, GL_COMBINE_EXT);
466
467 if (material.MaterialType == EMT_LIGHTMAP_ADD)
468 glTexEnvi(GL_TEXTURE_ENV, GL_COMBINE_RGB_EXT, GL_ADD);
469 else
470 glTexEnvi(GL_TEXTURE_ENV, GL_COMBINE_RGB_EXT, GL_MODULATE);
471
472 glTexEnvi(GL_TEXTURE_ENV, GL_SOURCE0_RGB_EXT, GL_TEXTURE);
473 glTexEnvi(GL_TEXTURE_ENV, GL_SOURCE1_RGB_EXT, GL_PREVIOUS_EXT);
474 glTexEnvf(GL_TEXTURE_ENV, GL_COMBINE_ALPHA_EXT, GL_MODULATE);
475 glTexEnvi(GL_TEXTURE_ENV, GL_SOURCE0_ALPHA_EXT, GL_TEXTURE);
476 glTexEnvi(GL_TEXTURE_ENV, GL_SOURCE1_ALPHA_EXT, GL_PREVIOUS_EXT);
477#endif
478
479 switch (material.MaterialType)
480 {
481 case EMT_LIGHTMAP_M4:
482 case EMT_LIGHTMAP_LIGHTING_M4:
483#ifdef GL_ARB_texture_env_combine
484 glTexEnvf(GL_TEXTURE_ENV, GL_RGB_SCALE_ARB, 4.0f);
485#else
486 glTexEnvf(GL_TEXTURE_ENV, GL_RGB_SCALE_EXT, 4.0f);
487#endif
488 break;
489 case EMT_LIGHTMAP_M2:
490 case EMT_LIGHTMAP_LIGHTING_M2:
491#ifdef GL_ARB_texture_env_combine
492 glTexEnvf(GL_TEXTURE_ENV, GL_RGB_SCALE_ARB, 2.0f);
493#else
494 glTexEnvf(GL_TEXTURE_ENV, GL_RGB_SCALE_EXT, 2.0f);
495#endif
496 break;
497 default:
498#ifdef GL_ARB_texture_env_combine
499 glTexEnvf(GL_TEXTURE_ENV, GL_RGB_SCALE_ARB, 1.0f);
500#else
501 glTexEnvf(GL_TEXTURE_ENV, GL_RGB_SCALE_EXT, 1.0f);
502#endif
503 }
504 Driver->extGlActiveTexture(GL_TEXTURE0_ARB);
505 }
506 }
507 }
508
509 virtual void OnUnsetMaterial()
510 {
511 if (Driver->queryFeature(EVDF_MULTITEXTURE))
512 {
513 Driver->extGlActiveTexture(GL_TEXTURE1_ARB);
514#ifdef GL_ARB_texture_env_combine
515 glTexEnvf(GL_TEXTURE_ENV, GL_RGB_SCALE_ARB, 1.f );
516#else
517 glTexEnvf(GL_TEXTURE_ENV, GL_RGB_SCALE_EXT, 1.f );
518#endif
519 glTexEnvi(GL_TEXTURE_ENV, GL_TEXTURE_ENV_MODE, GL_MODULATE);
520 Driver->extGlActiveTexture(GL_TEXTURE0_ARB);
521 glTexEnvi(GL_TEXTURE_ENV, GL_TEXTURE_ENV_MODE, GL_MODULATE);
522 }
523 }
524};
525
526
527
528//! detail map material renderer
529class COpenGLMaterialRenderer_DETAIL_MAP : public COpenGLMaterialRenderer
530{
531public:
532
533 COpenGLMaterialRenderer_DETAIL_MAP(video::COpenGLDriver* d)
534 : COpenGLMaterialRenderer(d) {}
535
536 virtual void OnSetMaterial(const SMaterial& material, const SMaterial& lastMaterial,
537 bool resetAllRenderstates, IMaterialRendererServices* services)
538 {
539 Driver->disableTextures(2);
540 Driver->setBasicRenderStates(material, lastMaterial, resetAllRenderstates);
541
542 if (material.MaterialType != lastMaterial.MaterialType || resetAllRenderstates)
543 {
544 // diffuse map is default modulated
545
546 // detail map on second layer
547 if (Driver->queryFeature(EVDF_MULTITEXTURE))
548 {
549 Driver->extGlActiveTexture(GL_TEXTURE1_ARB);
550#ifdef GL_ARB_texture_env_combine
551 glTexEnvi(GL_TEXTURE_ENV, GL_TEXTURE_ENV_MODE, GL_COMBINE_ARB);
552 glTexEnvi(GL_TEXTURE_ENV, GL_COMBINE_RGB_ARB, GL_ADD_SIGNED_ARB);
553 glTexEnvi(GL_TEXTURE_ENV, GL_SOURCE0_RGB_ARB, GL_TEXTURE);
554 glTexEnvi(GL_TEXTURE_ENV, GL_SOURCE1_RGB_ARB, GL_PREVIOUS_ARB);
555#else
556 glTexEnvi(GL_TEXTURE_ENV, GL_TEXTURE_ENV_MODE, GL_COMBINE_EXT);
557 glTexEnvi(GL_TEXTURE_ENV, GL_COMBINE_RGB_EXT, GL_ADD_SIGNED_EXT);
558 glTexEnvi(GL_TEXTURE_ENV, GL_SOURCE0_RGB_EXT, GL_TEXTURE);
559 glTexEnvi(GL_TEXTURE_ENV, GL_SOURCE1_RGB_EXT, GL_PREVIOUS_EXT);
560#endif
561 }
562 }
563 }
564
565 virtual void OnUnsetMaterial()
566 {
567 if (Driver->queryFeature(EVDF_MULTITEXTURE))
568 {
569 Driver->extGlActiveTexture(GL_TEXTURE1_ARB);
570 glTexEnvi(GL_TEXTURE_ENV, GL_TEXTURE_ENV_MODE, GL_MODULATE);
571 Driver->extGlActiveTexture(GL_TEXTURE0_ARB);
572 }
573 }
574};
575
576
577//! sphere map material renderer
578class COpenGLMaterialRenderer_SPHERE_MAP : public COpenGLMaterialRenderer
579{
580public:
581
582 COpenGLMaterialRenderer_SPHERE_MAP(video::COpenGLDriver* d)
583 : COpenGLMaterialRenderer(d) {}
584
585 virtual void OnSetMaterial(const SMaterial& material, const SMaterial& lastMaterial,
586 bool resetAllRenderstates, IMaterialRendererServices* services)
587 {
588 Driver->disableTextures(1);
589 // texture needs to be flipped for OpenGL
590 core::matrix4 tmp = Driver->getTransform(ETS_TEXTURE_0);
591 tmp[5]*=-1;
592 Driver->setTransform(ETS_TEXTURE_0, tmp);
593 Driver->setBasicRenderStates(material, lastMaterial, resetAllRenderstates);
594
595 if (material.MaterialType != lastMaterial.MaterialType || resetAllRenderstates)
596 {
597 glTexGeni(GL_S, GL_TEXTURE_GEN_MODE, GL_SPHERE_MAP);
598 glTexGeni(GL_T, GL_TEXTURE_GEN_MODE, GL_SPHERE_MAP);
599
600 glEnable(GL_TEXTURE_GEN_S);
601 glEnable(GL_TEXTURE_GEN_T);
602 }
603 }
604
605 virtual void OnUnsetMaterial()
606 {
607 glDisable(GL_TEXTURE_GEN_S);
608 glDisable(GL_TEXTURE_GEN_T);
609 }
610};
611
612
613//! reflection 2 layer material renderer
614class COpenGLMaterialRenderer_REFLECTION_2_LAYER : public COpenGLMaterialRenderer
615{
616public:
617
618 COpenGLMaterialRenderer_REFLECTION_2_LAYER(video::COpenGLDriver* d)
619 : COpenGLMaterialRenderer(d) {}
620
621 virtual void OnSetMaterial(const SMaterial& material, const SMaterial& lastMaterial,
622 bool resetAllRenderstates, IMaterialRendererServices* services)
623 {
624 Driver->disableTextures(2);
625 Driver->setBasicRenderStates(material, lastMaterial, resetAllRenderstates);
626
627 if (material.MaterialType != lastMaterial.MaterialType || resetAllRenderstates)
628 {
629 if (Driver->queryFeature(EVDF_MULTITEXTURE))
630 {
631 Driver->extGlActiveTexture(GL_TEXTURE1_ARB);
632#ifdef GL_ARB_texture_env_combine
633 glTexEnvi(GL_TEXTURE_ENV, GL_TEXTURE_ENV_MODE, GL_COMBINE_ARB);
634 glTexEnvi(GL_TEXTURE_ENV, GL_COMBINE_RGB_ARB, GL_MODULATE);
635 glTexEnvi(GL_TEXTURE_ENV, GL_SOURCE0_RGB_ARB, GL_TEXTURE);
636 glTexEnvi(GL_TEXTURE_ENV, GL_SOURCE1_RGB_ARB, GL_PREVIOUS_ARB);
637#else
638 glTexEnvi(GL_TEXTURE_ENV, GL_TEXTURE_ENV_MODE, GL_COMBINE_EXT);
639 glTexEnvi(GL_TEXTURE_ENV, GL_COMBINE_RGB_EXT, GL_MODULATE);
640 glTexEnvi(GL_TEXTURE_ENV, GL_SOURCE0_RGB_EXT, GL_TEXTURE);
641 glTexEnvi(GL_TEXTURE_ENV, GL_SOURCE1_RGB_EXT, GL_PREVIOUS_EXT);
642#endif
643 }
644 glTexGeni(GL_S, GL_TEXTURE_GEN_MODE, GL_SPHERE_MAP);
645 glTexGeni(GL_T, GL_TEXTURE_GEN_MODE, GL_SPHERE_MAP);
646 glEnable(GL_TEXTURE_GEN_S);
647 glEnable(GL_TEXTURE_GEN_T);
648 }
649 }
650
651 virtual void OnUnsetMaterial()
652 {
653 if (Driver->queryFeature(EVDF_MULTITEXTURE))
654 {
655 Driver->extGlActiveTexture(GL_TEXTURE1_ARB);
656 glTexEnvi(GL_TEXTURE_ENV, GL_TEXTURE_ENV_MODE, GL_MODULATE);
657 }
658 glDisable(GL_TEXTURE_GEN_S);
659 glDisable(GL_TEXTURE_GEN_T);
660 if (Driver->queryFeature(EVDF_MULTITEXTURE))
661 {
662 Driver->extGlActiveTexture(GL_TEXTURE0_ARB);
663 }
664 }
665};
666
667
668//! reflection 2 layer material renderer
669class COpenGLMaterialRenderer_TRANSPARENT_REFLECTION_2_LAYER : public COpenGLMaterialRenderer
670{
671public:
672
673 COpenGLMaterialRenderer_TRANSPARENT_REFLECTION_2_LAYER(video::COpenGLDriver* d)
674 : COpenGLMaterialRenderer(d) {}
675
676 virtual void OnSetMaterial(const SMaterial& material, const SMaterial& lastMaterial,
677 bool resetAllRenderstates, IMaterialRendererServices* services)
678 {
679 Driver->disableTextures(2);
680 Driver->setBasicRenderStates(material, lastMaterial, resetAllRenderstates);
681
682 if (material.MaterialType != lastMaterial.MaterialType || resetAllRenderstates)
683 {
684#ifdef GL_ARB_texture_env_combine
685 glTexEnvi(GL_TEXTURE_ENV, GL_TEXTURE_ENV_MODE, GL_COMBINE_ARB);
686 glTexEnvi(GL_TEXTURE_ENV, GL_COMBINE_RGB_ARB, GL_MODULATE);
687 glTexEnvi(GL_TEXTURE_ENV, GL_SOURCE0_RGB_ARB, GL_TEXTURE);
688 glTexEnvi(GL_TEXTURE_ENV, GL_SOURCE1_RGB_ARB, GL_PREVIOUS_ARB);
689 glTexEnvi(GL_TEXTURE_ENV, GL_COMBINE_ALPHA_ARB, GL_REPLACE);
690 glTexEnvi(GL_TEXTURE_ENV, GL_SOURCE0_ALPHA_ARB, GL_PREVIOUS_ARB);
691#else
692 glTexEnvi(GL_TEXTURE_ENV, GL_TEXTURE_ENV_MODE, GL_COMBINE_EXT);
693 glTexEnvi(GL_TEXTURE_ENV, GL_COMBINE_RGB_EXT, GL_MODULATE);
694 glTexEnvi(GL_TEXTURE_ENV, GL_SOURCE0_RGB_EXT, GL_TEXTURE);
695 glTexEnvi(GL_TEXTURE_ENV, GL_SOURCE1_RGB_EXT, GL_PREVIOUS_EXT);
696 glTexEnvi(GL_TEXTURE_ENV, GL_COMBINE_ALPHA_EXT, GL_REPLACE);
697 glTexEnvi(GL_TEXTURE_ENV, GL_SOURCE0_ALPHA_EXT, GL_PREVIOUS_ARB);
698#endif
699 if (Driver->queryFeature(EVDF_MULTITEXTURE))
700 {
701 Driver->extGlActiveTexture(GL_TEXTURE1_ARB);
702#ifdef GL_ARB_texture_env_combine
703 glTexEnvi(GL_TEXTURE_ENV, GL_TEXTURE_ENV_MODE, GL_COMBINE_ARB);
704 glTexEnvi(GL_TEXTURE_ENV, GL_COMBINE_RGB_ARB, GL_MODULATE);
705 glTexEnvi(GL_TEXTURE_ENV, GL_SOURCE0_RGB_ARB, GL_TEXTURE);
706 glTexEnvi(GL_TEXTURE_ENV, GL_SOURCE1_RGB_ARB, GL_PREVIOUS_ARB);
707 glTexEnvi(GL_TEXTURE_ENV, GL_COMBINE_ALPHA_ARB, GL_REPLACE);
708 glTexEnvi(GL_TEXTURE_ENV, GL_SOURCE0_ALPHA_ARB, GL_PREVIOUS_ARB);
709#else
710 glTexEnvi(GL_TEXTURE_ENV, GL_TEXTURE_ENV_MODE, GL_COMBINE_EXT);
711 glTexEnvi(GL_TEXTURE_ENV, GL_COMBINE_RGB_EXT, GL_MODULATE);
712 glTexEnvi(GL_TEXTURE_ENV, GL_SOURCE0_RGB_EXT, GL_TEXTURE);
713 glTexEnvi(GL_TEXTURE_ENV, GL_SOURCE1_RGB_EXT, GL_PREVIOUS_EXT);
714 glTexEnvi(GL_TEXTURE_ENV, GL_COMBINE_ALPHA_EXT, GL_REPLACE);
715 glTexEnvi(GL_TEXTURE_ENV, GL_SOURCE0_ALPHA_EXT, GL_PREVIOUS_ARB);
716#endif
717 }
718 glTexGeni(GL_S, GL_TEXTURE_GEN_MODE, GL_SPHERE_MAP);
719 glTexGeni(GL_T, GL_TEXTURE_GEN_MODE, GL_SPHERE_MAP);
720 glEnable(GL_TEXTURE_GEN_S);
721 glEnable(GL_TEXTURE_GEN_T);
722
723 glBlendFunc(GL_SRC_ALPHA, GL_ONE_MINUS_SRC_ALPHA);
724 glEnable(GL_BLEND);
725 }
726 }
727
728 virtual void OnUnsetMaterial()
729 {
730 if (Driver->queryFeature(EVDF_MULTITEXTURE))
731 {
732 Driver->extGlActiveTexture(GL_TEXTURE1_ARB);
733 glTexEnvi(GL_TEXTURE_ENV, GL_TEXTURE_ENV_MODE, GL_MODULATE);
734 }
735 glDisable(GL_TEXTURE_GEN_S);
736 glDisable(GL_TEXTURE_GEN_T);
737 if (Driver->queryFeature(EVDF_MULTITEXTURE))
738 {
739 Driver->extGlActiveTexture(GL_TEXTURE0_ARB);
740 }
741 glDisable(GL_BLEND);
742 }
743
744 //! Returns if the material is transparent.
745 virtual bool isTransparent() const
746 {
747 return true;
748 }
749};
750
751} // end namespace video
752} // end namespace irr
753
754#endif
755#endif
756