Merge lp:~widelands-dev/widelands/remove_software_rendering into lp:widelands
- remove_software_rendering
- Merge into trunk
Proposed by
SirVer
Status: | Merged | ||||||||
---|---|---|---|---|---|---|---|---|---|
Merged at revision: | 7275 | ||||||||
Proposed branch: | lp:~widelands-dev/widelands/remove_software_rendering | ||||||||
Merge into: | lp:widelands | ||||||||
Diff against target: |
3423 lines (+409/-2210) 39 files modified
src/graphic/CMakeLists.txt (+9/-13) src/graphic/gl/game_renderer.cc (+2/-2) src/graphic/gl/road_program.cc (+2/-2) src/graphic/gl/road_program.h (+3/-3) src/graphic/gl/surface.cc (+0/-171) src/graphic/gl/surface.h (+0/-68) src/graphic/gl/surface_screen.cc (+0/-8) src/graphic/gl/surface_screen.h (+2/-4) src/graphic/gl/surface_texture.cc (+7/-15) src/graphic/gl/surface_texture.h (+5/-6) src/graphic/graphic.cc (+53/-112) src/graphic/graphic.h (+1/-7) src/graphic/image_transformations.cc (+1/-9) src/graphic/sdl/game_renderer.cc (+0/-279) src/graphic/sdl/game_renderer.h (+0/-55) src/graphic/sdl/surface.cc (+0/-355) src/graphic/sdl/surface.h (+0/-77) src/graphic/sdl/terrain.cc (+0/-34) src/graphic/sdl/terrain.h (+0/-668) src/graphic/sdl/utils.cc (+0/-30) src/graphic/sdl/utils.h (+0/-29) src/graphic/sdl/vertex.h (+0/-39) src/graphic/sdl_utils.cc (+28/-0) src/graphic/sdl_utils.h (+29/-0) src/graphic/surface.cc (+163/-31) src/graphic/surface.h (+50/-36) src/graphic/text/CMakeLists.txt (+1/-0) src/graphic/text/sdl_ttf_font.cc (+1/-1) src/graphic/text/test/CMakeLists.txt (+1/-0) src/graphic/text/test/render_richtext.cc (+19/-5) src/graphic/texture.cc (+8/-79) src/graphic/texture.h (+9/-17) src/logic/map_info.cc (+4/-16) src/ui_fsmenu/options.cc (+0/-12) src/ui_fsmenu/options.h (+0/-3) src/wlapplication.cc (+8/-14) src/wlapplication.h (+1/-1) src/wlapplication_messages.cc (+1/-2) src/wui/mapview.cc (+1/-7) |
||||||||
To merge this branch: | bzr merge lp:~widelands-dev/widelands/remove_software_rendering | ||||||||
Related bugs: |
|
Reviewer | Review Type | Date Requested | Status |
---|---|---|---|
GunChleoc | Approve | ||
Review via email: mp+242587@code.launchpad.net |
Commit message
- Removes software renderering.
- Moves code from GLSurface into Surface. GLSurface is gone now.
- Changes stand alone richtext renderer to bring up a graphics system so that offscreen rendering works. This makes it unsuitable for being a unit test ran after compilation though.
Description of the change
To post a comment you must log in.
Revision history for this message
SirVer (sirver) : | # |
Preview Diff
[H/L] Next/Prev Comment, [J/K] Next/Prev File, [N/P] Next/Prev Hunk
1 | === modified file 'src/graphic/CMakeLists.txt' |
2 | --- src/graphic/CMakeLists.txt 2014-11-08 14:59:03 +0000 |
3 | +++ src/graphic/CMakeLists.txt 2014-11-23 12:03:00 +0000 |
4 | @@ -36,21 +36,22 @@ |
5 | graphic_surface |
6 | ) |
7 | |
8 | +wl_library(graphic_sdl_utils |
9 | + SRCS |
10 | + sdl_utils.h |
11 | + sdl_utils.cc |
12 | + USES_SDL2 |
13 | +) |
14 | + |
15 | wl_library(graphic_surface |
16 | SRCS |
17 | compositemode.h |
18 | - gl/surface.cc |
19 | - gl/surface.h |
20 | gl/surface_screen.cc |
21 | gl/surface_screen.h |
22 | gl/surface_texture.cc |
23 | gl/surface_texture.h |
24 | gl/utils.cc |
25 | gl/utils.h |
26 | - sdl/surface.cc |
27 | - sdl/surface.h |
28 | - sdl/utils.cc |
29 | - sdl/utils.h |
30 | surface.cc |
31 | surface.h |
32 | surface_cache.cc |
33 | @@ -58,12 +59,13 @@ |
34 | USES_OPENGL |
35 | USES_SDL2 |
36 | DEPENDS |
37 | - base_macros |
38 | base_exceptions |
39 | base_geometry |
40 | base_log |
41 | + base_macros |
42 | graphic |
43 | graphic_color |
44 | + graphic_sdl_utils |
45 | ) |
46 | |
47 | wl_library(graphic |
48 | @@ -114,11 +116,6 @@ |
49 | rendertarget.h |
50 | richtext.cc |
51 | richtext.h |
52 | - sdl/game_renderer.cc |
53 | - sdl/game_renderer.h |
54 | - sdl/terrain.cc |
55 | - sdl/terrain.h |
56 | - sdl/vertex.h |
57 | text_parser.cc |
58 | text_parser.h |
59 | texture.cc |
60 | @@ -150,7 +147,6 @@ |
61 | io_stream |
62 | logic |
63 | profile |
64 | - random |
65 | scripting |
66 | sound |
67 | ui_basic |
68 | |
69 | === modified file 'src/graphic/gl/game_renderer.cc' |
70 | --- src/graphic/gl/game_renderer.cc 2014-11-22 11:59:34 +0000 |
71 | +++ src/graphic/gl/game_renderer.cc 2014-11-23 12:03:00 +0000 |
72 | @@ -24,10 +24,10 @@ |
73 | #include "graphic/gl/dither_program.h" |
74 | #include "graphic/gl/fields_to_draw.h" |
75 | #include "graphic/gl/road_program.h" |
76 | -#include "graphic/gl/surface.h" |
77 | #include "graphic/gl/terrain_program.h" |
78 | #include "graphic/graphic.h" |
79 | #include "graphic/rendertarget.h" |
80 | +#include "graphic/surface.h" |
81 | #include "graphic/texture.h" |
82 | #include "logic/editor_game_base.h" |
83 | #include "logic/player.h" |
84 | @@ -133,7 +133,7 @@ |
85 | road_program_.reset(new RoadProgram()); |
86 | } |
87 | |
88 | - GLSurface* surface = dynamic_cast<GLSurface*>(m_dst->get_surface()); |
89 | + Surface* surface = m_dst->get_surface(); |
90 | if (!surface) |
91 | return; |
92 | |
93 | |
94 | === modified file 'src/graphic/gl/road_program.cc' |
95 | --- src/graphic/gl/road_program.cc 2014-11-09 14:20:59 +0000 |
96 | +++ src/graphic/gl/road_program.cc 2014-11-23 12:03:00 +0000 |
97 | @@ -87,7 +87,7 @@ |
98 | u_busy_road_texture_ = glGetUniformLocation(gl_program_.object(), "u_busy_road_texture"); |
99 | } |
100 | |
101 | -void RoadProgram::add_road(const GLSurface& surface, |
102 | +void RoadProgram::add_road(const Surface& surface, |
103 | const FieldsToDraw::Field& start, |
104 | const FieldsToDraw::Field& end, |
105 | const Widelands::RoadType road_type) { |
106 | @@ -146,7 +146,7 @@ |
107 | vertices_.emplace_back(p4); |
108 | } |
109 | |
110 | -void RoadProgram::draw(const GLSurface& surface, const FieldsToDraw& fields_to_draw) { |
111 | +void RoadProgram::draw(const Surface& surface, const FieldsToDraw& fields_to_draw) { |
112 | vertices_.clear(); |
113 | |
114 | for (size_t current_index = 0; current_index < fields_to_draw.size(); ++current_index) { |
115 | |
116 | === modified file 'src/graphic/gl/road_program.h' |
117 | --- src/graphic/gl/road_program.h 2014-11-08 18:06:17 +0000 |
118 | +++ src/graphic/gl/road_program.h 2014-11-23 12:03:00 +0000 |
119 | @@ -24,8 +24,8 @@ |
120 | |
121 | #include "base/macros.h" |
122 | #include "graphic/gl/fields_to_draw.h" |
123 | -#include "graphic/gl/surface.h" |
124 | #include "graphic/gl/utils.h" |
125 | +#include "graphic/surface.h" |
126 | #include "logic/roadtype.h" |
127 | |
128 | class RoadProgram { |
129 | @@ -35,7 +35,7 @@ |
130 | |
131 | // Draws the roads. The 'surface' is needed to convert from pixel space to |
132 | // GL space. |
133 | - void draw(const GLSurface& surface, const FieldsToDraw& fields_to_draw); |
134 | + void draw(const Surface& surface, const FieldsToDraw& fields_to_draw); |
135 | |
136 | private: |
137 | struct PerVertexData { |
138 | @@ -55,7 +55,7 @@ |
139 | |
140 | // Adds a road from 'start' to 'end' to be rendered in this frame using the |
141 | // correct texture for 'road_type'. |
142 | - void add_road(const GLSurface& surface, |
143 | + void add_road(const Surface& surface, |
144 | const FieldsToDraw::Field& start, |
145 | const FieldsToDraw::Field& end, |
146 | const Widelands::RoadType road_type); |
147 | |
148 | === removed file 'src/graphic/gl/surface.cc' |
149 | --- src/graphic/gl/surface.cc 2014-11-22 11:59:34 +0000 |
150 | +++ src/graphic/gl/surface.cc 1970-01-01 00:00:00 +0000 |
151 | @@ -1,171 +0,0 @@ |
152 | -/* |
153 | - * Copyright (C) 2006-2012 by the Widelands Development Team |
154 | - * |
155 | - * This program is free software; you can redistribute it and/or |
156 | - * modify it under the terms of the GNU General Public License |
157 | - * as published by the Free Software Foundation; either version 2 |
158 | - * of the License, or (at your option) any later version. |
159 | - * |
160 | - * This program is distributed in the hope that it will be useful, |
161 | - * but WITHOUT ANY WARRANTY; without even the implied warranty of |
162 | - * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the |
163 | - * GNU General Public License for more details. |
164 | - * |
165 | - * You should have received a copy of the GNU General Public License |
166 | - * along with this program; if not, write to the Free Software |
167 | - * Foundation, Inc., 675 Mass Ave, Cambridge, MA 02139, USA. |
168 | - * |
169 | - */ |
170 | - |
171 | -#include "graphic/gl/surface.h" |
172 | - |
173 | -#include <cassert> |
174 | -#include <cmath> |
175 | -#include <cstdlib> |
176 | - |
177 | -#include "base/macros.h" |
178 | -#include "graphic/gl/blit_program.h" |
179 | -#include "graphic/gl/draw_line_program.h" |
180 | -#include "graphic/gl/draw_rect_program.h" |
181 | -#include "graphic/gl/fill_rect_program.h" |
182 | -#include "graphic/gl/surface_texture.h" |
183 | -#include "graphic/graphic.h" |
184 | - |
185 | -uint16_t GLSurface::width() const { |
186 | - return m_w; |
187 | -} |
188 | - |
189 | -uint16_t GLSurface::height() const { |
190 | - return m_h; |
191 | -} |
192 | - |
193 | -uint8_t * GLSurface::get_pixels() const |
194 | -{ |
195 | - return m_pixels.get(); |
196 | -} |
197 | - |
198 | -uint32_t GLSurface::get_pixel(uint16_t x, uint16_t y) { |
199 | - assert(m_pixels); |
200 | - assert(x < m_w); |
201 | - assert(y < m_h); |
202 | - |
203 | - uint8_t * data = &m_pixels[y * get_pitch() + 4 * x]; |
204 | - return *(reinterpret_cast<uint32_t *>(data)); |
205 | -} |
206 | - |
207 | -void GLSurface::set_pixel(uint16_t x, uint16_t y, uint32_t clr) { |
208 | - assert(m_pixels); |
209 | - assert(x < m_w); |
210 | - assert(y < m_h); |
211 | - |
212 | - uint8_t * data = &m_pixels[y * get_pitch() + 4 * x]; |
213 | - *(reinterpret_cast<uint32_t *>(data)) = clr; |
214 | -} |
215 | - |
216 | -FloatRect GLSurface::to_opengl(const Rect& rect, ConversionMode mode) { |
217 | - const float delta = mode == ConversionMode::kExact ? 0. : 0.5; |
218 | - float x1 = rect.x + delta; |
219 | - float y1 = rect.y + delta; |
220 | - pixel_to_gl(&x1, &y1); |
221 | - float x2 = rect.x + rect.w - delta; |
222 | - float y2 = rect.y + rect.h - delta; |
223 | - pixel_to_gl(&x2, &y2); |
224 | - |
225 | - return FloatRect(x1, y1, x2 - x1, y2 - y1); |
226 | -} |
227 | - |
228 | -void GLSurface::draw_rect(const Rect& rc, const RGBColor& clr) |
229 | -{ |
230 | - glViewport(0, 0, width(), height()); |
231 | - DrawRectProgram::instance().draw(to_opengl(rc, ConversionMode::kMidPoint), clr); |
232 | -} |
233 | - |
234 | -/** |
235 | - * Draws a filled rectangle |
236 | - */ |
237 | -void GLSurface::fill_rect(const Rect& rc, const RGBAColor& clr) { |
238 | - glViewport(0, 0, width(), height()); |
239 | - |
240 | - glBlendFunc(GL_ONE, GL_ZERO); |
241 | - |
242 | - FillRectProgram::instance().draw(to_opengl(rc, ConversionMode::kExact), clr); |
243 | - |
244 | - glBlendFunc(GL_SRC_ALPHA, GL_ONE_MINUS_SRC_ALPHA); |
245 | -} |
246 | - |
247 | -/** |
248 | - * Change the brightness of the given rectangle |
249 | - */ |
250 | -void GLSurface::brighten_rect(const Rect& rc, const int32_t factor) |
251 | -{ |
252 | - if (!factor) |
253 | - return; |
254 | - |
255 | - glViewport(0, 0, width(), height()); |
256 | - |
257 | - // The simple trick here is to fill the rect, but using a different glBlendFunc that will sum |
258 | - // src and target (or subtract them if factor is negative). |
259 | - if (factor < 0) { |
260 | - glBlendEquation(GL_FUNC_REVERSE_SUBTRACT); |
261 | - } |
262 | - |
263 | - glBlendFunc(GL_ONE, GL_ONE); |
264 | - |
265 | - const int delta = std::abs(factor); |
266 | - FillRectProgram::instance().draw( |
267 | - to_opengl(rc, ConversionMode::kExact), RGBAColor(delta, delta, delta, 0)); |
268 | - |
269 | - if (factor < 0) { |
270 | - glBlendEquation(GL_FUNC_ADD); |
271 | - } |
272 | - |
273 | - glBlendFunc(GL_SRC_ALPHA, GL_ONE_MINUS_SRC_ALPHA); |
274 | -} |
275 | - |
276 | -void GLSurface::draw_line |
277 | - (int32_t x1, int32_t y1, int32_t x2, int32_t y2, const RGBColor& color, uint8_t gwidth) |
278 | -{ |
279 | - glViewport(0, 0, width(), height()); |
280 | - |
281 | - float gl_x1 = x1 + 0.5; |
282 | - float gl_y1 = y1 + 0.5; |
283 | - pixel_to_gl(&gl_x1, &gl_y1); |
284 | - |
285 | - float gl_x2 = x2 + 0.5; |
286 | - float gl_y2 = y2 + 0.5; |
287 | - pixel_to_gl(&gl_x2, &gl_y2); |
288 | - |
289 | - DrawLineProgram::instance().draw(gl_x1, gl_y1, gl_x2, gl_y2, color, gwidth); |
290 | -} |
291 | - |
292 | -// Converts the pixel (x, y) in a texture to a gl coordinate in [0, 1]. |
293 | -inline void pixel_to_gl_texture(const int width, const int height, float* x, float* y) { |
294 | - *x = (*x / width); |
295 | - *y = (*y / height); |
296 | -} |
297 | - |
298 | -void GLSurface::blit |
299 | - (const Point& dst, const Surface* image, const Rect& srcrc, Composite cm) |
300 | -{ |
301 | - glViewport(0, 0, width(), height()); |
302 | - |
303 | - // Source Rectangle. |
304 | - const GLSurfaceTexture* const texture = static_cast<const GLSurfaceTexture*>(image); |
305 | - FloatRect gl_src_rect; |
306 | - { |
307 | - float x1 = srcrc.x; |
308 | - float y1 = srcrc.y; |
309 | - pixel_to_gl_texture(texture->width(), texture->height(), &x1, &y1); |
310 | - float x2 = srcrc.x + srcrc.w; |
311 | - float y2 = srcrc.y + srcrc.h; |
312 | - pixel_to_gl_texture(texture->width(), texture->height(), &x2, &y2); |
313 | - gl_src_rect.x = x1; |
314 | - gl_src_rect.y = y1; |
315 | - gl_src_rect.w = x2 - x1; |
316 | - gl_src_rect.h = y2 - y1; |
317 | - } |
318 | - |
319 | - const FloatRect gl_dst_rect = to_opengl(Rect(dst.x, dst.y, srcrc.w, srcrc.h), ConversionMode::kExact); |
320 | - |
321 | - BlitProgram::instance().draw(gl_dst_rect, gl_src_rect, texture->get_gl_texture(), cm); |
322 | -} |
323 | |
324 | === removed file 'src/graphic/gl/surface.h' |
325 | --- src/graphic/gl/surface.h 2014-11-08 18:06:17 +0000 |
326 | +++ src/graphic/gl/surface.h 1970-01-01 00:00:00 +0000 |
327 | @@ -1,68 +0,0 @@ |
328 | -/* |
329 | - * Copyright (C) 2006-2012 by the Widelands Development Team |
330 | - * |
331 | - * This program is free software; you can redistribute it and/or |
332 | - * modify it under the terms of the GNU General Public License |
333 | - * as published by the Free Software Foundation; either version 2 |
334 | - * of the License, or (at your option) any later version. |
335 | - * |
336 | - * This program is distributed in the hope that it will be useful, |
337 | - * but WITHOUT ANY WARRANTY; without even the implied warranty of |
338 | - * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the |
339 | - * GNU General Public License for more details. |
340 | - * |
341 | - * You should have received a copy of the GNU General Public License |
342 | - * along with this program; if not, write to the Free Software |
343 | - * Foundation, Inc., 675 Mass Ave, Cambridge, MA 02139, USA. |
344 | - * |
345 | - */ |
346 | - |
347 | -#ifndef WL_GRAPHIC_GL_SURFACE_H |
348 | -#define WL_GRAPHIC_GL_SURFACE_H |
349 | - |
350 | -#include <memory> |
351 | - |
352 | -#include "graphic/gl/system_headers.h" |
353 | -#include "graphic/surface.h" |
354 | - |
355 | -class GLSurface : public Surface { |
356 | -public: |
357 | - virtual ~GLSurface() {} |
358 | - |
359 | - /// Interface implementations |
360 | - uint16_t width() const override; |
361 | - uint16_t height() const override; |
362 | - uint8_t * get_pixels() const override; |
363 | - void set_pixel(uint16_t x, uint16_t y, uint32_t clr) override; |
364 | - uint32_t get_pixel(uint16_t x, uint16_t y) override; |
365 | - void blit(const Point&, const Surface*, const Rect& srcrc, Composite cm) override; |
366 | - void fill_rect(const Rect&, const RGBAColor&) override; |
367 | - void draw_rect(const Rect&, const RGBColor&) override; |
368 | - void brighten_rect(const Rect&, int32_t factor) override; |
369 | - virtual void draw_line |
370 | - (int32_t x1, int32_t y1, int32_t x2, int32_t y2, const RGBColor&, uint8_t width) override; |
371 | - |
372 | - // Converts the given pixel into an OpenGl point. This might need some |
373 | - // flipping of axis, depending if you want to render on the screen or not. |
374 | - virtual void pixel_to_gl(float* x, float* y) const = 0; |
375 | - |
376 | -protected: |
377 | - // Convert the 'rect' in pixel space into opengl space. |
378 | - enum class ConversionMode { |
379 | - // Convert the rect as given. |
380 | - kExact, |
381 | - |
382 | - // Convert the rect so that the borders are in the center |
383 | - // of the pixels. |
384 | - kMidPoint, |
385 | - }; |
386 | - FloatRect to_opengl(const Rect& rect, ConversionMode mode); |
387 | - |
388 | - /// Logical width and height of the surface |
389 | - uint16_t m_w, m_h; |
390 | - |
391 | - /// Pixel data, while the texture is locked |
392 | - std::unique_ptr<uint8_t[]> m_pixels; |
393 | -}; |
394 | - |
395 | -#endif // end of include guard: WL_GRAPHIC_GL_SURFACE_H |
396 | |
397 | === modified file 'src/graphic/gl/surface_screen.cc' |
398 | --- src/graphic/gl/surface_screen.cc 2014-11-08 18:06:17 +0000 |
399 | +++ src/graphic/gl/surface_screen.cc 2014-11-23 12:03:00 +0000 |
400 | @@ -52,10 +52,6 @@ |
401 | } |
402 | } |
403 | |
404 | -const SDL_PixelFormat & GLSurfaceScreen::format() const { |
405 | - return Gl::gl_rgba_format(); |
406 | -} |
407 | - |
408 | void GLSurfaceScreen::lock(Surface::LockMode mode) |
409 | { |
410 | assert(!m_pixels); |
411 | @@ -85,7 +81,3 @@ |
412 | |
413 | m_pixels.reset(nullptr); |
414 | } |
415 | - |
416 | -uint16_t GLSurfaceScreen::get_pitch() const { |
417 | - return 4 * m_w; |
418 | -} |
419 | |
420 | === modified file 'src/graphic/gl/surface_screen.h' |
421 | --- src/graphic/gl/surface_screen.h 2014-11-08 18:06:17 +0000 |
422 | +++ src/graphic/gl/surface_screen.h 2014-11-23 12:03:00 +0000 |
423 | @@ -19,12 +19,12 @@ |
424 | #ifndef WL_GRAPHIC_GL_SURFACE_SCREEN_H |
425 | #define WL_GRAPHIC_GL_SURFACE_SCREEN_H |
426 | |
427 | -#include "graphic/gl/surface.h" |
428 | +#include "graphic/surface.h" |
429 | |
430 | /** |
431 | * This surface represents the screen in OpenGL mode. |
432 | */ |
433 | -class GLSurfaceScreen : public GLSurface { |
434 | +class GLSurfaceScreen : public Surface { |
435 | public: |
436 | GLSurfaceScreen(uint16_t w, uint16_t h); |
437 | virtual ~GLSurfaceScreen() {} |
438 | @@ -32,8 +32,6 @@ |
439 | /// Interface implementations |
440 | void lock(LockMode) override; |
441 | void unlock(UnlockMode) override; |
442 | - uint16_t get_pitch() const override; |
443 | - const SDL_PixelFormat & format() const override; |
444 | |
445 | private: |
446 | void pixel_to_gl(float* x, float* y) const override; |
447 | |
448 | === modified file 'src/graphic/gl/surface_texture.cc' |
449 | --- src/graphic/gl/surface_texture.cc 2014-11-08 18:06:17 +0000 |
450 | +++ src/graphic/gl/surface_texture.cc 2014-11-23 12:03:00 +0000 |
451 | @@ -24,10 +24,10 @@ |
452 | #include "base/macros.h" |
453 | #include "base/wexception.h" |
454 | #include "graphic/gl/blit_program.h" |
455 | -#include "graphic/gl/surface.h" |
456 | #include "graphic/gl/utils.h" |
457 | #include "graphic/graphic.h" |
458 | -#include "graphic/sdl/utils.h" |
459 | +#include "graphic/sdl_utils.h" |
460 | +#include "graphic/surface.h" |
461 | |
462 | namespace { |
463 | |
464 | @@ -160,10 +160,6 @@ |
465 | glTexParameteri(GL_TEXTURE_2D, GL_TEXTURE_MAG_FILTER, GL_LINEAR); |
466 | } |
467 | |
468 | -const SDL_PixelFormat & GLSurfaceTexture::format() const { |
469 | - return Gl::gl_rgba_format(); |
470 | -} |
471 | - |
472 | void GLSurfaceTexture::lock(LockMode mode) { |
473 | if (m_w <= 0 || m_h <= 0) { |
474 | return; |
475 | @@ -194,17 +190,13 @@ |
476 | m_pixels.reset(nullptr); |
477 | } |
478 | |
479 | -uint16_t GLSurfaceTexture::get_pitch() const { |
480 | - return 4 * m_w; |
481 | -} |
482 | - |
483 | void GLSurfaceTexture::draw_rect(const Rect& rectangle, const RGBColor& clr) |
484 | { |
485 | if (m_w <= 0 || m_h <= 0) { |
486 | return; |
487 | } |
488 | setup_gl(m_texture); |
489 | - GLSurface::draw_rect(rectangle, clr); |
490 | + Surface::draw_rect(rectangle, clr); |
491 | reset_gl(); |
492 | } |
493 | |
494 | @@ -219,7 +211,7 @@ |
495 | } |
496 | |
497 | setup_gl(m_texture); |
498 | - GLSurface::fill_rect(rectangle, clr); |
499 | + Surface::fill_rect(rectangle, clr); |
500 | reset_gl(); |
501 | } |
502 | |
503 | @@ -233,7 +225,7 @@ |
504 | } |
505 | |
506 | setup_gl(m_texture); |
507 | - GLSurface::brighten_rect(rectangle, factor); |
508 | + Surface::brighten_rect(rectangle, factor); |
509 | reset_gl(); |
510 | } |
511 | |
512 | @@ -245,7 +237,7 @@ |
513 | } |
514 | |
515 | setup_gl(m_texture); |
516 | - GLSurface::draw_line(x1, y1, x2, y2, color, gwidth); |
517 | + Surface::draw_line(x1, y1, x2, y2, color, gwidth); |
518 | reset_gl(); |
519 | } |
520 | |
521 | @@ -257,6 +249,6 @@ |
522 | } |
523 | |
524 | setup_gl(m_texture); |
525 | - GLSurface::blit(dst, src, srcrc, cm); |
526 | + Surface::blit(dst, src, srcrc, cm); |
527 | reset_gl(); |
528 | } |
529 | |
530 | === modified file 'src/graphic/gl/surface_texture.h' |
531 | --- src/graphic/gl/surface_texture.h 2014-11-08 18:06:17 +0000 |
532 | +++ src/graphic/gl/surface_texture.h 2014-11-23 12:03:00 +0000 |
533 | @@ -19,11 +19,12 @@ |
534 | #ifndef WL_GRAPHIC_GL_SURFACE_TEXTURE_H |
535 | #define WL_GRAPHIC_GL_SURFACE_TEXTURE_H |
536 | |
537 | -#include "graphic/gl/surface.h" |
538 | +#include "graphic/gl/system_headers.h" |
539 | +#include "graphic/surface.h" |
540 | |
541 | struct SDL_Surface; |
542 | |
543 | -class GLSurfaceTexture : public GLSurface { |
544 | +class GLSurfaceTexture : public Surface { |
545 | public: |
546 | GLSurfaceTexture(SDL_Surface * surface, bool intensity = false); |
547 | GLSurfaceTexture(int w, int h); |
548 | @@ -34,13 +35,11 @@ |
549 | //@{ |
550 | void lock(LockMode) override; |
551 | void unlock(UnlockMode) override; |
552 | - uint16_t get_pitch() const override; |
553 | - const SDL_PixelFormat & format() const override; |
554 | |
555 | // Note: the following functions are reimplemented here though they |
556 | - // basically only call the functions in GLSurface wrapped in calls to |
557 | + // basically only call the functions in Surface wrapped in calls to |
558 | // setup_gl(), reset_gl(). The same functionality can be achieved by making |
559 | - // those two functions virtual and calling them in GLSurface. However, |
560 | + // those two functions virtual and calling them in Surface. However, |
561 | // especially for blit which is called very often and mostly on the screen, |
562 | // this costs two virtual function calls which makes a notable difference in |
563 | // profiles. |
564 | |
565 | === modified file 'src/graphic/graphic.cc' |
566 | --- src/graphic/graphic.cc 2014-11-22 10:18:20 +0000 |
567 | +++ src/graphic/graphic.cc 2014-11-23 12:03:00 +0000 |
568 | @@ -40,7 +40,6 @@ |
569 | #include "graphic/image_io.h" |
570 | #include "graphic/image_transformations.h" |
571 | #include "graphic/rendertarget.h" |
572 | -#include "graphic/sdl/surface.h" |
573 | #include "graphic/surface_cache.h" |
574 | #include "graphic/texture.h" |
575 | #include "io/fileread.h" |
576 | @@ -52,7 +51,6 @@ |
577 | using namespace std; |
578 | |
579 | Graphic * g_gr; |
580 | -bool g_opengl; |
581 | |
582 | namespace { |
583 | |
584 | @@ -91,115 +89,81 @@ |
585 | ImageTransformations::initialize(); |
586 | |
587 | m_sdl_window = nullptr; |
588 | - m_sdl_screen = nullptr; |
589 | - m_sdl_renderer = nullptr; |
590 | - m_sdl_texture = nullptr; |
591 | m_glcontext = nullptr; |
592 | } |
593 | |
594 | -void Graphic::initialize(int32_t w, int32_t h, bool fullscreen, bool opengl) { |
595 | +void Graphic::initialize(int32_t w, int32_t h, bool fullscreen) { |
596 | cleanup(); |
597 | |
598 | - // Set video mode using SDL. First collect the flags |
599 | - int32_t flags = 0; |
600 | - g_opengl = false; |
601 | - |
602 | - if (opengl) { |
603 | - log("Graphics: Trying opengl\n"); |
604 | - |
605 | - SDL_GL_SetAttribute(SDL_GL_DOUBLEBUFFER, 1); |
606 | - |
607 | - // Request an OpenGL 2 context. |
608 | - SDL_GL_SetAttribute(SDL_GL_CONTEXT_MAJOR_VERSION, 2); |
609 | - SDL_GL_SetAttribute(SDL_GL_CONTEXT_MINOR_VERSION, 1); |
610 | - |
611 | - flags |= SDL_WINDOW_OPENGL; |
612 | - } |
613 | - |
614 | + // Request an OpenGL 2 context with double buffering. |
615 | + SDL_GL_SetAttribute(SDL_GL_DOUBLEBUFFER, 1); |
616 | + SDL_GL_SetAttribute(SDL_GL_CONTEXT_MAJOR_VERSION, 2); |
617 | + SDL_GL_SetAttribute(SDL_GL_CONTEXT_MINOR_VERSION, 1); |
618 | + |
619 | + int32_t flags = SDL_WINDOW_OPENGL; |
620 | if (fullscreen) { |
621 | flags |= SDL_WINDOW_FULLSCREEN; |
622 | log("Graphics: Trying FULLSCREEN\n"); |
623 | } |
624 | |
625 | log("Graphics: Try to set Videomode %ux%u\n", w, h); |
626 | - // Here we actually set the video mode |
627 | - m_sdl_window = SDL_CreateWindow("Widelands Window", |
628 | - SDL_WINDOWPOS_UNDEFINED, SDL_WINDOWPOS_UNDEFINED, w, h, flags); |
629 | - |
630 | + m_sdl_window = SDL_CreateWindow( |
631 | + "Widelands Window", SDL_WINDOWPOS_UNDEFINED, SDL_WINDOWPOS_UNDEFINED, w, h, flags); |
632 | if (!m_sdl_window) { |
633 | - log |
634 | - ("Graphics: Could not set videomode: %s, trying minimum graphics settings\n", |
635 | - SDL_GetError()); |
636 | + log("Graphics: Could not set Videomode: %s, trying minimum graphics settings\n", |
637 | + SDL_GetError()); |
638 | flags &= ~SDL_WINDOW_FULLSCREEN; |
639 | m_sdl_window = SDL_CreateWindow("Widelands Window", |
640 | SDL_WINDOWPOS_UNDEFINED, SDL_WINDOWPOS_UNDEFINED, |
641 | kFallbackGraphicsWidth, kFallbackGraphicsHeight, flags); |
642 | m_fallback_settings_in_effect = true; |
643 | if (!m_sdl_window) { |
644 | - throw wexception |
645 | - ("Graphics: could not set video mode: %s", SDL_GetError()); |
646 | + throw wexception("Graphics: could not set video mode: %s", SDL_GetError()); |
647 | } |
648 | } |
649 | |
650 | SDL_SetWindowTitle(m_sdl_window, ("Widelands " + build_id() + '(' + build_type() + ')').c_str()); |
651 | - |
652 | - if (opengl) { |
653 | - m_glcontext = SDL_GL_CreateContext(m_sdl_window); |
654 | - if (m_glcontext) { |
655 | - SDL_GL_MakeCurrent(m_sdl_window, m_glcontext); |
656 | - } |
657 | - |
658 | - // We now really have a working opengl screen... |
659 | - g_opengl = true; |
660 | - |
661 | - // See graphic/gl/system_headers.h for an explanation of the |
662 | - // next line. |
663 | - glewExperimental = GL_TRUE; |
664 | - GLenum err = glewInit(); |
665 | - if (err != GLEW_OK) { |
666 | - log("glewInit returns %i\nYour OpenGL installation must be __very__ broken. %s\n", |
667 | - err, glewGetErrorString(err)); |
668 | - throw wexception("glewInit returns %i: Broken OpenGL installation.", err); |
669 | - } |
670 | - |
671 | - log("Graphics: OpenGL: Version \"%s\"\n", |
672 | - reinterpret_cast<const char*>(glGetString(GL_VERSION))); |
673 | - |
674 | - GLboolean glBool; |
675 | - glGetBooleanv(GL_DOUBLEBUFFER, &glBool); |
676 | - log("Graphics: OpenGL: Double buffering %s\n", (glBool == GL_TRUE) ? "enabled" : "disabled"); |
677 | - |
678 | - GLint glInt; |
679 | - glGetIntegerv(GL_MAX_TEXTURE_SIZE, &glInt); |
680 | - log("Graphics: OpenGL: Max texture size: %u\n", glInt); |
681 | - |
682 | - SDL_GL_SetSwapInterval(1); |
683 | - SDL_GL_SwapWindow(m_sdl_window); |
684 | - |
685 | - glDrawBuffer(GL_BACK); |
686 | - |
687 | - glDisable(GL_DEPTH_TEST); |
688 | - glEnable(GL_TEXTURE_2D); |
689 | - glEnable(GL_BLEND); |
690 | - glBlendFunc(GL_SRC_ALPHA, GL_ONE_MINUS_SRC_ALPHA); |
691 | - |
692 | - glClear(GL_COLOR_BUFFER_BIT); |
693 | - |
694 | - screen_.reset(new GLSurfaceScreen(w, h)); |
695 | - } else { |
696 | - m_sdl_renderer = SDL_CreateRenderer(m_sdl_window, -1, 0); |
697 | - uint32_t rmask, gmask, bmask, amask; |
698 | - int bpp; |
699 | - SDL_PixelFormatEnumToMasks(SDL_PIXELFORMAT_ARGB8888, &bpp, &rmask, &gmask, &bmask, &amask); |
700 | - m_sdl_screen = SDL_CreateRGBSurface(0, w, h, bpp, rmask, gmask, bmask, amask); |
701 | - m_sdl_texture = SDL_CreateTexture(m_sdl_renderer, |
702 | - SDL_PIXELFORMAT_ARGB8888, SDL_TEXTUREACCESS_STREAMING, |
703 | - w, h); |
704 | - screen_.reset(new SDLSurface(m_sdl_screen, false)); |
705 | - } |
706 | - |
707 | set_icon(m_sdl_window); |
708 | |
709 | + m_glcontext = SDL_GL_CreateContext(m_sdl_window); |
710 | + SDL_GL_MakeCurrent(m_sdl_window, m_glcontext); |
711 | + |
712 | + // See graphic/gl/system_headers.h for an explanation of the |
713 | + // next line. |
714 | + glewExperimental = GL_TRUE; |
715 | + GLenum err = glewInit(); |
716 | + if (err != GLEW_OK) { |
717 | + log("glewInit returns %i\nYour OpenGL installation must be __very__ broken. %s\n", |
718 | + err, glewGetErrorString(err)); |
719 | + throw wexception("glewInit returns %i: Broken OpenGL installation.", err); |
720 | + } |
721 | + |
722 | + log("Graphics: OpenGL: Version \"%s\"\n", |
723 | + reinterpret_cast<const char*>(glGetString(GL_VERSION))); |
724 | + |
725 | + GLboolean glBool; |
726 | + glGetBooleanv(GL_DOUBLEBUFFER, &glBool); |
727 | + log("Graphics: OpenGL: Double buffering %s\n", (glBool == GL_TRUE) ? "enabled" : "disabled"); |
728 | + |
729 | + GLint glInt; |
730 | + glGetIntegerv(GL_MAX_TEXTURE_SIZE, &glInt); |
731 | + log("Graphics: OpenGL: Max texture size: %u\n", glInt); |
732 | + |
733 | + SDL_GL_SetSwapInterval(1); |
734 | + |
735 | + glDrawBuffer(GL_BACK); |
736 | + |
737 | + glDisable(GL_DEPTH_TEST); |
738 | + glEnable(GL_TEXTURE_2D); |
739 | + glEnable(GL_BLEND); |
740 | + glBlendFunc(GL_SRC_ALPHA, GL_ONE_MINUS_SRC_ALPHA); |
741 | + |
742 | + glClear(GL_COLOR_BUFFER_BIT); |
743 | + |
744 | + SDL_GL_SwapWindow(m_sdl_window); |
745 | + |
746 | + screen_.reset(new GLSurfaceScreen(w, h)); |
747 | + |
748 | /* Information about the video capabilities. */ |
749 | { |
750 | SDL_DisplayMode disp_mode; |
751 | @@ -216,8 +180,6 @@ |
752 | assert(SDL_BYTESPERPIXEL(disp_mode.format) == 4); |
753 | } |
754 | |
755 | - Surface::display_format_is_now_defined(); |
756 | - |
757 | m_rendertarget.reset(new RenderTarget(screen_.get())); |
758 | |
759 | pic_road_normal_.reset(load_image("world/pics/roadt_normal.png")); |
760 | @@ -236,14 +198,6 @@ |
761 | if (UI::g_fh) |
762 | UI::g_fh->flush(); |
763 | |
764 | - if (m_sdl_texture) { |
765 | - SDL_DestroyTexture(m_sdl_texture); |
766 | - m_sdl_texture = nullptr; |
767 | - } |
768 | - if (m_sdl_screen) { |
769 | - SDL_FreeSurface(m_sdl_screen); |
770 | - m_sdl_screen = nullptr; |
771 | - } |
772 | if (m_sdl_window) { |
773 | SDL_DestroyWindow(m_sdl_window); |
774 | m_sdl_window = nullptr; |
775 | @@ -329,16 +283,7 @@ |
776 | */ |
777 | void Graphic::refresh() |
778 | { |
779 | - if (g_opengl) { |
780 | - SDL_GL_SwapWindow(m_sdl_window); |
781 | - m_update = false; |
782 | - return; |
783 | - } |
784 | - |
785 | - SDL_UpdateTexture(m_sdl_texture, nullptr, m_sdl_screen->pixels, m_sdl_screen->pitch); |
786 | - SDL_RenderClear(m_sdl_renderer); |
787 | - SDL_RenderCopy(m_sdl_renderer, m_sdl_texture, nullptr, nullptr); |
788 | - SDL_RenderPresent(m_sdl_renderer); |
789 | + SDL_GL_SwapWindow(m_sdl_window); |
790 | m_update = false; |
791 | } |
792 | |
793 | @@ -355,11 +300,7 @@ |
794 | |
795 | uint32_t Graphic::new_maptexture(const std::vector<std::string>& texture_files, const uint32_t frametime) |
796 | { |
797 | - SDL_PixelFormat* pixel_fmt = SDL_AllocFormat(SDL_PIXELFORMAT_ARGB8888); |
798 | - m_maptextures.emplace_back(new Texture(texture_files, frametime, *pixel_fmt)); |
799 | - if (pixel_fmt) { |
800 | - SDL_FreeFormat(pixel_fmt); |
801 | - } |
802 | + m_maptextures.emplace_back(new Texture(texture_files, frametime)); |
803 | return m_maptextures.size(); // ID 1 is at m_maptextures[0] |
804 | } |
805 | |
806 | |
807 | === modified file 'src/graphic/graphic.h' |
808 | --- src/graphic/graphic.h 2014-11-13 06:45:36 +0000 |
809 | +++ src/graphic/graphic.h 2014-11-23 12:03:00 +0000 |
810 | @@ -35,7 +35,6 @@ |
811 | class RenderTarget; |
812 | class Surface; |
813 | class SurfaceCache; |
814 | -struct SDL_Surface; |
815 | class StreamWrite; |
816 | struct Texture; |
817 | |
818 | @@ -51,8 +50,7 @@ |
819 | ~Graphic(); |
820 | |
821 | // Initialize or reinitialize the graphics system. Throws on error. |
822 | - void initialize |
823 | - (int32_t w, int32_t h, bool fullscreen, bool opengl); |
824 | + void initialize(int32_t w, int32_t h, bool fullscreen); |
825 | |
826 | int32_t get_xres(); |
827 | int32_t get_yres(); |
828 | @@ -94,10 +92,7 @@ |
829 | /// This saves a copy of the screen SDL_Surface. This is needed for |
830 | /// opengl rendering as the SurfaceOpenGL does not use it. It allows |
831 | /// manipulation the screen context. |
832 | - SDL_Surface * m_sdl_screen; |
833 | - SDL_Renderer * m_sdl_renderer; |
834 | SDL_Window * m_sdl_window; |
835 | - SDL_Texture * m_sdl_texture; |
836 | SDL_GLContext m_glcontext; |
837 | /// A RenderTarget for screen_. This is initialized during init() |
838 | std::unique_ptr<RenderTarget> m_rendertarget; |
839 | @@ -120,6 +115,5 @@ |
840 | }; |
841 | |
842 | extern Graphic * g_gr; |
843 | -extern bool g_opengl; |
844 | |
845 | #endif // end of include guard: WL_GRAPHIC_GRAPHIC_H |
846 | |
847 | === modified file 'src/graphic/image_transformations.cc' |
848 | --- src/graphic/image_transformations.cc 2014-11-02 20:15:01 +0000 |
849 | +++ src/graphic/image_transformations.cc 2014-11-23 12:03:00 +0000 |
850 | @@ -28,7 +28,6 @@ |
851 | #include "base/macros.h" |
852 | #include "graphic/color.h" |
853 | #include "graphic/graphic.h" |
854 | -#include "graphic/sdl/surface.h" |
855 | #include "graphic/surface.h" |
856 | #include "graphic/surface_cache.h" |
857 | |
858 | @@ -87,15 +86,8 @@ |
859 | Rect srcrect = Rect(Point(0, 0), src->width(), src->height()); |
860 | |
861 | // Second step: get source material |
862 | - SDL_Surface * srcsdl = nullptr; |
863 | + SDL_Surface * srcsdl = extract_sdl_surface(*src, srcrect); |
864 | bool free_source = true; |
865 | - if (upcast(const SDLSurface, sdlsrcsurf, src)) { |
866 | - srcsdl = sdlsrcsurf->get_sdl_surface(); |
867 | - free_source = false; |
868 | - } else { |
869 | - // This is in OpenGL |
870 | - srcsdl = extract_sdl_surface(*src, srcrect); |
871 | - } |
872 | |
873 | // If we actually shrink a surface, ballpark the zoom so that the shrinking |
874 | // effect is weakened. |
875 | |
876 | === removed directory 'src/graphic/sdl' |
877 | === removed file 'src/graphic/sdl/game_renderer.cc' |
878 | --- src/graphic/sdl/game_renderer.cc 2014-09-27 18:53:55 +0000 |
879 | +++ src/graphic/sdl/game_renderer.cc 1970-01-01 00:00:00 +0000 |
880 | @@ -1,279 +0,0 @@ |
881 | -/* |
882 | - * Copyright (C) 2010-2013 by the Widelands Development Team |
883 | - * |
884 | - * This program is free software; you can redistribute it and/or |
885 | - * modify it under the terms of the GNU General Public License |
886 | - * as published by the Free Software Foundation; either version 2 |
887 | - * of the License, or (at your option) any later version. |
888 | - * |
889 | - * This program is distributed in the hope that it will be useful, |
890 | - * but WITHOUT ANY WARRANTY; without even the implied warranty of |
891 | - * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the |
892 | - * GNU General Public License for more details. |
893 | - * |
894 | - * You should have received a copy of the GNU General Public License |
895 | - * along with this program; if not, write to the Free Software |
896 | - * Foundation, Inc., 51 Franklin Street, Fifth Floor, Boston, MA 02110-1301, USA. |
897 | - * |
898 | - */ |
899 | - |
900 | -#include "graphic/sdl/game_renderer.h" |
901 | - |
902 | -#include "graphic/rendertarget.h" |
903 | -#include "graphic/sdl/terrain.h" |
904 | -#include "logic/field.h" |
905 | -#include "logic/map.h" |
906 | -#include "logic/player.h" |
907 | -#include "logic/world/terrain_description.h" |
908 | -#include "logic/world/world.h" |
909 | -#include "wui/overlay_manager.h" |
910 | - |
911 | - |
912 | -using namespace Widelands; |
913 | - |
914 | -///This is used by rendermap to calculate the brightness of the terrain. |
915 | -inline static int8_t node_brightness |
916 | - (Widelands::Time const gametime, |
917 | - Widelands::Time const last_seen, |
918 | - Widelands::Vision const vision, |
919 | - int8_t result) |
920 | -{ |
921 | - if (vision == 0) |
922 | - result = -128; |
923 | - else if (vision == 1) { |
924 | - assert(last_seen <= gametime); |
925 | - Widelands::Duration const time_ago = gametime - last_seen; |
926 | - result = |
927 | - static_cast<int16_t> |
928 | - (((static_cast<int16_t>(result) + 128) >> 1) |
929 | - * |
930 | - (1.0 + (time_ago < 45000 ? expf(-8.46126929e-5 * time_ago) : 0))) |
931 | - - |
932 | - 128; |
933 | - } |
934 | - |
935 | - return result; |
936 | -} |
937 | - |
938 | - |
939 | -void SdlGameRenderer::draw() |
940 | -{ |
941 | - draw_terrain(); |
942 | - draw_objects(); |
943 | -} |
944 | - |
945 | -void SdlGameRenderer::draw_terrain() |
946 | -{ |
947 | - if (m_player && !m_player->see_all()) |
948 | - m_dst->get_surface()->fill_rect(m_dst->get_rect(), RGBAColor(0, 0, 0, 255)); |
949 | - |
950 | - const Map & map = m_egbase->map(); |
951 | - const World & world = m_egbase->world(); |
952 | - uint32_t const mapwidth = map.get_width(); |
953 | - |
954 | -#define get_terrain_texture(ter) \ |
955 | - (g_gr->get_maptexture_data(world.terrain_descr((ter)).get_texture())) |
956 | - |
957 | - int32_t dx = m_maxfx - m_minfx + 1; |
958 | - int32_t dy = m_maxfy - m_minfy + 1; |
959 | - int32_t linear_fy = m_minfy; |
960 | - int32_t b_posy = linear_fy * TRIANGLE_HEIGHT + m_dst_offset.y; |
961 | - |
962 | - Widelands::Time const gametime = m_egbase->get_gametime(); |
963 | - |
964 | - while (dy--) { |
965 | - const int32_t posy = b_posy; |
966 | - b_posy += TRIANGLE_HEIGHT; |
967 | - const int32_t linear_fx = m_minfx; |
968 | - FCoords r(Coords(linear_fx, linear_fy)); |
969 | - FCoords br(Coords(linear_fx + (linear_fy & 1) - 1, linear_fy + 1)); |
970 | - int32_t r_posx = |
971 | - r.x * TRIANGLE_WIDTH |
972 | - + |
973 | - (linear_fy & 1) * (TRIANGLE_WIDTH / 2) |
974 | - + |
975 | - m_dst_offset.x; |
976 | - int32_t br_posx = r_posx - TRIANGLE_WIDTH / 2; |
977 | - |
978 | - // Calculate safe (bounded) field coordinates and get field pointers |
979 | - map.normalize_coords(r); |
980 | - map.normalize_coords(br); |
981 | - MapIndex r_index = Map::get_index (r, mapwidth); |
982 | - r.field = &map[r_index]; |
983 | - MapIndex br_index = Map::get_index(br, mapwidth); |
984 | - br.field = &map[br_index]; |
985 | - FCoords tr; |
986 | - map.get_tln(r, &tr); |
987 | - MapIndex tr_index = tr.field - &map[0]; |
988 | - |
989 | - const Texture * f_r_texture; |
990 | - |
991 | - if (m_player && !m_player->see_all()) { |
992 | - const Player::Field & l_pf = m_player->fields()[Map::get_index(map.l_n(r), mapwidth)]; |
993 | - f_r_texture = get_terrain_texture(l_pf.terrains.r); |
994 | - } else { |
995 | - f_r_texture = get_terrain_texture(map.l_n(r).field->get_terrains().r); |
996 | - } |
997 | - |
998 | - uint32_t count = dx; |
999 | - |
1000 | - while (count--) { |
1001 | - const FCoords bl = br; |
1002 | - const FCoords f = r; |
1003 | - const int32_t f_posx = r_posx; |
1004 | - const int32_t bl_posx = br_posx; |
1005 | - MapIndex f_index = r_index; |
1006 | - MapIndex bl_index = br_index; |
1007 | - move_r(mapwidth, tr, tr_index); |
1008 | - move_r(mapwidth, r, r_index); |
1009 | - move_r(mapwidth, br, br_index); |
1010 | - r_posx += TRIANGLE_WIDTH; |
1011 | - br_posx += TRIANGLE_WIDTH; |
1012 | - |
1013 | - const Texture * l_r_texture = f_r_texture; |
1014 | - const Texture * f_d_texture; |
1015 | - const Texture * tr_d_texture; |
1016 | - uint8_t roads; |
1017 | - int8_t f_brightness; |
1018 | - int8_t r_brightness; |
1019 | - int8_t bl_brightness; |
1020 | - int8_t br_brightness; |
1021 | - |
1022 | - if (m_player && !m_player->see_all()) { |
1023 | - const Player::Field & f_pf = m_player->fields()[f_index]; |
1024 | - const Player::Field & r_pf = m_player->fields()[r_index]; |
1025 | - const Player::Field & bl_pf = m_player->fields()[bl_index]; |
1026 | - const Player::Field & br_pf = m_player->fields()[br_index]; |
1027 | - const Player::Field & tr_pf = m_player->fields()[tr_index]; |
1028 | - |
1029 | - f_r_texture = get_terrain_texture(f_pf.terrains.r); |
1030 | - f_d_texture = get_terrain_texture(f_pf.terrains.d); |
1031 | - tr_d_texture = get_terrain_texture(tr_pf.terrains.d); |
1032 | - |
1033 | - roads = f_pf.roads; |
1034 | - |
1035 | - f_brightness = node_brightness |
1036 | - (gametime, f_pf.time_node_last_unseen, |
1037 | - f_pf.vision, f.field->get_brightness()); |
1038 | - r_brightness = node_brightness |
1039 | - (gametime, r_pf.time_node_last_unseen, |
1040 | - r_pf.vision, r.field->get_brightness()); |
1041 | - bl_brightness = node_brightness |
1042 | - (gametime, bl_pf.time_node_last_unseen, |
1043 | - bl_pf.vision, bl.field->get_brightness()); |
1044 | - br_brightness = node_brightness |
1045 | - (gametime, br_pf.time_node_last_unseen, |
1046 | - br_pf.vision, br.field->get_brightness()); |
1047 | - } else { |
1048 | - f_r_texture = get_terrain_texture(f.field->get_terrains().r); |
1049 | - f_d_texture = get_terrain_texture(f.field->get_terrains().d); |
1050 | - tr_d_texture = get_terrain_texture(tr.field->get_terrains().d); |
1051 | - |
1052 | - roads = f.field->get_roads(); |
1053 | - |
1054 | - f_brightness = f.field->get_brightness(); |
1055 | - r_brightness = r.field->get_brightness(); |
1056 | - bl_brightness = bl.field->get_brightness(); |
1057 | - br_brightness = br.field->get_brightness(); |
1058 | - } |
1059 | - roads |= map.overlay_manager().get_road_overlay(f); |
1060 | - |
1061 | - Vertex f_vert |
1062 | - (f_posx, posy - f.field->get_height() * HEIGHT_FACTOR, |
1063 | - f_brightness, 0, 0); |
1064 | - Vertex r_vert |
1065 | - (r_posx, posy - r.field->get_height() * HEIGHT_FACTOR, |
1066 | - r_brightness, TRIANGLE_WIDTH, 0); |
1067 | - Vertex bl_vert |
1068 | - (bl_posx, b_posy - bl.field->get_height() * HEIGHT_FACTOR, |
1069 | - bl_brightness, 0, 64); |
1070 | - Vertex br_vert |
1071 | - (br_posx, b_posy - br.field->get_height() * HEIGHT_FACTOR, |
1072 | - br_brightness, TRIANGLE_WIDTH, 64); |
1073 | - |
1074 | - if (linear_fy & 1) { |
1075 | - f_vert.tx += TRIANGLE_WIDTH / 2; |
1076 | - r_vert.tx += TRIANGLE_WIDTH / 2; |
1077 | - } else { |
1078 | - f_vert.tx += TRIANGLE_WIDTH; |
1079 | - r_vert.tx += TRIANGLE_WIDTH; |
1080 | - bl_vert.tx += TRIANGLE_WIDTH / 2; |
1081 | - br_vert.tx += TRIANGLE_WIDTH / 2; |
1082 | - } |
1083 | - |
1084 | - draw_field // Render ground |
1085 | - (*m_dst, |
1086 | - f_vert, r_vert, bl_vert, br_vert, |
1087 | - roads, |
1088 | - *tr_d_texture, *l_r_texture, *f_d_texture, *f_r_texture); |
1089 | - } |
1090 | - |
1091 | - ++linear_fy; |
1092 | - } |
1093 | - |
1094 | -#undef get_terrain_texture |
1095 | -} |
1096 | - |
1097 | - |
1098 | -/** |
1099 | - * Draw ground textures and roads for the given parallelogram (two triangles) |
1100 | - * into the bitmap. |
1101 | - * |
1102 | - * Vertices: |
1103 | - * - f_vert vertex of the field |
1104 | - * - r_vert vertex right of the field |
1105 | - * - bl_vert vertex bottom left of the field |
1106 | - * - br_vert vertex bottom right of the field |
1107 | - * |
1108 | - * Textures: |
1109 | - * - f_r_texture Terrain of the triangle right of the field |
1110 | - * - f_d_texture Terrain of the triangle under of the field |
1111 | - * - tr_d_texture Terrain of the triangle top of the right triangle ?? |
1112 | - * - l_r_texture Terrain of the triangle left of the down triangle ?? |
1113 | - * |
1114 | - * (tr_d) |
1115 | - * |
1116 | - * (f) *------* (r) |
1117 | - * / \ r / |
1118 | - * (l_r) / \ / |
1119 | - * / d \/ |
1120 | - * (bl) *------* (br) |
1121 | - */ |
1122 | -void SdlGameRenderer::draw_field |
1123 | - (RenderTarget & dst, |
1124 | - const Vertex & f_vert, |
1125 | - const Vertex & r_vert, |
1126 | - const Vertex & bl_vert, |
1127 | - const Vertex & br_vert, |
1128 | - uint8_t roads, |
1129 | - const Texture & tr_d_texture, |
1130 | - const Texture & l_r_texture, |
1131 | - const Texture & f_d_texture, |
1132 | - const Texture & f_r_texture) |
1133 | -{ |
1134 | - upcast(SDLSurface, sdlsurf, dst.get_surface()); |
1135 | - if (sdlsurf) |
1136 | - { |
1137 | - sdlsurf->set_subwin(dst.get_rect()); |
1138 | - switch (sdlsurf->format().BytesPerPixel) { |
1139 | - case 2: |
1140 | - draw_field_int<uint16_t> |
1141 | - (*sdlsurf, |
1142 | - f_vert, r_vert, bl_vert, br_vert, |
1143 | - roads, |
1144 | - tr_d_texture, l_r_texture, f_d_texture, f_r_texture); |
1145 | - break; |
1146 | - case 4: |
1147 | - draw_field_int<uint32_t> |
1148 | - (*sdlsurf, |
1149 | - f_vert, r_vert, bl_vert, br_vert, |
1150 | - roads, |
1151 | - tr_d_texture, l_r_texture, f_d_texture, f_r_texture); |
1152 | - break; |
1153 | - default: |
1154 | - assert(false); |
1155 | - break; |
1156 | - } |
1157 | - sdlsurf->unset_subwin(); |
1158 | - } |
1159 | -} |
1160 | |
1161 | === removed file 'src/graphic/sdl/game_renderer.h' |
1162 | --- src/graphic/sdl/game_renderer.h 2014-09-27 18:53:55 +0000 |
1163 | +++ src/graphic/sdl/game_renderer.h 1970-01-01 00:00:00 +0000 |
1164 | @@ -1,55 +0,0 @@ |
1165 | -/* |
1166 | - * Copyright (C) 2010-2013 by the Widelands Development Team |
1167 | - * |
1168 | - * This program is free software; you can redistribute it and/or |
1169 | - * modify it under the terms of the GNU General Public License |
1170 | - * as published by the Free Software Foundation; either version 2 |
1171 | - * of the License, or (at your option) any later version. |
1172 | - * |
1173 | - * This program is distributed in the hope that it will be useful, |
1174 | - * but WITHOUT ANY WARRANTY; without even the implied warranty of |
1175 | - * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the |
1176 | - * GNU General Public License for more details. |
1177 | - * |
1178 | - * You should have received a copy of the GNU General Public License |
1179 | - * along with this program; if not, write to the Free Software |
1180 | - * Foundation, Inc., 51 Franklin Street, Fifth Floor, Boston, MA 02110-1301, USA. |
1181 | - * |
1182 | - */ |
1183 | - |
1184 | -#ifndef WL_GRAPHIC_SDL_GAME_RENDERER_H |
1185 | -#define WL_GRAPHIC_SDL_GAME_RENDERER_H |
1186 | - |
1187 | -#include "graphic/game_renderer.h" |
1188 | - |
1189 | -struct Texture; |
1190 | -struct Vertex; |
1191 | - |
1192 | -/** |
1193 | - * Software-rendering implementation of @ref GameRenderer. |
1194 | - */ |
1195 | -class SdlGameRenderer : public GameRenderer { |
1196 | -protected: |
1197 | - void draw() override; |
1198 | - |
1199 | -private: |
1200 | - void draw_terrain(); |
1201 | - |
1202 | - /** |
1203 | - * Helper function to draw two terrain triangles. This is called from the |
1204 | - * rendermap() functions. |
1205 | - */ |
1206 | - void draw_field |
1207 | - (RenderTarget & dst, |
1208 | - const Vertex & f_vert, |
1209 | - const Vertex & r_vert, |
1210 | - const Vertex & bl_vert, |
1211 | - const Vertex & br_vert, |
1212 | - uint8_t roads, |
1213 | - const Texture & tr_d_texture, |
1214 | - const Texture & l_r_texture, |
1215 | - const Texture & f_d_texture, |
1216 | - const Texture & f_r_texture); |
1217 | -}; |
1218 | - |
1219 | -#endif // end of include guard: WL_GRAPHIC_SDL_GAME_RENDERER_H |
1220 | |
1221 | === removed file 'src/graphic/sdl/surface.cc' |
1222 | --- src/graphic/sdl/surface.cc 2014-11-02 20:31:40 +0000 |
1223 | +++ src/graphic/sdl/surface.cc 1970-01-01 00:00:00 +0000 |
1224 | @@ -1,355 +0,0 @@ |
1225 | -/* |
1226 | - * Copyright (C) 2002-2004, 2007-2013 by the Widelands Development Team |
1227 | - * |
1228 | - * This program is free software; you can redistribute it and/or |
1229 | - * modify it under the terms of the GNU General Public License |
1230 | - * as published by the Free Software Foundation; either version 2 |
1231 | - * of the License, or (at your option) any later version. |
1232 | - * |
1233 | - * This program is distributed in the hope that it will be useful, |
1234 | - * but WITHOUT ANY WARRANTY; without even the implied warranty of |
1235 | - * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the |
1236 | - * GNU General Public License for more details. |
1237 | - * |
1238 | - * You should have received a copy of the GNU General Public License |
1239 | - * along with this program; if not, write to the Free Software |
1240 | - * Foundation, Inc., 51 Franklin Street, Fifth Floor, Boston, MA 02110-1301, USA. |
1241 | - * |
1242 | - */ |
1243 | - |
1244 | -#include "graphic/sdl/surface.h" |
1245 | - |
1246 | -#include <cassert> |
1247 | - |
1248 | -#include <SDL.h> |
1249 | - |
1250 | -SDLSurface::SDLSurface(SDL_Surface* surface, bool free_surface_on_delete) : |
1251 | - m_surface(surface), |
1252 | - m_offsx(0), m_offsy(0), |
1253 | - m_w(surface->w), m_h(surface->h), |
1254 | - m_free_surface_on_delete(free_surface_on_delete) |
1255 | -{} |
1256 | - |
1257 | -SDLSurface::~SDLSurface() { |
1258 | - assert(m_surface); |
1259 | - |
1260 | - if (m_free_surface_on_delete) |
1261 | - SDL_FreeSurface(m_surface); |
1262 | -} |
1263 | - |
1264 | -const SDL_PixelFormat & SDLSurface::format() const { |
1265 | - assert(m_surface); |
1266 | - return *m_surface->format; |
1267 | -} |
1268 | - |
1269 | -uint8_t * SDLSurface::get_pixels() const { |
1270 | - assert(m_surface); |
1271 | - |
1272 | - return |
1273 | - static_cast<uint8_t *>(m_surface->pixels) |
1274 | - + |
1275 | - m_offsy * m_surface->pitch |
1276 | - + |
1277 | - m_offsx * m_surface->format->BytesPerPixel; |
1278 | -} |
1279 | - |
1280 | -void SDLSurface::lock(LockMode) { |
1281 | - if (SDL_MUSTLOCK(m_surface)) |
1282 | - SDL_LockSurface(m_surface); |
1283 | -} |
1284 | - |
1285 | -void SDLSurface::unlock(UnlockMode) { |
1286 | - if (SDL_MUSTLOCK(m_surface)) |
1287 | - SDL_UnlockSurface(m_surface); |
1288 | -} |
1289 | - |
1290 | -uint32_t SDLSurface::get_pixel(uint16_t x, uint16_t y) { |
1291 | - x += m_offsx; |
1292 | - y += m_offsy; |
1293 | - |
1294 | - assert(x < width()); |
1295 | - assert(y < height()); |
1296 | - assert(m_surface); |
1297 | - |
1298 | - // Locking not needed: reading only |
1299 | - const uint8_t bytes_per_pixel = m_surface->format->BytesPerPixel; |
1300 | - uint8_t * const pix = |
1301 | - static_cast<uint8_t *>(m_surface->pixels) + |
1302 | - y * m_surface->pitch + x * bytes_per_pixel; |
1303 | - |
1304 | - switch (bytes_per_pixel) { |
1305 | - case 1: |
1306 | - return *pix; // Maybe needed for save_png. |
1307 | - case 2: |
1308 | - return *reinterpret_cast<const uint16_t *>(pix); |
1309 | - case 3: //Needed for save_png. |
1310 | - // We can not dereference a pointer to a size 4 object in this case |
1311 | - // since that would casue a read beyond the end of the block pointed to |
1312 | - // by m_surface. Furthermore it would not be properly aligned to a 4 |
1313 | - // byte boundary. |
1314 | - // |
1315 | - // Suppose that the image is 2 * 2 pixels. Then m_surface points to a |
1316 | - // block of size 2 * 2 * 3 = 12. The values for the last pixel are at |
1317 | - // m_surface[9], m_surface[10] and m_surface[11]. But m_surface[12] is |
1318 | - // beyond the end of the block, so we can not read 4 bytes starting at |
1319 | - // m_surface[9] (even if unaligned access is allowed). |
1320 | - // |
1321 | - // Therefore we read the 3 bytes separately and get the result by |
1322 | - // shifting the values. It is alignment safe. |
1323 | - return pix[0] << 0x00 | pix[1] << 0x08 | pix[2] << 0x10; |
1324 | - case 4: |
1325 | - return *reinterpret_cast<const uint32_t *>(pix); |
1326 | - default: |
1327 | - assert(false); |
1328 | - } |
1329 | - |
1330 | - return 0; // Should never be here |
1331 | -} |
1332 | - |
1333 | -void SDLSurface::set_pixel(uint16_t x, uint16_t y, const uint32_t clr) { |
1334 | - x += m_offsx; |
1335 | - y += m_offsy; |
1336 | - |
1337 | - if (x >= width() || y >= height()) |
1338 | - return; |
1339 | - assert(m_surface); |
1340 | - |
1341 | - if (SDL_MUSTLOCK(m_surface)) |
1342 | - SDL_LockSurface(m_surface); |
1343 | - |
1344 | - const uint8_t bytes_per_pixel = m_surface->format->BytesPerPixel; |
1345 | - uint8_t * const pix = |
1346 | - static_cast<uint8_t *>(m_surface->pixels) + |
1347 | - y * m_surface->pitch + x * bytes_per_pixel; |
1348 | - switch (bytes_per_pixel) { |
1349 | - case 2: *reinterpret_cast<uint16_t *>(pix) = static_cast<uint16_t>(clr); break; |
1350 | - case 4: *reinterpret_cast<uint32_t *>(pix) = clr; break; |
1351 | - default: break; |
1352 | - }; |
1353 | - |
1354 | - if (SDL_MUSTLOCK(m_surface)) |
1355 | - SDL_UnlockSurface(m_surface); |
1356 | -} |
1357 | - |
1358 | -void SDLSurface::set_subwin(const Rect& r) { |
1359 | - m_offsx = r.x; |
1360 | - m_offsy = r.y; |
1361 | - m_w = r.w; |
1362 | - m_h = r.h; |
1363 | -} |
1364 | - |
1365 | -void SDLSurface::unset_subwin() { |
1366 | - m_offsx = 0; |
1367 | - m_offsy = 0; |
1368 | - m_w = m_surface->w; |
1369 | - m_h = m_surface->h; |
1370 | -} |
1371 | - |
1372 | -/* |
1373 | -=============== |
1374 | -Draws the outline of a rectangle |
1375 | -=============== |
1376 | -*/ |
1377 | -void SDLSurface::draw_rect(const Rect& rc, const RGBColor& clr) { |
1378 | - assert(m_surface); |
1379 | - assert(rc.x >= 0); |
1380 | - assert(rc.y >= 0); |
1381 | - |
1382 | - const uint32_t color = clr.map(format()); |
1383 | - |
1384 | - const Point bl = rc.bottom_right() - Point(1, 1); |
1385 | - |
1386 | - for (int32_t x = rc.x + 1; x < bl.x; ++x) { |
1387 | - set_pixel(x, rc.y, color); |
1388 | - set_pixel(x, bl.y, color); |
1389 | - } |
1390 | - for (int32_t y = rc.y; y <= bl.y; ++y) { |
1391 | - set_pixel(rc.x, y, color); |
1392 | - set_pixel(bl.x, y, color); |
1393 | - } |
1394 | -} |
1395 | - |
1396 | - |
1397 | -/* |
1398 | -=============== |
1399 | -Draws a filled rectangle |
1400 | -=============== |
1401 | -*/ |
1402 | -void SDLSurface::fill_rect(const Rect& rc, const RGBAColor& clr) { |
1403 | - assert(m_surface); |
1404 | - assert(rc.x >= 0); |
1405 | - assert(rc.y >= 0); |
1406 | - |
1407 | - const uint32_t color = clr.map(format()); |
1408 | - |
1409 | - SDL_Rect r = { |
1410 | - static_cast<int16_t>(rc.x), static_cast<int16_t>(rc.y), |
1411 | - static_cast<uint16_t>(rc.w), static_cast<uint16_t>(rc.h) |
1412 | - }; |
1413 | - SDL_FillRect(m_surface, &r, color); |
1414 | -} |
1415 | - |
1416 | - |
1417 | -/* |
1418 | -=============== |
1419 | -Change the brightness of the given rectangle |
1420 | -This function is slow as hell. |
1421 | - |
1422 | -* This function is a possible point to optimize on |
1423 | - slow system. It takes a lot of cpu time atm and is |
1424 | - not needed. It is used by the ui_basic stuff to |
1425 | - highlight things. |
1426 | -=============== |
1427 | -*/ |
1428 | -void SDLSurface::brighten_rect(const Rect& rc, const int32_t factor) { |
1429 | - if (!factor) |
1430 | - return; |
1431 | - assert(rc.x >= 0); |
1432 | - assert(rc.y >= 0); |
1433 | - assert(rc.w >= 1); |
1434 | - assert(rc.h >= 1); |
1435 | - |
1436 | - const Point bl = rc.bottom_right(); |
1437 | - |
1438 | - lock(Surface::Lock_Normal); |
1439 | - |
1440 | - if (m_surface->format->BytesPerPixel == 4) |
1441 | - { |
1442 | - for (int32_t y = rc.y; y < bl.y; ++y) |
1443 | - for (int32_t x = rc.x; x < bl.x; ++x) |
1444 | - { |
1445 | - |
1446 | - uint8_t * const pix = |
1447 | - static_cast<uint8_t *>(m_surface->pixels) + |
1448 | - (y + m_offsy) * m_surface->pitch + (x + m_offsx) * 4; |
1449 | - |
1450 | - uint32_t const clr = *reinterpret_cast<const uint32_t *>(pix); |
1451 | - uint8_t gr, gg, gb; |
1452 | - SDL_GetRGB(clr, m_surface->format, &gr, &gg, &gb); |
1453 | - int16_t r = gr + factor; |
1454 | - int16_t g = gg + factor; |
1455 | - int16_t b = gb + factor; |
1456 | - |
1457 | - if (b & 0xFF00) |
1458 | - b = ~b >> 24; |
1459 | - if (g & 0xFF00) |
1460 | - g = ~g >> 24; |
1461 | - if (r & 0xFF00) |
1462 | - r = ~r >> 24; |
1463 | - |
1464 | - *reinterpret_cast<uint32_t *>(pix) = |
1465 | - SDL_MapRGB(m_surface->format, r, g, b); |
1466 | - } |
1467 | - } else if (m_surface->format->BytesPerPixel == 2) { |
1468 | - for (int32_t y = rc.y; y < bl.y; ++y) |
1469 | - for (int32_t x = rc.x; x < bl.x; ++x) |
1470 | - { |
1471 | - uint8_t * const pix = |
1472 | - static_cast<uint8_t *>(m_surface->pixels) + |
1473 | - (y + m_offsy) * m_surface->pitch + (x + m_offsx) * 2; |
1474 | - |
1475 | - uint32_t const clr = *reinterpret_cast<const uint16_t *>(pix); |
1476 | - uint8_t gr, gg, gb; |
1477 | - SDL_GetRGB(clr, m_surface->format, &gr, &gg, &gb); |
1478 | - int16_t r = gr + factor; |
1479 | - int16_t g = gg + factor; |
1480 | - int16_t b = gb + factor; |
1481 | - |
1482 | - if (b & 0xFF00) |
1483 | - b = ~b >> 24; |
1484 | - if (g & 0xFF00) |
1485 | - g = ~g >> 24; |
1486 | - if (r & 0xFF00) |
1487 | - r = ~r >> 24; |
1488 | - |
1489 | - *reinterpret_cast<uint16_t *>(pix) = |
1490 | - SDL_MapRGB(m_surface->format, r, g, b); |
1491 | - } |
1492 | - } |
1493 | - unlock(Surface::Unlock_Update); |
1494 | -} |
1495 | - |
1496 | -/** |
1497 | -* This functions draws a (not horizontal or vertical) |
1498 | -* line in the target, using Bresenham's algorithm |
1499 | -* |
1500 | -* This function could be faster by using direct pixel |
1501 | -* access instead of the set_pixel() function |
1502 | -*/ |
1503 | -void SDLSurface::draw_line |
1504 | - (int32_t x1, int32_t y1, int32_t x2, int32_t y2, const RGBColor& color, uint8_t gwidth) |
1505 | -{ |
1506 | - int32_t dx = x2 - x1; /* the horizontal distance of the line */ |
1507 | - int32_t dy = y2 - y1; /* the vertical distance of the line */ |
1508 | - const uint32_t dxabs = abs(dx); |
1509 | - const uint32_t dyabs = abs(dy); |
1510 | - int32_t sdx = dx < 0 ? -1 : 1; |
1511 | - int32_t sdy = dy < 0 ? -1 : 1; |
1512 | - uint32_t x = dyabs / 2; |
1513 | - uint32_t y = dxabs / 2; |
1514 | - Point p(x1, y1); |
1515 | - |
1516 | - set_pixel(p.x, p.y, color.map(format())); |
1517 | - |
1518 | - if (dxabs >= dyabs) // the line is more horizontal than vertical |
1519 | - for (uint32_t i = 0; i < dxabs; ++i) { |
1520 | - y += dyabs; |
1521 | - |
1522 | - if (y >= dxabs) { |
1523 | - y -= dxabs; |
1524 | - p.y += sdy; |
1525 | - } |
1526 | - |
1527 | - p.x += sdx; |
1528 | - for (int32_t w = 0; w < gwidth; ++w) { |
1529 | - set_pixel(p.x, p.y + w, color.map(format())); |
1530 | - } |
1531 | - } |
1532 | - else // the line is more vertical than horizontal |
1533 | - for (uint32_t i = 0; i < dyabs; ++i) { |
1534 | - x += dxabs; |
1535 | - |
1536 | - if (x >= dyabs) { |
1537 | - x -= dyabs; |
1538 | - p.x += sdx; |
1539 | - } |
1540 | - |
1541 | - p.y += sdy; |
1542 | - for (int32_t w = 0; w < gwidth; ++w) { |
1543 | - set_pixel(p.x + w, p.y, color.map(format())); |
1544 | - } |
1545 | - } |
1546 | -} |
1547 | - |
1548 | - |
1549 | -void SDLSurface::blit |
1550 | - (const Point& dst, const Surface* src, const Rect& srcrc, Composite cm) |
1551 | -{ |
1552 | - SDL_Surface* sdlsurf = static_cast<const SDLSurface*>(src)->get_sdl_surface(); |
1553 | - SDL_Rect srcrect = { |
1554 | - static_cast<int16_t>(srcrc.x), static_cast<int16_t>(srcrc.y), |
1555 | - static_cast<uint16_t>(srcrc.w), static_cast<uint16_t>(srcrc.h) |
1556 | - }; |
1557 | - SDL_Rect dstrect = { |
1558 | - static_cast<int16_t>(dst.x), static_cast<int16_t>(dst.y), |
1559 | - 0, 0 |
1560 | - }; |
1561 | - |
1562 | - bool alpha = false; |
1563 | - uint8_t alphaval = 0; |
1564 | - if (cm == CM_Copy) { |
1565 | - SDL_BlendMode bm; |
1566 | - SDL_GetSurfaceBlendMode(sdlsurf, &bm); |
1567 | - alpha = bm & SDL_BLENDMODE_BLEND; |
1568 | - SDL_GetSurfaceAlphaMod(sdlsurf, &alphaval); |
1569 | - SDL_SetSurfaceAlphaMod(sdlsurf, 255); |
1570 | - SDL_SetSurfaceBlendMode(sdlsurf, SDL_BLENDMODE_NONE); |
1571 | - } |
1572 | - |
1573 | - SDL_BlitSurface(sdlsurf, &srcrect, m_surface, &dstrect); |
1574 | - |
1575 | - if (cm == CM_Copy) { |
1576 | - SDL_SetSurfaceAlphaMod(sdlsurf, alphaval); |
1577 | - SDL_SetSurfaceBlendMode(sdlsurf, alpha ? SDL_BLENDMODE_BLEND : SDL_BLENDMODE_NONE); |
1578 | - } |
1579 | -} |
1580 | |
1581 | === removed file 'src/graphic/sdl/surface.h' |
1582 | --- src/graphic/sdl/surface.h 2014-11-02 20:31:40 +0000 |
1583 | +++ src/graphic/sdl/surface.h 1970-01-01 00:00:00 +0000 |
1584 | @@ -1,77 +0,0 @@ |
1585 | -/* |
1586 | - * Copyright (C) 2010-2011 by the Widelands Development Team |
1587 | - * |
1588 | - * This program is free software; you can redistribute it and/or |
1589 | - * modify it under the terms of the GNU General Public License |
1590 | - * as published by the Free Software Foundation; either version 2 |
1591 | - * of the License, or (at your option) any later version. |
1592 | - * |
1593 | - * This program is distributed in the hope that it will be useful, |
1594 | - * but WITHOUT ANY WARRANTY; without even the implied warranty of |
1595 | - * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the |
1596 | - * GNU General Public License for more details. |
1597 | - * |
1598 | - * You should have received a copy of the GNU General Public License |
1599 | - * along with this program; if not, write to the Free Software |
1600 | - * Foundation, Inc., 51 Franklin Street, Fifth Floor, Boston, MA 02110-1301, USA. |
1601 | - * |
1602 | - */ |
1603 | - |
1604 | -#ifndef WL_GRAPHIC_SDL_SURFACE_H |
1605 | -#define WL_GRAPHIC_SDL_SURFACE_H |
1606 | - |
1607 | -#include <SDL_render.h> |
1608 | - |
1609 | -#include "base/rect.h" |
1610 | -#include "graphic/color.h" |
1611 | -#include "graphic/surface.h" |
1612 | - |
1613 | -/** |
1614 | -* This implements SDL rendering. Do not use this class directly. The right |
1615 | -* way is to use the base struct Surface wherever possible. Everything which |
1616 | -* needs to know about the underlying renderer should go to the graphics |
1617 | -* subdirectory. |
1618 | -*/ |
1619 | -class SDLSurface : public Surface { |
1620 | -public: |
1621 | - // The surface set by SetVideoMode must not be freed according to the SDL |
1622 | - // docs, so we need 'free_surface_on_delete'. |
1623 | - SDLSurface(SDL_Surface* surface, bool free_surface_on_delete = true); |
1624 | - virtual ~SDLSurface(); |
1625 | - |
1626 | - // Implements Image |
1627 | - uint16_t width() const override {return m_w;} |
1628 | - uint16_t height() const override {return m_h;} |
1629 | - |
1630 | - // Implements Surface |
1631 | - void blit(const Point&, const Surface*, const Rect& srcrc, Composite cm) override; |
1632 | - void fill_rect(const Rect&, const RGBAColor&) override; |
1633 | - |
1634 | - // Implements Surface |
1635 | - void draw_rect(const Rect&, const RGBColor&) override; |
1636 | - virtual void draw_line |
1637 | - (int32_t x1, int32_t y1, int32_t x2, int32_t y2, const RGBColor&, uint8_t width) override; |
1638 | - void brighten_rect(const Rect&, int32_t factor) override; |
1639 | - |
1640 | - const SDL_PixelFormat & format() const override; |
1641 | - void lock(LockMode) override; |
1642 | - void unlock(UnlockMode) override; |
1643 | - uint32_t get_pixel(uint16_t x, uint16_t y) override; |
1644 | - void set_pixel(uint16_t x, uint16_t y, uint32_t clr) override; |
1645 | - uint16_t get_pitch() const override {return m_surface->pitch;} |
1646 | - uint8_t * get_pixels() const override; |
1647 | - |
1648 | - SDL_Surface * get_sdl_surface() const {return m_surface;} |
1649 | - |
1650 | - void set_subwin(const Rect& r); |
1651 | - void unset_subwin(); |
1652 | - |
1653 | -protected: |
1654 | - SDL_Surface * m_surface; |
1655 | - int32_t m_offsx; |
1656 | - int32_t m_offsy; |
1657 | - uint16_t m_w, m_h; |
1658 | - bool m_free_surface_on_delete; |
1659 | -}; |
1660 | - |
1661 | -#endif // end of include guard: WL_GRAPHIC_SDL_SURFACE_H |
1662 | |
1663 | === removed file 'src/graphic/sdl/terrain.cc' |
1664 | --- src/graphic/sdl/terrain.cc 2014-09-27 18:53:55 +0000 |
1665 | +++ src/graphic/sdl/terrain.cc 1970-01-01 00:00:00 +0000 |
1666 | @@ -1,34 +0,0 @@ |
1667 | -/* |
1668 | - * Copyright (C) 2002-2004, 2006, 2009-2010 by the Widelands Development Team |
1669 | - * |
1670 | - * This program is free software; you can redistribute it and/or |
1671 | - * modify it under the terms of the GNU General Public License |
1672 | - * as published by the Free Software Foundation; either version 2 |
1673 | - * of the License, or (at your option) any later version. |
1674 | - * |
1675 | - * This program is distributed in the hope that it will be useful, |
1676 | - * but WITHOUT ANY WARRANTY; without even the implied warranty of |
1677 | - * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the |
1678 | - * GNU General Public License for more details. |
1679 | - * |
1680 | - * You should have received a copy of the GNU General Public License |
1681 | - * along with this program; if not, write to the Free Software |
1682 | - * Foundation, Inc., 51 Franklin Street, Fifth Floor, Boston, MA 02110-1301, USA. |
1683 | - * |
1684 | - */ |
1685 | - |
1686 | -#include "graphic/sdl/terrain.h" |
1687 | - |
1688 | -/// get lambda and mu so that |
1689 | -/// lambda * u + mu * v = (1 0)^T with u = (u1 u2)^T and v = (v1 v2)^T |
1690 | -void get_horiz_linearcomb |
1691 | - (int32_t const u1, int32_t const u2, int32_t const v1, int32_t const v2, |
1692 | - float & lambda, float & mu) |
1693 | -{ |
1694 | - float det; |
1695 | - |
1696 | - det = u1 * v2 - u2 * v1; // determinant of (u v) |
1697 | - |
1698 | - lambda = v2 / det; // by Cramer's rule |
1699 | - mu = -u2 / det; |
1700 | -} |
1701 | |
1702 | === removed file 'src/graphic/sdl/terrain.h' |
1703 | --- src/graphic/sdl/terrain.h 2014-09-27 18:53:55 +0000 |
1704 | +++ src/graphic/sdl/terrain.h 1970-01-01 00:00:00 +0000 |
1705 | @@ -1,668 +0,0 @@ |
1706 | -/* |
1707 | - * Copyright (C) 2002-2004, 2006-2010 by the Widelands Development Team |
1708 | - * |
1709 | - * This program is free software; you can redistribute it and/or |
1710 | - * modify it under the terms of the GNU General Public License |
1711 | - * as published by the Free Software Foundation; either version 2 |
1712 | - * of the License, or (at your option) any later version. |
1713 | - * |
1714 | - * This program is distributed in the hope that it will be useful, |
1715 | - * but WITHOUT ANY WARRANTY; without even the implied warranty of |
1716 | - * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the |
1717 | - * GNU General Public License for more details. |
1718 | - * |
1719 | - * You should have received a copy of the GNU General Public License |
1720 | - * along with this program; if not, write to the Free Software |
1721 | - * Foundation, Inc., 51 Franklin Street, Fifth Floor, Boston, MA 02110-1301, USA. |
1722 | - * |
1723 | - */ |
1724 | - |
1725 | -#ifndef WL_GRAPHIC_SDL_TERRAIN_H |
1726 | -#define WL_GRAPHIC_SDL_TERRAIN_H |
1727 | - |
1728 | -#include <cassert> |
1729 | - |
1730 | -#include "base/log.h" |
1731 | -#include "base/macros.h" |
1732 | -#include "graphic/graphic.h" |
1733 | -#include "graphic/sdl/surface.h" |
1734 | -#include "graphic/sdl/vertex.h" |
1735 | -#include "graphic/texture.h" |
1736 | -#include "logic/roadtype.h" |
1737 | -#include "random/random.h" |
1738 | -#include "wui/mapviewpixelconstants.h" |
1739 | - |
1740 | -///Must be a power of two |
1741 | -#define DITHER_WIDTH 4 |
1742 | - |
1743 | -#define DITHER_RAND_MASK (DITHER_WIDTH * 2 - 1) |
1744 | -#define DITHER_RAND_SHIFT (16 / DITHER_WIDTH) |
1745 | - |
1746 | -// TODO(unknown): Dangerous: casting, assumptions for sizeof(X), bitshifting |
1747 | -#define FTOFIX(f) (static_cast<int32_t>((f) * 0x10000)) |
1748 | -#define ITOFIX(i) ((i)<<16) |
1749 | -#define FIXTOI(f) ((f)>>16) |
1750 | - |
1751 | -void get_horiz_linearcomb |
1752 | - (int32_t u1, int32_t u2, int32_t v1, int32_t v2, |
1753 | - float & lambda, float & mu); |
1754 | - |
1755 | - |
1756 | -struct LeftEdge { |
1757 | - /** |
1758 | - * Height of the edge. |
1759 | - * |
1760 | - * This is the number of pixels spanned by the edge in a vertical direction |
1761 | - */ |
1762 | - uint32_t height; |
1763 | - |
1764 | - // the following are all fixed point |
1765 | - int32_t x0; |
1766 | - int32_t tx0; |
1767 | - int32_t ty0; |
1768 | - int32_t b0; |
1769 | - int32_t dx; |
1770 | - int32_t dtx; |
1771 | - int32_t dty; |
1772 | - int32_t db; |
1773 | -}; |
1774 | - |
1775 | -struct RightEdge { |
1776 | - uint32_t height; |
1777 | - |
1778 | - int32_t x0; |
1779 | - int32_t dx; |
1780 | -}; |
1781 | - |
1782 | - |
1783 | -/** |
1784 | - * Render a polygon based on the given edge lists. |
1785 | - * |
1786 | - * The edge lists will be overwritten with undefined values. |
1787 | - */ |
1788 | -template<typename T> static void render_edge_lists |
1789 | - (SDLSurface & dst, const Texture & tex, |
1790 | - int32_t y, int32_t height, |
1791 | - LeftEdge * left, RightEdge * right, |
1792 | - int32_t dbdx, int32_t dtydx) |
1793 | -{ |
1794 | - if (-y >= height) |
1795 | - return; // completely above screen |
1796 | - |
1797 | - uint8_t * texpixels; |
1798 | - T * texcolormap; |
1799 | - |
1800 | - texpixels = tex.get_curpixels(); |
1801 | - texcolormap = static_cast<T *>(tex.get_colormap()); |
1802 | - |
1803 | - // Skip lines that are above the screen |
1804 | - while (y < 0) { |
1805 | - int32_t skip = -y; |
1806 | - if (skip > static_cast<int32_t>(left->height)) |
1807 | - skip = left->height; |
1808 | - if (skip > static_cast<int32_t>(right->height)) |
1809 | - skip = right->height; |
1810 | - |
1811 | - if (skip < static_cast<int32_t>(left->height)) { |
1812 | - left->x0 += skip * left->dx; |
1813 | - left->tx0 += skip * left->dtx; |
1814 | - left->ty0 += skip * left->dty; |
1815 | - left->b0 += skip * left->db; |
1816 | - left->height -= skip; |
1817 | - } else { |
1818 | - ++left; |
1819 | - } |
1820 | - |
1821 | - if (skip < static_cast<int32_t>(right->height)) { |
1822 | - right->x0 += skip * right->dx; |
1823 | - right->height -= skip; |
1824 | - } else { |
1825 | - ++right; |
1826 | - } |
1827 | - |
1828 | - height -= skip; |
1829 | - y += skip; |
1830 | - } |
1831 | - |
1832 | - // Cut off lines below screen |
1833 | - if (y + height > static_cast<int32_t>(dst.height())) |
1834 | - height = dst.height() - y; |
1835 | - |
1836 | - int32_t dstw = dst.width(); |
1837 | - while (height > 0) { |
1838 | - int32_t leftx = FIXTOI(left->x0); |
1839 | - int32_t rightx = FIXTOI(right->x0); |
1840 | - |
1841 | - if (leftx < 0) |
1842 | - leftx = 0; |
1843 | - if (rightx > dstw) |
1844 | - rightx = dstw; |
1845 | - |
1846 | - if (leftx < rightx) { |
1847 | - int32_t tx = left->tx0; |
1848 | - int32_t ty = left->ty0; |
1849 | - int32_t b = left->b0; |
1850 | - |
1851 | - int32_t adjust = ITOFIX(leftx) - left->x0; |
1852 | - tx += adjust; // note: dtx/dx = 1 |
1853 | - ty += FIXTOI(static_cast<long long>(adjust) * dtydx); |
1854 | - b += FIXTOI(static_cast<long long>(adjust) * dbdx); |
1855 | - |
1856 | - // Technically, we should clamp b at every pixel, but that's too |
1857 | - // expensive. The following seems to be enough to get rid of |
1858 | - // artifacts along the border between seen and unseen fields. |
1859 | - if (b < ITOFIX(-128)) |
1860 | - b = ITOFIX(-128); |
1861 | - |
1862 | - tx = FIXTOI(tx); |
1863 | - |
1864 | - T * scanline = |
1865 | - reinterpret_cast<T *> |
1866 | - (static_cast<uint8_t *>(dst.get_pixels()) + y * dst.get_pitch()) |
1867 | - + |
1868 | - leftx; |
1869 | - |
1870 | - uint32_t count = rightx - leftx; |
1871 | - while (count--) { |
1872 | - *scanline++ = |
1873 | - texcolormap |
1874 | - [texpixels |
1875 | - [(tx & (TEXTURE_WIDTH - 1)) | |
1876 | - ((ty >> 10) & ((TEXTURE_HEIGHT - 1) << 6))] |
1877 | - | |
1878 | - ((b >> 8) & 0xFF00)]; |
1879 | - |
1880 | - b += dbdx; |
1881 | - ++tx; |
1882 | - ty += dtydx; |
1883 | - } |
1884 | - } |
1885 | - |
1886 | - // Advance the line |
1887 | - ++y; |
1888 | - left->x0 += left->dx; |
1889 | - left->tx0 += left->dtx; |
1890 | - left->ty0 += left->dty; |
1891 | - left->b0 += left->db; |
1892 | - right->x0 += right->dx; |
1893 | - |
1894 | - if (--left->height == 0) |
1895 | - ++left; |
1896 | - if (--right->height == 0) |
1897 | - ++right; |
1898 | - --height; |
1899 | - } |
1900 | -} |
1901 | - |
1902 | -struct WLPolygon { |
1903 | - Point p[3]; |
1904 | - uint8_t nrpoints; |
1905 | -}; |
1906 | - |
1907 | - |
1908 | -/** |
1909 | - * Render a triangle into the given destination surface. |
1910 | - * |
1911 | - * \note It is assumed that p1, p2, p3 are sorted in counter-clockwise order. |
1912 | - * |
1913 | - * \note The rendering code assumes that d(tx)/d(x) = 1. This can be achieved |
1914 | - * by making sure that there is a 1:1 relation between x coordinates and |
1915 | - * texture x coordinates. |
1916 | - */ |
1917 | -template<typename T> static void render_triangle |
1918 | - (SDLSurface & dst, |
1919 | - const Vertex & p1, const Vertex & p2, const Vertex & p3, |
1920 | - const Texture & tex) |
1921 | -{ |
1922 | - if (p1.y == p2.y && p2.y == p3.y) |
1923 | - return; // degenerate triangle |
1924 | - |
1925 | - // Clip the triangle |
1926 | - WLPolygon polygon; |
1927 | - |
1928 | - polygon.p[0] = p1; |
1929 | - polygon.p[1] = p2; |
1930 | - polygon.p[2] = p3; |
1931 | - polygon.nrpoints = 3; |
1932 | - |
1933 | - // Determine a top vertex |
1934 | - int32_t top = 0, topy = 0; |
1935 | - |
1936 | - topy = 0x7fffffff; |
1937 | - for (uint8_t i = 0; i < polygon.nrpoints; ++i) { |
1938 | - if (polygon.p[i].y < topy) { |
1939 | - top = i; |
1940 | - topy = polygon.p[i].y; |
1941 | - } |
1942 | - } |
1943 | - |
1944 | - // Calculate d(b) / d(x) etc. as fixed point variables. |
1945 | - // Remember that we assume d(tx) / d(x) == 1 and d(tx) / d(y) == 0. |
1946 | - |
1947 | - // lA * (p2 - p1) + lB * (p3 - p1) = (1, 0) |
1948 | - // mA * (p2 - p1) + mB * (p3 - p1) = (0, 1) |
1949 | - int32_t const det = |
1950 | - (p2.x - p1.x) * (p3.y - p1.y) - (p2.y - p1.y) * (p3.x - p1.x); |
1951 | - int32_t const lA = ITOFIX(p3.y - p1.y) / det; |
1952 | - int32_t const lB = -ITOFIX(p2.y - p1.y) / det; |
1953 | - int32_t const mA = -ITOFIX(p3.x - p1.x) / det; |
1954 | - int32_t const mB = ITOFIX(p2.x - p1.x) / det; |
1955 | - int32_t const dbdx = lA * (p2.b - p1.b) + lB * (p3.b - p1.b); |
1956 | - int32_t const dbdy = mA * (p2.b - p1.b) + mB * (p3.b - p1.b); |
1957 | - int32_t const dtydx = lA * (p2.ty - p1.ty) + lB * (p3.ty - p1.ty); |
1958 | - int32_t const dtydy = mA * (p2.ty - p1.ty) + mB * (p3.ty - p1.ty); |
1959 | - |
1960 | - // Build left edges |
1961 | - int32_t boty = topy; |
1962 | - LeftEdge leftedges[3]; |
1963 | - |
1964 | - { |
1965 | - uint8_t nrleftedges = 0; |
1966 | - uint8_t start = top; |
1967 | - uint8_t end = (top + 1) % polygon.nrpoints; |
1968 | - do { |
1969 | - if (polygon.p[end].y > polygon.p[start].y) { |
1970 | - boty = polygon.p[end].y; |
1971 | - |
1972 | - LeftEdge & edge = leftedges[nrleftedges++]; |
1973 | - assert(nrleftedges <= 3); |
1974 | - |
1975 | - edge.height = polygon.p[end].y - polygon.p[start].y; |
1976 | - edge.x0 = ITOFIX(polygon.p[start].x); |
1977 | - edge.dx = |
1978 | - ITOFIX(polygon.p[end].x - polygon.p[start].x) |
1979 | - / |
1980 | - static_cast<int32_t>(edge.height); |
1981 | - |
1982 | - int32_t startdx = polygon.p[start].x - p1.x; |
1983 | - int32_t startdy = polygon.p[start].y - p1.y; |
1984 | - int32_t dx = polygon.p[end].x - polygon.p[start].x; |
1985 | - int32_t dy = polygon.p[end].y - polygon.p[start].y; |
1986 | - |
1987 | - edge.tx0 = ITOFIX(p1.tx + startdx); |
1988 | - edge.ty0 = ITOFIX(p1.ty) + startdx * dtydx + startdy * dtydy; |
1989 | - edge.b0 = ITOFIX(p1.b) + startdx * dbdx + startdy * dbdy; |
1990 | - edge.dtx = ITOFIX(dx) / static_cast<int32_t>(edge.height); |
1991 | - edge.dty = |
1992 | - (dx * dtydx + dy * dtydy) / static_cast<int32_t>(edge.height); |
1993 | - edge.db = |
1994 | - (dx * dbdx + dy * dbdy) / static_cast<int32_t>(edge.height); |
1995 | - } |
1996 | - |
1997 | - start = end; |
1998 | - end = (start + 1) % polygon.nrpoints; |
1999 | - } while (polygon.p[end].y >= polygon.p[start].y); |
2000 | - } |
2001 | - |
2002 | - // Build right edges |
2003 | - RightEdge rightedges[3]; |
2004 | - |
2005 | - { |
2006 | - uint8_t nrrightedges = 0; |
2007 | - uint8_t start = top; |
2008 | - uint8_t end = (polygon.nrpoints + top - 1) % polygon.nrpoints; |
2009 | - do { |
2010 | - if (polygon.p[end].y > polygon.p[start].y) { |
2011 | - RightEdge & edge = rightedges[nrrightedges++]; |
2012 | - assert(nrrightedges <= 3); |
2013 | - |
2014 | - edge.height = polygon.p[end].y - polygon.p[start].y; |
2015 | - edge.x0 = ITOFIX(polygon.p[start].x); |
2016 | - edge.dx = |
2017 | - ITOFIX(polygon.p[end].x - polygon.p[start].x) |
2018 | - / |
2019 | - static_cast<int32_t>(edge.height); |
2020 | - } |
2021 | - |
2022 | - start = end; |
2023 | - end = (polygon.nrpoints + start - 1) % polygon.nrpoints; |
2024 | - } while (polygon.p[end].y >= polygon.p[start].y); |
2025 | - } |
2026 | - |
2027 | - render_edge_lists<T> |
2028 | - (dst, tex, topy, boty - topy, leftedges, rightedges, dbdx, dtydx); |
2029 | -} |
2030 | - |
2031 | -/** |
2032 | - * Blur the polygon edge between vertices start and end. |
2033 | - * |
2034 | - * It is dithered by randomly placing points taken from the texture of the |
2035 | - * adjacent polygon. The blend area is a few pixels wide, and the chance for |
2036 | - * replacing a pixel depends on the distance from the center line. Texture |
2037 | - * coordinates and brightness are interpolated across the center line (outer |
2038 | - * loop). To the sides these are approximated (inner loop): Brightness is kept |
2039 | - * constant, and the texture is mapped orthogonally to the center line. It is |
2040 | - * important that only those pixels are drawn whose texture actually changes in |
2041 | - * order to minimize artifacts. |
2042 | - * |
2043 | - * \note All this is preliminary and subject to change. For example, a special |
2044 | - * edge texture could be used instead of stochastically dithering. Road |
2045 | - * rendering could be handled as a special case then. |
2046 | -*/ |
2047 | -template<typename T> static void dither_edge_horiz |
2048 | - (SDLSurface & dst, |
2049 | - const Vertex & start, const Vertex & end, |
2050 | - const Texture & ttex, const Texture & btex) |
2051 | -{ |
2052 | - uint8_t * tpixels, * bpixels; |
2053 | - T * tcolormap, * bcolormap; |
2054 | - |
2055 | - tpixels = ttex.get_curpixels(); |
2056 | - tcolormap = static_cast<T *>(ttex.get_colormap()); |
2057 | - bpixels = btex.get_curpixels(); |
2058 | - bcolormap = static_cast<T *>(btex.get_colormap()); |
2059 | - |
2060 | - int32_t tx, ty, b, dtx, dty, db, tx0, ty0; |
2061 | - |
2062 | - tx = ITOFIX(start.tx); |
2063 | - ty = ITOFIX(start.ty); |
2064 | - b = ITOFIX(start.b); |
2065 | - dtx = (ITOFIX(end.tx) - tx) / (end.x - start.x + 1); |
2066 | - dty = (ITOFIX(end.ty) - ty) / (end.x - start.x + 1); |
2067 | - db = (ITOFIX(end.b) - b) / (end.x - start.x + 1); |
2068 | - |
2069 | - // TODO(unknown): seed this depending on field coordinates |
2070 | - uint32_t rnd = 0; |
2071 | - |
2072 | - const int32_t dstw = dst.width(); |
2073 | - const int32_t dsth = dst.height(); |
2074 | - |
2075 | - int32_t ydiff = ITOFIX(end.y - start.y) / (end.x - start.x); |
2076 | - int32_t centery = ITOFIX(start.y); |
2077 | - |
2078 | - for (int32_t x = start.x; x < end.x; x++, centery += ydiff) { |
2079 | - rnd = SIMPLE_RAND(rnd); |
2080 | - |
2081 | - if (x >= 0 && x < dstw) { |
2082 | - int32_t y = FIXTOI(centery) - DITHER_WIDTH; |
2083 | - |
2084 | - tx0 = tx - DITHER_WIDTH * dty; |
2085 | - ty0 = ty + DITHER_WIDTH * dtx; |
2086 | - |
2087 | - uint32_t rnd0 = rnd; |
2088 | - |
2089 | - // dither above the edge |
2090 | - for (uint32_t i = 0; i < DITHER_WIDTH; i++, y++) { |
2091 | - if ((rnd0 & DITHER_RAND_MASK) <= i && y >= 0 && y < dsth) { |
2092 | - T * const pix = |
2093 | - reinterpret_cast<T *> |
2094 | - (static_cast<uint8_t *>(dst.get_pixels()) |
2095 | - + |
2096 | - y * dst.get_pitch()) |
2097 | - + |
2098 | - x; |
2099 | - *pix = |
2100 | - tcolormap |
2101 | - [tpixels |
2102 | - [((tx0 >> 16) & (TEXTURE_WIDTH - 1)) | |
2103 | - ((ty0 >> 10) & ((TEXTURE_HEIGHT - 1) << 6))] |
2104 | - | |
2105 | - ((b >> 8) & 0xFF00)]; |
2106 | - } |
2107 | - |
2108 | - tx0 += dty; |
2109 | - ty0 -= dtx; |
2110 | - rnd0 >>= DITHER_RAND_SHIFT; |
2111 | - } |
2112 | - |
2113 | - // dither below the edge |
2114 | - for |
2115 | - (uint32_t i = 0; |
2116 | - i < DITHER_WIDTH; |
2117 | - ++i, ++y, tx0 += dty, ty0 -= dtx, rnd0 >>= DITHER_RAND_SHIFT) |
2118 | - if |
2119 | - ((rnd0 & DITHER_RAND_MASK) >= i + DITHER_WIDTH && |
2120 | - y >= 0 && y < dsth) |
2121 | - reinterpret_cast<T *> |
2122 | - (static_cast<uint8_t *>(dst.get_pixels()) |
2123 | - + |
2124 | - y * dst.get_pitch()) |
2125 | - [x] |
2126 | - = |
2127 | - bcolormap |
2128 | - [bpixels |
2129 | - [((tx0 >> 16) & (TEXTURE_WIDTH - 1)) | |
2130 | - ((ty0 >> 10) & ((TEXTURE_HEIGHT - 1) << 6))] |
2131 | - | |
2132 | - ((b >> 8) & 0xFF00)]; |
2133 | - } |
2134 | - |
2135 | - tx += dtx; |
2136 | - ty += dty; |
2137 | - b += db; |
2138 | - } |
2139 | -} |
2140 | - |
2141 | -/** |
2142 | - * \see dither_edge_horiz |
2143 | - */ |
2144 | -template<typename T> static void dither_edge_vert |
2145 | - (SDLSurface & dst, |
2146 | - const Vertex & start, const Vertex & end, |
2147 | - const Texture & ltex, const Texture & rtex) |
2148 | -{ |
2149 | - uint8_t * lpixels, * rpixels; |
2150 | - T * lcolormap, * rcolormap; |
2151 | - |
2152 | - lpixels = ltex.get_curpixels(); |
2153 | - lcolormap = static_cast<T *>(ltex.get_colormap()); |
2154 | - rpixels = rtex.get_curpixels(); |
2155 | - rcolormap = static_cast<T *>(rtex.get_colormap()); |
2156 | - |
2157 | - int32_t tx, ty, b, dtx, dty, db, tx0, ty0; |
2158 | - |
2159 | - tx = ITOFIX(start.tx); |
2160 | - ty = ITOFIX(start.ty); |
2161 | - b = ITOFIX(start.b); |
2162 | - dtx = (ITOFIX(end.tx) - tx) / (end.y - start.y + 1); |
2163 | - dty = (ITOFIX(end.ty) - ty) / (end.y - start.y + 1); |
2164 | - db = (ITOFIX(end.b) - b) / (end.y - start.y + 1); |
2165 | - |
2166 | - // TODO(unknown): seed this depending on field coordinates |
2167 | - uint32_t rnd = 0; |
2168 | - |
2169 | - const int32_t dstw = dst.width(); |
2170 | - const int32_t dsth = dst.height(); |
2171 | - |
2172 | - int32_t xdiff = ITOFIX(end.x - start.x) / (end.y - start.y); |
2173 | - int32_t centerx = ITOFIX(start.x); |
2174 | - |
2175 | - for (int32_t y = start.y; y < end.y; y++, centerx += xdiff) { |
2176 | - rnd = SIMPLE_RAND(rnd); |
2177 | - |
2178 | - if (y >= 0 && y < dsth) { |
2179 | - int32_t x = FIXTOI(centerx) - DITHER_WIDTH; |
2180 | - |
2181 | - tx0 = tx - DITHER_WIDTH * dty; |
2182 | - ty0 = ty + DITHER_WIDTH * dtx; |
2183 | - |
2184 | - uint32_t rnd0 = rnd; |
2185 | - |
2186 | - // dither on left side |
2187 | - for |
2188 | - (uint32_t i = 0; |
2189 | - i < DITHER_WIDTH; |
2190 | - ++i, ++x, tx0 += dty, ty0 -= dtx, rnd0 >>= DITHER_RAND_SHIFT) |
2191 | - if ((rnd0 & DITHER_RAND_MASK) <= i && x >= 0 && x < dstw) |
2192 | - reinterpret_cast<T *> |
2193 | - (static_cast<uint8_t *>(dst.get_pixels()) |
2194 | - + |
2195 | - y * dst.get_pitch()) |
2196 | - [x] |
2197 | - = |
2198 | - lcolormap |
2199 | - [lpixels |
2200 | - [((tx0 >> 16) & (TEXTURE_WIDTH - 1)) | |
2201 | - ((ty0 >> 10) & ((TEXTURE_HEIGHT - 1) << 6))] |
2202 | - | |
2203 | - ((b >> 8) & 0xFF00)]; |
2204 | - |
2205 | - // dither on right side |
2206 | - for |
2207 | - (uint32_t i = 0; |
2208 | - i < DITHER_WIDTH; |
2209 | - ++i, ++x, tx0 += dty, ty0 -= dtx, rnd0 >>= DITHER_RAND_SHIFT) |
2210 | - if |
2211 | - ((rnd0 & DITHER_RAND_MASK) >= i + DITHER_WIDTH |
2212 | - && |
2213 | - x >= 0 && x < dstw) |
2214 | - reinterpret_cast<T *> |
2215 | - (static_cast<uint8_t *>(dst.get_pixels()) |
2216 | - + |
2217 | - y * dst.get_pitch()) |
2218 | - [x] |
2219 | - = |
2220 | - rcolormap |
2221 | - [rpixels |
2222 | - [((tx0 >> 16) & (TEXTURE_WIDTH - 1)) | |
2223 | - ((ty0 >> 10) & ((TEXTURE_HEIGHT - 1) << 6))] |
2224 | - | |
2225 | - ((b >> 8) & 0xFF00)]; |
2226 | - } |
2227 | - |
2228 | - tx += dtx; |
2229 | - ty += dty; |
2230 | - b += db; |
2231 | - } |
2232 | -} |
2233 | - |
2234 | -template<typename T> static void render_road_horiz |
2235 | - (SDLSurface & dst, Point const start, Point const end, const SDLSurface & src) |
2236 | -{ |
2237 | - int32_t const dstw = dst.width(); |
2238 | - int32_t const dsth = dst.height(); |
2239 | - |
2240 | - int32_t const ydiff = ((end.y - start.y) << 16) / (end.x - start.x); |
2241 | - int32_t centery = start.y << 16; |
2242 | - |
2243 | - for (int32_t x = start.x, sx = 0; x < end.x; ++x, centery += ydiff, ++sx) { |
2244 | - if (x < 0 || x >= dstw) |
2245 | - continue; |
2246 | - |
2247 | - for (int32_t i = 0, y = (centery >> 16) - 2; i < 5; ++i, ++y) |
2248 | - if (0 < y && y < dsth) |
2249 | - reinterpret_cast<T *> |
2250 | - (static_cast<uint8_t *>(dst.get_pixels()) + y * dst.get_pitch()) |
2251 | - [x] |
2252 | - = |
2253 | - reinterpret_cast<T const *> |
2254 | - (static_cast<uint8_t const *>(src.get_pixels()) |
2255 | - + |
2256 | - i * src.get_pitch()) |
2257 | - [sx]; |
2258 | - } |
2259 | -} |
2260 | - |
2261 | -template<typename T> static void render_road_vert |
2262 | - (SDLSurface & dst, Point const start, Point const end, const SDLSurface & src) |
2263 | -{ |
2264 | - int32_t const dstw = dst.width(); |
2265 | - int32_t const dsth = dst.height(); |
2266 | - |
2267 | - int32_t const xdiff = ((end.x - start.x) << 16) / (end.y - start.y); |
2268 | - int32_t centerx = start.x << 16; |
2269 | - |
2270 | - for (int32_t y = start.y, sy = 0; y < end.y; ++y, centerx += xdiff, ++sy) { |
2271 | - if (y < 0 || y >= dsth) |
2272 | - continue; |
2273 | - |
2274 | - for (int32_t i = 0, x = (centerx >> 16) - 2; i < 5; ++i, ++x) |
2275 | - if (0 < x && x < dstw) |
2276 | - reinterpret_cast<T *> |
2277 | - (static_cast<uint8_t *>(dst.get_pixels()) + y * dst.get_pitch()) |
2278 | - [x] |
2279 | - = |
2280 | - reinterpret_cast<T const *> |
2281 | - (static_cast<uint8_t const *>(src.get_pixels()) |
2282 | - + |
2283 | - sy * src.get_pitch()) |
2284 | - [i]; |
2285 | - } |
2286 | -} |
2287 | - |
2288 | -template<typename T> static void draw_field_int |
2289 | - (SDLSurface & dst, |
2290 | - const Vertex & f_vert, |
2291 | - const Vertex & r_vert, |
2292 | - const Vertex & bl_vert, |
2293 | - const Vertex & br_vert, |
2294 | - uint8_t roads, |
2295 | - const Texture & tr_d_texture, |
2296 | - const Texture & l_r_texture, |
2297 | - const Texture & f_d_texture, |
2298 | - const Texture & f_r_texture) |
2299 | -{ |
2300 | - SDLSurface& rt_busy = static_cast<SDLSurface&>(g_gr->get_road_texture(Widelands::Road_Busy)); |
2301 | - SDLSurface& rt_normal = static_cast<SDLSurface&>(g_gr->get_road_texture(Widelands::Road_Normal)); |
2302 | - |
2303 | - dst.lock(Surface::Lock_Normal); |
2304 | - |
2305 | - render_triangle<T> (dst, f_vert, br_vert, r_vert, f_r_texture); |
2306 | - render_triangle<T> (dst, f_vert, bl_vert, br_vert, f_d_texture); |
2307 | - |
2308 | - // Render roads and dither polygon edges |
2309 | - uint8_t road; |
2310 | - |
2311 | - road = (roads >> Widelands::Road_East) & Widelands::Road_Mask; |
2312 | - if (-128 < f_vert.b || -128 < r_vert.b) { |
2313 | - if (road) { |
2314 | - switch (road) { |
2315 | - case Widelands::Road_Normal: |
2316 | - render_road_horiz<T> (dst, f_vert, r_vert, rt_normal); |
2317 | - break; |
2318 | - case Widelands::Road_Busy: |
2319 | - render_road_horiz<T> (dst, f_vert, r_vert, rt_busy); |
2320 | - break; |
2321 | - default: |
2322 | - assert(false); |
2323 | - break; |
2324 | - } |
2325 | - } else if (&f_r_texture != &tr_d_texture) { |
2326 | - dither_edge_horiz<T>(dst, f_vert, r_vert, f_r_texture, tr_d_texture); |
2327 | - } |
2328 | - } |
2329 | - |
2330 | - road = (roads >> Widelands::Road_SouthEast) & Widelands::Road_Mask; |
2331 | - if (-128 < f_vert.b || -128 < br_vert.b) { |
2332 | - if (road) { |
2333 | - switch (road) { |
2334 | - case Widelands::Road_Normal: |
2335 | - render_road_vert<T> (dst, f_vert, br_vert, rt_normal); |
2336 | - break; |
2337 | - case Widelands::Road_Busy: |
2338 | - render_road_vert<T> (dst, f_vert, br_vert, rt_busy); |
2339 | - break; |
2340 | - default: |
2341 | - assert(false); |
2342 | - break; |
2343 | - } |
2344 | - } else if (&f_r_texture != &f_d_texture) { |
2345 | - dither_edge_vert<T>(dst, f_vert, br_vert, f_r_texture, f_d_texture); |
2346 | - } |
2347 | - } |
2348 | - |
2349 | - road = (roads >> Widelands::Road_SouthWest) & Widelands::Road_Mask; |
2350 | - if (-128 < f_vert.b || -128 < bl_vert.b) { |
2351 | - if (road) { |
2352 | - switch (road) { |
2353 | - case Widelands::Road_Normal: |
2354 | - render_road_vert<T> (dst, f_vert, bl_vert, rt_normal); |
2355 | - break; |
2356 | - case Widelands::Road_Busy: |
2357 | - render_road_vert<T> (dst, f_vert, bl_vert, rt_busy); |
2358 | - break; |
2359 | - default: |
2360 | - assert(false); |
2361 | - break; |
2362 | - } |
2363 | - } else if (&l_r_texture != &f_d_texture) { |
2364 | - dither_edge_vert<T>(dst, f_vert, bl_vert, f_d_texture, l_r_texture); |
2365 | - } |
2366 | - } |
2367 | - |
2368 | - dst.unlock(Surface::Unlock_Update); |
2369 | - |
2370 | - // TODO(unknown): similar textures may not need dithering |
2371 | -} |
2372 | - |
2373 | -#endif // end of include guard: WL_GRAPHIC_SDL_TERRAIN_H |
2374 | |
2375 | === removed file 'src/graphic/sdl/utils.cc' |
2376 | --- src/graphic/sdl/utils.cc 2014-11-08 15:47:38 +0000 |
2377 | +++ src/graphic/sdl/utils.cc 1970-01-01 00:00:00 +0000 |
2378 | @@ -1,30 +0,0 @@ |
2379 | -/* |
2380 | - * Copyright (C) 2006-2012 by the Widelands Development Team |
2381 | - * |
2382 | - * This program is free software; you can redistribute it and/or |
2383 | - * modify it under the terms of the GNU General Public License |
2384 | - * as published by the Free Software Foundation; either version 2 |
2385 | - * of the License, or (at your option) any later version. |
2386 | - * |
2387 | - * This program is distributed in the hope that it will be useful, |
2388 | - * but WITHOUT ANY WARRANTY; without even the implied warranty of |
2389 | - * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the |
2390 | - * GNU General Public License for more details. |
2391 | - * |
2392 | - * You should have received a copy of the GNU General Public License |
2393 | - * along with this program; if not, write to the Free Software |
2394 | - * Foundation, Inc., 675 Mass Ave, Cambridge, MA 02139, USA. |
2395 | - * |
2396 | - */ |
2397 | - |
2398 | -#include "graphic/sdl/utils.h" |
2399 | - |
2400 | -#include <cassert> |
2401 | - |
2402 | -#include <SDL.h> |
2403 | - |
2404 | -SDL_Surface * empty_sdl_surface(int16_t w, int16_t h) { |
2405 | - SDL_Surface* const surface = |
2406 | - SDL_CreateRGBSurface(SDL_SWSURFACE, w, h, 32, 0x000000ff, 0x0000ff00, 0x00ff0000, 0xff000000); |
2407 | - return surface; |
2408 | -} |
2409 | |
2410 | === removed file 'src/graphic/sdl/utils.h' |
2411 | --- src/graphic/sdl/utils.h 2014-09-27 18:53:55 +0000 |
2412 | +++ src/graphic/sdl/utils.h 1970-01-01 00:00:00 +0000 |
2413 | @@ -1,29 +0,0 @@ |
2414 | -/* |
2415 | - * Copyright (C) 2006-2012 by the Widelands Development Team |
2416 | - * |
2417 | - * This program is free software; you can redistribute it and/or |
2418 | - * modify it under the terms of the GNU General Public License |
2419 | - * as published by the Free Software Foundation; either version 2 |
2420 | - * of the License, or (at your option) any later version. |
2421 | - * |
2422 | - * This program is distributed in the hope that it will be useful, |
2423 | - * but WITHOUT ANY WARRANTY; without even the implied warranty of |
2424 | - * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the |
2425 | - * GNU General Public License for more details. |
2426 | - * |
2427 | - * You should have received a copy of the GNU General Public License |
2428 | - * along with this program; if not, write to the Free Software |
2429 | - * Foundation, Inc., 675 Mass Ave, Cambridge, MA 02139, USA. |
2430 | - * |
2431 | - */ |
2432 | - |
2433 | -#ifndef WL_GRAPHIC_SDL_UTILS_H |
2434 | -#define WL_GRAPHIC_SDL_UTILS_H |
2435 | - |
2436 | -#include <stdint.h> |
2437 | - |
2438 | -struct SDL_Surface; |
2439 | - |
2440 | -SDL_Surface * empty_sdl_surface(int16_t w, int16_t h); |
2441 | - |
2442 | -#endif // end of include guard: WL_GRAPHIC_SDL_UTILS_H |
2443 | |
2444 | === removed file 'src/graphic/sdl/vertex.h' |
2445 | --- src/graphic/sdl/vertex.h 2014-09-27 18:53:55 +0000 |
2446 | +++ src/graphic/sdl/vertex.h 1970-01-01 00:00:00 +0000 |
2447 | @@ -1,39 +0,0 @@ |
2448 | -/* |
2449 | - * Copyright (C) 2002-2004, 2006-2007 by the Widelands Development Team |
2450 | - * |
2451 | - * This program is free software; you can redistribute it and/or |
2452 | - * modify it under the terms of the GNU General Public License |
2453 | - * as published by the Free Software Foundation; either version 2 |
2454 | - * of the License, or (at your option) any later version. |
2455 | - * |
2456 | - * This program is distributed in the hope that it will be useful, |
2457 | - * but WITHOUT ANY WARRANTY; without even the implied warranty of |
2458 | - * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the |
2459 | - * GNU General Public License for more details. |
2460 | - * |
2461 | - * You should have received a copy of the GNU General Public License |
2462 | - * along with this program; if not, write to the Free Software |
2463 | - * Foundation, Inc., 51 Franklin Street, Fifth Floor, Boston, MA 02110-1301, USA. |
2464 | - * |
2465 | - */ |
2466 | - |
2467 | -#ifndef WL_GRAPHIC_SDL_VERTEX_H |
2468 | -#define WL_GRAPHIC_SDL_VERTEX_H |
2469 | - |
2470 | -#include "base/point.h" |
2471 | - |
2472 | -/// Like a point but with an additional bright factor and texture coordinates. |
2473 | -struct Vertex:public Point { |
2474 | - Vertex() : Point (0, 0), b(0), tx(0), ty(0) {} |
2475 | - Vertex |
2476 | - (const int32_t vx, const int32_t vy, |
2477 | - const int32_t vb, |
2478 | - const int32_t vtx, const int32_t vty) |
2479 | - |
2480 | - : Point(vx, vy), b(vb), tx(vtx), ty(vty) |
2481 | - {} |
2482 | - |
2483 | - int32_t b, tx, ty; |
2484 | -}; |
2485 | - |
2486 | -#endif // end of include guard: WL_GRAPHIC_SDL_VERTEX_H |
2487 | |
2488 | === added file 'src/graphic/sdl_utils.cc' |
2489 | --- src/graphic/sdl_utils.cc 1970-01-01 00:00:00 +0000 |
2490 | +++ src/graphic/sdl_utils.cc 2014-11-23 12:03:00 +0000 |
2491 | @@ -0,0 +1,28 @@ |
2492 | +/* |
2493 | + * Copyright (C) 2006-2014 by the Widelands Development Team |
2494 | + * |
2495 | + * This program is free software; you can redistribute it and/or |
2496 | + * modify it under the terms of the GNU General Public License |
2497 | + * as published by the Free Software Foundation; either version 2 |
2498 | + * of the License, or (at your option) any later version. |
2499 | + * |
2500 | + * This program is distributed in the hope that it will be useful, |
2501 | + * but WITHOUT ANY WARRANTY; without even the implied warranty of |
2502 | + * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the |
2503 | + * GNU General Public License for more details. |
2504 | + * |
2505 | + * You should have received a copy of the GNU General Public License |
2506 | + * along with this program; if not, write to the Free Software |
2507 | + * Foundation, Inc., 675 Mass Ave, Cambridge, MA 02139, USA. |
2508 | + * |
2509 | + */ |
2510 | + |
2511 | +#include "graphic/sdl_utils.h" |
2512 | + |
2513 | +#include <SDL.h> |
2514 | + |
2515 | +SDL_Surface* empty_sdl_surface(int16_t w, int16_t h) { |
2516 | + SDL_Surface* const surface = |
2517 | + SDL_CreateRGBSurface(SDL_SWSURFACE, w, h, 32, 0x000000ff, 0x0000ff00, 0x00ff0000, 0xff000000); |
2518 | + return surface; |
2519 | +} |
2520 | |
2521 | === added file 'src/graphic/sdl_utils.h' |
2522 | --- src/graphic/sdl_utils.h 1970-01-01 00:00:00 +0000 |
2523 | +++ src/graphic/sdl_utils.h 2014-11-23 12:03:00 +0000 |
2524 | @@ -0,0 +1,29 @@ |
2525 | +/* |
2526 | + * Copyright (C) 2006-2014 by the Widelands Development Team |
2527 | + * |
2528 | + * This program is free software; you can redistribute it and/or |
2529 | + * modify it under the terms of the GNU General Public License |
2530 | + * as published by the Free Software Foundation; either version 2 |
2531 | + * of the License, or (at your option) any later version. |
2532 | + * |
2533 | + * This program is distributed in the hope that it will be useful, |
2534 | + * but WITHOUT ANY WARRANTY; without even the implied warranty of |
2535 | + * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the |
2536 | + * GNU General Public License for more details. |
2537 | + * |
2538 | + * You should have received a copy of the GNU General Public License |
2539 | + * along with this program; if not, write to the Free Software |
2540 | + * Foundation, Inc., 675 Mass Ave, Cambridge, MA 02139, USA. |
2541 | + * |
2542 | + */ |
2543 | + |
2544 | +#ifndef WL_GRAPHIC_SDL_UTILS_H |
2545 | +#define WL_GRAPHIC_SDL_UTILS_H |
2546 | + |
2547 | +#include <stdint.h> |
2548 | + |
2549 | +struct SDL_Surface; |
2550 | + |
2551 | +SDL_Surface * empty_sdl_surface(int16_t w, int16_t h); |
2552 | + |
2553 | +#endif // end of include guard: |
2554 | |
2555 | === modified file 'src/graphic/surface.cc' |
2556 | --- src/graphic/surface.cc 2014-11-02 20:15:01 +0000 |
2557 | +++ src/graphic/surface.cc 2014-11-23 12:03:00 +0000 |
2558 | @@ -19,43 +19,175 @@ |
2559 | |
2560 | #include "graphic/surface.h" |
2561 | |
2562 | +#include <cassert> |
2563 | +#include <cmath> |
2564 | +#include <cstdlib> |
2565 | + |
2566 | #include <SDL.h> |
2567 | |
2568 | +#include "base/macros.h" |
2569 | +#include "graphic/gl/blit_program.h" |
2570 | +#include "graphic/gl/draw_line_program.h" |
2571 | +#include "graphic/gl/draw_rect_program.h" |
2572 | +#include "graphic/gl/fill_rect_program.h" |
2573 | #include "graphic/gl/surface_texture.h" |
2574 | -#include "graphic/sdl/surface.h" |
2575 | -#include "graphic/sdl/utils.h" |
2576 | - |
2577 | -extern bool g_opengl; |
2578 | - |
2579 | -namespace { |
2580 | - |
2581 | -bool s_is_diplay_format_defined = false; |
2582 | - |
2583 | -SDL_Surface* maybe_convert_to_diplay_format(SDL_Surface* surface) { |
2584 | - if (!s_is_diplay_format_defined) { |
2585 | - return surface; |
2586 | - } |
2587 | - SDL_Surface * converted = SDL_ConvertSurfaceFormat(surface, SDL_PIXELFORMAT_ARGB8888, 0); |
2588 | - SDL_FreeSurface(surface); |
2589 | - return converted; |
2590 | -} |
2591 | - |
2592 | -} // namespace |
2593 | - |
2594 | -void Surface::display_format_is_now_defined() { |
2595 | - s_is_diplay_format_defined = true; |
2596 | -} |
2597 | +#include "graphic/gl/utils.h" |
2598 | +#include "graphic/graphic.h" |
2599 | + |
2600 | |
2601 | Surface* Surface::create(SDL_Surface* surf) { |
2602 | - if (g_opengl) { |
2603 | - return new GLSurfaceTexture(surf); |
2604 | - } |
2605 | - return new SDLSurface(maybe_convert_to_diplay_format(surf)); |
2606 | + return new GLSurfaceTexture(surf); |
2607 | } |
2608 | |
2609 | Surface* Surface::create(uint16_t w, uint16_t h) { |
2610 | - if (g_opengl) { |
2611 | - return new GLSurfaceTexture(w, h); |
2612 | - } |
2613 | - return new SDLSurface(empty_sdl_surface(w, h)); |
2614 | + return new GLSurfaceTexture(w, h); |
2615 | +} |
2616 | + |
2617 | + |
2618 | +uint16_t Surface::width() const { |
2619 | + return m_w; |
2620 | +} |
2621 | + |
2622 | +uint16_t Surface::height() const { |
2623 | + return m_h; |
2624 | +} |
2625 | + |
2626 | +uint8_t * Surface::get_pixels() const |
2627 | +{ |
2628 | + return m_pixels.get(); |
2629 | +} |
2630 | + |
2631 | +uint32_t Surface::get_pixel(uint16_t x, uint16_t y) { |
2632 | + assert(m_pixels); |
2633 | + assert(x < m_w); |
2634 | + assert(y < m_h); |
2635 | + |
2636 | + uint8_t * data = &m_pixels[y * get_pitch() + 4 * x]; |
2637 | + return *(reinterpret_cast<uint32_t *>(data)); |
2638 | +} |
2639 | + |
2640 | +uint16_t Surface::get_pitch() const { |
2641 | + return 4 * m_w; |
2642 | +} |
2643 | + |
2644 | +const SDL_PixelFormat & Surface::format() const { |
2645 | + return Gl::gl_rgba_format(); |
2646 | +} |
2647 | + |
2648 | + |
2649 | +void Surface::set_pixel(uint16_t x, uint16_t y, uint32_t clr) { |
2650 | + assert(m_pixels); |
2651 | + assert(x < m_w); |
2652 | + assert(y < m_h); |
2653 | + |
2654 | + uint8_t * data = &m_pixels[y * get_pitch() + 4 * x]; |
2655 | + *(reinterpret_cast<uint32_t *>(data)) = clr; |
2656 | +} |
2657 | + |
2658 | +FloatRect Surface::to_opengl(const Rect& rect, ConversionMode mode) { |
2659 | + const float delta = mode == ConversionMode::kExact ? 0. : 0.5; |
2660 | + float x1 = rect.x + delta; |
2661 | + float y1 = rect.y + delta; |
2662 | + pixel_to_gl(&x1, &y1); |
2663 | + float x2 = rect.x + rect.w - delta; |
2664 | + float y2 = rect.y + rect.h - delta; |
2665 | + pixel_to_gl(&x2, &y2); |
2666 | + |
2667 | + return FloatRect(x1, y1, x2 - x1, y2 - y1); |
2668 | +} |
2669 | + |
2670 | +void Surface::draw_rect(const Rect& rc, const RGBColor& clr) |
2671 | +{ |
2672 | + glViewport(0, 0, width(), height()); |
2673 | + DrawRectProgram::instance().draw(to_opengl(rc, ConversionMode::kMidPoint), clr); |
2674 | +} |
2675 | + |
2676 | +/** |
2677 | + * Draws a filled rectangle |
2678 | + */ |
2679 | +void Surface::fill_rect(const Rect& rc, const RGBAColor& clr) { |
2680 | + glViewport(0, 0, width(), height()); |
2681 | + |
2682 | + glBlendFunc(GL_ONE, GL_ZERO); |
2683 | + |
2684 | + FillRectProgram::instance().draw(to_opengl(rc, ConversionMode::kExact), clr); |
2685 | + |
2686 | + glBlendFunc(GL_SRC_ALPHA, GL_ONE_MINUS_SRC_ALPHA); |
2687 | +} |
2688 | + |
2689 | +/** |
2690 | + * Change the brightness of the given rectangle |
2691 | + */ |
2692 | +void Surface::brighten_rect(const Rect& rc, const int32_t factor) |
2693 | +{ |
2694 | + if (!factor) |
2695 | + return; |
2696 | + |
2697 | + glViewport(0, 0, width(), height()); |
2698 | + |
2699 | + // The simple trick here is to fill the rect, but using a different glBlendFunc that will sum |
2700 | + // src and target (or subtract them if factor is negative). |
2701 | + if (factor < 0) { |
2702 | + glBlendEquation(GL_FUNC_REVERSE_SUBTRACT); |
2703 | + } |
2704 | + |
2705 | + glBlendFunc(GL_ONE, GL_ONE); |
2706 | + |
2707 | + const int delta = std::abs(factor); |
2708 | + FillRectProgram::instance().draw( |
2709 | + to_opengl(rc, ConversionMode::kExact), RGBAColor(delta, delta, delta, 0)); |
2710 | + |
2711 | + if (factor < 0) { |
2712 | + glBlendEquation(GL_FUNC_ADD); |
2713 | + } |
2714 | + |
2715 | + glBlendFunc(GL_SRC_ALPHA, GL_ONE_MINUS_SRC_ALPHA); |
2716 | +} |
2717 | + |
2718 | +void Surface::draw_line |
2719 | + (int32_t x1, int32_t y1, int32_t x2, int32_t y2, const RGBColor& color, uint8_t gwidth) |
2720 | +{ |
2721 | + glViewport(0, 0, width(), height()); |
2722 | + |
2723 | + float gl_x1 = x1 + 0.5; |
2724 | + float gl_y1 = y1 + 0.5; |
2725 | + pixel_to_gl(&gl_x1, &gl_y1); |
2726 | + |
2727 | + float gl_x2 = x2 + 0.5; |
2728 | + float gl_y2 = y2 + 0.5; |
2729 | + pixel_to_gl(&gl_x2, &gl_y2); |
2730 | + |
2731 | + DrawLineProgram::instance().draw(gl_x1, gl_y1, gl_x2, gl_y2, color, gwidth); |
2732 | +} |
2733 | + |
2734 | +// Converts the pixel (x, y) in a texture to a gl coordinate in [0, 1]. |
2735 | +inline void pixel_to_gl_texture(const int width, const int height, float* x, float* y) { |
2736 | + *x = (*x / width); |
2737 | + *y = (*y / height); |
2738 | +} |
2739 | + |
2740 | +void Surface::blit |
2741 | + (const Point& dst, const Surface* image, const Rect& srcrc, Composite cm) |
2742 | +{ |
2743 | + glViewport(0, 0, width(), height()); |
2744 | + |
2745 | + // Source Rectangle. |
2746 | + const GLSurfaceTexture* const texture = static_cast<const GLSurfaceTexture*>(image); |
2747 | + FloatRect gl_src_rect; |
2748 | + { |
2749 | + float x1 = srcrc.x; |
2750 | + float y1 = srcrc.y; |
2751 | + pixel_to_gl_texture(texture->width(), texture->height(), &x1, &y1); |
2752 | + float x2 = srcrc.x + srcrc.w; |
2753 | + float y2 = srcrc.y + srcrc.h; |
2754 | + pixel_to_gl_texture(texture->width(), texture->height(), &x2, &y2); |
2755 | + gl_src_rect.x = x1; |
2756 | + gl_src_rect.y = y1; |
2757 | + gl_src_rect.w = x2 - x1; |
2758 | + gl_src_rect.h = y2 - y1; |
2759 | + } |
2760 | + |
2761 | + const FloatRect gl_dst_rect = to_opengl(Rect(dst.x, dst.y, srcrc.w, srcrc.h), ConversionMode::kExact); |
2762 | + |
2763 | + BlitProgram::instance().draw(gl_dst_rect, gl_src_rect, texture->get_gl_texture(), cm); |
2764 | } |
2765 | |
2766 | === modified file 'src/graphic/surface.h' |
2767 | --- src/graphic/surface.h 2014-11-08 16:02:07 +0000 |
2768 | +++ src/graphic/surface.h 2014-11-23 12:03:00 +0000 |
2769 | @@ -20,6 +20,8 @@ |
2770 | #ifndef WL_GRAPHIC_SURFACE_H |
2771 | #define WL_GRAPHIC_SURFACE_H |
2772 | |
2773 | +#include <memory> |
2774 | + |
2775 | #include "base/macros.h" |
2776 | #include "base/rect.h" |
2777 | #include "graphic/color.h" |
2778 | @@ -31,13 +33,6 @@ |
2779 | */ |
2780 | class Surface { |
2781 | public: |
2782 | - // Surfaces can either be converted to display format on creation or kept in |
2783 | - // the format they were created. The only reason not to convert to display |
2784 | - // format is when no display format is defined - trying will then crash the |
2785 | - // program. This is only the case when SDL_SetVideoMode() has never been |
2786 | - // called, so call this method after you called SDL_SetVideoMode. |
2787 | - static void display_format_is_now_defined(); |
2788 | - |
2789 | // Create a new surface from an SDL_Surface. Ownership is taken. |
2790 | static Surface* create(SDL_Surface*); |
2791 | |
2792 | @@ -49,26 +44,26 @@ |
2793 | virtual ~Surface() {} |
2794 | |
2795 | /// Dimensions. |
2796 | - virtual uint16_t width() const = 0; |
2797 | - virtual uint16_t height() const = 0; |
2798 | + uint16_t width() const; |
2799 | + uint16_t height() const; |
2800 | |
2801 | /// This draws a part of another surface to this surface |
2802 | - virtual void blit(const Point&, const Surface*, const Rect& srcrc, Composite cm = CM_UseAlpha) = 0; |
2803 | + virtual void blit(const Point&, const Surface*, const Rect& srcrc, Composite cm = CM_UseAlpha); |
2804 | |
2805 | /// Draws a filled rect to the surface. No blending takes place, the values |
2806 | //in the target are just replaced (i.e. / Composite would be CM_Copy). |
2807 | - virtual void fill_rect(const Rect&, const RGBAColor&) = 0; |
2808 | + virtual void fill_rect(const Rect&, const RGBAColor&); |
2809 | |
2810 | /// Draws a rect (frame only) to the surface. |
2811 | - virtual void draw_rect(const Rect&, const RGBColor&) = 0; |
2812 | + virtual void draw_rect(const Rect&, const RGBColor&); |
2813 | |
2814 | /// draw a line to the surface |
2815 | virtual void draw_line |
2816 | - (int32_t x1, int32_t y1, int32_t x2, int32_t y2, const RGBColor& color, uint8_t width = 1) = 0; |
2817 | + (int32_t x1, int32_t y1, int32_t x2, int32_t y2, const RGBColor& color, uint8_t width = 1); |
2818 | |
2819 | /// makes a rectangle on the surface brighter (or darker). |
2820 | /// @note this is slow in SDL mode. Use with care |
2821 | - virtual void brighten_rect(const Rect&, int32_t factor) = 0; |
2822 | + virtual void brighten_rect(const Rect&, int32_t factor); |
2823 | |
2824 | /// The functions below are for direct pixel access. This should be used |
2825 | /// only very sparingly as / it is potentially expensive (especially for |
2826 | @@ -105,7 +100,21 @@ |
2827 | }; |
2828 | |
2829 | /// This returns the pixel format for direct pixel access. |
2830 | - virtual const SDL_PixelFormat & format() const = 0; |
2831 | + const SDL_PixelFormat & format() const; |
2832 | + |
2833 | + /** |
2834 | + * \return Pitch of the raw pixel data, i.e. the number of bytes |
2835 | + * contained in each image row. This can be strictly larger than |
2836 | + * bytes per pixel times the width. |
2837 | + */ |
2838 | + uint16_t get_pitch() const; |
2839 | + |
2840 | + /** |
2841 | + * \return Pointer to the raw pixel data. |
2842 | + * |
2843 | + * \warning May only be called inside lock/unlock pairs. |
2844 | + */ |
2845 | + uint8_t * get_pixels() const; |
2846 | |
2847 | /** |
2848 | * Lock/Unlock pairs must guard any of the direct pixel access using the |
2849 | @@ -113,29 +122,34 @@ |
2850 | * |
2851 | * \note Lock/Unlock pairs cannot be nested. |
2852 | */ |
2853 | - //@{ |
2854 | virtual void lock(LockMode) = 0; |
2855 | virtual void unlock(UnlockMode) = 0; |
2856 | - //@} |
2857 | - |
2858 | - //@{ |
2859 | - virtual uint32_t get_pixel(uint16_t x, uint16_t y) = 0; |
2860 | - virtual void set_pixel(uint16_t x, uint16_t y, uint32_t clr) = 0; |
2861 | - //@} |
2862 | - |
2863 | - /** |
2864 | - * \return Pitch of the raw pixel data, i.e. the number of bytes |
2865 | - * contained in each image row. This can be strictly larger than |
2866 | - * bytes per pixel times the width. |
2867 | - */ |
2868 | - virtual uint16_t get_pitch() const = 0; |
2869 | - |
2870 | - /** |
2871 | - * \return Pointer to the raw pixel data. |
2872 | - * |
2873 | - * \warning May only be called inside lock/unlock pairs. |
2874 | - */ |
2875 | - virtual uint8_t * get_pixels() const = 0; |
2876 | + |
2877 | + uint32_t get_pixel(uint16_t x, uint16_t y); |
2878 | + void set_pixel(uint16_t x, uint16_t y, uint32_t clr); |
2879 | + |
2880 | + // Converts the given pixel into an OpenGl point. This might |
2881 | + // need some flipping of axis, depending if you want to render |
2882 | + // on the screen or not. |
2883 | + virtual void pixel_to_gl(float* x, float* y) const = 0; |
2884 | + |
2885 | +protected: |
2886 | + // Convert the 'rect' in pixel space into opengl space. |
2887 | + enum class ConversionMode { |
2888 | + // Convert the rect as given. |
2889 | + kExact, |
2890 | + |
2891 | + // Convert the rect so that the borders are in the center |
2892 | + // of the pixels. |
2893 | + kMidPoint, |
2894 | + }; |
2895 | + FloatRect to_opengl(const Rect& rect, ConversionMode mode); |
2896 | + |
2897 | + /// Logical width and height of the surface |
2898 | + uint16_t m_w, m_h; |
2899 | + |
2900 | + /// Pixel data, while the texture is locked |
2901 | + std::unique_ptr<uint8_t[]> m_pixels; |
2902 | |
2903 | private: |
2904 | DISALLOW_COPY_AND_ASSIGN(Surface); |
2905 | |
2906 | === modified file 'src/graphic/text/CMakeLists.txt' |
2907 | --- src/graphic/text/CMakeLists.txt 2014-10-13 15:04:50 +0000 |
2908 | +++ src/graphic/text/CMakeLists.txt 2014-11-23 12:03:00 +0000 |
2909 | @@ -18,6 +18,7 @@ |
2910 | USES_SDL2_TTF |
2911 | USES_SDL2_GFX |
2912 | DEPENDS |
2913 | + graphic_sdl_utils |
2914 | base_exceptions |
2915 | base_geometry |
2916 | graphic_color |
2917 | |
2918 | === modified file 'src/graphic/text/sdl_ttf_font.cc' |
2919 | --- src/graphic/text/sdl_ttf_font.cc 2014-11-02 20:15:01 +0000 |
2920 | +++ src/graphic/text/sdl_ttf_font.cc 2014-11-23 12:03:00 +0000 |
2921 | @@ -23,7 +23,7 @@ |
2922 | #include <SDL_ttf.h> |
2923 | #include <boost/format.hpp> |
2924 | |
2925 | -#include "graphic/sdl/utils.h" |
2926 | +#include "graphic/sdl_utils.h" |
2927 | #include "graphic/surface.h" |
2928 | #include "graphic/surface_cache.h" |
2929 | #include "graphic/text/rt_errors.h" |
2930 | |
2931 | === modified file 'src/graphic/text/test/CMakeLists.txt' |
2932 | --- src/graphic/text/test/CMakeLists.txt 2014-07-17 14:34:32 +0000 |
2933 | +++ src/graphic/text/test/CMakeLists.txt 2014-11-23 12:03:00 +0000 |
2934 | @@ -7,6 +7,7 @@ |
2935 | render_richtext.cc |
2936 | DEPENDS |
2937 | base_log |
2938 | + graphic |
2939 | graphic_image_io |
2940 | graphic_surface |
2941 | graphic_text |
2942 | |
2943 | === modified file 'src/graphic/text/test/render_richtext.cc' |
2944 | --- src/graphic/text/test/render_richtext.cc 2014-10-11 13:26:59 +0000 |
2945 | +++ src/graphic/text/test/render_richtext.cc 2014-11-23 12:03:00 +0000 |
2946 | @@ -30,11 +30,14 @@ |
2947 | #undef main // No, we do not want SDL_main |
2948 | |
2949 | #include "base/log.h" |
2950 | +#include "config.h" |
2951 | +#include "graphic/graphic.h" |
2952 | #include "graphic/image_io.h" |
2953 | -#include "graphic/sdl/surface.h" |
2954 | +#include "graphic/surface.h" |
2955 | #include "graphic/text/rt_errors.h" |
2956 | #include "graphic/text/test/render.h" |
2957 | #include "io/filesystem/filesystem.h" |
2958 | +#include "io/filesystem/layered_filesystem.h" |
2959 | #include "io/streamwrite.h" |
2960 | |
2961 | namespace { |
2962 | @@ -88,6 +91,17 @@ |
2963 | return 0; |
2964 | } |
2965 | |
2966 | +// Setup the static objects Widelands needs to operate and initializes systems. |
2967 | +void initialize() { |
2968 | + SDL_Init(SDL_INIT_VIDEO); |
2969 | + |
2970 | + g_fs = new LayeredFileSystem(); |
2971 | + g_fs->add_file_system(&FileSystem::create(INSTALL_DATADIR)); |
2972 | + |
2973 | + g_gr = new Graphic(); |
2974 | + g_gr->initialize(1, 1, false); |
2975 | +} |
2976 | + |
2977 | } // namespace |
2978 | |
2979 | int main(int argc, char** argv) { |
2980 | @@ -117,19 +131,19 @@ |
2981 | return 1; |
2982 | } |
2983 | |
2984 | + initialize(); |
2985 | + |
2986 | StandaloneRenderer standalone_renderer; |
2987 | |
2988 | try { |
2989 | - std::unique_ptr<SDLSurface> surf( |
2990 | - static_cast<SDLSurface*>(standalone_renderer.renderer()->render(txt, w, allowed_tags))); |
2991 | + std::unique_ptr<Surface> surf(standalone_renderer.renderer()->render(txt, w, allowed_tags)); |
2992 | |
2993 | std::unique_ptr<FileSystem> fs(&FileSystem::create(".")); |
2994 | std::unique_ptr<StreamWrite> sw(fs->open_stream_write(outname)); |
2995 | if (!save_surface_to_png(surf.get(), sw.get())) { |
2996 | std::cout << "Could not encode PNG." << std::endl; |
2997 | } |
2998 | - } |
2999 | - catch (RT::Exception& e) { |
3000 | + } catch (RT::Exception& e) { |
3001 | std::cout << e.what() << std::endl; |
3002 | } |
3003 | |
3004 | |
3005 | === modified file 'src/graphic/texture.cc' |
3006 | --- src/graphic/texture.cc 2014-09-20 09:37:47 +0000 |
3007 | +++ src/graphic/texture.cc 2014-11-23 12:03:00 +0000 |
3008 | @@ -28,8 +28,6 @@ |
3009 | #include "io/fileread.h" |
3010 | #include "io/filesystem/layered_filesystem.h" |
3011 | |
3012 | -extern bool g_opengl; |
3013 | - |
3014 | using namespace std; |
3015 | |
3016 | /** |
3017 | @@ -37,15 +35,8 @@ |
3018 | * Currently it converts a 16 bit image to a 8 bit texture. This should |
3019 | * be changed to load a 8 bit file directly, however. |
3020 | */ |
3021 | -Texture::Texture(const std::vector<std::string>& texture_files, |
3022 | - const uint32_t frametime, |
3023 | - const SDL_PixelFormat& format) |
3024 | - : m_colormap(nullptr), |
3025 | - m_pixels(nullptr), |
3026 | - m_curframe(nullptr), |
3027 | - m_frame_num(0), |
3028 | - m_nrframes(0), |
3029 | - m_frametime(frametime) { |
3030 | +Texture::Texture(const std::vector<std::string>& texture_files, const uint32_t frametime) |
3031 | + : m_frame_num(0), m_frametime(frametime) { |
3032 | if (texture_files.empty()) { |
3033 | throw wexception("No images for texture."); |
3034 | } |
3035 | @@ -58,7 +49,8 @@ |
3036 | m_texture_image = fname; |
3037 | SDL_Surface* surf = load_image_as_sdl_surface(fname, g_fs); |
3038 | if (!surf) { |
3039 | - throw wexception("WARNING: Failed to load texture frame %s: %s\n", fname.c_str(), IMG_GetError()); |
3040 | + throw wexception( |
3041 | + "WARNING: Failed to load texture frame %s: %s\n", fname.c_str(), IMG_GetError()); |
3042 | } |
3043 | if (surf->w != TEXTURE_WIDTH || surf->h != TEXTURE_HEIGHT) { |
3044 | SDL_FreeSurface(surf); |
3045 | @@ -69,7 +61,7 @@ |
3046 | } |
3047 | |
3048 | // calculate shades on the first frame |
3049 | - if (!m_nrframes) { |
3050 | + if (m_gl_textures.empty()) { |
3051 | uint8_t top_left_pixel = static_cast<uint8_t*>(surf->pixels)[0]; |
3052 | SDL_Color top_left_pixel_color = surf->format->palette->colors[top_left_pixel]; |
3053 | for (int i = -128; i < 128; i++) { |
3054 | @@ -80,73 +72,13 @@ |
3055 | m_minimap_colors[shade] = RGBColor(r, g, b); |
3056 | } |
3057 | } |
3058 | - |
3059 | - if (g_opengl) { |
3060 | - // Note: we except the constructor to free the SDL surface |
3061 | - GLSurfaceTexture* surface = new GLSurfaceTexture(surf); |
3062 | - m_glFrames.emplace_back(surface); |
3063 | - |
3064 | - ++m_nrframes; |
3065 | - continue; |
3066 | - } |
3067 | - |
3068 | - // Determine color map if it's the first frame |
3069 | - if (!m_nrframes) { |
3070 | - if (surf->format->BitsPerPixel != 8) { |
3071 | - throw wexception("Terrain %s is not 8 bits per pixel.", fname.c_str()); |
3072 | - } |
3073 | - m_colormap.reset(new Colormap(*surf->format->palette->colors, format)); |
3074 | - } |
3075 | - |
3076 | - // Convert to our palette |
3077 | - SDL_Palette palette; |
3078 | - SDL_PixelFormat fmt; |
3079 | - |
3080 | - palette.ncolors = 256; |
3081 | - palette.colors = m_colormap->get_palette(); |
3082 | - |
3083 | - memset(&fmt, 0, sizeof(fmt)); |
3084 | - fmt.BitsPerPixel = 8; |
3085 | - fmt.BytesPerPixel = 1; |
3086 | - fmt.palette = &palette; |
3087 | - |
3088 | - SDL_Surface * const cv = SDL_ConvertSurface(surf, &fmt, 0); |
3089 | - |
3090 | - // Add the frame |
3091 | - uint8_t* new_ptr = |
3092 | - static_cast<uint8_t *> |
3093 | - (realloc |
3094 | - (m_pixels, TEXTURE_WIDTH * TEXTURE_HEIGHT * (m_nrframes + 1))); |
3095 | - if (!new_ptr) |
3096 | - throw wexception("Out of memory."); |
3097 | - m_pixels = new_ptr; |
3098 | - |
3099 | - |
3100 | - m_curframe = &m_pixels[TEXTURE_WIDTH * TEXTURE_HEIGHT * m_nrframes]; |
3101 | - ++m_nrframes; |
3102 | - |
3103 | - SDL_LockSurface(cv); |
3104 | - |
3105 | - for (int32_t y = 0; y < TEXTURE_HEIGHT; ++y) |
3106 | - memcpy |
3107 | - (m_curframe + y * TEXTURE_WIDTH, |
3108 | - static_cast<uint8_t *>(cv->pixels) + y * cv->pitch, |
3109 | - TEXTURE_WIDTH); |
3110 | - SDL_UnlockSurface(cv); |
3111 | - SDL_FreeSurface(cv); |
3112 | - SDL_FreeSurface(surf); |
3113 | + m_gl_textures.emplace_back(new GLSurfaceTexture(surf)); |
3114 | } |
3115 | |
3116 | - if (!m_nrframes) |
3117 | + if (m_gl_textures.empty()) |
3118 | throw wexception("Texture has no frames"); |
3119 | } |
3120 | |
3121 | - |
3122 | -Texture::~Texture () |
3123 | -{ |
3124 | - free(m_pixels); |
3125 | -} |
3126 | - |
3127 | /** |
3128 | * Return the basic terrain colour to be used in the minimap. |
3129 | */ |
3130 | @@ -159,8 +91,5 @@ |
3131 | */ |
3132 | void Texture::animate(uint32_t time) |
3133 | { |
3134 | - m_frame_num = (time / m_frametime) % m_nrframes; |
3135 | - if (g_opengl) |
3136 | - return; |
3137 | - m_curframe = &m_pixels[TEXTURE_WIDTH * TEXTURE_HEIGHT * m_frame_num]; |
3138 | + m_frame_num = (time / m_frametime) % m_gl_textures.size(); |
3139 | } |
3140 | |
3141 | === modified file 'src/graphic/texture.h' |
3142 | --- src/graphic/texture.h 2014-10-11 13:26:59 +0000 |
3143 | +++ src/graphic/texture.h 2014-11-23 12:03:00 +0000 |
3144 | @@ -45,33 +45,25 @@ |
3145 | * changed to load 8 bit bitmaps directly. |
3146 | */ |
3147 | struct Texture { |
3148 | - Texture(const std::vector<std::string>& texture_files, |
3149 | - uint32_t frametime, |
3150 | - const SDL_PixelFormat&); |
3151 | - ~Texture(); |
3152 | - |
3153 | - const std::string & get_texture_image() const {return m_texture_image;} |
3154 | - |
3155 | - uint8_t * get_pixels () const {return m_pixels;} |
3156 | - uint8_t * get_curpixels() const {return m_curframe;} |
3157 | - void * get_colormap () const {return m_colormap->get_colormap();} |
3158 | + Texture(const std::vector<std::string>& texture_files, uint32_t frametime); |
3159 | + |
3160 | + const std::string& get_texture_image() const { |
3161 | + return m_texture_image; |
3162 | + } |
3163 | + uint32_t get_texture() const { |
3164 | + return m_gl_textures.at(m_frame_num)->get_gl_texture(); |
3165 | + } |
3166 | |
3167 | RGBColor get_minimap_color(int8_t shade); |
3168 | |
3169 | void animate(uint32_t time); |
3170 | - uint32_t get_texture() const |
3171 | - {return m_glFrames.at(m_frame_num)->get_gl_texture();} |
3172 | |
3173 | private: |
3174 | - std::unique_ptr<Colormap> m_colormap; |
3175 | - uint8_t * m_pixels; |
3176 | RGBColor m_minimap_colors[256]; |
3177 | - uint8_t * m_curframe; |
3178 | int32_t m_frame_num; |
3179 | std::string m_texture_image; |
3180 | - uint32_t m_nrframes; |
3181 | uint32_t m_frametime; |
3182 | - std::vector<std::unique_ptr<GLSurfaceTexture>> m_glFrames; |
3183 | + std::vector<std::unique_ptr<GLSurfaceTexture>> m_gl_textures; |
3184 | }; |
3185 | |
3186 | #endif // end of include guard: WL_GRAPHIC_TEXTURE_H |
3187 | |
3188 | === modified file 'src/logic/map_info.cc' |
3189 | --- src/logic/map_info.cc 2014-11-12 20:12:48 +0000 |
3190 | +++ src/logic/map_info.cc 2014-11-23 12:03:00 +0000 |
3191 | @@ -43,19 +43,14 @@ |
3192 | namespace { |
3193 | |
3194 | // Setup the static objects Widelands needs to operate and initializes systems. |
3195 | -void initialize(bool use_opengl) { |
3196 | +void initialize() { |
3197 | SDL_Init(SDL_INIT_VIDEO); |
3198 | |
3199 | g_fs = new LayeredFileSystem(); |
3200 | g_fs->add_file_system(&FileSystem::create(INSTALL_DATADIR)); |
3201 | |
3202 | -#ifdef HAS_GETENV |
3203 | - char dummy_video_env[] = "SDL_VIDEODRIVER=dummy"; |
3204 | - putenv(dummy_video_env); |
3205 | -#endif |
3206 | - |
3207 | g_gr = new Graphic(); |
3208 | - g_gr->initialize(1, 1, false, use_opengl); |
3209 | + g_gr->initialize(1, 1, false); |
3210 | } |
3211 | |
3212 | } // namespace |
3213 | @@ -63,21 +58,14 @@ |
3214 | int main(int argc, char ** argv) |
3215 | { |
3216 | if (!(2 <= argc && argc <= 3)) { |
3217 | - log("Usage: %s [--opengl] <map file>\n", argv[0]); |
3218 | + log("Usage: %s <map file>\n", argv[0]); |
3219 | return 1; |
3220 | } |
3221 | |
3222 | - bool use_opengl = false; |
3223 | - for (int i = 0; i < argc; ++i) { |
3224 | - if (std::string(argv[i]) == "--opengl") { |
3225 | - use_opengl = true; |
3226 | - } |
3227 | - } |
3228 | - |
3229 | const std::string map_path = argv[argc - 1]; |
3230 | |
3231 | try { |
3232 | - initialize(use_opengl); |
3233 | + initialize(); |
3234 | |
3235 | std::string map_dir = FileSystem::fs_dirname(map_path); |
3236 | if (map_dir.empty()) { |
3237 | |
3238 | === modified file 'src/ui_fsmenu/options.cc' |
3239 | --- src/ui_fsmenu/options.cc 2014-11-22 22:11:36 +0000 |
3240 | +++ src/ui_fsmenu/options.cc 2014-11-23 12:03:00 +0000 |
3241 | @@ -555,14 +555,6 @@ |
3242 | get_w() - 2 * m_hmargin - m_remove_syncstreams.get_w() - m_padding, 40, |
3243 | _("Remove Syncstream dumps on startup"), UI::Align_VCenter), |
3244 | |
3245 | - m_opengl (this, Point(m_hmargin, |
3246 | - m_label_remove_syncstreams.get_y() + |
3247 | - m_label_remove_syncstreams.get_h() + m_padding)), |
3248 | - m_label_opengl |
3249 | - (this, |
3250 | - m_hmargin + m_opengl.get_w() + m_padding, m_opengl.get_y(), |
3251 | - get_w() - 2 * m_hmargin - m_opengl.get_w() - m_padding, 40, |
3252 | - _("OpenGL rendering"), UI::Align_VCenter), |
3253 | os(opt) |
3254 | { |
3255 | for (UI::Button* temp_button : m_sb_dis_panel.get_buttons()) { |
3256 | @@ -594,7 +586,6 @@ |
3257 | m_message_sound .set_state(opt.message_sound); |
3258 | m_nozip .set_state(opt.nozip); |
3259 | m_remove_syncstreams .set_state(opt.remove_syncstreams); |
3260 | - m_opengl .set_state(opt.opengl); |
3261 | m_transparent_chat .set_state(opt.transparent_chat); |
3262 | |
3263 | // Fill the font list. |
3264 | @@ -678,7 +669,6 @@ |
3265 | os.panel_snap_distance = m_sb_dis_panel.get_value(); |
3266 | os.border_snap_distance = m_sb_dis_border.get_value(); |
3267 | os.remove_syncstreams = m_remove_syncstreams.get_state(); |
3268 | - os.opengl = m_opengl.get_state(); |
3269 | os.transparent_chat = m_transparent_chat.get_state(); |
3270 | return os; |
3271 | } |
3272 | @@ -734,7 +724,6 @@ |
3273 | opt.panel_snap_distance = m_opt_section.get_int("panel_snap_distance", 0); |
3274 | opt.remove_replays = m_opt_section.get_int("remove_replays", 0); |
3275 | opt.remove_syncstreams = m_opt_section.get_bool("remove_syncstreams", true); |
3276 | - opt.opengl = m_opt_section.get_bool("opengl", true); |
3277 | opt.transparent_chat = m_opt_section.get_bool("transparent_chat", true); |
3278 | return opt; |
3279 | } |
3280 | @@ -766,7 +755,6 @@ |
3281 | |
3282 | m_opt_section.set_int("remove_replays", opt.remove_replays); |
3283 | m_opt_section.set_bool("remove_syncstreams", opt.remove_syncstreams); |
3284 | - m_opt_section.set_bool("opengl", opt.opengl); |
3285 | m_opt_section.set_bool("transparent_chat", opt.transparent_chat); |
3286 | |
3287 | WLApplication::get()->set_input_grab(opt.inputgrab); |
3288 | |
3289 | === modified file 'src/ui_fsmenu/options.h' |
3290 | --- src/ui_fsmenu/options.h 2014-10-14 06:30:20 +0000 |
3291 | +++ src/ui_fsmenu/options.h 2014-11-23 12:03:00 +0000 |
3292 | @@ -54,7 +54,6 @@ |
3293 | uint32_t maxfps; |
3294 | uint32_t remove_replays; |
3295 | bool remove_syncstreams; |
3296 | - bool opengl; |
3297 | bool transparent_chat; |
3298 | |
3299 | // advanced options |
3300 | @@ -197,8 +196,6 @@ |
3301 | UI::MultilineTextarea m_label_nozip; |
3302 | UI::Checkbox m_remove_syncstreams; |
3303 | UI::MultilineTextarea m_label_remove_syncstreams; |
3304 | - UI::Checkbox m_opengl; |
3305 | - UI::MultilineTextarea m_label_opengl; |
3306 | |
3307 | OptionsCtrl::OptionsStruct os; |
3308 | }; |
3309 | |
3310 | === modified file 'src/wlapplication.cc' |
3311 | --- src/wlapplication.cc 2014-11-22 10:18:20 +0000 |
3312 | +++ src/wlapplication.cc 2014-11-23 12:03:00 +0000 |
3313 | @@ -676,7 +676,7 @@ |
3314 | * with the given resolution. |
3315 | * Throws an exception on failure. |
3316 | */ |
3317 | -void WLApplication::init_graphics(int32_t w, int32_t h, bool fullscreen, bool opengl) |
3318 | +void WLApplication::init_graphics(int32_t w, int32_t h, bool fullscreen) |
3319 | { |
3320 | if (!w && !h) { // shutdown. |
3321 | delete g_gr; |
3322 | @@ -687,13 +687,10 @@ |
3323 | |
3324 | if (!g_gr) { |
3325 | g_gr = new Graphic(); |
3326 | - g_gr->initialize(w, h, fullscreen, opengl); |
3327 | + g_gr->initialize(w, h, fullscreen); |
3328 | } else { |
3329 | - if |
3330 | - (g_gr->get_xres() != w || g_gr->get_yres() != h |
3331 | - || g_gr->is_fullscreen() != fullscreen || g_opengl != opengl) |
3332 | - { |
3333 | - g_gr->initialize(w, h, fullscreen, opengl); |
3334 | + if (g_gr->get_xres() != w || g_gr->get_yres() != h || g_gr->is_fullscreen() != fullscreen) { |
3335 | + g_gr->initialize(w, h, fullscreen); |
3336 | } |
3337 | } |
3338 | } |
3339 | @@ -703,11 +700,9 @@ |
3340 | Section & s = g_options.pull_section("global"); |
3341 | |
3342 | // Switch to the new graphics system now, if necessary. |
3343 | - init_graphics |
3344 | - (s.get_int("xres", DEFAULT_RESOLUTION_W), |
3345 | - s.get_int("yres", DEFAULT_RESOLUTION_H), |
3346 | - s.get_bool("fullscreen", false), |
3347 | - s.get_bool("opengl", true)); |
3348 | + init_graphics(s.get_int("xres", DEFAULT_RESOLUTION_W), |
3349 | + s.get_int("yres", DEFAULT_RESOLUTION_H), |
3350 | + s.get_bool("fullscreen", false)); |
3351 | // does only work with a window |
3352 | set_input_grab(s.get_bool("inputgrab", false)); |
3353 | } |
3354 | @@ -732,7 +727,6 @@ |
3355 | // Profile needs support for a Syntax definition to solve this in a |
3356 | // sensible way |
3357 | s.get_bool("fullscreen"); |
3358 | - s.get_bool("opengl"); |
3359 | s.get_int("xres"); |
3360 | s.get_int("yres"); |
3361 | s.get_int("border_snap_distance"); |
3362 | @@ -851,7 +845,7 @@ |
3363 | "alive!" |
3364 | << std::endl; |
3365 | |
3366 | - init_graphics(0, 0, false, false); |
3367 | + init_graphics(0, 0, false); |
3368 | SDL_QuitSubSystem(SDL_INIT_TIMER|SDL_INIT_VIDEO|SDL_INIT_JOYSTICK); |
3369 | |
3370 | #ifndef _WIN32 |
3371 | |
3372 | === modified file 'src/wlapplication.h' |
3373 | --- src/wlapplication.h 2014-11-22 10:18:20 +0000 |
3374 | +++ src/wlapplication.h 2014-11-23 12:03:00 +0000 |
3375 | @@ -164,7 +164,7 @@ |
3376 | void set_mouse_lock(const bool locked) {m_mouse_locked = locked;} |
3377 | //@} |
3378 | |
3379 | - void init_graphics(int32_t w, int32_t h, bool fullscreen, bool opengl); |
3380 | + void init_graphics(int32_t w, int32_t h, bool fullscreen); |
3381 | |
3382 | /** |
3383 | * Refresh the graphics from the latest options. |
3384 | |
3385 | === modified file 'src/wlapplication_messages.cc' |
3386 | --- src/wlapplication_messages.cc 2014-11-03 19:51:45 +0000 |
3387 | +++ src/wlapplication_messages.cc 2014-11-23 12:03:00 +0000 |
3388 | @@ -99,8 +99,7 @@ |
3389 | << _(" --yres=[...] Height of the window in pixel.") << endl |
3390 | /** TRANSLATORS: You may translate true/false, also as on/off or yes/no, but */ |
3391 | /** TRANSLATORS: it HAS TO BE CONSISTENT with the translation in the widelands textdomain */ |
3392 | - << _(" --opengl=[true|false]\n" |
3393 | - " Enables OpenGL rendering") << endl << endl |
3394 | + << endl |
3395 | << _("Options for the internal window manager:") << endl |
3396 | << _(" --border_snap_distance=[0 ...]\n" |
3397 | " Move a window to the edge of the screen\n" |
3398 | |
3399 | === modified file 'src/wui/mapview.cc' |
3400 | --- src/wui/mapview.cc 2014-11-13 08:25:45 +0000 |
3401 | +++ src/wui/mapview.cc 2014-11-23 12:03:00 +0000 |
3402 | @@ -23,7 +23,6 @@ |
3403 | #include "graphic/gl/game_renderer.h" |
3404 | #include "graphic/graphic.h" |
3405 | #include "graphic/rendertarget.h" |
3406 | -#include "graphic/sdl/game_renderer.h" |
3407 | #include "logic/map.h" |
3408 | #include "logic/player.h" |
3409 | #include "wlapplication.h" |
3410 | @@ -92,12 +91,7 @@ |
3411 | egbase.map().overlay_manager().load_graphics(); |
3412 | |
3413 | if (!m_renderer) { |
3414 | - if (g_opengl) { |
3415 | - m_renderer.reset(new GlGameRenderer()); |
3416 | - } else |
3417 | - { |
3418 | - m_renderer.reset(new SdlGameRenderer()); |
3419 | - } |
3420 | + m_renderer.reset(new GlGameRenderer()); |
3421 | } |
3422 | if (upcast(InteractivePlayer const, interactive_player, &intbase())) { |
3423 | m_renderer->rendermap(dst, egbase, interactive_player->player(), m_viewpoint); |
You inherited a strange comment in line 3112 that you might want to fix as well.
Otherwise, LGTM and tested.