fix debug tools

This commit is contained in:
SamGondelman 2018-08-07 15:25:56 -07:00
parent 82029b4cb0
commit 6ff0b9d417
8 changed files with 90 additions and 118 deletions

View file

@ -22,10 +22,8 @@
#include "Args.h"
using namespace render;
const gpu::PipelinePointer DrawSceneOctree::getDrawCellBoundsPipeline() {
if (!_drawCellBoundsPipeline) {
gpu::ShaderPointer program = gpu::Shader::createProgram(shader::render::program::drawCellBounds);
@ -71,7 +69,6 @@ void DrawSceneOctree::run(const RenderContextPointer& renderContext, const ItemS
std::static_pointer_cast<Config>(renderContext->jobConfig)->numAllocatedCells = (int)scene->getSpatialTree().getNumAllocatedCells();
std::static_pointer_cast<Config>(renderContext->jobConfig)->numFreeCells = (int)scene->getSpatialTree().getNumFreeCells();
gpu::doInBatch("DrawSceneOctree::run", args->_context, [&](gpu::Batch& batch) {
glm::mat4 projMat;
Transform viewMat;
@ -86,44 +83,30 @@ void DrawSceneOctree::run(const RenderContextPointer& renderContext, const ItemS
// bind the one gpu::Pipeline we need
batch.setPipeline(getDrawCellBoundsPipeline());
if (_showVisibleCells) {
for (const auto& cellID : inSelection.cellSelection.insideCells) {
auto drawCellBounds = [this, &scene, &batch](const std::vector<gpu::Stamp>& cells) {
for (const auto& cellID : cells) {
auto cell = scene->getSpatialTree().getConcreteCell(cellID);
auto cellLoc = cell.getlocation();
glm::ivec4 cellLocation(cellLoc.pos.x, cellLoc.pos.y, cellLoc.pos.z, cellLoc.depth);
bool doDraw = true;
if (cell.isBrickEmpty() || !cell.hasBrick()) {
bool empty = cell.isBrickEmpty() || !cell.hasBrick();
if (empty) {
if (!_showEmptyCells) {
doDraw = false;
continue;
}
cellLocation.w *= -1;
cellLocation.w *= -1.0;
} else if (!empty && !_showVisibleCells) {
continue;
}
if (doDraw) {
batch._glUniform4iv(gpu::slot::uniform::Extra0, 1, ((const int*)(&cellLocation)));
batch.draw(gpu::LINES, 24, 0);
}
}
for (const auto& cellID : inSelection.cellSelection.partialCells) {
auto cell = scene->getSpatialTree().getConcreteCell(cellID);
auto cellLoc = cell.getlocation();
glm::ivec4 cellLocation(cellLoc.pos.x, cellLoc.pos.y, cellLoc.pos.z, cellLoc.depth);
bool doDraw = true;
if (cell.isBrickEmpty() || !cell.hasBrick()) {
if (!_showEmptyCells) {
doDraw = false;
}
cellLocation.w *= -1;
}
if (doDraw) {
batch._glUniform4iv(gpu::slot::uniform::Extra0, 1, ((const int*)(&cellLocation)));
batch.draw(gpu::LINES, 24, 0);
}
batch._glUniform4iv(gpu::slot::uniform::Extra0, 1, ((const int*)(&cellLocation)));
batch.draw(gpu::LINES, 24, 0);
}
}
};
drawCellBounds(inSelection.cellSelection.insideCells);
drawCellBounds(inSelection.cellSelection.partialCells);
// Draw the LOD Reticle
{
float angle = glm::degrees(getPerspectiveAccuracyAngle(args->_sizeScale, args->_boundaryLevelAdjust));
@ -169,6 +152,19 @@ void DrawItemSelection::run(const RenderContextPointer& renderContext, const Ite
RenderArgs* args = renderContext->args;
auto& scene = renderContext->_scene;
if (!_boundsBufferInside) {
_boundsBufferInside = std::make_shared<gpu::Buffer>(sizeof(render::ItemBound));
}
if (!_boundsBufferInsideSubcell) {
_boundsBufferInsideSubcell = std::make_shared<gpu::Buffer>(sizeof(render::ItemBound));
}
if (!_boundsBufferPartial) {
_boundsBufferPartial = std::make_shared<gpu::Buffer>(sizeof(render::ItemBound));
}
if (!_boundsBufferPartialSubcell) {
_boundsBufferPartialSubcell = std::make_shared<gpu::Buffer>(sizeof(render::ItemBound));
}
gpu::doInBatch("DrawItemSelection::run", args->_context, [&](gpu::Batch& batch) {
glm::mat4 projMat;
Transform viewMat;
@ -183,48 +179,35 @@ void DrawItemSelection::run(const RenderContextPointer& renderContext, const Ite
// bind the one gpu::Pipeline we need
batch.setPipeline(getDrawItemBoundPipeline());
auto drawItemBounds = [&](const render::ItemIDs itemIDs, const gpu::BufferPointer buffer) {
render::ItemBounds itemBounds;
for (const auto& itemID : itemIDs) {
auto& item = scene->getItem(itemID);
auto itemBound = item.getBound();
if (!itemBound.isInvalid()) {
itemBounds.emplace_back(itemID, itemBound);
}
}
if (itemBounds.size() > 0) {
buffer->setData(itemBounds.size() * sizeof(render::ItemBound), (const gpu::Byte*) itemBounds.data());
batch.setResourceBuffer(0, buffer);
batch.draw(gpu::LINES, (gpu::uint32) itemBounds.size() * 24, 0);
}
};
if (_showInsideItems) {
for (const auto& itemID : inSelection.insideItems) {
auto& item = scene->getItem(itemID);
auto itemBound = item.getBound();
auto itemCell = scene->getSpatialTree().getCellLocation(item.getCell());
glm::ivec4 cellLocation(0, 0, 0, itemCell.depth);
batch.draw(gpu::LINES, 24, 0);
}
drawItemBounds(inSelection.insideItems, _boundsBufferInside);
}
if (_showInsideSubcellItems) {
for (const auto& itemID : inSelection.insideSubcellItems) {
auto& item = scene->getItem(itemID);
auto itemBound = item.getBound();
auto itemCell = scene->getSpatialTree().getCellLocation(item.getCell());
glm::ivec4 cellLocation(0, 0, 1, itemCell.depth);
batch.draw(gpu::LINES, 24, 0);
}
drawItemBounds(inSelection.insideSubcellItems, _boundsBufferInsideSubcell);
}
if (_showPartialItems) {
for (const auto& itemID : inSelection.partialItems) {
auto& item = scene->getItem(itemID);
auto itemBound = item.getBound();
auto itemCell = scene->getSpatialTree().getCellLocation(item.getCell());
glm::ivec4 cellLocation(0, 0, 0, itemCell.depth);
batch.draw(gpu::LINES, 24, 0);
}
drawItemBounds(inSelection.partialItems, _boundsBufferPartial);
}
if (_showPartialSubcellItems) {
for (const auto& itemID : inSelection.partialSubcellItems) {
auto& item = scene->getItem(itemID);
auto itemBound = item.getBound();
auto itemCell = scene->getSpatialTree().getCellLocation(item.getCell());
glm::ivec4 cellLocation(0, 0, 1, itemCell.depth);
batch.draw(gpu::LINES, 24, 0);
}
drawItemBounds(inSelection.partialSubcellItems, _boundsBufferPartialSubcell);
}
batch.setResourceBuffer(0, 0);
});
}

View file

@ -52,7 +52,6 @@ namespace render {
class DrawSceneOctree {
gpu::PipelinePointer _drawCellBoundsPipeline;
gpu::BufferPointer _cells;
gpu::PipelinePointer _drawLODReticlePipeline;
gpu::PipelinePointer _drawItemBoundPipeline;
@ -107,6 +106,10 @@ namespace render {
class DrawItemSelection {
gpu::PipelinePointer _drawItemBoundPipeline;
gpu::BufferPointer _boundsBufferInside;
gpu::BufferPointer _boundsBufferInsideSubcell;
gpu::BufferPointer _boundsBufferPartial;
gpu::BufferPointer _boundsBufferPartialSubcell;
bool _showInsideItems; // initialized by Config
bool _showInsideSubcellItems; // initialized by Config

View file

@ -51,7 +51,7 @@ const gpu::PipelinePointer DrawStatus::getDrawItemBoundsPipeline() {
const gpu::PipelinePointer DrawStatus::getDrawItemStatusPipeline() {
if (!_drawItemStatusPipeline) {
gpu::ShaderPointer program = gpu::Shader::createProgram(shader::render::program::blurGaussianDepthAwareV);
gpu::ShaderPointer program = gpu::Shader::createProgram(shader::render::program::drawItemStatus);
auto state = std::make_shared<gpu::State>();
@ -92,36 +92,30 @@ void DrawStatus::run(const RenderContextPointer& renderContext, const Input& inp
const auto& inItems = input.get0();
const auto jitter = input.get1();
// FIrst thing, we collect the bound and the status for all the items we want to render
// First thing, we collect the bound and the status for all the items we want to render
int nbItems = 0;
render::ItemBounds itemBounds;
std::vector<std::pair<glm::ivec4, glm::ivec4>> itemStatus;
{
_itemBounds.resize(inItems.size());
_itemStatus.resize(inItems.size());
_itemCells.resize(inItems.size());
// AABox* itemAABox = reinterpret_cast<AABox*> (_itemBounds->editData());
// glm::ivec4* itemStatus = reinterpret_cast<glm::ivec4*> (_itemStatus->editData());
// Octree::Location* itemCell = reinterpret_cast<Octree::Location*> (_itemCells->editData());
for (size_t i = 0; i < inItems.size(); ++i) {
const auto& item = inItems[i];
if (!item.bound.isInvalid()) {
if (!item.bound.isNull()) {
_itemBounds[i] = item.bound;
itemBounds.emplace_back(render::ItemBound(item.id, item.bound));
} else {
_itemBounds[i].setBox(item.bound.getCorner(), 0.1f);
itemBounds.emplace_back(item.id, AABox(item.bound.getCorner(), 0.1f));
}
auto& itemScene = scene->getItem(item.id);
_itemCells[i] = scene->getSpatialTree().getCellLocation(itemScene.getCell());
auto itemStatusPointer = itemScene.getStatus();
if (itemStatusPointer) {
itemStatus.push_back(std::pair<glm::ivec4, glm::ivec4>());
// 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++) {
auto& value = (vec4Num ? _itemStatus[i].first : _itemStatus[i].second);
auto& value = (vec4Num ? itemStatus[nbItems].first : itemStatus[nbItems].second);
value = glm::ivec4(Item::Status::Value::INVALID.getPackedData());
for (int component = 0; component < VEC4_LENGTH; component++) {
valueNum = vec4Num * VEC4_LENGTH + component;
@ -131,7 +125,8 @@ void DrawStatus::run(const RenderContextPointer& renderContext, const Input& inp
}
}
} else {
_itemStatus[i].first = _itemStatus[i].second = glm::ivec4(Item::Status::Value::INVALID.getPackedData());
auto invalid = glm::ivec4(Item::Status::Value::INVALID.getPackedData());
itemStatus.emplace_back(invalid, invalid);
}
nbItems++;
}
@ -142,7 +137,11 @@ void DrawStatus::run(const RenderContextPointer& renderContext, const Input& inp
return;
}
// Allright, something to render let's do it
if (!_boundsBuffer) {
_boundsBuffer = std::make_shared<gpu::Buffer>(sizeof(render::ItemBound));
}
// Alright, something to render let's do it
gpu::doInBatch("DrawStatus::run", args->_context, [&](gpu::Batch& batch) {
glm::mat4 projMat;
Transform viewMat;
@ -158,32 +157,24 @@ void DrawStatus::run(const RenderContextPointer& renderContext, const Input& inp
// bind the one gpu::Pipeline we need
batch.setPipeline(getDrawItemBoundsPipeline());
//AABox* itemAABox = reinterpret_cast<AABox*> (_itemBounds->editData());
//glm::ivec4* itemStatus = reinterpret_cast<glm::ivec4*> (_itemStatus->editData());
//Octree::Location* itemCell = reinterpret_cast<Octree::Location*> (_itemCells->editData());
const unsigned int VEC3_ADRESS_OFFSET = 3;
_boundsBuffer->setData(itemBounds.size() * sizeof(render::ItemBound), (const gpu::Byte*) itemBounds.data());
if (_showDisplay) {
for (int i = 0; i < nbItems; i++) {
//batch._glUniform3fv(gpu::slot::uniform::Extra0, 1, (const float*)&(_itemBounds[i]));
//batch._glUniform3fv(gpu::slot::uniform::Extra1, 1, ((const float*)&(_itemBounds[i])) + VEC3_ADRESS_OFFSET);
//glm::ivec4 cellLocation(_itemCells[i].pos, _itemCells[i].depth);
//batch._glUniform4iv(_drawItemCellLocLoc, 1, ((const int*)(&cellLocation)));
batch.draw(gpu::LINES, 24, 0);
}
batch.setResourceBuffer(0, _boundsBuffer);
batch.draw(gpu::LINES, (gpu::uint32) itemBounds.size() * 24, 0);
}
batch.setResourceBuffer(0, 0);
batch.setResourceTexture(0, gpu::TextureView(getStatusIconMap(), 0));
batch.setPipeline(getDrawItemStatusPipeline());
if (_showNetwork) {
for (int i = 0; i < nbItems; i++) {
batch._glUniform3fv(gpu::slot::uniform::Extra0, 1, (const float*)&(_itemBounds[i]));
batch._glUniform3fv(gpu::slot::uniform::Extra1, 1, ((const float*)&(_itemBounds[i])) + VEC3_ADRESS_OFFSET);
batch._glUniform4iv(gpu::slot::uniform::Extra2, 1, (const int*)&(_itemStatus[i].first));
batch._glUniform4iv(gpu::slot::uniform::Extra3, 1, (const int*)&(_itemStatus[i].second));
for (size_t i = 0; i < itemBounds.size(); i++) {
batch._glUniform3fv(gpu::slot::uniform::Extra0, 1, (const float*)&itemBounds[i].bound.getCorner());
batch._glUniform3fv(gpu::slot::uniform::Extra1, 1, ((const float*)&itemBounds[i].bound.getScale()));
batch._glUniform4iv(gpu::slot::uniform::Extra2, 1, (const int*)&(itemStatus[i].first));
batch._glUniform4iv(gpu::slot::uniform::Extra3, 1, (const int*)&(itemStatus[i].second));
batch.draw(gpu::TRIANGLES, 24 * NUM_STATUS_VEC4_PER_ITEM, 0);
}
}

View file

@ -62,12 +62,7 @@ namespace render {
gpu::PipelinePointer _drawItemBoundsPipeline;
gpu::PipelinePointer _drawItemStatusPipeline;
std::vector<AABox> _itemBounds;
std::vector<std::pair<glm::ivec4, glm::ivec4>> _itemStatus;
std::vector<Octree::Location> _itemCells;
//gpu::BufferPointer _itemBounds;
//gpu::BufferPointer _itemCells;
//gpu::BufferPointer _itemStatus;
gpu::BufferPointer _boundsBuffer;
gpu::TexturePointer _statusIconMap;
};
}

View file

@ -321,6 +321,7 @@ inline QDebug operator<<(QDebug debug, const ItemFilter& me) {
// Handy type to just pass the ID and the bound of an item
class ItemBound {
public:
ItemBound() {}
ItemBound(ItemID id) : id(id) { }
ItemBound(ItemID id, const AABox& bound) : id(id), bound(bound) { }

View file

@ -24,7 +24,6 @@ layout(location=GPU_UNIFORM_EXTRA0) uniform ivec4 inCellLocation;
layout(location=0) out vec4 varColor;
void main(void) {
const vec4 UNIT_BOX[8] = vec4[8](
vec4(0.0, 0.0, 0.0, 1.0),

View file

@ -20,10 +20,8 @@
<@include gpu/Color.slh@>
<$declareColorWheel()$>
layout(location=GPU_UNIFORM_COLOR) uniform vec4 inColor;
struct ItemBound {
vec4 id_boundPos;
vec4 boundDim_s;
@ -48,8 +46,6 @@ ItemBound getItemBound(int i) {
}
#endif
layout(location=0) out vec4 varColor;
layout(location=1) out vec2 varTexcoord;

View file

@ -19,7 +19,7 @@ Column {
Component.onCompleted: {
sceneOctree.enabled = true;
itemSelection.enabled = true;
itemSelection.enabled = true;
sceneOctree.showVisibleCells = false;
sceneOctree.showEmptyCells = false;
itemSelection.showInsideItems = false;
@ -29,9 +29,9 @@ Column {
}
Component.onDestruction: {
sceneOctree.enabled = false;
itemSelection.enabled = false;
itemSelection.enabled = false;
Render.getConfig("RenderMainView.FetchSceneSelection").freezeFrustum = false;
Render.getConfig("RenderMainView.CullSceneSelection").freezeFrustum = false;
Render.getConfig("RenderMainView.CullSceneSelection").freezeFrustum = false;
}
GroupBox {
@ -44,7 +44,7 @@ Column {
CheckBox {
text: "Freeze Culling Frustum"
checked: false
onCheckedChanged: {
onCheckedChanged: {
Render.getConfig("RenderMainView.FetchSceneSelection").freezeFrustum = checked;
Render.getConfig("RenderMainView.CullSceneSelection").freezeFrustum = checked;
}
@ -88,15 +88,19 @@ Column {
text: "Partial Sub-cell Items"
checked: false
onCheckedChanged: { root.itemSelection.showPartialSubcellItems = checked }
}
}
}
}
}
}
GroupBox {
title: "Render Items"
anchors.left: parent.left;
anchors.right: parent.right;
Column{
anchors.left: parent.left;
anchors.right: parent.right;
Repeater {
model: [ "Opaque:RenderMainView.DrawOpaqueDeferred", "Transparent:RenderMainView.DrawTransparentDeferred", "Light:RenderMainView.DrawLight",
"Opaque Overlays:RenderMainView.DrawOverlay3DOpaque", "Transparent Overlays:RenderMainView.DrawOverlay3DTransparent" ]