2021-01-11 20:42:44 +00:00
|
|
|
/*
|
|
|
|
* Copyright 2020 Google LLC
|
|
|
|
*
|
|
|
|
* Use of this source code is governed by a BSD-style license that can be
|
|
|
|
* found in the LICENSE file.
|
|
|
|
*/
|
|
|
|
|
|
|
|
#ifndef SKSL_DSL_VAR
|
|
|
|
#define SKSL_DSL_VAR
|
|
|
|
|
2021-03-04 19:30:25 +00:00
|
|
|
#include "include/sksl/DSLExpression.h"
|
|
|
|
#include "include/sksl/DSLModifiers.h"
|
2021-01-11 20:42:44 +00:00
|
|
|
|
|
|
|
namespace SkSL {
|
|
|
|
|
|
|
|
class Variable;
|
|
|
|
|
|
|
|
namespace dsl {
|
|
|
|
|
|
|
|
class DSLType;
|
|
|
|
|
|
|
|
class DSLVar {
|
|
|
|
public:
|
|
|
|
/**
|
|
|
|
* Constructs a new variable with the specified type and name. The name is used (in mangled
|
|
|
|
* form) in the resulting shader code; it is not otherwise important. Since mangling prevents
|
|
|
|
* name conflicts and the variable's name is only important when debugging shaders, the name
|
|
|
|
* parameter is optional.
|
|
|
|
*/
|
2021-03-05 19:23:48 +00:00
|
|
|
DSLVar(DSLType type, const char* name = "var", DSLExpression initialValue = DSLExpression());
|
2021-01-11 20:42:44 +00:00
|
|
|
|
2021-03-05 19:23:48 +00:00
|
|
|
DSLVar(DSLType type, DSLExpression initialValue);
|
|
|
|
|
|
|
|
DSLVar(DSLModifiers modifiers, DSLType type, const char* name = "var",
|
|
|
|
DSLExpression initialValue = DSLExpression());
|
|
|
|
|
|
|
|
DSLVar(DSLModifiers modifiers, DSLType type, DSLExpression initialValue);
|
2021-01-27 12:53:46 +00:00
|
|
|
|
2021-01-11 20:42:44 +00:00
|
|
|
DSLVar(DSLVar&&) = delete;
|
|
|
|
|
2021-03-04 19:30:25 +00:00
|
|
|
~DSLVar();
|
|
|
|
|
2021-01-26 19:31:29 +00:00
|
|
|
DSLExpression x() {
|
|
|
|
return DSLExpression(*this).x();
|
|
|
|
}
|
|
|
|
|
|
|
|
DSLExpression y() {
|
|
|
|
return DSLExpression(*this).y();
|
|
|
|
}
|
|
|
|
|
|
|
|
DSLExpression z() {
|
|
|
|
return DSLExpression(*this).z();
|
|
|
|
}
|
|
|
|
|
|
|
|
DSLExpression w() {
|
|
|
|
return DSLExpression(*this).w();
|
|
|
|
}
|
|
|
|
|
|
|
|
DSLExpression r() {
|
|
|
|
return DSLExpression(*this).r();
|
|
|
|
}
|
|
|
|
|
|
|
|
DSLExpression g() {
|
|
|
|
return DSLExpression(*this).g();
|
|
|
|
}
|
|
|
|
|
|
|
|
DSLExpression b() {
|
|
|
|
return DSLExpression(*this).b();
|
|
|
|
}
|
|
|
|
|
|
|
|
DSLExpression a() {
|
|
|
|
return DSLExpression(*this).a();
|
|
|
|
}
|
|
|
|
|
2021-02-11 20:18:31 +00:00
|
|
|
DSLExpression field(const char* name) {
|
|
|
|
return DSLExpression(*this).field(name);
|
|
|
|
}
|
|
|
|
|
2021-02-26 01:50:32 +00:00
|
|
|
DSLPossibleExpression operator=(const DSLVar& var) {
|
2021-01-13 15:38:59 +00:00
|
|
|
return this->operator=(DSLExpression(var));
|
|
|
|
}
|
|
|
|
|
2021-02-26 01:50:32 +00:00
|
|
|
DSLPossibleExpression operator=(DSLExpression expr);
|
2021-01-13 15:38:59 +00:00
|
|
|
|
2021-02-26 01:50:32 +00:00
|
|
|
DSLPossibleExpression operator=(int expr) {
|
2021-01-13 15:38:59 +00:00
|
|
|
return this->operator=(DSLExpression(expr));
|
|
|
|
}
|
|
|
|
|
2021-02-26 01:50:32 +00:00
|
|
|
DSLPossibleExpression operator=(float expr) {
|
2021-01-13 15:38:59 +00:00
|
|
|
return this->operator=(DSLExpression(expr));
|
|
|
|
}
|
|
|
|
|
2021-02-26 01:50:32 +00:00
|
|
|
DSLPossibleExpression operator[](DSLExpression&& index);
|
2021-01-26 15:07:01 +00:00
|
|
|
|
2021-02-26 01:50:32 +00:00
|
|
|
DSLPossibleExpression operator++() {
|
2021-01-13 15:38:59 +00:00
|
|
|
return ++DSLExpression(*this);
|
|
|
|
}
|
|
|
|
|
2021-02-26 01:50:32 +00:00
|
|
|
DSLPossibleExpression operator++(int) {
|
2021-01-13 15:38:59 +00:00
|
|
|
return DSLExpression(*this)++;
|
|
|
|
}
|
|
|
|
|
2021-02-26 01:50:32 +00:00
|
|
|
DSLPossibleExpression operator--() {
|
|
|
|
return --DSLExpression(*this);
|
|
|
|
}
|
|
|
|
|
|
|
|
DSLPossibleExpression operator--(int) {
|
|
|
|
return DSLExpression(*this)--;
|
|
|
|
}
|
|
|
|
|
2021-01-11 20:42:44 +00:00
|
|
|
private:
|
|
|
|
/**
|
|
|
|
* Constructs a reference to a variable that already exists in the symbol table. This is used
|
|
|
|
* internally to reference built-in vars.
|
|
|
|
*/
|
|
|
|
DSLVar(const char* name);
|
|
|
|
|
|
|
|
const char* name() const {
|
|
|
|
return fName;
|
|
|
|
}
|
|
|
|
|
2021-03-04 19:30:25 +00:00
|
|
|
int fUniformHandle;
|
2021-01-22 20:18:25 +00:00
|
|
|
std::unique_ptr<SkSL::Statement> fDeclaration;
|
2021-03-05 19:23:48 +00:00
|
|
|
bool fDeclared = false;
|
|
|
|
const SkSL::Variable* fVar;
|
2021-03-16 20:37:29 +00:00
|
|
|
const char* fRawName; // for error reporting
|
2021-01-11 20:42:44 +00:00
|
|
|
const char* fName;
|
|
|
|
|
2021-02-17 20:52:09 +00:00
|
|
|
friend DSLVar sk_SampleCoord();
|
|
|
|
|
2021-01-22 20:18:25 +00:00
|
|
|
friend class DSLCore;
|
2021-01-11 20:42:44 +00:00
|
|
|
friend class DSLExpression;
|
2021-03-16 20:37:29 +00:00
|
|
|
friend class DSLFunction;
|
2021-01-13 15:38:59 +00:00
|
|
|
friend class DSLWriter;
|
2021-01-11 20:42:44 +00:00
|
|
|
};
|
|
|
|
|
|
|
|
} // namespace dsl
|
|
|
|
|
|
|
|
} // namespace SkSL
|
|
|
|
|
|
|
|
|
|
|
|
#endif
|