On Thu, 19 May 2011 16:37:11 +0900 "Sung W. Park" <sung...@gmail.com> said:

1. func_set for setting render func.. :) 
2. fixes for size set for setting native buffer resolution/size - changing obj
size by a resize is not the way to go.
3. changes in policies were not enacted always. now they are.
4. a DEFAULT 64x64 buffer size :) so you have something at least as opposed to
0x0 :)
5. some other things...

also added my simple test case (i patched mine into elementary_test thus why
its created in a callback)

> Thanks for your comments.
> 
> Ok, I've added a focus_hook so it now handles events properly.  Now
> the elmglviewgears
> handles key events and mouse events.  You can rotate it using
> "Left,Right,Up,Down Arrows"
> or use the mouse and drag it.  It doesn't actually have a real
> trackball feature
> implemented so you will notice it not rotating it properly if you
> rotate it too much.
> 
> I've dropped the elm_glview_z_get function.  I didn't think it was
> necessary for now.
> maybe we can add it later.
> 
> Also, the gl_func_call api was for internal testing purpose and it was
> commented out
> in the patch but i've removed them completely in this patch.
> 
> Also, I've made some changes with the API.   It has been brought to my
> attention that there is a performance issue with the way the current APIs are
> implemented. Currently, the render function was registered using the
> 
> "evas_object_image_pixels_get_callback_set"
> 
> This is so that it doesn't trigger GL rendering when the image object
> isn't visible.
> Unfortunately, it causes and extra make_current to be called during
> the rendering
> life cycle of evas.
> 
> Evas Render... -> (context switch) -> EvasGL Renders -> (context_switch) ->
> Evas Finishes rendering
> 
> The context switch is quite expensive in the hw driver that i'm using
> so it actually
> lowers the performance quite a bit.
> 
> SO, after discussing it with a few people, we've decided to give an
> option to the user
> to choose the rendering policy.  If you choose to have render function
> render all the time,
> it avoids one extra context switch.
> 
> EvasGL Renders -> (context_switch) -> Evas Renders
> 
> Hence the render policy of RENDER_POLICY_ON_DEMAND vs. RENDER_POLICY_ALWAYS.
> 
> I've also changed the name "elm_glview_display_func" to
> "elm_glview_render_func"
> 
> Here's the latest set of elm_glview APIs...
> ______________________________________
> 
> typedef enum _Elm_GLView_Resize_Policy
>   {
>      ELM_GLVIEW_RESIZE_POLICY_RECREATE = 1,
>      ELM_GLVIEW_RESIZE_POLICY_SCALE    = 2
>   } Elm_GLView_Resize_Policy;
> 
> typedef enum _Elm_GLView_Render_Policy
>   {
>      ELM_GLVIEW_RENDER_POLICY_ON_DEMAND = 1,
>      ELM_GLVIEW_RENDER_POLICY_ALWAYS    = 2
>   } Elm_GLView_Render_Policy;
> 
> 
> Evas_Object    *elm_glview_add(Evas_Object *parent);
> void             elm_glview_size_set(Evas_Object *obj, Evas_Coord
> width, Evas_Coord height);
> void             elm_glview_size_get(Evas_Object *obj, Evas_Coord
> *width, Evas_Coord *height);
> Evas_GL_API  *elm_glview_gl_api_get(Evas_Object *obj);
> Eina_Bool    elm_glview_mode_set(Evas_Object *obj, Elm_GLView_Mode mode);
> Eina_Bool    elm_glview_scale_policy_set(Evas_Object *obj,
> Elm_GLView_Resize_Policy policy);
> Eina_Bool    elm_glview_render_policy_set(Evas_Object *obj,
> Elm_GLView_Render_Policy policy);
> void             elm_glview_render_func(Evas_Object *obj, Elm_GLView_Func
> func); void             elm_glview_changed_set(Evas_Object *obj);
> ______________________________________
> 
> I'm including the updated elm_glview patch/files and the updated
> elmglviewgears.
> 
> Let me know if you have questions/comments.
> 
> cheers,
> Sung
> 
> 
> On Wed, May 18, 2011 at 7:10 PM, Carsten Haitzler <ras...@rasterman.com>
> wrote:
> >
> > On Fri, 13 May 2011 00:00:50 +0900 "Sung W. Park" <sung...@gmail.com> said:
> >
> > ok. missing the focus hook thing u'd need if u want key events to work...
> > display_func -> render_func_set() probably better. z_get probably can be
> > skipped if really too much of a pita.
> >
> > whats the gl_func_call api for.. why pass the func - u already set it? could
> > set it then call a manual render.. if that's needed. is it really needed?
> > curious.  :)
> >
> > > Hi all,
> > >
> > > As you all know, I've been working on adding GL rendering features to
> > > Evas and we now have an early working version of Evas_GL in the svn.
> > >
> > > Since then, there's been a request from people around me for an
> > > elementary widget that
> > > allows simple GL rendering.  Since Evas_GL can be seen as a low level API
> > > it made sense to have a user friendly layer that allows GL rendering.  I
> > > thought it
> > > went well with the EFL philosophy.  Take away some control but make it
> > > easy to use for the users as you go up the layers from Evas->Ecore->ELM->
> > > etc.
> > >
> > > So, I've decided to take a crack at elm_glview.  By the way, this is
> > > my first time writing
> > > an elementary widget so I KNOW I've missed a lot that i need to handle.
> > >  Also, I'm aware of the fact thatI need to handle input events. I'll need
> > > to figure that out
> > > but I open to comments and suggestions.  However, before I get all the
> > > nitty gritty
> > > detail right, I wanted to start a discussion with the community on the
> > > APIs and ask for suggestions.
> > >
> > > So far, after discussing this with a few people, we've come up with
> > > the following.
> > >
> > >    typedef enum _Elm_GLView_Scale_Policy
> > >      {
> > >         ELM_GLVIEW_POLICY_RESIZE,   /**< Resize the internal surface
> > > along with the image */
> > >         ELM_GLVIEW_POLICY_SCALE     /**< Only reize the internal image
> > > and not the surface */
> > >      } Elm_GLView_Scale_Policy;
> > >
> > >    Evas_Object *elm_glview_add(Evas_Object *parent);
> > >    void              elm_glview_size_set(Evas_Object *obj, Evas_Coord
> > > width, Evas_Coord height);
> > >    void              elm_glview_size_get(Evas_Object *obj, Evas_Coord
> > > *width, Evas_Coord *height);
> > >    Evas_GL_API  *elm_glview_gl_api_get(Evas_Object *obj);
> > >    Eina_Bool        elm_glview_mode_set(Evas_Object *obj, Elm_GLView_Mode
> > > mode); Eina_Bool        elm_glview_scale_policy_set(Evas_Object *obj,
> > > Elm_GLView_Scale_Policy policy);
> > >    void             elm_glview_display_func(Evas_Object *obj,
> > > Elm_GLView_Func func);
> > >    void             elm_glview_changed_set(Evas_Object *obj);
> > >    Eina_Bool    elm_glview_z_get(Evas_Object *obj, Evas_Coord x,
> > > Evas_Coord y, Evas_Coord *z);
> > >
> > >
> > > Internally, elm_glview handles creating an image object, evas_gl
> > > object, evas_gl context,
> > > surface, doing make current for display function. You just need to set
> > > the display_function
> > > callback and put your GL calls in there. The scale policy concerns how the
> > > glview would resize.  setting it to SCALE would keep the current
> > > glview but simply scale
> > > the underlying image.  otherwise, it would recreate the surface.  The
> > > API is pretty straight forward
> > > in my opinion.  It's very much GLUT-like adapted for EFL.
> > >
> > > In order to use the elm_glview, you would do something like
> > >
> > > main()
> > > {
> > >    ...
> > >    // Add a GLView
> > >    glview = elm_glview_add(win);
> > >    glapi = elm_glview_gl_api_get(glview);
> > >    elm_glview_mode_set(glview, ELM_GLVIEW_ALPHA | ELM_GLVIEW_DEPTH);
> > >    elm_glview_scale_policy_set(glview, ELM_GLVIEW_POLICY_SCALE);
> > >    elm_glview_display_func(glview, (Elm_GLView_Func)draw);
> > >    evas_object_resize(glview, 256, 256);
> > >    evas_object_show(glview);
> > >    ecore_animator_add(on_animate, glview);
> > >    ...
> > > }
> > >
> > > on_animate()
> > > {
> > >    elm_glview_changed_set((Evas_Object*)data);
> > >    return EINA_TRUE;
> > > }
> > >
> > > // GL calls
> > > draw()
> > > {
> > >    elm_glview_size_get(..., &w, &h);
> > >    glapi->glViewport(..., w, h);
> > >    ...
> > > }
> > >
> > > I guess it's easier to see the sample files and run the code to see
> > > how they actually work.
> > > I'm including a patch that shows the above example.  I'm including the
> > > following files.
> > >
> > > 1. elm_glview.path
> > >   -. apply using: patch -p0 elm_glview.patch
> > > 2. elm_glview.c
> > >   -. copy the file to src/lib
> > >   -. make/ install elmentary
> > > 3. elmglviewsample1.c, elmglviewgears.c, Makefile
> > >   -. do a make on the samples using the given makefile.
> > >
> > > Ok, that's all for now.  I'd love to hear comments and suggestions on
> > > it as I continue to
> > > work on it.
> > >
> > > thanks!
> > >
> > > cheers,
> > > Sung
> >
> >
> > --
> > ------------- Codito, ergo sum - "I code, therefore I am" --------------
> > The Rasterman (Carsten Haitzler)    ras...@rasterman.com
> >


