Added osg::Image::setPixelFormat(..) and setInternalTextureFormat(), and

renamed osg::Image::pixelFormat(), internalTextureFormat(),dataType() to
osg::Image::getPixelFormat() etc.  These changes are to bring it more
into line with the style of the rest of the OSG.

Updated the rest of the distribution to take account for these names changes.
This commit is contained in:
Robert Osfield
2002-04-16 14:57:39 +00:00
parent 2b4008bbbc
commit 7836540bb3
8 changed files with 66 additions and 41 deletions

View File

@@ -85,15 +85,15 @@ void DrawPixels::drawImmediateMode(State&)
{
const GLvoid* pixels = _image->data();
glDrawPixels(_width,_height,
(GLenum)_image->pixelFormat(),
(GLenum)_image->dataType(),
(GLenum)_image->getPixelFormat(),
(GLenum)_image->getDataType(),
pixels);
}
else
{
glDrawPixels(_image->s(), _image->t(),
(GLenum)_image->pixelFormat(),
(GLenum)_image->dataType(),
(GLenum)_image->getPixelFormat(),
(GLenum)_image->getDataType(),
_image->data() );
}
}

View File

@@ -163,6 +163,29 @@ const unsigned int Image::computeRowWidthInBytes(int width,GLenum format,GLenum
}
void Image::setInternalTextureFormat(GLint internalFormat)
{
// won't do any sanity checking right now, leave it to
// OpenGL to make the call.
_internalTextureFormat = internalFormat;
}
void Image::setPixelFormat(const GLenum format)
{
if (_pixelFormat==format) return; // do nothing if the same.
if (computeNumComponents(_pixelFormat)==computeNumComponents(format))
{
// if the two formats have the same number of componets then
// we can do a straight swap.
_pixelFormat = format;
}
else
{
notify(WARN)<<"Image::setPixelFormat(..) - warning, attempt to reset the pixel format with a different number of components."<<std::endl;
}
}
void Image::createImage(int s,int t,int r,
GLenum format,GLenum type,
int packing)

View File

