yum-mirror/slang

Making it easier to work with shaders

git clone https://git.yummers.dev/yum-mirror/slang

Gangzheng TongConvert gfx unit tests and examples to use slang-rhi (#7577)43d0c2100

master
1.6 KiB80 linesraw
1// model.h
2#pragma once
3
4#include "platform-api.h"
5#include "slang-com-ptr.h"
6#include "slang-rhi.h"
7#include "vector-math.h"
8
9#include <string>
10#include <vector>
11
12namespace platform
13{
14
15struct ModelLoader
16{
17    struct MaterialData
18    {
19        glm::vec3 diffuseColor;
20        glm::vec3 specularColor;
21        float specularity;
22
23        Slang::ComPtr<rhi::ITexture> diffuseMap;
24    };
25
26    struct Vertex
27    {
28        glm::vec3 position;
29        glm::vec3 normal;
30        glm::vec2 uv;
31    };
32
33    typedef uint32_t Index;
34
35    struct MeshData
36    {
37        int firstIndex;
38        int indexCount;
39
40        void* material;
41    };
42
43    struct ModelData
44    {
45        Slang::ComPtr<rhi::IBuffer> vertexBuffer;
46        Slang::ComPtr<rhi::IBuffer> indexBuffer;
47        rhi::PrimitiveTopology primitiveTopology;
48        int vertexCount;
49        int indexCount;
50        int meshCount;
51        void* const* meshes;
52    };
53
54    struct ICallbacks
55    {
56        typedef ModelLoader::MaterialData MaterialData;
57        typedef ModelLoader::MeshData MeshData;
58        typedef ModelLoader::ModelData ModelData;
59
60        virtual void* createMaterial(MaterialData const& data) = 0;
61        virtual void* createMesh(MeshData const& data) = 0;
62        virtual void* createModel(ModelData const& data) = 0;
63    };
64
65    typedef uint32_t LoadFlags;
66    enum LoadFlag : LoadFlags
67    {
68        FlipWinding = 1 << 0,
69    };
70
71    ICallbacks* callbacks = nullptr;
72    rhi::IDevice* device;
73    LoadFlags loadFlags = 0;
74    float scale = 1.0f;
75
76    SLANG_PLATFORM_API SlangResult load(char const* inputPath, void** outModel);
77};
78
79
80} // namespace platform