From: "Sung W. Park" <sungwoo@gmail.com>
authorraster <raster@7cbeb6ba-43b4-40fd-8cce-4c39aea84d33>
Mon, 25 Apr 2011 08:41:36 +0000 (08:41 +0000)
committerraster <raster@7cbeb6ba-43b4-40fd-8cce-4c39aea84d33>
Mon, 25 Apr 2011 08:41:36 +0000 (08:41 +0000)
Subject: [E-devel] [Review] [Patch] Evas - OpenGL on Evas: surface
texture creation patch

I'm attaching a patch that addresses the awkward usage case. It's something
that didn't bother me initially but the more I look at it, i think
it's a little off. :-)

The initial version of the evas_gl that I've submitted had the
following use case.

   evasgl = evas_gl_new(e);
   sfc = evas_gl_surface_create(...);
   ctx = evas_gl_context_create(...);

// Make current triggers surface texture and FBO to be created
   evas_gl_make_current(evasgl, sfc, ctx);

// Then you can do a surface_get to retrieve the proper texture and set it
   evas_gl_native_surface_get(evasgl, sfc, &ns);
   evas_object_image_native_surface_set(img_obj, &ns);

   The unnatural thing about this use case is that you have to call the make_current
one time in order for evas_gl to generate a surface texture.  This is because
you need a context to create a texture.  Unfortunately, this makes the usage
case really awkward.

So, instead, I've decided to get rid of the need for calling the make_current
by generating a surface texture when evas_gl_surface_create() is called
by using the evas' gl context.  This works because the newly created context
shares resources with evas.  in fact, this is what i'm currently doing with surface
deletion anyway so I thought this solution was reasonable.

Here's how it looks after you get rid of the make_current:

   evasgl = evas_gl_new(e);
   sfc = evas_gl_surface_create(...);
   ctx = evas_gl_context_create(...);

   evas_gl_native_surface_get(evasgl, sfc, &ns);
   evas_object_image_native_surface_set(img_obj, &ns);

The patch is pretty small and straightforward.

git-svn-id: svn+ssh://svn.enlightenment.org/var/svn/e/trunk/evas@58892 7cbeb6ba-43b4-40fd-8cce-4c39aea84d33

m4/evas_check_engine.m4
src/modules/engines/gl_x11/evas_engine.c

index b1f60c7..f5dbe24 100644 (file)
@@ -113,16 +113,19 @@ if test "x$gl_flavor_gles" = "xyes" ; then
 fi
 
 if test "x${have_dep}" = "xyes" ; then
-   if test "x$2" = "xyes" ; then
-      x_libs="${x_libs} -lX11 -lXext -lXrender"
-   else
-      x_dir=${x_dir:-/usr/X11R6}
-      x_cflags=${x_cflags:--I${x_includes:-$x_dir/include}}
-      x_libs="${x_libs:--L${x_libraries:-$x_dir/lib}} -lX11 -lXext -lXrender"
-   fi
-   evas_engine_[]$1[]_cflags="-I/usr/include ${x_cflags}"
-   evas_engine_[]$1[]_libs="${x_libs} -lGL $gl_pt_lib"
-   evas_engine_gl_common_libs="-lGL $gl_pt_lib"
+   PKG_CHECK_MODULES([GL_EET], [eet >= 1.4.0], [have_dep="yes"], [have_dep="no"])
+   if test "x${have_dep}" = "xyes" ; then
+     if test "x$2" = "xyes" ; then
+       x_libs="${x_libs} -lX11 -lXext -lXrender"
+     else
+       x_dir=${x_dir:-/usr/X11R6}
+       x_cflags=${x_cflags:--I${x_includes:-$x_dir/include}}
+       x_libs="${x_libs:--L${x_libraries:-$x_dir/lib}} -lX11 -lXext -lXrender"
+     fi
+    evas_engine_[]$1[]_cflags="-I/usr/include ${x_cflags}"
+    evas_engine_[]$1[]_libs="${x_libs} -lGL $gl_pt_lib"
+    evas_engine_gl_common_libs="-lGL $gl_pt_lib"
+  fi   
 else
    if test "x$2" = "xyes" ; then
       x_libs="${x_libs} -lX11 -lXext -lXrender"
