diff options
author | Jeroen Bakker <jeroen@blender.org> | 2022-01-17 16:45:22 +0300 |
---|---|---|
committer | Jeroen Bakker <jeroen@blender.org> | 2022-01-17 16:46:32 +0300 |
commit | 9d3f35a0bf1bf5776363bfd61d53a7c85b5827a4 (patch) | |
tree | 595fe492f09aea9f97049339385f7966ac02f0e1 /source/blender/gpu/intern/gpu_shader_interface.hh | |
parent | edee5a947b7ea3e1324aa334a22c7c9bbf47f5f7 (diff) |
Revert "Revert "GPUShaderCreateInfo for interface abstraction""
This reverts commit edee5a947b7ea3e1324aa334a22c7c9bbf47f5f7.
Fixes compilation error (Missing file BLI_float2.hh)
Diffstat (limited to 'source/blender/gpu/intern/gpu_shader_interface.hh')
-rw-r--r-- | source/blender/gpu/intern/gpu_shader_interface.hh | 26 |
1 files changed, 24 insertions, 2 deletions
diff --git a/source/blender/gpu/intern/gpu_shader_interface.hh b/source/blender/gpu/intern/gpu_shader_interface.hh index 4bd8f245e2b..735b8fea71d 100644 --- a/source/blender/gpu/intern/gpu_shader_interface.hh +++ b/source/blender/gpu/intern/gpu_shader_interface.hh @@ -34,6 +34,7 @@ #include "BLI_utildefines.h" #include "GPU_shader.h" +#include "gpu_shader_create_info.hh" namespace blender::gpu { @@ -50,6 +51,7 @@ typedef struct ShaderInput { * Base class which is then specialized for each implementation (GL, VK, ...). */ class ShaderInterface { + friend shader::ShaderCreateInfo; /* TODO(fclem): should be protected. */ public: /** Flat array. In this order: Attributes, Ubos, Uniforms. */ @@ -72,6 +74,7 @@ class ShaderInterface { public: ShaderInterface(); + ShaderInterface(const shader::ShaderCreateInfo &info); virtual ~ShaderInterface(); void debug_print(); @@ -129,6 +132,10 @@ class ShaderInterface { static inline const char *builtin_uniform_block_name(GPUUniformBlockBuiltin u); inline uint32_t set_input_name(ShaderInput *input, char *name, uint32_t name_len) const; + inline void copy_input_name(ShaderInput *input, + const StringRefNull &name, + char *name_buffer, + uint32_t &name_buffer_offset) const; /** * Finalize interface construction by sorting the #ShaderInputs for faster lookups. @@ -216,8 +223,12 @@ inline uint32_t ShaderInterface::set_input_name(ShaderInput *input, { /* remove "[0]" from array name */ if (name[name_len - 1] == ']') { - name[name_len - 3] = '\0'; - name_len -= 3; + for (; name_len > 1; name_len--) { + if (name[name_len] == '[') { + name[name_len] = '\0'; + break; + } + } } input->name_offset = (uint32_t)(name - name_buffer_); @@ -225,6 +236,17 @@ inline uint32_t ShaderInterface::set_input_name(ShaderInput *input, return name_len + 1; /* include NULL terminator */ } +inline void ShaderInterface::copy_input_name(ShaderInput *input, + const StringRefNull &name, + char *name_buffer, + uint32_t &name_buffer_offset) const +{ + uint32_t name_len = name.size(); + /* Copy include NULL terminator. */ + memcpy(name_buffer + name_buffer_offset, name.c_str(), name_len + 1); + name_buffer_offset += set_input_name(input, name_buffer + name_buffer_offset, name_len); +} + inline const ShaderInput *ShaderInterface::input_lookup(const ShaderInput *const inputs, const uint inputs_len, const char *name) const |