Qt
Internal/Contributor docs for the Qt SDK. <b>Note:</b> These are NOT official API docs; those are found <a href='https://doc.qt.io/'>here</a>.
Loading...
Searching...
No Matches
glsltypes.cpp
Go to the documentation of this file.
1// Copyright (C) 2021 The Qt Company Ltd.
2// SPDX-License-Identifier: LicenseRef-Qt-Commercial OR GPL-3.0-only
3
4#include "glsltypes_p.h"
5#include "glslsymbols_p.h"
6#include "glslengine_p.h"
7#include "glslparser_p.h"
8
10
11using namespace GLSL;
12
14{
15 if (other && other->asUndefinedType() != nullptr)
16 return true;
17 return false;
18}
19
21{
23 Q_ASSERT(other != nullptr);
24 Q_ASSERT(other->asUndefinedType() != nullptr);
25 return false;
26}
27
28bool VoidType::isEqualTo(const Type *other) const
29{
30 if (other && other->asVoidType() != nullptr)
31 return true;
32 return false;
33}
34
36{
38 Q_ASSERT(other != nullptr);
39 Q_ASSERT(other->asVoidType() != nullptr);
40 return false;
41}
42
43bool BoolType::isEqualTo(const Type *other) const
44{
45 if (other && other->asBoolType() != nullptr)
46 return true;
47 return false;
48}
49
51{
53 Q_ASSERT(other != nullptr);
54 Q_ASSERT(other->asBoolType() != nullptr);
55 return false;
56}
57
58bool IntType::isEqualTo(const Type *other) const
59{
60 if (other && other->asIntType() != nullptr)
61 return true;
62 return false;
63}
64
65bool IntType::isLessThan(const Type *other) const
66{
68 Q_ASSERT(other != nullptr);
69 Q_ASSERT(other->asIntType() != nullptr);
70 return false;
71}
72
73bool UIntType::isEqualTo(const Type *other) const
74{
75 if (other && other->asUIntType() != nullptr)
76 return true;
77 return false;
78}
79
81{
83 Q_ASSERT(other != nullptr);
84 Q_ASSERT(other->asUIntType() != nullptr);
85 return false;
86}
87
89{
90 if (other && other->asFloatType() != nullptr)
91 return true;
92 return false;
93}
94
96{
98 Q_ASSERT(other != nullptr);
99 Q_ASSERT(other->asFloatType() != nullptr);
100 return false;
101}
102
104{
105 if (other && other->asDoubleType() != nullptr)
106 return true;
107 return false;
108}
109
111{
113 Q_ASSERT(other != nullptr);
114 Q_ASSERT(other->asDoubleType() != nullptr);
115 return false;
116}
117
119{
120 const char *prefix = "";
121 if (elementType()->asBoolType() != nullptr)
122 prefix = "b";
123 else if (elementType()->asIntType() != nullptr)
124 prefix = "i'";
125 else if (elementType()->asUIntType() != nullptr)
126 prefix = "u";
127 else if (elementType()->asDoubleType() != nullptr)
128 prefix = "d";
129 return QString::fromLatin1("%1vec%2").arg(QLatin1String(prefix)).arg(_dimension);
130}
131
133{
134 _members.insert(symbol->name(), symbol);
135}
136
138{
139 return _members.value(name);
140}
141
142void VectorType::populateMembers(Engine *engine)
143{
144 if (_members.isEmpty()) {
145 populateMembers(engine, "xyzw");
146 populateMembers(engine, "rgba");
147 populateMembers(engine, "stpq");
148 }
149}
150
151void VectorType::populateMembers(Engine *engine, const char *components)
152{
153 // Single component swizzles.
154 for (int x = 0; x < _dimension; ++x) {
155 const QString *name = engine->identifier(components + x, 1);
156 add(engine->newVariable(this, *name, elementType()));
157 }
158
159 // Two component swizzles.
160 const Type *vec2Type;
161 if (_dimension == 2)
162 vec2Type = this;
163 else
164 vec2Type = engine->vectorType(elementType(), 2);
165 for (int x = 0; x < _dimension; ++x) {
166 for (int y = 0; y < _dimension; ++y) {
170 add(engine->newVariable
171 (this, *engine->identifier(name), vec2Type));
172 }
173 }
174
175 // Three component swizzles.
176 const Type *vec3Type;
177 if (_dimension == 3)
178 vec3Type = this;
179 else if (_dimension < 3)
180 return;
181 else
182 vec3Type = engine->vectorType(elementType(), 3);
183 for (int x = 0; x < _dimension; ++x) {
184 for (int y = 0; y < _dimension; ++y) {
185 for (int z = 0; z < _dimension; ++z) {
190 add(engine->newVariable
191 (this, *engine->identifier(name), vec3Type));
192 }
193 }
194 }
195
196 // Four component swizzles.
197 if (_dimension != 4)
198 return;
199 for (int x = 0; x < _dimension; ++x) {
200 for (int y = 0; y < _dimension; ++y) {
201 for (int z = 0; z < _dimension; ++z) {
202 for (int w = 0; w < _dimension; ++w) {
208 add(engine->newVariable
209 (this, *engine->identifier(name), this));
210 }
211 }
212 }
213 }
214}
215
217{
218 if (other) {
219 if (const VectorType *v = other->asVectorType()) {
220 if (_dimension != v->dimension())
221 return false;
222 else if (elementType() != v->elementType())
223 return false;
224 return true;
225 }
226 }
227 return false;
228}
229
231{
232 Q_ASSERT(other != nullptr);
233 const VectorType *vec = other->asVectorType();
234 Q_ASSERT(vec != nullptr);
235 if (_dimension < vec->dimension())
236 return true;
237 else if (_dimension == vec->dimension() && elementType() < vec->elementType())
238 return true;
239 return false;
240}
241
243{
244 const char *prefix = "";
245 if (elementType()->asBoolType() != nullptr)
246 prefix = "b";
247 else if (elementType()->asIntType() != nullptr)
248 prefix = "i";
249 else if (elementType()->asUIntType() != nullptr)
250 prefix = "u";
251 else if (elementType()->asDoubleType() != nullptr)
252 prefix = "d";
253 return QString::fromLatin1("%1mat%2x%3").arg(QLatin1String(prefix)).arg(_columns).arg(_rows);
254}
255
257{
258 if (other) {
259 if (const MatrixType *v = other->asMatrixType()) {
260 if (_columns != v->columns())
261 return false;
262 else if (_rows != v->rows())
263 return false;
264 else if (_elementType != v->elementType())
265 return false;
266 return true;
267 }
268 }
269 return false;
270}
271
273{
274 Q_ASSERT(other != nullptr);
275 const MatrixType *mat = other->asMatrixType();
276 Q_ASSERT(mat != nullptr);
277 if (_columns < mat->columns()) {
278 return true;
279 } else if (_columns == mat->columns()) {
280 if (_rows < mat->rows())
281 return true;
282 else if (_rows == mat->rows() && _elementType < mat->elementType())
283 return true;
284 }
285 return false;
286}
287
289{
290 return elementType()->toString() + QLatin1String("[]");
291}
292
294{
295 if (other) {
296 if (const ArrayType *array = other->asArrayType())
297 return elementType()->isEqualTo(array->elementType());
298 }
299 return false;
300}
301
303{
304 Q_ASSERT(other != nullptr);
305 const ArrayType *array = other->asArrayType();
306 Q_ASSERT(array != nullptr);
307 return elementType() < array->elementType();
308}
309
310QList<Symbol *> Struct::members() const
311{
312 QList<Symbol *> m;
313 for (Symbol *s : _members) {
314 if (! s->name().isEmpty())
315 m.append(s);
316 }
317 return m;
318}
319
320void Struct::add(Symbol *member)
321{
322 _members.append(member);
323}
324
326{
327 for (Symbol *s : _members) {
328 if (s->name() == name)
329 return s;
330 }
331 return nullptr;
332}
333
334bool Struct::isEqualTo(const Type *other) const
335{
337 return false;
338}
339
340bool Struct::isLessThan(const Type *other) const
341{
343 return false;
344}
345
346
348{
349 return prettyPrint();
350}
351
353{
354 QString proto;
355 proto += _returnType->toString();
356 proto += QLatin1Char(' ');
357 proto += name();
358 proto += QLatin1Char('(');
359 for (int i = 0; i < _arguments.size(); ++i) {
360 if (i != 0)
361 proto += QLatin1String(", ");
362 Argument *arg = _arguments.at(i);
363 proto += arg->type()->toString();
364 proto += QLatin1Char(' ');
365 proto += arg->name();
366 }
367 proto += QLatin1Char(')');
368 return proto;
369}
370
372{
373 return _returnType;
374}
375
376void Function::setReturnType(const Type *returnType)
377{
378 _returnType = returnType;
379}
380
381QVector<Argument *> Function::arguments() const
382{
383 return _arguments;
384}
385
387{
388 _arguments.append(arg);
389}
390
392{
393 return _arguments.size();
394}
395
397{
398 return _arguments.at(index);
399}
400
402{
404 return false;
405}
406
408{
410 return false;
411}
412
413QList<Symbol *> Function::members() const
414{
415 QList<Symbol *> m;
416 for (Argument *arg : _arguments) {
417 if (! arg->name().isEmpty())
418 m.append(arg);
419 }
420 return m;
421}
422
424{
425 for (Argument *arg : _arguments) {
426 if (arg->name() == name)
427 return arg;
428 }
429 return nullptr;
430}
431
433{
434 return QLatin1String(Parser::spell[_kind]);
435}
436
438{
439 if (other) {
440 if (const SamplerType *samp = other->asSamplerType())
441 return _kind == samp->kind();
442 }
443 return false;
444}
445
447{
448 Q_ASSERT(other != nullptr);
449 const SamplerType *samp = other->asSamplerType();
450 Q_ASSERT(samp != nullptr);
451 return _kind < samp->kind();
452}
453
455 : Scope(enclosingScope)
456{
457}
458
459QVector<Function *> OverloadSet::functions() const
460{
461 return _functions;
462}
463
465{
466 _functions.append(function);
467}
468
470{
471 return this;
472}
473
475{
476 return nullptr;
477}
478
480{
481 if (symbol) {
482 if (Function *fun = symbol->asFunction())
484 }
485}
486
488{
490 return false;
491}
492
494{
496 return false;
497}
498
static const char *const spell[]
bool isLessThan(const Type *other) const override
bool isEqualTo(const Type *other) const override
QString toString() const override
const Type * elementType() const
bool isEqualTo(const Type *other) const override
Definition glsltypes.cpp:43
bool isLessThan(const Type *other) const override
Definition glsltypes.cpp:50
bool isLessThan(const Type *other) const override
bool isEqualTo(const Type *other) const override
bool isLessThan(const Type *other) const override
Definition glsltypes.cpp:95
bool isEqualTo(const Type *other) const override
Definition glsltypes.cpp:88
void setReturnType(const Type *returnType)
QList< Symbol * > members() const override
bool isEqualTo(const Type *other) const override
QVector< Argument * > arguments() const
int argumentCount() const
const Type * returnType() const
Argument * argumentAt(int index) const
QString toString() const override
Symbol * find(const QString &name) const override
QString prettyPrint() const
void addArgument(Argument *arg)
bool isLessThan(const Type *other) const override
bool isLessThan(const Type *other) const override
Definition glsltypes.cpp:65
bool isEqualTo(const Type *other) const override
Definition glsltypes.cpp:58
QString toString() const override
bool isLessThan(const Type *other) const override
int rows() const
const Type * elementType() const
int columns() const
bool isEqualTo(const Type *other) const override
void addFunction(Function *function)
bool isEqualTo(const Type *other) const override
OverloadSet(Scope *enclosingScope=nullptr)
const Type * type() const override
QVector< Function * > functions() const
bool isLessThan(const Type *other) const override
Symbol * find(const QString &name) const override
void add(Symbol *symbol) override
bool isEqualTo(const Type *other) const override
bool isLessThan(const Type *other) const override
QString toString() const override
void add(Symbol *member) override
bool isEqualTo(const Type *other) const override
QList< Symbol * > members() const override
Symbol * find(const QString &name) const override
bool isLessThan(const Type *other) const override
virtual Function * asFunction()
QString name() const
virtual const DoubleType * asDoubleType() const
Definition glsltype_p.h:38
virtual const IntType * asIntType() const
Definition glsltype_p.h:35
virtual const UIntType * asUIntType() const
Definition glsltype_p.h:36
virtual const BoolType * asBoolType() const
Definition glsltype_p.h:34
virtual bool isEqualTo(const Type *other) const =0
virtual QString toString() const =0
bool isEqualTo(const Type *other) const override
Definition glsltypes.cpp:73
bool isLessThan(const Type *other) const override
Definition glsltypes.cpp:80
bool isEqualTo(const Type *other) const override
Definition glsltypes.cpp:13
bool isLessThan(const Type *other) const override
Definition glsltypes.cpp:20
QString toString() const override
int dimension() const
bool isLessThan(const Type *other) const override
void add(Symbol *symbol) override
const Type * elementType() const
Symbol * find(const QString &name) const override
bool isEqualTo(const Type *other) const override
bool isLessThan(const Type *other) const override
Definition glsltypes.cpp:35
bool isEqualTo(const Type *other) const override
Definition glsltypes.cpp:28
\macro QT_RESTRICTED_CAST_FROM_ASCII
Definition qstring.h:129
static QString fromLatin1(QByteArrayView ba)
This is an overloaded member function, provided for convenience. It differs from the above function o...
Definition qstring.cpp:5871
Definition glsl_p.h:22
Combined button and popup list for selecting options.
GLsizei const GLfloat * v
[13]
GLuint GLfloat GLfloat GLfloat GLfloat GLfloat z
GLint GLint GLint GLint GLint x
[0]
const GLfloat * m
GLfloat GLfloat GLfloat w
[0]
GLint GLenum GLint components
GLuint index
[2]
GLuint name
GLint y
GLdouble s
[6]
Definition qopenglext.h:235
GLenum array
#define Q_ASSERT(cond)
Definition qrandom.cpp:47
SSL_CTX int void * arg
QLatin1StringView QLatin1String
Definition qstringfwd.h:31
#define Q_UNUSED(x)
QSharedPointer< T > other(t)
[5]
QJSValue fun
[0]
QJSEngine engine
[0]
\inmodule QtCore \reentrant
Definition qchar.h:18
Definition moc.h:23