[FFmpeg-devel] [PATCH 3/3] lavd: add opengl device

Reimar Döffinger Reimar.Doeffinger at gmx.de
Tue Jan 14 00:26:21 CET 2014


On 13.01.2014, at 01:41, Lukasz Marek <lukasz.m.luki at gmail.com> wrote:
> +/* MinGW exposes only OpenGL 1.1 API */
> +#if defined(__MINGW32__)
> +#ifndef GL_MAJOR_VERSION
> +#define GL_MAJOR_VERSION                  0x821B
> +#endif
> +#ifndef GL_MINOR_VERSION
> +#define GL_MINOR_VERSION                  0x821C
> +#endif
> +#ifndef GL_NUM_EXTENSIONS
> +#define GL_NUM_EXTENSIONS                 0x821D
> +#endif
> +#ifndef GL_ARRAY_BUFFER
> +#define GL_ARRAY_BUFFER                   0x8892
> +#endif
> +#ifndef GL_ELEMENT_ARRAY_BUFFER
> +#define GL_ELEMENT_ARRAY_BUFFER           0x8893
> +#endif
> +#ifndef GL_STATIC_DRAW
> +#define GL_STATIC_DRAW                    0x88E4
> +#endif
> +#ifndef GL_FRAGMENT_SHADER
> +#define GL_FRAGMENT_SHADER                0x8B30
> +#endif
> +#ifndef GL_VERTEX_SHADER
> +#define GL_VERTEX_SHADER                  0x8B31
> +#endif
> +#ifndef GL_COMPILE_STATUS
> +#define GL_COMPILE_STATUS                 0x8B81
> +#endif
> +#ifndef GL_LINK_STATUS
> +#define GL_LINK_STATUS                    0x8B82
> +#endif
> +#ifndef GL_INFO_LOG_LENGTH
> +#define GL_INFO_LOG_LENGTH                0x8B84
> +#endif

If you want something more complete you could grab MPlayer's gl_compat.h

