Added support for hardware generated mipmaps into Textre2D::copy*() methods.
This commit is contained in:
@@ -14,6 +14,7 @@
|
||||
#include <osg/GLExtensions>
|
||||
#include <osg/Texture2D>
|
||||
#include <osg/State>
|
||||
#include <osg/Notify>
|
||||
#include <osg/GLU>
|
||||
|
||||
using namespace osg;
|
||||
@@ -246,16 +247,38 @@ void Texture2D::copyTexImage2D(State& state, int x, int y, int width, int height
|
||||
_image = NULL;
|
||||
|
||||
// switch off mip-mapping.
|
||||
_min_filter = LINEAR;
|
||||
_mag_filter = LINEAR;
|
||||
|
||||
//
|
||||
_textureObjectBuffer[contextID] = textureObject = generateTextureObject(contextID,GL_TEXTURE_2D);
|
||||
|
||||
textureObject->bind();
|
||||
|
||||
applyTexParameters(GL_TEXTURE_2D,state);
|
||||
|
||||
|
||||
bool needHardwareMipMap = (_min_filter != LINEAR && _min_filter != NEAREST);
|
||||
bool hardwareMipMapOn = false;
|
||||
if (needHardwareMipMap)
|
||||
{
|
||||
const Extensions* extensions = getExtensions(contextID,true);
|
||||
bool generateMipMapSupported = extensions->isGenerateMipMapSupported();
|
||||
|
||||
hardwareMipMapOn = _useHardwareMipMapGeneration && generateMipMapSupported;
|
||||
|
||||
if (!hardwareMipMapOn)
|
||||
{
|
||||
// have to swtich off mip mapping
|
||||
notify(NOTICE)<<"Warning: Texture2D::copyTexImage2D(,,,,) switch of mip mapping as hardware support not available."<<std::endl;
|
||||
_min_filter = LINEAR;
|
||||
}
|
||||
}
|
||||
|
||||
if (hardwareMipMapOn) glTexParameteri(GL_TEXTURE_2D, GL_GENERATE_MIPMAP_SGIS,GL_TRUE);
|
||||
|
||||
glCopyTexImage2D( GL_TEXTURE_2D, 0, _internalFormat, x, y, width, height, 0 );
|
||||
|
||||
if (hardwareMipMapOn) glTexParameteri(GL_TEXTURE_2D, GL_GENERATE_MIPMAP_SGIS,GL_FALSE);
|
||||
|
||||
|
||||
_textureWidth = width;
|
||||
_textureHeight = height;
|
||||
_numMipmapLevels = 1;
|
||||
@@ -282,10 +305,29 @@ void Texture2D::copyTexSubImage2D(State& state, int xoffset, int yoffset, int x,
|
||||
textureObject->bind();
|
||||
|
||||
applyTexParameters(GL_TEXTURE_2D,state);
|
||||
glCopyTexSubImage2D( GL_TEXTURE_2D, 0, xoffset,yoffset, x, y, width, height);
|
||||
|
||||
/* Redundant, delete later */
|
||||
//glBindTexture( GL_TEXTURE_2D, handle );
|
||||
bool needHardwareMipMap = (_min_filter != LINEAR && _min_filter != NEAREST);
|
||||
bool hardwareMipMapOn = false;
|
||||
if (needHardwareMipMap)
|
||||
{
|
||||
const Extensions* extensions = getExtensions(contextID,true);
|
||||
bool generateMipMapSupported = extensions->isGenerateMipMapSupported();
|
||||
|
||||
hardwareMipMapOn = _useHardwareMipMapGeneration && generateMipMapSupported;
|
||||
|
||||
if (!hardwareMipMapOn)
|
||||
{
|
||||
// have to swtich off mip mapping
|
||||
notify(NOTICE)<<"Warning: Texture2D::copyTexImage2D(,,,,) switch of mip mapping as hardware support not available."<<std::endl;
|
||||
_min_filter = LINEAR;
|
||||
}
|
||||
}
|
||||
|
||||
if (hardwareMipMapOn) glTexParameteri(GL_TEXTURE_2D, GL_GENERATE_MIPMAP_SGIS,GL_TRUE);
|
||||
|
||||
glCopyTexSubImage2D( GL_TEXTURE_2D, 0, xoffset, yoffset, x, y, width, height);
|
||||
|
||||
if (hardwareMipMapOn) glTexParameteri(GL_TEXTURE_2D, GL_GENERATE_MIPMAP_SGIS,GL_FALSE);
|
||||
|
||||
// inform state that this texture is the current one bound.
|
||||
state.haveAppliedAttribute(this);
|
||||
|
||||
Reference in New Issue
Block a user