diff options
author | Clément Foucault <foucault.clem@gmail.com> | 2020-08-17 19:11:09 +0300 |
---|---|---|
committer | Clément Foucault <foucault.clem@gmail.com> | 2020-08-18 22:30:10 +0300 |
commit | a9f2ebb215084debae70099b3d2e58195d9a9e32 (patch) | |
tree | 839b142dc49f8d6727a4d6e076a6227ea2e573d2 /source/blender/gpu | |
parent | 536c2e0ec916eb49c534b4937b36da278dbe2364 (diff) |
Cleanup: DRW: Use GPUState instead of raw opengl calls
Should not break anything! Huh!
Diffstat (limited to 'source/blender/gpu')
-rw-r--r-- | source/blender/gpu/GPU_state.h | 13 | ||||
-rw-r--r-- | source/blender/gpu/intern/gpu_state.cc | 37 | ||||
-rw-r--r-- | source/blender/gpu/opengl/gl_state.cc | 7 |
3 files changed, 57 insertions, 0 deletions
diff --git a/source/blender/gpu/GPU_state.h b/source/blender/gpu/GPU_state.h index 1e2b772224c..14617eeb614 100644 --- a/source/blender/gpu/GPU_state.h +++ b/source/blender/gpu/GPU_state.h @@ -23,6 +23,7 @@ #include "BLI_utildefines.h" typedef enum eGPUWriteMask { + GPU_WRITE_NONE = 0, GPU_WRITE_RED = (1 << 0), GPU_WRITE_GREEN = (1 << 1), GPU_WRITE_BLUE = (1 << 2), @@ -133,8 +134,20 @@ void GPU_color_mask(bool r, bool g, bool b, bool a); void GPU_depth_mask(bool depth); bool GPU_depth_mask_get(void); void GPU_unpack_row_length_set(uint len); +void GPU_shadow_offset(bool enable); void GPU_clip_distances(int enabled_len); bool GPU_mipmap_enabled(void); +void GPU_state_set(eGPUWriteMask write_mask, + eGPUBlend blend, + eGPUFaceCullTest culling_test, + eGPUDepthTest depth_test, + eGPUStencilTest stencil_test, + eGPUStencilOp stencil_op, + eGPUProvokingVertex provoking_vert); + +void GPU_stencil_reference_set(uint reference); +void GPU_stencil_write_mask_set(uint write_mask); +void GPU_stencil_compare_mask_set(uint compare_mask); eGPUBlend GPU_blend_get(void); eGPUWriteMask GPU_write_mask_get(void); diff --git a/source/blender/gpu/intern/gpu_state.cc b/source/blender/gpu/intern/gpu_state.cc index 039bce1f0ac..619f52da852 100644 --- a/source/blender/gpu/intern/gpu_state.cc +++ b/source/blender/gpu/intern/gpu_state.cc @@ -121,11 +121,35 @@ void GPU_depth_mask(bool depth) state.write_mask = write_mask; } +void GPU_shadow_offset(bool enable) +{ + SET_IMMUTABLE_STATE(shadow_bias, enable); +} + void GPU_clip_distances(int distances_enabled) { SET_IMMUTABLE_STATE(clip_distances, distances_enabled); } +void GPU_state_set(eGPUWriteMask write_mask, + eGPUBlend blend, + eGPUFaceCullTest culling_test, + eGPUDepthTest depth_test, + eGPUStencilTest stencil_test, + eGPUStencilOp stencil_op, + eGPUProvokingVertex provoking_vert) +{ + GPUStateManager *stack = GPU_context_active_get()->state_manager; + auto &state = stack->state; + state.write_mask = write_mask; + state.blend = blend; + state.culling_test = culling_test; + state.depth_test = depth_test; + state.stencil_test = stencil_test; + state.stencil_op = stencil_op; + state.provoking_vert = provoking_vert; +} + /** \} */ /* -------------------------------------------------------------------- */ @@ -185,6 +209,19 @@ void GPU_viewport(int x, int y, int width, int height) copy_v4_v4_int(state.viewport_rect, viewport_rect); } +void GPU_stencil_reference_set(uint reference) +{ + SET_MUTABLE_STATE(stencil_reference, (uint8_t)reference); +} +void GPU_stencil_write_mask_set(uint write_mask) +{ + SET_MUTABLE_STATE(stencil_write_mask, (uint8_t)write_mask); +} +void GPU_stencil_compare_mask_set(uint compare_mask) +{ + SET_MUTABLE_STATE(stencil_compare_mask, (uint8_t)compare_mask); +} + /** \} */ /* -------------------------------------------------------------------- */ diff --git a/source/blender/gpu/opengl/gl_state.cc b/source/blender/gpu/opengl/gl_state.cc index 5274a86ebe5..f85fb804317 100644 --- a/source/blender/gpu/opengl/gl_state.cc +++ b/source/blender/gpu/opengl/gl_state.cc @@ -153,6 +153,13 @@ void GLStateManager::set_write_mask(const eGPUWriteMask value) (value & GPU_WRITE_GREEN) != 0, (value & GPU_WRITE_BLUE) != 0, (value & GPU_WRITE_ALPHA) != 0); + + if (value == GPU_WRITE_NONE) { + glEnable(GL_RASTERIZER_DISCARD); + } + else { + glDisable(GL_RASTERIZER_DISCARD); + } } void GLStateManager::set_depth_test(const eGPUDepthTest value) |