aboutsummaryrefslogtreecommitdiff
path: root/src/renderer/Renderer.hpp
diff options
context:
space:
mode:
Diffstat (limited to 'src/renderer/Renderer.hpp')
-rw-r--r--src/renderer/Renderer.hpp110
1 files changed, 90 insertions, 20 deletions
diff --git a/src/renderer/Renderer.hpp b/src/renderer/Renderer.hpp
index 24d4b71..4fdf524 100644
--- a/src/renderer/Renderer.hpp
+++ b/src/renderer/Renderer.hpp
@@ -1,41 +1,111 @@
#pragma once
#include <basic/math.hpp>
-#include <renderer/RenderGroup.hpp>
+
#include <SDL3/SDL.h>
#include <SDL3/SDL_video.h>
+#include <imgui.h>
+
+#include <vector>
+#include <memory>
+
+
+class RSoftwareBackend;
+class Renderer;
+
+extern Renderer g_renderer;
+
+
+enum REntityType : int32_t {
+ REntityType_Rectangle,
+ REntityType_MonoBitmap,
+};
-struct RCanvas {
- uint32_t rshift;
- uint32_t gshift;
- uint32_t bshift;
- uint32_t ashift;
+struct REntity_Rectangle {
+ REntityType type;
+ float x0;
+ float y0;
+ float x1;
+ float y1;
+ float z;
+ Color color;
+};
+
+struct REntity_MonoBitmap {
+ REntityType type;
+ float x;
+ float y;
int32_t w;
int32_t h;
- uint32_t *pixels;
+ float z;
+ void *data;
+};
+
+union REntity {
+ REntityType type;
+ REntity_Rectangle rect;
+ REntity_MonoBitmap bitmap;
+};
+
+struct RSortEntry {
+ float z;
+ size_t entity_index;
};
class Renderer {
public:
- Renderer(SDL_Window *window);
+ void Init(SDL_Window* window);
+
+
+ /* core functions */
+
+ void Draw();
+ void Reset();
+
+ void Clear(Color color);
+ void PushRectangle(RectF32 rect, float z, Color color);
+ void PushMonoBitmap(V3F32 pos, int w, int h, void* bitmap);
+
+
+ /* helper functions */
+
+ void SetScreenSize(int32_t w, int32_t h);
+ void SetCameraSize(float w, float h);
+
+
+ int32_t WorldXToScreenX(float x);
+ int32_t WorldYToScreenY(float y);
+
+ int32_t WorldWidthToScreenWidth(float w);
+ int32_t WorldHeightToScreenHeight(float h);
+
+
+ /* temporary helper functions (from old RGroup api) */
+ float GetScale();
+ V2F32 ViewPosToScreenPos(V2F32 view_pos);
+ V2F32 ViewSizeToScreenSize(V2F32 view_size);
+ ImVec2 ViewPosToScreenPosImGui(V2F32 view_pos);
+ ImVec2 ViewSizeToScreenSizeImGui(V2F32 view_size);
+
+
+
+ // Todo: make this private
+public:
+ int32_t m_screen_w;
+ int32_t m_screen_h;
- bool Init();
- void ResizeCanvas(int32_t w, int32_t h);
- void Draw(RenderGroup &render_group);
+ float m_camera_w;
+ float m_camera_h;
+ Color m_clear_color {};
+ std::vector<REntity> m_render_entities;
+ std::vector<RSortEntry> m_sort_entries;
-private:
- void DrawRectangle(RenderGroup& rgroup, REntity_Rectangle& rect);
- void DrawMonoBitmap(REntity_Bitmap& bitmap, Color color);
- int32_t WorldXToScreenX(RenderGroup& rgroup, float x);
- int32_t WorldYToScreenY(RenderGroup& rgroup, float y);
+ std::unique_ptr<RSoftwareBackend> m_backend;
-private:
- SDL_Window *m_Window;
- uint32_t m_GlTexId;
- RCanvas m_Canvas;
+ friend class RSoftwareBackend;
};