Skip to content

Commit

Permalink
#5532: Remember the expressions used to define the scale/rotate/shear…
Browse files Browse the repository at this point in the history
… transforms
  • Loading branch information
codereader committed Feb 27, 2021
1 parent df45115 commit 9a1ada5
Show file tree
Hide file tree
Showing 3 changed files with 45 additions and 7 deletions.
9 changes: 9 additions & 0 deletions include/ShaderLayer.h
Expand Up @@ -233,6 +233,9 @@ class ShaderLayer
*/
virtual Vector2 getScale() = 0;

// Returns the expression of the given scale component (0 == x, 1 == y)
virtual const shaders::IShaderExpressionPtr& getScaleExpression(std::size_t index) = 0;

/**
* Returns the value of the translate expressions of this stage.
*/
Expand All @@ -246,11 +249,17 @@ class ShaderLayer
*/
virtual float getRotation() = 0;

// Returns the expression used to calculate the rotation value
virtual const shaders::IShaderExpressionPtr& getRotationExpression() = 0;

/**
* Returns the value of the 'shear' expressions of this stage.
*/
virtual Vector2 getShear() = 0;

// Returns the expression of the given shear component (0 == x, 1 == y)
virtual const shaders::IShaderExpressionPtr& getShearExpression(std::size_t index) = 0;

// Returns true if this layer has an alphatest expression defined
virtual bool hasAlphaTest() const = 0;

Expand Down
6 changes: 4 additions & 2 deletions radiantcore/shaders/Doom3ShaderLayer.cpp
Expand Up @@ -105,19 +105,21 @@ Doom3ShaderLayer::Doom3ShaderLayer(ShaderTemplate& material, ShaderLayer::Type t
_colIdx[3] = REG_ONE;

// Scale is set to 1,1 by default
_scale[0] = REG_ONE;
_scale[1] = REG_ONE;
_scale[0] = _scale[1] = REG_ONE;
_scaleExpression[0] = _scaleExpression[1] = NOT_DEFINED;

// Translation is set to 0,0 by default
_translation[0] = _translation[1] = REG_ZERO;
_translationExpression[0] = _translationExpression[1] = NOT_DEFINED;

// Rotation is set to 0 by default
_rotation = REG_ZERO;
_rotationExpression = NOT_DEFINED;

// No shearing so far
_shear[0] = REG_ZERO;
_shear[1] = REG_ZERO;
_shearExpression[0] = _shearExpression[1] = NOT_DEFINED;

_texGenParams[0] = _texGenParams[1] = _texGenParams[2] = REG_ZERO;
}
Expand Down
37 changes: 32 additions & 5 deletions radiantcore/shaders/Doom3ShaderLayer.h
Expand Up @@ -91,16 +91,19 @@ class Doom3ShaderLayer

// The register indices of this stage's scale expressions
std::size_t _scale[2];
std::size_t _scaleExpression[2];

// The register indices of this stage's translate expressions
std::size_t _translation[2];
std::size_t _translationExpression[2];

// The rotation register index
std::size_t _rotation;
std::size_t _rotationExpression;

// The register indices of this stage's shear expressions
std::size_t _shear[2];
std::size_t _shearExpression[2];

// The shader programs used in this stage
std::string _vertexProgram;
Expand Down Expand Up @@ -325,13 +328,22 @@ class Doom3ShaderLayer
return Vector2(_registers[_scale[0]], _registers[_scale[1]]);
}

const shaders::IShaderExpressionPtr& getScaleExpression(std::size_t index) override
{
assert(index < 2);
auto expressionIndex = _scaleExpression[index];
return expressionIndex != NOT_DEFINED ? _expressions[expressionIndex] : NULL_EXPRESSION;
}

/**
* Set the scale expressions of this stage, overwriting any previous scales.
*/
void setScale(const IShaderExpressionPtr& xExpr, const IShaderExpressionPtr& yExpr)
{
_expressions.push_back(xExpr);
_expressions.push_back(yExpr);
_scaleExpression[0] = _expressions.size();
_expressions.emplace_back(xExpr);
_scaleExpression[1] = _expressions.size();
_expressions.emplace_back(yExpr);

_scale[0] = xExpr->linkToRegister(_registers);
_scale[1] = yExpr->linkToRegister(_registers);
Expand Down Expand Up @@ -368,12 +380,18 @@ class Doom3ShaderLayer
return _registers[_rotation];
}

const shaders::IShaderExpressionPtr& getRotationExpression() override
{
return _rotationExpression != NOT_DEFINED ? _expressions[_rotationExpression] : NULL_EXPRESSION;
}

/**
* Set the "rotate" expression of this stage, overwriting any previous one.
*/
void setRotation(const IShaderExpressionPtr& expr)
{
_expressions.push_back(expr);
_rotationExpression = _expressions.size();
_expressions.emplace_back(expr);

_rotation = expr->linkToRegister(_registers);
}
Expand All @@ -383,13 +401,22 @@ class Doom3ShaderLayer
return Vector2(_registers[_shear[0]], _registers[_shear[1]]);
}

const shaders::IShaderExpressionPtr& getShearExpression(std::size_t index) override
{
assert(index < 2);
auto expressionIndex = _shearExpression[index];
return expressionIndex != NOT_DEFINED ? _expressions[expressionIndex] : NULL_EXPRESSION;
}

/**
* Set the shear expressions of this stage, overwriting any previous ones.
*/
void setShear(const IShaderExpressionPtr& xExpr, const IShaderExpressionPtr& yExpr)
{
_expressions.push_back(xExpr);
_expressions.push_back(yExpr);
_shearExpression[0] = _expressions.size();
_expressions.emplace_back(xExpr);
_shearExpression[1] = _expressions.size();
_expressions.emplace_back(yExpr);

_shear[0] = xExpr->linkToRegister(_registers);
_shear[1] = yExpr->linkToRegister(_registers);
Expand Down

0 comments on commit 9a1ada5

Please sign in to comment.