-- 
------------- Codito, ergo sum - "I code, therefore I am" --------------
The Rasterman (Carsten Haitzler)    ras...@rasterman.com

#include <Elementary.h>
#include <Evas_GL.h>
#include "elm_priv.h"

/**
 * @defgroup GLView
 *
 * A simple GLView widget that allows GL rendering.
 *
 * Signals that you can add callbacks for are:
 *
 * "clicked" - This is called when a user has clicked the image
 */
typedef struct _Widget_Data Widget_Data;

struct _Widget_Data
{
   Evas_Object	           *glview_image;

   Elm_GLView_Mode          mode;
   Elm_GLView_Resize_Policy  scale_policy;
   Elm_GLView_Render_Policy render_policy;

   Evas_GL                 *evasgl;
   Evas_GL_Config           config;
   Evas_GL_Surface         *surface;
   Evas_GL_Context         *context;

   Evas_Coord               w, h;

   Elm_GLView_Func          render_func;
   Ecore_Idle_Enterer      *render_idle_enterer;

   Eina_Bool                initialized;
};

static const char *widtype = NULL;
static void _del_hook(Evas_Object *obj);
static void _on_focus_hook(void *data, Evas_Object *obj);

static const char SIG_FOCUSED[] = "focused";
static const char SIG_UNFOCUSED[] = "unfocused";

