X-Git-Url: https://git.lukelau.me/?p=opengl.git;a=blobdiff_plain;f=image.cpp;h=fb534be70302ef92ca80ab2ba3a8255a10d6326c;hp=02fd60b878ee1122bd9a027e38df10304d681ef8;hb=671418e7effc7cbbb7e05df216291406d2b82dd7;hpb=99d2b81ce5567869469fe2e55722cc212370c7db diff --git a/image.cpp b/image.cpp index 02fd60b..fb534be 100644 --- a/image.cpp +++ b/image.cpp @@ -51,17 +51,27 @@ GLenum Image::format() const { return GL_RGBA; } +inline bool Image::usesFloat() const { return info & kCGBitmapFloatComponents; } + GLint Image::internalFormat() const { switch (format()) { case GL_DEPTH_COMPONENT: return GL_DEPTH_COMPONENT; - case GL_RGB: return GL_RGB; + case GL_RGB: + if (bitsPerComponent == 16) + return usesFloat() ? GL_RGB16F : GL_RGB16; + else if (bitsPerComponent == 8) + return GL_RGB; + else abort(); default: return GL_RGBA; } } GLenum Image::type() const { - bool isFloat = info & kCGBitmapFloatComponents; - if (isFloat) return GL_FLOAT; + if (usesFloat()) { + if (bitsPerComponent == 16) return GL_HALF_FLOAT; + else if (bitsPerComponent == 32) return GL_FLOAT; + abort(); + } return GL_UNSIGNED_BYTE; //TODO: