diff --git a/ROADMAP.txt b/ROADMAP.txt index 28df7fa..f960a19 100644 --- a/ROADMAP.txt +++ b/ROADMAP.txt @@ -1,10 +1,9 @@ ------------ Tyra's v2.0 roadmap to publish on GitHub ------------ --- H4570 -- [Renderer] Static and dynamic pipeline -- [Renderer] Add possibility to on/off frustum check in all pipelines (renderOptions?) - [Loaders] Think about ".tyrobj" format - implement it (add multicolor support) - [Loaders] DFF loader as static Mesh loader +- [Game] Update intellisense from docker - [Texture] Test cache hits with large amount of textures (dolphin sample?) - [Demo] Create cool demo which will show all features of Tyra (I will take this one) @@ -24,7 +23,7 @@ - [General] Check all TYRA_ASSERT() if there are no asserts like (TYRA_ASSERT(!audsrv_load_adpcm(result, data, adpcmFileSize))) because this lines will be removed on make-release. Only debug stuff should be checked in assert -- [General] All Copyrights to 2020-2022 +- [General] All Copyrights to 2022 - [General] CI in Github via docker image @@ -53,4 +52,5 @@ because Mesh rendering uses only core.render() ------------ Github issues for Tyra v2 ------------ - [3D] Add drawLine(x, y , color, size) -- [3D] Add drawBBox(x, y , color, size) \ No newline at end of file +- [3D] Add drawBBox(x, y , color, size) +- [File] Async file loading diff --git a/engine/inc/math/m4x4.hpp b/engine/inc/math/m4x4.hpp index efb9a74..994e627 100644 --- a/engine/inc/math/m4x4.hpp +++ b/engine/inc/math/m4x4.hpp @@ -12,6 +12,7 @@ #include "math/vec4.hpp" #include "math/math.hpp" +#include namespace Tyra { diff --git a/engine/inc/math/plane.hpp b/engine/inc/math/plane.hpp index a9c802d..68a57c3 100644 --- a/engine/inc/math/plane.hpp +++ b/engine/inc/math/plane.hpp @@ -10,6 +10,8 @@ #pragma once +#include "./vec4.hpp" +#include namespace Tyra { diff --git a/engine/inc/math/vec2.hpp b/engine/inc/math/vec2.hpp index 9f479ae..bace816 100644 --- a/engine/inc/math/vec2.hpp +++ b/engine/inc/math/vec2.hpp @@ -15,7 +15,6 @@ extern "C" { #include } -#include #include #include "math/math.hpp" diff --git a/engine/inc/math/vec4.hpp b/engine/inc/math/vec4.hpp index 35c1df6..673d280 100644 --- a/engine/inc/math/vec4.hpp +++ b/engine/inc/math/vec4.hpp @@ -16,9 +16,6 @@ extern "C" { } #include -#include -#include -#include #include #include "math/math.hpp" diff --git a/engine/inc/renderer/3d/mesh/dynamic/dynamic_mesh.hpp b/engine/inc/renderer/3d/mesh/dynamic/dynamic_mesh.hpp new file mode 100644 index 0000000..d8f47d4 --- /dev/null +++ b/engine/inc/renderer/3d/mesh/dynamic/dynamic_mesh.hpp @@ -0,0 +1,82 @@ +/* +# ______ ____ ___ +# | \/ ____| |___| +# | | | \ | | +#----------------------------------------------------------------------- +# Copyright 2022, tyra - https://github.com/h4570/tyra +# Licenced under Apache License 2.0 +# Sandro Sobczyński +*/ + +#pragma once + +#include "loaders/3d/builder/mesh_builder_data.hpp" +#include "../mesh_frame.hpp" +#include "../mesh_material_frame.hpp" +#include "./dynamic_mesh_anim_state.hpp" +#include "../mesh.hpp" + +namespace Tyra { + +class DynamicMesh : public Mesh { + public: + explicit DynamicMesh(const MeshBuilderData& data); + explicit DynamicMesh(const DynamicMesh& mesh); + ~DynamicMesh(); + + const DynamicMeshAnimState& getAnimState() const { return animState; } + + /** Returns single frame. */ + MeshFrame* getFrame(const u32& i) { return frames[i]; } + + MeshFrame** getFrames() { return frames; } + + /** 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; } + + void setCurrentAnimationFrame(const u32& v) { animState.currentFrame = v; } + void setNextAnimationFrame(const u32& v) { animState.nextFrame = v; } + void setStartAnimationFrame(const u32& v) { animState.startFrame = v; } + void setEndAnimationFrame(const u32& v) { animState.endFrame = v; } + void setStayAnimationFrame(const u32& v) { animState.stayFrame = v; } + + /** @returns bounding box object of current frame. */ + const BBox& getCurrentBoundingBox() const { + return frames[animState.currentFrame]->getBBox(); + } + + /** 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 initAnimation(); + DynamicMeshAnimState animState; + u32 framesCount; + MeshFrame** frames; +}; + +} // namespace Tyra diff --git a/engine/inc/renderer/3d/mesh/mesh_anim_state.hpp b/engine/inc/renderer/3d/mesh/dynamic/dynamic_mesh_anim_state.hpp similarity index 95% rename from engine/inc/renderer/3d/mesh/mesh_anim_state.hpp rename to engine/inc/renderer/3d/mesh/dynamic/dynamic_mesh_anim_state.hpp index 4a02964..25a5e25 100644 --- a/engine/inc/renderer/3d/mesh/mesh_anim_state.hpp +++ b/engine/inc/renderer/3d/mesh/dynamic/dynamic_mesh_anim_state.hpp @@ -25,6 +25,6 @@ typedef struct { u32 animType; u32 currentFrame; u32 nextFrame; -} MeshAnimState; +} DynamicMeshAnimState; } // namespace Tyra diff --git a/engine/inc/renderer/3d/mesh/mesh.hpp b/engine/inc/renderer/3d/mesh/mesh.hpp index 9b48ee0..d90ace5 100644 --- a/engine/inc/renderer/3d/mesh/mesh.hpp +++ b/engine/inc/renderer/3d/mesh/mesh.hpp @@ -1,121 +1,60 @@ -/* -# ______ ____ ___ -# | \/ ____| |___| -# | | | \ | | -#----------------------------------------------------------------------- -# Copyright 2022, tyra - https://github.com/h4570/tyra -# Licenced under Apache License 2.0 -# Sandro Sobczyński -*/ - -#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(&translation.data[3 * 4]); - } - - void setPosition(const Vec4& v) { - TYRA_ASSERT(v.w == 1.0F, "Vec4 must be homogeneous"); - reinterpret_cast(&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 +/* +# ______ ____ ___ +# | \/ ____| |___| +# | | | \ | | +#----------------------------------------------------------------------- +# Copyright 2022, tyra - https://github.com/h4570/tyra +# Licenced under Apache License 2.0 +# Sandro Sobczyński +*/ + +#pragma once + +#include "math/m4x4.hpp" +#include "./mesh_material.hpp" +#include +#include "debug/debug.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; + + inline const u32& getId() const { return id; } + inline const u8& isMother() const { return _isMother; } + M4x4 getModelMatrix() const; + + /** Get position from translation matrix */ + inline Vec4* getPosition() { + return reinterpret_cast(&translation.data[3 * 4]); + } + + void setPosition(const Vec4& v); + + /** Returns material, which is a mesh "subgroup". */ + MeshMaterial* getMaterial(const u32& i) const { return materials[i]; } + + MeshMaterial** getMaterials() { return materials; } + + const u32& getMaterialsCount() const { return materialsCount; } + + protected: + void init(); + u8 _isMother; + u32 id, materialsCount; + MeshMaterial** materials; +}; + +} // namespace Tyra diff --git a/engine/inc/renderer/3d/mesh/mesh_frame.hpp b/engine/inc/renderer/3d/mesh/mesh_frame.hpp index 9aa09a4..8bc7bcb 100644 --- a/engine/inc/renderer/3d/mesh/mesh_frame.hpp +++ b/engine/inc/renderer/3d/mesh/mesh_frame.hpp @@ -10,7 +10,7 @@ #pragma once -#include "renderer/3d/mesh/mesh_material.hpp" +#include "./mesh_material.hpp" #include "loaders/3d/builder/mesh_builder_data.hpp" #include "renderer/3d/bbox/bbox.hpp" @@ -23,18 +23,9 @@ class MeshFrame { ~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()); } @@ -43,9 +34,7 @@ class MeshFrame { private: u8 _isMother; BBox* bbox; - u32 id, vertexCount, textureCoordsCount, normalsCount, colorsCount; - Vec4 *vertices, *textureCoords, *normals; - Color* colors; + u32 id; }; } // namespace Tyra diff --git a/engine/inc/renderer/3d/mesh/mesh_material.hpp b/engine/inc/renderer/3d/mesh/mesh_material.hpp index af5d83a..063c94f 100644 --- a/engine/inc/renderer/3d/mesh/mesh_material.hpp +++ b/engine/inc/renderer/3d/mesh/mesh_material.hpp @@ -12,7 +12,7 @@ #include "debug/debug.hpp" #include "loaders/3d/builder/mesh_builder_data.hpp" -#include "renderer/3d/mesh/mesh_material_frame.hpp" +#include "./mesh_material_frame.hpp" namespace Tyra { @@ -22,22 +22,20 @@ class MeshMaterial { explicit MeshMaterial(const MeshMaterial& material); ~MeshMaterial(); - Color singleColor; + Color color; 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; } + const u32& getFramesCount() const { return framesCount; } + const u8& isSingleColorActivated() const { + return singleColorFlag; + } // TODO: colormode -> color / lightmap - 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; } + MeshMaterialFrame** getFrames() const { return frames; } + MeshMaterialFrame* getFrame(const u32& i) const { return frames[i]; } const BBox& getBBox(const u32& frame) const; - void setSingleColorFlag(const u8& flag); void print() const; @@ -50,8 +48,7 @@ class MeshMaterial { std::string _name; u8 _isMother, singleColorFlag; - u32 id, facesCount, framesCount; - u32 *vertexFaces, *textureCoordFaces, *normalFaces, *colorFaces; + u32 id, framesCount; }; } // namespace Tyra diff --git a/engine/inc/renderer/3d/mesh/mesh_material_frame.hpp b/engine/inc/renderer/3d/mesh/mesh_material_frame.hpp index 5cc3922..330744a 100644 --- a/engine/inc/renderer/3d/mesh/mesh_material_frame.hpp +++ b/engine/inc/renderer/3d/mesh/mesh_material_frame.hpp @@ -10,6 +10,7 @@ #pragma once +#include "loaders/3d/builder/mesh_builder_data.hpp" #include "./renderer/3d/bbox/bbox.hpp" namespace Tyra { @@ -25,11 +26,33 @@ class MeshMaterialFrame { const u8& isMother() const { return _isMother; } const BBox& getBBox() const { return *bbox; } + const u32& getVertexCount() const { return vertexCount; } + 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: + void allocateVertices(const MeshBuilderData& data, const u32& frameIndex, + const u32& materialIndex); + void allocateTextureCoords(const MeshBuilderData& data, const u32& frameIndex, + const u32& materialIndex); + void allocateNormals(const MeshBuilderData& data, const u32& frameIndex, + const u32& materialIndex); + void allocateColors(const MeshBuilderData& data, const u32& frameIndex, + const u32& materialIndex); + BBox* bbox; u8 _isMother; - u32 id; + u32 id, vertexCount; + Vec4 *vertices, *textureCoords, *normals; + Color* colors; }; } // namespace Tyra diff --git a/engine/inc/renderer/3d/mesh/static/static_mesh.hpp b/engine/inc/renderer/3d/mesh/static/static_mesh.hpp new file mode 100644 index 0000000..3b5275d --- /dev/null +++ b/engine/inc/renderer/3d/mesh/static/static_mesh.hpp @@ -0,0 +1,34 @@ +/* +# ______ ____ ___ +# | \/ ____| |___| +# | | | \ | | +#----------------------------------------------------------------------- +# Copyright 2022, tyra - https://github.com/h4570/tyra +# Licenced under Apache License 2.0 +# Sandro Sobczyński +*/ + +#pragma once + +#include "../mesh.hpp" +#include "../mesh_frame.hpp" +#include "../mesh_material.hpp" + +namespace Tyra { + +class StaticMesh : public Mesh { + public: + StaticMesh(const MeshBuilderData& data); + StaticMesh(const StaticMesh& mesh); + ~StaticMesh(); + + MeshFrame* getFrame() { return frame; } + + /** @returns bounding box object of current frame. */ + const BBox& getBoundingBox() const { return frame->getBBox(); } + + private: + MeshFrame* frame; +}; + +} // namespace Tyra diff --git a/engine/inc/renderer/3d/pipeline/dynamic/core/bag/dynpip_bag.hpp b/engine/inc/renderer/3d/pipeline/dynamic/core/bag/dynpip_bag.hpp new file mode 100644 index 0000000..0b71e26 --- /dev/null +++ b/engine/inc/renderer/3d/pipeline/dynamic/core/bag/dynpip_bag.hpp @@ -0,0 +1,67 @@ +/* +# ______ ____ ___ +# | \/ ____| |___| +# | | | \ | | +#----------------------------------------------------------------------- +# Copyright 2022, tyra - https://github.com/h4570/tyra +# Licenced under Apache License 2.0 +# Sandro Sobczyński +*/ + +#pragma once + +#include "math/vec4.hpp" + +#include "renderer/3d/pipeline/shared/bag/pipeline_info_bag.hpp" +#include "./dynpip_color_bag.hpp" +#include "./dynpip_lighting_bag.hpp" +#include "./dynpip_texture_bag.hpp" +#include "renderer/core/texture/models/texture.hpp" + +namespace Tyra { + +/** + * @brief 3D Animated render data bag. + * Supports frustum culling, simple clipping (culling), lighting, + * texture and single color / many colors. + */ +class DynPipBag { + public: + DynPipBag(); + ~DynPipBag(); + + /** Mandatory. Object info. */ + PipelineInfoBag* info; + + /** Mandatory. Object color(s). */ + DynPipColorBag* color; + + /** Mandatory. Vertex count per frame. */ + u32 count; + + /** Mandatory. From (frame) vertices */ + Vec4* verticesFrom; + + /** Mandatory. To (frame) vertices */ + Vec4* verticesTo; + + /** + * Mandatory. + * State of animation interpolation + * (between from and to) + */ + float interpolation; + + /** Optional. Texture coordinates and image. */ + DynPipTextureBag* texture; + + /** Optional. Object lighting. */ + DynPipLightingBag* lighting; + + 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 diff --git a/engine/inc/renderer/3d/pipeline/dynamic/core/bag/dynpip_color_bag.hpp b/engine/inc/renderer/3d/pipeline/dynamic/core/bag/dynpip_color_bag.hpp new file mode 100644 index 0000000..c6d7065 --- /dev/null +++ b/engine/inc/renderer/3d/pipeline/dynamic/core/bag/dynpip_color_bag.hpp @@ -0,0 +1,29 @@ +/* +# ______ ____ ___ +# | \/ ____| |___| +# | | | \ | | +#----------------------------------------------------------------------- +# Copyright 2022, tyra - https://github.com/h4570/tyra +# Licenced under Apache License 2.0 +# Sandro Sobczyński +*/ + +#pragma once + +#include "renderer/models/color.hpp" + +namespace Tyra { + +/** + * @brief Color data. At least one color data is required (single/many). + */ +class DynPipColorBag { + public: + DynPipColorBag(); + ~DynPipColorBag(); + + /** Mandatory */ + Color* single; +}; + +} // namespace Tyra diff --git a/engine/inc/renderer/3d/pipeline/dynamic/core/bag/dynpip_lighting_bag.hpp b/engine/inc/renderer/3d/pipeline/dynamic/core/bag/dynpip_lighting_bag.hpp new file mode 100644 index 0000000..3f0bfec --- /dev/null +++ b/engine/inc/renderer/3d/pipeline/dynamic/core/bag/dynpip_lighting_bag.hpp @@ -0,0 +1,36 @@ +/* +# ______ ____ ___ +# | \/ ____| |___| +# | | | \ | | +#----------------------------------------------------------------------- +# Copyright 2022, tyra - https://github.com/h4570/tyra +# Licenced under Apache License 2.0 +# Sandro Sobczyński +*/ + +#pragma once + +#include "math/vec4.hpp" +#include "renderer/3d/pipeline/shared/bag/pipeline_dir_lights_bag.hpp" + +namespace Tyra { + +class DynPipLightingBag { + public: + DynPipLightingBag(); + ~DynPipLightingBag(); + + /** Mandatory. Model matrix for lights. */ + M4x4* lightMatrix; + + /** Mandatory. Lighting normals per vertex. */ + Vec4* normalsFrom; + Vec4* normalsTo; + + /** Mandatory. Directional lights */ + PipelineDirLightsBag* dirLights; + + void freeNormals(); +}; + +} // namespace Tyra diff --git a/engine/inc/renderer/3d/pipeline/std/core/bag/stdpip_info_bag.hpp b/engine/inc/renderer/3d/pipeline/dynamic/core/bag/dynpip_texture_bag.hpp similarity index 56% rename from engine/inc/renderer/3d/pipeline/std/core/bag/stdpip_info_bag.hpp rename to engine/inc/renderer/3d/pipeline/dynamic/core/bag/dynpip_texture_bag.hpp index 3e6c94d..f08863b 100644 --- a/engine/inc/renderer/3d/pipeline/std/core/bag/stdpip_info_bag.hpp +++ b/engine/inc/renderer/3d/pipeline/dynamic/core/bag/dynpip_texture_bag.hpp @@ -10,25 +10,24 @@ #pragma once -#include -#include "math/m4x4.hpp" #include "math/vec4.hpp" -#include "../../stdpip_shading_type.hpp" +#include "renderer/core/texture/models/texture.hpp" namespace Tyra { -class StdpipInfoBag { +class DynPipTextureBag { public: - StdpipInfoBag(); - ~StdpipInfoBag(); + DynPipTextureBag(); + ~DynPipTextureBag(); - /** Mandatory. Model matrix */ - M4x4* model; + /** Mandatory. Texture coordinates per vertex. */ + Vec4* coordinatesFrom; + Vec4* coordinatesTo; - StdpipShadingType shadingType; - bool blendingEnabled; - bool antiAliasingEnabled; - bool noClipChecks; + /** Mandatory. Texture image. */ + Texture* texture; + + void freeCoords(); }; } // namespace Tyra diff --git a/engine/inc/renderer/3d/pipeline/dynamic/core/dynpip_core.hpp b/engine/inc/renderer/3d/pipeline/dynamic/core/dynpip_core.hpp new file mode 100644 index 0000000..2e4dca0 --- /dev/null +++ b/engine/inc/renderer/3d/pipeline/dynamic/core/dynpip_core.hpp @@ -0,0 +1,66 @@ +/* +# ______ ____ ___ +# | \/ ____| |___| +# | | | \ | | +#----------------------------------------------------------------------- +# Copyright 2022, tyra - https://github.com/h4570/tyra +# Licenced under Apache License 2.0 +# Sandro Sobczyński +*/ + +#pragma once + +#include +#include "./bag/dynpip_bag.hpp" +#include "renderer/core/renderer_core.hpp" +#include "./dynpip_programs_repository.hpp" +#include "./dynpip_renderer.hpp" + +namespace Tyra { + +class DynPipCore { + public: + DynPipCore(); + ~DynPipCore(); + + DynPipProgramsRepository repository; + + void init(RendererCore* t_core); + + /** Force starting VU1 program instead of continueing */ + void clear() { qbufferRenderer.clearLastProgramName(); } + + /** + * Send model matrix, lighting data and other + * repetitve stuff to VU1 + */ + void initParts(DynPipBag* data); + + /** Render 3D via "bags" */ + void renderPart(DynPipBag** bags, const u32& count, + const bool& frustumCull = true); + + /** Get max vert count of VU1 qbuffer (for optimizations) */ + u32 getMaxVertCountByParams(const bool& isLightingEnabled, + const bool& isTextureEnabled); + + /** + * - 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 reinitVU1Programs(); + + void allocateOnUse(const u32& t_packetSize) { + qbufferRenderer.allocateOnUse(t_packetSize); + } + void deallocateOnUse() { qbufferRenderer.deallocateOnUse(); } + + private: + M4x4 mvp; + RendererCore* rendererCore; + DynPipRenderer qbufferRenderer; +}; + +} // namespace Tyra diff --git a/engine/inc/renderer/3d/pipeline/dynamic/core/dynpip_program_name.hpp b/engine/inc/renderer/3d/pipeline/dynamic/core/dynpip_program_name.hpp new file mode 100644 index 0000000..ee5a08a --- /dev/null +++ b/engine/inc/renderer/3d/pipeline/dynamic/core/dynpip_program_name.hpp @@ -0,0 +1,24 @@ +/* +# ______ ____ ___ +# | \/ ____| |___| +# | | | \ | | +#----------------------------------------------------------------------- +# Copyright 2022, tyra - https://github.com/h4570/tyra +# Licenced under Apache License 2.0 +# Sandro Sobczyński +*/ + +#pragma once + +namespace Tyra { + +enum DynPipProgramName { + DynPipUndefinedProgram, + + DynPipColor, + DynPipDirLights, + DynPipTextureDirLights, + DynPipTextureColor, +}; + +} // namespace Tyra diff --git a/engine/inc/renderer/3d/pipeline/dynamic/core/dynpip_programs_repository.hpp b/engine/inc/renderer/3d/pipeline/dynamic/core/dynpip_programs_repository.hpp new file mode 100644 index 0000000..c53f9cf --- /dev/null +++ b/engine/inc/renderer/3d/pipeline/dynamic/core/dynpip_programs_repository.hpp @@ -0,0 +1,41 @@ +/* +# ______ ____ ___ +# | \/ ____| |___| +# | | | \ | | +#----------------------------------------------------------------------- +# Copyright 2022, tyra - https://github.com/h4570/tyra +# Licenced under Apache License 2.0 +# Sandro Sobczyński +*/ + +#pragma once + +#include "debug/debug.hpp" +#include "renderer/core/paths/path1/vu1_program.hpp" +#include "./bag/dynpip_bag.hpp" + +#include "./programs/dynpip_c_vu1_program.hpp" +#include "./programs/dynpip_d_vu1_program.hpp" +#include "./programs/dynpip_td_vu1_program.hpp" +#include "./programs/dynpip_tc_vu1_program.hpp" + +namespace Tyra { + +class DynPipProgramsRepository { + public: + DynPipProgramsRepository(); + ~DynPipProgramsRepository(); + + DynPipVU1Program* getProgram(const DynPipProgramName& name); + DynPipVU1Program* getProgramByParams(const bool& isLightingEnabled, + const bool& isTextureEnabled); + DynPipVU1Program* getProgramByBag(const DynPipBag* bag); + + private: + DynPipCVU1Program color; + DynPipDVU1Program dirLights; + DynPipTDVU1Program textureDirLights; + DynPipTCVU1Program textureColor; +}; + +} // namespace Tyra diff --git a/engine/inc/renderer/3d/pipeline/dynamic/core/dynpip_renderer.hpp b/engine/inc/renderer/3d/pipeline/dynamic/core/dynpip_renderer.hpp new file mode 100644 index 0000000..e5a33c6 --- /dev/null +++ b/engine/inc/renderer/3d/pipeline/dynamic/core/dynpip_renderer.hpp @@ -0,0 +1,66 @@ +/* +# ______ ____ ___ +# | \/ ____| |___| +# | | | \ | | +#----------------------------------------------------------------------- +# Copyright 2022, tyra - https://github.com/h4570/tyra +# Licenced under Apache License 2.0 +# Sandro Sobczyński +*/ + +#pragma once + +#include +#include "renderer/core/renderer_core.hpp" +#include "./dynpip_programs_repository.hpp" + +namespace Tyra { + +class DynPipRenderer { + public: + DynPipRenderer(); + ~DynPipRenderer(); + + void init(RendererCore* t_core, DynPipProgramsRepository* t_programRepo); + + void reinitVU1(); + + void sendObjectData(DynPipBag* bag, M4x4* mvp, + RendererCoreTextureBuffers* texBuffers) const; + + void render(DynPipBag** bags, const u32& count); + + void clearLastProgramName(); + + const u16& getBufferSize() { return bufferSize; } + + void allocateOnUse(const u32& t_packetSize); + void deallocateOnUse(); + + private: + void sendStaticData() const; + void setProgramsCache(); + void uploadPrograms(); + void setDoubleBuffer(); + + void addBufferDataToPacket(DynPipVU1Program* program, DynPipBag** bags, + const u32& count); + void sendPacket(); + + packet2_t* packets[2]; + packet2_t* programsPacket; + packet2_t* currentPacket; + packet2_t* staticDataPacket; + packet2_t* objectDataPacket; + + DynPipProgramsRepository* programsRepo; + RendererCore* rendererCore; + Path1* path1; + + DynPipProgramName lastProgramName; + + u16 bufferSize; + u8 context; +}; + +} // namespace Tyra diff --git a/engine/inc/renderer/3d/pipeline/dynamic/core/dynpip_vu1_program.hpp b/engine/inc/renderer/3d/pipeline/dynamic/core/dynpip_vu1_program.hpp new file mode 100644 index 0000000..fb15cd9 --- /dev/null +++ b/engine/inc/renderer/3d/pipeline/dynamic/core/dynpip_vu1_program.hpp @@ -0,0 +1,48 @@ +/* +# ______ ____ ___ +# | \/ ____| |___| +# | | | \ | | +#----------------------------------------------------------------------- +# Copyright 2022, tyra - https://github.com/h4570/tyra +# Licenced under Apache License 2.0 +# Sandro Sobczyński +*/ + +#pragma once + +#include "./dynpip_program_name.hpp" +#include "renderer/core/paths/path1/vu1_program.hpp" +#include "./programs/dynpip_vu1_shared_defines.h" +#include "./bag/dynpip_bag.hpp" + +namespace Tyra { + +class DynPipVU1Program : public VU1Program { + public: + DynPipVU1Program(const DynPipProgramName& name, u32* start, u32* end, + const u32& t_reglist, const u8& t_reglistCount, + const u8& t_elementsPerVertex); + ~DynPipVU1Program(); + + u32& getReglist(); + + const DynPipProgramName& getName() const; + + u16 getMaxVertCount(const u16& vu1DBufferSize) const; + + void addBufferDataToPacket(packet2_t* packet, DynPipBag* bag, prim_t* prim); + + protected: + DynPipProgramName name; + u8 reglistCount, elementsPerVertex; + u32 destinationAddress, reglist; + + virtual void addProgramQBufferDataToPacket(packet2_t* packet, + DynPipBag* bag) const = 0; + + private: + void addStandardBufferDataToPacket(packet2_t* packet, DynPipBag* bag, + prim_t* prim); +}; + +} // namespace Tyra diff --git a/engine/inc/renderer/core/paths/path1/programs/draw_finish/vu1_draw_finish.hpp b/engine/inc/renderer/3d/pipeline/dynamic/core/programs/dynpip_c_vu1_program.hpp similarity index 65% rename from engine/inc/renderer/core/paths/path1/programs/draw_finish/vu1_draw_finish.hpp rename to engine/inc/renderer/3d/pipeline/dynamic/core/programs/dynpip_c_vu1_program.hpp index 538549b..994355f 100644 --- a/engine/inc/renderer/core/paths/path1/programs/draw_finish/vu1_draw_finish.hpp +++ b/engine/inc/renderer/3d/pipeline/dynamic/core/programs/dynpip_c_vu1_program.hpp @@ -12,17 +12,17 @@ #include #include -#include "../../vu1_program.hpp" +#include "../dynpip_vu1_program.hpp" namespace Tyra { -class VU1DrawFinish : public VU1Program { +class DynPipCVU1Program : public DynPipVU1Program { public: - VU1DrawFinish(); - ~VU1DrawFinish(); + DynPipCVU1Program(); + ~DynPipCVU1Program(); std::string getStringName() const; - void addTag(packet2_t* packet, prim_t* prim) const; + void addProgramQBufferDataToPacket(packet2_t* packet, DynPipBag* bag) const; }; } // namespace Tyra diff --git a/engine/inc/renderer/3d/pipeline/dynamic/core/programs/dynpip_d_vu1_program.hpp b/engine/inc/renderer/3d/pipeline/dynamic/core/programs/dynpip_d_vu1_program.hpp new file mode 100644 index 0000000..b498ad1 --- /dev/null +++ b/engine/inc/renderer/3d/pipeline/dynamic/core/programs/dynpip_d_vu1_program.hpp @@ -0,0 +1,28 @@ +/* +# ______ ____ ___ +# | \/ ____| |___| +# | | | \ | | +#----------------------------------------------------------------------- +# Copyright 2022, tyra - https://github.com/h4570/tyra +# Licenced under Apache License 2.0 +# Sandro Sobczyński +*/ + +#pragma once + +#include +#include +#include "../dynpip_vu1_program.hpp" + +namespace Tyra { + +class DynPipDVU1Program : public DynPipVU1Program { + public: + DynPipDVU1Program(); + ~DynPipDVU1Program(); + + std::string getStringName() const; + void addProgramQBufferDataToPacket(packet2_t* packet, DynPipBag* bag) const; +}; + +} // namespace Tyra diff --git a/engine/inc/renderer/3d/pipeline/dynamic/core/programs/dynpip_tc_vu1_program.hpp b/engine/inc/renderer/3d/pipeline/dynamic/core/programs/dynpip_tc_vu1_program.hpp new file mode 100644 index 0000000..5b1d231 --- /dev/null +++ b/engine/inc/renderer/3d/pipeline/dynamic/core/programs/dynpip_tc_vu1_program.hpp @@ -0,0 +1,28 @@ +/* +# ______ ____ ___ +# | \/ ____| |___| +# | | | \ | | +#----------------------------------------------------------------------- +# Copyright 2022, tyra - https://github.com/h4570/tyra +# Licenced under Apache License 2.0 +# Sandro Sobczyński +*/ + +#pragma once + +#include +#include +#include "../dynpip_vu1_program.hpp" + +namespace Tyra { + +class DynPipTCVU1Program : public DynPipVU1Program { + public: + DynPipTCVU1Program(); + ~DynPipTCVU1Program(); + + std::string getStringName() const; + void addProgramQBufferDataToPacket(packet2_t* packet, DynPipBag* bag) const; +}; + +} // namespace Tyra diff --git a/engine/inc/renderer/3d/pipeline/dynamic/core/programs/dynpip_td_vu1_program.hpp b/engine/inc/renderer/3d/pipeline/dynamic/core/programs/dynpip_td_vu1_program.hpp new file mode 100644 index 0000000..5f528e0 --- /dev/null +++ b/engine/inc/renderer/3d/pipeline/dynamic/core/programs/dynpip_td_vu1_program.hpp @@ -0,0 +1,28 @@ +/* +# ______ ____ ___ +# | \/ ____| |___| +# | | | \ | | +#----------------------------------------------------------------------- +# Copyright 2022, tyra - https://github.com/h4570/tyra +# Licenced under Apache License 2.0 +# Sandro Sobczyński +*/ + +#pragma once + +#include +#include +#include "../dynpip_vu1_program.hpp" + +namespace Tyra { + +class DynPipTDVU1Program : public DynPipVU1Program { + public: + DynPipTDVU1Program(); + ~DynPipTDVU1Program(); + + std::string getStringName() const; + void addProgramQBufferDataToPacket(packet2_t* packet, DynPipBag* bag) const; +}; + +} // namespace Tyra diff --git a/engine/inc/renderer/3d/pipeline/std/core/path1/programs/stdpip_vu1_shared_defines.h b/engine/inc/renderer/3d/pipeline/dynamic/core/programs/dynpip_vu1_shared_defines.h similarity index 100% rename from engine/inc/renderer/3d/pipeline/std/core/path1/programs/stdpip_vu1_shared_defines.h rename to engine/inc/renderer/3d/pipeline/dynamic/core/programs/dynpip_vu1_shared_defines.h diff --git a/engine/inc/renderer/3d/pipeline/dynamic/dynamic_pipeline.hpp b/engine/inc/renderer/3d/pipeline/dynamic/dynamic_pipeline.hpp new file mode 100644 index 0000000..b77a604 --- /dev/null +++ b/engine/inc/renderer/3d/pipeline/dynamic/dynamic_pipeline.hpp @@ -0,0 +1,89 @@ +/* +# ______ ____ ___ +# | \/ ____| |___| +# | | | \ | | +#----------------------------------------------------------------------- +# Copyright 2022, tyra - https://github.com/h4570/tyra +# Licenced under Apache License 2.0 +# Sandro Sobczyński +*/ + +#pragma once + +#include +#include "../renderer_3d_pipeline.hpp" +#include "./dynpip_options.hpp" +#include "./core/dynpip_core.hpp" +#include "renderer/core/renderer_core.hpp" +#include "renderer/3d/mesh/dynamic/dynamic_mesh.hpp" + +namespace Tyra { + +/** + * Pipeline for animated models (DynamicMesh). + * Supports: + * - Simple PS2 clipping (culling) + * - Frustum culling + * - Modes: color, texture+color, dir lights, texture + dir lights + */ +class DynamicPipeline : public Renderer3DPipeline { + public: + DynamicPipeline(); + ~DynamicPipeline(); + + static const u32 buffersCount; + + DynPipCore core; + + void setRenderer(RendererCore* core); + + void onUse(); + + void onUseEnd(); + + /** + * Render dynamic model. + * This render() method is a bridge to core.render() method. + */ + void render(DynamicMesh* mesh, const DynPipOptions* options = nullptr); + + private: + RendererCore* rendererCore; + Vec4* colorsCache; + DynPipBag* buffers; + static const u32 halfBuffersCount; + + void setBuffer(DynPipBag* buffers, DynPipBag* buffer, u16* bufferIndex, + const PipelineFrustumCulling& frustumCulling); + + void sendRestOfBuffers(DynPipBag* buffers, u16* bufferIndex, + const PipelineFrustumCulling& frustumCulling); + + void addVertices(MeshMaterialFrame* materialFrameFrom, + MeshMaterialFrame* materialFrameTo, DynPipBag* bag, + const u32& startIndex) const; + + PipelineInfoBag* getInfoBag(DynamicMesh* mesh, const DynPipOptions* options, + M4x4* model) const; + + DynPipColorBag* getColorBag(MeshMaterial* material) const; + + DynPipTextureBag* getTextureBag(MeshMaterial* material, + MeshMaterialFrame* materialFrameFrom, + MeshMaterialFrame* materialFrameTo, + const u32& startIndex); + + DynPipLightingBag* getLightingBag(MeshMaterialFrame* materialFrameFrom, + MeshMaterialFrame* materialFrameTo, + M4x4* model, const DynPipOptions* options, + PipelineDirLightsBag* dirLightsBag, + const u32& startIndex) const; + + void setLightingColorsCache(PipelineLightingOptions* lightingOptions); + void freeBuffer(DynPipBag* bag); + void setBuffersDefaultVars(DynPipBag* buffers, DynamicMesh* mesh, + PipelineInfoBag* infoBag); + void setBuffersColorBag(DynPipBag* buffers, DynPipColorBag* colorBag); +}; + +} // namespace Tyra diff --git a/engine/inc/renderer/3d/pipeline/dynamic/dynpip_options.hpp b/engine/inc/renderer/3d/pipeline/dynamic/dynpip_options.hpp new file mode 100644 index 0000000..ece1bad --- /dev/null +++ b/engine/inc/renderer/3d/pipeline/dynamic/dynpip_options.hpp @@ -0,0 +1,23 @@ +/* +# ______ ____ ___ +# | \/ ____| |___| +# | | | \ | | +#----------------------------------------------------------------------- +# Copyright 2022, tyra - https://github.com/h4570/tyra +# Licenced under Apache License 2.0 +# Sandro Sobczyński +*/ + +#pragma once + +#include "renderer/3d/pipeline/shared/pipeline_options.hpp" + +namespace Tyra { + +class DynPipOptions : public PipelineOptions { + public: + DynPipOptions() {} + ~DynPipOptions() {} +}; + +} // namespace Tyra diff --git a/engine/inc/renderer/3d/pipeline/minecraft/minecraft_pipeline.hpp b/engine/inc/renderer/3d/pipeline/minecraft/minecraft_pipeline.hpp index 7a270e8..dded51d 100644 --- a/engine/inc/renderer/3d/pipeline/minecraft/minecraft_pipeline.hpp +++ b/engine/inc/renderer/3d/pipeline/minecraft/minecraft_pipeline.hpp @@ -18,17 +18,34 @@ namespace Tyra { +/** + * Pipeline specialized in fast rendering of voxels + * Supports: + * - Full "against each plane" clipping + * - Frustum culling (on fullClipChecks = true) + */ class MinecraftPipeline : public Renderer3DPipeline { public: MinecraftPipeline(); ~MinecraftPipeline(); - void init(RendererCore* core); + void setRenderer(RendererCore* core); void onUse(); + void onUseEnd(); + /** + * @brief Render voxels + * + * @param blocks blocks to render + * @param count number of blocks to render + * @param t_tex texture to use + * @param isMulti is this a 6 texture voxel? + * @param fullClipChecks false = faster, simple PS2 clipping. True = slower + * "against each plane" clipping. + */ void render(McpipBlock* blocks, const u32& count, Texture* t_tex, - const bool& isMulti = false, const bool& noClipChecks = true); + const bool& isMulti = false, const bool& fullClipChecks = false); inline const float& getTextureOffset() const { return manager.getTextureOffset(); @@ -42,12 +59,17 @@ class MinecraftPipeline : public Renderer3DPipeline { RenderBBox* bbox; McpipProgramName latestMode; + McpipBlock*** spamBuffers; + u32* spamCounts; + u32 spamBuffersCount; + u32 spammerIndex; + void initBBox(); void changeMode(const McpipProgramName& requestedMode, const u8& force); void cull(McpipBlock* blocks, const std::vector& indexes, - RendererCoreTextureBuffers* texBuffers, + RendererCoreTextureBuffers* texBuffers, const bool& isCullOnly, const bool& isMulti = false); void clip(McpipBlock* blocks, const std::vector& indexes, @@ -55,6 +77,12 @@ class MinecraftPipeline : public Renderer3DPipeline { const bool& isMulti = false); Tyra::CoreBBoxFrustum isInFrustum(const McpipBlock& block) const; + + void addToSpammer(McpipBlock** blockPointerArray, const u32& count, + RendererCoreTextureBuffers* texBuffers, + const bool& isMulti); + void flushSpammer(RendererCoreTextureBuffers* texBuffers, + const bool& isMulti); }; } // namespace Tyra diff --git a/engine/inc/renderer/3d/pipeline/minecraft/programs/as_is/mcpip_clip.hpp b/engine/inc/renderer/3d/pipeline/minecraft/programs/as_is/mcpip_clip.hpp index 17ef516..b3b9d1c 100644 --- a/engine/inc/renderer/3d/pipeline/minecraft/programs/as_is/mcpip_clip.hpp +++ b/engine/inc/renderer/3d/pipeline/minecraft/programs/as_is/mcpip_clip.hpp @@ -18,7 +18,7 @@ #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" +#include "renderer/core/3d/clipper/ee_clip_algorithm.hpp" namespace Tyra { @@ -27,8 +27,8 @@ class McpipClip { McpipClip(); ~McpipClip(); - Path1EEClipAlgorithm algorithm; - Path1EEClipAlgorithmSettings algoSettings; + EEClipAlgorithm algorithm; + EEClipAlgorithmSettings algoSettings; void init(RendererCore* core, McpipBlockData* t_singleBlockData, McpipBlockData* t_multiBlockData); @@ -48,16 +48,14 @@ class McpipClip { packet2_t* staticPacket; u16 vu1DBufferSize; - std::vector clippedTriangle; - std::vector inputTriangle; + std::vector clippedTriangle; + std::vector inputTriangle; Vec4 vertexBuffers[2][108]; Vec4 texCoordBuffers[2][108]; - void addCorrections(std::vector* vertices, - McpipBlock* block); - void moveDataToBuffer(std::vector* vertices, - const u8& context); + void addCorrections(std::vector* vertices, McpipBlock* block); + void moveDataToBuffer(std::vector* vertices, const u8& context); void addDataToPacket(packet2_t* packet, const u8& context, McpipBlock* block, const int& count, RendererCoreTextureBuffers* texBuffers); diff --git a/engine/inc/renderer/3d/pipeline/minecraft/programs/mcpip_programs_manager.hpp b/engine/inc/renderer/3d/pipeline/minecraft/programs/mcpip_programs_manager.hpp index aecff93..6dac5c4 100644 --- a/engine/inc/renderer/3d/pipeline/minecraft/programs/mcpip_programs_manager.hpp +++ b/engine/inc/renderer/3d/pipeline/minecraft/programs/mcpip_programs_manager.hpp @@ -42,6 +42,10 @@ class BlockizerProgramsManager { void clearLastProgram() { lastProgramName = UndefinedMcpipProgram; } + void cullSpam(McpipBlock*** blockPointerArrays, u32* blockPointerArrayCounts, + u32 blockPointerArraysCount, + RendererCoreTextureBuffers* texBuffers, const bool& isMulti); + void cull(McpipBlock** blockPointerArray, u32 blockPointerArrayCount, RendererCoreTextureBuffers* texBuffers, const bool& isMulti); @@ -54,6 +58,9 @@ class BlockizerProgramsManager { const McpipBlockData& getBlockData() const { return singleTexBlockData; } + void allocateOnUse(); + void deallocateOnUse(); + private: McpipProgramsRepository repo; Renderer* renderer; @@ -69,6 +76,7 @@ class BlockizerProgramsManager { void setProgramsCache(); void uploadBlock(bool isMulti); + void addProgram(McpipProgram* program); void sendPacket(McpipProgram* program); }; diff --git a/engine/inc/renderer/3d/pipeline/renderer_3d_pipeline.hpp b/engine/inc/renderer/3d/pipeline/renderer_3d_pipeline.hpp index 7b9f3a6..d447c71 100644 --- a/engine/inc/renderer/3d/pipeline/renderer_3d_pipeline.hpp +++ b/engine/inc/renderer/3d/pipeline/renderer_3d_pipeline.hpp @@ -19,8 +19,9 @@ class Renderer3DPipeline { Renderer3DPipeline() {} ~Renderer3DPipeline() {} - virtual void init(RendererCore* core) = 0; + virtual void setRenderer(RendererCore* core) = 0; virtual void onUse() = 0; + virtual void onUseEnd() = 0; }; } // namespace Tyra diff --git a/engine/inc/renderer/3d/pipeline/std/core/bag/stdpip_lighting_bag.hpp b/engine/inc/renderer/3d/pipeline/shared/bag/pipeline_dir_lights_bag.hpp similarity index 84% rename from engine/inc/renderer/3d/pipeline/std/core/bag/stdpip_lighting_bag.hpp rename to engine/inc/renderer/3d/pipeline/shared/bag/pipeline_dir_lights_bag.hpp index f399c9d..7531688 100644 --- a/engine/inc/renderer/3d/pipeline/std/core/bag/stdpip_lighting_bag.hpp +++ b/engine/inc/renderer/3d/pipeline/shared/bag/pipeline_dir_lights_bag.hpp @@ -16,15 +16,12 @@ namespace Tyra { -enum StdpipLightingBagMode { Auto, Manual }; +enum PipelineDirLightsBagMode { Auto, Manual }; -class StdpipLightingBag { +class PipelineDirLightsBag { public: - explicit StdpipLightingBag(const bool& manual = false); - ~StdpipLightingBag(); - - Vec4* normals; - M4x4* lightMatrix; + explicit PipelineDirLightsBag(const bool& manual = false); + ~PipelineDirLightsBag(); void setAmbientColor(const Color& color); void setDirectionalLightColors(Color* colors, const u8& count); @@ -47,7 +44,7 @@ class StdpipLightingBag { void deallocate(); void forceDeallocate(); u8 isAllocated; - StdpipLightingBagMode mode; + PipelineDirLightsBagMode mode; Vec4* lightColors; Vec4* lightDirections; diff --git a/engine/inc/renderer/3d/pipeline/shared/bag/pipeline_info_bag.hpp b/engine/inc/renderer/3d/pipeline/shared/bag/pipeline_info_bag.hpp new file mode 100644 index 0000000..aa14523 --- /dev/null +++ b/engine/inc/renderer/3d/pipeline/shared/bag/pipeline_info_bag.hpp @@ -0,0 +1,44 @@ +/* +# ______ ____ ___ +# | \/ ____| |___| +# | | | \ | | +#----------------------------------------------------------------------- +# Copyright 2022, tyra - https://github.com/h4570/tyra +# Licenced under Apache License 2.0 +# Sandro Sobczyński +*/ + +#pragma once + +#include +#include "math/m4x4.hpp" +#include "math/vec4.hpp" +#include "../pipeline_shading_type.hpp" + +namespace Tyra { + +class PipelineInfoBag { + public: + PipelineInfoBag(); + ~PipelineInfoBag(); + + /** Mandatory. Model matrix */ + M4x4* model; + + PipelineShadingType shadingType; + bool blendingEnabled; + bool antiAliasingEnabled; + + /** + * @brief False -> disables "clip against each plane" algorithm. + * Default: True. + * + * Full clip checks are slow, but they are + * preventing visual artifacts, which can happen + * for big 3D objects (or objects near camera eyes) + * Force enabled in dynamic pipe, because of efficiency. + */ + bool fullClipChecks; +}; + +} // namespace Tyra diff --git a/engine/inc/renderer/3d/pipeline/shared/pipeline_frustum_culling.hpp b/engine/inc/renderer/3d/pipeline/shared/pipeline_frustum_culling.hpp new file mode 100644 index 0000000..a374e44 --- /dev/null +++ b/engine/inc/renderer/3d/pipeline/shared/pipeline_frustum_culling.hpp @@ -0,0 +1,24 @@ +/* +# ______ ____ ___ +# | \/ ____| |___| +# | | | \ | | +#----------------------------------------------------------------------- +# Copyright 2022, tyra - https://github.com/h4570/tyra +# Licenced under Apache License 2.0 +# Sandro Sobczyński +*/ + +#pragma once + +namespace Tyra { + +enum PipelineFrustumCulling { + /** No frustum culling */ + PipelineFrustumCulling_None = 0, + /** Frustum culling of whole object */ + PipelineFrustumCulling_Simple = 1, + /** Frustum culling of parts of an object */ + PipelineFrustumCulling_Precise = 2, +}; + +} diff --git a/engine/inc/renderer/3d/pipeline/std/stdpip_lighting_options.hpp b/engine/inc/renderer/3d/pipeline/shared/pipeline_lighting_options.hpp similarity index 89% rename from engine/inc/renderer/3d/pipeline/std/stdpip_lighting_options.hpp rename to engine/inc/renderer/3d/pipeline/shared/pipeline_lighting_options.hpp index ae4bc85..df8d484 100644 --- a/engine/inc/renderer/3d/pipeline/std/stdpip_lighting_options.hpp +++ b/engine/inc/renderer/3d/pipeline/shared/pipeline_lighting_options.hpp @@ -15,10 +15,10 @@ namespace Tyra { -class StdpipLightingOptions { +class PipelineLightingOptions { public: - StdpipLightingOptions() {} - ~StdpipLightingOptions() {} + PipelineLightingOptions() {} + ~PipelineLightingOptions() {} /** * Mandatory. diff --git a/engine/inc/renderer/3d/pipeline/std/stdpip_options.hpp b/engine/inc/renderer/3d/pipeline/shared/pipeline_options.hpp similarity index 54% rename from engine/inc/renderer/3d/pipeline/std/stdpip_options.hpp rename to engine/inc/renderer/3d/pipeline/shared/pipeline_options.hpp index 71f207b..214f999 100644 --- a/engine/inc/renderer/3d/pipeline/std/stdpip_options.hpp +++ b/engine/inc/renderer/3d/pipeline/shared/pipeline_options.hpp @@ -10,23 +10,24 @@ #pragma once -#include "./stdpip_shading_type.hpp" -#include "./stdpip_lighting_options.hpp" +#include "renderer/3d/pipeline/shared/pipeline_shading_type.hpp" +#include "../shared/pipeline_lighting_options.hpp" +#include "./pipeline_frustum_culling.hpp" namespace Tyra { -class StdpipOptions { +class PipelineOptions { public: - StdpipOptions() {} - ~StdpipOptions() {} + PipelineOptions() { lighting = nullptr; } + ~PipelineOptions() {} - StdpipShadingType shadingType; + PipelineFrustumCulling frustumCulling; + PipelineShadingType shadingType; bool blendingEnabled; bool antiAliasingEnabled; - bool noClipChecks; /** Optional */ - StdpipLightingOptions* lighting; + PipelineLightingOptions* lighting; }; } // namespace Tyra diff --git a/engine/inc/renderer/3d/pipeline/std/stdpip_shading_type.hpp b/engine/inc/renderer/3d/pipeline/shared/pipeline_shading_type.hpp similarity index 79% rename from engine/inc/renderer/3d/pipeline/std/stdpip_shading_type.hpp rename to engine/inc/renderer/3d/pipeline/shared/pipeline_shading_type.hpp index d38b2fb..9fa387f 100644 --- a/engine/inc/renderer/3d/pipeline/std/stdpip_shading_type.hpp +++ b/engine/inc/renderer/3d/pipeline/shared/pipeline_shading_type.hpp @@ -12,9 +12,9 @@ namespace Tyra { -enum StdpipShadingType { - StdpipShadingFlat, - StdpipShadingGouraud, +enum PipelineShadingType { + TyraShadingFlat, + TyraShadingGouraud, }; } // namespace Tyra diff --git a/engine/inc/renderer/3d/pipeline/std/core/bag/packaging/stdpip_bag_package.hpp b/engine/inc/renderer/3d/pipeline/static/core/bag/packaging/stapip_bag_package.hpp similarity index 79% rename from engine/inc/renderer/3d/pipeline/std/core/bag/packaging/stdpip_bag_package.hpp rename to engine/inc/renderer/3d/pipeline/static/core/bag/packaging/stapip_bag_package.hpp index 194b28d..0ab35e3 100644 --- a/engine/inc/renderer/3d/pipeline/std/core/bag/packaging/stdpip_bag_package.hpp +++ b/engine/inc/renderer/3d/pipeline/static/core/bag/packaging/stapip_bag_package.hpp @@ -10,17 +10,17 @@ #pragma once -#include "../stdpip_bag.hpp" +#include "../stapip_bag.hpp" #include "renderer/core/3d/bbox/core_bbox_frustum.hpp" namespace Tyra { -class StdpipBagPackage { +class StaPipBagPackage { public: - StdpipBagPackage(); - ~StdpipBagPackage(); + StaPipBagPackage(); + ~StaPipBagPackage(); - StdpipBag* bag; + StaPipBag* bag; Vec4* vertices; Vec4* sts; @@ -32,12 +32,12 @@ class StdpipBagPackage { CoreBBoxFrustum isInFrustum; /** - * We are creating StdpipBagPackagesBBox which checks CoreBBoxBBox for every + * We are creating StaPipBagPackagesBBox which checks CoreBBoxBBox for every * maxVertCount / 3. So this variable is index of starting - * StdpipBagPackagesBBox's CoreBBoxBBox. If package have <= maxVertCount / 3 + * StaPipBagPackagesBBox'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. + * StaPipBagPackagesBBox's bboxes. */ u32 indexOf1By3BBox; diff --git a/engine/inc/renderer/3d/pipeline/std/core/bag/packaging/stdpip_bag_packager.hpp b/engine/inc/renderer/3d/pipeline/static/core/bag/packaging/stapip_bag_packager.hpp similarity index 63% rename from engine/inc/renderer/3d/pipeline/std/core/bag/packaging/stdpip_bag_packager.hpp rename to engine/inc/renderer/3d/pipeline/static/core/bag/packaging/stapip_bag_packager.hpp index aa91507..3c338e0 100644 --- a/engine/inc/renderer/3d/pipeline/std/core/bag/packaging/stdpip_bag_packager.hpp +++ b/engine/inc/renderer/3d/pipeline/static/core/bag/packaging/stapip_bag_packager.hpp @@ -12,20 +12,20 @@ #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" +#include "renderer/core/3d/clipper/ee_clip_algorithm.hpp" +#include "./stapip_bag_packages_bbox.hpp" +#include "./stapip_bag_package.hpp" +#include "../stapip_bag.hpp" namespace Tyra { -class StdpipBagPackager { +class StaPipBagPackager { public: - StdpipBagPackager(); - ~StdpipBagPackager(); + StaPipBagPackager(); + ~StaPipBagPackager(); void init(Renderer3DFrustumPlanes* frustumPlanes); - void setRenderBBox(StdpipBagPackagesBBox* bbox) { renderBBox = bbox; } + void setRenderBBox(StaPipBagPackagesBBox* bbox) { renderBBox = bbox; } void setMaxVertCount(const u32& count); /** @@ -33,20 +33,20 @@ class StdpipBagPackager { * * @param size Max maxVertCount verts (VU1 buffer size) */ - StdpipBagPackage* create(u16* o_size, StdpipBag* data, u16 size); + StaPipBagPackage* create(u16* o_size, StaPipBag* 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); + StaPipBagPackage* create(u16* o_size, const StaPipBagPackage& pkg, u16 size); - CoreBBoxFrustum checkFrustum(const StdpipBagPackage& pkg); + CoreBBoxFrustum checkFrustum(const StaPipBagPackage& pkg); private: u32 maxVertCount; Renderer3DFrustumPlanes* frustumPlanes; - StdpipBagPackagesBBox* renderBBox; + StaPipBagPackagesBBox* renderBBox; }; } // namespace Tyra diff --git a/engine/inc/renderer/3d/pipeline/std/core/bag/packaging/stdpip_bag_packages_bbox.hpp b/engine/inc/renderer/3d/pipeline/static/core/bag/packaging/stapip_bag_packages_bbox.hpp similarity index 90% rename from engine/inc/renderer/3d/pipeline/std/core/bag/packaging/stdpip_bag_packages_bbox.hpp rename to engine/inc/renderer/3d/pipeline/static/core/bag/packaging/stapip_bag_packages_bbox.hpp index ed7a460..94ddd1f 100644 --- a/engine/inc/renderer/3d/pipeline/std/core/bag/packaging/stdpip_bag_packages_bbox.hpp +++ b/engine/inc/renderer/3d/pipeline/static/core/bag/packaging/stapip_bag_packages_bbox.hpp @@ -18,13 +18,13 @@ namespace Tyra { * Splits all 3D input vertices into 16vert parts and creates child bboxes for * it */ -class StdpipBagPackagesBBox { +class StaPipBagPackagesBBox { public: - StdpipBagPackagesBBox(Vec4* t_vertices, u32* t_faces, const u32& t_facesCount, + StaPipBagPackagesBBox(Vec4* t_vertices, u32* t_faces, const u32& t_facesCount, const u32& t_maxVertCount); - StdpipBagPackagesBBox(Vec4* t_vertices, const u32& t_counts, + StaPipBagPackagesBBox(Vec4* t_vertices, const u32& t_counts, const u32& t_maxVertCount); - ~StdpipBagPackagesBBox(); + ~StaPipBagPackagesBBox(); void setMaxVertCount(const u32& count); diff --git a/engine/inc/renderer/3d/pipeline/std/core/bag/stdpip_bag.hpp b/engine/inc/renderer/3d/pipeline/static/core/bag/stapip_bag.hpp similarity index 67% rename from engine/inc/renderer/3d/pipeline/std/core/bag/stdpip_bag.hpp rename to engine/inc/renderer/3d/pipeline/static/core/bag/stapip_bag.hpp index 30b4ffa..a89d93c 100644 --- a/engine/inc/renderer/3d/pipeline/std/core/bag/stdpip_bag.hpp +++ b/engine/inc/renderer/3d/pipeline/static/core/bag/stapip_bag.hpp @@ -11,30 +11,30 @@ #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/3d/pipeline/shared/bag/pipeline_info_bag.hpp" +#include "./stapip_color_bag.hpp" +#include "./stapip_lighting_bag.hpp" +#include "./stapip_texture_bag.hpp" #include "renderer/core/texture/models/texture.hpp" -#include "./packaging/stdpip_bag_packages_bbox.hpp" +#include "./packaging/stapip_bag_packages_bbox.hpp" namespace Tyra { /** * @brief 3D Render data bag. - * Supports frustum culling, clipping, lighting, + * Supports frustum culling, full plane clipping, lighting, * texture and single color / many colors. */ -class StdpipBag { +class StaPipBag { public: - StdpipBag(); - ~StdpipBag(); + StaPipBag(); + ~StaPipBag(); /** Mandatory. Object info. */ - StdpipInfoBag* info; + PipelineInfoBag* info; /** Mandatory. Object color(s). */ - StdpipColorBag* color; + StaPipColorBag* color; /** Mandatory. Vertex count. */ u32 count; @@ -43,15 +43,15 @@ class StdpipBag { Vec4* vertices; /** Optional. Texture coordinates and image. */ - StdpipTextureBag* texture; + StaPipTextureBag* texture; /** Optional. Object lighting. */ - StdpipLightingBag* lighting; + StaPipLightingBag* lighting; /** * @param maxVertCount This parameter is available in renderer API. */ - StdpipBagPackagesBBox calculateBbox(const u32& maxVertCount); + StaPipBagPackagesBBox calculateBbox(const u32& maxVertCount); void print() const; void print(const char* name) const; diff --git a/engine/inc/renderer/3d/pipeline/std/core/bag/stdpip_color_bag.hpp b/engine/inc/renderer/3d/pipeline/static/core/bag/stapip_color_bag.hpp similarity index 90% rename from engine/inc/renderer/3d/pipeline/std/core/bag/stdpip_color_bag.hpp rename to engine/inc/renderer/3d/pipeline/static/core/bag/stapip_color_bag.hpp index e6a7132..4106cd4 100644 --- a/engine/inc/renderer/3d/pipeline/std/core/bag/stdpip_color_bag.hpp +++ b/engine/inc/renderer/3d/pipeline/static/core/bag/stapip_color_bag.hpp @@ -17,10 +17,10 @@ namespace Tyra { /** * @brief Color data. At least one color data is required (single/many). */ -class StdpipColorBag { +class StaPipColorBag { public: - StdpipColorBag(); - ~StdpipColorBag(); + StaPipColorBag(); + ~StaPipColorBag(); /** Optional. Single color for all vertices. */ Color* single; diff --git a/engine/inc/renderer/3d/pipeline/static/core/bag/stapip_lighting_bag.hpp b/engine/inc/renderer/3d/pipeline/static/core/bag/stapip_lighting_bag.hpp new file mode 100644 index 0000000..46f3223 --- /dev/null +++ b/engine/inc/renderer/3d/pipeline/static/core/bag/stapip_lighting_bag.hpp @@ -0,0 +1,33 @@ +/* +# ______ ____ ___ +# | \/ ____| |___| +# | | | \ | | +#----------------------------------------------------------------------- +# Copyright 2022, tyra - https://github.com/h4570/tyra +# Licenced under Apache License 2.0 +# Sandro Sobczyński +*/ + +#pragma once + +#include "math/vec4.hpp" +#include "renderer/3d/pipeline/shared/bag/pipeline_dir_lights_bag.hpp" + +namespace Tyra { + +class StaPipLightingBag { + public: + StaPipLightingBag(); + ~StaPipLightingBag(); + + /** Mandatory. Model matrix for lights. */ + M4x4* lightMatrix; + + /** Mandatory. Lighting normals per vertex. */ + Vec4* normals; + + /** Mandatory. Directional lights */ + PipelineDirLightsBag* dirLights; +}; + +} // namespace Tyra diff --git a/engine/inc/renderer/3d/pipeline/std/core/bag/stdpip_texture_bag.hpp b/engine/inc/renderer/3d/pipeline/static/core/bag/stapip_texture_bag.hpp similarity index 89% rename from engine/inc/renderer/3d/pipeline/std/core/bag/stdpip_texture_bag.hpp rename to engine/inc/renderer/3d/pipeline/static/core/bag/stapip_texture_bag.hpp index 9ee3e70..b940fe7 100644 --- a/engine/inc/renderer/3d/pipeline/std/core/bag/stdpip_texture_bag.hpp +++ b/engine/inc/renderer/3d/pipeline/static/core/bag/stapip_texture_bag.hpp @@ -15,10 +15,10 @@ namespace Tyra { -class StdpipTextureBag { +class StaPipTextureBag { public: - StdpipTextureBag(); - ~StdpipTextureBag(); + StaPipTextureBag(); + ~StaPipTextureBag(); /** Mandatory. Texture coordinates per vertex. */ Vec4* coordinates; diff --git a/engine/inc/renderer/3d/pipeline/std/core/path1/programs/as_is/stdpip_as_is_c_vu1_program.hpp b/engine/inc/renderer/3d/pipeline/static/core/programs/as_is/stapip_as_is_c_vu1_program.hpp similarity index 67% rename from engine/inc/renderer/3d/pipeline/std/core/path1/programs/as_is/stdpip_as_is_c_vu1_program.hpp rename to engine/inc/renderer/3d/pipeline/static/core/programs/as_is/stapip_as_is_c_vu1_program.hpp index 3b337ff..1b7d45c 100644 --- a/engine/inc/renderer/3d/pipeline/std/core/path1/programs/as_is/stdpip_as_is_c_vu1_program.hpp +++ b/engine/inc/renderer/3d/pipeline/static/core/programs/as_is/stapip_as_is_c_vu1_program.hpp @@ -12,19 +12,19 @@ #include #include -#include "../../stdpip_vu1_program.hpp" +#include "../../stapip_vu1_program.hpp" namespace Tyra { -class StdpipAsIsCVU1Program : public StdpipVU1Program { +class StaPipAsIsCVU1Program : public StaPipVU1Program { public: - StdpipAsIsCVU1Program(); - ~StdpipAsIsCVU1Program(); + StaPipAsIsCVU1Program(); + ~StaPipAsIsCVU1Program(); std::string getStringName() const; void addProgramQBufferDataToPacket(packet2_t* packet, - StdpipQBuffer* qbuffer) const; + StaPipQBuffer* qbuffer) const; }; } // namespace Tyra diff --git a/engine/inc/renderer/3d/pipeline/std/core/path1/programs/as_is/stdpip_as_is_d_vu1_program.hpp b/engine/inc/renderer/3d/pipeline/static/core/programs/as_is/stapip_as_is_d_vu1_program.hpp similarity index 67% rename from engine/inc/renderer/3d/pipeline/std/core/path1/programs/as_is/stdpip_as_is_d_vu1_program.hpp rename to engine/inc/renderer/3d/pipeline/static/core/programs/as_is/stapip_as_is_d_vu1_program.hpp index 9f3f621..59aa838 100644 --- a/engine/inc/renderer/3d/pipeline/std/core/path1/programs/as_is/stdpip_as_is_d_vu1_program.hpp +++ b/engine/inc/renderer/3d/pipeline/static/core/programs/as_is/stapip_as_is_d_vu1_program.hpp @@ -12,18 +12,18 @@ #include #include -#include "../../stdpip_vu1_program.hpp" +#include "../../stapip_vu1_program.hpp" namespace Tyra { -class StdpipAsIsDVU1Program : public StdpipVU1Program { +class StaPipAsIsDVU1Program : public StaPipVU1Program { public: - StdpipAsIsDVU1Program(); - ~StdpipAsIsDVU1Program(); + StaPipAsIsDVU1Program(); + ~StaPipAsIsDVU1Program(); std::string getStringName() const; void addProgramQBufferDataToPacket(packet2_t* packet, - StdpipQBuffer* qbuffer) const; + StaPipQBuffer* qbuffer) const; }; } // namespace Tyra diff --git a/engine/inc/renderer/3d/pipeline/std/core/path1/programs/as_is/stdpip_as_is_tc_vu1_program.hpp b/engine/inc/renderer/3d/pipeline/static/core/programs/as_is/stapip_as_is_tc_vu1_program.hpp similarity index 67% rename from engine/inc/renderer/3d/pipeline/std/core/path1/programs/as_is/stdpip_as_is_tc_vu1_program.hpp rename to engine/inc/renderer/3d/pipeline/static/core/programs/as_is/stapip_as_is_tc_vu1_program.hpp index c63e6c8..b026174 100644 --- a/engine/inc/renderer/3d/pipeline/std/core/path1/programs/as_is/stdpip_as_is_tc_vu1_program.hpp +++ b/engine/inc/renderer/3d/pipeline/static/core/programs/as_is/stapip_as_is_tc_vu1_program.hpp @@ -12,18 +12,18 @@ #include #include -#include "../../stdpip_vu1_program.hpp" +#include "../../stapip_vu1_program.hpp" namespace Tyra { -class StdpipAsIsTCVU1Program : public StdpipVU1Program { +class StaPipAsIsTCVU1Program : public StaPipVU1Program { public: - StdpipAsIsTCVU1Program(); - ~StdpipAsIsTCVU1Program(); + StaPipAsIsTCVU1Program(); + ~StaPipAsIsTCVU1Program(); std::string getStringName() const; void addProgramQBufferDataToPacket(packet2_t* packet, - StdpipQBuffer* qbuffer) const; + StaPipQBuffer* qbuffer) const; }; } // namespace Tyra diff --git a/engine/inc/renderer/3d/pipeline/std/core/path1/programs/cull/stdpip_cull_c_vu1_program.hpp b/engine/inc/renderer/3d/pipeline/static/core/programs/as_is/stapip_as_is_td_vu1_program.hpp similarity index 71% rename from engine/inc/renderer/3d/pipeline/std/core/path1/programs/cull/stdpip_cull_c_vu1_program.hpp rename to engine/inc/renderer/3d/pipeline/static/core/programs/as_is/stapip_as_is_td_vu1_program.hpp index 4979595..2d98e3b 100644 --- a/engine/inc/renderer/3d/pipeline/std/core/path1/programs/cull/stdpip_cull_c_vu1_program.hpp +++ b/engine/inc/renderer/3d/pipeline/static/core/programs/as_is/stapip_as_is_td_vu1_program.hpp @@ -12,18 +12,18 @@ #include #include -#include "../../stdpip_vu1_program.hpp" +#include "../../stapip_vu1_program.hpp" namespace Tyra { -class StdpipCullCVU1Program : public StdpipVU1Program { +class StaPipAsIsTDVU1Program : public StaPipVU1Program { public: - StdpipCullCVU1Program(); - ~StdpipCullCVU1Program(); + StaPipAsIsTDVU1Program(); + ~StaPipAsIsTDVU1Program(); std::string getStringName() const; void addProgramQBufferDataToPacket(packet2_t* packet, - StdpipQBuffer* qbuffer) const; + StaPipQBuffer* qbuffer) const; }; } // namespace Tyra diff --git a/engine/inc/renderer/3d/pipeline/std/core/path1/programs/cull/stdpip_cull_d_vu1_program.hpp b/engine/inc/renderer/3d/pipeline/static/core/programs/cull/stapip_cull_c_vu1_program.hpp similarity index 67% rename from engine/inc/renderer/3d/pipeline/std/core/path1/programs/cull/stdpip_cull_d_vu1_program.hpp rename to engine/inc/renderer/3d/pipeline/static/core/programs/cull/stapip_cull_c_vu1_program.hpp index 1d77e12..ff4bb4a 100644 --- a/engine/inc/renderer/3d/pipeline/std/core/path1/programs/cull/stdpip_cull_d_vu1_program.hpp +++ b/engine/inc/renderer/3d/pipeline/static/core/programs/cull/stapip_cull_c_vu1_program.hpp @@ -12,18 +12,18 @@ #include #include -#include "../../stdpip_vu1_program.hpp" +#include "../../stapip_vu1_program.hpp" namespace Tyra { -class StdpipCullDVU1Program : public StdpipVU1Program { +class StaPipCullCVU1Program : public StaPipVU1Program { public: - StdpipCullDVU1Program(); - ~StdpipCullDVU1Program(); + StaPipCullCVU1Program(); + ~StaPipCullCVU1Program(); std::string getStringName() const; void addProgramQBufferDataToPacket(packet2_t* packet, - StdpipQBuffer* qbuffer) const; + StaPipQBuffer* qbuffer) const; }; } // namespace Tyra diff --git a/engine/inc/renderer/3d/pipeline/static/core/programs/cull/stapip_cull_d_vu1_program.hpp b/engine/inc/renderer/3d/pipeline/static/core/programs/cull/stapip_cull_d_vu1_program.hpp new file mode 100644 index 0000000..c1d35d7 --- /dev/null +++ b/engine/inc/renderer/3d/pipeline/static/core/programs/cull/stapip_cull_d_vu1_program.hpp @@ -0,0 +1,29 @@ +/* +# ______ ____ ___ +# | \/ ____| |___| +# | | | \ | | +#----------------------------------------------------------------------- +# Copyright 2022, tyra - https://github.com/h4570/tyra +# Licenced under Apache License 2.0 +# Sandro Sobczyński +*/ + +#pragma once + +#include +#include +#include "../../stapip_vu1_program.hpp" + +namespace Tyra { + +class StaPipCullDVU1Program : public StaPipVU1Program { + public: + StaPipCullDVU1Program(); + ~StaPipCullDVU1Program(); + + std::string getStringName() const; + void addProgramQBufferDataToPacket(packet2_t* packet, + StaPipQBuffer* qbuffer) const; +}; + +} // namespace Tyra diff --git a/engine/inc/renderer/3d/pipeline/std/core/path1/programs/as_is/stdpip_as_is_td_vu1_program.hpp b/engine/inc/renderer/3d/pipeline/static/core/programs/cull/stapip_cull_tc_vu1_program.hpp similarity index 67% rename from engine/inc/renderer/3d/pipeline/std/core/path1/programs/as_is/stdpip_as_is_td_vu1_program.hpp rename to engine/inc/renderer/3d/pipeline/static/core/programs/cull/stapip_cull_tc_vu1_program.hpp index 8c45f9a..b8d35d3 100644 --- a/engine/inc/renderer/3d/pipeline/std/core/path1/programs/as_is/stdpip_as_is_td_vu1_program.hpp +++ b/engine/inc/renderer/3d/pipeline/static/core/programs/cull/stapip_cull_tc_vu1_program.hpp @@ -12,18 +12,18 @@ #include #include -#include "../../stdpip_vu1_program.hpp" +#include "../../stapip_vu1_program.hpp" namespace Tyra { -class StdpipAsIsTDVU1Program : public StdpipVU1Program { +class StaPipCullTCVU1Program : public StaPipVU1Program { public: - StdpipAsIsTDVU1Program(); - ~StdpipAsIsTDVU1Program(); + StaPipCullTCVU1Program(); + ~StaPipCullTCVU1Program(); std::string getStringName() const; void addProgramQBufferDataToPacket(packet2_t* packet, - StdpipQBuffer* qbuffer) const; + StaPipQBuffer* qbuffer) const; }; } // namespace Tyra diff --git a/engine/inc/renderer/3d/pipeline/static/core/programs/cull/stapip_cull_td_vu1_program.hpp b/engine/inc/renderer/3d/pipeline/static/core/programs/cull/stapip_cull_td_vu1_program.hpp new file mode 100644 index 0000000..cc0406d --- /dev/null +++ b/engine/inc/renderer/3d/pipeline/static/core/programs/cull/stapip_cull_td_vu1_program.hpp @@ -0,0 +1,29 @@ +/* +# ______ ____ ___ +# | \/ ____| |___| +# | | | \ | | +#----------------------------------------------------------------------- +# Copyright 2022, tyra - https://github.com/h4570/tyra +# Licenced under Apache License 2.0 +# Sandro Sobczyński +*/ + +#pragma once + +#include +#include +#include "../../stapip_vu1_program.hpp" + +namespace Tyra { + +class StaPipCullTDVU1Program : public StaPipVU1Program { + public: + StaPipCullTDVU1Program(); + ~StaPipCullTDVU1Program(); + + std::string getStringName() const; + void addProgramQBufferDataToPacket(packet2_t* packet, + StaPipQBuffer* qbuffer) const; +}; + +} // namespace Tyra diff --git a/engine/inc/renderer/3d/pipeline/static/core/programs/stapip_vu1_shared_defines.h b/engine/inc/renderer/3d/pipeline/static/core/programs/stapip_vu1_shared_defines.h new file mode 100644 index 0000000..712c07a --- /dev/null +++ b/engine/inc/renderer/3d/pipeline/static/core/programs/stapip_vu1_shared_defines.h @@ -0,0 +1,24 @@ +// +// ______ ____ ___ +// | \/ ____| |___| +// | | | \ | | +//----------------------------------------------------------------------- +// Copyright 2022, tyra - https://github.com/h4570/tyra +// Licenced under Apache License 2.0 +// Sandro Sobczyński +// + +// 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 diff --git a/engine/inc/renderer/3d/pipeline/std/core/path1/stdpip_clipper.hpp b/engine/inc/renderer/3d/pipeline/static/core/stapip_clipper.hpp similarity index 68% rename from engine/inc/renderer/3d/pipeline/std/core/path1/stdpip_clipper.hpp rename to engine/inc/renderer/3d/pipeline/static/core/stapip_clipper.hpp index ab598e9..28ddd43 100644 --- a/engine/inc/renderer/3d/pipeline/std/core/path1/stdpip_clipper.hpp +++ b/engine/inc/renderer/3d/pipeline/static/core/stapip_clipper.hpp @@ -12,9 +12,9 @@ #include #include "debug/debug.hpp" -#include "./stdpip_qbuffer.hpp" +#include "./stapip_qbuffer.hpp" #include "renderer/renderer_settings.hpp" -#include "renderer/core/paths/path1/clipper/path1_ee_clip_algorithm.hpp" +#include "renderer/core/3d/clipper/ee_clip_algorithm.hpp" namespace Tyra { @@ -25,23 +25,23 @@ namespace Tyra { * 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 { +class StaPipClipper { public: - StdpipClipper(); - ~StdpipClipper(); - void clip(StdpipQBuffer* buffer); + StaPipClipper(); + ~StaPipClipper(); + void clip(StaPipQBuffer* buffer); void init(const RendererSettings& settings); void setMaxVertCount(const u32& count); void setMVP(M4x4* mvp); private: u32 maxVertCount; - Path1EEClipAlgorithm algorithm; + EEClipAlgorithm algorithm; M4x4* mvp; - void perspectiveDivide(std::vector* vertices); - void moveDataToBuffer(const std::vector& vertices, - StdpipQBuffer* buffer); + void perspectiveDivide(std::vector* vertices); + void moveDataToBuffer(const std::vector& vertices, + StaPipQBuffer* buffer); }; } // namespace Tyra diff --git a/engine/inc/renderer/3d/pipeline/std/core/std_pipeline_core.hpp b/engine/inc/renderer/3d/pipeline/static/core/stapip_core.hpp similarity index 54% rename from engine/inc/renderer/3d/pipeline/std/core/std_pipeline_core.hpp rename to engine/inc/renderer/3d/pipeline/static/core/stapip_core.hpp index 9b44486..6c95766 100644 --- a/engine/inc/renderer/3d/pipeline/std/core/std_pipeline_core.hpp +++ b/engine/inc/renderer/3d/pipeline/static/core/stapip_core.hpp @@ -11,23 +11,25 @@ #pragma once #include -#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" +#include "./bag/stapip_bag.hpp" +#include "./bag/packaging/stapip_bag_packages_bbox.hpp" +#include "./bag/packaging/stapip_bag_package.hpp" +#include "./bag/packaging/stapip_bag_packager.hpp" +#include "./stapip_qbuffer_renderer.hpp" +#include "renderer/3d/pipeline/shared/pipeline_frustum_culling.hpp" namespace Tyra { -class StdPipelineCore { +class StaPipCore { public: - StdPipelineCore(); - ~StdPipelineCore(); + StaPipCore(); + ~StaPipCore(); void init(RendererCore* t_core); - /** Render 3D data via "bags" */ - void render(StdpipBag* data, StdpipBagPackagesBBox* bbox = nullptr); + /** Render 3D via "bags" */ + void render(StaPipBag* bag, const bool& frustumCull, + StaPipBagPackagesBBox* bbox = nullptr); /** Get max vert count of VU1 qbuffer (for optimizations) */ u32 getMaxVertCountByParams(const bool& isSingleColor, @@ -35,7 +37,7 @@ class StdPipelineCore { const bool& isTextureEnabled); /** Get max vert count of VU1 qbuffer (for optimizations) */ - u32 getMaxVertCountByBag(const StdpipBag* bag); + u32 getMaxVertCountByBag(const StaPipBag* bag); /** * - Uploads standard VU1 programs. @@ -43,17 +45,20 @@ class StdPipelineCore { * - Sets double buffers exactly for "Tyra Renderer3D" * Should be called if VU1 was used by your non standard programs. */ - void reinitStandardVU1Programs(); + void reinitVU1Programs(); + + void allocateOnUse() { qbufferRenderer.allocateOnUse(); } + void deallocateOnUse() { qbufferRenderer.deallocateOnUse(); } 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); + StaPipBagPackager packager; + StaPipQBufferRenderer qbufferRenderer; + void renderPkgs(StaPipBagPackage* packages, const bool& doClip, u16 count); + void renderSubpkgs(StaPipBagPackage* packages, u16 count); }; } // namespace Tyra diff --git a/engine/inc/renderer/3d/pipeline/std/core/path1/stdpip_program_name.hpp b/engine/inc/renderer/3d/pipeline/static/core/stapip_program_name.hpp similarity index 59% rename from engine/inc/renderer/3d/pipeline/std/core/path1/stdpip_program_name.hpp rename to engine/inc/renderer/3d/pipeline/static/core/stapip_program_name.hpp index 4eba03f..cddf586 100644 --- a/engine/inc/renderer/3d/pipeline/std/core/path1/stdpip_program_name.hpp +++ b/engine/inc/renderer/3d/pipeline/static/core/stapip_program_name.hpp @@ -12,20 +12,20 @@ namespace Tyra { -enum StdpipProgramName { - StdipUndefinedProgram, +enum StaPipProgramName { + StaPipUndefinedProgram, - StdpipCullColor, - StdpipAsIsColor, + StaPipCullColor, + StaPipAsIsColor, - StdpipCullDirLights, - StdpipAsIsDirLights, + StaPipCullDirLights, + StaPipAsIsDirLights, - StdpipCullTextureDirLights, - StdpipAsIsTextureDirLights, + StaPipCullTextureDirLights, + StaPipAsIsTextureDirLights, - StdpipCullTextureColor, - StdpipAsIsTextureColor, + StaPipCullTextureColor, + StaPipAsIsTextureColor, }; } // namespace Tyra diff --git a/engine/inc/renderer/3d/pipeline/std/core/path1/stdpip_program_type.hpp b/engine/inc/renderer/3d/pipeline/static/core/stapip_program_type.hpp similarity index 75% rename from engine/inc/renderer/3d/pipeline/std/core/path1/stdpip_program_type.hpp rename to engine/inc/renderer/3d/pipeline/static/core/stapip_program_type.hpp index 3618c56..cde8d83 100644 --- a/engine/inc/renderer/3d/pipeline/std/core/path1/stdpip_program_type.hpp +++ b/engine/inc/renderer/3d/pipeline/static/core/stapip_program_type.hpp @@ -12,11 +12,11 @@ namespace Tyra { -enum StdpipProgramType { - StdpipVU1Color, - StdpipVU1DirLights, - StdpipVU1TextureDirLights, - StdpipVU1TextureColor, +enum StaPipProgramType { + StaPipVU1Color, + StaPipVU1DirLights, + StaPipVU1TextureDirLights, + StaPipVU1TextureColor, }; } // namespace Tyra diff --git a/engine/inc/renderer/3d/pipeline/static/core/stapip_programs_repository.hpp b/engine/inc/renderer/3d/pipeline/static/core/stapip_programs_repository.hpp new file mode 100644 index 0000000..1d6639e --- /dev/null +++ b/engine/inc/renderer/3d/pipeline/static/core/stapip_programs_repository.hpp @@ -0,0 +1,46 @@ +/* +# ______ ____ ___ +# | \/ ____| |___| +# | | | \ | | +#----------------------------------------------------------------------- +# Copyright 2022, tyra - https://github.com/h4570/tyra +# Licenced under Apache License 2.0 +# Sandro Sobczyński +*/ + +#pragma once + +#include "debug/debug.hpp" +#include "renderer/core/paths/path1/vu1_program.hpp" + +#include "./programs/as_is/stapip_as_is_c_vu1_program.hpp" +#include "./programs/as_is/stapip_as_is_d_vu1_program.hpp" +#include "./programs/as_is/stapip_as_is_td_vu1_program.hpp" +#include "./programs/as_is/stapip_as_is_tc_vu1_program.hpp" + +#include "./programs/cull/stapip_cull_c_vu1_program.hpp" +#include "./programs/cull/stapip_cull_d_vu1_program.hpp" +#include "./programs/cull/stapip_cull_td_vu1_program.hpp" +#include "./programs/cull/stapip_cull_tc_vu1_program.hpp" + +namespace Tyra { + +class StaPipProgramsRepository { + public: + StaPipProgramsRepository(); + ~StaPipProgramsRepository(); + + StaPipVU1Program* getProgram(const StaPipProgramName& name); + + private: + StaPipAsIsCVU1Program asIsColor; + StaPipCullCVU1Program cullColor; + StaPipAsIsDVU1Program asIsDirLights; + StaPipCullDVU1Program cullDirLights; + StaPipAsIsTDVU1Program asIsTextureDirLights; + StaPipCullTDVU1Program cullTextureDirLights; + StaPipAsIsTCVU1Program asIsTextureColor; + StaPipCullTCVU1Program cullTextureColor; +}; + +} // namespace Tyra diff --git a/engine/inc/renderer/3d/pipeline/std/core/path1/stdpip_qbuffer.hpp b/engine/inc/renderer/3d/pipeline/static/core/stapip_qbuffer.hpp similarity index 72% rename from engine/inc/renderer/3d/pipeline/std/core/path1/stdpip_qbuffer.hpp rename to engine/inc/renderer/3d/pipeline/static/core/stapip_qbuffer.hpp index 588f3bc..e873e63 100644 --- a/engine/inc/renderer/3d/pipeline/std/core/path1/stdpip_qbuffer.hpp +++ b/engine/inc/renderer/3d/pipeline/static/core/stapip_qbuffer.hpp @@ -12,17 +12,16 @@ #include #include -#include #include "debug/debug.hpp" -#include "../bag/packaging/stdpip_bag_package.hpp" -#include "../bag/stdpip_bag.hpp" +#include "./bag/packaging/stapip_bag_package.hpp" +#include "./bag/stapip_bag.hpp" namespace Tyra { -class StdpipQBuffer { +class StaPipQBuffer { public: - StdpipQBuffer(); - ~StdpipQBuffer(); + StaPipQBuffer(); + ~StaPipQBuffer(); void setMaxVertCount(const u32& count); @@ -30,27 +29,27 @@ class StdpipQBuffer { * @brief Dont allocate any dynamic data in buffer. * Just copy pointers to input data. */ - void fillByPointer(const StdpipBagPackage& pkg); + void fillByPointer(const StaPipBagPackage& pkg); /** * @brief Allocate dynamic data in buffer * And copy input data to it. */ - void fillByCopyMax(const StdpipBagPackage& pkg1, const StdpipBagPackage& pkg2, - const StdpipBagPackage& pkg3); + void fillByCopyMax(const StaPipBagPackage& pkg1, const StaPipBagPackage& pkg2, + const StaPipBagPackage& pkg3); /** * @brief Allocate dynamic data in buffer * And copy input data to it. */ - void fillByCopy1By2(const StdpipBagPackage& pkg1, - const StdpipBagPackage& pkg2); + void fillByCopy1By2(const StaPipBagPackage& pkg1, + const StaPipBagPackage& pkg2); /** * @brief Allocate dynamic data in buffer * And copy input data to it. */ - void fillByCopy1By3(const StdpipBagPackage& pkg); + void fillByCopy1By3(const StaPipBagPackage& pkg); /** * @brief Deallocate dynamic data if it was allocated and allocate new data @@ -61,7 +60,7 @@ class StdpipQBuffer { bool any() const; - StdpipBag* bag; + StaPipBag* bag; Vec4* vertices; Vec4* sts; @@ -77,7 +76,7 @@ class StdpipQBuffer { private: u32 maxVertCount; void deallocateDynamicData(); - void allocateDynamicData(u16 size, StdpipBag* bag); + void allocateDynamicData(u16 size, StaPipBag* bag); u8 _isDynamicallyAllocated, _stAllocated, _colorAllocated, _normalAllocated; }; diff --git a/engine/inc/renderer/3d/pipeline/std/core/path1/stdpip_qbuffer_renderer.hpp b/engine/inc/renderer/3d/pipeline/static/core/stapip_qbuffer_renderer.hpp similarity index 50% rename from engine/inc/renderer/3d/pipeline/std/core/path1/stdpip_qbuffer_renderer.hpp rename to engine/inc/renderer/3d/pipeline/static/core/stapip_qbuffer_renderer.hpp index 150a028..4db373e 100644 --- a/engine/inc/renderer/3d/pipeline/std/core/path1/stdpip_qbuffer_renderer.hpp +++ b/engine/inc/renderer/3d/pipeline/static/core/stapip_qbuffer_renderer.hpp @@ -17,21 +17,21 @@ #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 "./stapip_qbuffer.hpp" +#include "./stapip_program_type.hpp" +#include "./stapip_program_name.hpp" +#include "./stapip_programs_repository.hpp" +#include "./stapip_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 { +class StaPipQBufferRenderer { public: - StdpipQBufferRenderer(); - ~StdpipQBufferRenderer(); + StaPipQBufferRenderer(); + ~StaPipQBufferRenderer(); void init(RendererCore* t_core); @@ -39,59 +39,73 @@ class StdpipQBufferRenderer { void setClipperMVP(M4x4* mvp) { clipper.setMVP(mvp); } - StdpipQBuffer* getBuffer(); + StaPipQBuffer* getBuffer(); - void sendObjectData(StdpipBag* bag, M4x4* mvp, + void sendObjectData(StaPipBag* bag, M4x4* mvp, RendererCoreTextureBuffers* texBuffers) const; void setMaxVertCount(const u32& count); - void setInfo(StdpipInfoBag* bag); + void setInfo(PipelineInfoBag* bag); /** Fast render with culling */ - void cull(StdpipQBuffer* buffer); + void cull(StaPipQBuffer* buffer); /** Slower render with clipping */ - void clip(StdpipQBuffer* buffer); + void clip(StaPipQBuffer* buffer); + + void flushBuffers(); void clearLastProgramName(); - StdpipVU1Program* getCullProgramByBag(const StdpipBag* bag); + StaPipVU1Program* getCullProgramByBag(const StaPipBag* bag); - StdpipVU1Program* getCullProgramByParams(const bool& isLightingEnabled, + StaPipVU1Program* getCullProgramByParams(const bool& isLightingEnabled, const bool& isTextureEnabled); const u16& getBufferSize() { return bufferSize; } + void allocateOnUse(); + void deallocateOnUse(); + private: + bool is1stDBufferFlushTime(); + bool is2ndDBufferFlushTime(); + void sendStaticData() const; void setProgramsCache(); void uploadPrograms(); void setDoubleBuffer(); + u16 getQBufferIndex(StaPipQBuffer* buffer); + u16 qbuffersPacketSize; - StdpipVU1Program* getProgramByName(const StdpipProgramName& name); - void addBufferDataToPacket(StdpipVU1Program* program, StdpipQBuffer* buffer); + static const u16 buffersCount; + + StaPipVU1Program* getProgramByName(const StaPipProgramName& name); + void addBufferDataToPacket(StaPipQBuffer** buffers, const u32& count); void sendPacket(); - StdpipVU1Program* getAsIsProgramByBag(const StdpipBag* bag); - StdpipVU1Program* getCullProgramByType(const StdpipProgramType& programType); - StdpipProgramType getDrawProgramTypeByBag(const StdpipBag* bag) const; - StdpipProgramType getDrawProgramTypeByParams( + StaPipVU1Program* getAsIsProgramByBag(const StaPipBag* bag); + StaPipVU1Program* getCullProgramByType(const StaPipProgramType& programType); + StaPipProgramType getDrawProgramTypeByBag(const StaPipBag* bag) const; + StaPipProgramType getDrawProgramTypeByParams( const bool& isLightingEnabled, const bool& isTextureEnabled) const; - packet2_t* packets[2]; packet2_t* programsPacket; - StdpipQBuffer buffers[2]; + + packet2_t** packets; + StaPipVU1Program** dBufferPrograms; + StaPipQBuffer** buffers; packet2_t* currentPacket; packet2_t* staticDataPacket; packet2_t* objectDataPacket; RendererCore* rendererCore; - StdpipProgramName lastProgramName; + StaPipProgramName lastProgramName; Path1* path1; - StdpipClipper clipper; - StdpipProgramsRepository repository; + StaPipClipper clipper; + StaPipProgramsRepository repository; - u16 bufferSize; + u16 bufferSize, nextBufferIndex, currentBufferIndex; u8 context; }; diff --git a/engine/inc/renderer/3d/pipeline/std/core/path1/stdpip_vu1_program.hpp b/engine/inc/renderer/3d/pipeline/static/core/stapip_vu1_program.hpp similarity index 65% rename from engine/inc/renderer/3d/pipeline/std/core/path1/stdpip_vu1_program.hpp rename to engine/inc/renderer/3d/pipeline/static/core/stapip_vu1_program.hpp index c2cecba..b4b5eb4 100644 --- a/engine/inc/renderer/3d/pipeline/std/core/path1/stdpip_vu1_program.hpp +++ b/engine/inc/renderer/3d/pipeline/static/core/stapip_vu1_program.hpp @@ -10,40 +10,40 @@ #pragma once -#include "./stdpip_program_name.hpp" +#include "./stapip_program_name.hpp" #include "renderer/core/paths/path1/vu1_program.hpp" -#include "./stdpip_qbuffer.hpp" -#include "./programs/stdpip_vu1_shared_defines.h" +#include "./stapip_qbuffer.hpp" +#include "./programs/stapip_vu1_shared_defines.h" namespace Tyra { -class StdpipVU1Program : public VU1Program { +class StaPipVU1Program : public VU1Program { public: - StdpipVU1Program(const StdpipProgramName& name, u32* start, u32* end, + StaPipVU1Program(const StaPipProgramName& name, u32* start, u32* end, const u32& t_reglist, const u8& t_reglistCount, const u8& t_elementsPerVertex); - ~StdpipVU1Program(); + ~StaPipVU1Program(); u32& getReglist(); - const StdpipProgramName& getName() const; + const StaPipProgramName& getName() const; u16 getMaxVertCount(const bool& singleColorEnabled, const u16& vu1DBufferSize) const; - void addBufferDataToPacket(packet2_t* packet, StdpipQBuffer* buffer, + void addBufferDataToPacket(packet2_t* packet, StaPipQBuffer* buffer, prim_t* prim); protected: - StdpipProgramName name; + StaPipProgramName name; u8 reglistCount, elementsPerVertex; u32 destinationAddress, reglist; virtual void addProgramQBufferDataToPacket(packet2_t* packet, - StdpipQBuffer* qbuffer) const = 0; + StaPipQBuffer* qbuffer) const = 0; private: - void addStandardBufferDataToPacket(packet2_t* packet, StdpipQBuffer* buffer, + void addStandardBufferDataToPacket(packet2_t* packet, StaPipQBuffer* buffer, prim_t* prim); }; diff --git a/engine/inc/renderer/3d/pipeline/static/stapip_options.hpp b/engine/inc/renderer/3d/pipeline/static/stapip_options.hpp new file mode 100644 index 0000000..90c23c2 --- /dev/null +++ b/engine/inc/renderer/3d/pipeline/static/stapip_options.hpp @@ -0,0 +1,33 @@ +/* +# ______ ____ ___ +# | \/ ____| |___| +# | | | \ | | +#----------------------------------------------------------------------- +# Copyright 2022, tyra - https://github.com/h4570/tyra +# Licenced under Apache License 2.0 +# Sandro Sobczyński +*/ + +#pragma once + +#include "renderer/3d/pipeline/shared/pipeline_options.hpp" + +namespace Tyra { + +class StaPipOptions : public PipelineOptions { + public: + StaPipOptions() { fullClipChecks = false; } + ~StaPipOptions() {} + + /** + * @brief False -> disables "clip against each plane" algorithm. + * Mandatory, default: True. + * + * Full clip checks are slow, but they are + * preventing visual artifacts, which can happen + * for big 3D objects (or objects near camera eyes) + */ + bool fullClipChecks; +}; + +} // namespace Tyra diff --git a/engine/inc/renderer/3d/pipeline/static/static_pipeline.hpp b/engine/inc/renderer/3d/pipeline/static/static_pipeline.hpp new file mode 100644 index 0000000..1131bc0 --- /dev/null +++ b/engine/inc/renderer/3d/pipeline/static/static_pipeline.hpp @@ -0,0 +1,74 @@ +/* +# ______ ____ ___ +# | \/ ____| |___| +# | | | \ | | +#----------------------------------------------------------------------- +# Copyright 2022, tyra - https://github.com/h4570/tyra +# Licenced under Apache License 2.0 +# Sandro Sobczyński +*/ + +#pragma once + +#include +#include "../renderer_3d_pipeline.hpp" +#include "../shared/pipeline_lighting_options.hpp" +#include "renderer/core/renderer_core.hpp" +#include "renderer/3d/mesh/static/static_mesh.hpp" +#include "./core/stapip_core.hpp" +#include "./stapip_options.hpp" + +namespace Tyra { + +/** + * Pipeline for static models (StaticMesh). + * Supports: + * - Full "against each plane" clipping and simple PS2 clipping + * (fullClipChecks), + * - Force enabled precise frustum culling (checks parts of given mesh) + * - Modes: color(s), texture+color(s), dir lights, texture + dir lights + */ +class StaticPipeline : public Renderer3DPipeline { + public: + StaticPipeline(); + ~StaticPipeline(); + + StaPipCore core; + + void setRenderer(RendererCore* core); + + void onUse(); + + void onUseEnd(); + + /** + * Render static model + * This render() method is a bridge to core.render() method. + */ + void render(StaticMesh* mesh, const StaPipOptions* options = nullptr); + + private: + RendererCore* rendererCore; + Vec4* colorsCache; + + void addVertices(MeshMaterialFrame* materialFrame, StaPipBag* bag) const; + + PipelineInfoBag* getInfoBag(StaticMesh* mesh, const StaPipOptions* options, + M4x4* model) const; + + StaPipColorBag* getColorBag(MeshMaterial* material, + MeshMaterialFrame* materialFrame) const; + + StaPipTextureBag* getTextureBag(MeshMaterial* material, + MeshMaterialFrame* materialFrame); + + StaPipLightingBag* getLightingBag(MeshMaterialFrame* materialFrame, + M4x4* model, + const StaPipOptions* options) const; + + void deallocDrawBags(StaPipBag* bag, MeshMaterial* material) const; + + void setLightingColorsCache(PipelineLightingOptions* lightingOptions); +}; + +} // namespace Tyra diff --git a/engine/inc/renderer/3d/pipeline/std/core/path1/programs/cull/stdpip_cull_tc_vu1_program.hpp b/engine/inc/renderer/3d/pipeline/std/core/path1/programs/cull/stdpip_cull_tc_vu1_program.hpp deleted file mode 100644 index e1d62f6..0000000 --- a/engine/inc/renderer/3d/pipeline/std/core/path1/programs/cull/stdpip_cull_tc_vu1_program.hpp +++ /dev/null @@ -1,29 +0,0 @@ -/* -# ______ ____ ___ -# | \/ ____| |___| -# | | | \ | | -#----------------------------------------------------------------------- -# Copyright 2022, tyra - https://github.com/h4570/tyra -# Licenced under Apache License 2.0 -# Sandro Sobczyński -*/ - -#pragma once - -#include -#include -#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 diff --git a/engine/inc/renderer/3d/pipeline/std/core/path1/programs/cull/stdpip_cull_td_vu1_program.hpp b/engine/inc/renderer/3d/pipeline/std/core/path1/programs/cull/stdpip_cull_td_vu1_program.hpp deleted file mode 100644 index 5da4969..0000000 --- a/engine/inc/renderer/3d/pipeline/std/core/path1/programs/cull/stdpip_cull_td_vu1_program.hpp +++ /dev/null @@ -1,29 +0,0 @@ -/* -# ______ ____ ___ -# | \/ ____| |___| -# | | | \ | | -#----------------------------------------------------------------------- -# Copyright 2022, tyra - https://github.com/h4570/tyra -# Licenced under Apache License 2.0 -# Sandro Sobczyński -*/ - -#pragma once - -#include -#include -#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 diff --git a/engine/inc/renderer/3d/pipeline/std/core/path1/stdpip_programs_repository.hpp b/engine/inc/renderer/3d/pipeline/std/core/path1/stdpip_programs_repository.hpp deleted file mode 100644 index 26ef7e2..0000000 --- a/engine/inc/renderer/3d/pipeline/std/core/path1/stdpip_programs_repository.hpp +++ /dev/null @@ -1,49 +0,0 @@ -/* -# ______ ____ ___ -# | \/ ____| |___| -# | | | \ | | -#----------------------------------------------------------------------- -# Copyright 2022, tyra - https://github.com/h4570/tyra -# Licenced under Apache License 2.0 -# Sandro Sobczyński -*/ - -#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 diff --git a/engine/inc/renderer/3d/pipeline/std/std_pipeline.hpp b/engine/inc/renderer/3d/pipeline/std/std_pipeline.hpp deleted file mode 100644 index 44c87d3..0000000 --- a/engine/inc/renderer/3d/pipeline/std/std_pipeline.hpp +++ /dev/null @@ -1,59 +0,0 @@ -/* -# ______ ____ ___ -# | \/ ____| |___| -# | | | \ | | -#----------------------------------------------------------------------- -# Copyright 2022, tyra - https://github.com/h4570/tyra -# Licenced under Apache License 2.0 -# Sandro Sobczyński -*/ - -#pragma once - -#include -#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 diff --git a/engine/inc/renderer/core/3d/bbox/core_bbox.hpp b/engine/inc/renderer/core/3d/bbox/core_bbox.hpp index 711ec69..0d2f4a5 100644 --- a/engine/inc/renderer/core/3d/bbox/core_bbox.hpp +++ b/engine/inc/renderer/core/3d/bbox/core_bbox.hpp @@ -11,6 +11,7 @@ #pragma once #include +#include #include "./core_bbox_frustum.hpp" #include "math/m4x4.hpp" #include "math/plane.hpp" diff --git a/engine/inc/renderer/core/paths/path1/clipper/path1_ee_clip_algorithm.hpp b/engine/inc/renderer/core/3d/clipper/ee_clip_algorithm.hpp similarity index 54% rename from engine/inc/renderer/core/paths/path1/clipper/path1_ee_clip_algorithm.hpp rename to engine/inc/renderer/core/3d/clipper/ee_clip_algorithm.hpp index bcca06c..631a76c 100644 --- a/engine/inc/renderer/core/paths/path1/clipper/path1_ee_clip_algorithm.hpp +++ b/engine/inc/renderer/core/3d/clipper/ee_clip_algorithm.hpp @@ -11,42 +11,42 @@ #pragma once #include -#include "./path1_clip_vertex.hpp" +#include "./ee_clip_vertex.hpp" #include "debug/debug.hpp" #include "renderer/renderer_settings.hpp" namespace Tyra { -struct Path1EEClipAlgorithmSettings { +struct EEClipAlgorithmSettings { bool lerpNormals, lerpTexCoords, lerpColors; }; -class Path1EEClipAlgorithm { +class EEClipAlgorithm { public: - Path1EEClipAlgorithm(); - ~Path1EEClipAlgorithm(); + EEClipAlgorithm(); + ~EEClipAlgorithm(); void init(const RendererSettings& settings); - void clip(std::vector* o_vertices, - const std::vector& vertices, - const Path1EEClipAlgorithmSettings& settings); + void clip(std::vector* o_vertices, + const std::vector& vertices, + const EEClipAlgorithmSettings& settings); static float clipMargin; private: float halfWidth, halfHeight, near, far; - std::vector tempVertices; + std::vector tempVertices; - float getValueByPlane(const Path1ClipVertex& v, const int& plane); + float getValueByPlane(const EEClipVertex& v, const int& plane); bool isInside(const int& plane, const float& v, const float& w, const float& planeLimitValue); - void clipAgainstPlane(const std::vector& original, - std::vector* clipped, const int& plane, + void clipAgainstPlane(const std::vector& original, + std::vector* clipped, const int& plane, const float& planeLimitValue, - const Path1EEClipAlgorithmSettings& settings); + const EEClipAlgorithmSettings& settings); }; } // namespace Tyra diff --git a/engine/inc/renderer/core/paths/path1/clipper/path1_clip_vertex.hpp b/engine/inc/renderer/core/3d/clipper/ee_clip_vertex.hpp similarity index 94% rename from engine/inc/renderer/core/paths/path1/clipper/path1_clip_vertex.hpp rename to engine/inc/renderer/core/3d/clipper/ee_clip_vertex.hpp index f9d6f3c..b55dc7c 100644 --- a/engine/inc/renderer/core/paths/path1/clipper/path1_clip_vertex.hpp +++ b/engine/inc/renderer/core/3d/clipper/ee_clip_vertex.hpp @@ -14,7 +14,7 @@ namespace Tyra { -struct Path1ClipVertex { +struct EEClipVertex { Vec4 position, normal, st, color; }; diff --git a/engine/inc/renderer/core/3d/renderer_3d_frustum_planes.hpp b/engine/inc/renderer/core/3d/renderer_3d_frustum_planes.hpp index 3b4ab6d..94ee7b8 100644 --- a/engine/inc/renderer/core/3d/renderer_3d_frustum_planes.hpp +++ b/engine/inc/renderer/core/3d/renderer_3d_frustum_planes.hpp @@ -10,7 +10,7 @@ #pragma once -#include +#include #include "renderer/renderer_settings.hpp" #include "./camera_info_3d.hpp" #include "math/plane.hpp" diff --git a/engine/inc/renderer/core/texture/models/texture_bpp.hpp b/engine/inc/renderer/core/texture/models/texture_bpp.hpp index 69bd7df..32c748f 100644 --- a/engine/inc/renderer/core/texture/models/texture_bpp.hpp +++ b/engine/inc/renderer/core/texture/models/texture_bpp.hpp @@ -14,29 +14,29 @@ namespace Tyra { enum TextureBpp { - // Tyra has 1.3MB~ free VRAM for textures. + // Tyra has 2.27MB~ free VRAM for textures. /** * @brief 32-bit RGBA - Slowest - * Tyra can cache about 4~ of these textures (256x256) + * Tyra can cache about 8~ of these textures (256x256) */ bpp32 = 32, /** * @brief 24-bit RGB - Slow - * Tyra can cache about 6~ of these textures (256x256) + * Tyra can cache about 11~ of these textures (256x256) */ bpp24 = 24, /** * @brief 8-bit palletized (indexed) - Super fast - * Tyra can cache about 19~ of these textures (256x256) + * Tyra can cache about 34~ of these textures (256x256) */ bpp8 = 8, /** * @brief 4-bit palletized (indexed) - Super, super fast - * Tyra can cache about 39~ of these textures (256x256) + * Tyra can cache about 69~ of these textures (256x256) */ bpp4 = 4, }; diff --git a/engine/inc/renderer/core/texture/texture_repository.hpp b/engine/inc/renderer/core/texture/texture_repository.hpp index 9ff627d..e4a7ed5 100644 --- a/engine/inc/renderer/core/texture/texture_repository.hpp +++ b/engine/inc/renderer/core/texture/texture_repository.hpp @@ -36,31 +36,19 @@ class TextureRepository { * For 3D: MeshMaterial id. * For 2D: Sprite id. */ - Texture* getBySpriteOrMesh(const u32& t_id) { - for (u32 i = 0; i < textures.size(); i++) - if (textures[i]->isLinkedWith(t_id)) return textures[i]; - return nullptr; - } + Texture* getBySpriteOrMesh(const u32& t_id) const; /** * Returns single texture. * nullptr if not found. */ - Texture* getByTextureId(const u32& t_id) const { - for (u32 i = 0; i < textures.size(); i++) - if (t_id == textures[i]->getId()) return textures[i]; - return nullptr; - } + Texture* getByTextureId(const u32& t_id) const; /** * Returns index of link. * -1 if not found. */ - const s32 getIndexOf(const u32& t_texId) const { - for (u32 i = 0; i < textures.size(); i++) - if (textures[i]->getId() == t_texId) return i; - return -1; - } + const s32 getIndexOf(const u32& t_texId) const; // ---- // Setters @@ -107,19 +95,19 @@ class TextureRepository { * Remove texture from repository. * Texture is NOT destructed. */ - void removeByIndex(const u32& t_index) { - textures.erase(textures.begin() + t_index); - } + void removeByIndex(const u32& t_index); /** * Remove texture from repository. * Texture is NOT destructed. */ - const void removeById(const u32& t_texId) { - s32 index = getIndexOf(t_texId); - TYRA_ASSERT(index != -1, "Cant remove texture, because it was not found!"); - removeByIndex(index); - } + void removeById(const u32& t_texId); + + /** + * Remove texture from repository. + * Texture IS destructed. + */ + void free(const u32& t_texId); private: std::vector textures; diff --git a/engine/inc/renderer/renderer_settings.hpp b/engine/inc/renderer/renderer_settings.hpp index f696329..3317c7d 100644 --- a/engine/inc/renderer/renderer_settings.hpp +++ b/engine/inc/renderer/renderer_settings.hpp @@ -33,6 +33,11 @@ class RendererSettings { const float& getProjectionScale() const { return projectionScale; } const float& getAspectRatio() const { return aspectRatio; } + float getInterlacedHeightF() const { return getHeight() / 2; } + unsigned int getInterlacedHeightUI() const { + return static_cast(getInterlacedHeightF()); + } + static void copy(RendererSettings* out, const RendererSettings* in); void set(const RendererSettings& v); diff --git a/engine/src/loaders/3d/builder/mesh_builder_frame_data.cpp b/engine/src/loaders/3d/builder/mesh_builder_frame_data.cpp index c8f0b4e..e7d7513 100644 --- a/engine/src/loaders/3d/builder/mesh_builder_frame_data.cpp +++ b/engine/src/loaders/3d/builder/mesh_builder_frame_data.cpp @@ -24,7 +24,20 @@ MeshBuilderFrameData::MeshBuilderFrameData() { colorsCount = 0; } -MeshBuilderFrameData::~MeshBuilderFrameData() {} +MeshBuilderFrameData::~MeshBuilderFrameData() { + if (vertices) { + delete[] vertices; + } + if (normals) { + delete[] normals; + } + if (textureCoords) { + delete[] textureCoords; + } + if (colors) { + delete[] colors; + } +} void MeshBuilderFrameData::allocateTextureCoords(const u32& count) { textureCoordsCount = count; diff --git a/engine/src/loaders/3d/builder/mesh_builder_material_data.cpp b/engine/src/loaders/3d/builder/mesh_builder_material_data.cpp index 712daec..7eff1e7 100644 --- a/engine/src/loaders/3d/builder/mesh_builder_material_data.cpp +++ b/engine/src/loaders/3d/builder/mesh_builder_material_data.cpp @@ -22,7 +22,20 @@ MeshBuilderMaterialData::MeshBuilderMaterialData() { count = 0; } -MeshBuilderMaterialData::~MeshBuilderMaterialData() {} +MeshBuilderMaterialData::~MeshBuilderMaterialData() { + if (vertexFaces) { + delete[] vertexFaces; + } + if (textureCoordFaces) { + delete[] textureCoordFaces; + } + if (normalFaces) { + delete[] normalFaces; + } + if (colorFaces) { + delete[] colorFaces; + } +} void MeshBuilderMaterialData::allocateFaces(const u32& t_count) { vertexFaces = new u32[t_count]; diff --git a/engine/src/math/m4x4.cpp b/engine/src/math/m4x4.cpp index bf61b01..d87910e 100644 --- a/engine/src/math/m4x4.cpp +++ b/engine/src/math/m4x4.cpp @@ -9,7 +9,7 @@ */ #include -#include +#include #include #include "math/m4x4.hpp" diff --git a/engine/src/math/plane.cpp b/engine/src/math/plane.cpp index d0b97d8..696d813 100644 --- a/engine/src/math/plane.cpp +++ b/engine/src/math/plane.cpp @@ -8,8 +8,9 @@ # Sandro Sobczyński */ -#include #include "math/vec4.hpp" +#include +#include #include "math/plane.hpp" namespace Tyra { diff --git a/engine/src/math/vec2.cpp b/engine/src/math/vec2.cpp index 68613dc..808180d 100644 --- a/engine/src/math/vec2.cpp +++ b/engine/src/math/vec2.cpp @@ -9,6 +9,7 @@ */ #include "math/vec2.hpp" +#include namespace Tyra { diff --git a/engine/src/math/vec4.cpp b/engine/src/math/vec4.cpp index d53320a..8d7d9ef 100644 --- a/engine/src/math/vec4.cpp +++ b/engine/src/math/vec4.cpp @@ -9,6 +9,9 @@ */ #include "math/vec4.hpp" +#include +#include +#include namespace Tyra { diff --git a/engine/src/renderer/3d/mesh/dynamic/dynamic_mesh.cpp b/engine/src/renderer/3d/mesh/dynamic/dynamic_mesh.cpp new file mode 100644 index 0000000..0df1454 --- /dev/null +++ b/engine/src/renderer/3d/mesh/dynamic/dynamic_mesh.cpp @@ -0,0 +1,112 @@ + +/* +# ______ ____ ___ +# | \/ ____| |___| +# | | | \ | | +#----------------------------------------------------------------------- +# Copyright 2020, tyra - https://github.com/h4570/tyra +# Licenced under Apache License 2.0 +# Sandro Sobczyński +*/ + +#include +#include "math/m4x4.hpp" +#include "renderer/3d/mesh/dynamic/dynamic_mesh.hpp" + +namespace Tyra { + +DynamicMesh::DynamicMesh(const MeshBuilderData& data) : Mesh(data) { + TYRA_ASSERT(framesCount > 1, "Frames count must be greater than 1"); + + framesCount = data.framesCount; + + frames = new MeshFrame*[framesCount]; + for (u32 i = 0; i < framesCount; i++) { + frames[i] = new MeshFrame(data, i); + } + + initAnimation(); +} + +DynamicMesh::DynamicMesh(const DynamicMesh& mesh) : Mesh(mesh) { + framesCount = mesh.framesCount; + + frames = new MeshFrame*[framesCount]; + for (u32 i = 0; i < framesCount; i++) { + frames[i] = new MeshFrame(*mesh.frames[i]); + } + + initAnimation(); +} + +DynamicMesh::~DynamicMesh() { + for (u32 i = 0; i < framesCount; i++) { + delete frames[i]; + } + delete[] frames; +} + +void DynamicMesh::initAnimation() { + animState.startFrame = 0; + animState.endFrame = 0; + animState.interpolation = 0.0F; + animState.animType = 0; + animState.currentFrame = 0; + animState.stayFrame = 0; + animState.isStayFrameSet = false; + animState.nextFrame = 0; + animState.speed = 0.1F; +} + +void DynamicMesh::playAnimation(const u32& t_startFrame, + const u32& t_endFrame) { + TYRA_ASSERT(framesCount > 0, + "Cant play animation, because no mesh data was loaded!"); + TYRA_ASSERT(framesCount != 1, + "Cant play animation, because this mesh have only one frame."); + TYRA_ASSERT( + t_endFrame < framesCount, + "End frame value is too high. Valid range: (0, getFramesCount()-1)"); + animState.startFrame = t_startFrame; + animState.endFrame = t_endFrame; + if (animState.currentFrame == t_startFrame) + animState.nextFrame = t_endFrame; + else + animState.nextFrame = t_startFrame; +} + +void DynamicMesh::playAnimation(const u32& t_startFrame, const u32& t_endFrame, + const u32& t_stayFrame) { + TYRA_ASSERT(framesCount > 0, + "Cant play animation, because no mesh data was loaded!"); + TYRA_ASSERT(framesCount != 1, + "Cant play animation, because this mesh have only one frame."); + TYRA_ASSERT( + t_endFrame < framesCount, + "End frame value is too high. Valid range: (0, getFramesCount()-1)"); + animState.startFrame = t_startFrame; + animState.endFrame = t_endFrame; + animState.isStayFrameSet = true; + animState.stayFrame = t_stayFrame; + animState.nextFrame = t_startFrame; +} + +void DynamicMesh::animate() { + animState.interpolation += animState.speed; + if (animState.interpolation >= 1.0F) { + animState.interpolation = 0.0F; + animState.currentFrame = animState.nextFrame; + if (++animState.nextFrame > animState.endFrame) { + if (animState.isStayFrameSet) { + animState.isStayFrameSet = false; + animState.nextFrame = animState.stayFrame; + animState.startFrame = animState.stayFrame; + animState.endFrame = animState.stayFrame; + } else { + animState.nextFrame = animState.startFrame; + } + } + } +} + +} // namespace Tyra diff --git a/engine/src/renderer/3d/mesh/mesh.cpp b/engine/src/renderer/3d/mesh/mesh.cpp index 78d30e8..942b425 100644 --- a/engine/src/renderer/3d/mesh/mesh.cpp +++ b/engine/src/renderer/3d/mesh/mesh.cpp @@ -1,144 +1,65 @@ - -/* -# ______ ____ ___ -# | \/ ____| |___| -# | | | \ | | -#----------------------------------------------------------------------- -# Copyright 2020, tyra - https://github.com/h4570/tyra -# Licenced under Apache License 2.0 -# Sandro Sobczyński -*/ - -#include -#include "math/m4x4.hpp" -#include "renderer/3d/mesh/mesh.hpp" - -namespace Tyra { - -Mesh::Mesh(const MeshBuilderData& data) { - id = rand() % 1000000; - - framesCount = data.framesCount; - TYRA_ASSERT(framesCount > 0, "Frames count must be greater than 0"); - - materialsCount = data.materialsCount; - TYRA_ASSERT(materialsCount > 0, "Materials count must be greater than 0"); - - frames = new MeshFrame*[framesCount]; - for (u32 i = 0; i < framesCount; i++) { - frames[i] = new MeshFrame(data, i); - } - - materials = new MeshMaterial*[materialsCount]; - for (u32 i = 0; i < materialsCount; i++) { - materials[i] = new MeshMaterial(data, i); - } - - translation.translate(Vec4(0.0F, 0.0F, 0.0F, 1.0F)); - - initMesh(); - - _isMother = true; -} - -Mesh::Mesh(const Mesh& mesh) { - id = rand() % 1000000; - - framesCount = mesh.framesCount; - materialsCount = mesh.materialsCount; - - frames = new MeshFrame*[framesCount]; - for (u32 i = 0; i < framesCount; i++) { - frames[i] = new MeshFrame(*mesh.frames[i]); - } - - materials = new MeshMaterial*[materialsCount]; - for (u32 i = 0; i < materialsCount; i++) { - materials[i] = new MeshMaterial(*mesh.materials[i]); - } - - translation.translate(Vec4(0.0F, 0.0F, 0.0F, 1.0F)); - - initMesh(); - - _isMother = false; -} - -Mesh::~Mesh() { - for (u32 i = 0; i < framesCount; i++) { - delete frames[i]; - } - delete[] frames; - - for (u32 i = 0; i < materialsCount; i++) { - delete materials[i]; - - delete[] materials; - } -} - -M4x4 Mesh::getModelMatrix() const { return translation * rotation * scale; } - -void Mesh::initMesh() { - animState.startFrame = 0; - animState.endFrame = 0; - animState.interpolation = 0.0F; - animState.animType = 0; - animState.currentFrame = 0; - animState.stayFrame = 0; - animState.isStayFrameSet = false; - animState.nextFrame = 0; - animState.speed = 0.1F; -} - -void Mesh::playAnimation(const u32& t_startFrame, const u32& t_endFrame) { - TYRA_ASSERT(framesCount > 0, - "Cant play animation, because no mesh data was loaded!"); - TYRA_ASSERT(framesCount != 1, - "Cant play animation, because this mesh have only one frame."); - TYRA_ASSERT( - t_endFrame < framesCount, - "End frame value is too high. Valid range: (0, getFramesCount()-1)"); - animState.startFrame = t_startFrame; - animState.endFrame = t_endFrame; - if (animState.currentFrame == t_startFrame) - animState.nextFrame = t_endFrame; - else - animState.nextFrame = t_startFrame; -} - -void Mesh::playAnimation(const u32& t_startFrame, const u32& t_endFrame, - const u32& t_stayFrame) { - TYRA_ASSERT(framesCount > 0, - "Cant play animation, because no mesh data was loaded!"); - TYRA_ASSERT(framesCount != 1, - "Cant play animation, because this mesh have only one frame."); - TYRA_ASSERT( - t_endFrame < framesCount, - "End frame value is too high. Valid range: (0, getFramesCount()-1)"); - animState.startFrame = t_startFrame; - animState.endFrame = t_endFrame; - animState.isStayFrameSet = true; - animState.stayFrame = t_stayFrame; - animState.nextFrame = t_startFrame; -} - -void Mesh::animate() { - animState.interpolation += animState.speed; - if (animState.interpolation >= 1.0F) { - animState.interpolation = 0.0F; - animState.currentFrame = animState.nextFrame; - if (++animState.nextFrame > animState.endFrame) { - if (animState.isStayFrameSet) { - animState.isStayFrameSet = false; - animState.nextFrame = animState.stayFrame; - animState.startFrame = animState.stayFrame; - animState.endFrame = animState.stayFrame; - } else { - animState.nextFrame = animState.startFrame; - } - } - } -} - -} // namespace Tyra + +/* +# ______ ____ ___ +# | \/ ____| |___| +# | | | \ | | +#----------------------------------------------------------------------- +# Copyright 2020, tyra - https://github.com/h4570/tyra +# Licenced under Apache License 2.0 +# Sandro Sobczyński +*/ + +#include "renderer/3d/mesh/mesh.hpp" + +namespace Tyra { + +Mesh::Mesh(const MeshBuilderData& data) { + init(); + + TYRA_ASSERT(data.materialsCount > 0, + "Materials count must be greater than 0"); + + materialsCount = data.materialsCount; + materials = new MeshMaterial*[materialsCount]; + + for (u32 i = 0; i < materialsCount; i++) { + materials[i] = new MeshMaterial(data, i); + } + + _isMother = true; +} + +Mesh::Mesh(const Mesh& mesh) { + init(); + + materialsCount = mesh.materialsCount; + materials = new MeshMaterial*[materialsCount]; + + for (u32 i = 0; i < materialsCount; i++) { + materials[i] = new MeshMaterial(*mesh.materials[i]); + } + + _isMother = false; +} + +M4x4 Mesh::getModelMatrix() const { return translation * rotation * scale; } + +Mesh::~Mesh() { + for (u32 i = 0; i < materialsCount; i++) { + delete materials[i]; + } + delete[] materials; +} + +void Mesh::init() { + id = rand() % 1000000; + materialsCount = 0; + translation.translate(Vec4(0.0F, 0.0F, 0.0F, 1.0F)); +} + +void Mesh::setPosition(const Vec4& v) { + TYRA_ASSERT(v.w == 1.0F, "Vec4 must be homogeneous"); + reinterpret_cast(&translation.data[3 * 4])->set(v); +} + +} // namespace Tyra diff --git a/engine/src/renderer/3d/mesh/mesh_frame.cpp b/engine/src/renderer/3d/mesh/mesh_frame.cpp index 4e5219b..a3e8b47 100644 --- a/engine/src/renderer/3d/mesh/mesh_frame.cpp +++ b/engine/src/renderer/3d/mesh/mesh_frame.cpp @@ -11,6 +11,7 @@ #include "debug/debug.hpp" #include +#include #include #include "math/vec4.hpp" #include "renderer/models/color.hpp" @@ -24,38 +25,6 @@ MeshFrame::MeshFrame(const MeshBuilderData& data, const u32& index) { id = rand() % 1000000; - vertices = data.frames[index]->vertices; - TYRA_ASSERT(vertices != nullptr, "Vertices are required"); - vertexCount = data.frames[index]->verticesCount; - TYRA_ASSERT(vertexCount > 0, "Vertices count must be greater than 0"); - - if (data.normalsEnabled) { - normals = data.frames[index]->normals; - normalsCount = data.frames[index]->normalsCount; - TYRA_ASSERT(normals != nullptr, "Normals are required"); - } else { - normalsCount = 0; - normals = nullptr; - } - - if (data.textureCoordsEnabled) { - textureCoords = data.frames[index]->textureCoords; - textureCoordsCount = data.frames[index]->textureCoordsCount; - TYRA_ASSERT(textureCoords != nullptr, "Texture coordinates are required"); - } else { - textureCoordsCount = 0; - textureCoords = nullptr; - } - - if (data.manyColorsEnabled) { - colors = data.frames[index]->colors; - colorsCount = data.frames[index]->colorsCount; - TYRA_ASSERT(colors != nullptr, "Colors are required"); - } else { - colorsCount = 0; - colors = nullptr; - } - bbox = new BBox(data.frames[index]->vertices, data.frames[index]->verticesCount); @@ -65,16 +34,6 @@ MeshFrame::MeshFrame(const MeshBuilderData& data, const u32& index) { MeshFrame::MeshFrame(const MeshFrame& frame) { id = rand() % 1000000; - vertices = frame.vertices; - normals = frame.normals; - textureCoords = frame.textureCoords; - colors = frame.colors; - - vertexCount = frame.vertexCount; - normalsCount = frame.normalsCount; - textureCoordsCount = frame.textureCoordsCount; - colorsCount = frame.colorsCount; - bbox = frame.bbox; _isMother = false; @@ -82,10 +41,6 @@ MeshFrame::MeshFrame(const MeshFrame& frame) { MeshFrame::~MeshFrame() { if (_isMother) { - delete[] vertices; - if (normals) delete[] normals; - if (textureCoords) delete[] textureCoords; - if (colors) delete[] colors; delete bbox; } } @@ -108,40 +63,9 @@ std::string MeshFrame::getPrint(const char* name) const { res << "MeshFrame("; } res << std::fixed << std::setprecision(2); - + res << "Id: " << id << ", " << std::endl; - res << "VertexCount: " << vertexCount << ", " << std::endl; - res << "NormalsCount: " << normalsCount << ", " << std::endl; - res << "TextureCoordsCount: " << textureCoordsCount << ", " << std::endl; - res << "ColorsCount: " << colorsCount << ", " << std::endl; res << "BBox: " << bbox->getPrint() << ", " << std::endl; - - res << "Vertices: "; - for (u32 i = 0; i < vertexCount; i++) { - res << vertices[i].getPrint() << ", " << std::endl; - } - - if (normals) { - res << "Normals: "; - for (u32 i = 0; i < normalsCount; i++) { - res << normals[i].getPrint() << ", " << std::endl; - } - } - - if (textureCoords) { - res << "TextureCoords: "; - for (u32 i = 0; i < textureCoordsCount; i++) { - res << textureCoords[i].getPrint() << ", " << std::endl; - } - } - - if (colors) { - res << "Colors: "; - for (u32 i = 0; i < colorsCount; i++) { - res << colors[i].getPrint() << ", " << std::endl; - } - } - res << ")"; return res.str(); diff --git a/engine/src/renderer/3d/mesh/mesh_material.cpp b/engine/src/renderer/3d/mesh/mesh_material.cpp index d0087df..8c583d5 100644 --- a/engine/src/renderer/3d/mesh/mesh_material.cpp +++ b/engine/src/renderer/3d/mesh/mesh_material.cpp @@ -12,49 +12,27 @@ #include #include #include +#include #include "renderer/3d/mesh/mesh_material.hpp" namespace Tyra { MeshMaterial::MeshMaterial(const MeshBuilderData& data, const u32& materialIndex) - : singleColor(false) { + : color(false) { TYRA_ASSERT(materialIndex < data.materialsCount && materialIndex >= 0, "Provided index \"", materialIndex, "\" is out of range"); id = rand() % 1000000; - vertexFaces = data.materials[materialIndex]->vertexFaces; - TYRA_ASSERT(vertexFaces != nullptr, "Vertex faces are required"); - - if (data.textureCoordsEnabled) { - textureCoordFaces = data.materials[materialIndex]->textureCoordFaces; - TYRA_ASSERT(textureCoordFaces != nullptr, - "Texture coord faces are required"); - } else { - textureCoordFaces = nullptr; - } - - if (data.normalsEnabled) { - normalFaces = data.materials[materialIndex]->normalFaces; - TYRA_ASSERT(normalFaces != nullptr, "Normal faces are required"); - } else { - normalFaces = nullptr; - } - if (data.manyColorsEnabled) { - colorFaces = data.materials[materialIndex]->colorFaces; singleColorFlag = false; - TYRA_ASSERT(colorFaces != nullptr, "Colors faces are required"); + TYRA_ASSERT(data.frames[0]->colors != nullptr, "Colors faces are required"); } else { - colorFaces = nullptr; singleColorFlag = true; } - singleColor.set(128.0F, 128.0F, 128.0F, 128.0F); - - facesCount = data.materials[materialIndex]->count; - TYRA_ASSERT(facesCount > 0, "Faces count must be greater than 0"); + color.set(128.0F, 128.0F, 128.0F, 128.0F); _name = data.materials[materialIndex]->name; TYRA_ASSERT(_name.length() > 0, "MeshMaterial name cannot be empty"); @@ -71,16 +49,11 @@ MeshMaterial::MeshMaterial(const MeshBuilderData& data, MeshMaterial::MeshMaterial(const MeshMaterial& mesh) { id = rand() % 1000000; - vertexFaces = mesh.vertexFaces; - textureCoordFaces = mesh.textureCoordFaces; - normalFaces = mesh.normalFaces; - colorFaces = mesh.colorFaces; - - facesCount = mesh.facesCount; + singleColorFlag = mesh.singleColorFlag; framesCount = mesh.framesCount; _name = mesh._name; - singleColor.set(128.0F, 128.0F, 128.0F, 128.0F); + color.set(128.0F, 128.0F, 128.0F, 128.0F); frames = new MeshMaterialFrame*[framesCount]; for (u32 i = 0; i < framesCount; i++) { @@ -91,13 +64,6 @@ MeshMaterial::MeshMaterial(const MeshMaterial& mesh) { } MeshMaterial::~MeshMaterial() { - if (_isMother) { - delete[] vertexFaces; - if (textureCoordFaces) delete[] textureCoordFaces; - if (normalFaces) delete[] normalFaces; - if (colorFaces) delete[] colorFaces; - } - for (u32 i = 0; i < framesCount; i++) { delete frames[i]; } @@ -110,7 +76,7 @@ const BBox& MeshMaterial::getBBox(const u32& frame) const { void MeshMaterial::setSingleColorFlag(const u8& flag) { TYRA_ASSERT( - colorFaces != nullptr, + frames[0]->getColors() != nullptr, "Colors and color faces are required to use color-per-vertex mode"); singleColorFlag = flag; @@ -138,39 +104,8 @@ std::string MeshMaterial::getPrint(const char* name) const { res << std::fixed << std::setprecision(2); res << "Id: " << id << ", " << std::endl; res << "Name: " << _name << ", " << std::endl; - res << "FacesCount: " << facesCount << ", " << std::endl; - res << "FramesCount: " << framesCount << ", " << std::endl; - - res << "vertexFaces: " << std::endl; - for (u32 i = 0; i < facesCount; i++) { - res << vertexFaces[i] << ", "; - if (i % 3 == 2) res << std::endl; - } - - if (textureCoordFaces) { - res << "TextureCoordFaces: " << std::endl; - for (u32 i = 0; i < facesCount; i++) { - res << textureCoordFaces[i] << ", "; - if (i % 3 == 2) res << std::endl; - } - } - - if (normalFaces) { - res << "NormalFaces: " << std::endl; - for (u32 i = 0; i < facesCount; i++) { - res << normalFaces[i] << ", "; - if (i % 3 == 2) res << std::endl; - } - } - - if (colorFaces) { - res << "ColorFaces: " << std::endl; - for (u32 i = 0; i < facesCount; i++) { - res << colorFaces[i] << ", "; - if (i % 3 == 2) res << std::endl; - } - } - + res << "Frames count: " << framesCount << ", " << std::endl; + res << "Single color?: " << static_cast(singleColorFlag) << std::endl; res << ")"; return res.str(); diff --git a/engine/src/renderer/3d/mesh/mesh_material_frame.cpp b/engine/src/renderer/3d/mesh/mesh_material_frame.cpp index f4e8519..d151cb5 100644 --- a/engine/src/renderer/3d/mesh/mesh_material_frame.cpp +++ b/engine/src/renderer/3d/mesh/mesh_material_frame.cpp @@ -11,6 +11,8 @@ #include "debug/debug.hpp" #include +#include +#include #include "renderer/models/color.hpp" #include "loaders/3d/builder/mesh_builder_data.hpp" #include "renderer/3d/mesh/mesh_material_frame.hpp" @@ -31,12 +33,24 @@ MeshMaterialFrame::MeshMaterialFrame(const MeshBuilderData& data, data.materials[materialIndex]->vertexFaces, data.materials[materialIndex]->count); + allocateVertices(data, frameIndex, materialIndex); + allocateNormals(data, frameIndex, materialIndex); + allocateTextureCoords(data, frameIndex, materialIndex); + allocateColors(data, frameIndex, materialIndex); + _isMother = true; } MeshMaterialFrame::MeshMaterialFrame(const MeshMaterialFrame& frame) { id = rand() % 1000000; + vertexCount = frame.vertexCount; + + vertices = frame.vertices; + normals = frame.normals; + textureCoords = frame.textureCoords; + colors = frame.colors; + bbox = frame.bbox; _isMother = false; @@ -44,8 +58,124 @@ MeshMaterialFrame::MeshMaterialFrame(const MeshMaterialFrame& frame) { MeshMaterialFrame::~MeshMaterialFrame() { if (_isMother) { + delete[] vertices; + if (normals) delete[] normals; + if (textureCoords) delete[] textureCoords; + if (colors) delete[] colors; delete bbox; } } +std::string MeshMaterialFrame::getPrint(const char* name) const { + std::stringstream res; + if (name) { + res << name << "("; + } else { + res << "MeshMaterialFrame("; + } + res << std::fixed << std::setprecision(2); + + res << "Id: " << id << ", " << std::endl; + res << "Vertex count: " << vertexCount << ", " << std::endl; + res << "BBox: " << bbox->getPrint() << ", " << std::endl; + + res << "Vertices: "; + for (u32 i = 0; i < vertexCount; i++) { + res << vertices[i].getPrint() << ", " << std::endl; + } + + if (normals) { + res << "Normals: "; + for (u32 i = 0; i < vertexCount; i++) { + res << normals[i].getPrint() << ", " << std::endl; + } + } + + if (textureCoords) { + res << "TextureCoords: "; + for (u32 i = 0; i < vertexCount; i++) { + res << textureCoords[i].getPrint() << ", " << std::endl; + } + } + + if (colors) { + res << "Colors: "; + for (u32 i = 0; i < vertexCount; i++) { + res << colors[i].getPrint() << ", " << std::endl; + } + } + + res << ")"; + + return res.str(); +} + +void MeshMaterialFrame::allocateVertices(const MeshBuilderData& data, + const u32& frameIndex, + const u32& materialIndex) { + vertexCount = data.materials[materialIndex]->count; // faces count + vertices = new Vec4[vertexCount]; + + TYRA_ASSERT(vertexCount > 0, "Vertex count must be greater than 0"); + + auto* rolled = data.frames[frameIndex]->vertices; + auto* faces = data.materials[materialIndex]->vertexFaces; + + TYRA_ASSERT(rolled != nullptr, "Vertices are required"); + TYRA_ASSERT(faces != nullptr, "Vertex faces are required"); + + for (u32 i = 0; i < vertexCount; i++) vertices[i] = rolled[faces[i]]; +} + +void MeshMaterialFrame::allocateTextureCoords(const MeshBuilderData& data, + const u32& frameIndex, + const u32& materialIndex) { + textureCoords = nullptr; + if (!data.textureCoordsEnabled) return; + + textureCoords = new Vec4[vertexCount]; + + auto* rolled = data.frames[frameIndex]->textureCoords; + auto* faces = data.materials[materialIndex]->textureCoordFaces; + + TYRA_ASSERT(rolled != nullptr, "Texture coordinates are required"); + TYRA_ASSERT(faces != nullptr, "Texture coordinate faces are required"); + + for (u32 i = 0; i < vertexCount; i++) textureCoords[i] = rolled[faces[i]]; +} + +void MeshMaterialFrame::allocateNormals(const MeshBuilderData& data, + const u32& frameIndex, + const u32& materialIndex) { + normals = nullptr; + if (!data.normalsEnabled) return; + + normals = new Vec4[vertexCount]; + + auto* rolled = data.frames[frameIndex]->normals; + auto* faces = data.materials[materialIndex]->normalFaces; + + TYRA_ASSERT(rolled != nullptr, "Normals are required"); + TYRA_ASSERT(faces != nullptr, "Normal faces are required"); + + for (u32 i = 0; i < vertexCount; i++) normals[i] = rolled[faces[i]]; +} + +void MeshMaterialFrame::allocateColors(const MeshBuilderData& data, + const u32& frameIndex, + const u32& materialIndex) { + colors = nullptr; + if (!data.manyColorsEnabled) return; + + colors = new Color[vertexCount]; + + auto* rolled = data.frames[frameIndex]->colors; + auto* faces = data.materials[materialIndex]->colorFaces; + + TYRA_ASSERT(rolled != nullptr, "Colors are required"); + TYRA_ASSERT(faces != nullptr, "Color faces are required"); + + for (u32 i = 0; i < vertexCount; i++) colors[i] = rolled[faces[i]]; +} + } // namespace Tyra diff --git a/engine/src/renderer/3d/mesh/static/static_mesh.cpp b/engine/src/renderer/3d/mesh/static/static_mesh.cpp new file mode 100644 index 0000000..e1b4392 --- /dev/null +++ b/engine/src/renderer/3d/mesh/static/static_mesh.cpp @@ -0,0 +1,32 @@ + +/* +# ______ ____ ___ +# | \/ ____| |___| +# | | | \ | | +#----------------------------------------------------------------------- +# Copyright 2020, tyra - https://github.com/h4570/tyra +# Licenced under Apache License 2.0 +# Sandro Sobczyński +*/ + +#include "renderer/3d/mesh/static/static_mesh.hpp" + +namespace Tyra { + +StaticMesh::StaticMesh(const MeshBuilderData& data) : Mesh(data) { + TYRA_ASSERT(data.framesCount > 0, "Frames count must be greater than 0"); + + if (data.framesCount > 1) + TYRA_WARN("Static meshes should have only one frame, but ", + data.framesCount, " frames were found"); + + frame = new MeshFrame(data, 0); +} + +StaticMesh::StaticMesh(const StaticMesh& mesh) : Mesh(mesh) { + frame = new MeshFrame(*mesh.frame); +} + +StaticMesh::~StaticMesh() { delete frame; } + +} // namespace Tyra diff --git a/engine/src/renderer/3d/pipeline/dynamic/core/bag/dynpip_bag.cpp b/engine/src/renderer/3d/pipeline/dynamic/core/bag/dynpip_bag.cpp new file mode 100644 index 0000000..0578573 --- /dev/null +++ b/engine/src/renderer/3d/pipeline/dynamic/core/bag/dynpip_bag.cpp @@ -0,0 +1,87 @@ +/* +# ______ ____ ___ +# | \/ ____| |___| +# | | | \ | | +#----------------------------------------------------------------------- +# Copyright 2022, tyra - https://github.com/h4570/tyra +# Licenced under Apache License 2.0 +# Sandro Sobczyński +*/ + +#include "renderer/3d/pipeline/dynamic/core/bag/dynpip_bag.hpp" +#include +#include + +namespace Tyra { + +DynPipBag::DynPipBag() { + info = nullptr; + color = nullptr; + texture = nullptr; + lighting = nullptr; + verticesFrom = nullptr; + verticesTo = nullptr; +} + +DynPipBag::~DynPipBag() {} + +void DynPipBag::print() const { + auto text = getPrint(nullptr); + printf("%s\n", text.c_str()); +} + +void DynPipBag::print(const char* name) const { + auto text = getPrint(name); + printf("%s\n", text.c_str()); +} + +std::string DynPipBag::getPrint(const char* name) const { + std::stringstream res; + if (name) { + res << name << "("; + } else { + res << "DynPipBag("; + } + res << std::fixed << std::setprecision(4); + res << std::endl; + res << "Count: " << count << ", " << std::endl; + res << "Vertices from present: " << (verticesFrom != nullptr ? "Yes" : "No") + << ", " << std::endl; + res << "Vertices to present: " << (verticesTo != nullptr ? "Yes" : "No") + << ", " << std::endl; + res << "Info present: " << (info != nullptr ? "Yes" : "No") << ", " + << std::endl; + res << "Color present: " << (color != nullptr ? "Yes" : "No") << ", " + << std::endl; + res << "Texture present: " << (texture != nullptr ? "Yes" : "No") << ", " + << std::endl; + res << "Lighting present: " << (lighting != nullptr ? "Yes" : "No") << ", " + << std::endl; + res << "Model matrix: " << info->model->getPrint() << ", " << std::endl; + if (color->single) { + res << "Color single: " << color->single->getPrint() << ", " << std::endl; + } + if (texture) { + res << "Texture coords from present: " + << (texture->coordinatesFrom != nullptr ? "Yes" : "No") << ", " + << std::endl; + res << "Texture coords to present: " + << (texture->coordinatesTo != nullptr ? "Yes" : "No") << ", " + << std::endl; + res << "Texture: " << texture->texture->getPrint() << ", " << std::endl; + } + + if (lighting) { + res << "Lighting normals from present: " + << (lighting->normalsFrom ? "Yes" : "No") << ", " << std::endl; + res << "Lighting normals to present: " + << (lighting->normalsTo ? "Yes" : "No") << ", " << std::endl; + res << "Lighting matrix: " << lighting->lightMatrix->getPrint() << ", " + << std::endl; + } + res << ")"; + + return res.str(); +} + +} // namespace Tyra diff --git a/engine/src/renderer/3d/pipeline/dynamic/core/bag/dynpip_color_bag.cpp b/engine/src/renderer/3d/pipeline/dynamic/core/bag/dynpip_color_bag.cpp new file mode 100644 index 0000000..e942ef6 --- /dev/null +++ b/engine/src/renderer/3d/pipeline/dynamic/core/bag/dynpip_color_bag.cpp @@ -0,0 +1,19 @@ +/* +# ______ ____ ___ +# | \/ ____| |___| +# | | | \ | | +#----------------------------------------------------------------------- +# Copyright 2022, tyra - https://github.com/h4570/tyra +# Licenced under Apache License 2.0 +# Sandro Sobczyński +*/ + +#include "renderer/3d/pipeline/dynamic/core/bag/dynpip_color_bag.hpp" + +namespace Tyra { + +DynPipColorBag::DynPipColorBag() { single = nullptr; } + +DynPipColorBag::~DynPipColorBag() {} + +} // namespace Tyra diff --git a/engine/src/renderer/3d/pipeline/dynamic/core/bag/dynpip_lighting_bag.cpp b/engine/src/renderer/3d/pipeline/dynamic/core/bag/dynpip_lighting_bag.cpp new file mode 100644 index 0000000..c33b89f --- /dev/null +++ b/engine/src/renderer/3d/pipeline/dynamic/core/bag/dynpip_lighting_bag.cpp @@ -0,0 +1,29 @@ +/* +# ______ ____ ___ +# | \/ ____| |___| +# | | | \ | | +#----------------------------------------------------------------------- +# Copyright 2022, tyra - https://github.com/h4570/tyra +# Licenced under Apache License 2.0 +# Sandro Sobczyński +*/ + +#include "renderer/3d/pipeline/dynamic/core/bag/dynpip_lighting_bag.hpp" + +namespace Tyra { + +DynPipLightingBag::DynPipLightingBag() { + lightMatrix = nullptr; + normalsFrom = nullptr; + normalsTo = nullptr; + dirLights = nullptr; +} + +DynPipLightingBag::~DynPipLightingBag() {} + +void DynPipLightingBag::freeNormals() { + if (normalsFrom) delete[] normalsFrom; + if (normalsTo) delete[] normalsTo; +} + +} // namespace Tyra diff --git a/engine/src/renderer/3d/pipeline/dynamic/core/bag/dynpip_texture_bag.cpp b/engine/src/renderer/3d/pipeline/dynamic/core/bag/dynpip_texture_bag.cpp new file mode 100644 index 0000000..a47a44b --- /dev/null +++ b/engine/src/renderer/3d/pipeline/dynamic/core/bag/dynpip_texture_bag.cpp @@ -0,0 +1,28 @@ +/* +# ______ ____ ___ +# | \/ ____| |___| +# | | | \ | | +#----------------------------------------------------------------------- +# Copyright 2022, tyra - https://github.com/h4570/tyra +# Licenced under Apache License 2.0 +# Sandro Sobczyński +*/ + +#include "renderer/3d/pipeline/dynamic/core/bag/dynpip_texture_bag.hpp" + +namespace Tyra { + +DynPipTextureBag::DynPipTextureBag() { + coordinatesFrom = nullptr; + coordinatesTo = nullptr; + texture = nullptr; +} + +DynPipTextureBag::~DynPipTextureBag() {} + +void DynPipTextureBag::freeCoords() { + if (coordinatesFrom) delete[] coordinatesFrom; + if (coordinatesTo) delete[] coordinatesTo; +} + +} // namespace Tyra diff --git a/engine/src/renderer/3d/pipeline/dynamic/core/dynpip_core.cpp b/engine/src/renderer/3d/pipeline/dynamic/core/dynpip_core.cpp new file mode 100644 index 0000000..5ee7f90 --- /dev/null +++ b/engine/src/renderer/3d/pipeline/dynamic/core/dynpip_core.cpp @@ -0,0 +1,99 @@ +/* +# ______ ____ ___ +# | \/ ____| |___| +# | | | \ | | +#----------------------------------------------------------------------- +# Copyright 2022, tyra - https://github.com/h4570/tyra +# Licenced under Apache License 2.0 +# Sandro Sobczyński +*/ + +#include "renderer/3d/pipeline/dynamic/core/dynpip_core.hpp" +#include +#include +#include "thread/threading.hpp" + +namespace Tyra { + +DynPipCore::DynPipCore() {} + +DynPipCore::~DynPipCore() {} + +void DynPipCore::init(RendererCore* t_core) { + rendererCore = t_core; + qbufferRenderer.init(t_core, &repository); +} + +void DynPipCore::reinitVU1Programs() { qbufferRenderer.reinitVU1(); } + +u32 DynPipCore::getMaxVertCountByParams(const bool& isLightingEnabled, + const bool& isTextureEnabled) { + return repository.getProgramByParams(isLightingEnabled, isTextureEnabled) + ->getMaxVertCount(qbufferRenderer.getBufferSize()); +} + +void DynPipCore::initParts(DynPipBag* bag) { + RendererCoreTextureBuffers* texBuffers = nullptr; + if (bag->texture) { + auto temp = rendererCore->texture.useTexture(bag->texture->texture); + texBuffers = new RendererCoreTextureBuffers{temp.id, temp.core, temp.clut}; + } + + mvp = rendererCore->renderer3D.getViewProj() * *bag->info->model; + + qbufferRenderer.sendObjectData(bag, &mvp, texBuffers); + + delete texBuffers; +} + +void DynPipCore::renderPart(DynPipBag** bags, const u32& count, + const bool& frustumCull) { + if (count <= 0) return; + + TYRA_ASSERT( + bags[0]->verticesFrom != nullptr && bags[0]->verticesTo != nullptr, + "Vertices are required in 3D render bag!"); + TYRA_ASSERT(bags[0]->info != nullptr, + "Info bag is required in 3D render bag!"); + TYRA_ASSERT(bags[0]->info->model != nullptr, + "Info bag's model pointer is empty!"); + TYRA_ASSERT(bags[0]->color != nullptr, + "Color bag is required in 3D render bag!"); + TYRA_ASSERT(bags[0]->color->single, "Color is required in 3D render bag!"); + TYRA_ASSERT( + !bags[0]->lighting || + (bags[0]->lighting->lightMatrix && bags[0]->lighting->normalsFrom && + bags[0]->lighting->normalsTo && bags[0]->lighting->dirLights), + "If you want lighting, please provide light matrix normals and dir " + "lights!"); + TYRA_ASSERT(!bags[0]->texture || (bags[0]->texture->texture && + bags[0]->texture->coordinatesFrom && + bags[0]->texture->coordinatesTo), + "If you want texture, please provide texture and coordinates!"); + + if (!frustumCull) { + qbufferRenderer.render(bags, count); + return; + } + + DynPipBag** bagsToRender = new DynPipBag*[count]; + u32 inserted = 0; + + for (u32 i = 0; i < count; i++) { + auto* bag = bags[i]; + + CoreBBox bbox(bag->verticesTo, bag->count); + if (bbox.isInFrustum(rendererCore->renderer3D.frustumPlanes.getAll(), + *bag->info->model) == + CoreBBoxFrustum::OUTSIDE_FRUSTUM) { + continue; + } + + bagsToRender[inserted++] = bag; + } + + qbufferRenderer.render(bagsToRender, inserted); + delete[] bagsToRender; +} + +} // namespace Tyra diff --git a/engine/src/renderer/3d/pipeline/dynamic/core/dynpip_programs_repository.cpp b/engine/src/renderer/3d/pipeline/dynamic/core/dynpip_programs_repository.cpp new file mode 100644 index 0000000..c47e9f4 --- /dev/null +++ b/engine/src/renderer/3d/pipeline/dynamic/core/dynpip_programs_repository.cpp @@ -0,0 +1,54 @@ +/* +# ______ ____ ___ +# | \/ ____| |___| +# | | | \ | | +#----------------------------------------------------------------------- +# Copyright 2022, tyra - https://github.com/h4570/tyra +# Licenced under Apache License 2.0 +# Sandro Sobczyński +*/ + +#include "renderer/3d/pipeline/dynamic/core/dynpip_programs_repository.hpp" + +namespace Tyra { + +DynPipProgramsRepository::DynPipProgramsRepository() {} + +DynPipProgramsRepository::~DynPipProgramsRepository() {} + +DynPipVU1Program* DynPipProgramsRepository::getProgramByBag( + const DynPipBag* bag) { + return getProgramByParams(bag->lighting, bag->texture); +} + +DynPipVU1Program* DynPipProgramsRepository::getProgramByParams( + const bool& isLightingEnabled, const bool& isTextureEnabled) { + if (isLightingEnabled && isTextureEnabled) + return &textureDirLights; + else if (isLightingEnabled) + return &dirLights; + else if (isTextureEnabled) + return &textureColor; + else + return &color; +} + +DynPipVU1Program* DynPipProgramsRepository::getProgram( + const DynPipProgramName& name) { + switch (name) { + case DynPipProgramName::DynPipColor: + return &color; + case DynPipProgramName::DynPipDirLights: + return &dirLights; + case DynPipProgramName::DynPipTextureDirLights: + return &textureDirLights; + case DynPipProgramName::DynPipTextureColor: + return &textureColor; + + default: + TYRA_TRAP("Unknown VU1 program name"); + return &color; + } +} + +} // namespace Tyra diff --git a/engine/src/renderer/3d/pipeline/dynamic/core/dynpip_renderer.cpp b/engine/src/renderer/3d/pipeline/dynamic/core/dynpip_renderer.cpp new file mode 100644 index 0000000..760290f --- /dev/null +++ b/engine/src/renderer/3d/pipeline/dynamic/core/dynpip_renderer.cpp @@ -0,0 +1,200 @@ +/* +# ______ ____ ___ +# | \/ ____| |___| +# | | | \ | | +#----------------------------------------------------------------------- +# Copyright 2022, tyra - https://github.com/h4570/tyra +# Licenced under Apache License 2.0 +# Sandro Sobczyński +*/ + +#include "renderer/3d/pipeline/dynamic/core/dynpip_renderer.hpp" +#include "renderer/3d/pipeline/dynamic/core/programs/dynpip_vu1_shared_defines.h" +#include + +namespace Tyra { + +DynPipRenderer::DynPipRenderer() { + context = 0; + bufferSize = 0; + lastProgramName = DynPipProgramName::DynPipUndefinedProgram; + + programsPacket = nullptr; +} + +DynPipRenderer::~DynPipRenderer() { + if (programsPacket) packet2_free(programsPacket); +} + +void DynPipRenderer::allocateOnUse(const u32& t_packetSize) { + staticDataPacket = packet2_create(3, P2_TYPE_NORMAL, P2_MODE_CHAIN, true); + objectDataPacket = packet2_create(16, P2_TYPE_NORMAL, P2_MODE_CHAIN, true); + + for (u16 i = 0; i < 2; i++) + packets[i] = + packet2_create(t_packetSize, P2_TYPE_NORMAL, P2_MODE_CHAIN, true); + + sendStaticData(); +} + +void DynPipRenderer::deallocateOnUse() { + packet2_free(staticDataPacket); + packet2_free(objectDataPacket); + + for (u16 i = 0; i < 2; i++) packet2_free(packets[i]); +} + +void DynPipRenderer::init(RendererCore* t_core, + DynPipProgramsRepository* t_programRepo) { + path1 = t_core->getPath1(); + rendererCore = t_core; + programsRepo = t_programRepo; + + dma_channel_initialize(DMA_CHANNEL_VIF1, NULL, 0); + dma_channel_fast_waits(DMA_CHANNEL_VIF1); + + setProgramsCache(); + + reinitVU1(); + + TYRA_LOG("DynPipRenderer initialized"); +} + +void DynPipRenderer::reinitVU1() { + uploadPrograms(); + setDoubleBuffer(); +} + +void DynPipRenderer::setProgramsCache() { + VU1Program** programs = new VU1Program*[4]; + programs[0] = programsRepo->getProgram(DynPipProgramName::DynPipColor); + programs[1] = programsRepo->getProgram(DynPipProgramName::DynPipDirLights); + programs[2] = programsRepo->getProgram(DynPipProgramName::DynPipTextureColor); + programs[3] = + programsRepo->getProgram(DynPipProgramName::DynPipTextureDirLights); + programsPacket = path1->createProgramsCache(programs, 4, 0); + delete[] programs; +} + +void DynPipRenderer::sendStaticData() const { + packet2_reset(staticDataPacket, false); + packet2_utils_vu_open_unpack(staticDataPacket, VU1_SET_GIFTAG_ADDR, false); + { packet2_utils_gif_add_set(staticDataPacket, 1); } + packet2_utils_vu_close_unpack(staticDataPacket); + + packet2_utils_vu_add_end_tag(staticDataPacket); + dma_channel_wait(DMA_CHANNEL_VIF1, 0); + dma_channel_send_packet2(staticDataPacket, DMA_CHANNEL_VIF1, true); +} + +void DynPipRenderer::sendObjectData( + DynPipBag* bag, M4x4* mvp, RendererCoreTextureBuffers* texBuffers) const { + packet2_reset(objectDataPacket, false); + packet2_utils_vu_add_unpack_data(objectDataPacket, VU1_MVP_MATRIX_ADDR, + mvp->data, 4, false); + + if (bag->lighting) { + packet2_utils_vu_add_unpack_data(objectDataPacket, VU1_LIGHTS_MATRIX_ADDR, + bag->lighting->lightMatrix, 3, false); + + packet2_utils_vu_add_unpack_data( + objectDataPacket, VU1_LIGHTS_DIRS_ADDR, + bag->lighting->dirLights->getLightDirections(), 3, false); + + packet2_utils_vu_add_unpack_data(objectDataPacket, VU1_LIGHTS_COLORS_ADDR, + bag->lighting->dirLights->getLightColors(), + 4, false); + } + + u8 singleColorEnabled = bag->color->single != nullptr; + + 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); + + packet2_utils_vu_open_unpack(objectDataPacket, VU1_OPTIONS_ADDR, false); + { + packet2_add_u32(objectDataPacket, + singleColorEnabled); // Single color enabled. + packet2_add_float(objectDataPacket, + bag->interpolation); // Interpolation value + packet2_add_u32(objectDataPacket, 0); // not used, padding + packet2_add_u32(objectDataPacket, 0); // not used, padding + + packet2_utils_gs_add_lod(objectDataPacket, &rendererCore->gs.lod); + + if (texBuffers != nullptr) { + packet2_utils_gs_add_texbuff_clut(objectDataPacket, texBuffers->core, + &rendererCore->texture.clut); + + rendererCore->texture.updateClutBuffer(texBuffers->clut); + } + } + packet2_utils_vu_close_unpack(objectDataPacket); + + packet2_utils_vu_add_end_tag(objectDataPacket); + dma_channel_wait(DMA_CHANNEL_VIF1, 0); + dma_channel_send_packet2(objectDataPacket, DMA_CHANNEL_VIF1, true); +} + +void DynPipRenderer::render(DynPipBag** bags, const u32& count) { + if (count <= 0) return; + + auto* program = programsRepo->getProgramByBag(bags[0]); + addBufferDataToPacket(program, bags, count); + sendPacket(); +} + +void DynPipRenderer::addBufferDataToPacket(DynPipVU1Program* program, + DynPipBag** bags, const u32& count) { + currentPacket = packets[context]; + packet2_reset(currentPacket, false); + + for (u32 i = 0; i < count; i++) { + if (bags[i]->count <= 0) continue; + + program->addBufferDataToPacket(currentPacket, bags[i], + &rendererCore->gs.prim); + + if (lastProgramName != program->getName()) { + packet2_utils_vu_add_start_program(currentPacket, + program->getDestinationAddress()); + lastProgramName = program->getName(); + } else { + packet2_utils_vu_add_continue_program(currentPacket); + } + } + + packet2_utils_vu_add_end_tag(currentPacket); +} + +void DynPipRenderer::sendPacket() { + dma_channel_wait(DMA_CHANNEL_VIF1, 0); + dma_channel_send_packet2(currentPacket, DMA_CHANNEL_VIF1, true); + // Switch packet, so we can proceed during DMA transfer + context = !context; +} + +void DynPipRenderer::clearLastProgramName() { + lastProgramName = DynPipUndefinedProgram; +} + +void DynPipRenderer::uploadPrograms() { + dma_channel_wait(DMA_CHANNEL_VIF1, 0); + dma_channel_send_packet2(programsPacket, DMA_CHANNEL_VIF1, true); + dma_channel_wait(DMA_CHANNEL_VIF1, 0); +} + +void DynPipRenderer::setDoubleBuffer() { + u16 startingAddr = VU1_LAST_ITEM_ADDR + 1; + const u16 bufferMaxSize = 1000; + bufferSize = (bufferMaxSize - startingAddr) / 2; + + path1->setDoubleBuffer(startingAddr, bufferSize); + + bufferSize -= 1; // Because we don't want to upload anything from first + // buffer, to first addr of second buffer +} + +} // namespace Tyra diff --git a/engine/src/renderer/3d/pipeline/dynamic/core/dynpip_vu1_program.cpp b/engine/src/renderer/3d/pipeline/dynamic/core/dynpip_vu1_program.cpp new file mode 100644 index 0000000..6e20408 --- /dev/null +++ b/engine/src/renderer/3d/pipeline/dynamic/core/dynpip_vu1_program.cpp @@ -0,0 +1,79 @@ +/* +# ______ ____ ___ +# | \/ ____| |___| +# | | | \ | | +#----------------------------------------------------------------------- +# Copyright 2022, tyra - https://github.com/h4570/tyra +# Licenced under Apache License 2.0 +# Sandro Sobczyński +*/ + +#include "renderer/3d/pipeline/dynamic/core/dynpip_vu1_program.hpp" + +namespace Tyra { + +DynPipVU1Program::DynPipVU1Program(const DynPipProgramName& t_name, + u32* t_start, u32* t_end, + const u32& t_reglist, + const u8& t_reglistCount, + const u8& t_elementsPerVertex) + : VU1Program(t_start, t_end), + name(t_name), + reglistCount(t_reglistCount), + elementsPerVertex(t_elementsPerVertex), + reglist(t_reglist) { + packetSize = packet2_utils_get_packet_size_for_program(start, end); + programSize = calculateProgramSize(); +} + +DynPipVU1Program::~DynPipVU1Program() {} + +const DynPipProgramName& DynPipVU1Program::getName() const { return name; } + +u32& DynPipVU1Program::getReglist() { return reglist; } + +void DynPipVU1Program::addBufferDataToPacket(packet2_t* packet, DynPipBag* bag, + prim_t* prim) { + addStandardBufferDataToPacket(packet, bag, prim); + addProgramQBufferDataToPacket(packet, bag); +} + +void DynPipVU1Program::addStandardBufferDataToPacket(packet2_t* packet, + DynPipBag* bag, + prim_t* prim) { + if (bag->texture) + prim->mapping = 1; + else + prim->mapping = 0; + + packet2_utils_vu_open_unpack(packet, 0, true); + { + packet2_add_float(packet, 2048.0F); // scale + packet2_add_float(packet, 2048.0F); // scale + packet2_add_float(packet, + static_cast(0xFFFFFF) / 32.0F); // scale + packet2_add_u32(packet, bag->count); // vertex count + + packet2_utils_gs_add_prim_giftag(packet, prim, bag->count, reglist, + reglistCount, 0); + } + packet2_utils_vu_close_unpack(packet); +} + +u16 DynPipVU1Program::getMaxVertCount(const u16& bufferSize) const { + u16 res = bufferSize - 4; + res /= (elementsPerVertex + reglistCount); + + // Buffer size = VU1 double buffer size (xtop) + // QBufferSize = res (it is placed inside VU1) + + // Animation = 2 verts for final vert + res = res / 2; + + // Triangle = 3 verts + res = res / 3; + res = res * 3; + return res; +} + +} // namespace Tyra diff --git a/engine/src/renderer/3d/pipeline/dynamic/core/programs/dynpip_c_vu1.vclpp b/engine/src/renderer/3d/pipeline/dynamic/core/programs/dynpip_c_vu1.vclpp new file mode 100644 index 0000000..273ea2e --- /dev/null +++ b/engine/src/renderer/3d/pipeline/dynamic/core/programs/dynpip_c_vu1.vclpp @@ -0,0 +1,130 @@ +; ______ ____ ___ +; | \/ ____| |___| +; | | | \ | | +;--------------------------------------------------------------- +; Copyright 2022, tyra - https://github.com/h4570/tyra +; Licenced under Apache License 2.0 +; Sandro Sobczyński +; +;--------------------------------------------------------------- +; Triangle list +; Cull = Standard PS2 way. clipw polys are culled. +; Animation +; Color +;--------------------------------------------------------------- + +.syntax new +.name DynPipVU1_C +.vu +.init_vf_all +.init_vi_all + +#include "src/renderer/3d/pipeline/shared/vcl_sml.i" +#include "src/renderer/3d/pipeline/shared/tyra_macros.i" +#include "inc/renderer/3d/pipeline/dynamic/core/programs/dynpip_vu1_shared_defines.h" + +#define RGBA_STORE_OFFSET 0 +#define XYZ2_STORE_OFFSET 1 + +--enter +--endenter + +#vuprog DynPipVU1C + + ResetClipFlags{ } + LoadTyraStaticData{ gifSetTag } + MatrixLoad{ mvp, VU1_MVP_MATRIX_ADDR, vi00 } + LoadTyraSingleColor{ singleColor, singleColorEnabled, VU1_SINGLE_COLOR_ADDR, VU1_OPTIONS_ADDR } + LoadTyraTags{ lodGifTag, texBufferClutGifTag, VU1_LOD_ADDR, VU1_CLUT_ADDR } + FixColor{ singleColor } + +begin: + xtop buffer + LoadTyraPrimTag{ primTag, buffer } + + ilw.w vertexCount, 0(buffer) + iaddiu vertexDataFrom, buffer, VU1_VERT_DATA_ADDR + + iadd kickAddress, vertexDataFrom, vertexCount + iadd destAddress, kickAddress, vertexCount + iadd kickAddress, kickAddress, vertexCount + + StoreTyraGifTags{ gifSetTag, lodGifTag, texBufferClutGifTag, primTag, destAddress } + LoadTyraLerpValue{ interp, VU1_OPTIONS_ADDR } + LoadTyraScaleValue{ scale, buffer } + + ;--- Loop + iadd vertexCounter, buffer, vertexCount +vertexLoop: + + iadd vertexDataTo, vertexDataFrom, vertexCount + + ;--- Vertex 1 - from-to -> lerp + lq vertex1From, (vertexDataFrom) + lq vertex1To, (vertexDataTo) + Lerp{ vertex1, vertex1From, vertex1To, interp } + + ;--- Vertex 1 - Calculate + MatrixMultiplyVertex{ vertex1, mvp, vertex1 } + PerformClipCheck{ vertex1, destAddress, XYZ2_STORE_OFFSET } + VertexPersCorr{ vertex1, vertex1 } + ScaleVertexToGSFormat{ scale, vertex1 } + + ;--- Vertex 1 - Store + sq singleColor, RGBA_STORE_OFFSET(destAddress) + sq.xyz vertex1, XYZ2_STORE_OFFSET(destAddress) + + ; --------------------------------------- + + ;--- Vertex 2 - from-to -> lerp + lq vertex2From, 1(vertexDataFrom) + lq vertex2To, 1(vertexDataTo) + Lerp{ vertex2, vertex2From, vertex2To, interp } + + ;--- Vertex 2 - Calculate + MatrixMultiplyVertex{ vertex2, mvp, vertex2 } + PerformClipCheck{ vertex2, destAddress, XYZ2_STORE_OFFSET+2 } + VertexPersCorr{ vertex2, vertex2 } + ScaleVertexToGSFormat{ scale, vertex2 } + + ;--- Vertex 2 - Store + sq singleColor, RGBA_STORE_OFFSET+2(destAddress) + sq.xyz vertex2, XYZ2_STORE_OFFSET+2(destAddress) + + ; --------------------------------------- + + ;--- Vertex 3 - from-to -> lerp + lq vertex3From, 2(vertexDataFrom) + lq vertex3To, 2(vertexDataTo) + Lerp{ vertex3, vertex3From, vertex3To, interp } + + ;--- Vertex 3 - Calculate + MatrixMultiplyVertex{ vertex3, mvp, vertex3 } + PerformClipCheck{ vertex3, destAddress, XYZ2_STORE_OFFSET+4 } + VertexPersCorr{ vertex3, vertex3 } + ScaleVertexToGSFormat{ scale, vertex3 } + + ;--- Vertex 3 - Store + sq singleColor, RGBA_STORE_OFFSET+4(destAddress) + sq.xyz vertex3, XYZ2_STORE_OFFSET+4(destAddress) + + ;------------------------------- + + iaddiu vertexDataFrom, vertexDataFrom, 3 + iaddiu destAddress, destAddress, 6 + + ;--- Fix loop + iaddi vertexCounter, vertexCounter, -3 ; decrement the loop counter + ibne vertexCounter, buffer, vertexLoop ; and repeat if needed + + xgkick kickAddress ; dispatch to the GS rasterizer. + +--barrier ; Why the hell I must add barrier AFTER XGKICK? VCL does not adds E bit without it... +--cont + + b begin + +#endvuprog + +--exit +--endexit diff --git a/engine/src/renderer/3d/pipeline/dynamic/core/programs/dynpip_c_vu1_program.cpp b/engine/src/renderer/3d/pipeline/dynamic/core/programs/dynpip_c_vu1_program.cpp new file mode 100644 index 0000000..986098e --- /dev/null +++ b/engine/src/renderer/3d/pipeline/dynamic/core/programs/dynpip_c_vu1_program.cpp @@ -0,0 +1,42 @@ +/* +# ______ ____ ___ +# | \/ ____| |___| +# | | | \ | | +#----------------------------------------------------------------------- +# Copyright 2022, tyra - https://github.com/h4570/tyra +# Licenced under Apache License 2.0 +# Sandro Sobczyński +*/ + +#include "debug/debug.hpp" +#include "renderer/3d/pipeline/dynamic/core/programs/dynpip_c_vu1_program.hpp" + +extern u32 DynPipVU1_C_CodeStart __attribute__((section(".vudata"))); +extern u32 DynPipVU1_C_CodeEnd __attribute__((section(".vudata"))); + +namespace Tyra { + +DynPipCVU1Program::DynPipCVU1Program() + : DynPipVU1Program( + DynPipColor, &DynPipVU1_C_CodeStart, &DynPipVU1_C_CodeEnd, + ((u64)GIF_REG_RGBAQ) << 0 | ((u64)GIF_REG_XYZ2) << 4, 2, 1) {} + +DynPipCVU1Program::~DynPipCVU1Program() {} + +std::string DynPipCVU1Program::getStringName() const { + return std::string("DynPip - C"); +} + +void DynPipCVU1Program::addProgramQBufferDataToPacket(packet2_t* packet, + DynPipBag* bag) const { + u32 addr = VU1_VERT_DATA_ADDR; + + // Add vertices + packet2_utils_vu_add_unpack_data(packet, addr, bag->verticesFrom, bag->count, + true); + addr += bag->count; + packet2_utils_vu_add_unpack_data(packet, addr, bag->verticesTo, bag->count, + true); +} + +} // namespace Tyra diff --git a/engine/src/renderer/3d/pipeline/dynamic/core/programs/dynpip_d_vu1.vclpp b/engine/src/renderer/3d/pipeline/dynamic/core/programs/dynpip_d_vu1.vclpp new file mode 100644 index 0000000..d7ab38f --- /dev/null +++ b/engine/src/renderer/3d/pipeline/dynamic/core/programs/dynpip_d_vu1.vclpp @@ -0,0 +1,154 @@ +; ______ ____ ___ +; | \/ ____| |___| +; | | | \ | | +;--------------------------------------------------------------- +; Copyright 2022, tyra - https://github.com/h4570/tyra +; Licenced under Apache License 2.0 +; Sandro Sobczyński +; +;--------------------------------------------------------------- +; Triangle list +; Cull = Standard PS2 way. clipw polys are culled. +; Animation +; Directional lights +;--------------------------------------------------------------- + +.syntax new +.name DynPipVU1_D +.vu +.init_vf_all +.init_vi_all + +#include "src/renderer/3d/pipeline/shared/vcl_sml.i" +#include "src/renderer/3d/pipeline/shared/tyra_macros.i" +#include "inc/renderer/3d/pipeline/dynamic/core/programs/dynpip_vu1_shared_defines.h" + +#define RGBA_STORE_OFFSET 0 +#define XYZ2_STORE_OFFSET 1 + +--enter +--endenter + +#vuprog DynPipVU1D + + ResetClipFlags{ } + LoadTyraStaticData{ gifSetTag } + MatrixLoad{ mvp, VU1_MVP_MATRIX_ADDR, vi00 } + LoadTyraTags{ lodGifTag, texBufferClutGifTag, VU1_LOD_ADDR, VU1_CLUT_ADDR } + +begin: + xtop buffer + LoadTyraPrimTag{ primTag, buffer } + + ilw.w vertexCount, 0(buffer) + iaddiu vertexDataFrom, buffer, VU1_VERT_DATA_ADDR + + iadd normalDataFrom, vertexDataFrom, vertexCount + iadd normalDataFrom, normalDataFrom, vertexCount + + iadd kickAddress, normalDataFrom, vertexCount + iadd destAddress, kickAddress, vertexCount + iadd kickAddress, kickAddress, vertexCount + + StoreTyraGifTags{ gifSetTag, lodGifTag, texBufferClutGifTag, primTag, destAddress } + LoadTyraLerpValue{ interp, VU1_OPTIONS_ADDR } + LoadTyraScaleValue{ scale, buffer } + + ;--- Loop + iadd vertexCounter, buffer, vertexCount +vertexLoop: + + iadd vertexDataTo, vertexDataFrom, vertexCount + iadd normalDataTo, normalDataFrom, vertexCount + + ;--- Vertex 1 - from-to -> lerp + lq vertex1From, (vertexDataFrom) + lq vertex1To, (vertexDataTo) + Lerp{ vertex1, vertex1From, vertex1To, interp } + + lq.xyz normal1From, (normalDataFrom) + lq.xyz normal1To, (normalDataTo) + LerpXYZ{ normal1, normal1From, normal1To, interp } + + ;--- Vertex 1 - Calculate + MatrixMultiplyVertex{ vertex1, mvp, vertex1 } + PerformClipCheck{ vertex1, destAddress, XYZ2_STORE_OFFSET } + VertexPersCorr{ vertex1, vertex1 } + ScaleVertexToGSFormat{ scale, vertex1 } + LoadTyraDirectionalLights{ lightMatrix, lightDirections, lightColors, ambientColor, VU1_LIGHTS_DIRS_ADDR, VU1_LIGHTS_COLORS_ADDR, VU1_LIGHTS_MATRIX_ADDR } + CalculateTyraDirectionalLights{ outputColor1, normal1, lightDirections, lightColors, lightMatrix, ambientColor } + FixColor{ outputColor1 } + + ;--- Vertex 1 - Store + sq outputColor1, RGBA_STORE_OFFSET(destAddress) + sq.xyz vertex1, XYZ2_STORE_OFFSET(destAddress) + + ; --------------------------------------- + + ;--- Vertex 2 - from-to -> lerp + lq vertex2From, 1(vertexDataFrom) + lq vertex2To, 1(vertexDataTo) + Lerp{ vertex2, vertex2From, vertex2To, interp } + + lq.xyz normal2From, 1(normalDataFrom) + lq.xyz normal2To, 1(normalDataTo) + LerpXYZ{ normal2, normal2From, normal2To, interp } + + ;--- Vertex 2 - Calculate + MatrixMultiplyVertex{ vertex2, mvp, vertex2 } + PerformClipCheck{ vertex2, destAddress, XYZ2_STORE_OFFSET } + VertexPersCorr{ vertex2, vertex2 } + ScaleVertexToGSFormat{ scale, vertex2 } + LoadTyraDirectionalLights{ lightMatrix, lightDirections, lightColors, ambientColor, VU1_LIGHTS_DIRS_ADDR, VU1_LIGHTS_COLORS_ADDR, VU1_LIGHTS_MATRIX_ADDR } + CalculateTyraDirectionalLights{ outputColor2, normal2, lightDirections, lightColors, lightMatrix, ambientColor } + FixColor{ outputColor2 } + + ;--- Vertex 2 - Store + sq outputColor2, RGBA_STORE_OFFSET+2(destAddress) + sq.xyz vertex2, XYZ2_STORE_OFFSET+2(destAddress) + + ; --------------------------------------- + + ;--- Vertex 3 - from-to -> lerp + lq vertex3From, 2(vertexDataFrom) + lq vertex3To, 2(vertexDataTo) + Lerp{ vertex3, vertex3From, vertex3To, interp } + + lq.xyz normal3From, 2(normalDataFrom) + lq.xyz normal3To, 2(normalDataTo) + LerpXYZ{ normal3, normal3From, normal3To, interp } + + ;--- Vertex 3 - Calculate + MatrixMultiplyVertex{ vertex3, mvp, vertex3 } + PerformClipCheck{ vertex3, destAddress, XYZ2_STORE_OFFSET } + VertexPersCorr{ vertex3, vertex3 } + ScaleVertexToGSFormat{ scale, vertex3 } + LoadTyraDirectionalLights{ lightMatrix, lightDirections, lightColors, ambientColor, VU1_LIGHTS_DIRS_ADDR, VU1_LIGHTS_COLORS_ADDR, VU1_LIGHTS_MATRIX_ADDR } + CalculateTyraDirectionalLights{ outputColor3, normal3, lightDirections, lightColors, lightMatrix, ambientColor } + FixColor{ outputColor3 } + + ;--- Vertex 3 - Store + sq outputColor3, RGBA_STORE_OFFSET+4(destAddress) + sq.xyz vertex3, XYZ2_STORE_OFFSET+4(destAddress) + + ;------------------------------- + + iaddiu vertexDataFrom, vertexDataFrom, 3 + iaddiu normalDataFrom, normalDataFrom, 3 + iaddiu destAddress, destAddress, 6 + + ;--- Fix loop + iaddi vertexCounter, vertexCounter, -3 ; decrement the loop counter + ibne vertexCounter, buffer, vertexLoop ; and repeat if needed + + xgkick kickAddress ; dispatch to the GS rasterizer. + +--barrier ; Why the hell I must add barrier AFTER XGKICK? VCL does not adds E bit without it... +--cont + + b begin + +#endvuprog + +--exit +--endexit diff --git a/engine/src/renderer/3d/pipeline/dynamic/core/programs/dynpip_d_vu1_program.cpp b/engine/src/renderer/3d/pipeline/dynamic/core/programs/dynpip_d_vu1_program.cpp new file mode 100644 index 0000000..0be32ed --- /dev/null +++ b/engine/src/renderer/3d/pipeline/dynamic/core/programs/dynpip_d_vu1_program.cpp @@ -0,0 +1,53 @@ +/* +# ______ ____ ___ +# | \/ ____| |___| +# | | | \ | | +#----------------------------------------------------------------------- +# Copyright 2022, tyra - https://github.com/h4570/tyra +# Licenced under Apache License 2.0 +# Sandro Sobczyński +*/ + +#include "debug/debug.hpp" +#include "renderer/3d/pipeline/dynamic/core/programs/dynpip_d_vu1_program.hpp" + +extern u32 DynPipVU1_D_CodeStart __attribute__((section(".vudata"))); +extern u32 DynPipVU1_D_CodeEnd __attribute__((section(".vudata"))); + +namespace Tyra { + +DynPipDVU1Program::DynPipDVU1Program() + : DynPipVU1Program( + DynPipDirLights, &DynPipVU1_D_CodeStart, &DynPipVU1_D_CodeEnd, + ((u64)GIF_REG_RGBAQ) << 0 | ((u64)GIF_REG_XYZ2) << 4, 2, 2) {} + +DynPipDVU1Program::~DynPipDVU1Program() {} + +std::string DynPipDVU1Program::getStringName() const { + return std::string("DynPip - D"); +} + +void DynPipDVU1Program::addProgramQBufferDataToPacket(packet2_t* packet, + DynPipBag* bag) const { + u32 addr = VU1_VERT_DATA_ADDR; + + // Add vertices + packet2_utils_vu_add_unpack_data(packet, addr, bag->verticesFrom, bag->count, + true); + addr += bag->count; + packet2_utils_vu_add_unpack_data(packet, addr, bag->verticesTo, bag->count, + true); + addr += bag->count; + + if (bag->lighting) { + // Add normal + packet2_utils_vu_add_unpack_data(packet, addr, bag->lighting->normalsFrom, + bag->count, true); + addr += bag->count; + packet2_utils_vu_add_unpack_data(packet, addr, bag->lighting->normalsTo, + bag->count, true); + addr += bag->count; + } +} + +} // namespace Tyra diff --git a/engine/src/renderer/3d/pipeline/dynamic/core/programs/dynpip_tc_vu1.vclpp b/engine/src/renderer/3d/pipeline/dynamic/core/programs/dynpip_tc_vu1.vclpp new file mode 100644 index 0000000..3d4a361 --- /dev/null +++ b/engine/src/renderer/3d/pipeline/dynamic/core/programs/dynpip_tc_vu1.vclpp @@ -0,0 +1,154 @@ +; ______ ____ ___ +; | \/ ____| |___| +; | | | \ | | +;--------------------------------------------------------------- +; Copyright 2022, tyra - https://github.com/h4570/tyra +; Licenced under Apache License 2.0 +; Sandro Sobczyński +; +;--------------------------------------------------------------- +; Triangle list +; Cull = Standard PS2 way. clipw polys are culled. +; Animation +; Lighting, texture, color +;--------------------------------------------------------------- + +.syntax new +.name DynPipVU1_TC +.vu +.init_vf_all +.init_vi_all + +#include "src/renderer/3d/pipeline/shared/vcl_sml.i" +#include "src/renderer/3d/pipeline/shared/tyra_macros.i" +#include "inc/renderer/3d/pipeline/dynamic/core/programs/dynpip_vu1_shared_defines.h" + +#define STQ_STORE_OFFSET 0 +#define RGBA_STORE_OFFSET 1 +#define XYZ2_STORE_OFFSET 2 + +--enter +--endenter + +#vuprog DynPipVU1TC + + ResetClipFlags{ } + LoadTyraStaticData{ gifSetTag } + MatrixLoad{ mvp, VU1_MVP_MATRIX_ADDR, vi00 } + LoadTyraSingleColor{ singleColor, singleColorEnabled, VU1_SINGLE_COLOR_ADDR, VU1_OPTIONS_ADDR } + LoadTyraTags{ lodGifTag, texBufferClutGifTag, VU1_LOD_ADDR, VU1_CLUT_ADDR } + FixColor{ singleColor } + +begin: + xtop buffer + LoadTyraPrimTag{ primTag, buffer } + + ilw.w vertexCount, 0(buffer) + iaddiu vertexDataFrom, buffer, VU1_VERT_DATA_ADDR + + iadd stqDataFrom, vertexDataFrom, vertexCount + iadd stqDataFrom, stqDataFrom, vertexCount + + iadd kickAddress, stqDataFrom, vertexCount + iadd destAddress, kickAddress, vertexCount + iadd kickAddress, kickAddress, vertexCount + + StoreTyraGifTags{ gifSetTag, lodGifTag, texBufferClutGifTag, primTag, destAddress } + LoadTyraLerpValue{ interp, VU1_OPTIONS_ADDR } + LoadTyraScaleValue{ scale, buffer } + + ;--- Loop + iadd vertexCounter, buffer, vertexCount +vertexLoop: + + iadd vertexDataTo, vertexDataFrom, vertexCount + iadd stqDataTo, stqDataFrom, vertexCount + + ;--- Vertex 1 - from-to -> lerp + lq vertex1From, (vertexDataFrom) + lq vertex1To, (vertexDataTo) + Lerp{ vertex1, vertex1From, vertex1To, interp } + + lq stq1From, (stqDataFrom) + lq stq1To, (stqDataTo) + Lerp{ stq1, stq1From, stq1To, interp } + + ;--- Vertex 1 - Calculate + MatrixMultiplyVertex{ vertex1, mvp, vertex1 } + PerformClipCheck{ vertex1, destAddress, XYZ2_STORE_OFFSET } + VertexPersCorr{ vertex1, vertex1 } + ScaleVertexToGSFormat{ scale, vertex1 } + PerformTexturePerspectiveCorrection{ outputStq1, stq1 } + + ;--- Vertex 1 - Store + sq outputStq1, STQ_STORE_OFFSET(destAddress) + sq singleColor, RGBA_STORE_OFFSET(destAddress) + sq.xyz vertex1, XYZ2_STORE_OFFSET(destAddress) + + ; --------------------------------------- + + ;--- Vertex 2 - from-to -> lerp + lq vertex2From, 1(vertexDataFrom) + lq vertex2To, 1(vertexDataTo) + Lerp{ vertex2, vertex2From, vertex2To, interp } + + lq stq2From, 1(stqDataFrom) + lq stq2To, 1(stqDataTo) + Lerp{ stq2, stq2From, stq2To, interp } + + ;--- Vertex 2 - Calculate + MatrixMultiplyVertex{ vertex2, mvp, vertex2 } + PerformClipCheck{ vertex2, destAddress, XYZ2_STORE_OFFSET+3 } + VertexPersCorr{ vertex2, vertex2 } + ScaleVertexToGSFormat{ scale, vertex2 } + PerformTexturePerspectiveCorrection{ outputStq2, stq2 } + + ;--- Vertex 2 - Store + sq outputStq2, STQ_STORE_OFFSET+3(destAddress) + sq singleColor, RGBA_STORE_OFFSET+3(destAddress) + sq.xyz vertex2, XYZ2_STORE_OFFSET+3(destAddress) + + ; --------------------------------------- + + ;--- Vertex 3 - from-to -> lerp + lq vertex3From, 2(vertexDataFrom) + lq vertex3To, 2(vertexDataTo) + Lerp{ vertex3, vertex3From, vertex3To, interp } + + lq stq3From, 2(stqDataFrom) + lq stq3To, 2(stqDataTo) + Lerp{ stq3, stq3From, stq3To, interp } + + ;--- Vertex 3 - Calculate + MatrixMultiplyVertex{ vertex3, mvp, vertex3 } + PerformClipCheck{ vertex3, destAddress, XYZ2_STORE_OFFSET+6 } + VertexPersCorr{ vertex3, vertex3 } + ScaleVertexToGSFormat{ scale, vertex3 } + PerformTexturePerspectiveCorrection{ outputStq3, stq3 } + + ;--- Vertex 3 - Store + sq outputStq3, STQ_STORE_OFFSET+6(destAddress) + sq singleColor, RGBA_STORE_OFFSET+6(destAddress) + sq.xyz vertex3, XYZ2_STORE_OFFSET+6(destAddress) + + ;------------------------------- + + iaddiu vertexDataFrom, vertexDataFrom, 3 + iaddiu stqDataFrom, stqDataFrom, 3 + iaddiu destAddress, destAddress, 9 + + ;--- Fix loop + iaddi vertexCounter, vertexCounter, -3 ; decrement the loop counter + ibne vertexCounter, buffer, vertexLoop ; and repeat if needed + + xgkick kickAddress ; dispatch to the GS rasterizer. + +--barrier ; Why the hell I must add barrier AFTER XGKICK? VCL does not adds E bit without it... +--cont + + b begin + +#endvuprog + +--exit +--endexit diff --git a/engine/src/renderer/3d/pipeline/dynamic/core/programs/dynpip_tc_vu1_program.cpp b/engine/src/renderer/3d/pipeline/dynamic/core/programs/dynpip_tc_vu1_program.cpp new file mode 100644 index 0000000..73572c0 --- /dev/null +++ b/engine/src/renderer/3d/pipeline/dynamic/core/programs/dynpip_tc_vu1_program.cpp @@ -0,0 +1,55 @@ +/* +# ______ ____ ___ +# | \/ ____| |___| +# | | | \ | | +#----------------------------------------------------------------------- +# Copyright 2022, tyra - https://github.com/h4570/tyra +# Licenced under Apache License 2.0 +# Sandro Sobczyński +*/ + +#include "debug/debug.hpp" +#include "renderer/3d/pipeline/dynamic/core/programs/dynpip_tc_vu1_program.hpp" + +extern u32 DynPipVU1_TC_CodeStart __attribute__((section(".vudata"))); +extern u32 DynPipVU1_TC_CodeEnd __attribute__((section(".vudata"))); + +namespace Tyra { + +DynPipTCVU1Program::DynPipTCVU1Program() + : DynPipVU1Program(DynPipTextureColor, &DynPipVU1_TC_CodeStart, + &DynPipVU1_TC_CodeEnd, + ((u64)GIF_REG_ST) << 0 | ((u64)GIF_REG_RGBAQ) << 4 | + ((u64)GIF_REG_XYZ2) << 8, + 3, 2) {} + +DynPipTCVU1Program::~DynPipTCVU1Program() {} + +std::string DynPipTCVU1Program::getStringName() const { + return std::string("DynPip - TC"); +} + +void DynPipTCVU1Program::addProgramQBufferDataToPacket(packet2_t* packet, + DynPipBag* bag) const { + u32 addr = VU1_VERT_DATA_ADDR; + + // Add vertices + packet2_utils_vu_add_unpack_data(packet, addr, bag->verticesFrom, bag->count, + true); + addr += bag->count; + packet2_utils_vu_add_unpack_data(packet, addr, bag->verticesTo, bag->count, + true); + addr += bag->count; + + if (bag->texture) { + // Add sts + packet2_utils_vu_add_unpack_data( + packet, addr, bag->texture->coordinatesFrom, bag->count, true); + addr += bag->count; + packet2_utils_vu_add_unpack_data(packet, addr, bag->texture->coordinatesTo, + bag->count, true); + addr += bag->count; + } +} + +} // namespace Tyra diff --git a/engine/src/renderer/3d/pipeline/dynamic/core/programs/dynpip_td_vu1.vclpp b/engine/src/renderer/3d/pipeline/dynamic/core/programs/dynpip_td_vu1.vclpp new file mode 100644 index 0000000..ec06ea3 --- /dev/null +++ b/engine/src/renderer/3d/pipeline/dynamic/core/programs/dynpip_td_vu1.vclpp @@ -0,0 +1,178 @@ +; ______ ____ ___ +; | \/ ____| |___| +; | | | \ | | +;--------------------------------------------------------------- +; Copyright 2022, tyra - https://github.com/h4570/tyra +; Licenced under Apache License 2.0 +; Sandro Sobczyński +; +;--------------------------------------------------------------- +; Triangle list +; Cull = Standard PS2 way. clipw polys are culled. +; Animation +; Texture, directional lights +;--------------------------------------------------------------- + +.syntax new +.name DynPipVU1_TD +.vu +.init_vf_all +.init_vi_all + +#include "src/renderer/3d/pipeline/shared/vcl_sml.i" +#include "src/renderer/3d/pipeline/shared/tyra_macros.i" +#include "inc/renderer/3d/pipeline/dynamic/core/programs/dynpip_vu1_shared_defines.h" + +#define STQ_STORE_OFFSET 0 +#define RGBA_STORE_OFFSET 1 +#define XYZ2_STORE_OFFSET 2 + +--enter +--endenter + +#vuprog DynPipVU1TD + + ResetClipFlags{ } + LoadTyraStaticData{ gifSetTag } + MatrixLoad{ mvp, VU1_MVP_MATRIX_ADDR, vi00 } + LoadTyraTags{ lodGifTag, texBufferClutGifTag, VU1_LOD_ADDR, VU1_CLUT_ADDR } + +begin: + xtop buffer + LoadTyraPrimTag{ primTag, buffer } + + ilw.w vertexCount, 0(buffer) + iaddiu vertexDataFrom, buffer, VU1_VERT_DATA_ADDR + + iadd stqDataFrom, vertexDataFrom, vertexCount + iadd stqDataFrom, stqDataFrom, vertexCount + + iadd normalDataFrom, stqDataFrom, vertexCount + iadd normalDataFrom, normalDataFrom, vertexCount + + iadd kickAddress, normalDataFrom, vertexCount + iadd destAddress, kickAddress, vertexCount + iadd kickAddress, kickAddress, vertexCount + + StoreTyraGifTags{ gifSetTag, lodGifTag, texBufferClutGifTag, primTag, destAddress } + LoadTyraLerpValue{ interp, VU1_OPTIONS_ADDR } + LoadTyraScaleValue{ scale, buffer } + + ;--- Loop + iadd vertexCounter, buffer, vertexCount +vertexLoop: + + iadd vertexDataTo, vertexDataFrom, vertexCount + iadd stqDataTo, stqDataFrom, vertexCount + iadd normalDataTo, normalDataFrom, vertexCount + + ;--- Vertex 1 - from-to -> lerp + lq vertex1From, (vertexDataFrom) + lq vertex1To, (vertexDataTo) + Lerp{ vertex1, vertex1From, vertex1To, interp } + + lq stq1From, (stqDataFrom) + lq stq1To, (stqDataTo) + Lerp{ stq1, stq1From, stq1To, interp } + + lq.xyz normal1From, (normalDataFrom) + lq.xyz normal1To, (normalDataTo) + LerpXYZ{ normal1, normal1From, normal1To, interp } + + ;--- Vertex 1 - Calculate + MatrixMultiplyVertex{ vertex1, mvp, vertex1 } + PerformClipCheck{ vertex1, destAddress, XYZ2_STORE_OFFSET } + VertexPersCorr{ vertex1, vertex1 } + ScaleVertexToGSFormat{ scale, vertex1 } + PerformTexturePerspectiveCorrection{ outputStq1, stq1 } + LoadTyraDirectionalLights{ lightMatrix, lightDirections, lightColors, ambientColor, VU1_LIGHTS_DIRS_ADDR, VU1_LIGHTS_COLORS_ADDR, VU1_LIGHTS_MATRIX_ADDR } + CalculateTyraDirectionalLights{ outputColor1, normal1, lightDirections, lightColors, lightMatrix, ambientColor } + FixColor{ outputColor1 } + + ;--- Vertex 1 - Store + sq outputStq1, STQ_STORE_OFFSET(destAddress) + sq outputColor1, RGBA_STORE_OFFSET(destAddress) + sq.xyz vertex1, XYZ2_STORE_OFFSET(destAddress) + + ; --------------------------------------- + + ;--- Vertex 2 - from-to -> lerp + lq vertex2From, 1(vertexDataFrom) + lq vertex2To, 1(vertexDataTo) + Lerp{ vertex2, vertex2From, vertex2To, interp } + + lq stq2From, 1(stqDataFrom) + lq stq2To, 1(stqDataTo) + Lerp{ stq2, stq2From, stq2To, interp } + + lq.xyz normal2From, 1(normalDataFrom) + lq.xyz normal2To, 1(normalDataTo) + LerpXYZ{ normal2, normal2From, normal2To, interp } + + ;--- Vertex 2 - Calculate + MatrixMultiplyVertex{ vertex2, mvp, vertex2 } + PerformClipCheck{ vertex2, destAddress, XYZ2_STORE_OFFSET+3 } + VertexPersCorr{ vertex2, vertex2 } + ScaleVertexToGSFormat{ scale, vertex2 } + PerformTexturePerspectiveCorrection{ outputStq2, stq2 } + LoadTyraDirectionalLights{ lightMatrix, lightDirections, lightColors, ambientColor, VU1_LIGHTS_DIRS_ADDR, VU1_LIGHTS_COLORS_ADDR, VU1_LIGHTS_MATRIX_ADDR } + CalculateTyraDirectionalLights{ outputColor2, normal2, lightDirections, lightColors, lightMatrix, ambientColor } + FixColor{ outputColor2 } + + ;--- Vertex 2 - Store + sq outputStq2, STQ_STORE_OFFSET+3(destAddress) + sq outputColor2, RGBA_STORE_OFFSET+3(destAddress) + sq.xyz vertex2, XYZ2_STORE_OFFSET+3(destAddress) + + ; --------------------------------------- + + ;--- Vertex 3 - from-to -> lerp + lq vertex3From, 2(vertexDataFrom) + lq vertex3To, 2(vertexDataTo) + Lerp{ vertex3, vertex3From, vertex3To, interp } + + lq stq3From, 2(stqDataFrom) + lq stq3To, 2(stqDataTo) + Lerp{ stq3, stq3From, stq3To, interp } + + lq.xyz normal3From, 2(normalDataFrom) + lq.xyz normal3To, 2(normalDataTo) + LerpXYZ{ normal3, normal3From, normal3To, interp } + + ;--- Vertex 3 - Calculate + MatrixMultiplyVertex{ vertex3, mvp, vertex3 } + PerformClipCheck{ vertex3, destAddress, XYZ2_STORE_OFFSET+6 } + VertexPersCorr{ vertex3, vertex3 } + ScaleVertexToGSFormat{ scale, vertex3 } + PerformTexturePerspectiveCorrection{ outputStq3, stq3 } + LoadTyraDirectionalLights{ lightMatrix, lightDirections, lightColors, ambientColor, VU1_LIGHTS_DIRS_ADDR, VU1_LIGHTS_COLORS_ADDR, VU1_LIGHTS_MATRIX_ADDR } + CalculateTyraDirectionalLights{ outputColor3, normal3, lightDirections, lightColors, lightMatrix, ambientColor } + FixColor{ outputColor3 } + + ;--- Vertex 3 - Store + sq outputStq3, STQ_STORE_OFFSET+6(destAddress) + sq outputColor3, RGBA_STORE_OFFSET+6(destAddress) + sq.xyz vertex3, XYZ2_STORE_OFFSET+6(destAddress) + + ;------------------------------- + + iaddiu vertexDataFrom, vertexDataFrom, 3 + iaddiu stqDataFrom, stqDataFrom, 3 + iaddiu normalDataFrom, normalDataFrom, 3 + iaddiu destAddress, destAddress, 9 + + ;--- Fix loop + iaddi vertexCounter, vertexCounter, -3 ; decrement the loop counter + ibne vertexCounter, buffer, vertexLoop ; and repeat if needed + + xgkick kickAddress ; dispatch to the GS rasterizer. + +--barrier ; Why the hell I must add barrier AFTER XGKICK? VCL does not adds E bit without it... +--cont + + b begin + +#endvuprog + +--exit +--endexit diff --git a/engine/src/renderer/3d/pipeline/dynamic/core/programs/dynpip_td_vu1_program.cpp b/engine/src/renderer/3d/pipeline/dynamic/core/programs/dynpip_td_vu1_program.cpp new file mode 100644 index 0000000..f3cc69c --- /dev/null +++ b/engine/src/renderer/3d/pipeline/dynamic/core/programs/dynpip_td_vu1_program.cpp @@ -0,0 +1,65 @@ +/* +# ______ ____ ___ +# | \/ ____| |___| +# | | | \ | | +#----------------------------------------------------------------------- +# Copyright 2022, tyra - https://github.com/h4570/tyra +# Licenced under Apache License 2.0 +# Sandro Sobczyński +*/ + +#include "debug/debug.hpp" +#include "renderer/3d/pipeline/dynamic/core/programs/dynpip_td_vu1_program.hpp" + +extern u32 DynPipVU1_TD_CodeStart __attribute__((section(".vudata"))); +extern u32 DynPipVU1_TD_CodeEnd __attribute__((section(".vudata"))); + +namespace Tyra { + +DynPipTDVU1Program::DynPipTDVU1Program() + : DynPipVU1Program(DynPipTextureDirLights, &DynPipVU1_TD_CodeStart, + &DynPipVU1_TD_CodeEnd, + ((u64)GIF_REG_ST) << 0 | ((u64)GIF_REG_RGBAQ) << 4 | + ((u64)GIF_REG_XYZ2) << 8, + 3, 3) {} + +DynPipTDVU1Program::~DynPipTDVU1Program() {} + +std::string DynPipTDVU1Program::getStringName() const { + return std::string("DynPip - TD"); +} + +void DynPipTDVU1Program::addProgramQBufferDataToPacket(packet2_t* packet, + DynPipBag* bag) const { + u32 addr = VU1_VERT_DATA_ADDR; + + // Add vertices + packet2_utils_vu_add_unpack_data(packet, addr, bag->verticesFrom, bag->count, + true); + addr += bag->count; + packet2_utils_vu_add_unpack_data(packet, addr, bag->verticesTo, bag->count, + true); + addr += bag->count; + + if (bag->texture) { + // Add sts + packet2_utils_vu_add_unpack_data( + packet, addr, bag->texture->coordinatesFrom, bag->count, true); + addr += bag->count; + packet2_utils_vu_add_unpack_data(packet, addr, bag->texture->coordinatesTo, + bag->count, true); + addr += bag->count; + } + + if (bag->lighting) { + // Add normal + packet2_utils_vu_add_unpack_data(packet, addr, bag->lighting->normalsFrom, + bag->count, true); + addr += bag->count; + packet2_utils_vu_add_unpack_data(packet, addr, bag->lighting->normalsTo, + bag->count, true); + addr += bag->count; + } +} + +} // namespace Tyra diff --git a/engine/src/renderer/3d/pipeline/dynamic/dynamic_pipeline.cpp b/engine/src/renderer/3d/pipeline/dynamic/dynamic_pipeline.cpp new file mode 100644 index 0000000..1ec4de8 --- /dev/null +++ b/engine/src/renderer/3d/pipeline/dynamic/dynamic_pipeline.cpp @@ -0,0 +1,281 @@ +/* +# ______ ____ ___ +# | \/ ____| |___| +# | | | \ | | +#----------------------------------------------------------------------- +# Copyright 2022, tyra - https://github.com/h4570/tyra +# Licenced under Apache License 2.0 +# Sandro Sobczyński +*/ + +#include "renderer/3d/pipeline/dynamic/dynamic_pipeline.hpp" + +namespace Tyra { + +const u32 DynamicPipeline::buffersCount = 64; +const u32 DynamicPipeline::halfBuffersCount = buffersCount / 2; + +DynamicPipeline::DynamicPipeline() {} + +DynamicPipeline::~DynamicPipeline() {} + +void DynamicPipeline::setRenderer(RendererCore* t_core) { + rendererCore = t_core; + + core.init(t_core); +} + +void DynamicPipeline::onUse() { + colorsCache = new Vec4[4]; + + buffers = new DynPipBag[buffersCount]; + + auto packetSize = + buffersCount * 5.1F; // 5.1 = packet2_get_qw_count / buffersCount + + core.allocateOnUse(static_cast(packetSize)); + core.reinitVU1Programs(); +} + +void DynamicPipeline::onUseEnd() { + delete[] colorsCache; + + for (u32 i = 0; i < buffersCount; i++) freeBuffer(&buffers[i]); + delete[] buffers; + + core.deallocateOnUse(); +} + +void DynamicPipeline::render(DynamicMesh* mesh, const DynPipOptions* options) { + auto model = mesh->getModelMatrix(); + auto* infoBag = getInfoBag(mesh, options, &model); + PipelineDirLightsBag* dirLights = nullptr; + auto frustumCulling = + options ? options->frustumCulling : PipelineFrustumCulling_Simple; + + if (frustumCulling == PipelineFrustumCulling_Simple) { + auto* frameTo = mesh->getFrame(mesh->getNextAnimationFrame()); + if (frameTo->getBBox().isInFrustum( + rendererCore->renderer3D.frustumPlanes.getAll(), model) == + CoreBBoxFrustum::OUTSIDE_FRUSTUM) { + return; + } + } + + if (options && options->lighting) { + setLightingColorsCache(options->lighting); + dirLights = new PipelineDirLightsBag(true); + dirLights->setLightsManually(colorsCache, + options->lighting->directionalDirections); + } + + u16 bufferIndex = 0; + + setBuffersDefaultVars(buffers, mesh, infoBag); + core.clear(); + + for (u32 i = 0; i < mesh->getMaterialsCount(); i++) { + auto* material = mesh->getMaterial(i); + auto* frameFrom = material->getFrame(mesh->getCurrentAnimationFrame()); + auto* frameTo = material->getFrame(mesh->getNextAnimationFrame()); + + auto partSize = + core.getMaxVertCountByParams(options && options->lighting, + material->getFrame(0)->getTextureCoords()); + + u32 partsCount = + ceil(frameFrom->getVertexCount() / static_cast(partSize)); + + auto* colorBag = getColorBag(material); + + setBuffersColorBag(buffers, colorBag); + u8 isPartInitialized = false; + + for (u32 k = 0; k < partsCount; k++) { + auto& buffer = buffers[bufferIndex]; + + freeBuffer(&buffer); + buffer.count = k == partsCount - 1 + ? frameFrom->getVertexCount() - k * partSize + : partSize; + + u32 startIndex = k * partSize; + + addVertices(frameFrom, frameTo, &buffer, startIndex); + buffer.texture = getTextureBag(material, frameFrom, frameTo, startIndex); + buffer.lighting = getLightingBag(frameFrom, frameTo, &model, options, + dirLights, startIndex); + + if (!isPartInitialized) { + core.initParts(&buffer); + isPartInitialized = true; + } + + setBuffer(buffers, &buffer, &bufferIndex, frustumCulling); + } + + delete colorBag; + } + + sendRestOfBuffers(buffers, &bufferIndex, frustumCulling); + + if (dirLights) { + delete dirLights; + } + + delete infoBag; +} + +void DynamicPipeline::setBuffer(DynPipBag* buffers, DynPipBag* buffer, + u16* bufferIndex, + const PipelineFrustumCulling& frustumCulling) { + auto isEndOf1stDBuffer = *bufferIndex == halfBuffersCount - 1; + auto isEndOf2ndDBuffer = *bufferIndex == buffersCount - 1; + + if (isEndOf1stDBuffer || isEndOf2ndDBuffer) { + u32 offset = isEndOf1stDBuffer ? 0 : halfBuffersCount; + + DynPipBag** sendBuffers = new DynPipBag*[halfBuffersCount]; + + for (u32 i = 0; i < halfBuffersCount; i++) + sendBuffers[i] = &buffers[offset + i]; + + core.renderPart(sendBuffers, halfBuffersCount, + frustumCulling == PipelineFrustumCulling_Precise); + + delete[] sendBuffers; + } + + if (isEndOf2ndDBuffer) + *bufferIndex = 0; + else + *bufferIndex += 1; +} + +void DynamicPipeline::sendRestOfBuffers( + DynPipBag* buffers, u16* bufferIndex, + const PipelineFrustumCulling& frustumCulling) { + auto isEndOf1stDBuffer = *bufferIndex <= halfBuffersCount - 1; + + u32 offset = isEndOf1stDBuffer ? 0 : halfBuffersCount; + u32 size = *bufferIndex - offset; + + if (size <= 0) return; + + DynPipBag** sendBuffers = new DynPipBag*[size]; + for (u32 i = 0; i < size; i++) { + sendBuffers[i] = &buffers[offset + i]; + } + + core.renderPart(sendBuffers, size, + frustumCulling == PipelineFrustumCulling_Precise); + + delete[] sendBuffers; +} + +void DynamicPipeline::setBuffersDefaultVars(DynPipBag* buffers, + DynamicMesh* mesh, + PipelineInfoBag* infoBag) { + for (u32 i = 0; i < buffersCount; i++) { + buffers[i].info = infoBag; + buffers[i].interpolation = mesh->getAnimState().interpolation; + } +} + +void DynamicPipeline::setBuffersColorBag(DynPipBag* buffers, + DynPipColorBag* colorBag) { + for (u32 i = 0; i < buffersCount; i++) { + buffers[i].color = colorBag; + } +} + +void DynamicPipeline::freeBuffer(DynPipBag* bag) { + if (bag->texture) { + delete bag->texture; + } + + if (bag->lighting) { + delete bag->lighting; + } +} + +PipelineInfoBag* DynamicPipeline::getInfoBag(DynamicMesh* mesh, + const DynPipOptions* options, + M4x4* model) const { + auto* result = new PipelineInfoBag(); + + if (options) { + result->antiAliasingEnabled = options->antiAliasingEnabled; + result->blendingEnabled = options->blendingEnabled; + result->shadingType = options->shadingType; + } else { + result->antiAliasingEnabled = false; + result->blendingEnabled = true; + result->shadingType = TyraShadingFlat; + } + + result->model = model; + + return result; +} + +void DynamicPipeline::addVertices(MeshMaterialFrame* materialFrameFrom, + MeshMaterialFrame* materialFrameTo, + DynPipBag* bag, const u32& startIndex) const { + bag->verticesFrom = &materialFrameFrom->getVertices()[startIndex]; + bag->verticesTo = &materialFrameTo->getVertices()[startIndex]; +} + +DynPipColorBag* DynamicPipeline::getColorBag(MeshMaterial* material) const { + auto* result = new DynPipColorBag(); + result->single = &material->color; + return result; +} + +DynPipTextureBag* DynamicPipeline::getTextureBag( + MeshMaterial* material, MeshMaterialFrame* materialFrameFrom, + MeshMaterialFrame* materialFrameTo, const u32& startIndex) { + if (!materialFrameFrom->getTextureCoords()) return nullptr; + + auto* result = new DynPipTextureBag(); + + result->texture = + rendererCore->texture.repository.getBySpriteOrMesh(material->getId()); + TYRA_ASSERT(result->texture, "Texture for material id: ", material->getId(), + "was not found in texture repository!"); + + result->coordinatesFrom = &materialFrameFrom->getTextureCoords()[startIndex]; + result->coordinatesTo = &materialFrameTo->getTextureCoords()[startIndex]; + + return result; +} + +DynPipLightingBag* DynamicPipeline::getLightingBag( + MeshMaterialFrame* materialFrameFrom, MeshMaterialFrame* materialFrameTo, + M4x4* model, const DynPipOptions* options, + PipelineDirLightsBag* dirLightsBag, const u32& startIndex) const { + if (!materialFrameFrom->getNormals() || options == nullptr || + options->lighting == nullptr) + return nullptr; + + auto* result = new DynPipLightingBag(); + + result->lightMatrix = model; + result->dirLights = dirLightsBag; + + result->normalsFrom = &materialFrameFrom->getNormals()[startIndex]; + result->normalsTo = &materialFrameTo->getNormals()[startIndex]; + + return result; +} + +void DynamicPipeline::setLightingColorsCache( + PipelineLightingOptions* lightingOptions) { + for (int i = 0; i < 3; i++) { + colorsCache[i] = + reinterpret_cast(lightingOptions->directionalColors[i]); + } + colorsCache[3] = reinterpret_cast(*lightingOptions->ambientColor); +} + +} // namespace Tyra diff --git a/engine/src/renderer/3d/pipeline/minecraft/minecraft_pipeline.cpp b/engine/src/renderer/3d/pipeline/minecraft/minecraft_pipeline.cpp index 2212b45..49ab140 100644 --- a/engine/src/renderer/3d/pipeline/minecraft/minecraft_pipeline.cpp +++ b/engine/src/renderer/3d/pipeline/minecraft/minecraft_pipeline.cpp @@ -14,7 +14,11 @@ namespace Tyra { -MinecraftPipeline::MinecraftPipeline() { latestMode = UndefinedMcpipProgram; } +MinecraftPipeline::MinecraftPipeline() { + latestMode = UndefinedMcpipProgram; + spamBuffersCount = 4; + spammerIndex = 0; +} MinecraftPipeline::~MinecraftPipeline() { if (bbox) { @@ -22,7 +26,7 @@ MinecraftPipeline::~MinecraftPipeline() { } } -void MinecraftPipeline::init(RendererCore* core) { +void MinecraftPipeline::setRenderer(RendererCore* core) { rendererCore = core; manager.init(core); @@ -30,11 +34,21 @@ void MinecraftPipeline::init(RendererCore* core) { } void MinecraftPipeline::onUse() { + spamBuffers = new McpipBlock**[spamBuffersCount]; + spamCounts = new u32[spamBuffersCount]; + manager.allocateOnUse(); + manager.uploadVU1Programs(); changeMode(McPipCull, true); } +void MinecraftPipeline::onUseEnd() { + delete[] spamBuffers; + delete[] spamCounts; + manager.deallocateOnUse(); +} + void MinecraftPipeline::initBBox() { const auto& block = manager.getBlockData(); bbox = new RenderBBox(block.vertices, block.count); @@ -42,36 +56,35 @@ void MinecraftPipeline::initBBox() { void MinecraftPipeline::render(McpipBlock* blocks, const u32& count, Texture* t_tex, const bool& isMulti, - const bool& noClipChecks) { + const bool& fullClipChecks) { auto texBuffers = rendererCore->texture.useTexture(t_tex); rendererCore->gs.prim.mapping = 1; manager.clearLastProgram(); std::vector cullIndexes; - if (noClipChecks) { + if (!fullClipChecks) { for (u32 i = 0; i < count; i++) cullIndexes.push_back(i); - cull(blocks, cullIndexes, &texBuffers, isMulti); - } else { - u32 culled = 0, clipped = 0; - std::vector clipIndexes; - - for (u32 i = 0; i < count; i++) { - auto frustum = isInFrustum(blocks[i]); - if (frustum == CoreBBoxFrustum::IN_FRUSTUM) { - cullIndexes.push_back(i); - culled++; - } else if (frustum == CoreBBoxFrustum::PARTIALLY_IN_FRUSTUM) { - clipIndexes.push_back(i); - clipped++; - } - } - - if (culled > 0) cull(blocks, cullIndexes, &texBuffers, isMulti); - if (clipped > 0) clip(blocks, clipIndexes, &texBuffers, isMulti); + cull(blocks, cullIndexes, &texBuffers, true, isMulti); + return; } - Threading::switchThread(); + u32 culled = 0, clipped = 0; + std::vector clipIndexes; + + for (u32 i = 0; i < count; i++) { + auto frustum = isInFrustum(blocks[i]); + if (frustum == CoreBBoxFrustum::IN_FRUSTUM) { + cullIndexes.push_back(i); + culled++; + } else if (frustum == CoreBBoxFrustum::PARTIALLY_IN_FRUSTUM) { + clipIndexes.push_back(i); + clipped++; + } + } + + if (culled > 0) cull(blocks, cullIndexes, &texBuffers, false, isMulti); + if (clipped > 0) clip(blocks, clipIndexes, &texBuffers, isMulti); } CoreBBoxFrustum MinecraftPipeline::isInFrustum(const McpipBlock& block) const { @@ -82,7 +95,7 @@ CoreBBoxFrustum MinecraftPipeline::isInFrustum(const McpipBlock& block) const { void MinecraftPipeline::cull(McpipBlock* blocks, const std::vector& indexes, RendererCoreTextureBuffers* texBuffers, - const bool& isMulti) { + const bool& isCullOnly, const bool& isMulti) { changeMode(McPipCull, false); auto maxBlocksPerQBuffer = manager.culler.getMaxBlocksCountPerQBuffer(); @@ -101,10 +114,18 @@ void MinecraftPipeline::cull(McpipBlock* blocks, &blocks[indexes[i * maxBlocksPerQBuffer + j]]; } - manager.cull(blockPointerArray, blockPointerArrayCount, texBuffers, - isMulti); + if (isCullOnly) { + addToSpammer(blockPointerArray, blockPointerArrayCount, texBuffers, + isMulti); + } else { + manager.cull(blockPointerArray, blockPointerArrayCount, texBuffers, + isMulti); + delete[] blockPointerArray; + } + } - delete[] blockPointerArray; + if (isCullOnly) { + flushSpammer(texBuffers, isMulti); } } @@ -140,4 +161,38 @@ void MinecraftPipeline::changeMode(const McpipProgramName& requestedMode, } } +void MinecraftPipeline::addToSpammer(McpipBlock** blockPointerArray, + const u32& count, + RendererCoreTextureBuffers* texBuffers, + const bool& isMulti) { + spamBuffers[spammerIndex] = blockPointerArray; + spamCounts[spammerIndex] = count; + + spammerIndex++; + + if (spammerIndex == spamBuffersCount) { + spammerIndex = 0; + + manager.cullSpam(spamBuffers, spamCounts, spamBuffersCount, texBuffers, + isMulti); + + for (u32 i = 0; i < spamBuffersCount; i++) { + delete[] spamBuffers[i]; + } + } +} + +void MinecraftPipeline::flushSpammer(RendererCoreTextureBuffers* texBuffers, + const bool& isMulti) { + if (spammerIndex == 0) return; + + manager.cullSpam(spamBuffers, spamCounts, spammerIndex, texBuffers, isMulti); + + for (u32 i = 0; i < spammerIndex; i++) { + delete[] spamBuffers[i]; + } + + spammerIndex = 0; +} + } // namespace Tyra diff --git a/engine/src/renderer/3d/pipeline/minecraft/programs/as_is/mcpip_as_is_vu1.vclpp b/engine/src/renderer/3d/pipeline/minecraft/programs/as_is/mcpip_as_is_vu1.vclpp index a211973..a706e90 100644 --- a/engine/src/renderer/3d/pipeline/minecraft/programs/as_is/mcpip_as_is_vu1.vclpp +++ b/engine/src/renderer/3d/pipeline/minecraft/programs/as_is/mcpip_as_is_vu1.vclpp @@ -21,7 +21,7 @@ .init_vf_all .init_vi_all -#include "src/renderer/core/paths/path1/programs/vcl_sml.i" +#include "src/renderer/3d/pipeline/shared/vcl_sml.i" #include "inc/renderer/3d/pipeline/minecraft/programs/as_is/mcpip_vu1_as_is_shared_defines.h" #include "src/renderer/3d/pipeline/minecraft/programs/as_is/macros.i" diff --git a/engine/src/renderer/3d/pipeline/minecraft/programs/as_is/mcpip_as_is_vu1_program.cpp b/engine/src/renderer/3d/pipeline/minecraft/programs/as_is/mcpip_as_is_vu1_program.cpp index 5d6c811..3796372 100644 --- a/engine/src/renderer/3d/pipeline/minecraft/programs/as_is/mcpip_as_is_vu1_program.cpp +++ b/engine/src/renderer/3d/pipeline/minecraft/programs/as_is/mcpip_as_is_vu1_program.cpp @@ -22,7 +22,7 @@ McpipAsIsVU1Program::McpipAsIsVU1Program() McpipAsIsVU1Program::~McpipAsIsVU1Program() {} std::string McpipAsIsVU1Program::getStringName() const { - return std::string("As is"); + return std::string("McPip - As is"); } } // namespace Tyra diff --git a/engine/src/renderer/3d/pipeline/minecraft/programs/as_is/mcpip_clip.cpp b/engine/src/renderer/3d/pipeline/minecraft/programs/as_is/mcpip_clip.cpp index 40746df..a4e1075 100644 --- a/engine/src/renderer/3d/pipeline/minecraft/programs/as_is/mcpip_clip.cpp +++ b/engine/src/renderer/3d/pipeline/minecraft/programs/as_is/mcpip_clip.cpp @@ -57,15 +57,15 @@ void McpipClip::initStaticPacket() { void McpipClip::addData(McpipBlock* block, const bool& isMulti, RendererCoreTextureBuffers* texBuffers, packet2_t* packet, const u8& context) { - std::vector clippedVertices; + std::vector clippedVertices; auto mvp = rendererCore->renderer3D.getViewProj() * block->model; const auto* blockData = isMulti ? multiBlockData : singleBlockData; for (u32 i = 0; i < blockData->count / 3; i++) { for (u8 j = 0; j < 3; j++) { - Path1ClipVertex vert = {mvp * blockData->vertices[i * 3 + j], Vec4(), - blockData->textureCoords[i * 3 + j], Vec4()}; + EEClipVertex vert = {mvp * blockData->vertices[i * 3 + j], Vec4(), + blockData->textureCoords[i * 3 + j], Vec4()}; inputTriangle.push_back(vert); } @@ -93,7 +93,7 @@ void McpipClip::addData(McpipBlock* block, const bool& isMulti, addDataToPacket(packet, context, block, clippedVertices.size(), texBuffers); } -void McpipClip::addCorrections(std::vector* vertices, +void McpipClip::addCorrections(std::vector* vertices, McpipBlock* block) { for (u32 i = 0; i < vertices->size(); i++) { (*vertices)[i].position /= (*vertices)[i].position.w; // Perspective divide @@ -101,7 +101,7 @@ void McpipClip::addCorrections(std::vector* vertices, } } -void McpipClip::moveDataToBuffer(std::vector* vertices, +void McpipClip::moveDataToBuffer(std::vector* vertices, const u8& context) { for (u32 i = 0; i < vertices->size(); i++) { vertexBuffers[context][i].set(vertices->at(i).position); diff --git a/engine/src/renderer/3d/pipeline/minecraft/programs/cull/mcpip_cull.cpp b/engine/src/renderer/3d/pipeline/minecraft/programs/cull/mcpip_cull.cpp index e3c3fe4..5f04d46 100644 --- a/engine/src/renderer/3d/pipeline/minecraft/programs/cull/mcpip_cull.cpp +++ b/engine/src/renderer/3d/pipeline/minecraft/programs/cull/mcpip_cull.cpp @@ -107,8 +107,6 @@ void McpipCull::sendVU1StaticData() { void McpipCull::addData(packet2_t* packet, McpipBlock** blockPointerArray, u32 blockPointerArrayCount, RendererCoreTextureBuffers* texBuffers, bool isMulti) { - packet2_reset(packet, false); - rendererCore->texture.updateClutBuffer(texBuffers->clut); packet2_utils_vu_open_unpack( diff --git a/engine/src/renderer/3d/pipeline/minecraft/programs/cull/mcpip_cull_vu1.vclpp b/engine/src/renderer/3d/pipeline/minecraft/programs/cull/mcpip_cull_vu1.vclpp index ea42007..5e2c1a6 100644 --- a/engine/src/renderer/3d/pipeline/minecraft/programs/cull/mcpip_cull_vu1.vclpp +++ b/engine/src/renderer/3d/pipeline/minecraft/programs/cull/mcpip_cull_vu1.vclpp @@ -21,7 +21,7 @@ .init_vf_all .init_vi_all -#include "src/renderer/core/paths/path1/programs/vcl_sml.i" +#include "src/renderer/3d/pipeline/shared/vcl_sml.i" #include "inc/renderer/3d/pipeline/minecraft/programs/cull/mcpip_vu1_cull_shared_defines.h" #include "src/renderer/3d/pipeline/minecraft/programs/cull/macros.i" diff --git a/engine/src/renderer/3d/pipeline/minecraft/programs/cull/mcpip_cull_vu1_program.cpp b/engine/src/renderer/3d/pipeline/minecraft/programs/cull/mcpip_cull_vu1_program.cpp index 3ec49c9..f572427 100644 --- a/engine/src/renderer/3d/pipeline/minecraft/programs/cull/mcpip_cull_vu1_program.cpp +++ b/engine/src/renderer/3d/pipeline/minecraft/programs/cull/mcpip_cull_vu1_program.cpp @@ -22,7 +22,7 @@ McpipCullVU1Program::McpipCullVU1Program() McpipCullVU1Program::~McpipCullVU1Program() {} std::string McpipCullVU1Program::getStringName() const { - return std::string("Cull"); + return std::string("McPip - Cull"); } } // namespace Tyra diff --git a/engine/src/renderer/3d/pipeline/minecraft/programs/mcpip_programs_manager.cpp b/engine/src/renderer/3d/pipeline/minecraft/programs/mcpip_programs_manager.cpp index aa89c39..69e5632 100644 --- a/engine/src/renderer/3d/pipeline/minecraft/programs/mcpip_programs_manager.cpp +++ b/engine/src/renderer/3d/pipeline/minecraft/programs/mcpip_programs_manager.cpp @@ -16,16 +16,23 @@ BlockizerProgramsManager::BlockizerProgramsManager() { lastProgramName = UndefinedMcpipProgram; context = 0; vu1BlockData = BlockNotUploaded; - dynamicPackets[0] = packet2_create(100, P2_TYPE_NORMAL, P2_MODE_CHAIN, true); - dynamicPackets[1] = packet2_create(100, P2_TYPE_NORMAL, P2_MODE_CHAIN, true); - staticPacket = packet2_create(2, P2_TYPE_NORMAL, P2_MODE_CHAIN, true); + setProgramsCache(); } -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); + staticPacket = packet2_create(2, P2_TYPE_NORMAL, P2_MODE_CHAIN, true); +} + +void BlockizerProgramsManager::deallocateOnUse() { packet2_free(dynamicPackets[0]); packet2_free(dynamicPackets[1]); packet2_free(staticPacket); +} + +BlockizerProgramsManager::~BlockizerProgramsManager() { packet2_free(programsPacket); } @@ -79,6 +86,32 @@ void BlockizerProgramsManager::uploadBlock(bool isMulti) { dma_channel_send_packet2(staticPacket, DMA_CHANNEL_VIF1, true); } +void BlockizerProgramsManager::cullSpam(McpipBlock*** blockPointerArrays, + u32* blockPointerArrayCounts, + u32 blockPointerArraysCount, + RendererCoreTextureBuffers* texBuffers, + const bool& isMulti) { + uploadBlock(isMulti); + + auto* currentPacket = dynamicPackets[context]; + + auto* program = repo.getProgram(McpipProgramName::McPipCull); + + packet2_reset(currentPacket, false); + + for (u32 i = 0; i < blockPointerArraysCount; i++) { + auto* blockPointerArray = blockPointerArrays[i]; + auto blockPointerArrayCount = blockPointerArrayCounts[i]; + + culler.addData(currentPacket, blockPointerArray, blockPointerArrayCount, + texBuffers, isMulti); + + addProgram(program); + } + + sendPacket(program); +} + void BlockizerProgramsManager::cull(McpipBlock** blockPointerArray, u32 blockPointerArrayCount, RendererCoreTextureBuffers* texBuffers, @@ -89,9 +122,12 @@ void BlockizerProgramsManager::cull(McpipBlock** blockPointerArray, auto* program = repo.getProgram(McpipProgramName::McPipCull); + packet2_reset(currentPacket, false); + culler.addData(currentPacket, blockPointerArray, blockPointerArrayCount, texBuffers, isMulti); + addProgram(program); sendPacket(program); } @@ -106,10 +142,11 @@ void BlockizerProgramsManager::clip(McpipBlock* block, clipper.addData(block, isMulti, texBuffers, currentPacket, context); + addProgram(program); sendPacket(program); } -void BlockizerProgramsManager::sendPacket(McpipProgram* program) { +void BlockizerProgramsManager::addProgram(McpipProgram* program) { auto* currentPacket = dynamicPackets[context]; if (lastProgramName != program->getName()) { @@ -119,6 +156,10 @@ void BlockizerProgramsManager::sendPacket(McpipProgram* program) { } else { packet2_utils_vu_add_continue_program(currentPacket); } +} + +void BlockizerProgramsManager::sendPacket(McpipProgram* program) { + auto* currentPacket = dynamicPackets[context]; packet2_utils_vu_add_end_tag(currentPacket); diff --git a/engine/src/renderer/3d/pipeline/std/core/bag/stdpip_lighting_bag.cpp b/engine/src/renderer/3d/pipeline/shared/bag/pipeline_dir_lights_bag.cpp similarity index 62% rename from engine/src/renderer/3d/pipeline/std/core/bag/stdpip_lighting_bag.cpp rename to engine/src/renderer/3d/pipeline/shared/bag/pipeline_dir_lights_bag.cpp index 68dd97a..0638810 100644 --- a/engine/src/renderer/3d/pipeline/std/core/bag/stdpip_lighting_bag.cpp +++ b/engine/src/renderer/3d/pipeline/shared/bag/pipeline_dir_lights_bag.cpp @@ -9,15 +9,13 @@ */ #include "debug/debug.hpp" -#include "renderer/3d/pipeline/std/core/bag/stdpip_lighting_bag.hpp" +#include "renderer/3d/pipeline/shared/bag/pipeline_dir_lights_bag.hpp" namespace Tyra { -StdpipLightingBag::StdpipLightingBag(const bool& manual) { +PipelineDirLightsBag::PipelineDirLightsBag(const bool& manual) { isAllocated = false; mode = Auto; - normals = nullptr; - lightMatrix = nullptr; lightColors = nullptr; lightDirections = nullptr; if (manual) { @@ -27,33 +25,33 @@ StdpipLightingBag::StdpipLightingBag(const bool& manual) { } } -StdpipLightingBag::~StdpipLightingBag() { deallocate(); } +PipelineDirLightsBag::~PipelineDirLightsBag() { deallocate(); } -void StdpipLightingBag::setAmbientColor(const Color& color) { +void PipelineDirLightsBag::setAmbientColor(const Color& color) { TYRA_ASSERT(mode != Manual, "Ambient color cannot be set in manual mode"); lightColors[3].set(reinterpret_cast(color)); } -void StdpipLightingBag::setDirectionalLightColors(Color* colors, - const u8& count) { +void PipelineDirLightsBag::setDirectionalLightColors(Color* colors, + const u8& count) { for (u8 i = 0; i < count; i++) setDirectionalLightColor(colors[i], i); } -void StdpipLightingBag::setDirectionalLightDirections(Vec4* directions, - const u8& count) { +void PipelineDirLightsBag::setDirectionalLightDirections(Vec4* directions, + const u8& count) { for (u8 i = 0; i < count; i++) setDirectionalLightDirection(directions[i], i); } -void StdpipLightingBag::setDirectionalLightColor(const Color& color, - const u8& index) { +void PipelineDirLightsBag::setDirectionalLightColor(const Color& color, + const u8& index) { TYRA_ASSERT(mode != Manual, "Directional lights cannot be set in manual mode"); TYRA_ASSERT(index < 3, "There are max 3 directional lights"); lightColors[index].set(reinterpret_cast(color)); } -void StdpipLightingBag::setDirectionalLightDirection(const Vec4& direction, - const u8& index) { +void PipelineDirLightsBag::setDirectionalLightDirection(const Vec4& direction, + const u8& index) { TYRA_ASSERT(mode != Manual, "Directional lights cannot be set in manual mode"); TYRA_ASSERT(index < 3, "There are max 3 directional lights"); @@ -61,19 +59,19 @@ void StdpipLightingBag::setDirectionalLightDirection(const Vec4& direction, lightDirections[index].set(direction); } -void StdpipLightingBag::setLightsManually(Vec4* colors, Vec4* directions) { +void PipelineDirLightsBag::setLightsManually(Vec4* colors, Vec4* directions) { deallocate(); lightColors = colors; lightDirections = directions; mode = Manual; } -void StdpipLightingBag::disableManualMode() { +void PipelineDirLightsBag::disableManualMode() { allocate(); mode = Auto; } -void StdpipLightingBag::allocate() { +void PipelineDirLightsBag::allocate() { if (isAllocated) return; lightColors = new Vec4[4]; @@ -92,27 +90,27 @@ void StdpipLightingBag::allocate() { isAllocated = true; } -void StdpipLightingBag::deallocate() { +void PipelineDirLightsBag::deallocate() { if (!isAllocated) return; forceDeallocate(); } -void StdpipLightingBag::forceDeallocate() { +void PipelineDirLightsBag::forceDeallocate() { forceDeallocateColors(); forceDeallocateDirections(); isAllocated = false; } -void StdpipLightingBag::forceDeallocateColors() { +void PipelineDirLightsBag::forceDeallocateColors() { if (lightColors != nullptr) { delete[] lightColors; lightColors = nullptr; } } -void StdpipLightingBag::forceDeallocateDirections() { +void PipelineDirLightsBag::forceDeallocateDirections() { if (lightDirections != nullptr) { delete[] lightDirections; lightDirections = nullptr; diff --git a/engine/src/renderer/3d/pipeline/std/core/bag/stdpip_info_bag.cpp b/engine/src/renderer/3d/pipeline/shared/bag/pipeline_info_bag.cpp similarity index 70% rename from engine/src/renderer/3d/pipeline/std/core/bag/stdpip_info_bag.cpp rename to engine/src/renderer/3d/pipeline/shared/bag/pipeline_info_bag.cpp index 64d5640..e42b02e 100644 --- a/engine/src/renderer/3d/pipeline/std/core/bag/stdpip_info_bag.cpp +++ b/engine/src/renderer/3d/pipeline/shared/bag/pipeline_info_bag.cpp @@ -8,17 +8,17 @@ # Sandro Sobczyński */ -#include "renderer/3d/pipeline/std/core/bag/stdpip_info_bag.hpp" +#include "renderer/3d/pipeline/shared/bag/pipeline_info_bag.hpp" namespace Tyra { -StdpipInfoBag::StdpipInfoBag() { - shadingType = StdpipShadingFlat; +PipelineInfoBag::PipelineInfoBag() { + shadingType = TyraShadingFlat; blendingEnabled = true; antiAliasingEnabled = false; model = nullptr; } -StdpipInfoBag::~StdpipInfoBag() {} +PipelineInfoBag::~PipelineInfoBag() {} } // namespace Tyra diff --git a/engine/src/renderer/core/paths/path1/programs/tyra_macros.i b/engine/src/renderer/3d/pipeline/shared/tyra_macros.i similarity index 77% rename from engine/src/renderer/core/paths/path1/programs/tyra_macros.i rename to engine/src/renderer/3d/pipeline/shared/tyra_macros.i index 4b4214c..27f339e 100644 --- a/engine/src/renderer/core/paths/path1/programs/tyra_macros.i +++ b/engine/src/renderer/3d/pipeline/shared/tyra_macros.i @@ -17,6 +17,20 @@ ilw.x t_singleColorEnabled, t_optionsAddr(vi00) #endmacro +;//--------------------------------------------------------- +;// LoadTyraLerpValue - Loads interpolation value. +;//--------------------------------------------------------- +#macro LoadTyraLerpValue: t_lerpValue, t_optionsAddr + lq.y t_lerpValue, t_optionsAddr(vi00) +#endmacro + +;//--------------------------------------------------------- +;// LoadTyraScaleValue - Loads screen scales. +;//--------------------------------------------------------- +#macro LoadTyraScaleValue: t_scale, t_buffer + lq.xyz t_scale, 0(t_buffer) +#endmacro + ;//--------------------------------------------------------- ;// LoadTyraTags - Load lod, texture buffer and clut ;// 1 - GIF tag - texture LOD @@ -27,6 +41,14 @@ lq t_texBufferClutGifTag, t_ClutAddr(vi00) #endmacro +;//--------------------------------------------------------- +;// LoadTyraPrimTag - Load prim tag +;// 2 - GIF tag - tell GS how many data we will send +;//--------------------------------------------------------- +#macro LoadTyraPrimTag: t_primTag, t_buffer + lq t_primTag, 1(t_buffer) +#endmacro + ;//--------------------------------------------------------- ;// LoadTyraBufferTags - Load scales and prim tag ;// 1 - float : X, Y, Z - scale vector that we will use to scale the verts after projecting them, float : W - vert count. @@ -97,3 +119,21 @@ loi 128 addi.w t_outputColor, vf00, i #endmacro + +;//--------------------------------------------------------- +;// LerpXYZ - Linear interpolation between two points +;//--------------------------------------------------------- +#macro LerpXYZ: t_output, t_from, t_to, t_interp + sub.xyz temp1, t_to, t_from + mul.xyz temp2, temp1, t_interp[y] + add.xyz t_output, temp2, t_from +#endmacro + +;//--------------------------------------------------------- +;// Lerp - Linear interpolation between two points +;//--------------------------------------------------------- +#macro Lerp: t_output, t_from, t_to, t_interp + sub temp1, t_to, t_from + mul temp2, temp1, t_interp[y] + add t_output, temp2, t_from +#endmacro \ No newline at end of file diff --git a/engine/src/renderer/core/paths/path1/programs/vcl_sml.i b/engine/src/renderer/3d/pipeline/shared/vcl_sml.i similarity index 100% rename from engine/src/renderer/core/paths/path1/programs/vcl_sml.i rename to engine/src/renderer/3d/pipeline/shared/vcl_sml.i diff --git a/engine/src/renderer/3d/pipeline/std/core/bag/packaging/stdpip_bag_package.cpp b/engine/src/renderer/3d/pipeline/static/core/bag/packaging/stapip_bag_package.cpp similarity index 82% rename from engine/src/renderer/3d/pipeline/std/core/bag/packaging/stdpip_bag_package.cpp rename to engine/src/renderer/3d/pipeline/static/core/bag/packaging/stapip_bag_package.cpp index f79a60f..1f953f8 100644 --- a/engine/src/renderer/3d/pipeline/std/core/bag/packaging/stdpip_bag_package.cpp +++ b/engine/src/renderer/3d/pipeline/static/core/bag/packaging/stapip_bag_package.cpp @@ -11,11 +11,12 @@ #include #include #include -#include "renderer/3d/pipeline/std/core/bag/packaging/stdpip_bag_package.hpp" +#include +#include "renderer/3d/pipeline/static/core/bag/packaging/stapip_bag_package.hpp" namespace Tyra { -StdpipBagPackage::StdpipBagPackage() { +StaPipBagPackage::StaPipBagPackage() { size = 0; bag = nullptr; vertices = nullptr; @@ -23,24 +24,24 @@ StdpipBagPackage::StdpipBagPackage() { normals = nullptr; colors = nullptr; } -StdpipBagPackage::~StdpipBagPackage() {} +StaPipBagPackage::~StaPipBagPackage() {} -void StdpipBagPackage::print() const { +void StaPipBagPackage::print() const { auto text = getPrint(nullptr); printf("%s\n", text.c_str()); } -void StdpipBagPackage::print(const char* name) const { +void StaPipBagPackage::print(const char* name) const { auto text = getPrint(name); printf("%s\n", text.c_str()); } -std::string StdpipBagPackage::getPrint(const char* name) const { +std::string StaPipBagPackage::getPrint(const char* name) const { std::stringstream res; if (name) { res << name << "("; } else { - res << "StdpipBagPackage("; + res << "StaPipBagPackage("; } res << std::fixed << std::setprecision(2); res << std::endl; diff --git a/engine/src/renderer/3d/pipeline/std/core/bag/packaging/stdpip_bag_packager.cpp b/engine/src/renderer/3d/pipeline/static/core/bag/packaging/stapip_bag_packager.cpp similarity index 74% rename from engine/src/renderer/3d/pipeline/std/core/bag/packaging/stdpip_bag_packager.cpp rename to engine/src/renderer/3d/pipeline/static/core/bag/packaging/stapip_bag_packager.cpp index 9d8e169..649e4a8 100644 --- a/engine/src/renderer/3d/pipeline/std/core/bag/packaging/stdpip_bag_packager.cpp +++ b/engine/src/renderer/3d/pipeline/static/core/bag/packaging/stapip_bag_packager.cpp @@ -11,14 +11,14 @@ #include #include #include "debug/debug.hpp" -#include "renderer/3d/pipeline/std/core/bag/packaging/stdpip_bag_packager.hpp" +#include "renderer/3d/pipeline/static/core/bag/packaging/stapip_bag_packager.hpp" namespace Tyra { -StdpipBagPackager::StdpipBagPackager() {} -StdpipBagPackager::~StdpipBagPackager() {} +StaPipBagPackager::StaPipBagPackager() {} +StaPipBagPackager::~StaPipBagPackager() {} -void StdpipBagPackager::init(Renderer3DFrustumPlanes* t_frustumPlanes) { +void StaPipBagPackager::init(Renderer3DFrustumPlanes* t_frustumPlanes) { frustumPlanes = t_frustumPlanes; } @@ -27,13 +27,13 @@ void StdpipBagPackager::init(Renderer3DFrustumPlanes* t_frustumPlanes) { * * @param size Max maxVertCount verts (VU1 buffer size) */ -StdpipBagPackage* StdpipBagPackager::create(u16* o_size, StdpipBag* data, +StaPipBagPackage* StaPipBagPackager::create(u16* o_size, StaPipBag* data, u16 size) { - TYRA_ASSERT(size <= maxVertCount, "StdpipBagPackage can have max ", + TYRA_ASSERT(size <= maxVertCount, "StaPipBagPackage can have max ", maxVertCount, " verts. Provided \"", size, "\""); *o_size = ceil(data->count / static_cast(size)); - StdpipBagPackage* result = new StdpipBagPackage[*o_size]; + StaPipBagPackage* result = new StaPipBagPackage[*o_size]; for (u16 i = 0; i < *o_size; i++) { result[i].bag = data; @@ -65,14 +65,14 @@ StdpipBagPackage* StdpipBagPackager::create(u16* o_size, StdpipBag* data, * * @param size Max maxVertCount verts (VU1 buffer size) */ -StdpipBagPackage* StdpipBagPackager::create(u16* o_count, - const StdpipBagPackage& pkg, +StaPipBagPackage* StaPipBagPackager::create(u16* o_count, + const StaPipBagPackage& pkg, u16 size) { - TYRA_ASSERT(size <= maxVertCount, "StdpipBagPackage can have max ", + TYRA_ASSERT(size <= maxVertCount, "StaPipBagPackage can have max ", maxVertCount, " verts. Provided \"", size, "\""); *o_count = ceil(pkg.size / static_cast(size)); - auto* result = new StdpipBagPackage[*o_count]; + auto* result = new StaPipBagPackage[*o_count]; for (u16 i = 0; i < *o_count; i++) { result[i].bag = pkg.bag; @@ -99,7 +99,9 @@ StdpipBagPackage* StdpipBagPackager::create(u16* o_count, return result; } -CoreBBoxFrustum StdpipBagPackager::checkFrustum(const StdpipBagPackage& pkg) { +CoreBBoxFrustum StaPipBagPackager::checkFrustum(const StaPipBagPackage& pkg) { + if (!renderBBox) return CoreBBoxFrustum::OUTSIDE_FRUSTUM; + if (pkg.size <= (maxVertCount / 3)) { // Is subpackage auto& bbox = renderBBox->getChildBBox1By3(pkg.indexOf1By3BBox); return bbox.clipIsInFrustum(frustumPlanes->getAll(), *pkg.bag->info->model); @@ -112,7 +114,7 @@ CoreBBoxFrustum StdpipBagPackager::checkFrustum(const StdpipBagPackage& pkg) { } } -void StdpipBagPackager::setMaxVertCount(const u32& count) { +void StaPipBagPackager::setMaxVertCount(const u32& count) { maxVertCount = count; } diff --git a/engine/src/renderer/3d/pipeline/std/core/bag/packaging/stdpip_bag_packages_bbox.cpp b/engine/src/renderer/3d/pipeline/static/core/bag/packaging/stapip_bag_packages_bbox.cpp similarity index 77% rename from engine/src/renderer/3d/pipeline/std/core/bag/packaging/stdpip_bag_packages_bbox.cpp rename to engine/src/renderer/3d/pipeline/static/core/bag/packaging/stapip_bag_packages_bbox.cpp index f08f25f..c802719 100644 --- a/engine/src/renderer/3d/pipeline/std/core/bag/packaging/stdpip_bag_packages_bbox.cpp +++ b/engine/src/renderer/3d/pipeline/static/core/bag/packaging/stapip_bag_packages_bbox.cpp @@ -11,13 +11,14 @@ #include #include #include +#include #include #include "debug/debug.hpp" -#include "renderer/3d/pipeline/std/core/bag/packaging/stdpip_bag_packages_bbox.hpp" +#include "renderer/3d/pipeline/static/core/bag/packaging/stapip_bag_packages_bbox.hpp" namespace Tyra { -StdpipBagPackagesBBox::StdpipBagPackagesBBox(Vec4* t_vertices, u32* t_faces, +StaPipBagPackagesBBox::StaPipBagPackagesBBox(Vec4* t_vertices, u32* t_faces, const u32& t_facesCount, const u32& t_maxVertCount) { u32 splitPartSize = t_maxVertCount / 3; @@ -34,7 +35,7 @@ StdpipBagPackagesBBox::StdpipBagPackagesBBox(Vec4* t_vertices, u32* t_faces, mainBBox = new RenderBBox(*bboxParts, 0, partsCount); } -StdpipBagPackagesBBox::StdpipBagPackagesBBox(Vec4* t_vertices, +StaPipBagPackagesBBox::StaPipBagPackagesBBox(Vec4* t_vertices, const u32& t_count, const u32& t_maxVertCount) { u32 splitPartSize = t_maxVertCount / 3; @@ -51,40 +52,40 @@ StdpipBagPackagesBBox::StdpipBagPackagesBBox(Vec4* t_vertices, mainBBox = new RenderBBox(*bboxParts, 0, partsCount); } -const RenderBBox& StdpipBagPackagesBBox::getChildBBox1By3( +const RenderBBox& StaPipBagPackagesBBox::getChildBBox1By3( const u32& index) const { TYRA_ASSERT(index < partsCount, "Index out of range. Provided index: ", index); return static_cast(bboxParts->at(index)); } -RenderBBox* StdpipBagPackagesBBox::getMainBBox() { return mainBBox; } +RenderBBox* StaPipBagPackagesBBox::getMainBBox() { return mainBBox; } -const u32& StdpipBagPackagesBBox::getPartsCount() const { return partsCount; } +const u32& StaPipBagPackagesBBox::getPartsCount() const { return partsCount; } -const u32& StdpipBagPackagesBBox::getVertexCount() const { return vertexCount; } +const u32& StaPipBagPackagesBBox::getVertexCount() const { return vertexCount; } -RenderBBox StdpipBagPackagesBBox::createChildBBox(const u32& index, +RenderBBox StaPipBagPackagesBBox::createChildBBox(const u32& index, const u16& partsSize) const { return RenderBBox(*bboxParts, index, partsSize); } -void StdpipBagPackagesBBox::print() const { +void StaPipBagPackagesBBox::print() const { auto text = getPrint(nullptr); printf("%s\n", text.c_str()); } -void StdpipBagPackagesBBox::print(const char* name) const { +void StaPipBagPackagesBBox::print(const char* name) const { auto text = getPrint(name); printf("%s\n", text.c_str()); } -std::string StdpipBagPackagesBBox::getPrint(const char* name) const { +std::string StaPipBagPackagesBBox::getPrint(const char* name) const { std::stringstream res; if (name) { res << name << "("; } else { - res << "StdpipBagPackagesBBox("; + res << "StaPipBagPackagesBBox("; } res << std::fixed << std::setprecision(2); res << std::endl; @@ -105,7 +106,7 @@ std::string StdpipBagPackagesBBox::getPrint(const char* name) const { return res.str(); } -StdpipBagPackagesBBox::~StdpipBagPackagesBBox() { +StaPipBagPackagesBBox::~StaPipBagPackagesBBox() { delete bboxParts; delete mainBBox; } diff --git a/engine/src/renderer/3d/pipeline/std/core/bag/stdpip_bag.cpp b/engine/src/renderer/3d/pipeline/static/core/bag/stapip_bag.cpp similarity index 79% rename from engine/src/renderer/3d/pipeline/std/core/bag/stdpip_bag.cpp rename to engine/src/renderer/3d/pipeline/static/core/bag/stapip_bag.cpp index 16c3f9b..25830d8 100644 --- a/engine/src/renderer/3d/pipeline/std/core/bag/stdpip_bag.cpp +++ b/engine/src/renderer/3d/pipeline/static/core/bag/stapip_bag.cpp @@ -8,42 +8,43 @@ # Sandro Sobczyński */ -#include -#include "renderer/3d/pipeline/std/core/bag/stdpip_bag.hpp" +#include "renderer/3d/pipeline/static/core/bag/stapip_bag.hpp" +#include +#include namespace Tyra { -StdpipBag::StdpipBag() { +StaPipBag::StaPipBag() { info = nullptr; color = nullptr; texture = nullptr; lighting = nullptr; } -StdpipBag::~StdpipBag() {} +StaPipBag::~StaPipBag() {} -StdpipBagPackagesBBox StdpipBag::calculateBbox(const u32& maxVertCount) { +StaPipBagPackagesBBox StaPipBag::calculateBbox(const u32& maxVertCount) { TYRA_ASSERT(vertices != nullptr, "Vertices are required to calculate bbox"); TYRA_ASSERT(count > 0, "Count must be greater than 0 to calculate bbox"); - return StdpipBagPackagesBBox(vertices, count, maxVertCount); + return StaPipBagPackagesBBox(vertices, count, maxVertCount); } -void StdpipBag::print() const { +void StaPipBag::print() const { auto text = getPrint(nullptr); printf("%s\n", text.c_str()); } -void StdpipBag::print(const char* name) const { +void StaPipBag::print(const char* name) const { auto text = getPrint(name); printf("%s\n", text.c_str()); } -std::string StdpipBag::getPrint(const char* name) const { +std::string StaPipBag::getPrint(const char* name) const { std::stringstream res; if (name) { res << name << "("; } else { - res << "StdpipBag("; + res << "StaPipBag("; } res << std::fixed << std::setprecision(4); res << std::endl; @@ -62,7 +63,8 @@ std::string StdpipBag::getPrint(const char* name) const { if (color->single) { res << "Color single: " << color->single->getPrint() << ", " << std::endl; } else { - res << "Color many: " << color->many->getPrint() << ", " << std::endl; + res << "Color many present: " << (color->many != nullptr ? "Yes" : "No") + << ", " << std::endl; } if (texture) { res << "Texture coords present: " diff --git a/engine/src/renderer/3d/pipeline/std/core/bag/stdpip_color_bag.cpp b/engine/src/renderer/3d/pipeline/static/core/bag/stapip_color_bag.cpp similarity index 73% rename from engine/src/renderer/3d/pipeline/std/core/bag/stdpip_color_bag.cpp rename to engine/src/renderer/3d/pipeline/static/core/bag/stapip_color_bag.cpp index 2d50dbc..e428735 100644 --- a/engine/src/renderer/3d/pipeline/std/core/bag/stdpip_color_bag.cpp +++ b/engine/src/renderer/3d/pipeline/static/core/bag/stapip_color_bag.cpp @@ -8,15 +8,15 @@ # Sandro Sobczyński */ -#include "renderer/3d/pipeline/std/core/bag/stdpip_color_bag.hpp" +#include "renderer/3d/pipeline/static/core/bag/stapip_color_bag.hpp" namespace Tyra { -StdpipColorBag::StdpipColorBag() { +StaPipColorBag::StaPipColorBag() { single = nullptr; many = nullptr; } -StdpipColorBag::~StdpipColorBag() {} +StaPipColorBag::~StaPipColorBag() {} } // namespace Tyra diff --git a/engine/src/renderer/3d/pipeline/static/core/bag/stapip_lighting_bag.cpp b/engine/src/renderer/3d/pipeline/static/core/bag/stapip_lighting_bag.cpp new file mode 100644 index 0000000..8312d8e --- /dev/null +++ b/engine/src/renderer/3d/pipeline/static/core/bag/stapip_lighting_bag.cpp @@ -0,0 +1,23 @@ +/* +# ______ ____ ___ +# | \/ ____| |___| +# | | | \ | | +#----------------------------------------------------------------------- +# Copyright 2022, tyra - https://github.com/h4570/tyra +# Licenced under Apache License 2.0 +# Sandro Sobczyński +*/ + +#include "renderer/3d/pipeline/static/core/bag/stapip_lighting_bag.hpp" + +namespace Tyra { + +StaPipLightingBag::StaPipLightingBag() { + lightMatrix = nullptr; + normals = nullptr; + dirLights = nullptr; +} + +StaPipLightingBag::~StaPipLightingBag() {} + +} // namespace Tyra diff --git a/engine/src/renderer/3d/pipeline/std/core/bag/stdpip_texture_bag.cpp b/engine/src/renderer/3d/pipeline/static/core/bag/stapip_texture_bag.cpp similarity index 72% rename from engine/src/renderer/3d/pipeline/std/core/bag/stdpip_texture_bag.cpp rename to engine/src/renderer/3d/pipeline/static/core/bag/stapip_texture_bag.cpp index 34542a5..b643c48 100644 --- a/engine/src/renderer/3d/pipeline/std/core/bag/stdpip_texture_bag.cpp +++ b/engine/src/renderer/3d/pipeline/static/core/bag/stapip_texture_bag.cpp @@ -8,15 +8,15 @@ # Sandro Sobczyński */ -#include "renderer/3d/pipeline/std/core/bag/stdpip_texture_bag.hpp" +#include "renderer/3d/pipeline/static/core/bag/stapip_texture_bag.hpp" namespace Tyra { -StdpipTextureBag::StdpipTextureBag() { +StaPipTextureBag::StaPipTextureBag() { coordinates = nullptr; texture = nullptr; } -StdpipTextureBag::~StdpipTextureBag() {} +StaPipTextureBag::~StaPipTextureBag() {} } // namespace Tyra diff --git a/engine/src/renderer/3d/pipeline/std/core/path1/programs/as_is/stdpip_as_is_c_vu1.vclpp b/engine/src/renderer/3d/pipeline/static/core/programs/as_is/stapip_as_is_c_vu1.vclpp similarity index 90% rename from engine/src/renderer/3d/pipeline/std/core/path1/programs/as_is/stdpip_as_is_c_vu1.vclpp rename to engine/src/renderer/3d/pipeline/static/core/programs/as_is/stapip_as_is_c_vu1.vclpp index 49620cb..1c63352 100644 --- a/engine/src/renderer/3d/pipeline/std/core/path1/programs/as_is/stdpip_as_is_c_vu1.vclpp +++ b/engine/src/renderer/3d/pipeline/static/core/programs/as_is/stapip_as_is_c_vu1.vclpp @@ -13,14 +13,14 @@ ;--------------------------------------------------------------- .syntax new -.name StdpipVU1As_Is_C +.name StaPipVU1As_Is_C .vu .init_vf_all .init_vi_all -#include "src/renderer/core/paths/path1/programs/vcl_sml.i" -#include "src/renderer/core/paths/path1/programs/tyra_macros.i" -#include "inc/renderer/3d/pipeline/std/core/path1/programs/stdpip_vu1_shared_defines.h" +#include "src/renderer/3d/pipeline/shared/vcl_sml.i" +#include "src/renderer/3d/pipeline/shared/tyra_macros.i" +#include "inc/renderer/3d/pipeline/static/core/programs/stapip_vu1_shared_defines.h" #define RGBA_STORE_OFFSET 0 #define XYZ2_STORE_OFFSET 1 @@ -28,7 +28,7 @@ --enter --endenter -#vuprog StdpipVU1AsIsC +#vuprog StaPipVU1AsIsC LoadTyraStaticData{ gifSetTag } LoadTyraSingleColor{ singleColor, singleColorEnabled, VU1_SINGLE_COLOR_ADDR, VU1_OPTIONS_ADDR } diff --git a/engine/src/renderer/3d/pipeline/std/core/path1/programs/as_is/stdpip_as_is_c_vu1_program.cpp b/engine/src/renderer/3d/pipeline/static/core/programs/as_is/stapip_as_is_c_vu1_program.cpp similarity index 56% rename from engine/src/renderer/3d/pipeline/std/core/path1/programs/as_is/stdpip_as_is_c_vu1_program.cpp rename to engine/src/renderer/3d/pipeline/static/core/programs/as_is/stapip_as_is_c_vu1_program.cpp index 34091f6..b10900a 100644 --- a/engine/src/renderer/3d/pipeline/std/core/path1/programs/as_is/stdpip_as_is_c_vu1_program.cpp +++ b/engine/src/renderer/3d/pipeline/static/core/programs/as_is/stapip_as_is_c_vu1_program.cpp @@ -9,27 +9,27 @@ */ #include "debug/debug.hpp" -#include "renderer/3d/pipeline/std/core/path1/programs/as_is/stdpip_as_is_c_vu1_program.hpp" +#include "renderer/3d/pipeline/static/core/programs/as_is/stapip_as_is_c_vu1_program.hpp" -extern u32 StdpipVU1As_Is_C_CodeStart __attribute__((section(".vudata"))); -extern u32 StdpipVU1As_Is_C_CodeEnd __attribute__((section(".vudata"))); +extern u32 StaPipVU1As_Is_C_CodeStart __attribute__((section(".vudata"))); +extern u32 StaPipVU1As_Is_C_CodeEnd __attribute__((section(".vudata"))); namespace Tyra { -StdpipAsIsCVU1Program::StdpipAsIsCVU1Program() - : StdpipVU1Program(StdpipAsIsColor, &StdpipVU1As_Is_C_CodeStart, - &StdpipVU1As_Is_C_CodeEnd, +StaPipAsIsCVU1Program::StaPipAsIsCVU1Program() + : StaPipVU1Program(StaPipAsIsColor, &StaPipVU1As_Is_C_CodeStart, + &StaPipVU1As_Is_C_CodeEnd, ((u64)GIF_REG_RGBAQ) << 0 | ((u64)GIF_REG_XYZ2) << 4, 2, 2) {} -StdpipAsIsCVU1Program::~StdpipAsIsCVU1Program() {} +StaPipAsIsCVU1Program::~StaPipAsIsCVU1Program() {} -std::string StdpipAsIsCVU1Program::getStringName() const { - return std::string("As is - C"); +std::string StaPipAsIsCVU1Program::getStringName() const { + return std::string("StaPip - As is - C"); } -void StdpipAsIsCVU1Program::addProgramQBufferDataToPacket( - packet2_t* packet, StdpipQBuffer* qbuffer) const { +void StaPipAsIsCVU1Program::addProgramQBufferDataToPacket( + packet2_t* packet, StaPipQBuffer* qbuffer) const { u32 addr = VU1_VERT_DATA_ADDR; // Add vertices diff --git a/engine/src/renderer/3d/pipeline/std/core/path1/programs/as_is/stdpip_as_is_d_vu1.vclpp b/engine/src/renderer/3d/pipeline/static/core/programs/as_is/stapip_as_is_d_vu1.vclpp similarity index 90% rename from engine/src/renderer/3d/pipeline/std/core/path1/programs/as_is/stdpip_as_is_d_vu1.vclpp rename to engine/src/renderer/3d/pipeline/static/core/programs/as_is/stapip_as_is_d_vu1.vclpp index 52ea541..d9071fa 100644 --- a/engine/src/renderer/3d/pipeline/std/core/path1/programs/as_is/stdpip_as_is_d_vu1.vclpp +++ b/engine/src/renderer/3d/pipeline/static/core/programs/as_is/stapip_as_is_d_vu1.vclpp @@ -13,14 +13,14 @@ ;--------------------------------------------------------------- .syntax new -.name StdpipVU1As_Is_D +.name StaPipVU1As_Is_D .vu .init_vf_all .init_vi_all -#include "src/renderer/core/paths/path1/programs/vcl_sml.i" -#include "src/renderer/core/paths/path1/programs/tyra_macros.i" -#include "inc/renderer/3d/pipeline/std/core/path1/programs/stdpip_vu1_shared_defines.h" +#include "src/renderer/3d/pipeline/shared/vcl_sml.i" +#include "src/renderer/3d/pipeline/shared/tyra_macros.i" +#include "inc/renderer/3d/pipeline/static/core/programs/stapip_vu1_shared_defines.h" #define RGBA_STORE_OFFSET 0 #define XYZ2_STORE_OFFSET 1 @@ -28,7 +28,7 @@ --enter --endenter -#vuprog StdpipVU1AsIsD +#vuprog StaPipVU1AsIsD LoadTyraStaticData{ gifSetTag } LoadTyraDirectionalLights{ lightMatrix, lightDirections, lightColors, ambientColor, VU1_LIGHTS_DIRS_ADDR, VU1_LIGHTS_COLORS_ADDR, VU1_LIGHTS_MATRIX_ADDR } diff --git a/engine/src/renderer/3d/pipeline/std/core/path1/programs/as_is/stdpip_as_is_d_vu1_program.cpp b/engine/src/renderer/3d/pipeline/static/core/programs/as_is/stapip_as_is_d_vu1_program.cpp similarity index 60% rename from engine/src/renderer/3d/pipeline/std/core/path1/programs/as_is/stdpip_as_is_d_vu1_program.cpp rename to engine/src/renderer/3d/pipeline/static/core/programs/as_is/stapip_as_is_d_vu1_program.cpp index dac410e..ffd4552 100644 --- a/engine/src/renderer/3d/pipeline/std/core/path1/programs/as_is/stdpip_as_is_d_vu1_program.cpp +++ b/engine/src/renderer/3d/pipeline/static/core/programs/as_is/stapip_as_is_d_vu1_program.cpp @@ -9,27 +9,27 @@ */ #include "debug/debug.hpp" -#include "renderer/3d/pipeline/std/core/path1/programs/as_is/stdpip_as_is_d_vu1_program.hpp" +#include "renderer/3d/pipeline/static/core/programs/as_is/stapip_as_is_d_vu1_program.hpp" -extern u32 StdpipVU1As_Is_D_CodeStart __attribute__((section(".vudata"))); -extern u32 StdpipVU1As_Is_D_CodeEnd __attribute__((section(".vudata"))); +extern u32 StaPipVU1As_Is_D_CodeStart __attribute__((section(".vudata"))); +extern u32 StaPipVU1As_Is_D_CodeEnd __attribute__((section(".vudata"))); namespace Tyra { -StdpipAsIsDVU1Program::StdpipAsIsDVU1Program() - : StdpipVU1Program(StdpipAsIsDirLights, &StdpipVU1As_Is_D_CodeStart, - &StdpipVU1As_Is_D_CodeEnd, +StaPipAsIsDVU1Program::StaPipAsIsDVU1Program() + : StaPipVU1Program(StaPipAsIsDirLights, &StaPipVU1As_Is_D_CodeStart, + &StaPipVU1As_Is_D_CodeEnd, ((u64)GIF_REG_RGBAQ) << 0 | ((u64)GIF_REG_XYZ2) << 4, 2, 3) {} -StdpipAsIsDVU1Program::~StdpipAsIsDVU1Program() {} +StaPipAsIsDVU1Program::~StaPipAsIsDVU1Program() {} -std::string StdpipAsIsDVU1Program::getStringName() const { - return std::string("As is - LC"); +std::string StaPipAsIsDVU1Program::getStringName() const { + return std::string("StaPip - As is - D"); } -void StdpipAsIsDVU1Program::addProgramQBufferDataToPacket( - packet2_t* packet, StdpipQBuffer* qbuffer) const { +void StaPipAsIsDVU1Program::addProgramQBufferDataToPacket( + packet2_t* packet, StaPipQBuffer* qbuffer) const { u32 addr = VU1_VERT_DATA_ADDR; // Add vertices diff --git a/engine/src/renderer/3d/pipeline/std/core/path1/programs/as_is/stdpip_as_is_tc_vu1.vclpp b/engine/src/renderer/3d/pipeline/static/core/programs/as_is/stapip_as_is_tc_vu1.vclpp similarity index 91% rename from engine/src/renderer/3d/pipeline/std/core/path1/programs/as_is/stdpip_as_is_tc_vu1.vclpp rename to engine/src/renderer/3d/pipeline/static/core/programs/as_is/stapip_as_is_tc_vu1.vclpp index ab40535..90775ab 100644 --- a/engine/src/renderer/3d/pipeline/std/core/path1/programs/as_is/stdpip_as_is_tc_vu1.vclpp +++ b/engine/src/renderer/3d/pipeline/static/core/programs/as_is/stapip_as_is_tc_vu1.vclpp @@ -13,14 +13,14 @@ ;--------------------------------------------------------------- .syntax new -.name StdpipVU1As_Is_TC +.name StaPipVU1As_Is_TC .vu .init_vf_all .init_vi_all -#include "src/renderer/core/paths/path1/programs/vcl_sml.i" -#include "src/renderer/core/paths/path1/programs/tyra_macros.i" -#include "inc/renderer/3d/pipeline/std/core/path1/programs/stdpip_vu1_shared_defines.h" +#include "src/renderer/3d/pipeline/shared/vcl_sml.i" +#include "src/renderer/3d/pipeline/shared/tyra_macros.i" +#include "inc/renderer/3d/pipeline/static/core/programs/stapip_vu1_shared_defines.h" #define STQ_STORE_OFFSET 0 #define RGBA_STORE_OFFSET 1 @@ -29,7 +29,7 @@ --enter --endenter -#vuprog StdpipVU1AsIsTC +#vuprog StaPipVU1AsIsTC LoadTyraStaticData{ gifSetTag } LoadTyraSingleColor{ singleColor, singleColorEnabled, VU1_SINGLE_COLOR_ADDR, VU1_OPTIONS_ADDR } diff --git a/engine/src/renderer/3d/pipeline/std/core/path1/programs/as_is/stdpip_as_is_tc_vu1_program.cpp b/engine/src/renderer/3d/pipeline/static/core/programs/as_is/stapip_as_is_tc_vu1_program.cpp similarity index 61% rename from engine/src/renderer/3d/pipeline/std/core/path1/programs/as_is/stdpip_as_is_tc_vu1_program.cpp rename to engine/src/renderer/3d/pipeline/static/core/programs/as_is/stapip_as_is_tc_vu1_program.cpp index 66b3261..9ae6de8 100644 --- a/engine/src/renderer/3d/pipeline/std/core/path1/programs/as_is/stdpip_as_is_tc_vu1_program.cpp +++ b/engine/src/renderer/3d/pipeline/static/core/programs/as_is/stapip_as_is_tc_vu1_program.cpp @@ -9,28 +9,28 @@ */ #include "debug/debug.hpp" -#include "renderer/3d/pipeline/std/core/path1/programs/as_is/stdpip_as_is_tc_vu1_program.hpp" +#include "renderer/3d/pipeline/static/core/programs/as_is/stapip_as_is_tc_vu1_program.hpp" -extern u32 StdpipVU1As_Is_TC_CodeStart __attribute__((section(".vudata"))); -extern u32 StdpipVU1As_Is_TC_CodeEnd __attribute__((section(".vudata"))); +extern u32 StaPipVU1As_Is_TC_CodeStart __attribute__((section(".vudata"))); +extern u32 StaPipVU1As_Is_TC_CodeEnd __attribute__((section(".vudata"))); namespace Tyra { -StdpipAsIsTCVU1Program::StdpipAsIsTCVU1Program() - : StdpipVU1Program(StdpipAsIsTextureColor, &StdpipVU1As_Is_TC_CodeStart, - &StdpipVU1As_Is_TC_CodeEnd, +StaPipAsIsTCVU1Program::StaPipAsIsTCVU1Program() + : StaPipVU1Program(StaPipAsIsTextureColor, &StaPipVU1As_Is_TC_CodeStart, + &StaPipVU1As_Is_TC_CodeEnd, ((u64)GIF_REG_ST) << 0 | ((u64)GIF_REG_RGBAQ) << 4 | ((u64)GIF_REG_XYZ2) << 8, 3, 3) {} -StdpipAsIsTCVU1Program::~StdpipAsIsTCVU1Program() {} +StaPipAsIsTCVU1Program::~StaPipAsIsTCVU1Program() {} -std::string StdpipAsIsTCVU1Program::getStringName() const { - return std::string("As is - TC"); +std::string StaPipAsIsTCVU1Program::getStringName() const { + return std::string("StaPip - As is - TC"); } -void StdpipAsIsTCVU1Program::addProgramQBufferDataToPacket( - packet2_t* packet, StdpipQBuffer* qbuffer) const { +void StaPipAsIsTCVU1Program::addProgramQBufferDataToPacket( + packet2_t* packet, StaPipQBuffer* qbuffer) const { u32 addr = VU1_VERT_DATA_ADDR; // Add vertices diff --git a/engine/src/renderer/3d/pipeline/std/core/path1/programs/as_is/stdpip_as_is_td_vu1.vclpp b/engine/src/renderer/3d/pipeline/static/core/programs/as_is/stapip_as_is_td_vu1.vclpp similarity index 91% rename from engine/src/renderer/3d/pipeline/std/core/path1/programs/as_is/stdpip_as_is_td_vu1.vclpp rename to engine/src/renderer/3d/pipeline/static/core/programs/as_is/stapip_as_is_td_vu1.vclpp index 966323f..b072c83 100644 --- a/engine/src/renderer/3d/pipeline/std/core/path1/programs/as_is/stdpip_as_is_td_vu1.vclpp +++ b/engine/src/renderer/3d/pipeline/static/core/programs/as_is/stapip_as_is_td_vu1.vclpp @@ -13,14 +13,14 @@ ;--------------------------------------------------------------- .syntax new -.name StdpipVU1As_Is_TD +.name StaPipVU1As_Is_TD .vu .init_vf_all .init_vi_all -#include "src/renderer/core/paths/path1/programs/vcl_sml.i" -#include "src/renderer/core/paths/path1/programs/tyra_macros.i" -#include "inc/renderer/3d/pipeline/std/core/path1/programs/stdpip_vu1_shared_defines.h" +#include "src/renderer/3d/pipeline/shared/vcl_sml.i" +#include "src/renderer/3d/pipeline/shared/tyra_macros.i" +#include "inc/renderer/3d/pipeline/static/core/programs/stapip_vu1_shared_defines.h" #define STQ_STORE_OFFSET 0 #define RGBA_STORE_OFFSET 1 @@ -29,7 +29,7 @@ --enter --endenter -#vuprog StdpipVU1AsIsTD +#vuprog StaPipVU1AsIsTD LoadTyraStaticData{ gifSetTag } LoadTyraDirectionalLights{ lightMatrix, lightDirections, lightColors, ambientColor, VU1_LIGHTS_DIRS_ADDR, VU1_LIGHTS_COLORS_ADDR, VU1_LIGHTS_MATRIX_ADDR } diff --git a/engine/src/renderer/3d/pipeline/std/core/path1/programs/as_is/stdpip_as_is_td_vu1_program.cpp b/engine/src/renderer/3d/pipeline/static/core/programs/as_is/stapip_as_is_td_vu1_program.cpp similarity index 64% rename from engine/src/renderer/3d/pipeline/std/core/path1/programs/as_is/stdpip_as_is_td_vu1_program.cpp rename to engine/src/renderer/3d/pipeline/static/core/programs/as_is/stapip_as_is_td_vu1_program.cpp index 8132b3b..605c7d3 100644 --- a/engine/src/renderer/3d/pipeline/std/core/path1/programs/as_is/stdpip_as_is_td_vu1_program.cpp +++ b/engine/src/renderer/3d/pipeline/static/core/programs/as_is/stapip_as_is_td_vu1_program.cpp @@ -9,28 +9,28 @@ */ #include "debug/debug.hpp" -#include "renderer/3d/pipeline/std/core/path1/programs/as_is/stdpip_as_is_td_vu1_program.hpp" +#include "renderer/3d/pipeline/static/core/programs/as_is/stapip_as_is_td_vu1_program.hpp" -extern u32 StdpipVU1As_Is_TD_CodeStart __attribute__((section(".vudata"))); -extern u32 StdpipVU1As_Is_TD_CodeEnd __attribute__((section(".vudata"))); +extern u32 StaPipVU1As_Is_TD_CodeStart __attribute__((section(".vudata"))); +extern u32 StaPipVU1As_Is_TD_CodeEnd __attribute__((section(".vudata"))); namespace Tyra { -StdpipAsIsTDVU1Program::StdpipAsIsTDVU1Program() - : StdpipVU1Program(StdpipAsIsTextureDirLights, &StdpipVU1As_Is_TD_CodeStart, - &StdpipVU1As_Is_TD_CodeEnd, +StaPipAsIsTDVU1Program::StaPipAsIsTDVU1Program() + : StaPipVU1Program(StaPipAsIsTextureDirLights, &StaPipVU1As_Is_TD_CodeStart, + &StaPipVU1As_Is_TD_CodeEnd, ((u64)GIF_REG_ST) << 0 | ((u64)GIF_REG_RGBAQ) << 4 | ((u64)GIF_REG_XYZ2) << 8, 3, 4) {} -StdpipAsIsTDVU1Program::~StdpipAsIsTDVU1Program() {} +StaPipAsIsTDVU1Program::~StaPipAsIsTDVU1Program() {} -std::string StdpipAsIsTDVU1Program::getStringName() const { - return std::string("As is - LTC"); +std::string StaPipAsIsTDVU1Program::getStringName() const { + return std::string("StaPip - As is - TD"); } -void StdpipAsIsTDVU1Program::addProgramQBufferDataToPacket( - packet2_t* packet, StdpipQBuffer* qbuffer) const { +void StaPipAsIsTDVU1Program::addProgramQBufferDataToPacket( + packet2_t* packet, StaPipQBuffer* qbuffer) const { u32 addr = VU1_VERT_DATA_ADDR; // Add vertices diff --git a/engine/src/renderer/3d/pipeline/std/core/path1/programs/cull/stdpip_cull_c_vu1.vclpp b/engine/src/renderer/3d/pipeline/static/core/programs/cull/stapip_cull_c_vu1.vclpp similarity index 91% rename from engine/src/renderer/3d/pipeline/std/core/path1/programs/cull/stdpip_cull_c_vu1.vclpp rename to engine/src/renderer/3d/pipeline/static/core/programs/cull/stapip_cull_c_vu1.vclpp index 8234ae3..27067f1 100644 --- a/engine/src/renderer/3d/pipeline/std/core/path1/programs/cull/stdpip_cull_c_vu1.vclpp +++ b/engine/src/renderer/3d/pipeline/static/core/programs/cull/stapip_cull_c_vu1.vclpp @@ -9,18 +9,18 @@ ;--------------------------------------------------------------- ; Triangle list ; Cull = Standard PS2 way. clipw polys are culled. -; Volors +; Colors ;--------------------------------------------------------------- .syntax new -.name StdpipVU1Cull_C +.name StaPipVU1Cull_C .vu .init_vf_all .init_vi_all -#include "src/renderer/core/paths/path1/programs/vcl_sml.i" -#include "src/renderer/core/paths/path1/programs/tyra_macros.i" -#include "inc/renderer/3d/pipeline/std/core/path1/programs/stdpip_vu1_shared_defines.h" +#include "src/renderer/3d/pipeline/shared/vcl_sml.i" +#include "src/renderer/3d/pipeline/shared/tyra_macros.i" +#include "inc/renderer/3d/pipeline/static/core/programs/stapip_vu1_shared_defines.h" #define RGBA_STORE_OFFSET 0 #define XYZ2_STORE_OFFSET 1 @@ -28,7 +28,7 @@ --enter --endenter -#vuprog StdpipVU1CullC +#vuprog StaPipVU1CullC ResetClipFlags{ } LoadTyraStaticData{ gifSetTag } diff --git a/engine/src/renderer/3d/pipeline/std/core/path1/programs/cull/stdpip_cull_c_vu1_program.cpp b/engine/src/renderer/3d/pipeline/static/core/programs/cull/stapip_cull_c_vu1_program.cpp similarity index 57% rename from engine/src/renderer/3d/pipeline/std/core/path1/programs/cull/stdpip_cull_c_vu1_program.cpp rename to engine/src/renderer/3d/pipeline/static/core/programs/cull/stapip_cull_c_vu1_program.cpp index 6bd1cf4..c8307aa 100644 --- a/engine/src/renderer/3d/pipeline/std/core/path1/programs/cull/stdpip_cull_c_vu1_program.cpp +++ b/engine/src/renderer/3d/pipeline/static/core/programs/cull/stapip_cull_c_vu1_program.cpp @@ -9,26 +9,26 @@ */ #include "debug/debug.hpp" -#include "renderer/3d/pipeline/std/core/path1/programs/cull/stdpip_cull_c_vu1_program.hpp" +#include "renderer/3d/pipeline/static/core/programs/cull/stapip_cull_c_vu1_program.hpp" -extern u32 StdpipVU1Cull_C_CodeStart __attribute__((section(".vudata"))); -extern u32 StdpipVU1Cull_C_CodeEnd __attribute__((section(".vudata"))); +extern u32 StaPipVU1Cull_C_CodeStart __attribute__((section(".vudata"))); +extern u32 StaPipVU1Cull_C_CodeEnd __attribute__((section(".vudata"))); namespace Tyra { -StdpipCullCVU1Program::StdpipCullCVU1Program() - : StdpipVU1Program( - StdpipCullColor, &StdpipVU1Cull_C_CodeStart, &StdpipVU1Cull_C_CodeEnd, +StaPipCullCVU1Program::StaPipCullCVU1Program() + : StaPipVU1Program( + StaPipCullColor, &StaPipVU1Cull_C_CodeStart, &StaPipVU1Cull_C_CodeEnd, ((u64)GIF_REG_RGBAQ) << 0 | ((u64)GIF_REG_XYZ2) << 4, 2, 2) {} -StdpipCullCVU1Program::~StdpipCullCVU1Program() {} +StaPipCullCVU1Program::~StaPipCullCVU1Program() {} -std::string StdpipCullCVU1Program::getStringName() const { - return std::string("Cull - C"); +std::string StaPipCullCVU1Program::getStringName() const { + return std::string("StaPip - Cull - C"); } -void StdpipCullCVU1Program::addProgramQBufferDataToPacket( - packet2_t* packet, StdpipQBuffer* qbuffer) const { +void StaPipCullCVU1Program::addProgramQBufferDataToPacket( + packet2_t* packet, StaPipQBuffer* qbuffer) const { u32 addr = VU1_VERT_DATA_ADDR; // Add vertices diff --git a/engine/src/renderer/3d/pipeline/std/core/path1/programs/cull/stdpip_cull_d_vu1.vclpp b/engine/src/renderer/3d/pipeline/static/core/programs/cull/stapip_cull_d_vu1.vclpp similarity index 91% rename from engine/src/renderer/3d/pipeline/std/core/path1/programs/cull/stdpip_cull_d_vu1.vclpp rename to engine/src/renderer/3d/pipeline/static/core/programs/cull/stapip_cull_d_vu1.vclpp index ffa857c..0894b9a 100644 --- a/engine/src/renderer/3d/pipeline/std/core/path1/programs/cull/stdpip_cull_d_vu1.vclpp +++ b/engine/src/renderer/3d/pipeline/static/core/programs/cull/stapip_cull_d_vu1.vclpp @@ -13,14 +13,14 @@ ;--------------------------------------------------------------- .syntax new -.name StdpipVU1Cull_D +.name StaPipVU1Cull_D .vu .init_vf_all .init_vi_all -#include "src/renderer/core/paths/path1/programs/vcl_sml.i" -#include "src/renderer/core/paths/path1/programs/tyra_macros.i" -#include "inc/renderer/3d/pipeline/std/core/path1/programs/stdpip_vu1_shared_defines.h" +#include "src/renderer/3d/pipeline/shared/vcl_sml.i" +#include "src/renderer/3d/pipeline/shared/tyra_macros.i" +#include "inc/renderer/3d/pipeline/static/core/programs/stapip_vu1_shared_defines.h" #define RGBA_STORE_OFFSET 0 #define XYZ2_STORE_OFFSET 1 @@ -28,7 +28,7 @@ --enter --endenter -#vuprog StdpipVU1CullD +#vuprog StaPipVU1CullD ResetClipFlags{ } LoadTyraStaticData{ gifSetTag } diff --git a/engine/src/renderer/3d/pipeline/std/core/path1/programs/cull/stdpip_cull_d_vu1_program.cpp b/engine/src/renderer/3d/pipeline/static/core/programs/cull/stapip_cull_d_vu1_program.cpp similarity index 60% rename from engine/src/renderer/3d/pipeline/std/core/path1/programs/cull/stdpip_cull_d_vu1_program.cpp rename to engine/src/renderer/3d/pipeline/static/core/programs/cull/stapip_cull_d_vu1_program.cpp index 9ac111c..6e32177 100644 --- a/engine/src/renderer/3d/pipeline/std/core/path1/programs/cull/stdpip_cull_d_vu1_program.cpp +++ b/engine/src/renderer/3d/pipeline/static/core/programs/cull/stapip_cull_d_vu1_program.cpp @@ -9,27 +9,27 @@ */ #include "debug/debug.hpp" -#include "renderer/3d/pipeline/std/core/path1/programs/cull/stdpip_cull_d_vu1_program.hpp" +#include "renderer/3d/pipeline/static/core/programs/cull/stapip_cull_d_vu1_program.hpp" -extern u32 StdpipVU1Cull_D_CodeStart __attribute__((section(".vudata"))); -extern u32 StdpipVU1Cull_D_CodeEnd __attribute__((section(".vudata"))); +extern u32 StaPipVU1Cull_D_CodeStart __attribute__((section(".vudata"))); +extern u32 StaPipVU1Cull_D_CodeEnd __attribute__((section(".vudata"))); namespace Tyra { -StdpipCullDVU1Program::StdpipCullDVU1Program() - : StdpipVU1Program(StdpipCullDirLights, &StdpipVU1Cull_D_CodeStart, - &StdpipVU1Cull_D_CodeEnd, +StaPipCullDVU1Program::StaPipCullDVU1Program() + : StaPipVU1Program(StaPipCullDirLights, &StaPipVU1Cull_D_CodeStart, + &StaPipVU1Cull_D_CodeEnd, ((u64)GIF_REG_RGBAQ) << 0 | ((u64)GIF_REG_XYZ2) << 4, 2, 3) {} -StdpipCullDVU1Program::~StdpipCullDVU1Program() {} +StaPipCullDVU1Program::~StaPipCullDVU1Program() {} -std::string StdpipCullDVU1Program::getStringName() const { - return std::string("Cull - LC"); +std::string StaPipCullDVU1Program::getStringName() const { + return std::string("StaPip - Cull - D"); } -void StdpipCullDVU1Program::addProgramQBufferDataToPacket( - packet2_t* packet, StdpipQBuffer* qbuffer) const { +void StaPipCullDVU1Program::addProgramQBufferDataToPacket( + packet2_t* packet, StaPipQBuffer* qbuffer) const { u32 addr = VU1_VERT_DATA_ADDR; // Add vertices diff --git a/engine/src/renderer/3d/pipeline/std/core/path1/programs/cull/stdpip_cull_tc_vu1.vclpp b/engine/src/renderer/3d/pipeline/static/core/programs/cull/stapip_cull_tc_vu1.vclpp similarity index 92% rename from engine/src/renderer/3d/pipeline/std/core/path1/programs/cull/stdpip_cull_tc_vu1.vclpp rename to engine/src/renderer/3d/pipeline/static/core/programs/cull/stapip_cull_tc_vu1.vclpp index cc2d0bb..5aae3b7 100644 --- a/engine/src/renderer/3d/pipeline/std/core/path1/programs/cull/stdpip_cull_tc_vu1.vclpp +++ b/engine/src/renderer/3d/pipeline/static/core/programs/cull/stapip_cull_tc_vu1.vclpp @@ -13,14 +13,14 @@ ;--------------------------------------------------------------- .syntax new -.name StdpipVU1Cull_TC +.name StaPipVU1Cull_TC .vu .init_vf_all .init_vi_all -#include "src/renderer/core/paths/path1/programs/vcl_sml.i" -#include "src/renderer/core/paths/path1/programs/tyra_macros.i" -#include "inc/renderer/3d/pipeline/std/core/path1/programs/stdpip_vu1_shared_defines.h" +#include "src/renderer/3d/pipeline/shared/vcl_sml.i" +#include "src/renderer/3d/pipeline/shared/tyra_macros.i" +#include "inc/renderer/3d/pipeline/static/core/programs/stapip_vu1_shared_defines.h" #define STQ_STORE_OFFSET 0 #define RGBA_STORE_OFFSET 1 @@ -29,7 +29,7 @@ --enter --endenter -#vuprog StdpipVU1CullTC +#vuprog StaPipVU1CullTC ResetClipFlags{ } LoadTyraStaticData{ gifSetTag } diff --git a/engine/src/renderer/3d/pipeline/std/core/path1/programs/cull/stdpip_cull_tc_vu1_program.cpp b/engine/src/renderer/3d/pipeline/static/core/programs/cull/stapip_cull_tc_vu1_program.cpp similarity index 61% rename from engine/src/renderer/3d/pipeline/std/core/path1/programs/cull/stdpip_cull_tc_vu1_program.cpp rename to engine/src/renderer/3d/pipeline/static/core/programs/cull/stapip_cull_tc_vu1_program.cpp index 6437241..9e5b1a5 100644 --- a/engine/src/renderer/3d/pipeline/std/core/path1/programs/cull/stdpip_cull_tc_vu1_program.cpp +++ b/engine/src/renderer/3d/pipeline/static/core/programs/cull/stapip_cull_tc_vu1_program.cpp @@ -9,28 +9,28 @@ */ #include "debug/debug.hpp" -#include "renderer/3d/pipeline/std/core/path1/programs/cull/stdpip_cull_tc_vu1_program.hpp" +#include "renderer/3d/pipeline/static/core/programs/cull/stapip_cull_tc_vu1_program.hpp" -extern u32 StdpipVU1Cull_TC_CodeStart __attribute__((section(".vudata"))); -extern u32 StdpipVU1Cull_TC_CodeEnd __attribute__((section(".vudata"))); +extern u32 StaPipVU1Cull_TC_CodeStart __attribute__((section(".vudata"))); +extern u32 StaPipVU1Cull_TC_CodeEnd __attribute__((section(".vudata"))); namespace Tyra { -StdpipCullTCVU1Program::StdpipCullTCVU1Program() - : StdpipVU1Program(StdpipCullTextureColor, &StdpipVU1Cull_TC_CodeStart, - &StdpipVU1Cull_TC_CodeEnd, +StaPipCullTCVU1Program::StaPipCullTCVU1Program() + : StaPipVU1Program(StaPipCullTextureColor, &StaPipVU1Cull_TC_CodeStart, + &StaPipVU1Cull_TC_CodeEnd, ((u64)GIF_REG_ST) << 0 | ((u64)GIF_REG_RGBAQ) << 4 | ((u64)GIF_REG_XYZ2) << 8, 3, 3) {} -StdpipCullTCVU1Program::~StdpipCullTCVU1Program() {} +StaPipCullTCVU1Program::~StaPipCullTCVU1Program() {} -std::string StdpipCullTCVU1Program::getStringName() const { - return std::string("Cull - TC"); +std::string StaPipCullTCVU1Program::getStringName() const { + return std::string("StaPip - Cull - TC"); } -void StdpipCullTCVU1Program::addProgramQBufferDataToPacket( - packet2_t* packet, StdpipQBuffer* qbuffer) const { +void StaPipCullTCVU1Program::addProgramQBufferDataToPacket( + packet2_t* packet, StaPipQBuffer* qbuffer) const { u32 addr = VU1_VERT_DATA_ADDR; // Add vertices diff --git a/engine/src/renderer/3d/pipeline/std/core/path1/programs/cull/stdpip_cull_td_vu1.vclpp b/engine/src/renderer/3d/pipeline/static/core/programs/cull/stapip_cull_td_vu1.vclpp similarity index 92% rename from engine/src/renderer/3d/pipeline/std/core/path1/programs/cull/stdpip_cull_td_vu1.vclpp rename to engine/src/renderer/3d/pipeline/static/core/programs/cull/stapip_cull_td_vu1.vclpp index 22877e8..3a7c3ff 100644 --- a/engine/src/renderer/3d/pipeline/std/core/path1/programs/cull/stdpip_cull_td_vu1.vclpp +++ b/engine/src/renderer/3d/pipeline/static/core/programs/cull/stapip_cull_td_vu1.vclpp @@ -13,14 +13,14 @@ ;--------------------------------------------------------------- .syntax new -.name StdpipVU1Cull_TD +.name StaPipVU1Cull_TD .vu .init_vf_all .init_vi_all -#include "src/renderer/core/paths/path1/programs/vcl_sml.i" -#include "src/renderer/core/paths/path1/programs/tyra_macros.i" -#include "inc/renderer/3d/pipeline/std/core/path1/programs/stdpip_vu1_shared_defines.h" +#include "src/renderer/3d/pipeline/shared/vcl_sml.i" +#include "src/renderer/3d/pipeline/shared/tyra_macros.i" +#include "inc/renderer/3d/pipeline/static/core/programs/stapip_vu1_shared_defines.h" #define STQ_STORE_OFFSET 0 #define RGBA_STORE_OFFSET 1 @@ -29,7 +29,7 @@ --enter --endenter -#vuprog StdpipVU1CullTD +#vuprog StaPipVU1CullTD ResetClipFlags{ } LoadTyraStaticData{ gifSetTag } diff --git a/engine/src/renderer/3d/pipeline/std/core/path1/programs/cull/stdpip_cull_td_vu1_program.cpp b/engine/src/renderer/3d/pipeline/static/core/programs/cull/stapip_cull_td_vu1_program.cpp similarity index 64% rename from engine/src/renderer/3d/pipeline/std/core/path1/programs/cull/stdpip_cull_td_vu1_program.cpp rename to engine/src/renderer/3d/pipeline/static/core/programs/cull/stapip_cull_td_vu1_program.cpp index 18c5ba4..9e94207 100644 --- a/engine/src/renderer/3d/pipeline/std/core/path1/programs/cull/stdpip_cull_td_vu1_program.cpp +++ b/engine/src/renderer/3d/pipeline/static/core/programs/cull/stapip_cull_td_vu1_program.cpp @@ -9,28 +9,28 @@ */ #include "debug/debug.hpp" -#include "renderer/3d/pipeline/std/core/path1/programs/cull/stdpip_cull_td_vu1_program.hpp" +#include "renderer/3d/pipeline/static/core/programs/cull/stapip_cull_td_vu1_program.hpp" -extern u32 StdpipVU1Cull_TD_CodeStart __attribute__((section(".vudata"))); -extern u32 StdpipVU1Cull_TD_CodeEnd __attribute__((section(".vudata"))); +extern u32 StaPipVU1Cull_TD_CodeStart __attribute__((section(".vudata"))); +extern u32 StaPipVU1Cull_TD_CodeEnd __attribute__((section(".vudata"))); namespace Tyra { -StdpipCullTDVU1Program::StdpipCullTDVU1Program() - : StdpipVU1Program(StdpipCullTextureDirLights, &StdpipVU1Cull_TD_CodeStart, - &StdpipVU1Cull_TD_CodeEnd, +StaPipCullTDVU1Program::StaPipCullTDVU1Program() + : StaPipVU1Program(StaPipCullTextureDirLights, &StaPipVU1Cull_TD_CodeStart, + &StaPipVU1Cull_TD_CodeEnd, ((u64)GIF_REG_ST) << 0 | ((u64)GIF_REG_RGBAQ) << 4 | ((u64)GIF_REG_XYZ2) << 8, 3, 4) {} -StdpipCullTDVU1Program::~StdpipCullTDVU1Program() {} +StaPipCullTDVU1Program::~StaPipCullTDVU1Program() {} -std::string StdpipCullTDVU1Program::getStringName() const { - return std::string("Cull - LTC"); +std::string StaPipCullTDVU1Program::getStringName() const { + return std::string("StaPip - Cull - TD"); } -void StdpipCullTDVU1Program::addProgramQBufferDataToPacket( - packet2_t* packet, StdpipQBuffer* qbuffer) const { +void StaPipCullTDVU1Program::addProgramQBufferDataToPacket( + packet2_t* packet, StaPipQBuffer* qbuffer) const { u32 addr = VU1_VERT_DATA_ADDR; // Add vertices diff --git a/engine/src/renderer/3d/pipeline/std/core/path1/stdpip_clipper.cpp b/engine/src/renderer/3d/pipeline/static/core/stapip_clipper.cpp similarity index 66% rename from engine/src/renderer/3d/pipeline/std/core/path1/stdpip_clipper.cpp rename to engine/src/renderer/3d/pipeline/static/core/stapip_clipper.cpp index 42f3d05..1bb847c 100644 --- a/engine/src/renderer/3d/pipeline/std/core/path1/stdpip_clipper.cpp +++ b/engine/src/renderer/3d/pipeline/static/core/stapip_clipper.cpp @@ -8,35 +8,35 @@ # Sandro Sobczyński */ -#include "renderer/3d/pipeline/std/core/path1/stdpip_clipper.hpp" +#include "renderer/3d/pipeline/static/core/stapip_clipper.hpp" namespace Tyra { -StdpipClipper::StdpipClipper() {} -StdpipClipper::~StdpipClipper() {} +StaPipClipper::StaPipClipper() {} +StaPipClipper::~StaPipClipper() {} -void StdpipClipper::setMVP(M4x4* t_mvp) { mvp = t_mvp; } +void StaPipClipper::setMVP(M4x4* t_mvp) { mvp = t_mvp; } -void StdpipClipper::init(const RendererSettings& settings) { +void StaPipClipper::init(const RendererSettings& settings) { algorithm.init(settings); } -void StdpipClipper::setMaxVertCount(const u32& count) { maxVertCount = count; } +void StaPipClipper::setMaxVertCount(const u32& count) { maxVertCount = count; } -void StdpipClipper::clip(StdpipQBuffer* buffer) { +void StaPipClipper::clip(StaPipQBuffer* buffer) { TYRA_ASSERT(buffer->size <= maxVertCount / 3, "Buffer should have max ", maxVertCount / 3, " verts if we want to clip it."); - Path1EEClipAlgorithmSettings algoSettings = { - buffer->bag->lighting != nullptr, buffer->bag->texture != nullptr, - buffer->bag->color->many != nullptr}; + EEClipAlgorithmSettings algoSettings = {buffer->bag->lighting != nullptr, + buffer->bag->texture != nullptr, + buffer->bag->color->many != nullptr}; - std::vector clippedVertices; + std::vector clippedVertices; for (u32 i = 0; i < buffer->size / 3; i++) { - std::vector inputTriangle; + std::vector inputTriangle; for (u8 j = 0; j < 3; j++) { - Path1ClipVertex vert = { + EEClipVertex vert = { *mvp * buffer->vertices[i * 3 + j], buffer->bag->lighting ? buffer->normals[i * 3 + j] : Vec4(), buffer->bag->texture ? buffer->sts[i * 3 + j] : Vec4(), @@ -45,7 +45,7 @@ void StdpipClipper::clip(StdpipQBuffer* buffer) { inputTriangle.push_back(vert); } - std::vector clippedTriangle; + std::vector clippedTriangle; algorithm.clip(&clippedTriangle, inputTriangle, algoSettings); if (clippedTriangle.size() == 0) continue; @@ -64,14 +64,14 @@ void StdpipClipper::clip(StdpipQBuffer* buffer) { moveDataToBuffer(clippedVertices, buffer); } -void StdpipClipper::perspectiveDivide(std::vector* vertices) { +void StaPipClipper::perspectiveDivide(std::vector* vertices) { for (u32 i = 0; i < vertices->size(); i++) { (*vertices)[i].position /= (*vertices)[i].position.w; } } -void StdpipClipper::moveDataToBuffer( - const std::vector& vertices, StdpipQBuffer* buffer) { +void StaPipClipper::moveDataToBuffer(const std::vector& vertices, + StaPipQBuffer* buffer) { buffer->reallocateManually(vertices.size()); for (u32 i = 0; i < vertices.size(); i++) { diff --git a/engine/src/renderer/3d/pipeline/std/core/std_pipeline_core.cpp b/engine/src/renderer/3d/pipeline/static/core/stapip_core.cpp similarity index 68% rename from engine/src/renderer/3d/pipeline/std/core/std_pipeline_core.cpp rename to engine/src/renderer/3d/pipeline/static/core/stapip_core.cpp index 3444b94..efb179b 100644 --- a/engine/src/renderer/3d/pipeline/std/core/std_pipeline_core.cpp +++ b/engine/src/renderer/3d/pipeline/static/core/stapip_core.cpp @@ -8,7 +8,7 @@ # Sandro Sobczyński */ -#include "renderer/3d/pipeline/std/core/std_pipeline_core.hpp" +#include "renderer/3d/pipeline/static/core/stapip_core.hpp" #include "renderer/core/renderer_core.hpp" #include "thread/threading.hpp" @@ -22,34 +22,33 @@ namespace Tyra { -StdPipelineCore::StdPipelineCore() { maxVertCount = 0; } +StaPipCore::StaPipCore() { maxVertCount = 0; } -StdPipelineCore::~StdPipelineCore() {} +StaPipCore::~StaPipCore() {} -void StdPipelineCore::init(RendererCore* t_core) { +void StaPipCore::init(RendererCore* t_core) { rendererCore = t_core; qbufferRenderer.init(t_core); packager.init(&rendererCore->renderer3D.frustumPlanes); } -void StdPipelineCore::reinitStandardVU1Programs() { - qbufferRenderer.reinitVU1(); -} +void StaPipCore::reinitVU1Programs() { qbufferRenderer.reinitVU1(); } -u32 StdPipelineCore::getMaxVertCountByBag(const StdpipBag* bag) { +u32 StaPipCore::getMaxVertCountByBag(const StaPipBag* bag) { return qbufferRenderer.getCullProgramByBag(bag)->getMaxVertCount( bag->color->many == nullptr, qbufferRenderer.getBufferSize()); } -u32 StdPipelineCore::getMaxVertCountByParams(const bool& isSingleColor, - const bool& isLightingEnabled, - const bool& isTextureEnabled) { +u32 StaPipCore::getMaxVertCountByParams(const bool& isSingleColor, + const bool& isLightingEnabled, + const bool& isTextureEnabled) { return qbufferRenderer .getCullProgramByParams(isLightingEnabled, isTextureEnabled) ->getMaxVertCount(isSingleColor, qbufferRenderer.getBufferSize()); } -void StdPipelineCore::render(StdpipBag* bag, StdpipBagPackagesBBox* bbox) { +void StaPipCore::render(StaPipBag* bag, const bool& frustumCull, + StaPipBagPackagesBBox* bbox) { if (bag->count <= 0) return; TYRA_ASSERT(bag->vertices != nullptr, @@ -65,30 +64,40 @@ void StdPipelineCore::render(StdpipBag* bag, StdpipBagPackagesBBox* bbox) { (!bag->color->many && bag->lighting), "Multicolor is not supported with lighting, please choose one!"); TYRA_ASSERT( - !bag->lighting || (bag->lighting->lightMatrix && bag->lighting->normals), - "If you want lighting, please provide light matrix and normals!"); + !bag->lighting || (bag->lighting->lightMatrix && bag->lighting->normals && + bag->lighting->dirLights), + "If you want lighting, please provide light matrix normals and dir " + "lights!"); TYRA_ASSERT( !bag->texture || (bag->texture->texture && bag->texture->coordinates), "If you want texture, please provide texture and coordinates!"); - - StdpipBagPackagesBBox* renderBbox; + TYRA_ASSERT(!(frustumCull == false && bag->info->fullClipChecks == true), + "Full clip checks are not supported with frustum culling = off!"); u32 maxVertCount = getMaxVertCountByBag(bag); - setMaxVertCount(maxVertCount); - if (!bbox) - renderBbox = - new StdpipBagPackagesBBox(bag->vertices, bag->count, maxVertCount); - else - renderBbox = bbox; + StaPipBagPackagesBBox* renderBbox = nullptr; + + CoreBBoxFrustum frustumCheck = OUTSIDE_FRUSTUM; + + if (frustumCull) { + if (!bbox) + renderBbox = + new StaPipBagPackagesBBox(bag->vertices, bag->count, maxVertCount); + else + renderBbox = bbox; + + frustumCheck = renderBbox->getMainBBox()->clipIsInFrustum( + rendererCore->renderer3D.frustumPlanes.getAll(), *bag->info->model); + + if (frustumCheck == OUTSIDE_FRUSTUM) return; + } + + packager.setRenderBBox(renderBbox); - auto frustumCheck = renderBbox->getMainBBox()->clipIsInFrustum( - rendererCore->renderer3D.frustumPlanes.getAll(), *bag->info->model); auto mvp = rendererCore->renderer3D.getViewProj() * *bag->info->model; - if (frustumCheck == OUTSIDE_FRUSTUM) return; - RendererCoreTextureBuffers* texBuffers = nullptr; if (bag->texture) { auto temp = rendererCore->texture.useTexture(bag->texture->texture); @@ -99,14 +108,28 @@ void StdPipelineCore::render(StdpipBag* bag, StdpipBagPackagesBBox* bbox) { qbufferRenderer.sendObjectData(bag, &mvp, texBuffers); - packager.setRenderBBox(renderBbox); - qbufferRenderer.setClipperMVP(&mvp); qbufferRenderer.setInfo(bag->info); - if (frustumCheck == IN_FRUSTUM || - (frustumCheck == PARTIALLY_IN_FRUSTUM && bag->info->noClipChecks)) { + auto checkYesFrustumInClipYes = // cull all + frustumCull && frustumCheck == IN_FRUSTUM && bag->info->fullClipChecks; + + auto checkYesFrustumPartialClipYes = // pkgs, cull + clip + frustumCull && frustumCheck == PARTIALLY_IN_FRUSTUM && + bag->info->fullClipChecks; + + auto checkYesFrustumInClipNo = // cull all + frustumCull && frustumCheck == IN_FRUSTUM && !bag->info->fullClipChecks; + + auto checkYesFrustumPartialClipNo = // pkgs, cull all + frustumCull && frustumCheck == PARTIALLY_IN_FRUSTUM && + !bag->info->fullClipChecks; + + auto checkNoClipNo = // cull all + !frustumCull && !bag->info->fullClipChecks; + + if (checkYesFrustumInClipYes || checkYesFrustumInClipNo || checkNoClipNo) { u16 packagesCount = 0; auto biggerPkgs = packager.create(&packagesCount, bag, maxVertCount); Verbose("Material - in frustum. Pkgs: ", packagesCount, @@ -118,12 +141,13 @@ void StdPipelineCore::render(StdpipBag* bag, StdpipBagPackagesBBox* bbox) { qbufferRenderer.cull(buffer); } delete[] biggerPkgs; - } else if (frustumCheck == PARTIALLY_IN_FRUSTUM) { + } else if (checkYesFrustumPartialClipYes || checkYesFrustumPartialClipNo) { u16 packagesCount = 0; - if (bag->count >= maxVertCount * 2) { + auto doClip = checkYesFrustumPartialClipYes; + if (!doClip || bag->count >= maxVertCount * 2) { auto packages = packager.create(&packagesCount, bag, maxVertCount); Verbose("Material - partial. Packages: ", packagesCount); - renderPkgs(packages, packagesCount); + renderPkgs(packages, doClip, packagesCount); delete[] packages; } else { auto subpkgs = packager.create(&packagesCount, bag, maxVertCount / 3); @@ -133,22 +157,26 @@ void StdPipelineCore::render(StdpipBag* bag, StdpipBagPackagesBBox* bbox) { } } - if (!bbox) delete renderBbox; + if (frustumCull && !bbox) delete renderBbox; if (texBuffers) delete texBuffers; - Threading::switchThread(); + qbufferRenderer.flushBuffers(); Verbose("Render finished"); } -void StdPipelineCore::renderPkgs(StdpipBagPackage* packages, u16 count) { +void StaPipCore::renderPkgs(StaPipBagPackage* packages, const bool& doClip, + u16 count) { for (u16 i = 0; i < count; i++) { - if (packages[i].isInFrustum == IN_FRUSTUM) { + auto cull = (doClip && packages[i].isInFrustum == IN_FRUSTUM) || !doClip; + auto doSubpkgs = doClip && packages[i].isInFrustum == PARTIALLY_IN_FRUSTUM; + + if (cull) { Verbose(i, " - package in frustum -> cull"); auto buffer = qbufferRenderer.getBuffer(); buffer->fillByPointer(packages[i]); qbufferRenderer.cull(buffer); - } else if (packages[i].isInFrustum == PARTIALLY_IN_FRUSTUM) { + } else if (doSubpkgs) { u16 subpkgsSize = 0; auto packages1By3 = packager.create(&subpkgsSize, packages[i], maxVertCount / 3); @@ -161,7 +189,7 @@ void StdPipelineCore::renderPkgs(StdpipBagPackage* packages, u16 count) { } } -void StdPipelineCore::renderSubpkgs(StdpipBagPackage* subpkgs, u16 count) { +void StaPipCore::renderSubpkgs(StaPipBagPackage* subpkgs, u16 count) { std::vector doneIndexes; std::vector loadedIndexes; @@ -218,7 +246,7 @@ void StdPipelineCore::renderSubpkgs(StdpipBagPackage* subpkgs, u16 count) { } } -void StdPipelineCore::setMaxVertCount(const u32& count) { +void StaPipCore::setMaxVertCount(const u32& count) { maxVertCount = count; packager.setMaxVertCount(count); qbufferRenderer.setMaxVertCount(count); diff --git a/engine/src/renderer/3d/pipeline/static/core/stapip_programs_repository.cpp b/engine/src/renderer/3d/pipeline/static/core/stapip_programs_repository.cpp new file mode 100644 index 0000000..dcf5c72 --- /dev/null +++ b/engine/src/renderer/3d/pipeline/static/core/stapip_programs_repository.cpp @@ -0,0 +1,48 @@ +/* +# ______ ____ ___ +# | \/ ____| |___| +# | | | \ | | +#----------------------------------------------------------------------- +# Copyright 2022, tyra - https://github.com/h4570/tyra +# Licenced under Apache License 2.0 +# Sandro Sobczyński +*/ + +#include "renderer/3d/pipeline/static/core/stapip_programs_repository.hpp" + +namespace Tyra { + +StaPipProgramsRepository::StaPipProgramsRepository() {} + +StaPipProgramsRepository::~StaPipProgramsRepository() {} + +StaPipVU1Program* StaPipProgramsRepository::getProgram( + const StaPipProgramName& name) { + switch (name) { + case StaPipProgramName::StaPipAsIsColor: + return &asIsColor; + case StaPipProgramName::StaPipCullColor: + return &cullColor; + + case StaPipProgramName::StaPipAsIsDirLights: + return &asIsDirLights; + case StaPipProgramName::StaPipCullDirLights: + return &cullDirLights; + + case StaPipProgramName::StaPipAsIsTextureDirLights: + return &asIsTextureDirLights; + case StaPipProgramName::StaPipCullTextureDirLights: + return &cullTextureDirLights; + + case StaPipProgramName::StaPipAsIsTextureColor: + return &asIsTextureColor; + case StaPipProgramName::StaPipCullTextureColor: + return &cullTextureColor; + + default: + TYRA_TRAP("Unknown VU1 program name"); + return &cullTextureDirLights; + } +} + +} // namespace Tyra diff --git a/engine/src/renderer/3d/pipeline/std/core/path1/stdpip_qbuffer.cpp b/engine/src/renderer/3d/pipeline/static/core/stapip_qbuffer.cpp similarity index 84% rename from engine/src/renderer/3d/pipeline/std/core/path1/stdpip_qbuffer.cpp rename to engine/src/renderer/3d/pipeline/static/core/stapip_qbuffer.cpp index c650943..03825a6 100644 --- a/engine/src/renderer/3d/pipeline/std/core/path1/stdpip_qbuffer.cpp +++ b/engine/src/renderer/3d/pipeline/static/core/stapip_qbuffer.cpp @@ -8,11 +8,13 @@ # Sandro Sobczyński */ -#include "renderer/3d/pipeline/std/core/path1/stdpip_qbuffer.hpp" +#include "renderer/3d/pipeline/static/core/stapip_qbuffer.hpp" +#include +#include namespace Tyra { -StdpipQBuffer::StdpipQBuffer() { +StaPipQBuffer::StaPipQBuffer() { size = 0; _isDynamicallyAllocated = false; _stAllocated = false; @@ -25,11 +27,11 @@ StdpipQBuffer::StdpipQBuffer() { normals = nullptr; } -StdpipQBuffer::~StdpipQBuffer() { deallocateDynamicData(); } +StaPipQBuffer::~StaPipQBuffer() { deallocateDynamicData(); } -void StdpipQBuffer::setMaxVertCount(const u32& count) { maxVertCount = count; } +void StaPipQBuffer::setMaxVertCount(const u32& count) { maxVertCount = count; } -void StdpipQBuffer::fillByPointer(const StdpipBagPackage& pkg) { +void StaPipQBuffer::fillByPointer(const StaPipBagPackage& pkg) { TYRA_ASSERT(pkg.size <= maxVertCount, "VU1 buffer supports only ", maxVertCount, " verts. Provided: ", pkg.size); @@ -43,9 +45,9 @@ void StdpipQBuffer::fillByPointer(const StdpipBagPackage& pkg) { bag = pkg.bag; } -void StdpipQBuffer::fillByCopyMax(const StdpipBagPackage& pkg1, - const StdpipBagPackage& pkg2, - const StdpipBagPackage& pkg3) { +void StaPipQBuffer::fillByCopyMax(const StaPipBagPackage& pkg1, + const StaPipBagPackage& pkg2, + const StaPipBagPackage& pkg3) { TYRA_ASSERT(pkg1.size <= maxVertCount / 3, "Wrong package size (1). Provided: ", pkg1.size); TYRA_ASSERT(pkg2.size <= maxVertCount / 3, @@ -95,8 +97,8 @@ void StdpipQBuffer::fillByCopyMax(const StdpipBagPackage& pkg1, bag = pkg1.bag; } -void StdpipQBuffer::fillByCopy1By2(const StdpipBagPackage& pkg1, - const StdpipBagPackage& pkg2) { +void StaPipQBuffer::fillByCopy1By2(const StaPipBagPackage& pkg1, + const StaPipBagPackage& pkg2) { TYRA_ASSERT(pkg1.size <= maxVertCount / 3, "Wrong package size (1). Provided: ", pkg1.size); TYRA_ASSERT(pkg2.size <= maxVertCount / 3, @@ -131,7 +133,7 @@ void StdpipQBuffer::fillByCopy1By2(const StdpipBagPackage& pkg1, bag = pkg1.bag; } -void StdpipQBuffer::fillByCopy1By3(const StdpipBagPackage& pkg) { +void StaPipQBuffer::fillByCopy1By3(const StaPipBagPackage& pkg) { TYRA_ASSERT(pkg.size <= maxVertCount / 3, "Wrong package size (1). Provided: ", pkg.size); @@ -153,13 +155,13 @@ void StdpipQBuffer::fillByCopy1By3(const StdpipBagPackage& pkg) { bag = pkg.bag; } -void StdpipQBuffer::reallocateManually(const u16& t_size) { +void StaPipQBuffer::reallocateManually(const u16& t_size) { deallocateDynamicData(); allocateDynamicData(t_size, bag); size = t_size; } -void StdpipQBuffer::deallocateDynamicData() { +void StaPipQBuffer::deallocateDynamicData() { if (_isDynamicallyAllocated) { delete[] vertices; @@ -184,7 +186,7 @@ void StdpipQBuffer::deallocateDynamicData() { /** When we not receive maxVertCount vertices, we must align it by ourself. * Too bad - not efficient. */ -void StdpipQBuffer::allocateDynamicData(u16 size, StdpipBag* bag) { +void StaPipQBuffer::allocateDynamicData(u16 size, StaPipBag* bag) { TYRA_ASSERT(size <= maxVertCount, "Wrong size. Max buffer size in VU1 is ", maxVertCount, ". Provided: ", size); TYRA_ASSERT(!_isDynamicallyAllocated, "Buffer is already allocated"); @@ -209,30 +211,30 @@ void StdpipQBuffer::allocateDynamicData(u16 size, StdpipBag* bag) { _isDynamicallyAllocated = true; } -bool StdpipQBuffer::any() const { return size > 0; } +bool StaPipQBuffer::any() const { return size > 0; } -void StdpipQBuffer::print() const { +void StaPipQBuffer::print() const { auto text = getPrint(nullptr); printf("%s\n", text.c_str()); } -void StdpipQBuffer::print(const char* name) const { +void StaPipQBuffer::print(const char* name) const { auto text = getPrint(name); printf("%s\n", text.c_str()); } -std::string StdpipQBuffer::getPrint(const char* name) const { +std::string StaPipQBuffer::getPrint(const char* name) const { std::stringstream res; if (name) { res << name << "("; } else { - res << "Path1Buffer("; + res << "StaPipQBuffer("; } res << std::fixed << std::setprecision(2); res << std::endl; res << "Size: " << static_cast(size) << std::endl; - res << "Vectors: " << std::endl; + res << "Vertices: " << std::endl; for (u32 i = 0; i < size; i++) res << i << ": " << vertices[i].getPrint() << std::endl; diff --git a/engine/src/renderer/3d/pipeline/static/core/stapip_qbuffer_renderer.cpp b/engine/src/renderer/3d/pipeline/static/core/stapip_qbuffer_renderer.cpp new file mode 100644 index 0000000..4c9eb45 --- /dev/null +++ b/engine/src/renderer/3d/pipeline/static/core/stapip_qbuffer_renderer.cpp @@ -0,0 +1,381 @@ +/* +# ______ ____ ___ +# | \/ ____| |___| +# | | | \ | | +#----------------------------------------------------------------------- +# Copyright 2022, tyra - https://github.com/h4570/tyra +# Licenced under Apache License 2.0 +# Sandro Sobczyński +*/ + +#include "renderer/3d/pipeline/static/core/stapip_qbuffer_renderer.hpp" +#include "renderer/3d/pipeline/static/core/programs/stapip_vu1_shared_defines.h" + +namespace Tyra { + +/** + * VU1 = 1000 vert + * + * Quadbuffering: + * 2 main buffers = 1000 / 2 = 500 vert + * 2 kick buffers = 500 / 2 = 250 vert + * + * Vert data: + * Pos + Normal + ST + Color = 4 + * = 4 * 48 = 192 + * + * Other data: + * mvp matrix, light matrix, tags = 14 + * 20 light vectors, light intesities = 25 + * = 14 + 25 = 39 + * + * All data: + * = 192 + 39 = 231 + * + */ + +const u16 StaPipQBufferRenderer::buffersCount = 16; + +StaPipQBufferRenderer::StaPipQBufferRenderer() { + currentBufferIndex = 0; + nextBufferIndex = 0; + context = 0; + lastProgramName = StaPipUndefinedProgram; + + qbuffersPacketSize = 4 * buffersCount; + programsPacket = nullptr; +} + +void StaPipQBufferRenderer::allocateOnUse() { + staticDataPacket = packet2_create(3, P2_TYPE_NORMAL, P2_MODE_CHAIN, true); + objectDataPacket = packet2_create(16, P2_TYPE_NORMAL, P2_MODE_CHAIN, true); + + packets = new packet2_t*[buffersCount]; + for (u16 i = 0; i < 2; i++) + packets[i] = + packet2_create(qbuffersPacketSize, P2_TYPE_NORMAL, P2_MODE_CHAIN, true); + + buffers = new StaPipQBuffer*[buffersCount]; + for (u16 i = 0; i < buffersCount; i++) { + buffers[i] = new StaPipQBuffer(); + } + + dBufferPrograms = new StaPipVU1Program*[buffersCount]; + + sendStaticData(); +} + +void StaPipQBufferRenderer::deallocateOnUse() { + packet2_free(staticDataPacket); + packet2_free(objectDataPacket); + + for (u16 i = 0; i < 2; i++) packet2_free(packets[i]); + delete[] packets; + + for (u16 i = 0; i < buffersCount; i++) delete buffers[i]; + delete[] buffers; + + delete[] dBufferPrograms; +} + +StaPipQBufferRenderer::~StaPipQBufferRenderer() { + if (programsPacket) packet2_free(programsPacket); +} + +void StaPipQBufferRenderer::init(RendererCore* t_core) { + path1 = t_core->getPath1(); + clipper.init(t_core->getSettings()); + rendererCore = t_core; + + dma_channel_initialize(DMA_CHANNEL_VIF1, NULL, 0); + dma_channel_fast_waits(DMA_CHANNEL_VIF1); + + setProgramsCache(); + + reinitVU1(); + + TYRA_LOG("StaPipQBufferRenderer initialized"); +} + +void StaPipQBufferRenderer::reinitVU1() { + uploadPrograms(); + setDoubleBuffer(); +} + +void StaPipQBufferRenderer::sendObjectData( + StaPipBag* bag, M4x4* mvp, RendererCoreTextureBuffers* texBuffers) const { + packet2_reset(objectDataPacket, false); + packet2_utils_vu_add_unpack_data(objectDataPacket, VU1_MVP_MATRIX_ADDR, + mvp->data, 4, false); + + if (bag->lighting) { + packet2_utils_vu_add_unpack_data(objectDataPacket, VU1_LIGHTS_MATRIX_ADDR, + bag->lighting->lightMatrix, 3, false); + + packet2_utils_vu_add_unpack_data( + objectDataPacket, VU1_LIGHTS_DIRS_ADDR, + bag->lighting->dirLights->getLightDirections(), 3, false); + + packet2_utils_vu_add_unpack_data(objectDataPacket, VU1_LIGHTS_COLORS_ADDR, + bag->lighting->dirLights->getLightColors(), + 4, false); + } + + u8 singleColorEnabled = bag->color->single != nullptr; + + 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); + + packet2_utils_vu_open_unpack(objectDataPacket, VU1_OPTIONS_ADDR, false); + { + packet2_add_u32(objectDataPacket, + singleColorEnabled); // Single color enabled. + packet2_add_u32(objectDataPacket, 0); // not used, padding + packet2_add_u32(objectDataPacket, 0); // not used, padding + packet2_add_u32(objectDataPacket, 0); // not used, padding + + packet2_utils_gs_add_lod(objectDataPacket, &rendererCore->gs.lod); + + if (texBuffers != nullptr) { + packet2_utils_gs_add_texbuff_clut(objectDataPacket, texBuffers->core, + &rendererCore->texture.clut); + + rendererCore->texture.updateClutBuffer(texBuffers->clut); + } + } + packet2_utils_vu_close_unpack(objectDataPacket); + + packet2_utils_vu_add_end_tag(objectDataPacket); + dma_channel_wait(DMA_CHANNEL_VIF1, 0); + dma_channel_send_packet2(objectDataPacket, DMA_CHANNEL_VIF1, true); +} + +void StaPipQBufferRenderer::setInfo(PipelineInfoBag* bag) { + rendererCore->gs.prim.antialiasing = bag->antiAliasingEnabled; + rendererCore->gs.prim.blending = bag->blendingEnabled; + rendererCore->gs.prim.shading = bag->shadingType; +} + +void StaPipQBufferRenderer::sendStaticData() const { + packet2_reset(staticDataPacket, false); + packet2_utils_vu_open_unpack(staticDataPacket, VU1_SET_GIFTAG_ADDR, false); + { packet2_utils_gif_add_set(staticDataPacket, 1); } + packet2_utils_vu_close_unpack(staticDataPacket); + + packet2_utils_vu_add_end_tag(staticDataPacket); + dma_channel_wait(DMA_CHANNEL_VIF1, 0); + dma_channel_send_packet2(staticDataPacket, DMA_CHANNEL_VIF1, true); +} + +void StaPipQBufferRenderer::setProgramsCache() { + VU1Program** programs = new VU1Program*[8]; + programs[0] = repository.getProgram(StaPipCullColor); + programs[1] = repository.getProgram(StaPipAsIsColor); + programs[2] = repository.getProgram(StaPipCullDirLights); + programs[3] = repository.getProgram(StaPipAsIsDirLights); + programs[4] = repository.getProgram(StaPipCullTextureDirLights); + programs[5] = repository.getProgram(StaPipAsIsTextureDirLights); + programs[6] = repository.getProgram(StaPipCullTextureColor); + programs[7] = repository.getProgram(StaPipAsIsTextureColor); + programsPacket = path1->createProgramsCache(programs, 8, 0); + delete[] programs; +} + +void StaPipQBufferRenderer::uploadPrograms() { + dma_channel_wait(DMA_CHANNEL_VIF1, 0); + dma_channel_send_packet2(programsPacket, DMA_CHANNEL_VIF1, true); + dma_channel_wait(DMA_CHANNEL_VIF1, 0); +} + +void StaPipQBufferRenderer::setDoubleBuffer() { + u16 startingAddr = VU1_LAST_ITEM_ADDR + 1; + const u16 bufferMaxSize = 1000; + bufferSize = (bufferMaxSize - startingAddr) / 2; + + path1->setDoubleBuffer(startingAddr, bufferSize); + + bufferSize -= 1; // Because we don't want to upload anything from first + // buffer, to first addr of second buffer +} + +StaPipQBuffer* StaPipQBufferRenderer::getBuffer() { + currentBufferIndex = nextBufferIndex++; + auto* result = buffers[currentBufferIndex]; + if (nextBufferIndex >= buffersCount) nextBufferIndex = 0; + return result; +} + +u16 StaPipQBufferRenderer::getQBufferIndex(StaPipQBuffer* buffer) { + for (u16 i = 0; i < buffersCount; i++) { + if (buffers[i] == buffer) return i; + } + return 0; +} + +bool StaPipQBufferRenderer::is1stDBufferFlushTime() { + return nextBufferIndex == buffersCount / 2; +} + +bool StaPipQBufferRenderer::is2ndDBufferFlushTime() { + return nextBufferIndex == 0; +} + +void StaPipQBufferRenderer::flushBuffers() { + auto is1stDBuffer = is1stDBufferFlushTime(); + auto is2ndDBuffer = is2ndDBufferFlushTime(); + + if (!is1stDBuffer && !is2ndDBuffer) { + auto offset = currentBufferIndex >= buffersCount / 2 ? buffersCount / 2 : 0; + auto size = (currentBufferIndex + 1) - offset; + auto dbuffer = &buffers[offset]; + addBufferDataToPacket(dbuffer, size); + sendPacket(); + } + + currentBufferIndex = 0; + nextBufferIndex = 0; +} + +void StaPipQBufferRenderer::cull(StaPipQBuffer* buffer) { + if (buffer->size == 0) { + return; + } + + dBufferPrograms[getQBufferIndex(buffer)] = getCullProgramByBag(buffer->bag); + + auto is1stDBuffer = is1stDBufferFlushTime(); + auto is2ndDBuffer = is2ndDBufferFlushTime(); + + if (is1stDBuffer || is2ndDBuffer) { + auto dbuffer = &buffers[is1stDBuffer ? 0 : buffersCount / 2]; + addBufferDataToPacket(dbuffer, buffersCount / 2); + sendPacket(); + } +} + +void StaPipQBufferRenderer::clip(StaPipQBuffer* buffer) { + if (buffer->size == 0) { + return; + } + + dBufferPrograms[getQBufferIndex(buffer)] = getAsIsProgramByBag(buffer->bag); + + clipper.clip(buffer); + + auto is1stDBuffer = is1stDBufferFlushTime(); + auto is2ndDBuffer = is2ndDBufferFlushTime(); + + if (is1stDBuffer || is2ndDBuffer) { + auto dbuffer = &buffers[is1stDBuffer ? 0 : buffersCount / 2]; + addBufferDataToPacket(dbuffer, buffersCount / 2); + sendPacket(); + } +} + +void StaPipQBufferRenderer::clearLastProgramName() { + lastProgramName = StaPipUndefinedProgram; +} + +void StaPipQBufferRenderer::addBufferDataToPacket(StaPipQBuffer** buffers, + const u32& count) { + currentPacket = packets[context]; + packet2_reset(currentPacket, false); + + for (u32 i = 0; i < count; i++) { + if (!buffers[i]->any()) continue; + + dBufferPrograms[i]->addBufferDataToPacket(currentPacket, buffers[i], + &rendererCore->gs.prim); + + if (lastProgramName != dBufferPrograms[i]->getName()) { + packet2_utils_vu_add_start_program( + currentPacket, dBufferPrograms[i]->getDestinationAddress()); + lastProgramName = dBufferPrograms[i]->getName(); + } else { + packet2_utils_vu_add_continue_program(currentPacket); + } + } + + packet2_utils_vu_add_end_tag(currentPacket); +} + +void StaPipQBufferRenderer::sendPacket() { + dma_channel_wait(DMA_CHANNEL_VIF1, 0); + dma_channel_send_packet2(currentPacket, DMA_CHANNEL_VIF1, true); + + // Switch packet, so we can proceed during DMA transfer + context = !context; +} + +void StaPipQBufferRenderer::setMaxVertCount(const u32& count) { + for (u32 i = 0; i < buffersCount; i++) { + buffers[i]->setMaxVertCount(count); + } + clipper.setMaxVertCount(count); +} + +StaPipVU1Program* StaPipQBufferRenderer::getAsIsProgramByBag( + const StaPipBag* bag) { + auto programType = getDrawProgramTypeByBag(bag); + + if (programType == StaPipVU1TextureDirLights) + return getProgramByName(StaPipAsIsTextureDirLights); + else if (programType == StaPipVU1DirLights) + return getProgramByName(StaPipAsIsDirLights); + else if (programType == StaPipVU1TextureColor) + return getProgramByName(StaPipAsIsTextureColor); + else + return getProgramByName(StaPipAsIsColor); +} + +StaPipVU1Program* StaPipQBufferRenderer::getCullProgramByBag( + const StaPipBag* bag) { + auto programType = getDrawProgramTypeByBag(bag); + return getCullProgramByType(programType); +} + +StaPipVU1Program* StaPipQBufferRenderer::getProgramByName( + const StaPipProgramName& name) { + return repository.getProgram(name); +} + +StaPipVU1Program* StaPipQBufferRenderer::getCullProgramByParams( + const bool& isLightingEnabled, const bool& isTextureEnabled) { + auto type = getDrawProgramTypeByParams(isLightingEnabled, isTextureEnabled); + return getCullProgramByType(type); +} + +StaPipVU1Program* StaPipQBufferRenderer::getCullProgramByType( + const StaPipProgramType& programType) { + if (programType == StaPipVU1TextureDirLights) + return getProgramByName(StaPipCullTextureDirLights); + else if (programType == StaPipVU1DirLights) + return getProgramByName(StaPipCullDirLights); + else if (programType == StaPipVU1TextureColor) + return getProgramByName(StaPipCullTextureColor); + else + return getProgramByName(StaPipCullColor); +} + +StaPipProgramType StaPipQBufferRenderer::getDrawProgramTypeByBag( + const StaPipBag* bag) const { + auto isLightingEnabled = bag->lighting != nullptr; + auto isTextureEnabled = bag->texture != nullptr; + return getDrawProgramTypeByParams(isLightingEnabled, isTextureEnabled); +} + +StaPipProgramType StaPipQBufferRenderer::getDrawProgramTypeByParams( + const bool& isLightingEnabled, const bool& isTextureEnabled) const { + if (isLightingEnabled && isTextureEnabled) + return StaPipVU1TextureDirLights; + else if (isLightingEnabled) + return StaPipVU1DirLights; + else if (isTextureEnabled) + return StaPipVU1TextureColor; + else + return StaPipVU1Color; +} + +} // namespace Tyra diff --git a/engine/src/renderer/3d/pipeline/std/core/path1/stdpip_vu1_program.cpp b/engine/src/renderer/3d/pipeline/static/core/stapip_vu1_program.cpp similarity index 76% rename from engine/src/renderer/3d/pipeline/std/core/path1/stdpip_vu1_program.cpp rename to engine/src/renderer/3d/pipeline/static/core/stapip_vu1_program.cpp index 9725637..04305ef 100644 --- a/engine/src/renderer/3d/pipeline/std/core/path1/stdpip_vu1_program.cpp +++ b/engine/src/renderer/3d/pipeline/static/core/stapip_vu1_program.cpp @@ -8,11 +8,11 @@ # Sandro Sobczyński */ -#include "renderer/3d/pipeline/std/core/path1/stdpip_vu1_program.hpp" +#include "renderer/3d/pipeline/static/core/stapip_vu1_program.hpp" namespace Tyra { -StdpipVU1Program::StdpipVU1Program(const StdpipProgramName& t_name, +StaPipVU1Program::StaPipVU1Program(const StaPipProgramName& t_name, u32* t_start, u32* t_end, const u32& t_reglist, const u8& t_reglistCount, @@ -26,21 +26,21 @@ StdpipVU1Program::StdpipVU1Program(const StdpipProgramName& t_name, programSize = calculateProgramSize(); } -StdpipVU1Program::~StdpipVU1Program() {} +StaPipVU1Program::~StaPipVU1Program() {} -const StdpipProgramName& StdpipVU1Program::getName() const { return name; } +const StaPipProgramName& StaPipVU1Program::getName() const { return name; } -u32& StdpipVU1Program::getReglist() { return reglist; } +u32& StaPipVU1Program::getReglist() { return reglist; } -void StdpipVU1Program::addBufferDataToPacket(packet2_t* packet, - StdpipQBuffer* buffer, +void StaPipVU1Program::addBufferDataToPacket(packet2_t* packet, + StaPipQBuffer* buffer, prim_t* prim) { addStandardBufferDataToPacket(packet, buffer, prim); addProgramQBufferDataToPacket(packet, buffer); } -void StdpipVU1Program::addStandardBufferDataToPacket(packet2_t* packet, - StdpipQBuffer* buffer, +void StaPipVU1Program::addStandardBufferDataToPacket(packet2_t* packet, + StaPipQBuffer* buffer, prim_t* prim) { if (buffer->bag->texture) prim->mapping = 1; @@ -61,7 +61,7 @@ void StdpipVU1Program::addStandardBufferDataToPacket(packet2_t* packet, packet2_utils_vu_close_unpack(packet); } -u16 StdpipVU1Program::getMaxVertCount(const bool& singleColorEnabled, +u16 StaPipVU1Program::getMaxVertCount(const bool& singleColorEnabled, const u16& bufferSize) const { u16 res = bufferSize - 4; u8 colorElementsPerVertex = @@ -69,7 +69,7 @@ u16 StdpipVU1Program::getMaxVertCount(const bool& singleColorEnabled, res /= (colorElementsPerVertex + reglistCount); // Buffer size = VU1 double buffer size (xtop) - // res = qbuffer size (directly inside VU1) + // QBufferSize = res (it is placed inside VU1) // Must be dividable by 3 and the result also dividable by 3. Why? // 1st dividable reason - triangle, and packaging system in 3d rendering diff --git a/engine/src/renderer/3d/pipeline/static/static_pipeline.cpp b/engine/src/renderer/3d/pipeline/static/static_pipeline.cpp new file mode 100644 index 0000000..34b93e6 --- /dev/null +++ b/engine/src/renderer/3d/pipeline/static/static_pipeline.cpp @@ -0,0 +1,181 @@ +/* +# ______ ____ ___ +# | \/ ____| |___| +# | | | \ | | +#----------------------------------------------------------------------- +# Copyright 2022, tyra - https://github.com/h4570/tyra +# Licenced under Apache License 2.0 +# Sandro Sobczyński +*/ + +#include "renderer/3d/pipeline/static/static_pipeline.hpp" +#include "debug/debug.hpp" + +namespace Tyra { + +StaticPipeline::StaticPipeline() {} + +StaticPipeline::~StaticPipeline() {} + +void StaticPipeline::setRenderer(RendererCore* t_core) { + rendererCore = t_core; + core.init(t_core); +} + +void StaticPipeline::onUse() { + colorsCache = new Vec4[4]; + core.allocateOnUse(); + core.reinitVU1Programs(); +} + +void StaticPipeline::onUseEnd() { + delete[] colorsCache; + + core.deallocateOnUse(); +} + +void StaticPipeline::render(StaticMesh* mesh, const StaPipOptions* options) { + auto model = mesh->getModelMatrix(); + auto* infoBag = getInfoBag(mesh, options, &model); + + auto frustumCulling = + options ? options->frustumCulling : PipelineFrustumCulling_Simple; + + TYRA_ASSERT( + !(frustumCulling != PipelineFrustumCulling_Precise && + infoBag->fullClipChecks == true), + "Full clip checks are only supported with frustum culling == Precise!"); + + if (frustumCulling == PipelineFrustumCulling_Simple) { + auto* frame = mesh->getFrame(); + if (frame->getBBox().isInFrustum( + rendererCore->renderer3D.frustumPlanes.getAll(), model) == + CoreBBoxFrustum::OUTSIDE_FRUSTUM) { + return; + } + } + + if (options && options->lighting) setLightingColorsCache(options->lighting); + + for (u32 i = 0; i < mesh->getMaterialsCount(); i++) { + auto* material = mesh->getMaterial(i); + auto* materialFrame = material->getFrame(0); + + StaPipBag bag; + addVertices(materialFrame, &bag); + bag.info = infoBag; + bag.color = getColorBag(material, materialFrame); + bag.texture = getTextureBag(material, materialFrame); + bag.lighting = getLightingBag(materialFrame, &model, options); + + core.render(&bag, frustumCulling == PipelineFrustumCulling_Precise); + + deallocDrawBags(&bag, material); + } + + delete infoBag; +} + +void StaticPipeline::addVertices(MeshMaterialFrame* materialFrame, + StaPipBag* bag) const { + bag->count = materialFrame->getVertexCount(); + bag->vertices = materialFrame->getVertices(); +} + +PipelineInfoBag* StaticPipeline::getInfoBag(StaticMesh* mesh, + const StaPipOptions* options, + M4x4* model) const { + auto* result = new PipelineInfoBag(); + + if (options) { + result->antiAliasingEnabled = options->antiAliasingEnabled; + result->blendingEnabled = options->blendingEnabled; + result->shadingType = options->shadingType; + result->fullClipChecks = options->fullClipChecks; + } else { + result->antiAliasingEnabled = false; + result->blendingEnabled = true; + result->shadingType = TyraShadingFlat; + result->fullClipChecks = false; + } + + result->model = model; + + return result; +} + +StaPipColorBag* StaticPipeline::getColorBag( + MeshMaterial* material, MeshMaterialFrame* materialFrame) const { + auto* result = new StaPipColorBag(); + + if (material->isSingleColorActivated()) { + result->single = &material->color; + } else { + result->many = materialFrame->getColors(); + } + + return result; +} + +StaPipTextureBag* StaticPipeline::getTextureBag( + MeshMaterial* material, MeshMaterialFrame* materialFrame) { + if (!materialFrame->getTextureCoords()) return nullptr; + + auto* result = new StaPipTextureBag(); + + result->texture = + rendererCore->texture.repository.getBySpriteOrMesh(material->getId()); + TYRA_ASSERT(result->texture, "Texture for material id: ", material->getId(), + "was not found in texture repository!"); + + result->coordinates = materialFrame->getTextureCoords(); + + return result; +} + +StaPipLightingBag* StaticPipeline::getLightingBag( + MeshMaterialFrame* materialFrame, M4x4* model, + const StaPipOptions* options) const { + if (!materialFrame->getNormals() || options == nullptr || + options->lighting == nullptr) + return nullptr; + + auto* result = new StaPipLightingBag(); + auto* dirLightsBag = new PipelineDirLightsBag(true); // TODO: 1 dir + // lights per obiekt, dealokowac recznie + result->dirLights = dirLightsBag; + + result->lightMatrix = model; + + result->dirLights->setLightsManually( + colorsCache, options->lighting->directionalDirections); + + result->normals = materialFrame->getNormals(); + + return result; +} + +void StaticPipeline::setLightingColorsCache( + PipelineLightingOptions* lightingOptions) { + for (int i = 0; i < 3; i++) { + colorsCache[i] = + reinterpret_cast(lightingOptions->directionalColors[i]); + } + colorsCache[3] = reinterpret_cast(*lightingOptions->ambientColor); +} + +void StaticPipeline::deallocDrawBags(StaPipBag* bag, + MeshMaterial* material) const { + if (bag->texture) { + delete bag->texture; + } + + if (bag->lighting) { + delete bag->lighting->dirLights; // TODO + delete bag->lighting; + } + + delete bag->color; +} + +} // namespace Tyra diff --git a/engine/src/renderer/3d/pipeline/std/core/path1/stdpip_programs_repository.cpp b/engine/src/renderer/3d/pipeline/std/core/path1/stdpip_programs_repository.cpp deleted file mode 100644 index b102150..0000000 --- a/engine/src/renderer/3d/pipeline/std/core/path1/stdpip_programs_repository.cpp +++ /dev/null @@ -1,48 +0,0 @@ -/* -# ______ ____ ___ -# | \/ ____| |___| -# | | | \ | | -#----------------------------------------------------------------------- -# Copyright 2022, tyra - https://github.com/h4570/tyra -# Licenced under Apache License 2.0 -# Sandro Sobczyński -*/ - -#include "renderer/3d/pipeline/std/core/path1/stdpip_programs_repository.hpp" - -namespace Tyra { - -StdpipProgramsRepository::StdpipProgramsRepository() {} - -StdpipProgramsRepository::~StdpipProgramsRepository() {} - -StdpipVU1Program* StdpipProgramsRepository::getProgram( - const StdpipProgramName& name) { - switch (name) { - case StdpipProgramName::StdpipAsIsColor: - return &asIsColor; - case StdpipProgramName::StdpipCullColor: - return &cullColor; - - case StdpipProgramName::StdpipAsIsDirLights: - return &asIsLightingColor; - case StdpipProgramName::StdpipCullDirLights: - return &cullLightingColor; - - case StdpipProgramName::StdpipAsIsTextureDirLights: - return &asIsLightingTextureColor; - case StdpipProgramName::StdpipCullTextureDirLights: - return &cullLightingTextureColor; - - case StdpipProgramName::StdpipAsIsTextureColor: - return &asIsTextureColor; - case StdpipProgramName::StdpipCullTextureColor: - return &cullTextureColor; - - default: - TYRA_TRAP("Unknown VU1 program name"); - return &cullLightingTextureColor; - } -} - -} // namespace Tyra diff --git a/engine/src/renderer/3d/pipeline/std/core/path1/stdpip_qbuffer_renderer.cpp b/engine/src/renderer/3d/pipeline/std/core/path1/stdpip_qbuffer_renderer.cpp deleted file mode 100644 index b9df310..0000000 --- a/engine/src/renderer/3d/pipeline/std/core/path1/stdpip_qbuffer_renderer.cpp +++ /dev/null @@ -1,320 +0,0 @@ -/* -# ______ ____ ___ -# | \/ ____| |___| -# | | | \ | | -#----------------------------------------------------------------------- -# Copyright 2022, tyra - https://github.com/h4570/tyra -# Licenced under Apache License 2.0 -# Sandro Sobczyński -*/ - -#include "renderer/3d/pipeline/std/core/path1/stdpip_qbuffer_renderer.hpp" -#include "renderer/3d/pipeline/std/core/path1/programs/stdpip_vu1_shared_defines.h" - -namespace Tyra { - -/** - * VU1 = 1000 vert - * - * Quadbuffering: - * 2 main buffers = 1000 / 2 = 500 vert - * 2 kick buffers = 500 / 2 = 250 vert - * - * Vert data: - * Pos + Normal + ST + Color = 4 - * = 4 * 48 = 192 - * - * Other data: - * mvp matrix, light matrix, tags = 14 - * 20 light vectors, light intesities = 25 - * = 14 + 25 = 39 - * - * All data: - * = 192 + 39 = 231 - * - */ - -StdpipQBufferRenderer::StdpipQBufferRenderer() { - context = 0; - lastProgramName = StdipUndefinedProgram; - staticDataPacket = packet2_create(3, P2_TYPE_NORMAL, P2_MODE_CHAIN, true); - objectDataPacket = packet2_create(16, P2_TYPE_NORMAL, P2_MODE_CHAIN, true); - programsPacket = nullptr; -} -StdpipQBufferRenderer::~StdpipQBufferRenderer() { - packet2_free(packets[0]); - packet2_free(packets[1]); - packet2_free(staticDataPacket); - packet2_free(objectDataPacket); - - if (programsPacket) packet2_free(programsPacket); -} - -void StdpipQBufferRenderer::init(RendererCore* t_core) { - path1 = t_core->getPath1(); - clipper.init(t_core->getSettings()); - rendererCore = t_core; - - dma_channel_initialize(DMA_CHANNEL_VIF1, NULL, 0); - dma_channel_fast_waits(DMA_CHANNEL_VIF1); - - const u32 VU1_PACKET_SIZE = 16; - - packets[0] = - packet2_create(VU1_PACKET_SIZE, P2_TYPE_NORMAL, P2_MODE_CHAIN, true); - - packets[1] = - packet2_create(VU1_PACKET_SIZE, P2_TYPE_NORMAL, P2_MODE_CHAIN, true); - - setProgramsCache(); - - reinitVU1(); - - TYRA_LOG("Renderer3DQBufferRenderer initialized"); -} - -void StdpipQBufferRenderer::reinitVU1() { - sendStaticData(); - uploadPrograms(); - setDoubleBuffer(); -} - -StdpipQBuffer* StdpipQBufferRenderer::getBuffer() { return &buffers[context]; } - -void StdpipQBufferRenderer::sendObjectData( - StdpipBag* bag, M4x4* mvp, RendererCoreTextureBuffers* texBuffers) const { - packet2_reset(objectDataPacket, false); - packet2_utils_vu_add_unpack_data(objectDataPacket, VU1_MVP_MATRIX_ADDR, - mvp->data, 4, false); - - if (bag->lighting) { - packet2_utils_vu_add_unpack_data(objectDataPacket, VU1_LIGHTS_MATRIX_ADDR, - bag->lighting->lightMatrix, 3, false); - - packet2_utils_vu_add_unpack_data(objectDataPacket, VU1_LIGHTS_DIRS_ADDR, - bag->lighting->getLightDirections(), 3, - false); - - packet2_utils_vu_add_unpack_data(objectDataPacket, VU1_LIGHTS_COLORS_ADDR, - bag->lighting->getLightColors(), 4, false); - } - - u8 singleColorEnabled = bag->color->single != nullptr; - - 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); - - packet2_utils_vu_open_unpack(objectDataPacket, VU1_OPTIONS_ADDR, false); - { - packet2_add_u32(objectDataPacket, - singleColorEnabled); // Single color enabled. - packet2_add_u32(objectDataPacket, 0); // not used, padding - packet2_add_u32(objectDataPacket, 0); // not used, padding - packet2_add_u32(objectDataPacket, 0); // not used, padding - - packet2_utils_gs_add_lod(objectDataPacket, &rendererCore->gs.lod); - - if (texBuffers != nullptr) { - packet2_utils_gs_add_texbuff_clut(objectDataPacket, texBuffers->core, - &rendererCore->texture.clut); - - rendererCore->texture.updateClutBuffer(texBuffers->clut); - } - } - packet2_utils_vu_close_unpack(objectDataPacket); - - packet2_utils_vu_add_end_tag(objectDataPacket); - dma_channel_wait(DMA_CHANNEL_VIF1, 0); - dma_channel_send_packet2(objectDataPacket, DMA_CHANNEL_VIF1, true); -} - -void StdpipQBufferRenderer::setInfo(StdpipInfoBag* bag) { - rendererCore->gs.prim.antialiasing = bag->antiAliasingEnabled; - rendererCore->gs.prim.blending = bag->blendingEnabled; - rendererCore->gs.prim.shading = bag->shadingType; -} - -void StdpipQBufferRenderer::sendStaticData() const { - packet2_reset(staticDataPacket, false); - packet2_utils_vu_open_unpack(staticDataPacket, VU1_SET_GIFTAG_ADDR, false); - { packet2_utils_gif_add_set(staticDataPacket, 1); } - packet2_utils_vu_close_unpack(staticDataPacket); - - packet2_utils_vu_add_end_tag(staticDataPacket); - dma_channel_wait(DMA_CHANNEL_VIF1, 0); - dma_channel_send_packet2(staticDataPacket, DMA_CHANNEL_VIF1, true); -} - -void StdpipQBufferRenderer::setProgramsCache() { - VU1Program** programs = new VU1Program*[8]; - programs[0] = repository.getProgram(StdpipCullColor); - programs[1] = repository.getProgram(StdpipAsIsColor); - programs[2] = repository.getProgram(StdpipCullDirLights); - programs[3] = repository.getProgram(StdpipAsIsDirLights); - programs[4] = repository.getProgram(StdpipCullTextureDirLights); - programs[5] = repository.getProgram(StdpipAsIsTextureDirLights); - programs[6] = repository.getProgram(StdpipCullTextureColor); - programs[7] = repository.getProgram(StdpipAsIsTextureColor); - programsPacket = path1->createProgramsCache(programs, 8, 0); - delete[] programs; -} - -void StdpipQBufferRenderer::uploadPrograms() { - dma_channel_wait(DMA_CHANNEL_VIF1, 0); - dma_channel_send_packet2(programsPacket, DMA_CHANNEL_VIF1, true); - dma_channel_wait(DMA_CHANNEL_VIF1, 0); -} - -void StdpipQBufferRenderer::setDoubleBuffer() { - u16 startingAddr = VU1_LAST_ITEM_ADDR + 1; - const u16 bufferMaxSize = 1000; - bufferSize = (bufferMaxSize - startingAddr) / 2; - - path1->setDoubleBuffer(startingAddr, bufferSize); - - bufferSize -= 1; // Because we don't want to upload anything from first - // buffer, to first addr of second buffer -} - -void StdpipQBufferRenderer::cull(StdpipQBuffer* buffer) { - if (buffer->size == 0) { - return; - } - - auto program = getCullProgramByBag(buffer->bag); - addBufferDataToPacket(program, buffer); - sendPacket(); -} - -// void StdpipQBufferRenderer::sendFinishTag() { -// StdpipQBufferRenderer way proposition -// auto program = path1->getProgramByName(Draw_Finish); -// addBufferDataToPacket(program, nullptr); -// sendPacket(); - -// packet2_t* packet2 = packet2_create(8, P2_TYPE_NORMAL, P2_MODE_CHAIN, -// true); auto program = -// static_cast(getProgramByName(Draw_Finish)); - -// program->addTag(packet2, prim); -// packet2_utils_vu_add_start_program(packet2, -// program->getDestinationAddress()); packet2_utils_vu_add_end_tag(packet2); -// dma_channel_wait(DMA_CHANNEL_VIF1, 0); -// dma_channel_send_packet2(packet2, DMA_CHANNEL_VIF1, true); -// packet2_free(packet2); -// } - -void StdpipQBufferRenderer::clip(StdpipQBuffer* buffer) { - if (buffer->size == 0) { - return; - } - - auto program = getAsIsProgramByBag(buffer->bag); - clipper.clip(buffer); - - if (buffer->any()) { - if (buffer) addBufferDataToPacket(program, buffer); - sendPacket(); - } -} - -void StdpipQBufferRenderer::clearLastProgramName() { - lastProgramName = StdipUndefinedProgram; -} - -void StdpipQBufferRenderer::addBufferDataToPacket(StdpipVU1Program* program, - StdpipQBuffer* buffer) { - currentPacket = packets[context]; - packet2_reset(currentPacket, false); - - program->addBufferDataToPacket(currentPacket, buffer, &rendererCore->gs.prim); - - if (lastProgramName != program->getName()) { - packet2_utils_vu_add_start_program(currentPacket, - program->getDestinationAddress()); - lastProgramName = program->getName(); - } else { - packet2_utils_vu_add_continue_program(currentPacket); - } - packet2_utils_vu_add_end_tag(currentPacket); -} - -void StdpipQBufferRenderer::sendPacket() { - dma_channel_wait(DMA_CHANNEL_VIF1, 0); - dma_channel_send_packet2(currentPacket, DMA_CHANNEL_VIF1, true); - - // Switch packet, so we can proceed during DMA transfer - context = !context; -} - -void StdpipQBufferRenderer::setMaxVertCount(const u32& count) { - buffers[0].setMaxVertCount(count); - buffers[1].setMaxVertCount(count); - clipper.setMaxVertCount(count); -} - -StdpipVU1Program* StdpipQBufferRenderer::getAsIsProgramByBag( - const StdpipBag* bag) { - auto programType = getDrawProgramTypeByBag(bag); - - if (programType == StdpipVU1TextureDirLights) - return getProgramByName(StdpipAsIsTextureDirLights); - else if (programType == StdpipVU1DirLights) - return getProgramByName(StdpipAsIsDirLights); - else if (programType == StdpipVU1TextureColor) - return getProgramByName(StdpipAsIsTextureColor); - else - return getProgramByName(StdpipAsIsColor); -} - -StdpipVU1Program* StdpipQBufferRenderer::getCullProgramByBag( - const StdpipBag* bag) { - auto programType = getDrawProgramTypeByBag(bag); - return getCullProgramByType(programType); -} - -StdpipVU1Program* StdpipQBufferRenderer::getProgramByName( - const StdpipProgramName& name) { - return repository.getProgram(name); -} - -StdpipVU1Program* StdpipQBufferRenderer::getCullProgramByParams( - const bool& isLightingEnabled, const bool& isTextureEnabled) { - auto type = getDrawProgramTypeByParams(isLightingEnabled, isTextureEnabled); - return getCullProgramByType(type); -} - -StdpipVU1Program* StdpipQBufferRenderer::getCullProgramByType( - const StdpipProgramType& programType) { - if (programType == StdpipVU1TextureDirLights) - return getProgramByName(StdpipCullTextureDirLights); - else if (programType == StdpipVU1DirLights) - return getProgramByName(StdpipCullDirLights); - else if (programType == StdpipVU1TextureColor) - return getProgramByName(StdpipCullTextureColor); - else - return getProgramByName(StdpipCullColor); -} - -StdpipProgramType StdpipQBufferRenderer::getDrawProgramTypeByBag( - const StdpipBag* bag) const { - auto isLightingEnabled = bag->lighting != nullptr; - auto isTextureEnabled = bag->texture != nullptr; - return getDrawProgramTypeByParams(isLightingEnabled, isTextureEnabled); -} - -StdpipProgramType StdpipQBufferRenderer::getDrawProgramTypeByParams( - const bool& isLightingEnabled, const bool& isTextureEnabled) const { - if (isLightingEnabled && isTextureEnabled) - return StdpipVU1TextureDirLights; - else if (isLightingEnabled) - return StdpipVU1DirLights; - else if (isTextureEnabled) - return StdpipVU1TextureColor; - else - return StdpipVU1Color; -} - -} // namespace Tyra diff --git a/engine/src/renderer/3d/pipeline/std/std_pipeline.cpp b/engine/src/renderer/3d/pipeline/std/std_pipeline.cpp deleted file mode 100644 index 00982b4..0000000 --- a/engine/src/renderer/3d/pipeline/std/std_pipeline.cpp +++ /dev/null @@ -1,221 +0,0 @@ -/* -# ______ ____ ___ -# | \/ ____| |___| -# | | | \ | | -#----------------------------------------------------------------------- -# Copyright 2022, tyra - https://github.com/h4570/tyra -# Licenced under Apache License 2.0 -# Sandro Sobczyński -*/ - -#include "renderer/3d/pipeline/std/std_pipeline.hpp" - -namespace Tyra { - -StdPipeline::StdPipeline() { colorsCache = new Vec4[4]; } - -StdPipeline::~StdPipeline() { delete[] colorsCache; } - -void StdPipeline::init(RendererCore* t_core) { - rendererCore = t_core; - core.init(t_core); -} - -void StdPipeline::onUse() { core.reinitStandardVU1Programs(); } - -void StdPipeline::render(Mesh* mesh, const StdpipOptions* options) { - auto model = mesh->getModelMatrix(); - - MeshFrame* frameFrom = mesh->getFramesCount() > 0 - ? mesh->getFrame(mesh->getCurrentAnimationFrame()) - : mesh->getFrame(0); - - MeshFrame* frameTo = mesh->getFramesCount() > 0 - ? mesh->getFrame(mesh->getNextAnimationFrame()) - : nullptr; - - auto* infoBag = getInfoBag(mesh, options, &model); - - if (options->lighting) setLightingColorsCache(options->lighting); - - for (u32 i = 0; i < mesh->getMaterialsCount(); i++) { - auto* material = mesh->getMaterial(i); - - // 2x bufory[maxVertCount*2] -> pętla po mniejszych częściach i czestsze - // rendery - - // TODO: Double buffering in future - // auto maxVertCount = core->renderer3D.getMaxVertCountByParams( - // material->isSingleColorActivated(), material->getNormalFaces(), - // material->getTextureCoordFaces()); - - StdpipBag bag; - addVertices(mesh, material, &bag, frameFrom, frameTo); - bag.info = infoBag; - bag.color = getColorBag(mesh, material, frameFrom, frameTo); - bag.texture = getTextureBag(mesh, material, frameFrom, frameTo); - bag.lighting = - getLightingBag(mesh, material, &model, frameFrom, frameTo, options); - - core.render(&bag); - - deallocDrawBags(&bag, material); - } - - delete infoBag; -} - -void StdPipeline::addVertices(Mesh* mesh, MeshMaterial* material, - StdpipBag* bag, MeshFrame* frameFrom, - MeshFrame* frameTo) const { - bag->count = material->getFacesCount(); - bag->vertices = new Vec4[bag->count]; - - for (u32 i = 0; i < bag->count; i++) { - auto& face = material->getVertexFaces()[i]; - if (frameTo == nullptr) { - bag->vertices[i] = frameFrom->getVertices()[face]; - } else { - Vec4::setLerp(&bag->vertices[i], frameFrom->getVertices()[face], - frameTo->getVertices()[face], - mesh->getAnimState().interpolation); - } - } -} - -StdpipInfoBag* StdPipeline::getInfoBag(Mesh* mesh, const StdpipOptions* options, - M4x4* model) const { - auto* result = new StdpipInfoBag(); - - if (options) { - result->antiAliasingEnabled = options->antiAliasingEnabled; - result->blendingEnabled = options->blendingEnabled; - result->shadingType = options->shadingType; - result->noClipChecks = options->noClipChecks; - } else { - result->antiAliasingEnabled = false; - result->blendingEnabled = true; - result->shadingType = StdpipShadingFlat; - result->noClipChecks = true; - } - - result->model = model; - - return result; -} - -StdpipColorBag* StdPipeline::getColorBag(Mesh* mesh, MeshMaterial* material, - MeshFrame* frameFrom, - MeshFrame* frameTo) const { - auto* result = new StdpipColorBag(); - - if (material->isSingleColorActivated()) { - result->single = &material->singleColor; - } else { - result->many = new Color[material->getFacesCount()]; - - for (u32 i = 0; i < material->getFacesCount(); i++) { - auto& face = material->getColorFaces()[i]; - if (frameTo == nullptr) { - result->many[i] = frameFrom->getColors()[face]; - } else { - Vec4::setLerp( - reinterpret_cast(&result->many[i]), - reinterpret_cast(frameFrom->getColors()[face]), - reinterpret_cast(frameTo->getColors()[face]), - mesh->getAnimState().interpolation); - } - } - } - - return result; -} - -StdpipTextureBag* StdPipeline::getTextureBag(Mesh* mesh, MeshMaterial* material, - MeshFrame* frameFrom, - MeshFrame* frameTo) { - if (!material->getTextureCoordFaces()) return nullptr; - - auto* result = new StdpipTextureBag(); - - result->texture = - rendererCore->texture.repository.getBySpriteOrMesh(material->getId()); - TYRA_ASSERT(result->texture, "Texture for material id: ", material->getId(), - " was not found in texture repository!"); - - result->coordinates = new Vec4[material->getFacesCount()]; - - for (u32 i = 0; i < material->getFacesCount(); i++) { - auto& face = material->getTextureCoordFaces()[i]; - if (frameTo == nullptr) { - result->coordinates[i] = frameFrom->getTextureCoords()[face]; - } else { - Vec4::setLerp(&result->coordinates[i], - frameFrom->getTextureCoords()[face], - frameTo->getTextureCoords()[face], - mesh->getAnimState().interpolation); - } - } - - return result; -} - -StdpipLightingBag* StdPipeline::getLightingBag( - Mesh* mesh, MeshMaterial* material, M4x4* model, MeshFrame* frameFrom, - MeshFrame* frameTo, const StdpipOptions* options) const { - if (!material->getNormalFaces() || options == nullptr || - options->lighting == nullptr) - return nullptr; - - auto* result = new StdpipLightingBag(true); - result->lightMatrix = model; - - result->setLightsManually(colorsCache, - options->lighting->directionalDirections); - - result->normals = new Vec4[material->getFacesCount()]; - - for (u32 i = 0; i < material->getFacesCount(); i++) { - auto& face = material->getNormalFaces()[i]; - if (frameTo == nullptr) { - result->normals[i] = frameFrom->getNormals()[face]; - } else { - Vec4::setLerp(&result->normals[i], frameFrom->getNormals()[face], - frameTo->getNormals()[face], - mesh->getAnimState().interpolation); - } - } - - return result; -} - -void StdPipeline::setLightingColorsCache( - StdpipLightingOptions* lightingOptions) { - for (int i = 0; i < 3; i++) { - colorsCache[i] = - reinterpret_cast(lightingOptions->directionalColors[i]); - } - colorsCache[3] = reinterpret_cast(*lightingOptions->ambientColor); -} - -void StdPipeline::deallocDrawBags(StdpipBag* bag, - MeshMaterial* material) const { - if (bag->color->many) { - delete[] bag->color->many; - } - - if (bag->texture) { - delete[] bag->texture->coordinates; - delete bag->texture; - } - - if (bag->lighting) { - delete[] bag->lighting->normals; - delete bag->lighting; - } - - delete[] bag->vertices; - delete bag->color; -} - -} // namespace Tyra diff --git a/engine/src/renderer/3d/renderer_3d.cpp b/engine/src/renderer/3d/renderer_3d.cpp index f9352f7..2ffb4b8 100644 --- a/engine/src/renderer/3d/renderer_3d.cpp +++ b/engine/src/renderer/3d/renderer_3d.cpp @@ -19,6 +19,7 @@ Renderer3D::~Renderer3D() {} void Renderer3D::usePipeline(Renderer3DPipeline* pipeline) { if (currentPipeline != pipeline) { + if (currentPipeline) currentPipeline->onUseEnd(); currentPipeline = pipeline; currentPipeline->onUse(); } diff --git a/engine/src/renderer/core/2d/renderer_core_2d.cpp b/engine/src/renderer/core/2d/renderer_core_2d.cpp index 11c6aab..cfc0377 100644 --- a/engine/src/renderer/core/2d/renderer_core_2d.cpp +++ b/engine/src/renderer/core/2d/renderer_core_2d.cpp @@ -88,10 +88,11 @@ void RendererCore2D::render(Sprite* sprite, packet2_utils_gs_add_texbuff_clut(packet, texBuffers.core, clutBuffer); draw_enable_blending(); packet2_update(packet, draw_rect_textured(packet->next, 0, rect)); - packet2_update(packet, draw_primitive_xyoffset( - packet->next, 0, - SCREEN_CENTER - (settings->getWidth() / 2.0F), - SCREEN_CENTER - (settings->getHeight() / 2.0F))); + packet2_update( + packet, + draw_primitive_xyoffset( + packet->next, 0, SCREEN_CENTER - (settings->getWidth() / 2.0F), + SCREEN_CENTER - (settings->getInterlacedHeightF() / 2.0F))); draw_disable_blending(); packet2_update(packet, draw_finish(packet->next)); diff --git a/engine/src/renderer/core/3d/bbox/core_bbox.cpp b/engine/src/renderer/core/3d/bbox/core_bbox.cpp index 7004338..919fcde 100644 --- a/engine/src/renderer/core/3d/bbox/core_bbox.cpp +++ b/engine/src/renderer/core/3d/bbox/core_bbox.cpp @@ -10,6 +10,7 @@ #include #include +#include #include "renderer/core/3d/bbox/core_bbox.hpp" namespace Tyra { diff --git a/engine/src/renderer/core/paths/path1/clipper/path1_ee_clip_algorithm.cpp b/engine/src/renderer/core/3d/clipper/ee_clip_algorithm.cpp similarity index 70% rename from engine/src/renderer/core/paths/path1/clipper/path1_ee_clip_algorithm.cpp rename to engine/src/renderer/core/3d/clipper/ee_clip_algorithm.cpp index c398efd..d5ed65d 100644 --- a/engine/src/renderer/core/paths/path1/clipper/path1_ee_clip_algorithm.cpp +++ b/engine/src/renderer/core/3d/clipper/ee_clip_algorithm.cpp @@ -8,26 +8,26 @@ # Sandro Sobczyński */ -#include "renderer/core/paths/path1/clipper/path1_ee_clip_algorithm.hpp" +#include "renderer/core/3d/clipper/ee_clip_algorithm.hpp" namespace Tyra { -Path1EEClipAlgorithm::Path1EEClipAlgorithm() {} +EEClipAlgorithm::EEClipAlgorithm() {} -Path1EEClipAlgorithm::~Path1EEClipAlgorithm() {} +EEClipAlgorithm::~EEClipAlgorithm() {} -float Path1EEClipAlgorithm::clipMargin = -10.0F; +float EEClipAlgorithm::clipMargin = -10.0F; -void Path1EEClipAlgorithm::init(const RendererSettings& settings) { +void EEClipAlgorithm::init(const RendererSettings& settings) { halfWidth = settings.getWidth() / 2; halfHeight = settings.getHeight() / 2; near = settings.getNear() - (-clipMargin); far = -settings.getFar(); } -void Path1EEClipAlgorithm::clip(std::vector* o_vertices, - const std::vector& vertices, - const Path1EEClipAlgorithmSettings& settings) { +void EEClipAlgorithm::clip(std::vector* o_vertices, + const std::vector& vertices, + const EEClipAlgorithmSettings& settings) { tempVertices.clear(); for (u32 i = 0; i < vertices.size(); i++) { @@ -42,8 +42,8 @@ void Path1EEClipAlgorithm::clip(std::vector* o_vertices, clipAgainstPlane(tempVertices, o_vertices, 4, far, settings); } -float Path1EEClipAlgorithm::getValueByPlane(const Path1ClipVertex& v, - const int& plane) { +float EEClipAlgorithm::getValueByPlane(const EEClipVertex& v, + const int& plane) { switch (plane) { case 1: return v.position.x; // x plane @@ -57,9 +57,8 @@ float Path1EEClipAlgorithm::getValueByPlane(const Path1ClipVertex& v, } } -bool Path1EEClipAlgorithm::isInside(const int& plane, const float& v, - const float& w, - const float& planeLimitValue) { +bool EEClipAlgorithm::isInside(const int& plane, const float& v, const float& w, + const float& planeLimitValue) { switch (plane) { case 3: return v <= planeLimitValue; // near z plane @@ -71,11 +70,10 @@ bool Path1EEClipAlgorithm::isInside(const int& plane, const float& v, } } -void Path1EEClipAlgorithm::clipAgainstPlane( - const std::vector& original, - std::vector* clipped, const int& plane, - const float& planeLimitValue, - const Path1EEClipAlgorithmSettings& settings) { +void EEClipAlgorithm::clipAgainstPlane( + const std::vector& original, + std::vector* clipped, const int& plane, + const float& planeLimitValue, const EEClipAlgorithmSettings& settings) { clipped->clear(); for (u32 i = 0; i < original.size(); i++) { @@ -98,7 +96,7 @@ void Path1EEClipAlgorithm::clipAgainstPlane( ((b.position.w - a.position.w) * planeLimitValue - (bpx - apx)); - Path1ClipVertex nb = { + EEClipVertex nb = { Vec4::getByLerp(a.position, b.position, p), settings.lerpNormals ? Vec4::getByLerp(a.normal, b.normal, p) : Vec4(), diff --git a/engine/src/renderer/core/3d/renderer_3d_frustum_planes.cpp b/engine/src/renderer/core/3d/renderer_3d_frustum_planes.cpp index cb6185f..a539dc8 100644 --- a/engine/src/renderer/core/3d/renderer_3d_frustum_planes.cpp +++ b/engine/src/renderer/core/3d/renderer_3d_frustum_planes.cpp @@ -8,8 +8,9 @@ # Sandro Sobczyński */ -#include #include "debug/debug.hpp" +#include +#include #include "renderer/core/3d/renderer_3d_frustum_planes.hpp" namespace Tyra { diff --git a/engine/src/renderer/core/3d/renderer_core_3d.cpp b/engine/src/renderer/core/3d/renderer_core_3d.cpp index 189d400..9658ee9 100644 --- a/engine/src/renderer/core/3d/renderer_core_3d.cpp +++ b/engine/src/renderer/core/3d/renderer_core_3d.cpp @@ -37,7 +37,7 @@ void RendererCore3D::setFov(const float& t_fov) { void RendererCore3D::setProjection() { projection = M4x4::perspective( - fov, settings->getWidth(), settings->getHeight(), + fov, settings->getWidth(), settings->getInterlacedHeightF(), settings->getProjectionScale(), settings->getAspectRatio(), settings->getNear(), settings->getFar()); } diff --git a/engine/src/renderer/core/gs/renderer_core_gs.cpp b/engine/src/renderer/core/gs/renderer_core_gs.cpp index 2b6ac67..37085d6 100644 --- a/engine/src/renderer/core/gs/renderer_core_gs.cpp +++ b/engine/src/renderer/core/gs/renderer_core_gs.cpp @@ -52,12 +52,12 @@ void RendererCoreGS::initChannels() { } void RendererCoreGS::allocateBuffers() { - const u16 psm = 24; + const u16 psm = 32; frameBuffers[0].width = static_cast(settings->getWidth()); - frameBuffers[0].height = static_cast(settings->getHeight()); + frameBuffers[0].height = settings->getInterlacedHeightUI(); frameBuffers[0].mask = 0; - frameBuffers[0].psm = GS_PSM_24; + frameBuffers[0].psm = GS_PSM_32; frameBuffers[0].address = graph_vram_allocate(frameBuffers[0].width, frameBuffers[0].height, frameBuffers[0].psm, GRAPH_ALIGN_PAGE); @@ -73,15 +73,20 @@ void RendererCoreGS::allocateBuffers() { zBuffer.enable = DRAW_ENABLE; zBuffer.mask = 0; zBuffer.method = ZTEST_METHOD_GREATER_EQUAL; - zBuffer.zsm = GS_ZBUF_24; + zBuffer.zsm = GS_ZBUF_32; zBuffer.address = graph_vram_allocate(frameBuffers[0].width, frameBuffers[0].height, zBuffer.zsm, GRAPH_ALIGN_PAGE); TYRA_LOG("Framebuffers, zBuffer set and allocated!"); - // Initialize the screen and tie the first framebuffer to the read circuits. - graph_initialize(frameBuffers[1].address, frameBuffers[1].width, - frameBuffers[1].height, frameBuffers[1].psm, 0, 0); + graph_set_mode(GRAPH_MODE_INTERLACED, GRAPH_MODE_NTSC, GRAPH_MODE_FRAME, + GRAPH_ENABLE); + graph_set_screen(0, 0, static_cast(settings->getWidth()), + static_cast(settings->getHeight())); + graph_set_bgcolor(0, 0, 0); + graph_set_framebuffer_filtered(frameBuffers[1].address, frameBuffers[1].width, + frameBuffers[1].psm, 0, 0); + graph_enable_output(); spaceOccupiedByFrameBuffers = ((frameBuffers[0].width / 100.0F) * (frameBuffers[0].height / 100.0F) * @@ -96,10 +101,11 @@ void RendererCoreGS::initDrawingEnvironment() { packet2_t* packet2 = packet2_create(20, P2_TYPE_NORMAL, P2_MODE_NORMAL, 0); packet2_update(packet2, draw_setup_environment(packet2->base, 0, frameBuffers, &zBuffer)); - packet2_update(packet2, draw_primitive_xyoffset( - packet2->next, 0, - screenCenter - (settings->getWidth() / 2.0F), - screenCenter - (settings->getHeight() / 2.0F))); + packet2_update( + packet2, + draw_primitive_xyoffset( + packet2->next, 0, screenCenter - (settings->getWidth() / 2.0F), + screenCenter - (settings->getInterlacedHeightF() / 2.0F))); packet2_update(packet2, draw_finish(packet2->next)); dma_channel_send_packet2(packet2, DMA_CHANNEL_GIF, true); dma_channel_wait(DMA_CHANNEL_GIF, 0); diff --git a/engine/src/renderer/core/paths/path1/programs/draw_finish/draw_finish.vclpp b/engine/src/renderer/core/paths/path1/programs/draw_finish/draw_finish.vclpp deleted file mode 100644 index 95e687f..0000000 --- a/engine/src/renderer/core/paths/path1/programs/draw_finish/draw_finish.vclpp +++ /dev/null @@ -1,45 +0,0 @@ -; ______ ____ ___ -; | \/ ____| |___| -; | | | \ | | -;--------------------------------------------------------------- -; Copyright 2022, tyra - https://github.com/h4570/tyra -; Licenced under Apache License 2.0 -; Sandro Sobczyński -; -;--------------------------------------------------------------- -; Needed for synchronization with draw_wait_finish() -;--------------------------------------------------------------- - -.syntax new -.name VU1DrawFinish -.vu -.init_vf_all -.init_vi_all - -#include "src/renderer/core/paths/path1/programs/vcl_sml.i" -#include "src/renderer/core/paths/path1/programs/tyra_macros.i" -#include "inc/renderer/3d/pipeline/std/core/path1/programs/stdpip_vu1_shared_defines.h" - ---enter ---endenter - -#vuprog VU1DrawFinish - - LoadTyraStaticData{ gifSetTag } - - xtop buffer - lq drawFinishTag, 0(buffer) - lq primTag, 1(buffer) - - iaddiu kickAddress, buffer, 2 - - sq gifSetTag, 0(kickAddress) - sq drawFinishTag, 1(kickAddress) - sq primTag, 2(kickAddress) - - xgkick kickAddress - -#endvuprog - ---exit ---endexit diff --git a/engine/src/renderer/core/paths/path1/programs/draw_finish/vu1_draw_finish.cpp b/engine/src/renderer/core/paths/path1/programs/draw_finish/vu1_draw_finish.cpp deleted file mode 100644 index 76cd2e0..0000000 --- a/engine/src/renderer/core/paths/path1/programs/draw_finish/vu1_draw_finish.cpp +++ /dev/null @@ -1,37 +0,0 @@ -/* -# ______ ____ ___ -# | \/ ____| |___| -# | | | \ | | -#----------------------------------------------------------------------- -# Copyright 2022, tyra - https://github.com/h4570/tyra -# Licenced under Apache License 2.0 -# Sandro Sobczyński -*/ - -#include "debug/debug.hpp" -#include "renderer/core/paths/path1/programs/draw_finish/vu1_draw_finish.hpp" - -extern u32 VU1DrawFinish_CodeStart __attribute__((section(".vudata"))); -extern u32 VU1DrawFinish_CodeEnd __attribute__((section(".vudata"))); - -namespace Tyra { - -VU1DrawFinish::VU1DrawFinish() - : VU1Program(&VU1DrawFinish_CodeStart, &VU1DrawFinish_CodeEnd) {} - -VU1DrawFinish::~VU1DrawFinish() {} - -std::string VU1DrawFinish::getStringName() const { - return std::string("Draw finish"); -} - -void VU1DrawFinish::addTag(packet2_t* packet, prim_t* prim) const { - packet2_utils_vu_open_unpack(packet, 0, true); - packet2_utils_gs_add_draw_finish_giftag(packet); - packet2_utils_gs_add_prim_giftag( - packet, prim, 1, ((u64)GIF_REG_RGBAQ) << 0 | ((u64)GIF_REG_XYZ2) << 4, 2, - 0); - packet2_utils_vu_close_unpack(packet); -} - -} // namespace Tyra diff --git a/engine/src/renderer/core/texture/models/texture.cpp b/engine/src/renderer/core/texture/models/texture.cpp index 2898785..a4ab27b 100644 --- a/engine/src/renderer/core/texture/models/texture.cpp +++ b/engine/src/renderer/core/texture/models/texture.cpp @@ -162,10 +162,15 @@ std::string Texture::getPrint(const char* objectName) const { else if (wrap.horizontal == WRAP_CLAMP) wrapString = "WRAP_CLAMP"; - res << "id: " << id << ", "; - res << "name: " << name << ", "; - res << "core: " << core->getPrint() << ", "; - if (clut != nullptr) res << "clut: " << clut->getPrint() << ", "; + res << "id: " << id << ", " << std::endl; + res << "name: " << name << ", " << std::endl; + res << "core: " << core->getPrint() << ", " << std::endl; + if (clut != nullptr) res << "clut: " << clut->getPrint() << ", " << std::endl; + if (links.size()) { + for (size_t i = 0; i < links.size(); i++) { + res << "link " << i << " for id: " << links[i].id << ", " << std::endl; + } + } res << "wrap: " << wrapString << ")"; return res.str(); } diff --git a/engine/src/renderer/core/texture/renderer_core_texture_sender.cpp b/engine/src/renderer/core/texture/renderer_core_texture_sender.cpp index ca2df10..7e47a1c 100644 --- a/engine/src/renderer/core/texture/renderer_core_texture_sender.cpp +++ b/engine/src/renderer/core/texture/renderer_core_texture_sender.cpp @@ -30,7 +30,8 @@ RendererCoreTextureBuffers RendererCoreTextureSender::allocate( texbuffer_t* core = allocateTextureCore(t_texture); texbuffer_t* clut = nullptr; - if (t_texture->getClutData() != nullptr) { + auto texClut = t_texture->getClutData(); + if (texClut != nullptr && texClut->width + texClut->height > 0) { clut = allocateTextureClut(t_texture); } return {t_texture->getId(), core, clut}; @@ -66,12 +67,11 @@ texbuffer_t* RendererCoreTextureSender::allocateTextureCore( TYRA_ASSERT(t_texture->getSizeInMB() <= getFreeVRamInMB(), "Not enough VRAM memory for texture!"); - result->address = + auto address = graph_vram_allocate(t_texture->getWidth(), t_texture->getHeight(), result->psm, GRAPH_ALIGN_BLOCK); - - TYRA_ASSERT(result->address > 0, - "Texture buffer allocation error. No memory!"); + TYRA_ASSERT(address > 0, "Texture buffer allocation error, no memory!"); + result->address = address; allocatedVRamMemForTextures += t_texture->getSizeInMB(); result->info.width = draw_log2(t_texture->getWidth()); @@ -89,8 +89,10 @@ texbuffer_t* RendererCoreTextureSender::allocateTextureClut( result->psm = clut->psm; result->info.components = clut->components; - result->address = graph_vram_allocate(clut->width, clut->height, result->psm, - GRAPH_ALIGN_BLOCK); + auto address = graph_vram_allocate(clut->width, clut->height, result->psm, + GRAPH_ALIGN_BLOCK); + TYRA_ASSERT(address > 0, "Texture clut buffer allocation error, no memory!"); + result->address = address; result->info.width = draw_log2(clut->width); result->info.height = draw_log2(clut->height); diff --git a/engine/src/renderer/core/texture/texture_repository.cpp b/engine/src/renderer/core/texture/texture_repository.cpp index d9a71b9..06539e7 100644 --- a/engine/src/renderer/core/texture/texture_repository.cpp +++ b/engine/src/renderer/core/texture/texture_repository.cpp @@ -22,15 +22,50 @@ TextureRepository::~TextureRepository() { } } -// ---- -// Methods -// ---- +Texture* TextureRepository::getBySpriteOrMesh(const u32& t_id) const { + for (u32 i = 0; i < textures.size(); i++) { + if (textures[i]->isLinkedWith(t_id)) return textures[i]; + } + return nullptr; +} + +Texture* TextureRepository::getByTextureId(const u32& t_id) const { + for (u32 i = 0; i < textures.size(); i++) + if (t_id == textures[i]->getId()) return textures[i]; + return nullptr; +} + +const s32 TextureRepository::getIndexOf(const u32& t_texId) const { + for (u32 i = 0; i < textures.size(); i++) + if (textures[i]->getId() == t_texId) return i; + return -1; +} Texture* TextureRepository::add(Texture* texture) { textures.push_back(texture); return texture; } +void TextureRepository::removeByIndex(const u32& t_index) { + textures.erase(textures.begin() + t_index); +} + +void TextureRepository::removeById(const u32& t_texId) { + s32 index = getIndexOf(t_texId); + TYRA_ASSERT(index != -1, "Cant remove texture, because it was not found!"); + removeByIndex(index); +} + +void TextureRepository::free(const u32& t_texId) { + s32 index = getIndexOf(t_texId); + auto* tex = textures[index]; + + TYRA_ASSERT(index != -1, "Cant remove texture, because it was not found!"); + removeByIndex(index); + + delete tex; +} + Texture* TextureRepository::add(const char* fullpath) { TextureLoader& loader = texLoaderSelector.getLoaderByFileName(fullpath); diff --git a/engine/src/renderer/models/color.cpp b/engine/src/renderer/models/color.cpp index a48ab4d..2eccaeb 100644 --- a/engine/src/renderer/models/color.cpp +++ b/engine/src/renderer/models/color.cpp @@ -9,6 +9,8 @@ */ #include "renderer/models/color.hpp" +#include +#include namespace Tyra { diff --git a/samples/h4570/inc/h4570.hpp b/samples/h4570/inc/h4570.hpp index 3f59399..d340a18 100644 --- a/samples/h4570/inc/h4570.hpp +++ b/samples/h4570/inc/h4570.hpp @@ -13,7 +13,9 @@ #include #include #include "renderer/3d/pipeline/minecraft/minecraft_pipeline.hpp" -#include "renderer/3d/pipeline/std/std_pipeline.hpp" +#include "renderer/3d/pipeline/static/static_pipeline.hpp" +#include "renderer/3d/pipeline/dynamic/dynamic_pipeline.hpp" +#include "renderer/3d/mesh/static/static_mesh.hpp" namespace Tyra { @@ -28,10 +30,10 @@ class H4570 : public Game { private: Engine* engine; - Mesh* warrior; - Mesh* warrior2; - Mesh* warrior3; - Mesh* warrior4; + StaticMesh* staticMesh; + DynamicMesh* warrior; + u8 warriorsCount; + DynamicMesh** warriors; Sprite* picture; audsrv_adpcm_t* adpcmSample; Timer adpcmTimer; @@ -39,8 +41,11 @@ class H4570 : public Game { Vec4 cameraPosition, cameraLookAt; MinecraftPipeline mcPip; - StdPipeline stdPip; - StdpipOptions* renderOptions; + DynamicPipeline dynpip; + StaticPipeline stapip; + StaPipOptions* staOptions; + DynPipOptions* dynOptions; + Texture* warriorTex; Texture* blocksTex; u32 blocksCount; diff --git a/samples/h4570/src/h4570.cpp b/samples/h4570/src/h4570.cpp index 7bccfc4..f89589a 100644 --- a/samples/h4570/src/h4570.cpp +++ b/samples/h4570/src/h4570.cpp @@ -11,14 +11,27 @@ #include "h4570.hpp" #include "file/file_utils.hpp" #include "loaders/3d/md2/md2_loader.hpp" +#include "thread/threading.hpp" namespace Tyra { +float getRandomFloat(float a, float b) { + float random = ((float)rand()) / (float)RAND_MAX; + float diff = b - a; + float r = random * diff; + return a + r; +} + +int getRandomInt(int a, int b) { return (rand() % (b - a + 1)) + a; } + H4570::H4570(Engine* t_engine) { engine = t_engine; } H4570::~H4570() {} -Mesh* getWarrior(Renderer* renderer); -StdpipOptions* getRenderingOptions(); +StaticMesh* getStaticMesh(Renderer* renderer); +DynamicMesh* getWarrior(Renderer* renderer); +StaPipOptions* getStaPipOptions(); +DynPipOptions* getDynPipOptions(); +void setPipelineOptions(PipelineOptions* options); Sprite* get2DPicture(Renderer* renderer); void H4570::init() { @@ -33,30 +46,29 @@ void H4570::init() { engine->renderer.setClearScreenColor(Color(64.0F, 64.0F, 64.0F)); - warrior = getWarrior(&engine->renderer); + staticMesh = getStaticMesh(&engine->renderer); - auto* warriorTex = engine->renderer.core.texture.repository.getBySpriteOrMesh( + warrior = getWarrior(&engine->renderer); + warriorTex = engine->renderer.core.texture.repository.getBySpriteOrMesh( warrior->getMaterial(0)->getId()); - warrior2 = new Mesh(*warrior); - warrior2->translation.translateX(-3.0F); - warriorTex->addLink(warrior2->getMaterial(0)->getId()); - warrior2->playAnimation(0, warrior2->getFramesCount() - 1); - warrior2->setAnimSpeed(0.10F); + warriorsCount = 22; + warriors = new DynamicMesh*[warriorsCount]; + for (u8 i = 0; i < warriorsCount; i++) { + warriors[i] = new DynamicMesh(*warrior); + warriors[i]->translation.translateX(-40.0F + static_cast(i) * 4); + warriors[i]->translation.translateY(30.0F); + warriors[i]->translation.translateZ(-10.0F); + warriors[i]->translation.rotateX(-1.5F); + warriorTex->addLink(warriors[i]->getMaterial(0)->getId()); + warriors[i]->playAnimation(0, warriors[i]->getFramesCount() - 1); + warriors[i]->setCurrentAnimationFrame( + getRandomInt(0, warriors[i]->getFramesCount() - 1)); + warriors[i]->setAnimSpeed(getRandomFloat(0.1F, 0.9F)); + } - warrior3 = new Mesh(*warrior); - warrior3->translation.translateX(-6.0F); - warriorTex->addLink(warrior3->getMaterial(0)->getId()); - warrior3->playAnimation(0, warrior3->getFramesCount() - 1); - warrior3->setAnimSpeed(0.7F); - - warrior4 = new Mesh(*warrior); - warrior4->translation.translateX(3.0F); - warriorTex->addLink(warrior4->getMaterial(0)->getId()); - warrior4->playAnimation(0, warrior4->getFramesCount() - 1); - warrior4->setAnimSpeed(0.5F); - - renderOptions = getRenderingOptions(); + staOptions = getStaPipOptions(); + dynOptions = getDynPipOptions(); cameraPosition = Vec4(0.0F, 0.0F, 20.0F); cameraLookAt = *warrior->getPosition(); @@ -64,8 +76,9 @@ void H4570::init() { blocksTex = engine->renderer.core.texture.repository.add( FileUtils::fromCwd("blocks.png")); - mcPip.init(&engine->renderer.core); - stdPip.init(&engine->renderer.core); + mcPip.setRenderer(&engine->renderer.core); + dynpip.setRenderer(&engine->renderer.core); + stapip.setRenderer(&engine->renderer.core); picture = get2DPicture(&engine->renderer); @@ -100,30 +113,19 @@ void H4570::init() { blocks[i].color = Color(128.0F, 128.0F, 128.0F, 128.0F); } - engine->audio.playSong(); + // engine->audio.playSong(); + engine->renderer.setFrameLimit(false); } u32 counter = 0; void H4570::loop() { - if (counter++ > 100) { + if (counter++ > 30) { + // TYRA_LOG(engine->info.getFps()); counter = 0; - TYRA_LOG(engine->info.getFps()); } - warrior->animate(); - warrior2->animate(); - warrior3->animate(); - warrior4->animate(); - - // if ((engine->pad.getPressed().DpadUp || engine->pad.getPressed().DpadDown - // || - // engine->pad.getPressed().DpadLeft || - // engine->pad.getPressed().DpadRight) && - // adpcmTimer.getTimeDelta() > 8000) { - // adpcmTimer.prime(); - // engine->audio.playADPCM(adpcmSample, 1); - // } + for (u8 i = 0; i < warriorsCount; i++) warriors[i]->animate(); engine->renderer.beginFrame(CameraInfo3D(&cameraPosition, &cameraLookAt)); { @@ -135,26 +137,43 @@ void H4570::loop() { blocks[i].model = translations[i] * rotations[i] * scales[i]; } - // engine->renderer.renderer2D.render(picture); + engine->renderer.renderer3D.usePipeline(&stapip); + { stapip.render(staticMesh, staOptions); } - engine->renderer.renderer3D.usePipeline(&stdPip); + engine->renderer.renderer3D.usePipeline(&dynpip); { - stdPip.render(warrior, renderOptions); - // stdPip.render(warrior2, renderOptions); - // stdPip.render(warrior3, renderOptions); - // stdPip.render(warrior4, renderOptions); + Threading::switchThread(); + for (u8 i = 0; i < warriorsCount; i++) { + dynpip.render(warriors[i], dynOptions); + if (i == 5) Threading::switchThread(); + if (i == 10) Threading::switchThread(); + if (i == 15) Threading::switchThread(); + } } engine->renderer.renderer3D.usePipeline(&mcPip); - { mcPip.render(blocks, blocksCount, blocksTex, false); } + { mcPip.render(blocks, blocksCount, blocksTex); } } engine->renderer.endFrame(); } -Mesh* getWarrior(Renderer* renderer) { +StaticMesh* getStaticMesh(Renderer* renderer) { MD2Loader loader; auto* data = loader.load(FileUtils::fromCwd("warrior.md2"), .08F, false); - auto* result = new Mesh(*data); + auto* result = new StaticMesh(*data); + // result->translation.translateZ(-30.0F); + delete data; + + renderer->core.texture.repository.addByMesh(result, FileUtils::getCwd(), + "png"); + + return result; +} + +DynamicMesh* getWarrior(Renderer* renderer) { + MD2Loader loader; + auto* data = loader.load(FileUtils::fromCwd("warrior.md2"), .08F, false); + auto* result = new DynamicMesh(*data); // result->translation.translateZ(-30.0F); delete data; @@ -179,9 +198,19 @@ Sprite* get2DPicture(Renderer* renderer) { return sprite; } -StdpipOptions* getRenderingOptions() { - auto* options = new StdpipOptions(); +StaPipOptions* getStaPipOptions() { + auto* options = new StaPipOptions(); + setPipelineOptions(options); + return options; +} +DynPipOptions* getDynPipOptions() { + auto* options = new DynPipOptions(); + setPipelineOptions(options); + return options; +} + +void setPipelineOptions(PipelineOptions* options) { auto* ambientColor = new Color(32.0F, 32.0F, 32.0F, 32.0F); auto* directionalColors = new Color[3]; for (int i = 0; i < 3; i++) directionalColors[i].set(0.0F, 0.0F, 0.0F, 1.0F); @@ -189,12 +218,12 @@ StdpipOptions* getRenderingOptions() { for (int i = 0; i < 3; i++) directionalDirections[i].set(1.0F, 1.0F, 1.0F, 1.0F); - auto* lightingOptions = new StdpipLightingOptions(); // Memory leak! + auto* lightingOptions = new PipelineLightingOptions(); // Memory leak! lightingOptions->ambientColor = ambientColor; lightingOptions->directionalColors = directionalColors; lightingOptions->directionalDirections = directionalDirections; - options->shadingType = Tyra::StdpipShadingGouraud; + options->shadingType = Tyra::TyraShadingGouraud; options->blendingEnabled = true; options->antiAliasingEnabled = false; options->lighting = lightingOptions; @@ -204,8 +233,6 @@ StdpipOptions* getRenderingOptions() { directionalDirections[1].set(1.0F, 0.0F, 0.0F); directionalColors[1].set(96.0F, 0.0F, 0.0F); - - return options; } } // namespace Tyra diff --git a/samples/wellinator/inc/wellinator.hpp b/samples/wellinator/inc/wellinator.hpp index 236516a..ed115e3 100644 --- a/samples/wellinator/inc/wellinator.hpp +++ b/samples/wellinator/inc/wellinator.hpp @@ -13,7 +13,7 @@ #include #include #include "renderer/3d/pipeline/minecraft/minecraft_pipeline.hpp" -#include "renderer/3d/pipeline/std/std_pipeline.hpp" +#include "renderer/3d/pipeline/static/static_pipeline.hpp" namespace Tyra { @@ -28,7 +28,7 @@ class Wellinator : public Game { private: Engine* engine; - Mesh* warrior; + DynamicMesh* warrior; Sprite* picture; audsrv_adpcm_t* adpcmSample; Timer adpcmTimer; @@ -36,8 +36,8 @@ class Wellinator : public Game { Vec4 cameraPosition, cameraLookAt; MinecraftPipeline mcPip; - StdPipeline stdPip; - StdpipOptions* renderOptions; + StaticPipeline stapip; + StaPipOptions* renderOptions; Texture* blocksTex; u32 blocksCount; diff --git a/samples/wellinator/src/wellinator.cpp b/samples/wellinator/src/wellinator.cpp index 4504c30..4673a8e 100644 --- a/samples/wellinator/src/wellinator.cpp +++ b/samples/wellinator/src/wellinator.cpp @@ -17,8 +17,8 @@ namespace Tyra { Wellinator::Wellinator(Engine* t_engine) { engine = t_engine; } Wellinator::~Wellinator() {} -Mesh* getWarrior(Renderer* renderer); -StdpipOptions* getRenderingOptions(); +DynamicMesh* getWarrior(Renderer* renderer); +StaPipOptions* getRenderingOptions(); Sprite* get2DPicture(Renderer* renderer); void Wellinator::init() { @@ -41,8 +41,8 @@ void Wellinator::init() { blocksTex = engine->renderer.core.texture.repository.add( FileUtils::fromCwd("blocks.png")); - mcPip.init(&engine->renderer.core); - stdPip.init(&engine->renderer.core); + mcPip.setRenderer(&engine->renderer.core); + stapip.setRenderer(&engine->renderer.core); picture = get2DPicture(&engine->renderer); @@ -116,8 +116,8 @@ void Wellinator::loop() { // warrior->setPosition(*nextPos); - engine->renderer.renderer3D.usePipeline(&stdPip); - { stdPip.render(warrior, renderOptions); } + engine->renderer.renderer3D.usePipeline(&stapip); + { stapip.render(warrior, renderOptions); } engine->renderer.renderer3D.usePipeline(&mcPip); { mcPip.render(blocks, blocksCount, blocksTex, false); } @@ -125,10 +125,10 @@ void Wellinator::loop() { engine->renderer.endFrame(); } -Mesh* getWarrior(Renderer* renderer) { +DynamicMesh* getWarrior(Renderer* renderer) { MD2Loader loader; auto* data = loader.load(FileUtils::fromCwd("warrior.md2"), .08F, false); - auto* result = new Mesh(*data); + auto* result = new DynamicMesh(*data); result->translation.translateZ(-30.0F); delete data; renderer->core.texture.repository.addByMesh(result, FileUtils::getCwd(), @@ -150,8 +150,8 @@ Sprite* get2DPicture(Renderer* renderer) { return sprite; } -StdpipOptions* getRenderingOptions() { - auto* options = new StdpipOptions(); +StaPipOptions* getRenderingOptions() { + auto* options = new StaPipOptions(); auto* ambientColor = new Color(32.0F, 32.0F, 32.0F, 128.0F); auto* directionalColors = new Color[3]; @@ -160,12 +160,12 @@ StdpipOptions* getRenderingOptions() { for (int i = 0; i < 3; i++) directionalDirections[i].set(1.0F, 1.0F, 1.0F, 1.0F); - auto* lightingOptions = new StdpipLightingOptions(); // Memory leak! + auto* lightingOptions = new PipelineLightingOptions(); // Memory leak! lightingOptions->ambientColor = ambientColor; lightingOptions->directionalColors = directionalColors; lightingOptions->directionalDirections = directionalDirections; - options->shadingType = Tyra::StdpipShadingGouraud; + options->shadingType = Tyra::TyraShadingGouraud; options->blendingEnabled = true; options->antiAliasingEnabled = false; options->lighting = lightingOptions;