Cleanup: GPU: Move towards an explicit Blend state

This make use of the GLStateStack functions for:
- `GPU_blend()`
- `GPU_blend_set_func()`
- `GPU_blend_set_func_separate()`

The goal is to unify them using an explicit state setting.
This will remove the need to use obscure blend functions
This commit is contained in:
Clément Foucault 2020-08-16 14:47:13 +02:00
parent 2ae1c895a2
commit a1459b2f7a
7 changed files with 32 additions and 19 deletions

View File

@ -135,7 +135,6 @@ static void region_draw_emboss(const ARegion *region, const rcti *scirct, int si
immUnbindProgram();
GPU_blend(false);
GPU_blend_set_func(GPU_SRC_ALPHA, GPU_ONE_MINUS_SRC_ALPHA);
}
void ED_region_pixelspace(ARegion *region)

View File

@ -308,10 +308,9 @@ static void scrarea_draw_shape_dark(ScrArea *area, char dir, uint pos)
*/
static void scrarea_draw_shape_light(ScrArea *area, char UNUSED(dir), uint pos)
{
GPU_blend_set_func(GPU_DST_COLOR, GPU_SRC_ALPHA);
/* value 181 was hardly computed: 181~105 */
immUniformColor4ub(255, 255, 255, 50);
/* draw_join_shape(area, dir); */
GPU_blend_set_func_separate(
GPU_SRC_ALPHA, GPU_ONE_MINUS_SRC_ALPHA, GPU_ONE, GPU_ONE_MINUS_SRC_ALPHA);
immUniformColor4ub(255, 255, 255, 25);
immRectf(pos, area->v1->vec.x, area->v1->vec.y, area->v3->vec.x, area->v3->vec.y);
}

View File

@ -634,8 +634,8 @@ static bool paint_draw_tex_overlay(UnifiedPaintSettings *ups,
uint texCoord = GPU_vertformat_attr_add(format, "texCoord", GPU_COMP_F32, 2, GPU_FETCH_FLOAT);
/* Premultiplied alpha blending. */
GPU_blend_set_func(GPU_ONE, GPU_ONE_MINUS_SRC_ALPHA);
GPU_blend(true);
GPU_blend_set_func(GPU_ONE, GPU_ONE_MINUS_SRC_ALPHA);
immBindBuiltinProgram(GPU_SHADER_2D_IMAGE_COLOR);
@ -670,8 +670,6 @@ static bool paint_draw_tex_overlay(UnifiedPaintSettings *ups,
GPU_texture_unbind(texture);
GPU_blend_set_func(GPU_SRC_ALPHA, GPU_ONE_MINUS_SRC_ALPHA);
if (ELEM(mtex->brush_map_mode, MTEX_MAP_MODE_STENCIL, MTEX_MAP_MODE_VIEW)) {
GPU_matrix_pop();
}
@ -729,8 +727,8 @@ static bool paint_draw_cursor_overlay(
uint pos = GPU_vertformat_attr_add(format, "pos", GPU_COMP_F32, 2, GPU_FETCH_FLOAT);
uint texCoord = GPU_vertformat_attr_add(format, "texCoord", GPU_COMP_F32, 2, GPU_FETCH_FLOAT);
GPU_blend_set_func(GPU_ONE, GPU_ONE_MINUS_SRC_ALPHA);
GPU_blend(true);
GPU_blend_set_func(GPU_ONE, GPU_ONE_MINUS_SRC_ALPHA);
immBindBuiltinProgram(GPU_SHADER_2D_IMAGE_COLOR);
@ -757,8 +755,6 @@ static bool paint_draw_cursor_overlay(
immUnbindProgram();
GPU_blend_set_func(GPU_SRC_ALPHA, GPU_ONE_MINUS_SRC_ALPHA);
if (do_pop) {
GPU_matrix_pop();
}

View File

@ -35,8 +35,17 @@
#include "gpu_state_private.hh"
/* TODO remove */
#include "gl_state.hh"
using namespace blender::gpu;
// /* This should replace GPU_blend, GPU_blend_set_func and GPU_blend_set_func_separate. */
// void GPU_blend_set(eGPUBlend blend)
// {
// GLStateStack::set_blend(blend);
// }
static GLenum gpu_get_gl_blendfunction(eGPUBlendFunction blend)
{
switch (blend) {
@ -59,16 +68,30 @@ static GLenum gpu_get_gl_blendfunction(eGPUBlendFunction blend)
void GPU_blend(bool enable)
{
if (enable) {
glEnable(GL_BLEND);
GLStateStack::set_blend(GPU_BLEND_ALPHA);
}
else {
glDisable(GL_BLEND);
GLStateStack::set_blend(GPU_BLEND_NONE);
}
}
void GPU_blend_set_func(eGPUBlendFunction sfactor, eGPUBlendFunction dfactor)
{
glBlendFunc(gpu_get_gl_blendfunction(sfactor), gpu_get_gl_blendfunction(dfactor));
if (sfactor == GPU_ONE && dfactor == GPU_ONE) {
GLStateStack::set_blend(GPU_BLEND_ADDITIVE);
}
else if (sfactor == GPU_ONE && dfactor == GPU_ONE_MINUS_SRC_ALPHA) {
GLStateStack::set_blend(GPU_BLEND_ALPHA_PREMULT);
}
else if (sfactor == GPU_SRC_ALPHA && dfactor == GPU_ONE_MINUS_SRC_ALPHA) {
GLStateStack::set_blend(GPU_BLEND_ALPHA);
}
else if (sfactor == GPU_DST_COLOR && dfactor == GPU_ZERO) {
GLStateStack::set_blend(GPU_BLEND_MULTIPLY);
}
else {
BLI_assert(0);
}
}
void GPU_blend_set_func_separate(eGPUBlendFunction src_rgb,

View File

@ -577,8 +577,8 @@ void wm_draw_region_blend(ARegion *region, int view, bool blend)
if (blend) {
/* GL_ONE because regions drawn offscreen have premultiplied alpha. */
GPU_blend_set_func(GPU_ONE, GPU_ONE_MINUS_SRC_ALPHA);
GPU_blend(true);
GPU_blend_set_func(GPU_ONE, GPU_ONE_MINUS_SRC_ALPHA);
}
/* setup actual texture */
@ -603,7 +603,6 @@ void wm_draw_region_blend(ARegion *region, int view, bool blend)
GPU_texture_unbind(texture);
if (blend) {
GPU_blend_set_func(GPU_SRC_ALPHA, GPU_ONE_MINUS_SRC_ALPHA);
GPU_blend(false);
}
}

View File

@ -370,7 +370,6 @@ static void draw_filled_lasso(wmGesture *gt)
MEM_freeN(pixel_buf);
GPU_blend(false);
GPU_blend_set_func(GPU_SRC_ALPHA, GPU_ONE_MINUS_SRC_ALPHA);
}
MEM_freeN(mcoords);

View File

@ -350,8 +350,6 @@ void WM_init(bContext *C, int argc, const char **argv)
BKE_material_copybuf_clear();
ED_render_clear_mtex_copybuf();
// GPU_blend_set_func(GPU_SRC_ALPHA, GPU_ONE_MINUS_SRC_ALPHA, GPU_ONE, GPU_ONE_MINUS_SRC_ALPHA);
wm_history_file_read();
/* allow a path of "", this is what happens when making a new file */