widelands-dev team mailing list archive
-
widelands-dev team
-
Mailing list archive
-
Message #03157
[Merge] lp:~widelands-dev/widelands/move_road_texture_out_of_graphics into lp:widelands
SirVer has proposed merging lp:~widelands-dev/widelands/move_road_texture_out_of_graphics into lp:widelands with lp:~widelands-dev/widelands/fix_some_resizing_bugs as a prerequisite.
Requested reviews:
Widelands Developers (widelands-dev)
For more details, see:
https://code.launchpad.net/~widelands-dev/widelands/move_road_texture_out_of_graphics/+merge/242627
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.
--
Your team Widelands Developers is requested to review the proposed merge of lp:~widelands-dev/widelands/move_road_texture_out_of_graphics into lp:widelands.
=== modified file 'src/editor/ui_menus/editor_tool_set_terrain_options_menu.cc'
--- src/editor/ui_menus/editor_tool_set_terrain_options_menu.cc 2014-11-02 20:31:40 +0000
+++ src/editor/ui_menus/editor_tool_set_terrain_options_menu.cc 2014-11-24 07:32:35 +0000
@@ -30,7 +30,7 @@
#include "graphic/graphic.h"
#include "graphic/in_memory_image.h"
#include "graphic/rendertarget.h"
-#include "graphic/surface.h"
+#include "graphic/terrain_texture.h"
#include "graphic/texture.h"
#include "logic/map.h"
#include "logic/world/editor_category.h"
@@ -77,50 +77,50 @@
const Image* tex = g_gr->images().get(
g_gr->get_maptexture_data(terrain_descr.get_texture())->get_texture_image());
- Surface* surf = Surface::create(tex->width(), tex->height());
- surf->blit(Point(0, 0), tex->surface(), Rect(0, 0, tex->width(), tex->height()), CM_Copy);
+ Texture* texture = new Texture(tex->width(), tex->height());
+ texture->blit(Point(0, 0), tex->texture(), Rect(0, 0, tex->width(), tex->height()), BlendMode::Copy);
Point pt(1, tex->height() - kSmallPicHeight - 1);
if (ter_is == TerrainDescription::GREEN) {
- surf->blit(pt, green->surface(), Rect(0, 0, green->width(), green->height()));
+ texture->blit(pt, green->texture(), Rect(0, 0, green->width(), green->height()));
pt.x += kSmallPicWidth + 1;
/** TRANSLATORS: This is a terrain type tooltip in the editor */
tooltips.push_back(_("arable"));
} else {
if (ter_is & TerrainDescription::WATER) {
- surf->blit(pt, water->surface(), Rect(0, 0, water->width(), water->height()));
+ texture->blit(pt, water->texture(), Rect(0, 0, water->width(), water->height()));
pt.x += kSmallPicWidth + 1;
/** TRANSLATORS: This is a terrain type tooltip in the editor */
tooltips.push_back(_("aquatic"));
}
else if (ter_is & TerrainDescription::MOUNTAIN) {
- surf->blit(pt, mountain->surface(), Rect(0, 0, mountain->width(), mountain->height()));
+ texture->blit(pt, mountain->texture(), Rect(0, 0, mountain->width(), mountain->height()));
pt.x += kSmallPicWidth + 1;
/** TRANSLATORS: This is a terrain type tooltip in the editor */
tooltips.push_back(_("mountainous"));
}
if (ter_is & TerrainDescription::ACID) {
- surf->blit(pt, dead->surface(), Rect(0, 0, dead->width(), dead->height()));
+ texture->blit(pt, dead->texture(), Rect(0, 0, dead->width(), dead->height()));
pt.x += kSmallPicWidth + 1;
/** TRANSLATORS: This is a terrain type tooltip in the editor */
tooltips.push_back(_("dead"));
}
if (ter_is & TerrainDescription::UNPASSABLE) {
- surf->blit(
- pt, unpassable->surface(), Rect(0, 0, unpassable->width(), unpassable->height()));
+ texture->blit(
+ pt, unpassable->texture(), Rect(0, 0, unpassable->width(), unpassable->height()));
pt.x += kSmallPicWidth + 1;
/** TRANSLATORS: This is a terrain type tooltip in the editor */
tooltips.push_back(_("unpassable"));
}
if (ter_is & TerrainDescription::DRY) {
- surf->blit(pt, dry->surface(), Rect(0, 0, dry->width(), dry->height()));
+ texture->blit(pt, dry->texture(), Rect(0, 0, dry->width(), dry->height()));
/** TRANSLATORS: This is a terrain type tooltip in the editor */
tooltips.push_back(_("treeless"));
}
}
// Make sure we delete this later on.
- offscreen_images->emplace_back(new_in_memory_image("dummy_hash", surf));
+ offscreen_images->emplace_back(new_in_memory_image("dummy_hash", texture));
break;
}
/** TRANSLATORS: %1% = terrain name, %2% = list of terrain types */
=== modified file 'src/game_io/CMakeLists.txt'
--- src/game_io/CMakeLists.txt 2014-10-11 16:08:10 +0000
+++ src/game_io/CMakeLists.txt 2014-11-24 07:32:35 +0000
@@ -27,7 +27,6 @@
base_time_string
economy
graphic
- graphic_surface
io_fileread
io_filesystem
logic
=== modified file 'src/game_io/game_preload_packet.cc'
--- src/game_io/game_preload_packet.cc 2014-11-01 18:24:28 +0000
+++ src/game_io/game_preload_packet.cc 2014-11-24 07:32:35 +0000
@@ -28,7 +28,6 @@
#include "graphic/graphic.h"
#include "graphic/in_memory_image.h"
#include "graphic/minimap_renderer.h"
-#include "graphic/surface.h"
#include "logic/game.h"
#include "logic/game_data_error.h"
#include "logic/map.h"
=== modified file 'src/graphic/CMakeLists.txt'
--- src/graphic/CMakeLists.txt 2014-11-23 10:13:14 +0000
+++ src/graphic/CMakeLists.txt 2014-11-24 07:32:35 +0000
@@ -45,17 +45,17 @@
wl_library(graphic_surface
SRCS
- compositemode.h
- gl/surface_screen.cc
- gl/surface_screen.h
- gl/surface_texture.cc
- gl/surface_texture.h
+ blend_mode.h
gl/utils.cc
gl/utils.h
+ screen.cc
+ screen.h
surface.cc
surface.h
- surface_cache.cc
- surface_cache.h
+ texture.cc
+ texture.h
+ texture_cache.cc
+ texture_cache.h
USES_OPENGL
USES_SDL2
DEPENDS
@@ -90,20 +90,20 @@
gl/blit_program.h
gl/dither_program.cc
gl/dither_program.h
+ gl/draw_line_program.cc
+ gl/draw_line_program.h
gl/draw_rect_program.cc
gl/draw_rect_program.h
- gl/draw_line_program.cc
- gl/draw_line_program.h
+ gl/fields_to_draw.h
gl/fill_rect_program.cc
gl/fill_rect_program.h
- gl/fields_to_draw.h
gl/game_renderer.cc
gl/game_renderer.h
gl/road_program.cc
gl/road_program.h
+ gl/system_headers.h
gl/terrain_program.cc
gl/terrain_program.h
- gl/system_headers.h
graphic.cc
graphic.h
image_transformations.cc
@@ -116,10 +116,10 @@
rendertarget.h
richtext.cc
richtext.h
+ terrain_texture.cc
+ terrain_texture.h
text_parser.cc
text_parser.h
- texture.cc
- texture.h
wordwrap.cc
wordwrap.h
USES_OPENGL
@@ -146,6 +146,7 @@
io_filesystem
io_stream
logic
+ notifications
profile
scripting
sound
=== modified file 'src/graphic/animation.cc'
--- src/graphic/animation.cc 2014-09-20 09:37:47 +0000
+++ src/graphic/animation.cc 2014-11-24 07:32:35 +0000
@@ -41,7 +41,7 @@
#include "graphic/image_cache.h"
#include "graphic/image_transformations.h"
#include "graphic/surface.h"
-#include "graphic/surface_cache.h"
+#include "graphic/texture_cache.h"
#include "io/filesystem/layered_filesystem.h"
#include "logic/bob.h"
#include "logic/instances.h"
@@ -324,7 +324,7 @@
assert(target);
const Image& frame = get_frame(time, clr);
- target->blit(dst, frame.surface(), srcrc);
+ target->blit(dst, frame.texture(), srcrc);
}
const Image& NonPackedAnimation::get_frame(uint32_t time, const RGBColor* playercolor) const {
=== renamed file 'src/graphic/compositemode.h' => 'src/graphic/blend_mode.h'
--- src/graphic/compositemode.h 2014-11-02 14:11:52 +0000
+++ src/graphic/blend_mode.h 2014-11-24 07:32:35 +0000
@@ -17,23 +17,17 @@
*
*/
-#ifndef WL_GRAPHIC_COMPOSITEMODE_H
-#define WL_GRAPHIC_COMPOSITEMODE_H
-
-/**
- * Defines composition operations performed while blitting.
- */
-enum Composite {
- /**
- * Perform a normal blitting operation that respects the alpha
- * channel if present.
- */
- CM_UseAlpha = 0,
-
- /**
- * Copy all pixel information, including alpha channel information.
- */
- CM_Copy
+#ifndef WL_GRAPHIC_BLEND_MODE_H
+#define WL_GRAPHIC_BLEND_MODE_H
+
+// Defines blending during blitting.
+enum BlendMode {
+ // Perform a normal blitting operation that respects the alpha channel if
+ // present.
+ UseAlpha = 0,
+
+ // Copy all pixel information, including alpha channel information.
+ Copy
};
-#endif // end of include guard: WL_GRAPHIC_COMPOSITEMODE_H
+#endif // end of include guard: WL_GRAPHIC_BLEND_MODE_H
=== modified file 'src/graphic/font_handler.cc'
--- src/graphic/font_handler.cc 2014-10-14 06:30:20 +0000
+++ src/graphic/font_handler.cc 2014-11-24 07:32:35 +0000
@@ -31,7 +31,7 @@
#include "graphic/graphic.h"
#include "graphic/in_memory_image.h"
#include "graphic/rendertarget.h"
-#include "graphic/surface.h"
+#include "graphic/texture.h"
#include "graphic/wordwrap.h"
namespace UI {
@@ -197,7 +197,7 @@
return;
}
- lce.image = new_in_memory_image("dummy_hash", Surface::create(text_surface));
+ lce.image = new_in_memory_image("dummy_hash", new Texture(text_surface));
lce.width = lce.image->width();
lce.height = lce.image->height();
}
=== modified file 'src/graphic/font_handler1.cc'
--- src/graphic/font_handler1.cc 2014-09-10 14:48:40 +0000
+++ src/graphic/font_handler1.cc 2014-11-24 07:32:35 +0000
@@ -29,11 +29,11 @@
#include "graphic/image.h"
#include "graphic/image_cache.h"
#include "graphic/rendertarget.h"
-#include "graphic/surface.h"
-#include "graphic/surface_cache.h"
#include "graphic/text/rt_errors.h"
#include "graphic/text/rt_render.h"
#include "graphic/text/sdl_ttf_font.h"
+#include "graphic/texture.h"
+#include "graphic/texture_cache.h"
#include "io/filesystem/filesystem.h"
@@ -42,29 +42,29 @@
namespace {
-// An Image implementation that recreates a rich text surface when needed on
+// An Image implementation that recreates a rich text texture when needed on
// the fly. It is meant to be saved into the ImageCache.
class RTImage : public Image {
public:
RTImage
- (const string& ghash, SurfaceCache* surface_cache, RT::Renderer*
+ (const string& ghash, TextureCache* texture_cache, RT::Renderer*
rt_renderer, const string& text, uint16_t gwidth)
- : hash_(ghash), text_(text), width_(gwidth), surface_cache_(surface_cache),
+ : hash_(ghash), text_(text), width_(gwidth), texture_cache_(texture_cache),
rt_renderer_(rt_renderer)
{}
virtual ~RTImage() {}
// Implements Image.
- uint16_t width() const override {return surface()->width();}
- uint16_t height() const override {return surface()->height();}
+ uint16_t width() const override {return texture()->width();}
+ uint16_t height() const override {return texture()->height();}
const string& hash() const override {return hash_;}
- Surface* surface() const override {
- Surface* surf = surface_cache_->get(hash_);
+ Texture* texture() const override {
+ Texture* surf = texture_cache_->get(hash_);
if (surf)
return surf;
surf = rt_renderer_->render(text_, width_);
- surface_cache_->insert(hash_, surf, true);
+ texture_cache_->insert(hash_, surf, true);
return surf;
}
@@ -74,7 +74,7 @@
uint16_t width_;
// Nothing owned.
- SurfaceCache* const surface_cache_;
+ TextureCache* const texture_cache_;
RT::Renderer* const rt_renderer_;
};
@@ -87,8 +87,8 @@
// be a problem.
class FontHandler1 : public IFontHandler1 {
public:
- FontHandler1(ImageCache* image_cache, SurfaceCache* surface_cache, RT::Renderer* renderer) :
- surface_cache_(surface_cache), image_cache_(image_cache), renderer_(renderer) {}
+ FontHandler1(ImageCache* image_cache, TextureCache* texture_cache, RT::Renderer* renderer) :
+ texture_cache_(texture_cache), image_cache_(image_cache), renderer_(renderer) {}
virtual ~FontHandler1() {}
const Image* render(const string& text, uint16_t w = 0) override {
@@ -97,21 +97,21 @@
if (image_cache_->has(hash))
return image_cache_->get(hash);
- std::unique_ptr<RTImage> image(new RTImage(hash, surface_cache_, renderer_.get(), text, w));
- image->surface(); // force the rich text to get rendered in case there is an exception thrown.
+ std::unique_ptr<RTImage> image(new RTImage(hash, texture_cache_, renderer_.get(), text, w));
+ image->texture(); // force the rich text to get rendered in case there is an exception thrown.
return image_cache_->insert(image.release());
}
private:
- SurfaceCache* const surface_cache_; // not owned
+ TextureCache* const texture_cache_; // not owned
ImageCache* const image_cache_; // not owned
std::unique_ptr<RT::Renderer> renderer_;
};
IFontHandler1 * create_fonthandler(Graphic* gr) {
return new FontHandler1(
- &gr->images(), &gr->surfaces(), new RT::Renderer(&gr->images(), &gr->surfaces()));
+ &gr->images(), &gr->textures(), new RT::Renderer(&gr->images(), &gr->textures()));
}
IFontHandler1 * g_fh1 = nullptr;
=== modified file 'src/graphic/gl/blit_program.cc'
--- src/graphic/gl/blit_program.cc 2014-11-02 16:55:53 +0000
+++ src/graphic/gl/blit_program.cc 2014-11-24 07:32:35 +0000
@@ -97,7 +97,7 @@
void BlitProgram::draw(const FloatRect& gl_dest_rect,
const FloatRect& gl_src_rect,
const GLuint gl_texture,
- const Composite composite) {
+ const BlendMode blend_mode) {
glUseProgram(gl_program_.object());
glEnableVertexAttribArray(attr_position_);
glBindBuffer(GL_ARRAY_BUFFER, gl_array_buffer_.object());
@@ -117,13 +117,13 @@
glActiveTexture(GL_TEXTURE0);
glBindTexture(GL_TEXTURE_2D, gl_texture);
- if (composite == CM_Copy) {
+ if (blend_mode == BlendMode::Copy) {
glBlendFunc(GL_ONE, GL_ZERO);
}
glDrawArrays(GL_TRIANGLE_STRIP, 0, 4);
- if (composite == CM_Copy) {
+ if (blend_mode == BlendMode::Copy) {
glBlendFunc(GL_SRC_ALPHA, GL_ONE_MINUS_SRC_ALPHA);
}
=== modified file 'src/graphic/gl/blit_program.h'
--- src/graphic/gl/blit_program.h 2014-11-08 18:06:17 +0000
+++ src/graphic/gl/blit_program.h 2014-11-24 07:32:35 +0000
@@ -21,8 +21,8 @@
#define WL_GRAPHIC_GL_BLIT_PROGRAM_H
#include "base/rect.h"
+#include "graphic/blend_mode.h"
#include "graphic/color.h"
-#include "graphic/gl/surface_texture.h"
#include "graphic/gl/utils.h"
class BlitProgram {
@@ -32,12 +32,12 @@
// Draws the rectangle 'gl_src_rect' from the texture with the name
// 'gl_texture' to 'gl_dest_rect' in the currently bound framebuffer. All
- // coordinates are in the OpenGL frame. The 'composite' defines if the
+ // coordinates are in the OpenGL frame. The 'blend_mode' defines if the
// values are copied or if alpha values are used.
void draw(const FloatRect& gl_dest_rect,
const FloatRect& gl_src_rect,
const GLuint gl_texture,
- const Composite composite);
+ const BlendMode blend_mode);
private:
BlitProgram();
=== modified file 'src/graphic/gl/dither_program.cc'
--- src/graphic/gl/dither_program.cc 2014-11-08 18:06:17 +0000
+++ src/graphic/gl/dither_program.cc 2014-11-24 07:32:35 +0000
@@ -21,10 +21,9 @@
#include "base/wexception.h"
#include "graphic/gl/fields_to_draw.h"
-#include "graphic/gl/surface_texture.h"
#include "graphic/graphic.h"
#include "graphic/image_io.h"
-#include "graphic/surface_cache.h"
+#include "graphic/terrain_texture.h"
#include "graphic/texture.h"
#include "io/fileread.h"
#include "io/filesystem/layered_filesystem.h"
@@ -73,19 +72,6 @@
}
)";
-// Returns the texture mask for the dithering step.
-const GLSurfaceTexture* get_dither_edge_texture() {
- constexpr char kFilename[] = "world/pics/edge.png";
- constexpr char kCacheName[] = "gltex#world/pics/edge.png";
-
- if (Surface* surface = g_gr->surfaces().get(kCacheName))
- return dynamic_cast<GLSurfaceTexture*>(surface);
-
- SDL_Surface* sdlsurf = load_image_as_sdl_surface(kFilename, g_fs);
- GLSurfaceTexture* edgetexture = new GLSurfaceTexture(sdlsurf, true);
- g_gr->surfaces().insert(kCacheName, edgetexture, false);
- return edgetexture;
-}
} // namespace
@@ -101,8 +87,13 @@
u_dither_texture_ = glGetUniformLocation(gl_program_.object(), "u_dither_texture");
u_terrain_texture_ = glGetUniformLocation(gl_program_.object(), "u_terrain_texture");
+
+ SDL_Surface* sdlsurf = load_image_as_sdl_surface("world/pics/edge.png", g_fs);
+ dither_mask_.reset(new Texture(sdlsurf, true));
}
+DitherProgram::~DitherProgram() {}
+
void DitherProgram::add_vertex(const FieldsToDraw::Field& field,
const int order_index,
const int terrain) {
@@ -220,7 +211,7 @@
// Set the sampler texture unit to 0
glActiveTexture(GL_TEXTURE0);
glUniform1i(u_dither_texture_, 0);
- glBindTexture(GL_TEXTURE_2D, get_dither_edge_texture()->get_gl_texture());
+ glBindTexture(GL_TEXTURE_2D, dither_mask_->get_gl_texture());
glTexParameteri(GL_TEXTURE_2D, GL_TEXTURE_WRAP_S, GL_CLAMP);
glTexParameteri(GL_TEXTURE_2D, GL_TEXTURE_WRAP_T, GL_CLAMP);
@@ -234,9 +225,10 @@
if (current_data.empty()) {
continue;
}
- glBindTexture(
- GL_TEXTURE_2D,
- g_gr->get_maptexture_data(terrains.get_unmutable(i).get_texture())->get_texture());
+ glBindTexture(GL_TEXTURE_2D,
+ g_gr->get_maptexture_data(terrains.get_unmutable(i).get_texture())
+ ->texture()
+ .get_gl_texture());
glBufferData(GL_ARRAY_BUFFER,
sizeof(PerVertexData) * current_data.size(),
=== modified file 'src/graphic/gl/dither_program.h'
--- src/graphic/gl/dither_program.h 2014-11-08 18:06:17 +0000
+++ src/graphic/gl/dither_program.h 2014-11-24 07:32:35 +0000
@@ -20,14 +20,19 @@
#ifndef WL_GRAPHIC_GL_DITHER_PROGRAM_H
#define WL_GRAPHIC_GL_DITHER_PROGRAM_H
+#include <memory>
+
#include "graphic/gl/fields_to_draw.h"
#include "graphic/gl/utils.h"
#include "logic/description_maintainer.h"
#include "logic/world/terrain_description.h"
+class Texture;
+
class DitherProgram {
public:
DitherProgram();
+ ~DitherProgram();
// Draws the terrain.
void draw(const DescriptionMaintainer<Widelands::TerrainDescription>& terrains,
@@ -77,6 +82,9 @@
GLint u_terrain_texture_;
GLint u_dither_texture_;
+ // The texture mask for the dithering step.
+ std::unique_ptr<Texture> dither_mask_;
+
// Objects below are here to avoid memory allocations on each frame, they
// could theoretically also always be recreated. Index as follows:
// vertices_[terrain_index][vertex_index]
=== modified file 'src/graphic/gl/game_renderer.cc'
--- src/graphic/gl/game_renderer.cc 2014-11-22 21:31:21 +0000
+++ src/graphic/gl/game_renderer.cc 2014-11-24 07:32:35 +0000
@@ -28,7 +28,7 @@
#include "graphic/graphic.h"
#include "graphic/rendertarget.h"
#include "graphic/surface.h"
-#include "graphic/texture.h"
+#include "graphic/terrain_texture.h"
#include "logic/editor_game_base.h"
#include "logic/player.h"
#include "logic/world/world.h"
@@ -165,8 +165,8 @@
map.normalize_coords(coords);
const FCoords& fcoords = map.get_fcoords(coords);
- f.texture_x = float(x) / TEXTURE_WIDTH;
- f.texture_y = float(y) / TEXTURE_HEIGHT;
+ f.texture_x = float(x) / kTextureWidth;
+ f.texture_y = float(y) / kTextureHeight;
f.gl_x = f.pixel_x = x + surface_offset.x;
f.gl_y = f.pixel_y = y + surface_offset.y - fcoords.field->get_height() * HEIGHT_FACTOR;
=== modified file 'src/graphic/gl/road_program.cc'
--- src/graphic/gl/road_program.cc 2014-11-22 21:31:21 +0000
+++ src/graphic/gl/road_program.cc 2014-11-24 07:32:35 +0000
@@ -24,6 +24,7 @@
#include "base/log.h"
#include "graphic/gl/fields_to_draw.h"
#include "graphic/graphic.h"
+#include "graphic/image_io.h"
#include "graphic/texture.h"
#include "logic/roadtype.h"
@@ -85,6 +86,12 @@
u_normal_road_texture_ = glGetUniformLocation(gl_program_.object(), "u_normal_road_texture");
u_busy_road_texture_ = glGetUniformLocation(gl_program_.object(), "u_busy_road_texture");
+
+ normal_road_texture_.reset(load_image("world/pics/roadt_normal.png"));
+ busy_road_texture_.reset(load_image("world/pics/roadt_busy.png"));
+}
+
+RoadProgram::~RoadProgram() {
}
void RoadProgram::add_road(const Surface& surface,
@@ -211,17 +218,12 @@
glBindBuffer(GL_ARRAY_BUFFER, 0);
// Bind the textures.
- const GLuint rt_normal = dynamic_cast<const GLSurfaceTexture&>(
- g_gr->get_road_texture(Widelands::Road_Normal)).get_gl_texture();
- const GLuint rt_busy = dynamic_cast<const GLSurfaceTexture&>(
- g_gr->get_road_texture(Widelands::Road_Busy)).get_gl_texture();
-
glActiveTexture(GL_TEXTURE0);
- glBindTexture(GL_TEXTURE_2D, rt_normal);
+ glBindTexture(GL_TEXTURE_2D, normal_road_texture_->get_gl_texture());
glUniform1i(u_normal_road_texture_, 0);
glActiveTexture(GL_TEXTURE1);
- glBindTexture(GL_TEXTURE_2D, rt_busy);
+ glBindTexture(GL_TEXTURE_2D, busy_road_texture_->get_gl_texture());
glUniform1i(u_busy_road_texture_, 1);
glDrawArrays(GL_TRIANGLES, 0, vertices_.size());
=== modified file 'src/graphic/gl/road_program.h'
--- src/graphic/gl/road_program.h 2014-11-22 21:31:21 +0000
+++ src/graphic/gl/road_program.h 2014-11-24 07:32:35 +0000
@@ -20,18 +20,22 @@
#ifndef WL_GRAPHIC_GL_ROAD_PROGRAM_H
#define WL_GRAPHIC_GL_ROAD_PROGRAM_H
+#include <memory>
#include <vector>
#include "base/macros.h"
#include "graphic/gl/fields_to_draw.h"
#include "graphic/gl/utils.h"
-#include "graphic/surface.h"
#include "logic/roadtype.h"
+class Texture;
+class Surface;
+
class RoadProgram {
public:
// Compiles the program. Throws on error.
RoadProgram();
+ ~RoadProgram();
// Draws the roads. The 'surface' is needed to convert from pixel space to
// GL space.
@@ -79,6 +83,10 @@
// All vertices that get rendered this frame.
std::vector<PerVertexData> vertices_;
+ // The road textures.
+ std::unique_ptr<Texture> normal_road_texture_;
+ std::unique_ptr<Texture> busy_road_texture_;
+
DISALLOW_COPY_AND_ASSIGN(RoadProgram);
};
=== modified file 'src/graphic/gl/terrain_program.cc'
--- src/graphic/gl/terrain_program.cc 2014-11-08 18:06:17 +0000
+++ src/graphic/gl/terrain_program.cc 2014-11-24 07:32:35 +0000
@@ -21,6 +21,7 @@
#include "graphic/gl/fields_to_draw.h"
#include "graphic/graphic.h"
+#include "graphic/terrain_texture.h"
#include "graphic/texture.h"
namespace {
@@ -117,9 +118,10 @@
if (indices.empty()) {
continue;
}
- glBindTexture(
- GL_TEXTURE_2D,
- g_gr->get_maptexture_data(terrains.get_unmutable(i).get_texture())->get_texture());
+ glBindTexture(GL_TEXTURE_2D,
+ g_gr->get_maptexture_data(terrains.get_unmutable(i).get_texture())
+ ->texture()
+ .get_gl_texture());
glDrawElements(GL_TRIANGLES, indices.size(), GL_UNSIGNED_SHORT, indices.data());
}
=== modified file 'src/graphic/graphic.cc'
--- src/graphic/graphic.cc 2014-11-24 07:32:34 +0000
+++ src/graphic/graphic.cc 2014-11-24 07:32:35 +0000
@@ -35,13 +35,15 @@
#include "graphic/animation.h"
#include "graphic/diranimations.h"
#include "graphic/font_handler.h"
-#include "graphic/gl/surface_screen.h"
+#include "graphic/gl/system_headers.h"
#include "graphic/image.h"
#include "graphic/image_io.h"
#include "graphic/image_transformations.h"
#include "graphic/rendertarget.h"
-#include "graphic/surface_cache.h"
+#include "graphic/screen.h"
+#include "graphic/terrain_texture.h"
#include "graphic/texture.h"
+#include "graphic/texture_cache.h"
#include "io/fileread.h"
#include "io/filesystem/layered_filesystem.h"
#include "io/streamwrite.h"
@@ -57,7 +59,7 @@
/// The size of the transient (i.e. temporary) surfaces in the cache in bytes.
/// These are all surfaces that are not loaded from disk.
-const uint32_t TRANSIENT_SURFACE_CACHE_SIZE = 160 << 20; // shifting converts to MB
+const uint32_t TRANSIENT_TEXTURE_CACHE_SIZE = 160 << 20; // shifting converts to MB
// Sets the icon for the application.
void set_icon(SDL_Window* sdl_window) {
@@ -80,8 +82,8 @@
: m_window_mode_width(window_mode_w),
m_window_mode_height(window_mode_h),
m_update(true),
- surface_cache_(create_surface_cache(TRANSIENT_SURFACE_CACHE_SIZE)),
- image_cache_(new ImageCache(surface_cache_.get())),
+ texture_cache_(create_texture_cache(TRANSIENT_TEXTURE_CACHE_SIZE)),
+ image_cache_(new ImageCache(texture_cache_.get())),
animation_manager_(new AnimationManager())
{
ImageTransformations::initialize();
@@ -156,15 +158,12 @@
disp_mode.h);
assert(SDL_BYTESPERPIXEL(disp_mode.format) == 4);
}
-
- pic_road_normal_.reset(load_image("world/pics/roadt_normal.png"));
- pic_road_busy_.reset(load_image("world/pics/roadt_busy.png"));
}
Graphic::~Graphic()
{
m_maptextures.clear();
- surface_cache_->flush();
+ texture_cache_->flush();
// TODO(unknown): this should really not be needed, but currently is :(
if (UI::g_fh)
UI::g_fh->flush();
@@ -209,7 +208,7 @@
int new_w, new_h;
SDL_GetWindowSize(m_sdl_window, &new_w, &new_h);
- screen_.reset(new GLSurfaceScreen(new_w, new_h));
+ screen_.reset(new Screen(new_w, new_h));
m_rendertarget.reset(new RenderTarget(screen_.get()));
Notifications::publish(GraphicResolutionChanged{new_w, new_h});
@@ -301,12 +300,12 @@
* @param sw a StreamWrite where the png is written to
*/
void Graphic::save_png(const Image* image, StreamWrite * sw) const {
- save_surface_to_png(image->surface(), sw);
+ save_surface_to_png(image->texture(), sw);
}
uint32_t Graphic::new_maptexture(const std::vector<std::string>& texture_files, const uint32_t frametime)
{
- m_maptextures.emplace_back(new Texture(texture_files, frametime));
+ m_maptextures.emplace_back(new TerrainTexture(texture_files, frametime));
return m_maptextures.size(); // ID 1 is at m_maptextures[0]
}
@@ -335,20 +334,10 @@
* Retrieve the map texture with the given number
* \return the actual texture data associated with the given ID.
*/
-Texture * Graphic::get_maptexture_data(uint32_t id)
+TerrainTexture * Graphic::get_maptexture_data(uint32_t id)
{
--id; // ID 1 is at m_maptextures[0]
assert(id < m_maptextures.size());
return m_maptextures[id].get();
}
-
-/**
- * Retrives the texture of the road type.
- * \return The road texture
- */
-Surface& Graphic::get_road_texture(int32_t roadtex)
-{
- return
- roadtex == Widelands::Road_Normal ? *pic_road_normal_.get() : *pic_road_busy_.get();
-}
=== modified file 'src/graphic/graphic.h'
--- src/graphic/graphic.h 2014-11-24 07:32:34 +0000
+++ src/graphic/graphic.h 2014-11-24 07:32:35 +0000
@@ -36,9 +36,9 @@
class AnimationManager;
class RenderTarget;
class Surface;
-class SurfaceCache;
+class TextureCache;
class StreamWrite;
-struct Texture;
+struct TerrainTexture;
// Will be send whenever the resolution changes.
struct GraphicResolutionChanged {
@@ -50,10 +50,10 @@
};
/**
- * This class is a kind of Swiss Army knife for your graphics need. It
- * initializes the graphic system and provides access to resolutions. It has an
- * Animation, Image and Surface cache and owns the road textures. It also
- * offers functionality to save a screenshot.
+ * This class is a kind of Swiss Army knife for your graphics need.
+ * It initializes the graphic system and provides access to
+ * resolutions. It owns an Animation, Image and Surface cache. It
+ * also offers functionality to save a screenshot.
*/
class Graphic {
public:
@@ -77,21 +77,19 @@
void refresh();
SDL_Window* get_sdlwindow() {return m_sdl_window;}
- SurfaceCache& surfaces() const {return *surface_cache_.get();}
+ TextureCache& textures() const {return *texture_cache_.get();}
ImageCache& images() const {return *image_cache_.get();}
AnimationManager& animations() const {return *animation_manager_.get();}
void save_png(const Image*, StreamWrite*) const;
- // Creates a new Texture() with the given 'frametime' and using the given
+ // Creates a new TerrainTexture() with the given 'frametime' and using the given
// 'texture_files' as the images for it and returns it id.
uint32_t new_maptexture(const std::vector<std::string>& texture_files, uint32_t frametime);
void animate_maptextures(uint32_t time);
void screenshot(const std::string& fname) const;
- Texture * get_maptexture_data(uint32_t id);
-
- Surface& get_road_texture(int32_t roadtex);
+ TerrainTexture * get_maptexture_data(uint32_t id);
private:
// Called when the resolution (might) have changed.
@@ -114,19 +112,15 @@
/// This marks the complete screen for updating.
bool m_update;
- /// Volatile cache of Hardware dependant surfaces.
- std::unique_ptr<SurfaceCache> surface_cache_;
+ /// Volatile cache of Hardware dependant textures.
+ std::unique_ptr<TextureCache> texture_cache_;
/// Non-volatile cache of hardware independent images. The use the
- /// surface_cache_ to cache their pixel data.
+ /// texture_cache_ to cache their pixel data.
std::unique_ptr<ImageCache> image_cache_;
/// This holds all animations.
std::unique_ptr<AnimationManager> animation_manager_;
- // The texture needed to draw roads.
- std::unique_ptr<Surface> pic_road_normal_;
- std::unique_ptr<Surface> pic_road_busy_;
-
- std::vector<std::unique_ptr<Texture>> m_maptextures;
+ std::vector<std::unique_ptr<TerrainTexture>> m_maptextures;
};
extern Graphic * g_gr;
=== modified file 'src/graphic/image.h'
--- src/graphic/image.h 2014-07-14 19:48:07 +0000
+++ src/graphic/image.h 2014-11-24 07:32:35 +0000
@@ -26,12 +26,12 @@
#include "base/macros.h"
+class Texture;
+
/**
* Interface to a bitmap that can act as the source of a rendering
* operation.
*/
-class Surface;
-
class Image {
public:
Image() = default;
@@ -41,7 +41,7 @@
virtual uint16_t height() const = 0;
// Internal functions needed for caching.
- virtual Surface* surface() const = 0;
+ virtual Texture* texture() const = 0;
virtual const std::string& hash() const = 0;
DISALLOW_COPY_AND_ASSIGN(Image);
=== modified file 'src/graphic/image_cache.cc'
--- src/graphic/image_cache.cc 2014-07-26 10:43:23 +0000
+++ src/graphic/image_cache.cc 2014-11-24 07:32:35 +0000
@@ -25,21 +25,21 @@
#include "base/log.h"
#include "graphic/image.h"
#include "graphic/image_io.h"
-#include "graphic/surface.h"
-#include "graphic/surface_cache.h"
+#include "graphic/texture.h"
+#include "graphic/texture_cache.h"
namespace {
// Image Implementation that loads images from disc when they should be drawn.
-// Uses SurfaceCache. These images are meant to be cached in ImageCache.
+// Uses TextureCache. These images are meant to be cached in ImageCache.
class FromDiskImage : public Image {
public:
- FromDiskImage(const std::string& filename, SurfaceCache* surface_cache) :
+ FromDiskImage(const std::string& filename, TextureCache* texture_cache) :
filename_(filename),
- surface_cache_(surface_cache) {
- Surface* surf = reload_image_();
- w_ = surf->width();
- h_ = surf->height();
+ texture_cache_(texture_cache) {
+ Texture* texture = reload_image_();
+ w_ = texture->width();
+ h_ = texture->height();
}
virtual ~FromDiskImage() {}
@@ -47,27 +47,27 @@
uint16_t width() const override {return w_; }
uint16_t height() const override {return h_;}
const std::string& hash() const override {return filename_;}
- Surface* surface() const override {
- Surface* surf = surface_cache_->get(filename_);
- if (surf)
- return surf;
+ Texture* texture() const override {
+ Texture* texture = texture_cache_->get(filename_);
+ if (texture)
+ return texture;
return reload_image_();
}
private:
- Surface* reload_image_() const {
- Surface* surf = surface_cache_->insert(filename_, load_image(filename_), false);
- return surf;
+ Texture* reload_image_() const {
+ Texture* texture = texture_cache_->insert(filename_, load_image(filename_), false);
+ return texture;
}
uint16_t w_, h_;
const std::string filename_;
- SurfaceCache* const surface_cache_; // Not owned.
+ TextureCache* const texture_cache_; // Not owned.
};
} // namespace
-ImageCache::ImageCache(SurfaceCache* const surface_cache) : surface_cache_(surface_cache) {
+ImageCache::ImageCache(TextureCache* const texture_cache) : texture_cache_(texture_cache) {
}
ImageCache::~ImageCache() {
@@ -90,7 +90,7 @@
const Image* ImageCache::get(const std::string& hash) {
ImageMap::const_iterator it = images_.find(hash);
if (it == images_.end()) {
- images_.insert(make_pair(hash, new FromDiskImage(hash, surface_cache_)));
+ images_.insert(make_pair(hash, new FromDiskImage(hash, texture_cache_)));
return get(hash);
}
return it->second;
=== modified file 'src/graphic/image_cache.h'
--- src/graphic/image_cache.h 2014-09-14 11:31:58 +0000
+++ src/graphic/image_cache.h 2014-11-24 07:32:35 +0000
@@ -28,7 +28,7 @@
#include "base/macros.h"
#include "graphic/image.h"
-class SurfaceCache;
+class TextureCache;
// For historic reasons, most part of the Widelands code base expect that an
// Image stays valid for the whole duration of the program run. This class is
@@ -40,7 +40,7 @@
class ImageCache {
public:
// Does not take ownership.
- ImageCache(SurfaceCache* surface_cache);
+ ImageCache(TextureCache* texture_cache);
~ImageCache();
// Insert the given Image into the cache. The hash is defined by Image's hash()
@@ -60,7 +60,7 @@
using ImageMap = std::map<std::string, const Image*>;
ImageMap images_; /// hash of cached filename/image pairs
- SurfaceCache* const surface_cache_; // Not owned.
+ TextureCache* const texture_cache_; // Not owned.
DISALLOW_COPY_AND_ASSIGN(ImageCache);
};
=== modified file 'src/graphic/image_io.cc'
--- src/graphic/image_io.cc 2014-09-20 09:37:47 +0000
+++ src/graphic/image_io.cc 2014-11-24 07:32:35 +0000
@@ -26,7 +26,7 @@
#include <png.h>
#include "base/wexception.h"
-#include "graphic/surface.h"
+#include "graphic/texture.h"
#include "io/fileread.h"
#include "io/filesystem/layered_filesystem.h"
#include "io/streamwrite.h"
@@ -47,8 +47,8 @@
} // namespace
-Surface* load_image(const std::string& fname, FileSystem* fs) {
- return Surface::create(load_image_as_sdl_surface(fname, fs));
+Texture* load_image(const std::string& fname, FileSystem* fs) {
+ return new Texture(load_image_as_sdl_surface(fname, fs));
}
SDL_Surface* load_image_as_sdl_surface(const std::string& fname, FileSystem* fs) {
=== modified file 'src/graphic/image_io.h'
--- src/graphic/image_io.h 2014-09-09 17:15:20 +0000
+++ src/graphic/image_io.h 2014-11-24 07:32:35 +0000
@@ -25,6 +25,7 @@
#include "base/wexception.h"
class FileSystem;
+class Texture;
class StreamWrite;
class Surface;
struct SDL_Surface;
@@ -43,12 +44,11 @@
};
/// Loads the image 'fn' from 'fs'.
-Surface* load_image(const std::string& fn, FileSystem* fs = nullptr);
+Texture* load_image(const std::string& fn, FileSystem* fs = nullptr);
/// Loads the image 'fn' from 'fs' into an SDL_Surface. Caller must SDL_FreeSurface() the returned value.
SDL_Surface* load_image_as_sdl_surface(const std::string& fn, FileSystem* fs = nullptr);
-
/// Saves the 'surface' to 'sw' as a PNG.
bool save_surface_to_png(Surface* surface, StreamWrite* sw);
=== modified file 'src/graphic/image_transformations.cc'
--- src/graphic/image_transformations.cc 2014-11-22 21:31:21 +0000
+++ src/graphic/image_transformations.cc 2014-11-24 07:32:35 +0000
@@ -28,8 +28,8 @@
#include "base/macros.h"
#include "graphic/color.h"
#include "graphic/graphic.h"
-#include "graphic/surface.h"
-#include "graphic/surface_cache.h"
+#include "graphic/texture.h"
+#include "graphic/texture_cache.h"
using namespace std;
@@ -44,24 +44,24 @@
* Create and return an \ref SDL_Surface that contains the given sub-rectangle
* of the given pixel region.
*/
-SDL_Surface* extract_sdl_surface(Surface & surf, Rect srcrect)
+SDL_Surface* extract_sdl_surface(Texture & texture, Rect srcrect)
{
assert(srcrect.x >= 0);
assert(srcrect.y >= 0);
- assert(srcrect.x + srcrect.w <= surf.width());
- assert(srcrect.y + srcrect.h <= surf.height());
+ assert(srcrect.x + srcrect.w <= texture.width());
+ assert(srcrect.y + srcrect.h <= texture.height());
- const SDL_PixelFormat & fmt = surf.format();
+ const SDL_PixelFormat & fmt = texture.format();
SDL_Surface * dest = SDL_CreateRGBSurface
(SDL_SWSURFACE, srcrect.w, srcrect.h,
fmt.BitsPerPixel, fmt.Rmask, fmt.Gmask, fmt.Bmask, fmt.Amask);
- surf.lock(Surface::Lock_Normal);
+ texture.lock(Surface::Lock_Normal);
SDL_LockSurface(dest);
- uint32_t srcpitch = surf.get_pitch();
+ uint32_t srcpitch = texture.get_pitch();
uint32_t rowsize = srcrect.w * fmt.BytesPerPixel;
- uint8_t * srcpix = surf.get_pixels() + srcpitch * srcrect.y + fmt.BytesPerPixel * srcrect.x;
+ uint8_t * srcpix = texture.get_pixels() + srcpitch * srcrect.y + fmt.BytesPerPixel * srcrect.x;
uint8_t * dstpix = static_cast<uint8_t *>(dest->pixels);
for (uint32_t y = 0; y < srcrect.h; ++y) {
@@ -71,7 +71,7 @@
}
SDL_UnlockSurface(dest);
- surf.unlock(Surface::Unlock_NoChange);
+ texture.unlock(Surface::Unlock_NoChange);
return dest;
}
@@ -79,7 +79,7 @@
/**
* Produces a resized version of the specified image
*/
-Surface* resize_surface(Surface* src, uint32_t w, uint32_t h) {
+Texture* resize_surface(Texture* src, uint32_t w, uint32_t h) {
assert(w != src->width() || h != src->height());
// First step: compute scaling factors
@@ -89,7 +89,7 @@
SDL_Surface * srcsdl = extract_sdl_surface(*src, srcrect);
bool free_source = true;
- // If we actually shrink a surface, ballpark the zoom so that the shrinking
+ // If we actually shrink a texture, ballpark the zoom so that the shrinking
// effect is weakened.
int factor = 1;
while ((static_cast<double>(w) * factor / srcsdl->w) < 1. ||
@@ -146,29 +146,29 @@
zoomed = placed;
}
- return Surface::create(zoomed);
+ return new Texture(zoomed);
}
/**
- * Create a grayed version of the given surface.
+ * Create a grayed version of the given texture.
*/
-Surface* gray_out_surface(Surface* surf) {
- assert(surf);
-
- uint16_t w = surf->width();
- uint16_t h = surf->height();
- const SDL_PixelFormat & origfmt = surf->format();
-
- Surface* dest = Surface::create(w, h);
+Texture* gray_out_texture(Texture* texture) {
+ assert(texture);
+
+ uint16_t w = texture->width();
+ uint16_t h = texture->height();
+ const SDL_PixelFormat & origfmt = texture->format();
+
+ Texture* dest = new Texture(w, h);
const SDL_PixelFormat & destfmt = dest->format();
- surf->lock(Surface::Lock_Normal);
+ texture->lock(Surface::Lock_Normal);
dest->lock(Surface::Lock_Discard);
for (uint32_t y = 0; y < h; ++y) {
for (uint32_t x = 0; x < w; ++x) {
RGBAColor color;
- color.set(origfmt, surf->get_pixel(x, y));
+ color.set(origfmt, texture->get_pixel(x, y));
// Halve the opacity to give some difference for image that are
// grayscale to begin with.
@@ -184,32 +184,32 @@
dest->set_pixel(x, y, color.map(destfmt));
}
}
- surf->unlock(Surface::Unlock_NoChange);
+ texture->unlock(Surface::Unlock_NoChange);
dest->unlock(Surface::Unlock_Update);
return dest;
}
/**
- * Creates an image with changed luminosity from the given surface.
+ * Creates an image with changed luminosity from the given texture.
*/
-Surface* change_luminosity_of_surface(Surface* surf, float factor, bool halve_alpha) {
- assert(surf);
-
- uint16_t w = surf->width();
- uint16_t h = surf->height();
- const SDL_PixelFormat & origfmt = surf->format();
-
- Surface* dest = Surface::create(w, h);
+Texture* change_luminosity_of_texture(Texture* texture, float factor, bool halve_alpha) {
+ assert(texture);
+
+ uint16_t w = texture->width();
+ uint16_t h = texture->height();
+ const SDL_PixelFormat & origfmt = texture->format();
+
+ Texture* dest = new Texture(w, h);
const SDL_PixelFormat & destfmt = dest->format();
- surf->lock(Surface::Lock_Normal);
+ texture->lock(Surface::Lock_Normal);
dest->lock(Surface::Lock_Discard);
for (uint32_t y = 0; y < h; ++y) {
for (uint32_t x = 0; x < w; ++x) {
RGBAColor color;
- color.set(origfmt, surf->get_pixel(x, y));
+ color.set(origfmt, texture->get_pixel(x, y));
if (halve_alpha)
color.a >>= 1;
@@ -221,7 +221,7 @@
dest->set_pixel(x, y, color.map(destfmt));
}
}
- surf->unlock(Surface::Unlock_NoChange);
+ texture->unlock(Surface::Unlock_NoChange);
dest->unlock(Surface::Unlock_Update);
return dest;
@@ -229,26 +229,28 @@
// Encodes the given Image into the corresponding image for player color.
// Takes the neutral set of images and the player color mask.
-Surface* make_playerclr_surface(Surface& orig_surface, Surface& pcmask_surface, const RGBColor& color) {
- Surface* new_surface = Surface::create(orig_surface.width(), orig_surface.height());
-
- const SDL_PixelFormat & fmt = orig_surface.format();
- const SDL_PixelFormat & fmt_pc = pcmask_surface.format();
- const SDL_PixelFormat & destfmt = new_surface->format();
-
- orig_surface.lock(Surface::Lock_Normal);
- pcmask_surface.lock(Surface::Lock_Normal);
- new_surface->lock(Surface::Lock_Discard);
+Texture* make_playerclr_texture(Texture& original_texture,
+ Texture& pcmask_texture,
+ const RGBColor& color) {
+ Texture* new_texture = new Texture(original_texture.width(), original_texture.height());
+
+ const SDL_PixelFormat & fmt = original_texture.format();
+ const SDL_PixelFormat & fmt_pc = pcmask_texture.format();
+ const SDL_PixelFormat & destfmt = new_texture->format();
+
+ original_texture.lock(Surface::Lock_Normal);
+ pcmask_texture.lock(Surface::Lock_Normal);
+ new_texture->lock(Surface::Lock_Discard);
// This could be done significantly faster, but since we
// cache the result, let's keep it simple for now.
- for (uint32_t y = 0; y < orig_surface.height(); ++y) {
- for (uint32_t x = 0; x < orig_surface.width(); ++x) {
+ for (uint32_t y = 0; y < original_texture.height(); ++y) {
+ for (uint32_t x = 0; x < original_texture.width(); ++x) {
RGBAColor source;
RGBAColor mask;
RGBAColor product;
- source.set(fmt, orig_surface.get_pixel(x, y));
- mask.set(fmt_pc, pcmask_surface.get_pixel(x, y));
+ source.set(fmt, original_texture.get_pixel(x, y));
+ mask.set(fmt_pc, pcmask_texture.get_pixel(x, y));
if
(uint32_t const influence =
@@ -277,45 +279,45 @@
product = source;
}
- new_surface->set_pixel(x, y, product.map(destfmt));
+ new_texture->set_pixel(x, y, product.map(destfmt));
}
}
- orig_surface.unlock(Surface::Unlock_NoChange);
- pcmask_surface.unlock(Surface::Unlock_NoChange);
- new_surface->unlock(Surface::Unlock_Update);
+ original_texture.unlock(Surface::Unlock_NoChange);
+ pcmask_texture.unlock(Surface::Unlock_NoChange);
+ new_texture->unlock(Surface::Unlock_Update);
- return new_surface;
+ return new_texture;
}
// An Image implementation that is the transformation of another Image. Uses
-// the SurfaceCache to avoid recalculating the transformation too often. No
+// the TextureCache to avoid recalculating the transformation too often. No
// ownerships are taken.
class TransformedImage : public Image {
public:
- TransformedImage(const string& ghash, const Image& original, SurfaceCache* surface_cache) :
- hash_(ghash), original_(original), surface_cache_(surface_cache) {}
+ TransformedImage(const string& ghash, const Image& original, TextureCache* texture_cache) :
+ hash_(ghash), original_(original), texture_cache_(texture_cache) {}
virtual ~TransformedImage() {}
// Implements Image.
uint16_t width() const override {return original_.width();}
uint16_t height() const override {return original_.height();}
const string& hash() const override {return hash_;}
- Surface* surface() const override {
- Surface* surf = surface_cache_->get(hash_);
- if (surf)
- return surf;
+ Texture* texture() const override {
+ Texture* texture = texture_cache_->get(hash_);
+ if (texture)
+ return texture;
- surf = recalculate_surface();
- surface_cache_->insert(hash_, surf, true);
- return surf;
+ texture = recalculate_texture();
+ texture_cache_->insert(hash_, texture, true);
+ return texture;
}
- virtual Surface* recalculate_surface() const = 0;
+ virtual Texture* recalculate_texture() const = 0;
protected:
const string hash_;
const Image& original_;
- SurfaceCache* const surface_cache_; // not owned
+ TextureCache* const texture_cache_; // not owned
};
// A resized copy of an Image.
@@ -323,8 +325,8 @@
public:
ResizedImage
(const string& ghash, const Image& original,
- SurfaceCache* surface_cache, uint16_t w, uint16_t h)
- : TransformedImage(ghash, original, surface_cache), w_(w), h_(h) {
+ TextureCache* texture_cache, uint16_t w, uint16_t h)
+ : TransformedImage(ghash, original, texture_cache), w_(w), h_(h) {
assert(w != original.width() || h != original.height());
}
virtual ~ResizedImage() {}
@@ -334,8 +336,8 @@
uint16_t height() const override {return h_;}
// Implements TransformedImage.
- Surface* recalculate_surface() const override {
- Surface* rv = resize_surface(original_.surface(), w_, h_);
+ Texture* recalculate_texture() const override {
+ Texture* rv = resize_surface(original_.texture(), w_, h_);
return rv;
}
@@ -346,14 +348,14 @@
// A grayed out copy of an Image.
class GrayedOutImage : public TransformedImage {
public:
- GrayedOutImage(const string& ghash, const Image& original, SurfaceCache* surface_cache) :
- TransformedImage(ghash, original, surface_cache)
+ GrayedOutImage(const string& ghash, const Image& original, TextureCache* texture_cache) :
+ TransformedImage(ghash, original, texture_cache)
{}
virtual ~GrayedOutImage() {}
// Implements TransformedImage.
- Surface* recalculate_surface() const override {
- return gray_out_surface(original_.surface());
+ Texture* recalculate_texture() const override {
+ return gray_out_texture(original_.texture());
}
};
@@ -362,16 +364,16 @@
public:
ChangeLuminosityImage
(const string& ghash, const Image& original,
- SurfaceCache* surface_cache, float factor, bool halve_alpha)
- : TransformedImage(ghash, original, surface_cache),
+ TextureCache* texture_cache, float factor, bool halve_alpha)
+ : TransformedImage(ghash, original, texture_cache),
factor_(factor),
halve_alpha_(halve_alpha)
{}
virtual ~ChangeLuminosityImage() {}
// Implements TransformedImage.
- Surface* recalculate_surface() const override {
- return change_luminosity_of_surface(original_.surface(), factor_, halve_alpha_);
+ Texture* recalculate_texture() const override {
+ return change_luminosity_of_texture(original_.texture(), factor_, halve_alpha_);
}
private:
@@ -385,14 +387,14 @@
public:
PlayerColoredImage
(const string& ghash, const Image& original,
- SurfaceCache* surface_cache, const RGBColor& color, const Image& mask)
- : TransformedImage(ghash, original, surface_cache), color_(color), mask_(mask)
+ TextureCache* texture_cache, const RGBColor& color, const Image& mask)
+ : TransformedImage(ghash, original, texture_cache), color_(color), mask_(mask)
{}
virtual ~PlayerColoredImage() {}
// Implements TransformedImage.
- Surface* recalculate_surface() const override {
- return make_playerclr_surface(*original_.surface(), *mask_.surface(), color_);
+ Texture* recalculate_texture() const override {
+ return make_playerclr_texture(*original_.texture(), *mask_.texture(), color_);
}
private:
@@ -425,7 +427,7 @@
if (g_gr->images().has(new_hash))
return g_gr->images().get(new_hash);
return
- g_gr->images().insert(new ResizedImage(new_hash, *original, &g_gr->surfaces(), w, h));
+ g_gr->images().insert(new ResizedImage(new_hash, *original, &g_gr->textures(), w, h));
}
const Image* gray_out(const Image* original) {
@@ -433,7 +435,7 @@
if (g_gr->images().has(new_hash))
return g_gr->images().get(new_hash);
return
- g_gr->images().insert(new GrayedOutImage(new_hash, *original, &g_gr->surfaces()));
+ g_gr->images().insert(new GrayedOutImage(new_hash, *original, &g_gr->textures()));
}
const Image* change_luminosity(const Image* original, float factor, bool halve_alpha) {
@@ -443,7 +445,7 @@
return g_gr->images().get(new_hash);
return
g_gr->images().insert
- (new ChangeLuminosityImage(new_hash, *original, &g_gr->surfaces(), factor, halve_alpha));
+ (new ChangeLuminosityImage(new_hash, *original, &g_gr->textures(), factor, halve_alpha));
}
const Image* player_colored(const RGBColor& clr, const Image* original, const Image* mask) {
@@ -455,7 +457,7 @@
return g_gr->images().get(new_hash);
return
g_gr->images().insert
- (new PlayerColoredImage(new_hash, *original, &g_gr->surfaces(), clr, *mask));
+ (new PlayerColoredImage(new_hash, *original, &g_gr->textures(), clr, *mask));
}
} // namespace ImageTransformations
=== modified file 'src/graphic/in_memory_image.cc'
--- src/graphic/in_memory_image.cc 2014-07-26 10:43:23 +0000
+++ src/graphic/in_memory_image.cc 2014-11-24 07:32:35 +0000
@@ -22,15 +22,15 @@
#include <memory>
#include "graphic/image.h"
-#include "graphic/surface.h"
+#include "graphic/texture.h"
using namespace std;
// An Image implementation the does !not! cache its Surface in the
-// SurfaceCache. Avoid using this whenever possible and also do not store it in
+// TextureCache. Avoid using this whenever possible and also do not store it in
// the ImageCache.
//
-// This is only used when the surface can not be easily recalculated on the fly
+// This is only used when the texture can not be easily recalculated on the fly
// or if ownership of the image is managed by the caller itself. Note that this
// is always tricky because Widelands assumes in many places that Images can be
// relied to exist forever. So when you pass out a pointer to your
@@ -38,24 +38,24 @@
// or prepare for core dumps.
class InMemoryImage : public Image {
public:
- InMemoryImage(const string& ghash, Surface* surf) :
- hash_(ghash), surf_(surf) {}
+ InMemoryImage(const string& ghash, Texture* texture) :
+ hash_(ghash), texture_(texture) {}
virtual ~InMemoryImage() {
}
// Implements Image.
- uint16_t width() const override {return surf_->width();}
- uint16_t height() const override {return surf_->height();}
+ uint16_t width() const override {return texture_->width();}
+ uint16_t height() const override {return texture_->height();}
// Note: hash will mostly be dummy values for this implementation. It should
// not wind up in ImageCache, otherwise the ownership question is not clear.
const string& hash() const override {return hash_;}
- Surface* surface() const override {return surf_.get();}
+ Texture* texture() const override {return texture_.get();}
private:
const string hash_;
- std::unique_ptr<Surface> surf_;
+ std::unique_ptr<Texture> texture_;
};
-const Image* new_in_memory_image(const string& hash, Surface* surf) {
- return new InMemoryImage(hash, surf);
+const Image* new_in_memory_image(const string& hash, Texture* texture) {
+ return new InMemoryImage(hash, texture);
}
=== modified file 'src/graphic/in_memory_image.h'
--- src/graphic/in_memory_image.h 2014-07-05 16:41:51 +0000
+++ src/graphic/in_memory_image.h 2014-11-24 07:32:35 +0000
@@ -22,9 +22,9 @@
#include <string>
+class Texture;
class Image;
-class Surface;
-const Image* new_in_memory_image(const std::string& hash, Surface* surf);
+const Image* new_in_memory_image(const std::string& hash, Texture* texture);
#endif // end of include guard: WL_GRAPHIC_IN_MEMORY_IMAGE_H
=== modified file 'src/graphic/minimap_renderer.cc'
--- src/graphic/minimap_renderer.cc 2014-09-27 18:53:55 +0000
+++ src/graphic/minimap_renderer.cc 2014-11-24 07:32:35 +0000
@@ -27,7 +27,7 @@
#include "graphic/graphic.h"
#include "graphic/image.h"
#include "graphic/in_memory_image.h"
-#include "graphic/surface.h"
+#include "graphic/terrain_texture.h"
#include "graphic/texture.h"
#include "logic/field.h"
#include "logic/map.h"
@@ -154,16 +154,16 @@
// Does the actual work of drawing the minimap.
void draw_minimap_int
- (Surface* surface, const Widelands::EditorGameBase& egbase,
+ (Texture* texture, const Widelands::EditorGameBase& egbase,
const Widelands::Player* player, const Point& viewpoint, MiniMapLayer layers)
{
const Widelands::Map & map = egbase.map();
- uint8_t* const pixels = surface->get_pixels();
- const SDL_PixelFormat& format = surface->format();
- const uint16_t pitch = surface->get_pitch();
- const uint16_t surface_h = surface->height();
- const uint16_t surface_w = surface->width();
+ uint8_t* const pixels = texture->get_pixels();
+ const SDL_PixelFormat& format = texture->format();
+ const uint16_t pitch = texture->get_pitch();
+ const uint16_t surface_h = texture->height();
+ const uint16_t surface_w = texture->width();
// size of the display frame
int32_t xsize = g_gr->get_xres() / TRIANGLE_WIDTH / 2;
@@ -258,29 +258,29 @@
} // namespace
-std::unique_ptr<Surface> draw_minimap(const EditorGameBase& egbase,
+std::unique_ptr<Texture> draw_minimap(const EditorGameBase& egbase,
const Player* player,
const Point& viewpoint,
MiniMapLayer layers) {
// First create a temporary SDL Surface to draw the minimap.
// TODO(unknown): Currently the minimap is redrawn every frame. That is not really
- // necesary. The created surface could be cached and only redrawn two
+ // necesary. The created texture could be cached and only redrawn two
// or three times per second
const Map& map = egbase.map();
const int16_t map_w = (layers & MiniMapLayer::Zoom2) ? map.get_width() * 2 : map.get_width();
const int16_t map_h = (layers & MiniMapLayer::Zoom2) ? map.get_height() * 2 : map.get_height();
- Surface* surface = Surface::create(map_w, map_h);
- assert(surface->format().BytesPerPixel == sizeof(uint32_t));
-
- surface->fill_rect(Rect(0, 0, surface->width(), surface->height()), RGBAColor(0, 0, 0, 255));
- surface->lock(Surface::Lock_Normal);
-
- draw_minimap_int(surface, egbase, player, viewpoint, layers);
-
- surface->unlock(Surface::Unlock_Update);
-
- return std::unique_ptr<Surface>(surface);
+ Texture* texture = new Texture(map_w, map_h);
+ assert(texture->format().BytesPerPixel == sizeof(uint32_t));
+
+ texture->fill_rect(Rect(0, 0, texture->width(), texture->height()), RGBAColor(0, 0, 0, 255));
+ texture->lock(Surface::Lock_Normal);
+
+ draw_minimap_int(texture, egbase, player, viewpoint, layers);
+
+ texture->unlock(Surface::Unlock_Update);
+
+ return std::unique_ptr<Texture>(texture);
}
void write_minimap_image
@@ -309,8 +309,8 @@
viewpoint.y -= map_h / 2;
// Render minimap
- std::unique_ptr<Surface> surface(draw_minimap(egbase, player, viewpoint, layers));
- std::unique_ptr<const Image> image(new_in_memory_image("minimap", surface.release()));
+ std::unique_ptr<Texture> texture(draw_minimap(egbase, player, viewpoint, layers));
+ std::unique_ptr<const Image> image(new_in_memory_image("minimap", texture.release()));
g_gr->save_png(image.get(), streamwrite);
image.reset();
}
=== modified file 'src/graphic/minimap_renderer.h'
--- src/graphic/minimap_renderer.h 2014-09-27 18:53:55 +0000
+++ src/graphic/minimap_renderer.h 2014-11-24 07:32:35 +0000
@@ -22,9 +22,9 @@
#include <memory>
-#include "graphic/rendertarget.h"
-
class StreamWrite;
+class Texture;
+struct Point;
namespace Widelands {
class Player;
@@ -56,7 +56,7 @@
/// Render the minimap. If player is not nullptr, it renders from that player's
/// point of view.
/// \param viewpoint: top left corner in map coordinates
-std::unique_ptr<Surface> draw_minimap
+std::unique_ptr<Texture> draw_minimap
(const Widelands::EditorGameBase& egbase, const Widelands::Player* player,
const Point& viewpoint, MiniMapLayer layers);
=== modified file 'src/graphic/rendertarget.cc'
--- src/graphic/rendertarget.cc 2014-09-10 13:03:40 +0000
+++ src/graphic/rendertarget.cc 2014-11-24 07:32:35 +0000
@@ -166,7 +166,7 @@
* If the source surface contains a alpha channel this is used during
* the blit.
*/
-void RenderTarget::blit(const Point& dst, const Image* image, Composite cm, UI::Align align)
+void RenderTarget::blit(const Point& dst, const Image* image, BlendMode blend_mode, UI::Align align)
{
Point dstpoint(dst);
@@ -175,14 +175,14 @@
Rect srcrc(Point(0, 0), image->width(), image->height());
if (to_surface_geometry(&dstpoint, &srcrc))
- m_surface->blit(dstpoint, image->surface(), srcrc, cm);
+ m_surface->blit(dstpoint, image->texture(), srcrc, blend_mode);
}
/**
* Like \ref blit, but use only a sub-rectangle of the source image.
*/
void RenderTarget::blitrect
- (const Point& dst, const Image* image, const Rect& gsrcrc, Composite cm)
+ (const Point& dst, const Image* image, const Rect& gsrcrc, BlendMode blend_mode)
{
assert(0 <= gsrcrc.x);
assert(0 <= gsrcrc.y);
@@ -196,7 +196,7 @@
Point dstpt(dst);
if (to_surface_geometry(&dstpt, &srcrc))
- m_surface->blit(dstpt, image->surface(), srcrc, cm);
+ m_surface->blit(dstpt, image->texture(), srcrc, blend_mode);
}
/**
@@ -205,7 +205,7 @@
* The pixel from ofs inside image is placed at the top-left corner of
* the filled rectangle.
*/
-void RenderTarget::tile(const Rect& rect, const Image* image, const Point& gofs, Composite cm)
+void RenderTarget::tile(const Rect& rect, const Image* image, const Point& gofs, BlendMode blend_mode)
{
int32_t srcw = image->width();
int32_t srch = image->height();
@@ -251,7 +251,7 @@
if (tx + srcrc.w > r.w)
srcrc.w = r.w - tx;
- m_surface->blit(r.top_left() + Point(tx, ty), image->surface(), srcrc, cm);
+ m_surface->blit(r.top_left() + Point(tx, ty), image->texture(), srcrc, blend_mode);
tx += srcrc.w;
=== modified file 'src/graphic/rendertarget.h'
--- src/graphic/rendertarget.h 2014-11-02 14:11:52 +0000
+++ src/graphic/rendertarget.h 2014-11-24 07:32:35 +0000
@@ -24,8 +24,8 @@
#include "base/rect.h"
#include "graphic/align.h"
+#include "graphic/blend_mode.h"
#include "graphic/color.h"
-#include "graphic/compositemode.h"
#include "graphic/image.h"
class Surface;
@@ -64,9 +64,20 @@
void fill_rect(const Rect&, const RGBAColor&);
void brighten_rect(const Rect&, int32_t factor);
- void blit(const Point& dst, const Image* image, Composite cm = CM_UseAlpha, UI::Align = UI::Align_TopLeft);
- void blitrect(const Point& dst, const Image* image, const Rect& src, Composite cm = CM_UseAlpha);
- void tile(const Rect&, const Image* image, const Point& ofs, Composite cm = CM_UseAlpha);
+ void blit(const Point& dst,
+ const Image* image,
+ BlendMode blend_mode = BlendMode::UseAlpha,
+ UI::Align = UI::Align_TopLeft);
+
+ void blitrect(const Point& dst,
+ const Image* image,
+ const Rect& src,
+ BlendMode blend_mode = BlendMode::UseAlpha);
+
+ void tile(const Rect&,
+ const Image* image,
+ const Point& ofs,
+ BlendMode blend_mode = BlendMode::UseAlpha);
void drawanim(const Point& dst, uint32_t animation, uint32_t time, const Widelands::Player* = 0);
void drawanimrect
=== renamed file 'src/graphic/gl/surface_screen.cc' => 'src/graphic/screen.cc'
--- src/graphic/gl/surface_screen.cc 2014-11-22 21:31:21 +0000
+++ src/graphic/screen.cc 2014-11-24 07:32:35 +0000
@@ -16,20 +16,20 @@
* Foundation, Inc., 51 Franklin Street, Fifth Floor, Boston, MA 02110-1301, USA.
*/
-#include "graphic/gl/surface_screen.h"
+#include "graphic/screen.h"
#include <algorithm>
#include <cassert>
#include "graphic/gl/utils.h"
-GLSurfaceScreen::GLSurfaceScreen(uint16_t w, uint16_t h)
+Screen::Screen(uint16_t w, uint16_t h)
{
m_w = w;
m_h = h;
}
-void GLSurfaceScreen::pixel_to_gl(float* x, float* y) const {
+void Screen::pixel_to_gl(float* x, float* y) const {
*x = (*x / m_w) * 2. - 1.;
*y = 1. - (*y / m_h) * 2.;
}
@@ -38,7 +38,7 @@
* Swap order of rows in m_pixels, to compensate for the upside-down nature of the
* OpenGL coordinate system.
*/
-void GLSurfaceScreen::swap_rows()
+void Screen::swap_rows()
{
uint8_t * begin_row = m_pixels.get();
uint8_t * end_row = m_pixels.get() + (m_w * (m_h - 1) * 4);
@@ -52,7 +52,7 @@
}
}
-void GLSurfaceScreen::lock(Surface::LockMode mode)
+void Screen::lock(Surface::LockMode mode)
{
assert(!m_pixels);
@@ -70,7 +70,7 @@
}
}
-void GLSurfaceScreen::unlock(Surface::UnlockMode mode)
+void Screen::unlock(Surface::UnlockMode mode)
{
assert(m_pixels);
=== renamed file 'src/graphic/gl/surface_screen.h' => 'src/graphic/screen.h'
--- src/graphic/gl/surface_screen.h 2014-11-22 21:31:21 +0000
+++ src/graphic/screen.h 2014-11-24 07:32:35 +0000
@@ -16,18 +16,18 @@
* Foundation, Inc., 51 Franklin Street, Fifth Floor, Boston, MA 02110-1301, USA.
*/
-#ifndef WL_GRAPHIC_GL_SURFACE_SCREEN_H
-#define WL_GRAPHIC_GL_SURFACE_SCREEN_H
+#ifndef WL_GRAPHIC_SCREEN_H
+#define WL_GRAPHIC_SCREEN_H
#include "graphic/surface.h"
/**
* This surface represents the screen in OpenGL mode.
*/
-class GLSurfaceScreen : public Surface {
+class Screen : public Surface {
public:
- GLSurfaceScreen(uint16_t w, uint16_t h);
- virtual ~GLSurfaceScreen() {}
+ Screen(uint16_t w, uint16_t h);
+ virtual ~Screen() {}
/// Interface implementations
void lock(LockMode) override;
@@ -39,4 +39,4 @@
void swap_rows();
};
-#endif // end of include guard:
+#endif // end of include guard: WL_GRAPHIC_SCREEN_H
=== modified file 'src/graphic/surface.cc'
--- src/graphic/surface.cc 2014-11-22 21:31:21 +0000
+++ src/graphic/surface.cc 2014-11-24 07:32:35 +0000
@@ -30,18 +30,9 @@
#include "graphic/gl/draw_line_program.h"
#include "graphic/gl/draw_rect_program.h"
#include "graphic/gl/fill_rect_program.h"
-#include "graphic/gl/surface_texture.h"
#include "graphic/gl/utils.h"
#include "graphic/graphic.h"
-
-
-Surface* Surface::create(SDL_Surface* surf) {
- return new GLSurfaceTexture(surf);
-}
-
-Surface* Surface::create(uint16_t w, uint16_t h) {
- return new GLSurfaceTexture(w, h);
-}
+#include "graphic/texture.h"
uint16_t Surface::width() const {
@@ -167,12 +158,11 @@
}
void Surface::blit
- (const Point& dst, const Surface* image, const Rect& srcrc, Composite cm)
+ (const Point& dst, const Texture* texture, const Rect& srcrc, BlendMode blend_mode)
{
glViewport(0, 0, width(), height());
// Source Rectangle.
- const GLSurfaceTexture* const texture = static_cast<const GLSurfaceTexture*>(image);
FloatRect gl_src_rect;
{
float x1 = srcrc.x;
@@ -189,5 +179,5 @@
const FloatRect gl_dst_rect = to_opengl(Rect(dst.x, dst.y, srcrc.w, srcrc.h), ConversionMode::kExact);
- BlitProgram::instance().draw(gl_dst_rect, gl_src_rect, texture->get_gl_texture(), cm);
+ BlitProgram::instance().draw(gl_dst_rect, gl_src_rect, texture->get_gl_texture(), blend_mode);
}
=== modified file 'src/graphic/surface.h'
--- src/graphic/surface.h 2014-11-22 21:31:21 +0000
+++ src/graphic/surface.h 2014-11-24 07:32:35 +0000
@@ -24,8 +24,10 @@
#include "base/macros.h"
#include "base/rect.h"
+#include "graphic/blend_mode.h"
#include "graphic/color.h"
-#include "graphic/compositemode.h"
+
+class Texture;
/**
* Interface to a basic surfaces that can be used as destination for blitting and drawing.
@@ -33,13 +35,6 @@
*/
class Surface {
public:
- // Create a new surface from an SDL_Surface. Ownership is taken.
- static Surface* create(SDL_Surface*);
-
- // Create a new empty (that is randomly filled) Surface with the given
- // dimensions.
- static Surface* create(uint16_t w, uint16_t h);
-
Surface() = default;
virtual ~Surface() {}
@@ -48,10 +43,13 @@
uint16_t height() const;
/// This draws a part of another surface to this surface
- virtual void blit(const Point&, const Surface*, const Rect& srcrc, Composite cm = CM_UseAlpha);
+ virtual void blit(const Point&,
+ const Texture*,
+ const Rect& srcrc,
+ BlendMode blend_mode = BlendMode::UseAlpha);
/// Draws a filled rect to the surface. No blending takes place, the values
- //in the target are just replaced (i.e. / Composite would be CM_Copy).
+ // in the target are just replaced (i.e. / BlendMode would be BlendMode::Copy).
virtual void fill_rect(const Rect&, const RGBAColor&);
/// Draws a rect (frame only) to the surface.
=== renamed file 'src/graphic/texture.cc' => 'src/graphic/terrain_texture.cc'
--- src/graphic/texture.cc 2014-11-23 12:01:59 +0000
+++ src/graphic/terrain_texture.cc 2014-11-24 07:32:35 +0000
@@ -17,7 +17,7 @@
*
*/
-#include "graphic/texture.h"
+#include "graphic/terrain_texture.h"
#include <SDL_image.h>
@@ -25,6 +25,7 @@
#include "base/log.h"
#include "base/wexception.h"
#include "graphic/image_io.h"
+#include "graphic/texture.h"
#include "io/fileread.h"
#include "io/filesystem/layered_filesystem.h"
@@ -35,7 +36,7 @@
* Currently it converts a 16 bit image to a 8 bit texture. This should
* be changed to load a 8 bit file directly, however.
*/
-Texture::Texture(const std::vector<std::string>& texture_files, const uint32_t frametime)
+TerrainTexture::TerrainTexture(const std::vector<std::string>& texture_files, const uint32_t frametime)
: m_frame_num(0), m_frametime(frametime) {
if (texture_files.empty()) {
throw wexception("No images for texture.");
@@ -47,23 +48,23 @@
}
m_texture_image = fname;
- SDL_Surface* surf = load_image_as_sdl_surface(fname, g_fs);
- if (!surf) {
+ SDL_Surface* sdl_surface = load_image_as_sdl_surface(fname, g_fs);
+ if (!sdl_surface) {
throw wexception(
"WARNING: Failed to load texture frame %s: %s\n", fname.c_str(), IMG_GetError());
}
- if (surf->w != TEXTURE_WIDTH || surf->h != TEXTURE_HEIGHT) {
- SDL_FreeSurface(surf);
+ if (sdl_surface->w != kTextureWidth || sdl_surface->h != kTextureHeight) {
+ SDL_FreeSurface(sdl_surface);
throw wexception("WARNING: %s: texture must be %ix%i pixels big\n",
fname.c_str(),
- TEXTURE_WIDTH,
- TEXTURE_HEIGHT);
+ kTextureWidth,
+ kTextureHeight);
}
// calculate shades on the first frame
- if (m_gl_textures.empty()) {
- uint8_t top_left_pixel = static_cast<uint8_t*>(surf->pixels)[0];
- SDL_Color top_left_pixel_color = surf->format->palette->colors[top_left_pixel];
+ if (m_textures.empty()) {
+ uint8_t top_left_pixel = static_cast<uint8_t*>(sdl_surface->pixels)[0];
+ SDL_Color top_left_pixel_color = sdl_surface->format->palette->colors[top_left_pixel];
for (int i = -128; i < 128; i++) {
const int shade = 128 + i;
int32_t r = std::min<int32_t>((top_left_pixel_color.r * shade) >> 7, 255);
@@ -72,24 +73,26 @@
m_minimap_colors[shade] = RGBColor(r, g, b);
}
}
- m_gl_textures.emplace_back(new GLSurfaceTexture(surf));
+ m_textures.emplace_back(new Texture(sdl_surface));
}
- if (m_gl_textures.empty())
- throw wexception("Texture has no frames");
+ if (m_textures.empty())
+ throw wexception("TerrainTexture has no frames");
}
-/**
- * Return the basic terrain colour to be used in the minimap.
-*/
-RGBColor Texture::get_minimap_color(int8_t shade) {
+RGBColor TerrainTexture::get_minimap_color(int8_t shade) {
return m_minimap_colors[128 + shade];
}
-/**
- * Set the current frame according to the game time.
- */
-void Texture::animate(uint32_t time)
+void TerrainTexture::animate(uint32_t time)
{
- m_frame_num = (time / m_frametime) % m_gl_textures.size();
+ m_frame_num = (time / m_frametime) % m_textures.size();
+}
+
+const std::string& TerrainTexture::get_texture_image() const {
+ return m_texture_image;
+}
+
+const Texture& TerrainTexture::texture() const {
+ return *m_textures.at(m_frame_num);
}
=== renamed file 'src/graphic/texture.h' => 'src/graphic/terrain_texture.h'
--- src/graphic/texture.h 2014-11-22 21:31:21 +0000
+++ src/graphic/terrain_texture.h 2014-11-24 07:32:35 +0000
@@ -17,8 +17,8 @@
*
*/
-#ifndef WL_GRAPHIC_TEXTURE_H
-#define WL_GRAPHIC_TEXTURE_H
+#ifndef WL_GRAPHIC_TERRAIN_TEXTURE_H
+#define WL_GRAPHIC_TERRAIN_TEXTURE_H
#include <memory>
#include <string>
@@ -27,35 +27,28 @@
#include <stdint.h>
#include "graphic/colormap.h"
-#include "graphic/gl/surface_texture.h"
-
-/// Textures have a fixed size and are squares.
-/// TEXTURE_HEIGHT is just defined for easier understanding of the code.
-#define TEXTURE_WIDTH 64
-#define TEXTURE_HEIGHT TEXTURE_WIDTH
-
-/** struct Texture
-*
-* Texture represents are terrain texture, which is strictly
-* TEXTURE_WIDTH by TEXTURE_HEIGHT pixels in size. It uses 8 bit color, and
-* a pointer to the corresponding palette and color lookup table is
-* provided.
-*
-* Currently, this is initialized from a 16 bit bitmap. This should be
-* changed to load 8 bit bitmaps directly.
-*/
-struct Texture {
- Texture(const std::vector<std::string>& texture_files, uint32_t frametime);
-
- const std::string& get_texture_image() const {
- return m_texture_image;
- }
- uint32_t get_texture() const {
- return m_gl_textures.at(m_frame_num)->get_gl_texture();
- }
-
+
+class Texture;
+
+/// TerrainTextures have a fixed size and are squares.
+constexpr int kTextureWidth = 64;
+constexpr int kTextureHeight = kTextureWidth;
+
+// TerrainTexture represents are terrain texture, which is strictly kTextureWidth by
+// kTextureHeight pixels in size.
+struct TerrainTexture {
+ TerrainTexture(const std::vector<std::string>& texture_files, uint32_t frametime);
+
+ // Returns the path to a representative image for this texture.
+ const std::string& get_texture_image() const;
+
+ // Returns the texture for the current animation phase.
+ const Texture& texture() const;
+
+ // Return the basic terrain colour to be used in the minimap.
RGBColor get_minimap_color(int8_t shade);
+ // Set the current frame according to the game time.
void animate(uint32_t time);
private:
@@ -63,7 +56,7 @@
int32_t m_frame_num;
std::string m_texture_image;
uint32_t m_frametime;
- std::vector<std::unique_ptr<GLSurfaceTexture>> m_gl_textures;
+ std::vector<std::unique_ptr<Texture>> m_textures;
};
-#endif // end of include guard: WL_GRAPHIC_TEXTURE_H
+#endif // end of include guard: WL_GRAPHIC_TERRAIN_TEXTURE_H
=== modified file 'src/graphic/text/rt_render.cc'
--- src/graphic/text/rt_render.cc 2014-11-02 14:11:52 +0000
+++ src/graphic/text/rt_render.cc 2014-11-24 07:32:35 +0000
@@ -32,10 +32,10 @@
#include "base/rect.h"
#include "graphic/image_cache.h"
#include "graphic/image_io.h"
-#include "graphic/surface.h"
#include "graphic/text/font_io.h"
#include "graphic/text/rt_parse.h"
#include "graphic/text/textstream.h"
+#include "graphic/texture.h"
using namespace std;
@@ -108,7 +108,7 @@
virtual uint16_t width() = 0;
virtual uint16_t height() = 0;
virtual uint16_t hotspot_y() = 0;
- virtual Surface* render(SurfaceCache* surface_cache) = 0;
+ virtual Texture* render(TextureCache* texture_cache) = 0;
virtual bool is_non_mandatory_space() {return false;}
virtual bool is_expanding() {return false;}
@@ -313,7 +313,7 @@
return rv;
}
- Surface* render(SurfaceCache* surface_cache) override;
+ Texture* render(TextureCache* texture_cache) override;
protected:
uint16_t m_w, m_h;
@@ -330,10 +330,10 @@
uint16_t TextNode::hotspot_y() {
return m_font.ascent(m_s.font_style);
}
-Surface* TextNode::render(SurfaceCache* surface_cache) {
- const Surface& img = m_font.render(m_txt, m_s.font_color, m_s.font_style, surface_cache);
- Surface* rv = Surface::create(img.width(), img.height());
- rv->blit(Point(0, 0), &img, Rect(0, 0, img.width(), img.height()), CM_Copy);
+Texture* TextNode::render(TextureCache* texture_cache) {
+ const Texture& img = m_font.render(m_txt, m_s.font_color, m_s.font_style, texture_cache);
+ Texture* rv = new Texture(img.width(), img.height());
+ rv->blit(Point(0, 0), &img, Rect(0, 0, img.width(), img.height()), BlendMode::Copy);
return rv;
}
@@ -348,7 +348,7 @@
m_w = w;
}
virtual ~FillingTextNode() {}
- Surface* render(SurfaceCache*) override;
+ Texture* render(TextureCache*) override;
bool is_expanding() override {return m_expanding;}
void set_w(uint16_t w) override {m_w = w;}
@@ -356,12 +356,12 @@
private:
bool m_expanding;
};
-Surface* FillingTextNode::render(SurfaceCache* surface_cache) {
- const Surface& t = m_font.render(m_txt, m_s.font_color, m_s.font_style, surface_cache);
- Surface* rv = Surface::create(m_w, m_h);
+Texture* FillingTextNode::render(TextureCache* texture_cache) {
+ const Texture& t = m_font.render(m_txt, m_s.font_color, m_s.font_style, texture_cache);
+ Texture* rv = new Texture(m_w, m_h);
for (uint16_t curx = 0; curx < m_w; curx += t.width()) {
Rect srcrect(Point(0, 0), min<int>(t.width(), m_w - curx), m_h);
- rv->blit(Point(curx, 0), &t, srcrect, CM_Copy);
+ rv->blit(Point(curx, 0), &t, srcrect, BlendMode::Copy);
}
return rv;
}
@@ -375,13 +375,13 @@
WordSpacerNode(IFont& font, NodeStyle& ns) : TextNode(font, ns, " ") {}
static void show_spaces(bool t) {m_show_spaces = t;}
- Surface* render(SurfaceCache* surface_cache) override {
+ Texture* render(TextureCache* texture_cache) override {
if (m_show_spaces) {
- Surface* rv = Surface::create(m_w, m_h);
+ Texture* rv = new Texture(m_w, m_h);
rv->fill_rect(Rect(0, 0, m_w, m_h), RGBAColor(0xff, 0, 0, 0xff));
return rv;
}
- return TextNode::render(surface_cache);
+ return TextNode::render(texture_cache);
}
bool is_non_mandatory_space() override {return true;}
@@ -400,7 +400,7 @@
uint16_t height() override {return 0;}
uint16_t width() override {return INFINITE_WIDTH; }
uint16_t hotspot_y() override {return 0;}
- Surface* render(SurfaceCache* /* surface_cache */) override {
+ Texture* render(TextureCache* /* texture_cache */) override {
assert(false);
throw RenderError("This should never be called. This is a bug, please submit a report.");
}
@@ -418,8 +418,8 @@
uint16_t height() override {return m_h;}
uint16_t width() override {return m_w;}
uint16_t hotspot_y() override {return m_h;}
- Surface* render(SurfaceCache* /* surface_cache */) override {
- Surface* rv = Surface::create(m_w, m_h);
+ Texture* render(TextureCache* /* texture_cache */) override {
+ Texture* rv = new Texture(m_w, m_h);
// Draw background image (tiling)
if (m_bg) {
@@ -430,7 +430,7 @@
dst.y = 0;
srcrect.w = min<int>(m_bg->width(), m_w - curx);
srcrect.h = m_h;
- rv->blit(dst, m_bg->surface(), srcrect, CM_Copy);
+ rv->blit(dst, m_bg->texture(), srcrect, BlendMode::Copy);
}
} else {
rv->fill_rect(Rect(0, 0, m_w, m_h), RGBAColor(255, 255, 255, 0));
@@ -468,8 +468,8 @@
uint16_t width() override {return m_w + m_margin.left + m_margin.right;}
uint16_t height() override {return m_h + m_margin.top + m_margin.bottom;}
uint16_t hotspot_y() override {return height();}
- Surface* render(SurfaceCache* surface_cache) override {
- Surface* rv = Surface::create(width(), height());
+ Texture* render(TextureCache* texture_cache) override {
+ Texture* rv = new Texture(width(), height());
rv->fill_rect(Rect(0, 0, rv->width(), rv->height()), RGBAColor(255, 255, 255, 0));
// Draw Solid background Color
@@ -490,20 +490,20 @@
dst.x = curx; dst.y = cury;
src.w = min<int>(m_bg_img->width(), m_w + m_margin.left - curx);
src.h = min<int>(m_bg_img->height(), m_h + m_margin.top - cury);
- rv->blit(dst, m_bg_img->surface(), src, CM_Copy);
+ rv->blit(dst, m_bg_img->texture(), src, BlendMode::Copy);
}
}
set_alpha = false;
}
for (RenderNode* n : m_nodes_to_render) {
- Surface* nsur = n->render(surface_cache);
- if (nsur) {
+ Texture* node_texture = n->render(texture_cache);
+ if (node_texture) {
Point dst = Point(n->x() + m_margin.left, n->y() + m_margin.top);
- Rect src = Rect(0, 0, nsur->width(), nsur->height());
+ Rect src = Rect(0, 0, node_texture->width(), node_texture->height());
- rv->blit(dst, nsur, src, set_alpha ? CM_Copy : CM_UseAlpha);
- delete nsur;
+ rv->blit(dst, node_texture, src, set_alpha ? BlendMode::Copy : BlendMode::UseAlpha);
+ delete node_texture;
}
delete n;
}
@@ -545,15 +545,15 @@
uint16_t width() override {return m_image.width();}
uint16_t height() override {return m_image.height();}
uint16_t hotspot_y() override {return m_image.height();}
- Surface* render(SurfaceCache* surface_cache) override;
+ Texture* render(TextureCache* texture_cache) override;
private:
const Image& m_image;
};
-Surface* ImgRenderNode::render(SurfaceCache* /* surface_cache */) {
- Surface* rv = Surface::create(m_image.width(), m_image.height());
- rv->blit(Point(0, 0), m_image.surface(), Rect(0, 0, m_image.width(), m_image.height()), CM_Copy);
+Texture* ImgRenderNode::render(TextureCache* /* texture_cache */) {
+ Texture* rv = new Texture(m_image.width(), m_image.height());
+ rv->blit(Point(0, 0), m_image.texture(), Rect(0, 0, m_image.width(), m_image.height()), BlendMode::Copy);
return rv;
}
// End: Helper Stuff
@@ -946,9 +946,9 @@
return i->second(tag, fc, ns, image_cache);
}
-Renderer::Renderer(ImageCache* image_cache, SurfaceCache* surface_cache) :
+Renderer::Renderer(ImageCache* image_cache, TextureCache* texture_cache) :
font_cache_(new FontCache()), parser_(new Parser()),
- image_cache_(image_cache), surface_cache_(surface_cache) {
+ image_cache_(image_cache), texture_cache_(texture_cache) {
}
Renderer::~Renderer() {
@@ -976,10 +976,10 @@
return nodes[0];
}
-Surface* Renderer::render(const string& text, uint16_t width, const TagSet& allowed_tags) {
+Texture* Renderer::render(const string& text, uint16_t width, const TagSet& allowed_tags) {
std::unique_ptr<RenderNode> node(layout_(text, width, allowed_tags));
- return node->render(surface_cache_);
+ return node->render(texture_cache_);
}
IRefMap* Renderer::make_reference_map(const string& text, uint16_t width, const TagSet& allowed_tags) {
=== modified file 'src/graphic/text/rt_render.h'
--- src/graphic/text/rt_render.h 2014-09-14 11:31:58 +0000
+++ src/graphic/text/rt_render.h 2014-11-24 07:32:35 +0000
@@ -29,8 +29,9 @@
#include "graphic/color.h"
#include "graphic/image.h"
-class SurfaceCache;
+class Texture;
class ImageCache;
+class TextureCache;
namespace RT {
@@ -58,7 +59,7 @@
virtual ~IFont() {}
virtual void dimensions(const std::string&, int, uint16_t *, uint16_t *) = 0;
- virtual const Surface& render(const std::string&, const RGBColor& clr, int, SurfaceCache*) = 0;
+ virtual const Texture& render(const std::string&, const RGBColor& clr, int, TextureCache*) = 0;
virtual uint16_t ascent(int) const = 0;
};
@@ -81,13 +82,13 @@
class Renderer {
public:
// Ownership is not taken.
- Renderer(ImageCache* image_cache, SurfaceCache* surface_cache);
+ Renderer(ImageCache* image_cache, TextureCache* texture_cache);
~Renderer();
// Render the given string in the given width. Restricts the allowed tags to
- // the ones in TagSet. The renderer does not do caching in the SurfaceCache
+ // the ones in TagSet. The renderer does not do caching in the TextureCache
// for its individual nodes, but the font render does.
- Surface* render(const std::string&, uint16_t width, const TagSet& tagset = TagSet());
+ Texture* render(const std::string&, uint16_t width, const TagSet& tagset = TagSet());
// Returns a reference map of the clickable hyperlinks in the image. This
// will do no caching and needs to do all layouting, so do not call this too
@@ -100,7 +101,7 @@
std::unique_ptr<FontCache> font_cache_;
std::unique_ptr<Parser> parser_;
ImageCache* const image_cache_; // Not owned.
- SurfaceCache* const surface_cache_; // Not owned.
+ TextureCache* const texture_cache_; // Not owned.
};
}
=== modified file 'src/graphic/text/sdl_ttf_font.cc'
--- src/graphic/text/sdl_ttf_font.cc 2014-11-23 10:13:14 +0000
+++ src/graphic/text/sdl_ttf_font.cc 2014-11-24 07:32:35 +0000
@@ -24,9 +24,9 @@
#include <boost/format.hpp>
#include "graphic/sdl_utils.h"
-#include "graphic/surface.h"
-#include "graphic/surface_cache.h"
#include "graphic/text/rt_errors.h"
+#include "graphic/texture.h"
+#include "graphic/texture_cache.h"
using namespace std;
using namespace boost;
@@ -58,13 +58,13 @@
*gw = w; *gh = h;
}
-const Surface& SdlTtfFont::render
- (const string& txt, const RGBColor& clr, int style, SurfaceCache* surface_cache) {
+const Texture& SdlTtfFont::render
+ (const string& txt, const RGBColor& clr, int style, TextureCache* texture_cache) {
const string hash =
(boost::format("%s:%s:%i:%02x%02x%02x:%i") % font_name_ % ptsize_ % txt %
static_cast<int>(clr.r) % static_cast<int>(clr.g) % static_cast<int>(clr.b) % style)
.str();
- const Surface* rv = surface_cache->get(hash);
+ const Texture* rv = texture_cache->get(hash);
if (rv) return *rv;
m_set_style(style);
@@ -120,7 +120,7 @@
if (!text_surface)
throw RenderError((format("Rendering '%s' gave the error: %s") % txt % TTF_GetError()).str());
- return *surface_cache->insert(hash, Surface::create(text_surface), true);
+ return *texture_cache->insert(hash, new Texture(text_surface), true);
}
uint16_t SdlTtfFont::ascent(int style) const {
=== modified file 'src/graphic/text/sdl_ttf_font.h'
--- src/graphic/text/sdl_ttf_font.h 2014-09-10 16:57:31 +0000
+++ src/graphic/text/sdl_ttf_font.h 2014-11-24 07:32:35 +0000
@@ -37,7 +37,7 @@
virtual ~SdlTtfFont();
void dimensions(const std::string&, int, uint16_t * w, uint16_t * h) override;
- const Surface& render(const std::string&, const RGBColor& clr, int, SurfaceCache*) override;
+ const Texture& render(const std::string&, const RGBColor& clr, int, TextureCache*) override;
uint16_t ascent(int) const override;
private:
=== modified file 'src/graphic/text/test/render.cc'
--- src/graphic/text/test/render.cc 2014-09-20 09:37:47 +0000
+++ src/graphic/text/test/render.cc 2014-11-24 07:32:35 +0000
@@ -25,9 +25,9 @@
#include <string>
#include "graphic/image_cache.h"
-#include "graphic/surface_cache.h"
#include "graphic/text/rt_render.h"
#include "graphic/text/test/paths.h"
+#include "graphic/texture_cache.h"
#include "io/filesystem/layered_filesystem.h"
StandaloneRenderer::StandaloneRenderer() {
@@ -35,9 +35,9 @@
g_fs->add_file_system(&FileSystem::create(WIDELANDS_DATA_DIR));
g_fs->add_file_system(&FileSystem::create(RICHTEXT_DATA_DIR));
- surface_cache_.reset(create_surface_cache(500 << 20)); // 500 MB
- image_cache_.reset(new ImageCache(surface_cache_.get()));
- renderer_.reset(new RT::Renderer(image_cache_.get(), surface_cache_.get()));
+ texture_cache_.reset(create_texture_cache(500 << 20)); // 500 MB
+ image_cache_.reset(new ImageCache(texture_cache_.get()));
+ renderer_.reset(new RT::Renderer(image_cache_.get(), texture_cache_.get()));
}
StandaloneRenderer::~StandaloneRenderer() {
=== modified file 'src/graphic/text/test/render.h'
--- src/graphic/text/test/render.h 2014-07-14 10:45:44 +0000
+++ src/graphic/text/test/render.h 2014-11-24 07:32:35 +0000
@@ -36,7 +36,7 @@
RT::Renderer* renderer();
private:
- std::unique_ptr<SurfaceCache> surface_cache_;
+ std::unique_ptr<TextureCache> texture_cache_;
std::unique_ptr<ImageCache> image_cache_;
std::unique_ptr<RT::Renderer> renderer_;
};
=== modified file 'src/graphic/text/test/render_richtext.cc'
--- src/graphic/text/test/render_richtext.cc 2014-11-24 07:32:34 +0000
+++ src/graphic/text/test/render_richtext.cc 2014-11-24 07:32:35 +0000
@@ -33,9 +33,9 @@
#include "config.h"
#include "graphic/graphic.h"
#include "graphic/image_io.h"
-#include "graphic/surface.h"
#include "graphic/text/rt_errors.h"
#include "graphic/text/test/render.h"
+#include "graphic/texture.h"
#include "io/filesystem/filesystem.h"
#include "io/filesystem/layered_filesystem.h"
#include "io/streamwrite.h"
@@ -135,11 +135,12 @@
StandaloneRenderer standalone_renderer;
try {
- std::unique_ptr<Surface> surf(standalone_renderer.renderer()->render(txt, w, allowed_tags));
+ std::unique_ptr<Texture> texture(
+ standalone_renderer.renderer()->render(txt, w, allowed_tags));
std::unique_ptr<FileSystem> fs(&FileSystem::create("."));
std::unique_ptr<StreamWrite> sw(fs->open_stream_write(outname));
- if (!save_surface_to_png(surf.get(), sw.get())) {
+ if (!save_surface_to_png(texture.get(), sw.get())) {
std::cout << "Could not encode PNG." << std::endl;
}
} catch (RT::Exception& e) {
=== renamed file 'src/graphic/gl/surface_texture.cc' => 'src/graphic/texture.cc'
--- src/graphic/gl/surface_texture.cc 2014-11-23 10:13:14 +0000
+++ src/graphic/texture.cc 2014-11-24 07:32:35 +0000
@@ -16,7 +16,7 @@
* Foundation, Inc., 51 Franklin Street, Fifth Floor, Boston, MA 02110-1301, USA.
*/
-#include "graphic/gl/surface_texture.h"
+#include "graphic/texture.h"
#include <cassert>
@@ -77,7 +77,7 @@
*
* The initial data of the texture is undefined.
*/
-GLSurfaceTexture::GLSurfaceTexture(int w, int h)
+Texture::Texture(int w, int h)
{
init(w, h);
@@ -94,7 +94,7 @@
*
* \note Takes ownership of the given surface.
*/
-GLSurfaceTexture::GLSurfaceTexture(SDL_Surface * surface, bool intensity)
+Texture::Texture(SDL_Surface * surface, bool intensity)
{
init(surface->w, surface->h);
@@ -132,17 +132,17 @@
SDL_FreeSurface(surface);
}
-GLSurfaceTexture::~GLSurfaceTexture()
+Texture::~Texture()
{
glDeleteTextures(1, &m_texture);
}
-void GLSurfaceTexture::pixel_to_gl(float* x, float* y) const {
+void Texture::pixel_to_gl(float* x, float* y) const {
*x = (*x / m_w) * 2. - 1.;
*y = (*y / m_h) * 2. - 1.;
}
-void GLSurfaceTexture::init(uint16_t w, uint16_t h)
+void Texture::init(uint16_t w, uint16_t h)
{
m_w = w;
m_h = h;
@@ -160,7 +160,7 @@
glTexParameteri(GL_TEXTURE_2D, GL_TEXTURE_MAG_FILTER, GL_LINEAR);
}
-void GLSurfaceTexture::lock(LockMode mode) {
+void Texture::lock(LockMode mode) {
if (m_w <= 0 || m_h <= 0) {
return;
}
@@ -174,7 +174,7 @@
}
}
-void GLSurfaceTexture::unlock(UnlockMode mode) {
+void Texture::unlock(UnlockMode mode) {
if (m_w <= 0 || m_h <= 0) {
return;
}
@@ -190,7 +190,7 @@
m_pixels.reset(nullptr);
}
-void GLSurfaceTexture::draw_rect(const Rect& rectangle, const RGBColor& clr)
+void Texture::draw_rect(const Rect& rectangle, const RGBColor& clr)
{
if (m_w <= 0 || m_h <= 0) {
return;
@@ -204,7 +204,7 @@
/**
* Draws a filled rectangle
*/
-void GLSurfaceTexture::fill_rect(const Rect& rectangle, const RGBAColor& clr)
+void Texture::fill_rect(const Rect& rectangle, const RGBAColor& clr)
{
if (m_w <= 0 || m_h <= 0) {
return;
@@ -218,7 +218,7 @@
/**
* Change the brightness of the given rectangle
*/
-void GLSurfaceTexture::brighten_rect(const Rect& rectangle, const int32_t factor)
+void Texture::brighten_rect(const Rect& rectangle, const int32_t factor)
{
if (m_w <= 0 || m_h <= 0) {
return;
@@ -229,7 +229,7 @@
reset_gl();
}
-void GLSurfaceTexture::draw_line
+void Texture::draw_line
(int32_t x1, int32_t y1, int32_t x2, int32_t y2, const RGBColor& color, uint8_t gwidth)
{
if (m_w <= 0 || m_h <= 0) {
@@ -241,14 +241,14 @@
reset_gl();
}
-void GLSurfaceTexture::blit
- (const Point& dst, const Surface* src, const Rect& srcrc, Composite cm)
+void Texture::blit
+ (const Point& dst, const Texture* src, const Rect& srcrc, BlendMode blend_mode)
{
if (m_w <= 0 || m_h <= 0) {
return;
}
setup_gl(m_texture);
- Surface::blit(dst, src, srcrc, cm);
+ Surface::blit(dst, src, srcrc, blend_mode);
reset_gl();
}
=== renamed file 'src/graphic/gl/surface_texture.h' => 'src/graphic/texture.h'
--- src/graphic/gl/surface_texture.h 2014-11-22 21:31:21 +0000
+++ src/graphic/texture.h 2014-11-24 07:32:35 +0000
@@ -16,20 +16,25 @@
* Foundation, Inc., 51 Franklin Street, Fifth Floor, Boston, MA 02110-1301, USA.
*/
-#ifndef WL_GRAPHIC_GL_SURFACE_TEXTURE_H
-#define WL_GRAPHIC_GL_SURFACE_TEXTURE_H
+#ifndef WL_GRAPHIC_TEXTURE_H
+#define WL_GRAPHIC_TEXTURE_H
#include "graphic/gl/system_headers.h"
#include "graphic/surface.h"
struct SDL_Surface;
-class GLSurfaceTexture : public Surface {
+class Texture : public Surface {
public:
- GLSurfaceTexture(SDL_Surface * surface, bool intensity = false);
- GLSurfaceTexture(int w, int h);
-
- virtual ~GLSurfaceTexture();
+ // Create a new surface from an SDL_Surface. If intensity is true, an GL_INTENSITY texture
+ // is created. Ownership is taken.
+ Texture(SDL_Surface * surface, bool intensity = false);
+
+ // Create a new empty (that is randomly filled) Surface with the given
+ // dimensions.
+ Texture(int w, int h);
+
+ virtual ~Texture();
/// Interface implementation
//@{
@@ -48,7 +53,10 @@
void brighten_rect(const Rect&, int32_t factor) override;
virtual void draw_line
(int32_t x1, int32_t y1, int32_t x2, int32_t y2, const RGBColor&, uint8_t width) override;
- void blit(const Point&, const Surface*, const Rect& srcrc, Composite cm) override;
+ void blit(const Point&,
+ const Texture*,
+ const Rect& srcrc,
+ BlendMode blend_mode = BlendMode::UseAlpha) override;
GLuint get_gl_texture() const {return m_texture;}
@@ -59,4 +67,4 @@
GLuint m_texture;
};
-#endif // end of include guard: WL_GRAPHIC_GL_SURFACE_TEXTURE_H
+#endif // end of include guard: WL_GRAPHIC_TEXTURE_H
=== renamed file 'src/graphic/surface_cache.cc' => 'src/graphic/texture_cache.cc'
--- src/graphic/surface_cache.cc 2014-09-14 11:31:58 +0000
+++ src/graphic/texture_cache.cc 2014-11-24 07:32:35 +0000
@@ -17,7 +17,7 @@
*
*/
-#include "graphic/surface_cache.h"
+#include "graphic/texture_cache.h"
#include <cassert>
#include <list>
@@ -26,33 +26,33 @@
#include <SDL.h>
-#include "graphic/surface.h"
+#include "graphic/texture.h"
using namespace std;
// I took inspiration from http://timday.bitbucket.org/lru.html, but our use
// case here is a little different.
namespace {
-class SurfaceCacheImpl : public SurfaceCache {
+class TextureCacheImpl : public TextureCache {
public:
- SurfaceCacheImpl(uint32_t max_transient_memory) :
+ TextureCacheImpl(uint32_t max_transient_memory) :
max_transient_memory_(max_transient_memory), used_transient_memory_(0) {}
- virtual ~SurfaceCacheImpl();
+ virtual ~TextureCacheImpl();
- // Implements SurfaceCache.
+ // Implements TextureCache.
void flush() override;
- Surface* get(const string& hash) override;
- Surface* insert(const string& hash, Surface*, bool) override;
+ Texture* get(const string& hash) override;
+ Texture* insert(const string& hash, Texture*, bool) override;
private:
void drop();
using AccessHistory = list<string>;
struct Entry {
- Entry(Surface* gs, const AccessHistory::iterator& it, bool transient) :
- surface(gs), is_transient(transient), last_access(SDL_GetTicks()), list_iterator(it) {}
+ Entry(Texture* gs, const AccessHistory::iterator& it, bool transient) :
+ texture(gs), is_transient(transient), last_access(SDL_GetTicks()), list_iterator(it) {}
- std::unique_ptr<Surface> surface;
+ std::unique_ptr<Texture> texture;
bool is_transient;
uint32_t last_access; // Mainly for debugging and analysis.
const AccessHistory::iterator list_iterator; // Only valid if is_transient is true.
@@ -65,11 +65,11 @@
AccessHistory access_history_;
};
-SurfaceCacheImpl::~SurfaceCacheImpl() {
+TextureCacheImpl::~TextureCacheImpl() {
flush();
}
-void SurfaceCacheImpl::flush() {
+void TextureCacheImpl::flush() {
for (Container::iterator it = entries_.begin(); it != entries_.end(); ++it) {
delete it->second;
}
@@ -78,7 +78,7 @@
used_transient_memory_ = 0;
}
-Surface* SurfaceCacheImpl::get(const string& hash) {
+Texture* TextureCacheImpl::get(const string& hash) {
const Container::iterator it = entries_.find(hash);
if (it == entries_.end())
return nullptr;
@@ -89,30 +89,29 @@
access_history_.splice(access_history_.end(), access_history_, it->second->list_iterator);
it->second->last_access = SDL_GetTicks();
}
- return it->second->surface.get();
+ return it->second->texture.get();
}
-Surface* SurfaceCacheImpl::insert(const string& hash, Surface* surf, bool transient) {
+Texture* TextureCacheImpl::insert(const string& hash, Texture* texture, bool transient) {
assert(entries_.find(hash) == entries_.end());
if (transient) {
- const uint32_t surface_size = surf->width() * surf->height() * 4;
- while (used_transient_memory_ + surface_size > max_transient_memory_) {
+ const uint32_t texture_size = texture->width() * texture->height() * 4;
+ while (used_transient_memory_ + texture_size > max_transient_memory_) {
drop();
}
// Record hash as most-recently-used.
AccessHistory::iterator it = access_history_.insert(access_history_.end(), hash);
- used_transient_memory_ += surface_size;
- entries_.insert(make_pair(hash, new Entry(surf, it, true)));
+ used_transient_memory_ += texture_size;
+ entries_.insert(make_pair(hash, new Entry(texture, it, true)));
} else {
- entries_.insert(make_pair(hash, new Entry(surf, access_history_.end(), false)));
+ entries_.insert(make_pair(hash, new Entry(texture, access_history_.end(), false)));
}
-
- return surf;
+ return texture;
}
-void SurfaceCacheImpl::drop() {
+void TextureCacheImpl::drop() {
assert(!access_history_.empty());
// Identify least recently used key
@@ -120,8 +119,8 @@
assert(it != entries_.end());
assert(it->second->is_transient);
- const uint32_t surface_size = it->second->surface->width() * it->second->surface->height() * 4;
- used_transient_memory_ -= surface_size;
+ const uint32_t texture_size = it->second->texture->width() * it->second->texture->height() * 4;
+ used_transient_memory_ -= texture_size;
// Erase both elements to completely purge record
delete it->second;
@@ -131,6 +130,6 @@
} // namespace
-SurfaceCache* create_surface_cache(uint32_t transient_memory_in_bytes) {
- return new SurfaceCacheImpl(transient_memory_in_bytes);
+TextureCache* create_texture_cache(uint32_t transient_memory_in_bytes) {
+ return new TextureCacheImpl(transient_memory_in_bytes);
}
=== renamed file 'src/graphic/surface_cache.h' => 'src/graphic/texture_cache.h'
--- src/graphic/surface_cache.h 2014-07-14 19:48:07 +0000
+++ src/graphic/texture_cache.h 2014-11-24 07:32:35 +0000
@@ -17,8 +17,8 @@
*
*/
-#ifndef WL_GRAPHIC_SURFACE_CACHE_H
-#define WL_GRAPHIC_SURFACE_CACHE_H
+#ifndef WL_GRAPHIC_TEXTURE_CACHE_H
+#define WL_GRAPHIC_TEXTURE_CACHE_H
#include <string>
@@ -26,7 +26,7 @@
#include "base/macros.h"
-class Surface;
+class Texture;
// Caches Surfaces. It contains surfaces which must not be deleted and
// transient surfaces that are always free to be deleted - somebody else must
@@ -35,32 +35,32 @@
// Nobody in Widelands should hold onto a Surface they get from this class,
// instead, they should use it only temporarily and rerequest it whenever they
// need it.
-class SurfaceCache {
+class TextureCache {
public:
- SurfaceCache() {}
- virtual ~SurfaceCache() {}
+ TextureCache() {}
+ virtual ~TextureCache() {}
/// Deletes all surfaces in the cache leaving it as if it were just created.
virtual void flush() = 0;
/// Returns an entry if it is cached, nullptr otherwise.
- virtual Surface* get(const std::string& hash) = 0;
+ virtual Texture* get(const std::string& hash) = 0;
- // Inserts this entry into the SurfaceCache. asserts() that there is no
+ // Inserts this entry into the TextureCache. asserts() that there is no
// entry with this hash already cached. Returns the given Surface for
// convenience. If 'transient' is false, this surface will not be deleted
// automatically - use this if surfaces are around for a long time and
// recreation is expensive (i.e. images loaded from disk).
- virtual Surface* insert(const std::string& hash, Surface*, bool transient) = 0;
+ virtual Texture* insert(const std::string& hash, Texture*, bool transient) = 0;
private:
- DISALLOW_COPY_AND_ASSIGN(SurfaceCache);
+ DISALLOW_COPY_AND_ASSIGN(TextureCache);
};
// Create a new Cache whichs combined pixels in all transient surfaces are
// always below the given limit (Note: there is overhead for class members
// which is not counted as the pixels make up the bulk of the size of a
// surface).
-SurfaceCache* create_surface_cache(uint32_t transient_memory_in_bytes);
+TextureCache* create_texture_cache(uint32_t transient_memory_in_bytes);
-#endif // end of include guard: WL_GRAPHIC_SURFACE_CACHE_H
+#endif // end of include guard: WL_GRAPHIC_TEXTURE_CACHE_H
=== modified file 'src/logic/building.cc'
--- src/logic/building.cc 2014-11-02 14:11:52 +0000
+++ src/logic/building.cc 2014-11-24 07:32:35 +0000
@@ -732,7 +732,7 @@
if (dpyflags & InteractiveBase::dfShowCensus) {
const std::string info = info_string(igbase.building_census_format());
if (!info.empty()) {
- dst.blit(pos - Point(0, 48), UI::g_fh1->render(info), CM_UseAlpha, UI::Align_Center);
+ dst.blit(pos - Point(0, 48), UI::g_fh1->render(info), BlendMode::UseAlpha, UI::Align_Center);
}
}
@@ -744,7 +744,7 @@
return;
const std::string info = info_string(igbase.building_statistics_format());
if (!info.empty()) {
- dst.blit(pos - Point(0, 35), UI::g_fh1->render(info), CM_UseAlpha, UI::Align_Center);
+ dst.blit(pos - Point(0, 35), UI::g_fh1->render(info), BlendMode::UseAlpha, UI::Align_Center);
}
}
}
=== modified file 'src/logic/immovable.cc'
--- src/logic/immovable.cc 2014-11-02 14:11:52 +0000
+++ src/logic/immovable.cc 2014-11-24 07:32:35 +0000
@@ -562,7 +562,7 @@
dst.drawanimrect
(pos, m_anim, current_frame * frametime, get_owner(), Rect(Point(0, curh - lines), curw, lines));
- // Additionnaly, if statistics are enabled, draw a progression string
+ // Additionally, if statistics are enabled, draw a progression string
if (game.get_ibase()->get_display_flags() & InteractiveBase::dfShowStatistics) {
unsigned int percent = (100 * done / total);
m_construct_string =
@@ -570,7 +570,10 @@
% UI_FONT_CLR_DARK_HEX % (boost::format(_("%i%% built")) % percent).str())
.str();
m_construct_string = as_uifont(m_construct_string);
- dst.blit(pos - Point(0, 48), UI::g_fh1->render(m_construct_string), CM_UseAlpha, UI::Align_Center);
+ dst.blit(pos - Point(0, 48),
+ UI::g_fh1->render(m_construct_string),
+ BlendMode::UseAlpha,
+ UI::Align_Center);
}
}
=== modified file 'src/logic/map_info.cc'
--- src/logic/map_info.cc 2014-11-24 07:32:34 +0000
+++ src/logic/map_info.cc 2014-11-24 07:32:35 +0000
@@ -29,7 +29,7 @@
#include "graphic/graphic.h"
#include "graphic/image_io.h"
#include "graphic/minimap_renderer.h"
-#include "graphic/surface.h"
+#include "graphic/texture.h"
#include "io/filesystem/filesystem.h"
#include "io/filesystem/layered_filesystem.h"
#include "io/filewrite.h"
@@ -87,7 +87,8 @@
ml->preload_map(true);
ml->load_map_complete(egbase, true);
- std::unique_ptr<Surface> minimap(draw_minimap(egbase, nullptr, Point(0, 0), MiniMapLayer::Terrain));
+ std::unique_ptr<Texture> minimap(
+ draw_minimap(egbase, nullptr, Point(0, 0), MiniMapLayer::Terrain));
// Write minimap
{
=== modified file 'src/map_io/map_extradata_packet.cc'
--- src/map_io/map_extradata_packet.cc 2014-09-20 09:37:47 +0000
+++ src/map_io/map_extradata_packet.cc 2014-11-24 07:32:35 +0000
@@ -23,7 +23,7 @@
#include "graphic/graphic.h"
#include "graphic/in_memory_image.h"
-#include "graphic/surface.h"
+#include "graphic/texture.h"
#include "io/fileread.h"
#include "io/filewrite.h"
#include "logic/editor_game_base.h"
@@ -67,7 +67,7 @@
IMG_Load_RW(SDL_RWFromMem(fr.data(0), fr.get_size()), 1);
if (!surf)
continue; // Illegal pic. Skip it.
- image = g_gr->images().insert(new_in_memory_image(hash, Surface::create(surf)));
+ image = g_gr->images().insert(new_in_memory_image(hash, new Texture(surf)));
} else {
image = g_gr->images().get(hash);
}
=== modified file 'src/map_io/map_saver.cc'
--- src/map_io/map_saver.cc 2014-11-22 15:27:45 +0000
+++ src/map_io/map_saver.cc 2014-11-24 07:32:35 +0000
@@ -26,7 +26,7 @@
#include "base/wexception.h"
#include "graphic/image_io.h"
#include "graphic/minimap_renderer.h"
-#include "graphic/surface.h"
+#include "graphic/texture.h"
#include "io/filesystem/filesystem.h"
#include "io/filewrite.h"
#include "logic/editor_game_base.h"
@@ -217,7 +217,7 @@
// Write minimap
{
- std::unique_ptr<Surface> minimap(
+ std::unique_ptr<Texture> minimap(
draw_minimap(m_egbase, nullptr, Point(0, 0), MiniMapLayer::Terrain));
FileWrite fw;
save_surface_to_png(minimap.get(), &fw);
=== modified file 'src/ui_basic/progressbar.cc'
--- src/ui_basic/progressbar.cc 2014-11-02 14:11:52 +0000
+++ src/ui_basic/progressbar.cc 2014-11-24 07:32:35 +0000
@@ -109,6 +109,6 @@
const std::string progress_text =
(boost::format("<font color=%1$s>%2$i%%</font>") % "ffffff" % percent).str();
const Point pos(get_w() / 2, get_h() / 2);
- dst.blit(pos, UI::g_fh1->render(as_uifont(progress_text)), CM_UseAlpha, Align_Center);
+ dst.blit(pos, UI::g_fh1->render(as_uifont(progress_text)), BlendMode::UseAlpha, Align_Center);
}
}
=== modified file 'src/ui_basic/window.cc'
--- src/ui_basic/window.cc 2014-11-22 11:51:38 +0000
+++ src/ui_basic/window.cc 2014-11-24 07:32:35 +0000
@@ -320,7 +320,7 @@
dst.blit
(Point(get_lborder() + get_inner_w() / 2, TP_B_PIXMAP_THICKNESS / 2),
UI::g_fh1->render(m_title),
- CM_UseAlpha,
+ BlendMode::UseAlpha,
Align_Center);
}
=== modified file 'src/ui_fsmenu/loadgame.cc'
--- src/ui_fsmenu/loadgame.cc 2014-11-22 10:18:20 +0000
+++ src/ui_fsmenu/loadgame.cc 2014-11-24 07:32:35 +0000
@@ -36,7 +36,7 @@
#include "graphic/image_io.h"
#include "graphic/image_transformations.h"
#include "graphic/in_memory_image.h"
-#include "graphic/surface.h"
+#include "graphic/texture.h"
#include "helper.h"
#include "io/filesystem/layered_filesystem.h"
#include "logic/game.h"
@@ -317,13 +317,13 @@
if (!minimap_path.empty()) {
try {
// Load the image
- std::unique_ptr<Surface> surface(
+ std::unique_ptr<Texture> texture(
load_image(
minimap_path,
std::unique_ptr<FileSystem>(g_fs->make_sub_file_system(gamedata.filename)).get()));
m_minimap_image.reset(new_in_memory_image(std::string(gamedata.filename + minimap_path),
- surface.release()));
+ texture.release()));
// Scale it
double scale = double(m_minimap_w) / m_minimap_image->width();
@@ -337,7 +337,7 @@
const Image* resized = ImageTransformations::resize(m_minimap_image.get(), w, h);
// keeps our in_memory_image around and give to icon the one
// from resize that is handled by the cache. It is still linked to our
- // surface
+ // texture.
m_minimap_icon.set_size(w, h);
// Center the minimap in the available space
=== modified file 'src/wui/buildingwindow.cc'
--- src/wui/buildingwindow.cc 2014-11-22 10:18:20 +0000
+++ src/wui/buildingwindow.cc 2014-11-24 07:32:35 +0000
@@ -119,7 +119,7 @@
const Image* dark_frame = ImageTransformations::change_luminosity
(&anim.representative_image(building().owner().get_playercolor()), 1.22, true);
- dst.blit(Point(get_inner_w() / 2, get_inner_h() / 2), dark_frame, CM_UseAlpha, UI::Align_Center);
+ dst.blit(Point(get_inner_w() / 2, get_inner_h() / 2), dark_frame, BlendMode::UseAlpha, UI::Align_Center);
}
/*
=== modified file 'src/wui/interactive_base.cc'
--- src/wui/interactive_base.cc 2014-11-24 07:32:34 +0000
+++ src/wui/interactive_base.cc 2014-11-24 07:32:35 +0000
@@ -410,7 +410,7 @@
if (get_display_flag(dfDebug) || !dynamic_cast<const Game*>(&egbase())) {
const std::string gametime(gametimestring(egbase().get_gametime()));
const std::string gametime_text = as_uifont(gametime, UI_FONT_SIZE_SMALL);
- dst.blit(Point(5, 5), UI::g_fh1->render(gametime_text), CM_UseAlpha, UI::Align_TopLeft);
+ dst.blit(Point(5, 5), UI::g_fh1->render(gametime_text), BlendMode::UseAlpha, UI::Align_TopLeft);
static boost::format node_format("(%i, %i)");
const std::string node_text = as_uifont
@@ -418,7 +418,7 @@
dst.blit(
Point(get_w() - 5, get_h() - 5),
UI::g_fh1->render(node_text),
- CM_UseAlpha,
+ BlendMode::UseAlpha,
UI::Align_BottomRight
);
}
@@ -430,7 +430,7 @@
((fps_format %
(1000.0 / m_frametime) % (1000.0 / (m_avg_usframetime / 1000)))
.str(), UI_FONT_SIZE_SMALL);
- dst.blit(Point(5, 25), UI::g_fh1->render(fps_text), CM_UseAlpha, UI::Align_Left);
+ dst.blit(Point(5, 25), UI::g_fh1->render(fps_text), BlendMode::UseAlpha, UI::Align_Left);
}
}
=== modified file 'src/wui/minimap.cc'
--- src/wui/minimap.cc 2014-11-22 11:32:06 +0000
+++ src/wui/minimap.cc 2014-11-24 07:32:35 +0000
@@ -26,7 +26,7 @@
#include "graphic/in_memory_image.h"
#include "graphic/minimap_renderer.h"
#include "graphic/rendertarget.h"
-#include "graphic/surface.h"
+#include "graphic/texture.h"
#include "logic/map.h"
#include "wui/interactive_player.h"
#include "wui/mapviewpixelconstants.h"
@@ -63,15 +63,15 @@
void MiniMap::View::draw(RenderTarget & dst)
{
- std::unique_ptr<Surface> surface(
+ std::unique_ptr<Texture> texture(
draw_minimap(m_ibase.egbase(),
m_ibase.get_player(),
(*m_flags) & (MiniMapLayer::Zoom2) ?
Point((m_viewx - get_w() / 4), (m_viewy - get_h() / 4)) :
Point((m_viewx - get_w() / 2), (m_viewy - get_h() / 2)),
*m_flags | MiniMapLayer::ViewWindow));
- // Give ownership of the surface to the new image
- std::unique_ptr<const Image> im(new_in_memory_image("minimap", surface.release()));
+ // Give ownership of the texture to the new image
+ std::unique_ptr<const Image> im(new_in_memory_image("minimap", texture.release()));
dst.blit(Point(), im.get());
im.reset();
}
=== modified file 'src/wui/plot_area.cc'
--- src/wui/plot_area.cc 2014-11-08 14:59:03 +0000
+++ src/wui/plot_area.cc 2014-11-24 07:32:35 +0000
@@ -142,7 +142,7 @@
*/
void draw_value(const string& value, const RGBColor& color, const Point& pos, RenderTarget & dst) {
const Image* pic = UI::g_fh1->render(ytick_text_style(value, color));
- dst.blit(pos, pic, CM_UseAlpha, UI::Align_CenterRight);
+ dst.blit(pos, pic, BlendMode::UseAlpha, UI::Align_CenterRight);
}
/**
@@ -223,7 +223,7 @@
(xtick_text_style((boost::format("-%u ") % (max_x / how_many_ticks * i)).str()));
dst.blit
(Point(static_cast<int32_t>(posx), inner_h - space_at_bottom + 10),
- xtick, CM_UseAlpha, UI::Align_Center);
+ xtick, BlendMode::UseAlpha, UI::Align_Center);
posx -= sub;
}
@@ -242,7 +242,7 @@
// print the used unit
const Image* xtick = UI::g_fh1->render(xtick_text_style(get_unit_name(unit)));
- dst.blit(Point(2, spacing + 2), xtick, CM_UseAlpha, UI::Align_CenterLeft);
+ dst.blit(Point(2, spacing + 2), xtick, BlendMode::UseAlpha, UI::Align_CenterLeft);
}
} // namespace
Follow ups