move M2 rendering to its own entities | Update MapView.cpp, Model.cpp, and 9 more files...
This commit is contained in:
@@ -2815,7 +2815,12 @@ void MapView::saveMinimap(MinimapRenderSettings* settings)
|
||||
|
||||
_main_window->statusBar()->addPermanentWidget(cancel_btn);
|
||||
|
||||
//connect(this, &MapView::updateProgress, progress, &QProgressBar::setValue);
|
||||
connect(this, &MapView::updateProgress,
|
||||
[=](int value)
|
||||
{
|
||||
|
||||
progress->setValue(value);
|
||||
});
|
||||
|
||||
// setup combined image if necessary
|
||||
if (settings->combined_minimap)
|
||||
@@ -2920,7 +2925,15 @@ void MapView::saveMinimap(MinimapRenderSettings* settings)
|
||||
|
||||
_main_window->statusBar()->addPermanentWidget(cancel_btn);
|
||||
|
||||
connect(this, &MapView::updateProgress, progress, &QProgressBar::setValue);
|
||||
connect(this, &MapView::updateProgress,
|
||||
[=](int value)
|
||||
{
|
||||
// This weirdness is required due to a bug on Linux when QT repaint crashes due to too many events
|
||||
// being passed through. TODO: this potentially only masks the issue, which may reappear on faster
|
||||
// hardware.
|
||||
if (progress->value() != value)
|
||||
progress->setValue(value);
|
||||
});
|
||||
|
||||
// setup combined image if necessary
|
||||
if (settings->combined_minimap)
|
||||
|
||||
1037
src/noggit/Model.cpp
1037
src/noggit/Model.cpp
File diff suppressed because it is too large
Load Diff
@@ -17,6 +17,7 @@
|
||||
#include <optional>
|
||||
#include <string>
|
||||
#include <vector>
|
||||
#include <noggit/rendering/ModelRender.hpp>
|
||||
|
||||
class Bone;
|
||||
class Model;
|
||||
@@ -24,6 +25,12 @@ class ModelInstance;
|
||||
class ParticleSystem;
|
||||
class RibbonEmitter;
|
||||
|
||||
namespace Noggit::Rendering
|
||||
{
|
||||
class ModelRender;
|
||||
struct ModelRenderPass;
|
||||
}
|
||||
|
||||
|
||||
glm::vec3 fixCoordSystem(glm::vec3 v);
|
||||
|
||||
@@ -97,89 +104,6 @@ struct ModelTransparency {
|
||||
};
|
||||
|
||||
|
||||
enum class M2Blend : uint16_t
|
||||
{
|
||||
Opaque,
|
||||
Alpha_Key,
|
||||
Alpha,
|
||||
No_Add_Alpha,
|
||||
Add,
|
||||
Mod,
|
||||
Mod2x
|
||||
};
|
||||
|
||||
enum class ModelPixelShader : uint16_t
|
||||
{
|
||||
Combiners_Opaque,
|
||||
Combiners_Decal,
|
||||
Combiners_Add,
|
||||
Combiners_Mod2x,
|
||||
Combiners_Fade,
|
||||
Combiners_Mod,
|
||||
Combiners_Opaque_Opaque,
|
||||
Combiners_Opaque_Add,
|
||||
Combiners_Opaque_Mod2x,
|
||||
Combiners_Opaque_Mod2xNA,
|
||||
Combiners_Opaque_AddNA,
|
||||
Combiners_Opaque_Mod,
|
||||
Combiners_Mod_Opaque,
|
||||
Combiners_Mod_Add,
|
||||
Combiners_Mod_Mod2x,
|
||||
Combiners_Mod_Mod2xNA,
|
||||
Combiners_Mod_AddNA,
|
||||
Combiners_Mod_Mod,
|
||||
Combiners_Add_Mod,
|
||||
Combiners_Mod2x_Mod2x,
|
||||
Combiners_Opaque_Mod2xNA_Alpha,
|
||||
Combiners_Opaque_AddAlpha,
|
||||
Combiners_Opaque_AddAlpha_Alpha,
|
||||
};
|
||||
|
||||
enum class texture_unit_lookup : int
|
||||
{
|
||||
environment,
|
||||
t1,
|
||||
t2,
|
||||
none
|
||||
};
|
||||
|
||||
|
||||
struct ModelRenderPass : ModelTexUnit
|
||||
{
|
||||
ModelRenderPass() = delete;
|
||||
ModelRenderPass(ModelTexUnit const& tex_unit, Model* m);
|
||||
|
||||
float ordering_thingy = 0.f;
|
||||
uint16_t index_start = 0, index_count = 0, vertex_start = 0, vertex_end = 0;
|
||||
uint16_t blend_mode = 0;
|
||||
texture_unit_lookup tu_lookups[2];
|
||||
uint16_t textures[2];
|
||||
uint16_t uv_animations[2];
|
||||
std::optional<ModelPixelShader> pixel_shader;
|
||||
|
||||
|
||||
bool prepare_draw(OpenGL::Scoped::use_program& m2_shader, Model *m, OpenGL::M2RenderState& model_render_state);
|
||||
void after_draw();
|
||||
void bind_texture(size_t index, Model* m, OpenGL::M2RenderState& model_render_state, OpenGL::Scoped::use_program& m2_shader);
|
||||
void init_uv_types(Model* m);
|
||||
|
||||
bool operator< (const ModelRenderPass &m) const
|
||||
{
|
||||
if (priority_plane < m.priority_plane)
|
||||
{
|
||||
return true;
|
||||
}
|
||||
else if (priority_plane > m.priority_plane)
|
||||
{
|
||||
return false;
|
||||
}
|
||||
else
|
||||
{
|
||||
return blend_mode == m.blend_mode ? (ordering_thingy < m.ordering_thingy) : blend_mode < m.blend_mode;
|
||||
}
|
||||
}
|
||||
};
|
||||
|
||||
struct FakeGeometry
|
||||
{
|
||||
FakeGeometry(Model* m);
|
||||
@@ -202,6 +126,9 @@ struct ModelLight {
|
||||
|
||||
class Model : public AsyncObject
|
||||
{
|
||||
friend class Noggit::Rendering::ModelRender;
|
||||
friend struct Noggit::Rendering::ModelRenderPass;
|
||||
|
||||
public:
|
||||
template<typename T>
|
||||
static std::vector<T> M2Array(BlizzardArchive::ClientFile const& f, uint32_t offset, uint32_t count)
|
||||
@@ -212,40 +139,6 @@ public:
|
||||
|
||||
Model(const std::string& name, Noggit::NoggitRenderContext context );
|
||||
|
||||
void draw(glm::mat4x4 const& model_view
|
||||
, ModelInstance& instance
|
||||
, OpenGL::Scoped::use_program& m2_shader
|
||||
, OpenGL::M2RenderState& model_render_state
|
||||
, math::frustum const& frustum
|
||||
, const float& cull_distance
|
||||
, const glm::vec3& camera
|
||||
, int animtime
|
||||
, display_mode display
|
||||
, bool no_cull = false
|
||||
);
|
||||
void draw (glm::mat4x4 const& model_view
|
||||
, std::vector<glm::mat4x4> const& instances
|
||||
, OpenGL::Scoped::use_program& m2_shader
|
||||
, OpenGL::M2RenderState& model_render_state
|
||||
, math::frustum const& frustum
|
||||
, const float& cull_distance
|
||||
, const glm::vec3& camera
|
||||
, int animtime
|
||||
, bool all_boxes
|
||||
, std::unordered_map<Model*, std::size_t>& model_boxes_to_draw
|
||||
, display_mode display
|
||||
, bool no_cull = false
|
||||
);
|
||||
void draw_particles( glm::mat4x4 const& model_view
|
||||
, OpenGL::Scoped::use_program& particles_shader
|
||||
, std::size_t instance_count
|
||||
);
|
||||
void draw_ribbons( OpenGL::Scoped::use_program& ribbons_shader
|
||||
, std::size_t instance_count
|
||||
);
|
||||
|
||||
void draw_box (OpenGL::Scoped::use_program& m2_box_shader, std::size_t box_count);
|
||||
|
||||
std::vector<float> intersect (glm::mat4x4 const& model_view, math::ray const&, int animtime);
|
||||
|
||||
void updateEmitters(float dt);
|
||||
@@ -268,6 +161,9 @@ public:
|
||||
return true;
|
||||
}
|
||||
|
||||
[[nodiscard]]
|
||||
Noggit::Rendering::ModelRender* renderer() { return &_renderer; }
|
||||
|
||||
// ===============================
|
||||
// Toggles
|
||||
// ===============================
|
||||
@@ -295,8 +191,6 @@ public:
|
||||
float trans;
|
||||
bool animcalc;
|
||||
|
||||
void unload();
|
||||
|
||||
private:
|
||||
bool _per_instance_animation;
|
||||
int _current_anim_seq;
|
||||
@@ -309,42 +203,12 @@ private:
|
||||
bool isAnimated(const BlizzardArchive::ClientFile& f);
|
||||
void initAnimated(const BlizzardArchive::ClientFile& f);
|
||||
|
||||
void fix_shader_id_blend_override();
|
||||
void fix_shader_id_layer();
|
||||
void compute_pixel_shader_ids();
|
||||
|
||||
void animate(glm::mat4x4 const& model_view, int anim_id, int anim_time);
|
||||
void calcBones(glm::mat4x4 const& model_view, int anim, int time, int animation_time);
|
||||
|
||||
void lightsOn(OpenGL::light lbase);
|
||||
void lightsOff(OpenGL::light lbase);
|
||||
|
||||
void upload();
|
||||
void setupVAO(OpenGL::Scoped::use_program& m2_shader);
|
||||
|
||||
bool _finished_upload = false;
|
||||
bool _vao_setup = false;
|
||||
|
||||
std::vector<glm::vec3> _vertex_box_points;
|
||||
|
||||
// buffers
|
||||
OpenGL::Scoped::deferred_upload_buffers<6> _buffers;
|
||||
OpenGL::Scoped::deferred_upload_vertex_arrays<2> _vertex_arrays;
|
||||
|
||||
std::vector<uint16_t> const _box_indices = {5, 7, 3, 2, 0, 1, 3, 1, 5, 4, 0, 4, 6, 2, 6, 7};
|
||||
|
||||
GLuint const& _vao = _vertex_arrays[0];
|
||||
GLuint const& _transform_buffer = _buffers[0];
|
||||
GLuint const& _vertices_buffer = _buffers[1];
|
||||
GLuint const& _indices_buffer = _buffers[3];
|
||||
GLuint const& _box_indices_buffer = _buffers[4];
|
||||
GLuint const& _bone_matrices_buffer = _buffers[5];
|
||||
|
||||
GLuint const& _box_vao = _vertex_arrays[1];
|
||||
GLuint const& _box_vbo = _buffers[2];
|
||||
|
||||
GLuint _bone_matrices_buf_tex;
|
||||
|
||||
// ===============================
|
||||
// Geometry
|
||||
// ===============================
|
||||
@@ -354,7 +218,6 @@ private:
|
||||
|
||||
std::vector<uint16_t> _indices;
|
||||
|
||||
std::vector<ModelRenderPass> _render_passes;
|
||||
std::optional<FakeGeometry> _fake_geometry;
|
||||
|
||||
// ===============================
|
||||
@@ -384,8 +247,8 @@ private:
|
||||
std::vector<int16_t> _transparency_lookup;
|
||||
std::vector<ModelLight> _lights;
|
||||
|
||||
bool _hidden = false;
|
||||
Noggit::Rendering::ModelRender _renderer;
|
||||
|
||||
friend struct ModelRenderPass;
|
||||
bool _hidden = false;
|
||||
};
|
||||
|
||||
|
||||
@@ -1,7 +1,7 @@
|
||||
// This file is part of Noggit3, licensed under GNU General Public License (version 3).
|
||||
#pragma once
|
||||
#include <cstdint>
|
||||
#include <glm/vec2.hpp>
|
||||
#include <glm/glm.hpp>
|
||||
|
||||
#pragma pack(push,1)
|
||||
|
||||
|
||||
@@ -72,7 +72,7 @@ void ModelManager::unload_all(Noggit::NoggitRenderContext context)
|
||||
_.context_aware_apply(
|
||||
[&] (BlizzardArchive::Listfile::FileKey const&, Model& model)
|
||||
{
|
||||
model.unload();
|
||||
model.renderer()->unload();
|
||||
}
|
||||
, context
|
||||
);
|
||||
|
||||
@@ -518,7 +518,7 @@ bool Skies::draw(glm::mat4x4 const& model_view
|
||||
m2_shader.uniform("tex_unit_lookup_2", 0);
|
||||
m2_shader.uniform("pixel_shader", 0);
|
||||
|
||||
model.model->draw(model_view, model, m2_shader, model_render_state, frustum, 1000000, camera_pos, animtime, display_mode::in_3D);
|
||||
model.model->renderer()->draw(model_view, model, m2_shader, model_render_state, frustum, 1000000, camera_pos, animtime, display_mode::in_3D);
|
||||
}
|
||||
}
|
||||
// if it's night, draw the stars
|
||||
@@ -543,7 +543,7 @@ bool Skies::draw(glm::mat4x4 const& model_view
|
||||
m2_shader.uniform("tex_unit_lookup_2", 0);
|
||||
m2_shader.uniform("pixel_shader", 0);
|
||||
|
||||
stars.model->draw(model_view, stars, m2_shader, model_render_state, frustum, 1000000, camera_pos, animtime, display_mode::in_3D);
|
||||
stars.model->renderer()->draw(model_view, stars, m2_shader, model_render_state, frustum, 1000000, camera_pos, animtime, display_mode::in_3D);
|
||||
}
|
||||
|
||||
return true;
|
||||
|
||||
1051
src/noggit/rendering/ModelRender.cpp
Normal file
1051
src/noggit/rendering/ModelRender.cpp
Normal file
File diff suppressed because it is too large
Load Diff
190
src/noggit/rendering/ModelRender.hpp
Normal file
190
src/noggit/rendering/ModelRender.hpp
Normal file
@@ -0,0 +1,190 @@
|
||||
// This file is part of Noggit3, licensed under GNU General Public License (version 3).
|
||||
|
||||
#ifndef NOGGIT_MODELRENDER_HPP
|
||||
#define NOGGIT_MODELRENDER_HPP
|
||||
|
||||
#include <noggit/rendering/BaseRender.hpp>
|
||||
#include <noggit/ModelHeaders.h>
|
||||
#include <noggit/tool_enums.hpp>
|
||||
#include <opengl/scoped.hpp>
|
||||
#include <opengl/shader.hpp>
|
||||
#include <math/frustum.hpp>
|
||||
|
||||
class Model;
|
||||
class ModelInstance;
|
||||
|
||||
namespace Noggit::Rendering
|
||||
{
|
||||
enum class M2Blend : uint16_t
|
||||
{
|
||||
Opaque,
|
||||
Alpha_Key,
|
||||
Alpha,
|
||||
No_Add_Alpha,
|
||||
Add,
|
||||
Mod,
|
||||
Mod2x
|
||||
};
|
||||
|
||||
enum class ModelPixelShader : uint16_t
|
||||
{
|
||||
Combiners_Opaque,
|
||||
Combiners_Decal,
|
||||
Combiners_Add,
|
||||
Combiners_Mod2x,
|
||||
Combiners_Fade,
|
||||
Combiners_Mod,
|
||||
Combiners_Opaque_Opaque,
|
||||
Combiners_Opaque_Add,
|
||||
Combiners_Opaque_Mod2x,
|
||||
Combiners_Opaque_Mod2xNA,
|
||||
Combiners_Opaque_AddNA,
|
||||
Combiners_Opaque_Mod,
|
||||
Combiners_Mod_Opaque,
|
||||
Combiners_Mod_Add,
|
||||
Combiners_Mod_Mod2x,
|
||||
Combiners_Mod_Mod2xNA,
|
||||
Combiners_Mod_AddNA,
|
||||
Combiners_Mod_Mod,
|
||||
Combiners_Add_Mod,
|
||||
Combiners_Mod2x_Mod2x,
|
||||
Combiners_Opaque_Mod2xNA_Alpha,
|
||||
Combiners_Opaque_AddAlpha,
|
||||
Combiners_Opaque_AddAlpha_Alpha,
|
||||
};
|
||||
|
||||
enum class texture_unit_lookup : int
|
||||
{
|
||||
environment,
|
||||
t1,
|
||||
t2,
|
||||
none
|
||||
};
|
||||
|
||||
|
||||
struct ModelRenderPass : ModelTexUnit
|
||||
{
|
||||
ModelRenderPass() = delete;
|
||||
ModelRenderPass(ModelTexUnit const& tex_unit, Model* m);
|
||||
|
||||
float ordering_thingy = 0.f;
|
||||
uint16_t index_start = 0, index_count = 0, vertex_start = 0, vertex_end = 0;
|
||||
uint16_t blend_mode = 0;
|
||||
texture_unit_lookup tu_lookups[2];
|
||||
uint16_t textures[2];
|
||||
uint16_t uv_animations[2];
|
||||
std::optional<ModelPixelShader> pixel_shader;
|
||||
|
||||
|
||||
bool prepareDraw(OpenGL::Scoped::use_program& m2_shader, Model *m, OpenGL::M2RenderState& model_render_state);
|
||||
void afterDraw();
|
||||
void bindTexture(size_t index, Model* m, OpenGL::M2RenderState& model_render_state, OpenGL::Scoped::use_program& m2_shader);
|
||||
void initUVTypes(Model* m);
|
||||
|
||||
bool operator< (const ModelRenderPass &m) const
|
||||
{
|
||||
if (priority_plane < m.priority_plane)
|
||||
{
|
||||
return true;
|
||||
}
|
||||
else if (priority_plane > m.priority_plane)
|
||||
{
|
||||
return false;
|
||||
}
|
||||
else
|
||||
{
|
||||
return blend_mode == m.blend_mode ? (ordering_thingy < m.ordering_thingy) : blend_mode < m.blend_mode;
|
||||
}
|
||||
}
|
||||
};
|
||||
|
||||
class ModelRender : public BaseRender
|
||||
{
|
||||
friend struct ModelRenderPass;
|
||||
|
||||
public:
|
||||
ModelRender(Model* model);
|
||||
|
||||
void upload() override;
|
||||
void unload() override;
|
||||
|
||||
void draw(glm::mat4x4 const& model_view
|
||||
, ModelInstance& instance
|
||||
, OpenGL::Scoped::use_program& m2_shader
|
||||
, OpenGL::M2RenderState& model_render_state
|
||||
, math::frustum const& frustum
|
||||
, const float& cull_distance
|
||||
, const glm::vec3& camera
|
||||
, int animtime
|
||||
, display_mode display
|
||||
, bool no_cull = false
|
||||
);
|
||||
|
||||
void draw (glm::mat4x4 const& model_view
|
||||
, std::vector<glm::mat4x4> const& instances
|
||||
, OpenGL::Scoped::use_program& m2_shader
|
||||
, OpenGL::M2RenderState& model_render_state
|
||||
, math::frustum const& frustum
|
||||
, const float& cull_distance
|
||||
, const glm::vec3& camera
|
||||
, int animtime
|
||||
, bool all_boxes
|
||||
, std::unordered_map<Model*, std::size_t>& model_boxes_to_draw
|
||||
, display_mode display
|
||||
, bool no_cull = false
|
||||
);
|
||||
|
||||
void drawParticles(glm::mat4x4 const& model_view
|
||||
, OpenGL::Scoped::use_program& particles_shader
|
||||
, std::size_t instance_count
|
||||
);
|
||||
|
||||
void drawRibbons(OpenGL::Scoped::use_program& ribbons_shader
|
||||
, std::size_t instance_count
|
||||
);
|
||||
|
||||
void drawBox(OpenGL::Scoped::use_program& m2_box_shader, std::size_t box_count);
|
||||
|
||||
[[nodiscard]]
|
||||
std::vector<ModelRenderPass> const& renderPasses() const { return _render_passes; };
|
||||
|
||||
void updateBoneMatrices();
|
||||
|
||||
void initRenderPasses(ModelView const* view, ModelTexUnit const* tex_unit, ModelGeoset const* model_geosets);
|
||||
|
||||
private:
|
||||
|
||||
void setupVAO(OpenGL::Scoped::use_program& m2_shader);
|
||||
void fixShaderIdBlendOverride();
|
||||
void fixShaderIDLayer();
|
||||
void computePixelShaderIDs();
|
||||
|
||||
|
||||
Model* _model;
|
||||
|
||||
// buffers
|
||||
OpenGL::Scoped::deferred_upload_buffers<6> _buffers;
|
||||
OpenGL::Scoped::deferred_upload_vertex_arrays<2> _vertex_arrays;
|
||||
|
||||
std::vector<uint16_t> const _box_indices = {5, 7, 3, 2, 0, 1, 3, 1, 5, 4, 0, 4, 6, 2, 6, 7};
|
||||
|
||||
GLuint const& _vao = _vertex_arrays[0];
|
||||
GLuint const& _transform_buffer = _buffers[0];
|
||||
GLuint const& _vertices_buffer = _buffers[1];
|
||||
GLuint const& _indices_buffer = _buffers[3];
|
||||
GLuint const& _box_indices_buffer = _buffers[4];
|
||||
GLuint const& _bone_matrices_buffer = _buffers[5];
|
||||
|
||||
GLuint const& _box_vao = _vertex_arrays[1];
|
||||
GLuint const& _box_vbo = _buffers[2];
|
||||
|
||||
GLuint _bone_matrices_buf_tex;
|
||||
std::vector<glm::vec3> _vertex_box_points;
|
||||
std::vector<ModelRenderPass> _render_passes;
|
||||
|
||||
bool _uploaded = false;
|
||||
bool _vao_setup = false;
|
||||
};
|
||||
}
|
||||
|
||||
#endif //NOGGIT_MODELRENDER_HPP
|
||||
@@ -148,7 +148,7 @@ bool WMORender::drawSkybox(const glm::mat4x4& model_view, const glm::vec3& camer
|
||||
m2_shader.uniform("tex_unit_lookup_2", 0);
|
||||
m2_shader.uniform("pixel_shader", 0);
|
||||
|
||||
_wmo->skybox->get()->draw(model_view, sky, m2_shader, model_render_state, frustum, cull_distance, camera_pos, animtime, display_mode::in_3D);
|
||||
_wmo->skybox->get()->renderer()->draw(model_view, sky, m2_shader, model_render_state, frustum, cull_distance, camera_pos, animtime, display_mode::in_3D);
|
||||
|
||||
return true;
|
||||
}
|
||||
|
||||
@@ -651,7 +651,7 @@ void WorldRender::draw (glm::mat4x4 const& model_view
|
||||
|
||||
if (draw_hidden_models || !pair.first->is_hidden())
|
||||
{
|
||||
pair.first->draw( model_view
|
||||
pair.first->renderer()->draw( model_view
|
||||
, pair.second
|
||||
, m2_shader
|
||||
, model_render_state
|
||||
@@ -731,7 +731,7 @@ void WorldRender::draw (glm::mat4x4 const& model_view
|
||||
;
|
||||
|
||||
m2_box_shader.uniform("color", color);
|
||||
it.first->draw_box(m2_box_shader, it.second);
|
||||
it.first->renderer()->drawBox(m2_box_shader, it.second);
|
||||
}
|
||||
}
|
||||
|
||||
|
||||
@@ -245,7 +245,7 @@ void PreviewRenderer::draw()
|
||||
instance[0] = &model_instance;
|
||||
instance_mtx[0] = model_instance.transformMatrix();
|
||||
|
||||
model_instance.model->draw(
|
||||
model_instance.model->renderer()->draw(
|
||||
mv
|
||||
, instance_mtx
|
||||
, m2_shader
|
||||
@@ -269,7 +269,7 @@ void PreviewRenderer::draw()
|
||||
instance_mtx.push_back(instance->transformMatrix());
|
||||
}
|
||||
|
||||
it.second[0]->model->draw(
|
||||
it.second[0]->model->renderer()->draw(
|
||||
mv
|
||||
, instance_mtx
|
||||
, m2_shader
|
||||
@@ -303,7 +303,7 @@ void PreviewRenderer::draw()
|
||||
;
|
||||
|
||||
m2_box_shader.uniform("color", color);
|
||||
it.first->draw_box(m2_box_shader, it.second);
|
||||
it.first->renderer()->drawBox(m2_box_shader, it.second);
|
||||
}
|
||||
}
|
||||
}
|
||||
|
||||
Reference in New Issue
Block a user