Pass Renderer2D to Renderable and have each subclass of Renderable decide what the Renderer should do (like drawText(), drawRect() etc). This makes the Renderable more flexible. right now, each renderable has a texture, vertices and indices. but what if some renderables does not use textures? or more than one? What if some renderables are just a group of other renderables? (Scene Graph's). If we instead just make Renderables implement render(Renderer2D& r) interface. we can make each renderable pass the data it holds to the renderer without a hard defined interface.
49 lines
941 B
C++
49 lines
941 B
C++
|
|
#ifndef SPECTRE_GRAPHICS_SPRITE_H
|
|
#define SPECTRE_GRAPHICS_SPRITE_H
|
|
|
|
#include <Spectre/Math/Color.h>
|
|
#include "Vertex2D.h"
|
|
#include "Renderable.h"
|
|
|
|
class Texture;
|
|
|
|
class Sprite : public Renderable2D
|
|
{
|
|
public :
|
|
Sprite();
|
|
|
|
Sprite(const vec2f& pos, const vec2f& size);
|
|
|
|
void init();
|
|
|
|
void setSize(vec2f size);
|
|
|
|
void setColor(const Color& color);
|
|
|
|
void setTexture(const Texture& texture);
|
|
|
|
void setTextureCoords(const vec2u& pos, const vec2u& size);
|
|
|
|
virtual const Texture* getTexture() const;
|
|
|
|
virtual const std::vector<Vertex2D>& getVertices() const;
|
|
|
|
virtual const std::vector<unsigned short>& getIndices() const;
|
|
|
|
virtual const RenderType getRenderType() const { return RenderType_Scene; };
|
|
|
|
virtual void render(Renderer2D& renderer) const;
|
|
|
|
protected :
|
|
|
|
void updateGeometry();
|
|
|
|
std::vector<unsigned short> m_indicies;
|
|
|
|
std::vector<Vertex2D> m_vertices;
|
|
|
|
const Texture* m_texture;
|
|
};
|
|
|
|
#endif /* SPECTRE_GRAPHICS_SPRITE_H */
|