moving textures to textures repo #1
This commit is contained in:
@@ -54,7 +54,7 @@ public:
|
|||||||
u8 isMd2Loaded, isObjLoaded, isDffLoaded, isSpecInitialized;
|
u8 isMd2Loaded, isObjLoaded, isDffLoaded, isSpecInitialized;
|
||||||
clutbuffer_t clut;
|
clutbuffer_t clut;
|
||||||
lod_t lod;
|
lod_t lod;
|
||||||
MeshTexture **textures;
|
MeshTexture *textures;
|
||||||
|
|
||||||
private:
|
private:
|
||||||
void setupLodAndClut();
|
void setupLodAndClut();
|
||||||
|
|||||||
@@ -14,12 +14,12 @@
|
|||||||
#include <tamtypes.h>
|
#include <tamtypes.h>
|
||||||
#include <draw_sampling.h>
|
#include <draw_sampling.h>
|
||||||
#include "./texture_wrap_settings.hpp"
|
#include "./texture_wrap_settings.hpp"
|
||||||
|
#include "./texture_link.hpp"
|
||||||
|
|
||||||
/**
|
/**
|
||||||
* Class which contains texture data
|
* Class which contains texture data.
|
||||||
* Textures are paired with material via material id.
|
* Textures are paired with meshes via addUsage(),
|
||||||
* Additionaly, you can load two textures for single material
|
* removeUsage() functions which use meshId and materialId.
|
||||||
* and switch materialId here to change texture.
|
|
||||||
*/
|
*/
|
||||||
class MeshTexture
|
class MeshTexture
|
||||||
{
|
{
|
||||||
@@ -40,17 +40,12 @@ public:
|
|||||||
*/
|
*/
|
||||||
const u32 &getId() const { return id; };
|
const u32 &getId() const { return id; };
|
||||||
|
|
||||||
/**
|
|
||||||
* Core role of this variable is to assign texture to correct material.
|
|
||||||
* For example you can have two textures for single material.
|
|
||||||
* Example: Same player can have two textures (team A, team B)
|
|
||||||
*/
|
|
||||||
const u32 &getMaterialId() const { return materialId; };
|
|
||||||
|
|
||||||
const u8 &getWidth() const { return width; };
|
const u8 &getWidth() const { return width; };
|
||||||
|
|
||||||
const u8 &getHeight() const { return height; };
|
const u8 &getHeight() const { return height; };
|
||||||
|
|
||||||
|
const u32 &getTextureLinksCount() const { return texLinkCount; };
|
||||||
|
|
||||||
texwrap_t *getWrapSettings() { return &wrapSettings; };
|
texwrap_t *getWrapSettings() { return &wrapSettings; };
|
||||||
|
|
||||||
/**
|
/**
|
||||||
@@ -71,17 +66,13 @@ public:
|
|||||||
*/
|
*/
|
||||||
char *getName() const { return name; };
|
char *getName() const { return name; };
|
||||||
|
|
||||||
|
/** Array of texture links. Size of getTextureLinksCount() */
|
||||||
|
TextureLink *getTextureLinks() const { return texLinks; };
|
||||||
|
|
||||||
// ----
|
// ----
|
||||||
// Setters
|
// Setters
|
||||||
// ----
|
// ----
|
||||||
|
|
||||||
/**
|
|
||||||
* Core role of this variable is to assign texture to correct material.
|
|
||||||
* For example you can have two textures for single material.
|
|
||||||
* Example: Same player can have two textures (team A, team B)
|
|
||||||
*/
|
|
||||||
void setMaterialId(const u32 &t_val) { materialId = t_val; }
|
|
||||||
|
|
||||||
/**
|
/**
|
||||||
* Set texture size and allocate texture data
|
* Set texture size and allocate texture data
|
||||||
* Do not call this method unless you know what you do.
|
* Do not call this method unless you know what you do.
|
||||||
@@ -114,16 +105,22 @@ public:
|
|||||||
// Other
|
// Other
|
||||||
// ----
|
// ----
|
||||||
|
|
||||||
|
/** Assign texture to mesh and mesh material */
|
||||||
|
void addLink(u32 t_meshId, u32 t_materialId);
|
||||||
|
|
||||||
|
/** Remove mesh and mesh material assignment */
|
||||||
|
void removeLink(u32 t_meshId, u32 t_materialId);
|
||||||
|
|
||||||
const u8 &isNameSet() const { return _isNameSet; };
|
const u8 &isNameSet() const { return _isNameSet; };
|
||||||
|
|
||||||
const u8 &isSizeSet() const { return _isSizeSet; };
|
const u8 &isSizeSet() const { return _isSizeSet; };
|
||||||
|
|
||||||
private:
|
private:
|
||||||
void setDefaultWrapSettings();
|
void setDefaultWrapSettings();
|
||||||
|
|
||||||
texwrap_t wrapSettings;
|
texwrap_t wrapSettings;
|
||||||
char *name;
|
char *name;
|
||||||
u32 id, materialId;
|
TextureLink *texLinks;
|
||||||
|
u32 id, texLinkCount;
|
||||||
u8 width, height, _isNameSet, _isSizeSet;
|
u8 width, height, _isNameSet, _isSizeSet;
|
||||||
unsigned char *data;
|
unsigned char *data;
|
||||||
};
|
};
|
||||||
|
|||||||
@@ -0,0 +1,21 @@
|
|||||||
|
/*
|
||||||
|
# ______ ____ ___
|
||||||
|
# | \/ ____| |___|
|
||||||
|
# | | | \ | |
|
||||||
|
#-----------------------------------------------------------------------
|
||||||
|
# Copyright 2020, tyra - https://github.com/h4570/tyra
|
||||||
|
# Licenced under Apache License 2.0
|
||||||
|
# Sandro Sobczyński <sandro.sobczynski@gmail.com>
|
||||||
|
*/
|
||||||
|
|
||||||
|
#ifndef _TYRA_TEXTURE_USAGE_
|
||||||
|
#define _TYRA_TEXTURE_USAGE_
|
||||||
|
|
||||||
|
#include <tamtypes.h>
|
||||||
|
|
||||||
|
struct TextureLink
|
||||||
|
{
|
||||||
|
u32 meshId, materialId;
|
||||||
|
};
|
||||||
|
|
||||||
|
#endif
|
||||||
@@ -19,6 +19,7 @@
|
|||||||
#include "../models/math/plane.hpp"
|
#include "../models/math/plane.hpp"
|
||||||
#include "../models/screen_settings.hpp"
|
#include "../models/screen_settings.hpp"
|
||||||
#include "../models/render_data.hpp"
|
#include "../models/render_data.hpp"
|
||||||
|
#include "./texture_repository.hpp"
|
||||||
|
|
||||||
/** Class responsible for intializing draw env, textures and buffers */
|
/** Class responsible for intializing draw env, textures and buffers */
|
||||||
class Renderer
|
class Renderer
|
||||||
@@ -55,17 +56,21 @@ public:
|
|||||||
|
|
||||||
void endFrame(float fps);
|
void endFrame(float fps);
|
||||||
|
|
||||||
|
TextureRepository *getTextureRepository() { return &textureRepo; };
|
||||||
|
|
||||||
private:
|
private:
|
||||||
|
void changeTexture(Mesh *t_mesh, u8 t_textureIndex);
|
||||||
|
u32 lastTextureId;
|
||||||
|
texbuffer_t textureBuffer;
|
||||||
|
u8 isTextureVRAMAllocated;
|
||||||
void allocateTextureBuffer(u16 t_width, u16 t_height);
|
void allocateTextureBuffer(u16 t_width, u16 t_height);
|
||||||
void deallocateTextureBuffer();
|
void deallocateTextureBuffer();
|
||||||
void changeTexture(Mesh *t_mesh, u8 t_textureIndex);
|
|
||||||
void flipBuffers();
|
void flipBuffers();
|
||||||
void beginFrameIfNeeded();
|
void beginFrameIfNeeded();
|
||||||
u8 isFrameEmpty, isTextureVRAMAllocated;
|
u8 isFrameEmpty;
|
||||||
Matrix perspective;
|
Matrix perspective;
|
||||||
RenderData renderData;
|
RenderData renderData;
|
||||||
texbuffer_t textureBuffer;
|
TextureRepository textureRepo;
|
||||||
u32 lastTextureId;
|
|
||||||
GifSender *gifSender;
|
GifSender *gifSender;
|
||||||
VifSender *vifSender;
|
VifSender *vifSender;
|
||||||
packet_t *flipPacket;
|
packet_t *flipPacket;
|
||||||
|
|||||||
@@ -24,10 +24,6 @@ public:
|
|||||||
~TextureRepository();
|
~TextureRepository();
|
||||||
|
|
||||||
private:
|
private:
|
||||||
void allocateTextureBuffer(u16 t_width, u16 t_height);
|
|
||||||
void deallocateTextureBuffer();
|
|
||||||
void changeTexture(Mesh *t_mesh, u8 t_textureIndex);
|
|
||||||
texbuffer_t textureBuffer;
|
|
||||||
};
|
};
|
||||||
|
|
||||||
#endif
|
#endif
|
||||||
|
|||||||
@@ -171,29 +171,26 @@ void Mesh::loadTextures(char *t_subfolder, char *t_extension)
|
|||||||
BmpLoader bmpLoader = BmpLoader();
|
BmpLoader bmpLoader = BmpLoader();
|
||||||
if (isObjLoaded)
|
if (isObjLoaded)
|
||||||
{
|
{
|
||||||
textures = new MeshTexture *[obj->frames[0].getMaterialsCount()];
|
textures = new MeshTexture[obj->frames[0].getMaterialsCount()];
|
||||||
for (u8 i = 0; i < obj->frames[0].getMaterialsCount(); i++)
|
for (u8 i = 0; i < obj->frames[0].getMaterialsCount(); i++)
|
||||||
{
|
{
|
||||||
textures[i] = new MeshTexture();
|
bmpLoader.load(textures[i], t_subfolder, obj->frames[0].getMaterial(i).getName(), t_extension);
|
||||||
bmpLoader.load(*textures[i], t_subfolder, obj->frames[0].getMaterial(i).getName(), t_extension);
|
|
||||||
// setDefaultWrapSettings(spec->textures[i].wrapSettings);
|
// setDefaultWrapSettings(spec->textures[i].wrapSettings);
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
else if (isMd2Loaded)
|
else if (isMd2Loaded)
|
||||||
{
|
{
|
||||||
textures = new MeshTexture *[1];
|
textures = new MeshTexture[1];
|
||||||
textures[0] = new MeshTexture();
|
bmpLoader.load(textures[0], t_subfolder, md2->filename, t_extension);
|
||||||
bmpLoader.load(*textures[0], t_subfolder, md2->filename, t_extension);
|
|
||||||
// setDefaultWrapSettings(spec->textures[0].wrapSettings);
|
// setDefaultWrapSettings(spec->textures[0].wrapSettings);
|
||||||
}
|
}
|
||||||
else if (isDffLoaded)
|
else if (isDffLoaded)
|
||||||
{
|
{
|
||||||
textures = new MeshTexture *[dff->clump.geometryList.geometries[0].materialList.data.materialCount];
|
textures = new MeshTexture[dff->clump.geometryList.geometries[0].materialList.data.materialCount];
|
||||||
for (u8 i = 0; i < dff->clump.geometryList.geometries[0].materialList.data.materialCount; i++)
|
for (u8 i = 0; i < dff->clump.geometryList.geometries[0].materialList.data.materialCount; i++)
|
||||||
for (u8 j = 0; j < dff->clump.geometryList.geometries[0].materialList.materials[i].data.textureCount; j++)
|
for (u8 j = 0; j < dff->clump.geometryList.geometries[0].materialList.materials[i].data.textureCount; j++)
|
||||||
{
|
{
|
||||||
textures[i] = new MeshTexture();
|
bmpLoader.load(textures[i], t_subfolder, dff->clump.geometryList.geometries[0].materialList.materials[i].textures[j].textureName.text, t_extension);
|
||||||
bmpLoader.load(*textures[i], t_subfolder, dff->clump.geometryList.geometries[0].materialList.materials[i].textures[j].textureName.text, t_extension);
|
|
||||||
// setDefaultWrapSettings(spec->textures[i].wrapSettings);
|
// setDefaultWrapSettings(spec->textures[i].wrapSettings);
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|||||||
@@ -21,7 +21,7 @@
|
|||||||
MeshTexture::MeshTexture()
|
MeshTexture::MeshTexture()
|
||||||
{
|
{
|
||||||
id = rand() % 100000;
|
id = rand() % 100000;
|
||||||
materialId = 0;
|
texLinkCount = 0;
|
||||||
_isSizeSet = false;
|
_isSizeSet = false;
|
||||||
_isNameSet = false;
|
_isNameSet = false;
|
||||||
setDefaultWrapSettings();
|
setDefaultWrapSettings();
|
||||||
@@ -29,6 +29,8 @@ MeshTexture::MeshTexture()
|
|||||||
|
|
||||||
MeshTexture::~MeshTexture()
|
MeshTexture::~MeshTexture()
|
||||||
{
|
{
|
||||||
|
if (texLinkCount > 0)
|
||||||
|
delete[] texLinks;
|
||||||
if (_isNameSet)
|
if (_isNameSet)
|
||||||
delete[] name;
|
delete[] name;
|
||||||
if (_isSizeSet)
|
if (_isSizeSet)
|
||||||
@@ -78,3 +80,31 @@ void MeshTexture::setWrapSettings(const WrapSettings t_horizontal, const WrapSet
|
|||||||
wrapSettings.horizontal = t_horizontal;
|
wrapSettings.horizontal = t_horizontal;
|
||||||
wrapSettings.vertical = t_vertical;
|
wrapSettings.vertical = t_vertical;
|
||||||
}
|
}
|
||||||
|
|
||||||
|
void MeshTexture::addLink(u32 t_meshId, u32 t_materialId)
|
||||||
|
{
|
||||||
|
TextureLink *savedLinks = texLinks;
|
||||||
|
texLinks = new TextureLink[++texLinkCount];
|
||||||
|
for (u32 i = 0; i < texLinkCount - 1; i++)
|
||||||
|
{
|
||||||
|
texLinks[i].materialId = savedLinks[i].materialId;
|
||||||
|
texLinks[i].meshId = savedLinks[i].meshId;
|
||||||
|
}
|
||||||
|
delete[] savedLinks;
|
||||||
|
texLinks[texLinkCount - 1].materialId = t_materialId;
|
||||||
|
texLinks[texLinkCount - 1].meshId = t_meshId;
|
||||||
|
}
|
||||||
|
|
||||||
|
void MeshTexture::removeLink(u32 t_meshId, u32 t_materialId)
|
||||||
|
{
|
||||||
|
TextureLink *savedLinks = texLinks;
|
||||||
|
texLinks = new TextureLink[--texLinkCount];
|
||||||
|
u32 savedCount = 0;
|
||||||
|
for (u32 i = 0; i < texLinkCount + 1; i++)
|
||||||
|
if (savedLinks[i].materialId != t_materialId && savedLinks[i].meshId != t_meshId)
|
||||||
|
{
|
||||||
|
texLinks[savedCount++].materialId = savedLinks[i].materialId;
|
||||||
|
texLinks[savedCount++].meshId = savedLinks[i].meshId;
|
||||||
|
}
|
||||||
|
delete[] savedLinks;
|
||||||
|
}
|
||||||
|
|||||||
@@ -36,8 +36,9 @@ Renderer::Renderer(u32 t_packetSize, ScreenSettings *t_screen)
|
|||||||
dma_channel_initialize(DMA_CHANNEL_GIF, NULL, 0); // Initialize DMA to enable data transfer
|
dma_channel_initialize(DMA_CHANNEL_GIF, NULL, 0); // Initialize DMA to enable data transfer
|
||||||
dma_channel_fast_waits(DMA_CHANNEL_GIF);
|
dma_channel_fast_waits(DMA_CHANNEL_GIF);
|
||||||
context = 0;
|
context = 0;
|
||||||
lastTextureId = 0;
|
isTextureVRAMAllocated = false;
|
||||||
isFrameEmpty = false;
|
isFrameEmpty = false;
|
||||||
|
lastTextureId = 0;
|
||||||
flipPacket = packet_init(3, PACKET_UCAB); // Uncached accelerated
|
flipPacket = packet_init(3, PACKET_UCAB); // Uncached accelerated
|
||||||
allocateBuffers(t_screen->width, t_screen->height);
|
allocateBuffers(t_screen->width, t_screen->height);
|
||||||
initDrawingEnv(t_screen->width, t_screen->height);
|
initDrawingEnv(t_screen->width, t_screen->height);
|
||||||
@@ -55,6 +56,42 @@ Renderer::~Renderer() {}
|
|||||||
// Methods
|
// Methods
|
||||||
// ----
|
// ----
|
||||||
|
|
||||||
|
/** Configure and allocate vRAM for texture buffer */
|
||||||
|
void Renderer::allocateTextureBuffer(u16 t_width, u16 t_height)
|
||||||
|
{
|
||||||
|
textureBuffer.width = t_width;
|
||||||
|
textureBuffer.psm = GS_PSM_24;
|
||||||
|
textureBuffer.address = graph_vram_allocate(t_width, t_height, GS_PSM_24, 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.function = TEXTURE_FUNCTION_MODULATE;
|
||||||
|
isTextureVRAMAllocated = true;
|
||||||
|
}
|
||||||
|
|
||||||
|
/** Configure and allocate vRAM for texture buffer */
|
||||||
|
void Renderer::deallocateTextureBuffer()
|
||||||
|
{
|
||||||
|
if (isTextureVRAMAllocated)
|
||||||
|
{
|
||||||
|
graph_vram_free(textureBuffer.address);
|
||||||
|
isTextureVRAMAllocated = false;
|
||||||
|
}
|
||||||
|
}
|
||||||
|
|
||||||
|
void Renderer::changeTexture(Mesh *t_mesh, u8 t_textureIndex)
|
||||||
|
{
|
||||||
|
if (t_mesh->textures[t_textureIndex].getId() != lastTextureId)
|
||||||
|
{
|
||||||
|
lastTextureId = t_mesh->textures[t_textureIndex].getId();
|
||||||
|
deallocateTextureBuffer();
|
||||||
|
allocateTextureBuffer(t_mesh->textures[t_textureIndex].getWidth(), t_mesh->textures[t_textureIndex].getHeight());
|
||||||
|
GifSender::sendTexture(t_mesh->textures[t_textureIndex], &textureBuffer);
|
||||||
|
}
|
||||||
|
}
|
||||||
|
|
||||||
/** Initializes drawing environment (1st app packet) */
|
/** Initializes drawing environment (1st app packet) */
|
||||||
void Renderer::initDrawingEnv(float t_screenW, float t_screenH)
|
void Renderer::initDrawingEnv(float t_screenW, float t_screenH)
|
||||||
{
|
{
|
||||||
@@ -88,42 +125,6 @@ void Renderer::setPrim()
|
|||||||
PRINT_LOG("Prim set!");
|
PRINT_LOG("Prim set!");
|
||||||
}
|
}
|
||||||
|
|
||||||
/** Configure and allocate vRAM for texture buffer */
|
|
||||||
void Renderer::allocateTextureBuffer(u16 t_width, u16 t_height)
|
|
||||||
{
|
|
||||||
textureBuffer.width = t_width;
|
|
||||||
textureBuffer.psm = GS_PSM_24;
|
|
||||||
textureBuffer.address = graph_vram_allocate(t_width, t_height, GS_PSM_24, 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.function = TEXTURE_FUNCTION_MODULATE;
|
|
||||||
isTextureVRAMAllocated = true;
|
|
||||||
}
|
|
||||||
|
|
||||||
/** Configure and allocate vRAM for texture buffer */
|
|
||||||
void Renderer::deallocateTextureBuffer()
|
|
||||||
{
|
|
||||||
if (isTextureVRAMAllocated)
|
|
||||||
{
|
|
||||||
graph_vram_free(textureBuffer.address);
|
|
||||||
isTextureVRAMAllocated = false;
|
|
||||||
}
|
|
||||||
}
|
|
||||||
|
|
||||||
void Renderer::changeTexture(Mesh *t_mesh, u8 t_textureIndex)
|
|
||||||
{
|
|
||||||
if (t_mesh->textures[t_textureIndex]->getId() != lastTextureId)
|
|
||||||
{
|
|
||||||
lastTextureId = t_mesh->textures[t_textureIndex]->getId();
|
|
||||||
deallocateTextureBuffer();
|
|
||||||
allocateTextureBuffer(t_mesh->textures[t_textureIndex]->getWidth(), t_mesh->textures[t_textureIndex]->getHeight());
|
|
||||||
GifSender::sendTexture(*t_mesh->textures[t_textureIndex], &textureBuffer);
|
|
||||||
}
|
|
||||||
}
|
|
||||||
|
|
||||||
/** Defines and allocates framebuffers and zbuffer */
|
/** Defines and allocates framebuffers and zbuffer */
|
||||||
void Renderer::allocateBuffers(float t_screenW, float t_screenH)
|
void Renderer::allocateBuffers(float t_screenW, float t_screenH)
|
||||||
{
|
{
|
||||||
|
|||||||
@@ -18,6 +18,7 @@ EE_OBJS = \
|
|||||||
../../engine/modules/light.o \
|
../../engine/modules/light.o \
|
||||||
../../engine/modules/pad.o \
|
../../engine/modules/pad.o \
|
||||||
../../engine/modules/renderer.o \
|
../../engine/modules/renderer.o \
|
||||||
|
../../engine/modules/texture_repository.o \
|
||||||
../../engine/modules/timer.o \
|
../../engine/modules/timer.o \
|
||||||
../../engine/modules/vif_sender.o \
|
../../engine/modules/vif_sender.o \
|
||||||
../../engine/modules/vu1.o \
|
../../engine/modules/vu1.o \
|
||||||
|
|||||||
@@ -75,6 +75,7 @@ void Ari::onInit()
|
|||||||
engine.audio.init(0);
|
engine.audio.init(0);
|
||||||
engine.audio.setVolume(40);
|
engine.audio.setVolume(40);
|
||||||
engine.audio.loadSong("MOV-CIRC.WAV");
|
engine.audio.loadSong("MOV-CIRC.WAV");
|
||||||
|
texRepo = engine.renderer->getTextureRepository();
|
||||||
// engine.audio.play();
|
// engine.audio.play();
|
||||||
|
|
||||||
// Vector3 islandPos = Vector3(0.0F, 10.0F, 0.0F);
|
// Vector3 islandPos = Vector3(0.0F, 10.0F, 0.0F);
|
||||||
|
|||||||
@@ -16,6 +16,7 @@
|
|||||||
#include <engine.hpp>
|
#include <engine.hpp>
|
||||||
#include "objects/player.hpp"
|
#include "objects/player.hpp"
|
||||||
#include <models/light_bulb.hpp>
|
#include <models/light_bulb.hpp>
|
||||||
|
#include <modules/texture_repository.hpp>
|
||||||
#include "./camera.hpp"
|
#include "./camera.hpp"
|
||||||
|
|
||||||
class Ari : public Game
|
class Ari : public Game
|
||||||
@@ -35,6 +36,7 @@ private:
|
|||||||
LightBulb bulb;
|
LightBulb bulb;
|
||||||
Player *player;
|
Player *player;
|
||||||
Camera *camera;
|
Camera *camera;
|
||||||
|
TextureRepository *texRepo;
|
||||||
};
|
};
|
||||||
|
|
||||||
#endif
|
#endif
|
||||||
|
|||||||
Reference in New Issue
Block a user