Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Skip glTexCoordPointer() call if not needed (performance optimization) #1015

Closed
wants to merge 1 commit into from
Closed
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Jump to
Jump to file
Failed to load files.
Diff view
Diff view
1 change: 1 addition & 0 deletions include/SFML/Graphics/RenderTarget.hpp
Expand Up @@ -406,6 +406,7 @@ class SFML_GRAPHICS_API RenderTarget : NonCopyable
bool viewChanged; ///< Has the current view changed since last draw?
BlendMode lastBlendMode; ///< Cached blending mode
Uint64 lastTextureId; ///< Cached texture
bool texCoordsArrayEnabled; ///< Is GL_TEXTURE_COORD_ARRAY client state enabled?
bool useVertexCache; ///< Did we previously use the vertex cache?
Vertex vertexCache[VertexCacheSize]; ///< Pre-transformed vertices cache
};
Expand Down
16 changes: 15 additions & 1 deletion src/SFML/Graphics/RenderTarget.cpp
Expand Up @@ -269,13 +269,25 @@ void RenderTarget::draw(const Vertex* vertices, std::size_t vertexCount,
vertices = NULL;
}

// Check if texture coordinates array is needed, and update client state accordingly
bool enableTexCoordsArray = (states.texture || states.shader);
if (enableTexCoordsArray != m_cache.texCoordsArrayEnabled)
{
if (enableTexCoordsArray)
glCheck(glEnableClientState(GL_TEXTURE_COORD_ARRAY));
else
glCheck(glDisableClientState(GL_TEXTURE_COORD_ARRAY));
m_cache.texCoordsArrayEnabled = enableTexCoordsArray;
}

// Setup the pointers to the vertices' components
if (vertices)
{
const char* data = reinterpret_cast<const char*>(vertices);
glCheck(glVertexPointer(2, GL_FLOAT, sizeof(Vertex), data + 0));
glCheck(glColorPointer(4, GL_UNSIGNED_BYTE, sizeof(Vertex), data + 8));
glCheck(glTexCoordPointer(2, GL_FLOAT, sizeof(Vertex), data + 12));
if (enableTexCoordsArray)
glCheck(glTexCoordPointer(2, GL_FLOAT, sizeof(Vertex), data + 12));
}

// Find the OpenGL primitive type
Expand Down Expand Up @@ -390,6 +402,8 @@ void RenderTarget::resetGLStates()
if (shaderAvailable)
applyShader(NULL);

m_cache.texCoordsArrayEnabled = true;

m_cache.useVertexCache = false;

// Set the default view
Expand Down