1 /****************************************************************************
2 **
3 ** Copyright (C) 2008-2012 NVIDIA Corporation.
4 ** Copyright (C) 2019 The Qt Company Ltd.
5 ** Contact: https://www.qt.io/licensing/
6 **
7 ** This file is part of Qt Quick 3D.
8 **
9 ** $QT_BEGIN_LICENSE:GPL$
10 ** Commercial License Usage
11 ** Licensees holding valid commercial Qt licenses may use this file in
12 ** accordance with the commercial license agreement provided with the
13 ** Software or, alternatively, in accordance with the terms contained in
14 ** a written agreement between you and The Qt Company. For licensing terms
15 ** and conditions see https://www.qt.io/terms-conditions. For further
16 ** information use the contact form at https://www.qt.io/contact-us.
17 **
18 ** GNU General Public License Usage
19 ** Alternatively, this file may be used under the terms of the GNU
20 ** General Public License version 3 or (at your option) any later version
21 ** approved by the KDE Free Qt Foundation. The licenses are as published by
22 ** the Free Software Foundation and appearing in the file LICENSE.GPL3
23 ** included in the packaging of this file. Please review the following
24 ** information to ensure the GNU General Public License requirements will
25 ** be met: https://www.gnu.org/licenses/gpl-3.0.html.
26 **
27 ** $QT_END_LICENSE$
28 **
29 ****************************************************************************/
30 
31 #ifndef QSSGN_RENDERQSSGDER_TYPES_H
32 #define QSSGN_RENDERQSSGDER_TYPES_H
33 
34 //
35 //  W A R N I N G
36 //  -------------
37 //
38 // This file is not part of the Qt API.  It exists purely as an
39 // implementation detail.  This header file may change from version to
40 // version without notice, or even be removed.
41 //
42 // We mean it.
43 //
44 
45 #include <QtQuick3DUtils/private/qssgdataref_p.h>
46 
47 #include <QtQuick3DRender/private/qtquick3drenderglobal_p.h>
48 #include <QtQuick3DRender/private/qssgrenderlogging_p.h>
49 
50 #include <QtGui/QVector2D>
51 #include <QtGui/QVector3D>
52 #include <QtGui/QVector4D>
53 #include <QtGui/QMatrix4x4>
54 #include <QtGui/QMatrix3x3>
55 #include <QFloat16>
56 
57 #include <cmath>
58 
59 QT_BEGIN_NAMESPACE
60 
61 enum class QSSGRenderComponentType
62 {
63     Unknown = 0,
64     UnsignedInteger8,
65     Integer8,
66     UnsignedInteger16,
67     Integer16,
68     UnsignedInteger32,
69     Integer32,
70     UnsignedInteger64,
71     Integer64,
72     Float16,
73     Float32,
74     Float64
75 };
76 
toString(QSSGRenderComponentType value)77 inline const char *toString(QSSGRenderComponentType value)
78 {
79     switch (value) {
80     case QSSGRenderComponentType::UnsignedInteger8:
81         return "UnsignedInteger8";
82     case QSSGRenderComponentType::Integer8:
83         return "Integer8";
84     case QSSGRenderComponentType::UnsignedInteger16:
85         return "UnsignedInteger16";
86     case QSSGRenderComponentType::Integer16:
87         return "Integer16";
88     case QSSGRenderComponentType::UnsignedInteger32:
89         return "UnsignedInteger32";
90     case QSSGRenderComponentType::Integer32:
91         return "Integer32";
92     case QSSGRenderComponentType::UnsignedInteger64:
93         return "UnsignedInteger64";
94     case QSSGRenderComponentType::Integer64:
95         return "Integer64";
96     case QSSGRenderComponentType::Float16:
97         return "Float16";
98     case QSSGRenderComponentType::Float32:
99         return "Float32";
100     case QSSGRenderComponentType::Float64:
101         return "Float64";
102     default:
103         break;
104     }
105     return "Unknown";
106 }
107 
getSizeOfType(QSSGRenderComponentType value)108 inline quint32 getSizeOfType(QSSGRenderComponentType value)
109 {
110     switch (value) {
111     case QSSGRenderComponentType::UnsignedInteger8:
112         return sizeof(quint8);
113     case QSSGRenderComponentType::Integer8:
114         return sizeof(qint8);
115     case QSSGRenderComponentType::UnsignedInteger16:
116         return sizeof(quint16);
117     case QSSGRenderComponentType::Integer16:
118         return sizeof(qint16);
119     case QSSGRenderComponentType::UnsignedInteger32:
120         return sizeof(quint32);
121     case QSSGRenderComponentType::Integer32:
122         return sizeof(qint32);
123     case QSSGRenderComponentType::UnsignedInteger64:
124         return sizeof(quint64);
125     case QSSGRenderComponentType::Integer64:
126         return sizeof(qint64);
127     case QSSGRenderComponentType::Float16:
128         return sizeof(qfloat16);
129     case QSSGRenderComponentType::Float32:
130         return sizeof(float);
131     case QSSGRenderComponentType::Float64:
132         return sizeof(double);
133     default:
134         break;
135     }
136     Q_ASSERT(false);
137     return 0;
138 }
139 
140 enum class QSSGRenderContextType : quint32
141 {
142     GLES2 = 1 << 0,
143     GL2 = 1 << 1,
144     GLES3 = 1 << 2,
145     GL3 = 1 << 3,
146     GLES3PLUS = 1 << 4,
147     GL4 = 1 << 5,
148     NullContext = 1 << 6,
149 };
150 
151 Q_DECLARE_FLAGS(QSSGRenderContextTypes, QSSGRenderContextType)
152 Q_DECLARE_OPERATORS_FOR_FLAGS(QSSGRenderContextTypes)
153 
154 enum class QSSGRenderClearValues : quint32
155 {
156     Color = 1 << 0,
157     Depth = 1 << 1,
158     Stencil = 1 << 3,
159     Coverage = 1 << 4,
160 };
161 
162 Q_DECLARE_FLAGS(QSSGRenderClearFlags, QSSGRenderClearValues)
163 Q_DECLARE_OPERATORS_FOR_FLAGS(QSSGRenderClearFlags)
164 
165 enum class QSSGRenderQueryType
166 {
167     Unknown = 0,
168     Samples, ///< samples query object
169     Timer, ///< timer query object
170 };
171 
172 enum class QSSGRenderQueryResultType
173 {
174     Unknown = 0,
175     ResultAvailable, ///< Check if query result is available
176     Result, ///< Get actual result
177 };
178 
179 enum class QSSGRenderSyncType
180 {
181     Unknown = 0,
182     GpuCommandsComplete, ///< sync to Gpu commands finished
183 };
184 
185 enum class QSSGRenderSyncValues
186 {
187     Unknown = 0, ///< for future usage
188 };
189 
190 Q_DECLARE_FLAGS(QSSGRenderSyncFlags, QSSGRenderSyncValues)
191 Q_DECLARE_OPERATORS_FOR_FLAGS(QSSGRenderSyncFlags)
192 
193 enum class QSSGRenderCommandFlushValues
194 {
195     SyncFlushCommands = 0, ///< sync for flushing command
196 };
197 
198 Q_DECLARE_FLAGS(QSSGRenderCommandFlushFlags, QSSGRenderCommandFlushValues)
199 Q_DECLARE_OPERATORS_FOR_FLAGS(QSSGRenderCommandFlushFlags)
200 
201 enum class QSSGRenderBufferType : quint32
202 {
203     Vertex, ///< Bind as vertex buffer
204     Index, ///< Bind as index buffer
205     Constant, ///< Bind as constant buffer
206     Storage, ///< Bind as shader storage buffer
207 };
208 
209 enum class QSSGRenderBufferUsageType
210 {
211     Unknown = 0,
212     Static, ///< Rarely updated
213     Dynamic, ///< Most likely updated every frame
214 };
215 
216 enum class QSSGRenderImageAccessType
217 {
218     Unknown = 0,
219     Read, ///< Read only access
220     Write, ///< Write only access
221     ReadWrite, ///< Read and write access
222 };
223 
224 enum class QSSGRenderBufferAccessTypeValues
225 {
226     Unknown = 0,
227     Read = 1 << 0, ///< Read access
228     Write = 1 << 1, ///< Write access
229     Invalid = 1 << 2, ///< No sync
230     InvalidRange = 1 << 3, ///< No sync
231 };
232 
233 Q_DECLARE_FLAGS(QSSGRenderBufferAccessFlags, QSSGRenderBufferAccessTypeValues)
234 Q_DECLARE_OPERATORS_FOR_FLAGS(QSSGRenderBufferAccessFlags)
235 
236 ///< defines a barrier of ordering the memory transactions to a command relative to those issued
237 /// before the barrier
238 enum class QSSGRenderBufferBarrierValues
239 {
240     Unknown = 0,
241     VertexAttribArray = 1 << 0, ///< Barrier for vertex attributes sourced from a buffer
242     ElementArray = 1 << 1, ///< Barrier for indices sourced from a buffer
243     UniformBuffer = 1 << 2, ///< Barrier for shader uniforms sourced from a buffer
244     TextureFetch = 1 << 3, ///< Barrier for texture fetches within shaders
245     ShaderImageAccess = 1 << 4, ///< Barrier for image access using load / store
246     CommandBuffer = 1 << 5, ///< Barrier for indirect drawing
247     PixelBuffer = 1 << 6, ///< Barrier for pixel buffer access
248     TextureUpdate = 1 << 7, ///< Barrier for texture writes
249     BufferUpdate = 1 << 8, ///< Barrier for buffer writes
250     Framebuffer = 1 << 9, ///< Barrier for framebuffer writes
251     TransformFeedback = 1 << 10, ///< Barrier for transform feedback writes
252     AtomicCounter = 1 << 11, ///< Barrier for atomic counter writes
253     ShaderStorage = 1 << 12, ///< Barrier for shader storage blocks writes
254     All = 0xFFFF, ///< Barrier for all of the above
255 };
256 
257 Q_DECLARE_FLAGS(QSSGRenderBufferBarrierFlags, QSSGRenderBufferBarrierValues)
258 Q_DECLARE_OPERATORS_FOR_FLAGS(QSSGRenderBufferBarrierFlags)
259 
260 enum class QSSGRenderRenderBufferFormat
261 {
262     Unknown = 0,
263     RGBA4,
264     RGB565,
265     RGBA5551,
266     Depth16,
267     Depth24,
268     Depth32,
269     StencilIndex8,
270     CoverageNV
271 };
272 
toString(QSSGRenderRenderBufferFormat value)273 inline const char *toString(QSSGRenderRenderBufferFormat value)
274 {
275     switch (value) {
276     case QSSGRenderRenderBufferFormat::RGBA4:
277         return "RGBA4";
278     case QSSGRenderRenderBufferFormat::RGB565:
279         return "RGB565";
280     case QSSGRenderRenderBufferFormat::RGBA5551:
281         return "RGBA5551";
282     case QSSGRenderRenderBufferFormat::Depth16:
283         return "Depth16";
284     case QSSGRenderRenderBufferFormat::Depth24:
285         return "Depth24";
286     case QSSGRenderRenderBufferFormat::Depth32:
287         return "Depth32";
288     case QSSGRenderRenderBufferFormat::StencilIndex8:
289         return "StencilIndex8";
290     case QSSGRenderRenderBufferFormat::CoverageNV:
291         return "CoverageNV";
292     default:
293         break;
294     }
295     return "Unknown";
296 }
297 
298 struct QSSGRenderTextureFormat
299 {
300     enum Format : quint8 {
301         Unknown = 0,
302         R8,
303         R16,
304         R16F,
305         R32I,
306         R32UI,
307         R32F,
308         RG8,
309         RGBA8,
310         RGB8,
311         SRGB8,
312         SRGB8A8,
313         RGB565,
314         RGBA5551,
315         Alpha8,
316         Luminance8,
317         Luminance16,
318         LuminanceAlpha8,
319         RGBA16F,
320         RG16F,
321         RG32F,
322         RGB32F,
323         RGBA32F,
324         R11G11B10,
325         RGB9E5,
326         RGB10_A2,
327         RGB16F,
328         RGBA32UI,
329         RGB32UI,
330         RGBA16UI,
331         RGB16UI,
332         RGBA8UI,
333         RGB8UI,
334         RGBA32I,
335         RGB32I,
336         RGBA16I,
337         RGB16I,
338         RGBA8I,
339         RGB8I,
340         RGBE8,
341         RGBA_DXT1,
342         RGB_DXT1,
343         RGBA_DXT3,
344         RGBA_DXT5,
345         R11_EAC_UNorm,
346         R11_EAC_SNorm,
347         RG11_EAC_UNorm,
348         RG11_EAC_SNorm,
349         RGB8_ETC2,
350         SRGB8_ETC2,
351         RGB8_PunchThrough_Alpha1_ETC2,
352         SRGB8_PunchThrough_Alpha1_ETC2,
353         RGBA8_ETC2_EAC,
354         SRGB8_Alpha8_ETC2_EAC,
355 //        RGB8_ETC1,
356         RGBA_ASTC_4x4,
357         RGBA_ASTC_5x4,
358         RGBA_ASTC_5x5,
359         RGBA_ASTC_6x5,
360         RGBA_ASTC_6x6,
361         RGBA_ASTC_8x5,
362         RGBA_ASTC_8x6,
363         RGBA_ASTC_8x8,
364         RGBA_ASTC_10x5,
365         RGBA_ASTC_10x6,
366         RGBA_ASTC_10x8,
367         RGBA_ASTC_10x10,
368         RGBA_ASTC_12x10,
369         RGBA_ASTC_12x12,
370         SRGB8_Alpha8_ASTC_4x4,
371         SRGB8_Alpha8_ASTC_5x4,
372         SRGB8_Alpha8_ASTC_5x5,
373         SRGB8_Alpha8_ASTC_6x5,
374         SRGB8_Alpha8_ASTC_6x6,
375         SRGB8_Alpha8_ASTC_8x5,
376         SRGB8_Alpha8_ASTC_8x6,
377         SRGB8_Alpha8_ASTC_8x8,
378         SRGB8_Alpha8_ASTC_10x5,
379         SRGB8_Alpha8_ASTC_10x6,
380         SRGB8_Alpha8_ASTC_10x8,
381         SRGB8_Alpha8_ASTC_10x10,
382         SRGB8_Alpha8_ASTC_12x10,
383         SRGB8_Alpha8_ASTC_12x12,
384         Depth16,
385         Depth24,
386         Depth32,
387         Depth24Stencil8
388     };
389     Format format;
390 
QSSGRenderTextureFormatQSSGRenderTextureFormat391     constexpr QSSGRenderTextureFormat(Format f) : format(f) {}
392 
isUncompressedTextureFormatQSSGRenderTextureFormat393     bool isUncompressedTextureFormat() const
394     {
395         switch (format) {
396         case QSSGRenderTextureFormat::R8:
397             return true;
398         case QSSGRenderTextureFormat::R16:
399             return true;
400         case QSSGRenderTextureFormat::R16F:
401             return true;
402         case QSSGRenderTextureFormat::R32I:
403             return true;
404         case QSSGRenderTextureFormat::R32UI:
405             return true;
406         case QSSGRenderTextureFormat::R32F:
407             return true;
408         case QSSGRenderTextureFormat::RG8:
409             return true;
410         case QSSGRenderTextureFormat::RGBA8:
411             return true;
412         case QSSGRenderTextureFormat::RGB8:
413             return true;
414         case QSSGRenderTextureFormat::SRGB8:
415             return true;
416         case QSSGRenderTextureFormat::SRGB8A8:
417             return true;
418         case QSSGRenderTextureFormat::RGB565:
419             return true;
420         case QSSGRenderTextureFormat::RGBA5551:
421             return true;
422         case QSSGRenderTextureFormat::Alpha8:
423             return true;
424         case QSSGRenderTextureFormat::Luminance8:
425             return true;
426         case QSSGRenderTextureFormat::Luminance16:
427             return true;
428         case QSSGRenderTextureFormat::LuminanceAlpha8:
429             return true;
430         case QSSGRenderTextureFormat::RGBA16F:
431             return true;
432         case QSSGRenderTextureFormat::RG16F:
433             return true;
434         case QSSGRenderTextureFormat::RG32F:
435             return true;
436         case QSSGRenderTextureFormat::RGB32F:
437             return true;
438         case QSSGRenderTextureFormat::RGBA32F:
439             return true;
440         case QSSGRenderTextureFormat::R11G11B10:
441             return true;
442         case QSSGRenderTextureFormat::RGB9E5:
443             return true;
444         case QSSGRenderTextureFormat::RGB10_A2:
445             return true;
446         case QSSGRenderTextureFormat::RGB16F:
447             return true;
448         case QSSGRenderTextureFormat::RGBA32UI:
449             return true;
450         case QSSGRenderTextureFormat::RGB32UI:
451             return true;
452         case QSSGRenderTextureFormat::RGBA16UI:
453             return true;
454         case QSSGRenderTextureFormat::RGB16UI:
455             return true;
456         case QSSGRenderTextureFormat::RGBA8UI:
457             return true;
458         case QSSGRenderTextureFormat::RGB8UI:
459             return true;
460         case QSSGRenderTextureFormat::RGBA32I:
461             return true;
462         case QSSGRenderTextureFormat::RGB32I:
463             return true;
464         case QSSGRenderTextureFormat::RGBA16I:
465             return true;
466         case QSSGRenderTextureFormat::RGB16I:
467             return true;
468         case QSSGRenderTextureFormat::RGBA8I:
469             return true;
470         case QSSGRenderTextureFormat::RGB8I:
471             return true;
472         case QSSGRenderTextureFormat::RGBE8:
473             return true;
474         default:
475             break;
476         }
477         return false;
478     }
479 
isCompressedTextureFormatQSSGRenderTextureFormat480     bool isCompressedTextureFormat() const
481     {
482         switch (format) {
483         case QSSGRenderTextureFormat::RGBA_DXT1:
484             return true;
485         case QSSGRenderTextureFormat::RGB_DXT1:
486             return true;
487         case QSSGRenderTextureFormat::RGBA_DXT3:
488             return true;
489         case QSSGRenderTextureFormat::RGBA_DXT5:
490             return true;
491         case QSSGRenderTextureFormat::R11_EAC_UNorm:
492         case QSSGRenderTextureFormat::R11_EAC_SNorm:
493         case QSSGRenderTextureFormat::RG11_EAC_UNorm:
494         case QSSGRenderTextureFormat::RG11_EAC_SNorm:
495         case QSSGRenderTextureFormat::RGB8_ETC2:
496         case QSSGRenderTextureFormat::SRGB8_ETC2:
497         case QSSGRenderTextureFormat::RGB8_PunchThrough_Alpha1_ETC2:
498         case QSSGRenderTextureFormat::SRGB8_PunchThrough_Alpha1_ETC2:
499         case QSSGRenderTextureFormat::RGBA8_ETC2_EAC:
500         case QSSGRenderTextureFormat::SRGB8_Alpha8_ETC2_EAC:
501 //        case QSSGRenderTextureFormat::RGB8_ETC1:
502         case QSSGRenderTextureFormat::RGBA_ASTC_4x4:
503         case QSSGRenderTextureFormat::RGBA_ASTC_5x4:
504         case QSSGRenderTextureFormat::RGBA_ASTC_5x5:
505         case QSSGRenderTextureFormat::RGBA_ASTC_6x5:
506         case QSSGRenderTextureFormat::RGBA_ASTC_6x6:
507         case QSSGRenderTextureFormat::RGBA_ASTC_8x5:
508         case QSSGRenderTextureFormat::RGBA_ASTC_8x6:
509         case QSSGRenderTextureFormat::RGBA_ASTC_8x8:
510         case QSSGRenderTextureFormat::RGBA_ASTC_10x5:
511         case QSSGRenderTextureFormat::RGBA_ASTC_10x6:
512         case QSSGRenderTextureFormat::RGBA_ASTC_10x8:
513         case QSSGRenderTextureFormat::RGBA_ASTC_10x10:
514         case QSSGRenderTextureFormat::RGBA_ASTC_12x10:
515         case QSSGRenderTextureFormat::RGBA_ASTC_12x12:
516         case QSSGRenderTextureFormat::SRGB8_Alpha8_ASTC_4x4:
517         case QSSGRenderTextureFormat::SRGB8_Alpha8_ASTC_5x4:
518         case QSSGRenderTextureFormat::SRGB8_Alpha8_ASTC_5x5:
519         case QSSGRenderTextureFormat::SRGB8_Alpha8_ASTC_6x5:
520         case QSSGRenderTextureFormat::SRGB8_Alpha8_ASTC_6x6:
521         case QSSGRenderTextureFormat::SRGB8_Alpha8_ASTC_8x5:
522         case QSSGRenderTextureFormat::SRGB8_Alpha8_ASTC_8x6:
523         case QSSGRenderTextureFormat::SRGB8_Alpha8_ASTC_8x8:
524         case QSSGRenderTextureFormat::SRGB8_Alpha8_ASTC_10x5:
525         case QSSGRenderTextureFormat::SRGB8_Alpha8_ASTC_10x6:
526         case QSSGRenderTextureFormat::SRGB8_Alpha8_ASTC_10x8:
527         case QSSGRenderTextureFormat::SRGB8_Alpha8_ASTC_10x10:
528         case QSSGRenderTextureFormat::SRGB8_Alpha8_ASTC_12x10:
529         case QSSGRenderTextureFormat::SRGB8_Alpha8_ASTC_12x12:
530             return true;
531         default:
532             break;
533         }
534         return false;
535     }
536 
isDepthTextureFormatQSSGRenderTextureFormat537     bool isDepthTextureFormat() const
538     {
539         switch (format) {
540         case QSSGRenderTextureFormat::Depth16:
541             return true;
542         case QSSGRenderTextureFormat::Depth24:
543             return true;
544         case QSSGRenderTextureFormat::Depth32:
545             return true;
546         case QSSGRenderTextureFormat::Depth24Stencil8:
547             return true;
548         default:
549             break;
550         }
551         return false;
552     }
553 
toStringQSSGRenderTextureFormat554     const char *toString() const
555     {
556         switch (format) {
557         case R8:
558             return "R8";
559         case R16:
560             return "R16";
561         case R16F:
562             return "R16F";
563         case R32I:
564             return "R32I";
565         case R32UI:
566             return "R32UI";
567         case R32F:
568             return "R32F";
569         case RG8:
570             return "RG8";
571         case RGBA8:
572             return "RGBA8";
573         case RGB8:
574             return "RGB8";
575         case SRGB8:
576             return "SRGB8";
577         case SRGB8A8:
578             return "SRGB8A8";
579         case RGB565:
580             return "RGB565";
581         case RGBA5551:
582             return "RGBA5551";
583         case Alpha8:
584             return "Alpha8";
585         case Luminance8:
586             return "Luminance8";
587         case Luminance16:
588             return "Luminance16";
589         case LuminanceAlpha8:
590             return "LuminanceAlpha8";
591         case RGBA16F:
592             return "RGBA16F";
593         case RG16F:
594             return "RG16F";
595         case RG32F:
596             return "RG32F";
597         case RGB32F:
598             return "RGB32F";
599         case RGBA32F:
600             return "RGBA32F";
601         case R11G11B10:
602             return "R11G11B10";
603         case RGB9E5:
604             return "RGB9E5";
605         case RGBE8:
606             return "RGBE8";
607         case RGBA_DXT1:
608             return "RGBA_DXT1";
609         case RGB_DXT1:
610             return "RGB_DXT1";
611         case RGBA_DXT3:
612             return "RGBA_DXT3";
613         case RGBA_DXT5:
614             return "RGBA_DXT5";
615         case R11_EAC_UNorm:
616             return "R11_EAC_UNorm";
617         case R11_EAC_SNorm:
618             return "R11_EAC_SNorm";
619         case RG11_EAC_UNorm:
620             return "RG11_EAC_UNorm";
621         case RG11_EAC_SNorm:
622             return "RG11_EAC_SNorm";
623         case RGB8_ETC2:
624             return "RGB8_ETC2";
625         case SRGB8_ETC2:
626             return "SRGB8_ETC2";
627         case RGB8_PunchThrough_Alpha1_ETC2:
628             return "RGB8_PunchThrough_Alpha1_ETC2";
629         case SRGB8_PunchThrough_Alpha1_ETC2:
630             return "SRGB8_PunchThrough_Alpha1_ETC2";
631         case RGBA8_ETC2_EAC:
632             return "RGBA8_ETC2_EAC";
633         case SRGB8_Alpha8_ETC2_EAC:
634             return "SRGB8_Alpha8_ETC2_EAC";
635 //        case RGB8_ETC1:
636 //            return "RGB8_ETC1";
637         case RGBA_ASTC_4x4:
638             return "RGBA_ASTC_4x4";
639         case RGBA_ASTC_5x4:
640             return "RGBA_ASTC_5x4";
641         case RGBA_ASTC_5x5:
642             return "RGBA_ASTC_5x5";
643         case RGBA_ASTC_6x5:
644             return "RGBA_ASTC_6x5";
645         case RGBA_ASTC_6x6:
646             return "RGBA_ASTC_6x6";
647         case RGBA_ASTC_8x5:
648             return "RGBA_ASTC_8x5";
649         case RGBA_ASTC_8x6:
650             return "RGBA_ASTC_8x6";
651         case RGBA_ASTC_8x8:
652             return "RGBA_ASTC_8x8";
653         case RGBA_ASTC_10x5:
654             return "RGBA_ASTC_10x5";
655         case RGBA_ASTC_10x6:
656             return "RGBA_ASTC_10x6";
657         case RGBA_ASTC_10x8:
658             return "RGBA_ASTC_10x8";
659         case RGBA_ASTC_10x10:
660             return "RGBA_ASTC_10x10";
661         case RGBA_ASTC_12x10:
662             return "RGBA_ASTC_12x10";
663         case RGBA_ASTC_12x12:
664             return "RGBA_ASTC_12x12";
665         case SRGB8_Alpha8_ASTC_4x4:
666             return "SRGB8_Alpha8_ASTC_4x4";
667         case SRGB8_Alpha8_ASTC_5x4:
668             return "SRGB8_Alpha8_ASTC_5x4";
669         case SRGB8_Alpha8_ASTC_5x5:
670             return "SRGB8_Alpha8_ASTC_5x5";
671         case SRGB8_Alpha8_ASTC_6x5:
672             return "SRGB8_Alpha8_ASTC_6x5";
673         case SRGB8_Alpha8_ASTC_6x6:
674             return "SRGB8_Alpha8_ASTC_6x6";
675         case SRGB8_Alpha8_ASTC_8x5:
676             return "SRGB8_Alpha8_ASTC_8x5";
677         case SRGB8_Alpha8_ASTC_8x6:
678             return "SRGB8_Alpha8_ASTC_8x6";
679         case SRGB8_Alpha8_ASTC_8x8:
680             return "SRGB8_Alpha8_ASTC_8x8";
681         case SRGB8_Alpha8_ASTC_10x5:
682             return "SRGB8_Alpha8_ASTC_10x5";
683         case SRGB8_Alpha8_ASTC_10x6:
684             return "SRGB8_Alpha8_ASTC_10x6";
685         case SRGB8_Alpha8_ASTC_10x8:
686             return "SRGB8_Alpha8_ASTC_10x8";
687         case SRGB8_Alpha8_ASTC_10x10:
688             return "SRGB8_Alpha8_ASTC_10x10";
689         case SRGB8_Alpha8_ASTC_12x10:
690             return "SRGB8_Alpha8_ASTC_12x10";
691         case SRGB8_Alpha8_ASTC_12x12:
692             return "SRGB8_Alpha8_ASTC_12x12";
693         case Depth16:
694             return "Depth16";
695         case Depth24:
696             return "Depth24";
697         case Depth32:
698             return "Depth32";
699         case Depth24Stencil8:
700             return "Depth24Stencil8";
701         default:
702             break;
703         }
704         return "Unknown";
705     }
706 
getSizeofFormatQSSGRenderTextureFormat707     qint32 getSizeofFormat() const
708     {
709         switch (format) {
710         case R8:
711             return 1;
712         case R16F:
713             return 2;
714         case R16:
715             return 2;
716         case R32I:
717             return 4;
718         case R32F:
719             return 4;
720         case RGBE8:
721         case RGBA8:
722             return 4;
723         case RGB8:
724             return 3;
725         case RGB565:
726             return 2;
727         case RGBA5551:
728             return 2;
729         case Alpha8:
730             return 1;
731         case Luminance8:
732             return 1;
733         case LuminanceAlpha8:
734             return 1;
735         case Depth16:
736             return 2;
737         case Depth24:
738             return 3;
739         case Depth32:
740             return 4;
741         case Depth24Stencil8:
742             return 4;
743         case RGB9E5:
744             return 4;
745         case SRGB8:
746             return 3;
747         case SRGB8A8:
748             return 4;
749         case RGBA16F:
750             return 8;
751         case RG16F:
752             return 4;
753         case RG32F:
754             return 8;
755         case RGBA32F:
756             return 16;
757         case RGB32F:
758             return 12;
759         case R11G11B10:
760             return 4;
761         default:
762             break;
763         }
764         Q_ASSERT(false);
765         return 0;
766     }
767 
getNumberOfComponentQSSGRenderTextureFormat768     qint32 getNumberOfComponent() const
769     {
770         switch (format) {
771         case R8:
772             return 1;
773         case R16F:
774             return 1;
775         case R16:
776             return 1;
777         case R32I:
778             return 1;
779         case R32F:
780             return 1;
781         case RGBA8:
782             return 4;
783         case RGB8:
784             return 3;
785         case RGB565:
786             return 3;
787         case RGBA5551:
788             return 4;
789         case Alpha8:
790             return 1;
791         case Luminance8:
792             return 1;
793         case LuminanceAlpha8:
794             return 2;
795         case Depth16:
796             return 1;
797         case Depth24:
798             return 1;
799         case Depth32:
800             return 1;
801         case Depth24Stencil8:
802             return 2;
803         case RGB9E5:
804             return 3;
805         case SRGB8:
806             return 3;
807         case SRGB8A8:
808             return 4;
809         case RGBA16F:
810             return 4;
811         case RG16F:
812             return 2;
813         case RG32F:
814             return 2;
815         case RGBA32F:
816             return 4;
817         case RGB32F:
818             return 3;
819         case R11G11B10:
820             return 3;
821         case RGBE8:
822             return 4;
823         default:
824             break;
825         }
826         Q_ASSERT(false);
827         return 0;
828     }
829 
830     void decodeToFloat(void *inPtr, qint32 byteOfs, float *outPtr) const;
831     void encodeToPixel(float *inPtr, void *outPtr, qint32 byteOfs) const;
832 
833     bool operator==(const QSSGRenderTextureFormat &other) const { return format == other.format; }
834     bool operator!=(const QSSGRenderTextureFormat &other) const { return format != other.format; }
835 };
836 
837 enum class QSSGRenderTextureTargetType
838 {
839     Unknown = 0,
840     Texture2D,
841     Texture2D_MS,
842     TextureCube,
843     TextureCubePosX,
844     TextureCubeNegX,
845     TextureCubePosY,
846     TextureCubeNegY,
847     TextureCubePosZ,
848     TextureCubeNegZ,
849 };
850 
851 enum class QSSGRenderTextureUnit
852 {
853     TextureUnit_0 = 0,
854     TextureUnit_1,
855     TextureUnit_2,
856     TextureUnit_3,
857     TextureUnit_4,
858     TextureUnit_5,
859     TextureUnit_6,
860     TextureUnit_7,
861     TextureUnit_8,
862     TextureUnit_9,
863     TextureUnit_10,
864     TextureUnit_11,
865     TextureUnit_12,
866     TextureUnit_13,
867     TextureUnit_14,
868     TextureUnit_15,
869     TextureUnit_16,
870     TextureUnit_17,
871     TextureUnit_18,
872     TextureUnit_19,
873     TextureUnit_20,
874     TextureUnit_21,
875     TextureUnit_22,
876     TextureUnit_23,
877     TextureUnit_24,
878     TextureUnit_25,
879     TextureUnit_26,
880     TextureUnit_27,
881     TextureUnit_28,
882     TextureUnit_29,
883     TextureUnit_30,
884     TextureUnit_31
885 };
886 
887 enum class QSSGRenderTextureCompareMode
888 {
889     Unknown = 0,
890     NoCompare,
891     CompareToRef
892 };
893 
894 enum class QSSGRenderTextureSwizzleMode
895 {
896     NoSwizzle = 0,
897     L8toR8,
898     A8toR8,
899     L8A8toRG8,
900     L16toR16
901 };
902 
903 enum class QSSGRenderTextureCompareOp
904 {
905     Never,
906     Less,
907     LessThanOrEqual,
908     Equal,
909     NotEqual,
910     Greater,
911     GreaterThanOrEqual,
912     AlwaysTrue,
913 };
914 
915 enum class QSSGRenderTextureMinifyingOp
916 {
917     Unknown = 0,
918     Nearest,
919     Linear,
920     NearestMipmapNearest,
921     LinearMipmapNearest,
922     NearestMipmapLinear,
923     LinearMipmapLinear
924 };
toString(QSSGRenderTextureMinifyingOp value)925 inline const char *toString(QSSGRenderTextureMinifyingOp value)
926 {
927     switch (value) {
928     case QSSGRenderTextureMinifyingOp::Nearest:
929         return "Nearest";
930     case QSSGRenderTextureMinifyingOp::Linear:
931         return "Linear";
932     case QSSGRenderTextureMinifyingOp::NearestMipmapNearest:
933         return "NearestMipmapNearest";
934     case QSSGRenderTextureMinifyingOp::LinearMipmapNearest:
935         return "LinearMipmapNearest";
936     case QSSGRenderTextureMinifyingOp::NearestMipmapLinear:
937         return "NearestMipmapLinear";
938     case QSSGRenderTextureMinifyingOp::LinearMipmapLinear:
939         return "LinearMipmapLinear";
940     default:
941         break;
942     }
943     return "Unknown";
944 }
945 
946 enum class QSSGRenderTextureMagnifyingOp
947 {
948     Unknown = 0,
949     Nearest,
950     Linear
951 };
toString(QSSGRenderTextureMagnifyingOp value)952 inline const char *toString(QSSGRenderTextureMagnifyingOp value)
953 {
954     switch (value) {
955     case QSSGRenderTextureMagnifyingOp::Nearest:
956         return "Nearest";
957     case QSSGRenderTextureMagnifyingOp::Linear:
958         return "Linear";
959     default:
960         break;
961     }
962     return "Unknown";
963 }
964 
965 enum class QSSGRenderTextureCoordOp : quint8
966 {
967     Unknown = 0,
968     ClampToEdge,
969     MirroredRepeat,
970     Repeat
971 };
972 
toString(QSSGRenderTextureCoordOp value)973 inline const char *toString(QSSGRenderTextureCoordOp value)
974 {
975     switch (value) {
976     case QSSGRenderTextureCoordOp::ClampToEdge:
977         return "ClampToEdge";
978     case QSSGRenderTextureCoordOp::MirroredRepeat:
979         return "MirroredRepeat";
980     case QSSGRenderTextureCoordOp::Repeat:
981         return "Repeat";
982     default:
983         break;
984     }
985     return "Unknown";
986 }
987 
988 enum class QSSGRenderHint
989 {
990     Unknown = 0,
991     Fastest,
992     Nicest,
993     Unspecified
994 };
toString(QSSGRenderHint value)995 inline const char *toString(QSSGRenderHint value)
996 {
997     switch (value) {
998     case QSSGRenderHint::Fastest:
999         return "Fastest";
1000     case QSSGRenderHint::Nicest:
1001         return "Nicest";
1002     case QSSGRenderHint::Unspecified:
1003         return "Unspecified";
1004     default:
1005         break;
1006     }
1007     return "Unknown";
1008 }
1009 
1010 struct QSSGRenderVertexBufferEntry
1011 {
1012     const char *m_name;
1013     /** Datatype of the this entry points to in the buffer */
1014     QSSGRenderComponentType m_componentType;
1015     /** Number of components of each data member. 1,2,3, or 4.  Don't be stupid.*/
1016     quint32 m_numComponents;
1017     /** Offset from the beginning of the buffer of the first item */
1018     quint32 m_firstItemOffset;
1019     /** Attribute input slot used for this entry*/
1020     quint32 m_inputSlot;
1021 
1022     QSSGRenderVertexBufferEntry(const char *nm,
1023                                   QSSGRenderComponentType type,
1024                                   quint32 numComponents,
1025                                   quint32 firstItemOffset = 0,
1026                                   quint32 inputSlot = 0)
m_nameQSSGRenderVertexBufferEntry1027         : m_name(nm), m_componentType(type), m_numComponents(numComponents), m_firstItemOffset(firstItemOffset), m_inputSlot(inputSlot)
1028     {
1029     }
1030 
QSSGRenderVertexBufferEntryQSSGRenderVertexBufferEntry1031     QSSGRenderVertexBufferEntry()
1032         : m_name(nullptr), m_componentType(QSSGRenderComponentType::Unknown), m_numComponents(0), m_firstItemOffset(0), m_inputSlot(0)
1033     {
1034     }
1035 
QSSGRenderVertexBufferEntryQSSGRenderVertexBufferEntry1036     QSSGRenderVertexBufferEntry(const QSSGRenderVertexBufferEntry &inOther)
1037         : m_name(inOther.m_name)
1038         , m_componentType(inOther.m_componentType)
1039         , m_numComponents(inOther.m_numComponents)
1040         , m_firstItemOffset(inOther.m_firstItemOffset)
1041         , m_inputSlot(inOther.m_inputSlot)
1042     {
1043     }
1044 
1045     QSSGRenderVertexBufferEntry &operator=(const QSSGRenderVertexBufferEntry &inOther)
1046     {
1047         if (this != &inOther) {
1048             m_name = inOther.m_name;
1049             m_componentType = inOther.m_componentType;
1050             m_numComponents = inOther.m_numComponents;
1051             m_firstItemOffset = inOther.m_firstItemOffset;
1052             m_inputSlot = inOther.m_inputSlot;
1053         }
1054         return *this;
1055     }
1056 };
1057 
1058 class QSSGRenderShaderProgram;
1059 
1060 // typedef QSSGConstDataRef<qint8> TConstI8Ref;
1061 
1062 struct Q_QUICK3DRENDER_EXPORT QSSGRenderVertFragCompilationResult
1063 {
1064     const char *m_shaderName = nullptr;
1065     QSSGRef<QSSGRenderShaderProgram> m_shader; ///< contains the program
1066 
1067     QSSGRenderVertFragCompilationResult();
1068     ~QSSGRenderVertFragCompilationResult();
1069     QSSGRenderVertFragCompilationResult(const QSSGRenderVertFragCompilationResult &);
1070     QSSGRenderVertFragCompilationResult & operator=(const QSSGRenderVertFragCompilationResult &other);
1071 };
1072 
1073 enum class QSSGRenderFrameBufferAttachment
1074 {
1075     Unknown = 0,
1076     Color0,
1077     Color1,
1078     Color2,
1079     Color3,
1080     Color4,
1081     Color5,
1082     Color6,
1083     Color7,
1084     Depth,
1085     Stencil,
1086     DepthStencil,
1087     CoverageNV,
1088     LastAttachment,
1089 };
1090 
1091 enum class QSSGRenderDrawMode
1092 {
1093     Unknown = 0,
1094     Points,
1095     LineStrip,
1096     LineLoop,
1097     Lines,
1098     TriangleStrip,
1099     TriangleFan,
1100     Triangles,
1101     Patches,
1102 };
1103 
1104 enum class QSSGRenderTextureCubeFace
1105 {
1106     InvalidFace = 0,
1107     CubePosX = 1,
1108     CubeNegX,
1109     CubePosY,
1110     CubeNegY,
1111     CubePosZ,
1112     CubeNegZ
1113 };
1114 
1115 enum class QSSGRenderWinding
1116 {
1117     Unknown = 0,
1118     Clockwise,
1119     CounterClockwise
1120 };
1121 
toString(QSSGRenderWinding value)1122 inline const char *toString(QSSGRenderWinding value)
1123 {
1124     switch (value) {
1125     case QSSGRenderWinding::Clockwise:
1126         return "Clockwise";
1127     case QSSGRenderWinding::CounterClockwise:
1128         return "CounterClockwise";
1129     default:
1130         break;
1131     }
1132     return "Unknown";
1133 }
1134 
1135 enum class QSSGRenderState
1136 {
1137     Unknown = 0,
1138     Blend,
1139     CullFace,
1140     DepthTest,
1141     StencilTest,
1142     ScissorTest,
1143     DepthWrite,
1144     Multisample
1145 };
1146 
toString(QSSGRenderState value)1147 inline const char *toString(QSSGRenderState value)
1148 {
1149     switch (value) {
1150     case QSSGRenderState::Blend:
1151         return "Blend";
1152     case QSSGRenderState::CullFace:
1153         return "CullFace";
1154     case QSSGRenderState::DepthTest:
1155         return "DepthTest";
1156     case QSSGRenderState::StencilTest:
1157         return "StencilTest";
1158     case QSSGRenderState::ScissorTest:
1159         return "ScissorTest";
1160     case QSSGRenderState::DepthWrite:
1161         return "DepthWrite";
1162     case QSSGRenderState::Multisample:
1163         return "Multisample";
1164     default:
1165         break;
1166     }
1167     return "Unknown";
1168 }
1169 
1170 enum class QSSGRenderSrcBlendFunc
1171 {
1172     Unknown = 0,
1173     Zero,
1174     One,
1175     SrcColor,
1176     OneMinusSrcColor,
1177     DstColor,
1178     OneMinusDstColor,
1179     SrcAlpha,
1180     OneMinusSrcAlpha,
1181     DstAlpha,
1182     OneMinusDstAlpha,
1183     ConstantColor,
1184     OneMinusConstantColor,
1185     ConstantAlpha,
1186     OneMinusConstantAlpha,
1187     SrcAlphaSaturate
1188 };
1189 
toString(QSSGRenderSrcBlendFunc value)1190 inline const char *toString(QSSGRenderSrcBlendFunc value)
1191 {
1192     switch (value) {
1193     case QSSGRenderSrcBlendFunc::Zero:
1194         return "Zero";
1195     case QSSGRenderSrcBlendFunc::One:
1196         return "One";
1197     case QSSGRenderSrcBlendFunc::SrcColor:
1198         return "SrcColor";
1199     case QSSGRenderSrcBlendFunc::OneMinusSrcColor:
1200         return "OneMinusSrcColor";
1201     case QSSGRenderSrcBlendFunc::DstColor:
1202         return "DstColor";
1203     case QSSGRenderSrcBlendFunc::OneMinusDstColor:
1204         return "OneMinusDstColor";
1205     case QSSGRenderSrcBlendFunc::SrcAlpha:
1206         return "SrcAlpha";
1207     case QSSGRenderSrcBlendFunc::OneMinusSrcAlpha:
1208         return "OneMinusSrcAlpha";
1209     case QSSGRenderSrcBlendFunc::DstAlpha:
1210         return "DstAlpha";
1211     case QSSGRenderSrcBlendFunc::OneMinusDstAlpha:
1212         return "OneMinusDstAlpha";
1213     case QSSGRenderSrcBlendFunc::ConstantColor:
1214         return "ConstantColor";
1215     case QSSGRenderSrcBlendFunc::OneMinusConstantColor:
1216         return "OneMinusConstantColor";
1217     case QSSGRenderSrcBlendFunc::ConstantAlpha:
1218         return "ConstantAlpha";
1219     case QSSGRenderSrcBlendFunc::OneMinusConstantAlpha:
1220         return "OneMinusConstantAlpha";
1221     case QSSGRenderSrcBlendFunc::SrcAlphaSaturate:
1222         return "SrcAlphaSaturate";
1223     default:
1224         break;
1225     }
1226     return "Unknown";
1227 }
1228 
1229 enum class QSSGRenderDstBlendFunc
1230 {
1231     Unknown = 0,
1232     Zero,
1233     One,
1234     SrcColor,
1235     OneMinusSrcColor,
1236     DstColor,
1237     OneMinusDstColor,
1238     SrcAlpha,
1239     OneMinusSrcAlpha,
1240     DstAlpha,
1241     OneMinusDstAlpha,
1242     ConstantColor,
1243     OneMinusConstantColor,
1244     ConstantAlpha,
1245     OneMinusConstantAlpha
1246 };
1247 
toString(QSSGRenderDstBlendFunc value)1248 inline const char *toString(QSSGRenderDstBlendFunc value)
1249 {
1250     return toString(static_cast<QSSGRenderSrcBlendFunc>(value));
1251 }
1252 
1253 enum class QSSGRenderBlendEquation
1254 {
1255     Unknown = 0,
1256     Add,
1257     Subtract,
1258     ReverseSubtract,
1259     Overlay,
1260     ColorBurn,
1261     ColorDodge
1262 };
1263 
toString(QSSGRenderBlendEquation value)1264 inline const char *toString(QSSGRenderBlendEquation value)
1265 {
1266     switch (value) {
1267     case QSSGRenderBlendEquation::Add:
1268         return "Add";
1269     case QSSGRenderBlendEquation::Subtract:
1270         return "Subtract";
1271     case QSSGRenderBlendEquation::ReverseSubtract:
1272         return "ReverseSubtract";
1273     case QSSGRenderBlendEquation::Overlay:
1274         return "Overlay";
1275     case QSSGRenderBlendEquation::ColorBurn:
1276         return "ColorBurn";
1277     case QSSGRenderBlendEquation::ColorDodge:
1278         return "ColorDodge";
1279     default:
1280         break;
1281     }
1282     return "Unknown";
1283 }
1284 
1285 enum class QSSGCullFaceMode
1286 {
1287     Unknown = 0,
1288     Back,
1289     Front,
1290     Disabled,
1291     FrontAndBack, // Not exposed in the front-end
1292 };
1293 
toString(QSSGCullFaceMode value)1294 inline const char *toString(QSSGCullFaceMode value)
1295 {
1296     switch (value) {
1297     case QSSGCullFaceMode::Front:
1298         return "Front";
1299     case QSSGCullFaceMode::Back:
1300         return "Back";
1301     case QSSGCullFaceMode::FrontAndBack:
1302         return "FrontAndBack";
1303     default:
1304         break;
1305     }
1306     return "Unknown";
1307 }
1308 
1309 enum class QSSGReadFace
1310 {
1311     Unknown = 0,
1312     Front,
1313     Back,
1314     Color0,
1315     Color1,
1316     Color2,
1317     Color3,
1318     Color4,
1319     Color5,
1320     Color6,
1321     Color7
1322 };
1323 
toString(QSSGReadFace value)1324 inline const char *toString(QSSGReadFace value)
1325 {
1326     switch (value) {
1327     case QSSGReadFace::Front:
1328         return "Front";
1329     case QSSGReadFace::Back:
1330         return "Back";
1331     case QSSGReadFace::Color0:
1332         return "Color0";
1333     case QSSGReadFace::Color1:
1334         return "Color1";
1335     case QSSGReadFace::Color2:
1336         return "Color2";
1337     case QSSGReadFace::Color3:
1338         return "Color3";
1339     case QSSGReadFace::Color4:
1340         return "Color4";
1341     case QSSGReadFace::Color5:
1342         return "Color5";
1343     case QSSGReadFace::Color6:
1344         return "Color6";
1345     case QSSGReadFace::Color7:
1346         return "Color7";
1347     default:
1348         break;
1349     }
1350     return "Unknown";
1351 }
1352 
1353 enum class QSSGRenderBoolOp
1354 {
1355 
1356     Unknown = 0,
1357     Never,
1358     Less,
1359     LessThanOrEqual,
1360     Equal,
1361     NotEqual,
1362     Greater,
1363     GreaterThanOrEqual,
1364     AlwaysTrue
1365 };
1366 
toString(QSSGRenderBoolOp value)1367 inline const char *toString(QSSGRenderBoolOp value)
1368 {
1369     switch (value) {
1370     case QSSGRenderBoolOp::Never:
1371         return "Never";
1372     case QSSGRenderBoolOp::Less:
1373         return "Less";
1374     case QSSGRenderBoolOp::LessThanOrEqual:
1375         return "LessThanOrEqual";
1376     case QSSGRenderBoolOp::Equal:
1377         return "Equal";
1378     case QSSGRenderBoolOp::NotEqual:
1379         return "NotEqual";
1380     case QSSGRenderBoolOp::Greater:
1381         return "Greater";
1382     case QSSGRenderBoolOp::GreaterThanOrEqual:
1383         return "GreaterThanOrEqual";
1384     case QSSGRenderBoolOp::AlwaysTrue:
1385         return "AlwaysTrue";
1386     default:
1387         break;
1388     }
1389     return "Unknown";
1390 }
1391 
1392 enum class QSSGRenderStencilOp
1393 {
1394     Unknown = 0,
1395     Keep,
1396     Zero,
1397     Replace,
1398     Increment,
1399     IncrementWrap,
1400     Decrement,
1401     DecrementWrap,
1402     Invert
1403 };
1404 
toString(QSSGRenderStencilOp value)1405 inline const char *toString(QSSGRenderStencilOp value)
1406 {
1407     switch (value) {
1408     case QSSGRenderStencilOp::Keep:
1409         return "Keep";
1410     case QSSGRenderStencilOp::Zero:
1411         return "Zero";
1412     case QSSGRenderStencilOp::Replace:
1413         return "Replace";
1414     case QSSGRenderStencilOp::Increment:
1415         return "Increment";
1416     case QSSGRenderStencilOp::IncrementWrap:
1417         return "IncrementWrap";
1418     case QSSGRenderStencilOp::Decrement:
1419         return "Decrement";
1420     case QSSGRenderStencilOp::DecrementWrap:
1421         return "DecrementWrap";
1422     case QSSGRenderStencilOp::Invert:
1423         return "Invert";
1424     default:
1425         break;
1426     }
1427     return "Unknown";
1428 }
1429 
1430 struct QSSGRenderBlendFunctionArgument
1431 {
1432     QSSGRenderSrcBlendFunc m_srcRgb;
1433     QSSGRenderDstBlendFunc m_dstRgb;
1434     QSSGRenderSrcBlendFunc m_srcAlpha;
1435     QSSGRenderDstBlendFunc m_dstAlpha;
1436 
QSSGRenderBlendFunctionArgumentQSSGRenderBlendFunctionArgument1437     QSSGRenderBlendFunctionArgument(QSSGRenderSrcBlendFunc srcRGB,
1438                                       QSSGRenderDstBlendFunc dstRGB,
1439                                       QSSGRenderSrcBlendFunc srcAlpha,
1440                                       QSSGRenderDstBlendFunc dstAlpha)
1441         : m_srcRgb(srcRGB), m_dstRgb(dstRGB), m_srcAlpha(srcAlpha), m_dstAlpha(dstAlpha)
1442     {
1443     }
1444 
1445     // Default blend system premultiplies values.
QSSGRenderBlendFunctionArgumentQSSGRenderBlendFunctionArgument1446     QSSGRenderBlendFunctionArgument()
1447         : m_srcRgb(QSSGRenderSrcBlendFunc::SrcAlpha)
1448         , m_dstRgb(QSSGRenderDstBlendFunc::OneMinusSrcAlpha)
1449         , m_srcAlpha(QSSGRenderSrcBlendFunc::One)
1450         , m_dstAlpha(QSSGRenderDstBlendFunc::OneMinusSrcAlpha)
1451     {
1452     }
1453 
1454     bool operator==(const QSSGRenderBlendFunctionArgument& other) const
1455     {
1456         return (m_srcRgb == other.m_srcRgb && m_dstRgb == other.m_dstRgb &&
1457                 m_srcAlpha == other.m_srcAlpha && m_dstAlpha == other.m_dstAlpha);
1458     }
1459 };
1460 
1461 struct QSSGRenderBlendEquationArgument
1462 {
1463     QSSGRenderBlendEquation m_rgbEquation;
1464     QSSGRenderBlendEquation m_alphaEquation;
1465 
QSSGRenderBlendEquationArgumentQSSGRenderBlendEquationArgument1466     QSSGRenderBlendEquationArgument(QSSGRenderBlendEquation rgb, QSSGRenderBlendEquation alpha)
1467         : m_rgbEquation(rgb), m_alphaEquation(alpha)
1468     {
1469     }
QSSGRenderBlendEquationArgumentQSSGRenderBlendEquationArgument1470     QSSGRenderBlendEquationArgument()
1471         : m_rgbEquation(QSSGRenderBlendEquation::Add), m_alphaEquation(QSSGRenderBlendEquation::Add)
1472     {
1473     }
1474 
1475     bool operator==(const QSSGRenderBlendEquationArgument& other) const
1476     {
1477         return (m_rgbEquation == other.m_rgbEquation && m_alphaEquation == other.m_alphaEquation);
1478     }
1479 };
1480 
1481 struct QSSGRenderStencilOperation
1482 {
1483     QSSGRenderStencilOp m_stencilFail = QSSGRenderStencilOp::Keep; // What happens when stencil test fails.
1484     // These values assume the stencil passed
1485 
1486     // What happens when the stencil passes but depth test fail.
1487     QSSGRenderStencilOp m_depthFail = QSSGRenderStencilOp::Keep;
1488      // What happens when the stencil and depth tests pass.
1489     QSSGRenderStencilOp m_depthPass = QSSGRenderStencilOp::Keep;
1490 
QSSGRenderStencilOperationQSSGRenderStencilOperation1491     QSSGRenderStencilOperation(QSSGRenderStencilOp fail,
1492                                          QSSGRenderStencilOp depthFail,
1493                                          QSSGRenderStencilOp depthPass)
1494         : m_stencilFail(fail), m_depthFail(depthFail), m_depthPass(depthPass)
1495     {
1496     }
1497     QSSGRenderStencilOperation() = default;
1498 
1499     bool operator==(const QSSGRenderStencilOperation &other) const
1500     {
1501         return (m_stencilFail == other.m_stencilFail && m_depthFail == other.m_depthFail && m_depthPass == other.m_depthPass);
1502     }
1503 };
1504 
1505 // see glStencilFuncSeparate
1506 struct QSSGRenderStencilFunction
1507 {
1508     QSSGRenderBoolOp m_function = QSSGRenderBoolOp::AlwaysTrue;
1509     quint32 m_referenceValue = 0;
1510     quint32 m_mask = std::numeric_limits<quint32>::max();
1511 
QSSGRenderStencilFunctionQSSGRenderStencilFunction1512     QSSGRenderStencilFunction(QSSGRenderBoolOp function, quint32 referenceValue, quint32 mask)
1513         : m_function(function), m_referenceValue(referenceValue), m_mask(mask)
1514     {
1515     }
1516     QSSGRenderStencilFunction() = default;
1517 
1518     bool operator==(const QSSGRenderStencilFunction &other) const
1519     {
1520         return (m_function == other.m_function && m_referenceValue == other.m_referenceValue && m_mask == other.m_mask);
1521     }
1522 };
1523 
1524 class QSSGRenderFrameBuffer;
1525 class QSSGRenderVertexBuffer;
1526 class QSSGRenderIndexBuffer;
1527 class QSSGRenderProgramPipeline;
1528 class QSSGRenderTextureBase;
1529 class QSSGRenderTexture2D;
1530 class QSSGRenderTextureCube;
1531 class QSSGRenderImage2D;
1532 class QSSGRenderDataBuffer;
1533 class QSSGRenderAttribLayout;
1534 class QSSGRenderInputAssembler;
1535 
1536 // Return coordinates in pixels but relative to this rect.
toRectRelative(const QRectF & r,const QVector2D & absoluteCoordinates)1537 inline QVector2D toRectRelative(const QRectF &r, const QVector2D &absoluteCoordinates)
1538 {
1539     return QVector2D(absoluteCoordinates.x() - float(r.x()), absoluteCoordinates.y() - float(r.y()));
1540 }
1541 
halfDims(const QRectF & r)1542 inline QVector2D halfDims(const QRectF &r)
1543 {
1544     return QVector2D(float(r.width() / 2.0), float(r.height() / 2.0));
1545 }
1546 
1547 // Take coordinates in global space and move local space where 0,0 is the center
1548 // of the rect but return value in pixels, not in normalized -1,1 range
toNormalizedRectRelative(const QRectF & r,QVector2D absoluteCoordinates)1549 inline QVector2D toNormalizedRectRelative(const QRectF &r, QVector2D absoluteCoordinates)
1550 {
1551     // normalize them
1552     const QVector2D relativeCoords(toRectRelative(r, absoluteCoordinates));
1553     const QVector2D halfD(halfDims(r));
1554     const QVector2D normalized((relativeCoords.x() / halfD.x()) - 1.0f, (relativeCoords.y() / halfD.y()) - 1.0f);
1555     return QVector2D(normalized.x() * halfD.x(), normalized.y() * halfD.y());
1556 }
1557 
relativeToNormalizedCoordinates(const QRectF & r,QVector2D rectRelativeCoords)1558 inline QVector2D relativeToNormalizedCoordinates(const QRectF &r, QVector2D rectRelativeCoords)
1559 {
1560     return { (rectRelativeCoords.x() / halfDims(r).x()) - 1.0f, (rectRelativeCoords.y() / halfDims(r).y()) - 1.0f };
1561 }
1562 
1563 // Normalized coordinates are in the range of -1,1 where -1 is the left, bottom edges
1564 // and 1 is the top,right edges.
absoluteToNormalizedCoordinates(const QRectF & r,const QVector2D & absoluteCoordinates)1565 inline QVector2D absoluteToNormalizedCoordinates(const QRectF &r, const QVector2D &absoluteCoordinates)
1566 {
1567     return relativeToNormalizedCoordinates(r, toRectRelative(r, absoluteCoordinates));
1568 }
1569 
toAbsoluteCoords(const QRectF & r,const QVector2D & inRelativeCoords)1570 inline QVector2D toAbsoluteCoords(const QRectF &r, const QVector2D &inRelativeCoords)
1571 {
1572     return QVector2D(inRelativeCoords.x() + float(r.x()), inRelativeCoords.y() + float(r.y()));
1573 }
1574 
1575 template<typename TDataType>
1576 struct QSSGRenderGenericVec2
1577 {
1578     TDataType x;
1579     TDataType y;
QSSGRenderGenericVec2QSSGRenderGenericVec21580     QSSGRenderGenericVec2(TDataType _x, TDataType _y) : x(_x), y(_y) {}
QSSGRenderGenericVec2QSSGRenderGenericVec21581     QSSGRenderGenericVec2() {}
1582     bool operator==(const QSSGRenderGenericVec2 &inOther) const { return x == inOther.x && y == inOther.y; }
1583 };
1584 
1585 template<typename TDataType>
1586 struct QSSGRenderGenericVec3
1587 {
1588     TDataType x;
1589     TDataType y;
1590     TDataType z;
QSSGRenderGenericVec3QSSGRenderGenericVec31591     QSSGRenderGenericVec3(TDataType _x, TDataType _y, TDataType _z) : x(_x), y(_y), z(_z) {}
QSSGRenderGenericVec3QSSGRenderGenericVec31592     QSSGRenderGenericVec3() {}
1593     bool operator==(const QSSGRenderGenericVec3 &inOther) const
1594     {
1595         return x == inOther.x && y == inOther.y && z == inOther.z;
1596     }
1597 };
1598 
1599 template<typename TDataType>
1600 struct QSSGRenderGenericVec4
1601 {
1602     TDataType x;
1603     TDataType y;
1604     TDataType z;
1605     TDataType w;
QSSGRenderGenericVec4QSSGRenderGenericVec41606     QSSGRenderGenericVec4(TDataType _x, TDataType _y, TDataType _z, TDataType _w) : x(_x), y(_y), z(_z), w(_w) {}
QSSGRenderGenericVec4QSSGRenderGenericVec41607     QSSGRenderGenericVec4() {}
1608     bool operator==(const QSSGRenderGenericVec4 &inOther) const
1609     {
1610         return x == inOther.x && y == inOther.y && z == inOther.z && w == inOther.w;
1611     }
1612 };
1613 
1614 typedef QSSGRenderGenericVec2<bool> bool_2;
1615 typedef QSSGRenderGenericVec3<bool> bool_3;
1616 typedef QSSGRenderGenericVec4<bool> bool_4;
1617 typedef QSSGRenderGenericVec2<quint32> quint32_2;
1618 typedef QSSGRenderGenericVec3<quint32> quint32_3;
1619 typedef QSSGRenderGenericVec4<quint32> quint32_4;
1620 typedef QSSGRenderGenericVec2<qint32> qint32_2;
1621 typedef QSSGRenderGenericVec3<qint32> qint32_3;
1622 typedef QSSGRenderGenericVec4<qint32> qint32_4;
1623 
1624 enum class QSSGRenderShaderDataType : quint32
1625 {
1626     Unknown = 0,
1627     Integer, // qint32,
1628     IntegerVec2, // qint32_2,
1629     IntegerVec3, // qint32_3,
1630     IntegerVec4, // qint32_4,
1631     Boolean, // bool
1632     BooleanVec2, // bool_2,
1633     BooleanVec3, // bool_3,
1634     BooleanVec4, // bool_4,
1635     Float, // float,
1636     Vec2, // QVector2D,
1637     Vec3, // QVector3D,
1638     Vec4, // QVector4D,
1639     UnsignedInteger, // quint32,
1640     UnsignedIntegerVec2, // quint32_2,
1641     UnsignedIntegerVec3, // quint32_3,
1642     UnsignedIntegerVec4, // quint32_4,
1643     Matrix3x3, // QMatrix3x3,
1644     Matrix4x4, // QMatrix4x4,
1645     Rgba, // QColor
1646     Texture2D, // QSSGRenderTexture2D *,
1647     Texture2DHandle, // QSSGRenderTexture2D **,
1648     TextureCube, // QSSGRenderTextureCube *,
1649     TextureCubeHandle, // QSSGRenderTextureCube **,
1650     Image2D, // QSSGRenderImage2D *,
1651     DataBuffer // QSSGRenderDataBuffer *
1652 };
1653 
1654 template<typename TDataType>
1655 struct QSSGDataTypeToShaderDataTypeMap
1656 {
1657 };
1658 
1659 template<>
1660 struct QSSGDataTypeToShaderDataTypeMap<qint32>
1661 {
1662     static QSSGRenderShaderDataType getType() { return QSSGRenderShaderDataType::Integer; }
1663 };
1664 
1665 template<>
1666 struct QSSGDataTypeToShaderDataTypeMap<qint32_2>
1667 {
1668     static QSSGRenderShaderDataType getType() { return QSSGRenderShaderDataType::IntegerVec2; }
1669 };
1670 
1671 template<>
1672 struct QSSGDataTypeToShaderDataTypeMap<qint32_3>
1673 {
1674     static QSSGRenderShaderDataType getType() { return QSSGRenderShaderDataType::IntegerVec3; }
1675 };
1676 
1677 template<>
1678 struct QSSGDataTypeToShaderDataTypeMap<qint32_4>
1679 {
1680     static QSSGRenderShaderDataType getType() { return QSSGRenderShaderDataType::IntegerVec4; }
1681 };
1682 
1683 template<>
1684 struct QSSGDataTypeToShaderDataTypeMap<bool>
1685 {
1686     static QSSGRenderShaderDataType getType() { return QSSGRenderShaderDataType::Boolean; }
1687 };
1688 
1689 template<>
1690 struct QSSGDataTypeToShaderDataTypeMap<bool_2>
1691 {
1692     static QSSGRenderShaderDataType getType() { return QSSGRenderShaderDataType::BooleanVec2; }
1693 };
1694 
1695 template<>
1696 struct QSSGDataTypeToShaderDataTypeMap<bool_3>
1697 {
1698     static QSSGRenderShaderDataType getType() { return QSSGRenderShaderDataType::BooleanVec3; }
1699 };
1700 
1701 template<>
1702 struct QSSGDataTypeToShaderDataTypeMap<bool_4>
1703 {
1704     static QSSGRenderShaderDataType getType() { return QSSGRenderShaderDataType::BooleanVec4; }
1705 };
1706 
1707 template<>
1708 struct QSSGDataTypeToShaderDataTypeMap<float>
1709 {
1710     static QSSGRenderShaderDataType getType() { return QSSGRenderShaderDataType::Float; }
1711 };
1712 
1713 template<>
1714 struct QSSGDataTypeToShaderDataTypeMap<QVector2D>
1715 {
1716     static QSSGRenderShaderDataType getType() { return QSSGRenderShaderDataType::Vec2; }
1717 };
1718 
1719 template<>
1720 struct QSSGDataTypeToShaderDataTypeMap<QVector3D>
1721 {
1722     static QSSGRenderShaderDataType getType() { return QSSGRenderShaderDataType::Vec3; }
1723 };
1724 
1725 template<>
1726 struct QSSGDataTypeToShaderDataTypeMap<QVector4D>
1727 {
1728     static QSSGRenderShaderDataType getType() { return QSSGRenderShaderDataType::Vec4; }
1729 };
1730 
1731 template <>
1732 struct QSSGDataTypeToShaderDataTypeMap<QColor>
1733 {
1734     static QSSGRenderShaderDataType getType() { return QSSGRenderShaderDataType::Rgba; }
1735 };
1736 
1737 template<>
1738 struct QSSGDataTypeToShaderDataTypeMap<quint32>
1739 {
1740     static QSSGRenderShaderDataType getType() { return QSSGRenderShaderDataType::UnsignedInteger; }
1741 };
1742 
1743 template<>
1744 struct QSSGDataTypeToShaderDataTypeMap<quint32_2>
1745 {
1746     static QSSGRenderShaderDataType getType() { return QSSGRenderShaderDataType::UnsignedIntegerVec2; }
1747 };
1748 
1749 template<>
1750 struct QSSGDataTypeToShaderDataTypeMap<quint32_3>
1751 {
1752     static QSSGRenderShaderDataType getType() { return QSSGRenderShaderDataType::UnsignedIntegerVec3; }
1753 };
1754 
1755 template<>
1756 struct QSSGDataTypeToShaderDataTypeMap<quint32_4>
1757 {
1758     static QSSGRenderShaderDataType getType() { return QSSGRenderShaderDataType::UnsignedIntegerVec4; }
1759 };
1760 
1761 template<>
1762 struct QSSGDataTypeToShaderDataTypeMap<QMatrix3x3>
1763 {
1764     static QSSGRenderShaderDataType getType() { return QSSGRenderShaderDataType::Matrix3x3; }
1765 };
1766 
1767 template<>
1768 struct QSSGDataTypeToShaderDataTypeMap<QMatrix4x4>
1769 {
1770     static QSSGRenderShaderDataType getType() { return QSSGRenderShaderDataType::Matrix4x4; }
1771 };
1772 
1773 template<>
1774 struct QSSGDataTypeToShaderDataTypeMap<QSSGDataView<QMatrix4x4>>
1775 {
1776     static QSSGRenderShaderDataType getType() { return QSSGRenderShaderDataType::Matrix4x4; }
1777 };
1778 
1779 template<>
1780 struct QSSGDataTypeToShaderDataTypeMap<QSSGRenderTexture2D *>
1781 {
1782     static QSSGRenderShaderDataType getType() { return QSSGRenderShaderDataType::Texture2D; }
1783 };
1784 
1785 template<>
1786 struct QSSGDataTypeToShaderDataTypeMap<QSSGRenderTexture2D **>
1787 {
1788     static QSSGRenderShaderDataType getType() { return QSSGRenderShaderDataType::Texture2DHandle; }
1789 };
1790 
1791 template<>
1792 struct QSSGDataTypeToShaderDataTypeMap<QSSGRenderTextureCube *>
1793 {
1794     static QSSGRenderShaderDataType getType() { return QSSGRenderShaderDataType::TextureCube; }
1795 };
1796 
1797 template<>
1798 struct QSSGDataTypeToShaderDataTypeMap<QSSGRenderTextureCube **>
1799 {
1800     static QSSGRenderShaderDataType getType() { return QSSGRenderShaderDataType::TextureCubeHandle; }
1801 };
1802 
1803 template<>
1804 struct QSSGDataTypeToShaderDataTypeMap<QSSGRenderImage2D *>
1805 {
1806     static QSSGRenderShaderDataType getType() { return QSSGRenderShaderDataType::Image2D; }
1807 };
1808 
1809 template<>
1810 struct QSSGDataTypeToShaderDataTypeMap<QSSGRenderDataBuffer *>
1811 {
1812     static QSSGRenderShaderDataType getType() { return QSSGRenderShaderDataType::DataBuffer; }
1813 };
1814 
1815 enum class QSSGRenderShaderTypeValue
1816 {
1817     Unknown = 1 << 0,
1818     Vertex = 1 << 1,
1819     Fragment = 1 << 2,
1820     TessControl = 1 << 3,
1821     TessEvaluation = 1 << 4,
1822     Geometry = 1 << 5
1823 };
1824 
1825 Q_DECLARE_FLAGS(QSSGRenderShaderTypeFlags, QSSGRenderShaderTypeValue)
1826 Q_DECLARE_OPERATORS_FOR_FLAGS(QSSGRenderShaderTypeFlags)
1827 
1828 enum class QSSGRenderTextureTypeValue
1829 {
1830     Unknown = 0,
1831     Diffuse,
1832     Specular,
1833     Environment,
1834     Bump,
1835     Normal,
1836     Displace,
1837     Emissive,
1838     Anisotropy,
1839     Translucent,
1840     LightmapIndirect,
1841     LightmapRadiosity,
1842     LightmapShadow
1843 };
1844 
1845 inline const char *toString(QSSGRenderTextureTypeValue value)
1846 {
1847     switch (value) {
1848     case QSSGRenderTextureTypeValue::Unknown:
1849         return "Unknown";
1850     case QSSGRenderTextureTypeValue::Diffuse:
1851         return "Diffuse";
1852     case QSSGRenderTextureTypeValue::Specular:
1853         return "Specular";
1854     case QSSGRenderTextureTypeValue::Environment:
1855         return "Environment";
1856     case QSSGRenderTextureTypeValue::Bump:
1857         return "Bump";
1858     case QSSGRenderTextureTypeValue::Normal:
1859         return "Normal";
1860     case QSSGRenderTextureTypeValue::Displace:
1861         return "Displace";
1862     case QSSGRenderTextureTypeValue::Emissive:
1863         return "Emissive";
1864     case QSSGRenderTextureTypeValue::Anisotropy:
1865         return "Anisotropy";
1866     case QSSGRenderTextureTypeValue::Translucent:
1867         return "Translucent";
1868     case QSSGRenderTextureTypeValue::LightmapIndirect:
1869         return "LightmapIndirect";
1870     case QSSGRenderTextureTypeValue::LightmapRadiosity:
1871         return "LightmapRadiosity";
1872     case QSSGRenderTextureTypeValue::LightmapShadow:
1873         return "LightmapShadow";
1874     }
1875     return nullptr;
1876 }
1877 
1878 enum class QSSGRenderReadPixelFormat
1879 {
1880     Alpha8,
1881     RGB565,
1882     RGB8,
1883     RGBA4444,
1884     RGBA5551,
1885     RGBA8
1886 };
1887 
1888 inline int sizeofPixelFormat(QSSGRenderReadPixelFormat f)
1889 {
1890     switch (f) {
1891     case QSSGRenderReadPixelFormat::Alpha8:
1892         return 1;
1893     case QSSGRenderReadPixelFormat::RGB565:
1894     case QSSGRenderReadPixelFormat::RGBA5551:
1895     case QSSGRenderReadPixelFormat::RGBA4444:
1896         return 2;
1897     case QSSGRenderReadPixelFormat::RGB8:
1898         return 3;
1899     case QSSGRenderReadPixelFormat::RGBA8:
1900         return 4;
1901     }
1902 
1903     Q_ASSERT(0);
1904     return 0;
1905 }
1906 
1907 // Now for scoped property access.
1908 template<typename TBaseType, typename TDataType>
1909 struct QSSGRenderGenericScopedProperty
1910 {
1911     typedef void (TBaseType::*TSetter)(TDataType inType, bool forceSet);
1912     typedef TDataType (TBaseType::*TGetter)() const;
1913 
1914     TBaseType &m_context;
1915     TSetter m_setter;
1916     typename std::remove_reference<TDataType>::type m_initialValue;
1917     QSSGRenderGenericScopedProperty(TBaseType &ctx, TGetter getter, TSetter setter)
1918         : m_context(ctx), m_setter(setter), m_initialValue(((ctx).*getter)())
1919     {
1920     }
1921     QSSGRenderGenericScopedProperty(TBaseType &ctx, TGetter getter, TSetter setter, const TDataType &inNewValue)
1922         : m_context(ctx), m_setter(setter), m_initialValue(((ctx).*getter)())
1923     {
1924         ((m_context).*m_setter)(inNewValue, false);
1925     }
1926     ~QSSGRenderGenericScopedProperty() { ((m_context).*m_setter)(m_initialValue, false); }
1927 };
1928 
1929 QT_END_NAMESPACE
1930 
1931 Q_DECLARE_METATYPE(bool_2)
1932 Q_DECLARE_METATYPE(bool_3)
1933 Q_DECLARE_METATYPE(bool_4)
1934 Q_DECLARE_METATYPE(quint32_2)
1935 Q_DECLARE_METATYPE(quint32_3)
1936 Q_DECLARE_METATYPE(quint32_4)
1937 Q_DECLARE_METATYPE(qint32_2)
1938 Q_DECLARE_METATYPE(qint32_3)
1939 Q_DECLARE_METATYPE(qint32_4)
1940 
1941 #endif
1942