Skip to content

Commit

Permalink
[Image|RectangleShape] Now using default index buffer.
Browse files Browse the repository at this point in the history
  • Loading branch information
Unarelith committed Oct 29, 2023
1 parent a170b72 commit f59f995
Show file tree
Hide file tree
Showing 3 changed files with 5 additions and 24 deletions.
9 changes: 1 addition & 8 deletions source/client/graphics/Image.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -31,13 +31,6 @@

Image::Image() {
m_vbo.setupDefaultLayout();

static const u16 indices[] = {
0, 1, 3,
3, 1, 2
};

m_ibo.init(indices, sizeof(indices));
}

Image::Image(const std::string &textureName) : Image() {
Expand Down Expand Up @@ -149,5 +142,5 @@ void Image::draw(RenderTarget &target, RenderStates states) const {

states.texture = m_texture;

target.drawElements(m_vbo, m_ibo, 0, states);
target.drawElements(m_vbo, target.defaultIndexBuffer(), 6, states);
}
2 changes: 0 additions & 2 deletions source/client/graphics/Image.hpp
Original file line number Diff line number Diff line change
Expand Up @@ -32,7 +32,6 @@
#include <gk/gl/Transformable.hpp>

#include "Drawable.hpp"
#include "IndexBuffer.hpp"
#include "Texture.hpp"
#include "VertexBuffer.hpp"

Expand Down Expand Up @@ -70,7 +69,6 @@ class Image : public Drawable, public gk::Transformable {
const Texture *m_texture = nullptr;

VertexBuffer m_vbo;
IndexBuffer m_ibo;

private:
u16 m_width = 0;
Expand Down
18 changes: 4 additions & 14 deletions source/client/graphics/RectangleShape.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -29,19 +29,6 @@

RectangleShape::RectangleShape() {
m_vbo.setupDefaultLayout();

std::array<u16, 6 * 5> m_indices{{
0, 1, 3,
3, 1, 2
}};

for (u8 i = 1 ; i < 5 ; ++i) {
for (u8 j = 0 ; j < 6 ; ++j) {
m_indices[i * 6 + j] = u16(m_indices[j] + 4 * i);
}
}

m_ibo.init(m_indices.data(), 6 * 5 * sizeof(u16));
}

RectangleShape::RectangleShape(float width, float height, const gk::Color &color) : RectangleShape() {
Expand Down Expand Up @@ -107,5 +94,8 @@ void RectangleShape::draw(RenderTarget &target, RenderStates states) const {
states.isCullFaceEnabled = false;
states.isDepthTestEnabled = false;

target.drawElements(m_vbo, m_ibo, 0, states);
if (m_outlineThickness > 0)
target.drawElements(m_vbo, target.defaultIndexBuffer(), 0, states);
else
target.drawElements(m_vbo, target.defaultIndexBuffer(), 6, states);
}

0 comments on commit f59f995

Please sign in to comment.