From Brad Colbert/Robert Osfield: added s/getSourceFormat and s/getSourceType to osg::Texture

along with support for this Texture1D, 2D, 3D, TextureCubeMap and TextureRectangle.  The
new SourceFormat and SourceType parameters are only used when no osg::Image is assigned to
an osg::Texture, and main use is for render to texture effects.

Added support for --hdr option in osgprerender, which utilises the new Texture::setSourceFormat/Type() methods.
This commit is contained in:
Robert Osfield
2005-11-08 15:52:21 +00:00
parent 8922bde081
commit 53e075f78b
8 changed files with 114 additions and 10 deletions

View File

@@ -145,14 +145,40 @@ struct MyCameraPostDrawCallback : public osg::CameraNode::DrawCallback
// using the image can be informed that they need to update.
_image->dirty();
}
else if (_image && _image->getPixelFormat()==GL_RGBA && _image->getDataType()==GL_FLOAT)
{
// we'll pick out the center 1/2 of the whole image,
int column_start = _image->s()/4;
int column_end = 3*column_start;
int row_start = _image->t()/4;
int row_end = 3*row_start;
// and then invert these pixels
for(int r=row_start; r<row_end; ++r)
{
float* data = (float*)_image->data(column_start, r);
for(int c=column_start; c<column_end; ++c)
{
(*data) = 1.0f-(*data); ++data;
(*data) = 1.0f-(*data); ++data;
(*data) = 1.0f-(*data); ++data;
(*data) = 1.0f; ++data;
}
}
// dirty the image (increments the modified count) so that any textures
// using the image can be informed that they need to update.
_image->dirty();
}
}
osg::Image* _image;
};
osg::Node* createPreRenderSubGraph(osg::Node* subgraph, unsigned tex_width, unsigned tex_height, osg::CameraNode::RenderTargetImplementation renderImplementation, bool useImage, bool useTextureRectangle)
osg::Node* createPreRenderSubGraph(osg::Node* subgraph, unsigned tex_width, unsigned tex_height, osg::CameraNode::RenderTargetImplementation renderImplementation, bool useImage, bool useTextureRectangle, bool useHDR)
{
if (!subgraph) return 0;
@@ -182,6 +208,13 @@ osg::Node* createPreRenderSubGraph(osg::Node* subgraph, unsigned tex_width, unsi
texture = texture2D;
}
if (useHDR)
{
texture->setInternalFormat(GL_RGBA16F_ARB);
texture->setSourceFormat(GL_RGBA);
texture->setSourceType(GL_FLOAT);
}
// first create the geometry of the flag of which to view.
{
// create the to visualize.
@@ -298,7 +331,8 @@ osg::Node* createPreRenderSubGraph(osg::Node* subgraph, unsigned tex_width, unsi
if (useImage)
{
osg::Image* image = new osg::Image;
image->allocateImage(tex_width, tex_height, 1, GL_RGBA, GL_UNSIGNED_BYTE);
//image->allocateImage(tex_width, tex_height, 1, GL_RGBA, GL_UNSIGNED_BYTE);
image->allocateImage(tex_width, tex_height, 1, GL_RGBA, GL_FLOAT);
// attach the image so its copied on each frame.
camera->attach(osg::CameraNode::COLOR_BUFFER, image);
@@ -385,6 +419,8 @@ int main( int argc, char **argv )
bool useTextureRectangle = false;
while (arguments.read("--texture-rectangle")) { useTextureRectangle = true; }
bool useHDR = false;
while (arguments.read("--hdr")) { useHDR = true; }
// any option left unread are converted into errors to write out later.
arguments.reportRemainingOptionsAsUnrecognized();
@@ -418,7 +454,7 @@ int main( int argc, char **argv )
loadedModelTransform->setUpdateCallback(nc);
osg::Group* rootNode = new osg::Group();
rootNode->addChild(createPreRenderSubGraph(loadedModelTransform,tex_width,tex_height, renderImplementation, useImage, useTextureRectangle));
rootNode->addChild(createPreRenderSubGraph(loadedModelTransform,tex_width,tex_height, renderImplementation, useImage, useTextureRectangle, useHDR));
// add model to the viewer.
@@ -447,3 +483,4 @@ int main( int argc, char **argv )
return 0;
}

View File

@@ -342,8 +342,21 @@ class OSG_EXPORT Texture : public osg::StateAttribute
/** Gets the internal texture format. */
inline GLint getInternalFormat() const { if (_internalFormat==0) computeInternalFormat(); return _internalFormat; }
/** Return true if the internal format is one of the compressed formats.*/
bool isCompressedInternalFormat() const;
/** Sets the external source image format, used as a fallback when no osg::Image is attached to provide the source image format. */
inline void setSourceFormat(GLenum sourceFormat) { _sourceFormat = sourceFormat; }
/** Gets the external source image format. */
inline GLenum getSourceFormat() const { return _sourceFormat; }
/** Sets the external source data type, used as a fallback when no osg::Image is attached to provide the source image format.*/
inline void setSourceType(GLenum sourceType) { _sourceType = sourceType; }
/** Gets the external source data type.*/
inline GLenum getSourceType() const { return _sourceType; }
class TextureObject;
@@ -594,6 +607,8 @@ class OSG_EXPORT Texture : public osg::StateAttribute
InternalFormatMode _internalFormatMode;
mutable GLint _internalFormat;
mutable GLenum _sourceFormat;
mutable GLenum _sourceType;
bool _use_shadow_comparison;
ShadowCompareFunc _shadow_compare_func;

View File

@@ -345,6 +345,8 @@ Texture::Texture():
_borderWidth(0),
_internalFormatMode(USE_IMAGE_DATA_FORMAT),
_internalFormat(0),
_sourceFormat(0),
_sourceType(GL_UNSIGNED_BYTE),
_use_shadow_comparison(false),
_shadow_compare_func(LEQUAL),
_shadow_texture_mode(LUMINANCE),
@@ -368,6 +370,8 @@ Texture::Texture(const Texture& text,const CopyOp& copyop):
_borderWidth(text._borderWidth),
_internalFormatMode(text._internalFormatMode),
_internalFormat(text._internalFormat),
_sourceFormat(text._sourceFormat),
_sourceType(text._sourceType),
_use_shadow_comparison(text._use_shadow_comparison),
_shadow_compare_func(text._shadow_compare_func),
_shadow_texture_mode(text._shadow_texture_mode),
@@ -398,6 +402,9 @@ int Texture::compareTexture(const Texture& rhs) const
COMPARE_StateAttribute_Parameter(_internalFormat)
}
COMPARE_StateAttribute_Parameter(_sourceFormat)
COMPARE_StateAttribute_Parameter(_sourceType)
COMPARE_StateAttribute_Parameter(_use_shadow_comparison)
COMPARE_StateAttribute_Parameter(_shadow_compare_func)
COMPARE_StateAttribute_Parameter(_shadow_texture_mode)

View File

@@ -158,6 +158,28 @@ void Texture1D::apply(State& state) const
non_const_this->_image = 0;
}
}
else if ( (_textureWidth!=0) && (_internalFormat!=0) )
{
_textureObjectBuffer[contextID] = textureObject = generateTextureObject(
contextID,GL_TEXTURE_1D,_numMipmapLevels,_internalFormat,_textureWidth,1,1,0);
textureObject->bind();
applyTexParameters(GL_TEXTURE_1D,state);
// no image present, but dimensions at set so lets create the texture
glTexImage1D( GL_TEXTURE_1D, 0, _internalFormat,
_textureWidth, _borderWidth,
_sourceFormat ? _sourceFormat : _internalFormat,
_sourceType ? _sourceType : GL_UNSIGNED_BYTE,
0);
if (_readPBuffer.valid())
{
_readPBuffer->bindPBufferToTexture(GL_FRONT);
}
}
else
{

View File

@@ -222,8 +222,8 @@ void Texture2D::apply(State& state) const
// no image present, but dimensions at set so lets create the texture
glTexImage2D( GL_TEXTURE_2D, 0, _internalFormat,
_textureWidth, _textureHeight, _borderWidth,
_internalFormat,
GL_UNSIGNED_BYTE,
_sourceFormat ? _sourceFormat : _internalFormat,
_sourceType ? _sourceType : GL_UNSIGNED_BYTE,
0);
if (_readPBuffer.valid())

View File

@@ -240,6 +240,29 @@ void Texture3D::apply(State& state) const
non_const_this->_image = 0;
}
}
else if ( (_textureWidth!=0) && (_textureHeight!=0) && (_textureDepth!=0) && (_internalFormat!=0) )
{
_textureObjectBuffer[contextID] = textureObject = generateTextureObject(
contextID,GL_TEXTURE_3D,_numMipmapLevels,_internalFormat,_textureWidth,_textureHeight,_textureDepth,0);
textureObject->bind();
applyTexParameters(GL_TEXTURE_3D,state);
// no image present, but dimensions at set so lets create the texture
extensions->glTexImage3D( GL_TEXTURE_3D, 0, _internalFormat,
_textureWidth, _textureHeight, _textureDepth,
_borderWidth,
_sourceFormat ? _sourceFormat : _internalFormat,
_sourceType ? _sourceType : GL_UNSIGNED_BYTE,
0);
if (_readPBuffer.valid())
{
_readPBuffer->bindPBufferToTexture(GL_FRONT);
}
}
else
{

View File

@@ -264,8 +264,8 @@ void TextureCubeMap::apply(State& state) const
// no image present, but dimensions at set so less create the texture
glTexImage2D( faceTarget[n], 0, _internalFormat,
_textureWidth, _textureHeight, _borderWidth,
_internalFormat,
GL_UNSIGNED_BYTE,
_sourceFormat ? _sourceFormat : _internalFormat,
_sourceType ? _sourceType : GL_UNSIGNED_BYTE,
0);
}

View File

@@ -205,8 +205,8 @@ void TextureRectangle::apply(State& state) const
// no image present, but dimensions at set so lets create the texture
glTexImage2D( GL_TEXTURE_RECTANGLE, 0, _internalFormat,
_textureWidth, _textureHeight, _borderWidth,
_internalFormat,
GL_UNSIGNED_BYTE,
_sourceFormat ? _sourceFormat : _internalFormat,
_sourceType ? _sourceType : GL_UNSIGNED_BYTE,
0);
if (_readPBuffer.valid())