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:
Diffstat (limited to 'source/blender/gpu/opengl')
-rw-r--r--source/blender/gpu/opengl/gl_shader.cc18
-rw-r--r--source/blender/gpu/opengl/gl_shader_interface.cc37
-rw-r--r--source/blender/gpu/opengl/gl_shader_interface.hh3
3 files changed, 53 insertions, 5 deletions
diff --git a/source/blender/gpu/opengl/gl_shader.cc b/source/blender/gpu/opengl/gl_shader.cc
index 66a1bd5ceb7..63ba0ab0a34 100644
--- a/source/blender/gpu/opengl/gl_shader.cc
+++ b/source/blender/gpu/opengl/gl_shader.cc
@@ -225,8 +225,10 @@ bool GLShader::finalize()
this->print_log(sources, log, "Linking", true, &parser);
return false;
}
-
- interface = new GLShaderInterface(shader_program_);
+ const UniformBuiltinStructType *type_info = m_shader_struct != nullptr ?
+ &m_shader_struct->type_info() :
+ nullptr;
+ interface = new GLShaderInterface(type_info, shader_program_);
return true;
}
@@ -308,6 +310,12 @@ void GLShader::transform_feedback_disable()
void GLShader::uniform_float(int location, int comp_len, int array_size, const float *data)
{
+ if (m_shader_struct) {
+ if (m_shader_struct->uniform_float(location, comp_len, array_size, data)) {
+ return;
+ }
+ }
+
switch (comp_len) {
case 1:
glUniform1fv(location, array_size, data);
@@ -335,6 +343,12 @@ void GLShader::uniform_float(int location, int comp_len, int array_size, const f
void GLShader::uniform_int(int location, int comp_len, int array_size, const int *data)
{
+ if (m_shader_struct) {
+ if (m_shader_struct->uniform_int(location, comp_len, array_size, data)) {
+ return;
+ }
+ }
+
switch (comp_len) {
case 1:
glUniform1iv(location, array_size, data);
diff --git a/source/blender/gpu/opengl/gl_shader_interface.cc b/source/blender/gpu/opengl/gl_shader_interface.cc
index 9cf072b2e8a..d9291cd642a 100644
--- a/source/blender/gpu/opengl/gl_shader_interface.cc
+++ b/source/blender/gpu/opengl/gl_shader_interface.cc
@@ -145,7 +145,7 @@ static inline int ssbo_binding(int32_t program, uint32_t ssbo_index)
/** \name Creation / Destruction
* \{ */
-GLShaderInterface::GLShaderInterface(GLuint program)
+GLShaderInterface::GLShaderInterface(const UniformBuiltinStructType *type_info, GLuint program)
{
/* Necessary to make #glUniform works. */
glUseProgram(program);
@@ -187,6 +187,20 @@ GLShaderInterface::GLShaderInterface(GLuint program)
max_ssbo_name_len = 256;
}
+ /* Perform uniform builtin structs after work around to make sure the work around is passed. */
+ if (type_info) {
+ for (int i = 0; i < GPU_NUM_UNIFORMS; i++) {
+ const GPUUniformBuiltin builtin_uniform = static_cast<const GPUUniformBuiltin>(i);
+ const UniformBuiltinStructType::AttributeBinding &binding = type_info->attribute_binding(
+ builtin_uniform);
+ if (binding.has_binding()) {
+ uniform_len++;
+ max_uniform_name_len = max_ii(max_uniform_name_len,
+ strlen(builtin_uniform_name(builtin_uniform)));
+ }
+ }
+ }
+
/* GL_ACTIVE_UNIFORMS lied to us! Remove the UBO uniforms from the total before
* allocating the uniform array. */
GLint max_ubo_uni_len = 0;
@@ -281,6 +295,24 @@ GLShaderInterface::GLShaderInterface(GLuint program)
enabled_ima_mask_ |= (input->binding != -1) ? (1lu << input->binding) : 0lu;
}
}
+ if (type_info) {
+ for (int i = 0; i < GPU_NUM_UNIFORMS; i++) {
+ const GPUUniformBuiltin builtin_uniform = static_cast<const GPUUniformBuiltin>(i);
+ const UniformBuiltinStructType::AttributeBinding &binding = type_info->attribute_binding(
+ builtin_uniform);
+ if (binding.has_binding()) {
+ ShaderInput *input = &inputs_[attr_len_ + ubo_len_ + uniform_len_++];
+ input->location = binding.binding;
+ input->binding = -1;
+
+ char *name = name_buffer_ + name_buffer_offset;
+ const char *uniform_name = builtin_uniform_name(builtin_uniform);
+ size_t name_len = strlen(uniform_name);
+ strcpy(name, uniform_name);
+ name_buffer_offset += this->set_input_name(input, name, name_len);
+ }
+ }
+ }
/* SSBOs */
for (int i = 0; i < ssbo_len; i++) {
@@ -301,7 +333,8 @@ GLShaderInterface::GLShaderInterface(GLuint program)
/* Builtin Uniforms */
for (int32_t u_int = 0; u_int < GPU_NUM_UNIFORMS; u_int++) {
GPUUniformBuiltin u = static_cast<GPUUniformBuiltin>(u_int);
- builtins_[u] = glGetUniformLocation(program, builtin_uniform_name(u));
+ const ShaderInput *block = this->uniform_get(builtin_uniform_name(u));
+ builtins_[u] = (block != nullptr) ? block->binding : -1;
}
/* Builtin Uniforms Blocks */
diff --git a/source/blender/gpu/opengl/gl_shader_interface.hh b/source/blender/gpu/opengl/gl_shader_interface.hh
index 89a5b631047..5125c885cc5 100644
--- a/source/blender/gpu/opengl/gl_shader_interface.hh
+++ b/source/blender/gpu/opengl/gl_shader_interface.hh
@@ -35,6 +35,7 @@
#include "glew-mx.h"
#include "gpu_shader_interface.hh"
+#include "gpu_uniform_buffer_private.hh"
namespace blender::gpu {
@@ -49,7 +50,7 @@ class GLShaderInterface : public ShaderInterface {
Vector<GLVaoCache *> refs_;
public:
- GLShaderInterface(GLuint program);
+ GLShaderInterface(const UniformBuiltinStructType *type_info, GLuint program);
~GLShaderInterface();
void ref_add(GLVaoCache *ref);