mirror of
https://github.com/overte-org/overte.git
synced 2025-08-09 12:08:54 +02:00
fix paramsOffset and view flipping
This commit is contained in:
parent
e0f3657032
commit
5159367b4c
7 changed files with 28 additions and 28 deletions
|
@ -357,7 +357,7 @@ void OpenGLDisplayPlugin::customizeContext() {
|
||||||
auto presentThread = DependencyManager::get<PresentThread>();
|
auto presentThread = DependencyManager::get<PresentThread>();
|
||||||
Q_ASSERT(thread() == presentThread->thread());
|
Q_ASSERT(thread() == presentThread->thread());
|
||||||
|
|
||||||
getGLBackend()->setCameraCorrection(mat4(), mat4(), true);
|
getGLBackend()->setCameraCorrection(mat4(), mat4(), true, true);
|
||||||
|
|
||||||
for (auto& cursorValue : _cursorsData) {
|
for (auto& cursorValue : _cursorsData) {
|
||||||
auto& cursorData = cursorValue.second;
|
auto& cursorData = cursorValue.second;
|
||||||
|
@ -701,7 +701,7 @@ void OpenGLDisplayPlugin::present(const std::shared_ptr<RefreshRateController>&
|
||||||
|
|
||||||
if (_currentFrame) {
|
if (_currentFrame) {
|
||||||
auto correction = getViewCorrection();
|
auto correction = getViewCorrection();
|
||||||
getGLBackend()->setCameraCorrection(correction, _prevRenderView);
|
getGLBackend()->setCameraCorrection(correction, _prevRenderView, true);
|
||||||
_prevRenderView = correction * _currentFrame->view;
|
_prevRenderView = correction * _currentFrame->view;
|
||||||
{
|
{
|
||||||
withPresentThreadLock([&] {
|
withPresentThreadLock([&] {
|
||||||
|
|
|
@ -387,7 +387,6 @@ void GLBackend::renderPassDraw(const Batch& batch) {
|
||||||
case Batch::COMMAND_setModelTransform:
|
case Batch::COMMAND_setModelTransform:
|
||||||
case Batch::COMMAND_setViewTransform:
|
case Batch::COMMAND_setViewTransform:
|
||||||
case Batch::COMMAND_setProjectionTransform:
|
case Batch::COMMAND_setProjectionTransform:
|
||||||
case Batch::COMMAND_setContextMirrorViewCorrection:
|
|
||||||
break;
|
break;
|
||||||
|
|
||||||
case Batch::COMMAND_draw:
|
case Batch::COMMAND_draw:
|
||||||
|
@ -413,10 +412,10 @@ void GLBackend::renderPassDraw(const Batch& batch) {
|
||||||
//case Batch::COMMAND_setModelTransform:
|
//case Batch::COMMAND_setModelTransform:
|
||||||
//case Batch::COMMAND_setViewTransform:
|
//case Batch::COMMAND_setViewTransform:
|
||||||
//case Batch::COMMAND_setProjectionTransform:
|
//case Batch::COMMAND_setProjectionTransform:
|
||||||
//case Batch::COMMAND_setContextMirrorViewCorrection:
|
|
||||||
case Batch::COMMAND_setProjectionJitter:
|
case Batch::COMMAND_setProjectionJitter:
|
||||||
case Batch::COMMAND_setViewportTransform:
|
case Batch::COMMAND_setViewportTransform:
|
||||||
case Batch::COMMAND_setDepthRangeTransform:
|
case Batch::COMMAND_setDepthRangeTransform:
|
||||||
|
case Batch::COMMAND_setContextMirrorViewCorrection:
|
||||||
{
|
{
|
||||||
PROFILE_RANGE(render_gpu_gl_detail, "transform");
|
PROFILE_RANGE(render_gpu_gl_detail, "transform");
|
||||||
CommandCall call = _commandCalls[(*command)];
|
CommandCall call = _commandCalls[(*command)];
|
||||||
|
@ -625,24 +624,11 @@ void GLBackend::do_restoreContextViewCorrection(const Batch& batch, size_t param
|
||||||
|
|
||||||
void GLBackend::do_setContextMirrorViewCorrection(const Batch& batch, size_t paramOffset) {
|
void GLBackend::do_setContextMirrorViewCorrection(const Batch& batch, size_t paramOffset) {
|
||||||
bool prevMirrorViewCorrection = _transform._mirrorViewCorrection;
|
bool prevMirrorViewCorrection = _transform._mirrorViewCorrection;
|
||||||
_transform._mirrorViewCorrection = batch._params[paramOffset + 1]._uint != 0;
|
_transform._mirrorViewCorrection = batch._params[paramOffset]._uint != 0;
|
||||||
|
|
||||||
if (_transform._correction.correction != glm::mat4()) {
|
if (_transform._correction.correction != glm::mat4()) {
|
||||||
// If we were previously not flipped, take this opportunity to save our flipped and unflipped matrices.
|
setCameraCorrection(_transform._mirrorViewCorrection ? _transform._flippedCorrection : _transform._unflippedCorrection, _transform._correction.prevView, false);
|
||||||
if (!prevMirrorViewCorrection) {
|
_transform._invalidView = true;
|
||||||
_transform._unflippedCorrection = _transform._correction.correction;
|
|
||||||
quat flippedRotation = glm::quat_cast(_transform._unflippedCorrection);
|
|
||||||
flippedRotation.y *= -1.0f;
|
|
||||||
flippedRotation.z *= -1.0f;
|
|
||||||
vec3 flippedTranslation = _transform._unflippedCorrection[3];
|
|
||||||
flippedTranslation.x *= -1.0f;
|
|
||||||
_transform._flippedCorrection = glm::translate(glm::mat4_cast(flippedRotation), flippedTranslation);
|
|
||||||
}
|
|
||||||
|
|
||||||
if (prevMirrorViewCorrection != _transform._mirrorViewCorrection) {
|
|
||||||
setCameraCorrection(_transform._mirrorViewCorrection ? _transform._flippedCorrection : _transform._unflippedCorrection, _transform._correction.prevView);
|
|
||||||
_transform._invalidView = true;
|
|
||||||
}
|
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
|
@ -1024,15 +1010,29 @@ void GLBackend::recycle() const {
|
||||||
_textureManagement._transferEngine->manageMemory();
|
_textureManagement._transferEngine->manageMemory();
|
||||||
}
|
}
|
||||||
|
|
||||||
void GLBackend::setCameraCorrection(const Mat4& correction, const Mat4& prevRenderView, bool reset) {
|
void GLBackend::setCameraCorrection(const Mat4& correction, const Mat4& prevRenderView, bool primary, bool reset) {
|
||||||
auto invCorrection = glm::inverse(correction);
|
auto invCorrection = glm::inverse(correction);
|
||||||
auto invPrevView = glm::inverse(prevRenderView);
|
auto invPrevView = glm::inverse(prevRenderView);
|
||||||
_transform._correction.prevView = (reset ? Mat4() : prevRenderView);
|
_transform._correction.prevView = (reset ? Mat4() : prevRenderView);
|
||||||
_transform._correction.prevViewInverse = (reset ? Mat4() : invPrevView);
|
_transform._correction.prevViewInverse = (reset ? Mat4() : invPrevView);
|
||||||
_transform._correction.correction = correction;
|
_transform._correction.correction = correction;
|
||||||
_transform._correction.correctionInverse = invCorrection;
|
_transform._correction.correctionInverse = invCorrection;
|
||||||
_pipeline._cameraCorrectionBuffer._buffer->setSubData(0, _transform._correction);
|
|
||||||
_pipeline._cameraCorrectionBuffer._buffer->flush();
|
if (!_inRenderTransferPass) {
|
||||||
|
_pipeline._cameraCorrectionBuffer._buffer->setSubData(0, _transform._correction);
|
||||||
|
_pipeline._cameraCorrectionBuffer._buffer->flush();
|
||||||
|
}
|
||||||
|
|
||||||
|
if (primary) {
|
||||||
|
_transform._unflippedCorrection = _transform._correction.correction;
|
||||||
|
quat flippedRotation = glm::quat_cast(_transform._unflippedCorrection);
|
||||||
|
flippedRotation.y *= -1.0f;
|
||||||
|
flippedRotation.z *= -1.0f;
|
||||||
|
vec3 flippedTranslation = _transform._unflippedCorrection[3];
|
||||||
|
flippedTranslation.x *= -1.0f;
|
||||||
|
_transform._flippedCorrection = glm::translate(glm::mat4_cast(flippedRotation), flippedTranslation);
|
||||||
|
_transform._mirrorViewCorrection = false;
|
||||||
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
void GLBackend::syncProgram(const gpu::ShaderPointer& program) {
|
void GLBackend::syncProgram(const gpu::ShaderPointer& program) {
|
||||||
|
|
|
@ -121,7 +121,7 @@ public:
|
||||||
// Shutdown rendering and persist any required resources
|
// Shutdown rendering and persist any required resources
|
||||||
void shutdown() override;
|
void shutdown() override;
|
||||||
|
|
||||||
void setCameraCorrection(const Mat4& correction, const Mat4& prevRenderView, bool reset = false) override;
|
void setCameraCorrection(const Mat4& correction, const Mat4& prevRenderView, bool primary, bool reset = false) override;
|
||||||
void render(const Batch& batch) final override;
|
void render(const Batch& batch) final override;
|
||||||
|
|
||||||
// This call synchronize the Full Backend cache with the current GLState
|
// This call synchronize the Full Backend cache with the current GLState
|
||||||
|
|
|
@ -66,7 +66,7 @@ public:
|
||||||
virtual void syncProgram(const gpu::ShaderPointer& program) = 0;
|
virtual void syncProgram(const gpu::ShaderPointer& program) = 0;
|
||||||
virtual void recycle() const = 0;
|
virtual void recycle() const = 0;
|
||||||
virtual void downloadFramebuffer(const FramebufferPointer& srcFramebuffer, const Vec4i& region, QImage& destImage) = 0;
|
virtual void downloadFramebuffer(const FramebufferPointer& srcFramebuffer, const Vec4i& region, QImage& destImage) = 0;
|
||||||
virtual void setCameraCorrection(const Mat4& correction, const Mat4& prevRenderView, bool reset = false) {}
|
virtual void setCameraCorrection(const Mat4& correction, const Mat4& prevRenderView, bool primary, bool reset = false) {}
|
||||||
|
|
||||||
virtual bool supportedTextureFormat(const gpu::Element& format) = 0;
|
virtual bool supportedTextureFormat(const gpu::Element& format) = 0;
|
||||||
|
|
||||||
|
|
|
@ -96,7 +96,7 @@ void ToneMapAndResample::run(const RenderContextPointer& renderContext, const In
|
||||||
batch.setViewportTransform(destViewport);
|
batch.setViewportTransform(destViewport);
|
||||||
batch.setProjectionTransform(glm::mat4());
|
batch.setProjectionTransform(glm::mat4());
|
||||||
batch.resetViewTransform();
|
batch.resetViewTransform();
|
||||||
bool shouldMirror = _depth % 2 == (args->_renderMode != RenderArgs::MIRROR_RENDER_MODE);
|
bool shouldMirror = _depth >= (args->_renderMode != RenderArgs::MIRROR_RENDER_MODE);
|
||||||
batch.setPipeline(shouldMirror ? _mirrorPipeline : _pipeline);
|
batch.setPipeline(shouldMirror ? _mirrorPipeline : _pipeline);
|
||||||
|
|
||||||
batch.setModelTransform(gpu::Framebuffer::evalSubregionTexcoordTransform(srcBufferSize, args->_viewport));
|
batch.setModelTransform(gpu::Framebuffer::evalSubregionTexcoordTransform(srcBufferSize, args->_viewport));
|
||||||
|
|
|
@ -167,7 +167,7 @@ void UpsampleToBlitFramebuffer::run(const RenderContextPointer& renderContext, c
|
||||||
batch.setViewportTransform(viewport);
|
batch.setViewportTransform(viewport);
|
||||||
batch.setProjectionTransform(glm::mat4());
|
batch.setProjectionTransform(glm::mat4());
|
||||||
batch.resetViewTransform();
|
batch.resetViewTransform();
|
||||||
bool shouldMirror = _depth % 2 == (args->_renderMode != RenderArgs::MIRROR_RENDER_MODE);
|
bool shouldMirror = _depth >= (args->_renderMode != RenderArgs::MIRROR_RENDER_MODE);
|
||||||
batch.setPipeline(shouldMirror ? _mirrorPipeline : _pipeline);
|
batch.setPipeline(shouldMirror ? _mirrorPipeline : _pipeline);
|
||||||
|
|
||||||
batch.setModelTransform(gpu::Framebuffer::evalSubregionTexcoordTransform(bufferSize, viewport));
|
batch.setModelTransform(gpu::Framebuffer::evalSubregionTexcoordTransform(bufferSize, viewport));
|
||||||
|
|
|
@ -122,7 +122,7 @@ void RenderThread::renderFrame(gpu::FramePointer& frame) {
|
||||||
if (_correction != glm::mat4()) {
|
if (_correction != glm::mat4()) {
|
||||||
std::unique_lock<std::mutex> lock(_frameLock);
|
std::unique_lock<std::mutex> lock(_frameLock);
|
||||||
if (_correction != glm::mat4()) {
|
if (_correction != glm::mat4()) {
|
||||||
_backend->setCameraCorrection(_correction, _activeFrame->view);
|
_backend->setCameraCorrection(_correction, _activeFrame->view, true);
|
||||||
//_prevRenderView = _correction * _activeFrame->view;
|
//_prevRenderView = _correction * _activeFrame->view;
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|
Loading…
Reference in a new issue