fix mesh indexing

This commit is contained in:
Asuro
2025-03-27 16:52:34 +01:00
parent aafa5e966e
commit 24a724a021
5 changed files with 32 additions and 13 deletions

View File

@@ -24,7 +24,8 @@ namespace Game
{
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;
auto& rendering = GameRendering::Get();
@@ -32,7 +33,11 @@ namespace Game
bgfx::setTransform(Transform.M.M);
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::setIndexBuffer(currentModel.IndexBuffer);
bgfx::setState(currentMaterial.State);
@@ -79,7 +84,6 @@ namespace Game
needReset |= PuzzleTiles.Setup(storagePtr, needReset);
needReset |= UIQuads.Setup(storagePtr, needReset);
UIQuads.IsEnabled = false;
Tests.IsEnabled = false;
Cubes.IsEnabled = false;
@@ -269,6 +273,8 @@ namespace Game
bgfx::setViewTransform(viewId, player.PlayerCamTransform.M.M, proj);
}
bgfx::touch(viewId);
Cubes.Render(models, materials);
Tests.Render(models, materials);
PuzzleTiles.Render(models, materials);
@@ -277,7 +283,7 @@ namespace Game
void Cube::Setup()
{
EData.MaterialHandle = 0;
EData.MaterialHandle = EMaterial::Default;
EData.ModelH = GameRendering::Get().GetModelHandleFromPath("models/cube.gltf");
}
@@ -300,7 +306,7 @@ namespace Game
void TestEntity::Setup()
{
EData.MaterialHandle = 0;
EData.MaterialHandle = EMaterial::Default;
EData.ModelH = GameRendering::Get().GetModelHandleFromPath("models/zurg.gltf");
EData.Transform.Position = {0.0f, 0.0f, 0.0f};
@@ -313,8 +319,11 @@ namespace Game
{
TileHandles[i] = level.PuzzleTiles.New();
auto& tile = level.PuzzleTiles.Get(TileHandles[i]);
tile.EData.MaterialHandle = 0;
tile.EData.MaterialHandle = EMaterial::Default;
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;
LOG("finished setup!");
@@ -352,8 +361,9 @@ namespace Game
tile.EData.Transform.SetPosition(cardPos);
bx::mtxRotateY(tile.EData.Transform.Rotation.M, card.Rotation * bx::kPi * 0.5f);
Vec3 fw = {0, -1, 0};
quad.EData.Transform.SetPosition(fw);
Vec3 fw = {0, 0, 0};
Vec3 pos = {camTransform.Position.x, camTransform.Position.y, camTransform.Position.z};
quad.EData.Transform.SetPosition(pos);
quad.EData.Transform.Rotation = {};
}
}

View File

@@ -20,7 +20,7 @@ namespace Game
Vec4 TestColor{1.0f, 1.0f, 1.0f, 1.0f};
Vec4 BaseColor{0.0f, 0.0f, 0.0f, 1.0f};
Transform Transform;
uint16_t MaterialHandle = UINT16_MAX;
EMaterial MaterialHandle = EMaterial::UNDEFINED;
Generated::ModelHandle ModelH;
bool Visible = true;

View File

@@ -143,7 +143,7 @@ namespace Game
if (LoadMesh(mod, fullPath.getCPtr(), modelFileIsBinary[i]))
{
mod.Handle.Asset.Idx = CrcPath(fullPath.getCPtr());
mod.Handle.ModelIdx = inst.DebugData.AssetCount;
mod.Handle.ModelIdx = writeI;
if (inst.DebugData.AssetCount < inst.DebugData.MaxAssets)
{
inst.DebugData.AssetHandles[inst.DebugData.AssetCount] = mod.Handle.Asset;

View File

@@ -9,6 +9,7 @@
#include "SDL3/SDL_events.h"
#include "backends/imgui_impl_sdl3.h"
#include "bgfx/defines.h"
#include "bgfx/platform.h"
#include "bx/bx.h"
#include "bx/constants.h"
#include "bx/filepath.h"
@@ -343,7 +344,7 @@ namespace Game
bgfx::Init init;
init.type = bgfx::RendererType::Direct3D12;
#ifdef _DEBUG
// init.debug = true;
init.debug = true;
#endif
init.platformData.nwh = shared.Window.Handle;
init.platformData.ndt = nullptr;
@@ -375,7 +376,7 @@ namespace Game
Textures[0].SamplerHandle = DefaultSampler;
LoadModels(Models, ModelCount);
Materials[0] =
Materials[(uint16_t)EMaterial::Default] =
Material::LoadFromShader("vert", "frag", MainViewID, Textures[0].Handle, Textures[0].SamplerHandle);
imguiCreate();
SetImguiStyle();
@@ -448,7 +449,7 @@ namespace Game
bgfx::ProgramHandle newProgram = bgfx::createProgram(vertexShader, fragmentShader, true);
if (isValid(newProgram))
{
Materials[0].Shader = newProgram;
Materials[(uint16_t)EMaterial::Default].Shader = newProgram;
LastShaderLoadTime = GetInstance().Time.Now;
}
else
@@ -741,6 +742,7 @@ namespace Game
return Models[i].Handle;
}
}
LOG_WARN("Failed to find model for path %s", path);
return {};
}

View File

@@ -88,6 +88,13 @@ namespace Game
ImTextureID PreviewID = 0;
};
enum class EMaterial : uint16_t
{
Default = 0,
UI = 1,
UNDEFINED = UINT16_MAX
};
class GameRendering
{
public: