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
249 #define STACK_ATTRIB_ENABLE_BIT_LEN (sizeof(stackAttribEnableBit) / sizeof(stackAttribEnableBit[0]))
251 {
252 GL_ALPHA_TEST,
253 GL_BLEND,
254 GL_CLIP_PLANE0,
255 GL_CLIP_PLANE1,
256 GL_CLIP_PLANE2,
257 GL_CLIP_PLANE3,
258 GL_CLIP_PLANE4,
259 GL_CLIP_PLANE5,
260 GL_COLOR_MATERIAL,
261 GL_CULL_FACE,
262 GL_DEPTH_TEST,
263 GL_DITHER,
264 GL_FOG,
265 GL_LIGHT0,
266 GL_LIGHT1,
267 GL_LIGHT2,
268 GL_LIGHT3,
269 GL_LIGHT4,
270 GL_LIGHT5,
271 GL_LIGHT6,
272 GL_LIGHT7,
273 GL_LIGHTING,
274 GL_LINE_SMOOTH,
275 GL_COLOR_LOGIC_OP,
276 GL_MULTISAMPLE,
277 GL_NORMALIZE,
278 GL_POINT_SMOOTH,
279 GL_POLYGON_OFFSET_LINE,
280 GL_POLYGON_OFFSET_FILL,
281 GL_POLYGON_OFFSET_POINT,
282 GL_POLYGON_SMOOTH,
283 GL_POLYGON_STIPPLE,
284 GL_SAMPLE_ALPHA_TO_COVERAGE,
285 GL_SAMPLE_ALPHA_TO_ONE,
286 GL_SAMPLE_COVERAGE,
287 GL_SCISSOR_TEST,
288 GL_STENCIL_TEST,
289 GL_TEXTURE_1D,
290 GL_TEXTURE_2D,
291 GL_TEXTURE_GEN_S,
292 GL_TEXTURE_GEN_T,
293 GL_TEXTURE_GEN_R,
294 GL_TEXTURE_GEN_Q,
295 };
297 #define MAX_ATTRIB_STACK 16
298 struct attribStore
299 {
300 GLbitfield mask;
302 };
308 {
333 }
336 {
339 {
341 }
342 else
343 {
345 }
348 {
350 }
351 else
352 {
354 }
357 {
359 }
360 else
361 {
363 }
366 {
368 }
369 else
370 {
372 }
400 //glEsImpl->glBindTexture(GL_TEXTURE_2D, stackTextureState);
402 glEsImpl->glTexEnvi( GL_TEXTURE_ENV, GL_TEXTURE_ENV_MODE, activetmuState->texture_env_mode.value );
409 }
412 {
416 {
418 #ifndef USE_CORE_PROFILE
420 #endif
421 }
427 {
435 #if defined( __MULTITEXTURE_SUPPORT__ )
440 #endif
442 }
446 #if defined( __MULTITEXTURE_SUPPORT__ )
448 #endif
455 }
457 {
459 }
461 {
463 }
465 {
470 }
473 {
474 vertexCount += ( (unsigned char *)ptrVertexAttribArray - (unsigned char *)ptrVertexAttribArrayMark ) / sizeof( VertexAttrib );
476 {
478 }
480 {
482 {
491 }
494 {
497 {
502 }
503 }
506 {
513 {
517 indexCount++;
524 {
529 }
532 {
536 indexCount++;
537 }
538 }
539 else
540 {
541 //already aligned
547 {
552 }
555 {
560 indexCount++;
561 }
562 }
564 }
568 {
574 {
579 }
580 }
585 }
589 }
592 {
594 {
597 }
600 {
602 {
604 {
607 }
609 }
611 {
613 {
616 }
618 }
619 //case GL_CLIP_PLANEi
621 {
623 {
626 }
628 }
630 {
632 {
635 }
637 }
639 {
641 {
644 }
646 }
648 {
650 {
653 }
655 }
657 {
659 {
662 }
664 }
666 {
668 {
671 }
673 }
675 {
677 {
680 }
682 }
684 {
686 {
689 }
691 }
693 {
695 {
698 }
700 }
702 {
704 {
707 }
709 }
711 {
713 {
716 }
718 }
720 {
722 {
725 }
727 }
729 {
731 {
734 }
736 }
738 {
740 {
743 }
745 }
747 {
749 {
752 }
754 }
756 {
758 {
761 }
763 }
764 /* case GL_MATRIX_PALETTE_OES:
765 {
766 if (!nanoglState.matrix_palette_oes)
767 {
768 nanoglState.matrix_palette_oes = GL_TRUE;
769 statechanged = GL_TRUE;
770 }
771 break;
772 }*/
774 {
776 {
779 }
781 }
783 {
785 {
788 }
790 }
791 /* case GL_POINT_SPRITE_OES:
792 {
793 if (!nanoglState.point_sprite_oes)
794 {
795 nanoglState.point_sprite_oes = GL_TRUE;
796 statechanged = GL_TRUE;
797 }
798 break;
799 }*/
801 {
803 {
806 }
808 }
810 {
812 {
815 }
817 }
819 {
821 {
824 }
826 }
828 {
830 {
833 }
835 }
837 {
839 {
842 }
844 }
846 {
848 {
851 }
853 }
855 {
857 {
860 }
862 }
864 {
866 {
871 }
873 }
879 {
883 }
884 #endif
887 }
890 {
893 }
894 }
897 {
899 {
902 }
905 {
907 {
909 {
912 }
914 }
916 {
918 {
921 }
923 }
924 //case GL_CLIP_PLANEi
926 {
928 {
931 }
933 }
935 {
937 {
940 }
942 }
944 {
946 {
949 }
951 }
953 {
955 {
958 }
960 }
962 {
964 {
967 }
969 }
971 {
973 {
976 }
978 }
980 {
982 {
985 }
987 }
989 {
991 {
994 }
996 }
998 {
1000 {
1003 }
1005 }
1007 {
1009 {
1012 }
1014 }
1016 {
1018 {
1021 }
1023 }
1025 {
1027 {
1030 }
1032 }
1034 {
1036 {
1039 }
1041 }
1043 {
1045 {
1048 }
1050 }
1052 {
1054 {
1057 }
1059 }
1061 {
1063 {
1066 }
1068 }
1069 /* case GL_MATRIX_PALETTE_OES:
1070 {
1071 if (nanoglState.matrix_palette_oes)
1072 {
1073 nanoglState.matrix_palette_oes = GL_FALSE;
1074 statechanged = GL_TRUE;
1075 }
1076 break;
1077 }*/
1079 {
1081 {
1084 }
1086 }
1088 {
1090 {
1093 }
1095 }
1096 /* case GL_POINT_SPRITE_OES:
1097 {
1098 if (nanoglState.point_sprite_oes)
1099 {
1100 nanoglState.point_sprite_oes = GL_FALSE;
1101 statechanged = GL_TRUE;
1102 }
1103 break;
1104 }*/
1106 {
1108 {
1111 }
1113 }
1115 {
1117 {
1120 }
1122 }
1124 {
1126 {
1129 }
1131 }
1133 {
1135 {
1138 }
1140 }
1142 {
1144 {
1147 }
1149 }
1151 {
1153 {
1156 }
1158 }
1160 {
1162 {
1165 }
1167 }
1169 {
1171 {
1176 }
1178 }
1179 #if 0
1184 {
1188 }
1189 #endif
1192 }
1195 {
1198 }
1199 }
1202 {
1204 }
1207 {
1210 {
1212 }
1214 }
1217 {
1222 }
1225 {
1227 }
1230 {
1233 }
1236 {
1239 }
1242 {
1245 }
1248 {
1253 }
1255 void glOrtho( GLdouble left, GLdouble right, GLdouble bottom, GLdouble top, GLdouble zNear, GLdouble zFar )
1256 {
1258 #ifdef USE_CORE_PROFILE
1260 #else
1262 #endif
1263 }
1265 // Rikku2000: Light
1267 {
1271 }
1273 {
1277 }
1279 {
1283 }
1285 {
1289 }
1291 {
1295 }
1297 {
1301 }
1303 {
1307 }
1310 {
1312 {
1314 }
1318 }
1321 {
1323 {
1325 }
1329 {
1331 }
1335 }
1338 {
1340 }
1342 void glTexImage2D( GLenum target, GLint level, GLint internalformat, GLsizei width, GLsizei height, GLint border, GLenum format, GLenum type, const GLvoid *pixels )
1343 {
1347 {
1354 {
1357 }
1358 }
1361 glEsImpl->glTexImage2D( target, level, internalformat, width, height, border, format, type, data );
1365 }
1368 {
1369 }
1372 {
1375 }
1378 {
1381 }
1384 {
1387 }
1390 {
1392 {
1394 }
1395 else
1396 {
1399 }
1401 #ifdef USE_CORE_PROFILE
1403 #else
1405 #endif
1406 }
1409 {
1411 {
1413 }
1414 else
1415 {
1417 }
1420 }
1423 {
1426 }
1429 {
1432 }
1435 {
1437 {
1439 }
1440 else
1441 {
1443 }
1446 }
1448 void glFrustum( GLdouble left, GLdouble right, GLdouble bottom, GLdouble top, GLdouble zNear, GLdouble zFar )
1449 {
1452 }
1455 {
1458 }
1461 {
1466 #if defined( __MULTITEXTURE_SUPPORT__ )
1468 #else
1470 #endif
1471 }
1474 {
1482 }
1485 {
1493 }
1496 {
1497 //*((unsigned int*)(¤tVertexAttrib.red)) = *((unsigned int*)(v));
1505 }
1508 {
1516 }
1518 //-- nicknekit: xash3d funcs --
1521 {
1529 }
1532 {
1540 }
1543 {
1546 }
1548 void glCopyTexImage2D( GLenum target, GLint level, GLenum internalformat, GLint x, GLint y, GLsizei width, GLsizei height, GLint border )
1549 {
1552 }
1554 void glTexImage1D( GLenum target, GLint level, GLint internalformat, GLsizei width, GLint border, GLenum format, GLenum type, const GLvoid *pixels )
1555 {
1557 }
1559 void glTexImage3D( GLenum target, GLint level, GLint internalformat, GLsizei width, GLsizei height, GLsizei depth, GLint border, GLenum format, GLenum type, const GLvoid *pixels )
1560 {
1561 glTexImage2D( GL_TEXTURE_2D, level, internalformat, width, height, border, format, type, pixels );
1562 }
1564 void glTexSubImage1D( GLenum target, GLint level, GLint xoffset, GLsizei width, GLenum format, GLenum type, const GLvoid *pixels )
1565 {
1567 }
1573 GLenum format,
1575 {
1577 }
1580 {
1583 }
1585 // TODO: add native normal/reflection map texgen support
1588 {
1590 //glEsImpl->glTexGeniOES( coord, pname, param );
1591 }
1594 {
1596 //glEsImpl->glTexGenfvOES( coord, pname, params );
1597 }
1599 //-- --//
1602 {
1605 }
1608 {
1610 {
1613 }
1615 {
1617 }
1623 }
1626 {
1629 }
1632 {
1634 {
1636 }
1640 }
1643 {
1646 }
1649 {
1651 {
1654 }
1656 {
1658 {
1660 {
1662 }
1663 else
1664 {
1669 }
1670 }
1671 }
1674 }
1677 {
1680 #if defined( __MULTITEXTURE_SUPPORT__ )
1682 #else
1684 #endif
1685 }
1688 {
1690 {
1692 {
1694 }
1697 }
1699 }
1702 {
1704 {
1707 }
1709 {
1711 }
1715 }
1718 {
1721 }
1725 {
1728 {
1729 #if defined( __MULTITEXTURE_SUPPORT__ )
1730 sprintf( (char *)nano_extensions_string, "%s %s", glEsImpl->glGetString( name ), "GL_ARB_multitexture EXT_texture_env_add" );
1731 #else
1732 sprintf( (char *)nano_extensions_string, "%s %s", glEsImpl->glGetString( name ), "EXT_texture_env_add" );
1733 #endif
1735 }
1737 }
1740 {
1743 }
1746 {
1749 }
1751 void glReadPixels( GLint x, GLint y, GLsizei width, GLsizei height, GLenum format, GLenum type, GLvoid *pixels )
1752 {
1754 {
1755 // OpenglEs 1.1 does not support reading depth buffer without an extension
1758 }
1761 }
1764 {
1765 }
1768 {
1771 }
1773 void glTexSubImage2D( GLenum target, GLint level, GLint xoffset, GLint yoffset, GLsizei width, GLsizei height, GLenum format, GLenum type, const GLvoid *pixels )
1774 {
1776 glEsImpl->glTexSubImage2D( target, level, xoffset, yoffset, width, height, format, type, pixels );
1777 }
1780 {
1783 }
1786 {
1787 //FlushOnStateChange();
1789 }
1792 {
1794 {
1797 }
1799 {
1801 }
1803 {
1805 }
1806 else
1807 {
1810 }
1812 {
1814 }
1815 else
1816 {
1818 }
1820 }
1823 {
1825 {
1828 }
1830 {
1832 }
1834 {
1836 }
1837 else
1838 {
1841 }
1843 {
1845 }
1846 else
1847 {
1849 }
1851 }
1854 {
1856 {
1859 }
1861 }
1863 {
1865 {
1868 }
1870 }
1874 {
1875 }
1878 {
1881 }
1884 {
1887 }
1890 {
1898 }
1901 {
1904 }
1907 {
1910 }
1913 {
1914 }
1916 {
1917 }
1919 {
1920 }
1922 {
1925 }
1927 {
1930 }
1932 {
1935 }
1942 {
1944 {
1947 }
1948 // ensure that all primitives specified between glBegin/glEnd pairs
1949 // are rendered first, and that we have correct tmu in use..
1951 // setup correct vertex/color/texcoord pointers
1956 {
1958 }
1960 {
1962 {
1964 }
1965 else
1966 {
1968 }
1974 }
1976 {
1978 {
1980 }
1981 else
1982 {
1987 }
1993 }
1995 {
1997 {
1999 }
2000 else
2001 {
2003 }
2008 }
2010 {
2013 {
2015 }
2016 else
2017 {
2019 }
2024 }
2027 {
2031 {
2033 }
2034 else
2035 {
2037 }
2042 }
2046 }
2051 {
2053 {
2058 }
2061 {
2063 }
2065 {
2067 }
2068 else
2069 {
2071 }
2073 {
2076 {
2078 }
2084 {
2086 }
2093 {
2095 }
2102 {
2104 }
2110 }
2111 }
2113 {
2115 {
2120 }
2123 {
2125 }
2127 {
2129 }
2130 else
2131 {
2133 }
2135 {
2138 {
2140 }
2146 {
2148 }
2155 {
2157 }
2164 {
2166 }
2172 }
2173 }
2175 {
2178 {
2181 }
2186 {
2188 }
2194 }
2196 {
2198 {
2201 }
2204 {
2206 }
2208 {
2210 }
2215 {
2217 }
2223 }
2225 {
2230 {
2232 }
2238 }
2241 {
2247 {
2249 }
2255 }
2257 {
2260 }
2262 {
2265 }
2267 {
2270 }
2272 #if defined( __MULTITEXTURE_SUPPORT__ )
2277 {
2279 {
2281 }
2282 else
2283 {
2286 }
2287 }
2288 #endif
2290 /* Vladimir */
2291 /*void glDrawArrays( GLenum mode, int first, int count)
2292 {
2293 FlushOnStateChange();
2294 glEsImpl->glDrawArrays(mode, first , count);
2295 }*/
2297 {
2300 }
2303 {
2306 }
2309 {
2312 }
2315 {
2318 }
2321 {
2324 }
2327 {
2330 }
2332 // This gives: called unimplemented OpenGL ES API (Android)
2334 {
2336 {
2338 }
2342 {
2344 }
2348 }
2351 {
2353 {
2355 }
2359 {
2361 }
2364 }
2367 {
2370 }
2373 {
2376 }
2377 // End Vladimir
2380 {
2382 {
2385 }
2387 {
2389 {
2391 {
2393 }
2394 else
2395 {
2400 }
2401 }
2402 }
2405 }
2407 #ifdef __MULTITEXTURE_SUPPORT__
2409 {
2411 }
2414 {
2416 }
2417 #endif
2419 {
2421 {
2424 }
2425 // ensure that all primitives specified between glBegin/glEnd pairs
2426 // are rendered first, and that we have correct tmu in use..
2430 // setup correct vertex/color/texcoord pointers
2435 {
2437 }
2439 {
2441 {
2443 }
2444 else
2445 {
2447 }
2453 }
2455 {
2457 {
2459 }
2460 else
2461 {
2466 }
2472 }
2474 {
2476 {
2478 }
2479 else
2480 {
2482 }
2487 }
2489 {
2492 {
2494 }
2495 else
2496 {
2498 }
2503 }
2506 {
2510 {
2512 }
2513 else
2514 {
2516 }
2521 }
2525 }
2526 /*void glNormalPointer(GLenum type, GLsizei stride, const void *ptr)
2527 {
2528 glEsImpl->glNormalPointer( type, stride, ptr );
2529 }*/
2531 void glCopyTexSubImage2D( GLenum target, GLint level, GLint xoffset, GLint yoffset, GLint x, GLint y, GLsizei width, GLsizei height )
2532 {
2535 }
2538 {
2541 }
2544 {
2547 }
2550 {
2553 }
2556 {
2559 }
2561 void glFramebufferRenderbuffer( GLenum target, GLenum attachment, GLenum renderbuffertarget, GLuint renderbuffer )
2562 {
2565 }
2568 {
2571 }
2574 {
2577 }
2578 void glFramebufferTexture2D( GLenum target, GLenum attachment, GLenum textarget, GLuint texture, GLint level )
2579 {
2582 }
2584 void glRenderbufferStorage( GLenum target, GLenum internalformat, GLsizei width, GLsizei height )
2585 {
2588 }
2591 {
2603 {
2605 }
2607 }
2610 {
2612 }
2615 {
2617 }
2620 {
2622 }
2625 {
2627 }
2630 {
2634 {
2636 }
2639 {
2698 }
2699 }
2702 {
2706 {
2708 }
2713 {
2715 {
2717 }
2718 }
2721 {
2722 // TODO
2723 }
2726 {
2727 // TODO
2728 }
2731 }
2734 {
2739 {
2742 }
2747 {
2749 {
2751 {
2753 }
2754 else
2755 {
2757 }
2758 }
2759 }
2762 {
2763 // TODO
2764 }
2767 {
2768 // TODO
2769 }
2770 }