noggit now finally exists with code 0 | Update blizzard-database-library, MapTile.cpp, and 15 more files...

This commit is contained in:
Skarn
2022-01-17 20:10:04 +03:00
parent 04e20c6529
commit 55dfdef1a7
17 changed files with 265 additions and 222 deletions

View File

@@ -921,7 +921,7 @@ void MapTile::remove_model(uint32_t uid)
{
uids.erase(it);
const auto& obj = _world->get_model(uid).value();
const auto obj = _world->get_model(uid).value();
auto instance = std::get<selected_object_type>(obj);
auto& instances = object_instances[instance->instance_model()];

View File

@@ -111,7 +111,7 @@ public:
bool isTile(int pX, int pZ);
virtual async_priority loading_priority() const
async_priority loading_priority() const override
{
return async_priority::high;
}

View File

@@ -2686,12 +2686,6 @@ void MapView::on_uid_fix_fail()
void MapView::initializeGL()
{
_gl_guard_connection = connect(context(), &QOpenGLContext::aboutToBeDestroyed,
[this]()
{
unloadOpenglData();
});
bool uid_warning = false;
OpenGL::context::scoped_setter const _ (::gl, context());
@@ -2754,6 +2748,8 @@ void MapView::initializeGL()
gl.bufferData<GL_PIXEL_PACK_BUFFER>(_buffers[0], 4, nullptr, GL_DYNAMIC_READ);
gl.bufferData<GL_PIXEL_PACK_BUFFER>(_buffers[1], 4, nullptr, GL_DYNAMIC_READ);
connect(context(), &QOpenGLContext::aboutToBeDestroyed, [this](){ emit aboutToLooseContext(); });
_gl_initialized = true;
}
@@ -3205,8 +3201,6 @@ MapView::~MapView()
ModelManager::report();
TextureManager::report();
WMOManager::report();
disconnect(_gl_guard_connection);
}
void MapView::tick (float dt)
@@ -5122,11 +5116,8 @@ void MapView::randomizeStampRotation()
stampTool->changeRotation(uid(gen));
}
void MapView::unloadOpenglData(bool from_manager)
void MapView::unloadOpenglData()
{
LogDebug << "Changing context of MapView." << std::endl;
makeCurrent();
OpenGL::context::scoped_setter const _ (::gl, context());
@@ -5150,15 +5141,8 @@ void MapView::unloadOpenglData(bool from_manager)
_world->renderer()->unload();
if (!from_manager)
Noggit::Ui::Tools::ViewportManager::ViewportManager::unloadOpenglData(this);
_buffers.unload();
disconnect(_gl_guard_connection);
_gl_initialized = false;
LogDebug << "Changed context of MapView." << std::endl;
}
QWidget* MapView::getActiveStampModeItem()

View File

