1 
2 module glwt.shader;
3 
4 import cst_	;
5 
6 import derelict.opengl	;
7 
8 
9 
10 
11 
12 enum ShaderType {
13 	Vertex	= GL_VERTEX_SHADER	,
14 	Fragment	= GL_FRAGMENT_SHADER	,
15 	Geometry	= GL_GEOMETRY_SHADER	,
16 }
17 alias shader_type_t = ShaderType;
18 
19 
20 
21 /**	A wrapper for a shader.*/
22 struct Shader(ShaderType shaderType) {
23 	uint id = 0;
24 }
25 alias VertexShader	= Shader!(ShaderType.Vertex	) ;
26 alias FragmentShader	= Shader!(ShaderType.Fragment	) ;
27 alias GeometryShader	= Shader!(ShaderType.Geometry	) ;
28 
29 
30 
31 
32 
33 
34 /**	glCreateShader wrapper.
35 */
36 void
37 create(ShaderType shaderType)(ref Shader!shaderType shader)
38 {
39 	shader.id = glCreateShader(shaderType);
40 }
41 /**	glDeleteShader wrapper.
42 */
43 void
44 del(ShaderType shaderType)(ref Shader!shaderType shader)
45 {
46 	glDeleteShader(shader.id);
47 }
48 
49 
50 
51 
52 
53 
54 enum string shader_ensureGen_m = "version(assert){assert(shader.id!=0, \"Shader not created.  Call `shader.create` before using this function.\");}";
55 
56 
57 
58 
59 
60 /**	glShaderSource wraper
61 */
62 void
63 source(ShaderType shaderType)(ref Shader!shaderType shader, string code)
64 {
65 	mixin(shader_ensureGen_m);
66 	import std.string : toStringz;
67 	char* stringzCode = code.toStringz.cst!(char*);
68 	glShaderSource(shader.id, 1, &stringzCode, null);
69 }
70 
71 /**	glCompileShader wraper
72 */
73 void
74 compile(ShaderType shaderType)(ref Shader!shaderType shader)
75 {
76 	mixin(shader_ensureGen_m);
77 	glCompileShader(shader.id);
78 }