fix occlusion culling and selection bugs
This commit is contained in:
@@ -19,7 +19,6 @@
|
||||
|
||||
#include <QtCore/QSettings>
|
||||
|
||||
#include <algorithm>
|
||||
#include <cassert>
|
||||
#include <list>
|
||||
#include <map>
|
||||
@@ -27,7 +26,6 @@
|
||||
#include <utility>
|
||||
#include <vector>
|
||||
#include <limits>
|
||||
#include <cstdint>
|
||||
|
||||
|
||||
MapTile::MapTile( int pX
|
||||
@@ -698,8 +696,7 @@ bool MapTile::intersect (math::ray const& ray, selection_result* results) const
|
||||
{
|
||||
for (size_t i (0); i < 16; ++i)
|
||||
{
|
||||
if (mChunks[j][i]->intersect (ray, results))
|
||||
return true;
|
||||
mChunks[j][i]->intersect (ray, results);
|
||||
}
|
||||
}
|
||||
return false;
|
||||
@@ -1865,12 +1862,18 @@ void MapTile::doObjectOcclusionQuery(opengl::scoped::use_program& occlusion_shad
|
||||
gl.endQuery(GL_ANY_SAMPLES_PASSED);
|
||||
}
|
||||
|
||||
bool MapTile::getObjectOcclusionQueryResult()
|
||||
bool MapTile::getObjectOcclusionQueryResult(math::vector_3d const& camera)
|
||||
{
|
||||
// returns true if objects are not occluded by terrain
|
||||
if (!_uploaded)
|
||||
return !objects_occluded;
|
||||
|
||||
if (misc::pointInside(camera, _object_instance_extents))
|
||||
{
|
||||
_object_occlusion_query_in_use = false;
|
||||
return true;
|
||||
}
|
||||
|
||||
GLint result;
|
||||
gl.getQueryObjectiv(_objects_occlusion_query, GL_QUERY_RESULT_AVAILABLE, &result);
|
||||
|
||||
|
||||
@@ -167,7 +167,7 @@ public:
|
||||
std::unordered_set<SceneObject*>& getObjectInstances() { return object_instances; };
|
||||
|
||||
void doObjectOcclusionQuery(opengl::scoped::use_program& occlusion_shader);
|
||||
bool getObjectOcclusionQueryResult();
|
||||
bool getObjectOcclusionQueryResult(math::vector_3d const& camera);
|
||||
|
||||
float camDist() { return _cam_dist; }
|
||||
void calcCamDist(math::vector_3d const& camera);
|
||||
|
||||
@@ -14,6 +14,29 @@
|
||||
|
||||
namespace misc
|
||||
{
|
||||
|
||||
bool pointInside(math::vector_3d point, std::array<math::vector_3d, 2> const& extents)
|
||||
{
|
||||
return point.x >= extents[0].x && point.z >= extents[0].z &&
|
||||
point.x <= extents[1].x && point.z <= extents[1].z;
|
||||
}
|
||||
|
||||
void minmax(math::vector_3d* a, math::vector_3d* b)
|
||||
{
|
||||
if (a->x > b->x)
|
||||
{
|
||||
std::swap(a->x, b->x);
|
||||
}
|
||||
if (a->y > b->y)
|
||||
{
|
||||
std::swap(a->y, b->y);
|
||||
}
|
||||
if (a->z > b->z)
|
||||
{
|
||||
std::swap(a->z, b->z);
|
||||
}
|
||||
}
|
||||
|
||||
void find_and_replace(std::string& source, const std::string& find, const std::string& replace)
|
||||
{
|
||||
size_t found = source.rfind(find);
|
||||
@@ -186,26 +209,5 @@ void SetChunkHeader(sExtendableArray& pArray, int pPosition, int pMagix, int pSi
|
||||
Header->mSize = pSize;
|
||||
}
|
||||
|
||||
bool pointInside(math::vector_3d point, math::vector_3d extents[2])
|
||||
{
|
||||
minmax(&extents[0], &extents[1]);
|
||||
|
||||
return point.x >= extents[0].x && point.z >= extents[0].z &&
|
||||
point.x <= extents[1].x && point.z <= extents[1].z;
|
||||
}
|
||||
|
||||
void minmax(math::vector_3d* a, math::vector_3d* b)
|
||||
{
|
||||
if (a->x > b->x)
|
||||
{
|
||||
std::swap(a->x, b->x);
|
||||
}
|
||||
if (a->y > b->y)
|
||||
{
|
||||
std::swap(a->y, b->y);
|
||||
}
|
||||
if (a->z > b->z)
|
||||
{
|
||||
std::swap(a->z, b->z);
|
||||
}
|
||||
}
|
||||
|
||||
@@ -48,6 +48,9 @@ namespace misc
|
||||
bool vec3d_equals(math::vector_3d const& v1, math::vector_3d const& v2);
|
||||
bool deg_vec3d_equals(math::degrees::vec3 const& v1, math::degrees::vec3 const& v2);
|
||||
|
||||
bool pointInside(math::vector_3d point, std::array<math::vector_3d, 2> const& extents);
|
||||
void minmax(math::vector_3d* a, math::vector_3d* b);
|
||||
|
||||
inline int rounded_int_div(int value, int div)
|
||||
{
|
||||
return value / div + (value % div <= (div >> 1) ? 0 : 1);
|
||||
@@ -154,5 +157,3 @@ struct sChunkHeader
|
||||
|
||||
void SetChunkHeader(sExtendableArray& pArray, int pPosition, int pMagix, int pSize = 0);
|
||||
|
||||
bool pointInside(math::vector_3d point, math::vector_3d extents[2]);
|
||||
void minmax(math::vector_3d* a, math::vector_3d* b);
|
||||
|
||||
@@ -47,7 +47,7 @@ TexArrayParams& TextureManager::get_tex_array(int width, int height, int mip_lev
|
||||
{
|
||||
TexArrayParams& array_params = _tex_arrays[context][std::make_tuple(-1, width, height, mip_level)];
|
||||
|
||||
GLint n_layers = 1024;
|
||||
GLint n_layers = 512;
|
||||
//gl.getIntegerv(GL_MAX_ARRAY_TEXTURE_LAYERS, &n_layers);
|
||||
|
||||
int index_x = array_params.n_used / n_layers;
|
||||
@@ -91,7 +91,7 @@ TexArrayParams& TextureManager::get_tex_array(GLint compression, int width, int
|
||||
|
||||
TexArrayParams& array_params = _tex_arrays[context][std::make_tuple(compression, width, height, mip_level)];
|
||||
|
||||
GLint n_layers = 1024;
|
||||
GLint n_layers = 512;
|
||||
//gl.getIntegerv(GL_MAX_ARRAY_TEXTURE_LAYERS, &n_layers);
|
||||
|
||||
int index_x = array_params.n_used / n_layers;
|
||||
@@ -212,7 +212,7 @@ void blp_texture::upload()
|
||||
|
||||
int width = _width, height = _height;
|
||||
|
||||
GLint n_layers = 1024;
|
||||
GLint n_layers = 512;
|
||||
//gl.getIntegerv(GL_MAX_ARRAY_TEXTURE_LAYERS, &n_layers);
|
||||
|
||||
if (!_compression_format)
|
||||
|
||||
@@ -1261,7 +1261,7 @@ void World::draw ( math::matrix_4x4 const& model_view
|
||||
break;
|
||||
}
|
||||
|
||||
tile->objects_occluded = !tile->getObjectOcclusionQueryResult();
|
||||
tile->objects_occluded = !tile->getObjectOcclusionQueryResult(camera_pos);
|
||||
tile->doObjectOcclusionQuery(occluder_shader);
|
||||
}
|
||||
|
||||
|
||||
@@ -727,9 +727,10 @@ uid_fix_status MapIndex::fixUIDs (World* world, bool cancel_on_model_loading_err
|
||||
continue;
|
||||
}
|
||||
|
||||
math::vector_3d tileExtents[2];
|
||||
std::array<math::vector_3d, 2> tileExtents;
|
||||
tileExtents[0] = { x*TILESIZE, 0, z*TILESIZE };
|
||||
tileExtents[1] = { (x+1)*TILESIZE, 0, (z+1)*TILESIZE };
|
||||
misc::minmax(&tileExtents[0], &tileExtents[1]);
|
||||
|
||||
std::forward_list<ENTRY_MDDF> modelEntries;
|
||||
std::forward_list<ENTRY_MODF> wmoEntries;
|
||||
@@ -767,7 +768,7 @@ uid_fix_status MapIndex::fixUIDs (World* world, bool cancel_on_model_loading_err
|
||||
bool add = true;
|
||||
ENTRY_MDDF const& mddf = mddf_ptr[i];
|
||||
|
||||
if (!pointInside({ mddf.pos[0], 0, mddf.pos[2] }, tileExtents))
|
||||
if (!misc::pointInside({ mddf.pos[0], 0, mddf.pos[2] }, tileExtents))
|
||||
{
|
||||
continue;
|
||||
}
|
||||
@@ -809,7 +810,7 @@ uid_fix_status MapIndex::fixUIDs (World* world, bool cancel_on_model_loading_err
|
||||
bool add = true;
|
||||
ENTRY_MODF const& modf = modf_ptr[i];
|
||||
|
||||
if (!pointInside({ modf.pos[0], 0, modf.pos[2] }, tileExtents))
|
||||
if (!misc::pointInside({ modf.pos[0], 0, modf.pos[2] }, tileExtents))
|
||||
{
|
||||
continue;
|
||||
}
|
||||
|
||||
Reference in New Issue
Block a user