From 4af255431ce0206739707fcc72232b3b1f947642 Mon Sep 17 00:00:00 2001 From: Benau Date: Sun, 12 Feb 2017 10:23:18 +0800 Subject: [PATCH] Fix opengl warning about glTexSubImage2D buffer of null pointer For example, whitespace in freetype glyph has no bits buffer --- src/font/font_with_face.cpp | 45 ++++++++++++++++++++----------------- 1 file changed, 25 insertions(+), 20 deletions(-) diff --git a/src/font/font_with_face.cpp b/src/font/font_with_face.cpp index 39426f74a..beaf33c30 100644 --- a/src/font/font_with_face.cpp +++ b/src/font/font_with_face.cpp @@ -206,28 +206,33 @@ void FontWithFace::insertGlyph(wchar_t c, const GlyphInfo& gi) const unsigned int cur_tex = m_spritebank->getTextureCount() -1; #ifndef SERVER_ONLY - video::ITexture* tex = m_spritebank->getTexture(cur_tex); - glBindTexture(GL_TEXTURE_2D, tex->getOpenGLTextureName()); - assert(bits->pixel_mode == FT_PIXEL_MODE_GRAY); - if (CVS->isARBTextureSwizzleUsable()) + if (bits->buffer != NULL) { - glTexSubImage2D(GL_TEXTURE_2D, 0, m_used_width, m_used_height, - bits->width, bits->rows, GL_RED, GL_UNSIGNED_BYTE, bits->buffer); + video::ITexture* tex = m_spritebank->getTexture(cur_tex); + glBindTexture(GL_TEXTURE_2D, tex->getOpenGLTextureName()); + assert(bits->pixel_mode == FT_PIXEL_MODE_GRAY); + if (CVS->isARBTextureSwizzleUsable()) + { + glTexSubImage2D(GL_TEXTURE_2D, 0, m_used_width, m_used_height, + bits->width, bits->rows, GL_RED, GL_UNSIGNED_BYTE, + bits->buffer); + } + else + { + const unsigned int size = bits->width * bits->rows; + uint8_t* image_data = new uint8_t[size * 4]; + memset(image_data, 255, size * 4); + for (unsigned int i = 0; i < size; i++) + image_data[4 * i + 3] = bits->buffer[i]; + glTexSubImage2D(GL_TEXTURE_2D, 0, m_used_width, m_used_height, + bits->width, bits->rows, GL_BGRA, GL_UNSIGNED_BYTE, + image_data); + delete[] image_data; + } + if (tex->hasMipMaps()) + glGenerateMipmap(GL_TEXTURE_2D); + glBindTexture(GL_TEXTURE_2D, 0); } - else - { - const unsigned int size = bits->width * bits->rows; - uint8_t* image_data = new uint8_t[size * 4]; - memset(image_data, 255, size * 4); - for (unsigned int i = 0; i < size; i++) - image_data[4 * i + 3] = bits->buffer[i]; - glTexSubImage2D(GL_TEXTURE_2D, 0, m_used_width, m_used_height, - bits->width, bits->rows, GL_BGRA, GL_UNSIGNED_BYTE, image_data); - delete[] image_data; - } - if (tex->hasMipMaps()) - glGenerateMipmap(GL_TEXTURE_2D); - glBindTexture(GL_TEXTURE_2D, 0); #endif // Store the rectangle of current glyph