Mercurial > mplayer.hg
comparison libvo/gl_common.c @ 29942:9b90e1052b32
Use a fallback to make sure the basic OpenGL functions are available instead of
initializing them which does not work well with reinitializations.
author | reimar |
---|---|
date | Wed, 09 Dec 2009 17:50:07 +0000 |
parents | 092c1689c9df |
children | 7f09bc7a4279 |
comparison
equal
deleted
inserted
replaced
29941:092c1689c9df | 29942:9b90e1052b32 |
---|---|
33 #include <ctype.h> | 33 #include <ctype.h> |
34 #include <math.h> | 34 #include <math.h> |
35 #include "gl_common.h" | 35 #include "gl_common.h" |
36 #include "libavutil/common.h" | 36 #include "libavutil/common.h" |
37 | 37 |
38 void (GLAPIENTRY *Begin)(GLenum) = glBegin; | 38 void (GLAPIENTRY *Begin)(GLenum); |
39 void (GLAPIENTRY *End)(void) = glEnd; | 39 void (GLAPIENTRY *End)(void); |
40 void (GLAPIENTRY *Viewport)(GLint, GLint, GLsizei, GLsizei) = glViewport; | 40 void (GLAPIENTRY *Viewport)(GLint, GLint, GLsizei, GLsizei); |
41 void (GLAPIENTRY *MatrixMode)(GLenum) = glMatrixMode; | 41 void (GLAPIENTRY *MatrixMode)(GLenum); |
42 void (GLAPIENTRY *LoadIdentity)(void) = glLoadIdentity; | 42 void (GLAPIENTRY *LoadIdentity)(void); |
43 void (GLAPIENTRY *Scaled)(double, double, double) = glScaled; | 43 void (GLAPIENTRY *Scaled)(double, double, double); |
44 void (GLAPIENTRY *Ortho)(double, double, double, double, double, double) = glOrtho; | 44 void (GLAPIENTRY *Ortho)(double, double, double, double, double, double); |
45 void (GLAPIENTRY *PushMatrix)(void) = glPushMatrix; | 45 void (GLAPIENTRY *PushMatrix)(void); |
46 void (GLAPIENTRY *PopMatrix)(void) = glPopMatrix; | 46 void (GLAPIENTRY *PopMatrix)(void); |
47 void (GLAPIENTRY *Clear)(GLbitfield) = glClear; | 47 void (GLAPIENTRY *Clear)(GLbitfield); |
48 GLuint (GLAPIENTRY *GenLists)(GLsizei) = glGenLists; | 48 GLuint (GLAPIENTRY *GenLists)(GLsizei); |
49 void (GLAPIENTRY *DeleteLists)(GLuint, GLsizei) = glDeleteLists; | 49 void (GLAPIENTRY *DeleteLists)(GLuint, GLsizei); |
50 void (GLAPIENTRY *NewList)(GLuint, GLenum) = glNewList; | 50 void (GLAPIENTRY *NewList)(GLuint, GLenum); |
51 void (GLAPIENTRY *EndList)(void) = glEndList; | 51 void (GLAPIENTRY *EndList)(void); |
52 void (GLAPIENTRY *CallList)(GLuint) = glCallList; | 52 void (GLAPIENTRY *CallList)(GLuint); |
53 void (GLAPIENTRY *CallLists)(GLsizei, GLenum, const GLvoid *) = glCallLists; | 53 void (GLAPIENTRY *CallLists)(GLsizei, GLenum, const GLvoid *); |
54 void (GLAPIENTRY *GenTextures)(GLsizei, GLuint *) = glGenTextures; | 54 void (GLAPIENTRY *GenTextures)(GLsizei, GLuint *); |
55 void (GLAPIENTRY *DeleteTextures)(GLsizei, const GLuint *) = glDeleteTextures; | 55 void (GLAPIENTRY *DeleteTextures)(GLsizei, const GLuint *); |
56 void (GLAPIENTRY *TexEnvi)(GLenum, GLenum, GLint) = glTexEnvi; | 56 void (GLAPIENTRY *TexEnvi)(GLenum, GLenum, GLint); |
57 void (GLAPIENTRY *Color4ub)(GLubyte, GLubyte, GLubyte, GLubyte) = glColor4ub; | 57 void (GLAPIENTRY *Color4ub)(GLubyte, GLubyte, GLubyte, GLubyte); |
58 void (GLAPIENTRY *Color3f)(GLfloat, GLfloat, GLfloat) = glColor3f; | 58 void (GLAPIENTRY *Color3f)(GLfloat, GLfloat, GLfloat); |
59 void (GLAPIENTRY *ClearColor)(GLclampf, GLclampf, GLclampf, GLclampf) = glClearColor; | 59 void (GLAPIENTRY *ClearColor)(GLclampf, GLclampf, GLclampf, GLclampf); |
60 void (GLAPIENTRY *Enable)(GLenum) = glEnable; | 60 void (GLAPIENTRY *Enable)(GLenum); |
61 void (GLAPIENTRY *Disable)(GLenum) = glDisable; | 61 void (GLAPIENTRY *Disable)(GLenum); |
62 const GLubyte *(GLAPIENTRY *GetString)(GLenum) = glGetString; | 62 const GLubyte *(GLAPIENTRY *GetString)(GLenum); |
63 void (GLAPIENTRY *DrawBuffer)(GLenum) = glDrawBuffer; | 63 void (GLAPIENTRY *DrawBuffer)(GLenum); |
64 void (GLAPIENTRY *DepthMask)(GLboolean) = glDepthMask; | 64 void (GLAPIENTRY *DepthMask)(GLboolean); |
65 void (GLAPIENTRY *BlendFunc)(GLenum, GLenum) = glBlendFunc; | 65 void (GLAPIENTRY *BlendFunc)(GLenum, GLenum); |
66 void (GLAPIENTRY *Flush)(void) = glFlush; | 66 void (GLAPIENTRY *Flush)(void); |
67 void (GLAPIENTRY *Finish)(void) = glFinish; | 67 void (GLAPIENTRY *Finish)(void); |
68 void (GLAPIENTRY *PixelStorei)(GLenum, GLint) = glPixelStorei; | 68 void (GLAPIENTRY *PixelStorei)(GLenum, GLint); |
69 void (GLAPIENTRY *TexImage1D)(GLenum, GLint, GLint, GLsizei, GLint, GLenum, GLenum, const GLvoid *) = glTexImage1D; | 69 void (GLAPIENTRY *TexImage1D)(GLenum, GLint, GLint, GLsizei, GLint, GLenum, GLenum, const GLvoid *); |
70 void (GLAPIENTRY *TexImage2D)(GLenum, GLint, GLint, GLsizei, GLsizei, GLint, GLenum, GLenum, const GLvoid *) = glTexImage2D; | 70 void (GLAPIENTRY *TexImage2D)(GLenum, GLint, GLint, GLsizei, GLsizei, GLint, GLenum, GLenum, const GLvoid *); |
71 void (GLAPIENTRY *TexSubImage2D)(GLenum, GLint, GLint, GLint, GLsizei, GLsizei, GLenum, GLenum, const GLvoid *) = glTexSubImage2D; | 71 void (GLAPIENTRY *TexSubImage2D)(GLenum, GLint, GLint, GLint, GLsizei, GLsizei, GLenum, GLenum, const GLvoid *); |
72 void (GLAPIENTRY *TexParameteri)(GLenum, GLenum, GLint) = glTexParameteri; | 72 void (GLAPIENTRY *TexParameteri)(GLenum, GLenum, GLint); |
73 void (GLAPIENTRY *TexParameterf)(GLenum, GLenum, GLfloat) = glTexParameterf; | 73 void (GLAPIENTRY *TexParameterf)(GLenum, GLenum, GLfloat); |
74 void (GLAPIENTRY *TexParameterfv)(GLenum, GLenum, const GLfloat *) = glTexParameterfv; | 74 void (GLAPIENTRY *TexParameterfv)(GLenum, GLenum, const GLfloat *); |
75 void (GLAPIENTRY *TexCoord2f)(GLfloat, GLfloat) = glTexCoord2f; | 75 void (GLAPIENTRY *TexCoord2f)(GLfloat, GLfloat); |
76 void (GLAPIENTRY *Vertex2f)(GLfloat, GLfloat) = glVertex2f; | 76 void (GLAPIENTRY *Vertex2f)(GLfloat, GLfloat); |
77 void (GLAPIENTRY *GetIntegerv)(GLenum, GLint *) = glGetIntegerv; | 77 void (GLAPIENTRY *GetIntegerv)(GLenum, GLint *); |
78 | 78 |
79 /** | 79 /** |
80 * \defgroup glextfunctions OpenGL extension functions | 80 * \defgroup glextfunctions OpenGL extension functions |
81 * | 81 * |
82 * the pointers to these functions are acquired when the OpenGL | 82 * the pointers to these functions are acquired when the OpenGL |
327 | 327 |
328 typedef struct { | 328 typedef struct { |
329 void *funcptr; | 329 void *funcptr; |
330 const char *extstr; | 330 const char *extstr; |
331 const char *funcnames[7]; | 331 const char *funcnames[7]; |
332 void *fallback; | |
332 } extfunc_desc_t; | 333 } extfunc_desc_t; |
333 | 334 |
334 #define DEF_FUNC_DESC(name) {&name, NULL, {"gl"#name, NULL}} | 335 #define DEF_FUNC_DESC(name) {&name, NULL, {"gl"#name, NULL}, gl ##name} |
335 static const extfunc_desc_t extfuncs[] = { | 336 static const extfunc_desc_t extfuncs[] = { |
336 // these aren't extension functions but we query them anyway to allow | 337 // these aren't extension functions but we query them anyway to allow |
337 // different "backends" with one binary | 338 // different "backends" with one binary |
338 DEF_FUNC_DESC(Begin), | 339 DEF_FUNC_DESC(Begin), |
339 DEF_FUNC_DESC(End), | 340 DEF_FUNC_DESC(End), |
357 DEF_FUNC_DESC(Color4ub), | 358 DEF_FUNC_DESC(Color4ub), |
358 DEF_FUNC_DESC(Color3f), | 359 DEF_FUNC_DESC(Color3f), |
359 DEF_FUNC_DESC(ClearColor), | 360 DEF_FUNC_DESC(ClearColor), |
360 DEF_FUNC_DESC(Enable), | 361 DEF_FUNC_DESC(Enable), |
361 DEF_FUNC_DESC(Disable), | 362 DEF_FUNC_DESC(Disable), |
362 DEF_FUNC_DESC(GetString), | |
363 DEF_FUNC_DESC(DrawBuffer), | 363 DEF_FUNC_DESC(DrawBuffer), |
364 DEF_FUNC_DESC(DepthMask), | 364 DEF_FUNC_DESC(DepthMask), |
365 DEF_FUNC_DESC(BlendFunc), | 365 DEF_FUNC_DESC(BlendFunc), |
366 DEF_FUNC_DESC(Flush), | 366 DEF_FUNC_DESC(Flush), |
367 DEF_FUNC_DESC(Finish), | 367 DEF_FUNC_DESC(Finish), |
415 * \param ext2 an extra extension string | 415 * \param ext2 an extra extension string |
416 */ | 416 */ |
417 static void getFunctions(void *(*getProcAddress)(const GLubyte *), | 417 static void getFunctions(void *(*getProcAddress)(const GLubyte *), |
418 const char *ext2) { | 418 const char *ext2) { |
419 const extfunc_desc_t *dsc; | 419 const extfunc_desc_t *dsc; |
420 const char *extensions = (const char *)GetString(GL_EXTENSIONS); | 420 const char *extensions; |
421 char *allexts; | 421 char *allexts; |
422 | |
423 if (!getProcAddress) | |
424 getProcAddress = setNull; | |
425 | |
426 // special case, we need glGetString before starting to find the other functions | |
427 GetString = getProcAddress("glGetString"); | |
428 if (!GetString) | |
429 GetString = glGetString; | |
430 | |
431 extensions = (const char *)GetString(GL_EXTENSIONS); | |
422 if (!extensions) extensions = ""; | 432 if (!extensions) extensions = ""; |
423 if (!ext2) ext2 = ""; | 433 if (!ext2) ext2 = ""; |
424 allexts = malloc(strlen(extensions) + strlen(ext2) + 2); | 434 allexts = malloc(strlen(extensions) + strlen(ext2) + 2); |
425 strcpy(allexts, extensions); | 435 strcpy(allexts, extensions); |
426 strcat(allexts, " "); | 436 strcat(allexts, " "); |
427 strcat(allexts, ext2); | 437 strcat(allexts, ext2); |
428 mp_msg(MSGT_VO, MSGL_DBG2, "OpenGL extensions string:\n%s\n", allexts); | 438 mp_msg(MSGT_VO, MSGL_DBG2, "OpenGL extensions string:\n%s\n", allexts); |
429 if (!getProcAddress) | |
430 getProcAddress = setNull; | |
431 for (dsc = extfuncs; dsc->funcptr; dsc++) { | 439 for (dsc = extfuncs; dsc->funcptr; dsc++) { |
432 void *ptr = NULL; | 440 void *ptr = NULL; |
433 int i; | 441 int i; |
434 if (!dsc->extstr || strstr(allexts, dsc->extstr)) { | 442 if (!dsc->extstr || strstr(allexts, dsc->extstr)) { |
435 for (i = 0; !ptr && dsc->funcnames[i]; i++) | 443 for (i = 0; !ptr && dsc->funcnames[i]; i++) |
436 ptr = getProcAddress((const GLubyte *)dsc->funcnames[i]); | 444 ptr = getProcAddress((const GLubyte *)dsc->funcnames[i]); |
437 } | 445 } |
446 if (!ptr) | |
447 ptr = dsc->fallback; | |
438 *(void **)dsc->funcptr = ptr; | 448 *(void **)dsc->funcptr = ptr; |
439 } | 449 } |
440 if (strstr(allexts, "_texture_float")) | 450 if (strstr(allexts, "_texture_float")) |
441 hqtexfmt = GL_RGB32F; | 451 hqtexfmt = GL_RGB32F; |
442 else if (strstr(allexts, "NV_float_buffer")) | 452 else if (strstr(allexts, "NV_float_buffer")) |