From 3b434eacde58450965708c3eafb6b22eb2a99361 Mon Sep 17 00:00:00 2001 From: Juan Linietsky Date: Tue, 14 Apr 2015 22:05:14 -0300 Subject: [PATCH] Fix clipping when used in viewport or inside another viewport, fixes #1661 --- drivers/gles2/rasterizer_gles2.cpp | 55 +++++++++++++++++++++++++----- main/main.cpp | 10 +++--- 2 files changed, 53 insertions(+), 12 deletions(-) diff --git a/drivers/gles2/rasterizer_gles2.cpp b/drivers/gles2/rasterizer_gles2.cpp index f48105e3f1d..0359f5f5a01 100644 --- a/drivers/gles2/rasterizer_gles2.cpp +++ b/drivers/gles2/rasterizer_gles2.cpp @@ -7993,8 +7993,16 @@ void RasterizerGLES2::canvas_set_clip(bool p_clip, const Rect2& p_rect) { if (p_clip) { glEnable(GL_SCISSOR_TEST); - glScissor(viewport.x+p_rect.pos.x,viewport.y+ (viewport.height-(p_rect.pos.y+p_rect.size.height)), - p_rect.size.width,p_rect.size.height); + //glScissor(viewport.x+p_rect.pos.x,viewport.y+ (viewport.height-(p_rect.pos.y+p_rect.size.height)), + + int x = p_rect.pos.x; + int y = window_size.height-(p_rect.pos.y+p_rect.size.y); + int w = p_rect.size.x; + int h = p_rect.size.y; + + glScissor(x,y,w,h); + + } else { glDisable(GL_SCISSOR_TEST); @@ -9087,8 +9095,17 @@ void RasterizerGLES2::_canvas_item_render_commands(CanvasItem *p_item,CanvasItem } else { glEnable(GL_SCISSOR_TEST); - glScissor(viewport.x+current_clip->final_clip_rect.pos.x,viewport.y+ (viewport.height-(current_clip->final_clip_rect.pos.y+current_clip->final_clip_rect.size.height)), - current_clip->final_clip_rect.size.width,current_clip->final_clip_rect.size.height); + //glScissor(viewport.x+current_clip->final_clip_rect.pos.x,viewport.y+ (viewport.height-(current_clip->final_clip_rect.pos.y+current_clip->final_clip_rect.size.height)), + //current_clip->final_clip_rect.size.width,current_clip->final_clip_rect.size.height); + + int x = current_clip->final_clip_rect.pos.x; + int y = window_size.height-(current_clip->final_clip_rect.pos.y+current_clip->final_clip_rect.size.y); + int w = current_clip->final_clip_rect.size.x; + int h = current_clip->final_clip_rect.size.y; + + glScissor(x,y,w,h); + + reclip=false; } } @@ -9262,8 +9279,21 @@ void RasterizerGLES2::canvas_render_items(CanvasItem *p_item_list,int p_z,const if (current_clip) { glEnable(GL_SCISSOR_TEST); - glScissor(viewport.x+current_clip->final_clip_rect.pos.x,viewport.y+ (viewport.height-(current_clip->final_clip_rect.pos.y+current_clip->final_clip_rect.size.height)), - current_clip->final_clip_rect.size.width,current_clip->final_clip_rect.size.height); + //glScissor(viewport.x+current_clip->final_clip_rect.pos.x,viewport.y+ (viewport.height-(current_clip->final_clip_rect.pos.y+current_clip->final_clip_rect.size.height)), + //current_clip->final_clip_rect.size.width,current_clip->final_clip_rect.size.height); + +/* int x = viewport.x+current_clip->final_clip_rect.pos.x; + int y = window_size.height-(viewport.y+current_clip->final_clip_rect.pos.y+current_clip->final_clip_rect.size.y); + int w = current_clip->final_clip_rect.size.x; + int h = current_clip->final_clip_rect.size.y; +*/ + int x = current_clip->final_clip_rect.pos.x; + int y = window_size.height-(current_clip->final_clip_rect.pos.y+current_clip->final_clip_rect.size.y); + int w = current_clip->final_clip_rect.size.x; + int h = current_clip->final_clip_rect.size.y; + + glScissor(x,y,w,h); + } else { glDisable(GL_SCISSOR_TEST); @@ -9552,8 +9582,17 @@ void RasterizerGLES2::canvas_render_items(CanvasItem *p_item_list,int p_z,const if (reclip) { glEnable(GL_SCISSOR_TEST); - glScissor(viewport.x+current_clip->final_clip_rect.pos.x,viewport.y+ (viewport.height-(current_clip->final_clip_rect.pos.y+current_clip->final_clip_rect.size.height)), - current_clip->final_clip_rect.size.width,current_clip->final_clip_rect.size.height); + //glScissor(viewport.x+current_clip->final_clip_rect.pos.x,viewport.y+ (viewport.height-(current_clip->final_clip_rect.pos.y+current_clip->final_clip_rect.size.height)), + //current_clip->final_clip_rect.size.width,current_clip->final_clip_rect.size.height); + + int x = current_clip->final_clip_rect.pos.x; + int y = window_size.height-(current_clip->final_clip_rect.pos.y+current_clip->final_clip_rect.size.y); + int w = current_clip->final_clip_rect.size.x; + int h = current_clip->final_clip_rect.size.y; + + glScissor(x,y,w,h); + + } diff --git a/main/main.cpp b/main/main.cpp index 517ccaec08d..dcf3c6f8d1c 100644 --- a/main/main.cpp +++ b/main/main.cpp @@ -1293,12 +1293,15 @@ bool Main::iteration() { uint64_t ticks=OS::get_singleton()->get_ticks_usec(); uint64_t ticks_elapsed=ticks-last_ticks; + double step=(double)ticks_elapsed / 1000000.0; + float frame_slice=1.0/OS::get_singleton()->get_iterations_per_second(); + + //if (time_accum+step < frame_slice) + // return false; + frame+=ticks_elapsed; last_ticks=ticks; - double step=(double)ticks_elapsed / 1000000.0; - - float frame_slice=1.0/OS::get_singleton()->get_iterations_per_second(); if (step>frame_slice*8) step=frame_slice*8; @@ -1309,7 +1312,6 @@ bool Main::iteration() { bool exit=false; - int iters = 0; while(time_accum>frame_slice) {