From 6bd654b85477d3ada5fc0809dce45cab92f62fc8 Mon Sep 17 00:00:00 2001
From: LaurentGom <LaurentGom@4e206d99-4929-0410-ac5d-dfc041789085>
Date: Wed, 2 Dec 2009 20:45:53 +0000
Subject: [PATCH] Fixed wrong type for OpenGL indices (std::size_t could be 64
 bits on 64 bits platforms -- now using sf::Uint32)

git-svn-id: https://sfml.svn.sourceforge.net/svnroot/sfml/branches/sfml2@1297 4e206d99-4929-0410-ac5d-dfc041789085
---
 include/SFML/Graphics/RenderQueue.hpp     |  6 +++---
 src/SFML/Graphics/Batch.cpp               |  4 ++--
 src/SFML/Graphics/Batch.hpp               |  8 ++++----
 src/SFML/Graphics/GeometryRenderer.hpp    |  4 ++--
 src/SFML/Graphics/GeometryRendererIM.cpp  | 10 +++++-----
 src/SFML/Graphics/GeometryRendererIM.hpp  |  8 ++++----
 src/SFML/Graphics/GeometryRendererVA.cpp  |  4 ++--
 src/SFML/Graphics/GeometryRendererVA.hpp  |  6 +++---
 src/SFML/Graphics/GeometryRendererVBO.cpp |  8 ++++----
 src/SFML/Graphics/GeometryRendererVBO.hpp | 12 ++++++------
 src/SFML/Graphics/RenderQueue.cpp         |  6 +++---
 11 files changed, 38 insertions(+), 38 deletions(-)

diff --git a/include/SFML/Graphics/RenderQueue.hpp b/include/SFML/Graphics/RenderQueue.hpp
index 176820e4..49e761da 100644
--- a/include/SFML/Graphics/RenderQueue.hpp
+++ b/include/SFML/Graphics/RenderQueue.hpp
@@ -292,7 +292,7 @@ public :
     /// \param index2 Index of the third vertex of the triangle
     ///
     ////////////////////////////////////////////////////////////
-	void AddTriangle(std::size_t index0, std::size_t index1, std::size_t index2);
+    void AddTriangle(std::size_t index0, std::size_t index1, std::size_t index2);
 
     ////////////////////////////////////////////////////////////
     /// \brief Render the content of the whole queue
@@ -330,7 +330,7 @@ private :
     ////////////////////////////////////////////////////////////
     typedef std::vector<priv::Batch>  BatchArray;
     typedef std::vector<float>        VertexArray;
-    typedef std::vector<std::size_t>  IndexArray;
+    typedef std::vector<Uint32>       IndexArray;
 
     ////////////////////////////////////////////////////////////
     // Member data
@@ -343,7 +343,7 @@ private :
     Blend::Mode             myCurrentBlendMode;    ///< Current blending mode
     IntRect                 myCurrentViewport;     ///< Current target viewport
     Vector2f                myCurrentViewportSize; ///< Size of the current viewport (for vertex calculations)
-    std::size_t             myBaseIndex;           ///< Base vertex index for the current batch
+    Uint32                  myBaseIndex;           ///< Base vertex index for the current batch
     priv::GeometryRenderer* myRenderer;            ///< Optimized geometry renderer
     priv::Batch*            myCurrentBatch;        ///< Current geometry block
     BatchArray              myBatches;             ///< Blocks of geometry to render
diff --git a/src/SFML/Graphics/Batch.cpp b/src/SFML/Graphics/Batch.cpp
index b27b50a8..0a5fdaa6 100644
--- a/src/SFML/Graphics/Batch.cpp
+++ b/src/SFML/Graphics/Batch.cpp
@@ -62,14 +62,14 @@ bool Batch::Matches(const Image* texture, const Shader* shader, Blend::Mode blen
 
 
 ////////////////////////////////////////////////////////////
-void Batch::Begin(std::size_t index)
+void Batch::Begin(Uint32 index)
 {
     myStart = index;
 }
 
 
 ////////////////////////////////////////////////////////////
-void Batch::End(std::size_t index)
+void Batch::End(Uint32 index)
 {
     myCount = index - myStart;
 }
diff --git a/src/SFML/Graphics/Batch.hpp b/src/SFML/Graphics/Batch.hpp
index 3c206f93..9d0b430a 100644
--- a/src/SFML/Graphics/Batch.hpp
+++ b/src/SFML/Graphics/Batch.hpp
@@ -78,7 +78,7 @@ public :
     /// \param index Start index
     ///
     ////////////////////////////////////////////////////////////
-    void Begin(std::size_t index);
+    void Begin(Uint32 index);
 
     ////////////////////////////////////////////////////////////
     /// \brief Setup the end index of the batch
@@ -86,7 +86,7 @@ public :
     /// \param index End index
     ///
     ////////////////////////////////////////////////////////////
-    void End(std::size_t index);
+    void End(Uint32 index);
 
     ////////////////////////////////////////////////////////////
     /// \brief Render the contents of the batch
@@ -105,8 +105,8 @@ private :
     const Shader* myShader;    ///< Pixel shader used by the batch
     Blend::Mode   myBlendMode; ///< Blending mode used by the batch
     IntRect       myViewport;  ///< Target viewport for the batch
-    std::size_t   myStart;     ///< Index of the first index to render with this batch
-    std::size_t   myCount;     ///< Number of indices to render with this batch
+    Uint32        myStart;     ///< Index of the first index to render with this batch
+    Uint32        myCount;     ///< Number of indices to render with this batch
 };
 
 } // namespace priv
