File: vtkShader2Collection.cxx

package info (click to toggle)
vtk6 6.3.0%2Bdfsg2-8.1
  • links: PTS, VCS
  • area: main
  • in suites: bullseye
  • size: 118,972 kB
  • sloc: cpp: 1,442,790; ansic: 113,395; python: 72,383; tcl: 46,998; xml: 8,119; yacc: 4,525; java: 4,239; perl: 3,108; lex: 1,694; sh: 1,093; asm: 154; makefile: 68; objc: 17
file content (232 lines) | stat: -rw-r--r-- 7,243 bytes parent folder | download | duplicates (7)
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
65
66
67
68
69
70
71
72
73
74
75
76
77
78
79
80
81
82
83
84
85
86
87
88
89
90
91
92
93
94
95
96
97
98
99
100
101
102
103
104
105
106
107
108
109
110
111
112
113
114
115
116
117
118
119
120
121
122
123
124
125
126
127
128
129
130
131
132
133
134
135
136
137
138
139
140
141
142
143
144
145
146
147
148
149
150
151
152
153
154
155
156
157
158
159
160
161
162
163
164
165
166
167
168
169
170
171
172
173
174
175
176
177
178
179
180
181
182
183
184
185
186
187
188
189
190
191
192
193
194
195
196
197
198
199
200
201
202
203
204
205
206
207
208
209
210
211
212
213
214
215
216
217
218
219
220
221
222
223
224
225
226
227
228
229
230
231
232
/*=========================================================================

  Program:   Visualization Toolkit
  Module:    vtkShader2Collection.cxx

  Copyright (c) Ken Martin, Will Schroeder, Bill Lorensen
  All rights reserved.
  See Copyright.txt or http://www.kitware.com/Copyright.htm for details.

     This software is distributed WITHOUT ANY WARRANTY; without even
     the implied warranty of MERCHANTABILITY or FITNESS FOR A PARTICULAR
     PURPOSE.  See the above copyright notice for more information.

=========================================================================*/
#include "vtkShader2Collection.h"
#include "vtkObjectFactory.h"
#include "vtkShader2.h"
#include <cassert>

vtkStandardNewMacro(vtkShader2Collection);

// ----------------------------------------------------------------------------
// Description:
// Reentrant safe way to get an object in a collection. Just pass the
// same cookie back and forth.
vtkShader2 *vtkShader2Collection::GetNextShader(
vtkCollectionSimpleIterator &cookie)
{
  return static_cast<vtkShader2 *>(this->GetNextItemAsObject(cookie));
}

// ----------------------------------------------------------------------------
vtkShader2Collection::vtkShader2Collection()
{
}

// ----------------------------------------------------------------------------
vtkShader2Collection::~vtkShader2Collection()
{
}

// ----------------------------------------------------------------------------
unsigned long vtkShader2Collection::GetMTime()
{
  unsigned long result = this->Superclass::GetMTime();
  this->InitTraversal();
  vtkShader2 *s = this->GetNextShader();
  while (s!=0)
    {
    unsigned long time = s->GetMTime();
    if (time > result)
      {
      result = time;
      }
    s = this->GetNextShader();
    }
  return result;
}

// ----------------------------------------------------------------------------
// hide the standard AddItem from the user and the compiler.
void vtkShader2Collection::AddItem(vtkObject *o)
{
  this->vtkCollection::AddItem(o);
}

// ----------------------------------------------------------------------------
void vtkShader2Collection::AddItem(vtkShader2 *s)
{
  this->vtkCollection::AddItem(s);
}

// ----------------------------------------------------------------------------
vtkShader2 *vtkShader2Collection::GetNextShader()
{
  return static_cast<vtkShader2 *>(this->GetNextItemAsObject());
}

// ----------------------------------------------------------------------------
vtkShader2 *vtkShader2Collection::GetLastShader()
{
  return (this->Bottom) ?
    static_cast<vtkShader2 *>(this->Bottom->Item) : NULL;
}

// ----------------------------------------------------------------------------
// Description:
// Add the elements of `other' to the end of `this'.
// \pre other_exists: other!=0
// \pre not_self: other!=this
// \post added: this->GetNumberOfItems()=old this->GetNumberOfItems()+other->GetNumberOfItems()
void vtkShader2Collection::AddCollection(vtkShader2Collection *other)
{
  assert("pre: other_exists" && other != 0);
  assert("pre: not_self" && other != this);

  other->InitTraversal();
  vtkShader2 *s = other->GetNextShader();
  while (s)
    {
    this->AddItem(s);
    s = other->GetNextShader();
    }
}

