Added a simple visibility toggle command, fixed some bugs on linux

This commit is contained in:
Conál 2024-02-20 15:57:38 -05:00
parent b2de337c43
commit dc8e5a5483
5 changed files with 24 additions and 42 deletions

View File

@ -6,7 +6,7 @@ set(CMAKE_CXX_STANDARD_REQUIRED ON)
if(WIN32)
set(CMAKE_CXX_FLAGS "-D_DEBUG")
else()
set(CMAKE_CXX_FLAGS "-D_DEBUG -Wall")
set(CMAKE_CXX_FLAGS "-D_DEBUG -Wall -O3")
endif()
project(Pleascach)

View File

@ -70,15 +70,17 @@ struct Renderer {
Camera cam{ .pos = glm::vec3(0.0, 5.0, 0.0), };
float fps;
bool capture_mouse = false;
bool flycam = false;
/* time speed */
float time = 0.0;
float speed = 1.0;
bool paused = false;
bool visibility_testing = false;
size_t n_indices;
bool visibility_testing;
float near_plane = 2.0f;
float far_plane = 10000.0f;

View File

@ -21,18 +21,12 @@ static csys::ItemLog& operator<<(csys::ItemLog& log, ImVector<float>& vec) {
return log << vec[vec.size() - 1] << " }";
}
static void vec_setter(ImVector<float>& v, std::vector<float> in) {
/*static void vec_setter(ImVector<float>& v, std::vector<float> in) {
v.reserve(in.size());
std::memcpy(v.Data, in.data(), sizeof(float) * in.size());
}
}*/
UI::UI(Renderer* ren) :
info {
.flycam = ren->flycam, .visibility_testing = ren->visibility_testing,
.time = ren->time, .cam = ren->cam, .tess_factor = ren->tess_factor,
.tess_edge_size = ren->tess_edge_size, .n_indices = ren->n_indices,
.near_plane = ren->near_plane, .far_plane = ren->far_plane, .paused = ren->paused
}, dev(ren->dev) {
UI::UI(Renderer* ren) : ren(ren), dev(ren->dev) {
IMGUI_CHECKVERSION();
ImGui::CreateContext();
@ -107,8 +101,13 @@ UI::UI(Renderer* ren) :
console = std::make_unique<ImGuiConsole>("developer console");
console->System().RegisterCommand("pause", "Pauses or unpauses the engine", [this]() {
this->info.paused = !this->info.paused;
console->System().Log(csys::ItemType::INFO) << "Paused: " << (this->info.paused? "True" : "False") << csys::endl;
this->ren->paused = !this->ren->paused;
console->System().Log(csys::ItemType::INFO) << "Paused: " << (this->ren->paused? "True" : "False") << csys::endl;
});
console->System().RegisterCommand("toggle-visibility-testing", "Toggles visibility testings (using clusters and frustum culling)", [this]() {
this->ren->visibility_testing = !this->ren->visibility_testing;
console->System().Log(csys::ItemType::INFO) << "Visibility Testing: " << (this->ren->visibility_testing? "Enabled" : "Disabled") << csys::endl;
});
console->System().Log(csys::ItemType::INFO) << "Welcome to Pleascach!" << csys::endl;
@ -122,15 +121,14 @@ void UI::newFrame() {
ImGui::SetNextWindowBgAlpha(0.5f);
ImGui::Begin("Rendering Info", nullptr);
ImGui::Text("# of Indices: %zu", info.n_indices);
ImGui::Text("FPS: %f", info.fps);
ImGui::Text("Time: %f", info.time);
ImGui::Checkbox("Fly Camera", &info.flycam);
ImGui::Checkbox("Visibility Testing", &info.visibility_testing);
ImGui::SliderFloat("Near Plane", &info.near_plane, 0.00, 0.20);
ImGui::SliderFloat("Far Plane", &info.far_plane, 1000.0, 10000.0);
ImGui::SliderFloat("Tessellation Factor", &info.tess_factor, 0.1, 10.0);
ImGui::SliderFloat("Edge Size", &info.tess_edge_size, 0.0, 40.0);
ImGui::Text("# of Indices: %zu", ren->n_indices);
ImGui::Text("FPS: %f", ren->fps);
ImGui::Text("Time: %f", ren->time);
ImGui::Checkbox("Fly Camera", &ren->flycam);
ImGui::SliderFloat("Near Plane", &ren->near_plane, 0.00, 0.20);
ImGui::SliderFloat("Far Plane", &ren->far_plane, 1000.0, 10000.0);
ImGui::SliderFloat("Tessellation Factor", &ren->tess_factor, 0.1, 10.0);
ImGui::SliderFloat("Edge Size", &ren->tess_edge_size, 0.0, 40.0);
console->Draw();

View File

@ -13,23 +13,7 @@ struct Renderer;
struct Camera;
struct UI {
struct UI_Info {
float fps = 0.0;
bool& flycam;
bool& visibility_testing;
float& time;
/* camera stuff */
Camera& cam;
float& tess_factor;
float& tess_edge_size;
const size_t& n_indices;
float& near_plane;
float& far_plane;
bool& paused;
} info;
Renderer* ren;
vk::Device dev;
vk::DescriptorPool desc_pool;

View File

@ -69,8 +69,6 @@ int main(int argc, char* argv[]) {
ren.speed *= 10.0;
} else if (event.key.key == GLFW_KEY_Y && event.key.state == GLFW_PRESS) {
ren.speed /= 10.0;
} else if (event.key.key == GLFW_KEY_V && event.key.state == GLFW_PRESS) {
ren.visibility_testing = !ren.visibility_testing;
}
break;
}
@ -79,7 +77,7 @@ int main(int argc, char* argv[]) {
ren.draw();
ren.present();
const auto t = frame_timer.read();
ren.ui->info.fps = 1000.0f / t;
ren.fps = 1000.0f / t;
while (frame_timer.read() < 16.60)
;