mirror of https://github.com/auygun/kaliber.git
Compare commits
2 Commits
8b47314e72
...
75b5046684
Author | SHA1 | Date |
---|---|---|
Attila Uygun | 75b5046684 | |
Attila Uygun | 669ed5e098 |
|
@ -45,7 +45,7 @@ Engine::Engine(Platform* platform)
|
|||
platform_->SetObserver(this);
|
||||
}
|
||||
|
||||
Engine::~Engine() {
|
||||
Engine::~Engine() noexcept {
|
||||
LOG(0) << "Shutting down engine.";
|
||||
|
||||
thread_pool_.CancelTasks();
|
||||
|
@ -157,12 +157,13 @@ void Engine::Draw(float frame_frac) {
|
|||
}
|
||||
|
||||
if (stats_visible_) {
|
||||
ImVec2 center = ImGui::GetMainViewport()->GetCenter();
|
||||
ImGui::SetNextWindowPos(center, ImGuiCond_Appearing, ImVec2(0.5f, 0.5f));
|
||||
ImGuiWindowFlags window_flags =
|
||||
ImGuiWindowFlags_NoResize | ImGuiWindowFlags_NoTitleBar |
|
||||
ImGuiWindowFlags_NoScrollbar | ImGuiWindowFlags_NoCollapse |
|
||||
ImGuiWindowFlags_NoNav | ImGuiWindowFlags_AlwaysAutoResize;
|
||||
ImGui::Begin("Stats", nullptr, window_flags);
|
||||
ImGui::PushItemWidth(ImGui::GetFontSize() * -12);
|
||||
ImGui::Text("%s", renderer_->GetDebugName());
|
||||
ImGui::Text("%d fps", fps_);
|
||||
ImGui::End();
|
||||
|
|
|
@ -6,6 +6,7 @@
|
|||
#include "engine/asset/shader_source.h"
|
||||
#include "engine/engine.h"
|
||||
#include "engine/input_event.h"
|
||||
#include "engine/platform/asset_file.h"
|
||||
#include "engine/renderer/renderer.h"
|
||||
#include "engine/renderer/shader.h"
|
||||
#include "engine/renderer/texture.h"
|
||||
|
@ -26,6 +27,28 @@ ImguiBackend::~ImguiBackend() = default;
|
|||
void ImguiBackend::Initialize() {
|
||||
IMGUI_CHECKVERSION();
|
||||
ImGui::CreateContext();
|
||||
ImGui::GetIO().IniFilename = nullptr;
|
||||
|
||||
size_t buffer_size = 0;
|
||||
auto buffer = AssetFile::ReadWholeFile("engine/RobotoMono-Regular.ttf",
|
||||
Engine::Get().GetRootPath().c_str(),
|
||||
&buffer_size);
|
||||
if (buffer) {
|
||||
ImFontConfig font_cfg = ImFontConfig();
|
||||
font_cfg.FontDataOwnedByAtlas = false;
|
||||
float size_pixels = Engine::Get().IsMobile() ? 64 : 32;
|
||||
ImGui::GetIO().Fonts->AddFontFromMemoryTTF(buffer.get(), (int)buffer_size,
|
||||
size_pixels, &font_cfg);
|
||||
ImGui::GetIO().Fonts->Build();
|
||||
} else {
|
||||
LOG(0) << "Failed to read font file.";
|
||||
}
|
||||
|
||||
// Arbitrary scale-up for mobile devices.
|
||||
// TODO: Put some effort into DPI awareness.
|
||||
if (Engine::Get().IsMobile())
|
||||
ImGui::GetStyle().ScaleAllSizes(2.0f);
|
||||
|
||||
Engine::Get().SetImageSource(
|
||||
"imgui_atlas",
|
||||
[]() -> std::unique_ptr<Image> {
|
||||
|
@ -33,7 +56,7 @@ void ImguiBackend::Initialize() {
|
|||
unsigned char* pixels;
|
||||
int width, height;
|
||||
ImGui::GetIO().Fonts->GetTexDataAsRGBA32(&pixels, &width, &height);
|
||||
LOG(0) << "imgui font width: " << width << " height: " << height;
|
||||
LOG(0) << "Font atlas size: " << width << ", " << height;
|
||||
auto image = std::make_unique<Image>();
|
||||
image->Create(width, height);
|
||||
memcpy(image->GetBuffer(), pixels, width * height * 4);
|
||||
|
@ -98,7 +121,7 @@ void ImguiBackend::NewFrame() {
|
|||
ImGuiIO& io = ImGui::GetIO();
|
||||
io.DisplaySize = ImVec2((float)renderer_->GetScreenWidth(),
|
||||
(float)renderer_->GetScreenHeight());
|
||||
io.DeltaTime = timer_.Elapsed();
|
||||
io.DeltaTime = timer_.Delta();
|
||||
ImGui::NewFrame();
|
||||
}
|
||||
|
||||
|
@ -131,14 +154,14 @@ void ImguiBackend::Render() {
|
|||
|
||||
for (int cmd_i = 0; cmd_i < cmd_list->CmdBuffer.Size; cmd_i++) {
|
||||
const ImDrawCmd* pcmd = &cmd_list->CmdBuffer[cmd_i];
|
||||
reinterpret_cast<Texture*>(pcmd->GetTexID())->Activate(0);
|
||||
if (pcmd->ClipRect.z <= pcmd->ClipRect.x ||
|
||||
pcmd->ClipRect.w <= pcmd->ClipRect.y)
|
||||
continue;
|
||||
|
||||
if (pcmd->ClipRect.z > pcmd->ClipRect.x &&
|
||||
pcmd->ClipRect.w > pcmd->ClipRect.y) {
|
||||
renderer_->SetScissor(int(pcmd->ClipRect.x), int(pcmd->ClipRect.y),
|
||||
int(pcmd->ClipRect.z - pcmd->ClipRect.x),
|
||||
int(pcmd->ClipRect.w - pcmd->ClipRect.y));
|
||||
}
|
||||
reinterpret_cast<Texture*>(pcmd->GetTexID())->Activate(0);
|
||||
renderer_->SetScissor(int(pcmd->ClipRect.x), int(pcmd->ClipRect.y),
|
||||
int(pcmd->ClipRect.z - pcmd->ClipRect.x),
|
||||
int(pcmd->ClipRect.w - pcmd->ClipRect.y));
|
||||
renderer_->Draw(geometry_id, pcmd->ElemCount, pcmd->IdxOffset);
|
||||
}
|
||||
renderer_->DestroyGeometry(geometry_id);
|
||||
|
|
|
@ -29,7 +29,7 @@ class ImguiBackend {
|
|||
private:
|
||||
std::unique_ptr<Shader> shader_;
|
||||
Renderer* renderer_ = nullptr;
|
||||
base::ElapsedTimer timer_;
|
||||
base::DeltaTimer timer_;
|
||||
};
|
||||
|
||||
} // namespace eng
|
||||
|
|
|
@ -59,8 +59,6 @@ int RendererOpenGL::GetScreenHeight() const {
|
|||
}
|
||||
|
||||
void RendererOpenGL::SetScissor(int x, int y, int width, int height) {
|
||||
DCHECK(x >= 0 && y >= 0 && width >= 0 && height >= 0);
|
||||
DCHECK(x + width <= GetScreenWidth() && y + height <= GetScreenHeight());
|
||||
glScissor(x, screen_height_ - y - height, width, height);
|
||||
glEnable(GL_SCISSOR_TEST);
|
||||
}
|
||||
|
|
|
@ -391,8 +391,14 @@ int RendererVulkan::GetScreenHeight() const {
|
|||
}
|
||||
|
||||
void RendererVulkan::SetScissor(int x, int y, int width, int height) {
|
||||
DCHECK(x >= 0 && y >= 0 && width >= 0 && height >= 0);
|
||||
DCHECK(x + width <= GetScreenWidth() && y + height <= GetScreenHeight());
|
||||
if (x < 0)
|
||||
x = 0;
|
||||
if (y < 0)
|
||||
y = 0;
|
||||
if (x + width > GetScreenWidth())
|
||||
width = GetScreenWidth() - x;
|
||||
if (y + height > GetScreenHeight())
|
||||
height = GetScreenHeight() - y;
|
||||
|
||||
VkRect2D scissor;
|
||||
scissor.offset.x = x;
|
||||
|
|
Loading…
Reference in New Issue