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 "render/renderapi.h"
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()
{
Asset::BeginLoad();

View File

@ -1,9 +1,10 @@
#pragma once
#include "zstd/parray.h"
#include "refl/std/parray.h"
#include "asset_render.h"
#include "../meta/vertex.h"
namespace engineapi {
using zstd::parray;
using refl::parray;
using refl::ToParray;
class Texture;
class Material;
class Mesh : public Asset {
@ -12,7 +13,15 @@ namespace engineapi {
parray<Vertex> mVertices;
vector<uint32_t> mIndices;
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;
public:

View File

@ -45,10 +45,7 @@ namespace engineapi {
}
Mesh* Model::ProcessMesh(const aiMesh* mesh) {
// data to fill
parray<Vertex> vertices(mesh->mNumVertices, sizeof(BoneVertex));
parray<Vertex> vertices2(mesh->mNumVertices, sizeof(BoneVertex));
BoneVertex vertex2;
vertices2.push_back(vertex2);
vector<BoneVertex> vertices;
vector<uint32_t> indices;
// Walk through each of the mesh's vertices
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
#include "math/vector3.h"
#include "math/vector2.h"
#include "refl/refl.h"
#include "meta.h"
// 顶点最多关联4个骨骼
#define MAX_NUM_BONES_PER_VERTEX 4
@ -12,7 +12,7 @@ namespace engineapi {
struct PosVertex_Meta;
struct PosVertex : public Vertex{
using MyMeta = PosVertex_Meta;
__cppast(Meta = {})
__cppast(VkMeta = { {} ,VertexMeta{.vkFormat=EVkFormat::R32G32B32} })
Vector3 Position = {};
};
struct TexVertex_Meta;
@ -47,3 +47,4 @@ namespace engineapi {
};
};
#include "meta_vertex_gen.inl"
#include "vkmeta_vertex_gen.inl"

View File

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

View File

@ -45,6 +45,7 @@ namespace vulkanapi {
for (int i = 0; i < Creator.frames;i++) {
mSurfaces.push_back(new Image(Creator.device,"swapchain" + to_string(i), swapchain_images[i], args));
}
mFrames = Creator.frames;
mSurfaceSemaphore = Creator.device.CreateSemaphore();
mRenderSemaphore = Creator.device.CreateSemaphore();
}
@ -52,6 +53,9 @@ namespace vulkanapi {
{
ctx.surfaceSemaphore = mSurfaceSemaphore;
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)
{

View File

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

View File

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