Welcome to mirror list, hosted at ThFree Co, Russian Federation.

git.blender.org/blender.git - Unnamed repository; edit this file 'description' to name the repository.
summaryrefslogtreecommitdiff
diff options
context:
space:
mode:
authorClément Foucault <foucault.clem@gmail.com>2022-03-16 10:36:42 +0300
committerClément Foucault <foucault.clem@gmail.com>2022-03-18 22:54:42 +0300
commit93bf17d9521025fe849bf705773de7bacc1dc01d (patch)
treeb453ac58905391133b423902fbdde609ec81ab14 /source/blender/gpu/opengl
parent054957659f671910e1967fec83768affbbff060c (diff)
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.
Diffstat (limited to 'source/blender/gpu/opengl')
-rw-r--r--source/blender/gpu/opengl/gl_backend.cc2
-rw-r--r--source/blender/gpu/opengl/gl_context.hh1
-rw-r--r--source/blender/gpu/opengl/gl_texture.cc13
-rw-r--r--source/blender/gpu/opengl/gl_texture.hh1
4 files changed, 17 insertions, 0 deletions
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;