opengl_gal: Remove extra padding of bitmap textures.

Since the format has been changed to RGBA8, default (UN)PACK_ALIGNMENT = 4
works correctly, so the texture width padding to 4 is not needed anymore.

Fixes https://gitlab.com/kicad/code/kicad/issues/14432


(cherry picked from commit e91b53fc39)
This commit is contained in:
Alex 2023-04-07 13:52:43 +03:00 committed by dsa-t
parent 372e7b6312
commit d7b2247878
1 changed files with 3 additions and 12 deletions

View File

@ -169,14 +169,6 @@ GLuint GL_BITMAP_CACHE::cacheBitmap( const BITMAP_BASE* aBitmap )
bmp.w = imgData.GetSize().x;
bmp.h = imgData.GetSize().y;
// The bitmap size needs to be a multiple of 4.
// This is easiest to achieve by ensuring that each row
// has a multiple of 4 pixels
int extra_w = bmp.w % 4;
if( extra_w )
extra_w = 4 - extra_w;
GLuint textureID;
if( m_freedTextureIds.empty() )
@ -189,15 +181,14 @@ GLuint GL_BITMAP_CACHE::cacheBitmap( const BITMAP_BASE* aBitmap )
m_freedTextureIds.pop_front();
}
// make_unique initializes this to 0, so extra pixels are transparent
bmp.size = ( bmp.w + extra_w ) * bmp.h * 4;
bmp.size = bmp.w * bmp.h * 4;
auto buf = std::make_unique<uint8_t[]>( bmp.size );
for( int y = 0; y < bmp.h; y++ )
{
for( int x = 0; x < bmp.w; x++ )
{
uint8_t* p = buf.get() + ( ( bmp.w + extra_w ) * y + x ) * 4;
uint8_t* p = buf.get() + ( bmp.w * y + x ) * 4;
p[0] = imgData.GetRed( x, y );
p[1] = imgData.GetGreen( x, y );
@ -214,7 +205,7 @@ GLuint GL_BITMAP_CACHE::cacheBitmap( const BITMAP_BASE* aBitmap )
}
glBindTexture( GL_TEXTURE_2D, textureID );
glTexImage2D( GL_TEXTURE_2D, 0, GL_RGBA8, bmp.w + extra_w, bmp.h, 0, GL_RGBA, GL_UNSIGNED_BYTE,
glTexImage2D( GL_TEXTURE_2D, 0, GL_RGBA8, bmp.w, bmp.h, 0, GL_RGBA, GL_UNSIGNED_BYTE,
buf.get() );
glTexParameteri( GL_TEXTURE_2D, GL_TEXTURE_MAG_FILTER, GL_NEAREST );