| 1 | // Copyright (C) 2008-2012 NVIDIA Corporation. |
| 2 | // Copyright (C) 2019 The Qt Company Ltd. |
| 3 | // SPDX-License-Identifier: LicenseRef-Qt-Commercial OR GPL-3.0-only |
| 4 | |
| 5 | #ifndef QSSGRENDERBASETYPES_P_H |
| 6 | #define QSSGRENDERBASETYPES_P_H |
| 7 | |
| 8 | // |
| 9 | // W A R N I N G |
| 10 | // ------------- |
| 11 | // |
| 12 | // This file is not part of the Qt API. It exists purely as an |
| 13 | // implementation detail. This header file may change from version to |
| 14 | // version without notice, or even be removed. |
| 15 | // |
| 16 | // We mean it. |
| 17 | // |
| 18 | |
| 19 | #include <QtQuick3DUtils/qtquick3dutilsexports.h> |
| 20 | |
| 21 | #include <QtGui/QVector2D> |
| 22 | #include <QtGui/QVector3D> |
| 23 | #include <QtGui/QVector4D> |
| 24 | #include <QtGui/QMatrix4x4> |
| 25 | #include <QtGui/QMatrix3x3> |
| 26 | #include <QFloat16> |
| 27 | |
| 28 | #include <cmath> |
| 29 | |
| 30 | QT_BEGIN_NAMESPACE |
| 31 | |
| 32 | enum class QSSGRenderComponentType // stored in mesh files, the values must not change, must match Mesh::ComponentType |
| 33 | { |
| 34 | UnsignedInt8 = 1, |
| 35 | Int8, |
| 36 | UnsignedInt16, |
| 37 | Int16, |
| 38 | UnsignedInt32, |
| 39 | Int32, |
| 40 | UnsignedInt64, |
| 41 | Int64, |
| 42 | Float16, |
| 43 | Float32, |
| 44 | Float64 |
| 45 | }; |
| 46 | |
| 47 | enum class QSSGRenderDrawMode // stored in mesh files, the values must not change, must match Mesh::DrawMode |
| 48 | { |
| 49 | Points = 1, |
| 50 | LineStrip, |
| 51 | LineLoop, // Not supported |
| 52 | Lines, |
| 53 | TriangleStrip, |
| 54 | TriangleFan, |
| 55 | Triangles |
| 56 | }; |
| 57 | |
| 58 | enum class QSSGRenderWinding // stored in mesh files, the values must not change, must match Mesh::Winding |
| 59 | { |
| 60 | Clockwise = 1, |
| 61 | CounterClockwise |
| 62 | }; |
| 63 | |
| 64 | struct Q_QUICK3DUTILS_EXPORT QSSGRenderTextureFormat |
| 65 | { |
| 66 | static constexpr quint8 DepthTextureFlag = 1u << 6; |
| 67 | static constexpr quint8 CompressedTextureFlag = 1u << 7; |
| 68 | |
| 69 | enum Format : quint8 { |
| 70 | // Non-compressed formats |
| 71 | Unknown = 0, |
| 72 | R8, |
| 73 | R16, |
| 74 | R16F, |
| 75 | R32I, |
| 76 | R32UI, |
| 77 | R32F, |
| 78 | RG8, |
| 79 | RGBA8, |
| 80 | RGB8, |
| 81 | SRGB8, |
| 82 | SRGB8A8, |
| 83 | RGB565, |
| 84 | RGBA5551, |
| 85 | Alpha8, |
| 86 | Luminance8, |
| 87 | Luminance16, |
| 88 | LuminanceAlpha8, |
| 89 | RGBA16F, |
| 90 | RG16F, |
| 91 | RG32F, |
| 92 | RGB32F, |
| 93 | RGBA32F, |
| 94 | R11G11B10, |
| 95 | RGB9E5, |
| 96 | RGB10_A2, |
| 97 | RGB16F, |
| 98 | RGBA32UI, |
| 99 | RGB32UI, |
| 100 | RGBA16UI, |
| 101 | RGB16UI, |
| 102 | RGBA8UI, |
| 103 | RGB8UI, |
| 104 | RGBA32I, |
| 105 | RGB32I, |
| 106 | RGBA16I, |
| 107 | RGB16I, |
| 108 | RGBA8I, |
| 109 | RGB8I, |
| 110 | RGBE8, |
| 111 | |
| 112 | // Depth textures |
| 113 | Depth16 = DepthTextureFlag + 1, |
| 114 | Depth24, |
| 115 | Depth32, |
| 116 | Depth24Stencil8, |
| 117 | |
| 118 | // Compressed formats |
| 119 | RGBA_DXT1 = CompressedTextureFlag + 1, |
| 120 | RGB_DXT1, |
| 121 | RGBA_DXT3, |
| 122 | RGBA_DXT5, |
| 123 | R11_EAC_UNorm, |
| 124 | R11_EAC_SNorm, |
| 125 | RG11_EAC_UNorm, |
| 126 | RG11_EAC_SNorm, |
| 127 | RGB8_ETC2, |
| 128 | SRGB8_ETC2, |
| 129 | RGB8_PunchThrough_Alpha1_ETC2, |
| 130 | SRGB8_PunchThrough_Alpha1_ETC2, |
| 131 | RGBA8_ETC2_EAC, |
| 132 | SRGB8_Alpha8_ETC2_EAC, |
| 133 | RGBA_ASTC_4x4, |
| 134 | RGBA_ASTC_5x4, |
| 135 | RGBA_ASTC_5x5, |
| 136 | RGBA_ASTC_6x5, |
| 137 | RGBA_ASTC_6x6, |
| 138 | RGBA_ASTC_8x5, |
| 139 | RGBA_ASTC_8x6, |
| 140 | RGBA_ASTC_8x8, |
| 141 | RGBA_ASTC_10x5, |
| 142 | RGBA_ASTC_10x6, |
| 143 | RGBA_ASTC_10x8, |
| 144 | RGBA_ASTC_10x10, |
| 145 | RGBA_ASTC_12x10, |
| 146 | RGBA_ASTC_12x12, |
| 147 | SRGB8_Alpha8_ASTC_4x4, |
| 148 | SRGB8_Alpha8_ASTC_5x4, |
| 149 | SRGB8_Alpha8_ASTC_5x5, |
| 150 | SRGB8_Alpha8_ASTC_6x5, |
| 151 | SRGB8_Alpha8_ASTC_6x6, |
| 152 | SRGB8_Alpha8_ASTC_8x5, |
| 153 | SRGB8_Alpha8_ASTC_8x6, |
| 154 | SRGB8_Alpha8_ASTC_8x8, |
| 155 | SRGB8_Alpha8_ASTC_10x5, |
| 156 | SRGB8_Alpha8_ASTC_10x6, |
| 157 | SRGB8_Alpha8_ASTC_10x8, |
| 158 | SRGB8_Alpha8_ASTC_10x10, |
| 159 | SRGB8_Alpha8_ASTC_12x10, |
| 160 | SRGB8_Alpha8_ASTC_12x12, |
| 161 | BC1, |
| 162 | BC2, |
| 163 | BC3, |
| 164 | BC4, |
| 165 | BC5, |
| 166 | BC6H, |
| 167 | BC7, |
| 168 | }; |
| 169 | Format format; |
| 170 | |
| 171 | constexpr QSSGRenderTextureFormat(Format f) : format(f) {} |
| 172 | |
| 173 | [[nodiscard]] constexpr bool isCompressedTextureFormat() const noexcept |
| 174 | { |
| 175 | return (format & CompressedTextureFlag); |
| 176 | } |
| 177 | |
| 178 | [[nodiscard]] constexpr bool isUncompressedTextureFormat() const noexcept |
| 179 | { |
| 180 | return !isCompressedTextureFormat(); |
| 181 | } |
| 182 | |
| 183 | [[nodiscard]] bool isDepthTextureFormat() const noexcept |
| 184 | { |
| 185 | return (format & DepthTextureFlag); |
| 186 | } |
| 187 | |
| 188 | [[nodiscard]] const char *toString() const; |
| 189 | |
| 190 | [[nodiscard]] qint32 getSizeofFormat() const noexcept; |
| 191 | |
| 192 | [[nodiscard]] qint32 getNumberOfComponent() const noexcept; |
| 193 | |
| 194 | void decodeToFloat(void *inPtr, qint32 byteOfs, float *outPtr) const; |
| 195 | void encodeToPixel(float *inPtr, void *outPtr, qint32 byteOfs) const; |
| 196 | |
| 197 | bool operator==(const QSSGRenderTextureFormat &other) const { return format == other.format; } |
| 198 | bool operator!=(const QSSGRenderTextureFormat &other) const { return format != other.format; } |
| 199 | }; |
| 200 | |
| 201 | enum class QSSGRenderTextureFilterOp |
| 202 | { |
| 203 | None = 0, |
| 204 | Nearest, |
| 205 | Linear |
| 206 | }; |
| 207 | |
| 208 | enum class QSSGRenderTextureCoordOp : quint8 |
| 209 | { |
| 210 | Unknown = 0, |
| 211 | ClampToEdge, |
| 212 | MirroredRepeat, |
| 213 | Repeat |
| 214 | }; |
| 215 | |
| 216 | enum class QSSGCullFaceMode |
| 217 | { |
| 218 | Unknown = 0, |
| 219 | Back, |
| 220 | Front, |
| 221 | Disabled, |
| 222 | FrontAndBack, // Not exposed in the front-end |
| 223 | }; |
| 224 | |
| 225 | enum class QSSGDepthDrawMode |
| 226 | { |
| 227 | OpaqueOnly, |
| 228 | Always, |
| 229 | Never, |
| 230 | OpaquePrePass |
| 231 | }; |
| 232 | |
| 233 | template<typename TDataType> |
| 234 | struct QSSGRenderGenericVec2 |
| 235 | { |
| 236 | TDataType x; |
| 237 | TDataType y; |
| 238 | QSSGRenderGenericVec2(TDataType _x, TDataType _y) : x(_x), y(_y) {} |
| 239 | QSSGRenderGenericVec2() {} |
| 240 | bool operator==(const QSSGRenderGenericVec2 &inOther) const { return x == inOther.x && y == inOther.y; } |
| 241 | }; |
| 242 | |
| 243 | template<typename TDataType> |
| 244 | struct QSSGRenderGenericVec3 |
| 245 | { |
| 246 | TDataType x; |
| 247 | TDataType y; |
| 248 | TDataType z; |
| 249 | QSSGRenderGenericVec3(TDataType _x, TDataType _y, TDataType _z) : x(_x), y(_y), z(_z) {} |
| 250 | QSSGRenderGenericVec3() {} |
| 251 | bool operator==(const QSSGRenderGenericVec3 &inOther) const |
| 252 | { |
| 253 | return x == inOther.x && y == inOther.y && z == inOther.z; |
| 254 | } |
| 255 | }; |
| 256 | |
| 257 | template<typename TDataType> |
| 258 | struct QSSGRenderGenericVec4 |
| 259 | { |
| 260 | TDataType x; |
| 261 | TDataType y; |
| 262 | TDataType z; |
| 263 | TDataType w; |
| 264 | QSSGRenderGenericVec4(TDataType _x, TDataType _y, TDataType _z, TDataType _w) : x(_x), y(_y), z(_z), w(_w) {} |
| 265 | QSSGRenderGenericVec4() {} |
| 266 | bool operator==(const QSSGRenderGenericVec4 &inOther) const |
| 267 | { |
| 268 | return x == inOther.x && y == inOther.y && z == inOther.z && w == inOther.w; |
| 269 | } |
| 270 | }; |
| 271 | |
| 272 | namespace QSSGRenderShaderValue |
| 273 | { |
| 274 | enum Type : quint32 |
| 275 | { |
| 276 | Unknown = 0, |
| 277 | Integer, // qint32, |
| 278 | IntegerVec2, // qint32_2, |
| 279 | IntegerVec3, // qint32_3, |
| 280 | IntegerVec4, // qint32_4, |
| 281 | Boolean, // bool |
| 282 | BooleanVec2, // bool_2, |
| 283 | BooleanVec3, // bool_3, |
| 284 | BooleanVec4, // bool_4, |
| 285 | Float, // float, |
| 286 | Vec2, // QVector2D, |
| 287 | Vec3, // QVector3D, |
| 288 | Vec4, // QVector4D, |
| 289 | UnsignedInteger, // quint32, |
| 290 | UnsignedIntegerVec2, // quint32_2, |
| 291 | UnsignedIntegerVec3, // quint32_3, |
| 292 | UnsignedIntegerVec4, // quint32_4, |
| 293 | Matrix3x3, // QMatrix3x3, |
| 294 | Matrix4x4, // QMatrix4x4, |
| 295 | Rgba, // QColor |
| 296 | Size, // QSize |
| 297 | SizeF, // QSizeF |
| 298 | Point, // QPoint |
| 299 | PointF, // QPointF |
| 300 | Rect, // QRect |
| 301 | RectF, // QRectF |
| 302 | Quaternion, // QQuaternion |
| 303 | Texture, |
| 304 | }; |
| 305 | |
| 306 | using vec2 = QVector2D; |
| 307 | using vec3 = QVector3D; |
| 308 | using vec4 = QVector4D; |
| 309 | using bvec2 = QSSGRenderGenericVec2<bool>; |
| 310 | using bvec3 = QSSGRenderGenericVec3<bool>; |
| 311 | using bvec4 = QSSGRenderGenericVec4<bool>; |
| 312 | using ivec2 = QSSGRenderGenericVec2<qint32>; |
| 313 | using ivec3 = QSSGRenderGenericVec3<qint32>; |
| 314 | using ivec4 = QSSGRenderGenericVec4<qint32>; |
| 315 | using uvec2 = QSSGRenderGenericVec2<quint32>; |
| 316 | using uvec3 = QSSGRenderGenericVec3<quint32>; |
| 317 | using uvec4 = QSSGRenderGenericVec4<quint32>; |
| 318 | } |
| 319 | |
| 320 | enum class QSSGRenderTextureTypeValue |
| 321 | { |
| 322 | Unknown = 0, |
| 323 | Diffuse, |
| 324 | Specular, |
| 325 | Environment, |
| 326 | Bump, |
| 327 | Normal, |
| 328 | Emissive, |
| 329 | Anisotropy, |
| 330 | Translucent |
| 331 | }; |
| 332 | |
| 333 | enum class QSSGRenderTextureCubeFace : quint8 |
| 334 | { |
| 335 | PosX, |
| 336 | NegX, |
| 337 | PosY, |
| 338 | NegY, |
| 339 | PosZ, |
| 340 | NegZ |
| 341 | }; |
| 342 | |
| 343 | using QSSGRenderTextureCubeFaceT = std::underlying_type_t<QSSGRenderTextureCubeFace>; |
| 344 | |
| 345 | // Same order as expected by QRHI! |
| 346 | static constexpr QSSGRenderTextureCubeFace QSSGRenderTextureCubeFaces[] { |
| 347 | QSSGRenderTextureCubeFace::PosX, QSSGRenderTextureCubeFace::NegX, |
| 348 | QSSGRenderTextureCubeFace::PosY, QSSGRenderTextureCubeFace::NegY, |
| 349 | QSSGRenderTextureCubeFace::PosZ, QSSGRenderTextureCubeFace::NegZ |
| 350 | }; |
| 351 | |
| 352 | constexpr QSSGRenderTextureCubeFaceT QSSGRenderTextureCubeFaceMask { 0xf }; |
| 353 | constexpr QSSGRenderTextureCubeFace QSSGRenderTextureCubeFaceNone { QSSGRenderTextureCubeFaceT(1 << 4) }; |
| 354 | |
| 355 | class Q_QUICK3DUTILS_EXPORT QSSGBaseTypeHelpers |
| 356 | { |
| 357 | QSSGBaseTypeHelpers() = default; |
| 358 | public: |
| 359 | // Enum as string |
| 360 | static const char *toString(QSSGRenderTextureCubeFace value); |
| 361 | static const char *toString(QSSGRenderTextureTypeValue value); |
| 362 | static const char *toString(QSSGDepthDrawMode value); |
| 363 | static const char *toString(QSSGRenderWinding value); |
| 364 | static const char *toString(QSSGCullFaceMode value); |
| 365 | static const char *toString(QSSGRenderComponentType value); |
| 366 | static const char *toString(QSSGRenderTextureFormat::Format value); |
| 367 | static const char *toString(QSSGRenderTextureCoordOp value); |
| 368 | static const char *toString(QSSGRenderTextureFilterOp value); |
| 369 | |
| 370 | static const char *displayName(QSSGRenderTextureCubeFace face); |
| 371 | |
| 372 | static size_t getSizeOfType(QSSGRenderComponentType type); |
| 373 | |
| 374 | // Note: These will wrap around |
| 375 | static constexpr QSSGRenderTextureCubeFace next(QSSGRenderTextureCubeFace face) |
| 376 | { return (face == QSSGRenderTextureCubeFaces[5]) ? QSSGRenderTextureCubeFaces[0] : QSSGRenderTextureCubeFace(quint8(face) + 1); } |
| 377 | static constexpr QSSGRenderTextureCubeFace prev(QSSGRenderTextureCubeFace face) |
| 378 | { return (face == QSSGRenderTextureCubeFaces[0]) ? QSSGRenderTextureCubeFaces[5] : QSSGRenderTextureCubeFace(quint8(face) - 1); } |
| 379 | |
| 380 | static constexpr QSSGRenderTextureCubeFaceT indexOfCubeFace(QSSGRenderTextureCubeFace face) noexcept { return QSSGRenderTextureCubeFaceT(face) & 0xf; } |
| 381 | }; |
| 382 | |
| 383 | QT_END_NAMESPACE |
| 384 | |
| 385 | #endif // QSSGRENDERBASETYPES_P_H |
| 386 | |