summaryrefslogtreecommitdiff
path: root/src/new_render/skybox.h
blob: ec06658aecb8f0940d68e9172f6e02e7a38d3a6b (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
/**
 * @brief
 */

#pragma once
#include "backend_opengl.h"
#include "defines.h"
#include "ral_types.h"

typedef struct Skybox {
    BufferHandle vertex_buffer;
    TextureHandle texture;
    GPU_Pipeline* pipeline; // "shader"
} Skybox;

PUB Skybox Skybox_Create(const char** face_paths, int n); // should always pass n = 6 for now

PUB void Skybox_Draw(Skybox* skybox);

typedef struct SkyboxUniforms {
    Vec3 in_pos;
    TextureHandle cubemap;
} SkyboxUniforms;

static ShaderDataLayout Skybox_GetLayout(void* data) {
    SkyboxUniforms* d = (SkyboxUniforms*)data; // cold cast
    bool has_data = data != NULL;

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

    ShaderBinding b2 = {
        .label = "cubemap",
        .vis = VISIBILITY_FRAGMENT,
        .kind = BINDING_SAMPLER,
    };

    if (has_data) {
        b1.data.bytes.data = &d->in_pos;
        b2.data.texture.handle = d->cubemap;
    }
    return (ShaderDataLayout) {
        .bindings = { b1, b2},
        .binding_count = 2
    };
}