tutorial 1 and 2
This commit is contained in:
@@ -17,11 +17,13 @@ Renderer2D::~Renderer2D() {}
|
||||
|
||||
void Renderer2D::init(RendererCore* t_rendererCore) { core = t_rendererCore; }
|
||||
|
||||
void Renderer2D::render(Sprite* sprite) {
|
||||
auto* texture = core->texture.repository.getBySpriteOrMesh(sprite->id);
|
||||
void Renderer2D::render(const Sprite* sprite) { render(*sprite); }
|
||||
|
||||
void Renderer2D::render(const Sprite& sprite) {
|
||||
auto* texture = core->texture.repository.getBySpriteOrMesh(sprite.id);
|
||||
|
||||
TYRA_ASSERT(
|
||||
texture, "Texture for sprite with id: ", sprite->id,
|
||||
texture, "Texture for sprite with id: ", sprite.id,
|
||||
"Was not found in texture repository! Did you forget to add texture?");
|
||||
|
||||
auto texBuffers = core->texture.useTexture(texture);
|
||||
|
||||
@@ -11,6 +11,8 @@
|
||||
#include "renderer/3d/pipeline/dynamic/core/dynpip_renderer.hpp"
|
||||
#include "renderer/3d/pipeline/dynamic/core/programs/dynpip_vu1_shared_defines.h"
|
||||
#include <dma.h>
|
||||
#include <utility>
|
||||
#include "packet2/packet2_tyra_utils.hpp"
|
||||
|
||||
namespace Tyra {
|
||||
|
||||
@@ -114,8 +116,8 @@ void DynPipRenderer::sendObjectData(
|
||||
|
||||
if (singleColorEnabled) // Color is placed in 4th slot of
|
||||
// VU1_LIGHTS_MATRIX_ADDR
|
||||
packet2_utils_vu_add_unpack_data(objectDataPacket, VU1_SINGLE_COLOR_ADDR,
|
||||
bag->color->single->rgba, 1, false);
|
||||
Packet2TyraUtils::addUnpackData(objectDataPacket, VU1_SINGLE_COLOR_ADDR,
|
||||
bag->color->single->rgba, 1, false);
|
||||
|
||||
packet2_utils_vu_open_unpack(objectDataPacket, VU1_OPTIONS_ADDR, false);
|
||||
{
|
||||
|
||||
@@ -51,7 +51,13 @@ void DynamicPipeline::onUseEnd() {
|
||||
core.deallocateOnUse();
|
||||
}
|
||||
|
||||
void DynamicPipeline::render(DynamicMesh* mesh, const DynPipOptions* options) {
|
||||
void DynamicPipeline::render(const DynamicMesh& mesh,
|
||||
const DynPipOptions* options) {
|
||||
render(&mesh, options);
|
||||
}
|
||||
|
||||
void DynamicPipeline::render(const DynamicMesh* mesh,
|
||||
const DynPipOptions* options) {
|
||||
bool optionsManuallyAllocated = false;
|
||||
|
||||
if (!options) {
|
||||
@@ -185,7 +191,7 @@ void DynamicPipeline::sendRestOfBuffers(DynPipBag* buffers, u16* bufferIndex) {
|
||||
}
|
||||
|
||||
void DynamicPipeline::setBuffersDefaultVars(DynPipBag* buffers,
|
||||
DynamicMesh* mesh,
|
||||
const DynamicMesh* mesh,
|
||||
DynPipInfoBag* infoBag) {
|
||||
for (u32 i = 0; i < buffersCount; i++) {
|
||||
buffers[i].info = infoBag;
|
||||
@@ -210,7 +216,7 @@ void DynamicPipeline::freeBuffer(DynPipBag* bag) {
|
||||
}
|
||||
}
|
||||
|
||||
DynPipInfoBag* DynamicPipeline::getInfoBag(DynamicMesh* mesh,
|
||||
DynPipInfoBag* DynamicPipeline::getInfoBag(const DynamicMesh* mesh,
|
||||
const DynPipOptions* options,
|
||||
M4x4* model) const {
|
||||
auto* result = new DynPipInfoBag();
|
||||
@@ -230,22 +236,23 @@ DynPipInfoBag* DynamicPipeline::getInfoBag(DynamicMesh* mesh,
|
||||
return result;
|
||||
}
|
||||
|
||||
void DynamicPipeline::addVertices(MeshMaterialFrame* materialFrameFrom,
|
||||
MeshMaterialFrame* materialFrameTo,
|
||||
void DynamicPipeline::addVertices(const MeshMaterialFrame* materialFrameFrom,
|
||||
const MeshMaterialFrame* materialFrameTo,
|
||||
DynPipBag* bag, const u32& startIndex) const {
|
||||
bag->verticesFrom = &materialFrameFrom->vertices[startIndex];
|
||||
bag->verticesTo = &materialFrameTo->vertices[startIndex];
|
||||
}
|
||||
|
||||
DynPipColorBag* DynamicPipeline::getColorBag(MeshMaterial* material) const {
|
||||
DynPipColorBag* DynamicPipeline::getColorBag(
|
||||
const MeshMaterial* material) const {
|
||||
auto* result = new DynPipColorBag();
|
||||
result->single = &material->ambient;
|
||||
return result;
|
||||
}
|
||||
|
||||
DynPipTextureBag* DynamicPipeline::getTextureBag(
|
||||
Texture* texture, MeshMaterialFrame* materialFrameFrom,
|
||||
MeshMaterialFrame* materialFrameTo, const u32& startIndex) {
|
||||
Texture* texture, const MeshMaterialFrame* materialFrameFrom,
|
||||
const MeshMaterialFrame* materialFrameTo, const u32& startIndex) {
|
||||
if (!materialFrameFrom->textureCoords) return nullptr;
|
||||
|
||||
auto* result = new DynPipTextureBag();
|
||||
@@ -259,9 +266,10 @@ DynPipTextureBag* DynamicPipeline::getTextureBag(
|
||||
}
|
||||
|
||||
DynPipLightingBag* DynamicPipeline::getLightingBag(
|
||||
MeshMaterialFrame* materialFrameFrom, MeshMaterialFrame* materialFrameTo,
|
||||
M4x4* model, const DynPipOptions* options,
|
||||
PipelineDirLightsBag* dirLightsBag, const u32& startIndex) const {
|
||||
const MeshMaterialFrame* materialFrameFrom,
|
||||
const MeshMaterialFrame* materialFrameTo, M4x4* model,
|
||||
const DynPipOptions* options, PipelineDirLightsBag* dirLightsBag,
|
||||
const u32& startIndex) const {
|
||||
if (!materialFrameFrom->normals || options == nullptr ||
|
||||
options->lighting == nullptr)
|
||||
return nullptr;
|
||||
|
||||
@@ -43,7 +43,8 @@ StaPipBagPackage* StaPipBagPackager::create(u16* o_size, StaPipBag* data,
|
||||
if (data->texture) result[i].sts = &data->texture->coordinates[i * size];
|
||||
|
||||
if (data->color->many)
|
||||
result[i].colors = reinterpret_cast<Vec4*>(&data->color->many[i * size]);
|
||||
result[i].colors =
|
||||
reinterpret_cast<const Vec4*>(&data->color->many[i * size]);
|
||||
|
||||
if (data->lighting) result[i].normals = &data->lighting->normals[i * size];
|
||||
|
||||
|
||||
@@ -37,10 +37,12 @@ void StaPipQBuffer::fillByPointer(const StaPipBagPackage& pkg) {
|
||||
|
||||
deallocateDynamicData();
|
||||
|
||||
vertices = pkg.vertices;
|
||||
sts = pkg.sts;
|
||||
colors = pkg.colors;
|
||||
normals = pkg.normals;
|
||||
// Too bad, but in reality const is not violated.
|
||||
// This class needs refactor
|
||||
vertices = const_cast<Vec4*>(pkg.vertices);
|
||||
sts = const_cast<Vec4*>(pkg.sts);
|
||||
colors = const_cast<Vec4*>(pkg.colors);
|
||||
normals = const_cast<Vec4*>(pkg.normals);
|
||||
size = pkg.size;
|
||||
bag = pkg.bag;
|
||||
}
|
||||
|
||||
@@ -10,6 +10,7 @@
|
||||
|
||||
#include "renderer/3d/pipeline/static/core/stapip_qbuffer_renderer.hpp"
|
||||
#include "renderer/3d/pipeline/static/core/programs/stapip_vu1_shared_defines.h"
|
||||
#include "packet2/packet2_tyra_utils.hpp"
|
||||
|
||||
// #define TYRA_QBUFF_RENDERER_VERBOSE_LOG 1
|
||||
|
||||
@@ -135,8 +136,8 @@ void StaPipQBufferRenderer::sendObjectData(
|
||||
|
||||
if (singleColorEnabled) // Color is placed in 4th slot of
|
||||
// VU1_LIGHTS_MATRIX_ADDR
|
||||
packet2_utils_vu_add_unpack_data(objectDataPacket, VU1_SINGLE_COLOR_ADDR,
|
||||
bag->color->single->rgba, 1, false);
|
||||
Packet2TyraUtils::addUnpackData(objectDataPacket, VU1_SINGLE_COLOR_ADDR,
|
||||
bag->color->single->rgba, 1, false);
|
||||
|
||||
packet2_utils_vu_open_unpack(objectDataPacket, VU1_OPTIONS_ADDR, false);
|
||||
{
|
||||
|
||||
@@ -39,7 +39,13 @@ void StaticPipeline::onUseEnd() {
|
||||
core.deallocateOnUse();
|
||||
}
|
||||
|
||||
void StaticPipeline::render(StaticMesh* mesh, const StaPipOptions* options) {
|
||||
void StaticPipeline::render(const StaticMesh& mesh,
|
||||
const StaPipOptions* options) {
|
||||
render(&mesh, options);
|
||||
}
|
||||
|
||||
void StaticPipeline::render(const StaticMesh* mesh,
|
||||
const StaPipOptions* options) {
|
||||
bool optionsManuallyAllocated = false;
|
||||
|
||||
if (!options) {
|
||||
@@ -89,13 +95,13 @@ void StaticPipeline::render(StaticMesh* mesh, const StaPipOptions* options) {
|
||||
if (optionsManuallyAllocated) delete options;
|
||||
}
|
||||
|
||||
void StaticPipeline::addVertices(MeshMaterialFrame* materialFrame,
|
||||
void StaticPipeline::addVertices(const MeshMaterialFrame* materialFrame,
|
||||
StaPipBag* bag) const {
|
||||
bag->count = materialFrame->count;
|
||||
bag->vertices = materialFrame->vertices;
|
||||
}
|
||||
|
||||
StaPipInfoBag* StaticPipeline::getInfoBag(StaticMesh* mesh,
|
||||
StaPipInfoBag* StaticPipeline::getInfoBag(const StaticMesh* mesh,
|
||||
const StaPipOptions* options,
|
||||
M4x4* model) const {
|
||||
auto* result = new StaPipInfoBag();
|
||||
@@ -117,7 +123,8 @@ StaPipInfoBag* StaticPipeline::getInfoBag(StaticMesh* mesh,
|
||||
}
|
||||
|
||||
StaPipColorBag* StaticPipeline::getColorBag(
|
||||
MeshMaterial* material, MeshMaterialFrame* materialFrame) const {
|
||||
const MeshMaterial* material,
|
||||
const MeshMaterialFrame* materialFrame) const {
|
||||
auto* result = new StaPipColorBag();
|
||||
|
||||
if (material->lightmapFlag) {
|
||||
@@ -130,7 +137,7 @@ StaPipColorBag* StaticPipeline::getColorBag(
|
||||
}
|
||||
|
||||
StaPipTextureBag* StaticPipeline::getTextureBag(
|
||||
MeshMaterial* material, MeshMaterialFrame* materialFrame) {
|
||||
const MeshMaterial* material, const MeshMaterialFrame* materialFrame) {
|
||||
if (!materialFrame->textureCoords) return nullptr;
|
||||
|
||||
auto* result = new StaPipTextureBag();
|
||||
@@ -149,7 +156,7 @@ StaPipTextureBag* StaticPipeline::getTextureBag(
|
||||
}
|
||||
|
||||
StaPipLightingBag* StaticPipeline::getLightingBag(
|
||||
MeshMaterialFrame* materialFrame, M4x4* model,
|
||||
const MeshMaterialFrame* materialFrame, M4x4* model,
|
||||
const StaPipOptions* options) const {
|
||||
if (!materialFrame->normals || options == nullptr ||
|
||||
options->lighting == nullptr)
|
||||
@@ -181,7 +188,7 @@ void StaticPipeline::setLightingColorsCache(
|
||||
}
|
||||
|
||||
void StaticPipeline::deallocDrawBags(StaPipBag* bag,
|
||||
MeshMaterial* material) const {
|
||||
const MeshMaterial* material) const {
|
||||
if (bag->texture) {
|
||||
delete bag->texture;
|
||||
}
|
||||
|
||||
@@ -62,15 +62,15 @@ void RendererCore2D::init(RendererSettings* t_settings,
|
||||
clutBuffer = t_clutBuffer;
|
||||
}
|
||||
|
||||
void RendererCore2D::render(Sprite* sprite,
|
||||
void RendererCore2D::render(const Sprite& sprite,
|
||||
const RendererCoreTextureBuffers& texBuffers,
|
||||
Texture* texture) {
|
||||
auto* rect = rects[context];
|
||||
float sizeX, sizeY;
|
||||
|
||||
if (sprite->mode == MODE_REPEAT) {
|
||||
sizeX = sprite->size.x;
|
||||
sizeY = sprite->size.y;
|
||||
if (sprite.mode == MODE_REPEAT) {
|
||||
sizeX = sprite.size.x;
|
||||
sizeY = sprite.size.y;
|
||||
} else {
|
||||
sizeX = static_cast<float>(texture->getWidth());
|
||||
sizeY = static_cast<float>(texture->getHeight());
|
||||
@@ -84,24 +84,24 @@ void RendererCore2D::render(Sprite* sprite,
|
||||
else if (sizeY > sizeX)
|
||||
texS = texMax / (sizeY / sizeX);
|
||||
|
||||
rect->t0.s = sprite->flipHorizontal ? texS : 0.0F;
|
||||
rect->t0.t = sprite->flipVertical ? texT : 0.0F;
|
||||
rect->t1.s = sprite->flipHorizontal ? 0.0F : texS;
|
||||
rect->t1.t = sprite->flipVertical ? 0.0F : texT;
|
||||
rect->t0.s = sprite.flipHorizontal ? texS : 0.0F;
|
||||
rect->t0.t = sprite.flipVertical ? texT : 0.0F;
|
||||
rect->t1.s = sprite.flipHorizontal ? 0.0F : texS;
|
||||
rect->t1.t = sprite.flipVertical ? 0.0F : texT;
|
||||
|
||||
rect->color.r = sprite->color.r;
|
||||
rect->color.g = sprite->color.g;
|
||||
rect->color.b = sprite->color.b;
|
||||
rect->color.a = sprite->color.a;
|
||||
rect->color.r = sprite.color.r;
|
||||
rect->color.g = sprite.color.g;
|
||||
rect->color.b = sprite.color.b;
|
||||
rect->color.a = sprite.color.a;
|
||||
rect->color.q = 0;
|
||||
|
||||
rect->v0.x = sprite->position.x;
|
||||
rect->v0.y = sprite->position.y;
|
||||
rect->v0.x = sprite.position.x;
|
||||
rect->v0.y = sprite.position.y;
|
||||
// rect->v0.y /= 2.0F; // interlacing
|
||||
rect->v0.z = (u32)-1;
|
||||
|
||||
rect->v1.x = (sprite->size.x * sprite->scale) + sprite->position.x;
|
||||
rect->v1.y = (sprite->size.y * sprite->scale) + sprite->position.y;
|
||||
rect->v1.x = (sprite.size.x * sprite.scale) + sprite.position.x;
|
||||
rect->v1.y = (sprite.size.y * sprite.scale) + sprite.position.y;
|
||||
// rect->v1.y /= 2.0F; // interlacing
|
||||
rect->v1.z = (u32)-1;
|
||||
|
||||
|
||||
@@ -56,6 +56,10 @@ void TextureRepository::removeById(const u32& t_texId) {
|
||||
removeByIndex(index);
|
||||
}
|
||||
|
||||
void TextureRepository::free(const Texture* t_tex) { free(t_tex->id); }
|
||||
|
||||
void TextureRepository::free(const Texture& t_tex) { free(t_tex.id); }
|
||||
|
||||
void TextureRepository::free(const u32& t_texId) {
|
||||
s32 index = getIndexOf(t_texId);
|
||||
auto* tex = textures[index];
|
||||
|
||||
Reference in New Issue
Block a user