From 126a6d513d387ce3da31d559ce833706fafa0a4a Mon Sep 17 00:00:00 2001 From: Dan Lipsa Date: Wed, 7 Dec 2016 09:32:22 -0500 Subject: [PATCH] ENH: Add GenerateMipmap support to vtkGeometryRepresentation --- Rendering/OpenGL2/vtkOpenGLTexture.cxx | 1 + Rendering/OpenGL2/vtkTextureObject.cxx | 34 +++++++++++++++++++++++++--------- 2 files changed, 26 insertions(+), 9 deletions(-) diff --git a/Rendering/OpenGL2/vtkOpenGLTexture.cxx b/Rendering/OpenGL2/vtkOpenGLTexture.cxx index b8fa8aa..60dc860 100644 --- a/Rendering/OpenGL2/vtkOpenGLTexture.cxx +++ b/Rendering/OpenGL2/vtkOpenGLTexture.cxx @@ -258,6 +258,7 @@ void vtkOpenGLTexture::Load(vtkRenderer *ren) } else { + this->TextureObject->SetGenerateMipmap(true); this->TextureObject->Create2DFromRaw( xsize, ysize, bytesPerPixel, VTK_UNSIGNED_CHAR, resultData); } diff --git a/Rendering/OpenGL2/vtkTextureObject.cxx b/Rendering/OpenGL2/vtkTextureObject.cxx index 83a5ba1..f1532e9 100644 --- a/Rendering/OpenGL2/vtkTextureObject.cxx +++ b/Rendering/OpenGL2/vtkTextureObject.cxx @@ -1581,19 +1581,35 @@ bool vtkTextureObject::Create2DFromRaw(unsigned int width, unsigned int height, this->CreateTexture(); this->Bind(); + if (this->GenerateMipmap) + { + //this->SetMaxLevel(log2(std::max(this->Width, this->Height))); + //this->SetMinificationFilter(NearestMipmapNearest); + + glTexParameteri(this->Target, GL_TEXTURE_MIN_FILTER, + this->GetMinificationFilterMode(NearestMipmapNearest)); + glTexParameteri(this->Target, GL_TEXTURE_BASE_LEVEL, 0); + glTexParameteri(this->Target, GL_TEXTURE_MAX_LEVEL, log2(std::max(this->Width, this->Height))); + } + + // Source texture data from the PBO. glPixelStorei(GL_UNPACK_ALIGNMENT, 1); glTexImage2D( - this->Target, - 0, - this->InternalFormat, - static_cast(this->Width), - static_cast(this->Height), - 0, - this->Format, - this->Type, - static_cast(data)); + this->Target, + 0, + this->InternalFormat, + static_cast(this->Width), + static_cast(this->Height), + 0, + this->Format, + this->Type, + static_cast(data)); + if (this->GenerateMipmap) + { + glGenerateMipmap(this->Target); + } vtkOpenGLCheckErrorMacro("failed at glTexImage2D"); -- 2.9.3