Use unique_ptr

This commit is contained in:
John Firebaugh
2014-11-26 13:48:48 -08:00
parent 80df07a5da
commit fdc988a4a0
2 changed files with 4 additions and 10 deletions

View File

@@ -28,8 +28,6 @@ private:
const SDFGlyph& glyph);
public:
GlyphAtlas(uint16_t width, uint16_t height);
~GlyphAtlas();
Rect<uint16_t> addGlyph(uint64_t tile_id, const std::string& face_name,
const SDFGlyph& glyph);
@@ -46,7 +44,7 @@ private:
std::mutex mtx;
BinPack<uint16_t> bin;
std::map<std::string, std::map<uint32_t, GlyphValue>> index;
char *const data = nullptr;
std::unique_ptr<char[]> data;
std::atomic<bool> dirty;
uint32_t texture = 0;
};

View File

@@ -17,10 +17,6 @@ GlyphAtlas::GlyphAtlas(uint16_t width_, uint16_t height_)
dirty(true) {
}
GlyphAtlas::~GlyphAtlas() {
delete[] data;
}
Rect<uint16_t> GlyphAtlas::addGlyph(uint64_t tile_id, const std::string& face_name,
const SDFGlyph& glyph)
{
@@ -74,7 +70,7 @@ Rect<uint16_t> GlyphAtlas::addGlyph_impl(uint64_t tile_id, const std::string& fa
face.emplace(glyph.id, GlyphValue { rect, tile_id });
// Copy the bitmap
char *target = data;
char *target = data.get();
const char *source = glyph.bitmap.data();
for (uint32_t y = 0; y < buffered_height; y++) {
uint32_t y1 = width * (rect.y + y) + rect.x;
@@ -119,7 +115,7 @@ void GlyphAtlas::removeGlyphs(uint64_t tile_id) {
const Rect<uint16_t>& rect = value.rect;
// Clear out the bitmap.
char *target = data;
char *target = data.get();
for (uint32_t y = 0; y < rect.h; y++) {
uint32_t y1 = width * (rect.y + y) + rect.x;
for (uint32_t x = 0; x < rect.w; x++) {
@@ -157,7 +153,7 @@ void GlyphAtlas::bind() {
if (dirty) {
std::lock_guard<std::mutex> lock(mtx);
glTexImage2D(GL_TEXTURE_2D, 0, GL_ALPHA, width, height, 0, GL_ALPHA, GL_UNSIGNED_BYTE, data);
glTexImage2D(GL_TEXTURE_2D, 0, GL_ALPHA, width, height, 0, GL_ALPHA, GL_UNSIGNED_BYTE, data.get());
dirty = false;
#if defined(DEBUG)