diff options
Diffstat (limited to 'yage/render')
-rw-r--r-- | yage/render/batch.h | 44 | ||||
-rw-r--r-- | yage/render/drawable.h | 25 | ||||
-rw-r--r-- | yage/render/ellipse.h | 12 | ||||
-rw-r--r-- | yage/render/rectangle.cpp | 46 | ||||
-rw-r--r-- | yage/render/rectangle.h | 31 | ||||
-rw-r--r-- | yage/render/shape.h | 25 | ||||
-rw-r--r-- | yage/render/sprite.cpp | 95 | ||||
-rw-r--r-- | yage/render/sprite.h | 49 | ||||
-rw-r--r-- | yage/render/spritebatch.h | 1 |
9 files changed, 0 insertions, 328 deletions
diff --git a/yage/render/batch.h b/yage/render/batch.h deleted file mode 100644 index 45bf4b31..00000000 --- a/yage/render/batch.h +++ /dev/null @@ -1,44 +0,0 @@ -/** --------------------------------------------------------------------------- - * @file: batch.h - * - * Copyright (c) 2017 Yann Herklotz Grave <ymherklotz@gmail.com> - * MIT License, see LICENSE file for more details. - * ---------------------------------------------------------------------------- - */ - -#ifndef YAGE_CORE_BATCH_H -#define YAGE_CORE_BATCH_H - -namespace yage -{ - -/** The Batch class will be the base class for all the different batching - * processes that might use different shaders and attributes. This is necessary - * because when we use a different shader, we have to bind a specific number - * of attributes, and we might not always want to have a texture, colours and - * coordinates, for example, when only using simple shapes. - * - * Batching - * ======== - * The purpose of batching is to combine all sprites that use the same textures - * so that the textures does not have to be switched out on the gpu very often. - * This produces a much more efficient rendering process. An implementation of - * this can be seen in the SpriteBatch class, as it sorts and renders the - * objects you give it. - * - * The reason this base class exists, is because it makes it easier to also - * render objects that may not need a texture, or may require multiple textures - * or different attributes. - */ -class Batch -{ -public: - virtual bool init(); - virtual void begin(); - virtual void end(); - virtual void render(); -}; - -} // namespace yage - -#endif diff --git a/yage/render/drawable.h b/yage/render/drawable.h deleted file mode 100644 index 774aa451..00000000 --- a/yage/render/drawable.h +++ /dev/null @@ -1,25 +0,0 @@ -/** --------------------------------------------------------------------------- - * @file: drawable.h - * - * Copyright (c) 2017 Yann Herklotz Grave <ymherklotz@gmail.com> - * MIT License, see LICENSE file for more details. - * ---------------------------------------------------------------------------- - */ - -#ifndef YAGE_CORE_DRAWABLE_H -#define YAGE_CORE_DRAWABLE_H - -#include "spritebatch.h" - -namespace yage -{ - -class Drawable -{ -public: - virtual void draw(SpriteBatch &sp) = 0; -}; - -} // namespace yage - -#endif diff --git a/yage/render/ellipse.h b/yage/render/ellipse.h deleted file mode 100644 index 2a7552ba..00000000 --- a/yage/render/ellipse.h +++ /dev/null @@ -1,12 +0,0 @@ -/** --------------------------------------------------------------------------- - * @file: ellipse.h - * - * Copyright (c) 2017 Yann Herklotz Grave <ymherklotz@gmail.com> - * MIT License, see LICENSE file for more details. - * ---------------------------------------------------------------------------- - */ - -#ifndef YAGE_RENDER_ELLIPSE_H -#define YAGE_RENDER_ELLIPSE_H - -#endif diff --git a/yage/render/rectangle.cpp b/yage/render/rectangle.cpp deleted file mode 100644 index f48f79db..00000000 --- a/yage/render/rectangle.cpp +++ /dev/null @@ -1,46 +0,0 @@ -/** --------------------------------------------------------------------------- - * @file: rectangle.cpp - * - * Copyright (c) 2017 Yann Herklotz Grave <ymherklotz@gmail.com> - * MIT License, see LICENSE file for more details. - * ---------------------------------------------------------------------------- - */ - -#include "rectangle.h" - -#include "../data/vertex.h" - -#include <glad/glad.h> - -#include <cstddef> - -namespace yage -{ - -Rectangle::Rectangle(glm::vec4 position) : position_(position) {} - -void Rectangle::render() const -{ - // create vertex array - GLuint rect_vao, rect_vbo; - - // bind vertex array object - glGenVertexArrays(1, &rect_vao); - glBindVertexArray(rect_vao); - - // bind vertex buffer object - glGenBuffers(1, &rect_vbo); - glBindBuffer(GL_ARRAY_BUFFER, rect_vbo); - - // enable vertex attribute arrays - glEnableVertexAttribArray(0); - glEnableVertexAttribArray(1); - - // set the vertex attribute pointers - glVertexAttribPointer(0, 2, GL_FLOAT, GL_FALSE, sizeof(Vertex), - (void *)offsetof(Vertex, position)); - - glBindVertexArray(0); -} - -} // namepsace yage diff --git a/yage/render/rectangle.h b/yage/render/rectangle.h deleted file mode 100644 index bf87731b..00000000 --- a/yage/render/rectangle.h +++ /dev/null @@ -1,31 +0,0 @@ -/** --------------------------------------------------------------------------- - * @file: rectangle.h - * - * Copyright (c) 2017 Yann Herklotz Grave <ymherklotz@gmail.com> - * MIT License, see LICENSE file for more details. - * ---------------------------------------------------------------------------- - */ - -#ifndef YAGE_RENDER_RECTANGLE_H -#define YAGE_RENDER_RECTANGLE_H - -#include "shape.h" - -#include <glm/glm.hpp> - -namespace yage -{ - -class Rectangle : public Shape -{ -public: - Rectangle(glm::vec4 position); - virtual void render() const; - -private: - glm::vec4 position_; -}; - -} // namespace yage - -#endif diff --git a/yage/render/shape.h b/yage/render/shape.h deleted file mode 100644 index 0ac72ba8..00000000 --- a/yage/render/shape.h +++ /dev/null @@ -1,25 +0,0 @@ -/** --------------------------------------------------------------------------- - * @file: shape.h - * - * Copyright (c) 2017 Yann Herklotz Grave <ymherklotz@gmail.com> - * MIT License, see LICENSE file for more details. - * ---------------------------------------------------------------------------- - */ - -#ifndef YAGE_RENDER_SHAPE_H -#define YAGE_RENDER_SHAPE_H - -#include "drawable.h" - -namespace yage -{ - -class Shape : public Drawable -{ -public: - virtual void render() const; -}; - -} // namespace yage - -#endif diff --git a/yage/render/sprite.cpp b/yage/render/sprite.cpp deleted file mode 100644 index 98853c94..00000000 --- a/yage/render/sprite.cpp +++ /dev/null @@ -1,95 +0,0 @@ -/** --------------------------------------------------------------------------- - * @file: sprite.cpp - * - * Copyright (c) 2017 Yann Herklotz Grave <ymherklotz@gmail.com> - * MIT License, see LICENSE file for more details. - * ---------------------------------------------------------------------------- - */ - -#include "sprite.h" -#include "../core/resourcemanager.h" -#include "../data/vertex.h" - -#include <cstddef> - -namespace yage -{ - -Sprite::~Sprite() -{ - if (vbo_id_ != 0) { - glDeleteBuffers(1, &vbo_id_); - } -} - -void Sprite::init(float x, float y, float width, float height, - const std::string &texture_path) -{ - x_ = x; - y_ = y; - width_ = width; - height_ = height; - texture_ = ResourceManager::getTexture(texture_path); - - if (vbo_id_ == 0) { - glGenBuffers(1, &vbo_id_); - } - - Vertex vertex_data[6]; - - vertex_data[0].setPosition(x + width, y + height); - vertex_data[0].setUv(1.f, 1.f); - - vertex_data[1].setPosition(x, y + height); - vertex_data[1].setUv(0.f, 1.f); - - vertex_data[2].setPosition(x, y); - vertex_data[2].setUv(0.f, 0.f); - - vertex_data[3].setPosition(x, y); - vertex_data[3].setUv(0.f, 0.f); - - vertex_data[4].setPosition(x + width, y + height); - vertex_data[4].setUv(1.f, 1.f); - - vertex_data[5].setPosition(x + width, y); - vertex_data[5].setUv(1.f, 0.f); - - for (auto &i : vertex_data) { - i.setColour(255, 0, 255, 255); - } - - vertex_data[1].setColour(0, 255, 255, 255); - vertex_data[4].setColour(255, 0, 0, 255); - - glBindBuffer(GL_ARRAY_BUFFER, vbo_id_); - glBufferData(GL_ARRAY_BUFFER, sizeof(vertex_data), vertex_data, - GL_STATIC_DRAW); - glBindBuffer(GL_ARRAY_BUFFER, 0); -} - -void Sprite::draw() -{ - glBindTexture(GL_TEXTURE_2D, texture_.id); - glBindBuffer(GL_ARRAY_BUFFER, vbo_id_); - - glEnableVertexAttribArray(0); - glEnableVertexAttribArray(1); - glEnableVertexAttribArray(2); - - glVertexAttribPointer(0, 2, GL_FLOAT, GL_FALSE, sizeof(Vertex), - (void *)offsetof(Vertex, position)); - glVertexAttribPointer(1, 4, GL_UNSIGNED_BYTE, GL_TRUE, sizeof(Vertex), - (void *)offsetof(Vertex, colour)); - glVertexAttribPointer(2, 2, GL_FLOAT, GL_FALSE, sizeof(Vertex), - (void *)offsetof(Vertex, uv)); - glDrawArrays(GL_TRIANGLES, 0, 6); - - glDisableVertexAttribArray(2); - glDisableVertexAttribArray(1); - glDisableVertexAttribArray(0); - - glBindBuffer(GL_ARRAY_BUFFER, 0); -} - -} // namespace yage diff --git a/yage/render/sprite.h b/yage/render/sprite.h deleted file mode 100644 index 51821be5..00000000 --- a/yage/render/sprite.h +++ /dev/null @@ -1,49 +0,0 @@ -/** --------------------------------------------------------------------------- - * @file: sprite.h - * - * Copyright (c) 2017 Yann Herklotz Grave <ymherklotz@gmail.com> - * MIT License, see LICENSE file for more details. - * ---------------------------------------------------------------------------- - */ - -#ifndef SPRITE_H -#define SPRITE_H - -#include "../data/texture.h" - -#include <glad/glad.h> - -#include <string> - -namespace yage -{ - -/** @deprecated Use SpriteBatch instead - */ -class Sprite -{ -private: - float x_; - float y_; - float width_; - float height_; - GLuint vbo_id_ = 0; - Texture texture_; - -public: - Sprite() = default; - Sprite(const Sprite &) = delete; - Sprite(Sprite &&) = delete; - ~Sprite(); - - Sprite &operator=(const Sprite &) = delete; - Sprite &operator=(Sprite &&) = delete; - - void init(float x, float y, float width, float height, - const std::string &texture_path); - void draw(); -}; - -} // namespace yage - -#endif diff --git a/yage/render/spritebatch.h b/yage/render/spritebatch.h index fb9f6337..022a51c8 100644 --- a/yage/render/spritebatch.h +++ b/yage/render/spritebatch.h @@ -10,7 +10,6 @@ #define YAGE_SPRITE_BATCH_H #include "../data/vertex.h" -#include "batch.h" #include <glad/glad.h> #include <glm/glm.hpp> |