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 GLclampf depth_range_near;
71 GLclampf 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
248 {
270 }
273 {
276 {
278 }
279 else
280 {
282 }
285 {
287 }
288 else
289 {
291 }
294 {
296 }
297 else
298 {
300 }
303 {
305 }
306 else
307 {
309 }
332 glEsImpl->glColor4f( currentVertexAttrib.red, currentVertexAttrib.green, currentVertexAttrib.blue, currentVertexAttrib.alpha );
336 //glEsImpl->glBindTexture(GL_TEXTURE_2D, stackTextureState);
338 glEsImpl->glTexEnvi( GL_TEXTURE_ENV, GL_TEXTURE_ENV_MODE, activetmuState->texture_env_mode.value );
341 }
344 {
346 {
348 #ifndef USE_CORE_PROFILE
350 #endif
351 }
357 {
365 #if defined( __MULTITEXTURE_SUPPORT__ )
370 #endif
372 }
376 #if defined( __MULTITEXTURE_SUPPORT__ )
378 #endif
385 }
387 {
389 }
391 {
393 }
395 {
400 }
403 {
404 vertexCount += ( (unsigned char *)ptrVertexAttribArray - (unsigned char *)ptrVertexAttribArrayMark ) / sizeof( VertexAttrib );
406 {
408 }
410 {
412 {
421 }
424 {
427 {
432 }
433 }
436 {
443 {
447 indexCount++;
454 {
459 }
462 {
466 indexCount++;
467 }
468 }
469 else
470 {
471 //already aligned
477 {
482 }
485 {
490 indexCount++;
491 }
492 }
494 }
498 {
504 {
509 }
510 }
515 }
519 }
522 {
525 {
527 {
529 {
532 }
534 }
536 {
538 {
541 }
543 }
544 //case GL_CLIP_PLANEi
546 {
548 {
551 }
553 }
555 {
557 {
560 }
562 }
564 {
566 {
569 }
571 }
573 {
575 {
578 }
580 }
582 {
584 {
587 }
589 }
591 {
593 {
596 }
598 }
600 {
602 {
605 }
607 }
609 {
611 {
614 }
616 }
618 {
620 {
623 }
625 }
627 {
629 {
632 }
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 }
689 /* case GL_MATRIX_PALETTE_OES:
690 {
691 if (!nanoglState.matrix_palette_oes)
692 {
693 nanoglState.matrix_palette_oes = GL_TRUE;
694 statechanged = GL_TRUE;
695 }
696 break;
697 }*/
699 {
701 {
704 }
706 }
708 {
710 {
713 }
715 }
716 /* case GL_POINT_SPRITE_OES:
717 {
718 if (!nanoglState.point_sprite_oes)
719 {
720 nanoglState.point_sprite_oes = GL_TRUE;
721 statechanged = GL_TRUE;
722 }
723 break;
724 }*/
726 {
728 {
731 }
733 }
735 {
737 {
740 }
742 }
744 {
746 {
749 }
751 }
753 {
755 {
758 }
760 }
762 {
764 {
767 }
769 }
771 {
773 {
776 }
778 }
780 {
782 /* if (!nanoglState.stencil_test)
783 {
784 nanoglState.stencil_test = GL_TRUE;
785 statechanged = GL_TRUE;
786 }*/
788 }
790 {
792 {
797 }
799 }
802 }
805 {
808 }
809 }
812 {
815 {
817 {
819 {
822 }
824 }
826 {
828 {
831 }
833 }
834 //case GL_CLIP_PLANEi
836 {
838 {
841 }
843 }
845 {
847 {
850 }
852 }
854 {
856 {
859 }
861 }
863 {
865 {
868 }
870 }
872 {
874 {
877 }
879 }
881 {
883 {
886 }
888 }
890 {
892 {
895 }
897 }
899 {
901 {
904 }
906 }
908 {
910 {
913 }
915 }
917 {
919 {
922 }
924 }
926 {
928 {
931 }
933 }
935 {
937 {
940 }
942 }
944 {
946 {
949 }
951 }
953 {
955 {
958 }
960 }
962 {
964 {
967 }
969 }
971 {
973 {
976 }
978 }
979 /* case GL_MATRIX_PALETTE_OES:
980 {
981 if (nanoglState.matrix_palette_oes)
982 {
983 nanoglState.matrix_palette_oes = GL_FALSE;
984 statechanged = GL_TRUE;
985 }
986 break;
987 }*/
989 {
991 {
994 }
996 }
998 {
1000 {
1003 }
1005 }
1006 /* case GL_POINT_SPRITE_OES:
1007 {
1008 if (nanoglState.point_sprite_oes)
1009 {
1010 nanoglState.point_sprite_oes = GL_FALSE;
1011 statechanged = GL_TRUE;
1012 }
1013 break;
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 }
1070 {
1072 /* if (nanoglState.stencil_test)
1073 {
1074 nanoglState.stencil_test = GL_FALSE;
1075 statechanged = GL_TRUE;
1076 }*/
1078 }
1080 {
1082 {
1087 }
1089 }
1092 }
1095 {
1098 }
1099 }
1102 {
1104 }
1107 {
1110 {
1112 }
1114 }
1117 {
1122 }
1125 {
1127 }
1130 {
1133 }
1136 {
1139 }
1142 {
1145 }
1148 {
1153 }
1155 void glOrtho( GLfloat left, GLfloat right, GLfloat bottom, GLfloat top, GLfloat zNear, GLfloat zFar )
1156 {
1158 #ifdef USE_CORE_PROFILE
1160 #else
1162 #endif
1163 }
1165 // Rikku2000: Light
1167 {
1171 }
1173 {
1177 }
1179 {
1183 }
1185 {
1189 }
1191 {
1195 }
1197 {
1201 }
1203 {
1207 }
1210 {
1212 {
1214 }
1218 }
1221 {
1223 {
1225 }
1229 {
1231 }
1235 }
1238 {
1240 }
1242 void glTexImage2D( GLenum target, GLint level, GLint internalformat, GLsizei width, GLsizei height, GLint border, GLenum format, GLenum type, const GLvoid *pixels )
1243 {
1246 glEsImpl->glTexImage2D( target, level, internalformat, width, height, border, format, type, pixels );
1247 }
1250 {
1251 }
1254 {
1257 }
1260 {
1263 }
1266 {
1269 }
1272 {
1274 {
1276 }
1277 else
1278 {
1281 }
1283 #ifdef USE_CORE_PROFILE
1285 #else
1287 #endif
1288 }
1291 {
1293 {
1295 }
1296 else
1297 {
1299 }
1302 }
1305 {
1308 }
1311 {
1314 }
1317 {
1319 {
1321 }
1322 else
1323 {
1325 }
1328 }
1330 void glFrustum( GLfloat left, GLfloat right, GLfloat bottom, GLfloat top, GLfloat zNear, GLfloat zFar )
1331 {
1334 }
1337 {
1340 }
1343 {
1348 #if defined( __MULTITEXTURE_SUPPORT__ )
1350 #else
1352 #endif
1353 }
1356 {
1361 }
1364 {
1369 }
1372 {
1373 //*((unsigned int*)(¤tVertexAttrib.red)) = *((unsigned int*)(v));
1378 }
1381 {
1386 }
1388 //-- nicknekit: xash3d funcs --
1391 {
1396 }
1399 {
1404 }
1407 {
1410 }
1412 void glCopyTexImage2D( GLenum target, GLint level, GLenum internalformat, GLint x, GLint y, GLsizei width, GLsizei height, GLint border )
1413 {
1416 }
1418 void glTexImage1D( GLenum target, GLint level, GLint internalformat, GLsizei width, GLint border, GLenum format, GLenum type, const GLvoid *pixels )
1419 {
1421 }
1423 void glTexImage3D( GLenum target, GLint level, GLint internalformat, GLsizei width, GLsizei height, GLsizei depth, GLint border, GLenum format, GLenum type, const GLvoid *pixels )
1424 {
1425 glTexImage2D( GL_TEXTURE_2D, level, internalformat, width, height, border, format, type, pixels );
1426 }
1428 void glTexSubImage1D( GLenum target, GLint level, GLint xoffset, GLsizei width, GLenum format, GLenum type, const GLvoid *pixels )
1429 {
1431 }
1437 GLenum format,
1439 {
1441 }
1444 {
1447 }
1450 {
1451 //for mirrors? not needed for original hl?
1452 }
1455 {
1456 //for mirrors? not needed for original hl?
1457 }
1459 //-- --//
1462 {
1465 }
1468 {
1470 {
1472 }
1477 }
1480 {
1483 }
1486 {
1488 {
1490 }
1494 }
1497 {
1500 }
1503 {
1505 {
1507 {
1509 {
1511 }
1512 else
1513 {
1518 }
1519 }
1520 }
1523 }
1526 {
1529 #if defined( __MULTITEXTURE_SUPPORT__ )
1531 #else
1533 #endif
1534 }
1537 {
1539 {
1541 }
1545 }
1548 {
1550 {
1552 }
1556 }
1559 {
1562 }
1566 {
1569 {
1570 #if defined( __MULTITEXTURE_SUPPORT__ )
1571 sprintf( (char *)nano_extensions_string, "%s %s", glEsImpl->glGetString( name ), "GL_ARB_multitexture EXT_texture_env_add" );
1572 #else
1573 sprintf( (char *)nano_extensions_string, "%s %s", glEsImpl->glGetString( name ), "EXT_texture_env_add" );
1574 #endif
1576 }
1578 }
1581 {
1584 }
1587 {
1590 }
1592 void glReadPixels( GLint x, GLint y, GLsizei width, GLsizei height, GLenum format, GLenum type, GLvoid *pixels )
1593 {
1595 {
1596 // OpenglEs 1.1 does not support reading depth buffer without an extension
1599 }
1602 }
1605 {
1606 }
1609 {
1612 }
1614 void glTexSubImage2D( GLenum target, GLint level, GLint xoffset, GLint yoffset, GLsizei width, GLsizei height, GLenum format, GLenum type, const GLvoid *pixels )
1615 {
1617 glEsImpl->glTexSubImage2D( target, level, xoffset, yoffset, width, height, format, type, pixels );
1618 }
1621 {
1624 }
1627 {
1628 //FlushOnStateChange();
1630 }
1633 {
1635 {
1637 }
1639 {
1641 }
1642 else
1643 {
1646 }
1648 {
1650 }
1651 else
1652 {
1654 }
1656 }
1659 {
1661 }
1664 {
1665 }
1668 {
1671 }
1674 {
1677 }
1680 {
1688 }
1691 {
1694 }
1697 {
1700 }
1703 {
1704 }
1706 {
1707 }
1709 {
1710 }
1712 {
1713 }
1715 {
1716 }
1718 {
1719 }
1726 {
1727 // ensure that all primitives specified between glBegin/glEnd pairs
1728 // are rendered first, and that we have correct tmu in use..
1730 // setup correct vertex/color/texcoord pointers
1735 {
1737 }
1739 {
1741 {
1743 }
1744 else
1745 {
1747 }
1753 }
1755 {
1757 {
1759 }
1760 else
1761 {
1763 }
1769 }
1771 {
1773 {
1775 }
1776 else
1777 {
1779 }
1784 }
1786 {
1789 {
1791 }
1792 else
1793 {
1795 }
1800 }
1803 {
1807 {
1809 }
1810 else
1811 {
1813 }
1818 }
1822 }
1825 {
1828 {
1830 }
1832 {
1834 }
1835 else
1836 {
1838 }
1840 {
1843 {
1845 }
1851 {
1853 }
1860 {
1862 }
1869 {
1871 }
1877 }
1878 }
1880 {
1883 {
1885 }
1887 {
1889 }
1890 else
1891 {
1893 }
1895 {
1898 {
1900 }
1906 {
1908 }
1915 {
1917 }
1924 {
1926 }
1932 }
1933 }
1935 {
1940 {
1942 }
1948 }
1950 {
1953 {
1955 }
1957 {
1959 }
1964 {
1966 }
1972 }
1974 {
1979 {
1981 }
1987 }
1990 {
1996 {
1998 }
2004 }
2006 {
2009 }
2011 {
2012 }
2014 {
2015 }
2017 #if defined( __MULTITEXTURE_SUPPORT__ )
2022 {
2024 {
2026 }
2027 else
2028 {
2031 }
2032 }
2033 #endif
2035 /* Vladimir */
2036 /*void glDrawArrays( GLenum mode, int first, int count)
2037 {
2038 FlushOnStateChange();
2039 glEsImpl->glDrawArrays(mode, first , count);
2040 }*/
2042 {
2045 }
2048 {
2051 }
2054 {
2057 }
2060 {
2063 }
2066 {
2069 }
2071 // This gives: called unimplemented OpenGL ES API (Android)
2073 {
2075 {
2077 }
2081 {
2083 }
2087 }
2090 {
2092 {
2094 }
2098 {
2100 }
2103 }
2106 {
2109 }
2112 {
2115 }
2116 // End Vladimir
2119 {
2121 {
2123 {
2125 {
2127 }
2128 else
2129 {
2134 }
2135 }
2136 }
2139 }
2141 #ifdef __MULTITEXTURE_SUPPORT__
2143 {
2145 }
2148 {
2149 }
2150 #endif
2152 {
2153 // ensure that all primitives specified between glBegin/glEnd pairs
2154 // are rendered first, and that we have correct tmu in use..
2158 // setup correct vertex/color/texcoord pointers
2163 {
2165 }
2167 {
2169 {
2171 }
2172 else
2173 {
2175 }
2181 }
2183 {
2185 {
2187 }
2188 else
2189 {
2191 }
2197 }
2199 {
2201 {
2203 }
2204 else
2205 {
2207 }
2212 }
2214 {
2217 {
2219 }
2220 else
2221 {
2223 }
2228 }
2231 {
2235 {
2237 }
2238 else
2239 {
2241 }
2246 }
2250 }
2251 /*void glNormalPointer(GLenum type, GLsizei stride, const void *ptr)
2252 {
2253 glEsImpl->glNormalPointer( type, stride, ptr );
2254 }*/
2256 void glCopyTexSubImage2D( GLenum target, GLint level, GLint xoffset, GLint yoffset, GLint x, GLint y, GLsizei width, GLsizei height )
2257 {
2260 }
2263 {
2266 }
2269 {
2272 }
2275 {
2278 }
2281 {
2284 }
2286 void glFramebufferRenderbuffer( GLenum target, GLenum attachment, GLenum renderbuffertarget, GLuint renderbuffer )
2287 {
2290 }
2293 {
2296 }
2299 {
2302 }
2303 void glFramebufferTexture2D( GLenum target, GLenum attachment, GLenum textarget, GLuint texture, GLint level )
2304 {
2307 }
2309 void glRenderbufferStorage( GLenum target, GLenum internalformat, GLsizei width, GLsizei height )
2310 {
2313 }