mirror of
https://github.com/overte-org/overte.git
synced 2025-08-04 04:43:31 +02:00
Merge pull request #10653 from samcake/flash
Spectator-camera : Provide a way to render the side camera always mono
This commit is contained in:
commit
12e5fc20f7
11 changed files with 64 additions and 10 deletions
|
@ -1,6 +1,7 @@
|
||||||
|
|
||||||
#include "PrototypeSelfie.h"
|
#include "PrototypeSelfie.h"
|
||||||
|
|
||||||
|
#include <gpu/Context.h>
|
||||||
|
|
||||||
void MainRenderTask::build(JobModel& task, const render::Varying& inputs, render::Varying& outputs, render::CullFunctor cullFunctor, bool isDeferred) {
|
void MainRenderTask::build(JobModel& task, const render::Varying& inputs, render::Varying& outputs, render::CullFunctor cullFunctor, bool isDeferred) {
|
||||||
|
|
||||||
|
@ -51,9 +52,15 @@ public:
|
||||||
// Caching/restoring the old values doesn't seem to be needed. Is it because we happen to be last in the pipeline (which would be a bug waiting to happen)?
|
// Caching/restoring the old values doesn't seem to be needed. Is it because we happen to be last in the pipeline (which would be a bug waiting to happen)?
|
||||||
_cachedArgsPointer->_blitFramebuffer = args->_blitFramebuffer;
|
_cachedArgsPointer->_blitFramebuffer = args->_blitFramebuffer;
|
||||||
_cachedArgsPointer->_viewport = args->_viewport;
|
_cachedArgsPointer->_viewport = args->_viewport;
|
||||||
|
_cachedArgsPointer->_displayMode = args->_displayMode;
|
||||||
args->_blitFramebuffer = destFramebuffer;
|
args->_blitFramebuffer = destFramebuffer;
|
||||||
args->_viewport = glm::ivec4(0, 0, destFramebuffer->getWidth(), destFramebuffer->getHeight());
|
args->_viewport = glm::ivec4(0, 0, destFramebuffer->getWidth(), destFramebuffer->getHeight());
|
||||||
// FIXME: We're also going to need to clear/restore the stereo setup!
|
args->_viewport = glm::ivec4(0, 0, destFramebuffer->getWidth(), destFramebuffer->getHeight());
|
||||||
|
args->_displayMode = RenderArgs::MONO;
|
||||||
|
|
||||||
|
gpu::doInBatch(args->_context, [&](gpu::Batch& batch) {
|
||||||
|
batch.disableContextStereo();
|
||||||
|
});
|
||||||
|
|
||||||
auto srcViewFrustum = args->getViewFrustum();
|
auto srcViewFrustum = args->getViewFrustum();
|
||||||
srcViewFrustum.setPosition(_position);
|
srcViewFrustum.setPosition(_position);
|
||||||
|
@ -78,6 +85,11 @@ public:
|
||||||
args->_blitFramebuffer = cachedArgs->_blitFramebuffer;
|
args->_blitFramebuffer = cachedArgs->_blitFramebuffer;
|
||||||
args->_viewport = cachedArgs->_viewport;
|
args->_viewport = cachedArgs->_viewport;
|
||||||
args->popViewFrustum();
|
args->popViewFrustum();
|
||||||
|
args->_displayMode = cachedArgs->_displayMode;
|
||||||
|
|
||||||
|
gpu::doInBatch(args->_context, [&](gpu::Batch& batch) {
|
||||||
|
batch.restoreContextStereo();
|
||||||
|
});
|
||||||
}
|
}
|
||||||
};
|
};
|
||||||
|
|
||||||
|
|
|
@ -115,6 +115,9 @@ GLBackend::CommandCall GLBackend::_commandCalls[Batch::NUM_COMMANDS] =
|
||||||
|
|
||||||
(&::gpu::gl::GLBackend::do_resetStages),
|
(&::gpu::gl::GLBackend::do_resetStages),
|
||||||
|
|
||||||
|
(&::gpu::gl::GLBackend::do_disableContextStereo),
|
||||||
|
(&::gpu::gl::GLBackend::do_restoreContextStereo),
|
||||||
|
|
||||||
(&::gpu::gl::GLBackend::do_runLambda),
|
(&::gpu::gl::GLBackend::do_runLambda),
|
||||||
|
|
||||||
(&::gpu::gl::GLBackend::do_startNamedCall),
|
(&::gpu::gl::GLBackend::do_startNamedCall),
|
||||||
|
@ -224,6 +227,14 @@ void GLBackend::renderPassTransfer(const Batch& batch) {
|
||||||
_transform.preUpdate(_commandIndex, _stereo);
|
_transform.preUpdate(_commandIndex, _stereo);
|
||||||
break;
|
break;
|
||||||
|
|
||||||
|
case Batch::COMMAND_disableContextStereo:
|
||||||
|
_stereo._contextDisable = true;
|
||||||
|
break;
|
||||||
|
|
||||||
|
case Batch::COMMAND_restoreContextStereo:
|
||||||
|
_stereo._contextDisable = false;
|
||||||
|
break;
|
||||||
|
|
||||||
case Batch::COMMAND_setViewportTransform:
|
case Batch::COMMAND_setViewportTransform:
|
||||||
case Batch::COMMAND_setViewTransform:
|
case Batch::COMMAND_setViewTransform:
|
||||||
case Batch::COMMAND_setProjectionTransform: {
|
case Batch::COMMAND_setProjectionTransform: {
|
||||||
|
@ -308,16 +319,16 @@ void GLBackend::render(const Batch& batch) {
|
||||||
}
|
}
|
||||||
|
|
||||||
#ifdef GPU_STEREO_DRAWCALL_INSTANCED
|
#ifdef GPU_STEREO_DRAWCALL_INSTANCED
|
||||||
if (_stereo._enable) {
|
if (_stereo.isStereo()) {
|
||||||
glEnable(GL_CLIP_DISTANCE0);
|
glEnable(GL_CLIP_DISTANCE0);
|
||||||
}
|
}
|
||||||
#endif
|
#endif
|
||||||
{
|
{
|
||||||
PROFILE_RANGE(render_gpu_gl_detail, _stereo._enable ? "Render Stereo" : "Render");
|
PROFILE_RANGE(render_gpu_gl_detail, _stereo.isStereo() ? "Render Stereo" : "Render");
|
||||||
renderPassDraw(batch);
|
renderPassDraw(batch);
|
||||||
}
|
}
|
||||||
#ifdef GPU_STEREO_DRAWCALL_INSTANCED
|
#ifdef GPU_STEREO_DRAWCALL_INSTANCED
|
||||||
if (_stereo._enable) {
|
if (_stereo.isStereo()) {
|
||||||
glDisable(GL_CLIP_DISTANCE0);
|
glDisable(GL_CLIP_DISTANCE0);
|
||||||
}
|
}
|
||||||
#endif
|
#endif
|
||||||
|
@ -358,6 +369,15 @@ void GLBackend::do_resetStages(const Batch& batch, size_t paramOffset) {
|
||||||
resetStages();
|
resetStages();
|
||||||
}
|
}
|
||||||
|
|
||||||
|
|
||||||
|
void GLBackend::do_disableContextStereo(const Batch& batch, size_t paramOffset) {
|
||||||
|
|
||||||
|
}
|
||||||
|
|
||||||
|
void GLBackend::do_restoreContextStereo(const Batch& batch, size_t paramOffset) {
|
||||||
|
|
||||||
|
}
|
||||||
|
|
||||||
void GLBackend::do_runLambda(const Batch& batch, size_t paramOffset) {
|
void GLBackend::do_runLambda(const Batch& batch, size_t paramOffset) {
|
||||||
std::function<void()> f = batch._lambdas.get(batch._params[paramOffset]._uint);
|
std::function<void()> f = batch._lambdas.get(batch._params[paramOffset]._uint);
|
||||||
f();
|
f();
|
||||||
|
|
|
@ -143,6 +143,9 @@ public:
|
||||||
// Reset stages
|
// Reset stages
|
||||||
virtual void do_resetStages(const Batch& batch, size_t paramOffset) final;
|
virtual void do_resetStages(const Batch& batch, size_t paramOffset) final;
|
||||||
|
|
||||||
|
virtual void do_disableContextStereo(const Batch& batch, size_t paramOffset) final;
|
||||||
|
virtual void do_restoreContextStereo(const Batch& batch, size_t paramOffset) final;
|
||||||
|
|
||||||
virtual void do_runLambda(const Batch& batch, size_t paramOffset) final;
|
virtual void do_runLambda(const Batch& batch, size_t paramOffset) final;
|
||||||
|
|
||||||
virtual void do_startNamedCall(const Batch& batch, size_t paramOffset) final;
|
virtual void do_startNamedCall(const Batch& batch, size_t paramOffset) final;
|
||||||
|
|
|
@ -48,7 +48,7 @@ void GLBackend::do_setFramebuffer(const Batch& batch, size_t paramOffset) {
|
||||||
}
|
}
|
||||||
|
|
||||||
void GLBackend::do_clearFramebuffer(const Batch& batch, size_t paramOffset) {
|
void GLBackend::do_clearFramebuffer(const Batch& batch, size_t paramOffset) {
|
||||||
if (_stereo._enable && !_pipeline._stateCache.scissorEnable) {
|
if (_stereo.isStereo() && !_pipeline._stateCache.scissorEnable) {
|
||||||
qWarning("Clear without scissor in stereo mode");
|
qWarning("Clear without scissor in stereo mode");
|
||||||
}
|
}
|
||||||
|
|
||||||
|
|
|
@ -322,7 +322,7 @@ void GLBackend::do_setStateScissorRect(const Batch& batch, size_t paramOffset) {
|
||||||
Vec4i rect;
|
Vec4i rect;
|
||||||
memcpy(&rect, batch.readData(batch._params[paramOffset]._uint), sizeof(Vec4i));
|
memcpy(&rect, batch.readData(batch._params[paramOffset]._uint), sizeof(Vec4i));
|
||||||
|
|
||||||
if (_stereo._enable) {
|
if (_stereo.isStereo()) {
|
||||||
rect.z /= 2;
|
rect.z /= 2;
|
||||||
if (_stereo._pass) {
|
if (_stereo._pass) {
|
||||||
rect.x += rect.z;
|
rect.x += rect.z;
|
||||||
|
|
|
@ -37,7 +37,7 @@ void GLBackend::do_setViewportTransform(const Batch& batch, size_t paramOffset)
|
||||||
glViewport(vp.x, vp.y, vp.z, vp.w);
|
glViewport(vp.x, vp.y, vp.z, vp.w);
|
||||||
|
|
||||||
// Where we assign the GL viewport
|
// Where we assign the GL viewport
|
||||||
if (_stereo._enable) {
|
if (_stereo.isStereo()) {
|
||||||
vp.z /= 2;
|
vp.z /= 2;
|
||||||
if (_stereo._pass) {
|
if (_stereo._pass) {
|
||||||
vp.x += vp.z;
|
vp.x += vp.z;
|
||||||
|
|
|
@ -390,6 +390,15 @@ void Batch::resetStages() {
|
||||||
ADD_COMMAND(resetStages);
|
ADD_COMMAND(resetStages);
|
||||||
}
|
}
|
||||||
|
|
||||||
|
|
||||||
|
void Batch::disableContextStereo() {
|
||||||
|
ADD_COMMAND(disableContextStereo);
|
||||||
|
}
|
||||||
|
|
||||||
|
void Batch::restoreContextStereo() {
|
||||||
|
ADD_COMMAND(restoreContextStereo);
|
||||||
|
}
|
||||||
|
|
||||||
void Batch::runLambda(std::function<void()> f) {
|
void Batch::runLambda(std::function<void()> f) {
|
||||||
ADD_COMMAND(runLambda);
|
ADD_COMMAND(runLambda);
|
||||||
_params.emplace_back(_lambdas.cache(f));
|
_params.emplace_back(_lambdas.cache(f));
|
||||||
|
|
|
@ -217,6 +217,9 @@ public:
|
||||||
// Reset the stage caches and states
|
// Reset the stage caches and states
|
||||||
void resetStages();
|
void resetStages();
|
||||||
|
|
||||||
|
void disableContextStereo();
|
||||||
|
void restoreContextStereo();
|
||||||
|
|
||||||
// Debugging
|
// Debugging
|
||||||
void pushProfileRange(const char* name);
|
void pushProfileRange(const char* name);
|
||||||
void popProfileRange();
|
void popProfileRange();
|
||||||
|
@ -301,6 +304,9 @@ public:
|
||||||
|
|
||||||
COMMAND_resetStages,
|
COMMAND_resetStages,
|
||||||
|
|
||||||
|
COMMAND_disableContextStereo,
|
||||||
|
COMMAND_restoreContextStereo,
|
||||||
|
|
||||||
COMMAND_runLambda,
|
COMMAND_runLambda,
|
||||||
|
|
||||||
COMMAND_startNamedCall,
|
COMMAND_startNamedCall,
|
||||||
|
@ -467,7 +473,7 @@ public:
|
||||||
NamedBatchDataMap _namedData;
|
NamedBatchDataMap _namedData;
|
||||||
|
|
||||||
bool _enableStereo{ true };
|
bool _enableStereo{ true };
|
||||||
bool _enableSkybox{ false };
|
bool _enableSkybox { false };
|
||||||
|
|
||||||
protected:
|
protected:
|
||||||
friend class Context;
|
friend class Context;
|
||||||
|
|
|
@ -145,7 +145,7 @@ void Context::enableStereo(bool enable) {
|
||||||
}
|
}
|
||||||
|
|
||||||
bool Context::isStereo() {
|
bool Context::isStereo() {
|
||||||
return _stereo._enable;
|
return _stereo.isStereo();
|
||||||
}
|
}
|
||||||
|
|
||||||
void Context::setStereoProjections(const mat4 eyeProjections[2]) {
|
void Context::setStereoProjections(const mat4 eyeProjections[2]) {
|
||||||
|
|
|
@ -118,7 +118,7 @@ public:
|
||||||
|
|
||||||
protected:
|
protected:
|
||||||
virtual bool isStereo() {
|
virtual bool isStereo() {
|
||||||
return _stereo._enable;
|
return _stereo.isStereo();
|
||||||
}
|
}
|
||||||
|
|
||||||
void getStereoProjections(mat4* eyeProjections) const {
|
void getStereoProjections(mat4* eyeProjections) const {
|
||||||
|
|
|
@ -93,7 +93,11 @@ namespace gpu {
|
||||||
using TextureViews = std::vector<TextureView>;
|
using TextureViews = std::vector<TextureView>;
|
||||||
|
|
||||||
struct StereoState {
|
struct StereoState {
|
||||||
|
bool isStereo() const {
|
||||||
|
return _enable && !_contextDisable;
|
||||||
|
}
|
||||||
bool _enable{ false };
|
bool _enable{ false };
|
||||||
|
bool _contextDisable { false };
|
||||||
bool _skybox{ false };
|
bool _skybox{ false };
|
||||||
// 0 for left eye, 1 for right eye
|
// 0 for left eye, 1 for right eye
|
||||||
uint8 _pass{ 0 };
|
uint8 _pass{ 0 };
|
||||||
|
|
Loading…
Reference in a new issue