diff --git a/engine/assets/shader/gen/simple.frag.spv b/engine/assets/shader/gen/simple.frag.spv new file mode 100644 index 0000000..d3a34da Binary files /dev/null and b/engine/assets/shader/gen/simple.frag.spv differ diff --git a/engine/assets/shader/gen/simple.vert.spv b/engine/assets/shader/gen/simple.vert.spv new file mode 100644 index 0000000..b3268c2 Binary files /dev/null and b/engine/assets/shader/gen/simple.vert.spv differ diff --git a/engine/src/engine/render/asset/mesh.h b/engine/src/engine/render/asset/mesh.h index 97e7e3d..7df3f9f 100644 --- a/engine/src/engine/render/asset/mesh.h +++ b/engine/src/engine/render/asset/mesh.h @@ -4,7 +4,6 @@ #include "../meta/vertex.h" namespace engineapi { using refl::parray; - using refl::ToParray; class Texture; class Material; class Mesh : public Asset { diff --git a/engine/src/engine/render/asset/model.cpp b/engine/src/engine/render/asset/model.cpp index 7a34b4c..48c8c62 100644 --- a/engine/src/engine/render/asset/model.cpp +++ b/engine/src/engine/render/asset/model.cpp @@ -104,8 +104,7 @@ namespace engineapi { indices.push_back(face.mIndices[j]); } } - Mesh* model = new Mesh(mesh->mName.C_Str(), mFlags, vertices, indices); - return model; + return new Mesh(mesh->mName.C_Str(), mFlags, vertices, indices); } void Model::Use() { diff --git a/engine/src/engine/render/meta/meta.h b/engine/src/engine/render/meta/meta.h index 17ee36a..b1e7ccf 100644 --- a/engine/src/engine/render/meta/meta.h +++ b/engine/src/engine/render/meta/meta.h @@ -1,11 +1,7 @@ #pragma once #include "refl/refl.h" namespace engineapi { - enum class EVkFormat : uint32_t { - None = 0, - R32G32B32 = 106, - }; struct VertexMeta { - EVkFormat vkFormat; + uint32_t format; }; } \ No newline at end of file diff --git a/engine/src/engine/render/meta/vertex.cpp b/engine/src/engine/render/meta/vertex.cpp index 08034f7..f933553 100644 --- a/engine/src/engine/render/meta/vertex.cpp +++ b/engine/src/engine/render/meta/vertex.cpp @@ -1,5 +1,4 @@ #include "vertex.h" - namespace engineapi { void BoneVertex::AddBoneData(uint32_t boneID, float weight) { diff --git a/engine/src/engine/render/meta/vertex.h b/engine/src/engine/render/meta/vertex.h index 74992b2..41058cf 100644 --- a/engine/src/engine/render/meta/vertex.h +++ b/engine/src/engine/render/meta/vertex.h @@ -9,42 +9,40 @@ namespace engineapi { struct Vertex { }; - struct PosVertex_Meta; - struct PosVertex : public Vertex{ - using MyMeta = PosVertex_Meta; - __cppast(VkMeta = { {} ,VertexMeta{.vkFormat=EVkFormat::R32G32B32} }) + + struct PosVertex { + using MyMetas = class PosVertex_MultyMeta; + UPROPERTY_vk({}, VertexMeta{ VK_FORMAT_R32G32B32_SFLOAT }) Vector3 Position = {}; }; - struct TexVertex_Meta; struct TexVertex : public Vertex { - using MyMeta = TexVertex_Meta; - __cppast(Meta = {}) + using MyMetas = class TexVertex_MulytMeta; + UPROPERTY_vk({}, VertexMeta{ VK_FORMAT_R32G32B32_SFLOAT }) Vector3 Position = {}; - __cppast(Meta = {}) + UPROPERTY_vk() Vector3 Normal = {}; - __cppast(Meta = {}) + UPROPERTY_vk() Vector2 TexCoords = {}; }; - struct BoneVertex_Meta; struct BoneVertex : public Vertex { - using MyMeta = BoneVertex_Meta; - __cppast(Meta = {}) + using MyMetas = class BoneVertex_MulytMeta; + UPROPERTY_vk({}, VertexMeta{ VK_FORMAT_R32G32B32_SFLOAT }) Vector3 Position = {}; - __cppast(Meta = {}) + UPROPERTY_vk() Vector2 TexCoords = {}; - __cppast(Meta = {}) + UPROPERTY_vk() Vector3 Normal = {}; - __cppast(Meta = {}) + UPROPERTY_vk() Vector3 Tangent = {}; // 骨骼蒙皮数据 - __cppast(Meta = {}) + UPROPERTY_vk() float Weights[MAX_NUM_BONES_PER_VERTEX] = {}; - __cppast(Meta = {}) + UPROPERTY_vk() uint32_t BoneIDs[MAX_NUM_BONES_PER_VERTEX] = {}; void AddBoneData(uint32_t boneID, float weight); }; }; -#include "meta_vertex_gen.inl" -#include "vkmeta_vertex_gen.inl" \ No newline at end of file + +#include "vertex_gen.inl" \ No newline at end of file diff --git a/engine/src/engine/vulkanapi/vulkanapi.cpp b/engine/src/engine/vulkanapi/vulkanapi.cpp index b0c61a6..1e3381c 100644 --- a/engine/src/engine/vulkanapi/vulkanapi.cpp +++ b/engine/src/engine/vulkanapi/vulkanapi.cpp @@ -12,6 +12,7 @@ #include "wrapper/descriptorpool.h" #include "window.h" #include "zlog.h" +#include "vkmeta_vertex_gen.inl" namespace vulkanapi { RenderVulkanAPI::RenderVulkanAPI() :backend("vulkan") diff --git a/engine/xmake/glsl/glsl_compiler.lua b/engine/xmake/glsl/glsl_compiler.lua new file mode 100644 index 0000000..3cc6efc --- /dev/null +++ b/engine/xmake/glsl/glsl_compiler.lua @@ -0,0 +1,62 @@ +import("core.project.depend") +function cmd_compile(genfile, sourcefile, template, macro, define) + import("find_sdk") + local meta = find_sdk.find_my_program("refl") + template = template or path.join(meta.sdkdir, "template") + if not macro then --优先使用库定义 + macro = path.join(os.projectdir(), "engine/3rdparty/zlib/include/refl/macro.h") + if not os.exists(macro) then + macro = path.join(os.curdir(), "macro.h") + end + end + argv = {"build", sourcefile, "-o", genfile, "-t", template, "-m", macro} + if define then + table.insert(argv, "-d") + table.insert(argv, define) + end + print("cmd_meta_compile", genfile) + os.runv(meta.program, argv) + return argv +end + +function _listen_gen_vs_file(target, batch) + -- genfile, sourcefile = batch[1], batch[2] + -- local dependfile = target:dependfile(genfile) + -- depend.on_changed( + -- function() + -- cmd_compile(batch[1], batch[2], template, macro, define) + -- end, + -- {dependfile = dependfile, files = sourcefile} + -- ) +end +function compile(target) + local glsl_batch = target:data("glsl.batch") + if not glsl_batch then + return + end + for _, batch in ipairs(glsl_batch.vs) do + local dir = path.directory(batch) + local vs = path.filename(batch) + local vert = string.gsub(vs, ".vs.glsl$", ".vert.spv") + _listen_gen_vs_file(target, dir, vert) + end +end +function main(target) + local ps = {} + local psfiles = target:extraconf("rules", "glsl.env", "ps") + for _, file in ipairs(psfiles) do + local p = path.join(target:scriptdir(), file) + for __, filepath in ipairs(os.files(p)) do + table.insert(ps, filepath) + end + end + local vsfiles = target:extraconf("rules", "glsl.env", "vs") + for _, file in ipairs(vsfiles) do + local p = path.join(target:scriptdir(), file) + for __, filepath in ipairs(os.files(p)) do + table.insert(vs, filepath) + end + end + local glslfiles = {ps = ps, vs = vs} + target:data_set("glsl.batch", glslfiles) +end diff --git a/engine/xmake/glsl/xmake.lua b/engine/xmake/glsl/xmake.lua index f2d9f80..dcb3535 100644 --- a/engine/xmake/glsl/xmake.lua +++ b/engine/xmake/glsl/xmake.lua @@ -1,4 +1,10 @@ rule("glsl.env") + after_load(function (target) + import("glsl_compiler")(target) + end) + on_config(function (target) + import("glsl_compiler").compile(target) + end) -- before load before_build(function (target) os.cd("$(projectdir)/engine/assets/shader")