105 lines
2.9 KiB
C++
105 lines
2.9 KiB
C++
#pragma once
|
|
|
|
#include <algorithm>
|
|
#include <raylib.h>
|
|
#include <vector>
|
|
#include <functional>
|
|
|
|
class RenderContext {
|
|
public:
|
|
struct RenderLayer {
|
|
enum Type {
|
|
SKYBOX = 0,
|
|
TERRAIN = 100,
|
|
ENTITIES = 200,
|
|
TRANSPARENT = 300,
|
|
UI = 400
|
|
};
|
|
};
|
|
|
|
struct RenderCommand {
|
|
int layer;
|
|
std::function<void()> command;
|
|
|
|
bool operator<(const RenderCommand& other) const {
|
|
return layer < other.layer;
|
|
}
|
|
};
|
|
|
|
private:
|
|
std::vector<RenderCommand> commands;
|
|
Camera3D* activeCamera;
|
|
bool is3DMode;
|
|
|
|
public:
|
|
RenderContext() : activeCamera(nullptr), is3DMode(false) {}
|
|
|
|
void begin3D(Camera3D& camera) {
|
|
activeCamera = &camera;
|
|
is3DMode = true;
|
|
BeginMode3D(camera);
|
|
}
|
|
|
|
void end3D() {
|
|
executeCommands();
|
|
EndMode3D();
|
|
is3DMode = false;
|
|
activeCamera = nullptr;
|
|
}
|
|
|
|
void submitModel(const Model& model, const Vector3& position,
|
|
float scale = 1.0f, Color tint = WHITE,
|
|
int layer = RenderLayer::ENTITIES) {
|
|
commands.push_back({layer, [model, position, scale, tint]() {
|
|
DrawModel(model, position, scale, tint);
|
|
}});
|
|
}
|
|
|
|
void submitModelEx(const Model& model, const Vector3& position,
|
|
const Vector3& rotation, const Vector3& scale,
|
|
Color tint = WHITE, int layer = RenderLayer::ENTITIES) {
|
|
commands.push_back({layer, [model, position, rotation, scale, tint]() {
|
|
DrawModelEx(model, position, rotation, 0.0f, scale, tint);
|
|
}});
|
|
}
|
|
|
|
void submitCube(const Vector3& position, const Vector3& size,
|
|
Color color, int layer = RenderLayer::ENTITIES) {
|
|
commands.push_back({layer, [position, size, color]() {
|
|
DrawCube(position, size.x, size.y, size.z, color);
|
|
}});
|
|
}
|
|
|
|
void submitCubeWires(const Vector3& position, const Vector3& size,
|
|
Color color, int layer = RenderLayer::ENTITIES) {
|
|
commands.push_back({layer, [position, size, color]() {
|
|
DrawCubeWires(position, size.x, size.y, size.z, color);
|
|
}});
|
|
}
|
|
|
|
void submitLine3D(const Vector3& start, const Vector3& end,
|
|
Color color, int layer = RenderLayer::ENTITIES) {
|
|
commands.push_back({layer, [start, end, color]() {
|
|
DrawLine3D(start, end, color);
|
|
}});
|
|
}
|
|
|
|
void submitCustom(std::function<void()> renderFunc, int layer) {
|
|
commands.push_back({layer, renderFunc});
|
|
}
|
|
|
|
Camera3D* getActiveCamera() { return activeCamera; }
|
|
bool isIn3DMode() const { return is3DMode; }
|
|
|
|
private:
|
|
void executeCommands() {
|
|
std::sort(commands.begin(), commands.end());
|
|
|
|
for (const auto& cmd : commands) {
|
|
cmd.command();
|
|
}
|
|
|
|
commands.clear();
|
|
}
|
|
};
|