summaryrefslogtreecommitdiff
path: root/src
diff options
context:
space:
mode:
authorRhys Weatherley <rhys.weatherley@nokia.com>2010-11-26 11:06:24 +1000
committerRhys Weatherley <rhys.weatherley@nokia.com>2010-11-26 11:19:11 +1000
commit04608e7011a59192dc512245e7ae4578c233242d (patch)
tree4c9c0998ddf287fbc3af8f77086306dbf7b979cf /src
parent8f40ac2f616ed12995aceaf77e96123d8205872c (diff)
downloadqt-creator-04608e7011a59192dc512245e7ae4578c233242d.tar.gz
Add support for GLSL array and index types.
Index types are arrays, matrices, and vectors, which can all be "indexed" by operator[].
Diffstat (limited to 'src')
-rw-r--r--src/libs/glsl/glsl.h2
-rw-r--r--src/libs/glsl/glslengine.cpp3
-rw-r--r--src/libs/glsl/glsltype.h2
-rw-r--r--src/libs/glsl/glsltypes.cpp27
-rw-r--r--src/libs/glsl/glsltypes.h41
5 files changed, 62 insertions, 13 deletions
diff --git a/src/libs/glsl/glsl.h b/src/libs/glsl/glsl.h
index 1916fc33f7..73f35be0c1 100644
--- a/src/libs/glsl/glsl.h
+++ b/src/libs/glsl/glsl.h
@@ -58,8 +58,10 @@ class UIntType;
class FloatType;
class DoubleType;
class OpaqueType;
+class IndexType;
class VectorType;
class MatrixType;
+class ArrayType;
// symbols
class Symbol;
diff --git a/src/libs/glsl/glslengine.cpp b/src/libs/glsl/glslengine.cpp
index ec5c40a551..6b11bc5f30 100644
--- a/src/libs/glsl/glslengine.cpp
+++ b/src/libs/glsl/glslengine.cpp
@@ -155,7 +155,8 @@ const VectorType *Engine::vectorType(const Type *elementType, int dimension)
const MatrixType *Engine::matrixType(const Type *elementType, int columns, int rows)
{
- return _matrixTypes.intern(MatrixType(elementType, columns, rows));
+ return _matrixTypes.intern(MatrixType(elementType, columns, rows,
+ vectorType(elementType, rows)));
}
QList<DiagnosticMessage> Engine::diagnosticMessages() const
diff --git a/src/libs/glsl/glsltype.h b/src/libs/glsl/glsltype.h
index a1608b8ade..46ba3913ed 100644
--- a/src/libs/glsl/glsltype.h
+++ b/src/libs/glsl/glsltype.h
@@ -46,8 +46,10 @@ public:
virtual const FloatType *asFloatType() const { return 0; }
virtual const DoubleType *asDoubleType() const { return 0; }
virtual const OpaqueType *asOpaqueType() const { return 0; }
+ virtual const IndexType *asIndexType() const { return 0; }
virtual const VectorType *asVectorType() const { return 0; }
virtual const MatrixType *asMatrixType() const { return 0; }
+ virtual const ArrayType *asArrayType() const { return 0; }
virtual const Struct *asStructType() const { return 0; }
virtual const Function *asFunctionType() const { return 0; }
diff --git a/src/libs/glsl/glsltypes.cpp b/src/libs/glsl/glsltypes.cpp
index 8d3e1964b8..3e53fa4f8c 100644
--- a/src/libs/glsl/glsltypes.cpp
+++ b/src/libs/glsl/glsltypes.cpp
@@ -162,7 +162,7 @@ void VectorType::populateMembers(Engine *engine, const char *components)
// Single component swizzles.
for (int x = 0; x < _dimension; ++x) {
const QString *name = engine->identifier(components + x, 1);
- add(engine->newVariable(this, *name, _elementType));
+ add(engine->newVariable(this, *name, elementType()));
}
// Two component swizzles.
@@ -170,7 +170,7 @@ void VectorType::populateMembers(Engine *engine, const char *components)
if (_dimension == 2)
vec2Type = this;
else
- vec2Type = engine->vectorType(_elementType, 2);
+ vec2Type = engine->vectorType(elementType(), 2);
for (int x = 0; x < _dimension; ++x) {
for (int y = 0; y < _dimension; ++y) {
QString name;
@@ -188,7 +188,7 @@ void VectorType::populateMembers(Engine *engine, const char *components)
else if (_dimension < 3)
return;
else
- vec3Type = engine->vectorType(_elementType, 3);
+ vec3Type = engine->vectorType(elementType(), 3);
for (int x = 0; x < _dimension; ++x) {
for (int y = 0; y < _dimension; ++y) {
for (int z = 0; z < _dimension; ++z) {
@@ -228,7 +228,7 @@ bool VectorType::isEqualTo(const Type *other) const
if (const VectorType *v = other->asVectorType()) {
if (_dimension != v->dimension())
return false;
- else if (_elementType != v->elementType())
+ else if (elementType() != v->elementType())
return false;
return true;
}
@@ -243,7 +243,7 @@ bool VectorType::isLessThan(const Type *other) const
Q_ASSERT(vec != 0);
if (_dimension < vec->dimension())
return true;
- else if (_dimension == vec->dimension() && _elementType < vec->elementType())
+ else if (_dimension == vec->dimension() && elementType() < vec->elementType())
return true;
return false;
}
@@ -280,6 +280,23 @@ bool MatrixType::isLessThan(const Type *other) const
return false;
}
+bool ArrayType::isEqualTo(const Type *other) const
+{
+ if (other) {
+ if (const ArrayType *array = other->asArrayType())
+ return elementType()->isEqualTo(array->elementType());
+ }
+ return false;
+}
+
+bool ArrayType::isLessThan(const Type *other) const
+{
+ Q_ASSERT(other != 0);
+ const ArrayType *array = other->asArrayType();
+ Q_ASSERT(array != 0);
+ return elementType() < array->elementType();
+}
+
void Struct::add(Symbol *member)
{
_members.append(member);
diff --git a/src/libs/glsl/glsltypes.h b/src/libs/glsl/glsltypes.h
index 7a2481ee6a..74e969f80f 100644
--- a/src/libs/glsl/glsltypes.h
+++ b/src/libs/glsl/glsltypes.h
@@ -99,13 +99,27 @@ public:
virtual bool isLessThan(const Type *other) const;
};
-class GLSL_EXPORT VectorType: public Type, public Scope
+// Type that can be indexed with the [] operator.
+class GLSL_EXPORT IndexType: public Type
+{
+public:
+ IndexType(const Type *indexElementType) : _indexElementType(indexElementType) {}
+
+ const Type *indexElementType() const { return _indexElementType; }
+
+ virtual const IndexType *asIndexType() const { return this; }
+
+private:
+ const Type *_indexElementType;
+};
+
+class GLSL_EXPORT VectorType: public IndexType, public Scope
{
public:
VectorType(const Type *elementType, int dimension)
- : _elementType(elementType), _dimension(dimension) {}
+ : IndexType(elementType), _dimension(dimension) {}
- const Type *elementType() const { return _elementType; }
+ const Type *elementType() const { return indexElementType(); }
int dimension() const { return _dimension; }
virtual void add(Symbol *symbol);
@@ -117,7 +131,6 @@ public:
virtual bool isLessThan(const Type *other) const;
private:
- const Type *_elementType;
int _dimension;
QHash<QString, Symbol *> _members;
@@ -127,13 +140,14 @@ private:
void populateMembers(Engine *engine, const char *components);
};
-class GLSL_EXPORT MatrixType: public Type
+class GLSL_EXPORT MatrixType: public IndexType
{
public:
- MatrixType(const Type *elementType, int columns, int rows)
- : _elementType(elementType), _columns(columns), _rows(rows) {}
+ MatrixType(const Type *elementType, int columns, int rows, const Type *columnType)
+ : IndexType(columnType), _elementType(elementType), _columns(columns), _rows(rows) {}
const Type *elementType() const { return _elementType; }
+ const Type *columnType() const { return indexElementType(); }
int columns() const { return _columns; }
int rows() const { return _rows; }
@@ -147,6 +161,19 @@ private:
int _rows;
};
+class GLSL_EXPORT ArrayType: public IndexType
+{
+public:
+ explicit ArrayType(const Type *elementType)
+ : IndexType(elementType) {}
+
+ const Type *elementType() const { return indexElementType(); }
+
+ virtual const ArrayType *asArrayType() const { return this; }
+ virtual bool isEqualTo(const Type *other) const;
+ virtual bool isLessThan(const Type *other) const;
+};
+
class GLSL_EXPORT Struct: public Type, public Scope
{
public: