From c255be2d02393d538be1ef0dbf2cc1f7279e57ed Mon Sep 17 00:00:00 2001 From: =?UTF-8?q?Cl=C3=A9ment=20Foucault?= Date: Sun, 13 Nov 2022 16:47:43 +0100 Subject: DRW: Manager: Add `bind_texture` command for vertex buffer This allows the same behavior as with `DRW_shgroup_buffer_texture`. --- source/blender/draw/intern/draw_command.cc | 6 ++++++ source/blender/draw/intern/draw_command.hh | 7 +++++++ source/blender/draw/intern/draw_pass.hh | 24 ++++++++++++++++++++++++ 3 files changed, 37 insertions(+) diff --git a/source/blender/draw/intern/draw_command.cc b/source/blender/draw/intern/draw_command.cc index 3ef33f13c4a..7a053933cc1 100644 --- a/source/blender/draw/intern/draw_command.cc +++ b/source/blender/draw/intern/draw_command.cc @@ -44,6 +44,9 @@ void ResourceBind::execute() const case ResourceBind::Type::Sampler: GPU_texture_bind_ex(is_reference ? *texture_ref : texture, sampler, slot, false); break; + case ResourceBind::Type::BufferSampler: + GPU_vertbuf_bind_as_texture(is_reference ? *vertex_buf_ref : vertex_buf, slot); + break; case ResourceBind::Type::Image: GPU_texture_image_bind(is_reference ? *texture_ref : texture, slot); break; @@ -251,6 +254,9 @@ std::string ResourceBind::serialize() const return std::string(".bind_texture") + (is_reference ? "_ref" : "") + "(" + std::to_string(slot) + (sampler != GPU_SAMPLER_MAX ? ", sampler=" + std::to_string(sampler) : "") + ")"; + case Type::BufferSampler: + return std::string(".bind_vertbuf_as_texture") + (is_reference ? "_ref" : "") + "(" + + std::to_string(slot) + ")"; case Type::Image: return std::string(".bind_image") + (is_reference ? "_ref" : "") + "(" + std::to_string(slot) + ")"; diff --git a/source/blender/draw/intern/draw_command.hh b/source/blender/draw/intern/draw_command.hh index ea92b54d2ec..bbbc63e4c9c 100644 --- a/source/blender/draw/intern/draw_command.hh +++ b/source/blender/draw/intern/draw_command.hh @@ -134,6 +134,7 @@ struct ResourceBind { enum class Type : uint8_t { Sampler = 0, + BufferSampler, Image, UniformBuf, StorageBuf, @@ -149,6 +150,8 @@ struct ResourceBind { /** NOTE: Texture is used for both Sampler and Image binds. */ GPUTexture *texture; GPUTexture **texture_ref; + GPUVertBuf *vertex_buf; + GPUVertBuf **vertex_buf_ref; }; ResourceBind() = default; @@ -169,6 +172,10 @@ struct ResourceBind { : sampler(state), slot(slot_), is_reference(false), type(Type::Sampler), texture(res){}; ResourceBind(int slot_, GPUTexture **res, eGPUSamplerState state) : sampler(state), slot(slot_), is_reference(true), type(Type::Sampler), texture_ref(res){}; + ResourceBind(int slot_, GPUVertBuf *res) + : slot(slot_), is_reference(false), type(Type::BufferSampler), vertex_buf(res){}; + ResourceBind(int slot_, GPUVertBuf **res) + : slot(slot_), is_reference(true), type(Type::BufferSampler), vertex_buf_ref(res){}; void execute() const; std::string serialize() const; diff --git a/source/blender/draw/intern/draw_pass.hh b/source/blender/draw/intern/draw_pass.hh index a9c1d776091..10cc03bdf11 100644 --- a/source/blender/draw/intern/draw_pass.hh +++ b/source/blender/draw/intern/draw_pass.hh @@ -279,8 +279,12 @@ class PassBase { void bind_image(int slot, GPUTexture **image); void bind_texture(const char *name, GPUTexture *texture, eGPUSamplerState state = sampler_auto); void bind_texture(const char *name, GPUTexture **texture, eGPUSamplerState state = sampler_auto); + void bind_texture(const char *name, GPUVertBuf *buffer); + void bind_texture(const char *name, GPUVertBuf **buffer); void bind_texture(int slot, GPUTexture *texture, eGPUSamplerState state = sampler_auto); void bind_texture(int slot, GPUTexture **texture, eGPUSamplerState state = sampler_auto); + void bind_texture(int slot, GPUVertBuf *buffer); + void bind_texture(int slot, GPUVertBuf **buffer); void bind_ssbo(const char *name, GPUStorageBuf *buffer); void bind_ssbo(const char *name, GPUStorageBuf **buffer); void bind_ssbo(int slot, GPUStorageBuf *buffer); @@ -849,6 +853,16 @@ inline void PassBase::bind_texture(const char *name, this->bind_texture(GPU_shader_get_texture_binding(shader_, name), texture, state); } +template inline void PassBase::bind_texture(const char *name, GPUVertBuf *buffer) +{ + this->bind_texture(GPU_shader_get_texture_binding(shader_, name), buffer); +} + +template inline void PassBase::bind_texture(const char *name, GPUVertBuf **buffer) +{ + this->bind_texture(GPU_shader_get_texture_binding(shader_, name), buffer); +} + template inline void PassBase::bind_image(const char *name, GPUTexture *image) { this->bind_image(GPU_shader_get_texture_binding(shader_, name), image); @@ -870,6 +884,16 @@ inline void PassBase::bind_texture(int slot, GPUTexture *texture, eGPUSampler create_command(Type::ResourceBind).resource_bind = {slot, texture, state}; } +template inline void PassBase::bind_texture(int slot, GPUVertBuf *buffer) +{ + create_command(Type::ResourceBind).resource_bind = {slot, buffer}; +} + +template inline void PassBase::bind_texture(int slot, GPUVertBuf **buffer) +{ + create_command(Type::ResourceBind).resource_bind = {slot, buffer}; +} + template inline void PassBase::bind_image(int slot, GPUTexture *image) { create_command(Type::ResourceBind).resource_bind = {slot, as_image(image)}; -- cgit v1.2.3