asset browser: fix rendering bounding boxes from multiple contexts

This commit is contained in:
sshumakov3
2020-11-17 15:28:44 +03:00
parent 9c62263a36
commit b1e769836c
5 changed files with 67 additions and 50 deletions

View File

@@ -56,39 +56,39 @@ void ModelInstance::draw_box ( math::matrix_4x4 const& model_view
if (is_current_selection)
{
opengl::primitives::wire_box::getInstance().draw ( model_view
, projection
, transform_matrix_transposed()
, { 1.0f, 1.0f, 0.0f, 1.0f }
, misc::transform_model_box_coords(model->header.collision_box_min)
, misc::transform_model_box_coords(model->header.collision_box_max)
);
opengl::primitives::wire_box::getInstance(_context).draw ( model_view
, projection
, transform_matrix_transposed()
, { 1.0f, 1.0f, 0.0f, 1.0f }
, misc::transform_model_box_coords(model->header.collision_box_min)
, misc::transform_model_box_coords(model->header.collision_box_max)
);
opengl::primitives::wire_box::getInstance().draw ( model_view
, projection
, transform_matrix_transposed()
, {1.0f, 1.0f, 1.0f, 1.0f}
, misc::transform_model_box_coords(model->header.bounding_box_min)
, misc::transform_model_box_coords(model->header.bounding_box_max)
);
opengl::primitives::wire_box::getInstance(_context).draw ( model_view
, projection
, transform_matrix_transposed()
, {1.0f, 1.0f, 1.0f, 1.0f}
, misc::transform_model_box_coords(model->header.bounding_box_min)
, misc::transform_model_box_coords(model->header.bounding_box_max)
);
opengl::primitives::wire_box::getInstance().draw ( model_view
, projection
, math::matrix_4x4(math::matrix_4x4::unit)
, {0.0f, 1.0f, 0.0f, 1.0f}
, _extents[0]
, _extents[1]
);
opengl::primitives::wire_box::getInstance(_context).draw ( model_view
, projection
, math::matrix_4x4(math::matrix_4x4::unit)
, {0.0f, 1.0f, 0.0f, 1.0f}
, _extents[0]
, _extents[1]
);
}
else
{
opengl::primitives::wire_box::getInstance().draw ( model_view
, projection
, transform_matrix_transposed()
, {0.5f, 0.5f, 0.5f, 1.0f}
, misc::transform_model_box_coords(model->header.bounding_box_min)
, misc::transform_model_box_coords(model->header.bounding_box_max)
);
opengl::primitives::wire_box::getInstance(_context).draw ( model_view
, projection
, transform_matrix_transposed()
, {0.5f, 0.5f, 0.5f, 1.0f}
, misc::transform_model_box_coords(model->header.bounding_box_min)
, misc::transform_model_box_coords(model->header.bounding_box_max)
);
}
}

View File

@@ -460,6 +460,7 @@ QPixmap* PreviewRenderer::renderToPixmap()
gl.clearColor(0.5f, 0.5f, 0.5f, 1.f);
gl.clear(GL_COLOR_BUFFER_BIT | GL_DEPTH_BUFFER_BIT);
tick(20.f);
draw();
auto& async_loader = AsyncLoader::instance();

View File

@@ -369,22 +369,22 @@ void WMO::draw ( opengl::scoped::use_program& wmo_shader
for (auto& group : groups)
{
opengl::primitives::wire_box::getInstance().draw( model_view
, projection
, transform_matrix_transposed
, {1.0f, 1.0f, 1.0f, 1.0f}
, group.BoundingBoxMin
, group.BoundingBoxMax
);
opengl::primitives::wire_box::getInstance(_context).draw( model_view
, projection
, transform_matrix_transposed
, {1.0f, 1.0f, 1.0f, 1.0f}
, group.BoundingBoxMin
, group.BoundingBoxMax
);
}
opengl::primitives::wire_box::getInstance().draw ( model_view
, projection
, transform_matrix_transposed
, {1.0f, 0.0f, 0.0f, 1.0f}
, math::vector_3d(extents[0].x, extents[0].z, -extents[0].y)
, math::vector_3d(extents[1].x, extents[1].z, -extents[1].y)
);
opengl::primitives::wire_box::getInstance(_context).draw ( model_view
, projection
, transform_matrix_transposed
, {1.0f, 0.0f, 0.0f, 1.0f}
, math::vector_3d(extents[0].x, extents[0].z, -extents[0].y)
, math::vector_3d(extents[1].x, extents[1].z, -extents[1].y)
);
}
}

View File

@@ -98,9 +98,15 @@ void WMOInstance::draw ( opengl::scoped::use_program& wmo_shader
gl.enable(GL_BLEND);
gl.blendFunc(GL_SRC_ALPHA, GL_ONE_MINUS_SRC_ALPHA);
math::vector_4d color = force_box ? math::vector_4d(0.0f, 0.0f, 1.0f, 1.0f) : math::vector_4d(0.0f, 1.0f, 0.0f, 1.0f);
opengl::primitives::wire_box::getInstance().draw(model_view, projection, math::matrix_4x4(math::matrix_4x4::unit),
color, extents[0], extents[1]);
math::vector_4d color = force_box ? math::vector_4d(0.0f, 0.0f, 1.0f, 1.0f)
: math::vector_4d(0.0f, 1.0f, 0.0f, 1.0f);
opengl::primitives::wire_box::getInstance(_context).draw(model_view
, projection
, math::matrix_4x4(math::matrix_4x4::unit)
, color
, extents[0]
, extents[1]);
}
}

View File

@@ -4,8 +4,10 @@
#include <opengl/scoped.hpp>
#include <opengl/shader.hpp>
#include <noggit/ContextObject.hpp>
#include <memory>
#include <unordered_map>
namespace math
{
@@ -19,15 +21,23 @@ namespace opengl
{
class wire_box
{
private:
public:
wire_box() {}
wire_box( const wire_box&);
wire_box& operator=( wire_box& );
wire_box& operator=( wire_box& box ) { return *this; };
public:
static wire_box& getInstance() {
static wire_box instance;
return instance;
static wire_box& getInstance(noggit::NoggitRenderContext context)
{
static std::unordered_map<noggit::NoggitRenderContext, wire_box> instances;
if (instances.find(context) == instances.end())
{
wire_box instance;
instances[context] = instance;
}
return instances.at(context);
}
void draw ( math::matrix_4x4 const& model_view