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 GLclampf depth_range_near
;
64 GLclampf depth_range_far
;
73 static struct nanoState nanoglState
;
75 static struct nanoState nanoglInitState
=
143 struct booleanstate texture_2d
;
144 struct floatstate texture_env_mode
;
145 struct uintstate boundtexture
;
146 struct ptrstate vertex_array
;
147 struct ptrstate color_array
;
148 struct ptrstate texture_coord_array
;
149 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
;
181 #if !defined (__WINS__)
182 //#define __FORCEINLINE __forceinline
183 #define __FORCEINLINE inline
185 #define __FORCEINLINE
188 static GLboolean delayedttmuchange
= GL_FALSE
;
189 static GLenum delayedtmutarget
= GL_TEXTURE0
;
196 #if !defined(__MULTITEXTURE_SUPPORT__)
206 #if defined(__MULTITEXTURE_SUPPORT__)
212 static VertexAttrib vertexattribs
[60000];
214 static GLushort indexArray
[50000];
216 static GLuint vertexCount
= 0;
217 static GLuint indexCount
= 0;
218 static GLuint vertexMark
= 0;
219 static int indexbase
= 0;
221 static VertexAttrib
* ptrVertexAttribArray
= NULL
;
222 static VertexAttrib
* ptrVertexAttribArrayMark
= NULL
;
224 static VertexAttrib currentVertexAttrib
;
225 #if defined(__MULTITEXTURE_SUPPORT__)
226 static VertexAttrib currentVertexAttribInit
= {0.0f
,0.0f
,0.0f
,
232 static VertexAttrib currentVertexAttribInit
= {0.0f
,0.0f
,0.0f
,0.0f
,
237 static GLushort
* ptrIndexArray
= NULL
;
239 static GLboolean arraysValid
= GL_FALSE
;
243 ptrVertexAttribArray
= vertexattribs
;
244 ptrVertexAttribArrayMark
= ptrVertexAttribArray
;
245 ptrIndexArray
= indexArray
;
247 memcpy(&nanoglState
, &nanoglInitState
, sizeof(struct nanoState
));
248 memcpy(&tmuState0
,&tmuInitState
,sizeof(struct nanotmuState
));
249 memcpy(&tmuState1
,&tmuInitState
,sizeof(struct nanotmuState
));
250 memcpy(¤tVertexAttrib
,¤tVertexAttribInit
,sizeof(struct VertexAttrib
));
252 activetmuState
= &tmuState0
;
253 wrapperPrimitiveMode
= GL_QUADS
;
254 useTexCoordArray
= GL_FALSE
;
255 activetmu
= GL_TEXTURE0
;
256 clientactivetmu
= GL_TEXTURE0
;
257 delayedttmuchange
= GL_FALSE
;
258 delayedtmutarget
= GL_TEXTURE0
;
263 arraysValid
= GL_FALSE
;
266 void ResetNanoState()
269 if (tmuState0
.color_array
.enabled
)
271 glEsImpl
->glEnableClientState(GL_COLOR_ARRAY
);
275 glEsImpl
->glDisableClientState(GL_COLOR_ARRAY
);
278 if (tmuState0
.vertex_array
.enabled
)
280 glEsImpl
->glEnableClientState(GL_VERTEX_ARRAY
);
284 glEsImpl
->glDisableClientState(GL_VERTEX_ARRAY
);
287 if (tmuState0
.texture_coord_array
.enabled
)
289 glEsImpl
->glEnableClientState(GL_TEXTURE_COORD_ARRAY
);
293 glEsImpl
->glDisableClientState(GL_TEXTURE_COORD_ARRAY
);
296 if (tmuState0
.normal_array
.enabled
)
298 glEsImpl
->glEnableClientState(GL_NORMAL_ARRAY
);
302 glEsImpl
->glDisableClientState(GL_NORMAL_ARRAY
);
304 glEsImpl
->glVertexPointer(tmuState0
.vertex_array
.size
,
305 tmuState0
.vertex_array
.type
,
306 tmuState0
.vertex_array
.stride
,
307 tmuState0
.vertex_array
.ptr
);
309 glEsImpl
->glTexCoordPointer(tmuState0
.texture_coord_array
.size
,
310 tmuState0
.texture_coord_array
.type
,
311 tmuState0
.texture_coord_array
.stride
,
312 tmuState0
.texture_coord_array
.ptr
);
314 glEsImpl
->glColorPointer(tmuState0
.color_array
.size
,
315 tmuState0
.color_array
.type
,
316 tmuState0
.color_array
.stride
,
317 tmuState0
.color_array
.ptr
);
319 glEsImpl
->glNormalPointer(
320 tmuState0
.normal_array
.type
,
321 tmuState0
.normal_array
.stride
,
322 tmuState0
.normal_array
.ptr
);
324 glEsImpl
->glMatrixMode(nanoglState
.matrixmode
);
328 glEsImpl
->glColor4f (currentVertexAttrib
.red
, currentVertexAttrib
.green
, currentVertexAttrib
.blue
, currentVertexAttrib
.alpha
);
330 glEsImpl
->glBlendFunc(nanoglState
.sfactor
, nanoglState
.dfactor
);
332 //glEsImpl->glBindTexture(GL_TEXTURE_2D, stackTextureState);
334 glEsImpl
->glTexEnvi(GL_TEXTURE_ENV
, GL_TEXTURE_ENV_MODE
, activetmuState
->texture_env_mode
.value
);
336 arraysValid
= GL_FALSE
;
339 void FlushOnStateChange()
341 if (delayedttmuchange
)
343 delayedttmuchange
= GL_FALSE
;
344 #ifndef USE_CORE_PROFILE
345 glEsImpl
->glActiveTexture(delayedtmutarget
);
354 glEsImpl
->glClientActiveTexture(GL_TEXTURE0
);
355 glEsImpl
->glVertexPointer(3, GL_FLOAT
, sizeof(VertexAttrib
), &vertexattribs
[0].x
);
356 glEsImpl
->glColorPointer(4, GL_UNSIGNED_BYTE
, sizeof(VertexAttrib
), &vertexattribs
[0].red
);
357 glEsImpl
->glTexCoordPointer(2, GL_FLOAT
, sizeof(VertexAttrib
), &vertexattribs
[0].s
);
358 glEsImpl
->glEnableClientState(GL_VERTEX_ARRAY
);
359 glEsImpl
->glEnableClientState(GL_TEXTURE_COORD_ARRAY
);
360 glEsImpl
->glEnableClientState(GL_COLOR_ARRAY
);
361 #if defined(__MULTITEXTURE_SUPPORT__)
362 glEsImpl
->glClientActiveTexture(GL_TEXTURE1
);
363 glEsImpl
->glTexCoordPointer(2, GL_FLOAT
, sizeof(VertexAttrib
), &vertexattribs
[0].s_multi
);
364 glEsImpl
->glEnableClientState(GL_TEXTURE_COORD_ARRAY
);
365 glEsImpl
->glClientActiveTexture(GL_TEXTURE0
);
367 arraysValid
= GL_TRUE
;
370 glEsImpl
->glDrawElements( GL_TRIANGLES
,vertexCount
,GL_UNSIGNED_SHORT
, indexArray
);
373 #if defined(__MULTITEXTURE_SUPPORT__)
374 useMultiTexCoordArray
= GL_FALSE
;
378 ptrVertexAttribArray
= vertexattribs
;
379 ptrVertexAttribArrayMark
= ptrVertexAttribArray
;
380 ptrIndexArray
= indexArray
;
381 useTexCoordArray
= GL_FALSE
;
385 FlushOnStateChange();
391 void glBegin(GLenum mode
)
393 wrapperPrimitiveMode
= mode
;
394 vertexMark
= vertexCount
;
395 ptrVertexAttribArrayMark
= ptrVertexAttribArray
;
396 indexbase
= indexCount
;
401 vertexCount
+=((unsigned char*)ptrVertexAttribArray
-(unsigned char*)ptrVertexAttribArrayMark
)/sizeof(VertexAttrib
);
406 switch (wrapperPrimitiveMode
)
410 *ptrIndexArray
++ = indexCount
;
411 *ptrIndexArray
++ = indexCount
+1;
412 *ptrIndexArray
++ = indexCount
+2;
413 *ptrIndexArray
++ = indexCount
;
414 *ptrIndexArray
++ = indexCount
+2;
415 *ptrIndexArray
++ = indexCount
+3;
422 int vcount
= (vertexCount
-vertexMark
)/3;
423 for (int count
= 0; count
< vcount
; count
++)
425 *ptrIndexArray
++ = indexCount
;
426 *ptrIndexArray
++ = indexCount
+1;
427 *ptrIndexArray
++ = indexCount
+2;
432 case GL_TRIANGLE_STRIP
:
434 *ptrIndexArray
++ = indexCount
;
435 *ptrIndexArray
++ = indexCount
+1;
436 *ptrIndexArray
++ = indexCount
+2;
438 int vcount
= ((vertexCount
-vertexMark
)-3);
439 if (vcount
&& ((long)ptrIndexArray
& 0x02))
441 *ptrIndexArray
++ = indexCount
-1; // 2
442 *ptrIndexArray
++ = indexCount
-2; // 1
443 *ptrIndexArray
++ = indexCount
; // 3
448 unsigned int* longptr
= (unsigned int*) ptrIndexArray
;
450 for (int count
= 0; count
< vcount
; count
++)
452 *(longptr
++) = (indexCount
-2) | ((indexCount
-1)<<16);
453 *(longptr
++) = (indexCount
) | ((indexCount
)<<16);
454 *(longptr
++) = (indexCount
-1) | ((indexCount
+1)<<16);
457 ptrIndexArray
= (unsigned short*)(longptr
);
460 *ptrIndexArray
++ = indexCount
-2; // 2
461 *ptrIndexArray
++ = indexCount
-1; // 1
462 *ptrIndexArray
++ = indexCount
; // 3
471 unsigned int* longptr
= (unsigned int*) ptrIndexArray
;
473 for (int count
= 0; count
< vcount
; count
++)
475 *(longptr
++) = (indexCount
-1) | ((indexCount
-2)<<16);
476 *(longptr
++) = (indexCount
) | ((indexCount
-1)<<16);
477 *(longptr
++) = (indexCount
) | ((indexCount
+1)<<16);
481 ptrIndexArray
= (unsigned short*)(longptr
);
485 *ptrIndexArray
++ = indexCount
-1; // 2
486 *ptrIndexArray
++ = indexCount
-2; // 1
487 *ptrIndexArray
++ = indexCount
; // 3
491 vertexCount
+=(vertexCount
-vertexMark
-3)*2;
495 case GL_TRIANGLE_FAN
:
497 *ptrIndexArray
++ = indexCount
++;
498 *ptrIndexArray
++ = indexCount
++;
499 *ptrIndexArray
++ = indexCount
++;
500 int vcount
= ((vertexCount
-vertexMark
)-3);
501 for (int count
= 0; count
< vcount
; count
++)
503 *ptrIndexArray
++ = indexbase
;
504 *ptrIndexArray
++ = indexCount
-1;
505 *ptrIndexArray
++ = indexCount
++;
514 if( ptrVertexAttribArray
- vertexattribs
> 20000 * sizeof(VertexAttrib
) ||
515 ptrIndexArray
- indexArray
> 15000 * sizeof(GLushort
) )
516 FlushOnStateChange();
519 void glEnable (GLenum cap
)
521 GLboolean statechanged
= GL_FALSE
;
526 if (!nanoglState
.alpha_test
)
528 nanoglState
.alpha_test
= GL_TRUE
;
529 statechanged
= GL_TRUE
;
535 if (!nanoglState
.blend
)
537 nanoglState
.blend
= GL_TRUE
;
538 statechanged
= GL_TRUE
;
542 //case GL_CLIP_PLANEi
543 case GL_COLOR_LOGIC_OP
:
545 if (!nanoglState
.color_logic_op
)
547 nanoglState
.color_logic_op
= GL_TRUE
;
548 statechanged
= GL_TRUE
;
552 case GL_COLOR_MATERIAL
:
554 if (!nanoglState
.color_material
)
556 nanoglState
.color_material
= GL_TRUE
;
557 statechanged
= GL_TRUE
;
563 if (!nanoglState
.cull_face
)
565 nanoglState
.cull_face
= GL_TRUE
;
566 statechanged
= GL_TRUE
;
572 if (!nanoglState
.depth_test
)
574 nanoglState
.depth_test
= GL_TRUE
;
575 statechanged
= GL_TRUE
;
581 if (!nanoglState
.dither
)
583 nanoglState
.dither
= GL_TRUE
;
584 statechanged
= GL_TRUE
;
591 if (!nanoglState
.fog
)
593 nanoglState
.fog
= GL_TRUE
;
594 statechanged
= GL_TRUE
;
600 if (!nanoglState
.lighting
)
602 nanoglState
.lighting
= GL_TRUE
;
603 statechanged
= GL_TRUE
;
609 if (!nanoglState
.line_smooth
)
611 nanoglState
.line_smooth
= GL_TRUE
;
612 statechanged
= GL_TRUE
;
616 /* case GL_MATRIX_PALETTE_OES:
618 if (!nanoglState.matrix_palette_oes)
620 nanoglState.matrix_palette_oes = GL_TRUE;
621 statechanged = GL_TRUE;
627 if (!nanoglState
.multisample
)
629 nanoglState
.multisample
= GL_TRUE
;
630 statechanged
= GL_TRUE
;
636 if (!nanoglState
.normalize
)
638 nanoglState
.normalize
= GL_TRUE
;
639 statechanged
= GL_TRUE
;
643 /* case GL_POINT_SPRITE_OES:
645 if (!nanoglState.point_sprite_oes)
647 nanoglState.point_sprite_oes = GL_TRUE;
648 statechanged = GL_TRUE;
652 case GL_POLYGON_OFFSET_FILL
:
654 if (!nanoglState
.polygon_offset_fill
)
656 nanoglState
.polygon_offset_fill
= GL_TRUE
;
657 statechanged
= GL_TRUE
;
661 case GL_RESCALE_NORMAL
:
663 if (!nanoglState
.rescale_normal
)
665 nanoglState
.rescale_normal
= GL_TRUE
;
666 statechanged
= GL_TRUE
;
670 case GL_SAMPLE_ALPHA_TO_COVERAGE
:
672 if (!nanoglState
.sample_alpha_to_coverage
)
674 nanoglState
.sample_alpha_to_coverage
= GL_TRUE
;
675 statechanged
= GL_TRUE
;
679 case GL_SAMPLE_ALPHA_TO_ONE
:
681 if (!nanoglState
.sample_alpha_to_one
)
683 nanoglState
.sample_alpha_to_one
= GL_TRUE
;
684 statechanged
= GL_TRUE
;
688 case GL_SAMPLE_COVERAGE
:
690 if (!nanoglState
.sample_coverage
)
692 nanoglState
.sample_coverage
= GL_TRUE
;
693 statechanged
= GL_TRUE
;
697 case GL_SCISSOR_TEST
:
699 if (!nanoglState
.scissor_test
)
701 nanoglState
.scissor_test
= GL_TRUE
;
702 statechanged
= GL_TRUE
;
706 case GL_STENCIL_TEST
:
709 /* if (!nanoglState.stencil_test)
711 nanoglState.stencil_test = GL_TRUE;
712 statechanged = GL_TRUE;
718 if (!activetmuState
->texture_2d
.value
)
720 FlushOnStateChange();
721 glEsImpl
->glEnable(cap
);
722 activetmuState
->texture_2d
.value
= GL_TRUE
;
733 FlushOnStateChange();
734 glEsImpl
->glEnable(cap
);
738 void glDisable (GLenum cap
)
740 GLboolean statechanged
= GL_FALSE
;
745 if (nanoglState
.alpha_test
)
747 nanoglState
.alpha_test
= GL_FALSE
;
748 statechanged
= GL_TRUE
;
754 if (nanoglState
.blend
)
756 nanoglState
.blend
= GL_FALSE
;
757 statechanged
= GL_TRUE
;
761 //case GL_CLIP_PLANEi
762 case GL_COLOR_LOGIC_OP
:
764 if (nanoglState
.color_logic_op
)
766 nanoglState
.color_logic_op
= GL_FALSE
;
767 statechanged
= GL_TRUE
;
771 case GL_COLOR_MATERIAL
:
773 if (nanoglState
.color_material
)
775 nanoglState
.color_material
= GL_FALSE
;
776 statechanged
= GL_TRUE
;
782 if (nanoglState
.cull_face
)
784 nanoglState
.cull_face
= GL_FALSE
;
785 statechanged
= GL_TRUE
;
791 if (nanoglState
.depth_test
)
793 nanoglState
.depth_test
= GL_FALSE
;
794 statechanged
= GL_TRUE
;
800 if (nanoglState
.dither
)
802 nanoglState
.dither
= GL_FALSE
;
803 statechanged
= GL_TRUE
;
812 nanoglState
.fog
= GL_FALSE
;
813 statechanged
= GL_TRUE
;
819 if (nanoglState
.lighting
)
821 nanoglState
.lighting
= GL_FALSE
;
822 statechanged
= GL_TRUE
;
828 if (nanoglState
.line_smooth
)
830 nanoglState
.line_smooth
= GL_FALSE
;
831 statechanged
= GL_TRUE
;
835 /* case GL_MATRIX_PALETTE_OES:
837 if (nanoglState.matrix_palette_oes)
839 nanoglState.matrix_palette_oes = GL_FALSE;
840 statechanged = GL_TRUE;
846 if (nanoglState
.multisample
)
848 nanoglState
.multisample
= GL_FALSE
;
849 statechanged
= GL_TRUE
;
855 if (nanoglState
.normalize
)
857 nanoglState
.normalize
= GL_FALSE
;
858 statechanged
= GL_TRUE
;
862 /* case GL_POINT_SPRITE_OES:
864 if (nanoglState.point_sprite_oes)
866 nanoglState.point_sprite_oes = GL_FALSE;
867 statechanged = GL_TRUE;
871 case GL_POLYGON_OFFSET_FILL
:
873 if (nanoglState
.polygon_offset_fill
)
875 nanoglState
.polygon_offset_fill
= GL_FALSE
;
876 statechanged
= GL_TRUE
;
880 case GL_RESCALE_NORMAL
:
882 if (nanoglState
.rescale_normal
)
884 nanoglState
.rescale_normal
= GL_FALSE
;
885 statechanged
= GL_TRUE
;
889 case GL_SAMPLE_ALPHA_TO_COVERAGE
:
891 if (nanoglState
.sample_alpha_to_coverage
)
893 nanoglState
.sample_alpha_to_coverage
= GL_FALSE
;
894 statechanged
= GL_TRUE
;
898 case GL_SAMPLE_ALPHA_TO_ONE
:
900 if (nanoglState
.sample_alpha_to_one
)
902 nanoglState
.sample_alpha_to_one
= GL_FALSE
;
903 statechanged
= GL_TRUE
;
907 case GL_SAMPLE_COVERAGE
:
909 if (nanoglState
.sample_coverage
)
911 nanoglState
.sample_coverage
= GL_FALSE
;
912 statechanged
= GL_TRUE
;
916 case GL_SCISSOR_TEST
:
918 if (nanoglState
.scissor_test
)
920 nanoglState
.scissor_test
= GL_FALSE
;
921 statechanged
= GL_TRUE
;
925 case GL_STENCIL_TEST
:
928 /* if (nanoglState.stencil_test)
930 nanoglState.stencil_test = GL_FALSE;
931 statechanged = GL_TRUE;
937 if (activetmuState
->texture_2d
.value
)
939 FlushOnStateChange();
940 glEsImpl
->glDisable(cap
);
941 activetmuState
->texture_2d
.value
= GL_FALSE
;
954 FlushOnStateChange();
955 glEsImpl
->glDisable(cap
);
959 void glVertex2f(GLfloat x
, GLfloat y
)
961 glVertex3f(x
,y
,0.0f
);
965 __FORCEINLINE
unsigned int ClampTo255(float value
)
967 unsigned int retval
= (unsigned int)(value
);
975 void glColor3f( GLfloat red
, GLfloat green
, GLfloat blue
)
977 currentVertexAttrib
.red
= (unsigned char)ClampTo255(red
*255.0f
);
978 currentVertexAttrib
.green
= (unsigned char)ClampTo255(green
*255.0f
);
979 currentVertexAttrib
.blue
= (unsigned char)ClampTo255(blue
*255.0f
);
980 currentVertexAttrib
.alpha
= 255;
984 void glTexCoord2fv( const GLfloat
*v
)
986 memcpy(¤tVertexAttrib
.s
, v
, 2*sizeof(float));
990 void glTexCoord2f(GLfloat s
, GLfloat t
)
992 currentVertexAttrib
.s
= s
;
993 currentVertexAttrib
.t
= t
;
996 void glViewport (GLint x
, GLint y
, GLsizei width
, GLsizei height
)
998 FlushOnStateChange();
999 glEsImpl
->glViewport(x
,y
,width
,height
);
1002 void glLoadIdentity (void)
1004 FlushOnStateChange();
1005 glEsImpl
->glLoadIdentity();
1008 void glColor4f (GLfloat red
, GLfloat green
, GLfloat blue
, GLfloat alpha
)
1010 currentVertexAttrib
.red
= (unsigned char)ClampTo255(red
*255.0f
);
1011 currentVertexAttrib
.green
= (unsigned char)ClampTo255(green
*255.0f
);
1012 currentVertexAttrib
.blue
= (unsigned char)ClampTo255(blue
*255.0f
);
1013 currentVertexAttrib
.alpha
= (unsigned char)ClampTo255(alpha
*255.0f
);
1016 void glOrtho (GLfloat left
, GLfloat right
, GLfloat bottom
, GLfloat top
, GLfloat zNear
, GLfloat zFar
)
1018 FlushOnStateChange();
1019 #ifdef USE_CORE_PROFILE
1020 glEsImpl
->glOrtho(left
,right
,bottom
,top
, zNear
,zFar
);
1022 glEsImpl
->glOrthof(left
,right
,bottom
,top
, zNear
,zFar
);
1026 void glMatrixMode (GLenum mode
)
1028 if (nanoglState
.matrixmode
== mode
)
1032 nanoglState
.matrixmode
= mode
;
1033 FlushOnStateChange();
1034 glEsImpl
->glMatrixMode(mode
);
1037 void glTexParameterf (GLenum target
, GLenum pname
, GLfloat param
)
1039 if (pname
== GL_TEXTURE_BORDER_COLOR
)
1041 return; // not supported by opengl es
1043 if ( (pname
== GL_TEXTURE_WRAP_S
||
1044 pname
== GL_TEXTURE_WRAP_T
) &&
1050 FlushOnStateChange();
1051 glEsImpl
->glTexParameterf(target
, pname
,param
);
1054 void glTexParameterfv( GLenum target
, GLenum pname
, const GLfloat
*params
)
1056 glTexParameterf(target
, pname
, params
[0]);
1059 void glTexImage2D (GLenum target
, GLint level
, GLint internalformat
, GLsizei width
, GLsizei height
, GLint border
, GLenum format
, GLenum type
, const GLvoid
*pixels
)
1061 FlushOnStateChange();
1062 internalformat
= format
;
1063 glEsImpl
->glTexImage2D(target
, level
, internalformat
, width
, height
,border
,format
,type
,pixels
);
1066 void glDrawBuffer(GLenum
/*mode*/)
1070 void glTranslatef (GLfloat x
, GLfloat y
, GLfloat z
)
1072 FlushOnStateChange();
1073 glEsImpl
->glTranslatef(x
,y
,z
);
1076 void glRotatef (GLfloat angle
, GLfloat x
, GLfloat y
, GLfloat z
)
1078 FlushOnStateChange();
1079 glEsImpl
->glRotatef(angle
, x
, y
, z
);
1082 void glScalef (GLfloat x
, GLfloat y
, GLfloat z
)
1084 FlushOnStateChange();
1085 glEsImpl
->glScalef(x
,y
,z
);
1088 void glDepthRange(GLclampf zNear
, GLclampf zFar
)
1090 if ((nanoglState
.depth_range_near
== zNear
) &&(nanoglState
.depth_range_far
== zFar
))
1096 nanoglState
.depth_range_near
= zNear
;
1097 nanoglState
.depth_range_far
= zFar
;
1099 FlushOnStateChange();
1100 #ifdef USE_CORE_PROFILE
1101 glEsImpl
->glDepthRange(zNear
, zFar
);
1103 glEsImpl
->glDepthRangef(zNear
, zFar
);
1107 void glDepthFunc (GLenum func
)
1109 if (nanoglState
.depth_func
== func
)
1115 nanoglState
.depth_func
= func
;
1117 FlushOnStateChange();
1118 glEsImpl
->glDepthFunc(func
);
1121 void glFinish (void)
1123 FlushOnStateChange();
1124 glEsImpl
->glFinish();
1127 void glGetFloatv (GLenum pname
, GLfloat
*params
)
1129 FlushOnStateChange();
1130 glEsImpl
->glGetFloatv(pname
, params
);
1133 void glCullFace (GLenum mode
)
1135 if (nanoglState
.cullface
== mode
)
1141 nanoglState
.cullface
= mode
;
1143 FlushOnStateChange();
1144 glEsImpl
->glCullFace(mode
);
1147 void glFrustum (GLfloat left
, GLfloat right
, GLfloat bottom
, GLfloat top
, GLfloat zNear
, GLfloat zFar
)
1149 FlushOnStateChange();
1150 glEsImpl
->glFrustumf(left
,right
,bottom
,top
,zNear
,zFar
);
1153 void glClear (GLbitfield mask
)
1155 FlushOnStateChange();
1156 glEsImpl
->glClear(mask
);
1160 void glVertex3f( GLfloat x
, GLfloat y
, GLfloat z
)
1162 GLfloat
* vert
= (GLfloat
*)ptrVertexAttribArray
++;
1166 #if defined(__MULTITEXTURE_SUPPORT__)
1167 memcpy(vert
, ¤tVertexAttrib
.red
, 5*sizeof(GLfloat
));
1169 memcpy(vert
+1, ¤tVertexAttrib
.red
, 3*sizeof(GLfloat
));
1174 void glColor4fv( const GLfloat
*v
)
1176 currentVertexAttrib
.red
= (unsigned char)ClampTo255(v
[0]*255.0f
);
1177 currentVertexAttrib
.green
= (unsigned char)ClampTo255(v
[1]*255.0f
);
1178 currentVertexAttrib
.blue
= (unsigned char)ClampTo255(v
[2]*255.0f
);
1179 currentVertexAttrib
.alpha
= (unsigned char)ClampTo255(v
[3]*255.0f
);
1182 void glColor3ubv( const GLubyte
* v
)
1184 currentVertexAttrib
.red
= v
[0];
1185 currentVertexAttrib
.green
= v
[1];
1186 currentVertexAttrib
.blue
= v
[2];
1187 currentVertexAttrib
.alpha
= 255;
1190 void glColor4ubv( const GLubyte
*v
)
1192 //*((unsigned int*)(¤tVertexAttrib.red)) = *((unsigned int*)(v));
1193 currentVertexAttrib
.red
= v
[0];
1194 currentVertexAttrib
.green
= v
[1];
1195 currentVertexAttrib
.blue
= v
[2];
1196 currentVertexAttrib
.alpha
= v
[3];
1199 void glColor3fv( const GLfloat
*v
)
1201 currentVertexAttrib
.red
= (unsigned char)ClampTo255(v
[0]*255.0f
);
1202 currentVertexAttrib
.green
= (unsigned char)ClampTo255(v
[1]*255.0f
);
1203 currentVertexAttrib
.blue
= (unsigned char)ClampTo255(v
[2]*255.0f
);
1204 currentVertexAttrib
.alpha
= 255;
1207 //-- nicknekit: xash3d funcs --
1209 void glColor4ub( GLubyte red
, GLubyte green
, GLubyte blue
, GLubyte alpha
)
1211 currentVertexAttrib
.red
= red
;
1212 currentVertexAttrib
.green
= green
;
1213 currentVertexAttrib
.blue
= blue
;
1214 currentVertexAttrib
.alpha
= alpha
;
1217 void glColor3ub( GLubyte red
, GLubyte green
, GLubyte blue
)
1219 currentVertexAttrib
.red
= red
;
1220 currentVertexAttrib
.green
= green
;
1221 currentVertexAttrib
.blue
= blue
;
1222 currentVertexAttrib
.alpha
= 255;
1225 void glNormal3fv( const GLfloat
*v
)
1227 FlushOnStateChange();
1228 glEsImpl
->glNormal3f(v
[0],v
[1],v
[2]);
1231 void glCopyTexImage2D( GLenum target
, GLint level
, GLenum internalformat
, GLint x
, GLint y
, GLsizei width
, GLsizei height
, GLint border
)
1233 FlushOnStateChange();
1234 glEsImpl
->glCopyTexImage2D(target
, level
, internalformat
, x
, y
, width
, height
, border
);
1237 void glTexImage1D(GLenum target
, GLint level
, GLint internalformat
, GLsizei width
, GLint border
, GLenum format
, GLenum type
, const GLvoid
*pixels
)
1239 glTexImage2D(GL_TEXTURE_2D
, level
, internalformat
, width
, 1, border
, format
, type
, pixels
);
1242 void glTexImage3D(GLenum target
, GLint level
, GLint internalformat
, GLsizei width
, GLsizei height
, GLsizei depth
, GLint border
, GLenum format
, GLenum type
, const GLvoid
*pixels
)
1244 glTexImage2D(GL_TEXTURE_2D
, level
, internalformat
, width
, height
, border
, format
, type
, pixels
);
1247 void glTexSubImage1D( GLenum target
, GLint level
, GLint xoffset
, GLsizei width
, GLenum format
, GLenum type
, const GLvoid
*pixels
)
1249 glTexSubImage2D(target
,level
,xoffset
,0,width
,1,format
,type
,pixels
);
1252 void glTexSubImage3D( GLenum target
, GLint level
,
1253 GLint xoffset
, GLint yoffset
,
1254 GLint zoffset
, GLsizei width
,
1255 GLsizei height
, GLsizei depth
,
1257 GLenum type
, const GLvoid
*pixels
)
1259 glTexSubImage2D(target
,level
,xoffset
,yoffset
,width
,height
,format
,type
,pixels
);
1264 GLboolean
glIsTexture(GLuint texture
)
1266 FlushOnStateChange();
1267 return glEsImpl
->glIsTexture(texture
);
1271 void glTexGeni( GLenum coord
, GLenum pname
, GLint param
)
1273 //for mirrors? not needed for original hl?
1276 void glTexGenfv( GLenum coord
, GLenum pname
, const GLfloat
*params
)
1278 //for mirrors? not needed for original hl?
1283 void glHint (GLenum target
, GLenum mode
)
1285 FlushOnStateChange();
1286 glEsImpl
->glHint(target
, mode
);
1289 void glBlendFunc (GLenum sfactor
, GLenum dfactor
)
1291 if ((nanoglState
.sfactor
== sfactor
) && (nanoglState
.dfactor
== dfactor
))
1295 nanoglState
.sfactor
= sfactor
;
1296 nanoglState
.dfactor
= dfactor
;
1297 FlushOnStateChange();
1298 glEsImpl
->glBlendFunc(sfactor
, dfactor
);
1301 void glPopMatrix (void)
1303 FlushOnStateChange();
1304 glEsImpl
->glPopMatrix();
1307 void glShadeModel (GLenum mode
)
1309 if (nanoglState
.shademodel
== mode
)
1313 nanoglState
.shademodel
= mode
;
1314 FlushOnStateChange();
1315 glEsImpl
->glShadeModel(mode
);
1318 void glPushMatrix (void)
1320 FlushOnStateChange();
1321 glEsImpl
->glPushMatrix();
1324 void glTexEnvf (GLenum target
, GLenum pname
, GLfloat param
)
1326 if (target
== GL_TEXTURE_ENV
)
1328 if (pname
== GL_TEXTURE_ENV_MODE
)
1330 if (param
== activetmuState
->texture_env_mode
.value
)
1336 FlushOnStateChange();
1337 glEsImpl
->glTexEnvf(target
, pname
, param
);
1338 activetmuState
->texture_env_mode
.value
= param
;
1343 FlushOnStateChange();
1344 glEsImpl
->glTexEnvf(target
, pname
, param
);
1347 void glVertex3fv( const GLfloat
*v
)
1349 GLfloat
* vert
= (GLfloat
*)ptrVertexAttribArray
++;
1350 memcpy(vert
, v
, 3*sizeof(GLfloat
));
1351 #if defined(__MULTITEXTURE_SUPPORT__)
1352 memcpy(vert
+3, ¤tVertexAttrib
.red
, 5*sizeof(GLfloat
));
1354 memcpy(vert
+4, ¤tVertexAttrib
.red
, 3*sizeof(GLfloat
));
1359 void glDepthMask (GLboolean flag
)
1361 if (nanoglState
.depthmask
== flag
)
1365 nanoglState
.depthmask
= flag
;
1366 FlushOnStateChange();
1367 glEsImpl
->glDepthMask(flag
);
1370 void glBindTexture (GLenum target
, GLuint texture
)
1372 if (activetmuState
->boundtexture
.value
== texture
)
1376 FlushOnStateChange();
1377 activetmuState
->boundtexture
.value
= texture
;
1378 glEsImpl
->glBindTexture(target
, texture
);
1382 void glGetIntegerv (GLenum pname
, GLint
*params
)
1384 FlushOnStateChange();
1385 glEsImpl
->glGetIntegerv(pname
, params
);
1388 GLubyte nano_extensions_string
[4096];
1389 const GLubyte
* glGetString (GLenum name
)
1392 if (name
== GL_EXTENSIONS
)
1394 #if defined(__MULTITEXTURE_SUPPORT__)
1395 sprintf((char*)nano_extensions_string
,"%s %s",glEsImpl
->glGetString(name
),"GL_ARB_multitexture EXT_texture_env_add");
1397 sprintf((char*)nano_extensions_string
,"%s %s",glEsImpl
->glGetString(name
),"EXT_texture_env_add");
1399 return nano_extensions_string
;
1401 return glEsImpl
->glGetString(name
);
1404 void glAlphaFunc (GLenum func
, GLclampf ref
)
1406 FlushOnStateChange();
1407 glEsImpl
->glAlphaFunc(func
,ref
);
1412 FlushOnStateChange();
1413 glEsImpl
->glFlush();
1416 void glReadPixels (GLint x
, GLint y
, GLsizei width
, GLsizei height
, GLenum format
, GLenum type
, GLvoid
*pixels
)
1418 if (format
== GL_DEPTH_COMPONENT
)
1420 // OpenglEs 1.1 does not support reading depth buffer without an extension
1421 memset(pixels
, 0xff,4);
1424 FlushOnStateChange();
1425 glEsImpl
->glReadPixels(x
,y
,width
,height
,format
,type
,pixels
);
1428 void glReadBuffer( GLenum
/*mode*/ )
1433 void glLoadMatrixf (const GLfloat
*m
)
1435 FlushOnStateChange();
1436 glEsImpl
->glLoadMatrixf(m
);
1439 void glTexSubImage2D (GLenum target
, GLint level
, GLint xoffset
, GLint yoffset
, GLsizei width
, GLsizei height
, GLenum format
, GLenum type
, const GLvoid
*pixels
)
1441 FlushOnStateChange();
1442 glEsImpl
->glTexSubImage2D(target
,level
,xoffset
,yoffset
,width
,height
,format
,type
,pixels
);
1445 void glClearColor (GLclampf red
, GLclampf green
, GLclampf blue
, GLclampf alpha
)
1447 FlushOnStateChange();
1448 glEsImpl
->glClearColor(red
,green
,blue
,alpha
);
1451 GLenum
glGetError (void)
1453 //FlushOnStateChange();
1454 return GL_NO_ERROR
;//glEsImpl->glGetError();
1457 void glActiveTexture (GLenum texture
)
1459 if (activetmu
== texture
)
1463 if (delayedttmuchange
)
1465 delayedttmuchange
= GL_FALSE
;
1469 delayedttmuchange
= GL_TRUE
;
1470 delayedtmutarget
= texture
;
1472 if (texture
== GL_TEXTURE0
)
1474 activetmuState
= &tmuState0
;
1478 activetmuState
= &tmuState1
;
1480 activetmu
= texture
;
1483 void glClientActiveTexture (GLenum texture
)
1485 clientactivetmu
= texture
;
1488 void glPolygonMode( GLenum face
, GLenum mode
)
1492 void glDeleteTextures( GLsizei n
, const GLuint
*textures
)
1494 FlushOnStateChange();
1495 glEsImpl
->glDeleteTextures(n
,textures
);
1498 void glClearDepth( GLclampf depth
)
1500 FlushOnStateChange();
1501 glEsImpl
->glClearDepthf( depth
);
1504 void glClipPlane( GLenum plane
, const GLdouble
*equation
)
1506 FlushOnStateChange();
1508 array
[0] = (GLfloat
)(equation
[0]);
1509 array
[1] = (GLfloat
)(equation
[1]);
1510 array
[2] = (GLfloat
)(equation
[2]);
1511 array
[3] = (GLfloat
)(equation
[3]);
1512 glEsImpl
->glClipPlanef( plane
, array
);
1515 void glScissor( GLint x
, GLint y
, GLsizei width
, GLsizei height
)
1517 FlushOnStateChange();
1518 glEsImpl
->glScissor( x
, y
, width
,height
);
1521 void glPointSize( GLfloat size
)
1523 FlushOnStateChange();
1524 glEsImpl
->glPointSize( size
);
1527 void glArrayElement(GLint i
) {}
1528 void glLineWidth(GLfloat width
) {}
1529 void glCallList( GLuint list
) {}
1530 void glColorMask( GLboolean red
, GLboolean green
, GLboolean blue
, GLboolean alpha
) {}
1531 void glStencilFunc( GLenum func
, GLint ref
, GLuint mask
) {}
1532 void glStencilOp( GLenum fail
, GLenum zfail
, GLenum zpass
) {}
1534 struct ptrstate vertex_array
;
1535 struct ptrstate color_array
;
1536 struct ptrstate texture_coord_array
;
1538 void glDrawElements( GLenum mode
, GLsizei count
, GLenum type
, const GLvoid
*indices
)
1540 // ensure that all primitives specified between glBegin/glEnd pairs
1541 // are rendered first, and that we have correct tmu in use..
1542 FlushOnStateChange();
1543 // setup correct vertex/color/texcoord pointers
1545 tmuState0
.vertex_array
.changed
||
1546 tmuState0
.color_array
.changed
||
1547 tmuState0
.texture_coord_array
.changed
|| tmuState0
.normal_array
.changed
)
1549 glEsImpl
->glClientActiveTexture(GL_TEXTURE0
);
1551 if (arraysValid
|| tmuState0
.vertex_array
.changed
)
1553 if (tmuState0
.vertex_array
.enabled
)
1555 glEsImpl
->glEnableClientState(GL_VERTEX_ARRAY
);
1559 glEsImpl
->glDisableClientState(GL_VERTEX_ARRAY
);
1561 glEsImpl
->glVertexPointer(tmuState0
.vertex_array
.size
,
1562 tmuState0
.vertex_array
.type
,
1563 tmuState0
.vertex_array
.stride
,
1564 tmuState0
.vertex_array
.ptr
);
1565 tmuState0
.vertex_array
.changed
= GL_FALSE
;
1567 if (arraysValid
|| tmuState0
.color_array
.changed
)
1569 if (tmuState0
.color_array
.enabled
)
1571 glEsImpl
->glEnableClientState(GL_COLOR_ARRAY
);
1575 glEsImpl
->glDisableClientState(GL_COLOR_ARRAY
);
1577 glEsImpl
->glColorPointer(tmuState0
.color_array
.size
,
1578 tmuState0
.color_array
.type
,
1579 tmuState0
.color_array
.stride
,
1580 tmuState0
.color_array
.ptr
);
1581 tmuState0
.color_array
.changed
= GL_FALSE
;
1583 if (arraysValid
|| tmuState0
.normal_array
.changed
)
1585 if (tmuState0
.normal_array
.enabled
)
1587 glEsImpl
->glEnableClientState(GL_NORMAL_ARRAY
);
1591 glEsImpl
->glDisableClientState(GL_NORMAL_ARRAY
);
1593 glEsImpl
->glNormalPointer(tmuState0
.normal_array
.type
,
1594 tmuState0
.normal_array
.stride
,
1595 tmuState0
.normal_array
.ptr
);
1596 tmuState0
.normal_array
.changed
= GL_FALSE
;
1598 if (arraysValid
|| tmuState0
.texture_coord_array
.changed
)
1600 tmuState0
.texture_coord_array
.changed
= GL_FALSE
;
1601 if (tmuState0
.texture_coord_array
.enabled
)
1603 glEsImpl
->glEnableClientState(GL_TEXTURE_COORD_ARRAY
);
1607 glEsImpl
->glDisableClientState(GL_TEXTURE_COORD_ARRAY
);
1609 glEsImpl
->glTexCoordPointer(tmuState0
.texture_coord_array
.size
,
1610 tmuState0
.texture_coord_array
.type
,
1611 tmuState0
.texture_coord_array
.stride
,
1612 tmuState0
.texture_coord_array
.ptr
);
1615 if (arraysValid
|| tmuState1
.texture_coord_array
.changed
)
1617 tmuState1
.texture_coord_array
.changed
= GL_FALSE
;
1618 glEsImpl
->glClientActiveTexture(GL_TEXTURE1
);
1619 if (tmuState1
.texture_coord_array
.enabled
)
1621 glEsImpl
->glEnableClientState(GL_TEXTURE_COORD_ARRAY
);
1625 glEsImpl
->glDisableClientState(GL_TEXTURE_COORD_ARRAY
);
1627 glEsImpl
->glTexCoordPointer(tmuState1
.texture_coord_array
.size
,
1628 tmuState1
.texture_coord_array
.type
,
1629 tmuState1
.texture_coord_array
.stride
,
1630 tmuState1
.texture_coord_array
.ptr
);
1633 arraysValid
= GL_FALSE
;
1634 glEsImpl
->glDrawElements(mode
, count
, type
, indices
);
1637 void glEnableClientState(GLenum array
)
1639 struct nanotmuState
* clientstate
= NULL
;
1640 if (clientactivetmu
== GL_TEXTURE0
)
1642 clientstate
= &tmuState0
;
1644 else if (clientactivetmu
== GL_TEXTURE1
)
1646 clientstate
= &tmuState1
;
1654 case GL_VERTEX_ARRAY
:
1655 if (clientstate
->vertex_array
.enabled
)
1659 clientstate
->vertex_array
.enabled
= GL_TRUE
;
1660 clientstate
->vertex_array
.changed
= GL_TRUE
;
1662 case GL_COLOR_ARRAY
:
1663 if (clientstate
->color_array
.enabled
)
1667 clientstate
->color_array
.enabled
= GL_TRUE
;
1668 clientstate
->color_array
.changed
= GL_TRUE
;
1671 case GL_NORMAL_ARRAY
:
1672 if (clientstate
->normal_array
.enabled
)
1676 clientstate
->normal_array
.enabled
= GL_TRUE
;
1677 clientstate
->normal_array
.changed
= GL_TRUE
;
1680 case GL_TEXTURE_COORD_ARRAY
:
1681 if (clientstate
->texture_coord_array
.enabled
)
1685 clientstate
->texture_coord_array
.enabled
= GL_TRUE
;
1686 clientstate
->texture_coord_array
.changed
= GL_TRUE
;
1692 void glDisableClientState(GLenum array
)
1694 struct nanotmuState
* clientstate
= NULL
;
1695 if (clientactivetmu
== GL_TEXTURE0
)
1697 clientstate
= &tmuState0
;
1699 else if (clientactivetmu
== GL_TEXTURE1
)
1701 clientstate
= &tmuState1
;
1709 case GL_VERTEX_ARRAY
:
1710 if (!clientstate
->vertex_array
.enabled
)
1714 clientstate
->vertex_array
.enabled
= GL_FALSE
;
1715 clientstate
->vertex_array
.changed
= GL_TRUE
;
1717 case GL_COLOR_ARRAY
:
1718 if (!clientstate
->color_array
.enabled
)
1722 clientstate
->color_array
.enabled
= GL_FALSE
;
1723 clientstate
->color_array
.changed
= GL_TRUE
;
1726 case GL_NORMAL_ARRAY
:
1727 if (!clientstate
->normal_array
.enabled
)
1731 clientstate
->normal_array
.enabled
= GL_FALSE
;
1732 clientstate
->normal_array
.changed
= GL_TRUE
;
1735 case GL_TEXTURE_COORD_ARRAY
:
1736 if (!clientstate
->texture_coord_array
.enabled
)
1740 clientstate
->texture_coord_array
.enabled
= GL_FALSE
;
1741 clientstate
->texture_coord_array
.changed
= GL_TRUE
;
1747 void glVertexPointer( GLint size
, GLenum type
,GLsizei stride
, const GLvoid
*pointer
)
1749 if (tmuState0
.vertex_array
.size
== size
&&
1750 tmuState0
.vertex_array
.stride
== stride
&&
1751 tmuState0
.vertex_array
.type
== type
&&
1752 tmuState0
.vertex_array
.ptr
== pointer
)
1756 tmuState0
.vertex_array
.size
= size
;
1757 tmuState0
.vertex_array
.stride
= stride
;
1758 tmuState0
.vertex_array
.type
= type
;
1759 tmuState0
.vertex_array
.ptr
= (GLvoid
*)pointer
;
1760 tmuState0
.vertex_array
.changed
= GL_TRUE
;
1762 void glTexCoordPointer( GLint size
, GLenum type
, GLsizei stride
, const GLvoid
*pointer
)
1764 struct nanotmuState
* clientstate
= NULL
;
1765 if (clientactivetmu
== GL_TEXTURE0
)
1767 clientstate
= &tmuState0
;
1769 else if (clientactivetmu
== GL_TEXTURE1
)
1771 clientstate
= &tmuState1
;
1773 if (clientstate
->texture_coord_array
.size
== size
&&
1774 clientstate
->texture_coord_array
.stride
== stride
&&
1775 clientstate
->texture_coord_array
.type
== type
&&
1776 clientstate
->texture_coord_array
.ptr
== pointer
)
1780 clientstate
->texture_coord_array
.size
= size
;
1781 clientstate
->texture_coord_array
.stride
= stride
;
1782 clientstate
->texture_coord_array
.type
= type
;
1783 clientstate
->texture_coord_array
.ptr
= (GLvoid
*)pointer
;
1784 clientstate
->texture_coord_array
.changed
= GL_TRUE
;
1786 void glColorPointer( GLint size
, GLenum type
, GLsizei stride
, const GLvoid
*pointer
)
1788 if (tmuState0
.color_array
.size
== size
&&
1789 tmuState0
.color_array
.stride
== stride
&&
1790 tmuState0
.color_array
.type
== type
&&
1791 tmuState0
.color_array
.ptr
== pointer
)
1795 tmuState0
.color_array
.size
= size
;
1796 tmuState0
.color_array
.stride
= stride
;
1797 tmuState0
.color_array
.type
= type
;
1798 tmuState0
.color_array
.ptr
= (GLvoid
*)pointer
;
1799 tmuState0
.color_array
.changed
= GL_TRUE
;
1802 void glNormalPointer( GLenum type
, GLsizei stride
, const GLvoid
*pointer
)
1805 if (tmuState0
.normal_array
.size
== size
&&
1806 tmuState0
.normal_array
.stride
== stride
&&
1807 tmuState0
.normal_array
.type
== type
&&
1808 tmuState0
.normal_array
.ptr
== pointer
)
1812 tmuState0
.normal_array
.size
= size
;
1813 tmuState0
.normal_array
.stride
= stride
;
1814 tmuState0
.normal_array
.type
= type
;
1815 tmuState0
.normal_array
.ptr
= (GLvoid
*)pointer
;
1816 tmuState0
.normal_array
.changed
= GL_TRUE
;
1818 void glPolygonOffset( GLfloat factor
, GLfloat units
)
1820 FlushOnStateChange();
1821 glEsImpl
->glPolygonOffset(factor
, units
);
1823 void glStencilMask( GLuint mask
) {}
1824 void glClearStencil( GLint s
) {}
1826 #if defined(__MULTITEXTURE_SUPPORT__)
1828 extern "C" void glMultiTexCoord2fARB( GLenum target
, GLfloat s
, GLfloat t
);
1830 void glMultiTexCoord2fARB( GLenum target
, GLfloat s
, GLfloat t
)
1832 if (target
== GL_TEXTURE0
)
1838 currentVertexAttrib
.s_multi
= s
;
1839 currentVertexAttrib
.t_multi
= t
;
1845 /*void glDrawArrays( GLenum mode, int first, int count)
1847 FlushOnStateChange();
1848 glEsImpl->glDrawArrays(mode, first , count);
1850 void glMultMatrixf (const GLfloat
*m
)
1852 FlushOnStateChange();
1853 glEsImpl
->glMultMatrixf(m
);
1856 void glPixelStorei (GLenum pname
, GLint param
)
1858 FlushOnStateChange();
1859 glEsImpl
->glPixelStorei(pname
, param
);
1863 void glFogf (GLenum pname
, GLfloat param
)
1865 FlushOnStateChange();
1866 glEsImpl
->glFogf(pname
, param
);
1869 void glFogfv (GLenum pname
, const GLfloat
*params
)
1871 FlushOnStateChange();
1872 glEsImpl
->glFogfv(pname
, params
);
1875 void glGetTexParameteriv (GLenum target
, GLenum pname
, GLint
*params
)
1877 FlushOnStateChange();
1878 glEsImpl
->glGetTexParameteriv(target
, pname
, params
);
1882 // This gives: called unimplemented OpenGL ES API (Android)
1883 void glTexParameteri (GLenum target
, GLenum pname
, GLint param
)
1885 if (pname
== GL_TEXTURE_BORDER_COLOR
) {
1886 return; // not supported by opengl es
1888 if ( (pname
== GL_TEXTURE_WRAP_S
||
1889 pname
== GL_TEXTURE_WRAP_T
) &&
1890 param
== GL_CLAMP
) {
1894 FlushOnStateChange();
1895 glEsImpl
->glTexParameteri(target
, pname
, param
);
1898 void glTexParameterx (GLenum target
, GLenum pname
, GLfixed param
)
1900 if (pname
== GL_TEXTURE_BORDER_COLOR
) {
1901 return; // not supported by opengl es
1903 if ( (pname
== GL_TEXTURE_WRAP_S
||
1904 pname
== GL_TEXTURE_WRAP_T
) &&
1905 param
== GL_CLAMP
) {
1908 FlushOnStateChange();
1909 glEsImpl
->glTexParameterx(target
, pname
, param
);
1912 void glGenTextures (GLsizei n
, GLuint
*textures
)
1914 FlushOnStateChange();
1915 glEsImpl
->glGenTextures(n
, textures
);
1918 void glFrontFace (GLenum mode
)
1920 FlushOnStateChange();
1921 glEsImpl
->glFrontFace(mode
);
1925 void glTexEnvi (GLenum target
, GLenum pname
, GLint param
)
1927 if (target
== GL_TEXTURE_ENV
)
1929 if (pname
== GL_TEXTURE_ENV_MODE
)
1931 if (param
== activetmuState
->texture_env_mode
.value
)
1937 FlushOnStateChange();
1938 glEsImpl
->glTexEnvi(target
, pname
, param
);
1939 activetmuState
->texture_env_mode
.value
= param
;
1944 FlushOnStateChange();
1945 glEsImpl
->glTexEnvi(target
, pname
, param
);
1948 #ifdef __MULTITEXTURE_SUPPORT__
1949 void glMultiTexCoord3fARB(GLenum a
, GLfloat b
, GLfloat c
, GLfloat
)
1951 return glMultiTexCoord2fARB(a
, b
, c
);
1954 void glMultiTexCoord2f(GLenum
, GLfloat
, GLfloat
)
1959 void glDrawArrays( GLenum mode
, GLint first
, GLsizei count
)
1961 // ensure that all primitives specified between glBegin/glEnd pairs
1962 // are rendered first, and that we have correct tmu in use..
1963 if( mode
== GL_QUADS
) mode
= GL_TRIANGLE_FAN
;
1964 FlushOnStateChange();
1965 // setup correct vertex/color/texcoord pointers
1967 tmuState0
.vertex_array
.changed
||
1968 tmuState0
.color_array
.changed
||
1969 tmuState0
.texture_coord_array
.changed
|| tmuState0
.normal_array
.changed
)
1971 glEsImpl
->glClientActiveTexture(GL_TEXTURE0
);
1973 if (arraysValid
|| tmuState0
.vertex_array
.changed
)
1975 if (tmuState0
.vertex_array
.enabled
)
1977 glEsImpl
->glEnableClientState(GL_VERTEX_ARRAY
);
1981 glEsImpl
->glDisableClientState(GL_VERTEX_ARRAY
);
1983 glEsImpl
->glVertexPointer(tmuState0
.vertex_array
.size
,
1984 tmuState0
.vertex_array
.type
,
1985 tmuState0
.vertex_array
.stride
,
1986 tmuState0
.vertex_array
.ptr
);
1987 tmuState0
.vertex_array
.changed
= GL_FALSE
;
1989 if (arraysValid
|| tmuState0
.color_array
.changed
)
1991 if (tmuState0
.color_array
.enabled
)
1993 glEsImpl
->glEnableClientState(GL_COLOR_ARRAY
);
1997 glEsImpl
->glDisableClientState(GL_COLOR_ARRAY
);
1999 glEsImpl
->glColorPointer(tmuState0
.color_array
.size
,
2000 tmuState0
.color_array
.type
,
2001 tmuState0
.color_array
.stride
,
2002 tmuState0
.color_array
.ptr
);
2003 tmuState0
.color_array
.changed
= GL_FALSE
;
2005 if (arraysValid
|| tmuState0
.normal_array
.changed
)
2007 if (tmuState0
.normal_array
.enabled
)
2009 glEsImpl
->glEnableClientState(GL_NORMAL_ARRAY
);
2013 glEsImpl
->glDisableClientState(GL_NORMAL_ARRAY
);
2015 glEsImpl
->glNormalPointer(tmuState0
.normal_array
.type
,
2016 tmuState0
.normal_array
.stride
,
2017 tmuState0
.normal_array
.ptr
);
2018 tmuState0
.normal_array
.changed
= GL_FALSE
;
2020 if (arraysValid
|| tmuState0
.texture_coord_array
.changed
)
2022 tmuState0
.texture_coord_array
.changed
= GL_FALSE
;
2023 if (tmuState0
.texture_coord_array
.enabled
)
2025 glEsImpl
->glEnableClientState(GL_TEXTURE_COORD_ARRAY
);
2029 glEsImpl
->glDisableClientState(GL_TEXTURE_COORD_ARRAY
);
2031 glEsImpl
->glTexCoordPointer(tmuState0
.texture_coord_array
.size
,
2032 tmuState0
.texture_coord_array
.type
,
2033 tmuState0
.texture_coord_array
.stride
,
2034 tmuState0
.texture_coord_array
.ptr
);
2037 if (arraysValid
|| tmuState1
.texture_coord_array
.changed
)
2039 tmuState1
.texture_coord_array
.changed
= GL_FALSE
;
2040 glEsImpl
->glClientActiveTexture(GL_TEXTURE1
);
2041 if (tmuState1
.texture_coord_array
.enabled
)
2043 glEsImpl
->glEnableClientState(GL_TEXTURE_COORD_ARRAY
);
2047 glEsImpl
->glDisableClientState(GL_TEXTURE_COORD_ARRAY
);
2049 glEsImpl
->glTexCoordPointer(tmuState1
.texture_coord_array
.size
,
2050 tmuState1
.texture_coord_array
.type
,
2051 tmuState1
.texture_coord_array
.stride
,
2052 tmuState1
.texture_coord_array
.ptr
);
2055 arraysValid
= GL_FALSE
;
2056 glEsImpl
->glDrawArrays(mode
, first
, count
);
2058 /*void glNormalPointer(GLenum type, GLsizei stride, const void *ptr)
2060 glEsImpl->glNormalPointer( type, stride, ptr );
2063 void glCopyTexSubImage2D(GLenum target
, GLint level
, GLint xoffset
, GLint yoffset
, GLint x
, GLint y
, GLsizei width
, GLsizei height
)
2065 FlushOnStateChange();
2066 glEsImpl
->glCopyTexSubImage2D( target
, level
, xoffset
, yoffset
, x
, y
, width
, height
);
2069 void glGenFramebuffers (GLsizei n
, GLuint
* framebuffers
)
2071 FlushOnStateChange();
2072 glEsImpl
->glGenFramebuffers( n
, framebuffers
);
2076 void glGenRenderbuffers( GLsizei n
, GLuint
* renderbuffers
)
2078 FlushOnStateChange();
2079 glEsImpl
->glGenRenderbuffers( n
, renderbuffers
);
2082 void glBindRenderbuffer(GLenum target
, GLuint renderbuffer
)
2084 FlushOnStateChange();
2085 glEsImpl
->glBindRenderbuffer( target
, renderbuffer
);
2088 void glBindFramebuffer(GLenum target
, GLuint framebuffer
)\
2090 FlushOnStateChange();
2091 glEsImpl
->glBindFramebuffer( target
, framebuffer
);
2094 void glFramebufferRenderbuffer(GLenum target
, GLenum attachment
, GLenum renderbuffertarget
, GLuint renderbuffer
)
2096 FlushOnStateChange();
2097 glEsImpl
->glFramebufferRenderbuffer( target
, attachment
, renderbuffertarget
, renderbuffer
);
2100 void glDeleteFramebuffers(GLsizei n
, const GLuint
*framebuffers
)
2102 FlushOnStateChange();
2103 glEsImpl
->glDeleteFramebuffers(n
, framebuffers
);
2106 void glDeleteRenderbuffers(GLsizei n
, const GLuint
*renderbuffers
)
2108 FlushOnStateChange();
2109 glEsImpl
->glDeleteRenderbuffers( n
, renderbuffers
);
2111 void glFramebufferTexture2D(GLenum target
, GLenum attachment
, GLenum textarget
, GLuint texture
, GLint level
)
2113 FlushOnStateChange();
2114 glEsImpl
->glFramebufferTexture2D(target
, attachment
,textarget
,texture
,level
);
2117 void glRenderbufferStorage(GLenum target
, GLenum internalformat
, GLsizei width
, GLsizei height
)
2119 FlushOnStateChange();
2120 glEsImpl
->glRenderbufferStorage(target
, internalformat
, width
, height
);