static void
_del_hook(Evas_Object *obj)
{
   Widget_Data *wd = elm_widget_data_get(obj);
   if (!wd) return;
   
   if (wd->render_idle_enterer) ecore_idle_enterer_del(wd->render_idle_enterer);

   if (wd->surface) evas_gl_surface_destroy(wd->evasgl, wd->surface);
   if (wd->context) evas_gl_context_destroy(wd->evasgl, wd->context);
   if (wd->evasgl) evas_gl_free(wd->evasgl);

   free(wd);
}

static void
_on_focus_hook(void *data __UNUSED__, Evas_Object *obj)
{
   Widget_Data *wd = elm_widget_data_get(obj);
   if (!wd) return;

   if (elm_widget_focus_get(obj))
     {
        evas_object_focus_set(wd->glview_image, EINA_TRUE);
        evas_object_smart_callback_call(obj, SIG_FOCUSED, NULL);
     }
   else
     {
        evas_object_focus_set(wd->glview_image, EINA_FALSE);
        evas_object_smart_callback_call(obj, SIG_UNFOCUSED, NULL);
     }
}

static void
_glview_update_surface(Evas_Object *obj)
{
   Widget_Data *wd = elm_widget_data_get(obj);
   if (!wd) return;

   if (wd->surface)
     {
        evas_object_image_native_surface_set(wd->glview_image, NULL);
        evas_gl_surface_destroy(wd->evasgl, wd->surface);
        wd->surface = NULL;
     }
   
   evas_object_image_size_set(wd->glview_image, wd->w, wd->h);
   
   if (!wd->surface) 
     {
        Evas_Native_Surface ns;
        
        wd->surface = evas_gl_surface_create(wd->evasgl, &wd->config, 
                                             wd->w, wd->h);
        evas_gl_native_surface_get(wd->evasgl, wd->surface, &ns);
        evas_object_image_native_surface_set(wd->glview_image, &ns);
        elm_glview_changed_set(obj);
     }
}

