Plasma Engine  2.0
Loading...
Searching...
No Matches
RasterizerView.h
1#pragma once
2
3#include <Foundation/Containers/Deque.h>
4#include <Foundation/Math/Transform.h>
5#include <Foundation/Threading/Mutex.h>
6#include <Foundation/Types/ArrayPtr.h>
7#include <RendererCore/RendererCoreDLL.h>
8
9class Rasterizer;
11class plColorLinearUB;
12class plCamera;
13class plSimdBBox;
14
15class PL_RENDERERCORE_DLL plRasterizerView final
16{
17 PL_DISALLOW_COPY_AND_ASSIGN(plRasterizerView);
18
19public:
22
24 void SetResolution(plUInt32 uiWidth, plUInt32 uiHeight, float fAspectRatio);
25
26 plUInt32 GetResolutionX() const { return m_uiResolutionX; }
27 plUInt32 GetResolutionY() const { return m_uiResolutionY; }
28
30 void BeginScene();
31
33 void EndScene();
34
38 void ReadBackFrame(plArrayPtr<plColorLinearUB> targetBuffer) const;
39
41 void SetCamera(const plCamera* pCamera)
42 {
43 m_pCamera = pCamera;
44 }
45
47 void AddObject(const plRasterizerObject* pObject, const plTransform& transform)
48 {
49 auto& inst = m_Instances.ExpandAndGetRef();
50 inst.m_pObject = pObject;
51 inst.m_Transform = transform;
52 }
53
57 bool IsVisible(const plSimdBBox& aabb) const;
58
61 {
62 return m_bAnyOccludersRasterized;
63 }
64
65private:
66 void SortObjectsFrontToBack();
67 void RasterizeObjects(plUInt32 uiMaxObjects);
68 void UpdateViewProjectionMatrix();
69 void ApplyModelViewProjectionMatrix(const plTransform& modelTransform);
70
71 bool m_bAnyOccludersRasterized = false;
72 const plCamera* m_pCamera = nullptr;
73 plUInt32 m_uiResolutionX = 0;
74 plUInt32 m_uiResolutionY = 0;
75 float m_fAspectRation = 1.0f;
76 plUniquePtr<Rasterizer> m_pRasterizer;
77
78 struct Instance
79 {
80 plTransform m_Transform;
81 const plRasterizerObject* m_pObject;
82 };
83
84 plDeque<Instance> m_Instances;
85 plMat4 m_mViewProjection;
86};
87
89{
90public:
91 plRasterizerView* GetRasterizerView(plUInt32 uiWidth, plUInt32 uiHeight, float fAspectRatio);
92 void ReturnRasterizerView(plRasterizerView* pView);
93
94private:
95 struct PoolEntry
96 {
97 bool m_bInUse = false;
98 plRasterizerView m_RasterizerView;
99 };
100
101 plMutex m_Mutex;
102 plDeque<PoolEntry> m_Entries;
103};
This class encapsulates an array and it's size. It is recommended to use this class instead of plain ...
Definition ArrayPtr.h:37
A camera class that stores the orientation and some basic camera settings.
Definition Camera.h:41
A 8bit per channel unsigned normalized (values interpreted as 0-1) color storage format that represen...
Definition Color8UNorm.h:61
Definition Deque.h:270
Provides a simple mechanism for mutual exclusion to prevent multiple threads from accessing a shared ...
Definition Mutex.h:13
Definition RasterizerObject.h:13
Definition RasterizerView.h:16
void AddObject(const plRasterizerObject *pObject, const plTransform &transform)
Adds an object as an occluder to the scene. Once all occluders have been rasterized,...
Definition RasterizerView.h:47
void SetCamera(const plCamera *pCamera)
Sets the camera from which to extract the rendering position, direction and field-of-view.
Definition RasterizerView.h:41
bool HasRasterizedAnyOccluders() const
Wether any occluder was actually added and also rasterized. If not, no need to do any visibility chec...
Definition RasterizerView.h:60
Definition RasterizerView.h:89
Definition SimdBBox.h:6
A Unique ptr manages an object and destroys that object when it goes out of scope....
Definition UniquePtr.h:10