mirror of
https://github.com/lubosz/overte.git
synced 2025-04-23 07:43:57 +02:00
Drafting the octree, allocating the first cells
This commit is contained in:
parent
a847a16788
commit
903c7dde5a
6 changed files with 50 additions and 32 deletions
|
@ -25,8 +25,6 @@
|
|||
|
||||
using namespace render;
|
||||
|
||||
const int DrawSceneOctree_CellsSlot = 0;
|
||||
const int DrawSceneOctree_OctreeInfoSlot = 1;
|
||||
|
||||
const gpu::PipelinePointer DrawSceneOctree::getDrawCellBoundsPipeline() {
|
||||
if (!_drawCellBoundsPipeline) {
|
||||
|
@ -35,10 +33,11 @@ const gpu::PipelinePointer DrawSceneOctree::getDrawCellBoundsPipeline() {
|
|||
gpu::ShaderPointer program = gpu::Shader::createProgram(vs, ps);
|
||||
|
||||
gpu::Shader::BindingSet slotBindings;
|
||||
slotBindings.insert(gpu::Shader::Binding(std::string("cellsBuffer"), DrawSceneOctree_CellsSlot));
|
||||
slotBindings.insert(gpu::Shader::Binding(std::string("octreeInfoBuffer"), DrawSceneOctree_OctreeInfoSlot));
|
||||
gpu::Shader::makeProgram(*program, slotBindings);
|
||||
|
||||
_drawBoundPosLoc = program->getUniforms().findLocation("inBoundPos");
|
||||
_drawBoundDimLoc = program->getUniforms().findLocation("inBoundDim");
|
||||
|
||||
auto state = std::make_shared<gpu::State>();
|
||||
|
||||
state->setDepthTest(true, false, gpu::LESS_EQUAL);
|
||||
|
@ -69,9 +68,19 @@ void DrawSceneOctree::run(const SceneContextPointer& sceneContext,
|
|||
if (!_cells) {
|
||||
_cells = std::make_shared<gpu::Buffer>();
|
||||
}
|
||||
if (!_octreeInfo) {
|
||||
/* if (!_octreeInfo) {
|
||||
_octreeInfo = std::make_shared<gpu::Buffer>();;
|
||||
}*/
|
||||
|
||||
const auto& inCells = scene->_spatialTree._cells;
|
||||
_cells->resize(inCells.size() * sizeof(AABox));
|
||||
AABox* cellAABox = reinterpret_cast<AABox*> (_cells->editData());
|
||||
for (const auto& cell : inCells) {
|
||||
(*cellAABox) = scene->_spatialTree.evalBound(cell.cellpos);
|
||||
nbCells++;
|
||||
cellAABox++;
|
||||
}
|
||||
|
||||
/*
|
||||
_cells->resize((inItems.size() * sizeof(AABox)));
|
||||
_itemStatus->resize((inItems.size() * NUM_STATUS_VEC4_PER_ITEM * sizeof(glm::vec4)));
|
||||
|
@ -108,9 +117,7 @@ void DrawSceneOctree::run(const SceneContextPointer& sceneContext,
|
|||
itemStatus++;
|
||||
}
|
||||
|
||||
nbItems++;
|
||||
itemAABox++;
|
||||
}
|
||||
}
|
||||
}*/
|
||||
}
|
||||
|
||||
|
@ -119,7 +126,7 @@ void DrawSceneOctree::run(const SceneContextPointer& sceneContext,
|
|||
}
|
||||
|
||||
// Allright, something to render let's do it
|
||||
/* gpu::doInBatch(args->_context, [&](gpu::Batch& batch) {
|
||||
gpu::doInBatch(args->_context, [&](gpu::Batch& batch) {
|
||||
glm::mat4 projMat;
|
||||
Transform viewMat;
|
||||
args->_viewFrustum->evalProjectionMatrix(projMat);
|
||||
|
@ -133,18 +140,15 @@ void DrawSceneOctree::run(const SceneContextPointer& sceneContext,
|
|||
// bind the one gpu::Pipeline we need
|
||||
batch.setPipeline(getDrawCellBoundsPipeline());
|
||||
|
||||
AABox* itemAABox = reinterpret_cast<AABox*> (_itemBounds->editData());
|
||||
glm::ivec4* itemStatus = reinterpret_cast<glm::ivec4*> (_itemStatus->editData());
|
||||
AABox* cellAABox = reinterpret_cast<AABox*> (_cells->editData());
|
||||
|
||||
const unsigned int VEC3_ADRESS_OFFSET = 3;
|
||||
|
||||
if ((renderContext->getDrawStatus() & showDisplayStatusFlag) > 0) {
|
||||
for (int i = 0; i < nbCells; i++) {
|
||||
batch._glUniform3fv(_drawItemBoundPosLoc, 1, (const float*) (itemAABox + i));
|
||||
batch._glUniform3fv(_drawItemBoundDimLoc, 1, ((const float*) (itemAABox + i)) + VEC3_ADRESS_OFFSET);
|
||||
for (int i = 0; i < nbCells; i++) {
|
||||
batch._glUniform3fv(_drawBoundPosLoc, 1, (const float*) (cellAABox + i));
|
||||
batch._glUniform3fv(_drawBoundDimLoc, 1, ((const float*) (cellAABox + i)) + VEC3_ADRESS_OFFSET);
|
||||
|
||||
batch.draw(gpu::LINES, 24, 0);
|
||||
}
|
||||
batch.draw(gpu::LINES, 24, 0);
|
||||
}
|
||||
});*/
|
||||
});
|
||||
}
|
||||
|
|
|
@ -18,9 +18,10 @@
|
|||
namespace render {
|
||||
class DrawSceneOctree {
|
||||
|
||||
int _drawBoundPosLoc;
|
||||
int _drawBoundDimLoc;
|
||||
gpu::PipelinePointer _drawCellBoundsPipeline;
|
||||
gpu::BufferPointer _cells;
|
||||
gpu::BufferPointer _octreeInfo;
|
||||
|
||||
public:
|
||||
|
||||
|
|
|
@ -14,12 +14,6 @@
|
|||
using namespace render;
|
||||
|
||||
Octree::Indices Octree::allocateCellPath(const CellPath& path) {
|
||||
|
||||
|
||||
CellPoint point{ Coord3{ 2, 4, 3 }, 3 };
|
||||
|
||||
auto ppath = CellPoint::rootTo(point);
|
||||
|
||||
Indices cellPath;
|
||||
|
||||
Index currentIndex = 0;
|
||||
|
@ -27,14 +21,15 @@ Octree::Indices Octree::allocateCellPath(const CellPath& path) {
|
|||
int d = 0;
|
||||
cellPath.push_back(currentIndex);
|
||||
|
||||
for (; d < path.back().depth; d++) {
|
||||
for (; d <= path.back().depth; d++) {
|
||||
auto& cellPoint = path[d];
|
||||
|
||||
auto currentIndex = currentCell->child(cellPoint.octant());
|
||||
if (currentIndex == INVALID) {
|
||||
break;
|
||||
currentIndex = _cells.size();
|
||||
currentCell->links[cellPoint.octant()] = currentIndex;
|
||||
_cells.push_back(Cell(cellPath.back(), cellPoint));
|
||||
}
|
||||
|
||||
cellPath.push_back(currentIndex);
|
||||
currentCell = _cells.data() + currentIndex;
|
||||
}
|
||||
|
|
|
@ -19,6 +19,9 @@
|
|||
#include <glm/glm.hpp>
|
||||
#include <glm/gtx/bit.hpp>
|
||||
|
||||
|
||||
#include <AABox.h>
|
||||
|
||||
namespace render {
|
||||
|
||||
class Octree {
|
||||
|
@ -147,6 +150,11 @@ namespace render {
|
|||
Cell() :
|
||||
links({ { INVALID, INVALID, INVALID, INVALID, INVALID, INVALID, INVALID, INVALID, INVALID } })
|
||||
{}
|
||||
|
||||
Cell(Index parent, CellPoint pos) :
|
||||
cellpos(pos),
|
||||
links({ { INVALID, INVALID, INVALID, INVALID, INVALID, INVALID, INVALID, INVALID, parent } })
|
||||
{}
|
||||
};
|
||||
using Cells = std::vector< Cell >;
|
||||
|
||||
|
@ -163,11 +171,20 @@ namespace render {
|
|||
Cells _cells = Cells(1, Cell()); // start with only the Cell root
|
||||
Bricks _bricks;
|
||||
|
||||
float _size = 320.0f;
|
||||
|
||||
Octree() {};
|
||||
|
||||
// allocatePath
|
||||
Indices allocateCellPath(const CellPath& path);
|
||||
|
||||
AABox evalBound(const CellPoint& point) const {
|
||||
|
||||
float width = (float) (_size / double(1 << point.depth));
|
||||
glm::vec3 corner = glm::vec3(-_size * 0.5f) + glm::vec3(point.pos) * width;
|
||||
return AABox(corner, width);
|
||||
|
||||
}
|
||||
};
|
||||
|
||||
|
||||
|
|
|
@ -142,9 +142,9 @@ Scene::Scene() {
|
|||
|
||||
|
||||
_spatialTree;
|
||||
Octree::CellPoint point{ Octree::Coord3{ 2, 4, 3 }, 3 };
|
||||
Octree::CellPoint point{ Octree::Coord3{ 2, 4, 3 }, 15};
|
||||
auto path = Octree::CellPoint::rootTo(point);
|
||||
|
||||
auto indices = _spatialTree.allocateCellPath(path);
|
||||
}
|
||||
|
||||
ItemID Scene::allocateID() {
|
||||
|
|
|
@ -513,6 +513,9 @@ public:
|
|||
|
||||
void processPendingChangesQueue();
|
||||
|
||||
|
||||
Octree _spatialTree;
|
||||
|
||||
protected:
|
||||
// Thread safe elements that can be accessed from anywhere
|
||||
std::atomic<unsigned int> _IDAllocator{ 1 }; // first valid itemID will be One
|
||||
|
@ -529,8 +532,6 @@ protected:
|
|||
void removeItems(const ItemIDs& ids);
|
||||
void updateItems(const ItemIDs& ids, UpdateFunctors& functors);
|
||||
|
||||
Octree _spatialTree;
|
||||
|
||||
friend class Engine;
|
||||
};
|
||||
|
||||
|
|
Loading…
Reference in a new issue