Skip to content

Commit

Permalink
#5565: Start working on getting qer_editorimage manipulatable at runtime
Browse files Browse the repository at this point in the history
  • Loading branch information
codereader committed Mar 26, 2021
1 parent 444be05 commit 51ac2ff
Show file tree
Hide file tree
Showing 7 changed files with 295 additions and 42 deletions.
7 changes: 7 additions & 0 deletions include/ishaders.h
Expand Up @@ -190,6 +190,13 @@ class Material
/// Return true if the editor image is no tex for this shader.
virtual bool isEditorImageNoTex() = 0;

// Returns the expression defining the editor image of this material, as passed to qer_editorimage statement,
// or an empty string if this keyword was not used at all in this declaration.
virtual shaders::IMapExpression::Ptr getEditorImageExpression() = 0;

// Set the editor image path of this material
virtual void setEditorImageExpressionFromString(const std::string& editorImagePath) = 0;

/// Get the string name of this material
virtual std::string getName() const = 0;

Expand Down
256 changes: 222 additions & 34 deletions install/ui/materialeditor.fbp

Large diffs are not rendered by default.

29 changes: 29 additions & 0 deletions install/ui/materialeditor.xrc
Expand Up @@ -334,6 +334,35 @@
<object class="wxBoxSizer">
<orient>wxVERTICAL</orient>
<object class="sizeritem">
<option>0</option>
<flag>wxBOTTOM|wxEXPAND|wxTOP</flag>
<border>6</border>
<object class="wxPanel" name="MaterialEditorImagePanel">
<style>wxTAB_TRAVERSAL</style>
<object class="wxBoxSizer">
<orient>wxHORIZONTAL</orient>
<object class="sizeritem">
<option>0</option>
<flag>wxALIGN_CENTER_VERTICAL|wxLEFT|wxRIGHT</flag>
<border>6</border>
<object class="wxStaticText" name="m_staticText59">
<tooltip>qer__editorimage</tooltip>
<label>Editor Image:</label>
<wrap>-1</wrap>
</object>
</object>
<object class="sizeritem">
<option>1</option>
<flag>wxALIGN_CENTER_VERTICAL</flag>
<border>6</border>
<object class="wxTextCtrl" name="MaterialEditorImage">
<value></value>
</object>
</object>
</object>
</object>
</object>
<object class="sizeritem">
<option>1</option>
<flag>wxEXPAND</flag>
<border>0</border>
Expand Down
12 changes: 12 additions & 0 deletions radiantcore/shaders/CShader.cpp
@@ -1,5 +1,6 @@
#include "CShader.h"
#include "Doom3ShaderSystem.h"
#include "MapExpression.h"

#include "iregistry.h"
#include "ishaders.h"
Expand Down Expand Up @@ -87,6 +88,17 @@ TexturePtr CShader::getEditorImage()
return _editorTexture;
}

IMapExpression::Ptr CShader::getEditorImageExpression()
{
return _template->getEditorTexture();
}

void CShader::setEditorImageExpressionFromString(const std::string& editorImagePath)
{
ensureTemplateCopy();
_template->setEditorImageExpressionFromString(editorImagePath);
}

bool CShader::isEditorImageNoTex()
{
return (getEditorImage() == GetTextureManager().getShaderNotFound());
Expand Down
2 changes: 2 additions & 0 deletions radiantcore/shaders/CShader.h
Expand Up @@ -65,6 +65,8 @@ class CShader final :
float getPolygonOffset() const override;
void setPolygonOffset(float offset) override;
TexturePtr getEditorImage() override;
IMapExpression::Ptr getEditorImageExpression() override;
void setEditorImageExpressionFromString(const std::string& editorImagePath) override;
bool isEditorImageNoTex() override;
TexturePtr lightFalloffImage() override;
std::string getName() const override;
Expand Down
25 changes: 19 additions & 6 deletions radiantcore/shaders/ShaderTemplate.cpp
Expand Up @@ -68,14 +68,27 @@ std::shared_ptr<ShaderTemplate> ShaderTemplate::clone() const
return std::make_shared<ShaderTemplate>(*this);
}

NamedBindablePtr ShaderTemplate::getEditorTexture()
const MapExpressionPtr& ShaderTemplate::getEditorTexture()
{
if (!_parsed)
parseDefinition();
if (!_parsed) parseDefinition();

return _editorTex;
}

void ShaderTemplate::setEditorImageExpressionFromString(const std::string& expression)
{
if (!_parsed) parseDefinition();

if (expression.empty())
{
_editorTex.reset();
return;
}

_editorTex = MapExpression::createForString(expression);
onTemplateChanged();
}

IShaderExpression::Ptr ShaderTemplate::parseSingleExpressionTerm(parser::DefTokeniser& tokeniser)
{
std::string token = tokeniser.nextToken();
Expand Down Expand Up @@ -1307,10 +1320,10 @@ void ShaderTemplate::addLayer(const Doom3ShaderLayer::Ptr& layer)
_layers.emplace_back(layer);

// If there is no editor texture yet, use the bindable texture, but no Bump or speculars
if (!_editorTex && layer->getBindableTexture() &&
layer->getType() != IShaderLayer::BUMP && layer->getType() != IShaderLayer::SPECULAR)
if (!_editorTex && layer->getType() != IShaderLayer::BUMP &&
layer->getType() != IShaderLayer::SPECULAR && std::dynamic_pointer_cast<MapExpression>(layer->getMapExpression()))
{
_editorTex = layer->getBindableTexture();
_editorTex = std::static_pointer_cast<MapExpression>(layer->getMapExpression());
}
}

Expand Down
6 changes: 4 additions & 2 deletions radiantcore/shaders/ShaderTemplate.h
Expand Up @@ -40,7 +40,7 @@ class ShaderTemplate final
std::vector<Doom3ShaderLayer::Ptr> _layers;

// Editorimage texture
NamedBindablePtr _editorTex;
MapExpressionPtr _editorTex;

// Map expressions
MapExpressionPtr _lightFalloff;
Expand Down Expand Up @@ -425,7 +425,9 @@ class ShaderTemplate final
* Return the named bindable corresponding to the editor preview texture
* (qer_editorimage).
*/
NamedBindablePtr getEditorTexture();
const MapExpressionPtr& getEditorTexture();

void setEditorImageExpressionFromString(const std::string& expression);

const MapExpressionPtr& getLightFalloff()
{
Expand Down

0 comments on commit 51ac2ff

Please sign in to comment.