// ----------------------------------------------------------------------------
// Description:
// Remove the elements of `other' from `this'. It assumes that `this' already
// has all the elements of `other' added contiguously.
// \pre other_exists: other!=0
// \pre not_self: other!=this
// \post removed: this->GetNumberOfItems()=old this->GetNumberOfItems()-other->GetNumberOfItems()
void vtkShader2Collection::RemoveCollection(vtkShader2Collection *other)
{
  assert("pre: other_exists" && other != 0);
  assert("pre: not_self" && other != this);

  other->InitTraversal();
  vtkShader2 *s = other->GetNextShader();
  if (s)
    {
    // `other' is not an empty list.
    int loc = this->IsItemPresent(s);
    if (loc == 0)
      {
      vtkErrorMacro("try to remove the elements of vtkShader2Collection " << other << " but they don't exist in vtkShader2Collection" << this);
      return;
      }
    int size = other->GetNumberOfItems();
    --loc;
    int i = 0;
    while (i < size)
      {
      this->RemoveItem(loc);
      ++i;
      }
    }
}

// ----------------------------------------------------------------------------
// Description:
// Tells if at least one of the shaders is on given type.
bool vtkShader2Collection::HasShadersOfType(int t)
{
  bool result = false;

  this->InitTraversal();
  vtkShader2 *s = this->GetNextShader();
  while (!result && s)
    {
    result = (s->GetType() == t);
    s = this->GetNextShader();
    }

  return result;
}
// ----------------------------------------------------------------------------
// Description:
// Tells if at least one of the shaders is a vertex shader.
// If yes, it means the vertex processing of the fixed-pipeline is bypassed.
// If no, it means the vertex processing of the fixed-pipeline is used.
bool vtkShader2Collection::HasVertexShaders()
{
  return HasShadersOfType(VTK_SHADER_TYPE_VERTEX);
}

// ----------------------------------------------------------------------------
// Description:
// Tells if at least one of the shaders is a tessellation control shader.
bool vtkShader2Collection::HasTessellationControlShaders()
{
  return HasShadersOfType(VTK_SHADER_TYPE_TESSELLATION_CONTROL);
}

// ----------------------------------------------------------------------------
// Description:
// Tells if at least one of the shaders is a tessellation evaluation shader.
bool vtkShader2Collection::HasTessellationEvaluationShaders()
{
  return HasShadersOfType(VTK_SHADER_TYPE_TESSELLATION_EVALUATION);
}

// ----------------------------------------------------------------------------
// Description:
// Tells if at least one of the shaders is a geometry shader.
bool vtkShader2Collection::HasGeometryShaders()
{
  return HasShadersOfType(VTK_SHADER_TYPE_GEOMETRY);
}

// ----------------------------------------------------------------------------
// Description:
// Tells if at least one of the shaders is a fragment shader.
// If yes, it means the fragment processing of the fixed-pipeline is
// bypassed.
// If no, it means the fragment processing of the fixed-pipeline is used.
bool vtkShader2Collection::HasFragmentShaders()
{
  return HasShadersOfType(VTK_SHADER_TYPE_FRAGMENT);
}

// ----------------------------------------------------------------------------
// Description:
// Release OpenGL resources (shader id of each item).
void vtkShader2Collection::ReleaseGraphicsResources()
{
  this->InitTraversal();
  vtkShader2 *s = this->GetNextShader();
  while (s)
    {
    s->ReleaseGraphicsResources();
    s = this->GetNextShader();
    }
}

// ----------------------------------------------------------------------------
void vtkShader2Collection::PrintSelf(ostream& os, vtkIndent indent)
{
  this->Superclass::PrintSelf(os, indent);

  int i = 0;
  int c = this->GetNumberOfItems();
  this->InitTraversal();
  vtkShader2 *s = this->GetNextShader();
  while (s)
    {
    os << indent << "shader #" << i << "/" << c <<endl;
    s->PrintSelf(os, indent.GetNextIndent());
    s = this->GetNextShader();
    ++i;
    }
}