Menu â–¾ â–´

#24 swizzle support

open
nobody
None
2018-05-10
2018-01-20
Anonymous
No

Originally created by: recp

now as C math library cglm supports swizzling: https://www.khronos.org/opengl/wiki/Data_Type_(GLSL)#Swizzling

glm_vec_swizzle(vec4 v, int mask, vec4 dest)
glm_vec4_swizzle(vec4 v, int mask, vec4 dest)

Predefined masks:

/* vec3 */
GLM_XXX
GLM_YYY
GLM_ZZZ
GLM_ZYX

/* vec4 */
GLM_XXXX
GLM_YYYY
GLM_ZZZZ
GLM_WWWW
GLM_WZYX

Example usage (flip vec4 components):

vec4 vector = {12, 73.7, 0.936, 1.05};
glm_vec4_print(vector, stderr);

glm_vec4_swizzle(vector, GLM_WZYX, vector);
glm_vec4_print(vector, stderr);

/* 
Vector (float4):
    |12.0000   73.7000.  0.9360   1.0500|

Vector (float4):
    |1.0500.  0.9360.  73.7000   12.0000|

 */

This functions may be improved my SIMD instructions

Discussion


Log in to post a comment.

MongoDB Logo MongoDB