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-11-13 18:47:43 +0300
committerClément Foucault <foucault.clem@gmail.com>2022-11-13 18:47:43 +0300
commitc255be2d02393d538be1ef0dbf2cc1f7279e57ed (patch)
tree9c87e2a409fa72d4b30e29f485dbed15a77fc5ae
parentcd64615425248eaf8dc80653626fe5f2dbb084a2 (diff)
DRW: Manager: Add `bind_texture` command for vertex buffer
This allows the same behavior as with `DRW_shgroup_buffer_texture`.
-rw-r--r--source/blender/draw/intern/draw_command.cc6
-rw-r--r--source/blender/draw/intern/draw_command.hh7
-rw-r--r--source/blender/draw/intern/draw_pass.hh24
3 files changed, 37 insertions, 0 deletions
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<T>::bind_texture(const char *name,
this->bind_texture(GPU_shader_get_texture_binding(shader_, name), texture, state);
}
+template<class T> inline void PassBase<T>::bind_texture(const char *name, GPUVertBuf *buffer)
+{
+ this->bind_texture(GPU_shader_get_texture_binding(shader_, name), buffer);
+}
+
+template<class T> inline void PassBase<T>::bind_texture(const char *name, GPUVertBuf **buffer)
+{
+ this->bind_texture(GPU_shader_get_texture_binding(shader_, name), buffer);
+}
+
template<class T> inline void PassBase<T>::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<T>::bind_texture(int slot, GPUTexture *texture, eGPUSampler
create_command(Type::ResourceBind).resource_bind = {slot, texture, state};
}
+template<class T> inline void PassBase<T>::bind_texture(int slot, GPUVertBuf *buffer)
+{
+ create_command(Type::ResourceBind).resource_bind = {slot, buffer};
+}
+
+template<class T> inline void PassBase<T>::bind_texture(int slot, GPUVertBuf **buffer)
+{
+ create_command(Type::ResourceBind).resource_bind = {slot, buffer};
+}
+
template<class T> inline void PassBase<T>::bind_image(int slot, GPUTexture *image)
{
create_command(Type::ResourceBind).resource_bind = {slot, as_image(image)};