Permalink
Browse files

workaround on opengl unsupported row align

  • Loading branch information...
jlblancoc committed Jan 11, 2019
1 parent 33d39b9 commit 54e779bf4feebaa66ee72efdac332be75411f8f4
Showing with 15 additions and 3 deletions.
  1. +15 −3 libs/opengl/src/COpenGLViewport.cpp
@@ -242,7 +242,7 @@ void COpenGLViewport::render(
// - PTAM, by Klein & Murray
// http://www.robots.ox.ac.uk/~gk/PTAM/

const mrpt::img::CImage* img = m_imageview_img.get();
mrpt::img::CImage* img = m_imageview_img.get();

const int img_w = img->getWidth();
const int img_h = img->getHeight();
@@ -269,6 +269,19 @@ void COpenGLViewport::render(
glPixelZoom(vw / float(ortho_w), -vh / float(ortho_h));

// Prepare image data types:
auto row_align = img->guessRowAlignment();
if (row_align > 8)
{
// Not supported by OpenGL: we need to make a copy of
// the image!
const auto prev_align =
mrpt::img::CImage::ROW_MEM_ALIGNMENT();
mrpt::img::CImage::ROW_MEM_ALIGNMENT(1);
*img = img->makeDeepCopy();
mrpt::img::CImage::ROW_MEM_ALIGNMENT(prev_align);
row_align = 1;
}

const GLenum img_type = GL_UNSIGNED_BYTE;
const int nBytesPerPixel = img->isColor() ? 3 : 1;
// Reverse RGB <-> BGR order?
@@ -279,8 +292,7 @@ void COpenGLViewport::render(
: GL_LUMINANCE;

// Send image data to OpenGL:
glPixelStorei(
GL_UNPACK_ALIGNMENT, img->guessRowAlignment());
glPixelStorei(GL_UNPACK_ALIGNMENT, row_align);
glPixelStorei(GL_UNPACK_ROW_LENGTH, img->getWidth());
glDrawPixels(
img_w, img_h, img_format, img_type,

0 comments on commit 54e779b

Please sign in to comment.