Preliminary steps to support for compressed 3D textures.
This commit is contained in:
@@ -20,6 +20,7 @@
|
||||
#include <osg/Geometry>
|
||||
#include <osg/StateSet>
|
||||
#include <osg/Texture2D>
|
||||
#include <osg/Texture3D>
|
||||
|
||||
#include "dxtctool.h"
|
||||
|
||||
@@ -404,20 +405,31 @@ void Image::readPixels(int x,int y,int width,int height,
|
||||
void Image::readImageFromCurrentTexture(unsigned int contextID, bool copyMipMapsIfAvailable)
|
||||
{
|
||||
const osg::Texture::Extensions* extensions = osg::Texture::getExtensions(contextID,true);
|
||||
const osg::Texture3D::Extensions* extensions3D = osg::Texture3D::getExtensions(contextID,true);
|
||||
|
||||
|
||||
GLboolean binding1D, binding2D, binding3D;
|
||||
glGetBooleanv(GL_TEXTURE_BINDING_1D, &binding1D);
|
||||
glGetBooleanv(GL_TEXTURE_BINDING_2D, &binding2D);
|
||||
glGetBooleanv(GL_TEXTURE_BINDING_3D, &binding3D);
|
||||
|
||||
GLenum textureMode = binding1D ? GL_TEXTURE_1D : binding2D ? GL_TEXTURE_2D : binding3D ? GL_TEXTURE_3D : 0;
|
||||
|
||||
if (textureMode==0) return;
|
||||
|
||||
GLint internalformat;
|
||||
GLint width;
|
||||
GLint height;
|
||||
GLint depth;
|
||||
|
||||
|
||||
GLint numMipMaps = 0;
|
||||
if (copyMipMapsIfAvailable)
|
||||
{
|
||||
for(;numMipMaps<20;++numMipMaps)
|
||||
{
|
||||
glGetTexLevelParameteriv(GL_TEXTURE_2D, numMipMaps, GL_TEXTURE_WIDTH, &width);
|
||||
glGetTexLevelParameteriv(GL_TEXTURE_2D, numMipMaps, GL_TEXTURE_HEIGHT, &height);
|
||||
glGetTexLevelParameteriv(GL_TEXTURE_2D, numMipMaps, GL_TEXTURE_DEPTH, &depth);
|
||||
glGetTexLevelParameteriv(textureMode, numMipMaps, GL_TEXTURE_WIDTH, &width);
|
||||
glGetTexLevelParameteriv(textureMode, numMipMaps, GL_TEXTURE_HEIGHT, &height);
|
||||
glGetTexLevelParameteriv(textureMode, numMipMaps, GL_TEXTURE_DEPTH, &depth);
|
||||
if (width==0 || height==0 || depth==0) break;
|
||||
}
|
||||
}
|
||||
@@ -429,11 +441,23 @@ void Image::readImageFromCurrentTexture(unsigned int contextID, bool copyMipMaps
|
||||
|
||||
GLint compressed = 0;
|
||||
|
||||
if (extensions->isCompressedTexImage2DSupported())
|
||||
if (textureMode==GL_TEXTURE_2D)
|
||||
{
|
||||
glGetTexLevelParameteriv(GL_TEXTURE_2D, 0, GL_TEXTURE_COMPRESSED_ARB,&compressed);
|
||||
if (extensions->isCompressedTexImage2DSupported())
|
||||
{
|
||||
glGetTexLevelParameteriv(GL_TEXTURE_2D, 0, GL_TEXTURE_COMPRESSED_ARB,&compressed);
|
||||
}
|
||||
}
|
||||
else if (textureMode==GL_TEXTURE_2D)
|
||||
{
|
||||
if (extensions3D->isCompressedTexImage3DSupported())
|
||||
{
|
||||
glGetTexLevelParameteriv(GL_TEXTURE_3D, 0, GL_TEXTURE_COMPRESSED_ARB,&compressed);
|
||||
}
|
||||
}
|
||||
|
||||
|
||||
|
||||
/* if the compression has been successful */
|
||||
if (compressed == GL_TRUE)
|
||||
{
|
||||
@@ -447,7 +471,7 @@ void Image::readImageFromCurrentTexture(unsigned int contextID, bool copyMipMaps
|
||||
if (i>0) mipMapData.push_back(total_size);
|
||||
|
||||
GLint compressed_size;
|
||||
glGetTexLevelParameteriv(GL_TEXTURE_2D, i, GL_TEXTURE_COMPRESSED_IMAGE_SIZE_ARB, &compressed_size);
|
||||
glGetTexLevelParameteriv(textureMode, i, GL_TEXTURE_COMPRESSED_IMAGE_SIZE_ARB, &compressed_size);
|
||||
|
||||
total_size += compressed_size;
|
||||
}
|
||||
@@ -462,10 +486,10 @@ void Image::readImageFromCurrentTexture(unsigned int contextID, bool copyMipMaps
|
||||
|
||||
deallocateData(); // and sets it to NULL.
|
||||
|
||||
glGetTexLevelParameteriv(GL_TEXTURE_2D, 0, GL_TEXTURE_INTERNAL_FORMAT, &internalformat);
|
||||
glGetTexLevelParameteriv(GL_TEXTURE_2D, 0, GL_TEXTURE_WIDTH, &width);
|
||||
glGetTexLevelParameteriv(GL_TEXTURE_2D, 0, GL_TEXTURE_HEIGHT, &height);
|
||||
glGetTexLevelParameteriv(GL_TEXTURE_2D, 0, GL_TEXTURE_DEPTH, &depth);
|
||||
glGetTexLevelParameteriv(textureMode, 0, GL_TEXTURE_INTERNAL_FORMAT, &internalformat);
|
||||
glGetTexLevelParameteriv(textureMode, 0, GL_TEXTURE_WIDTH, &width);
|
||||
glGetTexLevelParameteriv(textureMode, 0, GL_TEXTURE_HEIGHT, &height);
|
||||
glGetTexLevelParameteriv(textureMode, 0, GL_TEXTURE_DEPTH, &depth);
|
||||
|
||||
_data = data;
|
||||
_s = width;
|
||||
@@ -480,7 +504,7 @@ void Image::readImageFromCurrentTexture(unsigned int contextID, bool copyMipMaps
|
||||
|
||||
for(i=0;i<numMipMaps;++i)
|
||||
{
|
||||
extensions->glGetCompressedTexImage(GL_TEXTURE_2D, i, getMipmapData(i));
|
||||
extensions->glGetCompressedTexImage(textureMode, i, getMipmapData(i));
|
||||
}
|
||||
|
||||
++_modifiedTag;
|
||||
@@ -496,9 +520,9 @@ void Image::readImageFromCurrentTexture(unsigned int contextID, bool copyMipMaps
|
||||
{
|
||||
if (i>0) mipMapData.push_back(total_size);
|
||||
|
||||
glGetTexLevelParameteriv(GL_TEXTURE_2D, i, GL_TEXTURE_WIDTH, &width);
|
||||
glGetTexLevelParameteriv(GL_TEXTURE_2D, i, GL_TEXTURE_HEIGHT, &height);
|
||||
glGetTexLevelParameteriv(GL_TEXTURE_2D, i, GL_TEXTURE_DEPTH, &depth);
|
||||
glGetTexLevelParameteriv(textureMode, i, GL_TEXTURE_WIDTH, &width);
|
||||
glGetTexLevelParameteriv(textureMode, i, GL_TEXTURE_HEIGHT, &height);
|
||||
glGetTexLevelParameteriv(textureMode, i, GL_TEXTURE_DEPTH, &depth);
|
||||
|
||||
unsigned int level_size = computeRowWidthInBytes(width,_pixelFormat,GL_UNSIGNED_BYTE,_packing)*height*depth;
|
||||
|
||||
@@ -515,10 +539,10 @@ void Image::readImageFromCurrentTexture(unsigned int contextID, bool copyMipMaps
|
||||
|
||||
deallocateData(); // and sets it to NULL.
|
||||
|
||||
glGetTexLevelParameteriv(GL_TEXTURE_2D, 0, GL_TEXTURE_INTERNAL_FORMAT, &internalformat);
|
||||
glGetTexLevelParameteriv(GL_TEXTURE_2D, 0, GL_TEXTURE_WIDTH, &width);
|
||||
glGetTexLevelParameteriv(GL_TEXTURE_2D, 0, GL_TEXTURE_HEIGHT, &height);
|
||||
glGetTexLevelParameteriv(GL_TEXTURE_2D, 0, GL_TEXTURE_DEPTH, &depth);
|
||||
glGetTexLevelParameteriv(textureMode, 0, GL_TEXTURE_INTERNAL_FORMAT, &internalformat);
|
||||
glGetTexLevelParameteriv(textureMode, 0, GL_TEXTURE_WIDTH, &width);
|
||||
glGetTexLevelParameteriv(textureMode, 0, GL_TEXTURE_HEIGHT, &height);
|
||||
glGetTexLevelParameteriv(textureMode, 0, GL_TEXTURE_DEPTH, &depth);
|
||||
|
||||
_data = data;
|
||||
_s = width;
|
||||
@@ -533,7 +557,7 @@ void Image::readImageFromCurrentTexture(unsigned int contextID, bool copyMipMaps
|
||||
|
||||
for(i=0;i<numMipMaps;++i)
|
||||
{
|
||||
glGetTexImage(GL_TEXTURE_2D,i,_pixelFormat,_dataType,getMipmapData(i));
|
||||
glGetTexImage(textureMode,i,_pixelFormat,_dataType,getMipmapData(i));
|
||||
}
|
||||
|
||||
++_modifiedTag;
|
||||
|
||||
@@ -1355,7 +1355,7 @@ void Texture::Extensions::glCompressedTexImage2D(GLenum target, GLint level, GLe
|
||||
|
||||
void Texture::Extensions::glCompressedTexSubImage2D(GLenum target, GLint level, GLint xoffset, GLint yoffset, GLsizei width, GLsizei height, GLenum format, GLsizei imageSize, const GLvoid *data) const
|
||||
{
|
||||
if (_glCompressedTexImage2D)
|
||||
if (_glCompressedTexSubImage2D)
|
||||
{
|
||||
typedef void (APIENTRY * CompressedTexSubImage2DArbProc) (GLenum target, GLint level, GLint xoffset, GLint yoffset, GLsizei width, GLsizei height, GLenum format, GLsizei imageSize, const GLvoid *data);
|
||||
((CompressedTexSubImage2DArbProc)_glCompressedTexSubImage2D)(target, level, xoffset, yoffset, width, height, format, imageSize, data);
|
||||
|
||||
@@ -16,8 +16,6 @@
|
||||
#include <osg/State>
|
||||
#include <osg/GLU>
|
||||
|
||||
typedef void (APIENTRY * MyCompressedTexImage2DArbProc) (GLenum target, GLint level, GLenum internalformat, GLsizei width, GLsizei height, GLint border, GLsizei imageSize, const GLvoid *data);
|
||||
|
||||
using namespace osg;
|
||||
|
||||
Texture2D::Texture2D():
|
||||
|
||||
@@ -205,8 +205,8 @@ void Texture3D::applyTexImage3D(GLenum target, Image* image, State& state, GLsiz
|
||||
bool compressed = isCompressedInternalFormat(_internalFormat);
|
||||
if (compressed)
|
||||
{
|
||||
notify(WARN)<<"Warning::cannot currently use compressed format with 3D textures."<<std::endl;
|
||||
return;
|
||||
//notify(WARN)<<"Warning::cannot currently use compressed format with 3D textures."<<std::endl;
|
||||
//return;
|
||||
}
|
||||
|
||||
image->ensureValidSizeForTexturing(extensions->maxTexture3DSize());
|
||||
@@ -345,6 +345,8 @@ void Texture3D::Extensions::lowestCommonDenominator(const Extensions& rhs)
|
||||
|
||||
if (!rhs._glTexImage3D) _glTexImage3D = 0;
|
||||
if (!rhs._glTexSubImage3D) _glTexSubImage3D = 0;
|
||||
if (!rhs._glCompressedTexImage3D) _glTexImage3D = 0;
|
||||
if (!rhs._glCompressedTexSubImage3D) _glTexSubImage3D = 0;
|
||||
if (!rhs._glCopyTexSubImage3D) _glCopyTexSubImage3D = 0;
|
||||
if (!rhs._gluBuild3DMipmaps) _gluBuild3DMipmaps = 0;
|
||||
}
|
||||
@@ -358,10 +360,12 @@ void Texture3D::Extensions::setupGLExtenions()
|
||||
|
||||
glGetIntegerv(GL_MAX_3D_TEXTURE_SIZE, &_maxTexture3DSize);
|
||||
|
||||
_glTexImage3D = getGLExtensionFuncPtr("glTexImage3D","glTexImage3DEXT");;
|
||||
_glTexSubImage3D = getGLExtensionFuncPtr("glTexSubImage3D","glTexSubImage3DEXT");
|
||||
_glCopyTexSubImage3D = getGLExtensionFuncPtr("glCopyTexSubImage3D","glCopyTexSubImage3DEXT");
|
||||
_gluBuild3DMipmaps = getGLExtensionFuncPtr("gluBuild3DMipmaps");
|
||||
_glTexImage3D = getGLExtensionFuncPtr("glTexImage3D","glTexImage3DEXT");
|
||||
_glTexSubImage3D = getGLExtensionFuncPtr("glTexSubImage3D","glTexSubImage3DEXT");
|
||||
_glCompressedTexImage3D = getGLExtensionFuncPtr("glCompressedTexImage3D","glCompressedTexImage3DARB");
|
||||
_glCompressedTexSubImage3D = getGLExtensionFuncPtr("glCompressedTexSubImage3D","glCompressedTexSubImage3DARB");
|
||||
_glCopyTexSubImage3D = getGLExtensionFuncPtr("glCopyTexSubImage3D","glCopyTexSubImage3DEXT");
|
||||
_gluBuild3DMipmaps = getGLExtensionFuncPtr("gluBuild3DMipmaps");
|
||||
|
||||
}
|
||||
|
||||
@@ -393,6 +397,32 @@ void Texture3D::Extensions::glTexSubImage3D( GLenum target, GLint level, GLint x
|
||||
}
|
||||
}
|
||||
|
||||
void Texture3D::Extensions::glCompressedTexImage3D(GLenum target, GLint level, GLenum internalformat, GLsizei width, GLsizei height, GLsizei depth, GLint border, GLsizei imageSize, const GLvoid *data) const
|
||||
{
|
||||
if (_glCompressedTexImage3D)
|
||||
{
|
||||
typedef void (APIENTRY * CompressedTexImage3DArbProc) (GLenum target, GLint level, GLenum internalformat, GLsizei width, GLsizei height, GLsizei depth, GLint border, GLsizei imageSize, const GLvoid *data);
|
||||
((CompressedTexImage3DArbProc)_glCompressedTexImage3D)(target, level, internalformat, width, height, depth, border, imageSize, data);
|
||||
}
|
||||
else
|
||||
{
|
||||
notify(WARN)<<"Error: glCompressedTexImage3D not supported by OpenGL driver"<<std::endl;
|
||||
}
|
||||
}
|
||||
|
||||
void Texture3D::Extensions::glCompressedTexSubImage3D( GLenum target, GLint level, GLint xoffset, GLint yoffset, GLint zoffset, GLsizei width, GLsizei height, GLsizei depth, GLenum format, GLsizei imageSize, const GLvoid *data ) const
|
||||
{
|
||||
if (_glCompressedTexSubImage3D)
|
||||
{
|
||||
typedef void (APIENTRY * CompressedTexSubImage3DArbProc) (GLenum target, GLint level, GLint xoffset, GLint yoffset, GLint zoffset, GLsizei width, GLsizei height, GLsizei depth, GLenum format, GLsizei imageSize, const GLvoid *data);
|
||||
((CompressedTexSubImage3DArbProc)_glCompressedTexSubImage3D)(target, level, xoffset, yoffset, zoffset, width, height, depth, format, imageSize, data);
|
||||
}
|
||||
else
|
||||
{
|
||||
notify(WARN)<<"Error: glCompressedTexImage2D not supported by OpenGL driver"<<std::endl;
|
||||
}
|
||||
}
|
||||
|
||||
void Texture3D::Extensions::glCopyTexSubImage3D( GLenum target, GLint level, GLint xoffset, GLint yoffset, GLint zoffset, GLint x, GLint y, GLsizei width, GLsizei height ) const
|
||||
{
|
||||
// ::glCopyTexSubImage3D(target, level, xoffset, yoffset, zoffset, x, y, width, height);
|
||||
|
||||
Reference in New Issue
Block a user