DEADSOFTWARE

Reformat with clang-format. Nothing useful
[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 GLclampf depth_range_near;
64 GLclampf depth_range_far;
65 GLenum depth_func;
66 GLenum cullface;
67 GLenum shademodel;
68 GLenum sfactor;
69 GLenum dfactor;
70 GLenum matrixmode;
71 };
73 static struct nanoState nanoglState;
75 static struct nanoState nanoglInitState =
76 {
77 GL_FALSE,
78 GL_FALSE,
79 GL_FALSE,
80 GL_FALSE,
81 GL_FALSE,
82 GL_FALSE,
83 GL_FALSE,
84 GL_TRUE,
85 GL_FALSE,
86 GL_FALSE,
87 GL_FALSE,
88 GL_FALSE,
89 GL_FALSE,
90 GL_TRUE,
91 GL_FALSE,
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_TRUE,
102 0.0f,
103 1.0f,
104 GL_LESS,
105 GL_BACK,
106 GL_SMOOTH,
107 GL_ONE,
108 GL_ZERO,
109 GL_MODELVIEW,
110 };
112 struct booleanstate
114 GLboolean value;
115 GLboolean changed;
116 };
118 struct floatstate
120 GLfloat value;
121 GLboolean changed;
122 };
124 struct uintstate
126 GLuint value;
127 GLboolean changed;
128 };
130 struct ptrstate
132 GLint size;
133 GLenum type;
134 GLsizei stride;
135 GLvoid *ptr;
136 GLboolean changed;
137 GLboolean enabled;
138 };
140 struct nanotmuState
142 struct booleanstate texture_2d;
143 struct floatstate texture_env_mode;
144 struct uintstate boundtexture;
145 struct ptrstate vertex_array;
146 struct ptrstate color_array;
147 struct ptrstate texture_coord_array;
148 struct ptrstate normal_array;
149 };
151 static struct nanotmuState tmuState0;
152 static struct nanotmuState tmuState1;
154 static struct nanotmuState tmuInitState =
156 {GL_FALSE, GL_FALSE},
157 {GL_MODULATE, GL_FALSE},
158 {0x7fffffff, GL_FALSE},
159 {4, GL_FLOAT, 0, NULL, GL_FALSE, GL_FALSE},
160 {4, GL_FLOAT, 0, NULL, GL_FALSE, GL_FALSE},
161 {4, GL_FLOAT, 0, NULL, GL_FALSE, GL_FALSE},
162 {3, GL_FLOAT, 0, NULL, GL_FALSE, GL_FALSE},
163 };
165 static struct nanotmuState *activetmuState = &tmuState0;
167 extern "C++" GlESInterface *glEsImpl;
169 static GLenum wrapperPrimitiveMode = GL_QUADS;
170 GLboolean useTexCoordArray = GL_FALSE;
171 static GLenum activetmu = GL_TEXTURE0;
172 static GLenum clientactivetmu = GL_TEXTURE0;
174 #if defined( __MULTITEXTURE_SUPPORT__ )
175 GLboolean useMultiTexCoordArray = GL_FALSE;
176 #endif
178 #if !defined( __WINS__ )
179 //#define __FORCEINLINE __forceinline
180 #define __FORCEINLINE inline
181 #else
182 #define __FORCEINLINE
183 #endif
185 static GLboolean delayedttmuchange = GL_FALSE;
186 static GLenum delayedtmutarget = GL_TEXTURE0;
188 struct VertexAttrib
190 float x;
191 float y;
192 float z;
193 #if !defined( __MULTITEXTURE_SUPPORT__ )
194 float padding;
195 #endif
196 unsigned char red;
197 unsigned char green;
198 unsigned char blue;
199 unsigned char alpha;
201 float s;
202 float t;
203 #if defined( __MULTITEXTURE_SUPPORT__ )
204 float s_multi;
205 float t_multi;
206 #endif
207 };
209 static VertexAttrib vertexattribs[60000];
211 static GLushort indexArray[50000];
213 static GLuint vertexCount = 0;
214 static GLuint indexCount = 0;
215 static GLuint vertexMark = 0;
216 static int indexbase = 0;
218 static VertexAttrib *ptrVertexAttribArray = NULL;
219 static VertexAttrib *ptrVertexAttribArrayMark = NULL;
221 static VertexAttrib currentVertexAttrib;
222 #if defined( __MULTITEXTURE_SUPPORT__ )
223 static VertexAttrib currentVertexAttribInit = {0.0f, 0.0f, 0.0f, 255, 255, 255, 255, 0.0f, 0.0f, 0.0f, 0.0f};
224 #else
225 static VertexAttrib currentVertexAttribInit = {
226 0.0f, 0.0f, 0.0f, 0.0f, 255, 255, 255, 255, 0.0f, 0.0f,
227 };
228 #endif
229 static GLushort *ptrIndexArray = NULL;
231 static GLboolean arraysValid = GL_FALSE;
233 void InitGLStructs( )
235 ptrVertexAttribArray = vertexattribs;
236 ptrVertexAttribArrayMark = ptrVertexAttribArray;
237 ptrIndexArray = indexArray;
239 memcpy( &nanoglState, &nanoglInitState, sizeof( struct nanoState ) );
240 memcpy( &tmuState0, &tmuInitState, sizeof( struct nanotmuState ) );
241 memcpy( &tmuState1, &tmuInitState, sizeof( struct nanotmuState ) );
242 memcpy( &currentVertexAttrib, &currentVertexAttribInit, sizeof( struct VertexAttrib ) );
244 activetmuState = &tmuState0;
245 wrapperPrimitiveMode = GL_QUADS;
246 useTexCoordArray = GL_FALSE;
247 activetmu = GL_TEXTURE0;
248 clientactivetmu = GL_TEXTURE0;
249 delayedttmuchange = GL_FALSE;
250 delayedtmutarget = GL_TEXTURE0;
251 vertexCount = 0;
252 indexCount = 0;
253 vertexMark = 0;
254 indexbase = 0;
255 arraysValid = GL_FALSE;
258 void ResetNanoState( )
261 if ( tmuState0.color_array.enabled )
263 glEsImpl->glEnableClientState( GL_COLOR_ARRAY );
265 else
267 glEsImpl->glDisableClientState( GL_COLOR_ARRAY );
270 if ( tmuState0.vertex_array.enabled )
272 glEsImpl->glEnableClientState( GL_VERTEX_ARRAY );
274 else
276 glEsImpl->glDisableClientState( GL_VERTEX_ARRAY );
279 if ( tmuState0.texture_coord_array.enabled )
281 glEsImpl->glEnableClientState( GL_TEXTURE_COORD_ARRAY );
283 else
285 glEsImpl->glDisableClientState( GL_TEXTURE_COORD_ARRAY );
288 if ( tmuState0.normal_array.enabled )
290 glEsImpl->glEnableClientState( GL_NORMAL_ARRAY );
292 else
294 glEsImpl->glDisableClientState( GL_NORMAL_ARRAY );
296 glEsImpl->glVertexPointer( tmuState0.vertex_array.size,
297 tmuState0.vertex_array.type,
298 tmuState0.vertex_array.stride,
299 tmuState0.vertex_array.ptr );
301 glEsImpl->glTexCoordPointer( tmuState0.texture_coord_array.size,
302 tmuState0.texture_coord_array.type,
303 tmuState0.texture_coord_array.stride,
304 tmuState0.texture_coord_array.ptr );
306 glEsImpl->glColorPointer( tmuState0.color_array.size,
307 tmuState0.color_array.type,
308 tmuState0.color_array.stride,
309 tmuState0.color_array.ptr );
311 glEsImpl->glNormalPointer(
312 tmuState0.normal_array.type,
313 tmuState0.normal_array.stride,
314 tmuState0.normal_array.ptr );
316 glEsImpl->glMatrixMode( nanoglState.matrixmode );
318 glEsImpl->glColor4f( currentVertexAttrib.red, currentVertexAttrib.green, currentVertexAttrib.blue, currentVertexAttrib.alpha );
320 glEsImpl->glBlendFunc( nanoglState.sfactor, nanoglState.dfactor );
322 //glEsImpl->glBindTexture(GL_TEXTURE_2D, stackTextureState);
324 glEsImpl->glTexEnvi( GL_TEXTURE_ENV, GL_TEXTURE_ENV_MODE, activetmuState->texture_env_mode.value );
326 arraysValid = GL_FALSE;
329 void FlushOnStateChange( )
331 if ( delayedttmuchange )
333 delayedttmuchange = GL_FALSE;
334 #ifndef USE_CORE_PROFILE
335 glEsImpl->glActiveTexture( delayedtmutarget );
336 #endif
339 if ( !vertexCount )
340 return;
342 if ( !arraysValid )
344 glEsImpl->glClientActiveTexture( GL_TEXTURE0 );
345 glEsImpl->glVertexPointer( 3, GL_FLOAT, sizeof( VertexAttrib ), &vertexattribs[0].x );
346 glEsImpl->glColorPointer( 4, GL_UNSIGNED_BYTE, sizeof( VertexAttrib ), &vertexattribs[0].red );
347 glEsImpl->glTexCoordPointer( 2, GL_FLOAT, sizeof( VertexAttrib ), &vertexattribs[0].s );
348 glEsImpl->glEnableClientState( GL_VERTEX_ARRAY );
349 glEsImpl->glEnableClientState( GL_TEXTURE_COORD_ARRAY );
350 glEsImpl->glEnableClientState( GL_COLOR_ARRAY );
351 #if defined( __MULTITEXTURE_SUPPORT__ )
352 glEsImpl->glClientActiveTexture( GL_TEXTURE1 );
353 glEsImpl->glTexCoordPointer( 2, GL_FLOAT, sizeof( VertexAttrib ), &vertexattribs[0].s_multi );
354 glEsImpl->glEnableClientState( GL_TEXTURE_COORD_ARRAY );
355 glEsImpl->glClientActiveTexture( GL_TEXTURE0 );
356 #endif
357 arraysValid = GL_TRUE;
360 glEsImpl->glDrawElements( GL_TRIANGLES, vertexCount, GL_UNSIGNED_SHORT, indexArray );
362 #if defined( __MULTITEXTURE_SUPPORT__ )
363 useMultiTexCoordArray = GL_FALSE;
364 #endif
365 vertexCount = 0;
366 indexCount = 0;
367 ptrVertexAttribArray = vertexattribs;
368 ptrVertexAttribArrayMark = ptrVertexAttribArray;
369 ptrIndexArray = indexArray;
370 useTexCoordArray = GL_FALSE;
372 void nanoGL_Flush( )
374 FlushOnStateChange( );
376 void nanoGL_Reset( )
378 ResetNanoState( );
380 void glBegin( GLenum mode )
382 wrapperPrimitiveMode = mode;
383 vertexMark = vertexCount;
384 ptrVertexAttribArrayMark = ptrVertexAttribArray;
385 indexbase = indexCount;
388 void glEnd( void )
390 vertexCount += ( (unsigned char *)ptrVertexAttribArray - (unsigned char *)ptrVertexAttribArrayMark ) / sizeof( VertexAttrib );
391 if ( vertexCount < 3 )
393 return;
395 switch ( wrapperPrimitiveMode )
397 case GL_QUADS:
399 *ptrIndexArray++ = indexCount;
400 *ptrIndexArray++ = indexCount + 1;
401 *ptrIndexArray++ = indexCount + 2;
402 *ptrIndexArray++ = indexCount;
403 *ptrIndexArray++ = indexCount + 2;
404 *ptrIndexArray++ = indexCount + 3;
405 indexCount += 4;
406 vertexCount += 2;
408 break;
409 case GL_TRIANGLES:
411 int vcount = ( vertexCount - vertexMark ) / 3;
412 for ( int count = 0; count < vcount; count++ )
414 *ptrIndexArray++ = indexCount;
415 *ptrIndexArray++ = indexCount + 1;
416 *ptrIndexArray++ = indexCount + 2;
417 indexCount += 3;
420 break;
421 case GL_TRIANGLE_STRIP:
423 *ptrIndexArray++ = indexCount;
424 *ptrIndexArray++ = indexCount + 1;
425 *ptrIndexArray++ = indexCount + 2;
426 indexCount += 3;
427 int vcount = ( ( vertexCount - vertexMark ) - 3 );
428 if ( vcount && ( (long)ptrIndexArray & 0x02 ) )
430 *ptrIndexArray++ = indexCount - 1; // 2
431 *ptrIndexArray++ = indexCount - 2; // 1
432 *ptrIndexArray++ = indexCount; // 3
433 indexCount++;
434 vcount -= 1;
435 int odd = vcount & 1;
436 vcount /= 2;
437 unsigned int *longptr = (unsigned int *)ptrIndexArray;
439 for ( int count = 0; count < vcount; count++ )
441 *( longptr++ ) = ( indexCount - 2 ) | ( ( indexCount - 1 ) << 16 );
442 *( longptr++ ) = ( indexCount ) | ( ( indexCount ) << 16 );
443 *( longptr++ ) = ( indexCount - 1 ) | ( ( indexCount + 1 ) << 16 );
444 indexCount += 2;
446 ptrIndexArray = (unsigned short *)( longptr );
447 if ( odd )
449 *ptrIndexArray++ = indexCount - 2; // 2
450 *ptrIndexArray++ = indexCount - 1; // 1
451 *ptrIndexArray++ = indexCount; // 3
452 indexCount++;
455 else
457 //already aligned
458 int odd = vcount & 1;
459 vcount /= 2;
460 unsigned int *longptr = (unsigned int *)ptrIndexArray;
462 for ( int count = 0; count < vcount; count++ )
464 *( longptr++ ) = ( indexCount - 1 ) | ( ( indexCount - 2 ) << 16 );
465 *( longptr++ ) = ( indexCount ) | ( ( indexCount - 1 ) << 16 );
466 *( longptr++ ) = ( indexCount ) | ( ( indexCount + 1 ) << 16 );
467 indexCount += 2;
469 ptrIndexArray = (unsigned short *)( longptr );
470 if ( odd )
473 *ptrIndexArray++ = indexCount - 1; // 2
474 *ptrIndexArray++ = indexCount - 2; // 1
475 *ptrIndexArray++ = indexCount; // 3
476 indexCount++;
479 vertexCount += ( vertexCount - vertexMark - 3 ) * 2;
481 break;
482 case GL_POLYGON:
483 case GL_TRIANGLE_FAN:
485 *ptrIndexArray++ = indexCount++;
486 *ptrIndexArray++ = indexCount++;
487 *ptrIndexArray++ = indexCount++;
488 int vcount = ( ( vertexCount - vertexMark ) - 3 );
489 for ( int count = 0; count < vcount; count++ )
491 *ptrIndexArray++ = indexbase;
492 *ptrIndexArray++ = indexCount - 1;
493 *ptrIndexArray++ = indexCount++;
494 vertexCount += 2;
497 break;
499 default:
500 break;
502 if ( ptrVertexAttribArray - vertexattribs > 20000 * sizeof( VertexAttrib ) ||
503 ptrIndexArray - indexArray > 15000 * sizeof( GLushort ) )
504 FlushOnStateChange( );
507 void glEnable( GLenum cap )
509 GLboolean statechanged = GL_FALSE;
510 switch ( cap )
512 case GL_ALPHA_TEST:
514 if ( !nanoglState.alpha_test )
516 nanoglState.alpha_test = GL_TRUE;
517 statechanged = GL_TRUE;
519 break;
521 case GL_BLEND:
523 if ( !nanoglState.blend )
525 nanoglState.blend = GL_TRUE;
526 statechanged = GL_TRUE;
528 break;
530 //case GL_CLIP_PLANEi
531 case GL_COLOR_LOGIC_OP:
533 if ( !nanoglState.color_logic_op )
535 nanoglState.color_logic_op = GL_TRUE;
536 statechanged = GL_TRUE;
538 break;
540 case GL_COLOR_MATERIAL:
542 if ( !nanoglState.color_material )
544 nanoglState.color_material = GL_TRUE;
545 statechanged = GL_TRUE;
547 break;
549 case GL_CULL_FACE:
551 if ( !nanoglState.cull_face )
553 nanoglState.cull_face = GL_TRUE;
554 statechanged = GL_TRUE;
556 break;
558 case GL_DEPTH_TEST:
560 if ( !nanoglState.depth_test )
562 nanoglState.depth_test = GL_TRUE;
563 statechanged = GL_TRUE;
565 break;
567 case GL_DITHER:
569 if ( !nanoglState.dither )
571 nanoglState.dither = GL_TRUE;
572 statechanged = GL_TRUE;
574 break;
576 case GL_FOG:
577 //case GL_LIGHTi
579 if ( !nanoglState.fog )
581 nanoglState.fog = GL_TRUE;
582 statechanged = GL_TRUE;
584 break;
586 case GL_LIGHTING:
588 if ( !nanoglState.lighting )
590 nanoglState.lighting = GL_TRUE;
591 statechanged = GL_TRUE;
593 break;
595 case GL_LINE_SMOOTH:
597 if ( !nanoglState.line_smooth )
599 nanoglState.line_smooth = GL_TRUE;
600 statechanged = GL_TRUE;
602 break;
604 /* case GL_MATRIX_PALETTE_OES:
606 if (!nanoglState.matrix_palette_oes)
608 nanoglState.matrix_palette_oes = GL_TRUE;
609 statechanged = GL_TRUE;
611 break;
612 }*/
613 case GL_MULTISAMPLE:
615 if ( !nanoglState.multisample )
617 nanoglState.multisample = GL_TRUE;
618 statechanged = GL_TRUE;
620 break;
622 case GL_NORMALIZE:
624 if ( !nanoglState.normalize )
626 nanoglState.normalize = GL_TRUE;
627 statechanged = GL_TRUE;
629 break;
631 /* case GL_POINT_SPRITE_OES:
633 if (!nanoglState.point_sprite_oes)
635 nanoglState.point_sprite_oes = GL_TRUE;
636 statechanged = GL_TRUE;
638 break;
639 }*/
640 case GL_POLYGON_OFFSET_FILL:
642 if ( !nanoglState.polygon_offset_fill )
644 nanoglState.polygon_offset_fill = GL_TRUE;
645 statechanged = GL_TRUE;
647 break;
649 case GL_RESCALE_NORMAL:
651 if ( !nanoglState.rescale_normal )
653 nanoglState.rescale_normal = GL_TRUE;
654 statechanged = GL_TRUE;
656 break;
658 case GL_SAMPLE_ALPHA_TO_COVERAGE:
660 if ( !nanoglState.sample_alpha_to_coverage )
662 nanoglState.sample_alpha_to_coverage = GL_TRUE;
663 statechanged = GL_TRUE;
665 break;
667 case GL_SAMPLE_ALPHA_TO_ONE:
669 if ( !nanoglState.sample_alpha_to_one )
671 nanoglState.sample_alpha_to_one = GL_TRUE;
672 statechanged = GL_TRUE;
674 break;
676 case GL_SAMPLE_COVERAGE:
678 if ( !nanoglState.sample_coverage )
680 nanoglState.sample_coverage = GL_TRUE;
681 statechanged = GL_TRUE;
683 break;
685 case GL_SCISSOR_TEST:
687 if ( !nanoglState.scissor_test )
689 nanoglState.scissor_test = GL_TRUE;
690 statechanged = GL_TRUE;
692 break;
694 case GL_STENCIL_TEST:
696 return;
697 /* if (!nanoglState.stencil_test)
699 nanoglState.stencil_test = GL_TRUE;
700 statechanged = GL_TRUE;
701 }*/
702 break;
704 case GL_TEXTURE_2D:
706 if ( !activetmuState->texture_2d.value )
708 FlushOnStateChange( );
709 glEsImpl->glEnable( cap );
710 activetmuState->texture_2d.value = GL_TRUE;
711 return;
713 break;
715 default:
716 break;
719 if ( statechanged )
721 FlushOnStateChange( );
722 glEsImpl->glEnable( cap );
726 void glDisable( GLenum cap )
728 GLboolean statechanged = GL_FALSE;
729 switch ( cap )
731 case GL_ALPHA_TEST:
733 if ( nanoglState.alpha_test )
735 nanoglState.alpha_test = GL_FALSE;
736 statechanged = GL_TRUE;
738 break;
740 case GL_BLEND:
742 if ( nanoglState.blend )
744 nanoglState.blend = GL_FALSE;
745 statechanged = GL_TRUE;
747 break;
749 //case GL_CLIP_PLANEi
750 case GL_COLOR_LOGIC_OP:
752 if ( nanoglState.color_logic_op )
754 nanoglState.color_logic_op = GL_FALSE;
755 statechanged = GL_TRUE;
757 break;
759 case GL_COLOR_MATERIAL:
761 if ( nanoglState.color_material )
763 nanoglState.color_material = GL_FALSE;
764 statechanged = GL_TRUE;
766 break;
768 case GL_CULL_FACE:
770 if ( nanoglState.cull_face )
772 nanoglState.cull_face = GL_FALSE;
773 statechanged = GL_TRUE;
775 break;
777 case GL_DEPTH_TEST:
779 if ( nanoglState.depth_test )
781 nanoglState.depth_test = GL_FALSE;
782 statechanged = GL_TRUE;
784 break;
786 case GL_DITHER:
788 if ( nanoglState.dither )
790 nanoglState.dither = GL_FALSE;
791 statechanged = GL_TRUE;
793 break;
795 case GL_FOG:
796 //case GL_LIGHTi
798 if ( nanoglState.fog )
800 nanoglState.fog = GL_FALSE;
801 statechanged = GL_TRUE;
803 break;
805 case GL_LIGHTING:
807 if ( nanoglState.lighting )
809 nanoglState.lighting = GL_FALSE;
810 statechanged = GL_TRUE;
812 break;
814 case GL_LINE_SMOOTH:
816 if ( nanoglState.line_smooth )
818 nanoglState.line_smooth = GL_FALSE;
819 statechanged = GL_TRUE;
821 break;
823 /* case GL_MATRIX_PALETTE_OES:
825 if (nanoglState.matrix_palette_oes)
827 nanoglState.matrix_palette_oes = GL_FALSE;
828 statechanged = GL_TRUE;
830 break;
831 }*/
832 case GL_MULTISAMPLE:
834 if ( nanoglState.multisample )
836 nanoglState.multisample = GL_FALSE;
837 statechanged = GL_TRUE;
839 break;
841 case GL_NORMALIZE:
843 if ( nanoglState.normalize )
845 nanoglState.normalize = GL_FALSE;
846 statechanged = GL_TRUE;
848 break;
850 /* case GL_POINT_SPRITE_OES:
852 if (nanoglState.point_sprite_oes)
854 nanoglState.point_sprite_oes = GL_FALSE;
855 statechanged = GL_TRUE;
857 break;
858 }*/
859 case GL_POLYGON_OFFSET_FILL:
861 if ( nanoglState.polygon_offset_fill )
863 nanoglState.polygon_offset_fill = GL_FALSE;
864 statechanged = GL_TRUE;
866 break;
868 case GL_RESCALE_NORMAL:
870 if ( nanoglState.rescale_normal )
872 nanoglState.rescale_normal = GL_FALSE;
873 statechanged = GL_TRUE;
875 break;
877 case GL_SAMPLE_ALPHA_TO_COVERAGE:
879 if ( nanoglState.sample_alpha_to_coverage )
881 nanoglState.sample_alpha_to_coverage = GL_FALSE;
882 statechanged = GL_TRUE;
884 break;
886 case GL_SAMPLE_ALPHA_TO_ONE:
888 if ( nanoglState.sample_alpha_to_one )
890 nanoglState.sample_alpha_to_one = GL_FALSE;
891 statechanged = GL_TRUE;
893 break;
895 case GL_SAMPLE_COVERAGE:
897 if ( nanoglState.sample_coverage )
899 nanoglState.sample_coverage = GL_FALSE;
900 statechanged = GL_TRUE;
902 break;
904 case GL_SCISSOR_TEST:
906 if ( nanoglState.scissor_test )
908 nanoglState.scissor_test = GL_FALSE;
909 statechanged = GL_TRUE;
911 break;
913 case GL_STENCIL_TEST:
915 return;
916 /* if (nanoglState.stencil_test)
918 nanoglState.stencil_test = GL_FALSE;
919 statechanged = GL_TRUE;
920 }*/
921 break;
923 case GL_TEXTURE_2D:
925 if ( activetmuState->texture_2d.value )
927 FlushOnStateChange( );
928 glEsImpl->glDisable( cap );
929 activetmuState->texture_2d.value = GL_FALSE;
930 return;
932 break;
934 default:
935 break;
938 if ( statechanged )
940 FlushOnStateChange( );
941 glEsImpl->glDisable( cap );
945 void glVertex2f( GLfloat x, GLfloat y )
947 glVertex3f( x, y, 0.0f );
950 __FORCEINLINE unsigned int ClampTo255( float value )
952 unsigned int retval = (unsigned int)( value );
953 if ( retval > 255 )
955 retval = 255;
957 return retval;
960 void glColor3f( GLfloat red, GLfloat green, GLfloat blue )
962 currentVertexAttrib.red = (unsigned char)ClampTo255( red * 255.0f );
963 currentVertexAttrib.green = (unsigned char)ClampTo255( green * 255.0f );
964 currentVertexAttrib.blue = (unsigned char)ClampTo255( blue * 255.0f );
965 currentVertexAttrib.alpha = 255;
968 void glTexCoord2fv( const GLfloat *v )
970 memcpy( &currentVertexAttrib.s, v, 2 * sizeof( float ) );
973 void glTexCoord2f( GLfloat s, GLfloat t )
975 currentVertexAttrib.s = s;
976 currentVertexAttrib.t = t;
979 void glViewport( GLint x, GLint y, GLsizei width, GLsizei height )
981 FlushOnStateChange( );
982 glEsImpl->glViewport( x, y, width, height );
985 void glLoadIdentity( void )
987 FlushOnStateChange( );
988 glEsImpl->glLoadIdentity( );
991 void glColor4f( GLfloat red, GLfloat green, GLfloat blue, GLfloat alpha )
993 currentVertexAttrib.red = (unsigned char)ClampTo255( red * 255.0f );
994 currentVertexAttrib.green = (unsigned char)ClampTo255( green * 255.0f );
995 currentVertexAttrib.blue = (unsigned char)ClampTo255( blue * 255.0f );
996 currentVertexAttrib.alpha = (unsigned char)ClampTo255( alpha * 255.0f );
999 void glOrtho( GLfloat left, GLfloat right, GLfloat bottom, GLfloat top, GLfloat zNear, GLfloat zFar )
1001 FlushOnStateChange( );
1002 #ifdef USE_CORE_PROFILE
1003 glEsImpl->glOrtho( left, right, bottom, top, zNear, zFar );
1004 #else
1005 glEsImpl->glOrthof( left, right, bottom, top, zNear, zFar );
1006 #endif
1009 void glMatrixMode( GLenum mode )
1011 if ( nanoglState.matrixmode == mode )
1013 return;
1015 nanoglState.matrixmode = mode;
1016 FlushOnStateChange( );
1017 glEsImpl->glMatrixMode( mode );
1020 void glTexParameterf( GLenum target, GLenum pname, GLfloat param )
1022 if ( pname == GL_TEXTURE_BORDER_COLOR )
1024 return; // not supported by opengl es
1026 if ( ( pname == GL_TEXTURE_WRAP_S ||
1027 pname == GL_TEXTURE_WRAP_T ) &&
1028 param == GL_CLAMP )
1030 param = 0x812F;
1033 FlushOnStateChange( );
1034 glEsImpl->glTexParameterf( target, pname, param );
1037 void glTexParameterfv( GLenum target, GLenum pname, const GLfloat *params )
1039 glTexParameterf( target, pname, params[0] );
1042 void glTexImage2D( GLenum target, GLint level, GLint internalformat, GLsizei width, GLsizei height, GLint border, GLenum format, GLenum type, const GLvoid *pixels )
1044 FlushOnStateChange( );
1045 internalformat = format;
1046 glEsImpl->glTexImage2D( target, level, internalformat, width, height, border, format, type, pixels );
1049 void glDrawBuffer( GLenum /*mode*/ )
1053 void glTranslatef( GLfloat x, GLfloat y, GLfloat z )
1055 FlushOnStateChange( );
1056 glEsImpl->glTranslatef( x, y, z );
1059 void glRotatef( GLfloat angle, GLfloat x, GLfloat y, GLfloat z )
1061 FlushOnStateChange( );
1062 glEsImpl->glRotatef( angle, x, y, z );
1065 void glScalef( GLfloat x, GLfloat y, GLfloat z )
1067 FlushOnStateChange( );
1068 glEsImpl->glScalef( x, y, z );
1071 void glDepthRange( GLclampf zNear, GLclampf zFar )
1073 if ( ( nanoglState.depth_range_near == zNear ) && ( nanoglState.depth_range_far == zFar ) )
1075 return;
1077 else
1079 nanoglState.depth_range_near = zNear;
1080 nanoglState.depth_range_far = zFar;
1082 FlushOnStateChange( );
1083 #ifdef USE_CORE_PROFILE
1084 glEsImpl->glDepthRange( zNear, zFar );
1085 #else
1086 glEsImpl->glDepthRangef( zNear, zFar );
1087 #endif
1090 void glDepthFunc( GLenum func )
1092 if ( nanoglState.depth_func == func )
1094 return;
1096 else
1098 nanoglState.depth_func = func;
1100 FlushOnStateChange( );
1101 glEsImpl->glDepthFunc( func );
1104 void glFinish( void )
1106 FlushOnStateChange( );
1107 glEsImpl->glFinish( );
1110 void glGetFloatv( GLenum pname, GLfloat *params )
1112 FlushOnStateChange( );
1113 glEsImpl->glGetFloatv( pname, params );
1116 void glCullFace( GLenum mode )
1118 if ( nanoglState.cullface == mode )
1120 return;
1122 else
1124 nanoglState.cullface = mode;
1126 FlushOnStateChange( );
1127 glEsImpl->glCullFace( mode );
1130 void glFrustum( GLfloat left, GLfloat right, GLfloat bottom, GLfloat top, GLfloat zNear, GLfloat zFar )
1132 FlushOnStateChange( );
1133 glEsImpl->glFrustumf( left, right, bottom, top, zNear, zFar );
1136 void glClear( GLbitfield mask )
1138 FlushOnStateChange( );
1139 glEsImpl->glClear( mask );
1142 void glVertex3f( GLfloat x, GLfloat y, GLfloat z )
1144 GLfloat *vert = (GLfloat *)ptrVertexAttribArray++;
1145 *vert++ = x;
1146 *vert++ = y;
1147 *vert++ = z;
1148 #if defined( __MULTITEXTURE_SUPPORT__ )
1149 memcpy( vert, &currentVertexAttrib.red, 5 * sizeof( GLfloat ) );
1150 #else
1151 memcpy( vert + 1, &currentVertexAttrib.red, 3 * sizeof( GLfloat ) );
1152 #endif
1155 void glColor4fv( const GLfloat *v )
1157 currentVertexAttrib.red = (unsigned char)ClampTo255( v[0] * 255.0f );
1158 currentVertexAttrib.green = (unsigned char)ClampTo255( v[1] * 255.0f );
1159 currentVertexAttrib.blue = (unsigned char)ClampTo255( v[2] * 255.0f );
1160 currentVertexAttrib.alpha = (unsigned char)ClampTo255( v[3] * 255.0f );
1163 void glColor3ubv( const GLubyte *v )
1165 currentVertexAttrib.red = v[0];
1166 currentVertexAttrib.green = v[1];
1167 currentVertexAttrib.blue = v[2];
1168 currentVertexAttrib.alpha = 255;
1171 void glColor4ubv( const GLubyte *v )
1173 //*((unsigned int*)(&currentVertexAttrib.red)) = *((unsigned int*)(v));
1174 currentVertexAttrib.red = v[0];
1175 currentVertexAttrib.green = v[1];
1176 currentVertexAttrib.blue = v[2];
1177 currentVertexAttrib.alpha = v[3];
1180 void glColor3fv( const GLfloat *v )
1182 currentVertexAttrib.red = (unsigned char)ClampTo255( v[0] * 255.0f );
1183 currentVertexAttrib.green = (unsigned char)ClampTo255( v[1] * 255.0f );
1184 currentVertexAttrib.blue = (unsigned char)ClampTo255( v[2] * 255.0f );
1185 currentVertexAttrib.alpha = 255;
1188 //-- nicknekit: xash3d funcs --
1190 void glColor4ub( GLubyte red, GLubyte green, GLubyte blue, GLubyte alpha )
1192 currentVertexAttrib.red = red;
1193 currentVertexAttrib.green = green;
1194 currentVertexAttrib.blue = blue;
1195 currentVertexAttrib.alpha = alpha;
1198 void glColor3ub( GLubyte red, GLubyte green, GLubyte blue )
1200 currentVertexAttrib.red = red;
1201 currentVertexAttrib.green = green;
1202 currentVertexAttrib.blue = blue;
1203 currentVertexAttrib.alpha = 255;
1206 void glNormal3fv( const GLfloat *v )
1208 FlushOnStateChange( );
1209 glEsImpl->glNormal3f( v[0], v[1], v[2] );
1212 void glCopyTexImage2D( GLenum target, GLint level, GLenum internalformat, GLint x, GLint y, GLsizei width, GLsizei height, GLint border )
1214 FlushOnStateChange( );
1215 glEsImpl->glCopyTexImage2D( target, level, internalformat, x, y, width, height, border );
1218 void glTexImage1D( GLenum target, GLint level, GLint internalformat, GLsizei width, GLint border, GLenum format, GLenum type, const GLvoid *pixels )
1220 glTexImage2D( GL_TEXTURE_2D, level, internalformat, width, 1, border, format, type, pixels );
1223 void glTexImage3D( GLenum target, GLint level, GLint internalformat, GLsizei width, GLsizei height, GLsizei depth, GLint border, GLenum format, GLenum type, const GLvoid *pixels )
1225 glTexImage2D( GL_TEXTURE_2D, level, internalformat, width, height, border, format, type, pixels );
1228 void glTexSubImage1D( GLenum target, GLint level, GLint xoffset, GLsizei width, GLenum format, GLenum type, const GLvoid *pixels )
1230 glTexSubImage2D( target, level, xoffset, 0, width, 1, format, type, pixels );
1233 void glTexSubImage3D( GLenum target, GLint level,
1234 GLint xoffset, GLint yoffset,
1235 GLint zoffset, GLsizei width,
1236 GLsizei height, GLsizei depth,
1237 GLenum format,
1238 GLenum type, const GLvoid *pixels )
1240 glTexSubImage2D( target, level, xoffset, yoffset, width, height, format, type, pixels );
1243 GLboolean glIsTexture( GLuint texture )
1245 FlushOnStateChange( );
1246 return glEsImpl->glIsTexture( texture );
1249 void glTexGeni( GLenum coord, GLenum pname, GLint param )
1251 //for mirrors? not needed for original hl?
1254 void glTexGenfv( GLenum coord, GLenum pname, const GLfloat *params )
1256 //for mirrors? not needed for original hl?
1259 //-- --//
1261 void glHint( GLenum target, GLenum mode )
1263 FlushOnStateChange( );
1264 glEsImpl->glHint( target, mode );
1267 void glBlendFunc( GLenum sfactor, GLenum dfactor )
1269 if ( ( nanoglState.sfactor == sfactor ) && ( nanoglState.dfactor == dfactor ) )
1271 return;
1273 nanoglState.sfactor = sfactor;
1274 nanoglState.dfactor = dfactor;
1275 FlushOnStateChange( );
1276 glEsImpl->glBlendFunc( sfactor, dfactor );
1279 void glPopMatrix( void )
1281 FlushOnStateChange( );
1282 glEsImpl->glPopMatrix( );
1285 void glShadeModel( GLenum mode )
1287 if ( nanoglState.shademodel == mode )
1289 return;
1291 nanoglState.shademodel = mode;
1292 FlushOnStateChange( );
1293 glEsImpl->glShadeModel( mode );
1296 void glPushMatrix( void )
1298 FlushOnStateChange( );
1299 glEsImpl->glPushMatrix( );
1302 void glTexEnvf( GLenum target, GLenum pname, GLfloat param )
1304 if ( target == GL_TEXTURE_ENV )
1306 if ( pname == GL_TEXTURE_ENV_MODE )
1308 if ( param == activetmuState->texture_env_mode.value )
1310 return;
1312 else
1314 FlushOnStateChange( );
1315 glEsImpl->glTexEnvf( target, pname, param );
1316 activetmuState->texture_env_mode.value = param;
1317 return;
1321 FlushOnStateChange( );
1322 glEsImpl->glTexEnvf( target, pname, param );
1325 void glVertex3fv( const GLfloat *v )
1327 GLfloat *vert = (GLfloat *)ptrVertexAttribArray++;
1328 memcpy( vert, v, 3 * sizeof( GLfloat ) );
1329 #if defined( __MULTITEXTURE_SUPPORT__ )
1330 memcpy( vert + 3, &currentVertexAttrib.red, 5 * sizeof( GLfloat ) );
1331 #else
1332 memcpy( vert + 4, &currentVertexAttrib.red, 3 * sizeof( GLfloat ) );
1333 #endif
1336 void glDepthMask( GLboolean flag )
1338 if ( nanoglState.depthmask == flag )
1340 return;
1342 nanoglState.depthmask = flag;
1343 FlushOnStateChange( );
1344 glEsImpl->glDepthMask( flag );
1347 void glBindTexture( GLenum target, GLuint texture )
1349 if ( activetmuState->boundtexture.value == texture )
1351 return;
1353 FlushOnStateChange( );
1354 activetmuState->boundtexture.value = texture;
1355 glEsImpl->glBindTexture( target, texture );
1358 void glGetIntegerv( GLenum pname, GLint *params )
1360 FlushOnStateChange( );
1361 glEsImpl->glGetIntegerv( pname, params );
1364 GLubyte nano_extensions_string[4096];
1365 const GLubyte *glGetString( GLenum name )
1368 if ( name == GL_EXTENSIONS )
1370 #if defined( __MULTITEXTURE_SUPPORT__ )
1371 sprintf( (char *)nano_extensions_string, "%s %s", glEsImpl->glGetString( name ), "GL_ARB_multitexture EXT_texture_env_add" );
1372 #else
1373 sprintf( (char *)nano_extensions_string, "%s %s", glEsImpl->glGetString( name ), "EXT_texture_env_add" );
1374 #endif
1375 return nano_extensions_string;
1377 return glEsImpl->glGetString( name );
1380 void glAlphaFunc( GLenum func, GLclampf ref )
1382 FlushOnStateChange( );
1383 glEsImpl->glAlphaFunc( func, ref );
1386 void glFlush( void )
1388 FlushOnStateChange( );
1389 glEsImpl->glFlush( );
1392 void glReadPixels( GLint x, GLint y, GLsizei width, GLsizei height, GLenum format, GLenum type, GLvoid *pixels )
1394 if ( format == GL_DEPTH_COMPONENT )
1396 // OpenglEs 1.1 does not support reading depth buffer without an extension
1397 memset( pixels, 0xff, 4 );
1398 return;
1400 FlushOnStateChange( );
1401 glEsImpl->glReadPixels( x, y, width, height, format, type, pixels );
1404 void glReadBuffer( GLenum /*mode*/ )
1408 void glLoadMatrixf( const GLfloat *m )
1410 FlushOnStateChange( );
1411 glEsImpl->glLoadMatrixf( m );
1414 void glTexSubImage2D( GLenum target, GLint level, GLint xoffset, GLint yoffset, GLsizei width, GLsizei height, GLenum format, GLenum type, const GLvoid *pixels )
1416 FlushOnStateChange( );
1417 glEsImpl->glTexSubImage2D( target, level, xoffset, yoffset, width, height, format, type, pixels );
1420 void glClearColor( GLclampf red, GLclampf green, GLclampf blue, GLclampf alpha )
1422 FlushOnStateChange( );
1423 glEsImpl->glClearColor( red, green, blue, alpha );
1426 GLenum glGetError( void )
1428 //FlushOnStateChange();
1429 return GL_NO_ERROR; //glEsImpl->glGetError();
1432 void glActiveTexture( GLenum texture )
1434 if ( activetmu == texture )
1436 return;
1438 if ( delayedttmuchange )
1440 delayedttmuchange = GL_FALSE;
1442 else
1444 delayedttmuchange = GL_TRUE;
1445 delayedtmutarget = texture;
1447 if ( texture == GL_TEXTURE0 )
1449 activetmuState = &tmuState0;
1451 else
1453 activetmuState = &tmuState1;
1455 activetmu = texture;
1458 void glClientActiveTexture( GLenum texture )
1460 clientactivetmu = texture;
1463 void glPolygonMode( GLenum face, GLenum mode )
1467 void glDeleteTextures( GLsizei n, const GLuint *textures )
1469 FlushOnStateChange( );
1470 glEsImpl->glDeleteTextures( n, textures );
1473 void glClearDepth( GLclampf depth )
1475 FlushOnStateChange( );
1476 glEsImpl->glClearDepthf( depth );
1479 void glClipPlane( GLenum plane, const GLdouble *equation )
1481 FlushOnStateChange( );
1482 float array[4];
1483 array[0] = ( GLfloat )( equation[0] );
1484 array[1] = ( GLfloat )( equation[1] );
1485 array[2] = ( GLfloat )( equation[2] );
1486 array[3] = ( GLfloat )( equation[3] );
1487 glEsImpl->glClipPlanef( plane, array );
1490 void glScissor( GLint x, GLint y, GLsizei width, GLsizei height )
1492 FlushOnStateChange( );
1493 glEsImpl->glScissor( x, y, width, height );
1496 void glPointSize( GLfloat size )
1498 FlushOnStateChange( );
1499 glEsImpl->glPointSize( size );
1502 void glArrayElement( GLint i )
1505 void glLineWidth( GLfloat width )
1508 void glCallList( GLuint list )
1511 void glColorMask( GLboolean red, GLboolean green, GLboolean blue, GLboolean alpha )
1514 void glStencilFunc( GLenum func, GLint ref, GLuint mask )
1517 void glStencilOp( GLenum fail, GLenum zfail, GLenum zpass )
1521 struct ptrstate vertex_array;
1522 struct ptrstate color_array;
1523 struct ptrstate texture_coord_array;
1525 void glDrawElements( GLenum mode, GLsizei count, GLenum type, const GLvoid *indices )
1527 // ensure that all primitives specified between glBegin/glEnd pairs
1528 // are rendered first, and that we have correct tmu in use..
1529 FlushOnStateChange( );
1530 // setup correct vertex/color/texcoord pointers
1531 if ( arraysValid ||
1532 tmuState0.vertex_array.changed ||
1533 tmuState0.color_array.changed ||
1534 tmuState0.texture_coord_array.changed || tmuState0.normal_array.changed )
1536 glEsImpl->glClientActiveTexture( GL_TEXTURE0 );
1538 if ( arraysValid || tmuState0.vertex_array.changed )
1540 if ( tmuState0.vertex_array.enabled )
1542 glEsImpl->glEnableClientState( GL_VERTEX_ARRAY );
1544 else
1546 glEsImpl->glDisableClientState( GL_VERTEX_ARRAY );
1548 glEsImpl->glVertexPointer( tmuState0.vertex_array.size,
1549 tmuState0.vertex_array.type,
1550 tmuState0.vertex_array.stride,
1551 tmuState0.vertex_array.ptr );
1552 tmuState0.vertex_array.changed = GL_FALSE;
1554 if ( arraysValid || tmuState0.color_array.changed )
1556 if ( tmuState0.color_array.enabled )
1558 glEsImpl->glEnableClientState( GL_COLOR_ARRAY );
1560 else
1562 glEsImpl->glDisableClientState( GL_COLOR_ARRAY );
1564 glEsImpl->glColorPointer( tmuState0.color_array.size,
1565 tmuState0.color_array.type,
1566 tmuState0.color_array.stride,
1567 tmuState0.color_array.ptr );
1568 tmuState0.color_array.changed = GL_FALSE;
1570 if ( arraysValid || tmuState0.normal_array.changed )
1572 if ( tmuState0.normal_array.enabled )
1574 glEsImpl->glEnableClientState( GL_NORMAL_ARRAY );
1576 else
1578 glEsImpl->glDisableClientState( GL_NORMAL_ARRAY );
1580 glEsImpl->glNormalPointer( tmuState0.normal_array.type,
1581 tmuState0.normal_array.stride,
1582 tmuState0.normal_array.ptr );
1583 tmuState0.normal_array.changed = GL_FALSE;
1585 if ( arraysValid || tmuState0.texture_coord_array.changed )
1587 tmuState0.texture_coord_array.changed = GL_FALSE;
1588 if ( tmuState0.texture_coord_array.enabled )
1590 glEsImpl->glEnableClientState( GL_TEXTURE_COORD_ARRAY );
1592 else
1594 glEsImpl->glDisableClientState( GL_TEXTURE_COORD_ARRAY );
1596 glEsImpl->glTexCoordPointer( tmuState0.texture_coord_array.size,
1597 tmuState0.texture_coord_array.type,
1598 tmuState0.texture_coord_array.stride,
1599 tmuState0.texture_coord_array.ptr );
1602 if ( arraysValid || tmuState1.texture_coord_array.changed )
1604 tmuState1.texture_coord_array.changed = GL_FALSE;
1605 glEsImpl->glClientActiveTexture( GL_TEXTURE1 );
1606 if ( tmuState1.texture_coord_array.enabled )
1608 glEsImpl->glEnableClientState( GL_TEXTURE_COORD_ARRAY );
1610 else
1612 glEsImpl->glDisableClientState( GL_TEXTURE_COORD_ARRAY );
1614 glEsImpl->glTexCoordPointer( tmuState1.texture_coord_array.size,
1615 tmuState1.texture_coord_array.type,
1616 tmuState1.texture_coord_array.stride,
1617 tmuState1.texture_coord_array.ptr );
1620 arraysValid = GL_FALSE;
1621 glEsImpl->glDrawElements( mode, count, type, indices );
1624 void glEnableClientState( GLenum array )
1626 struct nanotmuState *clientstate = NULL;
1627 if ( clientactivetmu == GL_TEXTURE0 )
1629 clientstate = &tmuState0;
1631 else if ( clientactivetmu == GL_TEXTURE1 )
1633 clientstate = &tmuState1;
1635 else
1637 return;
1639 switch ( array )
1641 case GL_VERTEX_ARRAY:
1642 if ( clientstate->vertex_array.enabled )
1644 return;
1646 clientstate->vertex_array.enabled = GL_TRUE;
1647 clientstate->vertex_array.changed = GL_TRUE;
1648 break;
1649 case GL_COLOR_ARRAY:
1650 if ( clientstate->color_array.enabled )
1652 return;
1654 clientstate->color_array.enabled = GL_TRUE;
1655 clientstate->color_array.changed = GL_TRUE;
1657 break;
1658 case GL_NORMAL_ARRAY:
1659 if ( clientstate->normal_array.enabled )
1661 return;
1663 clientstate->normal_array.enabled = GL_TRUE;
1664 clientstate->normal_array.changed = GL_TRUE;
1666 break;
1667 case GL_TEXTURE_COORD_ARRAY:
1668 if ( clientstate->texture_coord_array.enabled )
1670 return;
1672 clientstate->texture_coord_array.enabled = GL_TRUE;
1673 clientstate->texture_coord_array.changed = GL_TRUE;
1674 break;
1675 default:
1676 break;
1679 void glDisableClientState( GLenum array )
1681 struct nanotmuState *clientstate = NULL;
1682 if ( clientactivetmu == GL_TEXTURE0 )
1684 clientstate = &tmuState0;
1686 else if ( clientactivetmu == GL_TEXTURE1 )
1688 clientstate = &tmuState1;
1690 else
1692 return;
1694 switch ( array )
1696 case GL_VERTEX_ARRAY:
1697 if ( !clientstate->vertex_array.enabled )
1699 return;
1701 clientstate->vertex_array.enabled = GL_FALSE;
1702 clientstate->vertex_array.changed = GL_TRUE;
1703 break;
1704 case GL_COLOR_ARRAY:
1705 if ( !clientstate->color_array.enabled )
1707 return;
1709 clientstate->color_array.enabled = GL_FALSE;
1710 clientstate->color_array.changed = GL_TRUE;
1712 break;
1713 case GL_NORMAL_ARRAY:
1714 if ( !clientstate->normal_array.enabled )
1716 return;
1718 clientstate->normal_array.enabled = GL_FALSE;
1719 clientstate->normal_array.changed = GL_TRUE;
1721 break;
1722 case GL_TEXTURE_COORD_ARRAY:
1723 if ( !clientstate->texture_coord_array.enabled )
1725 return;
1727 clientstate->texture_coord_array.enabled = GL_FALSE;
1728 clientstate->texture_coord_array.changed = GL_TRUE;
1729 break;
1730 default:
1731 break;
1734 void glVertexPointer( GLint size, GLenum type, GLsizei stride, const GLvoid *pointer )
1736 if ( tmuState0.vertex_array.size == size &&
1737 tmuState0.vertex_array.stride == stride &&
1738 tmuState0.vertex_array.type == type &&
1739 tmuState0.vertex_array.ptr == pointer )
1741 return;
1743 tmuState0.vertex_array.size = size;
1744 tmuState0.vertex_array.stride = stride;
1745 tmuState0.vertex_array.type = type;
1746 tmuState0.vertex_array.ptr = (GLvoid *)pointer;
1747 tmuState0.vertex_array.changed = GL_TRUE;
1749 void glTexCoordPointer( GLint size, GLenum type, GLsizei stride, const GLvoid *pointer )
1751 struct nanotmuState *clientstate = NULL;
1752 if ( clientactivetmu == GL_TEXTURE0 )
1754 clientstate = &tmuState0;
1756 else if ( clientactivetmu == GL_TEXTURE1 )
1758 clientstate = &tmuState1;
1760 if ( clientstate->texture_coord_array.size == size &&
1761 clientstate->texture_coord_array.stride == stride &&
1762 clientstate->texture_coord_array.type == type &&
1763 clientstate->texture_coord_array.ptr == pointer )
1765 return;
1767 clientstate->texture_coord_array.size = size;
1768 clientstate->texture_coord_array.stride = stride;
1769 clientstate->texture_coord_array.type = type;
1770 clientstate->texture_coord_array.ptr = (GLvoid *)pointer;
1771 clientstate->texture_coord_array.changed = GL_TRUE;
1773 void glColorPointer( GLint size, GLenum type, GLsizei stride, const GLvoid *pointer )
1775 if ( tmuState0.color_array.size == size &&
1776 tmuState0.color_array.stride == stride &&
1777 tmuState0.color_array.type == type &&
1778 tmuState0.color_array.ptr == pointer )
1780 return;
1782 tmuState0.color_array.size = size;
1783 tmuState0.color_array.stride = stride;
1784 tmuState0.color_array.type = type;
1785 tmuState0.color_array.ptr = (GLvoid *)pointer;
1786 tmuState0.color_array.changed = GL_TRUE;
1789 void glNormalPointer( GLenum type, GLsizei stride, const GLvoid *pointer )
1791 int size = 0;
1792 if ( tmuState0.normal_array.size == size &&
1793 tmuState0.normal_array.stride == stride &&
1794 tmuState0.normal_array.type == type &&
1795 tmuState0.normal_array.ptr == pointer )
1797 return;
1799 tmuState0.normal_array.size = size;
1800 tmuState0.normal_array.stride = stride;
1801 tmuState0.normal_array.type = type;
1802 tmuState0.normal_array.ptr = (GLvoid *)pointer;
1803 tmuState0.normal_array.changed = GL_TRUE;
1805 void glPolygonOffset( GLfloat factor, GLfloat units )
1807 FlushOnStateChange( );
1808 glEsImpl->glPolygonOffset( factor, units );
1810 void glStencilMask( GLuint mask )
1813 void glClearStencil( GLint s )
1817 #if defined( __MULTITEXTURE_SUPPORT__ )
1819 extern "C" void glMultiTexCoord2fARB( GLenum target, GLfloat s, GLfloat t );
1821 void glMultiTexCoord2fARB( GLenum target, GLfloat s, GLfloat t )
1823 if ( target == GL_TEXTURE0 )
1825 glTexCoord2f( s, t );
1827 else
1829 currentVertexAttrib.s_multi = s;
1830 currentVertexAttrib.t_multi = t;
1833 #endif
1835 /* Vladimir */
1836 /*void glDrawArrays( GLenum mode, int first, int count)
1838 FlushOnStateChange();
1839 glEsImpl->glDrawArrays(mode, first , count);
1840 }*/
1841 void glMultMatrixf( const GLfloat *m )
1843 FlushOnStateChange( );
1844 glEsImpl->glMultMatrixf( m );
1847 void glPixelStorei( GLenum pname, GLint param )
1849 FlushOnStateChange( );
1850 glEsImpl->glPixelStorei( pname, param );
1853 void glFogf( GLenum pname, GLfloat param )
1855 FlushOnStateChange( );
1856 glEsImpl->glFogf( pname, param );
1859 void glFogfv( GLenum pname, const GLfloat *params )
1861 FlushOnStateChange( );
1862 glEsImpl->glFogfv( pname, params );
1865 void glGetTexParameteriv( GLenum target, GLenum pname, GLint *params )
1867 FlushOnStateChange( );
1868 glEsImpl->glGetTexParameteriv( target, pname, params );
1871 // This gives: called unimplemented OpenGL ES API (Android)
1872 void glTexParameteri( GLenum target, GLenum pname, GLint param )
1874 if ( pname == GL_TEXTURE_BORDER_COLOR )
1876 return; // not supported by opengl es
1878 if ( ( pname == GL_TEXTURE_WRAP_S ||
1879 pname == GL_TEXTURE_WRAP_T ) &&
1880 param == GL_CLAMP )
1882 param = 0x812F;
1885 FlushOnStateChange( );
1886 glEsImpl->glTexParameteri( target, pname, param );
1889 void glTexParameterx( GLenum target, GLenum pname, GLfixed param )
1891 if ( pname == GL_TEXTURE_BORDER_COLOR )
1893 return; // not supported by opengl es
1895 if ( ( pname == GL_TEXTURE_WRAP_S ||
1896 pname == GL_TEXTURE_WRAP_T ) &&
1897 param == GL_CLAMP )
1899 param = 0x812F;
1901 FlushOnStateChange( );
1902 glEsImpl->glTexParameterx( target, pname, param );
1905 void glGenTextures( GLsizei n, GLuint *textures )
1907 FlushOnStateChange( );
1908 glEsImpl->glGenTextures( n, textures );
1911 void glFrontFace( GLenum mode )
1913 FlushOnStateChange( );
1914 glEsImpl->glFrontFace( mode );
1916 // End Vladimir
1918 void glTexEnvi( GLenum target, GLenum pname, GLint param )
1920 if ( target == GL_TEXTURE_ENV )
1922 if ( pname == GL_TEXTURE_ENV_MODE )
1924 if ( param == activetmuState->texture_env_mode.value )
1926 return;
1928 else
1930 FlushOnStateChange( );
1931 glEsImpl->glTexEnvi( target, pname, param );
1932 activetmuState->texture_env_mode.value = param;
1933 return;
1937 FlushOnStateChange( );
1938 glEsImpl->glTexEnvi( target, pname, param );
1941 #ifdef __MULTITEXTURE_SUPPORT__
1942 void glMultiTexCoord3fARB( GLenum a, GLfloat b, GLfloat c, GLfloat )
1944 return glMultiTexCoord2fARB( a, b, c );
1947 void glMultiTexCoord2f( GLenum, GLfloat, GLfloat )
1950 #endif
1951 void glDrawArrays( GLenum mode, GLint first, GLsizei count )
1953 // ensure that all primitives specified between glBegin/glEnd pairs
1954 // are rendered first, and that we have correct tmu in use..
1955 if ( mode == GL_QUADS )
1956 mode = GL_TRIANGLE_FAN;
1957 FlushOnStateChange( );
1958 // setup correct vertex/color/texcoord pointers
1959 if ( arraysValid ||
1960 tmuState0.vertex_array.changed ||
1961 tmuState0.color_array.changed ||
1962 tmuState0.texture_coord_array.changed || tmuState0.normal_array.changed )
1964 glEsImpl->glClientActiveTexture( GL_TEXTURE0 );
1966 if ( arraysValid || tmuState0.vertex_array.changed )
1968 if ( tmuState0.vertex_array.enabled )
1970 glEsImpl->glEnableClientState( GL_VERTEX_ARRAY );
1972 else
1974 glEsImpl->glDisableClientState( GL_VERTEX_ARRAY );
1976 glEsImpl->glVertexPointer( tmuState0.vertex_array.size,
1977 tmuState0.vertex_array.type,
1978 tmuState0.vertex_array.stride,
1979 tmuState0.vertex_array.ptr );
1980 tmuState0.vertex_array.changed = GL_FALSE;
1982 if ( arraysValid || tmuState0.color_array.changed )
1984 if ( tmuState0.color_array.enabled )
1986 glEsImpl->glEnableClientState( GL_COLOR_ARRAY );
1988 else
1990 glEsImpl->glDisableClientState( GL_COLOR_ARRAY );
1992 glEsImpl->glColorPointer( tmuState0.color_array.size,
1993 tmuState0.color_array.type,
1994 tmuState0.color_array.stride,
1995 tmuState0.color_array.ptr );
1996 tmuState0.color_array.changed = GL_FALSE;
1998 if ( arraysValid || tmuState0.normal_array.changed )
2000 if ( tmuState0.normal_array.enabled )
2002 glEsImpl->glEnableClientState( GL_NORMAL_ARRAY );
2004 else
2006 glEsImpl->glDisableClientState( GL_NORMAL_ARRAY );
2008 glEsImpl->glNormalPointer( tmuState0.normal_array.type,
2009 tmuState0.normal_array.stride,
2010 tmuState0.normal_array.ptr );
2011 tmuState0.normal_array.changed = GL_FALSE;
2013 if ( arraysValid || tmuState0.texture_coord_array.changed )
2015 tmuState0.texture_coord_array.changed = GL_FALSE;
2016 if ( tmuState0.texture_coord_array.enabled )
2018 glEsImpl->glEnableClientState( GL_TEXTURE_COORD_ARRAY );
2020 else
2022 glEsImpl->glDisableClientState( GL_TEXTURE_COORD_ARRAY );
2024 glEsImpl->glTexCoordPointer( tmuState0.texture_coord_array.size,
2025 tmuState0.texture_coord_array.type,
2026 tmuState0.texture_coord_array.stride,
2027 tmuState0.texture_coord_array.ptr );
2030 if ( arraysValid || tmuState1.texture_coord_array.changed )
2032 tmuState1.texture_coord_array.changed = GL_FALSE;
2033 glEsImpl->glClientActiveTexture( GL_TEXTURE1 );
2034 if ( tmuState1.texture_coord_array.enabled )
2036 glEsImpl->glEnableClientState( GL_TEXTURE_COORD_ARRAY );
2038 else
2040 glEsImpl->glDisableClientState( GL_TEXTURE_COORD_ARRAY );
2042 glEsImpl->glTexCoordPointer( tmuState1.texture_coord_array.size,
2043 tmuState1.texture_coord_array.type,
2044 tmuState1.texture_coord_array.stride,
2045 tmuState1.texture_coord_array.ptr );
2048 arraysValid = GL_FALSE;
2049 glEsImpl->glDrawArrays( mode, first, count );
2051 /*void glNormalPointer(GLenum type, GLsizei stride, const void *ptr)
2053 glEsImpl->glNormalPointer( type, stride, ptr );
2054 }*/
2056 void glCopyTexSubImage2D( GLenum target, GLint level, GLint xoffset, GLint yoffset, GLint x, GLint y, GLsizei width, GLsizei height )
2058 FlushOnStateChange( );
2059 glEsImpl->glCopyTexSubImage2D( target, level, xoffset, yoffset, x, y, width, height );
2062 void glGenFramebuffers( GLsizei n, GLuint *framebuffers )
2064 FlushOnStateChange( );
2065 glEsImpl->glGenFramebuffers( n, framebuffers );
2068 void glGenRenderbuffers( GLsizei n, GLuint *renderbuffers )
2070 FlushOnStateChange( );
2071 glEsImpl->glGenRenderbuffers( n, renderbuffers );
2074 void glBindRenderbuffer( GLenum target, GLuint renderbuffer )
2076 FlushOnStateChange( );
2077 glEsImpl->glBindRenderbuffer( target, renderbuffer );
2080 void glBindFramebuffer( GLenum target, GLuint framebuffer )
2082 FlushOnStateChange( );
2083 glEsImpl->glBindFramebuffer( target, framebuffer );
2086 void glFramebufferRenderbuffer( GLenum target, GLenum attachment, GLenum renderbuffertarget, GLuint renderbuffer )
2088 FlushOnStateChange( );
2089 glEsImpl->glFramebufferRenderbuffer( target, attachment, renderbuffertarget, renderbuffer );
2092 void glDeleteFramebuffers( GLsizei n, const GLuint *framebuffers )
2094 FlushOnStateChange( );
2095 glEsImpl->glDeleteFramebuffers( n, framebuffers );
2098 void glDeleteRenderbuffers( GLsizei n, const GLuint *renderbuffers )
2100 FlushOnStateChange( );
2101 glEsImpl->glDeleteRenderbuffers( n, renderbuffers );
2103 void glFramebufferTexture2D( GLenum target, GLenum attachment, GLenum textarget, GLuint texture, GLint level )
2105 FlushOnStateChange( );
2106 glEsImpl->glFramebufferTexture2D( target, attachment, textarget, texture, level );
2109 void glRenderbufferStorage( GLenum target, GLenum internalformat, GLsizei width, GLsizei height )
2111 FlushOnStateChange( );
2112 glEsImpl->glRenderbufferStorage( target, internalformat, width, height );