Merge remote-tracking branch 'upstream/master'

zero
This commit is contained in:
Foxar
2020-12-02 20:59:09 +01:00
31 changed files with 646 additions and 198 deletions
-8
View File
@@ -1,13 +1,5 @@
.vscode/
*.[Bb][Mm][Pp]
*.[Oo][Bb][Jj]
*.[Ww][Aa][Vv]
*.[Dd][Ff][Ff]
*.[Ii][Rr][Xx]
*.[Aa][Dd][Pp][Cc][Mm]
*.[Mm][Dd]2
# ---
# Prerequisites
+1 -1
View File
@@ -92,7 +92,7 @@ YouTube tutorials soon!
This is an example of how to list things you need to use the software and how to install them.
* PS2 DEV environment - [PS2DEV](https://github.com/ps2dev/ps2dev)
* At least #1a4587d PS2SDK - [PS2SDK](https://github.com/ps2dev/ps2sdk)
* At least #674b6f4 PS2SDK (01.12.2020) - [PS2SDK](https://github.com/ps2dev/ps2sdk)
* PS2 Emulator. For example [PCSX2](https://pcsx2.net/)
### Installation
+48
View File
@@ -0,0 +1,48 @@
TYRA_DIR = ./
EE_OBJS = \
models/math/matrix.o \
models/math/plane.o \
models/math/point.o \
models/math/vector3.o \
models/mesh_frame.o \
models/mesh_material.o \
models/mesh.o \
models/sprite.o \
models/texture.o \
modules/audio.o \
modules/camera_base.o \
modules/file_service.o \
modules/gif_sender.o \
modules/light.o \
modules/pad.o \
modules/renderer.o \
modules/texture_repository.o \
modules/timer.o \
modules/vif_sender.o \
utils/math.o \
utils/string.o \
loaders/bmp_loader.o \
loaders/dff_loader.o \
loaders/md2_loader.o \
loaders/obj_loader.o \
loaders/png_loader.o \
vu1_progs/draw3D.o \
engine.o
all: $(EE_OBJS)
ar rcs $(LIB_NAME) $(EE_OBJS)
rm -f $(EE_OBJS)
# https://github.com/microsoft/wsl/issues/2468#issuecomment-374904520
#%.vsm: %.vcl # sudo service binfmt-support start
# $(EE_VCL) $< >> $@
%.o: %.vsm
$(EE_DVP) $< -o $@
clean:
rm -f $(EE_OBJS)
rm -f $(LIB_NAME)
include Makefile.pref
+11
View File
@@ -0,0 +1,11 @@
EE_LIBS := $(EE_LIBS) -ldraw -lgraph -lmath3d -lpacket -ldma -lpacket2 -lpad -laudsrv -lc -lstdc++ -lpng -lz
EE_INCS := -I$(TYRA_DIR)/include -I$(PS2SDK)/ports/include $(EE_INCS)
EE_LDFLAGS := -L$(PS2SDK)/ports/lib -L$(TYRA_DIR) $(EE_LDFLAGS)
EE_CFLAGS := -DHAVE_LIBPNG -DHAVE_ZLIB $(EE_CFLAGS)
EE_CXXFLAGS := -DHAVE_LIBPNG -DHAVE_ZLIB $(EE_CXXFLAGS)
EE_DVP = dvp-as
EE_VCL = vcl
LIB_NAME = libtyra.a
include $(PS2SDK)/samples/Makefile.pref
include $(PS2SDK)/samples/Makefile.eeglobal
+2 -2
View File
@@ -13,7 +13,7 @@
#include <stdio.h>
#include <tamtypes.h>
#include "../models/mesh_texture.hpp"
#include "../models/texture.hpp"
/** Class responsible for loading images in bmp format */
class BmpLoader
@@ -23,7 +23,7 @@ public:
BmpLoader();
~BmpLoader();
void load(MeshTexture &o_texture, char *t_subfolder, char *t_name, char *t_extension);
void load(Texture &o_texture, char *t_subfolder, char *t_name, char *t_extension);
};
#endif
+29
View File
@@ -0,0 +1,29 @@
/*
# ______ ____ ___
# | \/ ____| |___|
# | | | \ | |
#-----------------------------------------------------------------------
# Copyright 2020, tyra - https://github.com/h4570/tyra
# Licenced under Apache License 2.0
# Sandro Sobczyński <sandro.sobczynski@gmail.com>
*/
#ifndef _TYRA_PNG_LOADER_
#define _TYRA_BMP_LOADER_
#include <stdio.h>
#include <tamtypes.h>
#include "../models/texture.hpp"
/** Class responsible for loading images in bmp format */
class PngLoader
{
public:
PngLoader();
~PngLoader();
void load(Texture &o_texture, char *t_subfolder, char *t_name, char *t_extension);
};
#endif
+1
View File
@@ -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;
};
+1 -1
View File
@@ -13,7 +13,7 @@
#include "math/vector3.hpp"
#include "math/plane.hpp"
#include "./mesh_texture.hpp"
#include "./texture.hpp"
#include "./mesh_frame.hpp"
#include <tamtypes.h>
#include <draw_types.h>
+67
View File
@@ -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
@@ -8,8 +8,8 @@
# Sandro Sobczyński <sandro.sobczynski@gmail.com>
*/
#ifndef _TYRA_MESH_TEXTURE_
#define _TYRA_MESH_TEXTURE_
#ifndef _TYRA_TEXTURE_
#define _TYRA_TEXTURE_
#include <tamtypes.h>
#include <draw_sampling.h>
@@ -17,18 +17,25 @@
#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.
* Textures are paired with meshes via addLink() and
* removeLink() functions which use meshId and materialId.
* Textures are paired with meshes/sprites via addLink() and
* removeLink() functions which use meshId/spriteId and materialId (for mesh).
*/
class MeshTexture
class Texture
{
public:
MeshTexture();
~MeshTexture();
Texture();
~Texture();
// ----
// Getters
@@ -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.
@@ -78,11 +87,17 @@ public:
const s32 getIndexOfLink(const u32 &t_meshId, const u32 &t_materialId) const
{
for (u32 i = 0; i < texLinks.size(); i++)
if (texLinks[i].materialId == t_materialId && texLinks[i].meshId == t_meshId)
if (texLinks[i].materialId == t_materialId && texLinks[i].meshOrSpriteId == t_meshId)
return i;
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;
+4 -1
View File
@@ -15,7 +15,10 @@
struct TextureLink
{
u32 meshId, materialId;
/** Mesh id or sprite id */
u32 meshOrSpriteId;
/** Mesh material id or 0 if is sprite */
u32 materialId;
};
#endif
+2 -2
View File
@@ -22,7 +22,7 @@
#include "../models/screen_settings.hpp"
#include "../models/light_bulb.hpp"
#include "../models/render_data.hpp"
#include "../models/mesh_texture.hpp"
#include "../models/texture.hpp"
/** Class responsible for sending data packets via GIF (PATH3) */
class GifSender
@@ -37,7 +37,7 @@ public:
void addClear(zbuffer_t *t_zBuffer);
void sendPacket();
void sendClear(zbuffer_t *t_zBuffer);
static void sendTexture(MeshTexture &texture, texbuffer_t *t_texBuffer);
static void sendTexture(Texture &texture, texbuffer_t *t_texBuffer);
private:
xyz_t *xyz;
+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(Texture *t_tex);
u32 lastTextureId;
texbuffer_t textureBuffer;
u8 isTextureVRAMAllocated, isVSyncEnabled;
void allocateTextureBuffer(u16 t_width, u16 t_height);
void allocateTextureBuffer(Texture *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
@@ -31,7 +38,7 @@ public:
// ----
/** Returns all repository textures. */
std::vector<MeshTexture *> *getAll() { return &textures; }
std::vector<Texture *> *getAll() { return &textures; }
u32 getTexturesCount() const { return static_cast<u32>(textures.size()); };
@@ -39,7 +46,19 @@ public:
* Returns single texture.
* NULL if not found.
*/
MeshTexture *getByMesh(const u32 &t_meshId, const u32 &t_materialId)
Texture *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.
*/
Texture *getByMesh(const u32 &t_meshId, const u32 &t_materialId)
{
for (u32 i = 0; i < textures.size(); i++)
if (textures[i]->isLinkedWith(t_meshId, t_materialId))
@@ -51,7 +70,7 @@ public:
* Returns single texture.
* NULL if not found.
*/
MeshTexture *getByTextureId(const u32 &t_id) const
Texture *getByTextureId(const u32 &t_id) const
{
for (u32 i = 0; i < textures.size(); i++)
if (t_id == textures[i]->getId())
@@ -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);
Texture *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.
@@ -114,8 +135,9 @@ public:
}
private:
std::vector<MeshTexture *> textures;
BmpLoader loader;
std::vector<Texture *> textures;
BmpLoader bmpLoader;
PngLoader pngLoader;
};
#endif
+2 -4
View File
@@ -30,7 +30,7 @@ BmpLoader::~BmpLoader() {}
* @param t_name Without extension. Example "skyfall2"
* @param t_extension With dot and extension. Example ".BMP"
*/
void BmpLoader::load(MeshTexture &o_texture, char *t_subfolder, char *t_name, char *t_extension)
void BmpLoader::load(Texture &o_texture, char *t_subfolder, char *t_name, char *t_extension)
{
char *path_part1 = String::createConcatenated(t_subfolder, t_name);
char *path_part2 = String::createConcatenated("host:", path_part1);
@@ -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);
+196
View File
@@ -0,0 +1,196 @@
/*
# ______ ____ ___
# | \/ ____| |___|
# | | | \ | |
#-----------------------------------------------------------------------
# Copyright 2020, tyra - https://github.com/h4570/tyra
# Licenced under Apache License 2.0
# Sandro Sobczyński <sandro.sobczynski@gmail.com>
*/
#include "../include/loaders/png_loader.hpp"
#include "../include/utils/debug.hpp"
#include "../include/utils/string.hpp"
#include <cstdlib>
#include <png.h>
// ----
// Constructors/Destructors
// ----
PngLoader::PngLoader() {}
PngLoader::~PngLoader() {}
// ----
// Methods
// ----
/**
* @param t_name Without extension. Example "skyfall2"
* @param t_extension With dot and extension. Example ".png"
*/
void PngLoader::load(Texture &o_texture, char *t_subfolder, char *t_name, char *t_extension)
{
char *path_part1 = String::createConcatenated(t_subfolder, t_name);
char *path_part2 = String::createConcatenated("host:", path_part1);
char *path = String::createConcatenated(path_part2, t_extension);
delete[] path_part1;
delete[] path_part2;
FILE *file = fopen(path, "rb");
if (file == NULL)
{
PRINT_ERR("Failed to load .png file!");
return;
}
png_structp png_ptr;
png_infop info_ptr;
png_uint_32 width, height;
u32 sig_read = 0, row = 0, i = 0, j = 0;
int bit_depth, color_type, interlace_type;
png_ptr = png_create_read_struct(PNG_LIBPNG_VER_STRING, (png_voidp)NULL, NULL, NULL);
if (!png_ptr)
{
printf("PNG Read Struct Init Failed\n");
fclose(file);
return;
}
info_ptr = png_create_info_struct(png_ptr);
if (!info_ptr)
{
printf("PNG Info Struct Init Failed\n");
fclose(file);
png_destroy_read_struct(&png_ptr, (png_infopp)NULL, (png_infopp)NULL);
return;
}
if (setjmp(png_jmpbuf(png_ptr)))
{
printf("Got PNG Error!\n");
png_destroy_read_struct(&png_ptr, &info_ptr, (png_infopp)NULL);
fclose(file);
return;
}
png_init_io(png_ptr, file);
png_set_sig_bytes(png_ptr, sig_read);
png_read_info(png_ptr, info_ptr);
png_get_IHDR(png_ptr, info_ptr, &width, &height, &bit_depth, &color_type, &interlace_type, NULL, NULL);
png_set_strip_16(png_ptr);
if (color_type == PNG_COLOR_TYPE_PALETTE)
png_set_expand(png_ptr);
if (color_type == PNG_COLOR_TYPE_GRAY && bit_depth < 8)
png_set_expand(png_ptr);
if (png_get_valid(png_ptr, info_ptr, PNG_INFO_tRNS))
png_set_tRNS_to_alpha(png_ptr);
png_set_filler(png_ptr, 0xff, PNG_FILLER_AFTER);
png_read_update_info(png_ptr, info_ptr);
png_byte pngType = png_get_color_type(png_ptr, info_ptr);
TextureType type;
switch (pngType)
{
case PNG_COLOR_TYPE_RGB_ALPHA:
type = TEX_TYPE_RGBA;
break;
case PNG_COLOR_TYPE_RGB:
type = TEX_TYPE_RGB;
break;
default:
PRINT_ERR("This png format is not supported!");
}
o_texture.setSize(width, height, type);
printf("PNGLoader - width: %d | height: %d\n", width, height);
if (type == TEX_TYPE_RGBA)
{
int row_bytes = png_get_rowbytes(png_ptr, info_ptr);
png_byte *row_pointers[height];
for (row = 0; row < height; row++)
row_pointers[row] = new png_byte[row_bytes];
png_read_image(png_ptr, row_pointers);
struct pixel
{
u8 r, g, b, a;
};
u32 x = 0;
for (i = 0; i < height; i++)
{
for (j = 0; j < width; j++)
{
o_texture.setData(x, row_pointers[i][4 * j]);
o_texture.setData(x + 1, row_pointers[i][4 * j + 1]);
o_texture.setData(x + 2, row_pointers[i][4 * j + 2]);
o_texture.setData(x + 3, ((int)row_pointers[i][4 * j + 3] * 128 / 255));
x += 4;
}
}
for (row = 0; row < height; row++)
delete row_pointers[row];
}
else if (type == TEX_TYPE_RGB)
{
int row_bytes = png_get_rowbytes(png_ptr, info_ptr);
png_byte *row_pointers[height];
for (row = 0; row < height; row++)
row_pointers[row] = new png_byte[row_bytes];
png_read_image(png_ptr, row_pointers);
struct pixel3
{
u8 r, g, b;
};
u32 x = 0;
for (i = 0; i < height; i++)
{
for (j = 0; j < width; j++)
{
o_texture.setData(x, row_pointers[i][4 * j]);
o_texture.setData(x + 1, row_pointers[i][4 * j + 1]);
o_texture.setData(x + 2, row_pointers[i][4 * j + 2]);
x += 3;
}
}
for (row = 0; row < height; row++)
delete row_pointers[row];
}
else
{
printf("This texture depth is not supported yet!\n");
return;
}
// Texture->Filter = GS_FILTER_NEAREST;
png_read_end(png_ptr, NULL);
png_destroy_read_struct(&png_ptr, &info_ptr, (png_infopp)NULL);
delete[] path;
fclose(file);
}
+16
View File
@@ -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);
+1 -1
View File
@@ -13,7 +13,7 @@
#include "../include/loaders/md2_loader.hpp"
#include "../include/loaders/dff_loader.hpp"
#include "../include/loaders/bmp_loader.hpp"
#include "../include/models/mesh_texture.hpp"
#include "../include/models/texture.hpp"
#include "../include/utils/debug.hpp"
#include "../include/utils/string.hpp"
#include <cstdlib>
+55
View File
@@ -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;
}
@@ -8,7 +8,7 @@
# Sandro Sobczyński <sandro.sobczynski@gmail.com>
*/
#include "../include/models/mesh_texture.hpp"
#include "../include/models/texture.hpp"
#include "../include/utils/string.hpp"
#include <cstdlib>
#include <draw_sampling.h>
@@ -17,7 +17,7 @@
// Constructors/Destructors
// ----
MeshTexture::MeshTexture()
Texture::Texture()
{
id = rand() % 1000000;
_isSizeSet = false;
@@ -25,7 +25,7 @@ MeshTexture::MeshTexture()
setDefaultWrapSettings();
}
MeshTexture::~MeshTexture()
Texture::~Texture()
{
if (getTextureLinksCount() > 0)
texLinks.clear();
@@ -39,20 +39,23 @@ MeshTexture::~MeshTexture()
// Methods
// ----
void MeshTexture::setSize(const u8 &t_width, const u8 &t_height)
void Texture::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;
}
void MeshTexture::setName(char *t_val)
void Texture::setName(char *t_val)
{
if (_isNameSet)
{
@@ -63,7 +66,7 @@ void MeshTexture::setName(char *t_val)
_isNameSet = true;
}
void MeshTexture::setDefaultWrapSettings()
void Texture::setDefaultWrapSettings()
{
wrapSettings.horizontal = WRAP_REPEAT;
wrapSettings.vertical = WRAP_REPEAT;
@@ -73,16 +76,24 @@ void MeshTexture::setDefaultWrapSettings()
wrapSettings.minv = 0;
}
void MeshTexture::setWrapSettings(const WrapSettings t_horizontal, const WrapSettings t_vertical)
void Texture::setWrapSettings(const WrapSettings t_horizontal, const WrapSettings t_vertical)
{
wrapSettings.horizontal = t_horizontal;
wrapSettings.vertical = t_vertical;
}
void MeshTexture::addLink(const u32 &t_meshId, const u32 &t_materialId)
void Texture::addLink(const u32 &t_meshId, const u32 &t_materialId)
{
TextureLink link;
link.materialId = t_materialId;
link.meshId = t_meshId;
link.meshOrSpriteId = t_meshId;
texLinks.push_back(link);
}
void Texture::addLink(const u32 &t_spriteId)
{
TextureLink link;
link.materialId = 0;
link.meshOrSpriteId = t_spriteId;
texLinks.push_back(link);
}
+5 -3
View File
@@ -13,6 +13,7 @@
#include "../include/utils/math.hpp"
#include "../include/utils/debug.hpp"
#include "../include/modules/light.hpp"
#include <packet2_chain.h>
#include <kernel.h>
#include <dma.h>
#include <draw.h>
@@ -52,7 +53,7 @@ GifSender::~GifSender()
#include <gs_gp.h>
/** Send texture via GIF */
void GifSender::sendTexture(MeshTexture &texture, texbuffer_t *t_texBuffer)
void GifSender::sendTexture(Texture &texture, texbuffer_t *t_texBuffer)
{
packet2_t *packet2 = packet2_create(15, P2_TYPE_NORMAL, P2_MODE_CHAIN, false);
packet2_update(
@@ -61,7 +62,8 @@ void GifSender::sendTexture(MeshTexture &texture, texbuffer_t *t_texBuffer)
packet2->base,
texture.getData(),
texture.getWidth(),
texture.getHeight(), GS_PSM_24,
texture.getHeight(),
texture.getType(),
t_texBuffer->address,
t_texBuffer->width));
packet2_chain_open_cnt(packet2, 0, 0, 0);
@@ -257,5 +259,5 @@ void GifSender::addCurrentCalcs(u32 &t_vertexCount)
packet2_add_u64(currentPacket, st[i].uv);
packet2_add_u64(currentPacket, xyz[i].xyz);
}
packet2_align_to_qword(currentPacket);
packet2_pad128(currentPacket, 0);
}
+39 -37
View File
@@ -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(Texture *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(Texture *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());
Texture *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());
Texture *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);
}
+12 -6
View File
@@ -35,21 +35,27 @@ TextureRepository::~TextureRepository()
// Methods
// ----
MeshTexture *TextureRepository::add(char *t_subfolder, char *t_name)
Texture *TextureRepository::add(char *t_subfolder, char *t_name, TextureFormat t_format)
{
MeshTexture *texture = new MeshTexture();
loader.load(*texture, t_subfolder, t_name, ".bmp");
Texture *texture = new Texture();
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");
Texture *texture = new Texture();
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);
+6 -4
View File
@@ -125,7 +125,7 @@ void VifSender::setDoubleBuffer()
void VifSender::drawVertices(Mesh &t_mesh, u32 t_start, u32 t_end, VECTOR *t_vertices, VECTOR *t_coordinates, prim_t *t_prim, texbuffer_t *textureBuffer)
{
const u32 vertCount = t_end - t_start;
currPacket->vif_added_bytes = 0;
u32 vif_added_bytes = 0;
packet2_utils_vu_open_unpack(currPacket, 0, 1);
// TODO get this via screensettings
packet2_add_float(currPacket, 2048.0F); // scale
@@ -181,8 +181,10 @@ void VifSender::drawVertices(Mesh &t_mesh, u32 t_start, u32 t_end, VECTOR *t_ver
packet2_add_float(currPacket, 0.0F);
//// Clipping tests end
packet2_utils_vu_close_unpack(currPacket);
packet2_utils_vu_add_unpack_data(currPacket, packet2_get_vif_added_qws(currPacket), t_vertices + t_start, vertCount, 1);
packet2_utils_vu_add_unpack_data(currPacket, packet2_get_vif_added_qws(currPacket), t_coordinates + t_start, vertCount, 1);
vif_added_bytes += packet2_utils_vu_close_unpack(currPacket);
packet2_utils_vu_add_unpack_data(currPacket, vif_added_bytes, t_vertices + t_start, vertCount, 1);
vif_added_bytes += vertCount;
packet2_utils_vu_add_unpack_data(currPacket, vif_added_bytes, t_coordinates + t_start, vertCount, 1);
vif_added_bytes += vertCount;
packet2_utils_vu_add_start_program(currPacket, 0);
}
+3
View File
@@ -0,0 +1,3 @@
.vscode/
bin/**
fonts/**
+6 -38
View File
@@ -1,53 +1,22 @@
EE_BIN = ari.elf
TYRA_DIR = ./../../engine
EE_OBJS = \
../../engine/models/math/matrix.o \
../../engine/models/math/plane.o \
../../engine/models/math/point.o \
../../engine/models/math/vector3.o \
../../engine/models/mesh_frame.o \
../../engine/models/mesh_material.o \
../../engine/models/mesh.o \
../../engine/models/mesh_texture.o \
../../engine/modules/audio.o \
../../engine/modules/camera_base.o \
../../engine/modules/file_service.o \
../../engine/modules/gif_sender.o \
../../engine/modules/light.o \
../../engine/modules/pad.o \
../../engine/modules/renderer.o \
../../engine/modules/texture_repository.o \
../../engine/modules/timer.o \
../../engine/modules/vif_sender.o \
../../engine/utils/math.o \
../../engine/utils/string.o \
../../engine/loaders/bmp_loader.o \
../../engine/loaders/dff_loader.o \
../../engine/loaders/md2_loader.o \
../../engine/loaders/obj_loader.o \
../../engine/vu1_progs/draw3D.o \
../../engine/engine.o \
camera.o \
objects/player.o \
ari.o \
main.o
EE_LIBS = -ldraw -lgraph -lmath3d -lpacket -ldma -lpacket2 -lpad -laudsrv -lc -lstdc++
EE_INCS := -I./../../engine/include $(EE_INCS)
EE_DVP = dvp-as
EE_VCL = vcl
EE_LIBS = -ltyra
all: $(EE_BIN)
$(EE_STRIP) --strip-all $(EE_BIN)
mv $(EE_BIN) bin/$(EE_BIN)
rm $(EE_OBJS)
# https://github.com/microsoft/wsl/issues/2468#issuecomment-374904520
#%.vsm: %.vcl # sudo service binfmt-support start
# $(EE_VCL) $< >> $@
%.o: %.vsm
$(EE_DVP) $< -o $@
rebuild-engine:
cd $(TYRA_DIR) && make clean && make
clean:
rm -f $(EE_OBJS)
@@ -61,5 +30,4 @@ run: $(EE_BIN)
rm $(EE_OBJS)
cd bin/ && ps2client execee host:$(EE_BIN)
include $(PS2SDK)/samples/Makefile.pref
include $(PS2SDK)/samples/Makefile.eeglobal
include $(TYRA_DIR)/Makefile.pref
+11 -7
View File
@@ -48,6 +48,10 @@ void Ari::onInit()
island.shouldBeBackfaceCulled = true;
island.shouldBeFrustumCulled = false;
fist.size.set(100.0F, 100.0F);
Texture *fistTex = texRepo->add("2d/", "fist", PNG);
fistTex->addLink(fist.getId());
islandAddons.loadDff("sunnyisl/", "sunnyisl3", 0.1F, false);
islandAddons.shouldBeBackfaceCulled = true;
islandAddons.rotation.x = -1.6F;
@@ -58,7 +62,7 @@ void Ari::onInit()
waterFloors[0].loadObj("water/", "water", 5.0F, false);
waterFloors[0].position.set(0.0F, 8.0F, 0.0F);
texRepo->addByMesh("water/", waterFloors[0]);
texRepo->addByMesh("water/", waterFloors[0], BMP);
for (u8 i = 0; i < WATER_TILES_COUNT; i++)
{
spirals[i].x = 1.0F;
@@ -74,11 +78,11 @@ void Ari::onInit()
->addLink(waterFloors[i].getId(), waterFloors[i].getMaterial(0).getId());
}
texRepo->addByMesh("sunnyisl/", island);
texRepo->addByMesh("sunnyisl/", islandAddons);
texRepo->addByMesh("skybox/", skybox);
texRepo->addByMesh("ari/", player.mesh);
engine->audio.playSong();
texRepo->addByMesh("sunnyisl/", island, BMP);
texRepo->addByMesh("sunnyisl/", islandAddons, BMP);
texRepo->addByMesh("skybox/", skybox, BMP);
texRepo->addByMesh("ari/", player.mesh, BMP);
// engine->audio.playSong();
}
void Ari::initBulb()
@@ -98,8 +102,8 @@ void Ari::onUpdate()
if (engine->pad.isCircleClicked)
engine->audio.playADPCM(adpcm2);
camera.update(engine->pad, player.mesh);
engine->renderer->drawRectangle();
engine->renderer->draw(skybox);
engine->renderer->draw(fist);
engine->renderer->draw(island);
engine->renderer->draw(islandAddons);
engine->renderer->draw(player.mesh);
+2
View File
@@ -17,6 +17,7 @@
#include <engine.hpp>
#include "objects/player.hpp"
#include <models/light_bulb.hpp>
#include <models/sprite.hpp>
#include <modules/texture_repository.hpp>
#include "./camera.hpp"
@@ -39,6 +40,7 @@ private:
Player player;
Mesh island, islandAddons, skybox;
Mesh *waterFloors;
Sprite fist;
audsrv_adpcm_t *adpcm1, *adpcm2;
Point *spirals;
Camera camera;
+3
View File
@@ -0,0 +1,3 @@
.vscode/
bin/**
fonts/**
+7 -38
View File
@@ -1,32 +1,8 @@
EE_BIN = floors.elf
TYRA_DIR = ./../../engine
EE_OBJS = \
../../engine/models/math/matrix.o \
../../engine/models/math/plane.o \
../../engine/models/math/point.o \
../../engine/models/math/vector3.o \
../../engine/models/mesh_frame.o \
../../engine/models/mesh_material.o \
../../engine/models/mesh.o \
../../engine/models/mesh_texture.o \
../../engine/modules/audio.o \
../../engine/modules/camera_base.o \
../../engine/modules/file_service.o \
../../engine/modules/gif_sender.o \
../../engine/modules/light.o \
../../engine/modules/pad.o \
../../engine/modules/renderer.o \
../../engine/modules/texture_repository.o \
../../engine/modules/timer.o \
../../engine/modules/vif_sender.o \
../../engine/utils/math.o \
../../engine/utils/string.o \
../../engine/loaders/bmp_loader.o \
../../engine/loaders/dff_loader.o \
../../engine/loaders/md2_loader.o \
../../engine/loaders/obj_loader.o \
../../engine/vu1_progs/draw3D.o \
../../engine/engine.o \
managers/light_manager.o \
managers/floor_manager.o \
camera.o \
@@ -36,24 +12,18 @@ EE_OBJS = \
floors.o \
main.o
EE_LIBS = -ldraw -lgraph -lmath3d -lpacket -ldma -lpad -lpacket2 -laudsrv -lc -lstdc++
EE_INCS := -I./../../engine/include $(EE_INCS)
EE_DVP = dvp-as
EE_VCL = openvcl
EE_LIBS = -ltyra
all: $(EE_BIN)
$(EE_STRIP) --strip-all $(EE_BIN)
mv $(EE_BIN) bin/$(EE_BIN)
rm $(EE_OBJS)
%.vsm: %.vcl
$(EE_VCL) $< >> $@
%.o: %.vsm
$(EE_DVP) $< -o $@
rebuild-engine:
cd $(TYRA_DIR) && make clean && make
clean:
rm -f $(EE_BIN) $(EE_OBJS)
rm -f $(EE_OBJS)
run: $(EE_BIN)
killall -v ps2client || true
@@ -64,5 +34,4 @@ run: $(EE_BIN)
rm $(EE_OBJS)
cd bin/ && ps2client execee host:$(EE_BIN)
include $(PS2SDK)/samples/Makefile.pref
include $(PS2SDK)/samples/Makefile.eeglobal
include $(TYRA_DIR)/Makefile.pref
+2 -2
View File
@@ -36,8 +36,8 @@ void Floors::onInit()
engine->audio.setSongVolume(100);
engine->audio.playSong();
texRepo = engine->renderer->getTextureRepository();
texRepo->addByMesh("warrior/", player.mesh);
texRepo->addByMesh("floor/", floorManager.floors[0].mesh);
texRepo->addByMesh("warrior/", player.mesh, BMP);
texRepo->addByMesh("floor/", floorManager.floors[0].mesh, BMP);
for (u32 i = 1; i < floorManager.floorAmount; i++)
texRepo->getByMesh(floorManager.floors[0].mesh.getId(), floorManager.floors[0].mesh.getMaterial(0).getId())
->addLink(floorManager.floors[i].mesh.getId(), floorManager.floors[i].mesh.getMaterial(0).getId());