static void
_glview_resize(void *data, Evas *e __UNUSED__, Evas_Object *obj __UNUSED__, void *event_info __UNUSED__)
{
   Widget_Data *wd = elm_widget_data_get(data);
   Evas_Coord w, h;

   if (!wd) return;
   if (wd->scale_policy == ELM_GLVIEW_RESIZE_POLICY_RECREATE) 
     {
        evas_object_geometry_get(wd->glview_image, NULL, NULL, &w, &h);
        if ((w == 0) || (h == 0))
          {
             w = 64;
             h = 64;
          }
        if ((wd->w == w) && (wd->h == h)) return;
        wd->w = w;
        wd->h = h;
        _glview_update_surface(data);
        if (wd->render_func)
          {
             evas_gl_make_current(wd->evasgl, wd->surface, wd->context);
             wd->render_func(data);
          }
     }
}


static Eina_Bool 
_render_cb(void *obj)
{
   Widget_Data *wd = elm_widget_data_get(obj);
   if (!wd) return EINA_FALSE;

   // Do a make current
   if (!evas_gl_make_current(wd->evasgl, wd->surface, wd->context))
     {
        wd->render_idle_enterer = NULL;
        return EINA_FALSE;
     }

   // Call the render function
   if (wd->render_func) wd->render_func(obj);

   // Depending on the policy return true or false
   if (wd->render_policy == ELM_GLVIEW_RENDER_POLICY_ON_DEMAND)
      return EINA_TRUE;
   else if (wd->render_policy == ELM_GLVIEW_RENDER_POLICY_ALWAYS)
     {
        // Return false so it only runs once
        wd->render_idle_enterer = NULL;
        return EINA_FALSE;
     }
   else
     {
        ERR("Invalid Render Policy.\n");
        wd->render_idle_enterer = NULL;
        return EINA_FALSE;
     }
   return EINA_TRUE;
}

static void
_set_render_policy_callback(Evas_Object *obj)
{
   Widget_Data *wd = elm_widget_data_get(obj);

   switch (wd->render_policy)
     {
      case ELM_GLVIEW_RENDER_POLICY_ON_DEMAND:
        // Delete idle_enterer if it for some reason is around
        if (wd->render_idle_enterer)
          {
             ecore_idle_enterer_del(wd->render_idle_enterer);
             wd->render_idle_enterer = NULL;
          }
        
        // Set pixel getter callback
        evas_object_image_pixels_get_callback_set
           (wd->glview_image, (Evas_Object_Image_Pixels_Get_Cb)_render_cb, obj);
        break;
      case ELM_GLVIEW_RENDER_POLICY_ALWAYS:
        
        // Unset the pixel getter callback if set already
        evas_object_image_pixels_get_callback_set(wd->glview_image, NULL, NULL);
        break;
      default:
        ERR("Invalid Render Policy.\n");
        return;
     }
}



/**
 * Add a new glview to the parent
 *
 * @param parent The parent object
 * @return The new object or NULL if it cannot be created
 *
 * @ingroup GLView
 */
