3DRenderer instancing

This commit is contained in:
JackCarterSmith 2024-10-12 14:35:08 +02:00
parent 9ab9e476b9
commit b200c38ca1
Signed by: JackCarterSmith
GPG Key ID: 832E52F4E23F8F24
6 changed files with 14 additions and 13 deletions

View File

@ -20,7 +20,6 @@ public:
void Draw(sf::RenderTexture& context);
private:
sf::RenderTexture mWorldRender; // This is used to create the scene
std::unique_ptr<Camera> mMainCamera; // Default player view
std::vector<std::shared_ptr<WorldObject>> mRenderList; // List of elements to be rendered next frame

View File

@ -16,7 +16,7 @@ void Camera::UpdateCamView() {
M3D_VECTOR L = M3D_V4LoadF3(&mLook);
M3D_VECTOR U = M3D_V4LoadF3(&mUp);
M3D_V4StoreF4x4(&mViewMat, M3D_TransformMatrixCamLookAtLH(P, L, U));
M3D_V4StoreF4x4(&mViewMat, M3D_TransformMatrixCamLookToLH(P, L, U));
}
void Camera::LookAt(M3D_VECTOR pos, M3D_VECTOR target, M3D_VECTOR worldUp) {

View File

@ -69,7 +69,7 @@ void CockpitUI::Draw(std::shared_ptr<sf::RenderWindow> context) {
}
WorldUI::WorldUI() : UI() {
WorldUI::WorldUI(std::shared_ptr<Graphic3DRenderer> engineInstance) : UI(), mWorld3D(engineInstance) {
sf::ContextSettings sViewSettings;
sViewSettings.depthBits = 0;
sViewSettings.stencilBits = 0;
@ -98,7 +98,7 @@ void WorldUI::Draw(std::shared_ptr<sf::RenderWindow> context) {
mUIRender.clear(sf::Color::Transparent);
// Draw the 3D view
m3DEngine.Draw(mUIRender);
mWorld3D->Draw(mUIRender);
// Do the final texture render
mUIRender.display();

View File

@ -42,7 +42,7 @@ private:
class WorldUI final : public UI {
public:
WorldUI();
WorldUI(std::shared_ptr<Graphic3DRenderer> engineInstance);
~WorldUI() {}
WorldUI(WorldUI&&) = default;
@ -54,6 +54,6 @@ public:
void Draw(std::shared_ptr<sf::RenderWindow>) override;
private:
Graphic3DRenderer m3DEngine;
std::shared_ptr<Graphic3DRenderer> mWorld3D;
};

View File

@ -1,7 +1,6 @@
#include "Game.hpp"
#include <numeric>
#include <SFML/System.hpp>
#include <SFML/Window/Event.hpp>
@ -13,12 +12,12 @@ using std::make_unique;
#define TARGET_FPS (60)
std::unique_ptr<SysTimer> mPerfsTimer = nullptr;
Game* Game::smInstance = nullptr;
Game::Game(std::shared_ptr<sf::RenderWindow> mainWnd, bool dbgFlag) : mbDbgModeEnabled(dbgFlag), mMainWindow(mainWnd) {
mWorld3D = make_shared<Graphic3DRenderer>();
mCockpitUI = make_unique<CockpitUI>();
mWorldUI = make_unique<WorldUI>();
mWorldUI = make_unique<WorldUI>(mWorld3D);
if (mbDbgModeEnabled) {
mDbgUI = make_unique<DebugUI>();
@ -61,8 +60,8 @@ GAME_STATUS Game::Tick() {
// Ugly way to wait for next frame... Maybe create a separate thread for rendering?
//while(time.GetDeltaTime() < (1000/TARGET_FPS)) {}
// Process to the final rendering
if (mSysTimer.GetDeltaTime() >= (1000/TARGET_FPS)) {
// Process to the final rendering if the window have the focus
if (mSysTimer.GetDeltaTime() >= (1000/TARGET_FPS) && mMainWindow->hasFocus()) {
Render();
mFrameCnt++;
mSysTimer.Reset();

View File

@ -4,6 +4,7 @@
#include "Engine/Graphics/UI.hpp"
#include "Engine/Graphics/DebugUI.hpp"
#include "Engine/Graphics/3DRenderer.hpp"
#include "Engine/Utils/Timers.hpp"
@ -41,9 +42,11 @@ private:
std::unique_ptr<DebugUI> mDbgUI = nullptr;
SysTimer mSysTimer;
std::unique_ptr<SysTimer> mPerfsTimer = nullptr;
std::shared_ptr<sf::RenderWindow> mMainWindow;
std::unique_ptr<CockpitUI> mCockpitUI = nullptr;
std::unique_ptr<WorldUI> mWorldUI = nullptr;
std::shared_ptr<Graphic3DRenderer> mWorld3D;
std::unique_ptr<CockpitUI> mCockpitUI;
std::unique_ptr<WorldUI> mWorldUI;
};