1 #include "evas_gl_private.h"
3 static int sym_done = 0;
5 void (*glsym_glGenFramebuffers) (GLsizei a, GLuint *b) = NULL;
6 void (*glsym_glBindFramebuffer) (GLenum a, GLuint b) = NULL;
7 void (*glsym_glFramebufferTexture2D) (GLenum a, GLenum b, GLenum c, GLuint d, GLint e) = NULL;
8 void (*glsym_glDeleteFramebuffers) (GLsizei a, const GLuint *b) = NULL;
13 printf("EVAS ERROR - GL symbols missing!\n");
22 #ifdef _EVAS_ENGINE_SDL_H
23 # define FINDSYM(dst, sym) if (!dst) dst = SDL_GL_GetProcAddress(sym)
25 # define FINDSYM(dst, sym) if (!dst) dst = dlsym(RTLD_DEFAULT, sym)
27 #define FALLBAK(dst) if (!dst) dst = (void *)sym_missing;
29 FINDSYM(glsym_glGenFramebuffers, "glGenFramebuffers");
30 FINDSYM(glsym_glGenFramebuffers, "glGenFramebuffersEXT");
31 FINDSYM(glsym_glGenFramebuffers, "glGenFramebuffersARB");
32 FALLBAK(glsym_glGenFramebuffers);
34 FINDSYM(glsym_glBindFramebuffer, "glBindFramebuffer");
35 FINDSYM(glsym_glBindFramebuffer, "glBindFramebufferEXT");
36 FINDSYM(glsym_glBindFramebuffer, "glBindFramebufferARB");
37 FALLBAK(glsym_glBindFramebuffer);
39 FINDSYM(glsym_glFramebufferTexture2D, "glFramebufferTexture2D");
40 FINDSYM(glsym_glFramebufferTexture2D, "glFramebufferTexture2DEXT");
41 FINDSYM(glsym_glFramebufferTexture2D, "glFramebufferTexture2DARB");
42 FALLBAK(glsym_glFramebufferTexture2D);
44 FINDSYM(glsym_glDeleteFramebuffers, "glDeleteFramebuffers");
45 FINDSYM(glsym_glDeleteFramebuffers, "glDeleteFramebuffersEXT");
46 FINDSYM(glsym_glDeleteFramebuffers, "glDeleteFramebuffersARB");
47 FALLBAK(glsym_glDeleteFramebuffers);
50 static void shader_array_flush(Evas_GL_Context *gc);
52 static Evas_GL_Context *_evas_gl_common_context = NULL;
53 static Evas_GL_Shared *shared = NULL;
56 glerr(int err, const char *file, const char *func, int line, const char *op)
58 fprintf(stderr, "GLERR: %s:%i %s(), %s: ", file, line, func, op);
62 fprintf(stderr, "GL_INVALID_ENUM\n");
64 case GL_INVALID_VALUE:
65 fprintf(stderr, "GL_INVALID_VALUE\n");
67 case GL_INVALID_OPERATION:
68 fprintf(stderr, "GL_INVALID_OPERATION\n");
70 case GL_OUT_OF_MEMORY:
71 fprintf(stderr, "GL_OUT_OF_MEMORY\n");
74 fprintf(stderr, "0x%x\n", err);
79 matrix_ident(GLfloat *m)
81 memset(m, 0, 16 * sizeof(GLfloat));
82 m[0] = m[5] = m[10] = m[15] = 1.0;
83 //------------------------
91 matrix_ortho(GLfloat *m,
94 GLfloat near, GLfloat far,
95 int rot, int w, int h)
102 //------------------------
103 m[0] = 2.0 / (r - l);
108 //------------------------
110 m[5] = 2.0 / (t - b);
114 //------------------------
117 m[10] = -(2.0 / (far - near));
120 //------------------------
121 m[12] = -((r + l) / (r - l));
122 m[13] = -((t + b) / (t - b));
123 m[14] = -((near + far) / (far - near));
127 rotf = (((rot / 90) & 0x3) * M_PI) / 2.0;
150 m[0] = (2.0 / (r - l)) * ( cosv);
151 m[1] = (2.0 / (r - l)) * ( sinv);
153 m[4] = (2.0 / (t - b)) * (-sinv);
154 m[5] = (2.0 / (t - b)) * ( cosv);
156 m[12] += (m[0] * tx) + (m[4] * ty);
157 m[13] += (m[1] * tx) + (m[5] * ty);
158 m[14] += (m[2] * tx) + (m[6] * ty);
159 m[15] += (m[3] * tx) + (m[7] * ty);
163 _evas_gl_common_version_check()
172 * glGetString returns a string describing the current GL connection.
173 * GL_VERSION is used to get the version of the connection
176 version = (char *)glGetString(GL_VERSION);
183 * OpenGL ES-<profile> <major>.<minor>
185 * where <profile> is either "CM" or "CL". The minor can be followed by the vendor
186 * specific information
190 * OpenGL<space>ES<space><version number><space><vendor-specific information>
193 /* OpenGL ES 1.* ? */
195 if ((tmp = strstr(version, "OpenGL ES-CM ")) || (tmp = strstr(version, "OpenGL ES-CL ")))
201 /* OpenGL ES 2.* ? */
203 if ((tmp = strstr(version, "OpenGL ES ")))
212 * The GL_VERSION and GL_SHADING_LANGUAGE_VERSION strings begin with a
213 * version number. The version number uses one of these forms:
215 * major_number.minor_number
216 * major_number.minor_number.release_number
218 * Vendor-specific information may follow the version number. Its format
219 * depends on the implementation, but a space always separates the
220 * version number and the vendor-specific information.
223 /* glGetString() returns a static string, and we are going to */
224 /* modify it, so we get a copy first */
225 version = strdup(version);
229 tmp = strchr(version, '.');
230 /* the first '.' always exists */
232 major = atoi(version);
233 /* FIXME: maybe we can assume that minor in only a cipher */
235 while ((*tmp != '.') && (*tmp != ' ') && (*tmp != '\0'))
237 /* *tmp is '\0' : version is major_number.minor_number */
238 /* *tmp is '.' : version is major_number.minor_number.release_number */
239 /* *tmp is ' ' : version is major_number.minor_number followed by vendor */
244 if (((major == 1) && (minor >= 4)) || (major >= 2))
251 _evas_gl_common_viewport_set(Evas_GL_Context *gc)
254 int w = 1, h = 1, m = 1, rot = 1;
256 if ((gc->shader.surface == gc->def_surface) ||
257 (!gc->shader.surface))
265 w = gc->shader.surface->w;
266 h = gc->shader.surface->h;
271 if ((!gc->change.size) ||
272 ((gc->shared->w == w) && (gc->shared->h == h) && (gc->shared->rot == rot)))
277 gc->shared->rot = rot;
280 if ((rot == 0) || (rot == 180))
281 glViewport(0, 0, w, h);
283 glViewport(0, 0, h, w);
284 GLERR(__FUNCTION__, __FILE__, __LINE__, "");
287 if (m == 1) matrix_ortho(proj, 0, w, 0, h, -1.0, 1.0, rot, w, h);
288 else matrix_ortho(proj, 0, w, h, 0, -1.0, 1.0, rot, w, h);
290 glUseProgram(gc->shared->shader.rect.prog);
291 GLERR(__FUNCTION__, __FILE__, __LINE__, "");
292 glUniformMatrix4fv(glGetUniformLocation(gc->shared->shader.rect.prog, "mvp"), 1,
294 GLERR(__FUNCTION__, __FILE__, __LINE__, "");
295 glUseProgram(gc->shared->shader.font.prog);
296 GLERR(__FUNCTION__, __FILE__, __LINE__, "");
297 glUniformMatrix4fv(glGetUniformLocation(gc->shared->shader.font.prog, "mvp"), 1,
299 GLERR(__FUNCTION__, __FILE__, __LINE__, "");
301 glUseProgram(gc->shared->shader.yuv.prog);
302 GLERR(__FUNCTION__, __FILE__, __LINE__, "");
303 glUniformMatrix4fv(glGetUniformLocation(gc->shared->shader.yuv.prog, "mvp"), 1,
305 GLERR(__FUNCTION__, __FILE__, __LINE__, "");
306 glUseProgram(gc->shared->shader.yuv_nomul.prog);
307 GLERR(__FUNCTION__, __FILE__, __LINE__, "");
308 glUniformMatrix4fv(glGetUniformLocation(gc->shared->shader.yuv_nomul.prog, "mvp"), 1,
310 GLERR(__FUNCTION__, __FILE__, __LINE__, "");
312 glUseProgram(gc->shared->shader.tex.prog);
313 GLERR(__FUNCTION__, __FILE__, __LINE__, "");
314 glUniformMatrix4fv(glGetUniformLocation(gc->shared->shader.tex.prog, "mvp"), 1,
316 GLERR(__FUNCTION__, __FILE__, __LINE__, "");
317 glUseProgram(gc->shared->shader.tex_nomul.prog);
318 GLERR(__FUNCTION__, __FILE__, __LINE__, "");
319 glUniformMatrix4fv(glGetUniformLocation(gc->shared->shader.tex_nomul.prog, "mvp"), 1,
321 GLERR(__FUNCTION__, __FILE__, __LINE__, "");
323 glUseProgram(gc->shared->shader.img.prog);
324 GLERR(__FUNCTION__, __FILE__, __LINE__, "");
325 glUniformMatrix4fv(glGetUniformLocation(gc->shared->shader.img.prog, "mvp"), 1,
327 GLERR(__FUNCTION__, __FILE__, __LINE__, "");
328 glUseProgram(gc->shared->shader.img_nomul.prog);
329 GLERR(__FUNCTION__, __FILE__, __LINE__, "");
330 glUniformMatrix4fv(glGetUniformLocation(gc->shared->shader.img_nomul.prog, "mvp"), 1,
332 GLERR(__FUNCTION__, __FILE__, __LINE__, "");
334 glUseProgram(gc->shared->shader.img_bgra.prog);
335 GLERR(__FUNCTION__, __FILE__, __LINE__, "");
336 glUniformMatrix4fv(glGetUniformLocation(gc->shared->shader.img_bgra.prog, "mvp"), 1,
338 GLERR(__FUNCTION__, __FILE__, __LINE__, "");
339 glUseProgram(gc->shared->shader.img_bgra_nomul.prog);
340 GLERR(__FUNCTION__, __FILE__, __LINE__, "");
341 glUniformMatrix4fv(glGetUniformLocation(gc->shared->shader.img_bgra_nomul.prog, "mvp"), 1,
343 GLERR(__FUNCTION__, __FILE__, __LINE__, "");
345 glUseProgram(gc->shader.cur_prog);
346 GLERR(__FUNCTION__, __FILE__, __LINE__, "");
350 evas_gl_common_context_new(void)
355 if (_evas_gl_common_context)
357 _evas_gl_common_context->references++;
358 return _evas_gl_common_context;
361 if (!_evas_gl_common_version_check())
363 gc = calloc(1, sizeof(Evas_GL_Context));
364 if (!gc) return NULL;
370 _evas_gl_common_context = gc;
372 gc->shader.render_op = EVAS_RENDER_BLEND;
377 unsigned int pixel = 0xffffffff;
380 shared = calloc(1, sizeof(Evas_GL_Shared));
381 ext = glGetString(GL_EXTENSIONS);
384 fprintf(stderr, "EXT:\n%s\n", ext);
385 if ((strstr((char*) ext, "GL_ARB_texture_non_power_of_two")) ||
386 (strstr((char*) ext, "OES_texture_npot")) ||
387 (strstr((char*) ext, "GL_IMG_texture_npot")))
388 shared->info.tex_npo2 = 1;
389 if ((strstr((char*) ext, "GL_NV_texture_rectangle")) ||
390 (strstr((char*) ext, "GL_EXT_texture_rectangle")) ||
391 (strstr((char*) ext, "GL_ARB_texture_rectangle")))
392 shared->info.tex_rect = 1;
393 #ifdef GL_TEXTURE_MAX_ANISOTROPY_EXT
394 if ((strstr((char*) ext, "GL_EXT_texture_filter_anisotropic")))
395 glGetFloatv(GL_MAX_TEXTURE_MAX_ANISOTROPY_EXT,
396 &(shared->info.anisotropic));
399 if ((strstr((char*) ext, "GL_EXT_bgra")) ||
400 (strstr((char*) ext, "GL_EXT_texture_format_BGRA8888")))
401 shared->info.bgra = 1;
404 glGetIntegerv(GL_MAX_TEXTURE_IMAGE_UNITS,
405 &(shared->info.max_texture_units));
406 glGetIntegerv(GL_MAX_TEXTURE_SIZE,
407 &(shared->info.max_texture_size));
409 shared->info.cutout_max = 512; // hmmm is this good?
410 if (getenv("EVAS_GL_CUTOUT_MAX"))
411 shared->info.cutout_max = atoi(getenv("EVAS_GL_CUTOUT_MAX"));
413 fprintf(stderr, "max tex size %ix%i\n"
415 "non-power-2 tex %i\n"
418 "max ansiotropic filtering: %3.3f\n"
422 shared->info.max_texture_size, shared->info.max_texture_size,
423 shared->info.max_texture_units,
424 (int)shared->info.tex_npo2,
425 (int)shared->info.tex_rect,
426 (int)shared->info.bgra,
427 (double)shared->info.anisotropic,
429 shared->info.cutout_max
432 glDisable(GL_DEPTH_TEST);
433 GLERR(__FUNCTION__, __FILE__, __LINE__, "");
435 GLERR(__FUNCTION__, __FILE__, __LINE__, "");
437 GLERR(__FUNCTION__, __FILE__, __LINE__, "");
438 glBlendFunc(GL_ONE, GL_ONE_MINUS_SRC_ALPHA);
439 GLERR(__FUNCTION__, __FILE__, __LINE__, "");
441 // glBlendFunc(GL_SRC_ALPHA, GL_ONE_MINUS_SRC_ALPHA); // dest alpha
442 // glBlendFunc(GL_SRC_ALPHA, GL_ONE); // ???
443 glDepthMask(GL_FALSE);
444 GLERR(__FUNCTION__, __FILE__, __LINE__, "");
446 glTexParameteri(GL_TEXTURE_2D, GL_TEXTURE_MAG_FILTER, GL_NEAREST);
447 GLERR(__FUNCTION__, __FILE__, __LINE__, "");
448 glTexParameteri(GL_TEXTURE_2D, GL_TEXTURE_MIN_FILTER, GL_NEAREST);
449 GLERR(__FUNCTION__, __FILE__, __LINE__, "");
450 glTexParameteri(GL_TEXTURE_2D, GL_TEXTURE_WRAP_S, GL_CLAMP_TO_EDGE);
451 GLERR(__FUNCTION__, __FILE__, __LINE__, "");
452 glTexParameteri(GL_TEXTURE_2D, GL_TEXTURE_WRAP_T, GL_CLAMP_TO_EDGE);
453 GLERR(__FUNCTION__, __FILE__, __LINE__, "");
454 #ifdef GL_TEXTURE_MAX_ANISOTROPY_EXT
455 if (shared->info.anisotropic > 0.0)
457 glTexParameterf(GL_TEXTURE_2D, GL_TEXTURE_MAX_ANISOTROPY_EXT, 1.0);
458 GLERR(__FUNCTION__, __FILE__, __LINE__, "");
462 glEnableVertexAttribArray(SHAD_VERTEX);
463 GLERR(__FUNCTION__, __FILE__, __LINE__, "");
464 glEnableVertexAttribArray(SHAD_COLOR);
465 GLERR(__FUNCTION__, __FILE__, __LINE__, "");
467 if (!evas_gl_common_shader_program_init(&(shared->shader.rect),
468 &(shader_rect_vert_src),
469 &(shader_rect_frag_src),
471 if (!evas_gl_common_shader_program_init(&(shared->shader.font),
472 &(shader_font_vert_src),
473 &(shader_font_frag_src),
475 if (!evas_gl_common_shader_program_init(&(shared->shader.img),
476 &(shader_img_vert_src),
477 &(shader_img_frag_src),
479 if (!evas_gl_common_shader_program_init(&(shared->shader.img_nomul),
480 &(shader_img_nomul_vert_src),
481 &(shader_img_nomul_frag_src),
482 "img_nomul")) goto error;
483 if (!evas_gl_common_shader_program_init(&(shared->shader.img_bgra),
484 &(shader_img_bgra_vert_src),
485 &(shader_img_bgra_frag_src),
486 "img_bgra")) goto error;
487 if (!evas_gl_common_shader_program_init(&(shared->shader.img_bgra_nomul),
488 &(shader_img_bgra_nomul_vert_src),
489 &(shader_img_bgra_nomul_frag_src),
490 "img_bgra_nomul")) goto error;
491 if (!evas_gl_common_shader_program_init(&(shared->shader.tex),
492 &(shader_tex_vert_src),
493 &(shader_tex_frag_src),
495 if (!evas_gl_common_shader_program_init(&(shared->shader.tex_nomul),
496 &(shader_tex_nomul_vert_src),
497 &(shader_tex_nomul_frag_src),
498 "tex_nomul")) goto error;
499 if (!evas_gl_common_shader_program_init(&(shared->shader.yuv),
500 &(shader_yuv_vert_src),
501 &(shader_yuv_frag_src),
503 if (!evas_gl_common_shader_program_init(&(shared->shader.yuv_nomul),
504 &(shader_yuv_nomul_vert_src),
505 &(shader_yuv_nomul_frag_src),
506 "yuv_nomul")) goto error;
508 glUseProgram(shared->shader.yuv.prog);
509 GLERR(__FUNCTION__, __FILE__, __LINE__, "");
510 glUniform1i(glGetUniformLocation(shared->shader.yuv.prog, "tex"), 0);
511 GLERR(__FUNCTION__, __FILE__, __LINE__, "");
512 glUniform1i(glGetUniformLocation(shared->shader.yuv.prog, "texu"), 1);
513 GLERR(__FUNCTION__, __FILE__, __LINE__, "");
514 glUniform1i(glGetUniformLocation(shared->shader.yuv.prog, "texv"), 2);
515 GLERR(__FUNCTION__, __FILE__, __LINE__, "");
517 glUseProgram(shared->shader.yuv_nomul.prog);
518 GLERR(__FUNCTION__, __FILE__, __LINE__, "");
519 glUniform1i(glGetUniformLocation(shared->shader.yuv_nomul.prog, "tex"), 0);
520 GLERR(__FUNCTION__, __FILE__, __LINE__, "");
521 glUniform1i(glGetUniformLocation(shared->shader.yuv_nomul.prog, "texu"), 1);
522 GLERR(__FUNCTION__, __FILE__, __LINE__, "");
523 glUniform1i(glGetUniformLocation(shared->shader.yuv_nomul.prog, "texv"), 2);
524 GLERR(__FUNCTION__, __FILE__, __LINE__, "");
526 glUseProgram(gc->shader.cur_prog);
527 GLERR(__FUNCTION__, __FILE__, __LINE__, "");
529 // uniform sampler2D tex[8];
533 // GLint loc = glGetUniformLocation(prog, "tex");
534 // glUniform1iv(loc, 8, texes);
537 gc->shared->references++;
538 _evas_gl_common_viewport_set(gc);
540 gc->def_surface = evas_gl_common_image_surface_new(gc, 1, 1, 1);
544 evas_gl_common_context_free(gc);
549 evas_gl_common_context_free(Evas_GL_Context *gc)
554 if (gc->references > 0) return;
555 if (gc->shared) gc->shared->references--;
557 if (gc->def_surface) evas_gl_common_image_free(gc->def_surface);
559 if ((gc->shared) && (gc->shared->references == 0))
561 evas_gl_common_shader_program_shutdown(&(gc->shared->shader.rect));
562 evas_gl_common_shader_program_shutdown(&(gc->shared->shader.font));
563 evas_gl_common_shader_program_shutdown(&(gc->shared->shader.img));
564 evas_gl_common_shader_program_shutdown(&(gc->shared->shader.img_nomul));
565 evas_gl_common_shader_program_shutdown(&(gc->shared->shader.img_bgra));
566 evas_gl_common_shader_program_shutdown(&(gc->shared->shader.img_bgra_nomul));
567 evas_gl_common_shader_program_shutdown(&(gc->shared->shader.yuv));
568 evas_gl_common_shader_program_shutdown(&(gc->shared->shader.yuv_nomul));
569 evas_gl_common_shader_program_shutdown(&(gc->shared->shader.tex));
570 evas_gl_common_shader_program_shutdown(&(gc->shared->shader.tex_nomul));
572 while (gc->shared->images)
574 evas_gl_common_image_free(gc->shared->images->data);
576 while (gc->shared->tex.whole)
578 evas_gl_common_texture_free(gc->shared->tex.whole->data);
580 for (i = 0; i < 33; i++)
582 for (j = 0; j < 3; j++)
584 while (gc->shared->tex.atlas[i][j])
586 evas_gl_common_texture_free
587 ((Evas_GL_Texture *)gc->shared->tex.atlas[i][j]);
588 gc->shared->tex.atlas[i][j] = NULL;
597 if (gc->array.vertex) free(gc->array.vertex);
598 if (gc->array.color) free(gc->array.color);
599 if (gc->array.texuv) free(gc->array.texuv);
600 if (gc->array.texuv2) free(gc->array.texuv2);
601 if (gc->array.texuv3) free(gc->array.texuv3);
603 if (gc == _evas_gl_common_context) _evas_gl_common_context = NULL;
608 evas_gl_common_context_use(Evas_GL_Context *gc)
610 if (_evas_gl_common_context == gc) return;
611 _evas_gl_common_context = gc;
612 _evas_gl_common_viewport_set(gc);
616 evas_gl_common_context_newframe(Evas_GL_Context *gc)
623 gc->shader.surface = NULL;
624 gc->shader.cur_prog = 0;
625 gc->shader.cur_tex = 0;
626 gc->shader.cur_texu = 0;
627 gc->shader.cur_texv = 0;
628 gc->shader.render_op = EVAS_RENDER_BLEND;
633 gc->shader.smooth = 0;
634 gc->shader.blend = 0;
636 gc->shader.current.cur_prog = 0;
637 gc->shader.current.cur_tex = 0;
638 gc->shader.current.cur_texu = 0;
639 gc->shader.current.cur_texv = 0;
640 gc->shader.current.render_op = 0;
641 gc->shader.current.cx = 0;
642 gc->shader.current.cy = 0;
643 gc->shader.current.cw = 0;
644 gc->shader.current.ch = 0;
645 gc->shader.current.smooth = 0;
646 gc->shader.current.blend = 0;
647 gc->shader.current.clip = 0;
650 glDisable(GL_SCISSOR_TEST);
651 GLERR(__FUNCTION__, __FILE__, __LINE__, "");
652 glScissor(0, 0, 0, 0);
653 GLERR(__FUNCTION__, __FILE__, __LINE__, "");
655 glDisable(GL_DEPTH_TEST);
656 GLERR(__FUNCTION__, __FILE__, __LINE__, "");
658 GLERR(__FUNCTION__, __FILE__, __LINE__, "");
660 GLERR(__FUNCTION__, __FILE__, __LINE__, "");
661 glBlendFunc(GL_ONE, GL_ONE_MINUS_SRC_ALPHA);
662 GLERR(__FUNCTION__, __FILE__, __LINE__, "");
664 // glBlendFunc(GL_SRC_ALPHA, GL_ONE_MINUS_SRC_ALPHA); // dest alpha
665 // glBlendFunc(GL_SRC_ALPHA, GL_ONE); // ???
666 glDepthMask(GL_FALSE);
667 GLERR(__FUNCTION__, __FILE__, __LINE__, "");
669 glTexParameteri(GL_TEXTURE_2D, GL_TEXTURE_MAG_FILTER, GL_NEAREST);
670 GLERR(__FUNCTION__, __FILE__, __LINE__, "");
671 glTexParameteri(GL_TEXTURE_2D, GL_TEXTURE_MIN_FILTER, GL_NEAREST);
672 GLERR(__FUNCTION__, __FILE__, __LINE__, "");
673 glTexParameteri(GL_TEXTURE_2D, GL_TEXTURE_WRAP_S, GL_CLAMP_TO_EDGE);
674 GLERR(__FUNCTION__, __FILE__, __LINE__, "");
675 glTexParameteri(GL_TEXTURE_2D, GL_TEXTURE_WRAP_T, GL_CLAMP_TO_EDGE);
676 GLERR(__FUNCTION__, __FILE__, __LINE__, "");
677 #ifdef GL_TEXTURE_MAX_ANISOTROPY_EXT
678 if (shared->info.anisotropic > 0.0)
680 glTexParameterf(GL_TEXTURE_2D, GL_TEXTURE_MAX_ANISOTROPY_EXT, 1.0);
681 GLERR(__FUNCTION__, __FILE__, __LINE__, "");
685 glEnableVertexAttribArray(SHAD_VERTEX);
686 GLERR(__FUNCTION__, __FILE__, __LINE__, "");
687 glEnableVertexAttribArray(SHAD_COLOR);
688 GLERR(__FUNCTION__, __FILE__, __LINE__, "");
689 glUseProgram(gc->shader.cur_prog);
690 GLERR(__FUNCTION__, __FILE__, __LINE__, "");
692 glActiveTexture(GL_TEXTURE0);
693 GLERR(__FUNCTION__, __FILE__, __LINE__, "");
694 glBindTexture(GL_TEXTURE_2D, gc->shader.cur_tex);
695 GLERR(__FUNCTION__, __FILE__, __LINE__, "");
697 _evas_gl_common_viewport_set(gc);
701 evas_gl_common_context_resize(Evas_GL_Context *gc, int w, int h, int rot)
703 if ((gc->w == w) && (gc->h == h) && (gc->rot == rot)) return;
708 if (_evas_gl_common_context == gc) _evas_gl_common_viewport_set(gc);
712 evas_gl_common_context_target_surface_set(Evas_GL_Context *gc,
713 Evas_GL_Image *surface)
715 if (surface == gc->shader.surface) return;
717 evas_gl_common_context_flush(gc);
719 gc->shader.surface = surface;
721 #if defined (GLES_VARIETY_S3C6410) || defined (GLES_VARIETY_SGX)
722 # ifndef GL_FRAMEBUFFER
723 # define GL_FRAMEBUFFER GL_FRAMEBUFFER_OES
726 # ifndef GL_FRAMEBUFFER
727 # define GL_FRAMEBUFFER GL_FRAMEBUFFER_EXT
730 if (gc->shader.surface == gc->def_surface)
732 glsym_glBindFramebuffer(GL_FRAMEBUFFER, 0);
733 GLERR(__FUNCTION__, __FILE__, __LINE__, "");
737 glsym_glBindFramebuffer(GL_FRAMEBUFFER, surface->tex->pt->fb);
738 GLERR(__FUNCTION__, __FILE__, __LINE__, "");
740 _evas_gl_common_viewport_set(gc);
743 #define PUSH_VERTEX(x, y, z) \
744 gc->array.vertex[nv++] = x; \
745 gc->array.vertex[nv++] = y; \
746 gc->array.vertex[nv++] = z
747 #define PUSH_COLOR(r, g, b, a) \
748 gc->array.color[nc++] = r; \
749 gc->array.color[nc++] = g; \
750 gc->array.color[nc++] = b; \
751 gc->array.color[nc++] = a
752 #define PUSH_TEXUV(u, v) \
753 gc->array.texuv[nu++] = u; \
754 gc->array.texuv[nu++] = v
755 #define PUSH_TEXUV2(u, v) \
756 gc->array.texuv2[nu2++] = u; \
757 gc->array.texuv2[nu2++] = v
758 #define PUSH_TEXUV3(u, v) \
759 gc->array.texuv3[nu3++] = u; \
760 gc->array.texuv3[nu3++] = v
763 _evas_gl_common_context_array_alloc(Evas_GL_Context *gc)
765 if (gc->array.num <= gc->array.alloc) return;
766 gc->array.alloc += 6 * 1024;
767 if (gc->array.use_vertex)
768 gc->array.vertex = realloc(gc->array.vertex,
769 gc->array.alloc * sizeof(GLshort) * 3);
770 if (gc->array.use_color)
771 gc->array.color = realloc(gc->array.color,
772 gc->array.alloc * sizeof(GLubyte) * 4);
773 if (gc->array.use_texuv)
774 gc->array.texuv = realloc(gc->array.texuv,
775 gc->array.alloc * sizeof(GLfloat) * 2);
776 if (gc->array.use_texuv2)
777 gc->array.texuv2 = realloc(gc->array.texuv2,
778 gc->array.alloc * sizeof(GLfloat) * 2);
779 if (gc->array.use_texuv3)
780 gc->array.texuv3 = realloc(gc->array.texuv3,
781 gc->array.alloc * sizeof(GLfloat) * 2);
785 evas_gl_common_context_line_push(Evas_GL_Context *gc,
786 int x1, int y1, int x2, int y2,
787 int clip, int cx, int cy, int cw, int ch,
788 int r, int g, int b, int a)
790 int pnum, nv, nc, nu, nt, i;
792 GLuint prog = gc->shared->shader.rect.prog;
794 shader_array_flush(gc);
796 if (a < 255) blend = 1;
797 if (gc->dc->render_op == EVAS_RENDER_COPY) blend = 0;
798 gc->shader.cur_tex = 0;
799 gc->shader.cur_prog = prog;
800 gc->shader.blend = blend;
801 gc->shader.render_op = gc->dc->render_op;
802 gc->shader.clip = clip;
809 gc->array.use_vertex = 1;
810 gc->array.use_color = 1;
811 gc->array.use_texuv = 0;
812 gc->array.use_texuv2 = 0;
813 gc->array.use_texuv3 = 0;
815 pnum = gc->array.num;
816 nv = pnum * 3; nc = pnum * 4; nu = pnum * 2; nt = pnum * 4;
818 _evas_gl_common_context_array_alloc(gc);
820 PUSH_VERTEX(x1, y1, 0);
821 PUSH_VERTEX(x2, y2, 0);
823 for (i = 0; i < 2; i++)
825 PUSH_COLOR(r, g, b, a);
828 shader_array_flush(gc);
830 gc->array.use_vertex = 0;
831 gc->array.use_color = 0;
832 gc->array.use_texuv = 0;
833 gc->array.use_texuv2 = 0;
834 gc->array.use_texuv3 = 0;
838 evas_gl_common_context_rectangle_push(Evas_GL_Context *gc,
839 int x, int y, int w, int h,
840 int r, int g, int b, int a)
842 int pnum, nv, nc, nu, nt, i;
844 GLuint prog = gc->shared->shader.rect.prog;
846 if (a < 255) blend = 1;
847 if (gc->dc->render_op == EVAS_RENDER_COPY) blend = 0;
849 if ((gc->shader.cur_tex != 0)
850 || (gc->shader.cur_prog != prog)
851 || (gc->shader.blend != blend)
852 || (gc->shader.render_op != gc->dc->render_op)
853 || (gc->shader.clip != 0)
856 shader_array_flush(gc);
857 gc->shader.cur_tex = 0;
858 gc->shader.cur_prog = prog;
859 gc->shader.blend = blend;
860 gc->shader.render_op = gc->dc->render_op;
865 gc->array.use_vertex = 1;
866 gc->array.use_color = 1;
867 gc->array.use_texuv = 0;
868 gc->array.use_texuv2 = 0;
869 gc->array.use_texuv3 = 0;
871 pnum = gc->array.num;
872 nv = pnum * 3; nc = pnum * 4; nu = pnum * 2; nt = pnum * 4;
874 _evas_gl_common_context_array_alloc(gc);
876 PUSH_VERTEX(x , y , 0);
877 PUSH_VERTEX(x + w, y , 0);
878 PUSH_VERTEX(x , y + h, 0);
880 PUSH_VERTEX(x + w, y , 0);
881 PUSH_VERTEX(x + w, y + h, 0);
882 PUSH_VERTEX(x , y + h, 0);
884 for (i = 0; i < 6; i++)
886 PUSH_COLOR(r, g, b, a);
891 evas_gl_common_context_image_push(Evas_GL_Context *gc,
892 Evas_GL_Texture *tex,
893 double sx, double sy, double sw, double sh,
894 int x, int y, int w, int h,
895 int r, int g, int b, int a,
896 Eina_Bool smooth, Eina_Bool tex_only)
898 int pnum, nv, nc, nu, nu2, nt, i;
899 GLfloat tx1, tx2, ty1, ty2;
901 GLuint prog = gc->shared->shader.img.prog;
903 if (!tex->alpha) blend = 0;
904 if (a < 255) blend = 1;
908 if ((a == 255) && (r == 255) && (g == 255) && (b == 255))
909 prog = gc->shared->shader.tex_nomul.prog;
911 prog = gc->shared->shader.tex.prog;
915 if (tex->gc->shared->info.bgra)
917 if ((a == 255) && (r == 255) && (g == 255) && (b == 255))
918 prog = gc->shared->shader.img_bgra_nomul.prog;
920 prog = gc->shared->shader.img_bgra.prog;
924 if ((a == 255) && (r == 255) && (g == 255) && (b == 255))
925 prog = gc->shared->shader.img_nomul.prog;
927 prog = gc->shared->shader.img.prog;
931 if ((gc->shader.cur_tex != tex->pt->texture)
932 || (gc->shader.cur_prog != prog)
933 || (gc->shader.smooth != smooth)
934 || (gc->shader.blend != blend)
935 || (gc->shader.render_op != gc->dc->render_op)
936 || (gc->shader.clip != 0)
939 shader_array_flush(gc);
940 gc->shader.cur_tex = tex->pt->texture;
941 gc->shader.cur_prog = prog;
942 gc->shader.smooth = smooth;
943 gc->shader.blend = blend;
944 gc->shader.render_op = gc->dc->render_op;
947 if ((tex->im) && (tex->im->native.data))
949 if (gc->array.im != tex->im)
951 shader_array_flush(gc);
952 gc->array.im = tex->im;
957 gc->array.use_vertex = 1;
958 // if nomul... dont need this
959 gc->array.use_color = 1;
960 gc->array.use_texuv = 1;
961 gc->array.use_texuv2 = 0;
962 gc->array.use_texuv3 = 0;
964 pnum = gc->array.num;
965 nv = pnum * 3; nc = pnum * 4; nu = pnum * 2; nu2 = pnum * 2;
968 _evas_gl_common_context_array_alloc(gc);
970 if ((tex->im) && (tex->im->native.data) && (!tex->im->native.yinvert))
972 tx1 = ((double)(tex->x) + sx) / (double)tex->pt->w;
973 ty1 = ((double)(tex->y) + sy + sh) / (double)tex->pt->h;
974 tx2 = ((double)(tex->x) + sx + sw) / (double)tex->pt->w;
975 ty2 = ((double)(tex->y) + sy) / (double)tex->pt->h;
979 tx1 = ((double)(tex->x) + sx) / (double)tex->pt->w;
980 ty1 = ((double)(tex->y) + sy) / (double)tex->pt->h;
981 tx2 = ((double)(tex->x) + sx + sw) / (double)tex->pt->w;
982 ty2 = ((double)(tex->y) + sy + sh) / (double)tex->pt->h;
985 PUSH_VERTEX(x , y , 0);
986 PUSH_VERTEX(x + w, y , 0);
987 PUSH_VERTEX(x , y + h, 0);
989 PUSH_TEXUV(tx1, ty1);
990 PUSH_TEXUV(tx2, ty1);
991 PUSH_TEXUV(tx1, ty2);
993 PUSH_VERTEX(x + w, y , 0);
994 PUSH_VERTEX(x + w, y + h, 0);
995 PUSH_VERTEX(x , y + h, 0);
997 PUSH_TEXUV(tx2, ty1);
998 PUSH_TEXUV(tx2, ty2);
999 PUSH_TEXUV(tx1, ty2);
1001 // if nomul... dont need this
1002 for (i = 0; i < 6; i++)
1004 PUSH_COLOR(r, g, b, a);
1009 evas_gl_common_context_font_push(Evas_GL_Context *gc,
1010 Evas_GL_Texture *tex,
1011 double sx, double sy, double sw, double sh,
1012 int x, int y, int w, int h,
1013 int r, int g, int b, int a)
1015 int pnum, nv, nc, nu, nt, i;
1016 GLfloat tx1, tx2, ty1, ty2;
1018 if ((gc->shader.cur_tex != tex->pt->texture)
1019 || (gc->shader.cur_prog != gc->shared->shader.font.prog)
1020 || (gc->shader.smooth != 0)
1021 || (gc->shader.blend != 1)
1022 || (gc->shader.render_op != gc->dc->render_op)
1023 || (gc->shader.clip != 0)
1026 shader_array_flush(gc);
1027 gc->shader.cur_tex = tex->pt->texture;
1028 gc->shader.cur_prog = gc->shared->shader.font.prog;
1029 gc->shader.smooth = 0;
1030 gc->shader.blend = 1;
1031 gc->shader.render_op = gc->dc->render_op;
1032 gc->shader.clip = 0;
1035 gc->array.use_vertex = 1;
1036 gc->array.use_color = 1;
1037 gc->array.use_texuv = 1;
1038 gc->array.use_texuv2 = 0;
1039 gc->array.use_texuv3 = 0;
1041 pnum = gc->array.num;
1042 nv = pnum * 3; nc = pnum * 4; nu = pnum * 2; nt = pnum * 4;
1044 _evas_gl_common_context_array_alloc(gc);
1055 tx1 = ((double)(tex->x) + sx) / (double)tex->pt->w;
1056 ty1 = ((double)(tex->y) + sy) / (double)tex->pt->h;
1057 tx2 = ((double)(tex->x) + sx + sw) / (double)tex->pt->w;
1058 ty2 = ((double)(tex->y) + sy + sh) / (double)tex->pt->h;
1061 PUSH_VERTEX(x , y , 0);
1062 PUSH_VERTEX(x + w, y , 0);
1063 PUSH_VERTEX(x , y + h, 0);
1065 PUSH_TEXUV(tx1, ty1);
1066 PUSH_TEXUV(tx2, ty1);
1067 PUSH_TEXUV(tx1, ty2);
1069 PUSH_VERTEX(x + w, y , 0);
1070 PUSH_VERTEX(x + w, y + h, 0);
1071 PUSH_VERTEX(x , y + h, 0);
1073 PUSH_TEXUV(tx2, ty1);
1074 PUSH_TEXUV(tx2, ty2);
1075 PUSH_TEXUV(tx1, ty2);
1077 for (i = 0; i < 6; i++)
1079 PUSH_COLOR(r, g, b, a);
1084 evas_gl_common_context_yuv_push(Evas_GL_Context *gc,
1085 Evas_GL_Texture *tex,
1086 double sx, double sy, double sw, double sh,
1087 int x, int y, int w, int h,
1088 int r, int g, int b, int a,
1091 int pnum, nv, nc, nu, nu2, nu3, nt, i;
1092 GLfloat tx1, tx2, ty1, ty2, t2x1, t2x2, t2y1, t2y2;
1093 Eina_Bool blend = 0;
1094 GLuint prog = gc->shared->shader.yuv.prog;
1096 if (a < 255) blend = 1;
1098 if ((a == 255) && (r == 255) && (g == 255) && (b == 255))
1099 prog = gc->shared->shader.yuv_nomul.prog;
1101 prog = gc->shared->shader.yuv.prog;
1103 if ((gc->shader.cur_tex != tex->pt->texture)
1104 || (gc->shader.cur_prog != prog)
1105 || (gc->shader.smooth != smooth)
1106 || (gc->shader.blend != blend)
1107 || (gc->shader.render_op != gc->dc->render_op)
1108 || (gc->shader.clip != 0)
1111 shader_array_flush(gc);
1112 gc->shader.cur_tex = tex->pt->texture;
1113 gc->shader.cur_texu = tex->ptu->texture;
1114 gc->shader.cur_texv = tex->ptv->texture;
1115 gc->shader.cur_prog = prog;
1116 gc->shader.smooth = smooth;
1117 gc->shader.blend = blend;
1118 gc->shader.render_op = gc->dc->render_op;
1119 gc->shader.clip = 0;
1122 gc->array.use_vertex = 1;
1123 gc->array.use_color = 1;
1124 gc->array.use_texuv = 1;
1125 gc->array.use_texuv2 = 1;
1126 gc->array.use_texuv3 = 1;
1128 pnum = gc->array.num;
1129 nv = pnum * 3; nc = pnum * 4; nu = pnum * 2;
1130 nu2 = pnum * 2; nu3 = pnum * 2; nt = pnum * 4;
1132 _evas_gl_common_context_array_alloc(gc);
1134 tx1 = (sx) / (double)tex->pt->w;
1135 ty1 = (sy) / (double)tex->pt->h;
1136 tx2 = (sx + sw) / (double)tex->pt->w;
1137 ty2 = (sy + sh) / (double)tex->pt->h;
1139 t2x1 = ((sx) / 2) / (double)tex->ptu->w;
1140 t2y1 = ((sy) / 2) / (double)tex->ptu->h;
1141 t2x2 = ((sx + sw) / 2) / (double)tex->ptu->w;
1142 t2y2 = ((sy + sh) / 2) / (double)tex->ptu->h;
1144 PUSH_VERTEX(x , y , 0);
1145 PUSH_VERTEX(x + w, y , 0);
1146 PUSH_VERTEX(x , y + h, 0);
1148 PUSH_TEXUV(tx1, ty1);
1149 PUSH_TEXUV(tx2, ty1);
1150 PUSH_TEXUV(tx1, ty2);
1152 PUSH_TEXUV2(t2x1, t2y1);
1153 PUSH_TEXUV2(t2x2, t2y1);
1154 PUSH_TEXUV2(t2x1, t2y2);
1156 PUSH_TEXUV3(t2x1, t2y1);
1157 PUSH_TEXUV3(t2x2, t2y1);
1158 PUSH_TEXUV3(t2x1, t2y2);
1160 PUSH_VERTEX(x + w, y , 0);
1161 PUSH_VERTEX(x + w, y + h, 0);
1162 PUSH_VERTEX(x , y + h, 0);
1164 PUSH_TEXUV(tx2, ty1);
1165 PUSH_TEXUV(tx2, ty2);
1166 PUSH_TEXUV(tx1, ty2);
1168 PUSH_TEXUV2(t2x2, t2y1);
1169 PUSH_TEXUV2(t2x2, t2y2);
1170 PUSH_TEXUV2(t2x1, t2y2);
1172 PUSH_TEXUV3(t2x2, t2y1);
1173 PUSH_TEXUV3(t2x2, t2y2);
1174 PUSH_TEXUV3(t2x1, t2y2);
1176 for (i = 0; i < 6; i++)
1178 PUSH_COLOR(r, g, b, a);
1183 evas_gl_common_context_image_map4_push(Evas_GL_Context *gc,
1184 Evas_GL_Texture *tex,
1186 int clip, int cx, int cy, int cw, int ch,
1187 int r, int g, int b, int a,
1188 Eina_Bool smooth, Eina_Bool tex_only)
1190 int pnum, nv, nc, nu, nu2, nt, i;
1191 const int points[6] = { 0, 1, 2, 0, 2, 3 };
1192 GLfloat tx[4], ty[4];
1193 Eina_Bool blend = 1;
1196 GLuint prog = gc->shared->shader.img.prog;
1198 if (!tex->alpha) blend = 0;
1199 if (a < 255) blend = 1;
1200 if ((A_VAL(&(p[0].col)) < 0xff) || (A_VAL(&(p[1].col)) < 0xff) ||
1201 (A_VAL(&(p[2].col)) < 0xff) || (A_VAL(&(p[3].col)) < 0xff))
1206 if ((a == 255) && (r == 255) && (g == 255) && (b == 255))
1208 if ((p[0].col == 0xffffffff) && (p[1].col == 0xffffffff) &&
1209 (p[2].col == 0xffffffff) && (p[3].col == 0xffffffff))
1210 prog = gc->shared->shader.tex_nomul.prog;
1212 prog = gc->shared->shader.tex.prog;
1215 prog = gc->shared->shader.tex.prog;
1219 if (tex->gc->shared->info.bgra)
1221 if ((a == 255) && (r == 255) && (g == 255) && (b == 255))
1223 if ((p[0].col == 0xffffffff) && (p[1].col == 0xffffffff) &&
1224 (p[2].col == 0xffffffff) && (p[3].col == 0xffffffff))
1225 prog = gc->shared->shader.img_bgra_nomul.prog;
1227 prog = gc->shared->shader.img_bgra.prog;
1230 prog = gc->shared->shader.img_bgra.prog;
1234 if ((a == 255) && (r == 255) && (g == 255) && (b == 255))
1236 if ((p[0].col == 0xffffffff) && (p[1].col == 0xffffffff) &&
1237 (p[2].col == 0xffffffff) && (p[3].col == 0xffffffff))
1238 prog = gc->shared->shader.img_nomul.prog;
1240 prog = gc->shared->shader.img.prog;
1243 prog = gc->shared->shader.img.prog;
1247 if ((gc->shader.cur_tex != tex->pt->texture)
1248 || (gc->shader.cur_prog != prog)
1249 || (gc->shader.smooth != smooth)
1250 || (gc->shader.blend != blend)
1251 || (gc->shader.render_op != gc->dc->render_op)
1252 || (gc->shader.clip != clip)
1253 || (gc->shader.cx != cx)
1254 || (gc->shader.cy != cy)
1255 || (gc->shader.cw != cw)
1256 || (gc->shader.ch != ch)
1259 shader_array_flush(gc);
1260 gc->shader.cur_tex = tex->pt->texture;
1261 gc->shader.cur_prog = prog;
1262 gc->shader.smooth = smooth;
1263 gc->shader.blend = blend;
1264 gc->shader.render_op = gc->dc->render_op;
1265 gc->shader.clip = clip;
1271 if ((tex->im) && (tex->im->native.data))
1273 if (gc->array.im != tex->im)
1275 shader_array_flush(gc);
1276 gc->array.im = tex->im;
1280 gc->array.use_vertex = 1;
1281 gc->array.use_color = 1;
1282 gc->array.use_texuv = 1;
1283 gc->array.use_texuv2 = 1;
1284 gc->array.use_texuv3 = 0;
1286 pnum = gc->array.num;
1287 nv = pnum * 3; nc = pnum * 4; nu = pnum * 2; nu2 = pnum * 2;
1290 _evas_gl_common_context_array_alloc(gc);
1292 for (i = 0; i < 4; i++)
1294 tx[i] = ((double)(tex->x) + (((double)p[i].u) / FP1)) /
1296 ty[i] = ((double)(tex->y) + (((double)p[i].v) / FP1)) /
1299 if ((tex->im) && (tex->im->native.data) && (!tex->im->native.yinvert))
1301 // FIXME: handle yinvert
1304 cmul = ARGB_JOIN(a, r, g, b);
1305 for (i = 0; i < 6; i++)
1307 DATA32 cl = MUL4_SYM(cmul, p[points[i]].col);
1308 PUSH_VERTEX((p[points[i]].x >> FP),
1309 (p[points[i]].y >> FP),
1311 PUSH_TEXUV(tx[points[i]],
1314 PUSH_COLOR(R_VAL(&cl),
1322 evas_gl_common_context_flush(Evas_GL_Context *gc)
1324 shader_array_flush(gc);
1325 // fprintf(stderr, "------------FRAME: done\n");
1329 shader_array_flush(Evas_GL_Context *gc)
1331 if (gc->array.num <= 0) return;
1333 // fprintf(stderr, " flush array %i\n", gc->array.num);
1334 GLERR(__FUNCTION__, __FILE__, __LINE__, "<flush err>");
1335 if (gc->shader.cur_prog != gc->shader.current.cur_prog)
1337 glUseProgram(gc->shader.cur_prog);
1338 GLERR(__FUNCTION__, __FILE__, __LINE__, "");
1341 if (gc->shader.cur_tex != gc->shader.current.cur_tex)
1344 if (gc->shader.cur_tex)
1346 glEnable(GL_TEXTURE_2D);
1347 GLERR(__FUNCTION__, __FILE__, __LINE__, "");
1351 glDisable(GL_TEXTURE_2D);
1352 GLERR(__FUNCTION__, __FILE__, __LINE__, "");
1355 glActiveTexture(GL_TEXTURE0);
1356 GLERR(__FUNCTION__, __FILE__, __LINE__, "");
1357 glBindTexture(GL_TEXTURE_2D, gc->shader.cur_tex);
1358 GLERR(__FUNCTION__, __FILE__, __LINE__, "");
1362 if (!gc->array.im->native.loose)
1364 if (gc->array.im->native.func.bind)
1365 gc->array.im->native.func.bind(gc->array.im->native.func.data,
1369 if (gc->shader.render_op != gc->shader.current.render_op)
1371 switch (gc->shader.render_op)
1373 case EVAS_RENDER_BLEND: /**< default op: d = d*(1-sa) + s */
1374 glBlendFunc(GL_ONE, GL_ONE_MINUS_SRC_ALPHA);
1375 GLERR(__FUNCTION__, __FILE__, __LINE__, "");
1377 case EVAS_RENDER_COPY: /**< d = s */
1378 gc->shader.blend = 0;
1379 glBlendFunc(GL_ONE, GL_ONE);
1380 GLERR(__FUNCTION__, __FILE__, __LINE__, "");
1382 // FIXME: fix blend funcs below!
1383 case EVAS_RENDER_BLEND_REL: /**< d = d*(1 - sa) + s*da */
1384 case EVAS_RENDER_COPY_REL: /**< d = s*da */
1385 case EVAS_RENDER_ADD: /**< d = d + s */
1386 case EVAS_RENDER_ADD_REL: /**< d = d + s*da */
1387 case EVAS_RENDER_SUB: /**< d = d - s */
1388 case EVAS_RENDER_SUB_REL: /**< d = d - s*da */
1389 case EVAS_RENDER_TINT: /**< d = d*s + d*(1 - sa) + s*(1 - da) */
1390 case EVAS_RENDER_TINT_REL: /**< d = d*(1 - sa + s) */
1391 case EVAS_RENDER_MASK: /**< d = d*sa */
1392 case EVAS_RENDER_MUL: /**< d = d*s */
1394 glBlendFunc(GL_ONE, GL_ONE_MINUS_SRC_ALPHA);
1395 GLERR(__FUNCTION__, __FILE__, __LINE__, "");
1399 if (gc->shader.blend != gc->shader.current.blend)
1401 if (gc->shader.blend)
1404 GLERR(__FUNCTION__, __FILE__, __LINE__, "");
1408 glDisable(GL_BLEND);
1409 GLERR(__FUNCTION__, __FILE__, __LINE__, "");
1412 if (gc->shader.smooth != gc->shader.current.smooth)
1414 if (gc->shader.smooth)
1416 #ifdef GL_TEXTURE_MAX_ANISOTROPY_EXT
1417 if (shared->info.anisotropic > 0.0)
1419 glTexParameterf(GL_TEXTURE_2D, GL_TEXTURE_MAX_ANISOTROPY_EXT, shared->info.anisotropic);
1420 GLERR(__FUNCTION__, __FILE__, __LINE__, "");
1423 glTexParameteri(GL_TEXTURE_2D, GL_TEXTURE_MAG_FILTER, GL_LINEAR);
1424 GLERR(__FUNCTION__, __FILE__, __LINE__, "");
1425 glTexParameteri(GL_TEXTURE_2D, GL_TEXTURE_MIN_FILTER, GL_LINEAR);
1426 GLERR(__FUNCTION__, __FILE__, __LINE__, "");
1427 glTexParameteri(GL_TEXTURE_2D, GL_TEXTURE_WRAP_S, GL_CLAMP_TO_EDGE);
1428 GLERR(__FUNCTION__, __FILE__, __LINE__, "");
1429 glTexParameteri(GL_TEXTURE_2D, GL_TEXTURE_WRAP_T, GL_CLAMP_TO_EDGE);
1430 GLERR(__FUNCTION__, __FILE__, __LINE__, "");
1434 #ifdef GL_TEXTURE_MAX_ANISOTROPY_EXT
1435 if (shared->info.anisotropic > 0.0)
1437 glTexParameterf(GL_TEXTURE_2D, GL_TEXTURE_MAX_ANISOTROPY_EXT, 1.0);
1438 GLERR(__FUNCTION__, __FILE__, __LINE__, "");
1441 glTexParameteri(GL_TEXTURE_2D, GL_TEXTURE_MAG_FILTER, GL_NEAREST);
1442 GLERR(__FUNCTION__, __FILE__, __LINE__, "");
1443 glTexParameteri(GL_TEXTURE_2D, GL_TEXTURE_MIN_FILTER, GL_NEAREST);
1444 GLERR(__FUNCTION__, __FILE__, __LINE__, "");
1445 glTexParameteri(GL_TEXTURE_2D, GL_TEXTURE_WRAP_S, GL_CLAMP_TO_EDGE);
1446 GLERR(__FUNCTION__, __FILE__, __LINE__, "");
1447 glTexParameteri(GL_TEXTURE_2D, GL_TEXTURE_WRAP_T, GL_CLAMP_TO_EDGE);
1448 GLERR(__FUNCTION__, __FILE__, __LINE__, "");
1451 /* hmmm this breaks things. must find out why!
1452 if (gc->shader.clip != gc->shader.current.clip)
1454 if (gc->shader.clip)
1455 glEnable(GL_SCISSOR_TEST);
1458 glDisable(GL_SCISSOR_TEST);
1459 // glScissor(0, 0, 0, 0);
1462 if (gc->shader.clip)
1464 if ((gc->shader.cx != gc->shader.current.cx) ||
1465 (gc->shader.cx != gc->shader.current.cx) ||
1466 (gc->shader.cx != gc->shader.current.cx) ||
1467 (gc->shader.cx != gc->shader.current.cx))
1469 glScissor(gc->shader.cx,
1470 gc->h - gc->shader.cy - gc->shader.ch,
1475 // gc->h - gc->clip.y - gc->clip.h,
1481 glVertexAttribPointer(SHAD_VERTEX, 3, GL_SHORT, GL_FALSE, 0, gc->array.vertex);
1482 GLERR(__FUNCTION__, __FILE__, __LINE__, "");
1483 glVertexAttribPointer(SHAD_COLOR, 4, GL_UNSIGNED_BYTE, GL_TRUE, 0, gc->array.color);
1484 GLERR(__FUNCTION__, __FILE__, __LINE__, "");
1485 if (gc->array.use_texuv)
1487 glEnableVertexAttribArray(SHAD_TEXUV);
1488 GLERR(__FUNCTION__, __FILE__, __LINE__, "");
1489 glVertexAttribPointer(SHAD_TEXUV, 2, GL_FLOAT, GL_FALSE, 0, gc->array.texuv);
1490 GLERR(__FUNCTION__, __FILE__, __LINE__, "");
1494 glDisableVertexAttribArray(SHAD_TEXUV);
1495 GLERR(__FUNCTION__, __FILE__, __LINE__, "");
1500 glDisableVertexAttribArray(SHAD_TEXUV);
1501 GLERR(__FUNCTION__, __FILE__, __LINE__, "");
1502 glDisableVertexAttribArray(SHAD_TEXUV2);
1503 GLERR(__FUNCTION__, __FILE__, __LINE__, "");
1504 glDisableVertexAttribArray(SHAD_TEXUV3);
1505 GLERR(__FUNCTION__, __FILE__, __LINE__, "");
1506 glDrawArrays(GL_LINES, 0, gc->array.num);
1507 GLERR(__FUNCTION__, __FILE__, __LINE__, "");
1511 if ((gc->array.use_texuv2) && (gc->array.use_texuv3))
1513 glEnableVertexAttribArray(SHAD_TEXUV2);
1514 GLERR(__FUNCTION__, __FILE__, __LINE__, "");
1515 glEnableVertexAttribArray(SHAD_TEXUV3);
1516 GLERR(__FUNCTION__, __FILE__, __LINE__, "");
1517 glVertexAttribPointer(SHAD_TEXUV2, 2, GL_FLOAT, GL_FALSE, 0, gc->array.texuv2);
1518 GLERR(__FUNCTION__, __FILE__, __LINE__, "");
1519 glVertexAttribPointer(SHAD_TEXUV3, 2, GL_FLOAT, GL_FALSE, 0, gc->array.texuv3);
1520 GLERR(__FUNCTION__, __FILE__, __LINE__, "");
1521 glActiveTexture(GL_TEXTURE1);
1522 GLERR(__FUNCTION__, __FILE__, __LINE__, "");
1523 glBindTexture(GL_TEXTURE_2D, gc->shader.cur_texu);
1524 GLERR(__FUNCTION__, __FILE__, __LINE__, "");
1525 glActiveTexture(GL_TEXTURE2);
1526 GLERR(__FUNCTION__, __FILE__, __LINE__, "");
1527 glBindTexture(GL_TEXTURE_2D, gc->shader.cur_texv);
1528 GLERR(__FUNCTION__, __FILE__, __LINE__, "");
1529 glActiveTexture(GL_TEXTURE0);
1530 GLERR(__FUNCTION__, __FILE__, __LINE__, "");
1532 else if (gc->array.use_texuv2)
1534 glEnableVertexAttribArray(SHAD_TEXUV2);
1535 GLERR(__FUNCTION__, __FILE__, __LINE__, "");
1536 glVertexAttribPointer(SHAD_TEXUV2, 2, GL_FLOAT, GL_FALSE, 0, gc->array.texuv2);
1537 GLERR(__FUNCTION__, __FILE__, __LINE__, "");
1541 glDisableVertexAttribArray(SHAD_TEXUV2);
1542 GLERR(__FUNCTION__, __FILE__, __LINE__, "");
1543 glDisableVertexAttribArray(SHAD_TEXUV3);
1544 GLERR(__FUNCTION__, __FILE__, __LINE__, "");
1547 glDrawArrays(GL_TRIANGLES, 0, gc->array.num);
1548 GLERR(__FUNCTION__, __FILE__, __LINE__, "");
1552 if (!gc->array.im->native.loose)
1554 if (gc->array.im->native.func.unbind)
1555 gc->array.im->native.func.unbind(gc->array.im->native.func.data,
1558 gc->array.im = NULL;
1561 gc->shader.current.cur_prog = gc->shader.cur_prog;
1562 gc->shader.current.cur_tex = gc->shader.cur_tex;
1563 gc->shader.current.blend = gc->shader.blend;
1564 gc->shader.current.smooth = gc->shader.smooth;
1565 gc->shader.current.render_op = gc->shader.render_op;
1566 gc->shader.current.clip = gc->shader.clip;
1567 gc->shader.current.cx = gc->shader.cx;
1568 gc->shader.current.cy = gc->shader.cy;
1569 gc->shader.current.cw = gc->shader.cw;
1570 gc->shader.current.ch = gc->shader.ch;
1572 if (gc->array.vertex) free(gc->array.vertex);
1573 if (gc->array.color) free(gc->array.color);
1574 if (gc->array.texuv) free(gc->array.texuv);
1575 if (gc->array.texuv2) free(gc->array.texuv2);
1576 if (gc->array.texuv3) free(gc->array.texuv3);
1578 gc->array.vertex = NULL;
1579 gc->array.color = NULL;
1580 gc->array.texuv = NULL;
1581 gc->array.texuv2 = NULL;
1582 gc->array.texuv3 = NULL;
1585 gc->array.alloc = 0;