mirror of
https://github.com/TomHarte/CLK.git
synced 2024-11-26 08:49:37 +00:00
Offers a less error-prone route to attribute binding.
This commit is contained in:
parent
73e32a9c76
commit
85ad490089
@ -46,6 +46,20 @@ GLuint Shader::compile_shader(const std::string &source, GLenum type) {
|
|||||||
}
|
}
|
||||||
|
|
||||||
Shader::Shader(const std::string &vertex_shader, const std::string &fragment_shader, const std::vector<AttributeBinding> &attribute_bindings) {
|
Shader::Shader(const std::string &vertex_shader, const std::string &fragment_shader, const std::vector<AttributeBinding> &attribute_bindings) {
|
||||||
|
init(vertex_shader, fragment_shader, attribute_bindings);
|
||||||
|
}
|
||||||
|
|
||||||
|
Shader::Shader(const std::string &vertex_shader, const std::string &fragment_shader, const std::vector<std::string> &binding_names) {
|
||||||
|
std::vector<AttributeBinding> bindings;
|
||||||
|
GLuint index = 0;
|
||||||
|
for(const auto &name: binding_names) {
|
||||||
|
bindings.emplace_back(name, index);
|
||||||
|
++index;
|
||||||
|
}
|
||||||
|
init(vertex_shader, fragment_shader, bindings);
|
||||||
|
}
|
||||||
|
|
||||||
|
void Shader::init(const std::string &vertex_shader, const std::string &fragment_shader, const std::vector<AttributeBinding> &attribute_bindings) {
|
||||||
shader_program_ = glCreateProgram();
|
shader_program_ = glCreateProgram();
|
||||||
const GLuint vertex = compile_shader(vertex_shader, GL_VERTEX_SHADER);
|
const GLuint vertex = compile_shader(vertex_shader, GL_VERTEX_SHADER);
|
||||||
const GLuint fragment = compile_shader(fragment_shader, GL_FRAGMENT_SHADER);
|
const GLuint fragment = compile_shader(fragment_shader, GL_FRAGMENT_SHADER);
|
||||||
|
@ -34,6 +34,7 @@ public:
|
|||||||
};
|
};
|
||||||
|
|
||||||
struct AttributeBinding {
|
struct AttributeBinding {
|
||||||
|
AttributeBinding(const std::string &name, GLuint index) : name(name), index(index) {}
|
||||||
const std::string name;
|
const std::string name;
|
||||||
const GLuint index;
|
const GLuint index;
|
||||||
};
|
};
|
||||||
@ -45,6 +46,13 @@ public:
|
|||||||
@param attribute_bindings A vector of attribute bindings.
|
@param attribute_bindings A vector of attribute bindings.
|
||||||
*/
|
*/
|
||||||
Shader(const std::string &vertex_shader, const std::string &fragment_shader, const std::vector<AttributeBinding> &attribute_bindings = {});
|
Shader(const std::string &vertex_shader, const std::string &fragment_shader, const std::vector<AttributeBinding> &attribute_bindings = {});
|
||||||
|
/*!
|
||||||
|
Attempts to compile a shader, throwing @c VertexShaderCompilationError, @c FragmentShaderCompilationError or @c ProgramLinkageError upon failure.
|
||||||
|
@param vertex_shader The vertex shader source code.
|
||||||
|
@param fragment_shader The fragment shader source code.
|
||||||
|
@param binding_names A list of attributes to generate bindings for; these will be given indices 0...n-1.
|
||||||
|
*/
|
||||||
|
Shader(const std::string &vertex_shader, const std::string &fragment_shader, const std::vector<std::string> &binding_names);
|
||||||
~Shader();
|
~Shader();
|
||||||
|
|
||||||
/*!
|
/*!
|
||||||
@ -109,6 +117,8 @@ public:
|
|||||||
void set_uniform_matrix(const std::string &name, GLint size, GLsizei count, bool transpose, const GLfloat *values);
|
void set_uniform_matrix(const std::string &name, GLint size, GLsizei count, bool transpose, const GLfloat *values);
|
||||||
|
|
||||||
private:
|
private:
|
||||||
|
void init(const std::string &vertex_shader, const std::string &fragment_shader, const std::vector<AttributeBinding> &attribute_bindings);
|
||||||
|
|
||||||
GLuint compile_shader(const std::string &source, GLenum type);
|
GLuint compile_shader(const std::string &source, GLenum type);
|
||||||
GLuint shader_program_;
|
GLuint shader_program_;
|
||||||
|
|
||||||
|
@ -179,12 +179,12 @@ std::unique_ptr<Shader> ScanTarget::composition_shader() const {
|
|||||||
vertex_shader,
|
vertex_shader,
|
||||||
fragment_shader + "}",
|
fragment_shader + "}",
|
||||||
{
|
{
|
||||||
{"startDataX", 0},
|
"startDataX",
|
||||||
{"startClock", 1},
|
"startClock",
|
||||||
{"endDataX", 2},
|
"endDataX",
|
||||||
{"endClock", 3},
|
"endClock",
|
||||||
{"dataY", 4},
|
"dataY",
|
||||||
{"lineY", 5},
|
"lineY",
|
||||||
}
|
}
|
||||||
));
|
));
|
||||||
}
|
}
|
||||||
@ -491,14 +491,14 @@ std::unique_ptr<Shader> ScanTarget::conversion_shader() const {
|
|||||||
vertex_shader,
|
vertex_shader,
|
||||||
fragment_shader,
|
fragment_shader,
|
||||||
{
|
{
|
||||||
{"startPoint", 0},
|
"startPoint",
|
||||||
{"endPoint", 1},
|
"endPoint",
|
||||||
{"startClock", 2},
|
"startClock",
|
||||||
{"endClock", 3},
|
"endClock",
|
||||||
{"lineY", 4},
|
"lineY",
|
||||||
{"lineCompositeAmplitude", 5},
|
"lineCompositeAmplitude",
|
||||||
{"startCompositeAngle", 6},
|
"startCompositeAngle",
|
||||||
{"endCompositeAngle", 7},
|
"endCompositeAngle"
|
||||||
}
|
}
|
||||||
);
|
);
|
||||||
|
|
||||||
|
Loading…
Reference in New Issue
Block a user