1 #include "evas_gl_private.h"
5 static int sym_done = 0;
6 int _evas_engine_GL_common_log_dom = -1;
8 typedef void (*glsym_func_void) ();
10 void (*glsym_glGenFramebuffers) (GLsizei a, GLuint *b) = NULL;
11 void (*glsym_glBindFramebuffer) (GLenum a, GLuint b) = NULL;
12 void (*glsym_glFramebufferTexture2D) (GLenum a, GLenum b, GLenum c, GLuint d, GLint e) = NULL;
13 void (*glsym_glDeleteFramebuffers) (GLsizei a, const GLuint *b) = NULL;
14 void (*glsym_glGetProgramBinary) (GLuint a, GLsizei b, GLsizei *c, GLenum *d, void *e) = NULL;
15 void (*glsym_glProgramBinary) (GLuint a, GLenum b, const void *c, GLint d) = NULL;
16 void (*glsym_glProgramParameteri) (GLuint a, GLuint b, GLint d) = NULL;
18 #if defined (GLES_VARIETY_S3C6410) || defined (GLES_VARIETY_SGX)
19 // just used for finding symbols :)
20 typedef void (*_eng_fn) (void);
22 typedef _eng_fn (*secsym_func_eng_fn) ();
23 typedef unsigned int (*secsym_func_uint) ();
24 typedef void *(*secsym_func_void_ptr) ();
26 static _eng_fn (*secsym_eglGetProcAddress) (const char *a) = NULL;
28 void *(*secsym_eglCreateImage) (void *a, void *b, GLenum c, void *d, const int *e) = NULL;
29 unsigned int (*secsym_eglDestroyImage) (void *a, void *b) = NULL;
30 void (*secsym_glEGLImageTargetTexture2DOES) (int a, void *b) = NULL;
31 void *(*secsym_eglMapImageSEC) (void *a, void *b) = NULL;
32 unsigned int (*secsym_eglUnmapImageSEC) (void *a, void *b) = NULL;
33 unsigned int (*secsym_eglGetImageAttribSEC) (void *a, void *b, int c, int *d) = NULL;
36 static int dbgflushnum = -1;
41 ERR("GL symbols missing!");
50 #ifdef _EVAS_ENGINE_SDL_H
51 # define FINDSYM(dst, sym, typ) if (!dst) dst = (typ)SDL_GL_GetProcAddress(sym)
53 # define FINDSYM(dst, sym, typ) if (!dst) dst = (typ)dlsym(RTLD_DEFAULT, sym)
55 #define FALLBAK(dst, typ) if (!dst) dst = (typ)sym_missing;
57 FINDSYM(glsym_glGenFramebuffers, "glGenFramebuffers", glsym_func_void);
58 FINDSYM(glsym_glGenFramebuffers, "glGenFramebuffersEXT", glsym_func_void);
59 FINDSYM(glsym_glGenFramebuffers, "glGenFramebuffersARB", glsym_func_void);
60 FALLBAK(glsym_glGenFramebuffers, glsym_func_void);
62 FINDSYM(glsym_glBindFramebuffer, "glBindFramebuffer", glsym_func_void);
63 FINDSYM(glsym_glBindFramebuffer, "glBindFramebufferEXT", glsym_func_void);
64 FINDSYM(glsym_glBindFramebuffer, "glBindFramebufferARB", glsym_func_void);
65 FALLBAK(glsym_glBindFramebuffer, glsym_func_void);
67 FINDSYM(glsym_glFramebufferTexture2D, "glFramebufferTexture2D", glsym_func_void);
68 FINDSYM(glsym_glFramebufferTexture2D, "glFramebufferTexture2DEXT", glsym_func_void);
69 FINDSYM(glsym_glFramebufferTexture2D, "glFramebufferTexture2DARB", glsym_func_void);
70 FALLBAK(glsym_glFramebufferTexture2D, glsym_func_void);
72 FINDSYM(glsym_glDeleteFramebuffers, "glDeleteFramebuffers", glsym_func_void);
73 FINDSYM(glsym_glDeleteFramebuffers, "glDeleteFramebuffersEXT", glsym_func_void);
74 FINDSYM(glsym_glDeleteFramebuffers, "glDeleteFramebuffersARB", glsym_func_void);
75 FALLBAK(glsym_glDeleteFramebuffers, glsym_func_void);
77 FINDSYM(glsym_glGetProgramBinary, "glGetProgramBinary", glsym_func_void);
78 FINDSYM(glsym_glGetProgramBinary, "glGetProgramBinaryEXT", glsym_func_void);
79 FINDSYM(glsym_glGetProgramBinary, "glGetProgramBinaryARB", glsym_func_void);
80 FINDSYM(glsym_glGetProgramBinary, "glGetProgramBinaryOES", glsym_func_void);
82 FINDSYM(glsym_glProgramBinary, "glProgramBinary", glsym_func_void);
83 FINDSYM(glsym_glProgramBinary, "glProgramBinaryEXT", glsym_func_void);
84 FINDSYM(glsym_glProgramBinary, "glProgramBinaryARB", glsym_func_void);
86 FINDSYM(glsym_glProgramParameteri, "glProgramParameteri", glsym_func_void);
87 FINDSYM(glsym_glProgramParameteri, "glProgramParameteriEXT", glsym_func_void);
88 FINDSYM(glsym_glProgramParameteri, "glProgramParameteriARB", glsym_func_void);
90 #if defined (GLES_VARIETY_S3C6410) || defined (GLES_VARIETY_SGX)
92 #define FINDSYM(dst, sym, typ) \
93 if ((!dst) && (secsym_eglGetProcAddress)) dst = (typ)secsym_eglGetProcAddress(sym); \
94 if (!dst) dst = (typ)dlsym(RTLD_DEFAULT, sym)
95 // yes - gl core looking for egl stuff. i know it's odd. a reverse-layer thing
96 // but it will work as the egl/glx layer calls gl core common stuff and thus
97 // these symbols will work. making the glx/egl + x11 layer do this kind-of is
98 // wrong as this is not x11 (output) layer specific like the native surface
99 // stuff. this is generic zero-copy textures for gl
101 FINDSYM(secsym_eglGetProcAddress, "eglGetProcAddress", secsym_func_eng_fn);
102 FINDSYM(secsym_eglGetProcAddress, "eglGetProcAddressEXT", secsym_func_eng_fn);
103 FINDSYM(secsym_eglGetProcAddress, "eglGetProcAddressARB", secsym_func_eng_fn);
104 FINDSYM(secsym_eglGetProcAddress, "eglGetProcAddressKHR", secsym_func_eng_fn);
106 FINDSYM(secsym_eglCreateImage, "eglCreateImage", secsym_func_void_ptr);
107 FINDSYM(secsym_eglCreateImage, "eglCreateImageEXT", secsym_func_void_ptr);
108 FINDSYM(secsym_eglCreateImage, "eglCreateImageARB", secsym_func_void_ptr);
109 FINDSYM(secsym_eglCreateImage, "eglCreateImageKHR", secsym_func_void_ptr);
111 FINDSYM(secsym_eglDestroyImage, "eglDestroyImage", secsym_func_uint);
112 FINDSYM(secsym_eglDestroyImage, "eglDestroyImageEXT", secsym_func_uint);
113 FINDSYM(secsym_eglDestroyImage, "eglDestroyImageARB", secsym_func_uint);
114 FINDSYM(secsym_eglDestroyImage, "eglDestroyImageKHR", secsym_func_uint);
116 FINDSYM(glsym_glGetProgramBinary, "glGetProgramBinary", glsym_func_void);
117 FINDSYM(glsym_glGetProgramBinary, "glGetProgramBinaryEXT", glsym_func_void);
118 FINDSYM(glsym_glGetProgramBinary, "glGetProgramBinaryARB", glsym_func_void);
119 FINDSYM(glsym_glGetProgramBinary, "glGetProgramBinaryOES", glsym_func_void);
120 FINDSYM(glsym_glGetProgramBinary, "glGetProgramBinaryKHR", glsym_func_void);
122 FINDSYM(glsym_glProgramBinary, "glProgramBinary", glsym_func_void);
123 FINDSYM(glsym_glProgramBinary, "glProgramBinaryEXT", glsym_func_void);
124 FINDSYM(glsym_glProgramBinary, "glProgramBinaryARB", glsym_func_void);
125 FINDSYM(glsym_glProgramBinary, "glProgramBinaryOES", glsym_func_void);
126 FINDSYM(glsym_glProgramBinary, "glProgramBinaryKHR", glsym_func_void);
128 FINDSYM(glsym_glProgramParameteri, "glProgramParameteri", glsym_func_void);
129 FINDSYM(glsym_glProgramParameteri, "glProgramParameteriEXT", glsym_func_void);
130 FINDSYM(glsym_glProgramParameteri, "glProgramParameteriARB", glsym_func_void);
131 FINDSYM(glsym_glProgramParameteri, "glProgramParameteriOES", glsym_func_void);
132 FINDSYM(glsym_glProgramParameteri, "glProgramParameteriKHR", glsym_func_void);
134 FINDSYM(secsym_glEGLImageTargetTexture2DOES, "glEGLImageTargetTexture2DOES", glsym_func_void);
136 FINDSYM(secsym_eglMapImageSEC, "eglMapImageSEC", secsym_func_void_ptr);
138 FINDSYM(secsym_eglUnmapImageSEC, "eglUnmapImageSEC", secsym_func_uint);
140 FINDSYM(secsym_eglGetImageAttribSEC, "eglGetImageAttribSEC", secsym_func_uint);
144 static void shader_array_flush(Evas_Engine_GL_Context *gc);
146 static Evas_Engine_GL_Context *_evas_gl_common_context = NULL;
147 static Evas_GL_Shared *shared = NULL;
150 glerr(int err, const char *file, const char *func, int line, const char *op)
157 case GL_INVALID_ENUM:
158 errmsg = "GL_INVALID_ENUM";
160 case GL_INVALID_VALUE:
161 errmsg = "GL_INVALID_VALUE";
163 case GL_INVALID_OPERATION:
164 errmsg = "GL_INVALID_OPERATION";
166 case GL_OUT_OF_MEMORY:
167 errmsg = "GL_OUT_OF_MEMORY";
170 snprintf(buf, sizeof(buf), "%#x", err);
174 eina_log_print(_evas_engine_GL_common_log_dom, EINA_LOG_LEVEL_ERR,
175 file, func, line, "%s: %s", op, errmsg);
179 matrix_ortho(GLfloat *m,
180 GLfloat l, GLfloat r,
181 GLfloat t, GLfloat b,
182 GLfloat near, GLfloat far,
183 int rot, int vw, int vh,
184 int foc, GLfloat orth)
190 rotf = (((rot / 90) & 0x3) * M_PI) / 2.0;
192 tx = -0.5 * (1.0 - orth);
193 ty = -0.5 * (1.0 - orth);
214 m[0] = (2.0 / (r - l)) * ( cosv);
215 m[1] = (2.0 / (r - l)) * ( sinv);
219 m[4] = (2.0 / (t - b)) * (-sinv);
220 m[5] = (2.0 / (t - b)) * ( cosv);
226 m[10] = -(2.0 / (far - near));
227 m[11] = 1.0 / (GLfloat)foc;
229 m[12] = (m[0] * tx) + (m[4] * ty) - ((r + l) / (r - l));
230 m[13] = (m[1] * tx) + (m[5] * ty) - ((t + b) / (t - b));
231 m[14] = (m[2] * tx) + (m[6] * ty) - ((near + far) / (far - near));
232 m[15] = (m[3] * tx) + (m[7] * ty) + orth;
236 _evas_gl_common_version_check()
245 * glGetString returns a string describing the current GL connection.
246 * GL_VERSION is used to get the version of the connection
249 version = (char *)glGetString(GL_VERSION);
256 * OpenGL ES-<profile> <major>.<minor>
258 * where <profile> is either "CM" or "CL". The minor can be followed by the vendor
259 * specific information
263 * OpenGL<space>ES<space><version number><space><vendor-specific information>
266 /* OpenGL ES 1.* ? */
268 if ((tmp = strstr(version, "OpenGL ES-CM ")) || (tmp = strstr(version, "OpenGL ES-CL ")))
274 /* OpenGL ES 2.* ? */
276 if ((tmp = strstr(version, "OpenGL ES ")))
285 * The GL_VERSION and GL_SHADING_LANGUAGE_VERSION strings begin with a
286 * version number. The version number uses one of these forms:
288 * major_number.minor_number
289 * major_number.minor_number.release_number
291 * Vendor-specific information may follow the version number. Its format
292 * depends on the implementation, but a space always separates the
293 * version number and the vendor-specific information.
296 /* glGetString() returns a static string, and we are going to */
297 /* modify it, so we get a copy first */
298 version = strdup(version);
302 tmp = strchr(version, '.');
303 /* the first '.' always exists */
305 major = atoi(version);
306 /* FIXME: maybe we can assume that minor in only a cipher */
308 while ((*tmp != '.') && (*tmp != ' ') && (*tmp != '\0'))
310 /* *tmp is '\0' : version is major_number.minor_number */
311 /* *tmp is '.' : version is major_number.minor_number.release_number */
312 /* *tmp is ' ' : version is major_number.minor_number followed by vendor */
317 if (((major == 1) && (minor >= 4)) || (major >= 2))
324 _evas_gl_common_viewport_set(Evas_Engine_GL_Context *gc)
328 int w = 1, h = 1, m = 1, rot = 1, foc = 0;
330 EINA_SAFETY_ON_NULL_RETURN(gc);
332 // surface in pipe 0 will be the same as all pipes
333 if ((gc->pipe[0].shader.surface == gc->def_surface) ||
334 (!gc->pipe[0].shader.surface))
342 w = gc->pipe[0].shader.surface->w;
343 h = gc->pipe[0].shader.surface->h;
348 if ((!gc->change.size) ||
349 ((gc->shared->w == w) && (gc->shared->h == h) &&
350 (gc->shared->rot == rot) && (gc->shared->foc == gc->foc) &&
351 (gc->shared->mflip == m)))
356 gc->shared->rot = rot;
357 gc->shared->mflip = m;
358 gc->shared->foc = foc;
359 gc->shared->z0 = gc->z0;
360 gc->shared->px = gc->px;
361 gc->shared->py = gc->py;
366 if ((rot == 0) || (rot == 180))
367 glViewport(0, 0, w, h);
369 glViewport(0, 0, h, w);
370 GLERR(__FUNCTION__, __FILE__, __LINE__, "");
375 -1000000.0, 1000000.0,
378 // v flipped matrix for render-to-texture
382 -1000000.0, 1000000.0,
388 int px, py, vx, vy, vw = 0, vh = 0, ax = 0, ay = 0, ppx = 0, ppy = 0;
393 if ((rot == 0 ) || (rot == 90 )) ppx = px;
394 else if ((rot == 180) || (rot == 270)) ppx = w - px;
395 if ((rot == 0 ) || (rot == 270)) ppy = py;
396 else if ((rot == 90 ) || (rot == 180)) ppy = h - py;
398 vx = ((w / 2) - ppx);
402 if ((rot == 0 ) || (rot == 90 )) ax = 2 * vx;
403 else if ((rot == 180) || (rot == 270)) ax = 0;
408 if ((rot == 0 ) || (rot == 90 )) ax = 0;
409 else if ((rot == 180) || (rot == 270)) ax = ppx - px;
413 vy = ((h / 2) - ppy);
417 if ((rot == 0 )) ay = 0;
418 else if ((rot == 90 ) || (rot == 180) || (rot == 270)) ay = ppy - py;
424 if ((rot == 0 ) || (rot == 270)) ay = 2 * vy;
425 else if ((rot == 90 ) || (rot == 180)) ay = 0;
429 if (m == -1) ay = vy * 2;
431 if ((rot == 0) || (rot == 180))
432 glViewport(-2 * vx, -2 * vy, vw, vh);
434 glViewport(-2 * vy, -2 * vx, vh, vw);
436 matrix_ortho(proj, 0, vw, 0, vh,
437 -1000000.0, 1000000.0,
441 matrix_ortho(proj, 0, vw, vh, 0,
442 -1000000.0, 1000000.0,
449 for (i = 0; i < SHADER_LAST; ++i)
451 glUseProgram(gc->shared->shader[i].prog);
452 GLERR(__FUNCTION__, __FILE__, __LINE__, "");
453 glUniformMatrix4fv(glGetUniformLocation(gc->shared->shader[i].prog, "mvp"), 1, GL_FALSE, proj);
454 GLERR(__FUNCTION__, __FILE__, __LINE__, "");
457 glUseProgram(gc->state.current.cur_prog);
458 GLERR(__FUNCTION__, __FILE__, __LINE__, "");
461 Evas_Engine_GL_Context *
462 evas_gl_common_context_new(void)
464 Evas_Engine_GL_Context *gc;
469 if (_evas_gl_common_context)
471 _evas_gl_common_context->references++;
472 return _evas_gl_common_context;
475 if (!_evas_gl_common_version_check())
477 gc = calloc(1, sizeof(Evas_Engine_GL_Context));
478 if (!gc) return NULL;
484 _evas_gl_common_context = gc;
486 for (i = 0; i < MAX_PIPES; i++)
487 gc->pipe[i].shader.render_op = EVAS_RENDER_BLEND;
493 shared = calloc(1, sizeof(Evas_GL_Shared));
494 ext = glGetString(GL_EXTENSIONS);
497 if (getenv("EVAS_GL_INFO"))
498 fprintf(stderr, "EXT:\n%s\n", ext);
499 if ((strstr((char *)ext, "GL_ARB_texture_non_power_of_two")) ||
500 (strstr((char *)ext, "OES_texture_npot")) ||
501 (strstr((char *)ext, "GL_IMG_texture_npot")))
502 shared->info.tex_npo2 = 1;
503 if ((strstr((char *)ext, "GL_NV_texture_rectangle")) ||
504 (strstr((char *)ext, "GL_EXT_texture_rectangle")) ||
505 (strstr((char *)ext, "GL_ARB_texture_rectangle")))
506 shared->info.tex_rect = 1;
507 if ((strstr((char *)ext, "GL_ARB_get_program_binary")) ||
508 (strstr((char *)ext, "GL_OES_get_program_binary")))
509 shared->info.bin_program = 1;
510 #ifdef GL_TEXTURE_MAX_ANISOTROPY_EXT
511 if ((strstr((char *)ext, "GL_EXT_texture_filter_anisotropic")))
512 glGetFloatv(GL_MAX_TEXTURE_MAX_ANISOTROPY_EXT,
513 &(shared->info.anisotropic));
516 if ((strstr((char *)ext, "GL_EXT_bgra")) ||
517 (strstr((char *)ext, "GL_EXT_texture_format_BGRA8888")))
518 shared->info.bgra = 1;
520 #if defined (GLES_VARIETY_S3C6410) || defined (GLES_VARIETY_SGX)
521 // FIXME: there should be an extension name/string to check for
522 // not just symbols in the lib
524 s = getenv("EVAS_GL_NO_MAP_IMAGE_SEC");
528 // test for all needed symbols - be "conservative" and
530 if ((secsym_eglCreateImage) &&
531 (secsym_eglDestroyImage) &&
532 (secsym_glEGLImageTargetTexture2DOES) &&
533 (secsym_eglMapImageSEC) &&
534 (secsym_eglUnmapImageSEC) &&
535 (secsym_eglGetImageAttribSEC))
536 shared->info.sec_image_map = 1;
540 glGetIntegerv(GL_MAX_TEXTURE_IMAGE_UNITS,
541 &(shared->info.max_texture_units));
542 glGetIntegerv(GL_MAX_TEXTURE_SIZE,
543 &(shared->info.max_texture_size));
544 shared->info.max_vertex_elements = 6 * 100000;
545 #ifdef GL_MAX_ELEMENTS_VERTICES
546 /* only applies to glDrawRangeElements. don't really need to get it.
547 glGetIntegerv(GL_MAX_ELEMENTS_VERTICES,
548 &(shared->info.max_vertex_elements));
551 s = getenv("EVAS_GL_VERTEX_MAX");
552 if (s) shared->info.max_vertex_elements = atoi(s);
553 if (shared->info.max_vertex_elements < 6)
554 shared->info.max_vertex_elements = 6;
556 // magic numbers that are a result of imperical testing and getting
557 // "best case" performance across a range of systems
558 shared->info.tune.cutout.max = DEF_CUTOUT;
559 shared->info.tune.pipes.max = DEF_PIPES;
560 shared->info.tune.atlas.max_alloc_size = DEF_ATLAS_ALLOC;
561 shared->info.tune.atlas.max_alloc_alpha_size = DEF_ATLAS_ALLOC_ALPHA;
562 shared->info.tune.atlas.max_w = DEF_ATLAS_W;
563 shared->info.tune.atlas.max_h = DEF_ATLAS_H;
564 shared->info.tune.atlas.slot_size = DEF_ATLAS_SLOT;
566 // per gpu hacks. based on impirical measurement of some known gpu's
567 s = (const char *)glGetString(GL_RENDERER);
570 if (strstr(s, "PowerVR SGX 540"))
571 shared->info.tune.pipes.max = DEF_PIPES_SGX_540;
572 else if (strstr(s, "NVIDIA Tegra"))
573 shared->info.tune.pipes.max = DEF_PIPES_TEGRA_2;
576 #define GETENVOPT(name, tune_param, min, max) \
578 const char *__v = getenv(name); \
580 shared->info.tune.tune_param = atoi(__v); \
581 if (shared->info.tune.tune_param > max) \
582 shared->info.tune.tune_param = max; \
583 else if (shared->info.tune.tune_param < min) \
584 shared->info.tune.tune_param = min; \
588 GETENVOPT("EVAS_GL_CUTOUT_MAX", cutout.max, -1, 0x7fffffff);
589 GETENVOPT("EVAS_GL_PIPES_MAX", pipes.max, 1, MAX_PIPES);
590 GETENVOPT("EVAS_GL_ATLAS_ALLOC_SIZE", atlas.max_alloc_size, MIN_ATLAS_ALLOC, MAX_ATLAS_ALLOC);
591 GETENVOPT("EVAS_GL_ATLAS_ALLOC_ALPHA_SIZE", atlas.max_alloc_alpha_size, MIN_ATLAS_ALLOC_ALPHA, MAX_ATLAS_ALLOC_ALPHA);
592 GETENVOPT("EVAS_GL_ATLAS_MAX_W", atlas.max_w, 0, MAX_ATLAS_W);
593 GETENVOPT("EVAS_GL_ATLAS_MAX_H", atlas.max_h, 0, MAX_ATLAS_H);
594 GETENVOPT("EVAS_GL_ATLAS_SLOT_SIZE", atlas.slot_size, MIN_ATLAS_SLOT, MAX_ATLAS_SLOT);
595 s = (const char *)getenv("EVAS_GL_GET_PROGRAM_BINARY");
598 if (atoi(s) == 0) shared->info.bin_program = 0;
601 if (getenv("EVAS_GL_INFO"))
603 "max tex size %ix%i\n"
605 "non-power-2 tex %i\n"
608 "max ansiotropic filtering: %3.3f\n"
609 "egl sec map image: %i\n"
610 "max vertex count: %i\n"
612 "(can set EVAS_GL_VERTEX_MAX EVAS_GL_NO_MAP_IMAGE_SEC EVAS_GL_INFO EVAS_GL_MEMINFO )\n"
614 "EVAS_GL_GET_PROGRAM_BINARY: %i\n"
615 "EVAS_GL_CUTOUT_MAX: %i\n"
616 "EVAS_GL_PIPES_MAX: %i\n"
617 "EVAS_GL_ATLAS_ALLOC_SIZE: %i\n"
618 "EVAS_GL_ATLAS_ALLOC_ALPHA_SIZE: %i\n"
619 "EVAS_GL_ATLAS_MAX_W x EVAS_GL_ATLAS_MAX_H: %i x %i\n"
620 "EVAS_GL_ATLAS_SLOT_SIZE: %i\n"
622 (int)shared->info.max_texture_size, (int)shared->info.max_texture_size,
623 (int)shared->info.max_texture_units,
624 (int)shared->info.tex_npo2,
625 (int)shared->info.tex_rect,
626 (int)shared->info.bgra,
627 (double)shared->info.anisotropic,
628 (int)shared->info.sec_image_map,
629 (int)shared->info.max_vertex_elements,
631 (int)shared->info.bin_program,
632 (int)shared->info.tune.cutout.max,
633 (int)shared->info.tune.pipes.max,
634 (int)shared->info.tune.atlas.max_alloc_size,
635 (int)shared->info.tune.atlas.max_alloc_alpha_size,
636 (int)shared->info.tune.atlas.max_w, (int)shared->info.tune.atlas.max_h,
637 (int)shared->info.tune.atlas.slot_size
640 glDisable(GL_DEPTH_TEST);
641 GLERR(__FUNCTION__, __FILE__, __LINE__, "");
643 GLERR(__FUNCTION__, __FILE__, __LINE__, "");
645 GLERR(__FUNCTION__, __FILE__, __LINE__, "");
646 glBlendFunc(GL_ONE, GL_ONE_MINUS_SRC_ALPHA);
647 GLERR(__FUNCTION__, __FILE__, __LINE__, "");
649 // glBlendFunc(GL_SRC_ALPHA, GL_ONE_MINUS_SRC_ALPHA); // dest alpha
650 // glBlendFunc(GL_SRC_ALPHA, GL_ONE); // ???
651 glDepthMask(GL_FALSE);
652 GLERR(__FUNCTION__, __FILE__, __LINE__, "");
654 glTexParameteri(GL_TEXTURE_2D, GL_TEXTURE_MAG_FILTER, GL_NEAREST);
655 GLERR(__FUNCTION__, __FILE__, __LINE__, "");
656 glTexParameteri(GL_TEXTURE_2D, GL_TEXTURE_MIN_FILTER, GL_NEAREST);
657 GLERR(__FUNCTION__, __FILE__, __LINE__, "");
658 glTexParameteri(GL_TEXTURE_2D, GL_TEXTURE_WRAP_S, GL_CLAMP_TO_EDGE);
659 GLERR(__FUNCTION__, __FILE__, __LINE__, "");
660 glTexParameteri(GL_TEXTURE_2D, GL_TEXTURE_WRAP_T, GL_CLAMP_TO_EDGE);
661 GLERR(__FUNCTION__, __FILE__, __LINE__, "");
662 #ifdef GL_TEXTURE_MAX_ANISOTROPY_EXT
663 if (shared->info.anisotropic > 0.0)
665 glTexParameterf(GL_TEXTURE_2D, GL_TEXTURE_MAX_ANISOTROPY_EXT, 1.0);
666 GLERR(__FUNCTION__, __FILE__, __LINE__, "");
670 glEnableVertexAttribArray(SHAD_VERTEX);
671 GLERR(__FUNCTION__, __FILE__, __LINE__, "");
672 glEnableVertexAttribArray(SHAD_COLOR);
673 GLERR(__FUNCTION__, __FILE__, __LINE__, "");
675 if (!evas_gl_common_shader_program_init(shared)) goto error;
677 #define SHADER_TEXTURE_ADD(Shared, Shader, Name) \
678 glUseProgram(Shared->shader[SHADER_##Shader].prog); \
679 GLERR(__FUNCTION__, __FILE__, __LINE__, ""); \
680 glUniform1i(glGetUniformLocation(Shared->shader[SHADER_##Shader].prog, #Name), Shared->shader[SHADER_##Shader].tex_count++); \
681 GLERR(__FUNCTION__, __FILE__, __LINE__, "");
683 SHADER_TEXTURE_ADD(shared, YUV, tex);
684 SHADER_TEXTURE_ADD(shared, YUV, texu);
685 SHADER_TEXTURE_ADD(shared, YUV, texv);
687 SHADER_TEXTURE_ADD(shared, YUY2, tex);
688 SHADER_TEXTURE_ADD(shared, YUY2, texuv);
690 SHADER_TEXTURE_ADD(shared, NV12, tex);
691 SHADER_TEXTURE_ADD(shared, NV12, texuv);
693 SHADER_TEXTURE_ADD(shared, YUV_NOMUL, tex);
694 SHADER_TEXTURE_ADD(shared, YUV_NOMUL, texu);
695 SHADER_TEXTURE_ADD(shared, YUV_NOMUL, texv);
697 SHADER_TEXTURE_ADD(shared, YUY2_NOMUL, tex);
698 SHADER_TEXTURE_ADD(shared, YUY2_NOMUL, texuv);
700 SHADER_TEXTURE_ADD(shared, NV12_NOMUL, tex);
701 SHADER_TEXTURE_ADD(shared, NV12_NOMUL, texuv);
703 SHADER_TEXTURE_ADD(shared, IMG_MASK, tex);
704 SHADER_TEXTURE_ADD(shared, IMG_MASK, texm);
706 glUseProgram(gc->state.current.cur_prog);
707 GLERR(__FUNCTION__, __FILE__, __LINE__, "");
709 evas_gl_common_shader_program_init_done();
711 // uniform sampler2D tex[8];
715 // GLint loc = glGetUniformLocation(prog, "tex");
716 // glUniform1iv(loc, 8, texes);
718 shared->native_pm_hash = eina_hash_int32_new(NULL);
719 shared->native_tex_hash = eina_hash_int32_new(NULL);
722 gc->shared->references++;
723 _evas_gl_common_viewport_set(gc);
725 gc->def_surface = evas_gl_common_image_surface_new(gc, 1, 1, 1);
729 evas_gl_common_context_free(gc);
734 evas_gl_common_context_free(Evas_Engine_GL_Context *gc)
740 if (gc->references > 0) return;
741 if (gc->shared) gc->shared->references--;
743 if (gc->def_surface) evas_gl_common_image_free(gc->def_surface);
747 for (i = 0; i < gc->shared->info.tune.pipes.max; i++)
749 if (gc->pipe[i].array.vertex) free(gc->pipe[i].array.vertex);
750 if (gc->pipe[i].array.color) free(gc->pipe[i].array.color);
751 if (gc->pipe[i].array.texuv) free(gc->pipe[i].array.texuv);
752 if (gc->pipe[i].array.texm) free(gc->pipe[i].array.texm);
753 if (gc->pipe[i].array.texuv2) free(gc->pipe[i].array.texuv2);
754 if (gc->pipe[i].array.texuv3) free(gc->pipe[i].array.texuv3);
758 if ((gc->shared) && (gc->shared->references == 0))
760 Evas_GL_Texture_Pool *pt;
762 for (i = 0; i < SHADER_LAST; ++i)
763 evas_gl_common_shader_program_shutdown(&(gc->shared->shader[i]));
765 while (gc->shared->images)
767 evas_gl_common_image_free(gc->shared->images->data);
770 EINA_LIST_FOREACH(gc->shared->tex.whole, l, pt)
771 evas_gl_texture_pool_empty(pt);
772 for (i = 0; i < 33; i++)
774 for (j = 0; j < 3; j++)
776 EINA_LIST_FOREACH(gc->shared->tex.atlas[i][j], l, pt)
777 evas_gl_texture_pool_empty(pt);
780 eina_hash_free(gc->shared->native_pm_hash);
781 eina_hash_free(gc->shared->native_tex_hash);
785 if (gc == _evas_gl_common_context) _evas_gl_common_context = NULL;
790 evas_gl_common_context_use(Evas_Engine_GL_Context *gc)
792 if (_evas_gl_common_context == gc) return;
793 _evas_gl_common_context = gc;
794 if (gc) _evas_gl_common_viewport_set(gc);
798 evas_gl_common_context_newframe(Evas_Engine_GL_Context *gc)
805 if (getenv("EVAS_GL_DBG")) dbgflushnum = 1;
807 if (dbgflushnum) printf("----prev-flushnum: %i -----------------------------------\n", gc->flushnum);
810 gc->state.current.cur_prog = 0;
811 gc->state.current.cur_tex = 0;
812 gc->state.current.cur_texu = 0;
813 gc->state.current.cur_texv = 0;
814 gc->state.current.cur_texm = 0;
815 gc->state.current.cur_texmu = 0;
816 gc->state.current.cur_texmv = 0;
817 gc->state.current.render_op = 0;
818 gc->state.current.smooth = 0;
819 gc->state.current.blend = 0;
820 gc->state.current.clip = 0;
821 gc->state.current.cx = 0;
822 gc->state.current.cy = 0;
823 gc->state.current.cw = 0;
824 gc->state.current.ch = 0;
826 for (i = 0; i < gc->shared->info.tune.pipes.max; i++)
828 gc->pipe[i].region.x = 0;
829 gc->pipe[i].region.y = 0;
830 gc->pipe[i].region.w = 0;
831 gc->pipe[i].region.h = 0;
832 gc->pipe[i].region.type = 0;
833 gc->pipe[i].clip.active = 0;
834 gc->pipe[i].clip.x = 0;
835 gc->pipe[i].clip.y = 0;
836 gc->pipe[i].clip.w = 0;
837 gc->pipe[i].clip.h = 0;
838 gc->pipe[i].shader.surface = NULL;
839 gc->pipe[i].shader.cur_prog = 0;
840 gc->pipe[i].shader.cur_tex = 0;
841 gc->pipe[i].shader.cur_texu = 0;
842 gc->pipe[i].shader.cur_texv = 0;
843 gc->pipe[i].shader.cur_texm = 0;
844 gc->pipe[i].shader.render_op = EVAS_RENDER_BLEND;
845 gc->pipe[i].shader.smooth = 0;
846 gc->pipe[i].shader.blend = 0;
847 gc->pipe[i].shader.clip = 0;
848 gc->pipe[i].shader.cx = 0;
849 gc->pipe[i].shader.cy = 0;
850 gc->pipe[i].shader.cw = 0;
851 gc->pipe[i].shader.ch = 0;
855 glDisable(GL_SCISSOR_TEST);
856 GLERR(__FUNCTION__, __FILE__, __LINE__, "");
857 glScissor(0, 0, 0, 0);
858 GLERR(__FUNCTION__, __FILE__, __LINE__, "");
860 glDisable(GL_DEPTH_TEST);
861 GLERR(__FUNCTION__, __FILE__, __LINE__, "");
863 GLERR(__FUNCTION__, __FILE__, __LINE__, "");
865 GLERR(__FUNCTION__, __FILE__, __LINE__, "");
866 glBlendFunc(GL_ONE, GL_ONE_MINUS_SRC_ALPHA);
867 GLERR(__FUNCTION__, __FILE__, __LINE__, "");
869 // glBlendFunc(GL_SRC_ALPHA, GL_ONE_MINUS_SRC_ALPHA); // dest alpha
870 // glBlendFunc(GL_SRC_ALPHA, GL_ONE); // ???
871 glDepthMask(GL_FALSE);
872 GLERR(__FUNCTION__, __FILE__, __LINE__, "");
874 glTexParameteri(GL_TEXTURE_2D, GL_TEXTURE_MAG_FILTER, GL_NEAREST);
875 GLERR(__FUNCTION__, __FILE__, __LINE__, "");
876 glTexParameteri(GL_TEXTURE_2D, GL_TEXTURE_MIN_FILTER, GL_NEAREST);
877 GLERR(__FUNCTION__, __FILE__, __LINE__, "");
878 glTexParameteri(GL_TEXTURE_2D, GL_TEXTURE_WRAP_S, GL_CLAMP_TO_EDGE);
879 GLERR(__FUNCTION__, __FILE__, __LINE__, "");
880 glTexParameteri(GL_TEXTURE_2D, GL_TEXTURE_WRAP_T, GL_CLAMP_TO_EDGE);
881 GLERR(__FUNCTION__, __FILE__, __LINE__, "");
882 #ifdef GL_TEXTURE_MAX_ANISOTROPY_EXT
883 if (shared->info.anisotropic > 0.0)
885 glTexParameterf(GL_TEXTURE_2D, GL_TEXTURE_MAX_ANISOTROPY_EXT, 1.0);
886 GLERR(__FUNCTION__, __FILE__, __LINE__, "");
890 glEnableVertexAttribArray(SHAD_VERTEX);
891 GLERR(__FUNCTION__, __FILE__, __LINE__, "");
892 glEnableVertexAttribArray(SHAD_COLOR);
893 GLERR(__FUNCTION__, __FILE__, __LINE__, "");
894 glUseProgram(gc->state.current.cur_prog);
895 GLERR(__FUNCTION__, __FILE__, __LINE__, "");
897 glActiveTexture(GL_TEXTURE0);
898 GLERR(__FUNCTION__, __FILE__, __LINE__, "");
899 glBindTexture(GL_TEXTURE_2D, gc->pipe[0].shader.cur_tex);
900 GLERR(__FUNCTION__, __FILE__, __LINE__, "");
902 _evas_gl_common_viewport_set(gc);
906 evas_gl_common_context_resize(Evas_Engine_GL_Context *gc, int w, int h, int rot)
908 if ((gc->w == w) && (gc->h == h) && (gc->rot == rot)) return;
909 evas_gl_common_context_flush(gc);
914 if (_evas_gl_common_context == gc) _evas_gl_common_viewport_set(gc);
918 evas_gl_common_context_target_surface_set(Evas_Engine_GL_Context *gc,
919 Evas_GL_Image *surface)
921 if (surface == gc->pipe[0].shader.surface) return;
923 evas_gl_common_context_flush(gc);
925 gc->state.current.cur_prog = -1;
926 gc->state.current.cur_tex = -1;
927 gc->state.current.cur_texu = -1;
928 gc->state.current.cur_texv = -1;
929 gc->state.current.render_op = -1;
930 gc->state.current.smooth = -1;
931 gc->state.current.blend = -1;
932 gc->state.current.clip = -1;
933 gc->state.current.cx = -1;
934 gc->state.current.cy = -1;
935 gc->state.current.cw = -1;
936 gc->state.current.ch = -1;
938 gc->pipe[0].shader.surface = surface;
940 #if defined (GLES_VARIETY_S3C6410) || defined (GLES_VARIETY_SGX)
941 # ifndef GL_FRAMEBUFFER
942 # define GL_FRAMEBUFFER GL_FRAMEBUFFER_OES
945 # ifndef GL_FRAMEBUFFER
946 # define GL_FRAMEBUFFER GL_FRAMEBUFFER_EXT
949 if (gc->pipe[0].shader.surface == gc->def_surface)
951 glsym_glBindFramebuffer(GL_FRAMEBUFFER, 0);
952 GLERR(__FUNCTION__, __FILE__, __LINE__, "");
956 glsym_glBindFramebuffer(GL_FRAMEBUFFER, surface->tex->pt->fb);
957 GLERR(__FUNCTION__, __FILE__, __LINE__, "");
959 _evas_gl_common_viewport_set(gc);
962 #define PUSH_VERTEX(n, x, y, z) \
963 gc->pipe[n].array.vertex[nv++] = x; \
964 gc->pipe[n].array.vertex[nv++] = y; \
965 gc->pipe[n].array.vertex[nv++] = z
966 #define PUSH_COLOR(n, r, g, b, a) \
967 gc->pipe[n].array.color[nc++] = r; \
968 gc->pipe[n].array.color[nc++] = g; \
969 gc->pipe[n].array.color[nc++] = b; \
970 gc->pipe[n].array.color[nc++] = a
971 #define PUSH_TEXUV(n, u, v) \
972 gc->pipe[n].array.texuv[nu++] = u; \
973 gc->pipe[n].array.texuv[nu++] = v
974 #define PUSH_TEXUV2(n, u, v) \
975 gc->pipe[n].array.texuv2[nu2++] = u; \
976 gc->pipe[n].array.texuv2[nu2++] = v
977 #define PUSH_TEXUV3(n, u, v) \
978 gc->pipe[n].array.texuv3[nu3++] = u; \
979 gc->pipe[n].array.texuv3[nu3++] = v
980 #define PUSH_TEXM(n, u, v) \
981 gc->pipe[n].array.texm[nm++] = u; \
982 gc->pipe[n].array.texm[nm++] = v
986 array_alloc(Evas_Engine_GL_Context *gc, int n)
988 gc->havestuff = EINA_TRUE;
989 if (gc->pipe[n].array.num <= gc->pipe[n].array.alloc) return;
990 gc->pipe[n].array.alloc += 6 * 1024;
991 if (gc->pipe[n].array.use_vertex)
992 gc->pipe[n].array.vertex = realloc(gc->pipe[n].array.vertex,
993 gc->pipe[n].array.alloc * sizeof(GLshort) * 3);
994 if (gc->pipe[n].array.use_color)
995 gc->pipe[n].array.color = realloc(gc->pipe[n].array.color,
996 gc->pipe[n].array.alloc * sizeof(GLubyte) * 4);
997 if (gc->pipe[n].array.use_texuv)
998 gc->pipe[n].array.texuv = realloc(gc->pipe[n].array.texuv,
999 gc->pipe[n].array.alloc * sizeof(GLfloat) * 2);
1000 if (gc->pipe[n].array.use_texm)
1001 gc->pipe[n].array.texm = realloc(gc->pipe[n].array.texm,
1002 gc->pipe[n].array.alloc * sizeof(GLfloat) * 2);
1003 if (gc->pipe[n].array.use_texuv2)
1004 gc->pipe[n].array.texuv2 = realloc(gc->pipe[n].array.texuv2,
1005 gc->pipe[n].array.alloc * sizeof(GLfloat) * 2);
1006 if (gc->pipe[n].array.use_texuv3)
1007 gc->pipe[n].array.texuv3 = realloc(gc->pipe[n].array.texuv3,
1008 gc->pipe[n].array.alloc * sizeof(GLfloat) * 2);
1013 pipe_region_intersects(Evas_Engine_GL_Context *gc, int n,
1014 int x, int y, int w, int h)
1016 int i, rx, ry, rw, rh, ii;
1018 rx = gc->pipe[n].region.x;
1019 ry = gc->pipe[n].region.y;
1020 rw = gc->pipe[n].region.w;
1021 rh = gc->pipe[n].region.h;
1022 if (!RECTS_INTERSECT(x, y, w, h, rx, ry, rw, rh))
1025 // a hack for now. map pipes use their whole bounding box for intersects
1026 // which at worst case reduces to old pipeline flushes, but cheaper than
1027 // full quad region or triangle intersects right now
1028 if (gc->pipe[n].region.type == RTYPE_MAP) return 1;
1033 i < gc->pipe[n].array.num;
1038 // 0, 1, 2 < top left
1039 // 3, 4, 5 < top right
1040 // 6. 7, 8 < bottom left
1041 rx = gc->pipe[n].array.vertex[ii + 0];
1042 ry = gc->pipe[n].array.vertex[ii + 1];
1043 rw = gc->pipe[n].array.vertex[ii + 3] - rx;
1044 rh = gc->pipe[n].array.vertex[ii + 7] - ry;
1045 if (RECTS_INTERSECT(x, y, w, h, rx, ry, rw, rh))
1053 pipe_region_expand(Evas_Engine_GL_Context *gc, int n,
1054 int x, int y, int w, int h)
1058 if (gc->pipe[n].region.w <= 0)
1060 gc->pipe[n].region.x = x;
1061 gc->pipe[n].region.y = y;
1062 gc->pipe[n].region.w = w;
1063 gc->pipe[n].region.h = h;
1066 x1 = gc->pipe[n].region.x;
1067 y1 = gc->pipe[n].region.y;
1068 x2 = gc->pipe[n].region.x + gc->pipe[n].region.w;
1069 y2 = gc->pipe[n].region.y + gc->pipe[n].region.h;
1072 if ((x + w) > x2) x2 = x + w;
1073 if ((y + h) > y2) y2 = y + h;
1074 gc->pipe[n].region.x = x1;
1075 gc->pipe[n].region.y = y1;
1076 gc->pipe[n].region.w = x2 - x1;
1077 gc->pipe[n].region.h = y2 - y1;
1081 vertex_array_size_check(Evas_Engine_GL_Context *gc, int pn, int n)
1084 // this fixup breaks for expedite test 32. why?
1085 if ((gc->pipe[pn].array.num + n) > gc->shared->info.max_vertex_elements)
1087 shader_array_flush(gc);
1093 static inline Evas_GL_Shader
1094 evas_gl_common_shader_choice(int npoints __UNUSED__,
1096 int r, int g, int b, int a,
1097 Evas_GL_Shader nomul,
1100 if ((a == 255) && (r == 255) && (g == 255) && (b == 255))
1102 if (!p) return nomul;
1104 if ((p[0].col == 0xffffffff) && (p[1].col == 0xffffffff) &&
1105 (p[2].col == 0xffffffff) && (p[3].col == 0xffffffff))
1112 _evas_gl_common_context_push(int rtype,
1113 Evas_Engine_GL_Context *gc,
1114 Evas_GL_Texture *tex,
1115 Evas_GL_Texture *texm,
1117 int x, int y, int w, int h,
1121 int cx, int cy, int cw, int ch)
1128 vertex_array_size_check(gc, gc->state.top_pipe, 6);
1129 pn = gc->state.top_pipe;
1131 if (!((pn == 0) && (gc->pipe[pn].array.num == 0)))
1136 for (i = pn; i >= 0; i--)
1138 if ((gc->pipe[i].region.type == rtype)
1139 && (!tex || gc->pipe[i].shader.cur_tex == tex->pt->texture)
1140 && (!texm || gc->pipe[i].shader.cur_texm == texm->pt->texture)
1141 && (gc->pipe[i].shader.cur_prog == prog)
1142 && (gc->pipe[i].shader.smooth == smooth)
1143 && (gc->pipe[i].shader.blend == blend)
1144 && (gc->pipe[i].shader.render_op == gc->dc->render_op)
1145 && (gc->pipe[i].shader.clip == clip)
1146 && (!clip || ((gc->pipe[i].shader.cx == cx)
1147 && (gc->pipe[i].shader.cy == cy)
1148 && (gc->pipe[i].shader.cw == cw)
1149 && (gc->pipe[i].shader.ch == ch))))
1155 if (pipe_region_intersects(gc, i, x, y, w, h)) break;
1159 pn = gc->state.top_pipe + 1;
1160 if (pn >= gc->shared->info.tune.pipes.max)
1162 shader_array_flush(gc);
1165 gc->state.top_pipe = pn;
1168 if ((tex) && (((tex->im) && (tex->im->native.data)) || tex->pt->dyn.img))
1170 if (gc->pipe[pn].array.im != tex->im)
1172 shader_array_flush(gc);
1173 pn = gc->state.top_pipe;
1174 gc->pipe[pn].array.im = tex->im;
1179 if (!((gc->pipe[pn].region.type == rtype)
1180 && (!tex || gc->pipe[pn].shader.cur_tex == tex->pt->texture)
1181 && (!texm || gc->pipe[pn].shader.cur_texm == texm->pt->texture)
1182 && (gc->pipe[pn].shader.cur_prog == prog)
1183 && (gc->pipe[pn].shader.smooth == smooth)
1184 && (gc->pipe[pn].shader.blend == blend)
1185 && (gc->pipe[pn].shader.render_op == gc->dc->render_op)
1186 && (gc->pipe[pn].shader.clip == clip)
1187 && (!clip || ((gc->pipe[pn].shader.cx == cx)
1188 && (gc->pipe[pn].shader.cy == cy)
1189 && (gc->pipe[pn].shader.cw == cw)
1190 && (gc->pipe[pn].shader.ch == ch)))))
1192 shader_array_flush(gc);
1194 if ((tex) && (((tex->im) && (tex->im->native.data)) || tex->pt->dyn.img))
1196 if (gc->pipe[pn].array.im != tex->im)
1198 shader_array_flush(gc);
1199 gc->pipe[pn].array.im = tex->im;
1208 evas_gl_common_context_line_push(Evas_Engine_GL_Context *gc,
1209 int x1, int y1, int x2, int y2,
1210 int clip, int cx, int cy, int cw, int ch,
1211 int r, int g, int b, int a)
1213 int pnum, nv, nc, nu, nt, i;
1214 Eina_Bool blend = 0;
1215 GLuint prog = gc->shared->shader[SHADER_RECT].prog;
1218 if (a < 255) blend = 1;
1219 if (gc->dc->render_op == EVAS_RENDER_COPY) blend = 0;
1221 shader_array_flush(gc);
1222 vertex_array_size_check(gc, gc->state.top_pipe, 2);
1223 pn = gc->state.top_pipe;
1224 gc->pipe[pn].shader.cur_tex = 0;
1225 gc->pipe[pn].shader.cur_prog = prog;
1226 gc->pipe[pn].shader.blend = blend;
1227 gc->pipe[pn].shader.render_op = gc->dc->render_op;
1228 gc->pipe[pn].shader.clip = clip;
1229 gc->pipe[pn].shader.cx = cx;
1230 gc->pipe[pn].shader.cy = cy;
1231 gc->pipe[pn].shader.cw = cw;
1232 gc->pipe[pn].shader.ch = ch;
1234 gc->pipe[pn].array.line = 1;
1235 gc->pipe[pn].array.use_vertex = 1;
1236 gc->pipe[pn].array.use_color = 1;
1237 gc->pipe[pn].array.use_texuv = 0;
1238 gc->pipe[pn].array.use_texuv2 = 0;
1239 gc->pipe[pn].array.use_texuv3 = 0;
1241 pnum = gc->pipe[pn].array.num;
1242 nv = pnum * 3; nc = pnum * 4; nu = pnum * 2; nt = pnum * 4;
1243 gc->pipe[pn].array.num += 2;
1244 array_alloc(gc, pn);
1246 PUSH_VERTEX(pn, x1, y1, 0);
1247 PUSH_VERTEX(pn, x2, y2, 0);
1249 for (i = 0; i < 2; i++)
1251 PUSH_COLOR(pn, r, g, b, a);
1254 shader_array_flush(gc);
1255 gc->pipe[pn].array.line = 0;
1256 gc->pipe[pn].array.use_vertex = 0;
1257 gc->pipe[pn].array.use_color = 0;
1258 gc->pipe[pn].array.use_texuv = 0;
1259 gc->pipe[pn].array.use_texuv2 = 0;
1260 gc->pipe[pn].array.use_texuv3 = 0;
1264 evas_gl_common_context_rectangle_push(Evas_Engine_GL_Context *gc,
1265 int x, int y, int w, int h,
1266 int r, int g, int b, int a)
1268 int pnum, nv, nc, nu, nt, i;
1269 Eina_Bool blend = 0;
1270 GLuint prog = gc->shared->shader[SHADER_RECT].prog;
1273 if (gc->dc->mask.mask)
1275 RGBA_Draw_Context *dc;
1278 im = (void *)dc->mask.mask;
1279 evas_gl_common_context_font_push(gc, im->tex,
1280 x - dc->mask.x,y - dc->mask.y,
1281 dc->mask.w,dc->mask.h,
1286 if (a < 255) blend = 1;
1287 if (gc->dc->render_op == EVAS_RENDER_COPY) blend = 0;
1290 vertex_array_size_check(gc, gc->state.top_pipe, 6);
1291 pn = gc->state.top_pipe;
1293 if ((pn == 0) && (gc->pipe[pn].array.num == 0))
1295 gc->pipe[pn].region.type = RTYPE_RECT;
1296 gc->pipe[pn].shader.cur_tex = 0;
1297 gc->pipe[pn].shader.cur_prog = prog;
1298 gc->pipe[pn].shader.blend = blend;
1299 gc->pipe[pn].shader.render_op = gc->dc->render_op;
1300 gc->pipe[pn].shader.clip = 0;
1301 gc->pipe[pn].shader.cx = 0;
1302 gc->pipe[pn].shader.cy = 0;
1303 gc->pipe[pn].shader.cw = 0;
1304 gc->pipe[pn].shader.ch = 0;
1305 gc->pipe[pn].array.line = 0;
1306 gc->pipe[pn].array.use_vertex = 1;
1307 gc->pipe[pn].array.use_color = 1;
1308 gc->pipe[pn].array.use_texuv = 0;
1309 gc->pipe[pn].array.use_texuv2 = 0;
1310 gc->pipe[pn].array.use_texuv3 = 0;
1316 for (i = pn; i >= 0; i--)
1318 if ((gc->pipe[i].region.type == RTYPE_RECT)
1319 && (gc->pipe[i].shader.cur_tex == 0)
1320 && (gc->pipe[i].shader.cur_prog == prog)
1321 && (gc->pipe[i].shader.blend == blend)
1322 && (gc->pipe[i].shader.render_op == gc->dc->render_op)
1323 && (gc->pipe[i].shader.clip == 0)
1330 if (pipe_region_intersects(gc, i, x, y, w, h)) break;
1334 pn = gc->state.top_pipe + 1;
1335 if (pn >= gc->shared->info.tune.pipes.max)
1337 shader_array_flush(gc);
1340 gc->state.top_pipe = pn;
1341 gc->pipe[pn].region.type = RTYPE_RECT;
1342 gc->pipe[pn].shader.cur_tex = 0;
1343 gc->pipe[pn].shader.cur_prog = prog;
1344 gc->pipe[pn].shader.blend = blend;
1345 gc->pipe[pn].shader.render_op = gc->dc->render_op;
1346 gc->pipe[pn].shader.clip = 0;
1347 gc->pipe[pn].shader.cx = 0;
1348 gc->pipe[pn].shader.cy = 0;
1349 gc->pipe[pn].shader.cw = 0;
1350 gc->pipe[pn].shader.ch = 0;
1351 gc->pipe[pn].array.line = 0;
1352 gc->pipe[pn].array.use_vertex = 1;
1353 gc->pipe[pn].array.use_color = 1;
1354 gc->pipe[pn].array.use_texuv = 0;
1355 gc->pipe[pn].array.use_texuv2 = 0;
1356 gc->pipe[pn].array.use_texuv3 = 0;
1360 if ((gc->pipe[pn].shader.cur_tex != 0)
1361 || (gc->pipe[pn].shader.cur_prog != prog)
1362 || (gc->pipe[pn].shader.blend != blend)
1363 || (gc->pipe[pn].shader.render_op != gc->dc->render_op)
1364 || (gc->pipe[pn].shader.clip != 0)
1367 shader_array_flush(gc);
1368 pn = gc->state.top_pipe;
1369 gc->pipe[pn].shader.cur_tex = 0;
1370 gc->pipe[pn].shader.cur_prog = prog;
1371 gc->pipe[pn].shader.blend = blend;
1372 gc->pipe[pn].shader.render_op = gc->dc->render_op;
1373 gc->pipe[pn].shader.clip = 0;
1374 gc->pipe[pn].shader.cx = 0;
1375 gc->pipe[pn].shader.cy = 0;
1376 gc->pipe[pn].shader.cw = 0;
1377 gc->pipe[pn].shader.ch = 0;
1380 gc->pipe[pn].region.type = RTYPE_RECT;
1381 gc->pipe[pn].array.line = 0;
1382 gc->pipe[pn].array.use_vertex = 1;
1383 gc->pipe[pn].array.use_color = 1;
1384 gc->pipe[pn].array.use_texuv = 0;
1385 gc->pipe[pn].array.use_texuv2 = 0;
1386 gc->pipe[pn].array.use_texuv3 = 0;
1389 pipe_region_expand(gc, pn, x, y, w, h);
1391 pnum = gc->pipe[pn].array.num;
1392 nv = pnum * 3; nc = pnum * 4; nu = pnum * 2; nt = pnum * 4;
1393 gc->pipe[pn].array.num += 6;
1394 array_alloc(gc, pn);
1396 PUSH_VERTEX(pn, x , y , 0);
1397 PUSH_VERTEX(pn, x + w, y , 0);
1398 PUSH_VERTEX(pn, x , y + h, 0);
1400 PUSH_VERTEX(pn, x + w, y , 0);
1401 PUSH_VERTEX(pn, x + w, y + h, 0);
1402 PUSH_VERTEX(pn, x , y + h, 0);
1404 for (i = 0; i < 6; i++)
1406 PUSH_COLOR(pn, r, g, b, a);
1411 evas_gl_common_context_image_push(Evas_Engine_GL_Context *gc,
1412 Evas_GL_Texture *tex,
1413 double sx, double sy, double sw, double sh,
1414 int x, int y, int w, int h,
1415 int r, int g, int b, int a,
1416 Eina_Bool smooth, Eina_Bool tex_only)
1418 int pnum, nv, nc, nu, nu2, nt, i;
1419 GLfloat tx1, tx2, ty1, ty2;
1420 Eina_Bool blend = 1;
1421 GLuint prog = gc->shared->shader[SHADER_IMG].prog;
1424 if (!tex->alpha) blend = 0;
1425 if (a < 255) blend = 1;
1427 if (gc->filter_prog)
1429 prog = gc->filter_prog;
1433 if (tex->pt->dyn.img)
1435 prog = gc->shared->shader[evas_gl_common_shader_choice(0, NULL, r, g, b, a,
1436 SHADER_IMG_BGRA_NOMUL, SHADER_IMG_BGRA)].prog;
1440 prog = gc->shared->shader[evas_gl_common_shader_choice(0, NULL, r, g, b, a,
1441 SHADER_TEX_NOMUL, SHADER_TEX)].prog;
1446 if (tex->gc->shared->info.bgra)
1448 prog = gc->shared->shader[evas_gl_common_shader_choice(0, NULL, r, g, b, a,
1449 SHADER_IMG_BGRA_NOMUL, SHADER_IMG_BGRA)].prog;
1453 prog = gc->shared->shader[evas_gl_common_shader_choice(0, NULL, r, g, b, a,
1454 SHADER_IMG_NOMUL, SHADER_IMG)].prog;
1458 pn = _evas_gl_common_context_push(RTYPE_IMAGE,
1466 gc->pipe[pn].region.type = RTYPE_IMAGE;
1467 gc->pipe[pn].shader.cur_tex = tex->pt->texture;
1468 gc->pipe[pn].shader.cur_prog = prog;
1469 gc->pipe[pn].shader.smooth = smooth;
1470 gc->pipe[pn].shader.blend = blend;
1471 gc->pipe[pn].shader.render_op = gc->dc->render_op;
1472 gc->pipe[pn].shader.clip = 0;
1473 gc->pipe[pn].shader.cx = 0;
1474 gc->pipe[pn].shader.cy = 0;
1475 gc->pipe[pn].shader.cw = 0;
1476 gc->pipe[pn].shader.ch = 0;
1477 gc->pipe[pn].array.line = 0;
1478 gc->pipe[pn].array.use_vertex = 1;
1479 // if nomul... dont need this
1480 gc->pipe[pn].array.use_color = 1;
1481 gc->pipe[pn].array.use_texuv = 1;
1482 gc->pipe[pn].array.use_texuv2 = 0;
1483 gc->pipe[pn].array.use_texuv3 = 0;
1485 pipe_region_expand(gc, pn, x, y, w, h);
1487 pnum = gc->pipe[pn].array.num;
1488 nv = pnum * 3; nc = pnum * 4; nu = pnum * 2; nu2 = pnum * 2;
1490 gc->pipe[pn].array.num += 6;
1491 array_alloc(gc, pn);
1493 if ((tex->im) && (tex->im->native.data) && (!tex->im->native.yinvert))
1495 tx1 = ((double)(tex->x) + sx) / (double)tex->pt->w;
1496 ty1 = 1.0 - ((double)(tex->y) + sy) / (double)tex->pt->h;
1497 tx2 = ((double)(tex->x) + sx + sw) / (double)tex->pt->w;
1498 ty2 = 1.0 - ((double)(tex->y) + sy + sh) / (double)tex->pt->h;
1502 tx1 = ((double)(tex->x) + sx) / (double)tex->pt->w;
1503 ty1 = ((double)(tex->y) + sy) / (double)tex->pt->h;
1504 tx2 = ((double)(tex->x) + sx + sw) / (double)tex->pt->w;
1505 ty2 = ((double)(tex->y) + sy + sh) / (double)tex->pt->h;
1508 PUSH_VERTEX(pn, x , y , 0);
1509 PUSH_VERTEX(pn, x + w, y , 0);
1510 PUSH_VERTEX(pn, x , y + h, 0);
1512 PUSH_TEXUV(pn, tx1, ty1);
1513 PUSH_TEXUV(pn, tx2, ty1);
1514 PUSH_TEXUV(pn, tx1, ty2);
1516 PUSH_VERTEX(pn, x + w, y , 0);
1517 PUSH_VERTEX(pn, x + w, y + h, 0);
1518 PUSH_VERTEX(pn, x , y + h, 0);
1520 PUSH_TEXUV(pn, tx2, ty1);
1521 PUSH_TEXUV(pn, tx2, ty2);
1522 PUSH_TEXUV(pn, tx1, ty2);
1524 // if nomul... dont need this
1525 for (i = 0; i < 6; i++)
1527 PUSH_COLOR(pn, r, g, b, a);
1532 evas_gl_common_context_image_mask_push(Evas_Engine_GL_Context *gc,
1533 Evas_GL_Texture *tex,
1534 Evas_GL_Texture *texm,
1535 double sx, double sy, double sw, double sh,
1536 double sxm, double sym, double swm,double shm,
1537 int x, int y, int w, int h,
1538 int r, int g, int b, int a,
1541 int pnum, nv, nc, nu, nm, nt, i;
1542 GLfloat tx1, tx2, ty1, ty2;
1543 GLfloat txm1, txm2, tym1, tym2;
1544 Eina_Bool blend = 1;
1545 GLuint prog = gc->shared->shader[SHADER_IMG_MASK].prog;
1549 if (tex->gc->shared->info.bgra)
1551 prog = gc->shared->shader[SHADER_IMG_MASK].prog;
1555 #warning Nash: FIXME: Need two shaders?
1556 printf("Not good: Need other texture\n");
1557 prog = gc->shared->shader[SHADER_IMG].prog;
1561 pn = _evas_gl_common_context_push(RTYPE_IMASK,
1569 gc->pipe[pn].region.type = RTYPE_IMASK;
1570 gc->pipe[pn].shader.cur_tex = tex->pt->texture;
1571 gc->pipe[pn].shader.cur_texm = texm->pt->texture;
1572 gc->pipe[pn].shader.cur_prog = prog;
1573 gc->pipe[pn].shader.smooth = smooth;
1574 gc->pipe[pn].shader.blend = blend;
1575 gc->pipe[pn].shader.render_op = gc->dc->render_op;
1576 gc->pipe[pn].shader.clip = 0;
1577 gc->pipe[pn].shader.cx = 0;
1578 gc->pipe[pn].shader.cy = 0;
1579 gc->pipe[pn].shader.cw = 0;
1580 gc->pipe[pn].shader.ch = 0;
1581 gc->pipe[pn].array.line = 0;
1582 gc->pipe[pn].array.use_vertex = 1;
1583 // if nomul... dont need this
1584 gc->pipe[pn].array.use_color = 1;
1585 gc->pipe[pn].array.use_texuv = 1;
1586 gc->pipe[pn].array.use_texuv2 = 0;
1587 gc->pipe[pn].array.use_texuv3 = 0;
1588 gc->pipe[pn].array.use_texm = 1;
1590 pipe_region_expand(gc, pn, x, y, w, h);
1592 pnum = gc->pipe[pn].array.num;
1593 nv = pnum * 3; nc = pnum * 4; nm = pnum * 2; nu = pnum * 2;
1595 gc->pipe[pn].array.num += 6;
1596 array_alloc(gc, pn);
1598 if ((tex->im) && (tex->im->native.data) && (!tex->im->native.yinvert))
1600 tx1 = ((double)(tex->x) + sx) / (double)tex->pt->w;
1601 ty1 = ((double)(tex->y) + sy + sh) / (double)tex->pt->h;
1602 tx2 = ((double)(tex->x) + sx + sw) / (double)tex->pt->w;
1603 ty2 = ((double)(tex->y) + sy) / (double)tex->pt->h;
1605 txm1 = ((double)(texm->x) + sxm) / (double)texm->pt->w;
1606 tym1 = ((double)(texm->y) + sym + shm) / (double)texm->pt->h;
1607 txm2 = ((double)(texm->x) + sxm + swm) / (double)texm->pt->w;
1608 tym2 = ((double)(texm->y) + sym) / (double)texm->pt->h;
1612 tx1 = ((double)(tex->x) + sx) / (double)tex->pt->w;
1613 ty1 = ((double)(tex->y) + sy) / (double)tex->pt->h;
1614 tx2 = ((double)(tex->x) + sx + sw) / (double)tex->pt->w;
1615 ty2 = ((double)(tex->y) + sy + sh) / (double)tex->pt->h;
1617 txm1 = (texm->x + sxm) / (double)texm->pt->w;
1618 tym1 = (texm->y + sym) / (double)texm->pt->h;
1619 txm2 = (texm->x + sxm + swm) / (double)texm->pt->w;
1620 tym2 = (texm->y + sym + shm) / (double)texm->pt->h;
1622 // printf(" %3.6lf %3.6lf %3.6lf %3.6lf\n",sx,sy,sw,sh);
1623 // printf("m%3.6lf %3.6lf %3.6lf %3.6lf\n",sxm,sym,swm,shm);
1624 // printf(" %3f %3f %3f %3f\n",tx1,ty1,tx2,ty2);
1625 // printf("m%3f %3f %3f %3f\n",txm1,tym1,txm2,tym2);
1627 PUSH_VERTEX(pn, x , y , 0);
1628 PUSH_VERTEX(pn, x + w, y , 0);
1629 PUSH_VERTEX(pn, x , y + h, 0);
1631 PUSH_TEXUV(pn, tx1, ty1);
1632 PUSH_TEXUV(pn, tx2, ty1);
1633 PUSH_TEXUV(pn, tx1, ty2);
1635 PUSH_TEXM(pn, txm1, tym1);
1636 PUSH_TEXM(pn, txm2, tym1);
1637 PUSH_TEXM(pn, txm1, tym2);
1639 PUSH_VERTEX(pn, x + w, y , 0);
1640 PUSH_VERTEX(pn, x + w, y + h, 0);
1641 PUSH_VERTEX(pn, x , y + h, 0);
1643 PUSH_TEXUV(pn, tx2, ty1);
1644 PUSH_TEXUV(pn, tx2, ty2);
1645 PUSH_TEXUV(pn, tx1, ty2);
1647 PUSH_TEXM(pn, txm2, tym1);
1648 PUSH_TEXM(pn, txm2, tym2);
1649 PUSH_TEXM(pn, txm1, tym2);
1651 // if nomul... dont need this
1652 for (i = 0; i < 6; i++)
1654 PUSH_COLOR(pn, r, g, b, a);
1660 evas_gl_common_context_font_push(Evas_Engine_GL_Context *gc,
1661 Evas_GL_Texture *tex,
1662 double sx, double sy, double sw, double sh,
1663 int x, int y, int w, int h,
1664 int r, int g, int b, int a)
1666 int pnum, nv, nc, nu, nt, i;
1667 GLfloat tx1, tx2, ty1, ty2;
1668 GLuint prog = gc->shared->shader[SHADER_FONT].prog;
1671 pn = _evas_gl_common_context_push(RTYPE_FONT,
1679 gc->pipe[pn].region.type = RTYPE_FONT;
1680 gc->pipe[pn].shader.cur_tex = tex->pt->texture;
1681 gc->pipe[pn].shader.cur_prog = prog;
1682 gc->pipe[pn].shader.smooth = 0;
1683 gc->pipe[pn].shader.blend = 1;
1684 gc->pipe[pn].shader.render_op = gc->dc->render_op;
1685 gc->pipe[pn].shader.clip = 0;
1686 gc->pipe[pn].shader.cx = 0;
1687 gc->pipe[pn].shader.cy = 0;
1688 gc->pipe[pn].shader.cw = 0;
1689 gc->pipe[pn].shader.ch = 0;
1690 gc->pipe[pn].array.line = 0;
1691 gc->pipe[pn].array.use_vertex = 1;
1692 gc->pipe[pn].array.use_color = 1;
1693 gc->pipe[pn].array.use_texuv = 1;
1694 gc->pipe[pn].array.use_texuv2 = 0;
1695 gc->pipe[pn].array.use_texuv3 = 0;
1697 pipe_region_expand(gc, pn, x, y, w, h);
1699 pnum = gc->pipe[pn].array.num;
1700 nv = pnum * 3; nc = pnum * 4; nu = pnum * 2; nt = pnum * 4;
1701 gc->pipe[pn].array.num += 6;
1702 array_alloc(gc, pn);
1713 tx1 = ((double)(tex->x) + sx) / (double)tex->pt->w;
1714 ty1 = ((double)(tex->y) + sy) / (double)tex->pt->h;
1715 tx2 = ((double)(tex->x) + sx + sw) / (double)tex->pt->w;
1716 ty2 = ((double)(tex->y) + sy + sh) / (double)tex->pt->h;
1719 PUSH_VERTEX(pn, x , y , 0);
1720 PUSH_VERTEX(pn, x + w, y , 0);
1721 PUSH_VERTEX(pn, x , y + h, 0);
1723 PUSH_TEXUV(pn, tx1, ty1);
1724 PUSH_TEXUV(pn, tx2, ty1);
1725 PUSH_TEXUV(pn, tx1, ty2);
1727 PUSH_VERTEX(pn, x + w, y , 0);
1728 PUSH_VERTEX(pn, x + w, y + h, 0);
1729 PUSH_VERTEX(pn, x , y + h, 0);
1731 PUSH_TEXUV(pn, tx2, ty1);
1732 PUSH_TEXUV(pn, tx2, ty2);
1733 PUSH_TEXUV(pn, tx1, ty2);
1735 for (i = 0; i < 6; i++)
1737 PUSH_COLOR(pn, r, g, b, a);
1742 evas_gl_common_context_yuv_push(Evas_Engine_GL_Context *gc,
1743 Evas_GL_Texture *tex,
1744 double sx, double sy, double sw, double sh,
1745 int x, int y, int w, int h,
1746 int r, int g, int b, int a,
1749 int pnum, nv, nc, nu, nu2, nu3, nt, i;
1750 GLfloat tx1, tx2, ty1, ty2, t2x1, t2x2, t2y1, t2y2;
1751 Eina_Bool blend = 0;
1755 if (a < 255) blend = 1;
1757 prog = gc->shared->shader[evas_gl_common_shader_choice(0, NULL, r, g, b, a,
1758 SHADER_YUV_NOMUL, SHADER_YUV)].prog;
1760 pn = _evas_gl_common_context_push(RTYPE_YUV,
1768 gc->pipe[pn].region.type = RTYPE_YUV;
1769 gc->pipe[pn].shader.cur_tex = tex->pt->texture;
1770 gc->pipe[pn].shader.cur_texu = tex->ptu->texture;
1771 gc->pipe[pn].shader.cur_texv = tex->ptv->texture;
1772 gc->pipe[pn].shader.cur_prog = prog;
1773 gc->pipe[pn].shader.smooth = smooth;
1774 gc->pipe[pn].shader.blend = blend;
1775 gc->pipe[pn].shader.render_op = gc->dc->render_op;
1776 gc->pipe[pn].shader.clip = 0;
1777 gc->pipe[pn].shader.cx = 0;
1778 gc->pipe[pn].shader.cy = 0;
1779 gc->pipe[pn].shader.cw = 0;
1780 gc->pipe[pn].shader.ch = 0;
1781 gc->pipe[pn].array.line = 0;
1782 gc->pipe[pn].array.use_vertex = 1;
1783 gc->pipe[pn].array.use_color = 1;
1784 gc->pipe[pn].array.use_texuv = 1;
1785 gc->pipe[pn].array.use_texuv2 = 1;
1786 gc->pipe[pn].array.use_texuv3 = 1;
1788 pipe_region_expand(gc, pn, x, y, w, h);
1790 pnum = gc->pipe[pn].array.num;
1791 nv = pnum * 3; nc = pnum * 4; nu = pnum * 2;
1792 nu2 = pnum * 2; nu3 = pnum * 2; nt = pnum * 4;
1793 gc->pipe[pn].array.num += 6;
1794 array_alloc(gc, pn);
1796 tx1 = (sx) / (double)tex->pt->w;
1797 ty1 = (sy) / (double)tex->pt->h;
1798 tx2 = (sx + sw) / (double)tex->pt->w;
1799 ty2 = (sy + sh) / (double)tex->pt->h;
1801 t2x1 = ((sx) / 2) / (double)tex->ptu->w;
1802 t2y1 = ((sy) / 2) / (double)tex->ptu->h;
1803 t2x2 = ((sx + sw) / 2) / (double)tex->ptu->w;
1804 t2y2 = ((sy + sh) / 2) / (double)tex->ptu->h;
1806 PUSH_VERTEX(pn, x , y , 0);
1807 PUSH_VERTEX(pn, x + w, y , 0);
1808 PUSH_VERTEX(pn, x , y + h, 0);
1810 PUSH_TEXUV(pn, tx1, ty1);
1811 PUSH_TEXUV(pn, tx2, ty1);
1812 PUSH_TEXUV(pn, tx1, ty2);
1814 PUSH_TEXUV2(pn, t2x1, t2y1);
1815 PUSH_TEXUV2(pn, t2x2, t2y1);
1816 PUSH_TEXUV2(pn, t2x1, t2y2);
1818 PUSH_TEXUV3(pn, t2x1, t2y1);
1819 PUSH_TEXUV3(pn, t2x2, t2y1);
1820 PUSH_TEXUV3(pn, t2x1, t2y2);
1822 PUSH_VERTEX(pn, x + w, y , 0);
1823 PUSH_VERTEX(pn, x + w, y + h, 0);
1824 PUSH_VERTEX(pn, x , y + h, 0);
1826 PUSH_TEXUV(pn, tx2, ty1);
1827 PUSH_TEXUV(pn, tx2, ty2);
1828 PUSH_TEXUV(pn, tx1, ty2);
1830 PUSH_TEXUV2(pn, t2x2, t2y1);
1831 PUSH_TEXUV2(pn, t2x2, t2y2);
1832 PUSH_TEXUV2(pn, t2x1, t2y2);
1834 PUSH_TEXUV3(pn, t2x2, t2y1);
1835 PUSH_TEXUV3(pn, t2x2, t2y2);
1836 PUSH_TEXUV3(pn, t2x1, t2y2);
1838 for (i = 0; i < 6; i++)
1840 PUSH_COLOR(pn, r, g, b, a);
1845 evas_gl_common_context_yuy2_push(Evas_Engine_GL_Context *gc,
1846 Evas_GL_Texture *tex,
1847 double sx, double sy, double sw, double sh,
1848 int x, int y, int w, int h,
1849 int r, int g, int b, int a,
1852 int pnum, nv, nc, nu, nu2, nu3, nt, i;
1853 GLfloat tx1, tx2, ty1, ty2, t2x1, t2x2, t2y1, t2y2;
1854 Eina_Bool blend = 0;
1858 if (a < 255) blend = 1;
1860 prog = gc->shared->shader[evas_gl_common_shader_choice(0, NULL, r, g, b, a,
1861 SHADER_YUY2_NOMUL, SHADER_YUY2)].prog;
1863 pn = _evas_gl_common_context_push(RTYPE_YUY2,
1871 gc->pipe[pn].region.type = RTYPE_YUY2;
1872 gc->pipe[pn].shader.cur_tex = tex->pt->texture;
1873 gc->pipe[pn].shader.cur_texu = tex->ptuv->texture;
1874 gc->pipe[pn].shader.cur_prog = prog;
1875 gc->pipe[pn].shader.smooth = smooth;
1876 gc->pipe[pn].shader.blend = blend;
1877 gc->pipe[pn].shader.render_op = gc->dc->render_op;
1878 gc->pipe[pn].shader.clip = 0;
1879 gc->pipe[pn].shader.cx = 0;
1880 gc->pipe[pn].shader.cy = 0;
1881 gc->pipe[pn].shader.cw = 0;
1882 gc->pipe[pn].shader.ch = 0;
1883 gc->pipe[pn].array.line = 0;
1884 gc->pipe[pn].array.use_vertex = 1;
1885 gc->pipe[pn].array.use_color = 1;
1886 gc->pipe[pn].array.use_texuv = 1;
1887 gc->pipe[pn].array.use_texuv2 = 1;
1888 gc->pipe[pn].array.use_texuv3 = 0;
1890 pipe_region_expand(gc, pn, x, y, w, h);
1892 pnum = gc->pipe[pn].array.num;
1893 nv = pnum * 3; nc = pnum * 4; nu = pnum * 2;
1894 nu2 = pnum * 2; nu3 = pnum * 2; nt = pnum * 4;
1895 gc->pipe[pn].array.num += 6;
1896 array_alloc(gc, pn);
1898 tx1 = (sx) / (double)tex->pt->w;
1899 ty1 = (sy) / (double)tex->pt->h;
1900 tx2 = (sx + sw) / (double)tex->pt->w;
1901 ty2 = (sy + sh) / (double)tex->pt->h;
1903 t2x1 = sx / (double)tex->ptuv->w;
1904 t2y1 = sy / (double)tex->ptuv->h;
1905 t2x2 = (sx + sw) / (double)tex->ptuv->w;
1906 t2y2 = (sy + sh) / (double)tex->ptuv->h;
1908 PUSH_VERTEX(pn, x , y , 0);
1909 PUSH_VERTEX(pn, x + w, y , 0);
1910 PUSH_VERTEX(pn, x , y + h, 0);
1912 PUSH_TEXUV(pn, tx1, ty1);
1913 PUSH_TEXUV(pn, tx2, ty1);
1914 PUSH_TEXUV(pn, tx1, ty2);
1916 PUSH_TEXUV2(pn, t2x1, t2y1);
1917 PUSH_TEXUV2(pn, t2x2, t2y1);
1918 PUSH_TEXUV2(pn, t2x1, t2y2);
1920 PUSH_VERTEX(pn, x + w, y , 0);
1921 PUSH_VERTEX(pn, x + w, y + h, 0);
1922 PUSH_VERTEX(pn, x , y + h, 0);
1924 PUSH_TEXUV(pn, tx2, ty1);
1925 PUSH_TEXUV(pn, tx2, ty2);
1926 PUSH_TEXUV(pn, tx1, ty2);
1928 PUSH_TEXUV2(pn, t2x2, t2y1);
1929 PUSH_TEXUV2(pn, t2x2, t2y2);
1930 PUSH_TEXUV2(pn, t2x1, t2y2);
1932 for (i = 0; i < 6; i++)
1934 PUSH_COLOR(pn, r, g, b, a);
1939 evas_gl_common_context_nv12_push(Evas_Engine_GL_Context *gc,
1940 Evas_GL_Texture *tex,
1941 double sx, double sy, double sw, double sh,
1942 int x, int y, int w, int h,
1943 int r, int g, int b, int a,
1946 int pnum, nv, nc, nu, nu2, nu3, nt, i;
1947 GLfloat tx1, tx2, ty1, ty2, t2x1, t2x2, t2y1, t2y2;
1948 Eina_Bool blend = 0;
1952 if (a < 255) blend = 1;
1954 prog = gc->shared->shader[evas_gl_common_shader_choice(0, NULL, r, g, b, a,
1955 SHADER_NV12_NOMUL, SHADER_NV12)].prog;
1957 pn = _evas_gl_common_context_push(RTYPE_NV12,
1965 gc->pipe[pn].region.type = RTYPE_NV12;
1966 gc->pipe[pn].shader.cur_tex = tex->pt->texture;
1967 gc->pipe[pn].shader.cur_tex_dyn = tex->pt->dyn.img;
1968 gc->pipe[pn].shader.cur_texu = tex->ptuv->texture;
1969 gc->pipe[pn].shader.cur_texu_dyn = tex->ptuv->dyn.img;
1970 gc->pipe[pn].shader.cur_prog = prog;
1971 gc->pipe[pn].shader.smooth = smooth;
1972 gc->pipe[pn].shader.blend = blend;
1973 gc->pipe[pn].shader.render_op = gc->dc->render_op;
1974 gc->pipe[pn].shader.clip = 0;
1975 gc->pipe[pn].shader.cx = 0;
1976 gc->pipe[pn].shader.cy = 0;
1977 gc->pipe[pn].shader.cw = 0;
1978 gc->pipe[pn].shader.ch = 0;
1979 gc->pipe[pn].array.line = 0;
1980 gc->pipe[pn].array.use_vertex = 1;
1981 gc->pipe[pn].array.use_color = 1;
1982 gc->pipe[pn].array.use_texuv = 1;
1983 gc->pipe[pn].array.use_texuv2 = 1;
1984 gc->pipe[pn].array.use_texuv3 = 0;
1986 pipe_region_expand(gc, pn, x, y, w, h);
1988 pnum = gc->pipe[pn].array.num;
1989 nv = pnum * 3; nc = pnum * 4; nu = pnum * 2;
1990 nu2 = pnum * 2; nu3 = pnum * 2; nt = pnum * 4;
1991 gc->pipe[pn].array.num += 6;
1992 array_alloc(gc, pn);
1994 tx1 = (sx) / (double)tex->pt->w;
1995 ty1 = (sy) / (double)tex->pt->h;
1996 tx2 = (sx + sw) / (double)tex->pt->w;
1997 ty2 = (sy + sh) / (double)tex->pt->h;
1999 t2x1 = sx / (double)tex->ptuv->w;
2000 t2y1 = sy / (double)tex->ptuv->h;
2001 t2x2 = (sx + sw) / (double)tex->ptuv->w;
2002 t2y2 = (sy + sh) / (double)tex->ptuv->h;
2004 PUSH_VERTEX(pn, x , y , 0);
2005 PUSH_VERTEX(pn, x + w, y , 0);
2006 PUSH_VERTEX(pn, x , y + h, 0);
2008 PUSH_TEXUV(pn, tx1, ty1);
2009 PUSH_TEXUV(pn, tx2, ty1);
2010 PUSH_TEXUV(pn, tx1, ty2);
2012 PUSH_TEXUV2(pn, t2x1, t2y1);
2013 PUSH_TEXUV2(pn, t2x2, t2y1);
2014 PUSH_TEXUV2(pn, t2x1, t2y2);
2016 PUSH_VERTEX(pn, x + w, y , 0);
2017 PUSH_VERTEX(pn, x + w, y + h, 0);
2018 PUSH_VERTEX(pn, x , y + h, 0);
2020 PUSH_TEXUV(pn, tx2, ty1);
2021 PUSH_TEXUV(pn, tx2, ty2);
2022 PUSH_TEXUV(pn, tx1, ty2);
2024 PUSH_TEXUV2(pn, t2x2, t2y1);
2025 PUSH_TEXUV2(pn, t2x2, t2y2);
2026 PUSH_TEXUV2(pn, t2x1, t2y2);
2028 for (i = 0; i < 6; i++)
2030 PUSH_COLOR(pn, r, g, b, a);
2035 evas_gl_common_context_image_map_push(Evas_Engine_GL_Context *gc,
2036 Evas_GL_Texture *tex,
2039 int clip, int cx, int cy, int cw, int ch,
2040 int r, int g, int b, int a,
2041 Eina_Bool smooth, Eina_Bool tex_only,
2042 Evas_Colorspace cspace)
2044 int pnum, nv, nc, nu, nu2, nu3, nt, i;
2045 const int points[6] = { 0, 1, 2, 0, 2, 3 };
2046 int x = 0, y = 0, w = 0, h = 0, px = 0, py = 0;
2047 GLfloat tx[4], ty[4], t2x[4], t2y[4];
2048 Eina_Bool blend = 1;
2050 GLuint prog = gc->shared->shader[SHADER_IMG].prog;
2051 Eina_Bool utexture = EINA_FALSE;
2052 Eina_Bool uvtexture = EINA_FALSE;
2056 if (!tex->alpha) blend = 0;
2057 if (a < 255) blend = 1;
2060 // FIXME: nash - you didn't fix this for n points. its still all
2061 // 4 point stuff!!! grrrr.
2064 if ((A_VAL(&(p[0].col)) < 0xff) || (A_VAL(&(p[1].col)) < 0xff) ||
2065 (A_VAL(&(p[2].col)) < 0xff) || (A_VAL(&(p[3].col)) < 0xff))
2068 if ((p[0].z == p[1].z) && (p[1].z == p[2].z) && (p[2].z == p[3].z))
2071 if (!clip) cx = cy = cw = ch = 0;
2075 if (p[0].foc <= 0) flat = 1;
2080 case EVAS_COLORSPACE_YCBCR422P601_PL:
2081 case EVAS_COLORSPACE_YCBCR422P709_PL:
2082 prog = gc->shared->shader[evas_gl_common_shader_choice(npoints, p, r, g, b, a,
2083 SHADER_YUV_NOMUL, SHADER_YUV)].prog;
2084 utexture = EINA_TRUE;
2086 case EVAS_COLORSPACE_YCBCR422601_PL:
2087 prog = gc->shared->shader[evas_gl_common_shader_choice(npoints, p, r, g, b, a,
2088 SHADER_YUY2_NOMUL, SHADER_YUY2)].prog;
2089 uvtexture = EINA_TRUE;
2091 case EVAS_COLORSPACE_YCBCR420NV12601_PL:
2092 case EVAS_COLORSPACE_YCBCR420TM12601_PL:
2093 prog = gc->shared->shader[evas_gl_common_shader_choice(npoints, p, r, g, b, a,
2094 SHADER_NV12_NOMUL, SHADER_NV12)].prog;
2095 uvtexture = EINA_TRUE;
2101 if (tex->pt->dyn.img)
2103 prog = gc->shared->shader[evas_gl_common_shader_choice(npoints, p, r, g, b, a,
2104 SHADER_IMG_BGRA_NOMUL, SHADER_IMG_BGRA)].prog;
2108 prog = gc->shared->shader[evas_gl_common_shader_choice(npoints, p, r, g, b, a,
2109 SHADER_TEX_NOMUL, SHADER_TEX)].prog;
2114 if (tex->gc->shared->info.bgra)
2116 prog = gc->shared->shader[evas_gl_common_shader_choice(npoints, p, r, g, b, a,
2117 SHADER_IMG_BGRA_NOMUL,
2118 SHADER_IMG_BGRA)].prog;
2122 prog = gc->shared->shader[evas_gl_common_shader_choice(npoints, p, r, g, b, a,
2129 x = w = (p[0].x >> FP);
2130 y = h = (p[0].y >> FP);
2131 for (i = 0; i < 4; i++)
2133 tx[i] = ((double)(tex->x) + (((double)p[i].u) / FP1)) /
2135 ty[i] = ((double)(tex->y) + (((double)p[i].v) / FP1)) /
2137 px = (p[i].x >> FP);
2139 else if (px > w) w = px;
2140 py = (p[i].y >> FP);
2142 else if (py > h) h = py;
2145 t2x[i] = ((((double)p[i].u / 2) / FP1)) / (double)tex->ptu->w;
2146 t2y[i] = ((((double)p[i].v / 2) / FP1)) / (double)tex->ptu->h;
2150 t2x[i] = ((((double)p[i].u / 2) / FP1)) / (double)tex->ptuv->w;
2151 t2y[i] = ((((double)p[i].v / 2) / FP1)) / (double)tex->ptuv->h;
2159 int nx = x, ny = y, nw = w, nh = h;
2161 RECTS_CLIP_TO_RECT(nx, ny, nw, nh, cx, cy, cw, ch);
2162 if ((nx == x) && (ny == y) && (nw == w) && (nh == h))
2164 clip = 0; cx = 0; cy = 0; cw = 0; ch = 0;
2166 x = nx; y = nw; w = nw; h = nh;
2171 shader_array_flush(gc);
2172 gc->foc = p[0].foc >> FP;
2173 gc->z0 = p[0].z0 >> FP;
2174 gc->px = p[0].px >> FP;
2175 gc->py = p[0].py >> FP;
2176 gc->change.size = 1;
2177 _evas_gl_common_viewport_set(gc);
2180 pn = _evas_gl_common_context_push(RTYPE_MAP,
2186 clip, cx, cy, cw, ch);
2187 gc->pipe[pn].region.type = RTYPE_MAP;
2188 gc->pipe[pn].shader.cur_tex = tex->pt->texture;
2191 gc->pipe[pn].shader.cur_texu = tex->ptu->texture;
2192 gc->pipe[pn].shader.cur_texu_dyn = tex->ptu->dyn.img;
2193 gc->pipe[pn].shader.cur_texv = tex->ptv->texture;
2194 gc->pipe[pn].shader.cur_texv_dyn = tex->ptv->dyn.img;
2198 gc->pipe[pn].shader.cur_texu = tex->ptuv->texture;
2199 gc->pipe[pn].shader.cur_texu_dyn = tex->ptuv->dyn.img;
2201 gc->pipe[pn].shader.cur_prog = prog;
2202 gc->pipe[pn].shader.smooth = smooth;
2203 gc->pipe[pn].shader.blend = blend;
2204 gc->pipe[pn].shader.render_op = gc->dc->render_op;
2205 gc->pipe[pn].shader.clip = clip;
2206 gc->pipe[pn].shader.cx = cx;
2207 gc->pipe[pn].shader.cy = cy;
2208 gc->pipe[pn].shader.cw = cw;
2209 gc->pipe[pn].shader.ch = ch;
2210 gc->pipe[pn].array.line = 0;
2211 gc->pipe[pn].array.use_vertex = 1;
2212 gc->pipe[pn].array.use_color = 1;
2213 gc->pipe[pn].array.use_texuv = 1;
2214 gc->pipe[pn].array.use_texuv2 = (utexture || uvtexture) ? 1 : 0;
2215 gc->pipe[pn].array.use_texuv3 = (utexture) ? 1 : 0;
2217 pipe_region_expand(gc, pn, x, y, w, h);
2219 pnum = gc->pipe[pn].array.num;
2220 nv = pnum * 3; nc = pnum * 4; nu = pnum * 2; nu2 = pnum * 2;
2221 nu2 = pnum * 2; nu3 = pnum * 2; nt = pnum * 4;
2222 gc->pipe[pn].array.num += 6;
2223 array_alloc(gc, pn);
2225 if ((tex->im) && (tex->im->native.data) && (!tex->im->native.yinvert))
2227 for (i = 0; i < 4; i++)
2229 ty[i] = 1.0 - ty[i];
2230 if (utexture || uvtexture)
2231 t2y[i] = 1.0 - t2y[i];
2235 cmul = ARGB_JOIN(a, r, g, b);
2236 for (i = 0; i < 6; i++)
2238 DATA32 cl = MUL4_SYM(cmul, p[points[i]].col);
2242 (p[points[i]].x >> FP),
2243 (p[points[i]].y >> FP),
2249 (p[points[i]].fx) + gc->shared->ax,
2250 (p[points[i]].fy) + gc->shared->ay,
2252 + (gc->shared->foc - gc->shared->z0));
2281 shader_array_flush(gc);
2286 gc->change.size = 1;
2287 _evas_gl_common_viewport_set(gc);
2292 evas_gl_common_context_flush(Evas_Engine_GL_Context *gc)
2294 shader_array_flush(gc);
2298 scissor_rot(Evas_Engine_GL_Context *gc __UNUSED__,
2299 int rot, int gw, int gh, int cx, int cy, int cw, int ch)
2303 case 0: // UP this way: ^
2304 glScissor(cx, cy, cw, ch);
2306 case 90: // UP this way: <
2307 glScissor(gh - (cy + ch), cx, ch, cw);
2309 case 180: // UP this way: v
2310 glScissor(gw - (cx + cw), gh - (cy + ch), cw, ch);
2312 case 270: // UP this way: >
2313 glScissor(cy, gw - (cx + cw), ch, cw);
2315 default: // assume up is up
2316 glScissor(cx, cy, cw, ch);
2322 shader_array_flush(Evas_Engine_GL_Context *gc)
2324 int i, gw, gh, setclip, cy, fbo = 0, done = 0;
2326 if (!gc->havestuff) return;
2329 if (!((gc->pipe[0].shader.surface == gc->def_surface) ||
2330 (!gc->pipe[0].shader.surface)))
2332 gw = gc->pipe[0].shader.surface->w;
2333 gh = gc->pipe[0].shader.surface->h;
2336 for (i = 0; i < gc->shared->info.tune.pipes.max; i++)
2338 if (gc->pipe[i].array.num <= 0) break;
2342 GLERR(__FUNCTION__, __FILE__, __LINE__, "<flush err>");
2343 if (gc->pipe[i].shader.cur_prog != gc->state.current.cur_prog)
2345 glUseProgram(gc->pipe[i].shader.cur_prog);
2346 GLERR(__FUNCTION__, __FILE__, __LINE__, "");
2349 if (gc->pipe[i].shader.cur_tex != gc->state.current.cur_tex)
2352 if (gc->pipe[i].shader.cur_tex)
2354 glEnable(GL_TEXTURE_2D);
2355 GLERR(__FUNCTION__, __FILE__, __LINE__, "");
2359 glDisable(GL_TEXTURE_2D);
2360 GLERR(__FUNCTION__, __FILE__, __LINE__, "");
2363 glActiveTexture(GL_TEXTURE0);
2364 GLERR(__FUNCTION__, __FILE__, __LINE__, "");
2365 glBindTexture(GL_TEXTURE_2D, gc->pipe[i].shader.cur_tex);
2366 GLERR(__FUNCTION__, __FILE__, __LINE__, "");
2368 if (gc->pipe[i].array.im)
2370 #if defined (GLES_VARIETY_S3C6410) || defined (GLES_VARIETY_SGX)
2371 if (gc->pipe[i].array.im->tex->pt->dyn.img)
2373 secsym_glEGLImageTargetTexture2DOES
2374 (GL_TEXTURE_2D, gc->pipe[i].array.im->tex->pt->dyn.img);
2379 if (!gc->pipe[i].array.im->native.loose)
2381 if (gc->pipe[i].array.im->native.func.bind)
2382 gc->pipe[i].array.im->native.func.bind(gc->pipe[i].array.im->native.func.data,
2383 gc->pipe[i].array.im);
2387 if (gc->pipe[i].shader.render_op != gc->state.current.render_op)
2389 switch (gc->pipe[i].shader.render_op)
2391 case EVAS_RENDER_BLEND: /**< default op: d = d*(1-sa) + s */
2392 glBlendFunc(GL_ONE, GL_ONE_MINUS_SRC_ALPHA);
2393 GLERR(__FUNCTION__, __FILE__, __LINE__, "");
2395 case EVAS_RENDER_COPY: /**< d = s */
2396 gc->pipe[i].shader.blend = 0;
2397 glBlendFunc(GL_ONE, GL_ONE);
2398 GLERR(__FUNCTION__, __FILE__, __LINE__, "");
2400 // FIXME: fix blend funcs below!
2401 case EVAS_RENDER_BLEND_REL: /**< d = d*(1 - sa) + s*da */
2402 case EVAS_RENDER_COPY_REL: /**< d = s*da */
2403 case EVAS_RENDER_ADD: /**< d = d + s */
2404 case EVAS_RENDER_ADD_REL: /**< d = d + s*da */
2405 case EVAS_RENDER_SUB: /**< d = d - s */
2406 case EVAS_RENDER_SUB_REL: /**< d = d - s*da */
2407 case EVAS_RENDER_TINT: /**< d = d*s + d*(1 - sa) + s*(1 - da) */
2408 case EVAS_RENDER_TINT_REL: /**< d = d*(1 - sa + s) */
2409 case EVAS_RENDER_MASK: /**< d = d*sa */
2410 case EVAS_RENDER_MUL: /**< d = d*s */
2412 glBlendFunc(GL_ONE, GL_ONE_MINUS_SRC_ALPHA);
2413 GLERR(__FUNCTION__, __FILE__, __LINE__, "");
2417 if (gc->pipe[i].shader.blend != gc->state.current.blend)
2419 if (gc->pipe[i].shader.blend)
2422 GLERR(__FUNCTION__, __FILE__, __LINE__, "");
2426 glDisable(GL_BLEND);
2427 GLERR(__FUNCTION__, __FILE__, __LINE__, "");
2430 if ((gc->pipe[i].shader.smooth != gc->state.current.smooth) ||
2431 (gc->pipe[i].shader.cur_tex != gc->state.current.cur_tex))
2433 if (gc->pipe[i].shader.smooth)
2435 #ifdef GL_TEXTURE_MAX_ANISOTROPY_EXT
2436 if (shared->info.anisotropic > 0.0)
2438 glTexParameterf(GL_TEXTURE_2D, GL_TEXTURE_MAX_ANISOTROPY_EXT, shared->info.anisotropic);
2439 GLERR(__FUNCTION__, __FILE__, __LINE__, "");
2442 glTexParameteri(GL_TEXTURE_2D, GL_TEXTURE_MAG_FILTER, GL_LINEAR);
2443 GLERR(__FUNCTION__, __FILE__, __LINE__, "");
2444 glTexParameteri(GL_TEXTURE_2D, GL_TEXTURE_MIN_FILTER, GL_LINEAR);
2445 GLERR(__FUNCTION__, __FILE__, __LINE__, "");
2446 glTexParameteri(GL_TEXTURE_2D, GL_TEXTURE_WRAP_S, GL_CLAMP_TO_EDGE);
2447 GLERR(__FUNCTION__, __FILE__, __LINE__, "");
2448 glTexParameteri(GL_TEXTURE_2D, GL_TEXTURE_WRAP_T, GL_CLAMP_TO_EDGE);
2449 GLERR(__FUNCTION__, __FILE__, __LINE__, "");
2453 #ifdef GL_TEXTURE_MAX_ANISOTROPY_EXT
2454 if (shared->info.anisotropic > 0.0)
2456 glTexParameterf(GL_TEXTURE_2D, GL_TEXTURE_MAX_ANISOTROPY_EXT, 1.0);
2457 GLERR(__FUNCTION__, __FILE__, __LINE__, "");
2460 glTexParameteri(GL_TEXTURE_2D, GL_TEXTURE_MAG_FILTER, GL_NEAREST);
2461 GLERR(__FUNCTION__, __FILE__, __LINE__, "");
2462 glTexParameteri(GL_TEXTURE_2D, GL_TEXTURE_MIN_FILTER, GL_NEAREST);
2463 GLERR(__FUNCTION__, __FILE__, __LINE__, "");
2464 glTexParameteri(GL_TEXTURE_2D, GL_TEXTURE_WRAP_S, GL_CLAMP_TO_EDGE);
2465 GLERR(__FUNCTION__, __FILE__, __LINE__, "");
2466 glTexParameteri(GL_TEXTURE_2D, GL_TEXTURE_WRAP_T, GL_CLAMP_TO_EDGE);
2467 GLERR(__FUNCTION__, __FILE__, __LINE__, "");
2470 if (gc->pipe[i].shader.clip != gc->state.current.clip)
2473 if (gc->pipe[i].shader.clip)
2475 cy = gh - gc->pipe[i].shader.cy - gc->pipe[i].shader.ch;
2476 if (fbo) cy = gc->pipe[i].shader.cy;
2477 glEnable(GL_SCISSOR_TEST);
2479 scissor_rot(gc, gc->rot, gw, gh,
2480 gc->pipe[i].shader.cx,
2482 gc->pipe[i].shader.cw,
2483 gc->pipe[i].shader.ch);
2485 glScissor(gc->pipe[i].shader.cx, cy,
2486 gc->pipe[i].shader.cw, gc->pipe[i].shader.ch);
2491 glDisable(GL_SCISSOR_TEST);
2492 glScissor(0, 0, 0, 0);
2495 if ((gc->pipe[i].shader.clip) && (!setclip))
2497 if ((gc->pipe[i].shader.cx != gc->state.current.cx) ||
2498 (gc->pipe[i].shader.cy != gc->state.current.cy) ||
2499 (gc->pipe[i].shader.cw != gc->state.current.cw) ||
2500 (gc->pipe[i].shader.ch != gc->state.current.ch))
2502 cy = gh - gc->pipe[i].shader.cy - gc->pipe[i].shader.ch;
2503 if (fbo) cy = gc->pipe[i].shader.cy;
2505 scissor_rot(gc, gc->rot, gw, gh,
2506 gc->pipe[i].shader.cx,
2508 gc->pipe[i].shader.cw,
2509 gc->pipe[i].shader.ch);
2511 glScissor(gc->pipe[i].shader.cx, cy,
2512 gc->pipe[i].shader.cw, gc->pipe[i].shader.ch);
2516 glVertexAttribPointer(SHAD_VERTEX, 3, GL_SHORT, GL_FALSE, 0, gc->pipe[i].array.vertex);
2517 GLERR(__FUNCTION__, __FILE__, __LINE__, "");
2518 glVertexAttribPointer(SHAD_COLOR, 4, GL_UNSIGNED_BYTE, GL_TRUE, 0, gc->pipe[i].array.color);
2519 GLERR(__FUNCTION__, __FILE__, __LINE__, "");
2520 if (gc->pipe[i].array.use_texuv)
2522 glEnableVertexAttribArray(SHAD_TEXUV);
2523 GLERR(__FUNCTION__, __FILE__, __LINE__, "");
2524 glVertexAttribPointer(SHAD_TEXUV, 2, GL_FLOAT, GL_FALSE, 0, gc->pipe[i].array.texuv);
2525 GLERR(__FUNCTION__, __FILE__, __LINE__, "");
2529 glDisableVertexAttribArray(SHAD_TEXUV);
2530 GLERR(__FUNCTION__, __FILE__, __LINE__, "");
2533 if (gc->pipe[i].array.line)
2535 glDisableVertexAttribArray(SHAD_TEXUV);
2536 GLERR(__FUNCTION__, __FILE__, __LINE__, "");
2537 glDisableVertexAttribArray(SHAD_TEXUV2);
2538 GLERR(__FUNCTION__, __FILE__, __LINE__, "");
2539 glDisableVertexAttribArray(SHAD_TEXUV3);
2540 GLERR(__FUNCTION__, __FILE__, __LINE__, "");
2541 glDrawArrays(GL_LINES, 0, gc->pipe[i].array.num);
2542 GLERR(__FUNCTION__, __FILE__, __LINE__, "");
2546 if (gc->pipe[i].array.use_texm)
2548 glEnableVertexAttribArray(SHAD_TEXM);
2549 GLERR(__FUNCTION__, __FILE__, __LINE__, "");
2550 glVertexAttribPointer(SHAD_TEXM, 2, GL_FLOAT, GL_FALSE, 0, gc->pipe[i].array.texm);
2551 GLERR(__FUNCTION__, __FILE__, __LINE__, "");
2552 glActiveTexture(GL_TEXTURE1);
2553 GLERR(__FUNCTION__, __FILE__, __LINE__, "");
2554 glBindTexture(GL_TEXTURE_2D, gc->pipe[i].shader.cur_texm);
2555 GLERR(__FUNCTION__, __FILE__, __LINE__, "");
2556 glActiveTexture(GL_TEXTURE0);
2557 GLERR(__FUNCTION__, __FILE__, __LINE__, "");
2561 glDisableVertexAttribArray(SHAD_TEXM);
2563 if ((gc->pipe[i].array.use_texuv2) && (gc->pipe[i].array.use_texuv3))
2565 glEnableVertexAttribArray(SHAD_TEXUV2);
2566 GLERR(__FUNCTION__, __FILE__, __LINE__, "");
2567 glEnableVertexAttribArray(SHAD_TEXUV3);
2568 GLERR(__FUNCTION__, __FILE__, __LINE__, "");
2569 glVertexAttribPointer(SHAD_TEXUV2, 2, GL_FLOAT, GL_FALSE, 0, gc->pipe[i].array.texuv2);
2570 GLERR(__FUNCTION__, __FILE__, __LINE__, "");
2571 glVertexAttribPointer(SHAD_TEXUV3, 2, GL_FLOAT, GL_FALSE, 0, gc->pipe[i].array.texuv3);
2572 GLERR(__FUNCTION__, __FILE__, __LINE__, "");
2574 glActiveTexture(GL_TEXTURE1);
2575 GLERR(__FUNCTION__, __FILE__, __LINE__, "");
2576 glBindTexture(GL_TEXTURE_2D, gc->pipe[i].shader.cur_texu);
2577 GLERR(__FUNCTION__, __FILE__, __LINE__, "");
2578 #if defined (GLES_VARIETY_S3C6410) || defined (GLES_VARIETY_SGX)
2579 if (gc->pipe[i].shader.cur_texu_dyn)
2580 secsym_glEGLImageTargetTexture2DOES(GL_TEXTURE_2D, gc->pipe[i].shader.cur_texu_dyn);
2583 glActiveTexture(GL_TEXTURE2);
2584 GLERR(__FUNCTION__, __FILE__, __LINE__, "");
2585 glBindTexture(GL_TEXTURE_2D, gc->pipe[i].shader.cur_texv);
2586 GLERR(__FUNCTION__, __FILE__, __LINE__, "");
2587 #if defined (GLES_VARIETY_S3C6410) || defined (GLES_VARIETY_SGX)
2588 if (gc->pipe[i].shader.cur_texv_dyn)
2589 secsym_glEGLImageTargetTexture2DOES(GL_TEXTURE_2D, gc->pipe[i].shader.cur_texv_dyn);
2591 glActiveTexture(GL_TEXTURE0);
2592 GLERR(__FUNCTION__, __FILE__, __LINE__, "");
2594 else if (gc->pipe[i].array.use_texuv2)
2596 glEnableVertexAttribArray(SHAD_TEXUV2);
2597 GLERR(__FUNCTION__, __FILE__, __LINE__, "");
2598 glVertexAttribPointer(SHAD_TEXUV2, 2, GL_FLOAT, GL_FALSE, 0, gc->pipe[i].array.texuv2);
2599 GLERR(__FUNCTION__, __FILE__, __LINE__, "");
2601 glActiveTexture(GL_TEXTURE1);
2602 GLERR(__FUNCTION__, __FILE__, __LINE__, "");
2603 glBindTexture(GL_TEXTURE_2D, gc->pipe[i].shader.cur_texu);
2604 GLERR(__FUNCTION__, __FILE__, __LINE__, "");
2605 #if defined (GLES_VARIETY_S3C6410) || defined (GLES_VARIETY_SGX)
2606 if (gc->pipe[i].shader.cur_texu_dyn)
2607 secsym_glEGLImageTargetTexture2DOES(GL_TEXTURE_2D, gc->pipe[i].shader.cur_texu_dyn);
2609 glActiveTexture(GL_TEXTURE0);
2610 GLERR(__FUNCTION__, __FILE__, __LINE__, "");
2614 glDisableVertexAttribArray(SHAD_TEXUV2);
2615 GLERR(__FUNCTION__, __FILE__, __LINE__, "");
2616 glDisableVertexAttribArray(SHAD_TEXUV3);
2617 GLERR(__FUNCTION__, __FILE__, __LINE__, "");
2621 const char *types[6] =
2622 {"----", "RECT", "IMAG", "FONT", "YUV-", "MAP"};
2623 printf(" DRAW#%3i %4i -> %p[%4ix%4i] @ %4ix%4i -{ tex %4i type %s }-\n",
2625 gc->pipe[i].array.num / 6,
2626 gc->pipe[0].shader.surface,
2627 gc->pipe[0].shader.surface->w,
2628 gc->pipe[0].shader.surface->h,
2630 gc->pipe[i].shader.cur_tex,
2631 types[gc->pipe[i].region.type]
2634 glDrawArrays(GL_TRIANGLES, 0, gc->pipe[i].array.num);
2635 GLERR(__FUNCTION__, __FILE__, __LINE__, "");
2637 if (gc->pipe[i].array.im)
2639 if (!gc->pipe[i].array.im->native.loose)
2641 if (gc->pipe[i].array.im->native.func.unbind)
2642 gc->pipe[i].array.im->native.func.unbind(gc->pipe[i].array.im->native.func.data,
2643 gc->pipe[i].array.im);
2645 gc->pipe[i].array.im = NULL;
2648 gc->state.current.cur_prog = gc->pipe[i].shader.cur_prog;
2649 gc->state.current.cur_tex = gc->pipe[i].shader.cur_tex;
2650 gc->state.current.render_op = gc->pipe[i].shader.render_op;
2651 gc->state.current.cx = gc->pipe[i].shader.cx;
2652 gc->state.current.cy = gc->pipe[i].shader.cy;
2653 gc->state.current.cw = gc->pipe[i].shader.cw;
2654 gc->state.current.ch = gc->pipe[i].shader.ch;
2655 gc->state.current.smooth = gc->pipe[i].shader.smooth;
2656 gc->state.current.blend = gc->pipe[i].shader.blend;
2657 gc->state.current.clip = gc->pipe[i].shader.clip;
2659 if (gc->pipe[i].array.vertex) free(gc->pipe[i].array.vertex);
2660 if (gc->pipe[i].array.color) free(gc->pipe[i].array.color);
2661 if (gc->pipe[i].array.texuv) free(gc->pipe[i].array.texuv);
2662 if (gc->pipe[i].array.texm) free(gc->pipe[i].array.texm);
2663 if (gc->pipe[i].array.texuv2) free(gc->pipe[i].array.texuv2);
2664 if (gc->pipe[i].array.texuv3) free(gc->pipe[i].array.texuv3);
2666 gc->pipe[i].array.vertex = NULL;
2667 gc->pipe[i].array.color = NULL;
2668 gc->pipe[i].array.texuv = NULL;
2669 gc->pipe[i].array.texm = NULL;
2670 gc->pipe[i].array.texuv2 = NULL;
2671 gc->pipe[i].array.texuv3 = NULL;
2673 gc->pipe[i].array.num = 0;
2674 gc->pipe[i].array.alloc = 0;
2676 gc->pipe[i].region.x = 0;
2677 gc->pipe[i].region.y = 0;
2678 gc->pipe[i].region.w = 0;
2679 gc->pipe[i].region.h = 0;
2680 gc->pipe[i].region.type = 0;
2682 gc->state.top_pipe = 0;
2685 if (done > 0) printf("DONE (pipes): %i\n", done);
2687 gc->havestuff = EINA_FALSE;
2691 evas_gl_common_module_open(void)
2693 if (_evas_engine_GL_common_log_dom < 0)
2694 _evas_engine_GL_common_log_dom = eina_log_domain_register
2695 ("evas-gl_common", EVAS_DEFAULT_LOG_COLOR);
2696 if (_evas_engine_GL_common_log_dom < 0)
2698 EINA_LOG_ERR("Can not create a module log domain.");
2705 evas_gl_common_module_close(void)
2707 if (_evas_engine_GL_common_log_dom < 0) return;
2708 eina_log_domain_unregister(_evas_engine_GL_common_log_dom);
2709 _evas_engine_GL_common_log_dom = -1;