#include "../../../include/RenderBackend/OpenGL/PixelShader.hpp" using namespace std; namespace amalgine { PixelShaderTooManyAttributes::PixelShaderTooManyAttributes(i32 maxPixelAttributes) : runtime_error(string("Attempting to define more than ") + to_string(maxPixelAttributes) + " pixel attributes") { } PixelShaderAttributeAlreadyDefined::PixelShaderAttributeAlreadyDefined(const std::string &attributeName) : runtime_error(string("A pixel attribute with the name ") + attributeName + " has already been defined") { } PixelShaderInvalidAttributeName::PixelShaderInvalidAttributeName(const std::string &attributeName) : runtime_error(string("Pixel attribute name ") + attributeName + " is invalid") { } PixelShaderFunctionAlreadyDefined::PixelShaderFunctionAlreadyDefined(const std::string &funcName) : runtime_error(string("Pixel shader function already defined: ") + funcName) { } PixelShader::PixelShader() : mainFuncDefined(false) { writeHeader("#version 330 core\n\n"); } void PixelShader::defineMain(PixelShaderMainFunc mainFunc) { if(mainFuncDefined) throw PixelShaderFunctionAlreadyDefined("main"); writeBody("void main() {\n"); mainFunc(); mainFuncDefined = true; writeBody("}\n\n"); } void PixelShader::assign(const ShaderOutputVec4 &lhsVariable, const ShaderVec4 &rhsVariable) { writeBody(lhsVariable.getName()); writeBody(" = "); writeBody(rhsVariable.getOutput()); writeBody(";\n"); } string PixelShader::build() const { std::string result; result.reserve(header.size() + 2 + body.size()); result += header; result += "\n"; result += body; return result; } void PixelShader::writeHeader(const string &code) { header += code; } void PixelShader::writeBody(const string &code) { body += code; } }