added 2d png support

This commit is contained in:
h4570
2020-12-01 17:26:10 +01:00
parent 3841487388
commit 510199164c
17 changed files with 317 additions and 80 deletions
+5 -4
View File
@@ -17,6 +17,7 @@
#include "gif_sender.hpp"
#include "vif_sender.hpp"
#include "../models/math/plane.hpp"
#include "../models/sprite.hpp"
#include "../models/screen_settings.hpp"
#include "../models/render_data.hpp"
#include "./texture_repository.hpp"
@@ -39,6 +40,8 @@ public:
/// --- Draw: PATH3
void draw(Sprite &t_sprite);
/**
* Draw many meshes with lighting information.
* Slowest way of rendering (PATH 3, using EE and GIF).
@@ -103,14 +106,12 @@ public:
TextureRepository *getTextureRepository() { return &textureRepo; };
void drawRectangle();
private:
void changeTexture(const Mesh &t_mesh, u32 t_materialId);
void changeTexture(MeshTexture *t_tex);
u32 lastTextureId;
texbuffer_t textureBuffer;
u8 isTextureVRAMAllocated, isVSyncEnabled;
void allocateTextureBuffer(u16 t_width, u16 t_height);
void allocateTextureBuffer(MeshTexture *t_texture);
void deallocateTextureBuffer();
void flipBuffers();
void beginFrameIfNeeded();
@@ -17,6 +17,13 @@
#include "../models/mesh.hpp"
#include "../models/mesh_frame.hpp"
#include "../loaders/bmp_loader.hpp"
#include "../loaders/png_loader.hpp"
enum TextureFormat
{
BMP,
PNG
};
/** Class responsible for intializing draw env, textures and buffers */
class TextureRepository
@@ -35,6 +42,18 @@ public:
u32 getTexturesCount() const { return static_cast<u32>(textures.size()); };
/**
* Returns single texture.
* NULL if not found.
*/
MeshTexture *getBySprite(const u32 &t_spriteId)
{
for (u32 i = 0; i < textures.size(); i++)
if (textures[i]->isLinkedWith(t_spriteId))
return textures[i];
return NULL;
}
/**
* Returns single texture.
* NULL if not found.
@@ -79,20 +98,22 @@ public:
// Other
// ----
/** Add unlinked texture.
* NOTICE: BMP (RGB 888 24bit, without color information) is suppored only!
/**
* Add unlinked texture.
* @param t_subfolder Relative path. Ex.: "textures/"
* @param t_name Filename without extension. Ex.: "water"
*
* @param t_format if you want to use BMP, be sure that you have
* BMP with RGB 888 24bit, without color information.
*/
MeshTexture *add(char *t_subfolder, char *t_name);
MeshTexture *add(char *t_subfolder, char *t_name, TextureFormat t_format);
/**
* Add linked textures in given subpath for mesh material names.
* NOTICE: BMP (RGB 888 24bit, without color information) is suppored only!
* @param t_path Relative path where textures should be searched
* @param t_path Relative path where textures should be searched.
* @param t_format if you want to use BMP, be sure that you have
* BMP with RGB 888 24bit, without color information.
*/
void addByMesh(char *t_path, Mesh &mesh);
void addByMesh(char *t_path, Mesh &mesh, TextureFormat t_format);
/**
* Remove texture from repository.
@@ -115,7 +136,8 @@ public:
private:
std::vector<MeshTexture *> textures;
BmpLoader loader;
BmpLoader bmpLoader;
PngLoader pngLoader;
};
#endif