Qt 6.x
The Qt SDK
Loading...
Searching...
No Matches
qssgrenderbasetypes_p.h
Go to the documentation of this file.
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 QSSGN_RENDERQSSGDER_TYPES_H
6#define QSSGN_RENDERQSSGDER_TYPES_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/private/qssgdataref_p.h>
20
21#include <QtQuick3DUtils/private/qtquick3dutilsglobal_p.h>
22
23#include <QtGui/QVector2D>
24#include <QtGui/QVector3D>
25#include <QtGui/QVector4D>
26#include <QtGui/QMatrix4x4>
27#include <QtGui/QMatrix3x3>
28#include <QFloat16>
29
30#include <cmath>
31
33
34enum class QSSGRenderComponentType // stored in mesh files, the values must not change, must match Mesh::ComponentType
35{
36 UnsignedInt8 = 1,
37 Int8,
39 Int16,
41 Int32,
43 Int64,
44 Float16,
45 Float32,
47};
48
49enum class QSSGRenderDrawMode // stored in mesh files, the values must not change, must match Mesh::DrawMode
50{
51 Points = 1,
53 LineLoop, // Not supported
54 Lines,
58};
59
60enum class QSSGRenderWinding // stored in mesh files, the values must not change, must match Mesh::Winding
61{
62 Clockwise = 1,
64};
65
66struct Q_QUICK3DUTILS_PRIVATE_EXPORT QSSGRenderTextureFormat
67{
68 static constexpr quint8 DepthTextureFlag = 1u << 6;
69 static constexpr quint8 CompressedTextureFlag = 1u << 7;
70
71 enum Format : quint8 {
72 // Non-compressed formats
113
114 // Depth textures
115 Depth16 = DepthTextureFlag + 1,
119
120 // Compressed formats
121 RGBA_DXT1 = CompressedTextureFlag + 1,
170 };
172
174
175 [[nodiscard]] constexpr bool isCompressedTextureFormat() const noexcept
176 {
177 return (format & CompressedTextureFlag);
178 }
179
180 [[nodiscard]] constexpr bool isUncompressedTextureFormat() const noexcept
181 {
182 return !isCompressedTextureFormat();
183 }
184
185 [[nodiscard]] bool isDepthTextureFormat() const noexcept
186 {
187 return (format & DepthTextureFlag);
188 }
189
190 [[nodiscard]] const char *toString() const;
191
193 {
194 switch (format) {
195 case R8:
196 return 1;
197 case R16F:
198 return 2;
199 case R16:
200 return 2;
201 case R32I:
202 return 4;
203 case R32F:
204 return 4;
205 case RGBE8:
206 case RGBA8:
207 return 4;
208 case RGB8:
209 return 3;
210 case RGB565:
211 return 2;
212 case RGBA5551:
213 return 2;
214 case Alpha8:
215 return 1;
216 case Luminance8:
217 return 1;
218 case LuminanceAlpha8:
219 return 1;
220 case Depth16:
221 return 2;
222 case Depth24:
223 return 3;
224 case Depth32:
225 return 4;
226 case Depth24Stencil8:
227 return 4;
228 case RGB9E5:
229 return 4;
230 case SRGB8:
231 return 3;
232 case SRGB8A8:
233 return 4;
234 case RGBA16F:
235 return 8;
236 case RG16F:
237 return 4;
238 case RG32F:
239 return 8;
240 case RGBA32F:
241 return 16;
242 case RGB32F:
243 return 12;
244 case R11G11B10:
245 return 4;
246 default:
247 break;
248 }
249 Q_ASSERT(false);
250 return 0;
251 }
252
254 {
255 switch (format) {
256 case R8:
257 return 1;
258 case R16F:
259 return 1;
260 case R16:
261 return 1;
262 case R32I:
263 return 1;
264 case R32F:
265 return 1;
266 case RGBA8:
267 return 4;
268 case RGB8:
269 return 3;
270 case RGB565:
271 return 3;
272 case RGBA5551:
273 return 4;
274 case Alpha8:
275 return 1;
276 case Luminance8:
277 return 1;
278 case LuminanceAlpha8:
279 return 2;
280 case Depth16:
281 return 1;
282 case Depth24:
283 return 1;
284 case Depth32:
285 return 1;
286 case Depth24Stencil8:
287 return 2;
288 case RGB9E5:
289 return 3;
290 case SRGB8:
291 return 3;
292 case SRGB8A8:
293 return 4;
294 case RGBA16F:
295 return 4;
296 case RG16F:
297 return 2;
298 case RG32F:
299 return 2;
300 case RGBA32F:
301 return 4;
302 case RGB32F:
303 return 3;
304 case R11G11B10:
305 return 3;
306 case RGBE8:
307 return 4;
308 default:
309 break;
310 }
311 Q_ASSERT(false);
312 return 0;
313 }
314
315 struct M8E8
316 {
319 M8E8() : m(0), e(0){
320 }
321 M8E8(const float val) {
322 float l2 = 1.f + std::floor(log2f(val));
323 float mm = val / powf(2.f, l2);
324 m = quint8(mm * 255.f);
325 e = quint8(l2 + 128);
326 }
327 M8E8(const float val, quint8 exp) {
328 if (val <= 0) {
329 m = e = 0;
330 return;
331 }
332 float mm = val / powf(2.f, exp - 128);
333 m = quint8(mm * 255.f);
334 e = exp;
335 }
336 };
337
338 void decodeToFloat(void *inPtr, qint32 byteOfs, float *outPtr) const;
339 void encodeToPixel(float *inPtr, void *outPtr, qint32 byteOfs) const;
340
341 bool operator==(const QSSGRenderTextureFormat &other) const { return format == other.format; }
342 bool operator!=(const QSSGRenderTextureFormat &other) const { return format != other.format; }
343};
344
346{
347 None = 0,
348 Nearest,
349 Linear
350};
351
353{
354 Unknown = 0,
357 Repeat
358};
359
361{
369
372 quint32 numComponents,
373 quint32 firstItemOffset = 0)
374 : m_name(nm), m_componentType(type), m_numComponents(numComponents), m_firstItemOffset(firstItemOffset)
375 {
376 }
377
380 {
381 }
382
384 : m_name(inOther.m_name)
388 {
389 }
390
392 {
393 if (this != &inOther) {
394 m_name = inOther.m_name;
398 }
399 return *this;
400 }
401};
402
404{
405 Unknown = 0,
406 Back,
407 Front,
408 Disabled,
409 FrontAndBack, // Not exposed in the front-end
410};
411
413{
415 Always,
416 Never,
418};
419
420// Return coordinates in pixels but relative to this rect.
421inline QVector2D toRectRelative(const QRectF &r, const QVector2D &absoluteCoordinates)
422{
423 return QVector2D(absoluteCoordinates.x() - float(r.x()), absoluteCoordinates.y() - float(r.y()));
424}
425
427{
428 return QVector2D(float(r.width() / 2.0), float(r.height() / 2.0));
429}
430
431// Take coordinates in global space and move local space where 0,0 is the center
432// of the rect but return value in pixels, not in normalized -1,1 range
433inline QVector2D toNormalizedRectRelative(const QRectF &r, QVector2D absoluteCoordinates)
434{
435 // normalize them
436 const QVector2D relativeCoords(toRectRelative(r, absoluteCoordinates));
437 const QVector2D halfD(halfDims(r));
438 const QVector2D normalized((relativeCoords.x() / halfD.x()) - 1.0f, (relativeCoords.y() / halfD.y()) - 1.0f);
439 return QVector2D(normalized.x() * halfD.x(), normalized.y() * halfD.y());
440}
441
443{
444 return { (rectRelativeCoords.x() / halfDims(r).x()) - 1.0f, (rectRelativeCoords.y() / halfDims(r).y()) - 1.0f };
445}
446
447// Normalized coordinates are in the range of -1,1 where -1 is the left, bottom edges
448// and 1 is the top,right edges.
449inline QVector2D absoluteToNormalizedCoordinates(const QRectF &r, const QVector2D &absoluteCoordinates)
450{
451 return relativeToNormalizedCoordinates(r, toRectRelative(r, absoluteCoordinates));
452}
453
454inline QVector2D toAbsoluteCoords(const QRectF &r, const QVector2D &inRelativeCoords)
455{
456 return QVector2D(inRelativeCoords.x() + float(r.x()), inRelativeCoords.y() + float(r.y()));
457}
458
459template<typename TDataType>
461{
462 TDataType x;
463 TDataType y;
464 QSSGRenderGenericVec2(TDataType _x, TDataType _y) : x(_x), y(_y) {}
466 bool operator==(const QSSGRenderGenericVec2 &inOther) const { return x == inOther.x && y == inOther.y; }
467};
468
469template<typename TDataType>
471{
472 TDataType x;
473 TDataType y;
474 TDataType z;
475 QSSGRenderGenericVec3(TDataType _x, TDataType _y, TDataType _z) : x(_x), y(_y), z(_z) {}
477 bool operator==(const QSSGRenderGenericVec3 &inOther) const
478 {
479 return x == inOther.x && y == inOther.y && z == inOther.z;
480 }
481};
482
483template<typename TDataType>
485{
486 TDataType x;
487 TDataType y;
488 TDataType z;
489 TDataType w;
490 QSSGRenderGenericVec4(TDataType _x, TDataType _y, TDataType _z, TDataType _w) : x(_x), y(_y), z(_z), w(_w) {}
492 bool operator==(const QSSGRenderGenericVec4 &inOther) const
493 {
494 return x == inOther.x && y == inOther.y && z == inOther.z && w == inOther.w;
495 }
496};
497
507
509{
510 Unknown = 0,
511 Integer, // qint32,
512 IntegerVec2, // qint32_2,
513 IntegerVec3, // qint32_3,
514 IntegerVec4, // qint32_4,
515 Boolean, // bool
516 BooleanVec2, // bool_2,
517 BooleanVec3, // bool_3,
518 BooleanVec4, // bool_4,
519 Float, // float,
520 Vec2, // QVector2D,
521 Vec3, // QVector3D,
522 Vec4, // QVector4D,
523 UnsignedInteger, // quint32,
524 UnsignedIntegerVec2, // quint32_2,
525 UnsignedIntegerVec3, // quint32_3,
526 UnsignedIntegerVec4, // quint32_4,
527 Matrix3x3, // QMatrix3x3,
528 Matrix4x4, // QMatrix4x4,
529 Rgba, // QColor
530 Size, // QSize
531 SizeF, // QSizeF
532 Point, // QPoint
533 PointF, // QPointF
534 Rect, // QRect
535 RectF, // QRectF
536 Quaternion, // QQuaternion
537 Texture,
538};
539
541{
542 Unknown = 0,
543 Diffuse,
544 Specular,
546 Bump,
547 Normal,
548 Emissive,
551};
552
554{
555 PosX,
556 NegX,
557 PosY,
558 NegY,
559 PosZ,
560 NegZ
561};
562
563// Same order as expected by QRHI!
568};
569
570class Q_QUICK3DUTILS_PRIVATE_EXPORT QSSGBaseTypeHelpers
571{
572 QSSGBaseTypeHelpers() = default;
573public:
574 // Enum as string
575 static const char *toString(QSSGRenderTextureCubeFace value);
576 static const char *toString(QSSGRenderTextureTypeValue value);
577 static const char *toString(QSSGDepthDrawMode value);
578 static const char *toString(QSSGRenderWinding value);
579 static const char *toString(QSSGCullFaceMode value);
580 static const char *toString(QSSGRenderComponentType value);
582 static const char *toString(QSSGRenderTextureCoordOp value);
583 static const char *toString(QSSGRenderTextureFilterOp value);
584
585 static const char *displayName(QSSGRenderTextureCubeFace face);
586
587 static size_t getSizeOfType(QSSGRenderComponentType type);
588
589 // Note: These will wrap around
594};
595
597
598#endif
\inmodule QtCore
Definition qbytearray.h:57
\inmodule QtCore\reentrant
Definition qrect.h:483
static constexpr QSSGRenderTextureCubeFace next(QSSGRenderTextureCubeFace face)
static constexpr QSSGRenderTextureCubeFace prev(QSSGRenderTextureCubeFace face)
The QVector2D class represents a vector or vertex in 2D space.
Definition qvectornd.h:31
constexpr float y() const noexcept
Returns the y coordinate of this point.
Definition qvectornd.h:502
constexpr float x() const noexcept
Returns the x coordinate of this point.
Definition qvectornd.h:501
double e
Combined button and popup list for selecting options.
static QString displayName(CGDirectDisplayID displayID)
EGLOutputLayerEXT EGLint EGLAttrib value
[5]
GLuint GLfloat GLfloat GLfloat GLfloat GLfloat z
GLint GLint GLint GLint GLint x
[0]
const GLfloat * m
GLfloat GLfloat GLfloat w
[0]
GLboolean r
[2]
GLenum face
GLfloat GLfloat f
GLenum type
GLint GLsizei GLsizei GLenum format
GLint y
GLuint GLfloat * val
GLint GLenum GLboolean normalized
Definition qopenglext.h:752
#define Q_ASSERT(cond)
Definition qrandom.cpp:47
QSSGRenderGenericVec3< bool > bool_3
QVector2D toRectRelative(const QRectF &r, const QVector2D &absoluteCoordinates)
static constexpr QSSGRenderTextureCubeFace QSSGRenderTextureCubeFaces[]
QSSGRenderTextureCubeFace
QSSGRenderGenericVec3< qint32 > qint32_3
QSSGRenderGenericVec3< quint32 > quint32_3
QVector2D relativeToNormalizedCoordinates(const QRectF &r, QVector2D rectRelativeCoords)
QSSGRenderTextureCoordOp
QSSGRenderGenericVec4< qint32 > qint32_4
QSSGRenderShaderDataType
QVector2D absoluteToNormalizedCoordinates(const QRectF &r, const QVector2D &absoluteCoordinates)
QSSGRenderTextureFilterOp
QVector2D toAbsoluteCoords(const QRectF &r, const QVector2D &inRelativeCoords)
QSSGRenderTextureTypeValue
QSSGRenderGenericVec2< bool > bool_2
QVector2D halfDims(const QRectF &r)
QSSGRenderGenericVec2< qint32 > qint32_2
QSSGRenderComponentType
QVector2D toNormalizedRectRelative(const QRectF &r, QVector2D absoluteCoordinates)
QSSGRenderGenericVec4< quint32 > quint32_4
QSSGRenderGenericVec2< quint32 > quint32_2
QSSGRenderGenericVec4< bool > bool_4
unsigned int quint32
Definition qtypes.h:45
int qint32
Definition qtypes.h:44
unsigned char quint8
Definition qtypes.h:41
QSharedPointer< T > other(t)
[5]
char * toString(const MyType &t)
[31]
QSSGRenderGenericVec2(TDataType _x, TDataType _y)
bool operator==(const QSSGRenderGenericVec2 &inOther) const
QSSGRenderGenericVec3(TDataType _x, TDataType _y, TDataType _z)
bool operator==(const QSSGRenderGenericVec3 &inOther) const
bool operator==(const QSSGRenderGenericVec4 &inOther) const
QSSGRenderGenericVec4(TDataType _x, TDataType _y, TDataType _z, TDataType _w)
M8E8(const float val, quint8 exp)
bool isDepthTextureFormat() const noexcept
bool operator==(const QSSGRenderTextureFormat &other) const
bool operator!=(const QSSGRenderTextureFormat &other) const
constexpr bool isCompressedTextureFormat() const noexcept
constexpr QSSGRenderTextureFormat(Format f)
constexpr bool isUncompressedTextureFormat() const noexcept
QSSGRenderVertexBufferEntry & operator=(const QSSGRenderVertexBufferEntry &inOther)
QSSGRenderVertexBufferEntry(const QSSGRenderVertexBufferEntry &inOther)
QSSGRenderVertexBufferEntry(const QByteArray &nm, QSSGRenderComponentType type, quint32 numComponents, quint32 firstItemOffset=0)
QSSGRenderComponentType m_componentType