AndroidGL2ES.cpp 23 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118119120121122123124125126127128129130131132133134135136137138139140141142143144145146147148149150151152153154155156157158159160161162163164165166167168169170171172173174175176177178179180181182183184185186187188189190191192193194195196197198199200201202203204205206207208209210211212213214215216217218219220221222223224225226227228229230231232233234235236237238239240241242243244245246247248249250251252253254255256257258259260261262263264265266267268269270271272273274275276277278279280281282283284285286287288289290291292293294295296297298299300301302303304305306307308309310311312313314315316317318319320321322323324325326327328329330331332333334335336337338339340341342343344345346347348349350351352353354355356357358359360361362363364365366367368369370371372373374375376377378379380381382383384385386387388389390391392393394395396397398399400401402403404405406407408409410411412413414415416417418419420421422423424425426427428429430431432433434435436437438439440441442443444445446447448449450451452453454455456457458459460461462463464465466467468469470471472473474475476477478479480481482483484485486487488489490491492493494495496497498499500501502503504505506507508509510511512513514515516517518519520521522523524525526527528529530531532533534535536537538539540541542543544545546547548549550551552553554555556557558559560561562563564565566567568569570571572573574575576577578579580581582583584585586587588589590591592593594595596597598599600601602603604605606607608609610611612613614615616617618619620621622623624625626627628629630631632633634635636637638639640641642643644645646647648649650651652653654655656657658659660661662
  1. //-----------------------------------------------------------------------------
  2. // Copyright (c) 2013 GarageGames, LLC
  3. //
  4. // Permission is hereby granted, free of charge, to any person obtaining a copy
  5. // of this software and associated documentation files (the "Software"), to
  6. // deal in the Software without restriction, including without limitation the
  7. // rights to use, copy, modify, merge, publish, distribute, sublicense, and/or
  8. // sell copies of the Software, and to permit persons to whom the Software is
  9. // furnished to do so, subject to the following conditions:
  10. //
  11. // The above copyright notice and this permission notice shall be included in
  12. // all copies or substantial portions of the Software.
  13. //
  14. // THE SOFTWARE IS PROVIDED "AS IS", WITHOUT WARRANTY OF ANY KIND, EXPRESS OR
  15. // IMPLIED, INCLUDING BUT NOT LIMITED TO THE WARRANTIES OF MERCHANTABILITY,
  16. // FITNESS FOR A PARTICULAR PURPOSE AND NONINFRINGEMENT. IN NO EVENT SHALL THE
  17. // AUTHORS OR COPYRIGHT HOLDERS BE LIABLE FOR ANY CLAIM, DAMAGES OR OTHER
  18. // LIABILITY, WHETHER IN AN ACTION OF CONTRACT, TORT OR OTHERWISE, ARISING
  19. // FROM, OUT OF OR IN CONNECTION WITH THE SOFTWARE OR THE USE OR OTHER DEALINGS
  20. // IN THE SOFTWARE.
  21. //-----------------------------------------------------------------------------
  22. //
  23. // AndroidGL2ES.mm
  24. // TGE
  25. //
  26. // Created by Puap Puap on 7/31/08.
  27. // Copyright 2008 Pick Up And Play. All rights reserved.
  28. //
  29. #include "AndroidGL2ES.h"
  30. #include "platform/platformAssert.h"
  31. #include "AndroidOGLVideo.h"
  32. #include "math/mMatrix.h"
  33. #include "math/mPoint.h"
  34. #define INV_255 0.0039215686f
  35. #define INV_32767 3.0518509476e-5f
  36. /* EAGL and GL functions calling wrappers that log on error */
  37. #define CALL_EAGL_FUNCTION(__FUNC__, ...) ({ EAGLError __error = __FUNC__( __VA_ARGS__ ); if(__error != kEAGLErrorSuccess) Con::printf("%s() called from %s returned error %i\n", #__FUNC__, __FUNCTION__, __error); (__error ? 0 : 1); })
  38. #define CHECK_GL_ERROR() ({ int __error = glGetError(); if(__error) Con::printf("OpenGL error 0x%04X in %s\n", __error, __FUNCTION__); (__error ? 0 : 1); })
  39. // define this to print out glErrors, un-define to get rid of it
  40. #define TEST_FOR_OPENGL_ERRORS CHECK_GL_ERROR();
  41. /////////////////////////////////////////////////////////////////////////////
  42. //
  43. // Wrapper around the matrix stack ops, to see if ever have over/underflow
  44. //
  45. extern "C"
  46. {
  47. static GLenum currentMatrixMode = GL_MODELVIEW;
  48. static int currentProjStackDepth = 0;
  49. static GLfloat projStack[256];
  50. static int currentTexStackDepth = 0;
  51. static GLfloat texStack[256];
  52. static int currentModelStackDepth = 0;
  53. static GLfloat modStack[256];
  54. #undef glPushMatrix // temporarily
  55. void AndroidGLPushMatrix() {
  56. GLint depth;
  57. switch (currentMatrixMode) {
  58. case GL_MODELVIEW:
  59. if (currentModelStackDepth > 15) {
  60. AssertFatal( 0, "ModelView Stack overflow" );
  61. } else {
  62. glGetFloatv( GL_MODELVIEW_MATRIX, &modStack[currentModelStackDepth*16] );
  63. currentModelStackDepth++;
  64. glGetIntegerv( GL_MODELVIEW_STACK_DEPTH, &depth );
  65. // AssertWarn( (currentModelStackDepth > depth), "Native ModelView stack depth has been exceeded" );
  66. }
  67. break;
  68. case GL_PROJECTION:
  69. if (currentProjStackDepth > 15) {
  70. AssertFatal( 0, "Projection Stack overflow" );
  71. } else {
  72. glGetFloatv( GL_PROJECTION_MATRIX, &projStack[currentProjStackDepth*16] );
  73. currentProjStackDepth++;
  74. glGetIntegerv( GL_PROJECTION_STACK_DEPTH, &depth );
  75. // AssertWarn( (currentProjStackDepth > depth), "Native Projection stack depth has been exceeded" );
  76. }
  77. break;
  78. case GL_TEXTURE:
  79. if (currentTexStackDepth > 15) {
  80. AssertFatal( 0, "Texture Stack overflow" );
  81. } else {
  82. glGetFloatv( GL_TEXTURE_MATRIX, &texStack[currentTexStackDepth*16] );
  83. currentTexStackDepth++;
  84. glGetIntegerv( GL_TEXTURE_STACK_DEPTH, &depth );
  85. // AssertWarn( (currentTexStackDepth > depth), "Native Texture stack depth has been exceeded" );
  86. }
  87. break;
  88. default:
  89. glPushMatrix();
  90. GLenum err;
  91. err = glGetError();
  92. AssertFatal( !(err == GL_STACK_OVERFLOW), "GL Stack overflow" );
  93. break;
  94. }
  95. }
  96. #define glPushMatrix AndroidGLPushMatrix
  97. #undef glPopMatrix // temporarily
  98. void AndroidGLPopMatrix() {
  99. switch (currentMatrixMode) {
  100. case GL_MODELVIEW:
  101. if (currentModelStackDepth <= 0) {
  102. AssertFatal( 0, "ModelView Stack underflow" );
  103. } else {
  104. currentModelStackDepth--;
  105. glLoadMatrixf( &modStack[currentModelStackDepth*16] );
  106. }
  107. break;
  108. case GL_PROJECTION:
  109. if (currentProjStackDepth <= 0) {
  110. AssertFatal( 0, "Projection Stack underflow" );
  111. } else {
  112. currentProjStackDepth--;
  113. glLoadMatrixf( &projStack[currentProjStackDepth*16] );
  114. }
  115. break;
  116. case GL_TEXTURE:
  117. if (currentTexStackDepth <= 0) {
  118. AssertFatal( 0, "Texture Stack underflow" );
  119. } else {
  120. currentTexStackDepth--;
  121. glLoadMatrixf( &texStack[currentTexStackDepth*16] );
  122. }
  123. break;
  124. default:
  125. glPopMatrix();
  126. GLenum err;
  127. err = glGetError();
  128. AssertFatal( !(err == GL_STACK_UNDERFLOW), "GL Stack underflow" );
  129. break;
  130. }
  131. }
  132. #define glPopMatrix AndroidGLPopMatrix
  133. #undef glMatrixMode // temporarily
  134. void AndroidGLMatrixMode( GLenum mode ) {
  135. currentMatrixMode = mode;
  136. glMatrixMode( mode );
  137. }
  138. #define glMatrixMode AndroidGLMatrixMode // redefine for everyone else
  139. }
  140. /////////////////////////////////////////////////////////////////////////////
  141. //
  142. // The following API functions are wrappers to add opengl functionality to opengl-es
  143. //
  144. static GLint beginEndMode = -1;
  145. // tex coord array
  146. static GLfloat * beginEndTexCoord2f = NULL; // 2 entries per coord
  147. static int beginEndTexCoord2f_alloc = 0; // number of bytes allocated to the array
  148. static int beginEndTexCoord2f_size = 0; // number of coords in the array
  149. // vertex array
  150. static GLfloat * beginEndVertex = NULL; // 4 entries per vertex
  151. static int beginEndVertex_alloc = 0; // number of bytes allocated to the array
  152. static int beginEndVertex_size = 0; // number of vertexes in the array
  153. // color array -- needed if glColor is called inside begin/end
  154. static GLfloat * beginEndColor = NULL; // 4 entries per color
  155. static int beginEndColor_size = 0; // number of colors in the array
  156. // normal array
  157. static GLfloat * beginEndNormal = NULL; // 3 entries per normal
  158. static int beginEndNormal_alloc = 0; // number of bytes allocated to the array
  159. static int beginEndNormal_size = 0; // number of normals in the array
  160. // macros to handle re-sizing the arrays as needed
  161. #define CHECK_ARRAY_SIZE( ppArray, pAlloc, pSize, nType, nGroup ) \
  162. if (*ppArray == NULL) { \
  163. *pAlloc = 32 * sizeof(nType) * nGroup; \
  164. *ppArray = (nType*)dMalloc( 32 * sizeof(nType) * nGroup ); \
  165. } \
  166. if (*pSize >= *pAlloc / (nGroup * sizeof(nType))) { \
  167. *ppArray = (nType*)dRealloc( *ppArray, 2 * (*pAlloc) ); \
  168. *pAlloc *= 2; \
  169. }
  170. void glBegin( GLint mode )
  171. {
  172. if (beginEndMode >= 0) {
  173. AssertFatal(0, "glBegin(): called without a glEnd");
  174. }
  175. beginEndMode = mode;
  176. beginEndTexCoord2f_size = 0;
  177. beginEndVertex_size = 0;
  178. beginEndColor_size = 0;
  179. beginEndNormal_size = 0;
  180. int glError;
  181. glError = TEST_FOR_OPENGL_ERRORS
  182. }
  183. void glEnd()
  184. {
  185. if (beginEndMode < 0) {
  186. AssertFatal(0, "glEnd(): called without a glBegin");
  187. }
  188. if (beginEndVertex_size > 0) {
  189. glEnableClientState( GL_VERTEX_ARRAY );
  190. glVertexPointer( 4, GL_FLOAT, 4*sizeof(GL_FLOAT), beginEndVertex );
  191. }
  192. if (beginEndNormal_size > 0) {
  193. glEnableClientState( GL_NORMAL_ARRAY );
  194. glNormalPointer( GL_FLOAT, 3*sizeof(GL_FLOAT), beginEndNormal );
  195. }
  196. if (beginEndColor_size > 0) {
  197. glEnableClientState( GL_COLOR_ARRAY );
  198. glColorPointer( 4, GL_FLOAT, 4*sizeof(GL_FLOAT), beginEndColor );
  199. }
  200. if (beginEndTexCoord2f_size > 0) {
  201. glEnableClientState( GL_TEXTURE_COORD_ARRAY );
  202. glTexCoordPointer( 2, GL_FLOAT, 2*sizeof(GL_FLOAT), beginEndTexCoord2f );
  203. }
  204. switch (beginEndMode) {
  205. case GL_POINTS:
  206. glDrawArrays( GL_POINTS, 0, beginEndVertex_size );
  207. break;
  208. case GL_LINES:
  209. glDrawArrays( GL_LINES, 0, beginEndVertex_size );
  210. break;
  211. case GL_LINE_STRIP:
  212. glDrawArrays( GL_LINE_STRIP, 0, beginEndVertex_size );
  213. break;
  214. case GL_LINE_LOOP:
  215. glDrawArrays( GL_LINE_LOOP, 0, beginEndVertex_size );
  216. break;
  217. case GL_TRIANGLES:
  218. glDrawArrays( GL_TRIANGLES, 0, beginEndVertex_size );
  219. break;
  220. case GL_TRIANGLE_STRIP:
  221. glDrawArrays( GL_TRIANGLE_STRIP, 0, beginEndVertex_size );
  222. break;
  223. case GL_TRIANGLE_FAN:
  224. glDrawArrays( GL_TRIANGLE_FAN, 0, beginEndVertex_size );
  225. break;
  226. case GL_QUADS:
  227. #if 1 // %%PUAP%% TESTING
  228. // for now, just draw a couple lines to indicate the edges of the quads
  229. glDrawArrays( GL_LINES, 0, beginEndVertex_size );
  230. #else
  231. // draw these as individual pairs of triangle_strips
  232. glDrawArrays( GL_TRIANGLE_STRIP, 0, beginEndVertex_size );
  233. #endif
  234. break;
  235. case GL_QUAD_STRIP:
  236. #if 1 // %%PUAP%% TESTING
  237. glDrawArrays( GL_LINES, 0, beginEndVertex_size );
  238. #endif
  239. break;
  240. case GL_POLYGON:
  241. // see if it is really just a triangle...
  242. if (beginEndVertex_size == 3) {
  243. glDrawArrays( GL_TRIANGLES, 0, 3 );
  244. } else
  245. // see if it is really just a quad...
  246. if (beginEndVertex_size == 4) {
  247. glDrawArrays( GL_TRIANGLE_STRIP, 0, 4 );
  248. } else
  249. AssertFatal( 0, "glBegin(GL_POLYGON): this method call needs to be implemented");
  250. break;
  251. }
  252. if (beginEndVertex_size > 0) {
  253. glDisableClientState( GL_VERTEX_ARRAY );
  254. }
  255. if (beginEndNormal_size > 0) {
  256. glDisableClientState( GL_NORMAL_ARRAY );
  257. }
  258. if (beginEndColor_size > 0) {
  259. glDisableClientState( GL_COLOR_ARRAY );
  260. }
  261. if (beginEndTexCoord2f_size > 0) {
  262. glDisableClientState( GL_TEXTURE_COORD_ARRAY );
  263. }
  264. beginEndMode = -1;
  265. int glError;
  266. glError = TEST_FOR_OPENGL_ERRORS
  267. }
  268. void glTexCoord2f( GLfloat x, GLfloat y)
  269. {
  270. AssertFatal( (beginEndMode >= 0), "glTexCoord2f(): called outside glBegin/glEnd");
  271. CHECK_ARRAY_SIZE( &beginEndTexCoord2f, &beginEndTexCoord2f_alloc, &beginEndTexCoord2f_size, GLfloat, 2 );
  272. beginEndTexCoord2f[ beginEndTexCoord2f_size*2 ] = x;
  273. beginEndTexCoord2f[ beginEndTexCoord2f_size*2+1 ] = y;
  274. beginEndTexCoord2f_size++;
  275. int glError;
  276. glError = TEST_FOR_OPENGL_ERRORS
  277. }
  278. void glVertex4f( GLfloat x, GLfloat y, GLfloat z, GLfloat w)
  279. {
  280. AssertFatal( (beginEndMode >= 0), "glVertex3f(): called outside glBegin/glEnd");
  281. CHECK_ARRAY_SIZE( &beginEndVertex, &beginEndVertex_alloc, &beginEndVertex_size, GLfloat, 4 );
  282. beginEndVertex[ beginEndVertex_size*4 ] = x;
  283. beginEndVertex[ beginEndVertex_size*4+1 ] = y;
  284. beginEndVertex[ beginEndVertex_size*4+2 ] = z;
  285. beginEndVertex[ beginEndVertex_size*4+3 ] = w;
  286. beginEndVertex_size++;
  287. int glError;
  288. glError = TEST_FOR_OPENGL_ERRORS
  289. }
  290. void glVertex2f( GLfloat x, GLfloat y )
  291. {
  292. AssertFatal( (beginEndMode >= 0), "glVertex2f(): called outside glBegin/glEnd");
  293. glVertex4f( x, y, 0.0f, 1.0f );
  294. int glError;
  295. glError = TEST_FOR_OPENGL_ERRORS
  296. }
  297. void glVertex3f( GLfloat x, GLfloat y, GLfloat z )
  298. {
  299. AssertFatal( (beginEndMode >= 0), "glVertex3f(): called outside glBegin/glEnd");
  300. glVertex4f( x, y, z, 1.0f );
  301. int glError;
  302. glError = TEST_FOR_OPENGL_ERRORS
  303. }
  304. void glVertex2fv( const F32 * pv )
  305. {
  306. AssertFatal( (beginEndMode >= 0), "glVertex2fv(): called outside glBegin/glEnd");
  307. glVertex4f( pv[0], pv[1], 0.0f, 1.0f );
  308. int glError;
  309. glError = TEST_FOR_OPENGL_ERRORS
  310. }
  311. void glVertex2i( GLint x, GLint y)
  312. {
  313. AssertFatal( (beginEndMode >= 0), "glVertex2i(): called outside glBegin/glEnd");
  314. glVertex4f( GLfloat(x), GLfloat(y), 0.0f, 1.0f );
  315. int glError;
  316. glError = TEST_FOR_OPENGL_ERRORS
  317. }
  318. void glVertex3fv( const F32 * pv )
  319. {
  320. AssertFatal( (beginEndMode >= 0), "glVertex3fv(): called outside glBegin/glEnd");
  321. glVertex4f( pv[0], pv[1], pv[2], 1.0f );
  322. int glError;
  323. glError = TEST_FOR_OPENGL_ERRORS
  324. }
  325. void glVertex4fv( const F32 * pv )
  326. {
  327. AssertFatal( (beginEndMode >= 0), "glVertex3fv(): called outside glBegin/glEnd");
  328. glVertex4f( pv[0], pv[1], pv[2], pv[3] );
  329. int glError;
  330. glError = TEST_FOR_OPENGL_ERRORS
  331. }
  332. void glNormal3f( GLfloat x, GLfloat y, GLfloat z, GLfloat w)
  333. {
  334. AssertFatal( (beginEndMode >= 0), "glNormal3f(): called outside glBegin/glEnd");
  335. CHECK_ARRAY_SIZE( &beginEndNormal, &beginEndNormal_alloc, &beginEndNormal_size, GLfloat, 3 );
  336. beginEndNormal[ beginEndNormal_size*3 ] = x;
  337. beginEndNormal[ beginEndNormal_size*3+1 ] = y;
  338. beginEndNormal[ beginEndNormal_size*3+2 ] = z;
  339. beginEndNormal_size++;
  340. int glError;
  341. glError = TEST_FOR_OPENGL_ERRORS
  342. }
  343. void glNormal3fv( const F32 * pv)
  344. {
  345. AssertFatal( (beginEndMode >= 0), "glNormal3fv(): called outside glBegin/glEnd");
  346. glNormal3f( pv[0], pv[1], pv[2] );
  347. int glError;
  348. glError = TEST_FOR_OPENGL_ERRORS
  349. }
  350. void glColor3fv( const F32 * pv)
  351. {
  352. glColor4f( pv[0], pv[1], pv[2], 1.0f );
  353. int glError;
  354. glError = TEST_FOR_OPENGL_ERRORS
  355. }
  356. void glColor4fv( const F32 * pv)
  357. {
  358. glColor4f( pv[0], pv[1], pv[2], pv[3] );
  359. int glError;
  360. glError = TEST_FOR_OPENGL_ERRORS
  361. }
  362. void glActiveTextureARB( GLint index )
  363. {
  364. glActiveTexture( index );
  365. int glError;
  366. glError = TEST_FOR_OPENGL_ERRORS
  367. }
  368. void glMultiTexCoord2fARB( GLint, GLfloat, GLfloat)
  369. {
  370. AssertWarn( 0, "glMultiTexCoord2fARB(): this method call needs to be implemented");
  371. }
  372. void glPushAttrib( GLint )
  373. {
  374. AssertWarn( 0, "glPushAttrib(): this method call needs to be implemented");
  375. }
  376. void glPopAttrib()
  377. {
  378. AssertWarn( 0, "glPopAttrib(): this method call needs to be implemented");
  379. }
  380. //void glOrtho( GLfloat left, GLfloat right, GLfloat bottom, GLfloat top, GLfloat zNear, GLfloat zFar)
  381. //{
  382. // GLfloat tx = -(right+left)/(right-left);
  383. // GLfloat ty = -(top+bottom)/(top-bottom);
  384. // GLfloat tz = -(zFar+zNear)/(zFar-zNear);
  385. // MatrixF m = MatrixF(true);
  386. // ((F32*)m)[0] = 2.0f/(right-left);
  387. // ((F32*)m)[3] = tx;
  388. // ((F32*)m)[5] = 2.0f/(top-bottom);
  389. // ((F32*)m)[7] = ty;
  390. // ((F32*)m)[10] = -2.0f/(zFar-zNear);
  391. // ((F32*)m)[11] = tz;
  392. //
  393. // glMultMatrixf( (F32*)(m.transpose())); // make col major for opengl
  394. //}
  395. //void glFrustum( GLfloat left, GLfloat right, GLfloat bottom, GLfloat top, GLfloat zNear, GLfloat zFar )
  396. //{
  397. // MatrixF m = MatrixF(true);
  398. // ((F32*)m)[0] = 2.0f*zNear/(right-left);
  399. // ((F32*)m)[2] = (right+left)/(right-left);
  400. // ((F32*)m)[5] = 2.0f*zNear/(top-bottom);
  401. // ((F32*)m)[6] = (top+bottom)/(top-bottom);
  402. // ((F32*)m)[10] = -(zFar+zNear)/(zFar-zNear);
  403. // ((F32*)m)[11] = -2.0f*zFar*zNear/(zFar-zNear);
  404. // ((F32*)m)[14] = -1.0f;
  405. // ((F32*)m)[15] = 0.0f;
  406. //
  407. // glMultMatrixf( (F32*)(m.transpose())); // make col major for opengl
  408. //}
  409. void glReadBuffer( GLint )
  410. {
  411. AssertWarn( 0, "glReadBuffer(): this method call needs to be implemented");
  412. int glError;
  413. glError = TEST_FOR_OPENGL_ERRORS
  414. }
  415. void glClientActiveTextureARB( GLint texture )
  416. {
  417. glClientActiveTexture( texture );
  418. int glError;
  419. glError = TEST_FOR_OPENGL_ERRORS
  420. }
  421. void glColor3i( GLint r, GLint g, GLint b )
  422. {
  423. glColor4f( ((GLfloat)r) * INV_32767, ((GLfloat)g) * INV_32767, ((GLfloat)b) * INV_32767, 1.0f );
  424. int glError;
  425. glError = TEST_FOR_OPENGL_ERRORS
  426. }
  427. void glColor3ubv( const GLubyte *v )
  428. {
  429. glColor4f( ((GLfloat)v[0]) * INV_255, ((GLfloat)v[1]) * INV_255, ((GLfloat)v[2]) * INV_255, 1.0f );
  430. int glError;
  431. glError = TEST_FOR_OPENGL_ERRORS
  432. }
  433. void glColor4ubv( const GLubyte *v )
  434. {
  435. glColor4f( ((GLfloat)v[0]) * INV_255, ((GLfloat)v[1]) * INV_255, ((GLfloat)v[2]) * INV_255, ((GLfloat)v[3]) * INV_255 );
  436. int glError;
  437. glError = TEST_FOR_OPENGL_ERRORS
  438. }
  439. void glRecti( GLint x1, GLint y1, GLint x2, GLint y2 )
  440. {
  441. AssertFatal( beginEndMode<0, "glRecti(): called inside glBegin/glEnd");
  442. glBegin(GL_LINE_LOOP);
  443. glVertex2i(x1, y1);
  444. glVertex2i(x2, y1);
  445. glVertex2i(x2, y2);
  446. glVertex2i(x1, y2);
  447. glEnd();
  448. int glError;
  449. glError = TEST_FOR_OPENGL_ERRORS
  450. }
  451. void glGetDoublev( GLint pname, GLdouble * params )
  452. {
  453. int i;
  454. GLfloat fparams[16];
  455. glGetFloatv( pname, fparams );
  456. AssertFatal((glGetError() == GL_NO_ERROR), "glGetDoublev parameter invalid");
  457. params[0] = (double)fparams[0];
  458. if ((pname == GL_ALIASED_POINT_SIZE_RANGE) ||
  459. (pname == GL_ALIASED_LINE_WIDTH_RANGE) ||
  460. (pname == GL_DEPTH_RANGE) ||
  461. (pname == GL_MAX_VIEWPORT_DIMS) ||
  462. (pname == GL_SMOOTH_LINE_WIDTH_RANGE) ||
  463. (pname == GL_SMOOTH_POINT_SIZE_RANGE)) {
  464. // 2 items
  465. params[1] = (double)fparams[1];
  466. return;
  467. }
  468. if ((pname == GL_COLOR_CLEAR_VALUE) ||
  469. (pname == GL_COLOR_WRITEMASK) ||
  470. (pname == GL_FOG_COLOR) ||
  471. (pname == GL_LIGHT_MODEL_AMBIENT) ||
  472. (pname == GL_SCISSOR_BOX) ||
  473. (pname == GL_VIEWPORT) ) {
  474. // 4 items
  475. params[1] = (double)fparams[1];
  476. params[2] = (double)fparams[2];
  477. params[3] = (double)fparams[3];
  478. return;
  479. }
  480. if ((pname == GL_PROJECTION_MATRIX) ||
  481. //Luma: Added MODDELVIEW support
  482. (pname == GL_MODELVIEW_MATRIX) ||
  483. //(pname == GL_MODELVIEW_MATRIX_FLOAT_AS_INT_BITS) ||
  484. //(pname == GL_PROJECTION_MATRIX_FLOAT_AS_INT_BITS) ||
  485. (pname == GL_TEXTURE_MATRIX) ) {
  486. // 16 items
  487. for (i=1; i<16; i++) {
  488. params[i] = (double)fparams[i];
  489. }
  490. return;
  491. }
  492. }
  493. void glPolygonMode( GLint, GLint )
  494. {
  495. //AssertFatal( 0, "glPolygonMode(): this method call needs to be implemented");
  496. }
  497. void glLockArraysEXT( GLint, GLint )
  498. {
  499. AssertFatal( 0, "glLockArraysEXT(): this method call needs to be implemented");
  500. }
  501. void glUnlockArraysEXT()
  502. {
  503. AssertFatal( 0, "glUnlockArraysEXT(): this method call needs to be implemented");
  504. }
  505. void glColor3ub( GLint r, GLint g, GLint b )
  506. {
  507. glColor4f( ((GLfloat)r) * INV_255, ((GLfloat)g) * INV_255, ((GLfloat)b) * INV_255, 1.0f );
  508. int glError;
  509. glError = TEST_FOR_OPENGL_ERRORS
  510. }
  511. void glFogi( GLint pname, GLint param )
  512. {
  513. glFogf( pname, (GLfloat)param );
  514. int glError;
  515. glError = TEST_FOR_OPENGL_ERRORS
  516. }
  517. /* -Mat note: only guiCanvas uses this, and before adding this GL2ES stuff we didn't need to use it (it was one of the first things if'ed out)
  518. void glDrawBuffer( GLint buffid )
  519. {
  520. ((EAGLView *)platState.ctx).currentRenderBuffer = buffid;
  521. TEST_FOR_OPENGL_ERRORS
  522. }
  523. */
  524. void glColorTableEXT( GLint, GLint, GLint, GLint, GLint, const ColorI * )
  525. {
  526. AssertFatal( 0, "glColorTableEXT(): this method call needs to be implemented");
  527. }
  528. void glBlendColorEXT( GLfloat, GLfloat, GLfloat, GLfloat )
  529. {
  530. AssertFatal( 0, "glBlendColorEXT(): this method call needs to be implemented");
  531. }
  532. void glBlendEquationEXT( GLint )
  533. {
  534. AssertFatal( 0, "glBlendEquationEXT(): this method call needs to be implemented");
  535. }
  536. void glArrayElement( GLint )
  537. {
  538. AssertFatal( 0, "glArrayElement(): this method call needs to be implemented");
  539. }
  540. void glFogCoordPointerEXT(GLenum, GLsizei, void *)
  541. {
  542. AssertFatal( 0, "glFogCoordPointerEXT(): this method call needs to be implemented");
  543. }
  544. //void glDepthRange( GLfloat, GLfloat )
  545. //{
  546. // AssertFatal( 0, "glDepthRange(): this method call needs to be implemented");
  547. //}
  548. void glTexGeni( GLenum coord, GLenum pname, GLint param )
  549. {
  550. AssertFatal( 0, "glTexGeni(): this method call needs to be implemented");
  551. }
  552. void glTexGenfv( GLenum coord, GLenum pname, const GLfloat *params )
  553. {
  554. AssertFatal( 0, "glTexGenfv(): this method call needs to be implemented");
  555. }
  556. void glClipPlane( GLuint plane, GLdouble * equation )
  557. {
  558. GLfloat fequ[4];
  559. fequ[0] = (GLfloat)equation[0];
  560. fequ[1] = (GLfloat)equation[1];
  561. fequ[2] = (GLfloat)equation[2];
  562. fequ[3] = (GLfloat)equation[3];
  563. glClipPlanef( plane, fequ );
  564. int glError;
  565. glError = TEST_FOR_OPENGL_ERRORS
  566. }
  567. GLboolean glAreTexturesResident( GLsizei, const GLuint *, GLboolean*)
  568. {
  569. int glError;
  570. glError = TEST_FOR_OPENGL_ERRORS
  571. return GL_FALSE;
  572. }
  573. void gluOrtho2D( GLfloat left, GLfloat right, GLfloat bottom, GLfloat top )
  574. {
  575. glOrtho( left, right, bottom, top, -1.0f, 1.0f );
  576. int glError;
  577. glError = TEST_FOR_OPENGL_ERRORS
  578. // GLfloat zNear = -1.0f;
  579. // GLfloat zFar = 1.0f;
  580. // GLfloat tx = -(right+left)/(right-left);
  581. // GLfloat ty = -(top+bottom)/(top-bottom);
  582. // GLfloat tz = -(zFar+zNear)/(zFar-zNear);
  583. // MatrixF m = MatrixF(true);
  584. // ((F32*)m)[0] = 2.0f/(right-left);
  585. // ((F32*)m)[3] = tx;
  586. // ((F32*)m)[5] = 2.0f/(top-bottom);
  587. // ((F32*)m)[7] = ty;
  588. // ((F32*)m)[10] = -2.0f/(zFar-zNear);
  589. // ((F32*)m)[11] = tz;
  590. //
  591. // glMultMatrixf( (F32*)(m.transpose())); // make col major for opengl
  592. }
  593. GLint gluProject( GLdouble objx, GLdouble objy, GLdouble objz, const F64 *model, const F64 * proj, const GLint * vp, F64 * winx, F64 * winy, F64 * winz )
  594. {
  595. Vector4F v = Vector4F( objx, objy, objz, 1.0f );
  596. MatrixF pmat = MatrixF( false );
  597. for (int i=0; i<16; i++) { ((F32*)pmat)[i] = (float)proj[i]; }
  598. MatrixF mmat = MatrixF( false );
  599. for (int i=0; i<16; i++) { ((F32*)mmat)[i] = (float)model[i]; }
  600. //Luma: Projection fix
  601. mmat.transpose();
  602. pmat.transpose();
  603. (pmat.mul(mmat)).mul(v);
  604. //Luma: Projection fix
  605. if(v.w == 0.0f)
  606. {
  607. return GL_FALSE;
  608. }
  609. F32 invW = 1.0f / v.w;
  610. v.x *= invW;
  611. v.y *= invW;
  612. v.z *= invW;
  613. *winx = (GLfloat)vp[0] + (GLfloat)vp[2] * (v.x + 1.0f) * 0.5f;
  614. *winy = (GLfloat)vp[1] + (GLfloat)vp[3] * (v.y + 1.0f) * 0.5f;
  615. *winz = (v.z + 1.0f) * 0.5f;
  616. int glError;
  617. glError = TEST_FOR_OPENGL_ERRORS
  618. return GL_TRUE;
  619. }
  620. GLint gluUnProject( GLdouble winx, GLdouble winy, GLdouble winz, const F64 *model, const F64 * proj, const GLint * vp, F64 * x, F64 * y, F64 * z )
  621. {
  622. Vector4F v = Vector4F( 2.0f*(winx-vp[0])/vp[2] - 1.0f, 2.0f*(winy-vp[1])/vp[2] - 1.0f, 2.0f*vp[2] - 1.0f, 1.0f );
  623. MatrixF pmat = MatrixF( false );
  624. for (int i=0; i<16; i++) { ((F32*)pmat)[i] = (float)proj[i]; }
  625. MatrixF mmat = MatrixF( false );
  626. for (int i=0; i<16; i++) { ((F32*)mmat)[i] = (float)model[i]; }
  627. mmat = pmat.mul(mmat);
  628. mmat = mmat.inverse();
  629. mmat.mul( v );
  630. *x = v.x;
  631. *y = v.y;
  632. *z = v.z;
  633. int glError;
  634. glError = TEST_FOR_OPENGL_ERRORS
  635. return GL_TRUE;
  636. }