~vladh/peony

peony/src/models.hpp -rw-r--r-- 4.3 KiB
7fc9922bVlad-Stefan Harbuz changes shaders namespace into class a month ago
                                                                                
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
81
82
83
84
85
86
87
88
89
90
91
92
93
94
95
96
97
98
99
100
101
102
103
104
105
106
107
108
109
110
111
112
113
114
115
116
117
118
119
120
121
122
123
124
125
126
127
128
129
130
131
132
133
134
135
136
137
138
139
140
141
142
143
144
145
146
147
148
149
150
151
152
153
154
155
156
157
158
159
160
161
162
163
164
165
166
167
168
/*
  Peony Game Engine
  Copyright (C) 2020 Vlad-Stefan Harbuz <vlad@vladh.net>
  All rights reserved.
*/

#pragma once

#include "types.hpp"
#include "stackarray.hpp"
#include "materials.hpp"
#include "entities.hpp"
#include "spatial.hpp"
#include "anim.hpp"
#include "behavior.hpp"
#include "physics.hpp"
#include "queue.hpp"
#include "tasks.hpp"
#include "pack.hpp"
#include "lights.hpp"

namespace models {
  // NOTE: Should be at least peony_parser::MAX_N_ARRAY_VALUES
  constexpr uint32 const MAX_N_COMMON_ARRAY_VALUES = 8;

  enum class RenderMode {regular, depth};

  enum class RenderPass : uint32 {
    none = 0,
    shadowcaster = (1 << 0),
    deferred = (1 << 1),
    forward_depth = (1 << 2),
    forward_nodepth = (1 << 3),
    forward_skybox = (1 << 4),
    lighting = (1 << 5),
    postprocessing = (1 << 6),
    preblur = (1 << 7),
    blur1 = (1 << 8),
    blur2 = (1 << 9),
    renderdebug = (1 << 10),
  };

  struct Vertex {
    v3 position;
    v3 normal;
    v2 tex_coords;
    uint32 bone_idxs[MAX_N_BONES_PER_VERTEX];
    real32 bone_weights[MAX_N_BONES_PER_VERTEX];
  };

  struct Mesh {
    MemoryPool temp_memory_pool;
    m4 transform;
    char material_name[MAX_COMMON_NAME_LENGTH];
    Pack indices_pack;
    uint32 vao;
    uint32 vbo;
    uint32 ebo;
    GLenum mode;
    Vertex *vertices;
    uint32 *indices;
    uint32 n_vertices;
    uint32 n_indices;
  };

  enum class ModelLoaderState {
    empty,
    initialized,
    mesh_data_being_loaded,
    mesh_data_loaded,
    vertex_buffers_set_up,
    complete
  };

  struct ModelLoader {
    // These from from the file
    char model_path[MAX_PATH];
    char material_names[MAX_COMMON_NAME_LENGTH][MAX_N_COMMON_ARRAY_VALUES];
    uint32 n_material_names;

    // These are created later
    Mesh meshes[MAX_N_MESHES];
    uint32 n_meshes;
    AnimationComponent animation_component;
    ModelLoaderState state;
  };

  enum class EntityLoaderState {
    empty,
    initialized,
    complete
  };

  struct EntityLoader {
    char name[MAX_DEBUG_NAME_LENGTH];
    char model_path[MAX_PATH];
    EntityHandle entity_handle;
    RenderPass render_pass;
    EntityLoaderState state;
    SpatialComponent spatial_component;
    LightComponent light_component;
    BehaviorComponent behavior_component;
    PhysicsComponent physics_component;
  };

  struct EntityLoaderSet {
    Array<EntityLoader> loaders;
  };

  struct DrawableComponent {
    EntityHandle entity_handle;
    Mesh mesh;
    RenderPass target_render_pass = RenderPass::none;
  };

  struct DrawableComponentSet {
    Array<DrawableComponent> components;
    uint32 last_drawn_shader_program;
  };

#include "models_data.hpp"

  const char* render_pass_to_string(RenderPass render_pass);
  RenderPass render_pass_from_string(const char* str);
  bool32 prepare_model_loader_and_check_if_done(
    ModelLoader *model_loader,
    PersistentPbo *persistent_pbo,
    TextureNamePool *texture_name_pool,
    Queue<Task> *task_queue,
    BoneMatrixPool *bone_matrix_pool
  );
  bool32 prepare_entity_loader_and_check_if_done(
    EntityLoader *entity_loader,
    EntitySet *entity_set,
    ModelLoader *model_loader,
    DrawableComponentSet *drawable_component_set,
    SpatialComponentSet *spatial_component_set,
    LightComponentSet *light_component_set,
    BehaviorComponentSet *behavior_component_set,
    AnimationComponentSet *animation_component_set,
    PhysicsComponentSet *physics_component_set
  );
  bool32 is_model_loader_valid(ModelLoader *model_loader);
  bool32 is_entity_loader_valid(EntityLoader *entity_loader);
  void add_material_to_model_loader(
    ModelLoader *model_loader,
    char const *material_name
  );
  ModelLoader* init_model_loader(
    ModelLoader *model_loader,
    const char *model_path
  );
  EntityLoader* init_entity_loader(
    EntityLoader *entity_loader,
    const char *name,
    const char *model_path,
    RenderPass render_pass,
    EntityHandle entity_handle
  );
  bool32 is_drawable_component_valid(DrawableComponent *drawable_component);
  void destroy_drawable_component(DrawableComponent *drawable_component);
}

using models::Vertex, models::Mesh, models::ModelLoaderState,
  models::ModelLoader, models::EntityLoaderState, models::EntityLoader,
  models::EntityLoaderSet,
  models::DrawableComponent, models::DrawableComponentSet,
  models::RenderMode, models::RenderPass;