mirror of
https://github.com/zoriya/Bomberman.git
synced 2025-12-21 05:45:10 +00:00
putting shaders changes on a new branch to avoid merge nightmare
This commit is contained in:
49
lib/Ray/sources/Shaders/Shaders.cpp
Normal file
49
lib/Ray/sources/Shaders/Shaders.cpp
Normal file
@@ -0,0 +1,49 @@
|
||||
//
|
||||
// Created by cbihan on 04/06/2021.
|
||||
//
|
||||
|
||||
#include "Shaders.hpp"
|
||||
|
||||
#include <utility>
|
||||
#include "Exceptions/RayError.hpp"
|
||||
|
||||
namespace RAY
|
||||
{
|
||||
Cache<::Shader> Shader::_shadersCache(LoadShader, UnloadShader);
|
||||
|
||||
|
||||
Shader::Shader(const std::string &vertexFile, const std::string &fragmentFile)
|
||||
: _vertexFile(vertexFile),
|
||||
_fragmentFile(fragmentFile),
|
||||
_rayLibShader(_shadersCache.fetch(vertexFile, fragmentFile))
|
||||
{
|
||||
}
|
||||
|
||||
const std::shared_ptr<::Shader> &Shader::getShaderPtr() const
|
||||
{
|
||||
return this->_rayLibShader;
|
||||
}
|
||||
|
||||
void Shader::setShaderUniformVar(const std::string &varName, float value)
|
||||
{
|
||||
if (this->_shaderIndexVars.find(varName) == this->_shaderIndexVars.end()) {
|
||||
int varShaderIndex = GetShaderLocation(*this->_rayLibShader, varName.c_str());
|
||||
|
||||
if (varShaderIndex < 0) {
|
||||
throw Exception::WrongInputError("The loaded shader doesn't have a variable called: " + varName);
|
||||
}
|
||||
this->_shaderIndexVars[varName] = varShaderIndex;
|
||||
}
|
||||
SetShaderValue(*this->_rayLibShader, this->_shaderIndexVars[varName], &value, SHADER_UNIFORM_FLOAT);
|
||||
}
|
||||
|
||||
void Shader::BeginUsingCustomShader(Shader &shader)
|
||||
{
|
||||
BeginShaderMode(*shader.getShaderPtr());
|
||||
}
|
||||
|
||||
void Shader::EndUsingCustomShader()
|
||||
{
|
||||
EndShaderMode();
|
||||
}
|
||||
}
|
||||
Reference in New Issue
Block a user