Merge lp:~widelands-dev/widelands/bug-1397500 into lp:widelands
- bug-1397500
- Merge into trunk
Status: | Merged |
---|---|
Merged at revision: | 7794 |
Proposed branch: | lp:~widelands-dev/widelands/bug-1397500 |
Merge into: | lp:widelands |
Diff against target: |
737 lines (+243/-280) 21 files modified
data/shaders/blit.fp (+28/-0) data/shaders/blit.vp (+21/-0) data/shaders/dither.fp (+24/-0) data/shaders/dither.vp (+24/-0) data/shaders/draw_line.fp (+7/-0) data/shaders/draw_line.vp (+12/-0) data/shaders/fill_rect.fp (+7/-0) data/shaders/fill_rect.vp (+12/-0) data/shaders/road.fp (+13/-0) data/shaders/road.vp (+18/-0) data/shaders/terrain.fp (+26/-0) data/shaders/terrain.vp (+21/-0) src/graphic/CMakeLists.txt (+2/-0) src/graphic/gl/blit_program.cc (+1/-56) src/graphic/gl/dither_program.cc (+1/-59) src/graphic/gl/draw_line_program.cc (+1/-26) src/graphic/gl/fill_rect_program.cc (+1/-30) src/graphic/gl/road_program.cc (+1/-42) src/graphic/gl/terrain_program.cc (+2/-61) src/graphic/gl/utils.cc (+18/-3) src/graphic/gl/utils.h (+3/-3) |
To merge this branch: | bzr merge lp:~widelands-dev/widelands/bug-1397500 |
Related bugs: |
Reviewer | Review Type | Date Requested | Status |
---|---|---|---|
SirVer | Approve | ||
Review via email: mp+284574@code.launchpad.net |
Commit message
Moved GL shaders into external files. Fragment shaders now live in "data/shaders/
Description of the change
Now to the original purpose of this bug: moved the GL shaders into text files.
The warning message in utils/buildcat.py is now gone.
bunnybot (widelandsofficial) wrote : | # |
bunnybot (widelandsofficial) wrote : | # |
Continuous integration builds have changed state:
Travis build 472. State: errored. Details: https:/
Appveyor build 365. State: success. Details: https:/
bunnybot (widelandsofficial) wrote : | # |
Continuous integration builds have changed state:
Travis build 485. State: failed. Details: https:/
Appveyor build 370. State: success. Details: https:/
bunnybot (widelandsofficial) wrote : | # |
Continuous integration builds have changed state:
Travis build 503. State: errored. Details: https:/
Appveyor build 384. State: success. Details: https:/
bunnybot (widelandsofficial) wrote : | # |
Continuous integration builds have changed state:
Travis build 536. State: passed. Details: https:/
Appveyor build 384. State: success. Details: https:/
kaputtnik (franku) wrote : | # |
Maybe a silly question: With this change we have some piece of C++ code living in directory data/. As i understand this folder would be regularly installed in a whole (from an installer or when installing over a ppa). So they get installed without usage?
kaputtnik (franku) wrote : | # |
Sorry, answered myself... the files are needed after compiling and when starting widelands.
SirVer (sirver) wrote : | # |
Looks great. I fixed a couple of small nits while testing - see last commit. If you are happy, feel free to merge.
GunChleoc (gunchleoc) wrote : | # |
Yes, that looks much better :)
@bunnybot merge
Preview Diff
1 | === added directory 'data/shaders' |
2 | === added file 'data/shaders/blit.fp' |
3 | --- data/shaders/blit.fp 1970-01-01 00:00:00 +0000 |
4 | +++ data/shaders/blit.fp 2016-02-06 20:55:31 +0000 |
5 | @@ -0,0 +1,28 @@ |
6 | +#version 120 |
7 | + |
8 | +uniform sampler2D u_texture; |
9 | +uniform sampler2D u_mask; |
10 | + |
11 | +varying vec2 out_mask_texture_coordinate; |
12 | +varying vec2 out_texture_coordinate; |
13 | +varying vec4 out_blend; |
14 | +varying float out_program_flavor; |
15 | + |
16 | +void main() { |
17 | + vec4 texture_color = texture2D(u_texture, out_texture_coordinate); |
18 | + |
19 | + // See http://en.wikipedia.org/wiki/YUV. |
20 | + float luminance = dot(vec3(0.299, 0.587, 0.114), texture_color.rgb); |
21 | + |
22 | + if (out_program_flavor == 0.) { |
23 | + gl_FragColor = vec4(texture_color.rgb, out_blend.a * texture_color.a); |
24 | + } else if (out_program_flavor == 1.) { |
25 | + gl_FragColor = vec4(vec3(luminance) * out_blend.rgb, out_blend.a * texture_color.a); |
26 | + } else { |
27 | + vec4 mask_color = texture2D(u_mask, out_mask_texture_coordinate); |
28 | + float blend_influence = mask_color.r * mask_color.a; |
29 | + gl_FragColor = vec4( |
30 | + mix(texture_color.rgb, out_blend.rgb * luminance, blend_influence), |
31 | + out_blend.a * texture_color.a); |
32 | + } |
33 | +} |
34 | |
35 | === added file 'data/shaders/blit.vp' |
36 | --- data/shaders/blit.vp 1970-01-01 00:00:00 +0000 |
37 | +++ data/shaders/blit.vp 2016-02-06 20:55:31 +0000 |
38 | @@ -0,0 +1,21 @@ |
39 | +#version 120 |
40 | + |
41 | +// Attributes. |
42 | +attribute vec2 attr_mask_texture_position; |
43 | +attribute vec2 attr_texture_position; |
44 | +attribute vec3 attr_position; |
45 | +attribute vec4 attr_blend; |
46 | +attribute float attr_program_flavor; |
47 | + |
48 | +varying vec2 out_mask_texture_coordinate; |
49 | +varying vec2 out_texture_coordinate; |
50 | +varying vec4 out_blend; |
51 | +varying float out_program_flavor; |
52 | + |
53 | +void main() { |
54 | + out_mask_texture_coordinate = attr_mask_texture_position; |
55 | + out_texture_coordinate = attr_texture_position; |
56 | + out_blend = attr_blend; |
57 | + out_program_flavor = attr_program_flavor; |
58 | + gl_Position = vec4(attr_position, 1.); |
59 | +} |
60 | |
61 | === added file 'data/shaders/dither.fp' |
62 | --- data/shaders/dither.fp 1970-01-01 00:00:00 +0000 |
63 | +++ data/shaders/dither.fp 2016-02-06 20:55:31 +0000 |
64 | @@ -0,0 +1,24 @@ |
65 | +#version 120 |
66 | + |
67 | +uniform sampler2D u_dither_texture; |
68 | +uniform sampler2D u_terrain_texture; |
69 | +uniform vec2 u_texture_dimensions; |
70 | + |
71 | +varying float var_brightness; |
72 | +varying vec2 var_dither_texture_position; |
73 | +varying vec2 var_texture_position; |
74 | +varying vec2 var_texture_offset; |
75 | + |
76 | +// TODO(sirver): This is a hack to make sure we are sampling inside of the |
77 | +// terrain texture. This is a common problem with OpenGL and texture atlases. |
78 | +#define MARGIN 1e-2 |
79 | + |
80 | +void main() { |
81 | + vec2 texture_fract = clamp( |
82 | + fract(var_texture_position), |
83 | + vec2(MARGIN, MARGIN), |
84 | + vec2(1. - MARGIN, 1. - MARGIN)); |
85 | + vec4 clr = texture2D(u_terrain_texture, var_texture_offset + u_texture_dimensions * texture_fract); |
86 | + gl_FragColor = vec4(clr.rgb * var_brightness, |
87 | + 1. - texture2D(u_dither_texture, var_dither_texture_position).a); |
88 | +} |
89 | |
90 | === added file 'data/shaders/dither.vp' |
91 | --- data/shaders/dither.vp 1970-01-01 00:00:00 +0000 |
92 | +++ data/shaders/dither.vp 2016-02-06 20:55:31 +0000 |
93 | @@ -0,0 +1,24 @@ |
94 | +#version 120 |
95 | + |
96 | +// Attributes. |
97 | +attribute float attr_brightness; |
98 | +attribute vec2 attr_dither_texture_position; |
99 | +attribute vec2 attr_position; |
100 | +attribute vec2 attr_texture_offset; |
101 | +attribute vec2 attr_texture_position; |
102 | + |
103 | +uniform float u_z_value; |
104 | + |
105 | +// Output of vertex shader. |
106 | +varying float var_brightness; |
107 | +varying vec2 var_dither_texture_position; |
108 | +varying vec2 var_texture_offset; |
109 | +varying vec2 var_texture_position; |
110 | + |
111 | +void main() { |
112 | + var_brightness = attr_brightness; |
113 | + var_dither_texture_position = attr_dither_texture_position; |
114 | + var_texture_offset = attr_texture_offset; |
115 | + var_texture_position = attr_texture_position; |
116 | + gl_Position = vec4(attr_position, u_z_value, 1.); |
117 | +} |
118 | |
119 | === added file 'data/shaders/draw_line.fp' |
120 | --- data/shaders/draw_line.fp 1970-01-01 00:00:00 +0000 |
121 | +++ data/shaders/draw_line.fp 2016-02-06 20:55:31 +0000 |
122 | @@ -0,0 +1,7 @@ |
123 | +#version 120 |
124 | + |
125 | +varying vec3 var_color; |
126 | + |
127 | +void main() { |
128 | + gl_FragColor = vec4(var_color.rgb, 1.); |
129 | +} |
130 | |
131 | === added file 'data/shaders/draw_line.vp' |
132 | --- data/shaders/draw_line.vp 1970-01-01 00:00:00 +0000 |
133 | +++ data/shaders/draw_line.vp 2016-02-06 20:55:31 +0000 |
134 | @@ -0,0 +1,12 @@ |
135 | +#version 120 |
136 | + |
137 | +// Attributes. |
138 | +attribute vec3 attr_position; |
139 | +attribute vec3 attr_color; |
140 | + |
141 | +varying vec3 var_color; |
142 | + |
143 | +void main() { |
144 | + var_color = attr_color; |
145 | + gl_Position = vec4(attr_position, 1.); |
146 | +} |
147 | |
148 | === added file 'data/shaders/fill_rect.fp' |
149 | --- data/shaders/fill_rect.fp 1970-01-01 00:00:00 +0000 |
150 | +++ data/shaders/fill_rect.fp 2016-02-06 20:55:31 +0000 |
151 | @@ -0,0 +1,7 @@ |
152 | +#version 120 |
153 | + |
154 | +varying vec4 var_color; |
155 | + |
156 | +void main() { |
157 | + gl_FragColor = var_color; |
158 | +} |
159 | |
160 | === added file 'data/shaders/fill_rect.vp' |
161 | --- data/shaders/fill_rect.vp 1970-01-01 00:00:00 +0000 |
162 | +++ data/shaders/fill_rect.vp 2016-02-06 20:55:31 +0000 |
163 | @@ -0,0 +1,12 @@ |
164 | +#version 120 |
165 | + |
166 | +// Attributes. |
167 | +attribute vec3 attr_position; |
168 | +attribute vec4 attr_color; |
169 | + |
170 | +varying vec4 var_color; |
171 | + |
172 | +void main() { |
173 | + var_color = attr_color; |
174 | + gl_Position = vec4(attr_position, 1.); |
175 | +} |
176 | |
177 | === added file 'data/shaders/road.fp' |
178 | --- data/shaders/road.fp 1970-01-01 00:00:00 +0000 |
179 | +++ data/shaders/road.fp 2016-02-06 20:55:31 +0000 |
180 | @@ -0,0 +1,13 @@ |
181 | +#version 120 |
182 | + |
183 | +// Inputs. |
184 | +varying vec2 out_texture_position; |
185 | +varying float out_brightness; |
186 | + |
187 | +uniform sampler2D u_texture; |
188 | + |
189 | +void main() { |
190 | + vec4 color = texture2D(u_texture, out_texture_position); |
191 | + color.rgb *= out_brightness; |
192 | + gl_FragColor = color; |
193 | +} |
194 | |
195 | === added file 'data/shaders/road.vp' |
196 | --- data/shaders/road.vp 1970-01-01 00:00:00 +0000 |
197 | +++ data/shaders/road.vp 2016-02-06 20:55:31 +0000 |
198 | @@ -0,0 +1,18 @@ |
199 | +#version 120 |
200 | + |
201 | +// Attributes. |
202 | +attribute vec2 attr_position; |
203 | +attribute vec2 attr_texture_position; |
204 | +attribute float attr_brightness; |
205 | + |
206 | +uniform float u_z_value; |
207 | + |
208 | +// Outputs. |
209 | +varying vec2 out_texture_position; |
210 | +varying float out_brightness; |
211 | + |
212 | +void main() { |
213 | + out_texture_position = attr_texture_position; |
214 | + out_brightness = attr_brightness; |
215 | + gl_Position = vec4(attr_position, u_z_value, 1.); |
216 | +} |
217 | |
218 | === added file 'data/shaders/terrain.fp' |
219 | --- data/shaders/terrain.fp 1970-01-01 00:00:00 +0000 |
220 | +++ data/shaders/terrain.fp 2016-02-06 20:55:31 +0000 |
221 | @@ -0,0 +1,26 @@ |
222 | +#version 120 |
223 | + |
224 | +uniform sampler2D u_terrain_texture; |
225 | +uniform vec2 u_texture_dimensions; |
226 | + |
227 | +varying float var_brightness; |
228 | +varying vec2 var_texture_position; |
229 | +varying vec2 var_texture_offset; |
230 | + |
231 | +// TODO(sirver): This is a hack to make sure we are sampling inside of the |
232 | +// terrain texture. This is a common problem with OpenGL and texture atlases. |
233 | +#define MARGIN 1e-2 |
234 | + |
235 | +void main() { |
236 | + // The arbitrary multiplication by 0.99 makes sure that we never sample |
237 | + // outside of the texture in the texture atlas - this means non-perfect |
238 | + // pixel mapping of textures to the screen, but we are pretty meh about that |
239 | + // here. |
240 | + vec2 texture_fract = clamp( |
241 | + fract(var_texture_position), |
242 | + vec2(MARGIN, MARGIN), |
243 | + vec2(1. - MARGIN, 1. - MARGIN)); |
244 | + vec4 clr = texture2D(u_terrain_texture, var_texture_offset + u_texture_dimensions * texture_fract); |
245 | + clr.rgb *= var_brightness; |
246 | + gl_FragColor = clr; |
247 | +} |
248 | |
249 | === added file 'data/shaders/terrain.vp' |
250 | --- data/shaders/terrain.vp 1970-01-01 00:00:00 +0000 |
251 | +++ data/shaders/terrain.vp 2016-02-06 20:55:31 +0000 |
252 | @@ -0,0 +1,21 @@ |
253 | +#version 120 |
254 | + |
255 | +// Attributes. |
256 | +attribute float attr_brightness; |
257 | +attribute vec2 attr_position; |
258 | +attribute vec2 attr_texture_offset; |
259 | +attribute vec2 attr_texture_position; |
260 | + |
261 | +uniform float u_z_value; |
262 | + |
263 | +// Output of vertex shader. |
264 | +varying float var_brightness; |
265 | +varying vec2 var_texture_offset; |
266 | +varying vec2 var_texture_position; |
267 | + |
268 | +void main() { |
269 | + var_texture_position = attr_texture_position; |
270 | + var_brightness = attr_brightness; |
271 | + var_texture_offset = attr_texture_offset; |
272 | + gl_Position = vec4(attr_position, u_z_value, 1.); |
273 | +} |
274 | |
275 | === modified file 'src/graphic/CMakeLists.txt' |
276 | --- src/graphic/CMakeLists.txt 2016-01-31 10:57:58 +0000 |
277 | +++ src/graphic/CMakeLists.txt 2016-02-06 20:55:31 +0000 |
278 | @@ -100,6 +100,8 @@ |
279 | base_geometry |
280 | base_log |
281 | base_macros |
282 | + io_fileread |
283 | + io_filesystem |
284 | ) |
285 | |
286 | wl_library(graphic_terrain_programs |
287 | |
288 | === modified file 'src/graphic/gl/blit_program.cc' |
289 | --- src/graphic/gl/blit_program.cc 2016-01-10 11:48:47 +0000 |
290 | +++ src/graphic/gl/blit_program.cc 2016-02-06 20:55:31 +0000 |
291 | @@ -29,61 +29,6 @@ |
292 | |
293 | namespace { |
294 | |
295 | -const char kBlitVertexShader[] = R"( |
296 | -#version 120 |
297 | - |
298 | -// Attributes. |
299 | -attribute vec2 attr_mask_texture_position; |
300 | -attribute vec2 attr_texture_position; |
301 | -attribute vec3 attr_position; |
302 | -attribute vec4 attr_blend; |
303 | -attribute float attr_program_flavor; |
304 | - |
305 | -varying vec2 out_mask_texture_coordinate; |
306 | -varying vec2 out_texture_coordinate; |
307 | -varying vec4 out_blend; |
308 | -varying float out_program_flavor; |
309 | - |
310 | -void main() { |
311 | - out_mask_texture_coordinate = attr_mask_texture_position; |
312 | - out_texture_coordinate = attr_texture_position; |
313 | - out_blend = attr_blend; |
314 | - out_program_flavor = attr_program_flavor; |
315 | - gl_Position = vec4(attr_position, 1.); |
316 | -} |
317 | -)"; |
318 | - |
319 | -const char kBlitFragmentShader[] = R"( |
320 | -#version 120 |
321 | - |
322 | -uniform sampler2D u_texture; |
323 | -uniform sampler2D u_mask; |
324 | - |
325 | -varying vec2 out_mask_texture_coordinate; |
326 | -varying vec2 out_texture_coordinate; |
327 | -varying vec4 out_blend; |
328 | -varying float out_program_flavor; |
329 | - |
330 | -void main() { |
331 | - vec4 texture_color = texture2D(u_texture, out_texture_coordinate); |
332 | - |
333 | - // See http://en.wikipedia.org/wiki/YUV. |
334 | - float luminance = dot(vec3(0.299, 0.587, 0.114), texture_color.rgb); |
335 | - |
336 | - if (out_program_flavor == 0.) { |
337 | - gl_FragColor = vec4(texture_color.rgb, out_blend.a * texture_color.a); |
338 | - } else if (out_program_flavor == 1.) { |
339 | - gl_FragColor = vec4(vec3(luminance) * out_blend.rgb, out_blend.a * texture_color.a); |
340 | - } else { |
341 | - vec4 mask_color = texture2D(u_mask, out_mask_texture_coordinate); |
342 | - float blend_influence = mask_color.r * mask_color.a; |
343 | - gl_FragColor = vec4( |
344 | - mix(texture_color.rgb, out_blend.rgb * luminance, blend_influence), |
345 | - out_blend.a * texture_color.a); |
346 | - } |
347 | -} |
348 | -)"; |
349 | - |
350 | // While drawing we put all draw calls into a buffer, so that we have to |
351 | // transfer the buffer to the GPU only once, even though we might need to do |
352 | // many glDraw* calls. This structure represents the parameters for one glDraw* |
353 | @@ -99,7 +44,7 @@ |
354 | } // namespace |
355 | |
356 | BlitProgram::BlitProgram() { |
357 | - gl_program_.build(kBlitVertexShader, kBlitFragmentShader); |
358 | + gl_program_.build("blit"); |
359 | |
360 | attr_blend_ = glGetAttribLocation(gl_program_.object(), "attr_blend"); |
361 | attr_mask_texture_position_ = glGetAttribLocation(gl_program_.object(), "attr_mask_texture_position"); |
362 | |
363 | === modified file 'src/graphic/gl/dither_program.cc' |
364 | --- src/graphic/gl/dither_program.cc 2016-01-29 08:37:22 +0000 |
365 | +++ src/graphic/gl/dither_program.cc 2016-02-06 20:55:31 +0000 |
366 | @@ -27,66 +27,8 @@ |
367 | #include "graphic/texture.h" |
368 | #include "io/filesystem/layered_filesystem.h" |
369 | |
370 | -namespace { |
371 | - |
372 | -const char kDitherVertexShader[] = R"( |
373 | -#version 120 |
374 | - |
375 | -// Attributes. |
376 | -attribute float attr_brightness; |
377 | -attribute vec2 attr_dither_texture_position; |
378 | -attribute vec2 attr_position; |
379 | -attribute vec2 attr_texture_offset; |
380 | -attribute vec2 attr_texture_position; |
381 | - |
382 | -uniform float u_z_value; |
383 | - |
384 | -// Output of vertex shader. |
385 | -varying float var_brightness; |
386 | -varying vec2 var_dither_texture_position; |
387 | -varying vec2 var_texture_offset; |
388 | -varying vec2 var_texture_position; |
389 | - |
390 | -void main() { |
391 | - var_brightness = attr_brightness; |
392 | - var_dither_texture_position = attr_dither_texture_position; |
393 | - var_texture_offset = attr_texture_offset; |
394 | - var_texture_position = attr_texture_position; |
395 | - gl_Position = vec4(attr_position, u_z_value, 1.); |
396 | -} |
397 | -)"; |
398 | - |
399 | -const char kDitherFragmentShader[] = R"( |
400 | -#version 120 |
401 | - |
402 | -uniform sampler2D u_dither_texture; |
403 | -uniform sampler2D u_terrain_texture; |
404 | -uniform vec2 u_texture_dimensions; |
405 | - |
406 | -varying float var_brightness; |
407 | -varying vec2 var_dither_texture_position; |
408 | -varying vec2 var_texture_position; |
409 | -varying vec2 var_texture_offset; |
410 | - |
411 | -// TODO(sirver): This is a hack to make sure we are sampling inside of the |
412 | -// terrain texture. This is a common problem with OpenGL and texture atlases. |
413 | -#define MARGIN 1e-2 |
414 | - |
415 | -void main() { |
416 | - vec2 texture_fract = clamp( |
417 | - fract(var_texture_position), |
418 | - vec2(MARGIN, MARGIN), |
419 | - vec2(1. - MARGIN, 1. - MARGIN)); |
420 | - vec4 clr = texture2D(u_terrain_texture, var_texture_offset + u_texture_dimensions * texture_fract); |
421 | - gl_FragColor = vec4(clr.rgb * var_brightness, |
422 | - 1. - texture2D(u_dither_texture, var_dither_texture_position).a); |
423 | -} |
424 | -)"; |
425 | - |
426 | -} // namespace |
427 | - |
428 | DitherProgram::DitherProgram() { |
429 | - gl_program_.build(kDitherVertexShader, kDitherFragmentShader); |
430 | + gl_program_.build("dither"); |
431 | |
432 | attr_brightness_ = glGetAttribLocation(gl_program_.object(), "attr_brightness"); |
433 | attr_dither_texture_position_ = glGetAttribLocation(gl_program_.object(), "attr_dither_texture_position"); |
434 | |
435 | === modified file 'src/graphic/gl/draw_line_program.cc' |
436 | --- src/graphic/gl/draw_line_program.cc 2016-01-09 15:27:05 +0000 |
437 | +++ src/graphic/gl/draw_line_program.cc 2016-02-06 20:55:31 +0000 |
438 | @@ -27,31 +27,6 @@ |
439 | |
440 | namespace { |
441 | |
442 | -const char kDrawLineVertexShader[] = R"( |
443 | -#version 120 |
444 | - |
445 | -// Attributes. |
446 | -attribute vec3 attr_position; |
447 | -attribute vec3 attr_color; |
448 | - |
449 | -varying vec3 var_color; |
450 | - |
451 | -void main() { |
452 | - var_color = attr_color; |
453 | - gl_Position = vec4(attr_position, 1.); |
454 | -} |
455 | -)"; |
456 | - |
457 | -const char kDrawLineFragmentShader[] = R"( |
458 | -#version 120 |
459 | - |
460 | -varying vec3 var_color; |
461 | - |
462 | -void main() { |
463 | - gl_FragColor = vec4(var_color.rgb, 1.); |
464 | -} |
465 | -)"; |
466 | - |
467 | struct DrawBatch { |
468 | int offset; |
469 | int count; |
470 | @@ -67,7 +42,7 @@ |
471 | } |
472 | |
473 | DrawLineProgram::DrawLineProgram() { |
474 | - gl_program_.build(kDrawLineVertexShader, kDrawLineFragmentShader); |
475 | + gl_program_.build("draw_line"); |
476 | |
477 | attr_position_ = glGetAttribLocation(gl_program_.object(), "attr_position"); |
478 | attr_color_ = glGetAttribLocation(gl_program_.object(), "attr_color"); |
479 | |
480 | === modified file 'src/graphic/gl/fill_rect_program.cc' |
481 | --- src/graphic/gl/fill_rect_program.cc 2016-01-17 09:55:27 +0000 |
482 | +++ src/graphic/gl/fill_rect_program.cc 2016-02-06 20:55:31 +0000 |
483 | @@ -24,35 +24,6 @@ |
484 | #include "base/log.h" |
485 | #include "base/wexception.h" |
486 | |
487 | -namespace { |
488 | - |
489 | -const char kFillRectVertexShader[] = R"( |
490 | -#version 120 |
491 | - |
492 | -// Attributes. |
493 | -attribute vec3 attr_position; |
494 | -attribute vec4 attr_color; |
495 | - |
496 | -varying vec4 var_color; |
497 | - |
498 | -void main() { |
499 | - var_color = attr_color; |
500 | - gl_Position = vec4(attr_position, 1.); |
501 | -} |
502 | -)"; |
503 | - |
504 | -const char kFillRectFragmentShader[] = R"( |
505 | -#version 120 |
506 | - |
507 | -varying vec4 var_color; |
508 | - |
509 | -void main() { |
510 | - gl_FragColor = var_color; |
511 | -} |
512 | -)"; |
513 | - |
514 | -} // namespace |
515 | - |
516 | // static |
517 | FillRectProgram& FillRectProgram::instance() { |
518 | static FillRectProgram fill_rect_program; |
519 | @@ -60,7 +31,7 @@ |
520 | } |
521 | |
522 | FillRectProgram::FillRectProgram() { |
523 | - gl_program_.build(kFillRectVertexShader, kFillRectFragmentShader); |
524 | + gl_program_.build("fill_rect"); |
525 | |
526 | attr_position_ = glGetAttribLocation(gl_program_.object(), "attr_position"); |
527 | attr_color_ = glGetAttribLocation(gl_program_.object(), "attr_color"); |
528 | |
529 | === modified file 'src/graphic/gl/road_program.cc' |
530 | --- src/graphic/gl/road_program.cc 2016-01-28 05:24:34 +0000 |
531 | +++ src/graphic/gl/road_program.cc 2016-02-06 20:55:31 +0000 |
532 | @@ -31,50 +31,9 @@ |
533 | #include "graphic/texture.h" |
534 | #include "logic/roadtype.h" |
535 | |
536 | -namespace { |
537 | - |
538 | // We target OpenGL 2.1 for the desktop here. |
539 | -const char kRoadVertexShader[] = R"( |
540 | -#version 120 |
541 | - |
542 | -// Attributes. |
543 | -attribute vec2 attr_position; |
544 | -attribute vec2 attr_texture_position; |
545 | -attribute float attr_brightness; |
546 | - |
547 | -uniform float u_z_value; |
548 | - |
549 | -// Outputs. |
550 | -varying vec2 out_texture_position; |
551 | -varying float out_brightness; |
552 | - |
553 | -void main() { |
554 | - out_texture_position = attr_texture_position; |
555 | - out_brightness = attr_brightness; |
556 | - gl_Position = vec4(attr_position, u_z_value, 1.); |
557 | -} |
558 | -)"; |
559 | - |
560 | -const char kRoadFragmentShader[] = R"( |
561 | -#version 120 |
562 | - |
563 | -// Inputs. |
564 | -varying vec2 out_texture_position; |
565 | -varying float out_brightness; |
566 | - |
567 | -uniform sampler2D u_texture; |
568 | - |
569 | -void main() { |
570 | - vec4 color = texture2D(u_texture, out_texture_position); |
571 | - color.rgb *= out_brightness; |
572 | - gl_FragColor = color; |
573 | -} |
574 | -)"; |
575 | - |
576 | -} // namespace |
577 | - |
578 | RoadProgram::RoadProgram() { |
579 | - gl_program_.build(kRoadVertexShader, kRoadFragmentShader); |
580 | + gl_program_.build("road"); |
581 | |
582 | attr_position_ = glGetAttribLocation(gl_program_.object(), "attr_position"); |
583 | attr_texture_position_ = glGetAttribLocation(gl_program_.object(), "attr_texture_position"); |
584 | |
585 | === modified file 'src/graphic/gl/terrain_program.cc' |
586 | --- src/graphic/gl/terrain_program.cc 2016-01-16 15:22:32 +0000 |
587 | +++ src/graphic/gl/terrain_program.cc 2016-02-06 20:55:31 +0000 |
588 | @@ -24,72 +24,13 @@ |
589 | #include "graphic/gl/utils.h" |
590 | #include "graphic/texture.h" |
591 | |
592 | -namespace { |
593 | - |
594 | -using namespace Widelands; |
595 | - |
596 | // QuickRef: |
597 | // http://www.cs.unh.edu/~cs770/docs/glsl-1.20-quickref.pdf |
598 | // Full specification: |
599 | // http://www.opengl.org/registry/doc/GLSLangSpec.Full.1.20.8.pdf |
600 | // We target OpenGL 2.1 for the desktop here. |
601 | -const char kTerrainVertexShader[] = R"( |
602 | -#version 120 |
603 | - |
604 | -// Attributes. |
605 | -attribute float attr_brightness; |
606 | -attribute vec2 attr_position; |
607 | -attribute vec2 attr_texture_offset; |
608 | -attribute vec2 attr_texture_position; |
609 | - |
610 | -uniform float u_z_value; |
611 | - |
612 | -// Output of vertex shader. |
613 | -varying float var_brightness; |
614 | -varying vec2 var_texture_offset; |
615 | -varying vec2 var_texture_position; |
616 | - |
617 | -void main() { |
618 | - var_texture_position = attr_texture_position; |
619 | - var_brightness = attr_brightness; |
620 | - var_texture_offset = attr_texture_offset; |
621 | - gl_Position = vec4(attr_position, u_z_value, 1.); |
622 | -} |
623 | -)"; |
624 | - |
625 | -const char kTerrainFragmentShader[] = R"( |
626 | -#version 120 |
627 | - |
628 | -uniform sampler2D u_terrain_texture; |
629 | -uniform vec2 u_texture_dimensions; |
630 | - |
631 | -varying float var_brightness; |
632 | -varying vec2 var_texture_position; |
633 | -varying vec2 var_texture_offset; |
634 | - |
635 | -// TODO(sirver): This is a hack to make sure we are sampling inside of the |
636 | -// terrain texture. This is a common problem with OpenGL and texture atlases. |
637 | -#define MARGIN 1e-2 |
638 | - |
639 | -void main() { |
640 | - // The arbitrary multiplication by 0.99 makes sure that we never sample |
641 | - // outside of the texture in the texture atlas - this means non-perfect |
642 | - // pixel mapping of textures to the screen, but we are pretty meh about that |
643 | - // here. |
644 | - vec2 texture_fract = clamp( |
645 | - fract(var_texture_position), |
646 | - vec2(MARGIN, MARGIN), |
647 | - vec2(1. - MARGIN, 1. - MARGIN)); |
648 | - vec4 clr = texture2D(u_terrain_texture, var_texture_offset + u_texture_dimensions * texture_fract); |
649 | - clr.rgb *= var_brightness; |
650 | - gl_FragColor = clr; |
651 | -} |
652 | -)"; |
653 | - |
654 | -} // namespace |
655 | - |
656 | TerrainProgram::TerrainProgram() { |
657 | - gl_program_.build(kTerrainVertexShader, kTerrainFragmentShader); |
658 | + gl_program_.build("terrain"); |
659 | |
660 | attr_brightness_ = glGetAttribLocation(gl_program_.object(), "attr_brightness"); |
661 | attr_position_ = glGetAttribLocation(gl_program_.object(), "attr_position"); |
662 | @@ -143,7 +84,7 @@ |
663 | } |
664 | |
665 | void TerrainProgram::draw(uint32_t gametime, |
666 | - const DescriptionMaintainer<TerrainDescription>& terrains, |
667 | + const DescriptionMaintainer<Widelands::TerrainDescription>& terrains, |
668 | const FieldsToDraw& fields_to_draw, |
669 | float z_value) { |
670 | // This method expects that all terrains have the same dimensions and that |
671 | |
672 | === modified file 'src/graphic/gl/utils.cc' |
673 | --- src/graphic/gl/utils.cc 2016-01-24 12:43:26 +0000 |
674 | +++ src/graphic/gl/utils.cc 2016-02-06 20:55:31 +0000 |
675 | @@ -24,6 +24,8 @@ |
676 | |
677 | #include "base/log.h" |
678 | #include "base/wexception.h" |
679 | +#include "io/fileread.h" |
680 | +#include "io/filesystem/layered_filesystem.h" |
681 | |
682 | namespace Gl { |
683 | |
684 | @@ -31,6 +33,16 @@ |
685 | |
686 | constexpr GLenum NONE = static_cast<GLenum>(0); |
687 | |
688 | +// Reads 'filename' from g_fs into a string. |
689 | +std::string read_file(const std::string& filename) { |
690 | + std::string content; |
691 | + FileRead fr; |
692 | + fr.open(*g_fs, filename); |
693 | + content.assign(fr.data(0), fr.get_size()); |
694 | + fr.close(); |
695 | + return content; |
696 | +} |
697 | + |
698 | // Returns a readable string for a GL_*_SHADER 'type' for debug output. |
699 | std::string shader_to_string(GLenum type) { |
700 | if (type == GL_VERTEX_SHADER) { |
701 | @@ -126,13 +138,16 @@ |
702 | } |
703 | } |
704 | |
705 | -void Program::build(const char* vertex_shader_source, const char* fragment_shader_source) { |
706 | +void Program::build(const std::string& program_name) { |
707 | + std::string fragment_shader_source = read_file("shaders/" + program_name + ".fp"); |
708 | + std::string vertex_shader_source = read_file("shaders/" + program_name + ".vp"); |
709 | + |
710 | vertex_shader_.reset(new Shader(GL_VERTEX_SHADER)); |
711 | - vertex_shader_->compile(vertex_shader_source); |
712 | + vertex_shader_->compile(vertex_shader_source.c_str()); |
713 | glAttachShader(program_object_, vertex_shader_->object()); |
714 | |
715 | fragment_shader_.reset(new Shader(GL_FRAGMENT_SHADER)); |
716 | - fragment_shader_->compile(fragment_shader_source); |
717 | + fragment_shader_->compile(fragment_shader_source.c_str()); |
718 | glAttachShader(program_object_, fragment_shader_->object()); |
719 | |
720 | glLinkProgram(program_object_); |
721 | |
722 | === modified file 'src/graphic/gl/utils.h' |
723 | --- src/graphic/gl/utils.h 2016-01-24 12:43:26 +0000 |
724 | +++ src/graphic/gl/utils.h 2016-02-06 20:55:31 +0000 |
725 | @@ -50,9 +50,9 @@ |
726 | return program_object_; |
727 | } |
728 | |
729 | - // Creates and compiles 'vertex_shader_source' and 'fragment_shader_source' |
730 | - // into shader objects. Then links them into the program. |
731 | - void build(const char* vertex_shader_source, const char* fragment_shader_source); |
732 | + // Creates and compiles shader objects based on the corresponding files in data/shaders, |
733 | + // then links them into the program. |
734 | + void build(const std::string& program_name); |
735 | |
736 | private: |
737 | const GLuint program_object_; |
Hi, I am bunnybot (https:/ /github. com/widelands/ bunnybot).
I am keeping the source branch lp:~widelands-dev/widelands/bug-1397500 mirrored to https:/ /github. com/widelands/ widelands/ tree/_widelands _dev_widelands_ bug_1397500
You can give me commands by starting a line with @bunnybot <command>. I understand:
merge: Merges the source branch into the target branch, closing the merge proposal. I will use the proposed commit message if it is set.