1 /* vim:set ts=8 sw=3 sts=3 expandtab cino=>5n-2f0^-2{2(0W1st0 :*/
2 #include "evas_common.h"
3 #include "evas_private.h"
15 struct _Evas_GL_Context
20 struct _Evas_GL_Surface
30 MAGIC_CHECK(e, Evas, MAGIC_EVAS);
34 evas_gl = calloc(1, sizeof(Evas_GL));
35 if (!evas_gl) return NULL;
37 evas_gl->magic = MAGIC_EVAS_GL;
40 if (!evas_gl->evas->engine.func->gl_context_create)
42 ERR("Evas GL engine not available.");
51 evas_gl_free(Evas_GL *evas_gl)
53 MAGIC_CHECK(evas_gl, Evas_GL, MAGIC_EVAS_GL);
58 // Delete undeleted surfaces
59 while (evas_gl->surfaces)
60 evas_gl_surface_destroy(evas_gl, evas_gl->surfaces->data);
62 // Delete undeleted contexts
63 while (evas_gl->contexts)
64 evas_gl_context_destroy(evas_gl, evas_gl->contexts->data);
75 cfg = calloc(1, sizeof(Evas_GL_Config));
77 if (!cfg) return NULL;
83 evas_gl_config_free(Evas_GL_Config *cfg)
88 EAPI Evas_GL_Surface *
89 evas_gl_surface_create(Evas_GL *evas_gl, Evas_GL_Config *config, int width, int height)
91 Evas_GL_Surface *surf;
93 MAGIC_CHECK(evas_gl, Evas_GL, MAGIC_EVAS_GL);
99 ERR("Invalid Config Pointer!");
103 surf = calloc(1, sizeof(Evas_GL_Surface));
105 if (!surf) return NULL;
107 surf->data = evas_gl->evas->engine.func->gl_surface_create(evas_gl->evas->engine.data.output, config, width, height);
111 ERR("Failed creating a surface from the engine.");
116 // Keep track of the surface creations
117 evas_gl->surfaces = eina_list_prepend(evas_gl->surfaces, surf);
123 evas_gl_surface_destroy(Evas_GL *evas_gl, Evas_GL_Surface *surf)
126 MAGIC_CHECK(evas_gl, Evas_GL, MAGIC_EVAS_GL);
132 ERR("Trying to destroy a NULL surface pointer!");
136 // Call Engine's Surface Destroy
137 evas_gl->evas->engine.func->gl_surface_destroy(evas_gl->evas->engine.data.output, surf->data);
139 // Remove it from the list
140 evas_gl->surfaces = eina_list_remove(evas_gl->surfaces, surf);
147 EAPI Evas_GL_Context *
148 evas_gl_context_create(Evas_GL *evas_gl, Evas_GL_Context *share_ctx)
150 Evas_GL_Context *ctx;
153 MAGIC_CHECK(evas_gl, Evas_GL, MAGIC_EVAS_GL);
157 // Allocate a context object
158 ctx = calloc(1, sizeof(Evas_GL_Context));
161 ERR("Unable to create a Evas_GL_Context object");
165 // Call engine->gl_create_context
168 ctx->data = evas_gl->evas->engine.func->gl_context_create(evas_gl->evas->engine.data.output, share_ctx->data);
172 ctx->data = evas_gl->evas->engine.func->gl_context_create(evas_gl->evas->engine.data.output, NULL);
175 // Set a few variables
178 ERR("Failed creating a context from the engine.");
183 // Keep track of the context creations
184 evas_gl->contexts = eina_list_prepend(evas_gl->contexts, ctx);
191 evas_gl_context_destroy(Evas_GL *evas_gl, Evas_GL_Context *ctx)
194 MAGIC_CHECK(evas_gl, Evas_GL, MAGIC_EVAS_GL);
200 ERR("Trying to destroy a NULL context pointer!");
204 // Call Engine's destroy
205 evas_gl->evas->engine.func->gl_context_destroy(evas_gl->evas->engine.data.output, ctx->data);
207 // Remove it from the list
208 evas_gl->contexts = eina_list_remove(evas_gl->contexts, ctx);
216 evas_gl_make_current(Evas_GL *evas_gl, Evas_GL_Surface *surf, Evas_GL_Context *ctx)
220 MAGIC_CHECK(evas_gl, Evas_GL, MAGIC_EVAS_GL);
224 if ((!surf) || (!ctx))
225 ret = (Eina_Bool)evas_gl->evas->engine.func->gl_make_current(evas_gl->evas->engine.data.output, NULL, NULL);
227 ret = (Eina_Bool)evas_gl->evas->engine.func->gl_make_current(evas_gl->evas->engine.data.output, surf->data, ctx->data);
233 evas_gl_string_query(Evas_GL *evas_gl, int name)
235 MAGIC_CHECK(evas_gl, Evas_GL, MAGIC_EVAS_GL);
239 return (const char *)evas_gl->evas->engine.func->gl_string_query(evas_gl->evas->engine.data.output, name);
243 evas_gl_proc_address_get(Evas_GL *evas_gl, const char *name)
245 MAGIC_CHECK(evas_gl, Evas_GL, MAGIC_EVAS_GL);
249 return (Evas_GL_Func)evas_gl->evas->engine.func->gl_proc_address_get(evas_gl->evas->engine.data.output, name);
253 evas_gl_native_surface_get(Evas_GL *evas_gl, Evas_GL_Surface *surf, Evas_Native_Surface *ns)
255 MAGIC_CHECK(evas_gl, Evas_GL, MAGIC_EVAS_GL);
259 if ((!surf) || (!ns))
261 ERR("Invalid input parameters!");
265 return (Eina_Bool)evas_gl->evas->engine.func->gl_native_surface_get(evas_gl->evas->engine.data.output, surf->data, ns);
270 evas_gl_api_get(Evas_GL *evas_gl)
272 MAGIC_CHECK(evas_gl, Evas_GL, MAGIC_EVAS_GL);
276 return (Evas_GL_API*)evas_gl->evas->engine.func->gl_api_get(evas_gl->evas->engine.data.output);