Cleanup: GPU: Encapsulate scissor test

This commit is contained in:
Clément Foucault 2020-07-17 19:21:33 +02:00
parent d19b3019d9
commit 1f2edba1fb
6 changed files with 19 additions and 9 deletions

View File

@ -404,7 +404,7 @@ void ED_screen_draw_edges(wmWindow *win)
/* It seems that all areas gets smaller when pixelsize is > 1.
* So in order to avoid missing pixels we just disable de scissors. */
if (U.pixelsize <= 1.0f) {
glEnable(GL_SCISSOR_TEST);
GPU_scissor_test(true);
}
UI_GetThemeColor4fv(TH_EDITOR_OUTLINE, col);
@ -429,7 +429,7 @@ void ED_screen_draw_edges(wmWindow *win)
GPU_blend(false);
if (U.pixelsize <= 1.0f) {
glDisable(GL_SCISSOR_TEST);
GPU_scissor_test(false);
}
}

View File

@ -615,8 +615,7 @@ static bool paint_draw_tex_overlay(UnifiedPaintSettings *ups,
if (load_tex(brush, vc, zoom, col, primary)) {
GPU_color_mask(true, true, true, true);
GPU_depth_mask(false);
glDepthFunc(GL_ALWAYS);
GPU_depth_test(false);
if (mtex->brush_map_mode == MTEX_MAP_MODE_VIEW) {
GPU_matrix_push();

View File

@ -55,6 +55,7 @@ void GPU_blend_set_func_separate(eGPUBlendFunction src_rgb,
void GPU_depth_range(float near, float far);
void GPU_depth_test(bool enable);
bool GPU_depth_test_enabled(void);
void GPU_scissor_test(bool enable);
void GPU_line_smooth(bool enable);
void GPU_line_width(float width);
void GPU_point_size(float size);

View File

@ -979,10 +979,10 @@ void GPU_offscreen_bind(GPUOffScreen *ofs, bool save)
GPUFrameBuffer *fb = GPU_framebuffer_active_get();
gpuPushFrameBuffer(fb);
}
glDisable(GL_SCISSOR_TEST);
GPUFrameBuffer *ofs_fb = gpu_offscreen_fb_get(ofs);
GPU_framebuffer_bind(ofs_fb);
glDisable(GL_FRAMEBUFFER_SRGB);
GPU_scissor_test(false);
GPU_shader_set_framebuffer_srgb_target(false);
}

View File

@ -146,6 +146,16 @@ void GPU_program_point_size(bool enable)
}
}
void GPU_scissor_test(bool enable)
{
if (enable) {
glEnable(GL_SCISSOR_TEST);
}
else {
glDisable(GL_SCISSOR_TEST);
}
}
void GPU_scissor(int x, int y, int width, int height)
{
glScissor(x, y, width, height);

View File

@ -106,7 +106,7 @@ static void wm_paintcursor_draw(bContext *C, ScrArea *area, ARegion *region)
if (pc->poll == NULL || pc->poll(C)) {
/* Prevent drawing outside region. */
glEnable(GL_SCISSOR_TEST);
GPU_scissor_test(true);
GPU_scissor(region->winrct.xmin,
region->winrct.ymin,
BLI_rcti_size_x(&region->winrct) + 1,
@ -121,7 +121,7 @@ static void wm_paintcursor_draw(bContext *C, ScrArea *area, ARegion *region)
pc->draw(C, win->eventstate->x, win->eventstate->y, pc->customdata);
}
glDisable(GL_SCISSOR_TEST);
GPU_scissor_test(false);
}
}
}
@ -461,7 +461,7 @@ static void wm_draw_region_bind(ARegion *region, int view)
/* For now scissor is expected by region drawing, we could disable it
* and do the enable/disable in the specific cases that setup scissor. */
glEnable(GL_SCISSOR_TEST);
GPU_scissor_test(true);
GPU_scissor(0, 0, region->winx, region->winy);
}
@ -480,7 +480,7 @@ static void wm_draw_region_unbind(ARegion *region)
GPU_viewport_unbind(region->draw_buffer->viewport);
}
else {
glDisable(GL_SCISSOR_TEST);
GPU_scissor_test(false);
GPU_offscreen_unbind(region->draw_buffer->offscreen, false);
}
}