70 lines
2.0 KiB
C++
70 lines
2.0 KiB
C++
// Copyright (c) 2022 Dominic Masters
|
|
//
|
|
// This software is released under the MIT License.
|
|
// https://opensource.org/licenses/MIT
|
|
|
|
#include "Material.hpp"
|
|
#include "scene/Scene.hpp"
|
|
#include "game/DawnGame.hpp"
|
|
|
|
using namespace Dawn;
|
|
|
|
Material::Material(SceneItem *item) : SceneItemComponent(item) {
|
|
this->shader = item->scene->game->renderManager.getDefaultShader();
|
|
this->updateShaderParameters();
|
|
}
|
|
|
|
void Material::updateShaderParameters() {
|
|
this->colorValues.clear();
|
|
this->boolValues.clear();
|
|
|
|
this->parameters = this->shader->getParameters();
|
|
this->shader->setDefaultParameters(this);
|
|
|
|
// We do need to validate these params at some point to make sure that the
|
|
// shader has actually bound them.
|
|
}
|
|
|
|
void Material::setShaderParameters() {
|
|
auto it = this->parameters.begin();
|
|
while(it != this->parameters.end()) {
|
|
switch(it->second) {
|
|
case SHADER_PARAMETER_TYPE_COLOR:
|
|
this->shader->setColor(it->first, this->colorValues[it->first]);
|
|
break;
|
|
|
|
case SHADER_PARAMETER_TYPE_MATRIX:
|
|
this->shader->setMatrix(it->first, this->matrixValues[it->first]);
|
|
break;
|
|
|
|
case SHADER_PARAMETER_TYPE_BOOLEAN:
|
|
this->shader->setBoolean(it->first, this->boolValues[it->first]);
|
|
break;
|
|
|
|
case SHADER_PARAMETER_TYPE_VECTOR3:
|
|
this->shader->setVector3(it->first, this->vec3Values[it->first]);
|
|
break;
|
|
|
|
case SHADER_PARAMETER_TYPE_TEXTURE:
|
|
this->shader->setTexture(it->first, this->textureValues[it->first]);
|
|
break;
|
|
|
|
case SHADER_PARAMETER_TYPE_FLOAT:
|
|
this->shader->setFloat(it->first, this->floatValues[it->first]);
|
|
break;
|
|
|
|
default:
|
|
throw "An unsupported or invalid shader parameter type was supplied.";
|
|
}
|
|
++it;
|
|
}
|
|
}
|
|
|
|
Shader * Material::getShader() {
|
|
return this->shader;
|
|
}
|
|
|
|
void Material::setShader(Shader * shader) {
|
|
this->shader = shader;
|
|
this->updateShaderParameters();
|
|
} |