Allow passing shaders and attribute locations to Program constructor.
This commit is contained in:
parent
b16d6fa43f
commit
52d7eb5eab
@ -7,13 +7,17 @@ class Program
|
||||
{
|
||||
private GLuint m_id;
|
||||
|
||||
this()
|
||||
this(Args...)(Args args)
|
||||
{
|
||||
m_id = glCreateProgram();
|
||||
if (m_id == 0u)
|
||||
{
|
||||
throw new Exception("Failed to allocate an OpenGL program");
|
||||
}
|
||||
static if (args.length != 0u)
|
||||
{
|
||||
build(args);
|
||||
}
|
||||
}
|
||||
|
||||
~this()
|
||||
@ -26,7 +30,7 @@ class Program
|
||||
glAttachShader(m_id, shader.id);
|
||||
}
|
||||
|
||||
void bind_attrib_location(uint index, string name)
|
||||
void bind_attrib_location(string name, uint index) const
|
||||
{
|
||||
glBindAttribLocation(m_id, index, name.toStringz());
|
||||
}
|
||||
@ -54,12 +58,12 @@ class Program
|
||||
}
|
||||
}
|
||||
|
||||
GLint get_uniform_location(string uniform_name)
|
||||
GLint get_uniform_location(string uniform_name) const
|
||||
{
|
||||
return glGetUniformLocation(m_id, uniform_name.toStringz());
|
||||
}
|
||||
|
||||
@property GLuint id()
|
||||
@property GLuint id() const
|
||||
{
|
||||
return m_id;
|
||||
}
|
||||
@ -68,4 +72,21 @@ class Program
|
||||
{
|
||||
glUseProgram(m_id);
|
||||
}
|
||||
|
||||
private void build(Args...)(Shader s, Args args) const
|
||||
{
|
||||
attach_shader(s);
|
||||
build(args);
|
||||
}
|
||||
|
||||
private void build(Args...)(string attrib_name, uint index, Args args) const
|
||||
{
|
||||
bind_attrib_location(attrib_name, index);
|
||||
build(args);
|
||||
}
|
||||
|
||||
private void build() const
|
||||
{
|
||||
link();
|
||||
}
|
||||
}
|
||||
|
@ -47,11 +47,7 @@ class Gui
|
||||
v_shader.set_source_from_file("share/jes/shaders/text.v.glsl");
|
||||
auto f_shader = new gltk.Shader(GL_FRAGMENT_SHADER);
|
||||
f_shader.set_source_from_file("share/jes/shaders/text.f.glsl");
|
||||
m_text_program = new gltk.Program();
|
||||
m_text_program.attach_shader(v_shader);
|
||||
m_text_program.attach_shader(f_shader);
|
||||
m_text_program.bind_attrib_location(0u, "coords");
|
||||
m_text_program.link();
|
||||
m_text_program = new gltk.Program(v_shader, f_shader, "coords", 0);
|
||||
m_viewport_size = m_text_program.get_uniform_location("viewport_size");
|
||||
m_texture = m_text_program.get_uniform_location("texture");
|
||||
m_color = m_text_program.get_uniform_location("color");
|
||||
|
Loading…
x
Reference in New Issue
Block a user