mirror of
https://gitlab.freedesktop.org/mesa/mesa.git
synced 2025-12-23 22:00:13 +01:00
glsl: Add simple vector type accessor helpers.
This patch introduces new functions to quickly grab a pointer to a vector type. For example: glsl_type::bvec(4) returns glsl_type::bvec4_type glsl_type::ivec(3) returns glsl_type::ivec3_type glsl_type::uvec(2) returns glsl_type::uvec2_type glsl_type::vec(1) returns glsl_type::float_type This is less wordy than glsl_type::get_instance(GLSL_TYPE_BOOL, 4, 1), which can help avoid extra word wrapping. Signed-off-by: Kenneth Graunke <kenneth@whitecape.org> Reviewed-by: Eric Anholt <eric@anholt.net>
This commit is contained in:
parent
9a14e412d6
commit
d367a1cbdb
2 changed files with 61 additions and 0 deletions
|
|
@ -534,6 +534,58 @@ glsl_type::glsl_type(const glsl_type *array, unsigned length) :
|
|||
}
|
||||
|
||||
|
||||
const glsl_type *const
|
||||
glsl_type::vec(unsigned components)
|
||||
{
|
||||
if (components == 0 || components > 4)
|
||||
return error_type;
|
||||
|
||||
static const glsl_type *const ts[] = {
|
||||
float_type, vec2_type, vec3_type, vec4_type
|
||||
};
|
||||
return ts[components - 1];
|
||||
}
|
||||
|
||||
|
||||
const glsl_type *const
|
||||
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];
|
||||
}
|
||||
|
||||
|
||||
const glsl_type *const
|
||||
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];
|
||||
}
|
||||
|
||||
|
||||
const glsl_type *const
|
||||
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];
|
||||
}
|
||||
|
||||
|
||||
const glsl_type *
|
||||
glsl_type::get_instance(unsigned base_type, unsigned rows, unsigned columns)
|
||||
{
|
||||
|
|
|
|||
|
|
@ -187,6 +187,15 @@ struct glsl_type {
|
|||
static const glsl_type *const mat4_type;
|
||||
/*@}*/
|
||||
|
||||
/**
|
||||
* Convenience accessors for vector types (shorter than get_instance()).
|
||||
* @{
|
||||
*/
|
||||
static const glsl_type *const vec(unsigned components);
|
||||
static const glsl_type *const ivec(unsigned components);
|
||||
static const glsl_type *const uvec(unsigned components);
|
||||
static const glsl_type *const bvec(unsigned components);
|
||||
/**@}*/
|
||||
|
||||
/**
|
||||
* For numeric and boolean derrived types returns the basic scalar type
|
||||
|
|
|
|||
Loading…
Add table
Reference in a new issue