Compare commits
2 Commits
aafa5e966e
...
2ff08d7258
| Author | SHA1 | Date | |
|---|---|---|---|
|
|
2ff08d7258 | ||
|
|
24a724a021 |
@@ -24,7 +24,8 @@ namespace Game
|
|||||||
{
|
{
|
||||||
void EntityRenderData::Render(const Model* models, const Material* materials)
|
void EntityRenderData::Render(const Model* models, const Material* materials)
|
||||||
{
|
{
|
||||||
if (!Generated::IsValid(ModelH) || MaterialHandle == UINT16_MAX) return;
|
if (models == nullptr || materials == nullptr) return;
|
||||||
|
if (!Generated::IsValid(ModelH) || MaterialHandle == EMaterial::UNDEFINED) return;
|
||||||
if (!Visible) return;
|
if (!Visible) return;
|
||||||
auto& rendering = GameRendering::Get();
|
auto& rendering = GameRendering::Get();
|
||||||
|
|
||||||
@@ -32,7 +33,11 @@ namespace Game
|
|||||||
bgfx::setTransform(Transform.M.M);
|
bgfx::setTransform(Transform.M.M);
|
||||||
|
|
||||||
const Model& currentModel = models[ModelH.ModelIdx];
|
const Model& currentModel = models[ModelH.ModelIdx];
|
||||||
const Material& currentMaterial = materials[MaterialHandle];
|
const Material& currentMaterial = materials[(uint16_t)MaterialHandle];
|
||||||
|
|
||||||
|
if (!isValid(currentModel.IndexBuffer) || !isValid(currentModel.VertexBuffer)) return;
|
||||||
|
if (!isValid(currentMaterial.Shader)) return;
|
||||||
|
|
||||||
bgfx::setVertexBuffer(0, currentModel.VertexBuffer);
|
bgfx::setVertexBuffer(0, currentModel.VertexBuffer);
|
||||||
bgfx::setIndexBuffer(currentModel.IndexBuffer);
|
bgfx::setIndexBuffer(currentModel.IndexBuffer);
|
||||||
bgfx::setState(currentMaterial.State);
|
bgfx::setState(currentMaterial.State);
|
||||||
@@ -79,7 +84,6 @@ namespace Game
|
|||||||
needReset |= PuzzleTiles.Setup(storagePtr, needReset);
|
needReset |= PuzzleTiles.Setup(storagePtr, needReset);
|
||||||
needReset |= UIQuads.Setup(storagePtr, needReset);
|
needReset |= UIQuads.Setup(storagePtr, needReset);
|
||||||
|
|
||||||
UIQuads.IsEnabled = false;
|
|
||||||
Tests.IsEnabled = false;
|
Tests.IsEnabled = false;
|
||||||
Cubes.IsEnabled = false;
|
Cubes.IsEnabled = false;
|
||||||
|
|
||||||
@@ -269,6 +273,8 @@ namespace Game
|
|||||||
bgfx::setViewTransform(viewId, player.PlayerCamTransform.M.M, proj);
|
bgfx::setViewTransform(viewId, player.PlayerCamTransform.M.M, proj);
|
||||||
}
|
}
|
||||||
|
|
||||||
|
bgfx::touch(viewId);
|
||||||
|
|
||||||
Cubes.Render(models, materials);
|
Cubes.Render(models, materials);
|
||||||
Tests.Render(models, materials);
|
Tests.Render(models, materials);
|
||||||
PuzzleTiles.Render(models, materials);
|
PuzzleTiles.Render(models, materials);
|
||||||
@@ -277,7 +283,7 @@ namespace Game
|
|||||||
|
|
||||||
void Cube::Setup()
|
void Cube::Setup()
|
||||||
{
|
{
|
||||||
EData.MaterialHandle = 0;
|
EData.MaterialHandle = EMaterial::Default;
|
||||||
EData.ModelH = GameRendering::Get().GetModelHandleFromPath("models/cube.gltf");
|
EData.ModelH = GameRendering::Get().GetModelHandleFromPath("models/cube.gltf");
|
||||||
}
|
}
|
||||||
|
|
||||||
@@ -300,7 +306,7 @@ namespace Game
|
|||||||
|
|
||||||
void TestEntity::Setup()
|
void TestEntity::Setup()
|
||||||
{
|
{
|
||||||
EData.MaterialHandle = 0;
|
EData.MaterialHandle = EMaterial::Default;
|
||||||
EData.ModelH = GameRendering::Get().GetModelHandleFromPath("models/zurg.gltf");
|
EData.ModelH = GameRendering::Get().GetModelHandleFromPath("models/zurg.gltf");
|
||||||
|
|
||||||
EData.Transform.Position = {0.0f, 0.0f, 0.0f};
|
EData.Transform.Position = {0.0f, 0.0f, 0.0f};
|
||||||
@@ -313,8 +319,11 @@ namespace Game
|
|||||||
{
|
{
|
||||||
TileHandles[i] = level.PuzzleTiles.New();
|
TileHandles[i] = level.PuzzleTiles.New();
|
||||||
auto& tile = level.PuzzleTiles.Get(TileHandles[i]);
|
auto& tile = level.PuzzleTiles.Get(TileHandles[i]);
|
||||||
tile.EData.MaterialHandle = 0;
|
tile.EData.MaterialHandle = EMaterial::Default;
|
||||||
UIPlacedCards[i] = level.UIQuads.New();
|
UIPlacedCards[i] = level.UIQuads.New();
|
||||||
|
auto& quad = level.UIQuads.Get(UIPlacedCards[i]);
|
||||||
|
quad.EData.ModelH = GameRendering::Get().GetModelHandleFromPath("models/plane.glb");
|
||||||
|
quad.EData.MaterialHandle = EMaterial::Default;
|
||||||
}
|
}
|
||||||
IsSetup = true;
|
IsSetup = true;
|
||||||
LOG("finished setup!");
|
LOG("finished setup!");
|
||||||
@@ -352,8 +361,9 @@ namespace Game
|
|||||||
tile.EData.Transform.SetPosition(cardPos);
|
tile.EData.Transform.SetPosition(cardPos);
|
||||||
bx::mtxRotateY(tile.EData.Transform.Rotation.M, card.Rotation * bx::kPi * 0.5f);
|
bx::mtxRotateY(tile.EData.Transform.Rotation.M, card.Rotation * bx::kPi * 0.5f);
|
||||||
|
|
||||||
Vec3 fw = {0, -1, 0};
|
Vec3 fw = {0, 0, 0};
|
||||||
quad.EData.Transform.SetPosition(fw);
|
Vec3 pos = {camTransform.Position.x, camTransform.Position.y, camTransform.Position.z};
|
||||||
|
quad.EData.Transform.SetPosition(pos);
|
||||||
quad.EData.Transform.Rotation = {};
|
quad.EData.Transform.Rotation = {};
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|||||||
@@ -20,7 +20,7 @@ namespace Game
|
|||||||
Vec4 TestColor{1.0f, 1.0f, 1.0f, 1.0f};
|
Vec4 TestColor{1.0f, 1.0f, 1.0f, 1.0f};
|
||||||
Vec4 BaseColor{0.0f, 0.0f, 0.0f, 1.0f};
|
Vec4 BaseColor{0.0f, 0.0f, 0.0f, 1.0f};
|
||||||
Transform Transform;
|
Transform Transform;
|
||||||
uint16_t MaterialHandle = UINT16_MAX;
|
EMaterial MaterialHandle = EMaterial::UNDEFINED;
|
||||||
Generated::ModelHandle ModelH;
|
Generated::ModelHandle ModelH;
|
||||||
bool Visible = true;
|
bool Visible = true;
|
||||||
|
|
||||||
|
|||||||
@@ -1,10 +1,13 @@
|
|||||||
#include "Log.h"
|
#include "Log.h"
|
||||||
#include "bx/handlealloc.h"
|
#include "bx/handlealloc.h"
|
||||||
#include "bx/hash.h"
|
#include "bx/hash.h"
|
||||||
|
#include "bx/timer.h"
|
||||||
#include <bx/string.h>
|
#include <bx/string.h>
|
||||||
#define WIN32_LEAN_AND_MEAN
|
#define WIN32_LEAN_AND_MEAN
|
||||||
#include "Windows.h"
|
#include "Windows.h"
|
||||||
|
|
||||||
|
#include "Instance.h"
|
||||||
|
|
||||||
#define ESC "\x1B["
|
#define ESC "\x1B["
|
||||||
#define YELLOW ESC "33m"
|
#define YELLOW ESC "33m"
|
||||||
#define RED ESC "31m"
|
#define RED ESC "31m"
|
||||||
@@ -12,9 +15,11 @@
|
|||||||
|
|
||||||
namespace
|
namespace
|
||||||
{
|
{
|
||||||
char LineBuffer[1024]{0};
|
char LineBuffer[LogInternal::MaxLineSize]{0};
|
||||||
char OutBuffer[1024]{0};
|
char OutBuffer[LogInternal::MaxLineSize]{0};
|
||||||
bx::HandleHashMapT<1024> OnceMap;
|
bx::HandleHashMapT<1024> OnceMap;
|
||||||
|
LogHistory History;
|
||||||
|
|
||||||
constexpr char LogFormat[]{"%s\n"};
|
constexpr char LogFormat[]{"%s\n"};
|
||||||
constexpr char WarnFormat[]{YELLOW "%s" END "\n"};
|
constexpr char WarnFormat[]{YELLOW "%s" END "\n"};
|
||||||
constexpr char ErrorFormat[]{RED "%s" END "\n"};
|
constexpr char ErrorFormat[]{RED "%s" END "\n"};
|
||||||
@@ -33,6 +38,11 @@ void Log(ELogType logType, const char* file, uint32_t line, const char* format,
|
|||||||
bx::vsnprintf(OutBuffer, sizeof(OutBuffer), LineBuffer, args);
|
bx::vsnprintf(OutBuffer, sizeof(OutBuffer), LineBuffer, args);
|
||||||
va_end(args);
|
va_end(args);
|
||||||
OutputDebugStringA(OutBuffer);
|
OutputDebugStringA(OutBuffer);
|
||||||
|
|
||||||
|
bx::strCopy(&History.LogBuffer[History.WriteIdx * LogInternal::MaxLineSize], LogInternal::MaxLineSize, OutBuffer);
|
||||||
|
History.WriteTime[History.WriteIdx] = bx::getHPCounter();
|
||||||
|
++History.WriteIdx;
|
||||||
|
if (History.WriteIdx >= LogInternal::LogHistorySize) History.WriteIdx = 0;
|
||||||
}
|
}
|
||||||
|
|
||||||
bool WasLogged(ELogType logType, const char* file, uint32_t line, const char* format)
|
bool WasLogged(ELogType logType, const char* file, uint32_t line, const char* format)
|
||||||
@@ -48,3 +58,8 @@ bool WasLogged(ELogType logType, const char* file, uint32_t line, const char* fo
|
|||||||
OnceMap.insert(hash, {});
|
OnceMap.insert(hash, {});
|
||||||
return false;
|
return false;
|
||||||
}
|
}
|
||||||
|
|
||||||
|
LogHistory& GetLogHistory()
|
||||||
|
{
|
||||||
|
return History;
|
||||||
|
}
|
||||||
|
|||||||
@@ -27,5 +27,19 @@ enum class ELogType
|
|||||||
Error,
|
Error,
|
||||||
};
|
};
|
||||||
|
|
||||||
|
namespace LogInternal
|
||||||
|
{
|
||||||
|
constexpr int32_t MaxLineSize = 1024;
|
||||||
|
constexpr int32_t LogHistorySize = 1024;
|
||||||
|
} // namespace LogInternal
|
||||||
|
|
||||||
|
struct LogHistory
|
||||||
|
{
|
||||||
|
char LogBuffer[LogInternal::MaxLineSize * LogInternal::LogHistorySize]{0};
|
||||||
|
int32_t WriteIdx = 0;
|
||||||
|
int64_t WriteTime[LogInternal::LogHistorySize]{0};
|
||||||
|
};
|
||||||
|
|
||||||
void Log(ELogType logType, const char* file, uint32_t line, const char* format, ...);
|
void Log(ELogType logType, const char* file, uint32_t line, const char* format, ...);
|
||||||
bool WasLogged(ELogType logType, const char* file, uint32_t line, const char* format);
|
bool WasLogged(ELogType logType, const char* file, uint32_t line, const char* format);
|
||||||
|
LogHistory& GetLogHistory();
|
||||||
|
|||||||
@@ -143,7 +143,7 @@ namespace Game
|
|||||||
if (LoadMesh(mod, fullPath.getCPtr(), modelFileIsBinary[i]))
|
if (LoadMesh(mod, fullPath.getCPtr(), modelFileIsBinary[i]))
|
||||||
{
|
{
|
||||||
mod.Handle.Asset.Idx = CrcPath(fullPath.getCPtr());
|
mod.Handle.Asset.Idx = CrcPath(fullPath.getCPtr());
|
||||||
mod.Handle.ModelIdx = inst.DebugData.AssetCount;
|
mod.Handle.ModelIdx = writeI;
|
||||||
if (inst.DebugData.AssetCount < inst.DebugData.MaxAssets)
|
if (inst.DebugData.AssetCount < inst.DebugData.MaxAssets)
|
||||||
{
|
{
|
||||||
inst.DebugData.AssetHandles[inst.DebugData.AssetCount] = mod.Handle.Asset;
|
inst.DebugData.AssetHandles[inst.DebugData.AssetCount] = mod.Handle.Asset;
|
||||||
|
|||||||
@@ -9,6 +9,7 @@
|
|||||||
#include "SDL3/SDL_events.h"
|
#include "SDL3/SDL_events.h"
|
||||||
#include "backends/imgui_impl_sdl3.h"
|
#include "backends/imgui_impl_sdl3.h"
|
||||||
#include "bgfx/defines.h"
|
#include "bgfx/defines.h"
|
||||||
|
#include "bgfx/platform.h"
|
||||||
#include "bx/bx.h"
|
#include "bx/bx.h"
|
||||||
#include "bx/constants.h"
|
#include "bx/constants.h"
|
||||||
#include "bx/filepath.h"
|
#include "bx/filepath.h"
|
||||||
@@ -343,7 +344,7 @@ namespace Game
|
|||||||
bgfx::Init init;
|
bgfx::Init init;
|
||||||
init.type = bgfx::RendererType::Direct3D12;
|
init.type = bgfx::RendererType::Direct3D12;
|
||||||
#ifdef _DEBUG
|
#ifdef _DEBUG
|
||||||
// init.debug = true;
|
init.debug = true;
|
||||||
#endif
|
#endif
|
||||||
init.platformData.nwh = shared.Window.Handle;
|
init.platformData.nwh = shared.Window.Handle;
|
||||||
init.platformData.ndt = nullptr;
|
init.platformData.ndt = nullptr;
|
||||||
@@ -375,7 +376,7 @@ namespace Game
|
|||||||
Textures[0].SamplerHandle = DefaultSampler;
|
Textures[0].SamplerHandle = DefaultSampler;
|
||||||
LoadModels(Models, ModelCount);
|
LoadModels(Models, ModelCount);
|
||||||
|
|
||||||
Materials[0] =
|
Materials[(uint16_t)EMaterial::Default] =
|
||||||
Material::LoadFromShader("vert", "frag", MainViewID, Textures[0].Handle, Textures[0].SamplerHandle);
|
Material::LoadFromShader("vert", "frag", MainViewID, Textures[0].Handle, Textures[0].SamplerHandle);
|
||||||
imguiCreate();
|
imguiCreate();
|
||||||
SetImguiStyle();
|
SetImguiStyle();
|
||||||
@@ -448,7 +449,7 @@ namespace Game
|
|||||||
bgfx::ProgramHandle newProgram = bgfx::createProgram(vertexShader, fragmentShader, true);
|
bgfx::ProgramHandle newProgram = bgfx::createProgram(vertexShader, fragmentShader, true);
|
||||||
if (isValid(newProgram))
|
if (isValid(newProgram))
|
||||||
{
|
{
|
||||||
Materials[0].Shader = newProgram;
|
Materials[(uint16_t)EMaterial::Default].Shader = newProgram;
|
||||||
LastShaderLoadTime = GetInstance().Time.Now;
|
LastShaderLoadTime = GetInstance().Time.Now;
|
||||||
}
|
}
|
||||||
else
|
else
|
||||||
@@ -473,6 +474,22 @@ namespace Game
|
|||||||
debug.DebugCardRotation++;
|
debug.DebugCardRotation++;
|
||||||
if (debug.DebugCardRotation >= 4) debug.DebugCardRotation = 0;
|
if (debug.DebugCardRotation >= 4) debug.DebugCardRotation = 0;
|
||||||
}
|
}
|
||||||
|
if (ImGui::Begin("Log"))
|
||||||
|
{
|
||||||
|
for (int32_t i = 0; i < bx::min(100, LogInternal::LogHistorySize); ++i)
|
||||||
|
{
|
||||||
|
int32_t idx = GetLogHistory().WriteIdx - i - 1;
|
||||||
|
if (idx < 0) idx += LogInternal::LogHistorySize;
|
||||||
|
const char* line = &GetLogHistory().LogBuffer[idx * LogInternal::MaxLineSize];
|
||||||
|
if (line[0] != 0)
|
||||||
|
{
|
||||||
|
int64_t timeOffset = GetLogHistory().WriteTime[idx] - GetInstance().Time.StartTime;
|
||||||
|
double writeTime = (double)timeOffset / bx::getHPFrequency();
|
||||||
|
ImGui::Text("%.04f: %s", writeTime, line);
|
||||||
|
}
|
||||||
|
}
|
||||||
|
}
|
||||||
|
ImGui::End();
|
||||||
if (ImGui::Begin("Rendering"))
|
if (ImGui::Begin("Rendering"))
|
||||||
{
|
{
|
||||||
if (LastShaderLoadTime >= 0.0f)
|
if (LastShaderLoadTime >= 0.0f)
|
||||||
@@ -741,6 +758,7 @@ namespace Game
|
|||||||
return Models[i].Handle;
|
return Models[i].Handle;
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
LOG_WARN("Failed to find model for path %s", path);
|
||||||
return {};
|
return {};
|
||||||
}
|
}
|
||||||
|
|
||||||
|
|||||||
@@ -88,6 +88,13 @@ namespace Game
|
|||||||
ImTextureID PreviewID = 0;
|
ImTextureID PreviewID = 0;
|
||||||
};
|
};
|
||||||
|
|
||||||
|
enum class EMaterial : uint16_t
|
||||||
|
{
|
||||||
|
Default = 0,
|
||||||
|
UI = 1,
|
||||||
|
UNDEFINED = UINT16_MAX
|
||||||
|
};
|
||||||
|
|
||||||
class GameRendering
|
class GameRendering
|
||||||
{
|
{
|
||||||
public:
|
public:
|
||||||
|
|||||||
Reference in New Issue
Block a user