1 #include "evas_gl_private.h"
4 # include <dlfcn.h> /* dlopen,dlclose,etc */
6 # error gl_common should not get compiled if dlsym is not found on the system!
9 #define PRG_INVALID 0xffffffff
12 static int sym_done = 0;
13 int _evas_engine_GL_common_log_dom = -1;
15 typedef void (*glsym_func_void) ();
17 void (*glsym_glGenFramebuffers) (GLsizei a, GLuint *b) = NULL;
18 void (*glsym_glBindFramebuffer) (GLenum a, GLuint b) = NULL;
19 void (*glsym_glFramebufferTexture2D) (GLenum a, GLenum b, GLenum c, GLuint d, GLint e) = NULL;
20 void (*glsym_glDeleteFramebuffers) (GLsizei a, const GLuint *b) = NULL;
21 void (*glsym_glGetProgramBinary) (GLuint a, GLsizei b, GLsizei *c, GLenum *d, void *e) = NULL;
22 void (*glsym_glProgramBinary) (GLuint a, GLenum b, const void *c, GLint d) = NULL;
23 void (*glsym_glProgramParameteri) (GLuint a, GLuint b, GLint d) = NULL;
24 void (*glsym_glReleaseShaderCompiler)(void) = NULL;
26 #if defined (GLES_VARIETY_S3C6410) || defined (GLES_VARIETY_SGX)
27 // just used for finding symbols :)
28 typedef void (*_eng_fn) (void);
30 typedef _eng_fn (*secsym_func_eng_fn) ();
31 typedef unsigned int (*secsym_func_uint) ();
32 typedef void *(*secsym_func_void_ptr) ();
34 static _eng_fn (*secsym_eglGetProcAddress) (const char *a) = NULL;
36 void *(*secsym_eglCreateImage) (void *a, void *b, GLenum c, void *d, const int *e) = NULL;
37 unsigned int (*secsym_eglDestroyImage) (void *a, void *b) = NULL;
38 void (*secsym_glEGLImageTargetTexture2DOES) (int a, void *b) = NULL;
39 void *(*secsym_eglMapImageSEC) (void *a, void *b) = NULL;
40 unsigned int (*secsym_eglUnmapImageSEC) (void *a, void *b) = NULL;
41 unsigned int (*secsym_eglGetImageAttribSEC) (void *a, void *b, int c, int *d) = NULL;
44 static int dbgflushnum = -1;
49 ERR("GL symbols missing!");
58 /* FIXME: If using the SDL engine, we should use SDL_GL_GetProcAddress
60 * if (!dst) dst = (typ)SDL_GL_GetProcAddress(sym)
62 #define FINDSYM(dst, sym, typ) if (!dst) dst = (typ)dlsym(RTLD_DEFAULT, sym)
63 #define FALLBAK(dst, typ) if (!dst) dst = (typ)sym_missing;
65 FINDSYM(glsym_glGenFramebuffers, "glGenFramebuffers", glsym_func_void);
66 FINDSYM(glsym_glGenFramebuffers, "glGenFramebuffersEXT", glsym_func_void);
67 FINDSYM(glsym_glGenFramebuffers, "glGenFramebuffersARB", glsym_func_void);
68 FALLBAK(glsym_glGenFramebuffers, glsym_func_void);
70 FINDSYM(glsym_glBindFramebuffer, "glBindFramebuffer", glsym_func_void);
71 FINDSYM(glsym_glBindFramebuffer, "glBindFramebufferEXT", glsym_func_void);
72 FINDSYM(glsym_glBindFramebuffer, "glBindFramebufferARB", glsym_func_void);
73 FALLBAK(glsym_glBindFramebuffer, glsym_func_void);
75 FINDSYM(glsym_glFramebufferTexture2D, "glFramebufferTexture2D", glsym_func_void);
76 FINDSYM(glsym_glFramebufferTexture2D, "glFramebufferTexture2DEXT", glsym_func_void);
77 FINDSYM(glsym_glFramebufferTexture2D, "glFramebufferTexture2DARB", glsym_func_void);
78 FALLBAK(glsym_glFramebufferTexture2D, glsym_func_void);
80 FINDSYM(glsym_glDeleteFramebuffers, "glDeleteFramebuffers", glsym_func_void);
81 FINDSYM(glsym_glDeleteFramebuffers, "glDeleteFramebuffersEXT", glsym_func_void);
82 FINDSYM(glsym_glDeleteFramebuffers, "glDeleteFramebuffersARB", glsym_func_void);
83 FALLBAK(glsym_glDeleteFramebuffers, glsym_func_void);
85 FINDSYM(glsym_glGetProgramBinary, "glGetProgramBinary", glsym_func_void);
86 FINDSYM(glsym_glGetProgramBinary, "glGetProgramBinaryEXT", glsym_func_void);
87 FINDSYM(glsym_glGetProgramBinary, "glGetProgramBinaryARB", glsym_func_void);
88 FINDSYM(glsym_glGetProgramBinary, "glGetProgramBinaryOES", glsym_func_void);
90 FINDSYM(glsym_glProgramBinary, "glProgramBinary", glsym_func_void);
91 FINDSYM(glsym_glProgramBinary, "glProgramBinaryEXT", glsym_func_void);
92 FINDSYM(glsym_glProgramBinary, "glProgramBinaryARB", glsym_func_void);
94 FINDSYM(glsym_glProgramParameteri, "glProgramParameteri", glsym_func_void);
95 FINDSYM(glsym_glProgramParameteri, "glProgramParameteriEXT", glsym_func_void);
96 FINDSYM(glsym_glProgramParameteri, "glProgramParameteriARB", glsym_func_void);
98 FINDSYM(glsym_glReleaseShaderCompiler, "glReleaseShaderCompiler", glsym_func_void);
99 FINDSYM(glsym_glReleaseShaderCompiler, "glReleaseShaderCompilerEXT", glsym_func_void);
100 FINDSYM(glsym_glReleaseShaderCompiler, "glReleaseShaderCompilerARB", glsym_func_void);
102 #if defined (GLES_VARIETY_S3C6410) || defined (GLES_VARIETY_SGX)
104 #define FINDSYM(dst, sym, typ) \
105 if ((!dst) && (secsym_eglGetProcAddress)) dst = (typ)secsym_eglGetProcAddress(sym); \
106 if (!dst) dst = (typ)dlsym(RTLD_DEFAULT, sym)
107 // yes - gl core looking for egl stuff. i know it's odd. a reverse-layer thing
108 // but it will work as the egl/glx layer calls gl core common stuff and thus
109 // these symbols will work. making the glx/egl + x11 layer do this kind-of is
110 // wrong as this is not x11 (output) layer specific like the native surface
111 // stuff. this is generic zero-copy textures for gl
113 FINDSYM(secsym_eglGetProcAddress, "eglGetProcAddress", secsym_func_eng_fn);
114 FINDSYM(secsym_eglGetProcAddress, "eglGetProcAddressEXT", secsym_func_eng_fn);
115 FINDSYM(secsym_eglGetProcAddress, "eglGetProcAddressARB", secsym_func_eng_fn);
116 FINDSYM(secsym_eglGetProcAddress, "eglGetProcAddressKHR", secsym_func_eng_fn);
118 FINDSYM(secsym_eglCreateImage, "eglCreateImage", secsym_func_void_ptr);
119 FINDSYM(secsym_eglCreateImage, "eglCreateImageEXT", secsym_func_void_ptr);
120 FINDSYM(secsym_eglCreateImage, "eglCreateImageARB", secsym_func_void_ptr);
121 FINDSYM(secsym_eglCreateImage, "eglCreateImageKHR", secsym_func_void_ptr);
123 FINDSYM(secsym_eglDestroyImage, "eglDestroyImage", secsym_func_uint);
124 FINDSYM(secsym_eglDestroyImage, "eglDestroyImageEXT", secsym_func_uint);
125 FINDSYM(secsym_eglDestroyImage, "eglDestroyImageARB", secsym_func_uint);
126 FINDSYM(secsym_eglDestroyImage, "eglDestroyImageKHR", secsym_func_uint);
128 FINDSYM(glsym_glGetProgramBinary, "glGetProgramBinary", glsym_func_void);
129 FINDSYM(glsym_glGetProgramBinary, "glGetProgramBinaryEXT", glsym_func_void);
130 FINDSYM(glsym_glGetProgramBinary, "glGetProgramBinaryARB", glsym_func_void);
131 FINDSYM(glsym_glGetProgramBinary, "glGetProgramBinaryOES", glsym_func_void);
132 FINDSYM(glsym_glGetProgramBinary, "glGetProgramBinaryKHR", glsym_func_void);
134 FINDSYM(glsym_glProgramBinary, "glProgramBinary", glsym_func_void);
135 FINDSYM(glsym_glProgramBinary, "glProgramBinaryEXT", glsym_func_void);
136 FINDSYM(glsym_glProgramBinary, "glProgramBinaryARB", glsym_func_void);
137 FINDSYM(glsym_glProgramBinary, "glProgramBinaryOES", glsym_func_void);
138 FINDSYM(glsym_glProgramBinary, "glProgramBinaryKHR", glsym_func_void);
140 FINDSYM(glsym_glProgramParameteri, "glProgramParameteri", glsym_func_void);
141 FINDSYM(glsym_glProgramParameteri, "glProgramParameteriEXT", glsym_func_void);
142 FINDSYM(glsym_glProgramParameteri, "glProgramParameteriARB", glsym_func_void);
143 FINDSYM(glsym_glProgramParameteri, "glProgramParameteriOES", glsym_func_void);
144 FINDSYM(glsym_glProgramParameteri, "glProgramParameteriKHR", glsym_func_void);
146 FINDSYM(secsym_glEGLImageTargetTexture2DOES, "glEGLImageTargetTexture2DOES", glsym_func_void);
148 FINDSYM(secsym_eglMapImageSEC, "eglMapImageSEC", secsym_func_void_ptr);
150 FINDSYM(secsym_eglUnmapImageSEC, "eglUnmapImageSEC", secsym_func_uint);
152 FINDSYM(secsym_eglGetImageAttribSEC, "eglGetImageAttribSEC", secsym_func_uint);
156 static void shader_array_flush(Evas_Engine_GL_Context *gc);
158 static Evas_Engine_GL_Context *_evas_gl_common_context = NULL;
159 static Evas_GL_Shared *shared = NULL;
162 glerr(int err, const char *file, const char *func, int line, const char *op)
169 case GL_INVALID_ENUM:
170 errmsg = "GL_INVALID_ENUM";
172 case GL_INVALID_VALUE:
173 errmsg = "GL_INVALID_VALUE";
175 case GL_INVALID_OPERATION:
176 errmsg = "GL_INVALID_OPERATION";
178 case GL_OUT_OF_MEMORY:
179 errmsg = "GL_OUT_OF_MEMORY";
182 snprintf(buf, sizeof(buf), "%#x", err);
186 eina_log_print(_evas_engine_GL_common_log_dom, EINA_LOG_LEVEL_ERR,
187 file, func, line, "%s: %s", op, errmsg);
191 matrix_ortho(GLfloat *m,
192 GLfloat l, GLfloat r,
193 GLfloat t, GLfloat b,
194 GLfloat near, GLfloat far,
195 int rot, int vw, int vh,
196 int foc, GLfloat orth)
202 rotf = (((rot / 90) & 0x3) * M_PI) / 2.0;
204 tx = -0.5 * (1.0 - orth);
205 ty = -0.5 * (1.0 - orth);
226 m[0] = (2.0 / (r - l)) * ( cosv);
227 m[1] = (2.0 / (r - l)) * ( sinv);
231 m[4] = (2.0 / (t - b)) * (-sinv);
232 m[5] = (2.0 / (t - b)) * ( cosv);
238 m[10] = -(2.0 / (far - near));
239 m[11] = 1.0 / (GLfloat)foc;
241 m[12] = (m[0] * tx) + (m[4] * ty) - ((r + l) / (r - l));
242 m[13] = (m[1] * tx) + (m[5] * ty) - ((t + b) / (t - b));
243 m[14] = (m[2] * tx) + (m[6] * ty) - ((near + far) / (far - near));
244 m[15] = (m[3] * tx) + (m[7] * ty) + orth;
248 _evas_gl_common_version_check()
257 * glGetString returns a string describing the current GL connection.
258 * GL_VERSION is used to get the version of the connection
261 version = (char *)glGetString(GL_VERSION);
268 * OpenGL ES-<profile> <major>.<minor>
270 * where <profile> is either "CM" or "CL". The minor can be followed by the vendor
271 * specific information
275 * OpenGL<space>ES<space><version number><space><vendor-specific information>
278 /* OpenGL ES 1.* ? */
280 if ((tmp = strstr(version, "OpenGL ES-CM ")) || (tmp = strstr(version, "OpenGL ES-CL ")))
286 /* OpenGL ES 2.* ? */
288 if ((tmp = strstr(version, "OpenGL ES ")))
297 * The GL_VERSION and GL_SHADING_LANGUAGE_VERSION strings begin with a
298 * version number. The version number uses one of these forms:
300 * major_number.minor_number
301 * major_number.minor_number.release_number
303 * Vendor-specific information may follow the version number. Its format
304 * depends on the implementation, but a space always separates the
305 * version number and the vendor-specific information.
308 /* glGetString() returns a static string, and we are going to */
309 /* modify it, so we get a copy first */
310 version = strdup(version);
314 tmp = strchr(version, '.');
315 /* the first '.' always exists */
317 major = atoi(version);
318 /* FIXME: maybe we can assume that minor in only a cipher */
320 while ((*tmp != '.') && (*tmp != ' ') && (*tmp != '\0'))
322 /* *tmp is '\0' : version is major_number.minor_number */
323 /* *tmp is '.' : version is major_number.minor_number.release_number */
324 /* *tmp is ' ' : version is major_number.minor_number followed by vendor */
329 if (((major == 1) && (minor >= 4)) || (major >= 2))
336 _evas_gl_common_viewport_set(Evas_Engine_GL_Context *gc)
340 int w = 1, h = 1, m = 1, rot = 1, foc = 0;
342 EINA_SAFETY_ON_NULL_RETURN(gc);
344 // surface in pipe 0 will be the same as all pipes
345 if ((gc->pipe[0].shader.surface == gc->def_surface) ||
346 (!gc->pipe[0].shader.surface))
354 w = gc->pipe[0].shader.surface->w;
355 h = gc->pipe[0].shader.surface->h;
360 if ((!gc->change.size) ||
361 ((gc->shared->w == w) && (gc->shared->h == h) &&
362 (gc->shared->rot == rot) && (gc->shared->foc == gc->foc) &&
363 (gc->shared->mflip == m)))
368 gc->shared->rot = rot;
369 gc->shared->mflip = m;
370 gc->shared->foc = foc;
371 gc->shared->z0 = gc->z0;
372 gc->shared->px = gc->px;
373 gc->shared->py = gc->py;
378 if ((rot == 0) || (rot == 180))
379 glViewport(0, 0, w, h);
381 glViewport(0, 0, h, w);
382 GLERR(__FUNCTION__, __FILE__, __LINE__, "");
387 -1000000.0, 1000000.0,
390 // v flipped matrix for render-to-texture
394 -1000000.0, 1000000.0,
400 int px, py, vx, vy, vw = 0, vh = 0, ax = 0, ay = 0, ppx = 0, ppy = 0;
405 if ((rot == 0 ) || (rot == 90 )) ppx = px;
406 else if ((rot == 180) || (rot == 270)) ppx = w - px;
407 if ((rot == 0 ) || (rot == 270)) ppy = py;
408 else if ((rot == 90 ) || (rot == 180)) ppy = h - py;
410 vx = ((w / 2) - ppx);
414 if ((rot == 0 ) || (rot == 90 )) ax = 2 * vx;
415 else if ((rot == 180) || (rot == 270)) ax = 0;
420 if ((rot == 0 ) || (rot == 90 )) ax = 0;
421 else if ((rot == 180) || (rot == 270)) ax = ppx - px;
425 vy = ((h / 2) - ppy);
429 if ((rot == 0 )) ay = 0;
430 else if ((rot == 90 ) || (rot == 180) || (rot == 270)) ay = ppy - py;
436 if ((rot == 0 ) || (rot == 270)) ay = 2 * vy;
437 else if ((rot == 90 ) || (rot == 180)) ay = 0;
441 if (m == -1) ay = vy * 2;
443 if ((rot == 0) || (rot == 180))
444 glViewport(-2 * vx, -2 * vy, vw, vh);
446 glViewport(-2 * vy, -2 * vx, vh, vw);
448 matrix_ortho(proj, 0, vw, 0, vh,
449 -1000000.0, 1000000.0,
453 matrix_ortho(proj, 0, vw, vh, 0,
454 -1000000.0, 1000000.0,
461 for (i = 0; i < SHADER_LAST; ++i)
463 glUseProgram(gc->shared->shader[i].prog);
464 GLERR(__FUNCTION__, __FILE__, __LINE__, "");
465 glUniformMatrix4fv(glGetUniformLocation(gc->shared->shader[i].prog, "mvp"), 1, GL_FALSE, proj);
466 GLERR(__FUNCTION__, __FILE__, __LINE__, "");
469 if (gc->state.current.cur_prog == PRG_INVALID)
470 glUseProgram(gc->shared->shader[0].prog);
471 else glUseProgram(gc->state.current.cur_prog);
472 GLERR(__FUNCTION__, __FILE__, __LINE__, "");
475 Evas_Engine_GL_Context *
476 evas_gl_common_context_new(void)
478 Evas_Engine_GL_Context *gc;
483 if (_evas_gl_common_context)
485 _evas_gl_common_context->references++;
486 return _evas_gl_common_context;
489 if (!_evas_gl_common_version_check())
491 gc = calloc(1, sizeof(Evas_Engine_GL_Context));
492 if (!gc) return NULL;
498 _evas_gl_common_context = gc;
500 for (i = 0; i < MAX_PIPES; i++)
501 gc->pipe[i].shader.render_op = EVAS_RENDER_BLEND;
507 shared = calloc(1, sizeof(Evas_GL_Shared));
508 ext = glGetString(GL_EXTENSIONS);
511 if (getenv("EVAS_GL_INFO"))
512 fprintf(stderr, "EXT:\n%s\n", ext);
513 if ((strstr((char *)ext, "GL_ARB_texture_non_power_of_two")) ||
514 (strstr((char *)ext, "OES_texture_npot")) ||
515 (strstr((char *)ext, "GL_IMG_texture_npot")))
516 shared->info.tex_npo2 = 1;
517 if ((strstr((char *)ext, "GL_NV_texture_rectangle")) ||
518 (strstr((char *)ext, "GL_EXT_texture_rectangle")) ||
519 (strstr((char *)ext, "GL_ARB_texture_rectangle")))
520 shared->info.tex_rect = 1;
521 if ((strstr((char *)ext, "GL_ARB_get_program_binary")) ||
522 (strstr((char *)ext, "GL_OES_get_program_binary")))
523 shared->info.bin_program = 1;
524 #ifdef GL_TEXTURE_MAX_ANISOTROPY_EXT
525 if ((strstr((char *)ext, "GL_EXT_texture_filter_anisotropic")))
526 glGetFloatv(GL_MAX_TEXTURE_MAX_ANISOTROPY_EXT,
527 &(shared->info.anisotropic));
530 if ((strstr((char *)ext, "GL_EXT_bgra")) ||
531 (strstr((char *)ext, "GL_EXT_texture_format_BGRA8888")))
532 shared->info.bgra = 1;
534 #if defined (GLES_VARIETY_S3C6410) || defined (GLES_VARIETY_SGX)
535 // FIXME: there should be an extension name/string to check for
536 // not just symbols in the lib
538 s = getenv("EVAS_GL_NO_MAP_IMAGE_SEC");
542 // test for all needed symbols - be "conservative" and
544 if ((secsym_eglCreateImage) &&
545 (secsym_eglDestroyImage) &&
546 (secsym_glEGLImageTargetTexture2DOES) &&
547 (secsym_eglMapImageSEC) &&
548 (secsym_eglUnmapImageSEC) &&
549 (secsym_eglGetImageAttribSEC))
550 shared->info.sec_image_map = 1;
554 glGetIntegerv(GL_MAX_TEXTURE_IMAGE_UNITS,
555 &(shared->info.max_texture_units));
556 glGetIntegerv(GL_MAX_TEXTURE_SIZE,
557 &(shared->info.max_texture_size));
558 shared->info.max_vertex_elements = 6 * 100000;
559 #ifdef GL_MAX_ELEMENTS_VERTICES
560 /* only applies to glDrawRangeElements. don't really need to get it.
561 glGetIntegerv(GL_MAX_ELEMENTS_VERTICES,
562 &(shared->info.max_vertex_elements));
565 s = getenv("EVAS_GL_VERTEX_MAX");
566 if (s) shared->info.max_vertex_elements = atoi(s);
567 if (shared->info.max_vertex_elements < 6)
568 shared->info.max_vertex_elements = 6;
570 // magic numbers that are a result of imperical testing and getting
571 // "best case" performance across a range of systems
572 shared->info.tune.cutout.max = DEF_CUTOUT;
573 shared->info.tune.pipes.max = DEF_PIPES;
574 shared->info.tune.atlas.max_alloc_size = DEF_ATLAS_ALLOC;
575 shared->info.tune.atlas.max_alloc_alpha_size = DEF_ATLAS_ALLOC_ALPHA;
576 shared->info.tune.atlas.max_w = DEF_ATLAS_W;
577 shared->info.tune.atlas.max_h = DEF_ATLAS_H;
578 shared->info.tune.atlas.slot_size = DEF_ATLAS_SLOT;
580 // per gpu hacks. based on impirical measurement of some known gpu's
581 s = (const char *)glGetString(GL_RENDERER);
584 if (strstr(s, "PowerVR SGX 540"))
585 shared->info.tune.pipes.max = DEF_PIPES_SGX_540;
586 else if (strstr(s, "NVIDIA Tegra"))
587 shared->info.tune.pipes.max = DEF_PIPES_TEGRA_2;
590 #define GETENVOPT(name, tune_param, min, max) \
592 const char *__v = getenv(name); \
594 shared->info.tune.tune_param = atoi(__v); \
595 if (shared->info.tune.tune_param > max) \
596 shared->info.tune.tune_param = max; \
597 else if (shared->info.tune.tune_param < min) \
598 shared->info.tune.tune_param = min; \
602 GETENVOPT("EVAS_GL_CUTOUT_MAX", cutout.max, -1, 0x7fffffff);
603 GETENVOPT("EVAS_GL_PIPES_MAX", pipes.max, 1, MAX_PIPES);
604 GETENVOPT("EVAS_GL_ATLAS_ALLOC_SIZE", atlas.max_alloc_size, MIN_ATLAS_ALLOC, MAX_ATLAS_ALLOC);
605 GETENVOPT("EVAS_GL_ATLAS_ALLOC_ALPHA_SIZE", atlas.max_alloc_alpha_size, MIN_ATLAS_ALLOC_ALPHA, MAX_ATLAS_ALLOC_ALPHA);
606 GETENVOPT("EVAS_GL_ATLAS_MAX_W", atlas.max_w, 0, MAX_ATLAS_W);
607 GETENVOPT("EVAS_GL_ATLAS_MAX_H", atlas.max_h, 0, MAX_ATLAS_H);
608 GETENVOPT("EVAS_GL_ATLAS_SLOT_SIZE", atlas.slot_size, MIN_ATLAS_SLOT, MAX_ATLAS_SLOT);
609 s = (const char *)getenv("EVAS_GL_GET_PROGRAM_BINARY");
612 if (atoi(s) == 0) shared->info.bin_program = 0;
615 if (getenv("EVAS_GL_INFO"))
617 "max tex size %ix%i\n"
619 "non-power-2 tex %i\n"
622 "max ansiotropic filtering: %3.3f\n"
623 "egl sec map image: %i\n"
624 "max vertex count: %i\n"
626 "(can set EVAS_GL_VERTEX_MAX EVAS_GL_NO_MAP_IMAGE_SEC EVAS_GL_INFO EVAS_GL_MEMINFO )\n"
628 "EVAS_GL_GET_PROGRAM_BINARY: %i\n"
629 "EVAS_GL_CUTOUT_MAX: %i\n"
630 "EVAS_GL_PIPES_MAX: %i\n"
631 "EVAS_GL_ATLAS_ALLOC_SIZE: %i\n"
632 "EVAS_GL_ATLAS_ALLOC_ALPHA_SIZE: %i\n"
633 "EVAS_GL_ATLAS_MAX_W x EVAS_GL_ATLAS_MAX_H: %i x %i\n"
634 "EVAS_GL_ATLAS_SLOT_SIZE: %i\n"
636 (int)shared->info.max_texture_size, (int)shared->info.max_texture_size,
637 (int)shared->info.max_texture_units,
638 (int)shared->info.tex_npo2,
639 (int)shared->info.tex_rect,
640 (int)shared->info.bgra,
641 (double)shared->info.anisotropic,
642 (int)shared->info.sec_image_map,
643 (int)shared->info.max_vertex_elements,
645 (int)shared->info.bin_program,
646 (int)shared->info.tune.cutout.max,
647 (int)shared->info.tune.pipes.max,
648 (int)shared->info.tune.atlas.max_alloc_size,
649 (int)shared->info.tune.atlas.max_alloc_alpha_size,
650 (int)shared->info.tune.atlas.max_w, (int)shared->info.tune.atlas.max_h,
651 (int)shared->info.tune.atlas.slot_size
654 glDisable(GL_DEPTH_TEST);
655 GLERR(__FUNCTION__, __FILE__, __LINE__, "");
657 GLERR(__FUNCTION__, __FILE__, __LINE__, "");
659 GLERR(__FUNCTION__, __FILE__, __LINE__, "");
660 glBlendFunc(GL_ONE, GL_ONE_MINUS_SRC_ALPHA);
661 GLERR(__FUNCTION__, __FILE__, __LINE__, "");
663 // glBlendFunc(GL_SRC_ALPHA, GL_ONE_MINUS_SRC_ALPHA); // dest alpha
664 // glBlendFunc(GL_SRC_ALPHA, GL_ONE); // ???
665 glDepthMask(GL_FALSE);
666 GLERR(__FUNCTION__, __FILE__, __LINE__, "");
668 glTexParameteri(GL_TEXTURE_2D, GL_TEXTURE_MAG_FILTER, GL_NEAREST);
669 GLERR(__FUNCTION__, __FILE__, __LINE__, "");
670 glTexParameteri(GL_TEXTURE_2D, GL_TEXTURE_MIN_FILTER, GL_NEAREST);
671 GLERR(__FUNCTION__, __FILE__, __LINE__, "");
672 glTexParameteri(GL_TEXTURE_2D, GL_TEXTURE_WRAP_S, GL_CLAMP_TO_EDGE);
673 GLERR(__FUNCTION__, __FILE__, __LINE__, "");
674 glTexParameteri(GL_TEXTURE_2D, GL_TEXTURE_WRAP_T, GL_CLAMP_TO_EDGE);
675 GLERR(__FUNCTION__, __FILE__, __LINE__, "");
676 #ifdef GL_TEXTURE_MAX_ANISOTROPY_EXT
677 if (shared->info.anisotropic > 0.0)
679 glTexParameterf(GL_TEXTURE_2D, GL_TEXTURE_MAX_ANISOTROPY_EXT, 1.0);
680 GLERR(__FUNCTION__, __FILE__, __LINE__, "");
684 glEnableVertexAttribArray(SHAD_VERTEX);
685 GLERR(__FUNCTION__, __FILE__, __LINE__, "");
686 glEnableVertexAttribArray(SHAD_COLOR);
687 GLERR(__FUNCTION__, __FILE__, __LINE__, "");
689 if (!evas_gl_common_shader_program_init(shared)) goto error;
691 #define SHADER_TEXTURE_ADD(Shared, Shader, Name) \
692 glUseProgram(Shared->shader[SHADER_##Shader].prog); \
693 GLERR(__FUNCTION__, __FILE__, __LINE__, ""); \
694 glUniform1i(glGetUniformLocation(Shared->shader[SHADER_##Shader].prog, #Name), Shared->shader[SHADER_##Shader].tex_count++); \
695 GLERR(__FUNCTION__, __FILE__, __LINE__, "");
697 SHADER_TEXTURE_ADD(shared, YUV, tex);
698 SHADER_TEXTURE_ADD(shared, YUV, texu);
699 SHADER_TEXTURE_ADD(shared, YUV, texv);
701 SHADER_TEXTURE_ADD(shared, YUY2, tex);
702 SHADER_TEXTURE_ADD(shared, YUY2, texuv);
704 SHADER_TEXTURE_ADD(shared, NV12, tex);
705 SHADER_TEXTURE_ADD(shared, NV12, texuv);
707 SHADER_TEXTURE_ADD(shared, YUV_NOMUL, tex);
708 SHADER_TEXTURE_ADD(shared, YUV_NOMUL, texu);
709 SHADER_TEXTURE_ADD(shared, YUV_NOMUL, texv);
711 SHADER_TEXTURE_ADD(shared, YUY2_NOMUL, tex);
712 SHADER_TEXTURE_ADD(shared, YUY2_NOMUL, texuv);
714 SHADER_TEXTURE_ADD(shared, NV12_NOMUL, tex);
715 SHADER_TEXTURE_ADD(shared, NV12_NOMUL, texuv);
717 SHADER_TEXTURE_ADD(shared, IMG_MASK, tex);
718 SHADER_TEXTURE_ADD(shared, IMG_MASK, texm);
720 if (gc->state.current.cur_prog == PRG_INVALID)
721 glUseProgram(gc->shared->shader[0].prog);
722 else glUseProgram(gc->state.current.cur_prog);
723 GLERR(__FUNCTION__, __FILE__, __LINE__, "");
725 evas_gl_common_shader_program_init_done();
727 // uniform sampler2D tex[8];
731 // GLint loc = glGetUniformLocation(prog, "tex");
732 // glUniform1iv(loc, 8, texes);
734 shared->native_pm_hash = eina_hash_int32_new(NULL);
735 shared->native_tex_hash = eina_hash_int32_new(NULL);
738 gc->shared->references++;
739 _evas_gl_common_viewport_set(gc);
741 gc->def_surface = evas_gl_common_image_surface_new(gc, 1, 1, 1);
745 evas_gl_common_context_free(gc);
750 evas_gl_common_context_free(Evas_Engine_GL_Context *gc)
756 if (gc->references > 0) return;
757 if (gc->shared) gc->shared->references--;
759 if (gc->def_surface) evas_gl_common_image_free(gc->def_surface);
763 for (i = 0; i < gc->shared->info.tune.pipes.max; i++)
765 if (gc->pipe[i].array.vertex) free(gc->pipe[i].array.vertex);
766 if (gc->pipe[i].array.color) free(gc->pipe[i].array.color);
767 if (gc->pipe[i].array.texuv) free(gc->pipe[i].array.texuv);
768 if (gc->pipe[i].array.texm) free(gc->pipe[i].array.texm);
769 if (gc->pipe[i].array.texuv2) free(gc->pipe[i].array.texuv2);
770 if (gc->pipe[i].array.texuv3) free(gc->pipe[i].array.texuv3);
774 if ((gc->shared) && (gc->shared->references == 0))
776 Evas_GL_Texture_Pool *pt;
778 for (i = 0; i < SHADER_LAST; ++i)
779 evas_gl_common_shader_program_shutdown(&(gc->shared->shader[i]));
781 while (gc->shared->images)
783 evas_gl_common_image_free(gc->shared->images->data);
786 EINA_LIST_FOREACH(gc->shared->tex.whole, l, pt)
787 evas_gl_texture_pool_empty(pt);
788 for (i = 0; i < 33; i++)
790 for (j = 0; j < 3; j++)
792 EINA_LIST_FOREACH(gc->shared->tex.atlas[i][j], l, pt)
793 evas_gl_texture_pool_empty(pt);
796 eina_hash_free(gc->shared->native_pm_hash);
797 eina_hash_free(gc->shared->native_tex_hash);
801 if (gc == _evas_gl_common_context) _evas_gl_common_context = NULL;
806 evas_gl_common_context_use(Evas_Engine_GL_Context *gc)
808 if (_evas_gl_common_context == gc) return;
809 _evas_gl_common_context = gc;
810 if (gc) _evas_gl_common_viewport_set(gc);
814 evas_gl_common_context_newframe(Evas_Engine_GL_Context *gc)
821 if (getenv("EVAS_GL_DBG")) dbgflushnum = 1;
823 if (dbgflushnum) printf("----prev-flushnum: %i -----------------------------------\n", gc->flushnum);
826 gc->state.current.cur_prog = 0;
827 gc->state.current.cur_tex = 0;
828 gc->state.current.cur_texu = 0;
829 gc->state.current.cur_texv = 0;
830 gc->state.current.cur_texm = 0;
831 gc->state.current.cur_texmu = 0;
832 gc->state.current.cur_texmv = 0;
833 gc->state.current.render_op = 0;
834 gc->state.current.smooth = 0;
835 gc->state.current.blend = 0;
836 gc->state.current.clip = 0;
837 gc->state.current.cx = 0;
838 gc->state.current.cy = 0;
839 gc->state.current.cw = 0;
840 gc->state.current.ch = 0;
842 for (i = 0; i < gc->shared->info.tune.pipes.max; i++)
844 gc->pipe[i].region.x = 0;
845 gc->pipe[i].region.y = 0;
846 gc->pipe[i].region.w = 0;
847 gc->pipe[i].region.h = 0;
848 gc->pipe[i].region.type = 0;
849 gc->pipe[i].clip.active = 0;
850 gc->pipe[i].clip.x = 0;
851 gc->pipe[i].clip.y = 0;
852 gc->pipe[i].clip.w = 0;
853 gc->pipe[i].clip.h = 0;
854 gc->pipe[i].shader.surface = NULL;
855 gc->pipe[i].shader.cur_prog = 0;
856 gc->pipe[i].shader.cur_tex = 0;
857 gc->pipe[i].shader.cur_texu = 0;
858 gc->pipe[i].shader.cur_texv = 0;
859 gc->pipe[i].shader.cur_texm = 0;
860 gc->pipe[i].shader.render_op = EVAS_RENDER_BLEND;
861 gc->pipe[i].shader.smooth = 0;
862 gc->pipe[i].shader.blend = 0;
863 gc->pipe[i].shader.clip = 0;
864 gc->pipe[i].shader.cx = 0;
865 gc->pipe[i].shader.cy = 0;
866 gc->pipe[i].shader.cw = 0;
867 gc->pipe[i].shader.ch = 0;
871 glDisable(GL_SCISSOR_TEST);
872 GLERR(__FUNCTION__, __FILE__, __LINE__, "");
873 glScissor(0, 0, 0, 0);
874 GLERR(__FUNCTION__, __FILE__, __LINE__, "");
876 glDisable(GL_DEPTH_TEST);
877 GLERR(__FUNCTION__, __FILE__, __LINE__, "");
879 GLERR(__FUNCTION__, __FILE__, __LINE__, "");
881 GLERR(__FUNCTION__, __FILE__, __LINE__, "");
882 glBlendFunc(GL_ONE, GL_ONE_MINUS_SRC_ALPHA);
883 GLERR(__FUNCTION__, __FILE__, __LINE__, "");
885 // glBlendFunc(GL_SRC_ALPHA, GL_ONE_MINUS_SRC_ALPHA); // dest alpha
886 // glBlendFunc(GL_SRC_ALPHA, GL_ONE); // ???
887 glDepthMask(GL_FALSE);
888 GLERR(__FUNCTION__, __FILE__, __LINE__, "");
890 glTexParameteri(GL_TEXTURE_2D, GL_TEXTURE_MAG_FILTER, GL_NEAREST);
891 GLERR(__FUNCTION__, __FILE__, __LINE__, "");
892 glTexParameteri(GL_TEXTURE_2D, GL_TEXTURE_MIN_FILTER, GL_NEAREST);
893 GLERR(__FUNCTION__, __FILE__, __LINE__, "");
894 glTexParameteri(GL_TEXTURE_2D, GL_TEXTURE_WRAP_S, GL_CLAMP_TO_EDGE);
895 GLERR(__FUNCTION__, __FILE__, __LINE__, "");
896 glTexParameteri(GL_TEXTURE_2D, GL_TEXTURE_WRAP_T, GL_CLAMP_TO_EDGE);
897 GLERR(__FUNCTION__, __FILE__, __LINE__, "");
898 #ifdef GL_TEXTURE_MAX_ANISOTROPY_EXT
899 if (shared->info.anisotropic > 0.0)
901 glTexParameterf(GL_TEXTURE_2D, GL_TEXTURE_MAX_ANISOTROPY_EXT, 1.0);
902 GLERR(__FUNCTION__, __FILE__, __LINE__, "");
906 glEnableVertexAttribArray(SHAD_VERTEX);
907 GLERR(__FUNCTION__, __FILE__, __LINE__, "");
908 glEnableVertexAttribArray(SHAD_COLOR);
909 GLERR(__FUNCTION__, __FILE__, __LINE__, "");
910 if (gc->state.current.cur_prog == PRG_INVALID)
911 glUseProgram(gc->shared->shader[0].prog);
912 else glUseProgram(gc->state.current.cur_prog);
913 GLERR(__FUNCTION__, __FILE__, __LINE__, "");
915 glActiveTexture(GL_TEXTURE0);
916 GLERR(__FUNCTION__, __FILE__, __LINE__, "");
917 glBindTexture(GL_TEXTURE_2D, gc->pipe[0].shader.cur_tex);
918 GLERR(__FUNCTION__, __FILE__, __LINE__, "");
920 _evas_gl_common_viewport_set(gc);
924 evas_gl_common_context_resize(Evas_Engine_GL_Context *gc, int w, int h, int rot)
926 if ((gc->w == w) && (gc->h == h) && (gc->rot == rot)) return;
927 evas_gl_common_context_flush(gc);
932 if (_evas_gl_common_context == gc) _evas_gl_common_viewport_set(gc);
936 evas_gl_common_context_target_surface_set(Evas_Engine_GL_Context *gc,
937 Evas_GL_Image *surface)
939 if (surface == gc->pipe[0].shader.surface) return;
941 evas_gl_common_context_flush(gc);
943 gc->state.current.cur_prog = PRG_INVALID;
944 gc->state.current.cur_tex = -1;
945 gc->state.current.cur_texu = -1;
946 gc->state.current.cur_texv = -1;
947 gc->state.current.render_op = -1;
948 gc->state.current.smooth = -1;
949 gc->state.current.blend = -1;
950 gc->state.current.clip = -1;
951 gc->state.current.cx = -1;
952 gc->state.current.cy = -1;
953 gc->state.current.cw = -1;
954 gc->state.current.ch = -1;
956 gc->pipe[0].shader.surface = surface;
958 #if defined (GLES_VARIETY_S3C6410) || defined (GLES_VARIETY_SGX)
959 # ifndef GL_FRAMEBUFFER
960 # define GL_FRAMEBUFFER GL_FRAMEBUFFER_OES
963 # ifndef GL_FRAMEBUFFER
964 # define GL_FRAMEBUFFER GL_FRAMEBUFFER_EXT
967 if (gc->pipe[0].shader.surface == gc->def_surface)
969 glsym_glBindFramebuffer(GL_FRAMEBUFFER, 0);
970 GLERR(__FUNCTION__, __FILE__, __LINE__, "");
974 glsym_glBindFramebuffer(GL_FRAMEBUFFER, surface->tex->pt->fb);
975 GLERR(__FUNCTION__, __FILE__, __LINE__, "");
977 _evas_gl_common_viewport_set(gc);
980 #define PUSH_VERTEX(n, x, y, z) \
981 gc->pipe[n].array.vertex[nv++] = x; \
982 gc->pipe[n].array.vertex[nv++] = y; \
983 gc->pipe[n].array.vertex[nv++] = z
984 #define PUSH_COLOR(n, r, g, b, a) \
985 gc->pipe[n].array.color[nc++] = r; \
986 gc->pipe[n].array.color[nc++] = g; \
987 gc->pipe[n].array.color[nc++] = b; \
988 gc->pipe[n].array.color[nc++] = a
989 #define PUSH_TEXUV(n, u, v) \
990 gc->pipe[n].array.texuv[nu++] = u; \
991 gc->pipe[n].array.texuv[nu++] = v
992 #define PUSH_TEXUV2(n, u, v) \
993 gc->pipe[n].array.texuv2[nu2++] = u; \
994 gc->pipe[n].array.texuv2[nu2++] = v
995 #define PUSH_TEXUV3(n, u, v) \
996 gc->pipe[n].array.texuv3[nu3++] = u; \
997 gc->pipe[n].array.texuv3[nu3++] = v
998 #define PUSH_TEXM(n, u, v) \
999 gc->pipe[n].array.texm[nm++] = u; \
1000 gc->pipe[n].array.texm[nm++] = v
1004 array_alloc(Evas_Engine_GL_Context *gc, int n)
1006 gc->havestuff = EINA_TRUE;
1007 if (gc->pipe[n].array.num <= gc->pipe[n].array.alloc) return;
1008 gc->pipe[n].array.alloc += 6 * 1024;
1009 if (gc->pipe[n].array.use_vertex)
1010 gc->pipe[n].array.vertex = realloc(gc->pipe[n].array.vertex,
1011 gc->pipe[n].array.alloc * sizeof(GLshort) * 3);
1012 if (gc->pipe[n].array.use_color)
1013 gc->pipe[n].array.color = realloc(gc->pipe[n].array.color,
1014 gc->pipe[n].array.alloc * sizeof(GLubyte) * 4);
1015 if (gc->pipe[n].array.use_texuv)
1016 gc->pipe[n].array.texuv = realloc(gc->pipe[n].array.texuv,
1017 gc->pipe[n].array.alloc * sizeof(GLfloat) * 2);
1018 if (gc->pipe[n].array.use_texm)
1019 gc->pipe[n].array.texm = realloc(gc->pipe[n].array.texm,
1020 gc->pipe[n].array.alloc * sizeof(GLfloat) * 2);
1021 if (gc->pipe[n].array.use_texuv2)
1022 gc->pipe[n].array.texuv2 = realloc(gc->pipe[n].array.texuv2,
1023 gc->pipe[n].array.alloc * sizeof(GLfloat) * 2);
1024 if (gc->pipe[n].array.use_texuv3)
1025 gc->pipe[n].array.texuv3 = realloc(gc->pipe[n].array.texuv3,
1026 gc->pipe[n].array.alloc * sizeof(GLfloat) * 2);
1031 pipe_region_intersects(Evas_Engine_GL_Context *gc, int n,
1032 int x, int y, int w, int h)
1034 int i, rx, ry, rw, rh, ii;
1036 rx = gc->pipe[n].region.x;
1037 ry = gc->pipe[n].region.y;
1038 rw = gc->pipe[n].region.w;
1039 rh = gc->pipe[n].region.h;
1040 if (!RECTS_INTERSECT(x, y, w, h, rx, ry, rw, rh))
1043 // a hack for now. map pipes use their whole bounding box for intersects
1044 // which at worst case reduces to old pipeline flushes, but cheaper than
1045 // full quad region or triangle intersects right now
1046 if (gc->pipe[n].region.type == RTYPE_MAP) return 1;
1051 i < gc->pipe[n].array.num;
1056 // 0, 1, 2 < top left
1057 // 3, 4, 5 < top right
1058 // 6. 7, 8 < bottom left
1059 rx = gc->pipe[n].array.vertex[ii + 0];
1060 ry = gc->pipe[n].array.vertex[ii + 1];
1061 rw = gc->pipe[n].array.vertex[ii + 3] - rx;
1062 rh = gc->pipe[n].array.vertex[ii + 7] - ry;
1063 if (RECTS_INTERSECT(x, y, w, h, rx, ry, rw, rh))
1071 pipe_region_expand(Evas_Engine_GL_Context *gc, int n,
1072 int x, int y, int w, int h)
1076 if (gc->pipe[n].region.w <= 0)
1078 gc->pipe[n].region.x = x;
1079 gc->pipe[n].region.y = y;
1080 gc->pipe[n].region.w = w;
1081 gc->pipe[n].region.h = h;
1084 x1 = gc->pipe[n].region.x;
1085 y1 = gc->pipe[n].region.y;
1086 x2 = gc->pipe[n].region.x + gc->pipe[n].region.w;
1087 y2 = gc->pipe[n].region.y + gc->pipe[n].region.h;
1090 if ((x + w) > x2) x2 = x + w;
1091 if ((y + h) > y2) y2 = y + h;
1092 gc->pipe[n].region.x = x1;
1093 gc->pipe[n].region.y = y1;
1094 gc->pipe[n].region.w = x2 - x1;
1095 gc->pipe[n].region.h = y2 - y1;
1099 vertex_array_size_check(Evas_Engine_GL_Context *gc, int pn, int n)
1102 // this fixup breaks for expedite test 32. why?
1103 if ((gc->pipe[pn].array.num + n) > gc->shared->info.max_vertex_elements)
1105 shader_array_flush(gc);
1111 static inline Evas_GL_Shader
1112 evas_gl_common_shader_choice(int npoints __UNUSED__,
1114 int r, int g, int b, int a,
1115 Evas_GL_Shader nomul,
1118 if ((a == 255) && (r == 255) && (g == 255) && (b == 255))
1120 if (!p) return nomul;
1122 if ((p[0].col == 0xffffffff) && (p[1].col == 0xffffffff) &&
1123 (p[2].col == 0xffffffff) && (p[3].col == 0xffffffff))
1130 _evas_gl_common_context_push(int rtype,
1131 Evas_Engine_GL_Context *gc,
1132 Evas_GL_Texture *tex,
1133 Evas_GL_Texture *texm,
1135 int x, int y, int w, int h,
1139 int cx, int cy, int cw, int ch)
1146 vertex_array_size_check(gc, gc->state.top_pipe, 6);
1147 pn = gc->state.top_pipe;
1149 if (!((pn == 0) && (gc->pipe[pn].array.num == 0)))
1154 for (i = pn; i >= 0; i--)
1156 if ((gc->pipe[i].region.type == rtype)
1157 && (!tex || gc->pipe[i].shader.cur_tex == tex->pt->texture)
1158 && (!texm || gc->pipe[i].shader.cur_texm == texm->pt->texture)
1159 && (gc->pipe[i].shader.cur_prog == prog)
1160 && (gc->pipe[i].shader.smooth == smooth)
1161 && (gc->pipe[i].shader.blend == blend)
1162 && (gc->pipe[i].shader.render_op == gc->dc->render_op)
1163 && (gc->pipe[i].shader.clip == clip)
1164 && (!clip || ((gc->pipe[i].shader.cx == cx)
1165 && (gc->pipe[i].shader.cy == cy)
1166 && (gc->pipe[i].shader.cw == cw)
1167 && (gc->pipe[i].shader.ch == ch))))
1173 if (pipe_region_intersects(gc, i, x, y, w, h)) break;
1177 pn = gc->state.top_pipe + 1;
1178 if (pn >= gc->shared->info.tune.pipes.max)
1180 shader_array_flush(gc);
1183 gc->state.top_pipe = pn;
1186 if ((tex) && (((tex->im) && (tex->im->native.data)) || tex->pt->dyn.img))
1188 if (gc->pipe[pn].array.im != tex->im)
1190 shader_array_flush(gc);
1191 pn = gc->state.top_pipe;
1192 gc->pipe[pn].array.im = tex->im;
1197 if (!((gc->pipe[pn].region.type == rtype)
1198 && (!tex || gc->pipe[pn].shader.cur_tex == tex->pt->texture)
1199 && (!texm || gc->pipe[pn].shader.cur_texm == texm->pt->texture)
1200 && (gc->pipe[pn].shader.cur_prog == prog)
1201 && (gc->pipe[pn].shader.smooth == smooth)
1202 && (gc->pipe[pn].shader.blend == blend)
1203 && (gc->pipe[pn].shader.render_op == gc->dc->render_op)
1204 && (gc->pipe[pn].shader.clip == clip)
1205 && (!clip || ((gc->pipe[pn].shader.cx == cx)
1206 && (gc->pipe[pn].shader.cy == cy)
1207 && (gc->pipe[pn].shader.cw == cw)
1208 && (gc->pipe[pn].shader.ch == ch)))))
1210 shader_array_flush(gc);
1212 if ((tex) && (((tex->im) && (tex->im->native.data)) || tex->pt->dyn.img))
1214 if (gc->pipe[pn].array.im != tex->im)
1216 shader_array_flush(gc);
1217 gc->pipe[pn].array.im = tex->im;
1226 evas_gl_common_context_line_push(Evas_Engine_GL_Context *gc,
1227 int x1, int y1, int x2, int y2,
1228 int clip, int cx, int cy, int cw, int ch,
1229 int r, int g, int b, int a)
1231 int pnum, nv, nc, nu, nt, i;
1232 Eina_Bool blend = 0;
1233 GLuint prog = gc->shared->shader[SHADER_RECT].prog;
1236 if (a < 255) blend = 1;
1237 if (gc->dc->render_op == EVAS_RENDER_COPY) blend = 0;
1239 shader_array_flush(gc);
1240 vertex_array_size_check(gc, gc->state.top_pipe, 2);
1241 pn = gc->state.top_pipe;
1242 gc->pipe[pn].shader.cur_tex = 0;
1243 gc->pipe[pn].shader.cur_prog = prog;
1244 gc->pipe[pn].shader.blend = blend;
1245 gc->pipe[pn].shader.render_op = gc->dc->render_op;
1246 gc->pipe[pn].shader.clip = clip;
1247 gc->pipe[pn].shader.cx = cx;
1248 gc->pipe[pn].shader.cy = cy;
1249 gc->pipe[pn].shader.cw = cw;
1250 gc->pipe[pn].shader.ch = ch;
1252 gc->pipe[pn].array.line = 1;
1253 gc->pipe[pn].array.use_vertex = 1;
1254 gc->pipe[pn].array.use_color = 1;
1255 gc->pipe[pn].array.use_texuv = 0;
1256 gc->pipe[pn].array.use_texuv2 = 0;
1257 gc->pipe[pn].array.use_texuv3 = 0;
1259 pnum = gc->pipe[pn].array.num;
1260 nv = pnum * 3; nc = pnum * 4; nu = pnum * 2; nt = pnum * 4;
1261 gc->pipe[pn].array.num += 2;
1262 array_alloc(gc, pn);
1264 PUSH_VERTEX(pn, x1, y1, 0);
1265 PUSH_VERTEX(pn, x2, y2, 0);
1267 for (i = 0; i < 2; i++)
1269 PUSH_COLOR(pn, r, g, b, a);
1272 shader_array_flush(gc);
1273 gc->pipe[pn].array.line = 0;
1274 gc->pipe[pn].array.use_vertex = 0;
1275 gc->pipe[pn].array.use_color = 0;
1276 gc->pipe[pn].array.use_texuv = 0;
1277 gc->pipe[pn].array.use_texuv2 = 0;
1278 gc->pipe[pn].array.use_texuv3 = 0;
1282 evas_gl_common_context_rectangle_push(Evas_Engine_GL_Context *gc,
1283 int x, int y, int w, int h,
1284 int r, int g, int b, int a)
1286 int pnum, nv, nc, nu, nt, i;
1287 Eina_Bool blend = 0;
1288 GLuint prog = gc->shared->shader[SHADER_RECT].prog;
1291 if (gc->dc->mask.mask)
1293 RGBA_Draw_Context *dc;
1296 im = (void *)dc->mask.mask;
1297 evas_gl_common_context_font_push(gc, im->tex,
1300 dc->mask.w, dc->mask.h,
1306 if (a < 255) blend = 1;
1307 if (gc->dc->render_op == EVAS_RENDER_COPY) blend = 0;
1310 vertex_array_size_check(gc, gc->state.top_pipe, 6);
1311 pn = gc->state.top_pipe;
1313 if ((pn == 0) && (gc->pipe[pn].array.num == 0))
1315 gc->pipe[pn].region.type = RTYPE_RECT;
1316 gc->pipe[pn].shader.cur_tex = 0;
1317 gc->pipe[pn].shader.cur_prog = prog;
1318 gc->pipe[pn].shader.blend = blend;
1319 gc->pipe[pn].shader.render_op = gc->dc->render_op;
1320 gc->pipe[pn].shader.clip = 0;
1321 gc->pipe[pn].shader.cx = 0;
1322 gc->pipe[pn].shader.cy = 0;
1323 gc->pipe[pn].shader.cw = 0;
1324 gc->pipe[pn].shader.ch = 0;
1325 gc->pipe[pn].array.line = 0;
1326 gc->pipe[pn].array.use_vertex = 1;
1327 gc->pipe[pn].array.use_color = 1;
1328 gc->pipe[pn].array.use_texuv = 0;
1329 gc->pipe[pn].array.use_texuv2 = 0;
1330 gc->pipe[pn].array.use_texuv3 = 0;
1336 for (i = pn; i >= 0; i--)
1338 if ((gc->pipe[i].region.type == RTYPE_RECT)
1339 && (gc->pipe[i].shader.cur_tex == 0)
1340 && (gc->pipe[i].shader.cur_prog == prog)
1341 && (gc->pipe[i].shader.blend == blend)
1342 && (gc->pipe[i].shader.render_op == gc->dc->render_op)
1343 && (gc->pipe[i].shader.clip == 0)
1350 if (pipe_region_intersects(gc, i, x, y, w, h)) break;
1354 pn = gc->state.top_pipe + 1;
1355 if (pn >= gc->shared->info.tune.pipes.max)
1357 shader_array_flush(gc);
1360 gc->state.top_pipe = pn;
1361 gc->pipe[pn].region.type = RTYPE_RECT;
1362 gc->pipe[pn].shader.cur_tex = 0;
1363 gc->pipe[pn].shader.cur_prog = prog;
1364 gc->pipe[pn].shader.blend = blend;
1365 gc->pipe[pn].shader.render_op = gc->dc->render_op;
1366 gc->pipe[pn].shader.clip = 0;
1367 gc->pipe[pn].shader.cx = 0;
1368 gc->pipe[pn].shader.cy = 0;
1369 gc->pipe[pn].shader.cw = 0;
1370 gc->pipe[pn].shader.ch = 0;
1371 gc->pipe[pn].array.line = 0;
1372 gc->pipe[pn].array.use_vertex = 1;
1373 gc->pipe[pn].array.use_color = 1;
1374 gc->pipe[pn].array.use_texuv = 0;
1375 gc->pipe[pn].array.use_texuv2 = 0;
1376 gc->pipe[pn].array.use_texuv3 = 0;
1380 if ((gc->pipe[pn].shader.cur_tex != 0)
1381 || (gc->pipe[pn].shader.cur_prog != prog)
1382 || (gc->pipe[pn].shader.blend != blend)
1383 || (gc->pipe[pn].shader.render_op != gc->dc->render_op)
1384 || (gc->pipe[pn].shader.clip != 0)
1387 shader_array_flush(gc);
1388 pn = gc->state.top_pipe;
1389 gc->pipe[pn].shader.cur_tex = 0;
1390 gc->pipe[pn].shader.cur_prog = prog;
1391 gc->pipe[pn].shader.blend = blend;
1392 gc->pipe[pn].shader.render_op = gc->dc->render_op;
1393 gc->pipe[pn].shader.clip = 0;
1394 gc->pipe[pn].shader.cx = 0;
1395 gc->pipe[pn].shader.cy = 0;
1396 gc->pipe[pn].shader.cw = 0;
1397 gc->pipe[pn].shader.ch = 0;
1400 gc->pipe[pn].region.type = RTYPE_RECT;
1401 gc->pipe[pn].array.line = 0;
1402 gc->pipe[pn].array.use_vertex = 1;
1403 gc->pipe[pn].array.use_color = 1;
1404 gc->pipe[pn].array.use_texuv = 0;
1405 gc->pipe[pn].array.use_texuv2 = 0;
1406 gc->pipe[pn].array.use_texuv3 = 0;
1409 pipe_region_expand(gc, pn, x, y, w, h);
1411 pnum = gc->pipe[pn].array.num;
1412 nv = pnum * 3; nc = pnum * 4; nu = pnum * 2; nt = pnum * 4;
1413 gc->pipe[pn].array.num += 6;
1414 array_alloc(gc, pn);
1416 PUSH_VERTEX(pn, x , y , 0);
1417 PUSH_VERTEX(pn, x + w, y , 0);
1418 PUSH_VERTEX(pn, x , y + h, 0);
1420 PUSH_VERTEX(pn, x + w, y , 0);
1421 PUSH_VERTEX(pn, x + w, y + h, 0);
1422 PUSH_VERTEX(pn, x , y + h, 0);
1424 for (i = 0; i < 6; i++)
1426 PUSH_COLOR(pn, r, g, b, a);
1431 evas_gl_common_context_image_push(Evas_Engine_GL_Context *gc,
1432 Evas_GL_Texture *tex,
1433 double sx, double sy, double sw, double sh,
1434 int x, int y, int w, int h,
1435 int r, int g, int b, int a,
1436 Eina_Bool smooth, Eina_Bool tex_only)
1438 int pnum, nv, nc, nu, nu2, nt, i;
1439 GLfloat tx1, tx2, ty1, ty2;
1440 Eina_Bool blend = 1;
1441 GLuint prog = gc->shared->shader[SHADER_IMG].prog;
1444 if (!tex->alpha) blend = 0;
1445 if (a < 255) blend = 1;
1447 if (gc->filter_prog)
1449 prog = gc->filter_prog;
1453 if (tex->pt->dyn.img)
1455 prog = gc->shared->shader[evas_gl_common_shader_choice(0, NULL, r, g, b, a,
1456 SHADER_IMG_BGRA_NOMUL, SHADER_IMG_BGRA)].prog;
1460 prog = gc->shared->shader[evas_gl_common_shader_choice(0, NULL, r, g, b, a,
1461 SHADER_TEX_NOMUL, SHADER_TEX)].prog;
1466 if (tex->gc->shared->info.bgra)
1468 prog = gc->shared->shader[evas_gl_common_shader_choice(0, NULL, r, g, b, a,
1469 SHADER_IMG_BGRA_NOMUL, SHADER_IMG_BGRA)].prog;
1473 prog = gc->shared->shader[evas_gl_common_shader_choice(0, NULL, r, g, b, a,
1474 SHADER_IMG_NOMUL, SHADER_IMG)].prog;
1478 pn = _evas_gl_common_context_push(RTYPE_IMAGE,
1486 gc->pipe[pn].region.type = RTYPE_IMAGE;
1487 gc->pipe[pn].shader.cur_tex = tex->pt->texture;
1488 gc->pipe[pn].shader.cur_prog = prog;
1489 gc->pipe[pn].shader.smooth = smooth;
1490 gc->pipe[pn].shader.blend = blend;
1491 gc->pipe[pn].shader.render_op = gc->dc->render_op;
1492 gc->pipe[pn].shader.clip = 0;
1493 gc->pipe[pn].shader.cx = 0;
1494 gc->pipe[pn].shader.cy = 0;
1495 gc->pipe[pn].shader.cw = 0;
1496 gc->pipe[pn].shader.ch = 0;
1497 gc->pipe[pn].array.line = 0;
1498 gc->pipe[pn].array.use_vertex = 1;
1499 // if nomul... dont need this
1500 gc->pipe[pn].array.use_color = 1;
1501 gc->pipe[pn].array.use_texuv = 1;
1502 gc->pipe[pn].array.use_texuv2 = 0;
1503 gc->pipe[pn].array.use_texuv3 = 0;
1505 pipe_region_expand(gc, pn, x, y, w, h);
1507 pnum = gc->pipe[pn].array.num;
1508 nv = pnum * 3; nc = pnum * 4; nu = pnum * 2; nu2 = pnum * 2;
1510 gc->pipe[pn].array.num += 6;
1511 array_alloc(gc, pn);
1513 if ((tex->im) && (tex->im->native.data) && (!tex->im->native.yinvert))
1515 tx1 = ((double)(tex->x) + sx) / (double)tex->pt->w;
1516 ty1 = 1.0 - ((double)(tex->y) + sy) / (double)tex->pt->h;
1517 tx2 = ((double)(tex->x) + sx + sw) / (double)tex->pt->w;
1518 ty2 = 1.0 - ((double)(tex->y) + sy + sh) / (double)tex->pt->h;
1522 tx1 = ((double)(tex->x) + sx) / (double)tex->pt->w;
1523 ty1 = ((double)(tex->y) + sy) / (double)tex->pt->h;
1524 tx2 = ((double)(tex->x) + sx + sw) / (double)tex->pt->w;
1525 ty2 = ((double)(tex->y) + sy + sh) / (double)tex->pt->h;
1528 PUSH_VERTEX(pn, x , y , 0);
1529 PUSH_VERTEX(pn, x + w, y , 0);
1530 PUSH_VERTEX(pn, x , y + h, 0);
1532 PUSH_TEXUV(pn, tx1, ty1);
1533 PUSH_TEXUV(pn, tx2, ty1);
1534 PUSH_TEXUV(pn, tx1, ty2);
1536 PUSH_VERTEX(pn, x + w, y , 0);
1537 PUSH_VERTEX(pn, x + w, y + h, 0);
1538 PUSH_VERTEX(pn, x , y + h, 0);
1540 PUSH_TEXUV(pn, tx2, ty1);
1541 PUSH_TEXUV(pn, tx2, ty2);
1542 PUSH_TEXUV(pn, tx1, ty2);
1544 // if nomul... dont need this
1545 for (i = 0; i < 6; i++)
1547 PUSH_COLOR(pn, r, g, b, a);
1552 evas_gl_common_context_image_mask_push(Evas_Engine_GL_Context *gc,
1553 Evas_GL_Texture *tex,
1554 Evas_GL_Texture *texm,
1555 double sx, double sy, double sw, double sh,
1556 double sxm, double sym, double swm,double shm,
1557 int x, int y, int w, int h,
1558 int r, int g, int b, int a,
1561 int pnum, nv, nc, nu, nm, nt, i;
1562 GLfloat tx1, tx2, ty1, ty2;
1563 GLfloat txm1, txm2, tym1, tym2;
1564 Eina_Bool blend = 1;
1565 GLuint prog = gc->shared->shader[SHADER_IMG_MASK].prog;
1569 if (tex->gc->shared->info.bgra)
1571 prog = gc->shared->shader[SHADER_IMG_MASK].prog;
1575 #warning Nash: FIXME: Need two shaders?
1576 printf("Not good: Need other texture\n");
1577 prog = gc->shared->shader[SHADER_IMG].prog;
1581 pn = _evas_gl_common_context_push(RTYPE_IMASK,
1589 gc->pipe[pn].region.type = RTYPE_IMASK;
1590 gc->pipe[pn].shader.cur_tex = tex->pt->texture;
1591 gc->pipe[pn].shader.cur_texm = texm->pt->texture;
1592 gc->pipe[pn].shader.cur_prog = prog;
1593 gc->pipe[pn].shader.smooth = smooth;
1594 gc->pipe[pn].shader.blend = blend;
1595 gc->pipe[pn].shader.render_op = gc->dc->render_op;
1596 gc->pipe[pn].shader.clip = 0;
1597 gc->pipe[pn].shader.cx = 0;
1598 gc->pipe[pn].shader.cy = 0;
1599 gc->pipe[pn].shader.cw = 0;
1600 gc->pipe[pn].shader.ch = 0;
1601 gc->pipe[pn].array.line = 0;
1602 gc->pipe[pn].array.use_vertex = 1;
1603 // if nomul... dont need this
1604 gc->pipe[pn].array.use_color = 1;
1605 gc->pipe[pn].array.use_texuv = 1;
1606 gc->pipe[pn].array.use_texuv2 = 0;
1607 gc->pipe[pn].array.use_texuv3 = 0;
1608 gc->pipe[pn].array.use_texm = 1;
1610 pipe_region_expand(gc, pn, x, y, w, h);
1612 pnum = gc->pipe[pn].array.num;
1613 nv = pnum * 3; nc = pnum * 4; nm = pnum * 2; nu = pnum * 2;
1615 gc->pipe[pn].array.num += 6;
1616 array_alloc(gc, pn);
1618 if ((tex->im) && (tex->im->native.data) && (!tex->im->native.yinvert))
1620 tx1 = ((double)(tex->x) + sx) / (double)tex->pt->w;
1621 ty1 = ((double)(tex->y) + sy + sh) / (double)tex->pt->h;
1622 tx2 = ((double)(tex->x) + sx + sw) / (double)tex->pt->w;
1623 ty2 = ((double)(tex->y) + sy) / (double)tex->pt->h;
1625 txm1 = ((double)(texm->x) + sxm) / (double)texm->pt->w;
1626 tym1 = ((double)(texm->y) + sym + shm) / (double)texm->pt->h;
1627 txm2 = ((double)(texm->x) + sxm + swm) / (double)texm->pt->w;
1628 tym2 = ((double)(texm->y) + sym) / (double)texm->pt->h;
1632 tx1 = ((double)(tex->x) + sx) / (double)tex->pt->w;
1633 ty1 = ((double)(tex->y) + sy) / (double)tex->pt->h;
1634 tx2 = ((double)(tex->x) + sx + sw) / (double)tex->pt->w;
1635 ty2 = ((double)(tex->y) + sy + sh) / (double)tex->pt->h;
1637 txm1 = (texm->x + sxm) / (double)texm->pt->w;
1638 tym1 = (texm->y + sym) / (double)texm->pt->h;
1639 txm2 = (texm->x + sxm + swm) / (double)texm->pt->w;
1640 tym2 = (texm->y + sym + shm) / (double)texm->pt->h;
1642 // printf(" %3.6lf %3.6lf %3.6lf %3.6lf\n",sx,sy,sw,sh);
1643 // printf("m%3.6lf %3.6lf %3.6lf %3.6lf\n",sxm,sym,swm,shm);
1644 // printf(" %3f %3f %3f %3f\n",tx1,ty1,tx2,ty2);
1645 // printf("m%3f %3f %3f %3f\n",txm1,tym1,txm2,tym2);
1647 PUSH_VERTEX(pn, x , y , 0);
1648 PUSH_VERTEX(pn, x + w, y , 0);
1649 PUSH_VERTEX(pn, x , y + h, 0);
1651 PUSH_TEXUV(pn, tx1, ty1);
1652 PUSH_TEXUV(pn, tx2, ty1);
1653 PUSH_TEXUV(pn, tx1, ty2);
1655 PUSH_TEXM(pn, txm1, tym1);
1656 PUSH_TEXM(pn, txm2, tym1);
1657 PUSH_TEXM(pn, txm1, tym2);
1659 PUSH_VERTEX(pn, x + w, y , 0);
1660 PUSH_VERTEX(pn, x + w, y + h, 0);
1661 PUSH_VERTEX(pn, x , y + h, 0);
1663 PUSH_TEXUV(pn, tx2, ty1);
1664 PUSH_TEXUV(pn, tx2, ty2);
1665 PUSH_TEXUV(pn, tx1, ty2);
1667 PUSH_TEXM(pn, txm2, tym1);
1668 PUSH_TEXM(pn, txm2, tym2);
1669 PUSH_TEXM(pn, txm1, tym2);
1671 // if nomul... dont need this
1672 for (i = 0; i < 6; i++)
1674 PUSH_COLOR(pn, r, g, b, a);
1680 evas_gl_common_context_font_push(Evas_Engine_GL_Context *gc,
1681 Evas_GL_Texture *tex,
1682 double sx, double sy, double sw, double sh,
1683 int x, int y, int w, int h,
1684 int r, int g, int b, int a)
1686 int pnum, nv, nc, nu, nt, i;
1687 GLfloat tx1, tx2, ty1, ty2;
1688 GLuint prog = gc->shared->shader[SHADER_FONT].prog;
1691 pn = _evas_gl_common_context_push(RTYPE_FONT,
1699 gc->pipe[pn].region.type = RTYPE_FONT;
1700 gc->pipe[pn].shader.cur_tex = tex->pt->texture;
1701 gc->pipe[pn].shader.cur_prog = prog;
1702 gc->pipe[pn].shader.smooth = 0;
1703 gc->pipe[pn].shader.blend = 1;
1704 gc->pipe[pn].shader.render_op = gc->dc->render_op;
1705 gc->pipe[pn].shader.clip = 0;
1706 gc->pipe[pn].shader.cx = 0;
1707 gc->pipe[pn].shader.cy = 0;
1708 gc->pipe[pn].shader.cw = 0;
1709 gc->pipe[pn].shader.ch = 0;
1710 gc->pipe[pn].array.line = 0;
1711 gc->pipe[pn].array.use_vertex = 1;
1712 gc->pipe[pn].array.use_color = 1;
1713 gc->pipe[pn].array.use_texuv = 1;
1714 gc->pipe[pn].array.use_texuv2 = 0;
1715 gc->pipe[pn].array.use_texuv3 = 0;
1717 pipe_region_expand(gc, pn, x, y, w, h);
1719 pnum = gc->pipe[pn].array.num;
1720 nv = pnum * 3; nc = pnum * 4; nu = pnum * 2; nt = pnum * 4;
1721 gc->pipe[pn].array.num += 6;
1722 array_alloc(gc, pn);
1733 tx1 = ((double)(tex->x) + sx) / (double)tex->pt->w;
1734 ty1 = ((double)(tex->y) + sy) / (double)tex->pt->h;
1735 tx2 = ((double)(tex->x) + sx + sw) / (double)tex->pt->w;
1736 ty2 = ((double)(tex->y) + sy + sh) / (double)tex->pt->h;
1739 PUSH_VERTEX(pn, x , y , 0);
1740 PUSH_VERTEX(pn, x + w, y , 0);
1741 PUSH_VERTEX(pn, x , y + h, 0);
1743 PUSH_TEXUV(pn, tx1, ty1);
1744 PUSH_TEXUV(pn, tx2, ty1);
1745 PUSH_TEXUV(pn, tx1, ty2);
1747 PUSH_VERTEX(pn, x + w, y , 0);
1748 PUSH_VERTEX(pn, x + w, y + h, 0);
1749 PUSH_VERTEX(pn, x , y + h, 0);
1751 PUSH_TEXUV(pn, tx2, ty1);
1752 PUSH_TEXUV(pn, tx2, ty2);
1753 PUSH_TEXUV(pn, tx1, ty2);
1755 for (i = 0; i < 6; i++)
1757 PUSH_COLOR(pn, r, g, b, a);
1762 evas_gl_common_context_yuv_push(Evas_Engine_GL_Context *gc,
1763 Evas_GL_Texture *tex,
1764 double sx, double sy, double sw, double sh,
1765 int x, int y, int w, int h,
1766 int r, int g, int b, int a,
1769 int pnum, nv, nc, nu, nu2, nu3, nt, i;
1770 GLfloat tx1, tx2, ty1, ty2, t2x1, t2x2, t2y1, t2y2;
1771 Eina_Bool blend = 0;
1775 if (a < 255) blend = 1;
1777 prog = gc->shared->shader[evas_gl_common_shader_choice(0, NULL, r, g, b, a,
1778 SHADER_YUV_NOMUL, SHADER_YUV)].prog;
1780 pn = _evas_gl_common_context_push(RTYPE_YUV,
1788 gc->pipe[pn].region.type = RTYPE_YUV;
1789 gc->pipe[pn].shader.cur_tex = tex->pt->texture;
1790 gc->pipe[pn].shader.cur_texu = tex->ptu->texture;
1791 gc->pipe[pn].shader.cur_texv = tex->ptv->texture;
1792 gc->pipe[pn].shader.cur_prog = prog;
1793 gc->pipe[pn].shader.smooth = smooth;
1794 gc->pipe[pn].shader.blend = blend;
1795 gc->pipe[pn].shader.render_op = gc->dc->render_op;
1796 gc->pipe[pn].shader.clip = 0;
1797 gc->pipe[pn].shader.cx = 0;
1798 gc->pipe[pn].shader.cy = 0;
1799 gc->pipe[pn].shader.cw = 0;
1800 gc->pipe[pn].shader.ch = 0;
1801 gc->pipe[pn].array.line = 0;
1802 gc->pipe[pn].array.use_vertex = 1;
1803 gc->pipe[pn].array.use_color = 1;
1804 gc->pipe[pn].array.use_texuv = 1;
1805 gc->pipe[pn].array.use_texuv2 = 1;
1806 gc->pipe[pn].array.use_texuv3 = 1;
1808 pipe_region_expand(gc, pn, x, y, w, h);
1810 pnum = gc->pipe[pn].array.num;
1811 nv = pnum * 3; nc = pnum * 4; nu = pnum * 2;
1812 nu2 = pnum * 2; nu3 = pnum * 2; nt = pnum * 4;
1813 gc->pipe[pn].array.num += 6;
1814 array_alloc(gc, pn);
1816 tx1 = (sx) / (double)tex->pt->w;
1817 ty1 = (sy) / (double)tex->pt->h;
1818 tx2 = (sx + sw) / (double)tex->pt->w;
1819 ty2 = (sy + sh) / (double)tex->pt->h;
1821 t2x1 = ((sx) / 2) / (double)tex->ptu->w;
1822 t2y1 = ((sy) / 2) / (double)tex->ptu->h;
1823 t2x2 = ((sx + sw) / 2) / (double)tex->ptu->w;
1824 t2y2 = ((sy + sh) / 2) / (double)tex->ptu->h;
1826 PUSH_VERTEX(pn, x , y , 0);
1827 PUSH_VERTEX(pn, x + w, y , 0);
1828 PUSH_VERTEX(pn, x , y + h, 0);
1830 PUSH_TEXUV(pn, tx1, ty1);
1831 PUSH_TEXUV(pn, tx2, ty1);
1832 PUSH_TEXUV(pn, tx1, ty2);
1834 PUSH_TEXUV2(pn, t2x1, t2y1);
1835 PUSH_TEXUV2(pn, t2x2, t2y1);
1836 PUSH_TEXUV2(pn, t2x1, t2y2);
1838 PUSH_TEXUV3(pn, t2x1, t2y1);
1839 PUSH_TEXUV3(pn, t2x2, t2y1);
1840 PUSH_TEXUV3(pn, t2x1, t2y2);
1842 PUSH_VERTEX(pn, x + w, y , 0);
1843 PUSH_VERTEX(pn, x + w, y + h, 0);
1844 PUSH_VERTEX(pn, x , y + h, 0);
1846 PUSH_TEXUV(pn, tx2, ty1);
1847 PUSH_TEXUV(pn, tx2, ty2);
1848 PUSH_TEXUV(pn, tx1, ty2);
1850 PUSH_TEXUV2(pn, t2x2, t2y1);
1851 PUSH_TEXUV2(pn, t2x2, t2y2);
1852 PUSH_TEXUV2(pn, t2x1, t2y2);
1854 PUSH_TEXUV3(pn, t2x2, t2y1);
1855 PUSH_TEXUV3(pn, t2x2, t2y2);
1856 PUSH_TEXUV3(pn, t2x1, t2y2);
1858 for (i = 0; i < 6; i++)
1860 PUSH_COLOR(pn, r, g, b, a);
1865 evas_gl_common_context_yuy2_push(Evas_Engine_GL_Context *gc,
1866 Evas_GL_Texture *tex,
1867 double sx, double sy, double sw, double sh,
1868 int x, int y, int w, int h,
1869 int r, int g, int b, int a,
1872 int pnum, nv, nc, nu, nu2, nu3, nt, i;
1873 GLfloat tx1, tx2, ty1, ty2, t2x1, t2x2, t2y1, t2y2;
1874 Eina_Bool blend = 0;
1878 if (a < 255) blend = 1;
1880 prog = gc->shared->shader[evas_gl_common_shader_choice(0, NULL, r, g, b, a,
1881 SHADER_YUY2_NOMUL, SHADER_YUY2)].prog;
1883 pn = _evas_gl_common_context_push(RTYPE_YUY2,
1891 gc->pipe[pn].region.type = RTYPE_YUY2;
1892 gc->pipe[pn].shader.cur_tex = tex->pt->texture;
1893 gc->pipe[pn].shader.cur_texu = tex->ptuv->texture;
1894 gc->pipe[pn].shader.cur_prog = prog;
1895 gc->pipe[pn].shader.smooth = smooth;
1896 gc->pipe[pn].shader.blend = blend;
1897 gc->pipe[pn].shader.render_op = gc->dc->render_op;
1898 gc->pipe[pn].shader.clip = 0;
1899 gc->pipe[pn].shader.cx = 0;
1900 gc->pipe[pn].shader.cy = 0;
1901 gc->pipe[pn].shader.cw = 0;
1902 gc->pipe[pn].shader.ch = 0;
1903 gc->pipe[pn].array.line = 0;
1904 gc->pipe[pn].array.use_vertex = 1;
1905 gc->pipe[pn].array.use_color = 1;
1906 gc->pipe[pn].array.use_texuv = 1;
1907 gc->pipe[pn].array.use_texuv2 = 1;
1908 gc->pipe[pn].array.use_texuv3 = 0;
1910 pipe_region_expand(gc, pn, x, y, w, h);
1912 pnum = gc->pipe[pn].array.num;
1913 nv = pnum * 3; nc = pnum * 4; nu = pnum * 2;
1914 nu2 = pnum * 2; nu3 = pnum * 2; nt = pnum * 4;
1915 gc->pipe[pn].array.num += 6;
1916 array_alloc(gc, pn);
1918 tx1 = (sx) / (double)tex->pt->w;
1919 ty1 = (sy) / (double)tex->pt->h;
1920 tx2 = (sx + sw) / (double)tex->pt->w;
1921 ty2 = (sy + sh) / (double)tex->pt->h;
1923 t2x1 = sx / (double)tex->ptuv->w;
1924 t2y1 = sy / (double)tex->ptuv->h;
1925 t2x2 = (sx + sw) / (double)tex->ptuv->w;
1926 t2y2 = (sy + sh) / (double)tex->ptuv->h;
1928 PUSH_VERTEX(pn, x , y , 0);
1929 PUSH_VERTEX(pn, x + w, y , 0);
1930 PUSH_VERTEX(pn, x , y + h, 0);
1932 PUSH_TEXUV(pn, tx1, ty1);
1933 PUSH_TEXUV(pn, tx2, ty1);
1934 PUSH_TEXUV(pn, tx1, ty2);
1936 PUSH_TEXUV2(pn, t2x1, t2y1);
1937 PUSH_TEXUV2(pn, t2x2, t2y1);
1938 PUSH_TEXUV2(pn, t2x1, t2y2);
1940 PUSH_VERTEX(pn, x + w, y , 0);
1941 PUSH_VERTEX(pn, x + w, y + h, 0);
1942 PUSH_VERTEX(pn, x , y + h, 0);
1944 PUSH_TEXUV(pn, tx2, ty1);
1945 PUSH_TEXUV(pn, tx2, ty2);
1946 PUSH_TEXUV(pn, tx1, ty2);
1948 PUSH_TEXUV2(pn, t2x2, t2y1);
1949 PUSH_TEXUV2(pn, t2x2, t2y2);
1950 PUSH_TEXUV2(pn, t2x1, t2y2);
1952 for (i = 0; i < 6; i++)
1954 PUSH_COLOR(pn, r, g, b, a);
1959 evas_gl_common_context_nv12_push(Evas_Engine_GL_Context *gc,
1960 Evas_GL_Texture *tex,
1961 double sx, double sy, double sw, double sh,
1962 int x, int y, int w, int h,
1963 int r, int g, int b, int a,
1966 int pnum, nv, nc, nu, nu2, nu3, nt, i;
1967 GLfloat tx1, tx2, ty1, ty2, t2x1, t2x2, t2y1, t2y2;
1968 Eina_Bool blend = 0;
1972 if (a < 255) blend = 1;
1974 prog = gc->shared->shader[evas_gl_common_shader_choice(0, NULL, r, g, b, a,
1975 SHADER_NV12_NOMUL, SHADER_NV12)].prog;
1977 pn = _evas_gl_common_context_push(RTYPE_NV12,
1985 gc->pipe[pn].region.type = RTYPE_NV12;
1986 gc->pipe[pn].shader.cur_tex = tex->pt->texture;
1987 gc->pipe[pn].shader.cur_tex_dyn = tex->pt->dyn.img;
1988 gc->pipe[pn].shader.cur_texu = tex->ptuv->texture;
1989 gc->pipe[pn].shader.cur_texu_dyn = tex->ptuv->dyn.img;
1990 gc->pipe[pn].shader.cur_prog = prog;
1991 gc->pipe[pn].shader.smooth = smooth;
1992 gc->pipe[pn].shader.blend = blend;
1993 gc->pipe[pn].shader.render_op = gc->dc->render_op;
1994 gc->pipe[pn].shader.clip = 0;
1995 gc->pipe[pn].shader.cx = 0;
1996 gc->pipe[pn].shader.cy = 0;
1997 gc->pipe[pn].shader.cw = 0;
1998 gc->pipe[pn].shader.ch = 0;
1999 gc->pipe[pn].array.line = 0;
2000 gc->pipe[pn].array.use_vertex = 1;
2001 gc->pipe[pn].array.use_color = 1;
2002 gc->pipe[pn].array.use_texuv = 1;
2003 gc->pipe[pn].array.use_texuv2 = 1;
2004 gc->pipe[pn].array.use_texuv3 = 0;
2006 pipe_region_expand(gc, pn, x, y, w, h);
2008 pnum = gc->pipe[pn].array.num;
2009 nv = pnum * 3; nc = pnum * 4; nu = pnum * 2;
2010 nu2 = pnum * 2; nu3 = pnum * 2; nt = pnum * 4;
2011 gc->pipe[pn].array.num += 6;
2012 array_alloc(gc, pn);
2014 tx1 = (sx) / (double)tex->pt->w;
2015 ty1 = (sy) / (double)tex->pt->h;
2016 tx2 = (sx + sw) / (double)tex->pt->w;
2017 ty2 = (sy + sh) / (double)tex->pt->h;
2019 t2x1 = sx / (double)tex->ptuv->w;
2020 t2y1 = sy / (double)tex->ptuv->h;
2021 t2x2 = (sx + sw) / (double)tex->ptuv->w;
2022 t2y2 = (sy + sh) / (double)tex->ptuv->h;
2024 PUSH_VERTEX(pn, x , y , 0);
2025 PUSH_VERTEX(pn, x + w, y , 0);
2026 PUSH_VERTEX(pn, x , y + h, 0);
2028 PUSH_TEXUV(pn, tx1, ty1);
2029 PUSH_TEXUV(pn, tx2, ty1);
2030 PUSH_TEXUV(pn, tx1, ty2);
2032 PUSH_TEXUV2(pn, t2x1, t2y1);
2033 PUSH_TEXUV2(pn, t2x2, t2y1);
2034 PUSH_TEXUV2(pn, t2x1, t2y2);
2036 PUSH_VERTEX(pn, x + w, y , 0);
2037 PUSH_VERTEX(pn, x + w, y + h, 0);
2038 PUSH_VERTEX(pn, x , y + h, 0);
2040 PUSH_TEXUV(pn, tx2, ty1);
2041 PUSH_TEXUV(pn, tx2, ty2);
2042 PUSH_TEXUV(pn, tx1, ty2);
2044 PUSH_TEXUV2(pn, t2x2, t2y1);
2045 PUSH_TEXUV2(pn, t2x2, t2y2);
2046 PUSH_TEXUV2(pn, t2x1, t2y2);
2048 for (i = 0; i < 6; i++)
2050 PUSH_COLOR(pn, r, g, b, a);
2055 evas_gl_common_context_image_map_push(Evas_Engine_GL_Context *gc,
2056 Evas_GL_Texture *tex,
2059 int clip, int cx, int cy, int cw, int ch,
2060 int r, int g, int b, int a,
2061 Eina_Bool smooth, Eina_Bool tex_only,
2062 Evas_Colorspace cspace)
2064 int pnum, nv, nc, nu, nu2, nu3, nt, i;
2065 const int points[6] = { 0, 1, 2, 0, 2, 3 };
2066 int x = 0, y = 0, w = 0, h = 0, px = 0, py = 0;
2067 GLfloat tx[4], ty[4], t2x[4], t2y[4];
2068 Eina_Bool blend = 1;
2070 GLuint prog = gc->shared->shader[SHADER_IMG].prog;
2071 Eina_Bool utexture = EINA_FALSE;
2072 Eina_Bool uvtexture = EINA_FALSE;
2076 if (!tex->alpha) blend = 0;
2077 if (a < 255) blend = 1;
2080 // FIXME: nash - you didn't fix this for n points. its still all
2081 // 4 point stuff!!! grrrr.
2084 if ((A_VAL(&(p[0].col)) < 0xff) || (A_VAL(&(p[1].col)) < 0xff) ||
2085 (A_VAL(&(p[2].col)) < 0xff) || (A_VAL(&(p[3].col)) < 0xff))
2088 if ((p[0].z == p[1].z) && (p[1].z == p[2].z) && (p[2].z == p[3].z))
2091 if (!clip) cx = cy = cw = ch = 0;
2095 if (p[0].foc <= 0) flat = 1;
2100 case EVAS_COLORSPACE_YCBCR422P601_PL:
2101 case EVAS_COLORSPACE_YCBCR422P709_PL:
2102 prog = gc->shared->shader[evas_gl_common_shader_choice(npoints, p, r, g, b, a,
2103 SHADER_YUV_NOMUL, SHADER_YUV)].prog;
2104 utexture = EINA_TRUE;
2106 case EVAS_COLORSPACE_YCBCR422601_PL:
2107 prog = gc->shared->shader[evas_gl_common_shader_choice(npoints, p, r, g, b, a,
2108 SHADER_YUY2_NOMUL, SHADER_YUY2)].prog;
2109 uvtexture = EINA_TRUE;
2111 case EVAS_COLORSPACE_YCBCR420NV12601_PL:
2112 case EVAS_COLORSPACE_YCBCR420TM12601_PL:
2113 prog = gc->shared->shader[evas_gl_common_shader_choice(npoints, p, r, g, b, a,
2114 SHADER_NV12_NOMUL, SHADER_NV12)].prog;
2115 uvtexture = EINA_TRUE;
2121 if (tex->pt->dyn.img)
2123 prog = gc->shared->shader[evas_gl_common_shader_choice(npoints, p, r, g, b, a,
2124 SHADER_IMG_BGRA_NOMUL, SHADER_IMG_BGRA)].prog;
2128 prog = gc->shared->shader[evas_gl_common_shader_choice(npoints, p, r, g, b, a,
2129 SHADER_TEX_NOMUL, SHADER_TEX)].prog;
2134 if (tex->gc->shared->info.bgra)
2136 prog = gc->shared->shader[evas_gl_common_shader_choice(npoints, p, r, g, b, a,
2137 SHADER_IMG_BGRA_NOMUL,
2138 SHADER_IMG_BGRA)].prog;
2142 prog = gc->shared->shader[evas_gl_common_shader_choice(npoints, p, r, g, b, a,
2149 x = w = (p[0].x >> FP);
2150 y = h = (p[0].y >> FP);
2151 for (i = 0; i < 4; i++)
2153 tx[i] = ((double)(tex->x) + (((double)p[i].u) / FP1)) /
2155 ty[i] = ((double)(tex->y) + (((double)p[i].v) / FP1)) /
2157 px = (p[i].x >> FP);
2159 else if (px > w) w = px;
2160 py = (p[i].y >> FP);
2162 else if (py > h) h = py;
2165 t2x[i] = ((((double)p[i].u / 2) / FP1)) / (double)tex->ptu->w;
2166 t2y[i] = ((((double)p[i].v / 2) / FP1)) / (double)tex->ptu->h;
2170 t2x[i] = ((((double)p[i].u / 2) / FP1)) / (double)tex->ptuv->w;
2171 t2y[i] = ((((double)p[i].v / 2) / FP1)) / (double)tex->ptuv->h;
2179 int nx = x, ny = y, nw = w, nh = h;
2181 RECTS_CLIP_TO_RECT(nx, ny, nw, nh, cx, cy, cw, ch);
2182 if ((nx == x) && (ny == y) && (nw == w) && (nh == h))
2184 clip = 0; cx = 0; cy = 0; cw = 0; ch = 0;
2186 x = nx; y = nw; w = nw; h = nh;
2191 shader_array_flush(gc);
2192 gc->foc = p[0].foc >> FP;
2193 gc->z0 = p[0].z0 >> FP;
2194 gc->px = p[0].px >> FP;
2195 gc->py = p[0].py >> FP;
2196 gc->change.size = 1;
2197 _evas_gl_common_viewport_set(gc);
2200 pn = _evas_gl_common_context_push(RTYPE_MAP,
2206 clip, cx, cy, cw, ch);
2207 gc->pipe[pn].region.type = RTYPE_MAP;
2208 gc->pipe[pn].shader.cur_tex = tex->pt->texture;
2211 gc->pipe[pn].shader.cur_texu = tex->ptu->texture;
2212 gc->pipe[pn].shader.cur_texu_dyn = tex->ptu->dyn.img;
2213 gc->pipe[pn].shader.cur_texv = tex->ptv->texture;
2214 gc->pipe[pn].shader.cur_texv_dyn = tex->ptv->dyn.img;
2218 gc->pipe[pn].shader.cur_texu = tex->ptuv->texture;
2219 gc->pipe[pn].shader.cur_texu_dyn = tex->ptuv->dyn.img;
2221 gc->pipe[pn].shader.cur_prog = prog;
2222 gc->pipe[pn].shader.smooth = smooth;
2223 gc->pipe[pn].shader.blend = blend;
2224 gc->pipe[pn].shader.render_op = gc->dc->render_op;
2225 gc->pipe[pn].shader.clip = clip;
2226 gc->pipe[pn].shader.cx = cx;
2227 gc->pipe[pn].shader.cy = cy;
2228 gc->pipe[pn].shader.cw = cw;
2229 gc->pipe[pn].shader.ch = ch;
2230 gc->pipe[pn].array.line = 0;
2231 gc->pipe[pn].array.use_vertex = 1;
2232 gc->pipe[pn].array.use_color = 1;
2233 gc->pipe[pn].array.use_texuv = 1;
2234 gc->pipe[pn].array.use_texuv2 = (utexture || uvtexture) ? 1 : 0;
2235 gc->pipe[pn].array.use_texuv3 = (utexture) ? 1 : 0;
2237 pipe_region_expand(gc, pn, x, y, w, h);
2239 pnum = gc->pipe[pn].array.num;
2240 nv = pnum * 3; nc = pnum * 4; nu = pnum * 2; nu2 = pnum * 2;
2241 nu2 = pnum * 2; nu3 = pnum * 2; nt = pnum * 4;
2242 gc->pipe[pn].array.num += 6;
2243 array_alloc(gc, pn);
2245 if ((tex->im) && (tex->im->native.data) && (!tex->im->native.yinvert))
2247 for (i = 0; i < 4; i++)
2249 ty[i] = 1.0 - ty[i];
2250 if (utexture || uvtexture)
2251 t2y[i] = 1.0 - t2y[i];
2255 cmul = ARGB_JOIN(a, r, g, b);
2256 for (i = 0; i < 6; i++)
2258 DATA32 cl = MUL4_SYM(cmul, p[points[i]].col);
2262 (p[points[i]].x >> FP),
2263 (p[points[i]].y >> FP),
2269 (p[points[i]].fx) + gc->shared->ax,
2270 (p[points[i]].fy) + gc->shared->ay,
2272 + (gc->shared->foc - gc->shared->z0));
2301 shader_array_flush(gc);
2306 gc->change.size = 1;
2307 _evas_gl_common_viewport_set(gc);
2312 evas_gl_common_context_flush(Evas_Engine_GL_Context *gc)
2314 shader_array_flush(gc);
2318 scissor_rot(Evas_Engine_GL_Context *gc __UNUSED__,
2319 int rot, int gw, int gh, int cx, int cy, int cw, int ch)
2323 case 0: // UP this way: ^
2324 glScissor(cx, cy, cw, ch);
2326 case 90: // UP this way: <
2327 glScissor(gh - (cy + ch), cx, ch, cw);
2329 case 180: // UP this way: v
2330 glScissor(gw - (cx + cw), gh - (cy + ch), cw, ch);
2332 case 270: // UP this way: >
2333 glScissor(cy, gw - (cx + cw), ch, cw);
2335 default: // assume up is up
2336 glScissor(cx, cy, cw, ch);
2342 shader_array_flush(Evas_Engine_GL_Context *gc)
2344 int i, gw, gh, setclip, cy, fbo = 0, done = 0;
2346 if (!gc->havestuff) return;
2349 if (!((gc->pipe[0].shader.surface == gc->def_surface) ||
2350 (!gc->pipe[0].shader.surface)))
2352 gw = gc->pipe[0].shader.surface->w;
2353 gh = gc->pipe[0].shader.surface->h;
2356 for (i = 0; i < gc->shared->info.tune.pipes.max; i++)
2358 if (gc->pipe[i].array.num <= 0) break;
2362 GLERR(__FUNCTION__, __FILE__, __LINE__, "<flush err>");
2363 if (gc->pipe[i].shader.cur_prog != gc->state.current.cur_prog)
2365 glUseProgram(gc->pipe[i].shader.cur_prog);
2366 GLERR(__FUNCTION__, __FILE__, __LINE__, "");
2369 if (gc->pipe[i].shader.cur_tex != gc->state.current.cur_tex)
2372 if (gc->pipe[i].shader.cur_tex)
2374 glEnable(GL_TEXTURE_2D);
2375 GLERR(__FUNCTION__, __FILE__, __LINE__, "");
2379 glDisable(GL_TEXTURE_2D);
2380 GLERR(__FUNCTION__, __FILE__, __LINE__, "");
2383 glActiveTexture(GL_TEXTURE0);
2384 GLERR(__FUNCTION__, __FILE__, __LINE__, "");
2385 glBindTexture(GL_TEXTURE_2D, gc->pipe[i].shader.cur_tex);
2386 GLERR(__FUNCTION__, __FILE__, __LINE__, "");
2388 if (gc->pipe[i].array.im)
2390 #if defined (GLES_VARIETY_S3C6410) || defined (GLES_VARIETY_SGX)
2391 if (gc->pipe[i].array.im->tex->pt->dyn.img)
2393 secsym_glEGLImageTargetTexture2DOES
2394 (GL_TEXTURE_2D, gc->pipe[i].array.im->tex->pt->dyn.img);
2399 if (!gc->pipe[i].array.im->native.loose)
2401 if (gc->pipe[i].array.im->native.func.bind)
2402 gc->pipe[i].array.im->native.func.bind(gc->pipe[i].array.im->native.func.data,
2403 gc->pipe[i].array.im);
2407 if (gc->pipe[i].shader.render_op != gc->state.current.render_op)
2409 switch (gc->pipe[i].shader.render_op)
2411 case EVAS_RENDER_BLEND: /**< default op: d = d*(1-sa) + s */
2412 glBlendFunc(GL_ONE, GL_ONE_MINUS_SRC_ALPHA);
2413 GLERR(__FUNCTION__, __FILE__, __LINE__, "");
2415 case EVAS_RENDER_COPY: /**< d = s */
2416 gc->pipe[i].shader.blend = 0;
2417 glBlendFunc(GL_ONE, GL_ONE);
2418 GLERR(__FUNCTION__, __FILE__, __LINE__, "");
2420 // FIXME: fix blend funcs below!
2421 case EVAS_RENDER_BLEND_REL: /**< d = d*(1 - sa) + s*da */
2422 case EVAS_RENDER_COPY_REL: /**< d = s*da */
2423 case EVAS_RENDER_ADD: /**< d = d + s */
2424 case EVAS_RENDER_ADD_REL: /**< d = d + s*da */
2425 case EVAS_RENDER_SUB: /**< d = d - s */
2426 case EVAS_RENDER_SUB_REL: /**< d = d - s*da */
2427 case EVAS_RENDER_TINT: /**< d = d*s + d*(1 - sa) + s*(1 - da) */
2428 case EVAS_RENDER_TINT_REL: /**< d = d*(1 - sa + s) */
2429 case EVAS_RENDER_MASK: /**< d = d*sa */
2430 case EVAS_RENDER_MUL: /**< d = d*s */
2432 glBlendFunc(GL_ONE, GL_ONE_MINUS_SRC_ALPHA);
2433 GLERR(__FUNCTION__, __FILE__, __LINE__, "");
2437 if (gc->pipe[i].shader.blend != gc->state.current.blend)
2439 if (gc->pipe[i].shader.blend)
2442 GLERR(__FUNCTION__, __FILE__, __LINE__, "");
2446 glDisable(GL_BLEND);
2447 GLERR(__FUNCTION__, __FILE__, __LINE__, "");
2450 if ((gc->pipe[i].shader.smooth != gc->state.current.smooth) ||
2451 (gc->pipe[i].shader.cur_tex != gc->state.current.cur_tex))
2453 if (gc->pipe[i].shader.smooth)
2455 #ifdef GL_TEXTURE_MAX_ANISOTROPY_EXT
2456 if (shared->info.anisotropic > 0.0)
2458 glTexParameterf(GL_TEXTURE_2D, GL_TEXTURE_MAX_ANISOTROPY_EXT, shared->info.anisotropic);
2459 GLERR(__FUNCTION__, __FILE__, __LINE__, "");
2462 glTexParameteri(GL_TEXTURE_2D, GL_TEXTURE_MAG_FILTER, GL_LINEAR);
2463 GLERR(__FUNCTION__, __FILE__, __LINE__, "");
2464 glTexParameteri(GL_TEXTURE_2D, GL_TEXTURE_MIN_FILTER, GL_LINEAR);
2465 GLERR(__FUNCTION__, __FILE__, __LINE__, "");
2466 glTexParameteri(GL_TEXTURE_2D, GL_TEXTURE_WRAP_S, GL_CLAMP_TO_EDGE);
2467 GLERR(__FUNCTION__, __FILE__, __LINE__, "");
2468 glTexParameteri(GL_TEXTURE_2D, GL_TEXTURE_WRAP_T, GL_CLAMP_TO_EDGE);
2469 GLERR(__FUNCTION__, __FILE__, __LINE__, "");
2473 #ifdef GL_TEXTURE_MAX_ANISOTROPY_EXT
2474 if (shared->info.anisotropic > 0.0)
2476 glTexParameterf(GL_TEXTURE_2D, GL_TEXTURE_MAX_ANISOTROPY_EXT, 1.0);
2477 GLERR(__FUNCTION__, __FILE__, __LINE__, "");
2480 glTexParameteri(GL_TEXTURE_2D, GL_TEXTURE_MAG_FILTER, GL_NEAREST);
2481 GLERR(__FUNCTION__, __FILE__, __LINE__, "");
2482 glTexParameteri(GL_TEXTURE_2D, GL_TEXTURE_MIN_FILTER, GL_NEAREST);
2483 GLERR(__FUNCTION__, __FILE__, __LINE__, "");
2484 glTexParameteri(GL_TEXTURE_2D, GL_TEXTURE_WRAP_S, GL_CLAMP_TO_EDGE);
2485 GLERR(__FUNCTION__, __FILE__, __LINE__, "");
2486 glTexParameteri(GL_TEXTURE_2D, GL_TEXTURE_WRAP_T, GL_CLAMP_TO_EDGE);
2487 GLERR(__FUNCTION__, __FILE__, __LINE__, "");
2490 if (gc->pipe[i].shader.clip != gc->state.current.clip)
2493 if (gc->pipe[i].shader.clip)
2495 cy = gh - gc->pipe[i].shader.cy - gc->pipe[i].shader.ch;
2496 if (fbo) cy = gc->pipe[i].shader.cy;
2497 glEnable(GL_SCISSOR_TEST);
2499 scissor_rot(gc, gc->rot, gw, gh,
2500 gc->pipe[i].shader.cx,
2502 gc->pipe[i].shader.cw,
2503 gc->pipe[i].shader.ch);
2505 glScissor(gc->pipe[i].shader.cx, cy,
2506 gc->pipe[i].shader.cw, gc->pipe[i].shader.ch);
2511 glDisable(GL_SCISSOR_TEST);
2512 glScissor(0, 0, 0, 0);
2515 if ((gc->pipe[i].shader.clip) && (!setclip))
2517 if ((gc->pipe[i].shader.cx != gc->state.current.cx) ||
2518 (gc->pipe[i].shader.cy != gc->state.current.cy) ||
2519 (gc->pipe[i].shader.cw != gc->state.current.cw) ||
2520 (gc->pipe[i].shader.ch != gc->state.current.ch))
2522 cy = gh - gc->pipe[i].shader.cy - gc->pipe[i].shader.ch;
2523 if (fbo) cy = gc->pipe[i].shader.cy;
2525 scissor_rot(gc, gc->rot, gw, gh,
2526 gc->pipe[i].shader.cx,
2528 gc->pipe[i].shader.cw,
2529 gc->pipe[i].shader.ch);
2531 glScissor(gc->pipe[i].shader.cx, cy,
2532 gc->pipe[i].shader.cw, gc->pipe[i].shader.ch);
2536 glVertexAttribPointer(SHAD_VERTEX, 3, GL_SHORT, GL_FALSE, 0, gc->pipe[i].array.vertex);
2537 GLERR(__FUNCTION__, __FILE__, __LINE__, "");
2538 glVertexAttribPointer(SHAD_COLOR, 4, GL_UNSIGNED_BYTE, GL_TRUE, 0, gc->pipe[i].array.color);
2539 GLERR(__FUNCTION__, __FILE__, __LINE__, "");
2540 if (gc->pipe[i].array.use_texuv)
2542 glEnableVertexAttribArray(SHAD_TEXUV);
2543 GLERR(__FUNCTION__, __FILE__, __LINE__, "");
2544 glVertexAttribPointer(SHAD_TEXUV, 2, GL_FLOAT, GL_FALSE, 0, gc->pipe[i].array.texuv);
2545 GLERR(__FUNCTION__, __FILE__, __LINE__, "");
2549 glDisableVertexAttribArray(SHAD_TEXUV);
2550 GLERR(__FUNCTION__, __FILE__, __LINE__, "");
2553 if (gc->pipe[i].array.line)
2555 glDisableVertexAttribArray(SHAD_TEXUV);
2556 GLERR(__FUNCTION__, __FILE__, __LINE__, "");
2557 glDisableVertexAttribArray(SHAD_TEXUV2);
2558 GLERR(__FUNCTION__, __FILE__, __LINE__, "");
2559 glDisableVertexAttribArray(SHAD_TEXUV3);
2560 GLERR(__FUNCTION__, __FILE__, __LINE__, "");
2561 glDrawArrays(GL_LINES, 0, gc->pipe[i].array.num);
2562 GLERR(__FUNCTION__, __FILE__, __LINE__, "");
2566 if (gc->pipe[i].array.use_texm)
2568 glEnableVertexAttribArray(SHAD_TEXM);
2569 GLERR(__FUNCTION__, __FILE__, __LINE__, "");
2570 glVertexAttribPointer(SHAD_TEXM, 2, GL_FLOAT, GL_FALSE, 0, gc->pipe[i].array.texm);
2571 GLERR(__FUNCTION__, __FILE__, __LINE__, "");
2572 glActiveTexture(GL_TEXTURE1);
2573 GLERR(__FUNCTION__, __FILE__, __LINE__, "");
2574 glBindTexture(GL_TEXTURE_2D, gc->pipe[i].shader.cur_texm);
2575 GLERR(__FUNCTION__, __FILE__, __LINE__, "");
2576 glActiveTexture(GL_TEXTURE0);
2577 GLERR(__FUNCTION__, __FILE__, __LINE__, "");
2581 glDisableVertexAttribArray(SHAD_TEXM);
2583 if ((gc->pipe[i].array.use_texuv2) && (gc->pipe[i].array.use_texuv3))
2585 glEnableVertexAttribArray(SHAD_TEXUV2);
2586 GLERR(__FUNCTION__, __FILE__, __LINE__, "");
2587 glEnableVertexAttribArray(SHAD_TEXUV3);
2588 GLERR(__FUNCTION__, __FILE__, __LINE__, "");
2589 glVertexAttribPointer(SHAD_TEXUV2, 2, GL_FLOAT, GL_FALSE, 0, gc->pipe[i].array.texuv2);
2590 GLERR(__FUNCTION__, __FILE__, __LINE__, "");
2591 glVertexAttribPointer(SHAD_TEXUV3, 2, GL_FLOAT, GL_FALSE, 0, gc->pipe[i].array.texuv3);
2592 GLERR(__FUNCTION__, __FILE__, __LINE__, "");
2594 glActiveTexture(GL_TEXTURE1);
2595 GLERR(__FUNCTION__, __FILE__, __LINE__, "");
2596 glBindTexture(GL_TEXTURE_2D, gc->pipe[i].shader.cur_texu);
2597 GLERR(__FUNCTION__, __FILE__, __LINE__, "");
2598 #if defined (GLES_VARIETY_S3C6410) || defined (GLES_VARIETY_SGX)
2599 if (gc->pipe[i].shader.cur_texu_dyn)
2600 secsym_glEGLImageTargetTexture2DOES(GL_TEXTURE_2D, gc->pipe[i].shader.cur_texu_dyn);
2603 glActiveTexture(GL_TEXTURE2);
2604 GLERR(__FUNCTION__, __FILE__, __LINE__, "");
2605 glBindTexture(GL_TEXTURE_2D, gc->pipe[i].shader.cur_texv);
2606 GLERR(__FUNCTION__, __FILE__, __LINE__, "");
2607 #if defined (GLES_VARIETY_S3C6410) || defined (GLES_VARIETY_SGX)
2608 if (gc->pipe[i].shader.cur_texv_dyn)
2609 secsym_glEGLImageTargetTexture2DOES(GL_TEXTURE_2D, gc->pipe[i].shader.cur_texv_dyn);
2611 glActiveTexture(GL_TEXTURE0);
2612 GLERR(__FUNCTION__, __FILE__, __LINE__, "");
2614 else if (gc->pipe[i].array.use_texuv2)
2616 glEnableVertexAttribArray(SHAD_TEXUV2);
2617 GLERR(__FUNCTION__, __FILE__, __LINE__, "");
2618 glVertexAttribPointer(SHAD_TEXUV2, 2, GL_FLOAT, GL_FALSE, 0, gc->pipe[i].array.texuv2);
2619 GLERR(__FUNCTION__, __FILE__, __LINE__, "");
2621 glActiveTexture(GL_TEXTURE1);
2622 GLERR(__FUNCTION__, __FILE__, __LINE__, "");
2623 glBindTexture(GL_TEXTURE_2D, gc->pipe[i].shader.cur_texu);
2624 GLERR(__FUNCTION__, __FILE__, __LINE__, "");
2625 #if defined (GLES_VARIETY_S3C6410) || defined (GLES_VARIETY_SGX)
2626 if (gc->pipe[i].shader.cur_texu_dyn)
2627 secsym_glEGLImageTargetTexture2DOES(GL_TEXTURE_2D, gc->pipe[i].shader.cur_texu_dyn);
2629 glActiveTexture(GL_TEXTURE0);
2630 GLERR(__FUNCTION__, __FILE__, __LINE__, "");
2634 glDisableVertexAttribArray(SHAD_TEXUV2);
2635 GLERR(__FUNCTION__, __FILE__, __LINE__, "");
2636 glDisableVertexAttribArray(SHAD_TEXUV3);
2637 GLERR(__FUNCTION__, __FILE__, __LINE__, "");
2641 const char *types[6] =
2642 {"----", "RECT", "IMAG", "FONT", "YUV-", "MAP"};
2643 printf(" DRAW#%3i %4i -> %p[%4ix%4i] @ %4ix%4i -{ tex %4i type %s }-\n",
2645 gc->pipe[i].array.num / 6,
2646 gc->pipe[0].shader.surface,
2647 gc->pipe[0].shader.surface->w,
2648 gc->pipe[0].shader.surface->h,
2650 gc->pipe[i].shader.cur_tex,
2651 types[gc->pipe[i].region.type]
2654 glDrawArrays(GL_TRIANGLES, 0, gc->pipe[i].array.num);
2655 GLERR(__FUNCTION__, __FILE__, __LINE__, "");
2657 if (gc->pipe[i].array.im)
2659 if (!gc->pipe[i].array.im->native.loose)
2661 if (gc->pipe[i].array.im->native.func.unbind)
2662 gc->pipe[i].array.im->native.func.unbind(gc->pipe[i].array.im->native.func.data,
2663 gc->pipe[i].array.im);
2665 gc->pipe[i].array.im = NULL;
2668 gc->state.current.cur_prog = gc->pipe[i].shader.cur_prog;
2669 gc->state.current.cur_tex = gc->pipe[i].shader.cur_tex;
2670 gc->state.current.render_op = gc->pipe[i].shader.render_op;
2671 gc->state.current.cx = gc->pipe[i].shader.cx;
2672 gc->state.current.cy = gc->pipe[i].shader.cy;
2673 gc->state.current.cw = gc->pipe[i].shader.cw;
2674 gc->state.current.ch = gc->pipe[i].shader.ch;
2675 gc->state.current.smooth = gc->pipe[i].shader.smooth;
2676 gc->state.current.blend = gc->pipe[i].shader.blend;
2677 gc->state.current.clip = gc->pipe[i].shader.clip;
2679 if (gc->pipe[i].array.vertex) free(gc->pipe[i].array.vertex);
2680 if (gc->pipe[i].array.color) free(gc->pipe[i].array.color);
2681 if (gc->pipe[i].array.texuv) free(gc->pipe[i].array.texuv);
2682 if (gc->pipe[i].array.texm) free(gc->pipe[i].array.texm);
2683 if (gc->pipe[i].array.texuv2) free(gc->pipe[i].array.texuv2);
2684 if (gc->pipe[i].array.texuv3) free(gc->pipe[i].array.texuv3);
2686 gc->pipe[i].array.vertex = NULL;
2687 gc->pipe[i].array.color = NULL;
2688 gc->pipe[i].array.texuv = NULL;
2689 gc->pipe[i].array.texm = NULL;
2690 gc->pipe[i].array.texuv2 = NULL;
2691 gc->pipe[i].array.texuv3 = NULL;
2693 gc->pipe[i].array.num = 0;
2694 gc->pipe[i].array.alloc = 0;
2696 gc->pipe[i].region.x = 0;
2697 gc->pipe[i].region.y = 0;
2698 gc->pipe[i].region.w = 0;
2699 gc->pipe[i].region.h = 0;
2700 gc->pipe[i].region.type = 0;
2702 gc->state.top_pipe = 0;
2705 if (done > 0) printf("DONE (pipes): %i\n", done);
2707 gc->havestuff = EINA_FALSE;
2711 evas_gl_common_module_open(void)
2713 if (_evas_engine_GL_common_log_dom < 0)
2714 _evas_engine_GL_common_log_dom = eina_log_domain_register
2715 ("evas-gl_common", EVAS_DEFAULT_LOG_COLOR);
2716 if (_evas_engine_GL_common_log_dom < 0)
2718 EINA_LOG_ERR("Can not create a module log domain.");
2725 evas_gl_common_module_close(void)
2727 if (_evas_engine_GL_common_log_dom < 0) return;
2728 eina_log_domain_unregister(_evas_engine_GL_common_log_dom);
2729 _evas_engine_GL_common_log_dom = -1;