diff --git a/ROADMAP.txt b/ROADMAP.txt index b4a88dd..f657171 100644 --- a/ROADMAP.txt +++ b/ROADMAP.txt @@ -1,4 +1,5 @@ ------------ Tyra's v2.0 roadmap to publish on GitHub ------------ +- [General] Tyra version - [Renderer] Test clipper - [Renderer] Fog - [Demo] Create cool demo which will show all features of Tyra diff --git a/demo/inc/states/game/debug_object.hpp b/demo/inc/states/game/debug_object.hpp new file mode 100644 index 0000000..2ca5d85 --- /dev/null +++ b/demo/inc/states/game/debug_object.hpp @@ -0,0 +1,42 @@ +/* +# ______ ____ ___ +# | \/ ____| |___| +# | | | \ | | +#----------------------------------------------------------------------- +# Copyright 2022, tyra - https://github.com/h4570/tyra +# Licenced under Apache License 2.0 +# Sandro Sobczyński +*/ + +#pragma once + +#include +#include +#include +#include "states/game/renderer/renderer_static_pair.hpp" + +using Tyra::Renderer; +using Tyra::StaPipOptions; +using Tyra::StaticMesh; +using Tyra::TextureRepository; +using Tyra::Vec4; + +namespace Demo { + +class DebugObject { + public: + DebugObject(TextureRepository* repo); + ~DebugObject(); + + StaticMesh* mesh; + StaPipOptions* options; + RendererStaticPair* pair; + + void setPosition(const Vec4& v); + + private: + float rotator; + void allocateOptions(); +}; + +} // namespace Demo diff --git a/demo/inc/states/game/game_state.hpp b/demo/inc/states/game/game_state.hpp index 8a64f17..b8b5a3f 100644 --- a/demo/inc/states/game/game_state.hpp +++ b/demo/inc/states/game/game_state.hpp @@ -12,6 +12,10 @@ #include "state/state.hpp" #include "state/global_state_type.hpp" +#include "./player/player.hpp" +#include "./renderer/game_renderer.hpp" +#include "./terrain/terrain.hpp" +#include "./debug_object.hpp" namespace Demo { @@ -35,6 +39,12 @@ class GameState : public State { GlobalStateType state; bool _wantFinish; bool initialized; + u8 fpsChecker; + + GameRenderer renderer; + Player player; + Terrain terrain; + DebugObject dbgObj; }; } // namespace Demo diff --git a/demo/inc/states/game/player/camera.hpp b/demo/inc/states/game/player/camera.hpp new file mode 100644 index 0000000..b6ca32f --- /dev/null +++ b/demo/inc/states/game/player/camera.hpp @@ -0,0 +1,42 @@ +/* +# ______ ____ ___ +# | \/ ____| |___| +# | | | \ | | +#----------------------------------------------------------------------- +# 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/core/3d/camera_info_3d.hpp" +#include "pad/pad.hpp" + +using Tyra::CameraInfo3D; +using Tyra::Pad; +using Tyra::Vec4; + +namespace Demo { + +class Camera { + public: + Camera(Pad* pad); + ~Camera(); + + Vec4 lookAt; + Vec4 position; + Vec4 unitCircle; + + CameraInfo3D getCameraInfo() { return CameraInfo3D(&position, &lookAt); } + + void update(const Vec4& playerPosition); + + private: + float circleRotation, lengthFromOrigin, height; + + Pad* pad; +}; + +} // namespace Demo diff --git a/demo/inc/states/game/player/player.hpp b/demo/inc/states/game/player/player.hpp new file mode 100644 index 0000000..8525c26 --- /dev/null +++ b/demo/inc/states/game/player/player.hpp @@ -0,0 +1,47 @@ +/* +# ______ ____ ___ +# | \/ ____| |___| +# | | | \ | | +#----------------------------------------------------------------------- +# Copyright 2022, tyra - https://github.com/h4570/tyra +# Licenced under Apache License 2.0 +# Sandro Sobczyński +*/ + +#pragma once + +#include "states/game/renderer/renderer_dynamic_pair.hpp" +#include "states/game/renderer/renderer_static_pair.hpp" +#include "./weapon.hpp" +#include "./camera.hpp" +#include + +using Tyra::Engine; +using Tyra::Pad; +using Tyra::Vec4; + +namespace Demo { + +class Player { + public: + Player(Engine* engine); + ~Player(); + + CameraInfo3D getCameraInfo() { return camera.getCameraInfo(); } + + std::vector staticPairs; + std::vector dynamicPairs; + + void update(); + + private: + void handlePlayerPosition(); + +float speed; + Pad* pad; + Vec4 position; + Weapon weapon; + Camera camera; +}; + +} // namespace Demo diff --git a/demo/inc/states/game/player/weapon.hpp b/demo/inc/states/game/player/weapon.hpp new file mode 100644 index 0000000..0118461 --- /dev/null +++ b/demo/inc/states/game/player/weapon.hpp @@ -0,0 +1,38 @@ +/* +# ______ ____ ___ +# | \/ ____| |___| +# | | | \ | | +#----------------------------------------------------------------------- +# Copyright 2022, tyra - https://github.com/h4570/tyra +# Licenced under Apache License 2.0 +# Sandro Sobczyński +*/ + +#pragma once + +#include +#include +#include + +using Tyra::Renderer; +using Tyra::StaPipOptions; +using Tyra::StaticMesh; +using Tyra::TextureRepository; + +namespace Demo { + +class Weapon { + public: + Weapon(TextureRepository* repo); + ~Weapon(); + + StaticMesh* mesh; + StaPipOptions* options; + + void update(); + + private: + void allocateOptions(); +}; + +} // namespace Demo diff --git a/demo/inc/states/game/renderer/game_renderer.hpp b/demo/inc/states/game/renderer/game_renderer.hpp new file mode 100644 index 0000000..096566b --- /dev/null +++ b/demo/inc/states/game/renderer/game_renderer.hpp @@ -0,0 +1,49 @@ +/* +# ______ ____ ___ +# | \/ ____| |___| +# | | | \ | | +#----------------------------------------------------------------------- +# Copyright 2022, tyra - https://github.com/h4570/tyra +# Licenced under Apache License 2.0 +# Sandro Sobczyński +*/ + +#pragma once + +#include "renderer/renderer.hpp" +#include "renderer/3d/pipeline/dynamic/dynamic_pipeline.hpp" +#include "renderer/3d/pipeline/static/static_pipeline.hpp" +#include "./renderer_dynamic_pair.hpp" +#include "./renderer_static_pair.hpp" + +using Tyra::DynamicPipeline; +using Tyra::Renderer; +using Tyra::StaticPipeline; + +namespace Demo { + +class GameRenderer { + public: + GameRenderer(Renderer* renderer); + ~GameRenderer(); + + void add(std::vector staticPairs); + void add(std::vector dynamicPairs); + void add(RendererStaticPair* staticPair); + void add(RendererDynamicPair* dynamicPair); + + void clear(); + + void render(); + + private: + Renderer* renderer; + + StaticPipeline stpip; + DynamicPipeline dypip; + + std::vector staticPairs; + std::vector dynamicPairs; +}; + +} // namespace Demo diff --git a/demo/inc/states/game/renderer/renderer_dynamic_pair.hpp b/demo/inc/states/game/renderer/renderer_dynamic_pair.hpp new file mode 100644 index 0000000..d32968c --- /dev/null +++ b/demo/inc/states/game/renderer/renderer_dynamic_pair.hpp @@ -0,0 +1,26 @@ +/* +# ______ ____ ___ +# | \/ ____| |___| +# | | | \ | | +#----------------------------------------------------------------------- +# Copyright 2022, tyra - https://github.com/h4570/tyra +# Licenced under Apache License 2.0 +# Sandro Sobczyński +*/ + +#pragma once + +#include "renderer/3d/pipeline/dynamic/dynamic_pipeline.hpp" +#include "renderer/3d/mesh/dynamic/dynamic_mesh.hpp" + +using Tyra::DynamicMesh; +using Tyra::DynPipOptions; + +namespace Demo { + +struct RendererDynamicPair { + DynamicMesh* mesh; + DynPipOptions* options; +}; + +} // namespace Demo diff --git a/demo/inc/states/game/renderer/renderer_static_pair.hpp b/demo/inc/states/game/renderer/renderer_static_pair.hpp new file mode 100644 index 0000000..3876c1d --- /dev/null +++ b/demo/inc/states/game/renderer/renderer_static_pair.hpp @@ -0,0 +1,26 @@ +/* +# ______ ____ ___ +# | \/ ____| |___| +# | | | \ | | +#----------------------------------------------------------------------- +# Copyright 2022, tyra - https://github.com/h4570/tyra +# Licenced under Apache License 2.0 +# Sandro Sobczyński +*/ + +#pragma once + +#include "renderer/3d/pipeline/static/static_pipeline.hpp" +#include "renderer/3d/mesh/static/static_mesh.hpp" + +using Tyra::StaPipOptions; +using Tyra::StaticMesh; + +namespace Demo { + +struct RendererStaticPair { + StaticMesh* mesh; + StaPipOptions* options; +}; + +} // namespace Demo diff --git a/demo/inc/states/game/terrain/terrain.hpp b/demo/inc/states/game/terrain/terrain.hpp new file mode 100644 index 0000000..3c6e7be --- /dev/null +++ b/demo/inc/states/game/terrain/terrain.hpp @@ -0,0 +1,39 @@ +/* +# ______ ____ ___ +# | \/ ____| |___| +# | | | \ | | +#----------------------------------------------------------------------- +# Copyright 2022, tyra - https://github.com/h4570/tyra +# Licenced under Apache License 2.0 +# Sandro Sobczyński +*/ + +#pragma once + +#include +#include +#include "states/game/renderer/renderer_static_pair.hpp" +#include + +using Tyra::StaPipOptions; +using Tyra::StaticMesh; +using Tyra::TextureRepository; + +namespace Demo { + +class Terrain { + public: + Terrain(TextureRepository* repo); + ~Terrain(); + + StaticMesh* mesh; + StaPipOptions* options; + RendererStaticPair* pair; + + void update(); + + private: + void allocateOptions(); +}; + +} // namespace Demo diff --git a/demo/src/demo_game.cpp b/demo/src/demo_game.cpp index 532c20f..5774c32 100644 --- a/demo/src/demo_game.cpp +++ b/demo/src/demo_game.cpp @@ -15,7 +15,7 @@ namespace Demo { DemoGame::DemoGame(Engine* t_engine) - : engine(t_engine), stateManager(STATE_INTRO, STATE_EXIT) {} + : engine(t_engine), stateManager(STATE_GAME, STATE_EXIT) {} DemoGame::~DemoGame() {} void DemoGame::init() { diff --git a/demo/src/states/game/debug_object.cpp b/demo/src/states/game/debug_object.cpp new file mode 100644 index 0000000..92bf667 --- /dev/null +++ b/demo/src/states/game/debug_object.cpp @@ -0,0 +1,61 @@ +/* +# ______ ____ ___ +# | \/ ____| |___| +# | | | \ | | +#----------------------------------------------------------------------- +# Copyright 2022, tyra - https://github.com/h4570/tyra +# Licenced under Apache License 2.0 +# Sandro Sobczyński +*/ + +#include "states/game/debug_object.hpp" +#include +#include + +using Tyra::Color; +using Tyra::FileUtils; +using Tyra::TyrobjLoader; + +namespace Demo { + +DebugObject::DebugObject(TextureRepository* repo) { + TyrobjLoader loader; + auto* data = + loader.load(FileUtils::fromCwd("game/models/debug.obj"), 1, .5F, true); + data->normalsEnabled = false; + data->textureCoordsEnabled = false; + mesh = new StaticMesh(*data); + delete data; + mesh->getMaterial(0)->color = Color(192.0F, 32.0F, 32.0F, 128.0F); + rotator = 0.0F; + allocateOptions(); + + pair = new RendererStaticPair{mesh, options}; +} + +void DebugObject::setPosition(const Vec4& v) { + mesh->translation.identity(); + mesh->rotation.identity(); + mesh->translation.translate(v); + mesh->rotation.rotateX(rotator); + mesh->rotation.rotateY(rotator); + mesh->rotation.rotateZ(rotator); + + rotator += 0.05F; + if (rotator >= 360.0F) rotator = 0.0F; +} + +DebugObject::~DebugObject() { + delete mesh; + delete options; + delete pair; +} + +void DebugObject::allocateOptions() { + options = new StaPipOptions(); + options->shadingType = Tyra::TyraShadingGouraud; + options->blendingEnabled = false; + options->antiAliasingEnabled = false; +} + +} // namespace Demo diff --git a/demo/src/states/game/game_state.cpp b/demo/src/states/game/game_state.cpp index 805f613..5819020 100644 --- a/demo/src/states/game/game_state.cpp +++ b/demo/src/states/game/game_state.cpp @@ -9,19 +9,20 @@ */ #include "states/game/game_state.hpp" -#include "file/file_utils.hpp" -#include "thread/threading.hpp" #include "debug/debug.hpp" -using Tyra::FileUtils; -using Tyra::Threading; - namespace Demo { -GameState::GameState(Engine* t_engine) : State(t_engine) { +GameState::GameState(Engine* t_engine) + : State(t_engine), + renderer(&t_engine->renderer), + player(t_engine), + terrain(&t_engine->renderer.core.texture.repository), + dbgObj(&t_engine->renderer.core.texture.repository) { state = STATE_GAME; _wantFinish = false; initialized = false; + fpsChecker = 0; } GameState::~GameState() {} @@ -42,8 +43,26 @@ GlobalStateType GameState::onFinish() { } void GameState::update() { - engine->renderer.beginFrame(); - Threading::switchThread(); + if (fpsChecker++ > 100) { + TYRA_LOG("FPS: ", engine->info.getFps()); + fpsChecker = 0; + } + + auto cameraInfo = player.getCameraInfo(); + engine->renderer.beginFrame(cameraInfo); + + player.update(); + dbgObj.setPosition(*cameraInfo.looksAt); + + renderer.clear(); + { + renderer.add(player.staticPairs); + renderer.add(player.dynamicPairs); + renderer.add(terrain.pair); + renderer.add(dbgObj.pair); + } + renderer.render(); + engine->renderer.endFrame(); } diff --git a/demo/src/states/game/player/camera.cpp b/demo/src/states/game/player/camera.cpp new file mode 100644 index 0000000..6be3c9f --- /dev/null +++ b/demo/src/states/game/player/camera.cpp @@ -0,0 +1,49 @@ +/* +# ______ ____ ___ +# | \/ ____| |___| +# | | | \ | | +#----------------------------------------------------------------------- +# Copyright 2022, tyra - https://github.com/h4570/tyra +# Licenced under Apache License 2.0 +# Sandro Sobczyński +*/ + +#include "states/game/player/camera.hpp" +#include "debug/debug.hpp" + +namespace Demo { + +Camera::Camera(Pad* t_pad) : lookAt(0.0F), position(0.0F), pad(t_pad) { + lengthFromOrigin = 30.0F; + circleRotation = -3.5F; + height = 1.5F; +} + +Camera::~Camera() {} + +void Camera::update(const Vec4& playerPosition) { + const float rotationOffset = 0.03F; + const float heightOffset = 0.5F; + + const auto& rightJoy = pad->getRightJoyPad(); + + if (rightJoy.h <= 100) { + circleRotation -= rotationOffset; + } else if (rightJoy.h >= 200) { + circleRotation += rotationOffset; + } + + if (rightJoy.v <= 100) { + height -= heightOffset; + } else if (rightJoy.v >= 200) { + height += heightOffset; + } + + unitCircle.x = (sin(circleRotation) * lengthFromOrigin); + unitCircle.y = height + playerPosition.y; + unitCircle.z = (cos(circleRotation) * lengthFromOrigin); + + lookAt = unitCircle + playerPosition; +} + +} // namespace Demo diff --git a/demo/src/states/game/player/player.cpp b/demo/src/states/game/player/player.cpp new file mode 100644 index 0000000..89ced84 --- /dev/null +++ b/demo/src/states/game/player/player.cpp @@ -0,0 +1,70 @@ +/* +# ______ ____ ___ +# | \/ ____| |___| +# | | | \ | | +#----------------------------------------------------------------------- +# Copyright 2022, tyra - https://github.com/h4570/tyra +# Licenced under Apache License 2.0 +# Sandro Sobczyński +*/ + +#include "states/game/player/player.hpp" + +namespace Demo { + +Player::Player(Engine* engine) + : position(0.0F), + weapon(&engine->renderer.core.texture.repository), + camera(&engine->pad) { + staticPairs.push_back(new RendererStaticPair{weapon.mesh, weapon.options}); + pad = &engine->pad; + position = Vec4(3.0F, 3.0F, 0.0F); + camera.lookAt = Vec4(0.0F, 0.0F, -30.0F); + speed = 0.5F; +} + +Player::~Player() { + for (auto pair : staticPairs) { + delete pair; + } + for (auto pair : dynamicPairs) { + delete pair; + } +} + +void Player::update() { + handlePlayerPosition(); + camera.update(position); + weapon.update(); +} + +void Player::handlePlayerPosition() { + const auto& leftJoy = pad->getLeftJoyPad(); + + auto normalizedCamera = Vec4(camera.unitCircle); + normalizedCamera.normalize(); + normalizedCamera *= speed; + + Vec4 nextPosition(position); + + if (leftJoy.v <= 100) { + nextPosition.x += normalizedCamera.x; + nextPosition.z += normalizedCamera.z; + } else if (leftJoy.v >= 200) { + nextPosition.x += -normalizedCamera.x; + nextPosition.z += -normalizedCamera.z; + } + if (leftJoy.h <= 100) { + nextPosition.x += normalizedCamera.z; + nextPosition.z += -normalizedCamera.x; + } else if (leftJoy.h >= 200) { + nextPosition.x += -normalizedCamera.z; + nextPosition.z += normalizedCamera.x; + } + + position = nextPosition; + + camera.position = position; +} + +} // namespace Demo diff --git a/demo/src/states/game/player/weapon.cpp b/demo/src/states/game/player/weapon.cpp new file mode 100644 index 0000000..fe1754f --- /dev/null +++ b/demo/src/states/game/player/weapon.cpp @@ -0,0 +1,57 @@ +/* +# ______ ____ ___ +# | \/ ____| |___| +# | | | \ | | +#----------------------------------------------------------------------- +# Copyright 2022, tyra - https://github.com/h4570/tyra +# Licenced under Apache License 2.0 +# Sandro Sobczyński +*/ + +#include "states/game/player/weapon.hpp" +#include +#include + +using Tyra::FileUtils; +using Tyra::TyrobjLoader; + +namespace Demo { + +Weapon::Weapon(TextureRepository* repo) { + TyrobjLoader loader; + auto* data = loader.load(FileUtils::fromCwd("game/models/ak47/ak47.obj"), 1, + 1.0F, true); + data->normalsEnabled = false; + mesh = new StaticMesh(*data); + delete data; + + mesh->translation.translateZ(-50.0F); + + repo->addByMesh(mesh, FileUtils::fromCwd("game/models/ak47/"), "png"); + + allocateOptions(); +} + +// float testRotation = 0.0F; + +void Weapon::update() { + // testRotation += 0.001F; + mesh->rotation.identity(); + mesh->rotation.rotateZ(0.1F); + mesh->rotation.rotateY(-4.3F); + // TYRA_LOG(testRotation); +} + +Weapon::~Weapon() { + delete mesh; + delete options; +} + +void Weapon::allocateOptions() { + options = new StaPipOptions(); + options->shadingType = Tyra::TyraShadingGouraud; + options->blendingEnabled = false; + options->antiAliasingEnabled = false; +} + +} // namespace Demo diff --git a/demo/src/states/game/renderer/game_renderer.cpp b/demo/src/states/game/renderer/game_renderer.cpp new file mode 100644 index 0000000..d1913a9 --- /dev/null +++ b/demo/src/states/game/renderer/game_renderer.cpp @@ -0,0 +1,70 @@ +/* +# ______ ____ ___ +# | \/ ____| |___| +# | | | \ | | +#----------------------------------------------------------------------- +# Copyright 2022, tyra - https://github.com/h4570/tyra +# Licenced under Apache License 2.0 +# Sandro Sobczyński +*/ + +#include "states/game/renderer/game_renderer.hpp" +#include "thread/threading.hpp" + +using Tyra::Threading; + +namespace Demo { + +GameRenderer::GameRenderer(Renderer* t_renderer) { + renderer = t_renderer; + + stpip.setRenderer(&renderer->core); + dypip.setRenderer(&renderer->core); +} + +GameRenderer::~GameRenderer() {} + +void GameRenderer::add(std::vector t_staticPairs) { + staticPairs.insert(staticPairs.end(), t_staticPairs.begin(), + t_staticPairs.end()); +} + +void GameRenderer::add(std::vector t_dynamicPairs) { + dynamicPairs.insert(dynamicPairs.end(), t_dynamicPairs.begin(), + t_dynamicPairs.end()); +} + +void GameRenderer::add(RendererStaticPair* staticPair) { + staticPairs.push_back(staticPair); +} + +void GameRenderer::add(RendererDynamicPair* dynamicPair) { + dynamicPairs.push_back(dynamicPair); +} + +void GameRenderer::clear() { + staticPairs.clear(); + dynamicPairs.clear(); +} + +void GameRenderer::render() { + if (staticPairs.size()) { + renderer->renderer3D.usePipeline(&stpip); + + for (auto& pair : staticPairs) { + stpip.render(pair->mesh, pair->options); + } + } + + Threading::switchThread(); + + if (dynamicPairs.size()) { + renderer->renderer3D.usePipeline(&dypip); + + for (auto& pair : dynamicPairs) { + dypip.render(pair->mesh, pair->options); + } + } +} + +} // namespace Demo diff --git a/demo/src/states/game/terrain/terrain.cpp b/demo/src/states/game/terrain/terrain.cpp new file mode 100644 index 0000000..cb7298e --- /dev/null +++ b/demo/src/states/game/terrain/terrain.cpp @@ -0,0 +1,61 @@ +/* +# ______ ____ ___ +# | \/ ____| |___| +# | | | \ | | +#----------------------------------------------------------------------- +# Copyright 2022, tyra - https://github.com/h4570/tyra +# Licenced under Apache License 2.0 +# Sandro Sobczyński +*/ + +#include "states/game/terrain/terrain.hpp" +#include +#include + +using Tyra::FileUtils; +using Tyra::TyrobjLoader; + +namespace Demo { + +Terrain::Terrain(TextureRepository* repo) { + TyrobjLoader loader; + auto* data = loader.load( + FileUtils::fromCwd("game/models/terrain/terrain.obj"), 1, 5.0F, true); + data->normalsEnabled = false; + mesh = new StaticMesh(*data); + mesh->getMaterial(0)->color.r = 96.0F; + mesh->getMaterial(0)->color.g = 96.0F; + mesh->getMaterial(0)->color.b = 96.0F; + delete data; + + repo->addByMesh(mesh, FileUtils::fromCwd("game/models/terrain/"), "png"); + + allocateOptions(); + + pair = new RendererStaticPair{mesh, options}; +} + +// float testRotation = 0.0F; + +void Terrain::update() { + // testRotation += 0.001F; + mesh->rotation.identity(); + mesh->rotation.rotateZ(0.1F); + mesh->rotation.rotateY(-4.3F); + // TYRA_LOG(testRotation); +} + +Terrain::~Terrain() { + delete mesh; + delete options; + delete pair; +} + +void Terrain::allocateOptions() { + options = new StaPipOptions(); + options->shadingType = Tyra::TyraShadingGouraud; + options->blendingEnabled = true; + options->antiAliasingEnabled = false; +} + +} // namespace Demo diff --git a/engine/inc/renderer/3d/pipeline/dynamic/core/dynpip_core.hpp b/engine/inc/renderer/3d/pipeline/dynamic/core/dynpip_core.hpp index 773a553..23db40c 100644 --- a/engine/inc/renderer/3d/pipeline/dynamic/core/dynpip_core.hpp +++ b/engine/inc/renderer/3d/pipeline/dynamic/core/dynpip_core.hpp @@ -29,6 +29,7 @@ class DynPipCore { /** Force starting VU1 program instead of continueing */ void clear() { qbufferRenderer.clearLastProgramName(); } + void updatePrimLod(PipelineInfoBag* bag); /** * Send model matrix, lighting data and other 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 index aa14523..b2e4a65 100644 --- a/engine/inc/renderer/3d/pipeline/shared/bag/pipeline_info_bag.hpp +++ b/engine/inc/renderer/3d/pipeline/shared/bag/pipeline_info_bag.hpp @@ -14,6 +14,7 @@ #include "math/m4x4.hpp" #include "math/vec4.hpp" #include "../pipeline_shading_type.hpp" +#include "../pipeline_texture_mapping_type.hpp" namespace Tyra { @@ -26,6 +27,7 @@ class PipelineInfoBag { M4x4* model; PipelineShadingType shadingType; + PipelineTextureMappingType textureMappingType; bool blendingEnabled; bool antiAliasingEnabled; diff --git a/engine/inc/renderer/3d/pipeline/shared/pipeline_options.hpp b/engine/inc/renderer/3d/pipeline/shared/pipeline_options.hpp index a9f8f26..8800054 100644 --- a/engine/inc/renderer/3d/pipeline/shared/pipeline_options.hpp +++ b/engine/inc/renderer/3d/pipeline/shared/pipeline_options.hpp @@ -10,8 +10,9 @@ #pragma once -#include "renderer/3d/pipeline/shared/pipeline_shading_type.hpp" +#include "../shared/pipeline_shading_type.hpp" #include "../shared/pipeline_lighting_options.hpp" +#include "../shared/pipeline_texture_mapping_type.hpp" #include "./pipeline_frustum_culling.hpp" namespace Tyra { @@ -23,11 +24,13 @@ class PipelineOptions { antiAliasingEnabled = false; blendingEnabled = true; shadingType = TyraShadingFlat; + textureMappingType = TyraLinear; } ~PipelineOptions() {} PipelineFrustumCulling frustumCulling; PipelineShadingType shadingType; + PipelineTextureMappingType textureMappingType; bool blendingEnabled; bool antiAliasingEnabled; diff --git a/engine/inc/renderer/3d/pipeline/shared/pipeline_texture_mapping_type.hpp b/engine/inc/renderer/3d/pipeline/shared/pipeline_texture_mapping_type.hpp new file mode 100644 index 0000000..2c7cdeb --- /dev/null +++ b/engine/inc/renderer/3d/pipeline/shared/pipeline_texture_mapping_type.hpp @@ -0,0 +1,20 @@ +/* +# ______ ____ ___ +# | \/ ____| |___| +# | | | \ | | +#----------------------------------------------------------------------- +# Copyright 2022, tyra - https://github.com/h4570/tyra +# Licenced under Apache License 2.0 +# Sandro Sobczyński +*/ + +#pragma once + +namespace Tyra { + +enum PipelineTextureMappingType { + TyraNearest, + TyraLinear, +}; + +} // 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 index 09fa548..5cc9d14 100644 --- a/engine/src/renderer/3d/pipeline/dynamic/core/dynpip_core.cpp +++ b/engine/src/renderer/3d/pipeline/dynamic/core/dynpip_core.cpp @@ -41,8 +41,8 @@ void DynPipCore::setPrim() { void DynPipCore::setLod() { lod.calculation = LOD_USE_K; lod.max_level = 0; - lod.mag_filter = LOD_MAG_NEAREST; - lod.min_filter = LOD_MIN_NEAREST; + lod.mag_filter = LOD_MAG_LINEAR; + lod.min_filter = LOD_MIN_LINEAR; lod.mipmap_select = LOD_MIPMAP_REGISTER; lod.l = 0; lod.k = 0.0F; @@ -70,6 +70,20 @@ void DynPipCore::initParts(DynPipBag* bag) { delete texBuffers; } +void DynPipCore::updatePrimLod(PipelineInfoBag* bag) { + prim.antialiasing = bag->antiAliasingEnabled; + prim.blending = bag->blendingEnabled; + prim.shading = bag->shadingType; + + if (bag->textureMappingType == TyraLinear) { + lod.mag_filter = LOD_MAG_LINEAR; + lod.min_filter = LOD_MIN_LINEAR; + } else { + lod.mag_filter = LOD_MAG_NEAREST; + lod.min_filter = LOD_MIN_NEAREST; + } +} + void DynPipCore::renderPart(DynPipBag** bags, const u32& count, const bool& frustumCull) { if (count <= 0) return; diff --git a/engine/src/renderer/3d/pipeline/dynamic/dynamic_pipeline.cpp b/engine/src/renderer/3d/pipeline/dynamic/dynamic_pipeline.cpp index a38532b..fced2aa 100644 --- a/engine/src/renderer/3d/pipeline/dynamic/dynamic_pipeline.cpp +++ b/engine/src/renderer/3d/pipeline/dynamic/dynamic_pipeline.cpp @@ -75,6 +75,7 @@ void DynamicPipeline::render(DynamicMesh* mesh, const DynPipOptions* options) { setBuffersDefaultVars(buffers, mesh, infoBag); core.clear(); + core.updatePrimLod(infoBag); for (u32 i = 0; i < mesh->getMaterialsCount(); i++) { auto* material = mesh->getMaterial(i); @@ -210,10 +211,12 @@ PipelineInfoBag* DynamicPipeline::getInfoBag(DynamicMesh* mesh, result->antiAliasingEnabled = options->antiAliasingEnabled; result->blendingEnabled = options->blendingEnabled; result->shadingType = options->shadingType; + result->textureMappingType = options->textureMappingType; } else { result->antiAliasingEnabled = false; result->blendingEnabled = true; result->shadingType = TyraShadingFlat; + result->textureMappingType = TyraLinear; } result->model = model; @@ -243,8 +246,9 @@ DynPipTextureBag* DynamicPipeline::getTextureBag( result->texture = rendererCore->texture.repository.getBySpriteOrMesh(material->getId()); - TYRA_ASSERT(result->texture, "Texture for material id: ", material->getId(), - "was not found in texture repository!"); + TYRA_ASSERT( + result->texture, "Texture for material id: ", material->getId(), + "was not found in texture repository! Did you forget to add texture?"); result->coordinatesFrom = &materialFrameFrom->getTextureCoords()[startIndex]; result->coordinatesTo = &materialFrameTo->getTextureCoords()[startIndex]; diff --git a/engine/src/renderer/3d/pipeline/shared/bag/pipeline_info_bag.cpp b/engine/src/renderer/3d/pipeline/shared/bag/pipeline_info_bag.cpp index e42b02e..923d913 100644 --- a/engine/src/renderer/3d/pipeline/shared/bag/pipeline_info_bag.cpp +++ b/engine/src/renderer/3d/pipeline/shared/bag/pipeline_info_bag.cpp @@ -14,6 +14,7 @@ namespace Tyra { PipelineInfoBag::PipelineInfoBag() { shadingType = TyraShadingFlat; + textureMappingType = TyraLinear; blendingEnabled = true; antiAliasingEnabled = false; model = nullptr; diff --git a/engine/src/renderer/3d/pipeline/static/core/stapip_core.cpp b/engine/src/renderer/3d/pipeline/static/core/stapip_core.cpp index 5f755b6..8e46555 100644 --- a/engine/src/renderer/3d/pipeline/static/core/stapip_core.cpp +++ b/engine/src/renderer/3d/pipeline/static/core/stapip_core.cpp @@ -50,8 +50,8 @@ void StaPipCore::setPrim() { void StaPipCore::setLod() { lod.calculation = LOD_USE_K; lod.max_level = 0; - lod.mag_filter = LOD_MAG_NEAREST; - lod.min_filter = LOD_MIN_NEAREST; + lod.mag_filter = LOD_MAG_LINEAR; + lod.min_filter = LOD_MIN_LINEAR; lod.mipmap_select = LOD_MIPMAP_REGISTER; lod.l = 0; lod.k = 0.0F; 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 index 7a17e33..103c12e 100644 --- a/engine/src/renderer/3d/pipeline/static/core/stapip_qbuffer_renderer.cpp +++ b/engine/src/renderer/3d/pipeline/static/core/stapip_qbuffer_renderer.cpp @@ -159,6 +159,14 @@ void StaPipQBufferRenderer::setInfo(PipelineInfoBag* bag) { prim->antialiasing = bag->antiAliasingEnabled; prim->blending = bag->blendingEnabled; prim->shading = bag->shadingType; + + if (bag->textureMappingType == TyraLinear) { + lod->mag_filter = LOD_MAG_LINEAR; + lod->min_filter = LOD_MIN_LINEAR; + } else { + lod->mag_filter = LOD_MAG_NEAREST; + lod->min_filter = LOD_MIN_NEAREST; + } } void StaPipQBufferRenderer::sendStaticData() const { diff --git a/engine/src/renderer/3d/pipeline/static/static_pipeline.cpp b/engine/src/renderer/3d/pipeline/static/static_pipeline.cpp index 9fd57af..734bbc0 100644 --- a/engine/src/renderer/3d/pipeline/static/static_pipeline.cpp +++ b/engine/src/renderer/3d/pipeline/static/static_pipeline.cpp @@ -94,10 +94,12 @@ PipelineInfoBag* StaticPipeline::getInfoBag(StaticMesh* mesh, result->blendingEnabled = options->blendingEnabled; result->shadingType = options->shadingType; result->fullClipChecks = options->fullClipChecks; + result->textureMappingType = options->textureMappingType; } else { result->antiAliasingEnabled = false; result->blendingEnabled = true; result->shadingType = TyraShadingFlat; + result->textureMappingType = TyraLinear; result->fullClipChecks = false; } @@ -127,8 +129,9 @@ StaPipTextureBag* StaticPipeline::getTextureBag( result->texture = rendererCore->texture.repository.getBySpriteOrMesh(material->getId()); - TYRA_ASSERT(result->texture, "Texture for material id: ", material->getId(), - "was not found in texture repository!"); + TYRA_ASSERT( + result->texture, "Texture for material id: ", material->getId(), + "was not found in texture repository! Did you forget to add texture?"); result->coordinates = materialFrame->getTextureCoords();