DEADSOFTWARE

Merge glLight changes. Thanks, Rikku2000!
[nanogl.git] / nanoWrap.cpp
1 /*
2 Copyright (C) 2007-2009 Olli Hinkka
4 This program is free software; you can redistribute it and/or
5 modify it under the terms of the GNU General Public License
6 as published by the Free Software Foundation; either version 2
7 of the License, or (at your option) any later version.
9 This program is distributed in the hope that it will be useful,
10 but WITHOUT ANY WARRANTY; without even the implied warranty of
11 MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE.
13 See the GNU General Public License for more details.
15 You should have received a copy of the GNU General Public License
16 along with this program; if not, write to the Free Software
17 Foundation, Inc., 59 Temple Place - Suite 330, Boston, MA 02111-1307, USA.
19 */
20 /*
21 #include <e32def.h>
22 #include <e32std.h>
23 */
25 #include <stdio.h>
26 #include <stdlib.h>
27 #include <string.h>
29 #include "gl.h"
30 #include "glesinterface.h"
31 #include "nanogl.h"
33 #define GL_TEXTURE0_ARB 0x84C0
34 #define GL_TEXTURE1_ARB 0x84C1
36 struct nanoState
37 {
38 GLboolean alpha_test;
39 GLboolean blend;
40 GLboolean clip_planei;
41 GLboolean color_logic_op;
42 GLboolean color_material;
43 GLboolean cull_face;
44 GLboolean depth_test;
45 GLboolean dither;
46 GLboolean fog;
47 GLboolean light0;
48 GLboolean light1;
49 GLboolean light2;
50 GLboolean light3;
51 GLboolean light4;
52 GLboolean light5;
53 GLboolean light6;
54 GLboolean light7;
55 GLboolean lighting;
56 GLboolean line_smooth;
57 GLboolean matrix_palette_oes;
58 GLboolean multisample;
59 GLboolean normalize;
60 GLboolean point_smooth;
61 GLboolean point_sprite_oes;
62 GLboolean polygon_offset_fill;
63 GLboolean rescale_normal;
64 GLboolean sample_alpha_to_coverage;
65 GLboolean sample_alpha_to_one;
66 GLboolean sample_coverage;
67 GLboolean scissor_test;
68 GLboolean stencil_test;
69 GLboolean depthmask;
70 GLclampf depth_range_near;
71 GLclampf depth_range_far;
72 GLenum depth_func;
73 GLenum cullface;
74 GLenum shademodel;
75 GLenum sfactor;
76 GLenum dfactor;
77 GLenum matrixmode;
78 };
80 static struct nanoState nanoglState;
82 static struct nanoState nanoglInitState =
83 {
84 GL_FALSE,
85 GL_FALSE,
86 GL_FALSE,
87 GL_FALSE,
88 GL_FALSE,
89 GL_FALSE,
90 GL_FALSE,
91 GL_TRUE,
92 GL_FALSE,
93 GL_FALSE,
94 GL_FALSE,
95 GL_FALSE,
96 GL_FALSE,
97 GL_FALSE,
98 GL_FALSE,
99 GL_FALSE,
100 GL_FALSE,
101 GL_FALSE,
102 GL_FALSE,
103 GL_FALSE,
104 GL_TRUE,
105 GL_FALSE,
106 GL_FALSE,
107 GL_FALSE,
108 GL_FALSE,
109 GL_FALSE,
110 GL_FALSE,
111 GL_FALSE,
112 GL_FALSE,
113 GL_FALSE,
114 GL_FALSE,
115 GL_TRUE,
116 0.0f,
117 1.0f,
118 GL_LESS,
119 GL_BACK,
120 GL_SMOOTH,
121 GL_ONE,
122 GL_ZERO,
123 GL_MODELVIEW,
124 };
126 struct booleanstate
128 GLboolean value;
129 GLboolean changed;
130 };
132 struct floatstate
134 GLfloat value;
135 GLboolean changed;
136 };
138 struct uintstate
140 GLuint value;
141 GLboolean changed;
142 };
144 struct ptrstate
146 GLint size;
147 GLenum type;
148 GLsizei stride;
149 GLvoid *ptr;
150 GLboolean changed;
151 GLboolean enabled;
152 };
154 struct nanotmuState
156 struct booleanstate texture_2d;
157 struct floatstate texture_env_mode;
158 struct uintstate boundtexture;
159 struct ptrstate vertex_array;
160 struct ptrstate color_array;
161 struct ptrstate texture_coord_array;
162 struct ptrstate normal_array;
163 };
165 static struct nanotmuState tmuState0;
166 static struct nanotmuState tmuState1;
168 static struct nanotmuState tmuInitState =
170 {GL_FALSE, GL_FALSE},
171 {GL_MODULATE, GL_FALSE},
172 {0x7fffffff, GL_FALSE},
173 {4, GL_FLOAT, 0, NULL, GL_FALSE, GL_FALSE},
174 {4, GL_FLOAT, 0, NULL, GL_FALSE, GL_FALSE},
175 {4, GL_FLOAT, 0, NULL, GL_FALSE, GL_FALSE},
176 {3, GL_FLOAT, 0, NULL, GL_FALSE, GL_FALSE},
177 };
179 static struct nanotmuState *activetmuState = &tmuState0;
181 extern "C++" GlESInterface *glEsImpl;
183 static GLenum wrapperPrimitiveMode = GL_QUADS;
184 GLboolean useTexCoordArray = GL_FALSE;
185 static GLenum activetmu = GL_TEXTURE0;
186 static GLenum clientactivetmu = GL_TEXTURE0;
188 #if defined( __MULTITEXTURE_SUPPORT__ )
189 GLboolean useMultiTexCoordArray = GL_FALSE;
190 #endif
192 #if !defined( __WINS__ )
193 //#define __FORCEINLINE __forceinline
194 #define __FORCEINLINE inline
195 #else
196 #define __FORCEINLINE
197 #endif
199 static GLboolean delayedttmuchange = GL_FALSE;
200 static GLenum delayedtmutarget = GL_TEXTURE0;
202 struct VertexAttrib
204 float x;
205 float y;
206 float z;
207 #if !defined( __MULTITEXTURE_SUPPORT__ )
208 float padding;
209 #endif
210 unsigned char red;
211 unsigned char green;
212 unsigned char blue;
213 unsigned char alpha;
215 float s;
216 float t;
217 #if defined( __MULTITEXTURE_SUPPORT__ )
218 float s_multi;
219 float t_multi;
220 #endif
221 };
223 static VertexAttrib vertexattribs[60000];
225 static GLushort indexArray[50000];
227 static GLuint vertexCount = 0;
228 static GLuint indexCount = 0;
229 static GLuint vertexMark = 0;
230 static int indexbase = 0;
232 static VertexAttrib *ptrVertexAttribArray = NULL;
233 static VertexAttrib *ptrVertexAttribArrayMark = NULL;
235 static VertexAttrib currentVertexAttrib;
236 #if defined( __MULTITEXTURE_SUPPORT__ )
237 static VertexAttrib currentVertexAttribInit = {0.0f, 0.0f, 0.0f, 255, 255, 255, 255, 0.0f, 0.0f, 0.0f, 0.0f};
238 #else
239 static VertexAttrib currentVertexAttribInit = {
240 0.0f, 0.0f, 0.0f, 0.0f, 255, 255, 255, 255, 0.0f, 0.0f,
241 };
242 #endif
243 static GLushort *ptrIndexArray = NULL;
245 static GLboolean arraysValid = GL_FALSE;
247 void InitGLStructs( )
249 ptrVertexAttribArray = vertexattribs;
250 ptrVertexAttribArrayMark = ptrVertexAttribArray;
251 ptrIndexArray = indexArray;
253 memcpy( &nanoglState, &nanoglInitState, sizeof( struct nanoState ) );
254 memcpy( &tmuState0, &tmuInitState, sizeof( struct nanotmuState ) );
255 memcpy( &tmuState1, &tmuInitState, sizeof( struct nanotmuState ) );
256 memcpy( &currentVertexAttrib, &currentVertexAttribInit, sizeof( struct VertexAttrib ) );
258 activetmuState = &tmuState0;
259 wrapperPrimitiveMode = GL_QUADS;
260 useTexCoordArray = GL_FALSE;
261 activetmu = GL_TEXTURE0;
262 clientactivetmu = GL_TEXTURE0;
263 delayedttmuchange = GL_FALSE;
264 delayedtmutarget = GL_TEXTURE0;
265 vertexCount = 0;
266 indexCount = 0;
267 vertexMark = 0;
268 indexbase = 0;
269 arraysValid = GL_FALSE;
272 void ResetNanoState( )
275 if ( tmuState0.color_array.enabled )
277 glEsImpl->glEnableClientState( GL_COLOR_ARRAY );
279 else
281 glEsImpl->glDisableClientState( GL_COLOR_ARRAY );
284 if ( tmuState0.vertex_array.enabled )
286 glEsImpl->glEnableClientState( GL_VERTEX_ARRAY );
288 else
290 glEsImpl->glDisableClientState( GL_VERTEX_ARRAY );
293 if ( tmuState0.texture_coord_array.enabled )
295 glEsImpl->glEnableClientState( GL_TEXTURE_COORD_ARRAY );
297 else
299 glEsImpl->glDisableClientState( GL_TEXTURE_COORD_ARRAY );
302 if ( tmuState0.normal_array.enabled )
304 glEsImpl->glEnableClientState( GL_NORMAL_ARRAY );
306 else
308 glEsImpl->glDisableClientState( GL_NORMAL_ARRAY );
310 glEsImpl->glVertexPointer( tmuState0.vertex_array.size,
311 tmuState0.vertex_array.type,
312 tmuState0.vertex_array.stride,
313 tmuState0.vertex_array.ptr );
315 glEsImpl->glTexCoordPointer( tmuState0.texture_coord_array.size,
316 tmuState0.texture_coord_array.type,
317 tmuState0.texture_coord_array.stride,
318 tmuState0.texture_coord_array.ptr );
320 glEsImpl->glColorPointer( tmuState0.color_array.size,
321 tmuState0.color_array.type,
322 tmuState0.color_array.stride,
323 tmuState0.color_array.ptr );
325 glEsImpl->glNormalPointer(
326 tmuState0.normal_array.type,
327 tmuState0.normal_array.stride,
328 tmuState0.normal_array.ptr );
330 glEsImpl->glMatrixMode( nanoglState.matrixmode );
332 glEsImpl->glColor4f( currentVertexAttrib.red, currentVertexAttrib.green, currentVertexAttrib.blue, currentVertexAttrib.alpha );
334 glEsImpl->glBlendFunc( nanoglState.sfactor, nanoglState.dfactor );
336 //glEsImpl->glBindTexture(GL_TEXTURE_2D, stackTextureState);
338 glEsImpl->glTexEnvi( GL_TEXTURE_ENV, GL_TEXTURE_ENV_MODE, activetmuState->texture_env_mode.value );
340 arraysValid = GL_FALSE;
343 void FlushOnStateChange( )
345 if ( delayedttmuchange )
347 delayedttmuchange = GL_FALSE;
348 #ifndef USE_CORE_PROFILE
349 glEsImpl->glActiveTexture( delayedtmutarget );
350 #endif
353 if ( !vertexCount )
354 return;
356 if ( !arraysValid )
358 glEsImpl->glClientActiveTexture( GL_TEXTURE0 );
359 glEsImpl->glVertexPointer( 3, GL_FLOAT, sizeof( VertexAttrib ), &vertexattribs[0].x );
360 glEsImpl->glColorPointer( 4, GL_UNSIGNED_BYTE, sizeof( VertexAttrib ), &vertexattribs[0].red );
361 glEsImpl->glTexCoordPointer( 2, GL_FLOAT, sizeof( VertexAttrib ), &vertexattribs[0].s );
362 glEsImpl->glEnableClientState( GL_VERTEX_ARRAY );
363 glEsImpl->glEnableClientState( GL_TEXTURE_COORD_ARRAY );
364 glEsImpl->glEnableClientState( GL_COLOR_ARRAY );
365 #if defined( __MULTITEXTURE_SUPPORT__ )
366 glEsImpl->glClientActiveTexture( GL_TEXTURE1 );
367 glEsImpl->glTexCoordPointer( 2, GL_FLOAT, sizeof( VertexAttrib ), &vertexattribs[0].s_multi );
368 glEsImpl->glEnableClientState( GL_TEXTURE_COORD_ARRAY );
369 glEsImpl->glClientActiveTexture( GL_TEXTURE0 );
370 #endif
371 arraysValid = GL_TRUE;
374 glEsImpl->glDrawElements( GL_TRIANGLES, vertexCount, GL_UNSIGNED_SHORT, indexArray );
376 #if defined( __MULTITEXTURE_SUPPORT__ )
377 useMultiTexCoordArray = GL_FALSE;
378 #endif
379 vertexCount = 0;
380 indexCount = 0;
381 ptrVertexAttribArray = vertexattribs;
382 ptrVertexAttribArrayMark = ptrVertexAttribArray;
383 ptrIndexArray = indexArray;
384 useTexCoordArray = GL_FALSE;
386 void nanoGL_Flush( )
388 FlushOnStateChange( );
390 void nanoGL_Reset( )
392 ResetNanoState( );
394 void glBegin( GLenum mode )
396 wrapperPrimitiveMode = mode;
397 vertexMark = vertexCount;
398 ptrVertexAttribArrayMark = ptrVertexAttribArray;
399 indexbase = indexCount;
402 void glEnd( void )
404 vertexCount += ( (unsigned char *)ptrVertexAttribArray - (unsigned char *)ptrVertexAttribArrayMark ) / sizeof( VertexAttrib );
405 if ( vertexCount < 3 )
407 return;
409 switch ( wrapperPrimitiveMode )
411 case GL_QUADS:
413 *ptrIndexArray++ = indexCount;
414 *ptrIndexArray++ = indexCount + 1;
415 *ptrIndexArray++ = indexCount + 2;
416 *ptrIndexArray++ = indexCount;
417 *ptrIndexArray++ = indexCount + 2;
418 *ptrIndexArray++ = indexCount + 3;
419 indexCount += 4;
420 vertexCount += 2;
422 break;
423 case GL_TRIANGLES:
425 int vcount = ( vertexCount - vertexMark ) / 3;
426 for ( int count = 0; count < vcount; count++ )
428 *ptrIndexArray++ = indexCount;
429 *ptrIndexArray++ = indexCount + 1;
430 *ptrIndexArray++ = indexCount + 2;
431 indexCount += 3;
434 break;
435 case GL_TRIANGLE_STRIP:
437 *ptrIndexArray++ = indexCount;
438 *ptrIndexArray++ = indexCount + 1;
439 *ptrIndexArray++ = indexCount + 2;
440 indexCount += 3;
441 int vcount = ( ( vertexCount - vertexMark ) - 3 );
442 if ( vcount && ( (long)ptrIndexArray & 0x02 ) )
444 *ptrIndexArray++ = indexCount - 1; // 2
445 *ptrIndexArray++ = indexCount - 2; // 1
446 *ptrIndexArray++ = indexCount; // 3
447 indexCount++;
448 vcount -= 1;
449 int odd = vcount & 1;
450 vcount /= 2;
451 unsigned int *longptr = (unsigned int *)ptrIndexArray;
453 for ( int count = 0; count < vcount; count++ )
455 *( longptr++ ) = ( indexCount - 2 ) | ( ( indexCount - 1 ) << 16 );
456 *( longptr++ ) = ( indexCount ) | ( ( indexCount ) << 16 );
457 *( longptr++ ) = ( indexCount - 1 ) | ( ( indexCount + 1 ) << 16 );
458 indexCount += 2;
460 ptrIndexArray = (unsigned short *)( longptr );
461 if ( odd )
463 *ptrIndexArray++ = indexCount - 2; // 2
464 *ptrIndexArray++ = indexCount - 1; // 1
465 *ptrIndexArray++ = indexCount; // 3
466 indexCount++;
469 else
471 //already aligned
472 int odd = vcount & 1;
473 vcount /= 2;
474 unsigned int *longptr = (unsigned int *)ptrIndexArray;
476 for ( int count = 0; count < vcount; count++ )
478 *( longptr++ ) = ( indexCount - 1 ) | ( ( indexCount - 2 ) << 16 );
479 *( longptr++ ) = ( indexCount ) | ( ( indexCount - 1 ) << 16 );
480 *( longptr++ ) = ( indexCount ) | ( ( indexCount + 1 ) << 16 );
481 indexCount += 2;
483 ptrIndexArray = (unsigned short *)( longptr );
484 if ( odd )
487 *ptrIndexArray++ = indexCount - 1; // 2
488 *ptrIndexArray++ = indexCount - 2; // 1
489 *ptrIndexArray++ = indexCount; // 3
490 indexCount++;
493 vertexCount += ( vertexCount - vertexMark - 3 ) * 2;
495 break;
496 case GL_POLYGON:
497 case GL_TRIANGLE_FAN:
499 *ptrIndexArray++ = indexCount++;
500 *ptrIndexArray++ = indexCount++;
501 *ptrIndexArray++ = indexCount++;
502 int vcount = ( ( vertexCount - vertexMark ) - 3 );
503 for ( int count = 0; count < vcount; count++ )
505 *ptrIndexArray++ = indexbase;
506 *ptrIndexArray++ = indexCount - 1;
507 *ptrIndexArray++ = indexCount++;
508 vertexCount += 2;
511 break;
513 default:
514 break;
516 if ( ptrVertexAttribArray - vertexattribs > 20000 * sizeof( VertexAttrib ) ||
517 ptrIndexArray - indexArray > 15000 * sizeof( GLushort ) )
518 FlushOnStateChange( );
521 void glEnable( GLenum cap )
523 GLboolean statechanged = GL_FALSE;
524 switch ( cap )
526 case GL_ALPHA_TEST:
528 if ( !nanoglState.alpha_test )
530 nanoglState.alpha_test = GL_TRUE;
531 statechanged = GL_TRUE;
533 break;
535 case GL_BLEND:
537 if ( !nanoglState.blend )
539 nanoglState.blend = GL_TRUE;
540 statechanged = GL_TRUE;
542 break;
544 //case GL_CLIP_PLANEi
545 case GL_COLOR_LOGIC_OP:
547 if ( !nanoglState.color_logic_op )
549 nanoglState.color_logic_op = GL_TRUE;
550 statechanged = GL_TRUE;
552 break;
554 case GL_COLOR_MATERIAL:
556 if ( !nanoglState.color_material )
558 nanoglState.color_material = GL_TRUE;
559 statechanged = GL_TRUE;
561 break;
563 case GL_CULL_FACE:
565 if ( !nanoglState.cull_face )
567 nanoglState.cull_face = GL_TRUE;
568 statechanged = GL_TRUE;
570 break;
572 case GL_DEPTH_TEST:
574 if ( !nanoglState.depth_test )
576 nanoglState.depth_test = GL_TRUE;
577 statechanged = GL_TRUE;
579 break;
581 case GL_DITHER:
583 if ( !nanoglState.dither )
585 nanoglState.dither = GL_TRUE;
586 statechanged = GL_TRUE;
588 break;
590 case GL_FOG:
592 if ( !nanoglState.fog )
594 nanoglState.fog = GL_TRUE;
595 statechanged = GL_TRUE;
597 break;
599 case GL_LIGHT0:
601 if ( !nanoglState.light0 )
603 nanoglState.light0 = GL_TRUE;
604 statechanged = GL_TRUE;
606 break;
608 case GL_LIGHT1:
610 if ( !nanoglState.light1 )
612 nanoglState.light1 = GL_TRUE;
613 statechanged = GL_TRUE;
615 break;
617 case GL_LIGHT2:
619 if ( !nanoglState.light2 )
621 nanoglState.light2 = GL_TRUE;
622 statechanged = GL_TRUE;
624 break;
626 case GL_LIGHT3:
628 if ( !nanoglState.light3 )
630 nanoglState.light3 = GL_TRUE;
631 statechanged = GL_TRUE;
633 break;
635 case GL_LIGHT4:
637 if ( !nanoglState.light4 )
639 nanoglState.light4 = GL_TRUE;
640 statechanged = GL_TRUE;
642 break;
644 case GL_LIGHT5:
646 if ( !nanoglState.light5 )
648 nanoglState.light5 = GL_TRUE;
649 statechanged = GL_TRUE;
651 break;
653 case GL_LIGHT6:
655 if ( !nanoglState.light6 )
657 nanoglState.light6 = GL_TRUE;
658 statechanged = GL_TRUE;
660 break;
662 case GL_LIGHT7:
664 if ( !nanoglState.light7 )
666 nanoglState.light7 = GL_TRUE;
667 statechanged = GL_TRUE;
669 break;
671 case GL_LIGHTING:
673 if ( !nanoglState.lighting )
675 nanoglState.lighting = GL_TRUE;
676 statechanged = GL_TRUE;
678 break;
680 case GL_LINE_SMOOTH:
682 if ( !nanoglState.line_smooth )
684 nanoglState.line_smooth = GL_TRUE;
685 statechanged = GL_TRUE;
687 break;
689 /* case GL_MATRIX_PALETTE_OES:
691 if (!nanoglState.matrix_palette_oes)
693 nanoglState.matrix_palette_oes = GL_TRUE;
694 statechanged = GL_TRUE;
696 break;
697 }*/
698 case GL_MULTISAMPLE:
700 if ( !nanoglState.multisample )
702 nanoglState.multisample = GL_TRUE;
703 statechanged = GL_TRUE;
705 break;
707 case GL_NORMALIZE:
709 if ( !nanoglState.normalize )
711 nanoglState.normalize = GL_TRUE;
712 statechanged = GL_TRUE;
714 break;
716 /* case GL_POINT_SPRITE_OES:
718 if (!nanoglState.point_sprite_oes)
720 nanoglState.point_sprite_oes = GL_TRUE;
721 statechanged = GL_TRUE;
723 break;
724 }*/
725 case GL_POLYGON_OFFSET_FILL:
727 if ( !nanoglState.polygon_offset_fill )
729 nanoglState.polygon_offset_fill = GL_TRUE;
730 statechanged = GL_TRUE;
732 break;
734 case GL_RESCALE_NORMAL:
736 if ( !nanoglState.rescale_normal )
738 nanoglState.rescale_normal = GL_TRUE;
739 statechanged = GL_TRUE;
741 break;
743 case GL_SAMPLE_ALPHA_TO_COVERAGE:
745 if ( !nanoglState.sample_alpha_to_coverage )
747 nanoglState.sample_alpha_to_coverage = GL_TRUE;
748 statechanged = GL_TRUE;
750 break;
752 case GL_SAMPLE_ALPHA_TO_ONE:
754 if ( !nanoglState.sample_alpha_to_one )
756 nanoglState.sample_alpha_to_one = GL_TRUE;
757 statechanged = GL_TRUE;
759 break;
761 case GL_SAMPLE_COVERAGE:
763 if ( !nanoglState.sample_coverage )
765 nanoglState.sample_coverage = GL_TRUE;
766 statechanged = GL_TRUE;
768 break;
770 case GL_SCISSOR_TEST:
772 if ( !nanoglState.scissor_test )
774 nanoglState.scissor_test = GL_TRUE;
775 statechanged = GL_TRUE;
777 break;
779 case GL_STENCIL_TEST:
781 return;
782 /* if (!nanoglState.stencil_test)
784 nanoglState.stencil_test = GL_TRUE;
785 statechanged = GL_TRUE;
786 }*/
787 break;
789 case GL_TEXTURE_2D:
791 if ( !activetmuState->texture_2d.value )
793 FlushOnStateChange( );
794 glEsImpl->glEnable( cap );
795 activetmuState->texture_2d.value = GL_TRUE;
796 return;
798 break;
800 default:
801 break;
804 if ( statechanged )
806 FlushOnStateChange( );
807 glEsImpl->glEnable( cap );
811 void glDisable( GLenum cap )
813 GLboolean statechanged = GL_FALSE;
814 switch ( cap )
816 case GL_ALPHA_TEST:
818 if ( nanoglState.alpha_test )
820 nanoglState.alpha_test = GL_FALSE;
821 statechanged = GL_TRUE;
823 break;
825 case GL_BLEND:
827 if ( nanoglState.blend )
829 nanoglState.blend = GL_FALSE;
830 statechanged = GL_TRUE;
832 break;
834 //case GL_CLIP_PLANEi
835 case GL_COLOR_LOGIC_OP:
837 if ( nanoglState.color_logic_op )
839 nanoglState.color_logic_op = GL_FALSE;
840 statechanged = GL_TRUE;
842 break;
844 case GL_COLOR_MATERIAL:
846 if ( nanoglState.color_material )
848 nanoglState.color_material = GL_FALSE;
849 statechanged = GL_TRUE;
851 break;
853 case GL_CULL_FACE:
855 if ( nanoglState.cull_face )
857 nanoglState.cull_face = GL_FALSE;
858 statechanged = GL_TRUE;
860 break;
862 case GL_DEPTH_TEST:
864 if ( nanoglState.depth_test )
866 nanoglState.depth_test = GL_FALSE;
867 statechanged = GL_TRUE;
869 break;
871 case GL_DITHER:
873 if ( nanoglState.dither )
875 nanoglState.dither = GL_FALSE;
876 statechanged = GL_TRUE;
878 break;
880 case GL_FOG:
882 if ( nanoglState.fog )
884 nanoglState.fog = GL_FALSE;
885 statechanged = GL_TRUE;
887 break;
889 case GL_LIGHT0:
891 if ( !nanoglState.light0 )
893 nanoglState.light0 = GL_FALSE;
894 statechanged = GL_TRUE;
896 break;
898 case GL_LIGHT1:
900 if ( !nanoglState.light1 )
902 nanoglState.light1 = GL_FALSE;
903 statechanged = GL_TRUE;
905 break;
907 case GL_LIGHT2:
909 if ( !nanoglState.light2 )
911 nanoglState.light2 = GL_FALSE;
912 statechanged = GL_TRUE;
914 break;
916 case GL_LIGHT3:
918 if ( !nanoglState.light3 )
920 nanoglState.light3 = GL_FALSE;
921 statechanged = GL_TRUE;
923 break;
925 case GL_LIGHT4:
927 if ( !nanoglState.light4 )
929 nanoglState.light4 = GL_FALSE;
930 statechanged = GL_TRUE;
932 break;
934 case GL_LIGHT5:
936 if ( !nanoglState.light5 )
938 nanoglState.light5 = GL_FALSE;
939 statechanged = GL_TRUE;
941 break;
943 case GL_LIGHT6:
945 if ( !nanoglState.light6 )
947 nanoglState.light6 = GL_FALSE;
948 statechanged = GL_TRUE;
950 break;
952 case GL_LIGHT7:
954 if ( !nanoglState.light7 )
956 nanoglState.light7 = GL_FALSE;
957 statechanged = GL_TRUE;
959 break;
961 case GL_LIGHTING:
963 if ( nanoglState.lighting )
965 nanoglState.lighting = GL_FALSE;
966 statechanged = GL_TRUE;
968 break;
970 case GL_LINE_SMOOTH:
972 if ( nanoglState.line_smooth )
974 nanoglState.line_smooth = GL_FALSE;
975 statechanged = GL_TRUE;
977 break;
979 /* case GL_MATRIX_PALETTE_OES:
981 if (nanoglState.matrix_palette_oes)
983 nanoglState.matrix_palette_oes = GL_FALSE;
984 statechanged = GL_TRUE;
986 break;
987 }*/
988 case GL_MULTISAMPLE:
990 if ( nanoglState.multisample )
992 nanoglState.multisample = GL_FALSE;
993 statechanged = GL_TRUE;
995 break;
997 case GL_NORMALIZE:
999 if ( nanoglState.normalize )
1001 nanoglState.normalize = GL_FALSE;
1002 statechanged = GL_TRUE;
1004 break;
1006 /* case GL_POINT_SPRITE_OES:
1008 if (nanoglState.point_sprite_oes)
1010 nanoglState.point_sprite_oes = GL_FALSE;
1011 statechanged = GL_TRUE;
1013 break;
1014 }*/
1015 case GL_POLYGON_OFFSET_FILL:
1017 if ( nanoglState.polygon_offset_fill )
1019 nanoglState.polygon_offset_fill = GL_FALSE;
1020 statechanged = GL_TRUE;
1022 break;
1024 case GL_RESCALE_NORMAL:
1026 if ( nanoglState.rescale_normal )
1028 nanoglState.rescale_normal = GL_FALSE;
1029 statechanged = GL_TRUE;
1031 break;
1033 case GL_SAMPLE_ALPHA_TO_COVERAGE:
1035 if ( nanoglState.sample_alpha_to_coverage )
1037 nanoglState.sample_alpha_to_coverage = GL_FALSE;
1038 statechanged = GL_TRUE;
1040 break;
1042 case GL_SAMPLE_ALPHA_TO_ONE:
1044 if ( nanoglState.sample_alpha_to_one )
1046 nanoglState.sample_alpha_to_one = GL_FALSE;
1047 statechanged = GL_TRUE;
1049 break;
1051 case GL_SAMPLE_COVERAGE:
1053 if ( nanoglState.sample_coverage )
1055 nanoglState.sample_coverage = GL_FALSE;
1056 statechanged = GL_TRUE;
1058 break;
1060 case GL_SCISSOR_TEST:
1062 if ( nanoglState.scissor_test )
1064 nanoglState.scissor_test = GL_FALSE;
1065 statechanged = GL_TRUE;
1067 break;
1069 case GL_STENCIL_TEST:
1071 return;
1072 /* if (nanoglState.stencil_test)
1074 nanoglState.stencil_test = GL_FALSE;
1075 statechanged = GL_TRUE;
1076 }*/
1077 break;
1079 case GL_TEXTURE_2D:
1081 if ( activetmuState->texture_2d.value )
1083 FlushOnStateChange( );
1084 glEsImpl->glDisable( cap );
1085 activetmuState->texture_2d.value = GL_FALSE;
1086 return;
1088 break;
1090 default:
1091 break;
1094 if ( statechanged )
1096 FlushOnStateChange( );
1097 glEsImpl->glDisable( cap );
1101 void glVertex2f( GLfloat x, GLfloat y )
1103 glVertex3f( x, y, 0.0f );
1106 __FORCEINLINE unsigned int ClampTo255( float value )
1108 unsigned int retval = (unsigned int)( value );
1109 if ( retval > 255 )
1111 retval = 255;
1113 return retval;
1116 void glColor3f( GLfloat red, GLfloat green, GLfloat blue )
1118 currentVertexAttrib.red = (unsigned char)ClampTo255( red * 255.0f );
1119 currentVertexAttrib.green = (unsigned char)ClampTo255( green * 255.0f );
1120 currentVertexAttrib.blue = (unsigned char)ClampTo255( blue * 255.0f );
1121 currentVertexAttrib.alpha = 255;
1124 void glTexCoord2fv( const GLfloat *v )
1126 memcpy( &currentVertexAttrib.s, v, 2 * sizeof( float ) );
1129 void glTexCoord2f( GLfloat s, GLfloat t )
1131 currentVertexAttrib.s = s;
1132 currentVertexAttrib.t = t;
1135 void glViewport( GLint x, GLint y, GLsizei width, GLsizei height )
1137 FlushOnStateChange( );
1138 glEsImpl->glViewport( x, y, width, height );
1141 void glLoadIdentity( void )
1143 FlushOnStateChange( );
1144 glEsImpl->glLoadIdentity( );
1147 void glColor4f( GLfloat red, GLfloat green, GLfloat blue, GLfloat alpha )
1149 currentVertexAttrib.red = (unsigned char)ClampTo255( red * 255.0f );
1150 currentVertexAttrib.green = (unsigned char)ClampTo255( green * 255.0f );
1151 currentVertexAttrib.blue = (unsigned char)ClampTo255( blue * 255.0f );
1152 currentVertexAttrib.alpha = (unsigned char)ClampTo255( alpha * 255.0f );
1155 void glOrtho( GLfloat left, GLfloat right, GLfloat bottom, GLfloat top, GLfloat zNear, GLfloat zFar )
1157 FlushOnStateChange( );
1158 #ifdef USE_CORE_PROFILE
1159 glEsImpl->glOrtho( left, right, bottom, top, zNear, zFar );
1160 #else
1161 glEsImpl->glOrthof( left, right, bottom, top, zNear, zFar );
1162 #endif
1165 // Rikku2000: Light
1166 void glLightf( GLenum light, GLenum pname, GLfloat param )
1168 FlushOnStateChange( );
1170 glEsImpl->glLightf( light, pname, param );
1172 void glLightfv( GLenum light, GLenum pname, const GLfloat *params )
1174 FlushOnStateChange( );
1176 glEsImpl->glLightfv( light, pname, params );
1178 void glLightModelf( GLenum pname, GLfloat param )
1180 FlushOnStateChange( );
1182 glEsImpl->glLightModelf( pname, param );
1184 void glLightModelfv( GLenum pname, const GLfloat *params )
1186 FlushOnStateChange( );
1188 glEsImpl->glLightModelfv( pname, params );
1190 void glMaterialf( GLenum face, GLenum pname, GLfloat param )
1192 FlushOnStateChange( );
1194 glEsImpl->glMaterialf( face, pname, param );
1196 void glMaterialfv( GLenum face, GLenum pname, const GLfloat *params )
1198 FlushOnStateChange( );
1200 glEsImpl->glMaterialfv( face, pname, params );
1202 void glColorMaterial( GLenum face, GLenum mode )
1204 FlushOnStateChange( );
1206 glEsImpl->glColorMaterial( face, mode );
1209 void glMatrixMode( GLenum mode )
1211 if ( nanoglState.matrixmode == mode )
1213 return;
1215 nanoglState.matrixmode = mode;
1216 FlushOnStateChange( );
1217 glEsImpl->glMatrixMode( mode );
1220 void glTexParameterf( GLenum target, GLenum pname, GLfloat param )
1222 if ( pname == GL_TEXTURE_BORDER_COLOR )
1224 return; // not supported by opengl es
1226 if ( ( pname == GL_TEXTURE_WRAP_S ||
1227 pname == GL_TEXTURE_WRAP_T ) &&
1228 param == GL_CLAMP )
1230 param = 0x812F;
1233 FlushOnStateChange( );
1234 glEsImpl->glTexParameterf( target, pname, param );
1237 void glTexParameterfv( GLenum target, GLenum pname, const GLfloat *params )
1239 glTexParameterf( target, pname, params[0] );
1242 void glTexImage2D( GLenum target, GLint level, GLint internalformat, GLsizei width, GLsizei height, GLint border, GLenum format, GLenum type, const GLvoid *pixels )
1244 FlushOnStateChange( );
1245 internalformat = format;
1246 glEsImpl->glTexImage2D( target, level, internalformat, width, height, border, format, type, pixels );
1249 void glDrawBuffer( GLenum /*mode*/ )
1253 void glTranslatef( GLfloat x, GLfloat y, GLfloat z )
1255 FlushOnStateChange( );
1256 glEsImpl->glTranslatef( x, y, z );
1259 void glRotatef( GLfloat angle, GLfloat x, GLfloat y, GLfloat z )
1261 FlushOnStateChange( );
1262 glEsImpl->glRotatef( angle, x, y, z );
1265 void glScalef( GLfloat x, GLfloat y, GLfloat z )
1267 FlushOnStateChange( );
1268 glEsImpl->glScalef( x, y, z );
1271 void glDepthRange( GLclampf zNear, GLclampf zFar )
1273 if ( ( nanoglState.depth_range_near == zNear ) && ( nanoglState.depth_range_far == zFar ) )
1275 return;
1277 else
1279 nanoglState.depth_range_near = zNear;
1280 nanoglState.depth_range_far = zFar;
1282 FlushOnStateChange( );
1283 #ifdef USE_CORE_PROFILE
1284 glEsImpl->glDepthRange( zNear, zFar );
1285 #else
1286 glEsImpl->glDepthRangef( zNear, zFar );
1287 #endif
1290 void glDepthFunc( GLenum func )
1292 if ( nanoglState.depth_func == func )
1294 return;
1296 else
1298 nanoglState.depth_func = func;
1300 FlushOnStateChange( );
1301 glEsImpl->glDepthFunc( func );
1304 void glFinish( void )
1306 FlushOnStateChange( );
1307 glEsImpl->glFinish( );
1310 void glGetFloatv( GLenum pname, GLfloat *params )
1312 FlushOnStateChange( );
1313 glEsImpl->glGetFloatv( pname, params );
1316 void glCullFace( GLenum mode )
1318 if ( nanoglState.cullface == mode )
1320 return;
1322 else
1324 nanoglState.cullface = mode;
1326 FlushOnStateChange( );
1327 glEsImpl->glCullFace( mode );
1330 void glFrustum( GLfloat left, GLfloat right, GLfloat bottom, GLfloat top, GLfloat zNear, GLfloat zFar )
1332 FlushOnStateChange( );
1333 glEsImpl->glFrustumf( left, right, bottom, top, zNear, zFar );
1336 void glClear( GLbitfield mask )
1338 FlushOnStateChange( );
1339 glEsImpl->glClear( mask );
1342 void glVertex3f( GLfloat x, GLfloat y, GLfloat z )
1344 GLfloat *vert = (GLfloat *)ptrVertexAttribArray++;
1345 *vert++ = x;
1346 *vert++ = y;
1347 *vert++ = z;
1348 #if defined( __MULTITEXTURE_SUPPORT__ )
1349 memcpy( vert, &currentVertexAttrib.red, 5 * sizeof( GLfloat ) );
1350 #else
1351 memcpy( vert + 1, &currentVertexAttrib.red, 3 * sizeof( GLfloat ) );
1352 #endif
1355 void glColor4fv( const GLfloat *v )
1357 currentVertexAttrib.red = (unsigned char)ClampTo255( v[0] * 255.0f );
1358 currentVertexAttrib.green = (unsigned char)ClampTo255( v[1] * 255.0f );
1359 currentVertexAttrib.blue = (unsigned char)ClampTo255( v[2] * 255.0f );
1360 currentVertexAttrib.alpha = (unsigned char)ClampTo255( v[3] * 255.0f );
1363 void glColor3ubv( const GLubyte *v )
1365 currentVertexAttrib.red = v[0];
1366 currentVertexAttrib.green = v[1];
1367 currentVertexAttrib.blue = v[2];
1368 currentVertexAttrib.alpha = 255;
1371 void glColor4ubv( const GLubyte *v )
1373 //*((unsigned int*)(&currentVertexAttrib.red)) = *((unsigned int*)(v));
1374 currentVertexAttrib.red = v[0];
1375 currentVertexAttrib.green = v[1];
1376 currentVertexAttrib.blue = v[2];
1377 currentVertexAttrib.alpha = v[3];
1380 void glColor3fv( const GLfloat *v )
1382 currentVertexAttrib.red = (unsigned char)ClampTo255( v[0] * 255.0f );
1383 currentVertexAttrib.green = (unsigned char)ClampTo255( v[1] * 255.0f );
1384 currentVertexAttrib.blue = (unsigned char)ClampTo255( v[2] * 255.0f );
1385 currentVertexAttrib.alpha = 255;
1388 //-- nicknekit: xash3d funcs --
1390 void glColor4ub( GLubyte red, GLubyte green, GLubyte blue, GLubyte alpha )
1392 currentVertexAttrib.red = red;
1393 currentVertexAttrib.green = green;
1394 currentVertexAttrib.blue = blue;
1395 currentVertexAttrib.alpha = alpha;
1398 void glColor3ub( GLubyte red, GLubyte green, GLubyte blue )
1400 currentVertexAttrib.red = red;
1401 currentVertexAttrib.green = green;
1402 currentVertexAttrib.blue = blue;
1403 currentVertexAttrib.alpha = 255;
1406 void glNormal3fv( const GLfloat *v )
1408 FlushOnStateChange( );
1409 glEsImpl->glNormal3f( v[0], v[1], v[2] );
1412 void glCopyTexImage2D( GLenum target, GLint level, GLenum internalformat, GLint x, GLint y, GLsizei width, GLsizei height, GLint border )
1414 FlushOnStateChange( );
1415 glEsImpl->glCopyTexImage2D( target, level, internalformat, x, y, width, height, border );
1418 void glTexImage1D( GLenum target, GLint level, GLint internalformat, GLsizei width, GLint border, GLenum format, GLenum type, const GLvoid *pixels )
1420 glTexImage2D( GL_TEXTURE_2D, level, internalformat, width, 1, border, format, type, pixels );
1423 void glTexImage3D( GLenum target, GLint level, GLint internalformat, GLsizei width, GLsizei height, GLsizei depth, GLint border, GLenum format, GLenum type, const GLvoid *pixels )
1425 glTexImage2D( GL_TEXTURE_2D, level, internalformat, width, height, border, format, type, pixels );
1428 void glTexSubImage1D( GLenum target, GLint level, GLint xoffset, GLsizei width, GLenum format, GLenum type, const GLvoid *pixels )
1430 glTexSubImage2D( target, level, xoffset, 0, width, 1, format, type, pixels );
1433 void glTexSubImage3D( GLenum target, GLint level,
1434 GLint xoffset, GLint yoffset,
1435 GLint zoffset, GLsizei width,
1436 GLsizei height, GLsizei depth,
1437 GLenum format,
1438 GLenum type, const GLvoid *pixels )
1440 glTexSubImage2D( target, level, xoffset, yoffset, width, height, format, type, pixels );
1443 GLboolean glIsTexture( GLuint texture )
1445 FlushOnStateChange( );
1446 return glEsImpl->glIsTexture( texture );
1449 void glTexGeni( GLenum coord, GLenum pname, GLint param )
1451 //for mirrors? not needed for original hl?
1454 void glTexGenfv( GLenum coord, GLenum pname, const GLfloat *params )
1456 //for mirrors? not needed for original hl?
1459 //-- --//
1461 void glHint( GLenum target, GLenum mode )
1463 FlushOnStateChange( );
1464 glEsImpl->glHint( target, mode );
1467 void glBlendFunc( GLenum sfactor, GLenum dfactor )
1469 if ( ( nanoglState.sfactor == sfactor ) && ( nanoglState.dfactor == dfactor ) )
1471 return;
1473 nanoglState.sfactor = sfactor;
1474 nanoglState.dfactor = dfactor;
1475 FlushOnStateChange( );
1476 glEsImpl->glBlendFunc( sfactor, dfactor );
1479 void glPopMatrix( void )
1481 FlushOnStateChange( );
1482 glEsImpl->glPopMatrix( );
1485 void glShadeModel( GLenum mode )
1487 if ( nanoglState.shademodel == mode )
1489 return;
1491 nanoglState.shademodel = mode;
1492 FlushOnStateChange( );
1493 glEsImpl->glShadeModel( mode );
1496 void glPushMatrix( void )
1498 FlushOnStateChange( );
1499 glEsImpl->glPushMatrix( );
1502 void glTexEnvf( GLenum target, GLenum pname, GLfloat param )
1504 if ( target == GL_TEXTURE_ENV )
1506 if ( pname == GL_TEXTURE_ENV_MODE )
1508 if ( param == activetmuState->texture_env_mode.value )
1510 return;
1512 else
1514 FlushOnStateChange( );
1515 glEsImpl->glTexEnvf( target, pname, param );
1516 activetmuState->texture_env_mode.value = param;
1517 return;
1521 FlushOnStateChange( );
1522 glEsImpl->glTexEnvf( target, pname, param );
1525 void glVertex3fv( const GLfloat *v )
1527 GLfloat *vert = (GLfloat *)ptrVertexAttribArray++;
1528 memcpy( vert, v, 3 * sizeof( GLfloat ) );
1529 #if defined( __MULTITEXTURE_SUPPORT__ )
1530 memcpy( vert + 3, &currentVertexAttrib.red, 5 * sizeof( GLfloat ) );
1531 #else
1532 memcpy( vert + 4, &currentVertexAttrib.red, 3 * sizeof( GLfloat ) );
1533 #endif
1536 void glDepthMask( GLboolean flag )
1538 if ( nanoglState.depthmask == flag )
1540 return;
1542 nanoglState.depthmask = flag;
1543 FlushOnStateChange( );
1544 glEsImpl->glDepthMask( flag );
1547 void glBindTexture( GLenum target, GLuint texture )
1549 if ( activetmuState->boundtexture.value == texture )
1551 return;
1553 FlushOnStateChange( );
1554 activetmuState->boundtexture.value = texture;
1555 glEsImpl->glBindTexture( target, texture );
1558 void glGetIntegerv( GLenum pname, GLint *params )
1560 FlushOnStateChange( );
1561 glEsImpl->glGetIntegerv( pname, params );
1564 GLubyte nano_extensions_string[4096];
1565 const GLubyte *glGetString( GLenum name )
1568 if ( name == GL_EXTENSIONS )
1570 #if defined( __MULTITEXTURE_SUPPORT__ )
1571 sprintf( (char *)nano_extensions_string, "%s %s", glEsImpl->glGetString( name ), "GL_ARB_multitexture EXT_texture_env_add" );
1572 #else
1573 sprintf( (char *)nano_extensions_string, "%s %s", glEsImpl->glGetString( name ), "EXT_texture_env_add" );
1574 #endif
1575 return nano_extensions_string;
1577 return glEsImpl->glGetString( name );
1580 void glAlphaFunc( GLenum func, GLclampf ref )
1582 FlushOnStateChange( );
1583 glEsImpl->glAlphaFunc( func, ref );
1586 void glFlush( void )
1588 FlushOnStateChange( );
1589 glEsImpl->glFlush( );
1592 void glReadPixels( GLint x, GLint y, GLsizei width, GLsizei height, GLenum format, GLenum type, GLvoid *pixels )
1594 if ( format == GL_DEPTH_COMPONENT )
1596 // OpenglEs 1.1 does not support reading depth buffer without an extension
1597 memset( pixels, 0xff, 4 );
1598 return;
1600 FlushOnStateChange( );
1601 glEsImpl->glReadPixels( x, y, width, height, format, type, pixels );
1604 void glReadBuffer( GLenum /*mode*/ )
1608 void glLoadMatrixf( const GLfloat *m )
1610 FlushOnStateChange( );
1611 glEsImpl->glLoadMatrixf( m );
1614 void glTexSubImage2D( GLenum target, GLint level, GLint xoffset, GLint yoffset, GLsizei width, GLsizei height, GLenum format, GLenum type, const GLvoid *pixels )
1616 FlushOnStateChange( );
1617 glEsImpl->glTexSubImage2D( target, level, xoffset, yoffset, width, height, format, type, pixels );
1620 void glClearColor( GLclampf red, GLclampf green, GLclampf blue, GLclampf alpha )
1622 FlushOnStateChange( );
1623 glEsImpl->glClearColor( red, green, blue, alpha );
1626 GLenum glGetError( void )
1628 //FlushOnStateChange();
1629 return GL_NO_ERROR; //glEsImpl->glGetError();
1632 void glActiveTexture( GLenum texture )
1634 if ( activetmu == texture )
1636 return;
1638 if ( delayedttmuchange )
1640 delayedttmuchange = GL_FALSE;
1642 else
1644 delayedttmuchange = GL_TRUE;
1645 delayedtmutarget = texture;
1647 if ( texture == GL_TEXTURE0 )
1649 activetmuState = &tmuState0;
1651 else
1653 activetmuState = &tmuState1;
1655 activetmu = texture;
1658 void glClientActiveTexture( GLenum texture )
1660 clientactivetmu = texture;
1663 void glPolygonMode( GLenum face, GLenum mode )
1667 void glDeleteTextures( GLsizei n, const GLuint *textures )
1669 FlushOnStateChange( );
1670 glEsImpl->glDeleteTextures( n, textures );
1673 void glClearDepth( GLclampf depth )
1675 FlushOnStateChange( );
1676 glEsImpl->glClearDepthf( depth );
1679 void glClipPlane( GLenum plane, const GLdouble *equation )
1681 FlushOnStateChange( );
1682 float array[4];
1683 array[0] = ( GLfloat )( equation[0] );
1684 array[1] = ( GLfloat )( equation[1] );
1685 array[2] = ( GLfloat )( equation[2] );
1686 array[3] = ( GLfloat )( equation[3] );
1687 glEsImpl->glClipPlanef( plane, array );
1690 void glScissor( GLint x, GLint y, GLsizei width, GLsizei height )
1692 FlushOnStateChange( );
1693 glEsImpl->glScissor( x, y, width, height );
1696 void glPointSize( GLfloat size )
1698 FlushOnStateChange( );
1699 glEsImpl->glPointSize( size );
1702 void glArrayElement( GLint i )
1705 void glLineWidth( GLfloat width )
1708 void glCallList( GLuint list )
1711 void glColorMask( GLboolean red, GLboolean green, GLboolean blue, GLboolean alpha )
1714 void glStencilFunc( GLenum func, GLint ref, GLuint mask )
1717 void glStencilOp( GLenum fail, GLenum zfail, GLenum zpass )
1721 struct ptrstate vertex_array;
1722 struct ptrstate color_array;
1723 struct ptrstate texture_coord_array;
1725 void glDrawElements( GLenum mode, GLsizei count, GLenum type, const GLvoid *indices )
1727 // ensure that all primitives specified between glBegin/glEnd pairs
1728 // are rendered first, and that we have correct tmu in use..
1729 FlushOnStateChange( );
1730 // setup correct vertex/color/texcoord pointers
1731 if ( arraysValid ||
1732 tmuState0.vertex_array.changed ||
1733 tmuState0.color_array.changed ||
1734 tmuState0.texture_coord_array.changed || tmuState0.normal_array.changed )
1736 glEsImpl->glClientActiveTexture( GL_TEXTURE0 );
1738 if ( arraysValid || tmuState0.vertex_array.changed )
1740 if ( tmuState0.vertex_array.enabled )
1742 glEsImpl->glEnableClientState( GL_VERTEX_ARRAY );
1744 else
1746 glEsImpl->glDisableClientState( GL_VERTEX_ARRAY );
1748 glEsImpl->glVertexPointer( tmuState0.vertex_array.size,
1749 tmuState0.vertex_array.type,
1750 tmuState0.vertex_array.stride,
1751 tmuState0.vertex_array.ptr );
1752 tmuState0.vertex_array.changed = GL_FALSE;
1754 if ( arraysValid || tmuState0.color_array.changed )
1756 if ( tmuState0.color_array.enabled )
1758 glEsImpl->glEnableClientState( GL_COLOR_ARRAY );
1760 else
1762 glEsImpl->glDisableClientState( GL_COLOR_ARRAY );
1764 glEsImpl->glColorPointer( tmuState0.color_array.size,
1765 tmuState0.color_array.type,
1766 tmuState0.color_array.stride,
1767 tmuState0.color_array.ptr );
1768 tmuState0.color_array.changed = GL_FALSE;
1770 if ( arraysValid || tmuState0.normal_array.changed )
1772 if ( tmuState0.normal_array.enabled )
1774 glEsImpl->glEnableClientState( GL_NORMAL_ARRAY );
1776 else
1778 glEsImpl->glDisableClientState( GL_NORMAL_ARRAY );
1780 glEsImpl->glNormalPointer( tmuState0.normal_array.type,
1781 tmuState0.normal_array.stride,
1782 tmuState0.normal_array.ptr );
1783 tmuState0.normal_array.changed = GL_FALSE;
1785 if ( arraysValid || tmuState0.texture_coord_array.changed )
1787 tmuState0.texture_coord_array.changed = GL_FALSE;
1788 if ( tmuState0.texture_coord_array.enabled )
1790 glEsImpl->glEnableClientState( GL_TEXTURE_COORD_ARRAY );
1792 else
1794 glEsImpl->glDisableClientState( GL_TEXTURE_COORD_ARRAY );
1796 glEsImpl->glTexCoordPointer( tmuState0.texture_coord_array.size,
1797 tmuState0.texture_coord_array.type,
1798 tmuState0.texture_coord_array.stride,
1799 tmuState0.texture_coord_array.ptr );
1802 if ( arraysValid || tmuState1.texture_coord_array.changed )
1804 tmuState1.texture_coord_array.changed = GL_FALSE;
1805 glEsImpl->glClientActiveTexture( GL_TEXTURE1 );
1806 if ( tmuState1.texture_coord_array.enabled )
1808 glEsImpl->glEnableClientState( GL_TEXTURE_COORD_ARRAY );
1810 else
1812 glEsImpl->glDisableClientState( GL_TEXTURE_COORD_ARRAY );
1814 glEsImpl->glTexCoordPointer( tmuState1.texture_coord_array.size,
1815 tmuState1.texture_coord_array.type,
1816 tmuState1.texture_coord_array.stride,
1817 tmuState1.texture_coord_array.ptr );
1820 arraysValid = GL_FALSE;
1821 glEsImpl->glDrawElements( mode, count, type, indices );
1824 void glEnableClientState( GLenum array )
1826 struct nanotmuState *clientstate = NULL;
1827 if ( clientactivetmu == GL_TEXTURE0 )
1829 clientstate = &tmuState0;
1831 else if ( clientactivetmu == GL_TEXTURE1 )
1833 clientstate = &tmuState1;
1835 else
1837 return;
1839 switch ( array )
1841 case GL_VERTEX_ARRAY:
1842 if ( clientstate->vertex_array.enabled )
1844 return;
1846 clientstate->vertex_array.enabled = GL_TRUE;
1847 clientstate->vertex_array.changed = GL_TRUE;
1848 break;
1849 case GL_COLOR_ARRAY:
1850 if ( clientstate->color_array.enabled )
1852 return;
1854 clientstate->color_array.enabled = GL_TRUE;
1855 clientstate->color_array.changed = GL_TRUE;
1857 break;
1858 case GL_NORMAL_ARRAY:
1859 if ( clientstate->normal_array.enabled )
1861 return;
1863 clientstate->normal_array.enabled = GL_TRUE;
1864 clientstate->normal_array.changed = GL_TRUE;
1866 break;
1867 case GL_TEXTURE_COORD_ARRAY:
1868 if ( clientstate->texture_coord_array.enabled )
1870 return;
1872 clientstate->texture_coord_array.enabled = GL_TRUE;
1873 clientstate->texture_coord_array.changed = GL_TRUE;
1874 break;
1875 default:
1876 break;
1879 void glDisableClientState( GLenum array )
1881 struct nanotmuState *clientstate = NULL;
1882 if ( clientactivetmu == GL_TEXTURE0 )
1884 clientstate = &tmuState0;
1886 else if ( clientactivetmu == GL_TEXTURE1 )
1888 clientstate = &tmuState1;
1890 else
1892 return;
1894 switch ( array )
1896 case GL_VERTEX_ARRAY:
1897 if ( !clientstate->vertex_array.enabled )
1899 return;
1901 clientstate->vertex_array.enabled = GL_FALSE;
1902 clientstate->vertex_array.changed = GL_TRUE;
1903 break;
1904 case GL_COLOR_ARRAY:
1905 if ( !clientstate->color_array.enabled )
1907 return;
1909 clientstate->color_array.enabled = GL_FALSE;
1910 clientstate->color_array.changed = GL_TRUE;
1912 break;
1913 case GL_NORMAL_ARRAY:
1914 if ( !clientstate->normal_array.enabled )
1916 return;
1918 clientstate->normal_array.enabled = GL_FALSE;
1919 clientstate->normal_array.changed = GL_TRUE;
1921 break;
1922 case GL_TEXTURE_COORD_ARRAY:
1923 if ( !clientstate->texture_coord_array.enabled )
1925 return;
1927 clientstate->texture_coord_array.enabled = GL_FALSE;
1928 clientstate->texture_coord_array.changed = GL_TRUE;
1929 break;
1930 default:
1931 break;
1934 void glVertexPointer( GLint size, GLenum type, GLsizei stride, const GLvoid *pointer )
1936 if ( tmuState0.vertex_array.size == size &&
1937 tmuState0.vertex_array.stride == stride &&
1938 tmuState0.vertex_array.type == type &&
1939 tmuState0.vertex_array.ptr == pointer )
1941 return;
1943 tmuState0.vertex_array.size = size;
1944 tmuState0.vertex_array.stride = stride;
1945 tmuState0.vertex_array.type = type;
1946 tmuState0.vertex_array.ptr = (GLvoid *)pointer;
1947 tmuState0.vertex_array.changed = GL_TRUE;
1949 void glTexCoordPointer( GLint size, GLenum type, GLsizei stride, const GLvoid *pointer )
1951 struct nanotmuState *clientstate = NULL;
1952 if ( clientactivetmu == GL_TEXTURE0 )
1954 clientstate = &tmuState0;
1956 else if ( clientactivetmu == GL_TEXTURE1 )
1958 clientstate = &tmuState1;
1960 if ( clientstate->texture_coord_array.size == size &&
1961 clientstate->texture_coord_array.stride == stride &&
1962 clientstate->texture_coord_array.type == type &&
1963 clientstate->texture_coord_array.ptr == pointer )
1965 return;
1967 clientstate->texture_coord_array.size = size;
1968 clientstate->texture_coord_array.stride = stride;
1969 clientstate->texture_coord_array.type = type;
1970 clientstate->texture_coord_array.ptr = (GLvoid *)pointer;
1971 clientstate->texture_coord_array.changed = GL_TRUE;
1973 void glColorPointer( GLint size, GLenum type, GLsizei stride, const GLvoid *pointer )
1975 if ( tmuState0.color_array.size == size &&
1976 tmuState0.color_array.stride == stride &&
1977 tmuState0.color_array.type == type &&
1978 tmuState0.color_array.ptr == pointer )
1980 return;
1982 tmuState0.color_array.size = size;
1983 tmuState0.color_array.stride = stride;
1984 tmuState0.color_array.type = type;
1985 tmuState0.color_array.ptr = (GLvoid *)pointer;
1986 tmuState0.color_array.changed = GL_TRUE;
1989 void glNormalPointer( GLenum type, GLsizei stride, const GLvoid *pointer )
1991 int size = 0;
1992 if ( tmuState0.normal_array.size == size &&
1993 tmuState0.normal_array.stride == stride &&
1994 tmuState0.normal_array.type == type &&
1995 tmuState0.normal_array.ptr == pointer )
1997 return;
1999 tmuState0.normal_array.size = size;
2000 tmuState0.normal_array.stride = stride;
2001 tmuState0.normal_array.type = type;
2002 tmuState0.normal_array.ptr = (GLvoid *)pointer;
2003 tmuState0.normal_array.changed = GL_TRUE;
2005 void glPolygonOffset( GLfloat factor, GLfloat units )
2007 FlushOnStateChange( );
2008 glEsImpl->glPolygonOffset( factor, units );
2010 void glStencilMask( GLuint mask )
2013 void glClearStencil( GLint s )
2017 #if defined( __MULTITEXTURE_SUPPORT__ )
2019 extern "C" void glMultiTexCoord2fARB( GLenum target, GLfloat s, GLfloat t );
2021 void glMultiTexCoord2fARB( GLenum target, GLfloat s, GLfloat t )
2023 if ( target == GL_TEXTURE0 )
2025 glTexCoord2f( s, t );
2027 else
2029 currentVertexAttrib.s_multi = s;
2030 currentVertexAttrib.t_multi = t;
2033 #endif
2035 /* Vladimir */
2036 /*void glDrawArrays( GLenum mode, int first, int count)
2038 FlushOnStateChange();
2039 glEsImpl->glDrawArrays(mode, first , count);
2040 }*/
2041 void glMultMatrixf( const GLfloat *m )
2043 FlushOnStateChange( );
2044 glEsImpl->glMultMatrixf( m );
2047 void glPixelStorei( GLenum pname, GLint param )
2049 FlushOnStateChange( );
2050 glEsImpl->glPixelStorei( pname, param );
2053 void glFogf( GLenum pname, GLfloat param )
2055 FlushOnStateChange( );
2056 glEsImpl->glFogf( pname, param );
2059 void glFogfv( GLenum pname, const GLfloat *params )
2061 FlushOnStateChange( );
2062 glEsImpl->glFogfv( pname, params );
2065 void glGetTexParameteriv( GLenum target, GLenum pname, GLint *params )
2067 FlushOnStateChange( );
2068 glEsImpl->glGetTexParameteriv( target, pname, params );
2071 // This gives: called unimplemented OpenGL ES API (Android)
2072 void glTexParameteri( GLenum target, GLenum pname, GLint param )
2074 if ( pname == GL_TEXTURE_BORDER_COLOR )
2076 return; // not supported by opengl es
2078 if ( ( pname == GL_TEXTURE_WRAP_S ||
2079 pname == GL_TEXTURE_WRAP_T ) &&
2080 param == GL_CLAMP )
2082 param = 0x812F;
2085 FlushOnStateChange( );
2086 glEsImpl->glTexParameteri( target, pname, param );
2089 void glTexParameterx( GLenum target, GLenum pname, GLfixed param )
2091 if ( pname == GL_TEXTURE_BORDER_COLOR )
2093 return; // not supported by opengl es
2095 if ( ( pname == GL_TEXTURE_WRAP_S ||
2096 pname == GL_TEXTURE_WRAP_T ) &&
2097 param == GL_CLAMP )
2099 param = 0x812F;
2101 FlushOnStateChange( );
2102 glEsImpl->glTexParameterx( target, pname, param );
2105 void glGenTextures( GLsizei n, GLuint *textures )
2107 FlushOnStateChange( );
2108 glEsImpl->glGenTextures( n, textures );
2111 void glFrontFace( GLenum mode )
2113 FlushOnStateChange( );
2114 glEsImpl->glFrontFace( mode );
2116 // End Vladimir
2118 void glTexEnvi( GLenum target, GLenum pname, GLint param )
2120 if ( target == GL_TEXTURE_ENV )
2122 if ( pname == GL_TEXTURE_ENV_MODE )
2124 if ( param == activetmuState->texture_env_mode.value )
2126 return;
2128 else
2130 FlushOnStateChange( );
2131 glEsImpl->glTexEnvi( target, pname, param );
2132 activetmuState->texture_env_mode.value = param;
2133 return;
2137 FlushOnStateChange( );
2138 glEsImpl->glTexEnvi( target, pname, param );
2141 #ifdef __MULTITEXTURE_SUPPORT__
2142 void glMultiTexCoord3fARB( GLenum a, GLfloat b, GLfloat c, GLfloat )
2144 return glMultiTexCoord2fARB( a, b, c );
2147 void glMultiTexCoord2f( GLenum, GLfloat, GLfloat )
2150 #endif
2151 void glDrawArrays( GLenum mode, GLint first, GLsizei count )
2153 // ensure that all primitives specified between glBegin/glEnd pairs
2154 // are rendered first, and that we have correct tmu in use..
2155 if ( mode == GL_QUADS )
2156 mode = GL_TRIANGLE_FAN;
2157 FlushOnStateChange( );
2158 // setup correct vertex/color/texcoord pointers
2159 if ( arraysValid ||
2160 tmuState0.vertex_array.changed ||
2161 tmuState0.color_array.changed ||
2162 tmuState0.texture_coord_array.changed || tmuState0.normal_array.changed )
2164 glEsImpl->glClientActiveTexture( GL_TEXTURE0 );
2166 if ( arraysValid || tmuState0.vertex_array.changed )
2168 if ( tmuState0.vertex_array.enabled )
2170 glEsImpl->glEnableClientState( GL_VERTEX_ARRAY );
2172 else
2174 glEsImpl->glDisableClientState( GL_VERTEX_ARRAY );
2176 glEsImpl->glVertexPointer( tmuState0.vertex_array.size,
2177 tmuState0.vertex_array.type,
2178 tmuState0.vertex_array.stride,
2179 tmuState0.vertex_array.ptr );
2180 tmuState0.vertex_array.changed = GL_FALSE;
2182 if ( arraysValid || tmuState0.color_array.changed )
2184 if ( tmuState0.color_array.enabled )
2186 glEsImpl->glEnableClientState( GL_COLOR_ARRAY );
2188 else
2190 glEsImpl->glDisableClientState( GL_COLOR_ARRAY );
2192 glEsImpl->glColorPointer( tmuState0.color_array.size,
2193 tmuState0.color_array.type,
2194 tmuState0.color_array.stride,
2195 tmuState0.color_array.ptr );
2196 tmuState0.color_array.changed = GL_FALSE;
2198 if ( arraysValid || tmuState0.normal_array.changed )
2200 if ( tmuState0.normal_array.enabled )
2202 glEsImpl->glEnableClientState( GL_NORMAL_ARRAY );
2204 else
2206 glEsImpl->glDisableClientState( GL_NORMAL_ARRAY );
2208 glEsImpl->glNormalPointer( tmuState0.normal_array.type,
2209 tmuState0.normal_array.stride,
2210 tmuState0.normal_array.ptr );
2211 tmuState0.normal_array.changed = GL_FALSE;
2213 if ( arraysValid || tmuState0.texture_coord_array.changed )
2215 tmuState0.texture_coord_array.changed = GL_FALSE;
2216 if ( tmuState0.texture_coord_array.enabled )
2218 glEsImpl->glEnableClientState( GL_TEXTURE_COORD_ARRAY );
2220 else
2222 glEsImpl->glDisableClientState( GL_TEXTURE_COORD_ARRAY );
2224 glEsImpl->glTexCoordPointer( tmuState0.texture_coord_array.size,
2225 tmuState0.texture_coord_array.type,
2226 tmuState0.texture_coord_array.stride,
2227 tmuState0.texture_coord_array.ptr );
2230 if ( arraysValid || tmuState1.texture_coord_array.changed )
2232 tmuState1.texture_coord_array.changed = GL_FALSE;
2233 glEsImpl->glClientActiveTexture( GL_TEXTURE1 );
2234 if ( tmuState1.texture_coord_array.enabled )
2236 glEsImpl->glEnableClientState( GL_TEXTURE_COORD_ARRAY );
2238 else
2240 glEsImpl->glDisableClientState( GL_TEXTURE_COORD_ARRAY );
2242 glEsImpl->glTexCoordPointer( tmuState1.texture_coord_array.size,
2243 tmuState1.texture_coord_array.type,
2244 tmuState1.texture_coord_array.stride,
2245 tmuState1.texture_coord_array.ptr );
2248 arraysValid = GL_FALSE;
2249 glEsImpl->glDrawArrays( mode, first, count );
2251 /*void glNormalPointer(GLenum type, GLsizei stride, const void *ptr)
2253 glEsImpl->glNormalPointer( type, stride, ptr );
2254 }*/
2256 void glCopyTexSubImage2D( GLenum target, GLint level, GLint xoffset, GLint yoffset, GLint x, GLint y, GLsizei width, GLsizei height )
2258 FlushOnStateChange( );
2259 glEsImpl->glCopyTexSubImage2D( target, level, xoffset, yoffset, x, y, width, height );
2262 void glGenFramebuffers( GLsizei n, GLuint *framebuffers )
2264 FlushOnStateChange( );
2265 glEsImpl->glGenFramebuffers( n, framebuffers );
2268 void glGenRenderbuffers( GLsizei n, GLuint *renderbuffers )
2270 FlushOnStateChange( );
2271 glEsImpl->glGenRenderbuffers( n, renderbuffers );
2274 void glBindRenderbuffer( GLenum target, GLuint renderbuffer )
2276 FlushOnStateChange( );
2277 glEsImpl->glBindRenderbuffer( target, renderbuffer );
2280 void glBindFramebuffer( GLenum target, GLuint framebuffer )
2282 FlushOnStateChange( );
2283 glEsImpl->glBindFramebuffer( target, framebuffer );
2286 void glFramebufferRenderbuffer( GLenum target, GLenum attachment, GLenum renderbuffertarget, GLuint renderbuffer )
2288 FlushOnStateChange( );
2289 glEsImpl->glFramebufferRenderbuffer( target, attachment, renderbuffertarget, renderbuffer );
2292 void glDeleteFramebuffers( GLsizei n, const GLuint *framebuffers )
2294 FlushOnStateChange( );
2295 glEsImpl->glDeleteFramebuffers( n, framebuffers );
2298 void glDeleteRenderbuffers( GLsizei n, const GLuint *renderbuffers )
2300 FlushOnStateChange( );
2301 glEsImpl->glDeleteRenderbuffers( n, renderbuffers );
2303 void glFramebufferTexture2D( GLenum target, GLenum attachment, GLenum textarget, GLuint texture, GLint level )
2305 FlushOnStateChange( );
2306 glEsImpl->glFramebufferTexture2D( target, attachment, textarget, texture, level );
2309 void glRenderbufferStorage( GLenum target, GLenum internalformat, GLsizei width, GLsizei height )
2311 FlushOnStateChange( );
2312 glEsImpl->glRenderbufferStorage( target, internalformat, width, height );