Implement updateTexture for GEGLTexture
This commit is contained in:
parent
4f9471dcff
commit
64c5762eeb
@ -166,4 +166,41 @@ void GEGLTexture::formatConversion(uint8_t* data, unsigned int* format,
|
|||||||
}
|
}
|
||||||
} // formatConversion
|
} // formatConversion
|
||||||
|
|
||||||
|
//-----------------------------------------------------------------------------
|
||||||
|
void GEGLTexture::updateTexture(void* data, video::ECOLOR_FORMAT format, u32 w,
|
||||||
|
u32 h, u32 x, u32 y)
|
||||||
|
{
|
||||||
|
glBindTexture(GL_TEXTURE_2D, m_texture_name);
|
||||||
|
|
||||||
|
if (m_single_channel)
|
||||||
|
{
|
||||||
|
if (format == video::ECF_R8)
|
||||||
|
{
|
||||||
|
glTexSubImage2D(GL_TEXTURE_2D, 0, x, y, w, h, GL_RED,
|
||||||
|
GL_UNSIGNED_BYTE, data);
|
||||||
|
}
|
||||||
|
}
|
||||||
|
else
|
||||||
|
{
|
||||||
|
if (format == video::ECF_R8)
|
||||||
|
{
|
||||||
|
const unsigned int size = w * h;
|
||||||
|
std::vector<uint8_t> image_data(size * 4, 255);
|
||||||
|
uint8_t* orig_data = (uint8_t*)data;
|
||||||
|
for (unsigned int i = 0; i < size; i++)
|
||||||
|
image_data[4 * i + 3] = orig_data[i];
|
||||||
|
glTexSubImage2D(GL_TEXTURE_2D, 0, x, y, w, h, GL_RGBA,
|
||||||
|
GL_UNSIGNED_BYTE, image_data.data());
|
||||||
|
}
|
||||||
|
else if (format == video::ECF_A8R8G8B8)
|
||||||
|
{
|
||||||
|
glTexSubImage2D(GL_TEXTURE_2D, 0, x, y, w, h, GL_RGBA,
|
||||||
|
GL_UNSIGNED_BYTE, data);
|
||||||
|
}
|
||||||
|
}
|
||||||
|
if (hasMipMaps())
|
||||||
|
glGenerateMipmap(GL_TEXTURE_2D);
|
||||||
|
glBindTexture(GL_TEXTURE_2D, 0);
|
||||||
|
} // updateTexture
|
||||||
|
|
||||||
}
|
}
|
||||||
|
@ -73,7 +73,9 @@ public:
|
|||||||
virtual unsigned int getTextureSize() const { return m_texture_size; }
|
virtual unsigned int getTextureSize() const { return m_texture_size; }
|
||||||
// ------------------------------------------------------------------------
|
// ------------------------------------------------------------------------
|
||||||
virtual void reload();
|
virtual void reload();
|
||||||
|
// ------------------------------------------------------------------------
|
||||||
|
virtual void updateTexture(void* data, irr::video::ECOLOR_FORMAT format,
|
||||||
|
u32 w, u32 h, u32 x, u32 y);
|
||||||
}; // GEGLTexture
|
}; // GEGLTexture
|
||||||
|
|
||||||
}
|
}
|
||||||
|
@ -246,27 +246,10 @@ void FontWithFace::insertGlyph(unsigned font_number, unsigned glyph_index)
|
|||||||
if (bits->buffer != NULL && !GUIEngine::isNoGraphics())
|
if (bits->buffer != NULL && !GUIEngine::isNoGraphics())
|
||||||
{
|
{
|
||||||
video::ITexture* tex = m_spritebank->getTexture(cur_tex);
|
video::ITexture* tex = m_spritebank->getTexture(cur_tex);
|
||||||
glBindTexture(GL_TEXTURE_2D, tex->getTextureHandler());
|
|
||||||
if (bits->pixel_mode == FT_PIXEL_MODE_GRAY)
|
if (bits->pixel_mode == FT_PIXEL_MODE_GRAY)
|
||||||
{
|
{
|
||||||
if (CVS->isARBTextureSwizzleUsable() && !useColorGlyphPage())
|
tex->updateTexture(bits->buffer, video::ECF_R8, bits->width,
|
||||||
{
|
bits->rows, m_used_width, m_used_height);
|
||||||
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_RGBA, GL_UNSIGNED_BYTE,
|
|
||||||
image_data);
|
|
||||||
delete[] image_data;
|
|
||||||
}
|
|
||||||
}
|
}
|
||||||
else if (bits->pixel_mode == FT_PIXEL_MODE_BGRA)
|
else if (bits->pixel_mode == FT_PIXEL_MODE_BGRA)
|
||||||
{
|
{
|
||||||
@ -315,9 +298,9 @@ void FontWithFace::insertGlyph(unsigned font_number, unsigned glyph_index)
|
|||||||
scaled_data[i * 4] = scaled_data[i * 4 + 2];
|
scaled_data[i * 4] = scaled_data[i * 4 + 2];
|
||||||
scaled_data[i * 4 + 2] = tmp_val;
|
scaled_data[i * 4 + 2] = tmp_val;
|
||||||
}
|
}
|
||||||
glTexSubImage2D(GL_TEXTURE_2D, 0, m_used_width, m_used_height,
|
tex->updateTexture(scaled_data, video::ECF_A8R8G8B8,
|
||||||
cur_glyph_width, cur_glyph_height, GL_RGBA, GL_UNSIGNED_BYTE,
|
cur_glyph_width, cur_glyph_height, m_used_width,
|
||||||
scaled_data);
|
m_used_height);
|
||||||
unscaled->drop();
|
unscaled->drop();
|
||||||
scaled->drop();
|
scaled->drop();
|
||||||
}
|
}
|
||||||
@ -325,9 +308,6 @@ void FontWithFace::insertGlyph(unsigned font_number, unsigned glyph_index)
|
|||||||
{
|
{
|
||||||
assert(false && "Invalid pixel mode");
|
assert(false && "Invalid pixel mode");
|
||||||
}
|
}
|
||||||
if (tex->hasMipMaps())
|
|
||||||
glGenerateMipmap(GL_TEXTURE_2D);
|
|
||||||
glBindTexture(GL_TEXTURE_2D, 0);
|
|
||||||
}
|
}
|
||||||
|
|
||||||
// Store the rectangle of current glyph
|
// Store the rectangle of current glyph
|
||||||
|
Loading…
Reference in New Issue
Block a user