mirror of https://github.com/buggins/dlangui.git
decreased a number of vao creations
This commit is contained in:
parent
936838bf2d
commit
4d16c29506
|
@ -71,6 +71,7 @@ class GLDrawBuf : DrawBuf, GLConfigCallback {
|
||||||
_scene.reset();
|
_scene.reset();
|
||||||
}
|
}
|
||||||
_scene = new Scene(this);
|
_scene = new Scene(this);
|
||||||
|
glSupport.prepareShaders();
|
||||||
}
|
}
|
||||||
|
|
||||||
/// reserved for hardware-accelerated drawing - ends drawing batch
|
/// reserved for hardware-accelerated drawing - ends drawing batch
|
||||||
|
|
|
@ -289,6 +289,27 @@ class SolidFillProgram : GLProgram {
|
||||||
return matrixLocation >= 0 && vertexLocation >= 0 && colAttrLocation >= 0;
|
return matrixLocation >= 0 && vertexLocation >= 0 && colAttrLocation >= 0;
|
||||||
}
|
}
|
||||||
|
|
||||||
|
VAO vao;
|
||||||
|
VBO vbo;
|
||||||
|
bool needToCreateVAO = true;
|
||||||
|
void createVAO(float[] vertices, float[] colors) {
|
||||||
|
if(vao)
|
||||||
|
destroy(vao);
|
||||||
|
vao = new VAO;
|
||||||
|
|
||||||
|
if(vbo)
|
||||||
|
destroy(vbo);
|
||||||
|
vbo = new VBO;
|
||||||
|
|
||||||
|
glVertexAttribPointer(vertexLocation, 3, GL_FLOAT, GL_FALSE, 0, cast(void*) 0);
|
||||||
|
glVertexAttribPointer(colAttrLocation, 4, GL_FLOAT, GL_FALSE, 0, cast(void*) (vertices.length * float.sizeof));
|
||||||
|
|
||||||
|
glEnableVertexAttribArray(vertexLocation);
|
||||||
|
glEnableVertexAttribArray(colAttrLocation);
|
||||||
|
|
||||||
|
needToCreateVAO = false;
|
||||||
|
}
|
||||||
|
|
||||||
void beforeExecute() {
|
void beforeExecute() {
|
||||||
glEnable(GL_BLEND);
|
glEnable(GL_BLEND);
|
||||||
checkgl!glDisable(GL_CULL_FACE);
|
checkgl!glDisable(GL_CULL_FACE);
|
||||||
|
@ -302,21 +323,15 @@ class SolidFillProgram : GLProgram {
|
||||||
return false;
|
return false;
|
||||||
beforeExecute();
|
beforeExecute();
|
||||||
|
|
||||||
VAO vao = new VAO();
|
if(needToCreateVAO)
|
||||||
|
createVAO(vertices, colors);
|
||||||
|
|
||||||
VBO vbo = new VBO();
|
vbo.bind();
|
||||||
vbo.fill([vertices, colors]);
|
vbo.fill([vertices, colors]);
|
||||||
|
|
||||||
glVertexAttribPointer(vertexLocation, 3, GL_FLOAT, GL_FALSE, 0, cast(void*) 0);
|
vao.bind();
|
||||||
glVertexAttribPointer(colAttrLocation, 4, GL_FLOAT, GL_FALSE, 0, cast(void*) (vertices.length * vertices[0].sizeof));
|
checkgl!glDrawArrays(GL_TRIANGLE_STRIP, 0, 4);
|
||||||
|
vao.unbind();
|
||||||
glEnableVertexAttribArray(vertexLocation);
|
|
||||||
glEnableVertexAttribArray(colAttrLocation);
|
|
||||||
|
|
||||||
checkgl!glDrawArrays(GL_TRIANGLE_STRIP, 0, cast(int)vertices.length/3);
|
|
||||||
|
|
||||||
destroy(vbo);
|
|
||||||
destroy(vao);
|
|
||||||
return true;
|
return true;
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
@ -327,21 +342,15 @@ class LineProgram : SolidFillProgram {
|
||||||
return false;
|
return false;
|
||||||
beforeExecute();
|
beforeExecute();
|
||||||
|
|
||||||
VAO vao = new VAO();
|
if(needToCreateVAO)
|
||||||
|
createVAO(vertices, colors);
|
||||||
|
|
||||||
VBO vbo = new VBO();
|
vbo.bind();
|
||||||
vbo.fill([vertices, colors]);
|
vbo.fill([vertices, colors]);
|
||||||
|
|
||||||
glVertexAttribPointer(vertexLocation, 3, GL_FLOAT, GL_FALSE, 0, cast(void*) 0);
|
vao.bind();
|
||||||
glVertexAttribPointer(colAttrLocation, 4, GL_FLOAT, GL_FALSE, 0, cast(void*) (vertices.length * vertices[0].sizeof));
|
checkgl!glDrawArrays(GL_LINES, 0, 2);
|
||||||
|
vao.unbind();
|
||||||
glEnableVertexAttribArray(vertexLocation);
|
|
||||||
glEnableVertexAttribArray(colAttrLocation);
|
|
||||||
|
|
||||||
checkgl!glDrawArrays(GL_LINES, 0, cast(int)vertices.length/3);
|
|
||||||
|
|
||||||
destroy(vbo);
|
|
||||||
destroy(vao);
|
|
||||||
return true;
|
return true;
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
@ -384,6 +393,26 @@ class TextureProgram : SolidFillProgram {
|
||||||
return res && texCoordLocation >= 0;
|
return res && texCoordLocation >= 0;
|
||||||
}
|
}
|
||||||
|
|
||||||
|
void createVAO(float[] vertices, float[] colors, float[] texcoords) {
|
||||||
|
if(vao)
|
||||||
|
destroy(vao);
|
||||||
|
vao = new VAO;
|
||||||
|
|
||||||
|
if(vbo)
|
||||||
|
destroy(vbo);
|
||||||
|
vbo = new VBO;
|
||||||
|
|
||||||
|
glVertexAttribPointer(vertexLocation, 3, GL_FLOAT, GL_FALSE, 0, cast(void*) 0);
|
||||||
|
glVertexAttribPointer(colAttrLocation, 4, GL_FLOAT, GL_FALSE, 0, cast(void*) (vertices.length * float.sizeof));
|
||||||
|
glVertexAttribPointer(texCoordLocation, 2, GL_FLOAT, GL_FALSE, 0, cast(void*) ((vertices.length + colors.length) * float.sizeof));
|
||||||
|
|
||||||
|
glEnableVertexAttribArray(vertexLocation);
|
||||||
|
glEnableVertexAttribArray(colAttrLocation);
|
||||||
|
glEnableVertexAttribArray(texCoordLocation);
|
||||||
|
|
||||||
|
needToCreateVAO = false;
|
||||||
|
}
|
||||||
|
|
||||||
bool execute(float[] vertices, float[] colors, float[] texcoords, Tex2D texture, bool linear) {
|
bool execute(float[] vertices, float[] colors, float[] texcoords, Tex2D texture, bool linear) {
|
||||||
if(!check())
|
if(!check())
|
||||||
return false;
|
return false;
|
||||||
|
@ -392,23 +421,15 @@ class TextureProgram : SolidFillProgram {
|
||||||
texture.setup();
|
texture.setup();
|
||||||
texture.setSamplerParams(linear);
|
texture.setSamplerParams(linear);
|
||||||
|
|
||||||
VAO vao = new VAO();
|
if(needToCreateVAO)
|
||||||
|
createVAO(vertices, colors, texcoords);
|
||||||
|
|
||||||
VBO vbo = new VBO();
|
vbo.bind();
|
||||||
vbo.fill([vertices, colors, texcoords]);
|
vbo.fill([vertices, colors, texcoords]);
|
||||||
|
|
||||||
glVertexAttribPointer(vertexLocation, 3, GL_FLOAT, GL_FALSE, 0, cast(void*) 0);
|
vao.bind();
|
||||||
glVertexAttribPointer(colAttrLocation, 4, GL_FLOAT, GL_FALSE, 0, cast(void*) (vertices.length * vertices[0].sizeof));
|
checkgl!glDrawArrays(GL_TRIANGLE_STRIP, 0, 4);
|
||||||
glVertexAttribPointer(texCoordLocation, 2, GL_FLOAT, GL_FALSE, 0, cast(void*) (vertices.length * vertices[0].sizeof + colors.length * colors[0].sizeof));
|
vao.unbind();
|
||||||
|
|
||||||
glEnableVertexAttribArray(vertexLocation);
|
|
||||||
glEnableVertexAttribArray(colAttrLocation);
|
|
||||||
glEnableVertexAttribArray(texCoordLocation);
|
|
||||||
|
|
||||||
checkgl!glDrawArrays(GL_TRIANGLE_STRIP, 0, cast(int)vertices.length/3);
|
|
||||||
|
|
||||||
destroy(vbo);
|
|
||||||
destroy(vao);
|
|
||||||
|
|
||||||
texture.unbind();
|
texture.unbind();
|
||||||
return true;
|
return true;
|
||||||
|
@ -578,6 +599,12 @@ class GLSupport {
|
||||||
return true;
|
return true;
|
||||||
}
|
}
|
||||||
|
|
||||||
|
void prepareShaders() {
|
||||||
|
_solidFillProgram.needToCreateVAO = true;
|
||||||
|
_lineProgram.needToCreateVAO = true;
|
||||||
|
_textureProgram.needToCreateVAO = true;
|
||||||
|
}
|
||||||
|
|
||||||
void setRotation(int x, int y, int rotationAngle) {
|
void setRotation(int x, int y, int rotationAngle) {
|
||||||
/*
|
/*
|
||||||
this->rotationAngle = rotationAngle;
|
this->rotationAngle = rotationAngle;
|
||||||
|
|
Loading…
Reference in New Issue