In Pixmap and BitmapFont, use std::vector instead of std::unique_ptr.

MSVC 2013 keeps having aggravating bugs where its unique_ptr
implementation wants to use deleted functions.

In this case the worst that could happen is one copy per entity
once during initialization (which should in principle be elided
anyway because a return value is a prvalue... no idea if MSVC does
actually do that).
pull/10/head
whitequark 2016-05-18 10:40:56 +00:00
parent 56e2d451f4
commit 69b8a3b3b3
3 changed files with 10 additions and 11 deletions

View File

@ -575,7 +575,7 @@ void ssglDrawPixmap(const Pixmap &pixmap, bool flip) {
int format = pixmap.hasAlpha ? GL_RGBA : GL_RGB; int format = pixmap.hasAlpha ? GL_RGBA : GL_RGB;
glTexImage2D(GL_TEXTURE_2D, 0, format, pixmap.width, pixmap.height, 0, glTexImage2D(GL_TEXTURE_2D, 0, format, pixmap.width, pixmap.height, 0,
format, GL_UNSIGNED_BYTE, pixmap.data.get()); format, GL_UNSIGNED_BYTE, &pixmap.data[0]);
glEnable(GL_TEXTURE_2D); glEnable(GL_TEXTURE_2D);
glBegin(GL_QUADS); glBegin(GL_QUADS);
@ -612,8 +612,7 @@ static void LoadBitmapFont() {
BuiltinBitmapFont.AddGlyph(0xE006, LoadPNG("fonts/private/6-stipple-dash.png")); BuiltinBitmapFont.AddGlyph(0xE006, LoadPNG("fonts/private/6-stipple-dash.png"));
BuiltinBitmapFont.AddGlyph(0xE007, LoadPNG("fonts/private/7-stipple-zigzag.png")); BuiltinBitmapFont.AddGlyph(0xE007, LoadPNG("fonts/private/7-stipple-zigzag.png"));
// Unifont doesn't have a glyph for U+0020. // Unifont doesn't have a glyph for U+0020.
std::unique_ptr<uint8_t[]> blank(new uint8_t[8*16*3] {}); BuiltinBitmapFont.AddGlyph(0x20, Pixmap({ 8, 16, 8*3, false, std::vector<uint8_t>(8*16*3) }));
BuiltinBitmapFont.AddGlyph(0x20, Pixmap({ 8, 16, 8*3, false, std::move(blank) }));
} }
void ssglInitializeBitmapFont() void ssglInitializeBitmapFont()
@ -628,7 +627,7 @@ void ssglInitializeBitmapFont()
glTexEnvf(GL_TEXTURE_ENV, GL_TEXTURE_ENV_MODE, GL_REPLACE); glTexEnvf(GL_TEXTURE_ENV, GL_TEXTURE_ENV_MODE, GL_REPLACE);
glTexImage2D(GL_TEXTURE_2D, 0, GL_ALPHA, glTexImage2D(GL_TEXTURE_2D, 0, GL_ALPHA,
BitmapFont::TEXTURE_DIM, BitmapFont::TEXTURE_DIM, BitmapFont::TEXTURE_DIM, BitmapFont::TEXTURE_DIM,
0, GL_ALPHA, GL_UNSIGNED_BYTE, BuiltinBitmapFont.texture.get()); 0, GL_ALPHA, GL_UNSIGNED_BYTE, &BuiltinBitmapFont.texture[0]);
} }
int ssglBitmapCharWidth(char32_t codepoint) { int ssglBitmapCharWidth(char32_t codepoint) {

View File

@ -73,7 +73,7 @@ void Pixmap::Clear() {
} }
RgbaColor Pixmap::GetPixel(size_t x, size_t y) const { RgbaColor Pixmap::GetPixel(size_t x, size_t y) const {
uint8_t *pixel = &data[y * stride + x * GetBytesPerPixel()]; const uint8_t *pixel = &data[y * stride + x * GetBytesPerPixel()];
if(hasAlpha) { if(hasAlpha) {
return RgbaColor::From(pixel[0], pixel[1], pixel[2], pixel[3]); return RgbaColor::From(pixel[0], pixel[1], pixel[2], pixel[3]);
@ -94,7 +94,7 @@ static Pixmap ReadPNGIntoPixmap(png_struct *png_ptr, png_info *info_ptr) {
if(stride % 4 != 0) stride += 4 - stride % 4; if(stride % 4 != 0) stride += 4 - stride % 4;
pixmap.stride = stride; pixmap.stride = stride;
pixmap.data = std::unique_ptr<uint8_t[]>(new uint8_t[pixmap.stride * pixmap.height]); pixmap.data = std::vector<uint8_t>(pixmap.stride * pixmap.height);
uint8_t **rows = png_get_rows(png_ptr, info_ptr); uint8_t **rows = png_get_rows(png_ptr, info_ptr);
for(size_t y = 0; y < pixmap.height; y++) { for(size_t y = 0; y < pixmap.height; y++) {
memcpy(&pixmap.data[pixmap.stride * y], rows[y], memcpy(&pixmap.data[pixmap.stride * y], rows[y],
@ -264,7 +264,7 @@ static uint8_t *BitmapFontTextureRow(uint8_t *texture, uint16_t position, size_t
BitmapFont BitmapFont::From(std::string &&unifontData) { BitmapFont BitmapFont::From(std::string &&unifontData) {
BitmapFont font = {}; BitmapFont font = {};
font.unifontData = std::move(unifontData); font.unifontData = std::move(unifontData);
font.texture = std::unique_ptr<uint8_t[]>(new uint8_t[TEXTURE_DIM * TEXTURE_DIM]); font.texture = std::vector<uint8_t>(TEXTURE_DIM * TEXTURE_DIM);
return font; return font;
} }
@ -279,7 +279,7 @@ void BitmapFont::AddGlyph(char32_t codepoint, const Pixmap &pixmap) {
glyphs.emplace(codepoint, std::move(glyph)); glyphs.emplace(codepoint, std::move(glyph));
for(size_t y = 0; y < pixmap.height; y++) { for(size_t y = 0; y < pixmap.height; y++) {
uint8_t *row = BitmapFontTextureRow(texture.get(), glyph.position, y); uint8_t *row = BitmapFontTextureRow(&texture[0], glyph.position, y);
for(size_t x = 0; x < pixmap.width; x++) { for(size_t x = 0; x < pixmap.width; x++) {
if(pixmap.GetPixel(x, y).ToPackedInt() != 0) { if(pixmap.GetPixel(x, y).ToPackedInt() != 0) {
row[x] = 255; row[x] = 255;
@ -348,7 +348,7 @@ const BitmapFont::Glyph &BitmapFont::GetGlyph(char32_t codepoint) {
// Fill in the texture (one texture byte per glyph bit). // Fill in the texture (one texture byte per glyph bit).
for(size_t y = 0; y < 16; y++) { for(size_t y = 0; y < 16; y++) {
uint8_t *row = BitmapFontTextureRow(texture.get(), glyph.position, y); uint8_t *row = BitmapFontTextureRow(&texture[0], glyph.position, y);
for(size_t x = 0; x < 16; x++) { for(size_t x = 0; x < 16; x++) {
if(glyphBits[y] & (1 << (15 - x))) { if(glyphBits[y] & (1 << (15 - x))) {
row[x] = 255; row[x] = 255;

View File

@ -26,7 +26,7 @@ public:
size_t height; size_t height;
size_t stride; size_t stride;
bool hasAlpha; bool hasAlpha;
std::unique_ptr<uint8_t[]> data; std::vector<uint8_t> data;
static Pixmap FromPNG(const uint8_t *data, size_t size); static Pixmap FromPNG(const uint8_t *data, size_t size);
static Pixmap FromPNG(FILE *f); static Pixmap FromPNG(FILE *f);
@ -49,7 +49,7 @@ public:
std::string unifontData; std::string unifontData;
std::map<char32_t, Glyph> glyphs; std::map<char32_t, Glyph> glyphs;
std::unique_ptr<uint8_t[]> texture; std::vector<uint8_t> texture;
uint16_t nextPosition; uint16_t nextPosition;
static BitmapFont From(std::string &&unifontData); static BitmapFont From(std::string &&unifontData);