Skip to content

Commit

Permalink
Support displaying more image formats.
Browse files Browse the repository at this point in the history
  • Loading branch information
stevenlovegrove committed Aug 23, 2016
1 parent 39dfed8 commit 66b8acf
Show file tree
Hide file tree
Showing 3 changed files with 20 additions and 9 deletions.
4 changes: 2 additions & 2 deletions include/pangolin/gl/gl.h
Original file line number Diff line number Diff line change
Expand Up @@ -55,7 +55,7 @@ class PANGOLIN_EXPORT GlTexture
{
public:
//! internal_format normally one of GL_RGBA8, GL_LUMINANCE8, GL_INTENSITY16
GlTexture(GLint width, GLint height, GLint internal_format = GL_RGBA, bool sampling_linear = true, int border = 0, GLenum glformat = GL_RGBA, GLenum gltype = GL_UNSIGNED_BYTE, GLvoid* data = NULL );
GlTexture(GLint width, GLint height, GLint internal_format = GL_RGBA8, bool sampling_linear = true, int border = 0, GLenum glformat = GL_RGBA, GLenum gltype = GL_UNSIGNED_BYTE, GLvoid* data = NULL );

#ifdef CALLEE_HAS_RVALREF
//! Move Constructor
Expand All @@ -72,7 +72,7 @@ class PANGOLIN_EXPORT GlTexture
void Delete();

//! Reinitialise teture width / height / format
void Reinitialise(GLsizei width, GLsizei height, GLint internal_format = GL_RGBA, bool sampling_linear = true, int border = 0, GLenum glformat = GL_RGBA, GLenum gltype = GL_UNSIGNED_BYTE, GLvoid* data = NULL );
void Reinitialise(GLsizei width, GLsizei height, GLint internal_format = GL_RGBA8, bool sampling_linear = true, int border = 0, GLenum glformat = GL_RGBA, GLenum gltype = GL_UNSIGNED_BYTE, GLvoid* data = NULL );

void Bind() const;
void Unbind() const;
Expand Down
17 changes: 14 additions & 3 deletions include/pangolin/gl/gl.hpp
Original file line number Diff line number Diff line change
Expand Up @@ -238,28 +238,39 @@ inline void GlTexture::Download(TypedImage& image) const
image.Alloc(width, height, VideoFormatFromString("GRAY8") );
Download(image.ptr, GL_LUMINANCE, GL_UNSIGNED_BYTE);
break;
case GL_RGB:
case GL_LUMINANCE16:
image.Alloc(width, height, VideoFormatFromString("GRAY16LE") );
Download(image.ptr, GL_LUMINANCE, GL_UNSIGNED_SHORT);
break;
case GL_RGB8:
image.Alloc(width, height, VideoFormatFromString("RGB24"));
Download(image.ptr, GL_RGB, GL_UNSIGNED_BYTE);
break;
case GL_RGBA:
case GL_RGBA8:
image.Alloc(width, height, VideoFormatFromString("RGBA32"));
Download(image.ptr, GL_RGBA, GL_UNSIGNED_BYTE);
break;
case GL_LUMINANCE:
case GL_LUMINANCE32F_ARB:
image.Alloc(width, height, VideoFormatFromString("GRAY32F"));
Download(image.ptr, GL_LUMINANCE, GL_FLOAT);
break;
case GL_RGB:
case GL_RGB32F:
image.Alloc(width, height, VideoFormatFromString("RGB96F"));
Download(image.ptr, GL_RGB, GL_FLOAT);
break;
case GL_RGBA:
case GL_RGBA32F:
image.Alloc(width, height, VideoFormatFromString("RGBA128F"));
Download(image.ptr, GL_RGBA, GL_FLOAT);
break;
default:
throw std::runtime_error( "GlTexture::Download - Unknown internal format");
throw std::runtime_error(
"GlTexture::Download - Unknown internal format (" +
pangolin::Convert<std::string,GLint>::Do(internal_format) +
")"
);
}

}
Expand Down
8 changes: 4 additions & 4 deletions include/pangolin/gl/glformattraits.h
Original file line number Diff line number Diff line change
Expand Up @@ -66,7 +66,7 @@ struct GlFormatTraits<double>
template<>
struct GlFormatTraits<unsigned char>
{
static const GLint glinternalformat = GL_LUMINANCE;
static const GLint glinternalformat = GL_LUMINANCE32F_ARB;
static const GLenum glformat = GL_LUMINANCE;
static const GLenum gltype = GL_UNSIGNED_BYTE;
};
Expand All @@ -76,23 +76,23 @@ struct GlFormatTraits<unsigned char>
template<>
struct GlFormatTraits<unsigned short>
{
static const GLint glinternalformat = GL_LUMINANCE;
static const GLint glinternalformat = GL_LUMINANCE32F_ARB;
static const GLenum glformat = GL_LUMINANCE;
static const GLenum gltype = GL_UNSIGNED_SHORT;
};

template<>
struct GlFormatTraits<unsigned int>
{
static const GLint glinternalformat = GL_LUMINANCE;
static const GLint glinternalformat = GL_LUMINANCE32F_ARB;
static const GLenum glformat = GL_LUMINANCE;
static const GLenum gltype = GL_UNSIGNED_INT;
};

template<>
struct GlFormatTraits<int>
{
static const GLint glinternalformat = GL_LUMINANCE;
static const GLint glinternalformat = GL_LUMINANCE32F_ARB;
static const GLenum glformat = GL_LUMINANCE;
static const GLenum gltype = GL_INT;
};
Expand Down

0 comments on commit 66b8acf

Please sign in to comment.