3
0
Fork 0
mirror of https://github.com/lubosz/overte.git synced 2025-04-27 05:35:37 +02:00

Prototyping the ResourceBuffer with the DrawBounds Job, yeah

This commit is contained in:
Sam Cake 2017-04-13 00:51:02 -07:00
parent d41f34ce8d
commit 78bfc006f1
4 changed files with 41 additions and 9 deletions

View file

@ -166,6 +166,18 @@ void DrawBounds::run(const SceneContextPointer& sceneContext, const RenderContex
const Inputs& items) {
RenderArgs* args = renderContext->args;
auto numItems = items.size();
if (numItems == 0) {
return;
}
static const uint32_t sizeOfItemBound = sizeof(ItemBound);
if (!_drawBuffer) {
_drawBuffer = std::make_shared<gpu::Buffer>(sizeOfItemBound);
}
_drawBuffer->setData(numItems * sizeOfItemBound, (const gpu::Byte*) items.data());
gpu::doInBatch(args->_context, [&](gpu::Batch& batch) {
args->_batch = &batch;
@ -180,17 +192,23 @@ void DrawBounds::run(const SceneContextPointer& sceneContext, const RenderContex
// Bind program
batch.setPipeline(getPipeline());
assert(_cornerLocation >= 0);
assert(_scaleLocation >= 0);
// assert(_cornerLocation >= 0);
// assert(_scaleLocation >= 0);
// Render bounds
for (const auto& item : items) {
/* for (const auto& item : items) {
batch._glUniform3fv(_cornerLocation, 1, (const float*)(&item.bound.getCorner()));
batch._glUniform3fv(_scaleLocation, 1, (const float*)(&item.bound.getScale()));
static const int NUM_VERTICES_PER_CUBE = 24;
batch.draw(gpu::LINES, NUM_VERTICES_PER_CUBE, 0);
}
*/
batch.setResourceBuffer(0, _drawBuffer);
static const int NUM_VERTICES_PER_CUBE = 24;
batch.draw(gpu::LINES, NUM_VERTICES_PER_CUBE * numItems, 0);
});
}

View file

@ -67,6 +67,7 @@ private:
gpu::PipelinePointer _boundsPipeline;
int _cornerLocation { -1 };
int _scaleLocation { -1 };
gpu::BufferPointer _drawBuffer;
};
}

View file

@ -227,6 +227,7 @@ class ItemBound {
ItemID id;
AABox bound;
uint32_t padding;
};
// many Item Bounds in a vector

View file

@ -22,8 +22,14 @@ uniform vec3 inBoundPos;
uniform vec3 inBoundDim;
uniform ivec4 inCellLocation;
struct ItemBound {
vec4 id_boundPos;
vec4 boundDim_s;
};
layout(std140) buffer ssbo0Buffer {
vec4 perBoundData[];
ItemBound bounds[];
};
@ -55,11 +61,17 @@ void main(void) {
0, 4,
1, 5
);
vec4 cubeVec = UNIT_BOX[UNIT_BOX_LINE_INDICES[gl_VertexID]];
vec4 offset = perBoundData[gl_VertexID];
int boundID = gl_VertexID / 24;
int vertexID = gl_VertexID - boundID * 24;
vec4 pos = vec4(inBoundPos + inBoundDim * cubeVec.xyz, 1.0);
vec4 cubeVec = UNIT_BOX[UNIT_BOX_LINE_INDICES[vertexID]];
ItemBound bound = bounds[boundID];
vec3 boundPos = bound.id_boundPos.yzw;
vec3 boundDim = bound.boundDim_s.xyz;
vec4 pos = vec4(boundPos + boundDim * cubeVec.xyz, 1.0);
// standard transform
TransformCamera cam = getTransformCamera();
@ -68,7 +80,7 @@ void main(void) {
bool subcell = bool((inCellLocation.z));
float cellDepth = float(inCellLocation.w);
varColor = vec4(colorWheel(fract(cellDepth / 5.0)), 1.0 - float(subcell)) + offset;
varTexcoord = vec2(cubeVec.w, length(inBoundDim));
varColor = vec4(colorWheel(fract(cellDepth / 5.0)), 1.0 - float(subcell));
varTexcoord = vec2(cubeVec.w, length(boundDim));
}