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 };
140 struct nanotmuState
141 {
149 };
155 {
163 };
174 #if defined( __MULTITEXTURE_SUPPORT__ )
176 #endif
178 #if !defined( __WINS__ )
179 //#define __FORCEINLINE __forceinline
180 #define __FORCEINLINE inline
181 #else
182 #define __FORCEINLINE
183 #endif
188 struct VertexAttrib
189 {
193 #if !defined( __MULTITEXTURE_SUPPORT__ )
195 #endif
203 #if defined( __MULTITEXTURE_SUPPORT__ )
206 #endif
207 };
222 #if defined( __MULTITEXTURE_SUPPORT__ )
223 static VertexAttrib currentVertexAttribInit = {0.0f, 0.0f, 0.0f, 255, 255, 255, 255, 0.0f, 0.0f, 0.0f, 0.0f};
224 #else
227 };
228 #endif
234 {
256 }
259 {
262 {
264 }
265 else
266 {
268 }
271 {
273 }
274 else
275 {
277 }
280 {
282 }
283 else
284 {
286 }
289 {
291 }
292 else
293 {
295 }
318 glEsImpl->glColor4f( currentVertexAttrib.red, currentVertexAttrib.green, currentVertexAttrib.blue, currentVertexAttrib.alpha );
322 //glEsImpl->glBindTexture(GL_TEXTURE_2D, stackTextureState);
324 glEsImpl->glTexEnvi( GL_TEXTURE_ENV, GL_TEXTURE_ENV_MODE, activetmuState->texture_env_mode.value );
327 }
330 {
332 {
334 #ifndef USE_CORE_PROFILE
336 #endif
337 }
343 {
351 #if defined( __MULTITEXTURE_SUPPORT__ )
356 #endif
358 }
362 #if defined( __MULTITEXTURE_SUPPORT__ )
364 #endif
371 }
373 {
375 }
377 {
379 }
381 {
386 }
389 {
390 vertexCount += ( (unsigned char *)ptrVertexAttribArray - (unsigned char *)ptrVertexAttribArrayMark ) / sizeof( VertexAttrib );
392 {
394 }
396 {
398 {
407 }
410 {
413 {
418 }
419 }
422 {
429 {
433 indexCount++;
440 {
445 }
448 {
452 indexCount++;
453 }
454 }
455 else
456 {
457 //already aligned
463 {
468 }
471 {
476 indexCount++;
477 }
478 }
480 }
484 {
490 {
495 }
496 }
501 }
505 }
508 {
511 {
513 {
515 {
518 }
520 }
522 {
524 {
527 }
529 }
530 //case GL_CLIP_PLANEi
532 {
534 {
537 }
539 }
541 {
543 {
546 }
548 }
550 {
552 {
555 }
557 }
559 {
561 {
564 }
566 }
568 {
570 {
573 }
575 }
577 //case GL_LIGHTi
578 {
580 {
583 }
585 }
587 {
589 {
592 }
594 }
596 {
598 {
601 }
603 }
604 /* case GL_MATRIX_PALETTE_OES:
605 {
606 if (!nanoglState.matrix_palette_oes)
607 {
608 nanoglState.matrix_palette_oes = GL_TRUE;
609 statechanged = GL_TRUE;
610 }
611 break;
612 }*/
614 {
616 {
619 }
621 }
623 {
625 {
628 }
630 }
631 /* case GL_POINT_SPRITE_OES:
632 {
633 if (!nanoglState.point_sprite_oes)
634 {
635 nanoglState.point_sprite_oes = GL_TRUE;
636 statechanged = GL_TRUE;
637 }
638 break;
639 }*/
641 {
643 {
646 }
648 }
650 {
652 {
655 }
657 }
659 {
661 {
664 }
666 }
668 {
670 {
673 }
675 }
677 {
679 {
682 }
684 }
686 {
688 {
691 }
693 }
695 {
697 /* if (!nanoglState.stencil_test)
698 {
699 nanoglState.stencil_test = GL_TRUE;
700 statechanged = GL_TRUE;
701 }*/
703 }
705 {
707 {
712 }
714 }
717 }
720 {
723 }
724 }
727 {
730 {
732 {
734 {
737 }
739 }
741 {
743 {
746 }
748 }
749 //case GL_CLIP_PLANEi
751 {
753 {
756 }
758 }
760 {
762 {
765 }
767 }
769 {
771 {
774 }
776 }
778 {
780 {
783 }
785 }
787 {
789 {
792 }
794 }
796 //case GL_LIGHTi
797 {
799 {
802 }
804 }
806 {
808 {
811 }
813 }
815 {
817 {
820 }
822 }
823 /* case GL_MATRIX_PALETTE_OES:
824 {
825 if (nanoglState.matrix_palette_oes)
826 {
827 nanoglState.matrix_palette_oes = GL_FALSE;
828 statechanged = GL_TRUE;
829 }
830 break;
831 }*/
833 {
835 {
838 }
840 }
842 {
844 {
847 }
849 }
850 /* case GL_POINT_SPRITE_OES:
851 {
852 if (nanoglState.point_sprite_oes)
853 {
854 nanoglState.point_sprite_oes = GL_FALSE;
855 statechanged = GL_TRUE;
856 }
857 break;
858 }*/
860 {
862 {
865 }
867 }
869 {
871 {
874 }
876 }
878 {
880 {
883 }
885 }
887 {
889 {
892 }
894 }
896 {
898 {
901 }
903 }
905 {
907 {
910 }
912 }
914 {
916 /* if (nanoglState.stencil_test)
917 {
918 nanoglState.stencil_test = GL_FALSE;
919 statechanged = GL_TRUE;
920 }*/
922 }
924 {
926 {
931 }
933 }
936 }
939 {
942 }
943 }
946 {
948 }
951 {
954 {
956 }
958 }
961 {
966 }
969 {
971 }
974 {
977 }
980 {
983 }
986 {
989 }
992 {
997 }
999 void glOrtho( GLfloat left, GLfloat right, GLfloat bottom, GLfloat top, GLfloat zNear, GLfloat zFar )
1000 {
1002 #ifdef USE_CORE_PROFILE
1004 #else
1006 #endif
1007 }
1010 {
1012 {
1014 }
1018 }
1021 {
1023 {
1025 }
1029 {
1031 }
1035 }
1038 {
1040 }
1042 void glTexImage2D( GLenum target, GLint level, GLint internalformat, GLsizei width, GLsizei height, GLint border, GLenum format, GLenum type, const GLvoid *pixels )
1043 {
1046 glEsImpl->glTexImage2D( target, level, internalformat, width, height, border, format, type, pixels );
1047 }
1050 {
1051 }
1054 {
1057 }
1060 {
1063 }
1066 {
1069 }
1072 {
1074 {
1076 }
1077 else
1078 {
1081 }
1083 #ifdef USE_CORE_PROFILE
1085 #else
1087 #endif
1088 }
1091 {
1093 {
1095 }
1096 else
1097 {
1099 }
1102 }
1105 {
1108 }
1111 {
1114 }
1117 {
1119 {
1121 }
1122 else
1123 {
1125 }
1128 }
1130 void glFrustum( GLfloat left, GLfloat right, GLfloat bottom, GLfloat top, GLfloat zNear, GLfloat zFar )
1131 {
1134 }
1137 {
1140 }
1143 {
1148 #if defined( __MULTITEXTURE_SUPPORT__ )
1150 #else
1152 #endif
1153 }
1156 {
1161 }
1164 {
1169 }
1172 {
1173 //*((unsigned int*)(¤tVertexAttrib.red)) = *((unsigned int*)(v));
1178 }
1181 {
1186 }
1188 //-- nicknekit: xash3d funcs --
1191 {
1196 }
1199 {
1204 }
1207 {
1210 }
1212 void glCopyTexImage2D( GLenum target, GLint level, GLenum internalformat, GLint x, GLint y, GLsizei width, GLsizei height, GLint border )
1213 {
1216 }
1218 void glTexImage1D( GLenum target, GLint level, GLint internalformat, GLsizei width, GLint border, GLenum format, GLenum type, const GLvoid *pixels )
1219 {
1221 }
1223 void glTexImage3D( GLenum target, GLint level, GLint internalformat, GLsizei width, GLsizei height, GLsizei depth, GLint border, GLenum format, GLenum type, const GLvoid *pixels )
1224 {
1225 glTexImage2D( GL_TEXTURE_2D, level, internalformat, width, height, border, format, type, pixels );
1226 }
1228 void glTexSubImage1D( GLenum target, GLint level, GLint xoffset, GLsizei width, GLenum format, GLenum type, const GLvoid *pixels )
1229 {
1231 }
1237 GLenum format,
1239 {
1241 }
1244 {
1247 }
1250 {
1251 //for mirrors? not needed for original hl?
1252 }
1255 {
1256 //for mirrors? not needed for original hl?
1257 }
1259 //-- --//
1262 {
1265 }
1268 {
1270 {
1272 }
1277 }
1280 {
1283 }
1286 {
1288 {
1290 }
1294 }
1297 {
1300 }
1303 {
1305 {
1307 {
1309 {
1311 }
1312 else
1313 {
1318 }
1319 }
1320 }
1323 }
1326 {
1329 #if defined( __MULTITEXTURE_SUPPORT__ )
1331 #else
1333 #endif
1334 }
1337 {
1339 {
1341 }
1345 }
1348 {
1350 {
1352 }
1356 }
1359 {
1362 }
1366 {
1369 {
1370 #if defined( __MULTITEXTURE_SUPPORT__ )
1371 sprintf( (char *)nano_extensions_string, "%s %s", glEsImpl->glGetString( name ), "GL_ARB_multitexture EXT_texture_env_add" );
1372 #else
1373 sprintf( (char *)nano_extensions_string, "%s %s", glEsImpl->glGetString( name ), "EXT_texture_env_add" );
1374 #endif
1376 }
1378 }
1381 {
1384 }
1387 {
1390 }
1392 void glReadPixels( GLint x, GLint y, GLsizei width, GLsizei height, GLenum format, GLenum type, GLvoid *pixels )
1393 {
1395 {
1396 // OpenglEs 1.1 does not support reading depth buffer without an extension
1399 }
1402 }
1405 {
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 {
1417 glEsImpl->glTexSubImage2D( target, level, xoffset, yoffset, width, height, format, type, pixels );
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 }
1503 {
1504 }
1506 {
1507 }
1509 {
1510 }
1512 {
1513 }
1515 {
1516 }
1518 {
1519 }
1526 {
1527 // ensure that all primitives specified between glBegin/glEnd pairs
1528 // are rendered first, and that we have correct tmu in use..
1530 // setup correct vertex/color/texcoord pointers
1535 {
1537 }
1539 {
1541 {
1543 }
1544 else
1545 {
1547 }
1553 }
1555 {
1557 {
1559 }
1560 else
1561 {
1563 }
1569 }
1571 {
1573 {
1575 }
1576 else
1577 {
1579 }
1584 }
1586 {
1589 {
1591 }
1592 else
1593 {
1595 }
1600 }
1603 {
1607 {
1609 }
1610 else
1611 {
1613 }
1618 }
1622 }
1625 {
1628 {
1630 }
1632 {
1634 }
1635 else
1636 {
1638 }
1640 {
1643 {
1645 }
1651 {
1653 }
1660 {
1662 }
1669 {
1671 }
1677 }
1678 }
1680 {
1683 {
1685 }
1687 {
1689 }
1690 else
1691 {
1693 }
1695 {
1698 {
1700 }
1706 {
1708 }
1715 {
1717 }
1724 {
1726 }
1732 }
1733 }
1735 {
1740 {
1742 }
1748 }
1750 {
1753 {
1755 }
1757 {
1759 }
1764 {
1766 }
1772 }
1774 {
1779 {
1781 }
1787 }
1790 {
1796 {
1798 }
1804 }
1806 {
1809 }
1811 {
1812 }
1814 {
1815 }
1817 #if defined( __MULTITEXTURE_SUPPORT__ )
1822 {
1824 {
1826 }
1827 else
1828 {
1831 }
1832 }
1833 #endif
1835 /* Vladimir */
1836 /*void glDrawArrays( GLenum mode, int first, int count)
1837 {
1838 FlushOnStateChange();
1839 glEsImpl->glDrawArrays(mode, first , count);
1840 }*/
1842 {
1845 }
1848 {
1851 }
1854 {
1857 }
1860 {
1863 }
1866 {
1869 }
1871 // This gives: called unimplemented OpenGL ES API (Android)
1873 {
1875 {
1877 }
1881 {
1883 }
1887 }
1890 {
1892 {
1894 }
1898 {
1900 }
1903 }
1906 {
1909 }
1912 {
1915 }
1916 // End Vladimir
1919 {
1921 {
1923 {
1925 {
1927 }
1928 else
1929 {
1934 }
1935 }
1936 }
1939 }
1941 #ifdef __MULTITEXTURE_SUPPORT__
1943 {
1945 }
1948 {
1949 }
1950 #endif
1952 {
1953 // ensure that all primitives specified between glBegin/glEnd pairs
1954 // are rendered first, and that we have correct tmu in use..
1958 // setup correct vertex/color/texcoord pointers
1963 {
1965 }
1967 {
1969 {
1971 }
1972 else
1973 {
1975 }
1981 }
1983 {
1985 {
1987 }
1988 else
1989 {
1991 }
1997 }
1999 {
2001 {
2003 }
2004 else
2005 {
2007 }
2012 }
2014 {
2017 {
2019 }
2020 else
2021 {
2023 }
2028 }
2031 {
2035 {
2037 }
2038 else
2039 {
2041 }
2046 }
2050 }
2051 /*void glNormalPointer(GLenum type, GLsizei stride, const void *ptr)
2052 {
2053 glEsImpl->glNormalPointer( type, stride, ptr );
2054 }*/
2056 void glCopyTexSubImage2D( GLenum target, GLint level, GLint xoffset, GLint yoffset, GLint x, GLint y, GLsizei width, GLsizei height )
2057 {
2060 }
2063 {
2066 }
2069 {
2072 }
2075 {
2078 }
2081 {
2084 }
2086 void glFramebufferRenderbuffer( GLenum target, GLenum attachment, GLenum renderbuffertarget, GLuint renderbuffer )
2087 {
2090 }
2093 {
2096 }
2099 {
2102 }
2103 void glFramebufferTexture2D( GLenum target, GLenum attachment, GLenum textarget, GLuint texture, GLint level )
2104 {
2107 }
2109 void glRenderbufferStorage( GLenum target, GLenum internalformat, GLsizei width, GLsizei height )
2110 {
2113 }