Skip to content

Commit

Permalink
Fix OpenGL texture coordinate pointer not being updated when the arra…
Browse files Browse the repository at this point in the history
…y enabled state changes but the RenderTarget's cache state doesn't.
  • Loading branch information
binary1248 authored and eXpl0it3r committed Oct 12, 2017
1 parent b3d6e48 commit 516678f
Showing 1 changed file with 16 additions and 13 deletions.
29 changes: 16 additions & 13 deletions src/SFML/Graphics/RenderTarget.cpp
Expand Up @@ -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)
Expand All @@ -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<const char*>(vertices);

// If we pre-transform the vertices, we must use our internal vertex cache
if (useVertexCache)
data = reinterpret_cast<const char*>(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<const char*>(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,
Expand All @@ -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;
}
}

Expand Down

0 comments on commit 516678f

Please sign in to comment.