aboutsummaryrefslogtreecommitdiff
path: root/src/renderer/RenderGroup.hpp
blob: 49042206cd2fa137f305bdea4eab27a55eca422c (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
81
82
83
#pragma once

#include <basic/defs.hpp>
#include <basic/math.hpp>
#include <vector>
#include <imgui.h>

enum REntityType : int32_t {
    REntityType_Rectangle,
    REntityType_Bitmap,
};

struct REntity_Rectangle {
    REntityType type;
    V3F32 pos;
    V2F32 dim;
    V3F32 color;
};

struct REntity_Bitmap {
    REntityType type;
    V3F32 pos;
    int32_t width;
    int32_t height;
    void *data;
};

union REntity {
    REntityType type;
    REntity_Rectangle rect;
    REntity_Bitmap bitmap;
};

struct RSortEntry {
    RSortEntry(float z, size_t entity_index);
    float z;
    size_t entity_index;
};


class RenderGroup {
public:
    RenderGroup();
    void Clear(V3F32 color);
    void Reset();

    void SetCameraSize(float width, float height);
    V2F32 ViewPosToScreenPos(V2F32 view_pos);
    V2F32 ViewSizeToScreenSize(V2F32 view_size);
    ImVec2 ViewPosToScreenPosImGui(V2F32 view_pos);
    ImVec2 ViewSizeToScreenSizeImGui(V2F32 view_size);
    float GetScale();


public:
    void PushRectangle(V3F32 pos, V2F32 dim, V3F32 color);
    void PushBitmap(V3F32 pos, int width, int height, void *bitmap);


private:
    void Sort();


public:
    int32_t m_ScreenWidth;
    int32_t m_ScreenHeight;


private:
    friend class GlRenderer;


    float m_CameraWidth;
    float m_CameraHeight;


    V3F32 m_ClearColor;

    std::vector<REntity> m_REntities;
    std::vector<RSortEntry> m_RSortEntries;
};