summaryrefslogtreecommitdiffstats
path: root/tools/platform/model.h
blob: 6289c3739c866ec89224e3a350fcd707369c8fb8 (plain)
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
65
66
67
68
69
70
71
72
73
74
75
76
77
78
79
80
// model.h
#pragma once

#include "platform-api.h"
#include "slang-com-ptr.h"
#include "slang-rhi.h"
#include "vector-math.h"

#include <string>
#include <vector>

namespace platform
{

struct ModelLoader
{
    struct MaterialData
    {
        glm::vec3 diffuseColor;
        glm::vec3 specularColor;
        float specularity;

        Slang::ComPtr<rhi::ITexture> diffuseMap;
    };

    struct Vertex
    {
        glm::vec3 position;
        glm::vec3 normal;
        glm::vec2 uv;
    };

    typedef uint32_t Index;

    struct MeshData
    {
        int firstIndex;
        int indexCount;

        void* material;
    };

    struct ModelData
    {
        Slang::ComPtr<rhi::IBuffer> vertexBuffer;
        Slang::ComPtr<rhi::IBuffer> indexBuffer;
        rhi::PrimitiveTopology primitiveTopology;
        int vertexCount;
        int indexCount;
        int meshCount;
        void* const* meshes;
    };

    struct ICallbacks
    {
        typedef ModelLoader::MaterialData MaterialData;
        typedef ModelLoader::MeshData MeshData;
        typedef ModelLoader::ModelData ModelData;

        virtual void* createMaterial(MaterialData const& data) = 0;
        virtual void* createMesh(MeshData const& data) = 0;
        virtual void* createModel(ModelData const& data) = 0;
    };

    typedef uint32_t LoadFlags;
    enum LoadFlag : LoadFlags
    {
        FlipWinding = 1 << 0,
    };

    ICallbacks* callbacks = nullptr;
    rhi::IDevice* device;
    LoadFlags loadFlags = 0;
    float scale = 1.0f;

    SLANG_PLATFORM_API SlangResult load(char const* inputPath, void** outModel);
};


} // namespace platform