COPASI API  4.16.103
Public Member Functions | Public Attributes | List of all members
CLLineStippleTexture Struct Reference

#include <utility_classes.h>

Public Member Functions

 CLLineStippleTexture (const std::vector< unsigned int > &dasharray)
 
 ~CLLineStippleTexture ()
 

Public Attributes

unsigned int mPatternLength
 
unsigned int mTextureLength
 
GLuint mTextureName
 

Detailed Description

Definition at line 76 of file utility_classes.h.

Constructor & Destructor Documentation

CLLineStippleTexture::CLLineStippleTexture ( const std::vector< unsigned int > &  dasharray)

Definition at line 17 of file utility_classes.cpp.

References mPatternLength, mTextureLength, and mTextureName.

17  :
18  mPatternLength(0),
19  mTextureLength(0),
20  mTextureName(0)
21 {
22  if (!dasharray.empty())
23  {
24  std::vector<unsigned int>::const_iterator it = dasharray.begin(), endit = dasharray.end();
25 
26  while (it != endit)
27  {
28  this->mPatternLength += *it;
29  ++it;
30  }
31 
32  // we only need to create a texture if the pattern length is not 0
33  if (this->mPatternLength != 0)
34  {
35  // the texture size should be a multiple of 2
36  unsigned int exponent = (unsigned int)ceil(log((double)this->mPatternLength) / log(2.0));
37 
38  if (exponent <= 31)
39  {
40  this->mTextureLength = 1 << exponent;
41  // make sure the texture name is really free
42  this->mTextureName = 0;
43  GLint w = -1;
44  glTexImage1D(GL_PROXY_TEXTURE_1D, 0, GL_ALPHA, this->mTextureLength, 0, GL_ALPHA, GL_UNSIGNED_BYTE, NULL);
45  glGetTexLevelParameteriv(GL_PROXY_TEXTURE_1D, 0, GL_TEXTURE_WIDTH, &w);
46 
47  if (w != 0)
48  {
49  GLubyte* pTextureData = new GLubyte[this->mTextureLength];
50  // now we create the pattern
51  it = dasharray.begin();
52  unsigned int i;
53  bool gap = false;
54  unsigned int index = 0;
55 
56  while (it != endit)
57  {
58  for (i = 0; i < *it; ++i)
59  {
60  // if it is a gap, we write 0, otherwise we write 255
61  pTextureData[index] = gap ? 0 : 255;
62  ++index;
63  }
64 
65  gap = !gap;
66  ++it;
67  }
68 
69  // fill the rest of the texture with 255
70  while (index < this->mTextureLength)
71  {
72  pTextureData[index++] = 70;
73  }
74 
75  // now we load the texture data into OpenGL
76  glGenTextures(1, &this->mTextureName);
77  // make sure a new texture name has been created
78  assert(this->mTextureName != 0);
79  glBindTexture(GL_TEXTURE_1D, this->mTextureName);
80  glTexParameteri(GL_TEXTURE_1D, GL_TEXTURE_MIN_FILTER, GL_LINEAR);
81  glTexParameteri(GL_TEXTURE_1D, GL_TEXTURE_MAG_FILTER, GL_LINEAR);
82  glTexParameteri(GL_TEXTURE_1D, GL_TEXTURE_WRAP_S, GL_REPEAT);
83  glTexEnvi(GL_TEXTURE_ENV, GL_TEXTURE_ENV_MODE, GL_MODULATE);
84  glTexImage1D(GL_TEXTURE_1D, 0, GL_ALPHA, this->mTextureLength, 0, GL_ALPHA, GL_UNSIGNED_BYTE, pTextureData);
85  // delete the memory
86  delete[] pTextureData;
87  }
88  else
89  {
90  std::cerr << "Line stipple texture of this size is not supported by the current OpenGL implementation." << std::endl;
91  }
92  }
93  else
94  {
95  std::cerr << "texture to large." << std::endl;
96  }
97  }
98  }
99 }
unsigned int mPatternLength
unsigned int mTextureLength
CLLineStippleTexture::~CLLineStippleTexture ( )

Definition at line 101 of file utility_classes.cpp.

References mTextureName.

102 {
103  if (this->mTextureName != 0)
104  {
105  glDeleteTextures(1, &this->mTextureName);
106  }
107 }

Member Data Documentation

unsigned int CLLineStippleTexture::mPatternLength

Definition at line 78 of file utility_classes.h.

Referenced by CLLineStippleTexture(), and CLLayoutRenderer::draw_line().

unsigned int CLLineStippleTexture::mTextureLength

Definition at line 79 of file utility_classes.h.

Referenced by CLLineStippleTexture(), and CLLayoutRenderer::draw_line().

GLuint CLLineStippleTexture::mTextureName

The documentation for this struct was generated from the following files: