Revert "Added a VertexBuffer implementation to all Drawables that were rendered via VertexArrays."

This reverts commit 4dfad062e4.
This commit is contained in:
binary1248 2019-05-04 16:39:50 +02:00 committed by Lukas Dürrenberger
parent b00317e90c
commit 81a1da6a59
6 changed files with 74 additions and 230 deletions

View File

@ -32,7 +32,6 @@
#include <SFML/Graphics/Drawable.hpp> #include <SFML/Graphics/Drawable.hpp>
#include <SFML/Graphics/Transformable.hpp> #include <SFML/Graphics/Transformable.hpp>
#include <SFML/Graphics/VertexArray.hpp> #include <SFML/Graphics/VertexArray.hpp>
#include <SFML/Graphics/VertexBuffer.hpp>
#include <SFML/System/Vector2.hpp> #include <SFML/System/Vector2.hpp>
@ -313,8 +312,6 @@ private:
float m_outlineThickness; ///< Thickness of the shape's outline float m_outlineThickness; ///< Thickness of the shape's outline
VertexArray m_vertices; ///< Vertex array containing the fill geometry VertexArray m_vertices; ///< Vertex array containing the fill geometry
VertexArray m_outlineVertices; ///< Vertex array containing the outline geometry VertexArray m_outlineVertices; ///< Vertex array containing the outline geometry
VertexBuffer m_verticesBuffer; ///< Vertex buffer containing the fill geometry
VertexBuffer m_outlineVerticesBuffer; ///< Vertex buffer containing the outline geometry
FloatRect m_insideBounds; ///< Bounding rectangle of the inside (fill) FloatRect m_insideBounds; ///< Bounding rectangle of the inside (fill)
FloatRect m_bounds; ///< Bounding rectangle of the whole shape (outline + fill) FloatRect m_bounds; ///< Bounding rectangle of the whole shape (outline + fill)
}; };

View File

@ -33,7 +33,6 @@
#include <SFML/Graphics/Transformable.hpp> #include <SFML/Graphics/Transformable.hpp>
#include <SFML/Graphics/Vertex.hpp> #include <SFML/Graphics/Vertex.hpp>
#include <SFML/Graphics/Rect.hpp> #include <SFML/Graphics/Rect.hpp>
#include <SFML/Graphics/VertexBuffer.hpp>
namespace sf namespace sf
@ -217,7 +216,6 @@ private:
// Member data // Member data
//////////////////////////////////////////////////////////// ////////////////////////////////////////////////////////////
Vertex m_vertices[4]; ///< Vertices defining the sprite's geometry Vertex m_vertices[4]; ///< Vertices defining the sprite's geometry
VertexBuffer m_verticesBuffer; ///< Vertex buffer containing the sprite's geometry
const Texture* m_texture; ///< Texture of the sprite const Texture* m_texture; ///< Texture of the sprite
IntRect m_textureRect; ///< Rectangle defining the area of the source texture to display IntRect m_textureRect; ///< Rectangle defining the area of the source texture to display
}; };

View File

@ -34,7 +34,6 @@
#include <SFML/Graphics/Font.hpp> #include <SFML/Graphics/Font.hpp>
#include <SFML/Graphics/Rect.hpp> #include <SFML/Graphics/Rect.hpp>
#include <SFML/Graphics/VertexArray.hpp> #include <SFML/Graphics/VertexArray.hpp>
#include <SFML/Graphics/VertexBuffer.hpp>
#include <SFML/System/String.hpp> #include <SFML/System/String.hpp>
#include <string> #include <string>
#include <vector> #include <vector>
@ -447,8 +446,6 @@ private:
float m_outlineThickness; ///< Thickness of the text's outline float m_outlineThickness; ///< Thickness of the text's outline
mutable VertexArray m_vertices; ///< Vertex array containing the fill geometry mutable VertexArray m_vertices; ///< Vertex array containing the fill geometry
mutable VertexArray m_outlineVertices; ///< Vertex array containing the outline geometry mutable VertexArray m_outlineVertices; ///< Vertex array containing the outline geometry
mutable VertexBuffer m_verticesBuffer; ///< Vertex buffer containing the fill geometry
mutable VertexBuffer m_outlineVerticesBuffer; ///< Vertex buffer containing the outline geometry
mutable FloatRect m_bounds; ///< Bounding rectangle of the text (in local coordinates) mutable FloatRect m_bounds; ///< Bounding rectangle of the text (in local coordinates)
mutable bool m_geometryNeedUpdate; ///< Does the geometry need to be recomputed? mutable bool m_geometryNeedUpdate; ///< Does the geometry need to be recomputed?
mutable Uint64 m_fontTextureId; ///< The font texture id mutable Uint64 m_fontTextureId; ///< The font texture id

View File

@ -87,10 +87,6 @@ void Shape::setTextureRect(const IntRect& rect)
{ {
m_textureRect = rect; m_textureRect = rect;
updateTexCoords(); updateTexCoords();
// Update the vertex buffers if they are being used
if (m_verticesBuffer.getVertexCount())
m_verticesBuffer.update(&m_vertices[0]);
} }
@ -106,10 +102,6 @@ void Shape::setFillColor(const Color& color)
{ {
m_fillColor = color; m_fillColor = color;
updateFillColors(); updateFillColors();
// Update the vertex buffers if they are being used
if (m_verticesBuffer.getVertexCount())
m_verticesBuffer.update(&m_vertices[0]);
} }
@ -125,10 +117,6 @@ void Shape::setOutlineColor(const Color& color)
{ {
m_outlineColor = color; m_outlineColor = color;
updateOutlineColors(); updateOutlineColors();
// Update the vertex buffers if they are being used
if (m_outlineVerticesBuffer.getVertexCount())
m_outlineVerticesBuffer.update(&m_outlineVertices[0]);
} }
@ -174,11 +162,9 @@ m_texture (NULL),
m_textureRect (), m_textureRect (),
m_fillColor (255, 255, 255), m_fillColor (255, 255, 255),
m_outlineColor (255, 255, 255), m_outlineColor (255, 255, 255),
m_outlineThickness (0), m_outlineThickness(0),
m_vertices (TriangleFan), m_vertices (TriangleFan),
m_outlineVertices (TriangleStrip), m_outlineVertices (TriangleStrip),
m_verticesBuffer (TriangleFan, VertexBuffer::Static),
m_outlineVerticesBuffer(TriangleStrip, VertexBuffer::Static),
m_insideBounds (), m_insideBounds (),
m_bounds () m_bounds ()
{ {
@ -194,16 +180,6 @@ void Shape::update()
{ {
m_vertices.resize(0); m_vertices.resize(0);
m_outlineVertices.resize(0); m_outlineVertices.resize(0);
if (VertexBuffer::isAvailable())
{
if (m_verticesBuffer.getVertexCount())
m_verticesBuffer.create(0);
if (m_outlineVerticesBuffer.getVertexCount())
m_outlineVerticesBuffer.create(0);
}
return; return;
} }
@ -230,21 +206,6 @@ void Shape::update()
// Outline // Outline
updateOutline(); updateOutline();
// Update the vertex buffers if they are being used
if (VertexBuffer::isAvailable())
{
if (m_verticesBuffer.getVertexCount() != m_vertices.getVertexCount())
m_verticesBuffer.create(m_vertices.getVertexCount());
m_verticesBuffer.update(&m_vertices[0]);
if (m_outlineVerticesBuffer.getVertexCount() != m_outlineVertices.getVertexCount())
m_outlineVerticesBuffer.create(m_outlineVertices.getVertexCount());
if (m_outlineVertices.getVertexCount())
m_outlineVerticesBuffer.update(&m_outlineVertices[0]);
}
} }
@ -255,30 +216,14 @@ void Shape::draw(RenderTarget& target, RenderStates states) const
// Render the inside // Render the inside
states.texture = m_texture; states.texture = m_texture;
if (VertexBuffer::isAvailable())
{
target.draw(m_verticesBuffer, states);
}
else
{
target.draw(m_vertices, states); target.draw(m_vertices, states);
}
// Render the outline // Render the outline
if (m_outlineThickness != 0) if (m_outlineThickness != 0)
{ {
states.texture = NULL; states.texture = NULL;
if (VertexBuffer::isAvailable())
{
target.draw(m_outlineVerticesBuffer, states);
}
else
{
target.draw(m_outlineVertices, states); target.draw(m_outlineVertices, states);
} }
}
} }

View File

@ -35,37 +35,26 @@ namespace sf
{ {
//////////////////////////////////////////////////////////// ////////////////////////////////////////////////////////////
Sprite::Sprite() : Sprite::Sprite() :
m_verticesBuffer(TrianglesStrip, VertexBuffer::Stream),
m_texture (NULL), m_texture (NULL),
m_textureRect () m_textureRect()
{ {
if (VertexBuffer::isAvailable())
m_verticesBuffer.create(4);
} }
//////////////////////////////////////////////////////////// ////////////////////////////////////////////////////////////
Sprite::Sprite(const Texture& texture) : Sprite::Sprite(const Texture& texture) :
m_verticesBuffer(TrianglesStrip, VertexBuffer::Stream),
m_texture (NULL), m_texture (NULL),
m_textureRect () m_textureRect()
{ {
if (VertexBuffer::isAvailable())
m_verticesBuffer.create(4);
setTexture(texture); setTexture(texture);
} }
//////////////////////////////////////////////////////////// ////////////////////////////////////////////////////////////
Sprite::Sprite(const Texture& texture, const IntRect& rectangle) : Sprite::Sprite(const Texture& texture, const IntRect& rectangle) :
m_verticesBuffer(TrianglesStrip, VertexBuffer::Stream),
m_texture (NULL), m_texture (NULL),
m_textureRect () m_textureRect()
{ {
if (VertexBuffer::isAvailable())
m_verticesBuffer.create(4);
setTexture(texture); setTexture(texture);
setTextureRect(rectangle); setTextureRect(rectangle);
} }
@ -91,10 +80,6 @@ void Sprite::setTextureRect(const IntRect& rectangle)
m_textureRect = rectangle; m_textureRect = rectangle;
updatePositions(); updatePositions();
updateTexCoords(); updateTexCoords();
// Update the vertex buffer if it is being used
if (VertexBuffer::isAvailable())
m_verticesBuffer.update(m_vertices);
} }
} }
@ -107,10 +92,6 @@ void Sprite::setColor(const Color& color)
m_vertices[1].color = color; m_vertices[1].color = color;
m_vertices[2].color = color; m_vertices[2].color = color;
m_vertices[3].color = color; m_vertices[3].color = color;
// Update the vertex buffer if it is being used
if (VertexBuffer::isAvailable())
m_verticesBuffer.update(m_vertices);
} }
@ -159,16 +140,8 @@ void Sprite::draw(RenderTarget& target, RenderStates states) const
{ {
states.transform *= getTransform(); states.transform *= getTransform();
states.texture = m_texture; states.texture = m_texture;
if (VertexBuffer::isAvailable())
{
target.draw(m_verticesBuffer, states);
}
else
{
target.draw(m_vertices, 4, TriangleStrip, states); target.draw(m_vertices, 4, TriangleStrip, states);
} }
}
} }

View File

