Fix HMD UI glow lines

This commit is contained in:
Brad Davis 2016-11-18 17:42:18 -08:00
parent 3074be7ad0
commit 362976645b
2 changed files with 10 additions and 9 deletions

View file

@ -55,8 +55,6 @@ struct HandLaserData {
vec4 color; vec4 color;
}; };
static const uint32_t HAND_LASER_UNIFORM_SLOT = 1;
static QString readFile(const QString& filename) { static QString readFile(const QString& filename) {
QFile file(filename); QFile file(filename);
file.open(QFile::Text | QFile::ReadOnly); file.open(QFile::Text | QFile::ReadOnly);
@ -133,10 +131,13 @@ void HmdDisplayPlugin::customizeContext() {
state->setBlendFunction(true, state->setBlendFunction(true,
gpu::State::SRC_ALPHA, gpu::State::BLEND_OP_ADD, gpu::State::INV_SRC_ALPHA, 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); gpu::State::FACTOR_ALPHA, gpu::State::BLEND_OP_ADD, gpu::State::ONE);
gpu::Shader::BindingSet slotBindings; gpu::Shader::makeProgram(*program, gpu::Shader::BindingSet());
slotBindings.insert(gpu::Shader::Binding(std::string("lineData"), HAND_LASER_UNIFORM_SLOT));
gpu::Shader::makeProgram(*program, slotBindings);
_glowLinePipeline = gpu::Pipeline::create(program, state); _glowLinePipeline = gpu::Pipeline::create(program, state);
for (const auto& buffer : program->getBuffers()) {
if (buffer._name == "lineData") {
_handLaserUniformSlot = buffer._location;
}
}
_handLaserUniforms = std::array<gpu::BufferPointer, 2>{ { std::make_shared<gpu::Buffer>(), std::make_shared<gpu::Buffer>() } }; _handLaserUniforms = std::array<gpu::BufferPointer, 2>{ { std::make_shared<gpu::Buffer>(), std::make_shared<gpu::Buffer>() } };
_extraLaserUniforms = std::make_shared<gpu::Buffer>(); _extraLaserUniforms = std::make_shared<gpu::Buffer>();
}; };
@ -724,8 +725,7 @@ void HmdDisplayPlugin::compositeExtra() {
const auto& points = _presentHandLaserPoints[index]; const auto& points = _presentHandLaserPoints[index];
_handLaserUniforms[index]->resize(sizeof(HandLaserData)); _handLaserUniforms[index]->resize(sizeof(HandLaserData));
_handLaserUniforms[index]->setSubData(0, HandLaserData { vec4(points.first, 1.0f), vec4(points.second, 1.0f), _handLasers[index].color }); _handLaserUniforms[index]->setSubData(0, HandLaserData { vec4(points.first, 1.0f), vec4(points.second, 1.0f), _handLasers[index].color });
batch.setUniformBuffer(HAND_LASER_UNIFORM_SLOT, _handLaserUniforms[index]); batch.setUniformBuffer(_handLaserUniformSlot, _handLaserUniforms[index]);
qDebug() << "Render line " << index;
batch.draw(gpu::TRIANGLE_STRIP, 4, 0); batch.draw(gpu::TRIANGLE_STRIP, 4, 0);
} }
}); });
@ -734,7 +734,7 @@ void HmdDisplayPlugin::compositeExtra() {
const auto& points = _presentExtraLaserPoints; const auto& points = _presentExtraLaserPoints;
_extraLaserUniforms->resize(sizeof(HandLaserData)); _extraLaserUniforms->resize(sizeof(HandLaserData));
_extraLaserUniforms->setSubData(0, HandLaserData { vec4(points.first, 1.0f), vec4(points.second, 1.0f), _presentExtraLaser.color }); _extraLaserUniforms->setSubData(0, HandLaserData { vec4(points.first, 1.0f), vec4(points.second, 1.0f), _presentExtraLaser.color });
batch.setUniformBuffer(HAND_LASER_UNIFORM_SLOT, _extraLaserUniforms); batch.setUniformBuffer(_handLaserUniformSlot, _extraLaserUniforms);
batch.draw(gpu::TRIANGLE_STRIP, 4, 0); batch.draw(gpu::TRIANGLE_STRIP, 4, 0);
} }
}); });

View file

@ -119,6 +119,7 @@ private:
bool _monoPreview { true }; bool _monoPreview { true };
bool _clearPreviewFlag { false }; bool _clearPreviewFlag { false };
std::array<gpu::BufferPointer, 2> _handLaserUniforms; std::array<gpu::BufferPointer, 2> _handLaserUniforms;
uint32_t _handLaserUniformSlot { 0 };
gpu::BufferPointer _extraLaserUniforms; gpu::BufferPointer _extraLaserUniforms;
gpu::PipelinePointer _glowLinePipeline; gpu::PipelinePointer _glowLinePipeline;
gpu::TexturePointer _previewTexture; gpu::TexturePointer _previewTexture;