X-Git-Url: https://git.lukelau.me/?p=opengl.git;a=blobdiff_plain;f=image.cpp;h=fb534be70302ef92ca80ab2ba3a8255a10d6326c;hp=02fd60b878ee1122bd9a027e38df10304d681ef8;hb=ceae87033f199ea0288399b5876fa4d1451eae3e;hpb=d0c631f46c6db417e013b1bc0edec24cb9c2824a 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: