Commit a373a92b authored by Thomas Guillem's avatar Thomas Guillem

opengl: use all GL symbols from the vtable

Refs #19093
parent a1b62e49
......@@ -44,18 +44,30 @@
typedef void (*PFNGLACTIVETEXTUREPROC) (GLenum texture);
#endif
typedef void (APIENTRY *PFNGLBINDTEXTUREPROC) (GLenum target, GLuint texture);
typedef void (APIENTRY *PFNGLBLENDFUNCPROC) (GLenum sfactor, GLenum dfactor);
typedef void (APIENTRY *PFNGLBUFFERSTORAGEPROC) (GLenum target, GLsizeiptr size, const void *data, GLbitfield flags);
typedef void (APIENTRY *PFNGLCLEARCOLORPROC) (GLfloat red, GLfloat green, GLfloat blue, GLfloat alpha);
typedef void (APIENTRY *PFNGLCLEARPROC) (GLbitfield mask);
typedef void (APIENTRY *PFNGLDELETETEXTURESPROC) (GLsizei n, const GLuint *textures);
typedef void (APIENTRY *PFNGLDEPTHMASKPROC) (GLboolean flag);
typedef void (APIENTRY *PFNGLDISABLEPROC) (GLenum cap);
typedef void (APIENTRY *PFNGLDRAWARRAYSPROC) (GLenum mode, GLint first, GLsizei count);
typedef void (APIENTRY *PFNGLDRAWELEMENTSPROC) (GLenum mode, GLsizei count, GLenum type, const void *indices);
typedef void (APIENTRY *PFNGLENABLEPROC) (GLenum cap);
typedef void (APIENTRY *PFNGLFINISHPROC)(void);
typedef void (APIENTRY *PFNGLFLUSHPROC)(void);
typedef void (APIENTRY *PFNGLGENTEXTURESPROC) (GLsizei n, GLuint *textures);
typedef GLenum (APIENTRY *PFNGLGETERRORPROC) (void);
typedef void (APIENTRY *PFNGLGETINTEGERVPROC) (GLenum pname, GLint *data);
typedef const GLubyte *(APIENTRY *PFNGLGETSTRINGPROC) (GLenum name);
typedef void (APIENTRY *PFNGLGETTEXLEVELPARAMETERIVPROC) (GLenum target, GLint level, GLenum pname, GLint *params);
typedef void (APIENTRY *PFNGLPIXELSTOREIPROC) (GLenum pname, GLint param);
typedef void (APIENTRY *PFNGLTEXENVFPROC)(GLenum target, GLenum pname, GLfloat param);
typedef void (APIENTRY *PFNGLTEXIMAGE2DPROC) (GLenum target, GLint level, GLint internalformat, GLsizei width, GLsizei height, GLint border, GLenum format, GLenum type, const void *pixels);
typedef void (APIENTRY *PFNGLTEXPARAMETERFPROC) (GLenum target, GLenum pname, GLfloat param);
typedef void (APIENTRY *PFNGLTEXPARAMETERIPROC) (GLenum target, GLenum pname, GLint param);
typedef void (APIENTRY *PFNGLTEXSUBIMAGE2DPROC) (GLenum target, GLint level, GLint xoffset, GLint yoffset, GLsizei width, GLsizei height, GLenum format, GLenum type, const void *pixels);
typedef void (APIENTRY *PFNGLVIEWPORTPROC) (GLint x, GLint y, GLsizei width, GLsizei height);
/* The following are defined in glext.h but not for GLES2 or on Apple systems */
#if defined(USE_OPENGL_ES2) || defined(__APPLE__)
......@@ -115,7 +127,17 @@ typedef struct {
* GL / GLES core functions
*/
PFNGLBINDTEXTUREPROC BindTexture;
PFNGLBLENDFUNCPROC BlendFunc;
PFNGLCLEARCOLORPROC ClearColor;
PFNGLCLEARPROC Clear;
PFNGLDELETETEXTURESPROC DeleteTextures;
PFNGLDEPTHMASKPROC DepthMask;
PFNGLDISABLEPROC Disable;
PFNGLDRAWARRAYSPROC DrawArrays;
PFNGLDRAWELEMENTSPROC DrawElements;
PFNGLENABLEPROC Enable;
PFNGLFINISHPROC Finish;
PFNGLFLUSHPROC Flush;
PFNGLGENTEXTURESPROC GenTextures;
PFNGLGETERRORPROC GetError;
PFNGLGETINTEGERVPROC GetIntegerv;
......@@ -125,9 +147,11 @@ typedef struct {
PFNGLTEXPARAMETERFPROC TexParameterf;
PFNGLTEXPARAMETERIPROC TexParameteri;
PFNGLTEXSUBIMAGE2DPROC TexSubImage2D;
PFNGLVIEWPORTPROC Viewport;
/* GL only core functions: NULL for GLES2 */
PFNGLGETTEXLEVELPARAMETERIVPROC GetTexLevelParameteriv; /* Can be NULL */
PFNGLTEXENVFPROC TexEnvf; /* Can be NULL */
/*
* GL / GLES extensions
......
......@@ -60,7 +60,7 @@
#ifdef HAVE_GL_ASSERT_NOERROR
# define GL_ASSERT_NOERROR() do { \
GLenum glError = glGetError(); \
GLenum glError = vgl->vt.GetError(); \
switch (glError) \
{ \
case GL_NO_ERROR: break; \
......@@ -411,7 +411,7 @@ GenTextures(const opengl_tex_converter_t *tc,
const GLsizei *tex_width, const GLsizei *tex_height,
GLuint *textures)
{
glGenTextures(tc->tex_count, textures);
tc->vt->GenTextures(tc->tex_count, textures);
for (unsigned i = 0; i < tc->tex_count; i++)
{
......@@ -419,14 +419,14 @@ GenTextures(const opengl_tex_converter_t *tc,
#if !defined(USE_OPENGL_ES2)
/* Set the texture parameters */
glTexParameterf(tc->tex_target, GL_TEXTURE_PRIORITY, 1.0);
glTexEnvf(GL_TEXTURE_ENV, GL_TEXTURE_ENV_MODE, GL_MODULATE);
tc->vt->TexParameterf(tc->tex_target, GL_TEXTURE_PRIORITY, 1.0);
tc->vt->TexEnvf(GL_TEXTURE_ENV, GL_TEXTURE_ENV_MODE, GL_MODULATE);
#endif
glTexParameteri(tc->tex_target, GL_TEXTURE_MAG_FILTER, GL_LINEAR);
glTexParameteri(tc->tex_target, GL_TEXTURE_MIN_FILTER, GL_LINEAR);
glTexParameteri(tc->tex_target, GL_TEXTURE_WRAP_S, GL_CLAMP_TO_EDGE);
glTexParameteri(tc->tex_target, GL_TEXTURE_WRAP_T, GL_CLAMP_TO_EDGE);
tc->vt->TexParameteri(tc->tex_target, GL_TEXTURE_MAG_FILTER, GL_LINEAR);
tc->vt->TexParameteri(tc->tex_target, GL_TEXTURE_MIN_FILTER, GL_LINEAR);
tc->vt->TexParameteri(tc->tex_target, GL_TEXTURE_WRAP_S, GL_CLAMP_TO_EDGE);
tc->vt->TexParameteri(tc->tex_target, GL_TEXTURE_WRAP_T, GL_CLAMP_TO_EDGE);
}
if (tc->pf_allocate_textures != NULL)
......@@ -434,7 +434,7 @@ GenTextures(const opengl_tex_converter_t *tc,
int ret = tc->pf_allocate_textures(tc, textures, tex_width, tex_height);
if (ret != VLC_SUCCESS)
{
glDeleteTextures(tc->tex_count, textures);
tc->vt->DeleteTextures(tc->tex_count, textures);
memset(textures, 0, tc->tex_count * sizeof(GLuint));
return ret;
}
......@@ -445,7 +445,7 @@ GenTextures(const opengl_tex_converter_t *tc,
static void
DelTextures(const opengl_tex_converter_t *tc, GLuint *textures)
{
glDeleteTextures(tc->tex_count, textures);
tc->vt->DeleteTextures(tc->tex_count, textures);
memset(textures, 0, tc->tex_count * sizeof(GLuint));
}
......@@ -727,30 +727,16 @@ vout_display_opengl_t *vout_display_opengl_New(video_format_t *fmt,
vlc_gl_t *gl,
const vlc_viewpoint_t *viewpoint)
{
vout_display_opengl_t *vgl = calloc(1, sizeof(*vgl));
if (!vgl)
return NULL;
GL_ASSERT_NOERROR();
vgl->gl = gl;
if (gl->getProcAddress == NULL) {
msg_Err(gl, "getProcAddress not implemented, bailing out\n");
free(vgl);
return NULL;
}
const char *extensions = (const char *)glGetString(GL_EXTENSIONS);
#if !defined(USE_OPENGL_ES2)
const unsigned char *ogl_version = glGetString(GL_VERSION);
bool supports_shaders = strverscmp((const char *)ogl_version, "2.0") >= 0;
if (!supports_shaders)
{
msg_Err(gl, "shaders not supported, bailing out\n");
free(vgl);
vout_display_opengl_t *vgl = calloc(1, sizeof(*vgl));
if (!vgl)
return NULL;
}
#endif
vgl->gl = gl;
#define GET_PROC_ADDR_CORE(name) vgl->vt.name = gl##name
#define GET_PROC_ADDR_EXT(name, critical) do { \
......@@ -771,7 +757,17 @@ vout_display_opengl_t *vout_display_opengl_New(video_format_t *fmt,
#define GET_PROC_ADDR_OPTIONAL(name) GET_PROC_ADDR_EXT(name, false) /* GL 3 or more */
GET_PROC_ADDR_CORE(BindTexture);
GET_PROC_ADDR_CORE(BlendFunc);
GET_PROC_ADDR_CORE(Clear);
GET_PROC_ADDR_CORE(ClearColor);
GET_PROC_ADDR_CORE(DeleteTextures);
GET_PROC_ADDR_CORE(DepthMask);
GET_PROC_ADDR_CORE(Disable);
GET_PROC_ADDR_CORE(DrawArrays);
GET_PROC_ADDR_CORE(DrawElements);
GET_PROC_ADDR_CORE(Enable);
GET_PROC_ADDR_CORE(Finish);
GET_PROC_ADDR_CORE(Flush);
GET_PROC_ADDR_CORE(GenTextures);
GET_PROC_ADDR_CORE(GetError);
GET_PROC_ADDR_CORE(GetIntegerv);
......@@ -781,8 +777,10 @@ vout_display_opengl_t *vout_display_opengl_New(video_format_t *fmt,
GET_PROC_ADDR_CORE(TexParameterf);
GET_PROC_ADDR_CORE(TexParameteri);
GET_PROC_ADDR_CORE(TexSubImage2D);
GET_PROC_ADDR_CORE(Viewport);
GET_PROC_ADDR_CORE_GL(GetTexLevelParameteriv);
GET_PROC_ADDR_CORE_GL(TexEnvf);
GET_PROC_ADDR(CreateShader);
GET_PROC_ADDR(ShaderSource);
......@@ -831,10 +829,24 @@ vout_display_opengl_t *vout_display_opengl_New(video_format_t *fmt,
GET_PROC_ADDR_OPTIONAL(ClientWaitSync);
#undef GET_PROC_ADDR
GL_ASSERT_NOERROR();
const char *extensions = (const char *)vgl->vt.GetString(GL_EXTENSIONS);
#if !defined(USE_OPENGL_ES2)
const unsigned char *ogl_version = vgl->vt.GetString(GL_VERSION);
bool supports_shaders = strverscmp((const char *)ogl_version, "2.0") >= 0;
if (!supports_shaders)
{
msg_Err(gl, "shaders not supported, bailing out\n");
free(vgl);
return NULL;
}
#endif
/* Resize the format if it is greater than the maximum texture size
* supported by the hardware */
GLint max_tex_size;
glGetIntegerv(GL_MAX_TEXTURE_SIZE, &max_tex_size);
vgl->vt.GetIntegerv(GL_MAX_TEXTURE_SIZE, &max_tex_size);
if ((GLint)fmt->i_width > max_tex_size ||
(GLint)fmt->i_height > max_tex_size)
......@@ -914,12 +926,12 @@ vout_display_opengl_t *vout_display_opengl_New(video_format_t *fmt,
}
/* */
glDisable(GL_BLEND);
glDisable(GL_DEPTH_TEST);
glDepthMask(GL_FALSE);
glEnable(GL_CULL_FACE);
glClearColor(0.0f, 0.0f, 0.0f, 1.0f);
glClear(GL_COLOR_BUFFER_BIT);
vgl->vt.Disable(GL_BLEND);
vgl->vt.Disable(GL_DEPTH_TEST);
vgl->vt.DepthMask(GL_FALSE);
vgl->vt.Enable(GL_CULL_FACE);
vgl->vt.ClearColor(0.0f, 0.0f, 0.0f, 1.0f);
vgl->vt.Clear(GL_COLOR_BUFFER_BIT);
vgl->vt.GenBuffers(1, &vgl->vertex_buffer_object);
vgl->vt.GenBuffers(1, &vgl->index_buffer_object);
......@@ -961,8 +973,8 @@ void vout_display_opengl_Delete(vout_display_opengl_t *vgl)
GL_ASSERT_NOERROR();
/* */
glFinish();
glFlush();
vgl->vt.Finish();
vgl->vt.Flush();
opengl_tex_converter_t *tc = vgl->prgm->tc;
if (!tc->handle_texs_gen)
......@@ -990,9 +1002,9 @@ void vout_display_opengl_Delete(vout_display_opengl_t *vgl)
opengl_deinit_program(vgl, vgl->prgm);
opengl_deinit_program(vgl, vgl->sub_prgm);
free(vgl);
GL_ASSERT_NOERROR();
free(vgl);
}
static void UpdateZ(vout_display_opengl_t *vgl)
......@@ -1568,7 +1580,7 @@ static void DrawWithShaders(vout_display_opengl_t *vgl, struct prgm *prgm)
vgl->vt.UniformMatrix4fv(prgm->uloc.ZoomMatrix, 1, GL_FALSE,
prgm->var.ZoomMatrix);
glDrawElements(GL_TRIANGLES, vgl->nb_indices, GL_UNSIGNED_SHORT, 0);
vgl->vt.DrawElements(GL_TRIANGLES, vgl->nb_indices, GL_UNSIGNED_SHORT, 0);
}
......@@ -1628,7 +1640,7 @@ int vout_display_opengl_Display(vout_display_opengl_t *vgl,
/* Why drawing here and not in Render()? Because this way, the
OpenGL providers can call vout_display_opengl_Display to force redraw.
Currently, the OS X provider uses it to get a smooth window resizing */
glClear(GL_COLOR_BUFFER_BIT);
vgl->vt.Clear(GL_COLOR_BUFFER_BIT);
vgl->vt.UseProgram(vgl->prgm->id);
......@@ -1685,8 +1697,8 @@ int vout_display_opengl_Display(vout_display_opengl_t *vgl,
opengl_tex_converter_t *tc = prgm->tc;
vgl->vt.UseProgram(program);
glEnable(GL_BLEND);
glBlendFunc(GL_SRC_ALPHA, GL_ONE_MINUS_SRC_ALPHA);
vgl->vt.Enable(GL_BLEND);
vgl->vt.BlendFunc(GL_SRC_ALPHA, GL_ONE_MINUS_SRC_ALPHA);
/* We need two buffer objects for each region: for vertex and texture coordinates. */
if (2 * vgl->region_count > vgl->subpicture_buffer_object_count) {
......@@ -1751,9 +1763,9 @@ int vout_display_opengl_Display(vout_display_opengl_t *vgl,
vgl->vt.UniformMatrix4fv(prgm->uloc.ZoomMatrix, 1, GL_FALSE,
prgm->var.ZoomMatrix);
glDrawArrays(GL_TRIANGLE_STRIP, 0, 4);
vgl->vt.DrawArrays(GL_TRIANGLE_STRIP, 0, 4);
}
glDisable(GL_BLEND);
vgl->vt.Disable(GL_BLEND);
/* Display */
vlc_gl_Swap(vgl->gl);
......
Markdown is supported
0% or
You are about to add 0 people to the discussion. Proceed with caution.
Finish editing this message first!
Please register or to comment