@@ -18,7 +18,6 @@
#include <noggit/ui/tools/ToolPanel/ToolPanel.hpp>
#include <noggit/TabletManager.hpp>
#include <external/qtimgui/QtImGui.h>
#include <external/QtAdvancedDockingSystem/src/DockManager.h>
#include <opengl/texture.hpp>
#include <opengl/scoped.hpp>
#include <optional>
@@ -148,6 +147,7 @@ private:
int _selected_area_id = -1;
[[nodiscard]]
math::ray intersect_ray() const;
selection_result intersect_result(bool terrain_only);
void doSelection(bool selectTerrainOnly, bool mouseMove = false);
@@ -155,7 +155,10 @@ private:
display_mode _display_mode;
[[nodiscard]]
glm::mat4x4 model_view() const;
[[nodiscard]]
glm::mat4x4 projection() const;
void draw_map();
@@ -246,7 +249,6 @@ public:
void change_selected_wmo_doodadset(int set);
void saveMinimap(MinimapRenderSettings* settings);
void initMinimapSave() { saving_minimap = true; };
auto populateImageModel(QStandardItemModel* model) const -> void;
auto setBrushTexture(QImage const* img) -> void;
Noggit::Camera* getCamera() { return &_camera; };
void randomizeTerrainRotation();
@@ -254,17 +256,29 @@ public:
void randomizeShaderRotation();
void randomizeStampRotation();
void onSettingsSave();
[[nodiscard]]
Noggit::Ui::minimap_widget* getMinimapWidget() const { return _minimap; }
void set_editing_mode (editing_mode);
editing_mode get_editing_mode() { return terrainMode; };
[[nodiscard]]
QWidget* getActiveStampModeItem();
[[nodiscard]]
Noggit::NoggitRenderContext getRenderContext() { return _context; };
[[nodiscard]]
World* getWorld() { return _world.get(); };
[[nodiscard]]
QDockWidget* getAssetBrowser() {return _asset_browser_dock; };
[[nodiscard]]
Noggit::Ui::object_editor* getObjectEditor() { return objectEditor; };
[[nodiscard]]
QDockWidget* getObjectPalette() { return _object_palette_dock; };
@@ -360,7 +374,7 @@ private:
void setToolPropertyWidgetVisibility(editing_mode mode);
void unloadOpenglData(bool from_manager = false) override;
void unloadOpenglData() override;
Noggit::Ui::help* _keybindings;
Noggit::Ui::tileset_chooser* TexturePalette;
@@ -397,7 +411,7 @@ private:
ImGuizmo::MODE _gizmo_mode = ImGuizmo::MODE::WORLD;
ImGuizmo::OPERATION _gizmo_operation = ImGuizmo::OPERATION::TRANSLATE;
Noggit::BoolToggleProperty _gizmo_on = {true};
QMetaObject::Connection _gl_guard_connection;
bool _gl_initialized = false;
bool _destroying = false;
bool _needs_redraw = false;

View File

