1 /**
2  * Copyright:   Copyright (C) 2018 Gabriel Gheorghe, All Rights Reserved
3  * Authors:     $(Gabriel Gheorghe)
4  * License:     $(LINK2 https://www.gnu.org/licenses/gpl-3.0.txt, GNU GENERAL PUBLIC LICENSE Version 3, 29 June 2007)
5  * Source:      $(LINK2 https://github.com/GabyForceQ/LibertyEngine/blob/master/source/liberty/graphics/video/shader.d, _shader.d)
6  * Documentation:
7  * Coverage:
8  */
9 module liberty.graphics.video.shader;
10 import liberty.math.vector : Vector2F, Vector3F, Vector4F;
11 import liberty.math.matrix: Matrix4F;
12 import liberty.graphics.renderer : Renderable;
13 import liberty.core.engine;
14 ///
15 enum ShaderType : byte {
16     ///
17     Vertex = 0x00,
18     ///
19     Fragment = 0x01,
20     ///
21     Geometry = 0x02,
22     ///
23     TesselationControl = 0x03,
24     ///
25     TesselationEval = 0x04,
26     ///
27     Compute = 0x05,
28     ///
29     Primitive = 0x06,
30     ///
31     Stencil = 0x07
32 }
33 ///
34 enum ShaderLanguage : byte {
35     ///
36     GLSL = 0x00,
37     ///
38     SPV = 0x01
39 }
40 ///
41 abstract class ShaderProgram : Renderable {
42 	protected {
43         uint _programID;
44         uint _vertexShaderID;
45         uint _fragmentShaderID;
46     }
47     ///
48     uint programID();
49     ///
50     void start();
51     ///
52     void stop();
53     ///
54     void cleanUp();
55     ///
56     void bindAttribute(int attribute, string var_name);
57     /// Load bool uniform using location id and value.
58     void loadUniform(int locationID, bool value) nothrow @trusted @nogc;
59     /// Load int uniform using location id and value.
60     void loadUniform(int locationID, int value) nothrow @trusted @nogc;
61     /// Load uint uniform using location id and value.
62     void loadUniform(int locationID, uint value) nothrow @trusted @nogc;
63     /// Load float uniform using location id and value.
64     void loadUniform(int locationID, float value) nothrow @trusted @nogc;
65     /// Load vec2 uniform using location id and value.
66     void loadUniform(int locationID, Vector2F vector) nothrow @trusted @nogc;
67     /// Load vec3 uniform using location id and value.
68     void loadUniform(int locationID, Vector3F vector) nothrow @trusted @nogc;
69     /// Load vec4 uniform using location id and value.
70     void loadUniform(int locationID, Vector4F vector) nothrow @trusted @nogc;
71     /// Load mat4 uniform using location id and value.
72     void loadUniform(int locationID, Matrix4F matrix) nothrow @trusted @nogc;
73     /// Load bool uniform using uniform name and value.
74     void loadUniform(string name, bool value) nothrow @trusted @nogc;
75     /// Load int uniform using uniform name and value.
76     void loadUniform(string name, int value) nothrow @trusted @nogc;
77     /// Load uint uniform using uniform name and value.
78     void loadUniform(string name, uint value) nothrow @trusted @nogc;
79     /// Load float uniform using uniform name and value.
80     void loadUniform(string name, float value) nothrow @trusted @nogc;
81     /// Load vec2 uniform using uniform name and value.
82     void loadUniform(string name, Vector2F vector) nothrow @trusted @nogc;
83     /// Load vec3 uniform using uniform name and value.
84     void loadUniform(string name, Vector3F vector) nothrow @trusted @nogc;
85     /// Load vec4 uniform using uniform name and value.
86     void loadUniform(string name, Vector4F vector) nothrow @trusted @nogc;
87     /// Load mat4 uniform using uniform name and value.
88     void loadUniform(string name, Matrix4F matrix) nothrow @trusted @nogc;
89     ///
90     override void render() {
91         loadUniform("projection", CoreEngine.get.activeScene.activeCamera.projection); // TODO: NOT HERE? ONLY ONCE?
92         loadUniform("view", CoreEngine.get.activeScene.activeCamera.view); // TODO: NOT HERE? ONLY ONCE?
93     }
94 }