Better fallback for APIENTRY when compiling for Windows
[mplayer/greg.git] / libvo / gl_common.h
blob2c84190fb8e2cbac723ca7901e00ef20040ea287
1 #ifndef __GL_COMMON_H__
2 #define __GL_COMMON_H__
4 #include "mp_msg.h"
5 #include "config.h"
7 #include <GL/gl.h>
8 #include "video_out.h"
10 #ifdef GL_WIN32
11 #include <windows.h>
12 #include <GL/glext.h>
13 #include "w32_common.h"
14 #else
15 #include <X11/Xlib.h>
16 #include <GL/glx.h>
17 #include "x11_common.h"
18 #endif
20 // workaround for some gl.h headers
21 #ifndef APIENTRY
22 #ifdef GLAPIENTRY
23 #define APIENTRY GLAPIENTRY
24 #elif defined(GL_WIN32)
25 #define APIENTRY __stdcall
26 #else
27 #define APIENTRY
28 #endif
29 #endif
31 /**
32 * \defgroup glextdefines OpenGL extension defines
34 * conditionally define all extension defines used.
35 * vendor specific extensions should be marked as such
36 * (e.g. _NV), _ARB is not used to ease readability.
37 * \{
39 #ifndef GL_REGISTER_COMBINERS_NV
40 #define GL_REGISTER_COMBINERS_NV 0x8522
41 #endif
42 #ifndef GL_MAX_GENERAL_COMBINERS_NV
43 #define GL_MAX_GENERAL_COMBINERS_NV 0x854D
44 #endif
45 #ifndef GL_NUM_GENERAL_COMBINERS_NV
46 #define GL_NUM_GENERAL_COMBINERS_NV 0x854E
47 #endif
48 #ifndef GL_CONSTANT_COLOR0_NV
49 #define GL_CONSTANT_COLOR0_NV 0x852A
50 #endif
51 #ifndef GL_CONSTANT_COLOR1_NV
52 #define GL_CONSTANT_COLOR1_NV 0x852B
53 #endif
54 #ifndef GL_COMBINER0_NV
55 #define GL_COMBINER0_NV 0x8550
56 #endif
57 #ifndef GL_COMBINER1_NV
58 #define GL_COMBINER1_NV 0x8551
59 #endif
60 #ifndef GL_VARIABLE_A_NV
61 #define GL_VARIABLE_A_NV 0x8523
62 #endif
63 #ifndef GL_VARIABLE_B_NV
64 #define GL_VARIABLE_B_NV 0x8524
65 #endif
66 #ifndef GL_VARIABLE_C_NV
67 #define GL_VARIABLE_C_NV 0x8525
68 #endif
69 #ifndef GL_VARIABLE_D_NV
70 #define GL_VARIABLE_D_NV 0x8526
71 #endif
72 #ifndef GL_UNSIGNED_INVERT_NV
73 #define GL_UNSIGNED_INVERT_NV 0x8537
74 #endif
75 #ifndef GL_HALF_BIAS_NORMAL_NV
76 #define GL_HALF_BIAS_NORMAL_NV 0x853A
77 #endif
78 #ifndef GL_SIGNED_IDENTITY_NV
79 #define GL_SIGNED_IDENTITY_NV 0x853C
80 #endif
81 #ifndef GL_SCALE_BY_FOUR_NV
82 #define GL_SCALE_BY_FOUR_NV 0x853F
83 #endif
84 #ifndef GL_DISCARD_NV
85 #define GL_DISCARD_NV 0x8530
86 #endif
87 #ifndef GL_SPARE0_NV
88 #define GL_SPARE0_NV 0x852E
89 #endif
90 #ifndef GL_FRAGMENT_SHADER_ATI
91 #define GL_FRAGMENT_SHADER_ATI 0x8920
92 #endif
93 #ifndef GL_NUM_FRAGMENT_REGISTERS_ATI
94 #define GL_NUM_FRAGMENT_REGISTERS_ATI 0x896E
95 #endif
96 #ifndef GL_REG_0_ATI
97 #define GL_REG_0_ATI 0x8921
98 #endif
99 #ifndef GL_REG_1_ATI
100 #define GL_REG_1_ATI 0x8922
101 #endif
102 #ifndef GL_REG_2_ATI
103 #define GL_REG_2_ATI 0x8923
104 #endif
105 #ifndef GL_CON_0_ATI
106 #define GL_CON_0_ATI 0x8941
107 #endif
108 #ifndef GL_CON_1_ATI
109 #define GL_CON_1_ATI 0x8942
110 #endif
111 #ifndef GL_ADD_ATI
112 #define GL_ADD_ATI 0x8963
113 #endif
114 #ifndef GL_MUL_ATI
115 #define GL_MUL_ATI 0x8964
116 #endif
117 #ifndef GL_MAD_ATI
118 #define GL_MAD_ATI 0x8968
119 #endif
120 #ifndef GL_SWIZZLE_STR_ATI
121 #define GL_SWIZZLE_STR_ATI 0x8976
122 #endif
123 #ifndef GL_4X_BIT_ATI
124 #define GL_4X_BIT_ATI 2
125 #endif
126 #ifndef GL_BIAS_BIT_ATI
127 #define GL_BIAS_BIT_ATI 8
128 #endif
129 #ifndef GL_MAX_TEXTURE_UNITS
130 #define GL_MAX_TEXTURE_UNITS 0x84E2
131 #endif
132 #ifndef GL_TEXTURE0
133 #define GL_TEXTURE0 0x84C0
134 #endif
135 #ifndef GL_TEXTURE1
136 #define GL_TEXTURE1 0x84C1
137 #endif
138 #ifndef GL_TEXTURE2
139 #define GL_TEXTURE2 0x84C2
140 #endif
141 #ifndef GL_TEXTURE3
142 #define GL_TEXTURE3 0x84C3
143 #endif
144 #ifndef GL_TEXTURE_RECTANGLE
145 #define GL_TEXTURE_RECTANGLE 0x84F5
146 #endif
147 #ifndef GL_PIXEL_UNPACK_BUFFER
148 #define GL_PIXEL_UNPACK_BUFFER 0x88EC
149 #endif
150 #ifndef GL_STREAM_DRAW
151 #define GL_STREAM_DRAW 0x88E0
152 #endif
153 #ifndef GL_DYNAMIC_DRAW
154 #define GL_DYNAMIC_DRAW 0x88E8
155 #endif
156 #ifndef GL_WRITE_ONLY
157 #define GL_WRITE_ONLY 0x88B9
158 #endif
159 #ifndef GL_BGR
160 #define GL_BGR 0x80E0
161 #endif
162 #ifndef GL_BGRA
163 #define GL_BGRA 0x80E1
164 #endif
165 #ifndef GL_UNSIGNED_BYTE_3_3_2
166 #define GL_UNSIGNED_BYTE_3_3_2 0x8032
167 #endif
168 #ifndef GL_UNSIGNED_BYTE_2_3_3_REV
169 #define GL_UNSIGNED_BYTE_2_3_3_REV 0x8362
170 #endif
171 #ifndef GL_UNSIGNED_SHORT_5_6_5
172 #define GL_UNSIGNED_SHORT_5_6_5 0x8363
173 #endif
174 #ifndef GL_UNSIGNED_SHORT_5_6_5_REV
175 #define GL_UNSIGNED_SHORT_5_6_5_REV 0x8364
176 #endif
177 #ifndef GL_UNSIGNED_SHORT_5_5_5_1
178 #define GL_UNSIGNED_SHORT_5_5_5_1 0x8034
179 #endif
180 #ifndef GL_UNSIGNED_SHORT_1_5_5_5_REV
181 #define GL_UNSIGNED_SHORT_1_5_5_5_REV 0x8366
182 #endif
183 #ifndef GL_FRAGMENT_PROGRAM
184 #define GL_FRAGMENT_PROGRAM 0x8804
185 #endif
186 #ifndef GL_PROGRAM_FORMAT_ASCII
187 #define GL_PROGRAM_FORMAT_ASCII 0x8875
188 #endif
189 #ifndef GL_PROGRAM_ERROR_POSITION
190 #define GL_PROGRAM_ERROR_POSITION 0x864B
191 #endif
192 /** \} */ // end of glextdefines group
194 void glAdjustAlignment(int stride);
196 const char *glValName(GLint value);
198 int glFindFormat(uint32_t format, int *bpp, GLint *gl_texfmt,
199 GLenum *gl_format, GLenum *gl_type);
200 int glFmt2bpp(GLenum format, GLenum type);
201 void glCreateClearTex(GLenum target, GLenum fmt, GLint filter,
202 int w, int h, unsigned char val);
203 int glCreatePPMTex(GLenum target, GLenum fmt, GLint filter,
204 FILE *f, int *width, int *height, int *maxval);
205 void glUploadTex(GLenum target, GLenum format, GLenum type,
206 const void *data, int stride,
207 int x, int y, int w, int h, int slice);
208 void glDrawTex(GLfloat x, GLfloat y, GLfloat w, GLfloat h,
209 GLfloat tx, GLfloat ty, GLfloat tw, GLfloat th,
210 int sx, int sy, int rect_tex, int is_yv12, int flip);
212 /** \addtogroup glconversion
213 * \{ */
214 //! do not use YUV conversion, this should always stay 0
215 #define YUV_CONVERSION_NONE 0
216 //! use nVidia specific register combiners for YUV conversion
217 #define YUV_CONVERSION_COMBINERS 1
218 //! use a fragment program for YUV conversion
219 #define YUV_CONVERSION_FRAGMENT 2
220 //! use a fragment program for YUV conversion with gamma using POW
221 #define YUV_CONVERSION_FRAGMENT_POW 3
222 //! use a fragment program with additional table lookup for YUV conversion
223 #define YUV_CONVERSION_FRAGMENT_LOOKUP 4
224 //! use ATI specific register combiners ("fragment program")
225 #define YUV_CONVERSION_COMBINERS_ATI 5
226 /** \} */
227 void glSetupYUVConversion(GLenum target, int type,
228 float brightness, float contrast,
229 float hue, float saturation,
230 float rgamma, float ggamma, float bgamma);
231 void inline glEnableYUVConversion(GLenum target, int type);
232 void inline glDisableYUVConversion(GLenum target, int type);
234 /** \addtogroup glcontext
235 * \{ */
236 //! could not set new window, will continue drawing into the old one.
237 #define SET_WINDOW_FAILED -1
238 //! new window is set, could even transfer the OpenGL context.
239 #define SET_WINDOW_OK 0
240 //! new window is set, but the OpenGL context needs to be reinitialized.
241 #define SET_WINDOW_REINIT 1
242 /** \} */
244 #ifdef GL_WIN32
245 #define vo_check_events() vo_w32_check_events()
246 #define vo_fullscreen() vo_w32_fullscreen()
247 #define vo_ontop() vo_w32_ontop()
248 #define vo_uninit() vo_w32_uninit()
249 int setGlWindow(int *vinfo, HGLRC *context, HWND win);
250 void releaseGlContext(int *vinfo, HGLRC *context);
251 #else
252 #define vo_check_events() vo_x11_check_events(mDisplay)
253 #define vo_fullscreen() vo_x11_fullscreen()
254 #define vo_ontop() vo_x11_ontop()
255 #define vo_uninit() vo_x11_uninit()
256 int setGlWindow(XVisualInfo **vinfo, GLXContext *context, Window win);
257 void releaseGlContext(XVisualInfo **vinfo, GLXContext *context);
258 #endif
259 void swapGlBuffers(void);
261 extern void (APIENTRY *GenBuffers)(GLsizei, GLuint *);
262 extern void (APIENTRY *DeleteBuffers)(GLsizei, const GLuint *);
263 extern void (APIENTRY *BindBuffer)(GLenum, GLuint);
264 extern GLvoid* (APIENTRY *MapBuffer)(GLenum, GLenum);
265 extern GLboolean (APIENTRY *UnmapBuffer)(GLenum);
266 extern void (APIENTRY *BufferData)(GLenum, intptr_t, const GLvoid *, GLenum);
267 extern void (APIENTRY *CombinerParameterfv)(GLenum, const GLfloat *);
268 extern void (APIENTRY *CombinerParameteri)(GLenum, GLint);
269 extern void (APIENTRY *CombinerInput)(GLenum, GLenum, GLenum, GLenum, GLenum,
270 GLenum);
271 extern void (APIENTRY *CombinerOutput)(GLenum, GLenum, GLenum, GLenum, GLenum,
272 GLenum, GLenum, GLboolean, GLboolean,
273 GLboolean);
274 extern void (APIENTRY *BeginFragmentShader)(void);
275 extern void (APIENTRY *EndFragmentShader)(void);
276 extern void (APIENTRY *SampleMap)(GLuint, GLuint, GLenum);
277 extern void (APIENTRY *ColorFragmentOp2)(GLenum, GLuint, GLuint, GLuint, GLuint,
278 GLuint, GLuint, GLuint, GLuint, GLuint);
279 extern void (APIENTRY *ColorFragmentOp3)(GLenum, GLuint, GLuint, GLuint, GLuint,
280 GLuint, GLuint, GLuint, GLuint, GLuint,
281 GLuint, GLuint, GLuint);
282 extern void (APIENTRY *SetFragmentShaderConstant)(GLuint, const GLfloat *);
283 extern void (APIENTRY *ActiveTexture)(GLenum);
284 extern void (APIENTRY *BindTexture)(GLenum, GLuint);
285 extern void (APIENTRY *MultiTexCoord2f)(GLenum, GLfloat, GLfloat);
286 extern void (APIENTRY *GenPrograms)(GLsizei, GLuint *);
287 extern void (APIENTRY *DeletePrograms)(GLsizei, const GLuint *);
288 extern void (APIENTRY *BindProgram)(GLenum, GLuint);
289 extern void (APIENTRY *ProgramString)(GLenum, GLenum, GLsizei, const GLvoid *);
290 extern void (APIENTRY *ProgramEnvParameter4f)(GLenum, GLuint, GLfloat, GLfloat,
291 GLfloat, GLfloat);
292 extern int (APIENTRY *SwapInterval)(int);
294 #endif