@@ -455,21 +455,94 @@ void blp_texture::finishLoading()
namespace Noggit
{
BLPRenderer::BLPRenderer()
QPixmap* BLPRenderer::render_blp_to_pixmap ( std::string const& blp_filename
, int width
, int height
)
{
if (!_uploaded)
[[unlikely]]
{
upload();
}
std::tuple<std::string, int, int> const curEntry{blp_filename, width, height};
auto it{_cache.find(curEntry)};
if(it != _cache.end())
return &it->second;
OpenGL::context::save_current_context const context_save (::gl);
_context->makeCurrent(_surface.get());
OpenGL::context::scoped_setter const context_set (::gl, _context.get());
gl.activeTexture(GL_TEXTURE0);
blp_texture texture(blp_filename, Noggit::NoggitRenderContext::BLP_RENDERER);
texture.finishLoading();
texture.upload();
width = width == -1 ? texture.width() : width;
height = height == -1 ? texture.height() : height;
float h = static_cast<float>(height);
float w = static_cast<float>(width);
QOpenGLFramebufferObject pixel_buffer(width, height, *_fmt.get());
pixel_buffer.bind();
gl.viewport(0, 0, w, h);
gl.clearColor(.0f, .0f, .0f, 1.f);
gl.clear(GL_COLOR_BUFFER_BIT);
OpenGL::Scoped::use_program shader (*_program.get());
shader.uniform("tex", 0);
shader.uniform("width", w);
shader.uniform("height", h);
gl.bindTexture(GL_TEXTURE_2D_ARRAY, texture.texture_array());
shader.uniform("tex_index", texture.array_index());
OpenGL::Scoped::vao_binder const _ (_vao[0]);
OpenGL::Scoped::buffer_binder<GL_ELEMENT_ARRAY_BUFFER> indices_binder(_buffers[0]);
gl.drawElements(GL_TRIANGLES, 6, GL_UNSIGNED_SHORT, nullptr);
QPixmap result{};
result = std::move(QPixmap::fromImage(pixel_buffer.toImage()));
pixel_buffer.release();
if (result.isNull())
{
throw std::runtime_error
("failed rendering " + blp_filename + " to pixmap");
}
return &(_cache[curEntry] = std::move(result));
}
void BLPRenderer::upload()
{
_cache = {};
OpenGL::context::save_current_context const context_save (::gl);
_context.create();
_fmt.setSamples(1);
_fmt.setInternalTextureFormat(GL_RGBA8);
_context = std::make_unique<QOpenGLContext>();
_fmt = std::make_unique<QOpenGLFramebufferObjectFormat>();
_surface = std::make_unique<QOffscreenSurface>();
_surface.create();
_context->create();
_context.makeCurrent(&_surface);
_fmt->setSamples(1);
_fmt->setInternalTextureFormat(GL_RGBA8);
OpenGL::context::scoped_setter const context_set (::gl, &_context);
_surface->create();
_context->makeCurrent(_surface.get());
OpenGL::context::scoped_setter const context_set (::gl, _context.get());
OpenGL::Scoped::bool_setter<GL_CULL_FACE, GL_FALSE> cull;
OpenGL::Scoped::bool_setter<GL_DEPTH_TEST, GL_FALSE> depth;
@@ -556,76 +629,26 @@ namespace Noggit
shader.attrib("tex_coord", 2, GL_FLOAT, GL_FALSE, 0, 0);
}
_uploaded = true;
}
QPixmap* BLPRenderer::render_blp_to_pixmap ( std::string const& blp_filename
, int width
, int height
)
void BLPRenderer::unload()
{
std::tuple<std::string, int, int> const curEntry{blp_filename, width, height};
auto it{_cache.find(curEntry)};
if(it != _cache.end())
return &it->second;
OpenGL::context::save_current_context const context_save (::gl);
_context->makeCurrent(_surface.get());
OpenGL::context::scoped_setter const context_set (::gl, _context.get());
_context.makeCurrent(&_surface);
_cache.clear();
_vao.unload();
_buffers.unload();
_program.reset();
_surface.reset();
_fmt.reset();
_context.reset();
OpenGL::context::scoped_setter const context_set (::gl, &_context);
gl.activeTexture(GL_TEXTURE0);
blp_texture texture(blp_filename, Noggit::NoggitRenderContext::BLP_RENDERER);
texture.finishLoading();
texture.upload();
width = width == -1 ? texture.width() : width;
height = height == -1 ? texture.height() : height;
float h = static_cast<float>(height);
float w = static_cast<float>(width);
QOpenGLFramebufferObject pixel_buffer(width, height, _fmt);
pixel_buffer.bind();
gl.viewport(0, 0, w, h);
gl.clearColor(.0f, .0f, .0f, 1.f);
gl.clear(GL_COLOR_BUFFER_BIT);
OpenGL::Scoped::use_program shader (*_program.get());
shader.uniform("tex", 0);
shader.uniform("width", w);
shader.uniform("height", h);
gl.bindTexture(GL_TEXTURE_2D_ARRAY, texture.texture_array());
shader.uniform("tex_index", texture.array_index());
OpenGL::Scoped::vao_binder const _ (_vao[0]);
OpenGL::Scoped::buffer_binder<GL_ELEMENT_ARRAY_BUFFER> indices_binder(_buffers[0]);
gl.drawElements(GL_TRIANGLES, 6, GL_UNSIGNED_SHORT, nullptr);
QPixmap result{};
result = std::move(QPixmap::fromImage(pixel_buffer.toImage()));
pixel_buffer.release();
if (result.isNull())
{
throw std::runtime_error
("failed rendering " + blp_filename + " to pixmap");
_uploaded = false;
}
return &(_cache[curEntry] = std::move(result));
}
BLPRenderer::~BLPRenderer()
{
OpenGL::context::scoped_setter const context_set (::gl, &_context);
}
}
scoped_blp_texture_reference::scoped_blp_texture_reference (std::string const& filename, Noggit::NoggitRenderContext context)
@@ -647,6 +670,7 @@ blp_texture* scoped_blp_texture_reference::operator->() const
{
return _blp_texture.get();
}
blp_texture* scoped_blp_texture_reference::get() const
{
return _blp_texture.get();

View File

@@ -144,21 +144,23 @@ namespace Noggit
class BLPRenderer
{
private:
BLPRenderer();
BLPRenderer() = default;
BLPRenderer( const BLPRenderer&);
BLPRenderer& operator=( BLPRenderer& );
BLPRenderer( const BLPRenderer&) = delete;
BLPRenderer& operator=( BLPRenderer& ) = delete;
std::map<std::tuple<std::string, int, int>, QPixmap> _cache;
QOpenGLContext _context;
QOpenGLFramebufferObjectFormat _fmt;
QOffscreenSurface _surface;
std::unique_ptr<QOpenGLContext> _context;
std::unique_ptr<QOpenGLFramebufferObjectFormat> _fmt;
std::unique_ptr<QOffscreenSurface> _surface;
std::unique_ptr<OpenGL::program> _program;
OpenGL::Scoped::deferred_upload_vertex_arrays<1> _vao;
OpenGL::Scoped::deferred_upload_buffers<3> _buffers;
bool _uploaded = false;
public:
static BLPRenderer& getInstance()
{
@@ -166,9 +168,9 @@ namespace Noggit
return instance;
}
~BLPRenderer();
QPixmap* render_blp_to_pixmap ( std::string const& blp_filename, int width = -1, int height = -1);
void unload();
void upload();
};

View File

@@ -48,7 +48,7 @@ public:
, int animtime
, int layer
, display_mode display
, LiquidTextureManager* tex_manager
, Noggit::Rendering::LiquidTextureManager* tex_manager
);
bool hasData(size_t layer);
bool hasData() { return _has_data; };

