Skip to content

Commit

Permalink
#5532: Migrate condition to use expression slots
Browse files Browse the repository at this point in the history
  • Loading branch information
codereader committed Mar 14, 2021
1 parent 32c566c commit 01be8ed
Show file tree
Hide file tree
Showing 3 changed files with 5 additions and 16 deletions.
1 change: 1 addition & 0 deletions include/ishaderlayer.h
Expand Up @@ -105,6 +105,7 @@ class IShaderLayer
enum Slot
{
AlphaTest = 0,
Condition,
TexGenParam1,
TexGenParam2,
TexGenParam3,
Expand Down
5 changes: 1 addition & 4 deletions radiantcore/shaders/Doom3ShaderLayer.cpp
Expand Up @@ -130,8 +130,6 @@ Doom3ShaderLayer::Doom3ShaderLayer(ShaderTemplate& material, IShaderLayer::Type
: _material(material),
_registers(NUM_RESERVED_REGISTERS),
_expressionSlots(_registers),
_condition(REG_ONE),
_conditionExpression(NOT_DEFINED),
_bindableTex(btex),
_type(type),
_mapType(MapType::Map),
Expand All @@ -148,6 +146,7 @@ Doom3ShaderLayer::Doom3ShaderLayer(ShaderTemplate& material, IShaderLayer::Type
_registers[REG_ONE] = 1;

_expressionSlots[Expression::AlphaTest].registerIndex = REG_ZERO;
_expressionSlots[Expression::Condition].registerIndex = REG_ONE;

// Init the colour to 1,1,1,1
_colIdx[0] = _colIdx[1] = _colIdx[2] = _colIdx[3] = REG_ONE;
Expand Down Expand Up @@ -180,8 +179,6 @@ Doom3ShaderLayer::Doom3ShaderLayer(const Doom3ShaderLayer& other, ShaderTemplate
_registers(other._registers),
_expressions(other._expressions),
_expressionSlots(other._expressionSlots, _registers),
_condition(other._condition),
_conditionExpression(other._conditionExpression),
_bindableTex(other._bindableTex),
_texture(other._texture),
_type(other._type),
Expand Down
15 changes: 3 additions & 12 deletions radiantcore/shaders/Doom3ShaderLayer.h
Expand Up @@ -78,10 +78,6 @@ class Doom3ShaderLayer :
static const IShaderExpression::Ptr NULL_EXPRESSION;
static const std::size_t NOT_DEFINED = std::numeric_limits<std::size_t>::max();

// The condition register for this stage. Points to a register to be interpreted as bool.
std::size_t _condition;
std::size_t _conditionExpression;

// The bindable texture for this stage
NamedBindablePtr _bindableTex;

Expand Down Expand Up @@ -188,22 +184,17 @@ class Doom3ShaderLayer :
// (expressions must have been evaluated before this call)
bool isVisible() const
{
return _registers[_condition] != 0;
return _registers[_expressionSlots[Expression::Condition].registerIndex] != 0;
}

const shaders::IShaderExpression::Ptr& getConditionExpression() const override
{
return _conditionExpression != NOT_DEFINED ? _expressions[_conditionExpression] : NULL_EXPRESSION;
return _expressionSlots[Expression::Condition].expression;
}

void setCondition(const IShaderExpression::Ptr& conditionExpr)
{
// Store the expression in our list
_conditionExpression = _expressions.size();
_expressions.emplace_back(conditionExpr);

// Link the result to our local registers
_condition = conditionExpr->linkToRegister(_registers);
_expressionSlots.assign(Expression::Condition, conditionExpr, REG_ONE);
}

void evaluateExpressions(std::size_t time)
Expand Down

0 comments on commit 01be8ed

Please sign in to comment.