added 2d png support
This commit is contained in:
@@ -32,6 +32,7 @@ public:
|
||||
~Point();
|
||||
|
||||
void set(const float &t_x, const float &t_y);
|
||||
void rotate(const float &t_angle, const float &t_x, const float &t_y);
|
||||
void set(const Point &v);
|
||||
const void print() const;
|
||||
};
|
||||
|
||||
@@ -17,6 +17,13 @@
|
||||
#include "./texture_link.hpp"
|
||||
#include "../include/utils/debug.hpp"
|
||||
#include <vector>
|
||||
#include <gs_psm.h>
|
||||
|
||||
enum TextureType
|
||||
{
|
||||
TEX_TYPE_RGB = GS_PSM_24, // BMP
|
||||
TEX_TYPE_RGBA = GS_PSM_32 // PNG
|
||||
};
|
||||
|
||||
/**
|
||||
* Class which contains texture data.
|
||||
@@ -46,15 +53,17 @@ public:
|
||||
|
||||
const u8 &getHeight() const { return height; };
|
||||
|
||||
const TextureType &getType() const { return _type; };
|
||||
|
||||
u32 getTextureLinksCount() const { return static_cast<u32>(texLinks.size()); };
|
||||
|
||||
texwrap_t *getWrapSettings() { return &wrapSettings; };
|
||||
|
||||
/**
|
||||
* Returns always width * width * 3.
|
||||
* 3 because of RGB
|
||||
* Returns always width * width * 3/4.
|
||||
* 3 for RGB, 4 for RGBA.
|
||||
*/
|
||||
u32 getDataSize() const { return width * height * 3; };
|
||||
u32 getDataSize() const { return _type == TEX_TYPE_RGB ? width * height * 3 : width * height * 4; };
|
||||
|
||||
/**
|
||||
* Texture data, used by renderer.
|
||||
@@ -83,6 +92,12 @@ public:
|
||||
return -1;
|
||||
};
|
||||
|
||||
/**
|
||||
* Returns index of link.
|
||||
* -1 if not found.
|
||||
*/
|
||||
inline const s32 getIndexOfLink(const u32 &t_spriteId) const { return getIndexOfLink(t_spriteId, 0); };
|
||||
|
||||
// ----
|
||||
// Setters
|
||||
// ----
|
||||
@@ -92,7 +107,7 @@ public:
|
||||
* Do not call this method unless you know what you do.
|
||||
* Should be called by data loader.
|
||||
*/
|
||||
void setSize(const u8 &t_width, const u8 &t_height);
|
||||
void setSize(const u8 &t_width, const u8 &t_height, const TextureType &t_type);
|
||||
|
||||
/**
|
||||
* Do not call this method unless you know what you do.
|
||||
@@ -101,8 +116,8 @@ public:
|
||||
void setHeight(const u8 &t_val) { height = t_val; }
|
||||
|
||||
/**
|
||||
* Set texture name.
|
||||
* Should be the file name without extension
|
||||
* Do not call this method unless you know what you do.
|
||||
* Should be called by data loader.
|
||||
*/
|
||||
void setData(const u32 &t_index, const unsigned char &t_val) { data[t_index] = t_val; }
|
||||
|
||||
@@ -119,9 +134,12 @@ public:
|
||||
// Other
|
||||
// ----
|
||||
|
||||
/** Assign texture to mesh and mesh material */
|
||||
/** Assign texture to mesh and mesh material. */
|
||||
void addLink(const u32 &t_meshId, const u32 &t_materialId);
|
||||
|
||||
/** Assign texture to sprite. */
|
||||
void addLink(const u32 &t_spriteId);
|
||||
|
||||
const u8 &isNameSet() const { return _isNameSet; };
|
||||
|
||||
const u8 &isSizeSet() const { return _isSizeSet; };
|
||||
@@ -135,13 +153,31 @@ public:
|
||||
return false;
|
||||
};
|
||||
|
||||
void removeLink(const u32 &t_index) { texLinks.erase(texLinks.begin() + t_index); }
|
||||
const u8 isLinkedWith(const u32 &t_spriteId) const
|
||||
{
|
||||
s32 index = getIndexOfLink(t_spriteId);
|
||||
if (index != -1)
|
||||
return true;
|
||||
else
|
||||
return false;
|
||||
};
|
||||
|
||||
void removeLink(const u32 &t_meshId, const u32 &t_materialId)
|
||||
void removeLinkByIndex(const u32 &t_index) { texLinks.erase(texLinks.begin() + t_index); }
|
||||
|
||||
void removeLinkBySprite(const u32 &t_spriteId)
|
||||
{
|
||||
s32 index = getIndexOfLink(t_spriteId);
|
||||
if (index != -1)
|
||||
removeLinkByIndex(index);
|
||||
else
|
||||
PRINT_ERR("Cant remove link, because it was not found!");
|
||||
}
|
||||
|
||||
void removeLinkByMesh(const u32 &t_meshId, const u32 &t_materialId)
|
||||
{
|
||||
s32 index = getIndexOfLink(t_meshId, t_materialId);
|
||||
if (index != -1)
|
||||
removeLink(index);
|
||||
removeLinkByIndex(index);
|
||||
else
|
||||
PRINT_ERR("Cant remove link, because it was not found!");
|
||||
}
|
||||
@@ -150,6 +186,7 @@ private:
|
||||
void setDefaultWrapSettings();
|
||||
texwrap_t wrapSettings;
|
||||
char *name;
|
||||
TextureType _type;
|
||||
std::vector<TextureLink> texLinks;
|
||||
u32 id;
|
||||
u8 width, height, _isNameSet, _isSizeSet;
|
||||
|
||||
@@ -0,0 +1,67 @@
|
||||
/*
|
||||
# ______ ____ ___
|
||||
# | \/ ____| |___|
|
||||
# | | | \ | |
|
||||
#-----------------------------------------------------------------------
|
||||
# Copyright 2020, tyra - https://github.com/h4570/tyra
|
||||
# Licenced under Apache License 2.0
|
||||
# Sandro Sobczyński <sandro.sobczynski@gmail.com>
|
||||
*/
|
||||
|
||||
#ifndef _TYRA_SPRITE_
|
||||
#define _TYRA_SPRITE_
|
||||
|
||||
#include <models/math/point.hpp>
|
||||
#include <draw_types.h>
|
||||
#include <draw_buffers.h>
|
||||
|
||||
/**
|
||||
* Class which have contain 2D image data.
|
||||
*/
|
||||
class Sprite
|
||||
{
|
||||
|
||||
public:
|
||||
Sprite();
|
||||
~Sprite();
|
||||
|
||||
Point position, size;
|
||||
float scale;
|
||||
color_t color;
|
||||
clutbuffer_t clut;
|
||||
|
||||
// ----
|
||||
// Getters
|
||||
// ----
|
||||
|
||||
/** Auto generated unique Id. */
|
||||
inline const u32 &getId() const { return id; };
|
||||
|
||||
// ----
|
||||
// Setters
|
||||
// ----
|
||||
|
||||
// ----
|
||||
// Other
|
||||
// ----
|
||||
|
||||
/** Flip texture horizontally. */
|
||||
inline void flipHorizontally(const u8 &t_set) { _flipH = t_set; };
|
||||
|
||||
/** Flip texture vertically. */
|
||||
inline void flipVertically(const u8 &t_set) { _flipV = t_set; };
|
||||
|
||||
/** Check if texture is vertically flipped. */
|
||||
inline const u8 &isFlippedVertically() const { return _flipV; };
|
||||
|
||||
/** Check if texture is horizontally flipped. */
|
||||
inline const u8 &isFlippedHorizontally() const { return _flipH; };
|
||||
|
||||
private:
|
||||
u32 id;
|
||||
u8 _isSizeSet, _flipH, _flipV;
|
||||
void setDefaultColor();
|
||||
void setDefaultLODAndClut();
|
||||
};
|
||||
|
||||
#endif
|
||||
@@ -15,7 +15,10 @@
|
||||
|
||||
struct TextureLink
|
||||
{
|
||||
u32 meshId, materialId;
|
||||
/** Mesh id or sprite id */
|
||||
u32 meshId;
|
||||
/** Mesh material id or 0 if is sprite */
|
||||
u32 materialId;
|
||||
};
|
||||
|
||||
#endif
|
||||
|
||||
Reference in New Issue
Block a user