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 light0;
48 GLboolean light1;
49 GLboolean light2;
50 GLboolean light3;
51 GLboolean light4;
52 GLboolean light5;
53 GLboolean light6;
54 GLboolean light7;
55 GLboolean lighting;
56 GLboolean line_smooth;
57 GLboolean matrix_palette_oes;
58 GLboolean multisample;
59 GLboolean normalize;
60 GLboolean point_smooth;
61 GLboolean point_sprite_oes;
62 GLboolean polygon_offset_fill;
63 GLboolean rescale_normal;
64 GLboolean sample_alpha_to_coverage;
65 GLboolean sample_alpha_to_one;
66 GLboolean sample_coverage;
67 GLboolean scissor_test;
68 GLboolean stencil_test;
69 GLboolean depthmask;
70 GLclampd depth_range_near;
71 GLclampd depth_range_far;
72 GLenum depth_func;
73 GLenum cullface;
74 GLenum shademodel;
75 GLenum sfactor;
76 GLenum dfactor;
77 GLenum matrixmode;
78 };
83 {
84 GL_FALSE,
85 GL_FALSE,
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_FALSE,
103 GL_FALSE,
104 GL_TRUE,
105 GL_FALSE,
106 GL_FALSE,
107 GL_FALSE,
108 GL_FALSE,
109 GL_FALSE,
110 GL_FALSE,
111 GL_FALSE,
112 GL_FALSE,
113 GL_FALSE,
114 GL_FALSE,
115 GL_TRUE,
118 GL_LESS,
119 GL_BACK,
120 GL_SMOOTH,
121 GL_ONE,
122 GL_ZERO,
123 GL_MODELVIEW,
124 };
126 struct booleanstate
127 {
128 GLboolean value;
129 GLboolean changed;
130 };
132 struct floatstate
133 {
134 GLfloat value;
135 GLboolean changed;
136 };
138 struct uintstate
139 {
140 GLuint value;
141 GLboolean changed;
142 };
144 struct ptrstate
145 {
146 GLint size;
147 GLenum type;
148 GLsizei stride;
150 GLboolean changed;
151 GLboolean enabled;
152 };
154 struct nanotmuState
155 {
163 };
169 {
177 };
188 #if defined( __MULTITEXTURE_SUPPORT__ )
190 #endif
192 #if !defined( __WINS__ )
193 //#define __FORCEINLINE __forceinline
194 #define __FORCEINLINE inline
195 #else
196 #define __FORCEINLINE
197 #endif
202 struct VertexAttrib
203 {
207 #if !defined( __MULTITEXTURE_SUPPORT__ )
209 #endif
217 #if defined( __MULTITEXTURE_SUPPORT__ )
220 #endif
221 };
236 #if defined( __MULTITEXTURE_SUPPORT__ )
237 static VertexAttrib currentVertexAttribInit = {0.0f, 0.0f, 0.0f, 255, 255, 255, 255, 0.0f, 0.0f, 0.0f, 0.0f};
238 #else
241 };
242 #endif
250 {
272 }
275 {
278 {
280 }
281 else
282 {
284 }
287 {
289 }
290 else
291 {
293 }
296 {
298 }
299 else
300 {
302 }
305 {
307 }
308 else
309 {
311 }
339 //glEsImpl->glBindTexture(GL_TEXTURE_2D, stackTextureState);
341 glEsImpl->glTexEnvi( GL_TEXTURE_ENV, GL_TEXTURE_ENV_MODE, activetmuState->texture_env_mode.value );
345 }
348 {
352 {
354 #ifndef USE_CORE_PROFILE
356 #endif
357 }
363 {
371 #if defined( __MULTITEXTURE_SUPPORT__ )
376 #endif
378 }
382 #if defined( __MULTITEXTURE_SUPPORT__ )
384 #endif
391 }
393 {
395 }
397 {
399 }
401 {
406 }
409 {
410 vertexCount += ( (unsigned char *)ptrVertexAttribArray - (unsigned char *)ptrVertexAttribArrayMark ) / sizeof( VertexAttrib );
412 {
414 }
416 {
418 {
427 }
430 {
433 {
438 }
439 }
442 {
449 {
453 indexCount++;
460 {
465 }
468 {
472 indexCount++;
473 }
474 }
475 else
476 {
477 //already aligned
483 {
488 }
491 {
496 indexCount++;
497 }
498 }
500 }
504 {
510 {
515 }
516 }
521 }
525 }
528 {
530 {
533 }
536 {
538 {
540 {
543 }
545 }
547 {
549 {
552 }
554 }
555 //case GL_CLIP_PLANEi
557 {
559 {
562 }
564 }
566 {
568 {
571 }
573 }
575 {
577 {
580 }
582 }
584 {
586 {
589 }
591 }
593 {
595 {
598 }
600 }
602 {
604 {
607 }
609 }
611 {
613 {
616 }
618 }
620 {
622 {
625 }
627 }
629 {
631 {
634 }
636 }
638 {
640 {
643 }
645 }
647 {
649 {
652 }
654 }
656 {
658 {
661 }
663 }
665 {
667 {
670 }
672 }
674 {
676 {
679 }
681 }
683 {
685 {
688 }
690 }
692 {
694 {
697 }
699 }
700 /* case GL_MATRIX_PALETTE_OES:
701 {
702 if (!nanoglState.matrix_palette_oes)
703 {
704 nanoglState.matrix_palette_oes = GL_TRUE;
705 statechanged = GL_TRUE;
706 }
707 break;
708 }*/
710 {
712 {
715 }
717 }
719 {
721 {
724 }
726 }
727 /* case GL_POINT_SPRITE_OES:
728 {
729 if (!nanoglState.point_sprite_oes)
730 {
731 nanoglState.point_sprite_oes = GL_TRUE;
732 statechanged = GL_TRUE;
733 }
734 break;
735 }*/
737 {
739 {
742 }
744 }
746 {
748 {
751 }
753 }
755 {
757 {
760 }
762 }
764 {
766 {
769 }
771 }
773 {
775 {
778 }
780 }
782 {
784 {
787 }
789 }
791 {
793 {
796 }
798 }
800 {
802 {
807 }
809 }
815 {
819 }
820 #endif
823 }
826 {
829 }
830 }
833 {
835 {
838 }
841 {
843 {
845 {
848 }
850 }
852 {
854 {
857 }
859 }
860 //case GL_CLIP_PLANEi
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 {
921 }
923 }
925 {
927 {
930 }
932 }
934 {
936 {
939 }
941 }
943 {
945 {
948 }
950 }
952 {
954 {
957 }
959 }
961 {
963 {
966 }
968 }
970 {
972 {
975 }
977 }
979 {
981 {
984 }
986 }
988 {
990 {
993 }
995 }
997 {
999 {
1002 }
1004 }
1005 /* case GL_MATRIX_PALETTE_OES:
1006 {
1007 if (nanoglState.matrix_palette_oes)
1008 {
1009 nanoglState.matrix_palette_oes = GL_FALSE;
1010 statechanged = GL_TRUE;
1011 }
1012 break;
1013 }*/
1015 {
1017 {
1020 }
1022 }
1024 {
1026 {
1029 }
1031 }
1032 /* case GL_POINT_SPRITE_OES:
1033 {
1034 if (nanoglState.point_sprite_oes)
1035 {
1036 nanoglState.point_sprite_oes = GL_FALSE;
1037 statechanged = GL_TRUE;
1038 }
1039 break;
1040 }*/
1042 {
1044 {
1047 }
1049 }
1051 {
1053 {
1056 }
1058 }
1060 {
1062 {
1065 }
1067 }
1069 {
1071 {
1074 }
1076 }
1078 {
1080 {
1083 }
1085 }
1087 {
1089 {
1092 }
1094 }
1096 {
1098 {
1101 }
1103 }
1105 {
1107 {
1112 }
1114 }
1115 #if 0
1120 {
1124 }
1125 #endif
1128 }
1131 {
1134 }
1135 }
1138 {
1140 }
1143 {
1146 {
1148 }
1150 }
1153 {
1158 }
1161 {
1163 }
1166 {
1169 }
1172 {
1175 }
1178 {
1181 }
1184 {
1189 }
1191 void glOrtho( GLdouble left, GLdouble right, GLdouble bottom, GLdouble top, GLdouble zNear, GLdouble zFar )
1192 {
1194 #ifdef USE_CORE_PROFILE
1196 #else
1198 #endif
1199 }
1201 // Rikku2000: Light
1203 {
1207 }
1209 {
1213 }
1215 {
1219 }
1221 {
1225 }
1227 {
1231 }
1233 {
1237 }
1239 {
1243 }
1246 {
1248 {
1250 }
1254 }
1257 {
1259 {
1261 }
1265 {
1267 }
1271 }
1274 {
1276 }
1278 void glTexImage2D( GLenum target, GLint level, GLint internalformat, GLsizei width, GLsizei height, GLint border, GLenum format, GLenum type, const GLvoid *pixels )
1279 {
1283 {
1290 {
1293 }
1294 }
1297 glEsImpl->glTexImage2D( target, level, internalformat, width, height, border, format, type, data );
1301 }
1304 {
1305 }
1308 {
1311 }
1314 {
1317 }
1320 {
1323 }
1326 {
1328 {
1330 }
1331 else
1332 {
1335 }
1337 #ifdef USE_CORE_PROFILE
1339 #else
1341 #endif
1342 }
1345 {
1347 {
1349 }
1350 else
1351 {
1353 }
1356 }
1359 {
1362 }
1365 {
1368 }
1371 {
1373 {
1375 }
1376 else
1377 {
1379 }
1382 }
1384 void glFrustum( GLdouble left, GLdouble right, GLdouble bottom, GLdouble top, GLdouble zNear, GLdouble zFar )
1385 {
1388 }
1391 {
1394 }
1397 {
1402 #if defined( __MULTITEXTURE_SUPPORT__ )
1404 #else
1406 #endif
1407 }
1410 {
1418 }
1421 {
1429 }
1432 {
1433 //*((unsigned int*)(¤tVertexAttrib.red)) = *((unsigned int*)(v));
1441 }
1444 {
1452 }
1454 //-- nicknekit: xash3d funcs --
1457 {
1465 }
1468 {
1476 }
1479 {
1482 }
1484 void glCopyTexImage2D( GLenum target, GLint level, GLenum internalformat, GLint x, GLint y, GLsizei width, GLsizei height, GLint border )
1485 {
1488 }
1490 void glTexImage1D( GLenum target, GLint level, GLint internalformat, GLsizei width, GLint border, GLenum format, GLenum type, const GLvoid *pixels )
1491 {
1493 }
1495 void glTexImage3D( GLenum target, GLint level, GLint internalformat, GLsizei width, GLsizei height, GLsizei depth, GLint border, GLenum format, GLenum type, const GLvoid *pixels )
1496 {
1497 glTexImage2D( GL_TEXTURE_2D, level, internalformat, width, height, border, format, type, pixels );
1498 }
1500 void glTexSubImage1D( GLenum target, GLint level, GLint xoffset, GLsizei width, GLenum format, GLenum type, const GLvoid *pixels )
1501 {
1503 }
1509 GLenum format,
1511 {
1513 }
1516 {
1519 }
1521 // TODO: add native normal/reflection map texgen support
1524 {
1526 //glEsImpl->glTexGeniOES( coord, pname, param );
1527 }
1530 {
1532 //glEsImpl->glTexGenfvOES( coord, pname, params );
1533 }
1535 //-- --//
1538 {
1541 }
1544 {
1546 {
1549 }
1551 {
1553 }
1559 }
1562 {
1565 }
1568 {
1570 {
1572 }
1576 }
1579 {
1582 }
1585 {
1587 {
1590 }
1592 {
1594 {
1596 {
1598 }
1599 else
1600 {
1605 }
1606 }
1607 }
1610 }
1613 {
1616 #if defined( __MULTITEXTURE_SUPPORT__ )
1618 #else
1620 #endif
1621 }
1624 {
1626 {
1628 {
1630 }
1633 }
1635 }
1638 {
1640 {
1643 }
1645 {
1647 }
1651 }
1654 {
1657 }
1661 {
1664 {
1665 #if defined( __MULTITEXTURE_SUPPORT__ )
1666 sprintf( (char *)nano_extensions_string, "%s %s", glEsImpl->glGetString( name ), "GL_ARB_multitexture EXT_texture_env_add" );
1667 #else
1668 sprintf( (char *)nano_extensions_string, "%s %s", glEsImpl->glGetString( name ), "EXT_texture_env_add" );
1669 #endif
1671 }
1673 }
1676 {
1679 }
1682 {
1685 }
1687 void glReadPixels( GLint x, GLint y, GLsizei width, GLsizei height, GLenum format, GLenum type, GLvoid *pixels )
1688 {
1690 {
1691 // OpenglEs 1.1 does not support reading depth buffer without an extension
1694 }
1697 }
1700 {
1701 }
1704 {
1707 }
1709 void glTexSubImage2D( GLenum target, GLint level, GLint xoffset, GLint yoffset, GLsizei width, GLsizei height, GLenum format, GLenum type, const GLvoid *pixels )
1710 {
1712 glEsImpl->glTexSubImage2D( target, level, xoffset, yoffset, width, height, format, type, pixels );
1713 }
1716 {
1719 }
1722 {
1723 //FlushOnStateChange();
1725 }
1728 {
1730 {
1733 }
1735 {
1737 }
1739 {
1741 }
1742 else
1743 {
1746 }
1748 {
1750 }
1751 else
1752 {
1754 }
1756 }
1759 {
1761 {
1764 }
1766 {
1768 }
1770 {
1772 }
1773 else
1774 {
1777 }
1779 {
1781 }
1782 else
1783 {
1785 }
1787 }
1790 {
1792 {
1795 }
1797 }
1799 {
1801 {
1804 }
1806 }
1810 {
1811 }
1814 {
1817 }
1820 {
1823 }
1826 {
1834 }
1837 {
1840 }
1843 {
1846 }
1849 {
1850 }
1852 {
1853 }
1855 {
1856 }
1858 {
1861 }
1863 {
1866 }
1868 {
1871 }
1878 {
1880 {
1883 }
1884 // ensure that all primitives specified between glBegin/glEnd pairs
1885 // are rendered first, and that we have correct tmu in use..
1887 // setup correct vertex/color/texcoord pointers
1892 {
1894 }
1896 {
1898 {
1900 }
1901 else
1902 {
1904 }
1910 }
1912 {
1914 {
1916 }
1917 else
1918 {
1923 }
1929 }
1931 {
1933 {
1935 }
1936 else
1937 {
1939 }
1944 }
1946 {
1949 {
1951 }
1952 else
1953 {
1955 }
1960 }
1963 {
1967 {
1969 }
1970 else
1971 {
1973 }
1978 }
1982 }
1987 {
1989 {
1994 }
1997 {
1999 }
2001 {
2003 }
2004 else
2005 {
2007 }
2009 {
2012 {
2014 }
2020 {
2022 }
2029 {
2031 }
2038 {
2040 }
2046 }
2047 }
2049 {
2051 {
2056 }
2059 {
2061 }
2063 {
2065 }
2066 else
2067 {
2069 }
2071 {
2074 {
2076 }
2082 {
2084 }
2091 {
2093 }
2100 {
2102 }
2108 }
2109 }
2111 {
2114 {
2117 }
2122 {
2124 }
2130 }
2132 {
2134 {
2137 }
2140 {
2142 }
2144 {
2146 }
2151 {
2153 }
2159 }
2161 {
2166 {
2168 }
2174 }
2177 {
2183 {
2185 }
2191 }
2193 {
2196 }
2198 {
2201 }
2203 {
2206 }
2208 #if defined( __MULTITEXTURE_SUPPORT__ )
2213 {
2215 {
2217 }
2218 else
2219 {
2222 }
2223 }
2224 #endif
2226 /* Vladimir */
2227 /*void glDrawArrays( GLenum mode, int first, int count)
2228 {
2229 FlushOnStateChange();
2230 glEsImpl->glDrawArrays(mode, first , count);
2231 }*/
2233 {
2236 }
2239 {
2242 }
2245 {
2248 }
2251 {
2254 }
2257 {
2260 }
2263 {
2266 }
2268 // This gives: called unimplemented OpenGL ES API (Android)
2270 {
2272 {
2274 }
2278 {
2280 }
2284 }
2287 {
2289 {
2291 }
2295 {
2297 }
2300 }
2303 {
2306 }
2309 {
2312 }
2313 // End Vladimir
2316 {
2318 {
2321 }
2323 {
2325 {
2327 {
2329 }
2330 else
2331 {
2336 }
2337 }
2338 }
2341 }
2343 #ifdef __MULTITEXTURE_SUPPORT__
2345 {
2347 }
2350 {
2352 }
2353 #endif
2355 {
2357 {
2360 }
2361 // ensure that all primitives specified between glBegin/glEnd pairs
2362 // are rendered first, and that we have correct tmu in use..
2366 // setup correct vertex/color/texcoord pointers
2371 {
2373 }
2375 {
2377 {
2379 }
2380 else
2381 {
2383 }
2389 }
2391 {
2393 {
2395 }
2396 else
2397 {
2402 }
2408 }
2410 {
2412 {
2414 }
2415 else
2416 {
2418 }
2423 }
2425 {
2428 {
2430 }
2431 else
2432 {
2434 }
2439 }
2442 {
2446 {
2448 }
2449 else
2450 {
2452 }
2457 }
2461 }
2462 /*void glNormalPointer(GLenum type, GLsizei stride, const void *ptr)
2463 {
2464 glEsImpl->glNormalPointer( type, stride, ptr );
2465 }*/
2467 void glCopyTexSubImage2D( GLenum target, GLint level, GLint xoffset, GLint yoffset, GLint x, GLint y, GLsizei width, GLsizei height )
2468 {
2471 }
2474 {
2477 }
2480 {
2483 }
2486 {
2489 }
2492 {
2495 }
2497 void glFramebufferRenderbuffer( GLenum target, GLenum attachment, GLenum renderbuffertarget, GLuint renderbuffer )
2498 {
2501 }
2504 {
2507 }
2510 {
2513 }
2514 void glFramebufferTexture2D( GLenum target, GLenum attachment, GLenum textarget, GLuint texture, GLint level )
2515 {
2518 }
2520 void glRenderbufferStorage( GLenum target, GLenum internalformat, GLsizei width, GLsizei height )
2521 {
2524 }
2527 {
2539 {
2541 }
2543 }
2546 {
2548 }
2551 {
2553 }
2556 {
2558 }
2561 {
2563 }