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
|
||||
|
||||
@@ -32,6 +32,7 @@ namespace Game
|
||||
bgfx::VertexBufferHandle VertexBuffer;
|
||||
bgfx::IndexBufferHandle IndexBuffer;
|
||||
bgfx::VertexLayout VertLayout;
|
||||
uint32_t AssetHandle = UINT16_MAX;
|
||||
};
|
||||
|
||||
struct Material
|
||||
@@ -54,13 +55,28 @@ namespace Game
|
||||
bgfx::UniformHandle sampler = BGFX_INVALID_HANDLE);
|
||||
};
|
||||
|
||||
enum class UIVisibilityState
|
||||
{
|
||||
None,
|
||||
Game,
|
||||
Debug,
|
||||
};
|
||||
|
||||
class GameRendering
|
||||
{
|
||||
public:
|
||||
static constexpr uint32_t MaxModels = 64;
|
||||
static GameRendering& Get();
|
||||
|
||||
public:
|
||||
UIVisibilityState UIVisible = UIVisibilityState::Game;
|
||||
|
||||
private:
|
||||
bgfx::UniformHandle DefaultSampler;
|
||||
Texture Textures[8];
|
||||
Material Materials[8];
|
||||
Model Models[8];
|
||||
uint32_t ModelCount = 0;
|
||||
Model Models[MaxModels];
|
||||
int32_t LastWidth = 0;
|
||||
int32_t LastHeight = 0;
|
||||
uint32_t ResetFlags = BGFX_RESET_VSYNC;
|
||||
@@ -70,5 +86,6 @@ namespace Game
|
||||
void Setup();
|
||||
void Update();
|
||||
void Shutdown();
|
||||
uint16_t GetModelHandleFromPath(const char* path);
|
||||
};
|
||||
} // namespace Game
|
||||
|
||||
Reference in New Issue
Block a user