Merge lp:~widelands-dev/widelands/move_road_texture_out_of_graphics into lp:widelands

Proposed by SirVer
Status: Merged
Merged at revision: 7278
Proposed branch: lp:~widelands-dev/widelands/move_road_texture_out_of_graphics
Merge into: lp:widelands
Prerequisite: lp:~widelands-dev/widelands/fix_some_resizing_bugs
Diff against target: 3118 lines (+545/-547)
59 files modified
src/editor/ui_menus/editor_tool_set_terrain_options_menu.cc (+11/-11)
src/game_io/CMakeLists.txt (+0/-1)
src/game_io/game_preload_packet.cc (+0/-1)
src/graphic/CMakeLists.txt (+14/-13)
src/graphic/animation.cc (+2/-2)
src/graphic/blend_mode.h (+12/-18)
src/graphic/font_handler.cc (+2/-2)
src/graphic/font_handler1.cc (+17/-17)
src/graphic/gl/blit_program.cc (+3/-3)
src/graphic/gl/blit_program.h (+3/-3)
src/graphic/gl/dither_program.cc (+11/-19)
src/graphic/gl/dither_program.h (+8/-0)
src/graphic/gl/game_renderer.cc (+3/-3)
src/graphic/gl/road_program.cc (+9/-7)
src/graphic/gl/road_program.h (+9/-1)
src/graphic/gl/terrain_program.cc (+5/-3)
src/graphic/graphic.cc (+12/-23)
src/graphic/graphic.h (+13/-19)
src/graphic/image.h (+3/-3)
src/graphic/image_cache.cc (+18/-18)
src/graphic/image_cache.h (+3/-3)
src/graphic/image_io.cc (+3/-3)
src/graphic/image_io.h (+2/-2)
src/graphic/image_transformations.cc (+90/-88)
src/graphic/in_memory_image.cc (+11/-11)
src/graphic/in_memory_image.h (+2/-2)
src/graphic/minimap_renderer.cc (+22/-22)
src/graphic/minimap_renderer.h (+3/-3)
src/graphic/rendertarget.cc (+6/-6)
src/graphic/rendertarget.h (+15/-4)
src/graphic/screen.cc (+6/-6)
src/graphic/screen.h (+6/-6)
src/graphic/surface.cc (+3/-13)
src/graphic/surface.h (+8/-10)
src/graphic/terrain_texture.cc (+26/-23)
src/graphic/terrain_texture.h (+24/-31)
src/graphic/text/rt_render.cc (+35/-35)
src/graphic/text/rt_render.h (+7/-6)
src/graphic/text/sdl_ttf_font.cc (+6/-6)
src/graphic/text/sdl_ttf_font.h (+1/-1)
src/graphic/text/test/render.cc (+4/-4)
src/graphic/text/test/render.h (+1/-1)
src/graphic/text/test/render_richtext.cc (+4/-3)
src/graphic/texture.cc (+15/-15)
src/graphic/texture.h (+17/-9)
src/graphic/texture_cache.cc (+27/-28)
src/graphic/texture_cache.h (+12/-12)
src/logic/building.cc (+2/-2)
src/logic/immovable.cc (+5/-2)
src/logic/map_info.cc (+3/-2)
src/map_io/map_extradata_packet.cc (+2/-2)
src/map_io/map_saver.cc (+2/-2)
src/ui_basic/progressbar.cc (+1/-1)
src/ui_basic/window.cc (+1/-1)
src/ui_fsmenu/loadgame.cc (+4/-4)
src/wui/buildingwindow.cc (+1/-1)
src/wui/interactive_base.cc (+3/-3)
src/wui/minimap.cc (+4/-4)
src/wui/plot_area.cc (+3/-3)
To merge this branch: bzr merge lp:~widelands-dev/widelands/move_road_texture_out_of_graphics
Reviewer Review Type Date Requested Status
Tino Approve
Review via email: mp+242627@code.launchpad.net

Description of the change

A bunch of cleanups and clarifications. This contains https://code.launchpad.net/~widelands-dev/widelands/fix_some_resizing_bugs (the diff should be against this branch) and should not be merged before the other one is.

Suggested commit message:

- Removes a lot of dynamic_casts from Surface to Texture.
- Ownership of dither texture and road textures are now only with the respective OpenGL programs. This cleans up class Graphic.
- Renamed Texture to TerrainTexture - I expect this will go away soon too.
- Renamed GLSurfaceScreen to Screen.
- Renamed GLSurfaceTexture to Texture.
- Renamed SurfaceCache to TextureCache.
- Renamed Composite to BlendMode.

To post a comment you must log in.
Revision history for this message
Tino (tino79) wrote :

Again: It does compile with mingw and a quick visual check revealed no graphical errors on my system.

Revision history for this message
Tino (tino79) :
review: Approve

Preview Diff

