Merge lp:~ahmed-a-ammar/pigment/pigment-gles2 into lp:~loic.molinari/pigment/trunk

Proposed by Ahmed Ammar
Status: Needs review
Proposed branch: lp:~ahmed-a-ammar/pigment/pigment-gles2
Merge into: lp:~loic.molinari/pigment/trunk
Diff against target: 1362 lines (+1077/-25)
9 files modified
ChangeLog (+15/-0)
configure.ac (+48/-3)
src/pgm/gst/pgm-gst-image.c (+77/-13)
src/renderers/opengles/Makefile.am (+49/-1)
src/renderers/opengles/backend-native.c (+22/-1)
src/renderers/opengles/backend-x11.c (+26/-5)
src/renderers/opengles/plugin-opengles2.c (+838/-0)
tests/manual/test-geometry-sorting.c (+1/-1)
tests/manual/test-gst-image.c (+1/-1)
To merge this branch: bzr merge lp:~ahmed-a-ammar/pigment/pigment-gles2
Reviewer Review Type Date Requested Status
Loïc Molinari Pending
Review via email: mp+25630@code.launchpad.net
To post a comment you must log in.

Unmerged revisions

255. By Ahmed Ammar

  * configure.ac:
  * src/pgm/gst/pgm-gst-image.c:
  * src/renderers/opengles/Makefile.am:
  * src/renderers/opengles/backend-native.c:
  * src/renderers/opengles/backend-x11.c:
  * src/renderers/opengles/plugin-opengles2.c:
  Implementation for OpenGL ES 2 renderer. Currently supports three texture
  units and no lights.

  * tests/manual/test-geometry-sorting.c:
  * tests/manual/test-gst-image.c:
  Modified tests to use auto renderer selection.

Preview Diff

