DEADSOFTWARE

Build a shared library instead of static
[nanogl.git] / nanoWrap.cpp
1 /*
2 Copyright (C) 2007-2009 Olli Hinkka
3
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.
8
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.
12
13 See the GNU General Public License for more details.
14
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.
18
19 */
20 /*
21 #include <e32def.h>
22 #include <e32std.h>
23 */
24
25 #include <stdio.h>
26 #include <stdlib.h>
27
28 #include "gl.h"
29 #include "glesinterface.h"
30
31 #define GL_TEXTURE0_ARB 0x84C0
32 #define GL_TEXTURE1_ARB 0x84C1
33
34 struct nanoState
35 {
36 GLboolean alpha_test;
37 GLboolean blend;
38 GLboolean clip_planei;
39 GLboolean color_logic_op;
40 GLboolean color_material;
41 GLboolean cull_face;
42 GLboolean depth_test;
43 GLboolean dither;
44 GLboolean fog;
45 GLboolean lighti;
46 GLboolean lighting;
47 GLboolean line_smooth;
48 GLboolean matrix_palette_oes;
49 GLboolean multisample;
50 GLboolean normalize;
51 GLboolean point_smooth;
52 GLboolean point_sprite_oes;
53 GLboolean polygon_offset_fill;
54 GLboolean rescale_normal;
55 GLboolean sample_alpha_to_coverage;
56 GLboolean sample_alpha_to_one;
57 GLboolean sample_coverage;
58 GLboolean scissor_test;
59 GLboolean stencil_test;
60 GLboolean depthmask;
61 GLclampf depth_range_near;
62 GLclampf depth_range_far;
63 GLenum depth_func;
64 GLenum cullface;
65 GLenum shademodel;
66 GLenum sfactor;
67 GLenum dfactor;
68 GLenum matrixmode;
69 };
70
71 static struct nanoState nanoglState;
72
73 static struct nanoState nanoglInitState =
74 {
75 GL_FALSE,
76 GL_FALSE,
77 GL_FALSE,
78 GL_FALSE,
79 GL_FALSE,
80 GL_FALSE,
81 GL_FALSE,
82 GL_TRUE,
83 GL_FALSE,
84 GL_FALSE,
85 GL_FALSE,
86 GL_FALSE,
87 GL_FALSE,
88 GL_TRUE,
89 GL_FALSE,
90 GL_FALSE,
91 GL_FALSE,
92 GL_FALSE,
93 GL_FALSE,
94 GL_FALSE,
95 GL_FALSE,
96 GL_FALSE,
97 GL_FALSE,
98 GL_FALSE,
99 GL_TRUE,
100 0.0f,
101 1.0f,
102 GL_LESS,
103 GL_BACK,
104 GL_SMOOTH,
105 GL_ONE,
106 GL_ZERO,
107 GL_MODELVIEW,
108 };
109
110 struct booleanstate
111 {
112 GLboolean value;
113 GLboolean changed;
114 };
115
116 struct floatstate
117 {
118 GLfloat value;
119 GLboolean changed;
120 };
121
122 struct uintstate
123 {
124 GLuint value;
125 GLboolean changed;
126 };
127
128 struct ptrstate
129 {
130 GLint size;
131 GLenum type;
132 GLsizei stride;
133 GLvoid* ptr;
134 GLboolean changed;
135 GLboolean enabled;
136 };
137
138
139 struct nanotmuState
140 {
141 struct booleanstate texture_2d;
142 struct floatstate texture_env_mode;
143 struct uintstate boundtexture;
144 struct ptrstate vertex_array;
145 struct ptrstate color_array;
146 struct ptrstate texture_coord_array;
147 };
148
149 static struct nanotmuState tmuState0;
150 static struct nanotmuState tmuState1;
151
152 static struct nanotmuState tmuInitState =
153 {
154 {GL_FALSE, GL_FALSE},
155 {GL_MODULATE,GL_FALSE},
156 {0x7fffffff,GL_FALSE},
157 {4,GL_FLOAT,0, NULL, GL_FALSE, GL_FALSE},
158 {4,GL_FLOAT,0, NULL, GL_FALSE, GL_FALSE},
159 {4,GL_FLOAT,0, NULL, GL_FALSE, GL_FALSE},
160 };
161
162 static struct nanotmuState* activetmuState = &tmuState0;
163
164 extern "C++" GlESInterface* glEsImpl;
165
166 static GLenum wrapperPrimitiveMode = GL_QUADS;
167 GLboolean useTexCoordArray = GL_FALSE;
168 static GLenum activetmu = GL_TEXTURE0;
169 static GLenum clientactivetmu = GL_TEXTURE0;
170
171 #if defined(__MULTITEXTURE_SUPPORT__)
172 GLboolean useMultiTexCoordArray = GL_FALSE;
173 #endif
174
175
176 #if !defined (__WINS__)
177 //#define __FORCEINLINE __forceinline
178 #define __FORCEINLINE inline
179 #else
180 #define __FORCEINLINE
181 #endif
182
183 static GLboolean delayedttmuchange = GL_FALSE;
184 static GLenum delayedtmutarget = GL_TEXTURE0;
185
186 struct VertexAttrib
187 {
188 float x;
189 float y;
190 float z;
191 #if !defined(__MULTITEXTURE_SUPPORT__)
192 float padding;
193 #endif
194 unsigned char red;
195 unsigned char green;
196 unsigned char blue;
197 unsigned char alpha;
198
199 float s;
200 float t;
201 #if defined(__MULTITEXTURE_SUPPORT__)
202 float s_multi;
203 float t_multi;
204 #endif
205 };
206
207 static VertexAttrib vertexattribs[8000];
208
209 static GLushort indexArray[30000];
210
211 static GLuint vertexCount = 0;
212 static GLuint indexCount = 0;
213 static GLuint vertexMark = 0;
214 static int indexbase = 0;
215
216 static VertexAttrib* ptrVertexAttribArray = NULL;
217 static VertexAttrib* ptrVertexAttribArrayMark = NULL;
218
219 static VertexAttrib currentVertexAttrib;
220 #if defined(__MULTITEXTURE_SUPPORT__)
221 static VertexAttrib currentVertexAttribInit = {0.0f,0.0f,0.0f,
222 255,255,255,255,
223 0.0f,0.0f,
224 0.0f,0.0f
225 };
226 #else
227 static VertexAttrib currentVertexAttribInit = {0.0f,0.0f,0.0f,0.0f,
228 255,255,255,255,
229 0.0f,0.0f,
230 };
231 #endif
232 static GLushort* ptrIndexArray = NULL;
233
234 static GLboolean arraysValid = GL_FALSE;
235
236 void InitGLStructs()
237 {
238 ptrVertexAttribArray = vertexattribs;
239 ptrVertexAttribArrayMark = ptrVertexAttribArray;
240 ptrIndexArray = indexArray;
241
242 memcpy(&nanoglState, &nanoglInitState, sizeof(struct nanoState));
243 memcpy(&tmuState0,&tmuInitState,sizeof(struct nanotmuState));
244 memcpy(&tmuState1,&tmuInitState,sizeof(struct nanotmuState));
245 memcpy(&currentVertexAttrib,&currentVertexAttribInit,sizeof(struct VertexAttrib));
246
247 activetmuState = &tmuState0;
248 wrapperPrimitiveMode = GL_QUADS;
249 useTexCoordArray = GL_FALSE;
250 activetmu = GL_TEXTURE0;
251 clientactivetmu = GL_TEXTURE0;
252 delayedttmuchange = GL_FALSE;
253 delayedtmutarget = GL_TEXTURE0;
254 vertexCount = 0;
255 indexCount = 0;
256 vertexMark = 0;
257 indexbase = 0;
258 arraysValid = GL_FALSE;
259 }
260
261
262 void FlushOnStateChange()
263 {
264 if (delayedttmuchange)
265 {
266 delayedttmuchange = GL_FALSE;
267 glEsImpl->glActiveTexture(delayedtmutarget);
268 }
269
270 if (!vertexCount)
271 return;
272
273 if (!arraysValid)
274 {
275 glEsImpl->glClientActiveTexture(GL_TEXTURE0);
276 glEsImpl->glVertexPointer(3, GL_FLOAT, sizeof(VertexAttrib), &vertexattribs[0].x);
277 glEsImpl->glColorPointer(4, GL_UNSIGNED_BYTE, sizeof(VertexAttrib), &vertexattribs[0].red);
278 glEsImpl->glTexCoordPointer(2, GL_FLOAT, sizeof(VertexAttrib), &vertexattribs[0].s);
279 glEsImpl->glEnableClientState(GL_VERTEX_ARRAY);
280 glEsImpl->glEnableClientState(GL_TEXTURE_COORD_ARRAY);
281 glEsImpl->glEnableClientState(GL_COLOR_ARRAY);
282 #if defined(__MULTITEXTURE_SUPPORT__)
283 glEsImpl->glClientActiveTexture(GL_TEXTURE1);
284 glEsImpl->glTexCoordPointer(2, GL_FLOAT, sizeof(VertexAttrib), &vertexattribs[0].s_multi);
285 glEsImpl->glEnableClientState(GL_TEXTURE_COORD_ARRAY);
286 glEsImpl->glClientActiveTexture(GL_TEXTURE0);
287 #endif
288 arraysValid = GL_TRUE;
289 }
290
291 glEsImpl->glDrawElements( GL_TRIANGLES,vertexCount,GL_UNSIGNED_SHORT, indexArray );
292
293
294 #if defined(__MULTITEXTURE_SUPPORT__)
295 useMultiTexCoordArray = GL_FALSE;
296 #endif
297 vertexCount = 0;
298 indexCount = 0;
299 ptrVertexAttribArray = vertexattribs;
300 ptrVertexAttribArrayMark = ptrVertexAttribArray;
301 ptrIndexArray = indexArray;
302 useTexCoordArray = GL_FALSE;
303 }
304
305 void glBegin(GLenum mode)
306 {
307 wrapperPrimitiveMode = mode;
308 vertexMark = vertexCount;
309 ptrVertexAttribArrayMark = ptrVertexAttribArray;
310 indexbase = indexCount;
311 }
312
313 void glEnd(void)
314 {
315 vertexCount+=((unsigned char*)ptrVertexAttribArray-(unsigned char*)ptrVertexAttribArrayMark)/sizeof(VertexAttrib);
316 if (vertexCount < 3)
317 {
318 return;
319 }
320 switch (wrapperPrimitiveMode)
321 {
322 case GL_QUADS:
323 {
324 *ptrIndexArray++ = indexCount;
325 *ptrIndexArray++ = indexCount+1;
326 *ptrIndexArray++ = indexCount+2;
327 *ptrIndexArray++ = indexCount;
328 *ptrIndexArray++ = indexCount+2;
329 *ptrIndexArray++ = indexCount+3;
330 indexCount+=4;
331 vertexCount+=2;
332 }
333 break;
334 case GL_TRIANGLES:
335 {
336 int vcount = (vertexCount-vertexMark)/3;
337 for (int count = 0; count < vcount; count++)
338 {
339 *ptrIndexArray++ = indexCount;
340 *ptrIndexArray++ = indexCount+1;
341 *ptrIndexArray++ = indexCount+2;
342 indexCount+=3;
343 }
344 }
345 break;
346 case GL_TRIANGLE_STRIP:
347 {
348 *ptrIndexArray++ = indexCount;
349 *ptrIndexArray++ = indexCount+1;
350 *ptrIndexArray++ = indexCount+2;
351 indexCount+=3;
352 int vcount = ((vertexCount-vertexMark)-3);
353 if (vcount && ((long)ptrIndexArray & 0x02))
354 {
355 *ptrIndexArray++ = indexCount-1; // 2
356 *ptrIndexArray++ = indexCount-2; // 1
357 *ptrIndexArray++ = indexCount; // 3
358 indexCount++;
359 vcount-=1;
360 int odd = vcount&1;
361 vcount/=2;
362 unsigned int* longptr = (unsigned int*) ptrIndexArray;
363
364 for (int count = 0; count < vcount; count++)
365 {
366 *(longptr++) = (indexCount-2) | ((indexCount-1)<<16);
367 *(longptr++) = (indexCount) | ((indexCount)<<16);
368 *(longptr++) = (indexCount-1) | ((indexCount+1)<<16);
369 indexCount+=2;
370 }
371 ptrIndexArray = (unsigned short*)(longptr);
372 if (odd)
373 {
374 *ptrIndexArray++ = indexCount-2; // 2
375 *ptrIndexArray++ = indexCount-1; // 1
376 *ptrIndexArray++ = indexCount; // 3
377 indexCount++;
378 }
379 }
380 else
381 {
382 //already aligned
383 int odd = vcount&1;
384 vcount/=2;
385 unsigned int* longptr = (unsigned int*) ptrIndexArray;
386
387 for (int count = 0; count < vcount; count++)
388 {
389 *(longptr++) = (indexCount-1) | ((indexCount-2)<<16);
390 *(longptr++) = (indexCount) | ((indexCount-1)<<16);
391 *(longptr++) = (indexCount) | ((indexCount+1)<<16);
392 indexCount+=2;
393
394 }
395 ptrIndexArray = (unsigned short*)(longptr);
396 if (odd)
397 {
398
399 *ptrIndexArray++ = indexCount-1; // 2
400 *ptrIndexArray++ = indexCount-2; // 1
401 *ptrIndexArray++ = indexCount; // 3
402 indexCount++;
403 }
404 }
405 vertexCount+=(vertexCount-vertexMark-3)*2;
406 }
407 break;
408 case GL_POLYGON:
409 case GL_TRIANGLE_FAN:
410 {
411 *ptrIndexArray++ = indexCount++;
412 *ptrIndexArray++ = indexCount++;
413 *ptrIndexArray++ = indexCount++;
414 int vcount = ((vertexCount-vertexMark)-3);
415 for (int count = 0; count < vcount; count++)
416 {
417 *ptrIndexArray++ = indexbase;
418 *ptrIndexArray++ = indexCount-1;
419 *ptrIndexArray++ = indexCount++;
420 vertexCount+=2;
421 }
422 }
423 break;
424
425 default:
426 break;
427 }
428 }
429
430 void glEnable (GLenum cap)
431 {
432 GLboolean statechanged = GL_FALSE;
433 switch(cap)
434 {
435 case GL_ALPHA_TEST:
436 {
437 if (!nanoglState.alpha_test)
438 {
439 nanoglState.alpha_test = GL_TRUE;
440 statechanged = GL_TRUE;
441 }
442 break;
443 }
444 case GL_BLEND:
445 {
446 if (!nanoglState.blend)
447 {
448 nanoglState.blend = GL_TRUE;
449 statechanged = GL_TRUE;
450 }
451 break;
452 }
453 //case GL_CLIP_PLANEi
454 case GL_COLOR_LOGIC_OP:
455 {
456 if (!nanoglState.color_logic_op)
457 {
458 nanoglState.color_logic_op = GL_TRUE;
459 statechanged = GL_TRUE;
460 }
461 break;
462 }
463 case GL_COLOR_MATERIAL:
464 {
465 if (!nanoglState.color_material)
466 {
467 nanoglState.color_material = GL_TRUE;
468 statechanged = GL_TRUE;
469 }
470 break;
471 }
472 case GL_CULL_FACE:
473 {
474 if (!nanoglState.cull_face)
475 {
476 nanoglState.cull_face = GL_TRUE;
477 statechanged = GL_TRUE;
478 }
479 break;
480 }
481 case GL_DEPTH_TEST:
482 {
483 if (!nanoglState.depth_test)
484 {
485 nanoglState.depth_test = GL_TRUE;
486 statechanged = GL_TRUE;
487 }
488 break;
489 }
490 case GL_DITHER:
491 {
492 if (!nanoglState.dither)
493 {
494 nanoglState.dither = GL_TRUE;
495 statechanged = GL_TRUE;
496 }
497 break;
498 }
499 case GL_FOG:
500 //case GL_LIGHTi
501 {
502 if (!nanoglState.fog)
503 {
504 nanoglState.fog = GL_TRUE;
505 statechanged = GL_TRUE;
506 }
507 break;
508 }
509 case GL_LIGHTING:
510 {
511 if (!nanoglState.lighting)
512 {
513 nanoglState.lighting = GL_TRUE;
514 statechanged = GL_TRUE;
515 }
516 break;
517 }
518 case GL_LINE_SMOOTH:
519 {
520 if (!nanoglState.line_smooth)
521 {
522 nanoglState.line_smooth = GL_TRUE;
523 statechanged = GL_TRUE;
524 }
525 break;
526 }
527 /* case GL_MATRIX_PALETTE_OES:
528 {
529 if (!nanoglState.matrix_palette_oes)
530 {
531 nanoglState.matrix_palette_oes = GL_TRUE;
532 statechanged = GL_TRUE;
533 }
534 break;
535 }*/
536 case GL_MULTISAMPLE:
537 {
538 if (!nanoglState.multisample)
539 {
540 nanoglState.multisample = GL_TRUE;
541 statechanged = GL_TRUE;
542 }
543 break;
544 }
545 case GL_NORMALIZE:
546 {
547 if (!nanoglState.normalize)
548 {
549 nanoglState.normalize = GL_TRUE;
550 statechanged = GL_TRUE;
551 }
552 break;
553 }
554 /* case GL_POINT_SPRITE_OES:
555 {
556 if (!nanoglState.point_sprite_oes)
557 {
558 nanoglState.point_sprite_oes = GL_TRUE;
559 statechanged = GL_TRUE;
560 }
561 break;
562 }*/
563 case GL_POLYGON_OFFSET_FILL:
564 {
565 if (!nanoglState.polygon_offset_fill)
566 {
567 nanoglState.polygon_offset_fill = GL_TRUE;
568 statechanged = GL_TRUE;
569 }
570 break;
571 }
572 case GL_RESCALE_NORMAL:
573 {
574 if (!nanoglState.rescale_normal)
575 {
576 nanoglState.rescale_normal = GL_TRUE;
577 statechanged = GL_TRUE;
578 }
579 break;
580 }
581 case GL_SAMPLE_ALPHA_TO_COVERAGE:
582 {
583 if (!nanoglState.sample_alpha_to_coverage)
584 {
585 nanoglState.sample_alpha_to_coverage = GL_TRUE;
586 statechanged = GL_TRUE;
587 }
588 break;
589 }
590 case GL_SAMPLE_ALPHA_TO_ONE:
591 {
592 if (!nanoglState.sample_alpha_to_one)
593 {
594 nanoglState.sample_alpha_to_one = GL_TRUE;
595 statechanged = GL_TRUE;
596 }
597 break;
598 }
599 case GL_SAMPLE_COVERAGE:
600 {
601 if (!nanoglState.sample_coverage)
602 {
603 nanoglState.sample_coverage = GL_TRUE;
604 statechanged = GL_TRUE;
605 }
606 break;
607 }
608 case GL_SCISSOR_TEST:
609 {
610 if (!nanoglState.scissor_test)
611 {
612 nanoglState.scissor_test = GL_TRUE;
613 statechanged = GL_TRUE;
614 }
615 break;
616 }
617 case GL_STENCIL_TEST:
618 {
619 return;
620 /* if (!nanoglState.stencil_test)
621 {
622 nanoglState.stencil_test = GL_TRUE;
623 statechanged = GL_TRUE;
624 }*/
625 break;
626 }
627 case GL_TEXTURE_2D:
628 {
629 if (!activetmuState->texture_2d.value)
630 {
631 FlushOnStateChange();
632 glEsImpl->glEnable(cap);
633 activetmuState->texture_2d.value = GL_TRUE;
634 return;
635 }
636 break;
637 }
638 default:
639 break;
640 }
641
642 if (statechanged)
643 {
644 FlushOnStateChange();
645 glEsImpl->glEnable(cap);
646 }
647 }
648
649 void glDisable (GLenum cap)
650 {
651 GLboolean statechanged = GL_FALSE;
652 switch(cap)
653 {
654 case GL_ALPHA_TEST:
655 {
656 if (nanoglState.alpha_test)
657 {
658 nanoglState.alpha_test = GL_FALSE;
659 statechanged = GL_TRUE;
660 }
661 break;
662 }
663 case GL_BLEND:
664 {
665 if (nanoglState.blend)
666 {
667 nanoglState.blend = GL_FALSE;
668 statechanged = GL_TRUE;
669 }
670 break;
671 }
672 //case GL_CLIP_PLANEi
673 case GL_COLOR_LOGIC_OP:
674 {
675 if (nanoglState.color_logic_op)
676 {
677 nanoglState.color_logic_op = GL_FALSE;
678 statechanged = GL_TRUE;
679 }
680 break;
681 }
682 case GL_COLOR_MATERIAL:
683 {
684 if (nanoglState.color_material)
685 {
686 nanoglState.color_material = GL_FALSE;
687 statechanged = GL_TRUE;
688 }
689 break;
690 }
691 case GL_CULL_FACE:
692 {
693 if (nanoglState.cull_face)
694 {
695 nanoglState.cull_face = GL_FALSE;
696 statechanged = GL_TRUE;
697 }
698 break;
699 }
700 case GL_DEPTH_TEST:
701 {
702 if (nanoglState.depth_test)
703 {
704 nanoglState.depth_test = GL_FALSE;
705 statechanged = GL_TRUE;
706 }
707 break;
708 }
709 case GL_DITHER:
710 {
711 if (nanoglState.dither)
712 {
713 nanoglState.dither = GL_FALSE;
714 statechanged = GL_TRUE;
715 }
716 break;
717 }
718 case GL_FOG:
719 //case GL_LIGHTi
720 {
721 if (nanoglState.fog)
722 {
723 nanoglState.fog = GL_FALSE;
724 statechanged = GL_TRUE;
725 }
726 break;
727 }
728 case GL_LIGHTING:
729 {
730 if (nanoglState.lighting)
731 {
732 nanoglState.lighting = GL_FALSE;
733 statechanged = GL_TRUE;
734 }
735 break;
736 }
737 case GL_LINE_SMOOTH:
738 {
739 if (nanoglState.line_smooth)
740 {
741 nanoglState.line_smooth = GL_FALSE;
742 statechanged = GL_TRUE;
743 }
744 break;
745 }
746 /* case GL_MATRIX_PALETTE_OES:
747 {
748 if (nanoglState.matrix_palette_oes)
749 {
750 nanoglState.matrix_palette_oes = GL_FALSE;
751 statechanged = GL_TRUE;
752 }
753 break;
754 }*/
755 case GL_MULTISAMPLE:
756 {
757 if (nanoglState.multisample)
758 {
759 nanoglState.multisample = GL_FALSE;
760 statechanged = GL_TRUE;
761 }
762 break;
763 }
764 case GL_NORMALIZE:
765 {
766 if (nanoglState.normalize)
767 {
768 nanoglState.normalize = GL_FALSE;
769 statechanged = GL_TRUE;
770 }
771 break;
772 }
773 /* case GL_POINT_SPRITE_OES:
774 {
775 if (nanoglState.point_sprite_oes)
776 {
777 nanoglState.point_sprite_oes = GL_FALSE;
778 statechanged = GL_TRUE;
779 }
780 break;
781 }*/
782 case GL_POLYGON_OFFSET_FILL:
783 {
784 if (nanoglState.polygon_offset_fill)
785 {
786 nanoglState.polygon_offset_fill = GL_FALSE;
787 statechanged = GL_TRUE;
788 }
789 break;
790 }
791 case GL_RESCALE_NORMAL:
792 {
793 if (nanoglState.rescale_normal)
794 {
795 nanoglState.rescale_normal = GL_FALSE;
796 statechanged = GL_TRUE;
797 }
798 break;
799 }
800 case GL_SAMPLE_ALPHA_TO_COVERAGE:
801 {
802 if (nanoglState.sample_alpha_to_coverage)
803 {
804 nanoglState.sample_alpha_to_coverage = GL_FALSE;
805 statechanged = GL_TRUE;
806 }
807 break;
808 }
809 case GL_SAMPLE_ALPHA_TO_ONE:
810 {
811 if (nanoglState.sample_alpha_to_one)
812 {
813 nanoglState.sample_alpha_to_one = GL_FALSE;
814 statechanged = GL_TRUE;
815 }
816 break;
817 }
818 case GL_SAMPLE_COVERAGE:
819 {
820 if (nanoglState.sample_coverage)
821 {
822 nanoglState.sample_coverage = GL_FALSE;
823 statechanged = GL_TRUE;
824 }
825 break;
826 }
827 case GL_SCISSOR_TEST:
828 {
829 if (nanoglState.scissor_test)
830 {
831 nanoglState.scissor_test = GL_FALSE;
832 statechanged = GL_TRUE;
833 }
834 break;
835 }
836 case GL_STENCIL_TEST:
837 {
838 return;
839 /* if (nanoglState.stencil_test)
840 {
841 nanoglState.stencil_test = GL_FALSE;
842 statechanged = GL_TRUE;
843 }*/
844 break;
845 }
846 case GL_TEXTURE_2D:
847 {
848 if (activetmuState->texture_2d.value)
849 {
850 FlushOnStateChange();
851 glEsImpl->glDisable(cap);
852 activetmuState->texture_2d.value = GL_FALSE;
853 return;
854
855
856 }
857 break;
858 }
859 default:
860 break;
861 }
862
863 if (statechanged)
864 {
865 FlushOnStateChange();
866 glEsImpl->glDisable(cap);
867 }
868 }
869
870 void glVertex2f(GLfloat x, GLfloat y)
871 {
872 glVertex3f(x,y,0.0f);
873 }
874
875
876 __FORCEINLINE unsigned int ClampTo255(float value)
877 {
878 unsigned int retval = (unsigned int)(value);
879 if (retval > 255)
880 {
881 retval = 255;
882 }
883 return retval;
884 }
885
886 void glColor3f( GLfloat red, GLfloat green, GLfloat blue)
887 {
888 currentVertexAttrib.red = (unsigned char)ClampTo255(red*255.0f);
889 currentVertexAttrib.green = (unsigned char)ClampTo255(green*255.0f);
890 currentVertexAttrib.blue = (unsigned char)ClampTo255(blue*255.0f);
891 currentVertexAttrib.alpha = 255;
892 }
893
894
895 void glTexCoord2fv( const GLfloat *v )
896 {
897 memcpy(&currentVertexAttrib.s, v, 2*sizeof(float));
898 }
899
900
901 void glTexCoord2f(GLfloat s, GLfloat t)
902 {
903 currentVertexAttrib.s = s;
904 currentVertexAttrib.t = t;
905 }
906
907 void glViewport (GLint x, GLint y, GLsizei width, GLsizei height)
908 {
909 FlushOnStateChange();
910 glEsImpl->glViewport(x,y,width,height);
911 }
912
913 void glLoadIdentity (void)
914 {
915 FlushOnStateChange();
916 glEsImpl->glLoadIdentity();
917 }
918
919 void glColor4f (GLfloat red, GLfloat green, GLfloat blue, GLfloat alpha)
920 {
921 currentVertexAttrib.red = (unsigned char)ClampTo255(red*255.0f);
922 currentVertexAttrib.green = (unsigned char)ClampTo255(green*255.0f);
923 currentVertexAttrib.blue = (unsigned char)ClampTo255(blue*255.0f);
924 currentVertexAttrib.alpha = (unsigned char)ClampTo255(alpha*255.0f);
925 }
926
927 void glOrtho (GLfloat left, GLfloat right, GLfloat bottom, GLfloat top, GLfloat zNear, GLfloat zFar)
928 {
929 FlushOnStateChange();
930 glEsImpl->glOrthof(left,right,bottom,top, zNear,zFar);
931 }
932
933 void glMatrixMode (GLenum mode)
934 {
935 if (nanoglState.matrixmode == mode)
936 {
937 return;
938 }
939 nanoglState.matrixmode = mode;
940 FlushOnStateChange();
941 glEsImpl->glMatrixMode(mode);
942 }
943
944 void glTexParameterf (GLenum target, GLenum pname, GLfloat param)
945 {
946 if (pname == GL_TEXTURE_BORDER_COLOR)
947 {
948 return; // not supported by opengl es
949 }
950 if ( (pname == GL_TEXTURE_WRAP_S ||
951 pname == GL_TEXTURE_WRAP_T) &&
952 param == GL_CLAMP)
953 {
954 param = 0x812F;
955 }
956
957 FlushOnStateChange();
958 glEsImpl->glTexParameterf(target, pname,param);
959 }
960
961 void glTexParameterfv( GLenum target, GLenum pname, const GLfloat *params)
962 {
963 glTexParameterf(target, pname, params[0]);
964 }
965
966 void glTexImage2D (GLenum target, GLint level, GLint internalformat, GLsizei width, GLsizei height, GLint border, GLenum format, GLenum type, const GLvoid *pixels)
967 {
968 FlushOnStateChange();
969 internalformat = format;
970 glEsImpl->glTexImage2D(target, level, internalformat, width, height,border,format,type,pixels);
971 }
972
973 void glDrawBuffer(GLenum /*mode*/)
974 {
975 }
976
977 void glTranslatef (GLfloat x, GLfloat y, GLfloat z)
978 {
979 FlushOnStateChange();
980 glEsImpl->glTranslatef(x,y,z);
981 }
982
983 void glRotatef (GLfloat angle, GLfloat x, GLfloat y, GLfloat z)
984 {
985 FlushOnStateChange();
986 glEsImpl->glRotatef(angle, x, y, z);
987 }
988
989 void glScalef (GLfloat x, GLfloat y, GLfloat z)
990 {
991 FlushOnStateChange();
992 glEsImpl->glScalef(x,y,z);
993 }
994
995 void glDepthRange(GLclampf zNear, GLclampf zFar)
996 {
997 if ((nanoglState.depth_range_near == zNear) &&(nanoglState.depth_range_far == zFar))
998 {
999 return;
1000 }
1001 else
1002 {
1003 nanoglState.depth_range_near = zNear;
1004 nanoglState.depth_range_far = zFar;
1005 }
1006 FlushOnStateChange();
1007 glEsImpl->glDepthRangef(zNear, zFar);
1008 }
1009
1010 void glDepthFunc (GLenum func)
1011 {
1012 if (nanoglState.depth_func == func)
1013 {
1014 return;
1015 }
1016 else
1017 {
1018 nanoglState.depth_func = func;
1019 }
1020 FlushOnStateChange();
1021 glEsImpl->glDepthFunc(func);
1022 }
1023
1024 void glFinish (void)
1025 {
1026 FlushOnStateChange();
1027 glEsImpl->glFinish();
1028 }
1029
1030 void glGetFloatv (GLenum pname, GLfloat *params)
1031 {
1032 FlushOnStateChange();
1033 glEsImpl->glGetFloatv(pname, params);
1034 }
1035
1036 void glCullFace (GLenum mode)
1037 {
1038 if (nanoglState.cullface == mode)
1039 {
1040 return;
1041 }
1042 else
1043 {
1044 nanoglState.cullface = mode;
1045 }
1046 FlushOnStateChange();
1047 glEsImpl->glCullFace(mode);
1048 }
1049
1050 void glFrustum (GLfloat left, GLfloat right, GLfloat bottom, GLfloat top, GLfloat zNear, GLfloat zFar)
1051 {
1052 FlushOnStateChange();
1053 glEsImpl->glFrustumf(left,right,bottom,top,zNear,zFar);
1054 }
1055
1056 void glClear (GLbitfield mask)
1057 {
1058 FlushOnStateChange();
1059 glEsImpl->glClear(mask);
1060 }
1061
1062
1063 void glVertex3f( GLfloat x, GLfloat y, GLfloat z )
1064 {
1065 GLfloat* vert = (GLfloat*)ptrVertexAttribArray++;
1066 *vert++ = x;
1067 *vert++ = y;
1068 *vert++ = z;
1069 #if defined(__MULTITEXTURE_SUPPORT__)
1070 memcpy(vert, &currentVertexAttrib.red, 5*sizeof(GLfloat));
1071 #else
1072 memcpy(vert+1, &currentVertexAttrib.red, 3*sizeof(GLfloat));
1073 #endif
1074
1075 }
1076
1077 void glColor4fv( const GLfloat *v )
1078 {
1079 currentVertexAttrib.red = (unsigned char)ClampTo255(v[0]*255.0f);
1080 currentVertexAttrib.green = (unsigned char)ClampTo255(v[1]*255.0f);
1081 currentVertexAttrib.blue = (unsigned char)ClampTo255(v[2]*255.0f);
1082 currentVertexAttrib.alpha = (unsigned char)ClampTo255(v[3]*255.0f);
1083 }
1084
1085 void glColor3ubv( const GLubyte* v)
1086 {
1087 currentVertexAttrib.red = v[0];
1088 currentVertexAttrib.green = v[1];
1089 currentVertexAttrib.blue = v[2];
1090 currentVertexAttrib.alpha = 255;
1091 }
1092
1093 void glColor4ubv( const GLubyte *v )
1094 {
1095 //*((unsigned int*)(&currentVertexAttrib.red)) = *((unsigned int*)(v));
1096 currentVertexAttrib.red = v[0];
1097 currentVertexAttrib.green = v[1];
1098 currentVertexAttrib.blue = v[2];
1099 currentVertexAttrib.alpha = v[3];
1100 }
1101
1102 void glColor3fv( const GLfloat *v )
1103 {
1104 currentVertexAttrib.red = (unsigned char)ClampTo255(v[0]*255.0f);
1105 currentVertexAttrib.green = (unsigned char)ClampTo255(v[1]*255.0f);
1106 currentVertexAttrib.blue = (unsigned char)ClampTo255(v[2]*255.0f);
1107 currentVertexAttrib.alpha = 255;
1108 }
1109
1110 //-- nicknekit: xash3d funcs --
1111
1112 void glColor4ub( GLubyte red, GLubyte green, GLubyte blue, GLubyte alpha)
1113 {
1114 currentVertexAttrib.red = red;
1115 currentVertexAttrib.green = green;
1116 currentVertexAttrib.blue = blue;
1117 currentVertexAttrib.alpha = alpha;
1118 }
1119
1120 void glColor3ub( GLubyte red, GLubyte green, GLubyte blue)
1121 {
1122 currentVertexAttrib.red = red;
1123 currentVertexAttrib.green = green;
1124 currentVertexAttrib.blue = blue;
1125 currentVertexAttrib.alpha = 255;
1126 }
1127
1128 void glNormal3fv( const GLfloat *v )
1129 {
1130 FlushOnStateChange();
1131 glEsImpl->glNormal3f(v[0],v[1],v[2]);
1132 }
1133
1134 void glCopyTexImage2D( GLenum target, GLint level, GLenum internalformat, GLint x, GLint y, GLsizei width, GLsizei height, GLint border )
1135 {
1136 FlushOnStateChange();
1137 glEsImpl->glCopyTexImage2D(target, level, internalformat, x, y, width, height, border);
1138 }
1139
1140 void glTexImage1D(GLenum target, GLint level, GLint internalformat, GLsizei width, GLint border, GLenum format, GLenum type, const GLvoid *pixels)
1141 {
1142 glTexImage2D(GL_TEXTURE_2D, level, internalformat, width, 1, border, format, type, pixels);
1143 }
1144
1145 void glTexImage3D(GLenum target, GLint level, GLint internalformat, GLsizei width, GLsizei height, GLsizei depth, GLint border, GLenum format, GLenum type, const GLvoid *pixels)
1146 {
1147 glTexImage2D(GL_TEXTURE_2D, level, internalformat, width, height, border, format, type, pixels);
1148 }
1149
1150 void glTexSubImage1D( GLenum target, GLint level, GLint xoffset, GLsizei width, GLenum format, GLenum type, const GLvoid *pixels )
1151 {
1152 glTexSubImage2D(target,level,xoffset,0,width,1,format,type,pixels);
1153 }
1154
1155 void glTexSubImage3D( GLenum target, GLint level,
1156 GLint xoffset, GLint yoffset,
1157 GLint zoffset, GLsizei width,
1158 GLsizei height, GLsizei depth,
1159 GLenum format,
1160 GLenum type, const GLvoid *pixels)
1161 {
1162 glTexSubImage2D(target,level,xoffset,yoffset,width,height,format,type,pixels);
1163 }
1164
1165
1166
1167 GLboolean glIsTexture(GLuint texture)
1168 {
1169 FlushOnStateChange();
1170 return glEsImpl->glIsTexture(texture);
1171 }
1172
1173
1174 void glTexGeni( GLenum coord, GLenum pname, GLint param )
1175 {
1176 //for mirrors? not needed for original hl?
1177 }
1178
1179 void glTexGenfv( GLenum coord, GLenum pname, const GLfloat *params )
1180 {
1181 //for mirrors? not needed for original hl?
1182 }
1183
1184 //-- --//
1185
1186 void glHint (GLenum target, GLenum mode)
1187 {
1188 FlushOnStateChange();
1189 glEsImpl->glHint(target, mode);
1190 }
1191
1192 void glBlendFunc (GLenum sfactor, GLenum dfactor)
1193 {
1194 if ((nanoglState.sfactor == sfactor) && (nanoglState.dfactor == dfactor))
1195 {
1196 return;
1197 }
1198 nanoglState.sfactor = sfactor;
1199 nanoglState.dfactor = dfactor;
1200 FlushOnStateChange();
1201 glEsImpl->glBlendFunc(sfactor, dfactor);
1202 }
1203
1204 void glPopMatrix (void)
1205 {
1206 FlushOnStateChange();
1207 glEsImpl->glPopMatrix();
1208 }
1209
1210 void glShadeModel (GLenum mode)
1211 {
1212 if (nanoglState.shademodel == mode)
1213 {
1214 return;
1215 }
1216 nanoglState.shademodel = mode;
1217 FlushOnStateChange();
1218 glEsImpl->glShadeModel(mode);
1219 }
1220
1221 void glPushMatrix (void)
1222 {
1223 FlushOnStateChange();
1224 glEsImpl->glPushMatrix();
1225 }
1226
1227 void glTexEnvf (GLenum target, GLenum pname, GLfloat param)
1228 {
1229 if (target == GL_TEXTURE_ENV)
1230 {
1231 if (pname == GL_TEXTURE_ENV_MODE)
1232 {
1233 if (param == activetmuState->texture_env_mode.value)
1234 {
1235 return;
1236 }
1237 else
1238 {
1239 FlushOnStateChange();
1240 glEsImpl->glTexEnvf(target, pname, param);
1241 activetmuState->texture_env_mode.value = param;
1242 return;
1243 }
1244 }
1245 }
1246 FlushOnStateChange();
1247 glEsImpl->glTexEnvf(target, pname, param);
1248 }
1249
1250 void glVertex3fv( const GLfloat *v )
1251 {
1252 GLfloat* vert = (GLfloat*)ptrVertexAttribArray++;
1253 memcpy(vert, v, 3*sizeof(GLfloat));
1254 #if defined(__MULTITEXTURE_SUPPORT__)
1255 memcpy(vert+3, &currentVertexAttrib.red, 5*sizeof(GLfloat));
1256 #else
1257 memcpy(vert+4, &currentVertexAttrib.red, 3*sizeof(GLfloat));
1258 #endif
1259 }
1260
1261
1262 void glDepthMask (GLboolean flag)
1263 {
1264 if (nanoglState.depthmask == flag)
1265 {
1266 return;
1267 }
1268 nanoglState.depthmask = flag;
1269 FlushOnStateChange();
1270 glEsImpl->glDepthMask(flag);
1271 }
1272
1273 void glBindTexture (GLenum target, GLuint texture)
1274 {
1275 if (activetmuState->boundtexture.value == texture)
1276 {
1277 return;
1278 }
1279 FlushOnStateChange();
1280 activetmuState->boundtexture.value = texture;
1281 glEsImpl->glBindTexture(target, texture);
1282 }
1283
1284
1285 void glGetIntegerv (GLenum pname, GLint *params)
1286 {
1287 FlushOnStateChange();
1288 glEsImpl->glGetIntegerv(pname, params);
1289 }
1290
1291 GLubyte nano_extensions_string[4096];
1292 const GLubyte* glGetString (GLenum name)
1293 {
1294
1295 if (name == GL_EXTENSIONS)
1296 {
1297 #if defined(__MULTITEXTURE_SUPPORT__)
1298 sprintf((char*)nano_extensions_string,"%s %s",glEsImpl->glGetString(name),"GL_ARB_multitexture EXT_texture_env_add");
1299 #else
1300 sprintf((char*)nano_extensions_string,"%s %s",glEsImpl->glGetString(name),"EXT_texture_env_add");
1301 #endif
1302 return nano_extensions_string;
1303 }
1304 return glEsImpl->glGetString(name);
1305 }
1306
1307 void glAlphaFunc (GLenum func, GLclampf ref)
1308 {
1309 FlushOnStateChange();
1310 glEsImpl->glAlphaFunc(func,ref);
1311 }
1312
1313 void glFlush (void)
1314 {
1315 FlushOnStateChange();
1316 glEsImpl->glFlush();
1317 }
1318
1319 void glReadPixels (GLint x, GLint y, GLsizei width, GLsizei height, GLenum format, GLenum type, GLvoid *pixels)
1320 {
1321 if (format == GL_DEPTH_COMPONENT)
1322 {
1323 // OpenglEs 1.1 does not support reading depth buffer without an extension
1324 memset(pixels, 0xff,4);
1325 return;
1326 }
1327 FlushOnStateChange();
1328 glEsImpl->glReadPixels(x,y,width,height,format,type,pixels);
1329 }
1330
1331 void glReadBuffer( GLenum /*mode*/ )
1332 {
1333
1334 }
1335
1336 void glLoadMatrixf (const GLfloat *m)
1337 {
1338 FlushOnStateChange();
1339 glEsImpl->glLoadMatrixf(m);
1340 }
1341
1342 void glTexSubImage2D (GLenum target, GLint level, GLint xoffset, GLint yoffset, GLsizei width, GLsizei height, GLenum format, GLenum type, const GLvoid *pixels)
1343 {
1344 FlushOnStateChange();
1345 glEsImpl->glTexSubImage2D(target,level,xoffset,yoffset,width,height,format,type,pixels);
1346 }
1347
1348 void glClearColor (GLclampf red, GLclampf green, GLclampf blue, GLclampf alpha)
1349 {
1350 FlushOnStateChange();
1351 glEsImpl->glClearColor(red,green,blue,alpha);
1352 }
1353
1354 GLenum glGetError (void)
1355 {
1356 FlushOnStateChange();
1357 return GL_NO_ERROR;//glEsImpl->glGetError();
1358 }
1359
1360 void glActiveTexture (GLenum texture)
1361 {
1362 if (activetmu == texture)
1363 {
1364 return;
1365 }
1366 if (delayedttmuchange)
1367 {
1368 delayedttmuchange = GL_FALSE;
1369 }
1370 else
1371 {
1372 delayedttmuchange = GL_TRUE;
1373 delayedtmutarget = texture;
1374 }
1375 if (texture == GL_TEXTURE0)
1376 {
1377 activetmuState = &tmuState0;
1378 }
1379 else
1380 {
1381 activetmuState = &tmuState1;
1382 }
1383 activetmu = texture;
1384 }
1385
1386 void glClientActiveTexture (GLenum texture)
1387 {
1388 clientactivetmu = texture;
1389 }
1390
1391 void glPolygonMode( GLenum face, GLenum mode )
1392 {
1393 }
1394
1395 void glDeleteTextures( GLsizei n, const GLuint *textures )
1396 {
1397 FlushOnStateChange();
1398 glEsImpl->glDeleteTextures(n,textures);
1399 }
1400
1401 void glClearDepth( GLclampf depth )
1402 {
1403 FlushOnStateChange();
1404 glEsImpl->glClearDepthf( depth );
1405 }
1406
1407 void glClipPlane( GLenum plane, const GLdouble *equation )
1408 {
1409 FlushOnStateChange();
1410 float array[4];
1411 array[0] = (GLfloat)(equation[0]);
1412 array[1] = (GLfloat)(equation[1]);
1413 array[2] = (GLfloat)(equation[2]);
1414 array[3] = (GLfloat)(equation[3]);
1415 glEsImpl->glClipPlanef( plane, array );
1416 }
1417
1418 void glScissor( GLint x, GLint y, GLsizei width, GLsizei height )
1419 {
1420 FlushOnStateChange();
1421 glEsImpl->glScissor( x, y, width,height);
1422 }
1423
1424 void glPointSize( GLfloat size )
1425 {
1426 FlushOnStateChange();
1427 glEsImpl->glPointSize( size );
1428 }
1429
1430 void glArrayElement(GLint i) {}
1431 void glLineWidth(GLfloat width) {}
1432 void glCallList( GLuint list ) {}
1433 void glColorMask( GLboolean red, GLboolean green, GLboolean blue, GLboolean alpha ) {}
1434 void glStencilFunc( GLenum func, GLint ref, GLuint mask ) {}
1435 void glStencilOp( GLenum fail, GLenum zfail, GLenum zpass ) {}
1436
1437 struct ptrstate vertex_array;
1438 struct ptrstate color_array;
1439 struct ptrstate texture_coord_array;
1440
1441 void glDrawElements( GLenum mode, GLsizei count, GLenum type, const GLvoid *indices )
1442 {
1443 // ensure that all primitives specified between glBegin/glEnd pairs
1444 // are rendered first, and that we have correct tmu in use..
1445 FlushOnStateChange();
1446 // setup correct vertex/color/texcoord pointers
1447 if (arraysValid ||
1448 tmuState0.vertex_array.changed ||
1449 tmuState0.color_array.changed ||
1450 tmuState0.texture_coord_array.changed)
1451 {
1452 glEsImpl->glClientActiveTexture(GL_TEXTURE0);
1453 }
1454 if (arraysValid || tmuState0.vertex_array.changed)
1455 {
1456 if (tmuState0.vertex_array.enabled)
1457 {
1458 glEsImpl->glEnableClientState(GL_VERTEX_ARRAY);
1459 }
1460 else
1461 {
1462 glEsImpl->glDisableClientState(GL_VERTEX_ARRAY);
1463 }
1464 glEsImpl->glVertexPointer(tmuState0.vertex_array.size,
1465 tmuState0.vertex_array.type,
1466 tmuState0.vertex_array.stride,
1467 tmuState0.vertex_array.ptr);
1468 tmuState0.vertex_array.changed = GL_FALSE;
1469 }
1470 if (arraysValid || tmuState0.color_array.changed)
1471 {
1472 if (tmuState0.color_array.enabled)
1473 {
1474 glEsImpl->glEnableClientState(GL_COLOR_ARRAY);
1475 }
1476 else
1477 {
1478 glEsImpl->glDisableClientState(GL_COLOR_ARRAY);
1479 }
1480 glEsImpl->glColorPointer(tmuState0.color_array.size,
1481 tmuState0.color_array.type,
1482 tmuState0.color_array.stride,
1483 tmuState0.color_array.ptr);
1484 tmuState0.color_array.changed = GL_FALSE;
1485 }
1486 if (arraysValid || tmuState0.texture_coord_array.changed)
1487 {
1488 tmuState0.texture_coord_array.changed = GL_FALSE;
1489 if (tmuState0.texture_coord_array.enabled)
1490 {
1491 glEsImpl->glEnableClientState(GL_TEXTURE_COORD_ARRAY);
1492 }
1493 else
1494 {
1495 glEsImpl->glDisableClientState(GL_TEXTURE_COORD_ARRAY);
1496 }
1497 glEsImpl->glTexCoordPointer(tmuState0.texture_coord_array.size,
1498 tmuState0.texture_coord_array.type,
1499 tmuState0.texture_coord_array.stride,
1500 tmuState0.texture_coord_array.ptr);
1501 }
1502
1503 if (arraysValid || tmuState1.texture_coord_array.changed)
1504 {
1505 tmuState1.texture_coord_array.changed = GL_FALSE;
1506 glEsImpl->glClientActiveTexture(GL_TEXTURE1);
1507 if (tmuState1.texture_coord_array.enabled)
1508 {
1509 glEsImpl->glEnableClientState(GL_TEXTURE_COORD_ARRAY);
1510 }
1511 else
1512 {
1513 glEsImpl->glDisableClientState(GL_TEXTURE_COORD_ARRAY);
1514 }
1515 glEsImpl->glTexCoordPointer(tmuState1.texture_coord_array.size,
1516 tmuState1.texture_coord_array.type,
1517 tmuState1.texture_coord_array.stride,
1518 tmuState1.texture_coord_array.ptr);
1519 }
1520
1521 arraysValid = GL_FALSE;
1522 glEsImpl->glDrawElements(mode, count, type, indices);
1523 }
1524
1525 void glEnableClientState(GLenum array)
1526 {
1527 struct nanotmuState* clientstate = NULL;
1528 if (clientactivetmu == GL_TEXTURE0)
1529 {
1530 clientstate = &tmuState0;
1531 }
1532 else if (clientactivetmu == GL_TEXTURE1)
1533 {
1534 clientstate = &tmuState1;
1535 }
1536 else
1537 {
1538 return;
1539 }
1540 switch (array)
1541 {
1542 case GL_VERTEX_ARRAY:
1543 if (clientstate->vertex_array.enabled)
1544 {
1545 return;
1546 }
1547 clientstate->vertex_array.enabled = GL_TRUE;
1548 clientstate->vertex_array.changed = GL_TRUE;
1549 break;
1550 case GL_COLOR_ARRAY:
1551 if (clientstate->color_array.enabled)
1552 {
1553 return;
1554 }
1555 clientstate->color_array.enabled = GL_TRUE;
1556 clientstate->color_array.changed = GL_TRUE;
1557
1558 break;
1559 case GL_TEXTURE_COORD_ARRAY:
1560 if (clientstate->texture_coord_array.enabled)
1561 {
1562 return;
1563 }
1564 clientstate->texture_coord_array.enabled = GL_TRUE;
1565 clientstate->texture_coord_array.changed = GL_TRUE;
1566 break;
1567 default:
1568 break;
1569 }
1570 }
1571 void glDisableClientState(GLenum array)
1572 {
1573 struct nanotmuState* clientstate = NULL;
1574 if (clientactivetmu == GL_TEXTURE0)
1575 {
1576 clientstate = &tmuState0;
1577 }
1578 else if (clientactivetmu == GL_TEXTURE1)
1579 {
1580 clientstate = &tmuState1;
1581 }
1582 else
1583 {
1584 return;
1585 }
1586 switch (array)
1587 {
1588 case GL_VERTEX_ARRAY:
1589 if (!clientstate->vertex_array.enabled)
1590 {
1591 return;
1592 }
1593 clientstate->vertex_array.enabled = GL_FALSE;
1594 clientstate->vertex_array.changed = GL_TRUE;
1595 break;
1596 case GL_COLOR_ARRAY:
1597 if (!clientstate->color_array.enabled)
1598 {
1599 return;
1600 }
1601 clientstate->color_array.enabled = GL_FALSE;
1602 clientstate->color_array.changed = GL_TRUE;
1603
1604 break;
1605 case GL_TEXTURE_COORD_ARRAY:
1606 if (!clientstate->texture_coord_array.enabled)
1607 {
1608 return;
1609 }
1610 clientstate->texture_coord_array.enabled = GL_FALSE;
1611 clientstate->texture_coord_array.changed = GL_TRUE;
1612 break;
1613 default:
1614 break;
1615 }
1616 }
1617 void glVertexPointer( GLint size, GLenum type,GLsizei stride, const GLvoid *pointer )
1618 {
1619 if (tmuState0.vertex_array.size == size &&
1620 tmuState0.vertex_array.stride == stride &&
1621 tmuState0.vertex_array.type == type &&
1622 tmuState0.vertex_array.ptr == pointer)
1623 {
1624 return;
1625 }
1626 tmuState0.vertex_array.size = size;
1627 tmuState0.vertex_array.stride = stride;
1628 tmuState0.vertex_array.type = type;
1629 tmuState0.vertex_array.ptr = (GLvoid*)pointer;
1630 tmuState0.vertex_array.changed = GL_TRUE;
1631 }
1632 void glTexCoordPointer( GLint size, GLenum type, GLsizei stride, const GLvoid *pointer )
1633 {
1634 struct nanotmuState* clientstate = NULL;
1635 if (clientactivetmu == GL_TEXTURE0)
1636 {
1637 clientstate = &tmuState0;
1638 }
1639 else if (clientactivetmu == GL_TEXTURE1)
1640 {
1641 clientstate = &tmuState1;
1642 }
1643 if (clientstate->texture_coord_array.size == size &&
1644 clientstate->texture_coord_array.stride == stride &&
1645 clientstate->texture_coord_array.type == type &&
1646 clientstate->texture_coord_array.ptr == pointer)
1647 {
1648 return;
1649 }
1650 clientstate->texture_coord_array.size = size;
1651 clientstate->texture_coord_array.stride = stride;
1652 clientstate->texture_coord_array.type = type;
1653 clientstate->texture_coord_array.ptr = (GLvoid*)pointer;
1654 clientstate->texture_coord_array.changed = GL_TRUE;
1655 }
1656 void glColorPointer( GLint size, GLenum type, GLsizei stride, const GLvoid *pointer )
1657 {
1658 if (tmuState0.color_array.size == size &&
1659 tmuState0.color_array.stride == stride &&
1660 tmuState0.color_array.type == type &&
1661 tmuState0.color_array.ptr == pointer)
1662 {
1663 return;
1664 }
1665 tmuState0.color_array.size = size;
1666 tmuState0.color_array.stride = stride;
1667 tmuState0.color_array.type = type;
1668 tmuState0.color_array.ptr = (GLvoid*)pointer;
1669 tmuState0.color_array.changed = GL_TRUE;
1670 }
1671 void glPolygonOffset( GLfloat factor, GLfloat units )
1672 {
1673 FlushOnStateChange();
1674 glEsImpl->glPolygonOffset(factor, units);
1675 }
1676 void glStencilMask( GLuint mask ) {}
1677 void glClearStencil( GLint s ) {}
1678
1679 #if defined(__MULTITEXTURE_SUPPORT__)
1680
1681 extern "C" void glMultiTexCoord2fARB( GLenum target, GLfloat s, GLfloat t );
1682
1683 void glMultiTexCoord2fARB( GLenum target, GLfloat s, GLfloat t )
1684 {
1685 if (target == GL_TEXTURE0)
1686 {
1687 glTexCoord2f(s,t);
1688 }
1689 else
1690 {
1691 currentVertexAttrib.s_multi = s;
1692 currentVertexAttrib.t_multi = t;
1693 }
1694 }
1695 #endif
1696
1697 /* Vladimir */
1698 void glDrawArrays( GLenum mode, int first, int count)
1699 {
1700 FlushOnStateChange();
1701 glEsImpl->glDrawArrays(mode, first , count);
1702 }
1703 void glMultMatrixf (const GLfloat *m)
1704 {
1705 FlushOnStateChange();
1706 glEsImpl->glMultMatrixf(m);
1707 }
1708
1709 void glPixelStorei (GLenum pname, GLint param)
1710 {
1711 FlushOnStateChange();
1712 glEsImpl->glPixelStorei(pname, param);
1713 }
1714
1715
1716 void glFogf (GLenum pname, GLfloat param)
1717 {
1718 FlushOnStateChange();
1719 glEsImpl->glFogf(pname, param);
1720 }
1721
1722 void glFogfv (GLenum pname, const GLfloat *params)
1723 {
1724 FlushOnStateChange();
1725 glEsImpl->glFogfv(pname, params);
1726 }
1727
1728 void glGetTexParameteriv (GLenum target, GLenum pname, GLint *params)
1729 {
1730 FlushOnStateChange();
1731 glEsImpl->glGetTexParameteriv(target, pname, params);
1732 }
1733
1734
1735 // This gives: called unimplemented OpenGL ES API (Android)
1736 void glTexParameteri (GLenum target, GLenum pname, GLint param)
1737 {
1738 if (pname == GL_TEXTURE_BORDER_COLOR) {
1739 return; // not supported by opengl es
1740 }
1741 if ( (pname == GL_TEXTURE_WRAP_S ||
1742 pname == GL_TEXTURE_WRAP_T) &&
1743 param == GL_CLAMP) {
1744 param = 0x812F;
1745 }
1746
1747 FlushOnStateChange();
1748 glEsImpl->glTexParameteri(target, pname, param);
1749 }
1750
1751 void glTexParameterx (GLenum target, GLenum pname, GLfixed param)
1752 {
1753 if (pname == GL_TEXTURE_BORDER_COLOR) {
1754 return; // not supported by opengl es
1755 }
1756 if ( (pname == GL_TEXTURE_WRAP_S ||
1757 pname == GL_TEXTURE_WRAP_T) &&
1758 param == GL_CLAMP) {
1759 param = 0x812F;
1760 }
1761 FlushOnStateChange();
1762 glEsImpl->glTexParameterx(target, pname, param);
1763 }
1764
1765 void glGenTextures (GLsizei n, GLuint *textures)
1766 {
1767 FlushOnStateChange();
1768 glEsImpl->glGenTextures(n, textures);
1769 }
1770
1771 void glFrontFace (GLenum mode)
1772 {
1773 FlushOnStateChange();
1774 glEsImpl->glFrontFace(mode);
1775 }
1776
1777
1778
1779 // End Vladimir
1780
1781
1782