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 QSSG_RENDER_COMMANDS_H
6#define QSSG_RENDER_COMMANDS_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/qssgrenderbasetypes_p.h>
20#include <QtQuick3DRuntimeRender/private/qssgrendershadercache_p.h>
21
22#include <QDebug>
23#include <QVariant>
24
25QT_BEGIN_NAMESPACE
26
27struct QSSGRenderEffect;
28
29enum class CommandType
30{
31 Unknown = 0,
32 AllocateBuffer,
33 BindTarget,
34 BindBuffer,
35 BindShader,
36 ApplyInstanceValue,
37 ApplyBufferValue,
38 Render,
39 ApplyValue,
40};
41
42struct QSSGCommand
43{
44 CommandType m_type;
45 QSSGCommand(CommandType inType) : m_type(inType) {}
46 const char *typeAsString() const;
47 QString debugString() const;
48 void addDebug(QDebug &stream) const;
49};
50
51enum class AllocateBufferFlagValues
52{
53 None = 0,
54 SceneLifetime = 1,
55};
56
57struct QSSGAllocateBufferFlags : public QFlags<AllocateBufferFlagValues>
58{
59 QSSGAllocateBufferFlags(quint32 inValues) : QFlags(inValues) {}
60 QSSGAllocateBufferFlags() {}
61 void setSceneLifetime(bool inValue) { setFlag(flag: AllocateBufferFlagValues::SceneLifetime, on: inValue); }
62 // If isSceneLifetime is unset the buffer is assumed to be frame lifetime and will be
63 // released after this render operation.
64 bool isSceneLifetime() const { return this->operator&(other: AllocateBufferFlagValues::SceneLifetime); }
65};
66
67struct QSSGAllocateBuffer : public QSSGCommand
68{
69 QByteArray m_name;
70 QSSGRenderTextureFormat m_format = QSSGRenderTextureFormat::RGBA8;
71 QSSGRenderTextureFilterOp m_filterOp = QSSGRenderTextureFilterOp::Linear;
72 QSSGRenderTextureCoordOp m_texCoordOp = QSSGRenderTextureCoordOp::ClampToEdge;
73 float m_sizeMultiplier = 1.0f;
74 QSSGAllocateBufferFlags m_bufferFlags;
75 QSSGAllocateBuffer() : QSSGCommand(CommandType::AllocateBuffer) {}
76 QSSGAllocateBuffer(const QByteArray &inName,
77 QSSGRenderTextureFormat inFormat,
78 QSSGRenderTextureFilterOp inFilterOp,
79 QSSGRenderTextureCoordOp inCoordOp,
80 float inMultiplier,
81 QSSGAllocateBufferFlags inFlags)
82 : QSSGCommand(CommandType::AllocateBuffer)
83 , m_name(inName)
84 , m_format(inFormat)
85 , m_filterOp(inFilterOp)
86 , m_texCoordOp(inCoordOp)
87 , m_sizeMultiplier(inMultiplier)
88 , m_bufferFlags(inFlags)
89 {
90 }
91 void addDebug(QDebug &stream) const {
92 stream << "name:" << m_name << "format:" << m_format.toString() << "size multiplier:" << m_sizeMultiplier << "filter:" << QSSGBaseTypeHelpers::toString(value: m_filterOp) << "tiling:" << QSSGBaseTypeHelpers::toString(value: m_texCoordOp) << "sceneLifetime:" << m_bufferFlags.isSceneLifetime();
93 }
94};
95
96struct QSSGBindTarget : public QSSGCommand
97{
98 QSSGRenderTextureFormat m_outputFormat;
99
100 explicit QSSGBindTarget(QSSGRenderTextureFormat inFormat = QSSGRenderTextureFormat::RGBA8)
101 : QSSGCommand(CommandType::BindTarget), m_outputFormat(inFormat)
102 {
103 }
104 void addDebug(QDebug &stream) const {
105 stream << "format" << m_outputFormat.toString();
106 }
107};
108
109struct QSSGBindBuffer : public QSSGCommand
110{
111 QByteArray m_bufferName;
112 QSSGBindBuffer(const QByteArray &inBufName)
113 : QSSGCommand(CommandType::BindBuffer), m_bufferName(inBufName)
114 {
115 }
116 void addDebug(QDebug &stream) const {
117 stream << "name:" << m_bufferName;
118 }
119};
120
121struct QSSGBindShader : public QSSGCommand
122{
123 QByteArray m_shaderPathKey; // something like "prefix>vertex_filename>fragment_filename:source_sha:y_up_in_fbo[:tonemapping]"
124 QSSGBindShader(const QByteArray &inShaderPathKey)
125 : QSSGCommand(CommandType::BindShader),
126 m_shaderPathKey(inShaderPathKey)
127 {
128 }
129 QSSGBindShader() : QSSGCommand(CommandType::BindShader) {}
130 void addDebug(QDebug &stream) const {
131 stream << "key:" << m_shaderPathKey << "effect:";
132 }
133};
134
135// The value sits immediately after the 'this' object
136// in memory.
137// If propertyName is not valid then we attempt to apply all of the effect property values
138// to the shader, ignoring ones that don't match up.
139struct QSSGApplyInstanceValue : public QSSGCommand
140{
141 // Name of value to apply in shader
142 QByteArray m_propertyName;
143 // type of value
144 QSSGRenderShaderValue::Type m_valueType;
145 // offset in the effect data section of value.
146 quint32 m_valueOffset;
147 QSSGApplyInstanceValue(const QByteArray &inName, QSSGRenderShaderValue::Type inValueType, quint32 inValueOffset)
148 : QSSGCommand(CommandType::ApplyInstanceValue), m_propertyName(inName), m_valueType(inValueType), m_valueOffset(inValueOffset)
149 {
150 }
151 // Default will attempt to apply all effect values to the currently bound shader
152 QSSGApplyInstanceValue()
153 : QSSGCommand(CommandType::ApplyInstanceValue), m_valueType(QSSGRenderShaderValue::Unknown), m_valueOffset(0)
154 {
155 }
156 void addDebug(QDebug &stream) const {
157 stream << "name:" << m_propertyName << "type:" << int(m_valueType) << "offset:" << m_valueOffset ;
158 }
159};
160
161struct QSSGApplyValue : public QSSGCommand
162{
163 QByteArray m_propertyName;
164 QVariant m_value;
165 explicit QSSGApplyValue(const QByteArray &inName)
166 : QSSGCommand(CommandType::ApplyValue), m_propertyName(inName)
167 {
168 }
169 // Default will attempt to apply all effect values to the currently bound shader
170 QSSGApplyValue() : QSSGCommand(CommandType::ApplyValue) {}
171 void addDebug(QDebug &stream) const {
172 stream << "name:" << m_propertyName << "value:" << m_value;
173 }
174};
175
176struct QSSGApplyBufferValue : public QSSGCommand
177{
178 QByteArray m_bufferName;
179 QByteArray m_samplerName;
180
181 QSSGApplyBufferValue(const QByteArray &bufferName, const QByteArray &shaderSampler)
182 : QSSGCommand(CommandType::ApplyBufferValue), m_bufferName(bufferName), m_samplerName(shaderSampler)
183 {
184 }
185 void addDebug(QDebug &stream) const {
186 stream << "name:" << m_bufferName << "sampler:" << m_samplerName;
187 }
188};
189
190struct QSSGRender : public QSSGCommand
191{
192 explicit QSSGRender() : QSSGCommand(CommandType::Render) { }
193
194 QSSGRender(const QSSGRender &)
195 : QSSGCommand(CommandType::Render)
196 {
197 }
198 void addDebug(QDebug &stream) const {
199 stream << "(no parameters)";
200 }
201};
202
203QT_END_NAMESPACE
204
205#endif
206

source code of qtquick3d/src/runtimerender/qssgrendercommands_p.h