meshes!
This commit is contained in:
@@ -10,7 +10,6 @@
|
||||
#include "bgfx/defines.h"
|
||||
#include "bx/bx.h"
|
||||
#include "bx/filepath.h"
|
||||
#include "bx/math.h"
|
||||
#include "bx/timer.h"
|
||||
#include <bgfx/bgfx.h>
|
||||
#include <bimg/bimg.h>
|
||||
@@ -191,11 +190,21 @@ namespace Game
|
||||
|
||||
return handle;
|
||||
}
|
||||
|
||||
GameRendering* Instance = nullptr;
|
||||
} // namespace
|
||||
|
||||
GameRendering& GameRendering::Get()
|
||||
{
|
||||
assert(Instance != nullptr);
|
||||
return *Instance;
|
||||
}
|
||||
|
||||
void GameRendering::Setup()
|
||||
{
|
||||
Log("--- RENDERING STARTUP ---");
|
||||
if (Instance != nullptr) Log("Warning, old rendering wasn't destroyed!");
|
||||
Instance = this;
|
||||
SharedData& shared = GetShared();
|
||||
|
||||
bgfx::Init init;
|
||||
@@ -229,8 +238,7 @@ namespace Game
|
||||
Textures[0].Handle =
|
||||
loadTexture(bx::FilePath{"models/body.dds"}, BGFX_TEXTURE_NONE | BGFX_SAMPLER_NONE, 0, nullptr, nullptr);
|
||||
Textures[0].SamplerHandle = DefaultSampler;
|
||||
LoadMesh(Models[0], "models/cube.gltf");
|
||||
LoadMesh(Models[1], "models/zurg.gltf");
|
||||
LoadModels(Models, ModelCount);
|
||||
|
||||
Materials[0] =
|
||||
Material::LoadFromShader("vert", "frag", MainViewID, Textures[0].Handle, Textures[0].SamplerHandle);
|
||||
@@ -312,7 +320,24 @@ namespace Game
|
||||
imguiBeginFrame(20);
|
||||
ImGui_ImplSDL3_NewFrame();
|
||||
ImGui::DockSpaceOverViewport(0, 0, ImGuiDockNodeFlags_PassthruCentralNode);
|
||||
ImGui::ShowDemoWindow();
|
||||
|
||||
if (UIVisible == UIVisibilityState::Debug)
|
||||
{
|
||||
if (ImGui::Begin("Rendering"))
|
||||
{
|
||||
if (ImGui::Button("Reload Meshes"))
|
||||
{
|
||||
LoadModels(Models, ModelCount);
|
||||
}
|
||||
if (ImGui::Button("Reload Level"))
|
||||
{
|
||||
auto& lvl = GetInstance().GameLevel;
|
||||
lvl = {};
|
||||
lvl.Setup(shared.Game);
|
||||
}
|
||||
}
|
||||
ImGui::End();
|
||||
}
|
||||
|
||||
GetInstance().GameLevel.Update();
|
||||
GetInstance().GameLevel.Render(MainViewID, Models, Materials);
|
||||
@@ -348,6 +373,7 @@ namespace Game
|
||||
ImGui_ImplSDL3_Shutdown();
|
||||
imguiDestroy();
|
||||
bgfx::shutdown();
|
||||
Instance = nullptr;
|
||||
}
|
||||
|
||||
Material Material::LoadFromShader(
|
||||
@@ -368,4 +394,18 @@ namespace Game
|
||||
mat.ViewID = view;
|
||||
return mat;
|
||||
}
|
||||
|
||||
uint16_t GameRendering::GetModelHandleFromPath(const char* path)
|
||||
{
|
||||
uint32_t AssetHandle = CrcPath(path);
|
||||
for (int32_t i = 0; i < ModelCount; ++i)
|
||||
{
|
||||
if (Models[i].AssetHandle == AssetHandle)
|
||||
{
|
||||
return i;
|
||||
}
|
||||
}
|
||||
return 0;
|
||||
}
|
||||
|
||||
} // namespace Game
|
||||
|
||||
Reference in New Issue
Block a user