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
|
||||
|
||||
@@ -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
|
||||
|
||||
@@ -50,10 +50,8 @@ void BmpLoader::load(MeshTexture &o_texture, char *t_subfolder, char *t_name, ch
|
||||
|
||||
u32 width = (u32)header[18];
|
||||
u32 height = (u32)header[22];
|
||||
o_texture.setSize(width, height);
|
||||
o_texture.setSize(width, height, TEX_TYPE_RGB);
|
||||
printf("BMPLoader - width: %d | height: %d\n", width, height);
|
||||
if (width > 128 || height > 128)
|
||||
PRINT_ERR("Given texture is big for PS2. Please strict to 128x128 max");
|
||||
|
||||
u64 rowPadded = (width * 3 + 3) & (~3);
|
||||
|
||||
|
||||
@@ -9,6 +9,7 @@
|
||||
*/
|
||||
|
||||
#include "../../include/models/math/point.hpp"
|
||||
#include "../../include/utils/math.hpp"
|
||||
|
||||
#include <stdio.h>
|
||||
|
||||
@@ -55,6 +56,21 @@ void Point::set(const Point &v)
|
||||
y = v.y;
|
||||
}
|
||||
|
||||
void Point::rotate(const float &t_angle, const float &t_x, const float &t_y)
|
||||
{
|
||||
float s = Math::sin(t_angle);
|
||||
float c = Math::cos(t_angle);
|
||||
|
||||
x -= t_x;
|
||||
y -= t_y;
|
||||
|
||||
float xnew = x * c - y * s;
|
||||
float ynew = x * s + y * c;
|
||||
|
||||
x = xnew + t_x;
|
||||
y = ynew + t_y;
|
||||
}
|
||||
|
||||
const void Point::print() const
|
||||
{
|
||||
printf("Point(%f, %f)\n", x, y);
|
||||
|
||||
@@ -39,15 +39,18 @@ MeshTexture::~MeshTexture()
|
||||
// Methods
|
||||
// ----
|
||||
|
||||
void MeshTexture::setSize(const u8 &t_width, const u8 &t_height)
|
||||
void MeshTexture::setSize(const u8 &t_width, const u8 &t_height, const TextureType &t_type)
|
||||
{
|
||||
if (_isSizeSet)
|
||||
{
|
||||
PRINT_ERR("Can't set size, because was already set!");
|
||||
return;
|
||||
}
|
||||
if (t_width > 256 || t_height > 256)
|
||||
PRINT_ERR("Given texture can be too big for PS2. Please strict to 256x256 max. Prefer 128x128.");
|
||||
width = t_width;
|
||||
height = t_height;
|
||||
_type = t_type;
|
||||
data = new unsigned char[getDataSize()];
|
||||
_isSizeSet = true;
|
||||
}
|
||||
@@ -86,3 +89,11 @@ void MeshTexture::addLink(const u32 &t_meshId, const u32 &t_materialId)
|
||||
link.meshId = t_meshId;
|
||||
texLinks.push_back(link);
|
||||
}
|
||||
|
||||
void MeshTexture::addLink(const u32 &t_spriteId)
|
||||
{
|
||||
TextureLink link;
|
||||
link.materialId = 0;
|
||||
link.meshId = t_spriteId;
|
||||
texLinks.push_back(link);
|
||||
}
|
||||
|
||||
@@ -0,0 +1,55 @@
|
||||
/*
|
||||
# ______ ____ ___
|
||||
# | \/ ____| |___|
|
||||
# | | | \ | |
|
||||
#-----------------------------------------------------------------------
|
||||
# Copyright 2020, tyra - https://github.com/h4570/tyra
|
||||
# Licenced under Apache License 2.0
|
||||
# Sandro Sobczyński <sandro.sobczynski@gmail.com>
|
||||
*/
|
||||
|
||||
#include "../include/models/sprite.hpp"
|
||||
#include "../include/utils/debug.hpp"
|
||||
#include "../include/utils/string.hpp"
|
||||
#include <cstdlib>
|
||||
|
||||
// ----
|
||||
// Constructors/Destructors
|
||||
// ----
|
||||
|
||||
Sprite::Sprite()
|
||||
{
|
||||
id = rand() % 1000000;
|
||||
_isSizeSet = false;
|
||||
_flipH = false;
|
||||
_flipV = false;
|
||||
scale = 1.0F;
|
||||
setDefaultColor();
|
||||
setDefaultLODAndClut();
|
||||
}
|
||||
|
||||
Sprite::~Sprite() {}
|
||||
|
||||
// ----
|
||||
// Methods
|
||||
// ----
|
||||
|
||||
/** Set's default object color + no transparency */
|
||||
void Sprite::setDefaultColor()
|
||||
{
|
||||
color.r = 0x80;
|
||||
color.g = 0x80;
|
||||
color.b = 0x80;
|
||||
color.a = 0x80;
|
||||
color.q = 0.0F;
|
||||
}
|
||||
|
||||
/** Sets texture level of details settings and CLUT settings */
|
||||
void Sprite::setDefaultLODAndClut()
|
||||
{
|
||||
clut.storage_mode = CLUT_STORAGE_MODE1;
|
||||
clut.start = 0;
|
||||
clut.psm = 0;
|
||||
clut.load_method = CLUT_NO_LOAD;
|
||||
clut.address = 0;
|
||||
}
|
||||
@@ -59,16 +59,16 @@ Renderer::~Renderer() {}
|
||||
// ----
|
||||
|
||||
/** Configure and allocate vRAM for texture buffer */
|
||||
void Renderer::allocateTextureBuffer(u16 t_width, u16 t_height)
|
||||
void Renderer::allocateTextureBuffer(MeshTexture *t_texture)
|
||||
{
|
||||
textureBuffer.width = t_width;
|
||||
textureBuffer.psm = GS_PSM_24;
|
||||
textureBuffer.address = graph_vram_allocate(t_width, t_height, GS_PSM_24, GRAPH_ALIGN_BLOCK);
|
||||
textureBuffer.width = t_texture->getWidth();
|
||||
textureBuffer.psm = t_texture->getType();
|
||||
textureBuffer.info.components = textureBuffer.psm == TEX_TYPE_RGBA ? TEXTURE_COMPONENTS_RGBA : TEXTURE_COMPONENTS_RGB;
|
||||
textureBuffer.address = graph_vram_allocate(t_texture->getWidth(), t_texture->getHeight(), textureBuffer.psm, GRAPH_ALIGN_BLOCK);
|
||||
if (textureBuffer.address <= 1)
|
||||
PRINT_ERR("Texture buffer allocation error. No memory!");
|
||||
textureBuffer.info.width = draw_log2(t_width);
|
||||
textureBuffer.info.height = draw_log2(t_height);
|
||||
textureBuffer.info.components = TEXTURE_COMPONENTS_RGB;
|
||||
textureBuffer.info.width = draw_log2(t_texture->getWidth());
|
||||
textureBuffer.info.height = draw_log2(t_texture->getHeight());
|
||||
textureBuffer.info.function = TEXTURE_FUNCTION_MODULATE;
|
||||
isTextureVRAMAllocated = true;
|
||||
}
|
||||
@@ -83,47 +83,47 @@ void Renderer::deallocateTextureBuffer()
|
||||
}
|
||||
}
|
||||
|
||||
void Renderer::changeTexture(const Mesh &t_mesh, u32 t_materialId)
|
||||
void Renderer::changeTexture(MeshTexture *t_tex)
|
||||
{
|
||||
|
||||
MeshTexture *tex = textureRepo.getByMesh(t_mesh.getId(), t_materialId);
|
||||
if (tex != NULL)
|
||||
if (t_tex != NULL)
|
||||
{
|
||||
if (tex->getId() != lastTextureId)
|
||||
if (t_tex->getId() != lastTextureId)
|
||||
{
|
||||
lastTextureId = tex->getId();
|
||||
lastTextureId = t_tex->getId();
|
||||
deallocateTextureBuffer();
|
||||
allocateTextureBuffer(tex->getWidth(), tex->getHeight());
|
||||
GifSender::sendTexture(*tex, &textureBuffer);
|
||||
allocateTextureBuffer(t_tex);
|
||||
GifSender::sendTexture(*t_tex, &textureBuffer);
|
||||
}
|
||||
}
|
||||
else
|
||||
PRINT_ERR("Texture was not found in texture repository!");
|
||||
}
|
||||
|
||||
void Renderer::drawRectangle()
|
||||
void Renderer::draw(Sprite &t_sprite)
|
||||
{
|
||||
texrect_t rect;
|
||||
rect.t0.s = t_sprite.isFlippedHorizontally() ? 128.0F : 0.0F;
|
||||
rect.t0.t = t_sprite.isFlippedVertically() ? 128.0F : 0.0F;
|
||||
rect.t1.s = t_sprite.isFlippedHorizontally() ? 0.0F : 128.0F;
|
||||
rect.t1.t = t_sprite.isFlippedVertically() ? 0.0F : 128.0F;
|
||||
rect.color.r = t_sprite.color.r;
|
||||
rect.color.g = t_sprite.color.g;
|
||||
rect.color.b = t_sprite.color.b;
|
||||
rect.color.a = t_sprite.color.a;
|
||||
rect.color.q = 0;
|
||||
rect.v0.x = t_sprite.position.x;
|
||||
rect.v0.y = t_sprite.position.y;
|
||||
rect.v0.z = (u32)-1;
|
||||
rect.v1.x = (t_sprite.size.x * t_sprite.scale) + t_sprite.position.x;
|
||||
rect.v1.y = (t_sprite.size.y * t_sprite.scale) + t_sprite.position.y;
|
||||
rect.v1.z = (u32)-1;
|
||||
beginFrameIfNeeded();
|
||||
packet2_t *packet2 = packet2_create(20, P2_TYPE_NORMAL, P2_MODE_NORMAL, 0);
|
||||
changeTexture(textureRepo.getBySprite(t_sprite.getId()));
|
||||
packet2_t *packet2 = packet2_create(12, P2_TYPE_NORMAL, P2_MODE_NORMAL, 0);
|
||||
packet2_update(packet2, draw_primitive_xyoffset(packet2->next, 0, 2048, 2048));
|
||||
|
||||
int loop0 = 10;
|
||||
|
||||
packet2_add_s64(packet2, GIF_SET_TAG(4, 0, 0, 0, GIF_FLG_PACKED, 1));
|
||||
packet2_add_s64(packet2, GIF_REG_AD);
|
||||
|
||||
packet2_add_s64(packet2, GIF_SET_PRIM(6, 0, 0, 0, 0, 0, 0, 0, 0));
|
||||
packet2_add_s64(packet2, GIF_REG_PRIM);
|
||||
|
||||
packet2_add_s64(packet2, GIF_SET_RGBAQ((loop0 * 10), 0, 255 - (loop0 * 10), 0x80, 0x3F800000));
|
||||
packet2_add_s64(packet2, GIF_REG_RGBAQ);
|
||||
|
||||
packet2_add_s64(packet2, GIF_SET_XYZ(((loop0 * 20) << 4) + (2048 << 4), ((loop0 * 10) << 4) + (2048 << 4), -128));
|
||||
packet2_add_s64(packet2, GIF_REG_XYZ2);
|
||||
|
||||
packet2_add_s64(packet2, GIF_SET_XYZ((((loop0 * 20) + 100) << 4) + (2048 << 4), (((loop0 * 10) + 100) << 4) + (2048 << 4), -128));
|
||||
packet2_add_s64(packet2, GIF_REG_XYZ2);
|
||||
|
||||
packet2_utils_gif_add_set(packet2, 1);
|
||||
packet2_utils_gs_add_texbuff_clut(packet2, &textureBuffer, &t_sprite.clut);
|
||||
packet2_update(packet2, draw_rect_textured(packet2->next, 0, &rect));
|
||||
packet2_update(packet2,
|
||||
draw_primitive_xyoffset(
|
||||
packet2->next,
|
||||
@@ -211,7 +211,8 @@ void Renderer::drawByPath3(Mesh &t_mesh, LightBulb *t_bulbs, u16 t_bulbsCount)
|
||||
{
|
||||
if (t_mesh.shouldBeFrustumCulled && !t_mesh.getMaterial(i).isInFrustum(renderData.frustumPlanes, t_mesh.position))
|
||||
return;
|
||||
changeTexture(t_mesh, t_mesh.getMaterial(i).getId());
|
||||
MeshTexture *tex = textureRepo.getByMesh(t_mesh.getId(), t_mesh.getMaterial(i).getId());
|
||||
changeTexture(tex);
|
||||
gifSender->initPacket(context);
|
||||
u32 vertCount = t_mesh.getMaterial(i).getFacesCount();
|
||||
VECTOR *vertices = new VECTOR[vertCount];
|
||||
@@ -258,7 +259,8 @@ void Renderer::draw(Mesh &t_mesh, LightBulb *t_bulbs, u16 t_bulbsCount)
|
||||
VECTOR __attribute__((aligned(16))) vertices[vertCount];
|
||||
VECTOR __attribute__((aligned(16))) normals[vertCount];
|
||||
VECTOR __attribute__((aligned(16))) coordinates[vertCount];
|
||||
changeTexture(t_mesh, t_mesh.getMaterial(i).getId());
|
||||
MeshTexture *tex = textureRepo.getByMesh(t_mesh.getId(), t_mesh.getMaterial(i).getId());
|
||||
changeTexture(tex);
|
||||
vertCount = t_mesh.getDrawData(i, vertices, normals, coordinates, rotatedCamera);
|
||||
vifSender->drawMesh(&renderData, perspective, vertCount, vertices, normals, coordinates, t_mesh, t_bulbs, t_bulbsCount, &textureBuffer);
|
||||
}
|
||||
|
||||
@@ -35,21 +35,27 @@ TextureRepository::~TextureRepository()
|
||||
// Methods
|
||||
// ----
|
||||
|
||||
MeshTexture *TextureRepository::add(char *t_subfolder, char *t_name)
|
||||
MeshTexture *TextureRepository::add(char *t_subfolder, char *t_name, TextureFormat t_format)
|
||||
{
|
||||
MeshTexture *texture = new MeshTexture();
|
||||
loader.load(*texture, t_subfolder, t_name, ".bmp");
|
||||
if (t_format == BMP)
|
||||
bmpLoader.load(*texture, t_subfolder, t_name, ".bmp");
|
||||
else
|
||||
pngLoader.load(*texture, t_subfolder, t_name, ".png");
|
||||
texture->setName(t_name);
|
||||
textures.push_back(texture);
|
||||
return texture;
|
||||
}
|
||||
|
||||
void TextureRepository::addByMesh(char *t_path, Mesh &mesh)
|
||||
void TextureRepository::addByMesh(char *t_path, Mesh &mesh, TextureFormat t_format)
|
||||
{
|
||||
for (u32 i = 0; i < mesh.getMaterialsCount(); i++)
|
||||
{
|
||||
MeshTexture *texture = new MeshTexture();
|
||||
loader.load(*texture, t_path, mesh.getMaterial(i).getName(), ".bmp");
|
||||
if (t_format == BMP)
|
||||
bmpLoader.load(*texture, t_path, mesh.getMaterial(i).getName(), ".bmp");
|
||||
else
|
||||
pngLoader.load(*texture, t_path, mesh.getMaterial(i).getName(), ".png");
|
||||
texture->setName(mesh.getMaterial(i).getName());
|
||||
texture->addLink(mesh.getId(), mesh.getMaterial(i).getId());
|
||||
textures.push_back(texture);
|
||||
|
||||
Reference in New Issue
Block a user