Skip to content

Commit

Permalink
Cap texture size to the max if exceeding it during map extraction. Al…
Browse files Browse the repository at this point in the history
…so added error messages when not enough vram for the map extraction and tell the users to lower their extract resolution.
  • Loading branch information
Jonathan-Greve committed Jan 16, 2024
1 parent 43893b0 commit aac37b6
Show file tree
Hide file tree
Showing 4 changed files with 75 additions and 10 deletions.
5 changes: 5 additions & 0 deletions SourceFiles/DeviceResources.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -240,6 +240,11 @@ void DeviceResources::UpdateOffscreenResources(int width, int height) {
m_d3dOffscreenDepthStencilView.Reset();
m_offscreenDepthStencil.Reset();

const int maxWidth = D3D11_REQ_TEXTURE2D_U_OR_V_DIMENSION; // Dx11 maximum texture dimension
const int maxHeight = D3D11_REQ_TEXTURE2D_U_OR_V_DIMENSION; // Dx11 maximum texture dimension
width = std::min(width, maxWidth);
height = std::min(height, maxHeight);

const DXGI_FORMAT backBufferFormat = (m_options & (c_FlipPresent | c_AllowTearing | c_EnableHDR))
? NoSRGB(m_backBufferFormat)
: m_backBufferFormat;
Expand Down
73 changes: 64 additions & 9 deletions SourceFiles/MapBrowser.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -170,17 +170,22 @@ void MapBrowser::Render()
ImGui_ImplDX11_NewFrame();
ImGui_ImplWin32_NewFrame();
ImGui::NewFrame();
if (m_show_error_msg) {
ShowErrorMessage();
}
else {

draw_ui(m_dat_managers, m_dat_manager_to_show_in_dat_browser, m_map_renderer.get(), picking_info, m_csv_data, m_FPS_target, m_timer, m_extract_panel_info);
draw_ui(m_dat_managers, m_dat_manager_to_show_in_dat_browser, m_map_renderer.get(), picking_info, m_csv_data, m_FPS_target, m_timer, m_extract_panel_info);

if (!m_mft_indices_to_extract.empty()) {
draw_dat_load_progress_bar(m_dat_managers[m_dat_manager_to_show_in_dat_browser]->get_num_files_for_type(FFNA_Type3) - m_mft_indices_to_extract.size(),
m_dat_managers[m_dat_manager_to_show_in_dat_browser]->get_num_files_for_type(FFNA_Type3));
}
if (!m_mft_indices_to_extract.empty()) {
draw_dat_load_progress_bar(m_dat_managers[m_dat_manager_to_show_in_dat_browser]->get_num_files_for_type(FFNA_Type3) - m_mft_indices_to_extract.size(),
m_dat_managers[m_dat_manager_to_show_in_dat_browser]->get_num_files_for_type(FFNA_Type3));
}

static bool show_demo_window = false;
if (show_demo_window)
ImGui::ShowDemoWindow(&show_demo_window);
static bool show_demo_window = false;
if (show_demo_window)
ImGui::ShowDemoWindow(&show_demo_window);
}

// Dear ImGui Render
ImGui::Render();
Expand Down Expand Up @@ -287,10 +292,31 @@ void MapBrowser::Render()

HRESULT hrSave = DirectX::SaveToDDSFile(compressedImage.GetImages(), compressedImage.GetImageCount(), compressedImage.GetMetadata(), DDS_FLAGS_NONE, filename.c_str());
if (FAILED(hrSave)) {
// Handle the error
m_mft_indices_to_extract.clear();

m_error_msg = std::format("SaveToDDSFile failed. Try lowering the resolution (i.e. use less pixels per tile).");
m_show_error_msg = true;
}
}
else {
m_mft_indices_to_extract.clear();

m_error_msg = std::format("Compress failed. Try lowering the resolution (i.e. use less pixels per tile).");
m_show_error_msg = true;
}
}
else {
m_mft_indices_to_extract.clear();

m_error_msg = std::format("GenerateMipMaps failed. Try lowering the resolution (i.e. use less pixels per tile).");
m_show_error_msg = true;
}
}
else {
m_mft_indices_to_extract.clear();

m_error_msg = std::format("CaptureTexture failed. Not enough VRAM, try lowering the resolution (i.e. use less pixels per tile).");
m_show_error_msg = true;
}
}

Expand Down Expand Up @@ -339,6 +365,35 @@ void MapBrowser::ClearOffscreen() {
m_deviceResources->PIXEndEvent();
}

void MapBrowser::ShowErrorMessage() {
if (m_show_error_msg) {
// Set the window to be centered
ImGui::SetNextWindowPos(ImVec2(ImGui::GetIO().DisplaySize.x * 0.5f,
ImGui::GetIO().DisplaySize.y * 0.5f),
ImGuiCond_Appearing, ImVec2(0.5f, 0.5f));

// Set the window to have a red border
ImGui::PushStyleColor(ImGuiCol_Border, ImVec4(1.0f, 0.0f, 0.0f, 1.0f));

// Create a window that is not resizable, not movable and with a title bar
ImGui::Begin("Error", &m_show_error_msg, ImGuiWindowFlags_NoResize | ImGuiWindowFlags_NoMove);

// Display the error message
ImGui::Text("%s", m_error_msg.c_str());

// Close button
if (ImGui::Button("Close")) {
m_show_error_msg = false;
}

// End the window
ImGui::End();

// Pop the style color for the border
ImGui::PopStyleColor();
}
}

#pragma region Message Handlers
// Message handlers
void MapBrowser::OnActivated()
Expand Down
5 changes: 5 additions & 0 deletions SourceFiles/MapBrowser.h
Original file line number Diff line number Diff line change
Expand Up @@ -55,6 +55,8 @@ class MapBrowser final : public DX::IDeviceNotify
void Clear();
void ClearOffscreen();

void ShowErrorMessage();

void CreateDeviceDependentResources();
void CreateWindowSizeDependentResources();

Expand Down Expand Up @@ -83,4 +85,7 @@ class MapBrowser final : public DX::IDeviceNotify
std::vector<std::vector<std::string>> m_csv_data;

std::unique_ptr<MapRenderer> m_map_renderer;

std::string m_error_msg = "";
bool m_show_error_msg = false;
};
2 changes: 1 addition & 1 deletion SourceFiles/draw_extract_panel.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -3,7 +3,7 @@
#include "GuiGlobalConstants.h"
#include "GWUnpacker.h"

constexpr int max_pixel_per_tile_dir = 20;
constexpr int max_pixel_per_tile_dir = 16384;

void draw_extract_panel(ExtractPanelInfo& extract_panel_info, DATManager* dat_manager)
{
Expand Down

0 comments on commit aac37b6

Please sign in to comment.