diff --git a/src/SFML/Graphics/GeometryRenderer.hpp b/src/SFML/Graphics/GeometryRenderer.hpp
index 1a3a295d..4b54b037 100644
--- a/src/SFML/Graphics/GeometryRenderer.hpp
+++ b/src/SFML/Graphics/GeometryRenderer.hpp
@@ -75,7 +75,7 @@ public :
     /// \param indicesCount  Number of indices to render
     ///
     ////////////////////////////////////////////////////////////
-    virtual void Begin(const float* vertices, std::size_t verticesCount, const std::size_t* indices, std::size_t indicesCount) = 0;
+    virtual void Begin(const float* vertices, std::size_t verticesCount, const Uint32* indices, std::size_t indicesCount) = 0;
 
     ////////////////////////////////////////////////////////////
     /// \brief Stop rendering geometry
@@ -95,7 +95,7 @@ public :
     /// \param count Number of indices to be rendered
     ///
     ////////////////////////////////////////////////////////////
-    virtual void RenderTriangles(std::size_t start, std::size_t count) = 0;
+    virtual void RenderTriangles(Uint32 start, Uint32 count) = 0;
 };
 
 } // namespace priv
diff --git a/src/SFML/Graphics/GeometryRendererIM.cpp b/src/SFML/Graphics/GeometryRendererIM.cpp
index 6523119e..b25e6a6a 100644
--- a/src/SFML/Graphics/GeometryRendererIM.cpp
+++ b/src/SFML/Graphics/GeometryRendererIM.cpp
@@ -51,7 +51,7 @@ myIndices (NULL)
 
 
 ////////////////////////////////////////////////////////////
