mirror of
https://github.com/TomHarte/CLK.git
synced 2024-11-22 12:33:29 +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) {
|
||||
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();
|
||||
const GLuint vertex = compile_shader(vertex_shader, GL_VERTEX_SHADER);
|
||||
const GLuint fragment = compile_shader(fragment_shader, GL_FRAGMENT_SHADER);
|
||||
|
@ -34,6 +34,7 @@ public:
|
||||
};
|
||||
|
||||
struct AttributeBinding {
|
||||
AttributeBinding(const std::string &name, GLuint index) : name(name), index(index) {}
|
||||
const std::string name;
|
||||
const GLuint index;
|
||||
};
|
||||
@ -45,6 +46,13 @@ public:
|
||||
@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 = {});
|
||||
/*!
|
||||
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();
|
||||
|
||||
/*!
|
||||
@ -109,6 +117,8 @@ public:
|
||||
void set_uniform_matrix(const std::string &name, GLint size, GLsizei count, bool transpose, const GLfloat *values);
|
||||
|
||||
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 shader_program_;
|
||||
|
||||
|
@ -179,12 +179,12 @@ std::unique_ptr<Shader> ScanTarget::composition_shader() const {
|
||||
vertex_shader,
|
||||
fragment_shader + "}",
|
||||
{
|
||||
{"startDataX", 0},
|
||||
{"startClock", 1},
|
||||
{"endDataX", 2},
|
||||
{"endClock", 3},
|
||||
{"dataY", 4},
|
||||
{"lineY", 5},
|
||||
"startDataX",
|
||||
"startClock",
|
||||
"endDataX",
|
||||
"endClock",
|
||||
"dataY",
|
||||
"lineY",
|
||||
}
|
||||
));
|
||||
}
|
||||
@ -491,14 +491,14 @@ std::unique_ptr<Shader> ScanTarget::conversion_shader() const {
|
||||
vertex_shader,
|
||||
fragment_shader,
|
||||
{
|
||||
{"startPoint", 0},
|
||||
{"endPoint", 1},
|
||||
{"startClock", 2},
|
||||
{"endClock", 3},
|
||||
{"lineY", 4},
|
||||
{"lineCompositeAmplitude", 5},
|
||||
{"startCompositeAngle", 6},
|
||||
{"endCompositeAngle", 7},
|
||||
"startPoint",
|
||||
"endPoint",
|
||||
"startClock",
|
||||
"endClock",
|
||||
"lineY",
|
||||
"lineCompositeAmplitude",
|
||||
"startCompositeAngle",
|
||||
"endCompositeAngle"
|
||||
}
|
||||
);
|
||||
|
||||
|
Loading…
Reference in New Issue
Block a user