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;
|
return false;
|
||||||
beforeExecute();
|
beforeExecute();
|
||||||
|
|
||||||
GLuint vao;
|
VAO vao = new VAO();
|
||||||
glGenVertexArrays(1, &vao);
|
|
||||||
glBindVertexArray(vao);
|
|
||||||
|
|
||||||
GLuint vbo;
|
VBO vbo = new VBO();
|
||||||
glGenBuffers(1, &vbo);
|
|
||||||
glBindBuffer(GL_ARRAY_BUFFER, vbo);
|
|
||||||
glBufferData(
|
glBufferData(
|
||||||
GL_ARRAY_BUFFER,
|
GL_ARRAY_BUFFER,
|
||||||
vertices.length * vertices[0].sizeof + colors.length * colors[0].sizeof,
|
vertices.length * vertices[0].sizeof + colors.length * colors[0].sizeof,
|
||||||
|
@ -336,31 +332,22 @@ class SolidFillProgram : GLProgram {
|
||||||
vertices.length * vertices[0].sizeof,
|
vertices.length * vertices[0].sizeof,
|
||||||
colors.length * colors[0].sizeof, colors.ptr);
|
colors.length * colors[0].sizeof, colors.ptr);
|
||||||
|
|
||||||
glEnableVertexAttribArray(vertexLocation);
|
|
||||||
checkError("glEnableVertexAttribArray");
|
|
||||||
glVertexAttribPointer(vertexLocation, 3, GL_FLOAT, GL_FALSE, 0, cast(void*) 0);
|
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);
|
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");
|
checkError("glDrawArrays");
|
||||||
|
|
||||||
glDisableVertexAttribArray(vertexLocation);
|
glDisableVertexAttribArray(vertexLocation);
|
||||||
checkError("glDisableVertexAttribArray");
|
|
||||||
glDisableVertexAttribArray(colAttrLocation);
|
glDisableVertexAttribArray(colAttrLocation);
|
||||||
checkError("glDisableVertexAttribArray");
|
|
||||||
|
|
||||||
afterExecute();
|
afterExecute();
|
||||||
|
|
||||||
glBindBuffer(GL_ARRAY_BUFFER, 0);
|
destroy(vbo);
|
||||||
glDeleteBuffers(1, &vbo);
|
destroy(vao);
|
||||||
|
|
||||||
glBindVertexArray(0);
|
|
||||||
glDeleteVertexArrays(1, &vao);
|
|
||||||
return true;
|
return true;
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
@ -371,13 +358,9 @@ class LineProgram : SolidFillProgram {
|
||||||
return false;
|
return false;
|
||||||
beforeExecute();
|
beforeExecute();
|
||||||
|
|
||||||
GLuint vao;
|
VAO vao = new VAO();
|
||||||
glGenVertexArrays(1, &vao);
|
|
||||||
glBindVertexArray(vao);
|
|
||||||
|
|
||||||
GLuint vbo;
|
VBO vbo = new VBO();
|
||||||
glGenBuffers(1, &vbo);
|
|
||||||
glBindBuffer(GL_ARRAY_BUFFER, vbo);
|
|
||||||
glBufferData(
|
glBufferData(
|
||||||
GL_ARRAY_BUFFER,
|
GL_ARRAY_BUFFER,
|
||||||
vertices.length * vertices[0].sizeof + colors.length * colors[0].sizeof,
|
vertices.length * vertices[0].sizeof + colors.length * colors[0].sizeof,
|
||||||
|
@ -394,31 +377,22 @@ class LineProgram : SolidFillProgram {
|
||||||
colors.length * colors[0].sizeof,
|
colors.length * colors[0].sizeof,
|
||||||
colors.ptr);
|
colors.ptr);
|
||||||
|
|
||||||
glEnableVertexAttribArray(vertexLocation);
|
|
||||||
checkError("glEnableVertexAttribArray");
|
|
||||||
glVertexAttribPointer(vertexLocation, 3, GL_FLOAT, GL_FALSE, 0, cast(void*) 0);
|
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);
|
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");
|
checkError("glDrawArrays");
|
||||||
|
|
||||||
glDisableVertexAttribArray(vertexLocation);
|
glDisableVertexAttribArray(vertexLocation);
|
||||||
checkError("glDisableVertexAttribArray");
|
|
||||||
glDisableVertexAttribArray(colAttrLocation);
|
glDisableVertexAttribArray(colAttrLocation);
|
||||||
checkError("glDisableVertexAttribArray");
|
|
||||||
|
|
||||||
afterExecute();
|
afterExecute();
|
||||||
|
|
||||||
glBindBuffer(GL_ARRAY_BUFFER, 0);
|
destroy(vbo);
|
||||||
glDeleteBuffers(1, &vbo);
|
destroy(vao);
|
||||||
|
|
||||||
glBindVertexArray(0);
|
|
||||||
glDeleteVertexArrays(1, &vao);
|
|
||||||
return true;
|
return true;
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
@ -474,13 +448,9 @@ class TextureProgram : SolidFillProgram {
|
||||||
glTexParameteri(GL_TEXTURE_2D, GL_TEXTURE_MIN_FILTER, linear ? GL_LINEAR : GL_NEAREST);
|
glTexParameteri(GL_TEXTURE_2D, GL_TEXTURE_MIN_FILTER, linear ? GL_LINEAR : GL_NEAREST);
|
||||||
checkError("drawColorAndTextureRect - glTexParameteri");
|
checkError("drawColorAndTextureRect - glTexParameteri");
|
||||||
|
|
||||||
GLuint vao;
|
VAO vao = new VAO();
|
||||||
glGenVertexArrays(1, &vao);
|
|
||||||
glBindVertexArray(vao);
|
|
||||||
|
|
||||||
GLuint vbo;
|
VBO vbo = new VBO();
|
||||||
glGenBuffers(1, &vbo);
|
|
||||||
glBindBuffer(GL_ARRAY_BUFFER, vbo);
|
|
||||||
glBufferData(
|
glBufferData(
|
||||||
GL_ARRAY_BUFFER,
|
GL_ARRAY_BUFFER,
|
||||||
vertices.length * vertices[0].sizeof +
|
vertices.length * vertices[0].sizeof +
|
||||||
|
@ -504,15 +474,15 @@ class TextureProgram : SolidFillProgram {
|
||||||
texcoords.length * texcoords[0].sizeof,
|
texcoords.length * texcoords[0].sizeof,
|
||||||
texcoords.ptr);
|
texcoords.ptr);
|
||||||
|
|
||||||
glEnableVertexAttribArray(vertexLocation);
|
|
||||||
glEnableVertexAttribArray(colAttrLocation);
|
|
||||||
glEnableVertexAttribArray(texCoordLocation);
|
|
||||||
|
|
||||||
glVertexAttribPointer(vertexLocation, 3, GL_FLOAT, GL_FALSE, 0, cast(void*) 0);
|
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(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));
|
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");
|
checkError("glDrawArrays");
|
||||||
|
|
||||||
glDisableVertexAttribArray(vertexLocation);
|
glDisableVertexAttribArray(vertexLocation);
|
||||||
|
@ -521,11 +491,8 @@ class TextureProgram : SolidFillProgram {
|
||||||
|
|
||||||
afterExecute();
|
afterExecute();
|
||||||
|
|
||||||
glBindBuffer(GL_ARRAY_BUFFER, 0);
|
destroy(vbo);
|
||||||
glDeleteBuffers(1, &vbo);
|
destroy(vao);
|
||||||
|
|
||||||
glBindVertexArray(0);
|
|
||||||
glDeleteVertexArrays(1, &vao);
|
|
||||||
|
|
||||||
glBindTexture(GL_TEXTURE_2D, 0);
|
glBindTexture(GL_TEXTURE_2D, 0);
|
||||||
checkError("glBindTexture");
|
checkError("glBindTexture");
|
||||||
|
@ -604,13 +571,9 @@ class FontProgram : SolidFillProgram {
|
||||||
glTexParameteri(GL_TEXTURE_2D, GL_TEXTURE_MIN_FILTER, linear ? GL_LINEAR : GL_NEAREST);
|
glTexParameteri(GL_TEXTURE_2D, GL_TEXTURE_MIN_FILTER, linear ? GL_LINEAR : GL_NEAREST);
|
||||||
checkError("drawColorAndTextureRect - glTexParameteri");
|
checkError("drawColorAndTextureRect - glTexParameteri");
|
||||||
|
|
||||||
GLuint vao;
|
VAO vao = new VAO();
|
||||||
glGenVertexArrays(1, &vao);
|
|
||||||
glBindVertexArray(vao);
|
|
||||||
|
|
||||||
GLuint vbo;
|
VBO vbo = new VBO();
|
||||||
glGenBuffers(1, &vbo);
|
|
||||||
glBindBuffer(GL_ARRAY_BUFFER, vbo);
|
|
||||||
glBufferData(
|
glBufferData(
|
||||||
GL_ARRAY_BUFFER,
|
GL_ARRAY_BUFFER,
|
||||||
vertices.length * vertices[0].sizeof +
|
vertices.length * vertices[0].sizeof +
|
||||||
|
@ -634,15 +597,15 @@ class FontProgram : SolidFillProgram {
|
||||||
texcoords.length * texcoords[0].sizeof,
|
texcoords.length * texcoords[0].sizeof,
|
||||||
texcoords.ptr);
|
texcoords.ptr);
|
||||||
|
|
||||||
glEnableVertexAttribArray(vertexLocation);
|
|
||||||
glEnableVertexAttribArray(colAttrLocation);
|
|
||||||
glEnableVertexAttribArray(texCoordLocation);
|
|
||||||
|
|
||||||
glVertexAttribPointer(vertexLocation, 3, GL_FLOAT, GL_FALSE, 0, cast(void*) 0);
|
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(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));
|
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");
|
checkError("glDrawArrays");
|
||||||
|
|
||||||
glDisableVertexAttribArray(vertexLocation);
|
glDisableVertexAttribArray(vertexLocation);
|
||||||
|
@ -651,11 +614,8 @@ class FontProgram : SolidFillProgram {
|
||||||
|
|
||||||
afterExecute();
|
afterExecute();
|
||||||
|
|
||||||
glBindBuffer(GL_ARRAY_BUFFER, 0);
|
destroy(vbo);
|
||||||
glDeleteBuffers(1, &vbo);
|
destroy(vao);
|
||||||
|
|
||||||
glBindVertexArray(0);
|
|
||||||
glDeleteVertexArrays(1, &vao);
|
|
||||||
|
|
||||||
glBindTexture(GL_TEXTURE_2D, 0);
|
glBindTexture(GL_TEXTURE_2D, 0);
|
||||||
checkError("glBindTexture");
|
checkError("glBindTexture");
|
||||||
|
|
Loading…
Reference in New Issue