Olympe Engine 2.0
2D Game Engine with ECS Architecture
Loading...
Searching...
No Matches
RenderContext.h
Go to the documentation of this file.
1/*
2 Olympe Engine - 2025
3 Nicolas Chereau
4 nchereau@gmail.com
5
6 This file is part of Olympe Engine.
7 Purpose: Singleton to track the currently active camera during rendering.
8 This allows drawing functions to automatically apply camera transforms
9 without requiring CameraTransform parameters in every function call.
10*/
11
12#pragma once
13
14#include "ECS_Systems.h"
15
16/// Singleton to track the currently active camera during rendering
17/// This allows drawing functions to automatically apply camera transforms
18/// without requiring CameraTransform parameters in every function call
20{
21public:
22 static RenderContext& Get() {
24 return instance;
25 }
26
27 /// Set the active camera for the current rendering pass
28 /// Call this at the start of rendering for each player/viewport
31 hasCameraSet_ = true;
32 }
33
34 /// Get the currently active camera
35 /// Returns identity transform (no transformation) if none is set
37 if (!hasCameraSet_) {
38 // Return default identity transform (screen space rendering)
39 return identityCamera_;
40 }
41 return activeCamera_;
42 }
43
44 /// Check if a camera is currently active
45 bool HasActiveCamera() const {
46 return hasCameraSet_;
47 }
48
49 /// Clear the active camera (e.g., at end of rendering pass)
51 hasCameraSet_ = false;
52 }
53
54private:
56 // Initialize identity camera once (for screen-space rendering)
57 identityCamera_.worldPosition = Vector(0.f, 0.f, 0.f);
58 identityCamera_.screenOffset = Vector(0.f, 0.f, 0.f);
59 identityCamera_.zoom = 1.0f;
61 identityCamera_.viewport = {0.f, 0.f, 1920.f, 1080.f};
63 }
64 ~RenderContext() = default;
65
67 CameraTransform identityCamera_; // Pre-initialized identity transform
69
70 // Prevent copying
71 RenderContext(const RenderContext&) = delete;
73};
ComponentTypeID GetComponentTypeID_Static()
Definition ECS_Entity.h:56
Singleton to track the currently active camera during rendering This allows drawing functions to auto...
void SetActiveCamera(const CameraTransform &cam)
Set the active camera for the current rendering pass Call this at the start of rendering for each pla...
void ClearActiveCamera()
Clear the active camera (e.g., at end of rendering pass)
RenderContext & operator=(const RenderContext &)=delete
~RenderContext()=default
const CameraTransform & GetActiveCamera() const
Get the currently active camera Returns identity transform (no transformation) if none is set.
CameraTransform identityCamera_
RenderContext(const RenderContext &)=delete
bool HasActiveCamera() const
Check if a camera is currently active.
static RenderContext & Get()
CameraTransform activeCamera_
SDL_FRect viewport