summaryrefslogtreecommitdiffstats
path: root/src/gui/rhi/qrhigles2.cpp
diff options
context:
space:
mode:
Diffstat (limited to 'src/gui/rhi/qrhigles2.cpp')
-rw-r--r--src/gui/rhi/qrhigles2.cpp32
1 files changed, 26 insertions, 6 deletions
diff --git a/src/gui/rhi/qrhigles2.cpp b/src/gui/rhi/qrhigles2.cpp
index b57558889a..4c21804596 100644
--- a/src/gui/rhi/qrhigles2.cpp
+++ b/src/gui/rhi/qrhigles2.cpp
@@ -2155,6 +2155,12 @@ void QRhiGles2::executeCommandBuffer(QRhiCommandBuffer *cb)
quint32 indexOffset = 0;
GLuint currentArrayBuffer = 0;
GLuint currentElementArrayBuffer = 0;
+ struct {
+ QRhiGraphicsPipeline *ps = nullptr;
+ GLuint buffer;
+ quint32 offset;
+ int binding;
+ } lastBindVertexBuffer;
static const int TRACKED_ATTRIB_COUNT = 16;
bool enabledAttribArrays[TRACKED_ATTRIB_COUNT];
memset(enabledAttribArrays, 0, sizeof(enabledAttribArrays));
@@ -2203,6 +2209,26 @@ void QRhiGles2::executeCommandBuffer(QRhiCommandBuffer *cb)
{
QGles2GraphicsPipeline *psD = QRHI_RES(QGles2GraphicsPipeline, cmd.args.bindVertexBuffer.ps);
if (psD) {
+ if (lastBindVertexBuffer.ps == psD
+ && lastBindVertexBuffer.buffer == cmd.args.bindVertexBuffer.buffer
+ && lastBindVertexBuffer.offset == cmd.args.bindVertexBuffer.offset
+ && lastBindVertexBuffer.binding == cmd.args.bindVertexBuffer.binding)
+ {
+ // The pipeline and so the vertex input layout is
+ // immutable, no point in issuing the exact same set of
+ // glVertexAttribPointer again and again for the same buffer.
+ break;
+ }
+ lastBindVertexBuffer.ps = psD;
+ lastBindVertexBuffer.buffer = cmd.args.bindVertexBuffer.buffer;
+ lastBindVertexBuffer.offset = cmd.args.bindVertexBuffer.offset;
+ lastBindVertexBuffer.binding = cmd.args.bindVertexBuffer.binding;
+
+ if (cmd.args.bindVertexBuffer.buffer != currentArrayBuffer) {
+ currentArrayBuffer = cmd.args.bindVertexBuffer.buffer;
+ // we do not support more than one vertex buffer
+ f->glBindBuffer(GL_ARRAY_BUFFER, currentArrayBuffer);
+ }
for (auto it = psD->m_vertexInputLayout.cbeginAttributes(), itEnd = psD->m_vertexInputLayout.cendAttributes();
it != itEnd; ++it)
{
@@ -2210,12 +2236,6 @@ void QRhiGles2::executeCommandBuffer(QRhiCommandBuffer *cb)
if (bindingIdx != cmd.args.bindVertexBuffer.binding)
continue;
- if (cmd.args.bindVertexBuffer.buffer != currentArrayBuffer) {
- currentArrayBuffer = cmd.args.bindVertexBuffer.buffer;
- // we do not support more than one vertex buffer
- f->glBindBuffer(GL_ARRAY_BUFFER, currentArrayBuffer);
- }
-
const QRhiVertexInputBinding *inputBinding = psD->m_vertexInputLayout.bindingAt(bindingIdx);
const int stride = int(inputBinding->stride());
int size = 1;