kwin: Update the GL1 code in GLVertexBuffer to match the VBO code
This saves two memory allocations in the GL1 path in setData().
This commit is contained in:
parent
e1a33cec44
commit
87ad8789f1
1 changed files with 19 additions and 26 deletions
|
@ -1222,8 +1222,7 @@ public:
|
||||||
static bool supported;
|
static bool supported;
|
||||||
static GLVertexBuffer *streamingBuffer;
|
static GLVertexBuffer *streamingBuffer;
|
||||||
static bool hasMapBufferRange;
|
static bool hasMapBufferRange;
|
||||||
QVector<float> legacyVertices;
|
QByteArray dataStore;
|
||||||
QVector<float> legacyTexCoords;
|
|
||||||
bool useColor;
|
bool useColor;
|
||||||
bool useTexCoords;
|
bool useTexCoords;
|
||||||
QColor color;
|
QColor color;
|
||||||
|
@ -1294,10 +1293,11 @@ void GLVertexBufferPrivate::legacyPainting(QRegion region, GLenum primitiveMode,
|
||||||
#else
|
#else
|
||||||
// Enable arrays
|
// Enable arrays
|
||||||
glEnableClientState(GL_VERTEX_ARRAY);
|
glEnableClientState(GL_VERTEX_ARRAY);
|
||||||
glVertexPointer(dimension, GL_FLOAT, 0, legacyVertices.constData());
|
glVertexPointer(dimension, GL_FLOAT, stride, (const GLvoid *) vertexAddress);
|
||||||
if (!legacyTexCoords.isEmpty()) {
|
|
||||||
|
if (useTexCoords) {
|
||||||
glEnableClientState(GL_TEXTURE_COORD_ARRAY);
|
glEnableClientState(GL_TEXTURE_COORD_ARRAY);
|
||||||
glTexCoordPointer(2, GL_FLOAT, 0, legacyTexCoords.constData());
|
glTexCoordPointer(2, GL_FLOAT, stride, (const GLvoid *) texCoordAddress);
|
||||||
}
|
}
|
||||||
|
|
||||||
if (useColor) {
|
if (useColor) {
|
||||||
|
@ -1314,7 +1314,7 @@ void GLVertexBufferPrivate::legacyPainting(QRegion region, GLenum primitiveMode,
|
||||||
}
|
}
|
||||||
|
|
||||||
glDisableClientState(GL_VERTEX_ARRAY);
|
glDisableClientState(GL_VERTEX_ARRAY);
|
||||||
if (!legacyTexCoords.isEmpty()) {
|
if (useTexCoords) {
|
||||||
glDisableClientState(GL_TEXTURE_COORD_ARRAY);
|
glDisableClientState(GL_TEXTURE_COORD_ARRAY);
|
||||||
}
|
}
|
||||||
#endif
|
#endif
|
||||||
|
@ -1445,30 +1445,23 @@ void GLVertexBuffer::setData(int vertexCount, int dim, const float* vertices, co
|
||||||
d->vertexCount = vertexCount;
|
d->vertexCount = vertexCount;
|
||||||
d->dimension = dim;
|
d->dimension = dim;
|
||||||
d->useTexCoords = (texcoords != NULL);
|
d->useTexCoords = (texcoords != NULL);
|
||||||
|
|
||||||
if (!GLVertexBufferPrivate::supported) {
|
|
||||||
// legacy data
|
|
||||||
d->legacyVertices.clear();
|
|
||||||
d->legacyVertices.reserve(vertexCount * dim);
|
|
||||||
for (int i = 0; i < vertexCount * dim; ++i) {
|
|
||||||
d->legacyVertices << vertices[i];
|
|
||||||
}
|
|
||||||
d->legacyTexCoords.clear();
|
|
||||||
if (d->useTexCoords) {
|
|
||||||
d->legacyTexCoords.reserve(vertexCount * 2);
|
|
||||||
for (int i = 0; i < vertexCount * 2; ++i) {
|
|
||||||
d->legacyTexCoords << texcoords[i];
|
|
||||||
}
|
|
||||||
}
|
|
||||||
return;
|
|
||||||
}
|
|
||||||
|
|
||||||
d->vertexAddress = 0;
|
|
||||||
d->texCoordAddress = dim * sizeof(float);
|
|
||||||
d->stride = (dim + (texcoords ? 2 : 0)) * sizeof(float);
|
d->stride = (dim + (texcoords ? 2 : 0)) * sizeof(float);
|
||||||
|
|
||||||
size_t size = vertexCount * d->stride;
|
size_t size = vertexCount * d->stride;
|
||||||
|
|
||||||
|
if (!GLVertexBufferPrivate::supported) {
|
||||||
|
// Legacy data
|
||||||
|
if (size_t(d->dataStore.size()) < size)
|
||||||
|
d->dataStore.resize(size);
|
||||||
|
|
||||||
|
d->interleaveArrays((float *) d->dataStore.data(),
|
||||||
|
dim, vertices, texcoords, vertexCount);
|
||||||
|
|
||||||
|
d->vertexAddress = intptr_t(d->dataStore.data());
|
||||||
|
d->texCoordAddress = d->vertexAddress + dim * sizeof(float);
|
||||||
|
return;
|
||||||
|
}
|
||||||
|
|
||||||
glBindBuffer(GL_ARRAY_BUFFER, d->buffer);
|
glBindBuffer(GL_ARRAY_BUFFER, d->buffer);
|
||||||
|
|
||||||
if (d->hasMapBufferRange) {
|
if (d->hasMapBufferRange) {
|
||||||
|
|
Loading…
Reference in a new issue