... | ... |
@@ -208,6 +208,24 @@ GLTEST(2, 0, 640, 480, glshader) |
208 | 208 |
"uniform block required but not found (did you mean the uniform?)." |
209 | 209 |
) |
210 | 210 |
|
211 |
+ // Texture. |
|
212 |
+ auto texture0 = GLuint{}; |
|
213 |
+ glGenTextures(1, &texture0); |
|
214 |
+ GLTEST_EXPECT_EXCEPTION(false, |
|
215 |
+ Shader({"tests/texture.vert"}).use().texture("texture0", texture0, GL_TEXTURE_2D).texture("texture0", texture0, GL_TEXTURE_3D), |
|
216 |
+ "Failed to set texture 1; " |
|
217 |
+ "expected target GL_TEXTURE_2D but got GL_TEXTURE_3D." |
|
218 |
+ ) |
|
219 |
+ auto texture1 = GLuint{}; |
|
220 |
+ glGenTextures(1, &texture1); |
|
221 |
+ glActiveTexture(GL_TEXTURE0); |
|
222 |
+ glBindTexture(GL_TEXTURE_3D, texture1); |
|
223 |
+ GLTEST_EXPECT_EXCEPTION(false, |
|
224 |
+ Shader({"tests/texture.vert"}).use().texture("texture0", texture1, GL_TEXTURE_2D), |
|
225 |
+ "Failed to bind texture 2 to target GL_TEXTURE_2D; " |
|
226 |
+ "got error GL_INVALID_OPERATION (wrong target?)." |
|
227 |
+ ) |
|
228 |
+ |
|
211 | 229 |
auto all = Shader({ |
212 | 230 |
"tests/all.vert", |
213 | 231 |
"tests/all.frag", |
... | ... |
@@ -1,3 +1,4 @@ |
1 |
+#include <array> |
|
1 | 2 |
#include <string> |
2 | 3 |
|
3 | 4 |
#include <GL/glew.h> |
... | ... |
@@ -166,6 +167,47 @@ GLTEST(2, 0, 640, 480, glshader) |
166 | 167 |
// Uniform OpenGL Mathematics (GLM). |
167 | 168 |
glm::vec4 color{1.0F}; |
168 | 169 |
|
170 |
+ // Uniform buffer. |
|
171 |
+ struct |
|
172 |
+ { |
|
173 |
+ std::array<float, 4> value1; |
|
174 |
+ } small = {}; |
|
175 |
+ struct |
|
176 |
+ { |
|
177 |
+ std::array<float, 4> value1; |
|
178 |
+ std::array<float, 4> value2; |
|
179 |
+ } big = {}; |
|
180 |
+ GLTEST_EXPECT_EXCEPTION(false, |
|
181 |
+ Shader({"tests/uniform_buffer_small.vert"}).use().validate(), |
|
182 |
+ "Failed to validate shader program 'tests/uniform_buffer_small.vert'; " |
|
183 |
+ "uniform block 'small' not set." |
|
184 |
+ ) |
|
185 |
+ GLTEST_EXPECT_EXCEPTION(false, |
|
186 |
+ Shader::uniform_buffer("small", big), |
|
187 |
+ "Failed to set uniform buffer 'small'; " |
|
188 |
+ "expected size 16 but got 32." |
|
189 |
+ ) |
|
190 |
+ GLTEST_EXPECT_EXCEPTION(false, |
|
191 |
+ Shader({"tests/uniform_buffer_small.vert"}).use().uniform("small", big), |
|
192 |
+ "Failed to set uniform block 'small' of shader program 'tests/uniform_buffer_small.vert'; " |
|
193 |
+ "expected size 16 but got 32." |
|
194 |
+ ) |
|
195 |
+ GLTEST_EXPECT_EXCEPTION(false, |
|
196 |
+ Shader({"tests/uniform_buffer_bad_size.vert"}), |
|
197 |
+ "Failed to initialize uniform block 'small' of shader program 'tests/uniform_buffer_bad_size.vert'; " |
|
198 |
+ "expected size 16 but got 32." |
|
199 |
+ ) |
|
200 |
+ GLTEST_EXPECT_EXCEPTION(false, |
|
201 |
+ Shader({"tests/uniform_buffer_small.vert"}).use().uniform("small", 1.0F), |
|
202 |
+ "Failed to set uniform 'small' of shader program 'tests/uniform_buffer_small.vert'; " |
|
203 |
+ "uniform required but not found (did you mean the uniform block?)." |
|
204 |
+ ) |
|
205 |
+ GLTEST_EXPECT_EXCEPTION(false, |
|
206 |
+ Shader({"tests/uniform_blue.frag"}).use().uniform("blue", small), |
|
207 |
+ "Failed to set uniform block 'blue' of shader program 'tests/uniform_blue.frag'; " |
|
208 |
+ "uniform block required but not found (did you mean the uniform?)." |
|
209 |
+ ) |
|
210 |
+ |
|
169 | 211 |
auto all = Shader({ |
170 | 212 |
"tests/all.vert", |
171 | 213 |
"tests/all.frag", |
... | ... |
@@ -175,7 +217,9 @@ GLTEST(2, 0, 640, 480, glshader) |
175 | 217 |
.use() |
176 | 218 |
.uniform("blue", blue) |
177 | 219 |
.uniform("color", color) |
220 |
+ .uniform("small", small) |
|
178 | 221 |
.validate(); |
222 |
+ Shader::uniform_buffer("small", small); |
|
179 | 223 |
|
180 | 224 |
constexpr auto size = 0.5F; |
181 | 225 |
glBegin(GL_TRIANGLE_STRIP); |
... | ... |
@@ -1,8 +1,10 @@ |
1 | 1 |
#include <string> |
2 | 2 |
|
3 | 3 |
#include <GL/glew.h> |
4 |
+#include <glm/glm.hpp> |
|
4 | 5 |
|
5 | 6 |
#include <glshader.hpp> |
7 |
+#include <glshader_glm.hpp> |
|
6 | 8 |
#include <gltest.hpp> |
7 | 9 |
|
8 | 10 |
|
... | ... |
@@ -161,6 +163,9 @@ GLTEST(2, 0, 640, 480, glshader) |
161 | 163 |
"got error GL_INVALID_OPERATION (wrong type?)." |
162 | 164 |
) |
163 | 165 |
|
166 |
+ // Uniform OpenGL Mathematics (GLM). |
|
167 |
+ glm::vec4 color{1.0F}; |
|
168 |
+ |
|
164 | 169 |
auto all = Shader({ |
165 | 170 |
"tests/all.vert", |
166 | 171 |
"tests/all.frag", |
... | ... |
@@ -169,6 +174,7 @@ GLTEST(2, 0, 640, 480, glshader) |
169 | 174 |
all |
170 | 175 |
.use() |
171 | 176 |
.uniform("blue", blue) |
177 |
+ .uniform("color", color) |
|
172 | 178 |
.validate(); |
173 | 179 |
|
174 | 180 |
constexpr auto size = 0.5F; |
... | ... |
@@ -137,6 +137,30 @@ GLTEST(2, 0, 640, 480, glshader) |
137 | 137 |
"Failed to initialize vertex input 'vert_unset' of shader program 'tests/vert_unset.vert'." |
138 | 138 |
); |
139 | 139 |
|
140 |
+ // Uniform scalars. |
|
141 |
+ constexpr auto blue = 0.25F; |
|
142 |
+ GLTEST_EXPECT_EXCEPTION(false, |
|
143 |
+ Shader({"tests/uniform_blue.frag"}).uniform("noncurrent", 1.0F), |
|
144 |
+ "Failed to set uniform 'noncurrent' of shader program 'tests/uniform_blue.frag'; " |
|
145 |
+ "shader program not current." |
|
146 |
+ ) |
|
147 |
+ GLTEST_EXPECT_EXCEPTION(false, |
|
148 |
+ Shader({"tests/uniform_blue.frag"}).use().uniform("nonexistent", 1.0F), |
|
149 |
+ "Failed to set uniform 'nonexistent' of shader program 'tests/uniform_blue.frag'; " |
|
150 |
+ "uniform required but not found." |
|
151 |
+ ) |
|
152 |
+ Shader({"tests/uniform_blue.frag"}).use().uniform("nonexistent", 1.0F, false); |
|
153 |
+ GLTEST_EXPECT_EXCEPTION(false, |
|
154 |
+ Shader({"tests/uniform_blue.frag"}).use().validate(), |
|
155 |
+ "Failed to validate shader program 'tests/uniform_blue.frag'; " |
|
156 |
+ "uniform 'blue' not set." |
|
157 |
+ ) |
|
158 |
+ GLTEST_EXPECT_EXCEPTION(false, |
|
159 |
+ Shader({"tests/uniform_blue.frag"}).use().uniform("blue", 1), |
|
160 |
+ "Failed to set uniform 'blue' of shader program 'tests/uniform_blue.frag'; " |
|
161 |
+ "got error GL_INVALID_OPERATION (wrong type?)." |
|
162 |
+ ) |
|
163 |
+ |
|
140 | 164 |
auto all = Shader({ |
141 | 165 |
"tests/all.vert", |
142 | 166 |
"tests/all.frag", |
... | ... |
@@ -144,6 +168,7 @@ GLTEST(2, 0, 640, 480, glshader) |
144 | 168 |
|
145 | 169 |
all |
146 | 170 |
.use() |
171 |
+ .uniform("blue", blue) |
|
147 | 172 |
.validate(); |
148 | 173 |
|
149 | 174 |
constexpr auto size = 0.5F; |
... | ... |
@@ -125,6 +125,18 @@ GLTEST(2, 0, 640, 480, glshader) |
125 | 125 |
"assets/shaders/tests/include_nested_extension.vert:7: #include \"include_nested_extension.h\"" |
126 | 126 |
) |
127 | 127 |
|
128 |
+ // Vertex inputs. |
|
129 |
+ constexpr auto vert_position = 0; |
|
130 |
+ constexpr auto vert_tex_coord = 1; |
|
131 |
+ Shader::verts({ |
|
132 |
+ {"vert_position", vert_position}, |
|
133 |
+ {"vert_tex_coord", vert_tex_coord}, |
|
134 |
+ }); |
|
135 |
+ GLTEST_EXPECT_EXCEPTION(false, |
|
136 |
+ Shader({"tests/vert_unset.vert"}), |
|
137 |
+ "Failed to initialize vertex input 'vert_unset' of shader program 'tests/vert_unset.vert'." |
|
138 |
+ ); |
|
139 |
+ |
|
128 | 140 |
auto all = Shader({ |
129 | 141 |
"tests/all.vert", |
130 | 142 |
"tests/all.frag", |
... | ... |
@@ -31,7 +31,7 @@ GLTEST(2, 0, 640, 480, glshader) |
31 | 31 |
GLTEST_EXPECT_EXCEPTION(true, |
32 | 32 |
Shader({"tests/create_bad_compile.vert"}), |
33 | 33 |
"Failed to compile shader 'tests/create_bad_compile.vert' of shader program 'tests/create_bad_compile.vert':\n" |
34 |
- "0:4(5): error: main() must return void\n" |
|
34 |
+ "\"assets/shaders/tests/create_bad_compile.vert\":4(5): error: main() must return void\n" |
|
35 | 35 |
) |
36 | 36 |
GLTEST_EXPECT_EXCEPTION(true, |
37 | 37 |
Shader({"tests/create_bad_link.vert"}), |
... | ... |
@@ -78,6 +78,53 @@ GLTEST(2, 0, 640, 480, glshader) |
78 | 78 |
{"red", std::to_string(red)}, |
79 | 79 |
}); |
80 | 80 |
|
81 |
+ // Include. |
|
82 |
+ GLTEST_EXPECT_EXCEPTION(true, |
|
83 |
+ Shader({"tests/include_malformed_extension.vert"}), |
|
84 |
+ "Failed to source shader 'tests/include_malformed_extension.vert' of shader program 'tests/include_malformed_extension.vert'; " |
|
85 |
+ "malformed #extension:\n" |
|
86 |
+ "assets/shaders/tests/include_malformed_extension.vert:4: #extension extension" |
|
87 |
+ ) |
|
88 |
+ GLTEST_EXPECT_EXCEPTION(true, |
|
89 |
+ Shader({"tests/include_malformed.vert"}), |
|
90 |
+ "Failed to source shader 'tests/include_malformed.vert' of shader program 'tests/include_malformed.vert'; " |
|
91 |
+ "malformed #include:\n" |
|
92 |
+ "assets/shaders/tests/include_malformed.vert:7: #include \"bad_include_malformed.h\" malformed.h\"" |
|
93 |
+ ) |
|
94 |
+ GLTEST_EXPECT_EXCEPTION(true, |
|
95 |
+ Shader({"tests/include_mismatched_quotes.vert"}), |
|
96 |
+ "Failed to source shader 'tests/include_mismatched_quotes.vert' of shader program 'tests/include_mismatched_quotes.vert'; " |
|
97 |
+ "mismatched #include quotes '\"' and '>':\n" |
|
98 |
+ "assets/shaders/tests/include_mismatched_quotes.vert:7: #include \"bad_include_quotes.h>" |
|
99 |
+ ) |
|
100 |
+ GLTEST_EXPECT_EXCEPTION(true, |
|
101 |
+ Shader({"tests/include_no_extension.vert"}), |
|
102 |
+ "Failed to source shader 'tests/include_no_extension.vert' of shader program 'tests/include_no_extension.vert'; " |
|
103 |
+ "#include found but #extension GL_ARB_shading_language_include not enabled:\n" |
|
104 |
+ "assets/shaders/tests/include_no_extension.vert:4: #include \"bad_include_noextension.h\"" |
|
105 |
+ ) |
|
106 |
+ GLTEST_EXPECT_EXCEPTION(true, |
|
107 |
+ Shader({"tests/include_nonexistent.vert"}), |
|
108 |
+ "Failed to source shader 'tests/include_nonexistent.vert' of shader program 'tests/include_nonexistent.vert'; " |
|
109 |
+ "could not open file 'assets/shaders/tests/bad_include_nonexistent.h':\n" |
|
110 |
+ "assets/shaders/tests/include_nonexistent.vert:7: #include \"bad_include_nonexistent.h\":\n" |
|
111 |
+ "No such file or directory" |
|
112 |
+ ) |
|
113 |
+ GLTEST_EXPECT_EXCEPTION(false, |
|
114 |
+ Shader({"tests/include_nested_version.vert"}), |
|
115 |
+ "Failed to source shader 'tests/include_nested_version.vert' of shader program 'tests/include_nested_version.vert'; " |
|
116 |
+ "found #version in #include:\n" |
|
117 |
+ "assets/shaders/tests/include_nested_version.h:1: #version 110\n" |
|
118 |
+ "assets/shaders/tests/include_nested_version.vert:7: #include \"include_nested_version.h\"" |
|
119 |
+ ) |
|
120 |
+ GLTEST_EXPECT_EXCEPTION(false, |
|
121 |
+ Shader({"tests/include_nested_extension.vert"}), |
|
122 |
+ "Failed to source shader 'tests/include_nested_extension.vert' of shader program 'tests/include_nested_extension.vert'; " |
|
123 |
+ "found #extension GL_ARB_shading_language_include in #include:\n" |
|
124 |
+ "assets/shaders/tests/include_nested_extension.h:1: #extension GL_ARB_shading_language_include : require\n" |
|
125 |
+ "assets/shaders/tests/include_nested_extension.vert:7: #include \"include_nested_extension.h\"" |
|
126 |
+ ) |
|
127 |
+ |
|
81 | 128 |
auto all = Shader({ |
82 | 129 |
"tests/all.vert", |
83 | 130 |
"tests/all.frag", |
... | ... |
@@ -72,6 +72,12 @@ GLTEST(2, 0, 640, 480, glshader) |
72 | 72 |
"assets/shaders/tests/version_repeated.vert:2: #version 110" |
73 | 73 |
) |
74 | 74 |
|
75 |
+ // Defines. |
|
76 |
+ constexpr auto red = 1.0F; |
|
77 |
+ Shader::defines({ |
|
78 |
+ {"red", std::to_string(red)}, |
|
79 |
+ }); |
|
80 |
+ |
|
75 | 81 |
auto all = Shader({ |
76 | 82 |
"tests/all.vert", |
77 | 83 |
"tests/all.frag", |
... | ... |
@@ -53,6 +53,25 @@ GLTEST(2, 0, 640, 480, glshader) |
53 | 53 |
"shader program not current." |
54 | 54 |
) |
55 | 55 |
|
56 |
+ // Version. |
|
57 |
+ GLTEST_EXPECT_EXCEPTION(false, |
|
58 |
+ Shader({"tests/version_none.vert"}), |
|
59 |
+ "Failed to source shader 'tests/version_none.vert' of shader program 'tests/version_none.vert'; " |
|
60 |
+ "found no #version." |
|
61 |
+ ) |
|
62 |
+ GLTEST_EXPECT_EXCEPTION(false, |
|
63 |
+ Shader({"tests/version_malformed.vert"}), |
|
64 |
+ "Failed to source shader 'tests/version_malformed.vert' of shader program 'tests/version_malformed.vert'; " |
|
65 |
+ "malformed #version:\n" |
|
66 |
+ "assets/shaders/tests/version_malformed.vert:1: #version 1.10" |
|
67 |
+ ) |
|
68 |
+ GLTEST_EXPECT_EXCEPTION(false, |
|
69 |
+ Shader({"tests/version_repeated.vert"}), |
|
70 |
+ "Failed to source shader 'tests/version_repeated.vert' of shader program 'tests/version_repeated.vert'; " |
|
71 |
+ "found repeated #version:\n" |
|
72 |
+ "assets/shaders/tests/version_repeated.vert:2: #version 110" |
|
73 |
+ ) |
|
74 |
+ |
|
56 | 75 |
auto all = Shader({ |
57 | 76 |
"tests/all.vert", |
58 | 77 |
"tests/all.frag", |
... | ... |
@@ -46,12 +46,20 @@ GLTEST(2, 0, 640, 480, glshader) |
46 | 46 |
"active samplers with a different type refer to the same texture image unit" |
47 | 47 |
) |
48 | 48 |
|
49 |
+ // Use. |
|
50 |
+ GLTEST_EXPECT_EXCEPTION(false, |
|
51 |
+ Shader({"tests/use.vert"}).validate(), |
|
52 |
+ "Failed to validate shader program 'tests/use.vert'; " |
|
53 |
+ "shader program not current." |
|
54 |
+ ) |
|
55 |
+ |
|
49 | 56 |
auto all = Shader({ |
50 | 57 |
"tests/all.vert", |
51 | 58 |
"tests/all.frag", |
52 | 59 |
}); |
53 | 60 |
|
54 | 61 |
all |
62 |
+ .use() |
|
55 | 63 |
.validate(); |
56 | 64 |
|
57 | 65 |
constexpr auto size = 0.5F; |
... | ... |
@@ -39,11 +39,21 @@ GLTEST(2, 0, 640, 480, glshader) |
39 | 39 |
"error: vertex shader does not write to `gl_Position'. \n" |
40 | 40 |
) |
41 | 41 |
|
42 |
+ // Validate. |
|
43 |
+ GLTEST_EXPECT_EXCEPTION(true, |
|
44 |
+ Shader({"tests/validate_bad_samplers.vert"}).validate(), |
|
45 |
+ "Failed to validate shader program 'tests/validate_bad_samplers.vert':\n" |
|
46 |
+ "active samplers with a different type refer to the same texture image unit" |
|
47 |
+ ) |
|
48 |
+ |
|
42 | 49 |
auto all = Shader({ |
43 | 50 |
"tests/all.vert", |
44 | 51 |
"tests/all.frag", |
45 | 52 |
}); |
46 | 53 |
|
54 |
+ all |
|
55 |
+ .validate(); |
|
56 |
+ |
|
47 | 57 |
constexpr auto size = 0.5F; |
48 | 58 |
glBegin(GL_TRIANGLE_STRIP); |
49 | 59 |
glVertex3f(-size, -size, 0.0F); |
... | ... |
@@ -0,0 +1,56 @@ |
1 |
+#include <string> |
|
2 |
+ |
|
3 |
+#include <GL/glew.h> |
|
4 |
+ |
|
5 |
+#include <glshader.hpp> |
|
6 |
+#include <gltest.hpp> |
|
7 |
+ |
|
8 |
+ |
|
9 |
+GLTEST(2, 0, 640, 480, glshader) |
|
10 |
+{ |
|
11 |
+ gltest_root("assets/tests"); |
|
12 |
+ Shader::root("assets/shaders"); |
|
13 |
+ |
|
14 |
+ // Create. |
|
15 |
+ GLTEST_EXPECT_EXCEPTION(false, |
|
16 |
+ Shader({"tests/create_noextension"}), |
|
17 |
+ "Failed to infer type of shader 'tests/create_noextension' of shader program 'tests/create_noextension'; " |
|
18 |
+ "no file extension." |
|
19 |
+ ) |
|
20 |
+ GLTEST_EXPECT_EXCEPTION(false, |
|
21 |
+ Shader({"tests/create.unknownextension"}), |
|
22 |
+ "Failed to infer type of shader 'tests/create.unknownextension' of shader program 'tests/create.unknownextension'; " |
|
23 |
+ "unknown file extension 'unknownextension'." |
|
24 |
+ ) |
|
25 |
+ GLTEST_EXPECT_EXCEPTION(true, |
|
26 |
+ Shader({"tests/create_nonexistent.vert"}), |
|
27 |
+ "Failed to source shader 'tests/create_nonexistent.vert' of shader program 'tests/create_nonexistent.vert'; " |
|
28 |
+ "could not open file 'assets/shaders/tests/create_nonexistent.vert':\n" |
|
29 |
+ "No such file or directory" |
|
30 |
+ ) |
|
31 |
+ GLTEST_EXPECT_EXCEPTION(true, |
|
32 |
+ Shader({"tests/create_bad_compile.vert"}), |
|
33 |
+ "Failed to compile shader 'tests/create_bad_compile.vert' of shader program 'tests/create_bad_compile.vert':\n" |
|
34 |
+ "0:4(5): error: main() must return void\n" |
|
35 |
+ ) |
|
36 |
+ GLTEST_EXPECT_EXCEPTION(true, |
|
37 |
+ Shader({"tests/create_bad_link.vert"}), |
|
38 |
+ "Failed to link shader program 'tests/create_bad_link.vert':\n" |
|
39 |
+ "error: vertex shader does not write to `gl_Position'. \n" |
|
40 |
+ ) |
|
41 |
+ |
|
42 |
+ auto all = Shader({ |
|
43 |
+ "tests/all.vert", |
|
44 |
+ "tests/all.frag", |
|
45 |
+ }); |
|
46 |
+ |
|
47 |
+ constexpr auto size = 0.5F; |
|
48 |
+ glBegin(GL_TRIANGLE_STRIP); |
|
49 |
+ glVertex3f(-size, -size, 0.0F); |
|
50 |
+ glVertex3f(-size, +size, 0.0F); |
|
51 |
+ glVertex3f(+size, -size, 0.0F); |
|
52 |
+ glVertex3f(+size, +size, 0.0F); |
|
53 |
+ glEnd(); |
|
54 |
+ |
|
55 |
+ GLTEST_EXPECT_FRAME("frame.data") |
|
56 |
+} |