-
Notifications
You must be signed in to change notification settings - Fork 1
/
Copy pathvtkOpenGLMultiChannelCamera.cxx
185 lines (157 loc) · 5.5 KB
/
vtkOpenGLMultiChannelCamera.cxx
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
/*=========================================================================
Name: vtkOpenGLMultiChannelCamera.cxx
Author: David Borland, The Renaissance Computing Institute (RENCI)
Copyright: The Renaissance Computing Institute (RENCI)
License: Licensed under the RENCI Open Source Software License v. 1.0.
See included License.txt or
http://www.renci.org/resources/open-source-software-license
for details.
=========================================================================*/
#include "vtkOpenGLMultiChannelCamera.h"
#include "vtkgluPickMatrix.h"
#include "vtkMatrix4x4.h"
#include "vtkObjectFactory.h"
#include "vtkOpenGLRenderer.h"
#include "vtkOpenGLRenderWindow.h"
#include "vtkOpenGL.h"
#ifndef VTK_IMPLEMENT_MESA_CXX
vtkCxxRevisionMacro(vtkOpenGLMultiChannelCamera, "$Revision: 1.0 $");
vtkStandardNewMacro(vtkOpenGLMultiChannelCamera);
#endif
//----------------------------------------------------------------------------
vtkOpenGLMultiChannelCamera::vtkOpenGLMultiChannelCamera()
{
this->AspectRatio = 1;
this->UseAspectRatio = 0;
}
//----------------------------------------------------------------------------
vtkOpenGLMultiChannelCamera::~vtkOpenGLMultiChannelCamera()
{
}
//----------------------------------------------------------------------------
void vtkOpenGLMultiChannelCamera::Render(vtkRenderer *ren)
{
if (!this->UseAspectRatio)
{
// Render as usual
vtkOpenGLCamera::Render(ren);
return;
}
// Render with the camera's aspect ratio,
// borrowing heavily from vtkOpenGLCamera::Render()
int lowerLeft[2];
int usize, vsize;
vtkMatrix4x4 *matrix = vtkMatrix4x4::New();
vtkOpenGLRenderWindow *win = vtkOpenGLRenderWindow::SafeDownCast(ren->GetRenderWindow());
// Find out if we should stereo render
this->Stereo = (ren->GetRenderWindow())->GetStereoRender();
ren->GetTiledSizeAndOrigin(&usize,&vsize,lowerLeft,lowerLeft+1);
// If were on a stereo renderer draw to special parts of screen
if (this->Stereo)
{
switch ((ren->GetRenderWindow())->GetStereoType())
{
case VTK_STEREO_CRYSTAL_EYES:
if (this->LeftEye)
{
if(ren->GetRenderWindow()->GetDoubleBuffer())
{
glDrawBuffer(static_cast<GLenum>(win->GetBackLeftBuffer()));
glReadBuffer(static_cast<GLenum>(win->GetBackLeftBuffer()));
}
else
{
glDrawBuffer(static_cast<GLenum>(win->GetFrontLeftBuffer()));
glReadBuffer(static_cast<GLenum>(win->GetFrontLeftBuffer()));
}
}
else
{
if(ren->GetRenderWindow()->GetDoubleBuffer())
{
glDrawBuffer(static_cast<GLenum>(win->GetBackRightBuffer()));
glReadBuffer(static_cast<GLenum>(win->GetBackRightBuffer()));
}
else
{
glDrawBuffer(static_cast<GLenum>(win->GetFrontRightBuffer()));
glReadBuffer(static_cast<GLenum>(win->GetFrontRightBuffer()));
}
}
break;
case VTK_STEREO_LEFT:
this->LeftEye = 1;
break;
case VTK_STEREO_RIGHT:
this->LeftEye = 0;
break;
default:
break;
}
}
else
{
if (ren->GetRenderWindow()->GetDoubleBuffer())
{
glDrawBuffer(static_cast<GLenum>(win->GetBackBuffer()));
// Reading back buffer means back left. see OpenGL spec.
// because one can write to two buffers at a time but can only read from
// one buffer at a time.
glReadBuffer(static_cast<GLenum>(win->GetBackBuffer()));
}
else
{
glDrawBuffer(static_cast<GLenum>(win->GetFrontBuffer()));
// Reading front buffer means front left. see OpenGL spec.
// because one can write to two buffers at a time but can only read from
// one buffer at a time.
glReadBuffer(static_cast<GLenum>(win->GetFrontBuffer()));
}
}
glViewport(lowerLeft[0], lowerLeft[1], usize, vsize);
glEnable(GL_SCISSOR_TEST);
glScissor(lowerLeft[0], lowerLeft[1], usize, vsize);
glMatrixMode(GL_PROJECTION);
if(usize && vsize)
{
// Use the user-supplied aspect ratio
matrix->DeepCopy(this->GetProjectionTransformMatrix(
this->AspectRatio, -1, 1));
matrix->Transpose();
}
if(ren->GetIsPicking())
{
int size[2]; size[0] = usize; size[1] = vsize;
glLoadIdentity();
vtkgluPickMatrix(ren->GetPickX(), ren->GetPickY(),
ren->GetPickWidth(), ren->GetPickHeight(),
lowerLeft, size);
glMultMatrixd(matrix->Element[0]);
}
else
{
// Insert camera view transformation
glLoadMatrixd(matrix->Element[0]);
}
// Push the model view matrix onto the stack, make sure we
// adjust the mode first
glMatrixMode(GL_MODELVIEW);
glPushMatrix();
matrix->DeepCopy(this->GetViewTransformMatrix());
matrix->Transpose();
// Insert camera view transformation
glMultMatrixd(matrix->Element[0]);
if ((ren->GetRenderWindow())->GetErase() && ren->GetErase()
&& !ren->GetIsPicking())
{
ren->Clear();
}
matrix->Delete();
}
//----------------------------------------------------------------------------
void vtkOpenGLMultiChannelCamera::PrintSelf(ostream& os, vtkIndent indent)
{
this->Superclass::PrintSelf(os,indent);
os << indent << "Aspect Ratio: " << this->AspectRatio << "\n";
os << indent << "Use Aspect Ratio: " << this->UseAspectRatio << "\n";
}