> +#ifndef PFNGLGETSTRINGIPROC
> +typedef const GLubyte * (APIENTRY *PFNGLGETSTRINGIPROC) (GLenum name, GLuint index);
> +#endif
> +#ifndef PFNGLACTIVETEXTUREPROC
> +typedef void (APIENTRY *PFNGLACTIVETEXTUREPROC) (GLenum texture);
> +#endif
> +#ifndef PFNGLGENBUFFERSPROC
> +typedef void (APIENTRY *PFNGLGENBUFFERSPROC) (GLsizei n, GLuint *buffers);
> +#endif
> +#ifndef PFNGLDELETEBUFFERSPROC
> +typedef void (APIENTRY *PFNGLDELETEBUFFERSPROC) (GLsizei n, const GLuint *buffers);
> +#endif
> +#ifndef PFNGLBUFFERDATAPROC
> +typedef void (APIENTRY *PFNGLBUFFERDATAPROC) (GLenum target, GLsizeiptr size, const GLvoid *data, GLenum usage);
> +#endif
> +#ifndef PFNGLBINDBUFFERPROC
> +typedef void (APIENTRY *PFNGLBINDBUFFERPROC) (GLenum target, GLuint buffer);
> +#endif
> +#ifndef PFNGLGETATTRIBLOCATIONPROC
> +typedef GLint (APIENTRY *PFNGLGETATTRIBLOCATIONPROC) (GLuint program, const GLchar *name);
> +#endif
> +#ifndef PFNGLGETUNIFORMLOCATIONPROC
> +typedef GLint (APIENTRY *PFNGLGETUNIFORMLOCATIONPROC) (GLuint program, const GLchar *name);
> +#endif
> +#ifndef PFNGLUNIFORM1FPROC
> +typedef void (APIENTRY *PFNGLUNIFORM1FPROC) (GLint location, GLfloat v0);
> +#endif
> +#ifndef PFNGLUNIFORM1IPROC
> +typedef void (APIENTRY *PFNGLUNIFORM1IPROC) (GLint location, GLint v0);
> +#endif
> +#ifndef PFNGLUNIFORMMATRIX4FVPROC
> +typedef void (APIENTRY *PFNGLUNIFORMMATRIX4FVPROC) (GLint location, GLsizei count, GLboolean transpose, const GLfloat *value);
> +#endif
> +#ifndef PFNGLCREATEPROGRAMPROC
> +typedef GLuint (APIENTRY *PFNGLCREATEPROGRAMPROC) (void);
> +#endif
> +#ifndef PFNGLDELETEPROGRAMPROC
> +typedef void (APIENTRY *PFNGLDELETEPROGRAMPROC) (GLuint program);
> +#endif
> +#ifndef PFNGLUSEPROGRAMPROC
> +typedef void (APIENTRY *PFNGLUSEPROGRAMPROC) (GLuint program);
> +#endif
> +#ifndef PFNGLLINKPROGRAMPROC
> +typedef void (APIENTRY *PFNGLLINKPROGRAMPROC) (GLuint program);
> +#endif
> +#ifndef PFNGLGETPROGRAMIVPROC
> +typedef void (APIENTRY *PFNGLGETPROGRAMIVPROC) (GLuint program, GLenum pname, GLint *params);
> +#endif
> +#ifndef PFNGLGETPROGRAMINFOLOGPROC
> +typedef void (APIENTRY *PFNGLGETPROGRAMINFOLOGPROC) (GLuint program, GLsizei bufSize, GLsizei *length, GLchar *infoLog);
> +#endif
> +#ifndef PFNGLATTACHSHADERPROC
> +typedef void (APIENTRY *PFNGLATTACHSHADERPROC) (GLuint program, GLuint shader);
> +#endif
> +#ifndef PFNGLCREATESHADERPROC
> +typedef GLuint (APIENTRY *PFNGLCREATESHADERPROC) (GLenum type);
> +#endif
> +#ifndef PFNGLDELETESHADERPROC
> +typedef void (APIENTRY *PFNGLDELETESHADERPROC) (GLuint shader);
> +#endif
> +#ifndef PFNGLCOMPILESHADERPROC
> +typedef void (APIENTRY *PFNGLCOMPILESHADERPROC) (GLuint shader);
> +#endif
> +#ifndef PFNGLSHADERSOURCEPROC
> +typedef void (APIENTRY *PFNGLSHADERSOURCEPROC) (GLuint shader, GLsizei count, const GLchar* *string, const GLint *length);
> +#endif
> +#ifndef PFNGLGETSHADERIVPROC
> +typedef void (APIENTRY *PFNGLGETSHADERIVPROC) (GLuint shader, GLenum pname, GLint *params);
> +#endif
> +#ifndef PFNGLGETSHADERINFOLOGPROC
> +typedef void (APIENTRY *PFNGLGETSHADERINFOLOGPROC) (GLuint shader, GLsizei bufSize, GLsizei *length, GLchar *infoLog);
> +#endif
> +#ifndef PFNGLENABLEVERTEXATTRIBARRAYPROC
> +typedef void (APIENTRY *PFNGLENABLEVERTEXATTRIBARRAYPROC) (GLuint index);
> +#endif
> +#ifndef PFNGLVERTEXATTRIBPOINTERPROC
> +typedef void (APIENTRY *PFNGLVERTEXATTRIBPOINTERPROC) (GLuint index, GLint size, GLenum type, GLboolean normalized, GLsizei stride, const GLvoid *pointer);
> +#endif

I don't really like the ifdef mess, why not just declare your own typedefs (with different names) unconditionally?

> +static int av_cold opengl_load_procedures(FFOpenGLFunctions *procs)
> +{
> +#if HAVE_GLXGETPROCADDRESS
> +#define SelectedGetProcAddress glXGetProcAddress
> +#elif HAVE_WGLGETPROCADDRESS
> +#define SelectedGetProcAddress wglGetProcAddress
> +#endif
> +
> +#define LOAD_OPENGL_FUN(name, type) \
> +    procs->name = (type)SelectedGetProcAddress(#name); \
> +    if (!procs->name) { \
> +        av_log(NULL, AV_LOG_ERROR, "Cannot load OpenGL function: '%s'\n", #name); \
> +        return -1; \
> +    }

If you use SDL, SDL_GL_GetProcAddress is likely to be more reliable.
This is e.g. due to the fact that on Windows you might have both the native and the X11 variant, and you can't know for which your SDL OpenGL context is.
In addition, the current code doesn't seem to be possible to use on OSX. But SDL-based OpenGL should be able to just work on OSX, too.
Lastly, this isn't really how you are supposed to do it. You are supposed to check that the required extensions are available _before_ trying to get the address. At least that's how I learned it.
Lastly, since you already use all the fragment/vertex shader stuff it would be nice if you could test and make it work with GLES v2 from the start.
Though whether you can easily test that depends a lot on what kind of system you are using exactly.
MESA's GLES2 implementation IMHO works fairly well for testing for example.
I didn't properly review the rest, it's quite a lot of code after all.


More information about the ffmpeg-devel mailing list