Skip to content

Commit

Permalink
#5585: Expose Material sort request methods. Fix a typo in the C++ in…
Browse files Browse the repository at this point in the history
…terface.
  • Loading branch information
codereader committed Apr 11, 2021
1 parent 2abcd93 commit f2ca7a8
Show file tree
Hide file tree
Showing 9 changed files with 59 additions and 7 deletions.
2 changes: 1 addition & 1 deletion include/ishaders.h
Expand Up @@ -224,7 +224,7 @@ class Material
virtual void setSortRequest(float sortRequest) = 0;

// Resets the sort request to the default value
virtual void resetSortReqest() = 0;
virtual void resetSortRequest() = 0;

/// Return a polygon offset if one is defined. The default is 0.
virtual float getPolygonOffset() const = 0;
Expand Down
8 changes: 8 additions & 0 deletions install/scripts/materialtest.py
@@ -1,4 +1,5 @@
import os
import darkradiant as dr

# Some interface tests

Expand Down Expand Up @@ -33,6 +34,13 @@
newMaterial.setShaderFileName(filename)
newMaterial.setEditorImageExpressionFromString('textures/common/caulk')

newMaterial.setSortRequest(45.3)

# There are a couple of pre-defined sort requests, corresponding to the engine code
newMaterial.setSortRequest(dr.Material.SortRequest.NEAREST)

print('Full Material definition:\n{0}\n{{{1}}}'.format(newMaterial.getName(), newMaterial.getDefinition()))

GlobalMaterialManager.saveMaterial(newMaterial.getName())

fullPath = GlobalFileSystem.findFile(filename) + filename
Expand Down
21 changes: 21 additions & 0 deletions plugins/script/interfaces/ShaderSystemInterface.cpp
Expand Up @@ -84,6 +84,23 @@ void ShaderSystemInterface::registerInterface(py::module& scope, py::dict& globa
// Add the old name as alias
scope.add_object("Shader", material);

// Expose the enums in the material scope
py::enum_<Material::SortRequest>(material, "SortRequest")
.value("SUBVIEW", Material::SORT_SUBVIEW)
.value("GUI", Material::SORT_GUI)
.value("BAD", Material::SORT_BAD)
.value("OPAQUE", Material::SORT_OPAQUE)
.value("PORTAL_SKY", Material::SORT_PORTAL_SKY)
.value("DECAL", Material::SORT_DECAL)
.value("FAR", Material::SORT_FAR)
.value("MEDIUM", Material::SORT_MEDIUM)
.value("CLOSE", Material::SORT_CLOSE)
.value("ALMOST_NEAREST", Material::SORT_ALMOST_NEAREST)
.value("NEAREST", Material::SORT_NEAREST)
.value("AFTER_FOG", Material::SORT_AFTER_FOG)
.value("POST_PROCESS", Material::SORT_POST_PROCESS)
.export_values();

material.def(py::init<const MaterialPtr&>());
material.def("getName", &ScriptMaterial::getName);
material.def("getShaderFileName", &ScriptMaterial::getShaderFileName);
Expand All @@ -97,6 +114,10 @@ void ShaderSystemInterface::registerInterface(py::module& scope, py::dict& globa
material.def("isNull", &ScriptMaterial::isNull);
material.def("getEditorImageExpressionString", &ScriptMaterial::getEditorImageExpressionString);
material.def("setEditorImageExpressionFromString", &ScriptMaterial::setEditorImageExpressionFromString);
material.def("getSortRequest", &ScriptMaterial::getSortRequest);
material.def("setSortRequest", static_cast<void(ScriptMaterial::*)(float)>(&ScriptMaterial::setSortRequest));
material.def("setSortRequest", static_cast<void(ScriptMaterial::*)(Material::SortRequest)>(&ScriptMaterial::setSortRequest));
material.def("resetSortRequest", &ScriptMaterial::resetSortRequest);

// Expose the MaterialVisitor interface

Expand Down
23 changes: 23 additions & 0 deletions plugins/script/interfaces/ShaderSystemInterface.h
Expand Up @@ -79,6 +79,29 @@ class ScriptMaterial
_material->setEditorImageExpressionFromString(editorImagePath);
}

float getSortRequest()
{
return _material ? _material->getSortRequest() : -1;
}

void setSortRequest(float sortRequest)
{
throwIfMaterialCannotBeModified();
if (_material) _material->setSortRequest(sortRequest);
}

void setSortRequest(Material::SortRequest sortRequest) // overload needed for python
{
throwIfMaterialCannotBeModified();
if (_material) _material->setSortRequest(static_cast<float>(sortRequest));
}

void resetSortRequest()
{
throwIfMaterialCannotBeModified();
if (_material) _material->resetSortRequest();
}

private:
void throwIfMaterialCannotBeModified()
{
Expand Down
2 changes: 1 addition & 1 deletion radiant/ui/materials/editor/MaterialEditor.cpp
Expand Up @@ -586,7 +586,7 @@ void MaterialEditor::setupMaterialProperties()
{
if (!value)
{
material->resetSortReqest();
material->resetSortRequest();
}
else
{
Expand Down
4 changes: 2 additions & 2 deletions radiantcore/shaders/CShader.cpp
Expand Up @@ -58,10 +58,10 @@ void CShader::setSortRequest(float sortRequest)
_template->setSortRequest(sortRequest);
}

void CShader::resetSortReqest()
void CShader::resetSortRequest()
{
ensureTemplateCopy();
_template->resetSortReqest();
_template->resetSortRequest();
}

float CShader::getPolygonOffset() const
Expand Down
2 changes: 1 addition & 1 deletion radiantcore/shaders/CShader.h
Expand Up @@ -61,7 +61,7 @@ class CShader final :
/* Material implementation */
float getSortRequest() const override;
void setSortRequest(float sortRequest) override;
void resetSortReqest() override;
void resetSortRequest() override;
float getPolygonOffset() const override;
void setPolygonOffset(float offset) override;
TexturePtr getEditorImage() override;
Expand Down
2 changes: 1 addition & 1 deletion radiantcore/shaders/ShaderTemplate.cpp
Expand Up @@ -1252,7 +1252,7 @@ void ShaderTemplate::parseDefinition()
// Some blend materials get SORT_MEDIUM applied by default, diffuses get OPAQUE assigned, but lights do not, etc.
if (_sortReq == SORT_UNDEFINED)
{
resetSortReqest();
resetSortRequest();
}

std::size_t numAmbientStages = 0;
Expand Down
2 changes: 1 addition & 1 deletion radiantcore/shaders/ShaderTemplate.h
Expand Up @@ -384,7 +384,7 @@ class ShaderTemplate final
onTemplateChanged();
}

void resetSortReqest()
void resetSortRequest()
{
if (!_parsed) parseDefinition();

Expand Down

0 comments on commit f2ca7a8

Please sign in to comment.