Skip to content
This repository has been archived by the owner on Aug 8, 2023. It is now read-only.

Commit

Permalink
remove unused dem memory
Browse files Browse the repository at this point in the history
  • Loading branch information
Molly Lloyd committed Dec 12, 2018
1 parent d812bab commit f37a59d
Show file tree
Hide file tree
Showing 4 changed files with 22 additions and 31 deletions.
26 changes: 10 additions & 16 deletions src/mbgl/geometry/dem_data.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -5,8 +5,8 @@ namespace mbgl {

DEMData::DEMData(const PremultipliedImage& _image, Tileset::DEMEncoding encoding):
dim(_image.size.height),
border(std::max<int32_t>(std::ceil(_image.size.height / 2), 1)),
stride(dim + 2 * border),
// extra two pixels per row for border backfilling on either edge
stride(dim + 2),
image({ static_cast<uint32_t>(stride), static_cast<uint32_t>(stride) }) {

if (_image.size.height != _image.size.width){
Expand Down Expand Up @@ -76,22 +76,16 @@ void DEMData::backfillBorder(const DEMData& borderTileData, int8_t dx, int8_t dy
// represents. For example, dx = -1, dy = -1 represents the upper left corner of the
// base tile, so we only need to backfill one pixel at coordinates (-1, -1) of the tile
// image.
int32_t _xMin = dx * dim;
int32_t _xMax = dx * dim + dim;
int32_t _yMin = dy * dim;
int32_t _yMax = dy * dim + dim;
int32_t xMin = dx * dim;
int32_t xMax = dx * dim + dim;
int32_t yMin = dy * dim;
int32_t yMax = dy * dim + dim;

if (dx == -1) _xMin = _xMax - 1;
else if (dx == 1) _xMax = _xMin + 1;
if (dx == -1) xMin = xMax - 1;
else if (dx == 1) xMax = xMin + 1;

if (dy == -1) _yMin = _yMax - 1;
else if (dy == 1) _yMax = _yMin + 1;

int32_t xMin = util::clamp(_xMin, -border, dim + border);
int32_t xMax = util::clamp(_xMax, -border, dim + border);

int32_t yMin = util::clamp(_yMin, -border, dim + border);
int32_t yMax = util::clamp(_yMax, -border, dim + border);
if (dy == -1) yMin = yMax - 1;
else if (dy == 1) yMax = yMin + 1;

int32_t ox = -dx * dim;
int32_t oy = -dy * dim;
Expand Down
11 changes: 5 additions & 6 deletions src/mbgl/geometry/dem_data.hpp
Original file line number Diff line number Diff line change
Expand Up @@ -29,19 +29,18 @@ class DEMData {
}

const int32_t dim;
const int32_t border;
const int32_t stride;


private:
PremultipliedImage image;

size_t idx(const int32_t x, const int32_t y) const {
assert(x >= -border);
assert(x < dim + border);
assert(y >= -border);
assert(y < dim + border);
return (y + border) * stride + (x + border);
assert(x >= -1);
assert(x < dim + 1);
assert(y >= -1);
assert(y < dim + 1);
return (y + 1) * stride + (x + 1);
}

};
Expand Down
6 changes: 3 additions & 3 deletions src/mbgl/renderer/layers/render_hillshade_layer.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -130,8 +130,8 @@ void RenderHillshadeLayer::render(PaintParameters& parameters, RenderSource* src
}

if (!bucket.isPrepared() && parameters.pass == RenderPass::Pass3D) {
const uint16_t tilesize = bucket.getDEMData().dim;
OffscreenTexture view(parameters.context, { tilesize, tilesize });
const uint16_t stride = bucket.getDEMData().stride;
OffscreenTexture view(parameters.context, { stride, stride });
view.bind();

parameters.context.bindTexture(*bucket.dem, 0, gl::TextureFilter::Nearest, gl::TextureMipMap::No, gl::TextureWrap::Clamp, gl::TextureWrap::Clamp);
Expand All @@ -143,7 +143,7 @@ void RenderHillshadeLayer::render(PaintParameters& parameters, RenderSource* src
const auto allUniformValues = programInstance.computeAllUniformValues(
HillshadePrepareProgram::UniformValues {
uniforms::u_matrix::Value( mat ),
uniforms::u_dimension::Value( {{uint16_t(tilesize * 2), uint16_t(tilesize * 2)}} ),
uniforms::u_dimension::Value( {{stride, stride}} ),
uniforms::u_zoom::Value( float(tile.id.canonical.z) ),
uniforms::u_maxzoom::Value( float(maxzoom) ),
uniforms::u_image::Value( 0 )
Expand Down
10 changes: 4 additions & 6 deletions test/geometry/dem_data.test.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -20,19 +20,17 @@ TEST(DEMData, ConstructorMapbox) {
DEMData demdata(image, Tileset::DEMEncoding::Mapbox);

EXPECT_EQ(demdata.dim, 16);
EXPECT_EQ(demdata.border, 8);
EXPECT_EQ(demdata.stride, 32);
EXPECT_EQ(demdata.getImage()->bytes(), size_t(32*32*4));
EXPECT_EQ(demdata.stride, 18);
EXPECT_EQ(demdata.getImage()->bytes(), size_t(18*18*4));
};

TEST(DEMData, ConstructorTerrarium) {
PremultipliedImage image = fakeImage({16, 16});
DEMData demdata(image, Tileset::DEMEncoding::Terrarium);

EXPECT_EQ(demdata.dim, 16);
EXPECT_EQ(demdata.border, 8);
EXPECT_EQ(demdata.stride, 32);
EXPECT_EQ(demdata.getImage()->bytes(), size_t(32*32*4));
EXPECT_EQ(demdata.stride, 18);
EXPECT_EQ(demdata.getImage()->bytes(), size_t(18*18*4));
};

TEST(DEMData, RoundTrip) {
Expand Down

0 comments on commit f37a59d

Please sign in to comment.