← Back to team overview

widelands-dev team mailing list archive

[Merge] lp:~widelands-dev/widelands/padding_in_atlas into lp:widelands

 

SirVer has proposed merging lp:~widelands-dev/widelands/padding_in_atlas into lp:widelands.

Commit message:
- Add 1 pixel padding in the texture atlas to avoid texture bleeding.
- Filter all textures linearly instead of near. This looks nicer and texture
  bleeding has been taken care off.

Requested reviews:
  Widelands Developers (widelands-dev)
Related bugs:
  Bug #1538709 in widelands: "small lines beside roads"
  https://bugs.launchpad.net/widelands/+bug/1538709

For more details, see:
https://code.launchpad.net/~widelands-dev/widelands/padding_in_atlas/+merge/284216

See commit.
-- 
Your team Widelands Developers is requested to review the proposed merge of lp:~widelands-dev/widelands/padding_in_atlas into lp:widelands.
=== modified file 'src/graphic/gl/dither_program.cc'
--- src/graphic/gl/dither_program.cc	2016-01-17 09:55:27 +0000
+++ src/graphic/gl/dither_program.cc	2016-01-28 06:43:38 +0000
@@ -105,7 +105,7 @@
 	glTexParameteri(GL_TEXTURE_2D, GL_TEXTURE_WRAP_S, static_cast<GLint>(GL_CLAMP_TO_EDGE));
 	glTexParameteri(GL_TEXTURE_2D, GL_TEXTURE_WRAP_T, static_cast<GLint>(GL_CLAMP_TO_EDGE));
 	glTexParameteri(GL_TEXTURE_2D, GL_TEXTURE_MIN_FILTER, static_cast<GLint>(GL_LINEAR));
-	glTexParameteri(GL_TEXTURE_2D, GL_TEXTURE_MAG_FILTER, static_cast<GLint>(GL_NEAREST));
+	glTexParameteri(GL_TEXTURE_2D, GL_TEXTURE_MAG_FILTER, static_cast<GLint>(GL_LINEAR));
 }
 
 DitherProgram::~DitherProgram() {}

=== modified file 'src/graphic/texture.cc'
--- src/graphic/texture.cc	2016-01-24 12:43:26 +0000
+++ src/graphic/texture.cc	2016-01-28 06:43:38 +0000
@@ -198,9 +198,9 @@
 
 	// set texture filter to use linear filtering. This looks nicer for resized
 	// texture. Most textures and images are not resized so the filtering
-	// makes no difference
+	// makes no difference.
 	glTexParameteri(GL_TEXTURE_2D, GL_TEXTURE_MIN_FILTER, static_cast<GLint>(GL_LINEAR));
-	glTexParameteri(GL_TEXTURE_2D, GL_TEXTURE_MAG_FILTER, static_cast<GLint>(GL_NEAREST));
+	glTexParameteri(GL_TEXTURE_2D, GL_TEXTURE_MAG_FILTER, static_cast<GLint>(GL_LINEAR));
 }
 
 void Texture::lock() {

=== modified file 'src/graphic/texture_atlas.cc'
--- src/graphic/texture_atlas.cc	2016-01-13 07:27:55 +0000
+++ src/graphic/texture_atlas.cc	2016-01-28 06:43:38 +0000
@@ -25,6 +25,15 @@
 
 #include "base/wexception.h"
 
+namespace  {
+
+// This padding will be applied to the left and bottom of each block to
+// separate them during blitting if OpenGL decides to be a jerk about where to
+// sample.
+constexpr int kPadding = 1;
+
+}  // namespace
+
 TextureAtlas::Node::Node(const Rect& init_r) : used(false), r(init_r) {
 }
 
@@ -72,7 +81,7 @@
                                                                 const int texture_atlas_index,
                                                                 std::vector<PackedTexture>* pack_info) {
 	std::unique_ptr<Node> root(
-	   new Node(Rect(0, 0, blocks_.begin()->texture->width(), blocks_.begin()->texture->height())));
+	   new Node(Rect(0, 0, blocks_.begin()->texture->width() + kPadding, blocks_.begin()->texture->height() + kPadding)));
 
 	const auto grow_right = [&root](int delta_w) {
 		std::unique_ptr<Node> new_root(new Node(Rect(0, 0, root->r.w + delta_w, root->r.h)));
@@ -92,8 +101,8 @@
 
 	std::vector<Block> packed, not_packed;
 	for (Block& block : blocks_) {
-		const int block_width = block.texture->width();
-		const int block_height = block.texture->height();
+		const int block_width = block.texture->width() + kPadding;
+		const int block_height = block.texture->height() + kPadding;
 
 		Node* fitting_node = find_node(root.get(), block_width, block_height);
 		if (fitting_node == nullptr) {


References