lens.h (1329B)
1 #pragma once 2 3 #include "resource.h" 4 #include <stddef.h> 5 #include <assert.h> 6 #include <string.h> 7 8 enum datatype { 9 DATA_ID_FLOAT = 1, 10 DATA_ID_INT, 11 DATA_ID_VEC2, 12 DATA_ID_VEC3, 13 DATA_ID_VEC3P, 14 DATA_ID_MAT3, 15 DATA_ID_MAT4, 16 DATA_ID_MAT4P, 17 }; 18 19 struct lens { 20 const char *name; 21 int offset; 22 enum datatype type; 23 }; 24 25 static inline void *get_lens_offset_ptr(struct lens *lens, void *structure) 26 { 27 return (void*)((unsigned char*)structure + lens->offset); 28 } 29 30 static inline float *get_lens_ptr(struct lens *lens, void *structure) 31 { 32 assert(lens->type == DATA_ID_MAT4P || lens->type == DATA_ID_VEC3P); 33 float **p = (float**)get_lens_offset_ptr(lens, structure); 34 return *p; 35 } 36 37 static inline float *get_lens_float_array(struct lens *lens, void *structure) 38 { 39 assert(lens->type == DATA_ID_MAT4 || 40 lens->type == DATA_ID_VEC3 || 41 lens->type == DATA_ID_VEC2 || 42 lens->type == DATA_ID_MAT3); 43 void *p = get_lens_offset_ptr(lens, structure); 44 return (float*)p; 45 } 46 47 static inline float get_lens_float(struct lens *lens, void *structure) 48 { 49 assert(lens->type == DATA_ID_FLOAT); 50 void *p = get_lens_offset_ptr(lens, structure); 51 return *(float*)p; 52 } 53 54 static inline int get_lens_int(struct lens *lens, void *structure) 55 { 56 assert(lens->type == DATA_ID_INT); 57 void *p = get_lens_offset_ptr(lens, structure); 58 return *(int*)p; 59 }