View File

@@ -15,11 +15,11 @@ namespace math
}
class MapTile;
class LiquidTextureManager;
namespace Noggit::Rendering
{
class LiquidTextureManager;
struct LiquidLayerDrawCallData
{

View File

@@ -5,6 +5,8 @@
#include "noggit/DBC.h"
#include "noggit/application/NoggitApplication.hpp"
using namespace Noggit::Rendering;
LiquidTextureManager::LiquidTextureManager(Noggit::NoggitRenderContext context)
: _context(context)
{

View File

@@ -3,13 +3,14 @@
#ifndef NOGGIT_LIQUIDTEXTUREMANAGER_HPP
#define NOGGIT_LIQUIDTEXTUREMANAGER_HPP
#include "noggit/TextureManager.h"
#include "noggit/ContextObject.hpp"
#include "external/tsl/robin_map.h"
#include <noggit/TextureManager.h>
#include <noggit/ContextObject.hpp>
#include <external/tsl/robin_map.h>
#include <tuple>
#include "external/glm/vec2.hpp"
#include <external/glm/vec2.hpp>
/*
template<typename ... Args>
std::string string_format(const std::string& format, Args ... args)
{
@@ -20,7 +21,10 @@ std::string string_format(const std::string& format, Args ... args)
std::snprintf(buf.get(), size, format.c_str(), args ...);
return std::string(buf.get(), buf.get() + size - 1); // We don't want the '\0' inside
}
*/
namespace Noggit::Rendering
{
class LiquidTextureManager
{
public:
@@ -42,4 +46,7 @@ private:
Noggit::NoggitRenderContext _context;
};
}
#endif //NOGGIT_LIQUIDTEXTUREMANAGER_HPP

View File

@@ -184,6 +184,11 @@ void ModelViewer::initializeGL()
AssetBrowser::ModelViewer::initializeGL();
_imgui_context = QtImGui::initialize(this);
connect(context(), &QOpenGLContext::aboutToBeDestroyed, [=]()
{
emit aboutToLooseContext();
});
}

View File

@@ -529,21 +529,7 @@ PreviewRenderer::~PreviewRenderer()
_m2_box_program.reset();
_wmo_program.reset();
}
else
{
makeCurrent();
OpenGL::context::scoped_setter const context_set (::gl, context());
_model_instances.clear();
_wmo_instances.clear();
_m2_program.reset();
_m2_instanced_program.reset();
_m2_particles_program.reset();
_m2_ribbons_program.reset();
_m2_box_program.reset();
_wmo_program.reset();
unload();
}
}
@@ -708,12 +694,11 @@ void PreviewRenderer::unload()
}
void PreviewRenderer::unloadOpenglData(bool from_manager)
void PreviewRenderer::unloadOpenglData()
{
if (_offscreen_mode)
return;
LogDebug << "Changing context of Asset Browser / Preset Editor." << std::endl;
makeCurrent();
OpenGL::context::scoped_setter const _ (::gl, context());
@@ -722,11 +707,6 @@ void PreviewRenderer::unloadOpenglData(bool from_manager)
TextureManager::unload_all(_context);
unload();
LogDebug << "Changed context of Asset Browser / Preset Editor.." << std::endl;
if (!from_manager)
ViewportManager::ViewportManager::unloadOpenglData(this);
}
void Noggit::Ui::Tools::PreviewRenderer::updateLightingUniformBlock()

