Skip to content

Commit b26abe8

Browse files
committed
add debug mode
1 parent 9ed79dc commit b26abe8

File tree

1 file changed

+30
-5
lines changed

1 file changed

+30
-5
lines changed

test/system_test/main.cpp

Lines changed: 30 additions & 5 deletions
Original file line numberDiff line numberDiff line change
@@ -16,10 +16,12 @@
1616

1717
#include <renderer.h>
1818

19+
#include <chrono>
1920
#include <cstdint>
2021
#include <iostream>
2122
#include <span>
2223
#include <string>
24+
#include <thread>
2325
#include <vector>
2426

2527
#include "buffer.hpp"
@@ -81,7 +83,7 @@ int main(int argc, char **argv) {
8183
simple_renderer::Camera camera(simple_renderer::Vector3f(0.0f, 0.0f, 1.0f));
8284

8385
// 设置渲染模式(可选:TRADITIONAL、TILE_BASED 或 DEFERRED)
84-
simple_renderer.SetRenderingMode(simple_renderer::RenderingMode::TILE_BASED);
86+
simple_renderer.SetRenderingMode(simple_renderer::RenderingMode::TRADITIONAL);
8587

8688
// 输出当前渲染模式
8789
std::string current_mode_name;
@@ -101,9 +103,11 @@ int main(int argc, char **argv) {
101103
auto display = Display(kWidth, kHeight);
102104
display.loopBegin();
103105

104-
while (!display.loopShouldClose()) {
105-
display.handleEvents(camera);
106-
106+
// 调试模式:固定相机状态,只渲染一帧
107+
bool debug_mode = true;
108+
109+
if (debug_mode) {
110+
// 固定相机参数进行调试
107111
shader.SetUniform("cameraPos", camera.GetPosition());
108112
shader.SetUniform("viewMatrix", camera.GetViewMatrix());
109113
shader.SetUniform("projectionMatrix",
@@ -115,8 +119,29 @@ int main(int argc, char **argv) {
115119
}
116120

117121
buffer.SwapBuffer();
118-
119122
display.fill(buffer.GetDisplayBuffer());
123+
124+
// 调试模式下等待几秒让我们看到结果
125+
std::this_thread::sleep_for(std::chrono::seconds(3));
126+
} else {
127+
// 正常渲染循环
128+
while (!display.loopShouldClose()) {
129+
display.handleEvents(camera);
130+
131+
shader.SetUniform("cameraPos", camera.GetPosition());
132+
shader.SetUniform("viewMatrix", camera.GetViewMatrix());
133+
shader.SetUniform("projectionMatrix",
134+
camera.GetProjectionMatrix(60.0f, static_cast<float>(kWidth) / static_cast<float>(kHeight), 0.1f, 100.0f));
135+
136+
buffer.ClearDrawBuffer(simple_renderer::Color::kBlack);
137+
for (auto &model : models) {
138+
simple_renderer.DrawModel(model, shader, buffer.GetDrawBuffer());
139+
}
140+
141+
buffer.SwapBuffer();
142+
143+
display.fill(buffer.GetDisplayBuffer());
144+
}
120145
}
121146

122147
return 0;

0 commit comments

Comments
 (0)