mesh loading

This commit is contained in:
Asuro
2025-02-10 01:49:03 +01:00
parent 90bc5753a9
commit 16fcfa8af9
17 changed files with 203 additions and 63 deletions

View File

@@ -3,6 +3,7 @@
#include "../../engine/Shared.h"
#include "../Global.h"
#include "../Instance.h"
#include "../Mesh.h"
#include "bgfx/defines.h"
#include "bx/timer.h"
#include <bx/file.h>
@@ -13,44 +14,6 @@ using namespace std::chrono_literals;
namespace Game
{
struct PosColorVertex
{
float x;
float y;
float z;
uint32_t abgr;
float uv_x;
float uv_y;
};
static PosColorVertex cubeVertices[] =
{
{-1.0f, 1.0f, 1.0f, 0xff000000, 0.0f, 0.0f },
{ 1.0f, 1.0f, 1.0f, 0xff0000ff, 0.0f, 0.0f },
{-1.0f, -1.0f, 1.0f, 0xff00ff00, 0.0f, 0.0f },
{ 1.0f, -1.0f, 1.0f, 0xff00ffff, 0.0f, 0.0f },
{-1.0f, 1.0f, -1.0f, 0xffff0000, 0.0f, 0.0f },
{ 1.0f, 1.0f, -1.0f, 0xffff00ff, 0.0f, 0.0f },
{-1.0f, -1.0f, -1.0f, 0xffffff00, 0.0f, 0.0f },
{ 1.0f, -1.0f, -1.0f, 0xffffffff, 0.0f, 0.0f },
};
static const uint16_t cubeTriList[] =
{
0, 1, 2,
1, 3, 2,
4, 6, 5,
5, 6, 7,
0, 2, 4,
4, 2, 6,
1, 5, 3,
5, 7, 3,
0, 4, 1,
4, 5, 1,
2, 3, 6,
6, 3, 7,
};
namespace
{
static const bgfx::Memory* loadMem(bx::FileReaderI* _reader, const bx::FilePath& _filePath)
@@ -121,7 +84,7 @@ namespace Game
}
}
void GameRendering::Setup()
void GameRendering::Setup()
{
Log("Game rendering setup...");
SharedData& shared = GetShared();
@@ -150,14 +113,8 @@ namespace Game
bgfx::setDebug(BGFX_DEBUG_TEXT);
bgfx::setViewClear(0, BGFX_CLEAR_COLOR | BGFX_CLEAR_DEPTH, 0x303030ff, 1.0f, 0);
Models[0].VertLayout.begin()
.add(bgfx::Attrib::Position, 3, bgfx::AttribType::Float)
.add(bgfx::Attrib::Color0, 4, bgfx::AttribType::Uint8, true)
.add(bgfx::Attrib::TexCoord0, 2, bgfx::AttribType::Float)
.end();
Models[0].VertexBuffer = bgfx::createVertexBuffer(bgfx::makeRef(cubeVertices, sizeof(cubeVertices)), Models[0].VertLayout);
Models[0].IndexBuffer = bgfx::createIndexBuffer(bgfx::makeRef(cubeTriList, sizeof(cubeTriList)));
LoadMesh(Models[0]);
bgfx::ShaderHandle vertexShader = loadShader("vert");
bgfx::ShaderHandle fragmentShader = loadShader("frag");
@@ -196,11 +153,11 @@ namespace Game
if (isValid(newProgram))
{
Materials[0].Shader = newProgram;
}
else
{
Log("Failed to load shader!");
}
}
else
{
Log("Failed to load shader!");
}
}
}

View File

@@ -5,12 +5,14 @@
namespace Game
{
struct VertexData
struct PosColorVertex
{
float X;
float Y;
float Z;
uint32_t VertCol;
float x;
float y;
float z;
uint32_t abgr;
float uv_x;
float uv_y;
};
struct BgfxCallback : public bgfx::CallbackI