1 // Written in the D programming language. 2 /++ 3 + Authors: KanzakiKino 4 + Copyright: KanzakiKino 2018 5 + License: LGPL-3.0 6 ++/ 7 module g4d.gl.type; 8 import g4d.gl.lib, 9 g4d.util.bitmap; 10 import std.format; 11 12 /// Converts vartypes to GLenum. 13 GLenum toGLType (T) () 14 { 15 static if ( is(T==ubyte) ) { 16 return GL_UNSIGNED_BYTE; 17 } else static if ( is(T==byte) ) { 18 return GL_BYTE; 19 } else static if ( is(T==ushort) ) { 20 return GL_UNSIGNED_SHORT; 21 } else static if ( is(T==short) ) { 22 return GL_SHORT; 23 } else static if ( is(T==uint) ) { 24 return GL_UNSIGNED_INT; 25 } else static if ( is(T==int) ) { 26 return GL_INT; 27 } else static if ( is(T==float) ) { 28 return GL_FLOAT; 29 } else { 30 enum typeName = __traits(identifier,T); 31 static assert( false, "Failed converting %s to GL_*.".format(typeName) ); 32 } 33 } 34 35 /// Converts length per pixel to GLenum(pixel format). 36 /// Examples: assert( 4.toFormat == GL_RGBA ); 37 GLenum toFormat ( uint lpp ) 38 { 39 assert( lpp > 0 && lpp <= 4 ); 40 return lpp==1? GL_RED : 41 lpp==2? GL_RG : 42 lpp==3? GL_RGB : 43 lpp==4? GL_RGBA: 44 0; 45 } 46 47 /// Converts length per pixel to GLenum(compressed pixel format). 48 /// Examples: assert( 4.toCompressedFormat == GL_COMPRESSED_RGBA ); 49 GLenum toCompressedFormat ( uint lpp ) 50 { 51 assert( lpp > 0 && lpp <= 4 ); 52 return lpp==1? GL_COMPRESSED_RED : 53 lpp==2? GL_COMPRESSED_RG : 54 lpp==3? GL_COMPRESSED_RGB : 55 lpp==4? GL_COMPRESSED_RGBA: 56 0; 57 }