EAPI Evas_Object *
elm_glview_add(Evas_Object *parent)
{
   Evas_Object *obj;
   Evas *e;
   Widget_Data *wd;
   Evas_GL_Config cfg = { EVAS_GL_RGB_8, 
                          EVAS_GL_DEPTH_NONE, 
                          EVAS_GL_STENCIL_NONE };

   ELM_WIDGET_STANDARD_SETUP(wd, Widget_Data, parent, e, obj, NULL);

   ELM_SET_WIDTYPE(widtype, "glview");
   elm_widget_type_set(obj, "glview");
   elm_widget_sub_object_add(parent, obj);
   elm_widget_on_focus_hook_set(obj, _on_focus_hook, NULL);
   elm_widget_data_set(obj, wd);
   elm_widget_del_hook_set(obj, _del_hook);

   // Evas_GL
   wd->evasgl = evas_gl_new(e);
   if (!wd->evasgl)
     {
        ERR("Failed Creating an Evas GL Object.\n");
        return NULL;
     }

   // Create image to render Evas_GL Surface
   wd->glview_image = evas_object_image_filled_add(e);
   evas_object_image_size_set(wd->glview_image, 1, 1);
   evas_object_event_callback_add(wd->glview_image, EVAS_CALLBACK_RESIZE,
                                  _glview_resize, obj);
   elm_widget_resize_object_set(obj, wd->glview_image);
   evas_object_show(wd->glview_image);

   // Initialize variables
   wd->mode          = 0;
   wd->scale_policy  = ELM_GLVIEW_RESIZE_POLICY_RECREATE;
   wd->render_policy = ELM_GLVIEW_RENDER_POLICY_ON_DEMAND;
   wd->config        = cfg;
   wd->surface       = NULL;

   wd->w             = 64;
   wd->h             = 64;

   wd->render_idle_enterer = NULL;

   // Create Context 
   if (!wd->context)
     {
        wd->context = evas_gl_context_create(wd->evasgl, NULL);
        if (!wd->context)
          {
             ERR("Error Creating an Evas_GL Context.\n");
             return NULL;
          }
     }

   return obj;

}

/**
 * Gets the gl api struct for gl rendering
 *
 * @param obj The glview object
 * @return The api object or NULL if it cannot be created
 *
 * @ingroup GLView
 */
EAPI Evas_GL_API *
elm_glview_gl_api_get(Evas_Object *obj)
{
   ELM_CHECK_WIDTYPE(obj, widtype) NULL;
   Widget_Data *wd = elm_widget_data_get(obj);

   if (!wd) return NULL;

   return evas_gl_api_get(wd->evasgl);
}


/**
 * Set the mode of the GLView. Supports Three simple modes. 
 *
 * @param obj The glview object
 * @param mode The mode Options OR'ed enabling Alpha, Depth, Stencil. 
 * @return True if set properly.
 *
 * @ingroup GLView
 */
EAPI Eina_Bool
elm_glview_mode_set(Evas_Object *obj, Elm_GLView_Mode mode)
{
   ELM_CHECK_WIDTYPE(obj, widtype) EINA_FALSE;
   Widget_Data *wd = elm_widget_data_get(obj);
   Evas_GL_Config cfg = { EVAS_GL_RGBA_8, 
                          EVAS_GL_DEPTH_NONE, 
                          EVAS_GL_STENCIL_NONE };
   if (!wd) return EINA_FALSE;

   // Set the configs
   if (mode & ELM_GLVIEW_ALPHA)
      cfg.color_format = EVAS_GL_RGBA_8;

   if (mode & ELM_GLVIEW_DEPTH)
      cfg.depth_bits = EVAS_GL_DEPTH_BIT_24;

   if (mode & ELM_GLVIEW_STENCIL)
      cfg.stencil_bits = EVAS_GL_STENCIL_BIT_8;

   // Check for Alpha Channel and enable it
   if (mode & ELM_GLVIEW_ALPHA)
      evas_object_image_alpha_set(wd->glview_image, EINA_TRUE);
   else 
      evas_object_image_alpha_set(wd->glview_image, EINA_FALSE);
   
   wd->mode   = mode;
   wd->config = cfg;
   
   elm_glview_changed_set(obj);

   return EINA_TRUE;
}

/**
 * Set the scaling policy for the glview object.
 *
 * @param obj The glview object.
 * @param policy The scaling policy.
 *
 * By default, the scaling policy is set to ELM_GLVIEW_RESIZE_POLICY_RECREATE.
 * When resize is called it destroys the previous surface and recreates the newly
 * specified size. If the policy is set to ELM_GLVIEW_RESIZE_POLICY_SCALE, however, 
 * glview only scales the image object and not the underlying GL Surface.
 * 
 * @ingroup GLView
 */
EAPI Eina_Bool
elm_glview_scale_policy_set(Evas_Object *obj, Elm_GLView_Resize_Policy policy)
{
   ELM_CHECK_WIDTYPE(obj, widtype) EINA_FALSE;
   Widget_Data *wd = elm_widget_data_get(obj);
   if (!wd) return EINA_FALSE;

   if (policy == wd->scale_policy) return EINA_TRUE;
   switch (policy)
     {
      case ELM_GLVIEW_RESIZE_POLICY_RECREATE:
      case ELM_GLVIEW_RESIZE_POLICY_SCALE:
        wd->scale_policy = policy;
        return EINA_TRUE;
      default:
        ERR("Invalid Scale Policy.\n");
        return EINA_FALSE;
     }
   _glview_update_surface(obj);
   elm_glview_changed_set(obj);
}

/**
 * Set the render policy for the glview object.
 *
 * @param obj The glview object.
 * @param policy The render policy.
 *
 * By default, the render policy is set to ELM_GLVIEW_RENDER_POLICY_ON_DEMAND.
 * This policy is set such that during the render loop, glview is only redrawn
 * if it needs to be redrawn. (i.e. When it is visible) If the policy is set
 * to ELM_GLVIEWW_RENDER_POLICY_ALWAYS, it redraws regardless of whether it is 
 * visible/need redrawing or not.
 * 
 * @ingroup GLView
 */
EAPI Eina_Bool
elm_glview_render_policy_set(Evas_Object *obj, Elm_GLView_Render_Policy policy)
{
   ELM_CHECK_WIDTYPE(obj, widtype) EINA_FALSE;
   Widget_Data *wd = elm_widget_data_get(obj);
   if (!wd) return EINA_FALSE;

   if ((policy != ELM_GLVIEW_RENDER_POLICY_ON_DEMAND) && 
       (policy != ELM_GLVIEW_RENDER_POLICY_ALWAYS))
     {
        ERR("Invalid Render Policy.\n");
        return EINA_FALSE;
     }
   if (wd->render_policy == policy) return EINA_TRUE;
   wd->render_policy = policy;
   _set_render_policy_callback(obj);
   _glview_update_surface(obj);
   return EINA_TRUE;
}

/**
 * Sets the size of the glview
 *
 * @param obj The glview object
 * @param width width of the glview object
 * @param height height of the glview object
 *
 * @ingroup GLView
 */
EAPI void
elm_glview_size_set(Evas_Object *obj, int width, int height)
{
   ELM_CHECK_WIDTYPE(obj, widtype);
   Widget_Data *wd = elm_widget_data_get(obj);
   if (!wd) return;
   
   if ((width == wd->w) && (height == wd->h)) return;
   wd->w = width;
   wd->h = height;
   _glview_update_surface(obj);
   elm_glview_changed_set(obj);
}

/**
 * Gets the size of the glview.
 *
 * @param obj The glview object
 * @param width width of the glview object
 * @param height height of the glview object
 *
 * Note that this function returns the actual image size of the glview.
 * This means that when the scale policy is set to ELM_GLVIEW_RESIZE_POLICY_SCALE,
 * it'll return the non-scaled size.
 *
 * @ingroup GLView
 */
EAPI void
elm_glview_size_get(Evas_Object *obj, int *width, int *height)
{
   ELM_CHECK_WIDTYPE(obj, widtype);
   Widget_Data *wd = elm_widget_data_get(obj);
   if (!wd) return;
   
   if (width) *width = wd->w;
   if (height) *height = wd->h;
}

/**
 * Set the render function that runs in the main loop.
 *
 * @param obj The glview object.
 * @param func The render function to be registered.
 *
 * @ingroup GLView
 */
EAPI void
elm_glview_render_func_set(Evas_Object *obj, Elm_GLView_Func func)
{
   ELM_CHECK_WIDTYPE(obj, widtype);
   Widget_Data *wd = elm_widget_data_get(obj);
   if (!wd) return;

   wd->render_func = func;

   _set_render_policy_callback(obj);
}


/**
 * Notifies that there has been changes in the GLView.
 *
 * @param obj The glview object.
 *
 * @ingroup GLView
 */
EAPI void
elm_glview_changed_set(Evas_Object *obj)
{
   ELM_CHECK_WIDTYPE(obj, widtype);
   Widget_Data *wd = elm_widget_data_get(obj);

   if (!wd) return;

   evas_object_image_pixels_dirty_set(wd->glview_image, EINA_TRUE);

   if (wd->render_policy == ELM_GLVIEW_RENDER_POLICY_ALWAYS)
     {
        if (!wd->render_idle_enterer)

           wd->render_idle_enterer = ecore_idle_enterer_before_add((Ecore_Task_Cb)_render_cb, obj);
     }

}