-void GeometryRendererIM::Begin(const float* vertices, std::size_t, const std::size_t* indices, std::size_t)
+void GeometryRendererIM::Begin(const float* vertices, std::size_t, const Uint32* indices, std::size_t)
 {
     // Store the geometry informations for later rendering
     myVertices = vertices;
@@ -67,17 +67,17 @@ void GeometryRendererIM::End()
 
 
 ////////////////////////////////////////////////////////////
-void GeometryRendererIM::RenderTriangles(std::size_t start, std::size_t count)
+void GeometryRendererIM::RenderTriangles(Uint32 start, Uint32 count)
 {
     // Caculate the bounds of the geometry range to render
-    const std::size_t* begin = myIndices + start;
-    const std::size_t* end = begin + count;
+    const Uint32* begin = myIndices + start;
+    const Uint32* end = begin + count;
 
     // Begin rendering
     glBegin(GL_TRIANGLES);
 
     // Send the vertices one by one
-    for (const std::size_t* index = begin; index != end; index++)
+    for (const Uint32* index = begin; index != end; index++)
     {
         const float* vertex = myVertices + *index * 8;
 
diff --git a/src/SFML/Graphics/GeometryRendererIM.hpp b/src/SFML/Graphics/GeometryRendererIM.hpp
index d2ea86d1..42f4a35b 100644
--- a/src/SFML/Graphics/GeometryRendererIM.hpp
+++ b/src/SFML/Graphics/GeometryRendererIM.hpp
@@ -71,7 +71,7 @@ public :
     /// \param indicesCount Number of indices to render
     ///
     ////////////////////////////////////////////////////////////
-    virtual void Begin(const float* vertices, std::size_t verticesCount, const std::size_t* indices, std::size_t indicesCount);
+    virtual void Begin(const float* vertices, std::size_t verticesCount, const Uint32* indices, std::size_t indicesCount);
 
     ////////////////////////////////////////////////////////////
     /// \brief Stop rendering geometry
@@ -91,13 +91,13 @@ public :
     /// \param count Number of indices to be rendered
     ///
     ////////////////////////////////////////////////////////////
-    virtual void RenderTriangles(std::size_t start, std::size_t count);
+    virtual void RenderTriangles(Uint32 start, Uint32 count);
 
     ////////////////////////////////////////////////////////////
     // Member data
     ////////////////////////////////////////////////////////////
-    const float*       myVertices; ///< Pointer to the vertices to render
-    const std::size_t* myIndices;  ///< Pointer to the indices to render
+    const float*  myVertices; ///< Pointer to the vertices to render
+    const Uint32* myIndices;  ///< Pointer to the indices to render
 };
 
 } // namespace priv
diff --git a/src/SFML/Graphics/GeometryRendererVA.cpp b/src/SFML/Graphics/GeometryRendererVA.cpp
index 433c07b8..ddd45ab3 100644
--- a/src/SFML/Graphics/GeometryRendererVA.cpp
+++ b/src/SFML/Graphics/GeometryRendererVA.cpp
@@ -51,7 +51,7 @@ myIndices(NULL)
 
 
 ////////////////////////////////////////////////////////////
-void GeometryRendererVA::Begin(const float* vertices, std::size_t verticesCount, const std::size_t* indices, std::size_t)
+void GeometryRendererVA::Begin(const float* vertices, std::size_t verticesCount, const Uint32* indices, std::size_t)
 {
     static const GLsizei stride = 8 * sizeof(float);
 
@@ -87,7 +87,7 @@ void GeometryRendererVA::End()
 
 
 ////////////////////////////////////////////////////////////
-void GeometryRendererVA::RenderTriangles(std::size_t start, std::size_t count)
+void GeometryRendererVA::RenderTriangles(Uint32 start, Uint32 count)
 {
     GLCheck(glDrawElements(GL_TRIANGLES, static_cast<GLsizei>(count), GL_UNSIGNED_INT, myIndices + start));
 }
diff --git a/src/SFML/Graphics/GeometryRendererVA.hpp b/src/SFML/Graphics/GeometryRendererVA.hpp
index fcfddaf5..0e581a08 100644
--- a/src/SFML/Graphics/GeometryRendererVA.hpp
+++ b/src/SFML/Graphics/GeometryRendererVA.hpp
@@ -71,7 +71,7 @@ public :
     /// \param indicesCount Number of indices to render
     ///
     ////////////////////////////////////////////////////////////
-    virtual void Begin(const float* vertices, std::size_t verticesCount, const std::size_t* indices, std::size_t indicesCount);
+    virtual void Begin(const float* vertices, std::size_t verticesCount, const Uint32* indices, std::size_t indicesCount);
 
     ////////////////////////////////////////////////////////////
     /// \brief Stop rendering geometry
@@ -91,12 +91,12 @@ public :
     /// \param count Number of indices to be rendered
     ///
     ////////////////////////////////////////////////////////////
-    virtual void RenderTriangles(std::size_t start, std::size_t count);
+    virtual void RenderTriangles(Uint32 start, Uint32 count);
 
     ////////////////////////////////////////////////////////////
     // Member data
     ////////////////////////////////////////////////////////////
-    const std::size_t* myIndices; ///< Pointer to the indices to render
+    const Uint32* myIndices; ///< Pointer to the indices to render
 };
 
 } // namespace priv
diff --git a/src/SFML/Graphics/GeometryRendererVBO.cpp b/src/SFML/Graphics/GeometryRendererVBO.cpp
index e0927cda..e753570b 100644
--- a/src/SFML/Graphics/GeometryRendererVBO.cpp
+++ b/src/SFML/Graphics/GeometryRendererVBO.cpp
@@ -64,7 +64,7 @@ GeometryRendererVBO::~GeometryRendererVBO()
 
 
 ////////////////////////////////////////////////////////////
