diff options
author | Colin Basnett <cmbasnett@gmail.com> | 2022-09-17 03:50:37 +0300 |
---|---|---|
committer | Colin Basnett <cmbasnett@gmail.com> | 2022-09-17 03:50:37 +0300 |
commit | 564bda241a973396da51d7c3ccd9efd97d51728a (patch) | |
tree | 4d9aa4cccd82e2e606b47774afa5e1015bf14768 /source/blender/gpu/opengl/gl_shader_interface.cc | |
parent | 0fff238150d076576053c25b646f653d6e3b0edb (diff) | |
parent | 48d7ff68f0df209c77bbb081ab46fbc109fd825a (diff) |
Merge branch 'master' into feature-imformatfeature-imformat
Diffstat (limited to 'source/blender/gpu/opengl/gl_shader_interface.cc')
-rw-r--r-- | source/blender/gpu/opengl/gl_shader_interface.cc | 69 |
1 files changed, 68 insertions, 1 deletions
diff --git a/source/blender/gpu/opengl/gl_shader_interface.cc b/source/blender/gpu/opengl/gl_shader_interface.cc index f6a7eee80c3..b230706b020 100644 --- a/source/blender/gpu/opengl/gl_shader_interface.cc +++ b/source/blender/gpu/opengl/gl_shader_interface.cc @@ -9,7 +9,6 @@ #include "BLI_bitmap.h" -#include "gl_backend.hh" #include "gl_batch.hh" #include "gl_context.hh" @@ -17,6 +16,7 @@ #include "GPU_capabilities.h" +using namespace blender::gpu::shader; namespace blender::gpu { /* -------------------------------------------------------------------- */ @@ -152,6 +152,52 @@ static inline int ssbo_binding(int32_t program, uint32_t ssbo_index) /** \name Creation / Destruction * \{ */ +static Type gpu_type_from_gl_type(int gl_type) +{ + switch (gl_type) { + case GL_FLOAT: + return Type::FLOAT; + case GL_FLOAT_VEC2: + return Type::VEC2; + case GL_FLOAT_VEC3: + return Type::VEC3; + case GL_FLOAT_VEC4: + return Type::VEC4; + case GL_FLOAT_MAT3: + return Type::MAT3; + case GL_FLOAT_MAT4: + return Type::MAT4; + case GL_UNSIGNED_INT: + return Type::UINT; + case GL_UNSIGNED_INT_VEC2: + return Type::UVEC2; + case GL_UNSIGNED_INT_VEC3: + return Type::UVEC3; + case GL_UNSIGNED_INT_VEC4: + return Type::UVEC4; + case GL_INT: + return Type::INT; + case GL_INT_VEC2: + return Type::IVEC2; + case GL_INT_VEC3: + return Type::IVEC3; + case GL_INT_VEC4: + return Type::IVEC4; + case GL_BOOL: + return Type::BOOL; + case GL_FLOAT_MAT2: + case GL_FLOAT_MAT2x3: + case GL_FLOAT_MAT2x4: + case GL_FLOAT_MAT3x2: + case GL_FLOAT_MAT3x4: + case GL_FLOAT_MAT4x2: + case GL_FLOAT_MAT4x3: + default: + BLI_assert(0); + } + return Type::FLOAT; +} + GLShaderInterface::GLShaderInterface(GLuint program) { /* Necessary to make #glUniform works. */ @@ -247,6 +293,9 @@ GLShaderInterface::GLShaderInterface(GLuint program) name_buffer_offset += set_input_name(input, name, name_len); enabled_attr_mask_ |= (1 << input->location); + + /* Used in `GPU_shader_get_attribute_info`. */ + attr_types_[input->location] = (uint8_t)gpu_type_from_gl_type(type); } /* Uniform Blocks */ @@ -319,6 +368,13 @@ GLShaderInterface::GLShaderInterface(GLuint program) builtin_blocks_[u] = (block != nullptr) ? block->binding : -1; } + /* Builtin Storage Buffers */ + for (int32_t u_int = 0; u_int < GPU_NUM_STORAGE_BUFFERS; u_int++) { + GPUStorageBufferBuiltin u = static_cast<GPUStorageBufferBuiltin>(u_int); + const ShaderInput *block = this->ssbo_get(builtin_storage_block_name(u)); + builtin_buffers_[u] = (block != nullptr) ? block->binding : -1; + } + MEM_freeN(uniforms_from_blocks); /* Resize name buffer to save some memory. */ @@ -399,7 +455,11 @@ GLShaderInterface::GLShaderInterface(GLuint program, const shader::ShaderCreateI } if (input->location != -1) { enabled_attr_mask_ |= (1 << input->location); + + /* Used in `GPU_shader_get_attribute_info`. */ + attr_types_[input->location] = (uint8_t)attr.type; } + input++; } @@ -482,6 +542,13 @@ GLShaderInterface::GLShaderInterface(GLuint program, const shader::ShaderCreateI builtin_blocks_[u] = (block != nullptr) ? block->binding : -1; } + /* Builtin Storage Buffers */ + for (int32_t u_int = 0; u_int < GPU_NUM_STORAGE_BUFFERS; u_int++) { + GPUStorageBufferBuiltin u = static_cast<GPUStorageBufferBuiltin>(u_int); + const ShaderInput *block = this->ssbo_get(builtin_storage_block_name(u)); + builtin_buffers_[u] = (block != nullptr) ? block->binding : -1; + } + this->sort_inputs(); // this->debug_print(); |