@@ -213,7 +213,7 @@ void Texture::apply(State& state) const
glTexSubImage2D(_target, 0,
_subloadOffsX, _subloadOffsY,
(_subloadWidth>0)?_subloadWidth:_image->s(), (_subloadHeight>0)?_subloadHeight:_image->t(),
(GLenum) _image->pixelFormat(), (GLenum) _image->dataType(),
(GLenum) _image->getPixelFormat(), (GLenum) _image->getDataType(),
_image->data());
// update the modified flag to show that the image has been loaded.
modifiedTag = _image->getModifiedTag();
@@ -333,23 +333,23 @@ void Texture::applyTexImage(GLenum target, Image* image, State& state) const
if (_subloadMode == OFF)
image->ensureValidSizeForTexturing();
glPixelStorei(GL_UNPACK_ALIGNMENT,image->packing());
glPixelStorei(GL_UNPACK_ALIGNMENT,image->getPacking());
static bool s_ARB_Compression = isGLExtensionSupported("GL_ARB_texture_compression");
static bool s_S3TC_Compression = isGLExtensionSupported("GL_EXT_texture_compression_s3tc");
// select the internalFormat required for the texture.
int internalFormat = image->internalTextureFormat();
GLint internalFormat = image->getInternalTextureFormat();
switch(_internalFormatMode)
{
case(USE_IMAGE_DATA_FORMAT):
internalFormat = image->internalTextureFormat();
internalFormat = image->getInternalTextureFormat();
break;
case(USE_ARB_COMPRESSION):
if (s_ARB_Compression)
{
switch(image->pixelFormat())
switch(image->getPixelFormat())
{
case(1): internalFormat = GL_COMPRESSED_ALPHA_ARB; break;
case(2): internalFormat = GL_COMPRESSED_LUMINANCE_ALPHA_ARB; break;
@@ -363,52 +363,52 @@ void Texture::applyTexImage(GLenum target, Image* image, State& state) const
case(GL_INTENSITY): internalFormat = GL_COMPRESSED_INTENSITY_ARB; break;
}
}
else internalFormat = image->internalTextureFormat();
else internalFormat = image->getInternalTextureFormat();
break;
case(USE_S3TC_DXT1_COMPRESSION):
if (s_S3TC_Compression)
{
switch(image->pixelFormat())
switch(image->getPixelFormat())
{
case(3): internalFormat = GL_COMPRESSED_RGB_S3TC_DXT1_EXT; break;
case(4): internalFormat = GL_COMPRESSED_RGBA_S3TC_DXT1_EXT; break;
case(GL_RGB): internalFormat = GL_COMPRESSED_RGB_S3TC_DXT1_EXT; break;
case(GL_RGBA): internalFormat = GL_COMPRESSED_RGBA_S3TC_DXT1_EXT; break;
default: internalFormat = image->internalTextureFormat(); break;
default: internalFormat = image->getInternalTextureFormat(); break;
}
}
else internalFormat = image->internalTextureFormat();
else internalFormat = image->getInternalTextureFormat();
break;
case(USE_S3TC_DXT3_COMPRESSION):
if (s_S3TC_Compression)
{
switch(image->pixelFormat())
switch(image->getPixelFormat())
{
case(3):
case(GL_RGB): internalFormat = GL_COMPRESSED_RGB_S3TC_DXT1_EXT; break;
case(4):
case(GL_RGBA): internalFormat = GL_COMPRESSED_RGBA_S3TC_DXT3_EXT; break;
default: internalFormat = _image->internalTextureFormat(); break;
default: internalFormat = _image->getInternalTextureFormat(); break;
}
}
else internalFormat = image->internalTextureFormat();
else internalFormat = image->getInternalTextureFormat();
break;
case(USE_S3TC_DXT5_COMPRESSION):
if (s_S3TC_Compression)
{
switch(image->pixelFormat())
switch(image->getPixelFormat())
{
case(3):
case(GL_RGB): internalFormat = GL_COMPRESSED_RGB_S3TC_DXT1_EXT; break;
case(4):
case(GL_RGBA): internalFormat = GL_COMPRESSED_RGBA_S3TC_DXT5_EXT; break;
default: internalFormat = image->internalTextureFormat(); break;
default: internalFormat = image->getInternalTextureFormat(); break;
}
}
else internalFormat = image->internalTextureFormat();
else internalFormat = image->getInternalTextureFormat();
break;
case(USE_USER_DEFINED_FORMAT):
@@ -427,8 +427,8 @@ void Texture::applyTexImage(GLenum target, Image* image, State& state) const
{
glTexImage2D( target, 0, internalFormat,
image->s(), image->t(), 0,
(GLenum)image->pixelFormat(),
(GLenum)image->dataType(),
(GLenum)image->getPixelFormat(),
(GLenum)image->getDataType(),
image->data() );
// just estimate estimate it right now..
@@ -441,7 +441,7 @@ void Texture::applyTexImage(GLenum target, Image* image, State& state) const
gluBuild2DMipmaps( target, internalFormat,
image->s(),image->t(),
(GLenum)image->pixelFormat(), (GLenum)image->dataType(),
(GLenum)image->getPixelFormat(), (GLenum)image->getDataType(),
image->data() );
// just estimate size it right now..
@@ -477,13 +477,13 @@ void Texture::applyTexImage(GLenum target, Image* image, State& state) const
// reserve appropriate texture memory
glTexImage2D(target, 0, internalFormat,
_textureWidth, _textureHeight, 0,
(GLenum) image->pixelFormat(), (GLenum) image->dataType(),
(GLenum) image->getPixelFormat(), (GLenum) image->getDataType(),
NULL);
glTexSubImage2D(target, 0,
_subloadOffsX, _subloadOffsY,
width, height,
(GLenum) image->pixelFormat(), (GLenum) image->dataType(),
(GLenum) image->getPixelFormat(), (GLenum) image->getDataType(),
image->data());
}

View File

@@ -206,7 +206,7 @@ void TextureCubeMap::apply(State& state) const
glTexSubImage2D(faceTarget[n], 0,
_subloadOffsX, _subloadOffsY,
(_subloadWidth>0)?_subloadWidth:_images[n]->s(), (_subloadHeight>0)?_subloadHeight:_images[n]->t(),
(GLenum) _images[n]->pixelFormat(), (GLenum) _images[n]->dataType(),
(GLenum) _images[n]->getPixelFormat(), (GLenum) _images[n]->getDataType(),
_images[n]->data());
// update the modified flag to show that the image has been loaded.
modifiedTag += _images[n]->getModifiedTag();

View File

@@ -1433,8 +1433,8 @@ std::string DXWriter::WriteImage( const osg::Image &image )
field.AddComponent( "connections", conn_name.c_str() );
// Generate colors
unsigned int pixel_fmt = image.pixelFormat(); // A user-friendly int_fmt
unsigned int data_type = image.dataType(); // Sample data type
unsigned int pixel_fmt = image.getPixelFormat(); // A user-friendly int_fmt
unsigned int data_type = image.getDataType(); // Sample data type
const unsigned char *data = image.data();
int r_dim = image.r();

View File

@@ -911,7 +911,7 @@ void ConvertFromFLT::visitFace(GeoSetBuilder* pBuilder, FaceRecord* rec)
if (osgTexture)
{
osg::Image* osgImage = osgTexture->getImage();
switch (osgImage->pixelFormat())
switch (osgImage->getPixelFormat())
{
case GL_LUMINANCE_ALPHA:
case GL_RGBA:

View File

@@ -521,10 +521,10 @@ pfGeoState* ConvertToPerformer::visitStateSet(osg::StateSet* stateset)
int ns = img->s();
int nt = img->t();
int ncomp =
img->pixelFormat() == GL_LUMINANCE ? 1 :
img->pixelFormat() == GL_LUMINANCE_ALPHA ? 2 :
img->pixelFormat() == GL_RGB ? 3 :
img->pixelFormat() == GL_RGBA ? 4 : 3;
img->getPixelFormat() == GL_LUMINANCE ? 1 :
img->getPixelFormat() == GL_LUMINANCE_ALPHA ? 2 :
img->getPixelFormat() == GL_RGB ? 3 :
img->getPixelFormat() == GL_RGBA ? 4 : 3;
uint *uim = (uint *)pfMalloc( ns * nt * ncomp, pfGetSharedArena() );