2
0
Эх сурвалжийг харах

Add xy and zw fields to V4 vectors

rexim 2 долоо хоног өмнө
parent
commit
66e05328d1
2 өөрчлөгдсөн 11 нэмэгдсэн , 0 устгасан
  1. 4 0
      la.h
  2. 7 0
      src/lag.c

+ 4 - 0
la.h

@@ -53,18 +53,22 @@ typedef union {
 } V3u;
 typedef union {
     struct { float x, y, z, w; };
+    struct { V2f xy; V2f zw; };
     float c[4];
 } V4f;
 typedef union {
     struct { double x, y, z, w; };
+    struct { V2d xy; V2d zw; };
     double c[4];
 } V4d;
 typedef union {
     struct { int x, y, z, w; };
+    struct { V2i xy; V2i zw; };
     int c[4];
 } V4i;
 typedef union {
     struct { unsigned int x, y, z, w; };
+    struct { V2u xy; V2u zw; };
     unsigned int c[4];
 } V4u;
 

+ 7 - 0
src/lag.c

@@ -91,6 +91,13 @@ void gen_vector_def(FILE *stream, size_t n, Type_Def type_def)
     }
     fprintf(stream, "; };\n");
 
+    if (n == 4) {
+        const char *half_vector_type = make_vector_type(n/2, type_def);
+        fprintf(stream, "    struct { %s %s%s; %s %s%s; };\n",
+                half_vector_type, vector_comps[0], vector_comps[1],
+                half_vector_type, vector_comps[2], vector_comps[3]);
+    }
+
     fprintf(stream, "    %s c[%zu];\n", type_def.name, n);
 
     fprintf(stream, "} %s;\n", vector_type);