Do _not_ use rbx on x86_64, it will fail to compile with PIC, besides it
[mplayer/glamo.git] / libvo / gl_common.h
blob6f9ec6f1e3eb26ee4caa11d35339830a4de0c2cd
1 /*
2 * This file is part of MPlayer.
4 * MPlayer is free software; you can redistribute it and/or modify
5 * it under the terms of the GNU General Public License as published by
6 * the Free Software Foundation; either version 2 of the License, or
7 * (at your option) any later version.
9 * MPlayer is distributed in the hope that it will be useful,
10 * but WITHOUT ANY WARRANTY; without even the implied warranty of
11 * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
12 * GNU General Public License for more details.
14 * You should have received a copy of the GNU General Public License along
15 * with MPlayer; if not, write to the Free Software Foundation, Inc.,
16 * 51 Franklin Street, Fifth Floor, Boston, MA 02110-1301 USA.
19 #ifndef MPLAYER_GL_COMMON_H
20 #define MPLAYER_GL_COMMON_H
22 #include <stdio.h>
23 #include <stdint.h>
25 #include "config.h"
26 #include "mp_msg.h"
28 #include "video_out.h"
30 #ifdef GL_WIN32
31 #include <windows.h>
32 #include <GL/gl.h>
33 #include "w32_common.h"
34 #else
35 #include <GL/gl.h>
36 #include <X11/Xlib.h>
37 #include <GL/glx.h>
38 #include "x11_common.h"
39 #endif
41 // workaround for some gl.h headers
42 #ifndef APIENTRY
43 #ifdef GLAPIENTRY
44 #define APIENTRY GLAPIENTRY
45 #elif defined(GL_WIN32)
46 #define APIENTRY __stdcall
47 #else
48 #define APIENTRY
49 #endif
50 #endif
52 /**
53 * \defgroup glextdefines OpenGL extension defines
55 * conditionally define all extension defines used.
56 * vendor specific extensions should be marked as such
57 * (e.g. _NV), _ARB is not used to ease readability.
58 * \{
60 #ifndef GL_TEXTURE_3D
61 #define GL_TEXTURE_3D 0x806F
62 #endif
63 #ifndef GL_TEXTURE_WRAP_R
64 #define GL_TEXTURE_WRAP_R 0x8072
65 #endif
66 #ifndef GL_CLAMP_TO_EDGE
67 #define GL_CLAMP_TO_EDGE 0x812F
68 #endif
69 #ifndef GL_REGISTER_COMBINERS_NV
70 #define GL_REGISTER_COMBINERS_NV 0x8522
71 #endif
72 #ifndef GL_MAX_GENERAL_COMBINERS_NV
73 #define GL_MAX_GENERAL_COMBINERS_NV 0x854D
74 #endif
75 #ifndef GL_NUM_GENERAL_COMBINERS_NV
76 #define GL_NUM_GENERAL_COMBINERS_NV 0x854E
77 #endif
78 #ifndef GL_CONSTANT_COLOR0_NV
79 #define GL_CONSTANT_COLOR0_NV 0x852A
80 #endif
81 #ifndef GL_CONSTANT_COLOR1_NV
82 #define GL_CONSTANT_COLOR1_NV 0x852B
83 #endif
84 #ifndef GL_COMBINER0_NV
85 #define GL_COMBINER0_NV 0x8550
86 #endif
87 #ifndef GL_COMBINER1_NV
88 #define GL_COMBINER1_NV 0x8551
89 #endif
90 #ifndef GL_VARIABLE_A_NV
91 #define GL_VARIABLE_A_NV 0x8523
92 #endif
93 #ifndef GL_VARIABLE_B_NV
94 #define GL_VARIABLE_B_NV 0x8524
95 #endif
96 #ifndef GL_VARIABLE_C_NV
97 #define GL_VARIABLE_C_NV 0x8525
98 #endif
99 #ifndef GL_VARIABLE_D_NV
100 #define GL_VARIABLE_D_NV 0x8526
101 #endif
102 #ifndef GL_UNSIGNED_INVERT_NV
103 #define GL_UNSIGNED_INVERT_NV 0x8537
104 #endif
105 #ifndef GL_HALF_BIAS_NORMAL_NV
106 #define GL_HALF_BIAS_NORMAL_NV 0x853A
107 #endif
108 #ifndef GL_SIGNED_IDENTITY_NV
109 #define GL_SIGNED_IDENTITY_NV 0x853C
110 #endif
111 #ifndef GL_SCALE_BY_FOUR_NV
112 #define GL_SCALE_BY_FOUR_NV 0x853F
113 #endif
114 #ifndef GL_DISCARD_NV
115 #define GL_DISCARD_NV 0x8530
116 #endif
117 #ifndef GL_SPARE0_NV
118 #define GL_SPARE0_NV 0x852E
119 #endif
120 #ifndef GL_FRAGMENT_SHADER_ATI
121 #define GL_FRAGMENT_SHADER_ATI 0x8920
122 #endif
123 #ifndef GL_NUM_FRAGMENT_REGISTERS_ATI
124 #define GL_NUM_FRAGMENT_REGISTERS_ATI 0x896E
125 #endif
126 #ifndef GL_REG_0_ATI
127 #define GL_REG_0_ATI 0x8921
128 #endif
129 #ifndef GL_REG_1_ATI
130 #define GL_REG_1_ATI 0x8922
131 #endif
132 #ifndef GL_REG_2_ATI
133 #define GL_REG_2_ATI 0x8923
134 #endif
135 #ifndef GL_CON_0_ATI
136 #define GL_CON_0_ATI 0x8941
137 #endif
138 #ifndef GL_CON_1_ATI
139 #define GL_CON_1_ATI 0x8942
140 #endif
141 #ifndef GL_ADD_ATI
142 #define GL_ADD_ATI 0x8963
143 #endif
144 #ifndef GL_MUL_ATI
145 #define GL_MUL_ATI 0x8964
146 #endif
147 #ifndef GL_MAD_ATI
148 #define GL_MAD_ATI 0x8968
149 #endif
150 #ifndef GL_SWIZZLE_STR_ATI
151 #define GL_SWIZZLE_STR_ATI 0x8976
152 #endif
153 #ifndef GL_4X_BIT_ATI
154 #define GL_4X_BIT_ATI 2
155 #endif
156 #ifndef GL_BIAS_BIT_ATI
157 #define GL_BIAS_BIT_ATI 8
158 #endif
159 #ifndef GL_MAX_TEXTURE_UNITS
160 #define GL_MAX_TEXTURE_UNITS 0x84E2
161 #endif
162 #ifndef GL_TEXTURE0
163 #define GL_TEXTURE0 0x84C0
164 #endif
165 #ifndef GL_TEXTURE1
166 #define GL_TEXTURE1 0x84C1
167 #endif
168 #ifndef GL_TEXTURE2
169 #define GL_TEXTURE2 0x84C2
170 #endif
171 #ifndef GL_TEXTURE3
172 #define GL_TEXTURE3 0x84C3
173 #endif
174 #ifndef GL_TEXTURE_RECTANGLE
175 #define GL_TEXTURE_RECTANGLE 0x84F5
176 #endif
177 #ifndef GL_PIXEL_UNPACK_BUFFER
178 #define GL_PIXEL_UNPACK_BUFFER 0x88EC
179 #endif
180 #ifndef GL_STREAM_DRAW
181 #define GL_STREAM_DRAW 0x88E0
182 #endif
183 #ifndef GL_DYNAMIC_DRAW
184 #define GL_DYNAMIC_DRAW 0x88E8
185 #endif
186 #ifndef GL_WRITE_ONLY
187 #define GL_WRITE_ONLY 0x88B9
188 #endif
189 #ifndef GL_BGR
190 #define GL_BGR 0x80E0
191 #endif
192 #ifndef GL_BGRA
193 #define GL_BGRA 0x80E1
194 #endif
195 #ifndef GL_UNSIGNED_BYTE_3_3_2
196 #define GL_UNSIGNED_BYTE_3_3_2 0x8032
197 #endif
198 #ifndef GL_UNSIGNED_BYTE_2_3_3_REV
199 #define GL_UNSIGNED_BYTE_2_3_3_REV 0x8362
200 #endif
201 #ifndef GL_UNSIGNED_SHORT_4_4_4_4
202 #define GL_UNSIGNED_SHORT_4_4_4_4 0x8033
203 #endif
204 #ifndef GL_UNSIGNED_SHORT_4_4_4_4_REV
205 #define GL_UNSIGNED_SHORT_4_4_4_4_REV 0x8365
206 #endif
207 #ifndef GL_UNSIGNED_SHORT_5_6_5
208 #define GL_UNSIGNED_SHORT_5_6_5 0x8363
209 #endif
210 #ifndef GL_UNSIGNED_INT_8_8_8_8
211 #define GL_UNSIGNED_INT_8_8_8_8 0x8035
212 #endif
213 #ifndef GL_UNSIGNED_INT_8_8_8_8_REV
214 #define GL_UNSIGNED_INT_8_8_8_8_REV 0x8367
215 #endif
216 #ifndef GL_UNSIGNED_SHORT_5_6_5_REV
217 #define GL_UNSIGNED_SHORT_5_6_5_REV 0x8364
218 #endif
219 #ifndef GL_UNSIGNED_INT_10_10_10_2
220 #define GL_UNSIGNED_INT_10_10_10_2 0x8036
221 #endif
222 #ifndef GL_UNSIGNED_INT_2_10_10_10_REV
223 #define GL_UNSIGNED_INT_2_10_10_10_REV 0x8368
224 #endif
225 #ifndef GL_UNSIGNED_SHORT_5_5_5_1
226 #define GL_UNSIGNED_SHORT_5_5_5_1 0x8034
227 #endif
228 #ifndef GL_UNSIGNED_SHORT_1_5_5_5_REV
229 #define GL_UNSIGNED_SHORT_1_5_5_5_REV 0x8366
230 #endif
231 #ifndef GL_UNSIGNED_SHORT_8_8
232 #define GL_UNSIGNED_SHORT_8_8 0x85BA
233 #endif
234 #ifndef GL_UNSIGNED_SHORT_8_8_REV
235 #define GL_UNSIGNED_SHORT_8_8_REV 0x85BB
236 #endif
237 #ifndef GL_YCBCR_MESA
238 #define GL_YCBCR_MESA 0x8757
239 #endif
240 #ifndef GL_RGB32F
241 #define GL_RGB32F 0x8815
242 #endif
243 #ifndef GL_FLOAT_RGB32_NV
244 #define GL_FLOAT_RGB32_NV 0x8889
245 #endif
246 #ifndef GL_UNPACK_CLIENT_STORAGE_APPLE
247 #define GL_UNPACK_CLIENT_STORAGE_APPLE 0x85B2
248 #endif
249 #ifndef GL_FRAGMENT_PROGRAM
250 #define GL_FRAGMENT_PROGRAM 0x8804
251 #endif
252 #ifndef GL_PROGRAM_FORMAT_ASCII
253 #define GL_PROGRAM_FORMAT_ASCII 0x8875
254 #endif
255 #ifndef GL_PROGRAM_ERROR_POSITION
256 #define GL_PROGRAM_ERROR_POSITION 0x864B
257 #endif
258 #ifndef GL_MAX_TEXTURE_IMAGE_UNITS
259 #define GL_MAX_TEXTURE_IMAGE_UNITS 0x8872
260 #endif
261 #ifndef GL_PROGRAM_ERROR_STRING
262 #define GL_PROGRAM_ERROR_STRING 0x8874
263 #endif
264 /** \} */ // end of glextdefines group
266 void glAdjustAlignment(int stride);
268 const char *glValName(GLint value);
270 int glFindFormat(uint32_t format, int *bpp, GLint *gl_texfmt,
271 GLenum *gl_format, GLenum *gl_type);
272 int glFmt2bpp(GLenum format, GLenum type);
273 void glCreateClearTex(GLenum target, GLenum fmt, GLenum format, GLenum type, GLint filter,
274 int w, int h, unsigned char val);
275 int glCreatePPMTex(GLenum target, GLenum fmt, GLint filter,
276 FILE *f, int *width, int *height, int *maxval);
277 void glUploadTex(GLenum target, GLenum format, GLenum type,
278 const void *dataptr, int stride,
279 int x, int y, int w, int h, int slice);
280 void glDrawTex(GLfloat x, GLfloat y, GLfloat w, GLfloat h,
281 GLfloat tx, GLfloat ty, GLfloat tw, GLfloat th,
282 int sx, int sy, int rect_tex, int is_yv12, int flip);
283 int loadGPUProgram(GLenum target, char *prog);
285 /** \addtogroup glconversion
286 * \{ */
287 //! do not use YUV conversion, this should always stay 0
288 #define YUV_CONVERSION_NONE 0
289 //! use nVidia specific register combiners for YUV conversion
290 #define YUV_CONVERSION_COMBINERS 1
291 //! use a fragment program for YUV conversion
292 #define YUV_CONVERSION_FRAGMENT 2
293 //! use a fragment program for YUV conversion with gamma using POW
294 #define YUV_CONVERSION_FRAGMENT_POW 3
295 //! use a fragment program with additional table lookup for YUV conversion
296 #define YUV_CONVERSION_FRAGMENT_LOOKUP 4
297 //! use ATI specific register combiners ("fragment program")
298 #define YUV_CONVERSION_COMBINERS_ATI 5
299 //! use a fragment program with 3D table lookup for YUV conversion
300 #define YUV_CONVERSION_FRAGMENT_LOOKUP3D 6
301 //! use normal bilinear scaling for textures
302 #define YUV_SCALER_BILIN 0
303 //! use higher quality bicubic scaling for textures
304 #define YUV_SCALER_BICUB 1
305 //! use cubic scaling in X and normal linear scaling in Y direction
306 #define YUV_SCALER_BICUB_X 2
307 //! use cubic scaling without additional lookup texture
308 #define YUV_SCALER_BICUB_NOTEX 3
309 #define YUV_SCALER_UNSHARP 4
310 #define YUV_SCALER_UNSHARP2 5
311 //! mask for conversion type
312 #define YUV_CONVERSION_MASK 0xF
313 //! mask for scaler type
314 #define YUV_SCALER_MASK 0xF
315 //! shift value for luminance scaler type
316 #define YUV_LUM_SCALER_SHIFT 8
317 //! shift value for chrominance scaler type
318 #define YUV_CHROM_SCALER_SHIFT 12
319 //! extract conversion out of type
320 #define YUV_CONVERSION(t) (t & YUV_CONVERSION_MASK)
321 //! extract luminance scaler out of type
322 #define YUV_LUM_SCALER(t) ((t >> YUV_LUM_SCALER_SHIFT) & YUV_SCALER_MASK)
323 //! extract chrominance scaler out of type
324 #define YUV_CHROM_SCALER(t) ((t >> YUV_CHROM_SCALER_SHIFT) & YUV_SCALER_MASK)
325 /** \} */
326 typedef struct {
327 GLenum target;
328 int type;
329 float brightness;
330 float contrast;
331 float hue;
332 float saturation;
333 float rgamma;
334 float ggamma;
335 float bgamma;
336 int texw;
337 int texh;
338 float filter_strength;
339 } gl_conversion_params_t;
341 void glSetupYUVConversion(gl_conversion_params_t *params);
342 void glEnableYUVConversion(GLenum target, int type);
343 void glDisableYUVConversion(GLenum target, int type);
345 /** \addtogroup glcontext
346 * \{ */
347 //! could not set new window, will continue drawing into the old one.
348 #define SET_WINDOW_FAILED -1
349 //! new window is set, could even transfer the OpenGL context.
350 #define SET_WINDOW_OK 0
351 //! new window is set, but the OpenGL context needs to be reinitialized.
352 #define SET_WINDOW_REINIT 1
353 /** \} */
355 #ifdef GL_WIN32
356 #define vo_border() vo_w32_border()
357 #define vo_check_events() vo_w32_check_events()
358 #define vo_fullscreen() vo_w32_fullscreen()
359 #define vo_ontop() vo_w32_ontop()
360 #define vo_uninit() vo_w32_uninit()
361 int setGlWindow(int *vinfo, HGLRC *context, HWND win);
362 void releaseGlContext(int *vinfo, HGLRC *context);
363 #else
364 #define vo_border() vo_x11_border()
365 #define vo_check_events() vo_x11_check_events(mDisplay)
366 #define vo_fullscreen() vo_x11_fullscreen()
367 #define vo_ontop() vo_x11_ontop()
368 #define vo_uninit() vo_x11_uninit()
369 int setGlWindow(XVisualInfo **vinfo, GLXContext *context, Window win);
370 void releaseGlContext(XVisualInfo **vinfo, GLXContext *context);
371 #endif
372 void swapGlBuffers(void);
374 extern void (APIENTRY *GenBuffers)(GLsizei, GLuint *);
375 extern void (APIENTRY *DeleteBuffers)(GLsizei, const GLuint *);
376 extern void (APIENTRY *BindBuffer)(GLenum, GLuint);
377 extern GLvoid* (APIENTRY *MapBuffer)(GLenum, GLenum);
378 extern GLboolean (APIENTRY *UnmapBuffer)(GLenum);
379 extern void (APIENTRY *BufferData)(GLenum, intptr_t, const GLvoid *, GLenum);
380 extern void (APIENTRY *CombinerParameterfv)(GLenum, const GLfloat *);
381 extern void (APIENTRY *CombinerParameteri)(GLenum, GLint);
382 extern void (APIENTRY *CombinerInput)(GLenum, GLenum, GLenum, GLenum, GLenum,
383 GLenum);
384 extern void (APIENTRY *CombinerOutput)(GLenum, GLenum, GLenum, GLenum, GLenum,
385 GLenum, GLenum, GLboolean, GLboolean,
386 GLboolean);
387 extern void (APIENTRY *BeginFragmentShader)(void);
388 extern void (APIENTRY *EndFragmentShader)(void);
389 extern void (APIENTRY *SampleMap)(GLuint, GLuint, GLenum);
390 extern void (APIENTRY *ColorFragmentOp2)(GLenum, GLuint, GLuint, GLuint, GLuint,
391 GLuint, GLuint, GLuint, GLuint, GLuint);
392 extern void (APIENTRY *ColorFragmentOp3)(GLenum, GLuint, GLuint, GLuint, GLuint,
393 GLuint, GLuint, GLuint, GLuint, GLuint,
394 GLuint, GLuint, GLuint);
395 extern void (APIENTRY *SetFragmentShaderConstant)(GLuint, const GLfloat *);
396 extern void (APIENTRY *ActiveTexture)(GLenum);
397 extern void (APIENTRY *BindTexture)(GLenum, GLuint);
398 extern void (APIENTRY *MultiTexCoord2f)(GLenum, GLfloat, GLfloat);
399 extern void (APIENTRY *GenPrograms)(GLsizei, GLuint *);
400 extern void (APIENTRY *DeletePrograms)(GLsizei, const GLuint *);
401 extern void (APIENTRY *BindProgram)(GLenum, GLuint);
402 extern void (APIENTRY *ProgramString)(GLenum, GLenum, GLsizei, const GLvoid *);
403 extern void (APIENTRY *ProgramEnvParameter4f)(GLenum, GLuint, GLfloat, GLfloat,
404 GLfloat, GLfloat);
405 extern int (APIENTRY *SwapInterval)(int);
406 extern void (APIENTRY *TexImage3D)(GLenum, GLint, GLenum, GLsizei, GLsizei,
407 GLsizei, GLint, GLenum, GLenum, const GLvoid *);
408 extern void* (APIENTRY *AllocateMemoryMESA)(void *, int, size_t, float, float, float);
409 extern void (APIENTRY *FreeMemoryMESA)(void *, int, void *);
411 #endif /* MPLAYER_GL_COMMON_H */