KiCad PCB EDA Suite
KIGFX::GL_BITMAP_CACHE Class Reference

Classes

struct  CACHED_BITMAP
 

Public Member Functions

 GL_BITMAP_CACHE ()
 
 ~GL_BITMAP_CACHE ()
 
GLuint RequestBitmap (const BITMAP_BASE *aBitmap)
 

Private Member Functions

GLuint cacheBitmap (const BITMAP_BASE *aBitmap)
 

Private Attributes

std::map< const BITMAP_BASE *, CACHED_BITMAPm_bitmaps
 

Detailed Description

Definition at line 68 of file opengl_gal.cpp.

Constructor & Destructor Documentation

KIGFX::GL_BITMAP_CACHE::GL_BITMAP_CACHE ( )
inline

Definition at line 71 of file opengl_gal.cpp.

72  {
73  }
GL_BITMAP_CACHE::~GL_BITMAP_CACHE ( )

Definition at line 95 of file opengl_gal.cpp.

96 {
97  for ( auto b = m_bitmaps.begin(); b != m_bitmaps.end(); ++b )
98  {
99  glDeleteTextures( 1, &b->second.id );
100  }
101 }
std::map< const BITMAP_BASE *, CACHED_BITMAP > m_bitmaps
Definition: opengl_gal.cpp:89

Member Function Documentation

GLuint GL_BITMAP_CACHE::cacheBitmap ( const BITMAP_BASE aBitmap)
private

Definition at line 119 of file opengl_gal.cpp.

References BITMAP_BASE::GetSizePixels(), KIGFX::GL_BITMAP_CACHE::CACHED_BITMAP::h, KIGFX::GL_BITMAP_CACHE::CACHED_BITMAP::id, and KIGFX::GL_BITMAP_CACHE::CACHED_BITMAP::w.

120 {
121  CACHED_BITMAP bmp;
122 
123  bmp.w = aBitmap->GetSizePixels().x;
124  bmp.h = aBitmap->GetSizePixels().y;
125 
126  // There are draw issues (incorrect rendering) with some w values.
127  // It happens when the w value is not a multiple of 4
128  // so we use only a sub image with a modified width
129  bmp.w -= bmp.w % 4;
130 
131  GLuint textureID;
132  glGenTextures(1, &textureID);
133 
134  uint8_t *buf = new uint8_t [ bmp.w * bmp.h * 3];
135  auto imgData = const_cast<BITMAP_BASE*>( aBitmap )->GetImageData();
136 
137  for( int y = 0; y < bmp.h; y++ )
138  {
139  for( int x = 0; x < bmp.w; x++ )
140  {
141  uint8_t *p = buf + ( bmp.w * y + x ) * 3;
142 
143  p[0] = imgData->GetRed( x, y );
144  p[1] = imgData->GetGreen( x, y );
145  p[2] = imgData->GetBlue( x, y );
146  }
147  }
148 
149  glBindTexture( GL_TEXTURE_2D, textureID );
150 
151  glTexImage2D( GL_TEXTURE_2D, 0,GL_RGB, bmp.w, bmp.h, 0, GL_RGB, GL_UNSIGNED_BYTE, buf );
152 
153  glTexParameteri( GL_TEXTURE_2D, GL_TEXTURE_MAG_FILTER, GL_NEAREST );
154  glTexParameteri( GL_TEXTURE_2D, GL_TEXTURE_MIN_FILTER, GL_NEAREST );
155 
156  delete [] buf;
157 
158  bmp.id = textureID;
159 
160  m_bitmaps[ aBitmap ] = bmp;
161 
162  return textureID;
163 }
This class handle bitmap images in KiCad.
Definition: bitmap_base.h:46
wxSize GetSizePixels() const
Function GetSizePixels.
Definition: bitmap_base.h:133
std::map< const BITMAP_BASE *, CACHED_BITMAP > m_bitmaps
Definition: opengl_gal.cpp:89
GLuint GL_BITMAP_CACHE::RequestBitmap ( const BITMAP_BASE aBitmap)

Definition at line 104 of file opengl_gal.cpp.

105 {
106  auto it = m_bitmaps.find( aBitmap) ;
107 
108  if ( it != m_bitmaps.end() )
109  {
110  return it->second.id;
111  }
112  else
113  {
114  return cacheBitmap( aBitmap );
115  }
116 }
GLuint cacheBitmap(const BITMAP_BASE *aBitmap)
Definition: opengl_gal.cpp:119
std::map< const BITMAP_BASE *, CACHED_BITMAP > m_bitmaps
Definition: opengl_gal.cpp:89

Member Data Documentation

std::map<const BITMAP_BASE*, CACHED_BITMAP> KIGFX::GL_BITMAP_CACHE::m_bitmaps
private

Definition at line 89 of file opengl_gal.cpp.


The documentation for this class was generated from the following file: