Functions that are used to do OpenGL rendering on Evas. More...
Data Structures | |
struct | _Evas_GL_Config |
Evas GL Surface configuration. More... | |
Typedefs | |
typedef struct _Evas_GL | Evas_GL |
Evas GL Object for rendering gl in Evas. | |
typedef struct _Evas_GL_Surface | Evas_GL_Surface |
Evas GL Surface object, a GL rendering target in Evas GL. | |
typedef struct _Evas_GL_Context | Evas_GL_Context |
Evas GL Context object, a GL rendering context in Evas GL. | |
typedef struct _Evas_GL_Config | Evas_GL_Config |
Evas GL Surface configuration object for surface creation. | |
typedef struct _Evas_GL_API | Evas_GL_API |
Evas GL API object that contains the GL APIs to be used in Evas GL. | |
typedef void * | Evas_GL_Func |
Evas GL Function Object used as a function pointer. | |
typedef void * | EvasGLImage |
Evas GL Image Object used in Evas GL Image extension. | |
typedef enum _Evas_GL_Color_Format | Evas_GL_Color_Format |
Surface Color Format. | |
typedef enum _Evas_GL_Depth_Bits | Evas_GL_Depth_Bits |
Surface Depth Format. | |
typedef enum _Evas_GL_Stencil_Bits | Evas_GL_Stencil_Bits |
Surface Stencil Format. | |
typedef enum _Evas_GL_Options_Bits | Evas_GL_Options_Bits |
Configuration Options. | |
typedef enum _Evas_GL_Multisample_Bits | Evas_GL_Multisample_Bits |
Configuration Option for Multisample Anti-aliased (MSAA) rendering surface. | |
Enumerations | |
enum | _Evas_GL_Color_Format |
Surface Color Format. | |
enum | _Evas_GL_Depth_Bits |
Surface Depth Format. | |
enum | _Evas_GL_Stencil_Bits |
Surface Stencil Format. | |
enum | _Evas_GL_Options_Bits { EVAS_GL_OPTIONS_NONE = 0, EVAS_GL_OPTIONS_DIRECT = (1<<0) } |
Configuration Options. More... | |
enum | _Evas_GL_Multisample_Bits { EVAS_GL_MULTISAMPLE_NONE = 0, EVAS_GL_MULTISAMPLE_LOW = 1, EVAS_GL_MULTISAMPLE_MED = 2, EVAS_GL_MULTISAMPLE_HIGH = 3 } |
Configuration Option for Multisample Anti-aliased (MSAA) rendering surface. More... | |
Functions | |
Evas_GL * | evas_gl_new (Evas *e) |
Creates a new Evas_GL object and returns a handle for gl rendering on efl. | |
void | evas_gl_free (Evas_GL *evas_gl) |
Frees the created Evas_GL object. | |
Evas_GL_Config * | evas_gl_config_new (void) |
Allocates a new config object for the user to fill out. | |
void | evas_gl_config_free (Evas_GL_Config *cfg) |
Frees a config object created from evas_gl_config_new. | |
Evas_GL_Surface * | evas_gl_surface_create (Evas_GL *evas_gl, Evas_GL_Config *cfg, int w, int h) |
Creates and returns new Evas_GL_Surface object for GL Rendering. | |
void | evas_gl_surface_destroy (Evas_GL *evas_gl, Evas_GL_Surface *surf) |
Destroys the created Evas GL Surface. | |
Evas_GL_Context * | evas_gl_context_create (Evas_GL *evas_gl, Evas_GL_Context *share_ctx) |
Creates and returns a new Evas GL context object. | |
void | evas_gl_context_destroy (Evas_GL *evas_gl, Evas_GL_Context *ctx) |
Destroys the given Evas GL context object. | |
Eina_Bool | evas_gl_make_current (Evas_GL *evas_gl, Evas_GL_Surface *surf, Evas_GL_Context *ctx) |
Sets the given context as a current context for the given surface. | |
const char * | evas_gl_string_query (Evas_GL *evas_gl, int name) EINA_PURE |
Returns a pointer to a static, zero-terminated string describing some aspect of evas_gl. | |
Evas_GL_Func | evas_gl_proc_address_get (Evas_GL *evas_gl, const char *name) EINA_PURE |
Returns a GL or the Glue Layer's extension function. | |
Eina_Bool | evas_gl_native_surface_get (Evas_GL *evas_gl, Evas_GL_Surface *surf, Evas_Native_Surface *ns) |
Fills in the Native Surface information from the given Evas GL surface. | |
Evas_GL_API * | evas_gl_api_get (Evas_GL *evas_gl) |
Get the API for rendering using OpenGL. |
Detailed Description
Functions that are used to do OpenGL rendering on Evas.
Evas allows you to use OpenGL to render to specially set up image objects (which act as render target surfaces).
Below is an illlustrative example of how to use OpenGL to render to an object in Evas.
// Simple Evas_GL example #include <Ecore_Evas.h> #include <Ecore.h> #include <Evas_GL.h> #include <stdio.h> // GL related data here.. typedef struct _GLData { Evas_GL_Context *ctx; Evas_GL_Surface *sfc; Evas_GL_Config *cfg; Evas_GL *evasgl; Evas_GL_API *glapi; GLuint program; GLuint vtx_shader; GLuint fgmt_shader; Eina_Bool initialized : 1; } GLData; // callbacks we want to handle deletion on the object and updates/draws static void on_del (void *data, Evas *e, Evas_Object *obj, void *event_info); static void on_pixels (void *data, Evas_Object *obj); // demo - animator just to keep ticking over saying to draw the image static Eina_Bool on_animate (void *data); // gl stuff static int init_shaders (GLData *gld); static GLuint load_shader (GLData *gld, GLenum type, const char *shader_src); int main(int argc, char **argv) { // a size by default int w = 256, h = 256; // some variables we will use Ecore_Evas *ee; Evas *canvas; Evas_Object *r1; Evas_Native_Surface ns; GLData *gld = NULL; // regular low-leve EFL (ecore+ecore-evas) init. elm is simpler ecore_init(); ecore_evas_init(); ee = ecore_evas_gl_x11_new(NULL, 0, 0, 0, 512, 512); ecore_evas_title_set(ee, "Ecore_Evas Template"); canvas = ecore_evas_get(ee); // alloc a data struct to hold our relevant gl info in if (!(gld = calloc(1, sizeof(GLData)))) return 0; //-//-//-// THIS IS WHERE GL INIT STUFF HAPPENS (ALA EGL) //-// // get the evas gl handle for doing gl things gld->evasgl = evas_gl_new(canvas); gld->glapi = evas_gl_api_get(gld->evasgl); // Set a surface config gld->cfg = evas_gl_config_new(); gld->cfg->color_format = EVAS_GL_RGBA_8888; //gld->cfg->depth_bits = EVAS_GL_DEPTH_NONE; // Othe config options //gld->cfg->stencil_bits = EVAS_GL_STENCIL_NONE; //gld->cfg->options_bits = EVAS_GL_OPTIONS_NONE; // create a surface and context gld->sfc = evas_gl_surface_create(gld->evasgl, gld->cfg, w, h); gld->ctx = evas_gl_context_create(gld->evasgl, NULL); //-// //-//-//-// END GL INIT BLOB // set up the image object. a filled one by default r1 = evas_object_image_filled_add(canvas); // attach important data we need to the object using key names. this just // avoids some global variables and means we can do nice cleanup. you can // avoid this if you are lazy evas_object_data_set(r1, "..gld", gld); // when the object is deleted - call the on_del callback. like the above, // this is just being clean evas_object_event_callback_add(r1, EVAS_CALLBACK_DEL, on_del, NULL); // set up an actual pixel size fot the buffer data. it may be different // to the output size. any windowing system has something like this, just // evas has 2 sizes, a pixel size and the output object size evas_object_image_size_set(r1, w, h); // set up the native surface info to use the context and surface created // above //-//-//-// THIS IS WHERE GL INIT STUFF HAPPENS (ALA EGL) //-// evas_gl_native_surface_get(gld->evasgl, gld->sfc, &ns); evas_object_image_native_surface_set(r1, &ns); evas_object_image_pixels_get_callback_set(r1, on_pixels, r1); //-// //-//-//-// END GL INIT BLOB // move the image object somewhere, resize it and show it. any windowing // system would need this kind of thing - place a child "window" evas_object_move(r1, 128, 128); evas_object_resize(r1, w, h); evas_object_show(r1); // animating - just a demo. as long as you trigger an update on the image // object via evas_object_image_pixels_dirty_set(). any display system, // mainloop siztem etc. will have something of this kind unless it's making // you spin infinitely yourself and invent your own animation mechanism // // NOTE: if you delete r1, this animator will keep running trying to access // r1 so you'd better delete this animator with ecore_animator_del() or // structure how you do animation differently. you can also attach it like // evasgl, sfc, etc. etc. if this animator is specific to this object // only and delete it in the del handler for the obj. ecore_animator_add(on_animate, r1); // finally show the window for the world to see. windowing system generic ecore_evas_show(ee); // begin the mainloop and tick over the animator, handle events etc. // also windowing system generic ecore_main_loop_begin(); // standard EFL shutdown stuff - generic for most systems, EFL or not ecore_evas_shutdown(); ecore_shutdown(); return 0; } static void on_del(void *data, Evas *e, Evas_Object *obj, void *event_info) { // on delete of our object clean up some things that don't get auto // celeted for us as they are not intrinsically bound to the image // object as such (you could use the same context and surface across // multiple image objects and re-use the evasgl handle too multiple times. // here we bind them to 1 object only though by doing this. GLData *gld = evas_object_data_get(obj, "..gld"); if (!gld) return; Evas_GL_API *gl = gld->glapi; evas_object_data_del(obj, "..gld"); // Do a make_current before deleting all the GL stuff. evas_gl_make_current(gld->evasgl, gld->sfc, gld->ctx); gl->glDeleteShader(gld->vtx_shader); gl->glDeleteShader(gld->fgmt_shader); gl->glDeleteProgram(gld->program); evas_gl_surface_destroy(gld->evasgl, gld->sfc); evas_gl_context_destroy(gld->evasgl, gld->ctx); evas_gl_config_free(gld->cfg); evas_gl_free(gld->evasgl); free(gld); } static void on_pixels(void *data, Evas_Object *obj) { // get some variable we need from the object data keys GLData *gld = evas_object_data_get(obj, "..gld"); if (!gld) return; Evas_GL_API *gl = gld->glapi; GLfloat vVertices[] = { 0.0f, 0.5f, 0.0f, -0.5f, -0.5f, 0.0f, 0.5f, -0.5f, 0.0f }; int w, h; // get the image size in case it changed with evas_object_image_size_set() evas_object_image_size_get(obj, &w, &h); // set up the context and surface as the current one evas_gl_make_current(gld->evasgl, gld->sfc, gld->ctx); if (!gld->initialized) { if (!init_shaders(gld)) printf("Error Initializing Shaders\n"); gld->initialized = EINA_TRUE; } // GL Viewport stuff. you can avoid doing this if viewport is all the // same as last frame if you want gl->glViewport(0, 0, w, h); // Clear the buffer gl->glClearColor(1.0, 0.0, 0.0, 1); gl->glClear(GL_COLOR_BUFFER_BIT); // Draw a Triangle gl->glEnable(GL_BLEND); gl->glUseProgram(gld->program); gl->glVertexAttribPointer(0, 3, GL_FLOAT, GL_FALSE, 0, vVertices); gl->glEnableVertexAttribArray(0); gl->glDrawArrays(GL_TRIANGLES, 0, 3); // Optional - Flush the GL pipeline gl->glFlush(); } static Eina_Bool on_animate(void *data) { // just a demo - animate here whenever an animation tick happens and then // mark the image as "dirty" meaning it needs an update next time evas // renders. it will call the pixel get callback then. evas_object_image_pixels_dirty_set(data, EINA_TRUE); return EINA_TRUE; // keep looping } static GLuint load_shader(GLData *gld, GLenum type, const char *shader_src) { Evas_GL_API *gl = gld->glapi; GLuint shader; GLint compiled = 0; // Create the shader object if (!(shader = gl->glCreateShader(type))) return 0; gl->glShaderSource(shader, 1, &shader_src, NULL); // Compile the shader gl->glCompileShader(shader); gl->glGetShaderiv(shader, GL_COMPILE_STATUS, &compiled); if (!compiled) { GLint len = 0; gl->glGetShaderiv(shader, GL_INFO_LOG_LENGTH, &len); if (len > 1) { char *info = malloc(sizeof(char) * len); if (info) { gl->glGetShaderInfoLog(shader, len, NULL, info); printf("Error compiling shader:\n" "%s\n", info); free(info); } } gl->glDeleteShader(shader); return 0; } return shader; } // Initialize the shader and program object static int init_shaders(GLData *gld) { Evas_GL_API *gl = gld->glapi; const char vShaderStr[] = "attribute vec4 vPosition; \n" "void main() \n" "{ \n" " gl_Position = vPosition; \n" "} \n"; const char fShaderStr[] = "precision mediump float; \n" "void main() \n" "{ \n" " gl_FragColor = vec4( 1.0, 0.0, 0.0, 1.0 );\n" "} \n"; GLint linked = 0; // Load the vertex/fragment shaders gld->vtx_shader = load_shader(gld, GL_VERTEX_SHADER, vShaderStr); gld->fgmt_shader = load_shader(gld, GL_FRAGMENT_SHADER, fShaderStr); // Create the program object if (!(gld->program = gl->glCreateProgram())) return 0; gl->glAttachShader(gld->program, gld->vtx_shader); gl->glAttachShader(gld->program, gld->fgmt_shader); // Bind vPosition to attribute 0 gl->glBindAttribLocation(gld->program, 0, "vPosition"); // Link the program gl->glLinkProgram(gld->program); gl->glGetProgramiv(gld->program, GL_LINK_STATUS, &linked); if (!linked) { GLint len = 0; gl->glGetProgramiv(gld->program, GL_INFO_LOG_LENGTH, &len); if (len > 1) { char *info = malloc(sizeof(char) * len); if (info) { gl->glGetProgramInfoLog(gld->program, len, NULL, info); printf("Error linking program:\n" "%s\n", info); free(info); } } gl->glDeleteProgram(gld->program); return 0; } return 1; }
Typedef Documentation
typedef enum _Evas_GL_Multisample_Bits Evas_GL_Multisample_Bits |
Configuration Option for Multisample Anti-aliased (MSAA) rendering surface.
Only works in supported device.
- Since:
- 1.2
typedef enum _Evas_GL_Options_Bits Evas_GL_Options_Bits |
Configuration Options.
- Since:
- 1.1
Enumeration Type Documentation
Configuration Option for Multisample Anti-aliased (MSAA) rendering surface.
Only works in supported device.
- Since:
- 1.2
Function Documentation
Evas_GL_API* evas_gl_api_get | ( | Evas_GL * | evas_gl | ) |
Get the API for rendering using OpenGL.
- Parameters:
-
evas_gl The given Eva_GL object.
- Returns:
- The API to use.
This returns a structure that contains all the OpenGL functions you can use to render in Evas. These functions consist of all the standard OpenGL-ES2.0 functions and any extra ones Evas has decided to provide in addition. This means that if you have your code ported to OpenGL-ES2.0, it will be easy to render to Evas.
void evas_gl_config_free | ( | Evas_GL_Config * | cfg | ) |
Frees a config object created from evas_gl_config_new.
As long as the Evas creates a config object for the user, it takes care of the backward compatibility issue.
Evas_GL_Config* evas_gl_config_new | ( | void | ) |
Allocates a new config object for the user to fill out.
As long as the Evas creates a config object for the user, it takes care of the backward compatibility issue.
Evas_GL_Context* evas_gl_context_create | ( | Evas_GL * | evas_gl, |
Evas_GL_Context * | share_ctx | ||
) |
Creates and returns a new Evas GL context object.
- Parameters:
-
evas_gl The given Evas_GL object.
- Returns:
- The created context, or NULL on failure.
void evas_gl_context_destroy | ( | Evas_GL * | evas_gl, |
Evas_GL_Context * | ctx | ||
) |
Destroys the given Evas GL context object.
- Parameters:
-
evas_gl The given Evas_GL object. ctx The given Evas GL context.
Referenced by evas_gl_free().
void evas_gl_free | ( | Evas_GL * | evas_gl | ) |
Frees the created Evas_GL object.
- Parameters:
-
evas_gl The given Evas_GL object.
References evas_gl_context_destroy(), and evas_gl_surface_destroy().
Eina_Bool evas_gl_make_current | ( | Evas_GL * | evas_gl, |
Evas_GL_Surface * | surf, | ||
Evas_GL_Context * | ctx | ||
) |
Sets the given context as a current context for the given surface.
- Parameters:
-
evas_gl The given Evas_GL object. surf The given Evas GL surface. ctx The given Evas GL context.
- Returns:
EINA_TRUE
if successful,EINA_FALSE
if not.
Eina_Bool evas_gl_native_surface_get | ( | Evas_GL * | evas_gl, |
Evas_GL_Surface * | surf, | ||
Evas_Native_Surface * | ns | ||
) |
Fills in the Native Surface information from the given Evas GL surface.
- Parameters:
-
evas_gl The given Evas_GL object. surf The given Evas GL surface to retrieve the Native Surface info from. ns The native surface structure that the function fills in.
- Returns:
EINA_TRUE
if successful,EINA_FALSE
if not.
Evas_GL* evas_gl_new | ( | Evas * | e | ) |
Creates a new Evas_GL object and returns a handle for gl rendering on efl.
- Parameters:
-
e The given evas canvas OpenGL is to be used on.
- Returns:
- The created evas_gl object, or NULl on fasilure.
Evas_GL_Func evas_gl_proc_address_get | ( | Evas_GL * | evas_gl, |
const char * | name | ||
) |
Returns a GL or the Glue Layer's extension function.
- Parameters:
-
evas_gl The given Evas_GL object. name The name of the function to return.
const char* evas_gl_string_query | ( | Evas_GL * | evas_gl, |
int | name | ||
) |
Returns a pointer to a static, zero-terminated string describing some aspect of evas_gl.
- Parameters:
-
evas_gl The given Evas_GL object. name Specifies a symbolic constant, one of EVAS_GL_EXTENSIONS...
Evas_GL_Surface* evas_gl_surface_create | ( | Evas_GL * | evas_gl, |
Evas_GL_Config * | cfg, | ||
int | w, | ||
int | h | ||
) |
Creates and returns new Evas_GL_Surface object for GL Rendering.
- Parameters:
-
evas_gl The given Evas_GL object. cfg The pixel format and configuration of the rendering surface. w The width of the surface. h The height of the surface.
- Returns:
- The created GL surface object, or NULL on failure.
void evas_gl_surface_destroy | ( | Evas_GL * | evas_gl, |
Evas_GL_Surface * | surf | ||
) |
Destroys the created Evas GL Surface.
- Parameters:
-
evas_gl The given Evas_GL object. surf The given GL surface object.
Referenced by evas_gl_free().