kaliber/src/engine/renderer/shader.cc

75 lines
1.6 KiB
C++
Raw Normal View History

2020-04-13 11:24:53 +00:00
#include "shader.h"
#include "../shader_source.h"
#include "renderer.h"
using namespace base;
namespace eng {
Shader::Shader(unsigned resource_id,
std::shared_ptr<void> impl_data,
Renderer* renderer)
: RenderResource(resource_id, impl_data, renderer) {}
Shader::~Shader() {
Destroy();
}
void Shader::Create(std::unique_ptr<ShaderSource> source,
const VertexDescripton& vd,
Primitive primitive) {
2020-04-13 11:24:53 +00:00
Destroy();
valid_ = true;
renderer_->CreateShader(impl_data_, std::move(source), vd, primitive);
2020-04-13 11:24:53 +00:00
}
void Shader::Destroy() {
if (valid_) {
renderer_->DestroyShader(impl_data_);
2020-04-13 11:24:53 +00:00
valid_ = false;
}
}
void Shader::Activate() {
if (valid_)
renderer_->ActivateShader(impl_data_);
2020-04-13 11:24:53 +00:00
}
void Shader::SetUniform(const std::string& name, const Vector2& v) {
if (valid_)
renderer_->SetUniform(impl_data_, name, v);
2020-04-13 11:24:53 +00:00
}
void Shader::SetUniform(const std::string& name, const Vector3& v) {
if (valid_)
renderer_->SetUniform(impl_data_, name, v);
2020-04-13 11:24:53 +00:00
}
void Shader::SetUniform(const std::string& name, const Vector4& v) {
if (valid_)
renderer_->SetUniform(impl_data_, name, v);
2020-04-13 11:24:53 +00:00
}
void Shader::SetUniform(const std::string& name, const Matrix4x4& m) {
if (valid_)
renderer_->SetUniform(impl_data_, name, m);
2020-04-13 11:24:53 +00:00
}
void Shader::SetUniform(const std::string& name, float f) {
if (valid_)
renderer_->SetUniform(impl_data_, name, f);
2020-04-13 11:24:53 +00:00
}
void Shader::SetUniform(const std::string& name, int i) {
if (valid_)
renderer_->SetUniform(impl_data_, name, i);
}
void Shader::UploadUniforms() {
if (valid_)
renderer_->UploadUniforms(impl_data_);
2020-04-13 11:24:53 +00:00
}
} // namespace eng