fix mesh indexing
This commit is contained in:
@@ -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;
|
||||||
|
|
||||||
|
|||||||
@@ -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
|
||||||
@@ -741,6 +742,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