-
Notifications
You must be signed in to change notification settings - Fork 0
Expand file tree
/
Copy pathvtkMultiTextureObjectHelper.cpp
More file actions
127 lines (103 loc) · 3.96 KB
/
vtkMultiTextureObjectHelper.cpp
File metadata and controls
127 lines (103 loc) · 3.96 KB
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
#include "vtkMultiTextureObjectHelper.h"
#include "vtk_glew.h"
#include "vtkObjectFactory.h"
#include "vtkNew.h"
#include "vtkOpenGLBufferObject.h"
#include "vtkOpenGLError.h"
#include "vtkOpenGLFramebufferObject.h"
#include "vtkOpenGLRenderWindow.h"
#include "vtkOpenGLResourceFreeCallback.h"
#include "vtkOpenGLShaderCache.h"
#include "vtkOpenGLState.h"
#include "vtkOpenGLTexture.h"
#include "vtkOpenGLVertexArrayObject.h"
#include "vtkPixelBufferObject.h"
#include "vtkRenderer.h"
#include "vtkShaderProgram.h"
#include "vtkOpenGLHelper.h"
#include <cassert>
void vtkMultiTextureObjectHelper::PrintSelf(ostream& os, vtkIndent indent)
{
Superclass::PrintSelf(os, indent);
}
vtkStandardNewMacro(vtkMultiTextureObjectHelper);
bool vtkMultiTextureObjectHelper::CreateSeq3DFromRaw(unsigned int width, unsigned int height, unsigned int depth,
int numComps, int dataType, void* data, int texUnit) {
assert(this->Context);
vtkOpenGLClearErrorMacro();
// Now, determine texture parameters using the arguments.
this->GetDataType(dataType);
this->GetInternalFormat(dataType, numComps, false);
this->GetFormat(dataType, numComps, false);
if (!this->InternalFormat || !this->Format || !this->Type)
{
vtkErrorMacro("Failed to determine texture parameters.");
return false;
}
this->Target = GL_TEXTURE_3D;
this->Components = numComps;
this->Width = width;
this->Height = height;
this->Depth = depth;
this->NumberOfDimensions = 3;
GLint texunit = texUnit;
this->Context->GetState()->vtkglActiveTexture(GL_TEXTURE0+texunit);
this->CreateSeqTexture(texUnit);
this->Bind();
// Source texture data from the PBO.
this->Context->GetState()->vtkglPixelStorei(GL_UNPACK_ALIGNMENT, 1);
glTexImage3D(this->Target, 0, this->InternalFormat, static_cast<GLsizei>(this->Width),
static_cast<GLsizei>(this->Height), static_cast<GLsizei>(this->Depth), 0, this->Format,
this->Type, static_cast<const GLvoid*>(data));
this->Deactivate();
return vtkOpenGLCheckErrors("Failed to allocate 3D texture.");
}
void vtkMultiTextureObjectHelper::CreateSeqTexture(int texUnit)
{
assert(this->Context);
this->ResourceCallback->RegisterGraphicsResources(this->Context);
// reuse the existing handle if we have one
if (!this->Handle)
{
GLuint tex = texUnit;
glGenTextures(1, &tex);
this->OwnHandle = true;
vtkOpenGLCheckErrorMacro("failed at glGenTextures");
this->Handle = tex;
#if defined(GL_TEXTURE_BUFFER)
if (this->Target && this->Target != GL_TEXTURE_BUFFER)
#else
if (this->Target)
#endif
{
glBindTexture(this->Target, this->Handle);
vtkOpenGLCheckErrorMacro("failed at glBindTexture");
// See: http://www.opengl.org/wiki/Common_Mistakes#Creating_a_complete_texture
// turn off mip map filter or set the base and max level correctly. here
// both are done.
#ifdef GL_TEXTURE_2D_MULTISAMPLE
if (this->Target != GL_TEXTURE_2D_MULTISAMPLE)
#endif
{
glTexParameteri(this->Target, GL_TEXTURE_MIN_FILTER,
this->GetMinificationFilterMode(this->MinificationFilter));
glTexParameteri(this->Target, GL_TEXTURE_MAG_FILTER,
this->GetMagnificationFilterMode(this->MagnificationFilter));
glTexParameteri(this->Target, GL_TEXTURE_WRAP_S, this->GetWrapSMode(this->WrapS));
glTexParameteri(this->Target, GL_TEXTURE_WRAP_T, this->GetWrapTMode(this->WrapT));
#if defined(GL_TEXTURE_3D)
if (this->Target == GL_TEXTURE_3D)
{
glTexParameteri(this->Target, GL_TEXTURE_WRAP_R, this->GetWrapRMode(this->WrapR));
}
#endif
}
if (this->Target == GL_TEXTURE_2D) // maybe expand later on
{
glTexParameteri(this->Target, GL_TEXTURE_BASE_LEVEL, this->BaseLevel);
glTexParameteri(this->Target, GL_TEXTURE_MAX_LEVEL, this->MaxLevel);
}
glBindTexture(this->Target, 0);
}
}
}