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 GLboolean stupidglesbug;
64 GLclampf depth_range_near;
65 GLclampf depth_range_far;
66 GLenum depth_func;
67 GLenum cullface;
68 GLenum shademodel;
69 GLenum sfactor;
70 GLenum dfactor;
71 GLenum matrixmode;
72 };
77 {
78 GL_FALSE,
79 GL_FALSE,
80 GL_FALSE,
81 GL_FALSE,
82 GL_FALSE,
83 GL_FALSE,
84 GL_FALSE,
85 GL_TRUE,
86 GL_FALSE,
87 GL_FALSE,
88 GL_FALSE,
89 GL_FALSE,
90 GL_FALSE,
91 GL_TRUE,
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_FALSE,
102 GL_TRUE,
103 GL_FALSE,
106 GL_LESS,
107 GL_BACK,
108 GL_SMOOTH,
109 GL_ONE,
110 GL_ZERO,
111 GL_MODELVIEW,
112 };
114 struct booleanstate
115 {
116 GLboolean value;
117 GLboolean changed;
118 };
120 struct floatstate
121 {
122 GLfloat value;
123 GLboolean changed;
124 };
126 struct uintstate
127 {
128 GLuint value;
129 GLboolean changed;
130 };
132 struct ptrstate
133 {
134 GLint size;
135 GLenum type;
136 GLsizei stride;
138 GLboolean changed;
139 GLboolean enabled;
140 };
142 struct nanotmuState
143 {
151 };
157 {
165 };
176 #if defined( __MULTITEXTURE_SUPPORT__ )
178 #endif
180 #if !defined( __WINS__ )
181 //#define __FORCEINLINE __forceinline
182 #define __FORCEINLINE inline
183 #else
184 #define __FORCEINLINE
185 #endif
190 struct VertexAttrib
191 {
195 #if !defined( __MULTITEXTURE_SUPPORT__ )
197 #endif
205 #if defined( __MULTITEXTURE_SUPPORT__ )
208 #endif
209 };
224 #if defined( __MULTITEXTURE_SUPPORT__ )
225 static VertexAttrib currentVertexAttribInit = {0.0f, 0.0f, 0.0f, 255, 255, 255, 255, 0.0f, 0.0f, 0.0f, 0.0f};
226 #else
229 };
230 #endif
236 {
258 }
261 {
264 {
266 }
267 else
268 {
270 }
273 {
275 }
276 else
277 {
279 }
282 {
284 }
285 else
286 {
288 }
291 {
293 }
294 else
295 {
297 }
320 glEsImpl->glColor4f( currentVertexAttrib.red, currentVertexAttrib.green, currentVertexAttrib.blue, currentVertexAttrib.alpha );
324 //glEsImpl->glBindTexture(GL_TEXTURE_2D, stackTextureState);
326 glEsImpl->glTexEnvi( GL_TEXTURE_ENV, GL_TEXTURE_ENV_MODE, activetmuState->texture_env_mode.value );
329 }
332 {
334 {
336 #ifndef USE_CORE_PROFILE
338 #endif
339 }
345 {
353 #if defined( __MULTITEXTURE_SUPPORT__ )
358 #endif
360 }
364 #if defined( __MULTITEXTURE_SUPPORT__ )
366 #endif
373 }
375 {
377 }
379 {
381 }
383 {
388 }
391 {
392 vertexCount += ( (unsigned char *)ptrVertexAttribArray - (unsigned char *)ptrVertexAttribArrayMark ) / sizeof( VertexAttrib );
394 {
396 }
398 {
400 {
409 }
412 {
415 {
420 }
421 }
424 {
431 {
435 indexCount++;
442 {
447 }
450 {
454 indexCount++;
455 }
456 }
457 else
458 {
459 //already aligned
465 {
470 }
473 {
478 indexCount++;
479 }
480 }
482 }
486 {
492 {
497 }
498 }
503 }
507 }
510 {
513 {
515 {
517 {
520 }
522 }
524 {
526 {
529 }
531 }
532 //case GL_CLIP_PLANEi
534 {
536 {
539 }
541 }
543 {
545 {
548 }
550 }
552 {
554 {
557 }
559 }
561 {
563 {
566 }
568 }
570 {
572 {
575 }
577 }
579 //case GL_LIGHTi
580 {
582 {
585 }
587 }
589 {
591 {
594 }
596 }
598 {
600 {
603 }
605 }
606 /* case GL_MATRIX_PALETTE_OES:
607 {
608 if (!nanoglState.matrix_palette_oes)
609 {
610 nanoglState.matrix_palette_oes = GL_TRUE;
611 statechanged = GL_TRUE;
612 }
613 break;
614 }*/
616 {
618 {
621 }
623 }
625 {
627 {
630 }
632 }
633 /* case GL_POINT_SPRITE_OES:
634 {
635 if (!nanoglState.point_sprite_oes)
636 {
637 nanoglState.point_sprite_oes = GL_TRUE;
638 statechanged = GL_TRUE;
639 }
640 break;
641 }*/
643 {
645 {
648 }
650 }
652 {
654 {
657 }
659 }
661 {
663 {
666 }
668 }
670 {
672 {
675 }
677 }
679 {
681 {
684 }
686 }
688 {
690 {
693 }
695 }
697 {
699 /* if (!nanoglState.stencil_test)
700 {
701 nanoglState.stencil_test = GL_TRUE;
702 statechanged = GL_TRUE;
703 }*/
705 }
707 {
709 {
714 }
716 }
719 }
722 {
725 }
726 }
729 {
732 {
734 {
736 {
739 }
741 }
743 {
745 {
748 }
750 }
751 //case GL_CLIP_PLANEi
753 {
755 {
758 }
760 }
762 {
764 {
767 }
769 }
771 {
773 {
776 }
778 }
780 {
782 {
785 }
787 }
789 {
791 {
794 }
796 }
798 //case GL_LIGHTi
799 {
801 {
804 }
806 }
808 {
810 {
813 }
815 }
817 {
819 {
822 }
824 }
825 /* case GL_MATRIX_PALETTE_OES:
826 {
827 if (nanoglState.matrix_palette_oes)
828 {
829 nanoglState.matrix_palette_oes = GL_FALSE;
830 statechanged = GL_TRUE;
831 }
832 break;
833 }*/
835 {
837 {
840 }
842 }
844 {
846 {
849 }
851 }
852 /* case GL_POINT_SPRITE_OES:
853 {
854 if (nanoglState.point_sprite_oes)
855 {
856 nanoglState.point_sprite_oes = GL_FALSE;
857 statechanged = GL_TRUE;
858 }
859 break;
860 }*/
862 {
864 {
867 }
869 }
871 {
873 {
876 }
878 }
880 {
882 {
885 }
887 }
889 {
891 {
894 }
896 }
898 {
900 {
903 }
905 }
907 {
909 {
912 }
914 }
916 {
918 /* if (nanoglState.stencil_test)
919 {
920 nanoglState.stencil_test = GL_FALSE;
921 statechanged = GL_TRUE;
922 }*/
924 }
926 {
928 {
933 }
935 }
938 }
941 {
944 }
945 }
948 {
950 }
953 {
956 {
958 }
960 }
963 {
968 }
971 {
973 }
976 {
979 }
982 {
985 }
988 {
991 }
994 {
996 {
1000 }
1001 else
1002 {
1006 }
1008 }
1010 void glOrtho( GLfloat left, GLfloat right, GLfloat bottom, GLfloat top, GLfloat zNear, GLfloat zFar )
1011 {
1013 #ifdef USE_CORE_PROFILE
1015 #else
1017 #endif
1018 }
1021 {
1023 {
1025 }
1029 }
1032 {
1034 {
1036 }
1040 {
1042 }
1046 }
1049 {
1051 }
1053 void glTexImage2D( GLenum target, GLint level, GLint internalformat, GLsizei width, GLsizei height, GLint border, GLenum format, GLenum type, const GLvoid *pixels )
1054 {
1057 glEsImpl->glTexImage2D( target, level, internalformat, width, height, border, format, type, pixels );
1058 }
1061 {
1062 }
1065 {
1068 }
1071 {
1074 }
1077 {
1080 }
1083 {
1085 {
1087 }
1088 else
1089 {
1092 }
1094 #ifdef USE_CORE_PROFILE
1096 #else
1098 #endif
1099 }
1102 {
1104 {
1106 }
1107 else
1108 {
1110 }
1113 }
1116 {
1119 }
1122 {
1125 }
1128 {
1130 {
1132 }
1133 else
1134 {
1136 }
1139 }
1141 void glFrustum( GLfloat left, GLfloat right, GLfloat bottom, GLfloat top, GLfloat zNear, GLfloat zFar )
1142 {
1145 }
1148 {
1151 }
1154 {
1159 #if defined( __MULTITEXTURE_SUPPORT__ )
1161 #else
1163 #endif
1164 }
1167 {
1169 {
1173 }
1174 else
1175 {
1179 }
1181 }
1184 {
1189 }
1192 {
1193 //*((unsigned int*)(¤tVertexAttrib.red)) = *((unsigned int*)(v));
1195 {
1199 }
1200 else
1201 {
1205 }
1207 }
1210 {
1215 }
1217 //-- nicknekit: xash3d funcs --
1220 {
1222 {
1226 }
1227 else
1228 {
1232 }
1234 }
1237 {
1242 }
1245 {
1248 }
1250 void glCopyTexImage2D( GLenum target, GLint level, GLenum internalformat, GLint x, GLint y, GLsizei width, GLsizei height, GLint border )
1251 {
1254 }
1256 void glTexImage1D( GLenum target, GLint level, GLint internalformat, GLsizei width, GLint border, GLenum format, GLenum type, const GLvoid *pixels )
1257 {
1259 }
1261 void glTexImage3D( GLenum target, GLint level, GLint internalformat, GLsizei width, GLsizei height, GLsizei depth, GLint border, GLenum format, GLenum type, const GLvoid *pixels )
1262 {
1263 glTexImage2D( GL_TEXTURE_2D, level, internalformat, width, height, border, format, type, pixels );
1264 }
1266 void glTexSubImage1D( GLenum target, GLint level, GLint xoffset, GLsizei width, GLenum format, GLenum type, const GLvoid *pixels )
1267 {
1269 }
1275 GLenum format,
1277 {
1279 }
1282 {
1285 }
1288 {
1289 //for mirrors? not needed for original hl?
1290 }
1293 {
1294 //for mirrors? not needed for original hl?
1295 }
1297 //-- --//
1300 {
1303 }
1306 {
1308 {
1310 }
1313 {
1316 }
1317 else
1324 }
1327 {
1330 }
1333 {
1335 {
1337 }
1341 }
1344 {
1347 }
1350 {
1352 {
1354 {
1356 {
1358 }
1359 else
1360 {
1365 }
1366 }
1367 }
1370 }
1373 {
1376 #if defined( __MULTITEXTURE_SUPPORT__ )
1378 #else
1380 #endif
1381 }
1384 {
1386 {
1388 }
1392 }
1395 {
1397 {
1399 }
1403 }
1406 {
1409 }
1413 {
1416 {
1417 #if defined( __MULTITEXTURE_SUPPORT__ )
1418 sprintf( (char *)nano_extensions_string, "%s %s", glEsImpl->glGetString( name ), "GL_ARB_multitexture EXT_texture_env_add" );
1419 #else
1420 sprintf( (char *)nano_extensions_string, "%s %s", glEsImpl->glGetString( name ), "EXT_texture_env_add" );
1421 #endif
1423 }
1425 }
1428 {
1431 }
1434 {
1437 }
1439 void glReadPixels( GLint x, GLint y, GLsizei width, GLsizei height, GLenum format, GLenum type, GLvoid *pixels )
1440 {
1442 {
1443 // OpenglEs 1.1 does not support reading depth buffer without an extension
1446 }
1449 }
1452 {
1453 }
1456 {
1459 }
1461 void glTexSubImage2D( GLenum target, GLint level, GLint xoffset, GLint yoffset, GLsizei width, GLsizei height, GLenum format, GLenum type, const GLvoid *pixels )
1462 {
1464 glEsImpl->glTexSubImage2D( target, level, xoffset, yoffset, width, height, format, type, pixels );
1465 }
1468 {
1471 }
1474 {
1475 //FlushOnStateChange();
1477 }
1480 {
1482 {
1484 }
1486 {
1488 }
1489 else
1490 {
1493 }
1495 {
1497 }
1498 else
1499 {
1501 }
1503 }
1506 {
1508 }
1511 {
1512 }
1515 {
1518 }
1521 {
1524 }
1527 {
1535 }
1538 {
1541 }
1544 {
1547 }
1550 {
1551 }
1553 {
1554 }
1556 {
1557 }
1559 {
1560 }
1562 {
1563 }
1565 {
1566 }
1573 {
1574 // ensure that all primitives specified between glBegin/glEnd pairs
1575 // are rendered first, and that we have correct tmu in use..
1577 // setup correct vertex/color/texcoord pointers
1582 {
1584 }
1586 {
1588 {
1590 }
1591 else
1592 {
1594 }
1600 }
1602 {
1604 {
1606 }
1607 else
1608 {
1610 }
1616 }
1618 {
1620 {
1622 }
1623 else
1624 {
1626 }
1631 }
1633 {
1636 {
1638 }
1639 else
1640 {
1642 }
1647 }
1650 {
1654 {
1656 }
1657 else
1658 {
1660 }
1665 }
1669 }
1672 {
1675 {
1677 }
1679 {
1681 }
1682 else
1683 {
1685 }
1687 {
1690 {
1692 }
1698 {
1700 }
1707 {
1709 }
1716 {
1718 }
1724 }
1725 }
1727 {
1730 {
1732 }
1734 {
1736 }
1737 else
1738 {
1740 }
1742 {
1745 {
1747 }
1753 {
1755 }
1762 {
1764 }
1771 {
1773 }
1779 }
1780 }
1782 {
1787 {
1789 }
1795 }
1797 {
1800 {
1802 }
1804 {
1806 }
1811 {
1813 }
1819 }
1821 {
1826 {
1828 }
1834 }
1837 {
1843 {
1845 }
1851 }
1853 {
1856 }
1858 {
1859 }
1861 {
1862 }
1864 #if defined( __MULTITEXTURE_SUPPORT__ )
1869 {
1871 {
1873 }
1874 else
1875 {
1878 }
1879 }
1880 #endif
1882 /* Vladimir */
1883 /*void glDrawArrays( GLenum mode, int first, int count)
1884 {
1885 FlushOnStateChange();
1886 glEsImpl->glDrawArrays(mode, first , count);
1887 }*/
1889 {
1892 }
1895 {
1898 }
1901 {
1904 }
1907 {
1910 }
1913 {
1916 }
1918 // This gives: called unimplemented OpenGL ES API (Android)
1920 {
1922 {
1924 }
1928 {
1930 }
1934 }
1937 {
1939 {
1941 }
1945 {
1947 }
1950 }
1953 {
1956 }
1959 {
1962 }
1963 // End Vladimir
1966 {
1968 {
1970 {
1972 {
1974 }
1975 else
1976 {
1981 }
1982 }
1983 }
1986 }
1988 #ifdef __MULTITEXTURE_SUPPORT__
1990 {
1992 }
1995 {
1996 }
1997 #endif
1999 {
2000 // ensure that all primitives specified between glBegin/glEnd pairs
2001 // are rendered first, and that we have correct tmu in use..
2005 // setup correct vertex/color/texcoord pointers
2010 {
2012 }
2014 {
2016 {
2018 }
2019 else
2020 {
2022 }
2028 }
2030 {
2032 {
2034 }
2035 else
2036 {
2038 }
2044 }
2046 {
2048 {
2050 }
2051 else
2052 {
2054 }
2059 }
2061 {
2064 {
2066 }
2067 else
2068 {
2070 }
2075 }
2078 {
2082 {
2084 }
2085 else
2086 {
2088 }
2093 }
2097 }
2098 /*void glNormalPointer(GLenum type, GLsizei stride, const void *ptr)
2099 {
2100 glEsImpl->glNormalPointer( type, stride, ptr );
2101 }*/
2103 void glCopyTexSubImage2D( GLenum target, GLint level, GLint xoffset, GLint yoffset, GLint x, GLint y, GLsizei width, GLsizei height )
2104 {
2107 }
2110 {
2113 }
2116 {
2119 }
2122 {
2125 }
2128 {
2131 }
2133 void glFramebufferRenderbuffer( GLenum target, GLenum attachment, GLenum renderbuffertarget, GLuint renderbuffer )
2134 {
2137 }
2140 {
2143 }
2146 {
2149 }
2150 void glFramebufferTexture2D( GLenum target, GLenum attachment, GLenum textarget, GLuint texture, GLint level )
2151 {
2154 }
2156 void glRenderbufferStorage( GLenum target, GLenum internalformat, GLsizei width, GLsizei height )
2157 {
2160 }