1 #ifndef EVAS_GL_COMMON_H
2 #define EVAS_GL_COMMON_H
4 #include "evas_common.h"
5 #include "evas_private.h"
16 #ifdef BUILD_ENGINE_GL_GLEW
19 # define GL_GLEXT_PROTOTYPES
22 #ifdef BUILD_ENGINE_GL_QUARTZ
23 # include <OpenGL/gl.h>
24 # include <OpenGL/glext.h>
26 # ifdef _EVAS_ENGINE_SDL_H
27 # if defined(GLES_VARIETY_S3C6410) || defined(GLES_VARIETY_SGX)
28 # include <SDL/SDL_opengles.h>
30 # include <SDL/SDL_opengl.h>
33 # if defined (GLES_VARIETY_S3C6410) || defined (GLES_VARIETY_SGX)
34 # if defined(GLES_VARIETY_S3C6410)
35 # include <GLES2/gl2.h>
36 # elif defined(GLES_VARIETY_SGX)
37 # include <GLES2/gl2.h>
38 # include <GLES2/gl2ext.h>
42 # include <GL/glext.h>
47 #ifndef GL_TEXTURE_RECTANGLE_NV
48 # define GL_TEXTURE_RECTANGLE_NV 0x84F5
51 # define GL_BGRA 0x80E1
54 #ifndef EGL_NO_CONTEXT
55 # define EGL_NO_CONTEXT 0
58 # define EGL_NONE 0x3038
67 #ifndef EGL_MAP_GL_TEXTURE_2D_SEC
68 # define EGL_MAP_GL_TEXTURE_2D_SEC 0x3201
70 #ifndef EGL_MAP_GL_TEXTURE_HEIGHT_SEC
71 # define EGL_MAP_GL_TEXTURE_HEIGHT_SEC 0x3202
73 #ifndef EGL_MAP_GL_TEXTURE_WIDTH_SEC
74 # define EGL_MAP_GL_TEXTURE_WIDTH_SEC 0x3203
76 #ifndef EGL_MAP_GL_TEXTURE_FORMAT_SEC
77 # define EGL_MAP_GL_TEXTURE_FORMAT_SEC 0x3204
79 #ifndef EGL_MAP_GL_TEXTURE_RGB_SEC
80 # define EGL_MAP_GL_TEXTURE_RGB_SEC 0x3205
82 #ifndef EGL_MAP_GL_TEXTURE_RGBA_SEC
83 # define EGL_MAP_GL_TEXTURE_RGBA_SEC 0x3206
85 #ifndef EGL_MAP_GL_TEXTURE_PIXEL_TYPE_SEC
86 # define EGL_MAP_GL_TEXTURE_PIXEL_TYPE_SEC 0x3206
88 #ifndef EGL_MAP_GL_TEXTURE_UNSIGNED_BYTE_SEC
89 # define EGL_MAP_GL_TEXTURE_UNSIGNED_BYTE_SEC 0x3207
91 #ifndef EGL_MAP_GL_TEXTURE_STRIDE_IN_BYTES_SEC
92 # define EGL_MAP_GL_TEXTURE_STRIDE_IN_BYTES_SEC 0x3208
101 typedef struct _Evas_GL_Program Evas_GL_Program;
102 typedef struct _Evas_GL_Program_Source Evas_GL_Program_Source;
103 typedef struct _Evas_GL_Shared Evas_GL_Shared;
104 typedef struct _Evas_GL_Context Evas_GL_Context;
105 typedef struct _Evas_GL_Texture_Pool Evas_GL_Texture_Pool;
106 typedef struct _Evas_GL_Texture Evas_GL_Texture;
107 typedef struct _Evas_GL_Image Evas_GL_Image;
108 typedef struct _Evas_GL_Font_Texture Evas_GL_Font_Texture;
109 typedef struct _Evas_GL_Polygon Evas_GL_Polygon;
110 typedef struct _Evas_GL_Polygon_Point Evas_GL_Polygon_Point;
112 struct _Evas_GL_Program
114 GLuint vert, frag, prog;
117 struct _Evas_GL_Program_Source
120 const unsigned int *bin;
124 struct _Evas_GL_Shared
129 GLint max_texture_units;
130 GLint max_texture_size;
131 GLint max_vertex_elements;
135 Eina_Bool tex_npo2 : 1;
136 Eina_Bool tex_rect : 1;
137 Eina_Bool sec_image_map : 1;
138 // tuning params - per gpu/cpu combo?
139 #define MAX_CUTOUT 512
140 #define DEF_CUTOUT 512
142 // FIXME bug with pipes > 1 right now, should default to 32
143 #define MAX_PIPES 128
145 #define DEF_PIPES_SGX_540 32
146 #define DEF_PIPES_TEGRA_2 1
148 #define MIN_ATLAS_ALLOC 16
149 #define MAX_ATLAS_ALLOC 1024
150 #define DEF_ATLAS_ALLOC 1024
152 #define MIN_ATLAS_ALLOC_ALPHA 16
153 #define MAX_ATLAS_ALLOC_ALPHA 4096
154 #define DEF_ATLAS_ALLOC_ALPHA 4096
156 #define MAX_ATLAS_W 512
157 #define DEF_ATLAS_W 512
159 #define MAX_ATLAS_H 512
160 #define DEF_ATLAS_H 512
162 #define MIN_ATLAS_SLOT 16
163 #define MAX_ATLAS_SLOT 512
164 #define DEF_ATLAS_SLOT 16
175 int max_alloc_alpha_size;
185 Eina_List *atlas[33][3];
188 Eina_Hash *native_hash;
191 Evas_GL_Program rect;
192 Evas_GL_Program font;
194 Evas_GL_Program img, img_nomul;
195 Evas_GL_Program img_bgra, img_bgra_nomul;
196 Evas_GL_Program yuv, yuv_nomul;
197 Evas_GL_Program tex, tex_nomul;
209 #define RTYPE_IMAGE 2
212 #define RTYPE_MAP 5 /* need to merge with image */
216 struct _Evas_GL_Context
222 RGBA_Draw_Context *dc;
224 Evas_GL_Shared *shared;
231 GLuint cur_tex, cur_texu, cur_texv;
247 Eina_Bool active : 1;
250 Evas_GL_Image *surface;
252 GLuint cur_tex, cur_texu, cur_texv;
267 Eina_Bool use_vertex : 1;
268 Eina_Bool use_color : 1;
269 Eina_Bool use_texuv : 1;
270 Eina_Bool use_texuv2 : 1;
271 Eina_Bool use_texuv3 : 1;
280 Evas_GL_Image *def_surface;
282 #if defined (GLES_VARIETY_S3C6410) || defined (GLES_VARIETY_SGX)
283 // FIXME: hack. expose egl display to gl core for egl image sec extn.
288 struct _Evas_GL_Texture_Pool
292 GLuint intformat, format, dataformat;
302 Eina_List *allocations;
304 Eina_Bool render : 1;
305 Eina_Bool native : 1;
306 Eina_Bool dynamic : 1;
309 struct _Evas_GL_Texture
313 Evas_GL_Texture_Pool *pt, *ptu, *ptv;
315 double sx1, sy1, sx2, sy2;
321 struct _Evas_GL_Image
325 Evas_GL_Texture *tex;
326 RGBA_Image_Loadopts load_opts;
328 // if im->im == NULL, it's a render-surface so these here are used
333 unsigned char no_free : 1;
339 void (*bind) (void *data, void *image);
340 void (*unbind) (void *data, void *image);
341 void (*free) (void *data, void *image);
347 unsigned char loose : 1;
350 int scale_hint, content_hint;
352 unsigned char dirty : 1;
353 unsigned char cached : 1;
354 unsigned char alpha : 1;
355 unsigned char tex_only : 1;
358 struct _Evas_GL_Font_Texture
360 Evas_GL_Texture *tex;
363 struct _Evas_GL_Polygon
366 Eina_Bool changed : 1;
369 struct _Evas_GL_Polygon_Point
374 extern Evas_GL_Program_Source shader_rect_frag_src;
375 extern Evas_GL_Program_Source shader_rect_vert_src;
376 extern Evas_GL_Program_Source shader_font_frag_src;
377 extern Evas_GL_Program_Source shader_font_vert_src;
379 extern Evas_GL_Program_Source shader_img_frag_src;
380 extern Evas_GL_Program_Source shader_img_vert_src;
381 extern Evas_GL_Program_Source shader_img_nomul_frag_src;
382 extern Evas_GL_Program_Source shader_img_nomul_vert_src;
383 extern Evas_GL_Program_Source shader_img_bgra_frag_src;
384 extern Evas_GL_Program_Source shader_img_bgra_vert_src;
385 extern Evas_GL_Program_Source shader_img_bgra_nomul_frag_src;
386 extern Evas_GL_Program_Source shader_img_bgra_nomul_vert_src;
388 extern Evas_GL_Program_Source shader_yuv_frag_src;
389 extern Evas_GL_Program_Source shader_yuv_vert_src;
390 extern Evas_GL_Program_Source shader_yuv_nomul_frag_src;
391 extern Evas_GL_Program_Source shader_yuv_nomul_vert_src;
393 extern Evas_GL_Program_Source shader_tex_frag_src;
394 extern Evas_GL_Program_Source shader_tex_vert_src;
395 extern Evas_GL_Program_Source shader_tex_nomul_frag_src;
396 extern Evas_GL_Program_Source shader_tex_nomul_vert_src;
398 void glerr(int err, const char *file, const char *func, int line, const char *op);
400 Evas_GL_Context *evas_gl_common_context_new(void);
401 void evas_gl_common_context_free(Evas_GL_Context *gc);
402 void evas_gl_common_context_use(Evas_GL_Context *gc);
403 void evas_gl_common_context_newframe(Evas_GL_Context *gc);
404 void evas_gl_common_context_resize(Evas_GL_Context *gc, int w, int h, int rot);
405 void evas_gl_common_context_target_surface_set(Evas_GL_Context *gc, Evas_GL_Image *surface);
407 void evas_gl_common_context_line_push(Evas_GL_Context *gc,
408 int x1, int y1, int x2, int y2,
409 int clip, int cx, int cy, int cw, int ch,
410 int r, int g, int b, int a);
411 void evas_gl_common_context_rectangle_push(Evas_GL_Context *gc,
412 int x, int y, int w, int h,
413 int r, int g, int b, int a);
414 void evas_gl_common_context_image_push(Evas_GL_Context *gc,
415 Evas_GL_Texture *tex,
416 double sx, double sy, double sw, double sh,
417 int x, int y, int w, int h,
418 int r, int g, int b, int a,
419 Eina_Bool smooth, Eina_Bool tex_only);
420 void evas_gl_common_context_font_push(Evas_GL_Context *gc,
421 Evas_GL_Texture *tex,
422 double sx, double sy, double sw, double sh,
423 int x, int y, int w, int h,
424 int r, int g, int b, int a);
425 void evas_gl_common_context_yuv_push(Evas_GL_Context *gc,
426 Evas_GL_Texture *tex,
427 double sx, double sy, double sw, double sh,
428 int x, int y, int w, int h,
429 int r, int g, int b, int a,
431 void evas_gl_common_context_image_map4_push(Evas_GL_Context *gc,
432 Evas_GL_Texture *tex,
434 int clip, int cx, int cy, int cw, int ch,
435 int r, int g, int b, int a,
439 void evas_gl_common_context_flush(Evas_GL_Context *gc);
441 int evas_gl_common_shader_program_init(Evas_GL_Program *p,
442 Evas_GL_Program_Source *vert,
443 Evas_GL_Program_Source *frag,
445 void evas_gl_common_shader_program_shutdown(Evas_GL_Program *p);
447 void evas_gl_common_rect_draw(Evas_GL_Context *gc, int x, int y, int w, int h);
449 Evas_GL_Texture *evas_gl_common_texture_new(Evas_GL_Context *gc, RGBA_Image *im);
450 Evas_GL_Texture *evas_gl_common_texture_native_new(Evas_GL_Context *gc, unsigned int w, unsigned int h, int alpha, Evas_GL_Image *im);
451 Evas_GL_Texture *evas_gl_common_texture_render_new(Evas_GL_Context *gc, unsigned int w, unsigned int h, int alpha);
452 Evas_GL_Texture *evas_gl_common_texture_dynamic_new(Evas_GL_Context *gc, Evas_GL_Image *im);
453 void evas_gl_common_texture_update(Evas_GL_Texture *tex, RGBA_Image *im);
454 void evas_gl_common_texture_free(Evas_GL_Texture *tex);
455 Evas_GL_Texture *evas_gl_common_texture_alpha_new(Evas_GL_Context *gc, DATA8 *pixels, unsigned int w, unsigned int h, int fh);
456 void evas_gl_common_texture_alpha_update(Evas_GL_Texture *tex, DATA8 *pixels, unsigned int w, unsigned int h, int fh);
457 Evas_GL_Texture *evas_gl_common_texture_yuv_new(Evas_GL_Context *gc, DATA8 **rows, unsigned int w, unsigned int h);
458 void evas_gl_common_texture_yuv_update(Evas_GL_Texture *tex, DATA8 **rows, unsigned int w, unsigned int h);
460 void evas_gl_common_image_all_unload(Evas_GL_Context *gc);
462 Evas_GL_Image *evas_gl_common_image_load(Evas_GL_Context *gc, const char *file, const char *key, Evas_Image_Load_Opts *lo, int *error);
463 Evas_GL_Image *evas_gl_common_image_new_from_data(Evas_GL_Context *gc, unsigned int w, unsigned int h, DATA32 *data, int alpha, int cspace);
464 Evas_GL_Image *evas_gl_common_image_new_from_copied_data(Evas_GL_Context *gc, unsigned int w, unsigned int h, DATA32 *data, int alpha, int cspace);
465 Evas_GL_Image *evas_gl_common_image_new(Evas_GL_Context *gc, unsigned int w, unsigned int h, int alpha, int cspace);
466 Evas_GL_Image *evas_gl_common_image_alpha_set(Evas_GL_Image *im, int alpha);
467 void evas_gl_common_image_native_enable(Evas_GL_Image *im);
468 void evas_gl_common_image_native_disable(Evas_GL_Image *im);
469 void evas_gl_common_image_scale_hint_set(Evas_GL_Image *im, int hint);
470 void evas_gl_common_image_content_hint_set(Evas_GL_Image *im, int hint);
471 void evas_gl_common_image_free(Evas_GL_Image *im);
472 Evas_GL_Image *evas_gl_common_image_surface_new(Evas_GL_Context *gc, unsigned int w, unsigned int h, int alpha);
473 void evas_gl_common_image_dirty(Evas_GL_Image *im, unsigned int x, unsigned int y, unsigned int w, unsigned int h);
474 void evas_gl_common_image_map4_draw(Evas_GL_Context *gc, Evas_GL_Image *im, RGBA_Map_Point *p, int smooth, int level);
475 void evas_gl_common_image_draw(Evas_GL_Context *gc, Evas_GL_Image *im, int sx, int sy, int sw, int sh, int dx, int dy, int dw, int dh, int smooth);
477 void *evas_gl_font_texture_new(void *gc, RGBA_Font_Glyph *fg);
478 void evas_gl_font_texture_free(void *);
479 void evas_gl_font_texture_draw(void *gc, void *surface, void *dc, RGBA_Font_Glyph *fg, int x, int y);
481 Evas_GL_Polygon *evas_gl_common_poly_point_add(Evas_GL_Polygon *poly, int x, int y);
482 Evas_GL_Polygon *evas_gl_common_poly_points_clear(Evas_GL_Polygon *poly);
483 void evas_gl_common_poly_draw(Evas_GL_Context *gc, Evas_GL_Polygon *poly, int x, int y);
485 void evas_gl_common_line_draw(Evas_GL_Context *gc, int x1, int y1, int x2, int y2);
487 extern void (*glsym_glGenFramebuffers) (GLsizei a, GLuint *b);
488 extern void (*glsym_glBindFramebuffer) (GLenum a, GLuint b);
489 extern void (*glsym_glFramebufferTexture2D) (GLenum a, GLenum b, GLenum c, GLuint d, GLint e);
490 extern void (*glsym_glDeleteFramebuffers) (GLsizei a, const GLuint *b);
492 #if defined (GLES_VARIETY_S3C6410) || defined (GLES_VARIETY_SGX)
493 extern void *(*secsym_eglCreateImage) (void *a, void *b, GLenum c, void *d, const int *e);
494 extern unsigned int (*secsym_eglDestroyImage) (void *a, void *b);
495 extern void (*secsym_glEGLImageTargetTexture2DOES) (int a, void *b);
496 extern void *(*secsym_eglMapImageSEC) (void *a, void *b);
497 extern unsigned int (*secsym_eglUnmapImageSEC) (void *a, void *b);
498 extern unsigned int (*secsym_eglGetImageAttribSEC) (void *a, void *b, int c, int *d);
504 # define GLERR(fn, fl, ln, op) \
506 int __gl_err = glGetError(); \
507 if (__gl_err != GL_NO_ERROR) glerr(__gl_err, fl, fn, ln, op); \
510 # define GLERR(fn, fl, ln, op)
513 Eina_Bool evas_gl_common_module_open(void);
514 void evas_gl_common_module_close(void);