[Bf-blender-cvs] [a9f2ebb2150] master: Cleanup: DRW: Use GPUState instead of raw opengl calls
Clément Foucault
noreply at git.blender.org
Tue Aug 18 21:31:01 CEST 2020
Commit: a9f2ebb215084debae70099b3d2e58195d9a9e32
Author: Clément Foucault
Date: Mon Aug 17 18:11:09 2020 +0200
Branches: master
https://developer.blender.org/rBa9f2ebb215084debae70099b3d2e58195d9a9e32
Cleanup: DRW: Use GPUState instead of raw opengl calls
Should not break anything! Huh!
===================================================================
M source/blender/draw/intern/DRW_render.h
M source/blender/draw/intern/draw_manager_exec.c
M source/blender/gpu/GPU_state.h
M source/blender/gpu/intern/gpu_state.cc
M source/blender/gpu/opengl/gl_state.cc
===================================================================
diff --git a/source/blender/draw/intern/DRW_render.h b/source/blender/draw/intern/DRW_render.h
index 134fdc0ba7c..63625fae185 100644
--- a/source/blender/draw/intern/DRW_render.h
+++ b/source/blender/draw/intern/DRW_render.h
@@ -361,6 +361,10 @@ typedef enum {
#define DRW_STATE_DEFAULT \
(DRW_STATE_WRITE_DEPTH | DRW_STATE_WRITE_COLOR | DRW_STATE_DEPTH_LESS_EQUAL)
+#define DRW_STATE_BLEND_ENABLED \
+ (DRW_STATE_BLEND_ADD | DRW_STATE_BLEND_ADD_FULL | DRW_STATE_BLEND_ALPHA | \
+ DRW_STATE_BLEND_ALPHA_PREMUL | DRW_STATE_BLEND_BACKGROUND | DRW_STATE_BLEND_OIT | \
+ DRW_STATE_BLEND_MUL | DRW_STATE_BLEND_SUB | DRW_STATE_BLEND_CUSTOM | DRW_STATE_LOGIC_INVERT)
#define DRW_STATE_RASTERIZER_ENABLED \
(DRW_STATE_WRITE_DEPTH | DRW_STATE_WRITE_COLOR | DRW_STATE_WRITE_STENCIL | \
DRW_STATE_WRITE_STENCIL_SHADOW_PASS | DRW_STATE_WRITE_STENCIL_SHADOW_FAIL)
diff --git a/source/blender/draw/intern/draw_manager_exec.c b/source/blender/draw/intern/draw_manager_exec.c
index b23bcd97f41..f08c3231e8c 100644
--- a/source/blender/draw/intern/draw_manager_exec.c
+++ b/source/blender/draw/intern/draw_manager_exec.c
@@ -32,6 +32,7 @@
#include "GPU_extensions.h"
#include "GPU_platform.h"
#include "GPU_shader.h"
+#include "GPU_state.h"
#ifdef USE_GPU_SELECT
# include "GPU_select.h"
@@ -81,309 +82,166 @@ void drw_state_set(DRWState state)
return;
}
-#define CHANGED_TO(f) \
- ((DST.state_lock & (f)) ? \
- 0 : \
- (((DST.state & (f)) ? ((state & (f)) ? 0 : -1) : ((state & (f)) ? 1 : 0))))
+ eGPUWriteMask write_mask = 0;
+ eGPUBlend blend = 0;
+ eGPUFaceCullTest culling_test = 0;
+ eGPUDepthTest depth_test = 0;
+ eGPUStencilTest stencil_test = 0;
+ eGPUStencilOp stencil_op = 0;
+ eGPUProvokingVertex provoking_vert = 0;
-#define CHANGED_ANY(f) (((DST.state & (f)) != (state & (f))) && ((DST.state_lock & (f)) == 0))
-
-#define CHANGED_ANY_STORE_VAR(f, enabled) \
- (((DST.state & (f)) != (enabled = (state & (f)))) && (((DST.state_lock & (f)) == 0)))
-
- /* Depth Write */
- {
- int test;
- if ((test = CHANGED_TO(DRW_STATE_WRITE_DEPTH))) {
- GPU_depth_mask(test == 1);
- }
+ if (state & DRW_STATE_WRITE_DEPTH) {
+ write_mask |= GPU_WRITE_DEPTH;
}
-
- /* Stencil Write */
- {
- DRWState test;
- if (CHANGED_ANY_STORE_VAR(DRW_STATE_WRITE_STENCIL_ENABLED, test)) {
- /* Stencil Write */
- if (test) {
- glStencilMask(0xFF);
- switch (test) {
- case DRW_STATE_WRITE_STENCIL:
- glStencilOp(GL_KEEP, GL_KEEP, GL_REPLACE);
- break;
- case DRW_STATE_WRITE_STENCIL_SHADOW_PASS:
- glStencilOpSeparate(GL_BACK, GL_KEEP, GL_KEEP, GL_INCR_WRAP);
- glStencilOpSeparate(GL_FRONT, GL_KEEP, GL_KEEP, GL_DECR_WRAP);
- break;
- case DRW_STATE_WRITE_STENCIL_SHADOW_FAIL:
- glStencilOpSeparate(GL_BACK, GL_KEEP, GL_DECR_WRAP, GL_KEEP);
- glStencilOpSeparate(GL_FRONT, GL_KEEP, GL_INCR_WRAP, GL_KEEP);
- break;
- default:
- BLI_assert(0);
- }
- }
- else {
- glStencilMask(0x00);
- glStencilOp(GL_KEEP, GL_KEEP, GL_KEEP);
- }
- }
+ if (state & DRW_STATE_WRITE_COLOR) {
+ write_mask |= GPU_WRITE_COLOR;
}
- /* Color Write */
- {
- int test;
- if ((test = CHANGED_TO(DRW_STATE_WRITE_COLOR))) {
- if (test == 1) {
- GPU_color_mask(true, true, true, true);
- }
- else {
- GPU_color_mask(false, false, false, false);
- }
- }
+ switch (state & (DRW_STATE_CULL_BACK | DRW_STATE_CULL_FRONT)) {
+ case DRW_STATE_CULL_BACK:
+ culling_test = GPU_CULL_BACK;
+ break;
+ case DRW_STATE_CULL_FRONT:
+ culling_test = GPU_CULL_FRONT;
+ break;
+ default:
+ culling_test = GPU_CULL_NONE;
+ break;
}
- /* Raster Discard */
- {
- if (CHANGED_ANY(DRW_STATE_RASTERIZER_ENABLED)) {
- if ((state & DRW_STATE_RASTERIZER_ENABLED) != 0) {
- glDisable(GL_RASTERIZER_DISCARD);
- }
- else {
- glEnable(GL_RASTERIZER_DISCARD);
- }
- }
+ switch (state & DRW_STATE_DEPTH_TEST_ENABLED) {
+ case DRW_STATE_DEPTH_LESS:
+ depth_test = GPU_DEPTH_LESS;
+ break;
+ case DRW_STATE_DEPTH_LESS_EQUAL:
+ depth_test = GPU_DEPTH_LESS_EQUAL;
+ break;
+ case DRW_STATE_DEPTH_EQUAL:
+ depth_test = GPU_DEPTH_EQUAL;
+ break;
+ case DRW_STATE_DEPTH_GREATER:
+ depth_test = GPU_DEPTH_GREATER;
+ break;
+ case DRW_STATE_DEPTH_GREATER_EQUAL:
+ depth_test = GPU_DEPTH_GREATER_EQUAL;
+ break;
+ case DRW_STATE_DEPTH_ALWAYS:
+ depth_test = GPU_DEPTH_ALWAYS;
+ break;
+ default:
+ depth_test = GPU_DEPTH_NONE;
+ break;
}
- /* Cull */
- {
- DRWState test;
- if (CHANGED_ANY_STORE_VAR(DRW_STATE_CULL_BACK | DRW_STATE_CULL_FRONT, test)) {
- if (test) {
- glEnable(GL_CULL_FACE);
-
- if ((state & DRW_STATE_CULL_BACK) != 0) {
- glCullFace(GL_BACK);
- }
- else if ((state & DRW_STATE_CULL_FRONT) != 0) {
- glCullFace(GL_FRONT);
- }
- else {
- BLI_assert(0);
- }
- }
- else {
- glDisable(GL_CULL_FACE);
- }
- }
+ switch (state & DRW_STATE_WRITE_STENCIL_ENABLED) {
+ case DRW_STATE_WRITE_STENCIL:
+ stencil_op = GPU_STENCIL_OP_REPLACE;
+ break;
+ case DRW_STATE_WRITE_STENCIL_SHADOW_PASS:
+ stencil_op = GPU_STENCIL_OP_COUNT_DEPTH_PASS;
+ break;
+ case DRW_STATE_WRITE_STENCIL_SHADOW_FAIL:
+ stencil_op = GPU_STENCIL_OP_COUNT_DEPTH_FAIL;
+ break;
+ default:
+ stencil_op = GPU_STENCIL_OP_NONE;
+ break;
}
+ GPU_stencil_write_mask_set(0xFF);
- /* Depth Test */
- {
- DRWState test;
- if (CHANGED_ANY_STORE_VAR(DRW_STATE_DEPTH_TEST_ENABLED, test)) {
- if (test) {
- glEnable(GL_DEPTH_TEST);
-
- switch (test) {
- case DRW_STATE_DEPTH_LESS:
- glDepthFunc(GL_LESS);
- break;
- case DRW_STATE_DEPTH_LESS_EQUAL:
- glDepthFunc(GL_LEQUAL);
- break;
- case DRW_STATE_DEPTH_EQUAL:
- glDepthFunc(GL_EQUAL);
- break;
- case DRW_STATE_DEPTH_GREATER:
- glDepthFunc(GL_GREATER);
- break;
- case DRW_STATE_DEPTH_GREATER_EQUAL:
- glDepthFunc(GL_GEQUAL);
- break;
- case DRW_STATE_DEPTH_ALWAYS:
- glDepthFunc(GL_ALWAYS);
- break;
- default:
- BLI_assert(0);
- }
- }
- else {
- glDisable(GL_DEPTH_TEST);
- }
- }
+ switch (state & DRW_STATE_STENCIL_TEST_ENABLED) {
+ case DRW_STATE_STENCIL_ALWAYS:
+ stencil_test = GPU_STENCIL_ALWAYS;
+ break;
+ case DRW_STATE_STENCIL_EQUAL:
+ stencil_test = GPU_STENCIL_EQUAL;
+ break;
+ case DRW_STATE_STENCIL_NEQUAL:
+ stencil_test = GPU_STENCIL_NEQUAL;
+ break;
+ default:
+ stencil_test = GPU_STENCIL_NONE;
+ break;
}
- /* Stencil Test */
- {
- int test;
- if (CHANGED_ANY_STORE_VAR(DRW_STATE_STENCIL_TEST_ENABLED, test)) {
- if (test) {
- glEnable(GL_STENCIL_TEST);
- }
- else {
- glDisable(GL_STENCIL_TEST);
- }
- }
+ switch (state & DRW_STATE_BLEND_ENABLED) {
+ case DRW_STATE_BLEND_ADD:
+ blend = GPU_BLEND_ADDITIVE;
+ break;
+ case DRW_STATE_BLEND_ADD_FULL:
+ blend = GPU_BLEND_ADDITIVE_PREMULT;
+ break;
+ case DRW_STATE_BLEND_ALPHA:
+ blend = GPU_BLEND_ALPHA;
+ break;
+ case DRW_STATE_BLEND_ALPHA_PREMUL:
+ blend = GPU_BLEND_ALPHA_PREMULT;
+ break;
+ case DRW_STATE_BLEND_BACKGROUND:
+ blend = GPU_BLEND_BACKGROUND;
+ break;
+ case DRW_STATE_BLEND_OIT:
+ blend = GPU_BLEND_OIT;
+ break;
+ case DRW_STATE_BLEND_MUL:
+ blend = GPU_BLEND_MULTIPLY;
+ break;
+ case DRW_STATE_BLEND_SUB:
+ blend = GPU_BLEND_SUBTRACT;
+ break;
+ case DRW_STATE_BLEND_CUSTOM:
+ blend = GPU_BLEND_CUSTOM;
+ break;
+ case DRW_STATE_LOGIC_INVERT:
+ blend = GPU_BLEND_INVERT;
+ break;
+ default:
+ blend = GPU_BLEND_NONE;
+ break;
}
- /* Blending (all buffer) */
- {
- int test;
- if (CHANGED_ANY_STORE_VAR(DRW_STATE_BLEND_ALPHA | DRW_STATE_BLEND_ALPHA_PREMUL |
- DRW_STATE_BLEND_ADD | DRW_STATE_BLEND_MUL |
- DRW_STATE_BLEND_ADD_FULL | DRW_STATE_BLEND_OIT |
- DRW_STATE_BLEND_BACKGROUND | DRW_STATE_BLEND_CUSTOM |
- DRW_STATE_LOGIC_INVERT | DRW_STATE_BLEND_SUB,
- test)) {
- if (test) {
- glEnable(GL_BLEND);
-
- switch (test) {
- case DRW_STATE_BLEND_ALPHA:
- glBlendFuncSeparate(GL_SRC_ALPHA,
- GL_ONE_MINUS_SRC_ALPHA, /* RGB */
- GL_ONE,
- GL_ONE_MINUS_SRC_ALPHA); /* Alpha */
- break;
- case DRW_STATE_BLEND_BACKGROUND:
- /* Special blend to add color under and multiply dst by alpha. */
- glBlendFuncSeparate(GL_ONE_MINUS_DST_ALPHA,
- GL_SRC_ALPHA, /* RGB */
- GL_ZERO,
- GL_SRC_ALPHA); /* Alpha */
- break;
- case DRW_STATE_BLEND_ALPHA_PREMUL:
- glBlendFunc(GL_ONE, GL_ONE_MINUS_SRC_ALPHA);
- break;
- case DRW_STATE_BLEND_MUL:
- glBlendFunc(GL_DST_COLOR, GL_ZERO);
- break;
- case DRW_STATE_BLEND_OIT:
- glBlendFuncSeparate(GL_ONE,
- GL_ONE, /* RGB */
- GL_ZERO,
- GL_ONE_MINUS_SRC_ALPHA); /* Alpha */
- break;
- case DRW_STATE_BLEND_ADD:
- /* Do not let alpha accumulate but premult the source RGB by it. */
- glBlendFuncSeparate(GL_SRC_ALPHA,
- GL_ONE, /* RGB */
- GL_ZERO,
-
@@ Diff output truncated at 10240 characters. @@
More information about the Bf-blender-cvs
mailing list