#include "../../../include/RenderBackend/OpenGL/ShaderVec.hpp" #include "../../../include/RenderBackend/OpenGL/Shader.hpp" #include "../../../include/RenderBackend/OpenGL/ShaderProgram.hpp" #include "../../../include/RenderBackend/OpenGL/opengl.hpp" #include #include using namespace std; namespace amalgine { AttributeType getAttributeTypeByName(const char *attributeName) { if(strncmp(attributeName, "vec2", 4) == 0) { return AttributeType::VEC2; } else if(strncmp(attributeName, "vec3", 4) == 0) { return AttributeType::VEC3; } else if(strncmp(attributeName, "vec4", 4) == 0) { return AttributeType::VEC4; } assert(false); return AttributeType::NONE; } void ShaderProgramGlobalVec3::set(f32 x, f32 y, f32 z) { shaderProgram->use(); glUniform3f(uniformId, x, y, z); } const string& ShaderInputVec2::getName() const { return shader->getInputAttributeName(attributeIndex); } void ShaderInputVec2::setData(const DeviceMemory &data) { data.use(); AttributeType attributeType = shader->getInputAttributeType(attributeIndex); switch(attributeType) { case AttributeType::VEC2: { glVertexAttribPointer(attributeIndex, 2, GL_FLOAT, GL_FALSE, 0, 0); break; } default: assert(false); break; } glEnableVertexAttribArray(attributeIndex); } const string& ShaderOutputVec4::getName() const { return shader->getOutputAttributeName(attributeIndex); } void ShaderOutputVec4::operator=(const ShaderVec4 &shaderVec4) { shader->assign(*this, shaderVec4); } }