mirror of
https://github.com/overte-org/overte.git
synced 2025-08-08 11:17:34 +02:00
fix backwards HUD in mirror mode
This commit is contained in:
parent
03b46c5e62
commit
046e5ca716
11 changed files with 69 additions and 16 deletions
|
@ -418,6 +418,19 @@ void OpenGLDisplayPlugin::customizeContext() {
|
||||||
_hudPipeline = gpu::Pipeline::create(program, state);
|
_hudPipeline = gpu::Pipeline::create(program, state);
|
||||||
}
|
}
|
||||||
|
|
||||||
|
{
|
||||||
|
auto vs = gpu::StandardShaderLib::getDrawUnitQuadTexcoordVS();
|
||||||
|
auto ps = gpu::StandardShaderLib::getDrawTextureMirroredXPS();
|
||||||
|
gpu::ShaderPointer program = gpu::Shader::createProgram(vs, ps);
|
||||||
|
gpu::Shader::makeProgram(*program);
|
||||||
|
gpu::StatePointer state = gpu::StatePointer(new gpu::State());
|
||||||
|
state->setDepthTest(gpu::State::DepthTest(false));
|
||||||
|
state->setBlendFunction(true,
|
||||||
|
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);
|
||||||
|
_mirrorHUDPipeline = gpu::Pipeline::create(program, state);
|
||||||
|
}
|
||||||
|
|
||||||
{
|
{
|
||||||
auto vs = gpu::StandardShaderLib::getDrawTransformUnitQuadVS();
|
auto vs = gpu::StandardShaderLib::getDrawTransformUnitQuadVS();
|
||||||
auto ps = gpu::StandardShaderLib::getDrawTexturePS();
|
auto ps = gpu::StandardShaderLib::getDrawTexturePS();
|
||||||
|
@ -438,6 +451,7 @@ void OpenGLDisplayPlugin::uncustomizeContext() {
|
||||||
_presentPipeline.reset();
|
_presentPipeline.reset();
|
||||||
_cursorPipeline.reset();
|
_cursorPipeline.reset();
|
||||||
_hudPipeline.reset();
|
_hudPipeline.reset();
|
||||||
|
_mirrorHUDPipeline.reset();
|
||||||
_compositeFramebuffer.reset();
|
_compositeFramebuffer.reset();
|
||||||
withPresentThreadLock([&] {
|
withPresentThreadLock([&] {
|
||||||
_currentFrame.reset();
|
_currentFrame.reset();
|
||||||
|
@ -562,11 +576,11 @@ void OpenGLDisplayPlugin::updateFrameData() {
|
||||||
});
|
});
|
||||||
}
|
}
|
||||||
|
|
||||||
std::function<void(gpu::Batch&, const gpu::TexturePointer&)> OpenGLDisplayPlugin::getHUDOperator() {
|
std::function<void(gpu::Batch&, const gpu::TexturePointer&, bool mirror)> OpenGLDisplayPlugin::getHUDOperator() {
|
||||||
return [this](gpu::Batch& batch, const gpu::TexturePointer& hudTexture) {
|
return [this](gpu::Batch& batch, const gpu::TexturePointer& hudTexture, bool mirror) {
|
||||||
if (_hudPipeline) {
|
if (_hudPipeline) {
|
||||||
batch.enableStereo(false);
|
batch.enableStereo(false);
|
||||||
batch.setPipeline(_hudPipeline);
|
batch.setPipeline(mirror ? _mirrorHUDPipeline : _hudPipeline);
|
||||||
batch.setResourceTexture(0, hudTexture);
|
batch.setResourceTexture(0, hudTexture);
|
||||||
if (isStereo()) {
|
if (isStereo()) {
|
||||||
for_each_eye([&](Eye eye) {
|
for_each_eye([&](Eye eye) {
|
||||||
|
|
|
@ -95,7 +95,7 @@ protected:
|
||||||
virtual QThread::Priority getPresentPriority() { return QThread::HighPriority; }
|
virtual QThread::Priority getPresentPriority() { return QThread::HighPriority; }
|
||||||
virtual void compositeLayers();
|
virtual void compositeLayers();
|
||||||
virtual void compositeScene();
|
virtual void compositeScene();
|
||||||
virtual std::function<void(gpu::Batch&, const gpu::TexturePointer&)> getHUDOperator();
|
virtual std::function<void(gpu::Batch&, const gpu::TexturePointer&, bool mirror)> getHUDOperator();
|
||||||
virtual void compositePointer();
|
virtual void compositePointer();
|
||||||
virtual void compositeExtra() {};
|
virtual void compositeExtra() {};
|
||||||
|
|
||||||
|
@ -140,6 +140,8 @@ protected:
|
||||||
gpu::Frame* _lastFrame { nullptr };
|
gpu::Frame* _lastFrame { nullptr };
|
||||||
gpu::FramebufferPointer _compositeFramebuffer;
|
gpu::FramebufferPointer _compositeFramebuffer;
|
||||||
gpu::PipelinePointer _hudPipeline;
|
gpu::PipelinePointer _hudPipeline;
|
||||||
|
gpu::PipelinePointer _mirrorHUDPipeline;
|
||||||
|
gpu::ShaderPointer _mirrorHUDPS;
|
||||||
gpu::PipelinePointer _simplePipeline;
|
gpu::PipelinePointer _simplePipeline;
|
||||||
gpu::PipelinePointer _presentPipeline;
|
gpu::PipelinePointer _presentPipeline;
|
||||||
gpu::PipelinePointer _cursorPipeline;
|
gpu::PipelinePointer _cursorPipeline;
|
||||||
|
|
|
@ -419,9 +419,9 @@ void HmdDisplayPlugin::HUDRenderer::updatePipeline() {
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
std::function<void(gpu::Batch&, const gpu::TexturePointer&)> HmdDisplayPlugin::HUDRenderer::render(HmdDisplayPlugin& plugin) {
|
std::function<void(gpu::Batch&, const gpu::TexturePointer&, bool mirror)> HmdDisplayPlugin::HUDRenderer::render(HmdDisplayPlugin& plugin) {
|
||||||
updatePipeline();
|
updatePipeline();
|
||||||
return [this](gpu::Batch& batch, const gpu::TexturePointer& hudTexture) {
|
return [this](gpu::Batch& batch, const gpu::TexturePointer& hudTexture, bool mirror) {
|
||||||
if (pipeline) {
|
if (pipeline) {
|
||||||
batch.setPipeline(pipeline);
|
batch.setPipeline(pipeline);
|
||||||
|
|
||||||
|
@ -436,7 +436,11 @@ std::function<void(gpu::Batch&, const gpu::TexturePointer&)> HmdDisplayPlugin::H
|
||||||
batch.setUniformBuffer(uniformsLocation, uniformsBuffer);
|
batch.setUniformBuffer(uniformsLocation, uniformsBuffer);
|
||||||
|
|
||||||
auto compositorHelper = DependencyManager::get<CompositorHelper>();
|
auto compositorHelper = DependencyManager::get<CompositorHelper>();
|
||||||
batch.setModelTransform(compositorHelper->getUiTransform());
|
glm::mat4 modelTransform = compositorHelper->getUiTransform();
|
||||||
|
if (mirror) {
|
||||||
|
modelTransform = glm::scale(modelTransform, glm::vec3(-1, 1, 1));
|
||||||
|
}
|
||||||
|
batch.setModelTransform(modelTransform);
|
||||||
batch.setResourceTexture(0, hudTexture);
|
batch.setResourceTexture(0, hudTexture);
|
||||||
|
|
||||||
batch.drawIndexed(gpu::TRIANGLES, indexCount);
|
batch.drawIndexed(gpu::TRIANGLES, indexCount);
|
||||||
|
@ -468,7 +472,7 @@ void HmdDisplayPlugin::compositePointer() {
|
||||||
});
|
});
|
||||||
}
|
}
|
||||||
|
|
||||||
std::function<void(gpu::Batch&, const gpu::TexturePointer&)> HmdDisplayPlugin::getHUDOperator() {
|
std::function<void(gpu::Batch&, const gpu::TexturePointer&, bool mirror)> HmdDisplayPlugin::getHUDOperator() {
|
||||||
return _hudRenderer.render(*this);
|
return _hudRenderer.render(*this);
|
||||||
}
|
}
|
||||||
|
|
||||||
|
|
|
@ -53,7 +53,7 @@ protected:
|
||||||
|
|
||||||
bool internalActivate() override;
|
bool internalActivate() override;
|
||||||
void internalDeactivate() override;
|
void internalDeactivate() override;
|
||||||
std::function<void(gpu::Batch&, const gpu::TexturePointer&)> getHUDOperator() override;
|
std::function<void(gpu::Batch&, const gpu::TexturePointer&, bool mirror)> getHUDOperator() override;
|
||||||
void compositePointer() override;
|
void compositePointer() override;
|
||||||
void internalPresent() override;
|
void internalPresent() override;
|
||||||
void customizeContext() override;
|
void customizeContext() override;
|
||||||
|
@ -116,6 +116,6 @@ private:
|
||||||
|
|
||||||
void build();
|
void build();
|
||||||
void updatePipeline();
|
void updatePipeline();
|
||||||
std::function<void(gpu::Batch&, const gpu::TexturePointer&)> render(HmdDisplayPlugin& plugin);
|
std::function<void(gpu::Batch&, const gpu::TexturePointer&, bool mirror)> render(HmdDisplayPlugin& plugin);
|
||||||
} _hudRenderer;
|
} _hudRenderer;
|
||||||
};
|
};
|
||||||
|
|
22
libraries/gpu/src/gpu/DrawTextureMirroredX.slf
Normal file
22
libraries/gpu/src/gpu/DrawTextureMirroredX.slf
Normal file
|
@ -0,0 +1,22 @@
|
||||||
|
<@include gpu/Config.slh@>
|
||||||
|
<$VERSION_HEADER$>
|
||||||
|
// Generated on <$_SCRIBE_DATE$>
|
||||||
|
//
|
||||||
|
// Draw texture 0 fetched at (1.0 - texcoord.x, texcoord.y)
|
||||||
|
//
|
||||||
|
// Created by Sam Gondelman on 10/24/2017
|
||||||
|
// Copyright 2017 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
|
||||||
|
//
|
||||||
|
|
||||||
|
|
||||||
|
uniform sampler2D colorMap;
|
||||||
|
|
||||||
|
in vec2 varTexCoord0;
|
||||||
|
out vec4 outFragColor;
|
||||||
|
|
||||||
|
void main(void) {
|
||||||
|
outFragColor = texture(colorMap, vec2(1.0 - varTexCoord0.x, varTexCoord0.y));
|
||||||
|
}
|
|
@ -23,6 +23,7 @@ const char DrawNada_frag[] = "void main(void) {}"; // DrawNada is really simple.
|
||||||
|
|
||||||
#include "DrawWhite_frag.h"
|
#include "DrawWhite_frag.h"
|
||||||
#include "DrawTexture_frag.h"
|
#include "DrawTexture_frag.h"
|
||||||
|
#include "DrawTextureMirroredX_frag.h"
|
||||||
#include "DrawTextureOpaque_frag.h"
|
#include "DrawTextureOpaque_frag.h"
|
||||||
#include "DrawColoredTexture_frag.h"
|
#include "DrawColoredTexture_frag.h"
|
||||||
|
|
||||||
|
@ -37,6 +38,7 @@ ShaderPointer StandardShaderLib::_drawTransformVertexPositionVS;
|
||||||
ShaderPointer StandardShaderLib::_drawNadaPS;
|
ShaderPointer StandardShaderLib::_drawNadaPS;
|
||||||
ShaderPointer StandardShaderLib::_drawWhitePS;
|
ShaderPointer StandardShaderLib::_drawWhitePS;
|
||||||
ShaderPointer StandardShaderLib::_drawTexturePS;
|
ShaderPointer StandardShaderLib::_drawTexturePS;
|
||||||
|
ShaderPointer StandardShaderLib::_drawTextureMirroredXPS;
|
||||||
ShaderPointer StandardShaderLib::_drawTextureOpaquePS;
|
ShaderPointer StandardShaderLib::_drawTextureOpaquePS;
|
||||||
ShaderPointer StandardShaderLib::_drawColoredTexturePS;
|
ShaderPointer StandardShaderLib::_drawColoredTexturePS;
|
||||||
StandardShaderLib::ProgramMap StandardShaderLib::_programs;
|
StandardShaderLib::ProgramMap StandardShaderLib::_programs;
|
||||||
|
@ -130,6 +132,13 @@ ShaderPointer StandardShaderLib::getDrawTexturePS() {
|
||||||
return _drawTexturePS;
|
return _drawTexturePS;
|
||||||
}
|
}
|
||||||
|
|
||||||
|
ShaderPointer StandardShaderLib::getDrawTextureMirroredXPS() {
|
||||||
|
if (!_drawTextureMirroredXPS) {
|
||||||
|
_drawTextureMirroredXPS = gpu::Shader::createPixel(std::string(DrawTextureMirroredX_frag));
|
||||||
|
}
|
||||||
|
return _drawTextureMirroredXPS;
|
||||||
|
}
|
||||||
|
|
||||||
ShaderPointer StandardShaderLib::getDrawTextureOpaquePS() {
|
ShaderPointer StandardShaderLib::getDrawTextureOpaquePS() {
|
||||||
if (!_drawTextureOpaquePS) {
|
if (!_drawTextureOpaquePS) {
|
||||||
_drawTextureOpaquePS = gpu::Shader::createPixel(std::string(DrawTextureOpaque_frag));
|
_drawTextureOpaquePS = gpu::Shader::createPixel(std::string(DrawTextureOpaque_frag));
|
||||||
|
|
|
@ -47,6 +47,7 @@ public:
|
||||||
|
|
||||||
static ShaderPointer getDrawWhitePS();
|
static ShaderPointer getDrawWhitePS();
|
||||||
static ShaderPointer getDrawTexturePS();
|
static ShaderPointer getDrawTexturePS();
|
||||||
|
static ShaderPointer getDrawTextureMirroredXPS();
|
||||||
static ShaderPointer getDrawTextureOpaquePS();
|
static ShaderPointer getDrawTextureOpaquePS();
|
||||||
static ShaderPointer getDrawColoredTexturePS();
|
static ShaderPointer getDrawColoredTexturePS();
|
||||||
|
|
||||||
|
@ -67,6 +68,7 @@ protected:
|
||||||
static ShaderPointer _drawNadaPS;
|
static ShaderPointer _drawNadaPS;
|
||||||
static ShaderPointer _drawWhitePS;
|
static ShaderPointer _drawWhitePS;
|
||||||
static ShaderPointer _drawTexturePS;
|
static ShaderPointer _drawTexturePS;
|
||||||
|
static ShaderPointer _drawTextureMirroredXPS;
|
||||||
static ShaderPointer _drawTextureOpaquePS;
|
static ShaderPointer _drawTextureOpaquePS;
|
||||||
static ShaderPointer _drawColoredTexturePS;
|
static ShaderPointer _drawColoredTexturePS;
|
||||||
|
|
||||||
|
|
|
@ -35,8 +35,8 @@ void DisplayPlugin::waitForPresent() {
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
std::function<void(gpu::Batch&, const gpu::TexturePointer&)> DisplayPlugin::getHUDOperator() {
|
std::function<void(gpu::Batch&, const gpu::TexturePointer&, bool mirror)> DisplayPlugin::getHUDOperator() {
|
||||||
std::function<void(gpu::Batch&, const gpu::TexturePointer&)> hudOperator;
|
std::function<void(gpu::Batch&, const gpu::TexturePointer&, bool mirror)> hudOperator;
|
||||||
{
|
{
|
||||||
QMutexLocker locker(&_presentMutex);
|
QMutexLocker locker(&_presentMutex);
|
||||||
hudOperator = _hudOperator;
|
hudOperator = _hudOperator;
|
||||||
|
|
|
@ -204,7 +204,7 @@ public:
|
||||||
|
|
||||||
void waitForPresent();
|
void waitForPresent();
|
||||||
|
|
||||||
std::function<void(gpu::Batch&, const gpu::TexturePointer&)> getHUDOperator();
|
std::function<void(gpu::Batch&, const gpu::TexturePointer&, bool mirror)> getHUDOperator();
|
||||||
|
|
||||||
static const QString& MENU_PATH();
|
static const QString& MENU_PATH();
|
||||||
|
|
||||||
|
@ -218,7 +218,7 @@ protected:
|
||||||
|
|
||||||
gpu::ContextPointer _gpuContext;
|
gpu::ContextPointer _gpuContext;
|
||||||
|
|
||||||
std::function<void(gpu::Batch&, const gpu::TexturePointer&)> _hudOperator { std::function<void(gpu::Batch&, const gpu::TexturePointer&)>() };
|
std::function<void(gpu::Batch&, const gpu::TexturePointer&, bool mirror)> _hudOperator { std::function<void(gpu::Batch&, const gpu::TexturePointer&, bool mirror)>() };
|
||||||
|
|
||||||
private:
|
private:
|
||||||
QMutex _presentMutex;
|
QMutex _presentMutex;
|
||||||
|
|
|
@ -441,7 +441,7 @@ void CompositeHUD::run(const RenderContextPointer& renderContext) {
|
||||||
// Grab the HUD texture
|
// Grab the HUD texture
|
||||||
gpu::doInBatch(renderContext->args->_context, [&](gpu::Batch& batch) {
|
gpu::doInBatch(renderContext->args->_context, [&](gpu::Batch& batch) {
|
||||||
if (renderContext->args->_hudOperator) {
|
if (renderContext->args->_hudOperator) {
|
||||||
renderContext->args->_hudOperator(batch, renderContext->args->_hudTexture);
|
renderContext->args->_hudOperator(batch, renderContext->args->_hudTexture, renderContext->args->_renderMode == RenderArgs::RenderMode::MIRROR_RENDER_MODE);
|
||||||
}
|
}
|
||||||
});
|
});
|
||||||
}
|
}
|
||||||
|
|
|
@ -122,7 +122,7 @@ namespace render {
|
||||||
render::ScenePointer _scene;
|
render::ScenePointer _scene;
|
||||||
int8_t _cameraMode { -1 };
|
int8_t _cameraMode { -1 };
|
||||||
|
|
||||||
std::function<void(gpu::Batch&, const gpu::TexturePointer&)> _hudOperator;
|
std::function<void(gpu::Batch&, const gpu::TexturePointer&, bool mirror)> _hudOperator;
|
||||||
gpu::TexturePointer _hudTexture;
|
gpu::TexturePointer _hudTexture;
|
||||||
};
|
};
|
||||||
|
|
||||||
|
|
Loading…
Reference in a new issue