Bind program attributes from code
This commit is contained in:
parent
d02e6ebf8f
commit
62b204ba56
|
@ -1,3 +0,0 @@
|
|||
position
|
||||
normal
|
||||
tex_coord
|
|
@ -73,7 +73,11 @@ int main()
|
|||
emscripten_set_mousemove_callback(nullptr, nullptr, false, on_em_mousemove);
|
||||
|
||||
Program *program = new Program("textured");
|
||||
program->bind_attrib_location(INDEX_POSITION, "position");
|
||||
program->bind_attrib_location(INDEX_NORMAL, "normal");
|
||||
program->bind_attrib_location(INDEX_TEX_COORD, "tex_coord");
|
||||
program->link();
|
||||
|
||||
program->use();
|
||||
|
||||
mvp_uniform = program->get_uniform_location("mvp");
|
||||
|
|
|
@ -20,22 +20,11 @@ Program::Program(const std::string &name)
|
|||
|
||||
glAttachShader(_id, vertex_shader.id());
|
||||
glAttachShader(_id, fragment_shader.id());
|
||||
|
||||
std::ifstream file(path + "attrib.txt", std::ios::in);
|
||||
|
||||
std::string line;
|
||||
int index = 0;
|
||||
|
||||
while (std::getline(file, line))
|
||||
glBindAttribLocation(_id, index++, line.c_str());
|
||||
|
||||
for (int i = 0; i < index; ++i)
|
||||
glEnableVertexAttribArray(i);
|
||||
}
|
||||
|
||||
void Program::use() const
|
||||
void Program::bind_attrib_location(GLuint index, const GLchar *name)
|
||||
{
|
||||
glUseProgram(_id);
|
||||
glBindAttribLocation(_id, index, name);
|
||||
}
|
||||
|
||||
void Program::link()
|
||||
|
@ -43,6 +32,11 @@ void Program::link()
|
|||
glLinkProgram(_id);
|
||||
}
|
||||
|
||||
void Program::use() const
|
||||
{
|
||||
glUseProgram(_id);
|
||||
}
|
||||
|
||||
GLuint Program::get_uniform_location(const GLchar *name) const
|
||||
{
|
||||
return glGetUniformLocation(_id, name);
|
||||
|
|
|
@ -9,10 +9,11 @@ struct Program
|
|||
{
|
||||
Program(const std::string &name);
|
||||
|
||||
void use() const;
|
||||
void bind_attrib_location(GLuint index, const GLchar *name);
|
||||
|
||||
void link();
|
||||
|
||||
void use() const;
|
||||
GLuint get_uniform_location(const GLchar *name) const;
|
||||
|
||||
private:
|
||||
|
|
Reference in New Issue