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,115 +455,17 @@ void blp_texture::finishLoading()
namespace Noggit
{
BLPRenderer::BLPRenderer()
{
_cache = {};
OpenGL::context::save_current_context const context_save (::gl);
_context.create();
_fmt.setSamples(1);
_fmt.setInternalTextureFormat(GL_RGBA8);
_surface.create();
_context.makeCurrent(&_surface);
OpenGL::context::scoped_setter const context_set (::gl, &_context);
OpenGL::Scoped::bool_setter<GL_CULL_FACE, GL_FALSE> cull;
OpenGL::Scoped::bool_setter<GL_DEPTH_TEST, GL_FALSE> depth;
_vao.upload();
_buffers.upload();
GLuint const& indices_vbo = _buffers[0];
GLuint const& vertices_vbo = _buffers[1];
GLuint const& texcoords_vbo = _buffers[2];
std::vector<glm::vec2> vertices =
{
{-1.0f, -1.0f}
,{-1.0f, 1.0f}
,{ 1.0f, 1.0f}
,{ 1.0f, -1.0f}
};
std::vector<glm::vec2> texcoords =
{
{0.f, 0.f}
,{0.f, 1.0f}
,{1.0f, 1.0f}
,{1.0f, 0.f}
};
std::vector<std::uint16_t> indices = {0,1,2, 2,3,0};
gl.bufferData<GL_ARRAY_BUFFER,glm::vec2>(vertices_vbo, vertices, GL_STATIC_DRAW);
gl.bufferData<GL_ARRAY_BUFFER,glm::vec2>(texcoords_vbo, texcoords, GL_STATIC_DRAW);
gl.bufferData<GL_ELEMENT_ARRAY_BUFFER, std::uint16_t>(indices_vbo, indices, GL_STATIC_DRAW);
_program.reset(new OpenGL::program
(
{
{
GL_VERTEX_SHADER, R"code(
#version 330 core
in vec4 position;
in vec2 tex_coord;
out vec2 f_tex_coord;
uniform float width;
uniform float height;
void main()
{
f_tex_coord = vec2(tex_coord.x * width, -tex_coord.y * height);
gl_Position = vec4(position.x * width / 2, position.y * height / 2, position.z, 1.0);
}
)code"
},
{
GL_FRAGMENT_SHADER, R"code(
#version 330 core
uniform sampler2DArray tex;
uniform int tex_index;
in vec2 f_tex_coord;
layout(location = 0) out vec4 out_color;
void main()
{
out_color = vec4(texture(tex, vec3(f_tex_coord/2.f + vec2(0.5), tex_index)).rgb, 1.);
}
)code"
}
}
));
OpenGL::Scoped::use_program shader (*_program.get());
OpenGL::Scoped::vao_binder const _ (_vao[0]);
{
OpenGL::Scoped::buffer_binder<GL_ARRAY_BUFFER> vertices_binder (vertices_vbo);
shader.attrib("position", 2, GL_FLOAT, GL_FALSE, 0, 0);
}
{
OpenGL::Scoped::buffer_binder<GL_ARRAY_BUFFER> texcoords_binder (texcoords_vbo);
shader.attrib("tex_coord", 2, GL_FLOAT, GL_FALSE, 0, 0);
}
}
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)};
@@ -572,9 +474,9 @@ namespace Noggit
OpenGL::context::save_current_context const context_save (::gl);
_context.makeCurrent(&_surface);
_context->makeCurrent(_surface.get());
OpenGL::context::scoped_setter const context_set (::gl, &_context);
OpenGL::context::scoped_setter const context_set (::gl, _context.get());
gl.activeTexture(GL_TEXTURE0);
blp_texture texture(blp_filename, Noggit::NoggitRenderContext::BLP_RENDERER);
@@ -587,7 +489,7 @@ namespace Noggit
float h = static_cast<float>(height);
float w = static_cast<float>(width);
QOpenGLFramebufferObject pixel_buffer(width, height, _fmt);
QOpenGLFramebufferObject pixel_buffer(width, height, *_fmt.get());
pixel_buffer.bind();
gl.viewport(0, 0, w, h);
@@ -622,10 +524,131 @@ namespace Noggit
return &(_cache[curEntry] = std::move(result));
}
BLPRenderer::~BLPRenderer()
void BLPRenderer::upload()
{
OpenGL::context::scoped_setter const context_set (::gl, &_context);
_cache = {};
OpenGL::context::save_current_context const context_save (::gl);
_context = std::make_unique<QOpenGLContext>();
_fmt = std::make_unique<QOpenGLFramebufferObjectFormat>();
_surface = std::make_unique<QOffscreenSurface>();
_context->create();
_fmt->setSamples(1);
_fmt->setInternalTextureFormat(GL_RGBA8);
_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;
_vao.upload();
_buffers.upload();
GLuint const& indices_vbo = _buffers[0];
GLuint const& vertices_vbo = _buffers[1];
GLuint const& texcoords_vbo = _buffers[2];
std::vector<glm::vec2> vertices =
{
{-1.0f, -1.0f}
,{-1.0f, 1.0f}
,{ 1.0f, 1.0f}
,{ 1.0f, -1.0f}
};
std::vector<glm::vec2> texcoords =
{
{0.f, 0.f}
,{0.f, 1.0f}
,{1.0f, 1.0f}
,{1.0f, 0.f}
};
std::vector<std::uint16_t> indices = {0,1,2, 2,3,0};
gl.bufferData<GL_ARRAY_BUFFER,glm::vec2>(vertices_vbo, vertices, GL_STATIC_DRAW);
gl.bufferData<GL_ARRAY_BUFFER,glm::vec2>(texcoords_vbo, texcoords, GL_STATIC_DRAW);
gl.bufferData<GL_ELEMENT_ARRAY_BUFFER, std::uint16_t>(indices_vbo, indices, GL_STATIC_DRAW);
_program.reset(new OpenGL::program
(
{
{
GL_VERTEX_SHADER, R"code(
#version 330 core
in vec4 position;
in vec2 tex_coord;
out vec2 f_tex_coord;
uniform float width;
uniform float height;
void main()
{
f_tex_coord = vec2(tex_coord.x * width, -tex_coord.y * height);
gl_Position = vec4(position.x * width / 2, position.y * height / 2, position.z, 1.0);
}
)code"
},
{
GL_FRAGMENT_SHADER, R"code(
#version 330 core
uniform sampler2DArray tex;
uniform int tex_index;
in vec2 f_tex_coord;
layout(location = 0) out vec4 out_color;
void main()
{
out_color = vec4(texture(tex, vec3(f_tex_coord/2.f + vec2(0.5), tex_index)).rgb, 1.);
}
)code"
}
}
));
OpenGL::Scoped::use_program shader (*_program.get());
OpenGL::Scoped::vao_binder const _ (_vao[0]);
{
OpenGL::Scoped::buffer_binder<GL_ARRAY_BUFFER> vertices_binder (vertices_vbo);
shader.attrib("position", 2, GL_FLOAT, GL_FALSE, 0, 0);
}
{
OpenGL::Scoped::buffer_binder<GL_ARRAY_BUFFER> texcoords_binder (texcoords_vbo);
shader.attrib("tex_coord", 2, GL_FLOAT, GL_FALSE, 0, 0);
}
_uploaded = true;
}
void BLPRenderer::unload()
{
OpenGL::context::save_current_context const context_save (::gl);
_context->makeCurrent(_surface.get());
OpenGL::context::scoped_setter const context_set (::gl, _context.get());
_cache.clear();
_vao.unload();
_buffers.unload();
_program.reset();
_surface.reset();
_fmt.reset();
_context.reset();
_uploaded = false;
}
}
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,26 +21,32 @@ 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
}
*/
class LiquidTextureManager
namespace Noggit::Rendering
{
public:
class LiquidTextureManager
{
public:
explicit LiquidTextureManager(Noggit::NoggitRenderContext context);
LiquidTextureManager() = delete;
explicit LiquidTextureManager(Noggit::NoggitRenderContext context);
LiquidTextureManager() = delete;
void upload();
void unload();
void upload();
void unload();
tsl::robin_map<unsigned, std::tuple<GLuint, glm::vec2, int, unsigned>> const& getTextureFrames() { return _texture_frames_map; };
tsl::robin_map<unsigned, std::tuple<GLuint, glm::vec2, int, unsigned>> const& getTextureFrames() { return _texture_frames_map; };
private:
bool _uploaded = false;
private:
bool _uploaded = false;
// liquidTypeRecID : (array, (animation_x, animation_y), liquid_type)
tsl::robin_map<unsigned, std::tuple<GLuint, glm::vec2, int, unsigned>> _texture_frames_map;
// liquidTypeRecID : (array, (animation_x, animation_y), liquid_type)
tsl::robin_map<unsigned, std::tuple<GLuint, glm::vec2, int, unsigned>> _texture_frames_map;
Noggit::NoggitRenderContext _context;
};
}
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,52 +5,59 @@
#include <vector>
#include <noggit/ContextObject.hpp>
namespace Noggit
namespace Noggit::Ui::Tools::ViewportManager
{
namespace Ui::Tools::ViewportManager
class Viewport;
class ViewportManager
{
public:
static std::vector<Viewport*> _viewports;
static void registerViewport(Viewport* viewport)
{
class Viewport;
class ViewportManager
ViewportManager::_viewports.push_back(viewport);
};
static void unregisterViewport(Viewport* viewport)
{
for (auto it = ViewportManager::_viewports.begin(); it != ViewportManager::_viewports.end(); ++it)
{
if (viewport == *it)
{
public:
static std::vector<Viewport*> _viewports;
ViewportManager::_viewports.erase(it);
break;
}
}
};
static void registerViewport(Viewport* viewport)
{
ViewportManager::_viewports.push_back(viewport);
};
static void unloadOpenglData(Viewport* caller);
static void unloadAll();
};
static void unregisterViewport(Viewport* viewport)
{
for(auto it = ViewportManager::_viewports.begin(); it != ViewportManager::_viewports.end(); ++it)
{
if (viewport == *it)
{
ViewportManager::_viewports.erase(it);
break;
}
}
};
class Viewport : public QOpenGLWidget
{
Q_OBJECT
static void unloadOpenglData(Viewport* caller);
};
public:
Viewport(QWidget* parent = nullptr);
class Viewport : public QOpenGLWidget
{
public:
Viewport(QWidget* parent = nullptr);
virtual void unloadOpenglData(bool from_manager = false) = 0;
Noggit::NoggitRenderContext getRenderContext() { return _context; };
virtual void unloadOpenglData() = 0;
~Viewport();
Noggit::NoggitRenderContext getRenderContext()
{ return _context; };
protected:
Noggit::NoggitRenderContext _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;