tyrav2 init
This commit is contained in:
@@ -0,0 +1,26 @@
|
||||
TARGET := libtyra.a
|
||||
|
||||
#The Directories, Source, Includes, Objects, Binary and Resources
|
||||
SRCDIR := src
|
||||
INCDIR := inc
|
||||
BUILDDIR := obj
|
||||
TARGETDIR := bin
|
||||
RESDIR := res
|
||||
SRCEXT := cpp
|
||||
VSMEXT := vsm
|
||||
VCLEXT := vcl
|
||||
VCLPPEXT := vclpp
|
||||
DEPEXT := d
|
||||
OBJEXT := o
|
||||
|
||||
#Flags, Libraries and Includes
|
||||
CFLAGS :=
|
||||
LIB :=
|
||||
LIBDIRS :=
|
||||
INC := -I$(INCDIR)
|
||||
INCDEP := -I$(INCDIR)
|
||||
|
||||
include ../Makefile.base
|
||||
|
||||
$(TARGET): $(OBJECTS) $(VCL_OBJECTS) $(VU_OBJECTS_VCL) $(VU_OBJECTS_VSM) $(IRXEM_OBJECTS)
|
||||
$(AR) rcs $(TARGETDIR)/$(TARGET) $(OBJECTS) $(VCL_OBJECTS) $(VU_OBJECTS_VCL) $(VU_OBJECTS_VSM) $(IRXEM_OBJECTS)
|
||||
@@ -0,0 +1,161 @@
|
||||
/*
|
||||
# ______ ____ ___
|
||||
# | \/ ____| |___|
|
||||
# | | | \ | |
|
||||
#-----------------------------------------------------------------------
|
||||
# Copyright 2020-2022, Tyra - https://github.com/h4570/tyrav2
|
||||
# Licenced under Apache License 2.0
|
||||
# Sandro Sobczyński <sandro.sobczynski@gmail.com>
|
||||
# Wellinator Carvalho <wellcoj@gmail.com>
|
||||
*/
|
||||
|
||||
#pragma once
|
||||
|
||||
#include "./audio_listener.hpp"
|
||||
#include <audsrv.h>
|
||||
#include <string>
|
||||
|
||||
namespace Tyra {
|
||||
|
||||
struct AudioListenerRef {
|
||||
AudioListener* listener;
|
||||
u32 id;
|
||||
};
|
||||
|
||||
/**
|
||||
* Class responsible for audio playing.
|
||||
* There are two main features:
|
||||
* - WAV song (background music)
|
||||
* - ADPCM samples
|
||||
*/
|
||||
class Audio {
|
||||
public:
|
||||
/** Constructor is called by the engine. */
|
||||
Audio();
|
||||
~Audio();
|
||||
|
||||
void init();
|
||||
|
||||
/**
|
||||
* Load 24bit 22050Hz Stereo WAV.
|
||||
* Can be used multiple times for song switching.
|
||||
* @param t_path Example: "host:song.wav" or "host:folder/song.wav"
|
||||
*/
|
||||
void loadSong(const char* t_path);
|
||||
|
||||
/**
|
||||
* Load 24bit 22050Hz Stereo WAV.
|
||||
* Can be used multiple times for song switching.
|
||||
* @param t_path Example: "host:song.wav" or "host:folder/song.wav"
|
||||
*/
|
||||
inline void loadSong(const std::string& t_path) { loadSong(t_path.c_str()); }
|
||||
|
||||
void playSong();
|
||||
|
||||
void stopSong();
|
||||
|
||||
const u8& isSongPlaying() const { return songPlaying; }
|
||||
|
||||
const u8& isSongLoaded() const { return songLoaded; }
|
||||
|
||||
/**
|
||||
* Set song loop/noloop.
|
||||
* @returns Looping state is 0 - noloop / 1 - loop
|
||||
*/
|
||||
const u8& isSongInLoop() const { return songInLoop; }
|
||||
|
||||
/**
|
||||
* Set song loop/noloop.
|
||||
* @param t_set false - noloop, true - loop
|
||||
*/
|
||||
void setSongLoop(const u8& t_set) { songInLoop = t_set; }
|
||||
|
||||
const u8& getVolume() const { return tyraVolume; }
|
||||
|
||||
/**
|
||||
* Set song volume.
|
||||
* @param t_vol Value 0-100
|
||||
*/
|
||||
void setSongVolume(const u8& t_vol);
|
||||
|
||||
/**
|
||||
* If you want to synchronize some actions with
|
||||
* background song, add audio listener.
|
||||
* @returns Listener id.
|
||||
*/
|
||||
u32 addSongListener(AudioListener* t_listener);
|
||||
|
||||
/** Remove song listener. */
|
||||
void removeSongListener(const u32& t_id);
|
||||
|
||||
/**
|
||||
* Load ADPCM sample. ADPCM sample is an output from
|
||||
* "adpenc" tool, shipped with PS2SDK.
|
||||
* @param t_path Example: "host:hit.adpcm" or "host:folder/jump.adpcm"
|
||||
*/
|
||||
audsrv_adpcm_t* loadADPCM(const char* t_path);
|
||||
|
||||
/**
|
||||
* Load ADPCM sample. ADPCM sample is an output from
|
||||
* "adpenc" tool, shipped with PS2SDK.
|
||||
* @param t_path Example: "host:hit.adpcm" or "host:folder/jump.adpcm"
|
||||
*/
|
||||
inline audsrv_adpcm_t* loadADPCM(const std::string& t_path) {
|
||||
return loadADPCM(t_path.c_str());
|
||||
}
|
||||
|
||||
/**
|
||||
* Play ADPCM sample.
|
||||
* ADPCM sample can't be stopped.
|
||||
* @param t_adpcm ADPCM data, created by loadADPCM();
|
||||
*/
|
||||
void playADPCM(audsrv_adpcm_t* t_adpcm);
|
||||
|
||||
/**
|
||||
* Play ADPCM sample.
|
||||
* ADPCM sample can't be stopped.
|
||||
* @param t_adpcm ADPCM data, created by loadADPCM();
|
||||
* @param t_ch Channel (0-23). Type -1 for use any free channel.
|
||||
*/
|
||||
void playADPCM(audsrv_adpcm_t* t_adpcm, const s8& t_ch);
|
||||
|
||||
/**
|
||||
* Set ADPCM volume.
|
||||
* @param t_vol Value 0-100
|
||||
* @param t_ch Channel (0-23)
|
||||
*/
|
||||
void setADPCMVolume(const u8& t_vol, const s8& t_ch) {
|
||||
audsrv_adpcm_set_volume(t_ch, t_vol);
|
||||
}
|
||||
|
||||
void work();
|
||||
|
||||
private:
|
||||
u8 songLoaded, tyraVolume, audsrvVolume, songPlaying, songInLoop,
|
||||
songFinished;
|
||||
FILE* wav;
|
||||
audsrv_fmt_t format;
|
||||
std::vector<AudioListenerRef*> songListeners;
|
||||
|
||||
ee_thread_t thread;
|
||||
int threadId;
|
||||
static const u16 threadStackSize;
|
||||
u8* threadStack;
|
||||
|
||||
ee_sema_t sema;
|
||||
s32 fillbufferSema;
|
||||
static const u16 chunkSize;
|
||||
char* chunk;
|
||||
s32 chunkReadStatus;
|
||||
|
||||
void setSongFormat();
|
||||
void unloadSong();
|
||||
void rewindSongToStart();
|
||||
u32 getSongListenersCount() const { return songListeners.size(); }
|
||||
|
||||
void initSema();
|
||||
void initAUDSRV();
|
||||
void initThread();
|
||||
};
|
||||
|
||||
} // namespace Tyra
|
||||
@@ -0,0 +1,25 @@
|
||||
/*
|
||||
# ______ ____ ___
|
||||
# | \/ ____| |___|
|
||||
# | | | \ | |
|
||||
#-----------------------------------------------------------------------
|
||||
# Copyright 2020-2022, Tyra - https://github.com/h4570/tyrav2
|
||||
# Licenced under Apache License 2.0
|
||||
# Sandro Sobczyński <sandro.sobczynski@gmail.com>
|
||||
# Wellinator Carvalho <wellcoj@gmail.com>
|
||||
*/
|
||||
|
||||
#pragma once
|
||||
|
||||
namespace Tyra {
|
||||
|
||||
class AudioListener {
|
||||
public:
|
||||
virtual ~AudioListener(){};
|
||||
virtual void onAudioTick() = 0;
|
||||
virtual void onAudioFinish() = 0;
|
||||
|
||||
private:
|
||||
};
|
||||
|
||||
} // namespace Tyra
|
||||
@@ -0,0 +1,76 @@
|
||||
/*
|
||||
# ______ ____ ___
|
||||
# | \/ ____| |___|
|
||||
# | | | \ | |
|
||||
#-----------------------------------------------------------------------
|
||||
# Copyright 2022, tyra - https://github.com/h4570/tyra
|
||||
# Licenced under Apache License 2.0
|
||||
# Sandro Sobczyński <sandro.sobczynski@gmail.com>
|
||||
*/
|
||||
|
||||
#pragma once
|
||||
|
||||
#ifdef NDEBUG
|
||||
#define TYRA_LOG(...) ((void)0)
|
||||
#define TYRA_WARN(...) ((void)0)
|
||||
#define TYRA_ERROR(...) ((void)0)
|
||||
#define TYRA_TRAP(...) ((void)0)
|
||||
#define TYRA_ASSERT(condition, ...) ((void)0)
|
||||
|
||||
#else // IF Debug
|
||||
|
||||
#include <stdio.h>
|
||||
#include <string>
|
||||
#include <sstream>
|
||||
#include <utility>
|
||||
|
||||
#define TYRA_LOG(...) Debug::writeLines("LOG: ", ##__VA_ARGS__, "\n")
|
||||
#define TYRA_WARN(...) Debug::writeLines("==WARN: ", ##__VA_ARGS__, "\n")
|
||||
#define TYRA_ERROR(...) Debug::writeLines("====ERR: ", ##__VA_ARGS__, "\n")
|
||||
#define TYRA_TRAP(...) Debug::trap(__FILE__, __LINE__, ##__VA_ARGS__)
|
||||
#define TYRA_BREAKPOINT() Debug::trap(__FILE__, __LINE__, "Breakpoint")
|
||||
#define TYRA_ASSERT(condition, ...) \
|
||||
if (!(condition)) Debug::trap(__FILE__, __LINE__, ##__VA_ARGS__)
|
||||
|
||||
class Debug {
|
||||
public:
|
||||
template <typename Arg, typename... Args>
|
||||
static void writeLines(Arg&& arg, Args&&... args) {
|
||||
std::stringstream ss;
|
||||
|
||||
ss << std::forward<Arg>(arg);
|
||||
using expander = int[];
|
||||
(void)expander{0, (void(ss << std::forward<Args>(args)), 0)...};
|
||||
|
||||
printf("%s", ss.str().c_str());
|
||||
}
|
||||
|
||||
template <typename... Args>
|
||||
static void trap(const char* file, int line, Args... args) {
|
||||
printf("\n");
|
||||
printf("============== TYRA ==============\n");
|
||||
printf("| Assertion failed!\n");
|
||||
printf("|\n");
|
||||
writeAssertLines(args...);
|
||||
printf("|\n");
|
||||
printf("| File : %s:%d\n", file, line);
|
||||
printf("====================================\n\n");
|
||||
for (;;) {
|
||||
}
|
||||
}
|
||||
|
||||
private:
|
||||
template <typename Arg, typename... Args>
|
||||
static void writeAssertLines(Arg&& arg, Args&&... args) {
|
||||
std::stringstream ss;
|
||||
|
||||
ss << "| " << std::forward<Arg>(arg) << "\n";
|
||||
using expander = int[];
|
||||
(void)expander{
|
||||
0, (void(ss << "| " << std::forward<Args>(args) << "\n"), 0)...};
|
||||
|
||||
printf("%s", ss.str().c_str());
|
||||
}
|
||||
};
|
||||
|
||||
#endif // NDEBUG
|
||||
@@ -0,0 +1,41 @@
|
||||
/*
|
||||
# ______ ____ ___
|
||||
# | \/ ____| |___|
|
||||
# | | | \ | |
|
||||
#-----------------------------------------------------------------------
|
||||
# Copyright 2020, tyra - https://github.com/h4570/tyra
|
||||
# Licenced under Apache License 2.0
|
||||
# Sandro Sobczyński <sandro.sobczynski@gmail.com>
|
||||
*/
|
||||
|
||||
#pragma once
|
||||
|
||||
#include "./renderer/renderer.hpp"
|
||||
#include "./pad/pad.hpp"
|
||||
#include "./audio/audio.hpp"
|
||||
#include "./irx/irx_loader.hpp"
|
||||
#include "./info/info.hpp"
|
||||
#include "./game.hpp"
|
||||
|
||||
namespace Tyra {
|
||||
|
||||
class Engine {
|
||||
public:
|
||||
Engine();
|
||||
~Engine();
|
||||
|
||||
Renderer renderer;
|
||||
Pad pad;
|
||||
Audio audio;
|
||||
IrxLoader irx;
|
||||
Info info;
|
||||
|
||||
void run(Game* t_game);
|
||||
|
||||
private:
|
||||
Game* game;
|
||||
|
||||
void realLoop();
|
||||
};
|
||||
|
||||
} // namespace Tyra
|
||||
@@ -0,0 +1,35 @@
|
||||
/*
|
||||
# ______ ____ ___
|
||||
# | \/ ____| |___|
|
||||
# | | | \ | |
|
||||
#-----------------------------------------------------------------------
|
||||
# Copyright 2020 - 2022, tyra - https://github.com/h4570/tyra
|
||||
# Licenced under Apache License 2.0
|
||||
# Wellington Carvalho <wellcoj@gmail.com>
|
||||
*/
|
||||
|
||||
#pragma once
|
||||
|
||||
namespace Tyra {
|
||||
|
||||
class FileUtils {
|
||||
public:
|
||||
FileUtils();
|
||||
~FileUtils();
|
||||
|
||||
static std::string getCwd();
|
||||
static std::string fromCwd(const char* relativePath);
|
||||
|
||||
const char* getElfName() const { return elfName; };
|
||||
const char* getElfPath() const { return elfPath; };
|
||||
|
||||
private:
|
||||
// Argv name+path & just path
|
||||
char cwd[NAME_MAX];
|
||||
char elfName[NAME_MAX];
|
||||
char elfPath[NAME_MAX - 14];
|
||||
|
||||
void setPathInfo(const char* path);
|
||||
};
|
||||
|
||||
} // namespace Tyra
|
||||
@@ -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>
|
||||
*/
|
||||
|
||||
#pragma once
|
||||
|
||||
namespace Tyra {
|
||||
|
||||
class Game {
|
||||
public:
|
||||
virtual void init() = 0;
|
||||
virtual void loop() = 0;
|
||||
};
|
||||
|
||||
} // namespace Tyra
|
||||
@@ -0,0 +1,36 @@
|
||||
/*
|
||||
# ______ ____ ___
|
||||
# | \/ ____| |___|
|
||||
# | | | \ | |
|
||||
#-----------------------------------------------------------------------
|
||||
# Copyright 2020 - 2022, tyra - https://github.com/h4570/tyra
|
||||
# Licenced under Apache License 2.0
|
||||
# Wellington Carvalho <wellcoj@gmail.com>
|
||||
*/
|
||||
|
||||
#pragma once
|
||||
|
||||
#include <tamtypes.h>
|
||||
#include "time/timer.hpp"
|
||||
|
||||
namespace Tyra {
|
||||
|
||||
class Info {
|
||||
public:
|
||||
Info();
|
||||
~Info();
|
||||
|
||||
/** Called by engine */
|
||||
void update();
|
||||
|
||||
const u32& getFps() const { return fps; };
|
||||
|
||||
private:
|
||||
float calcFps();
|
||||
|
||||
u8 fpsDelayer;
|
||||
u32 fps;
|
||||
Timer timer;
|
||||
};
|
||||
|
||||
} // namespace Tyra
|
||||
@@ -0,0 +1,36 @@
|
||||
/*
|
||||
# ______ ____ ___
|
||||
# | \/ ____| |___|
|
||||
# | | | \ | |
|
||||
#-----------------------------------------------------------------------
|
||||
# Copyright 2020 - 2022, tyra - https://github.com/h4570/tyra
|
||||
# Licenced under Apache License 2.0
|
||||
# Wellington Carvalho <wellcoj@gmail.com>
|
||||
*/
|
||||
|
||||
#pragma once
|
||||
|
||||
#include <tamtypes.h>
|
||||
|
||||
namespace Tyra {
|
||||
|
||||
class IrxLoader {
|
||||
public:
|
||||
IrxLoader();
|
||||
~IrxLoader();
|
||||
|
||||
/** Load's audio and pad driver */
|
||||
void loadDefaultDrivers();
|
||||
|
||||
void loadUSBDriver();
|
||||
|
||||
private:
|
||||
int applyRpcPatches();
|
||||
int loadAudio();
|
||||
int loadPad();
|
||||
int loadUsb();
|
||||
void waitUntilUsbDeviceIsReady();
|
||||
void delay(int count);
|
||||
};
|
||||
|
||||
} // namespace Tyra
|
||||
@@ -0,0 +1,44 @@
|
||||
|
||||
/*
|
||||
# ______ ____ ___
|
||||
# | \/ ____| |___|
|
||||
# | | | \ | |
|
||||
#-----------------------------------------------------------------------
|
||||
# Copyright 2020, tyra - https://github.com/h4570/tyra
|
||||
# Licenced under Apache License 2.0
|
||||
# Sandro Sobczyński <sandro.sobczynski@gmail.com>
|
||||
*/
|
||||
|
||||
#pragma once
|
||||
|
||||
#include "./mesh_builder_material_data.hpp"
|
||||
#include "./mesh_builder_frame_data.hpp"
|
||||
|
||||
namespace Tyra {
|
||||
|
||||
class MeshBuilderData {
|
||||
public:
|
||||
MeshBuilderData();
|
||||
|
||||
/**
|
||||
* Frames array and materials array will be deallocated, but
|
||||
* data (vert,st, ...) inside it not.
|
||||
* Data ownership is transferred to
|
||||
* the Mesh class.
|
||||
*/
|
||||
~MeshBuilderData();
|
||||
|
||||
MeshBuilderFrameData** frames;
|
||||
u32 framesCount;
|
||||
|
||||
MeshBuilderMaterialData** materials;
|
||||
u32 materialsCount;
|
||||
|
||||
bool textureCoordsEnabled, normalsEnabled, manyColorsEnabled;
|
||||
|
||||
void allocateFrames(const u32& count);
|
||||
void allocateMaterials(const u32& count);
|
||||
void allocate(const u32& framesCount, const u32& materialsCount);
|
||||
};
|
||||
|
||||
} // namespace Tyra
|
||||
@@ -0,0 +1,39 @@
|
||||
|
||||
/*
|
||||
# ______ ____ ___
|
||||
# | \/ ____| |___|
|
||||
# | | | \ | |
|
||||
#-----------------------------------------------------------------------
|
||||
# Copyright 2020, tyra - https://github.com/h4570/tyra
|
||||
# Licenced under Apache License 2.0
|
||||
# Sandro Sobczyński <sandro.sobczynski@gmail.com>
|
||||
*/
|
||||
|
||||
#pragma once
|
||||
|
||||
#include <tamtypes.h>
|
||||
#include "math/vec4.hpp"
|
||||
#include "renderer/models/color.hpp"
|
||||
|
||||
namespace Tyra {
|
||||
|
||||
/**
|
||||
* Data is not deallocated here.
|
||||
* Ownership is moved to Mesh class.
|
||||
*/
|
||||
class MeshBuilderFrameData {
|
||||
public:
|
||||
MeshBuilderFrameData();
|
||||
~MeshBuilderFrameData();
|
||||
|
||||
Vec4 *vertices, *normals, *textureCoords;
|
||||
Color* colors;
|
||||
u32 verticesCount, textureCoordsCount, normalsCount, colorsCount;
|
||||
|
||||
void allocateTextureCoords(const u32& count);
|
||||
void allocateVertices(const u32& count);
|
||||
void allocateNormals(const u32& count);
|
||||
void allocateColors(const u32& count);
|
||||
};
|
||||
|
||||
} // namespace Tyra
|
||||
@@ -0,0 +1,35 @@
|
||||
|
||||
/*
|
||||
# ______ ____ ___
|
||||
# | \/ ____| |___|
|
||||
# | | | \ | |
|
||||
#-----------------------------------------------------------------------
|
||||
# Copyright 2020, tyra - https://github.com/h4570/tyra
|
||||
# Licenced under Apache License 2.0
|
||||
# Sandro Sobczyński <sandro.sobczynski@gmail.com>
|
||||
*/
|
||||
|
||||
#pragma once
|
||||
|
||||
#include <tamtypes.h>
|
||||
#include <string>
|
||||
|
||||
namespace Tyra {
|
||||
|
||||
/**
|
||||
* Data is not deallocated here.
|
||||
* Ownership is moved to Mesh class.
|
||||
*/
|
||||
class MeshBuilderMaterialData {
|
||||
public:
|
||||
MeshBuilderMaterialData();
|
||||
~MeshBuilderMaterialData();
|
||||
|
||||
std::string name;
|
||||
u32 *vertexFaces, *textureCoordFaces, *normalFaces, *colorFaces;
|
||||
u32 count;
|
||||
|
||||
void allocateFaces(const u32& count);
|
||||
};
|
||||
|
||||
} // namespace Tyra
|
||||
@@ -0,0 +1,103 @@
|
||||
/*
|
||||
Copyright (C) 1997-2001 Id Software, Inc.
|
||||
This program is free software; you can redistribute it and/or
|
||||
modify it under the terms of the GNU General Public License
|
||||
as published by the Free Software Foundation; either version 2
|
||||
of the License, or (at your option) any later version.
|
||||
This program is distributed in the hope that it will be useful,
|
||||
but WITHOUT ANY WARRANTY; without even the implied warranty of
|
||||
MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE.
|
||||
See the GNU General Public License for more details.
|
||||
You should have received a copy of the GNU General Public License
|
||||
along with this program; if not, write to the Free Software
|
||||
Foundation, Inc., 59 Temple Place - Suite 330, Boston, MA 02111-1307, USA.
|
||||
*/
|
||||
|
||||
#pragma once
|
||||
|
||||
namespace Tyra {
|
||||
|
||||
const float ANORMS[162][3] = {
|
||||
{-0.525731f, 0.000000f, 0.850651f}, {-0.442863f, 0.238856f, 0.864188f},
|
||||
{-0.295242f, 0.000000f, 0.955423f}, {-0.309017f, 0.500000f, 0.809017f},
|
||||
{-0.162460f, 0.262866f, 0.951056f}, {0.000000f, 0.000000f, 1.000000f},
|
||||
{0.000000f, 0.850651f, 0.525731f}, {-0.147621f, 0.716567f, 0.681718f},
|
||||
{0.147621f, 0.716567f, 0.681718f}, {0.000000f, 0.525731f, 0.850651f},
|
||||
{0.309017f, 0.500000f, 0.809017f}, {0.525731f, 0.000000f, 0.850651f},
|
||||
{0.295242f, 0.000000f, 0.955423f}, {0.442863f, 0.238856f, 0.864188f},
|
||||
{0.162460f, 0.262866f, 0.951056f}, {-0.681718f, 0.147621f, 0.716567f},
|
||||
{-0.809017f, 0.309017f, 0.500000f}, {-0.587785f, 0.425325f, 0.688191f},
|
||||
{-0.850651f, 0.525731f, 0.000000f}, {-0.864188f, 0.442863f, 0.238856f},
|
||||
{-0.716567f, 0.681718f, 0.147621f}, {-0.688191f, 0.587785f, 0.425325f},
|
||||
{-0.500000f, 0.809017f, 0.309017f}, {-0.238856f, 0.864188f, 0.442863f},
|
||||
{-0.425325f, 0.688191f, 0.587785f}, {-0.716567f, 0.681718f, -0.147621f},
|
||||
{-0.500000f, 0.809017f, -0.309017f}, {-0.525731f, 0.850651f, 0.000000f},
|
||||
{0.000000f, 0.850651f, -0.525731f}, {-0.238856f, 0.864188f, -0.442863f},
|
||||
{0.000000f, 0.955423f, -0.295242f}, {-0.262866f, 0.951056f, -0.162460f},
|
||||
{0.000000f, 1.000000f, 0.000000f}, {0.000000f, 0.955423f, 0.295242f},
|
||||
{-0.262866f, 0.951056f, 0.162460f}, {0.238856f, 0.864188f, 0.442863f},
|
||||
{0.262866f, 0.951056f, 0.162460f}, {0.500000f, 0.809017f, 0.309017f},
|
||||
{0.238856f, 0.864188f, -0.442863f}, {0.262866f, 0.951056f, -0.162460f},
|
||||
{0.500000f, 0.809017f, -0.309017f}, {0.850651f, 0.525731f, 0.000000f},
|
||||
{0.716567f, 0.681718f, 0.147621f}, {0.716567f, 0.681718f, -0.147621f},
|
||||
{0.525731f, 0.850651f, 0.000000f}, {0.425325f, 0.688191f, 0.587785f},
|
||||
{0.864188f, 0.442863f, 0.238856f}, {0.688191f, 0.587785f, 0.425325f},
|
||||
{0.809017f, 0.309017f, 0.500000f}, {0.681718f, 0.147621f, 0.716567f},
|
||||
{0.587785f, 0.425325f, 0.688191f}, {0.955423f, 0.295242f, 0.000000f},
|
||||
{1.000000f, 0.000000f, 0.000000f}, {0.951056f, 0.162460f, 0.262866f},
|
||||
{0.850651f, -0.525731f, 0.000000f}, {0.955423f, -0.295242f, 0.000000f},
|
||||
{0.864188f, -0.442863f, 0.238856f}, {0.951056f, -0.162460f, 0.262866f},
|
||||
{0.809017f, -0.309017f, 0.500000f}, {0.681718f, -0.147621f, 0.716567f},
|
||||
{0.850651f, 0.000000f, 0.525731f}, {0.864188f, 0.442863f, -0.238856f},
|
||||
{0.809017f, 0.309017f, -0.500000f}, {0.951056f, 0.162460f, -0.262866f},
|
||||
{0.525731f, 0.000000f, -0.850651f}, {0.681718f, 0.147621f, -0.716567f},
|
||||
{0.681718f, -0.147621f, -0.716567f}, {0.850651f, 0.000000f, -0.525731f},
|
||||
{0.809017f, -0.309017f, -0.500000f}, {0.864188f, -0.442863f, -0.238856f},
|
||||
{0.951056f, -0.162460f, -0.262866f}, {0.147621f, 0.716567f, -0.681718f},
|
||||
{0.309017f, 0.500000f, -0.809017f}, {0.425325f, 0.688191f, -0.587785f},
|
||||
{0.442863f, 0.238856f, -0.864188f}, {0.587785f, 0.425325f, -0.688191f},
|
||||
{0.688191f, 0.587785f, -0.425325f}, {-0.147621f, 0.716567f, -0.681718f},
|
||||
{-0.309017f, 0.500000f, -0.809017f}, {0.000000f, 0.525731f, -0.850651f},
|
||||
{-0.525731f, 0.000000f, -0.850651f}, {-0.442863f, 0.238856f, -0.864188f},
|
||||
{-0.295242f, 0.000000f, -0.955423f}, {-0.162460f, 0.262866f, -0.951056f},
|
||||
{0.000000f, 0.000000f, -1.000000f}, {0.295242f, 0.000000f, -0.955423f},
|
||||
{0.162460f, 0.262866f, -0.951056f}, {-0.442863f, -0.238856f, -0.864188f},
|
||||
{-0.309017f, -0.500000f, -0.809017f}, {-0.162460f, -0.262866f, -0.951056f},
|
||||
{0.000000f, -0.850651f, -0.525731f}, {-0.147621f, -0.716567f, -0.681718f},
|
||||
{0.147621f, -0.716567f, -0.681718f}, {0.000000f, -0.525731f, -0.850651f},
|
||||
{0.309017f, -0.500000f, -0.809017f}, {0.442863f, -0.238856f, -0.864188f},
|
||||
{0.162460f, -0.262866f, -0.951056f}, {0.238856f, -0.864188f, -0.442863f},
|
||||
{0.500000f, -0.809017f, -0.309017f}, {0.425325f, -0.688191f, -0.587785f},
|
||||
{0.716567f, -0.681718f, -0.147621f}, {0.688191f, -0.587785f, -0.425325f},
|
||||
{0.587785f, -0.425325f, -0.688191f}, {0.000000f, -0.955423f, -0.295242f},
|
||||
{0.000000f, -1.000000f, 0.000000f}, {0.262866f, -0.951056f, -0.162460f},
|
||||
{0.000000f, -0.850651f, 0.525731f}, {0.000000f, -0.955423f, 0.295242f},
|
||||
{0.238856f, -0.864188f, 0.442863f}, {0.262866f, -0.951056f, 0.162460f},
|
||||
{0.500000f, -0.809017f, 0.309017f}, {0.716567f, -0.681718f, 0.147621f},
|
||||
{0.525731f, -0.850651f, 0.000000f}, {-0.238856f, -0.864188f, -0.442863f},
|
||||
{-0.500000f, -0.809017f, -0.309017f}, {-0.262866f, -0.951056f, -0.162460f},
|
||||
{-0.850651f, -0.525731f, 0.000000f}, {-0.716567f, -0.681718f, -0.147621f},
|
||||
{-0.716567f, -0.681718f, 0.147621f}, {-0.525731f, -0.850651f, 0.000000f},
|
||||
{-0.500000f, -0.809017f, 0.309017f}, {-0.238856f, -0.864188f, 0.442863f},
|
||||
{-0.262866f, -0.951056f, 0.162460f}, {-0.864188f, -0.442863f, 0.238856f},
|
||||
{-0.809017f, -0.309017f, 0.500000f}, {-0.688191f, -0.587785f, 0.425325f},
|
||||
{-0.681718f, -0.147621f, 0.716567f}, {-0.442863f, -0.238856f, 0.864188f},
|
||||
{-0.587785f, -0.425325f, 0.688191f}, {-0.309017f, -0.500000f, 0.809017f},
|
||||
{-0.147621f, -0.716567f, 0.681718f}, {-0.425325f, -0.688191f, 0.587785f},
|
||||
{-0.162460f, -0.262866f, 0.951056f}, {0.442863f, -0.238856f, 0.864188f},
|
||||
{0.162460f, -0.262866f, 0.951056f}, {0.309017f, -0.500000f, 0.809017f},
|
||||
{0.147621f, -0.716567f, 0.681718f}, {0.000000f, -0.525731f, 0.850651f},
|
||||
{0.425325f, -0.688191f, 0.587785f}, {0.587785f, -0.425325f, 0.688191f},
|
||||
{0.688191f, -0.587785f, 0.425325f}, {-0.955423f, 0.295242f, 0.000000f},
|
||||
{-0.951056f, 0.162460f, 0.262866f}, {-1.000000f, 0.000000f, 0.000000f},
|
||||
{-0.850651f, 0.000000f, 0.525731f}, {-0.955423f, -0.295242f, 0.000000f},
|
||||
{-0.951056f, -0.162460f, 0.262866f}, {-0.864188f, 0.442863f, -0.238856f},
|
||||
{-0.951056f, 0.162460f, -0.262866f}, {-0.809017f, 0.309017f, -0.500000f},
|
||||
{-0.864188f, -0.442863f, -0.238856f}, {-0.951056f, -0.162460f, -0.262866f},
|
||||
{-0.809017f, -0.309017f, -0.500000f}, {-0.681718f, 0.147621f, -0.716567f},
|
||||
{-0.681718f, -0.147621f, -0.716567f}, {-0.850651f, 0.000000f, -0.525731f},
|
||||
{-0.688191f, 0.587785f, -0.425325f}, {-0.587785f, 0.425325f, -0.688191f},
|
||||
{-0.425325f, 0.688191f, -0.587785f}, {-0.425325f, -0.688191f, -0.587785f},
|
||||
{-0.587785f, -0.425325f, -0.688191f}, {-0.688191f, -0.587785f, -0.425325f}};
|
||||
|
||||
}
|
||||
@@ -0,0 +1,32 @@
|
||||
/*
|
||||
# ______ ____ ___
|
||||
# | \/ ____| |___|
|
||||
# | | | \ | |
|
||||
#-----------------------------------------------------------------------
|
||||
# Copyright 2020, tyra - https://github.com/h4570/tyra
|
||||
# Licenced under Apache License 2.0
|
||||
# Sandro Sobczyński <sandro.sobczynski@gmail.com>
|
||||
*/
|
||||
|
||||
#pragma once
|
||||
|
||||
#include <string>
|
||||
|
||||
namespace Tyra {
|
||||
|
||||
/** Class responsible for loading&parsing Quake's II ".md2" 3D files */
|
||||
class MD2Loader : public Loader {
|
||||
public:
|
||||
MD2Loader();
|
||||
~MD2Loader();
|
||||
|
||||
MeshBuilderData* load(const char* fullpath, const float& t_scale,
|
||||
const u8& t_invertT);
|
||||
|
||||
inline MeshBuilderData* load(const std::string& fullpath,
|
||||
const float& t_scale, const u8& t_invertT) {
|
||||
return load(fullpath.c_str(), t_scale, t_invertT);
|
||||
}
|
||||
};
|
||||
|
||||
} // namespace Tyra
|
||||
@@ -0,0 +1,23 @@
|
||||
/*
|
||||
# ______ ____ ___
|
||||
# | \/ ____| |___|
|
||||
# | | | \ | |
|
||||
#-----------------------------------------------------------------------
|
||||
# Copyright 2020, tyra - https://github.com/h4570/tyra
|
||||
# Licenced under Apache License 2.0
|
||||
# Sandro Sobczyński <sandro.sobczynski@gmail.com>
|
||||
*/
|
||||
|
||||
#pragma once
|
||||
|
||||
#include <string>
|
||||
|
||||
namespace Tyra {
|
||||
|
||||
class Loader {
|
||||
protected:
|
||||
std::string getFilenameFromPath(const std::string& path);
|
||||
std::string getFilenameWithoutExtension(const std::string& filename);
|
||||
};
|
||||
|
||||
} // namespace Tyra
|
||||
@@ -0,0 +1,35 @@
|
||||
/*
|
||||
# ______ ____ ___
|
||||
# | \/ ____| |___|
|
||||
# | | | \ | |
|
||||
#-----------------------------------------------------------------------
|
||||
# Copyright 2020, tyra - https://github.com/h4570/tyra
|
||||
# Licenced under Apache License 2.0
|
||||
# Sandro Sobczyński <sandro.sobczynski@gmail.com>
|
||||
*/
|
||||
|
||||
#pragma once
|
||||
|
||||
#include "loaders/loader.hpp"
|
||||
#include "loaders/texture/builder/texture_builder_data.hpp"
|
||||
#include "renderer/core/texture/models/texture_bpp.hpp"
|
||||
#include <string>
|
||||
|
||||
namespace Tyra {
|
||||
class TextureLoader : public Loader {
|
||||
public:
|
||||
/**
|
||||
* @brief Loads texture data from file.
|
||||
* Sets size, name and data.
|
||||
* @param fullpath Full path to texture file. Example: "host:texture.png"
|
||||
*/
|
||||
virtual TextureBuilderData* load(const char* fullpath) = 0;
|
||||
|
||||
inline TextureBuilderData* load(const std::string& fullpath) {
|
||||
return load(fullpath.c_str());
|
||||
}
|
||||
|
||||
u32 getTextureSize(const u32& width, const u32& height,
|
||||
const TextureBpp& bpp);
|
||||
};
|
||||
} // namespace Tyra
|
||||
@@ -0,0 +1,34 @@
|
||||
/*
|
||||
# ______ ____ ___
|
||||
# | \/ ____| |___|
|
||||
# | | | \ | |
|
||||
#-----------------------------------------------------------------------
|
||||
# Copyright 2020, tyra - https://github.com/h4570/tyra
|
||||
# Licenced under Apache License 2.0
|
||||
# Sandro Sobczyński <sandro.sobczynski@gmail.com>
|
||||
*/
|
||||
|
||||
#pragma once
|
||||
|
||||
#include "loaders/texture/base/texture_loader.hpp"
|
||||
#include "loaders/texture/png_loader.hpp"
|
||||
#include <string>
|
||||
|
||||
namespace Tyra {
|
||||
class TextureLoaderSelector {
|
||||
public:
|
||||
TextureLoaderSelector();
|
||||
~TextureLoaderSelector();
|
||||
|
||||
TextureLoader& getLoaderByFileName(const char* fullpath);
|
||||
|
||||
inline TextureLoader& getLoaderByFileName(const std::string& fullpath) {
|
||||
return getLoaderByFileName(fullpath.c_str());
|
||||
}
|
||||
|
||||
TextureLoader& getLoaderByExtension(const std::string& extension);
|
||||
|
||||
private:
|
||||
PngLoader pngLoader;
|
||||
};
|
||||
} // namespace Tyra
|
||||
@@ -0,0 +1,36 @@
|
||||
/*
|
||||
# ______ ____ ___
|
||||
# | \/ ____| |___|
|
||||
# | | | \ | |
|
||||
#-----------------------------------------------------------------------
|
||||
# Copyright 2020, tyra - https://github.com/h4570/tyra
|
||||
# Licenced under Apache License 2.0
|
||||
# Sandro Sobczyński <sandro.sobczynski@gmail.com>
|
||||
*/
|
||||
|
||||
#pragma once
|
||||
|
||||
#include <tamtypes.h>
|
||||
#include <string>
|
||||
#include "renderer/core/texture/models/texture_bpp.hpp"
|
||||
|
||||
namespace Tyra {
|
||||
|
||||
class TextureBuilderData {
|
||||
public:
|
||||
TextureBuilderData();
|
||||
~TextureBuilderData();
|
||||
|
||||
std::string name;
|
||||
|
||||
int width, height;
|
||||
unsigned char* data;
|
||||
TextureBpp bpp;
|
||||
unsigned char gsComponents;
|
||||
|
||||
int clutWidth, clutHeight;
|
||||
unsigned char* clut;
|
||||
TextureBpp clutBpp;
|
||||
unsigned char clutGsComponents;
|
||||
};
|
||||
} // namespace Tyra
|
||||
@@ -0,0 +1,56 @@
|
||||
/*
|
||||
# ______ ____ ___
|
||||
# | \/ ____| |___|
|
||||
# | | | \ | |
|
||||
#-----------------------------------------------------------------------
|
||||
# Copyright 2020, tyra - https://github.com/h4570/tyra
|
||||
# Licenced under Apache License 2.0
|
||||
# Sandro Sobczyński <sandro.sobczynski@gmail.com>
|
||||
*/
|
||||
|
||||
#pragma once
|
||||
|
||||
#include "loaders/texture/base/texture_loader.hpp"
|
||||
#include "renderer/core/texture/models/texture.hpp"
|
||||
|
||||
#ifdef INTELLISENSE
|
||||
typedef void* png_structp;
|
||||
typedef void* png_bytep;
|
||||
typedef void* png_infop;
|
||||
typedef void* png_colorp;
|
||||
#else
|
||||
#include <png.h>
|
||||
#endif
|
||||
|
||||
namespace Tyra {
|
||||
|
||||
class PngLoader : public TextureLoader {
|
||||
public:
|
||||
PngLoader();
|
||||
~PngLoader();
|
||||
|
||||
TextureBuilderData* load(const char* fullpath);
|
||||
|
||||
private:
|
||||
void handle32bpp(TextureBuilderData* result, png_structp pngPtr,
|
||||
png_infop infoPtr, png_bytep* rowPointers);
|
||||
|
||||
void handle24bpp(TextureBuilderData* result, png_structp pngPtr,
|
||||
png_infop infoPtr, png_bytep* rowPointers);
|
||||
|
||||
void handlePalletized(TextureBuilderData* result, png_structp pngPtr,
|
||||
png_infop infoPtr, png_bytep* rowPointers,
|
||||
const int& bitDepth);
|
||||
|
||||
void handle8bppPalletized(TextureBuilderData* result, png_structp pngPtr,
|
||||
png_infop infoPtr, png_bytep* rowPointers,
|
||||
png_colorp palette, png_bytep trans,
|
||||
const int& numPallete, const int& numTrans);
|
||||
|
||||
void handle4bppPalletized(TextureBuilderData* result, png_structp pngPtr,
|
||||
png_infop infoPtr, png_bytep* rowPointers,
|
||||
png_colorp palette, png_bytep trans,
|
||||
const int& numPallete, const int& numTrans);
|
||||
};
|
||||
|
||||
} // namespace Tyra
|
||||
@@ -0,0 +1,194 @@
|
||||
/*
|
||||
# ______ ____ ___
|
||||
# | \/ ____| |___|
|
||||
# | | | \ | |
|
||||
#-----------------------------------------------------------------------
|
||||
# Copyright 2022, tyra - https://github.com/h4570/tyra
|
||||
# Licenced under Apache License 2.0
|
||||
# Sandro Sobczyński <sandro.sobczynski@gmail.com>
|
||||
*/
|
||||
|
||||
#pragma once
|
||||
|
||||
#include "math/vec4.hpp"
|
||||
#include "math/math.hpp"
|
||||
|
||||
namespace Tyra {
|
||||
|
||||
class M4x4 {
|
||||
public:
|
||||
MATRIX data alignas(sizeof(float) * 16);
|
||||
|
||||
/**
|
||||
* @param identity true = identity matrix, false = random values
|
||||
*/
|
||||
explicit M4x4(const bool& identity = true);
|
||||
M4x4(const M4x4& v) { copy(this, v); }
|
||||
explicit M4x4(const float* v) { copy(this, v); }
|
||||
inline M4x4(const float& m11, const float& m12, const float& m13,
|
||||
const float& m14, const float& m21, const float& m22,
|
||||
const float& m23, const float& m24, const float& m31,
|
||||
const float& m32, const float& m33, const float& m34,
|
||||
const float& m41, const float& m42, const float& m43,
|
||||
const float& m44) {
|
||||
set(m11, m12, m13, m14, m21, m22, m23, m24, m31, m32, m33, m34, m41, m42,
|
||||
m43, m44);
|
||||
}
|
||||
|
||||
static void copy(M4x4* out, const float* in);
|
||||
static void copy(M4x4* out, const M4x4& in) { copy(out, in.data); }
|
||||
|
||||
void operator=(const M4x4& v);
|
||||
Vec4 operator*(const Vec4& v) const;
|
||||
|
||||
M4x4 operator*(const M4x4& v) const {
|
||||
M4x4 result;
|
||||
cross(result.data, this->data, v.data);
|
||||
return result;
|
||||
}
|
||||
|
||||
void operator*=(const M4x4& v) { cross(this->data, this->data, v.data); }
|
||||
|
||||
float& operator[](const u8& index) { return data[index]; }
|
||||
|
||||
/**
|
||||
* 1 0 0 0
|
||||
* 0 1 0 0
|
||||
* 0 0 1 0
|
||||
* 0 0 0 1
|
||||
*/
|
||||
void identity();
|
||||
|
||||
/**
|
||||
* 1 0 0 0
|
||||
* 0 1 0 0
|
||||
* 0 0 1 0
|
||||
* 0 0 0 1
|
||||
*/
|
||||
void unit() { identity(); }
|
||||
|
||||
void set(const float& m11, const float& m12, const float& m13,
|
||||
const float& m14, const float& m21, const float& m22,
|
||||
const float& m23, const float& m24, const float& m31,
|
||||
const float& m32, const float& m33, const float& m34,
|
||||
const float& m41, const float& m42, const float& m43,
|
||||
const float& m44);
|
||||
|
||||
void translate(const Vec4& v) {
|
||||
M4x4 temp = M4x4(true);
|
||||
temp.translationX(v.x);
|
||||
temp.translationY(v.y);
|
||||
temp.translationZ(v.z);
|
||||
cross(this->data, temp.data, this->data);
|
||||
}
|
||||
|
||||
void translateX(const float& v) {
|
||||
M4x4 temp = M4x4(true);
|
||||
temp.translationX(v);
|
||||
cross(this->data, temp.data, this->data);
|
||||
}
|
||||
|
||||
void translateY(const float& v) {
|
||||
M4x4 temp = M4x4(true);
|
||||
temp.translationY(v);
|
||||
cross(this->data, temp.data, this->data);
|
||||
}
|
||||
|
||||
void translateZ(const float& v) {
|
||||
M4x4 temp = M4x4(true);
|
||||
temp.translationZ(v);
|
||||
cross(this->data, temp.data, this->data);
|
||||
}
|
||||
|
||||
/** Rotate M4x4. */
|
||||
void rotate(const Vec4& v) {
|
||||
M4x4 temp = M4x4(true);
|
||||
|
||||
temp.rotationZ(v.z);
|
||||
cross(this->data, temp.data, this->data);
|
||||
|
||||
temp.identity();
|
||||
temp.rotationY(v.y);
|
||||
cross(this->data, temp.data, this->data);
|
||||
|
||||
temp.identity();
|
||||
temp.rotationX(v.x);
|
||||
cross(this->data, temp.data, this->data);
|
||||
}
|
||||
|
||||
/** Rotate M4x4 by X. */
|
||||
void rotateX(const float& radians) {
|
||||
M4x4 temp = M4x4(true);
|
||||
temp.rotationX(radians);
|
||||
cross(this->data, temp.data, this->data);
|
||||
}
|
||||
|
||||
/** Rotate M4x4 by Y. */
|
||||
void rotateY(const float& radians) {
|
||||
M4x4 temp = M4x4(true);
|
||||
temp.rotationY(radians);
|
||||
cross(this->data, temp.data, this->data);
|
||||
}
|
||||
|
||||
/** Rotate M4x4 by Z. */
|
||||
void rotateZ(const float& radians) {
|
||||
M4x4 temp = M4x4(true);
|
||||
temp.rotationZ(radians);
|
||||
cross(this->data, temp.data, this->data);
|
||||
}
|
||||
|
||||
/** Rotate M4x4 by angle. */
|
||||
void rotateByAngle(const float& angle, const Vec4& axis) {
|
||||
M4x4 temp;
|
||||
temp.rotationByAngle(angle, axis);
|
||||
cross(this->data, temp.data, this->data);
|
||||
}
|
||||
|
||||
void scale(const float& v) { scale(Vec4(v, v, v, 1.0F)); }
|
||||
void scaleX(const float& v) { scale(Vec4(v, 1.0F, 1.0F, 1.0F)); }
|
||||
void scaleY(const float& v) { scale(Vec4(1.0F, v, 1.0F, 1.0F)); }
|
||||
void scaleZ(const float& v) { scale(Vec4(1.0F, 1.0F, v, 1.0F)); }
|
||||
|
||||
void scale(const Vec4& v) {
|
||||
M4x4 temp = M4x4(true);
|
||||
temp.setScale(v);
|
||||
cross(this->data, temp.data, this->data);
|
||||
}
|
||||
|
||||
/** Create perspective projection M4x4 (gluPerspective) */
|
||||
static M4x4 perspective(const float& fov, const float& width,
|
||||
const float& height, const float& projectionScale,
|
||||
const float& aspectRatio, const float& near,
|
||||
const float& far);
|
||||
|
||||
/**
|
||||
* Create a view M4x4 that transforms coordinates in
|
||||
* such a way that the user looks at a target vector
|
||||
* direction from a position vector (glLookAt)
|
||||
*/
|
||||
static M4x4 lookAt(const Vec4& position, const Vec4& target);
|
||||
static void lookAt(M4x4* res, const Vec4& position, const Vec4& target);
|
||||
|
||||
void print() const;
|
||||
void print(const char* name) const;
|
||||
void print(const std::string& name) const { print(name.c_str()); }
|
||||
std::string getPrint(const char* name = nullptr) const;
|
||||
|
||||
private:
|
||||
static float upVec[4] alignas(sizeof(float) * 4);
|
||||
static float viewVec[4] alignas(sizeof(float) * 4);
|
||||
|
||||
static void cross(float res[16], const float a[16], const float b[16]);
|
||||
void rotationX(const float& v);
|
||||
void rotationY(const float& v);
|
||||
void rotationZ(const float& v);
|
||||
void rotationByAngle(const float& angle, const Vec4& axis);
|
||||
void translationX(const float& v);
|
||||
void translationY(const float& v);
|
||||
void translationZ(const float& v);
|
||||
void setScale(const Vec4& val);
|
||||
static M4x4 setCamera(const float pos[4], const float vz[4],
|
||||
const float vy[4]);
|
||||
};
|
||||
|
||||
} // namespace Tyra
|
||||
@@ -0,0 +1,38 @@
|
||||
/*
|
||||
# ______ ____ ___
|
||||
# | \/ ____| |___|
|
||||
# | | | \ | |
|
||||
#-----------------------------------------------------------------------
|
||||
# Copyright 2022, tyra - https://github.com/h4570/tyra
|
||||
# Licenced under Apache License 2.0
|
||||
# Sandro Sobczyński <sandro.sobczynski@gmail.com>
|
||||
*/
|
||||
|
||||
#pragma once
|
||||
|
||||
extern "C" {
|
||||
#include <tamtypes.h>
|
||||
}
|
||||
|
||||
#include <math.h>
|
||||
|
||||
namespace Tyra {
|
||||
|
||||
class Math {
|
||||
public:
|
||||
constexpr static float HALF_ANG2RAD = 3.14159265358979323846F / 360.0F;
|
||||
constexpr static float ANG2RAD = 3.14159265358979323846F / 180.0F;
|
||||
constexpr static float PI = 3.1415926535897932384626433832795F;
|
||||
constexpr static float HALF_PI = 1.5707963267948966192313216916398F;
|
||||
static float cos(float x);
|
||||
static float asin(float x);
|
||||
static float mod(float x, float y);
|
||||
static inline float sin(float x) { return cos(x - HALF_PI); }
|
||||
static inline float tan(float x) { return sin(x) / cos(x); }
|
||||
static float invSqrt(float x);
|
||||
|
||||
private:
|
||||
Math();
|
||||
};
|
||||
|
||||
} // namespace Tyra
|
||||
@@ -0,0 +1,36 @@
|
||||
/*
|
||||
# ______ ____ ___
|
||||
# | \/ ____| |___|
|
||||
# | | | \ | |
|
||||
#-----------------------------------------------------------------------
|
||||
# Copyright 2022, tyra - https://github.com/h4570/tyra
|
||||
# Licenced under Apache License 2.0
|
||||
# Sandro Sobczyński <sandro.sobczynski@gmail.com>
|
||||
*/
|
||||
|
||||
#pragma once
|
||||
|
||||
|
||||
namespace Tyra {
|
||||
|
||||
class Plane {
|
||||
public:
|
||||
Vec4 normal;
|
||||
float distance;
|
||||
|
||||
Plane();
|
||||
Plane(const Vec4& a, const Vec4& b, const Vec4& c);
|
||||
~Plane();
|
||||
|
||||
void update(const Vec4& a, const Vec4& b, const Vec4& c);
|
||||
inline float distanceTo(const Vec4& t_vec) const {
|
||||
return this->distance + this->normal.innerProduct(t_vec);
|
||||
}
|
||||
|
||||
void print() const;
|
||||
void print(const char* name) const;
|
||||
void print(const std::string& name) const { print(name.c_str()); }
|
||||
std::string getPrint(const char* name = nullptr) const;
|
||||
};
|
||||
|
||||
} // namespace Tyra
|
||||
@@ -0,0 +1,49 @@
|
||||
/*
|
||||
# ______ ____ ___
|
||||
# | \/ ____| |___|
|
||||
# | | | \ | |
|
||||
#-----------------------------------------------------------------------
|
||||
# Copyright 2022, tyra - https://github.com/h4570/tyra
|
||||
# Licenced under Apache License 2.0
|
||||
# Sandro Sobczyński <sandro.sobczynski@gmail.com>
|
||||
*/
|
||||
|
||||
#pragma once
|
||||
|
||||
extern "C" {
|
||||
#include <stdio.h>
|
||||
#include <tamtypes.h>
|
||||
}
|
||||
|
||||
#include <iomanip>
|
||||
#include <string>
|
||||
#include "math/math.hpp"
|
||||
|
||||
namespace Tyra {
|
||||
|
||||
class Vec2 {
|
||||
public:
|
||||
union {
|
||||
struct {
|
||||
float x;
|
||||
float y;
|
||||
};
|
||||
float xy[2] alignas(sizeof(float) * 2);
|
||||
};
|
||||
|
||||
Vec2(const float& t_x, const float& t_y);
|
||||
Vec2(const Vec2& v);
|
||||
Vec2();
|
||||
~Vec2();
|
||||
|
||||
void set(const float& t_x, const float& t_y);
|
||||
void set(const Vec2& v);
|
||||
void rotate(const float& t_angle, const float& t_x, const float& t_y);
|
||||
|
||||
void print() const;
|
||||
void print(const char* name) const;
|
||||
void print(const std::string& name) const { print(name.c_str()); }
|
||||
std::string getPrint(const char* name = nullptr) const;
|
||||
};
|
||||
|
||||
} // namespace Tyra
|
||||
@@ -0,0 +1,151 @@
|
||||
/*
|
||||
# ______ ____ ___
|
||||
# | \/ ____| |___|
|
||||
# | | | \ | |
|
||||
#-----------------------------------------------------------------------
|
||||
# Copyright 2022, tyra - https://github.com/h4570/tyra
|
||||
# Licenced under Apache License 2.0
|
||||
# Sandro Sobczyński <sandro.sobczynski@gmail.com>
|
||||
*/
|
||||
|
||||
#pragma once
|
||||
|
||||
extern "C" {
|
||||
#include <stdio.h>
|
||||
#include <tamtypes.h>
|
||||
}
|
||||
|
||||
#include <math3d.h>
|
||||
#include <iomanip>
|
||||
#include <cmath>
|
||||
#include <sstream>
|
||||
#include <string>
|
||||
#include "math/math.hpp"
|
||||
|
||||
namespace Tyra {
|
||||
|
||||
class Vec4 {
|
||||
public:
|
||||
union {
|
||||
struct {
|
||||
float x;
|
||||
float y;
|
||||
float z;
|
||||
float w;
|
||||
};
|
||||
VECTOR xyzw alignas(sizeof(float) * 4);
|
||||
};
|
||||
|
||||
static void copy(Vec4* out, const float* in);
|
||||
static inline void copy(Vec4* out, const Vec4& in) { copy(out, in.xyzw); }
|
||||
|
||||
/** Initialize Vec4 without setting default values */
|
||||
Vec4() {}
|
||||
|
||||
/** Initialize Vec4 with provided values */
|
||||
Vec4(const float& x, const float& y = 0.0F, const float& z = 0.0F,
|
||||
const float& w = 1.0F)
|
||||
: x(x), y(y), z(z), w(w) {}
|
||||
|
||||
/** Initialize Vec4 with other Vec4 values */
|
||||
Vec4(const Vec4& v) { copy(this, v); }
|
||||
|
||||
/** Initialize Vec4 with float[4] values */
|
||||
explicit Vec4(const float* v) { copy(this, v); }
|
||||
|
||||
Vec4 operator+(const Vec4& v) const;
|
||||
Vec4 operator-(const Vec4& v) const;
|
||||
/** Cross product */
|
||||
Vec4 operator*(const Vec4& v) const;
|
||||
Vec4 operator*(const float& v) const;
|
||||
Vec4 operator/(const float& v) const;
|
||||
Vec4 operator-(void) const;
|
||||
void operator=(const Vec4& v);
|
||||
void operator+=(const Vec4& v);
|
||||
void operator*=(const float& v);
|
||||
void operator*=(const Vec4& v);
|
||||
void operator/=(const float& v);
|
||||
|
||||
inline void set(const Vec4& v) { copy(this, v.xyzw); }
|
||||
inline void set(const float* v) { copy(this, v); }
|
||||
void set(const float& x, const float& y = 0.0F, const float& z = 0.0F,
|
||||
const float& w = 1.0F);
|
||||
|
||||
Vec4 cross(const Vec4& v) const;
|
||||
|
||||
void rotateZ(const int& angle);
|
||||
|
||||
int getRelativeCosBetween(const Vec4& v) const;
|
||||
int getRelativeAngleBetween(const Vec4& v) const;
|
||||
|
||||
float innerProduct(const Vec4& v) const;
|
||||
inline float dot3(const Vec4& v) const { return innerProduct(v); }
|
||||
|
||||
/** Get vector length */
|
||||
float length() const;
|
||||
|
||||
/** Normalize vector */
|
||||
void normalize();
|
||||
|
||||
/** Returns distance between two vectors */
|
||||
float distanceTo(const Vec4& v) const;
|
||||
|
||||
/**
|
||||
* Checks intersection with given box
|
||||
* @param min Opposite min vertex (ex. near, left, down vertex of bounding
|
||||
* box)
|
||||
* @param max Opposite max vertex (ex. far, right, up vertex of bounding
|
||||
* box)
|
||||
*/
|
||||
u8 collidesBox(const Vec4& min, const Vec4& max) const {
|
||||
return ((this->x <= max.x && this->x >= min.x) &&
|
||||
(this->y < max.y && this->y >= min.y) &&
|
||||
(this->z <= max.z && this->z >= min.z))
|
||||
? 1
|
||||
: 0;
|
||||
}
|
||||
|
||||
/**
|
||||
* Checks if this vector is on given box (this->y >= box.y)
|
||||
* @param min Opposite min vertex (ex. near, left, down vertex of bounding
|
||||
* box)
|
||||
* @param max Opposite max vertex (ex. far, right, up vertex of bounding
|
||||
* box)
|
||||
*/
|
||||
u8 isOnBox(const Vec4& min, const Vec4& max) const {
|
||||
return ((this->x <= max.x && this->x >= min.x) && (this->y >= max.y) &&
|
||||
(this->z <= max.z && this->z >= min.z))
|
||||
? 1
|
||||
: 0;
|
||||
}
|
||||
|
||||
/** Check if given triangle should be backface culled */
|
||||
static u8 shouldBeBackfaceCulled(const Vec4* cameraPos, const Vec4* v0,
|
||||
const Vec4* v1, const Vec4* v2);
|
||||
|
||||
/**
|
||||
* Update this vector by linear interpolation between two vertices
|
||||
* @param v1 Before vertex
|
||||
* @param v2 After vertex
|
||||
* @param interp State of interpolation
|
||||
*/
|
||||
void lerp(const Vec4& v1, const Vec4& v2, const float& interp);
|
||||
|
||||
/**
|
||||
* Get vector by linear interpolation between two vertices
|
||||
* @param v1 Before vertex
|
||||
* @param v2 After vertex
|
||||
* @param interp State of interpolation
|
||||
*/
|
||||
static Vec4 getByLerp(const Vec4& v1, const Vec4& v2, const float& interp);
|
||||
|
||||
void print() const;
|
||||
void print(const char* name) const;
|
||||
void print(const std::string& name) const { print(name.c_str()); }
|
||||
std::string getPrint(const char* name = nullptr) const;
|
||||
|
||||
static void setLerp(Vec4* output, const Vec4& v1, const Vec4& v2,
|
||||
const float& interp);
|
||||
};
|
||||
|
||||
} // namespace Tyra
|
||||
@@ -0,0 +1,37 @@
|
||||
/*
|
||||
# ______ ____ ___
|
||||
# | \/ ____| |___|
|
||||
# | | | \ | |
|
||||
#-----------------------------------------------------------------------
|
||||
# Copyright 2022, tyra - https://github.com/h4570/tyra
|
||||
# Licenced under Apache License 2.0
|
||||
# Sandro Sobczyński <sandro.sobczynski@gmail.com>
|
||||
*/
|
||||
|
||||
#pragma once
|
||||
|
||||
#include <packet2_utils.h>
|
||||
#include "math/m4x4.hpp"
|
||||
#include "renderer/models/color.hpp"
|
||||
|
||||
namespace Tyra {
|
||||
|
||||
class Packet2TyraUtils {
|
||||
public:
|
||||
inline static void addM4x4(packet2_t* packet2, const M4x4& val) {
|
||||
*(reinterpret_cast<M4x4*>(packet2->next)) = val;
|
||||
packet2_advance_next(packet2, sizeof(MATRIX));
|
||||
}
|
||||
|
||||
inline static void addVec4(packet2_t* packet2, const Vec4& val) {
|
||||
*(reinterpret_cast<Vec4*>(packet2->next)) = val;
|
||||
packet2_advance_next(packet2, sizeof(VECTOR));
|
||||
}
|
||||
|
||||
inline static void addColor(packet2_t* packet2, const Color& val) {
|
||||
*(reinterpret_cast<Color*>(packet2->next)) = val;
|
||||
packet2_advance_next(packet2, sizeof(VECTOR));
|
||||
}
|
||||
};
|
||||
|
||||
} // namespace Tyra
|
||||
@@ -0,0 +1,58 @@
|
||||
/*
|
||||
# ______ ____ ___
|
||||
# | \/ ____| |___|
|
||||
# | | | \ | |
|
||||
#-----------------------------------------------------------------------
|
||||
# Copyright 2020-2022, tyra - https://github.com/h4570/tyrav2
|
||||
# Licenced under Apache License 2.0
|
||||
# Sandro Sobczyński <sandro.sobczynski@gmail.com>
|
||||
# Sandro Wellinator <wellcoj@gmail.com>
|
||||
*/
|
||||
|
||||
#include <kernel.h>
|
||||
#include <libpad.h>
|
||||
|
||||
#pragma once
|
||||
|
||||
namespace Tyra {
|
||||
|
||||
struct PadButtons {
|
||||
u8 Cross, Square, Triangle, Circle, DpadUp, DpadDown, DpadLeft, DpadRight, L1,
|
||||
L2, L3, R1, R2, R3, Start, Select;
|
||||
};
|
||||
|
||||
struct PadJoy {
|
||||
u8 h, v, isCentered, isMoved;
|
||||
};
|
||||
|
||||
/** Class responsible for player pad */
|
||||
class Pad {
|
||||
public:
|
||||
Pad();
|
||||
~Pad();
|
||||
|
||||
void init();
|
||||
void update();
|
||||
|
||||
inline const PadButtons& getClicked() { return clicked; }
|
||||
inline const PadButtons& getPressed() { return pressed; }
|
||||
inline const PadJoy& getLeftJoyPad() { return leftJoyPad; }
|
||||
inline const PadJoy& getRightJoyPad() { return rightJoyPad; }
|
||||
|
||||
private:
|
||||
char padBuf[256] alignas(sizeof(char) * 256);
|
||||
char actAlign[6];
|
||||
int actuators, ret, port, slot;
|
||||
padButtonStatus buttons;
|
||||
u32 padData, oldPad, newPad;
|
||||
PadButtons pressed, clicked;
|
||||
PadJoy leftJoyPad, rightJoyPad;
|
||||
|
||||
void reset();
|
||||
void handleClickedButtons();
|
||||
void handlePressedButtons();
|
||||
int waitPadReady();
|
||||
int initPad();
|
||||
};
|
||||
|
||||
} // namespace Tyra
|
||||
@@ -0,0 +1,30 @@
|
||||
/*
|
||||
# ______ ____ ___
|
||||
# | \/ ____| |___|
|
||||
# | | | \ | |
|
||||
#-----------------------------------------------------------------------
|
||||
# Copyright 2022, tyra - https://github.com/h4570/tyra
|
||||
# Licenced under Apache License 2.0
|
||||
# Sandro Sobczyński <sandro.sobczynski@gmail.com>
|
||||
*/
|
||||
|
||||
#pragma once
|
||||
|
||||
#include "renderer/core/2d/sprite/sprite.hpp"
|
||||
#include "renderer/core/renderer_core.hpp"
|
||||
|
||||
namespace Tyra {
|
||||
|
||||
class Renderer2D {
|
||||
public:
|
||||
Renderer2D();
|
||||
~Renderer2D();
|
||||
|
||||
void init(RendererCore* rendererCore);
|
||||
void render(Sprite* sprite);
|
||||
|
||||
private:
|
||||
RendererCore* core;
|
||||
};
|
||||
|
||||
} // namespace Tyra
|
||||
@@ -0,0 +1,64 @@
|
||||
/*
|
||||
# ______ ____ ___
|
||||
# | \/ ____| |___|
|
||||
# | | | \ | |
|
||||
#-----------------------------------------------------------------------
|
||||
# Copyright 2022, tyra - https://github.com/h4570/tyra
|
||||
# Licenced under Apache License 2.0
|
||||
# Sandro Sobczyński <sandro.sobczynski@gmail.com>
|
||||
*/
|
||||
|
||||
#pragma once
|
||||
|
||||
#include "./bbox_face.hpp"
|
||||
#include "renderer/core/3d/bbox/core_bbox.hpp"
|
||||
#include "math/vec4.hpp"
|
||||
|
||||
namespace Tyra {
|
||||
|
||||
/** Bounding box with more features */
|
||||
class BBox : public CoreBBox {
|
||||
public:
|
||||
explicit BBox(CoreBBox** t_bboxes, const u32& count);
|
||||
explicit BBox(Vec4* t_vertices, u32* faces, u32 t_count);
|
||||
explicit BBox(Vec4* t_vertices, u32 t_count);
|
||||
explicit BBox(Vec4* t_vertices);
|
||||
const float& getHeight() { return _height; }
|
||||
const float& getDepth() { return _depth; }
|
||||
const float& getWidth() { return _width; }
|
||||
/** @returns the vector directly in middle of the bounding box. */
|
||||
const Vec4& getCenter() { return _centerVector; }
|
||||
/** @returns the front face (further on z-axis) */
|
||||
const BBoxFace& getFrontFace() { return _frontFace; }
|
||||
/** @returns the back face (nearer on z-axis) */
|
||||
const BBoxFace& getBackFace() { return _backFace; }
|
||||
/** @returns the left face (further on x-axis) */
|
||||
const BBoxFace& getLeftFace() { return _leftFace; }
|
||||
/** @returns the right face (nearer on x-axis) */
|
||||
const BBoxFace& getRightFace() { return _rightFace; }
|
||||
/** @returns the top face (further on y-axis) */
|
||||
const BBoxFace& getTopFace() { return _topFace; }
|
||||
/** @returns the bottom face (nearer on y-axis) */
|
||||
const BBoxFace& getBottomFace() { return _bottomFace; }
|
||||
|
||||
protected:
|
||||
float _height, _depth, _width;
|
||||
Vec4 _centerVector;
|
||||
/** Front face (further on z-axis) */
|
||||
BBoxFace _frontFace;
|
||||
/** Back face (nearer on z-axis) */
|
||||
BBoxFace _backFace;
|
||||
/** Left face (nearer on x-axis) */
|
||||
BBoxFace _leftFace;
|
||||
/** Right face (further on x-axis) */
|
||||
BBoxFace _rightFace;
|
||||
/** Top face (further on y-axis) */
|
||||
BBoxFace _topFace;
|
||||
/** Bottom face (nearer on y-axis) */
|
||||
BBoxFace _bottomFace;
|
||||
|
||||
private:
|
||||
void setData();
|
||||
};
|
||||
|
||||
} // namespace Tyra
|
||||
@@ -0,0 +1,35 @@
|
||||
/*
|
||||
# ______ ____ ___
|
||||
# | \/ ____| |___|
|
||||
# | | | \ | |
|
||||
#-----------------------------------------------------------------------
|
||||
# Copyright 2022, tyra - https://github.com/h4570/tyra
|
||||
# Licenced under Apache License 2.0
|
||||
# Sandro Sobczyński <sandro.sobczynski@gmail.com>
|
||||
*/
|
||||
|
||||
#pragma once
|
||||
|
||||
#include "math/vec4.hpp"
|
||||
|
||||
namespace Tyra {
|
||||
|
||||
/** BBox face */
|
||||
class BBoxFace {
|
||||
public:
|
||||
BBoxFace() {}
|
||||
BBoxFace(const Vec4& t_minCorner, const Vec4& t_maxCorner, float t_axisPos) {
|
||||
minCorner = t_minCorner;
|
||||
maxCorner = t_maxCorner;
|
||||
axisPosition = t_axisPos;
|
||||
}
|
||||
|
||||
/** Position of the face on it's respective axis. */
|
||||
float axisPosition;
|
||||
/** Corner of the face with lower coordinates */
|
||||
Vec4 minCorner;
|
||||
/** Corner of the face with higher coordinates */
|
||||
Vec4 maxCorner;
|
||||
};
|
||||
|
||||
} // namespace Tyra
|
||||
@@ -0,0 +1,121 @@
|
||||
/*
|
||||
# ______ ____ ___
|
||||
# | \/ ____| |___|
|
||||
# | | | \ | |
|
||||
#-----------------------------------------------------------------------
|
||||
# Copyright 2022, tyra - https://github.com/h4570/tyra
|
||||
# Licenced under Apache License 2.0
|
||||
# Sandro Sobczyński <sandro.sobczynski@gmail.com>
|
||||
*/
|
||||
|
||||
#pragma once
|
||||
|
||||
#include "loaders/3d/builder/mesh_builder_data.hpp"
|
||||
#include "./mesh_frame.hpp"
|
||||
#include "./mesh_material_frame.hpp"
|
||||
#include "./mesh_anim_state.hpp"
|
||||
|
||||
namespace Tyra {
|
||||
|
||||
class Mesh {
|
||||
public:
|
||||
explicit Mesh(const MeshBuilderData& data);
|
||||
explicit Mesh(const Mesh& mesh);
|
||||
~Mesh();
|
||||
|
||||
/** Translation matrix */
|
||||
M4x4 translation;
|
||||
|
||||
/** Rotation matrix */
|
||||
M4x4 rotation;
|
||||
|
||||
/** Scale matrix */
|
||||
M4x4 scale;
|
||||
|
||||
const u32& getId() const { return id; }
|
||||
|
||||
const u8& isMother() const { return _isMother; }
|
||||
|
||||
/** Get position from translation matrix */
|
||||
Vec4* getPosition() {
|
||||
return reinterpret_cast<Vec4*>(&translation.data[3 * 4]);
|
||||
}
|
||||
|
||||
void setPosition(const Vec4& v) {
|
||||
TYRA_ASSERT(v.w == 1.0F, "Vec4 must be homogeneous");
|
||||
reinterpret_cast<Vec4*>(&translation.data[3 * 4])->set(v);
|
||||
}
|
||||
|
||||
/** Returns material, which is a mesh "subgroup". */
|
||||
MeshMaterial* getMaterial(const u32& i) const { return materials[i]; }
|
||||
|
||||
const u32& getMaterialsCount() const { return materialsCount; }
|
||||
|
||||
const MeshAnimState& getAnimState() const { return animState; }
|
||||
|
||||
/** Count of all vertices. */
|
||||
u32 getVertexCount() { return frames[0]->getVertexCount(); }
|
||||
|
||||
/** Returns single frame. */
|
||||
MeshFrame* getFrame(const u32& i) const { return frames[i]; }
|
||||
|
||||
/** Count of frames. Static object (not animated) will have only 1 frame. */
|
||||
const u32& getFramesCount() const { return framesCount; }
|
||||
|
||||
const u32& getCurrentAnimationFrame() const { return animState.currentFrame; }
|
||||
|
||||
const u32& getNextAnimationFrame() const { return animState.nextFrame; }
|
||||
|
||||
const u32& getStartAnimationFrame() const { return animState.startFrame; }
|
||||
|
||||
const u32& getEndAnimationFrame() const { return animState.endFrame; }
|
||||
|
||||
const u32& getStayAnimationFrame() const { return animState.stayFrame; }
|
||||
|
||||
M4x4 getModelMatrix() const;
|
||||
|
||||
// /**
|
||||
// * Returns material, which is a mesh "subgroup".
|
||||
// * NULL if not found.
|
||||
// */
|
||||
// MeshMaterial* getMaterialById(const u32& t_id) const;
|
||||
|
||||
/** @returns bounding box object of current frame. */
|
||||
const BBox& getCurrentBoundingBox() const {
|
||||
return frames[animState.currentFrame]->getBBox();
|
||||
}
|
||||
|
||||
/** Check if are there any frames */
|
||||
u8 isDataLoaded() const { return framesCount > 0; }
|
||||
|
||||
/** Loop in one frame */
|
||||
void playAnimation(const u32& t_frame) { playAnimation(t_frame, t_frame); }
|
||||
|
||||
/** Play animation in loop from startFrame to endFrame */
|
||||
void playAnimation(const u32& t_startFrame, const u32& t_endFrame);
|
||||
|
||||
/** Play animation from startFrame to endFrame and after loop in stayFrame
|
||||
*/
|
||||
void playAnimation(const u32& t_startFrame, const u32& t_endFrame,
|
||||
const u32& t_stayFrame);
|
||||
|
||||
void setAnimSpeed(const float& t_value) { animState.speed = t_value; }
|
||||
|
||||
void animate();
|
||||
|
||||
/**
|
||||
* Check if this class loaded mesh data first.
|
||||
* Meshes which use loadFrom() method have false there.
|
||||
*/
|
||||
const u8& isStayAnimationSet() const { return animState.isStayFrameSet; }
|
||||
|
||||
private:
|
||||
void initMesh();
|
||||
MeshAnimState animState;
|
||||
u8 _isMother;
|
||||
u32 id, framesCount, materialsCount;
|
||||
MeshFrame** frames;
|
||||
MeshMaterial** materials;
|
||||
};
|
||||
|
||||
} // namespace Tyra
|
||||
@@ -0,0 +1,30 @@
|
||||
|
||||
/*
|
||||
# ______ ____ ___
|
||||
# | \/ ____| |___|
|
||||
# | | | \ | |
|
||||
#-----------------------------------------------------------------------
|
||||
# Copyright 2020, tyra - https://github.com/h4570/tyra
|
||||
# Licenced under Apache License 2.0
|
||||
# Sandro Sobczyński <sandro.sobczynski@gmail.com>
|
||||
*/
|
||||
|
||||
#pragma once
|
||||
|
||||
#include <tamtypes.h>
|
||||
|
||||
namespace Tyra {
|
||||
|
||||
typedef struct {
|
||||
u32 startFrame;
|
||||
u32 endFrame;
|
||||
u32 stayFrame;
|
||||
u8 isStayFrameSet;
|
||||
float speed;
|
||||
float interpolation;
|
||||
u32 animType;
|
||||
u32 currentFrame;
|
||||
u32 nextFrame;
|
||||
} MeshAnimState;
|
||||
|
||||
} // namespace Tyra
|
||||
@@ -0,0 +1,51 @@
|
||||
/*
|
||||
# ______ ____ ___
|
||||
# | \/ ____| |___|
|
||||
# | | | \ | |
|
||||
#-----------------------------------------------------------------------
|
||||
# Copyright 2022, tyra - https://github.com/h4570/tyra
|
||||
# Licenced under Apache License 2.0
|
||||
# Sandro Sobczyński <sandro.sobczynski@gmail.com>
|
||||
*/
|
||||
|
||||
#pragma once
|
||||
|
||||
#include "renderer/3d/mesh/mesh_material.hpp"
|
||||
#include "loaders/3d/builder/mesh_builder_data.hpp"
|
||||
#include "renderer/3d/bbox/bbox.hpp"
|
||||
|
||||
namespace Tyra {
|
||||
|
||||
class MeshFrame {
|
||||
public:
|
||||
explicit MeshFrame(const MeshBuilderData& data, const u32& index);
|
||||
explicit MeshFrame(const MeshFrame& frame);
|
||||
~MeshFrame();
|
||||
|
||||
const u32& getId() const { return id; }
|
||||
const u32& getVertexCount() const { return vertexCount; }
|
||||
const u32& getTextureCoordsCount() const { return textureCoordsCount; }
|
||||
const u32& getNormalsCount() const { return normalsCount; }
|
||||
const u32& getColorsCount() const { return colorsCount; }
|
||||
const u8& isMother() const { return _isMother; }
|
||||
const BBox& getBBox() const { return *bbox; }
|
||||
|
||||
Vec4* getVertices() const { return vertices; }
|
||||
Vec4* getNormals() const { return normals; }
|
||||
Vec4* getTextureCoords() const { return textureCoords; }
|
||||
Color* getColors() const { return colors; }
|
||||
|
||||
void print() const;
|
||||
void print(const char* name) const;
|
||||
void print(const std::string& name) const { print(name.c_str()); }
|
||||
std::string getPrint(const char* name = nullptr) const;
|
||||
|
||||
private:
|
||||
u8 _isMother;
|
||||
BBox* bbox;
|
||||
u32 id, vertexCount, textureCoordsCount, normalsCount, colorsCount;
|
||||
Vec4 *vertices, *textureCoords, *normals;
|
||||
Color* colors;
|
||||
};
|
||||
|
||||
} // namespace Tyra
|
||||
@@ -0,0 +1,57 @@
|
||||
/*
|
||||
# ______ ____ ___
|
||||
# | \/ ____| |___|
|
||||
# | | | \ | |
|
||||
#-----------------------------------------------------------------------
|
||||
# Copyright 2022, tyra - https://github.com/h4570/tyra
|
||||
# Licenced under Apache License 2.0
|
||||
# Sandro Sobczyński <sandro.sobczynski@gmail.com>
|
||||
*/
|
||||
|
||||
#pragma once
|
||||
|
||||
#include "debug/debug.hpp"
|
||||
#include "loaders/3d/builder/mesh_builder_data.hpp"
|
||||
#include "renderer/3d/mesh/mesh_material_frame.hpp"
|
||||
|
||||
namespace Tyra {
|
||||
|
||||
class MeshMaterial {
|
||||
public:
|
||||
explicit MeshMaterial(const MeshBuilderData& data, const u32& materialIndex);
|
||||
explicit MeshMaterial(const MeshMaterial& material);
|
||||
~MeshMaterial();
|
||||
|
||||
Color singleColor;
|
||||
|
||||
const u32& getId() const { return id; }
|
||||
const std::string& getName() const { return _name; }
|
||||
const u32& getFacesCount() const { return facesCount; }
|
||||
const u8& isMother() const { return _isMother; }
|
||||
const u8& isSingleColorActivated() const { return singleColorFlag; }
|
||||
|
||||
u32* getVertexFaces() const { return vertexFaces; }
|
||||
u32* getTextureCoordFaces() const { return textureCoordFaces; }
|
||||
u32* getNormalFaces() const { return normalFaces; }
|
||||
u32* getColorFaces() const { return normalFaces; }
|
||||
MeshMaterialFrame* getFrames() const { return *frames; }
|
||||
|
||||
const BBox& getBBox(const u32& frame) const;
|
||||
|
||||
void setSingleColorFlag(const u8& flag);
|
||||
|
||||
void print() const;
|
||||
void print(const char* name) const;
|
||||
void print(const std::string& name) const { print(name.c_str()); }
|
||||
std::string getPrint(const char* name = nullptr) const;
|
||||
|
||||
private:
|
||||
MeshMaterialFrame** frames;
|
||||
|
||||
std::string _name;
|
||||
u8 _isMother, singleColorFlag;
|
||||
u32 id, facesCount, framesCount;
|
||||
u32 *vertexFaces, *textureCoordFaces, *normalFaces, *colorFaces;
|
||||
};
|
||||
|
||||
} // namespace Tyra
|
||||
@@ -0,0 +1,35 @@
|
||||
/*
|
||||
# ______ ____ ___
|
||||
# | \/ ____| |___|
|
||||
# | | | \ | |
|
||||
#-----------------------------------------------------------------------
|
||||
# Copyright 2022, tyra - https://github.com/h4570/tyra
|
||||
# Licenced under Apache License 2.0
|
||||
# Sandro Sobczyński <sandro.sobczynski@gmail.com>
|
||||
*/
|
||||
|
||||
#pragma once
|
||||
|
||||
#include "./renderer/3d/bbox/bbox.hpp"
|
||||
|
||||
namespace Tyra {
|
||||
|
||||
class MeshMaterialFrame {
|
||||
public:
|
||||
explicit MeshMaterialFrame(const MeshBuilderData& data, const u32& frameIndex,
|
||||
const u32& materialIndex);
|
||||
explicit MeshMaterialFrame(const MeshMaterialFrame& frame);
|
||||
~MeshMaterialFrame();
|
||||
|
||||
const u32& getId() const { return id; }
|
||||
const u8& isMother() const { return _isMother; }
|
||||
const BBox& getBBox() const { return *bbox; }
|
||||
|
||||
private:
|
||||
BBox* bbox;
|
||||
|
||||
u8 _isMother;
|
||||
u32 id;
|
||||
};
|
||||
|
||||
} // namespace Tyra
|
||||
@@ -0,0 +1,31 @@
|
||||
/*
|
||||
# ______ ____ ___
|
||||
# | \/ ____| |___|
|
||||
# | | | \ | |
|
||||
#-----------------------------------------------------------------------
|
||||
# Copyright 2022, tyra - https://github.com/h4570/tyra
|
||||
# Licenced under Apache License 2.0
|
||||
# Sandro Sobczyński <sandro.sobczynski@gmail.com>
|
||||
*/
|
||||
|
||||
#pragma once
|
||||
|
||||
#include "math/vec4.hpp"
|
||||
|
||||
namespace Tyra {
|
||||
|
||||
class McpipBlockData {
|
||||
public:
|
||||
McpipBlockData();
|
||||
~McpipBlockData();
|
||||
|
||||
u32 count;
|
||||
float offset;
|
||||
u32 getComboCount() const { return count * 2; }
|
||||
|
||||
Tyra::Vec4* comboData;
|
||||
Tyra::Vec4* vertices;
|
||||
Tyra::Vec4* textureCoords;
|
||||
};
|
||||
|
||||
} // namespace Tyra
|
||||
@@ -0,0 +1,35 @@
|
||||
/*
|
||||
# ______ ____ ___
|
||||
# | \/ ____| |___|
|
||||
# | | | \ | |
|
||||
#-----------------------------------------------------------------------
|
||||
# Copyright 2022, tyra - https://github.com/h4570/tyra
|
||||
# Licenced under Apache License 2.0
|
||||
# Sandro Sobczyński <sandro.sobczynski@gmail.com>
|
||||
*/
|
||||
|
||||
#pragma once
|
||||
|
||||
#include "debug/debug.hpp"
|
||||
#include "./mcpip_block_data.hpp"
|
||||
#include "string"
|
||||
|
||||
namespace Tyra {
|
||||
|
||||
class McpipMultiTexBlockData : public McpipBlockData {
|
||||
public:
|
||||
McpipMultiTexBlockData();
|
||||
~McpipMultiTexBlockData();
|
||||
|
||||
private:
|
||||
Vec4* tempVerts;
|
||||
Vec4* tempTexCoords;
|
||||
u32* tempVertFaces;
|
||||
u32* tempTexCoordsFaces;
|
||||
|
||||
void allocateTempData();
|
||||
void unroll();
|
||||
void dellocateTempData();
|
||||
};
|
||||
|
||||
} // namespace Tyra
|
||||
@@ -0,0 +1,35 @@
|
||||
/*
|
||||
# ______ ____ ___
|
||||
# | \/ ____| |___|
|
||||
# | | | \ | |
|
||||
#-----------------------------------------------------------------------
|
||||
# Copyright 2022, tyra - https://github.com/h4570/tyra
|
||||
# Licenced under Apache License 2.0
|
||||
# Sandro Sobczyński <sandro.sobczynski@gmail.com>
|
||||
*/
|
||||
|
||||
#pragma once
|
||||
|
||||
#include "debug/debug.hpp"
|
||||
#include "./mcpip_block_data.hpp"
|
||||
#include "string"
|
||||
|
||||
namespace Tyra {
|
||||
|
||||
class McpipSingleTexBlockData : public McpipBlockData {
|
||||
public:
|
||||
McpipSingleTexBlockData();
|
||||
~McpipSingleTexBlockData();
|
||||
|
||||
private:
|
||||
Vec4* tempVerts;
|
||||
Vec4* tempTexCoords;
|
||||
u32* tempVertFaces;
|
||||
u32* tempTexCoordsFaces;
|
||||
|
||||
void allocateTempData();
|
||||
void unroll();
|
||||
void dellocateTempData();
|
||||
};
|
||||
|
||||
} // namespace Tyra
|
||||
@@ -0,0 +1,30 @@
|
||||
/*
|
||||
# ______ ____ ___
|
||||
# | \/ ____| |___|
|
||||
# | | | \ | |
|
||||
#-----------------------------------------------------------------------
|
||||
# Copyright 2022, tyra - https://github.com/h4570/tyra
|
||||
# Licenced under Apache License 2.0
|
||||
# Sandro Sobczyński <sandro.sobczynski@gmail.com>
|
||||
*/
|
||||
|
||||
#pragma once
|
||||
|
||||
#include <tamtypes.h>
|
||||
#include "math/m4x4.hpp"
|
||||
#include "math/vec4.hpp"
|
||||
#include "renderer/models/color.hpp"
|
||||
|
||||
namespace Tyra {
|
||||
|
||||
class McpipBlock {
|
||||
public:
|
||||
McpipBlock() {}
|
||||
~McpipBlock() {}
|
||||
|
||||
M4x4 model;
|
||||
Color color;
|
||||
Vec4 textureOffset;
|
||||
};
|
||||
|
||||
} // namespace Tyra
|
||||
@@ -0,0 +1,58 @@
|
||||
/*
|
||||
# ______ ____ ___
|
||||
# | \/ ____| |___|
|
||||
# | | | \ | |
|
||||
#-----------------------------------------------------------------------
|
||||
# Copyright 2022, tyra - https://github.com/h4570/tyra
|
||||
# Licenced under Apache License 2.0
|
||||
# Sandro Sobczyński <sandro.sobczynski@gmail.com>
|
||||
*/
|
||||
|
||||
#pragma once
|
||||
|
||||
#include "./mcpip_block.hpp"
|
||||
#include "./programs/mcpip_programs_manager.hpp"
|
||||
#include "renderer/3d/pipeline/renderer_3d_pipeline.hpp"
|
||||
#include "renderer/core/3d/bbox/core_bbox_frustum.hpp"
|
||||
#include "renderer/core/3d/bbox/render_bbox.hpp"
|
||||
|
||||
namespace Tyra {
|
||||
|
||||
class MinecraftPipeline : public Renderer3DPipeline {
|
||||
public:
|
||||
MinecraftPipeline();
|
||||
~MinecraftPipeline();
|
||||
|
||||
void init(RendererCore* core);
|
||||
|
||||
void onUse();
|
||||
|
||||
void render(McpipBlock* blocks, const u32& count, Texture* t_tex,
|
||||
const bool& isMulti = false, const bool& noClipChecks = true);
|
||||
|
||||
inline const float& getTextureOffset() const {
|
||||
return manager.getTextureOffset();
|
||||
}
|
||||
|
||||
private:
|
||||
BlockizerProgramsManager manager;
|
||||
RendererCore* rendererCore;
|
||||
RenderBBox* bbox;
|
||||
McpipProgramName latestMode;
|
||||
|
||||
void initBBox();
|
||||
|
||||
void changeMode(const McpipProgramName& requestedMode, const u8& force);
|
||||
|
||||
void cull(McpipBlock* blocks, const std::vector<u32>& indexes,
|
||||
RendererCoreTextureBuffers* texBuffers,
|
||||
const bool& isMulti = false);
|
||||
|
||||
void clip(McpipBlock* blocks, const std::vector<u32>& indexes,
|
||||
RendererCoreTextureBuffers* texBuffers,
|
||||
const bool& isMulti = false);
|
||||
|
||||
Tyra::CoreBBoxFrustum isInFrustum(const McpipBlock& block) const;
|
||||
};
|
||||
|
||||
} // namespace Tyra
|
||||
@@ -0,0 +1,28 @@
|
||||
/*
|
||||
# ______ ____ ___
|
||||
# | \/ ____| |___|
|
||||
# | | | \ | |
|
||||
#-----------------------------------------------------------------------
|
||||
# Copyright 2022, tyra - https://github.com/h4570/tyra
|
||||
# Licenced under Apache License 2.0
|
||||
# Sandro Sobczyński <sandro.sobczynski@gmail.com>
|
||||
*/
|
||||
|
||||
#pragma once
|
||||
|
||||
#include <packet2_utils.h>
|
||||
#include <string>
|
||||
#include "debug/debug.hpp"
|
||||
#include "renderer/3d/pipeline/minecraft/programs/mcpip_program.hpp"
|
||||
|
||||
namespace Tyra {
|
||||
|
||||
class McpipAsIsVU1Program : public McpipProgram {
|
||||
public:
|
||||
McpipAsIsVU1Program();
|
||||
~McpipAsIsVU1Program();
|
||||
|
||||
std::string getStringName() const;
|
||||
};
|
||||
|
||||
} // namespace Tyra
|
||||
@@ -0,0 +1,70 @@
|
||||
/*
|
||||
# ______ ____ ___
|
||||
# | \/ ____| |___|
|
||||
# | | | \ | |
|
||||
#-----------------------------------------------------------------------
|
||||
# Copyright 2022, tyra - https://github.com/h4570/tyra
|
||||
# Licenced under Apache License 2.0
|
||||
# Sandro Sobczyński <sandro.sobczynski@gmail.com>
|
||||
*/
|
||||
|
||||
#pragma once
|
||||
|
||||
#include <packet2_utils.h>
|
||||
#include "debug/debug.hpp"
|
||||
#include "renderer/renderer.hpp"
|
||||
#include "packet2/packet2_tyra_utils.hpp"
|
||||
#include "../mcpip_programs_repository.hpp"
|
||||
#include "../../mcpip_block.hpp"
|
||||
#include "../../data/mcpip_block_data.hpp"
|
||||
#include "./mcpip_vu1_as_is_shared_defines.h"
|
||||
#include "renderer/core/paths/path1/clipper/path1_ee_clip_algorithm.hpp"
|
||||
|
||||
namespace Tyra {
|
||||
|
||||
class McpipClip {
|
||||
public:
|
||||
McpipClip();
|
||||
~McpipClip();
|
||||
|
||||
Path1EEClipAlgorithm algorithm;
|
||||
Path1EEClipAlgorithmSettings algoSettings;
|
||||
|
||||
void init(RendererCore* core, McpipBlockData* t_singleBlockData,
|
||||
McpipBlockData* t_multiBlockData);
|
||||
|
||||
u32 uploadVU1Program(McpipProgramsRepository* repo, const u32& addr);
|
||||
|
||||
void configureVU1AndSendStaticData();
|
||||
|
||||
void addData(McpipBlock* block, const bool& isMulti,
|
||||
RendererCoreTextureBuffers* texBuffers, packet2_t* packet,
|
||||
const u8& context);
|
||||
|
||||
private:
|
||||
RendererCore* rendererCore;
|
||||
McpipBlockData* singleBlockData;
|
||||
McpipBlockData* multiBlockData;
|
||||
packet2_t* staticPacket;
|
||||
u16 vu1DBufferSize;
|
||||
|
||||
std::vector<Path1ClipVertex> clippedTriangle;
|
||||
std::vector<Path1ClipVertex> inputTriangle;
|
||||
|
||||
Vec4 vertexBuffers[2][108];
|
||||
Vec4 texCoordBuffers[2][108];
|
||||
|
||||
void addCorrections(std::vector<Path1ClipVertex>* vertices,
|
||||
McpipBlock* block);
|
||||
void moveDataToBuffer(std::vector<Path1ClipVertex>* vertices,
|
||||
const u8& context);
|
||||
void addDataToPacket(packet2_t* packet, const u8& context, McpipBlock* block,
|
||||
const int& count,
|
||||
RendererCoreTextureBuffers* texBuffers);
|
||||
|
||||
void initStaticPacket();
|
||||
void sendVU1StaticData();
|
||||
void setDBufferSize();
|
||||
};
|
||||
|
||||
} // namespace Tyra
|
||||
+22
@@ -0,0 +1,22 @@
|
||||
//
|
||||
// ______ ____ ___
|
||||
// | \/ ____| |___|
|
||||
// | | | \ | |
|
||||
//-----------------------------------------------------------------------
|
||||
// Copyright 2022, tyra - https://github.com/h4570/tyra
|
||||
// Licenced under Apache License 2.0
|
||||
// Sandro Sobczyński <sandro.sobczynski@gmail.com>
|
||||
//
|
||||
|
||||
// Static data for blockizer program
|
||||
|
||||
#define VU1_MCPIP_AS_IS_STATIC_LOD 0
|
||||
#define VU1_MCPIP_AS_IS_STATIC_SET_TAG 1
|
||||
#define VU1_MCPIP_AS_IS_STATIC_LAST_DATA_ADDR 1
|
||||
|
||||
// Dynamic data (unpack per VU1 call)
|
||||
#define VU1_MCPIP_AS_IS_DYNAMIC_SCALE 0
|
||||
#define VU1_MCPIP_AS_IS_DYNAMIC_PRIM 1
|
||||
#define VU1_MCPIP_AS_IS_DYNAMIC_CLUT 2
|
||||
#define VU1_MCPIP_AS_IS_DYNAMIC_COLOR 3
|
||||
#define VU1_MCPIP_AS_IS_DYNAMIC_VERTEX_DATA_ADDR 4
|
||||
@@ -0,0 +1,52 @@
|
||||
/*
|
||||
# ______ ____ ___
|
||||
# | \/ ____| |___|
|
||||
# | | | \ | |
|
||||
#-----------------------------------------------------------------------
|
||||
# Copyright 2022, tyra - https://github.com/h4570/tyra
|
||||
# Licenced under Apache License 2.0
|
||||
# Sandro Sobczyński <sandro.sobczynski@gmail.com>
|
||||
*/
|
||||
|
||||
#pragma once
|
||||
|
||||
#include <packet2_utils.h>
|
||||
#include "debug/debug.hpp"
|
||||
#include "renderer/renderer.hpp"
|
||||
#include "packet2/packet2_tyra_utils.hpp"
|
||||
#include "../mcpip_programs_repository.hpp"
|
||||
#include "../../mcpip_block.hpp"
|
||||
#include "../../data/mcpip_block_data.hpp"
|
||||
#include "./mcpip_vu1_cull_shared_defines.h"
|
||||
|
||||
namespace Tyra {
|
||||
|
||||
class McpipCull {
|
||||
public:
|
||||
McpipCull();
|
||||
~McpipCull();
|
||||
|
||||
void init(RendererCore* core, McpipBlockData* t_blockData);
|
||||
|
||||
u32 uploadVU1Program(McpipProgramsRepository* repo, const u32& addr);
|
||||
|
||||
void configureVU1AndSendStaticData();
|
||||
|
||||
u32 getMaxBlocksCountPerQBuffer() const;
|
||||
|
||||
void addData(packet2_t* packet, McpipBlock** blockPointerArray,
|
||||
u32 blockPointerArrayCount,
|
||||
RendererCoreTextureBuffers* texBuffers, bool isMulti);
|
||||
|
||||
private:
|
||||
RendererCore* rendererCore;
|
||||
u16 vu1DBufferSize;
|
||||
McpipBlockData* blockData;
|
||||
packet2_t* staticPacket;
|
||||
|
||||
void initStaticPacket();
|
||||
void sendVU1StaticData();
|
||||
void setDBufferSize();
|
||||
};
|
||||
|
||||
} // namespace Tyra
|
||||
@@ -0,0 +1,28 @@
|
||||
/*
|
||||
# ______ ____ ___
|
||||
# | \/ ____| |___|
|
||||
# | | | \ | |
|
||||
#-----------------------------------------------------------------------
|
||||
# Copyright 2022, tyra - https://github.com/h4570/tyra
|
||||
# Licenced under Apache License 2.0
|
||||
# Sandro Sobczyński <sandro.sobczynski@gmail.com>
|
||||
*/
|
||||
|
||||
#pragma once
|
||||
|
||||
#include <packet2_utils.h>
|
||||
#include <string>
|
||||
#include "debug/debug.hpp"
|
||||
#include "renderer/3d/pipeline/minecraft/programs/mcpip_program.hpp"
|
||||
|
||||
namespace Tyra {
|
||||
|
||||
class McpipCullVU1Program : public McpipProgram {
|
||||
public:
|
||||
McpipCullVU1Program();
|
||||
~McpipCullVU1Program();
|
||||
|
||||
std::string getStringName() const;
|
||||
};
|
||||
|
||||
} // namespace Tyra
|
||||
+33
@@ -0,0 +1,33 @@
|
||||
//
|
||||
// ______ ____ ___
|
||||
// | \/ ____| |___|
|
||||
// | | | \ | |
|
||||
//-----------------------------------------------------------------------
|
||||
// Copyright 2022, tyra - https://github.com/h4570/tyra
|
||||
// Licenced under Apache License 2.0
|
||||
// Sandro Sobczyński <sandro.sobczynski@gmail.com>
|
||||
//
|
||||
|
||||
// Static data for blockizer program
|
||||
|
||||
#define VU1_MCPIP_CULL_VERTEX_COUNT 36
|
||||
#define VU1_MCPIP_CULL_QWORDS_PER_BLOCK 6
|
||||
|
||||
#define VU1_MCPIP_CULL_STATIC_LOD 0
|
||||
#define VU1_MCPIP_CULL_STATIC_PRIM 1
|
||||
#define VU1_MCPIP_CULL_STATIC_SET_TAG 2
|
||||
#define VU1_MCPIP_CULL_STATIC_VU1_OPTIONS 3
|
||||
#define VU1_MCPIP_CULL_STATIC_VERTEX_DATA 4
|
||||
#define VU1_MCPIP_CULL_STATIC_TEX_COORD_DATA 4 + 36
|
||||
#define VU1_MCPIP_CULL_STATIC_LAST_DATA_ADDR \
|
||||
VU1_MCPIP_CULL_STATIC_TEX_COORD_DATA + 36
|
||||
|
||||
// Dynamic data (unpack per VU1 call)
|
||||
#define VU1_MCPIP_CULL_DYNAMIC_SCALE_AND_BLOCKS_COUNT_ADDR 0
|
||||
#define VU1_MCPIP_CULL_DYNAMIC_CLUT_TEX 1
|
||||
#define VU1_MCPIP_CULL_DYNAMIC_VIEW_PROJ_MATRIX_ADDR 2
|
||||
#define VU1_MCPIP_CULL_DYNAMIC_BLOCKS_DATA 6
|
||||
|
||||
// Output mini double buffer inside VU1 mem
|
||||
#define VU1_MCPIP_CULL_DYNAMIC_OUTPUT_DOUBLE_BUFF1_ADDR 774
|
||||
#define VU1_MCPIP_CULL_DYNAMIC_OUTPUT_DOUBLE_BUFF2_ADDR 887
|
||||
@@ -0,0 +1,29 @@
|
||||
/*
|
||||
# ______ ____ ___
|
||||
# | \/ ____| |___|
|
||||
# | | | \ | |
|
||||
#-----------------------------------------------------------------------
|
||||
# Copyright 2022, tyra - https://github.com/h4570/tyra
|
||||
# Licenced under Apache License 2.0
|
||||
# Sandro Sobczyński <sandro.sobczynski@gmail.com>
|
||||
*/
|
||||
|
||||
#pragma once
|
||||
|
||||
#include "./mcpip_program_name.hpp"
|
||||
#include "renderer/core/paths/path1/vu1_program.hpp"
|
||||
|
||||
namespace Tyra {
|
||||
|
||||
class McpipProgram : public VU1Program {
|
||||
public:
|
||||
McpipProgram(const McpipProgramName& name, u32* start, u32* end);
|
||||
~McpipProgram();
|
||||
|
||||
const McpipProgramName& getName() const;
|
||||
|
||||
protected:
|
||||
McpipProgramName name;
|
||||
};
|
||||
|
||||
} // namespace Tyra
|
||||
@@ -0,0 +1,21 @@
|
||||
/*
|
||||
# ______ ____ ___
|
||||
# | \/ ____| |___|
|
||||
# | | | \ | |
|
||||
#-----------------------------------------------------------------------
|
||||
# Copyright 2022, tyra - https://github.com/h4570/tyra
|
||||
# Licenced under Apache License 2.0
|
||||
# Sandro Sobczyński <sandro.sobczynski@gmail.com>
|
||||
*/
|
||||
|
||||
#pragma once
|
||||
|
||||
namespace Tyra {
|
||||
|
||||
enum McpipProgramName {
|
||||
UndefinedMcpipProgram,
|
||||
McPipCull,
|
||||
McPipAsIs,
|
||||
};
|
||||
|
||||
} // namespace Tyra
|
||||
@@ -0,0 +1,75 @@
|
||||
/*
|
||||
# ______ ____ ___
|
||||
# | \/ ____| |___|
|
||||
# | | | \ | |
|
||||
#-----------------------------------------------------------------------
|
||||
# Copyright 2022, tyra - https://github.com/h4570/tyra
|
||||
# Licenced under Apache License 2.0
|
||||
# Sandro Sobczyński <sandro.sobczynski@gmail.com>
|
||||
*/
|
||||
|
||||
#pragma once
|
||||
|
||||
#include <packet2_utils.h>
|
||||
#include "debug/debug.hpp"
|
||||
#include "renderer/renderer.hpp"
|
||||
#include "./cull/mcpip_cull.hpp"
|
||||
#include "./as_is/mcpip_clip.hpp"
|
||||
#include "./mcpip_programs_repository.hpp"
|
||||
#include "../data/mcpip_single_tex_block_data.hpp"
|
||||
#include "../data/mcpip_multi_tex_block_data.hpp"
|
||||
#include "../mcpip_block.hpp"
|
||||
|
||||
namespace Tyra {
|
||||
|
||||
enum McpipStaticBlockData {
|
||||
BlockNotUploaded,
|
||||
BlockMultiUploaded,
|
||||
BlockSingleUploaded
|
||||
};
|
||||
|
||||
class BlockizerProgramsManager {
|
||||
public:
|
||||
BlockizerProgramsManager();
|
||||
~BlockizerProgramsManager();
|
||||
|
||||
McpipCull culler;
|
||||
McpipClip clipper;
|
||||
|
||||
void init(RendererCore* core);
|
||||
|
||||
void uploadVU1Programs();
|
||||
|
||||
void clearLastProgram() { lastProgramName = UndefinedMcpipProgram; }
|
||||
|
||||
void cull(McpipBlock** blockPointerArray, u32 blockPointerArrayCount,
|
||||
RendererCoreTextureBuffers* texBuffers, const bool& isMulti);
|
||||
|
||||
void clip(McpipBlock* block, RendererCoreTextureBuffers* texBuffers,
|
||||
const bool& isMulti);
|
||||
|
||||
inline const float& getTextureOffset() const {
|
||||
return singleTexBlockData.offset;
|
||||
}
|
||||
|
||||
const McpipBlockData& getBlockData() const { return singleTexBlockData; }
|
||||
|
||||
private:
|
||||
McpipProgramsRepository repo;
|
||||
Renderer* renderer;
|
||||
McpipSingleTexBlockData singleTexBlockData;
|
||||
McpipMultiTexBlockData multiTexBlockData;
|
||||
McpipProgramName lastProgramName;
|
||||
|
||||
packet2_t* programsPacket;
|
||||
packet2_t* staticPacket;
|
||||
packet2_t* dynamicPackets[2];
|
||||
u8 context;
|
||||
McpipStaticBlockData vu1BlockData;
|
||||
|
||||
void setProgramsCache();
|
||||
void uploadBlock(bool isMulti);
|
||||
void sendPacket(McpipProgram* program);
|
||||
};
|
||||
|
||||
} // namespace Tyra
|
||||
@@ -0,0 +1,32 @@
|
||||
/*
|
||||
# ______ ____ ___
|
||||
# | \/ ____| |___|
|
||||
# | | | \ | |
|
||||
#-----------------------------------------------------------------------
|
||||
# Copyright 2022, tyra - https://github.com/h4570/tyra
|
||||
# Licenced under Apache License 2.0
|
||||
# Sandro Sobczyński <sandro.sobczynski@gmail.com>
|
||||
*/
|
||||
|
||||
#pragma once
|
||||
|
||||
#include "debug/debug.hpp"
|
||||
#include "./mcpip_program.hpp"
|
||||
#include "cull/mcpip_cull_vu1_program.hpp"
|
||||
#include "as_is/mcpip_as_is_vu1_program.hpp"
|
||||
|
||||
namespace Tyra {
|
||||
|
||||
class McpipProgramsRepository {
|
||||
public:
|
||||
McpipProgramsRepository();
|
||||
~McpipProgramsRepository();
|
||||
|
||||
McpipProgram* getProgram(const McpipProgramName& name);
|
||||
|
||||
private:
|
||||
McpipCullVU1Program cull;
|
||||
McpipAsIsVU1Program asIs;
|
||||
};
|
||||
|
||||
} // namespace Tyra
|
||||
@@ -0,0 +1,26 @@
|
||||
/*
|
||||
# ______ ____ ___
|
||||
# | \/ ____| |___|
|
||||
# | | | \ | |
|
||||
#-----------------------------------------------------------------------
|
||||
# Copyright 2022, tyra - https://github.com/h4570/tyra
|
||||
# Licenced under Apache License 2.0
|
||||
# Sandro Sobczyński <sandro.sobczynski@gmail.com>
|
||||
*/
|
||||
|
||||
#pragma once
|
||||
|
||||
#include "renderer/core/renderer_core.hpp"
|
||||
|
||||
namespace Tyra {
|
||||
|
||||
class Renderer3DPipeline {
|
||||
public:
|
||||
Renderer3DPipeline() {}
|
||||
~Renderer3DPipeline() {}
|
||||
|
||||
virtual void init(RendererCore* core) = 0;
|
||||
virtual void onUse() = 0;
|
||||
};
|
||||
|
||||
} // namespace Tyra
|
||||
@@ -0,0 +1,50 @@
|
||||
/*
|
||||
# ______ ____ ___
|
||||
# | \/ ____| |___|
|
||||
# | | | \ | |
|
||||
#-----------------------------------------------------------------------
|
||||
# Copyright 2022, tyra - https://github.com/h4570/tyra
|
||||
# Licenced under Apache License 2.0
|
||||
# Sandro Sobczyński <sandro.sobczynski@gmail.com>
|
||||
*/
|
||||
|
||||
#pragma once
|
||||
|
||||
#include "../stdpip_bag.hpp"
|
||||
#include "renderer/core/3d/bbox/core_bbox_frustum.hpp"
|
||||
|
||||
namespace Tyra {
|
||||
|
||||
class StdpipBagPackage {
|
||||
public:
|
||||
StdpipBagPackage();
|
||||
~StdpipBagPackage();
|
||||
|
||||
StdpipBag* bag;
|
||||
|
||||
Vec4* vertices;
|
||||
Vec4* sts;
|
||||
Vec4* normals;
|
||||
Vec4* colors;
|
||||
/** maxVertCount is max value, because we decided to put max maxVertCount
|
||||
* verts to single quad buffer in VU1 */
|
||||
u16 size;
|
||||
CoreBBoxFrustum isInFrustum;
|
||||
|
||||
/**
|
||||
* We are creating StdpipBagPackagesBBox which checks CoreBBoxBBox for every
|
||||
* maxVertCount / 3. So this variable is index of starting
|
||||
* StdpipBagPackagesBBox's CoreBBoxBBox. If package have <= maxVertCount / 3
|
||||
* verts, we will need only single (starting) bbox. if package have
|
||||
* maxVertCount verts, we will calculate CoreBBoxBBox from 3
|
||||
* StdpipBagPackagesBBox's bboxes.
|
||||
*/
|
||||
u32 indexOf1By3BBox;
|
||||
|
||||
void print() const;
|
||||
void print(const char* name) const;
|
||||
void print(const std::string& name) const { print(name.c_str()); }
|
||||
std::string getPrint(const char* name = nullptr) const;
|
||||
};
|
||||
|
||||
} // namespace Tyra
|
||||
@@ -0,0 +1,52 @@
|
||||
/*
|
||||
# ______ ____ ___
|
||||
# | \/ ____| |___|
|
||||
# | | | \ | |
|
||||
#-----------------------------------------------------------------------
|
||||
# Copyright 2022, tyra - https://github.com/h4570/tyra
|
||||
# Licenced under Apache License 2.0
|
||||
# Sandro Sobczyński <sandro.sobczynski@gmail.com>
|
||||
*/
|
||||
|
||||
#pragma once
|
||||
|
||||
#include "renderer/core/3d/bbox/core_bbox.hpp"
|
||||
#include "renderer/core/3d/renderer_3d_frustum_planes.hpp"
|
||||
#include "renderer/core/paths/path1/clipper/path1_ee_clip_algorithm.hpp"
|
||||
#include "./stdpip_bag_packages_bbox.hpp"
|
||||
#include "./stdpip_bag_package.hpp"
|
||||
#include "../stdpip_bag.hpp"
|
||||
|
||||
namespace Tyra {
|
||||
|
||||
class StdpipBagPackager {
|
||||
public:
|
||||
StdpipBagPackager();
|
||||
~StdpipBagPackager();
|
||||
|
||||
void init(Renderer3DFrustumPlanes* frustumPlanes);
|
||||
void setRenderBBox(StdpipBagPackagesBBox* bbox) { renderBBox = bbox; }
|
||||
void setMaxVertCount(const u32& count);
|
||||
|
||||
/**
|
||||
* @brief Create render packages from provided render data
|
||||
*
|
||||
* @param size Max maxVertCount verts (VU1 buffer size)
|
||||
*/
|
||||
StdpipBagPackage* create(u16* o_size, StdpipBag* data, u16 size);
|
||||
/**
|
||||
* @brief Split render package to smaller packages
|
||||
*
|
||||
* @param size Max maxVertCount verts (VU1 buffer size)
|
||||
*/
|
||||
StdpipBagPackage* create(u16* o_size, const StdpipBagPackage& pkg, u16 size);
|
||||
|
||||
CoreBBoxFrustum checkFrustum(const StdpipBagPackage& pkg);
|
||||
|
||||
private:
|
||||
u32 maxVertCount;
|
||||
Renderer3DFrustumPlanes* frustumPlanes;
|
||||
StdpipBagPackagesBBox* renderBBox;
|
||||
};
|
||||
|
||||
} // namespace Tyra
|
||||
@@ -0,0 +1,69 @@
|
||||
/*
|
||||
# ______ ____ ___
|
||||
# | \/ ____| |___|
|
||||
# | | | \ | |
|
||||
#-----------------------------------------------------------------------
|
||||
# Copyright 2022, tyra - https://github.com/h4570/tyra
|
||||
# Licenced under Apache License 2.0
|
||||
# Sandro Sobczyński <sandro.sobczynski@gmail.com>
|
||||
*/
|
||||
|
||||
#pragma once
|
||||
|
||||
#include "renderer/core/3d/bbox/render_bbox.hpp"
|
||||
|
||||
namespace Tyra {
|
||||
|
||||
/**
|
||||
* Splits all 3D input vertices into 16vert parts and creates child bboxes for
|
||||
* it
|
||||
*/
|
||||
class StdpipBagPackagesBBox {
|
||||
public:
|
||||
StdpipBagPackagesBBox(Vec4* t_vertices, u32* t_faces, const u32& t_facesCount,
|
||||
const u32& t_maxVertCount);
|
||||
StdpipBagPackagesBBox(Vec4* t_vertices, const u32& t_counts,
|
||||
const u32& t_maxVertCount);
|
||||
~StdpipBagPackagesBBox();
|
||||
|
||||
void setMaxVertCount(const u32& count);
|
||||
|
||||
/**
|
||||
* @param index Index of part
|
||||
*/
|
||||
const RenderBBox& getChildBBox1By3(const u32& index) const;
|
||||
|
||||
/** @brief CoreBBox created from all of vertices */
|
||||
RenderBBox* getMainBBox();
|
||||
|
||||
/** @brief Get amount of child Bbox1/3 parts */
|
||||
const u32& getPartsCount() const;
|
||||
|
||||
/** @brief Get amount of vertices */
|
||||
const u32& getVertexCount() const;
|
||||
|
||||
/**
|
||||
* @brief For example if we want to build a bbox from 96-112 vertices, we
|
||||
* should input index = 3, partsSize = 1
|
||||
* @param index Index of part
|
||||
* @param partsSize How many 1/3 parts
|
||||
*/
|
||||
RenderBBox createChildBBox(const u32& index, const u16& partsSize) const;
|
||||
|
||||
void print() const;
|
||||
void print(const char* name) const;
|
||||
void print(const std::string& name) const { print(name.c_str()); }
|
||||
std::string getPrint(const char* name = nullptr) const;
|
||||
|
||||
private:
|
||||
u32 maxVertCount;
|
||||
u32 vertexCount, partsCount;
|
||||
|
||||
/** @brief CoreBBox of all vertices */
|
||||
RenderBBox* mainBBox;
|
||||
|
||||
/** @brief Bounding boxes of 1/3 vertices */
|
||||
std::vector<CoreBBox>* bboxParts;
|
||||
};
|
||||
|
||||
} // namespace Tyra
|
||||
@@ -0,0 +1,62 @@
|
||||
/*
|
||||
# ______ ____ ___
|
||||
# | \/ ____| |___|
|
||||
# | | | \ | |
|
||||
#-----------------------------------------------------------------------
|
||||
# Copyright 2022, tyra - https://github.com/h4570/tyra
|
||||
# Licenced under Apache License 2.0
|
||||
# Sandro Sobczyński <sandro.sobczynski@gmail.com>
|
||||
*/
|
||||
|
||||
#pragma once
|
||||
|
||||
#include "math/vec4.hpp"
|
||||
#include "./stdpip_lighting_bag.hpp"
|
||||
#include "./stdpip_info_bag.hpp"
|
||||
#include "./stdpip_color_bag.hpp"
|
||||
#include "./stdpip_texture_bag.hpp"
|
||||
#include "renderer/core/texture/models/texture.hpp"
|
||||
#include "./packaging/stdpip_bag_packages_bbox.hpp"
|
||||
|
||||
namespace Tyra {
|
||||
|
||||
/**
|
||||
* @brief 3D Render data bag.
|
||||
* Supports frustum culling, clipping, lighting,
|
||||
* texture and single color / many colors.
|
||||
*/
|
||||
class StdpipBag {
|
||||
public:
|
||||
StdpipBag();
|
||||
~StdpipBag();
|
||||
|
||||
/** Mandatory. Object info. */
|
||||
StdpipInfoBag* info;
|
||||
|
||||
/** Mandatory. Object color(s). */
|
||||
StdpipColorBag* color;
|
||||
|
||||
/** Mandatory. Vertex count. */
|
||||
u32 count;
|
||||
|
||||
/** Mandatory. Vertices. */
|
||||
Vec4* vertices;
|
||||
|
||||
/** Optional. Texture coordinates and image. */
|
||||
StdpipTextureBag* texture;
|
||||
|
||||
/** Optional. Object lighting. */
|
||||
StdpipLightingBag* lighting;
|
||||
|
||||
/**
|
||||
* @param maxVertCount This parameter is available in renderer API.
|
||||
*/
|
||||
StdpipBagPackagesBBox calculateBbox(const u32& maxVertCount);
|
||||
|
||||
void print() const;
|
||||
void print(const char* name) const;
|
||||
void print(const std::string& name) const { print(name.c_str()); }
|
||||
std::string getPrint(const char* name = nullptr) const;
|
||||
};
|
||||
|
||||
} // namespace Tyra
|
||||
@@ -0,0 +1,32 @@
|
||||
/*
|
||||
# ______ ____ ___
|
||||
# | \/ ____| |___|
|
||||
# | | | \ | |
|
||||
#-----------------------------------------------------------------------
|
||||
# Copyright 2022, tyra - https://github.com/h4570/tyra
|
||||
# Licenced under Apache License 2.0
|
||||
# Sandro Sobczyński <sandro.sobczynski@gmail.com>
|
||||
*/
|
||||
|
||||
#pragma once
|
||||
|
||||
#include "renderer/models/color.hpp"
|
||||
|
||||
namespace Tyra {
|
||||
|
||||
/**
|
||||
* @brief Color data. At least one color data is required (single/many).
|
||||
*/
|
||||
class StdpipColorBag {
|
||||
public:
|
||||
StdpipColorBag();
|
||||
~StdpipColorBag();
|
||||
|
||||
/** Optional. Single color for all vertices. */
|
||||
Color* single;
|
||||
|
||||
/** Optional. Color per vertex. */
|
||||
Color* many;
|
||||
};
|
||||
|
||||
} // namespace Tyra
|
||||
@@ -0,0 +1,34 @@
|
||||
/*
|
||||
# ______ ____ ___
|
||||
# | \/ ____| |___|
|
||||
# | | | \ | |
|
||||
#-----------------------------------------------------------------------
|
||||
# Copyright 2022, tyra - https://github.com/h4570/tyra
|
||||
# Licenced under Apache License 2.0
|
||||
# Sandro Sobczyński <sandro.sobczynski@gmail.com>
|
||||
*/
|
||||
|
||||
#pragma once
|
||||
|
||||
#include <draw.h>
|
||||
#include "math/m4x4.hpp"
|
||||
#include "math/vec4.hpp"
|
||||
#include "../../stdpip_shading_type.hpp"
|
||||
|
||||
namespace Tyra {
|
||||
|
||||
class StdpipInfoBag {
|
||||
public:
|
||||
StdpipInfoBag();
|
||||
~StdpipInfoBag();
|
||||
|
||||
/** Mandatory. Model matrix */
|
||||
M4x4* model;
|
||||
|
||||
StdpipShadingType shadingType;
|
||||
bool blendingEnabled;
|
||||
bool antiAliasingEnabled;
|
||||
bool noClipChecks;
|
||||
};
|
||||
|
||||
} // namespace Tyra
|
||||
@@ -0,0 +1,56 @@
|
||||
/*
|
||||
# ______ ____ ___
|
||||
# | \/ ____| |___|
|
||||
# | | | \ | |
|
||||
#-----------------------------------------------------------------------
|
||||
# Copyright 2022, tyra - https://github.com/h4570/tyra
|
||||
# Licenced under Apache License 2.0
|
||||
# Sandro Sobczyński <sandro.sobczynski@gmail.com>
|
||||
*/
|
||||
|
||||
#pragma once
|
||||
|
||||
#include "renderer/models/color.hpp"
|
||||
#include "math/m4x4.hpp"
|
||||
#include "math/vec4.hpp"
|
||||
|
||||
namespace Tyra {
|
||||
|
||||
enum StdpipLightingBagMode { Auto, Manual };
|
||||
|
||||
class StdpipLightingBag {
|
||||
public:
|
||||
explicit StdpipLightingBag(const bool& manual = false);
|
||||
~StdpipLightingBag();
|
||||
|
||||
Vec4* normals;
|
||||
M4x4* lightMatrix;
|
||||
|
||||
void setAmbientColor(const Color& color);
|
||||
void setDirectionalLightColors(Color* colors, const u8& count);
|
||||
void setDirectionalLightDirections(Vec4* directions, const u8& count);
|
||||
void setDirectionalLightColor(const Color& color, const u8& index);
|
||||
void setDirectionalLightDirection(const Vec4& direction, const u8& index);
|
||||
|
||||
void setLightsManually(Vec4* colors, Vec4* directions);
|
||||
void disableManualMode();
|
||||
|
||||
Vec4* getLightColors() { return lightColors; }
|
||||
|
||||
Vec4* getLightDirections() { return lightDirections; }
|
||||
|
||||
void forceDeallocateColors();
|
||||
void forceDeallocateDirections();
|
||||
|
||||
private:
|
||||
void allocate();
|
||||
void deallocate();
|
||||
void forceDeallocate();
|
||||
u8 isAllocated;
|
||||
StdpipLightingBagMode mode;
|
||||
|
||||
Vec4* lightColors;
|
||||
Vec4* lightDirections;
|
||||
};
|
||||
|
||||
} // namespace Tyra
|
||||
@@ -0,0 +1,30 @@
|
||||
/*
|
||||
# ______ ____ ___
|
||||
# | \/ ____| |___|
|
||||
# | | | \ | |
|
||||
#-----------------------------------------------------------------------
|
||||
# Copyright 2022, tyra - https://github.com/h4570/tyra
|
||||
# Licenced under Apache License 2.0
|
||||
# Sandro Sobczyński <sandro.sobczynski@gmail.com>
|
||||
*/
|
||||
|
||||
#pragma once
|
||||
|
||||
#include "math/vec4.hpp"
|
||||
#include "renderer/core/texture/models/texture.hpp"
|
||||
|
||||
namespace Tyra {
|
||||
|
||||
class StdpipTextureBag {
|
||||
public:
|
||||
StdpipTextureBag();
|
||||
~StdpipTextureBag();
|
||||
|
||||
/** Mandatory. Texture coordinates per vertex. */
|
||||
Vec4* coordinates;
|
||||
|
||||
/** Mandatory. Texture image. */
|
||||
Texture* texture;
|
||||
};
|
||||
|
||||
} // namespace Tyra
|
||||
+30
@@ -0,0 +1,30 @@
|
||||
/*
|
||||
# ______ ____ ___
|
||||
# | \/ ____| |___|
|
||||
# | | | \ | |
|
||||
#-----------------------------------------------------------------------
|
||||
# Copyright 2022, tyra - https://github.com/h4570/tyra
|
||||
# Licenced under Apache License 2.0
|
||||
# Sandro Sobczyński <sandro.sobczynski@gmail.com>
|
||||
*/
|
||||
|
||||
#pragma once
|
||||
|
||||
#include <packet2_utils.h>
|
||||
#include <string>
|
||||
#include "../../stdpip_vu1_program.hpp"
|
||||
|
||||
namespace Tyra {
|
||||
|
||||
class StdpipAsIsCVU1Program : public StdpipVU1Program {
|
||||
public:
|
||||
StdpipAsIsCVU1Program();
|
||||
~StdpipAsIsCVU1Program();
|
||||
|
||||
std::string getStringName() const;
|
||||
|
||||
void addProgramQBufferDataToPacket(packet2_t* packet,
|
||||
StdpipQBuffer* qbuffer) const;
|
||||
};
|
||||
|
||||
} // namespace Tyra
|
||||
+29
@@ -0,0 +1,29 @@
|
||||
/*
|
||||
# ______ ____ ___
|
||||
# | \/ ____| |___|
|
||||
# | | | \ | |
|
||||
#-----------------------------------------------------------------------
|
||||
# Copyright 2022, tyra - https://github.com/h4570/tyra
|
||||
# Licenced under Apache License 2.0
|
||||
# Sandro Sobczyński <sandro.sobczynski@gmail.com>
|
||||
*/
|
||||
|
||||
#pragma once
|
||||
|
||||
#include <packet2_utils.h>
|
||||
#include <string>
|
||||
#include "../../stdpip_vu1_program.hpp"
|
||||
|
||||
namespace Tyra {
|
||||
|
||||
class StdpipAsIsDVU1Program : public StdpipVU1Program {
|
||||
public:
|
||||
StdpipAsIsDVU1Program();
|
||||
~StdpipAsIsDVU1Program();
|
||||
|
||||
std::string getStringName() const;
|
||||
void addProgramQBufferDataToPacket(packet2_t* packet,
|
||||
StdpipQBuffer* qbuffer) const;
|
||||
};
|
||||
|
||||
} // namespace Tyra
|
||||
+29
@@ -0,0 +1,29 @@
|
||||
/*
|
||||
# ______ ____ ___
|
||||
# | \/ ____| |___|
|
||||
# | | | \ | |
|
||||
#-----------------------------------------------------------------------
|
||||
# Copyright 2022, tyra - https://github.com/h4570/tyra
|
||||
# Licenced under Apache License 2.0
|
||||
# Sandro Sobczyński <sandro.sobczynski@gmail.com>
|
||||
*/
|
||||
|
||||
#pragma once
|
||||
|
||||
#include <packet2_utils.h>
|
||||
#include <string>
|
||||
#include "../../stdpip_vu1_program.hpp"
|
||||
|
||||
namespace Tyra {
|
||||
|
||||
class StdpipAsIsTCVU1Program : public StdpipVU1Program {
|
||||
public:
|
||||
StdpipAsIsTCVU1Program();
|
||||
~StdpipAsIsTCVU1Program();
|
||||
|
||||
std::string getStringName() const;
|
||||
void addProgramQBufferDataToPacket(packet2_t* packet,
|
||||
StdpipQBuffer* qbuffer) const;
|
||||
};
|
||||
|
||||
} // namespace Tyra
|
||||
+29
@@ -0,0 +1,29 @@
|
||||
/*
|
||||
# ______ ____ ___
|
||||
# | \/ ____| |___|
|
||||
# | | | \ | |
|
||||
#-----------------------------------------------------------------------
|
||||
# Copyright 2022, tyra - https://github.com/h4570/tyra
|
||||
# Licenced under Apache License 2.0
|
||||
# Sandro Sobczyński <sandro.sobczynski@gmail.com>
|
||||
*/
|
||||
|
||||
#pragma once
|
||||
|
||||
#include <packet2_utils.h>
|
||||
#include <string>
|
||||
#include "../../stdpip_vu1_program.hpp"
|
||||
|
||||
namespace Tyra {
|
||||
|
||||
class StdpipAsIsTDVU1Program : public StdpipVU1Program {
|
||||
public:
|
||||
StdpipAsIsTDVU1Program();
|
||||
~StdpipAsIsTDVU1Program();
|
||||
|
||||
std::string getStringName() const;
|
||||
void addProgramQBufferDataToPacket(packet2_t* packet,
|
||||
StdpipQBuffer* qbuffer) const;
|
||||
};
|
||||
|
||||
} // namespace Tyra
|
||||
+29
@@ -0,0 +1,29 @@
|
||||
/*
|
||||
# ______ ____ ___
|
||||
# | \/ ____| |___|
|
||||
# | | | \ | |
|
||||
#-----------------------------------------------------------------------
|
||||
# Copyright 2022, tyra - https://github.com/h4570/tyra
|
||||
# Licenced under Apache License 2.0
|
||||
# Sandro Sobczyński <sandro.sobczynski@gmail.com>
|
||||
*/
|
||||
|
||||
#pragma once
|
||||
|
||||
#include <packet2_utils.h>
|
||||
#include <string>
|
||||
#include "../../stdpip_vu1_program.hpp"
|
||||
|
||||
namespace Tyra {
|
||||
|
||||
class StdpipCullCVU1Program : public StdpipVU1Program {
|
||||
public:
|
||||
StdpipCullCVU1Program();
|
||||
~StdpipCullCVU1Program();
|
||||
|
||||
std::string getStringName() const;
|
||||
void addProgramQBufferDataToPacket(packet2_t* packet,
|
||||
StdpipQBuffer* qbuffer) const;
|
||||
};
|
||||
|
||||
} // namespace Tyra
|
||||
+29
@@ -0,0 +1,29 @@
|
||||
/*
|
||||
# ______ ____ ___
|
||||
# | \/ ____| |___|
|
||||
# | | | \ | |
|
||||
#-----------------------------------------------------------------------
|
||||
# Copyright 2022, tyra - https://github.com/h4570/tyra
|
||||
# Licenced under Apache License 2.0
|
||||
# Sandro Sobczyński <sandro.sobczynski@gmail.com>
|
||||
*/
|
||||
|
||||
#pragma once
|
||||
|
||||
#include <packet2_utils.h>
|
||||
#include <string>
|
||||
#include "../../stdpip_vu1_program.hpp"
|
||||
|
||||
namespace Tyra {
|
||||
|
||||
class StdpipCullDVU1Program : public StdpipVU1Program {
|
||||
public:
|
||||
StdpipCullDVU1Program();
|
||||
~StdpipCullDVU1Program();
|
||||
|
||||
std::string getStringName() const;
|
||||
void addProgramQBufferDataToPacket(packet2_t* packet,
|
||||
StdpipQBuffer* qbuffer) const;
|
||||
};
|
||||
|
||||
} // namespace Tyra
|
||||
+29
@@ -0,0 +1,29 @@
|
||||
/*
|
||||
# ______ ____ ___
|
||||
# | \/ ____| |___|
|
||||
# | | | \ | |
|
||||
#-----------------------------------------------------------------------
|
||||
# Copyright 2022, tyra - https://github.com/h4570/tyra
|
||||
# Licenced under Apache License 2.0
|
||||
# Sandro Sobczyński <sandro.sobczynski@gmail.com>
|
||||
*/
|
||||
|
||||
#pragma once
|
||||
|
||||
#include <packet2_utils.h>
|
||||
#include <string>
|
||||
#include "../../stdpip_vu1_program.hpp"
|
||||
|
||||
namespace Tyra {
|
||||
|
||||
class StdpipCullTCVU1Program : public StdpipVU1Program {
|
||||
public:
|
||||
StdpipCullTCVU1Program();
|
||||
~StdpipCullTCVU1Program();
|
||||
|
||||
std::string getStringName() const;
|
||||
void addProgramQBufferDataToPacket(packet2_t* packet,
|
||||
StdpipQBuffer* qbuffer) const;
|
||||
};
|
||||
|
||||
} // namespace Tyra
|
||||
+29
@@ -0,0 +1,29 @@
|
||||
/*
|
||||
# ______ ____ ___
|
||||
# | \/ ____| |___|
|
||||
# | | | \ | |
|
||||
#-----------------------------------------------------------------------
|
||||
# Copyright 2022, tyra - https://github.com/h4570/tyra
|
||||
# Licenced under Apache License 2.0
|
||||
# Sandro Sobczyński <sandro.sobczynski@gmail.com>
|
||||
*/
|
||||
|
||||
#pragma once
|
||||
|
||||
#include <packet2_utils.h>
|
||||
#include <string>
|
||||
#include "../../stdpip_vu1_program.hpp"
|
||||
|
||||
namespace Tyra {
|
||||
|
||||
class StdpipCullTDVU1Program : public StdpipVU1Program {
|
||||
public:
|
||||
StdpipCullTDVU1Program();
|
||||
~StdpipCullTDVU1Program();
|
||||
|
||||
std::string getStringName() const;
|
||||
void addProgramQBufferDataToPacket(packet2_t* packet,
|
||||
StdpipQBuffer* qbuffer) const;
|
||||
};
|
||||
|
||||
} // namespace Tyra
|
||||
@@ -0,0 +1,24 @@
|
||||
//
|
||||
// ______ ____ ___
|
||||
// | \/ ____| |___|
|
||||
// | | | \ | |
|
||||
//-----------------------------------------------------------------------
|
||||
// Copyright 2022, tyra - https://github.com/h4570/tyra
|
||||
// Licenced under Apache License 2.0
|
||||
// Sandro Sobczyński <sandro.sobczynski@gmail.com>
|
||||
//
|
||||
|
||||
// Updated once per mesh
|
||||
#define VU1_MVP_MATRIX_ADDR 0
|
||||
#define VU1_LIGHTS_MATRIX_ADDR 4
|
||||
#define VU1_SINGLE_COLOR_ADDR 7
|
||||
#define VU1_OPTIONS_ADDR 8
|
||||
#define VU1_LOD_ADDR 9
|
||||
#define VU1_CLUT_ADDR 10
|
||||
#define VU1_LIGHTS_DIRS_ADDR 11
|
||||
#define VU1_LIGHTS_COLORS_ADDR 14
|
||||
#define VU1_SET_GIFTAG_ADDR 18
|
||||
#define VU1_LAST_ITEM_ADDR 18
|
||||
|
||||
// Buffer data (xtop)
|
||||
#define VU1_VERT_DATA_ADDR 2
|
||||
@@ -0,0 +1,47 @@
|
||||
/*
|
||||
# ______ ____ ___
|
||||
# | \/ ____| |___|
|
||||
# | | | \ | |
|
||||
#-----------------------------------------------------------------------
|
||||
# Copyright 2022, tyra - https://github.com/h4570/tyra
|
||||
# Licenced under Apache License 2.0
|
||||
# Sandro Sobczyński <sandro.sobczynski@gmail.com>
|
||||
*/
|
||||
|
||||
#pragma once
|
||||
|
||||
#include <vector>
|
||||
#include "debug/debug.hpp"
|
||||
#include "./stdpip_qbuffer.hpp"
|
||||
#include "renderer/renderer_settings.hpp"
|
||||
#include "renderer/core/paths/path1/clipper/path1_ee_clip_algorithm.hpp"
|
||||
|
||||
namespace Tyra {
|
||||
|
||||
/**
|
||||
* @brief This class requires VU1 buffer with max buffsize/3 vertices.
|
||||
* It will clip triangles and fill the buffer.
|
||||
*
|
||||
* To be honest clipping algorithm should be moved to VU1 and "AsIs" VU1 program
|
||||
* should be renamed to "Clip" - I don't want to do it now, too much time.
|
||||
*/
|
||||
class StdpipClipper {
|
||||
public:
|
||||
StdpipClipper();
|
||||
~StdpipClipper();
|
||||
void clip(StdpipQBuffer* buffer);
|
||||
void init(const RendererSettings& settings);
|
||||
void setMaxVertCount(const u32& count);
|
||||
void setMVP(M4x4* mvp);
|
||||
|
||||
private:
|
||||
u32 maxVertCount;
|
||||
Path1EEClipAlgorithm algorithm;
|
||||
M4x4* mvp;
|
||||
|
||||
void perspectiveDivide(std::vector<Path1ClipVertex>* vertices);
|
||||
void moveDataToBuffer(const std::vector<Path1ClipVertex>& vertices,
|
||||
StdpipQBuffer* buffer);
|
||||
};
|
||||
|
||||
} // namespace Tyra
|
||||
@@ -0,0 +1,31 @@
|
||||
/*
|
||||
# ______ ____ ___
|
||||
# | \/ ____| |___|
|
||||
# | | | \ | |
|
||||
#-----------------------------------------------------------------------
|
||||
# Copyright 2022, tyra - https://github.com/h4570/tyra
|
||||
# Licenced under Apache License 2.0
|
||||
# Sandro Sobczyński <sandro.sobczynski@gmail.com>
|
||||
*/
|
||||
|
||||
#pragma once
|
||||
|
||||
namespace Tyra {
|
||||
|
||||
enum StdpipProgramName {
|
||||
StdipUndefinedProgram,
|
||||
|
||||
StdpipCullColor,
|
||||
StdpipAsIsColor,
|
||||
|
||||
StdpipCullDirLights,
|
||||
StdpipAsIsDirLights,
|
||||
|
||||
StdpipCullTextureDirLights,
|
||||
StdpipAsIsTextureDirLights,
|
||||
|
||||
StdpipCullTextureColor,
|
||||
StdpipAsIsTextureColor,
|
||||
};
|
||||
|
||||
} // namespace Tyra
|
||||
@@ -0,0 +1,22 @@
|
||||
/*
|
||||
# ______ ____ ___
|
||||
# | \/ ____| |___|
|
||||
# | | | \ | |
|
||||
#-----------------------------------------------------------------------
|
||||
# Copyright 2022, tyra - https://github.com/h4570/tyra
|
||||
# Licenced under Apache License 2.0
|
||||
# Sandro Sobczyński <sandro.sobczynski@gmail.com>
|
||||
*/
|
||||
|
||||
#pragma once
|
||||
|
||||
namespace Tyra {
|
||||
|
||||
enum StdpipProgramType {
|
||||
StdpipVU1Color,
|
||||
StdpipVU1DirLights,
|
||||
StdpipVU1TextureDirLights,
|
||||
StdpipVU1TextureColor,
|
||||
};
|
||||
|
||||
} // namespace Tyra
|
||||
@@ -0,0 +1,49 @@
|
||||
/*
|
||||
# ______ ____ ___
|
||||
# | \/ ____| |___|
|
||||
# | | | \ | |
|
||||
#-----------------------------------------------------------------------
|
||||
# Copyright 2022, tyra - https://github.com/h4570/tyra
|
||||
# Licenced under Apache License 2.0
|
||||
# Sandro Sobczyński <sandro.sobczynski@gmail.com>
|
||||
*/
|
||||
|
||||
#pragma once
|
||||
|
||||
#include "debug/debug.hpp"
|
||||
#include "renderer/core/paths/path1/vu1_program.hpp"
|
||||
|
||||
#include "./programs/as_is/stdpip_as_is_c_vu1_program.hpp"
|
||||
#include "./programs/as_is/stdpip_as_is_d_vu1_program.hpp"
|
||||
#include "./programs/as_is/stdpip_as_is_td_vu1_program.hpp"
|
||||
#include "./programs/as_is/stdpip_as_is_tc_vu1_program.hpp"
|
||||
|
||||
#include "./programs/cull/stdpip_cull_c_vu1_program.hpp"
|
||||
#include "./programs/cull/stdpip_cull_d_vu1_program.hpp"
|
||||
#include "./programs/cull/stdpip_cull_td_vu1_program.hpp"
|
||||
#include "./programs/cull/stdpip_cull_tc_vu1_program.hpp"
|
||||
|
||||
#include "renderer/core/paths/path1/programs/draw_finish/vu1_draw_finish.hpp"
|
||||
|
||||
namespace Tyra {
|
||||
|
||||
class StdpipProgramsRepository {
|
||||
public:
|
||||
StdpipProgramsRepository();
|
||||
~StdpipProgramsRepository();
|
||||
|
||||
StdpipVU1Program* getProgram(const StdpipProgramName& name);
|
||||
|
||||
private:
|
||||
StdpipAsIsCVU1Program asIsColor;
|
||||
StdpipCullCVU1Program cullColor;
|
||||
StdpipAsIsDVU1Program asIsLightingColor;
|
||||
StdpipCullDVU1Program cullLightingColor;
|
||||
StdpipAsIsTDVU1Program asIsLightingTextureColor;
|
||||
StdpipCullTDVU1Program cullLightingTextureColor;
|
||||
StdpipAsIsTCVU1Program asIsTextureColor;
|
||||
StdpipCullTCVU1Program cullTextureColor;
|
||||
VU1DrawFinish drawFinish;
|
||||
};
|
||||
|
||||
} // namespace Tyra
|
||||
@@ -0,0 +1,84 @@
|
||||
/*
|
||||
# ______ ____ ___
|
||||
# | \/ ____| |___|
|
||||
# | | | \ | |
|
||||
#-----------------------------------------------------------------------
|
||||
# Copyright 2022, tyra - https://github.com/h4570/tyra
|
||||
# Licenced under Apache License 2.0
|
||||
# Sandro Sobczyński <sandro.sobczynski@gmail.com>
|
||||
*/
|
||||
|
||||
#pragma once
|
||||
|
||||
#include <math3d.h>
|
||||
#include <string>
|
||||
#include <sstream>
|
||||
#include "debug/debug.hpp"
|
||||
#include "../bag/packaging/stdpip_bag_package.hpp"
|
||||
#include "../bag/stdpip_bag.hpp"
|
||||
|
||||
namespace Tyra {
|
||||
|
||||
class StdpipQBuffer {
|
||||
public:
|
||||
StdpipQBuffer();
|
||||
~StdpipQBuffer();
|
||||
|
||||
void setMaxVertCount(const u32& count);
|
||||
|
||||
/**
|
||||
* @brief Dont allocate any dynamic data in buffer.
|
||||
* Just copy pointers to input data.
|
||||
*/
|
||||
void fillByPointer(const StdpipBagPackage& pkg);
|
||||
|
||||
/**
|
||||
* @brief Allocate dynamic data in buffer
|
||||
* And copy input data to it.
|
||||
*/
|
||||
void fillByCopyMax(const StdpipBagPackage& pkg1, const StdpipBagPackage& pkg2,
|
||||
const StdpipBagPackage& pkg3);
|
||||
|
||||
/**
|
||||
* @brief Allocate dynamic data in buffer
|
||||
* And copy input data to it.
|
||||
*/
|
||||
void fillByCopy1By2(const StdpipBagPackage& pkg1,
|
||||
const StdpipBagPackage& pkg2);
|
||||
|
||||
/**
|
||||
* @brief Allocate dynamic data in buffer
|
||||
* And copy input data to it.
|
||||
*/
|
||||
void fillByCopy1By3(const StdpipBagPackage& pkg);
|
||||
|
||||
/**
|
||||
* @brief Deallocate dynamic data if it was allocated and allocate new data
|
||||
* specified by size.
|
||||
* @param size 48 is max
|
||||
*/
|
||||
void reallocateManually(const u16& size);
|
||||
|
||||
bool any() const;
|
||||
|
||||
StdpipBag* bag;
|
||||
|
||||
Vec4* vertices;
|
||||
Vec4* sts;
|
||||
Vec4* colors;
|
||||
Vec4* normals;
|
||||
u32 size;
|
||||
|
||||
void print() const;
|
||||
void print(const char* name) const;
|
||||
void print(const std::string& name) const { print(name.c_str()); }
|
||||
std::string getPrint(const char* name = nullptr) const;
|
||||
|
||||
private:
|
||||
u32 maxVertCount;
|
||||
void deallocateDynamicData();
|
||||
void allocateDynamicData(u16 size, StdpipBag* bag);
|
||||
u8 _isDynamicallyAllocated, _stAllocated, _colorAllocated, _normalAllocated;
|
||||
};
|
||||
|
||||
} // namespace Tyra
|
||||
@@ -0,0 +1,98 @@
|
||||
/*
|
||||
# ______ ____ ___
|
||||
# | \/ ____| |___|
|
||||
# | | | \ | |
|
||||
#-----------------------------------------------------------------------
|
||||
# Copyright 2022, tyra - https://github.com/h4570/tyra
|
||||
# Licenced under Apache License 2.0
|
||||
# Sandro Sobczyński <sandro.sobczynski@gmail.com>
|
||||
*/
|
||||
|
||||
#pragma once
|
||||
|
||||
#include <dma.h>
|
||||
#include <packet2_utils.h>
|
||||
#include <vector>
|
||||
#include "debug/debug.hpp"
|
||||
#include "math/m4x4.hpp"
|
||||
#include "renderer/renderer_settings.hpp"
|
||||
#include "renderer/models/color.hpp"
|
||||
#include "./stdpip_qbuffer.hpp"
|
||||
#include "./stdpip_program_type.hpp"
|
||||
#include "./stdpip_program_name.hpp"
|
||||
#include "./stdpip_programs_repository.hpp"
|
||||
#include "./stdpip_clipper.hpp"
|
||||
#include "renderer/core/paths/path1/path1.hpp"
|
||||
#include "renderer/core/renderer_core.hpp"
|
||||
#include "renderer/core/texture/renderer_core_texture_buffers.hpp"
|
||||
|
||||
namespace Tyra {
|
||||
|
||||
class StdpipQBufferRenderer {
|
||||
public:
|
||||
StdpipQBufferRenderer();
|
||||
~StdpipQBufferRenderer();
|
||||
|
||||
void init(RendererCore* t_core);
|
||||
|
||||
void reinitVU1();
|
||||
|
||||
void setClipperMVP(M4x4* mvp) { clipper.setMVP(mvp); }
|
||||
|
||||
StdpipQBuffer* getBuffer();
|
||||
|
||||
void sendObjectData(StdpipBag* bag, M4x4* mvp,
|
||||
RendererCoreTextureBuffers* texBuffers) const;
|
||||
|
||||
void setMaxVertCount(const u32& count);
|
||||
|
||||
void setInfo(StdpipInfoBag* bag);
|
||||
|
||||
/** Fast render with culling */
|
||||
void cull(StdpipQBuffer* buffer);
|
||||
|
||||
/** Slower render with clipping */
|
||||
void clip(StdpipQBuffer* buffer);
|
||||
|
||||
void clearLastProgramName();
|
||||
|
||||
StdpipVU1Program* getCullProgramByBag(const StdpipBag* bag);
|
||||
|
||||
StdpipVU1Program* getCullProgramByParams(const bool& isLightingEnabled,
|
||||
const bool& isTextureEnabled);
|
||||
|
||||
const u16& getBufferSize() { return bufferSize; }
|
||||
|
||||
private:
|
||||
void sendStaticData() const;
|
||||
void setProgramsCache();
|
||||
void uploadPrograms();
|
||||
void setDoubleBuffer();
|
||||
|
||||
StdpipVU1Program* getProgramByName(const StdpipProgramName& name);
|
||||
void addBufferDataToPacket(StdpipVU1Program* program, StdpipQBuffer* buffer);
|
||||
void sendPacket();
|
||||
StdpipVU1Program* getAsIsProgramByBag(const StdpipBag* bag);
|
||||
StdpipVU1Program* getCullProgramByType(const StdpipProgramType& programType);
|
||||
StdpipProgramType getDrawProgramTypeByBag(const StdpipBag* bag) const;
|
||||
StdpipProgramType getDrawProgramTypeByParams(
|
||||
const bool& isLightingEnabled, const bool& isTextureEnabled) const;
|
||||
packet2_t* packets[2];
|
||||
packet2_t* programsPacket;
|
||||
StdpipQBuffer buffers[2];
|
||||
packet2_t* currentPacket;
|
||||
packet2_t* staticDataPacket;
|
||||
packet2_t* objectDataPacket;
|
||||
|
||||
RendererCore* rendererCore;
|
||||
|
||||
StdpipProgramName lastProgramName;
|
||||
Path1* path1;
|
||||
StdpipClipper clipper;
|
||||
StdpipProgramsRepository repository;
|
||||
|
||||
u16 bufferSize;
|
||||
u8 context;
|
||||
};
|
||||
|
||||
} // namespace Tyra
|
||||
@@ -0,0 +1,50 @@
|
||||
/*
|
||||
# ______ ____ ___
|
||||
# | \/ ____| |___|
|
||||
# | | | \ | |
|
||||
#-----------------------------------------------------------------------
|
||||
# Copyright 2022, tyra - https://github.com/h4570/tyra
|
||||
# Licenced under Apache License 2.0
|
||||
# Sandro Sobczyński <sandro.sobczynski@gmail.com>
|
||||
*/
|
||||
|
||||
#pragma once
|
||||
|
||||
#include "./stdpip_program_name.hpp"
|
||||
#include "renderer/core/paths/path1/vu1_program.hpp"
|
||||
#include "./stdpip_qbuffer.hpp"
|
||||
#include "./programs/stdpip_vu1_shared_defines.h"
|
||||
|
||||
namespace Tyra {
|
||||
|
||||
class StdpipVU1Program : public VU1Program {
|
||||
public:
|
||||
StdpipVU1Program(const StdpipProgramName& name, u32* start, u32* end,
|
||||
const u32& t_reglist, const u8& t_reglistCount,
|
||||
const u8& t_elementsPerVertex);
|
||||
~StdpipVU1Program();
|
||||
|
||||
u32& getReglist();
|
||||
|
||||
const StdpipProgramName& getName() const;
|
||||
|
||||
u16 getMaxVertCount(const bool& singleColorEnabled,
|
||||
const u16& vu1DBufferSize) const;
|
||||
|
||||
void addBufferDataToPacket(packet2_t* packet, StdpipQBuffer* buffer,
|
||||
prim_t* prim);
|
||||
|
||||
protected:
|
||||
StdpipProgramName name;
|
||||
u8 reglistCount, elementsPerVertex;
|
||||
u32 destinationAddress, reglist;
|
||||
|
||||
virtual void addProgramQBufferDataToPacket(packet2_t* packet,
|
||||
StdpipQBuffer* qbuffer) const = 0;
|
||||
|
||||
private:
|
||||
void addStandardBufferDataToPacket(packet2_t* packet, StdpipQBuffer* buffer,
|
||||
prim_t* prim);
|
||||
};
|
||||
|
||||
} // namespace Tyra
|
||||
@@ -0,0 +1,59 @@
|
||||
/*
|
||||
# ______ ____ ___
|
||||
# | \/ ____| |___|
|
||||
# | | | \ | |
|
||||
#-----------------------------------------------------------------------
|
||||
# Copyright 2022, tyra - https://github.com/h4570/tyra
|
||||
# Licenced under Apache License 2.0
|
||||
# Sandro Sobczyński <sandro.sobczynski@gmail.com>
|
||||
*/
|
||||
|
||||
#pragma once
|
||||
|
||||
#include <tamtypes.h>
|
||||
#include "./bag/stdpip_bag.hpp"
|
||||
#include "./bag/packaging/stdpip_bag_packages_bbox.hpp"
|
||||
#include "./bag/packaging/stdpip_bag_package.hpp"
|
||||
#include "./bag/packaging/stdpip_bag_packager.hpp"
|
||||
#include "./path1/stdpip_qbuffer_renderer.hpp"
|
||||
|
||||
namespace Tyra {
|
||||
|
||||
class StdPipelineCore {
|
||||
public:
|
||||
StdPipelineCore();
|
||||
~StdPipelineCore();
|
||||
|
||||
void init(RendererCore* t_core);
|
||||
|
||||
/** Render 3D data via "bags" */
|
||||
void render(StdpipBag* data, StdpipBagPackagesBBox* bbox = nullptr);
|
||||
|
||||
/** Get max vert count of VU1 qbuffer (for optimizations) */
|
||||
u32 getMaxVertCountByParams(const bool& isSingleColor,
|
||||
const bool& isLightingEnabled,
|
||||
const bool& isTextureEnabled);
|
||||
|
||||
/** Get max vert count of VU1 qbuffer (for optimizations) */
|
||||
u32 getMaxVertCountByBag(const StdpipBag* bag);
|
||||
|
||||
/**
|
||||
* - Uploads standard VU1 programs.
|
||||
* - Sends static "Tyra Renderer3D" VU1 data.
|
||||
* - Sets double buffers exactly for "Tyra Renderer3D"
|
||||
* Should be called if VU1 was used by your non standard programs.
|
||||
*/
|
||||
void reinitStandardVU1Programs();
|
||||
|
||||
private:
|
||||
u32 maxVertCount;
|
||||
RendererCore* rendererCore;
|
||||
|
||||
void setMaxVertCount(const u32& count);
|
||||
StdpipBagPackager packager;
|
||||
StdpipQBufferRenderer qbufferRenderer;
|
||||
void renderPkgs(StdpipBagPackage* packages, u16 count);
|
||||
void renderSubpkgs(StdpipBagPackage* packages, u16 count);
|
||||
};
|
||||
|
||||
} // namespace Tyra
|
||||
@@ -0,0 +1,59 @@
|
||||
/*
|
||||
# ______ ____ ___
|
||||
# | \/ ____| |___|
|
||||
# | | | \ | |
|
||||
#-----------------------------------------------------------------------
|
||||
# Copyright 2022, tyra - https://github.com/h4570/tyra
|
||||
# Licenced under Apache License 2.0
|
||||
# Sandro Sobczyński <sandro.sobczynski@gmail.com>
|
||||
*/
|
||||
|
||||
#pragma once
|
||||
|
||||
#include <tamtypes.h>
|
||||
#include "../renderer_3d_pipeline.hpp"
|
||||
#include "./stdpip_options.hpp"
|
||||
#include "renderer/core/renderer_core.hpp"
|
||||
#include "renderer/3d/mesh/mesh.hpp"
|
||||
#include "./core/std_pipeline_core.hpp"
|
||||
|
||||
namespace Tyra {
|
||||
|
||||
class StdPipeline : public Renderer3DPipeline {
|
||||
public:
|
||||
StdPipeline();
|
||||
~StdPipeline();
|
||||
|
||||
void init(RendererCore* core);
|
||||
|
||||
void onUse();
|
||||
|
||||
/**
|
||||
* Render 3D data via "meshes".
|
||||
* This render() method is a bridge to core.renderer3D.render() method.
|
||||
*/
|
||||
void render(Mesh* mesh, const StdpipOptions* options = nullptr);
|
||||
|
||||
private:
|
||||
StdPipelineCore core;
|
||||
RendererCore* rendererCore;
|
||||
Vec4* colorsCache;
|
||||
|
||||
void addVertices(Mesh* mesh, MeshMaterial* material, StdpipBag* bag,
|
||||
MeshFrame* frameFrom, MeshFrame* frameTo) const;
|
||||
StdpipInfoBag* getInfoBag(Mesh* mesh, const StdpipOptions* options,
|
||||
M4x4* model) const;
|
||||
StdpipColorBag* getColorBag(Mesh* mesh, MeshMaterial* material,
|
||||
MeshFrame* frameFrom, MeshFrame* frameTo) const;
|
||||
StdpipTextureBag* getTextureBag(Mesh* mesh, MeshMaterial* material,
|
||||
MeshFrame* frameFrom, MeshFrame* frameTo);
|
||||
StdpipLightingBag* getLightingBag(Mesh* mesh, MeshMaterial* material,
|
||||
M4x4* model, MeshFrame* frameFrom,
|
||||
MeshFrame* frameTo,
|
||||
const StdpipOptions* options) const;
|
||||
void deallocDrawBags(StdpipBag* bag, MeshMaterial* material) const;
|
||||
|
||||
void setLightingColorsCache(StdpipLightingOptions* lightingOptions);
|
||||
};
|
||||
|
||||
} // namespace Tyra
|
||||
@@ -0,0 +1,44 @@
|
||||
/*
|
||||
# ______ ____ ___
|
||||
# | \/ ____| |___|
|
||||
# | | | \ | |
|
||||
#-----------------------------------------------------------------------
|
||||
# Copyright 2022, tyra - https://github.com/h4570/tyra
|
||||
# Licenced under Apache License 2.0
|
||||
# Sandro Sobczyński <sandro.sobczynski@gmail.com>
|
||||
*/
|
||||
|
||||
#pragma once
|
||||
|
||||
#include "math/vec4.hpp"
|
||||
#include "renderer/models/color.hpp"
|
||||
|
||||
namespace Tyra {
|
||||
|
||||
class StdpipLightingOptions {
|
||||
public:
|
||||
StdpipLightingOptions() {}
|
||||
~StdpipLightingOptions() {}
|
||||
|
||||
/**
|
||||
* Mandatory.
|
||||
* Default 128.0F, 128.0F, 128.0F, 128.0F
|
||||
*/
|
||||
Color* ambientColor;
|
||||
|
||||
/**
|
||||
* Mandatory.
|
||||
* Min/max length - 3.
|
||||
* Example color value: 64.0F, 0.0F, 0.0F, 1.0F
|
||||
*/
|
||||
Color* directionalColors;
|
||||
|
||||
/**
|
||||
* Mandatory.
|
||||
* Min/max length - 3.
|
||||
* Example dir value: 1.0F, 0.0F, 0.0F, 1.0F
|
||||
*/
|
||||
Vec4* directionalDirections;
|
||||
};
|
||||
|
||||
} // namespace Tyra
|
||||
@@ -0,0 +1,32 @@
|
||||
/*
|
||||
# ______ ____ ___
|
||||
# | \/ ____| |___|
|
||||
# | | | \ | |
|
||||
#-----------------------------------------------------------------------
|
||||
# Copyright 2022, tyra - https://github.com/h4570/tyra
|
||||
# Licenced under Apache License 2.0
|
||||
# Sandro Sobczyński <sandro.sobczynski@gmail.com>
|
||||
*/
|
||||
|
||||
#pragma once
|
||||
|
||||
#include "./stdpip_shading_type.hpp"
|
||||
#include "./stdpip_lighting_options.hpp"
|
||||
|
||||
namespace Tyra {
|
||||
|
||||
class StdpipOptions {
|
||||
public:
|
||||
StdpipOptions() {}
|
||||
~StdpipOptions() {}
|
||||
|
||||
StdpipShadingType shadingType;
|
||||
bool blendingEnabled;
|
||||
bool antiAliasingEnabled;
|
||||
bool noClipChecks;
|
||||
|
||||
/** Optional */
|
||||
StdpipLightingOptions* lighting;
|
||||
};
|
||||
|
||||
} // namespace Tyra
|
||||
@@ -0,0 +1,20 @@
|
||||
/*
|
||||
# ______ ____ ___
|
||||
# | \/ ____| |___|
|
||||
# | | | \ | |
|
||||
#-----------------------------------------------------------------------
|
||||
# Copyright 2022, tyra - https://github.com/h4570/tyra
|
||||
# Licenced under Apache License 2.0
|
||||
# Sandro Sobczyński <sandro.sobczynski@gmail.com>
|
||||
*/
|
||||
|
||||
#pragma once
|
||||
|
||||
namespace Tyra {
|
||||
|
||||
enum StdpipShadingType {
|
||||
StdpipShadingFlat,
|
||||
StdpipShadingGouraud,
|
||||
};
|
||||
|
||||
} // namespace Tyra
|
||||
@@ -0,0 +1,28 @@
|
||||
/*
|
||||
# ______ ____ ___
|
||||
# | \/ ____| |___|
|
||||
# | | | \ | |
|
||||
#-----------------------------------------------------------------------
|
||||
# Copyright 2022, tyra - https://github.com/h4570/tyra
|
||||
# Licenced under Apache License 2.0
|
||||
# Sandro Sobczyński <sandro.sobczynski@gmail.com>
|
||||
*/
|
||||
|
||||
#pragma once
|
||||
|
||||
#include "./pipeline/renderer_3d_pipeline.hpp"
|
||||
|
||||
namespace Tyra {
|
||||
|
||||
class Renderer3D {
|
||||
public:
|
||||
Renderer3D();
|
||||
~Renderer3D();
|
||||
|
||||
void usePipeline(Renderer3DPipeline* pipeline);
|
||||
|
||||
private:
|
||||
Renderer3DPipeline* currentPipeline;
|
||||
};
|
||||
|
||||
} // namespace Tyra
|
||||
@@ -0,0 +1,44 @@
|
||||
/*
|
||||
# ______ ____ ___
|
||||
# | \/ ____| |___|
|
||||
# | | | \ | |
|
||||
#-----------------------------------------------------------------------
|
||||
# Copyright 2022, tyra - https://github.com/h4570/tyra
|
||||
# Licenced under Apache License 2.0
|
||||
# Sandro Sobczyński <sandro.sobczynski@gmail.com>
|
||||
*/
|
||||
|
||||
#pragma once
|
||||
|
||||
#include "debug/debug.hpp"
|
||||
#include "renderer/core/2d/sprite/sprite.hpp"
|
||||
#include "renderer/core/texture/renderer_core_texture_buffers.hpp"
|
||||
#include "renderer/core/texture/models/texture.hpp"
|
||||
#include "renderer/renderer_settings.hpp"
|
||||
#include <packet2_utils.h>
|
||||
#include <draw2d.h>
|
||||
|
||||
namespace Tyra {
|
||||
|
||||
class RendererCore2D {
|
||||
public:
|
||||
RendererCore2D();
|
||||
~RendererCore2D();
|
||||
|
||||
void init(RendererSettings* settings, clutbuffer_t* clutBuffer);
|
||||
|
||||
void render(Sprite* sprite, const RendererCoreTextureBuffers& texBuffers,
|
||||
Texture* texture);
|
||||
|
||||
private:
|
||||
static const float GS_CENTER;
|
||||
static const float SCREEN_CENTER;
|
||||
|
||||
u8 context;
|
||||
RendererSettings* settings;
|
||||
clutbuffer_t* clutBuffer;
|
||||
packet2_t* packets[2];
|
||||
texrect_t* rects[2];
|
||||
};
|
||||
|
||||
} // namespace Tyra
|
||||
@@ -0,0 +1,71 @@
|
||||
/*
|
||||
# ______ ____ ___
|
||||
# | \/ ____| |___|
|
||||
# | | | \ | |
|
||||
#-----------------------------------------------------------------------
|
||||
# Copyright 2022, tyra - https://github.com/h4570/tyra
|
||||
# Licenced under Apache License 2.0
|
||||
# Sandro Sobczyński <sandro.sobczynski@gmail.com>
|
||||
*/
|
||||
|
||||
#pragma once
|
||||
|
||||
#include <draw_types.h>
|
||||
#include <draw_buffers.h>
|
||||
#include "./sprite_mode.hpp"
|
||||
#include "math/vec2.hpp"
|
||||
#include "renderer/models/color.hpp"
|
||||
|
||||
namespace Tyra {
|
||||
|
||||
class Sprite {
|
||||
public:
|
||||
Sprite();
|
||||
~Sprite();
|
||||
|
||||
Vec2 position, size;
|
||||
float scale;
|
||||
Color color;
|
||||
|
||||
// ----
|
||||
// Getters
|
||||
// ----
|
||||
|
||||
/** Auto generated unique Id. */
|
||||
inline const u32& getId() const { return id; };
|
||||
|
||||
/** Get sprite drawing mode. */
|
||||
inline const SpriteMode& getMode() const { return mode; };
|
||||
|
||||
// ----
|
||||
// Setters
|
||||
// ----
|
||||
|
||||
/** Set sprite drawing mode. */
|
||||
void setMode(const SpriteMode& t_val) { mode = t_val; }
|
||||
|
||||
// ----
|
||||
// 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;
|
||||
SpriteMode mode;
|
||||
u8 _isSizeSet, _flipH, _flipV;
|
||||
void setDefaultColor();
|
||||
void setDefaultLODAndClut();
|
||||
};
|
||||
|
||||
} // namespace Tyra
|
||||
@@ -0,0 +1,17 @@
|
||||
/*
|
||||
# ______ ____ ___
|
||||
# | \/ ____| |___|
|
||||
# | | | \ | |
|
||||
#-----------------------------------------------------------------------
|
||||
# Copyright 2022, tyra - https://github.com/h4570/tyra
|
||||
# Licenced under Apache License 2.0
|
||||
# Sandro Sobczyński <sandro.sobczynski@gmail.com>
|
||||
*/
|
||||
|
||||
#pragma once
|
||||
|
||||
namespace Tyra {
|
||||
|
||||
enum SpriteMode { MODE_STRETCH, MODE_REPEAT };
|
||||
|
||||
}
|
||||
@@ -0,0 +1,43 @@
|
||||
/*
|
||||
# ______ ____ ___
|
||||
# | \/ ____| |___|
|
||||
# | | | \ | |
|
||||
#-----------------------------------------------------------------------
|
||||
# Copyright 2022, tyra - https://github.com/h4570/tyra
|
||||
# Licenced under Apache License 2.0
|
||||
# Sandro Sobczyński <sandro.sobczynski@gmail.com>
|
||||
*/
|
||||
|
||||
#pragma once
|
||||
|
||||
#include <vector>
|
||||
#include "./core_bbox_frustum.hpp"
|
||||
#include "math/m4x4.hpp"
|
||||
#include "math/plane.hpp"
|
||||
|
||||
namespace Tyra {
|
||||
|
||||
/** Bounding box */
|
||||
class CoreBBox {
|
||||
public:
|
||||
explicit CoreBBox(Vec4* t_vertices, u32* faces, u32 t_count);
|
||||
explicit CoreBBox(Vec4* t_vertices, u32 t_count);
|
||||
explicit CoreBBox(Vec4* t_vertices);
|
||||
explicit CoreBBox(CoreBBox** t_bboxes, const u32& count);
|
||||
explicit CoreBBox(const std::vector<CoreBBox>& t_bboxes,
|
||||
const u32& startIndex, const u32& stopIndex);
|
||||
|
||||
const Vec4& operator[](const u8& i) { return _vertices[i]; }
|
||||
const Vec4& getVertex(const u8& i) { return _vertices[i]; }
|
||||
Vec4* getVertices() { return _vertices; }
|
||||
|
||||
void print() const;
|
||||
void print(const char* name) const;
|
||||
void print(const std::string& name) const { print(name.c_str()); }
|
||||
std::string getPrint(const char* name = nullptr) const;
|
||||
|
||||
protected:
|
||||
Vec4 _vertices[8];
|
||||
};
|
||||
|
||||
} // namespace Tyra
|
||||
@@ -0,0 +1,17 @@
|
||||
/*
|
||||
# ______ ____ ___
|
||||
# | \/ ____| |___|
|
||||
# | | | \ | |
|
||||
#-----------------------------------------------------------------------
|
||||
# Copyright 2022, tyra - https://github.com/h4570/tyra
|
||||
# Licenced under Apache License 2.0
|
||||
# Sandro Sobczyński <sandro.sobczynski@gmail.com>
|
||||
*/
|
||||
|
||||
#pragma once
|
||||
|
||||
namespace Tyra {
|
||||
|
||||
enum CoreBBoxFrustum { IN_FRUSTUM, OUTSIDE_FRUSTUM, PARTIALLY_IN_FRUSTUM };
|
||||
|
||||
} // namespace Tyra
|
||||
@@ -0,0 +1,35 @@
|
||||
/*
|
||||
# ______ ____ ___
|
||||
# | \/ ____| |___|
|
||||
# | | | \ | |
|
||||
#-----------------------------------------------------------------------
|
||||
# Copyright 2022, tyra - https://github.com/h4570/tyra
|
||||
# Licenced under Apache License 2.0
|
||||
# Sandro Sobczyński <sandro.sobczynski@gmail.com>
|
||||
*/
|
||||
|
||||
#pragma once
|
||||
|
||||
#include <vector>
|
||||
#include "./core_bbox.hpp"
|
||||
|
||||
namespace Tyra {
|
||||
|
||||
/** Bounding box */
|
||||
class RenderBBox : public CoreBBox {
|
||||
public:
|
||||
explicit RenderBBox(Vec4* t_vertices, u32* faces, u32 t_count);
|
||||
explicit RenderBBox(Vec4* t_vertices, u32 t_count);
|
||||
explicit RenderBBox(Vec4* t_vertices);
|
||||
explicit RenderBBox(CoreBBox** t_bboxes, const u32& count);
|
||||
explicit RenderBBox(const std::vector<CoreBBox>& t_bboxes,
|
||||
const u32& startIndex, const u32& stopIndex);
|
||||
|
||||
CoreBBoxFrustum isInFrustum(const Plane* frustumPlanes, const M4x4& model,
|
||||
const float* margins = nullptr) const;
|
||||
|
||||
CoreBBoxFrustum clipIsInFrustum(const Plane* frustumPlanes,
|
||||
const M4x4& model) const;
|
||||
};
|
||||
|
||||
} // namespace Tyra
|
||||
@@ -0,0 +1,29 @@
|
||||
/*
|
||||
# ______ ____ ___
|
||||
# | \/ ____| |___|
|
||||
# | | | \ | |
|
||||
#-----------------------------------------------------------------------
|
||||
# Copyright 2022, tyra - https://github.com/h4570/tyra
|
||||
# Licenced under Apache License 2.0
|
||||
# Sandro Sobczyński <sandro.sobczynski@gmail.com>
|
||||
*/
|
||||
|
||||
#pragma once
|
||||
|
||||
#include "math/vec4.hpp"
|
||||
|
||||
namespace Tyra {
|
||||
|
||||
class CameraInfo3D {
|
||||
public:
|
||||
CameraInfo3D(Vec4* cameraPosition, Vec4* cameraLooksAt,
|
||||
Vec4* cameraUp = nullptr);
|
||||
~CameraInfo3D();
|
||||
|
||||
Vec4 *position, *looksAt, *up;
|
||||
|
||||
private:
|
||||
static Vec4 defaultCameraUp;
|
||||
};
|
||||
|
||||
} // namespace Tyra
|
||||
@@ -0,0 +1,45 @@
|
||||
/*
|
||||
# ______ ____ ___
|
||||
# | \/ ____| |___|
|
||||
# | | | \ | |
|
||||
#-----------------------------------------------------------------------
|
||||
# Copyright 2022, tyra - https://github.com/h4570/tyra
|
||||
# Licenced under Apache License 2.0
|
||||
# Sandro Sobczyński <sandro.sobczynski@gmail.com>
|
||||
*/
|
||||
|
||||
#pragma once
|
||||
|
||||
#include <sstream>
|
||||
#include "renderer/renderer_settings.hpp"
|
||||
#include "./camera_info_3d.hpp"
|
||||
#include "math/plane.hpp"
|
||||
|
||||
namespace Tyra {
|
||||
|
||||
class Renderer3DFrustumPlanes {
|
||||
public:
|
||||
Renderer3DFrustumPlanes();
|
||||
~Renderer3DFrustumPlanes();
|
||||
|
||||
void init(RendererSettings* settings, const float& fov);
|
||||
void update(const CameraInfo3D& cameraInfo, const float& fov);
|
||||
const Plane& get(u8 index) const { return frustumPlanes[index]; }
|
||||
const Plane* getAll() const { return frustumPlanes; }
|
||||
const Plane& operator[](u8 index) const { return frustumPlanes[index]; }
|
||||
|
||||
void print() const;
|
||||
void print(const char* name) const;
|
||||
void print(const std::string& name) const { print(name.c_str()); }
|
||||
std::string getPrint(const char* name = nullptr) const;
|
||||
|
||||
private:
|
||||
void computeStaticData(const float& fov);
|
||||
float lastFov;
|
||||
RendererSettings* settings;
|
||||
Plane frustumPlanes[6];
|
||||
float nearHeight, nearWidth, farHeight, farWidth;
|
||||
Vec4 nearCenter, farCenter, X, Y, Z, ntl, ntr, nbl, nbr, ftl, fbr, ftr, fbl;
|
||||
};
|
||||
|
||||
} // namespace Tyra
|
||||
@@ -0,0 +1,90 @@
|
||||
/*
|
||||
# ______ ____ ___
|
||||
# | \/ ____| |___|
|
||||
# | | | \ | |
|
||||
#-----------------------------------------------------------------------
|
||||
# Copyright 2022, tyra - https://github.com/h4570/tyra
|
||||
# Licenced under Apache License 2.0
|
||||
# Sandro Sobczyński <sandro.sobczynski@gmail.com>
|
||||
*/
|
||||
|
||||
#pragma once
|
||||
|
||||
#include <algorithm>
|
||||
#include "renderer/renderer_settings.hpp"
|
||||
#include "./renderer_3d_frustum_planes.hpp"
|
||||
#include "./camera_info_3d.hpp"
|
||||
#include "renderer/core/texture/models/texture.hpp"
|
||||
#include "renderer/core/3d/bbox/core_bbox.hpp"
|
||||
#include "renderer/core/paths/path1/path1.hpp"
|
||||
|
||||
namespace Tyra {
|
||||
|
||||
class RendererCore3D {
|
||||
public:
|
||||
RendererCore3D();
|
||||
~RendererCore3D();
|
||||
|
||||
/** Current camera frustum planes. */
|
||||
Renderer3DFrustumPlanes frustumPlanes;
|
||||
|
||||
/** Called by renderer. */
|
||||
void init(RendererSettings* settings, Path1* t_path1);
|
||||
|
||||
const float& getFov() const { return fov; }
|
||||
|
||||
void setFov(const float& t_fov);
|
||||
|
||||
/**
|
||||
* Called by beginFrame();
|
||||
* Updates camera info, to get proper frustum culling.
|
||||
*/
|
||||
void update(const CameraInfo3D& cameraInfo);
|
||||
|
||||
/** Get projection (screen) matrix */
|
||||
const M4x4& getProjection() { return projection; }
|
||||
|
||||
/**
|
||||
* Get view (camera) matrix
|
||||
* Updated at every beginFrame()
|
||||
*/
|
||||
const M4x4& getView() { return view; }
|
||||
|
||||
/**
|
||||
* Get projection * view matrix
|
||||
* Updated at every beginFrame()
|
||||
*/
|
||||
const M4x4& getViewProj() { return viewProj; }
|
||||
|
||||
/**
|
||||
* @brief
|
||||
* Upload VU1 program.
|
||||
* Please pay attention that you will be REPLACING
|
||||
* current VU1 programs
|
||||
*
|
||||
* @param address Starting address of your program.
|
||||
* @return Address of the end of your program, so next program can start from
|
||||
* this + 1
|
||||
*/
|
||||
u32 uploadVU1Program(VU1Program* program, const u32& address);
|
||||
|
||||
/**
|
||||
* @brief Set VU1 double buffer
|
||||
*
|
||||
* @param startingAddress Starting address. Example 10.
|
||||
* @param bufferSize Buffer size. Example 490, so second buffer will start
|
||||
* from 490+10
|
||||
*/
|
||||
void setVU1DoubleBuffers(const u16& startingAddress, const u16& bufferSize);
|
||||
|
||||
private:
|
||||
M4x4 view, projection, viewProj;
|
||||
float fov;
|
||||
|
||||
RendererSettings* settings;
|
||||
|
||||
Path1* path1;
|
||||
void setProjection();
|
||||
};
|
||||
|
||||
} // namespace Tyra
|
||||
@@ -0,0 +1,51 @@
|
||||
/*
|
||||
# ______ ____ ___
|
||||
# | \/ ____| |___|
|
||||
# | | | \ | |
|
||||
#-----------------------------------------------------------------------
|
||||
# Copyright 2022, tyra - https://github.com/h4570/tyra
|
||||
# Licenced under Apache License 2.0
|
||||
# Sandro Sobczyński <sandro.sobczynski@gmail.com>
|
||||
*/
|
||||
|
||||
#pragma once
|
||||
|
||||
#include "renderer/renderer_settings.hpp"
|
||||
|
||||
namespace Tyra {
|
||||
|
||||
class RendererCoreGS {
|
||||
public:
|
||||
RendererCoreGS();
|
||||
~RendererCoreGS();
|
||||
|
||||
prim_t prim;
|
||||
lod_t lod;
|
||||
zbuffer_t zBuffer;
|
||||
|
||||
void init(RendererSettings* settings);
|
||||
|
||||
void flipBuffers();
|
||||
|
||||
float getVRamFreeSpaceInMB() const {
|
||||
return 4.0F - spaceOccupiedByFrameBuffers - spaceOccupiedByZBuffer;
|
||||
}
|
||||
|
||||
private:
|
||||
constexpr static float gsCenter = 4096.0F;
|
||||
constexpr static float screenCenter = gsCenter / 2.0F;
|
||||
|
||||
float spaceOccupiedByFrameBuffers, spaceOccupiedByZBuffer;
|
||||
RendererSettings* settings;
|
||||
framebuffer_t frameBuffers[2];
|
||||
packet2_t* flipPacket;
|
||||
u8 context;
|
||||
|
||||
void allocateBuffers();
|
||||
void initDrawingEnvironment();
|
||||
void setPrim();
|
||||
void setLod();
|
||||
void initChannels();
|
||||
};
|
||||
|
||||
} // namespace Tyra
|
||||
@@ -0,0 +1,21 @@
|
||||
/*
|
||||
# ______ ____ ___
|
||||
# | \/ ____| |___|
|
||||
# | | | \ | |
|
||||
#-----------------------------------------------------------------------
|
||||
# Copyright 2022, tyra - https://github.com/h4570/tyra
|
||||
# Licenced under Apache License 2.0
|
||||
# Sandro Sobczyński <sandro.sobczynski@gmail.com>
|
||||
*/
|
||||
|
||||
#pragma once
|
||||
|
||||
#include "math/vec4.hpp"
|
||||
|
||||
namespace Tyra {
|
||||
|
||||
struct Path1ClipVertex {
|
||||
Vec4 position, normal, st, color;
|
||||
};
|
||||
|
||||
} // namespace Tyra
|
||||
@@ -0,0 +1,52 @@
|
||||
/*
|
||||
# ______ ____ ___
|
||||
# | \/ ____| |___|
|
||||
# | | | \ | |
|
||||
#-----------------------------------------------------------------------
|
||||
# Copyright 2022, tyra - https://github.com/h4570/tyra
|
||||
# Licenced under Apache License 2.0
|
||||
# Sandro Sobczyński <sandro.sobczynski@gmail.com>
|
||||
*/
|
||||
|
||||
#pragma once
|
||||
|
||||
#include <vector>
|
||||
#include "./path1_clip_vertex.hpp"
|
||||
#include "debug/debug.hpp"
|
||||
#include "renderer/renderer_settings.hpp"
|
||||
|
||||
namespace Tyra {
|
||||
|
||||
struct Path1EEClipAlgorithmSettings {
|
||||
bool lerpNormals, lerpTexCoords, lerpColors;
|
||||
};
|
||||
|
||||
class Path1EEClipAlgorithm {
|
||||
public:
|
||||
Path1EEClipAlgorithm();
|
||||
~Path1EEClipAlgorithm();
|
||||
|
||||
void init(const RendererSettings& settings);
|
||||
|
||||
void clip(std::vector<Path1ClipVertex>* o_vertices,
|
||||
const std::vector<Path1ClipVertex>& vertices,
|
||||
const Path1EEClipAlgorithmSettings& settings);
|
||||
|
||||
static float clipMargin;
|
||||
|
||||
private:
|
||||
float halfWidth, halfHeight, near, far;
|
||||
std::vector<Path1ClipVertex> tempVertices;
|
||||
|
||||
float getValueByPlane(const Path1ClipVertex& v, const int& plane);
|
||||
|
||||
bool isInside(const int& plane, const float& v, const float& w,
|
||||
const float& planeLimitValue);
|
||||
|
||||
void clipAgainstPlane(const std::vector<Path1ClipVertex>& original,
|
||||
std::vector<Path1ClipVertex>* clipped, const int& plane,
|
||||
const float& planeLimitValue,
|
||||
const Path1EEClipAlgorithmSettings& settings);
|
||||
};
|
||||
|
||||
} // namespace Tyra
|
||||
@@ -0,0 +1,36 @@
|
||||
/*
|
||||
# ______ ____ ___
|
||||
# | \/ ____| |___|
|
||||
# | | | \ | |
|
||||
#-----------------------------------------------------------------------
|
||||
# Copyright 2022, tyra - https://github.com/h4570/tyra
|
||||
# Licenced under Apache License 2.0
|
||||
# Sandro Sobczyński <sandro.sobczynski@gmail.com>
|
||||
*/
|
||||
|
||||
#pragma once
|
||||
|
||||
#include <dma.h>
|
||||
#include <packet2_utils.h>
|
||||
#include "debug/debug.hpp"
|
||||
#include "./vu1_program.hpp"
|
||||
|
||||
namespace Tyra {
|
||||
|
||||
class Path1 {
|
||||
public:
|
||||
Path1();
|
||||
~Path1();
|
||||
|
||||
u32 uploadProgram(VU1Program* program, const u32& address);
|
||||
|
||||
packet2_t* createProgramsCache(VU1Program** programs, const u32& count,
|
||||
const u32& address);
|
||||
|
||||
void setDoubleBuffer(const u16& startingAddress, const u16& bufferSize);
|
||||
|
||||
private:
|
||||
packet2_t* doubleBufferPacket;
|
||||
};
|
||||
|
||||
} // namespace Tyra
|
||||
@@ -0,0 +1,28 @@
|
||||
/*
|
||||
# ______ ____ ___
|
||||
# | \/ ____| |___|
|
||||
# | | | \ | |
|
||||
#-----------------------------------------------------------------------
|
||||
# Copyright 2022, tyra - https://github.com/h4570/tyra
|
||||
# Licenced under Apache License 2.0
|
||||
# Sandro Sobczyński <sandro.sobczynski@gmail.com>
|
||||
*/
|
||||
|
||||
#pragma once
|
||||
|
||||
#include <packet2_utils.h>
|
||||
#include <string>
|
||||
#include "../../vu1_program.hpp"
|
||||
|
||||
namespace Tyra {
|
||||
|
||||
class VU1DrawFinish : public VU1Program {
|
||||
public:
|
||||
VU1DrawFinish();
|
||||
~VU1DrawFinish();
|
||||
|
||||
std::string getStringName() const;
|
||||
void addTag(packet2_t* packet, prim_t* prim) const;
|
||||
};
|
||||
|
||||
} // namespace Tyra
|
||||
@@ -0,0 +1,41 @@
|
||||
/*
|
||||
# ______ ____ ___
|
||||
# | \/ ____| |___|
|
||||
# | | | \ | |
|
||||
#-----------------------------------------------------------------------
|
||||
# Copyright 2022, tyra - https://github.com/h4570/tyra
|
||||
# Licenced under Apache License 2.0
|
||||
# Sandro Sobczyński <sandro.sobczynski@gmail.com>
|
||||
*/
|
||||
|
||||
#pragma once
|
||||
|
||||
#include <tamtypes.h>
|
||||
#include <packet2_utils.h>
|
||||
#include <string>
|
||||
|
||||
namespace Tyra {
|
||||
|
||||
class VU1Program {
|
||||
public:
|
||||
VU1Program(u32* start, u32* end);
|
||||
~VU1Program();
|
||||
|
||||
const u32& getPacketSize() const;
|
||||
const u32& getProgramSize() const;
|
||||
const u32& getDestinationAddress() const;
|
||||
|
||||
u32* getStart() const;
|
||||
u32* getEnd() const;
|
||||
|
||||
virtual std::string getStringName() const = 0;
|
||||
|
||||
void setDestinationAddress(const u32& addr);
|
||||
|
||||
protected:
|
||||
u32 packetSize, destinationAddress, programSize;
|
||||
u32 *start, *end;
|
||||
u32 calculateProgramSize() const;
|
||||
};
|
||||
|
||||
} // namespace Tyra
|
||||
@@ -0,0 +1,42 @@
|
||||
/*
|
||||
# ______ ____ ___
|
||||
# | \/ ____| |___|
|
||||
# | | | \ | |
|
||||
#-----------------------------------------------------------------------
|
||||
# Copyright 2022, tyra - https://github.com/h4570/tyra
|
||||
# Licenced under Apache License 2.0
|
||||
# Sandro Sobczyński <sandro.sobczynski@gmail.com>
|
||||
*/
|
||||
|
||||
#pragma once
|
||||
|
||||
#include <dma.h>
|
||||
#include <packet2_chain.h>
|
||||
#include <draw.h>
|
||||
#include "renderer/core/texture/models/texture.hpp"
|
||||
#include "renderer/renderer_settings.hpp"
|
||||
#include "renderer/models/color.hpp"
|
||||
#include "renderer/core/texture/renderer_core_texture_buffers.hpp"
|
||||
|
||||
namespace Tyra {
|
||||
|
||||
class Path3 {
|
||||
public:
|
||||
Path3();
|
||||
~Path3();
|
||||
|
||||
void init(RendererSettings* settings);
|
||||
|
||||
void addDrawFinishTag();
|
||||
void clearScreen(zbuffer_t* z, const Color& color);
|
||||
void sendTexture(Texture* texture,
|
||||
const RendererCoreTextureBuffers& texBuffers);
|
||||
|
||||
private:
|
||||
packet2_t* drawFinishPacket;
|
||||
packet2_t* clearScreenPacket;
|
||||
packet2_t* texturePacket;
|
||||
RendererSettings* settings;
|
||||
};
|
||||
|
||||
} // namespace Tyra
|
||||
@@ -0,0 +1,73 @@
|
||||
/*
|
||||
# ______ ____ ___
|
||||
# | \/ ____| |___|
|
||||
# | | | \ | |
|
||||
#-----------------------------------------------------------------------
|
||||
# Copyright 2022, tyra - https://github.com/h4570/tyra
|
||||
# Licenced under Apache License 2.0
|
||||
# Sandro Sobczyński <sandro.sobczynski@gmail.com>
|
||||
*/
|
||||
|
||||
#pragma once
|
||||
|
||||
#include <tamtypes.h>
|
||||
#include "./2d/renderer_core_2d.hpp"
|
||||
#include "./3d/renderer_core_3d.hpp"
|
||||
#include "./gs/renderer_core_gs.hpp"
|
||||
#include "./texture/renderer_core_texture.hpp"
|
||||
#include "./paths/path3/path3.hpp"
|
||||
#include "./paths/path1/path1.hpp"
|
||||
#include "./renderer_core_sync.hpp"
|
||||
|
||||
namespace Tyra {
|
||||
|
||||
class RendererCore {
|
||||
public:
|
||||
RendererCore();
|
||||
~RendererCore();
|
||||
|
||||
/** Responsible for initializing GS. */
|
||||
RendererCoreGS gs;
|
||||
|
||||
/** All logic responsible for 3D drawing. */
|
||||
RendererCore3D renderer3D;
|
||||
|
||||
/** All logic responsible for 2D drawing. */
|
||||
RendererCore2D renderer2D;
|
||||
|
||||
/** Texture transferring. */
|
||||
RendererCoreTexture texture;
|
||||
|
||||
/** EE <-> VU1 synchronization */
|
||||
RendererCoreSync sync;
|
||||
|
||||
/** Called by renderer */
|
||||
void init();
|
||||
|
||||
/** World background color */
|
||||
void setClearScreenColor(const Color& color);
|
||||
|
||||
/** Clear screen and update view frustum for frustum culling. */
|
||||
void beginFrame(const CameraInfo3D& cameraInfo);
|
||||
|
||||
/** VSync and swap frame double buffer. */
|
||||
void endFrame();
|
||||
|
||||
void setFrameLimit(const bool& onoff) { isFrameLimitOn = onoff; }
|
||||
|
||||
/** Get screen settings */
|
||||
const RendererSettings& getSettings() const { return settings; }
|
||||
|
||||
Path1* getPath1() { return &path1; }
|
||||
|
||||
Path3* getPath3() { return &path3; }
|
||||
|
||||
private:
|
||||
bool isFrameLimitOn;
|
||||
Color bgColor;
|
||||
RendererSettings settings;
|
||||
Path3 path3;
|
||||
Path1 path1;
|
||||
};
|
||||
|
||||
} // namespace Tyra
|
||||
@@ -0,0 +1,50 @@
|
||||
/*
|
||||
# ______ ____ ___
|
||||
# | \/ ____| |___|
|
||||
# | | | \ | |
|
||||
#-----------------------------------------------------------------------
|
||||
# Copyright 2022, tyra - https://github.com/h4570/tyra
|
||||
# Licenced under Apache License 2.0
|
||||
# Sandro Sobczyński <sandro.sobczynski@gmail.com>
|
||||
*/
|
||||
|
||||
#pragma once
|
||||
|
||||
#include <draw.h>
|
||||
#include <gs_privileged.h>
|
||||
#include "./paths/path3/path3.hpp"
|
||||
|
||||
namespace Tyra {
|
||||
|
||||
/**
|
||||
* Synchronization class.
|
||||
* Mainly between VU1 and EE.
|
||||
*
|
||||
* For example you can set texture, render X vertices, then add() wait, and
|
||||
* wait() for it. Without it, there is risk for example to send new texture
|
||||
* during drawing with previous one.
|
||||
*/
|
||||
class RendererCoreSync {
|
||||
public:
|
||||
RendererCoreSync();
|
||||
~RendererCoreSync();
|
||||
|
||||
void init(Path3* path3);
|
||||
|
||||
/** Send draw finish tag via VU1 to GS. */
|
||||
void add();
|
||||
/** Check if finish flag was set by GS. */
|
||||
u8 check();
|
||||
/** Clear finish tag flag. */
|
||||
void clear();
|
||||
/** Wait for finish flag and clear it. */
|
||||
void waitAndClear();
|
||||
|
||||
/** Clear() -> Add() -> waitAndClear() */
|
||||
void align();
|
||||
|
||||
private:
|
||||
Path3* path3;
|
||||
};
|
||||
|
||||
} // namespace Tyra
|
||||
@@ -0,0 +1,48 @@
|
||||
/*
|
||||
# ______ ____ ___
|
||||
# | \/ ____| |___|
|
||||
# | | | \ | |
|
||||
#-----------------------------------------------------------------------
|
||||
# Copyright 2022, tyra - https://github.com/h4570/tyra
|
||||
# Licenced under Apache License 2.0
|
||||
# Sandro Sobczyński <sandro.sobczynski@gmail.com>
|
||||
*/
|
||||
|
||||
#pragma once
|
||||
|
||||
#include <tamtypes.h>
|
||||
#include <draw_buffers.h>
|
||||
#include <vector>
|
||||
#include "renderer/core/texture/models/texture.hpp"
|
||||
#include "./renderer_texture_cm_analysis.hpp"
|
||||
#include "../renderer_core_texture_buffers.hpp"
|
||||
|
||||
namespace Tyra {
|
||||
|
||||
class RendererTextureCacheManager {
|
||||
public:
|
||||
RendererTextureCacheManager();
|
||||
~RendererTextureCacheManager();
|
||||
|
||||
void onFrameChange();
|
||||
|
||||
void addRequestedTexture(Texture* texture);
|
||||
|
||||
u32 getTextureIdToDealloc(
|
||||
const std::vector<RendererCoreTextureBuffers>& currentAllocs);
|
||||
|
||||
private:
|
||||
RendererTextureCMAnalysis statistics;
|
||||
|
||||
void tryAddIdThatNotExistInAnalysis(
|
||||
std::vector<u32>* result,
|
||||
const std::vector<RendererCoreTextureBuffers>& currentAllocs,
|
||||
const std::vector<u32>& analysis);
|
||||
|
||||
void addIdThatExistInAnalysisButIsOnTheBottom(
|
||||
std::vector<u32>* result,
|
||||
const std::vector<RendererCoreTextureBuffers>& currentAllocs,
|
||||
const std::vector<u32>& analysis);
|
||||
};
|
||||
|
||||
} // namespace Tyra
|
||||
@@ -0,0 +1,73 @@
|
||||
/*
|
||||
# ______ ____ ___
|
||||
# | \/ ____| |___|
|
||||
# | | | \ | |
|
||||
#-----------------------------------------------------------------------
|
||||
# Copyright 2022, tyra - https://github.com/h4570/tyra
|
||||
# Licenced under Apache License 2.0
|
||||
# Sandro Sobczyński <sandro.sobczynski@gmail.com>
|
||||
*/
|
||||
|
||||
#pragma once
|
||||
|
||||
#include <algorithm>
|
||||
#include "debug/debug.hpp"
|
||||
#include <tamtypes.h>
|
||||
#include <vector>
|
||||
|
||||
namespace Tyra {
|
||||
|
||||
struct RendererTextureCMAnalysisWeight {
|
||||
u32 id;
|
||||
u16 weight;
|
||||
};
|
||||
|
||||
struct RendererTextureCMAnalysisOccurence {
|
||||
u32 id;
|
||||
u8 occurence;
|
||||
};
|
||||
|
||||
class RendererTextureCMAnalysis {
|
||||
public:
|
||||
RendererTextureCMAnalysis();
|
||||
~RendererTextureCMAnalysis();
|
||||
|
||||
void changeFrame();
|
||||
|
||||
void addNewRequest(const u32& id);
|
||||
|
||||
/**
|
||||
* @brief Returns top list (from most used to least used) of textures to be
|
||||
* deallocated.
|
||||
*
|
||||
* @param count Number of textures to be returned.
|
||||
*/
|
||||
std::vector<u32> getTopTextureIdsForNextChanges(const u8& count);
|
||||
|
||||
bool isReady();
|
||||
|
||||
bool isProbablyNotCorrect();
|
||||
|
||||
private:
|
||||
std::vector<u32>*current, *last;
|
||||
std::vector<u32> buffers[2];
|
||||
u32 currentIndex;
|
||||
|
||||
void flipBuffers();
|
||||
|
||||
std::vector<u32> getNextTextureIds(const u8& count);
|
||||
|
||||
std::vector<RendererTextureCMAnalysisOccurence> getOccurencesForTextureIds(
|
||||
const std::vector<u32>& textureIds);
|
||||
|
||||
std::vector<u32> getTextureIdsUnique(const std::vector<u32>& textureIds);
|
||||
|
||||
std::vector<RendererTextureCMAnalysisWeight> getWeights(
|
||||
const std::vector<u32>& uniqueTexIds,
|
||||
const std::vector<RendererTextureCMAnalysisOccurence>& occurencies);
|
||||
|
||||
std::vector<u32> weightsToResult(
|
||||
std::vector<RendererTextureCMAnalysisWeight>* weights);
|
||||
};
|
||||
|
||||
} // namespace Tyra
|
||||
Some files were not shown because too many files have changed in this diff Show More
Reference in New Issue
Block a user