@ -79,7 +79,7 @@ Text::Text() :
m_string (), m_string (),
m_font (NULL), m_font (NULL),
m_characterSize (30), m_characterSize (30),
m_letterSpacingFactor (1.f), m_letterSpacingFactor(1.f),
m_lineSpacingFactor (1.f), m_lineSpacingFactor (1.f),
m_style (Regular), m_style (Regular),
m_fillColor (255, 255, 255), m_fillColor (255, 255, 255),
@ -87,8 +87,6 @@ m_outlineColor (0, 0, 0),
m_outlineThickness (0), m_outlineThickness (0),
m_vertices (Triangles), m_vertices (Triangles),
m_outlineVertices (Triangles), m_outlineVertices (Triangles),
m_verticesBuffer (Triangles, VertexBuffer::Static),
m_outlineVerticesBuffer(Triangles, VertexBuffer::Static),
m_bounds (), m_bounds (),
m_geometryNeedUpdate (false), m_geometryNeedUpdate (false),
m_fontTextureId (0) m_fontTextureId (0)
@ -102,7 +100,7 @@ Text::Text(const String& string, const Font& font, unsigned int characterSize) :
m_string (string), m_string (string),
m_font (&font), m_font (&font),
m_characterSize (characterSize), m_characterSize (characterSize),
m_letterSpacingFactor (1.f), m_letterSpacingFactor(1.f),
m_lineSpacingFactor (1.f), m_lineSpacingFactor (1.f),
m_style (Regular), m_style (Regular),
m_fillColor (255, 255, 255), m_fillColor (255, 255, 255),
@ -110,8 +108,6 @@ m_outlineColor (0, 0, 0),
m_outlineThickness (0), m_outlineThickness (0),
m_vertices (Triangles), m_vertices (Triangles),
m_outlineVertices (Triangles), m_outlineVertices (Triangles),
m_verticesBuffer (Triangles, VertexBuffer::Static),
m_outlineVerticesBuffer(Triangles, VertexBuffer::Static),
m_bounds (), m_bounds (),
m_geometryNeedUpdate (true), m_geometryNeedUpdate (true),
m_fontTextureId (0) m_fontTextureId (0)
@ -206,15 +202,6 @@ void Text::setFillColor(const Color& color)
{ {
for (std::size_t i = 0; i < m_vertices.getVertexCount(); ++i) for (std::size_t i = 0; i < m_vertices.getVertexCount(); ++i)
m_vertices[i].color = m_fillColor; m_vertices[i].color = m_fillColor;
if (VertexBuffer::isAvailable())
{
if (m_verticesBuffer.getVertexCount() != m_vertices.getVertexCount())
m_verticesBuffer.create(m_vertices.getVertexCount());
if (m_vertices.getVertexCount() > 0)
m_verticesBuffer.update(&m_vertices[0]);
}
} }
} }
} }
@ -233,15 +220,6 @@ void Text::setOutlineColor(const Color& color)
{ {
for (std::size_t i = 0; i < m_outlineVertices.getVertexCount(); ++i) for (std::size_t i = 0; i < m_outlineVertices.getVertexCount(); ++i)
m_outlineVertices[i].color = m_outlineColor; m_outlineVertices[i].color = m_outlineColor;
if (VertexBuffer::isAvailable())
{
if (m_outlineVerticesBuffer.getVertexCount() != m_outlineVertices.getVertexCount())
m_outlineVerticesBuffer.create(m_outlineVertices.getVertexCount());
if (m_outlineVertices.getVertexCount() > 0)
m_outlineVerticesBuffer.update(&m_outlineVertices[0]);
}
} }
} }
} }
@ -404,26 +382,10 @@ void Text::draw(RenderTarget& target, RenderStates states) const
// Only draw the outline if there is something to draw // Only draw the outline if there is something to draw
if (m_outlineThickness != 0) if (m_outlineThickness != 0)
{
if (VertexBuffer::isAvailable())
{
target.draw(m_outlineVerticesBuffer, states);
}
else
{
target.draw(m_outlineVertices, states); target.draw(m_outlineVertices, states);
}
}
if (VertexBuffer::isAvailable())
{
target.draw(m_verticesBuffer, states);
}
else
{
target.draw(m_vertices, states); target.draw(m_vertices, states);
} }
}
} }
@ -446,23 +408,11 @@ void Text::ensureGeometryUpdate() const
// Clear the previous geometry // Clear the previous geometry
m_vertices.clear(); m_vertices.clear();
m_outlineVertices.clear(); m_outlineVertices.clear();
m_bounds = FloatRect(); m_bounds = FloatRect();
// No text: nothing to draw // No text: nothing to draw
if (m_string.isEmpty()) if (m_string.isEmpty())
{
if (VertexBuffer::isAvailable())
{
if (m_verticesBuffer.getVertexCount())
m_verticesBuffer.create(0);
if (m_outlineVerticesBuffer.getVertexCount())
m_outlineVerticesBuffer.create(0);
}
return; return;
}
// Compute values related to the text style // Compute values related to the text style
bool isBold = m_style & Bold; bool isBold = m_style & Bold;
@ -612,22 +562,6 @@ void Text::ensureGeometryUpdate() const
m_bounds.top = minY; m_bounds.top = minY;
m_bounds.width = maxX - minX; m_bounds.width = maxX - minX;
m_bounds.height = maxY - minY; m_bounds.height = maxY - minY;
// Update the vertex buffer if it is being used
if (VertexBuffer::isAvailable())
{
if (m_verticesBuffer.getVertexCount() != m_vertices.getVertexCount())
m_verticesBuffer.create(m_vertices.getVertexCount());
if (m_vertices.getVertexCount() > 0)
m_verticesBuffer.update(&m_vertices[0]);
if (m_outlineVerticesBuffer.getVertexCount() != m_outlineVertices.getVertexCount())
m_outlineVerticesBuffer.create(m_outlineVertices.getVertexCount());
if (m_outlineVertices.getVertexCount() > 0)
m_outlineVerticesBuffer.update(&m_outlineVertices[0]);
}
} }
} // namespace sf } // namespace sf