Add draw commands to support the texture atlas.
All checks were successful
Run ReCI Build Test / Explore-Gitea-Actions (push) Successful in 2m33s
All checks were successful
Run ReCI Build Test / Explore-Gitea-Actions (push) Successful in 2m33s
This commit is contained in:
@@ -29,6 +29,7 @@
|
||||
#include <JGL/types/Font.h>
|
||||
#include <JGL/types/VRamList.h>
|
||||
#include <JGL/types/VertexArray.h>
|
||||
#include <JGL/types/TextureAtlas.h>
|
||||
|
||||
// Fonts that are included by default.
|
||||
namespace JGL::Fonts {
|
||||
@@ -230,6 +231,10 @@ namespace JGL::J2D {
|
||||
void DrawSprite(const RenderTarget* render_target, const Vector2& position, float rad_rotation = 0, const Vector2& origin = Vector2(0 , 0),
|
||||
const Vector2& scale = Vector2(1, 1), const Color4& color = Colors::White, Direction inversion = Direction::None);
|
||||
|
||||
void DrawSprite(const TextureAtlas* texture_atlas, const AtlasRegion& atlas_region, const Vector2& position, float rad_rotation, const Vector2& origin = Vector2(0, 0),
|
||||
const Vector2& scale = Vector2(1, 1), const Color4& color = Colors::White);
|
||||
void DrawSprite(const TextureAtlas& texture_atlas, const AtlasRegion& atlas_region, const Vector2& position, float rad_rotation, const Vector2& origin = Vector2(0, 0),
|
||||
const Vector2& scale = Vector2(1, 1), const Color4& color = Colors::White);
|
||||
/// Draws a sprite to the screen by passing a G̶L̶u̶i̶n̶t̶ JGL Texture that represents a handle to a loaded texture.
|
||||
/// @param texture A texture instance to be displayed.
|
||||
/// @param position The point at which to draw the sprite (from the top-left down).
|
||||
|
@@ -2,18 +2,16 @@
|
||||
|
||||
#include <JGL/types/Texture.h>
|
||||
|
||||
// A texture which actually contains multiple such that you can pass it in to draw sprite or draw partial sprite.
|
||||
// It also makes for more efficient sprite batch because you don't have to swap textures between.
|
||||
|
||||
namespace JGL {
|
||||
struct AtlasRegion {
|
||||
Vector2i position = { 0, 0 };
|
||||
Vector2i size = { 0, 0 };
|
||||
};
|
||||
|
||||
class TextureAtlas;
|
||||
}
|
||||
|
||||
// A texture which actually contains multiple such that you can pass it in to draw sprite or draw partial sprite.
|
||||
// It also makes for more efficient sprite batch because you don't have to swap textures between.
|
||||
class JGL::TextureAtlas : public Texture {
|
||||
protected:
|
||||
std::vector<AtlasRegion> regions;
|
||||
@@ -32,5 +30,6 @@ public:
|
||||
/// @param size The size of the image.
|
||||
/// @param regions The individual regions that will make up your atlas.
|
||||
/// @param region_count The number of regions there are.
|
||||
TextureAtlas(const Color4* pixels, const Vector2i& size, AtlasRegion** regions, unsigned int region_count, FilteringMode filtering_mode = FilteringMode::NEAREST);
|
||||
TextureAtlas(const Color4* pixels, const Vector2i& size, AtlasRegion** regions, unsigned int region_count, FilteringMode filtering_mode = FilteringMode::NEAREST, SampleRate anisotropy = SampleRate::NONE);
|
||||
~TextureAtlas() = default;
|
||||
};
|
@@ -1075,3 +1075,11 @@ void J2D::FillEllipse(const Color4& color, const Vector2& position, float radius
|
||||
glDrawArrays(GL_TRIANGLE_FAN, 0, (int) vertices.size());
|
||||
glColor4fv(default_state.draw_color);
|
||||
}
|
||||
|
||||
void J2D::DrawSprite(const TextureAtlas* texture_atlas, const AtlasRegion& atlas_region, const Vector2& position, float rad_rotation, const Vector2& origin, const Vector2& scale, const Color4& color) {
|
||||
J2D::DrawPartialSprite(texture_atlas, position, Vector2(atlas_region.position), Vector2(atlas_region.size), rad_rotation, origin, scale, color);
|
||||
}
|
||||
|
||||
void J2D::DrawSprite(const TextureAtlas& texture_atlas, const AtlasRegion& atlas_region, const Vector2& position, float rad_rotation, const Vector2& origin, const Vector2& scale, const Color4& color) {
|
||||
J2D::DrawSprite(&texture_atlas, atlas_region, position, rad_rotation, origin, scale, color);
|
||||
}
|
||||
|
@@ -55,7 +55,7 @@ TextureAtlas::TextureAtlas(const Color4** pixels, const Vector2i** sizes, unsign
|
||||
operator delete(result);
|
||||
}
|
||||
|
||||
TextureAtlas::TextureAtlas(const Color4* pixels, const Vector2i& size, AtlasRegion** regions, unsigned int region_count, FilteringMode filtering_mode) : Texture(pixels, size, filtering_mode) {
|
||||
TextureAtlas::TextureAtlas(const Color4* pixels, const Vector2i& size, AtlasRegion** regions, unsigned int region_count, FilteringMode filtering_mode, SampleRate anisotropy) : Texture(pixels, size, filtering_mode, anisotropy) {
|
||||
this->regions.resize(region_count);
|
||||
for (unsigned int i = 0; i < region_count; ++i)
|
||||
this->regions[i] = *regions[i];
|
||||
|
Reference in New Issue
Block a user