gltk.Buffer constructor takes target parameter.

This commit is contained in:
Josh Holtrop 2020-12-10 20:28:49 -05:00
parent 64c3285fbc
commit e51953445b
2 changed files with 8 additions and 9 deletions

View File

@ -7,7 +7,7 @@ class Buffer
private GLenum m_target; private GLenum m_target;
this() this(GLenum target)
{ {
m_id = 0u; m_id = 0u;
glGenBuffers(1, &m_id); glGenBuffers(1, &m_id);
@ -15,6 +15,7 @@ class Buffer
{ {
throw new Exception("Failed to allocate an OpenGL buffer"); throw new Exception("Failed to allocate an OpenGL buffer");
} }
m_target = target;
} }
~this() ~this()
@ -32,17 +33,15 @@ class Buffer
return m_id; return m_id;
} }
void set_buffer_data(GLenum target, GLenum usage, const void * ptr, size_t size) void set_buffer_data(GLenum usage, const void * ptr, size_t size)
{ {
m_target = target;
bind(); bind();
glBufferData(target, size, ptr, usage); glBufferData(m_target, size, ptr, usage);
} }
void set_buffer_data(T)(GLenum target, GLenum usage, T[] arr) void set_buffer_data(T)(GLenum usage, T[] arr)
{ {
m_target = target;
bind(); bind();
glBufferData(target, arr.length * arr[0].sizeof, arr.ptr, usage); glBufferData(m_target, arr.length * arr[0].sizeof, arr.ptr, usage);
} }
} }

View File

@ -67,14 +67,14 @@ class Font
int top = cglyph.top; int top = cglyph.top;
float s_max = cglyph.width / cast(float)rounded_width; float s_max = cglyph.width / cast(float)rounded_width;
float t_max = cglyph.height / cast(float)rounded_height; float t_max = cglyph.height / cast(float)rounded_height;
m_buffer = new gltk.Buffer(); m_buffer = new gltk.Buffer(GL_ARRAY_BUFFER);
GLfloat[] data = [ GLfloat[] data = [
cast(GLfloat)left, cast(GLfloat)(top - cglyph.height), 0.0, 0.0, cast(GLfloat)left, cast(GLfloat)(top - cglyph.height), 0.0, 0.0,
cast(GLfloat)(left + cglyph.width), cast(GLfloat)(top - cglyph.height), s_max, 0.0, cast(GLfloat)(left + cglyph.width), cast(GLfloat)(top - cglyph.height), s_max, 0.0,
cast(GLfloat)left, cast(GLfloat)top, 0.0, t_max, cast(GLfloat)left, cast(GLfloat)top, 0.0, t_max,
cast(GLfloat)(left + cglyph.width), cast(GLfloat)top, s_max, t_max, cast(GLfloat)(left + cglyph.width), cast(GLfloat)top, s_max, t_max,
]; ];
m_buffer.set_buffer_data(GL_ARRAY_BUFFER, GL_STATIC_DRAW, data); m_buffer.set_buffer_data(GL_STATIC_DRAW, data);
glEnableVertexAttribArray(0); glEnableVertexAttribArray(0);
glVertexAttribPointer(0, 4, GL_FLOAT, GL_FALSE, 0, null); glVertexAttribPointer(0, 4, GL_FLOAT, GL_FALSE, 0, null);