#ifndef OBJ_H
#define OBJ_H

#include "aliases.h"
#include "img.h"
#include "mem_arena.h"
#include "typed_list.h"

#define NULL_MODEL ((Model){0})
#define INVALID_MODEL(m) (m.vertices == NULL || m.triangles == NULL)

typedef struct vertex Vertex;
struct vertex {
  f32 x;
  f32 y;
  f32 z;
};

typedef struct texcoord TexCoord;
struct texcoord {
  f32 u;
  f32 v;
};

typedef struct triangle Triangle;
struct triangle {
  u64 p0;
  u64 p1;
  u64 p2;
  u64 tx0;
  u64 tx1;
  u64 tx2;
};

typedef enum {
  RENDER_TYPE_WIREFRAME,
  RENDER_TYPE_FILLED,
  RENDER_TYPE_SHADED,

  COUNT_RENDER_TYPES,
} RenderType;

typedef enum {
  COLOUR_TYPE_FIXED,
  COLOUR_TYPE_RANDOM,

  COUNT_COLOUR_TYPE,
} ColourType;

MAKE_LIST_TYPE(Vertex);
MAKE_LIST_TYPE(TexCoord);
MAKE_LIST_TYPE(Triangle);

typedef struct model Model;
struct model {
  LIST_TYPE(Vertex) * vertices;
  LIST_TYPE(TexCoord) * texture_coordinates;
  LIST_TYPE(Triangle) * triangles;
  Image *texture;
};

typedef struct render Render;
struct render {
  Image img;
  Depth depth;
};

Model load_obj_file(Arena *arena, const char *filename, const char *texture);
bool init_render(Arena *arena, Render *render, u64 width, u64 height);
void render_model(const Model *model, Render *render, Colour colour,
                  RenderType type, ColourType colour_type);

#endif // OBJ_H
