From 93bf17d9521025fe849bf705773de7bacc1dc01d Mon Sep 17 00:00:00 2001 From: =?UTF-8?q?Cl=C3=A9ment=20Foucault?= Date: Wed, 16 Mar 2022 08:36:42 +0100 Subject: GPU: Add support for stencil buffer texturing mode. This adds the possibility to read the stencil buffer inside shaders. This is only available on GL 4.3 so use it accordingly. --- source/blender/gpu/opengl/gl_backend.cc | 2 ++ source/blender/gpu/opengl/gl_context.hh | 1 + source/blender/gpu/opengl/gl_texture.cc | 13 +++++++++++++ source/blender/gpu/opengl/gl_texture.hh | 1 + 4 files changed, 17 insertions(+) (limited to 'source/blender/gpu/opengl') diff --git a/source/blender/gpu/opengl/gl_backend.cc b/source/blender/gpu/opengl/gl_backend.cc index fe730ba3c05..883f9403920 100644 --- a/source/blender/gpu/opengl/gl_backend.cc +++ b/source/blender/gpu/opengl/gl_backend.cc @@ -444,6 +444,7 @@ bool GLContext::native_barycentric_support = false; bool GLContext::multi_bind_support = false; bool GLContext::multi_draw_indirect_support = false; bool GLContext::shader_draw_parameters_support = false; +bool GLContext::stencil_texturing_support = false; bool GLContext::texture_cube_map_array_support = false; bool GLContext::texture_filter_anisotropic_support = false; bool GLContext::texture_gather_support = false; @@ -511,6 +512,7 @@ void GLBackend::capabilities_init() GLContext::multi_bind_support = GLEW_ARB_multi_bind; GLContext::multi_draw_indirect_support = GLEW_ARB_multi_draw_indirect; GLContext::shader_draw_parameters_support = GLEW_ARB_shader_draw_parameters; + GLContext::stencil_texturing_support = GLEW_VERSION_4_3; GLContext::texture_cube_map_array_support = GLEW_ARB_texture_cube_map_array; GLContext::texture_filter_anisotropic_support = GLEW_EXT_texture_filter_anisotropic; GLContext::texture_gather_support = GLEW_ARB_texture_gather; diff --git a/source/blender/gpu/opengl/gl_context.hh b/source/blender/gpu/opengl/gl_context.hh index 54ef1b69e22..c333c8a4afd 100644 --- a/source/blender/gpu/opengl/gl_context.hh +++ b/source/blender/gpu/opengl/gl_context.hh @@ -63,6 +63,7 @@ class GLContext : public Context { static bool multi_bind_support; static bool multi_draw_indirect_support; static bool shader_draw_parameters_support; + static bool stencil_texturing_support; static bool texture_cube_map_array_support; static bool texture_filter_anisotropic_support; static bool texture_gather_support; diff --git a/source/blender/gpu/opengl/gl_texture.cc b/source/blender/gpu/opengl/gl_texture.cc index 9d070088802..4ab9360daaa 100644 --- a/source/blender/gpu/opengl/gl_texture.cc +++ b/source/blender/gpu/opengl/gl_texture.cc @@ -453,6 +453,19 @@ void GLTexture::swizzle_set(const char swizzle[4]) } } +void GLTexture::stencil_texture_mode_set(bool use_stencil) +{ + BLI_assert(GLContext::stencil_texturing_support); + GLint value = use_stencil ? GL_STENCIL_INDEX : GL_DEPTH_COMPONENT; + if (GLContext::direct_state_access_support) { + glTextureParameteri(tex_id_, GL_DEPTH_STENCIL_TEXTURE_MODE, value); + } + else { + GLContext::state_manager_active_get()->texture_bind_temp(this); + glTexParameteri(target_, GL_DEPTH_STENCIL_TEXTURE_MODE, value); + } +} + void GLTexture::mip_range_set(int min, int max) { BLI_assert(min <= max && min >= 0 && max <= mipmaps_); diff --git a/source/blender/gpu/opengl/gl_texture.hh b/source/blender/gpu/opengl/gl_texture.hh index d4d024f5e3e..2dde8d6c86b 100644 --- a/source/blender/gpu/opengl/gl_texture.hh +++ b/source/blender/gpu/opengl/gl_texture.hh @@ -57,6 +57,7 @@ class GLTexture : public Texture { void copy_to(Texture *dst) override; void clear(eGPUDataFormat format, const void *data) override; void swizzle_set(const char swizzle_mask[4]) override; + void stencil_texture_mode_set(bool use_stencil) override; void mip_range_set(int min, int max) override; void *read(int mip, eGPUDataFormat type) override; -- cgit v1.2.3