View File

@@ -87,7 +87,7 @@ class PreviewRenderer : public Noggit::Ui::Tools::ViewportManager::Viewport
void unload();
void unloadOpenglData(bool from_manager = false) override;
void unloadOpenglData() override;
void updateLightingUniformBlock();
@@ -115,7 +115,7 @@ class PreviewRenderer : public Noggit::Ui::Tools::ViewportManager::Viewport
OpenGL::MVPUniformBlock _mvp_ubo_data;
OpenGL::LightingUniformBlock _lighting_ubo_data;
LiquidTextureManager _liquid_texture_manager;
Noggit::Rendering::LiquidTextureManager _liquid_texture_manager;
bool _uploaded = false;
bool _lighting_needs_update = true;

View File

@@ -1,4 +1,5 @@
#include "ViewportManager.hpp"
#include <noggit/TextureManager.h>
using namespace Noggit::Ui::Tools::ViewportManager;
@@ -8,6 +9,11 @@ Viewport::Viewport(QWidget* parent)
: QOpenGLWidget(parent)
{
ViewportManager::registerViewport(this);
_gl_connection = connect(this, &Viewport::aboutToLooseContext, [this]()
{
ViewportManager::unloadOpenglData(this);
});
}
Viewport::~Viewport()
@@ -22,6 +28,16 @@ void ViewportManager::unloadOpenglData(Viewport* caller)
if (viewport == caller)
continue;
viewport->unloadOpenglData(true);
viewport->unloadOpenglData();
}
}
void ViewportManager::unloadAll()
{
for (auto viewport : ViewportManager::_viewports)
{
viewport->unloadOpenglData();
}
BLPRenderer::getInstance().unload();
}

View File

@@ -5,11 +5,10 @@
#include <vector>
#include <noggit/ContextObject.hpp>
namespace Noggit
{
namespace Ui::Tools::ViewportManager
namespace Noggit::Ui::Tools::ViewportManager
{
class Viewport;
class ViewportManager
{
public:
@@ -33,24 +32,32 @@ namespace Noggit
};
static void unloadOpenglData(Viewport* caller);
static void unloadAll();
};
class Viewport : public QOpenGLWidget
{
Q_OBJECT
public:
Viewport(QWidget* parent = nullptr);
virtual void unloadOpenglData(bool from_manager = false) = 0;
Noggit::NoggitRenderContext getRenderContext() { return _context; };
virtual void unloadOpenglData() = 0;
Noggit::NoggitRenderContext getRenderContext()
{ return _context; };
~Viewport();
signals:
void aboutToLooseContext();
protected:
Noggit::NoggitRenderContext _context;
QMetaObject::Connection _gl_connection;
};
}
}
#endif //NOGGIT_VIEWPORTMANAGER_HPP

View File

@@ -45,6 +45,7 @@
#include "ui_TitleBar.h"
#include <external/framelesshelper/framelesswindowsmanager.h>
#include <noggit/ui/tools/ViewportManager/ViewportManager.hpp>
namespace Noggit::Ui::Windows
{
@@ -371,6 +372,7 @@ namespace Noggit::Ui::Windows
map_loaded = false;
break;
case QMessageBox::DestructiveRole:
Noggit::Ui::Tools::ViewportManager::ViewportManager::unloadAll();
setCentralWidget(_null_widget = new QWidget(this));
event->accept();
break;