Commit 6e68915e authored by Aashish Chaudhary's avatar Aashish Chaudhary

Added ability to query maximum texture size (1D/2D/3D)

parent 693fd6ed
Pipeline #1230 passed with stage
......@@ -18,6 +18,7 @@ vtk_add_test_cxx(${vtk-module}CxxTests tests
TestSobelGradientMagnitudePass.cxx
TestEDLPass.cxx
TestCoincident.cxx
TestMaximumTextureSize.cxx
)
vtk_test_cxx_executable(${vtk-module}CxxTests tests RENDERING_FACTORY)
/*=========================================================================
Program: Visualization Toolkit
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.
=========================================================================*/
// This test queries the maximum texture size for 1D/2D/3D textures.
//
// The command line arguments are:
// -I => run in interactive mode; unless this is used, the program will
// not allow interaction and exit
#include <vtkTestUtilities.h>
#include <vtkNew.h>
#include <vtkOpenGLRenderWindow.h>
#include <vtkRenderWindowInteractor.h>
#include <vtkRenderWindow.h>
#include <vtkRenderer.h>
#include <vtkTextureObject.h>
int TestMaximumTextureSize(int argc, char* argv[])
{
vtkNew<vtkRenderWindowInteractor> iren;
vtkNew<vtkRenderWindow> renWin;
renWin->SetMultiSamples(0);
renWin->SetAlphaBitPlanes(1);
iren->SetRenderWindow(renWin.Get());
vtkNew<vtkRenderer> renderer;
renWin->AddRenderer(renderer.Get());
renWin->SetSize(500,500);
renWin->Render();
vtkOpenGLRenderWindow* glContext =
vtkOpenGLRenderWindow::SafeDownCast(renWin.GetPointer());
if (glContext)
{
vtkNew<vtkTextureObject> textureObject;
int maxTextureSize1D =
textureObject->GetMaximumTextureSize1D(glContext);
int maxTextureSize2D =
textureObject->GetMaximumTextureSize1D(glContext);
int maxTextureSize3D =
textureObject->GetMaximumTextureSize1D(glContext);
if (maxTextureSize1D != -1 && maxTextureSize2D != -1 &&
maxTextureSize3D != -1)
{
return 0;
}
return 1;
}
return 0;
}
......@@ -215,6 +215,42 @@ static const char *DepthInternalFormatFilterAsString[6]=
};
*/
//----------------------------------------------------------------------------
class vtkTextureObject::vtkInternal
{
public:
// Constructor
//--------------------------------------------------------------------------
vtkInternal(vtkTextureObject* parent)
{
this->Parent = parent;
}
// Query maximum texture size
//--------------------------------------------------------------------------
int GetMaximumTextureSize(int param, vtkRenderWindow* context)
{
int maxSize = -1;
if (context and context->IsCurrent())
{
bool textureEnabled = glIsEnabled(param);
if (!textureEnabled)
{
glEnable(param);
}
glGetIntegerv(GL_MAX_TEXTURE_SIZE, &maxSize);
if (!textureEnabled)
{
glDisable(param);
}
}
return maxSize;
}
vtkTextureObject* Parent;
};
//----------------------------------------------------------------------------
vtkStandardNewMacro(vtkTextureObject);
......@@ -2035,6 +2071,24 @@ void vtkTextureObject::CopyFromFrameBuffer(int srcXmin,
vtkOpenGLCheckErrorMacro("failed at glCopyTexImage2D " << this->Format);
}
//----------------------------------------------------------------------------
int vtkTextureObject::GetMaximumTextureSize1D(vtkOpenGLRenderWindow* context)
{
return this->Impl->GetMaximumTextureSize(GL_TEXTURE_1D, context);
}
//----------------------------------------------------------------------------
int vtkTextureObject::GetMaximumTextureSize2D(vtkOpenGLRenderWindow* context)
{
return this->Impl->GetMaximumTextureSize(GL_TEXTURE_2D, context);
}
//----------------------------------------------------------------------------
int vtkTextureObject::GetMaximumTextureSize3D(vtkOpenGLRenderWindow* context)
{
return this->Impl->GetMaximumTextureSize(GL_TEXTURE_3D, context);
}
//----------------------------------------------------------------------------
void vtkTextureObject::PrintSelf(ostream& os, vtkIndent indent)
{
......
......@@ -528,6 +528,21 @@ public:
vtkGetMacro(GenerateMipmap,bool);
vtkSetMacro(GenerateMipmap,bool);
// Description:
// Query and return maximum 1D texture size supported by the OpenGL
// driver for a particular context.
int GetMaximumTextureSize1D(vtkOpenGLRenderWindow* context);
// Description:
// Query and return maximum 2D texture size supported by the OpenGL
// driver for a particular context.
int GetMaximumTextureSize2D(vtkOpenGLRenderWindow* context);
// Description:
// Query and return maximum 3D texture size supported by the OpenGL
// driver for a particular context.
int GetMaximumTextureSize3D(vtkOpenGLRenderWindow* context);
// Description:
// Returns if the context supports the required extensions. If flags
// for optional extenisons are set then the test fails when support
......@@ -590,8 +605,6 @@ public:
int width,
int height);
protected:
vtkTextureObject();
~vtkTextureObject();
......@@ -655,6 +668,9 @@ protected:
// for texturebuffers we hold on to the Buffer
vtkOpenGLBufferObject *BufferObject;
class vtkInternal;
vtkInternal* Impl;
private:
vtkTextureObject(const vtkTextureObject&); // Not implemented.
void operator=(const vtkTextureObject&); // Not implemented.
......
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