MTLAccelerationStructureTypes.hpp
1 //------------------------------------------------------------------------------------------------------------------------------------------------------------- 2 // 3 // Metal/MTLAccelerationStructureTypes.hpp 4 // 5 // Copyright 2020-2024 Apple Inc. 6 // 7 // Licensed under the Apache License, Version 2.0 (the "License"); 8 // you may not use this file except in compliance with the License. 9 // You may obtain a copy of the License at 10 // 11 // http://www.apache.org/licenses/LICENSE-2.0 12 // 13 // Unless required by applicable law or agreed to in writing, software 14 // distributed under the License is distributed on an "AS IS" BASIS, 15 // WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. 16 // See the License for the specific language governing permissions and 17 // limitations under the License. 18 // 19 //------------------------------------------------------------------------------------------------------------------------------------------------------------- 20 21 #pragma once 22 23 //------------------------------------------------------------------------------------------------------------------------------------------------------------- 24 25 #include "MTLDefines.hpp" 26 #include "MTLPrivate.hpp" 27 #include "MTLResource.hpp" 28 #include "MTLStageInputOutputDescriptor.hpp" 29 30 #include "../Foundation/NSRange.hpp" 31 32 //------------------------------------------------------------------------------------------------------------------------------------------------------------- 33 34 namespace MTL 35 { 36 37 #pragma clang diagnostic push 38 #pragma clang diagnostic ignored "-Wnested-anon-types" 39 struct PackedFloat3 40 { 41 PackedFloat3(); 42 PackedFloat3(float x, float y, float z); 43 44 float& operator[](int idx); 45 float operator[](int idx) const; 46 47 union 48 { 49 struct 50 { 51 float x; 52 float y; 53 float z; 54 }; 55 56 float elements[3]; 57 }; 58 } _MTL_PACKED; 59 #pragma clang diagnostic pop 60 61 struct PackedFloat4x3 62 { 63 PackedFloat4x3(); 64 PackedFloat4x3(const PackedFloat3& col0, const PackedFloat3& col1, const PackedFloat3& col2, const PackedFloat3& col3); 65 66 PackedFloat3& operator[](int idx); 67 const PackedFloat3& operator[](int idx) const; 68 69 PackedFloat3 columns[4]; 70 } _MTL_PACKED; 71 72 struct AxisAlignedBoundingBox 73 { 74 AxisAlignedBoundingBox(); 75 AxisAlignedBoundingBox(PackedFloat3 p); 76 AxisAlignedBoundingBox(PackedFloat3 min, PackedFloat3 max); 77 78 PackedFloat3 min; 79 PackedFloat3 max; 80 } _MTL_PACKED; 81 82 #pragma clang diagnostic push 83 #pragma clang diagnostic ignored "-Wnested-anon-types" 84 struct PackedFloatQuaternion 85 { 86 PackedFloatQuaternion(); 87 PackedFloatQuaternion(float x, float y, float z, float w); 88 89 float& operator[](int idx); 90 const float& operator[](int idx) const; 91 92 union 93 { 94 struct 95 { 96 float x; 97 float y; 98 float z; 99 float w; 100 }; 101 102 float elements[4]; 103 }; 104 105 } _MTL_PACKED; 106 #pragma clang diagnostic pop 107 108 struct ComponentTransform 109 { 110 PackedFloat3 scale; 111 PackedFloat3 shear; 112 PackedFloat3 pivot; 113 PackedFloatQuaternion rotation; 114 PackedFloat3 translation; 115 } _MTL_PACKED; 116 117 } 118 119 //------------------------------------------------------------------------------------------------------------------------------------------------------------- 120 121 _MTL_INLINE MTL::PackedFloat3::PackedFloat3() 122 : x(0.0f) 123 , y(0.0f) 124 , z(0.0f) 125 { 126 } 127 128 //------------------------------------------------------------------------------------------------------------------------------------------------------------- 129 130 _MTL_INLINE MTL::PackedFloat3::PackedFloat3(float _x, float _y, float _z) 131 : x(_x) 132 , y(_y) 133 , z(_z) 134 { 135 } 136 137 //------------------------------------------------------------------------------------------------------------------------------------------------------------- 138 139 _MTL_INLINE float& MTL::PackedFloat3::operator[](int idx) 140 { 141 return elements[idx]; 142 } 143 144 //------------------------------------------------------------------------------------------------------------------------------------------------------------- 145 146 _MTL_INLINE float MTL::PackedFloat3::operator[](int idx) const 147 { 148 return elements[idx]; 149 } 150 151 //------------------------------------------------------------------------------------------------------------------------------------------------------------- 152 153 _MTL_INLINE MTL::PackedFloat4x3::PackedFloat4x3() 154 { 155 columns[0] = PackedFloat3(0.0f, 0.0f, 0.0f); 156 columns[1] = PackedFloat3(0.0f, 0.0f, 0.0f); 157 columns[2] = PackedFloat3(0.0f, 0.0f, 0.0f); 158 columns[3] = PackedFloat3(0.0f, 0.0f, 0.0f); 159 } 160 161 //------------------------------------------------------------------------------------------------------------------------------------------------------------- 162 163 _MTL_INLINE MTL::PackedFloat4x3::PackedFloat4x3(const PackedFloat3& col0, const PackedFloat3& col1, const PackedFloat3& col2, const PackedFloat3& col3) 164 { 165 columns[0] = col0; 166 columns[1] = col1; 167 columns[2] = col2; 168 columns[3] = col3; 169 } 170 171 //------------------------------------------------------------------------------------------------------------------------------------------------------------- 172 173 _MTL_INLINE MTL::PackedFloat3& MTL::PackedFloat4x3::operator[](int idx) 174 { 175 return columns[idx]; 176 } 177 178 //------------------------------------------------------------------------------------------------------------------------------------------------------------- 179 180 _MTL_INLINE const MTL::PackedFloat3& MTL::PackedFloat4x3::operator[](int idx) const 181 { 182 return columns[idx]; 183 } 184 185 //------------------------------------------------------------------------------------------------------------------------------------------------------------- 186 187 _MTL_INLINE MTL::AxisAlignedBoundingBox::AxisAlignedBoundingBox() 188 : min(INFINITY, INFINITY, INFINITY) 189 , max(-INFINITY, -INFINITY, -INFINITY) 190 { 191 } 192 193 //------------------------------------------------------------------------------------------------------------------------------------------------------------- 194 195 _MTL_INLINE MTL::AxisAlignedBoundingBox::AxisAlignedBoundingBox(PackedFloat3 p) 196 : min(p) 197 , max(p) 198 { 199 } 200 201 //------------------------------------------------------------------------------------------------------------------------------------------------------------- 202 203 _MTL_INLINE MTL::AxisAlignedBoundingBox::AxisAlignedBoundingBox(PackedFloat3 _min, PackedFloat3 _max) 204 : min(_min) 205 , max(_max) 206 { 207 } 208 209 //------------------------------------------------------------------------------------------------------------------------------------------------------------- 210 211 _MTL_INLINE MTL::PackedFloatQuaternion::PackedFloatQuaternion() 212 : x(0.0f) 213 , y(0.0f) 214 , z(0.0f) 215 , w(0.0f) 216 { 217 } 218 219 //------------------------------------------------------------------------------------------------------------------------------------------------------------- 220 221 _MTL_INLINE MTL::PackedFloatQuaternion::PackedFloatQuaternion(float x, float y, float z, float w) 222 : x(x) 223 , y(y) 224 , z(z) 225 , w(w) 226 { 227 } 228 229 //------------------------------------------------------------------------------------------------------------------------------------------------------------- 230 231 _MTL_INLINE float& MTL::PackedFloatQuaternion::operator[](int idx) 232 { 233 return elements[idx]; 234 } 235 236 //------------------------------------------------------------------------------------------------------------------------------------------------------------- 237 238 _MTL_INLINE const float& MTL::PackedFloatQuaternion::operator[](int idx) const 239 { 240 return elements[idx]; 241 } 242 243 //-------------------------------------------------------------------------------------------------------------------------------------------------------------