mirror of
https://thingvellir.net/git/overte
synced 2025-03-27 23:52:03 +01:00
first draft at using the status of the item for representing stats and current data about it in the DrawStatus phase
This commit is contained in:
parent
09f32f6839
commit
20cb519c14
8 changed files with 226 additions and 6 deletions
|
@ -18,7 +18,8 @@
|
|||
<@elif GLPROFILE == MAC_GL @>
|
||||
<@def GPU_FEATURE_PROFILE GPU_LEGACY@>
|
||||
<@def GPU_TRANSFORM_PROFILE GPU_LEGACY@>
|
||||
<@def VERSION_HEADER #version 120@>
|
||||
<@def VERSION_HEADER #version 120
|
||||
#extension GL_EXT_gpu_shader4 : enable@>
|
||||
<@else@>
|
||||
<@def GPU_FEATURE_PROFILE GPU_LEGACY@>
|
||||
<@def GPU_TRANSFORM_PROFILE GPU_LEGACY@>
|
||||
|
|
|
@ -17,6 +17,8 @@
|
|||
#include "RenderArgs.h"
|
||||
#include "TextureCache.h"
|
||||
|
||||
#include "render/DrawStatus.h"
|
||||
|
||||
#include <PerfStat.h>
|
||||
|
||||
#include "overlay3D_vert.h"
|
||||
|
@ -49,6 +51,7 @@ RenderDeferredTask::RenderDeferredTask() : Task() {
|
|||
)));
|
||||
_jobs.push_back(Job(new CullItems::JobModel("CullOpaque", _jobs.back().getOutput())));
|
||||
_jobs.push_back(Job(new DepthSortItems::JobModel("DepthSortOpaque", _jobs.back().getOutput())));
|
||||
auto& renderedOpaques = _jobs.back().getOutput();
|
||||
_jobs.push_back(Job(new DrawOpaqueDeferred::JobModel("DrawOpaqueDeferred", _jobs.back().getOutput())));
|
||||
_jobs.push_back(Job(new DrawLight::JobModel("DrawLight")));
|
||||
_jobs.push_back(Job(new ResetGLState::JobModel()));
|
||||
|
@ -65,6 +68,7 @@ RenderDeferredTask::RenderDeferredTask() : Task() {
|
|||
_jobs.push_back(Job(new CullItems::JobModel("CullTransparent", _jobs.back().getOutput())));
|
||||
_jobs.push_back(Job(new DepthSortItems::JobModel("DepthSortTransparent", _jobs.back().getOutput(), DepthSortItems(false))));
|
||||
_jobs.push_back(Job(new DrawTransparentDeferred::JobModel("TransparentDeferred", _jobs.back().getOutput())));
|
||||
_jobs.push_back(Job(new render::DrawStatus::JobModel("DrawStatus", renderedOpaques)));
|
||||
_jobs.push_back(Job(new DrawOverlay3D::JobModel("DrawOverlay3D")));
|
||||
_jobs.push_back(Job(new ResetGLState::JobModel()));
|
||||
}
|
||||
|
|
101
libraries/render/src/render/DrawStatus.cpp
Normal file
101
libraries/render/src/render/DrawStatus.cpp
Normal file
|
@ -0,0 +1,101 @@
|
|||
//
|
||||
// DrawStatus.cpp
|
||||
// render/src/render
|
||||
//
|
||||
// Created by Niraj Venkat on 5/21/15.
|
||||
// Copyright 20154 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 <algorithm>
|
||||
#include <assert.h>
|
||||
|
||||
#include "DrawStatus.h"
|
||||
|
||||
#include <PerfStat.h>
|
||||
#include "gpu/GPULogging.h"
|
||||
|
||||
|
||||
#include "gpu/Batch.h"
|
||||
#include "gpu/Context.h"
|
||||
|
||||
#include "ViewFrustum.h"
|
||||
#include "RenderArgs.h"
|
||||
|
||||
#include "drawItemBounds_vert.h"
|
||||
#include "drawItemBounds_frag.h"
|
||||
|
||||
using namespace render;
|
||||
|
||||
|
||||
|
||||
const gpu::PipelinePointer& DrawStatus::getDrawItemBoundsPipeline() {
|
||||
if (!_drawItemBoundsPipeline) {
|
||||
auto vs = gpu::ShaderPointer(gpu::Shader::createVertex(std::string(drawItemBounds_vert)));
|
||||
auto ps = gpu::ShaderPointer(gpu::Shader::createPixel(std::string(drawItemBounds_frag)));
|
||||
gpu::ShaderPointer program = gpu::ShaderPointer(gpu::Shader::createProgram(vs, ps));
|
||||
|
||||
gpu::Shader::BindingSet slotBindings;
|
||||
gpu::Shader::makeProgram(*program, slotBindings);
|
||||
|
||||
gpu::StatePointer state = gpu::StatePointer(new 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
|
||||
_drawItemBoundsPipeline.reset(gpu::Pipeline::create(program, state));
|
||||
}
|
||||
return _drawItemBoundsPipeline;
|
||||
}
|
||||
|
||||
void DrawStatus::run(const SceneContextPointer& sceneContext, const RenderContextPointer& renderContext, const ItemIDsBounds& inItems) {
|
||||
assert(renderContext->args);
|
||||
assert(renderContext->args->_viewFrustum);
|
||||
RenderArgs* args = renderContext->args;
|
||||
|
||||
gpu::Batch batch;
|
||||
|
||||
glm::mat4 projMat;
|
||||
Transform viewMat;
|
||||
args->_viewFrustum->evalProjectionMatrix(projMat);
|
||||
args->_viewFrustum->evalViewTransform(viewMat);
|
||||
if (args->_renderMode == RenderArgs::MIRROR_RENDER_MODE) {
|
||||
viewMat.postScale(glm::vec3(-1.0f, 1.0f, 1.0f));
|
||||
}
|
||||
batch.setProjectionTransform(projMat);
|
||||
batch.setViewTransform(viewMat);
|
||||
|
||||
|
||||
// batch.setModelTransform(Transform());
|
||||
// bind the unit cube geometry
|
||||
|
||||
// bind the one gpu::Pipeline we need
|
||||
batch.setPipeline(getDrawItemBoundsPipeline());
|
||||
|
||||
for (auto& item : inItems) {
|
||||
if (!item.bounds.isInvalid()) {
|
||||
Transform model;
|
||||
model.setTranslation(item.bounds.getCorner());
|
||||
if (!item.bounds.isNull()) {
|
||||
model.setScale(item.bounds.getDimensions());
|
||||
}
|
||||
|
||||
batch.setModelTransform(model);
|
||||
batch.draw(gpu::LINE_STRIP, 13, 0);
|
||||
}
|
||||
}
|
||||
|
||||
// Before rendering the batch make sure we re in sync with gl state
|
||||
args->_context->syncCache();
|
||||
renderContext->args->_context->syncCache();
|
||||
args->_context->render((batch));
|
||||
args->_batch = nullptr;
|
||||
|
||||
}
|
34
libraries/render/src/render/DrawStatus.h
Normal file
34
libraries/render/src/render/DrawStatus.h
Normal file
|
@ -0,0 +1,34 @@
|
|||
//
|
||||
// DrawStatus.h
|
||||
// render/src/render
|
||||
//
|
||||
// Created by Niraj Venkat on 6/29/15.
|
||||
// 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_DrawStatus_h
|
||||
#define hifi_render_DrawStatus_h
|
||||
|
||||
#include "DrawTask.h"
|
||||
#include "gpu/Batch.h"
|
||||
#include <PerfStat.h>
|
||||
|
||||
|
||||
namespace render {
|
||||
class DrawStatus {
|
||||
gpu::PipelinePointer _drawItemBoundsPipeline;
|
||||
|
||||
public:
|
||||
|
||||
void run(const SceneContextPointer& sceneContext, const RenderContextPointer& renderContext, const ItemIDsBounds& inItems);
|
||||
|
||||
typedef Job::ModelI<DrawStatus, ItemIDsBounds> JobModel;
|
||||
|
||||
const gpu::PipelinePointer& getDrawItemBoundsPipeline();
|
||||
};
|
||||
}
|
||||
|
||||
#endif // hifi_render_DrawStatus_h
|
|
@ -128,9 +128,10 @@ struct ItemBound {
|
|||
float _nearDepth = 0.0f;
|
||||
float _farDepth = 0.0f;
|
||||
ItemID _id = 0;
|
||||
AABox _bounds;
|
||||
|
||||
ItemBound() {}
|
||||
ItemBound(float centerDepth, float nearDepth, float farDepth, ItemID id) : _centerDepth(centerDepth), _nearDepth(nearDepth), _farDepth(farDepth), _id(id) {}
|
||||
ItemBound(float centerDepth, float nearDepth, float farDepth, ItemID id, const AABox& bounds) : _centerDepth(centerDepth), _nearDepth(nearDepth), _farDepth(farDepth), _id(id), _bounds(bounds) {}
|
||||
};
|
||||
|
||||
struct FrontToBackSort {
|
||||
|
@ -167,7 +168,7 @@ void render::depthSortItems(const SceneContextPointer& sceneContext, const Rende
|
|||
auto bound = itemDetails.bounds; // item.getBound();
|
||||
float distance = args->_viewFrustum->distanceToCamera(bound.calcCenter());
|
||||
|
||||
itemBounds.emplace_back(ItemBound(distance, distance, distance, itemDetails.id));
|
||||
itemBounds.emplace_back(ItemBound(distance, distance, distance, itemDetails.id, bound));
|
||||
}
|
||||
|
||||
// sort against Z
|
||||
|
@ -181,7 +182,7 @@ void render::depthSortItems(const SceneContextPointer& sceneContext, const Rende
|
|||
|
||||
// FInally once sorted result to a list of itemID
|
||||
for (auto& itemBound : itemBounds) {
|
||||
outItems.emplace_back(itemBound._id);
|
||||
outItems.emplace_back(ItemIDAndBounds(itemBound._id, itemBound._bounds));
|
||||
}
|
||||
}
|
||||
|
||||
|
|
|
@ -196,12 +196,19 @@ public:
|
|||
// Bound is the AABBox fully containing this item
|
||||
typedef AABox Bound;
|
||||
|
||||
// Stats records the life history and performances of this item while performing at rendering and updating.
|
||||
// Status records the life history and performances of this item while performing at rendering and updating.
|
||||
// This is Used for monitoring and dynamically adjust the quality
|
||||
class Stats {
|
||||
class Status {
|
||||
public:
|
||||
typedef glm::ivec2 Value;
|
||||
typedef std::function<Value()> Getter;
|
||||
|
||||
int _firstFrame;
|
||||
std::vector<Getter> _values;
|
||||
|
||||
void addGetter(Getter& getter) { _values.push_back(getter); }
|
||||
};
|
||||
typedef std::shared_ptr<Status> StatusPointer;
|
||||
|
||||
// Update Functor
|
||||
class UpdateFunctorInterface {
|
||||
|
@ -222,7 +229,14 @@ public:
|
|||
virtual const model::MaterialKey getMaterialKey() const = 0;
|
||||
|
||||
~PayloadInterface() {}
|
||||
|
||||
// Status interface is local to the base class
|
||||
const StatusPointer& getStatus() const { return _status; }
|
||||
void addStatusGetter(Status::Getter& getter) { _status->addGetter(getter); }
|
||||
|
||||
protected:
|
||||
StatusPointer _status;
|
||||
|
||||
friend class Item;
|
||||
virtual void update(const UpdateFunctorPointer& functor) = 0;
|
||||
};
|
||||
|
@ -253,6 +267,9 @@ public:
|
|||
// Shape Type Interface
|
||||
const model::MaterialKey getMaterialKey() const { return _payload->getMaterialKey(); }
|
||||
|
||||
// Access the status
|
||||
const StatusPointer& getStatus() const { return _payload->getStatus(); }
|
||||
|
||||
protected:
|
||||
PayloadPointer _payload;
|
||||
ItemKey _key;
|
||||
|
|
19
libraries/render/src/render/drawItemBounds.slf
Normal file
19
libraries/render/src/render/drawItemBounds.slf
Normal file
|
@ -0,0 +1,19 @@
|
|||
<@include gpu/Config.slh@>
|
||||
<$VERSION_HEADER$>
|
||||
// Generated on <$_SCRIBE_DATE$>
|
||||
// drawItemBounds.frag
|
||||
// fragment shader
|
||||
//
|
||||
// Created by Sam Gateau on 6/29/15.
|
||||
// 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
|
||||
//
|
||||
|
||||
varying vec4 varColor;
|
||||
|
||||
|
||||
void main(void) {
|
||||
gl_FragColor = vec4(1.0, 1.0, 1.0, 1.0);
|
||||
}
|
43
libraries/render/src/render/drawItemBounds.slv
Normal file
43
libraries/render/src/render/drawItemBounds.slv
Normal file
|
@ -0,0 +1,43 @@
|
|||
<@include gpu/Config.slh@>
|
||||
<$VERSION_HEADER$>
|
||||
// Generated on <$_SCRIBE_DATE$>
|
||||
//
|
||||
// drawItemBounds.slv
|
||||
// vertex shader
|
||||
//
|
||||
// Created by Sam Gateau on 6/29/2015.
|
||||
// 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()$>
|
||||
|
||||
void main(void) {
|
||||
const vec4 UNIT_BOX[13] = vec4[13](
|
||||
vec4(0.0, 0.0, 0.0, 1.0),
|
||||
vec4(1.0, 0.0, 0.0, 1.0),
|
||||
vec4(1.0, 1.0, 0.0, 1.0),
|
||||
vec4(0.0, 1.0, 0.0, 1.0),
|
||||
vec4(0.0, 0.0, 0.0, 1.0),
|
||||
vec4(1.0, 0.0, 0.0, 1.0),
|
||||
vec4(1.0, 0.0, 1.0, 1.0),
|
||||
vec4(0.0, 0.0, 1.0, 1.0),
|
||||
vec4(0.0, 0.0, 0.0, 1.0),
|
||||
vec4(0.0, 1.0, 0.0, 1.0),
|
||||
vec4(0.0, 1.0, 1.0, 1.0),
|
||||
vec4(0.0, 0.0, 1.0, 1.0),
|
||||
vec4(0.0, 0.0, 0.0, 1.0)
|
||||
);
|
||||
vec4 pos = UNIT_BOX[gl_VertexID];
|
||||
|
||||
// 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