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 #define FINDSYM(dst, sym) if (!dst) dst = dlsym(RTLD_DEFAULT, sym)
23 #define FALLBAK(dst) if (!dst) dst = (void *)sym_missing;
25 FINDSYM(glsym_glGenFramebuffers, "glGenFramebuffers");
26 FINDSYM(glsym_glGenFramebuffers, "glGenFramebuffersEXT");
27 FINDSYM(glsym_glGenFramebuffers, "glGenFramebuffersARB");
28 FALLBAK(glsym_glGenFramebuffers);
30 FINDSYM(glsym_glBindFramebuffer, "glBindFramebuffer");
31 FINDSYM(glsym_glBindFramebuffer, "glBindFramebufferEXT");
32 FINDSYM(glsym_glBindFramebuffer, "glBindFramebufferARB");
33 FALLBAK(glsym_glBindFramebuffer);
35 FINDSYM(glsym_glFramebufferTexture2D, "glFramebufferTexture2D");
36 FINDSYM(glsym_glFramebufferTexture2D, "glFramebufferTexture2DEXT");
37 FINDSYM(glsym_glFramebufferTexture2D, "glFramebufferTexture2DARB");
38 FALLBAK(glsym_glFramebufferTexture2D);
40 FINDSYM(glsym_glDeleteFramebuffers, "glDeleteFramebuffers");
41 FINDSYM(glsym_glDeleteFramebuffers, "glDeleteFramebuffersEXT");
42 FINDSYM(glsym_glDeleteFramebuffers, "glDeleteFramebuffersARB");
43 FALLBAK(glsym_glDeleteFramebuffers);
46 static void shader_array_flush(Evas_GL_Context *gc);
48 static Evas_GL_Context *_evas_gl_common_context = NULL;
49 static Evas_GL_Shared *shared = NULL;
52 glerr(const char *file, const char *func, int line, const char *op)
54 GLenum err = glGetError();
55 if (err != GL_NO_ERROR)
57 fprintf(stderr, "GLERR: %s:%i %s(), %s: ", file, line, func, op);
61 fprintf(stderr, "GL_INVALID_ENUM\n");
63 case GL_INVALID_VALUE:
64 fprintf(stderr, "GL_INVALID_VALUE\n");
66 case GL_INVALID_OPERATION:
67 fprintf(stderr, "GL_INVALID_OPERATION\n");
69 case GL_OUT_OF_MEMORY:
70 fprintf(stderr, "GL_OUT_OF_MEMORY\n");
73 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;
86 matrix_ortho(GLfloat *m,
89 GLfloat near, GLfloat far)
92 m[1] = m[2] = m[3] = 0.0;
99 m[10] = -(2.0 / (far - near));
102 m[12] = -((r + l)/(r - l));
103 m[13] = -((t + b)/(t - b));
104 m[14] = -((near + far)/(far - near));
109 _evas_gl_common_viewport_set(Evas_GL_Context *gc)
112 int w = 1, h = 1, m = 1;
114 if ((gc->shader.surface == gc->def_surface) ||
115 (!gc->shader.surface))
122 w = gc->shader.surface->w;
123 h = gc->shader.surface->h;
127 if ((!gc->change.size) ||
128 ((gc->shared->w == w) && (gc->shared->h == h)))
135 glViewport(0, 0, w, h);
138 if (m == 1) matrix_ortho(proj, 0, w, 0, h, -1.0, 1.0);
139 else matrix_ortho(proj, 0, w, h, 0, -1.0, 1.0);
141 glUseProgram(gc->shared->shader.rect.prog);
142 glUniformMatrix4fv(glGetUniformLocation(gc->shared->shader.rect.prog, "mvp"), 1,
144 glUseProgram(gc->shared->shader.img.prog);
145 glUniformMatrix4fv(glGetUniformLocation(gc->shared->shader.img.prog, "mvp"), 1,
147 glUseProgram(gc->shared->shader.font.prog);
148 glUniformMatrix4fv(glGetUniformLocation(gc->shared->shader.font.prog, "mvp"), 1,
150 glUseProgram(gc->shared->shader.yuv.prog);
151 glUniformMatrix4fv(glGetUniformLocation(gc->shared->shader.yuv.prog, "mvp"), 1,
153 glUseProgram(gc->shared->shader.tex.prog);
154 glUniformMatrix4fv(glGetUniformLocation(gc->shared->shader.tex.prog, "mvp"), 1,
156 glUseProgram(gc->shader.cur_prog);
160 evas_gl_common_context_new(void)
166 if (_evas_gl_common_context)
168 _evas_gl_common_context->references++;
169 return _evas_gl_common_context;
172 gc = calloc(1, sizeof(Evas_GL_Context));
173 if (!gc) return NULL;
177 _evas_gl_common_context = gc;
182 unsigned int pixel = 0xffffffff;
185 shared = calloc(1, sizeof(Evas_GL_Shared));
186 ext = glGetString(GL_EXTENSIONS);
189 fprintf(stderr, "EXT:\n%s\n", ext);
190 if ((strstr((char*) ext, "GL_ARB_texture_non_power_of_two")) ||
191 (strstr((char*) ext, "OES_texture_npot")) ||
192 (strstr((char*) ext, "GL_IMG_texture_npot")))
193 shared->info.tex_npo2 = 1;
194 if ((strstr((char*) ext, "GL_NV_texture_rectangle")) ||
195 (strstr((char*) ext, "GL_EXT_texture_rectangle")) ||
196 (strstr((char*) ext, "GL_ARB_texture_rectangle"))
198 shared->info.tex_rect = 1;
200 glGetIntegerv(GL_MAX_TEXTURE_IMAGE_UNITS,
201 &(shared->info.max_texture_units));
202 glGetIntegerv(GL_MAX_TEXTURE_SIZE,
203 &(shared->info.max_texture_size));
205 fprintf(stderr, "max tex size %ix%i\n"
207 "non-power-2 tex %i\n"
210 shared->info.max_texture_size, shared->info.max_texture_size,
211 shared->info.max_texture_units,
212 (int)shared->info.tex_npo2,
213 (int)shared->info.tex_rect
216 glDisable(GL_DEPTH_TEST);
219 glBlendFunc(GL_ONE, GL_ONE_MINUS_SRC_ALPHA);
221 // glBlendFunc(GL_SRC_ALPHA, GL_ONE_MINUS_SRC_ALPHA); // dest alpha
222 // glBlendFunc(GL_SRC_ALPHA, GL_ONE); // ???
223 glDepthMask(GL_FALSE);
225 glTexParameteri(GL_TEXTURE_2D, GL_TEXTURE_MAG_FILTER, GL_NEAREST);
226 glTexParameteri(GL_TEXTURE_2D, GL_TEXTURE_MIN_FILTER, GL_NEAREST);
227 glTexParameteri(GL_TEXTURE_2D, GL_TEXTURE_WRAP_S, GL_CLAMP_TO_EDGE);
228 glTexParameteri(GL_TEXTURE_2D, GL_TEXTURE_WRAP_T, GL_CLAMP_TO_EDGE);
229 #ifdef GL_TEXTURE_MAX_ANISOTROPY_EXT
230 glTexParameteri(GL_TEXTURE_2D, GL_TEXTURE_MAX_ANISOTROPY_EXT, 16);
233 glEnableVertexAttribArray(SHAD_VERTEX);
234 glEnableVertexAttribArray(SHAD_COLOR);
236 evas_gl_common_shader_program_init(&(shared->shader.rect),
237 &(shader_rect_vert_src),
238 &(shader_rect_frag_src),
240 evas_gl_common_shader_program_init(&(shared->shader.img),
241 &(shader_img_vert_src),
242 &(shader_img_frag_src),
244 evas_gl_common_shader_program_init(&(shared->shader.font),
245 &(shader_font_vert_src),
246 &(shader_font_frag_src),
248 evas_gl_common_shader_program_init(&(shared->shader.yuv),
249 &(shader_yuv_vert_src),
250 &(shader_yuv_frag_src),
252 evas_gl_common_shader_program_init(&(shared->shader.tex),
253 &(shader_tex_vert_src),
254 &(shader_tex_frag_src),
256 glUseProgram(shared->shader.yuv.prog);
257 glUniform1i(glGetUniformLocation(shared->shader.yuv.prog, "tex"), 0);
258 glUniform1i(glGetUniformLocation(shared->shader.yuv.prog, "texu"), 1);
259 glUniform1i(glGetUniformLocation(shared->shader.yuv.prog, "texv"), 2);
260 glUseProgram(gc->shader.cur_prog);
262 // uniform sampler2D tex[8];
266 // GLint loc = glGetUniformLocation(prog, "tex");
267 // glUniform1iv(loc, 8, texes);
270 gc->shared->references++;
271 _evas_gl_common_viewport_set(gc);
273 gc->def_surface = evas_gl_common_image_surface_new(gc, 1, 1, 1);
279 evas_gl_common_context_free(Evas_GL_Context *gc)
284 if (gc->references > 0) return;
285 gc->shared->references--;
287 evas_gl_common_image_free(gc->def_surface);
289 if (gc->shared->references == 0)
291 while (gc->shared->images)
293 evas_gl_common_image_free(gc->shared->images->data);
295 while (gc->shared->tex.whole)
297 evas_gl_common_texture_free(gc->shared->tex.whole->data);
299 for (i = 0; i < 33; i++)
301 for (j = 0; j < 3; j++)
303 while (gc->shared->tex.atlas[i][j])
304 evas_gl_common_texture_free
305 ((Evas_GL_Texture *)gc->shared->tex.atlas[i][j]);
313 if (gc->array.vertex) free(gc->array.vertex);
314 if (gc->array.color) free(gc->array.color);
315 if (gc->array.texuv) free(gc->array.texuv);
316 if (gc->array.texuv2) free(gc->array.texuv2);
317 if (gc->array.texuv3) free(gc->array.texuv3);
319 if (gc == _evas_gl_common_context) _evas_gl_common_context = NULL;
324 evas_gl_common_context_use(Evas_GL_Context *gc)
326 // if (_evas_gl_common_context == gc) return;
327 _evas_gl_common_context = gc;
328 _evas_gl_common_viewport_set(gc);
332 evas_gl_common_context_resize(Evas_GL_Context *gc, int w, int h)
334 if ((gc->w == w) && (gc->h == h)) return;
338 if (_evas_gl_common_context == gc) _evas_gl_common_viewport_set(gc);
342 evas_gl_common_context_target_surface_set(Evas_GL_Context *gc,
343 Evas_GL_Image *surface)
345 if (surface == gc->shader.surface) return;
347 evas_gl_common_context_flush(gc);
349 gc->shader.surface = surface;
351 #if defined (GLES_VARIETY_S3C6410) || defined (GLES_VARIETY_SGX)
352 # ifndef GL_FRAMEBUFFER
353 # define GL_FRAMEBUFFER GL_FRAMEBUFFER_OES
356 # ifndef GL_FRAMEBUFFER
357 # define GL_FRAMEBUFFER GL_FRAMEBUFFER_EXT
360 if (gc->shader.surface == gc->def_surface)
361 glsym_glBindFramebuffer(GL_FRAMEBUFFER, 0);
363 glsym_glBindFramebuffer(GL_FRAMEBUFFER, surface->tex->pt->fb);
364 _evas_gl_common_viewport_set(gc);
367 #define PUSH_VERTEX(x, y, z) \
368 gc->array.vertex[nv++] = x; \
369 gc->array.vertex[nv++] = y; \
370 gc->array.vertex[nv++] = z
371 #define PUSH_COLOR(r, g, b, a) \
372 gc->array.color[nc++] = r; \
373 gc->array.color[nc++] = g; \
374 gc->array.color[nc++] = b; \
375 gc->array.color[nc++] = a
376 #define PUSH_TEXUV(u, v) \
377 gc->array.texuv[nu++] = u; \
378 gc->array.texuv[nu++] = v
379 #define PUSH_TEXUV2(u, v) \
380 gc->array.texuv2[nu2++] = u; \
381 gc->array.texuv2[nu2++] = v
382 #define PUSH_TEXUV3(u, v) \
383 gc->array.texuv3[nu3++] = u; \
384 gc->array.texuv3[nu3++] = v
387 _evas_gl_common_context_array_alloc(Evas_GL_Context *gc)
389 if (gc->array.num <= gc->array.alloc) return;
390 gc->array.alloc += 6 * 1024;
391 if (gc->array.use_vertex)
392 gc->array.vertex = realloc(gc->array.vertex,
393 gc->array.alloc * sizeof(GLshort) * 3);
394 if (gc->array.use_color)
395 gc->array.color = realloc(gc->array.color,
396 gc->array.alloc * sizeof(GLubyte) * 4);
397 if (gc->array.use_texuv)
398 gc->array.texuv = realloc(gc->array.texuv,
399 gc->array.alloc * sizeof(GLfloat) * 2);
400 if (gc->array.use_texuv2)
401 gc->array.texuv2 = realloc(gc->array.texuv2,
402 gc->array.alloc * sizeof(GLfloat) * 2);
403 if (gc->array.use_texuv3)
404 gc->array.texuv3 = realloc(gc->array.texuv3,
405 gc->array.alloc * sizeof(GLfloat) * 2);
409 evas_gl_common_context_line_push(Evas_GL_Context *gc,
410 int x1, int y1, int x2, int y2,
411 int clip, int cx, int cy, int cw, int ch,
412 int r, int g, int b, int a)
414 int pnum, nv, nc, nu, nt, i;
417 shader_array_flush(gc);
419 if (a < 255) blend = 1;
420 if (gc->dc->render_op == EVAS_RENDER_COPY) blend = 0;
421 gc->shader.cur_tex = 0;
422 gc->shader.cur_prog = gc->shared->shader.rect.prog;
423 gc->shader.blend = 1;
424 gc->shader.render_op = gc->dc->render_op;
425 gc->shader.clip = clip;
432 gc->array.use_vertex = 1;
433 gc->array.use_color = 1;
434 gc->array.use_texuv = 0;
435 gc->array.use_texuv2 = 0;
436 gc->array.use_texuv3 = 0;
438 pnum = gc->array.num;
439 nv = pnum * 3; nc = pnum * 4; nu = pnum * 2; nt = pnum * 4;
441 _evas_gl_common_context_array_alloc(gc);
443 PUSH_VERTEX(x1, y1, 0);
444 PUSH_VERTEX(x2, y2, 0);
446 for (i = 0; i < 2; i++)
448 PUSH_COLOR(r, g, b, a);
451 shader_array_flush(gc);
453 gc->array.use_vertex = 0;
454 gc->array.use_color = 0;
455 gc->array.use_texuv = 0;
456 gc->array.use_texuv2 = 0;
457 gc->array.use_texuv3 = 0;
461 evas_gl_common_context_rectangle_push(Evas_GL_Context *gc,
462 int x, int y, int w, int h,
463 int r, int g, int b, int a)
465 int pnum, nv, nc, nu, nt, i;
468 if (a < 255) blend = 1;
469 if (gc->dc->render_op == EVAS_RENDER_COPY) blend = 0;
471 gc->shader.blend = 1;
473 if ((gc->shader.cur_tex != 0)
474 || (gc->shader.cur_prog != gc->shared->shader.rect.prog)
475 // || (gc->shader.blend != blend)
476 || (gc->shader.render_op != gc->dc->render_op)
477 || (gc->shader.clip != 0)
480 shader_array_flush(gc);
481 gc->shader.cur_tex = 0;
482 gc->shader.cur_prog = gc->shared->shader.rect.prog;
483 gc->shader.blend = 1;
484 gc->shader.render_op = gc->dc->render_op;
489 gc->array.use_vertex = 1;
490 gc->array.use_color = 1;
491 gc->array.use_texuv = 0;
492 gc->array.use_texuv2 = 0;
493 gc->array.use_texuv3 = 0;
495 pnum = gc->array.num;
496 nv = pnum * 3; nc = pnum * 4; nu = pnum * 2; nt = pnum * 4;
498 _evas_gl_common_context_array_alloc(gc);
500 PUSH_VERTEX(x , y , 0);
501 PUSH_VERTEX(x + w, y , 0);
502 PUSH_VERTEX(x , y + h, 0);
504 PUSH_VERTEX(x + w, y , 0);
505 PUSH_VERTEX(x + w, y + h, 0);
506 PUSH_VERTEX(x , y + h, 0);
508 for (i = 0; i < 6; i++)
510 PUSH_COLOR(r, g, b, a);
515 evas_gl_common_context_image_push(Evas_GL_Context *gc,
516 Evas_GL_Texture *tex,
517 double sx, double sy, double sw, double sh,
518 int x, int y, int w, int h,
519 int r, int g, int b, int a,
520 Eina_Bool smooth, Eina_Bool tex_only)
522 int pnum, nv, nc, nu, nu2, nt, i;
523 GLfloat tx1, tx2, ty1, ty2;
527 if (tex->pt->format == GL_RGB) blend = 0;
528 // if (a < 255) blend = 1;
530 gc->shader.blend = 1;
532 if ((gc->shader.cur_tex != tex->pt->texture)
533 || ((tex_only) && (gc->shader.cur_prog != gc->shared->shader.tex.prog))
534 || ((!tex_only) && (gc->shader.cur_prog != gc->shared->shader.img.prog))
535 || (gc->shader.smooth != smooth)
536 // || (gc->shader.blend != blend)
537 || (gc->shader.render_op != gc->dc->render_op)
538 || (gc->shader.clip != 0)
541 shader_array_flush(gc);
542 gc->shader.cur_tex = tex->pt->texture;
544 gc->shader.cur_prog = gc->shared->shader.tex.prog;
546 gc->shader.cur_prog =gc->shared->shader.img.prog;
547 gc->shader.smooth = smooth;
548 gc->shader.blend = 1;
549 gc->shader.render_op = gc->dc->render_op;
552 if ((tex->im) && (tex->im->native.data))
554 shader_array_flush(gc);
555 gc->array.im = tex->im;
558 gc->array.use_vertex = 1;
559 gc->array.use_color = 1;
560 gc->array.use_texuv = 1;
561 gc->array.use_texuv2 = 1;
562 gc->array.use_texuv3 = 0;
565 pnum = gc->array.num;
566 nv = pnum * 3; nc = pnum * 4; nu = pnum * 2; nu2 = pnum * 2;
569 _evas_gl_common_context_array_alloc(gc);
572 if ((tex->im) && (tex->im->native.data) && (!tex->im->native.yinvert))
574 tx1 = ((double)(tex->x) + sx) / (double)tex->pt->w;
575 ty1 = ((double)(tex->y) + sy + sh) / (double)tex->pt->h;
576 tx2 = ((double)(tex->x) + sx + sw) / (double)tex->pt->w;
577 ty2 = ((double)(tex->y) + sy) / (double)tex->pt->h;
581 tx1 = ((double)(tex->x) + sx) / (double)tex->pt->w;
582 ty1 = ((double)(tex->y) + sy) / (double)tex->pt->h;
583 tx2 = ((double)(tex->x) + sx + sw) / (double)tex->pt->w;
584 ty2 = ((double)(tex->y) + sy + sh) / (double)tex->pt->h;
588 PUSH_VERTEX(x , y , 0);
589 PUSH_VERTEX(x + w, y , 0);
590 PUSH_VERTEX(x , y + h, 0);
592 PUSH_TEXUV(tx1, ty1);
593 PUSH_TEXUV(tx2, ty1);
594 PUSH_TEXUV(tx1, ty2);
596 PUSH_TEXUV2(bl, 0.0);
597 PUSH_TEXUV2(bl, 0.0);
598 PUSH_TEXUV2(bl, 0.0);
600 PUSH_VERTEX(x + w, y , 0);
601 PUSH_VERTEX(x + w, y + h, 0);
602 PUSH_VERTEX(x , y + h, 0);
604 PUSH_TEXUV(tx2, ty1);
605 PUSH_TEXUV(tx2, ty2);
606 PUSH_TEXUV(tx1, ty2);
608 PUSH_TEXUV2(bl, 0.0);
609 PUSH_TEXUV2(bl, 0.0);
610 PUSH_TEXUV2(bl, 0.0);
612 for (i = 0; i < 6; i++)
614 PUSH_COLOR(r, g, b, a);
617 if ((tex->im) && (tex->im->native.data))
619 shader_array_flush(gc);
625 evas_gl_common_context_font_push(Evas_GL_Context *gc,
626 Evas_GL_Texture *tex,
627 double sx, double sy, double sw, double sh,
628 int x, int y, int w, int h,
629 int r, int g, int b, int a)
631 int pnum, nv, nc, nu, nt, i;
632 GLfloat tx1, tx2, ty1, ty2;
634 gc->shader.blend = 1;
636 if ((gc->shader.cur_tex != tex->pt->texture)
637 || (gc->shader.cur_prog != gc->shared->shader.font.prog)
638 || (gc->shader.smooth != 0)
639 // || (gc->shader.blend != 1)
640 || (gc->shader.render_op != gc->dc->render_op)
641 || (gc->shader.clip != 0)
644 shader_array_flush(gc);
645 gc->shader.cur_tex = tex->pt->texture;
646 gc->shader.cur_prog = gc->shared->shader.font.prog;
647 gc->shader.smooth = 0;
648 gc->shader.blend = 1;
649 gc->shader.render_op = gc->dc->render_op;
653 gc->array.use_vertex = 1;
654 gc->array.use_color = 1;
655 gc->array.use_texuv = 1;
656 gc->array.use_texuv2 = 0;
657 gc->array.use_texuv3 = 0;
659 pnum = gc->array.num;
660 nv = pnum * 3; nc = pnum * 4; nu = pnum * 2; nt = pnum * 4;
662 _evas_gl_common_context_array_alloc(gc);
673 tx1 = ((double)(tex->x) + sx) / (double)tex->pt->w;
674 ty1 = ((double)(tex->y) + sy) / (double)tex->pt->h;
675 tx2 = ((double)(tex->x) + sx + sw) / (double)tex->pt->w;
676 ty2 = ((double)(tex->y) + sy + sh) / (double)tex->pt->h;
679 PUSH_VERTEX(x , y , 0);
680 PUSH_VERTEX(x + w, y , 0);
681 PUSH_VERTEX(x , y + h, 0);
683 PUSH_TEXUV(tx1, ty1);
684 PUSH_TEXUV(tx2, ty1);
685 PUSH_TEXUV(tx1, ty2);
687 PUSH_VERTEX(x + w, y , 0);
688 PUSH_VERTEX(x + w, y + h, 0);
689 PUSH_VERTEX(x , y + h, 0);
691 PUSH_TEXUV(tx2, ty1);
692 PUSH_TEXUV(tx2, ty2);
693 PUSH_TEXUV(tx1, ty2);
695 for (i = 0; i < 6; i++)
697 PUSH_COLOR(r, g, b, a);
702 evas_gl_common_context_yuv_push(Evas_GL_Context *gc,
703 Evas_GL_Texture *tex,
704 double sx, double sy, double sw, double sh,
705 int x, int y, int w, int h,
706 int r, int g, int b, int a,
709 int pnum, nv, nc, nu, nu2, nu3, nt, i;
710 GLfloat tx1, tx2, ty1, ty2, t2x1, t2x2, t2y1, t2y2;
713 if (a < 255) blend = 1;
715 gc->shader.blend = 1;
717 if ((gc->shader.cur_tex != tex->pt->texture)
718 || (gc->shader.cur_prog != gc->shared->shader.yuv.prog)
719 || (gc->shader.smooth != smooth)
720 // || (gc->shader.blend != blend)
721 || (gc->shader.render_op != gc->dc->render_op)
722 || (gc->shader.clip != 0)
725 shader_array_flush(gc);
726 gc->shader.cur_tex = tex->pt->texture;
727 gc->shader.cur_texu = tex->ptu->texture;
728 gc->shader.cur_texv = tex->ptv->texture;
729 gc->shader.cur_prog = gc->shared->shader.yuv.prog;
730 gc->shader.smooth = smooth;
731 gc->shader.blend = 1;
732 gc->shader.render_op = gc->dc->render_op;
736 gc->array.use_vertex = 1;
737 gc->array.use_color = 1;
738 gc->array.use_texuv = 1;
739 gc->array.use_texuv2 = 1;
740 gc->array.use_texuv3 = 1;
742 pnum = gc->array.num;
743 nv = pnum * 3; nc = pnum * 4; nu = pnum * 2;
744 nu2 = pnum * 2; nu3 = pnum * 2; nt = pnum * 4;
746 _evas_gl_common_context_array_alloc(gc);
748 tx1 = (sx) / (double)tex->pt->w;
749 ty1 = (sy) / (double)tex->pt->h;
750 tx2 = (sx + sw) / (double)tex->pt->w;
751 ty2 = (sy + sh) / (double)tex->pt->h;
753 t2x1 = ((sx) / 2) / (double)tex->ptu->w;
754 t2y1 = ((sy) / 2) / (double)tex->ptu->h;
755 t2x2 = ((sx + sw) / 2) / (double)tex->ptu->w;
756 t2y2 = ((sy + sh) / 2) / (double)tex->ptu->h;
758 PUSH_VERTEX(x , y , 0);
759 PUSH_VERTEX(x + w, y , 0);
760 PUSH_VERTEX(x , y + h, 0);
762 PUSH_TEXUV(tx1, ty1);
763 PUSH_TEXUV(tx2, ty1);
764 PUSH_TEXUV(tx1, ty2);
766 PUSH_TEXUV2(t2x1, t2y1);
767 PUSH_TEXUV2(t2x2, t2y1);
768 PUSH_TEXUV2(t2x1, t2y2);
770 PUSH_TEXUV3(t2x1, t2y1);
771 PUSH_TEXUV3(t2x2, t2y1);
772 PUSH_TEXUV3(t2x1, t2y2);
774 PUSH_VERTEX(x + w, y , 0);
775 PUSH_VERTEX(x + w, y + h, 0);
776 PUSH_VERTEX(x , y + h, 0);
778 PUSH_TEXUV(tx2, ty1);
779 PUSH_TEXUV(tx2, ty2);
780 PUSH_TEXUV(tx1, ty2);
782 PUSH_TEXUV2(t2x2, t2y1);
783 PUSH_TEXUV2(t2x2, t2y2);
784 PUSH_TEXUV2(t2x1, t2y2);
786 PUSH_TEXUV3(t2x2, t2y1);
787 PUSH_TEXUV3(t2x2, t2y2);
788 PUSH_TEXUV3(t2x1, t2y2);
790 for (i = 0; i < 6; i++)
792 PUSH_COLOR(r, g, b, a);
797 evas_gl_common_context_image_map4_push(Evas_GL_Context *gc,
798 Evas_GL_Texture *tex,
800 int clip, int cx, int cy, int cw, int ch,
801 int r, int g, int b, int a,
802 Eina_Bool smooth, Eina_Bool tex_only)
804 int pnum, nv, nc, nu, nu2, nt, i;
805 const int points[6] = { 0, 1, 2, 0, 2, 3 };
806 GLfloat tx[4], ty[4];
812 gc->shader.blend = 1;
814 if (tex->pt->format == GL_RGB) blend = 0;
815 // if (a < 255) blend = 1;
817 if ((gc->shader.cur_tex != tex->pt->texture)
818 || ((tex_only) && (gc->shader.cur_prog != gc->shared->shader.tex.prog))
819 || ((!tex_only) && (gc->shader.cur_prog != gc->shared->shader.img.prog))
820 || (gc->shader.smooth != smooth)
821 // || (gc->shader.blend != blend)
822 || (gc->shader.render_op != gc->dc->render_op)
823 || (gc->shader.clip != clip)
824 || (gc->shader.cx != cx)
825 || (gc->shader.cy != cy)
826 || (gc->shader.cw != cw)
827 || (gc->shader.ch != ch)
830 shader_array_flush(gc);
831 gc->shader.cur_tex = tex->pt->texture;
833 gc->shader.cur_prog = gc->shared->shader.tex.prog;
835 gc->shader.cur_prog =gc->shared->shader.img.prog;
836 gc->shader.smooth = smooth;
837 gc->shader.blend = 1;
838 gc->shader.render_op = gc->dc->render_op;
839 gc->shader.clip = clip;
846 gc->array.use_vertex = 1;
847 gc->array.use_color = 1;
848 gc->array.use_texuv = 1;
849 gc->array.use_texuv2 = 1;
850 gc->array.use_texuv3 = 0;
852 pnum = gc->array.num;
853 nv = pnum * 3; nc = pnum * 4; nu = pnum * 2; nu2 = pnum * 2;
856 _evas_gl_common_context_array_alloc(gc);
858 // FIXME: handle yinvert
859 for (i = 0; i < 4; i++)
861 tx[i] = ((double)(tex->x) + (((double)p[i].u) / FP1)) /
863 ty[i] = ((double)(tex->y) + (((double)p[i].v) / FP1)) /
869 cmul = ARGB_JOIN(a, r, g, b);
870 for (i = 0; i < 6; i++)
872 DATA32 cl = MUL4_SYM(cmul, p[points[i]].col);
873 PUSH_VERTEX((p[points[i]].x >> FP),
874 (p[points[i]].y >> FP),
876 // (p[points[i]].y >> FP) + 4096);
877 // (p[points[i]].z >> FP));
878 PUSH_TEXUV(tx[points[i]],
881 PUSH_TEXUV2(bl, 0.0);
883 PUSH_COLOR(R_VAL(&cl),
891 evas_gl_common_context_flush(Evas_GL_Context *gc)
893 shader_array_flush(gc);
894 // fprintf(stderr, "------------FRAME: done\n");
898 shader_array_flush(Evas_GL_Context *gc)
900 if (gc->array.num <= 0) return;
902 // fprintf(stderr, " flush array %i\n", gc->array.num);
903 if (gc->shader.cur_prog != gc->shader.current.cur_prog)
904 glUseProgram(gc->shader.cur_prog);
906 if (gc->shader.cur_tex != gc->shader.current.cur_tex)
908 if (gc->shader.cur_tex) glEnable(GL_TEXTURE_2D);
909 else glDisable(GL_TEXTURE_2D);
910 glActiveTexture(GL_TEXTURE0);
911 glBindTexture(GL_TEXTURE_2D, gc->shader.cur_tex);
915 if (gc->array.im->native.func.bind)
916 gc->array.im->native.func.bind(gc->array.im->native.func.data,
919 if (gc->shader.render_op != gc->shader.current.render_op)
921 switch (gc->shader.render_op)
923 case EVAS_RENDER_BLEND: /**< default op: d = d*(1-sa) + s */
924 glBlendFunc(GL_ONE, GL_ONE_MINUS_SRC_ALPHA);
926 case EVAS_RENDER_COPY: /**< d = s */
927 gc->shader.blend = 0;
928 glBlendFunc(GL_ONE, GL_ONE);
930 // FIXME: fix blend funcs below!
931 case EVAS_RENDER_BLEND_REL: /**< d = d*(1 - sa) + s*da */
932 case EVAS_RENDER_COPY_REL: /**< d = s*da */
933 case EVAS_RENDER_ADD: /**< d = d + s */
934 case EVAS_RENDER_ADD_REL: /**< d = d + s*da */
935 case EVAS_RENDER_SUB: /**< d = d - s */
936 case EVAS_RENDER_SUB_REL: /**< d = d - s*da */
937 case EVAS_RENDER_TINT: /**< d = d*s + d*(1 - sa) + s*(1 - da) */
938 case EVAS_RENDER_TINT_REL: /**< d = d*(1 - sa + s) */
939 case EVAS_RENDER_MASK: /**< d = d*sa */
940 case EVAS_RENDER_MUL: /**< d = d*s */
942 glBlendFunc(GL_ONE, GL_ONE_MINUS_SRC_ALPHA);
946 if (gc->shader.blend != gc->shader.current.blend)
948 if (gc->shader.blend) glEnable(GL_BLEND);
949 else glDisable(GL_BLEND);
951 if (gc->shader.smooth != gc->shader.current.smooth)
953 if (gc->shader.smooth)
955 #ifdef GL_TEXTURE_MAX_ANISOTROPY_EXT
956 glTexParameteri(GL_TEXTURE_2D, GL_TEXTURE_MAX_ANISOTROPY_EXT, 16);
958 glTexParameteri(GL_TEXTURE_2D, GL_TEXTURE_MAG_FILTER, GL_LINEAR);
959 glTexParameteri(GL_TEXTURE_2D, GL_TEXTURE_MIN_FILTER, GL_LINEAR);
960 glTexParameteri(GL_TEXTURE_2D, GL_TEXTURE_WRAP_S, GL_CLAMP_TO_EDGE);
961 glTexParameteri(GL_TEXTURE_2D, GL_TEXTURE_WRAP_T, GL_CLAMP_TO_EDGE);
965 #ifdef GL_TEXTURE_MAX_ANISOTROPY_EXT
966 glTexParameteri(GL_TEXTURE_2D, GL_TEXTURE_MAX_ANISOTROPY_EXT, 1);
968 glTexParameteri(GL_TEXTURE_2D, GL_TEXTURE_MAG_FILTER, GL_NEAREST);
969 glTexParameteri(GL_TEXTURE_2D, GL_TEXTURE_MIN_FILTER, GL_NEAREST);
970 glTexParameteri(GL_TEXTURE_2D, GL_TEXTURE_WRAP_S, GL_CLAMP_TO_EDGE);
971 glTexParameteri(GL_TEXTURE_2D, GL_TEXTURE_WRAP_T, GL_CLAMP_TO_EDGE);
974 /* hmmm this breaks things. must find out why!
975 if (gc->shader.clip != gc->shader.current.clip)
978 glEnable(GL_SCISSOR_TEST);
981 glDisable(GL_SCISSOR_TEST);
982 // glScissor(0, 0, 0, 0);
987 if ((gc->shader.cx != gc->shader.current.cx) ||
988 (gc->shader.cx != gc->shader.current.cx) ||
989 (gc->shader.cx != gc->shader.current.cx) ||
990 (gc->shader.cx != gc->shader.current.cx))
992 glScissor(gc->shader.cx,
993 gc->h - gc->shader.cy - gc->shader.ch,
998 // gc->h - gc->clip.y - gc->clip.h,
1004 glVertexAttribPointer(SHAD_VERTEX, 3, GL_SHORT, GL_FALSE, 0, gc->array.vertex);
1005 glVertexAttribPointer(SHAD_COLOR, 4, GL_UNSIGNED_BYTE, GL_TRUE, 0, gc->array.color);
1006 if (gc->array.use_texuv)
1008 glEnableVertexAttribArray(SHAD_TEXUV);
1009 glVertexAttribPointer(SHAD_TEXUV, 2, GL_FLOAT, GL_FALSE, 0, gc->array.texuv);
1012 glDisableVertexAttribArray(SHAD_TEXUV);
1016 glDisableVertexAttribArray(SHAD_TEXUV);
1017 glDisableVertexAttribArray(SHAD_TEXUV2);
1018 glDisableVertexAttribArray(SHAD_TEXUV3);
1019 glDrawArrays(GL_LINES, 0, gc->array.num);
1023 if ((gc->array.use_texuv2) && (gc->array.use_texuv3))
1025 glEnableVertexAttribArray(SHAD_TEXUV2);
1026 glEnableVertexAttribArray(SHAD_TEXUV3);
1027 glVertexAttribPointer(SHAD_TEXUV2, 2, GL_FLOAT, GL_FALSE, 0, gc->array.texuv2);
1028 glVertexAttribPointer(SHAD_TEXUV3, 2, GL_FLOAT, GL_FALSE, 0, gc->array.texuv3);
1029 glActiveTexture(GL_TEXTURE1);
1030 glBindTexture(GL_TEXTURE_2D, gc->shader.cur_texu);
1031 glActiveTexture(GL_TEXTURE2);
1032 glBindTexture(GL_TEXTURE_2D, gc->shader.cur_texv);
1033 glActiveTexture(GL_TEXTURE0);
1035 else if (gc->array.use_texuv2)
1037 glEnableVertexAttribArray(SHAD_TEXUV2);
1038 glVertexAttribPointer(SHAD_TEXUV2, 2, GL_FLOAT, GL_FALSE, 0, gc->array.texuv2);
1042 glDisableVertexAttribArray(SHAD_TEXUV2);
1043 glDisableVertexAttribArray(SHAD_TEXUV3);
1046 glDrawArrays(GL_TRIANGLES, 0, gc->array.num);
1050 if (gc->array.im->native.func.unbind)
1051 gc->array.im->native.func.unbind(gc->array.im->native.func.data,
1054 gc->shader.cur_tex = 0;
1055 glBindTexture(GL_TEXTURE_2D, gc->shader.cur_tex);
1056 if (gc->shader.cur_tex) glEnable(GL_TEXTURE_2D);
1057 else glDisable(GL_TEXTURE_2D);
1061 gc->shader.current.cur_prog = gc->shader.cur_prog;
1062 gc->shader.current.cur_tex = gc->shader.cur_tex;
1063 gc->shader.current.blend = gc->shader.blend;
1064 gc->shader.current.smooth = gc->shader.smooth;
1065 gc->shader.current.render_op = gc->shader.render_op;
1066 gc->shader.current.clip = gc->shader.clip;
1067 gc->shader.current.cx = gc->shader.cx;
1068 gc->shader.current.cy = gc->shader.cy;
1069 gc->shader.current.cw = gc->shader.cw;
1070 gc->shader.current.ch = gc->shader.ch;
1072 if (gc->array.vertex) free(gc->array.vertex);
1073 if (gc->array.color) free(gc->array.color);
1074 if (gc->array.texuv) free(gc->array.texuv);
1075 if (gc->array.texuv2) free(gc->array.texuv2);
1076 if (gc->array.texuv3) free(gc->array.texuv3);
1078 gc->array.vertex = NULL;
1079 gc->array.color = NULL;
1080 gc->array.texuv = NULL;
1081 gc->array.texuv2 = NULL;
1082 gc->array.texuv3 = NULL;
1085 gc->array.alloc = 0;