mirror of https://github.com/buggins/dlangui.git
VAO and VBO with GLObject
This commit is contained in:
parent
bfbdd462fd
commit
3f2b14f4e3
|
@ -314,13 +314,9 @@ class SolidFillProgram : GLProgram {
|
|||
return false;
|
||||
beforeExecute();
|
||||
|
||||
GLuint vao;
|
||||
glGenVertexArrays(1, &vao);
|
||||
glBindVertexArray(vao);
|
||||
VAO vao = new VAO();
|
||||
|
||||
GLuint vbo;
|
||||
glGenBuffers(1, &vbo);
|
||||
glBindBuffer(GL_ARRAY_BUFFER, vbo);
|
||||
VBO vbo = new VBO();
|
||||
glBufferData(
|
||||
GL_ARRAY_BUFFER,
|
||||
vertices.length * vertices[0].sizeof + colors.length * colors[0].sizeof,
|
||||
|
@ -336,31 +332,22 @@ class SolidFillProgram : GLProgram {
|
|||
vertices.length * vertices[0].sizeof,
|
||||
colors.length * colors[0].sizeof, colors.ptr);
|
||||
|
||||
glEnableVertexAttribArray(vertexLocation);
|
||||
checkError("glEnableVertexAttribArray");
|
||||
glVertexAttribPointer(vertexLocation, 3, GL_FLOAT, GL_FALSE, 0, cast(void*) 0);
|
||||
checkError("glVertexAttribPointer");
|
||||
glVertexAttribPointer(colAttrLocation, 4, GL_FLOAT, GL_FALSE, 0, cast(void*) (vertices.length * vertices[0].sizeof));
|
||||
|
||||
glEnableVertexAttribArray(vertexLocation);
|
||||
glEnableVertexAttribArray(colAttrLocation);
|
||||
checkError("glEnableVertexAttribArray");
|
||||
glVertexAttribPointer(colAttrLocation, 4, GL_FLOAT, GL_FALSE, 0, cast(void*) (float.sizeof*3*6));
|
||||
checkError("glVertexAttribPointer");
|
||||
|
||||
glDrawArrays(GL_TRIANGLES, 0, 6);
|
||||
glDrawArrays(GL_TRIANGLES, 0, cast(int)vertices.length/3);
|
||||
checkError("glDrawArrays");
|
||||
|
||||
glDisableVertexAttribArray(vertexLocation);
|
||||
checkError("glDisableVertexAttribArray");
|
||||
glDisableVertexAttribArray(colAttrLocation);
|
||||
checkError("glDisableVertexAttribArray");
|
||||
|
||||
afterExecute();
|
||||
|
||||
glBindBuffer(GL_ARRAY_BUFFER, 0);
|
||||
glDeleteBuffers(1, &vbo);
|
||||
|
||||
glBindVertexArray(0);
|
||||
glDeleteVertexArrays(1, &vao);
|
||||
destroy(vbo);
|
||||
destroy(vao);
|
||||
return true;
|
||||
}
|
||||
}
|
||||
|
@ -371,13 +358,9 @@ class LineProgram : SolidFillProgram {
|
|||
return false;
|
||||
beforeExecute();
|
||||
|
||||
GLuint vao;
|
||||
glGenVertexArrays(1, &vao);
|
||||
glBindVertexArray(vao);
|
||||
VAO vao = new VAO();
|
||||
|
||||
GLuint vbo;
|
||||
glGenBuffers(1, &vbo);
|
||||
glBindBuffer(GL_ARRAY_BUFFER, vbo);
|
||||
VBO vbo = new VBO();
|
||||
glBufferData(
|
||||
GL_ARRAY_BUFFER,
|
||||
vertices.length * vertices[0].sizeof + colors.length * colors[0].sizeof,
|
||||
|
@ -394,31 +377,22 @@ class LineProgram : SolidFillProgram {
|
|||
colors.length * colors[0].sizeof,
|
||||
colors.ptr);
|
||||
|
||||
glEnableVertexAttribArray(vertexLocation);
|
||||
checkError("glEnableVertexAttribArray");
|
||||
glVertexAttribPointer(vertexLocation, 3, GL_FLOAT, GL_FALSE, 0, cast(void*) 0);
|
||||
checkError("glVertexAttribPointer");
|
||||
glVertexAttribPointer(colAttrLocation, 4, GL_FLOAT, GL_FALSE, 0, cast(void*) (vertices.length * vertices[0].sizeof));
|
||||
|
||||
glEnableVertexAttribArray(vertexLocation);
|
||||
glEnableVertexAttribArray(colAttrLocation);
|
||||
checkError("glEnableVertexAttribArray");
|
||||
glVertexAttribPointer(colAttrLocation, 4, GL_FLOAT, GL_FALSE, 0, cast(void*) (float.sizeof*3*2));
|
||||
checkError("glVertexAttribPointer");
|
||||
|
||||
glDrawArrays(GL_LINES, 0, 2);
|
||||
glDrawArrays(GL_LINES, 0, cast(int)vertices.length/3);
|
||||
checkError("glDrawArrays");
|
||||
|
||||
glDisableVertexAttribArray(vertexLocation);
|
||||
checkError("glDisableVertexAttribArray");
|
||||
glDisableVertexAttribArray(colAttrLocation);
|
||||
checkError("glDisableVertexAttribArray");
|
||||
|
||||
afterExecute();
|
||||
|
||||
glBindBuffer(GL_ARRAY_BUFFER, 0);
|
||||
glDeleteBuffers(1, &vbo);
|
||||
|
||||
glBindVertexArray(0);
|
||||
glDeleteVertexArrays(1, &vao);
|
||||
destroy(vbo);
|
||||
destroy(vao);
|
||||
return true;
|
||||
}
|
||||
}
|
||||
|
@ -474,13 +448,9 @@ class TextureProgram : SolidFillProgram {
|
|||
glTexParameteri(GL_TEXTURE_2D, GL_TEXTURE_MIN_FILTER, linear ? GL_LINEAR : GL_NEAREST);
|
||||
checkError("drawColorAndTextureRect - glTexParameteri");
|
||||
|
||||
GLuint vao;
|
||||
glGenVertexArrays(1, &vao);
|
||||
glBindVertexArray(vao);
|
||||
VAO vao = new VAO();
|
||||
|
||||
GLuint vbo;
|
||||
glGenBuffers(1, &vbo);
|
||||
glBindBuffer(GL_ARRAY_BUFFER, vbo);
|
||||
VBO vbo = new VBO();
|
||||
glBufferData(
|
||||
GL_ARRAY_BUFFER,
|
||||
vertices.length * vertices[0].sizeof +
|
||||
|
@ -504,15 +474,15 @@ class TextureProgram : SolidFillProgram {
|
|||
texcoords.length * texcoords[0].sizeof,
|
||||
texcoords.ptr);
|
||||
|
||||
glEnableVertexAttribArray(vertexLocation);
|
||||
glEnableVertexAttribArray(colAttrLocation);
|
||||
glEnableVertexAttribArray(texCoordLocation);
|
||||
|
||||
glVertexAttribPointer(vertexLocation, 3, GL_FLOAT, GL_FALSE, 0, cast(void*) 0);
|
||||
glVertexAttribPointer(colAttrLocation, 4, GL_FLOAT, GL_FALSE, 0, cast(void*) (vertices.length * vertices[0].sizeof));
|
||||
glVertexAttribPointer(texCoordLocation, 2, GL_FLOAT, GL_FALSE, 0, cast(void*) (vertices.length * vertices[0].sizeof + colors.length * colors[0].sizeof));
|
||||
|
||||
glDrawArrays(GL_TRIANGLES, 0, 6);
|
||||
glEnableVertexAttribArray(vertexLocation);
|
||||
glEnableVertexAttribArray(colAttrLocation);
|
||||
glEnableVertexAttribArray(texCoordLocation);
|
||||
|
||||
glDrawArrays(GL_TRIANGLES, 0, cast(int)vertices.length/3);
|
||||
checkError("glDrawArrays");
|
||||
|
||||
glDisableVertexAttribArray(vertexLocation);
|
||||
|
@ -521,11 +491,8 @@ class TextureProgram : SolidFillProgram {
|
|||
|
||||
afterExecute();
|
||||
|
||||
glBindBuffer(GL_ARRAY_BUFFER, 0);
|
||||
glDeleteBuffers(1, &vbo);
|
||||
|
||||
glBindVertexArray(0);
|
||||
glDeleteVertexArrays(1, &vao);
|
||||
destroy(vbo);
|
||||
destroy(vao);
|
||||
|
||||
glBindTexture(GL_TEXTURE_2D, 0);
|
||||
checkError("glBindTexture");
|
||||
|
@ -604,13 +571,9 @@ class FontProgram : SolidFillProgram {
|
|||
glTexParameteri(GL_TEXTURE_2D, GL_TEXTURE_MIN_FILTER, linear ? GL_LINEAR : GL_NEAREST);
|
||||
checkError("drawColorAndTextureRect - glTexParameteri");
|
||||
|
||||
GLuint vao;
|
||||
glGenVertexArrays(1, &vao);
|
||||
glBindVertexArray(vao);
|
||||
VAO vao = new VAO();
|
||||
|
||||
GLuint vbo;
|
||||
glGenBuffers(1, &vbo);
|
||||
glBindBuffer(GL_ARRAY_BUFFER, vbo);
|
||||
VBO vbo = new VBO();
|
||||
glBufferData(
|
||||
GL_ARRAY_BUFFER,
|
||||
vertices.length * vertices[0].sizeof +
|
||||
|
@ -634,15 +597,15 @@ class FontProgram : SolidFillProgram {
|
|||
texcoords.length * texcoords[0].sizeof,
|
||||
texcoords.ptr);
|
||||
|
||||
glEnableVertexAttribArray(vertexLocation);
|
||||
glEnableVertexAttribArray(colAttrLocation);
|
||||
glEnableVertexAttribArray(texCoordLocation);
|
||||
|
||||
glVertexAttribPointer(vertexLocation, 3, GL_FLOAT, GL_FALSE, 0, cast(void*) 0);
|
||||
glVertexAttribPointer(colAttrLocation, 4, GL_FLOAT, GL_FALSE, 0, cast(void*) (vertices.length * vertices[0].sizeof));
|
||||
glVertexAttribPointer(texCoordLocation, 2, GL_FLOAT, GL_FALSE, 0, cast(void*) (vertices.length * vertices[0].sizeof + colors.length * colors[0].sizeof));
|
||||
|
||||
glDrawArrays(GL_TRIANGLES, 0, 6);
|
||||
glEnableVertexAttribArray(vertexLocation);
|
||||
glEnableVertexAttribArray(colAttrLocation);
|
||||
glEnableVertexAttribArray(texCoordLocation);
|
||||
|
||||
glDrawArrays(GL_TRIANGLES, 0, cast(int)vertices.length/3);
|
||||
checkError("glDrawArrays");
|
||||
|
||||
glDisableVertexAttribArray(vertexLocation);
|
||||
|
@ -651,11 +614,8 @@ class FontProgram : SolidFillProgram {
|
|||
|
||||
afterExecute();
|
||||
|
||||
glBindBuffer(GL_ARRAY_BUFFER, 0);
|
||||
glDeleteBuffers(1, &vbo);
|
||||
|
||||
glBindVertexArray(0);
|
||||
glDeleteVertexArrays(1, &vao);
|
||||
destroy(vbo);
|
||||
destroy(vao);
|
||||
|
||||
glBindTexture(GL_TEXTURE_2D, 0);
|
||||
checkError("glBindTexture");
|
||||
|
|
Loading…
Reference in New Issue