mirror of
https://git.dev.opencascade.org/repos/occt.git
synced 2025-04-16 10:08:36 +03:00
0023632: Add support for NPOT mipmap textures in TKOpenGl
Use glGenerateMipmap instead of gluBuild2DMipmaps when available.
This commit is contained in:
parent
c34dba32d4
commit
1a7dfdb719
@ -575,7 +575,8 @@ void OpenGl_Context::init()
|
|||||||
|| !FindProcShort (extFBO, glDeleteRenderbuffersEXT)
|
|| !FindProcShort (extFBO, glDeleteRenderbuffersEXT)
|
||||||
|| !FindProcShort (extFBO, glBindRenderbufferEXT)
|
|| !FindProcShort (extFBO, glBindRenderbufferEXT)
|
||||||
|| !FindProcShort (extFBO, glRenderbufferStorageEXT)
|
|| !FindProcShort (extFBO, glRenderbufferStorageEXT)
|
||||||
|| !FindProcShort (extFBO, glFramebufferRenderbufferEXT))
|
|| !FindProcShort (extFBO, glFramebufferRenderbufferEXT)
|
||||||
|
|| !FindProcShort (extFBO, glGenerateMipmapEXT))
|
||||||
{
|
{
|
||||||
delete extFBO;
|
delete extFBO;
|
||||||
extFBO = NULL;
|
extFBO = NULL;
|
||||||
|
@ -1,6 +1,6 @@
|
|||||||
// Created on: 2012-01-26
|
// Created on: 2012-01-26
|
||||||
// Created by: Kirill GAVRILOV
|
// Created by: Kirill GAVRILOV
|
||||||
// Copyright (c) 2012-2012 OPEN CASCADE SAS
|
// Copyright (c) 2012 OPEN CASCADE SAS
|
||||||
//
|
//
|
||||||
// The content of this file is subject to the Open CASCADE Technology Public
|
// The content of this file is subject to the Open CASCADE Technology Public
|
||||||
// License Version 6.5 (the "License"). You may not use the content of this file
|
// License Version 6.5 (the "License"). You may not use the content of this file
|
||||||
@ -17,7 +17,6 @@
|
|||||||
// purpose or non-infringement. Please see the License for the specific terms
|
// purpose or non-infringement. Please see the License for the specific terms
|
||||||
// and conditions governing the rights and limitations under the License.
|
// and conditions governing the rights and limitations under the License.
|
||||||
|
|
||||||
|
|
||||||
#ifndef _OpenGl_ExtFBO_H__
|
#ifndef _OpenGl_ExtFBO_H__
|
||||||
#define _OpenGl_ExtFBO_H__
|
#define _OpenGl_ExtFBO_H__
|
||||||
|
|
||||||
@ -37,6 +36,7 @@ struct OpenGl_ExtFBO
|
|||||||
PFNGLBINDRENDERBUFFEREXTPROC glBindRenderbufferEXT;
|
PFNGLBINDRENDERBUFFEREXTPROC glBindRenderbufferEXT;
|
||||||
PFNGLRENDERBUFFERSTORAGEEXTPROC glRenderbufferStorageEXT;
|
PFNGLRENDERBUFFERSTORAGEEXTPROC glRenderbufferStorageEXT;
|
||||||
PFNGLFRAMEBUFFERRENDERBUFFEREXTPROC glFramebufferRenderbufferEXT;
|
PFNGLFRAMEBUFFERRENDERBUFFEREXTPROC glFramebufferRenderbufferEXT;
|
||||||
|
PFNGLGENERATEMIPMAPEXTPROC glGenerateMipmapEXT;
|
||||||
|
|
||||||
};
|
};
|
||||||
|
|
||||||
|
@ -18,6 +18,7 @@
|
|||||||
|
|
||||||
#include <OpenGl_Texture.hxx>
|
#include <OpenGl_Texture.hxx>
|
||||||
|
|
||||||
|
#include <OpenGl_ExtFBO.hxx>
|
||||||
#include <OpenGl_Context.hxx>
|
#include <OpenGl_Context.hxx>
|
||||||
#include <Graphic3d_TextureParams.hxx>
|
#include <Graphic3d_TextureParams.hxx>
|
||||||
#include <Standard_Assert.hxx>
|
#include <Standard_Assert.hxx>
|
||||||
@ -357,7 +358,6 @@ bool OpenGl_Texture::Init (const Handle(OpenGl_Context)& theCtx,
|
|||||||
if (aWidth != aWidthOut || aHeight != aHeightOut)
|
if (aWidth != aWidthOut || aHeight != aHeightOut)
|
||||||
{
|
{
|
||||||
// scale texture
|
// scale texture
|
||||||
|
|
||||||
if (!aCopy.InitTrash (theImage.Format(), Standard_Size(aWidthOut), Standard_Size(aHeightOut))
|
if (!aCopy.InitTrash (theImage.Format(), Standard_Size(aWidthOut), Standard_Size(aHeightOut))
|
||||||
|| gluScaleImage (aPixelFormat,
|
|| gluScaleImage (aPixelFormat,
|
||||||
aWidth, aHeight, aDataType, theImage.Data(),
|
aWidth, aHeight, aDataType, theImage.Data(),
|
||||||
@ -398,11 +398,42 @@ bool OpenGl_Texture::Init (const Handle(OpenGl_Context)& theCtx,
|
|||||||
glTexParameteri (GL_TEXTURE_2D, GL_TEXTURE_MIN_FILTER, GL_LINEAR_MIPMAP_LINEAR);
|
glTexParameteri (GL_TEXTURE_2D, GL_TEXTURE_MIN_FILTER, GL_LINEAR_MIPMAP_LINEAR);
|
||||||
glTexParameteri (GL_TEXTURE_2D, GL_TEXTURE_MAG_FILTER, GL_LINEAR);
|
glTexParameteri (GL_TEXTURE_2D, GL_TEXTURE_MAG_FILTER, GL_LINEAR);
|
||||||
|
|
||||||
bool isCreated = gluBuild2DMipmaps (GL_TEXTURE_2D, aTextureFormat,
|
if (theCtx->extFBO != NULL
|
||||||
aWidth, aHeight,
|
&& aWidth == aWidthOut && aHeight == aHeightOut)
|
||||||
aPixelFormat, aDataType, theImage.Data()) == 0;
|
{
|
||||||
Unbind (theCtx);
|
// use proxy to check texture could be created or not
|
||||||
return isCreated;
|
glTexImage2D (GL_PROXY_TEXTURE_2D, 0, aTextureFormat,
|
||||||
|
aWidthOut, aHeightOut, 0,
|
||||||
|
aPixelFormat, aDataType, NULL);
|
||||||
|
glGetTexLevelParameteriv (GL_PROXY_TEXTURE_2D, 0, GL_TEXTURE_WIDTH, &aTestWidth);
|
||||||
|
glGetTexLevelParameteriv (GL_PROXY_TEXTURE_2D, 0, GL_TEXTURE_HEIGHT, &aTestHeight);
|
||||||
|
if (aTestWidth == 0 || aTestHeight == 0)
|
||||||
|
{
|
||||||
|
// no memory or broken input parameters
|
||||||
|
Unbind (theCtx);
|
||||||
|
return false;
|
||||||
|
}
|
||||||
|
|
||||||
|
// upload main picture
|
||||||
|
glTexImage2D (GL_TEXTURE_2D, 0, aTextureFormat,
|
||||||
|
aWidthOut, aHeightOut, 0,
|
||||||
|
aPixelFormat, aDataType, theImage.Data());
|
||||||
|
|
||||||
|
// generate mipmaps
|
||||||
|
//glHint (GL_GENERATE_MIPMAP_HINT, GL_NICEST);
|
||||||
|
theCtx->extFBO->glGenerateMipmapEXT (GL_TEXTURE_2D);
|
||||||
|
|
||||||
|
Unbind (theCtx);
|
||||||
|
return true;
|
||||||
|
}
|
||||||
|
else
|
||||||
|
{
|
||||||
|
bool isCreated = gluBuild2DMipmaps (GL_TEXTURE_2D, aTextureFormat,
|
||||||
|
aWidth, aHeight,
|
||||||
|
aPixelFormat, aDataType, theImage.Data()) == 0;
|
||||||
|
Unbind (theCtx);
|
||||||
|
return isCreated;
|
||||||
|
}
|
||||||
}
|
}
|
||||||
default:
|
default:
|
||||||
{
|
{
|
||||||
|
Loading…
x
Reference in New Issue
Block a user