#include <cstring>
-#include <set>
#include <msp/core/algorithm.h>
-#include <msp/core/maputils.h>
-#include <msp/core/raii.h>
#include <msp/gl/extensions/arb_es2_compatibility.h>
#include <msp/gl/extensions/arb_fragment_shader.h>
#include <msp/gl/extensions/arb_gl_spirv.h>
#include <msp/gl/extensions/khr_debug.h>
#include <msp/gl/extensions/nv_non_square_matrices.h>
#include <msp/io/print.h>
-#include "buffer.h"
#include "error.h"
#include "program.h"
-#include "resources.h"
#include "glsl/compiler.h"
using namespace std;
+namespace {
+
+template<typename T, void (*&func)(GLint, GLsizei, const T *)>
+void uniform_wrapper(unsigned index, unsigned count, const void *data)
+{
+ func(index, count, static_cast<const T *>(data));
+}
+
+template<typename T, void (*&func)(GLint, GLsizei, GLboolean, const T *)>
+void uniform_matrix_wrapper(unsigned index, unsigned count, const void *data)
+{
+ func(index, count, false, static_cast<const T *>(data));
+}
+
+}
+
namespace Msp {
namespace GL {
u.matrix_stride = get_type_size(get_matrix_column_type(u.type));
default_block.uniforms.push_back(&u);
- if(is_image(u.type) && u.location>=0)
- glGetUniformiv(id, u.location, &u.binding);
+ if(u.location>=0)
+ {
+ UniformCall::FuncPtr func = 0;
+ if(u.type==FLOAT)
+ func = &uniform_wrapper<float, glUniform1fv>;
+ else if(u.type==FLOAT_VEC2)
+ func = &uniform_wrapper<float, glUniform2fv>;
+ else if(u.type==FLOAT_VEC3)
+ func = &uniform_wrapper<float, glUniform3fv>;
+ else if(u.type==FLOAT_VEC4)
+ func = &uniform_wrapper<float, glUniform4fv>;
+ else if(u.type==INT)
+ func = &uniform_wrapper<int, glUniform1iv>;
+ else if(u.type==INT_VEC2)
+ func = &uniform_wrapper<int, glUniform2iv>;
+ else if(u.type==INT_VEC3)
+ func = &uniform_wrapper<int, glUniform3iv>;
+ else if(u.type==INT_VEC4)
+ func = &uniform_wrapper<int, glUniform4iv>;
+ else if(u.type==FLOAT_MAT2)
+ func = &uniform_matrix_wrapper<float, glUniformMatrix2fv>;
+ else if(u.type==FLOAT_MAT3)
+ func = &uniform_matrix_wrapper<float, glUniformMatrix3fv>;
+ else if(u.type==FLOAT_MAT4)
+ func = &uniform_matrix_wrapper<float, glUniformMatrix4fv>;
+ else if(u.type==FLOAT_MAT2x3)
+ func = &uniform_matrix_wrapper<float, glUniformMatrix2x3fv>;
+ else if(u.type==FLOAT_MAT3x2)
+ func = &uniform_matrix_wrapper<float, glUniformMatrix3x2fv>;
+ else if(u.type==FLOAT_MAT2x4)
+ func = &uniform_matrix_wrapper<float, glUniformMatrix2x4fv>;
+ else if(u.type==FLOAT_MAT4x2)
+ func = &uniform_matrix_wrapper<float, glUniformMatrix4x2fv>;
+ else if(u.type==FLOAT_MAT3x4)
+ func = &uniform_matrix_wrapper<float, glUniformMatrix3x4fv>;
+ else if(u.type==FLOAT_MAT4x3)
+ func = &uniform_matrix_wrapper<float, glUniformMatrix4x3fv>;
+ else if(is_image(u.type))
+ glGetUniformiv(id, u.location, &u.binding);
+
+ if(func)
+ uniform_calls.push_back(UniformCall(u.location, u.array_size, func));
+ }
}
+ default_block.sort_uniforms();
+ if(!default_block.uniforms.empty())
+ {
+ const ReflectData::UniformInfo &uni = *default_block.uniforms.back();
+ default_block.data_size = uni.location*16+uni.array_size*get_type_size(uni.type);
+ }
default_block.update_layout_hash();
reflect_data.update_layout_hash();
}