[H/L] Next/Prev Comment, [J/K] Next/Prev File, [N/P] Next/Prev Hunk
=== modified file 'ChangeLog'
--- ChangeLog 2010-05-19 16:53:41 +0000
+++ ChangeLog 2010-05-19 17:34:31 +0000
@@ -1,3 +1,18 @@
12010-05-19 Ahmed Ammar <ahmed.ammar@connectmetv.com>
2
3 * configure.ac:
4 * src/pgm/gst/pgm-gst-image.c:
5 * src/renderers/opengles/Makefile.am:
6 * src/renderers/opengles/backend-native.c:
7 * src/renderers/opengles/backend-x11.c:
8 * src/renderers/opengles/plugin-opengles2.c:
9 Implementation for OpenGL ES 2 renderer. Currently supports three texture
10 units and no lights.
11
12 * tests/manual/test-geometry-sorting.c:
13 * tests/manual/test-gst-image.c:
14 Modified tests to use auto renderer selection.
15
12010-05-19 Loïc Molinari <loic@fluendo.com>162010-05-19 Loïc Molinari <loic@fluendo.com>
217
3 Patch by: Ahmed Ammar <ahmed.ammar@connectmetv.com>18 Patch by: Ahmed Ammar <ahmed.ammar@connectmetv.com>
419
=== modified file 'configure.ac'
--- configure.ac 2010-05-10 10:09:50 +0000
+++ configure.ac 2010-05-19 17:34:31 +0000
@@ -247,6 +247,8 @@
247247
248AC_CHECK_HEADERS([GLES/egl.h], [HAVE_EGL=yes], [HAVE_EGL=no])248AC_CHECK_HEADERS([GLES/egl.h], [HAVE_EGL=yes], [HAVE_EGL=no])
249AC_CHECK_HEADERS([GLES/gl.h], [HAVE_GLES=yes], [HAVE_GLES=no])249AC_CHECK_HEADERS([GLES/gl.h], [HAVE_GLES=yes], [HAVE_GLES=no])
250AC_CHECK_HEADERS([GLES2/gl2.h], [HAVE_GLES2=yes], [HAVE_GLES2=no])
251AC_CHECK_HEADERS([EGL/egl.h], [HAVE_EGL2=yes], [HAVE_EGL2=no])
250252
251AC_ARG_ENABLE(opengles1-gdl,253AC_ARG_ENABLE(opengles1-gdl,
252 AS_HELP_STRING([--enable-opengles1-gdl],[enable build of OpenGL ES 1 renderer using Intel GDL backend]),254 AS_HELP_STRING([--enable-opengles1-gdl],[enable build of OpenGL ES 1 renderer using Intel GDL backend]),
@@ -270,6 +272,38 @@
270 ],272 ],
271 [ENABLE_OPENGLES1_X11=no])273 [ENABLE_OPENGLES1_X11=no])
272274
275AC_ARG_ENABLE(opengles2-x11,
276 AC_HELP_STRING([--enable-opengles2-x11], [enable build of OpenGL ES 2 renderer using X11 backend]),
277 [
278 case "${enableval}" in
279 yes) ENABLE_OPENGLES2_X11=yes ;;
280 no) ENABLE_OPENGLES2_X11=no ;;
281 *) AC_MSG_ERROR(bad value ${enableval} for --enable-opengles2-x11) ;;
282 esac
283 ],
284 [ENABLE_OPENGLES2_X11=no])
285
286if test x$HAVE_EGL2 = xyes -a x$HAVE_GLES2 = xyes; then
287 if test x$ENABLE_OPENGLES2_X11 = xyes -a x$HAVE_X11 = xyes; then
288 AC_DEFINE([HAVE_EGL2_X11], [1],
289 [Defined to 1 if the OpenGL ES 2 renderer uses the X11 backend])
290 HAVE_OPENGLES2_PLUGIN="yes"
291 OPENGLES2_BACKEND="(X11 backend)"
292 PGM_GLES2_CFLAGS="$XLIB_CFLAG $GLIB_CFLAGS"
293 PGM_GLES2_LIBS="$XLIB_LIBS $GLIB_LIBS -lGLESv2 -lEGL"
294 else
295 AC_DEFINE([HAVE_EGL2_NATIVE], [1],
296 [Defined to 1 if the OpenGL ES 2 renderer uses the native backend])
297 HAVE_OPENGLES2_PLUGIN="yes"
298 OPENGLES2_BACKEND="(native backend)"
299 PGM_GLES2_CFLAGS="$GLIB_CFLAGS"
300 PGM_GLES2_LIBS="$GLIB_LIBS -lGLESv2 -lEGL"
301 fi
302else
303 HAVE_OPENGLES2_PLUGIN="no"
304 OPENGLES2_BACKEND=""
305fi
306
273if test x$HAVE_EGL = xyes -a x$HAVE_GLES = xyes; then307if test x$HAVE_EGL = xyes -a x$HAVE_GLES = xyes; then
274 if test x$ENABLE_OPENGLES1_GDL = xyes; then308 if test x$ENABLE_OPENGLES1_GDL = xyes; then
275 AC_CHECK_HEADERS([libgdl.h], [HAVE_GDL=yes], [HAVE_GDL=no])309 AC_CHECK_HEADERS([libgdl.h], [HAVE_GDL=yes], [HAVE_GDL=no])
@@ -290,8 +324,8 @@
290 [Defined to 1 if the OpenGL ES 1 renderer uses the X11 backend])324 [Defined to 1 if the OpenGL ES 1 renderer uses the X11 backend])
291 HAVE_OPENGLES1_PLUGIN="yes"325 HAVE_OPENGLES1_PLUGIN="yes"
292 OPENGLES1_BACKEND="(X11 backend)"326 OPENGLES1_BACKEND="(X11 backend)"
293 PGM_GLES1_CFLAGS="$GLIB_CFLAGS"327 PGM_GLES1_CFLAGS="$XLIB_LIBS $GLIB_CFLAGS"
294 PGM_GLES1_LIBS="$GLIB_LIBS -lGLES_CM"328 PGM_GLES1_LIBS="$XLIB_LIBS $GLIB_LIBS -lGLES_CM -lEGL"
295 else329 else
296 HAVE_OPENGLES1_PLUGIN="no"330 HAVE_OPENGLES1_PLUGIN="no"
297 OPENGLES1_BACKEND=""331 OPENGLES1_BACKEND=""
@@ -302,7 +336,7 @@
302 HAVE_OPENGLES1_PLUGIN="yes"336 HAVE_OPENGLES1_PLUGIN="yes"
303 OPENGLES1_BACKEND="(native backend)"337 OPENGLES1_BACKEND="(native backend)"
304 PGM_GLES1_CFLAGS="$GLIB_CFLAGS"338 PGM_GLES1_CFLAGS="$GLIB_CFLAGS"
305 PGM_GLES1_LIBS="$GLIB_LIBS -lGLES_CM"339 PGM_GLES1_LIBS="$GLIB_LIBS -lGLES_CM -lEGL"
306 fi340 fi
307else341else
308 HAVE_OPENGLES1_PLUGIN="no"342 HAVE_OPENGLES1_PLUGIN="no"
@@ -313,9 +347,19 @@
313AC_SUBST(HAVE_OPENGLES1_PLUGIN)347AC_SUBST(HAVE_OPENGLES1_PLUGIN)
314AC_SUBST(PGM_GLES1_CFLAGS)348AC_SUBST(PGM_GLES1_CFLAGS)
315AC_SUBST(PGM_GLES1_LIBS)349AC_SUBST(PGM_GLES1_LIBS)
350
351AC_SUBST(OPENGLES2_BACKEND)
352AC_SUBST(HAVE_OPENGLES2_PLUGIN)
353AC_SUBST(PGM_GLES2_CFLAGS)
354AC_SUBST(PGM_GLES2_LIBS)
355
316AM_CONDITIONAL(HAVE_OPENGLES1_PLUGIN_COND, test x$HAVE_OPENGLES1_PLUGIN = xyes)356AM_CONDITIONAL(HAVE_OPENGLES1_PLUGIN_COND, test x$HAVE_OPENGLES1_PLUGIN = xyes)
357AM_CONDITIONAL(HAVE_OPENGLES2_PLUGIN_COND, test x$HAVE_OPENGLES2_PLUGIN = xyes)
358AM_CONDITIONAL(HAVE_OPENGLES_PLUGIN_COND, test x$HAVE_OPENGLES2_PLUGIN = xyes -o x$HAVE_OPENGLES1_PLUGIN = xyes )
317AM_CONDITIONAL(HAVE_EGL_GDL_COND, test x$HAVE_EGL = xyes -a x$HAVE_GLES = xyes -a x$ENABLE_OPENGLES1_GDL = xyes)359AM_CONDITIONAL(HAVE_EGL_GDL_COND, test x$HAVE_EGL = xyes -a x$HAVE_GLES = xyes -a x$ENABLE_OPENGLES1_GDL = xyes)
318AM_CONDITIONAL(HAVE_EGL_X11_COND, test x$HAVE_EGL = xyes -a x$HAVE_GLES = xyes -a x$ENABLE_OPENGLES1_X11 = xyes)360AM_CONDITIONAL(HAVE_EGL_X11_COND, test x$HAVE_EGL = xyes -a x$HAVE_GLES = xyes -a x$ENABLE_OPENGLES1_X11 = xyes)
361AM_CONDITIONAL(HAVE_EGL2_X11_COND, test x$HAVE_EGL2 = xyes -a x$HAVE_GLES2 = xyes -a x$ENABLE_OPENGLES2_X11 = xyes)
362AM_CONDITIONAL(HAVE_EGL2_NATIVE_COND, test x$HAVE_EGL2 = xyes -a x$HAVE_GLES2 = xyes -a x$ENABLE_OPENGLES2_X11 = xno)
319AM_CONDITIONAL(HAVE_EGL_NATIVE_COND, test x$HAVE_EGL = xyes -a x$HAVE_GLES = xyes -a x$ENABLE_OPENGLES1_X11 = xno -a x$ENABLE_OPENGLES1_GDL = xno)363AM_CONDITIONAL(HAVE_EGL_NATIVE_COND, test x$HAVE_EGL = xyes -a x$HAVE_GLES = xyes -a x$ENABLE_OPENGLES1_X11 = xno -a x$ENABLE_OPENGLES1_GDL = xno)
320364
321# *** Documentation ***365# *** Documentation ***
@@ -448,6 +492,7 @@
448echo " 3D graphics engine: yes"492echo " 3D graphics engine: yes"
449echo " OpenGL renderer: ${HAVE_OPENGL_PLUGIN} ${OPENGL_BACKEND}"493echo " OpenGL renderer: ${HAVE_OPENGL_PLUGIN} ${OPENGL_BACKEND}"
450echo " OpenGL ES 1 renderer: ${HAVE_OPENGLES1_PLUGIN} ${OPENGLES1_BACKEND}"494echo " OpenGL ES 1 renderer: ${HAVE_OPENGLES1_PLUGIN} ${OPENGLES1_BACKEND}"
495echo " OpenGL ES 2 renderer: ${HAVE_OPENGLES2_PLUGIN} ${OPENGLES2_BACKEND}"
451echo " GUI classes: ${HAVE_GUI_CLASSES}"496echo " GUI classes: ${HAVE_GUI_CLASSES}"
452echo " GStreamer classes: ${HAVE_GST_CLASSES}"497echo " GStreamer classes: ${HAVE_GST_CLASSES}"
453echo " GTK+ classes: ${HAVE_GTK_CLASSES}"498echo " GTK+ classes: ${HAVE_GTK_CLASSES}"
454499
=== modified file 'src/pgm/gst/pgm-gst-image.c'
--- src/pgm/gst/pgm-gst-image.c 2009-11-30 18:52:29 +0000
+++ src/pgm/gst/pgm-gst-image.c 2010-05-19 17:34:31 +0000
@@ -17,6 +17,7 @@
17 *17 *
18 * Contributor(s):18 * Contributor(s):
19 * Loïc Molinari <loic@fluendo.com>19 * Loïc Molinari <loic@fluendo.com>
20 * Ahmed Ammar <ahmed.ammar@connecmetv.com>
20 */21 */
2122
22/**23/**
@@ -47,10 +48,12 @@
47static void pgm_gst_image_map (PgmNode*, PgmRenderer*, gfloat, gfloat);48static void pgm_gst_image_map (PgmNode*, PgmRenderer*, gfloat, gfloat);
48static void pgm_gst_image_unmap (PgmNode*);49static void pgm_gst_image_unmap (PgmNode*);
4950
50/* OpenGL ARB fragment program to convert from YV12/I420 planar YCbCr to RGB51/* Shaders converting from YV12/I420 planar YCbCr to RGB color space using
51 * color space using coefficients from the ITU-R BT.601 standard for SDTV and52 * coefficients from the ITU-R BT.601 standard for SDTV and the equations
52 * the equations detailed in the book "Video Demystified, 4th Edition" */53 * detailed in the book "Video Demystified, 4th Edition" */
53static const gchar *ycbcr2rgb_bt601_fp =54
55/* OpenGL ARB fragment program */
56static const gchar *ycbcr2rgb_bt601_glarbfp =
54 "!!ARBfp1.0"57 "!!ARBfp1.0"
55 "OPTION ARB_precision_hint_fastest;"58 "OPTION ARB_precision_hint_fastest;"
56 "ATTRIB position = fragment.texcoord[0];"59 "ATTRIB position = fragment.texcoord[0];"
@@ -65,12 +68,52 @@
65 "MUL result.color, fragment.color, color;"68 "MUL result.color, fragment.color, color;"
66 "END";69 "END";
6770
71/* OpenGL ES 2 shaders */
72static const gchar *ycbcr2rgb_bt601_glslesvp =
73 "uniform mat4 pgm_projection;\n"
74 "uniform mat4 pgm_modelview;\n"
75 "attribute highp vec4 pgm_position;\n"
76 "attribute highp vec4 pgm_color;\n"
77 "attribute highp vec4 pgm_texcoord;\n"
78 "varying highp vec2 frag_texcoord;\n"
79 "varying highp vec4 frag_color;\n"
80 "void main() {\n"
81 " frag_texcoord = pgm_texcoord.xy;\n"
82 " frag_color = pgm_color/255.0;\n"
83 " gl_Position = pgm_projection * pgm_modelview * pgm_position;\n"
84 "}\n";
85static const gchar *ycbcr2rgb_bt601_glslesfp =
86 "uniform sampler2D pgm_texture0;\n"
87 "uniform sampler2D pgm_texture1;\n"
88 "uniform sampler2D pgm_texture2;\n"
89 "varying highp vec2 frag_texcoord;\n"
90 "varying lowp vec4 frag_color;\n"
91 "void main() {"
92 " const lowp vec4 kcr = vec4( 1.596, -0.813, 0, 0 );\n"
93 " const lowp vec4 kcb = vec4( 0, -0.391, 2.018, 0 );\n"
94 " const lowp vec4 kadj = vec4( -0.871, 0.53, -1.082, 0 );\n"
95 " lowp float y = texture2D(pgm_texture0, frag_texcoord).x;\n"
96 " lowp float cb = texture2D(pgm_texture1, frag_texcoord).x;\n"
97 " lowp float cr = texture2D(pgm_texture2, frag_texcoord).x;\n"
98 " lowp vec4 color = vec4(y * 1.164);\n"
99 " color += kcr * cr;\n"
100 " color += kcb * cb;\n"
101 " color += kadj;\n"
102 " gl_FragColor = vec4(color.r, color.g, color.b, 1.0);\n"
103 "}\n";
104
68/* Image negociated format */105/* Image negociated format */
69typedef enum {106enum {
70 IMAGE_NOT_NEGOCIATED = 0,107 IMAGE_NOT_NEGOCIATED = 0,
71 IMAGE_RGB,108 IMAGE_RGB,
72 IMAGE_YCBCR109 IMAGE_YCBCR
73} ImageNegociatedFormat;110};
111
112/* Image available shading language */
113enum {
114 IMAGE_SHADING_LANGUAGE_ARBP = (1 << 0),
115 IMAGE_SHADING_LANGUAGE_GLSLES = (1 << 1)
116} ;
74117
75/* Private structure */118/* Private structure */
76struct _PgmGstImagePimpl {119struct _PgmGstImagePimpl {
@@ -86,6 +129,7 @@
86 gfloat texture_ratio;129 gfloat texture_ratio;
87 PgmGstImageLayout layout;130 PgmGstImageLayout layout;
88 guint8 negociated_format;131 guint8 negociated_format;
132 guint8 shading_language;
89};133};
90134
91/* GObject type definition */135/* GObject type definition */
@@ -158,6 +202,7 @@
158 /* pimpl->texture_ratio = 0.0f; */202 /* pimpl->texture_ratio = 0.0f; */
159 pimpl->layout = PGM_GST_IMAGE_SCALED;203 pimpl->layout = PGM_GST_IMAGE_SCALED;
160 /* pimpl->negociated_format = 0; */204 /* pimpl->negociated_format = 0; */
205 /* pimpl->shading_language = 0; */
161}206}
162207
163/* Private functions */208/* Private functions */
@@ -317,11 +362,18 @@
317 pgm_mesh_set_texture (pimpl->mesh, 1, cb);362 pgm_mesh_set_texture (pimpl->mesh, 1, cb);
318 pgm_mesh_set_texture (pimpl->mesh, 2, cr);363 pgm_mesh_set_texture (pimpl->mesh, 2, cr);
319364
320 /* Since we checked the support for ARB fragment program support for the365 /* Since we checked the support for shaders for the mapped renderer in the
321 * mapped renderer in the map virtual function, we can safely apply the366 * map virtual function, we can safely apply the color space conversion
322 * color space conversion shader to the mesh */367 * shader to the mesh depending on the supported language */
323 shader = pgm_shader_new ("arbp", NULL, 0, NULL, 0, ycbcr2rgb_bt601_fp,368 if (pimpl->shading_language & IMAGE_SHADING_LANGUAGE_ARBP)
324 strlen (ycbcr2rgb_bt601_fp), 0);369 shader = pgm_shader_new ("arbp", NULL, 0, NULL, 0,
370 ycbcr2rgb_bt601_glarbfp,
371 strlen (ycbcr2rgb_bt601_glarbfp), 0);
372 else
373 shader = pgm_shader_new ("glsles", ycbcr2rgb_bt601_glslesvp,
374 strlen (ycbcr2rgb_bt601_glslesvp), NULL, 0,
375 ycbcr2rgb_bt601_glslesfp,
376 strlen (ycbcr2rgb_bt601_glslesfp), 0);
325 pgm_mesh_set_shader (pimpl->mesh, shader);377 pgm_mesh_set_shader (pimpl->mesh, shader);
326378
327 /* Store the texture ratio, no need to check for a height of 0 since such a379 /* Store the texture ratio, no need to check for a height of 0 since such a
@@ -410,7 +462,20 @@
410 if (strcmp (sl->language, "arbp") == 0)462 if (strcmp (sl->language, "arbp") == 0)
411 {463 {
412 if (sl->programs | PGM_RENDERER_FRAGMENT_PROGRAM)464 if (sl->programs | PGM_RENDERER_FRAGMENT_PROGRAM)
413 formats |= PGM_GST_BASE_YCBCR;465 {
466 formats |= PGM_GST_BASE_YCBCR;
467 pimpl->shading_language = IMAGE_SHADING_LANGUAGE_ARBP;
468 }
469 break;
470 }
471 else if (strcmp (sl->language, "glsles") == 0)
472 {
473 if (sl->programs | PGM_RENDERER_FRAGMENT_PROGRAM
474 && sl->programs | PGM_RENDERER_VERTEX_PROGRAM)
475 {
476 formats |= PGM_GST_BASE_YCBCR;
477 pimpl->shading_language = IMAGE_SHADING_LANGUAGE_GLSLES;
478 }
414 break;479 break;
415 }480 }
416 walk = walk->next;481 walk = walk->next;
@@ -536,7 +601,6 @@
536 /* Set up the initial average position */601 /* Set up the initial average position */
537 pgm_mesh_set_average_position (pimpl->mesh, x + pimpl->width * 0.5f,602 pgm_mesh_set_average_position (pimpl->mesh, x + pimpl->width * 0.5f,
538 y + pimpl->height * 0.5f, z);603 y + pimpl->height * 0.5f, z);
539
540 return PGM_NODE (image);604 return PGM_NODE (image);
541}605}
542606
543607
=== modified file 'src/renderers/opengles/Makefile.am'
--- src/renderers/opengles/Makefile.am 2009-11-04 17:50:39 +0000
+++ src/renderers/opengles/Makefile.am 2010-05-19 17:34:31 +0000
@@ -1,7 +1,18 @@
1if HAVE_OPENGLES1_PLUGIN_COND1if HAVE_OPENGLES_PLUGIN_COND
22
3plugindir = @PLUGIN_PATH@3plugindir = @PLUGIN_PATH@
4
5if HAVE_OPENGLES1_PLUGIN_COND
6if HAVE_OPENGLES2_PLUGIN_COND
7plugin_LTLIBRARIES = libpgmopengles1.la libpgmopengles2.la
8else
4plugin_LTLIBRARIES = libpgmopengles1.la9plugin_LTLIBRARIES = libpgmopengles1.la
10endif
11else
12plugin_LTLIBRARIES = libpgmopengles2.la
13endif
14
15if HAVE_OPENGLES1_PLUGIN_COND
516
6libpgmopengles1_la_DEPENDENCIES = \17libpgmopengles1_la_DEPENDENCIES = \
7 $(top_builddir)/src/pgm/libpigment-@PGM_MAJORMINOR@.la18 $(top_builddir)/src/pgm/libpigment-@PGM_MAJORMINOR@.la
@@ -39,3 +50,40 @@
39noinst_HEADERS = backend.h50noinst_HEADERS = backend.h
4051
41endif52endif
53
54if HAVE_OPENGLES2_PLUGIN_COND
55
56
57libpgmopengles2_la_DEPENDENCIES = \
58 $(top_builddir)/src/pgm/libpigment-@PGM_MAJORMINOR@.la
59
60if HAVE_EGL2_NATIVE_COND
61libpgmopengles2_la_SOURCES = \
62 plugin-opengles2.c \
63 backend-native.c
64endif
65if HAVE_EGL2_X11_COND
66libpgmopengles2_la_SOURCES = \
67 plugin-opengles2.c \
68 backend-x11.c
69endif
70
71# egl.h contains non-strictly prototyped function declarations
72libpgmopengles2_la_CFLAGS = \
73 -I$(top_srcdir)/src -DHAVE_GLES2 \
74 $(PGM_CFLAGS) -Wno-strict-prototypes \
75 $(PGM_GLES2_CFLAGS)
76
77libpgmopengles2_la_LIBADD = \
78 $(top_builddir)/src/pgm/libpigment-@PGM_MAJORMINOR@.la \
79 $(PGM_GLES2_LIBS)
80
81libpgmopengles2_la_LDFLAGS = $(PGM_PLUGIN_LDFLAGS)
82
83libpgmopengles2_la_LIBTOOLFLAGS = --tag=disable-static
84
85noinst_HEADERS = backend.h
86
87endif
88
89endif
4290
=== modified file 'src/renderers/opengles/backend-native.c'
--- src/renderers/opengles/backend-native.c 2010-05-11 08:42:10 +0000
+++ src/renderers/opengles/backend-native.c 2010-05-19 17:34:31 +0000
@@ -17,6 +17,7 @@
17 *17 *
18 * Contributor(s):18 * Contributor(s):
19 * Loïc Molinari <loic@fluendo.com>19 * Loïc Molinari <loic@fluendo.com>
20 * Ahmed Ammar <ahmed.ammar@connectmetv.com>
20 */21 */
2122
22#ifdef HAVE_CONFIG_H23#ifdef HAVE_CONFIG_H
@@ -24,7 +25,12 @@
24#endif /* HAVE_CONFIG_H */25#endif /* HAVE_CONFIG_H */
2526
26#include "backend.h"27#include "backend.h"
28
29#ifdef HAVE_GLES2
30#include <EGL/egl.h>
31#else
27#include <GLES/egl.h>32#include <GLES/egl.h>
33#endif
2834
29/* Private structure */35/* Private structure */
30typedef struct {36typedef struct {
@@ -87,9 +93,21 @@
87 EGL_GREEN_SIZE, 6,93 EGL_GREEN_SIZE, 6,
88 EGL_BLUE_SIZE, 5,94 EGL_BLUE_SIZE, 5,
89 EGL_DEPTH_SIZE, 16,95 EGL_DEPTH_SIZE, 16,
96#ifdef HAVE_GLES2
97 EGL_RENDERABLE_TYPE, EGL_OPENGL_ES2_BIT,
98#else
90 EGL_RENDERABLE_TYPE, EGL_OPENGL_ES_BIT,99 EGL_RENDERABLE_TYPE, EGL_OPENGL_ES_BIT,
100#endif
91 EGL_NONE101 EGL_NONE
92 };102 };
103
104 const EGLint context_attribs[] = {
105#ifdef HAVE_GLES2
106 EGL_CONTEXT_CLIENT_VERSION, 2,
107#endif
108 EGL_NONE
109 };
110
93 const gchar *version, *vendor, *extensions;111 const gchar *version, *vendor, *extensions;
94 BackendNative *native;112 BackendNative *native;
95 EGLConfig config;113 EGLConfig config;
@@ -106,6 +124,9 @@
106 PGM_ERROR_OBJECT (native->rdr, "can't open default display");124 PGM_ERROR_OBJECT (native->rdr, "can't open default display");
107 return NULL;125 return NULL;
108 }126 }
127
128 eglBindAPI(EGL_OPENGL_ES_API);
129
109 if (eglInitialize (native->dpy, NULL, NULL) == EGL_FALSE)130 if (eglInitialize (native->dpy, NULL, NULL) == EGL_FALSE)
110 {131 {
111 print_egl_error (native->rdr, "eglInitialize");132 print_egl_error (native->rdr, "eglInitialize");
@@ -142,7 +163,7 @@
142 return NULL;163 return NULL;
143 }164 }
144 native->context = eglCreateContext (native->dpy, config,165 native->context = eglCreateContext (native->dpy, config,
145 EGL_NO_CONTEXT, NULL);166 EGL_NO_CONTEXT, context_attribs);
146 if (native->context == EGL_NO_CONTEXT)167 if (native->context == EGL_NO_CONTEXT)
147 {168 {
148 print_egl_error (native->rdr, "eglCreateContext");169 print_egl_error (native->rdr, "eglCreateContext");
149170
=== modified file 'src/renderers/opengles/backend-x11.c'
--- src/renderers/opengles/backend-x11.c 2010-05-11 08:42:10 +0000
+++ src/renderers/opengles/backend-x11.c 2010-05-19 17:34:31 +0000
@@ -17,6 +17,7 @@
17 *17 *
18 * Contributor(s):18 * Contributor(s):
19 * Loïc Molinari <loic@fluendo.com>19 * Loïc Molinari <loic@fluendo.com>
20 * Ahmed Ammar <ahmed.ammar@connectmetv.com>
20 */21 */
2122
22#ifdef HAVE_CONFIG_H23#ifdef HAVE_CONFIG_H
@@ -25,7 +26,11 @@
2526
26#include "backend.h"27#include "backend.h"
27#include <string.h> /* memset */28#include <string.h> /* memset */
29#ifdef HAVE_GLES2
30#include <EGL/egl.h>
31#else
28#include <GLES/egl.h>32#include <GLES/egl.h>
33#endif
29#include <X11/Xlib.h>34#include <X11/Xlib.h>
30#include <X11/Xutil.h>35#include <X11/Xutil.h>
31#include <X11/Xatom.h>36#include <X11/Xatom.h>
@@ -643,8 +648,19 @@
643 EGL_GREEN_SIZE, 8,648 EGL_GREEN_SIZE, 8,
644 EGL_BLUE_SIZE, 8,649 EGL_BLUE_SIZE, 8,
645 EGL_DEPTH_SIZE, 0,650 EGL_DEPTH_SIZE, 0,
651#ifdef HAVE_GLES2
652 EGL_RENDERABLE_TYPE, EGL_OPENGL_ES2_BIT,
653#endif
646 EGL_NONE654 EGL_NONE
647 };655 };
656
657 const EGLint context_attribs[] = {
658#ifdef HAVE_GLES2
659 EGL_CONTEXT_CLIENT_VERSION, 2,
660#endif
661 EGL_NONE
662 };
663
648 const gchar *version, *vendor, *extensions;664 const gchar *version, *vendor, *extensions;
649 BackendX11 *x11;665 BackendX11 *x11;
650 EGLConfig config;666 EGLConfig config;
@@ -670,6 +686,9 @@
670 g_slice_free1 (sizeof (BackendX11), x11);686 g_slice_free1 (sizeof (BackendX11), x11);
671 return NULL;687 return NULL;
672 }688 }
689
690 eglBindAPI(EGL_OPENGL_ES_API);
691
673 if (eglInitialize (x11->egldpy, NULL, NULL) == EGL_FALSE)692 if (eglInitialize (x11->egldpy, NULL, NULL) == EGL_FALSE)
674 {693 {
675 print_egl_error (x11->rdr, "eglInitialize");694 print_egl_error (x11->rdr, "eglInitialize");
@@ -709,7 +728,8 @@
709 g_slice_free1 (sizeof (BackendX11), x11);728 g_slice_free1 (sizeof (BackendX11), x11);
710 return NULL;729 return NULL;
711 }730 }
712 x11->context = eglCreateContext (x11->egldpy, config, EGL_NO_CONTEXT, NULL);731 x11->context = eglCreateContext (x11->egldpy, config,
732 EGL_NO_CONTEXT, context_attribs);
713 if (x11->context == EGL_NO_CONTEXT)733 if (x11->context == EGL_NO_CONTEXT)
714 {734 {
715 print_egl_error (x11->rdr, "eglCreateContext");735 print_egl_error (x11->rdr, "eglCreateContext");
@@ -856,16 +876,17 @@
856 {876 {
857 case PGM_RENDERER_LEFT_ARROW:877 case PGM_RENDERER_LEFT_ARROW:
858 XDefineCursor (x11->dpy, x11->win, XCreateFontCursor878 XDefineCursor (x11->dpy, x11->win, XCreateFontCursor
859 (x11->dpy, XC_top_left_arrow));879 (x11->dpy, XC_left_ptr));
860 break;880 break;
861881
862 case PGM_RENDERER_INHERIT:882 case PGM_RENDERER_INHERIT:
863 XDefineCursor (x11->dpy, x11->win, XCreateFontCursor883 XDefineCursor (x11->dpy, x11->win, XCreateFontCursor
864 (x11->dpy, XC_top_left_arrow));884 (x11->dpy, XC_left_ptr));
865 break;885 break;
866886
867 case PGM_RENDERER_NONE:887 case PGM_RENDERER_FLEUR:
868 XDefineCursor (x11->dpy, x11->win, x11->none_cursor);888 XDefineCursor (x11->dpy, x11->win,
889 XCreateFontCursor (x11->dpy, XC_fleur));
869 break;890 break;
870891
871 default:892 default:
872893
=== added file 'src/renderers/opengles/plugin-opengles2.c'
--- src/renderers/opengles/plugin-opengles2.c 1970-01-01 00:00:00 +0000
+++ src/renderers/opengles/plugin-opengles2.c 2010-05-19 17:34:31 +0000
@@ -0,0 +1,838 @@
1/*
2 * Pigment 3D graphics engine
3 * Rendering plugin based on OpenGL ES 1
4 *
5 * Copyright © 2006-2010 Fluendo Embedded S.L.
6 *
7 * This library is free software; you can redistribute it and/or modify it under
8 * the terms of the GNU Lesser General Public License as published by the Free
9 * Software Foundation; either version 2 of the License, or (at your option) any
10 * later version. This library is distributed in the hope that it will be
11 * useful, but WITHOUT ANY WARRANTY; without even the implied warranty of
12 * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the GNU Lesser
13 * General Public License for more details. You should have received a copy of
14 * the GNU Lesser General Public License along with this library; if not, write
15 * to the Free Software Foundation, Inc., 59 Temple Place - Suite 330, Boston,
16 * MA 02111-1307, USA.
17 *
18 * Contributor(s):
19 * Loïc Molinari <loic@fluendo.com>
20 * Ahmed Ammar <ahmed.ammar@connecmetv.com>
21 */
22
23#ifdef HAVE_CONFIG_H
24#include "config.h"
25#endif /* HAVE_CONFIG_H */
26
27#include "backend.h"
28#include <string.h> /* strlen */
29#include <ctype.h> /* isdigit */
30#include <stdio.h>
31#include <stdlib.h>
32#include <sys/ioctl.h>
33#include <sys/mman.h>
34#include <fcntl.h>
35
36#define GL_GLEXT_PROTOTYPES
37#include <GLES2/gl2.h>
38#include <GLES2/gl2ext.h>
39#undef GL_GLEXT_PROTOTYPES
40
41/* Extension constants */
42enum {
43 EXT_BGRA = 0x80e1,
44 EXT_MIRRORED_REPEAT = 0x8370
45};
46
47/* Extension flags */
48enum {
49 FLAG_TEXTURE_FORMAT_BGRA8888 = (1 << 0) ,
50 FLAG_TEXTURE_STREAM = (1 << 1)
51/* FLAG_BLEND_FUNC_SEPARATE = (1 << 1) */
52};
53
54/* OpenGL ES 2 attributes */
55enum {
56 PGM_APOSITION = 0,
57 PGM_ACOLOR = 1,
58 PGM_ATEXCOORD = 2,
59};
60
61/* IMG texture stream structure */
62typedef struct {
63 int number;
64 int width;
65 int height;
66 int format;
67} PluginOpengles2TextureBuffer;
68
69/* OpenGL ES 2 vertex shader */
70static const gchar *default_glslesvp =
71 "uniform mat4 pgm_projection;\n"
72 "uniform mat4 pgm_modelview;\n"
73 "attribute highp vec4 pgm_position;\n"
74 "attribute mediump vec4 pgm_color;\n"
75 "attribute mediump vec4 pgm_texcoord;\n"
76 "varying mediump vec2 frag_texcoord;\n"
77 "varying mediump vec4 frag_color;\n"
78 "void main() {\n"
79 " frag_texcoord = pgm_texcoord.xy;\n"
80 " frag_color = pgm_color/255.0;\n"
81 " gl_Position = pgm_projection * pgm_modelview * pgm_position;\n"
82 "}\n";
83static const gchar *default_glslesfp =
84 "uniform sampler2D pgm_texture0;\n"
85 "varying mediump vec2 frag_texcoord;\n"
86 "varying mediump vec4 frag_color;\n"
87 "void main() {\n"
88 " highp vec4 tex0 = texture2D(pgm_texture0, frag_texcoord);\n"
89 " gl_FragColor.rgb = frag_color.rgb + tex0.rgb;\n"
90 " gl_FragColor.a = frag_color.a * tex0.a;\n"
91 "}\n";
92
93/* Wrapper for the opaque PgmPluginTexture pointer */
94typedef struct {
95 GLenum type;
96 GLenum format;
97 GLuint id;
98 gfloat sx;
99 gfloat sy;
100 guint16 width;
101 guint16 height;
102 guint16 miplevels;
103} PluginOpengles2Texture;
104
105/* Wrapper for the opaque PgmPluginShader type */
106typedef struct {
107 GLuint vert_index, frag_index, prog_index;
108 GLint proj_index, modelview_index;
109 GLint texture0_index, texture1_index, texture2_index;
110} PluginOpengles2Shader;
111
112/* IMG texture stream functions */
113typedef void (*glGetTexAttrFunc) (GLenum target, GLenum pname, GLint *params);
114typedef void (*glTexBindStreamFunc) (GLint device, GLint deviceoffset);
115typedef const GLubyte *(*glGetTexDeviceFunc) (GLenum target);
116
117/* Extension functions */
118typedef struct {
119 /* IMG texture stream functions */
120 glTexBindStreamFunc glTexBindStreamIMG;
121 glGetTexAttrFunc glGetTexAttrIMG;
122 glGetTexDeviceFunc glGetTexDeviceIMG;
123} Opengles2ExtensionFunctions;
124
125/* Wrapper for the opaque PgmPlugin pointer */
126typedef struct {
127 PgmPluginFuncs *funcs;
128 PgmRendererCapabilities *caps;
129 PluginOpengles2Texture *default_texture;
130 PgmRenderer *rdr;
131 Backend *backend;
132 PluginOpengles2Texture *texture;
133 gint32 max_texture_units;
134 guint8 extension_flags;
135 /* GLES2 shader variables */
136 PluginOpengles2Shader *shader;
137 GLfloat *proj_mat, *modelview_mat;
138} PluginOpengles2;
139
140/* Texture target look-up table */
141static const GLenum texture_target[] = {
142 GL_TEXTURE_2D, /* PGM_TEXTURE_2D */
143 0 /* PGM_TEXTURE_CUBE */ /* Not supported */
144};
145
146/* Texture format look-up table */
147static const GLenum texture_format[] = {
148 GL_LUMINANCE, /* PGM_TEXTURE_L8 */
149 GL_LUMINANCE_ALPHA, /* PGM_TEXTURE_L8A8 */
150 GL_RGB, /* PGM_TEXTURE_R8G8B8 */
151 GL_RGB, /* PGM_TEXTURE_B8G8R8 */ /* Not supported */
152 GL_RGBA, /* PGM_TEXTURE_R8G8B8A8 */
153 GL_RGBA /* PGM_TEXTURE_B8G8R8A8 */ /* Not supported */
154};
155
156/* Plugin functions */
157static void
158set_sync_to_vblank (PluginOpengles2 *plugin,
159 gboolean sync)
160{
161 backend_set_sync_to_vblank (plugin->backend, sync);
162}
163
164static void
165wait_for_vblank (PluginOpengles2 *plugin)
166{
167 backend_wait_for_vblank (plugin->backend);
168}
169
170static void
171clear_buffers (PluginOpengles2 *plugin,
172 PgmPluginClearBuffer flags)
173{
174 /* Stencil buffer's not used in Pigment, but graphics hardware stores depth
175 * and stencil information in the same buffer so for best performance it's
176 * recommended that both depth and stencil be cleared together. As a side
177 * note, in the old times filling pixels was expensive and avoided as best
178 * as possible using convoluted tricks, nowadays this is not true anymore.
179 * Modern cards now support buffer compression and fast clearing of buffers
180 * using a constant color. More informations can be found in GPU
181 * manufacturer's architecture and performance papers. */
182
183 /* FIXME: Is that valid for embedded GPUs? */
184
185 const GLbitfield mask[] = {
186 0,
187 GL_COLOR_BUFFER_BIT,
188 GL_DEPTH_BUFFER_BIT | GL_STENCIL_BUFFER_BIT,
189 GL_COLOR_BUFFER_BIT | GL_DEPTH_BUFFER_BIT | GL_STENCIL_BUFFER_BIT
190 };
191 glClear (mask[flags]);
192}
193
194static void
195set_clear_color (PluginOpengles2 *plugin,
196 PgmVec4 *color)
197{
198 glClearColor (color->v[0], color->v[1], color->v[2], color->v[3]);
199}
200
201static void
202set_viewport (PluginOpengles2 *plugin,
203 gint32 x,
204 gint32 y,
205 gint32 width,
206 gint32 height)
207{
208 glViewport (x, y, width, height);
209}
210
211static void
212set_projection_matrix (PluginOpengles2 *plugin,
213 PgmMat4x4 *matrix)
214{
215 const GLfloat transpose[16] = {
216 matrix->m[0], matrix->m[4], matrix->m[8], matrix->m[12],
217 matrix->m[1], matrix->m[5], matrix->m[9], matrix->m[13],
218 matrix->m[2], matrix->m[6], matrix->m[10], matrix->m[14],
219 matrix->m[3], matrix->m[7], matrix->m[11], matrix->m[15]
220 };
221
222 memcpy(plugin->proj_mat, transpose, 16*sizeof(GLfloat));
223 glUniformMatrix4fv(plugin->shader->proj_index, 1, GL_FALSE, plugin->proj_mat);
224}
225
226static void
227set_modelview_matrix (PluginOpengles2 *plugin,
228 PgmMat4x4 *matrix)
229{
230 const GLfloat transpose[16] = {
231 matrix->m[0], matrix->m[4], matrix->m[8], matrix->m[12],
232 matrix->m[1], matrix->m[5], matrix->m[9], matrix->m[13],
233 matrix->m[2], matrix->m[6], matrix->m[10], matrix->m[14],
234 matrix->m[3], matrix->m[7], matrix->m[11], matrix->m[15]
235 };
236
237 memcpy(plugin->modelview_mat, transpose, 16*sizeof(GLfloat));
238 glUniformMatrix4fv(plugin->shader->modelview_index, 1, GL_FALSE, plugin->modelview_mat);
239}
240
241static void
242draw_primitive (PluginOpengles2 *plugin,
243 gpointer positions,
244 PgmVertexBufferType position_type,
245 guint8 position_size,
246 gpointer colors,
247 PgmVertexBufferType color_type,
248 gpointer texcoords,
249 PgmVertexBufferType texcoord_type,
250 guint8 texcoord_size,
251 guint16 *indices,
252 PgmMeshPrimitiveType primitive_type,
253 guint16 index_count)
254{
255 static const GLenum type[] = {
256 0, /* PGM_VERTEX_BUFFER_NONE */
257 GL_BYTE, /* PGM_VERTEX_BUFFER_INT8 */
258 GL_UNSIGNED_BYTE, /* PGM_VERTEX_BUFFER_UINT8 */
259 GL_SHORT, /* PGM_VERTEX_BUFFER_INT16 */
260 GL_UNSIGNED_SHORT, /* PGM_VERTEX_BUFFER_UINT16 */
261 0, /* PGM_VERTEX_BUFFER_INT32 */
262 0, /* PGM_VERTEX_BUFFER_UINT32 */
263 GL_FLOAT /* PGM_VERTEX_BUFFER_FLOAT */
264 };
265 static const GLenum mode[] = {
266 GL_LINES, /* PGM_MESH_LINE_LIST */
267 GL_LINE_STRIP, /* PGM_MESH_LINE_STRIP */
268 GL_TRIANGLES, /* PGM_MESH_TRIANGLE_LIST */
269 GL_TRIANGLE_STRIP /* PGM_MESH_TRIANGLE_STRIP */
270 };
271
272 glVertexAttribPointer(PGM_APOSITION, position_size, type[position_type], GL_FALSE, 0, positions);
273 if (texcoord_type == PGM_VERTEX_BUFFER_NONE) {
274 glEnableVertexAttribArray(PGM_ACOLOR);
275 glVertexAttribPointer(PGM_ACOLOR, 4, type[color_type], GL_FALSE, 0, colors);
276 glDrawElements (mode[primitive_type], index_count, GL_UNSIGNED_SHORT, indices);
277 glDisableVertexAttribArray(PGM_ACOLOR);
278 } else {
279 glEnableVertexAttribArray(PGM_ATEXCOORD);
280 glVertexAttribPointer(PGM_ATEXCOORD, texcoord_size, type[texcoord_type], GL_FALSE, 0, texcoords);
281 glDrawElements (mode[primitive_type], index_count, GL_UNSIGNED_SHORT, indices);
282 glDisableVertexAttribArray(PGM_ATEXCOORD);
283 }
284}
285
286static PgmPluginTexture
287create_texture (PluginOpengles2 *plugin,
288 PgmTextureTarget target,
289 PgmTextureFormat format,
290 guint16 width,
291 guint16 height)
292{
293 PluginOpengles2Texture *texture = g_slice_new (PluginOpengles2Texture);
294
295 texture->type = texture_target[target];
296 texture->format = texture_format[format];
297 texture->width = width;
298 texture->height = height;
299 texture->miplevels = 0;
300
301 glGenTextures (1, &texture->id);
302
303 return (PgmPluginTexture) texture;
304}
305
306static void
307delete_textures (PluginOpengles2 *plugin,
308 PluginOpengles2Texture **textures,
309 guint16 count)
310{
311 guint32 i;
312
313 for (i = 0; i < count; i++)
314 {
315 glDeleteTextures (1, &textures[i]->id);
316 g_slice_free (PluginOpengles2Texture, textures[i]);
317 }
318}
319
320static void
321bind_texture (PluginOpengles2 *plugin,
322 guint8 unit,
323 PluginOpengles2Texture *texture)
324{
325 if (unit < plugin->max_texture_units)
326 {
327 glActiveTexture (GL_TEXTURE0 + unit);
328 if (texture != NULL)
329 glBindTexture (texture->type, texture->id);
330 else
331 glBindTexture (GL_TEXTURE_2D, 0);
332 plugin->texture = texture;
333 }
334 else
335 {
336 PGM_WARN_OBJECT (plugin->rdr, "texture unit %d not available on "
337 "that OpenGL ES 2 implementation", unit);
338 }
339}
340
341static void
342upload_texture (PluginOpengles2 *plugin,
343 guint16 miplevel,
344 guint16 x_offset,
345 guint16 y_offset,
346 guint16 width,
347 guint16 height,
348 gpointer texels)
349{
350 PluginOpengles2Texture *tex = plugin->texture;
351
352 static int idx = 0;
353 if (tex->miplevels & (1 << miplevel))
354 {
355 glTexSubImage2D (tex->type, miplevel, x_offset, y_offset, width,
356 height, tex->format, GL_UNSIGNED_BYTE, texels);
357 }
358 else
359 {
360 glTexImage2D (tex->type, miplevel, tex->format, tex->width, tex->height,
361 0, tex->format, GL_UNSIGNED_BYTE, NULL);
362 glTexSubImage2D (tex->type, miplevel, x_offset, y_offset, width, height,
363 tex->format, GL_UNSIGNED_BYTE, texels);
364 tex->miplevels |= 1 << miplevel;
365 }
366 }
367
368static void
369set_texture_states (PluginOpengles2 *plugin,
370 PgmTextureFilter min_filter,
371 PgmTextureFilter mag_filter,
372 PgmTextureFilter mip_filter,
373 PgmTextureWrapping wrap_u,
374 PgmTextureWrapping wrap_v)
375{
376 static const GLenum map[] = {
377 0, /* PGM_TEXTURE_NONE */
378 GL_NEAREST, /* PGM_TEXTURE_NEAREST */
379 GL_LINEAR, /* PGM_TEXTURE_LINEAR */
380 GL_NEAREST_MIPMAP_NEAREST,
381 GL_LINEAR_MIPMAP_NEAREST,
382 GL_NEAREST_MIPMAP_LINEAR,
383 GL_LINEAR_MIPMAP_LINEAR
384 };
385 static const GLenum wrap[] = {
386 GL_CLAMP_TO_EDGE, /* PGM_PLUGIN_CLAMP */
387 GL_CLAMP_TO_EDGE, /* PGM_PLUGIN_BORDER */
388 GL_REPEAT, /* PGM_PLUGIN_REPEAT */
389 EXT_MIRRORED_REPEAT /* PGM_PLUGIN_MIRROR */
390 };
391 const GLenum type = plugin->texture->type;
392 glTexParameteri (type, GL_TEXTURE_MIN_FILTER, map[min_filter+mip_filter*2]);
393 glTexParameteri (type, GL_TEXTURE_MAG_FILTER, map[mag_filter]);
394 glTexParameteri (type, GL_TEXTURE_WRAP_S, wrap[wrap_u]);
395 glTexParameteri (type, GL_TEXTURE_WRAP_T, wrap[wrap_v]);
396}
397
398static PgmPluginShader
399create_shader (PluginOpengles2 *plugin,
400 const gchar *language,
401 gpointer vertex_program,
402 gsize vertex_program_size,
403 gpointer geometry_program,
404 gsize geometry_program_size,
405 gpointer fragment_program,
406 gsize fragment_program_size,
407 PgmShaderUniformInfo *uniforms_info,
408 guint8 uniforms_count)
409{
410 PluginOpengles2Shader *shader;
411 gint error_position = 0;
412 GLint success;
413
414 /* XXX Check language validity */
415
416 shader = g_slice_new (PluginOpengles2Shader);
417
418 shader->prog_index = glCreateProgram();
419
420 if ((vertex_program != NULL) || (fragment_program != NULL))
421 {
422 if (vertex_program != NULL)
423 {
424 PGM_INFO_OBJECT(plugin->rdr, "%s: creating new vertex shader\n", __func__);
425 shader->vert_index = glCreateShader(GL_VERTEX_SHADER);
426 glShaderSource(shader->vert_index, 1, (const char**) &vertex_program, (GLint *) &vertex_program_size);
427 glCompileShader(shader->vert_index);
428 glGetShaderiv(shader->vert_index, GL_COMPILE_STATUS, &success);
429 if (!success) PGM_WARN_OBJECT (plugin->rdr, "%s: vertex shader compilation error\n", __func__);
430 else glAttachShader(shader->prog_index, shader->vert_index);
431 }
432
433 if (fragment_program != NULL)
434 {
435 PGM_INFO_OBJECT(plugin->rdr, "%s: creating new fragment shader\n", __func__);
436 shader->frag_index = glCreateShader(GL_FRAGMENT_SHADER);
437 glShaderSource(shader->frag_index, 1, (const char**) &fragment_program, (GLint *) &fragment_program_size);
438 glCompileShader(shader->frag_index);
439 glGetShaderiv(shader->frag_index, GL_COMPILE_STATUS, &success);
440 if (!success) PGM_WARN_OBJECT (plugin->rdr, "%s: fragment shader compilation error\n", __func__);
441 else glAttachShader(shader->prog_index, shader->frag_index);
442 }
443
444 /* Bind attributes */
445 glBindAttribLocation(shader->prog_index, PGM_APOSITION, "pgm_position");
446 glBindAttribLocation(shader->prog_index, PGM_ACOLOR, "pgm_color");
447 glBindAttribLocation(shader->prog_index, PGM_ATEXCOORD, "pgm_texcoord");
448
449 glLinkProgram(shader->prog_index);
450 glGetProgramiv(shader->prog_index, GL_LINK_STATUS, &success);
451 if (success)
452 {
453 glUseProgram(shader->prog_index);
454 /* Get uniform locations */
455 shader->proj_index = glGetUniformLocation(shader->prog_index, "pgm_projection");
456 shader->modelview_index = glGetUniformLocation(shader->prog_index, "pgm_modelview");
457
458 shader->texture0_index = glGetUniformLocation(shader->prog_index,"pgm_texture0");
459 glUniform1i(shader->texture0_index, 0);
460 shader->texture1_index = glGetUniformLocation(shader->prog_index,"pgm_texture1");
461 glUniform1i(shader->texture1_index, 1);
462 shader->texture2_index = glGetUniformLocation(shader->prog_index,"pgm_texture2");
463 glUniform1i(shader->texture2_index, 2);
464 }
465 else
466 PGM_WARN_OBJECT (plugin->rdr, "program linking error\n");
467 }
468 return (PgmPluginShader) shader;
469}
470
471static void
472delete_shaders (PluginOpengles2 *plugin,
473 PluginOpengles2Shader *shaders,
474 guint16 count)
475{
476 guint32 i;
477 for (i = 0; i < count; i++)
478 {
479 glDetachShader(shaders[i].prog_index, shaders[i].vert_index);
480 glDetachShader(shaders[i].prog_index, shaders[i].frag_index);
481 glDeleteProgram(shaders[i].prog_index);
482 g_slice_free (PluginOpengles2Shader, &(shaders[i]));
483 }
484
485}
486
487static void
488bind_shader (PluginOpengles2 *plugin,
489 PluginOpengles2Shader *shader)
490{
491 GLint success;
492
493 if (shader != NULL) {
494 glUseProgram(shader->prog_index);
495 glUniformMatrix4fv(plugin->shader->proj_index, 1, GL_FALSE, plugin->proj_mat);
496 glUniformMatrix4fv(plugin->shader->modelview_index, 1, GL_FALSE, plugin->modelview_mat);
497 }
498 plugin->shader = shader;
499}
500
501static void
502set_shader_uniforms (PluginOpengles2 *plugin,
503 PgmShaderUniformData *uniforms)
504{
505 /* Not used, we have some predefined uniforms, have a look at the default shaders */
506 PGM_INFO_OBJECT(plugin->rdr, "%s: set shader uniforms\n", __func__);
507}
508
509static void
510swap_buffers (PluginOpengles2 *plugin)
511{
512 backend_swap_buffers (plugin->backend);
513}
514
515static void
516get_screen_size (PluginOpengles2 *plugin,
517 guint32 *width,
518 guint32 *height)
519{
520 backend_get_screen_size (plugin->backend, width, height);
521}
522
523static void
524get_screen_resolution (PluginOpengles2 *plugin,
525 guint32 *width,
526 guint32 *height)
527{
528 backend_get_screen_resolution (plugin->backend, width, height);
529}
530
531static void
532set_window_title (PluginOpengles2 *plugin,
533 const gchar *title)
534{
535 backend_set_window_title (plugin->backend, title);
536}
537
538static void
539set_window_visible (PluginOpengles2 *plugin,
540 gboolean visible)
541{
542 backend_set_window_visible (plugin->backend, visible);
543}
544
545static void
546set_window_decorated (PluginOpengles2 *plugin,
547 gboolean decorated)
548{
549 backend_set_window_decorated (plugin->backend, decorated);
550}
551
552static void
553set_window_fullscreen (PluginOpengles2 *plugin,
554 gboolean fullscreen)
555{
556 backend_set_window_fullscreen (plugin->backend, fullscreen);
557}
558
559static void
560set_window_iconified (PluginOpengles2 *plugin,
561 gboolean iconified)
562{
563 backend_set_window_iconified (plugin->backend, iconified);
564}
565
566static void
567set_window_cursor (PluginOpengles2 *plugin,
568 PgmRendererCursor cursor)
569{
570 backend_set_window_cursor (plugin->backend, cursor);
571}
572
573/* static void */
574/* set_window_icon (PluginOpengles2 *plugin, */
575/* GdkPixbuf *icon) */
576/* { */
577/* backend_set_window_icon (plugin->backend, icon); */
578/* } */
579
580static void
581set_window_size (PluginOpengles2 *plugin,
582 guint32 width,
583 guint32 height)
584{
585 backend_set_window_size (plugin->backend, width, height);
586}
587
588static void
589set_window_message_filter (PluginOpengles2 *plugin,
590 GList *filter)
591{
592 backend_set_window_message_filter (plugin->backend, filter);
593}
594
595static void
596window_focus (PluginOpengles2 *plugin)
597{
598 backend_window_focus (plugin->backend);
599}
600
601static guint32
602get_window_id (PluginOpengles2 *plugin)
603{
604 return backend_get_window_id (plugin->backend);
605}
606
607static void
608set_window_drag_status (PluginOpengles2 *plugin,
609 gboolean accept)
610{
611 backend_set_window_drag_status (plugin->backend, accept);
612}
613
614/* Plugin */
615
616static gboolean
617is_extension_supported (const gchar *extensions,
618 const gchar *extension)
619{
620 if (extensions != NULL && extension != NULL)
621 {
622 const gsize len = strlen (extension);
623 gchar *p = (gchar*) extensions;
624 gchar *end = p + strlen (p);
625
626 while (p < end)
627 {
628 const gsize size = strcspn (p, " ");
629 if (len == size && strncmp (extension, p, size) == 0)
630 return TRUE;
631 p += size + 1;
632 }
633 }
634
635 return FALSE;
636}
637
638static gboolean
639init_plugin (PluginOpengles2 *plugin,
640 guint32 options)
641{
642 const struct {
643 const gchar *name; guint8 flag;
644 } extension_map[] = {
645 { "GL_IMG_texture_format_BGRA8888", FLAG_TEXTURE_FORMAT_BGRA8888 },
646 { NULL, 0 }
647 };
648 const gchar *vendor, *renderer, *version, *extensions;
649 PluginOpengles2Texture *texture;
650 PgmRendererCapabilities *caps;
651 PgmPluginFuncs *funcs;
652 guint8 extension_flags = 0;
653 guint8 caps_flags = 0;
654 guint32 i;
655
656
657 /* Get the information strings */
658 version = (const gchar*) glGetString (GL_VERSION);
659 vendor = (const gchar*) glGetString (GL_VENDOR);
660 renderer = (const gchar*) glGetString (GL_RENDERER);
661 extensions = (const gchar*) glGetString (GL_EXTENSIONS);
662 PGM_INFO_OBJECT (plugin->rdr, "OpenGL ES vendor: %s", vendor);
663 PGM_INFO_OBJECT (plugin->rdr, "OpenGL ES renderer: %s", renderer);
664 PGM_INFO_OBJECT (plugin->rdr, "OpenGL ES version: %s", version);
665 PGM_DEBUG_OBJECT (plugin->rdr, "OpenGL ES extensions: %s", extensions);
666
667 /* Store the supported extensions in a bitfield */
668 for (i = 0; extension_map[i].name != NULL; i++)
669 if (is_extension_supported (extensions, extension_map[i].name) == TRUE)
670 extension_flags |= extension_map[i].flag;
671 plugin->extension_flags = extension_flags;
672
673 /* Set initial states */
674 /* XXX: Some of these must be set from the core with dedicated functions */
675 glEnableVertexAttribArray(PGM_APOSITION);
676 glEnable (GL_BLEND);
677 glDepthFunc (GL_LEQUAL);
678 glEnable (GL_DEPTH_TEST);
679
680 glBlendFunc (GL_ONE, GL_ONE_MINUS_SRC_ALPHA);
681 glEnable (GL_TEXTURE_2D);
682
683 /* Fill the default texture */
684 texture = g_slice_alloc (sizeof (PluginOpengles2Texture));
685 texture->type = GL_TEXTURE_2D;
686 texture->id = 0;
687 plugin->default_texture = texture;
688
689 /* Allocate memory for modelview/projection matrices */
690 plugin->proj_mat = (GLfloat*) malloc (16*sizeof(GLfloat));
691 plugin->modelview_mat = (GLfloat*) malloc (16*sizeof(GLfloat));
692
693 /* Fill the caps */
694 caps = pgm_renderer_capabilities_new ();
695 caps->device_vendor = g_strdup (vendor);
696 caps->device_description = g_strconcat (renderer, " (", version, ")", NULL);
697 if (backend_is_window_pluggable (plugin->backend))
698 caps_flags |= PGM_RENDERER_PLUGGABLE_WINDOW;
699 if (backend_is_window_layered (plugin->backend))
700 caps_flags |= PGM_RENDERER_LAYERED_WINDOW;
701 caps->flags = caps_flags;
702
703 /* Store supported shading languages */
704 caps->shading_languages = g_list_prepend
705 (NULL, pgm_renderer_shading_language_new ("glsles", "1.0", PGM_RENDERER_FRAGMENT_PROGRAM | PGM_RENDERER_VERTEX_PROGRAM ));
706
707 /* Store limits */
708 glGetIntegerv (GL_MAX_TEXTURE_SIZE, &caps->max_texture_size);
709 plugin->max_texture_units = caps->max_texture_units = 3;
710 caps->max_lights = 0;
711 plugin->caps = caps;
712
713 /* Fill the funcs */
714 funcs = g_slice_alloc (sizeof (PgmPluginFuncs));
715 funcs->set_sync_to_vblank =
716 (PgmPluginSetSyncToVBlankFunc) set_sync_to_vblank;
717 funcs->wait_for_vblank = (PgmPluginWaitForVBlankFunc) wait_for_vblank;
718 funcs->clear_buffers = (PgmPluginClearBuffersFunc) clear_buffers;
719 funcs->set_clear_color = (PgmPluginSetClearColorFunc) set_clear_color;
720 funcs->set_viewport = (PgmPluginSetViewportFunc) set_viewport;
721 funcs->set_projection_matrix =
722 (PgmPluginSetProjectionMatrixFunc) set_projection_matrix;
723 funcs->set_modelview_matrix =
724 (PgmPluginSetModelviewMatrixFunc) set_modelview_matrix;
725 funcs->draw_primitive = (PgmPluginDrawPrimitiveFunc) draw_primitive;
726 funcs->create_texture = (PgmPluginCreateTextureFunc) create_texture;
727 funcs->delete_textures = (PgmPluginDeleteTexturesFunc) delete_textures;
728 funcs->bind_texture = (PgmPluginBindTextureFunc) bind_texture;
729 funcs->upload_texture = (PgmPluginUploadTextureFunc) upload_texture;
730 funcs->set_texture_states =
731 (PgmPluginSetTextureStatesFunc) set_texture_states;
732 funcs->create_shader = (PgmPluginCreateShaderFunc) create_shader;
733 funcs->delete_shaders = (PgmPluginDeleteShadersFunc) delete_shaders;
734 funcs->bind_shader = (PgmPluginBindShaderFunc) bind_shader;
735 funcs->set_shader_uniforms =
736 (PgmPluginSetShaderUniformsFunc) set_shader_uniforms;
737 funcs->swap_buffers = (PgmPluginSwapBuffersFunc) swap_buffers;
738 funcs->get_screen_size = (PgmPluginGetScreenSizeFunc) get_screen_size;
739 funcs->get_screen_resolution =
740 (PgmPluginGetScreenResolutionFunc) get_screen_resolution;
741 funcs->read_pixels = NULL;
742 funcs->set_window_title = (PgmPluginSetWindowTitleFunc) set_window_title;
743 funcs->set_window_visible =
744 (PgmPluginSetWindowVisibleFunc) set_window_visible;
745 funcs->set_window_decorated =
746 (PgmPluginSetWindowDecoratedFunc) set_window_decorated;
747 funcs->set_window_fullscreen =
748 (PgmPluginSetWindowFullscreenFunc) set_window_fullscreen;
749 funcs->set_window_iconified =
750 (PgmPluginSetWindowIconifiedFunc) set_window_iconified;
751 funcs->set_window_cursor =
752 (PgmPluginSetWindowCursorFunc) set_window_cursor;
753/* funcs->set_window_icon = (PgmPluginSetWindowIconFunc) set_window_icon; */
754 funcs->set_window_size = (PgmPluginSetWindowSizeFunc) set_window_size;
755 funcs->set_window_message_filter =
756 (PgmPluginSetWindowMessageFilterFunc) set_window_message_filter;
757 funcs->window_focus = (PgmPluginWindowFocusFunc) window_focus;
758 funcs->get_window_id = (PgmPluginGetWindowIdFunc) get_window_id;
759 funcs->set_window_drag_status =
760 (PgmPluginSetWindowDragStatusFunc) set_window_drag_status;
761 plugin->funcs = funcs;
762
763 return TRUE;
764}
765
766static PgmPlugin
767construct (PgmRenderer *renderer,
768 GMainContext *context,
769 guint32 options,
770 PgmPluginFuncs **funcs,
771 PgmRendererCapabilities **caps,
772 PgmPluginTexture *texture,
773 PgmPluginShader *shader)
774{
775 PluginOpengles2 *plugin = g_slice_alloc0 (sizeof (PluginOpengles2));
776 Backend backend = backend_new (renderer, context, options);
777
778 if (backend != NULL)
779 {
780 plugin->rdr = renderer;
781 plugin->backend = backend;
782
783 plugin->shader = (PluginOpengles2Shader*) create_shader(plugin, "glsles", (gpointer)default_glslesvp,
784 strlen(default_glslesvp), NULL, 0,
785 (gpointer) default_glslesfp,
786 strlen(default_glslesfp), NULL, 0);
787
788 if (init_plugin (plugin, options) == TRUE)
789 {
790 *funcs = plugin->funcs;
791 *caps = plugin->caps;
792 *texture = plugin->default_texture;
793 *shader = plugin->shader;
794 return (PgmPlugin) plugin;
795 }
796 else
797 {
798 backend_free (backend);
799 g_slice_free1 (sizeof (PluginOpengles2), plugin);
800 PGM_ERROR_OBJECT (renderer, "can't initialize OpenGL ES plugin");
801 return NULL;
802 }
803 }
804 else
805 {
806 PGM_ERROR_OBJECT (renderer, "can't create OpenGL ES context");
807 return NULL;
808 }
809}
810
811static void
812destruct (PluginOpengles2 *plugin)
813{
814 /* XXX destruct shaders? */
815 g_slice_free1 (sizeof (PgmPluginFuncs), plugin->funcs);
816 g_slice_free1 (sizeof (PluginOpengles2Texture), plugin->default_texture);
817 pgm_renderer_capabilities_free (plugin->caps);
818 backend_free (plugin->backend);
819 g_slice_free1 (sizeof (PluginOpengles2), plugin);
820}
821
822#if defined (HAVE_EGL2_NATIVE)
823#define description "a plugin based on OpenGL ES 2 (native)"
824#elif defined (HAVE_EGL2_X11)
825#define description "a plugin based on OpenGL ES 2 (X11)"
826#endif
827
828PGM_PLUGIN_DEFINE (
829 "opengles2", /* Name */
830 VERSION, /* Version */
831 description, /* Description */
832 "LGPL", /* License */
833 "https://code.fluendo.com/pigment", /* Origin */
834 "Ahmed Ammar <ahmed.ammar@connectmetv.com>", /* Author */
835 (PgmPluginConstructFunc) construct, /* Constructor */
836 (PgmPluginDestructFunc) destruct, /* Destructor */
837 PGM_PLUGIN_SECONDARY /* Rank */
838)
0839
=== modified file 'tests/manual/test-geometry-sorting.c'
--- tests/manual/test-geometry-sorting.c 2010-05-07 16:58:25 +0000
+++ tests/manual/test-geometry-sorting.c 2010-05-19 17:34:31 +0000
@@ -447,7 +447,7 @@
447 pgm_init (&argc, &argv);447 pgm_init (&argc, &argv);
448448
449 /* OpenGL renderer creation */449 /* OpenGL renderer creation */
450 renderer = pgm_renderer_factory_make ("opengl", 1);450 renderer = pgm_renderer_factory_make_auto ();
451 if (!renderer)451 if (!renderer)
452 {452 {
453 g_print ("Cannot create a renderer\n");453 g_print ("Cannot create a renderer\n");
454454
=== modified file 'tests/manual/test-gst-image.c'
--- tests/manual/test-gst-image.c 2010-05-07 16:46:26 +0000
+++ tests/manual/test-gst-image.c 2010-05-19 17:34:31 +0000
@@ -78,7 +78,7 @@
78 pgm_init (&argc, &argv);78 pgm_init (&argc, &argv);
79 gst_init (&argc, &argv);79 gst_init (&argc, &argv);
8080
81 renderer = pgm_renderer_factory_make ("opengl", 0);81 renderer = pgm_renderer_factory_make_auto ();
82 if (!renderer)82 if (!renderer)
83 {83 {
84 g_print ("Cannot create the OpenGL renderer\n");84 g_print ("Cannot create the OpenGL renderer\n");

Subscribers

People subscribed via source and target branches

to all changes: