summaryrefslogtreecommitdiff
path: root/src/render/immdraw.h
blob: 6b456d5467ff218782f94cd949ffa1243889a0fc (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
/**
 * @brief Immediate-mode drawing APIs
 */

#pragma once
#include "defines.h"
#include "maths_types.h"
#include "ral_impl.h"
#include "ral_types.h"
#include "render_types.h"

typedef struct Immdraw_Storage {
  Mesh plane;
  Mesh cube;
  Mesh sphere;
  GPU_Pipeline* colour_pipeline; /** @brief Pipeline for drawing geometry that has vertex colours */
} Immdraw_Storage;

typedef struct ImmediateUniforms {
  Mat4 model;
  Vec4 colour;
} ImmediateUniforms;

// --- Public API

PUB void Immdraw_Init(Immdraw_Storage* storage);
PUB void Immdraw_Shutdown(Immdraw_Storage* storage);

// These functions cause a pipeline switch and so aren't optimised for performance
PUB void Immdraw_Plane(Transform tf, Vec4 colour, bool wireframe);
PUB void Immdraw_Cuboid(Transform tf, Vec4 colour, bool wireframe);
PUB void Immdraw_Sphere(Transform tf, Vec4 colour, bool wireframe);

PUB void Immdraw_TransformGizmo(Transform tf, f32 size);

// --- Internal

static ShaderDataLayout ImmediateUniforms_GetLayout(void* data) {
  ImmediateUniforms* d = (ImmediateUniforms*)data;
  bool has_data = data != NULL;

  ShaderBinding b1 = { .label = "ImmUniforms",
                       .kind = BINDING_BYTES,
                       // .vis = VISIBILITY_VERTEX,
                       .data.bytes.size = sizeof(ImmediateUniforms) };

  if (has_data) {
    b1.data.bytes.data = d;
  }

  return (ShaderDataLayout){ .bindings = { b1 }, .binding_count = 1 };
}