DEADSOFTWARE

b46b4c796cf1dff53a3d1beea2b600141a8f48b4
[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 lighti;
48 GLboolean lighting;
49 GLboolean line_smooth;
50 GLboolean matrix_palette_oes;
51 GLboolean multisample;
52 GLboolean normalize;
53 GLboolean point_smooth;
54 GLboolean point_sprite_oes;
55 GLboolean polygon_offset_fill;
56 GLboolean rescale_normal;
57 GLboolean sample_alpha_to_coverage;
58 GLboolean sample_alpha_to_one;
59 GLboolean sample_coverage;
60 GLboolean scissor_test;
61 GLboolean stencil_test;
62 GLboolean depthmask;
63 GLboolean stupidglesbug;
64 GLclampf depth_range_near;
65 GLclampf depth_range_far;
66 GLenum depth_func;
67 GLenum cullface;
68 GLenum shademodel;
69 GLenum sfactor;
70 GLenum dfactor;
71 GLenum matrixmode;
72 };
74 static struct nanoState nanoglState;
76 static struct nanoState nanoglInitState =
77 {
78 GL_FALSE,
79 GL_FALSE,
80 GL_FALSE,
81 GL_FALSE,
82 GL_FALSE,
83 GL_FALSE,
84 GL_FALSE,
85 GL_TRUE,
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_TRUE,
103 GL_FALSE,
104 0.0f,
105 1.0f,
106 GL_LESS,
107 GL_BACK,
108 GL_SMOOTH,
109 GL_ONE,
110 GL_ZERO,
111 GL_MODELVIEW,
112 };
114 struct booleanstate
116 GLboolean value;
117 GLboolean changed;
118 };
120 struct floatstate
122 GLfloat value;
123 GLboolean changed;
124 };
126 struct uintstate
128 GLuint value;
129 GLboolean changed;
130 };
132 struct ptrstate
134 GLint size;
135 GLenum type;
136 GLsizei stride;
137 GLvoid *ptr;
138 GLboolean changed;
139 GLboolean enabled;
140 };
142 struct nanotmuState
144 struct booleanstate texture_2d;
145 struct floatstate texture_env_mode;
146 struct uintstate boundtexture;
147 struct ptrstate vertex_array;
148 struct ptrstate color_array;
149 struct ptrstate texture_coord_array;
150 struct ptrstate normal_array;
151 };
153 static struct nanotmuState tmuState0;
154 static struct nanotmuState tmuState1;
156 static struct nanotmuState tmuInitState =
158 {GL_FALSE, GL_FALSE},
159 {GL_MODULATE, GL_FALSE},
160 {0x7fffffff, GL_FALSE},
161 {4, GL_FLOAT, 0, NULL, GL_FALSE, GL_FALSE},
162 {4, GL_FLOAT, 0, NULL, GL_FALSE, GL_FALSE},
163 {4, GL_FLOAT, 0, NULL, GL_FALSE, GL_FALSE},
164 {3, GL_FLOAT, 0, NULL, GL_FALSE, GL_FALSE},
165 };
167 static struct nanotmuState *activetmuState = &tmuState0;
169 extern "C++" GlESInterface *glEsImpl;
171 static GLenum wrapperPrimitiveMode = GL_QUADS;
172 GLboolean useTexCoordArray = GL_FALSE;
173 static GLenum activetmu = GL_TEXTURE0;
174 static GLenum clientactivetmu = GL_TEXTURE0;
176 #if defined( __MULTITEXTURE_SUPPORT__ )
177 GLboolean useMultiTexCoordArray = GL_FALSE;
178 #endif
180 #if !defined( __WINS__ )
181 //#define __FORCEINLINE __forceinline
182 #define __FORCEINLINE inline
183 #else
184 #define __FORCEINLINE
185 #endif
187 static GLboolean delayedttmuchange = GL_FALSE;
188 static GLenum delayedtmutarget = GL_TEXTURE0;
190 struct VertexAttrib
192 float x;
193 float y;
194 float z;
195 #if !defined( __MULTITEXTURE_SUPPORT__ )
196 float padding;
197 #endif
198 unsigned char red;
199 unsigned char green;
200 unsigned char blue;
201 unsigned char alpha;
203 float s;
204 float t;
205 #if defined( __MULTITEXTURE_SUPPORT__ )
206 float s_multi;
207 float t_multi;
208 #endif
209 };
211 static VertexAttrib vertexattribs[60000];
213 static GLushort indexArray[50000];
215 static GLuint vertexCount = 0;
216 static GLuint indexCount = 0;
217 static GLuint vertexMark = 0;
218 static int indexbase = 0;
220 static VertexAttrib *ptrVertexAttribArray = NULL;
221 static VertexAttrib *ptrVertexAttribArrayMark = NULL;
223 static VertexAttrib currentVertexAttrib;
224 #if defined( __MULTITEXTURE_SUPPORT__ )
225 static VertexAttrib currentVertexAttribInit = {0.0f, 0.0f, 0.0f, 255, 255, 255, 255, 0.0f, 0.0f, 0.0f, 0.0f};
226 #else
227 static VertexAttrib currentVertexAttribInit = {
228 0.0f, 0.0f, 0.0f, 0.0f, 255, 255, 255, 255, 0.0f, 0.0f,
229 };
230 #endif
231 static GLushort *ptrIndexArray = NULL;
233 static GLboolean arraysValid = GL_FALSE;
235 void InitGLStructs( )
237 ptrVertexAttribArray = vertexattribs;
238 ptrVertexAttribArrayMark = ptrVertexAttribArray;
239 ptrIndexArray = indexArray;
241 memcpy( &nanoglState, &nanoglInitState, sizeof( struct nanoState ) );
242 memcpy( &tmuState0, &tmuInitState, sizeof( struct nanotmuState ) );
243 memcpy( &tmuState1, &tmuInitState, sizeof( struct nanotmuState ) );
244 memcpy( &currentVertexAttrib, &currentVertexAttribInit, sizeof( struct VertexAttrib ) );
246 activetmuState = &tmuState0;
247 wrapperPrimitiveMode = GL_QUADS;
248 useTexCoordArray = GL_FALSE;
249 activetmu = GL_TEXTURE0;
250 clientactivetmu = GL_TEXTURE0;
251 delayedttmuchange = GL_FALSE;
252 delayedtmutarget = GL_TEXTURE0;
253 vertexCount = 0;
254 indexCount = 0;
255 vertexMark = 0;
256 indexbase = 0;
257 arraysValid = GL_FALSE;
260 void ResetNanoState( )
263 if ( tmuState0.color_array.enabled )
265 glEsImpl->glEnableClientState( GL_COLOR_ARRAY );
267 else
269 glEsImpl->glDisableClientState( GL_COLOR_ARRAY );
272 if ( tmuState0.vertex_array.enabled )
274 glEsImpl->glEnableClientState( GL_VERTEX_ARRAY );
276 else
278 glEsImpl->glDisableClientState( GL_VERTEX_ARRAY );
281 if ( tmuState0.texture_coord_array.enabled )
283 glEsImpl->glEnableClientState( GL_TEXTURE_COORD_ARRAY );
285 else
287 glEsImpl->glDisableClientState( GL_TEXTURE_COORD_ARRAY );
290 if ( tmuState0.normal_array.enabled )
292 glEsImpl->glEnableClientState( GL_NORMAL_ARRAY );
294 else
296 glEsImpl->glDisableClientState( GL_NORMAL_ARRAY );
298 glEsImpl->glVertexPointer( tmuState0.vertex_array.size,
299 tmuState0.vertex_array.type,
300 tmuState0.vertex_array.stride,
301 tmuState0.vertex_array.ptr );
303 glEsImpl->glTexCoordPointer( tmuState0.texture_coord_array.size,
304 tmuState0.texture_coord_array.type,
305 tmuState0.texture_coord_array.stride,
306 tmuState0.texture_coord_array.ptr );
308 glEsImpl->glColorPointer( tmuState0.color_array.size,
309 tmuState0.color_array.type,
310 tmuState0.color_array.stride,
311 tmuState0.color_array.ptr );
313 glEsImpl->glNormalPointer(
314 tmuState0.normal_array.type,
315 tmuState0.normal_array.stride,
316 tmuState0.normal_array.ptr );
318 glEsImpl->glMatrixMode( nanoglState.matrixmode );
320 glEsImpl->glColor4f( currentVertexAttrib.red, currentVertexAttrib.green, currentVertexAttrib.blue, currentVertexAttrib.alpha );
322 glEsImpl->glBlendFunc( nanoglState.sfactor, nanoglState.dfactor );
324 //glEsImpl->glBindTexture(GL_TEXTURE_2D, stackTextureState);
326 glEsImpl->glTexEnvi( GL_TEXTURE_ENV, GL_TEXTURE_ENV_MODE, activetmuState->texture_env_mode.value );
328 arraysValid = GL_FALSE;
331 void FlushOnStateChange( )
333 if ( delayedttmuchange )
335 delayedttmuchange = GL_FALSE;
336 #ifndef USE_CORE_PROFILE
337 glEsImpl->glActiveTexture( delayedtmutarget );
338 #endif
341 if ( !vertexCount )
342 return;
344 if ( !arraysValid )
346 glEsImpl->glClientActiveTexture( GL_TEXTURE0 );
347 glEsImpl->glVertexPointer( 3, GL_FLOAT, sizeof( VertexAttrib ), &vertexattribs[0].x );
348 glEsImpl->glColorPointer( 4, GL_UNSIGNED_BYTE, sizeof( VertexAttrib ), &vertexattribs[0].red );
349 glEsImpl->glTexCoordPointer( 2, GL_FLOAT, sizeof( VertexAttrib ), &vertexattribs[0].s );
350 glEsImpl->glEnableClientState( GL_VERTEX_ARRAY );
351 glEsImpl->glEnableClientState( GL_TEXTURE_COORD_ARRAY );
352 glEsImpl->glEnableClientState( GL_COLOR_ARRAY );
353 #if defined( __MULTITEXTURE_SUPPORT__ )
354 glEsImpl->glClientActiveTexture( GL_TEXTURE1 );
355 glEsImpl->glTexCoordPointer( 2, GL_FLOAT, sizeof( VertexAttrib ), &vertexattribs[0].s_multi );
356 glEsImpl->glEnableClientState( GL_TEXTURE_COORD_ARRAY );
357 glEsImpl->glClientActiveTexture( GL_TEXTURE0 );
358 #endif
359 arraysValid = GL_TRUE;
362 glEsImpl->glDrawElements( GL_TRIANGLES, vertexCount, GL_UNSIGNED_SHORT, indexArray );
364 #if defined( __MULTITEXTURE_SUPPORT__ )
365 useMultiTexCoordArray = GL_FALSE;
366 #endif
367 vertexCount = 0;
368 indexCount = 0;
369 ptrVertexAttribArray = vertexattribs;
370 ptrVertexAttribArrayMark = ptrVertexAttribArray;
371 ptrIndexArray = indexArray;
372 useTexCoordArray = GL_FALSE;
374 void nanoGL_Flush( )
376 FlushOnStateChange( );
378 void nanoGL_Reset( )
380 ResetNanoState( );
382 void glBegin( GLenum mode )
384 wrapperPrimitiveMode = mode;
385 vertexMark = vertexCount;
386 ptrVertexAttribArrayMark = ptrVertexAttribArray;
387 indexbase = indexCount;
390 void glEnd( void )
392 vertexCount += ( (unsigned char *)ptrVertexAttribArray - (unsigned char *)ptrVertexAttribArrayMark ) / sizeof( VertexAttrib );
393 if ( vertexCount < 3 )
395 return;
397 switch ( wrapperPrimitiveMode )
399 case GL_QUADS:
401 *ptrIndexArray++ = indexCount;
402 *ptrIndexArray++ = indexCount + 1;
403 *ptrIndexArray++ = indexCount + 2;
404 *ptrIndexArray++ = indexCount;
405 *ptrIndexArray++ = indexCount + 2;
406 *ptrIndexArray++ = indexCount + 3;
407 indexCount += 4;
408 vertexCount += 2;
410 break;
411 case GL_TRIANGLES:
413 int vcount = ( vertexCount - vertexMark ) / 3;
414 for ( int count = 0; count < vcount; count++ )
416 *ptrIndexArray++ = indexCount;
417 *ptrIndexArray++ = indexCount + 1;
418 *ptrIndexArray++ = indexCount + 2;
419 indexCount += 3;
422 break;
423 case GL_TRIANGLE_STRIP:
425 *ptrIndexArray++ = indexCount;
426 *ptrIndexArray++ = indexCount + 1;
427 *ptrIndexArray++ = indexCount + 2;
428 indexCount += 3;
429 int vcount = ( ( vertexCount - vertexMark ) - 3 );
430 if ( vcount && ( (long)ptrIndexArray & 0x02 ) )
432 *ptrIndexArray++ = indexCount - 1; // 2
433 *ptrIndexArray++ = indexCount - 2; // 1
434 *ptrIndexArray++ = indexCount; // 3
435 indexCount++;
436 vcount -= 1;
437 int odd = vcount & 1;
438 vcount /= 2;
439 unsigned int *longptr = (unsigned int *)ptrIndexArray;
441 for ( int count = 0; count < vcount; count++ )
443 *( longptr++ ) = ( indexCount - 2 ) | ( ( indexCount - 1 ) << 16 );
444 *( longptr++ ) = ( indexCount ) | ( ( indexCount ) << 16 );
445 *( longptr++ ) = ( indexCount - 1 ) | ( ( indexCount + 1 ) << 16 );
446 indexCount += 2;
448 ptrIndexArray = (unsigned short *)( longptr );
449 if ( odd )
451 *ptrIndexArray++ = indexCount - 2; // 2
452 *ptrIndexArray++ = indexCount - 1; // 1
453 *ptrIndexArray++ = indexCount; // 3
454 indexCount++;
457 else
459 //already aligned
460 int odd = vcount & 1;
461 vcount /= 2;
462 unsigned int *longptr = (unsigned int *)ptrIndexArray;
464 for ( int count = 0; count < vcount; count++ )
466 *( longptr++ ) = ( indexCount - 1 ) | ( ( indexCount - 2 ) << 16 );
467 *( longptr++ ) = ( indexCount ) | ( ( indexCount - 1 ) << 16 );
468 *( longptr++ ) = ( indexCount ) | ( ( indexCount + 1 ) << 16 );
469 indexCount += 2;
471 ptrIndexArray = (unsigned short *)( longptr );
472 if ( odd )
475 *ptrIndexArray++ = indexCount - 1; // 2
476 *ptrIndexArray++ = indexCount - 2; // 1
477 *ptrIndexArray++ = indexCount; // 3
478 indexCount++;
481 vertexCount += ( vertexCount - vertexMark - 3 ) * 2;
483 break;
484 case GL_POLYGON:
485 case GL_TRIANGLE_FAN:
487 *ptrIndexArray++ = indexCount++;
488 *ptrIndexArray++ = indexCount++;
489 *ptrIndexArray++ = indexCount++;
490 int vcount = ( ( vertexCount - vertexMark ) - 3 );
491 for ( int count = 0; count < vcount; count++ )
493 *ptrIndexArray++ = indexbase;
494 *ptrIndexArray++ = indexCount - 1;
495 *ptrIndexArray++ = indexCount++;
496 vertexCount += 2;
499 break;
501 default:
502 break;
504 if ( ptrVertexAttribArray - vertexattribs > 20000 * sizeof( VertexAttrib ) ||
505 ptrIndexArray - indexArray > 15000 * sizeof( GLushort ) )
506 FlushOnStateChange( );
509 void glEnable( GLenum cap )
511 GLboolean statechanged = GL_FALSE;
512 switch ( cap )
514 case GL_ALPHA_TEST:
516 if ( !nanoglState.alpha_test )
518 nanoglState.alpha_test = GL_TRUE;
519 statechanged = GL_TRUE;
521 break;
523 case GL_BLEND:
525 if ( !nanoglState.blend )
527 nanoglState.blend = GL_TRUE;
528 statechanged = GL_TRUE;
530 break;
532 //case GL_CLIP_PLANEi
533 case GL_COLOR_LOGIC_OP:
535 if ( !nanoglState.color_logic_op )
537 nanoglState.color_logic_op = GL_TRUE;
538 statechanged = GL_TRUE;
540 break;
542 case GL_COLOR_MATERIAL:
544 if ( !nanoglState.color_material )
546 nanoglState.color_material = GL_TRUE;
547 statechanged = GL_TRUE;
549 break;
551 case GL_CULL_FACE:
553 if ( !nanoglState.cull_face )
555 nanoglState.cull_face = GL_TRUE;
556 statechanged = GL_TRUE;
558 break;
560 case GL_DEPTH_TEST:
562 if ( !nanoglState.depth_test )
564 nanoglState.depth_test = GL_TRUE;
565 statechanged = GL_TRUE;
567 break;
569 case GL_DITHER:
571 if ( !nanoglState.dither )
573 nanoglState.dither = GL_TRUE;
574 statechanged = GL_TRUE;
576 break;
578 case GL_FOG:
579 //case GL_LIGHTi
581 if ( !nanoglState.fog )
583 nanoglState.fog = GL_TRUE;
584 statechanged = GL_TRUE;
586 break;
588 case GL_LIGHTING:
590 if ( !nanoglState.lighting )
592 nanoglState.lighting = GL_TRUE;
593 statechanged = GL_TRUE;
595 break;
597 case GL_LINE_SMOOTH:
599 if ( !nanoglState.line_smooth )
601 nanoglState.line_smooth = GL_TRUE;
602 statechanged = GL_TRUE;
604 break;
606 /* case GL_MATRIX_PALETTE_OES:
608 if (!nanoglState.matrix_palette_oes)
610 nanoglState.matrix_palette_oes = GL_TRUE;
611 statechanged = GL_TRUE;
613 break;
614 }*/
615 case GL_MULTISAMPLE:
617 if ( !nanoglState.multisample )
619 nanoglState.multisample = GL_TRUE;
620 statechanged = GL_TRUE;
622 break;
624 case GL_NORMALIZE:
626 if ( !nanoglState.normalize )
628 nanoglState.normalize = GL_TRUE;
629 statechanged = GL_TRUE;
631 break;
633 /* case GL_POINT_SPRITE_OES:
635 if (!nanoglState.point_sprite_oes)
637 nanoglState.point_sprite_oes = GL_TRUE;
638 statechanged = GL_TRUE;
640 break;
641 }*/
642 case GL_POLYGON_OFFSET_FILL:
644 if ( !nanoglState.polygon_offset_fill )
646 nanoglState.polygon_offset_fill = GL_TRUE;
647 statechanged = GL_TRUE;
649 break;
651 case GL_RESCALE_NORMAL:
653 if ( !nanoglState.rescale_normal )
655 nanoglState.rescale_normal = GL_TRUE;
656 statechanged = GL_TRUE;
658 break;
660 case GL_SAMPLE_ALPHA_TO_COVERAGE:
662 if ( !nanoglState.sample_alpha_to_coverage )
664 nanoglState.sample_alpha_to_coverage = GL_TRUE;
665 statechanged = GL_TRUE;
667 break;
669 case GL_SAMPLE_ALPHA_TO_ONE:
671 if ( !nanoglState.sample_alpha_to_one )
673 nanoglState.sample_alpha_to_one = GL_TRUE;
674 statechanged = GL_TRUE;
676 break;
678 case GL_SAMPLE_COVERAGE:
680 if ( !nanoglState.sample_coverage )
682 nanoglState.sample_coverage = GL_TRUE;
683 statechanged = GL_TRUE;
685 break;
687 case GL_SCISSOR_TEST:
689 if ( !nanoglState.scissor_test )
691 nanoglState.scissor_test = GL_TRUE;
692 statechanged = GL_TRUE;
694 break;
696 case GL_STENCIL_TEST:
698 return;
699 /* if (!nanoglState.stencil_test)
701 nanoglState.stencil_test = GL_TRUE;
702 statechanged = GL_TRUE;
703 }*/
704 break;
706 case GL_TEXTURE_2D:
708 if ( !activetmuState->texture_2d.value )
710 FlushOnStateChange( );
711 glEsImpl->glEnable( cap );
712 activetmuState->texture_2d.value = GL_TRUE;
713 return;
715 break;
717 default:
718 break;
721 if ( statechanged )
723 FlushOnStateChange( );
724 glEsImpl->glEnable( cap );
728 void glDisable( GLenum cap )
730 GLboolean statechanged = GL_FALSE;
731 switch ( cap )
733 case GL_ALPHA_TEST:
735 if ( nanoglState.alpha_test )
737 nanoglState.alpha_test = GL_FALSE;
738 statechanged = GL_TRUE;
740 break;
742 case GL_BLEND:
744 if ( nanoglState.blend )
746 nanoglState.blend = GL_FALSE;
747 statechanged = GL_TRUE;
749 break;
751 //case GL_CLIP_PLANEi
752 case GL_COLOR_LOGIC_OP:
754 if ( nanoglState.color_logic_op )
756 nanoglState.color_logic_op = GL_FALSE;
757 statechanged = GL_TRUE;
759 break;
761 case GL_COLOR_MATERIAL:
763 if ( nanoglState.color_material )
765 nanoglState.color_material = GL_FALSE;
766 statechanged = GL_TRUE;
768 break;
770 case GL_CULL_FACE:
772 if ( nanoglState.cull_face )
774 nanoglState.cull_face = GL_FALSE;
775 statechanged = GL_TRUE;
777 break;
779 case GL_DEPTH_TEST:
781 if ( nanoglState.depth_test )
783 nanoglState.depth_test = GL_FALSE;
784 statechanged = GL_TRUE;
786 break;
788 case GL_DITHER:
790 if ( nanoglState.dither )
792 nanoglState.dither = GL_FALSE;
793 statechanged = GL_TRUE;
795 break;
797 case GL_FOG:
798 //case GL_LIGHTi
800 if ( nanoglState.fog )
802 nanoglState.fog = GL_FALSE;
803 statechanged = GL_TRUE;
805 break;
807 case GL_LIGHTING:
809 if ( nanoglState.lighting )
811 nanoglState.lighting = GL_FALSE;
812 statechanged = GL_TRUE;
814 break;
816 case GL_LINE_SMOOTH:
818 if ( nanoglState.line_smooth )
820 nanoglState.line_smooth = GL_FALSE;
821 statechanged = GL_TRUE;
823 break;
825 /* case GL_MATRIX_PALETTE_OES:
827 if (nanoglState.matrix_palette_oes)
829 nanoglState.matrix_palette_oes = GL_FALSE;
830 statechanged = GL_TRUE;
832 break;
833 }*/
834 case GL_MULTISAMPLE:
836 if ( nanoglState.multisample )
838 nanoglState.multisample = GL_FALSE;
839 statechanged = GL_TRUE;
841 break;
843 case GL_NORMALIZE:
845 if ( nanoglState.normalize )
847 nanoglState.normalize = GL_FALSE;
848 statechanged = GL_TRUE;
850 break;
852 /* case GL_POINT_SPRITE_OES:
854 if (nanoglState.point_sprite_oes)
856 nanoglState.point_sprite_oes = GL_FALSE;
857 statechanged = GL_TRUE;
859 break;
860 }*/
861 case GL_POLYGON_OFFSET_FILL:
863 if ( nanoglState.polygon_offset_fill )
865 nanoglState.polygon_offset_fill = GL_FALSE;
866 statechanged = GL_TRUE;
868 break;
870 case GL_RESCALE_NORMAL:
872 if ( nanoglState.rescale_normal )
874 nanoglState.rescale_normal = GL_FALSE;
875 statechanged = GL_TRUE;
877 break;
879 case GL_SAMPLE_ALPHA_TO_COVERAGE:
881 if ( nanoglState.sample_alpha_to_coverage )
883 nanoglState.sample_alpha_to_coverage = GL_FALSE;
884 statechanged = GL_TRUE;
886 break;
888 case GL_SAMPLE_ALPHA_TO_ONE:
890 if ( nanoglState.sample_alpha_to_one )
892 nanoglState.sample_alpha_to_one = GL_FALSE;
893 statechanged = GL_TRUE;
895 break;
897 case GL_SAMPLE_COVERAGE:
899 if ( nanoglState.sample_coverage )
901 nanoglState.sample_coverage = GL_FALSE;
902 statechanged = GL_TRUE;
904 break;
906 case GL_SCISSOR_TEST:
908 if ( nanoglState.scissor_test )
910 nanoglState.scissor_test = GL_FALSE;
911 statechanged = GL_TRUE;
913 break;
915 case GL_STENCIL_TEST:
917 return;
918 /* if (nanoglState.stencil_test)
920 nanoglState.stencil_test = GL_FALSE;
921 statechanged = GL_TRUE;
922 }*/
923 break;
925 case GL_TEXTURE_2D:
927 if ( activetmuState->texture_2d.value )
929 FlushOnStateChange( );
930 glEsImpl->glDisable( cap );
931 activetmuState->texture_2d.value = GL_FALSE;
932 return;
934 break;
936 default:
937 break;
940 if ( statechanged )
942 FlushOnStateChange( );
943 glEsImpl->glDisable( cap );
947 void glVertex2f( GLfloat x, GLfloat y )
949 glVertex3f( x, y, 0.0f );
952 __FORCEINLINE unsigned int ClampTo255( float value )
954 unsigned int retval = (unsigned int)( value );
955 if ( retval > 255 )
957 retval = 255;
959 return retval;
962 void glColor3f( GLfloat red, GLfloat green, GLfloat blue )
964 currentVertexAttrib.red = (unsigned char)ClampTo255( red * 255.0f );
965 currentVertexAttrib.green = (unsigned char)ClampTo255( green * 255.0f );
966 currentVertexAttrib.blue = (unsigned char)ClampTo255( blue * 255.0f );
967 currentVertexAttrib.alpha = 255;
970 void glTexCoord2fv( const GLfloat *v )
972 memcpy( &currentVertexAttrib.s, v, 2 * sizeof( float ) );
975 void glTexCoord2f( GLfloat s, GLfloat t )
977 currentVertexAttrib.s = s;
978 currentVertexAttrib.t = t;
981 void glViewport( GLint x, GLint y, GLsizei width, GLsizei height )
983 FlushOnStateChange( );
984 glEsImpl->glViewport( x, y, width, height );
987 void glLoadIdentity( void )
989 FlushOnStateChange( );
990 glEsImpl->glLoadIdentity( );
993 void glColor4f( GLfloat red, GLfloat green, GLfloat blue, GLfloat alpha )
994 {
995 if( nanoglState.stupidglesbug )
997 currentVertexAttrib.red = (unsigned char)ClampTo255( ( red * alpha ) * 255.0f );
998 currentVertexAttrib.green = (unsigned char)ClampTo255( ( green * alpha ) * 255.0f );
999 currentVertexAttrib.blue = (unsigned char)ClampTo255( ( blue * alpha ) * 255.0f );
1001 else
1003 currentVertexAttrib.red = (unsigned char)ClampTo255( red * 255.0f );
1004 currentVertexAttrib.green = (unsigned char)ClampTo255( green * 255.0f );
1005 currentVertexAttrib.blue = (unsigned char)ClampTo255( blue * 255.0f );
1007 currentVertexAttrib.alpha = (unsigned char)ClampTo255( alpha * 255.0f );
1010 void glOrtho( GLfloat left, GLfloat right, GLfloat bottom, GLfloat top, GLfloat zNear, GLfloat zFar )
1012 FlushOnStateChange( );
1013 #ifdef USE_CORE_PROFILE
1014 glEsImpl->glOrtho( left, right, bottom, top, zNear, zFar );
1015 #else
1016 glEsImpl->glOrthof( left, right, bottom, top, zNear, zFar );
1017 #endif
1020 void glMatrixMode( GLenum mode )
1022 if ( nanoglState.matrixmode == mode )
1024 return;
1026 nanoglState.matrixmode = mode;
1027 FlushOnStateChange( );
1028 glEsImpl->glMatrixMode( mode );
1031 void glTexParameterf( GLenum target, GLenum pname, GLfloat param )
1033 if ( pname == GL_TEXTURE_BORDER_COLOR )
1035 return; // not supported by opengl es
1037 if ( ( pname == GL_TEXTURE_WRAP_S ||
1038 pname == GL_TEXTURE_WRAP_T ) &&
1039 param == GL_CLAMP )
1041 param = 0x812F;
1044 FlushOnStateChange( );
1045 glEsImpl->glTexParameterf( target, pname, param );
1048 void glTexParameterfv( GLenum target, GLenum pname, const GLfloat *params )
1050 glTexParameterf( target, pname, params[0] );
1053 void glTexImage2D( GLenum target, GLint level, GLint internalformat, GLsizei width, GLsizei height, GLint border, GLenum format, GLenum type, const GLvoid *pixels )
1055 FlushOnStateChange( );
1056 internalformat = format;
1057 glEsImpl->glTexImage2D( target, level, internalformat, width, height, border, format, type, pixels );
1060 void glDrawBuffer( GLenum /*mode*/ )
1064 void glTranslatef( GLfloat x, GLfloat y, GLfloat z )
1066 FlushOnStateChange( );
1067 glEsImpl->glTranslatef( x, y, z );
1070 void glRotatef( GLfloat angle, GLfloat x, GLfloat y, GLfloat z )
1072 FlushOnStateChange( );
1073 glEsImpl->glRotatef( angle, x, y, z );
1076 void glScalef( GLfloat x, GLfloat y, GLfloat z )
1078 FlushOnStateChange( );
1079 glEsImpl->glScalef( x, y, z );
1082 void glDepthRange( GLclampf zNear, GLclampf zFar )
1084 if ( ( nanoglState.depth_range_near == zNear ) && ( nanoglState.depth_range_far == zFar ) )
1086 return;
1088 else
1090 nanoglState.depth_range_near = zNear;
1091 nanoglState.depth_range_far = zFar;
1093 FlushOnStateChange( );
1094 #ifdef USE_CORE_PROFILE
1095 glEsImpl->glDepthRange( zNear, zFar );
1096 #else
1097 glEsImpl->glDepthRangef( zNear, zFar );
1098 #endif
1101 void glDepthFunc( GLenum func )
1103 if ( nanoglState.depth_func == func )
1105 return;
1107 else
1109 nanoglState.depth_func = func;
1111 FlushOnStateChange( );
1112 glEsImpl->glDepthFunc( func );
1115 void glFinish( void )
1117 FlushOnStateChange( );
1118 glEsImpl->glFinish( );
1121 void glGetFloatv( GLenum pname, GLfloat *params )
1123 FlushOnStateChange( );
1124 glEsImpl->glGetFloatv( pname, params );
1127 void glCullFace( GLenum mode )
1129 if ( nanoglState.cullface == mode )
1131 return;
1133 else
1135 nanoglState.cullface = mode;
1137 FlushOnStateChange( );
1138 glEsImpl->glCullFace( mode );
1141 void glFrustum( GLfloat left, GLfloat right, GLfloat bottom, GLfloat top, GLfloat zNear, GLfloat zFar )
1143 FlushOnStateChange( );
1144 glEsImpl->glFrustumf( left, right, bottom, top, zNear, zFar );
1147 void glClear( GLbitfield mask )
1149 FlushOnStateChange( );
1150 glEsImpl->glClear( mask );
1153 void glVertex3f( GLfloat x, GLfloat y, GLfloat z )
1155 GLfloat *vert = (GLfloat *)ptrVertexAttribArray++;
1156 *vert++ = x;
1157 *vert++ = y;
1158 *vert++ = z;
1159 #if defined( __MULTITEXTURE_SUPPORT__ )
1160 memcpy( vert, &currentVertexAttrib.red, 5 * sizeof( GLfloat ) );
1161 #else
1162 memcpy( vert + 1, &currentVertexAttrib.red, 3 * sizeof( GLfloat ) );
1163 #endif
1166 void glColor4fv( const GLfloat *v )
1167 {
1168 if( nanoglState.stupidglesbug )
1170 currentVertexAttrib.red = (unsigned char)ClampTo255( ( v[0] * v[3] ) * 255.0f );
1171 currentVertexAttrib.green = (unsigned char)ClampTo255( ( v[1] * v[3] ) * 255.0f );
1172 currentVertexAttrib.blue = (unsigned char)ClampTo255( ( v[2] * v[3] ) * 255.0f );
1174 else
1176 currentVertexAttrib.red = (unsigned char)ClampTo255( v[0] * 255.0f );
1177 currentVertexAttrib.green = (unsigned char)ClampTo255( v[1] * 255.0f );
1178 currentVertexAttrib.blue = (unsigned char)ClampTo255( v[2] * 255.0f );
1180 currentVertexAttrib.alpha = (unsigned char)ClampTo255( v[3] * 255.0f );
1183 void glColor3ubv( const GLubyte *v )
1185 currentVertexAttrib.red = v[0];
1186 currentVertexAttrib.green = v[1];
1187 currentVertexAttrib.blue = v[2];
1188 currentVertexAttrib.alpha = 255;
1191 void glColor4ubv( const GLubyte *v )
1193 //*((unsigned int*)(&currentVertexAttrib.red)) = *((unsigned int*)(v));
1194 if( nanoglState.stupidglesbug )
1196 currentVertexAttrib.red = (unsigned char)ClampTo255( v[0] * v[3] / 255.0f );
1197 currentVertexAttrib.green = (unsigned char)ClampTo255( v[1] * v[3] / 255.0f );
1198 currentVertexAttrib.blue = (unsigned char)ClampTo255( v[2] * v[3] / 255.0f );
1200 else
1202 currentVertexAttrib.red = v[0];
1203 currentVertexAttrib.green = v[1];
1204 currentVertexAttrib.blue = v[2];
1206 currentVertexAttrib.alpha = v[3];
1209 void glColor3fv( const GLfloat *v )
1211 currentVertexAttrib.red = (unsigned char)ClampTo255( v[0] * 255.0f );
1212 currentVertexAttrib.green = (unsigned char)ClampTo255( v[1] * 255.0f );
1213 currentVertexAttrib.blue = (unsigned char)ClampTo255( v[2] * 255.0f );
1214 currentVertexAttrib.alpha = 255;
1217 //-- nicknekit: xash3d funcs --
1219 void glColor4ub( GLubyte red, GLubyte green, GLubyte blue, GLubyte alpha )
1221 if( nanoglState.stupidglesbug )
1223 currentVertexAttrib.red = (unsigned char)ClampTo255( red * alpha / 255.0f );
1224 currentVertexAttrib.green = (unsigned char)ClampTo255( green * alpha / 255.0f );
1225 currentVertexAttrib.blue = (unsigned char)ClampTo255( blue * alpha / 255.0f );
1227 else
1229 currentVertexAttrib.red = red;
1230 currentVertexAttrib.green = green;
1231 currentVertexAttrib.blue = blue;
1233 currentVertexAttrib.alpha = alpha;
1236 void glColor3ub( GLubyte red, GLubyte green, GLubyte blue )
1238 currentVertexAttrib.red = red;
1239 currentVertexAttrib.green = green;
1240 currentVertexAttrib.blue = blue;
1241 currentVertexAttrib.alpha = 255;
1244 void glNormal3fv( const GLfloat *v )
1246 FlushOnStateChange( );
1247 glEsImpl->glNormal3f( v[0], v[1], v[2] );
1250 void glCopyTexImage2D( GLenum target, GLint level, GLenum internalformat, GLint x, GLint y, GLsizei width, GLsizei height, GLint border )
1252 FlushOnStateChange( );
1253 glEsImpl->glCopyTexImage2D( target, level, internalformat, x, y, width, height, border );
1256 void glTexImage1D( GLenum target, GLint level, GLint internalformat, GLsizei width, GLint border, GLenum format, GLenum type, const GLvoid *pixels )
1258 glTexImage2D( GL_TEXTURE_2D, level, internalformat, width, 1, border, format, type, pixels );
1261 void glTexImage3D( GLenum target, GLint level, GLint internalformat, GLsizei width, GLsizei height, GLsizei depth, GLint border, GLenum format, GLenum type, const GLvoid *pixels )
1263 glTexImage2D( GL_TEXTURE_2D, level, internalformat, width, height, border, format, type, pixels );
1266 void glTexSubImage1D( GLenum target, GLint level, GLint xoffset, GLsizei width, GLenum format, GLenum type, const GLvoid *pixels )
1268 glTexSubImage2D( target, level, xoffset, 0, width, 1, format, type, pixels );
1271 void glTexSubImage3D( GLenum target, GLint level,
1272 GLint xoffset, GLint yoffset,
1273 GLint zoffset, GLsizei width,
1274 GLsizei height, GLsizei depth,
1275 GLenum format,
1276 GLenum type, const GLvoid *pixels )
1278 glTexSubImage2D( target, level, xoffset, yoffset, width, height, format, type, pixels );
1281 GLboolean glIsTexture( GLuint texture )
1283 FlushOnStateChange( );
1284 return glEsImpl->glIsTexture( texture );
1287 void glTexGeni( GLenum coord, GLenum pname, GLint param )
1289 //for mirrors? not needed for original hl?
1292 void glTexGenfv( GLenum coord, GLenum pname, const GLfloat *params )
1294 //for mirrors? not needed for original hl?
1297 //-- --//
1299 void glHint( GLenum target, GLenum mode )
1301 FlushOnStateChange( );
1302 glEsImpl->glHint( target, mode );
1305 void glBlendFunc( GLenum sfactor, GLenum dfactor )
1307 if ( ( nanoglState.sfactor == sfactor ) && ( nanoglState.dfactor == dfactor ) )
1309 return;
1312 if( sfactor == GL_SRC_ALPHA && dfactor == GL_ONE )
1314 sfactor = GL_ONE; // workaround gles bug
1315 nanoglState.stupidglesbug = GL_TRUE;
1317 else
1318 nanoglState.stupidglesbug = GL_FALSE;
1320 nanoglState.sfactor = sfactor;
1321 nanoglState.dfactor = dfactor;
1322 FlushOnStateChange( );
1323 glEsImpl->glBlendFunc( sfactor, dfactor );
1326 void glPopMatrix( void )
1328 FlushOnStateChange( );
1329 glEsImpl->glPopMatrix( );
1332 void glShadeModel( GLenum mode )
1334 if ( nanoglState.shademodel == mode )
1336 return;
1338 nanoglState.shademodel = mode;
1339 FlushOnStateChange( );
1340 glEsImpl->glShadeModel( mode );
1343 void glPushMatrix( void )
1345 FlushOnStateChange( );
1346 glEsImpl->glPushMatrix( );
1349 void glTexEnvf( GLenum target, GLenum pname, GLfloat param )
1351 if ( target == GL_TEXTURE_ENV )
1353 if ( pname == GL_TEXTURE_ENV_MODE )
1355 if ( param == activetmuState->texture_env_mode.value )
1357 return;
1359 else
1361 FlushOnStateChange( );
1362 glEsImpl->glTexEnvf( target, pname, param );
1363 activetmuState->texture_env_mode.value = param;
1364 return;
1368 FlushOnStateChange( );
1369 glEsImpl->glTexEnvf( target, pname, param );
1372 void glVertex3fv( const GLfloat *v )
1374 GLfloat *vert = (GLfloat *)ptrVertexAttribArray++;
1375 memcpy( vert, v, 3 * sizeof( GLfloat ) );
1376 #if defined( __MULTITEXTURE_SUPPORT__ )
1377 memcpy( vert + 3, &currentVertexAttrib.red, 5 * sizeof( GLfloat ) );
1378 #else
1379 memcpy( vert + 4, &currentVertexAttrib.red, 3 * sizeof( GLfloat ) );
1380 #endif
1383 void glDepthMask( GLboolean flag )
1385 if ( nanoglState.depthmask == flag )
1387 return;
1389 nanoglState.depthmask = flag;
1390 FlushOnStateChange( );
1391 glEsImpl->glDepthMask( flag );
1394 void glBindTexture( GLenum target, GLuint texture )
1396 if ( activetmuState->boundtexture.value == texture )
1398 return;
1400 FlushOnStateChange( );
1401 activetmuState->boundtexture.value = texture;
1402 glEsImpl->glBindTexture( target, texture );
1405 void glGetIntegerv( GLenum pname, GLint *params )
1407 FlushOnStateChange( );
1408 glEsImpl->glGetIntegerv( pname, params );
1411 GLubyte nano_extensions_string[4096];
1412 const GLubyte *glGetString( GLenum name )
1415 if ( name == GL_EXTENSIONS )
1417 #if defined( __MULTITEXTURE_SUPPORT__ )
1418 sprintf( (char *)nano_extensions_string, "%s %s", glEsImpl->glGetString( name ), "GL_ARB_multitexture EXT_texture_env_add" );
1419 #else
1420 sprintf( (char *)nano_extensions_string, "%s %s", glEsImpl->glGetString( name ), "EXT_texture_env_add" );
1421 #endif
1422 return nano_extensions_string;
1424 return glEsImpl->glGetString( name );
1427 void glAlphaFunc( GLenum func, GLclampf ref )
1429 FlushOnStateChange( );
1430 glEsImpl->glAlphaFunc( func, ref );
1433 void glFlush( void )
1435 FlushOnStateChange( );
1436 glEsImpl->glFlush( );
1439 void glReadPixels( GLint x, GLint y, GLsizei width, GLsizei height, GLenum format, GLenum type, GLvoid *pixels )
1441 if ( format == GL_DEPTH_COMPONENT )
1443 // OpenglEs 1.1 does not support reading depth buffer without an extension
1444 memset( pixels, 0xff, 4 );
1445 return;
1447 FlushOnStateChange( );
1448 glEsImpl->glReadPixels( x, y, width, height, format, type, pixels );
1451 void glReadBuffer( GLenum /*mode*/ )
1455 void glLoadMatrixf( const GLfloat *m )
1457 FlushOnStateChange( );
1458 glEsImpl->glLoadMatrixf( m );
1461 void glTexSubImage2D( GLenum target, GLint level, GLint xoffset, GLint yoffset, GLsizei width, GLsizei height, GLenum format, GLenum type, const GLvoid *pixels )
1463 FlushOnStateChange( );
1464 glEsImpl->glTexSubImage2D( target, level, xoffset, yoffset, width, height, format, type, pixels );
1467 void glClearColor( GLclampf red, GLclampf green, GLclampf blue, GLclampf alpha )
1469 FlushOnStateChange( );
1470 glEsImpl->glClearColor( red, green, blue, alpha );
1473 GLenum glGetError( void )
1475 //FlushOnStateChange();
1476 return GL_NO_ERROR; //glEsImpl->glGetError();
1479 void glActiveTexture( GLenum texture )
1481 if ( activetmu == texture )
1483 return;
1485 if ( delayedttmuchange )
1487 delayedttmuchange = GL_FALSE;
1489 else
1491 delayedttmuchange = GL_TRUE;
1492 delayedtmutarget = texture;
1494 if ( texture == GL_TEXTURE0 )
1496 activetmuState = &tmuState0;
1498 else
1500 activetmuState = &tmuState1;
1502 activetmu = texture;
1505 void glClientActiveTexture( GLenum texture )
1507 clientactivetmu = texture;
1510 void glPolygonMode( GLenum face, GLenum mode )
1514 void glDeleteTextures( GLsizei n, const GLuint *textures )
1516 FlushOnStateChange( );
1517 glEsImpl->glDeleteTextures( n, textures );
1520 void glClearDepth( GLclampf depth )
1522 FlushOnStateChange( );
1523 glEsImpl->glClearDepthf( depth );
1526 void glClipPlane( GLenum plane, const GLdouble *equation )
1528 FlushOnStateChange( );
1529 float array[4];
1530 array[0] = ( GLfloat )( equation[0] );
1531 array[1] = ( GLfloat )( equation[1] );
1532 array[2] = ( GLfloat )( equation[2] );
1533 array[3] = ( GLfloat )( equation[3] );
1534 glEsImpl->glClipPlanef( plane, array );
1537 void glScissor( GLint x, GLint y, GLsizei width, GLsizei height )
1539 FlushOnStateChange( );
1540 glEsImpl->glScissor( x, y, width, height );
1543 void glPointSize( GLfloat size )
1545 FlushOnStateChange( );
1546 glEsImpl->glPointSize( size );
1549 void glArrayElement( GLint i )
1552 void glLineWidth( GLfloat width )
1555 void glCallList( GLuint list )
1558 void glColorMask( GLboolean red, GLboolean green, GLboolean blue, GLboolean alpha )
1561 void glStencilFunc( GLenum func, GLint ref, GLuint mask )
1564 void glStencilOp( GLenum fail, GLenum zfail, GLenum zpass )
1568 struct ptrstate vertex_array;
1569 struct ptrstate color_array;
1570 struct ptrstate texture_coord_array;
1572 void glDrawElements( GLenum mode, GLsizei count, GLenum type, const GLvoid *indices )
1574 // ensure that all primitives specified between glBegin/glEnd pairs
1575 // are rendered first, and that we have correct tmu in use..
1576 FlushOnStateChange( );
1577 // setup correct vertex/color/texcoord pointers
1578 if ( arraysValid ||
1579 tmuState0.vertex_array.changed ||
1580 tmuState0.color_array.changed ||
1581 tmuState0.texture_coord_array.changed || tmuState0.normal_array.changed )
1583 glEsImpl->glClientActiveTexture( GL_TEXTURE0 );
1585 if ( arraysValid || tmuState0.vertex_array.changed )
1587 if ( tmuState0.vertex_array.enabled )
1589 glEsImpl->glEnableClientState( GL_VERTEX_ARRAY );
1591 else
1593 glEsImpl->glDisableClientState( GL_VERTEX_ARRAY );
1595 glEsImpl->glVertexPointer( tmuState0.vertex_array.size,
1596 tmuState0.vertex_array.type,
1597 tmuState0.vertex_array.stride,
1598 tmuState0.vertex_array.ptr );
1599 tmuState0.vertex_array.changed = GL_FALSE;
1601 if ( arraysValid || tmuState0.color_array.changed )
1603 if ( tmuState0.color_array.enabled )
1605 glEsImpl->glEnableClientState( GL_COLOR_ARRAY );
1607 else
1609 glEsImpl->glDisableClientState( GL_COLOR_ARRAY );
1611 glEsImpl->glColorPointer( tmuState0.color_array.size,
1612 tmuState0.color_array.type,
1613 tmuState0.color_array.stride,
1614 tmuState0.color_array.ptr );
1615 tmuState0.color_array.changed = GL_FALSE;
1617 if ( arraysValid || tmuState0.normal_array.changed )
1619 if ( tmuState0.normal_array.enabled )
1621 glEsImpl->glEnableClientState( GL_NORMAL_ARRAY );
1623 else
1625 glEsImpl->glDisableClientState( GL_NORMAL_ARRAY );
1627 glEsImpl->glNormalPointer( tmuState0.normal_array.type,
1628 tmuState0.normal_array.stride,
1629 tmuState0.normal_array.ptr );
1630 tmuState0.normal_array.changed = GL_FALSE;
1632 if ( arraysValid || tmuState0.texture_coord_array.changed )
1634 tmuState0.texture_coord_array.changed = GL_FALSE;
1635 if ( tmuState0.texture_coord_array.enabled )
1637 glEsImpl->glEnableClientState( GL_TEXTURE_COORD_ARRAY );
1639 else
1641 glEsImpl->glDisableClientState( GL_TEXTURE_COORD_ARRAY );
1643 glEsImpl->glTexCoordPointer( tmuState0.texture_coord_array.size,
1644 tmuState0.texture_coord_array.type,
1645 tmuState0.texture_coord_array.stride,
1646 tmuState0.texture_coord_array.ptr );
1649 if ( arraysValid || tmuState1.texture_coord_array.changed )
1651 tmuState1.texture_coord_array.changed = GL_FALSE;
1652 glEsImpl->glClientActiveTexture( GL_TEXTURE1 );
1653 if ( tmuState1.texture_coord_array.enabled )
1655 glEsImpl->glEnableClientState( GL_TEXTURE_COORD_ARRAY );
1657 else
1659 glEsImpl->glDisableClientState( GL_TEXTURE_COORD_ARRAY );
1661 glEsImpl->glTexCoordPointer( tmuState1.texture_coord_array.size,
1662 tmuState1.texture_coord_array.type,
1663 tmuState1.texture_coord_array.stride,
1664 tmuState1.texture_coord_array.ptr );
1667 arraysValid = GL_FALSE;
1668 glEsImpl->glDrawElements( mode, count, type, indices );
1671 void glEnableClientState( GLenum array )
1673 struct nanotmuState *clientstate = NULL;
1674 if ( clientactivetmu == GL_TEXTURE0 )
1676 clientstate = &tmuState0;
1678 else if ( clientactivetmu == GL_TEXTURE1 )
1680 clientstate = &tmuState1;
1682 else
1684 return;
1686 switch ( array )
1688 case GL_VERTEX_ARRAY:
1689 if ( clientstate->vertex_array.enabled )
1691 return;
1693 clientstate->vertex_array.enabled = GL_TRUE;
1694 clientstate->vertex_array.changed = GL_TRUE;
1695 break;
1696 case GL_COLOR_ARRAY:
1697 if ( clientstate->color_array.enabled )
1699 return;
1701 clientstate->color_array.enabled = GL_TRUE;
1702 clientstate->color_array.changed = GL_TRUE;
1704 break;
1705 case GL_NORMAL_ARRAY:
1706 if ( clientstate->normal_array.enabled )
1708 return;
1710 clientstate->normal_array.enabled = GL_TRUE;
1711 clientstate->normal_array.changed = GL_TRUE;
1713 break;
1714 case GL_TEXTURE_COORD_ARRAY:
1715 if ( clientstate->texture_coord_array.enabled )
1717 return;
1719 clientstate->texture_coord_array.enabled = GL_TRUE;
1720 clientstate->texture_coord_array.changed = GL_TRUE;
1721 break;
1722 default:
1723 break;
1726 void glDisableClientState( GLenum array )
1728 struct nanotmuState *clientstate = NULL;
1729 if ( clientactivetmu == GL_TEXTURE0 )
1731 clientstate = &tmuState0;
1733 else if ( clientactivetmu == GL_TEXTURE1 )
1735 clientstate = &tmuState1;
1737 else
1739 return;
1741 switch ( array )
1743 case GL_VERTEX_ARRAY:
1744 if ( !clientstate->vertex_array.enabled )
1746 return;
1748 clientstate->vertex_array.enabled = GL_FALSE;
1749 clientstate->vertex_array.changed = GL_TRUE;
1750 break;
1751 case GL_COLOR_ARRAY:
1752 if ( !clientstate->color_array.enabled )
1754 return;
1756 clientstate->color_array.enabled = GL_FALSE;
1757 clientstate->color_array.changed = GL_TRUE;
1759 break;
1760 case GL_NORMAL_ARRAY:
1761 if ( !clientstate->normal_array.enabled )
1763 return;
1765 clientstate->normal_array.enabled = GL_FALSE;
1766 clientstate->normal_array.changed = GL_TRUE;
1768 break;
1769 case GL_TEXTURE_COORD_ARRAY:
1770 if ( !clientstate->texture_coord_array.enabled )
1772 return;
1774 clientstate->texture_coord_array.enabled = GL_FALSE;
1775 clientstate->texture_coord_array.changed = GL_TRUE;
1776 break;
1777 default:
1778 break;
1781 void glVertexPointer( GLint size, GLenum type, GLsizei stride, const GLvoid *pointer )
1783 if ( tmuState0.vertex_array.size == size &&
1784 tmuState0.vertex_array.stride == stride &&
1785 tmuState0.vertex_array.type == type &&
1786 tmuState0.vertex_array.ptr == pointer )
1788 return;
1790 tmuState0.vertex_array.size = size;
1791 tmuState0.vertex_array.stride = stride;
1792 tmuState0.vertex_array.type = type;
1793 tmuState0.vertex_array.ptr = (GLvoid *)pointer;
1794 tmuState0.vertex_array.changed = GL_TRUE;
1796 void glTexCoordPointer( GLint size, GLenum type, GLsizei stride, const GLvoid *pointer )
1798 struct nanotmuState *clientstate = NULL;
1799 if ( clientactivetmu == GL_TEXTURE0 )
1801 clientstate = &tmuState0;
1803 else if ( clientactivetmu == GL_TEXTURE1 )
1805 clientstate = &tmuState1;
1807 if ( clientstate->texture_coord_array.size == size &&
1808 clientstate->texture_coord_array.stride == stride &&
1809 clientstate->texture_coord_array.type == type &&
1810 clientstate->texture_coord_array.ptr == pointer )
1812 return;
1814 clientstate->texture_coord_array.size = size;
1815 clientstate->texture_coord_array.stride = stride;
1816 clientstate->texture_coord_array.type = type;
1817 clientstate->texture_coord_array.ptr = (GLvoid *)pointer;
1818 clientstate->texture_coord_array.changed = GL_TRUE;
1820 void glColorPointer( GLint size, GLenum type, GLsizei stride, const GLvoid *pointer )
1822 if ( tmuState0.color_array.size == size &&
1823 tmuState0.color_array.stride == stride &&
1824 tmuState0.color_array.type == type &&
1825 tmuState0.color_array.ptr == pointer )
1827 return;
1829 tmuState0.color_array.size = size;
1830 tmuState0.color_array.stride = stride;
1831 tmuState0.color_array.type = type;
1832 tmuState0.color_array.ptr = (GLvoid *)pointer;
1833 tmuState0.color_array.changed = GL_TRUE;
1836 void glNormalPointer( GLenum type, GLsizei stride, const GLvoid *pointer )
1838 int size = 0;
1839 if ( tmuState0.normal_array.size == size &&
1840 tmuState0.normal_array.stride == stride &&
1841 tmuState0.normal_array.type == type &&
1842 tmuState0.normal_array.ptr == pointer )
1844 return;
1846 tmuState0.normal_array.size = size;
1847 tmuState0.normal_array.stride = stride;
1848 tmuState0.normal_array.type = type;
1849 tmuState0.normal_array.ptr = (GLvoid *)pointer;
1850 tmuState0.normal_array.changed = GL_TRUE;
1852 void glPolygonOffset( GLfloat factor, GLfloat units )
1854 FlushOnStateChange( );
1855 glEsImpl->glPolygonOffset( factor, units );
1857 void glStencilMask( GLuint mask )
1860 void glClearStencil( GLint s )
1864 #if defined( __MULTITEXTURE_SUPPORT__ )
1866 extern "C" void glMultiTexCoord2fARB( GLenum target, GLfloat s, GLfloat t );
1868 void glMultiTexCoord2fARB( GLenum target, GLfloat s, GLfloat t )
1870 if ( target == GL_TEXTURE0 )
1872 glTexCoord2f( s, t );
1874 else
1876 currentVertexAttrib.s_multi = s;
1877 currentVertexAttrib.t_multi = t;
1880 #endif
1882 /* Vladimir */
1883 /*void glDrawArrays( GLenum mode, int first, int count)
1885 FlushOnStateChange();
1886 glEsImpl->glDrawArrays(mode, first , count);
1887 }*/
1888 void glMultMatrixf( const GLfloat *m )
1890 FlushOnStateChange( );
1891 glEsImpl->glMultMatrixf( m );
1894 void glPixelStorei( GLenum pname, GLint param )
1896 FlushOnStateChange( );
1897 glEsImpl->glPixelStorei( pname, param );
1900 void glFogf( GLenum pname, GLfloat param )
1902 FlushOnStateChange( );
1903 glEsImpl->glFogf( pname, param );
1906 void glFogfv( GLenum pname, const GLfloat *params )
1908 FlushOnStateChange( );
1909 glEsImpl->glFogfv( pname, params );
1912 void glGetTexParameteriv( GLenum target, GLenum pname, GLint *params )
1914 FlushOnStateChange( );
1915 glEsImpl->glGetTexParameteriv( target, pname, params );
1918 // This gives: called unimplemented OpenGL ES API (Android)
1919 void glTexParameteri( GLenum target, GLenum pname, GLint param )
1921 if ( pname == GL_TEXTURE_BORDER_COLOR )
1923 return; // not supported by opengl es
1925 if ( ( pname == GL_TEXTURE_WRAP_S ||
1926 pname == GL_TEXTURE_WRAP_T ) &&
1927 param == GL_CLAMP )
1929 param = 0x812F;
1932 FlushOnStateChange( );
1933 glEsImpl->glTexParameteri( target, pname, param );
1936 void glTexParameterx( GLenum target, GLenum pname, GLfixed param )
1938 if ( pname == GL_TEXTURE_BORDER_COLOR )
1940 return; // not supported by opengl es
1942 if ( ( pname == GL_TEXTURE_WRAP_S ||
1943 pname == GL_TEXTURE_WRAP_T ) &&
1944 param == GL_CLAMP )
1946 param = 0x812F;
1948 FlushOnStateChange( );
1949 glEsImpl->glTexParameterx( target, pname, param );
1952 void glGenTextures( GLsizei n, GLuint *textures )
1954 FlushOnStateChange( );
1955 glEsImpl->glGenTextures( n, textures );
1958 void glFrontFace( GLenum mode )
1960 FlushOnStateChange( );
1961 glEsImpl->glFrontFace( mode );
1963 // End Vladimir
1965 void glTexEnvi( GLenum target, GLenum pname, GLint param )
1967 if ( target == GL_TEXTURE_ENV )
1969 if ( pname == GL_TEXTURE_ENV_MODE )
1971 if ( param == activetmuState->texture_env_mode.value )
1973 return;
1975 else
1977 FlushOnStateChange( );
1978 glEsImpl->glTexEnvi( target, pname, param );
1979 activetmuState->texture_env_mode.value = param;
1980 return;
1984 FlushOnStateChange( );
1985 glEsImpl->glTexEnvi( target, pname, param );
1988 #ifdef __MULTITEXTURE_SUPPORT__
1989 void glMultiTexCoord3fARB( GLenum a, GLfloat b, GLfloat c, GLfloat )
1991 return glMultiTexCoord2fARB( a, b, c );
1994 void glMultiTexCoord2f( GLenum, GLfloat, GLfloat )
1997 #endif
1998 void glDrawArrays( GLenum mode, GLint first, GLsizei count )
2000 // ensure that all primitives specified between glBegin/glEnd pairs
2001 // are rendered first, and that we have correct tmu in use..
2002 if ( mode == GL_QUADS )
2003 mode = GL_TRIANGLE_FAN;
2004 FlushOnStateChange( );
2005 // setup correct vertex/color/texcoord pointers
2006 if ( arraysValid ||
2007 tmuState0.vertex_array.changed ||
2008 tmuState0.color_array.changed ||
2009 tmuState0.texture_coord_array.changed || tmuState0.normal_array.changed )
2011 glEsImpl->glClientActiveTexture( GL_TEXTURE0 );
2013 if ( arraysValid || tmuState0.vertex_array.changed )
2015 if ( tmuState0.vertex_array.enabled )
2017 glEsImpl->glEnableClientState( GL_VERTEX_ARRAY );
2019 else
2021 glEsImpl->glDisableClientState( GL_VERTEX_ARRAY );
2023 glEsImpl->glVertexPointer( tmuState0.vertex_array.size,
2024 tmuState0.vertex_array.type,
2025 tmuState0.vertex_array.stride,
2026 tmuState0.vertex_array.ptr );
2027 tmuState0.vertex_array.changed = GL_FALSE;
2029 if ( arraysValid || tmuState0.color_array.changed )
2031 if ( tmuState0.color_array.enabled )
2033 glEsImpl->glEnableClientState( GL_COLOR_ARRAY );
2035 else
2037 glEsImpl->glDisableClientState( GL_COLOR_ARRAY );
2039 glEsImpl->glColorPointer( tmuState0.color_array.size,
2040 tmuState0.color_array.type,
2041 tmuState0.color_array.stride,
2042 tmuState0.color_array.ptr );
2043 tmuState0.color_array.changed = GL_FALSE;
2045 if ( arraysValid || tmuState0.normal_array.changed )
2047 if ( tmuState0.normal_array.enabled )
2049 glEsImpl->glEnableClientState( GL_NORMAL_ARRAY );
2051 else
2053 glEsImpl->glDisableClientState( GL_NORMAL_ARRAY );
2055 glEsImpl->glNormalPointer( tmuState0.normal_array.type,
2056 tmuState0.normal_array.stride,
2057 tmuState0.normal_array.ptr );
2058 tmuState0.normal_array.changed = GL_FALSE;
2060 if ( arraysValid || tmuState0.texture_coord_array.changed )
2062 tmuState0.texture_coord_array.changed = GL_FALSE;
2063 if ( tmuState0.texture_coord_array.enabled )
2065 glEsImpl->glEnableClientState( GL_TEXTURE_COORD_ARRAY );
2067 else
2069 glEsImpl->glDisableClientState( GL_TEXTURE_COORD_ARRAY );
2071 glEsImpl->glTexCoordPointer( tmuState0.texture_coord_array.size,
2072 tmuState0.texture_coord_array.type,
2073 tmuState0.texture_coord_array.stride,
2074 tmuState0.texture_coord_array.ptr );
2077 if ( arraysValid || tmuState1.texture_coord_array.changed )
2079 tmuState1.texture_coord_array.changed = GL_FALSE;
2080 glEsImpl->glClientActiveTexture( GL_TEXTURE1 );
2081 if ( tmuState1.texture_coord_array.enabled )
2083 glEsImpl->glEnableClientState( GL_TEXTURE_COORD_ARRAY );
2085 else
2087 glEsImpl->glDisableClientState( GL_TEXTURE_COORD_ARRAY );
2089 glEsImpl->glTexCoordPointer( tmuState1.texture_coord_array.size,
2090 tmuState1.texture_coord_array.type,
2091 tmuState1.texture_coord_array.stride,
2092 tmuState1.texture_coord_array.ptr );
2095 arraysValid = GL_FALSE;
2096 glEsImpl->glDrawArrays( mode, first, count );
2098 /*void glNormalPointer(GLenum type, GLsizei stride, const void *ptr)
2100 glEsImpl->glNormalPointer( type, stride, ptr );
2101 }*/
2103 void glCopyTexSubImage2D( GLenum target, GLint level, GLint xoffset, GLint yoffset, GLint x, GLint y, GLsizei width, GLsizei height )
2105 FlushOnStateChange( );
2106 glEsImpl->glCopyTexSubImage2D( target, level, xoffset, yoffset, x, y, width, height );
2109 void glGenFramebuffers( GLsizei n, GLuint *framebuffers )
2111 FlushOnStateChange( );
2112 glEsImpl->glGenFramebuffers( n, framebuffers );
2115 void glGenRenderbuffers( GLsizei n, GLuint *renderbuffers )
2117 FlushOnStateChange( );
2118 glEsImpl->glGenRenderbuffers( n, renderbuffers );
2121 void glBindRenderbuffer( GLenum target, GLuint renderbuffer )
2123 FlushOnStateChange( );
2124 glEsImpl->glBindRenderbuffer( target, renderbuffer );
2127 void glBindFramebuffer( GLenum target, GLuint framebuffer )
2129 FlushOnStateChange( );
2130 glEsImpl->glBindFramebuffer( target, framebuffer );
2133 void glFramebufferRenderbuffer( GLenum target, GLenum attachment, GLenum renderbuffertarget, GLuint renderbuffer )
2135 FlushOnStateChange( );
2136 glEsImpl->glFramebufferRenderbuffer( target, attachment, renderbuffertarget, renderbuffer );
2139 void glDeleteFramebuffers( GLsizei n, const GLuint *framebuffers )
2141 FlushOnStateChange( );
2142 glEsImpl->glDeleteFramebuffers( n, framebuffers );
2145 void glDeleteRenderbuffers( GLsizei n, const GLuint *renderbuffers )
2147 FlushOnStateChange( );
2148 glEsImpl->glDeleteRenderbuffers( n, renderbuffers );
2150 void glFramebufferTexture2D( GLenum target, GLenum attachment, GLenum textarget, GLuint texture, GLint level )
2152 FlushOnStateChange( );
2153 glEsImpl->glFramebufferTexture2D( target, attachment, textarget, texture, level );
2156 void glRenderbufferStorage( GLenum target, GLenum internalformat, GLsizei width, GLsizei height )
2158 FlushOnStateChange( );
2159 glEsImpl->glRenderbufferStorage( target, internalformat, width, height );