DECL_TYPE(error, GL_INVALID_ENUM, GLSL_TYPE_ERROR, 0, 0)
DECL_TYPE(void, GL_INVALID_ENUM, GLSL_TYPE_VOID, 0, 0)
-DECL_TYPE(bool, GL_BOOL, GLSL_TYPE_BOOL, 1, 1)
-DECL_TYPE(bvec2, GL_BOOL_VEC2, GLSL_TYPE_BOOL, 2, 1)
-DECL_TYPE(bvec3, GL_BOOL_VEC3, GLSL_TYPE_BOOL, 3, 1)
-DECL_TYPE(bvec4, GL_BOOL_VEC4, GLSL_TYPE_BOOL, 4, 1)
-
-DECL_TYPE(int, GL_INT, GLSL_TYPE_INT, 1, 1)
-DECL_TYPE(ivec2, GL_INT_VEC2, GLSL_TYPE_INT, 2, 1)
-DECL_TYPE(ivec3, GL_INT_VEC3, GLSL_TYPE_INT, 3, 1)
-DECL_TYPE(ivec4, GL_INT_VEC4, GLSL_TYPE_INT, 4, 1)
-
-DECL_TYPE(uint, GL_UNSIGNED_INT, GLSL_TYPE_UINT, 1, 1)
-DECL_TYPE(uvec2, GL_UNSIGNED_INT_VEC2, GLSL_TYPE_UINT, 2, 1)
-DECL_TYPE(uvec3, GL_UNSIGNED_INT_VEC3, GLSL_TYPE_UINT, 3, 1)
-DECL_TYPE(uvec4, GL_UNSIGNED_INT_VEC4, GLSL_TYPE_UINT, 4, 1)
-
-DECL_TYPE(float, GL_FLOAT, GLSL_TYPE_FLOAT, 1, 1)
-DECL_TYPE(vec2, GL_FLOAT_VEC2, GLSL_TYPE_FLOAT, 2, 1)
-DECL_TYPE(vec3, GL_FLOAT_VEC3, GLSL_TYPE_FLOAT, 3, 1)
-DECL_TYPE(vec4, GL_FLOAT_VEC4, GLSL_TYPE_FLOAT, 4, 1)
+#define DECL_VEC_TYPE(stype, vtype, btype, etype, ...) \
+ DECL_TYPE(stype, etype ##__VA_ARGS__, btype, 1, 1) \
+ DECL_TYPE(vtype ## 2, etype ##_VEC2 ##__VA_ARGS__, btype, 2, 1) \
+ DECL_TYPE(vtype ## 3, etype ##_VEC3 ##__VA_ARGS__, btype, 3, 1) \
+ DECL_TYPE(vtype ## 4, etype ##_VEC4 ##__VA_ARGS__, btype, 4, 1)
+
+DECL_VEC_TYPE(bool, bvec, GLSL_TYPE_BOOL, GL_BOOL)
+DECL_VEC_TYPE(int, ivec, GLSL_TYPE_INT, GL_INT)
+DECL_VEC_TYPE(uint, uvec, GLSL_TYPE_UINT, GL_UNSIGNED_INT)
+DECL_VEC_TYPE(float, vec, GLSL_TYPE_FLOAT, GL_FLOAT)
+DECL_VEC_TYPE(float16_t, f16vec, GLSL_TYPE_FLOAT16, GL_FLOAT16, _NV)
+DECL_VEC_TYPE(double, dvec, GLSL_TYPE_DOUBLE, GL_DOUBLE)
+DECL_VEC_TYPE(int64_t, i64vec, GLSL_TYPE_INT64, GL_INT64, _ARB)
+DECL_VEC_TYPE(uint64_t, u64vec, GLSL_TYPE_UINT64, GL_UNSIGNED_INT64, _ARB)
+DECL_VEC_TYPE(int16_t, i16vec, GLSL_TYPE_INT16, GL_INT16, _NV)
+DECL_VEC_TYPE(uint16_t, u16vec, GLSL_TYPE_UINT16, GL_UNSIGNED_INT16, _NV)
+DECL_VEC_TYPE(int8_t, i8vec, GLSL_TYPE_INT8, GL_INT8, _NV)
+DECL_VEC_TYPE(uint8_t, u8vec, GLSL_TYPE_UINT8, GL_UNSIGNED_INT8, _NV)
DECL_TYPE(mat2, GL_FLOAT_MAT2, GLSL_TYPE_FLOAT, 2, 2)
DECL_TYPE(mat3, GL_FLOAT_MAT3, GLSL_TYPE_FLOAT, 3, 3)
DECL_TYPE(mat4x2, GL_FLOAT_MAT4x2, GLSL_TYPE_FLOAT, 2, 4)
DECL_TYPE(mat4x3, GL_FLOAT_MAT4x3, GLSL_TYPE_FLOAT, 3, 4)
-DECL_TYPE(float16_t, GL_FLOAT16_NV, GLSL_TYPE_FLOAT16, 1, 1)
-DECL_TYPE(f16vec2, GL_FLOAT16_VEC2_NV, GLSL_TYPE_FLOAT16, 2, 1)
-DECL_TYPE(f16vec3, GL_FLOAT16_VEC3_NV, GLSL_TYPE_FLOAT16, 3, 1)
-DECL_TYPE(f16vec4, GL_FLOAT16_VEC4_NV, GLSL_TYPE_FLOAT16, 4, 1)
-
DECL_TYPE(f16mat2, GL_FLOAT16_MAT2_AMD, GLSL_TYPE_FLOAT16, 2, 2)
DECL_TYPE(f16mat3, GL_FLOAT16_MAT3_AMD, GLSL_TYPE_FLOAT16, 3, 3)
DECL_TYPE(f16mat4, GL_FLOAT16_MAT4_AMD, GLSL_TYPE_FLOAT16, 4, 4)
DECL_TYPE(f16mat4x2, GL_FLOAT16_MAT4x2_AMD, GLSL_TYPE_FLOAT16, 2, 4)
DECL_TYPE(f16mat4x3, GL_FLOAT16_MAT4x3_AMD, GLSL_TYPE_FLOAT16, 3, 4)
-DECL_TYPE(double, GL_DOUBLE, GLSL_TYPE_DOUBLE, 1, 1)
-DECL_TYPE(dvec2, GL_DOUBLE_VEC2, GLSL_TYPE_DOUBLE, 2, 1)
-DECL_TYPE(dvec3, GL_DOUBLE_VEC3, GLSL_TYPE_DOUBLE, 3, 1)
-DECL_TYPE(dvec4, GL_DOUBLE_VEC4, GLSL_TYPE_DOUBLE, 4, 1)
-
DECL_TYPE(dmat2, GL_DOUBLE_MAT2, GLSL_TYPE_DOUBLE, 2, 2)
DECL_TYPE(dmat3, GL_DOUBLE_MAT3, GLSL_TYPE_DOUBLE, 3, 3)
DECL_TYPE(dmat4, GL_DOUBLE_MAT4, GLSL_TYPE_DOUBLE, 4, 4)
DECL_TYPE(dmat4x2, GL_DOUBLE_MAT4x2, GLSL_TYPE_DOUBLE, 2, 4)
DECL_TYPE(dmat4x3, GL_DOUBLE_MAT4x3, GLSL_TYPE_DOUBLE, 3, 4)
-DECL_TYPE(int64_t, GL_INT64_ARB, GLSL_TYPE_INT64, 1, 1)
-DECL_TYPE(i64vec2, GL_INT64_VEC2_ARB, GLSL_TYPE_INT64, 2, 1)
-DECL_TYPE(i64vec3, GL_INT64_VEC3_ARB, GLSL_TYPE_INT64, 3, 1)
-DECL_TYPE(i64vec4, GL_INT64_VEC4_ARB, GLSL_TYPE_INT64, 4, 1)
-
-DECL_TYPE(uint64_t, GL_UNSIGNED_INT64_ARB, GLSL_TYPE_UINT64, 1, 1)
-DECL_TYPE(u64vec2, GL_UNSIGNED_INT64_VEC2_ARB, GLSL_TYPE_UINT64, 2, 1)
-DECL_TYPE(u64vec3, GL_UNSIGNED_INT64_VEC3_ARB, GLSL_TYPE_UINT64, 3, 1)
-DECL_TYPE(u64vec4, GL_UNSIGNED_INT64_VEC4_ARB, GLSL_TYPE_UINT64, 4, 1)
-
-DECL_TYPE(int16_t, GL_INT16_NV, GLSL_TYPE_INT16, 1, 1)
-DECL_TYPE(i16vec2, GL_INT16_VEC2_NV, GLSL_TYPE_INT16, 2, 1)
-DECL_TYPE(i16vec3, GL_INT16_VEC3_NV, GLSL_TYPE_INT16, 3, 1)
-DECL_TYPE(i16vec4, GL_INT16_VEC4_NV, GLSL_TYPE_INT16, 4, 1)
-
-DECL_TYPE(uint16_t, GL_UNSIGNED_INT16_NV, GLSL_TYPE_UINT16, 1, 1)
-DECL_TYPE(u16vec2, GL_UNSIGNED_INT16_VEC2_NV, GLSL_TYPE_UINT16, 2, 1)
-DECL_TYPE(u16vec3, GL_UNSIGNED_INT16_VEC3_NV, GLSL_TYPE_UINT16, 3, 1)
-DECL_TYPE(u16vec4, GL_UNSIGNED_INT16_VEC4_NV, GLSL_TYPE_UINT16, 4, 1)
-
-DECL_TYPE(int8_t, GL_INT8_NV, GLSL_TYPE_INT8, 1, 1)
-DECL_TYPE(i8vec2, GL_INT8_VEC2_NV, GLSL_TYPE_INT8, 2, 1)
-DECL_TYPE(i8vec3, GL_INT8_VEC3_NV, GLSL_TYPE_INT8, 3, 1)
-DECL_TYPE(i8vec4, GL_INT8_VEC4_NV, GLSL_TYPE_INT8, 4, 1)
-
-DECL_TYPE(uint8_t, GL_UNSIGNED_INT8_NV, GLSL_TYPE_UINT8, 1, 1)
-DECL_TYPE(u8vec2, GL_UNSIGNED_INT8_VEC2_NV, GLSL_TYPE_UINT8, 2, 1)
-DECL_TYPE(u8vec3, GL_UNSIGNED_INT8_VEC3_NV, GLSL_TYPE_UINT8, 3, 1)
-DECL_TYPE(u8vec4, GL_UNSIGNED_INT8_VEC4_NV, GLSL_TYPE_UINT8, 4, 1)
-
DECL_TYPE(sampler, GL_SAMPLER_1D, GLSL_TYPE_SAMPLER, GLSL_SAMPLER_DIM_1D, 0, 0, GLSL_TYPE_VOID)
DECL_TYPE(sampler1D, GL_SAMPLER_1D, GLSL_TYPE_SAMPLER, GLSL_SAMPLER_DIM_1D, 0, 0, GLSL_TYPE_FLOAT)
DECL_TYPE(sampler2D, GL_SAMPLER_2D, GLSL_TYPE_SAMPLER, GLSL_SAMPLER_DIM_2D, 0, 0, GLSL_TYPE_FLOAT)
this->name = n;
}
-
const glsl_type *
-glsl_type::vec(unsigned components)
+glsl_type::vec(unsigned components, const glsl_type *const ts[])
{
- if (components == 0 || components > 4)
+ unsigned n = components;
+
+ if (n == 0 || n > 4)
return error_type;
- static const glsl_type *const ts[] = {
- float_type, vec2_type, vec3_type, vec4_type
- };
- return ts[components - 1];
+ return ts[n - 1];
}
+#define VECN(components, sname, vname) ({ \
+ static const glsl_type *const ts[] = { \
+ sname ## _type, vname ## 2_type, \
+ vname ## 3_type, vname ## 4_type, \
+ }; \
+ glsl_type::vec(components, ts); \
+ })
+
const glsl_type *
-glsl_type::f16vec(unsigned components)
+glsl_type::vec(unsigned components)
{
- if (components == 0 || components > 4)
- return error_type;
+ return VECN(components, float, vec);
+}
- static const glsl_type *const ts[] = {
- float16_t_type, f16vec2_type, f16vec3_type, f16vec4_type
- };
- return ts[components - 1];
+const glsl_type *
+glsl_type::f16vec(unsigned components)
+{
+ return VECN(components, float16_t, f16vec);
}
const glsl_type *
glsl_type::dvec(unsigned components)
{
- if (components == 0 || components > 4)
- return error_type;
-
- static const glsl_type *const ts[] = {
- double_type, dvec2_type, dvec3_type, dvec4_type
- };
- return ts[components - 1];
+ return VECN(components, double, dvec);
}
const glsl_type *
glsl_type::ivec(unsigned components)
{
- if (components == 0 || components > 4)
- return error_type;
-
- static const glsl_type *const ts[] = {
- int_type, ivec2_type, ivec3_type, ivec4_type
- };
- return ts[components - 1];
+ return VECN(components, int, ivec);
}
-
const glsl_type *
glsl_type::uvec(unsigned components)
{
- if (components == 0 || components > 4)
- return error_type;
-
- static const glsl_type *const ts[] = {
- uint_type, uvec2_type, uvec3_type, uvec4_type
- };
- return ts[components - 1];
+ return VECN(components, uint, uvec);
}
-
const glsl_type *
glsl_type::bvec(unsigned components)
{
- if (components == 0 || components > 4)
- return error_type;
-
- static const glsl_type *const ts[] = {
- bool_type, bvec2_type, bvec3_type, bvec4_type
- };
- return ts[components - 1];
+ return VECN(components, bool, bvec);
}
-
const glsl_type *
glsl_type::i64vec(unsigned components)
{
- if (components == 0 || components > 4)
- return error_type;
-
- static const glsl_type *const ts[] = {
- int64_t_type, i64vec2_type, i64vec3_type, i64vec4_type
- };
- return ts[components - 1];
+ return VECN(components, int64_t, i64vec);
}
const glsl_type *
glsl_type::u64vec(unsigned components)
{
- if (components == 0 || components > 4)
- return error_type;
-
- static const glsl_type *const ts[] = {
- uint64_t_type, u64vec2_type, u64vec3_type, u64vec4_type
- };
- return ts[components - 1];
+ return VECN(components, uint64_t, u64vec);
}
const glsl_type *
glsl_type::i16vec(unsigned components)
{
- if (components == 0 || components > 4)
- return error_type;
-
- static const glsl_type *const ts[] = {
- int16_t_type, i16vec2_type, i16vec3_type, i16vec4_type
- };
- return ts[components - 1];
+ return VECN(components, int16_t, i16vec);
}
const glsl_type *
glsl_type::u16vec(unsigned components)
{
- if (components == 0 || components > 4)
- return error_type;
-
- static const glsl_type *const ts[] = {
- uint16_t_type, u16vec2_type, u16vec3_type, u16vec4_type
- };
- return ts[components - 1];
+ return VECN(components, uint16_t, u16vec);
}
const glsl_type *
glsl_type::i8vec(unsigned components)
{
- if (components == 0 || components > 4)
- return error_type;
-
- static const glsl_type *const ts[] = {
- int8_t_type, i8vec2_type, i8vec3_type, i8vec4_type
- };
- return ts[components - 1];
+ return VECN(components, int8_t, i8vec);
}
const glsl_type *
glsl_type::u8vec(unsigned components)
{
- if (components == 0 || components > 4)
- return error_type;
-
- static const glsl_type *const ts[] = {
- uint8_t_type, u8vec2_type, u8vec3_type, u8vec4_type
- };
- return ts[components - 1];
+ return VECN(components, uint8_t, u8vec);
}
const glsl_type *
if (base_type == GLSL_TYPE_VOID)
return void_type;
- if ((rows < 1) || (rows > 4) || (columns < 1) || (columns > 4))
- return error_type;
-
/* Treat GLSL vectors as Nx1 matrices.
*/
if (columns == 1) {