update engine parray

This commit is contained in:
ouczbs 2024-04-28 00:23:55 +08:00
parent 7ee697a1e2
commit 9aa69217e1
10 changed files with 35 additions and 18 deletions

View File

@ -1,13 +1,6 @@
#include "mesh.h" #include "mesh.h"
#include "render/renderapi.h" #include "render/renderapi.h"
namespace engineapi { namespace engineapi {
Mesh::Mesh(string name, uint32_t flags, parray<Vertex>& vertices, vector<uint32_t>& indices)
:Asset(name, flags)
,mVertices(vertices)
,mIndices(indices)
{
BeginLoad();
}
void Mesh::BeginLoad() void Mesh::BeginLoad()
{ {
Asset::BeginLoad(); Asset::BeginLoad();

View File

@ -1,9 +1,10 @@
#pragma once #pragma once
#include "zstd/parray.h" #include "refl/std/parray.h"
#include "asset_render.h" #include "asset_render.h"
#include "../meta/vertex.h" #include "../meta/vertex.h"
namespace engineapi { namespace engineapi {
using zstd::parray; using refl::parray;
using refl::ToParray;
class Texture; class Texture;
class Material; class Material;
class Mesh : public Asset { class Mesh : public Asset {
@ -12,7 +13,15 @@ namespace engineapi {
parray<Vertex> mVertices; parray<Vertex> mVertices;
vector<uint32_t> mIndices; vector<uint32_t> mIndices;
public: public:
Mesh(string name, uint32_t flags, parray<Vertex>& vertices, vector<uint32_t>& indices); template<typename T>
requires std::is_base_of_v<Vertex, T>
Mesh(string name, uint32_t flags,vector<T>& vertices, vector<uint32_t>& indices)
:Asset(name, flags)
, mVertices(vertices)
, mIndices(indices)
{
BeginLoad();
}
void BeginLoad()override; void BeginLoad()override;
public: public:

View File

@ -45,10 +45,7 @@ namespace engineapi {
} }
Mesh* Model::ProcessMesh(const aiMesh* mesh) { Mesh* Model::ProcessMesh(const aiMesh* mesh) {
// data to fill // data to fill
parray<Vertex> vertices(mesh->mNumVertices, sizeof(BoneVertex)); vector<BoneVertex> vertices;
parray<Vertex> vertices2(mesh->mNumVertices, sizeof(BoneVertex));
BoneVertex vertex2;
vertices2.push_back(vertex2);
vector<uint32_t> indices; vector<uint32_t> indices;
// Walk through each of the mesh's vertices // Walk through each of the mesh's vertices
for (unsigned int i = 0; i < mesh->mNumVertices; i++) for (unsigned int i = 0; i < mesh->mNumVertices; i++)

View File

View File

@ -0,0 +1,11 @@
#pragma once
#include "refl/refl.h"
namespace engineapi {
enum class EVkFormat : uint32_t {
None = 0,
R32G32B32 = 106,
};
struct VertexMeta {
EVkFormat vkFormat;
};
}

View File

@ -1,7 +1,7 @@
#pragma once #pragma once
#include "math/vector3.h" #include "math/vector3.h"
#include "math/vector2.h" #include "math/vector2.h"
#include "refl/refl.h" #include "meta.h"
// 顶点最多关联4个骨骼 // 顶点最多关联4个骨骼
#define MAX_NUM_BONES_PER_VERTEX 4 #define MAX_NUM_BONES_PER_VERTEX 4
@ -12,7 +12,7 @@ namespace engineapi {
struct PosVertex_Meta; struct PosVertex_Meta;
struct PosVertex : public Vertex{ struct PosVertex : public Vertex{
using MyMeta = PosVertex_Meta; using MyMeta = PosVertex_Meta;
__cppast(Meta = {}) __cppast(VkMeta = { {} ,VertexMeta{.vkFormat=EVkFormat::R32G32B32} })
Vector3 Position = {}; Vector3 Position = {};
}; };
struct TexVertex_Meta; struct TexVertex_Meta;
@ -46,4 +46,5 @@ namespace engineapi {
void AddBoneData(uint32_t boneID, float weight); void AddBoneData(uint32_t boneID, float weight);
}; };
}; };
#include "meta_vertex_gen.inl" #include "meta_vertex_gen.inl"
#include "vkmeta_vertex_gen.inl"

View File

@ -67,7 +67,7 @@ namespace vulkanapi {
meshBuffer->vertexCount = Vertices.size(); meshBuffer->vertexCount = Vertices.size();
// ----------------------------------------------- Vertex Buffer ----------------------------------------------- // ----------------------------------------------- Vertex Buffer -----------------------------------------------
VkDeviceSize vertexBufferSize = Vertices.data_size(); VkDeviceSize vertexBufferSize = Vertices.capicty();
VmaAllocationCreateInfo vertexVmaStagingInfo = {}; VmaAllocationCreateInfo vertexVmaStagingInfo = {};
VmaAllocation vertexVmaStagingAlloc; VmaAllocation vertexVmaStagingAlloc;
VkBuffer vertexStagingBuffer = Buffer::CreateStageBuffer(vertexVmaStagingInfo, vertexVmaStagingAlloc, vertexBufferSize); VkBuffer vertexStagingBuffer = Buffer::CreateStageBuffer(vertexVmaStagingInfo, vertexVmaStagingAlloc, vertexBufferSize);

View File

@ -45,6 +45,7 @@ namespace vulkanapi {
for (int i = 0; i < Creator.frames;i++) { for (int i = 0; i < Creator.frames;i++) {
mSurfaces.push_back(new Image(Creator.device,"swapchain" + to_string(i), swapchain_images[i], args)); mSurfaces.push_back(new Image(Creator.device,"swapchain" + to_string(i), swapchain_images[i], args));
} }
mFrames = Creator.frames;
mSurfaceSemaphore = Creator.device.CreateSemaphore(); mSurfaceSemaphore = Creator.device.CreateSemaphore();
mRenderSemaphore = Creator.device.CreateSemaphore(); mRenderSemaphore = Creator.device.CreateSemaphore();
} }
@ -52,6 +53,9 @@ namespace vulkanapi {
{ {
ctx.surfaceSemaphore = mSurfaceSemaphore; ctx.surfaceSemaphore = mSurfaceSemaphore;
vkAcquireNextImageKHR(mDevice.Ptr(), mPtr, UINT64_MAX, ctx.surfaceSemaphore, VK_NULL_HANDLE, &ctx.frame); vkAcquireNextImageKHR(mDevice.Ptr(), mPtr, UINT64_MAX, ctx.surfaceSemaphore, VK_NULL_HANDLE, &ctx.frame);
if (ctx.frame >= mFrames) {
ctx.frame = 0;
}
} }
void Swapchain::Present(VulkanContext& ctx) void Swapchain::Present(VulkanContext& ctx)
{ {

View File

@ -11,6 +11,7 @@ namespace vulkanapi {
protected: protected:
VkSwapchainKHR mPtr; VkSwapchainKHR mPtr;
Device& mDevice; Device& mDevice;
int mFrames;
vector<Image*> mSurfaces; vector<Image*> mSurfaces;
VkSemaphore mSurfaceSemaphore; VkSemaphore mSurfaceSemaphore;
VkSemaphore mRenderSemaphore; VkSemaphore mRenderSemaphore;

View File

@ -1,6 +1,7 @@
includes("3rdparty/xmake.lua") includes("3rdparty/xmake.lua")
includes("xmake/xmake.lua") includes("xmake/xmake.lua")
--includes("test/**xmake.lua") --includes("test/**xmake.lua")
set_languages("cxx20")
target("zengine") target("zengine")
set_kind("binary") set_kind("binary")
set_rundir(".") set_rundir(".")