Added shared DebugDraw singleton.

This commit is contained in:
Anthony J. Thibault 2015-09-22 19:57:23 -07:00
parent d53295655f
commit d04f4d4b2b
5 changed files with 123 additions and 26 deletions
interface/src/avatar
libraries

View file

@ -47,6 +47,7 @@
#include "Recorder.h"
#include "Util.h"
#include "InterfaceLogging.h"
#include "DebugDraw.h"
using namespace std;
@ -1358,6 +1359,9 @@ void MyAvatar::preRender(RenderArgs* renderArgs) {
}
}
DebugDraw::getInstance().updateMyAvatarPos(getPosition());
DebugDraw::getInstance().updateMyAvatarRot(getOrientation());
if (shouldDrawHead != _prevShouldDrawHead) {
_skeletonModel.setCauterizeBones(!shouldDrawHead);
}

View file

@ -13,6 +13,7 @@
#include "AbstractViewStateInterface.h"
#include "RenderUtilsLogging.h"
#include "GLMHelpers.h"
#include "DebugDraw.h"
#include "AnimDebugDraw.h"
@ -67,13 +68,9 @@ namespace render {
}
}
static AnimDebugDraw* instance = nullptr;
AnimDebugDraw& AnimDebugDraw::getInstance() {
if (!instance) {
instance = new AnimDebugDraw();
}
return *instance;
static AnimDebugDraw instance;
return instance;
}
static uint32_t toRGBA(uint8_t r, uint8_t g, uint8_t b, uint8_t a) {
@ -176,14 +173,6 @@ void AnimDebugDraw::removePoses(const std::string& key) {
_poses.erase(key);
}
void AnimDebugDraw::addPose(const std::string& key, const AnimPose& pose, const AnimPose& rootPose) {
_singlePoses[key] = SinglePoseInfo(pose, rootPose);
}
void AnimDebugDraw::removePose(const std::string& key) {
_singlePoses.erase(key);
}
static const uint32_t red = toRGBA(255, 0, 0, 255);
static const uint32_t green = toRGBA(0, 255, 0, 255);
static const uint32_t blue = toRGBA(0, 0, 255, 255);
@ -380,7 +369,11 @@ void AnimDebugDraw::update() {
}
}
numVerts += _singlePoses.size() * VERTICES_PER_BONE;
// count marker verts from shared DebugDraw singleton
auto markerMap = DebugDraw::getInstance().getMarkerMap();
numVerts += markerMap.size() * VERTICES_PER_BONE;
auto myAvatarMarkerMap = DebugDraw::getInstance().getMyAvatarMarkerMap();
numVerts += myAvatarMarkerMap.size() * VERTICES_PER_BONE;
data._vertexBuffer->resize(sizeof(Vertex) * numVerts);
Vertex* verts = (Vertex*)data._vertexBuffer->editData();
@ -486,11 +479,22 @@ void AnimDebugDraw::update() {
}
}
for (auto& iter : _singlePoses) {
AnimPose pose = std::get<0>(iter.second);
AnimPose rootPose = std::get<1>(iter.second);
const float radius = POSE_RADIUS / (pose.scale.x * rootPose.scale.x);
addBone(rootPose, pose, radius, v);
// draw markers from shared DebugDraw singleton
for (auto& iter : markerMap) {
glm::quat rot = std::get<0>(iter.second);
glm::vec3 pos = std::get<1>(iter.second);
glm::vec4 color = std::get<2>(iter.second); // TODO: currently ignored.
const float radius = POSE_RADIUS;
addBone(AnimPose::identity, AnimPose(glm::vec3(1), rot, pos), radius, v);
}
AnimPose myAvatarPose(glm::vec3(1), DebugDraw::getInstance().getMyAvatarRot(), DebugDraw::getInstance().getMyAvatarPos());
for (auto& iter : myAvatarMarkerMap) {
glm::quat rot = std::get<0>(iter.second);
glm::vec3 pos = std::get<1>(iter.second);
glm::vec4 color = std::get<2>(iter.second); // TODO: currently ignored.
const float radius = POSE_RADIUS;
addBone(myAvatarPose, AnimPose(glm::vec3(1), rot, pos), radius, v);
}
assert(numVerts == (v - verts));

View file

@ -39,10 +39,6 @@ public:
void addPoses(const std::string& key, AnimSkeleton::ConstPointer skeleton, const AnimPoseVec& poses, const AnimPose& rootPose, const glm::vec4& color);
void removePoses(const std::string& key);
// draw a single pose
void addPose(const std::string& key, const AnimPose& rootPose, const AnimPose& pose);
void removePose(const std::string& key);
void update();
protected:
@ -55,12 +51,10 @@ protected:
typedef std::tuple<AnimSkeleton::ConstPointer, AnimPose, glm::vec4> SkeletonInfo;
typedef std::tuple<AnimNode::ConstPointer, AnimPose, glm::vec4> AnimNodeInfo;
typedef std::tuple<AnimSkeleton::ConstPointer, AnimPoseVec, AnimPose, glm::vec4> PosesInfo;
typedef std::tuple<AnimPose, AnimPose> SinglePoseInfo;
std::unordered_map<std::string, SkeletonInfo> _skeletons;
std::unordered_map<std::string, AnimNodeInfo> _animNodes;
std::unordered_map<std::string, PosesInfo> _poses;
std::unordered_map<std::string, SinglePoseInfo> _singlePoses;
// no copies
AnimDebugDraw(const AnimDebugDraw&) = delete;

View file

@ -0,0 +1,40 @@
//
// DebugDraw.cpp
//
// 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 "DebugDraw.h"
DebugDraw& DebugDraw::getInstance() {
static DebugDraw instance;
return instance;
}
DebugDraw::DebugDraw() {
}
DebugDraw::~DebugDraw() {
}
void DebugDraw::addMarker(const std::string& key, const glm::quat& rotation, const glm::vec3& position, const glm::vec4& color) {
_markers[key] = MarkerInfo(rotation, position, color);
}
void DebugDraw::removeMarker(const std::string& key) {
_markers.erase(key);
}
void DebugDraw::addMyAvatarMarker(const std::string& key, const glm::quat& rotation, const glm::vec3& position, const glm::vec4& color) {
_myAvatarMarkers[key] = MarkerInfo(rotation, position, color);
}
void DebugDraw::removeMyAvatarMarker(const std::string& key) {
_myAvatarMarkers.erase(key);
}

View file

@ -0,0 +1,55 @@
//
// DebugDraw.h
//
// 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_DebugDraw_h
#define hifi_DebugDraw_h
#include <unordered_map>
#include <tuple>
#include <string>
#include <glm/glm.hpp>
#include <glm/gtc/quaternion.hpp>
class DebugDraw {
public:
static DebugDraw& getInstance();
DebugDraw();
~DebugDraw();
// world space maker
void addMarker(const std::string& key, const glm::quat& rotation, const glm::vec3& position, const glm::vec4& color);
void removeMarker(const std::string& key);
// myAvatar relative marker
void addMyAvatarMarker(const std::string& key, const glm::quat& rotation, const glm::vec3& position, const glm::vec4& color);
void removeMyAvatarMarker(const std::string& key);
using MarkerInfo = std::tuple<glm::quat, glm::vec3, glm::vec4>;
using MarkerMap = std::unordered_map<std::string, MarkerInfo>;
//
// accessors used by renderer
//
const MarkerMap& getMarkerMap() const { return _markers; }
const MarkerMap& getMyAvatarMarkerMap() const { return _myAvatarMarkers; }
void updateMyAvatarPos(const glm::vec3& pos) { _myAvatarPos = pos; }
const glm::vec3& getMyAvatarPos() const { return _myAvatarPos; }
void updateMyAvatarRot(const glm::quat& rot) { _myAvatarRot = rot; }
const glm::quat& getMyAvatarRot() const { return _myAvatarRot; }
protected:
MarkerMap _markers;
MarkerMap _myAvatarMarkers;
glm::quat _myAvatarRot;
glm::vec3 _myAvatarPos;
};
#endif // hifi_DebugDraw_h