DEADSOFTWARE

glIsEnabled uses interanl structures, added glPushAttrib/glPopAttrib (not fully imple...
[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 GLclampd depth_range_near;
71 GLclampd 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 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 static GLboolean skipnanogl;
249 #define STACK_ATTRIB_ENABLE_BIT_LEN (sizeof(stackAttribEnableBit) / sizeof(stackAttribEnableBit[0]))
250 static const GLenum stackAttribEnableBit[] =
252 GL_ALPHA_TEST,
253 GL_BLEND,
254 GL_CLIP_PLANE0,
255 GL_CLIP_PLANE1,
256 GL_CLIP_PLANE2,
257 GL_CLIP_PLANE3,
258 GL_CLIP_PLANE4,
259 GL_CLIP_PLANE5,
260 GL_COLOR_MATERIAL,
261 GL_CULL_FACE,
262 GL_DEPTH_TEST,
263 GL_DITHER,
264 GL_FOG,
265 GL_LIGHT0,
266 GL_LIGHT1,
267 GL_LIGHT2,
268 GL_LIGHT3,
269 GL_LIGHT4,
270 GL_LIGHT5,
271 GL_LIGHT6,
272 GL_LIGHT7,
273 GL_LIGHTING,
274 GL_LINE_SMOOTH,
275 GL_COLOR_LOGIC_OP,
276 GL_MULTISAMPLE,
277 GL_NORMALIZE,
278 GL_POINT_SMOOTH,
279 GL_POLYGON_OFFSET_LINE,
280 GL_POLYGON_OFFSET_FILL,
281 GL_POLYGON_OFFSET_POINT,
282 GL_POLYGON_SMOOTH,
283 GL_POLYGON_STIPPLE,
284 GL_SAMPLE_ALPHA_TO_COVERAGE,
285 GL_SAMPLE_ALPHA_TO_ONE,
286 GL_SAMPLE_COVERAGE,
287 GL_SCISSOR_TEST,
288 GL_STENCIL_TEST,
289 GL_TEXTURE_1D,
290 GL_TEXTURE_2D,
291 GL_TEXTURE_GEN_S,
292 GL_TEXTURE_GEN_T,
293 GL_TEXTURE_GEN_R,
294 GL_TEXTURE_GEN_Q,
295 };
297 #define MAX_ATTRIB_STACK 16
298 struct attribStore
300 GLbitfield mask;
301 GLboolean enable[STACK_ATTRIB_ENABLE_BIT_LEN];
302 };
304 static struct attribStore attribStack[MAX_ATTRIB_STACK];
305 static int attribStackCount = 0;
307 void InitGLStructs( )
309 ptrVertexAttribArray = vertexattribs;
310 ptrVertexAttribArrayMark = ptrVertexAttribArray;
311 ptrIndexArray = indexArray;
313 memcpy( &nanoglState, &nanoglInitState, sizeof( struct nanoState ) );
314 memcpy( &tmuState0, &tmuInitState, sizeof( struct nanotmuState ) );
315 memcpy( &tmuState1, &tmuInitState, sizeof( struct nanotmuState ) );
316 memcpy( &currentVertexAttrib, &currentVertexAttribInit, sizeof( struct VertexAttrib ) );
318 activetmuState = &tmuState0;
319 wrapperPrimitiveMode = GL_QUADS;
320 useTexCoordArray = GL_FALSE;
321 activetmu = GL_TEXTURE0;
322 clientactivetmu = GL_TEXTURE0;
323 delayedttmuchange = GL_FALSE;
324 delayedtmutarget = GL_TEXTURE0;
325 vertexCount = 0;
326 indexCount = 0;
327 vertexMark = 0;
328 indexbase = 0;
329 arraysValid = GL_FALSE;
331 memset(attribStack, 0, sizeof( struct attribStore ));
332 attribStackCount = 0;
335 void ResetNanoState( )
338 if ( tmuState0.color_array.enabled )
340 glEsImpl->glEnableClientState( GL_COLOR_ARRAY );
342 else
344 glEsImpl->glDisableClientState( GL_COLOR_ARRAY );
347 if ( tmuState0.vertex_array.enabled )
349 glEsImpl->glEnableClientState( GL_VERTEX_ARRAY );
351 else
353 glEsImpl->glDisableClientState( GL_VERTEX_ARRAY );
356 if ( tmuState0.texture_coord_array.enabled )
358 glEsImpl->glEnableClientState( GL_TEXTURE_COORD_ARRAY );
360 else
362 glEsImpl->glDisableClientState( GL_TEXTURE_COORD_ARRAY );
365 if ( tmuState0.normal_array.enabled )
367 glEsImpl->glEnableClientState( GL_NORMAL_ARRAY );
369 else
371 glEsImpl->glDisableClientState( GL_NORMAL_ARRAY );
373 glEsImpl->glVertexPointer( tmuState0.vertex_array.size,
374 tmuState0.vertex_array.type,
375 tmuState0.vertex_array.stride,
376 tmuState0.vertex_array.ptr );
378 glEsImpl->glTexCoordPointer( tmuState0.texture_coord_array.size,
379 tmuState0.texture_coord_array.type,
380 tmuState0.texture_coord_array.stride,
381 tmuState0.texture_coord_array.ptr );
383 glEsImpl->glColorPointer( tmuState0.color_array.size,
384 tmuState0.color_array.type,
385 tmuState0.color_array.stride,
386 tmuState0.color_array.ptr );
388 glEsImpl->glNormalPointer(
389 tmuState0.normal_array.type,
390 tmuState0.normal_array.stride,
391 tmuState0.normal_array.ptr );
393 glEsImpl->glMatrixMode( nanoglState.matrixmode );
395 glEsImpl->glColor4f( currentVertexAttrib.red/255.0f, currentVertexAttrib.green/255.0f,
396 currentVertexAttrib.blue/255.0f, currentVertexAttrib.alpha/255.0f );
398 glEsImpl->glBlendFunc( nanoglState.sfactor, nanoglState.dfactor );
400 //glEsImpl->glBindTexture(GL_TEXTURE_2D, stackTextureState);
402 glEsImpl->glTexEnvi( GL_TEXTURE_ENV, GL_TEXTURE_ENV_MODE, activetmuState->texture_env_mode.value );
404 arraysValid = GL_FALSE;
405 skipnanogl = GL_FALSE;
407 memset(attribStack, 0, sizeof( struct attribStore ));
408 attribStackCount = 0;
411 void FlushOnStateChange( )
413 if( skipnanogl )
414 return;
415 if ( delayedttmuchange )
417 delayedttmuchange = GL_FALSE;
418 #ifndef USE_CORE_PROFILE
419 glEsImpl->glActiveTexture( delayedtmutarget );
420 #endif
423 if ( !vertexCount )
424 return;
426 if ( !arraysValid )
428 glEsImpl->glClientActiveTexture( GL_TEXTURE0 );
429 glEsImpl->glVertexPointer( 3, GL_FLOAT, sizeof( VertexAttrib ), &vertexattribs[0].x );
430 glEsImpl->glColorPointer( 4, GL_UNSIGNED_BYTE, sizeof( VertexAttrib ), &vertexattribs[0].red );
431 glEsImpl->glTexCoordPointer( 2, GL_FLOAT, sizeof( VertexAttrib ), &vertexattribs[0].s );
432 glEsImpl->glEnableClientState( GL_VERTEX_ARRAY );
433 glEsImpl->glEnableClientState( GL_TEXTURE_COORD_ARRAY );
434 glEsImpl->glEnableClientState( GL_COLOR_ARRAY );
435 #if defined( __MULTITEXTURE_SUPPORT__ )
436 glEsImpl->glClientActiveTexture( GL_TEXTURE1 );
437 glEsImpl->glTexCoordPointer( 2, GL_FLOAT, sizeof( VertexAttrib ), &vertexattribs[0].s_multi );
438 glEsImpl->glEnableClientState( GL_TEXTURE_COORD_ARRAY );
439 glEsImpl->glClientActiveTexture( GL_TEXTURE0 );
440 #endif
441 arraysValid = GL_TRUE;
444 glEsImpl->glDrawElements( GL_TRIANGLES, vertexCount, GL_UNSIGNED_SHORT, indexArray );
446 #if defined( __MULTITEXTURE_SUPPORT__ )
447 useMultiTexCoordArray = GL_FALSE;
448 #endif
449 vertexCount = 0;
450 indexCount = 0;
451 ptrVertexAttribArray = vertexattribs;
452 ptrVertexAttribArrayMark = ptrVertexAttribArray;
453 ptrIndexArray = indexArray;
454 useTexCoordArray = GL_FALSE;
456 void nanoGL_Flush( )
458 FlushOnStateChange( );
460 void nanoGL_Reset( )
462 ResetNanoState( );
464 void glBegin( GLenum mode )
466 wrapperPrimitiveMode = mode;
467 vertexMark = vertexCount;
468 ptrVertexAttribArrayMark = ptrVertexAttribArray;
469 indexbase = indexCount;
472 void glEnd( void )
474 vertexCount += ( (unsigned char *)ptrVertexAttribArray - (unsigned char *)ptrVertexAttribArrayMark ) / sizeof( VertexAttrib );
475 if ( vertexCount < 3 )
477 return;
479 switch ( wrapperPrimitiveMode )
481 case GL_QUADS:
483 *ptrIndexArray++ = indexCount;
484 *ptrIndexArray++ = indexCount + 1;
485 *ptrIndexArray++ = indexCount + 2;
486 *ptrIndexArray++ = indexCount;
487 *ptrIndexArray++ = indexCount + 2;
488 *ptrIndexArray++ = indexCount + 3;
489 indexCount += 4;
490 vertexCount += 2;
492 break;
493 case GL_TRIANGLES:
495 int vcount = ( vertexCount - vertexMark ) / 3;
496 for ( int count = 0; count < vcount; count++ )
498 *ptrIndexArray++ = indexCount;
499 *ptrIndexArray++ = indexCount + 1;
500 *ptrIndexArray++ = indexCount + 2;
501 indexCount += 3;
504 break;
505 case GL_TRIANGLE_STRIP:
507 *ptrIndexArray++ = indexCount;
508 *ptrIndexArray++ = indexCount + 1;
509 *ptrIndexArray++ = indexCount + 2;
510 indexCount += 3;
511 int vcount = ( ( vertexCount - vertexMark ) - 3 );
512 if ( vcount && ( (long)ptrIndexArray & 0x02 ) )
514 *ptrIndexArray++ = indexCount - 1; // 2
515 *ptrIndexArray++ = indexCount - 2; // 1
516 *ptrIndexArray++ = indexCount; // 3
517 indexCount++;
518 vcount -= 1;
519 int odd = vcount & 1;
520 vcount /= 2;
521 unsigned int *longptr = (unsigned int *)ptrIndexArray;
523 for ( int count = 0; count < vcount; count++ )
525 *( longptr++ ) = ( indexCount - 2 ) | ( ( indexCount - 1 ) << 16 );
526 *( longptr++ ) = ( indexCount ) | ( ( indexCount ) << 16 );
527 *( longptr++ ) = ( indexCount - 1 ) | ( ( indexCount + 1 ) << 16 );
528 indexCount += 2;
530 ptrIndexArray = (unsigned short *)( longptr );
531 if ( odd )
533 *ptrIndexArray++ = indexCount - 2; // 2
534 *ptrIndexArray++ = indexCount - 1; // 1
535 *ptrIndexArray++ = indexCount; // 3
536 indexCount++;
539 else
541 //already aligned
542 int odd = vcount & 1;
543 vcount /= 2;
544 unsigned int *longptr = (unsigned int *)ptrIndexArray;
546 for ( int count = 0; count < vcount; count++ )
548 *( longptr++ ) = ( indexCount - 1 ) | ( ( indexCount - 2 ) << 16 );
549 *( longptr++ ) = ( indexCount ) | ( ( indexCount - 1 ) << 16 );
550 *( longptr++ ) = ( indexCount ) | ( ( indexCount + 1 ) << 16 );
551 indexCount += 2;
553 ptrIndexArray = (unsigned short *)( longptr );
554 if ( odd )
557 *ptrIndexArray++ = indexCount - 1; // 2
558 *ptrIndexArray++ = indexCount - 2; // 1
559 *ptrIndexArray++ = indexCount; // 3
560 indexCount++;
563 vertexCount += ( vertexCount - vertexMark - 3 ) * 2;
565 break;
566 case GL_POLYGON:
567 case GL_TRIANGLE_FAN:
569 *ptrIndexArray++ = indexCount++;
570 *ptrIndexArray++ = indexCount++;
571 *ptrIndexArray++ = indexCount++;
572 int vcount = ( ( vertexCount - vertexMark ) - 3 );
573 for ( int count = 0; count < vcount; count++ )
575 *ptrIndexArray++ = indexbase;
576 *ptrIndexArray++ = indexCount - 1;
577 *ptrIndexArray++ = indexCount++;
578 vertexCount += 2;
581 break;
583 default:
584 break;
586 if ( ptrVertexAttribArray - vertexattribs > 20000 * sizeof( VertexAttrib ) ||
587 ptrIndexArray - indexArray > 15000 * sizeof( GLushort ) )
588 FlushOnStateChange( );
591 void glEnable( GLenum cap )
593 if( skipnanogl )
595 glEsImpl->glEnable( cap );
596 return;
598 GLboolean statechanged = GL_FALSE;
599 switch ( cap )
601 case GL_ALPHA_TEST:
603 if ( !nanoglState.alpha_test )
605 nanoglState.alpha_test = GL_TRUE;
606 statechanged = GL_TRUE;
608 break;
610 case GL_BLEND:
612 if ( !nanoglState.blend )
614 nanoglState.blend = GL_TRUE;
615 statechanged = GL_TRUE;
617 break;
619 //case GL_CLIP_PLANEi
620 case GL_COLOR_LOGIC_OP:
622 if ( !nanoglState.color_logic_op )
624 nanoglState.color_logic_op = GL_TRUE;
625 statechanged = GL_TRUE;
627 break;
629 case GL_COLOR_MATERIAL:
631 if ( !nanoglState.color_material )
633 nanoglState.color_material = GL_TRUE;
634 statechanged = GL_TRUE;
636 break;
638 case GL_CULL_FACE:
640 if ( !nanoglState.cull_face )
642 nanoglState.cull_face = GL_TRUE;
643 statechanged = GL_TRUE;
645 break;
647 case GL_DEPTH_TEST:
649 if ( !nanoglState.depth_test )
651 nanoglState.depth_test = GL_TRUE;
652 statechanged = GL_TRUE;
654 break;
656 case GL_DITHER:
658 if ( !nanoglState.dither )
660 nanoglState.dither = GL_TRUE;
661 statechanged = GL_TRUE;
663 break;
665 case GL_FOG:
667 if ( !nanoglState.fog )
669 nanoglState.fog = GL_TRUE;
670 statechanged = GL_TRUE;
672 break;
674 case GL_LIGHT0:
676 if ( !nanoglState.light0 )
678 nanoglState.light0 = GL_TRUE;
679 statechanged = GL_TRUE;
681 break;
683 case GL_LIGHT1:
685 if ( !nanoglState.light1 )
687 nanoglState.light1 = GL_TRUE;
688 statechanged = GL_TRUE;
690 break;
692 case GL_LIGHT2:
694 if ( !nanoglState.light2 )
696 nanoglState.light2 = GL_TRUE;
697 statechanged = GL_TRUE;
699 break;
701 case GL_LIGHT3:
703 if ( !nanoglState.light3 )
705 nanoglState.light3 = GL_TRUE;
706 statechanged = GL_TRUE;
708 break;
710 case GL_LIGHT4:
712 if ( !nanoglState.light4 )
714 nanoglState.light4 = GL_TRUE;
715 statechanged = GL_TRUE;
717 break;
719 case GL_LIGHT5:
721 if ( !nanoglState.light5 )
723 nanoglState.light5 = GL_TRUE;
724 statechanged = GL_TRUE;
726 break;
728 case GL_LIGHT6:
730 if ( !nanoglState.light6 )
732 nanoglState.light6 = GL_TRUE;
733 statechanged = GL_TRUE;
735 break;
737 case GL_LIGHT7:
739 if ( !nanoglState.light7 )
741 nanoglState.light7 = GL_TRUE;
742 statechanged = GL_TRUE;
744 break;
746 case GL_LIGHTING:
748 if ( !nanoglState.lighting )
750 nanoglState.lighting = GL_TRUE;
751 statechanged = GL_TRUE;
753 break;
755 case GL_LINE_SMOOTH:
757 if ( !nanoglState.line_smooth )
759 nanoglState.line_smooth = GL_TRUE;
760 statechanged = GL_TRUE;
762 break;
764 /* case GL_MATRIX_PALETTE_OES:
766 if (!nanoglState.matrix_palette_oes)
768 nanoglState.matrix_palette_oes = GL_TRUE;
769 statechanged = GL_TRUE;
771 break;
772 }*/
773 case GL_MULTISAMPLE:
775 if ( !nanoglState.multisample )
777 nanoglState.multisample = GL_TRUE;
778 statechanged = GL_TRUE;
780 break;
782 case GL_NORMALIZE:
784 if ( !nanoglState.normalize )
786 nanoglState.normalize = GL_TRUE;
787 statechanged = GL_TRUE;
789 break;
791 /* case GL_POINT_SPRITE_OES:
793 if (!nanoglState.point_sprite_oes)
795 nanoglState.point_sprite_oes = GL_TRUE;
796 statechanged = GL_TRUE;
798 break;
799 }*/
800 case GL_POLYGON_OFFSET_FILL:
802 if ( !nanoglState.polygon_offset_fill )
804 nanoglState.polygon_offset_fill = GL_TRUE;
805 statechanged = GL_TRUE;
807 break;
809 case GL_RESCALE_NORMAL:
811 if ( !nanoglState.rescale_normal )
813 nanoglState.rescale_normal = GL_TRUE;
814 statechanged = GL_TRUE;
816 break;
818 case GL_SAMPLE_ALPHA_TO_COVERAGE:
820 if ( !nanoglState.sample_alpha_to_coverage )
822 nanoglState.sample_alpha_to_coverage = GL_TRUE;
823 statechanged = GL_TRUE;
825 break;
827 case GL_SAMPLE_ALPHA_TO_ONE:
829 if ( !nanoglState.sample_alpha_to_one )
831 nanoglState.sample_alpha_to_one = GL_TRUE;
832 statechanged = GL_TRUE;
834 break;
836 case GL_SAMPLE_COVERAGE:
838 if ( !nanoglState.sample_coverage )
840 nanoglState.sample_coverage = GL_TRUE;
841 statechanged = GL_TRUE;
843 break;
845 case GL_SCISSOR_TEST:
847 if ( !nanoglState.scissor_test )
849 nanoglState.scissor_test = GL_TRUE;
850 statechanged = GL_TRUE;
852 break;
854 case GL_STENCIL_TEST:
856 if (!nanoglState.stencil_test)
858 nanoglState.stencil_test = GL_TRUE;
859 statechanged = GL_TRUE;
861 break;
863 case GL_TEXTURE_2D:
865 if ( !activetmuState->texture_2d.value )
867 FlushOnStateChange( );
868 glEsImpl->glEnable( cap );
869 activetmuState->texture_2d.value = GL_TRUE;
870 return;
872 break;
874 #if 0 // todo: implement cubemap texgen
875 case GL_TEXTURE_GEN_S:
876 case GL_TEXTURE_GEN_T:
877 case GL_TEXTURE_GEN_R:
878 case GL_TEXTURE_GEN_Q:
880 FlushOnStateChange( );
881 nanoglState.texgen = true;
882 return;
884 #endif
885 default:
886 break;
889 if ( statechanged )
891 FlushOnStateChange( );
892 glEsImpl->glEnable( cap );
896 void glDisable( GLenum cap )
898 if( skipnanogl )
900 glEsImpl->glDisable( cap );
901 return;
903 GLboolean statechanged = GL_FALSE;
904 switch ( cap )
906 case GL_ALPHA_TEST:
908 if ( nanoglState.alpha_test )
910 nanoglState.alpha_test = GL_FALSE;
911 statechanged = GL_TRUE;
913 break;
915 case GL_BLEND:
917 if ( nanoglState.blend )
919 nanoglState.blend = GL_FALSE;
920 statechanged = GL_TRUE;
922 break;
924 //case GL_CLIP_PLANEi
925 case GL_COLOR_LOGIC_OP:
927 if ( nanoglState.color_logic_op )
929 nanoglState.color_logic_op = GL_FALSE;
930 statechanged = GL_TRUE;
932 break;
934 case GL_COLOR_MATERIAL:
936 if ( nanoglState.color_material )
938 nanoglState.color_material = GL_FALSE;
939 statechanged = GL_TRUE;
941 break;
943 case GL_CULL_FACE:
945 if ( nanoglState.cull_face )
947 nanoglState.cull_face = GL_FALSE;
948 statechanged = GL_TRUE;
950 break;
952 case GL_DEPTH_TEST:
954 if ( nanoglState.depth_test )
956 nanoglState.depth_test = GL_FALSE;
957 statechanged = GL_TRUE;
959 break;
961 case GL_DITHER:
963 if ( nanoglState.dither )
965 nanoglState.dither = GL_FALSE;
966 statechanged = GL_TRUE;
968 break;
970 case GL_FOG:
972 if ( nanoglState.fog )
974 nanoglState.fog = GL_FALSE;
975 statechanged = GL_TRUE;
977 break;
979 case GL_LIGHT0:
981 if ( !nanoglState.light0 )
983 nanoglState.light0 = GL_FALSE;
984 statechanged = GL_TRUE;
986 break;
988 case GL_LIGHT1:
990 if ( !nanoglState.light1 )
992 nanoglState.light1 = GL_FALSE;
993 statechanged = GL_TRUE;
995 break;
997 case GL_LIGHT2:
999 if ( !nanoglState.light2 )
1001 nanoglState.light2 = GL_FALSE;
1002 statechanged = GL_TRUE;
1004 break;
1006 case GL_LIGHT3:
1008 if ( !nanoglState.light3 )
1010 nanoglState.light3 = GL_FALSE;
1011 statechanged = GL_TRUE;
1013 break;
1015 case GL_LIGHT4:
1017 if ( !nanoglState.light4 )
1019 nanoglState.light4 = GL_FALSE;
1020 statechanged = GL_TRUE;
1022 break;
1024 case GL_LIGHT5:
1026 if ( !nanoglState.light5 )
1028 nanoglState.light5 = GL_FALSE;
1029 statechanged = GL_TRUE;
1031 break;
1033 case GL_LIGHT6:
1035 if ( !nanoglState.light6 )
1037 nanoglState.light6 = GL_FALSE;
1038 statechanged = GL_TRUE;
1040 break;
1042 case GL_LIGHT7:
1044 if ( !nanoglState.light7 )
1046 nanoglState.light7 = GL_FALSE;
1047 statechanged = GL_TRUE;
1049 break;
1051 case GL_LIGHTING:
1053 if ( nanoglState.lighting )
1055 nanoglState.lighting = GL_FALSE;
1056 statechanged = GL_TRUE;
1058 break;
1060 case GL_LINE_SMOOTH:
1062 if ( nanoglState.line_smooth )
1064 nanoglState.line_smooth = GL_FALSE;
1065 statechanged = GL_TRUE;
1067 break;
1069 /* case GL_MATRIX_PALETTE_OES:
1071 if (nanoglState.matrix_palette_oes)
1073 nanoglState.matrix_palette_oes = GL_FALSE;
1074 statechanged = GL_TRUE;
1076 break;
1077 }*/
1078 case GL_MULTISAMPLE:
1080 if ( nanoglState.multisample )
1082 nanoglState.multisample = GL_FALSE;
1083 statechanged = GL_TRUE;
1085 break;
1087 case GL_NORMALIZE:
1089 if ( nanoglState.normalize )
1091 nanoglState.normalize = GL_FALSE;
1092 statechanged = GL_TRUE;
1094 break;
1096 /* case GL_POINT_SPRITE_OES:
1098 if (nanoglState.point_sprite_oes)
1100 nanoglState.point_sprite_oes = GL_FALSE;
1101 statechanged = GL_TRUE;
1103 break;
1104 }*/
1105 case GL_POLYGON_OFFSET_FILL:
1107 if ( nanoglState.polygon_offset_fill )
1109 nanoglState.polygon_offset_fill = GL_FALSE;
1110 statechanged = GL_TRUE;
1112 break;
1114 case GL_RESCALE_NORMAL:
1116 if ( nanoglState.rescale_normal )
1118 nanoglState.rescale_normal = GL_FALSE;
1119 statechanged = GL_TRUE;
1121 break;
1123 case GL_SAMPLE_ALPHA_TO_COVERAGE:
1125 if ( nanoglState.sample_alpha_to_coverage )
1127 nanoglState.sample_alpha_to_coverage = GL_FALSE;
1128 statechanged = GL_TRUE;
1130 break;
1132 case GL_SAMPLE_ALPHA_TO_ONE:
1134 if ( nanoglState.sample_alpha_to_one )
1136 nanoglState.sample_alpha_to_one = GL_FALSE;
1137 statechanged = GL_TRUE;
1139 break;
1141 case GL_SAMPLE_COVERAGE:
1143 if ( nanoglState.sample_coverage )
1145 nanoglState.sample_coverage = GL_FALSE;
1146 statechanged = GL_TRUE;
1148 break;
1150 case GL_SCISSOR_TEST:
1152 if ( nanoglState.scissor_test )
1154 nanoglState.scissor_test = GL_FALSE;
1155 statechanged = GL_TRUE;
1157 break;
1159 case GL_STENCIL_TEST:
1161 if (nanoglState.stencil_test)
1163 nanoglState.stencil_test = GL_FALSE;
1164 statechanged = GL_TRUE;
1166 break;
1168 case GL_TEXTURE_2D:
1170 if ( activetmuState->texture_2d.value )
1172 FlushOnStateChange( );
1173 glEsImpl->glDisable( cap );
1174 activetmuState->texture_2d.value = GL_FALSE;
1175 return;
1177 break;
1179 #if 0
1180 case GL_TEXTURE_GEN_S:
1181 case GL_TEXTURE_GEN_T:
1182 case GL_TEXTURE_GEN_R:
1183 case GL_TEXTURE_GEN_Q:
1185 FlushOnStateChange( );
1186 nanoglState.texgen = false;
1187 return;
1189 #endif
1190 default:
1191 break;
1194 if ( statechanged )
1196 FlushOnStateChange( );
1197 glEsImpl->glDisable( cap );
1201 void glVertex2f( GLfloat x, GLfloat y )
1203 glVertex3f( x, y, 0.0f );
1206 __FORCEINLINE unsigned int ClampTo255( float value )
1208 unsigned int retval = (unsigned int)( value );
1209 if ( retval > 255 )
1211 retval = 255;
1213 return retval;
1216 void glColor3f( GLfloat red, GLfloat green, GLfloat blue )
1218 currentVertexAttrib.red = (unsigned char)ClampTo255( red * 255.0f );
1219 currentVertexAttrib.green = (unsigned char)ClampTo255( green * 255.0f );
1220 currentVertexAttrib.blue = (unsigned char)ClampTo255( blue * 255.0f );
1221 currentVertexAttrib.alpha = 255;
1224 void glTexCoord2fv( const GLfloat *v )
1226 memcpy( &currentVertexAttrib.s, v, 2 * sizeof( float ) );
1229 void glTexCoord2f( GLfloat s, GLfloat t )
1231 currentVertexAttrib.s = s;
1232 currentVertexAttrib.t = t;
1235 void glViewport( GLint x, GLint y, GLsizei width, GLsizei height )
1237 FlushOnStateChange( );
1238 glEsImpl->glViewport( x, y, width, height );
1241 void glLoadIdentity( void )
1243 FlushOnStateChange( );
1244 glEsImpl->glLoadIdentity( );
1247 void glColor4f( GLfloat red, GLfloat green, GLfloat blue, GLfloat alpha )
1249 currentVertexAttrib.red = (unsigned char)ClampTo255( red * 255.0f );
1250 currentVertexAttrib.green = (unsigned char)ClampTo255( green * 255.0f );
1251 currentVertexAttrib.blue = (unsigned char)ClampTo255( blue * 255.0f );
1252 currentVertexAttrib.alpha = (unsigned char)ClampTo255( alpha * 255.0f );
1255 void glOrtho( GLdouble left, GLdouble right, GLdouble bottom, GLdouble top, GLdouble zNear, GLdouble zFar )
1257 FlushOnStateChange( );
1258 #ifdef USE_CORE_PROFILE
1259 glEsImpl->glOrtho( left, right, bottom, top, zNear, zFar );
1260 #else
1261 glEsImpl->glOrthof( left, right, bottom, top, zNear, zFar );
1262 #endif
1265 // Rikku2000: Light
1266 void glLightf( GLenum light, GLenum pname, GLfloat param )
1268 FlushOnStateChange( );
1270 glEsImpl->glLightf( light, pname, param );
1272 void glLightfv( GLenum light, GLenum pname, const GLfloat *params )
1274 FlushOnStateChange( );
1276 glEsImpl->glLightfv( light, pname, params );
1278 void glLightModelf( GLenum pname, GLfloat param )
1280 FlushOnStateChange( );
1282 glEsImpl->glLightModelf( pname, param );
1284 void glLightModelfv( GLenum pname, const GLfloat *params )
1286 FlushOnStateChange( );
1288 glEsImpl->glLightModelfv( pname, params );
1290 void glMaterialf( GLenum face, GLenum pname, GLfloat param )
1292 FlushOnStateChange( );
1294 glEsImpl->glMaterialf( face, pname, param );
1296 void glMaterialfv( GLenum face, GLenum pname, const GLfloat *params )
1298 FlushOnStateChange( );
1300 glEsImpl->glMaterialfv( face, pname, params );
1302 void glColorMaterial( GLenum face, GLenum mode )
1304 FlushOnStateChange( );
1306 glEsImpl->glColorMaterial( face, mode );
1309 void glMatrixMode( GLenum mode )
1311 if ( nanoglState.matrixmode == mode )
1313 return;
1315 nanoglState.matrixmode = mode;
1316 FlushOnStateChange( );
1317 glEsImpl->glMatrixMode( mode );
1320 void glTexParameterf( GLenum target, GLenum pname, GLfloat param )
1322 if ( pname == GL_TEXTURE_BORDER_COLOR )
1324 return; // not supported by opengl es
1326 if ( ( pname == GL_TEXTURE_WRAP_S ||
1327 pname == GL_TEXTURE_WRAP_T ) &&
1328 param == GL_CLAMP )
1330 param = 0x812F;
1333 FlushOnStateChange( );
1334 glEsImpl->glTexParameterf( target, pname, param );
1337 void glTexParameterfv( GLenum target, GLenum pname, const GLfloat *params )
1339 glTexParameterf( target, pname, params[0] );
1342 void glTexImage2D( GLenum target, GLint level, GLint internalformat, GLsizei width, GLsizei height, GLint border, GLenum format, GLenum type, const GLvoid *pixels )
1344 unsigned char *data = (unsigned char*)pixels;
1346 if( pixels && internalformat == GL_RGB && format == GL_RGBA ) // strip alpha from texture
1348 unsigned char *in = data, *out;
1349 int i = 0, size = width * height * 4;
1351 data = out = (unsigned char*)malloc( size );
1353 for( i = 0; i < size; i += 4, in += 4, out += 4 )
1355 memcpy( out, in, 3 );
1356 out[3] = 255;
1360 internalformat = format;
1361 glEsImpl->glTexImage2D( target, level, internalformat, width, height, border, format, type, data );
1363 if( data != pixels )
1364 free(data);
1367 void glDrawBuffer( GLenum /*mode*/ )
1371 void glTranslatef( GLfloat x, GLfloat y, GLfloat z )
1373 FlushOnStateChange( );
1374 glEsImpl->glTranslatef( x, y, z );
1377 void glRotatef( GLfloat angle, GLfloat x, GLfloat y, GLfloat z )
1379 FlushOnStateChange( );
1380 glEsImpl->glRotatef( angle, x, y, z );
1383 void glScalef( GLfloat x, GLfloat y, GLfloat z )
1385 FlushOnStateChange( );
1386 glEsImpl->glScalef( x, y, z );
1389 void glDepthRange( GLclampd zNear, GLclampd zFar )
1391 if ( ( nanoglState.depth_range_near == zNear ) && ( nanoglState.depth_range_far == zFar ) )
1393 return;
1395 else
1397 nanoglState.depth_range_near = zNear;
1398 nanoglState.depth_range_far = zFar;
1400 FlushOnStateChange( );
1401 #ifdef USE_CORE_PROFILE
1402 glEsImpl->glDepthRange( zNear, zFar );
1403 #else
1404 glEsImpl->glDepthRangef( zNear, zFar );
1405 #endif
1408 void glDepthFunc( GLenum func )
1410 if ( nanoglState.depth_func == func )
1412 return;
1414 else
1416 nanoglState.depth_func = func;
1418 FlushOnStateChange( );
1419 glEsImpl->glDepthFunc( func );
1422 void glFinish( void )
1424 FlushOnStateChange( );
1425 glEsImpl->glFinish( );
1428 void glGetFloatv( GLenum pname, GLfloat *params )
1430 FlushOnStateChange( );
1431 glEsImpl->glGetFloatv( pname, params );
1434 void glCullFace( GLenum mode )
1436 if ( nanoglState.cullface == mode )
1438 return;
1440 else
1442 nanoglState.cullface = mode;
1444 FlushOnStateChange( );
1445 glEsImpl->glCullFace( mode );
1448 void glFrustum( GLdouble left, GLdouble right, GLdouble bottom, GLdouble top, GLdouble zNear, GLdouble zFar )
1450 FlushOnStateChange( );
1451 glEsImpl->glFrustumf( left, right, bottom, top, zNear, zFar );
1454 void glClear( GLbitfield mask )
1456 FlushOnStateChange( );
1457 glEsImpl->glClear( mask );
1460 void glVertex3f( GLfloat x, GLfloat y, GLfloat z )
1462 GLfloat *vert = (GLfloat *)ptrVertexAttribArray++;
1463 *vert++ = x;
1464 *vert++ = y;
1465 *vert++ = z;
1466 #if defined( __MULTITEXTURE_SUPPORT__ )
1467 memcpy( vert, &currentVertexAttrib.red, 5 * sizeof( GLfloat ) );
1468 #else
1469 memcpy( vert + 1, &currentVertexAttrib.red, 3 * sizeof( GLfloat ) );
1470 #endif
1473 void glColor4fv( const GLfloat *v )
1475 currentVertexAttrib.red = (unsigned char)ClampTo255( v[0] * 255.0f );
1476 currentVertexAttrib.green = (unsigned char)ClampTo255( v[1] * 255.0f );
1477 currentVertexAttrib.blue = (unsigned char)ClampTo255( v[2] * 255.0f );
1478 currentVertexAttrib.alpha = (unsigned char)ClampTo255( v[3] * 255.0f );
1479 if( skipnanogl )
1480 glEsImpl->glColor4f( currentVertexAttrib.red/255.0f, currentVertexAttrib.green/255.0f,
1481 currentVertexAttrib.blue/255.0f, currentVertexAttrib.alpha/255.0f );
1484 void glColor3ubv( const GLubyte *v )
1486 currentVertexAttrib.red = v[0];
1487 currentVertexAttrib.green = v[1];
1488 currentVertexAttrib.blue = v[2];
1489 currentVertexAttrib.alpha = 255;
1490 if( skipnanogl )
1491 glEsImpl->glColor4f( currentVertexAttrib.red/255.0f, currentVertexAttrib.green/255.0f,
1492 currentVertexAttrib.blue/255.0f, currentVertexAttrib.alpha/255.0f );
1495 void glColor4ubv( const GLubyte *v )
1497 //*((unsigned int*)(&currentVertexAttrib.red)) = *((unsigned int*)(v));
1498 currentVertexAttrib.red = v[0];
1499 currentVertexAttrib.green = v[1];
1500 currentVertexAttrib.blue = v[2];
1501 currentVertexAttrib.alpha = v[3];
1502 if( skipnanogl )
1503 glEsImpl->glColor4f( currentVertexAttrib.red/255.0f, currentVertexAttrib.green/255.0f,
1504 currentVertexAttrib.blue/255.0f, currentVertexAttrib.alpha/255.0f );
1507 void glColor3fv( const GLfloat *v )
1509 currentVertexAttrib.red = (unsigned char)ClampTo255( v[0] * 255.0f );
1510 currentVertexAttrib.green = (unsigned char)ClampTo255( v[1] * 255.0f );
1511 currentVertexAttrib.blue = (unsigned char)ClampTo255( v[2] * 255.0f );
1512 currentVertexAttrib.alpha = 255;
1513 if( skipnanogl )
1514 glEsImpl->glColor4f( currentVertexAttrib.red/255.0f, currentVertexAttrib.green/255.0f,
1515 currentVertexAttrib.blue/255.0f, currentVertexAttrib.alpha/255.0f );
1518 //-- nicknekit: xash3d funcs --
1520 void glColor4ub( GLubyte red, GLubyte green, GLubyte blue, GLubyte alpha )
1522 currentVertexAttrib.red = red;
1523 currentVertexAttrib.green = green;
1524 currentVertexAttrib.blue = blue;
1525 currentVertexAttrib.alpha = alpha;
1526 if( skipnanogl )
1527 glEsImpl->glColor4f( currentVertexAttrib.red/255.0f, currentVertexAttrib.green/255.0f,
1528 currentVertexAttrib.blue/255.0f, currentVertexAttrib.alpha/255.0f );
1531 void glColor3ub( GLubyte red, GLubyte green, GLubyte blue )
1533 currentVertexAttrib.red = red;
1534 currentVertexAttrib.green = green;
1535 currentVertexAttrib.blue = blue;
1536 currentVertexAttrib.alpha = 255;
1537 if( skipnanogl )
1538 glEsImpl->glColor4f( currentVertexAttrib.red/255.0f, currentVertexAttrib.green/255.0f,
1539 currentVertexAttrib.blue/255.0f, currentVertexAttrib.alpha/255.0f );
1542 void glNormal3fv( const GLfloat *v )
1544 FlushOnStateChange( );
1545 glEsImpl->glNormal3f( v[0], v[1], v[2] );
1548 void glCopyTexImage2D( GLenum target, GLint level, GLenum internalformat, GLint x, GLint y, GLsizei width, GLsizei height, GLint border )
1550 FlushOnStateChange( );
1551 glEsImpl->glCopyTexImage2D( target, level, internalformat, x, y, width, height, border );
1554 void glTexImage1D( GLenum target, GLint level, GLint internalformat, GLsizei width, GLint border, GLenum format, GLenum type, const GLvoid *pixels )
1556 glTexImage2D( GL_TEXTURE_2D, level, internalformat, width, 1, border, format, type, pixels );
1559 void glTexImage3D( GLenum target, GLint level, GLint internalformat, GLsizei width, GLsizei height, GLsizei depth, GLint border, GLenum format, GLenum type, const GLvoid *pixels )
1561 glTexImage2D( GL_TEXTURE_2D, level, internalformat, width, height, border, format, type, pixels );
1564 void glTexSubImage1D( GLenum target, GLint level, GLint xoffset, GLsizei width, GLenum format, GLenum type, const GLvoid *pixels )
1566 glTexSubImage2D( target, level, xoffset, 0, width, 1, format, type, pixels );
1569 void glTexSubImage3D( GLenum target, GLint level,
1570 GLint xoffset, GLint yoffset,
1571 GLint zoffset, GLsizei width,
1572 GLsizei height, GLsizei depth,
1573 GLenum format,
1574 GLenum type, const GLvoid *pixels )
1576 glTexSubImage2D( target, level, xoffset, yoffset, width, height, format, type, pixels );
1579 GLboolean glIsTexture( GLuint texture )
1581 FlushOnStateChange( );
1582 return glEsImpl->glIsTexture( texture );
1585 // TODO: add native normal/reflection map texgen support
1587 void glTexGeni( GLenum coord, GLenum pname, GLint param )
1589 FlushOnStateChange();
1590 //glEsImpl->glTexGeniOES( coord, pname, param );
1593 void glTexGenfv( GLenum coord, GLenum pname, const GLfloat *params )
1595 FlushOnStateChange();
1596 //glEsImpl->glTexGenfvOES( coord, pname, params );
1599 //-- --//
1601 void glHint( GLenum target, GLenum mode )
1603 FlushOnStateChange( );
1604 glEsImpl->glHint( target, mode );
1607 void glBlendFunc( GLenum sfactor, GLenum dfactor )
1609 if( skipnanogl )
1611 glEsImpl->glBlendFunc( sfactor, dfactor );
1612 return;
1614 if ( ( nanoglState.sfactor == sfactor ) && ( nanoglState.dfactor == dfactor ) )
1616 return;
1619 nanoglState.sfactor = sfactor;
1620 nanoglState.dfactor = dfactor;
1621 FlushOnStateChange( );
1622 glEsImpl->glBlendFunc( sfactor, dfactor );
1625 void glPopMatrix( void )
1627 FlushOnStateChange( );
1628 glEsImpl->glPopMatrix( );
1631 void glShadeModel( GLenum mode )
1633 if ( nanoglState.shademodel == mode )
1635 return;
1637 nanoglState.shademodel = mode;
1638 FlushOnStateChange( );
1639 glEsImpl->glShadeModel( mode );
1642 void glPushMatrix( void )
1644 FlushOnStateChange( );
1645 glEsImpl->glPushMatrix( );
1648 void glTexEnvf( GLenum target, GLenum pname, GLfloat param )
1650 if( skipnanogl )
1652 glEsImpl->glTexEnvf( target, pname, param );
1653 return;
1655 if ( target == GL_TEXTURE_ENV )
1657 if ( pname == GL_TEXTURE_ENV_MODE )
1659 if ( param == activetmuState->texture_env_mode.value )
1661 return;
1663 else
1665 FlushOnStateChange( );
1666 glEsImpl->glTexEnvf( target, pname, param );
1667 activetmuState->texture_env_mode.value = param;
1668 return;
1672 FlushOnStateChange( );
1673 glEsImpl->glTexEnvf( target, pname, param );
1676 void glVertex3fv( const GLfloat *v )
1678 GLfloat *vert = (GLfloat *)ptrVertexAttribArray++;
1679 memcpy( vert, v, 3 * sizeof( GLfloat ) );
1680 #if defined( __MULTITEXTURE_SUPPORT__ )
1681 memcpy( vert + 3, &currentVertexAttrib.red, 5 * sizeof( GLfloat ) );
1682 #else
1683 memcpy( vert + 4, &currentVertexAttrib.red, 3 * sizeof( GLfloat ) );
1684 #endif
1687 void glDepthMask( GLboolean flag )
1689 if( !skipnanogl )
1691 if ( nanoglState.depthmask == flag )
1693 return;
1695 nanoglState.depthmask = flag;
1696 FlushOnStateChange( );
1698 glEsImpl->glDepthMask( flag );
1701 void glBindTexture( GLenum target, GLuint texture )
1703 if( skipnanogl )
1705 glEsImpl->glBindTexture( target,texture );
1706 return;
1708 if ( activetmuState->boundtexture.value == texture )
1710 return;
1712 FlushOnStateChange( );
1713 activetmuState->boundtexture.value = texture;
1714 glEsImpl->glBindTexture( target, texture );
1717 void glGetIntegerv( GLenum pname, GLint *params )
1719 FlushOnStateChange( );
1720 glEsImpl->glGetIntegerv( pname, params );
1723 GLubyte nano_extensions_string[4096];
1724 const GLubyte *glGetString( GLenum name )
1727 if ( name == GL_EXTENSIONS )
1729 #if defined( __MULTITEXTURE_SUPPORT__ )
1730 sprintf( (char *)nano_extensions_string, "%s %s", glEsImpl->glGetString( name ), "GL_ARB_multitexture EXT_texture_env_add" );
1731 #else
1732 sprintf( (char *)nano_extensions_string, "%s %s", glEsImpl->glGetString( name ), "EXT_texture_env_add" );
1733 #endif
1734 return nano_extensions_string;
1736 return glEsImpl->glGetString( name );
1739 void glAlphaFunc( GLenum func, GLclampf ref )
1741 FlushOnStateChange( );
1742 glEsImpl->glAlphaFunc( func, ref );
1745 void glFlush( void )
1747 FlushOnStateChange( );
1748 glEsImpl->glFlush( );
1751 void glReadPixels( GLint x, GLint y, GLsizei width, GLsizei height, GLenum format, GLenum type, GLvoid *pixels )
1753 if ( format == GL_DEPTH_COMPONENT )
1755 // OpenglEs 1.1 does not support reading depth buffer without an extension
1756 memset( pixels, 0xff, 4 );
1757 return;
1759 FlushOnStateChange( );
1760 glEsImpl->glReadPixels( x, y, width, height, format, type, pixels );
1763 void glReadBuffer( GLenum /*mode*/ )
1767 void glLoadMatrixf( const GLfloat *m )
1769 FlushOnStateChange( );
1770 glEsImpl->glLoadMatrixf( m );
1773 void glTexSubImage2D( GLenum target, GLint level, GLint xoffset, GLint yoffset, GLsizei width, GLsizei height, GLenum format, GLenum type, const GLvoid *pixels )
1775 FlushOnStateChange( );
1776 glEsImpl->glTexSubImage2D( target, level, xoffset, yoffset, width, height, format, type, pixels );
1779 void glClearColor( GLclampf red, GLclampf green, GLclampf blue, GLclampf alpha )
1781 FlushOnStateChange( );
1782 glEsImpl->glClearColor( red, green, blue, alpha );
1785 GLenum glGetError( void )
1787 //FlushOnStateChange();
1788 return GL_NO_ERROR; //glEsImpl->glGetError();
1791 void glActiveTexture( GLenum texture )
1793 if( skipnanogl )
1795 glEsImpl->glActiveTexture( texture );
1796 return;
1798 if ( activetmu == texture )
1800 return;
1802 if ( delayedttmuchange )
1804 delayedttmuchange = GL_FALSE;
1806 else
1808 delayedttmuchange = GL_TRUE;
1809 delayedtmutarget = texture;
1811 if ( texture == GL_TEXTURE0 )
1813 activetmuState = &tmuState0;
1815 else
1817 activetmuState = &tmuState1;
1819 activetmu = texture;
1822 void glActiveTextureARB( GLenum texture )
1824 if( skipnanogl )
1826 glEsImpl->glActiveTexture( texture );
1827 return;
1829 if ( activetmu == texture )
1831 return;
1833 if ( delayedttmuchange )
1835 delayedttmuchange = GL_FALSE;
1837 else
1839 delayedttmuchange = GL_TRUE;
1840 delayedtmutarget = texture;
1842 if ( texture == GL_TEXTURE0 )
1844 activetmuState = &tmuState0;
1846 else
1848 activetmuState = &tmuState1;
1850 activetmu = texture;
1853 void glClientActiveTexture( GLenum texture )
1855 if( skipnanogl )
1857 glEsImpl->glClientActiveTexture( texture );
1858 return;
1860 clientactivetmu = texture;
1862 void glClientActiveTextureARB( GLenum texture )
1864 if( skipnanogl )
1866 glEsImpl->glClientActiveTexture( texture );
1867 return;
1869 clientactivetmu = texture;
1873 void glPolygonMode( GLenum face, GLenum mode )
1877 void glDeleteTextures( GLsizei n, const GLuint *textures )
1879 FlushOnStateChange( );
1880 glEsImpl->glDeleteTextures( n, textures );
1883 void glClearDepth( GLclampd depth )
1885 FlushOnStateChange( );
1886 glEsImpl->glClearDepthf( depth );
1889 void glClipPlane( GLenum plane, const GLdouble *equation )
1891 FlushOnStateChange( );
1892 float array[4];
1893 array[0] = ( GLfloat )( equation[0] );
1894 array[1] = ( GLfloat )( equation[1] );
1895 array[2] = ( GLfloat )( equation[2] );
1896 array[3] = ( GLfloat )( equation[3] );
1897 glEsImpl->glClipPlanef( plane, array );
1900 void glScissor( GLint x, GLint y, GLsizei width, GLsizei height )
1902 FlushOnStateChange( );
1903 glEsImpl->glScissor( x, y, width, height );
1906 void glPointSize( GLfloat size )
1908 FlushOnStateChange( );
1909 glEsImpl->glPointSize( size );
1912 void glArrayElement( GLint i )
1915 void glLineWidth( GLfloat width )
1918 void glCallList( GLuint list )
1921 void glColorMask( GLboolean red, GLboolean green, GLboolean blue, GLboolean alpha )
1923 FlushOnStateChange( );
1924 glEsImpl->glColorMask( red, green, blue, alpha );
1926 void glStencilFunc( GLenum func, GLint ref, GLuint mask )
1928 FlushOnStateChange( );
1929 glEsImpl->glStencilFunc( func, ref, mask );
1931 void glStencilOp( GLenum fail, GLenum zfail, GLenum zpass )
1933 FlushOnStateChange( );
1934 glEsImpl->glStencilOp( fail, zfail, zpass );
1937 struct ptrstate vertex_array;
1938 struct ptrstate color_array;
1939 struct ptrstate texture_coord_array;
1941 void glDrawElements( GLenum mode, GLsizei count, GLenum type, const GLvoid *indices )
1943 if( skipnanogl )
1945 glEsImpl->glDrawElements( mode, count, type, indices );
1946 return;
1948 // ensure that all primitives specified between glBegin/glEnd pairs
1949 // are rendered first, and that we have correct tmu in use..
1950 FlushOnStateChange( );
1951 // setup correct vertex/color/texcoord pointers
1952 if ( arraysValid ||
1953 tmuState0.vertex_array.changed ||
1954 tmuState0.color_array.changed ||
1955 tmuState0.texture_coord_array.changed || tmuState0.normal_array.changed )
1957 glEsImpl->glClientActiveTexture( GL_TEXTURE0 );
1959 if ( arraysValid || tmuState0.vertex_array.changed )
1961 if ( tmuState0.vertex_array.enabled )
1963 glEsImpl->glEnableClientState( GL_VERTEX_ARRAY );
1965 else
1967 glEsImpl->glDisableClientState( GL_VERTEX_ARRAY );
1969 glEsImpl->glVertexPointer( tmuState0.vertex_array.size,
1970 tmuState0.vertex_array.type,
1971 tmuState0.vertex_array.stride,
1972 tmuState0.vertex_array.ptr );
1973 tmuState0.vertex_array.changed = GL_FALSE;
1975 if ( arraysValid || tmuState0.color_array.changed )
1977 if ( tmuState0.color_array.enabled )
1979 glEsImpl->glEnableClientState( GL_COLOR_ARRAY );
1981 else
1983 glEsImpl->glDisableClientState( GL_COLOR_ARRAY );
1984 glEsImpl->glColor4f( currentVertexAttrib.red/255.0f, currentVertexAttrib.green/255.0f,
1985 currentVertexAttrib.blue/255.0f, currentVertexAttrib.alpha/255.0f );
1988 glEsImpl->glColorPointer( tmuState0.color_array.size,
1989 tmuState0.color_array.type,
1990 tmuState0.color_array.stride,
1991 tmuState0.color_array.ptr );
1992 tmuState0.color_array.changed = GL_FALSE;
1994 if ( arraysValid || tmuState0.normal_array.changed )
1996 if ( tmuState0.normal_array.enabled )
1998 glEsImpl->glEnableClientState( GL_NORMAL_ARRAY );
2000 else
2002 glEsImpl->glDisableClientState( GL_NORMAL_ARRAY );
2004 glEsImpl->glNormalPointer( tmuState0.normal_array.type,
2005 tmuState0.normal_array.stride,
2006 tmuState0.normal_array.ptr );
2007 tmuState0.normal_array.changed = GL_FALSE;
2009 if ( arraysValid || tmuState0.texture_coord_array.changed )
2011 tmuState0.texture_coord_array.changed = GL_FALSE;
2012 if ( tmuState0.texture_coord_array.enabled )
2014 glEsImpl->glEnableClientState( GL_TEXTURE_COORD_ARRAY );
2016 else
2018 glEsImpl->glDisableClientState( GL_TEXTURE_COORD_ARRAY );
2020 glEsImpl->glTexCoordPointer( tmuState0.texture_coord_array.size,
2021 tmuState0.texture_coord_array.type,
2022 tmuState0.texture_coord_array.stride,
2023 tmuState0.texture_coord_array.ptr );
2026 if ( arraysValid || tmuState1.texture_coord_array.changed )
2028 tmuState1.texture_coord_array.changed = GL_FALSE;
2029 glEsImpl->glClientActiveTexture( GL_TEXTURE1 );
2030 if ( tmuState1.texture_coord_array.enabled )
2032 glEsImpl->glEnableClientState( GL_TEXTURE_COORD_ARRAY );
2034 else
2036 glEsImpl->glDisableClientState( GL_TEXTURE_COORD_ARRAY );
2038 glEsImpl->glTexCoordPointer( tmuState1.texture_coord_array.size,
2039 tmuState1.texture_coord_array.type,
2040 tmuState1.texture_coord_array.stride,
2041 tmuState1.texture_coord_array.ptr );
2044 arraysValid = GL_FALSE;
2045 glEsImpl->glDrawElements( mode, count, type, indices );
2048 bool vboarray;
2050 void glEnableClientState( GLenum array )
2052 if( skipnanogl )
2054 glEsImpl->glEnableClientState( array );
2055 if( array == GL_VERTEX_ARRAY )
2056 vboarray = true;
2057 return;
2059 struct nanotmuState *clientstate = NULL;
2060 if ( clientactivetmu == GL_TEXTURE0 )
2062 clientstate = &tmuState0;
2064 else if ( clientactivetmu == GL_TEXTURE1 )
2066 clientstate = &tmuState1;
2068 else
2070 return;
2072 switch ( array )
2074 case GL_VERTEX_ARRAY:
2075 if ( clientstate->vertex_array.enabled )
2077 return;
2079 clientstate->vertex_array.enabled = GL_TRUE;
2080 clientstate->vertex_array.changed = GL_TRUE;
2081 break;
2082 case GL_COLOR_ARRAY:
2083 if ( clientstate->color_array.enabled )
2085 return;
2087 clientstate->color_array.enabled = GL_TRUE;
2088 clientstate->color_array.changed = GL_TRUE;
2090 break;
2091 case GL_NORMAL_ARRAY:
2092 if ( clientstate->normal_array.enabled )
2094 return;
2096 clientstate->normal_array.enabled = GL_TRUE;
2097 clientstate->normal_array.changed = GL_TRUE;
2099 break;
2100 case GL_TEXTURE_COORD_ARRAY:
2101 if ( clientstate->texture_coord_array.enabled )
2103 return;
2105 clientstate->texture_coord_array.enabled = GL_TRUE;
2106 clientstate->texture_coord_array.changed = GL_TRUE;
2107 break;
2108 default:
2109 break;
2112 void glDisableClientState( GLenum array )
2114 if( skipnanogl )
2116 glEsImpl->glDisableClientState( array );
2117 if( array == GL_VERTEX_ARRAY )
2118 vboarray = false;
2119 return;
2121 struct nanotmuState *clientstate = NULL;
2122 if ( clientactivetmu == GL_TEXTURE0 )
2124 clientstate = &tmuState0;
2126 else if ( clientactivetmu == GL_TEXTURE1 )
2128 clientstate = &tmuState1;
2130 else
2132 return;
2134 switch ( array )
2136 case GL_VERTEX_ARRAY:
2137 if ( !clientstate->vertex_array.enabled )
2139 return;
2141 clientstate->vertex_array.enabled = GL_FALSE;
2142 clientstate->vertex_array.changed = GL_TRUE;
2143 break;
2144 case GL_COLOR_ARRAY:
2145 if ( !clientstate->color_array.enabled )
2147 return;
2149 clientstate->color_array.enabled = GL_FALSE;
2150 clientstate->color_array.changed = GL_TRUE;
2152 break;
2153 case GL_NORMAL_ARRAY:
2154 if ( !clientstate->normal_array.enabled )
2156 return;
2158 clientstate->normal_array.enabled = GL_FALSE;
2159 clientstate->normal_array.changed = GL_TRUE;
2161 break;
2162 case GL_TEXTURE_COORD_ARRAY:
2163 if ( !clientstate->texture_coord_array.enabled )
2165 return;
2167 clientstate->texture_coord_array.enabled = GL_FALSE;
2168 clientstate->texture_coord_array.changed = GL_TRUE;
2169 break;
2170 default:
2171 break;
2174 void glVertexPointer( GLint size, GLenum type, GLsizei stride, const GLvoid *pointer )
2177 if( skipnanogl )
2179 glEsImpl->glVertexPointer( size, type, stride, pointer );
2180 return;
2182 if ( tmuState0.vertex_array.size == size &&
2183 tmuState0.vertex_array.stride == stride &&
2184 tmuState0.vertex_array.type == type &&
2185 tmuState0.vertex_array.ptr == pointer )
2187 return;
2189 tmuState0.vertex_array.size = size;
2190 tmuState0.vertex_array.stride = stride;
2191 tmuState0.vertex_array.type = type;
2192 tmuState0.vertex_array.ptr = (GLvoid *)pointer;
2193 tmuState0.vertex_array.changed = GL_TRUE;
2195 void glTexCoordPointer( GLint size, GLenum type, GLsizei stride, const GLvoid *pointer )
2197 if( skipnanogl )
2199 glEsImpl->glTexCoordPointer( size, type, stride, pointer );
2200 return;
2202 struct nanotmuState *clientstate = NULL;
2203 if ( clientactivetmu == GL_TEXTURE0 )
2205 clientstate = &tmuState0;
2207 else if ( clientactivetmu == GL_TEXTURE1 )
2209 clientstate = &tmuState1;
2211 if ( clientstate->texture_coord_array.size == size &&
2212 clientstate->texture_coord_array.stride == stride &&
2213 clientstate->texture_coord_array.type == type &&
2214 clientstate->texture_coord_array.ptr == pointer )
2216 return;
2218 clientstate->texture_coord_array.size = size;
2219 clientstate->texture_coord_array.stride = stride;
2220 clientstate->texture_coord_array.type = type;
2221 clientstate->texture_coord_array.ptr = (GLvoid *)pointer;
2222 clientstate->texture_coord_array.changed = GL_TRUE;
2224 void glColorPointer( GLint size, GLenum type, GLsizei stride, const GLvoid *pointer )
2226 if ( tmuState0.color_array.size == size &&
2227 tmuState0.color_array.stride == stride &&
2228 tmuState0.color_array.type == type &&
2229 tmuState0.color_array.ptr == pointer )
2231 return;
2233 tmuState0.color_array.size = size;
2234 tmuState0.color_array.stride = stride;
2235 tmuState0.color_array.type = type;
2236 tmuState0.color_array.ptr = (GLvoid *)pointer;
2237 tmuState0.color_array.changed = GL_TRUE;
2240 void glNormalPointer( GLenum type, GLsizei stride, const GLvoid *pointer )
2242 int size = 0;
2243 if ( tmuState0.normal_array.size == size &&
2244 tmuState0.normal_array.stride == stride &&
2245 tmuState0.normal_array.type == type &&
2246 tmuState0.normal_array.ptr == pointer )
2248 return;
2250 tmuState0.normal_array.size = size;
2251 tmuState0.normal_array.stride = stride;
2252 tmuState0.normal_array.type = type;
2253 tmuState0.normal_array.ptr = (GLvoid *)pointer;
2254 tmuState0.normal_array.changed = GL_TRUE;
2256 void glPolygonOffset( GLfloat factor, GLfloat units )
2258 FlushOnStateChange( );
2259 glEsImpl->glPolygonOffset( factor, units );
2261 void glStencilMask( GLuint mask )
2263 FlushOnStateChange( );
2264 glEsImpl->glStencilMask( mask );
2266 void glClearStencil( GLint s )
2268 FlushOnStateChange( );
2269 glEsImpl->glClearStencil( s );
2272 #if defined( __MULTITEXTURE_SUPPORT__ )
2274 extern "C" void glMultiTexCoord2fARB( GLenum target, GLfloat s, GLfloat t );
2276 void glMultiTexCoord2fARB( GLenum target, GLfloat s, GLfloat t )
2278 if ( target == GL_TEXTURE0 )
2280 glTexCoord2f( s, t );
2282 else
2284 currentVertexAttrib.s_multi = s;
2285 currentVertexAttrib.t_multi = t;
2288 #endif
2290 /* Vladimir */
2291 /*void glDrawArrays( GLenum mode, int first, int count)
2293 FlushOnStateChange();
2294 glEsImpl->glDrawArrays(mode, first , count);
2295 }*/
2296 void glMultMatrixf( const GLfloat *m )
2298 FlushOnStateChange( );
2299 glEsImpl->glMultMatrixf( m );
2302 void glPixelStorei( GLenum pname, GLint param )
2304 FlushOnStateChange( );
2305 glEsImpl->glPixelStorei( pname, param );
2308 void glFogi( GLenum pname, GLint param )
2310 FlushOnStateChange( );
2311 glEsImpl->glFogf( pname, param );
2314 void glFogf( GLenum pname, GLfloat param )
2316 FlushOnStateChange( );
2317 glEsImpl->glFogf( pname, param );
2320 void glFogfv( GLenum pname, const GLfloat *params )
2322 FlushOnStateChange( );
2323 glEsImpl->glFogfv( pname, params );
2326 void glGetTexParameteriv( GLenum target, GLenum pname, GLint *params )
2328 FlushOnStateChange( );
2329 glEsImpl->glGetTexParameteriv( target, pname, params );
2332 // This gives: called unimplemented OpenGL ES API (Android)
2333 void glTexParameteri( GLenum target, GLenum pname, GLint param )
2335 if ( pname == GL_TEXTURE_BORDER_COLOR )
2337 return; // not supported by opengl es
2339 if ( ( pname == GL_TEXTURE_WRAP_S ||
2340 pname == GL_TEXTURE_WRAP_T ) &&
2341 param == GL_CLAMP )
2343 param = 0x812F;
2346 FlushOnStateChange( );
2347 glEsImpl->glTexParameteri( target, pname, param );
2350 void glTexParameterx( GLenum target, GLenum pname, GLfixed param )
2352 if ( pname == GL_TEXTURE_BORDER_COLOR )
2354 return; // not supported by opengl es
2356 if ( ( pname == GL_TEXTURE_WRAP_S ||
2357 pname == GL_TEXTURE_WRAP_T ) &&
2358 param == GL_CLAMP )
2360 param = 0x812F;
2362 FlushOnStateChange( );
2363 glEsImpl->glTexParameterx( target, pname, param );
2366 void glGenTextures( GLsizei n, GLuint *textures )
2368 FlushOnStateChange( );
2369 glEsImpl->glGenTextures( n, textures );
2372 void glFrontFace( GLenum mode )
2374 FlushOnStateChange( );
2375 glEsImpl->glFrontFace( mode );
2377 // End Vladimir
2379 void glTexEnvi( GLenum target, GLenum pname, GLint param )
2381 if( skipnanogl )
2383 glEsImpl->glTexEnvi( target, pname, param );
2384 return;
2386 if ( target == GL_TEXTURE_ENV )
2388 if ( pname == GL_TEXTURE_ENV_MODE )
2390 if ( param == activetmuState->texture_env_mode.value )
2392 return;
2394 else
2396 FlushOnStateChange( );
2397 glEsImpl->glTexEnvi( target, pname, param );
2398 activetmuState->texture_env_mode.value = param;
2399 return;
2403 FlushOnStateChange( );
2404 glEsImpl->glTexEnvi( target, pname, param );
2407 #ifdef __MULTITEXTURE_SUPPORT__
2408 void glMultiTexCoord3fARB( GLenum a, GLfloat b, GLfloat c, GLfloat )
2410 return glMultiTexCoord2fARB( a, b, c );
2413 void glMultiTexCoord2f( GLenum a, GLfloat b, GLfloat c )
2415 glMultiTexCoord2fARB(a,b,c);
2417 #endif
2418 void glDrawArrays( GLenum mode, GLint first, GLsizei count )
2420 if( skipnanogl )
2422 glEsImpl->glDrawArrays( mode, first, count );
2423 return;
2425 // ensure that all primitives specified between glBegin/glEnd pairs
2426 // are rendered first, and that we have correct tmu in use..
2427 if ( mode == GL_QUADS )
2428 mode = GL_TRIANGLE_FAN;
2429 FlushOnStateChange( );
2430 // setup correct vertex/color/texcoord pointers
2431 if ( arraysValid ||
2432 tmuState0.vertex_array.changed ||
2433 tmuState0.color_array.changed ||
2434 tmuState0.texture_coord_array.changed || tmuState0.normal_array.changed )
2436 glEsImpl->glClientActiveTexture( GL_TEXTURE0 );
2438 if ( arraysValid || tmuState0.vertex_array.changed )
2440 if ( tmuState0.vertex_array.enabled )
2442 glEsImpl->glEnableClientState( GL_VERTEX_ARRAY );
2444 else
2446 glEsImpl->glDisableClientState( GL_VERTEX_ARRAY );
2448 glEsImpl->glVertexPointer( tmuState0.vertex_array.size,
2449 tmuState0.vertex_array.type,
2450 tmuState0.vertex_array.stride,
2451 tmuState0.vertex_array.ptr );
2452 tmuState0.vertex_array.changed = GL_FALSE;
2454 if ( arraysValid || tmuState0.color_array.changed )
2456 if ( tmuState0.color_array.enabled )
2458 glEsImpl->glEnableClientState( GL_COLOR_ARRAY );
2460 else
2462 glEsImpl->glDisableClientState( GL_COLOR_ARRAY );
2463 glEsImpl->glColor4f( currentVertexAttrib.red/255.0f, currentVertexAttrib.green/255.0f,
2464 currentVertexAttrib.blue/255.0f, currentVertexAttrib.alpha/255.0f );
2467 glEsImpl->glColorPointer( tmuState0.color_array.size,
2468 tmuState0.color_array.type,
2469 tmuState0.color_array.stride,
2470 tmuState0.color_array.ptr );
2471 tmuState0.color_array.changed = GL_FALSE;
2473 if ( arraysValid || tmuState0.normal_array.changed )
2475 if ( tmuState0.normal_array.enabled )
2477 glEsImpl->glEnableClientState( GL_NORMAL_ARRAY );
2479 else
2481 glEsImpl->glDisableClientState( GL_NORMAL_ARRAY );
2483 glEsImpl->glNormalPointer( tmuState0.normal_array.type,
2484 tmuState0.normal_array.stride,
2485 tmuState0.normal_array.ptr );
2486 tmuState0.normal_array.changed = GL_FALSE;
2488 if ( arraysValid || tmuState0.texture_coord_array.changed )
2490 tmuState0.texture_coord_array.changed = GL_FALSE;
2491 if ( tmuState0.texture_coord_array.enabled )
2493 glEsImpl->glEnableClientState( GL_TEXTURE_COORD_ARRAY );
2495 else
2497 glEsImpl->glDisableClientState( GL_TEXTURE_COORD_ARRAY );
2499 glEsImpl->glTexCoordPointer( tmuState0.texture_coord_array.size,
2500 tmuState0.texture_coord_array.type,
2501 tmuState0.texture_coord_array.stride,
2502 tmuState0.texture_coord_array.ptr );
2505 if ( arraysValid || tmuState1.texture_coord_array.changed )
2507 tmuState1.texture_coord_array.changed = GL_FALSE;
2508 glEsImpl->glClientActiveTexture( GL_TEXTURE1 );
2509 if ( tmuState1.texture_coord_array.enabled )
2511 glEsImpl->glEnableClientState( GL_TEXTURE_COORD_ARRAY );
2513 else
2515 glEsImpl->glDisableClientState( GL_TEXTURE_COORD_ARRAY );
2517 glEsImpl->glTexCoordPointer( tmuState1.texture_coord_array.size,
2518 tmuState1.texture_coord_array.type,
2519 tmuState1.texture_coord_array.stride,
2520 tmuState1.texture_coord_array.ptr );
2523 arraysValid = GL_FALSE;
2524 glEsImpl->glDrawArrays( mode, first, count );
2526 /*void glNormalPointer(GLenum type, GLsizei stride, const void *ptr)
2528 glEsImpl->glNormalPointer( type, stride, ptr );
2529 }*/
2531 void glCopyTexSubImage2D( GLenum target, GLint level, GLint xoffset, GLint yoffset, GLint x, GLint y, GLsizei width, GLsizei height )
2533 FlushOnStateChange( );
2534 glEsImpl->glCopyTexSubImage2D( target, level, xoffset, yoffset, x, y, width, height );
2537 void glGenFramebuffers( GLsizei n, GLuint *framebuffers )
2539 FlushOnStateChange( );
2540 glEsImpl->glGenFramebuffers( n, framebuffers );
2543 void glGenRenderbuffers( GLsizei n, GLuint *renderbuffers )
2545 FlushOnStateChange( );
2546 glEsImpl->glGenRenderbuffers( n, renderbuffers );
2549 void glBindRenderbuffer( GLenum target, GLuint renderbuffer )
2551 FlushOnStateChange( );
2552 glEsImpl->glBindRenderbuffer( target, renderbuffer );
2555 void glBindFramebuffer( GLenum target, GLuint framebuffer )
2557 FlushOnStateChange( );
2558 glEsImpl->glBindFramebuffer( target, framebuffer );
2561 void glFramebufferRenderbuffer( GLenum target, GLenum attachment, GLenum renderbuffertarget, GLuint renderbuffer )
2563 FlushOnStateChange( );
2564 glEsImpl->glFramebufferRenderbuffer( target, attachment, renderbuffertarget, renderbuffer );
2567 void glDeleteFramebuffers( GLsizei n, const GLuint *framebuffers )
2569 FlushOnStateChange( );
2570 glEsImpl->glDeleteFramebuffers( n, framebuffers );
2573 void glDeleteRenderbuffers( GLsizei n, const GLuint *renderbuffers )
2575 FlushOnStateChange( );
2576 glEsImpl->glDeleteRenderbuffers( n, renderbuffers );
2578 void glFramebufferTexture2D( GLenum target, GLenum attachment, GLenum textarget, GLuint texture, GLint level )
2580 FlushOnStateChange( );
2581 glEsImpl->glFramebufferTexture2D( target, attachment, textarget, texture, level );
2584 void glRenderbufferStorage( GLenum target, GLenum internalformat, GLsizei width, GLsizei height )
2586 FlushOnStateChange( );
2587 glEsImpl->glRenderbufferStorage( target, internalformat, width, height );
2590 void glBindBufferARB( GLuint target, GLuint index )
2592 static int sindex;
2594 if( index && !sindex && !skipnanogl )
2595 FlushOnStateChange();
2596 glEsImpl->glDisableClientState( GL_COLOR_ARRAY );
2597 glEsImpl->glColor4f( currentVertexAttrib.red/255.0f, currentVertexAttrib.green/255.0f,
2598 currentVertexAttrib.blue/255.0f, currentVertexAttrib.alpha/255.0f );
2600 skipnanogl = (!!index) || vboarray;
2601 glEsImpl->glBindBuffer( target, index );
2602 if( sindex && !index )
2604 arraysValid = GL_FALSE;
2606 sindex = index;
2609 void glGenBuffersARB( GLuint count, GLuint *indexes )
2611 glEsImpl->glGenBuffers( count, indexes );
2614 void glDeleteBuffersARB( GLuint count, GLuint *indexes )
2616 glEsImpl->glDeleteBuffers( count, indexes );
2619 void glBufferDataARB( GLuint target, GLuint size, void *buffer, GLuint type )
2621 glEsImpl->glBufferData( target, size, buffer, type );
2624 void glBufferSubDataARB( GLuint target, GLsizei offset, GLsizei size, void *buffer )
2626 glEsImpl->glBufferSubData( target, offset, size, buffer );
2629 GLboolean glIsEnabled(GLenum cap)
2631 FlushOnStateChange( );
2633 if( skipnanogl )
2635 return glEsImpl->glIsEnabled(cap);
2638 switch ( cap )
2640 case GL_ALPHA_TEST:
2641 return nanoglState.alpha_test;
2642 case GL_BLEND:
2643 return nanoglState.blend;
2644 case GL_COLOR_LOGIC_OP:
2645 return nanoglState.color_logic_op;
2646 case GL_COLOR_MATERIAL:
2647 return nanoglState.color_material;
2648 case GL_CULL_FACE:
2649 return nanoglState.cull_face;
2650 case GL_DEPTH_TEST:
2651 return nanoglState.depth_test;
2652 case GL_DITHER:
2653 return nanoglState.dither;
2654 case GL_FOG:
2655 return nanoglState.fog;
2656 case GL_LIGHT0:
2657 return nanoglState.light0;
2658 case GL_LIGHT1:
2659 return nanoglState.light1;
2660 case GL_LIGHT2:
2661 return nanoglState.light2;
2662 case GL_LIGHT3:
2663 return nanoglState.light3;
2664 case GL_LIGHT4:
2665 return nanoglState.light4;
2666 case GL_LIGHT5:
2667 return nanoglState.light5;
2668 case GL_LIGHT6:
2669 return nanoglState.light6;
2670 case GL_LIGHT7:
2671 return nanoglState.light7;
2672 case GL_LIGHTING:
2673 return nanoglState.lighting;
2674 case GL_LINE_SMOOTH:
2675 return nanoglState.line_smooth;
2676 case GL_MULTISAMPLE:
2677 return nanoglState.multisample;
2678 case GL_NORMALIZE:
2679 return nanoglState.normalize;
2680 case GL_POLYGON_OFFSET_FILL:
2681 return nanoglState.polygon_offset_fill;
2682 case GL_RESCALE_NORMAL:
2683 return nanoglState.rescale_normal;
2684 case GL_SAMPLE_ALPHA_TO_COVERAGE:
2685 return nanoglState.sample_alpha_to_coverage;
2686 case GL_SAMPLE_ALPHA_TO_ONE:
2687 return nanoglState.sample_alpha_to_one;
2688 case GL_SAMPLE_COVERAGE:
2689 return nanoglState.sample_coverage;
2690 case GL_SCISSOR_TEST:
2691 return nanoglState.scissor_test;
2692 case GL_STENCIL_TEST:
2693 return nanoglState.stencil_test;
2694 case GL_TEXTURE_2D:
2695 return activetmuState->texture_2d.value;
2696 default:
2697 return glIsEnabled(cap);
2701 void glPushAttrib(GLbitfield mask)
2703 FlushOnStateChange( );
2705 if( (attribStackCount < 0) || (attribStackCount > MAX_ATTRIB_STACK) )
2707 return;
2710 attribStack[attribStackCount].mask = mask;
2712 if( mask & GL_ENABLE_BIT )
2714 for(int i = 0; i < STACK_ATTRIB_ENABLE_BIT_LEN; i++)
2716 attribStack[attribStackCount].enable[i] = glIsEnabled(stackAttribEnableBit[i]);
2720 if( mask & GL_COLOR_BUFFER_BIT )
2722 // TODO
2725 if( mask & GL_CURRENT_BIT )
2727 // TODO
2730 attribStackCount += 1;
2733 void glPopAttrib()
2735 FlushOnStateChange( );
2737 attribStackCount -= 1;
2738 if((attribStackCount < 0) || (attribStackCount > MAX_ATTRIB_STACK))
2740 attribStackCount += 1;
2741 return;
2744 GLbitfield mask = attribStack[attribStackCount].mask;
2746 if( mask & GL_ENABLE_BIT )
2748 for(int i = 0; i < STACK_ATTRIB_ENABLE_BIT_LEN; i++)
2750 if( attribStack[attribStackCount].enable[i] )
2752 glEnable(stackAttribEnableBit[i]);
2754 else
2756 glDisable(stackAttribEnableBit[i]);
2761 if( mask & GL_COLOR_BUFFER_BIT )
2763 // TODO
2766 if( mask & GL_CURRENT_BIT )
2768 // TODO