When learning OpenGL I always struggled with these values: which combinations are valid? This information is hard to find. So I made my engine try and output and finally found combinations that work (see code at the bottom). Interestingly, GL and GLES have it differently:
The values are: <my engine's enum> / <internal format> / <format> / <type>
-- in the relative order you pass them to glTexImage2d(), which is
glTexImage2D (GL_TEXTURE_2D, 0, <internal format>, 32, 32, 0, <format>, <type>, @buffer);
Desktop GL:
You tell it which internal format it should use and pass it image in what pixel format you have (usually 8 bits).
The driver does the work of converting the image to the internal format.
Code:
Trying texture formats...
OK: texformat_L8 / GL_LUMINANCE8 / GL_LUMINANCE / GL_UNSIGNED_BYTE
OK: texformat_A8 / GL_ALPHA8 / GL_ALPHA / GL_UNSIGNED_BYTE
OK: texformat_LA8 / GL_LUMINANCE8_ALPHA8 / GL_LUMINANCE_ALPHA / GL_UNSIGNED_BYTE
OK: texformat_L16 / GL_LUMINANCE16 / GL_LUMINANCE / GL_UNSIGNED_SHORT
OK: texformat_LA16 / GL_LUMINANCE16_ALPHA16 / GL_LUMINANCE_ALPHA / GL_UNSIGNED_SHORT
OK: texformat_R3G3B2 / GL_R3_G3_B2 / GL_RGB / GL_UNSIGNED_BYTE_3_3_2
OK: texformat_R3G3B2 / GL_R3_G3_B2 / GL_RGB / GL_UNSIGNED_BYTE
OK: texformat_R5G6B5 / GL_RGB5 / GL_RGB / GL_UNSIGNED_SHORT_5_6_5
OK: texformat_R5G6B5 / GL_RGB5 / GL_RGB / GL_UNSIGNED_BYTE
OK: texformat_R5G5B5A1 / GL_RGB5 / GL_RGBA / GL_UNSIGNED_SHORT_1_5_5_5_REV
OK: texformat_R5G5B5A1 / GL_RGB5 / GL_RGBA / GL_UNSIGNED_SHORT_5_5_5_1
OK: texformat_R5G5B5A1 / GL_RGB5 / GL_RGBA / GL_UNSIGNED_BYTE
OK: texformat_RGBA4 / GL_RGBA4 / GL_RGBA / GL_UNSIGNED_SHORT_4_4_4_4_REV
OK: texformat_RGBA4 / GL_RGBA4 / GL_RGBA / GL_UNSIGNED_SHORT_4_4_4_4
OK: texformat_RGBA4 / GL_RGBA4 / GL_RGBA / GL_UNSIGNED_BYTE
OK: texformat_RGB8 / GL_RGB8 / GL_RGB / GL_UNSIGNED_BYTE
OK: texformat_RGBA8 / GL_RGBA8 / GL_RGBA / GL_UNSIGNED_BYTE
OK: texformat_RGB16 / GL_RGB16 / GL_RGB / GL_UNSIGNED_SHORT
OK: texformat_RGBA16 / GL_RGBA16 / GL_RGBA / GL_UNSIGNED_SHORT
OK: texformat_R32F / GL_LUMINANCE32F / format 1903h / GL_FLOAT
OK: texformat_RGBA32F / GL_RGBA32F / GL_RGBA / GL_FLOAT
OK: texformat_R16F / GL_LUMINANCE16F / format 1903h / GL_HALF_FLOAT
OK: texformat_RGBA16F / GL_RGBA16F / GL_RGBA / GL_HALF_FLOAT
OK: texformat_DXT1 / GL_COMPRESSED_RGB_S3TC_DXT1_EXT / GL_RGB / GL_UNSIGNED_BYTE
OK: texformat_DXT1RGBA / GL_COMPRESSED_RGBA_S3TC_DXT1_EXT / GL_RGBA / GL_UNSIGNED_BYTE
OK: texformat_DXT3 / GL_COMPRESSED_RGBA_S3TC_DXT3_EXT / GL_RGBA / GL_UNSIGNED_BYTE
OK: texformat_DXT5 / GL_COMPRESSED_RGBA_S3TC_DXT5_EXT / GL_RGBA / GL_UNSIGNED_BYTE
GLES2 on ANGLE (Google's Direct3d wrapper):
You must convert the image to the desired pixel format. You do not tell the driver which internal format it should use -- it devises that from your image's pixel format Thankfully I use Vampyre Imaging library.
Code:
Trying texture formats...
OK: texformat_L8 / GL_LUMINANCE / GL_LUMINANCE / GL_UNSIGNED_BYTE
OK: texformat_LA8 / GL_LUMINANCE_ALPHA / GL_LUMINANCE_ALPHA / GL_UNSIGNED_BYTE
OK: texformat_RGB8 / GL_RGB / GL_RGB / GL_UNSIGNED_BYTE
OK: texformat_RGBA8 / GL_RGBA / GL_RGBA / GL_UNSIGNED_BYTE
texformat_R3G3B2 / GL_RGB / GL_RGB / GL_UNSIGNED_BYTE_3_3_2: failed, GL_INVALID_ENUM.
OK: texformat_R5G6B5 / GL_RGB / GL_RGB / GL_UNSIGNED_SHORT_5_6_5
texformat_R5G5B5A1 / GL_RGBA / GL_RGBA / GL_UNSIGNED_SHORT_1_5_5_5_REV: failed, GL_INVALID_ENUM.
OK: texformat_R5G5B5A1 / GL_RGBA / GL_RGBA / GL_UNSIGNED_SHORT_5_5_5_1
texformat_RGBA4 / GL_RGBA / GL_RGBA / GL_UNSIGNED_SHORT_4_4_4_4_REV: failed, GL_INVALID_ENUM.
OK: texformat_RGBA4 / GL_RGBA / GL_RGBA / GL_UNSIGNED_SHORT_4_4_4_4
OK: texformat_R16F / GL_LUMINANCE / GL_LUMINANCE / GL_HALF_FLOAT_OES
OK: texformat_RGBA16F / GL_RGBA / GL_RGBA / GL_HALF_FLOAT_OES
texformat_RGB16 / GL_RGB / GL_RGB / GL_UNSIGNED_SHORT: failed, GL_INVALID_OPERATION.
texformat_RGBA16 / GL_RGBA / GL_RGBA / GL_UNSIGNED_SHORT: failed, GL_INVALID_OPERATION.
OK: texformat_R32F / GL_LUMINANCE / GL_LUMINANCE / GL_FLOAT
OK: texformat_RGBA32F / GL_RGBA / GL_RGBA / GL_FLOAT
GLES2 on Physical raspberry Pi 2:
The same thing just with less formats working.
Code:
Trying texture formats...
OK: texformat_L8 / GL_LUMINANCE / GL_LUMINANCE / GL_UNSIGNED_BYTE
OK: texformat_LA8 / GL_LUMINANCE_ALPHA / GL_LUMINANCE_ALPHA / GL_UNSIGNED_BYTE
OK: texformat_RGB8 / GL_RGB / GL_RGB / GL_UNSIGNED_BYTE
OK: texformat_RGBA8 / GL_RGBA / GL_RGBA / GL_UNSIGNED_BYTE
texformat_R3G3B2 / GL_RGB / GL_RGB / GL_UNSIGNED_BYTE_3_3_2: failed, GL_INVALID_OPERATION.
OK: texformat_R5G6B5 / GL_RGB / GL_RGB / GL_UNSIGNED_SHORT_5_6_5
texformat_R5G5B5A1 / GL_RGBA / GL_RGBA / GL_UNSIGNED_SHORT_1_5_5_5_REV: failed, GL_INVALID_OPERATION.
OK: texformat_R5G5B5A1 / GL_RGBA / GL_RGBA / GL_UNSIGNED_SHORT_5_5_5_1
texformat_RGBA4 / GL_RGBA / GL_RGBA / GL_UNSIGNED_SHORT_4_4_4_4_REV: failed, GL_INVALID_OPERATION.
OK: texformat_RGBA4 / GL_RGBA / GL_RGBA / GL_UNSIGNED_SHORT_4_4_4_4
texformat_R16F / GL_LUMINANCE / GL_LUMINANCE / GL_HALF_FLOAT_OES: failed, GL_INVALID_OPERATION.
texformat_RGBA16F / GL_RGBA / GL_RGBA / GL_HALF_FLOAT_OES: failed, GL_INVALID_OPERATION.
texformat_RGB16 / GL_RGB / GL_RGB / GL_UNSIGNED_SHORT: failed, GL_INVALID_OPERATION.
texformat_RGBA16 / GL_RGBA / GL_RGBA / GL_UNSIGNED_SHORT: failed, GL_INVALID_OPERATION.
texformat_R32F / GL_LUMINANCE / GL_LUMINANCE / GL_FLOAT: failed, GL_INVALID_OPERATION.
texformat_RGBA32F / GL_RGBA / GL_RGBA / GL_FLOAT: failed, GL_INVALID_OPERATION.
Bookmarks