Skip to content

Commit 973ac8d

Browse files
hobby8eXpl0it3r
authored andcommitted
Skip glTexCoordPointer() call if not needed
1 parent 858c9ce commit 973ac8d

File tree

2 files changed

+16
-1
lines changed

2 files changed

+16
-1
lines changed

include/SFML/Graphics/RenderTarget.hpp

Lines changed: 1 addition & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -414,6 +414,7 @@ class SFML_GRAPHICS_API RenderTarget : NonCopyable
414414
bool viewChanged; ///< Has the current view changed since last draw?
415415
BlendMode lastBlendMode; ///< Cached blending mode
416416
Uint64 lastTextureId; ///< Cached texture
417+
bool texCoordsArrayEnabled; ///< Is GL_TEXTURE_COORD_ARRAY client state enabled?
417418
bool useVertexCache; ///< Did we previously use the vertex cache?
418419
Vertex vertexCache[VertexCacheSize]; ///< Pre-transformed vertices cache
419420
};

src/SFML/Graphics/RenderTarget.cpp

Lines changed: 15 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -269,13 +269,25 @@ void RenderTarget::draw(const Vertex* vertices, std::size_t vertexCount,
269269
vertices = NULL;
270270
}
271271

272+
// Check if texture coordinates array is needed, and update client state accordingly
273+
bool enableTexCoordsArray = (states.texture || states.shader);
274+
if (enableTexCoordsArray != m_cache.texCoordsArrayEnabled)
275+
{
276+
if (enableTexCoordsArray)
277+
glCheck(glEnableClientState(GL_TEXTURE_COORD_ARRAY));
278+
else
279+
glCheck(glDisableClientState(GL_TEXTURE_COORD_ARRAY));
280+
m_cache.texCoordsArrayEnabled = enableTexCoordsArray;
281+
}
282+
272283
// Setup the pointers to the vertices' components
273284
if (vertices)
274285
{
275286
const char* data = reinterpret_cast<const char*>(vertices);
276287
glCheck(glVertexPointer(2, GL_FLOAT, sizeof(Vertex), data + 0));
277288
glCheck(glColorPointer(4, GL_UNSIGNED_BYTE, sizeof(Vertex), data + 8));
278-
glCheck(glTexCoordPointer(2, GL_FLOAT, sizeof(Vertex), data + 12));
289+
if (enableTexCoordsArray)
290+
glCheck(glTexCoordPointer(2, GL_FLOAT, sizeof(Vertex), data + 12));
279291
}
280292

281293
// Find the OpenGL primitive type
@@ -390,6 +402,8 @@ void RenderTarget::resetGLStates()
390402
if (shaderAvailable)
391403
applyShader(NULL);
392404

405+
m_cache.texCoordsArrayEnabled = true;
406+
393407
m_cache.useVertexCache = false;
394408

395409
// Set the default view

0 commit comments

Comments
 (0)