On Sat, 10 Sep 2016 22:23:14 +0200
Armin Krezović <[email protected]> wrote:

> It appears that in current Mesa git master, GLESv2 function
> prototypes are hidden.
> 
> Per Emil's suggestion on [1], use eglGetProcAdddress to get
> the functions and update the code to use such functions.
> 
> [1] https://patchwork.freedesktop.org/patch/108369/
> 
> Signed-off-by: Armin Krezović <[email protected]>
> ---
>  clients/simple-egl.c      |  56 +++++-----
>  clients/subsurfaces.c     |  56 +++++-----
>  libweston/gl-renderer.c   | 264 
> +++++++++++++++++++++++-----------------------
>  shared/platform.h         | 142 +++++++++++++++++++++++++
>  tests/buffer-count-test.c |   6 +-
>  5 files changed, 337 insertions(+), 187 deletions(-)
> 

Hi Armin,

I appreciate the effort, but I've been thinking of using libepoxy for
this, to avoid all the manual labour.


> diff --git a/shared/platform.h b/shared/platform.h
> index 1eb96fd..294a948 100644
> --- a/shared/platform.h
> +++ b/shared/platform.h
> @@ -33,6 +33,7 @@
>  #include <wayland-egl.h>
>  #include <EGL/egl.h>
>  #include <EGL/eglext.h>
> +#include <GLES2/gl2.h>
>  #endif
>  
>  #include "weston-egl-ext.h"
> @@ -43,6 +44,52 @@ extern "C" {
>  
>  #ifdef ENABLE_EGL
>  
> +static PFNGLACTIVETEXTUREPROC weston_glActiveTexture;
> +static PFNGLATTACHSHADERPROC weston_glAttachShader;
> +static PFNGLBINDATTRIBLOCATIONPROC weston_glBindAttribLocation;
> +static PFNGLBINDFRAMEBUFFERPROC weston_glBindFramebuffer;
> +static PFNGLBINDTEXTUREPROC weston_glBindTexture;
> +static PFNGLBLENDFUNCPROC weston_glBlendFunc;
> +static PFNGLCHECKFRAMEBUFFERSTATUSPROC weston_glCheckFramebufferStatus;
> +static PFNGLCLEARPROC weston_glClear;
> +static PFNGLCLEARCOLORPROC weston_glClearColor;
> +static PFNGLCOMPILESHADERPROC weston_glCompileShader;
> +static PFNGLCREATEPROGRAMPROC weston_glCreateProgram;
> +static PFNGLCREATESHADERPROC weston_glCreateShader;
> +static PFNGLDELETEFRAMEBUFFERSPROC weston_glDeleteFramebuffers;
> +static PFNGLDELETEPROGRAMPROC weston_glDeleteProgram;
> +static PFNGLDELETESHADERPROC weston_glDeleteShader;
> +static PFNGLDELETETEXTURESPROC weston_glDeleteTextures;
> +static PFNGLDISABLEPROC weston_glDisable;
> +static PFNGLDISABLEVERTEXATTRIBARRAYPROC weston_glDisableVertexAttribArray;
> +static PFNGLDRAWARRAYSPROC weston_glDrawArrays;
> +static PFNGLDRAWELEMENTSPROC weston_glDrawElements;
> +static PFNGLENABLEPROC weston_glEnable;
> +static PFNGLENABLEVERTEXATTRIBARRAYPROC weston_glEnableVertexAttribArray;
> +static PFNGLFRAMEBUFFERTEXTURE2DPROC weston_glFramebufferTexture2D;
> +static PFNGLGENFRAMEBUFFERSPROC weston_glGenFramebuffers;
> +static PFNGLGENTEXTURESPROC weston_glGenTextures;
> +static PFNGLGETPROGRAMINFOLOGPROC weston_glGetProgramInfoLog;
> +static PFNGLGETPROGRAMIVPROC weston_glGetProgramiv;
> +static PFNGLGETSHADERINFOLOGPROC weston_glGetShaderInfoLog;
> +static PFNGLGETSHADERIVPROC weston_glGetShaderiv;
> +static PFNGLGETSTRINGPROC weston_glGetString;
> +static PFNGLGETUNIFORMLOCATIONPROC weston_glGetUniformLocation;
> +static PFNGLLINKPROGRAMPROC weston_glLinkProgram;
> +static PFNGLPIXELSTOREIPROC weston_glPixelStorei;
> +static PFNGLREADPIXELSPROC weston_glReadPixels;
> +static PFNGLSHADERSOURCEPROC weston_glShaderSource;
> +static PFNGLTEXIMAGE2DPROC weston_glTexImage2D;
> +static PFNGLTEXPARAMETERIPROC weston_glTexParameteri;
> +static PFNGLTEXSUBIMAGE2DPROC weston_glTexSubImage2D;
> +static PFNGLUNIFORM1FPROC weston_glUniform1f;
> +static PFNGLUNIFORM1IPROC weston_glUniform1i;
> +static PFNGLUNIFORM4FVPROC weston_glUniform4fv;
> +static PFNGLUNIFORMMATRIX4FVPROC weston_glUniformMatrix4fv;
> +static PFNGLUSEPROGRAMPROC weston_glUseProgram;
> +static PFNGLVERTEXATTRIBPOINTERPROC weston_glVertexAttribPointer;
> +static PFNGLVIEWPORTPROC weston_glViewport;
> +
>  static bool
>  weston_check_egl_extension(const char *extensions, const char *extension)
>  {
> @@ -128,6 +175,101 @@ weston_platform_create_egl_surface(EGLDisplay dpy, 
> EGLConfig config,
>                                     attrib_list);
>  }
>  
> +static inline void
> +weston_gles2_api_init(void)
> +{
> +     weston_glActiveTexture =
> +             (void *) 
> weston_platform_get_egl_proc_address("glActiveTexture");

weston_platform_get_egl_proc_address() is meant to used by EGL/Wayland
clients only, because it first checks that the EGL implementation
supports the Wayland platform. The compositor however is not running on
the Wayland platform if not using the wayland-backend.

Another thing is that the availability of GL ES core (not extension)
functions via eglGetProcAddress depends on
https://www.khronos.org/registry/egl/extensions/KHR/EGL_KHR_get_all_proc_addresses.txt
which we cannot assume is always present, so it needs to be checked
first.

If EGL_KHR_get_all_proc_addresses is not supported, then we need to use
dlopen/dlsym to fetch the function pointers. In this case the
implementation exports the functions from libGLESv2.so as before, we
just need the pointers to them without causing a start-up link-time
dependency on them, hence the need for dlsym().

And now I noticed that EGL_KHR_get_all_proc_addresses has another name
EGL_KHR_client_get_all_proc_addresses for a slightly different
environment/implementation...

So, as this is a problem all projects will be hitting, I'd prefer we
concentrate efforts to a common solution, which at this time seems to
be libepoxy.

I also wrote about it here:
https://bugs.freedesktop.org/show_bug.cgi?id=97773


Thanks,
pq

> +     weston_glAttachShader =
> +             (void *) weston_platform_get_egl_proc_address("glAttachShader");
> +     weston_glBindAttribLocation =
> +             (void *) 
> weston_platform_get_egl_proc_address("glBindAttribLocation");
> +     weston_glBindFramebuffer =
> +             (void *) 
> weston_platform_get_egl_proc_address("glBindFramebuffer");
> +     weston_glBindTexture =
> +             (void *) weston_platform_get_egl_proc_address("glBindTexture");
> +     weston_glBlendFunc =
> +             (void *)  weston_platform_get_egl_proc_address("glBlendFunc");
> +     weston_glCheckFramebufferStatus =
> +             (void *) 
> weston_platform_get_egl_proc_address("glCheckFramebufferStatus");
> +     weston_glClear =
> +             (void *) weston_platform_get_egl_proc_address("glClear");
> +     weston_glClearColor =
> +             (void *) weston_platform_get_egl_proc_address("glClearColor");
> +     weston_glCompileShader =
> +             (void *) 
> weston_platform_get_egl_proc_address("glCompileShader");
> +     weston_glCreateProgram =
> +             (void *) 
> weston_platform_get_egl_proc_address("glCreateProgram");
> +     weston_glCreateShader =
> +             (void *) weston_platform_get_egl_proc_address("glCreateShader");
> +     weston_glDeleteFramebuffers =
> +             (void *) 
> weston_platform_get_egl_proc_address("glDeleteFramebuffers");
> +     weston_glDeleteProgram =
> +             (void *) 
> weston_platform_get_egl_proc_address("glDeleteProgram");
> +     weston_glDeleteShader =
> +             (void *) weston_platform_get_egl_proc_address("glDeleteShader");
> +     weston_glDeleteTextures =
> +             (void *) 
> weston_platform_get_egl_proc_address("glDeleteTextures");
> +     weston_glDisable =
> +             (void *) weston_platform_get_egl_proc_address("glDisable");
> +     weston_glDisableVertexAttribArray =
> +             (void *) 
> weston_platform_get_egl_proc_address("glDisableVertexAttribArray");
> +     weston_glDrawArrays =
> +             (void *) weston_platform_get_egl_proc_address("glDrawArrays");
> +     weston_glDrawElements =
> +             (void *) weston_platform_get_egl_proc_address("glDrawElements");
> +     weston_glEnable =
> +             (void *) weston_platform_get_egl_proc_address("glEnable");
> +     weston_glEnableVertexAttribArray =
> +             (void *) 
> weston_platform_get_egl_proc_address("glEnableVertexAttribArray");
> +     weston_glFramebufferTexture2D =
> +             (void *) 
> weston_platform_get_egl_proc_address("glFramebufferTexture2D");
> +     weston_glGenFramebuffers =
> +             (void *) 
> weston_platform_get_egl_proc_address("glGenFramebuffers");
> +     weston_glGenTextures =
> +             (void *) weston_platform_get_egl_proc_address("glGenTextures");
> +     weston_glGetProgramInfoLog =
> +             (void *) 
> weston_platform_get_egl_proc_address("glGetProgramInfoLog");
> +     weston_glGetProgramiv =
> +             (void *) weston_platform_get_egl_proc_address("glGetProgramiv");
> +     weston_glGetShaderInfoLog =
> +             (void *) 
> weston_platform_get_egl_proc_address("glGetShaderInfoLog");
> +     weston_glGetShaderiv =
> +             (void *) weston_platform_get_egl_proc_address("glGetShaderiv");
> +     weston_glGetString =
> +             (void *) weston_platform_get_egl_proc_address("glGetString");
> +     weston_glGetUniformLocation =
> +             (void *) 
> weston_platform_get_egl_proc_address("glGetUniformLocation");
> +     weston_glLinkProgram =
> +             (void *) weston_platform_get_egl_proc_address("glLinkProgram");
> +     weston_glPixelStorei =
> +             (void *) weston_platform_get_egl_proc_address("glPixelStorei");
> +     weston_glReadPixels =
> +             (void *) weston_platform_get_egl_proc_address("glReadPixels");
> +     weston_glShaderSource =
> +             (void *) weston_platform_get_egl_proc_address("glShaderSource");
> +     weston_glTexImage2D =
> +             (void *) weston_platform_get_egl_proc_address("glTexImage2D");
> +     weston_glTexParameteri =
> +             (void *) 
> weston_platform_get_egl_proc_address("glTexParameteri");
> +     weston_glTexSubImage2D =
> +             (void *) 
> weston_platform_get_egl_proc_address("glTexSubImage2D");
> +     weston_glUniform1f =
> +             (void *) weston_platform_get_egl_proc_address("glUniform1f");
> +     weston_glUniform1i =
> +             (void *) weston_platform_get_egl_proc_address("glUniform1i");
> +     weston_glUniform4fv =
> +             (void *) weston_platform_get_egl_proc_address("glUniform4fv");
> +     weston_glUniformMatrix4fv =
> +             (void *) 
> weston_platform_get_egl_proc_address("glUniformMatrix4fv");
> +     weston_glUseProgram =
> +             (void *) weston_platform_get_egl_proc_address("glUseProgram");
> +     weston_glVertexAttribPointer =
> +             (void *) 
> weston_platform_get_egl_proc_address("glVertexAttribPointer");
> +     weston_glViewport =
> +             (void *) weston_platform_get_egl_proc_address("glViewport");
> +}
> +
>  #else /* ENABLE_EGL */
>  
>  static inline void *
> diff --git a/tests/buffer-count-test.c b/tests/buffer-count-test.c
> index e7d8ca7..d342826 100644
> --- a/tests/buffer-count-test.c
> +++ b/tests/buffer-count-test.c
> @@ -110,7 +110,7 @@ init_egl(struct test_data *test_data)
>  
>       /* This test is specific to mesa 10.1 and later, which is the
>        * first release that doesn't accidentally triple-buffer. */
> -     str = (const char *) glGetString(GL_VERSION);
> +     str = (const char *) weston_glGetString(GL_VERSION);
>       mesa = strstr(str, "Mesa ");
>       if (mesa == NULL)
>               skip("unknown EGL implementation (%s)\n", str);
> @@ -132,6 +132,8 @@ TEST(test_buffer_count)
>       if (!test_data.client->has_wl_drm)
>               skip("compositor has not bound its display to EGL\n");
>  
> +     weston_gles2_api_init();
> +
>       if (init_egl(&test_data) < 0)
>               skip("could not initialize egl, "
>                    "possibly using the headless backend\n");
> @@ -144,7 +146,7 @@ TEST(test_buffer_count)
>        * doing */
>  
>       for (i = 0; i < 10; i++) {
> -             glClear(GL_COLOR_BUFFER_BIT);
> +             weston_glClear(GL_COLOR_BUFFER_BIT);
>               eglSwapBuffers(test_data.egl_dpy, test_data.egl_surface);
>       }
>  

Attachment: pgp8pfvJ5y8xB.pgp
Description: OpenPGP digital signature

_______________________________________________
wayland-devel mailing list
[email protected]
https://lists.freedesktop.org/mailman/listinfo/wayland-devel

Reply via email to