From 516678fe1f83abf1ab595d9dee69ba5082cb4518 Mon Sep 17 00:00:00 2001 From: binary1248 Date: Fri, 29 Sep 2017 22:53:53 +0200 Subject: [PATCH] Fix OpenGL texture coordinate pointer not being updated when the array enabled state changes but the RenderTarget's cache state doesn't. --- src/SFML/Graphics/RenderTarget.cpp | 29 ++++++++++++++++------------- 1 file changed, 16 insertions(+), 13 deletions(-) diff --git a/src/SFML/Graphics/RenderTarget.cpp b/src/SFML/Graphics/RenderTarget.cpp index 244ee302..066eb864 100644 --- a/src/SFML/Graphics/RenderTarget.cpp +++ b/src/SFML/Graphics/RenderTarget.cpp @@ -259,16 +259,6 @@ void RenderTarget::draw(const Vertex* vertices, std::size_t vertexCount, if (states.shader) applyShader(states.shader); - // If we pre-transform the vertices, we must use our internal vertex cache - if (useVertexCache) - { - // ... and if we already used it previously, we don't need to set the pointers again - if (!m_cache.useVertexCache) - vertices = m_cache.vertexCache; - else - 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) @@ -277,18 +267,30 @@ void RenderTarget::draw(const Vertex* vertices, std::size_t vertexCount, 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) + // If we switch between non-cache and cache mode or enable texture + // coordinates we need to set up the pointers to the vertices' components + if (!useVertexCache || !m_cache.useVertexCache) { const char* data = reinterpret_cast(vertices); + + // If we pre-transform the vertices, we must use our internal vertex cache + if (useVertexCache) + data = reinterpret_cast(m_cache.vertexCache); + glCheck(glVertexPointer(2, GL_FLOAT, sizeof(Vertex), data + 0)); glCheck(glColorPointer(4, GL_UNSIGNED_BYTE, sizeof(Vertex), data + 8)); if (enableTexCoordsArray) glCheck(glTexCoordPointer(2, GL_FLOAT, sizeof(Vertex), data + 12)); } + else if (enableTexCoordsArray && !m_cache.texCoordsArrayEnabled) + { + // If we enter this block, we are already using our internal vertex cache + const char* data = reinterpret_cast(m_cache.vertexCache); + + glCheck(glTexCoordPointer(2, GL_FLOAT, sizeof(Vertex), data + 12)); + } // Find the OpenGL primitive type static const GLenum modes[] = {GL_POINTS, GL_LINES, GL_LINE_STRIP, GL_TRIANGLES, @@ -309,6 +311,7 @@ void RenderTarget::draw(const Vertex* vertices, std::size_t vertexCount, // Update the cache m_cache.useVertexCache = useVertexCache; + m_cache.texCoordsArrayEnabled = enableTexCoordsArray; } }