gles_glue.c 5.6 KB

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