32 #ifndef vtkOpenGLContextDevice2DPrivate_h 33 #define vtkOpenGLContextDevice2DPrivate_h 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 =
159 if (it != this->
Cache.end())
175 template <
class StringType>
184 return static_cast<unsigned int>(
id);
192 this->TextPropertyId = GetIdFromTextProperty(textProperty);
196 this->
Color.Set(static_cast<unsigned char>(color[0] * 255),
197 static_cast<unsigned char>(color[1] * 255),
198 static_cast<unsigned char>(color[2] * 255),
199 static_cast<unsigned char>(textProperty->
GetOpacity() * 255));
237 this->SpriteTexture = NULL;
238 this->SavedLighting = GL_TRUE;
239 this->SavedDepthTest = GL_TRUE;
240 this->SavedAlphaTest = GL_TRUE;
241 this->SavedStencilTest = GL_TRUE;
242 this->SavedBlend = GL_TRUE;
243 this->SavedDrawBuffer = 0;
244 this->SavedClearColor[0] = this->SavedClearColor[1] =
245 this->SavedClearColor[2] =
246 this->SavedClearColor[3] = 0.0f;
247 this->TextCounter = 0;
248 this->GLExtensionsLoaded =
false;
249 this->OpenGL15 =
false;
250 this->OpenGL20 =
false;
252 this->PowerOfTwoTextures =
true;
262 if (this->SpriteTexture)
264 this->SpriteTexture->
Delete();
265 this->SpriteTexture = NULL;
271 this->SavedLighting = glIsEnabled(GL_LIGHTING);
272 this->SavedDepthTest = glIsEnabled(GL_DEPTH_TEST);
276 this->SavedAlphaTest = glIsEnabled(GL_ALPHA_TEST);
277 this->SavedStencilTest = glIsEnabled(GL_STENCIL_TEST);
278 this->SavedBlend = glIsEnabled(GL_BLEND);
279 glGetFloatv(GL_COLOR_CLEAR_VALUE, this->SavedClearColor);
280 glGetIntegerv(GL_DRAW_BUFFER, &this->SavedDrawBuffer);
286 this->SetGLCapability(GL_LIGHTING, this->SavedLighting);
287 this->SetGLCapability(GL_DEPTH_TEST, this->SavedDepthTest);
291 this->SetGLCapability(GL_ALPHA_TEST, this->SavedAlphaTest);
292 this->SetGLCapability(GL_STENCIL_TEST, this->SavedStencilTest);
293 this->SetGLCapability(GL_BLEND, this->SavedBlend);
295 if(this->SavedDrawBuffer != GL_BACK_LEFT)
297 glDrawBuffer(this->SavedDrawBuffer);
301 bool colorDiffer =
false;
302 while(!colorDiffer && i < 4)
304 colorDiffer=this->SavedClearColor[i++] != 0.0;
308 glClearColor(this->SavedClearColor[0],
309 this->SavedClearColor[1],
310 this->SavedClearColor[2],
311 this->SavedClearColor[3]);
320 glEnable(capability);
324 glDisable(capability);
330 float* texCoord =
new float[2*
n];
331 float minX = f[0];
float minY = f[1];
332 float maxX = f[0];
float maxY = f[1];
334 for(
int i = 0; i <
n; ++i)
336 minX = fptr[0] < minX ? fptr[0] : minX;
337 maxX = fptr[0] > maxX ? fptr[0] : maxX;
338 minY = fptr[1] < minY ? fptr[1] : minY;
339 maxY = fptr[1] > maxY ? fptr[1] : maxY;
346 float rangeX = (textureBounds[1] - textureBounds[0]) ?
347 textureBounds[1] - textureBounds[0] : 1.;
348 float rangeY = (textureBounds[3] - textureBounds[2]) ?
349 textureBounds[3] - textureBounds[2] : 1.;
350 for (
int i = 0; i <
n; ++i)
352 texCoord[i*2] = (fptr[0]-minX) / rangeX;
353 texCoord[i*2+1] = (fptr[1]-minY) / rangeY;
359 float rangeX = (maxX - minX)? maxX - minX : 1.f;
360 float rangeY = (maxY - minY)? maxY - minY : 1.f;
361 for (
int i = 0; i <
n; ++i)
363 texCoord[i*2] = (fptr[0]-minX)/rangeX;
364 texCoord[i*2+1] = (fptr[1]-minY)/rangeY;
374 for (
int i = 0; i < 2; ++i)
376 while (pow2[i] < size[i])
388 cout <<
"Error = not an unsigned char..." << endl;
396 for (
int i = 0; i < 2; ++i)
398 texCoords[i] = size[i] /
float(newImg[i]);
401 unsigned char *dataPtr =
402 new unsigned char[newImg[0] * newImg[1] * bytesPerPixel];
403 unsigned char *origPtr =
406 for (
int i = 0; i < newImg[0]; ++i)
408 for (
int j = 0; j < newImg[1]; ++j)
410 for (
int k = 0; k < bytesPerPixel; ++k)
412 if (i < size[0] && j < size[1])
414 dataPtr[i * bytesPerPixel + j * newImg[0] * bytesPerPixel + k] =
415 origPtr[i * bytesPerPixel + j * size[0] * bytesPerPixel + k];
419 dataPtr[i * bytesPerPixel + j * newImg[0] * bytesPerPixel + k] =
427 GLint glFormat = bytesPerPixel == 3 ? GL_RGB : GL_RGBA;
428 GLint glInternalFormat = bytesPerPixel == 3 ? GL_RGB8 : GL_RGBA8;
430 glGenTextures(1, &tmpIndex);
431 glBindTexture(GL_TEXTURE_2D, tmpIndex);
436 glTexParameterf(GL_TEXTURE_2D, GL_TEXTURE_MIN_FILTER, GL_NEAREST);
437 glTexParameterf(GL_TEXTURE_2D, GL_TEXTURE_MAG_FILTER, GL_NEAREST);
438 glTexParameterf( GL_TEXTURE_2D, GL_TEXTURE_WRAP_S,
440 glTexParameterf( GL_TEXTURE_2D, GL_TEXTURE_WRAP_T,
443 glTexImage2D(GL_TEXTURE_2D, 0 , glInternalFormat,
444 newImg[0], newImg[1], 0, glFormat,
445 GL_UNSIGNED_BYTE, static_cast<const GLvoid *>(dataPtr));
446 glAlphaFunc(GL_GREATER, static_cast<GLclampf>(0));
447 glEnable(GL_ALPHA_TEST);
448 glMatrixMode(GL_TEXTURE);
450 glMatrixMode(GL_MODELVIEW);
451 glEnable(GL_TEXTURE_2D);
460 cout <<
"Error = not an unsigned char..." << endl;
467 unsigned char *dataPtr =
470 GLint glFormat = bytesPerPixel == 3 ? GL_RGB : GL_RGBA;
471 GLint glInternalFormat = bytesPerPixel == 3 ? GL_RGB8 : GL_RGBA8;
473 glGenTextures(1, &tmpIndex);
474 glBindTexture(GL_TEXTURE_2D, tmpIndex);
479 glTexParameterf(GL_TEXTURE_2D, GL_TEXTURE_MIN_FILTER, GL_NEAREST);
480 glTexParameterf(GL_TEXTURE_2D, GL_TEXTURE_MAG_FILTER, GL_NEAREST);
481 glTexParameterf( GL_TEXTURE_2D, GL_TEXTURE_WRAP_S,
483 glTexParameterf( GL_TEXTURE_2D, GL_TEXTURE_WRAP_T,
486 glTexImage2D(GL_TEXTURE_2D, 0 , glInternalFormat,
487 size[0], size[1], 0, glFormat,
488 GL_UNSIGNED_BYTE, static_cast<const GLvoid *>(dataPtr));
489 glAlphaFunc(GL_GREATER, static_cast<GLclampf>(0));
490 glEnable(GL_ALPHA_TEST);
491 glMatrixMode(GL_TEXTURE);
493 glMatrixMode(GL_MODELVIEW);
494 glEnable(GL_TEXTURE_2D);
508 GLfloat SavedClearColor[4];
527 #endif // VTKOPENGLCONTEXTDEVICE2DPRIVATE_H
TextPropertyKey(vtkTextProperty *textProperty, const StringType &text)
std::list< CacheElement > Cache
GLuint TextureFromImage(vtkImageData *image)
bool operator==(const CacheElement &other) const
GLenum GLsizei GLenum GLenum const GLvoid * image
void SetGLCapability(GLenum capability, GLboolean state)
typedef GLuint(APIENTRYP PFNGLCREATEPROGRAMPROC)(void)
static int GetNumberOfScalarComponents(vtkInformation *meta_data)
GLuint TextureFromImage(vtkImageData *image, vtkVector2f &texCoords)
bool IsKeyInCache(const Key &key) const
vtkSmartPointer< vtkTexture > Texture
typedef GLboolean(APIENTRYP PFNGLISQUERYPROC)(GLuint id)
static vtkSmartPointer< T > New()
CacheElement(const Key &key, const CacheData &cacheData)
void SetInputData(vtkDataObject *)
void ReleaseGraphicsResources(vtkWindow *window)
vtkSmartPointer< vtkImageData > ImageData
bool operator==(const TextPropertyKey &other) const
float * TexCoords(float *f, int n)
TextPropertyKey< vtkStdString > UTF8TextPropertyKey
window superclass for vtkRenderWindow
virtual int * GetDimensions()
static int GetScalarType(vtkInformation *meta_data)
topologically and geometrically regular array of data
vtkImageData * GetInput()
CacheData & GetCacheData(const Key &key)
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