Commit 919018ce authored by Aashish Chaudhary's avatar Aashish Chaudhary

Added ability to set texture attributes directly

Change-Id: I73c63f7d6c692152ad1a700c13472a9c85564b30
parent 0eb64395
......@@ -200,6 +200,7 @@ vtkTextureObject::vtkTextureObject()
this->NumberOfDimensions = 0;
this->Target = 0;
this->Format = 0;
this->InternalFormat = 0;
this->Type = 0;
this->Components = 0;
this->Width = 0;
......@@ -364,6 +365,7 @@ void vtkTextureObject::DestroyTexture()
this->NumberOfDimensions = 0;
this->Target =0;
this->Format = 0;
this->InternalFormat = 0;
this->Type = 0;
this->Components = 0;
this->Width = this->Height = this->Depth = 0;
......@@ -955,6 +957,16 @@ unsigned int vtkTextureObject::GetInternalFormat(int vtktype, int numComps,
#endif
//----------------------------------------------------------------------------
void vtkTextureObject::SetInternalFormat(unsigned int glInternalFormat)
{
if (this->InternalFormat != glInternalFormat)
{
this->InternalFormat = glInternalFormat;
this->Modified();
}
}
//----------------------------------------------------------------------------
unsigned int vtkTextureObject::GetFormat(int vtktype, int numComps,
bool shaderSupportsTextureInt)
......@@ -1000,10 +1012,20 @@ unsigned int vtkTextureObject::GetFormat(int vtktype, int numComps,
return 0;
}
//----------------------------------------------------------------------------
void vtkTextureObject::SetFormat(unsigned int glFormat)
{
if (this->Format != glFormat)
{
this->Format = glFormat;
this->Modified();
}
}
//----------------------------------------------------------------------------
static GLenum vtkGetType(int vtk_scalar_type)
{
// DON'T DEAL with VTK_CHAR as this is platform dependent.
switch (vtk_scalar_type)
{
case VTK_SIGNED_CHAR:
......@@ -1067,6 +1089,16 @@ int vtkTextureObject::GetDataType()
return ::vtkGetVTKType(this->Type);
}
//----------------------------------------------------------------------------
void vtkTextureObject::SetDataType(unsigned int glType)
{
if (this->Type != glType)
{
this->Type = glType;
this->Modified();
}
}
//----------------------------------------------------------------------------
unsigned int vtkTextureObject::GetDepthTextureModeFormat(int vtktype)
{
......@@ -1548,21 +1580,29 @@ bool vtkTextureObject::Create3DFromRaw(unsigned int width, unsigned int height,
assert(this->Context);
// Now, detemine texture parameters using the arguments.
GLenum type = ::vtkGetType(dataType);
GLenum internalFormat
= this->GetInternalFormat(dataType, numComps, false);
GLenum format
= this->GetFormat(dataType, numComps, false);
if (!this->Type)
{
this->Type = ::vtkGetType(dataType);
}
if (!internalFormat || !format || !type)
if (!this->InternalFormat)
{
this->InternalFormat
= this->GetInternalFormat(dataType, numComps, false);
}
if (!this->Format)
{
this->Format = this->GetFormat(dataType, numComps, false);
}
if (!this->InternalFormat || !this->Format || !this->Type)
{
vtkErrorMacro("Failed to detemine texture parameters.");
return false;
}
this->Target = GL_TEXTURE_3D;
this->Format = format;
this->Type = type;
this->Components = numComps;
this->Width = width;
this->Height = height;
......@@ -1578,7 +1618,7 @@ bool vtkTextureObject::Create3DFromRaw(unsigned int width, unsigned int height,
glTexImage3D(
this->Target,
0,
internalFormat,
this->InternalFormat,
static_cast<GLsizei>(this->Width),
static_cast<GLsizei>(this->Height),
static_cast<GLsizei>(this->Depth),
......
......@@ -310,11 +310,16 @@ public:
// Description:
// Get the data type for the texture as a vtk type int i.e. VTK_INT etc.
int GetDataType();
void SetDataType(unsigned int glType);
unsigned int GetInternalFormat(int vtktype, int numComps,
bool shaderSupportsTextureInt);
void SetInternalFormat(unsigned int glInternalFormat);
unsigned int GetFormat(int vtktype, int numComps,
bool shaderSupportsTextureInt);
void SetFormat(unsigned int glFormat);
unsigned int GetDepthTextureModeFormat(int vtktype);
unsigned int GetMinificationFilterMode(int vtktype);
unsigned int GetMagnificationFilterMode(int vtktype);
......@@ -589,6 +594,7 @@ protected:
unsigned int Target; // GLenum
unsigned int Format; // GLenum
unsigned int InternalFormat; // GLenum
unsigned int Type; // GLenum
int Components;
......
......@@ -590,6 +590,7 @@ bool vtkOpenGLGPUVolumeRayCastMapper::vtkInternal::LoadVolume(vtkRenderer* ren,
this->Scale = scale;
this->Bias = shift * this->Scale;
// Update texture size
imageData->GetExtent(this->Extents);
int i = 0;
......@@ -613,6 +614,9 @@ bool vtkOpenGLGPUVolumeRayCastMapper::vtkInternal::LoadVolume(vtkRenderer* ren,
// glPixelTransferf(GL_RED_SCALE,static_cast<GLfloat>(this->Scale));
// glPixelTransferf(GL_RED_BIAS,static_cast<GLfloat>(this->Bias));
this->VolumeTextureObject->SetDataType(type);
this->VolumeTextureObject->SetFormat(format);
this->VolumeTextureObject->SetInternalFormat(internalFormat);
this->VolumeTextureObject->Create3DFromRaw(
this->TextureSize[0],
this->TextureSize[1],
......@@ -646,7 +650,6 @@ bool vtkOpenGLGPUVolumeRayCastMapper::vtkInternal::LoadVolume(vtkRenderer* ren,
// right dimensions). Here we are assuming that
// GL_ARB_texture_non_power_of_two is available
glPixelStorei( GL_UNPACK_ALIGNMENT, 1 );
glTexImage3D(GL_TEXTURE_3D, 0, internalFormat,
this->TextureSize[0], this->TextureSize[1],
this->TextureSize[2], 0, format, type, 0);
......
Markdown is supported
0% or .
You are about to add 0 people to the discussion. Proceed with caution.
Finish editing this message first!
Please register or to comment