slowly start bringing back minimap renderer

This commit is contained in:
Skarn
2021-11-14 01:54:41 +03:00
parent 1618c56c62
commit 484fc38d82
6 changed files with 64 additions and 19 deletions

View File

@@ -611,5 +611,4 @@ target_link_libraries (noggit
FastNoise
nlohmann_json::nlohmann_json
sol2::sane
dl
)

View File

@@ -38,8 +38,8 @@ public:
explicit ModelInstance(std::string const& filename, ENTRY_MDDF const*d, noggit::NoggitRenderContext context);
ModelInstance(ModelInstance const& other) = delete;
ModelInstance& operator= (ModelInstance const& other) = delete;
ModelInstance(ModelInstance const& other) = default;
ModelInstance& operator= (ModelInstance const& other) = default;
ModelInstance (ModelInstance&& other)
: SceneObject(other._type, other._context, other._filename)

View File

@@ -508,7 +508,7 @@ DECLARE_NODE_DATA_TYPE_EXT(json_array, JSONArray, QJsonArray, NoDefaultWidget, t
DECLARE_NODE_DATA_TYPE_EXT(json_value, JSONValue, QJsonValue, NoDefaultWidget, toQStringNA);
#define CREATE_DATA_PAIR(TYPE_ID, TYPE_NAME) \
std::pair{#TYPE_ID ##sv, &_create<TYPE_NAME##Data>}
std::make_pair(#TYPE_ID ##sv, &_create<TYPE_NAME##Data>)
struct TypeFactory
{

View File

@@ -1048,6 +1048,7 @@ void World::draw ( math::matrix_4x4 const& model_view
, int water_layer
, display_mode display
, bool draw_occlusion_boxes
, bool minimap_render
)
{
@@ -1061,12 +1062,29 @@ void World::draw ( math::matrix_4x4 const& model_view
gl.disable(GL_DEPTH_TEST);
updateLightingUniformBlock(draw_fog, camera_pos);
if (!minimap_render)
updateLightingUniformBlock(draw_fog, camera_pos);
else
updateLightingUniformBlockMinimap(minimap_render_settings);
// setup render settings for minimap
if (minimap_render)
{
_terrain_params_ubo_data.draw_shadows = minimap_render_settings->draw_shadows;
_terrain_params_ubo_data.draw_lines = minimap_render_settings->draw_adt_grid;
_terrain_params_ubo_data.draw_terrain_height_contour = minimap_render_settings->draw_elevation;
_terrain_params_ubo_data.draw_hole_lines = false;
_terrain_params_ubo_data.draw_impass_overlay = false;
_terrain_params_ubo_data.draw_areaid_overlay = false;
_terrain_params_ubo_data.draw_paintability_overlay = false;
_terrain_params_ubo_data.draw_selection_overlay = false;
_terrain_params_ubo_data.draw_wireframe = false;
_need_terrain_params_ubo_update = true;
}
if (_need_terrain_params_ubo_update)
updateTerrainParamsUniformBlock();
// Frustum culling
_n_loaded_tiles = 0;
unsigned tile_counter = 0;
@@ -1107,17 +1125,9 @@ void World::draw ( math::matrix_4x4 const& model_view
_n_loaded_tiles++;
}
assert(tile_counter <= _loaded_tiles_buffer.size());
auto buf_end = _loaded_tiles_buffer.end();
auto buf_end = _loaded_tiles_buffer.begin() + tile_counter;
_loaded_tiles_buffer[tile_counter] = nullptr;
if (tile_counter < _loaded_tiles_buffer.size())
{
// nullptr should act as the data terminator, similar to null-terminator in strings
// the items that follow are undefined
_loaded_tiles_buffer[tile_counter] = nullptr;
buf_end = _loaded_tiles_buffer.begin() + tile_counter;
}
// It is always import to sort tiles __front to back__.
// Otherwise selection would not work. Overdraw overhead is gonna occur as well.
@@ -1139,7 +1149,7 @@ void World::draw ( math::matrix_4x4 const& model_view
});
// only draw the sky in 3D
if(display == display_mode::in_3D)
if(!minimap_render && display == display_mode::in_3D)
{
ZoneScopedN("World::draw() : Draw skies");
opengl::scoped::use_program m2_shader {*_m2_program.get()};
@@ -1821,7 +1831,7 @@ selection_result World::intersect ( math::matrix_4x4 const& model_view
if (!tile)
break;
if (!tile->finishedLoading())
if (!tile->finishedLoading()) // TODO: crash
continue;
if (tile->intersect(ray, &results))
@@ -2318,6 +2328,16 @@ void World::drawMinimap ( MapTile *tile
{
ZoneScoped;
// Also load a tile above the current one to correct the lookat approximation
tile_index m_tile = tile_index(camera_pos);
m_tile.z -= 1;
MapTile* mTile = mapIndex.loadTile(m_tile);
draw(model_view, projection, math::vector_3d{}, 0, math::vector_4d{},
CursorType::NONE, 0.f, false, 0.f, math::vector_3d{}, 0.f, 0.f, false, false, false, editing_mode::minimap, camera_pos, true, false, true, settings->draw_wmo, settings->draw_water, false, settings->draw_m2, false, false, true, settings, false, eTerrainType::eTerrainType_Linear, 0, display_mode::in_3D, false, true);
/*
if (!_display_initialized)
@@ -2680,7 +2700,7 @@ bool World::saveMinimap(tile_index const& tile_idx, MinimapRenderSettings* setti
if (AsyncLoader::instance().is_loading())
{
return false;
//return false;
}
float max_height = getMaxTileHeight(tile_idx);
@@ -2794,10 +2814,13 @@ bool World::saveMinimap(tile_index const& tile_idx, MinimapRenderSettings* setti
std::string tilename_left = (boost::format("%s\\map_%d_%02d.blp") % map_name % tile_idx.x % tile_idx.z).str();
mapIndex._minimap_md5translate[map_name][tilename_left] = tex_name;
/*
if (unload)
{
mapIndex.unloadTile(tile_idx);
}
*/
}
pixel_buffer.release();
@@ -4504,6 +4527,26 @@ void World::updateLightingUniformBlock(bool draw_fog, math::vector_3d const& cam
gl.bufferSubData(GL_UNIFORM_BUFFER, 0, sizeof(opengl::LightingUniformBlock), &_lighting_ubo_data);
}
void World::updateLightingUniformBlockMinimap(MinimapRenderSettings* settings)
{
ZoneScoped;
math::vector_3d diffuse = settings->diffuse_color;
math::vector_3d ambient = settings->ambient_color;
_lighting_ubo_data.DiffuseColor_FogStart = { diffuse, 0 };
_lighting_ubo_data.AmbientColor_FogEnd = { ambient, 0 };
_lighting_ubo_data.FogColor_FogOn = { 0, 0, 0, 0 };
_lighting_ubo_data.LightDir_FogRate = { outdoorLightStats.dayDir.x, outdoorLightStats.dayDir.y, outdoorLightStats.dayDir.z, skies->fogRate() };
_lighting_ubo_data.OceanColorLight = settings->ocean_color_light;
_lighting_ubo_data.OceanColorDark = settings->ocean_color_dark;
_lighting_ubo_data.RiverColorLight = settings->river_color_light;
_lighting_ubo_data.RiverColorDark = settings->river_color_dark;
gl.bindBuffer(GL_UNIFORM_BUFFER, _lighting_ubo);
gl.bufferSubData(GL_UNIFORM_BUFFER, 0, sizeof(opengl::LightingUniformBlock), &_lighting_ubo_data);
}
void World::updateTerrainParamsUniformBlock()
{
ZoneScoped;

View File

@@ -128,6 +128,7 @@ public:
, int water_layer
, display_mode display
, bool draw_occlusion_boxes = false
, bool minimap_render = false
);
unsigned int getAreaID (math::vector_3d const&);
@@ -418,6 +419,7 @@ private:
void updateMVPUniformBlock(const math::matrix_4x4& model_view, const math::matrix_4x4& projection);
void updateLightingUniformBlock(bool draw_fog, math::vector_3d const& camera_pos);
void updateLightingUniformBlockMinimap(MinimapRenderSettings* settings);
std::unordered_set<MapChunk*>& vertexBorderChunks();

View File

@@ -6,6 +6,7 @@
#include <math/matrix_4x4.hpp>
#include <math/vector_4d.hpp>
#include <cstdint>
#include <array>
namespace opengl
{