File: vtkOpenGLDisplayListPainter.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 (195 lines) | stat: -rw-r--r-- 5,896 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
/*=========================================================================

  Program:   Visualization Toolkit
  Module:    vtkOpenGLDisplayListPainter.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 "vtkOpenGLDisplayListPainter.h"

#include "vtkPolyData.h"
#include "vtkInformation.h"
#include "vtkObjectFactory.h"
#include "vtkProperty.h"
#include "vtkRenderer.h"
#include "vtkRenderWindow.h"
#include "vtkTimerLog.h"

#include "vtkOpenGL.h"
#include "vtkOpenGLError.h"

#include <map>

vtkStandardNewMacro(vtkOpenGLDisplayListPainter);

class vtkOpenGLDisplayListPainter::vtkInternals
{
public:
  typedef std::map<unsigned long, GLuint> DisplayListMapType;
  DisplayListMapType DisplayListMap;

  // Refers to the build time of the first display list.
  vtkTimeStamp BuildTime;

  void ReleaseAllLists()
    {
    vtkOpenGLClearErrorMacro();
    DisplayListMapType::iterator iter;
    for (iter = this->DisplayListMap.begin(); iter != this->DisplayListMap.end();
      iter++)
      {
      glDeleteLists(iter->second, 1);
      }
    this->DisplayListMap.clear();
    vtkOpenGLStaticCheckErrorMacro("failed after ReleaseAllLists");
    }

  void ReleaseList(unsigned long key)
    {
    vtkOpenGLClearErrorMacro();
    DisplayListMapType::iterator iter = this->DisplayListMap.find(key);
    if (iter != this->DisplayListMap.end())
      {
      glDeleteLists(iter->second, 1);
      this->DisplayListMap.erase(iter);
      }
    vtkOpenGLStaticCheckErrorMacro("failed after ReleaseList");
    }

  void UpdateBuildTime()
    {
    if (this->DisplayListMap.size() == 1)
      {
      this->BuildTime.Modified();
      }
    }
};

//-----------------------------------------------------------------------------
vtkOpenGLDisplayListPainter::vtkOpenGLDisplayListPainter()
{
  this->Internals = new vtkInternals();
}

//-----------------------------------------------------------------------------
vtkOpenGLDisplayListPainter::~vtkOpenGLDisplayListPainter()
{
  if (this->LastWindow)
    {
    this->ReleaseGraphicsResources(this->LastWindow);
    }
  delete this->Internals;
  this->Internals = 0;
}

//-----------------------------------------------------------------------------
void vtkOpenGLDisplayListPainter::ReleaseGraphicsResources(vtkWindow* win)
{
  if (win && win->GetMapped())
    {
    win->MakeCurrent();
    this->Internals->ReleaseAllLists();
    }
  this->Internals->DisplayListMap.clear();
  this->Superclass::ReleaseGraphicsResources(win);
  this->LastWindow = NULL;
}

//-----------------------------------------------------------------------------
void vtkOpenGLDisplayListPainter::RenderInternal(vtkRenderer *renderer,
                                                 vtkActor *actor,
                                                 unsigned long typeflags,
                                                 bool forceCompileOnly)
{
  vtkOpenGLClearErrorMacro();

  // if active render window has changed, then release the old display lists on
  // the old window, if the old window is still valid.
  if (this->LastWindow &&
    (renderer->GetRenderWindow() != this->LastWindow.GetPointer()))
    {
    this->ReleaseGraphicsResources(this->LastWindow);
    renderer->GetRenderWindow()->MakeCurrent();
    }

  if (this->ImmediateModeRendering)
    {
    // don't use display lists at all.
    if (!forceCompileOnly)
      {
      this->Superclass::RenderInternal(renderer, actor, typeflags,
        forceCompileOnly);
      }
    return;
    }

  this->TimeToDraw = 0.0;

  vtkDataObject* input = this->GetInput();
  // if something has changed regenrate display lists.

  // First check for the cases where all display lists (irrespective of
  // typeflags are obsolete.
  if (
    // the painter has changed.
    this->GetMTime() > this->Internals->BuildTime ||
    // Since input changed
    input->GetMTime() > this->Internals->BuildTime  ||
    // actor's properties were modified
    actor->GetProperty()->GetMTime() > this->Internals->BuildTime ||
    // mapper information was modified
    this->Information->GetMTime() > this->Internals->BuildTime)
    {
    this->Internals->ReleaseAllLists();
    this->LastWindow = 0;
    }

  vtkInternals::DisplayListMapType::iterator iter =
    this->Internals->DisplayListMap.find(typeflags);
  if (iter == this->Internals->DisplayListMap.end())
    {
    GLuint list = glGenLists(1);

    glNewList(list, GL_COMPILE);
    // generate the display list.
    this->Superclass::RenderInternal(renderer, actor, typeflags,
                                     forceCompileOnly);
    glEndList();

    this->Internals->DisplayListMap[typeflags] = list;
    this->Internals->UpdateBuildTime();

    this->LastWindow = renderer->GetRenderWindow();
    iter = this->Internals->DisplayListMap.find(typeflags);
    }

  if (!forceCompileOnly)
    {
    // Time the actual drawing.
    this->Timer->StartTimer();
    // render the display list.
    // if nothing has changed we use an old display list else
    // we use the newly generated list.
    glCallList(iter->second);
    // glFinish(); // To compute time correctly, we need to wait
    // till OpenGL finishes.
    this->Timer->StopTimer();
    this->TimeToDraw += this->Timer->GetElapsedTime();
    }

  vtkOpenGLCheckErrorMacro("failed after RenderInternal");
}

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