noggit now finally exists with code 0 | Update blizzard-database-library, MapTile.cpp, and 15 more files...
This commit is contained in:
2
src/external/blizzard-database-library
vendored
2
src/external/blizzard-database-library
vendored
Submodule src/external/blizzard-database-library updated: 5c6f2f381c...c2e8751af4
@@ -921,7 +921,7 @@ void MapTile::remove_model(uint32_t uid)
|
|||||||
{
|
{
|
||||||
uids.erase(it);
|
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 instance = std::get<selected_object_type>(obj);
|
||||||
|
|
||||||
auto& instances = object_instances[instance->instance_model()];
|
auto& instances = object_instances[instance->instance_model()];
|
||||||
|
|||||||
@@ -111,7 +111,7 @@ public:
|
|||||||
|
|
||||||
bool isTile(int pX, int pZ);
|
bool isTile(int pX, int pZ);
|
||||||
|
|
||||||
virtual async_priority loading_priority() const
|
async_priority loading_priority() const override
|
||||||
{
|
{
|
||||||
return async_priority::high;
|
return async_priority::high;
|
||||||
}
|
}
|
||||||
|
|||||||
@@ -2686,12 +2686,6 @@ void MapView::on_uid_fix_fail()
|
|||||||
|
|
||||||
void MapView::initializeGL()
|
void MapView::initializeGL()
|
||||||
{
|
{
|
||||||
_gl_guard_connection = connect(context(), &QOpenGLContext::aboutToBeDestroyed,
|
|
||||||
[this]()
|
|
||||||
{
|
|
||||||
unloadOpenglData();
|
|
||||||
});
|
|
||||||
|
|
||||||
bool uid_warning = false;
|
bool uid_warning = false;
|
||||||
|
|
||||||
OpenGL::context::scoped_setter const _ (::gl, context());
|
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[0], 4, nullptr, GL_DYNAMIC_READ);
|
||||||
gl.bufferData<GL_PIXEL_PACK_BUFFER>(_buffers[1], 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;
|
_gl_initialized = true;
|
||||||
}
|
}
|
||||||
|
|
||||||
@@ -3205,8 +3201,6 @@ MapView::~MapView()
|
|||||||
ModelManager::report();
|
ModelManager::report();
|
||||||
TextureManager::report();
|
TextureManager::report();
|
||||||
WMOManager::report();
|
WMOManager::report();
|
||||||
|
|
||||||
disconnect(_gl_guard_connection);
|
|
||||||
}
|
}
|
||||||
|
|
||||||
void MapView::tick (float dt)
|
void MapView::tick (float dt)
|
||||||
@@ -5122,11 +5116,8 @@ void MapView::randomizeStampRotation()
|
|||||||
stampTool->changeRotation(uid(gen));
|
stampTool->changeRotation(uid(gen));
|
||||||
}
|
}
|
||||||
|
|
||||||
void MapView::unloadOpenglData(bool from_manager)
|
void MapView::unloadOpenglData()
|
||||||
{
|
{
|
||||||
|
|
||||||
LogDebug << "Changing context of MapView." << std::endl;
|
|
||||||
|
|
||||||
makeCurrent();
|
makeCurrent();
|
||||||
OpenGL::context::scoped_setter const _ (::gl, context());
|
OpenGL::context::scoped_setter const _ (::gl, context());
|
||||||
|
|
||||||
@@ -5150,15 +5141,8 @@ void MapView::unloadOpenglData(bool from_manager)
|
|||||||
|
|
||||||
_world->renderer()->unload();
|
_world->renderer()->unload();
|
||||||
|
|
||||||
if (!from_manager)
|
|
||||||
Noggit::Ui::Tools::ViewportManager::ViewportManager::unloadOpenglData(this);
|
|
||||||
|
|
||||||
_buffers.unload();
|
_buffers.unload();
|
||||||
|
|
||||||
disconnect(_gl_guard_connection);
|
|
||||||
_gl_initialized = false;
|
_gl_initialized = false;
|
||||||
|
|
||||||
LogDebug << "Changed context of MapView." << std::endl;
|
|
||||||
}
|
}
|
||||||
|
|
||||||
QWidget* MapView::getActiveStampModeItem()
|
QWidget* MapView::getActiveStampModeItem()
|
||||||
|
|||||||
@@ -18,7 +18,6 @@
|
|||||||
#include <noggit/ui/tools/ToolPanel/ToolPanel.hpp>
|
#include <noggit/ui/tools/ToolPanel/ToolPanel.hpp>
|
||||||
#include <noggit/TabletManager.hpp>
|
#include <noggit/TabletManager.hpp>
|
||||||
#include <external/qtimgui/QtImGui.h>
|
#include <external/qtimgui/QtImGui.h>
|
||||||
#include <external/QtAdvancedDockingSystem/src/DockManager.h>
|
|
||||||
#include <opengl/texture.hpp>
|
#include <opengl/texture.hpp>
|
||||||
#include <opengl/scoped.hpp>
|
#include <opengl/scoped.hpp>
|
||||||
#include <optional>
|
#include <optional>
|
||||||
@@ -148,6 +147,7 @@ private:
|
|||||||
|
|
||||||
int _selected_area_id = -1;
|
int _selected_area_id = -1;
|
||||||
|
|
||||||
|
[[nodiscard]]
|
||||||
math::ray intersect_ray() const;
|
math::ray intersect_ray() const;
|
||||||
selection_result intersect_result(bool terrain_only);
|
selection_result intersect_result(bool terrain_only);
|
||||||
void doSelection(bool selectTerrainOnly, bool mouseMove = false);
|
void doSelection(bool selectTerrainOnly, bool mouseMove = false);
|
||||||
@@ -155,7 +155,10 @@ private:
|
|||||||
|
|
||||||
display_mode _display_mode;
|
display_mode _display_mode;
|
||||||
|
|
||||||
|
[[nodiscard]]
|
||||||
glm::mat4x4 model_view() const;
|
glm::mat4x4 model_view() const;
|
||||||
|
|
||||||
|
[[nodiscard]]
|
||||||
glm::mat4x4 projection() const;
|
glm::mat4x4 projection() const;
|
||||||
|
|
||||||
void draw_map();
|
void draw_map();
|
||||||
@@ -246,7 +249,6 @@ public:
|
|||||||
void change_selected_wmo_doodadset(int set);
|
void change_selected_wmo_doodadset(int set);
|
||||||
void saveMinimap(MinimapRenderSettings* settings);
|
void saveMinimap(MinimapRenderSettings* settings);
|
||||||
void initMinimapSave() { saving_minimap = true; };
|
void initMinimapSave() { saving_minimap = true; };
|
||||||
auto populateImageModel(QStandardItemModel* model) const -> void;
|
|
||||||
auto setBrushTexture(QImage const* img) -> void;
|
auto setBrushTexture(QImage const* img) -> void;
|
||||||
Noggit::Camera* getCamera() { return &_camera; };
|
Noggit::Camera* getCamera() { return &_camera; };
|
||||||
void randomizeTerrainRotation();
|
void randomizeTerrainRotation();
|
||||||
@@ -254,17 +256,29 @@ public:
|
|||||||
void randomizeShaderRotation();
|
void randomizeShaderRotation();
|
||||||
void randomizeStampRotation();
|
void randomizeStampRotation();
|
||||||
void onSettingsSave();
|
void onSettingsSave();
|
||||||
|
|
||||||
|
[[nodiscard]]
|
||||||
Noggit::Ui::minimap_widget* getMinimapWidget() const { return _minimap; }
|
Noggit::Ui::minimap_widget* getMinimapWidget() const { return _minimap; }
|
||||||
|
|
||||||
void set_editing_mode (editing_mode);
|
void set_editing_mode (editing_mode);
|
||||||
editing_mode get_editing_mode() { return terrainMode; };
|
editing_mode get_editing_mode() { return terrainMode; };
|
||||||
|
|
||||||
|
[[nodiscard]]
|
||||||
QWidget* getActiveStampModeItem();
|
QWidget* getActiveStampModeItem();
|
||||||
|
|
||||||
|
[[nodiscard]]
|
||||||
Noggit::NoggitRenderContext getRenderContext() { return _context; };
|
Noggit::NoggitRenderContext getRenderContext() { return _context; };
|
||||||
|
|
||||||
|
[[nodiscard]]
|
||||||
World* getWorld() { return _world.get(); };
|
World* getWorld() { return _world.get(); };
|
||||||
|
|
||||||
|
[[nodiscard]]
|
||||||
QDockWidget* getAssetBrowser() {return _asset_browser_dock; };
|
QDockWidget* getAssetBrowser() {return _asset_browser_dock; };
|
||||||
|
|
||||||
|
[[nodiscard]]
|
||||||
Noggit::Ui::object_editor* getObjectEditor() { return objectEditor; };
|
Noggit::Ui::object_editor* getObjectEditor() { return objectEditor; };
|
||||||
|
|
||||||
|
[[nodiscard]]
|
||||||
QDockWidget* getObjectPalette() { return _object_palette_dock; };
|
QDockWidget* getObjectPalette() { return _object_palette_dock; };
|
||||||
|
|
||||||
|
|
||||||
@@ -360,7 +374,7 @@ private:
|
|||||||
|
|
||||||
void setToolPropertyWidgetVisibility(editing_mode mode);
|
void setToolPropertyWidgetVisibility(editing_mode mode);
|
||||||
|
|
||||||
void unloadOpenglData(bool from_manager = false) override;
|
void unloadOpenglData() override;
|
||||||
|
|
||||||
Noggit::Ui::help* _keybindings;
|
Noggit::Ui::help* _keybindings;
|
||||||
Noggit::Ui::tileset_chooser* TexturePalette;
|
Noggit::Ui::tileset_chooser* TexturePalette;
|
||||||
@@ -397,7 +411,7 @@ private:
|
|||||||
ImGuizmo::MODE _gizmo_mode = ImGuizmo::MODE::WORLD;
|
ImGuizmo::MODE _gizmo_mode = ImGuizmo::MODE::WORLD;
|
||||||
ImGuizmo::OPERATION _gizmo_operation = ImGuizmo::OPERATION::TRANSLATE;
|
ImGuizmo::OPERATION _gizmo_operation = ImGuizmo::OPERATION::TRANSLATE;
|
||||||
Noggit::BoolToggleProperty _gizmo_on = {true};
|
Noggit::BoolToggleProperty _gizmo_on = {true};
|
||||||
QMetaObject::Connection _gl_guard_connection;
|
|
||||||
bool _gl_initialized = false;
|
bool _gl_initialized = false;
|
||||||
bool _destroying = false;
|
bool _destroying = false;
|
||||||
bool _needs_redraw = false;
|
bool _needs_redraw = false;
|
||||||
|
|||||||
@@ -455,115 +455,17 @@ void blp_texture::finishLoading()
|
|||||||
namespace Noggit
|
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
|
QPixmap* BLPRenderer::render_blp_to_pixmap ( std::string const& blp_filename
|
||||||
, int width
|
, int width
|
||||||
, int height
|
, int height
|
||||||
)
|
)
|
||||||
{
|
{
|
||||||
|
if (!_uploaded)
|
||||||
|
[[unlikely]]
|
||||||
|
{
|
||||||
|
upload();
|
||||||
|
}
|
||||||
|
|
||||||
std::tuple<std::string, int, int> const curEntry{blp_filename, width, height};
|
std::tuple<std::string, int, int> const curEntry{blp_filename, width, height};
|
||||||
auto it{_cache.find(curEntry)};
|
auto it{_cache.find(curEntry)};
|
||||||
|
|
||||||
@@ -572,9 +474,9 @@ namespace Noggit
|
|||||||
|
|
||||||
OpenGL::context::save_current_context const context_save (::gl);
|
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);
|
gl.activeTexture(GL_TEXTURE0);
|
||||||
blp_texture texture(blp_filename, Noggit::NoggitRenderContext::BLP_RENDERER);
|
blp_texture texture(blp_filename, Noggit::NoggitRenderContext::BLP_RENDERER);
|
||||||
@@ -587,7 +489,7 @@ namespace Noggit
|
|||||||
float h = static_cast<float>(height);
|
float h = static_cast<float>(height);
|
||||||
float w = static_cast<float>(width);
|
float w = static_cast<float>(width);
|
||||||
|
|
||||||
QOpenGLFramebufferObject pixel_buffer(width, height, _fmt);
|
QOpenGLFramebufferObject pixel_buffer(width, height, *_fmt.get());
|
||||||
pixel_buffer.bind();
|
pixel_buffer.bind();
|
||||||
|
|
||||||
gl.viewport(0, 0, w, h);
|
gl.viewport(0, 0, w, h);
|
||||||
@@ -622,10 +524,131 @@ namespace Noggit
|
|||||||
return &(_cache[curEntry] = std::move(result));
|
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)
|
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();
|
return _blp_texture.get();
|
||||||
}
|
}
|
||||||
|
|
||||||
blp_texture* scoped_blp_texture_reference::get() const
|
blp_texture* scoped_blp_texture_reference::get() const
|
||||||
{
|
{
|
||||||
return _blp_texture.get();
|
return _blp_texture.get();
|
||||||
|
|||||||
@@ -144,21 +144,23 @@ namespace Noggit
|
|||||||
class BLPRenderer
|
class BLPRenderer
|
||||||
{
|
{
|
||||||
private:
|
private:
|
||||||
BLPRenderer();
|
BLPRenderer() = default;
|
||||||
|
|
||||||
BLPRenderer( const BLPRenderer&);
|
BLPRenderer( const BLPRenderer&) = delete;
|
||||||
BLPRenderer& operator=( BLPRenderer& );
|
BLPRenderer& operator=( BLPRenderer& ) = delete;
|
||||||
|
|
||||||
std::map<std::tuple<std::string, int, int>, QPixmap> _cache;
|
std::map<std::tuple<std::string, int, int>, QPixmap> _cache;
|
||||||
|
|
||||||
QOpenGLContext _context;
|
std::unique_ptr<QOpenGLContext> _context;
|
||||||
QOpenGLFramebufferObjectFormat _fmt;
|
std::unique_ptr<QOpenGLFramebufferObjectFormat> _fmt;
|
||||||
QOffscreenSurface _surface;
|
std::unique_ptr<QOffscreenSurface> _surface;
|
||||||
std::unique_ptr<OpenGL::program> _program;
|
std::unique_ptr<OpenGL::program> _program;
|
||||||
|
|
||||||
OpenGL::Scoped::deferred_upload_vertex_arrays<1> _vao;
|
OpenGL::Scoped::deferred_upload_vertex_arrays<1> _vao;
|
||||||
OpenGL::Scoped::deferred_upload_buffers<3> _buffers;
|
OpenGL::Scoped::deferred_upload_buffers<3> _buffers;
|
||||||
|
|
||||||
|
bool _uploaded = false;
|
||||||
|
|
||||||
public:
|
public:
|
||||||
static BLPRenderer& getInstance()
|
static BLPRenderer& getInstance()
|
||||||
{
|
{
|
||||||
@@ -166,9 +168,9 @@ namespace Noggit
|
|||||||
return instance;
|
return instance;
|
||||||
}
|
}
|
||||||
|
|
||||||
~BLPRenderer();
|
|
||||||
|
|
||||||
QPixmap* render_blp_to_pixmap ( std::string const& blp_filename, int width = -1, int height = -1);
|
QPixmap* render_blp_to_pixmap ( std::string const& blp_filename, int width = -1, int height = -1);
|
||||||
|
void unload();
|
||||||
|
void upload();
|
||||||
|
|
||||||
};
|
};
|
||||||
|
|
||||||
|
|||||||
@@ -48,7 +48,7 @@ public:
|
|||||||
, int animtime
|
, int animtime
|
||||||
, int layer
|
, int layer
|
||||||
, display_mode display
|
, display_mode display
|
||||||
, LiquidTextureManager* tex_manager
|
, Noggit::Rendering::LiquidTextureManager* tex_manager
|
||||||
);
|
);
|
||||||
bool hasData(size_t layer);
|
bool hasData(size_t layer);
|
||||||
bool hasData() { return _has_data; };
|
bool hasData() { return _has_data; };
|
||||||
|
|||||||
@@ -15,11 +15,11 @@ namespace math
|
|||||||
}
|
}
|
||||||
|
|
||||||
class MapTile;
|
class MapTile;
|
||||||
class LiquidTextureManager;
|
|
||||||
|
|
||||||
|
|
||||||
namespace Noggit::Rendering
|
namespace Noggit::Rendering
|
||||||
{
|
{
|
||||||
|
class LiquidTextureManager;
|
||||||
|
|
||||||
struct LiquidLayerDrawCallData
|
struct LiquidLayerDrawCallData
|
||||||
{
|
{
|
||||||
|
|||||||
@@ -5,6 +5,8 @@
|
|||||||
#include "noggit/DBC.h"
|
#include "noggit/DBC.h"
|
||||||
#include "noggit/application/NoggitApplication.hpp"
|
#include "noggit/application/NoggitApplication.hpp"
|
||||||
|
|
||||||
|
using namespace Noggit::Rendering;
|
||||||
|
|
||||||
LiquidTextureManager::LiquidTextureManager(Noggit::NoggitRenderContext context)
|
LiquidTextureManager::LiquidTextureManager(Noggit::NoggitRenderContext context)
|
||||||
: _context(context)
|
: _context(context)
|
||||||
{
|
{
|
||||||
|
|||||||
@@ -3,13 +3,14 @@
|
|||||||
#ifndef NOGGIT_LIQUIDTEXTUREMANAGER_HPP
|
#ifndef NOGGIT_LIQUIDTEXTUREMANAGER_HPP
|
||||||
#define NOGGIT_LIQUIDTEXTUREMANAGER_HPP
|
#define NOGGIT_LIQUIDTEXTUREMANAGER_HPP
|
||||||
|
|
||||||
#include "noggit/TextureManager.h"
|
#include <noggit/TextureManager.h>
|
||||||
#include "noggit/ContextObject.hpp"
|
#include <noggit/ContextObject.hpp>
|
||||||
#include "external/tsl/robin_map.h"
|
#include <external/tsl/robin_map.h>
|
||||||
|
|
||||||
#include <tuple>
|
#include <tuple>
|
||||||
#include "external/glm/vec2.hpp"
|
#include <external/glm/vec2.hpp>
|
||||||
|
|
||||||
|
/*
|
||||||
template<typename ... Args>
|
template<typename ... Args>
|
||||||
std::string string_format(const std::string& format, Args ... 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 ...);
|
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
|
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);
|
explicit LiquidTextureManager(Noggit::NoggitRenderContext context);
|
||||||
LiquidTextureManager() = delete;
|
LiquidTextureManager() = delete;
|
||||||
|
|
||||||
void upload();
|
void upload();
|
||||||
void unload();
|
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:
|
private:
|
||||||
bool _uploaded = false;
|
bool _uploaded = false;
|
||||||
|
|
||||||
// liquidTypeRecID : (array, (animation_x, animation_y), liquid_type)
|
// liquidTypeRecID : (array, (animation_x, animation_y), liquid_type)
|
||||||
tsl::robin_map<unsigned, std::tuple<GLuint, glm::vec2, int, unsigned>> _texture_frames_map;
|
tsl::robin_map<unsigned, std::tuple<GLuint, glm::vec2, int, unsigned>> _texture_frames_map;
|
||||||
|
|
||||||
|
Noggit::NoggitRenderContext _context;
|
||||||
|
};
|
||||||
|
|
||||||
|
}
|
||||||
|
|
||||||
Noggit::NoggitRenderContext _context;
|
|
||||||
};
|
|
||||||
|
|
||||||
#endif //NOGGIT_LIQUIDTEXTUREMANAGER_HPP
|
#endif //NOGGIT_LIQUIDTEXTUREMANAGER_HPP
|
||||||
|
|||||||
@@ -184,6 +184,11 @@ void ModelViewer::initializeGL()
|
|||||||
AssetBrowser::ModelViewer::initializeGL();
|
AssetBrowser::ModelViewer::initializeGL();
|
||||||
_imgui_context = QtImGui::initialize(this);
|
_imgui_context = QtImGui::initialize(this);
|
||||||
|
|
||||||
|
connect(context(), &QOpenGLContext::aboutToBeDestroyed, [=]()
|
||||||
|
{
|
||||||
|
emit aboutToLooseContext();
|
||||||
|
});
|
||||||
|
|
||||||
}
|
}
|
||||||
|
|
||||||
|
|
||||||
|
|||||||
@@ -529,21 +529,7 @@ PreviewRenderer::~PreviewRenderer()
|
|||||||
_m2_box_program.reset();
|
_m2_box_program.reset();
|
||||||
_wmo_program.reset();
|
_wmo_program.reset();
|
||||||
|
|
||||||
}
|
unload();
|
||||||
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();
|
|
||||||
}
|
}
|
||||||
|
|
||||||
}
|
}
|
||||||
@@ -708,12 +694,11 @@ void PreviewRenderer::unload()
|
|||||||
|
|
||||||
}
|
}
|
||||||
|
|
||||||
void PreviewRenderer::unloadOpenglData(bool from_manager)
|
void PreviewRenderer::unloadOpenglData()
|
||||||
{
|
{
|
||||||
if (_offscreen_mode)
|
if (_offscreen_mode)
|
||||||
return;
|
return;
|
||||||
|
|
||||||
LogDebug << "Changing context of Asset Browser / Preset Editor." << std::endl;
|
|
||||||
makeCurrent();
|
makeCurrent();
|
||||||
OpenGL::context::scoped_setter const _ (::gl, context());
|
OpenGL::context::scoped_setter const _ (::gl, context());
|
||||||
|
|
||||||
@@ -722,11 +707,6 @@ void PreviewRenderer::unloadOpenglData(bool from_manager)
|
|||||||
TextureManager::unload_all(_context);
|
TextureManager::unload_all(_context);
|
||||||
|
|
||||||
unload();
|
unload();
|
||||||
|
|
||||||
LogDebug << "Changed context of Asset Browser / Preset Editor.." << std::endl;
|
|
||||||
|
|
||||||
if (!from_manager)
|
|
||||||
ViewportManager::ViewportManager::unloadOpenglData(this);
|
|
||||||
}
|
}
|
||||||
|
|
||||||
void Noggit::Ui::Tools::PreviewRenderer::updateLightingUniformBlock()
|
void Noggit::Ui::Tools::PreviewRenderer::updateLightingUniformBlock()
|
||||||
|
|||||||
@@ -87,7 +87,7 @@ class PreviewRenderer : public Noggit::Ui::Tools::ViewportManager::Viewport
|
|||||||
|
|
||||||
void unload();
|
void unload();
|
||||||
|
|
||||||
void unloadOpenglData(bool from_manager = false) override;
|
void unloadOpenglData() override;
|
||||||
|
|
||||||
void updateLightingUniformBlock();
|
void updateLightingUniformBlock();
|
||||||
|
|
||||||
@@ -115,7 +115,7 @@ class PreviewRenderer : public Noggit::Ui::Tools::ViewportManager::Viewport
|
|||||||
OpenGL::MVPUniformBlock _mvp_ubo_data;
|
OpenGL::MVPUniformBlock _mvp_ubo_data;
|
||||||
OpenGL::LightingUniformBlock _lighting_ubo_data;
|
OpenGL::LightingUniformBlock _lighting_ubo_data;
|
||||||
|
|
||||||
LiquidTextureManager _liquid_texture_manager;
|
Noggit::Rendering::LiquidTextureManager _liquid_texture_manager;
|
||||||
|
|
||||||
bool _uploaded = false;
|
bool _uploaded = false;
|
||||||
bool _lighting_needs_update = true;
|
bool _lighting_needs_update = true;
|
||||||
|
|||||||
@@ -1,4 +1,5 @@
|
|||||||
#include "ViewportManager.hpp"
|
#include "ViewportManager.hpp"
|
||||||
|
#include <noggit/TextureManager.h>
|
||||||
|
|
||||||
using namespace Noggit::Ui::Tools::ViewportManager;
|
using namespace Noggit::Ui::Tools::ViewportManager;
|
||||||
|
|
||||||
@@ -8,6 +9,11 @@ Viewport::Viewport(QWidget* parent)
|
|||||||
: QOpenGLWidget(parent)
|
: QOpenGLWidget(parent)
|
||||||
{
|
{
|
||||||
ViewportManager::registerViewport(this);
|
ViewportManager::registerViewport(this);
|
||||||
|
_gl_connection = connect(this, &Viewport::aboutToLooseContext, [this]()
|
||||||
|
{
|
||||||
|
ViewportManager::unloadOpenglData(this);
|
||||||
|
});
|
||||||
|
|
||||||
}
|
}
|
||||||
|
|
||||||
Viewport::~Viewport()
|
Viewport::~Viewport()
|
||||||
@@ -22,6 +28,16 @@ void ViewportManager::unloadOpenglData(Viewport* caller)
|
|||||||
if (viewport == caller)
|
if (viewport == caller)
|
||||||
continue;
|
continue;
|
||||||
|
|
||||||
viewport->unloadOpenglData(true);
|
viewport->unloadOpenglData();
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
|
void ViewportManager::unloadAll()
|
||||||
|
{
|
||||||
|
for (auto viewport : ViewportManager::_viewports)
|
||||||
|
{
|
||||||
|
viewport->unloadOpenglData();
|
||||||
|
}
|
||||||
|
|
||||||
|
BLPRenderer::getInstance().unload();
|
||||||
|
}
|
||||||
|
|||||||
@@ -5,52 +5,59 @@
|
|||||||
#include <vector>
|
#include <vector>
|
||||||
#include <noggit/ContextObject.hpp>
|
#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;
|
ViewportManager::_viewports.push_back(viewport);
|
||||||
class ViewportManager
|
};
|
||||||
|
|
||||||
|
static void unregisterViewport(Viewport* viewport)
|
||||||
|
{
|
||||||
|
for (auto it = ViewportManager::_viewports.begin(); it != ViewportManager::_viewports.end(); ++it)
|
||||||
|
{
|
||||||
|
if (viewport == *it)
|
||||||
{
|
{
|
||||||
public:
|
ViewportManager::_viewports.erase(it);
|
||||||
static std::vector<Viewport*> _viewports;
|
break;
|
||||||
|
}
|
||||||
|
}
|
||||||
|
};
|
||||||
|
|
||||||
static void registerViewport(Viewport* viewport)
|
static void unloadOpenglData(Viewport* caller);
|
||||||
{
|
static void unloadAll();
|
||||||
ViewportManager::_viewports.push_back(viewport);
|
};
|
||||||
};
|
|
||||||
|
|
||||||
static void unregisterViewport(Viewport* viewport)
|
class Viewport : public QOpenGLWidget
|
||||||
{
|
{
|
||||||
for(auto it = ViewportManager::_viewports.begin(); it != ViewportManager::_viewports.end(); ++it)
|
Q_OBJECT
|
||||||
{
|
|
||||||
if (viewport == *it)
|
|
||||||
{
|
|
||||||
ViewportManager::_viewports.erase(it);
|
|
||||||
break;
|
|
||||||
}
|
|
||||||
}
|
|
||||||
};
|
|
||||||
|
|
||||||
static void unloadOpenglData(Viewport* caller);
|
public:
|
||||||
};
|
Viewport(QWidget* parent = nullptr);
|
||||||
|
|
||||||
class Viewport : public QOpenGLWidget
|
virtual void unloadOpenglData() = 0;
|
||||||
{
|
|
||||||
public:
|
|
||||||
Viewport(QWidget* parent = nullptr);
|
|
||||||
virtual void unloadOpenglData(bool from_manager = false) = 0;
|
|
||||||
Noggit::NoggitRenderContext getRenderContext() { return _context; };
|
|
||||||
|
|
||||||
~Viewport();
|
Noggit::NoggitRenderContext getRenderContext()
|
||||||
|
{ return _context; };
|
||||||
|
|
||||||
protected:
|
~Viewport();
|
||||||
Noggit::NoggitRenderContext _context;
|
|
||||||
};
|
signals:
|
||||||
|
void aboutToLooseContext();
|
||||||
|
|
||||||
|
protected:
|
||||||
|
Noggit::NoggitRenderContext _context;
|
||||||
|
QMetaObject::Connection _gl_connection;
|
||||||
|
};
|
||||||
|
|
||||||
}
|
|
||||||
}
|
}
|
||||||
|
|
||||||
|
|
||||||
|
|
||||||
#endif //NOGGIT_VIEWPORTMANAGER_HPP
|
#endif //NOGGIT_VIEWPORTMANAGER_HPP
|
||||||
|
|||||||
@@ -45,6 +45,7 @@
|
|||||||
|
|
||||||
#include "ui_TitleBar.h"
|
#include "ui_TitleBar.h"
|
||||||
#include <external/framelesshelper/framelesswindowsmanager.h>
|
#include <external/framelesshelper/framelesswindowsmanager.h>
|
||||||
|
#include <noggit/ui/tools/ViewportManager/ViewportManager.hpp>
|
||||||
|
|
||||||
namespace Noggit::Ui::Windows
|
namespace Noggit::Ui::Windows
|
||||||
{
|
{
|
||||||
@@ -371,6 +372,7 @@ namespace Noggit::Ui::Windows
|
|||||||
map_loaded = false;
|
map_loaded = false;
|
||||||
break;
|
break;
|
||||||
case QMessageBox::DestructiveRole:
|
case QMessageBox::DestructiveRole:
|
||||||
|
Noggit::Ui::Tools::ViewportManager::ViewportManager::unloadAll();
|
||||||
setCentralWidget(_null_widget = new QWidget(this));
|
setCentralWidget(_null_widget = new QWidget(this));
|
||||||
event->accept();
|
event->accept();
|
||||||
break;
|
break;
|
||||||
|
|||||||
Reference in New Issue
Block a user