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.
This commit is contained in:
@@ -299,6 +299,11 @@ void GPU_texture_filter_mode(GPUTexture *tex, bool use_filter);
|
||||
void GPU_texture_mipmap_mode(GPUTexture *tex, bool use_mipmap, bool use_filter);
|
||||
void GPU_texture_wrap_mode(GPUTexture *tex, bool use_repeat, bool use_clamp);
|
||||
void GPU_texture_swizzle_set(GPUTexture *tex, const char swizzle[4]);
|
||||
/**
|
||||
* Set depth stencil texture sampling behavior. Can work on texture views.
|
||||
* If stencil sampling is enabled, an unsigned integer sampler is required.
|
||||
*/
|
||||
void GPU_texture_stencil_texture_mode_set(GPUTexture *tex, bool use_stencil);
|
||||
|
||||
/**
|
||||
* Return the number of dimensions of the texture ignoring dimension of layers (1, 2 or 3).
|
||||
|
||||
@@ -550,6 +550,12 @@ void GPU_texture_swizzle_set(GPUTexture *tex, const char swizzle[4])
|
||||
reinterpret_cast<Texture *>(tex)->swizzle_set(swizzle);
|
||||
}
|
||||
|
||||
void GPU_texture_stencil_texture_mode_set(GPUTexture *tex, bool use_stencil)
|
||||
{
|
||||
BLI_assert(GPU_texture_stencil(tex) || !use_stencil);
|
||||
reinterpret_cast<Texture *>(tex)->stencil_texture_mode_set(use_stencil);
|
||||
}
|
||||
|
||||
void GPU_texture_free(GPUTexture *tex_)
|
||||
{
|
||||
Texture *tex = reinterpret_cast<Texture *>(tex_);
|
||||
|
||||
@@ -117,6 +117,7 @@ class Texture {
|
||||
virtual void copy_to(Texture *tex) = 0;
|
||||
virtual void clear(eGPUDataFormat format, const void *data) = 0;
|
||||
virtual void swizzle_set(const char swizzle_mask[4]) = 0;
|
||||
virtual void stencil_texture_mode_set(bool use_stencil) = 0;
|
||||
virtual void mip_range_set(int min, int max) = 0;
|
||||
virtual void *read(int mip, eGPUDataFormat format) = 0;
|
||||
|
||||
|
||||
@@ -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;
|
||||
|
||||
@@ -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;
|
||||
|
||||
@@ -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_);
|
||||
|
||||
@@ -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;
|
||||
|
||||
|
||||
Reference in New Issue
Block a user