1 module des.gl.type; 2 3 import std.stdio; 4 import std..string; 5 6 import des.gl.general; 7 8 /// 9 enum GLType 10 { 11 UBYTE = GL_UNSIGNED_BYTE, /// `GL_UNSIGNED_BYTE` 12 BYTE = GL_BYTE, /// `GL_BYTE` 13 USHORT = GL_UNSIGNED_SHORT, /// `GL_UNSIGNED_SHORT` 14 SHORT = GL_SHORT, /// `GL_SHORT` 15 UINT = GL_UNSIGNED_INT, /// `GL_UNSIGNED_INT` 16 INT = GL_INT, /// `GL_INT` 17 FLOAT = GL_FLOAT, /// `GL_FLOAT` 18 DOUBLE = GL_DOUBLE, /// `GL_DOUBLE` 19 } 20 21 /// 22 size_t sizeofGLType( GLType type ) pure nothrow 23 { 24 final switch(type) 25 { 26 case GLType.BYTE: 27 case GLType.UBYTE: 28 return byte.sizeof; 29 30 case GLType.SHORT: 31 case GLType.USHORT: 32 return short.sizeof; 33 34 case GLType.INT: 35 case GLType.UINT: 36 return int.sizeof; 37 38 case GLType.FLOAT: 39 return float.sizeof; 40 41 case GLType.DOUBLE: 42 return double.sizeof; 43 } 44 } 45 46 /// 47 GLType toGLType(T)() nothrow pure @nogc @safe @property 48 { 49 static if( is( T == ubyte ) ) 50 return GLType.UBYTE; 51 else static if( is( T == byte ) ) 52 return GLType.BYTE; 53 else static if( is( T == ushort ) ) 54 return GLType.USHORT; 55 else static if( is( T == short ) ) 56 return GLType.SHORT; 57 else static if( is( T == uint ) ) 58 return GLType.UINT; 59 else static if( is( T == int ) ) 60 return GLType.INT; 61 else static if( is( T == float ) ) 62 return GLType.FLOAT; 63 else static if( is( T == double ) ) 64 return GLType.DOUBLE; 65 else 66 { 67 pragma(msg, "no GLType for ", T ); 68 static assert(0); 69 } 70 } 71 72 /// 73 unittest 74 { 75 assert( toGLType!ubyte == GLType.UBYTE ); 76 assert( toGLType!byte == GLType.BYTE ); 77 assert( toGLType!ushort == GLType.USHORT ); 78 assert( toGLType!short == GLType.SHORT ); 79 assert( toGLType!uint == GLType.UINT ); 80 assert( toGLType!int == GLType.INT ); 81 assert( toGLType!float == GLType.FLOAT ); 82 assert( toGLType!double == GLType.DOUBLE ); 83 } 84 85 import std.traits : EnumMembers; 86 87 /// 88 enum GLBufferTarget 89 { 90 UNKNOWN = 0, /// equals zero 91 ARRAY = GL_ARRAY_BUFFER, /// `GL_ARRAY_BUFFER` 92 ATOMIC_COUNTER = GL_ATOMIC_COUNTER_BUFFER, /// `GL_ATOMIC_COUNTER_BUFFER` 93 DISPATCH_INDIRECT = GL_DISPATCH_INDIRECT_BUFFER, /// `GL_DISPATCH_INDIRECT_BUFFER` 94 DRAW_INDIRECT = GL_DRAW_INDIRECT_BUFFER, /// `GL_DRAW_INDIRECT_BUFFER` 95 ELEMENT_ARRAY = GL_ELEMENT_ARRAY_BUFFER, /// `GL_ELEMENT_ARRAY_BUFFER` 96 PIXEL_PACK = GL_PIXEL_PACK_BUFFER, /// `GL_PIXEL_PACK_BUFFER` 97 PIXEL_UNPACK = GL_PIXEL_UNPACK_BUFFER, /// `GL_PIXEL_UNPACK_BUFFER` 98 QUERY = GL_QUERY_BUFFER, /// `GL_QUERY_BUFFER` 99 SHADER_STORAGE = GL_SHADER_STORAGE_BUFFER, /// `GL_SHADER_STORAGE_BUFFER` 100 TEXTURE = GL_TEXTURE_BUFFER, /// `GL_TEXTURE_BUFFER` 101 TRANSFORM_FEEDBACK = GL_TRANSFORM_FEEDBACK_BUFFER, /// `GL_TRANSFORM_FEEDBACK_BUFFER` 102 UNIFORM = GL_UNIFORM_BUFFER, /// `GL_UNIFORM_BUFFER` 103 } 104 105 /// 106 GLBufferTarget toGLBufferTarget( GLenum trg ) pure nothrow @nogc 107 { 108 foreach( e; [EnumMembers!GLBufferTarget] ) 109 if( cast(GLenum)e == trg ) return e; 110 return GLBufferTarget.UNKNOWN; 111 } 112 113 /// 114 enum GLTextureTarget 115 { 116 UNKNOWN = 0, /// equals zero 117 T1D = GL_TEXTURE_1D, /// `GL_TEXTURE_1D` 118 T1D_ARRAY = GL_TEXTURE_1D_ARRAY, /// `GL_TEXTURE_1D_ARRAY` 119 T2D = GL_TEXTURE_2D, /// `GL_TEXTURE_2D` 120 T2D_ARRAY = GL_TEXTURE_2D_ARRAY, /// `GL_TEXTURE_2D_ARRAY` 121 T2D_MULTISAMPLE = GL_TEXTURE_2D_MULTISAMPLE, /// `GL_TEXTURE_2D_MULTISAMPLE` 122 T2D_MULTISAMPLE_ARRAY = GL_TEXTURE_2D_MULTISAMPLE_ARRAY, /// `GL_TEXTURE_2D_MULTISAMPLE_ARRAY` 123 T3D = GL_TEXTURE_3D, /// `GL_TEXTURE_3D` 124 CUBE_MAP = GL_TEXTURE_CUBE_MAP, /// `GL_TEXTURE_CUBE_MAP` 125 CUBE_MAP_ARRAY = GL_TEXTURE_CUBE_MAP_ARRAY, /// `GL_TEXTURE_CUBE_MAP_ARRAY` 126 RECTANGLE = GL_TEXTURE_RECTANGLE, /// `GL_TEXTURE_RECTANGLE` 127 CUBE_MAP_POSITIVE_X = GL_TEXTURE_CUBE_MAP_POSITIVE_X, /// `GL_TEXTURE_CUBE_MAP_POSITIVE_X` 128 CUBE_MAP_NEGATIVE_X = GL_TEXTURE_CUBE_MAP_NEGATIVE_X, /// `GL_TEXTURE_CUBE_MAP_NEGATIVE_X` 129 CUBE_MAP_POSITIVE_Y = GL_TEXTURE_CUBE_MAP_POSITIVE_Y, /// `GL_TEXTURE_CUBE_MAP_POSITIVE_X` 130 CUBE_MAP_NEGATIVE_Y = GL_TEXTURE_CUBE_MAP_NEGATIVE_Y, /// `GL_TEXTURE_CUBE_MAP_NEGATIVE_X` 131 CUBE_MAP_POSITIVE_Z = GL_TEXTURE_CUBE_MAP_POSITIVE_Z, /// `GL_TEXTURE_CUBE_MAP_POSITIVE_X` 132 CUBE_MAP_NEGATIVE_Z = GL_TEXTURE_CUBE_MAP_NEGATIVE_Z, /// `GL_TEXTURE_CUBE_MAP_NEGATIVE_X` 133 } 134 135 /// 136 GLTextureTarget toGLTextureTarget( GLenum trg ) pure nothrow @nogc 137 { 138 foreach( e; [EnumMembers!GLTextureTarget] ) 139 if( cast(GLenum)e == trg ) return e; 140 return GLTextureTarget.UNKNOWN; 141 }