mirror of
https://github.com/JulianGro/overte.git
synced 2025-04-09 13:12:40 +02:00
Added AnimDebugDraw to render-utils
This commit is contained in:
parent
f5dee717a1
commit
91ca13c66d
7 changed files with 226 additions and 2 deletions
|
@ -142,6 +142,8 @@
|
|||
#include "ui/AddressBarDialog.h"
|
||||
#include "ui/UpdateDialog.h"
|
||||
|
||||
#include "AnimDebugDraw.h"
|
||||
|
||||
|
||||
// ON WIndows PC, NVidia Optimus laptop, we want to enable NVIDIA GPU
|
||||
#if defined(Q_OS_WIN)
|
||||
|
@ -645,6 +647,8 @@ Application::Application(int& argc, char** argv, QElapsedTimer &startup_time) :
|
|||
|
||||
auto& packetReceiver = nodeList->getPacketReceiver();
|
||||
packetReceiver.registerListener(PacketType::DomainConnectionDenied, this, "handleDomainConnectionDeniedPacket");
|
||||
|
||||
AnimDebugDraw& add = AnimDebugDraw::getInstance();
|
||||
}
|
||||
|
||||
void Application::aboutToQuit() {
|
||||
|
|
144
libraries/render-utils/src/AnimDebugDraw.cpp
Normal file
144
libraries/render-utils/src/AnimDebugDraw.cpp
Normal file
|
@ -0,0 +1,144 @@
|
|||
//
|
||||
// AnimDebugDraw.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 "animdebugdraw_vert.h"
|
||||
#include "animdebugdraw_frag.h"
|
||||
#include <gpu/Batch.h>
|
||||
|
||||
#include "AnimDebugDraw.h"
|
||||
#include "AbstractViewStateInterface.h"
|
||||
|
||||
struct Vertex {
|
||||
glm::vec3 pos;
|
||||
uint32_t rgba;
|
||||
};
|
||||
|
||||
class AnimDebugDrawData {
|
||||
public:
|
||||
typedef render::Payload<AnimDebugDrawData> Payload;
|
||||
typedef Payload::DataPointer Pointer;
|
||||
|
||||
AnimDebugDrawData() {
|
||||
|
||||
_vertexFormat = std::make_shared<gpu::Stream::Format>();
|
||||
_vertexBuffer = std::make_shared<gpu::Buffer>();
|
||||
_indexBuffer = std::make_shared<gpu::Buffer>();
|
||||
|
||||
_vertexFormat->setAttribute(gpu::Stream::POSITION, 0, gpu::Element::VEC3F_XYZ, 0);
|
||||
_vertexFormat->setAttribute(gpu::Stream::COLOR, 0, gpu::Element::COLOR_RGBA_32, offsetof(Vertex, rgba));
|
||||
}
|
||||
|
||||
void render(RenderArgs* args) {
|
||||
auto& batch = *args->_batch;
|
||||
batch.setPipeline(_pipeline);
|
||||
auto transform = Transform{};
|
||||
batch.setModelTransform(transform);
|
||||
|
||||
batch.setInputFormat(_vertexFormat);
|
||||
batch.setInputBuffer(0, _vertexBuffer, 0, sizeof(Vertex));
|
||||
batch.setIndexBuffer(gpu::UINT16, _indexBuffer, 0);
|
||||
|
||||
auto numIndices = _indexBuffer->getSize() / sizeof(uint16_t);
|
||||
batch.drawIndexed(gpu::LINES, numIndices);
|
||||
}
|
||||
|
||||
gpu::PipelinePointer _pipeline;
|
||||
render::ItemID _item;
|
||||
gpu::Stream::FormatPointer _vertexFormat;
|
||||
gpu::BufferPointer _vertexBuffer;
|
||||
gpu::BufferPointer _indexBuffer;
|
||||
};
|
||||
|
||||
typedef render::Payload<AnimDebugDrawData> AnimDebugDrawPayload;
|
||||
|
||||
namespace render {
|
||||
template <> const ItemKey payloadGetKey(const AnimDebugDrawData::Pointer& data) { return ItemKey::Builder::transparentShape(); }
|
||||
template <> const Item::Bound payloadGetBound(const AnimDebugDrawData::Pointer& data) { return Item::Bound(); }
|
||||
template <> void payloadRender(const AnimDebugDrawData::Pointer& data, RenderArgs* args) {
|
||||
data->render(args);
|
||||
}
|
||||
}
|
||||
|
||||
static AnimDebugDraw* instance = nullptr;
|
||||
|
||||
AnimDebugDraw& AnimDebugDraw::getInstance() {
|
||||
if (!instance) {
|
||||
instance = new AnimDebugDraw();
|
||||
}
|
||||
return *instance;
|
||||
}
|
||||
|
||||
static uint32_t toRGBA(uint8_t r, uint8_t g, uint8_t b, uint8_t a) {
|
||||
return ((uint32_t)r | (uint32_t)g << 8 | (uint32_t)b << 16 | (uint32_t)a << 24);
|
||||
}
|
||||
|
||||
gpu::PipelinePointer AnimDebugDraw::_pipeline;
|
||||
|
||||
AnimDebugDraw::AnimDebugDraw() :
|
||||
_itemID(0) {
|
||||
|
||||
auto state = std::make_shared<gpu::State>();
|
||||
state->setCullMode(gpu::State::CULL_BACK);
|
||||
state->setDepthTest(true, true, gpu::LESS_EQUAL);
|
||||
state->setBlendFunction(false, gpu::State::SRC_ALPHA, gpu::State::BLEND_OP_ADD,
|
||||
gpu::State::INV_SRC_ALPHA, gpu::State::FACTOR_ALPHA,
|
||||
gpu::State::BLEND_OP_ADD, gpu::State::ONE);
|
||||
auto vertShader = gpu::ShaderPointer(gpu::Shader::createVertex(std::string(animdebugdraw_vert)));
|
||||
auto fragShader = gpu::ShaderPointer(gpu::Shader::createPixel(std::string(animdebugdraw_frag)));
|
||||
auto program = gpu::ShaderPointer(gpu::Shader::createProgram(vertShader, fragShader));
|
||||
_pipeline = gpu::PipelinePointer(gpu::Pipeline::create(program, state));
|
||||
|
||||
_animDebugDrawData = std::make_shared<AnimDebugDrawData>();
|
||||
_animDebugDrawPayload = std::make_shared<AnimDebugDrawPayload>(_animDebugDrawData);
|
||||
|
||||
_animDebugDrawData->_pipeline = _pipeline;
|
||||
|
||||
render::ScenePointer scene = AbstractViewStateInterface::instance()->getMain3DScene();
|
||||
if (scene) {
|
||||
_itemID = scene->allocateID();
|
||||
render::PendingChanges pendingChanges;
|
||||
pendingChanges.resetItem(_itemID, _animDebugDrawPayload);
|
||||
scene->enqueuePendingChanges(pendingChanges);
|
||||
}
|
||||
|
||||
// HACK: add red, green and blue axis at (1,1,1)
|
||||
_animDebugDrawData->_vertexBuffer->resize(sizeof(Vertex) * 6);
|
||||
Vertex* data = (Vertex*)_animDebugDrawData->_vertexBuffer->editData();
|
||||
|
||||
data[0].pos = glm::vec3(1.0, 1.0f, 1.0f);
|
||||
data[0].rgba = toRGBA(255, 0, 0, 255);
|
||||
data[1].pos = glm::vec3(2.0, 1.0f, 1.0f);
|
||||
data[1].rgba = toRGBA(255, 0, 0, 255);
|
||||
|
||||
data[2].pos = glm::vec3(1.0, 1.0f, 1.0f);
|
||||
data[2].rgba = toRGBA(0, 255, 0, 255);
|
||||
data[3].pos = glm::vec3(1.0, 2.0f, 1.0f);
|
||||
data[3].rgba = toRGBA(0, 255, 0, 255);
|
||||
|
||||
data[4].pos = glm::vec3(1.0, 1.0f, 1.0f);
|
||||
data[4].rgba = toRGBA(0, 0, 255, 255);
|
||||
data[5].pos = glm::vec3(1.0, 1.0f, 2.0f);
|
||||
data[5].rgba = toRGBA(0, 0, 255, 255);
|
||||
|
||||
_animDebugDrawData->_indexBuffer->resize(sizeof(uint16_t) * 6);
|
||||
uint16_t* indices = (uint16_t*)_animDebugDrawData->_indexBuffer->editData();
|
||||
for (int i = 0; i < 6; i++) {
|
||||
indices[i] = i;
|
||||
}
|
||||
|
||||
}
|
||||
|
||||
AnimDebugDraw::~AnimDebugDraw() {
|
||||
render::ScenePointer scene = AbstractViewStateInterface::instance()->getMain3DScene();
|
||||
if (scene && _itemID) {
|
||||
render::PendingChanges pendingChanges;
|
||||
pendingChanges.removeItem(_itemID);
|
||||
scene->enqueuePendingChanges(pendingChanges);
|
||||
}
|
||||
}
|
36
libraries/render-utils/src/AnimDebugDraw.h
Normal file
36
libraries/render-utils/src/AnimDebugDraw.h
Normal file
|
@ -0,0 +1,36 @@
|
|||
//
|
||||
// AnimDebugDraw.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_AnimDebugDraw_h
|
||||
#define hifi_AnimDebugDraw_h
|
||||
|
||||
#include "AnimNode.h"
|
||||
#include <render/Scene.h>
|
||||
#include <gpu/Pipeline.h>
|
||||
|
||||
class AnimDebugDrawData;
|
||||
typedef render::Payload<AnimDebugDrawData> AnimDebugDrawPayload;
|
||||
|
||||
|
||||
class AnimDebugDraw {
|
||||
public:
|
||||
static AnimDebugDraw& getInstance();
|
||||
|
||||
AnimDebugDraw();
|
||||
~AnimDebugDraw();
|
||||
|
||||
protected:
|
||||
std::shared_ptr<AnimDebugDrawData> _animDebugDrawData;
|
||||
std::shared_ptr<AnimDebugDrawPayload> _animDebugDrawPayload;
|
||||
render::ItemID _itemID;
|
||||
|
||||
static gpu::PipelinePointer _pipeline;
|
||||
};
|
||||
|
||||
#endif // hifi_AnimDebugDraw
|
17
libraries/render-utils/src/animdebugdraw.slf
Normal file
17
libraries/render-utils/src/animdebugdraw.slf
Normal file
|
@ -0,0 +1,17 @@
|
|||
<@include gpu/Config.slh@>
|
||||
<$VERSION_HEADER$>
|
||||
// Generated on <$_SCRIBE_DATE$>
|
||||
//
|
||||
// unlit untextured fragment shader
|
||||
//
|
||||
// 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 = varColor;
|
||||
}
|
24
libraries/render-utils/src/animdebugdraw.slv
Normal file
24
libraries/render-utils/src/animdebugdraw.slv
Normal file
|
@ -0,0 +1,24 @@
|
|||
<@include gpu/Config.slh@>
|
||||
<$VERSION_HEADER$>
|
||||
// Generated on <$_SCRIBE_DATE$>
|
||||
//
|
||||
// unlit untextured vertex shader
|
||||
//
|
||||
// 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()$>
|
||||
|
||||
varying vec4 varColor;
|
||||
|
||||
void main(void) {
|
||||
// pass along the diffuse color
|
||||
varColor = gl_Color;
|
||||
|
||||
TransformCamera cam = getTransformCamera();
|
||||
TransformObject obj = getTransformObject();
|
||||
<$transformModelToClipPos(cam, obj, gl_Vertex, gl_Position)$>
|
||||
}
|
|
@ -1,6 +1,5 @@
|
|||
//
|
||||
// AnimClipTests.cpp
|
||||
// tests/rig/src
|
||||
//
|
||||
// Copyright 2015 High Fidelity, Inc.
|
||||
//
|
||||
|
|
|
@ -27,4 +27,4 @@ private slots:
|
|||
void testLoader();
|
||||
};
|
||||
|
||||
#endif // hifi_TransformTests_h
|
||||
#endif // hifi_AnimClipTests_h
|
||||
|
|
Loading…
Reference in a new issue