2008-09-07 16:09:51 +02:00
|
|
|
/*
|
|
|
|
* common OpenGL routines
|
2005-09-25 18:41:28 +02:00
|
|
|
*
|
2010-04-25 08:52:13 +02:00
|
|
|
* copyleft (C) 2005-2010 Reimar Döffinger <Reimar.Doeffinger@gmx.de>
|
2005-09-15 00:08:04 +02:00
|
|
|
* Special thanks go to the xine team and Matthias Hopf, whose video_out_opengl.c
|
|
|
|
* gave me lots of good ideas.
|
2008-09-07 16:09:51 +02:00
|
|
|
*
|
2015-04-13 09:36:54 +02:00
|
|
|
* This file is part of mpv.
|
2008-09-07 16:09:51 +02:00
|
|
|
*
|
2015-04-13 09:36:54 +02:00
|
|
|
* mpv is free software; you can redistribute it and/or modify
|
2008-09-07 16:09:51 +02:00
|
|
|
* it under the terms of the GNU General Public License as published by
|
|
|
|
* the Free Software Foundation; either version 2 of the License, or
|
|
|
|
* (at your option) any later version.
|
|
|
|
*
|
2015-04-13 09:36:54 +02:00
|
|
|
* mpv is distributed in the hope that it will be useful,
|
2008-09-07 16:09:51 +02:00
|
|
|
* but WITHOUT ANY WARRANTY; without even the implied warranty of
|
|
|
|
* MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
|
|
|
|
* GNU General Public License for more details.
|
|
|
|
*
|
|
|
|
* You should have received a copy of the GNU General Public License along
|
2015-04-13 09:36:54 +02:00
|
|
|
* with mpv. If not, see <http://www.gnu.org/licenses/>.
|
2010-06-13 12:42:32 +02:00
|
|
|
*
|
|
|
|
* You can alternatively redistribute this file and/or
|
|
|
|
* modify it under the terms of the GNU Lesser General Public
|
|
|
|
* License as published by the Free Software Foundation; either
|
|
|
|
* version 2.1 of the License, or (at your option) any later version.
|
2005-09-15 00:08:04 +02:00
|
|
|
*/
|
2008-09-07 16:09:51 +02:00
|
|
|
|
|
|
|
/**
|
|
|
|
* \file gl_common.c
|
|
|
|
* \brief OpenGL helper functions used by vo_gl.c and vo_gl2.c
|
|
|
|
*/
|
|
|
|
|
2011-09-25 11:18:07 +02:00
|
|
|
#include <stddef.h>
|
2005-07-27 19:22:24 +02:00
|
|
|
#include <stdlib.h>
|
2005-09-15 00:08:04 +02:00
|
|
|
#include <stdio.h>
|
2005-07-27 19:22:24 +02:00
|
|
|
#include <string.h>
|
2012-03-31 00:33:53 +02:00
|
|
|
#include <stdbool.h>
|
2005-09-15 00:08:04 +02:00
|
|
|
#include <math.h>
|
2012-10-03 01:54:13 +02:00
|
|
|
#include <assert.h>
|
2011-09-25 11:18:07 +02:00
|
|
|
#include "talloc.h"
|
2015-08-29 04:12:56 +02:00
|
|
|
#include "common.h"
|
2014-07-13 20:12:13 +02:00
|
|
|
#include "common/common.h"
|
2013-12-17 02:02:25 +01:00
|
|
|
#include "options/options.h"
|
|
|
|
#include "options/m_option.h"
|
2005-09-25 18:41:28 +02:00
|
|
|
|
2012-10-03 01:54:13 +02:00
|
|
|
// This guesses if the current GL context is a suspected software renderer.
|
|
|
|
static bool is_software_gl(GL *gl)
|
|
|
|
{
|
|
|
|
const char *renderer = gl->GetString(GL_RENDERER);
|
|
|
|
const char *vendor = gl->GetString(GL_VENDOR);
|
|
|
|
return !(renderer && vendor) ||
|
|
|
|
strcmp(renderer, "Software Rasterizer") == 0 ||
|
|
|
|
strstr(renderer, "llvmpipe") ||
|
|
|
|
strcmp(vendor, "Microsoft Corporation") == 0 ||
|
|
|
|
strcmp(renderer, "Mesa X11") == 0;
|
|
|
|
}
|
|
|
|
|
2014-12-09 22:36:28 +01:00
|
|
|
static void GLAPIENTRY dummy_glBindFramebuffer(GLenum target, GLuint framebuffer)
|
2014-12-09 22:28:16 +01:00
|
|
|
{
|
|
|
|
assert(framebuffer == 0);
|
|
|
|
}
|
|
|
|
|
2015-03-25 12:36:31 +01:00
|
|
|
static bool check_ext(GL *gl, const char *name)
|
|
|
|
{
|
|
|
|
const char *exts = gl->extensions;
|
|
|
|
char *s = strstr(exts, name);
|
|
|
|
char *e = s ? s + strlen(name) : NULL;
|
|
|
|
return s && (s == exts || s[-1] == ' ') && (e[0] == ' ' || !e[0]);
|
|
|
|
}
|
|
|
|
|
2012-10-03 01:54:13 +02:00
|
|
|
#define FN_OFFS(name) offsetof(GL, name)
|
|
|
|
|
2015-03-25 12:40:45 +01:00
|
|
|
#define DEF_FN(name) {FN_OFFS(name), "gl" # name}
|
|
|
|
#define DEF_FN_NAME(name, str) {FN_OFFS(name), str}
|
2012-10-03 01:54:13 +02:00
|
|
|
|
|
|
|
struct gl_function {
|
|
|
|
ptrdiff_t offset;
|
2015-03-25 12:40:45 +01:00
|
|
|
char *name;
|
2006-01-07 20:53:51 +01:00
|
|
|
};
|
|
|
|
|
2012-10-03 01:54:13 +02:00
|
|
|
struct gl_functions {
|
|
|
|
const char *extension; // introduced with this extension in any version
|
|
|
|
int provides; // bitfield of MPGL_CAP_* constants
|
|
|
|
int ver_core; // introduced as required function
|
|
|
|
int ver_removed; // removed as required function (no replacement)
|
2014-12-18 23:51:21 +01:00
|
|
|
int ver_es_core; // introduced as required GL ES function
|
|
|
|
int ver_es_removed; // removed as required function (no replacement)
|
2014-06-10 23:56:05 +02:00
|
|
|
const struct gl_function *functions;
|
2012-10-03 01:54:13 +02:00
|
|
|
};
|
|
|
|
|
2015-01-21 20:32:42 +01:00
|
|
|
#define MAX_FN_COUNT 100 // max functions per gl_functions section
|
2012-10-03 01:54:13 +02:00
|
|
|
|
2014-12-18 23:51:21 +01:00
|
|
|
// Note: to keep the number of sections low, some functions are in multiple
|
|
|
|
// sections (if there are tricky combinations of GL/ES versions)
|
2014-06-10 23:56:05 +02:00
|
|
|
static const struct gl_functions gl_functions[] = {
|
2015-01-21 20:32:42 +01:00
|
|
|
// GL 2.1+ desktop and GLES 2.0+ (anything we support)
|
|
|
|
// Probably all of these are in GL 2.0 too, but we require GLSL 120.
|
2014-12-18 23:51:21 +01:00
|
|
|
{
|
2015-01-21 20:32:42 +01:00
|
|
|
.ver_core = 210,
|
2014-12-18 23:51:21 +01:00
|
|
|
.ver_es_core = 200,
|
2014-06-10 23:56:05 +02:00
|
|
|
.functions = (const struct gl_function[]) {
|
2012-10-03 01:54:13 +02:00
|
|
|
DEF_FN(ActiveTexture),
|
2014-12-18 23:51:21 +01:00
|
|
|
DEF_FN(AttachShader),
|
|
|
|
DEF_FN(BindAttribLocation),
|
|
|
|
DEF_FN(BindBuffer),
|
2012-10-03 01:54:13 +02:00
|
|
|
DEF_FN(BindTexture),
|
2015-01-21 20:32:42 +01:00
|
|
|
DEF_FN(BlendFuncSeparate),
|
2014-12-18 23:51:21 +01:00
|
|
|
DEF_FN(BufferData),
|
2015-01-21 20:32:42 +01:00
|
|
|
DEF_FN(Clear),
|
|
|
|
DEF_FN(ClearColor),
|
2012-10-03 01:54:13 +02:00
|
|
|
DEF_FN(CompileShader),
|
|
|
|
DEF_FN(CreateProgram),
|
|
|
|
DEF_FN(CreateShader),
|
2014-12-18 23:51:21 +01:00
|
|
|
DEF_FN(DeleteBuffers),
|
2012-10-03 01:54:13 +02:00
|
|
|
DEF_FN(DeleteProgram),
|
2014-12-18 23:51:21 +01:00
|
|
|
DEF_FN(DeleteShader),
|
2015-01-21 20:32:42 +01:00
|
|
|
DEF_FN(DeleteTextures),
|
|
|
|
DEF_FN(Disable),
|
2014-12-18 23:51:21 +01:00
|
|
|
DEF_FN(DisableVertexAttribArray),
|
2015-01-21 20:32:42 +01:00
|
|
|
DEF_FN(DrawArrays),
|
|
|
|
DEF_FN(Enable),
|
2014-12-18 23:51:21 +01:00
|
|
|
DEF_FN(EnableVertexAttribArray),
|
2015-01-21 20:32:42 +01:00
|
|
|
DEF_FN(Finish),
|
|
|
|
DEF_FN(Flush),
|
2014-12-18 23:51:21 +01:00
|
|
|
DEF_FN(GenBuffers),
|
2015-01-21 20:32:42 +01:00
|
|
|
DEF_FN(GenTextures),
|
|
|
|
DEF_FN(GetAttribLocation),
|
|
|
|
DEF_FN(GetError),
|
|
|
|
DEF_FN(GetIntegerv),
|
2012-10-03 01:54:13 +02:00
|
|
|
DEF_FN(GetProgramInfoLog),
|
|
|
|
DEF_FN(GetProgramiv),
|
2015-01-21 20:32:42 +01:00
|
|
|
DEF_FN(GetShaderInfoLog),
|
|
|
|
DEF_FN(GetShaderiv),
|
|
|
|
DEF_FN(GetString),
|
2014-12-18 23:51:21 +01:00
|
|
|
DEF_FN(GetUniformLocation),
|
|
|
|
DEF_FN(LinkProgram),
|
2015-01-21 20:32:42 +01:00
|
|
|
DEF_FN(PixelStorei),
|
|
|
|
DEF_FN(ReadPixels),
|
2014-12-18 23:51:21 +01:00
|
|
|
DEF_FN(ShaderSource),
|
2015-01-21 20:32:42 +01:00
|
|
|
DEF_FN(TexImage2D),
|
|
|
|
DEF_FN(TexParameteri),
|
|
|
|
DEF_FN(TexSubImage2D),
|
2012-10-03 01:54:13 +02:00
|
|
|
DEF_FN(Uniform1f),
|
|
|
|
DEF_FN(Uniform2f),
|
|
|
|
DEF_FN(Uniform3f),
|
|
|
|
DEF_FN(Uniform1i),
|
2013-05-26 01:48:39 +02:00
|
|
|
DEF_FN(UniformMatrix2fv),
|
2012-10-03 01:54:13 +02:00
|
|
|
DEF_FN(UniformMatrix3fv),
|
2014-12-18 23:51:21 +01:00
|
|
|
DEF_FN(UseProgram),
|
|
|
|
DEF_FN(VertexAttribPointer),
|
2015-01-21 20:32:42 +01:00
|
|
|
DEF_FN(Viewport),
|
|
|
|
{0}
|
2012-10-03 01:54:13 +02:00
|
|
|
},
|
|
|
|
},
|
2015-01-21 20:32:42 +01:00
|
|
|
// GL 2.1+ desktop only (and GLSL 120 shaders)
|
2012-10-03 01:54:13 +02:00
|
|
|
{
|
2014-12-18 23:51:21 +01:00
|
|
|
.ver_core = 210,
|
2015-03-13 11:55:31 +01:00
|
|
|
.provides = MPGL_CAP_ROW_LENGTH | MPGL_CAP_1D_TEX | MPGL_CAP_3D_TEX,
|
2014-06-10 23:56:05 +02:00
|
|
|
.functions = (const struct gl_function[]) {
|
2015-01-21 20:32:42 +01:00
|
|
|
DEF_FN(DrawBuffer),
|
|
|
|
DEF_FN(GetTexLevelParameteriv),
|
2014-12-18 23:51:21 +01:00
|
|
|
DEF_FN(MapBuffer),
|
2015-01-21 20:32:42 +01:00
|
|
|
DEF_FN(ReadBuffer),
|
|
|
|
DEF_FN(TexImage1D),
|
2014-12-18 23:51:21 +01:00
|
|
|
DEF_FN(TexImage3D),
|
|
|
|
DEF_FN(UnmapBuffer),
|
|
|
|
{0}
|
|
|
|
},
|
|
|
|
},
|
2015-01-21 20:32:42 +01:00
|
|
|
// GL 3.0+ and ES 3.x core only functions.
|
2014-12-18 23:51:21 +01:00
|
|
|
{
|
|
|
|
.ver_core = 300,
|
|
|
|
.ver_es_core = 300,
|
|
|
|
.functions = (const struct gl_function[]) {
|
2012-10-03 01:54:13 +02:00
|
|
|
DEF_FN(GetStringi),
|
2014-12-18 23:51:21 +01:00
|
|
|
// for ES 3.0
|
2014-12-24 16:54:47 +01:00
|
|
|
DEF_FN(GetTexLevelParameteriv),
|
2014-12-18 23:51:21 +01:00
|
|
|
DEF_FN(ReadBuffer),
|
|
|
|
DEF_FN(UnmapBuffer),
|
2012-10-03 01:54:13 +02:00
|
|
|
{0}
|
|
|
|
},
|
|
|
|
},
|
2014-12-19 00:58:56 +01:00
|
|
|
// Useful for ES 2.0
|
|
|
|
{
|
|
|
|
.ver_core = 110,
|
|
|
|
.ver_es_core = 300,
|
|
|
|
.extension = "GL_EXT_unpack_subimage",
|
|
|
|
.provides = MPGL_CAP_ROW_LENGTH,
|
|
|
|
},
|
2012-10-03 01:54:13 +02:00
|
|
|
// Framebuffers, extension in GL 2.x, core in GL 3.x core.
|
|
|
|
{
|
2014-12-18 23:51:21 +01:00
|
|
|
.ver_core = 300,
|
2015-07-27 23:27:49 +02:00
|
|
|
.ver_es_core = 200,
|
2012-10-03 01:54:13 +02:00
|
|
|
.extension = "GL_ARB_framebuffer_object",
|
|
|
|
.provides = MPGL_CAP_FB,
|
2014-06-10 23:56:05 +02:00
|
|
|
.functions = (const struct gl_function[]) {
|
2012-10-03 01:54:13 +02:00
|
|
|
DEF_FN(BindFramebuffer),
|
|
|
|
DEF_FN(GenFramebuffers),
|
|
|
|
DEF_FN(DeleteFramebuffers),
|
|
|
|
DEF_FN(CheckFramebufferStatus),
|
|
|
|
DEF_FN(FramebufferTexture2D),
|
|
|
|
{0}
|
|
|
|
},
|
|
|
|
},
|
2014-12-23 14:32:24 +01:00
|
|
|
// VAOs, extension in GL 2.x, core in GL 3.x core.
|
|
|
|
{
|
|
|
|
.ver_core = 300,
|
|
|
|
.ver_es_core = 300,
|
|
|
|
.extension = "GL_ARB_vertex_array_object",
|
|
|
|
.provides = MPGL_CAP_VAO,
|
|
|
|
.functions = (const struct gl_function[]) {
|
|
|
|
DEF_FN(GenVertexArrays),
|
|
|
|
DEF_FN(BindVertexArray),
|
|
|
|
DEF_FN(DeleteVertexArrays),
|
|
|
|
{0}
|
|
|
|
}
|
|
|
|
},
|
2012-10-03 01:54:13 +02:00
|
|
|
// Float textures, extension in GL 2.x, core in GL 3.x core.
|
|
|
|
{
|
2014-12-18 23:51:21 +01:00
|
|
|
.ver_core = 300,
|
|
|
|
.ver_es_core = 300,
|
2012-10-03 01:54:13 +02:00
|
|
|
.extension = "GL_ARB_texture_float",
|
|
|
|
.provides = MPGL_CAP_FLOAT_TEX,
|
|
|
|
},
|
|
|
|
// GL_RED / GL_RG textures, extension in GL 2.x, core in GL 3.x core.
|
|
|
|
{
|
2014-12-18 23:51:21 +01:00
|
|
|
.ver_core = 300,
|
|
|
|
.ver_es_core = 300,
|
2012-10-03 01:54:13 +02:00
|
|
|
.extension = "GL_ARB_texture_rg",
|
|
|
|
.provides = MPGL_CAP_TEX_RG,
|
|
|
|
},
|
|
|
|
// Swap control, always an OS specific extension
|
2015-03-25 12:29:19 +01:00
|
|
|
// The OSX code loads this manually.
|
2012-10-03 01:54:13 +02:00
|
|
|
{
|
2015-03-25 12:29:19 +01:00
|
|
|
.extension = "GLX_SGI_swap_control",
|
2014-06-10 23:56:05 +02:00
|
|
|
.functions = (const struct gl_function[]) {
|
2015-03-25 12:40:45 +01:00
|
|
|
DEF_FN_NAME(SwapInterval, "glXSwapIntervalSGI"),
|
2015-03-25 12:29:19 +01:00
|
|
|
{0},
|
|
|
|
},
|
|
|
|
},
|
|
|
|
{
|
|
|
|
.extension = "WGL_EXT_swap_control",
|
|
|
|
.functions = (const struct gl_function[]) {
|
2015-03-25 12:40:45 +01:00
|
|
|
DEF_FN_NAME(SwapInterval, "wglSwapIntervalEXT"),
|
2015-03-25 12:29:19 +01:00
|
|
|
{0},
|
2012-10-03 01:54:13 +02:00
|
|
|
},
|
|
|
|
},
|
2014-08-15 23:36:10 +02:00
|
|
|
{
|
|
|
|
.extension = "GLX_SGI_video_sync",
|
2014-10-10 13:44:08 +02:00
|
|
|
.functions = (const struct gl_function[]) {
|
2015-03-25 12:40:45 +01:00
|
|
|
DEF_FN_NAME(GetVideoSync, "glXGetVideoSyncSGI"),
|
|
|
|
DEF_FN_NAME(WaitVideoSync, "glXWaitVideoSyncSGI"),
|
2014-08-15 23:36:10 +02:00
|
|
|
{0},
|
|
|
|
},
|
|
|
|
},
|
2013-11-05 22:06:48 +01:00
|
|
|
// For gl_hwdec_vdpau.c
|
|
|
|
// http://www.opengl.org/registry/specs/NV/vdpau_interop.txt
|
|
|
|
{
|
|
|
|
.extension = "GL_NV_vdpau_interop",
|
|
|
|
.provides = MPGL_CAP_VDPAU,
|
2014-06-10 23:56:05 +02:00
|
|
|
.functions = (const struct gl_function[]) {
|
2013-11-05 22:06:48 +01:00
|
|
|
// (only functions needed by us)
|
|
|
|
DEF_FN(VDPAUInitNV),
|
|
|
|
DEF_FN(VDPAUFiniNV),
|
|
|
|
DEF_FN(VDPAURegisterOutputSurfaceNV),
|
|
|
|
DEF_FN(VDPAUUnregisterSurfaceNV),
|
|
|
|
DEF_FN(VDPAUSurfaceAccessNV),
|
|
|
|
DEF_FN(VDPAUMapSurfacesNV),
|
|
|
|
DEF_FN(VDPAUUnmapSurfacesNV),
|
|
|
|
{0}
|
|
|
|
},
|
|
|
|
},
|
2013-11-13 21:52:34 +01:00
|
|
|
// Apple Packed YUV Formats
|
|
|
|
// For gl_hwdec_vda.c
|
|
|
|
// http://www.opengl.org/registry/specs/APPLE/rgb_422.txt
|
|
|
|
{
|
|
|
|
.extension = "GL_APPLE_rgb_422",
|
|
|
|
.provides = MPGL_CAP_APPLE_RGB_422,
|
|
|
|
},
|
2014-12-23 02:46:44 +01:00
|
|
|
{
|
|
|
|
.ver_core = 430,
|
|
|
|
.extension = "GL_ARB_debug_output",
|
|
|
|
.provides = MPGL_CAP_DEBUG,
|
|
|
|
.functions = (const struct gl_function[]) {
|
|
|
|
// (only functions needed by us)
|
|
|
|
DEF_FN(DebugMessageCallback),
|
|
|
|
{0}
|
|
|
|
},
|
|
|
|
},
|
2015-07-03 16:37:01 +02:00
|
|
|
// These don't exist - they are for the sake of mpv internals, and libmpv
|
|
|
|
// interaction (see libmpv/opengl_cb.h).
|
2015-09-24 21:07:16 +02:00
|
|
|
{
|
|
|
|
.extension = "GL_MP_MPGetNativeDisplay",
|
|
|
|
.functions = (const struct gl_function[]) {
|
|
|
|
DEF_FN(MPGetNativeDisplay),
|
|
|
|
{0}
|
|
|
|
},
|
|
|
|
},
|
|
|
|
// Same, but using the old name.
|
2015-07-03 16:37:01 +02:00
|
|
|
{
|
|
|
|
.extension = "GL_MP_D3D_interfaces",
|
|
|
|
.functions = (const struct gl_function[]) {
|
2015-09-24 21:07:16 +02:00
|
|
|
DEF_FN_NAME(MPGetNativeDisplay, "glMPGetD3DInterface"),
|
2015-07-03 16:37:01 +02:00
|
|
|
{0}
|
|
|
|
},
|
|
|
|
},
|
2012-10-03 01:54:13 +02:00
|
|
|
};
|
|
|
|
|
|
|
|
#undef FN_OFFS
|
|
|
|
#undef DEF_FN_HARD
|
|
|
|
#undef DEF_FN
|
2015-03-25 12:40:45 +01:00
|
|
|
#undef DEF_FN_NAME
|
2012-10-03 01:54:13 +02:00
|
|
|
|
|
|
|
|
gl_common: simplify window/context creation
Allow the backend code to create a GL context on best effort basis,
instead of having to implement separate functions for each variation.
This means there's only a single create_window callback now. Also,
getFunctions() doesn't have the gl3 parameter anymore, which was
confusing and hard to explain.
create_window() tries to create a GL context of any version. The field
MPGLContext.requested_gl_version is taken as a hint whether a GL3 or a
legacy context is preferred. (This should be easy on all platforms.)
The cocoa part always assumes that GL 3 is always available on
OSX 10.7.0 and higher, and miserably fails if it's not. One could try
to put more effort into probing the context, but apparently this
situation never happens, so don't bother. (And even if, mpv should be
able to fall back to vo_corevideo.)
The X11 part doesn't change much, but moving these functions around
makes the diff bigger.
Note about some corner cases:
This doesn't handle CONTEXT_FORWARD_COMPATIBLE_BIT_ARB on OpenGL 3.0
correctly. This was the one thing getFunctions() actually needed the
gl3 parameter, and we just make sure we never use forward compatible
contexts on 3.0. It should work with any version above (e.g. 3.1, 3.2
and 3.3 should be fine). This is because the GL_ARB_compatibility
extension is specified for 3.1 and up only. There doesn't seem to be
any way to detect presence of legacy GL on 3.0 with a forward
compatible context. As a counter measure, remove the FORWARD_COMPATIBLE
flags from the win32 code. Maybe this will go wrong. (Should this
happen, the flag has the be added back, and the win32 will have to
explicitly check for GL 3.0 and add "GL_ARB_compatibility" to the extra
extension string.)
Note about GLX:
Probing GL versions by trying to create a context on an existing window
was (probably) not always possible. Old code used GLX 1.2 to create
legacy contexts, and it required code different from GLX 1.3 even before
creation of the X window (the problem was selections of the X Visual).
That's why there were two functions for window creation (create_window_old
and create_window_gl3). However, the legacy context creation code was
updated to GLX 1.3 in commit b3b20cc, so having different functions for
window creation is not needed anymore.
2013-02-24 23:31:57 +01:00
|
|
|
// Fill the GL struct with function pointers and extensions from the current
|
2013-03-01 15:55:08 +01:00
|
|
|
// GL context. Called by the backend.
|
gl_common: simplify window/context creation
Allow the backend code to create a GL context on best effort basis,
instead of having to implement separate functions for each variation.
This means there's only a single create_window callback now. Also,
getFunctions() doesn't have the gl3 parameter anymore, which was
confusing and hard to explain.
create_window() tries to create a GL context of any version. The field
MPGLContext.requested_gl_version is taken as a hint whether a GL3 or a
legacy context is preferred. (This should be easy on all platforms.)
The cocoa part always assumes that GL 3 is always available on
OSX 10.7.0 and higher, and miserably fails if it's not. One could try
to put more effort into probing the context, but apparently this
situation never happens, so don't bother. (And even if, mpv should be
able to fall back to vo_corevideo.)
The X11 part doesn't change much, but moving these functions around
makes the diff bigger.
Note about some corner cases:
This doesn't handle CONTEXT_FORWARD_COMPATIBLE_BIT_ARB on OpenGL 3.0
correctly. This was the one thing getFunctions() actually needed the
gl3 parameter, and we just make sure we never use forward compatible
contexts on 3.0. It should work with any version above (e.g. 3.1, 3.2
and 3.3 should be fine). This is because the GL_ARB_compatibility
extension is specified for 3.1 and up only. There doesn't seem to be
any way to detect presence of legacy GL on 3.0 with a forward
compatible context. As a counter measure, remove the FORWARD_COMPATIBLE
flags from the win32 code. Maybe this will go wrong. (Should this
happen, the flag has the be added back, and the win32 will have to
explicitly check for GL 3.0 and add "GL_ARB_compatibility" to the extra
extension string.)
Note about GLX:
Probing GL versions by trying to create a context on an existing window
was (probably) not always possible. Old code used GLX 1.2 to create
legacy contexts, and it required code different from GLX 1.3 even before
creation of the X window (the problem was selections of the X Visual).
That's why there were two functions for window creation (create_window_old
and create_window_gl3). However, the legacy context creation code was
updated to GLX 1.3 in commit b3b20cc, so having different functions for
window creation is not needed anymore.
2013-02-24 23:31:57 +01:00
|
|
|
// getProcAddress: function to resolve function names, may be NULL
|
|
|
|
// ext2: an extra extension string
|
2013-09-12 00:57:32 +02:00
|
|
|
// log: used to output messages
|
gl_common: simplify window/context creation
Allow the backend code to create a GL context on best effort basis,
instead of having to implement separate functions for each variation.
This means there's only a single create_window callback now. Also,
getFunctions() doesn't have the gl3 parameter anymore, which was
confusing and hard to explain.
create_window() tries to create a GL context of any version. The field
MPGLContext.requested_gl_version is taken as a hint whether a GL3 or a
legacy context is preferred. (This should be easy on all platforms.)
The cocoa part always assumes that GL 3 is always available on
OSX 10.7.0 and higher, and miserably fails if it's not. One could try
to put more effort into probing the context, but apparently this
situation never happens, so don't bother. (And even if, mpv should be
able to fall back to vo_corevideo.)
The X11 part doesn't change much, but moving these functions around
makes the diff bigger.
Note about some corner cases:
This doesn't handle CONTEXT_FORWARD_COMPATIBLE_BIT_ARB on OpenGL 3.0
correctly. This was the one thing getFunctions() actually needed the
gl3 parameter, and we just make sure we never use forward compatible
contexts on 3.0. It should work with any version above (e.g. 3.1, 3.2
and 3.3 should be fine). This is because the GL_ARB_compatibility
extension is specified for 3.1 and up only. There doesn't seem to be
any way to detect presence of legacy GL on 3.0 with a forward
compatible context. As a counter measure, remove the FORWARD_COMPATIBLE
flags from the win32 code. Maybe this will go wrong. (Should this
happen, the flag has the be added back, and the win32 will have to
explicitly check for GL 3.0 and add "GL_ARB_compatibility" to the extra
extension string.)
Note about GLX:
Probing GL versions by trying to create a context on an existing window
was (probably) not always possible. Old code used GLX 1.2 to create
legacy contexts, and it required code different from GLX 1.3 even before
creation of the X window (the problem was selections of the X Visual).
That's why there were two functions for window creation (create_window_old
and create_window_gl3). However, the legacy context creation code was
updated to GLX 1.3 in commit b3b20cc, so having different functions for
window creation is not needed anymore.
2013-02-24 23:31:57 +01:00
|
|
|
// Note: if you create a CONTEXT_FORWARD_COMPATIBLE_BIT_ARB with OpenGL 3.0,
|
|
|
|
// you must append "GL_ARB_compatibility" to ext2.
|
2014-12-09 17:47:02 +01:00
|
|
|
void mpgl_load_functions2(GL *gl, void *(*get_fn)(void *ctx, const char *n),
|
|
|
|
void *fn_ctx, const char *ext2, struct mp_log *log)
|
2011-09-25 11:18:07 +02:00
|
|
|
{
|
2012-10-03 01:54:13 +02:00
|
|
|
talloc_free_children(gl);
|
|
|
|
*gl = (GL) {
|
|
|
|
.extensions = talloc_strdup(gl, ext2 ? ext2 : ""),
|
|
|
|
};
|
2011-09-25 11:18:07 +02:00
|
|
|
|
2014-12-09 17:47:02 +01:00
|
|
|
gl->GetString = get_fn(fn_ctx, "glGetString");
|
2014-05-26 22:56:13 +02:00
|
|
|
if (!gl->GetString) {
|
|
|
|
mp_err(log, "Can't load OpenGL functions.\n");
|
2015-01-21 20:32:42 +01:00
|
|
|
goto error;
|
2014-05-26 22:56:13 +02:00
|
|
|
}
|
gl_common: simplify window/context creation
Allow the backend code to create a GL context on best effort basis,
instead of having to implement separate functions for each variation.
This means there's only a single create_window callback now. Also,
getFunctions() doesn't have the gl3 parameter anymore, which was
confusing and hard to explain.
create_window() tries to create a GL context of any version. The field
MPGLContext.requested_gl_version is taken as a hint whether a GL3 or a
legacy context is preferred. (This should be easy on all platforms.)
The cocoa part always assumes that GL 3 is always available on
OSX 10.7.0 and higher, and miserably fails if it's not. One could try
to put more effort into probing the context, but apparently this
situation never happens, so don't bother. (And even if, mpv should be
able to fall back to vo_corevideo.)
The X11 part doesn't change much, but moving these functions around
makes the diff bigger.
Note about some corner cases:
This doesn't handle CONTEXT_FORWARD_COMPATIBLE_BIT_ARB on OpenGL 3.0
correctly. This was the one thing getFunctions() actually needed the
gl3 parameter, and we just make sure we never use forward compatible
contexts on 3.0. It should work with any version above (e.g. 3.1, 3.2
and 3.3 should be fine). This is because the GL_ARB_compatibility
extension is specified for 3.1 and up only. There doesn't seem to be
any way to detect presence of legacy GL on 3.0 with a forward
compatible context. As a counter measure, remove the FORWARD_COMPATIBLE
flags from the win32 code. Maybe this will go wrong. (Should this
happen, the flag has the be added back, and the win32 will have to
explicitly check for GL 3.0 and add "GL_ARB_compatibility" to the extra
extension string.)
Note about GLX:
Probing GL versions by trying to create a context on an existing window
was (probably) not always possible. Old code used GLX 1.2 to create
legacy contexts, and it required code different from GLX 1.3 even before
creation of the X window (the problem was selections of the X Visual).
That's why there were two functions for window creation (create_window_old
and create_window_gl3). However, the legacy context creation code was
updated to GLX 1.3 in commit b3b20cc, so having different functions for
window creation is not needed anymore.
2013-02-24 23:31:57 +01:00
|
|
|
|
2014-05-26 23:05:22 +02:00
|
|
|
int major = 0, minor = 0;
|
2014-12-18 23:51:21 +01:00
|
|
|
const char *version_string = gl->GetString(GL_VERSION);
|
2015-02-20 18:53:35 +01:00
|
|
|
if (!version_string)
|
|
|
|
goto error;
|
|
|
|
mp_verbose(log, "GL_VERSION='%s'\n", version_string);
|
2014-12-18 23:51:21 +01:00
|
|
|
if (strncmp(version_string, "OpenGL ES ", 10) == 0) {
|
|
|
|
version_string += 10;
|
2014-12-18 21:06:17 +01:00
|
|
|
gl->es = 100;
|
2014-12-17 21:48:23 +01:00
|
|
|
}
|
2015-02-20 18:53:35 +01:00
|
|
|
if (sscanf(version_string, "%d.%d", &major, &minor) < 2)
|
|
|
|
goto error;
|
gl_common: simplify window/context creation
Allow the backend code to create a GL context on best effort basis,
instead of having to implement separate functions for each variation.
This means there's only a single create_window callback now. Also,
getFunctions() doesn't have the gl3 parameter anymore, which was
confusing and hard to explain.
create_window() tries to create a GL context of any version. The field
MPGLContext.requested_gl_version is taken as a hint whether a GL3 or a
legacy context is preferred. (This should be easy on all platforms.)
The cocoa part always assumes that GL 3 is always available on
OSX 10.7.0 and higher, and miserably fails if it's not. One could try
to put more effort into probing the context, but apparently this
situation never happens, so don't bother. (And even if, mpv should be
able to fall back to vo_corevideo.)
The X11 part doesn't change much, but moving these functions around
makes the diff bigger.
Note about some corner cases:
This doesn't handle CONTEXT_FORWARD_COMPATIBLE_BIT_ARB on OpenGL 3.0
correctly. This was the one thing getFunctions() actually needed the
gl3 parameter, and we just make sure we never use forward compatible
contexts on 3.0. It should work with any version above (e.g. 3.1, 3.2
and 3.3 should be fine). This is because the GL_ARB_compatibility
extension is specified for 3.1 and up only. There doesn't seem to be
any way to detect presence of legacy GL on 3.0 with a forward
compatible context. As a counter measure, remove the FORWARD_COMPATIBLE
flags from the win32 code. Maybe this will go wrong. (Should this
happen, the flag has the be added back, and the win32 will have to
explicitly check for GL 3.0 and add "GL_ARB_compatibility" to the extra
extension string.)
Note about GLX:
Probing GL versions by trying to create a context on an existing window
was (probably) not always possible. Old code used GLX 1.2 to create
legacy contexts, and it required code different from GLX 1.3 even before
creation of the X window (the problem was selections of the X Visual).
That's why there were two functions for window creation (create_window_old
and create_window_gl3). However, the legacy context creation code was
updated to GLX 1.3 in commit b3b20cc, so having different functions for
window creation is not needed anymore.
2013-02-24 23:31:57 +01:00
|
|
|
gl->version = MPGL_VER(major, minor);
|
2014-12-18 21:06:17 +01:00
|
|
|
mp_verbose(log, "Detected %s %d.%d.\n", gl->es ? "GLES" : "desktop OpenGL",
|
|
|
|
major, minor);
|
2014-12-17 21:48:23 +01:00
|
|
|
|
2014-12-18 21:06:17 +01:00
|
|
|
if (gl->es) {
|
|
|
|
gl->es = gl->version;
|
2014-12-19 01:03:08 +01:00
|
|
|
gl->version = 0;
|
|
|
|
if (gl->es < 200) {
|
|
|
|
mp_fatal(log, "At least GLESv2 required.\n");
|
2015-01-21 20:32:42 +01:00
|
|
|
goto error;
|
2014-12-18 21:06:17 +01:00
|
|
|
}
|
2014-12-17 21:48:23 +01:00
|
|
|
}
|
gl_common: simplify window/context creation
Allow the backend code to create a GL context on best effort basis,
instead of having to implement separate functions for each variation.
This means there's only a single create_window callback now. Also,
getFunctions() doesn't have the gl3 parameter anymore, which was
confusing and hard to explain.
create_window() tries to create a GL context of any version. The field
MPGLContext.requested_gl_version is taken as a hint whether a GL3 or a
legacy context is preferred. (This should be easy on all platforms.)
The cocoa part always assumes that GL 3 is always available on
OSX 10.7.0 and higher, and miserably fails if it's not. One could try
to put more effort into probing the context, but apparently this
situation never happens, so don't bother. (And even if, mpv should be
able to fall back to vo_corevideo.)
The X11 part doesn't change much, but moving these functions around
makes the diff bigger.
Note about some corner cases:
This doesn't handle CONTEXT_FORWARD_COMPATIBLE_BIT_ARB on OpenGL 3.0
correctly. This was the one thing getFunctions() actually needed the
gl3 parameter, and we just make sure we never use forward compatible
contexts on 3.0. It should work with any version above (e.g. 3.1, 3.2
and 3.3 should be fine). This is because the GL_ARB_compatibility
extension is specified for 3.1 and up only. There doesn't seem to be
any way to detect presence of legacy GL on 3.0 with a forward
compatible context. As a counter measure, remove the FORWARD_COMPATIBLE
flags from the win32 code. Maybe this will go wrong. (Should this
happen, the flag has the be added back, and the win32 will have to
explicitly check for GL 3.0 and add "GL_ARB_compatibility" to the extra
extension string.)
Note about GLX:
Probing GL versions by trying to create a context on an existing window
was (probably) not always possible. Old code used GLX 1.2 to create
legacy contexts, and it required code different from GLX 1.3 even before
creation of the X window (the problem was selections of the X Visual).
That's why there were two functions for window creation (create_window_old
and create_window_gl3). However, the legacy context creation code was
updated to GLX 1.3 in commit b3b20cc, so having different functions for
window creation is not needed anymore.
2013-02-24 23:31:57 +01:00
|
|
|
|
2014-05-26 23:08:07 +02:00
|
|
|
mp_verbose(log, "GL_VENDOR='%s'\n", gl->GetString(GL_VENDOR));
|
|
|
|
mp_verbose(log, "GL_RENDERER='%s'\n", gl->GetString(GL_RENDERER));
|
2014-08-28 01:32:22 +02:00
|
|
|
const char *shader = gl->GetString(GL_SHADING_LANGUAGE_VERSION);
|
|
|
|
if (shader)
|
|
|
|
mp_verbose(log, "GL_SHADING_LANGUAGE_VERSION='%s'\n", shader);
|
2013-03-01 21:19:20 +01:00
|
|
|
|
2014-12-19 01:03:08 +01:00
|
|
|
if (gl->version >= 300) {
|
2014-12-09 17:47:02 +01:00
|
|
|
gl->GetStringi = get_fn(fn_ctx, "glGetStringi");
|
|
|
|
gl->GetIntegerv = get_fn(fn_ctx, "glGetIntegerv");
|
2012-03-31 00:33:53 +02:00
|
|
|
|
|
|
|
if (!(gl->GetStringi && gl->GetIntegerv))
|
2015-01-21 20:32:42 +01:00
|
|
|
goto error;
|
2012-03-31 00:33:53 +02:00
|
|
|
|
|
|
|
GLint exts;
|
|
|
|
gl->GetIntegerv(GL_NUM_EXTENSIONS, &exts);
|
|
|
|
for (int n = 0; n < exts; n++) {
|
gl_common: simplify window/context creation
Allow the backend code to create a GL context on best effort basis,
instead of having to implement separate functions for each variation.
This means there's only a single create_window callback now. Also,
getFunctions() doesn't have the gl3 parameter anymore, which was
confusing and hard to explain.
create_window() tries to create a GL context of any version. The field
MPGLContext.requested_gl_version is taken as a hint whether a GL3 or a
legacy context is preferred. (This should be easy on all platforms.)
The cocoa part always assumes that GL 3 is always available on
OSX 10.7.0 and higher, and miserably fails if it's not. One could try
to put more effort into probing the context, but apparently this
situation never happens, so don't bother. (And even if, mpv should be
able to fall back to vo_corevideo.)
The X11 part doesn't change much, but moving these functions around
makes the diff bigger.
Note about some corner cases:
This doesn't handle CONTEXT_FORWARD_COMPATIBLE_BIT_ARB on OpenGL 3.0
correctly. This was the one thing getFunctions() actually needed the
gl3 parameter, and we just make sure we never use forward compatible
contexts on 3.0. It should work with any version above (e.g. 3.1, 3.2
and 3.3 should be fine). This is because the GL_ARB_compatibility
extension is specified for 3.1 and up only. There doesn't seem to be
any way to detect presence of legacy GL on 3.0 with a forward
compatible context. As a counter measure, remove the FORWARD_COMPATIBLE
flags from the win32 code. Maybe this will go wrong. (Should this
happen, the flag has the be added back, and the win32 will have to
explicitly check for GL 3.0 and add "GL_ARB_compatibility" to the extra
extension string.)
Note about GLX:
Probing GL versions by trying to create a context on an existing window
was (probably) not always possible. Old code used GLX 1.2 to create
legacy contexts, and it required code different from GLX 1.3 even before
creation of the X window (the problem was selections of the X Visual).
That's why there were two functions for window creation (create_window_old
and create_window_gl3). However, the legacy context creation code was
updated to GLX 1.3 in commit b3b20cc, so having different functions for
window creation is not needed anymore.
2013-02-24 23:31:57 +01:00
|
|
|
const char *ext = gl->GetStringi(GL_EXTENSIONS, n);
|
|
|
|
gl->extensions = talloc_asprintf_append(gl->extensions, " %s", ext);
|
2012-03-31 00:33:53 +02:00
|
|
|
}
|
2012-10-03 01:54:13 +02:00
|
|
|
|
gl_common: simplify window/context creation
Allow the backend code to create a GL context on best effort basis,
instead of having to implement separate functions for each variation.
This means there's only a single create_window callback now. Also,
getFunctions() doesn't have the gl3 parameter anymore, which was
confusing and hard to explain.
create_window() tries to create a GL context of any version. The field
MPGLContext.requested_gl_version is taken as a hint whether a GL3 or a
legacy context is preferred. (This should be easy on all platforms.)
The cocoa part always assumes that GL 3 is always available on
OSX 10.7.0 and higher, and miserably fails if it's not. One could try
to put more effort into probing the context, but apparently this
situation never happens, so don't bother. (And even if, mpv should be
able to fall back to vo_corevideo.)
The X11 part doesn't change much, but moving these functions around
makes the diff bigger.
Note about some corner cases:
This doesn't handle CONTEXT_FORWARD_COMPATIBLE_BIT_ARB on OpenGL 3.0
correctly. This was the one thing getFunctions() actually needed the
gl3 parameter, and we just make sure we never use forward compatible
contexts on 3.0. It should work with any version above (e.g. 3.1, 3.2
and 3.3 should be fine). This is because the GL_ARB_compatibility
extension is specified for 3.1 and up only. There doesn't seem to be
any way to detect presence of legacy GL on 3.0 with a forward
compatible context. As a counter measure, remove the FORWARD_COMPATIBLE
flags from the win32 code. Maybe this will go wrong. (Should this
happen, the flag has the be added back, and the win32 will have to
explicitly check for GL 3.0 and add "GL_ARB_compatibility" to the extra
extension string.)
Note about GLX:
Probing GL versions by trying to create a context on an existing window
was (probably) not always possible. Old code used GLX 1.2 to create
legacy contexts, and it required code different from GLX 1.3 even before
creation of the X window (the problem was selections of the X Visual).
That's why there were two functions for window creation (create_window_old
and create_window_gl3). However, the legacy context creation code was
updated to GLX 1.3 in commit b3b20cc, so having different functions for
window creation is not needed anymore.
2013-02-24 23:31:57 +01:00
|
|
|
} else {
|
2012-03-31 00:33:53 +02:00
|
|
|
const char *ext = (char*)gl->GetString(GL_EXTENSIONS);
|
2012-10-03 01:54:13 +02:00
|
|
|
gl->extensions = talloc_asprintf_append(gl->extensions, " %s", ext);
|
2012-03-31 00:33:53 +02:00
|
|
|
}
|
2012-10-03 01:54:13 +02:00
|
|
|
|
2014-05-26 23:08:07 +02:00
|
|
|
mp_dbg(log, "Combined OpenGL extensions string:\n%s\n", gl->extensions);
|
2012-10-03 01:54:13 +02:00
|
|
|
|
2015-08-01 21:11:38 +02:00
|
|
|
for (int n = 0; n < MP_ARRAY_SIZE(gl_functions); n++) {
|
2014-06-10 23:56:05 +02:00
|
|
|
const struct gl_functions *section = &gl_functions[n];
|
2014-12-18 23:51:21 +01:00
|
|
|
int version = gl->es ? gl->es : gl->version;
|
|
|
|
int ver_core = gl->es ? section->ver_es_core : section->ver_core;
|
|
|
|
int ver_removed = gl->es ? section->ver_es_removed : section->ver_removed;
|
2012-10-03 01:54:13 +02:00
|
|
|
|
2015-07-24 23:34:43 +02:00
|
|
|
if (ver_removed && version >= ver_removed)
|
2012-10-03 01:54:13 +02:00
|
|
|
continue;
|
|
|
|
|
2012-12-27 17:08:17 +01:00
|
|
|
// NOTE: Function entrypoints can exist, even if they do not work.
|
|
|
|
// We must always check extension strings and versions.
|
2012-03-31 00:33:53 +02:00
|
|
|
|
2014-12-19 18:54:21 +01:00
|
|
|
bool exists = false, must_exist = false;
|
2014-12-18 23:51:21 +01:00
|
|
|
if (ver_core)
|
2014-12-19 18:54:21 +01:00
|
|
|
must_exist = version >= ver_core;
|
2012-12-27 17:08:17 +01:00
|
|
|
|
2015-03-25 12:36:31 +01:00
|
|
|
if (section->extension && check_ext(gl, section->extension))
|
2012-12-27 17:08:17 +01:00
|
|
|
exists = true;
|
|
|
|
|
2014-12-19 18:54:21 +01:00
|
|
|
exists |= must_exist;
|
2012-12-27 17:08:17 +01:00
|
|
|
if (!exists)
|
2012-10-03 01:54:13 +02:00
|
|
|
continue;
|
|
|
|
|
|
|
|
void *loaded[MAX_FN_COUNT] = {0};
|
|
|
|
bool all_loaded = true;
|
2014-12-18 15:29:47 +01:00
|
|
|
const struct gl_function *fnlist = section->functions;
|
2012-10-03 01:54:13 +02:00
|
|
|
|
2015-03-25 12:40:45 +01:00
|
|
|
for (int i = 0; fnlist && fnlist[i].name; i++) {
|
2014-12-18 15:29:47 +01:00
|
|
|
const struct gl_function *fn = &fnlist[i];
|
2015-03-25 12:40:45 +01:00
|
|
|
void *ptr = get_fn(fn_ctx, fn->name);
|
2012-10-03 01:54:13 +02:00
|
|
|
if (!ptr) {
|
|
|
|
all_loaded = false;
|
2015-01-21 20:32:42 +01:00
|
|
|
mp_warn(log, "Required function '%s' not "
|
2015-03-25 12:40:45 +01:00
|
|
|
"found for %s OpenGL %d.%d.\n", fn->name,
|
2015-01-21 20:32:42 +01:00
|
|
|
section->extension ? section->extension : "builtin",
|
|
|
|
MPGL_VER_GET_MAJOR(ver_core),
|
|
|
|
MPGL_VER_GET_MINOR(ver_core));
|
2015-08-01 21:11:38 +02:00
|
|
|
if (must_exist)
|
2015-01-21 20:32:42 +01:00
|
|
|
goto error;
|
|
|
|
break;
|
2012-10-03 01:54:13 +02:00
|
|
|
}
|
|
|
|
assert(i < MAX_FN_COUNT);
|
|
|
|
loaded[i] = ptr;
|
|
|
|
}
|
|
|
|
|
2015-01-21 20:32:42 +01:00
|
|
|
if (all_loaded) {
|
2012-10-03 01:54:13 +02:00
|
|
|
gl->mpgl_caps |= section->provides;
|
2015-03-25 12:40:45 +01:00
|
|
|
for (int i = 0; fnlist && fnlist[i].name; i++) {
|
2014-12-18 15:29:47 +01:00
|
|
|
const struct gl_function *fn = &fnlist[i];
|
2012-10-03 01:54:13 +02:00
|
|
|
void **funcptr = (void**)(((char*)gl) + fn->offset);
|
|
|
|
if (loaded[i])
|
|
|
|
*funcptr = loaded[i];
|
|
|
|
}
|
2015-07-03 15:12:42 +02:00
|
|
|
mp_verbose(log, "Loaded functions for %d/%s.\n", ver_core,
|
|
|
|
section->extension ? section->extension : "builtin");
|
2011-09-25 11:18:07 +02:00
|
|
|
}
|
2012-10-03 01:54:13 +02:00
|
|
|
}
|
|
|
|
|
|
|
|
gl->glsl_version = 0;
|
2014-12-17 21:48:23 +01:00
|
|
|
if (gl->es) {
|
2014-12-19 01:03:08 +01:00
|
|
|
if (gl->es >= 200)
|
|
|
|
gl->glsl_version = 100;
|
2014-12-18 23:51:21 +01:00
|
|
|
if (gl->es >= 300)
|
2014-12-17 21:48:23 +01:00
|
|
|
gl->glsl_version = 300;
|
|
|
|
} else {
|
2014-12-18 23:51:21 +01:00
|
|
|
if (gl->version >= 200)
|
2014-12-17 21:48:23 +01:00
|
|
|
gl->glsl_version = 110;
|
2014-12-18 23:51:21 +01:00
|
|
|
if (gl->version >= 210)
|
2014-12-17 21:48:23 +01:00
|
|
|
gl->glsl_version = 120;
|
2014-12-18 23:51:21 +01:00
|
|
|
if (gl->version >= 300)
|
2014-12-17 21:48:23 +01:00
|
|
|
gl->glsl_version = 130;
|
|
|
|
// Specifically needed for OSX (normally we request 3.0 contexts only, but
|
|
|
|
// OSX always creates 3.2 contexts when requesting a core context).
|
2014-12-18 23:51:21 +01:00
|
|
|
if (gl->version >= 320)
|
2014-12-17 21:48:23 +01:00
|
|
|
gl->glsl_version = 150;
|
|
|
|
}
|
2012-10-03 01:54:13 +02:00
|
|
|
|
2015-07-11 18:40:37 +02:00
|
|
|
if (is_software_gl(gl)) {
|
2014-12-19 18:37:16 +01:00
|
|
|
gl->mpgl_caps |= MPGL_CAP_SW;
|
2015-07-11 18:40:37 +02:00
|
|
|
mp_verbose(log, "Detected suspected software renderer.\n");
|
2014-12-19 18:37:16 +01:00
|
|
|
}
|
2014-12-09 22:28:16 +01:00
|
|
|
|
|
|
|
// Provided for simpler handling if no framebuffer support is available.
|
|
|
|
if (!gl->BindFramebuffer)
|
|
|
|
gl->BindFramebuffer = &dummy_glBindFramebuffer;
|
2015-01-21 20:32:42 +01:00
|
|
|
return;
|
|
|
|
|
|
|
|
error:
|
|
|
|
gl->version = 0;
|
|
|
|
gl->es = 0;
|
|
|
|
gl->mpgl_caps = 0;
|
2005-07-26 12:16:18 +02:00
|
|
|
}
|
|
|
|
|
2014-12-09 17:47:02 +01:00
|
|
|
static void *get_procaddr_wrapper(void *ctx, const char *name)
|
|
|
|
{
|
|
|
|
void *(*getProcAddress)(const GLubyte *) = ctx;
|
|
|
|
return getProcAddress ? getProcAddress((const GLubyte*)name) : NULL;
|
|
|
|
}
|
|
|
|
|
|
|
|
void mpgl_load_functions(GL *gl, void *(*getProcAddress)(const GLubyte *),
|
|
|
|
const char *ext2, struct mp_log *log)
|
|
|
|
{
|
|
|
|
mpgl_load_functions2(gl, get_procaddr_wrapper, getProcAddress, ext2, log);
|
|
|
|
}
|
|
|
|
|
2013-03-01 15:55:08 +01:00
|
|
|
typedef void (*MPGLSetBackendFn)(MPGLContext *ctx);
|
2012-10-03 01:54:13 +02:00
|
|
|
|
2013-03-01 15:55:08 +01:00
|
|
|
struct backend {
|
|
|
|
const char *name;
|
|
|
|
MPGLSetBackendFn init;
|
2015-05-13 23:55:07 +02:00
|
|
|
const struct mpgl_driver *driver;
|
2013-03-01 15:55:08 +01:00
|
|
|
};
|
2011-10-15 18:44:00 +02:00
|
|
|
|
2015-05-13 23:55:22 +02:00
|
|
|
extern const struct mpgl_driver mpgl_driver_x11;
|
2015-07-02 00:25:30 +02:00
|
|
|
extern const struct mpgl_driver mpgl_driver_x11egl;
|
2015-10-01 22:25:12 +02:00
|
|
|
extern const struct mpgl_driver mpgl_driver_cocoa;
|
2015-05-13 23:55:22 +02:00
|
|
|
|
2014-06-10 23:56:05 +02:00
|
|
|
static const struct backend backends[] = {
|
2015-08-18 22:35:33 +02:00
|
|
|
#if HAVE_RPI
|
2015-03-29 15:12:11 +02:00
|
|
|
{"rpi", mpgl_set_backend_rpi},
|
|
|
|
#endif
|
2013-07-16 13:28:28 +02:00
|
|
|
#if HAVE_GL_COCOA
|
2015-10-01 22:25:12 +02:00
|
|
|
{.driver = &mpgl_driver_cocoa},
|
2011-10-15 18:44:00 +02:00
|
|
|
#endif
|
2013-07-16 13:28:28 +02:00
|
|
|
#if HAVE_GL_WIN32
|
2013-03-01 15:55:08 +01:00
|
|
|
{"win", mpgl_set_backend_w32},
|
2009-12-08 07:42:46 +01:00
|
|
|
#endif
|
2013-09-14 16:30:03 +02:00
|
|
|
|
|
|
|
//Add the wayland backend before x11, in order to probe for a wayland-server before a x11-server and avoid using xwayland
|
2013-07-16 13:28:28 +02:00
|
|
|
#if HAVE_GL_WAYLAND
|
2013-03-01 15:55:08 +01:00
|
|
|
{"wayland", mpgl_set_backend_wayland},
|
2013-09-14 16:30:03 +02:00
|
|
|
#endif
|
2014-11-04 00:12:04 +01:00
|
|
|
#if HAVE_EGL_X11
|
2015-07-02 00:25:30 +02:00
|
|
|
{.driver = &mpgl_driver_x11egl},
|
2013-02-28 19:55:02 +01:00
|
|
|
#endif
|
2015-09-26 20:28:36 +02:00
|
|
|
#if HAVE_GL_X11
|
|
|
|
{.driver = &mpgl_driver_x11},
|
|
|
|
#endif
|
2011-12-18 20:02:31 +01:00
|
|
|
};
|
|
|
|
|
|
|
|
int mpgl_find_backend(const char *name)
|
|
|
|
{
|
2013-03-01 15:55:08 +01:00
|
|
|
if (name == NULL || strcmp(name, "auto") == 0)
|
|
|
|
return -1;
|
2015-05-13 23:55:07 +02:00
|
|
|
for (int n = 0; n < MP_ARRAY_SIZE(backends); n++) {
|
|
|
|
const struct backend *entry = &backends[n];
|
|
|
|
const char *ename = entry->driver ? entry->driver->name : entry->name;
|
|
|
|
if (strcmp(ename, name) == 0)
|
2013-03-01 15:55:08 +01:00
|
|
|
return entry - backends;
|
2011-12-18 20:02:31 +01:00
|
|
|
}
|
2013-03-01 15:55:08 +01:00
|
|
|
return -2;
|
2011-12-18 20:02:31 +01:00
|
|
|
}
|
|
|
|
|
2013-12-21 20:03:36 +01:00
|
|
|
int mpgl_validate_backend_opt(struct mp_log *log, const struct m_option *opt,
|
|
|
|
struct bstr name, struct bstr param)
|
2013-07-22 01:21:39 +02:00
|
|
|
{
|
2013-07-22 02:14:15 +02:00
|
|
|
if (bstr_equals0(param, "help")) {
|
2013-12-21 20:03:36 +01:00
|
|
|
mp_info(log, "OpenGL windowing backends:\n");
|
|
|
|
mp_info(log, " auto (autodetect)\n");
|
2015-05-13 23:55:07 +02:00
|
|
|
for (int n = 0; n < MP_ARRAY_SIZE(backends); n++) {
|
|
|
|
const struct backend *entry = &backends[n];
|
|
|
|
const char *ename = entry->driver ? entry->driver->name : entry->name;
|
|
|
|
mp_info(log, " %s\n", ename);
|
|
|
|
}
|
2013-07-22 02:14:15 +02:00
|
|
|
return M_OPT_EXIT - 1;
|
|
|
|
}
|
2013-07-22 01:21:39 +02:00
|
|
|
char s[20];
|
|
|
|
snprintf(s, sizeof(s), "%.*s", BSTR_P(param));
|
|
|
|
return mpgl_find_backend(s) >= -1 ? 1 : M_OPT_INVALID;
|
|
|
|
}
|
|
|
|
|
2015-09-27 21:20:46 +02:00
|
|
|
#if HAVE_C11_TLS
|
|
|
|
static _Thread_local MPGLContext *current_context;
|
|
|
|
|
|
|
|
static void * GLAPIENTRY get_native_display(const char *name)
|
|
|
|
{
|
|
|
|
if (current_context && current_context->native_display_type &&
|
|
|
|
name && strcmp(current_context->native_display_type, name) == 0)
|
|
|
|
return current_context->native_display;
|
|
|
|
return NULL;
|
|
|
|
}
|
|
|
|
|
|
|
|
static void set_current_context(MPGLContext *context)
|
|
|
|
{
|
|
|
|
current_context = context;
|
|
|
|
if (context && !context->gl->MPGetNativeDisplay)
|
|
|
|
context->gl->MPGetNativeDisplay = get_native_display;
|
|
|
|
}
|
|
|
|
#else
|
|
|
|
static void set_current_context(MPGLContext *context)
|
|
|
|
{
|
|
|
|
}
|
|
|
|
#endif
|
|
|
|
|
2015-05-13 23:55:07 +02:00
|
|
|
static MPGLContext *init_backend(struct vo *vo, const struct backend *backend,
|
2015-05-13 19:43:56 +02:00
|
|
|
bool probing, int vo_flags)
|
2011-09-25 11:18:07 +02:00
|
|
|
{
|
2013-03-01 15:55:08 +01:00
|
|
|
MPGLContext *ctx = talloc_ptrtype(NULL, ctx);
|
2012-10-03 01:54:13 +02:00
|
|
|
*ctx = (MPGLContext) {
|
|
|
|
.gl = talloc_zero(ctx, GL),
|
|
|
|
.vo = vo,
|
2015-05-13 23:55:07 +02:00
|
|
|
.driver = backend->driver,
|
2012-10-03 01:54:13 +02:00
|
|
|
};
|
2014-12-19 18:37:16 +01:00
|
|
|
bool old_probing = vo->probing;
|
|
|
|
vo->probing = probing; // hack; kill it once backends are separate
|
2015-05-13 23:55:07 +02:00
|
|
|
if (ctx->driver) {
|
2015-05-30 21:25:28 +02:00
|
|
|
MP_VERBOSE(vo, "Initializing OpenGL backend '%s'\n", ctx->driver->name);
|
2015-05-13 23:55:07 +02:00
|
|
|
ctx->priv = talloc_zero_size(ctx, ctx->driver->priv_size);
|
|
|
|
if (ctx->driver->init(ctx, vo_flags) < 0) {
|
|
|
|
talloc_free(ctx);
|
|
|
|
return NULL;
|
|
|
|
}
|
|
|
|
} else {
|
2015-05-30 21:25:28 +02:00
|
|
|
MP_VERBOSE(vo, "Initializing OpenGL backend '%s'\n", backend->name);
|
2015-05-13 23:55:07 +02:00
|
|
|
backend->init(ctx);
|
|
|
|
if (!ctx->vo_init(vo)) {
|
|
|
|
talloc_free(ctx);
|
|
|
|
return NULL;
|
|
|
|
}
|
2013-03-01 15:55:08 +01:00
|
|
|
}
|
2014-12-19 18:37:16 +01:00
|
|
|
vo->probing = old_probing;
|
|
|
|
|
2015-05-13 23:55:07 +02:00
|
|
|
if (!ctx->driver && !ctx->config_window(ctx, vo_flags | VOFLAG_HIDDEN))
|
2014-12-19 18:37:16 +01:00
|
|
|
goto cleanup;
|
|
|
|
|
2015-01-21 20:32:42 +01:00
|
|
|
if (!ctx->gl->version && !ctx->gl->es)
|
2014-12-19 18:37:16 +01:00
|
|
|
goto cleanup;
|
2014-11-26 20:48:11 +01:00
|
|
|
|
2014-12-19 20:32:50 +01:00
|
|
|
if (ctx->gl->es && vo->probing) {
|
|
|
|
MP_INFO(ctx->vo, "Skipping experimental GLES support (use --vo=opengl).\n");
|
|
|
|
goto cleanup;
|
|
|
|
}
|
|
|
|
|
2014-12-19 18:37:16 +01:00
|
|
|
if (ctx->gl->mpgl_caps & MPGL_CAP_SW) {
|
|
|
|
MP_WARN(ctx->vo, "Suspected software renderer or indirect context.\n");
|
2015-10-01 20:57:29 +02:00
|
|
|
if (vo->probing && !(vo_flags & VOFLAG_SW))
|
2014-12-19 18:37:16 +01:00
|
|
|
goto cleanup;
|
2012-03-31 00:33:53 +02:00
|
|
|
}
|
2012-10-03 01:54:13 +02:00
|
|
|
|
2014-12-23 02:46:44 +01:00
|
|
|
ctx->gl->debug_context = !!(vo_flags & VOFLAG_GL_DEBUG);
|
|
|
|
|
2015-09-27 21:20:46 +02:00
|
|
|
set_current_context(ctx);
|
|
|
|
|
2014-12-19 18:37:16 +01:00
|
|
|
return ctx;
|
|
|
|
|
|
|
|
cleanup:
|
2014-11-26 20:48:11 +01:00
|
|
|
mpgl_uninit(ctx);
|
|
|
|
return NULL;
|
|
|
|
}
|
|
|
|
|
2015-05-13 19:43:56 +02:00
|
|
|
// Create a VO window and create a GL context on it.
|
|
|
|
// vo_flags: passed to the backend's create window function
|
|
|
|
MPGLContext *mpgl_init(struct vo *vo, const char *backend_name, int vo_flags)
|
|
|
|
{
|
|
|
|
MPGLContext *ctx = NULL;
|
|
|
|
int index = mpgl_find_backend(backend_name);
|
|
|
|
if (index == -1) {
|
2015-05-13 23:55:07 +02:00
|
|
|
for (int n = 0; n < MP_ARRAY_SIZE(backends); n++) {
|
|
|
|
ctx = init_backend(vo, &backends[n], true, vo_flags);
|
2015-05-13 19:43:56 +02:00
|
|
|
if (ctx)
|
|
|
|
break;
|
|
|
|
}
|
|
|
|
} else if (index >= 0) {
|
2015-05-13 23:55:07 +02:00
|
|
|
ctx = init_backend(vo, &backends[index], false, vo_flags);
|
2015-05-13 19:43:56 +02:00
|
|
|
}
|
|
|
|
return ctx;
|
|
|
|
}
|
|
|
|
|
2015-01-28 19:40:52 +01:00
|
|
|
// flags: passed to the backend function
|
|
|
|
bool mpgl_reconfig_window(struct MPGLContext *ctx, int vo_flags)
|
2014-11-26 20:48:11 +01:00
|
|
|
{
|
2015-05-13 23:55:07 +02:00
|
|
|
if (ctx->driver) {
|
|
|
|
return ctx->driver->reconfig(ctx, vo_flags) >= 0;
|
|
|
|
} else {
|
|
|
|
return ctx->config_window(ctx, vo_flags);
|
|
|
|
}
|
|
|
|
}
|
|
|
|
|
|
|
|
int mpgl_control(struct MPGLContext *ctx, int *events, int request, void *arg)
|
|
|
|
{
|
|
|
|
if (ctx->driver) {
|
|
|
|
return ctx->driver->control(ctx, events, request, arg);
|
|
|
|
} else {
|
|
|
|
return ctx->vo_control(ctx->vo, events, request, arg);
|
|
|
|
}
|
|
|
|
}
|
|
|
|
|
|
|
|
void mpgl_swap_buffers(struct MPGLContext *ctx)
|
|
|
|
{
|
|
|
|
if (ctx->driver) {
|
|
|
|
ctx->driver->swap_buffers(ctx);
|
|
|
|
} else {
|
|
|
|
ctx->swapGlBuffers(ctx);
|
|
|
|
}
|
2012-10-03 01:54:13 +02:00
|
|
|
}
|
|
|
|
|
|
|
|
void mpgl_uninit(MPGLContext *ctx)
|
2011-09-25 11:18:07 +02:00
|
|
|
{
|
2015-09-27 21:20:46 +02:00
|
|
|
set_current_context(NULL);
|
2013-03-02 17:08:05 +01:00
|
|
|
if (ctx) {
|
2015-05-13 23:55:07 +02:00
|
|
|
if (ctx->driver) {
|
|
|
|
ctx->driver->uninit(ctx);
|
|
|
|
} else {
|
|
|
|
ctx->releaseGlContext(ctx);
|
|
|
|
ctx->vo_uninit(ctx->vo);
|
|
|
|
}
|
2012-10-03 01:54:13 +02:00
|
|
|
}
|
2011-09-25 11:18:07 +02:00
|
|
|
talloc_free(ctx);
|
2009-12-08 07:42:46 +01:00
|
|
|
}
|