mcpip changes
This commit is contained in:
@@ -19,12 +19,16 @@ namespace Tyra {
|
||||
|
||||
class McpipBlock {
|
||||
public:
|
||||
McpipBlock() {}
|
||||
McpipBlock() {
|
||||
model = nullptr;
|
||||
color = nullptr;
|
||||
textureOffset = nullptr;
|
||||
}
|
||||
~McpipBlock() {}
|
||||
|
||||
M4x4 model;
|
||||
Color color;
|
||||
Vec4 textureOffset;
|
||||
M4x4* model;
|
||||
Color* color;
|
||||
Vec4* textureOffset;
|
||||
};
|
||||
|
||||
} // namespace Tyra
|
||||
|
||||
@@ -37,14 +37,13 @@ class MinecraftPipeline : public Renderer3DPipeline {
|
||||
/**
|
||||
* @brief Render voxels
|
||||
*
|
||||
* @param blocks blocks to render
|
||||
* @param count number of blocks to render
|
||||
* @param blocks array of McpipBlock pointers
|
||||
* @param t_tex texture to use
|
||||
* @param isMulti is this a 6 texture voxel?
|
||||
* @param fullClipChecks false = faster, simple PS2 clipping. True = slower,
|
||||
* experimental "against each plane" clipping.
|
||||
*/
|
||||
void render(McpipBlock* blocks, const u32& count, Texture* t_tex,
|
||||
void render(std::vector<McpipBlock*> blocks, Texture* t_tex,
|
||||
const bool& isMulti = false, const bool& fullClipChecks = false);
|
||||
|
||||
inline const float& getTextureOffset() const {
|
||||
@@ -74,11 +73,11 @@ class MinecraftPipeline : public Renderer3DPipeline {
|
||||
|
||||
void changeMode(const McpipProgramName& requestedMode, const u8& force);
|
||||
|
||||
void cull(McpipBlock* blocks, const std::vector<u32>& indexes,
|
||||
void cull(std::vector<McpipBlock*> blocks, const std::vector<u32>& indexes,
|
||||
RendererCoreTextureBuffers* texBuffers, const bool& isCullOnly,
|
||||
const bool& isMulti = false);
|
||||
|
||||
void clip(McpipBlock* blocks, const std::vector<u32>& indexes,
|
||||
void clip(std::vector<McpipBlock*> blocks, const std::vector<u32>& indexes,
|
||||
RendererCoreTextureBuffers* texBuffers,
|
||||
const bool& isMulti = false);
|
||||
|
||||
|
||||
@@ -78,8 +78,8 @@ void MinecraftPipeline::initBBox() {
|
||||
bbox = new RenderBBox(block.vertices, block.count);
|
||||
}
|
||||
|
||||
void MinecraftPipeline::render(McpipBlock* blocks, const u32& count,
|
||||
Texture* t_tex, const bool& isMulti,
|
||||
void MinecraftPipeline::render(std::vector<McpipBlock*> blocks, Texture* t_tex,
|
||||
const bool& isMulti,
|
||||
const bool& fullClipChecks) {
|
||||
auto texBuffers = rendererCore->texture.useTexture(t_tex);
|
||||
|
||||
@@ -87,7 +87,7 @@ void MinecraftPipeline::render(McpipBlock* blocks, const u32& count,
|
||||
std::vector<u32> cullIndexes;
|
||||
|
||||
if (!fullClipChecks) {
|
||||
for (u32 i = 0; i < count; i++) cullIndexes.push_back(i);
|
||||
for (u32 i = 0; i < blocks.size(); i++) cullIndexes.push_back(i);
|
||||
cull(blocks, cullIndexes, &texBuffers, true, isMulti);
|
||||
return;
|
||||
}
|
||||
@@ -95,8 +95,8 @@ void MinecraftPipeline::render(McpipBlock* blocks, const u32& count,
|
||||
u32 culled = 0, clipped = 0;
|
||||
std::vector<u32> clipIndexes;
|
||||
|
||||
for (u32 i = 0; i < count; i++) {
|
||||
auto frustum = isInFrustum(blocks[i]);
|
||||
for (u32 i = 0; i < blocks.size(); i++) {
|
||||
auto frustum = isInFrustum(*blocks[i]);
|
||||
if (frustum == CoreBBoxFrustum::IN_FRUSTUM) {
|
||||
cullIndexes.push_back(i);
|
||||
culled++;
|
||||
@@ -112,10 +112,10 @@ void MinecraftPipeline::render(McpipBlock* blocks, const u32& count,
|
||||
|
||||
CoreBBoxFrustum MinecraftPipeline::isInFrustum(const McpipBlock& block) const {
|
||||
const auto* frustumPlanes = rendererCore->renderer3D.frustumPlanes.getAll();
|
||||
return bbox->clipIsInFrustum(frustumPlanes, block.model);
|
||||
return bbox->clipIsInFrustum(frustumPlanes, *block.model);
|
||||
}
|
||||
|
||||
void MinecraftPipeline::cull(McpipBlock* blocks,
|
||||
void MinecraftPipeline::cull(std::vector<McpipBlock*> blocks,
|
||||
const std::vector<u32>& indexes,
|
||||
RendererCoreTextureBuffers* texBuffers,
|
||||
const bool& isCullOnly, const bool& isMulti) {
|
||||
@@ -134,7 +134,7 @@ void MinecraftPipeline::cull(McpipBlock* blocks,
|
||||
u32 blockPointerArrayCount = 0;
|
||||
for (u32 j = 0; j < subArraySize; j++) {
|
||||
blockPointerArray[blockPointerArrayCount++] =
|
||||
&blocks[indexes[i * maxBlocksPerQBuffer + j]];
|
||||
blocks[indexes[i * maxBlocksPerQBuffer + j]];
|
||||
}
|
||||
|
||||
if (isCullOnly) {
|
||||
@@ -158,14 +158,14 @@ void MinecraftPipeline::cull(McpipBlock* blocks,
|
||||
// -- 1st qbuff: 500 - 221 = 279
|
||||
// Tags: 279 - for example 20 = 259
|
||||
// Vert + ST from EE = 259 / 2 = 129 verts | OK!
|
||||
void MinecraftPipeline::clip(McpipBlock* blocks,
|
||||
void MinecraftPipeline::clip(std::vector<McpipBlock*> blocks,
|
||||
const std::vector<u32>& indexes,
|
||||
RendererCoreTextureBuffers* texBuffers,
|
||||
const bool& isMulti) {
|
||||
changeMode(McPipAsIs, false);
|
||||
|
||||
for (u32 i = 0; i < indexes.size(); i++) {
|
||||
manager.clip(&blocks[indexes[i]], texBuffers, isMulti);
|
||||
manager.clip(blocks[indexes[i]], texBuffers, isMulti);
|
||||
}
|
||||
}
|
||||
|
||||
|
||||
@@ -61,7 +61,7 @@ void McpipClip::addData(McpipBlock* block, const bool& isMulti,
|
||||
RendererCoreTextureBuffers* texBuffers,
|
||||
packet2_t* packet, const u8& context) {
|
||||
std::vector<EEClipVertex> clippedVertices;
|
||||
auto mvp = rendererCore->renderer3D.getViewProj() * block->model;
|
||||
auto mvp = rendererCore->renderer3D.getViewProj() * (*block->model);
|
||||
|
||||
const auto* blockData = isMulti ? multiBlockData : singleBlockData;
|
||||
|
||||
@@ -96,7 +96,7 @@ void McpipClip::addCorrections(std::vector<EEClipVertex>* vertices,
|
||||
McpipBlock* block) {
|
||||
for (u32 i = 0; i < vertices->size(); i++) {
|
||||
(*vertices)[i].position /= (*vertices)[i].position.w; // Perspective divide
|
||||
(*vertices)[i].st += block->textureOffset; // Texture offset
|
||||
(*vertices)[i].st += *block->textureOffset; // Texture offset
|
||||
}
|
||||
}
|
||||
|
||||
@@ -132,7 +132,7 @@ void McpipClip::addDataToPacket(packet2_t* packet, const u8& context,
|
||||
packet2_utils_gs_add_texbuff_clut(packet, texBuffers->core,
|
||||
&rendererCore->texture.clut);
|
||||
|
||||
Packet2TyraUtils::addColor(packet, block->color);
|
||||
Packet2TyraUtils::addColor(packet, *block->color);
|
||||
}
|
||||
packet2_utils_vu_close_unpack(packet);
|
||||
|
||||
|
||||
@@ -131,9 +131,15 @@ void McpipCull::addData(packet2_t* packet, McpipBlock** blockPointerArray,
|
||||
u32 addr = VU1_MCPIP_CULL_DYNAMIC_BLOCKS_DATA;
|
||||
|
||||
for (u32 i = 0; i < blockPointerArrayCount; i++) {
|
||||
packet2_utils_vu_add_unpack_data(packet, addr, blockPointerArray[i],
|
||||
VU1_MCPIP_CULL_QWORDS_PER_BLOCK, true);
|
||||
addr += VU1_MCPIP_CULL_QWORDS_PER_BLOCK;
|
||||
packet2_utils_vu_add_unpack_data(packet, addr, blockPointerArray[i]->model,
|
||||
4, true);
|
||||
addr += 4;
|
||||
packet2_utils_vu_add_unpack_data(packet, addr, blockPointerArray[i]->color,
|
||||
1, true);
|
||||
addr += 1;
|
||||
packet2_utils_vu_add_unpack_data(
|
||||
packet, addr, blockPointerArray[i]->textureOffset, 1, true);
|
||||
addr += 1;
|
||||
}
|
||||
}
|
||||
|
||||
|
||||
@@ -21,8 +21,8 @@ BlockizerProgramsManager::BlockizerProgramsManager() {
|
||||
}
|
||||
|
||||
void BlockizerProgramsManager::allocateOnUse() {
|
||||
dynamicPackets[0] = packet2_create(300, P2_TYPE_NORMAL, P2_MODE_CHAIN, true);
|
||||
dynamicPackets[1] = packet2_create(300, P2_TYPE_NORMAL, P2_MODE_CHAIN, true);
|
||||
dynamicPackets[0] = packet2_create(800, P2_TYPE_NORMAL, P2_MODE_CHAIN, true);
|
||||
dynamicPackets[1] = packet2_create(800, P2_TYPE_NORMAL, P2_MODE_CHAIN, true);
|
||||
staticPacket = packet2_create(2, P2_TYPE_NORMAL, P2_MODE_CHAIN, true);
|
||||
}
|
||||
|
||||
|
||||
@@ -54,7 +54,7 @@ class Tutorial01 : public Game {
|
||||
Texture* blocksTex2;
|
||||
|
||||
u32 blocksCount;
|
||||
McpipBlock* blocks;
|
||||
std::vector<McpipBlock*> blocks;
|
||||
M4x4* translations;
|
||||
M4x4* rotations;
|
||||
M4x4* scales;
|
||||
|
||||
@@ -97,17 +97,16 @@ void Tutorial01 ::init() {
|
||||
for (u32 i = 0; i < picturesCount; i++)
|
||||
pictures[i] = get2DPicture(&engine->renderer);
|
||||
|
||||
u32 rows = 2; // 64
|
||||
u32 columns = 2; // 64
|
||||
u32 rows = 4; // 64
|
||||
u32 columns = 4; // 64
|
||||
blocksCount = rows * columns;
|
||||
|
||||
float offset = 4.0F;
|
||||
blocks = new McpipBlock[blocksCount];
|
||||
translations = new M4x4[blocksCount];
|
||||
rotations = new M4x4[blocksCount];
|
||||
scales = new M4x4[blocksCount];
|
||||
float center = (rows / 2.0F) * offset;
|
||||
|
||||
auto* color = new Color(128.0F, 128.0F, 128.0F, 128.0F);
|
||||
for (u32 i = 0; i < blocksCount; i++) {
|
||||
u32 column = i % columns;
|
||||
u32 row = i / rows;
|
||||
@@ -121,11 +120,13 @@ void Tutorial01 ::init() {
|
||||
u32 randRow = 0;
|
||||
u32 randColumn = 0;
|
||||
|
||||
blocks[i].textureOffset =
|
||||
Vec4(mcPip.getTextureOffset() * randRow,
|
||||
McpipBlock* block = new McpipBlock();
|
||||
block->textureOffset =
|
||||
new Vec4(mcPip.getTextureOffset() * randRow,
|
||||
mcPip.getTextureOffset() * randColumn, 0.0F, 1.0F);
|
||||
|
||||
blocks[i].color = Color(128.0F, 128.0F, 128.0F, 128.0F);
|
||||
block->color = color;
|
||||
blocks.push_back(block);
|
||||
}
|
||||
|
||||
// engine->audio.playSong();
|
||||
@@ -153,7 +154,10 @@ void Tutorial01 ::loop() {
|
||||
rotations[i].rotateY(0.04F);
|
||||
// rotations[i].rotateZ(0.01F);
|
||||
|
||||
blocks[i].model = translations[i] * rotations[i] * scales[i];
|
||||
if (blocks[i]->model) {
|
||||
delete blocks[i]->model;
|
||||
}
|
||||
blocks[i]->model = new M4x4(translations[i] * rotations[i] * scales[i]);
|
||||
}
|
||||
|
||||
for (u32 i = 0; i < picturesCount; i++)
|
||||
@@ -178,7 +182,7 @@ void Tutorial01 ::loop() {
|
||||
}
|
||||
|
||||
engine->renderer.renderer3D.usePipeline(&mcPip);
|
||||
{ mcPip.render(blocks, blocksCount, blocksTex2, true); }
|
||||
{ mcPip.render(blocks, blocksTex2, true); }
|
||||
}
|
||||
engine->renderer.endFrame();
|
||||
}
|
||||
|
||||
Reference in New Issue
Block a user