gles_glue.c 5.1 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118119120121122123124125126127128129130131132133134135136137138139140141142143144145146147148149150151152153154155156157158159160161162163164165166167168169170171172173174175176177178179180181182183184185186187188189190191192193194195196197198199200201
  1. /*
  2. Copyright (C) 2009-2011 id Software LLC, a ZeniMax Media company.
  3. Copyright (C) 2009 Id Software, Inc.
  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.
  8. This program is distributed in the hope that it will be useful,
  9. but WITHOUT ANY WARRANTY; without even the implied warranty of
  10. MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
  11. GNU General Public License for more details.
  12. You should have received a copy of the GNU General Public License
  13. along with this program; if not, write to the Free Software
  14. Foundation, Inc., 59 Temple Place - Suite 330, Boston, MA 02111-1307, USA.
  15. */
  16. #include "doomiphone.h"
  17. //int registration_sequence;
  18. //#include "iphone_gl.h"
  19. void GLCheckError(const char *message) {
  20. GLint err = glGetError();
  21. if ( err != GL_NO_ERROR ) {
  22. printf( "GL ERROR %d from %s\n", err, message );
  23. }
  24. }
  25. unsigned int QGLBeginStarted = 0;
  26. struct Vertex {
  27. float xyz[3];
  28. float st[2];
  29. #ifdef VERTEX_COLOR
  30. GLubyte c[4];
  31. #endif
  32. };
  33. #define MAX_VERTS 16384
  34. typedef struct Vertex Vertex;
  35. Vertex immediate[ MAX_VERTS ];
  36. Vertex vab;
  37. short quad_indexes[MAX_VERTS * 3 / 2 ];
  38. int curr_vertex;
  39. GLenum curr_prim;
  40. void SetImmediateModeGLVertexArrays() {
  41. glVertexPointer( 3, GL_FLOAT, sizeof( Vertex ), immediate[ 0 ].xyz );
  42. glEnableClientState( GL_VERTEX_ARRAY );
  43. glTexCoordPointer( 2, GL_FLOAT, sizeof( Vertex ), immediate[ 0 ].st );
  44. glEnableClientState( GL_TEXTURE_COORD_ARRAY );
  45. #ifdef VERTEX_COLOR
  46. glColorPointer( 4, GL_UNSIGNED_BYTE, sizeof( Vertex ), immediate[ 0 ].c );
  47. glEnableClientState( GL_COLOR_ARRAY );
  48. #endif
  49. }
  50. void InitImmediateModeGL() {
  51. for ( int i = 0; i < MAX_VERTS * 3 / 2; i+=6 ) {
  52. int q = i / 6 * 4;
  53. quad_indexes[ i + 0 ] = q + 0;
  54. quad_indexes[ i + 1 ] = q + 1;
  55. quad_indexes[ i + 2 ] = q + 2;
  56. quad_indexes[ i + 3 ] = q + 0;
  57. quad_indexes[ i + 4 ] = q + 2;
  58. quad_indexes[ i + 5 ] = q + 3;
  59. }
  60. SetImmediateModeGLVertexArrays();
  61. }
  62. void glBegin( GLenum prim ) {
  63. curr_vertex = 0;
  64. curr_prim = prim;
  65. }
  66. void glVertex3f( GLfloat x, GLfloat y, GLfloat z ) {
  67. assert( curr_vertex < MAX_VERTS );
  68. vab.xyz[ 0 ] = x;
  69. vab.xyz[ 1 ] = y;
  70. vab.xyz[ 2 ] = z;
  71. immediate[ curr_vertex ] = vab;
  72. curr_vertex++;
  73. }
  74. void glVertex3fv( GLfloat *xyz ) {
  75. assert( curr_vertex < MAX_VERTS );
  76. vab.xyz[ 0 ] = xyz[0];
  77. vab.xyz[ 1 ] = xyz[1];
  78. vab.xyz[ 2 ] = xyz[2];
  79. immediate[ curr_vertex ] = vab;
  80. curr_vertex++;
  81. }
  82. void glVertex2f( GLfloat x, GLfloat y ) {
  83. assert( curr_vertex < MAX_VERTS );
  84. vab.xyz[ 0 ] = (float)x;
  85. vab.xyz[ 1 ] = (float)y;
  86. vab.xyz[ 2 ] = 0.0f;
  87. immediate[ curr_vertex ] = vab;
  88. curr_vertex++;
  89. }
  90. void glVertex2i( GLint x, GLint y ) {
  91. assert( curr_vertex < MAX_VERTS );
  92. vab.xyz[ 0 ] = (float)x;
  93. vab.xyz[ 1 ] = (float)y;
  94. vab.xyz[ 2 ] = 0.0f;
  95. immediate[ curr_vertex ] = vab;
  96. curr_vertex++;
  97. }
  98. #ifdef VERTEX_COLOR
  99. void glColor4ub( GLubyte r, GLubyte g, GLubyte b, GLubyte a ) {
  100. vab.c[ 0 ] = r;
  101. vab.c[ 1 ] = g;
  102. vab.c[ 2 ] = b;
  103. vab.c[ 3 ] = a;
  104. }
  105. void glColor4ubv( GLubyte *rgba ) {
  106. vab.c[ 0 ] = rgba[0];
  107. vab.c[ 1 ] = rgba[1];
  108. vab.c[ 2 ] = rgba[2];
  109. vab.c[ 3 ] = rgba[3];
  110. }
  111. void glColor4f( GLfloat r, GLfloat g, GLfloat b, GLfloat a ) {
  112. vab.c[ 0 ] = (GLubyte) ( r * 255 );
  113. vab.c[ 1 ] = (GLubyte) ( g * 255 );
  114. vab.c[ 2 ] = (GLubyte) ( b * 255 );
  115. vab.c[ 3 ] = (GLubyte) ( a * 255 );
  116. }
  117. void glColor4fv( GLfloat *rgba ) {
  118. vab.c[ 0 ] = (GLubyte) ( rgba[0] * 255 );
  119. vab.c[ 1 ] = (GLubyte) ( rgba[1] * 255 );
  120. vab.c[ 2 ] = (GLubyte) ( rgba[2] * 255 );
  121. vab.c[ 3 ] = (GLubyte) ( rgba[3] * 255 );
  122. }
  123. void glColor3f( GLfloat r, GLfloat g, GLfloat b ) {
  124. vab.c[ 0 ] = (GLubyte) ( r * 255 );
  125. vab.c[ 1 ] = (GLubyte) ( g * 255 );
  126. vab.c[ 2 ] = (GLubyte) ( b * 255 );
  127. vab.c[ 3 ] = 255;
  128. }
  129. #endif
  130. void glTexCoord2i( GLint s, GLint t ) {
  131. vab.st[ 0 ] = (float)s;
  132. vab.st[ 1 ] = (float)t;
  133. }
  134. void glTexCoord2f( GLfloat s, GLfloat t ) {
  135. vab.st[ 0 ] = s;
  136. vab.st[ 1 ] = t;
  137. }
  138. void glTexCoord2fv( GLfloat *st ) {
  139. vab.st[ 0 ] = st[0];
  140. vab.st[ 1 ] = st[1];
  141. }
  142. void glEnd() {
  143. #if 0
  144. glVertexPointer( 3, GL_FLOAT, sizeof( Vertex ), immediate[ 0 ].xyz );
  145. glTexCoordPointer( 2, GL_FLOAT, sizeof( Vertex ), immediate[ 0 ].st );
  146. glColorPointer( 4, GL_UNSIGNED_BYTE, sizeof( Vertex ), immediate[ 0 ].c );
  147. glEnableClientState( GL_VERTEX_ARRAY );
  148. glEnableClientState( GL_TEXTURE_COORD_ARRAY );
  149. glEnableClientState( GL_COLOR_ARRAY );
  150. #endif
  151. if ( curr_prim == GL_QUADS ) {
  152. glDrawElements( GL_TRIANGLES, curr_vertex / 4 * 6, GL_UNSIGNED_SHORT, quad_indexes );
  153. } else {
  154. glDrawArrays( curr_prim, 0, curr_vertex );
  155. }
  156. curr_vertex = 0;
  157. curr_prim = 0;
  158. }
  159. void landscapeViewport( GLint x, GLint y, GLsizei width, GLsizei height ) {
  160. y = 0; // !@#
  161. if ( revLand->value ) {
  162. glViewport( displayheight - (y+height), x, height, width );
  163. } else {
  164. glViewport( y, x, height, width );
  165. }
  166. }
  167. void landscapeScissor( GLint x, GLint y, GLsizei width, GLsizei height ) {
  168. y = 0; // !@#
  169. if ( revLand->value ) {
  170. glScissor( displayheight - (y+height), x, height, width );
  171. } else {
  172. glScissor( y, x, height, width );
  173. }
  174. }