SDL_opengl.h 7.4 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118119120121122123124125126127128129130131132133134135136137138139140141142143144145146147148149150151152153154155156157158159160161162163164165166167168169170171172173174175176177178179180181182183184185186187188189190191192193194195196197198199200201202203204205206207208209210211212213214215216
  1. /*
  2. * SDL_opengl.h
  3. * doom
  4. *
  5. * Created by John Carmack on 4/13/09.
  6. * Copyright 2009 idSoftware. All rights reserved.
  7. *
  8. * iPhone glue to get the prBoom code compiling
  9. * Replaces SDL_opengl.h
  10. */
  11. #ifndef __SDL_OPENGL_H__
  12. #define __SDL_OPENGL_H__
  13. #include <OpenGLES/ES1/gl.h>
  14. #include <OpenGLES/ES1/glext.h>
  15. #ifdef __cplusplus
  16. extern "C" {
  17. #endif
  18. #define GLAPIENTRY
  19. // no colorTable in ES
  20. typedef void (* PFNGLCOLORTABLEEXTPROC) (GLenum target, GLenum internalFormat, GLsizei width, GLenum format, GLenum type, const GLvoid *table);
  21. static inline GLubyte *gluErrorString( int err ) { (void)err; return (GLubyte *)"GLU error"; }
  22. static inline void *SDL_GL_GetProcAddress( const char * proc ) { (void)proc; return 0; }
  23. static inline void SDL_GL_SwapBuffers() {}
  24. // we need to emulate immediate mode gl for ES
  25. void glBegin( GLenum prim );
  26. void glVertex3f( GLfloat x, GLfloat y, GLfloat z );
  27. void glVertex3fv( GLfloat *xyz );
  28. void glVertex2f( GLfloat x, GLfloat y );
  29. void glVertex2i( GLint x, GLint y );
  30. void glTexCoord2i( GLint s, GLint t );
  31. void glTexCoord2f( GLfloat s, GLfloat t );
  32. void glTexCoord2fv( GLfloat *st );
  33. void glEnd();
  34. // Doom just uses state color for all draw calls, setting it once
  35. // before a glBegin, rather than setting it each vertex, so we
  36. // don't need to emulate the color functions.
  37. //#defne VERTEX_COLOR
  38. #ifdef VERTEX_COLOR
  39. void glColor4ub( GLubyte r, GLubyte g, GLubyte b, GLubyte a );
  40. void glColor4f( GLfloat r, GLfloat g, GLfloat b, GLfloat a );
  41. void glColor4fv( GLfloat *rgba );
  42. void glColor3f( GLfloat r, GLfloat g, GLfloat b );
  43. #endif
  44. // GLES only defines glColor4ub and glColor4f, so define the others in terms of that
  45. #define glColor4fv(x) glColor4f(x[0],x[1],x[2],x[3])
  46. #define glColor4ubv(x) glColor4ub(x[0],x[1],x[2],x[3])
  47. #define glColor3f(r,g,b) glColor4f(r,g,b,1)
  48. // The width and height need to be flipped for iPhone landscape mode,
  49. // so redefine these functions to something that can do the work behind
  50. // the scenes.
  51. void landscapeViewport( GLint x, GLint y, GLsizei width, GLsizei height );
  52. void landscapeScissor( GLint x, GLint y, GLsizei width, GLsizei height );
  53. #define glViewport landscapeViewport
  54. #define glScissor landscapeScissor
  55. // ES made matching fixed and floating versions of some functions
  56. #define glClearDepth glClearDepthf
  57. #define glOrtho glOrthof
  58. #define glFogi glFogx
  59. // no GLdouble in ES, but needed for glu tesselator
  60. typedef double GLdouble;
  61. // ES doesn't have the messy clamp-to-half-border mode
  62. #define GL_CLAMP GL_CLAMP_TO_EDGE
  63. // this is the internal format used by the prBoom gl code
  64. // ES doesn't allow format conversions between external and internal,
  65. // so we need to manually convert to 5551 before doing glTexSubImage
  66. #define GL_RGBA8 GL_RGBA
  67. #define GL_RGBA2 GL_RGBA
  68. // not available in ES, so prBoom's skies must be implemeted differently
  69. static inline void glTexGenfv( int a, int b, void * c ) { (void)a; (void)b; (void)c; }
  70. static inline void glTexGenf( int a, int b, int c ) { (void)a; (void)b; (void)c; }
  71. // texGen enums not present in ES
  72. #define GL_S 0x2000
  73. #define GL_T 0x2001
  74. #define GL_R 0x2002
  75. #define GL_Q 0x2003
  76. #define GL_OBJECT_LINEAR 0x2401
  77. #define GL_OBJECT_PLANE 0x2501
  78. #define GL_EYE_LINEAR 0x2400
  79. #define GL_EYE_PLANE 0x2502
  80. #define GL_TEXTURE_GEN_MODE 0x2500
  81. #define GL_TEXTURE_GEN_S 0x0C60
  82. #define GL_TEXTURE_GEN_T 0x0C61
  83. #define GL_TEXTURE_GEN_R 0x0C62
  84. #define GL_TEXTURE_GEN_Q 0x0C63
  85. // other extensions not present in ES
  86. // Whlle the iPhone exports the extension for paletted
  87. // textures, it isn't actually supported in hardware, so
  88. // they are expanded internally on glTexImage2D, making their
  89. // use completely counterproductive.
  90. #define GL_SHARED_TEXTURE_PALETTE_EXT 0x81FB
  91. #define GL_COLOR_INDEX 0x1900
  92. #define GL_COLOR_INDEX8_EXT 0x80E5
  93. //===========================
  94. // all this for the glu tesselator, used by prBoom to make drawable sector geometry
  95. //===========================
  96. #include "../libtess/tess.h"
  97. /* TessCallback */
  98. #define GLU_TESS_BEGIN 100100
  99. #define GLU_BEGIN 100100
  100. #define GLU_TESS_VERTEX 100101
  101. #define GLU_VERTEX 100101
  102. #define GLU_TESS_END 100102
  103. #define GLU_END 100102
  104. #define GLU_TESS_ERROR 100103
  105. #define GLU_TESS_EDGE_FLAG 100104
  106. #define GLU_EDGE_FLAG 100104
  107. #define GLU_TESS_COMBINE 100105
  108. #define GLU_TESS_BEGIN_DATA 100106
  109. #define GLU_TESS_VERTEX_DATA 100107
  110. #define GLU_TESS_END_DATA 100108
  111. #define GLU_TESS_ERROR_DATA 100109
  112. #define GLU_TESS_EDGE_FLAG_DATA 100110
  113. #define GLU_TESS_COMBINE_DATA 100111
  114. /* TessContour */
  115. #define GLU_CW 100120
  116. #define GLU_CCW 100121
  117. #define GLU_INTERIOR 100122
  118. #define GLU_EXTERIOR 100123
  119. #define GLU_UNKNOWN 100124
  120. /* TessProperty */
  121. #define GLU_TESS_WINDING_RULE 100140
  122. #define GLU_TESS_BOUNDARY_ONLY 100141
  123. #define GLU_TESS_TOLERANCE 100142
  124. /* TessError */
  125. #define GLU_TESS_ERROR1 100151
  126. #define GLU_TESS_ERROR2 100152
  127. #define GLU_TESS_ERROR3 100153
  128. #define GLU_TESS_ERROR4 100154
  129. #define GLU_TESS_ERROR5 100155
  130. #define GLU_TESS_ERROR6 100156
  131. #define GLU_TESS_ERROR7 100157
  132. #define GLU_TESS_ERROR8 100158
  133. #define GLU_TESS_MISSING_BEGIN_POLYGON 100151
  134. #define GLU_TESS_MISSING_BEGIN_CONTOUR 100152
  135. #define GLU_TESS_MISSING_END_POLYGON 100153
  136. #define GLU_TESS_MISSING_END_CONTOUR 100154
  137. #define GLU_TESS_COORD_TOO_LARGE 100155
  138. #define GLU_TESS_NEED_COMBINE_CALLBACK 100156
  139. /* TessWinding */
  140. #define GLU_TESS_WINDING_ODD 100130
  141. #define GLU_TESS_WINDING_NONZERO 100131
  142. #define GLU_TESS_WINDING_POSITIVE 100132
  143. #define GLU_TESS_WINDING_NEGATIVE 100133
  144. #define GLU_TESS_WINDING_ABS_GEQ_TWO 100134
  145. /* ErrorCode */
  146. #define GLU_INVALID_ENUM 100900
  147. #define GLU_INVALID_VALUE 100901
  148. #define GLU_OUT_OF_MEMORY 100902
  149. #define GLU_INCOMPATIBLE_GL_VERSION 100903
  150. #define GLU_INVALID_OPERATION 100904
  151. #define GLAPI
  152. #define GLAPIENTRYP
  153. typedef struct GLUtesselator GLUtesselator;
  154. typedef GLUtesselator GLUtesselatorObj;
  155. typedef GLUtesselator GLUtriangulatorObj;
  156. #define GLU_TESS_MAX_COORD 1.0e150
  157. /* Internal convenience typedefs */
  158. typedef void (GLAPIENTRYP _GLUfuncptr)();
  159. GLAPI void GLAPIENTRY gluTessBeginContour (GLUtesselator* tess);
  160. GLAPI void GLAPIENTRY gluTessBeginPolygon (GLUtesselator* tess, GLvoid* data);
  161. GLAPI void GLAPIENTRY gluTessCallback (GLUtesselator* tess, GLenum which, _GLUfuncptr CallBackFunc);
  162. GLAPI void GLAPIENTRY gluTessEndContour (GLUtesselator* tess);
  163. GLAPI void GLAPIENTRY gluTessEndPolygon (GLUtesselator* tess);
  164. GLAPI void GLAPIENTRY gluTessNormal (GLUtesselator* tess, GLdouble valueX, GLdouble valueY, GLdouble valueZ);
  165. GLAPI void GLAPIENTRY gluTessProperty (GLUtesselator* tess, GLenum which, GLdouble data);
  166. GLAPI void GLAPIENTRY gluTessVertex (GLUtesselator* tess, GLdouble *location, GLvoid* data);
  167. GLUtesselator * GLAPIENTRY gluNewTess( void );
  168. void GLAPIENTRY gluDeleteTess( GLUtesselator *tess );
  169. #ifdef __cplusplus
  170. }
  171. #endif
  172. #endif