33 #ifndef vtkOpenGLContextDevice2DPrivate_h 34 #define vtkOpenGLContextDevice2DPrivate_h 84 : std::pair<Key,
CacheData>(key, cacheData){}
91 return this->first == other.first;
128 typename std::list<CacheElement >::iterator it;
129 for (it = this->
Cache.begin(); it != this->
Cache.end(); ++it)
131 it->second.Texture->ReleaseGraphicsResources(window);
147 this->
Cache.pop_back();
149 this->
Cache.push_front(CacheElement(key, cacheData));
150 return this->
Cache.begin()->second;
170 typename std::list<CacheElement>::iterator it =
171 std::find(this->
Cache.begin(), this->
Cache.end(), CacheElement(key));
172 if (it != this->
Cache.end())
179 cacheData.Texture->SetInputData(cacheData.ImageData);
186 template <
class StringType>
203 vtkTypeUInt32 hash =
static_cast<vtkTypeUInt32
>(id);
207 assert(
"Hash is really a uint32" && static_cast<size_t>(hash) ==
id);
228 this->TextPropertyId = GetIdFromTextProperty(textProperty);
232 this->
Color.Set(static_cast<unsigned char>(color[0] * 255),
233 static_cast<unsigned char>(color[1] * 255),
234 static_cast<unsigned char>(color[2] * 255),
235 static_cast<unsigned char>(textProperty->
GetOpacity() * 255));
254 this->DPI == other.
DPI;
276 this->SpriteTexture = NULL;
277 this->SavedLighting = GL_TRUE;
278 this->SavedDepthTest = GL_TRUE;
279 this->SavedAlphaTest = GL_TRUE;
280 this->SavedStencilTest = GL_TRUE;
281 this->SavedBlend = GL_TRUE;
282 this->SavedDrawBuffer = 0;
283 this->SavedClearColor[0] = this->SavedClearColor[1] =
284 this->SavedClearColor[2] =
285 this->SavedClearColor[3] = 0.0f;
286 this->TextCounter = 0;
287 this->GLExtensionsLoaded =
false;
288 this->OpenGL15 =
false;
289 this->OpenGL20 =
false;
291 this->PowerOfTwoTextures =
true;
301 if (this->SpriteTexture)
303 this->SpriteTexture->
Delete();
304 this->SpriteTexture = NULL;
310 this->SavedLighting = glIsEnabled(GL_LIGHTING);
311 this->SavedDepthTest = glIsEnabled(GL_DEPTH_TEST);
315 this->SavedAlphaTest = glIsEnabled(GL_ALPHA_TEST);
316 this->SavedStencilTest = glIsEnabled(GL_STENCIL_TEST);
317 this->SavedBlend = glIsEnabled(GL_BLEND);
318 glGetFloatv(GL_COLOR_CLEAR_VALUE, this->SavedClearColor);
319 glGetIntegerv(GL_DRAW_BUFFER, &this->SavedDrawBuffer);
325 this->SetGLCapability(GL_LIGHTING, this->SavedLighting);
326 this->SetGLCapability(GL_DEPTH_TEST, this->SavedDepthTest);
330 this->SetGLCapability(GL_ALPHA_TEST, this->SavedAlphaTest);
331 this->SetGLCapability(GL_STENCIL_TEST, this->SavedStencilTest);
332 this->SetGLCapability(GL_BLEND, this->SavedBlend);
334 if(this->SavedDrawBuffer != GL_BACK_LEFT)
336 glDrawBuffer(this->SavedDrawBuffer);
340 bool colorDiffer =
false;
341 while(!colorDiffer && i < 4)
343 colorDiffer=this->SavedClearColor[i++] != 0.0;
347 glClearColor(this->SavedClearColor[0],
348 this->SavedClearColor[1],
349 this->SavedClearColor[2],
350 this->SavedClearColor[3]);
359 glEnable(capability);
363 glDisable(capability);
369 float* texCoord =
new float[2*n];
370 float minX = f[0];
float minY = f[1];
371 float maxX = f[0];
float maxY = f[1];
373 for(
int i = 0; i < n; ++i)
375 minX = fptr[0] < minX ? fptr[0] : minX;
376 maxX = fptr[0] > maxX ? fptr[0] : maxX;
377 minY = fptr[1] < minY ? fptr[1] : minY;
378 maxY = fptr[1] > maxY ? fptr[1] : maxY;
385 float rangeX = (textureBounds[1] - textureBounds[0]) ?
386 textureBounds[1] - textureBounds[0] : 1.;
387 float rangeY = (textureBounds[3] - textureBounds[2]) ?
388 textureBounds[3] - textureBounds[2] : 1.;
389 for (
int i = 0; i < n; ++i)
391 texCoord[i*2] = (fptr[0]-minX) / rangeX;
392 texCoord[i*2+1] = (fptr[1]-minY) / rangeY;
398 float rangeX = (maxX - minX)? maxX - minX : 1.f;
399 float rangeY = (maxY - minY)? maxY - minY : 1.f;
400 for (
int i = 0; i < n; ++i)
402 texCoord[i*2] = (fptr[0]-minX)/rangeX;
403 texCoord[i*2+1] = (fptr[1]-minY)/rangeY;
413 for (
int i = 0; i < 2; ++i)
415 while (pow2[i] < size[i])
427 cout <<
"Error = not an unsigned char..." << endl;
435 for (
int i = 0; i < 2; ++i)
437 texCoords[i] = size[i] /
float(newImg[i]);
440 unsigned char *dataPtr =
441 new unsigned char[newImg[0] * newImg[1] * bytesPerPixel];
442 unsigned char *origPtr =
445 for (
int i = 0; i < newImg[0]; ++i)
447 for (
int j = 0; j < newImg[1]; ++j)
449 for (
int k = 0; k < bytesPerPixel; ++k)
451 if (i < size[0] && j < size[1])
453 dataPtr[i * bytesPerPixel + j * newImg[0] * bytesPerPixel + k] =
454 origPtr[i * bytesPerPixel + j * size[0] * bytesPerPixel + k];
458 dataPtr[i * bytesPerPixel + j * newImg[0] * bytesPerPixel + k] =
466 GLint glFormat = bytesPerPixel == 3 ? GL_RGB : GL_RGBA;
467 GLint glInternalFormat = bytesPerPixel == 3 ? GL_RGB8 : GL_RGBA8;
469 glGenTextures(1, &tmpIndex);
470 glBindTexture(GL_TEXTURE_2D, tmpIndex);
472 glTexEnvf(GL_TEXTURE_ENV, vtkgl::COMBINE_RGB, GL_REPLACE);
473 glTexEnvf(GL_TEXTURE_ENV, vtkgl::COMBINE_ALPHA, GL_REPLACE);
475 glTexParameterf(GL_TEXTURE_2D, GL_TEXTURE_MIN_FILTER, GL_NEAREST);
476 glTexParameterf(GL_TEXTURE_2D, GL_TEXTURE_MAG_FILTER, GL_NEAREST);
477 glTexParameterf( GL_TEXTURE_2D, GL_TEXTURE_WRAP_S,
478 vtkgl::CLAMP_TO_EDGE );
479 glTexParameterf( GL_TEXTURE_2D, GL_TEXTURE_WRAP_T,
480 vtkgl::CLAMP_TO_EDGE );
482 glTexImage2D(GL_TEXTURE_2D, 0 , glInternalFormat,
483 newImg[0], newImg[1], 0, glFormat,
484 GL_UNSIGNED_BYTE, static_cast<const GLvoid *>(dataPtr));
485 glAlphaFunc(GL_GREATER, static_cast<GLclampf>(0));
486 glEnable(GL_ALPHA_TEST);
487 glMatrixMode(GL_TEXTURE);
489 glMatrixMode(GL_MODELVIEW);
490 glEnable(GL_TEXTURE_2D);
499 cout <<
"Error = not an unsigned char..." << endl;
506 unsigned char *dataPtr =
509 GLint glFormat = bytesPerPixel == 3 ? GL_RGB : GL_RGBA;
510 GLint glInternalFormat = bytesPerPixel == 3 ? GL_RGB8 : GL_RGBA8;
512 glGenTextures(1, &tmpIndex);
513 glBindTexture(GL_TEXTURE_2D, tmpIndex);
515 glTexEnvf(GL_TEXTURE_ENV, vtkgl::COMBINE_RGB, GL_REPLACE);
516 glTexEnvf(GL_TEXTURE_ENV, vtkgl::COMBINE_ALPHA, GL_REPLACE);
518 glTexParameterf(GL_TEXTURE_2D, GL_TEXTURE_MIN_FILTER, GL_NEAREST);
519 glTexParameterf(GL_TEXTURE_2D, GL_TEXTURE_MAG_FILTER, GL_NEAREST);
520 glTexParameterf( GL_TEXTURE_2D, GL_TEXTURE_WRAP_S,
521 vtkgl::CLAMP_TO_EDGE );
522 glTexParameterf( GL_TEXTURE_2D, GL_TEXTURE_WRAP_T,
523 vtkgl::CLAMP_TO_EDGE );
525 glTexImage2D(GL_TEXTURE_2D, 0 , glInternalFormat,
526 size[0], size[1], 0, glFormat,
527 GL_UNSIGNED_BYTE, static_cast<const GLvoid *>(dataPtr));
528 glAlphaFunc(GL_GREATER, static_cast<GLclampf>(0));
529 glEnable(GL_ALPHA_TEST);
530 glMatrixMode(GL_TEXTURE);
532 glMatrixMode(GL_MODELVIEW);
533 glEnable(GL_TEXTURE_2D);
547 GLfloat SavedClearColor[4];
568 #endif // VTKOPENGLCONTEXTDEVICE2DPRIVATE_H
std::list< CacheElement > Cache
List of a pair of key and cache data.
GLuint TextureFromImage(vtkImageData *image)
virtual int GetJustification()
Set/Get the horizontal justification to left (default), centered, or right.
bool operator==(const CacheElement &other) const
void SetGLCapability(GLenum capability, GLboolean state)
double * GetBounds()
Return a pointer to the geometry bounding box in the form (xmin,xmax, ymin,ymax, zmin,zmax).
vtkTextRenderer::Metrics Metrics
static int GetNumberOfScalarComponents(vtkInformation *meta_data)
Set/Get the number of scalar components for points.
GLuint TextureFromImage(vtkImageData *image, vtkVector2f &texCoords)
vtkTypeUInt32 TextPropertyId
TextPropertyKey(vtkTextProperty *textProperty, const StringType &text, int dpi)
Creates a TextPropertyKey.
vtkSmartPointer< vtkTexture > Texture
static vtkSmartPointer< T > New()
Create an instance of a VTK object.
CacheElement(const Key &key, const CacheData &cacheData)
void ReleaseGraphicsResources(vtkWindow *window)
Release all the OpenGL Pixel Buffer Object(PBO) associated with the textures of the cache list...
vtkSmartPointer< vtkImageData > ImageData
float * TexCoords(float *f, int n)
TextPropertyKey< vtkStdString > UTF8TextPropertyKey
window superclass for vtkRenderWindow
size_t MaxSize
Maximum size the cache list can be.
bool operator==(const TextPropertyKey &other) const
Compares two TextPropertyKeys with each other.
virtual int * GetDimensions()
Get dimensions of this structured points dataset.
static int GetScalarType(vtkInformation *meta_data)
topologically and geometrically regular array of data
vtkImageData * GetInput()
Get the input as a vtkImageData object.
Some derived classes for the different vectors commonly used.
virtual int GetVerticalJustification()
Set/Get the vertical justification to bottom (default), middle, or top.
CacheData & GetCacheData(const Key &key)
Return the cache associated to a key.
bool IsKeyInCache(const Key &key) const
Search the cache list to see if a given key already exists.
handles properties associated with a texture map
vtkTextureImageCache()
Construct a texture image cache with a maximum number of texture of 50.
virtual double GetOpacity()
Set/Get the text's opacity.
represent text properties.
vtkTextureImageCache< UTF16TextPropertyKey > TextTextureCache
Cache for text images.
CacheElement(const Key &key)
virtual double * GetColor()
Set the color of the text.
#define VTK_UNSIGNED_CHAR
virtual void * GetScalarPointer(int coordinates[3])
Access the native pointer for the scalar data.
vtkTexture * SpriteTexture
unsigned int TextureProperties
CacheElement associates a unique key to some cache.
vtkVector2i FindPowerOfTwo(const vtkVector2i &size)
virtual int GetFontSize()
Set/Get the font size (in points).
TextPropertyKey< vtkUnicodeString > UTF16TextPropertyKey
static vtkTypeUInt32 GetIdFromTextProperty(vtkTextProperty *tprop)
Transform a text property into an unsigned long.
CacheData & AddCacheData(const Key &key, const CacheData &cacheData)
Add a new cache entry into the cache list.
GLboolean SavedStencilTest
void RestoreGLState(bool colorBuffer=false)
void SaveGLState(bool colorBuffer=false)
virtual void Delete()
Delete a VTK object.
vtkTextureImageCache< UTF8TextPropertyKey > MathTextTextureCache
Cache for text images.