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.
30 #include "glesinterface.h"
33 #define GL_TEXTURE0_ARB 0x84C0
34 #define GL_TEXTURE1_ARB 0x84C1
40 GLboolean clip_planei
;
41 GLboolean color_logic_op
;
42 GLboolean color_material
;
49 GLboolean line_smooth
;
50 GLboolean matrix_palette_oes
;
51 GLboolean multisample
;
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
;
63 GLboolean stupidglesbug
;
64 GLclampf depth_range_near
;
65 GLclampf depth_range_far
;
74 static struct nanoState nanoglState
;
76 static struct nanoState nanoglInitState
=
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
;
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
},
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
;
180 #if !defined( __WINS__ )
181 //#define __FORCEINLINE __forceinline
182 #define __FORCEINLINE inline
184 #define __FORCEINLINE
187 static GLboolean delayedttmuchange
= GL_FALSE
;
188 static GLenum delayedtmutarget
= GL_TEXTURE0
;
195 #if !defined( __MULTITEXTURE_SUPPORT__ )
205 #if defined( __MULTITEXTURE_SUPPORT__ )
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
};
227 static VertexAttrib currentVertexAttribInit
= {
228 0.0f
, 0.0f
, 0.0f
, 0.0f
, 255, 255, 255, 255, 0.0f
, 0.0f
,
231 static GLushort
*ptrIndexArray
= NULL
;
233 static GLboolean arraysValid
= GL_FALSE
;
235 static GLboolean skipnanogl
;
237 void InitGLStructs( )
239 ptrVertexAttribArray
= vertexattribs
;
240 ptrVertexAttribArrayMark
= ptrVertexAttribArray
;
241 ptrIndexArray
= indexArray
;
243 memcpy( &nanoglState
, &nanoglInitState
, sizeof( struct nanoState
) );
244 memcpy( &tmuState0
, &tmuInitState
, sizeof( struct nanotmuState
) );
245 memcpy( &tmuState1
, &tmuInitState
, sizeof( struct nanotmuState
) );
246 memcpy( ¤tVertexAttrib
, ¤tVertexAttribInit
, sizeof( struct VertexAttrib
) );
248 activetmuState
= &tmuState0
;
249 wrapperPrimitiveMode
= GL_QUADS
;
250 useTexCoordArray
= GL_FALSE
;
251 activetmu
= GL_TEXTURE0
;
252 clientactivetmu
= GL_TEXTURE0
;
253 delayedttmuchange
= GL_FALSE
;
254 delayedtmutarget
= GL_TEXTURE0
;
259 arraysValid
= GL_FALSE
;
262 void ResetNanoState( )
265 if ( tmuState0
.color_array
.enabled
)
267 glEsImpl
->glEnableClientState( GL_COLOR_ARRAY
);
271 glEsImpl
->glDisableClientState( GL_COLOR_ARRAY
);
274 if ( tmuState0
.vertex_array
.enabled
)
276 glEsImpl
->glEnableClientState( GL_VERTEX_ARRAY
);
280 glEsImpl
->glDisableClientState( GL_VERTEX_ARRAY
);
283 if ( tmuState0
.texture_coord_array
.enabled
)
285 glEsImpl
->glEnableClientState( GL_TEXTURE_COORD_ARRAY
);
289 glEsImpl
->glDisableClientState( GL_TEXTURE_COORD_ARRAY
);
292 if ( tmuState0
.normal_array
.enabled
)
294 glEsImpl
->glEnableClientState( GL_NORMAL_ARRAY
);
298 glEsImpl
->glDisableClientState( GL_NORMAL_ARRAY
);
300 glEsImpl
->glVertexPointer( tmuState0
.vertex_array
.size
,
301 tmuState0
.vertex_array
.type
,
302 tmuState0
.vertex_array
.stride
,
303 tmuState0
.vertex_array
.ptr
);
305 glEsImpl
->glTexCoordPointer( tmuState0
.texture_coord_array
.size
,
306 tmuState0
.texture_coord_array
.type
,
307 tmuState0
.texture_coord_array
.stride
,
308 tmuState0
.texture_coord_array
.ptr
);
310 glEsImpl
->glColorPointer( tmuState0
.color_array
.size
,
311 tmuState0
.color_array
.type
,
312 tmuState0
.color_array
.stride
,
313 tmuState0
.color_array
.ptr
);
315 glEsImpl
->glNormalPointer(
316 tmuState0
.normal_array
.type
,
317 tmuState0
.normal_array
.stride
,
318 tmuState0
.normal_array
.ptr
);
320 glEsImpl
->glMatrixMode( nanoglState
.matrixmode
);
322 glEsImpl
->glColor4f( currentVertexAttrib
.red
/255.0f
, currentVertexAttrib
.green
/255.0f
,
323 currentVertexAttrib
.blue
/255.0f
, currentVertexAttrib
.alpha
/255.0f
);
325 glEsImpl
->glBlendFunc( nanoglState
.sfactor
, nanoglState
.dfactor
);
327 //glEsImpl->glBindTexture(GL_TEXTURE_2D, stackTextureState);
329 glEsImpl
->glTexEnvi( GL_TEXTURE_ENV
, GL_TEXTURE_ENV_MODE
, activetmuState
->texture_env_mode
.value
);
331 arraysValid
= GL_FALSE
;
332 skipnanogl
= GL_FALSE
;
335 void FlushOnStateChange( )
339 if ( delayedttmuchange
)
341 delayedttmuchange
= GL_FALSE
;
342 #ifndef USE_CORE_PROFILE
343 glEsImpl
->glActiveTexture( delayedtmutarget
);
352 glEsImpl
->glClientActiveTexture( GL_TEXTURE0
);
353 glEsImpl
->glVertexPointer( 3, GL_FLOAT
, sizeof( VertexAttrib
), &vertexattribs
[0].x
);
354 glEsImpl
->glColorPointer( 4, GL_UNSIGNED_BYTE
, sizeof( VertexAttrib
), &vertexattribs
[0].red
);
355 glEsImpl
->glTexCoordPointer( 2, GL_FLOAT
, sizeof( VertexAttrib
), &vertexattribs
[0].s
);
356 glEsImpl
->glEnableClientState( GL_VERTEX_ARRAY
);
357 glEsImpl
->glEnableClientState( GL_TEXTURE_COORD_ARRAY
);
358 glEsImpl
->glEnableClientState( GL_COLOR_ARRAY
);
359 #if defined( __MULTITEXTURE_SUPPORT__ )
360 glEsImpl
->glClientActiveTexture( GL_TEXTURE1
);
361 glEsImpl
->glTexCoordPointer( 2, GL_FLOAT
, sizeof( VertexAttrib
), &vertexattribs
[0].s_multi
);
362 glEsImpl
->glEnableClientState( GL_TEXTURE_COORD_ARRAY
);
363 glEsImpl
->glClientActiveTexture( GL_TEXTURE0
);
365 arraysValid
= GL_TRUE
;
368 glEsImpl
->glDrawElements( GL_TRIANGLES
, vertexCount
, GL_UNSIGNED_SHORT
, indexArray
);
370 #if defined( __MULTITEXTURE_SUPPORT__ )
371 useMultiTexCoordArray
= GL_FALSE
;
375 ptrVertexAttribArray
= vertexattribs
;
376 ptrVertexAttribArrayMark
= ptrVertexAttribArray
;
377 ptrIndexArray
= indexArray
;
378 useTexCoordArray
= GL_FALSE
;
382 FlushOnStateChange( );
388 void glBegin( GLenum mode
)
390 wrapperPrimitiveMode
= mode
;
391 vertexMark
= vertexCount
;
392 ptrVertexAttribArrayMark
= ptrVertexAttribArray
;
393 indexbase
= indexCount
;
398 vertexCount
+= ( (unsigned char *)ptrVertexAttribArray
- (unsigned char *)ptrVertexAttribArrayMark
) / sizeof( VertexAttrib
);
399 if ( vertexCount
< 3 )
403 switch ( wrapperPrimitiveMode
)
407 *ptrIndexArray
++ = indexCount
;
408 *ptrIndexArray
++ = indexCount
+ 1;
409 *ptrIndexArray
++ = indexCount
+ 2;
410 *ptrIndexArray
++ = indexCount
;
411 *ptrIndexArray
++ = indexCount
+ 2;
412 *ptrIndexArray
++ = indexCount
+ 3;
419 int vcount
= ( vertexCount
- vertexMark
) / 3;
420 for ( int count
= 0; count
< vcount
; count
++ )
422 *ptrIndexArray
++ = indexCount
;
423 *ptrIndexArray
++ = indexCount
+ 1;
424 *ptrIndexArray
++ = indexCount
+ 2;
429 case GL_TRIANGLE_STRIP
:
431 *ptrIndexArray
++ = indexCount
;
432 *ptrIndexArray
++ = indexCount
+ 1;
433 *ptrIndexArray
++ = indexCount
+ 2;
435 int vcount
= ( ( vertexCount
- vertexMark
) - 3 );
436 if ( vcount
&& ( (long)ptrIndexArray
& 0x02 ) )
438 *ptrIndexArray
++ = indexCount
- 1; // 2
439 *ptrIndexArray
++ = indexCount
- 2; // 1
440 *ptrIndexArray
++ = indexCount
; // 3
443 int odd
= vcount
& 1;
445 unsigned int *longptr
= (unsigned int *)ptrIndexArray
;
447 for ( int count
= 0; count
< vcount
; count
++ )
449 *( longptr
++ ) = ( indexCount
- 2 ) | ( ( indexCount
- 1 ) << 16 );
450 *( longptr
++ ) = ( indexCount
) | ( ( indexCount
) << 16 );
451 *( longptr
++ ) = ( indexCount
- 1 ) | ( ( indexCount
+ 1 ) << 16 );
454 ptrIndexArray
= (unsigned short *)( longptr
);
457 *ptrIndexArray
++ = indexCount
- 2; // 2
458 *ptrIndexArray
++ = indexCount
- 1; // 1
459 *ptrIndexArray
++ = indexCount
; // 3
466 int odd
= vcount
& 1;
468 unsigned int *longptr
= (unsigned int *)ptrIndexArray
;
470 for ( int count
= 0; count
< vcount
; count
++ )
472 *( longptr
++ ) = ( indexCount
- 1 ) | ( ( indexCount
- 2 ) << 16 );
473 *( longptr
++ ) = ( indexCount
) | ( ( indexCount
- 1 ) << 16 );
474 *( longptr
++ ) = ( indexCount
) | ( ( indexCount
+ 1 ) << 16 );
477 ptrIndexArray
= (unsigned short *)( longptr
);
481 *ptrIndexArray
++ = indexCount
- 1; // 2
482 *ptrIndexArray
++ = indexCount
- 2; // 1
483 *ptrIndexArray
++ = indexCount
; // 3
487 vertexCount
+= ( vertexCount
- vertexMark
- 3 ) * 2;
491 case GL_TRIANGLE_FAN
:
493 *ptrIndexArray
++ = indexCount
++;
494 *ptrIndexArray
++ = indexCount
++;
495 *ptrIndexArray
++ = indexCount
++;
496 int vcount
= ( ( vertexCount
- vertexMark
) - 3 );
497 for ( int count
= 0; count
< vcount
; count
++ )
499 *ptrIndexArray
++ = indexbase
;
500 *ptrIndexArray
++ = indexCount
- 1;
501 *ptrIndexArray
++ = indexCount
++;
510 if ( ptrVertexAttribArray
- vertexattribs
> 20000 * sizeof( VertexAttrib
) ||
511 ptrIndexArray
- indexArray
> 15000 * sizeof( GLushort
) )
512 FlushOnStateChange( );
515 void glEnable( GLenum cap
)
519 glEsImpl
->glEnable( cap
);
522 GLboolean statechanged
= GL_FALSE
;
527 if ( !nanoglState
.alpha_test
)
529 nanoglState
.alpha_test
= GL_TRUE
;
530 statechanged
= GL_TRUE
;
536 if ( !nanoglState
.blend
)
538 nanoglState
.blend
= GL_TRUE
;
539 statechanged
= GL_TRUE
;
543 //case GL_CLIP_PLANEi
544 case GL_COLOR_LOGIC_OP
:
546 if ( !nanoglState
.color_logic_op
)
548 nanoglState
.color_logic_op
= GL_TRUE
;
549 statechanged
= GL_TRUE
;
553 case GL_COLOR_MATERIAL
:
555 if ( !nanoglState
.color_material
)
557 nanoglState
.color_material
= GL_TRUE
;
558 statechanged
= GL_TRUE
;
564 if ( !nanoglState
.cull_face
)
566 nanoglState
.cull_face
= GL_TRUE
;
567 statechanged
= GL_TRUE
;
573 if ( !nanoglState
.depth_test
)
575 nanoglState
.depth_test
= GL_TRUE
;
576 statechanged
= GL_TRUE
;
582 if ( !nanoglState
.dither
)
584 nanoglState
.dither
= GL_TRUE
;
585 statechanged
= GL_TRUE
;
592 if ( !nanoglState
.fog
)
594 nanoglState
.fog
= GL_TRUE
;
595 statechanged
= GL_TRUE
;
601 if ( !nanoglState
.lighting
)
603 nanoglState
.lighting
= GL_TRUE
;
604 statechanged
= GL_TRUE
;
610 if ( !nanoglState
.line_smooth
)
612 nanoglState
.line_smooth
= GL_TRUE
;
613 statechanged
= GL_TRUE
;
617 /* case GL_MATRIX_PALETTE_OES:
619 if (!nanoglState.matrix_palette_oes)
621 nanoglState.matrix_palette_oes = GL_TRUE;
622 statechanged = GL_TRUE;
628 if ( !nanoglState
.multisample
)
630 nanoglState
.multisample
= GL_TRUE
;
631 statechanged
= GL_TRUE
;
637 if ( !nanoglState
.normalize
)
639 nanoglState
.normalize
= GL_TRUE
;
640 statechanged
= GL_TRUE
;
644 /* case GL_POINT_SPRITE_OES:
646 if (!nanoglState.point_sprite_oes)
648 nanoglState.point_sprite_oes = GL_TRUE;
649 statechanged = GL_TRUE;
653 case GL_POLYGON_OFFSET_FILL
:
655 if ( !nanoglState
.polygon_offset_fill
)
657 nanoglState
.polygon_offset_fill
= GL_TRUE
;
658 statechanged
= GL_TRUE
;
662 case GL_RESCALE_NORMAL
:
664 if ( !nanoglState
.rescale_normal
)
666 nanoglState
.rescale_normal
= GL_TRUE
;
667 statechanged
= GL_TRUE
;
671 case GL_SAMPLE_ALPHA_TO_COVERAGE
:
673 if ( !nanoglState
.sample_alpha_to_coverage
)
675 nanoglState
.sample_alpha_to_coverage
= GL_TRUE
;
676 statechanged
= GL_TRUE
;
680 case GL_SAMPLE_ALPHA_TO_ONE
:
682 if ( !nanoglState
.sample_alpha_to_one
)
684 nanoglState
.sample_alpha_to_one
= GL_TRUE
;
685 statechanged
= GL_TRUE
;
689 case GL_SAMPLE_COVERAGE
:
691 if ( !nanoglState
.sample_coverage
)
693 nanoglState
.sample_coverage
= GL_TRUE
;
694 statechanged
= GL_TRUE
;
698 case GL_SCISSOR_TEST
:
700 if ( !nanoglState
.scissor_test
)
702 nanoglState
.scissor_test
= GL_TRUE
;
703 statechanged
= GL_TRUE
;
707 case GL_STENCIL_TEST
:
710 if (!nanoglState
.stencil_test
)
712 nanoglState
.stencil_test
= GL_TRUE
;
713 statechanged
= GL_TRUE
;
719 if ( !activetmuState
->texture_2d
.value
)
721 FlushOnStateChange( );
722 glEsImpl
->glEnable( cap
);
723 activetmuState
->texture_2d
.value
= GL_TRUE
;
728 #if 0 // todo: implement cubemap texgen
729 case GL_TEXTURE_GEN_S
:
730 case GL_TEXTURE_GEN_T
:
731 case GL_TEXTURE_GEN_R
:
732 case GL_TEXTURE_GEN_Q
:
734 FlushOnStateChange( );
735 nanoglState
.texgen
= true;
745 FlushOnStateChange( );
746 glEsImpl
->glEnable( cap
);
750 void glDisable( GLenum cap
)
754 glEsImpl
->glDisable( cap
);
757 GLboolean statechanged
= GL_FALSE
;
762 if ( nanoglState
.alpha_test
)
764 nanoglState
.alpha_test
= GL_FALSE
;
765 statechanged
= GL_TRUE
;
771 if ( nanoglState
.blend
)
773 nanoglState
.blend
= GL_FALSE
;
774 statechanged
= GL_TRUE
;
778 //case GL_CLIP_PLANEi
779 case GL_COLOR_LOGIC_OP
:
781 if ( nanoglState
.color_logic_op
)
783 nanoglState
.color_logic_op
= GL_FALSE
;
784 statechanged
= GL_TRUE
;
788 case GL_COLOR_MATERIAL
:
790 if ( nanoglState
.color_material
)
792 nanoglState
.color_material
= GL_FALSE
;
793 statechanged
= GL_TRUE
;
799 if ( nanoglState
.cull_face
)
801 nanoglState
.cull_face
= GL_FALSE
;
802 statechanged
= GL_TRUE
;
808 if ( nanoglState
.depth_test
)
810 nanoglState
.depth_test
= GL_FALSE
;
811 statechanged
= GL_TRUE
;
817 if ( nanoglState
.dither
)
819 nanoglState
.dither
= GL_FALSE
;
820 statechanged
= GL_TRUE
;
827 if ( nanoglState
.fog
)
829 nanoglState
.fog
= GL_FALSE
;
830 statechanged
= GL_TRUE
;
836 if ( nanoglState
.lighting
)
838 nanoglState
.lighting
= GL_FALSE
;
839 statechanged
= GL_TRUE
;
845 if ( nanoglState
.line_smooth
)
847 nanoglState
.line_smooth
= GL_FALSE
;
848 statechanged
= GL_TRUE
;
852 /* case GL_MATRIX_PALETTE_OES:
854 if (nanoglState.matrix_palette_oes)
856 nanoglState.matrix_palette_oes = GL_FALSE;
857 statechanged = GL_TRUE;
863 if ( nanoglState
.multisample
)
865 nanoglState
.multisample
= GL_FALSE
;
866 statechanged
= GL_TRUE
;
872 if ( nanoglState
.normalize
)
874 nanoglState
.normalize
= GL_FALSE
;
875 statechanged
= GL_TRUE
;
879 /* case GL_POINT_SPRITE_OES:
881 if (nanoglState.point_sprite_oes)
883 nanoglState.point_sprite_oes = GL_FALSE;
884 statechanged = GL_TRUE;
888 case GL_POLYGON_OFFSET_FILL
:
890 if ( nanoglState
.polygon_offset_fill
)
892 nanoglState
.polygon_offset_fill
= GL_FALSE
;
893 statechanged
= GL_TRUE
;
897 case GL_RESCALE_NORMAL
:
899 if ( nanoglState
.rescale_normal
)
901 nanoglState
.rescale_normal
= GL_FALSE
;
902 statechanged
= GL_TRUE
;
906 case GL_SAMPLE_ALPHA_TO_COVERAGE
:
908 if ( nanoglState
.sample_alpha_to_coverage
)
910 nanoglState
.sample_alpha_to_coverage
= GL_FALSE
;
911 statechanged
= GL_TRUE
;
915 case GL_SAMPLE_ALPHA_TO_ONE
:
917 if ( nanoglState
.sample_alpha_to_one
)
919 nanoglState
.sample_alpha_to_one
= GL_FALSE
;
920 statechanged
= GL_TRUE
;
924 case GL_SAMPLE_COVERAGE
:
926 if ( nanoglState
.sample_coverage
)
928 nanoglState
.sample_coverage
= GL_FALSE
;
929 statechanged
= GL_TRUE
;
933 case GL_SCISSOR_TEST
:
935 if ( nanoglState
.scissor_test
)
937 nanoglState
.scissor_test
= GL_FALSE
;
938 statechanged
= GL_TRUE
;
942 case GL_STENCIL_TEST
:
945 if (nanoglState
.stencil_test
)
947 nanoglState
.stencil_test
= GL_FALSE
;
948 statechanged
= GL_TRUE
;
954 if ( activetmuState
->texture_2d
.value
)
956 FlushOnStateChange( );
957 glEsImpl
->glDisable( cap
);
958 activetmuState
->texture_2d
.value
= GL_FALSE
;
964 case GL_TEXTURE_GEN_S
:
965 case GL_TEXTURE_GEN_T
:
966 case GL_TEXTURE_GEN_R
:
967 case GL_TEXTURE_GEN_Q
:
969 FlushOnStateChange( );
970 nanoglState
.texgen
= false;
980 FlushOnStateChange( );
981 glEsImpl
->glDisable( cap
);
985 void glVertex2f( GLfloat x
, GLfloat y
)
987 glVertex3f( x
, y
, 0.0f
);
990 __FORCEINLINE
unsigned int ClampTo255( float value
)
992 unsigned int retval
= (unsigned int)( value
);
1000 void glColor3f( GLfloat red
, GLfloat green
, GLfloat blue
)
1002 currentVertexAttrib
.red
= (unsigned char)ClampTo255( red
* 255.0f
);
1003 currentVertexAttrib
.green
= (unsigned char)ClampTo255( green
* 255.0f
);
1004 currentVertexAttrib
.blue
= (unsigned char)ClampTo255( blue
* 255.0f
);
1005 currentVertexAttrib
.alpha
= 255;
1008 void glTexCoord2fv( const GLfloat
*v
)
1010 memcpy( ¤tVertexAttrib
.s
, v
, 2 * sizeof( float ) );
1013 void glTexCoord2f( GLfloat s
, GLfloat t
)
1015 currentVertexAttrib
.s
= s
;
1016 currentVertexAttrib
.t
= t
;
1019 void glViewport( GLint x
, GLint y
, GLsizei width
, GLsizei height
)
1021 FlushOnStateChange( );
1022 glEsImpl
->glViewport( x
, y
, width
, height
);
1025 void glLoadIdentity( void )
1027 FlushOnStateChange( );
1028 glEsImpl
->glLoadIdentity( );
1031 void glColor4f( GLfloat red
, GLfloat green
, GLfloat blue
, GLfloat alpha
)
1033 if( nanoglState
.stupidglesbug
)
1035 currentVertexAttrib
.red
= (unsigned char)ClampTo255( ( red
* alpha
) * 255.0f
);
1036 currentVertexAttrib
.green
= (unsigned char)ClampTo255( ( green
* alpha
) * 255.0f
);
1037 currentVertexAttrib
.blue
= (unsigned char)ClampTo255( ( blue
* alpha
) * 255.0f
);
1041 currentVertexAttrib
.red
= (unsigned char)ClampTo255( red
* 255.0f
);
1042 currentVertexAttrib
.green
= (unsigned char)ClampTo255( green
* 255.0f
);
1043 currentVertexAttrib
.blue
= (unsigned char)ClampTo255( blue
* 255.0f
);
1045 currentVertexAttrib
.alpha
= (unsigned char)ClampTo255( alpha
* 255.0f
);
1048 void glOrtho( GLfloat left
, GLfloat right
, GLfloat bottom
, GLfloat top
, GLfloat zNear
, GLfloat zFar
)
1050 FlushOnStateChange( );
1051 #ifdef USE_CORE_PROFILE
1052 glEsImpl
->glOrtho( left
, right
, bottom
, top
, zNear
, zFar
);
1054 glEsImpl
->glOrthof( left
, right
, bottom
, top
, zNear
, zFar
);
1058 void glMatrixMode( GLenum mode
)
1060 if ( nanoglState
.matrixmode
== mode
)
1064 nanoglState
.matrixmode
= mode
;
1065 FlushOnStateChange( );
1066 glEsImpl
->glMatrixMode( mode
);
1069 void glTexParameterf( GLenum target
, GLenum pname
, GLfloat param
)
1071 if ( pname
== GL_TEXTURE_BORDER_COLOR
)
1073 return; // not supported by opengl es
1075 if ( ( pname
== GL_TEXTURE_WRAP_S
||
1076 pname
== GL_TEXTURE_WRAP_T
) &&
1082 FlushOnStateChange( );
1083 glEsImpl
->glTexParameterf( target
, pname
, param
);
1086 void glTexParameterfv( GLenum target
, GLenum pname
, const GLfloat
*params
)
1088 glTexParameterf( target
, pname
, params
[0] );
1091 void glTexImage2D( GLenum target
, GLint level
, GLint internalformat
, GLsizei width
, GLsizei height
, GLint border
, GLenum format
, GLenum type
, const GLvoid
*pixels
)
1093 FlushOnStateChange( );
1094 internalformat
= format
;
1095 glEsImpl
->glTexImage2D( target
, level
, internalformat
, width
, height
, border
, format
, type
, pixels
);
1098 void glDrawBuffer( GLenum
/*mode*/ )
1102 void glTranslatef( GLfloat x
, GLfloat y
, GLfloat z
)
1104 FlushOnStateChange( );
1105 glEsImpl
->glTranslatef( x
, y
, z
);
1108 void glRotatef( GLfloat angle
, GLfloat x
, GLfloat y
, GLfloat z
)
1110 FlushOnStateChange( );
1111 glEsImpl
->glRotatef( angle
, x
, y
, z
);
1114 void glScalef( GLfloat x
, GLfloat y
, GLfloat z
)
1116 FlushOnStateChange( );
1117 glEsImpl
->glScalef( x
, y
, z
);
1120 void glDepthRange( GLclampf zNear
, GLclampf zFar
)
1122 if ( ( nanoglState
.depth_range_near
== zNear
) && ( nanoglState
.depth_range_far
== zFar
) )
1128 nanoglState
.depth_range_near
= zNear
;
1129 nanoglState
.depth_range_far
= zFar
;
1131 FlushOnStateChange( );
1132 #ifdef USE_CORE_PROFILE
1133 glEsImpl
->glDepthRange( zNear
, zFar
);
1135 glEsImpl
->glDepthRangef( zNear
, zFar
);
1139 void glDepthFunc( GLenum func
)
1141 if ( nanoglState
.depth_func
== func
)
1147 nanoglState
.depth_func
= func
;
1149 FlushOnStateChange( );
1150 glEsImpl
->glDepthFunc( func
);
1153 void glFinish( void )
1155 FlushOnStateChange( );
1156 glEsImpl
->glFinish( );
1159 void glGetFloatv( GLenum pname
, GLfloat
*params
)
1161 FlushOnStateChange( );
1162 glEsImpl
->glGetFloatv( pname
, params
);
1165 void glCullFace( GLenum mode
)
1167 if ( nanoglState
.cullface
== mode
)
1173 nanoglState
.cullface
= mode
;
1175 FlushOnStateChange( );
1176 glEsImpl
->glCullFace( mode
);
1179 void glFrustum( GLfloat left
, GLfloat right
, GLfloat bottom
, GLfloat top
, GLfloat zNear
, GLfloat zFar
)
1181 FlushOnStateChange( );
1182 glEsImpl
->glFrustumf( left
, right
, bottom
, top
, zNear
, zFar
);
1185 void glClear( GLbitfield mask
)
1187 FlushOnStateChange( );
1188 glEsImpl
->glClear( mask
);
1191 void glVertex3f( GLfloat x
, GLfloat y
, GLfloat z
)
1193 GLfloat
*vert
= (GLfloat
*)ptrVertexAttribArray
++;
1197 #if defined( __MULTITEXTURE_SUPPORT__ )
1198 memcpy( vert
, ¤tVertexAttrib
.red
, 5 * sizeof( GLfloat
) );
1200 memcpy( vert
+ 1, ¤tVertexAttrib
.red
, 3 * sizeof( GLfloat
) );
1204 void glColor4fv( const GLfloat
*v
)
1206 if( nanoglState
.stupidglesbug
)
1208 currentVertexAttrib
.red
= (unsigned char)ClampTo255( ( v
[0] * v
[3] ) * 255.0f
);
1209 currentVertexAttrib
.green
= (unsigned char)ClampTo255( ( v
[1] * v
[3] ) * 255.0f
);
1210 currentVertexAttrib
.blue
= (unsigned char)ClampTo255( ( v
[2] * v
[3] ) * 255.0f
);
1214 currentVertexAttrib
.red
= (unsigned char)ClampTo255( v
[0] * 255.0f
);
1215 currentVertexAttrib
.green
= (unsigned char)ClampTo255( v
[1] * 255.0f
);
1216 currentVertexAttrib
.blue
= (unsigned char)ClampTo255( v
[2] * 255.0f
);
1218 currentVertexAttrib
.alpha
= (unsigned char)ClampTo255( v
[3] * 255.0f
);
1220 glEsImpl
->glColor4f( currentVertexAttrib
.red
/255.0f
, currentVertexAttrib
.green
/255.0f
,
1221 currentVertexAttrib
.blue
/255.0f
, currentVertexAttrib
.alpha
/255.0f
);
1224 void glColor3ubv( const GLubyte
*v
)
1226 currentVertexAttrib
.red
= v
[0];
1227 currentVertexAttrib
.green
= v
[1];
1228 currentVertexAttrib
.blue
= v
[2];
1229 currentVertexAttrib
.alpha
= 255;
1231 glEsImpl
->glColor4f( currentVertexAttrib
.red
/255.0f
, currentVertexAttrib
.green
/255.0f
,
1232 currentVertexAttrib
.blue
/255.0f
, currentVertexAttrib
.alpha
/255.0f
);
1235 void glColor4ubv( const GLubyte
*v
)
1237 //*((unsigned int*)(¤tVertexAttrib.red)) = *((unsigned int*)(v));
1238 if( nanoglState
.stupidglesbug
)
1240 currentVertexAttrib
.red
= (unsigned char)ClampTo255( v
[0] * v
[3] / 255.0f
);
1241 currentVertexAttrib
.green
= (unsigned char)ClampTo255( v
[1] * v
[3] / 255.0f
);
1242 currentVertexAttrib
.blue
= (unsigned char)ClampTo255( v
[2] * v
[3] / 255.0f
);
1246 currentVertexAttrib
.red
= v
[0];
1247 currentVertexAttrib
.green
= v
[1];
1248 currentVertexAttrib
.blue
= v
[2];
1250 currentVertexAttrib
.alpha
= v
[3];
1252 glEsImpl
->glColor4f( currentVertexAttrib
.red
/255.0f
, currentVertexAttrib
.green
/255.0f
,
1253 currentVertexAttrib
.blue
/255.0f
, currentVertexAttrib
.alpha
/255.0f
);
1256 void glColor3fv( const GLfloat
*v
)
1258 currentVertexAttrib
.red
= (unsigned char)ClampTo255( v
[0] * 255.0f
);
1259 currentVertexAttrib
.green
= (unsigned char)ClampTo255( v
[1] * 255.0f
);
1260 currentVertexAttrib
.blue
= (unsigned char)ClampTo255( v
[2] * 255.0f
);
1261 currentVertexAttrib
.alpha
= 255;
1263 glEsImpl
->glColor4f( currentVertexAttrib
.red
/255.0f
, currentVertexAttrib
.green
/255.0f
,
1264 currentVertexAttrib
.blue
/255.0f
, currentVertexAttrib
.alpha
/255.0f
);
1267 //-- nicknekit: xash3d funcs --
1269 void glColor4ub( GLubyte red
, GLubyte green
, GLubyte blue
, GLubyte alpha
)
1271 if( nanoglState
.stupidglesbug
)
1273 currentVertexAttrib
.red
= (unsigned char)ClampTo255( red
* alpha
/ 255.0f
);
1274 currentVertexAttrib
.green
= (unsigned char)ClampTo255( green
* alpha
/ 255.0f
);
1275 currentVertexAttrib
.blue
= (unsigned char)ClampTo255( blue
* alpha
/ 255.0f
);
1279 currentVertexAttrib
.red
= red
;
1280 currentVertexAttrib
.green
= green
;
1281 currentVertexAttrib
.blue
= blue
;
1283 currentVertexAttrib
.alpha
= alpha
;
1285 glEsImpl
->glColor4f( currentVertexAttrib
.red
/255.0f
, currentVertexAttrib
.green
/255.0f
,
1286 currentVertexAttrib
.blue
/255.0f
, currentVertexAttrib
.alpha
/255.0f
);
1289 void glColor3ub( GLubyte red
, GLubyte green
, GLubyte blue
)
1291 currentVertexAttrib
.red
= red
;
1292 currentVertexAttrib
.green
= green
;
1293 currentVertexAttrib
.blue
= blue
;
1294 currentVertexAttrib
.alpha
= 255;
1296 glEsImpl
->glColor4f( currentVertexAttrib
.red
/255.0f
, currentVertexAttrib
.green
/255.0f
,
1297 currentVertexAttrib
.blue
/255.0f
, currentVertexAttrib
.alpha
/255.0f
);
1300 void glNormal3fv( const GLfloat
*v
)
1302 FlushOnStateChange( );
1303 glEsImpl
->glNormal3f( v
[0], v
[1], v
[2] );
1306 void glCopyTexImage2D( GLenum target
, GLint level
, GLenum internalformat
, GLint x
, GLint y
, GLsizei width
, GLsizei height
, GLint border
)
1308 FlushOnStateChange( );
1309 glEsImpl
->glCopyTexImage2D( target
, level
, internalformat
, x
, y
, width
, height
, border
);
1312 void glTexImage1D( GLenum target
, GLint level
, GLint internalformat
, GLsizei width
, GLint border
, GLenum format
, GLenum type
, const GLvoid
*pixels
)
1314 glTexImage2D( GL_TEXTURE_2D
, level
, internalformat
, width
, 1, border
, format
, type
, pixels
);
1317 void glTexImage3D( GLenum target
, GLint level
, GLint internalformat
, GLsizei width
, GLsizei height
, GLsizei depth
, GLint border
, GLenum format
, GLenum type
, const GLvoid
*pixels
)
1319 glTexImage2D( GL_TEXTURE_2D
, level
, internalformat
, width
, height
, border
, format
, type
, pixels
);
1322 void glTexSubImage1D( GLenum target
, GLint level
, GLint xoffset
, GLsizei width
, GLenum format
, GLenum type
, const GLvoid
*pixels
)
1324 glTexSubImage2D( target
, level
, xoffset
, 0, width
, 1, format
, type
, pixels
);
1327 void glTexSubImage3D( GLenum target
, GLint level
,
1328 GLint xoffset
, GLint yoffset
,
1329 GLint zoffset
, GLsizei width
,
1330 GLsizei height
, GLsizei depth
,
1332 GLenum type
, const GLvoid
*pixels
)
1334 glTexSubImage2D( target
, level
, xoffset
, yoffset
, width
, height
, format
, type
, pixels
);
1337 GLboolean
glIsTexture( GLuint texture
)
1339 FlushOnStateChange( );
1340 return glEsImpl
->glIsTexture( texture
);
1343 // TODO: add native normal/reflection map texgen support
1345 void glTexGeni( GLenum coord
, GLenum pname
, GLint param
)
1347 FlushOnStateChange();
1348 //glEsImpl->glTexGeniOES( coord, pname, param );
1351 void glTexGenfv( GLenum coord
, GLenum pname
, const GLfloat
*params
)
1353 FlushOnStateChange();
1354 //glEsImpl->glTexGenfvOES( coord, pname, params );
1359 void glHint( GLenum target
, GLenum mode
)
1361 FlushOnStateChange( );
1362 glEsImpl
->glHint( target
, mode
);
1365 void glBlendFunc( GLenum sfactor
, GLenum dfactor
)
1369 glEsImpl
->glBlendFunc( sfactor
, dfactor
);
1372 if ( ( nanoglState
.sfactor
== sfactor
) && ( nanoglState
.dfactor
== dfactor
) )
1377 if( sfactor
== GL_SRC_ALPHA
&& dfactor
== GL_ONE
)
1379 sfactor
= GL_ONE
; // workaround gles bug
1380 nanoglState
.stupidglesbug
= GL_TRUE
;
1383 nanoglState
.stupidglesbug
= GL_FALSE
;
1385 nanoglState
.sfactor
= sfactor
;
1386 nanoglState
.dfactor
= dfactor
;
1387 FlushOnStateChange( );
1388 glEsImpl
->glBlendFunc( sfactor
, dfactor
);
1391 void glPopMatrix( void )
1393 FlushOnStateChange( );
1394 glEsImpl
->glPopMatrix( );
1397 void glShadeModel( GLenum mode
)
1399 if ( nanoglState
.shademodel
== mode
)
1403 nanoglState
.shademodel
= mode
;
1404 FlushOnStateChange( );
1405 glEsImpl
->glShadeModel( mode
);
1408 void glPushMatrix( void )
1410 FlushOnStateChange( );
1411 glEsImpl
->glPushMatrix( );
1414 void glTexEnvf( GLenum target
, GLenum pname
, GLfloat param
)
1418 glEsImpl
->glTexEnvf( target
, pname
, param
);
1421 if ( target
== GL_TEXTURE_ENV
)
1423 if ( pname
== GL_TEXTURE_ENV_MODE
)
1425 if ( param
== activetmuState
->texture_env_mode
.value
)
1431 FlushOnStateChange( );
1432 glEsImpl
->glTexEnvf( target
, pname
, param
);
1433 activetmuState
->texture_env_mode
.value
= param
;
1438 FlushOnStateChange( );
1439 glEsImpl
->glTexEnvf( target
, pname
, param
);
1442 void glVertex3fv( const GLfloat
*v
)
1444 GLfloat
*vert
= (GLfloat
*)ptrVertexAttribArray
++;
1445 memcpy( vert
, v
, 3 * sizeof( GLfloat
) );
1446 #if defined( __MULTITEXTURE_SUPPORT__ )
1447 memcpy( vert
+ 3, ¤tVertexAttrib
.red
, 5 * sizeof( GLfloat
) );
1449 memcpy( vert
+ 4, ¤tVertexAttrib
.red
, 3 * sizeof( GLfloat
) );
1453 void glDepthMask( GLboolean flag
)
1457 if ( nanoglState
.depthmask
== flag
)
1461 nanoglState
.depthmask
= flag
;
1462 FlushOnStateChange( );
1464 glEsImpl
->glDepthMask( flag
);
1467 void glBindTexture( GLenum target
, GLuint texture
)
1471 glEsImpl
->glBindTexture( target
,texture
);
1474 if ( activetmuState
->boundtexture
.value
== texture
)
1478 FlushOnStateChange( );
1479 activetmuState
->boundtexture
.value
= texture
;
1480 glEsImpl
->glBindTexture( target
, texture
);
1483 void glGetIntegerv( GLenum pname
, GLint
*params
)
1485 FlushOnStateChange( );
1486 glEsImpl
->glGetIntegerv( pname
, params
);
1489 GLubyte nano_extensions_string
[4096];
1490 const GLubyte
*glGetString( GLenum name
)
1493 if ( name
== GL_EXTENSIONS
)
1495 #if defined( __MULTITEXTURE_SUPPORT__ )
1496 sprintf( (char *)nano_extensions_string
, "%s %s", glEsImpl
->glGetString( name
), "GL_ARB_multitexture EXT_texture_env_add" );
1498 sprintf( (char *)nano_extensions_string
, "%s %s", glEsImpl
->glGetString( name
), "EXT_texture_env_add" );
1500 return nano_extensions_string
;
1502 return glEsImpl
->glGetString( name
);
1505 void glAlphaFunc( GLenum func
, GLclampf ref
)
1507 FlushOnStateChange( );
1508 glEsImpl
->glAlphaFunc( func
, ref
);
1511 void glFlush( void )
1513 FlushOnStateChange( );
1514 glEsImpl
->glFlush( );
1517 void glReadPixels( GLint x
, GLint y
, GLsizei width
, GLsizei height
, GLenum format
, GLenum type
, GLvoid
*pixels
)
1519 if ( format
== GL_DEPTH_COMPONENT
)
1521 // OpenglEs 1.1 does not support reading depth buffer without an extension
1522 memset( pixels
, 0xff, 4 );
1525 FlushOnStateChange( );
1526 glEsImpl
->glReadPixels( x
, y
, width
, height
, format
, type
, pixels
);
1529 void glReadBuffer( GLenum
/*mode*/ )
1533 void glLoadMatrixf( const GLfloat
*m
)
1535 FlushOnStateChange( );
1536 glEsImpl
->glLoadMatrixf( m
);
1539 void glTexSubImage2D( GLenum target
, GLint level
, GLint xoffset
, GLint yoffset
, GLsizei width
, GLsizei height
, GLenum format
, GLenum type
, const GLvoid
*pixels
)
1541 FlushOnStateChange( );
1542 glEsImpl
->glTexSubImage2D( target
, level
, xoffset
, yoffset
, width
, height
, format
, type
, pixels
);
1545 void glClearColor( GLclampf red
, GLclampf green
, GLclampf blue
, GLclampf alpha
)
1547 FlushOnStateChange( );
1548 glEsImpl
->glClearColor( red
, green
, blue
, alpha
);
1551 GLenum
glGetError( void )
1553 //FlushOnStateChange();
1554 return GL_NO_ERROR
; //glEsImpl->glGetError();
1557 void glActiveTexture( GLenum texture
)
1561 glEsImpl
->glActiveTexture( texture
);
1564 if ( activetmu
== texture
)
1568 if ( delayedttmuchange
)
1570 delayedttmuchange
= GL_FALSE
;
1574 delayedttmuchange
= GL_TRUE
;
1575 delayedtmutarget
= texture
;
1577 if ( texture
== GL_TEXTURE0
)
1579 activetmuState
= &tmuState0
;
1583 activetmuState
= &tmuState1
;
1585 activetmu
= texture
;
1588 void glClientActiveTexture( GLenum texture
)
1592 glEsImpl
->glClientActiveTexture( texture
);
1595 clientactivetmu
= texture
;
1598 void glPolygonMode( GLenum face
, GLenum mode
)
1602 void glDeleteTextures( GLsizei n
, const GLuint
*textures
)
1604 FlushOnStateChange( );
1605 glEsImpl
->glDeleteTextures( n
, textures
);
1608 void glClearDepth( GLclampf depth
)
1610 FlushOnStateChange( );
1611 glEsImpl
->glClearDepthf( depth
);
1614 void glClipPlane( GLenum plane
, const GLdouble
*equation
)
1616 FlushOnStateChange( );
1618 array
[0] = ( GLfloat
)( equation
[0] );
1619 array
[1] = ( GLfloat
)( equation
[1] );
1620 array
[2] = ( GLfloat
)( equation
[2] );
1621 array
[3] = ( GLfloat
)( equation
[3] );
1622 glEsImpl
->glClipPlanef( plane
, array
);
1625 void glScissor( GLint x
, GLint y
, GLsizei width
, GLsizei height
)
1627 FlushOnStateChange( );
1628 glEsImpl
->glScissor( x
, y
, width
, height
);
1631 void glPointSize( GLfloat size
)
1633 FlushOnStateChange( );
1634 glEsImpl
->glPointSize( size
);
1637 void glArrayElement( GLint i
)
1640 void glLineWidth( GLfloat width
)
1643 void glCallList( GLuint list
)
1646 void glColorMask( GLboolean red
, GLboolean green
, GLboolean blue
, GLboolean alpha
)
1649 void glStencilFunc( GLenum func
, GLint ref
, GLuint mask
)
1652 void glStencilOp( GLenum fail
, GLenum zfail
, GLenum zpass
)
1656 struct ptrstate vertex_array
;
1657 struct ptrstate color_array
;
1658 struct ptrstate texture_coord_array
;
1660 void glDrawElements( GLenum mode
, GLsizei count
, GLenum type
, const GLvoid
*indices
)
1664 glEsImpl
->glDrawElements( mode
, count
, type
, indices
);
1667 // ensure that all primitives specified between glBegin/glEnd pairs
1668 // are rendered first, and that we have correct tmu in use..
1669 FlushOnStateChange( );
1670 // setup correct vertex/color/texcoord pointers
1672 tmuState0
.vertex_array
.changed
||
1673 tmuState0
.color_array
.changed
||
1674 tmuState0
.texture_coord_array
.changed
|| tmuState0
.normal_array
.changed
)
1676 glEsImpl
->glClientActiveTexture( GL_TEXTURE0
);
1678 if ( arraysValid
|| tmuState0
.vertex_array
.changed
)
1680 if ( tmuState0
.vertex_array
.enabled
)
1682 glEsImpl
->glEnableClientState( GL_VERTEX_ARRAY
);
1686 glEsImpl
->glDisableClientState( GL_VERTEX_ARRAY
);
1688 glEsImpl
->glVertexPointer( tmuState0
.vertex_array
.size
,
1689 tmuState0
.vertex_array
.type
,
1690 tmuState0
.vertex_array
.stride
,
1691 tmuState0
.vertex_array
.ptr
);
1692 tmuState0
.vertex_array
.changed
= GL_FALSE
;
1694 if ( arraysValid
|| tmuState0
.color_array
.changed
)
1696 if ( tmuState0
.color_array
.enabled
)
1698 glEsImpl
->glEnableClientState( GL_COLOR_ARRAY
);
1702 glEsImpl
->glDisableClientState( GL_COLOR_ARRAY
);
1704 glEsImpl
->glColorPointer( tmuState0
.color_array
.size
,
1705 tmuState0
.color_array
.type
,
1706 tmuState0
.color_array
.stride
,
1707 tmuState0
.color_array
.ptr
);
1708 tmuState0
.color_array
.changed
= GL_FALSE
;
1710 if ( arraysValid
|| tmuState0
.normal_array
.changed
)
1712 if ( tmuState0
.normal_array
.enabled
)
1714 glEsImpl
->glEnableClientState( GL_NORMAL_ARRAY
);
1718 glEsImpl
->glDisableClientState( GL_NORMAL_ARRAY
);
1720 glEsImpl
->glNormalPointer( tmuState0
.normal_array
.type
,
1721 tmuState0
.normal_array
.stride
,
1722 tmuState0
.normal_array
.ptr
);
1723 tmuState0
.normal_array
.changed
= GL_FALSE
;
1725 if ( arraysValid
|| tmuState0
.texture_coord_array
.changed
)
1727 tmuState0
.texture_coord_array
.changed
= GL_FALSE
;
1728 if ( tmuState0
.texture_coord_array
.enabled
)
1730 glEsImpl
->glEnableClientState( GL_TEXTURE_COORD_ARRAY
);
1734 glEsImpl
->glDisableClientState( GL_TEXTURE_COORD_ARRAY
);
1736 glEsImpl
->glTexCoordPointer( tmuState0
.texture_coord_array
.size
,
1737 tmuState0
.texture_coord_array
.type
,
1738 tmuState0
.texture_coord_array
.stride
,
1739 tmuState0
.texture_coord_array
.ptr
);
1742 if ( arraysValid
|| tmuState1
.texture_coord_array
.changed
)
1744 tmuState1
.texture_coord_array
.changed
= GL_FALSE
;
1745 glEsImpl
->glClientActiveTexture( GL_TEXTURE1
);
1746 if ( tmuState1
.texture_coord_array
.enabled
)
1748 glEsImpl
->glEnableClientState( GL_TEXTURE_COORD_ARRAY
);
1752 glEsImpl
->glDisableClientState( GL_TEXTURE_COORD_ARRAY
);
1754 glEsImpl
->glTexCoordPointer( tmuState1
.texture_coord_array
.size
,
1755 tmuState1
.texture_coord_array
.type
,
1756 tmuState1
.texture_coord_array
.stride
,
1757 tmuState1
.texture_coord_array
.ptr
);
1760 arraysValid
= GL_FALSE
;
1761 glEsImpl
->glDrawElements( mode
, count
, type
, indices
);
1766 void glEnableClientState( GLenum array
)
1770 glEsImpl
->glEnableClientState( array
);
1771 if( array
== GL_VERTEX_ARRAY
)
1775 struct nanotmuState
*clientstate
= NULL
;
1776 if ( clientactivetmu
== GL_TEXTURE0
)
1778 clientstate
= &tmuState0
;
1780 else if ( clientactivetmu
== GL_TEXTURE1
)
1782 clientstate
= &tmuState1
;
1790 case GL_VERTEX_ARRAY
:
1791 if ( clientstate
->vertex_array
.enabled
)
1795 clientstate
->vertex_array
.enabled
= GL_TRUE
;
1796 clientstate
->vertex_array
.changed
= GL_TRUE
;
1798 case GL_COLOR_ARRAY
:
1799 if ( clientstate
->color_array
.enabled
)
1803 clientstate
->color_array
.enabled
= GL_TRUE
;
1804 clientstate
->color_array
.changed
= GL_TRUE
;
1807 case GL_NORMAL_ARRAY
:
1808 if ( clientstate
->normal_array
.enabled
)
1812 clientstate
->normal_array
.enabled
= GL_TRUE
;
1813 clientstate
->normal_array
.changed
= GL_TRUE
;
1816 case GL_TEXTURE_COORD_ARRAY
:
1817 if ( clientstate
->texture_coord_array
.enabled
)
1821 clientstate
->texture_coord_array
.enabled
= GL_TRUE
;
1822 clientstate
->texture_coord_array
.changed
= GL_TRUE
;
1828 void glDisableClientState( GLenum array
)
1832 glEsImpl
->glDisableClientState( array
);
1833 if( array
== GL_VERTEX_ARRAY
)
1837 struct nanotmuState
*clientstate
= NULL
;
1838 if ( clientactivetmu
== GL_TEXTURE0
)
1840 clientstate
= &tmuState0
;
1842 else if ( clientactivetmu
== GL_TEXTURE1
)
1844 clientstate
= &tmuState1
;
1852 case GL_VERTEX_ARRAY
:
1853 if ( !clientstate
->vertex_array
.enabled
)
1857 clientstate
->vertex_array
.enabled
= GL_FALSE
;
1858 clientstate
->vertex_array
.changed
= GL_TRUE
;
1860 case GL_COLOR_ARRAY
:
1861 if ( !clientstate
->color_array
.enabled
)
1865 clientstate
->color_array
.enabled
= GL_FALSE
;
1866 clientstate
->color_array
.changed
= GL_TRUE
;
1869 case GL_NORMAL_ARRAY
:
1870 if ( !clientstate
->normal_array
.enabled
)
1874 clientstate
->normal_array
.enabled
= GL_FALSE
;
1875 clientstate
->normal_array
.changed
= GL_TRUE
;
1878 case GL_TEXTURE_COORD_ARRAY
:
1879 if ( !clientstate
->texture_coord_array
.enabled
)
1883 clientstate
->texture_coord_array
.enabled
= GL_FALSE
;
1884 clientstate
->texture_coord_array
.changed
= GL_TRUE
;
1890 void glVertexPointer( GLint size
, GLenum type
, GLsizei stride
, const GLvoid
*pointer
)
1895 glEsImpl
->glVertexPointer( size
, type
, stride
, pointer
);
1898 if ( tmuState0
.vertex_array
.size
== size
&&
1899 tmuState0
.vertex_array
.stride
== stride
&&
1900 tmuState0
.vertex_array
.type
== type
&&
1901 tmuState0
.vertex_array
.ptr
== pointer
)
1905 tmuState0
.vertex_array
.size
= size
;
1906 tmuState0
.vertex_array
.stride
= stride
;
1907 tmuState0
.vertex_array
.type
= type
;
1908 tmuState0
.vertex_array
.ptr
= (GLvoid
*)pointer
;
1909 tmuState0
.vertex_array
.changed
= GL_TRUE
;
1911 void glTexCoordPointer( GLint size
, GLenum type
, GLsizei stride
, const GLvoid
*pointer
)
1915 glEsImpl
->glTexCoordPointer( size
, type
, stride
, pointer
);
1918 struct nanotmuState
*clientstate
= NULL
;
1919 if ( clientactivetmu
== GL_TEXTURE0
)
1921 clientstate
= &tmuState0
;
1923 else if ( clientactivetmu
== GL_TEXTURE1
)
1925 clientstate
= &tmuState1
;
1927 if ( clientstate
->texture_coord_array
.size
== size
&&
1928 clientstate
->texture_coord_array
.stride
== stride
&&
1929 clientstate
->texture_coord_array
.type
== type
&&
1930 clientstate
->texture_coord_array
.ptr
== pointer
)
1934 clientstate
->texture_coord_array
.size
= size
;
1935 clientstate
->texture_coord_array
.stride
= stride
;
1936 clientstate
->texture_coord_array
.type
= type
;
1937 clientstate
->texture_coord_array
.ptr
= (GLvoid
*)pointer
;
1938 clientstate
->texture_coord_array
.changed
= GL_TRUE
;
1940 void glColorPointer( GLint size
, GLenum type
, GLsizei stride
, const GLvoid
*pointer
)
1942 if ( tmuState0
.color_array
.size
== size
&&
1943 tmuState0
.color_array
.stride
== stride
&&
1944 tmuState0
.color_array
.type
== type
&&
1945 tmuState0
.color_array
.ptr
== pointer
)
1949 tmuState0
.color_array
.size
= size
;
1950 tmuState0
.color_array
.stride
= stride
;
1951 tmuState0
.color_array
.type
= type
;
1952 tmuState0
.color_array
.ptr
= (GLvoid
*)pointer
;
1953 tmuState0
.color_array
.changed
= GL_TRUE
;
1956 void glNormalPointer( GLenum type
, GLsizei stride
, const GLvoid
*pointer
)
1959 if ( tmuState0
.normal_array
.size
== size
&&
1960 tmuState0
.normal_array
.stride
== stride
&&
1961 tmuState0
.normal_array
.type
== type
&&
1962 tmuState0
.normal_array
.ptr
== pointer
)
1966 tmuState0
.normal_array
.size
= size
;
1967 tmuState0
.normal_array
.stride
= stride
;
1968 tmuState0
.normal_array
.type
= type
;
1969 tmuState0
.normal_array
.ptr
= (GLvoid
*)pointer
;
1970 tmuState0
.normal_array
.changed
= GL_TRUE
;
1972 void glPolygonOffset( GLfloat factor
, GLfloat units
)
1974 FlushOnStateChange( );
1975 glEsImpl
->glPolygonOffset( factor
, units
);
1977 void glStencilMask( GLuint mask
)
1980 void glClearStencil( GLint s
)
1984 #if defined( __MULTITEXTURE_SUPPORT__ )
1986 extern "C" void glMultiTexCoord2fARB( GLenum target
, GLfloat s
, GLfloat t
);
1988 void glMultiTexCoord2fARB( GLenum target
, GLfloat s
, GLfloat t
)
1990 if ( target
== GL_TEXTURE0
)
1992 glTexCoord2f( s
, t
);
1996 currentVertexAttrib
.s_multi
= s
;
1997 currentVertexAttrib
.t_multi
= t
;
2003 /*void glDrawArrays( GLenum mode, int first, int count)
2005 FlushOnStateChange();
2006 glEsImpl->glDrawArrays(mode, first , count);
2008 void glMultMatrixf( const GLfloat
*m
)
2010 FlushOnStateChange( );
2011 glEsImpl
->glMultMatrixf( m
);
2014 void glPixelStorei( GLenum pname
, GLint param
)
2016 FlushOnStateChange( );
2017 glEsImpl
->glPixelStorei( pname
, param
);
2020 void glFogf( GLenum pname
, GLfloat param
)
2022 FlushOnStateChange( );
2023 glEsImpl
->glFogf( pname
, param
);
2026 void glFogfv( GLenum pname
, const GLfloat
*params
)
2028 FlushOnStateChange( );
2029 glEsImpl
->glFogfv( pname
, params
);
2032 void glGetTexParameteriv( GLenum target
, GLenum pname
, GLint
*params
)
2034 FlushOnStateChange( );
2035 glEsImpl
->glGetTexParameteriv( target
, pname
, params
);
2038 // This gives: called unimplemented OpenGL ES API (Android)
2039 void glTexParameteri( GLenum target
, GLenum pname
, GLint param
)
2041 if ( pname
== GL_TEXTURE_BORDER_COLOR
)
2043 return; // not supported by opengl es
2045 if ( ( pname
== GL_TEXTURE_WRAP_S
||
2046 pname
== GL_TEXTURE_WRAP_T
) &&
2052 FlushOnStateChange( );
2053 glEsImpl
->glTexParameteri( target
, pname
, param
);
2056 void glTexParameterx( GLenum target
, GLenum pname
, GLfixed param
)
2058 if ( pname
== GL_TEXTURE_BORDER_COLOR
)
2060 return; // not supported by opengl es
2062 if ( ( pname
== GL_TEXTURE_WRAP_S
||
2063 pname
== GL_TEXTURE_WRAP_T
) &&
2068 FlushOnStateChange( );
2069 glEsImpl
->glTexParameterx( target
, pname
, param
);
2072 void glGenTextures( GLsizei n
, GLuint
*textures
)
2074 FlushOnStateChange( );
2075 glEsImpl
->glGenTextures( n
, textures
);
2078 void glFrontFace( GLenum mode
)
2080 FlushOnStateChange( );
2081 glEsImpl
->glFrontFace( mode
);
2085 void glTexEnvi( GLenum target
, GLenum pname
, GLint param
)
2089 glEsImpl
->glTexEnvi( target
, pname
, param
);
2092 if ( target
== GL_TEXTURE_ENV
)
2094 if ( pname
== GL_TEXTURE_ENV_MODE
)
2096 if ( param
== activetmuState
->texture_env_mode
.value
)
2102 FlushOnStateChange( );
2103 glEsImpl
->glTexEnvi( target
, pname
, param
);
2104 activetmuState
->texture_env_mode
.value
= param
;
2109 FlushOnStateChange( );
2110 glEsImpl
->glTexEnvi( target
, pname
, param
);
2113 #ifdef __MULTITEXTURE_SUPPORT__
2114 void glMultiTexCoord3fARB( GLenum a
, GLfloat b
, GLfloat c
, GLfloat
)
2116 return glMultiTexCoord2fARB( a
, b
, c
);
2119 void glMultiTexCoord2f( GLenum a
, GLfloat b
, GLfloat c
)
2121 glMultiTexCoord2fARB(a
,b
,c
);
2124 void glDrawArrays( GLenum mode
, GLint first
, GLsizei count
)
2128 glEsImpl
->glDrawArrays( mode
, first
, count
);
2131 // ensure that all primitives specified between glBegin/glEnd pairs
2132 // are rendered first, and that we have correct tmu in use..
2133 if ( mode
== GL_QUADS
)
2134 mode
= GL_TRIANGLE_FAN
;
2135 FlushOnStateChange( );
2136 // setup correct vertex/color/texcoord pointers
2138 tmuState0
.vertex_array
.changed
||
2139 tmuState0
.color_array
.changed
||
2140 tmuState0
.texture_coord_array
.changed
|| tmuState0
.normal_array
.changed
)
2142 glEsImpl
->glClientActiveTexture( GL_TEXTURE0
);
2144 if ( arraysValid
|| tmuState0
.vertex_array
.changed
)
2146 if ( tmuState0
.vertex_array
.enabled
)
2148 glEsImpl
->glEnableClientState( GL_VERTEX_ARRAY
);
2152 glEsImpl
->glDisableClientState( GL_VERTEX_ARRAY
);
2154 glEsImpl
->glVertexPointer( tmuState0
.vertex_array
.size
,
2155 tmuState0
.vertex_array
.type
,
2156 tmuState0
.vertex_array
.stride
,
2157 tmuState0
.vertex_array
.ptr
);
2158 tmuState0
.vertex_array
.changed
= GL_FALSE
;
2160 if ( arraysValid
|| tmuState0
.color_array
.changed
)
2162 if ( tmuState0
.color_array
.enabled
)
2164 glEsImpl
->glEnableClientState( GL_COLOR_ARRAY
);
2168 glEsImpl
->glDisableClientState( GL_COLOR_ARRAY
);
2170 glEsImpl
->glColorPointer( tmuState0
.color_array
.size
,
2171 tmuState0
.color_array
.type
,
2172 tmuState0
.color_array
.stride
,
2173 tmuState0
.color_array
.ptr
);
2174 tmuState0
.color_array
.changed
= GL_FALSE
;
2176 if ( arraysValid
|| tmuState0
.normal_array
.changed
)
2178 if ( tmuState0
.normal_array
.enabled
)
2180 glEsImpl
->glEnableClientState( GL_NORMAL_ARRAY
);
2184 glEsImpl
->glDisableClientState( GL_NORMAL_ARRAY
);
2186 glEsImpl
->glNormalPointer( tmuState0
.normal_array
.type
,
2187 tmuState0
.normal_array
.stride
,
2188 tmuState0
.normal_array
.ptr
);
2189 tmuState0
.normal_array
.changed
= GL_FALSE
;
2191 if ( arraysValid
|| tmuState0
.texture_coord_array
.changed
)
2193 tmuState0
.texture_coord_array
.changed
= GL_FALSE
;
2194 if ( tmuState0
.texture_coord_array
.enabled
)
2196 glEsImpl
->glEnableClientState( GL_TEXTURE_COORD_ARRAY
);
2200 glEsImpl
->glDisableClientState( GL_TEXTURE_COORD_ARRAY
);
2202 glEsImpl
->glTexCoordPointer( tmuState0
.texture_coord_array
.size
,
2203 tmuState0
.texture_coord_array
.type
,
2204 tmuState0
.texture_coord_array
.stride
,
2205 tmuState0
.texture_coord_array
.ptr
);
2208 if ( arraysValid
|| tmuState1
.texture_coord_array
.changed
)
2210 tmuState1
.texture_coord_array
.changed
= GL_FALSE
;
2211 glEsImpl
->glClientActiveTexture( GL_TEXTURE1
);
2212 if ( tmuState1
.texture_coord_array
.enabled
)
2214 glEsImpl
->glEnableClientState( GL_TEXTURE_COORD_ARRAY
);
2218 glEsImpl
->glDisableClientState( GL_TEXTURE_COORD_ARRAY
);
2220 glEsImpl
->glTexCoordPointer( tmuState1
.texture_coord_array
.size
,
2221 tmuState1
.texture_coord_array
.type
,
2222 tmuState1
.texture_coord_array
.stride
,
2223 tmuState1
.texture_coord_array
.ptr
);
2226 arraysValid
= GL_FALSE
;
2227 glEsImpl
->glDrawArrays( mode
, first
, count
);
2229 /*void glNormalPointer(GLenum type, GLsizei stride, const void *ptr)
2231 glEsImpl->glNormalPointer( type, stride, ptr );
2234 void glCopyTexSubImage2D( GLenum target
, GLint level
, GLint xoffset
, GLint yoffset
, GLint x
, GLint y
, GLsizei width
, GLsizei height
)
2236 FlushOnStateChange( );
2237 glEsImpl
->glCopyTexSubImage2D( target
, level
, xoffset
, yoffset
, x
, y
, width
, height
);
2240 void glGenFramebuffers( GLsizei n
, GLuint
*framebuffers
)
2242 FlushOnStateChange( );
2243 glEsImpl
->glGenFramebuffers( n
, framebuffers
);
2246 void glGenRenderbuffers( GLsizei n
, GLuint
*renderbuffers
)
2248 FlushOnStateChange( );
2249 glEsImpl
->glGenRenderbuffers( n
, renderbuffers
);
2252 void glBindRenderbuffer( GLenum target
, GLuint renderbuffer
)
2254 FlushOnStateChange( );
2255 glEsImpl
->glBindRenderbuffer( target
, renderbuffer
);
2258 void glBindFramebuffer( GLenum target
, GLuint framebuffer
)
2260 FlushOnStateChange( );
2261 glEsImpl
->glBindFramebuffer( target
, framebuffer
);
2264 void glFramebufferRenderbuffer( GLenum target
, GLenum attachment
, GLenum renderbuffertarget
, GLuint renderbuffer
)
2266 FlushOnStateChange( );
2267 glEsImpl
->glFramebufferRenderbuffer( target
, attachment
, renderbuffertarget
, renderbuffer
);
2270 void glDeleteFramebuffers( GLsizei n
, const GLuint
*framebuffers
)
2272 FlushOnStateChange( );
2273 glEsImpl
->glDeleteFramebuffers( n
, framebuffers
);
2276 void glDeleteRenderbuffers( GLsizei n
, const GLuint
*renderbuffers
)
2278 FlushOnStateChange( );
2279 glEsImpl
->glDeleteRenderbuffers( n
, renderbuffers
);
2281 void glFramebufferTexture2D( GLenum target
, GLenum attachment
, GLenum textarget
, GLuint texture
, GLint level
)
2283 FlushOnStateChange( );
2284 glEsImpl
->glFramebufferTexture2D( target
, attachment
, textarget
, texture
, level
);
2287 void glRenderbufferStorage( GLenum target
, GLenum internalformat
, GLsizei width
, GLsizei height
)
2289 FlushOnStateChange( );
2290 glEsImpl
->glRenderbufferStorage( target
, internalformat
, width
, height
);
2293 void glBindBufferARB( GLuint target
, GLuint index
)
2297 if( index
&& !sindex
&& !skipnanogl
)
2298 FlushOnStateChange();
2299 glEsImpl
->glDisableClientState( GL_COLOR_ARRAY
);
2300 glEsImpl
->glColor4f( currentVertexAttrib
.red
/255.0f
, currentVertexAttrib
.green
/255.0f
,
2301 currentVertexAttrib
.blue
/255.0f
, currentVertexAttrib
.alpha
/255.0f
);
2303 skipnanogl
= (!!index
) || vboarray
;
2304 glEsImpl
->glBindBuffer( target
, index
);
2305 if( sindex
&& !index
)
2307 arraysValid
= GL_FALSE
;
2312 void glGenBuffersARB( GLuint count
, GLuint
*indexes
)
2314 glEsImpl
->glGenBuffers( count
, indexes
);
2317 void glDeleteBuffersARB( GLuint count
, GLuint
*indexes
)
2319 glEsImpl
->glDeleteBuffers( count
, indexes
);
2322 void glBufferDataARB( GLuint target
, GLuint size
, void *buffer
, GLuint type
)
2324 glEsImpl
->glBufferData( target
, size
, buffer
, type
);
2327 void glBufferSubDataARB( GLuint target
, GLsizei offset
, GLsizei size
, void *buffer
)
2329 glEsImpl
->glBufferSubData( target
, offset
, size
, buffer
);