diff --git a/examples/osgprerender/osgprerender.cpp b/examples/osgprerender/osgprerender.cpp index 06ed7c6af..fc50c0c32 100644 --- a/examples/osgprerender/osgprerender.cpp +++ b/examples/osgprerender/osgprerender.cpp @@ -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; rdata(column_start, r); + for(int c=column_start; cdirty(); + } + } 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; } + diff --git a/include/osg/Texture b/include/osg/Texture index 231d79a47..9537c363b 100644 --- a/include/osg/Texture +++ b/include/osg/Texture @@ -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; diff --git a/src/osg/Texture.cpp b/src/osg/Texture.cpp index 07d766877..95efffd08 100644 --- a/src/osg/Texture.cpp +++ b/src/osg/Texture.cpp @@ -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) diff --git a/src/osg/Texture1D.cpp b/src/osg/Texture1D.cpp index 60bf5cb2a..9f17bb3f0 100644 --- a/src/osg/Texture1D.cpp +++ b/src/osg/Texture1D.cpp @@ -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 { diff --git a/src/osg/Texture2D.cpp b/src/osg/Texture2D.cpp index 832610289..60e075c14 100644 --- a/src/osg/Texture2D.cpp +++ b/src/osg/Texture2D.cpp @@ -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()) diff --git a/src/osg/Texture3D.cpp b/src/osg/Texture3D.cpp index 82a46d5be..28157e98e 100644 --- a/src/osg/Texture3D.cpp +++ b/src/osg/Texture3D.cpp @@ -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 { diff --git a/src/osg/TextureCubeMap.cpp b/src/osg/TextureCubeMap.cpp index e68199b04..cce4bf947 100644 --- a/src/osg/TextureCubeMap.cpp +++ b/src/osg/TextureCubeMap.cpp @@ -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); } diff --git a/src/osg/TextureRectangle.cpp b/src/osg/TextureRectangle.cpp index 75fd5cccf..d51559ba6 100644 --- a/src/osg/TextureRectangle.cpp +++ b/src/osg/TextureRectangle.cpp @@ -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())