/* vim:set ts=8 sw=3 sts=3 expandtab cino=>5n-2f0^-2{2(0W1st0 :*/
#include <Elementary.h>
#ifdef HAVE_CONFIG_H
# include "elementary_config.h"
#endif
#ifndef ELM_LIB_QUICKLAUNCH

static void
_draw_gl(Evas_Object *obj)
{
   int w, h;
   int r, g, b, a;
   Evas_GL_API *api = elm_glview_gl_api_get(obj);
   
   elm_glview_size_get(obj, &w, &h);
   printf("%ix%i\n", w, h);
   r = rand() & 0xff;
   g = rand() & 0xff;
   b = rand() & 0xff;
   a = rand() & 0xff;
   api->glClearColor(r / 255.0, g / 255.0, b / 255.0, a / 255.0);
   api->glClear(GL_COLOR_BUFFER_BIT | GL_DEPTH_BUFFER_BIT);
}

static Eina_Bool
_anim(void *data)
{
   elm_glview_changed_set(data);
   return EINA_TRUE;
}

static void
_del(void *data __UNUSED__, Evas *evas __UNUSED__, Evas_Object *obj, void *event_info __UNUSED__)
{
   Ecore_Animator *ani = evas_object_data_get(obj, "ani");
   ecore_animator_del(ani);
}
     
void
test_glview(void *data __UNUSED__, Evas_Object *obj __UNUSED__, void *event_info __UNUSED__)
{
   Evas_Object *win, *bg, *bx, *bt, *gl;
   Ecore_Animator *ani;
   
   win = elm_win_add(NULL, "glview", ELM_WIN_BASIC);
   elm_win_title_set(win, "GLView");
   elm_win_autodel_set(win, 1);

   bg = elm_bg_add(win);
   elm_win_resize_object_add(win, bg);
   evas_object_size_hint_weight_set(bg, EVAS_HINT_EXPAND, EVAS_HINT_EXPAND);
   evas_object_show(bg);

   bx = elm_box_add(win);
   evas_object_size_hint_weight_set(bx, EVAS_HINT_EXPAND, EVAS_HINT_EXPAND);
   elm_win_resize_object_add(win, bx);
   evas_object_show(bx);
   
   gl = elm_glview_add(win);
   evas_object_size_hint_align_set(gl, EVAS_HINT_FILL, EVAS_HINT_FILL);
   evas_object_size_hint_weight_set(gl, EVAS_HINT_EXPAND, EVAS_HINT_EXPAND);
   elm_glview_mode_set(gl, ELM_GLVIEW_ALPHA | ELM_GLVIEW_DEPTH);
//   elm_glview_scale_policy_set(gl, ELM_GLVIEW_RESIZE_POLICY_SCALE);
//   elm_glview_size_set(gl, 256, 256);
   elm_glview_scale_policy_set(gl, ELM_GLVIEW_RESIZE_POLICY_RECREATE);
   elm_glview_render_policy_set(gl, ELM_GLVIEW_RENDER_POLICY_ALWAYS);
   elm_glview_render_func_set(gl, _draw_gl);
   elm_box_pack_end(bx, gl);
   evas_object_show(gl);
   
   ani = ecore_animator_add(_anim, gl);
   evas_object_data_set(gl, "ani", ani);
   evas_object_event_callback_add(gl, EVAS_CALLBACK_DEL, _del, NULL);
   
   bt = elm_button_add(win);
   elm_button_label_set(bt, "OK");
   evas_object_size_hint_align_set(bt, EVAS_HINT_FILL, EVAS_HINT_FILL);
   evas_object_size_hint_weight_set(bt, EVAS_HINT_EXPAND, 0.0);
   elm_box_pack_end(bx, bt);
   evas_object_show(bt);

   evas_object_resize(win, 320, 480);
   evas_object_show(win);
}
#endif
------------------------------------------------------------------------------
Simplify data backup and recovery for your virtual environment with vRanger. 
Installation's a snap, and flexible recovery options mean your data is safe,
secure and there when you need it. Data protection magic?
Nope - It's vRanger. Get your free trial download today. 
http://p.sf.net/sfu/quest-sfdev2dev
_______________________________________________
enlightenment-devel mailing list
enlightenment-devel@lists.sourceforge.net
https://lists.sourceforge.net/lists/listinfo/enlightenment-devel

Reply via email to