Fixed handling of TextureCubeMap's with mipmapped/ImageSequence/PBO's.
This commit is contained in:
@@ -19,12 +19,16 @@
|
||||
#include <osg/Node>
|
||||
#include <osg/Geometry>
|
||||
#include <osg/Notify>
|
||||
#include <osg/Texture1D>
|
||||
#include <osg/Texture2D>
|
||||
#include <osg/Texture3D>
|
||||
#include <osg/TextureRectangle>
|
||||
#include <osg/ImageSequence>
|
||||
#include <osg/Geode>
|
||||
|
||||
#include <osgDB/Registry>
|
||||
#include <osgDB/ReadFile>
|
||||
#include <osgDB/WriteFile>
|
||||
|
||||
#include <osgViewer/Viewer>
|
||||
|
||||
@@ -36,27 +40,37 @@
|
||||
|
||||
osg::StateSet* createState()
|
||||
{
|
||||
// read 4 2d images
|
||||
osg::ref_ptr<osg::Image> image_0 = osgDB::readImageFile("Images/lz.rgb");
|
||||
osg::ref_ptr<osg::Image> image_1 = osgDB::readImageFile("Images/reflect.rgb");
|
||||
osg::ref_ptr<osg::Image> image_2 = osgDB::readImageFile("Images/tank.rgb");
|
||||
osg::ref_ptr<osg::Image> image_3 = osgDB::readImageFile("Images/skymap.jpg");
|
||||
|
||||
osg::ref_ptr<osg::ImageSequence> imageSequence = new osg::ImageSequence;
|
||||
imageSequence->addImage(image_0.get());
|
||||
imageSequence->addImage(image_1.get());
|
||||
imageSequence->addImage(image_2.get());
|
||||
imageSequence->addImage(image_3.get());
|
||||
|
||||
|
||||
imageSequence->setDuration(2.0);
|
||||
imageSequence->addImage(osgDB::readImageFile("Cubemap_axis/posx.png"));
|
||||
imageSequence->addImage(osgDB::readImageFile("Cubemap_axis/negx.png"));
|
||||
imageSequence->addImage(osgDB::readImageFile("Cubemap_axis/posy.png"));
|
||||
imageSequence->addImage(osgDB::readImageFile("Cubemap_axis/negy.png"));
|
||||
imageSequence->addImage(osgDB::readImageFile("Cubemap_axis/posz.png"));
|
||||
imageSequence->addImage(osgDB::readImageFile("Cubemap_axis/negz.png"));
|
||||
|
||||
#if 1
|
||||
osg::Texture2D* texture = new osg::Texture2D;
|
||||
texture->setFilter(osg::Texture2D::MIN_FILTER,osg::Texture2D::LINEAR);
|
||||
texture->setFilter(osg::Texture2D::MAG_FILTER,osg::Texture2D::LINEAR);
|
||||
texture->setWrap(osg::Texture2D::WRAP_R,osg::Texture2D::REPEAT);
|
||||
texture->setFilter(osg::Texture::MIN_FILTER,osg::Texture::LINEAR);
|
||||
texture->setFilter(osg::Texture::MAG_FILTER,osg::Texture::LINEAR);
|
||||
texture->setWrap(osg::Texture::WRAP_R,osg::Texture::REPEAT);
|
||||
texture->setResizeNonPowerOfTwoHint(false);
|
||||
texture->setImage(imageSequence.get());
|
||||
//texture->setTextureSize(512,512);
|
||||
|
||||
texture->setUpdateCallback(new osg::ImageSequence::UpdateCallback);
|
||||
//texture->setUpdateCallback(new osg::ImageSequence::UpdateCallback);
|
||||
#else
|
||||
osg::TextureRectangle* texture = new osg::TextureRectangle;
|
||||
texture->setFilter(osg::Texture::MIN_FILTER,osg::Texture::LINEAR);
|
||||
texture->setFilter(osg::Texture::MAG_FILTER,osg::Texture::LINEAR);
|
||||
texture->setWrap(osg::Texture::WRAP_R,osg::Texture::REPEAT);
|
||||
// texture->setResizeNonPowerOfTwoHint(false);
|
||||
texture->setImage(imageSequence.get());
|
||||
//texture->setTextureSize(512,512);
|
||||
|
||||
//texture->setUpdateCallback(new osg::ImageSequence::UpdateCallback);
|
||||
#endif
|
||||
|
||||
// create the StateSet to store the texture data
|
||||
osg::StateSet* stateset = new osg::StateSet;
|
||||
@@ -80,13 +94,17 @@ osg::Node* createModel()
|
||||
}
|
||||
|
||||
|
||||
int main(int , char **)
|
||||
int main(int argc, char **argv)
|
||||
{
|
||||
osg::ArgumentParser arguments(&argc,argv);
|
||||
|
||||
// construct the viewer.
|
||||
osgViewer::Viewer viewer;
|
||||
osgViewer::Viewer viewer(arguments);
|
||||
|
||||
// create a model from the images and pass it to the viewer.
|
||||
viewer.setSceneData(createModel());
|
||||
|
||||
//osgDB::writeNodeFile(*viewer.getSceneData(),"test.osg");
|
||||
|
||||
return viewer.run();
|
||||
}
|
||||
|
||||
@@ -26,7 +26,7 @@ void ImageSequence::UpdateCallback::operator () (osg::StateAttribute* attr, osg:
|
||||
{
|
||||
osg::Texture* texture = attr ? attr->asTexture() : 0;
|
||||
|
||||
//osg::notify(osg::NOTICE)<<"ImageSequence::UpdateCallback::"<<texture<<std::endl;
|
||||
// osg::notify(osg::NOTICE)<<"ImageSequence::UpdateCallback::"<<texture<<std::endl;
|
||||
if (texture)
|
||||
{
|
||||
for(unsigned int i=0; i<texture->getNumImages(); ++i)
|
||||
|
||||
@@ -42,7 +42,7 @@ using namespace osg;
|
||||
#define GL_STORAGE_SHARED_APPLE 0x85BF
|
||||
#endif
|
||||
|
||||
// #define DO_TIMING
|
||||
//#define DO_TIMING
|
||||
|
||||
ApplicationUsageProxy Texture_e0(ApplicationUsage::ENVIRONMENTAL_VARIABLE,"OSG_MAX_TEXTURE_SIZE","Set the maximum size of textures.");
|
||||
|
||||
@@ -1015,11 +1015,15 @@ void Texture::applyTexImage2D_load(State& state, GLenum target, const Image* ima
|
||||
|
||||
}
|
||||
|
||||
bool mipmappingRequired = _min_filter != LINEAR && _min_filter != NEAREST;
|
||||
bool useHardwareMipMapGeneration = mipmappingRequired && (!image->isMipmap() && isHardwareMipmapGenerationEnabled(state));
|
||||
bool useGluBuildMipMaps = mipmappingRequired && (!useHardwareMipMapGeneration && !image->isMipmap());
|
||||
|
||||
unsigned char* dataMinusOffset = 0;
|
||||
unsigned char* dataPlusOffset = 0;
|
||||
|
||||
const PixelBufferObject* pbo = image->getPixelBufferObject();
|
||||
if (pbo && pbo->isPBOSupported(contextID) && !needImageRescale)
|
||||
if (pbo && pbo->isPBOSupported(contextID) && !needImageRescale && !useGluBuildMipMaps)
|
||||
{
|
||||
state.bindPixelBufferObject(pbo);
|
||||
dataMinusOffset = data;
|
||||
@@ -1033,16 +1037,9 @@ void Texture::applyTexImage2D_load(State& state, GLenum target, const Image* ima
|
||||
pbo = 0;
|
||||
}
|
||||
|
||||
bool useHardwareMipMapGeneration = !image->isMipmap() && isHardwareMipmapGenerationEnabled(state);
|
||||
|
||||
if( _min_filter == LINEAR || _min_filter == NEAREST || useHardwareMipMapGeneration)
|
||||
if( !mipmappingRequired || useHardwareMipMapGeneration)
|
||||
{
|
||||
|
||||
if (_min_filter == LINEAR || _min_filter == NEAREST)
|
||||
{
|
||||
useHardwareMipMapGeneration = false;
|
||||
}
|
||||
|
||||
GenerateMipmapMode mipmapResult = mipmapBeforeTexImage(state, useHardwareMipMapGeneration);
|
||||
|
||||
if ( !compressed_image)
|
||||
@@ -1136,7 +1133,7 @@ void Texture::applyTexImage2D_load(State& state, GLenum target, const Image* ima
|
||||
gluBuild2DMipmaps( target, _internalFormat,
|
||||
inwidth,inheight,
|
||||
(GLenum)image->getPixelFormat(), (GLenum)image->getDataType(),
|
||||
data -dataMinusOffset+dataPlusOffset);
|
||||
data);
|
||||
|
||||
int width = image->s();
|
||||
int height = image->t();
|
||||
@@ -1264,13 +1261,16 @@ void Texture::applyTexImage2D_subload(State& state, GLenum target, const Image*
|
||||
|
||||
}
|
||||
|
||||
bool useHardwareMipMapGeneration = !image->isMipmap() && isHardwareMipmapGenerationEnabled(state);
|
||||
|
||||
unsigned char* dataMinusOffset=0;
|
||||
unsigned char* dataPlusOffset=0;
|
||||
|
||||
bool mipmappingRequired = _min_filter != LINEAR && _min_filter != NEAREST;
|
||||
bool useHardwareMipMapGeneration = mipmappingRequired && (!image->isMipmap() && isHardwareMipmapGenerationEnabled(state));
|
||||
bool useGluBuildMipMaps = mipmappingRequired && (!useHardwareMipMapGeneration && !image->isMipmap());
|
||||
|
||||
unsigned char* dataMinusOffset = 0;
|
||||
unsigned char* dataPlusOffset = 0;
|
||||
|
||||
const PixelBufferObject* pbo = image->getPixelBufferObject();
|
||||
if (pbo && pbo->isPBOSupported(contextID) && !needImageRescale)
|
||||
if (pbo && pbo->isPBOSupported(contextID) && !needImageRescale && !useGluBuildMipMaps)
|
||||
{
|
||||
state.bindPixelBufferObject(pbo);
|
||||
dataMinusOffset = data;
|
||||
@@ -1284,12 +1284,10 @@ void Texture::applyTexImage2D_subload(State& state, GLenum target, const Image*
|
||||
pbo = 0;
|
||||
}
|
||||
|
||||
if( _min_filter == LINEAR || _min_filter == NEAREST || useHardwareMipMapGeneration)
|
||||
if( !mipmappingRequired || useHardwareMipMapGeneration)
|
||||
{
|
||||
|
||||
bool hardwareMipMapOn = _min_filter != LINEAR && _min_filter != NEAREST;
|
||||
|
||||
GenerateMipmapMode mipmapResult = mipmapBeforeTexImage(state, hardwareMipMapOn);
|
||||
GenerateMipmapMode mipmapResult = mipmapBeforeTexImage(state, useHardwareMipMapGeneration);
|
||||
|
||||
if (!compressed_image)
|
||||
{
|
||||
|
||||
@@ -84,7 +84,7 @@ bool ImageSequence_writeLocalData(const Object& obj, Output& fw)
|
||||
itr != names.end();
|
||||
++itr)
|
||||
{
|
||||
fw.indent()<<*itr<<std::endl;
|
||||
fw.indent()<<fw.wrapString(*itr)<<std::endl;
|
||||
}
|
||||
|
||||
fw.moveOut();
|
||||
@@ -100,7 +100,7 @@ bool ImageSequence_writeLocalData(const Object& obj, Output& fw)
|
||||
itr != images.end();
|
||||
++itr)
|
||||
{
|
||||
if (!(*itr)->getFileName().empty()) fw.indent()<<(*itr)->getFileName()<<std::endl;
|
||||
if (!(*itr)->getFileName().empty()) fw.indent()<<fw.wrapString((*itr)->getFileName())<<std::endl;
|
||||
}
|
||||
|
||||
fw.moveOut();
|
||||
|
||||
@@ -30,15 +30,17 @@ RegisterDotOsgWrapperProxy g_TextureCubeMapProxy
|
||||
{\
|
||||
if (fr[2].matchWord("ImageSequence") || fr[2].matchWord("Image")) \
|
||||
{ \
|
||||
fr += 2;\
|
||||
osg::Image* image = fr.readImage(); \
|
||||
if (image) texture.setImage(osg::TextureCubeMap::FACE,image); \
|
||||
\
|
||||
iteratorAdvanced = true; \
|
||||
matched = true;\
|
||||
} \
|
||||
else if (fr[2].isString())\
|
||||
{ \
|
||||
Image* image = fr.readImage(fr[2].getStr());\
|
||||
if (image) texture.setImage(osg::TextureCubeMap::FACE,image);\
|
||||
fr += 2;\
|
||||
fr += 3;\
|
||||
iteratorAdvanced = true; \
|
||||
matched = true;\
|
||||
}\
|
||||
@@ -73,6 +75,7 @@ bool TextureCubeMap_readLocalData(Object& obj, Input& fr)
|
||||
const osg::ImageSequence* is = dynamic_cast<const osg::ImageSequence*>(image); \
|
||||
if (is) \
|
||||
{ \
|
||||
fw.indent() << "image "<<#FACE<<std::endl; \
|
||||
fw.writeObject(*is); \
|
||||
} \
|
||||
else \
|
||||
|
||||
Reference in New Issue
Block a user