opengl: expose npot support in gl_api
[vlc.git] / modules / video_output / opengl / gl_api.c
blob6bead1cb6bb1bcc1d933c467f61b82eeda1c5c50
1 /*****************************************************************************
2 * gl_api.h
3 *****************************************************************************
4 * Copyright (C) 2020 VLC authors and VideoLAN
5 * Copyright (C) 2020 Videolabs
7 * This program is free software; you can redistribute it and/or modify it
8 * under the terms of the GNU Lesser General Public License as published by
9 * the Free Software Foundation; either version 2.1 of the License, or
10 * (at your option) any later version.
12 * This program is distributed in the hope that it will be useful,
13 * but WITHOUT ANY WARRANTY; without even the implied warranty of
14 * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
15 * GNU Lesser General Public License for more details.
17 * You should have received a copy of the GNU Lesser General Public License
18 * along with this program; if not, write to the Free Software Foundation,
19 * Inc., 51 Franklin Street, Fifth Floor, Boston MA 02110-1301, USA.
20 *****************************************************************************/
22 #ifdef HAVE_CONFIG_H
23 # include "config.h"
24 #endif
26 #include "gl_api.h"
28 #include <assert.h>
29 #include <vlc_common.h>
30 #include <vlc_opengl.h>
32 #include "gl_common.h"
34 int
35 vlc_gl_api_Init(struct vlc_gl_api *api, vlc_gl_t *gl)
37 #if defined(USE_OPENGL_ES2) || defined(HAVE_GL_CORE_SYMBOLS)
38 #define GET_PROC_ADDR_CORE(name) api->vt.name = gl##name
39 #else
40 #define GET_PROC_ADDR_CORE(name) GET_PROC_ADDR_EXT(name, true)
41 #endif
42 #define GET_PROC_ADDR_EXT(name, critical) do { \
43 api->vt.name = vlc_gl_GetProcAddress(gl, "gl"#name); \
44 if (api->vt.name == NULL && critical) { \
45 msg_Err(gl, "gl"#name" symbol not found, bailing out"); \
46 return VLC_EGENERIC; \
47 } \
48 } while(0)
49 #if defined(USE_OPENGL_ES2)
50 #define GET_PROC_ADDR(name) GET_PROC_ADDR_CORE(name)
51 #define GET_PROC_ADDR_CORE_GL(name) GET_PROC_ADDR_EXT(name, false) /* optional for GLES */
52 #else
53 #define GET_PROC_ADDR(name) GET_PROC_ADDR_EXT(name, true)
54 #define GET_PROC_ADDR_CORE_GL(name) GET_PROC_ADDR_CORE(name)
55 #endif
56 #define GET_PROC_ADDR_OPTIONAL(name) GET_PROC_ADDR_EXT(name, false) /* GL 3 or more */
58 GET_PROC_ADDR_CORE(BindTexture);
59 GET_PROC_ADDR_CORE(BlendFunc);
60 GET_PROC_ADDR_CORE(Clear);
61 GET_PROC_ADDR_CORE(ClearColor);
62 GET_PROC_ADDR_CORE(DeleteTextures);
63 GET_PROC_ADDR_CORE(DepthMask);
64 GET_PROC_ADDR_CORE(Disable);
65 GET_PROC_ADDR_CORE(DrawArrays);
66 GET_PROC_ADDR_CORE(DrawElements);
67 GET_PROC_ADDR_CORE(Enable);
68 GET_PROC_ADDR_CORE(Finish);
69 GET_PROC_ADDR_CORE(Flush);
70 GET_PROC_ADDR_CORE(GenTextures);
71 GET_PROC_ADDR_CORE(GetError);
72 GET_PROC_ADDR_CORE(GetIntegerv);
73 GET_PROC_ADDR_CORE(GetString);
74 GET_PROC_ADDR_CORE(PixelStorei);
75 GET_PROC_ADDR_CORE(TexImage2D);
76 GET_PROC_ADDR_CORE(TexParameterf);
77 GET_PROC_ADDR_CORE(TexParameteri);
78 GET_PROC_ADDR_CORE(TexSubImage2D);
79 GET_PROC_ADDR_CORE(Viewport);
81 GET_PROC_ADDR_CORE_GL(GetTexLevelParameteriv);
82 GET_PROC_ADDR_CORE_GL(TexEnvf);
84 GET_PROC_ADDR(CreateShader);
85 GET_PROC_ADDR(ShaderSource);
86 GET_PROC_ADDR(CompileShader);
87 GET_PROC_ADDR(AttachShader);
88 GET_PROC_ADDR(DeleteShader);
90 GET_PROC_ADDR(GetProgramiv);
91 GET_PROC_ADDR(GetShaderiv);
92 GET_PROC_ADDR(GetProgramInfoLog);
93 GET_PROC_ADDR(GetShaderInfoLog);
95 GET_PROC_ADDR(GetUniformLocation);
96 GET_PROC_ADDR(GetAttribLocation);
97 GET_PROC_ADDR(VertexAttribPointer);
98 GET_PROC_ADDR(EnableVertexAttribArray);
99 GET_PROC_ADDR(UniformMatrix4fv);
100 GET_PROC_ADDR(UniformMatrix3fv);
101 GET_PROC_ADDR(UniformMatrix2fv);
102 GET_PROC_ADDR(Uniform4fv);
103 GET_PROC_ADDR(Uniform4f);
104 GET_PROC_ADDR(Uniform3f);
105 GET_PROC_ADDR(Uniform2f);
106 GET_PROC_ADDR(Uniform1f);
107 GET_PROC_ADDR(Uniform1i);
109 GET_PROC_ADDR(CreateProgram);
110 GET_PROC_ADDR(LinkProgram);
111 GET_PROC_ADDR(UseProgram);
112 GET_PROC_ADDR(DeleteProgram);
114 GET_PROC_ADDR(ActiveTexture);
116 GET_PROC_ADDR(GenBuffers);
117 GET_PROC_ADDR(BindBuffer);
118 GET_PROC_ADDR(BufferData);
119 GET_PROC_ADDR(DeleteBuffers);
121 GET_PROC_ADDR_OPTIONAL(GetFramebufferAttachmentParameteriv);
123 GET_PROC_ADDR_OPTIONAL(BufferSubData);
124 GET_PROC_ADDR_OPTIONAL(BufferStorage);
125 GET_PROC_ADDR_OPTIONAL(MapBufferRange);
126 GET_PROC_ADDR_OPTIONAL(FlushMappedBufferRange);
127 GET_PROC_ADDR_OPTIONAL(UnmapBuffer);
128 GET_PROC_ADDR_OPTIONAL(FenceSync);
129 GET_PROC_ADDR_OPTIONAL(DeleteSync);
130 GET_PROC_ADDR_OPTIONAL(ClientWaitSync);
131 #undef GET_PROC_ADDR
133 GL_ASSERT_NOERROR(&api->vt);
135 api->extensions = (const char *) api->vt.GetString(GL_EXTENSIONS);
136 assert(api->extensions);
137 if (!api->extensions)
139 msg_Err(gl, "glGetString returned NULL");
140 return VLC_EGENERIC;
143 #ifdef USE_OPENGL_ES2
144 api->is_gles = true;
145 /* OpenGL ES 2 includes support for non-power of 2 textures by specification
146 * so checks for extensions are bound to fail. Check for OpenGL ES version instead. */
147 api->supports_npot = true;
148 #else
149 api->is_gles = false;
150 api->supports_npot = vlc_gl_StrHasToken(api->extensions, "GL_ARB_texture_non_power_of_two") ||
151 vlc_gl_StrHasToken(api->extensions, "GL_APPLE_texture_2D_limited_npot");
152 #endif
154 return VLC_SUCCESS;