Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Fix rendering of textures with alpha channel #270

Merged
merged 2 commits into from
Sep 13, 2018
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
2 changes: 2 additions & 0 deletions doc/Changelog.md
Original file line number Diff line number Diff line change
Expand Up @@ -3,6 +3,8 @@ Changelog {#changelog}

# Release 1.5 (git master)

* [270](https://github.com/BlueBrain/Tide/pull/270):
Fix rendering of contents with alpha channel + "transparent windows" option.
* [269](https://github.com/BlueBrain/Tide/pull/269):
Fix segfault with TIFF pyramids in grayscale + alpha (2 bytes per pixel).
* [268](https://github.com/BlueBrain/Tide/pull/268):
Expand Down
2 changes: 2 additions & 0 deletions tide/core/data/FFMPEGVideoStream.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -358,6 +358,8 @@ void FFMPEGVideoStream::_generateSeekingParameters()
const auto den = int64_t(timeBase.num) * AV_TIME_BASE;
duration = av_rescale(_avFormatContext.duration, num, den);
}
if (duration <= 0)
throw std::runtime_error("cannot determine movie duration");

// Estimate number of frames if unavailable
_numFrames = _videoStream->nb_frames;
Expand Down
5 changes: 4 additions & 1 deletion tide/core/scene/MovieContent.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -43,6 +43,8 @@

#include "data/FFMPEGMovie.h"

#include "utils/log.h"

BOOST_CLASS_EXPORT_IMPLEMENT(MovieContent)

IMPLEMENT_SERIALIZE_FOR_XML(MovieContent)
Expand All @@ -67,8 +69,9 @@ bool MovieContent::readMetadata()
_frameDuration = movie.getFrameDuration();
return true;
}
catch (const std::runtime_error&)
catch (const std::runtime_error& e)
{
put_log(LOG_DEBUG, LOG_AV, e.what());
return false;
}
}
Expand Down
34 changes: 21 additions & 13 deletions tide/wall/qml/textureUtils.cpp
Original file line number Diff line number Diff line change
@@ -1,6 +1,6 @@
/*********************************************************************/
/* Copyright (c) 2017, EPFL/Blue Brain Project */
/* Raphael Dumusc <raphael.dumusc@epfl.ch> */
/* Copyright (c) 2017-2018, EPFL/Blue Brain Project */
/* Raphael Dumusc <raphael.dumusc@epfl.ch> */
/* All rights reserved. */
/* */
/* Redistribution and use in source and binary forms, with or */
Expand Down Expand Up @@ -63,17 +63,23 @@ void upload(const Image& image, const uint srcTextureIdx, QOpenGLBuffer& pbo)
pbo.release();
}

GLint _getUnpackAlignment(const uint textureWidth)
{
if (textureWidth % 4 == 0)
return 4;
if (textureWidth % 2 == 0)
return 2;
return 1;
}

void copy(QOpenGLBuffer& pbo, QSGTexture& texture, const uint glTexFormat)
{
auto gl = QOpenGLContext::currentContext()->functions();

const auto textureSize = texture.textureSize();

GLint alignment = 1;
if ((textureSize.width() % 4) == 0)
alignment = 4;
else if ((textureSize.width() % 2) == 0)
alignment = 2;
gl->glPixelStorei(GL_UNPACK_ALIGNMENT, alignment);
gl->glPixelStorei(GL_UNPACK_ALIGNMENT,
_getUnpackAlignment(textureSize.width()));

texture.bind();
pbo.bind();
Expand All @@ -86,8 +92,9 @@ void copy(QOpenGLBuffer& pbo, QSGTexture& texture, const uint glTexFormat)
std::unique_ptr<QSGTexture> createTexture(const QSize& size,
QQuickWindow& window)
{
uint textureID = 0;
auto gl = QOpenGLContext::currentContext()->functions();

auto textureID = GLuint{0};
gl->glGenTextures(1, &textureID);
gl->glBindTexture(GL_TEXTURE_2D, textureID);
gl->glTexImage2D(GL_TEXTURE_2D, 0, GL_R8, size.width(), size.height(), 0,
Expand All @@ -102,17 +109,18 @@ std::unique_ptr<QSGTexture> createTexture(const QSize& size,
std::unique_ptr<QSGTexture> createTextureRgba(const QSize& size,
QQuickWindow& window)
{
uint textureID;
auto gl = QOpenGLContext::currentContext()->functions();
gl->glActiveTexture(GL_TEXTURE0);

auto textureID = GLuint{0};
gl->glGenTextures(1, &textureID);
gl->glBindTexture(GL_TEXTURE_2D, textureID);
gl->glTexImage2D(GL_TEXTURE_2D, 0, GL_RGBA8, size.width(), size.height(), 0,
GL_RGBA, GL_UNSIGNED_BYTE, 0);
gl->glBindTexture(GL_TEXTURE_2D, 0);

const auto textureFlags =
QQuickWindow::CreateTextureOptions(QQuickWindow::TextureOwnsGLTexture);
const auto textureFlags = QQuickWindow::CreateTextureOptions(
QQuickWindow::TextureOwnsGLTexture |
QQuickWindow::TextureHasAlphaChannel);
return std::unique_ptr<QSGTexture>{
window.createTextureFromId(textureID, size, textureFlags)};
}
Expand Down