object.h 1.9 KB

12345678910111213141516171819202122232425262728293031323334353637383940414243444546474849505152535455565758596061626364656667686970717273747576777879808182
  1. #ifndef OBJECT_H
  2. #define OBJECT_H
  3. #include <CL/cl_platform.h>
  4. typedef struct {
  5. float x;
  6. float y;
  7. } Vec2;
  8. Vec2 lerp(Vec2 pos1, Vec2 pos2, float fraction){
  9. Vec2 result;
  10. float w0 = 1.0 - fraction;
  11. float w1 = fraction;
  12. result.x = pos1.x * w0 + pos2.x * w1;
  13. result.y = pos1.y * w0 + pos2.y * w1;
  14. return result;
  15. }
  16. typedef struct __attribute__((aligned(4))) {
  17. cl_uchar a; // 1
  18. cl_uchar r; // 1
  19. cl_uchar g; // 1
  20. cl_uchar b; // 1
  21. } ColorARGB; // size: 4, align: 4
  22. typedef struct __attribute__((aligned(4))) {
  23. ColorARGB albedo; // 4
  24. cl_int textureOffset; // 4
  25. cl_int normalMapOffset; // 4
  26. cl_int bumpMapOffset; // 4
  27. cl_ulong properties; // 8
  28. } Material; // size 24
  29. typedef struct __attribute__((aligned(16))) {
  30. cl_float x; // 4
  31. cl_float y; // 4
  32. cl_float z; // 4
  33. cl_float _pad0; // padding to align to 16 bytes
  34. } Vec3;
  35. typedef struct __attribute__((aligned(16))) {
  36. cl_float w;
  37. cl_float x;
  38. cl_float y;
  39. cl_float z;
  40. } Vec4;
  41. typedef struct __attribute__((aligned(16))) {
  42. Vec3 position; // 16 bytes
  43. Vec3 scale; // 16 bytes
  44. Vec4 rotation; // 16 bytes
  45. } Transform; // size: 48 bytes
  46. typedef struct __attribute__((aligned(4))) {
  47. cl_int transformedVertexOffset;
  48. cl_int transformedNormalOffset;
  49. cl_int triangleCount;
  50. cl_int vertexCount;
  51. cl_int normalCount;
  52. cl_int uvCount;
  53. cl_int triangleOffset;
  54. cl_int vertexOffset;
  55. cl_int normalOffset;
  56. cl_int uvOffset;
  57. } ModelInfo; // 10 × 4 = 40 bytes
  58. typedef struct __attribute__((aligned(16))) {
  59. Transform transform; // 64
  60. ModelInfo modelInfo; // 40
  61. cl_int id; // 4
  62. cl_int split_triangles; // 4 (pad so Material starts at 8-byte boundary)
  63. Material material; // 8
  64. cl_int _pad2; // 4 (pad to make Object size 128 bytes)
  65. cl_int _pad3; // 4
  66. } Object; // total: 64 + 40 + 4 + 4 + 8 + 4 + 4 = 128 bytes
  67. #endif