Skip to content

Commit

Permalink
#5532: Implement copy/clone functionality for ShaderTemplate and Doom…
Browse files Browse the repository at this point in the history
…3ShaderLayer
  • Loading branch information
codereader committed Mar 12, 2021
1 parent 8c4d89e commit f1cdf05
Show file tree
Hide file tree
Showing 3 changed files with 99 additions and 6 deletions.
60 changes: 60 additions & 0 deletions radiantcore/shaders/Doom3ShaderLayer.cpp
Expand Up @@ -123,6 +123,66 @@ Doom3ShaderLayer::Doom3ShaderLayer(ShaderTemplate& material, ShaderLayer::Type t
_texGenParams[0] = _texGenParams[1] = _texGenParams[2] = REG_ZERO;
}

Doom3ShaderLayer::Doom3ShaderLayer(const Doom3ShaderLayer& other, ShaderTemplate& material) :
_material(material),
_registers(other._registers),
_expressions(other._expressions),
_condition(other._condition),
_conditionExpression(other._conditionExpression),
_bindableTex(other._bindableTex),
_texture(other._texture),
_type(other._type),
_mapType(other._mapType),
_blendFuncStrings(other._blendFuncStrings),
_vertexColourMode(other._vertexColourMode),
_cubeMapMode(other._cubeMapMode),
_stageFlags(other._stageFlags),
_clampType(other._clampType),
_alphaTest(other._alphaTest),
_texGenType(other._texGenType),
_rotation(other._rotation),
_rotationExpression(other._rotationExpression),
_vertexProgram(other._vertexProgram),
_fragmentProgram(other._fragmentProgram),
_vertexParms(other._vertexParms),
_vertexParmDefinitions(other._vertexParmDefinitions),
_fragmentMaps(other._fragmentMaps),
_privatePolygonOffset(other._privatePolygonOffset),
_renderMapSize(other._renderMapSize),
_parseFlags(other._parseFlags)
{
_colIdx[0] = other._colIdx[0];
_colIdx[1] = other._colIdx[1];
_colIdx[2] = other._colIdx[2];
_colIdx[3] = other._colIdx[3];
_colExpression[0] = other._colExpression[0];
_colExpression[1] = other._colExpression[1];
_colExpression[2] = other._colExpression[2];
_colExpression[3] = other._colExpression[3];

_texGenParams[0] = other._texGenParams[0];
_texGenParams[1] = other._texGenParams[1];
_texGenParams[2] = other._texGenParams[2];
_texGenExpressions[0] = other._texGenExpressions[0];
_texGenExpressions[1] = other._texGenExpressions[1];
_texGenExpressions[2] = other._texGenExpressions[2];

_scale[0] = other._scale[0];
_scale[1] = other._scale[1];
_scaleExpression[0] = other._scaleExpression[0];
_scaleExpression[1] = other._scaleExpression[1];

_translation[0] = other._translation[0];
_translation[1] = other._translation[1];
_translationExpression[0] = other._translationExpression[0];
_translationExpression[1] = other._translationExpression[1];

_shear[0] = other._shear[0];
_shear[1] = other._shear[1];
_shearExpression[0] = other._shearExpression[0];
_shearExpression[1] = other._shearExpression[1];
}

TexturePtr Doom3ShaderLayer::getTexture() const
{
// Bind texture to GL if needed
Expand Down
9 changes: 5 additions & 4 deletions radiantcore/shaders/Doom3ShaderLayer.h
Expand Up @@ -18,8 +18,8 @@ class ShaderTemplate;
* \brief
* Implementation of ShaderLayer for Doom 3 shaders.
*/
class Doom3ShaderLayer
: public ShaderLayer
class Doom3ShaderLayer :
public ShaderLayer
{
private:
// The owning material template
Expand Down Expand Up @@ -115,12 +115,13 @@ class Doom3ShaderLayer
int _parseFlags;

public:

// Constructor
Doom3ShaderLayer(ShaderTemplate& material,
ShaderLayer::Type type = ShaderLayer::BLEND,
const NamedBindablePtr& btex = NamedBindablePtr());

// Copy-constructor, needs the new owner template as argument
Doom3ShaderLayer(const Doom3ShaderLayer& other, ShaderTemplate& material);

/* ShaderLayer implementation */
TexturePtr getTexture() const;
BlendFunc getBlendFunc() const;
Expand Down
36 changes: 34 additions & 2 deletions radiantcore/shaders/ShaderTemplate.cpp
Expand Up @@ -21,9 +21,41 @@
namespace shaders
{

ShaderTemplate::ShaderTemplate(const ShaderTemplate& other)
ShaderTemplate::ShaderTemplate(const ShaderTemplate& other) :
_name(other._name),
_currentLayer(new Doom3ShaderLayer(*this)),
_lightFalloff(other._lightFalloff),
_lightFalloffCubeMap(other._lightFalloffCubeMap),
fogLight(other.fogLight),
ambientLight(other.ambientLight),
blendLight(other.blendLight),
_cubicLight(other._cubicLight),
description(other.description),
_materialFlags(other._materialFlags),
_cullType(other._cullType),
_clampType(other._clampType),
_surfaceFlags(other._surfaceFlags),
_surfaceType(other._surfaceType),
_deformType(other._deformType),
_deformExpressions(other._deformExpressions),
_deformDeclName(other._deformDeclName),
_spectrum(other._spectrum),
_sortReq(other._sortReq),
_polygonOffset(other._polygonOffset),
_decalInfo(other._decalInfo),
_coverage(other._coverage),
_renderBumpArguments(other._renderBumpArguments),
_renderBumpFlatArguments(other._renderBumpFlatArguments),
_blockContents(other._blockContents),
_parsed(other._parsed),
_parseFlags(other._parseFlags),
_guiDeclName(other._guiDeclName)
{
// TODO
// Clone the layers
for (const auto& otherLayer : other._layers)
{
_layers.emplace_back(std::make_shared<Doom3ShaderLayer>(*otherLayer, *this));
}
}

std::shared_ptr<ShaderTemplate> ShaderTemplate::clone() const
Expand Down

0 comments on commit f1cdf05

Please sign in to comment.