mirror of
https://github.com/lubosz/overte.git
synced 2025-04-23 07:43:57 +02:00
Drafting the Octree and a debugging job
This commit is contained in:
parent
b96bbab22f
commit
a847a16788
5 changed files with 307 additions and 0 deletions
150
libraries/render/src/render/DrawSceneOctree.cpp
Normal file
150
libraries/render/src/render/DrawSceneOctree.cpp
Normal file
|
@ -0,0 +1,150 @@
|
|||
//
|
||||
// DrawSceneOctree.cpp
|
||||
// render/src/render
|
||||
//
|
||||
// Created by Sam Gateau on 1/25/16.
|
||||
// Copyright 2015 High Fidelity, Inc.
|
||||
//
|
||||
// Distributed under the Apache License, Version 2.0.
|
||||
// See the accompanying file LICENSE or http://www.apache.org/licenses/LICENSE-2.0.html
|
||||
//
|
||||
|
||||
#include "DrawSceneOctree.h"
|
||||
|
||||
#include <algorithm>
|
||||
#include <assert.h>
|
||||
|
||||
#include <PerfStat.h>
|
||||
#include <ViewFrustum.h>
|
||||
#include <RenderArgs.h>
|
||||
|
||||
#include <gpu/Context.h>
|
||||
|
||||
#include "drawCellBounds_vert.h"
|
||||
#include "drawCellBounds_frag.h"
|
||||
|
||||
using namespace render;
|
||||
|
||||
const int DrawSceneOctree_CellsSlot = 0;
|
||||
const int DrawSceneOctree_OctreeInfoSlot = 1;
|
||||
|
||||
const gpu::PipelinePointer DrawSceneOctree::getDrawCellBoundsPipeline() {
|
||||
if (!_drawCellBoundsPipeline) {
|
||||
auto vs = gpu::Shader::createVertex(std::string(drawCellBounds_vert));
|
||||
auto ps = gpu::Shader::createPixel(std::string(drawCellBounds_frag));
|
||||
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);
|
||||
|
||||
auto state = std::make_shared<gpu::State>();
|
||||
|
||||
state->setDepthTest(true, false, gpu::LESS_EQUAL);
|
||||
|
||||
// Blend on transparent
|
||||
state->setBlendFunction(true,
|
||||
gpu::State::SRC_ALPHA, gpu::State::BLEND_OP_ADD, gpu::State::INV_SRC_ALPHA,
|
||||
gpu::State::DEST_ALPHA, gpu::State::BLEND_OP_ADD, gpu::State::ZERO);
|
||||
|
||||
// Good to go add the brand new pipeline
|
||||
_drawCellBoundsPipeline = gpu::Pipeline::create(program, state);
|
||||
}
|
||||
return _drawCellBoundsPipeline;
|
||||
}
|
||||
|
||||
void DrawSceneOctree::run(const SceneContextPointer& sceneContext,
|
||||
const RenderContextPointer& renderContext) {
|
||||
assert(renderContext->getArgs());
|
||||
assert(renderContext->getArgs()->_viewFrustum);
|
||||
RenderArgs* args = renderContext->getArgs();
|
||||
auto& scene = sceneContext->_scene;
|
||||
const int NUM_STATUS_VEC4_PER_ITEM = 2;
|
||||
const int VEC4_LENGTH = 4;
|
||||
|
||||
// FIrst thing, we update the local buffers with the values coming from Scene octree
|
||||
int nbCells = 0;
|
||||
{
|
||||
if (!_cells) {
|
||||
_cells = std::make_shared<gpu::Buffer>();
|
||||
}
|
||||
if (!_octreeInfo) {
|
||||
_octreeInfo = std::make_shared<gpu::Buffer>();;
|
||||
}
|
||||
/*
|
||||
_cells->resize((inItems.size() * sizeof(AABox)));
|
||||
_itemStatus->resize((inItems.size() * NUM_STATUS_VEC4_PER_ITEM * sizeof(glm::vec4)));
|
||||
AABox* itemAABox = reinterpret_cast<AABox*> (_itemBounds->editData());
|
||||
glm::ivec4* itemStatus = reinterpret_cast<glm::ivec4*> (_itemStatus->editData());
|
||||
for (auto& item : inItems) {
|
||||
if (!item.bounds.isInvalid()) {
|
||||
if (!item.bounds.isNull()) {
|
||||
(*itemAABox) = item.bounds;
|
||||
} else {
|
||||
(*itemAABox).setBox(item.bounds.getCorner(), 0.1f);
|
||||
}
|
||||
auto& itemScene = scene->getItem(item.id);
|
||||
|
||||
auto itemStatusPointer = itemScene.getStatus();
|
||||
if (itemStatusPointer) {
|
||||
// Query the current status values, this is where the statusGetter lambda get called
|
||||
auto&& currentStatusValues = itemStatusPointer->getCurrentValues();
|
||||
int valueNum = 0;
|
||||
for (int vec4Num = 0; vec4Num < NUM_STATUS_VEC4_PER_ITEM; vec4Num++) {
|
||||
(*itemStatus) = glm::ivec4(Item::Status::Value::INVALID.getPackedData());
|
||||
for (int component = 0; component < VEC4_LENGTH; component++) {
|
||||
valueNum = vec4Num * VEC4_LENGTH + component;
|
||||
if (valueNum < (int)currentStatusValues.size()) {
|
||||
(*itemStatus)[component] = currentStatusValues[valueNum].getPackedData();
|
||||
}
|
||||
}
|
||||
itemStatus++;
|
||||
}
|
||||
} else {
|
||||
(*itemStatus) = glm::ivec4(Item::Status::Value::INVALID.getPackedData());
|
||||
itemStatus++;
|
||||
(*itemStatus) = glm::ivec4(Item::Status::Value::INVALID.getPackedData());
|
||||
itemStatus++;
|
||||
}
|
||||
|
||||
nbItems++;
|
||||
itemAABox++;
|
||||
}
|
||||
}*/
|
||||
}
|
||||
|
||||
if (nbCells == 0) {
|
||||
return;
|
||||
}
|
||||
|
||||
// Allright, something to render let's do it
|
||||
/* gpu::doInBatch(args->_context, [&](gpu::Batch& batch) {
|
||||
glm::mat4 projMat;
|
||||
Transform viewMat;
|
||||
args->_viewFrustum->evalProjectionMatrix(projMat);
|
||||
args->_viewFrustum->evalViewTransform(viewMat);
|
||||
batch.setViewportTransform(args->_viewport);
|
||||
|
||||
batch.setProjectionTransform(projMat);
|
||||
batch.setViewTransform(viewMat);
|
||||
batch.setModelTransform(Transform());
|
||||
|
||||
// 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());
|
||||
|
||||
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);
|
||||
|
||||
batch.draw(gpu::LINES, 24, 0);
|
||||
}
|
||||
}
|
||||
});*/
|
||||
}
|
37
libraries/render/src/render/DrawSceneOctree.h
Normal file
37
libraries/render/src/render/DrawSceneOctree.h
Normal file
|
@ -0,0 +1,37 @@
|
|||
//
|
||||
// DrawSceneOctree.h
|
||||
// render/src/render
|
||||
//
|
||||
// Created by Sam Gateau on 1/25/16.
|
||||
// Copyright 2015 High Fidelity, Inc.
|
||||
//
|
||||
// Distributed under the Apache License, Version 2.0.
|
||||
// See the accompanying file LICENSE or http://www.apache.org/licenses/LICENSE-2.0.html
|
||||
//
|
||||
|
||||
#ifndef hifi_render_DrawSceneOctree_h
|
||||
#define hifi_render_DrawSceneOctree_h
|
||||
|
||||
#include "DrawTask.h"
|
||||
#include "gpu/Batch.h"
|
||||
|
||||
namespace render {
|
||||
class DrawSceneOctree {
|
||||
|
||||
gpu::PipelinePointer _drawCellBoundsPipeline;
|
||||
gpu::BufferPointer _cells;
|
||||
gpu::BufferPointer _octreeInfo;
|
||||
|
||||
public:
|
||||
|
||||
DrawSceneOctree() {}
|
||||
|
||||
void run(const SceneContextPointer& sceneContext, const RenderContextPointer& renderContext);
|
||||
|
||||
using JobModel = Task::Job::Model<DrawSceneOctree>;
|
||||
|
||||
const gpu::PipelinePointer getDrawCellBoundsPipeline();
|
||||
};
|
||||
}
|
||||
|
||||
#endif // hifi_render_DrawStatus_h
|
43
libraries/render/src/render/Octree.cpp
Normal file
43
libraries/render/src/render/Octree.cpp
Normal file
|
@ -0,0 +1,43 @@
|
|||
//
|
||||
// Octree.h
|
||||
// render/src/render
|
||||
//
|
||||
// Created by Sam Gateau on 1/25/16.
|
||||
// Copyright 2014 High Fidelity, Inc.
|
||||
//
|
||||
// Distributed under the Apache License, Version 2.0.
|
||||
// See the accompanying file LICENSE or http://www.apache.org/licenses/LICENSE-2.0.html
|
||||
//
|
||||
#include "Octree.h"
|
||||
|
||||
|
||||
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;
|
||||
Cell* currentCell = _cells.data();
|
||||
int d = 0;
|
||||
cellPath.push_back(currentIndex);
|
||||
|
||||
for (; d < path.back().depth; d++) {
|
||||
auto& cellPoint = path[d];
|
||||
|
||||
auto currentIndex = currentCell->child(cellPoint.octant());
|
||||
if (currentIndex == INVALID) {
|
||||
break;
|
||||
}
|
||||
|
||||
cellPath.push_back(currentIndex);
|
||||
currentCell = _cells.data() + currentIndex;
|
||||
}
|
||||
|
||||
return cellPath;
|
||||
}
|
20
libraries/render/src/render/drawCellBounds.slf
Normal file
20
libraries/render/src/render/drawCellBounds.slf
Normal file
|
@ -0,0 +1,20 @@
|
|||
<@include gpu/Config.slh@>
|
||||
<$VERSION_HEADER$>
|
||||
// Generated on <$_SCRIBE_DATE$>
|
||||
// drawCellBounds.slf
|
||||
// fragment shader
|
||||
//
|
||||
// Created by Sam Gateau on 1/25/2016.
|
||||
// Copyright 2015 High Fidelity, Inc.
|
||||
//
|
||||
// Distributed under the Apache License, Version 2.0.
|
||||
// See the accompanying file LICENSE or http://www.apache.org/licenses/LICENSE-2.0.html
|
||||
//
|
||||
|
||||
in vec4 varColor;
|
||||
out vec4 outFragColor;
|
||||
|
||||
|
||||
void main(void) {
|
||||
outFragColor = vec4(1.0, 1.0, 1.0, 1.0);
|
||||
}
|
57
libraries/render/src/render/drawCellBounds.slv
Normal file
57
libraries/render/src/render/drawCellBounds.slv
Normal file
|
@ -0,0 +1,57 @@
|
|||
<@include gpu/Config.slh@>
|
||||
<$VERSION_HEADER$>
|
||||
// Generated on <$_SCRIBE_DATE$>
|
||||
//
|
||||
// drawCellBounds.slv
|
||||
// Vertex shader
|
||||
//
|
||||
// Created by Sam Gateau on 1/25/2016
|
||||
// Copyright 2015 High Fidelity, Inc.
|
||||
//
|
||||
// Distributed under the Apache License, Version 2.0.
|
||||
// See the accompanying file LICENSE or http://www.apache.org/licenses/LICENSE-2.0.html
|
||||
//
|
||||
|
||||
<@include gpu/Transform.slh@>
|
||||
|
||||
<$declareStandardTransform()$>
|
||||
|
||||
uniform vec3 inBoundPos;
|
||||
uniform vec3 inBoundDim;
|
||||
|
||||
void main(void) {
|
||||
const vec4 UNIT_BOX[8] = vec4[8](
|
||||
vec4(0.0, 0.0, 0.0, 1.0),
|
||||
vec4(1.0, 0.0, 0.0, 1.0),
|
||||
vec4(0.0, 1.0, 0.0, 1.0),
|
||||
vec4(1.0, 1.0, 0.0, 1.0),
|
||||
vec4(0.0, 0.0, 1.0, 1.0),
|
||||
vec4(1.0, 0.0, 1.0, 1.0),
|
||||
vec4(0.0, 1.0, 1.0, 1.0),
|
||||
vec4(1.0, 1.0, 1.0, 1.0)
|
||||
);
|
||||
const int UNIT_BOX_LINE_INDICES[24] = int[24](
|
||||
0, 1,
|
||||
1, 3,
|
||||
3, 2,
|
||||
2, 0,
|
||||
4, 5,
|
||||
5, 7,
|
||||
7, 6,
|
||||
6, 4,
|
||||
2, 6,
|
||||
3, 7,
|
||||
0, 4,
|
||||
1, 5
|
||||
);
|
||||
vec4 pos = UNIT_BOX[UNIT_BOX_LINE_INDICES[gl_VertexID]];
|
||||
|
||||
pos.xyz = inBoundPos + inBoundDim * pos.xyz;
|
||||
|
||||
// standard transform
|
||||
TransformCamera cam = getTransformCamera();
|
||||
TransformObject obj = getTransformObject();
|
||||
<$transformModelToClipPos(cam, obj, pos, gl_Position)$>
|
||||
|
||||
// varTexcoord = (pos.xy + 1) * 0.5;
|
||||
}
|
Loading…
Reference in a new issue