summaryrefslogtreecommitdiff
diff options
context:
space:
mode:
authorJean-Philippe Andre <jp.andre@samsung.com>2014-12-09 18:35:35 +0900
committerJean-Philippe Andre <jp.andre@samsung.com>2014-12-09 18:38:08 +0900
commite4a11c008c124f246ba410f6398e22559ba6ab00 (patch)
treea93d8de7a54e0147051eeba0a40b4e8062d3f1a5
parent2a69980959408ccd7cc48c29d7e3939764cb1281 (diff)
Evas GL: Fix scissors with direct rendering
If an app calls glDisable(SCISSORS) and uses direct rendering, then the DR scissors were dropped and so glClear would erase the contents of the entire canvas, instead of being restricted to the image object.
-rw-r--r--src/modules/evas/engines/gl_common/evas_gl_api.c111
-rw-r--r--src/modules/evas/engines/gl_common/evas_gl_core_private.h10
2 files changed, 108 insertions, 13 deletions
diff --git a/src/modules/evas/engines/gl_common/evas_gl_api.c b/src/modules/evas/engines/gl_common/evas_gl_api.c
index ed8f501..2e3f980 100644
--- a/src/modules/evas/engines/gl_common/evas_gl_api.c
+++ b/src/modules/evas/engines/gl_common/evas_gl_api.c
@@ -451,8 +451,66 @@ _evgl_glEnable(GLenum cap)
451 451
452 ctx = evas_gl_common_current_context_get(); 452 ctx = evas_gl_common_current_context_get();
453 453
454 if (cap == GL_SCISSOR_TEST) 454 if (ctx && (cap == GL_SCISSOR_TEST))
455 if (ctx) ctx->scissor_enabled = 1; 455 {
456 ctx->scissor_enabled = 1;
457
458 if (_evgl_direct_enabled())
459 {
460 EVGL_Resource *rsc = _evgl_tls_resource_get();
461 int oc[4] = {0,0,0,0}, nc[4] = {0,0,0,0}, cc[4] = {0,0,0,0};
462
463 if (!ctx->current_fbo)
464 {
465 // Direct rendering to canvas
466 if (!ctx->scissor_updated)
467 {
468 compute_gl_coordinates(rsc->direct.win_w, rsc->direct.win_h,
469 rsc->direct.rot, 0,
470 0, 0, 0, 0,
471 rsc->direct.img.x, rsc->direct.img.y,
472 rsc->direct.img.w, rsc->direct.img.h,
473 rsc->direct.clip.x, rsc->direct.clip.y,
474 rsc->direct.clip.w, rsc->direct.clip.h,
475 oc, nc, cc);
476 glScissor(cc[0], cc[1], cc[2], cc[3]);
477 }
478 else
479 {
480 compute_gl_coordinates(rsc->direct.win_w, rsc->direct.win_h,
481 rsc->direct.rot, 1,
482 ctx->scissor_coord[0], ctx->scissor_coord[1],
483 ctx->scissor_coord[2], ctx->scissor_coord[3],
484 rsc->direct.img.x, rsc->direct.img.y,
485 rsc->direct.img.w, rsc->direct.img.h,
486 rsc->direct.clip.x, rsc->direct.clip.y,
487 rsc->direct.clip.w, rsc->direct.clip.h,
488 oc, nc, cc);
489 glScissor(nc[0], nc[1], nc[2], nc[3]);
490 }
491 ctx->direct_scissor = 1;
492 }
493 else
494 {
495 // Bound to an FBO, reset scissors to user data
496 if (ctx->scissor_updated)
497 {
498 glScissor(ctx->scissor_coord[0], ctx->scissor_coord[1],
499 ctx->scissor_coord[2], ctx->scissor_coord[3]);
500 }
501 else if (ctx->direct_scissor)
502 {
503 // Back to the default scissors (here: max texture size)
504 glScissor(0, 0, evgl_engine->caps.max_w, evgl_engine->caps.max_h);
505 }
506 ctx->direct_scissor = 0;
507 }
508
509 glEnable(GL_SCISSOR_TEST);
510 return;
511 }
512 }
513
456 glEnable(cap); 514 glEnable(cap);
457} 515}
458 516
@@ -463,8 +521,43 @@ _evgl_glDisable(GLenum cap)
463 521
464 ctx = evas_gl_common_current_context_get(); 522 ctx = evas_gl_common_current_context_get();
465 523
466 if (cap == GL_SCISSOR_TEST) 524 if (ctx && (cap == GL_SCISSOR_TEST))
467 if (ctx) ctx->scissor_enabled = 0; 525 {
526 ctx->scissor_enabled = 0;
527
528 if (_evgl_direct_enabled())
529 {
530 if (!ctx->current_fbo)
531 {
532 // Restore default scissors for direct rendering
533 int oc[4] = {0,0,0,0}, nc[4] = {0,0,0,0}, cc[4] = {0,0,0,0};
534 EVGL_Resource *rsc = _evgl_tls_resource_get();
535
536 compute_gl_coordinates(rsc->direct.win_w, rsc->direct.win_h,
537 rsc->direct.rot, 1,
538 0, 0, rsc->direct.img.w, rsc->direct.img.h,
539 rsc->direct.img.x, rsc->direct.img.y,
540 rsc->direct.img.w, rsc->direct.img.h,
541 rsc->direct.clip.x, rsc->direct.clip.y,
542 rsc->direct.clip.w, rsc->direct.clip.h,
543 oc, nc, cc);
544
545 RECTS_CLIP_TO_RECT(nc[0], nc[1], nc[2], nc[3], cc[0], cc[1], cc[2], cc[3]);
546 glScissor(nc[0], nc[1], nc[2], nc[3]);
547
548 ctx->direct_scissor = 1;
549 glEnable(GL_SCISSOR_TEST);
550 }
551 else
552 {
553 // Bound to an FBO, disable scissors for real
554 ctx->direct_scissor = 0;
555 glDisable(GL_SCISSOR_TEST);
556 }
557 return;
558 }
559 }
560
468 glDisable(cap); 561 glDisable(cap);
469} 562}
470 563
@@ -506,8 +599,7 @@ _evgl_glGetIntegerv(GLenum pname, GLint* params)
506 return; 599 return;
507 } 600 }
508 } 601 }
509 602 else if (pname == GL_VIEWPORT)
510 if (pname == GL_VIEWPORT)
511 { 603 {
512 if (ctx->viewport_updated) 604 if (ctx->viewport_updated)
513 { 605 {
@@ -722,6 +814,7 @@ _evgl_glScissor(GLint x, GLint y, GLsizei width, GLsizei height)
722 { 814 {
723 if (!(rsc->current_ctx->current_fbo)) 815 if (!(rsc->current_ctx->current_fbo))
724 { 816 {
817 // Direct rendering to canvas
725 if ((ctx->direct_scissor) && (!ctx->scissor_enabled)) 818 if ((ctx->direct_scissor) && (!ctx->scissor_enabled))
726 { 819 {
727 glDisable(GL_SCISSOR_TEST); 820 glDisable(GL_SCISSOR_TEST);
@@ -747,11 +840,12 @@ _evgl_glScissor(GLint x, GLint y, GLsizei width, GLsizei height)
747 840
748 ctx->direct_scissor = 0; 841 ctx->direct_scissor = 0;
749 842
750 // Check....!!!! 843 // Mark user scissor_coord as valid
751 ctx->scissor_updated = 1; 844 ctx->scissor_updated = 1;
752 } 845 }
753 else 846 else
754 { 847 {
848 // Bound to an FBO, use these new scissors
755 if ((ctx->direct_scissor) && (!ctx->scissor_enabled)) 849 if ((ctx->direct_scissor) && (!ctx->scissor_enabled))
756 { 850 {
757 glDisable(GL_SCISSOR_TEST); 851 glDisable(GL_SCISSOR_TEST);
@@ -760,7 +854,8 @@ _evgl_glScissor(GLint x, GLint y, GLsizei width, GLsizei height)
760 854
761 glScissor(x, y, width, height); 855 glScissor(x, y, width, height);
762 856
763 ctx->scissor_updated = 0; 857 // Why did we set this flag to 0???
858 //ctx->scissor_updated = 0;
764 } 859 }
765 } 860 }
766 else 861 else
diff --git a/src/modules/evas/engines/gl_common/evas_gl_core_private.h b/src/modules/evas/engines/gl_common/evas_gl_core_private.h
index 4da0aa4..ec30529 100644
--- a/src/modules/evas/engines/gl_common/evas_gl_core_private.h
+++ b/src/modules/evas/engines/gl_common/evas_gl_core_private.h
@@ -157,12 +157,12 @@ struct _EVGL_Context
157 GLuint current_fbo; 157 GLuint current_fbo;
158 158
159 // Direct Rendering Related 159 // Direct Rendering Related
160 int scissor_enabled; 160 int scissor_enabled : 1;
161 int scissor_updated; 161 int scissor_updated : 1;
162 int scissor_coord[4]; 162 int direct_scissor : 1;
163 int direct_scissor; 163 int viewport_updated : 1;
164 164
165 int viewport_updated; 165 int scissor_coord[4];
166 int viewport_coord[4]; 166 int viewport_coord[4];
167 167
168 // Partial Rendering 168 // Partial Rendering