@@ -147,13 +150,16 @@ else
    if test "x${have_egl}" = "xyes" ; then
       AC_CHECK_LIB(GLESv2, glTexImage2D, [have_glesv2="yes"], , -lEGL ${x_libs} -lm $gl_pt_lib)
       if test "x${have_glesv2}" = "xyes" ; then
-         evas_engine_[]$1[]_cflags="${x_cflags}"
-         evas_engine_[]$1[]_libs="${x_libs} -lGLESv2 -lEGL -lm $gl_pt_lib"
-         evas_engine_gl_common_libs="-lGLESv2 -lm $gl_pt_lib"
-         have_dep="yes"
-         gl_flavor_gles="no"
-         AC_DEFINE(GLES_VARIETY_SGX, 1, [Imagination SGX GLES2 support])
-         gles_variety_sgx="yes"
+         PKG_CHECK_MODULES([GL_EET], [eet >= 1.4.0], [have_dep="yes"], [have_dep="no"])
+         if test "x${have_dep}" = "xyes" ; then
+           evas_engine_[]$1[]_cflags="${x_cflags}"
+           evas_engine_[]$1[]_libs="${x_libs} -lGLESv2 -lEGL -lm $gl_pt_lib"
+           evas_engine_gl_common_libs="-lGLESv2 -lm $gl_pt_lib"
+           have_dep="yes"
+           gl_flavor_gles="no"
+           AC_DEFINE(GLES_VARIETY_SGX, 1, [Imagination SGX GLES2 support])
+           gles_variety_sgx="yes"
+         fi
       fi
    fi
 fi
index 8fb7adb..1ab49f4 100644 (file)
@@ -2229,6 +2229,7 @@ eng_gl_surface_create(void *data, void *config, int w, int h)
    Render_Engine *re;
    Render_Engine_GL_Surface *sfc;
    Evas_GL_Config *cfg; 
+   int ret;
 
    sfc = calloc(1, sizeof(Render_Engine_GL_Surface));
 
@@ -2254,6 +2255,49 @@ eng_gl_surface_create(void *data, void *config, int w, int h)
         return NULL;
      }
 
+   // Create Render Target Texture/Buffers if not initialized
+   if (!sfc->initialized) 
+     {
+        // I'm using evas's original context to create the render target texture
+        // This is to prevent awkwardness in using native_surface_get() function
+        // If the rt texture creation is deferred till the context is created and
+        // make_current called, the user can't call native_surface_get() right
+        // after the surface is created. hence this is done here using evas' context. 
+#if defined (GLES_VARIETY_S3C6410) || defined (GLES_VARIETY_SGX)
+        ret = eglMakeCurrent(re->win->egl_disp, re->win->egl_surface[0], re->win->egl_surface[0], re->win->egl_context[0]);
+#else
+        ret = glXMakeCurrent(re->info->info.display, re->win->win, re->win->context);
+#endif
+        if (!ret) 
+          {
+             ERR("xxxMakeCurrent() failed!");
+             free(sfc);
+             return NULL;
+          }
+
+        // Create Render texture
+        if (!_create_rt_buffers(re, sfc)) 
+          {
+             ERR("_create_rt_buffers() failed.");
+             free(sfc);
+             return NULL;
+          }
+
+#if defined (GLES_VARIETY_S3C6410) || defined (GLES_VARIETY_SGX)
+        ret = eglMakeCurrent(re->win->egl_disp, EGL_NO_SURFACE, 
+                             EGL_NO_SURFACE, EGL_NO_CONTEXT);
+#else
+        ret = glXMakeCurrent(re->info->info.display, None, NULL);
+#endif
+        if (!ret) 
+          {
+             ERR("xxxMakeCurrent() failed!");
+             free(sfc);
+             return 0;
+          }
+        sfc->initialized = 1;
+     }
+
    return sfc;
 }
 
@@ -2505,17 +2549,6 @@ eng_gl_make_current(void *data, void *surface, void *context)
         return 0;
      }
 
-   // Create Render Target Texture/Buffers if not initialized
-   if (!sfc->initialized) 
-     {
-        if (!_create_rt_buffers(re, sfc)) 
-          {
-             ERR("_create_rt_buffers() failed.");
-             return 0;
-          }
-        sfc->initialized = 1;
-     }
-
    // Create FBO if not initalized already
    if (!ctx->initialized) 
      {