[H/L] Next/Prev Comment, [J/K] Next/Prev File, [N/P] Next/Prev Hunk
1=== modified file 'src/editor/ui_menus/editor_tool_set_terrain_options_menu.cc'
2--- src/editor/ui_menus/editor_tool_set_terrain_options_menu.cc 2014-11-02 20:31:40 +0000
3+++ src/editor/ui_menus/editor_tool_set_terrain_options_menu.cc 2014-11-24 07:32:35 +0000
4@@ -30,7 +30,7 @@
5 #include "graphic/graphic.h"
6 #include "graphic/in_memory_image.h"
7 #include "graphic/rendertarget.h"
8-#include "graphic/surface.h"
9+#include "graphic/terrain_texture.h"
10 #include "graphic/texture.h"
11 #include "logic/map.h"
12 #include "logic/world/editor_category.h"
13@@ -77,50 +77,50 @@
14
15 const Image* tex = g_gr->images().get(
16 g_gr->get_maptexture_data(terrain_descr.get_texture())->get_texture_image());
17- Surface* surf = Surface::create(tex->width(), tex->height());
18- surf->blit(Point(0, 0), tex->surface(), Rect(0, 0, tex->width(), tex->height()), CM_Copy);
19+ Texture* texture = new Texture(tex->width(), tex->height());
20+ texture->blit(Point(0, 0), tex->texture(), Rect(0, 0, tex->width(), tex->height()), BlendMode::Copy);
21 Point pt(1, tex->height() - kSmallPicHeight - 1);
22
23 if (ter_is == TerrainDescription::GREEN) {
24- surf->blit(pt, green->surface(), Rect(0, 0, green->width(), green->height()));
25+ texture->blit(pt, green->texture(), Rect(0, 0, green->width(), green->height()));
26 pt.x += kSmallPicWidth + 1;
27 /** TRANSLATORS: This is a terrain type tooltip in the editor */
28 tooltips.push_back(_("arable"));
29 } else {
30 if (ter_is & TerrainDescription::WATER) {
31- surf->blit(pt, water->surface(), Rect(0, 0, water->width(), water->height()));
32+ texture->blit(pt, water->texture(), Rect(0, 0, water->width(), water->height()));
33 pt.x += kSmallPicWidth + 1;
34 /** TRANSLATORS: This is a terrain type tooltip in the editor */
35 tooltips.push_back(_("aquatic"));
36 }
37 else if (ter_is & TerrainDescription::MOUNTAIN) {
38- surf->blit(pt, mountain->surface(), Rect(0, 0, mountain->width(), mountain->height()));
39+ texture->blit(pt, mountain->texture(), Rect(0, 0, mountain->width(), mountain->height()));
40 pt.x += kSmallPicWidth + 1;
41 /** TRANSLATORS: This is a terrain type tooltip in the editor */
42 tooltips.push_back(_("mountainous"));
43 }
44 if (ter_is & TerrainDescription::ACID) {
45- surf->blit(pt, dead->surface(), Rect(0, 0, dead->width(), dead->height()));
46+ texture->blit(pt, dead->texture(), Rect(0, 0, dead->width(), dead->height()));
47 pt.x += kSmallPicWidth + 1;
48 /** TRANSLATORS: This is a terrain type tooltip in the editor */
49 tooltips.push_back(_("dead"));
50 }
51 if (ter_is & TerrainDescription::UNPASSABLE) {
52- surf->blit(
53- pt, unpassable->surface(), Rect(0, 0, unpassable->width(), unpassable->height()));
54+ texture->blit(
55+ pt, unpassable->texture(), Rect(0, 0, unpassable->width(), unpassable->height()));
56 pt.x += kSmallPicWidth + 1;
57 /** TRANSLATORS: This is a terrain type tooltip in the editor */
58 tooltips.push_back(_("unpassable"));
59 }
60 if (ter_is & TerrainDescription::DRY) {
61- surf->blit(pt, dry->surface(), Rect(0, 0, dry->width(), dry->height()));
62+ texture->blit(pt, dry->texture(), Rect(0, 0, dry->width(), dry->height()));
63 /** TRANSLATORS: This is a terrain type tooltip in the editor */
64 tooltips.push_back(_("treeless"));
65 }
66 }
67
68 // Make sure we delete this later on.
69- offscreen_images->emplace_back(new_in_memory_image("dummy_hash", surf));
70+ offscreen_images->emplace_back(new_in_memory_image("dummy_hash", texture));
71 break;
72 }
73 /** TRANSLATORS: %1% = terrain name, %2% = list of terrain types */
74
75=== modified file 'src/game_io/CMakeLists.txt'
76--- src/game_io/CMakeLists.txt 2014-10-11 16:08:10 +0000
77+++ src/game_io/CMakeLists.txt 2014-11-24 07:32:35 +0000
78@@ -27,7 +27,6 @@
79 base_time_string
80 economy
81 graphic
82- graphic_surface
83 io_fileread
84 io_filesystem
85 logic
86
87=== modified file 'src/game_io/game_preload_packet.cc'
88--- src/game_io/game_preload_packet.cc 2014-11-01 18:24:28 +0000
89+++ src/game_io/game_preload_packet.cc 2014-11-24 07:32:35 +0000
90@@ -28,7 +28,6 @@
91 #include "graphic/graphic.h"
92 #include "graphic/in_memory_image.h"
93 #include "graphic/minimap_renderer.h"
94-#include "graphic/surface.h"
95 #include "logic/game.h"
96 #include "logic/game_data_error.h"
97 #include "logic/map.h"
98
99=== modified file 'src/graphic/CMakeLists.txt'
100--- src/graphic/CMakeLists.txt 2014-11-23 10:13:14 +0000
101+++ src/graphic/CMakeLists.txt 2014-11-24 07:32:35 +0000
102@@ -45,17 +45,17 @@
103
104 wl_library(graphic_surface
105 SRCS
106- compositemode.h
107- gl/surface_screen.cc
108- gl/surface_screen.h
109- gl/surface_texture.cc
110- gl/surface_texture.h
111+ blend_mode.h
112 gl/utils.cc
113 gl/utils.h
114+ screen.cc
115+ screen.h
116 surface.cc
117 surface.h
118- surface_cache.cc
119- surface_cache.h
120+ texture.cc
121+ texture.h
122+ texture_cache.cc
123+ texture_cache.h
124 USES_OPENGL
125 USES_SDL2
126 DEPENDS
127@@ -90,20 +90,20 @@
128 gl/blit_program.h
129 gl/dither_program.cc
130 gl/dither_program.h
131+ gl/draw_line_program.cc
132+ gl/draw_line_program.h
133 gl/draw_rect_program.cc
134 gl/draw_rect_program.h
135- gl/draw_line_program.cc
136- gl/draw_line_program.h
137+ gl/fields_to_draw.h
138 gl/fill_rect_program.cc
139 gl/fill_rect_program.h
140- gl/fields_to_draw.h
141 gl/game_renderer.cc
142 gl/game_renderer.h
143 gl/road_program.cc
144 gl/road_program.h
145+ gl/system_headers.h
146 gl/terrain_program.cc
147 gl/terrain_program.h
148- gl/system_headers.h
149 graphic.cc
150 graphic.h
151 image_transformations.cc
152@@ -116,10 +116,10 @@
153 rendertarget.h
154 richtext.cc
155 richtext.h
156+ terrain_texture.cc
157+ terrain_texture.h
158 text_parser.cc
159 text_parser.h
160- texture.cc
161- texture.h
162 wordwrap.cc
163 wordwrap.h
164 USES_OPENGL
165@@ -146,6 +146,7 @@
166 io_filesystem
167 io_stream
168 logic
169+ notifications
170 profile
171 scripting
172 sound
173
174=== modified file 'src/graphic/animation.cc'
175--- src/graphic/animation.cc 2014-09-20 09:37:47 +0000
176+++ src/graphic/animation.cc 2014-11-24 07:32:35 +0000
177@@ -41,7 +41,7 @@
178 #include "graphic/image_cache.h"
179 #include "graphic/image_transformations.h"
180 #include "graphic/surface.h"
181-#include "graphic/surface_cache.h"
182+#include "graphic/texture_cache.h"
183 #include "io/filesystem/layered_filesystem.h"
184 #include "logic/bob.h"
185 #include "logic/instances.h"
186@@ -324,7 +324,7 @@
187 assert(target);
188
189 const Image& frame = get_frame(time, clr);
190- target->blit(dst, frame.surface(), srcrc);
191+ target->blit(dst, frame.texture(), srcrc);
192 }
193
194 const Image& NonPackedAnimation::get_frame(uint32_t time, const RGBColor* playercolor) const {
195
196=== renamed file 'src/graphic/compositemode.h' => 'src/graphic/blend_mode.h'
197--- src/graphic/compositemode.h 2014-11-02 14:11:52 +0000
198+++ src/graphic/blend_mode.h 2014-11-24 07:32:35 +0000
199@@ -17,23 +17,17 @@
200 *
201 */
202
203-#ifndef WL_GRAPHIC_COMPOSITEMODE_H
204-#define WL_GRAPHIC_COMPOSITEMODE_H
205-
206-/**
207- * Defines composition operations performed while blitting.
208- */
209-enum Composite {
210- /**
211- * Perform a normal blitting operation that respects the alpha
212- * channel if present.
213- */
214- CM_UseAlpha = 0,
215-
216- /**
217- * Copy all pixel information, including alpha channel information.
218- */
219- CM_Copy
220+#ifndef WL_GRAPHIC_BLEND_MODE_H
221+#define WL_GRAPHIC_BLEND_MODE_H
222+
223+// Defines blending during blitting.
224+enum BlendMode {
225+ // Perform a normal blitting operation that respects the alpha channel if
226+ // present.
227+ UseAlpha = 0,
228+
229+ // Copy all pixel information, including alpha channel information.
230+ Copy
231 };
232
233-#endif // end of include guard: WL_GRAPHIC_COMPOSITEMODE_H
234+#endif // end of include guard: WL_GRAPHIC_BLEND_MODE_H
235
236=== modified file 'src/graphic/font_handler.cc'
237--- src/graphic/font_handler.cc 2014-10-14 06:30:20 +0000
238+++ src/graphic/font_handler.cc 2014-11-24 07:32:35 +0000
239@@ -31,7 +31,7 @@
240 #include "graphic/graphic.h"
241 #include "graphic/in_memory_image.h"
242 #include "graphic/rendertarget.h"
243-#include "graphic/surface.h"
244+#include "graphic/texture.h"
245 #include "graphic/wordwrap.h"
246
247 namespace UI {
248@@ -197,7 +197,7 @@
249 return;
250 }
251
252- lce.image = new_in_memory_image("dummy_hash", Surface::create(text_surface));
253+ lce.image = new_in_memory_image("dummy_hash", new Texture(text_surface));
254 lce.width = lce.image->width();
255 lce.height = lce.image->height();
256 }
257
258=== modified file 'src/graphic/font_handler1.cc'
259--- src/graphic/font_handler1.cc 2014-09-10 14:48:40 +0000
260+++ src/graphic/font_handler1.cc 2014-11-24 07:32:35 +0000
261@@ -29,11 +29,11 @@
262 #include "graphic/image.h"
263 #include "graphic/image_cache.h"
264 #include "graphic/rendertarget.h"
265-#include "graphic/surface.h"
266-#include "graphic/surface_cache.h"
267 #include "graphic/text/rt_errors.h"
268 #include "graphic/text/rt_render.h"
269 #include "graphic/text/sdl_ttf_font.h"
270+#include "graphic/texture.h"
271+#include "graphic/texture_cache.h"
272 #include "io/filesystem/filesystem.h"
273
274
275@@ -42,29 +42,29 @@
276
277 namespace {
278
279-// An Image implementation that recreates a rich text surface when needed on
280+// An Image implementation that recreates a rich text texture when needed on
281 // the fly. It is meant to be saved into the ImageCache.
282 class RTImage : public Image {
283 public:
284 RTImage
285- (const string& ghash, SurfaceCache* surface_cache, RT::Renderer*
286+ (const string& ghash, TextureCache* texture_cache, RT::Renderer*
287 rt_renderer, const string& text, uint16_t gwidth)
288- : hash_(ghash), text_(text), width_(gwidth), surface_cache_(surface_cache),
289+ : hash_(ghash), text_(text), width_(gwidth), texture_cache_(texture_cache),
290 rt_renderer_(rt_renderer)
291 {}
292 virtual ~RTImage() {}
293
294 // Implements Image.
295- uint16_t width() const override {return surface()->width();}
296- uint16_t height() const override {return surface()->height();}
297+ uint16_t width() const override {return texture()->width();}
298+ uint16_t height() const override {return texture()->height();}
299 const string& hash() const override {return hash_;}
300- Surface* surface() const override {
301- Surface* surf = surface_cache_->get(hash_);
302+ Texture* texture() const override {
303+ Texture* surf = texture_cache_->get(hash_);
304 if (surf)
305 return surf;
306
307 surf = rt_renderer_->render(text_, width_);
308- surface_cache_->insert(hash_, surf, true);
309+ texture_cache_->insert(hash_, surf, true);
310 return surf;
311 }
312
313@@ -74,7 +74,7 @@
314 uint16_t width_;
315
316 // Nothing owned.
317- SurfaceCache* const surface_cache_;
318+ TextureCache* const texture_cache_;
319 RT::Renderer* const rt_renderer_;
320 };
321
322@@ -87,8 +87,8 @@
323 // be a problem.
324 class FontHandler1 : public IFontHandler1 {
325 public:
326- FontHandler1(ImageCache* image_cache, SurfaceCache* surface_cache, RT::Renderer* renderer) :
327- surface_cache_(surface_cache), image_cache_(image_cache), renderer_(renderer) {}
328+ FontHandler1(ImageCache* image_cache, TextureCache* texture_cache, RT::Renderer* renderer) :
329+ texture_cache_(texture_cache), image_cache_(image_cache), renderer_(renderer) {}
330 virtual ~FontHandler1() {}
331
332 const Image* render(const string& text, uint16_t w = 0) override {
333@@ -97,21 +97,21 @@
334 if (image_cache_->has(hash))
335 return image_cache_->get(hash);
336
337- std::unique_ptr<RTImage> image(new RTImage(hash, surface_cache_, renderer_.get(), text, w));
338- image->surface(); // force the rich text to get rendered in case there is an exception thrown.
339+ std::unique_ptr<RTImage> image(new RTImage(hash, texture_cache_, renderer_.get(), text, w));
340+ image->texture(); // force the rich text to get rendered in case there is an exception thrown.
341
342 return image_cache_->insert(image.release());
343 }
344
345 private:
346- SurfaceCache* const surface_cache_; // not owned
347+ TextureCache* const texture_cache_; // not owned
348 ImageCache* const image_cache_; // not owned
349 std::unique_ptr<RT::Renderer> renderer_;
350 };
351
352 IFontHandler1 * create_fonthandler(Graphic* gr) {
353 return new FontHandler1(
354- &gr->images(), &gr->surfaces(), new RT::Renderer(&gr->images(), &gr->surfaces()));
355+ &gr->images(), &gr->textures(), new RT::Renderer(&gr->images(), &gr->textures()));
356 }
357
358 IFontHandler1 * g_fh1 = nullptr;
359
360=== modified file 'src/graphic/gl/blit_program.cc'
361--- src/graphic/gl/blit_program.cc 2014-11-02 16:55:53 +0000
362+++ src/graphic/gl/blit_program.cc 2014-11-24 07:32:35 +0000
363@@ -97,7 +97,7 @@
364 void BlitProgram::draw(const FloatRect& gl_dest_rect,
365 const FloatRect& gl_src_rect,
366 const GLuint gl_texture,
367- const Composite composite) {
368+ const BlendMode blend_mode) {
369 glUseProgram(gl_program_.object());
370 glEnableVertexAttribArray(attr_position_);
371 glBindBuffer(GL_ARRAY_BUFFER, gl_array_buffer_.object());
372@@ -117,13 +117,13 @@
373 glActiveTexture(GL_TEXTURE0);
374 glBindTexture(GL_TEXTURE_2D, gl_texture);
375
376- if (composite == CM_Copy) {
377+ if (blend_mode == BlendMode::Copy) {
378 glBlendFunc(GL_ONE, GL_ZERO);
379 }
380
381 glDrawArrays(GL_TRIANGLE_STRIP, 0, 4);
382
383- if (composite == CM_Copy) {
384+ if (blend_mode == BlendMode::Copy) {
385 glBlendFunc(GL_SRC_ALPHA, GL_ONE_MINUS_SRC_ALPHA);
386 }
387
388
389=== modified file 'src/graphic/gl/blit_program.h'
390--- src/graphic/gl/blit_program.h 2014-11-08 18:06:17 +0000
391+++ src/graphic/gl/blit_program.h 2014-11-24 07:32:35 +0000
392@@ -21,8 +21,8 @@
393 #define WL_GRAPHIC_GL_BLIT_PROGRAM_H
394
395 #include "base/rect.h"
396+#include "graphic/blend_mode.h"
397 #include "graphic/color.h"
398-#include "graphic/gl/surface_texture.h"
399 #include "graphic/gl/utils.h"
400
401 class BlitProgram {
402@@ -32,12 +32,12 @@
403
404 // Draws the rectangle 'gl_src_rect' from the texture with the name
405 // 'gl_texture' to 'gl_dest_rect' in the currently bound framebuffer. All
406- // coordinates are in the OpenGL frame. The 'composite' defines if the
407+ // coordinates are in the OpenGL frame. The 'blend_mode' defines if the
408 // values are copied or if alpha values are used.
409 void draw(const FloatRect& gl_dest_rect,
410 const FloatRect& gl_src_rect,
411 const GLuint gl_texture,
412- const Composite composite);
413+ const BlendMode blend_mode);
414
415 private:
416 BlitProgram();
417
418=== modified file 'src/graphic/gl/dither_program.cc'
419--- src/graphic/gl/dither_program.cc 2014-11-08 18:06:17 +0000
420+++ src/graphic/gl/dither_program.cc 2014-11-24 07:32:35 +0000
421@@ -21,10 +21,9 @@
422
423 #include "base/wexception.h"
424 #include "graphic/gl/fields_to_draw.h"
425-#include "graphic/gl/surface_texture.h"
426 #include "graphic/graphic.h"
427 #include "graphic/image_io.h"
428-#include "graphic/surface_cache.h"
429+#include "graphic/terrain_texture.h"
430 #include "graphic/texture.h"
431 #include "io/fileread.h"
432 #include "io/filesystem/layered_filesystem.h"
433@@ -73,19 +72,6 @@
434 }
435 )";
436
437-// Returns the texture mask for the dithering step.
438-const GLSurfaceTexture* get_dither_edge_texture() {
439- constexpr char kFilename[] = "world/pics/edge.png";
440- constexpr char kCacheName[] = "gltex#world/pics/edge.png";
441-
442- if (Surface* surface = g_gr->surfaces().get(kCacheName))
443- return dynamic_cast<GLSurfaceTexture*>(surface);
444-
445- SDL_Surface* sdlsurf = load_image_as_sdl_surface(kFilename, g_fs);
446- GLSurfaceTexture* edgetexture = new GLSurfaceTexture(sdlsurf, true);
447- g_gr->surfaces().insert(kCacheName, edgetexture, false);
448- return edgetexture;
449-}
450
451 } // namespace
452
453@@ -101,8 +87,13 @@
454
455 u_dither_texture_ = glGetUniformLocation(gl_program_.object(), "u_dither_texture");
456 u_terrain_texture_ = glGetUniformLocation(gl_program_.object(), "u_terrain_texture");
457+
458+ SDL_Surface* sdlsurf = load_image_as_sdl_surface("world/pics/edge.png", g_fs);
459+ dither_mask_.reset(new Texture(sdlsurf, true));
460 }
461
462+DitherProgram::~DitherProgram() {}
463+
464 void DitherProgram::add_vertex(const FieldsToDraw::Field& field,
465 const int order_index,
466 const int terrain) {
467@@ -220,7 +211,7 @@
468 // Set the sampler texture unit to 0
469 glActiveTexture(GL_TEXTURE0);
470 glUniform1i(u_dither_texture_, 0);
471- glBindTexture(GL_TEXTURE_2D, get_dither_edge_texture()->get_gl_texture());
472+ glBindTexture(GL_TEXTURE_2D, dither_mask_->get_gl_texture());
473 glTexParameteri(GL_TEXTURE_2D, GL_TEXTURE_WRAP_S, GL_CLAMP);
474 glTexParameteri(GL_TEXTURE_2D, GL_TEXTURE_WRAP_T, GL_CLAMP);
475
476@@ -234,9 +225,10 @@
477 if (current_data.empty()) {
478 continue;
479 }
480- glBindTexture(
481- GL_TEXTURE_2D,
482- g_gr->get_maptexture_data(terrains.get_unmutable(i).get_texture())->get_texture());
483+ glBindTexture(GL_TEXTURE_2D,
484+ g_gr->get_maptexture_data(terrains.get_unmutable(i).get_texture())
485+ ->texture()
486+ .get_gl_texture());
487
488 glBufferData(GL_ARRAY_BUFFER,
489 sizeof(PerVertexData) * current_data.size(),
490
491=== modified file 'src/graphic/gl/dither_program.h'
492--- src/graphic/gl/dither_program.h 2014-11-08 18:06:17 +0000
493+++ src/graphic/gl/dither_program.h 2014-11-24 07:32:35 +0000
494@@ -20,14 +20,19 @@
495 #ifndef WL_GRAPHIC_GL_DITHER_PROGRAM_H
496 #define WL_GRAPHIC_GL_DITHER_PROGRAM_H
497
498+#include <memory>
499+
500 #include "graphic/gl/fields_to_draw.h"
501 #include "graphic/gl/utils.h"
502 #include "logic/description_maintainer.h"
503 #include "logic/world/terrain_description.h"
504
505+class Texture;
506+
507 class DitherProgram {
508 public:
509 DitherProgram();
510+ ~DitherProgram();
511
512 // Draws the terrain.
513 void draw(const DescriptionMaintainer<Widelands::TerrainDescription>& terrains,
514@@ -77,6 +82,9 @@
515 GLint u_terrain_texture_;
516 GLint u_dither_texture_;
517
518+ // The texture mask for the dithering step.
519+ std::unique_ptr<Texture> dither_mask_;
520+
521 // Objects below are here to avoid memory allocations on each frame, they
522 // could theoretically also always be recreated. Index as follows:
523 // vertices_[terrain_index][vertex_index]
524
525=== modified file 'src/graphic/gl/game_renderer.cc'
526--- src/graphic/gl/game_renderer.cc 2014-11-22 21:31:21 +0000
527+++ src/graphic/gl/game_renderer.cc 2014-11-24 07:32:35 +0000
528@@ -28,7 +28,7 @@
529 #include "graphic/graphic.h"
530 #include "graphic/rendertarget.h"
531 #include "graphic/surface.h"
532-#include "graphic/texture.h"
533+#include "graphic/terrain_texture.h"
534 #include "logic/editor_game_base.h"
535 #include "logic/player.h"
536 #include "logic/world/world.h"
537@@ -165,8 +165,8 @@
538 map.normalize_coords(coords);
539 const FCoords& fcoords = map.get_fcoords(coords);
540
541- f.texture_x = float(x) / TEXTURE_WIDTH;
542- f.texture_y = float(y) / TEXTURE_HEIGHT;
543+ f.texture_x = float(x) / kTextureWidth;
544+ f.texture_y = float(y) / kTextureHeight;
545
546 f.gl_x = f.pixel_x = x + surface_offset.x;
547 f.gl_y = f.pixel_y = y + surface_offset.y - fcoords.field->get_height() * HEIGHT_FACTOR;
548
549=== modified file 'src/graphic/gl/road_program.cc'
550--- src/graphic/gl/road_program.cc 2014-11-22 21:31:21 +0000
551+++ src/graphic/gl/road_program.cc 2014-11-24 07:32:35 +0000
552@@ -24,6 +24,7 @@
553 #include "base/log.h"
554 #include "graphic/gl/fields_to_draw.h"
555 #include "graphic/graphic.h"
556+#include "graphic/image_io.h"
557 #include "graphic/texture.h"
558 #include "logic/roadtype.h"
559
560@@ -85,6 +86,12 @@
561
562 u_normal_road_texture_ = glGetUniformLocation(gl_program_.object(), "u_normal_road_texture");
563 u_busy_road_texture_ = glGetUniformLocation(gl_program_.object(), "u_busy_road_texture");
564+
565+ normal_road_texture_.reset(load_image("world/pics/roadt_normal.png"));
566+ busy_road_texture_.reset(load_image("world/pics/roadt_busy.png"));
567+}
568+
569+RoadProgram::~RoadProgram() {
570 }
571
572 void RoadProgram::add_road(const Surface& surface,
573@@ -211,17 +218,12 @@
574 glBindBuffer(GL_ARRAY_BUFFER, 0);
575
576 // Bind the textures.
577- const GLuint rt_normal = dynamic_cast<const GLSurfaceTexture&>(
578- g_gr->get_road_texture(Widelands::Road_Normal)).get_gl_texture();
579- const GLuint rt_busy = dynamic_cast<const GLSurfaceTexture&>(
580- g_gr->get_road_texture(Widelands::Road_Busy)).get_gl_texture();
581-
582 glActiveTexture(GL_TEXTURE0);
583- glBindTexture(GL_TEXTURE_2D, rt_normal);
584+ glBindTexture(GL_TEXTURE_2D, normal_road_texture_->get_gl_texture());
585 glUniform1i(u_normal_road_texture_, 0);
586
587 glActiveTexture(GL_TEXTURE1);
588- glBindTexture(GL_TEXTURE_2D, rt_busy);
589+ glBindTexture(GL_TEXTURE_2D, busy_road_texture_->get_gl_texture());
590 glUniform1i(u_busy_road_texture_, 1);
591
592 glDrawArrays(GL_TRIANGLES, 0, vertices_.size());
593
594=== modified file 'src/graphic/gl/road_program.h'
595--- src/graphic/gl/road_program.h 2014-11-22 21:31:21 +0000
596+++ src/graphic/gl/road_program.h 2014-11-24 07:32:35 +0000
597@@ -20,18 +20,22 @@
598 #ifndef WL_GRAPHIC_GL_ROAD_PROGRAM_H
599 #define WL_GRAPHIC_GL_ROAD_PROGRAM_H
600
601+#include <memory>
602 #include <vector>
603
604 #include "base/macros.h"
605 #include "graphic/gl/fields_to_draw.h"
606 #include "graphic/gl/utils.h"
607-#include "graphic/surface.h"
608 #include "logic/roadtype.h"
609
610+class Texture;
611+class Surface;
612+
613 class RoadProgram {
614 public:
615 // Compiles the program. Throws on error.
616 RoadProgram();
617+ ~RoadProgram();
618
619 // Draws the roads. The 'surface' is needed to convert from pixel space to
620 // GL space.
621@@ -79,6 +83,10 @@
622 // All vertices that get rendered this frame.
623 std::vector<PerVertexData> vertices_;
624
625+ // The road textures.
626+ std::unique_ptr<Texture> normal_road_texture_;
627+ std::unique_ptr<Texture> busy_road_texture_;
628+
629 DISALLOW_COPY_AND_ASSIGN(RoadProgram);
630 };
631
632
633=== modified file 'src/graphic/gl/terrain_program.cc'
634--- src/graphic/gl/terrain_program.cc 2014-11-08 18:06:17 +0000
635+++ src/graphic/gl/terrain_program.cc 2014-11-24 07:32:35 +0000
636@@ -21,6 +21,7 @@
637
638 #include "graphic/gl/fields_to_draw.h"
639 #include "graphic/graphic.h"
640+#include "graphic/terrain_texture.h"
641 #include "graphic/texture.h"
642
643 namespace {
644@@ -117,9 +118,10 @@
645 if (indices.empty()) {
646 continue;
647 }
648- glBindTexture(
649- GL_TEXTURE_2D,
650- g_gr->get_maptexture_data(terrains.get_unmutable(i).get_texture())->get_texture());
651+ glBindTexture(GL_TEXTURE_2D,
652+ g_gr->get_maptexture_data(terrains.get_unmutable(i).get_texture())
653+ ->texture()
654+ .get_gl_texture());
655 glDrawElements(GL_TRIANGLES, indices.size(), GL_UNSIGNED_SHORT, indices.data());
656 }
657
658
659=== modified file 'src/graphic/graphic.cc'
660--- src/graphic/graphic.cc 2014-11-24 07:32:34 +0000
661+++ src/graphic/graphic.cc 2014-11-24 07:32:35 +0000
662@@ -35,13 +35,15 @@
663 #include "graphic/animation.h"
664 #include "graphic/diranimations.h"
665 #include "graphic/font_handler.h"
666-#include "graphic/gl/surface_screen.h"
667+#include "graphic/gl/system_headers.h"
668 #include "graphic/image.h"
669 #include "graphic/image_io.h"
670 #include "graphic/image_transformations.h"
671 #include "graphic/rendertarget.h"
672-#include "graphic/surface_cache.h"
673+#include "graphic/screen.h"
674+#include "graphic/terrain_texture.h"
675 #include "graphic/texture.h"
676+#include "graphic/texture_cache.h"
677 #include "io/fileread.h"
678 #include "io/filesystem/layered_filesystem.h"
679 #include "io/streamwrite.h"
680@@ -57,7 +59,7 @@
681
682 /// The size of the transient (i.e. temporary) surfaces in the cache in bytes.
683 /// These are all surfaces that are not loaded from disk.
684-const uint32_t TRANSIENT_SURFACE_CACHE_SIZE = 160 << 20; // shifting converts to MB
685+const uint32_t TRANSIENT_TEXTURE_CACHE_SIZE = 160 << 20; // shifting converts to MB
686
687 // Sets the icon for the application.
688 void set_icon(SDL_Window* sdl_window) {
689@@ -80,8 +82,8 @@
690 : m_window_mode_width(window_mode_w),
691 m_window_mode_height(window_mode_h),
692 m_update(true),
693- surface_cache_(create_surface_cache(TRANSIENT_SURFACE_CACHE_SIZE)),
694- image_cache_(new ImageCache(surface_cache_.get())),
695+ texture_cache_(create_texture_cache(TRANSIENT_TEXTURE_CACHE_SIZE)),
696+ image_cache_(new ImageCache(texture_cache_.get())),
697 animation_manager_(new AnimationManager())
698 {
699 ImageTransformations::initialize();
700@@ -156,15 +158,12 @@
701 disp_mode.h);
702 assert(SDL_BYTESPERPIXEL(disp_mode.format) == 4);
703 }
704-
705- pic_road_normal_.reset(load_image("world/pics/roadt_normal.png"));
706- pic_road_busy_.reset(load_image("world/pics/roadt_busy.png"));
707 }
708
709 Graphic::~Graphic()
710 {
711 m_maptextures.clear();
712- surface_cache_->flush();
713+ texture_cache_->flush();
714 // TODO(unknown): this should really not be needed, but currently is :(
715 if (UI::g_fh)
716 UI::g_fh->flush();
717@@ -209,7 +208,7 @@
718 int new_w, new_h;
719 SDL_GetWindowSize(m_sdl_window, &new_w, &new_h);
720
721- screen_.reset(new GLSurfaceScreen(new_w, new_h));
722+ screen_.reset(new Screen(new_w, new_h));
723 m_rendertarget.reset(new RenderTarget(screen_.get()));
724
725 Notifications::publish(GraphicResolutionChanged{new_w, new_h});
726@@ -301,12 +300,12 @@
727 * @param sw a StreamWrite where the png is written to
728 */
729 void Graphic::save_png(const Image* image, StreamWrite * sw) const {
730- save_surface_to_png(image->surface(), sw);
731+ save_surface_to_png(image->texture(), sw);
732 }
733
734 uint32_t Graphic::new_maptexture(const std::vector<std::string>& texture_files, const uint32_t frametime)
735 {
736- m_maptextures.emplace_back(new Texture(texture_files, frametime));
737+ m_maptextures.emplace_back(new TerrainTexture(texture_files, frametime));
738 return m_maptextures.size(); // ID 1 is at m_maptextures[0]
739 }
740
741@@ -335,20 +334,10 @@
742 * Retrieve the map texture with the given number
743 * \return the actual texture data associated with the given ID.
744 */
745-Texture * Graphic::get_maptexture_data(uint32_t id)
746+TerrainTexture * Graphic::get_maptexture_data(uint32_t id)
747 {
748 --id; // ID 1 is at m_maptextures[0]
749
750 assert(id < m_maptextures.size());
751 return m_maptextures[id].get();
752 }
753-
754-/**
755- * Retrives the texture of the road type.
756- * \return The road texture
757- */
758-Surface& Graphic::get_road_texture(int32_t roadtex)
759-{
760- return
761- roadtex == Widelands::Road_Normal ? *pic_road_normal_.get() : *pic_road_busy_.get();
762-}
763
764=== modified file 'src/graphic/graphic.h'
765--- src/graphic/graphic.h 2014-11-24 07:32:34 +0000
766+++ src/graphic/graphic.h 2014-11-24 07:32:35 +0000
767@@ -36,9 +36,9 @@
768 class AnimationManager;
769 class RenderTarget;
770 class Surface;
771-class SurfaceCache;
772+class TextureCache;
773 class StreamWrite;
774-struct Texture;
775+struct TerrainTexture;
776
777 // Will be send whenever the resolution changes.
778 struct GraphicResolutionChanged {
779@@ -50,10 +50,10 @@
780 };
781
782 /**
783- * This class is a kind of Swiss Army knife for your graphics need. It
784- * initializes the graphic system and provides access to resolutions. It has an
785- * Animation, Image and Surface cache and owns the road textures. It also
786- * offers functionality to save a screenshot.
787+ * This class is a kind of Swiss Army knife for your graphics need.
788+ * It initializes the graphic system and provides access to
789+ * resolutions. It owns an Animation, Image and Surface cache. It
790+ * also offers functionality to save a screenshot.
791 */
792 class Graphic {
793 public:
794@@ -77,21 +77,19 @@
795 void refresh();
796 SDL_Window* get_sdlwindow() {return m_sdl_window;}
797
798- SurfaceCache& surfaces() const {return *surface_cache_.get();}
799+ TextureCache& textures() const {return *texture_cache_.get();}
800 ImageCache& images() const {return *image_cache_.get();}
801 AnimationManager& animations() const {return *animation_manager_.get();}
802
803 void save_png(const Image*, StreamWrite*) const;
804
805- // Creates a new Texture() with the given 'frametime' and using the given
806+ // Creates a new TerrainTexture() with the given 'frametime' and using the given
807 // 'texture_files' as the images for it and returns it id.
808 uint32_t new_maptexture(const std::vector<std::string>& texture_files, uint32_t frametime);
809 void animate_maptextures(uint32_t time);
810
811 void screenshot(const std::string& fname) const;
812- Texture * get_maptexture_data(uint32_t id);
813-
814- Surface& get_road_texture(int32_t roadtex);
815+ TerrainTexture * get_maptexture_data(uint32_t id);
816
817 private:
818 // Called when the resolution (might) have changed.
819@@ -114,19 +112,15 @@
820 /// This marks the complete screen for updating.
821 bool m_update;
822
823- /// Volatile cache of Hardware dependant surfaces.
824- std::unique_ptr<SurfaceCache> surface_cache_;
825+ /// Volatile cache of Hardware dependant textures.
826+ std::unique_ptr<TextureCache> texture_cache_;
827 /// Non-volatile cache of hardware independent images. The use the
828- /// surface_cache_ to cache their pixel data.
829+ /// texture_cache_ to cache their pixel data.
830 std::unique_ptr<ImageCache> image_cache_;
831 /// This holds all animations.
832 std::unique_ptr<AnimationManager> animation_manager_;
833
834- // The texture needed to draw roads.
835- std::unique_ptr<Surface> pic_road_normal_;
836- std::unique_ptr<Surface> pic_road_busy_;
837-
838- std::vector<std::unique_ptr<Texture>> m_maptextures;
839+ std::vector<std::unique_ptr<TerrainTexture>> m_maptextures;
840 };
841
842 extern Graphic * g_gr;
843
844=== modified file 'src/graphic/image.h'
845--- src/graphic/image.h 2014-07-14 19:48:07 +0000
846+++ src/graphic/image.h 2014-11-24 07:32:35 +0000
847@@ -26,12 +26,12 @@
848
849 #include "base/macros.h"
850
851+class Texture;
852+
853 /**
854 * Interface to a bitmap that can act as the source of a rendering
855 * operation.
856 */
857-class Surface;
858-
859 class Image {
860 public:
861 Image() = default;
862@@ -41,7 +41,7 @@
863 virtual uint16_t height() const = 0;
864
865 // Internal functions needed for caching.
866- virtual Surface* surface() const = 0;
867+ virtual Texture* texture() const = 0;
868 virtual const std::string& hash() const = 0;
869
870 DISALLOW_COPY_AND_ASSIGN(Image);
871
872=== modified file 'src/graphic/image_cache.cc'
873--- src/graphic/image_cache.cc 2014-07-26 10:43:23 +0000
874+++ src/graphic/image_cache.cc 2014-11-24 07:32:35 +0000
875@@ -25,21 +25,21 @@
876 #include "base/log.h"
877 #include "graphic/image.h"
878 #include "graphic/image_io.h"
879-#include "graphic/surface.h"
880-#include "graphic/surface_cache.h"
881+#include "graphic/texture.h"
882+#include "graphic/texture_cache.h"
883
884 namespace {
885
886 // Image Implementation that loads images from disc when they should be drawn.
887-// Uses SurfaceCache. These images are meant to be cached in ImageCache.
888+// Uses TextureCache. These images are meant to be cached in ImageCache.
889 class FromDiskImage : public Image {
890 public:
891- FromDiskImage(const std::string& filename, SurfaceCache* surface_cache) :
892+ FromDiskImage(const std::string& filename, TextureCache* texture_cache) :
893 filename_(filename),
894- surface_cache_(surface_cache) {
895- Surface* surf = reload_image_();
896- w_ = surf->width();
897- h_ = surf->height();
898+ texture_cache_(texture_cache) {
899+ Texture* texture = reload_image_();
900+ w_ = texture->width();
901+ h_ = texture->height();
902 }
903 virtual ~FromDiskImage() {}
904
905@@ -47,27 +47,27 @@
906 uint16_t width() const override {return w_; }
907 uint16_t height() const override {return h_;}
908 const std::string& hash() const override {return filename_;}
909- Surface* surface() const override {
910- Surface* surf = surface_cache_->get(filename_);
911- if (surf)
912- return surf;
913+ Texture* texture() const override {
914+ Texture* texture = texture_cache_->get(filename_);
915+ if (texture)
916+ return texture;
917 return reload_image_();
918 }
919
920 private:
921- Surface* reload_image_() const {
922- Surface* surf = surface_cache_->insert(filename_, load_image(filename_), false);
923- return surf;
924+ Texture* reload_image_() const {
925+ Texture* texture = texture_cache_->insert(filename_, load_image(filename_), false);
926+ return texture;
927 }
928 uint16_t w_, h_;
929 const std::string filename_;
930
931- SurfaceCache* const surface_cache_; // Not owned.
932+ TextureCache* const texture_cache_; // Not owned.
933 };
934
935 } // namespace
936
937-ImageCache::ImageCache(SurfaceCache* const surface_cache) : surface_cache_(surface_cache) {
938+ImageCache::ImageCache(TextureCache* const texture_cache) : texture_cache_(texture_cache) {
939 }
940
941 ImageCache::~ImageCache() {
942@@ -90,7 +90,7 @@
943 const Image* ImageCache::get(const std::string& hash) {
944 ImageMap::const_iterator it = images_.find(hash);
945 if (it == images_.end()) {
946- images_.insert(make_pair(hash, new FromDiskImage(hash, surface_cache_)));
947+ images_.insert(make_pair(hash, new FromDiskImage(hash, texture_cache_)));
948 return get(hash);
949 }
950 return it->second;
951
952=== modified file 'src/graphic/image_cache.h'
953--- src/graphic/image_cache.h 2014-09-14 11:31:58 +0000
954+++ src/graphic/image_cache.h 2014-11-24 07:32:35 +0000
955@@ -28,7 +28,7 @@
956 #include "base/macros.h"
957 #include "graphic/image.h"
958
959-class SurfaceCache;
960+class TextureCache;
961
962 // For historic reasons, most part of the Widelands code base expect that an
963 // Image stays valid for the whole duration of the program run. This class is
964@@ -40,7 +40,7 @@
965 class ImageCache {
966 public:
967 // Does not take ownership.
968- ImageCache(SurfaceCache* surface_cache);
969+ ImageCache(TextureCache* texture_cache);
970 ~ImageCache();
971
972 // Insert the given Image into the cache. The hash is defined by Image's hash()
973@@ -60,7 +60,7 @@
974 using ImageMap = std::map<std::string, const Image*>;
975
976 ImageMap images_; /// hash of cached filename/image pairs
977- SurfaceCache* const surface_cache_; // Not owned.
978+ TextureCache* const texture_cache_; // Not owned.
979
980 DISALLOW_COPY_AND_ASSIGN(ImageCache);
981 };
982
983=== modified file 'src/graphic/image_io.cc'
984--- src/graphic/image_io.cc 2014-09-20 09:37:47 +0000
985+++ src/graphic/image_io.cc 2014-11-24 07:32:35 +0000
986@@ -26,7 +26,7 @@
987 #include <png.h>
988
989 #include "base/wexception.h"
990-#include "graphic/surface.h"
991+#include "graphic/texture.h"
992 #include "io/fileread.h"
993 #include "io/filesystem/layered_filesystem.h"
994 #include "io/streamwrite.h"
995@@ -47,8 +47,8 @@
996
997 } // namespace
998
999-Surface* load_image(const std::string& fname, FileSystem* fs) {
1000- return Surface::create(load_image_as_sdl_surface(fname, fs));
1001+Texture* load_image(const std::string& fname, FileSystem* fs) {
1002+ return new Texture(load_image_as_sdl_surface(fname, fs));
1003 }
1004
1005 SDL_Surface* load_image_as_sdl_surface(const std::string& fname, FileSystem* fs) {
1006
1007=== modified file 'src/graphic/image_io.h'
1008--- src/graphic/image_io.h 2014-09-09 17:15:20 +0000
1009+++ src/graphic/image_io.h 2014-11-24 07:32:35 +0000
1010@@ -25,6 +25,7 @@
1011 #include "base/wexception.h"
1012
1013 class FileSystem;
1014+class Texture;
1015 class StreamWrite;
1016 class Surface;
1017 struct SDL_Surface;
1018@@ -43,12 +44,11 @@
1019 };
1020
1021 /// Loads the image 'fn' from 'fs'.
1022-Surface* load_image(const std::string& fn, FileSystem* fs = nullptr);
1023+Texture* load_image(const std::string& fn, FileSystem* fs = nullptr);
1024
1025 /// Loads the image 'fn' from 'fs' into an SDL_Surface. Caller must SDL_FreeSurface() the returned value.
1026 SDL_Surface* load_image_as_sdl_surface(const std::string& fn, FileSystem* fs = nullptr);
1027
1028-
1029 /// Saves the 'surface' to 'sw' as a PNG.
1030 bool save_surface_to_png(Surface* surface, StreamWrite* sw);
1031
1032
1033=== modified file 'src/graphic/image_transformations.cc'
1034--- src/graphic/image_transformations.cc 2014-11-22 21:31:21 +0000
1035+++ src/graphic/image_transformations.cc 2014-11-24 07:32:35 +0000
1036@@ -28,8 +28,8 @@
1037 #include "base/macros.h"
1038 #include "graphic/color.h"
1039 #include "graphic/graphic.h"
1040-#include "graphic/surface.h"
1041-#include "graphic/surface_cache.h"
1042+#include "graphic/texture.h"
1043+#include "graphic/texture_cache.h"
1044
1045 using namespace std;
1046
1047@@ -44,24 +44,24 @@
1048 * Create and return an \ref SDL_Surface that contains the given sub-rectangle
1049 * of the given pixel region.
1050 */
1051-SDL_Surface* extract_sdl_surface(Surface & surf, Rect srcrect)
1052+SDL_Surface* extract_sdl_surface(Texture & texture, Rect srcrect)
1053 {
1054 assert(srcrect.x >= 0);
1055 assert(srcrect.y >= 0);
1056- assert(srcrect.x + srcrect.w <= surf.width());
1057- assert(srcrect.y + srcrect.h <= surf.height());
1058+ assert(srcrect.x + srcrect.w <= texture.width());
1059+ assert(srcrect.y + srcrect.h <= texture.height());
1060
1061- const SDL_PixelFormat & fmt = surf.format();
1062+ const SDL_PixelFormat & fmt = texture.format();
1063 SDL_Surface * dest = SDL_CreateRGBSurface
1064 (SDL_SWSURFACE, srcrect.w, srcrect.h,
1065 fmt.BitsPerPixel, fmt.Rmask, fmt.Gmask, fmt.Bmask, fmt.Amask);
1066
1067- surf.lock(Surface::Lock_Normal);
1068+ texture.lock(Surface::Lock_Normal);
1069 SDL_LockSurface(dest);
1070
1071- uint32_t srcpitch = surf.get_pitch();
1072+ uint32_t srcpitch = texture.get_pitch();
1073 uint32_t rowsize = srcrect.w * fmt.BytesPerPixel;
1074- uint8_t * srcpix = surf.get_pixels() + srcpitch * srcrect.y + fmt.BytesPerPixel * srcrect.x;
1075+ uint8_t * srcpix = texture.get_pixels() + srcpitch * srcrect.y + fmt.BytesPerPixel * srcrect.x;
1076 uint8_t * dstpix = static_cast<uint8_t *>(dest->pixels);
1077
1078 for (uint32_t y = 0; y < srcrect.h; ++y) {
1079@@ -71,7 +71,7 @@
1080 }
1081
1082 SDL_UnlockSurface(dest);
1083- surf.unlock(Surface::Unlock_NoChange);
1084+ texture.unlock(Surface::Unlock_NoChange);
1085
1086 return dest;
1087 }
1088@@ -79,7 +79,7 @@
1089 /**
1090 * Produces a resized version of the specified image
1091 */
1092-Surface* resize_surface(Surface* src, uint32_t w, uint32_t h) {
1093+Texture* resize_surface(Texture* src, uint32_t w, uint32_t h) {
1094 assert(w != src->width() || h != src->height());
1095
1096 // First step: compute scaling factors
1097@@ -89,7 +89,7 @@
1098 SDL_Surface * srcsdl = extract_sdl_surface(*src, srcrect);
1099 bool free_source = true;
1100
1101- // If we actually shrink a surface, ballpark the zoom so that the shrinking
1102+ // If we actually shrink a texture, ballpark the zoom so that the shrinking
1103 // effect is weakened.
1104 int factor = 1;
1105 while ((static_cast<double>(w) * factor / srcsdl->w) < 1. ||
1106@@ -146,29 +146,29 @@
1107 zoomed = placed;
1108 }
1109
1110- return Surface::create(zoomed);
1111+ return new Texture(zoomed);
1112 }
1113
1114 /**
1115- * Create a grayed version of the given surface.
1116+ * Create a grayed version of the given texture.
1117 */
1118-Surface* gray_out_surface(Surface* surf) {
1119- assert(surf);
1120-
1121- uint16_t w = surf->width();
1122- uint16_t h = surf->height();
1123- const SDL_PixelFormat & origfmt = surf->format();
1124-
1125- Surface* dest = Surface::create(w, h);
1126+Texture* gray_out_texture(Texture* texture) {
1127+ assert(texture);
1128+
1129+ uint16_t w = texture->width();
1130+ uint16_t h = texture->height();
1131+ const SDL_PixelFormat & origfmt = texture->format();
1132+
1133+ Texture* dest = new Texture(w, h);
1134 const SDL_PixelFormat & destfmt = dest->format();
1135
1136- surf->lock(Surface::Lock_Normal);
1137+ texture->lock(Surface::Lock_Normal);
1138 dest->lock(Surface::Lock_Discard);
1139 for (uint32_t y = 0; y < h; ++y) {
1140 for (uint32_t x = 0; x < w; ++x) {
1141 RGBAColor color;
1142
1143- color.set(origfmt, surf->get_pixel(x, y));
1144+ color.set(origfmt, texture->get_pixel(x, y));
1145
1146 // Halve the opacity to give some difference for image that are
1147 // grayscale to begin with.
1148@@ -184,32 +184,32 @@
1149 dest->set_pixel(x, y, color.map(destfmt));
1150 }
1151 }
1152- surf->unlock(Surface::Unlock_NoChange);
1153+ texture->unlock(Surface::Unlock_NoChange);
1154 dest->unlock(Surface::Unlock_Update);
1155
1156 return dest;
1157 }
1158
1159 /**
1160- * Creates an image with changed luminosity from the given surface.
1161+ * Creates an image with changed luminosity from the given texture.
1162 */
1163-Surface* change_luminosity_of_surface(Surface* surf, float factor, bool halve_alpha) {
1164- assert(surf);
1165-
1166- uint16_t w = surf->width();
1167- uint16_t h = surf->height();
1168- const SDL_PixelFormat & origfmt = surf->format();
1169-
1170- Surface* dest = Surface::create(w, h);
1171+Texture* change_luminosity_of_texture(Texture* texture, float factor, bool halve_alpha) {
1172+ assert(texture);
1173+
1174+ uint16_t w = texture->width();
1175+ uint16_t h = texture->height();
1176+ const SDL_PixelFormat & origfmt = texture->format();
1177+
1178+ Texture* dest = new Texture(w, h);
1179 const SDL_PixelFormat & destfmt = dest->format();
1180
1181- surf->lock(Surface::Lock_Normal);
1182+ texture->lock(Surface::Lock_Normal);
1183 dest->lock(Surface::Lock_Discard);
1184 for (uint32_t y = 0; y < h; ++y) {
1185 for (uint32_t x = 0; x < w; ++x) {
1186 RGBAColor color;
1187
1188- color.set(origfmt, surf->get_pixel(x, y));
1189+ color.set(origfmt, texture->get_pixel(x, y));
1190
1191 if (halve_alpha)
1192 color.a >>= 1;
1193@@ -221,7 +221,7 @@
1194 dest->set_pixel(x, y, color.map(destfmt));
1195 }
1196 }
1197- surf->unlock(Surface::Unlock_NoChange);
1198+ texture->unlock(Surface::Unlock_NoChange);
1199 dest->unlock(Surface::Unlock_Update);
1200
1201 return dest;
1202@@ -229,26 +229,28 @@
1203
1204 // Encodes the given Image into the corresponding image for player color.
1205 // Takes the neutral set of images and the player color mask.
1206-Surface* make_playerclr_surface(Surface& orig_surface, Surface& pcmask_surface, const RGBColor& color) {
1207- Surface* new_surface = Surface::create(orig_surface.width(), orig_surface.height());
1208-
1209- const SDL_PixelFormat & fmt = orig_surface.format();
1210- const SDL_PixelFormat & fmt_pc = pcmask_surface.format();
1211- const SDL_PixelFormat & destfmt = new_surface->format();
1212-
1213- orig_surface.lock(Surface::Lock_Normal);
1214- pcmask_surface.lock(Surface::Lock_Normal);
1215- new_surface->lock(Surface::Lock_Discard);
1216+Texture* make_playerclr_texture(Texture& original_texture,
1217+ Texture& pcmask_texture,
1218+ const RGBColor& color) {
1219+ Texture* new_texture = new Texture(original_texture.width(), original_texture.height());
1220+
1221+ const SDL_PixelFormat & fmt = original_texture.format();
1222+ const SDL_PixelFormat & fmt_pc = pcmask_texture.format();
1223+ const SDL_PixelFormat & destfmt = new_texture->format();
1224+
1225+ original_texture.lock(Surface::Lock_Normal);
1226+ pcmask_texture.lock(Surface::Lock_Normal);
1227+ new_texture->lock(Surface::Lock_Discard);
1228 // This could be done significantly faster, but since we
1229 // cache the result, let's keep it simple for now.
1230- for (uint32_t y = 0; y < orig_surface.height(); ++y) {
1231- for (uint32_t x = 0; x < orig_surface.width(); ++x) {
1232+ for (uint32_t y = 0; y < original_texture.height(); ++y) {
1233+ for (uint32_t x = 0; x < original_texture.width(); ++x) {
1234 RGBAColor source;
1235 RGBAColor mask;
1236 RGBAColor product;
1237
1238- source.set(fmt, orig_surface.get_pixel(x, y));
1239- mask.set(fmt_pc, pcmask_surface.get_pixel(x, y));
1240+ source.set(fmt, original_texture.get_pixel(x, y));
1241+ mask.set(fmt_pc, pcmask_texture.get_pixel(x, y));
1242
1243 if
1244 (uint32_t const influence =
1245@@ -277,45 +279,45 @@
1246 product = source;
1247 }
1248
1249- new_surface->set_pixel(x, y, product.map(destfmt));
1250+ new_texture->set_pixel(x, y, product.map(destfmt));
1251 }
1252 }
1253- orig_surface.unlock(Surface::Unlock_NoChange);
1254- pcmask_surface.unlock(Surface::Unlock_NoChange);
1255- new_surface->unlock(Surface::Unlock_Update);
1256+ original_texture.unlock(Surface::Unlock_NoChange);
1257+ pcmask_texture.unlock(Surface::Unlock_NoChange);
1258+ new_texture->unlock(Surface::Unlock_Update);
1259
1260- return new_surface;
1261+ return new_texture;
1262 }
1263
1264 // An Image implementation that is the transformation of another Image. Uses
1265-// the SurfaceCache to avoid recalculating the transformation too often. No
1266+// the TextureCache to avoid recalculating the transformation too often. No
1267 // ownerships are taken.
1268 class TransformedImage : public Image {
1269 public:
1270- TransformedImage(const string& ghash, const Image& original, SurfaceCache* surface_cache) :
1271- hash_(ghash), original_(original), surface_cache_(surface_cache) {}
1272+ TransformedImage(const string& ghash, const Image& original, TextureCache* texture_cache) :
1273+ hash_(ghash), original_(original), texture_cache_(texture_cache) {}
1274 virtual ~TransformedImage() {}
1275
1276 // Implements Image.
1277 uint16_t width() const override {return original_.width();}
1278 uint16_t height() const override {return original_.height();}
1279 const string& hash() const override {return hash_;}
1280- Surface* surface() const override {
1281- Surface* surf = surface_cache_->get(hash_);
1282- if (surf)
1283- return surf;
1284+ Texture* texture() const override {
1285+ Texture* texture = texture_cache_->get(hash_);
1286+ if (texture)
1287+ return texture;
1288
1289- surf = recalculate_surface();
1290- surface_cache_->insert(hash_, surf, true);
1291- return surf;
1292+ texture = recalculate_texture();
1293+ texture_cache_->insert(hash_, texture, true);
1294+ return texture;
1295 }
1296
1297- virtual Surface* recalculate_surface() const = 0;
1298+ virtual Texture* recalculate_texture() const = 0;
1299
1300 protected:
1301 const string hash_;
1302 const Image& original_;
1303- SurfaceCache* const surface_cache_; // not owned
1304+ TextureCache* const texture_cache_; // not owned
1305 };
1306
1307 // A resized copy of an Image.
1308@@ -323,8 +325,8 @@
1309 public:
1310 ResizedImage
1311 (const string& ghash, const Image& original,
1312- SurfaceCache* surface_cache, uint16_t w, uint16_t h)
1313- : TransformedImage(ghash, original, surface_cache), w_(w), h_(h) {
1314+ TextureCache* texture_cache, uint16_t w, uint16_t h)
1315+ : TransformedImage(ghash, original, texture_cache), w_(w), h_(h) {
1316 assert(w != original.width() || h != original.height());
1317 }
1318 virtual ~ResizedImage() {}
1319@@ -334,8 +336,8 @@
1320 uint16_t height() const override {return h_;}
1321
1322 // Implements TransformedImage.
1323- Surface* recalculate_surface() const override {
1324- Surface* rv = resize_surface(original_.surface(), w_, h_);
1325+ Texture* recalculate_texture() const override {
1326+ Texture* rv = resize_surface(original_.texture(), w_, h_);
1327 return rv;
1328 }
1329
1330@@ -346,14 +348,14 @@
1331 // A grayed out copy of an Image.
1332 class GrayedOutImage : public TransformedImage {
1333 public:
1334- GrayedOutImage(const string& ghash, const Image& original, SurfaceCache* surface_cache) :
1335- TransformedImage(ghash, original, surface_cache)
1336+ GrayedOutImage(const string& ghash, const Image& original, TextureCache* texture_cache) :
1337+ TransformedImage(ghash, original, texture_cache)
1338 {}
1339 virtual ~GrayedOutImage() {}
1340
1341 // Implements TransformedImage.
1342- Surface* recalculate_surface() const override {
1343- return gray_out_surface(original_.surface());
1344+ Texture* recalculate_texture() const override {
1345+ return gray_out_texture(original_.texture());
1346 }
1347 };
1348
1349@@ -362,16 +364,16 @@
1350 public:
1351 ChangeLuminosityImage
1352 (const string& ghash, const Image& original,
1353- SurfaceCache* surface_cache, float factor, bool halve_alpha)
1354- : TransformedImage(ghash, original, surface_cache),
1355+ TextureCache* texture_cache, float factor, bool halve_alpha)
1356+ : TransformedImage(ghash, original, texture_cache),
1357 factor_(factor),
1358 halve_alpha_(halve_alpha)
1359 {}
1360 virtual ~ChangeLuminosityImage() {}
1361
1362 // Implements TransformedImage.
1363- Surface* recalculate_surface() const override {
1364- return change_luminosity_of_surface(original_.surface(), factor_, halve_alpha_);
1365+ Texture* recalculate_texture() const override {
1366+ return change_luminosity_of_texture(original_.texture(), factor_, halve_alpha_);
1367 }
1368
1369 private:
1370@@ -385,14 +387,14 @@
1371 public:
1372 PlayerColoredImage
1373 (const string& ghash, const Image& original,
1374- SurfaceCache* surface_cache, const RGBColor& color, const Image& mask)
1375- : TransformedImage(ghash, original, surface_cache), color_(color), mask_(mask)
1376+ TextureCache* texture_cache, const RGBColor& color, const Image& mask)
1377+ : TransformedImage(ghash, original, texture_cache), color_(color), mask_(mask)
1378 {}
1379 virtual ~PlayerColoredImage() {}
1380
1381 // Implements TransformedImage.
1382- Surface* recalculate_surface() const override {
1383- return make_playerclr_surface(*original_.surface(), *mask_.surface(), color_);
1384+ Texture* recalculate_texture() const override {
1385+ return make_playerclr_texture(*original_.texture(), *mask_.texture(), color_);
1386 }
1387
1388 private:
1389@@ -425,7 +427,7 @@
1390 if (g_gr->images().has(new_hash))
1391 return g_gr->images().get(new_hash);
1392 return
1393- g_gr->images().insert(new ResizedImage(new_hash, *original, &g_gr->surfaces(), w, h));
1394+ g_gr->images().insert(new ResizedImage(new_hash, *original, &g_gr->textures(), w, h));
1395 }
1396
1397 const Image* gray_out(const Image* original) {
1398@@ -433,7 +435,7 @@
1399 if (g_gr->images().has(new_hash))
1400 return g_gr->images().get(new_hash);
1401 return
1402- g_gr->images().insert(new GrayedOutImage(new_hash, *original, &g_gr->surfaces()));
1403+ g_gr->images().insert(new GrayedOutImage(new_hash, *original, &g_gr->textures()));
1404 }
1405
1406 const Image* change_luminosity(const Image* original, float factor, bool halve_alpha) {
1407@@ -443,7 +445,7 @@
1408 return g_gr->images().get(new_hash);
1409 return
1410 g_gr->images().insert
1411- (new ChangeLuminosityImage(new_hash, *original, &g_gr->surfaces(), factor, halve_alpha));
1412+ (new ChangeLuminosityImage(new_hash, *original, &g_gr->textures(), factor, halve_alpha));
1413 }
1414
1415 const Image* player_colored(const RGBColor& clr, const Image* original, const Image* mask) {
1416@@ -455,7 +457,7 @@
1417 return g_gr->images().get(new_hash);
1418 return
1419 g_gr->images().insert
1420- (new PlayerColoredImage(new_hash, *original, &g_gr->surfaces(), clr, *mask));
1421+ (new PlayerColoredImage(new_hash, *original, &g_gr->textures(), clr, *mask));
1422 }
1423
1424 } // namespace ImageTransformations
1425
1426=== modified file 'src/graphic/in_memory_image.cc'
1427--- src/graphic/in_memory_image.cc 2014-07-26 10:43:23 +0000
1428+++ src/graphic/in_memory_image.cc 2014-11-24 07:32:35 +0000
1429@@ -22,15 +22,15 @@
1430 #include <memory>
1431
1432 #include "graphic/image.h"
1433-#include "graphic/surface.h"
1434+#include "graphic/texture.h"
1435
1436 using namespace std;
1437
1438 // An Image implementation the does !not! cache its Surface in the
1439-// SurfaceCache. Avoid using this whenever possible and also do not store it in
1440+// TextureCache. Avoid using this whenever possible and also do not store it in
1441 // the ImageCache.
1442 //
1443-// This is only used when the surface can not be easily recalculated on the fly
1444+// This is only used when the texture can not be easily recalculated on the fly
1445 // or if ownership of the image is managed by the caller itself. Note that this
1446 // is always tricky because Widelands assumes in many places that Images can be
1447 // relied to exist forever. So when you pass out a pointer to your
1448@@ -38,24 +38,24 @@
1449 // or prepare for core dumps.
1450 class InMemoryImage : public Image {
1451 public:
1452- InMemoryImage(const string& ghash, Surface* surf) :
1453- hash_(ghash), surf_(surf) {}
1454+ InMemoryImage(const string& ghash, Texture* texture) :
1455+ hash_(ghash), texture_(texture) {}
1456 virtual ~InMemoryImage() {
1457 }
1458
1459 // Implements Image.
1460- uint16_t width() const override {return surf_->width();}
1461- uint16_t height() const override {return surf_->height();}
1462+ uint16_t width() const override {return texture_->width();}
1463+ uint16_t height() const override {return texture_->height();}
1464 // Note: hash will mostly be dummy values for this implementation. It should
1465 // not wind up in ImageCache, otherwise the ownership question is not clear.
1466 const string& hash() const override {return hash_;}
1467- Surface* surface() const override {return surf_.get();}
1468+ Texture* texture() const override {return texture_.get();}
1469
1470 private:
1471 const string hash_;
1472- std::unique_ptr<Surface> surf_;
1473+ std::unique_ptr<Texture> texture_;
1474 };
1475
1476-const Image* new_in_memory_image(const string& hash, Surface* surf) {
1477- return new InMemoryImage(hash, surf);
1478+const Image* new_in_memory_image(const string& hash, Texture* texture) {
1479+ return new InMemoryImage(hash, texture);
1480 }
1481
1482=== modified file 'src/graphic/in_memory_image.h'
1483--- src/graphic/in_memory_image.h 2014-07-05 16:41:51 +0000
1484+++ src/graphic/in_memory_image.h 2014-11-24 07:32:35 +0000
1485@@ -22,9 +22,9 @@
1486
1487 #include <string>
1488
1489+class Texture;
1490 class Image;
1491-class Surface;
1492
1493-const Image* new_in_memory_image(const std::string& hash, Surface* surf);
1494+const Image* new_in_memory_image(const std::string& hash, Texture* texture);
1495
1496 #endif // end of include guard: WL_GRAPHIC_IN_MEMORY_IMAGE_H
1497
1498=== modified file 'src/graphic/minimap_renderer.cc'
1499--- src/graphic/minimap_renderer.cc 2014-09-27 18:53:55 +0000
1500+++ src/graphic/minimap_renderer.cc 2014-11-24 07:32:35 +0000
1501@@ -27,7 +27,7 @@
1502 #include "graphic/graphic.h"
1503 #include "graphic/image.h"
1504 #include "graphic/in_memory_image.h"
1505-#include "graphic/surface.h"
1506+#include "graphic/terrain_texture.h"
1507 #include "graphic/texture.h"
1508 #include "logic/field.h"
1509 #include "logic/map.h"
1510@@ -154,16 +154,16 @@
1511
1512 // Does the actual work of drawing the minimap.
1513 void draw_minimap_int
1514- (Surface* surface, const Widelands::EditorGameBase& egbase,
1515+ (Texture* texture, const Widelands::EditorGameBase& egbase,
1516 const Widelands::Player* player, const Point& viewpoint, MiniMapLayer layers)
1517 {
1518 const Widelands::Map & map = egbase.map();
1519
1520- uint8_t* const pixels = surface->get_pixels();
1521- const SDL_PixelFormat& format = surface->format();
1522- const uint16_t pitch = surface->get_pitch();
1523- const uint16_t surface_h = surface->height();
1524- const uint16_t surface_w = surface->width();
1525+ uint8_t* const pixels = texture->get_pixels();
1526+ const SDL_PixelFormat& format = texture->format();
1527+ const uint16_t pitch = texture->get_pitch();
1528+ const uint16_t surface_h = texture->height();
1529+ const uint16_t surface_w = texture->width();
1530
1531 // size of the display frame
1532 int32_t xsize = g_gr->get_xres() / TRIANGLE_WIDTH / 2;
1533@@ -258,29 +258,29 @@
1534
1535 } // namespace
1536
1537-std::unique_ptr<Surface> draw_minimap(const EditorGameBase& egbase,
1538+std::unique_ptr<Texture> draw_minimap(const EditorGameBase& egbase,
1539 const Player* player,
1540 const Point& viewpoint,
1541 MiniMapLayer layers) {
1542 // First create a temporary SDL Surface to draw the minimap.
1543 // TODO(unknown): Currently the minimap is redrawn every frame. That is not really
1544- // necesary. The created surface could be cached and only redrawn two
1545+ // necesary. The created texture could be cached and only redrawn two
1546 // or three times per second
1547 const Map& map = egbase.map();
1548 const int16_t map_w = (layers & MiniMapLayer::Zoom2) ? map.get_width() * 2 : map.get_width();
1549 const int16_t map_h = (layers & MiniMapLayer::Zoom2) ? map.get_height() * 2 : map.get_height();
1550
1551- Surface* surface = Surface::create(map_w, map_h);
1552- assert(surface->format().BytesPerPixel == sizeof(uint32_t));
1553-
1554- surface->fill_rect(Rect(0, 0, surface->width(), surface->height()), RGBAColor(0, 0, 0, 255));
1555- surface->lock(Surface::Lock_Normal);
1556-
1557- draw_minimap_int(surface, egbase, player, viewpoint, layers);
1558-
1559- surface->unlock(Surface::Unlock_Update);
1560-
1561- return std::unique_ptr<Surface>(surface);
1562+ Texture* texture = new Texture(map_w, map_h);
1563+ assert(texture->format().BytesPerPixel == sizeof(uint32_t));
1564+
1565+ texture->fill_rect(Rect(0, 0, texture->width(), texture->height()), RGBAColor(0, 0, 0, 255));
1566+ texture->lock(Surface::Lock_Normal);
1567+
1568+ draw_minimap_int(texture, egbase, player, viewpoint, layers);
1569+
1570+ texture->unlock(Surface::Unlock_Update);
1571+
1572+ return std::unique_ptr<Texture>(texture);
1573 }
1574
1575 void write_minimap_image
1576@@ -309,8 +309,8 @@
1577 viewpoint.y -= map_h / 2;
1578
1579 // Render minimap
1580- std::unique_ptr<Surface> surface(draw_minimap(egbase, player, viewpoint, layers));
1581- std::unique_ptr<const Image> image(new_in_memory_image("minimap", surface.release()));
1582+ std::unique_ptr<Texture> texture(draw_minimap(egbase, player, viewpoint, layers));
1583+ std::unique_ptr<const Image> image(new_in_memory_image("minimap", texture.release()));
1584 g_gr->save_png(image.get(), streamwrite);
1585 image.reset();
1586 }
1587
1588=== modified file 'src/graphic/minimap_renderer.h'
1589--- src/graphic/minimap_renderer.h 2014-09-27 18:53:55 +0000
1590+++ src/graphic/minimap_renderer.h 2014-11-24 07:32:35 +0000
1591@@ -22,9 +22,9 @@
1592
1593 #include <memory>
1594
1595-#include "graphic/rendertarget.h"
1596-
1597 class StreamWrite;
1598+class Texture;
1599+struct Point;
1600
1601 namespace Widelands {
1602 class Player;
1603@@ -56,7 +56,7 @@
1604 /// Render the minimap. If player is not nullptr, it renders from that player's
1605 /// point of view.
1606 /// \param viewpoint: top left corner in map coordinates
1607-std::unique_ptr<Surface> draw_minimap
1608+std::unique_ptr<Texture> draw_minimap
1609 (const Widelands::EditorGameBase& egbase, const Widelands::Player* player,
1610 const Point& viewpoint, MiniMapLayer layers);
1611
1612
1613=== modified file 'src/graphic/rendertarget.cc'
1614--- src/graphic/rendertarget.cc 2014-09-10 13:03:40 +0000
1615+++ src/graphic/rendertarget.cc 2014-11-24 07:32:35 +0000
1616@@ -166,7 +166,7 @@
1617 * If the source surface contains a alpha channel this is used during
1618 * the blit.
1619 */
1620-void RenderTarget::blit(const Point& dst, const Image* image, Composite cm, UI::Align align)
1621+void RenderTarget::blit(const Point& dst, const Image* image, BlendMode blend_mode, UI::Align align)
1622 {
1623 Point dstpoint(dst);
1624
1625@@ -175,14 +175,14 @@
1626 Rect srcrc(Point(0, 0), image->width(), image->height());
1627
1628 if (to_surface_geometry(&dstpoint, &srcrc))
1629- m_surface->blit(dstpoint, image->surface(), srcrc, cm);
1630+ m_surface->blit(dstpoint, image->texture(), srcrc, blend_mode);
1631 }
1632
1633 /**
1634 * Like \ref blit, but use only a sub-rectangle of the source image.
1635 */
1636 void RenderTarget::blitrect
1637- (const Point& dst, const Image* image, const Rect& gsrcrc, Composite cm)
1638+ (const Point& dst, const Image* image, const Rect& gsrcrc, BlendMode blend_mode)
1639 {
1640 assert(0 <= gsrcrc.x);
1641 assert(0 <= gsrcrc.y);
1642@@ -196,7 +196,7 @@
1643
1644 Point dstpt(dst);
1645 if (to_surface_geometry(&dstpt, &srcrc))
1646- m_surface->blit(dstpt, image->surface(), srcrc, cm);
1647+ m_surface->blit(dstpt, image->texture(), srcrc, blend_mode);
1648 }
1649
1650 /**
1651@@ -205,7 +205,7 @@
1652 * The pixel from ofs inside image is placed at the top-left corner of
1653 * the filled rectangle.
1654 */
1655-void RenderTarget::tile(const Rect& rect, const Image* image, const Point& gofs, Composite cm)
1656+void RenderTarget::tile(const Rect& rect, const Image* image, const Point& gofs, BlendMode blend_mode)
1657 {
1658 int32_t srcw = image->width();
1659 int32_t srch = image->height();
1660@@ -251,7 +251,7 @@
1661 if (tx + srcrc.w > r.w)
1662 srcrc.w = r.w - tx;
1663
1664- m_surface->blit(r.top_left() + Point(tx, ty), image->surface(), srcrc, cm);
1665+ m_surface->blit(r.top_left() + Point(tx, ty), image->texture(), srcrc, blend_mode);
1666
1667 tx += srcrc.w;
1668
1669
1670=== modified file 'src/graphic/rendertarget.h'
1671--- src/graphic/rendertarget.h 2014-11-02 14:11:52 +0000
1672+++ src/graphic/rendertarget.h 2014-11-24 07:32:35 +0000
1673@@ -24,8 +24,8 @@
1674
1675 #include "base/rect.h"
1676 #include "graphic/align.h"
1677+#include "graphic/blend_mode.h"
1678 #include "graphic/color.h"
1679-#include "graphic/compositemode.h"
1680 #include "graphic/image.h"
1681
1682 class Surface;
1683@@ -64,9 +64,20 @@
1684 void fill_rect(const Rect&, const RGBAColor&);
1685 void brighten_rect(const Rect&, int32_t factor);
1686
1687- void blit(const Point& dst, const Image* image, Composite cm = CM_UseAlpha, UI::Align = UI::Align_TopLeft);
1688- void blitrect(const Point& dst, const Image* image, const Rect& src, Composite cm = CM_UseAlpha);
1689- void tile(const Rect&, const Image* image, const Point& ofs, Composite cm = CM_UseAlpha);
1690+ void blit(const Point& dst,
1691+ const Image* image,
1692+ BlendMode blend_mode = BlendMode::UseAlpha,
1693+ UI::Align = UI::Align_TopLeft);
1694+
1695+ void blitrect(const Point& dst,
1696+ const Image* image,
1697+ const Rect& src,
1698+ BlendMode blend_mode = BlendMode::UseAlpha);
1699+
1700+ void tile(const Rect&,
1701+ const Image* image,
1702+ const Point& ofs,
1703+ BlendMode blend_mode = BlendMode::UseAlpha);
1704
1705 void drawanim(const Point& dst, uint32_t animation, uint32_t time, const Widelands::Player* = 0);
1706 void drawanimrect
1707
1708=== renamed file 'src/graphic/gl/surface_screen.cc' => 'src/graphic/screen.cc'
1709--- src/graphic/gl/surface_screen.cc 2014-11-22 21:31:21 +0000
1710+++ src/graphic/screen.cc 2014-11-24 07:32:35 +0000
1711@@ -16,20 +16,20 @@
1712 * Foundation, Inc., 51 Franklin Street, Fifth Floor, Boston, MA 02110-1301, USA.
1713 */
1714
1715-#include "graphic/gl/surface_screen.h"
1716+#include "graphic/screen.h"
1717
1718 #include <algorithm>
1719 #include <cassert>
1720
1721 #include "graphic/gl/utils.h"
1722
1723-GLSurfaceScreen::GLSurfaceScreen(uint16_t w, uint16_t h)
1724+Screen::Screen(uint16_t w, uint16_t h)
1725 {
1726 m_w = w;
1727 m_h = h;
1728 }
1729
1730-void GLSurfaceScreen::pixel_to_gl(float* x, float* y) const {
1731+void Screen::pixel_to_gl(float* x, float* y) const {
1732 *x = (*x / m_w) * 2. - 1.;
1733 *y = 1. - (*y / m_h) * 2.;
1734 }
1735@@ -38,7 +38,7 @@
1736 * Swap order of rows in m_pixels, to compensate for the upside-down nature of the
1737 * OpenGL coordinate system.
1738 */
1739-void GLSurfaceScreen::swap_rows()
1740+void Screen::swap_rows()
1741 {
1742 uint8_t * begin_row = m_pixels.get();
1743 uint8_t * end_row = m_pixels.get() + (m_w * (m_h - 1) * 4);
1744@@ -52,7 +52,7 @@
1745 }
1746 }
1747
1748-void GLSurfaceScreen::lock(Surface::LockMode mode)
1749+void Screen::lock(Surface::LockMode mode)
1750 {
1751 assert(!m_pixels);
1752
1753@@ -70,7 +70,7 @@
1754 }
1755 }
1756
1757-void GLSurfaceScreen::unlock(Surface::UnlockMode mode)
1758+void Screen::unlock(Surface::UnlockMode mode)
1759 {
1760 assert(m_pixels);
1761
1762
1763=== renamed file 'src/graphic/gl/surface_screen.h' => 'src/graphic/screen.h'
1764--- src/graphic/gl/surface_screen.h 2014-11-22 21:31:21 +0000
1765+++ src/graphic/screen.h 2014-11-24 07:32:35 +0000
1766@@ -16,18 +16,18 @@
1767 * Foundation, Inc., 51 Franklin Street, Fifth Floor, Boston, MA 02110-1301, USA.
1768 */
1769
1770-#ifndef WL_GRAPHIC_GL_SURFACE_SCREEN_H
1771-#define WL_GRAPHIC_GL_SURFACE_SCREEN_H
1772+#ifndef WL_GRAPHIC_SCREEN_H
1773+#define WL_GRAPHIC_SCREEN_H
1774
1775 #include "graphic/surface.h"
1776
1777 /**
1778 * This surface represents the screen in OpenGL mode.
1779 */
1780-class GLSurfaceScreen : public Surface {
1781+class Screen : public Surface {
1782 public:
1783- GLSurfaceScreen(uint16_t w, uint16_t h);
1784- virtual ~GLSurfaceScreen() {}
1785+ Screen(uint16_t w, uint16_t h);
1786+ virtual ~Screen() {}
1787
1788 /// Interface implementations
1789 void lock(LockMode) override;
1790@@ -39,4 +39,4 @@
1791 void swap_rows();
1792 };
1793
1794-#endif // end of include guard:
1795+#endif // end of include guard: WL_GRAPHIC_SCREEN_H
1796
1797=== modified file 'src/graphic/surface.cc'
1798--- src/graphic/surface.cc 2014-11-22 21:31:21 +0000
1799+++ src/graphic/surface.cc 2014-11-24 07:32:35 +0000
1800@@ -30,18 +30,9 @@
1801 #include "graphic/gl/draw_line_program.h"
1802 #include "graphic/gl/draw_rect_program.h"
1803 #include "graphic/gl/fill_rect_program.h"
1804-#include "graphic/gl/surface_texture.h"
1805 #include "graphic/gl/utils.h"
1806 #include "graphic/graphic.h"
1807-
1808-
1809-Surface* Surface::create(SDL_Surface* surf) {
1810- return new GLSurfaceTexture(surf);
1811-}
1812-
1813-Surface* Surface::create(uint16_t w, uint16_t h) {
1814- return new GLSurfaceTexture(w, h);
1815-}
1816+#include "graphic/texture.h"
1817
1818
1819 uint16_t Surface::width() const {
1820@@ -167,12 +158,11 @@
1821 }
1822
1823 void Surface::blit
1824- (const Point& dst, const Surface* image, const Rect& srcrc, Composite cm)
1825+ (const Point& dst, const Texture* texture, const Rect& srcrc, BlendMode blend_mode)
1826 {
1827 glViewport(0, 0, width(), height());
1828
1829 // Source Rectangle.
1830- const GLSurfaceTexture* const texture = static_cast<const GLSurfaceTexture*>(image);
1831 FloatRect gl_src_rect;
1832 {
1833 float x1 = srcrc.x;
1834@@ -189,5 +179,5 @@
1835
1836 const FloatRect gl_dst_rect = to_opengl(Rect(dst.x, dst.y, srcrc.w, srcrc.h), ConversionMode::kExact);
1837
1838- BlitProgram::instance().draw(gl_dst_rect, gl_src_rect, texture->get_gl_texture(), cm);
1839+ BlitProgram::instance().draw(gl_dst_rect, gl_src_rect, texture->get_gl_texture(), blend_mode);
1840 }
1841
1842=== modified file 'src/graphic/surface.h'
1843--- src/graphic/surface.h 2014-11-22 21:31:21 +0000
1844+++ src/graphic/surface.h 2014-11-24 07:32:35 +0000
1845@@ -24,8 +24,10 @@
1846
1847 #include "base/macros.h"
1848 #include "base/rect.h"
1849+#include "graphic/blend_mode.h"
1850 #include "graphic/color.h"
1851-#include "graphic/compositemode.h"
1852+
1853+class Texture;
1854
1855 /**
1856 * Interface to a basic surfaces that can be used as destination for blitting and drawing.
1857@@ -33,13 +35,6 @@
1858 */
1859 class Surface {
1860 public:
1861- // Create a new surface from an SDL_Surface. Ownership is taken.
1862- static Surface* create(SDL_Surface*);
1863-
1864- // Create a new empty (that is randomly filled) Surface with the given
1865- // dimensions.
1866- static Surface* create(uint16_t w, uint16_t h);
1867-
1868 Surface() = default;
1869 virtual ~Surface() {}
1870
1871@@ -48,10 +43,13 @@
1872 uint16_t height() const;
1873
1874 /// This draws a part of another surface to this surface
1875- virtual void blit(const Point&, const Surface*, const Rect& srcrc, Composite cm = CM_UseAlpha);
1876+ virtual void blit(const Point&,
1877+ const Texture*,
1878+ const Rect& srcrc,
1879+ BlendMode blend_mode = BlendMode::UseAlpha);
1880
1881 /// Draws a filled rect to the surface. No blending takes place, the values
1882- //in the target are just replaced (i.e. / Composite would be CM_Copy).
1883+ // in the target are just replaced (i.e. / BlendMode would be BlendMode::Copy).
1884 virtual void fill_rect(const Rect&, const RGBAColor&);
1885
1886 /// Draws a rect (frame only) to the surface.
1887
1888=== renamed file 'src/graphic/texture.cc' => 'src/graphic/terrain_texture.cc'
1889--- src/graphic/texture.cc 2014-11-23 12:01:59 +0000
1890+++ src/graphic/terrain_texture.cc 2014-11-24 07:32:35 +0000
1891@@ -17,7 +17,7 @@
1892 *
1893 */
1894
1895-#include "graphic/texture.h"
1896+#include "graphic/terrain_texture.h"
1897
1898 #include <SDL_image.h>
1899
1900@@ -25,6 +25,7 @@
1901 #include "base/log.h"
1902 #include "base/wexception.h"
1903 #include "graphic/image_io.h"
1904+#include "graphic/texture.h"
1905 #include "io/fileread.h"
1906 #include "io/filesystem/layered_filesystem.h"
1907
1908@@ -35,7 +36,7 @@
1909 * Currently it converts a 16 bit image to a 8 bit texture. This should
1910 * be changed to load a 8 bit file directly, however.
1911 */
1912-Texture::Texture(const std::vector<std::string>& texture_files, const uint32_t frametime)
1913+TerrainTexture::TerrainTexture(const std::vector<std::string>& texture_files, const uint32_t frametime)
1914 : m_frame_num(0), m_frametime(frametime) {
1915 if (texture_files.empty()) {
1916 throw wexception("No images for texture.");
1917@@ -47,23 +48,23 @@
1918 }
1919
1920 m_texture_image = fname;
1921- SDL_Surface* surf = load_image_as_sdl_surface(fname, g_fs);
1922- if (!surf) {
1923+ SDL_Surface* sdl_surface = load_image_as_sdl_surface(fname, g_fs);
1924+ if (!sdl_surface) {
1925 throw wexception(
1926 "WARNING: Failed to load texture frame %s: %s\n", fname.c_str(), IMG_GetError());
1927 }
1928- if (surf->w != TEXTURE_WIDTH || surf->h != TEXTURE_HEIGHT) {
1929- SDL_FreeSurface(surf);
1930+ if (sdl_surface->w != kTextureWidth || sdl_surface->h != kTextureHeight) {
1931+ SDL_FreeSurface(sdl_surface);
1932 throw wexception("WARNING: %s: texture must be %ix%i pixels big\n",
1933 fname.c_str(),
1934- TEXTURE_WIDTH,
1935- TEXTURE_HEIGHT);
1936+ kTextureWidth,
1937+ kTextureHeight);
1938 }
1939
1940 // calculate shades on the first frame
1941- if (m_gl_textures.empty()) {
1942- uint8_t top_left_pixel = static_cast<uint8_t*>(surf->pixels)[0];
1943- SDL_Color top_left_pixel_color = surf->format->palette->colors[top_left_pixel];
1944+ if (m_textures.empty()) {
1945+ uint8_t top_left_pixel = static_cast<uint8_t*>(sdl_surface->pixels)[0];
1946+ SDL_Color top_left_pixel_color = sdl_surface->format->palette->colors[top_left_pixel];
1947 for (int i = -128; i < 128; i++) {
1948 const int shade = 128 + i;
1949 int32_t r = std::min<int32_t>((top_left_pixel_color.r * shade) >> 7, 255);
1950@@ -72,24 +73,26 @@
1951 m_minimap_colors[shade] = RGBColor(r, g, b);
1952 }
1953 }
1954- m_gl_textures.emplace_back(new GLSurfaceTexture(surf));
1955+ m_textures.emplace_back(new Texture(sdl_surface));
1956 }
1957
1958- if (m_gl_textures.empty())
1959- throw wexception("Texture has no frames");
1960+ if (m_textures.empty())
1961+ throw wexception("TerrainTexture has no frames");
1962 }
1963
1964-/**
1965- * Return the basic terrain colour to be used in the minimap.
1966-*/
1967-RGBColor Texture::get_minimap_color(int8_t shade) {
1968+RGBColor TerrainTexture::get_minimap_color(int8_t shade) {
1969 return m_minimap_colors[128 + shade];
1970 }
1971
1972-/**
1973- * Set the current frame according to the game time.
1974- */
1975-void Texture::animate(uint32_t time)
1976+void TerrainTexture::animate(uint32_t time)
1977 {
1978- m_frame_num = (time / m_frametime) % m_gl_textures.size();
1979+ m_frame_num = (time / m_frametime) % m_textures.size();
1980+}
1981+
1982+const std::string& TerrainTexture::get_texture_image() const {
1983+ return m_texture_image;
1984+}
1985+
1986+const Texture& TerrainTexture::texture() const {
1987+ return *m_textures.at(m_frame_num);
1988 }
1989
1990=== renamed file 'src/graphic/texture.h' => 'src/graphic/terrain_texture.h'
1991--- src/graphic/texture.h 2014-11-22 21:31:21 +0000
1992+++ src/graphic/terrain_texture.h 2014-11-24 07:32:35 +0000
1993@@ -17,8 +17,8 @@
1994 *
1995 */
1996
1997-#ifndef WL_GRAPHIC_TEXTURE_H
1998-#define WL_GRAPHIC_TEXTURE_H
1999+#ifndef WL_GRAPHIC_TERRAIN_TEXTURE_H
2000+#define WL_GRAPHIC_TERRAIN_TEXTURE_H
2001
2002 #include <memory>
2003 #include <string>
2004@@ -27,35 +27,28 @@
2005 #include <stdint.h>
2006
2007 #include "graphic/colormap.h"
2008-#include "graphic/gl/surface_texture.h"
2009-
2010-/// Textures have a fixed size and are squares.
2011-/// TEXTURE_HEIGHT is just defined for easier understanding of the code.
2012-#define TEXTURE_WIDTH 64
2013-#define TEXTURE_HEIGHT TEXTURE_WIDTH
2014-
2015-/** struct Texture
2016-*
2017-* Texture represents are terrain texture, which is strictly
2018-* TEXTURE_WIDTH by TEXTURE_HEIGHT pixels in size. It uses 8 bit color, and
2019-* a pointer to the corresponding palette and color lookup table is
2020-* provided.
2021-*
2022-* Currently, this is initialized from a 16 bit bitmap. This should be
2023-* changed to load 8 bit bitmaps directly.
2024-*/
2025-struct Texture {
2026- Texture(const std::vector<std::string>& texture_files, uint32_t frametime);
2027-
2028- const std::string& get_texture_image() const {
2029- return m_texture_image;
2030- }
2031- uint32_t get_texture() const {
2032- return m_gl_textures.at(m_frame_num)->get_gl_texture();
2033- }
2034-
2035+
2036+class Texture;
2037+
2038+/// TerrainTextures have a fixed size and are squares.
2039+constexpr int kTextureWidth = 64;
2040+constexpr int kTextureHeight = kTextureWidth;
2041+
2042+// TerrainTexture represents are terrain texture, which is strictly kTextureWidth by
2043+// kTextureHeight pixels in size.
2044+struct TerrainTexture {
2045+ TerrainTexture(const std::vector<std::string>& texture_files, uint32_t frametime);
2046+
2047+ // Returns the path to a representative image for this texture.
2048+ const std::string& get_texture_image() const;
2049+
2050+ // Returns the texture for the current animation phase.
2051+ const Texture& texture() const;
2052+
2053+ // Return the basic terrain colour to be used in the minimap.
2054 RGBColor get_minimap_color(int8_t shade);
2055
2056+ // Set the current frame according to the game time.
2057 void animate(uint32_t time);
2058
2059 private:
2060@@ -63,7 +56,7 @@
2061 int32_t m_frame_num;
2062 std::string m_texture_image;
2063 uint32_t m_frametime;
2064- std::vector<std::unique_ptr<GLSurfaceTexture>> m_gl_textures;
2065+ std::vector<std::unique_ptr<Texture>> m_textures;
2066 };
2067
2068-#endif // end of include guard: WL_GRAPHIC_TEXTURE_H
2069+#endif // end of include guard: WL_GRAPHIC_TERRAIN_TEXTURE_H
2070
2071=== modified file 'src/graphic/text/rt_render.cc'
2072--- src/graphic/text/rt_render.cc 2014-11-02 14:11:52 +0000
2073+++ src/graphic/text/rt_render.cc 2014-11-24 07:32:35 +0000
2074@@ -32,10 +32,10 @@
2075 #include "base/rect.h"
2076 #include "graphic/image_cache.h"
2077 #include "graphic/image_io.h"
2078-#include "graphic/surface.h"
2079 #include "graphic/text/font_io.h"
2080 #include "graphic/text/rt_parse.h"
2081 #include "graphic/text/textstream.h"
2082+#include "graphic/texture.h"
2083
2084
2085 using namespace std;
2086@@ -108,7 +108,7 @@
2087 virtual uint16_t width() = 0;
2088 virtual uint16_t height() = 0;
2089 virtual uint16_t hotspot_y() = 0;
2090- virtual Surface* render(SurfaceCache* surface_cache) = 0;
2091+ virtual Texture* render(TextureCache* texture_cache) = 0;
2092
2093 virtual bool is_non_mandatory_space() {return false;}
2094 virtual bool is_expanding() {return false;}
2095@@ -313,7 +313,7 @@
2096 return rv;
2097 }
2098
2099- Surface* render(SurfaceCache* surface_cache) override;
2100+ Texture* render(TextureCache* texture_cache) override;
2101
2102 protected:
2103 uint16_t m_w, m_h;
2104@@ -330,10 +330,10 @@
2105 uint16_t TextNode::hotspot_y() {
2106 return m_font.ascent(m_s.font_style);
2107 }
2108-Surface* TextNode::render(SurfaceCache* surface_cache) {
2109- const Surface& img = m_font.render(m_txt, m_s.font_color, m_s.font_style, surface_cache);
2110- Surface* rv = Surface::create(img.width(), img.height());
2111- rv->blit(Point(0, 0), &img, Rect(0, 0, img.width(), img.height()), CM_Copy);
2112+Texture* TextNode::render(TextureCache* texture_cache) {
2113+ const Texture& img = m_font.render(m_txt, m_s.font_color, m_s.font_style, texture_cache);
2114+ Texture* rv = new Texture(img.width(), img.height());
2115+ rv->blit(Point(0, 0), &img, Rect(0, 0, img.width(), img.height()), BlendMode::Copy);
2116 return rv;
2117 }
2118
2119@@ -348,7 +348,7 @@
2120 m_w = w;
2121 }
2122 virtual ~FillingTextNode() {}
2123- Surface* render(SurfaceCache*) override;
2124+ Texture* render(TextureCache*) override;
2125
2126 bool is_expanding() override {return m_expanding;}
2127 void set_w(uint16_t w) override {m_w = w;}
2128@@ -356,12 +356,12 @@
2129 private:
2130 bool m_expanding;
2131 };
2132-Surface* FillingTextNode::render(SurfaceCache* surface_cache) {
2133- const Surface& t = m_font.render(m_txt, m_s.font_color, m_s.font_style, surface_cache);
2134- Surface* rv = Surface::create(m_w, m_h);
2135+Texture* FillingTextNode::render(TextureCache* texture_cache) {
2136+ const Texture& t = m_font.render(m_txt, m_s.font_color, m_s.font_style, texture_cache);
2137+ Texture* rv = new Texture(m_w, m_h);
2138 for (uint16_t curx = 0; curx < m_w; curx += t.width()) {
2139 Rect srcrect(Point(0, 0), min<int>(t.width(), m_w - curx), m_h);
2140- rv->blit(Point(curx, 0), &t, srcrect, CM_Copy);
2141+ rv->blit(Point(curx, 0), &t, srcrect, BlendMode::Copy);
2142 }
2143 return rv;
2144 }
2145@@ -375,13 +375,13 @@
2146 WordSpacerNode(IFont& font, NodeStyle& ns) : TextNode(font, ns, " ") {}
2147 static void show_spaces(bool t) {m_show_spaces = t;}
2148
2149- Surface* render(SurfaceCache* surface_cache) override {
2150+ Texture* render(TextureCache* texture_cache) override {
2151 if (m_show_spaces) {
2152- Surface* rv = Surface::create(m_w, m_h);
2153+ Texture* rv = new Texture(m_w, m_h);
2154 rv->fill_rect(Rect(0, 0, m_w, m_h), RGBAColor(0xff, 0, 0, 0xff));
2155 return rv;
2156 }
2157- return TextNode::render(surface_cache);
2158+ return TextNode::render(texture_cache);
2159 }
2160 bool is_non_mandatory_space() override {return true;}
2161
2162@@ -400,7 +400,7 @@
2163 uint16_t height() override {return 0;}
2164 uint16_t width() override {return INFINITE_WIDTH; }
2165 uint16_t hotspot_y() override {return 0;}
2166- Surface* render(SurfaceCache* /* surface_cache */) override {
2167+ Texture* render(TextureCache* /* texture_cache */) override {
2168 assert(false);
2169 throw RenderError("This should never be called. This is a bug, please submit a report.");
2170 }
2171@@ -418,8 +418,8 @@
2172 uint16_t height() override {return m_h;}
2173 uint16_t width() override {return m_w;}
2174 uint16_t hotspot_y() override {return m_h;}
2175- Surface* render(SurfaceCache* /* surface_cache */) override {
2176- Surface* rv = Surface::create(m_w, m_h);
2177+ Texture* render(TextureCache* /* texture_cache */) override {
2178+ Texture* rv = new Texture(m_w, m_h);
2179
2180 // Draw background image (tiling)
2181 if (m_bg) {
2182@@ -430,7 +430,7 @@
2183 dst.y = 0;
2184 srcrect.w = min<int>(m_bg->width(), m_w - curx);
2185 srcrect.h = m_h;
2186- rv->blit(dst, m_bg->surface(), srcrect, CM_Copy);
2187+ rv->blit(dst, m_bg->texture(), srcrect, BlendMode::Copy);
2188 }
2189 } else {
2190 rv->fill_rect(Rect(0, 0, m_w, m_h), RGBAColor(255, 255, 255, 0));
2191@@ -468,8 +468,8 @@
2192 uint16_t width() override {return m_w + m_margin.left + m_margin.right;}
2193 uint16_t height() override {return m_h + m_margin.top + m_margin.bottom;}
2194 uint16_t hotspot_y() override {return height();}
2195- Surface* render(SurfaceCache* surface_cache) override {
2196- Surface* rv = Surface::create(width(), height());
2197+ Texture* render(TextureCache* texture_cache) override {
2198+ Texture* rv = new Texture(width(), height());
2199 rv->fill_rect(Rect(0, 0, rv->width(), rv->height()), RGBAColor(255, 255, 255, 0));
2200
2201 // Draw Solid background Color
2202@@ -490,20 +490,20 @@
2203 dst.x = curx; dst.y = cury;
2204 src.w = min<int>(m_bg_img->width(), m_w + m_margin.left - curx);
2205 src.h = min<int>(m_bg_img->height(), m_h + m_margin.top - cury);
2206- rv->blit(dst, m_bg_img->surface(), src, CM_Copy);
2207+ rv->blit(dst, m_bg_img->texture(), src, BlendMode::Copy);
2208 }
2209 }
2210 set_alpha = false;
2211 }
2212
2213 for (RenderNode* n : m_nodes_to_render) {
2214- Surface* nsur = n->render(surface_cache);
2215- if (nsur) {
2216+ Texture* node_texture = n->render(texture_cache);
2217+ if (node_texture) {
2218 Point dst = Point(n->x() + m_margin.left, n->y() + m_margin.top);
2219- Rect src = Rect(0, 0, nsur->width(), nsur->height());
2220+ Rect src = Rect(0, 0, node_texture->width(), node_texture->height());
2221
2222- rv->blit(dst, nsur, src, set_alpha ? CM_Copy : CM_UseAlpha);
2223- delete nsur;
2224+ rv->blit(dst, node_texture, src, set_alpha ? BlendMode::Copy : BlendMode::UseAlpha);
2225+ delete node_texture;
2226 }
2227 delete n;
2228 }
2229@@ -545,15 +545,15 @@
2230 uint16_t width() override {return m_image.width();}
2231 uint16_t height() override {return m_image.height();}
2232 uint16_t hotspot_y() override {return m_image.height();}
2233- Surface* render(SurfaceCache* surface_cache) override;
2234+ Texture* render(TextureCache* texture_cache) override;
2235
2236 private:
2237 const Image& m_image;
2238 };
2239
2240-Surface* ImgRenderNode::render(SurfaceCache* /* surface_cache */) {
2241- Surface* rv = Surface::create(m_image.width(), m_image.height());
2242- rv->blit(Point(0, 0), m_image.surface(), Rect(0, 0, m_image.width(), m_image.height()), CM_Copy);
2243+Texture* ImgRenderNode::render(TextureCache* /* texture_cache */) {
2244+ Texture* rv = new Texture(m_image.width(), m_image.height());
2245+ rv->blit(Point(0, 0), m_image.texture(), Rect(0, 0, m_image.width(), m_image.height()), BlendMode::Copy);
2246 return rv;
2247 }
2248 // End: Helper Stuff
2249@@ -946,9 +946,9 @@
2250 return i->second(tag, fc, ns, image_cache);
2251 }
2252
2253-Renderer::Renderer(ImageCache* image_cache, SurfaceCache* surface_cache) :
2254+Renderer::Renderer(ImageCache* image_cache, TextureCache* texture_cache) :
2255 font_cache_(new FontCache()), parser_(new Parser()),
2256- image_cache_(image_cache), surface_cache_(surface_cache) {
2257+ image_cache_(image_cache), texture_cache_(texture_cache) {
2258 }
2259
2260 Renderer::~Renderer() {
2261@@ -976,10 +976,10 @@
2262 return nodes[0];
2263 }
2264
2265-Surface* Renderer::render(const string& text, uint16_t width, const TagSet& allowed_tags) {
2266+Texture* Renderer::render(const string& text, uint16_t width, const TagSet& allowed_tags) {
2267 std::unique_ptr<RenderNode> node(layout_(text, width, allowed_tags));
2268
2269- return node->render(surface_cache_);
2270+ return node->render(texture_cache_);
2271 }
2272
2273 IRefMap* Renderer::make_reference_map(const string& text, uint16_t width, const TagSet& allowed_tags) {
2274
2275=== modified file 'src/graphic/text/rt_render.h'
2276--- src/graphic/text/rt_render.h 2014-09-14 11:31:58 +0000
2277+++ src/graphic/text/rt_render.h 2014-11-24 07:32:35 +0000
2278@@ -29,8 +29,9 @@
2279 #include "graphic/color.h"
2280 #include "graphic/image.h"
2281
2282-class SurfaceCache;
2283+class Texture;
2284 class ImageCache;
2285+class TextureCache;
2286
2287 namespace RT {
2288
2289@@ -58,7 +59,7 @@
2290 virtual ~IFont() {}
2291
2292 virtual void dimensions(const std::string&, int, uint16_t *, uint16_t *) = 0;
2293- virtual const Surface& render(const std::string&, const RGBColor& clr, int, SurfaceCache*) = 0;
2294+ virtual const Texture& render(const std::string&, const RGBColor& clr, int, TextureCache*) = 0;
2295
2296 virtual uint16_t ascent(int) const = 0;
2297 };
2298@@ -81,13 +82,13 @@
2299 class Renderer {
2300 public:
2301 // Ownership is not taken.
2302- Renderer(ImageCache* image_cache, SurfaceCache* surface_cache);
2303+ Renderer(ImageCache* image_cache, TextureCache* texture_cache);
2304 ~Renderer();
2305
2306 // Render the given string in the given width. Restricts the allowed tags to
2307- // the ones in TagSet. The renderer does not do caching in the SurfaceCache
2308+ // the ones in TagSet. The renderer does not do caching in the TextureCache
2309 // for its individual nodes, but the font render does.
2310- Surface* render(const std::string&, uint16_t width, const TagSet& tagset = TagSet());
2311+ Texture* render(const std::string&, uint16_t width, const TagSet& tagset = TagSet());
2312
2313 // Returns a reference map of the clickable hyperlinks in the image. This
2314 // will do no caching and needs to do all layouting, so do not call this too
2315@@ -100,7 +101,7 @@
2316 std::unique_ptr<FontCache> font_cache_;
2317 std::unique_ptr<Parser> parser_;
2318 ImageCache* const image_cache_; // Not owned.
2319- SurfaceCache* const surface_cache_; // Not owned.
2320+ TextureCache* const texture_cache_; // Not owned.
2321 };
2322
2323 }
2324
2325=== modified file 'src/graphic/text/sdl_ttf_font.cc'
2326--- src/graphic/text/sdl_ttf_font.cc 2014-11-23 10:13:14 +0000
2327+++ src/graphic/text/sdl_ttf_font.cc 2014-11-24 07:32:35 +0000
2328@@ -24,9 +24,9 @@
2329 #include <boost/format.hpp>
2330
2331 #include "graphic/sdl_utils.h"
2332-#include "graphic/surface.h"
2333-#include "graphic/surface_cache.h"
2334 #include "graphic/text/rt_errors.h"
2335+#include "graphic/texture.h"
2336+#include "graphic/texture_cache.h"
2337
2338 using namespace std;
2339 using namespace boost;
2340@@ -58,13 +58,13 @@
2341 *gw = w; *gh = h;
2342 }
2343
2344-const Surface& SdlTtfFont::render
2345- (const string& txt, const RGBColor& clr, int style, SurfaceCache* surface_cache) {
2346+const Texture& SdlTtfFont::render
2347+ (const string& txt, const RGBColor& clr, int style, TextureCache* texture_cache) {
2348 const string hash =
2349 (boost::format("%s:%s:%i:%02x%02x%02x:%i") % font_name_ % ptsize_ % txt %
2350 static_cast<int>(clr.r) % static_cast<int>(clr.g) % static_cast<int>(clr.b) % style)
2351 .str();
2352- const Surface* rv = surface_cache->get(hash);
2353+ const Texture* rv = texture_cache->get(hash);
2354 if (rv) return *rv;
2355
2356 m_set_style(style);
2357@@ -120,7 +120,7 @@
2358 if (!text_surface)
2359 throw RenderError((format("Rendering '%s' gave the error: %s") % txt % TTF_GetError()).str());
2360
2361- return *surface_cache->insert(hash, Surface::create(text_surface), true);
2362+ return *texture_cache->insert(hash, new Texture(text_surface), true);
2363 }
2364
2365 uint16_t SdlTtfFont::ascent(int style) const {
2366
2367=== modified file 'src/graphic/text/sdl_ttf_font.h'
2368--- src/graphic/text/sdl_ttf_font.h 2014-09-10 16:57:31 +0000
2369+++ src/graphic/text/sdl_ttf_font.h 2014-11-24 07:32:35 +0000
2370@@ -37,7 +37,7 @@
2371 virtual ~SdlTtfFont();
2372
2373 void dimensions(const std::string&, int, uint16_t * w, uint16_t * h) override;
2374- const Surface& render(const std::string&, const RGBColor& clr, int, SurfaceCache*) override;
2375+ const Texture& render(const std::string&, const RGBColor& clr, int, TextureCache*) override;
2376 uint16_t ascent(int) const override;
2377
2378 private:
2379
2380=== modified file 'src/graphic/text/test/render.cc'
2381--- src/graphic/text/test/render.cc 2014-09-20 09:37:47 +0000
2382+++ src/graphic/text/test/render.cc 2014-11-24 07:32:35 +0000
2383@@ -25,9 +25,9 @@
2384 #include <string>
2385
2386 #include "graphic/image_cache.h"
2387-#include "graphic/surface_cache.h"
2388 #include "graphic/text/rt_render.h"
2389 #include "graphic/text/test/paths.h"
2390+#include "graphic/texture_cache.h"
2391 #include "io/filesystem/layered_filesystem.h"
2392
2393 StandaloneRenderer::StandaloneRenderer() {
2394@@ -35,9 +35,9 @@
2395 g_fs->add_file_system(&FileSystem::create(WIDELANDS_DATA_DIR));
2396 g_fs->add_file_system(&FileSystem::create(RICHTEXT_DATA_DIR));
2397
2398- surface_cache_.reset(create_surface_cache(500 << 20)); // 500 MB
2399- image_cache_.reset(new ImageCache(surface_cache_.get()));
2400- renderer_.reset(new RT::Renderer(image_cache_.get(), surface_cache_.get()));
2401+ texture_cache_.reset(create_texture_cache(500 << 20)); // 500 MB
2402+ image_cache_.reset(new ImageCache(texture_cache_.get()));
2403+ renderer_.reset(new RT::Renderer(image_cache_.get(), texture_cache_.get()));
2404 }
2405
2406 StandaloneRenderer::~StandaloneRenderer() {
2407
2408=== modified file 'src/graphic/text/test/render.h'
2409--- src/graphic/text/test/render.h 2014-07-14 10:45:44 +0000
2410+++ src/graphic/text/test/render.h 2014-11-24 07:32:35 +0000
2411@@ -36,7 +36,7 @@
2412 RT::Renderer* renderer();
2413
2414 private:
2415- std::unique_ptr<SurfaceCache> surface_cache_;
2416+ std::unique_ptr<TextureCache> texture_cache_;
2417 std::unique_ptr<ImageCache> image_cache_;
2418 std::unique_ptr<RT::Renderer> renderer_;
2419 };
2420
2421=== modified file 'src/graphic/text/test/render_richtext.cc'
2422--- src/graphic/text/test/render_richtext.cc 2014-11-24 07:32:34 +0000
2423+++ src/graphic/text/test/render_richtext.cc 2014-11-24 07:32:35 +0000
2424@@ -33,9 +33,9 @@
2425 #include "config.h"
2426 #include "graphic/graphic.h"
2427 #include "graphic/image_io.h"
2428-#include "graphic/surface.h"
2429 #include "graphic/text/rt_errors.h"
2430 #include "graphic/text/test/render.h"
2431+#include "graphic/texture.h"
2432 #include "io/filesystem/filesystem.h"
2433 #include "io/filesystem/layered_filesystem.h"
2434 #include "io/streamwrite.h"
2435@@ -135,11 +135,12 @@
2436 StandaloneRenderer standalone_renderer;
2437
2438 try {
2439- std::unique_ptr<Surface> surf(standalone_renderer.renderer()->render(txt, w, allowed_tags));
2440+ std::unique_ptr<Texture> texture(
2441+ standalone_renderer.renderer()->render(txt, w, allowed_tags));
2442
2443 std::unique_ptr<FileSystem> fs(&FileSystem::create("."));
2444 std::unique_ptr<StreamWrite> sw(fs->open_stream_write(outname));
2445- if (!save_surface_to_png(surf.get(), sw.get())) {
2446+ if (!save_surface_to_png(texture.get(), sw.get())) {
2447 std::cout << "Could not encode PNG." << std::endl;
2448 }
2449 } catch (RT::Exception& e) {
2450
2451=== renamed file 'src/graphic/gl/surface_texture.cc' => 'src/graphic/texture.cc'
2452--- src/graphic/gl/surface_texture.cc 2014-11-23 10:13:14 +0000
2453+++ src/graphic/texture.cc 2014-11-24 07:32:35 +0000
2454@@ -16,7 +16,7 @@
2455 * Foundation, Inc., 51 Franklin Street, Fifth Floor, Boston, MA 02110-1301, USA.
2456 */
2457
2458-#include "graphic/gl/surface_texture.h"
2459+#include "graphic/texture.h"
2460
2461 #include <cassert>
2462
2463@@ -77,7 +77,7 @@
2464 *
2465 * The initial data of the texture is undefined.
2466 */
2467-GLSurfaceTexture::GLSurfaceTexture(int w, int h)
2468+Texture::Texture(int w, int h)
2469 {
2470 init(w, h);
2471
2472@@ -94,7 +94,7 @@
2473 *
2474 * \note Takes ownership of the given surface.
2475 */
2476-GLSurfaceTexture::GLSurfaceTexture(SDL_Surface * surface, bool intensity)
2477+Texture::Texture(SDL_Surface * surface, bool intensity)
2478 {
2479 init(surface->w, surface->h);
2480
2481@@ -132,17 +132,17 @@
2482 SDL_FreeSurface(surface);
2483 }
2484
2485-GLSurfaceTexture::~GLSurfaceTexture()
2486+Texture::~Texture()
2487 {
2488 glDeleteTextures(1, &m_texture);
2489 }
2490
2491-void GLSurfaceTexture::pixel_to_gl(float* x, float* y) const {
2492+void Texture::pixel_to_gl(float* x, float* y) const {
2493 *x = (*x / m_w) * 2. - 1.;
2494 *y = (*y / m_h) * 2. - 1.;
2495 }
2496
2497-void GLSurfaceTexture::init(uint16_t w, uint16_t h)
2498+void Texture::init(uint16_t w, uint16_t h)
2499 {
2500 m_w = w;
2501 m_h = h;
2502@@ -160,7 +160,7 @@
2503 glTexParameteri(GL_TEXTURE_2D, GL_TEXTURE_MAG_FILTER, GL_LINEAR);
2504 }
2505
2506-void GLSurfaceTexture::lock(LockMode mode) {
2507+void Texture::lock(LockMode mode) {
2508 if (m_w <= 0 || m_h <= 0) {
2509 return;
2510 }
2511@@ -174,7 +174,7 @@
2512 }
2513 }
2514
2515-void GLSurfaceTexture::unlock(UnlockMode mode) {
2516+void Texture::unlock(UnlockMode mode) {
2517 if (m_w <= 0 || m_h <= 0) {
2518 return;
2519 }
2520@@ -190,7 +190,7 @@
2521 m_pixels.reset(nullptr);
2522 }
2523
2524-void GLSurfaceTexture::draw_rect(const Rect& rectangle, const RGBColor& clr)
2525+void Texture::draw_rect(const Rect& rectangle, const RGBColor& clr)
2526 {
2527 if (m_w <= 0 || m_h <= 0) {
2528 return;
2529@@ -204,7 +204,7 @@
2530 /**
2531 * Draws a filled rectangle
2532 */
2533-void GLSurfaceTexture::fill_rect(const Rect& rectangle, const RGBAColor& clr)
2534+void Texture::fill_rect(const Rect& rectangle, const RGBAColor& clr)
2535 {
2536 if (m_w <= 0 || m_h <= 0) {
2537 return;
2538@@ -218,7 +218,7 @@
2539 /**
2540 * Change the brightness of the given rectangle
2541 */
2542-void GLSurfaceTexture::brighten_rect(const Rect& rectangle, const int32_t factor)
2543+void Texture::brighten_rect(const Rect& rectangle, const int32_t factor)
2544 {
2545 if (m_w <= 0 || m_h <= 0) {
2546 return;
2547@@ -229,7 +229,7 @@
2548 reset_gl();
2549 }
2550
2551-void GLSurfaceTexture::draw_line
2552+void Texture::draw_line
2553 (int32_t x1, int32_t y1, int32_t x2, int32_t y2, const RGBColor& color, uint8_t gwidth)
2554 {
2555 if (m_w <= 0 || m_h <= 0) {
2556@@ -241,14 +241,14 @@
2557 reset_gl();
2558 }
2559
2560-void GLSurfaceTexture::blit
2561- (const Point& dst, const Surface* src, const Rect& srcrc, Composite cm)
2562+void Texture::blit
2563+ (const Point& dst, const Texture* src, const Rect& srcrc, BlendMode blend_mode)
2564 {
2565 if (m_w <= 0 || m_h <= 0) {
2566 return;
2567 }
2568
2569 setup_gl(m_texture);
2570- Surface::blit(dst, src, srcrc, cm);
2571+ Surface::blit(dst, src, srcrc, blend_mode);
2572 reset_gl();
2573 }
2574
2575=== renamed file 'src/graphic/gl/surface_texture.h' => 'src/graphic/texture.h'
2576--- src/graphic/gl/surface_texture.h 2014-11-22 21:31:21 +0000
2577+++ src/graphic/texture.h 2014-11-24 07:32:35 +0000
2578@@ -16,20 +16,25 @@
2579 * Foundation, Inc., 51 Franklin Street, Fifth Floor, Boston, MA 02110-1301, USA.
2580 */
2581
2582-#ifndef WL_GRAPHIC_GL_SURFACE_TEXTURE_H
2583-#define WL_GRAPHIC_GL_SURFACE_TEXTURE_H
2584+#ifndef WL_GRAPHIC_TEXTURE_H
2585+#define WL_GRAPHIC_TEXTURE_H
2586
2587 #include "graphic/gl/system_headers.h"
2588 #include "graphic/surface.h"
2589
2590 struct SDL_Surface;
2591
2592-class GLSurfaceTexture : public Surface {
2593+class Texture : public Surface {
2594 public:
2595- GLSurfaceTexture(SDL_Surface * surface, bool intensity = false);
2596- GLSurfaceTexture(int w, int h);
2597-
2598- virtual ~GLSurfaceTexture();
2599+ // Create a new surface from an SDL_Surface. If intensity is true, an GL_INTENSITY texture
2600+ // is created. Ownership is taken.
2601+ Texture(SDL_Surface * surface, bool intensity = false);
2602+
2603+ // Create a new empty (that is randomly filled) Surface with the given
2604+ // dimensions.
2605+ Texture(int w, int h);
2606+
2607+ virtual ~Texture();
2608
2609 /// Interface implementation
2610 //@{
2611@@ -48,7 +53,10 @@
2612 void brighten_rect(const Rect&, int32_t factor) override;
2613 virtual void draw_line
2614 (int32_t x1, int32_t y1, int32_t x2, int32_t y2, const RGBColor&, uint8_t width) override;
2615- void blit(const Point&, const Surface*, const Rect& srcrc, Composite cm) override;
2616+ void blit(const Point&,
2617+ const Texture*,
2618+ const Rect& srcrc,
2619+ BlendMode blend_mode = BlendMode::UseAlpha) override;
2620
2621 GLuint get_gl_texture() const {return m_texture;}
2622
2623@@ -59,4 +67,4 @@
2624 GLuint m_texture;
2625 };
2626
2627-#endif // end of include guard: WL_GRAPHIC_GL_SURFACE_TEXTURE_H
2628+#endif // end of include guard: WL_GRAPHIC_TEXTURE_H
2629
2630=== renamed file 'src/graphic/surface_cache.cc' => 'src/graphic/texture_cache.cc'
2631--- src/graphic/surface_cache.cc 2014-09-14 11:31:58 +0000
2632+++ src/graphic/texture_cache.cc 2014-11-24 07:32:35 +0000
2633@@ -17,7 +17,7 @@
2634 *
2635 */
2636
2637-#include "graphic/surface_cache.h"
2638+#include "graphic/texture_cache.h"
2639
2640 #include <cassert>
2641 #include <list>
2642@@ -26,33 +26,33 @@
2643
2644 #include <SDL.h>
2645
2646-#include "graphic/surface.h"
2647+#include "graphic/texture.h"
2648
2649 using namespace std;
2650
2651 // I took inspiration from http://timday.bitbucket.org/lru.html, but our use
2652 // case here is a little different.
2653 namespace {
2654-class SurfaceCacheImpl : public SurfaceCache {
2655+class TextureCacheImpl : public TextureCache {
2656 public:
2657- SurfaceCacheImpl(uint32_t max_transient_memory) :
2658+ TextureCacheImpl(uint32_t max_transient_memory) :
2659 max_transient_memory_(max_transient_memory), used_transient_memory_(0) {}
2660- virtual ~SurfaceCacheImpl();
2661+ virtual ~TextureCacheImpl();
2662
2663- // Implements SurfaceCache.
2664+ // Implements TextureCache.
2665 void flush() override;
2666- Surface* get(const string& hash) override;
2667- Surface* insert(const string& hash, Surface*, bool) override;
2668+ Texture* get(const string& hash) override;
2669+ Texture* insert(const string& hash, Texture*, bool) override;
2670
2671 private:
2672 void drop();
2673
2674 using AccessHistory = list<string>;
2675 struct Entry {
2676- Entry(Surface* gs, const AccessHistory::iterator& it, bool transient) :
2677- surface(gs), is_transient(transient), last_access(SDL_GetTicks()), list_iterator(it) {}
2678+ Entry(Texture* gs, const AccessHistory::iterator& it, bool transient) :
2679+ texture(gs), is_transient(transient), last_access(SDL_GetTicks()), list_iterator(it) {}
2680
2681- std::unique_ptr<Surface> surface;
2682+ std::unique_ptr<Texture> texture;
2683 bool is_transient;
2684 uint32_t last_access; // Mainly for debugging and analysis.
2685 const AccessHistory::iterator list_iterator; // Only valid if is_transient is true.
2686@@ -65,11 +65,11 @@
2687 AccessHistory access_history_;
2688 };
2689
2690-SurfaceCacheImpl::~SurfaceCacheImpl() {
2691+TextureCacheImpl::~TextureCacheImpl() {
2692 flush();
2693 }
2694
2695-void SurfaceCacheImpl::flush() {
2696+void TextureCacheImpl::flush() {
2697 for (Container::iterator it = entries_.begin(); it != entries_.end(); ++it) {
2698 delete it->second;
2699 }
2700@@ -78,7 +78,7 @@
2701 used_transient_memory_ = 0;
2702 }
2703
2704-Surface* SurfaceCacheImpl::get(const string& hash) {
2705+Texture* TextureCacheImpl::get(const string& hash) {
2706 const Container::iterator it = entries_.find(hash);
2707 if (it == entries_.end())
2708 return nullptr;
2709@@ -89,30 +89,29 @@
2710 access_history_.splice(access_history_.end(), access_history_, it->second->list_iterator);
2711 it->second->last_access = SDL_GetTicks();
2712 }
2713- return it->second->surface.get();
2714+ return it->second->texture.get();
2715 }
2716
2717-Surface* SurfaceCacheImpl::insert(const string& hash, Surface* surf, bool transient) {
2718+Texture* TextureCacheImpl::insert(const string& hash, Texture* texture, bool transient) {
2719 assert(entries_.find(hash) == entries_.end());
2720
2721 if (transient) {
2722- const uint32_t surface_size = surf->width() * surf->height() * 4;
2723- while (used_transient_memory_ + surface_size > max_transient_memory_) {
2724+ const uint32_t texture_size = texture->width() * texture->height() * 4;
2725+ while (used_transient_memory_ + texture_size > max_transient_memory_) {
2726 drop();
2727 }
2728
2729 // Record hash as most-recently-used.
2730 AccessHistory::iterator it = access_history_.insert(access_history_.end(), hash);
2731- used_transient_memory_ += surface_size;
2732- entries_.insert(make_pair(hash, new Entry(surf, it, true)));
2733+ used_transient_memory_ += texture_size;
2734+ entries_.insert(make_pair(hash, new Entry(texture, it, true)));
2735 } else {
2736- entries_.insert(make_pair(hash, new Entry(surf, access_history_.end(), false)));
2737+ entries_.insert(make_pair(hash, new Entry(texture, access_history_.end(), false)));
2738 }
2739-
2740- return surf;
2741+ return texture;
2742 }
2743
2744-void SurfaceCacheImpl::drop() {
2745+void TextureCacheImpl::drop() {
2746 assert(!access_history_.empty());
2747
2748 // Identify least recently used key
2749@@ -120,8 +119,8 @@
2750 assert(it != entries_.end());
2751 assert(it->second->is_transient);
2752
2753- const uint32_t surface_size = it->second->surface->width() * it->second->surface->height() * 4;
2754- used_transient_memory_ -= surface_size;
2755+ const uint32_t texture_size = it->second->texture->width() * it->second->texture->height() * 4;
2756+ used_transient_memory_ -= texture_size;
2757
2758 // Erase both elements to completely purge record
2759 delete it->second;
2760@@ -131,6 +130,6 @@
2761
2762 } // namespace
2763
2764-SurfaceCache* create_surface_cache(uint32_t transient_memory_in_bytes) {
2765- return new SurfaceCacheImpl(transient_memory_in_bytes);
2766+TextureCache* create_texture_cache(uint32_t transient_memory_in_bytes) {
2767+ return new TextureCacheImpl(transient_memory_in_bytes);
2768 }
2769
2770=== renamed file 'src/graphic/surface_cache.h' => 'src/graphic/texture_cache.h'
2771--- src/graphic/surface_cache.h 2014-07-14 19:48:07 +0000
2772+++ src/graphic/texture_cache.h 2014-11-24 07:32:35 +0000
2773@@ -17,8 +17,8 @@
2774 *
2775 */
2776
2777-#ifndef WL_GRAPHIC_SURFACE_CACHE_H
2778-#define WL_GRAPHIC_SURFACE_CACHE_H
2779+#ifndef WL_GRAPHIC_TEXTURE_CACHE_H
2780+#define WL_GRAPHIC_TEXTURE_CACHE_H
2781
2782 #include <string>
2783
2784@@ -26,7 +26,7 @@
2785
2786 #include "base/macros.h"
2787
2788-class Surface;
2789+class Texture;
2790
2791 // Caches Surfaces. It contains surfaces which must not be deleted and
2792 // transient surfaces that are always free to be deleted - somebody else must
2793@@ -35,32 +35,32 @@
2794 // Nobody in Widelands should hold onto a Surface they get from this class,
2795 // instead, they should use it only temporarily and rerequest it whenever they
2796 // need it.
2797-class SurfaceCache {
2798+class TextureCache {
2799 public:
2800- SurfaceCache() {}
2801- virtual ~SurfaceCache() {}
2802+ TextureCache() {}
2803+ virtual ~TextureCache() {}
2804
2805 /// Deletes all surfaces in the cache leaving it as if it were just created.
2806 virtual void flush() = 0;
2807
2808 /// Returns an entry if it is cached, nullptr otherwise.
2809- virtual Surface* get(const std::string& hash) = 0;
2810+ virtual Texture* get(const std::string& hash) = 0;
2811
2812- // Inserts this entry into the SurfaceCache. asserts() that there is no
2813+ // Inserts this entry into the TextureCache. asserts() that there is no
2814 // entry with this hash already cached. Returns the given Surface for
2815 // convenience. If 'transient' is false, this surface will not be deleted
2816 // automatically - use this if surfaces are around for a long time and
2817 // recreation is expensive (i.e. images loaded from disk).
2818- virtual Surface* insert(const std::string& hash, Surface*, bool transient) = 0;
2819+ virtual Texture* insert(const std::string& hash, Texture*, bool transient) = 0;
2820
2821 private:
2822- DISALLOW_COPY_AND_ASSIGN(SurfaceCache);
2823+ DISALLOW_COPY_AND_ASSIGN(TextureCache);
2824 };
2825
2826 // Create a new Cache whichs combined pixels in all transient surfaces are
2827 // always below the given limit (Note: there is overhead for class members
2828 // which is not counted as the pixels make up the bulk of the size of a
2829 // surface).
2830-SurfaceCache* create_surface_cache(uint32_t transient_memory_in_bytes);
2831+TextureCache* create_texture_cache(uint32_t transient_memory_in_bytes);
2832
2833-#endif // end of include guard: WL_GRAPHIC_SURFACE_CACHE_H
2834+#endif // end of include guard: WL_GRAPHIC_TEXTURE_CACHE_H
2835
2836=== modified file 'src/logic/building.cc'
2837--- src/logic/building.cc 2014-11-02 14:11:52 +0000
2838+++ src/logic/building.cc 2014-11-24 07:32:35 +0000
2839@@ -732,7 +732,7 @@
2840 if (dpyflags & InteractiveBase::dfShowCensus) {
2841 const std::string info = info_string(igbase.building_census_format());
2842 if (!info.empty()) {
2843- dst.blit(pos - Point(0, 48), UI::g_fh1->render(info), CM_UseAlpha, UI::Align_Center);
2844+ dst.blit(pos - Point(0, 48), UI::g_fh1->render(info), BlendMode::UseAlpha, UI::Align_Center);
2845 }
2846 }
2847
2848@@ -744,7 +744,7 @@
2849 return;
2850 const std::string info = info_string(igbase.building_statistics_format());
2851 if (!info.empty()) {
2852- dst.blit(pos - Point(0, 35), UI::g_fh1->render(info), CM_UseAlpha, UI::Align_Center);
2853+ dst.blit(pos - Point(0, 35), UI::g_fh1->render(info), BlendMode::UseAlpha, UI::Align_Center);
2854 }
2855 }
2856 }
2857
2858=== modified file 'src/logic/immovable.cc'
2859--- src/logic/immovable.cc 2014-11-02 14:11:52 +0000
2860+++ src/logic/immovable.cc 2014-11-24 07:32:35 +0000
2861@@ -562,7 +562,7 @@
2862 dst.drawanimrect
2863 (pos, m_anim, current_frame * frametime, get_owner(), Rect(Point(0, curh - lines), curw, lines));
2864
2865- // Additionnaly, if statistics are enabled, draw a progression string
2866+ // Additionally, if statistics are enabled, draw a progression string
2867 if (game.get_ibase()->get_display_flags() & InteractiveBase::dfShowStatistics) {
2868 unsigned int percent = (100 * done / total);
2869 m_construct_string =
2870@@ -570,7 +570,10 @@
2871 % UI_FONT_CLR_DARK_HEX % (boost::format(_("%i%% built")) % percent).str())
2872 .str();
2873 m_construct_string = as_uifont(m_construct_string);
2874- dst.blit(pos - Point(0, 48), UI::g_fh1->render(m_construct_string), CM_UseAlpha, UI::Align_Center);
2875+ dst.blit(pos - Point(0, 48),
2876+ UI::g_fh1->render(m_construct_string),
2877+ BlendMode::UseAlpha,
2878+ UI::Align_Center);
2879 }
2880 }
2881
2882
2883=== modified file 'src/logic/map_info.cc'
2884--- src/logic/map_info.cc 2014-11-24 07:32:34 +0000
2885+++ src/logic/map_info.cc 2014-11-24 07:32:35 +0000
2886@@ -29,7 +29,7 @@
2887 #include "graphic/graphic.h"
2888 #include "graphic/image_io.h"
2889 #include "graphic/minimap_renderer.h"
2890-#include "graphic/surface.h"
2891+#include "graphic/texture.h"
2892 #include "io/filesystem/filesystem.h"
2893 #include "io/filesystem/layered_filesystem.h"
2894 #include "io/filewrite.h"
2895@@ -87,7 +87,8 @@
2896 ml->preload_map(true);
2897 ml->load_map_complete(egbase, true);
2898
2899- std::unique_ptr<Surface> minimap(draw_minimap(egbase, nullptr, Point(0, 0), MiniMapLayer::Terrain));
2900+ std::unique_ptr<Texture> minimap(
2901+ draw_minimap(egbase, nullptr, Point(0, 0), MiniMapLayer::Terrain));
2902
2903 // Write minimap
2904 {
2905
2906=== modified file 'src/map_io/map_extradata_packet.cc'
2907--- src/map_io/map_extradata_packet.cc 2014-09-20 09:37:47 +0000
2908+++ src/map_io/map_extradata_packet.cc 2014-11-24 07:32:35 +0000
2909@@ -23,7 +23,7 @@
2910
2911 #include "graphic/graphic.h"
2912 #include "graphic/in_memory_image.h"
2913-#include "graphic/surface.h"
2914+#include "graphic/texture.h"
2915 #include "io/fileread.h"
2916 #include "io/filewrite.h"
2917 #include "logic/editor_game_base.h"
2918@@ -67,7 +67,7 @@
2919 IMG_Load_RW(SDL_RWFromMem(fr.data(0), fr.get_size()), 1);
2920 if (!surf)
2921 continue; // Illegal pic. Skip it.
2922- image = g_gr->images().insert(new_in_memory_image(hash, Surface::create(surf)));
2923+ image = g_gr->images().insert(new_in_memory_image(hash, new Texture(surf)));
2924 } else {
2925 image = g_gr->images().get(hash);
2926 }
2927
2928=== modified file 'src/map_io/map_saver.cc'
2929--- src/map_io/map_saver.cc 2014-11-22 15:27:45 +0000
2930+++ src/map_io/map_saver.cc 2014-11-24 07:32:35 +0000
2931@@ -26,7 +26,7 @@
2932 #include "base/wexception.h"
2933 #include "graphic/image_io.h"
2934 #include "graphic/minimap_renderer.h"
2935-#include "graphic/surface.h"
2936+#include "graphic/texture.h"
2937 #include "io/filesystem/filesystem.h"
2938 #include "io/filewrite.h"
2939 #include "logic/editor_game_base.h"
2940@@ -217,7 +217,7 @@
2941
2942 // Write minimap
2943 {
2944- std::unique_ptr<Surface> minimap(
2945+ std::unique_ptr<Texture> minimap(
2946 draw_minimap(m_egbase, nullptr, Point(0, 0), MiniMapLayer::Terrain));
2947 FileWrite fw;
2948 save_surface_to_png(minimap.get(), &fw);
2949
2950=== modified file 'src/ui_basic/progressbar.cc'
2951--- src/ui_basic/progressbar.cc 2014-11-02 14:11:52 +0000
2952+++ src/ui_basic/progressbar.cc 2014-11-24 07:32:35 +0000
2953@@ -109,6 +109,6 @@
2954 const std::string progress_text =
2955 (boost::format("<font color=%1$s>%2$i%%</font>") % "ffffff" % percent).str();
2956 const Point pos(get_w() / 2, get_h() / 2);
2957- dst.blit(pos, UI::g_fh1->render(as_uifont(progress_text)), CM_UseAlpha, Align_Center);
2958+ dst.blit(pos, UI::g_fh1->render(as_uifont(progress_text)), BlendMode::UseAlpha, Align_Center);
2959 }
2960 }
2961
2962=== modified file 'src/ui_basic/window.cc'
2963--- src/ui_basic/window.cc 2014-11-22 11:51:38 +0000
2964+++ src/ui_basic/window.cc 2014-11-24 07:32:35 +0000
2965@@ -320,7 +320,7 @@
2966 dst.blit
2967 (Point(get_lborder() + get_inner_w() / 2, TP_B_PIXMAP_THICKNESS / 2),
2968 UI::g_fh1->render(m_title),
2969- CM_UseAlpha,
2970+ BlendMode::UseAlpha,
2971 Align_Center);
2972 }
2973
2974
2975=== modified file 'src/ui_fsmenu/loadgame.cc'
2976--- src/ui_fsmenu/loadgame.cc 2014-11-22 10:18:20 +0000
2977+++ src/ui_fsmenu/loadgame.cc 2014-11-24 07:32:35 +0000
2978@@ -36,7 +36,7 @@
2979 #include "graphic/image_io.h"
2980 #include "graphic/image_transformations.h"
2981 #include "graphic/in_memory_image.h"
2982-#include "graphic/surface.h"
2983+#include "graphic/texture.h"
2984 #include "helper.h"
2985 #include "io/filesystem/layered_filesystem.h"
2986 #include "logic/game.h"
2987@@ -317,13 +317,13 @@
2988 if (!minimap_path.empty()) {
2989 try {
2990 // Load the image
2991- std::unique_ptr<Surface> surface(
2992+ std::unique_ptr<Texture> texture(
2993 load_image(
2994 minimap_path,
2995 std::unique_ptr<FileSystem>(g_fs->make_sub_file_system(gamedata.filename)).get()));
2996
2997 m_minimap_image.reset(new_in_memory_image(std::string(gamedata.filename + minimap_path),
2998- surface.release()));
2999+ texture.release()));
3000
3001 // Scale it
3002 double scale = double(m_minimap_w) / m_minimap_image->width();
3003@@ -337,7 +337,7 @@
3004 const Image* resized = ImageTransformations::resize(m_minimap_image.get(), w, h);
3005 // keeps our in_memory_image around and give to icon the one
3006 // from resize that is handled by the cache. It is still linked to our
3007- // surface
3008+ // texture.
3009 m_minimap_icon.set_size(w, h);
3010
3011 // Center the minimap in the available space
3012
3013=== modified file 'src/wui/buildingwindow.cc'
3014--- src/wui/buildingwindow.cc 2014-11-22 10:18:20 +0000
3015+++ src/wui/buildingwindow.cc 2014-11-24 07:32:35 +0000
3016@@ -119,7 +119,7 @@
3017
3018 const Image* dark_frame = ImageTransformations::change_luminosity
3019 (&anim.representative_image(building().owner().get_playercolor()), 1.22, true);
3020- dst.blit(Point(get_inner_w() / 2, get_inner_h() / 2), dark_frame, CM_UseAlpha, UI::Align_Center);
3021+ dst.blit(Point(get_inner_w() / 2, get_inner_h() / 2), dark_frame, BlendMode::UseAlpha, UI::Align_Center);
3022 }
3023
3024 /*
3025
3026=== modified file 'src/wui/interactive_base.cc'
3027--- src/wui/interactive_base.cc 2014-11-24 07:32:34 +0000
3028+++ src/wui/interactive_base.cc 2014-11-24 07:32:35 +0000
3029@@ -410,7 +410,7 @@
3030 if (get_display_flag(dfDebug) || !dynamic_cast<const Game*>(&egbase())) {
3031 const std::string gametime(gametimestring(egbase().get_gametime()));
3032 const std::string gametime_text = as_uifont(gametime, UI_FONT_SIZE_SMALL);
3033- dst.blit(Point(5, 5), UI::g_fh1->render(gametime_text), CM_UseAlpha, UI::Align_TopLeft);
3034+ dst.blit(Point(5, 5), UI::g_fh1->render(gametime_text), BlendMode::UseAlpha, UI::Align_TopLeft);
3035 static boost::format node_format("(%i, %i)");
3036
3037 const std::string node_text = as_uifont
3038@@ -418,7 +418,7 @@
3039 dst.blit(
3040 Point(get_w() - 5, get_h() - 5),
3041 UI::g_fh1->render(node_text),
3042- CM_UseAlpha,
3043+ BlendMode::UseAlpha,
3044 UI::Align_BottomRight
3045 );
3046 }
3047@@ -430,7 +430,7 @@
3048 ((fps_format %
3049 (1000.0 / m_frametime) % (1000.0 / (m_avg_usframetime / 1000)))
3050 .str(), UI_FONT_SIZE_SMALL);
3051- dst.blit(Point(5, 25), UI::g_fh1->render(fps_text), CM_UseAlpha, UI::Align_Left);
3052+ dst.blit(Point(5, 25), UI::g_fh1->render(fps_text), BlendMode::UseAlpha, UI::Align_Left);
3053 }
3054 }
3055
3056
3057=== modified file 'src/wui/minimap.cc'
3058--- src/wui/minimap.cc 2014-11-22 11:32:06 +0000
3059+++ src/wui/minimap.cc 2014-11-24 07:32:35 +0000
3060@@ -26,7 +26,7 @@
3061 #include "graphic/in_memory_image.h"
3062 #include "graphic/minimap_renderer.h"
3063 #include "graphic/rendertarget.h"
3064-#include "graphic/surface.h"
3065+#include "graphic/texture.h"
3066 #include "logic/map.h"
3067 #include "wui/interactive_player.h"
3068 #include "wui/mapviewpixelconstants.h"
3069@@ -63,15 +63,15 @@
3070
3071 void MiniMap::View::draw(RenderTarget & dst)
3072 {
3073- std::unique_ptr<Surface> surface(
3074+ std::unique_ptr<Texture> texture(
3075 draw_minimap(m_ibase.egbase(),
3076 m_ibase.get_player(),
3077 (*m_flags) & (MiniMapLayer::Zoom2) ?
3078 Point((m_viewx - get_w() / 4), (m_viewy - get_h() / 4)) :
3079 Point((m_viewx - get_w() / 2), (m_viewy - get_h() / 2)),
3080 *m_flags | MiniMapLayer::ViewWindow));
3081- // Give ownership of the surface to the new image
3082- std::unique_ptr<const Image> im(new_in_memory_image("minimap", surface.release()));
3083+ // Give ownership of the texture to the new image
3084+ std::unique_ptr<const Image> im(new_in_memory_image("minimap", texture.release()));
3085 dst.blit(Point(), im.get());
3086 im.reset();
3087 }
3088
3089=== modified file 'src/wui/plot_area.cc'
3090--- src/wui/plot_area.cc 2014-11-08 14:59:03 +0000
3091+++ src/wui/plot_area.cc 2014-11-24 07:32:35 +0000
3092@@ -142,7 +142,7 @@
3093 */
3094 void draw_value(const string& value, const RGBColor& color, const Point& pos, RenderTarget & dst) {
3095 const Image* pic = UI::g_fh1->render(ytick_text_style(value, color));
3096- dst.blit(pos, pic, CM_UseAlpha, UI::Align_CenterRight);
3097+ dst.blit(pos, pic, BlendMode::UseAlpha, UI::Align_CenterRight);
3098 }
3099
3100 /**
3101@@ -223,7 +223,7 @@
3102 (xtick_text_style((boost::format("-%u ") % (max_x / how_many_ticks * i)).str()));
3103 dst.blit
3104 (Point(static_cast<int32_t>(posx), inner_h - space_at_bottom + 10),
3105- xtick, CM_UseAlpha, UI::Align_Center);
3106+ xtick, BlendMode::UseAlpha, UI::Align_Center);
3107
3108 posx -= sub;
3109 }
3110@@ -242,7 +242,7 @@
3111
3112 // print the used unit
3113 const Image* xtick = UI::g_fh1->render(xtick_text_style(get_unit_name(unit)));
3114- dst.blit(Point(2, spacing + 2), xtick, CM_UseAlpha, UI::Align_CenterLeft);
3115+ dst.blit(Point(2, spacing + 2), xtick, BlendMode::UseAlpha, UI::Align_CenterLeft);
3116 }
3117
3118 } // namespace

Subscribers

People subscribed via source and target branches

to status/vote changes: