DEADSOFTWARE

Implement stencil funcs
[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 void InitGLStructs( )
251 ptrVertexAttribArray = vertexattribs;
252 ptrVertexAttribArrayMark = ptrVertexAttribArray;
253 ptrIndexArray = indexArray;
255 memcpy( &nanoglState, &nanoglInitState, sizeof( struct nanoState ) );
256 memcpy( &tmuState0, &tmuInitState, sizeof( struct nanotmuState ) );
257 memcpy( &tmuState1, &tmuInitState, sizeof( struct nanotmuState ) );
258 memcpy( &currentVertexAttrib, &currentVertexAttribInit, sizeof( struct VertexAttrib ) );
260 activetmuState = &tmuState0;
261 wrapperPrimitiveMode = GL_QUADS;
262 useTexCoordArray = GL_FALSE;
263 activetmu = GL_TEXTURE0;
264 clientactivetmu = GL_TEXTURE0;
265 delayedttmuchange = GL_FALSE;
266 delayedtmutarget = GL_TEXTURE0;
267 vertexCount = 0;
268 indexCount = 0;
269 vertexMark = 0;
270 indexbase = 0;
271 arraysValid = GL_FALSE;
274 void ResetNanoState( )
277 if ( tmuState0.color_array.enabled )
279 glEsImpl->glEnableClientState( GL_COLOR_ARRAY );
281 else
283 glEsImpl->glDisableClientState( GL_COLOR_ARRAY );
286 if ( tmuState0.vertex_array.enabled )
288 glEsImpl->glEnableClientState( GL_VERTEX_ARRAY );
290 else
292 glEsImpl->glDisableClientState( GL_VERTEX_ARRAY );
295 if ( tmuState0.texture_coord_array.enabled )
297 glEsImpl->glEnableClientState( GL_TEXTURE_COORD_ARRAY );
299 else
301 glEsImpl->glDisableClientState( GL_TEXTURE_COORD_ARRAY );
304 if ( tmuState0.normal_array.enabled )
306 glEsImpl->glEnableClientState( GL_NORMAL_ARRAY );
308 else
310 glEsImpl->glDisableClientState( GL_NORMAL_ARRAY );
312 glEsImpl->glVertexPointer( tmuState0.vertex_array.size,
313 tmuState0.vertex_array.type,
314 tmuState0.vertex_array.stride,
315 tmuState0.vertex_array.ptr );
317 glEsImpl->glTexCoordPointer( tmuState0.texture_coord_array.size,
318 tmuState0.texture_coord_array.type,
319 tmuState0.texture_coord_array.stride,
320 tmuState0.texture_coord_array.ptr );
322 glEsImpl->glColorPointer( tmuState0.color_array.size,
323 tmuState0.color_array.type,
324 tmuState0.color_array.stride,
325 tmuState0.color_array.ptr );
327 glEsImpl->glNormalPointer(
328 tmuState0.normal_array.type,
329 tmuState0.normal_array.stride,
330 tmuState0.normal_array.ptr );
332 glEsImpl->glMatrixMode( nanoglState.matrixmode );
334 glEsImpl->glColor4f( currentVertexAttrib.red/255.0f, currentVertexAttrib.green/255.0f,
335 currentVertexAttrib.blue/255.0f, currentVertexAttrib.alpha/255.0f );
337 glEsImpl->glBlendFunc( nanoglState.sfactor, nanoglState.dfactor );
339 //glEsImpl->glBindTexture(GL_TEXTURE_2D, stackTextureState);
341 glEsImpl->glTexEnvi( GL_TEXTURE_ENV, GL_TEXTURE_ENV_MODE, activetmuState->texture_env_mode.value );
343 arraysValid = GL_FALSE;
344 skipnanogl = GL_FALSE;
347 void FlushOnStateChange( )
349 if( skipnanogl )
350 return;
351 if ( delayedttmuchange )
353 delayedttmuchange = GL_FALSE;
354 #ifndef USE_CORE_PROFILE
355 glEsImpl->glActiveTexture( delayedtmutarget );
356 #endif
359 if ( !vertexCount )
360 return;
362 if ( !arraysValid )
364 glEsImpl->glClientActiveTexture( GL_TEXTURE0 );
365 glEsImpl->glVertexPointer( 3, GL_FLOAT, sizeof( VertexAttrib ), &vertexattribs[0].x );
366 glEsImpl->glColorPointer( 4, GL_UNSIGNED_BYTE, sizeof( VertexAttrib ), &vertexattribs[0].red );
367 glEsImpl->glTexCoordPointer( 2, GL_FLOAT, sizeof( VertexAttrib ), &vertexattribs[0].s );
368 glEsImpl->glEnableClientState( GL_VERTEX_ARRAY );
369 glEsImpl->glEnableClientState( GL_TEXTURE_COORD_ARRAY );
370 glEsImpl->glEnableClientState( GL_COLOR_ARRAY );
371 #if defined( __MULTITEXTURE_SUPPORT__ )
372 glEsImpl->glClientActiveTexture( GL_TEXTURE1 );
373 glEsImpl->glTexCoordPointer( 2, GL_FLOAT, sizeof( VertexAttrib ), &vertexattribs[0].s_multi );
374 glEsImpl->glEnableClientState( GL_TEXTURE_COORD_ARRAY );
375 glEsImpl->glClientActiveTexture( GL_TEXTURE0 );
376 #endif
377 arraysValid = GL_TRUE;
380 glEsImpl->glDrawElements( GL_TRIANGLES, vertexCount, GL_UNSIGNED_SHORT, indexArray );
382 #if defined( __MULTITEXTURE_SUPPORT__ )
383 useMultiTexCoordArray = GL_FALSE;
384 #endif
385 vertexCount = 0;
386 indexCount = 0;
387 ptrVertexAttribArray = vertexattribs;
388 ptrVertexAttribArrayMark = ptrVertexAttribArray;
389 ptrIndexArray = indexArray;
390 useTexCoordArray = GL_FALSE;
392 void nanoGL_Flush( )
394 FlushOnStateChange( );
396 void nanoGL_Reset( )
398 ResetNanoState( );
400 void glBegin( GLenum mode )
402 wrapperPrimitiveMode = mode;
403 vertexMark = vertexCount;
404 ptrVertexAttribArrayMark = ptrVertexAttribArray;
405 indexbase = indexCount;
408 void glEnd( void )
410 vertexCount += ( (unsigned char *)ptrVertexAttribArray - (unsigned char *)ptrVertexAttribArrayMark ) / sizeof( VertexAttrib );
411 if ( vertexCount < 3 )
413 return;
415 switch ( wrapperPrimitiveMode )
417 case GL_QUADS:
419 *ptrIndexArray++ = indexCount;
420 *ptrIndexArray++ = indexCount + 1;
421 *ptrIndexArray++ = indexCount + 2;
422 *ptrIndexArray++ = indexCount;
423 *ptrIndexArray++ = indexCount + 2;
424 *ptrIndexArray++ = indexCount + 3;
425 indexCount += 4;
426 vertexCount += 2;
428 break;
429 case GL_TRIANGLES:
431 int vcount = ( vertexCount - vertexMark ) / 3;
432 for ( int count = 0; count < vcount; count++ )
434 *ptrIndexArray++ = indexCount;
435 *ptrIndexArray++ = indexCount + 1;
436 *ptrIndexArray++ = indexCount + 2;
437 indexCount += 3;
440 break;
441 case GL_TRIANGLE_STRIP:
443 *ptrIndexArray++ = indexCount;
444 *ptrIndexArray++ = indexCount + 1;
445 *ptrIndexArray++ = indexCount + 2;
446 indexCount += 3;
447 int vcount = ( ( vertexCount - vertexMark ) - 3 );
448 if ( vcount && ( (long)ptrIndexArray & 0x02 ) )
450 *ptrIndexArray++ = indexCount - 1; // 2
451 *ptrIndexArray++ = indexCount - 2; // 1
452 *ptrIndexArray++ = indexCount; // 3
453 indexCount++;
454 vcount -= 1;
455 int odd = vcount & 1;
456 vcount /= 2;
457 unsigned int *longptr = (unsigned int *)ptrIndexArray;
459 for ( int count = 0; count < vcount; count++ )
461 *( longptr++ ) = ( indexCount - 2 ) | ( ( indexCount - 1 ) << 16 );
462 *( longptr++ ) = ( indexCount ) | ( ( indexCount ) << 16 );
463 *( longptr++ ) = ( indexCount - 1 ) | ( ( indexCount + 1 ) << 16 );
464 indexCount += 2;
466 ptrIndexArray = (unsigned short *)( longptr );
467 if ( odd )
469 *ptrIndexArray++ = indexCount - 2; // 2
470 *ptrIndexArray++ = indexCount - 1; // 1
471 *ptrIndexArray++ = indexCount; // 3
472 indexCount++;
475 else
477 //already aligned
478 int odd = vcount & 1;
479 vcount /= 2;
480 unsigned int *longptr = (unsigned int *)ptrIndexArray;
482 for ( int count = 0; count < vcount; count++ )
484 *( longptr++ ) = ( indexCount - 1 ) | ( ( indexCount - 2 ) << 16 );
485 *( longptr++ ) = ( indexCount ) | ( ( indexCount - 1 ) << 16 );
486 *( longptr++ ) = ( indexCount ) | ( ( indexCount + 1 ) << 16 );
487 indexCount += 2;
489 ptrIndexArray = (unsigned short *)( longptr );
490 if ( odd )
493 *ptrIndexArray++ = indexCount - 1; // 2
494 *ptrIndexArray++ = indexCount - 2; // 1
495 *ptrIndexArray++ = indexCount; // 3
496 indexCount++;
499 vertexCount += ( vertexCount - vertexMark - 3 ) * 2;
501 break;
502 case GL_POLYGON:
503 case GL_TRIANGLE_FAN:
505 *ptrIndexArray++ = indexCount++;
506 *ptrIndexArray++ = indexCount++;
507 *ptrIndexArray++ = indexCount++;
508 int vcount = ( ( vertexCount - vertexMark ) - 3 );
509 for ( int count = 0; count < vcount; count++ )
511 *ptrIndexArray++ = indexbase;
512 *ptrIndexArray++ = indexCount - 1;
513 *ptrIndexArray++ = indexCount++;
514 vertexCount += 2;
517 break;
519 default:
520 break;
522 if ( ptrVertexAttribArray - vertexattribs > 20000 * sizeof( VertexAttrib ) ||
523 ptrIndexArray - indexArray > 15000 * sizeof( GLushort ) )
524 FlushOnStateChange( );
527 void glEnable( GLenum cap )
529 if( skipnanogl )
531 glEsImpl->glEnable( cap );
532 return;
534 GLboolean statechanged = GL_FALSE;
535 switch ( cap )
537 case GL_ALPHA_TEST:
539 if ( !nanoglState.alpha_test )
541 nanoglState.alpha_test = GL_TRUE;
542 statechanged = GL_TRUE;
544 break;
546 case GL_BLEND:
548 if ( !nanoglState.blend )
550 nanoglState.blend = GL_TRUE;
551 statechanged = GL_TRUE;
553 break;
555 //case GL_CLIP_PLANEi
556 case GL_COLOR_LOGIC_OP:
558 if ( !nanoglState.color_logic_op )
560 nanoglState.color_logic_op = GL_TRUE;
561 statechanged = GL_TRUE;
563 break;
565 case GL_COLOR_MATERIAL:
567 if ( !nanoglState.color_material )
569 nanoglState.color_material = GL_TRUE;
570 statechanged = GL_TRUE;
572 break;
574 case GL_CULL_FACE:
576 if ( !nanoglState.cull_face )
578 nanoglState.cull_face = GL_TRUE;
579 statechanged = GL_TRUE;
581 break;
583 case GL_DEPTH_TEST:
585 if ( !nanoglState.depth_test )
587 nanoglState.depth_test = GL_TRUE;
588 statechanged = GL_TRUE;
590 break;
592 case GL_DITHER:
594 if ( !nanoglState.dither )
596 nanoglState.dither = GL_TRUE;
597 statechanged = GL_TRUE;
599 break;
601 case GL_FOG:
603 if ( !nanoglState.fog )
605 nanoglState.fog = GL_TRUE;
606 statechanged = GL_TRUE;
608 break;
610 case GL_LIGHT0:
612 if ( !nanoglState.light0 )
614 nanoglState.light0 = GL_TRUE;
615 statechanged = GL_TRUE;
617 break;
619 case GL_LIGHT1:
621 if ( !nanoglState.light1 )
623 nanoglState.light1 = GL_TRUE;
624 statechanged = GL_TRUE;
626 break;
628 case GL_LIGHT2:
630 if ( !nanoglState.light2 )
632 nanoglState.light2 = GL_TRUE;
633 statechanged = GL_TRUE;
635 break;
637 case GL_LIGHT3:
639 if ( !nanoglState.light3 )
641 nanoglState.light3 = GL_TRUE;
642 statechanged = GL_TRUE;
644 break;
646 case GL_LIGHT4:
648 if ( !nanoglState.light4 )
650 nanoglState.light4 = GL_TRUE;
651 statechanged = GL_TRUE;
653 break;
655 case GL_LIGHT5:
657 if ( !nanoglState.light5 )
659 nanoglState.light5 = GL_TRUE;
660 statechanged = GL_TRUE;
662 break;
664 case GL_LIGHT6:
666 if ( !nanoglState.light6 )
668 nanoglState.light6 = GL_TRUE;
669 statechanged = GL_TRUE;
671 break;
673 case GL_LIGHT7:
675 if ( !nanoglState.light7 )
677 nanoglState.light7 = GL_TRUE;
678 statechanged = GL_TRUE;
680 break;
682 case GL_LIGHTING:
684 if ( !nanoglState.lighting )
686 nanoglState.lighting = GL_TRUE;
687 statechanged = GL_TRUE;
689 break;
691 case GL_LINE_SMOOTH:
693 if ( !nanoglState.line_smooth )
695 nanoglState.line_smooth = GL_TRUE;
696 statechanged = GL_TRUE;
698 break;
700 /* case GL_MATRIX_PALETTE_OES:
702 if (!nanoglState.matrix_palette_oes)
704 nanoglState.matrix_palette_oes = GL_TRUE;
705 statechanged = GL_TRUE;
707 break;
708 }*/
709 case GL_MULTISAMPLE:
711 if ( !nanoglState.multisample )
713 nanoglState.multisample = GL_TRUE;
714 statechanged = GL_TRUE;
716 break;
718 case GL_NORMALIZE:
720 if ( !nanoglState.normalize )
722 nanoglState.normalize = GL_TRUE;
723 statechanged = GL_TRUE;
725 break;
727 /* case GL_POINT_SPRITE_OES:
729 if (!nanoglState.point_sprite_oes)
731 nanoglState.point_sprite_oes = GL_TRUE;
732 statechanged = GL_TRUE;
734 break;
735 }*/
736 case GL_POLYGON_OFFSET_FILL:
738 if ( !nanoglState.polygon_offset_fill )
740 nanoglState.polygon_offset_fill = GL_TRUE;
741 statechanged = GL_TRUE;
743 break;
745 case GL_RESCALE_NORMAL:
747 if ( !nanoglState.rescale_normal )
749 nanoglState.rescale_normal = GL_TRUE;
750 statechanged = GL_TRUE;
752 break;
754 case GL_SAMPLE_ALPHA_TO_COVERAGE:
756 if ( !nanoglState.sample_alpha_to_coverage )
758 nanoglState.sample_alpha_to_coverage = GL_TRUE;
759 statechanged = GL_TRUE;
761 break;
763 case GL_SAMPLE_ALPHA_TO_ONE:
765 if ( !nanoglState.sample_alpha_to_one )
767 nanoglState.sample_alpha_to_one = GL_TRUE;
768 statechanged = GL_TRUE;
770 break;
772 case GL_SAMPLE_COVERAGE:
774 if ( !nanoglState.sample_coverage )
776 nanoglState.sample_coverage = GL_TRUE;
777 statechanged = GL_TRUE;
779 break;
781 case GL_SCISSOR_TEST:
783 if ( !nanoglState.scissor_test )
785 nanoglState.scissor_test = GL_TRUE;
786 statechanged = GL_TRUE;
788 break;
790 case GL_STENCIL_TEST:
792 if (!nanoglState.stencil_test)
794 nanoglState.stencil_test = GL_TRUE;
795 statechanged = GL_TRUE;
797 break;
799 case GL_TEXTURE_2D:
801 if ( !activetmuState->texture_2d.value )
803 FlushOnStateChange( );
804 glEsImpl->glEnable( cap );
805 activetmuState->texture_2d.value = GL_TRUE;
806 return;
808 break;
810 #if 0 // todo: implement cubemap texgen
811 case GL_TEXTURE_GEN_S:
812 case GL_TEXTURE_GEN_T:
813 case GL_TEXTURE_GEN_R:
814 case GL_TEXTURE_GEN_Q:
816 FlushOnStateChange( );
817 nanoglState.texgen = true;
818 return;
820 #endif
821 default:
822 break;
825 if ( statechanged )
827 FlushOnStateChange( );
828 glEsImpl->glEnable( cap );
832 void glDisable( GLenum cap )
834 if( skipnanogl )
836 glEsImpl->glDisable( cap );
837 return;
839 GLboolean statechanged = GL_FALSE;
840 switch ( cap )
842 case GL_ALPHA_TEST:
844 if ( nanoglState.alpha_test )
846 nanoglState.alpha_test = GL_FALSE;
847 statechanged = GL_TRUE;
849 break;
851 case GL_BLEND:
853 if ( nanoglState.blend )
855 nanoglState.blend = GL_FALSE;
856 statechanged = GL_TRUE;
858 break;
860 //case GL_CLIP_PLANEi
861 case GL_COLOR_LOGIC_OP:
863 if ( nanoglState.color_logic_op )
865 nanoglState.color_logic_op = GL_FALSE;
866 statechanged = GL_TRUE;
868 break;
870 case GL_COLOR_MATERIAL:
872 if ( nanoglState.color_material )
874 nanoglState.color_material = GL_FALSE;
875 statechanged = GL_TRUE;
877 break;
879 case GL_CULL_FACE:
881 if ( nanoglState.cull_face )
883 nanoglState.cull_face = GL_FALSE;
884 statechanged = GL_TRUE;
886 break;
888 case GL_DEPTH_TEST:
890 if ( nanoglState.depth_test )
892 nanoglState.depth_test = GL_FALSE;
893 statechanged = GL_TRUE;
895 break;
897 case GL_DITHER:
899 if ( nanoglState.dither )
901 nanoglState.dither = GL_FALSE;
902 statechanged = GL_TRUE;
904 break;
906 case GL_FOG:
908 if ( nanoglState.fog )
910 nanoglState.fog = GL_FALSE;
911 statechanged = GL_TRUE;
913 break;
915 case GL_LIGHT0:
917 if ( !nanoglState.light0 )
919 nanoglState.light0 = GL_FALSE;
920 statechanged = GL_TRUE;
922 break;
924 case GL_LIGHT1:
926 if ( !nanoglState.light1 )
928 nanoglState.light1 = GL_FALSE;
929 statechanged = GL_TRUE;
931 break;
933 case GL_LIGHT2:
935 if ( !nanoglState.light2 )
937 nanoglState.light2 = GL_FALSE;
938 statechanged = GL_TRUE;
940 break;
942 case GL_LIGHT3:
944 if ( !nanoglState.light3 )
946 nanoglState.light3 = GL_FALSE;
947 statechanged = GL_TRUE;
949 break;
951 case GL_LIGHT4:
953 if ( !nanoglState.light4 )
955 nanoglState.light4 = GL_FALSE;
956 statechanged = GL_TRUE;
958 break;
960 case GL_LIGHT5:
962 if ( !nanoglState.light5 )
964 nanoglState.light5 = GL_FALSE;
965 statechanged = GL_TRUE;
967 break;
969 case GL_LIGHT6:
971 if ( !nanoglState.light6 )
973 nanoglState.light6 = GL_FALSE;
974 statechanged = GL_TRUE;
976 break;
978 case GL_LIGHT7:
980 if ( !nanoglState.light7 )
982 nanoglState.light7 = GL_FALSE;
983 statechanged = GL_TRUE;
985 break;
987 case GL_LIGHTING:
989 if ( nanoglState.lighting )
991 nanoglState.lighting = GL_FALSE;
992 statechanged = GL_TRUE;
994 break;
996 case GL_LINE_SMOOTH:
998 if ( nanoglState.line_smooth )
1000 nanoglState.line_smooth = GL_FALSE;
1001 statechanged = GL_TRUE;
1003 break;
1005 /* case GL_MATRIX_PALETTE_OES:
1007 if (nanoglState.matrix_palette_oes)
1009 nanoglState.matrix_palette_oes = GL_FALSE;
1010 statechanged = GL_TRUE;
1012 break;
1013 }*/
1014 case GL_MULTISAMPLE:
1016 if ( nanoglState.multisample )
1018 nanoglState.multisample = GL_FALSE;
1019 statechanged = GL_TRUE;
1021 break;
1023 case GL_NORMALIZE:
1025 if ( nanoglState.normalize )
1027 nanoglState.normalize = GL_FALSE;
1028 statechanged = GL_TRUE;
1030 break;
1032 /* case GL_POINT_SPRITE_OES:
1034 if (nanoglState.point_sprite_oes)
1036 nanoglState.point_sprite_oes = GL_FALSE;
1037 statechanged = GL_TRUE;
1039 break;
1040 }*/
1041 case GL_POLYGON_OFFSET_FILL:
1043 if ( nanoglState.polygon_offset_fill )
1045 nanoglState.polygon_offset_fill = GL_FALSE;
1046 statechanged = GL_TRUE;
1048 break;
1050 case GL_RESCALE_NORMAL:
1052 if ( nanoglState.rescale_normal )
1054 nanoglState.rescale_normal = GL_FALSE;
1055 statechanged = GL_TRUE;
1057 break;
1059 case GL_SAMPLE_ALPHA_TO_COVERAGE:
1061 if ( nanoglState.sample_alpha_to_coverage )
1063 nanoglState.sample_alpha_to_coverage = GL_FALSE;
1064 statechanged = GL_TRUE;
1066 break;
1068 case GL_SAMPLE_ALPHA_TO_ONE:
1070 if ( nanoglState.sample_alpha_to_one )
1072 nanoglState.sample_alpha_to_one = GL_FALSE;
1073 statechanged = GL_TRUE;
1075 break;
1077 case GL_SAMPLE_COVERAGE:
1079 if ( nanoglState.sample_coverage )
1081 nanoglState.sample_coverage = GL_FALSE;
1082 statechanged = GL_TRUE;
1084 break;
1086 case GL_SCISSOR_TEST:
1088 if ( nanoglState.scissor_test )
1090 nanoglState.scissor_test = GL_FALSE;
1091 statechanged = GL_TRUE;
1093 break;
1095 case GL_STENCIL_TEST:
1097 if (nanoglState.stencil_test)
1099 nanoglState.stencil_test = GL_FALSE;
1100 statechanged = GL_TRUE;
1102 break;
1104 case GL_TEXTURE_2D:
1106 if ( activetmuState->texture_2d.value )
1108 FlushOnStateChange( );
1109 glEsImpl->glDisable( cap );
1110 activetmuState->texture_2d.value = GL_FALSE;
1111 return;
1113 break;
1115 #if 0
1116 case GL_TEXTURE_GEN_S:
1117 case GL_TEXTURE_GEN_T:
1118 case GL_TEXTURE_GEN_R:
1119 case GL_TEXTURE_GEN_Q:
1121 FlushOnStateChange( );
1122 nanoglState.texgen = false;
1123 return;
1125 #endif
1126 default:
1127 break;
1130 if ( statechanged )
1132 FlushOnStateChange( );
1133 glEsImpl->glDisable( cap );
1137 void glVertex2f( GLfloat x, GLfloat y )
1139 glVertex3f( x, y, 0.0f );
1142 __FORCEINLINE unsigned int ClampTo255( float value )
1144 unsigned int retval = (unsigned int)( value );
1145 if ( retval > 255 )
1147 retval = 255;
1149 return retval;
1152 void glColor3f( GLfloat red, GLfloat green, GLfloat blue )
1154 currentVertexAttrib.red = (unsigned char)ClampTo255( red * 255.0f );
1155 currentVertexAttrib.green = (unsigned char)ClampTo255( green * 255.0f );
1156 currentVertexAttrib.blue = (unsigned char)ClampTo255( blue * 255.0f );
1157 currentVertexAttrib.alpha = 255;
1160 void glTexCoord2fv( const GLfloat *v )
1162 memcpy( &currentVertexAttrib.s, v, 2 * sizeof( float ) );
1165 void glTexCoord2f( GLfloat s, GLfloat t )
1167 currentVertexAttrib.s = s;
1168 currentVertexAttrib.t = t;
1171 void glViewport( GLint x, GLint y, GLsizei width, GLsizei height )
1173 FlushOnStateChange( );
1174 glEsImpl->glViewport( x, y, width, height );
1177 void glLoadIdentity( void )
1179 FlushOnStateChange( );
1180 glEsImpl->glLoadIdentity( );
1183 void glColor4f( GLfloat red, GLfloat green, GLfloat blue, GLfloat alpha )
1185 currentVertexAttrib.red = (unsigned char)ClampTo255( red * 255.0f );
1186 currentVertexAttrib.green = (unsigned char)ClampTo255( green * 255.0f );
1187 currentVertexAttrib.blue = (unsigned char)ClampTo255( blue * 255.0f );
1188 currentVertexAttrib.alpha = (unsigned char)ClampTo255( alpha * 255.0f );
1191 void glOrtho( GLdouble left, GLdouble right, GLdouble bottom, GLdouble top, GLdouble zNear, GLdouble zFar )
1193 FlushOnStateChange( );
1194 #ifdef USE_CORE_PROFILE
1195 glEsImpl->glOrtho( left, right, bottom, top, zNear, zFar );
1196 #else
1197 glEsImpl->glOrthof( left, right, bottom, top, zNear, zFar );
1198 #endif
1201 // Rikku2000: Light
1202 void glLightf( GLenum light, GLenum pname, GLfloat param )
1204 FlushOnStateChange( );
1206 glEsImpl->glLightf( light, pname, param );
1208 void glLightfv( GLenum light, GLenum pname, const GLfloat *params )
1210 FlushOnStateChange( );
1212 glEsImpl->glLightfv( light, pname, params );
1214 void glLightModelf( GLenum pname, GLfloat param )
1216 FlushOnStateChange( );
1218 glEsImpl->glLightModelf( pname, param );
1220 void glLightModelfv( GLenum pname, const GLfloat *params )
1222 FlushOnStateChange( );
1224 glEsImpl->glLightModelfv( pname, params );
1226 void glMaterialf( GLenum face, GLenum pname, GLfloat param )
1228 FlushOnStateChange( );
1230 glEsImpl->glMaterialf( face, pname, param );
1232 void glMaterialfv( GLenum face, GLenum pname, const GLfloat *params )
1234 FlushOnStateChange( );
1236 glEsImpl->glMaterialfv( face, pname, params );
1238 void glColorMaterial( GLenum face, GLenum mode )
1240 FlushOnStateChange( );
1242 glEsImpl->glColorMaterial( face, mode );
1245 void glMatrixMode( GLenum mode )
1247 if ( nanoglState.matrixmode == mode )
1249 return;
1251 nanoglState.matrixmode = mode;
1252 FlushOnStateChange( );
1253 glEsImpl->glMatrixMode( mode );
1256 void glTexParameterf( GLenum target, GLenum pname, GLfloat param )
1258 if ( pname == GL_TEXTURE_BORDER_COLOR )
1260 return; // not supported by opengl es
1262 if ( ( pname == GL_TEXTURE_WRAP_S ||
1263 pname == GL_TEXTURE_WRAP_T ) &&
1264 param == GL_CLAMP )
1266 param = 0x812F;
1269 FlushOnStateChange( );
1270 glEsImpl->glTexParameterf( target, pname, param );
1273 void glTexParameterfv( GLenum target, GLenum pname, const GLfloat *params )
1275 glTexParameterf( target, pname, params[0] );
1278 void glTexImage2D( GLenum target, GLint level, GLint internalformat, GLsizei width, GLsizei height, GLint border, GLenum format, GLenum type, const GLvoid *pixels )
1280 unsigned char *data = (unsigned char*)pixels;
1282 if( pixels && internalformat == GL_RGB && format == GL_RGBA ) // strip alpha from texture
1284 unsigned char *in = data, *out;
1285 int i = 0, size = width * height * 4;
1287 data = out = (unsigned char*)malloc( size );
1289 for( i = 0; i < size; i += 4, in += 4, out += 4 )
1291 memcpy( out, in, 3 );
1292 out[3] = 255;
1296 internalformat = format;
1297 glEsImpl->glTexImage2D( target, level, internalformat, width, height, border, format, type, data );
1299 if( data != pixels )
1300 free(data);
1303 void glDrawBuffer( GLenum /*mode*/ )
1307 void glTranslatef( GLfloat x, GLfloat y, GLfloat z )
1309 FlushOnStateChange( );
1310 glEsImpl->glTranslatef( x, y, z );
1313 void glRotatef( GLfloat angle, GLfloat x, GLfloat y, GLfloat z )
1315 FlushOnStateChange( );
1316 glEsImpl->glRotatef( angle, x, y, z );
1319 void glScalef( GLfloat x, GLfloat y, GLfloat z )
1321 FlushOnStateChange( );
1322 glEsImpl->glScalef( x, y, z );
1325 void glDepthRange( GLclampd zNear, GLclampd zFar )
1327 if ( ( nanoglState.depth_range_near == zNear ) && ( nanoglState.depth_range_far == zFar ) )
1329 return;
1331 else
1333 nanoglState.depth_range_near = zNear;
1334 nanoglState.depth_range_far = zFar;
1336 FlushOnStateChange( );
1337 #ifdef USE_CORE_PROFILE
1338 glEsImpl->glDepthRange( zNear, zFar );
1339 #else
1340 glEsImpl->glDepthRangef( zNear, zFar );
1341 #endif
1344 void glDepthFunc( GLenum func )
1346 if ( nanoglState.depth_func == func )
1348 return;
1350 else
1352 nanoglState.depth_func = func;
1354 FlushOnStateChange( );
1355 glEsImpl->glDepthFunc( func );
1358 void glFinish( void )
1360 FlushOnStateChange( );
1361 glEsImpl->glFinish( );
1364 void glGetFloatv( GLenum pname, GLfloat *params )
1366 FlushOnStateChange( );
1367 glEsImpl->glGetFloatv( pname, params );
1370 void glCullFace( GLenum mode )
1372 if ( nanoglState.cullface == mode )
1374 return;
1376 else
1378 nanoglState.cullface = mode;
1380 FlushOnStateChange( );
1381 glEsImpl->glCullFace( mode );
1384 void glFrustum( GLdouble left, GLdouble right, GLdouble bottom, GLdouble top, GLdouble zNear, GLdouble zFar )
1386 FlushOnStateChange( );
1387 glEsImpl->glFrustumf( left, right, bottom, top, zNear, zFar );
1390 void glClear( GLbitfield mask )
1392 FlushOnStateChange( );
1393 glEsImpl->glClear( mask );
1396 void glVertex3f( GLfloat x, GLfloat y, GLfloat z )
1398 GLfloat *vert = (GLfloat *)ptrVertexAttribArray++;
1399 *vert++ = x;
1400 *vert++ = y;
1401 *vert++ = z;
1402 #if defined( __MULTITEXTURE_SUPPORT__ )
1403 memcpy( vert, &currentVertexAttrib.red, 5 * sizeof( GLfloat ) );
1404 #else
1405 memcpy( vert + 1, &currentVertexAttrib.red, 3 * sizeof( GLfloat ) );
1406 #endif
1409 void glColor4fv( const GLfloat *v )
1411 currentVertexAttrib.red = (unsigned char)ClampTo255( v[0] * 255.0f );
1412 currentVertexAttrib.green = (unsigned char)ClampTo255( v[1] * 255.0f );
1413 currentVertexAttrib.blue = (unsigned char)ClampTo255( v[2] * 255.0f );
1414 currentVertexAttrib.alpha = (unsigned char)ClampTo255( v[3] * 255.0f );
1415 if( skipnanogl )
1416 glEsImpl->glColor4f( currentVertexAttrib.red/255.0f, currentVertexAttrib.green/255.0f,
1417 currentVertexAttrib.blue/255.0f, currentVertexAttrib.alpha/255.0f );
1420 void glColor3ubv( const GLubyte *v )
1422 currentVertexAttrib.red = v[0];
1423 currentVertexAttrib.green = v[1];
1424 currentVertexAttrib.blue = v[2];
1425 currentVertexAttrib.alpha = 255;
1426 if( skipnanogl )
1427 glEsImpl->glColor4f( currentVertexAttrib.red/255.0f, currentVertexAttrib.green/255.0f,
1428 currentVertexAttrib.blue/255.0f, currentVertexAttrib.alpha/255.0f );
1431 void glColor4ubv( const GLubyte *v )
1433 //*((unsigned int*)(&currentVertexAttrib.red)) = *((unsigned int*)(v));
1434 currentVertexAttrib.red = v[0];
1435 currentVertexAttrib.green = v[1];
1436 currentVertexAttrib.blue = v[2];
1437 currentVertexAttrib.alpha = v[3];
1438 if( skipnanogl )
1439 glEsImpl->glColor4f( currentVertexAttrib.red/255.0f, currentVertexAttrib.green/255.0f,
1440 currentVertexAttrib.blue/255.0f, currentVertexAttrib.alpha/255.0f );
1443 void glColor3fv( const GLfloat *v )
1445 currentVertexAttrib.red = (unsigned char)ClampTo255( v[0] * 255.0f );
1446 currentVertexAttrib.green = (unsigned char)ClampTo255( v[1] * 255.0f );
1447 currentVertexAttrib.blue = (unsigned char)ClampTo255( v[2] * 255.0f );
1448 currentVertexAttrib.alpha = 255;
1449 if( skipnanogl )
1450 glEsImpl->glColor4f( currentVertexAttrib.red/255.0f, currentVertexAttrib.green/255.0f,
1451 currentVertexAttrib.blue/255.0f, currentVertexAttrib.alpha/255.0f );
1454 //-- nicknekit: xash3d funcs --
1456 void glColor4ub( GLubyte red, GLubyte green, GLubyte blue, GLubyte alpha )
1458 currentVertexAttrib.red = red;
1459 currentVertexAttrib.green = green;
1460 currentVertexAttrib.blue = blue;
1461 currentVertexAttrib.alpha = alpha;
1462 if( skipnanogl )
1463 glEsImpl->glColor4f( currentVertexAttrib.red/255.0f, currentVertexAttrib.green/255.0f,
1464 currentVertexAttrib.blue/255.0f, currentVertexAttrib.alpha/255.0f );
1467 void glColor3ub( GLubyte red, GLubyte green, GLubyte blue )
1469 currentVertexAttrib.red = red;
1470 currentVertexAttrib.green = green;
1471 currentVertexAttrib.blue = blue;
1472 currentVertexAttrib.alpha = 255;
1473 if( skipnanogl )
1474 glEsImpl->glColor4f( currentVertexAttrib.red/255.0f, currentVertexAttrib.green/255.0f,
1475 currentVertexAttrib.blue/255.0f, currentVertexAttrib.alpha/255.0f );
1478 void glNormal3fv( const GLfloat *v )
1480 FlushOnStateChange( );
1481 glEsImpl->glNormal3f( v[0], v[1], v[2] );
1484 void glCopyTexImage2D( GLenum target, GLint level, GLenum internalformat, GLint x, GLint y, GLsizei width, GLsizei height, GLint border )
1486 FlushOnStateChange( );
1487 glEsImpl->glCopyTexImage2D( target, level, internalformat, x, y, width, height, border );
1490 void glTexImage1D( GLenum target, GLint level, GLint internalformat, GLsizei width, GLint border, GLenum format, GLenum type, const GLvoid *pixels )
1492 glTexImage2D( GL_TEXTURE_2D, level, internalformat, width, 1, border, format, type, pixels );
1495 void glTexImage3D( GLenum target, GLint level, GLint internalformat, GLsizei width, GLsizei height, GLsizei depth, GLint border, GLenum format, GLenum type, const GLvoid *pixels )
1497 glTexImage2D( GL_TEXTURE_2D, level, internalformat, width, height, border, format, type, pixels );
1500 void glTexSubImage1D( GLenum target, GLint level, GLint xoffset, GLsizei width, GLenum format, GLenum type, const GLvoid *pixels )
1502 glTexSubImage2D( target, level, xoffset, 0, width, 1, format, type, pixels );
1505 void glTexSubImage3D( GLenum target, GLint level,
1506 GLint xoffset, GLint yoffset,
1507 GLint zoffset, GLsizei width,
1508 GLsizei height, GLsizei depth,
1509 GLenum format,
1510 GLenum type, const GLvoid *pixels )
1512 glTexSubImage2D( target, level, xoffset, yoffset, width, height, format, type, pixels );
1515 GLboolean glIsTexture( GLuint texture )
1517 FlushOnStateChange( );
1518 return glEsImpl->glIsTexture( texture );
1521 // TODO: add native normal/reflection map texgen support
1523 void glTexGeni( GLenum coord, GLenum pname, GLint param )
1525 FlushOnStateChange();
1526 //glEsImpl->glTexGeniOES( coord, pname, param );
1529 void glTexGenfv( GLenum coord, GLenum pname, const GLfloat *params )
1531 FlushOnStateChange();
1532 //glEsImpl->glTexGenfvOES( coord, pname, params );
1535 //-- --//
1537 void glHint( GLenum target, GLenum mode )
1539 FlushOnStateChange( );
1540 glEsImpl->glHint( target, mode );
1543 void glBlendFunc( GLenum sfactor, GLenum dfactor )
1545 if( skipnanogl )
1547 glEsImpl->glBlendFunc( sfactor, dfactor );
1548 return;
1550 if ( ( nanoglState.sfactor == sfactor ) && ( nanoglState.dfactor == dfactor ) )
1552 return;
1555 nanoglState.sfactor = sfactor;
1556 nanoglState.dfactor = dfactor;
1557 FlushOnStateChange( );
1558 glEsImpl->glBlendFunc( sfactor, dfactor );
1561 void glPopMatrix( void )
1563 FlushOnStateChange( );
1564 glEsImpl->glPopMatrix( );
1567 void glShadeModel( GLenum mode )
1569 if ( nanoglState.shademodel == mode )
1571 return;
1573 nanoglState.shademodel = mode;
1574 FlushOnStateChange( );
1575 glEsImpl->glShadeModel( mode );
1578 void glPushMatrix( void )
1580 FlushOnStateChange( );
1581 glEsImpl->glPushMatrix( );
1584 void glTexEnvf( GLenum target, GLenum pname, GLfloat param )
1586 if( skipnanogl )
1588 glEsImpl->glTexEnvf( target, pname, param );
1589 return;
1591 if ( target == GL_TEXTURE_ENV )
1593 if ( pname == GL_TEXTURE_ENV_MODE )
1595 if ( param == activetmuState->texture_env_mode.value )
1597 return;
1599 else
1601 FlushOnStateChange( );
1602 glEsImpl->glTexEnvf( target, pname, param );
1603 activetmuState->texture_env_mode.value = param;
1604 return;
1608 FlushOnStateChange( );
1609 glEsImpl->glTexEnvf( target, pname, param );
1612 void glVertex3fv( const GLfloat *v )
1614 GLfloat *vert = (GLfloat *)ptrVertexAttribArray++;
1615 memcpy( vert, v, 3 * sizeof( GLfloat ) );
1616 #if defined( __MULTITEXTURE_SUPPORT__ )
1617 memcpy( vert + 3, &currentVertexAttrib.red, 5 * sizeof( GLfloat ) );
1618 #else
1619 memcpy( vert + 4, &currentVertexAttrib.red, 3 * sizeof( GLfloat ) );
1620 #endif
1623 void glDepthMask( GLboolean flag )
1625 if( !skipnanogl )
1627 if ( nanoglState.depthmask == flag )
1629 return;
1631 nanoglState.depthmask = flag;
1632 FlushOnStateChange( );
1634 glEsImpl->glDepthMask( flag );
1637 void glBindTexture( GLenum target, GLuint texture )
1639 if( skipnanogl )
1641 glEsImpl->glBindTexture( target,texture );
1642 return;
1644 if ( activetmuState->boundtexture.value == texture )
1646 return;
1648 FlushOnStateChange( );
1649 activetmuState->boundtexture.value = texture;
1650 glEsImpl->glBindTexture( target, texture );
1653 void glGetIntegerv( GLenum pname, GLint *params )
1655 FlushOnStateChange( );
1656 glEsImpl->glGetIntegerv( pname, params );
1659 GLubyte nano_extensions_string[4096];
1660 const GLubyte *glGetString( GLenum name )
1663 if ( name == GL_EXTENSIONS )
1665 #if defined( __MULTITEXTURE_SUPPORT__ )
1666 sprintf( (char *)nano_extensions_string, "%s %s", glEsImpl->glGetString( name ), "GL_ARB_multitexture EXT_texture_env_add" );
1667 #else
1668 sprintf( (char *)nano_extensions_string, "%s %s", glEsImpl->glGetString( name ), "EXT_texture_env_add" );
1669 #endif
1670 return nano_extensions_string;
1672 return glEsImpl->glGetString( name );
1675 void glAlphaFunc( GLenum func, GLclampf ref )
1677 FlushOnStateChange( );
1678 glEsImpl->glAlphaFunc( func, ref );
1681 void glFlush( void )
1683 FlushOnStateChange( );
1684 glEsImpl->glFlush( );
1687 void glReadPixels( GLint x, GLint y, GLsizei width, GLsizei height, GLenum format, GLenum type, GLvoid *pixels )
1689 if ( format == GL_DEPTH_COMPONENT )
1691 // OpenglEs 1.1 does not support reading depth buffer without an extension
1692 memset( pixels, 0xff, 4 );
1693 return;
1695 FlushOnStateChange( );
1696 glEsImpl->glReadPixels( x, y, width, height, format, type, pixels );
1699 void glReadBuffer( GLenum /*mode*/ )
1703 void glLoadMatrixf( const GLfloat *m )
1705 FlushOnStateChange( );
1706 glEsImpl->glLoadMatrixf( m );
1709 void glTexSubImage2D( GLenum target, GLint level, GLint xoffset, GLint yoffset, GLsizei width, GLsizei height, GLenum format, GLenum type, const GLvoid *pixels )
1711 FlushOnStateChange( );
1712 glEsImpl->glTexSubImage2D( target, level, xoffset, yoffset, width, height, format, type, pixels );
1715 void glClearColor( GLclampf red, GLclampf green, GLclampf blue, GLclampf alpha )
1717 FlushOnStateChange( );
1718 glEsImpl->glClearColor( red, green, blue, alpha );
1721 GLenum glGetError( void )
1723 //FlushOnStateChange();
1724 return GL_NO_ERROR; //glEsImpl->glGetError();
1727 void glActiveTexture( GLenum texture )
1729 if( skipnanogl )
1731 glEsImpl->glActiveTexture( texture );
1732 return;
1734 if ( activetmu == texture )
1736 return;
1738 if ( delayedttmuchange )
1740 delayedttmuchange = GL_FALSE;
1742 else
1744 delayedttmuchange = GL_TRUE;
1745 delayedtmutarget = texture;
1747 if ( texture == GL_TEXTURE0 )
1749 activetmuState = &tmuState0;
1751 else
1753 activetmuState = &tmuState1;
1755 activetmu = texture;
1758 void glActiveTextureARB( GLenum texture )
1760 if( skipnanogl )
1762 glEsImpl->glActiveTexture( texture );
1763 return;
1765 if ( activetmu == texture )
1767 return;
1769 if ( delayedttmuchange )
1771 delayedttmuchange = GL_FALSE;
1773 else
1775 delayedttmuchange = GL_TRUE;
1776 delayedtmutarget = texture;
1778 if ( texture == GL_TEXTURE0 )
1780 activetmuState = &tmuState0;
1782 else
1784 activetmuState = &tmuState1;
1786 activetmu = texture;
1789 void glClientActiveTexture( GLenum texture )
1791 if( skipnanogl )
1793 glEsImpl->glClientActiveTexture( texture );
1794 return;
1796 clientactivetmu = texture;
1798 void glClientActiveTextureARB( GLenum texture )
1800 if( skipnanogl )
1802 glEsImpl->glClientActiveTexture( texture );
1803 return;
1805 clientactivetmu = texture;
1809 void glPolygonMode( GLenum face, GLenum mode )
1813 void glDeleteTextures( GLsizei n, const GLuint *textures )
1815 FlushOnStateChange( );
1816 glEsImpl->glDeleteTextures( n, textures );
1819 void glClearDepth( GLclampd depth )
1821 FlushOnStateChange( );
1822 glEsImpl->glClearDepthf( depth );
1825 void glClipPlane( GLenum plane, const GLdouble *equation )
1827 FlushOnStateChange( );
1828 float array[4];
1829 array[0] = ( GLfloat )( equation[0] );
1830 array[1] = ( GLfloat )( equation[1] );
1831 array[2] = ( GLfloat )( equation[2] );
1832 array[3] = ( GLfloat )( equation[3] );
1833 glEsImpl->glClipPlanef( plane, array );
1836 void glScissor( GLint x, GLint y, GLsizei width, GLsizei height )
1838 FlushOnStateChange( );
1839 glEsImpl->glScissor( x, y, width, height );
1842 void glPointSize( GLfloat size )
1844 FlushOnStateChange( );
1845 glEsImpl->glPointSize( size );
1848 void glArrayElement( GLint i )
1851 void glLineWidth( GLfloat width )
1854 void glCallList( GLuint list )
1857 void glColorMask( GLboolean red, GLboolean green, GLboolean blue, GLboolean alpha )
1859 FlushOnStateChange( );
1860 glEsImpl->glColorMask( red, green, blue, alpha );
1862 void glStencilFunc( GLenum func, GLint ref, GLuint mask )
1864 FlushOnStateChange( );
1865 glEsImpl->glStencilFunc( func, ref, mask );
1867 void glStencilOp( GLenum fail, GLenum zfail, GLenum zpass )
1869 FlushOnStateChange( );
1870 glEsImpl->glStencilOp( fail, zfail, zpass );
1873 struct ptrstate vertex_array;
1874 struct ptrstate color_array;
1875 struct ptrstate texture_coord_array;
1877 void glDrawElements( GLenum mode, GLsizei count, GLenum type, const GLvoid *indices )
1879 if( skipnanogl )
1881 glEsImpl->glDrawElements( mode, count, type, indices );
1882 return;
1884 // ensure that all primitives specified between glBegin/glEnd pairs
1885 // are rendered first, and that we have correct tmu in use..
1886 FlushOnStateChange( );
1887 // setup correct vertex/color/texcoord pointers
1888 if ( arraysValid ||
1889 tmuState0.vertex_array.changed ||
1890 tmuState0.color_array.changed ||
1891 tmuState0.texture_coord_array.changed || tmuState0.normal_array.changed )
1893 glEsImpl->glClientActiveTexture( GL_TEXTURE0 );
1895 if ( arraysValid || tmuState0.vertex_array.changed )
1897 if ( tmuState0.vertex_array.enabled )
1899 glEsImpl->glEnableClientState( GL_VERTEX_ARRAY );
1901 else
1903 glEsImpl->glDisableClientState( GL_VERTEX_ARRAY );
1905 glEsImpl->glVertexPointer( tmuState0.vertex_array.size,
1906 tmuState0.vertex_array.type,
1907 tmuState0.vertex_array.stride,
1908 tmuState0.vertex_array.ptr );
1909 tmuState0.vertex_array.changed = GL_FALSE;
1911 if ( arraysValid || tmuState0.color_array.changed )
1913 if ( tmuState0.color_array.enabled )
1915 glEsImpl->glEnableClientState( GL_COLOR_ARRAY );
1917 else
1919 glEsImpl->glDisableClientState( GL_COLOR_ARRAY );
1920 glEsImpl->glColor4f( currentVertexAttrib.red/255.0f, currentVertexAttrib.green/255.0f,
1921 currentVertexAttrib.blue/255.0f, currentVertexAttrib.alpha/255.0f );
1924 glEsImpl->glColorPointer( tmuState0.color_array.size,
1925 tmuState0.color_array.type,
1926 tmuState0.color_array.stride,
1927 tmuState0.color_array.ptr );
1928 tmuState0.color_array.changed = GL_FALSE;
1930 if ( arraysValid || tmuState0.normal_array.changed )
1932 if ( tmuState0.normal_array.enabled )
1934 glEsImpl->glEnableClientState( GL_NORMAL_ARRAY );
1936 else
1938 glEsImpl->glDisableClientState( GL_NORMAL_ARRAY );
1940 glEsImpl->glNormalPointer( tmuState0.normal_array.type,
1941 tmuState0.normal_array.stride,
1942 tmuState0.normal_array.ptr );
1943 tmuState0.normal_array.changed = GL_FALSE;
1945 if ( arraysValid || tmuState0.texture_coord_array.changed )
1947 tmuState0.texture_coord_array.changed = GL_FALSE;
1948 if ( tmuState0.texture_coord_array.enabled )
1950 glEsImpl->glEnableClientState( GL_TEXTURE_COORD_ARRAY );
1952 else
1954 glEsImpl->glDisableClientState( GL_TEXTURE_COORD_ARRAY );
1956 glEsImpl->glTexCoordPointer( tmuState0.texture_coord_array.size,
1957 tmuState0.texture_coord_array.type,
1958 tmuState0.texture_coord_array.stride,
1959 tmuState0.texture_coord_array.ptr );
1962 if ( arraysValid || tmuState1.texture_coord_array.changed )
1964 tmuState1.texture_coord_array.changed = GL_FALSE;
1965 glEsImpl->glClientActiveTexture( GL_TEXTURE1 );
1966 if ( tmuState1.texture_coord_array.enabled )
1968 glEsImpl->glEnableClientState( GL_TEXTURE_COORD_ARRAY );
1970 else
1972 glEsImpl->glDisableClientState( GL_TEXTURE_COORD_ARRAY );
1974 glEsImpl->glTexCoordPointer( tmuState1.texture_coord_array.size,
1975 tmuState1.texture_coord_array.type,
1976 tmuState1.texture_coord_array.stride,
1977 tmuState1.texture_coord_array.ptr );
1980 arraysValid = GL_FALSE;
1981 glEsImpl->glDrawElements( mode, count, type, indices );
1984 bool vboarray;
1986 void glEnableClientState( GLenum array )
1988 if( skipnanogl )
1990 glEsImpl->glEnableClientState( array );
1991 if( array == GL_VERTEX_ARRAY )
1992 vboarray = true;
1993 return;
1995 struct nanotmuState *clientstate = NULL;
1996 if ( clientactivetmu == GL_TEXTURE0 )
1998 clientstate = &tmuState0;
2000 else if ( clientactivetmu == GL_TEXTURE1 )
2002 clientstate = &tmuState1;
2004 else
2006 return;
2008 switch ( array )
2010 case GL_VERTEX_ARRAY:
2011 if ( clientstate->vertex_array.enabled )
2013 return;
2015 clientstate->vertex_array.enabled = GL_TRUE;
2016 clientstate->vertex_array.changed = GL_TRUE;
2017 break;
2018 case GL_COLOR_ARRAY:
2019 if ( clientstate->color_array.enabled )
2021 return;
2023 clientstate->color_array.enabled = GL_TRUE;
2024 clientstate->color_array.changed = GL_TRUE;
2026 break;
2027 case GL_NORMAL_ARRAY:
2028 if ( clientstate->normal_array.enabled )
2030 return;
2032 clientstate->normal_array.enabled = GL_TRUE;
2033 clientstate->normal_array.changed = GL_TRUE;
2035 break;
2036 case GL_TEXTURE_COORD_ARRAY:
2037 if ( clientstate->texture_coord_array.enabled )
2039 return;
2041 clientstate->texture_coord_array.enabled = GL_TRUE;
2042 clientstate->texture_coord_array.changed = GL_TRUE;
2043 break;
2044 default:
2045 break;
2048 void glDisableClientState( GLenum array )
2050 if( skipnanogl )
2052 glEsImpl->glDisableClientState( array );
2053 if( array == GL_VERTEX_ARRAY )
2054 vboarray = false;
2055 return;
2057 struct nanotmuState *clientstate = NULL;
2058 if ( clientactivetmu == GL_TEXTURE0 )
2060 clientstate = &tmuState0;
2062 else if ( clientactivetmu == GL_TEXTURE1 )
2064 clientstate = &tmuState1;
2066 else
2068 return;
2070 switch ( array )
2072 case GL_VERTEX_ARRAY:
2073 if ( !clientstate->vertex_array.enabled )
2075 return;
2077 clientstate->vertex_array.enabled = GL_FALSE;
2078 clientstate->vertex_array.changed = GL_TRUE;
2079 break;
2080 case GL_COLOR_ARRAY:
2081 if ( !clientstate->color_array.enabled )
2083 return;
2085 clientstate->color_array.enabled = GL_FALSE;
2086 clientstate->color_array.changed = GL_TRUE;
2088 break;
2089 case GL_NORMAL_ARRAY:
2090 if ( !clientstate->normal_array.enabled )
2092 return;
2094 clientstate->normal_array.enabled = GL_FALSE;
2095 clientstate->normal_array.changed = GL_TRUE;
2097 break;
2098 case GL_TEXTURE_COORD_ARRAY:
2099 if ( !clientstate->texture_coord_array.enabled )
2101 return;
2103 clientstate->texture_coord_array.enabled = GL_FALSE;
2104 clientstate->texture_coord_array.changed = GL_TRUE;
2105 break;
2106 default:
2107 break;
2110 void glVertexPointer( GLint size, GLenum type, GLsizei stride, const GLvoid *pointer )
2113 if( skipnanogl )
2115 glEsImpl->glVertexPointer( size, type, stride, pointer );
2116 return;
2118 if ( tmuState0.vertex_array.size == size &&
2119 tmuState0.vertex_array.stride == stride &&
2120 tmuState0.vertex_array.type == type &&
2121 tmuState0.vertex_array.ptr == pointer )
2123 return;
2125 tmuState0.vertex_array.size = size;
2126 tmuState0.vertex_array.stride = stride;
2127 tmuState0.vertex_array.type = type;
2128 tmuState0.vertex_array.ptr = (GLvoid *)pointer;
2129 tmuState0.vertex_array.changed = GL_TRUE;
2131 void glTexCoordPointer( GLint size, GLenum type, GLsizei stride, const GLvoid *pointer )
2133 if( skipnanogl )
2135 glEsImpl->glTexCoordPointer( size, type, stride, pointer );
2136 return;
2138 struct nanotmuState *clientstate = NULL;
2139 if ( clientactivetmu == GL_TEXTURE0 )
2141 clientstate = &tmuState0;
2143 else if ( clientactivetmu == GL_TEXTURE1 )
2145 clientstate = &tmuState1;
2147 if ( clientstate->texture_coord_array.size == size &&
2148 clientstate->texture_coord_array.stride == stride &&
2149 clientstate->texture_coord_array.type == type &&
2150 clientstate->texture_coord_array.ptr == pointer )
2152 return;
2154 clientstate->texture_coord_array.size = size;
2155 clientstate->texture_coord_array.stride = stride;
2156 clientstate->texture_coord_array.type = type;
2157 clientstate->texture_coord_array.ptr = (GLvoid *)pointer;
2158 clientstate->texture_coord_array.changed = GL_TRUE;
2160 void glColorPointer( GLint size, GLenum type, GLsizei stride, const GLvoid *pointer )
2162 if ( tmuState0.color_array.size == size &&
2163 tmuState0.color_array.stride == stride &&
2164 tmuState0.color_array.type == type &&
2165 tmuState0.color_array.ptr == pointer )
2167 return;
2169 tmuState0.color_array.size = size;
2170 tmuState0.color_array.stride = stride;
2171 tmuState0.color_array.type = type;
2172 tmuState0.color_array.ptr = (GLvoid *)pointer;
2173 tmuState0.color_array.changed = GL_TRUE;
2176 void glNormalPointer( GLenum type, GLsizei stride, const GLvoid *pointer )
2178 int size = 0;
2179 if ( tmuState0.normal_array.size == size &&
2180 tmuState0.normal_array.stride == stride &&
2181 tmuState0.normal_array.type == type &&
2182 tmuState0.normal_array.ptr == pointer )
2184 return;
2186 tmuState0.normal_array.size = size;
2187 tmuState0.normal_array.stride = stride;
2188 tmuState0.normal_array.type = type;
2189 tmuState0.normal_array.ptr = (GLvoid *)pointer;
2190 tmuState0.normal_array.changed = GL_TRUE;
2192 void glPolygonOffset( GLfloat factor, GLfloat units )
2194 FlushOnStateChange( );
2195 glEsImpl->glPolygonOffset( factor, units );
2197 void glStencilMask( GLuint mask )
2199 FlushOnStateChange( );
2200 glEsImpl->glStencilMask( mask );
2202 void glClearStencil( GLint s )
2204 FlushOnStateChange( );
2205 glEsImpl->glClearStencil( s );
2208 #if defined( __MULTITEXTURE_SUPPORT__ )
2210 extern "C" void glMultiTexCoord2fARB( GLenum target, GLfloat s, GLfloat t );
2212 void glMultiTexCoord2fARB( GLenum target, GLfloat s, GLfloat t )
2214 if ( target == GL_TEXTURE0 )
2216 glTexCoord2f( s, t );
2218 else
2220 currentVertexAttrib.s_multi = s;
2221 currentVertexAttrib.t_multi = t;
2224 #endif
2226 /* Vladimir */
2227 /*void glDrawArrays( GLenum mode, int first, int count)
2229 FlushOnStateChange();
2230 glEsImpl->glDrawArrays(mode, first , count);
2231 }*/
2232 void glMultMatrixf( const GLfloat *m )
2234 FlushOnStateChange( );
2235 glEsImpl->glMultMatrixf( m );
2238 void glPixelStorei( GLenum pname, GLint param )
2240 FlushOnStateChange( );
2241 glEsImpl->glPixelStorei( pname, param );
2244 void glFogi( GLenum pname, GLint param )
2246 FlushOnStateChange( );
2247 glEsImpl->glFogf( pname, param );
2250 void glFogf( GLenum pname, GLfloat param )
2252 FlushOnStateChange( );
2253 glEsImpl->glFogf( pname, param );
2256 void glFogfv( GLenum pname, const GLfloat *params )
2258 FlushOnStateChange( );
2259 glEsImpl->glFogfv( pname, params );
2262 void glGetTexParameteriv( GLenum target, GLenum pname, GLint *params )
2264 FlushOnStateChange( );
2265 glEsImpl->glGetTexParameteriv( target, pname, params );
2268 // This gives: called unimplemented OpenGL ES API (Android)
2269 void glTexParameteri( GLenum target, GLenum pname, GLint param )
2271 if ( pname == GL_TEXTURE_BORDER_COLOR )
2273 return; // not supported by opengl es
2275 if ( ( pname == GL_TEXTURE_WRAP_S ||
2276 pname == GL_TEXTURE_WRAP_T ) &&
2277 param == GL_CLAMP )
2279 param = 0x812F;
2282 FlushOnStateChange( );
2283 glEsImpl->glTexParameteri( target, pname, param );
2286 void glTexParameterx( GLenum target, GLenum pname, GLfixed param )
2288 if ( pname == GL_TEXTURE_BORDER_COLOR )
2290 return; // not supported by opengl es
2292 if ( ( pname == GL_TEXTURE_WRAP_S ||
2293 pname == GL_TEXTURE_WRAP_T ) &&
2294 param == GL_CLAMP )
2296 param = 0x812F;
2298 FlushOnStateChange( );
2299 glEsImpl->glTexParameterx( target, pname, param );
2302 void glGenTextures( GLsizei n, GLuint *textures )
2304 FlushOnStateChange( );
2305 glEsImpl->glGenTextures( n, textures );
2308 void glFrontFace( GLenum mode )
2310 FlushOnStateChange( );
2311 glEsImpl->glFrontFace( mode );
2313 // End Vladimir
2315 void glTexEnvi( GLenum target, GLenum pname, GLint param )
2317 if( skipnanogl )
2319 glEsImpl->glTexEnvi( target, pname, param );
2320 return;
2322 if ( target == GL_TEXTURE_ENV )
2324 if ( pname == GL_TEXTURE_ENV_MODE )
2326 if ( param == activetmuState->texture_env_mode.value )
2328 return;
2330 else
2332 FlushOnStateChange( );
2333 glEsImpl->glTexEnvi( target, pname, param );
2334 activetmuState->texture_env_mode.value = param;
2335 return;
2339 FlushOnStateChange( );
2340 glEsImpl->glTexEnvi( target, pname, param );
2343 #ifdef __MULTITEXTURE_SUPPORT__
2344 void glMultiTexCoord3fARB( GLenum a, GLfloat b, GLfloat c, GLfloat )
2346 return glMultiTexCoord2fARB( a, b, c );
2349 void glMultiTexCoord2f( GLenum a, GLfloat b, GLfloat c )
2351 glMultiTexCoord2fARB(a,b,c);
2353 #endif
2354 void glDrawArrays( GLenum mode, GLint first, GLsizei count )
2356 if( skipnanogl )
2358 glEsImpl->glDrawArrays( mode, first, count );
2359 return;
2361 // ensure that all primitives specified between glBegin/glEnd pairs
2362 // are rendered first, and that we have correct tmu in use..
2363 if ( mode == GL_QUADS )
2364 mode = GL_TRIANGLE_FAN;
2365 FlushOnStateChange( );
2366 // setup correct vertex/color/texcoord pointers
2367 if ( arraysValid ||
2368 tmuState0.vertex_array.changed ||
2369 tmuState0.color_array.changed ||
2370 tmuState0.texture_coord_array.changed || tmuState0.normal_array.changed )
2372 glEsImpl->glClientActiveTexture( GL_TEXTURE0 );
2374 if ( arraysValid || tmuState0.vertex_array.changed )
2376 if ( tmuState0.vertex_array.enabled )
2378 glEsImpl->glEnableClientState( GL_VERTEX_ARRAY );
2380 else
2382 glEsImpl->glDisableClientState( GL_VERTEX_ARRAY );
2384 glEsImpl->glVertexPointer( tmuState0.vertex_array.size,
2385 tmuState0.vertex_array.type,
2386 tmuState0.vertex_array.stride,
2387 tmuState0.vertex_array.ptr );
2388 tmuState0.vertex_array.changed = GL_FALSE;
2390 if ( arraysValid || tmuState0.color_array.changed )
2392 if ( tmuState0.color_array.enabled )
2394 glEsImpl->glEnableClientState( GL_COLOR_ARRAY );
2396 else
2398 glEsImpl->glDisableClientState( GL_COLOR_ARRAY );
2399 glEsImpl->glColor4f( currentVertexAttrib.red/255.0f, currentVertexAttrib.green/255.0f,
2400 currentVertexAttrib.blue/255.0f, currentVertexAttrib.alpha/255.0f );
2403 glEsImpl->glColorPointer( tmuState0.color_array.size,
2404 tmuState0.color_array.type,
2405 tmuState0.color_array.stride,
2406 tmuState0.color_array.ptr );
2407 tmuState0.color_array.changed = GL_FALSE;
2409 if ( arraysValid || tmuState0.normal_array.changed )
2411 if ( tmuState0.normal_array.enabled )
2413 glEsImpl->glEnableClientState( GL_NORMAL_ARRAY );
2415 else
2417 glEsImpl->glDisableClientState( GL_NORMAL_ARRAY );
2419 glEsImpl->glNormalPointer( tmuState0.normal_array.type,
2420 tmuState0.normal_array.stride,
2421 tmuState0.normal_array.ptr );
2422 tmuState0.normal_array.changed = GL_FALSE;
2424 if ( arraysValid || tmuState0.texture_coord_array.changed )
2426 tmuState0.texture_coord_array.changed = GL_FALSE;
2427 if ( tmuState0.texture_coord_array.enabled )
2429 glEsImpl->glEnableClientState( GL_TEXTURE_COORD_ARRAY );
2431 else
2433 glEsImpl->glDisableClientState( GL_TEXTURE_COORD_ARRAY );
2435 glEsImpl->glTexCoordPointer( tmuState0.texture_coord_array.size,
2436 tmuState0.texture_coord_array.type,
2437 tmuState0.texture_coord_array.stride,
2438 tmuState0.texture_coord_array.ptr );
2441 if ( arraysValid || tmuState1.texture_coord_array.changed )
2443 tmuState1.texture_coord_array.changed = GL_FALSE;
2444 glEsImpl->glClientActiveTexture( GL_TEXTURE1 );
2445 if ( tmuState1.texture_coord_array.enabled )
2447 glEsImpl->glEnableClientState( GL_TEXTURE_COORD_ARRAY );
2449 else
2451 glEsImpl->glDisableClientState( GL_TEXTURE_COORD_ARRAY );
2453 glEsImpl->glTexCoordPointer( tmuState1.texture_coord_array.size,
2454 tmuState1.texture_coord_array.type,
2455 tmuState1.texture_coord_array.stride,
2456 tmuState1.texture_coord_array.ptr );
2459 arraysValid = GL_FALSE;
2460 glEsImpl->glDrawArrays( mode, first, count );
2462 /*void glNormalPointer(GLenum type, GLsizei stride, const void *ptr)
2464 glEsImpl->glNormalPointer( type, stride, ptr );
2465 }*/
2467 void glCopyTexSubImage2D( GLenum target, GLint level, GLint xoffset, GLint yoffset, GLint x, GLint y, GLsizei width, GLsizei height )
2469 FlushOnStateChange( );
2470 glEsImpl->glCopyTexSubImage2D( target, level, xoffset, yoffset, x, y, width, height );
2473 void glGenFramebuffers( GLsizei n, GLuint *framebuffers )
2475 FlushOnStateChange( );
2476 glEsImpl->glGenFramebuffers( n, framebuffers );
2479 void glGenRenderbuffers( GLsizei n, GLuint *renderbuffers )
2481 FlushOnStateChange( );
2482 glEsImpl->glGenRenderbuffers( n, renderbuffers );
2485 void glBindRenderbuffer( GLenum target, GLuint renderbuffer )
2487 FlushOnStateChange( );
2488 glEsImpl->glBindRenderbuffer( target, renderbuffer );
2491 void glBindFramebuffer( GLenum target, GLuint framebuffer )
2493 FlushOnStateChange( );
2494 glEsImpl->glBindFramebuffer( target, framebuffer );
2497 void glFramebufferRenderbuffer( GLenum target, GLenum attachment, GLenum renderbuffertarget, GLuint renderbuffer )
2499 FlushOnStateChange( );
2500 glEsImpl->glFramebufferRenderbuffer( target, attachment, renderbuffertarget, renderbuffer );
2503 void glDeleteFramebuffers( GLsizei n, const GLuint *framebuffers )
2505 FlushOnStateChange( );
2506 glEsImpl->glDeleteFramebuffers( n, framebuffers );
2509 void glDeleteRenderbuffers( GLsizei n, const GLuint *renderbuffers )
2511 FlushOnStateChange( );
2512 glEsImpl->glDeleteRenderbuffers( n, renderbuffers );
2514 void glFramebufferTexture2D( GLenum target, GLenum attachment, GLenum textarget, GLuint texture, GLint level )
2516 FlushOnStateChange( );
2517 glEsImpl->glFramebufferTexture2D( target, attachment, textarget, texture, level );
2520 void glRenderbufferStorage( GLenum target, GLenum internalformat, GLsizei width, GLsizei height )
2522 FlushOnStateChange( );
2523 glEsImpl->glRenderbufferStorage( target, internalformat, width, height );
2526 void glBindBufferARB( GLuint target, GLuint index )
2528 static int sindex;
2530 if( index && !sindex && !skipnanogl )
2531 FlushOnStateChange();
2532 glEsImpl->glDisableClientState( GL_COLOR_ARRAY );
2533 glEsImpl->glColor4f( currentVertexAttrib.red/255.0f, currentVertexAttrib.green/255.0f,
2534 currentVertexAttrib.blue/255.0f, currentVertexAttrib.alpha/255.0f );
2536 skipnanogl = (!!index) || vboarray;
2537 glEsImpl->glBindBuffer( target, index );
2538 if( sindex && !index )
2540 arraysValid = GL_FALSE;
2542 sindex = index;
2545 void glGenBuffersARB( GLuint count, GLuint *indexes )
2547 glEsImpl->glGenBuffers( count, indexes );
2550 void glDeleteBuffersARB( GLuint count, GLuint *indexes )
2552 glEsImpl->glDeleteBuffers( count, indexes );
2555 void glBufferDataARB( GLuint target, GLuint size, void *buffer, GLuint type )
2557 glEsImpl->glBufferData( target, size, buffer, type );
2560 void glBufferSubDataARB( GLuint target, GLsizei offset, GLsizei size, void *buffer )
2562 glEsImpl->glBufferSubData( target, offset, size, buffer );