Merge pull request #365 from g4z3r/gl

GL optimizations
This commit is contained in:
Vadim Lopatin 2017-06-06 09:16:14 +03:00 committed by GitHub
commit 950c0c26cb
2 changed files with 6 additions and 32 deletions

View File

@ -572,7 +572,7 @@ private class GLImageCache : GLCache
dstrc.bottom -= clip.bottom;
}
if (!dstrc.empty)
glSupport.queue.addTexturedRect(_texture, _tdx, _tdy, color, color, color, color, srcrc, dstrc, srcrc.width() != dstrc.width() || srcrc.height() != dstrc.height());
glSupport.queue.addTexturedRect(_texture, _tdx, _tdy, color, color, color, color, srcrc, dstrc, true);
}
}
}

View File

@ -515,14 +515,14 @@ class SolidFillProgram : GLProgram {
glEnableVertexAttribArray(colAttrLocation);
}
bool drawBatch(int length, int start) {
bool drawBatch(int length, int start, bool areLines = false) {
if(!check())
return false;
beforeExecute();
vao.bind();
checkgl!glDrawElements(GL_TRIANGLES, cast(int)length, GL_UNSIGNED_INT, cast(void*)(start * 4));
checkgl!glDrawElements(areLines ? GL_LINES : GL_TRIANGLES, cast(int)length, GL_UNSIGNED_INT, cast(void*)(start * 4));
return true;
}
@ -533,20 +533,6 @@ class SolidFillProgram : GLProgram {
}
}
class LineProgram : SolidFillProgram {
override bool drawBatch(int length, int start) {
if(!check())
return false;
beforeExecute();
vao.bind();
checkgl!glDrawElements(GL_LINES, cast(int)length, GL_UNSIGNED_INT, cast(void*)(start * 4));
return true;
}
}
class TextureProgram : SolidFillProgram {
@property override string vertexSource() {
return q{
@ -772,11 +758,10 @@ final class GLSupport {
OpenGLQueue _queue;
SolidFillProgram _solidFillProgram;
LineProgram _lineProgram;
TextureProgram _textureProgram;
@property bool valid() {
return _legacyMode || _textureProgram && _solidFillProgram && _lineProgram;
return _legacyMode || _textureProgram && _solidFillProgram;
}
bool initShaders() {
@ -787,12 +772,6 @@ final class GLSupport {
if (!_solidFillProgram.compile())
return false;
}
if (_lineProgram is null) {
Log.v("Compiling line program");
_lineProgram = new LineProgram();
if (!_lineProgram.compile())
return false;
}
if (_textureProgram is null) {
Log.v("Compiling texture program");
_textureProgram = new TextureProgram();
@ -809,10 +788,6 @@ final class GLSupport {
destroy(_solidFillProgram);
_solidFillProgram = null;
}
if (_lineProgram !is null) {
destroy(_lineProgram);
_lineProgram = null;
}
if (_textureProgram !is null) {
destroy(_textureProgram);
_textureProgram = null;
@ -843,7 +818,6 @@ final class GLSupport {
_solidFillProgram.createVAO(vertices.length);
vbo.bind();
ebo.bind();
_lineProgram.vao = _solidFillProgram.vao;
_textureProgram.createVAO(vertices.length, colors.length);
vbo.bind();
ebo.bind();
@ -883,8 +857,8 @@ final class GLSupport {
glDisable(GL_BLEND);
}
} else {
if (_lineProgram !is null) {
_lineProgram.drawBatch(length, start);
if (_solidFillProgram !is null) {
_solidFillProgram.drawBatch(length, start, true);
} else
Log.e("No program");
}