return ptr->gl_type;
}
+DataType from_gl_type(GLenum gl_type)
+{
+ for(unsigned i=0; i<type_map_size; ++i)
+ if(type_map[i].gl_type==gl_type)
+ return type_map[i].type;
+ throw invalid_argument("from_gl_type");
+}
+
+void require_type(DataType type)
+{
+ unsigned rows = ((type>>12)&3)+1;
+ unsigned cols = ((type>>14)&4)+1;
+ if(rows>1 && cols>1 && rows!=cols)
+ static Require _req(NV_non_square_matrices);
+ if((type&0x200) && get_type_size(type)/(rows*cols)==8)
+ static Require _req(ARB_gpu_shader_fp64);
+}
+
} // namespace GL
} // namespace Msp
SAMPLER_CUBE_ARRAY_SHADOW = 0x3C0304
};
-inline unsigned get_type_size(DataType t)
-{ return t&0xFF; }
+inline unsigned get_type_size(DataType t) { return t&0xFF; }
+inline bool is_matrix(DataType t) { return (t>>14)&3; }
+inline bool is_vector(DataType t) { return !is_matrix(t) && ((t>>12)&3); }
GLenum get_gl_type(DataType);
+DataType from_gl_type(GLenum);
+
+void require_type(DataType);
} // namespace GL
} // namespace Msp
require_type(i->second.type);
}
-void Program::require_type(GLenum t)
-{
- switch(t)
- {
- case GL_FLOAT_MAT2x3:
- case GL_FLOAT_MAT2x4:
- case GL_FLOAT_MAT3x2:
- case GL_FLOAT_MAT3x4:
- case GL_FLOAT_MAT4x2:
- case GL_FLOAT_MAT4x3:
- { static Require _req(NV_non_square_matrices); }
- break;
- }
-}
-
void Program::query_uniforms()
{
unsigned count = get_program_i(id, GL_ACTIVE_UNIFORMS);
info.size = size;
info.array_stride = 0;
info.matrix_stride = 0;
- info.type = type;
+ info.type = from_gl_type(type);
uniforms_by_index[i] = &info;
}
}
indices2.clear();
for(vector<int>::iterator j=indices.begin(); j!=indices.end(); ++j)
{
- GLenum t = uniforms_by_index[*j]->type;
- if(t==GL_FLOAT_MAT4 || t==GL_FLOAT_MAT3 || t==GL_FLOAT_MAT2 ||
- t==GL_FLOAT_MAT2x3 || t==GL_FLOAT_MAT2x4 || t==GL_FLOAT_MAT3x2 ||
- t==GL_FLOAT_MAT3x4 || t==GL_FLOAT_MAT4x2 || t==GL_FLOAT_MAT4x3)
+ DataType t = uniforms_by_index[*j]->type;
+ if(is_matrix(t))
indices2.push_back(*j);
}
if(!indices2.empty())
info.name = name;
info.location = glGetAttribLocation(id, name);
info.size = size;
- info.type = type;
+ info.type = from_gl_type(type);
}
}
}
#include <vector>
#include <msp/datafile/objectloader.h>
#include "bindable.h"
+#include "datatype.h"
#include "gl.h"
#include "vertexformat.h"
unsigned size;
unsigned array_stride;
unsigned matrix_stride;
- GLenum type;
+ DataType type;
};
struct UniformBlockInfo
std::string name;
unsigned location;
unsigned size;
- GLenum type;
+ DataType type;
};
typedef std::map<std::string, UniformInfo> UniformMap;
void link();
private:
- static void require_type(GLenum);
void query_uniforms();
void query_uniform_blocks(const std::vector<UniformInfo *> &);
void query_attributes();