Index: vtkOpenGLTexture.cxx
===================================================================
RCS file: /cvsroot/VTK/VTK/Rendering/vtkOpenGLTexture.cxx,v
retrieving revision 1.66
diff -u -u -r1.66 vtkOpenGLTexture.cxx
--- vtkOpenGLTexture.cxx	14 Feb 2008 20:02:03 -0000	1.66
+++ vtkOpenGLTexture.cxx	3 Oct 2008 11:49:02 -0000
@@ -21,7 +21,7 @@
 #include "vtkPointData.h"
 #include "vtkRenderWindow.h"
 #include "vtkOpenGLRenderWindow.h"
-
+#include "vtkOpenGLExtensionManager.h"
 #include "vtkOpenGL.h"
 #include "vtkgl.h" // vtkgl namespace
 
@@ -37,6 +37,7 @@
 {
   this->Index = 0;
   this->RenderWindow = 0;
+  this->AllowsNonPowerOfTwoTextures = -1; // don't know until first render
 }
 
 vtkOpenGLTexture::~vtkOpenGLTexture()
@@ -168,28 +169,53 @@
         }
       }
 
-    // xsize and ysize must be a power of 2 in OpenGL
-    xs = static_cast<unsigned short>(xsize);
-    ys = static_cast<unsigned short>(ysize);
-    while (!(xs & 0x01))
+    // free any old display lists (from the old context)
+    if (this->RenderWindow)
       {
-      xs = xs >> 1;
+      this->ReleaseGraphicsResources(this->RenderWindow);
       }
-    while (!(ys & 0x01))
+    
+     this->RenderWindow = ren->GetRenderWindow();
+     
+    // make the new context current before we mess with opengl
+    this->RenderWindow->MakeCurrent();
+
+    if (this->AllowsNonPowerOfTwoTextures == -1)
       {
-      ys = ys >> 1;
+      // Check to see if this OpenGL implementation 
+      // allows for non-power of two textures
+      vtkOpenGLExtensionManager *extensions = vtkOpenGLExtensionManager::New();
+      extensions->SetRenderWindow(this->RenderWindow);
+      this->AllowsNonPowerOfTwoTextures = 
+        extensions->ExtensionSupported("GL_ARB_texture_non_power_of_two");
+      extensions->Delete();
       }
 
-    // -- decide whether the texture needs to be resampled --
     int resampleNeeded = 0;
-    // if not a power of two then resampling is required
-    if ((xs > 1)||(ys > 1))
+    if (this->AllowsNonPowerOfTwoTextures != 1) 
       {
-      resampleNeeded = 1;
+      // xsize and ysize must be a power of 2 in OpenGL without the supported extension
+      xs = (unsigned short)xsize;
+      ys = (unsigned short)ysize;
+      while (!(xs & 0x01))
+        {
+        xs = xs >> 1;
+        }
+      while (!(ys & 0x01))
+        {
+        ys = ys >> 1;
+        }
+
+      // -- decide whether the texture needs to be resampled --
+      // if not a power of two then resampling is required
+      if ((xs > 1)||(ys > 1))
+        {
+        resampleNeeded = 1;
+        }
       }
     GLint maxDimGL;
     glGetIntegerv(GL_MAX_TEXTURE_SIZE,&maxDimGL);
-    // if larger than permitted by the graphics library then must resample
+    // if larger than permitted by the graphics library then must resample anyway
     if ( xsize > maxDimGL || ysize > maxDimGL )
       {
       vtkDebugMacro( "Texture too big for gl, maximum is " << maxDimGL);
@@ -235,16 +261,6 @@
         }
       }
 
-    // free any old display lists (from the old context)
-    if (this->RenderWindow)
-      {
-      this->ReleaseGraphicsResources(this->RenderWindow);
-      }
-    
-     this->RenderWindow = ren->GetRenderWindow();
-     
-    // make the new context current before we mess with opengl
-    this->RenderWindow->MakeCurrent();
  
     // define a display list for this texture
     // get a unique display list id
@@ -466,4 +482,5 @@
 {
   this->Superclass::PrintSelf(os,indent);
   os << indent << "Index: " << this->Index << endl;
+  os << indent << "AllowsNonPowerOfTwoTexture: " << this->AllowsNonPowerOfTwoTextures;
 }
Index: vtkOpenGLTexture.h
===================================================================
RCS file: /cvsroot/VTK/VTK/Rendering/vtkOpenGLTexture.h,v
retrieving revision 1.26
diff -u -u -r1.26 vtkOpenGLTexture.h
--- vtkOpenGLTexture.h	26 Dec 2007 16:14:28 -0000	1.26
+++ vtkOpenGLTexture.h	3 Oct 2008 11:49:02 -0000
@@ -62,6 +62,7 @@
 
   vtkTimeStamp   LoadTime;
   long          Index;
+  int           AllowsNonPowerOfTwoTextures; // -1=unknown, 0=no, 1=yes.
   vtkWeakPointer<vtkRenderWindow> RenderWindow;   // RenderWindow used for previous render
 private:
   vtkOpenGLTexture(const vtkOpenGLTexture&);  // Not implemented.
