32 #ifndef vtkOpenGLContextDevice2DPrivate_h 33 #define vtkOpenGLContextDevice2DPrivate_h 80 : std::pair<Key,
CacheData>(key, cacheData){}
87 return this->
first == other.first;
121 typename std::list<CacheElement >::iterator it;
122 for (it = this->
Cache.begin(); it != this->
Cache.end(); ++it)
124 it->second.Texture->ReleaseGraphicsResources(window);
138 this->
Cache.pop_back();
140 this->
Cache.push_front(CacheElement(key, cacheData));
141 return this->
Cache.begin()->second;
157 typename std::list<CacheElement>::iterator it =
158 std::find(this->
Cache.begin(), this->
Cache.end(), CacheElement(key));
159 if (it != this->
Cache.end())
166 cacheData.Texture->SetInputData(cacheData.ImageData);
167 cacheData.TextWidth = 0;
168 cacheData.TextHeight = 0;
175 template <
class StringType>
185 return static_cast<unsigned int>(
id);
194 this->TextPropertyId = GetIdFromTextProperty(textProperty);
198 this->
Color.Set(static_cast<unsigned char>(color[0] * 255),
199 static_cast<unsigned char>(color[1] * 255),
200 static_cast<unsigned char>(color[2] * 255),
201 static_cast<unsigned char>(textProperty->
GetOpacity() * 255));
219 this->DPI == other.
DPI;
242 this->SpriteTexture = NULL;
243 this->SavedLighting = GL_TRUE;
244 this->SavedDepthTest = GL_TRUE;
245 this->SavedAlphaTest = GL_TRUE;
246 this->SavedStencilTest = GL_TRUE;
247 this->SavedBlend = GL_TRUE;
248 this->SavedDrawBuffer = 0;
249 this->SavedClearColor[0] = this->SavedClearColor[1] =
250 this->SavedClearColor[2] =
251 this->SavedClearColor[3] = 0.0f;
252 this->TextCounter = 0;
253 this->GLExtensionsLoaded =
false;
254 this->OpenGL15 =
false;
255 this->OpenGL20 =
false;
257 this->PowerOfTwoTextures =
true;
267 if (this->SpriteTexture)
269 this->SpriteTexture->
Delete();
270 this->SpriteTexture = NULL;
276 this->SavedLighting = glIsEnabled(GL_LIGHTING);
277 this->SavedDepthTest = glIsEnabled(GL_DEPTH_TEST);
281 this->SavedAlphaTest = glIsEnabled(GL_ALPHA_TEST);
282 this->SavedStencilTest = glIsEnabled(GL_STENCIL_TEST);
283 this->SavedBlend = glIsEnabled(GL_BLEND);
284 glGetFloatv(GL_COLOR_CLEAR_VALUE, this->SavedClearColor);
285 glGetIntegerv(GL_DRAW_BUFFER, &this->SavedDrawBuffer);
291 this->SetGLCapability(GL_LIGHTING, this->SavedLighting);
292 this->SetGLCapability(GL_DEPTH_TEST, this->SavedDepthTest);
296 this->SetGLCapability(GL_ALPHA_TEST, this->SavedAlphaTest);
297 this->SetGLCapability(GL_STENCIL_TEST, this->SavedStencilTest);
298 this->SetGLCapability(GL_BLEND, this->SavedBlend);
300 if(this->SavedDrawBuffer != GL_BACK_LEFT)
302 glDrawBuffer(this->SavedDrawBuffer);
306 bool colorDiffer =
false;
307 while(!colorDiffer && i < 4)
309 colorDiffer=this->SavedClearColor[i++] != 0.0;
313 glClearColor(this->SavedClearColor[0],
314 this->SavedClearColor[1],
315 this->SavedClearColor[2],
316 this->SavedClearColor[3]);
325 glEnable(capability);
329 glDisable(capability);
335 float* texCoord =
new float[2*
n];
336 float minX = f[0];
float minY = f[1];
337 float maxX = f[0];
float maxY = f[1];
339 for(
int i = 0; i <
n; ++i)
341 minX = fptr[0] < minX ? fptr[0] : minX;
342 maxX = fptr[0] > maxX ? fptr[0] : maxX;
343 minY = fptr[1] < minY ? fptr[1] : minY;
344 maxY = fptr[1] > maxY ? fptr[1] : maxY;
351 float rangeX = (textureBounds[1] - textureBounds[0]) ?
352 textureBounds[1] - textureBounds[0] : 1.;
353 float rangeY = (textureBounds[3] - textureBounds[2]) ?
354 textureBounds[3] - textureBounds[2] : 1.;
355 for (
int i = 0; i <
n; ++i)
357 texCoord[i*2] = (fptr[0]-minX) / rangeX;
358 texCoord[i*2+1] = (fptr[1]-minY) / rangeY;
364 float rangeX = (maxX - minX)? maxX - minX : 1.f;
365 float rangeY = (maxY - minY)? maxY - minY : 1.f;
366 for (
int i = 0; i <
n; ++i)
368 texCoord[i*2] = (fptr[0]-minX)/rangeX;
369 texCoord[i*2+1] = (fptr[1]-minY)/rangeY;
379 for (
int i = 0; i < 2; ++i)
381 while (pow2[i] < size[i])
393 cout <<
"Error = not an unsigned char..." << endl;
401 for (
int i = 0; i < 2; ++i)
403 texCoords[i] = size[i] /
float(newImg[i]);
406 unsigned char *dataPtr =
407 new unsigned char[newImg[0] * newImg[1] * bytesPerPixel];
408 unsigned char *origPtr =
411 for (
int i = 0; i < newImg[0]; ++i)
413 for (
int j = 0; j < newImg[1]; ++j)
415 for (
int k = 0; k < bytesPerPixel; ++k)
417 if (i < size[0] && j < size[1])
419 dataPtr[i * bytesPerPixel + j * newImg[0] * bytesPerPixel + k] =
420 origPtr[i * bytesPerPixel + j * size[0] * bytesPerPixel + k];
424 dataPtr[i * bytesPerPixel + j * newImg[0] * bytesPerPixel + k] =
432 GLint glFormat = bytesPerPixel == 3 ? GL_RGB : GL_RGBA;
433 GLint glInternalFormat = bytesPerPixel == 3 ? GL_RGB8 : GL_RGBA8;
435 glGenTextures(1, &tmpIndex);
436 glBindTexture(GL_TEXTURE_2D, tmpIndex);
441 glTexParameterf(GL_TEXTURE_2D, GL_TEXTURE_MIN_FILTER, GL_NEAREST);
442 glTexParameterf(GL_TEXTURE_2D, GL_TEXTURE_MAG_FILTER, GL_NEAREST);
443 glTexParameterf( GL_TEXTURE_2D, GL_TEXTURE_WRAP_S,
445 glTexParameterf( GL_TEXTURE_2D, GL_TEXTURE_WRAP_T,
448 glTexImage2D(GL_TEXTURE_2D, 0 , glInternalFormat,
449 newImg[0], newImg[1], 0, glFormat,
450 GL_UNSIGNED_BYTE, static_cast<const GLvoid *>(dataPtr));
451 glAlphaFunc(GL_GREATER, static_cast<GLclampf>(0));
452 glEnable(GL_ALPHA_TEST);
453 glMatrixMode(GL_TEXTURE);
455 glMatrixMode(GL_MODELVIEW);
456 glEnable(GL_TEXTURE_2D);
465 cout <<
"Error = not an unsigned char..." << endl;
472 unsigned char *dataPtr =
475 GLint glFormat = bytesPerPixel == 3 ? GL_RGB : GL_RGBA;
476 GLint glInternalFormat = bytesPerPixel == 3 ? GL_RGB8 : GL_RGBA8;
478 glGenTextures(1, &tmpIndex);
479 glBindTexture(GL_TEXTURE_2D, tmpIndex);
484 glTexParameterf(GL_TEXTURE_2D, GL_TEXTURE_MIN_FILTER, GL_NEAREST);
485 glTexParameterf(GL_TEXTURE_2D, GL_TEXTURE_MAG_FILTER, GL_NEAREST);
486 glTexParameterf( GL_TEXTURE_2D, GL_TEXTURE_WRAP_S,
488 glTexParameterf( GL_TEXTURE_2D, GL_TEXTURE_WRAP_T,
491 glTexImage2D(GL_TEXTURE_2D, 0 , glInternalFormat,
492 size[0], size[1], 0, glFormat,
493 GL_UNSIGNED_BYTE, static_cast<const GLvoid *>(dataPtr));
494 glAlphaFunc(GL_GREATER, static_cast<GLclampf>(0));
495 glEnable(GL_ALPHA_TEST);
496 glMatrixMode(GL_TEXTURE);
498 glMatrixMode(GL_MODELVIEW);
499 glEnable(GL_TEXTURE_2D);
513 GLfloat SavedClearColor[4];
532 #endif // VTKOPENGLCONTEXTDEVICE2DPRIVATE_H
std::list< CacheElement > Cache
GLuint TextureFromImage(vtkImageData *image)
GLenum GLsizei GLenum GLenum const GLvoid * image
bool operator==(const CacheElement &other) const
void SetGLCapability(GLenum capability, GLboolean state)
typedef GLuint(APIENTRYP PFNGLCREATEPROGRAMPROC)(void)
static int GetNumberOfScalarComponents(vtkInformation *meta_data)
GLuint TextureFromImage(vtkImageData *image, vtkVector2f &texCoords)
TextPropertyKey(vtkTextProperty *textProperty, const StringType &text, int dpi)
vtkSmartPointer< vtkTexture > Texture
typedef GLboolean(APIENTRYP PFNGLISQUERYPROC)(GLuint id)
static vtkSmartPointer< T > New()
CacheElement(const Key &key, const CacheData &cacheData)
void ReleaseGraphicsResources(vtkWindow *window)
vtkSmartPointer< vtkImageData > ImageData
float * TexCoords(float *f, int n)
TextPropertyKey< vtkStdString > UTF8TextPropertyKey
window superclass for vtkRenderWindow
bool operator==(const TextPropertyKey &other) const
virtual int * GetDimensions()
static int GetScalarType(vtkInformation *meta_data)
topologically and geometrically regular array of data
vtkImageData * GetInput()
CacheData & GetCacheData(const Key &key)
bool IsKeyInCache(const Key &key) const
handles properties associated with a texture map
virtual double GetOpacity()
represent text properties.
vtkTextureImageCache< UTF16TextPropertyKey > TextTextureCache
static unsigned int GetIdFromTextProperty(vtkTextProperty *textProperty)
typedef GLint(APIENTRYP PFNGLGETATTRIBLOCATIONPROC)(GLuint program
CacheElement(const Key &key)
virtual double * GetColor()
#define VTK_UNSIGNED_CHAR
typedef GLenum(APIENTRYP PFNGLCHECKFRAMEBUFFERSTATUSPROC)(GLenum target)
virtual void * GetScalarPointer(int coordinates[3])
vtkTexture * SpriteTexture
unsigned int TextureProperties
vtkVector2i FindPowerOfTwo(const vtkVector2i &size)
virtual int GetFontSize()
TextPropertyKey< vtkUnicodeString > UTF16TextPropertyKey
CacheData & AddCacheData(const Key &key, const CacheData &cacheData)
unsigned int TextPropertyId
const GLenum CLAMP_TO_EDGE
GLboolean SavedStencilTest
void RestoreGLState(bool colorBuffer=false)
void SaveGLState(bool colorBuffer=false)
const GLenum COMBINE_ALPHA
vtkTextureImageCache< UTF8TextPropertyKey > MathTextTextureCache