working toward display icons for debug/status display

This commit is contained in:
Seth Alves 2015-11-10 10:15:58 -08:00
parent bc516c0b86
commit 8e466190e0
8 changed files with 56 additions and 16 deletions

View file

@ -12,6 +12,7 @@
#include "RenderDeferredTask.h"
#include <PerfStat.h>
#include <PathUtils.h>
#include <RenderArgs.h>
#include <ViewFrustum.h>
#include <gpu/Context.h>
@ -111,7 +112,11 @@ RenderDeferredTask::RenderDeferredTask() : Task() {
_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)));
// Grab a texture map representing the different status icons and assign that to the drawStatsuJob
auto iconMapPath = PathUtils::resourcesPath() + "images/hifi-logo.svg";
auto statusIconMap = DependencyManager::get<TextureCache>()->getImageTexture(iconMapPath);
_jobs.push_back(Job(new render::DrawStatus::JobModel("DrawStatus", renderedOpaques, DrawStatus(statusIconMap))));
_jobs.back().setEnabled(false);
@ -387,4 +392,4 @@ void DrawBackgroundDeferred::run(const SceneContextPointer& sceneContext, const
});
args->_batch = nullptr;
}
}

View file

@ -29,7 +29,7 @@ using namespace render;
const gpu::PipelinePointer& DrawStatus::getDrawItemBoundsPipeline() {
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)));
@ -56,13 +56,14 @@ const gpu::PipelinePointer& DrawStatus::getDrawItemBoundsPipeline() {
return _drawItemBoundsPipeline;
}
const gpu::PipelinePointer& DrawStatus::getDrawItemStatusPipeline() {
const gpu::PipelinePointer DrawStatus::getDrawItemStatusPipeline() {
if (!_drawItemStatusPipeline) {
auto vs = gpu::ShaderPointer(gpu::Shader::createVertex(std::string(drawItemStatus_vert)));
auto ps = gpu::ShaderPointer(gpu::Shader::createPixel(std::string(drawItemStatus_frag)));
gpu::ShaderPointer program = gpu::ShaderPointer(gpu::Shader::createProgram(vs, ps));
gpu::Shader::BindingSet slotBindings;
slotBindings.insert(gpu::Shader::Binding(std::string("iconStatusMap"), 0));
gpu::Shader::makeProgram(*program, slotBindings);
_drawItemStatusPosLoc = program->getUniforms().findLocation("inBoundPos");
@ -84,6 +85,14 @@ const gpu::PipelinePointer& DrawStatus::getDrawItemStatusPipeline() {
return _drawItemStatusPipeline;
}
void DrawStatus::setStatusIconMap(const gpu::TexturePointer& map) {
_statusIconMap = map;
}
const gpu::TexturePointer DrawStatus::getStatusIconMap() const {
return _statusIconMap;
}
void DrawStatus::run(const SceneContextPointer& sceneContext, const RenderContextPointer& renderContext, const ItemIDsBounds& inItems) {
assert(renderContext->args);
assert(renderContext->args->_viewFrustum);
@ -151,6 +160,8 @@ void DrawStatus::run(const SceneContextPointer& sceneContext, const RenderContex
batch.draw(gpu::LINES, 24, 0);
}
batch.setResourceTexture(0, gpu::TextureView(getStatusIconMap(), 0));
batch.setPipeline(getDrawItemStatusPipeline());
for (int i = 0; i < nbItems; i++) {
batch._glUniform3fv(_drawItemStatusPosLoc, 1, (const float*) (itemAABox + i));
@ -159,5 +170,6 @@ void DrawStatus::run(const SceneContextPointer& sceneContext, const RenderContex
batch.draw(gpu::TRIANGLES, 24, 0);
}
batch.setResourceTexture(0, 0);
});
}

View file

@ -28,15 +28,22 @@ namespace render {
gpu::PipelinePointer _drawItemStatusPipeline;
gpu::BufferPointer _itemBounds;
gpu::BufferPointer _itemStatus;
gpu::TexturePointer _statusIconMap;
public:
DrawStatus() {}
DrawStatus(const gpu::TexturePointer statusIconMap) { setStatusIconMap(statusIconMap); }
void run(const SceneContextPointer& sceneContext, const RenderContextPointer& renderContext, const ItemIDsBounds& inItems);
typedef Job::ModelI<DrawStatus, ItemIDsBounds> JobModel;
const gpu::PipelinePointer& getDrawItemBoundsPipeline();
const gpu::PipelinePointer& getDrawItemStatusPipeline();
const gpu::PipelinePointer getDrawItemBoundsPipeline();
const gpu::PipelinePointer getDrawItemStatusPipeline();
void setStatusIconMap(const gpu::TexturePointer& map);
const gpu::TexturePointer getStatusIconMap() const;
};
}

View file

@ -143,7 +143,7 @@ public:
const Varying getInput() const { return _input; }
ModelI(const std::string& name, const Varying& input): Concept(name), _input(input) {}
ModelI(const std::string& name, const Varying& input, Data data = Data()) : Concept(name), _data(data), _input(input) {}
ModelI(const std::string& name, Data data): Concept(name), _data(data) {}
void run(const SceneContextPointer& sceneContext, const RenderContextPointer& renderContext) {

View file

@ -72,7 +72,10 @@ void Item::Status::Value::setScale(float scale) {
void Item::Status::Value::setColor(float hue) {
// Convert the HUe from range [0, 360] to signed normalized value
const float HUE_MAX = 360.0f;
_color = (std::numeric_limits<unsigned short>::max() - 1) * 0.5f * (1.0f + std::max(std::min(hue, HUE_MAX), 0.0f) / HUE_MAX);
_color = (std::numeric_limits<unsigned char>::max()) * (std::max(std::min(hue, HUE_MAX), 0.0f) / HUE_MAX);
}
void Item::Status::Value::setIcon(unsigned char icon) {
_icon = icon;
}
void Item::Status::getPackedValues(glm::ivec4& values) const {

View file

@ -206,17 +206,21 @@ public:
// It can be scaled in the range [0, 1] and the color hue in the range [0, 360] representing the color wheel hue
class Value {
unsigned short _scale = 0xFFFF;
unsigned short _color = 0xFFFF;
unsigned char _color = 0xFF;
unsigned char _icon = 0xFF;
public:
const static Value INVALID; // Invalid value meanss the status won't show
Value() {}
Value(float scale, float hue) { setScale(scale); setColor(hue); }
Value(float scale, float hue, unsigned char icon = 0) { setScale(scale); setColor(hue); setIcon(icon); }
// It can be scaled in the range [0, 1]
void setScale(float scale);
// the color hue in the range [0, 360] representing the color wheel hue
void setColor(float hue);
// the icon to display in the range [0, 255], where 0 means no icon, just filled quad and anything else would
// hopefully have an icon available to display (see DrawStatusJob)
void setIcon(unsigned char icon);
// Standard color Hue
static const float RED; // 0.0f;

View file

@ -12,9 +12,16 @@
//
in vec4 varColor;
in vec3 varTexcoord;
out vec4 outFragColor;
uniform sampler2D _icons;
void main(void) {
outFragColor = varColor;
if (varTexcoord.z > 0.0f) {
outFragColor = texture(_icons, varTexcoord.xy) * varColor;
} else {
outFragColor = varColor;
}
}

View file

@ -17,6 +17,7 @@
<$declareStandardTransform()$>
out vec4 varColor;
out vec3 varTexcoord;
uniform vec3 inBoundPos;
uniform vec3 inBoundDim;
@ -43,9 +44,10 @@ vec3 paintRainbow(float normalizedHue) {
}
}
vec2 unpackStatus(int v) {
return vec2(clamp(float(int((v >> 0) & 0xFFFF) - 32727) / 32727.0, -1.0, 1.0),
clamp(float(int((v >> 16) & 0xFFFF) - 32727) / 32727.0, -1.0, 1.0));
vec3 unpackStatus(int v) {
return vec3(clamp(float(int((v >> 0) & 0xFFFF) - 32727) / 32727.0, -1.0, 1.0),
clamp(float(uint((v >> 16) & 0xFF)) / 255.0, 0.0, 1.0),
clamp(float(int((v >> 24) & 0xFF)), 0.0, 256.0));
}
void main(void) {
@ -78,14 +80,14 @@ void main(void) {
}
// unpack to get x and y satus
vec2 iconStatus = unpackStatus(inStatus[iconNum]);
vec3 iconStatus = unpackStatus(inStatus[iconNum]);
// Use the status for showing a color
varColor = vec4(paintRainbow(abs(iconStatus.y)), 1.0);
// Also changes the size of the notification
vec2 iconScale = ICON_PIXEL_SIZE;
iconScale = max(vec2(1, 1), (iconScale * iconStatus.x));
iconScale = max(vec2(0, 0), (iconScale * iconStatus.x));
//Offset icon to the right based on the iconNum
vec2 offset = vec2(iconNum * (ICON_PIXEL_SIZE.x + MARGIN_PIXEL_SIZE.x), 0);