1
1
#pragma once
2
2
3
3
#include < imgui.h>
4
+ #include < vector>
4
5
5
6
#include " RaycastingCameraViewport.hpp"
6
7
@@ -13,18 +14,90 @@ class RenderingOrchestrator
13
14
14
15
void Render (World &world, RaycastingCamera &cam)
15
16
{
17
+ auto & renderTexture = cameraViewport.GetRenderTexture ();
18
+
16
19
if (play)
17
20
{
18
- RasterizeWorldInTexture (cameraViewport.GetRenderTexture (), world, cam);
21
+ InitilizeFrame (world, cam);
22
+
23
+ if (rasterizer.IsRenderIterationRemains ())
24
+ {
25
+ OneRenderItr (true );
26
+ }
27
+
28
+ while (rasterizer.IsRenderIterationRemains ())
29
+ {
30
+ OneRenderItr (false );
31
+ }
19
32
}
20
- else
33
+ else if (stepByStepNewFrame)
21
34
{
22
- RenderStepByStep ();
35
+ stepByStepNewFrame = false ;
36
+ InitilizeFrame (world, cam);
37
+ OneRenderItr (true );
23
38
}
24
39
}
25
- void RenderStepByStep ()
40
+
41
+ void InitilizeFrame (World &world, RaycastingCamera &cam)
26
42
{
27
- // / ...
43
+ auto & renderTexture = cameraViewport.GetRenderTexture ();
44
+ rasterizer.Reset (renderTexture.texture .width , renderTexture.texture .height , world, cam);
45
+
46
+ if (rasterizingItrsTextures.size () > 0 )
47
+ {
48
+ int width = rasterizingItrsTextures[0 ].texture .width ;
49
+ int height = rasterizingItrsTextures[0 ].texture .height ;
50
+
51
+ if (renderTexture.texture .width != width || renderTexture.texture .height != height)
52
+ {
53
+ for (RenderTexture2D& texture : rasterizingItrsTextures)
54
+ {
55
+ UnloadRenderTexture (texture);
56
+ texture = { 0 };
57
+ }
58
+ }
59
+ }
60
+
61
+ if (rasterizingItrsTextures.size () != cam.maxRenderItr )
62
+ {
63
+ rasterizingItrsTextures.resize (cam.maxRenderItr , { 0 });
64
+ }
65
+ }
66
+
67
+ void OneRenderItr (bool firstItr)
68
+ {
69
+ if (rasterizer.IsRenderIterationRemains ())
70
+ {
71
+ auto & renderTexture = cameraViewport.GetRenderTexture ();
72
+
73
+ BeginTextureMode (renderTexture);
74
+
75
+ if (firstItr)
76
+ {
77
+ ClearBackground (MY_BLACK);
78
+ }
79
+
80
+ rasterizer.RenderIteration ();
81
+ EndTextureMode ();
82
+
83
+ auto & ctx = rasterizer.GetContext ();
84
+ assert (rasterizingItrsTextures.size () >= ctx.currentRenderItr );
85
+
86
+ auto & texture = rasterizingItrsTextures.at (ctx.currentRenderItr - 1 );
87
+
88
+ if (texture.id == 0 )
89
+ {
90
+ texture = LoadRenderTexture (renderTexture.texture .width , renderTexture.texture .height );
91
+ }
92
+
93
+ BeginTextureMode (texture);
94
+ DrawTexture (renderTexture.texture , 0 , 0 , WHITE);
95
+ EndTextureMode ();
96
+ }
97
+ else
98
+ {
99
+ stepByStepNewFrame = true ;
100
+ }
28
101
}
29
102
30
103
void DrawGUI ()
@@ -39,23 +112,46 @@ class RenderingOrchestrator
39
112
if (ImGui::Button (" Pause" ))
40
113
{
41
114
play = false ;
115
+ stepByStepNewFrame = true ;
116
+ }
117
+ ImGui::SameLine ();
118
+ if (ImGui::Button (" > Step" ) && !play)
119
+ {
120
+ OneRenderItr (stepByStepNewFrame);
42
121
}
43
122
ImGui::SameLine ();
44
123
if (ImGui::Button (" >> Step" ) && !play)
45
124
{
46
-
125
+
47
126
}
48
127
49
- // ***
50
- // Display renderStack step by step
51
- // ***
128
+ {
129
+ auto & ctx = rasterizer.GetContext ();
130
+
131
+ for (size_t i = 0 ; auto & texture : rasterizingItrsTextures)
132
+ {
133
+ if (texture.id != 0 && i < ctx.currentRenderItr )
134
+ {
135
+ ImGui::Text (" Iteration - %d" , i);
136
+ rlImGuiImageRenderTextureFitWidth (&texture);
137
+ }
138
+
139
+ ++i;
140
+ }
141
+ }
52
142
53
143
ImGui::End ();
54
144
}
55
145
56
146
private:
147
+ RaycastingCameraViewport& cameraViewport;
148
+
149
+ // Step By step
57
150
bool play = true ;
151
+ bool stepByStepNewFrame = false ;
58
152
59
- RaycastingCameraViewport& cameraViewport;
153
+ WorldRasterizer rasterizer;
154
+
155
+ std::vector<RenderTexture> rasterizingItrsTextures;
60
156
};
61
157
0 commit comments