diff options
author | Yann Herklotz <ymherklotz@gmail.com> | 2017-12-25 13:54:09 +0000 |
---|---|---|
committer | Yann Herklotz <ymherklotz@gmail.com> | 2017-12-25 13:54:09 +0000 |
commit | f949692714e72a0e2d45ebb6a5d698424ab71dee (patch) | |
tree | cfab638d8c4d35c297e981773cfee1a9af3490ee /yage | |
parent | 022a4bdd81332ce67d799be6a06afb42ae45ac2e (diff) | |
download | YAGE-f949692714e72a0e2d45ebb6a5d698424ab71dee.tar.gz YAGE-f949692714e72a0e2d45ebb6a5d698424ab71dee.zip |
[Broken] Reorganising and fixing.
Diffstat (limited to 'yage')
-rw-r--r-- | yage/data/input.h (renamed from yage/core/input.h) | 0 | ||||
-rw-r--r-- | yage/data/renderbatch.h | 17 | ||||
-rw-r--r-- | yage/data/texture.h (renamed from yage/core/texture.h) | 0 | ||||
-rw-r--r-- | yage/data/vertex.h (renamed from yage/core/vertex.h) | 0 | ||||
-rw-r--r-- | yage/render/batch.h | 39 | ||||
-rw-r--r-- | yage/render/drawable.h | 15 | ||||
-rw-r--r-- | yage/render/ellipse.h | 6 | ||||
-rw-r--r-- | yage/render/glslprogram.cpp (renamed from yage/core/glslprogram.cpp) | 0 | ||||
-rw-r--r-- | yage/render/glslprogram.h (renamed from yage/core/glslprogram.h) | 0 | ||||
-rw-r--r-- | yage/render/rectangle.h | 15 | ||||
-rw-r--r-- | yage/render/shape.h | 16 | ||||
-rw-r--r-- | yage/render/sprite.cpp (renamed from yage/core/sprite.cpp) | 0 | ||||
-rw-r--r-- | yage/render/sprite.h (renamed from yage/core/sprite.h) | 0 | ||||
-rw-r--r-- | yage/render/spritebatch.cpp (renamed from yage/core/spritebatch.cpp) | 2 | ||||
-rw-r--r-- | yage/render/spritebatch.h (renamed from yage/core/spritebatch.h) | 28 |
15 files changed, 113 insertions, 25 deletions
diff --git a/yage/core/input.h b/yage/data/input.h index 866793d8..866793d8 100644 --- a/yage/core/input.h +++ b/yage/data/input.h diff --git a/yage/data/renderbatch.h b/yage/data/renderbatch.h new file mode 100644 index 00000000..0d034035 --- /dev/null +++ b/yage/data/renderbatch.h @@ -0,0 +1,17 @@ +#ifndef YAGE_CORE_RENDERBATCH_H +#define YAGE_CORE_RENDERBATCH_H + +#include <glad/glad.h> + +struct RenderBatch { + GLint offset; + GLsizei num_vertices; + GLuint texture; + + RenderBatch(GLint offset_i, GLsizei num_vertices_i, GLuint texture_i) + : offset(offset_i), num_vertices(num_vertices_i), texture(texture_i = 0) + { + } +}; + +#endif diff --git a/yage/core/texture.h b/yage/data/texture.h index aec7b906..aec7b906 100644 --- a/yage/core/texture.h +++ b/yage/data/texture.h diff --git a/yage/core/vertex.h b/yage/data/vertex.h index 4cd095a9..4cd095a9 100644 --- a/yage/core/vertex.h +++ b/yage/data/vertex.h diff --git a/yage/render/batch.h b/yage/render/batch.h new file mode 100644 index 00000000..e301531c --- /dev/null +++ b/yage/render/batch.h @@ -0,0 +1,39 @@ +#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 draw(); + virtual void render(); + +protected: +}; + +} // namespace yage + +#endif diff --git a/yage/render/drawable.h b/yage/render/drawable.h new file mode 100644 index 00000000..0e4b6843 --- /dev/null +++ b/yage/render/drawable.h @@ -0,0 +1,15 @@ +#ifndef YAGE_CORE_DRAWABLE_H +#define YAGE_CORE_DRAWABLE_H + +namespace yage +{ + +class Drawable +{ +public: + virtual void render() const; +}; + +} // namespace yage + +#endif diff --git a/yage/render/ellipse.h b/yage/render/ellipse.h new file mode 100644 index 00000000..bd0b0d3e --- /dev/null +++ b/yage/render/ellipse.h @@ -0,0 +1,6 @@ +#ifndef YAGE_RENDER_ELLIPSE_H +#define YAGE_RENDER_ELLIPSE_H + + + +#endif diff --git a/yage/core/glslprogram.cpp b/yage/render/glslprogram.cpp index 13abbba3..13abbba3 100644 --- a/yage/core/glslprogram.cpp +++ b/yage/render/glslprogram.cpp diff --git a/yage/core/glslprogram.h b/yage/render/glslprogram.h index 0617bc1e..0617bc1e 100644 --- a/yage/core/glslprogram.h +++ b/yage/render/glslprogram.h diff --git a/yage/render/rectangle.h b/yage/render/rectangle.h new file mode 100644 index 00000000..11df8a18 --- /dev/null +++ b/yage/render/rectangle.h @@ -0,0 +1,15 @@ +#ifndef YAGE_RENDER_RECTANGLE_H +#define YAGE_RENDER_RECTANGLE_H + +#include "shape.h" + +namespace yage { + +class Rectangle +{ + virtual void render() const; +}; + +} // namespace yage + +#endif diff --git a/yage/render/shape.h b/yage/render/shape.h new file mode 100644 index 00000000..bdf318ed --- /dev/null +++ b/yage/render/shape.h @@ -0,0 +1,16 @@ +#ifndef YAGE_RENDER_SHAPE_H +#define YAGE_RENDER_SHAPE_H + +#include "drawable.h" + +namespace yage +{ + +class Shape : public Drawable +{ + virtual void render() const; +}; + +} // namespace yage + +#endif diff --git a/yage/core/sprite.cpp b/yage/render/sprite.cpp index 6862f910..6862f910 100644 --- a/yage/core/sprite.cpp +++ b/yage/render/sprite.cpp diff --git a/yage/core/sprite.h b/yage/render/sprite.h index 852f4f28..852f4f28 100644 --- a/yage/core/sprite.h +++ b/yage/render/sprite.h diff --git a/yage/core/spritebatch.cpp b/yage/render/spritebatch.cpp index 2159aeec..d65340d7 100644 --- a/yage/core/spritebatch.cpp +++ b/yage/render/spritebatch.cpp @@ -6,7 +6,7 @@ * ---------------------------------------------------------------------------- */ -#include <yage/core/spritebatch.h> +#include "spritebatch.h" #include <algorithm> #include <stdexcept> diff --git a/yage/core/spritebatch.h b/yage/render/spritebatch.h index c16b44f6..c018bdc6 100644 --- a/yage/core/spritebatch.h +++ b/yage/render/spritebatch.h @@ -6,17 +6,14 @@ * ---------------------------------------------------------------------------- */ -/** @file - */ - #ifndef YAGE_SPRITE_BATCH_H #define YAGE_SPRITE_BATCH_H +#include "batch.h" #include "vertex.h" #include <glad/glad.h> #include <glm/glm.hpp> -#include <yage/math/matrix.h> #include <vector> @@ -50,24 +47,8 @@ public: Vertex bottom_left() const { return bottom_left_; } }; -class RenderBatch -{ - friend SpriteBatch; - -private: - GLsizei num_vertices_; - GLint offset_; - GLuint texture_; - -public: - RenderBatch(GLint offset, GLsizei num_vertices, GLuint texture); - - GLint offset() const { return offset_; } - GLsizei num_vertices() const { return num_vertices_; } - GLuint texture() const { return texture_; } -}; -class SpriteBatch +class SpriteBatch : public Batch { public: static const int NUM_VERTICES = 6; @@ -93,9 +74,8 @@ public: void end(); // adds a sprite to the sprite batch to be rendered later - void draw(const yage::Vector4f &destination_rect, - const yage::Vector4f &uv_rect, GLuint texture, - const Colour &colour, float depth); + void draw(const glm::vec4 &destination_rect, const glm::vec4 &uv_rect, + GLuint texture, const Colour &colour, float depth); // render the batch void render(); |