1 /*
2 Copyright (C) 2007-2009 Olli Hinkka
4 This program is free software; you can redistribute it and/or
5 modify it under the terms of the GNU General Public License
6 as published by the Free Software Foundation; either version 2
7 of the License, or (at your option) any later version.
9 This program is distributed in the hope that it will be useful,
10 but WITHOUT ANY WARRANTY; without even the implied warranty of
11 MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE.
13 See the GNU General Public License for more details.
15 You should have received a copy of the GNU General Public License
16 along with this program; if not, write to the Free Software
17 Foundation, Inc., 59 Temple Place - Suite 330, Boston, MA 02111-1307, USA.
19 */
20 /*
21 #include <e32def.h>
22 #include <e32std.h>
23 */
25 #include <stdio.h>
26 #include <stdlib.h>
27 #include <string.h>
33 #define GL_TEXTURE0_ARB 0x84C0
34 #define GL_TEXTURE1_ARB 0x84C1
36 struct nanoState
37 {
38 GLboolean alpha_test;
39 GLboolean blend;
40 GLboolean clip_planei;
41 GLboolean color_logic_op;
42 GLboolean color_material;
43 GLboolean cull_face;
44 GLboolean depth_test;
45 GLboolean dither;
46 GLboolean fog;
47 GLboolean lighti;
48 GLboolean lighting;
49 GLboolean line_smooth;
50 GLboolean matrix_palette_oes;
51 GLboolean multisample;
52 GLboolean normalize;
53 GLboolean point_smooth;
54 GLboolean point_sprite_oes;
55 GLboolean polygon_offset_fill;
56 GLboolean rescale_normal;
57 GLboolean sample_alpha_to_coverage;
58 GLboolean sample_alpha_to_one;
59 GLboolean sample_coverage;
60 GLboolean scissor_test;
61 GLboolean stencil_test;
62 GLboolean depthmask;
63 GLclampf depth_range_near;
64 GLclampf depth_range_far;
65 GLenum depth_func;
66 GLenum cullface;
67 GLenum shademodel;
68 GLenum sfactor;
69 GLenum dfactor;
70 GLenum matrixmode;
71 };
76 {
77 GL_FALSE,
78 GL_FALSE,
79 GL_FALSE,
80 GL_FALSE,
81 GL_FALSE,
82 GL_FALSE,
83 GL_FALSE,
84 GL_TRUE,
85 GL_FALSE,
86 GL_FALSE,
87 GL_FALSE,
88 GL_FALSE,
89 GL_FALSE,
90 GL_TRUE,
91 GL_FALSE,
92 GL_FALSE,
93 GL_FALSE,
94 GL_FALSE,
95 GL_FALSE,
96 GL_FALSE,
97 GL_FALSE,
98 GL_FALSE,
99 GL_FALSE,
100 GL_FALSE,
101 GL_TRUE,
104 GL_LESS,
105 GL_BACK,
106 GL_SMOOTH,
107 GL_ONE,
108 GL_ZERO,
109 GL_MODELVIEW,
110 };
112 struct booleanstate
113 {
114 GLboolean value;
115 GLboolean changed;
116 };
118 struct floatstate
119 {
120 GLfloat value;
121 GLboolean changed;
122 };
124 struct uintstate
125 {
126 GLuint value;
127 GLboolean changed;
128 };
130 struct ptrstate
131 {
132 GLint size;
133 GLenum type;
134 GLsizei stride;
136 GLboolean changed;
137 GLboolean enabled;
138 };
141 struct nanotmuState
142 {
149 };
155 {
162 };
173 #if defined(__MULTITEXTURE_SUPPORT__)
175 #endif
178 #if !defined (__WINS__)
179 //#define __FORCEINLINE __forceinline
180 #define __FORCEINLINE inline
181 #else
182 #define __FORCEINLINE
183 #endif
189 {
193 #if !defined(__MULTITEXTURE_SUPPORT__)
195 #endif
203 #if defined(__MULTITEXTURE_SUPPORT__)
206 #endif
222 #if defined(__MULTITEXTURE_SUPPORT__)
227 };
228 #else
232 };
233 #endif
239 {
261 }
264 {
267 {
269 }
270 else
271 {
273 }
276 {
278 }
279 else
280 {
282 }
285 {
287 }
288 else
289 {
291 }
311 glEsImpl->glColor4f (currentVertexAttrib.red, currentVertexAttrib.green, currentVertexAttrib.blue, currentVertexAttrib.alpha);
315 //glEsImpl->glBindTexture(GL_TEXTURE_2D, stackTextureState);
317 glEsImpl->glTexEnvi(GL_TEXTURE_ENV, GL_TEXTURE_ENV_MODE, activetmuState->texture_env_mode.value);
320 }
323 {
325 {
328 }
334 {
342 #if defined(__MULTITEXTURE_SUPPORT__)
347 #endif
349 }
354 #if defined(__MULTITEXTURE_SUPPORT__)
356 #endif
363 }
365 {
367 }
369 {
371 }
373 {
378 }
381 {
382 vertexCount+=((unsigned char*)ptrVertexAttribArray-(unsigned char*)ptrVertexAttribArrayMark)/sizeof(VertexAttrib);
384 {
386 }
388 {
390 {
399 }
402 {
405 {
410 }
411 }
414 {
421 {
427 indexCount++;
434 {
439 }
442 {
446 indexCount++;
447 }
448 }
449 else
450 {
451 //already aligned
459 {
465 }
468 {
473 indexCount++;
474 }
475 }
477 }
481 {
488 {
493 }
494 }
499 }
500 }
503 {
506 {
508 {
510 {
513 }
515 }
517 {
519 {
522 }
524 }
525 //case GL_CLIP_PLANEi
527 {
529 {
532 }
534 }
536 {
538 {
541 }
543 }
545 {
547 {
550 }
552 }
554 {
556 {
559 }
561 }
563 {
565 {
568 }
570 }
572 //case GL_LIGHTi
573 {
575 {
578 }
580 }
582 {
584 {
587 }
589 }
591 {
593 {
596 }
598 }
599 /* case GL_MATRIX_PALETTE_OES:
600 {
601 if (!nanoglState.matrix_palette_oes)
602 {
603 nanoglState.matrix_palette_oes = GL_TRUE;
604 statechanged = GL_TRUE;
605 }
606 break;
607 }*/
609 {
611 {
614 }
616 }
618 {
620 {
623 }
625 }
626 /* case GL_POINT_SPRITE_OES:
627 {
628 if (!nanoglState.point_sprite_oes)
629 {
630 nanoglState.point_sprite_oes = GL_TRUE;
631 statechanged = GL_TRUE;
632 }
633 break;
634 }*/
636 {
638 {
641 }
643 }
645 {
647 {
650 }
652 }
654 {
656 {
659 }
661 }
663 {
665 {
668 }
670 }
672 {
674 {
677 }
679 }
681 {
683 {
686 }
688 }
690 {
692 /* if (!nanoglState.stencil_test)
693 {
694 nanoglState.stencil_test = GL_TRUE;
695 statechanged = GL_TRUE;
696 }*/
698 }
700 {
702 {
707 }
709 }
712 }
715 {
718 }
719 }
722 {
725 {
727 {
729 {
732 }
734 }
736 {
738 {
741 }
743 }
744 //case GL_CLIP_PLANEi
746 {
748 {
751 }
753 }
755 {
757 {
760 }
762 }
764 {
766 {
769 }
771 }
773 {
775 {
778 }
780 }
782 {
784 {
787 }
789 }
791 //case GL_LIGHTi
792 {
794 {
797 }
799 }
801 {
803 {
806 }
808 }
810 {
812 {
815 }
817 }
818 /* case GL_MATRIX_PALETTE_OES:
819 {
820 if (nanoglState.matrix_palette_oes)
821 {
822 nanoglState.matrix_palette_oes = GL_FALSE;
823 statechanged = GL_TRUE;
824 }
825 break;
826 }*/
828 {
830 {
833 }
835 }
837 {
839 {
842 }
844 }
845 /* case GL_POINT_SPRITE_OES:
846 {
847 if (nanoglState.point_sprite_oes)
848 {
849 nanoglState.point_sprite_oes = GL_FALSE;
850 statechanged = GL_TRUE;
851 }
852 break;
853 }*/
855 {
857 {
860 }
862 }
864 {
866 {
869 }
871 }
873 {
875 {
878 }
880 }
882 {
884 {
887 }
889 }
891 {
893 {
896 }
898 }
900 {
902 {
905 }
907 }
909 {
911 /* if (nanoglState.stencil_test)
912 {
913 nanoglState.stencil_test = GL_FALSE;
914 statechanged = GL_TRUE;
915 }*/
917 }
919 {
921 {
928 }
930 }
933 }
936 {
939 }
940 }
943 {
945 }
949 {
952 {
954 }
956 }
959 {
964 }
968 {
970 }
974 {
977 }
980 {
983 }
986 {
989 }
992 {
997 }
999 void glOrtho (GLfloat left, GLfloat right, GLfloat bottom, GLfloat top, GLfloat zNear, GLfloat zFar)
1000 {
1003 }
1006 {
1008 {
1010 }
1014 }
1017 {
1019 {
1021 }
1025 {
1027 }
1031 }
1034 {
1036 }
1038 void glTexImage2D (GLenum target, GLint level, GLint internalformat, GLsizei width, GLsizei height, GLint border, GLenum format, GLenum type, const GLvoid *pixels)
1039 {
1042 glEsImpl->glTexImage2D(target, level, internalformat, width, height,border,format,type,pixels);
1043 }
1046 {
1047 }
1050 {
1053 }
1056 {
1059 }
1062 {
1065 }
1068 {
1070 {
1072 }
1073 else
1074 {
1077 }
1080 }
1083 {
1085 {
1087 }
1088 else
1089 {
1091 }
1094 }
1097 {
1100 }
1103 {
1106 }
1109 {
1111 {
1113 }
1114 else
1115 {
1117 }
1120 }
1122 void glFrustum (GLfloat left, GLfloat right, GLfloat bottom, GLfloat top, GLfloat zNear, GLfloat zFar)
1123 {
1126 }
1129 {
1132 }
1136 {
1141 #if defined(__MULTITEXTURE_SUPPORT__)
1143 #else
1145 #endif
1147 }
1150 {
1155 }
1158 {
1163 }
1166 {
1167 //*((unsigned int*)(¤tVertexAttrib.red)) = *((unsigned int*)(v));
1172 }
1175 {
1180 }
1182 //-- nicknekit: xash3d funcs --
1185 {
1190 }
1193 {
1198 }
1201 {
1204 }
1206 void glCopyTexImage2D( GLenum target, GLint level, GLenum internalformat, GLint x, GLint y, GLsizei width, GLsizei height, GLint border )
1207 {
1210 }
1212 void glTexImage1D(GLenum target, GLint level, GLint internalformat, GLsizei width, GLint border, GLenum format, GLenum type, const GLvoid *pixels)
1213 {
1215 }
1217 void glTexImage3D(GLenum target, GLint level, GLint internalformat, GLsizei width, GLsizei height, GLsizei depth, GLint border, GLenum format, GLenum type, const GLvoid *pixels)
1218 {
1219 glTexImage2D(GL_TEXTURE_2D, level, internalformat, width, height, border, format, type, pixels);
1220 }
1222 void glTexSubImage1D( GLenum target, GLint level, GLint xoffset, GLsizei width, GLenum format, GLenum type, const GLvoid *pixels )
1223 {
1225 }
1231 GLenum format,
1233 {
1235 }
1240 {
1243 }
1247 {
1248 //for mirrors? not needed for original hl?
1249 }
1252 {
1253 //for mirrors? not needed for original hl?
1254 }
1256 //-- --//
1259 {
1262 }
1265 {
1267 {
1269 }
1274 }
1277 {
1280 }
1283 {
1285 {
1287 }
1291 }
1294 {
1297 }
1300 {
1302 {
1304 {
1306 {
1308 }
1309 else
1310 {
1315 }
1316 }
1317 }
1320 }
1323 {
1326 #if defined(__MULTITEXTURE_SUPPORT__)
1328 #else
1330 #endif
1331 }
1335 {
1337 {
1339 }
1343 }
1346 {
1348 {
1350 }
1354 }
1358 {
1361 }
1365 {
1368 {
1369 #if defined(__MULTITEXTURE_SUPPORT__)
1370 sprintf((char*)nano_extensions_string,"%s %s",glEsImpl->glGetString(name),"GL_ARB_multitexture EXT_texture_env_add");
1371 #else
1372 sprintf((char*)nano_extensions_string,"%s %s",glEsImpl->glGetString(name),"EXT_texture_env_add");
1373 #endif
1375 }
1377 }
1380 {
1383 }
1386 {
1389 }
1391 void glReadPixels (GLint x, GLint y, GLsizei width, GLsizei height, GLenum format, GLenum type, GLvoid *pixels)
1392 {
1394 {
1395 // OpenglEs 1.1 does not support reading depth buffer without an extension
1398 }
1401 }
1404 {
1406 }
1409 {
1412 }
1414 void glTexSubImage2D (GLenum target, GLint level, GLint xoffset, GLint yoffset, GLsizei width, GLsizei height, GLenum format, GLenum type, const GLvoid *pixels)
1415 {
1418 }
1421 {
1424 }
1427 {
1428 //FlushOnStateChange();
1430 }
1433 {
1435 {
1437 }
1439 {
1441 }
1442 else
1443 {
1446 }
1448 {
1450 }
1451 else
1452 {
1454 }
1456 }
1459 {
1461 }
1464 {
1465 }
1468 {
1471 }
1474 {
1477 }
1480 {
1488 }
1491 {
1494 }
1497 {
1500 }
1514 {
1515 // ensure that all primitives specified between glBegin/glEnd pairs
1516 // are rendered first, and that we have correct tmu in use..
1518 // setup correct vertex/color/texcoord pointers
1523 {
1525 }
1527 {
1529 {
1531 }
1532 else
1533 {
1535 }
1541 }
1543 {
1545 {
1547 }
1548 else
1549 {
1551 }
1557 }
1559 {
1562 {
1564 }
1565 else
1566 {
1568 }
1573 }
1576 {
1580 {
1582 }
1583 else
1584 {
1586 }
1591 }
1595 }
1598 {
1601 {
1603 }
1605 {
1607 }
1608 else
1609 {
1611 }
1613 {
1616 {
1618 }
1624 {
1626 }
1633 {
1635 }
1641 }
1642 }
1644 {
1647 {
1649 }
1651 {
1653 }
1654 else
1655 {
1657 }
1659 {
1662 {
1664 }
1670 {
1672 }
1679 {
1681 }
1687 }
1688 }
1690 {
1695 {
1697 }
1703 }
1705 {
1708 {
1710 }
1712 {
1714 }
1719 {
1721 }
1727 }
1729 {
1734 {
1736 }
1742 }
1744 {
1747 }
1751 #if defined(__MULTITEXTURE_SUPPORT__)
1756 {
1758 {
1760 }
1761 else
1762 {
1765 }
1766 }
1767 #endif
1769 /* Vladimir */
1771 {
1774 }
1776 {
1779 }
1782 {
1785 }
1789 {
1792 }
1795 {
1798 }
1801 {
1804 }
1807 // This gives: called unimplemented OpenGL ES API (Android)
1809 {
1812 }
1817 }
1821 }
1824 {
1827 }
1832 }
1835 }
1838 {
1841 }
1844 {
1847 }
1851 // End Vladimir