-void GeometryRendererVBO::Begin(const float* vertices, std::size_t verticesCount, const std::size_t* indices, std::size_t indicesCount)
+void GeometryRendererVBO::Begin(const float* vertices, std::size_t verticesCount, const Uint32* indices, std::size_t indicesCount)
 {
     // Update the vertex buffer data (make it grow if it is not large enough)
     GLCheck(glBindBufferARB(GL_ARRAY_BUFFER_ARB, myVertexBuffer));
@@ -82,12 +82,12 @@ void GeometryRendererVBO::Begin(const float* vertices, std::size_t verticesCount
     GLCheck(glBindBufferARB(GL_ELEMENT_ARRAY_BUFFER_ARB, myIndexBuffer));
     if (indicesCount > myIndexBufferSize)
     {
-        GLCheck(glBufferDataARB(GL_ELEMENT_ARRAY_BUFFER_ARB, indicesCount * sizeof(std::size_t), indices, GL_DYNAMIC_DRAW_ARB));
+        GLCheck(glBufferDataARB(GL_ELEMENT_ARRAY_BUFFER_ARB, indicesCount * sizeof(Uint32), indices, GL_DYNAMIC_DRAW_ARB));
         myIndexBufferSize = indicesCount;
     }
     else
     {
-        GLCheck(glBufferSubDataARB(GL_ELEMENT_ARRAY_BUFFER_ARB, 0, indicesCount * sizeof(std::size_t), indices));
+        GLCheck(glBufferSubDataARB(GL_ELEMENT_ARRAY_BUFFER_ARB, 0, indicesCount * sizeof(Uint32), indices));
     }
 
     static const GLsizei stride  = 8 * sizeof(float);
@@ -116,7 +116,7 @@ void GeometryRendererVBO::End()
 
 
 ////////////////////////////////////////////////////////////
-void GeometryRendererVBO::RenderTriangles(std::size_t start, std::size_t count)
+void GeometryRendererVBO::RenderTriangles(Uint32 start, Uint32 count)
 {
     static const std::size_t* pointer = NULL;
     GLCheck(glDrawElements(GL_TRIANGLES, static_cast<GLsizei>(count), GL_UNSIGNED_INT, pointer + start));
diff --git a/src/SFML/Graphics/GeometryRendererVBO.hpp b/src/SFML/Graphics/GeometryRendererVBO.hpp
index 4fee51aa..8c86606c 100644
--- a/src/SFML/Graphics/GeometryRendererVBO.hpp
+++ b/src/SFML/Graphics/GeometryRendererVBO.hpp
@@ -78,7 +78,7 @@ public :
     /// \param indicesCount Number of indices to render
     ///
     ////////////////////////////////////////////////////////////
-    virtual void Begin(const float* vertices, std::size_t verticesCount, const std::size_t* indices, std::size_t indicesCount);
+    virtual void Begin(const float* vertices, std::size_t verticesCount, const Uint32* indices, std::size_t indicesCount);
 
     ////////////////////////////////////////////////////////////
     /// \brief Stop rendering geometry
@@ -98,15 +98,15 @@ public :
     /// \param count Number of indices to be rendered
     ///
     ////////////////////////////////////////////////////////////
-    virtual void RenderTriangles(std::size_t start, std::size_t count);
+    virtual void RenderTriangles(Uint32 start, Uint32 count);
 
     ////////////////////////////////////////////////////////////
     // Member data
     ////////////////////////////////////////////////////////////
-    GLuint      myVertexBuffer;
-    GLuint      myIndexBuffer;
-    std::size_t myVertexBufferSize;
-    std::size_t myIndexBufferSize;
+    GLuint myVertexBuffer;     ///< Identifier of the vertex buffer
+    GLuint myIndexBuffer;      ///< Identifier of the index buffer
+    Uint32 myVertexBufferSize; ///< Size of the vertex buffer
+    Uint32 myIndexBufferSize;  ///< Size of the index buffer
 };
 
 } // namespace priv
diff --git a/src/SFML/Graphics/RenderQueue.cpp b/src/SFML/Graphics/RenderQueue.cpp
index e05fe013..dea71a8d 100644
--- a/src/SFML/Graphics/RenderQueue.cpp
+++ b/src/SFML/Graphics/RenderQueue.cpp
@@ -270,9 +270,9 @@ void RenderQueue::AddTriangle(std::size_t index0, std::size_t index1, std::size_
         myIndices.resize(size + size / 2);
 
     // Copy the index data
-    myIndices[myCurrentIndexCount + 0] = index0 + myBaseIndex;
-    myIndices[myCurrentIndexCount + 1] = index1 + myBaseIndex;
-    myIndices[myCurrentIndexCount + 2] = index2 + myBaseIndex;
+    myIndices[myCurrentIndexCount + 0] = static_cast<Uint32>(index0 + myBaseIndex);
+    myIndices[myCurrentIndexCount + 1] = static_cast<Uint32>(index1 + myBaseIndex);
+    myIndices[myCurrentIndexCount + 2] = static_cast<Uint32>(index2 + myBaseIndex);
 
     // Increase the index count
     myCurrentIndexCount += 3;