Improved support for texture subload/render to texture in various Texture classes

and RenderStage.
This commit is contained in:
Robert Osfield
2005-11-04 12:08:16 +00:00
parent 89b0ef09a8
commit 4915259878
13 changed files with 123 additions and 33 deletions

View File

@@ -71,16 +71,10 @@ class OSG_EXPORT Texture1D : public Texture
/** Sets the texture width. If width is zero, calculate the value
* from the source image width. */
inline void setTextureSize(int width) const
{
_textureWidth = width;
}
inline void setTextureWidth(int width) const { _textureWidth = width; }
/** Gets the texture subload width. */
inline void getTextureSize(int& width) const
{
width = _textureWidth;
}
/** Gets the texture width. */
inline int getTextureWidth() const { return _textureWidth; }
class OSG_EXPORT SubloadCallback : public Referenced

View File

@@ -84,6 +84,15 @@ class OSG_EXPORT Texture3D : public Texture
depth = _textureDepth;
}
void setTextureWidth(int width) { _textureWidth=width; }
int getTextureWidth() const { return _textureWidth; }
void setTextureHeight(int height) { _textureHeight=height; }
int getTextureHeight() const { return _textureHeight; }
void setTextureDepth(int depth) { _textureDepth=depth; }
int getTextureDepth() const { return _textureDepth; }
class OSG_EXPORT SubloadCallback : public Referenced
{

View File

@@ -85,13 +85,11 @@ class OSG_EXPORT TextureCubeMap : public Texture
_textureHeight = height;
}
/** Get the texture subload width. */
inline void getTextureSize(int& width, int& height) const
{
width = _textureWidth;
height = _textureHeight;
}
void setTextureWidth(int width) { _textureWidth=width; }
int getTextureWidth() const { return _textureWidth; }
void setTextureHeight(int height) { _textureHeight=height; }
int getTextureHeight() const { return _textureHeight; }
class OSG_EXPORT SubloadCallback : public Referenced
{

View File

@@ -84,12 +84,11 @@ class OSG_EXPORT TextureRectangle : public Texture
_textureHeight = height;
}
/** Get the texture subload width. */
inline void getTextureSize(int& width, int& height) const
{
width = _textureWidth;
height = _textureHeight;
}
void setTextureWidth(int width) { _textureWidth=width; }
int getTextureWidth() const { return _textureWidth; }
void setTextureHeight(int height) { _textureHeight=height; }
int getTextureHeight() const { return _textureHeight; }
class SubloadCallback : public Referenced
{

View File

@@ -62,12 +62,12 @@ void CameraNode::setRenderTargetImplementation(RenderTargetImplementation impl)
void CameraNode::setRenderTargetImplementation(RenderTargetImplementation impl, RenderTargetImplementation fallback)
{
if (impl<fallback)
if (impl<fallback || (impl==FRAME_BUFFER && fallback==FRAME_BUFFER))
{
_renderTargetImplementation = impl;
_renderTargetFallback = fallback;
}
else
else
{
osg::notify(osg::NOTICE)<<"Warning: CameraNode::setRenderTargetImplementation(impl,fallback) must have a lower rated fallback than the main target implementation."<<std::endl;
setRenderTargetImplementation(impl);

View File

@@ -291,6 +291,10 @@ void TextureCubeMap::copyTexSubImageCubeMap(State& state, int face, int xoffset,
if (!textureObject)
{
if (_textureWidth==0) _textureWidth = width;
if (_textureHeight==0) _textureHeight = height;
// create texture object.
apply(state);

View File

@@ -193,6 +193,28 @@ void TextureRectangle::apply(State& state) const
non_const_this->_image = 0;
}
}
else if ( (_textureWidth!=0) && (_textureHeight!=0) && (_internalFormat!=0) )
{
_textureObjectBuffer[contextID] = textureObject = generateTextureObject(
contextID,GL_TEXTURE_RECTANGLE,0,_internalFormat,_textureWidth,_textureHeight,1,0);
textureObject->bind();
applyTexParameters(GL_TEXTURE_RECTANGLE,state);
// 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,
0);
if (_readPBuffer.valid())
{
_readPBuffer->bindPBufferToTexture(GL_FRONT);
}
}
else
{
glBindTexture(GL_TEXTURE_RECTANGLE, 0);

View File

@@ -32,10 +32,8 @@ void TextureCubeMap::write(DataOutputStream* out){
// Write TextureCubeMap's properties.
// Write texture size
int width,height;
getTextureSize(width, height);
out->writeInt(width);
out->writeInt(height);
out->writeInt(getTextureWidth());
out->writeInt(getTextureHeight());
// Write number of mipmap levels
out->writeInt(getNumMipmapLevels());

View File

@@ -184,7 +184,54 @@ void RenderStage::runCameraSetUp(osg::State& state)
_imageReadPixelFormat = pixelFormat;
_imageReadPixelDataType = dataType;
setImage(itr->second._image.get());
setImage(itr->second._image.get());
}
if (itr->second._texture.valid())
{
osg::Texture* texture = itr->second._texture.get();
osg::Texture1D* texture1D = 0;
osg::Texture2D* texture2D = 0;
osg::Texture3D* texture3D = 0;
osg::TextureCubeMap* textureCubeMap = 0;
osg::TextureRectangle* textureRectangle = 0;
if (0 != (texture1D=dynamic_cast<osg::Texture1D*>(texture)))
{
if (texture1D->getTextureWidth()==0)
{
texture1D->setTextureWidth(_viewport->width());
}
}
else if (0 != (texture2D = dynamic_cast<osg::Texture2D*>(texture)))
{
if (texture2D->getTextureWidth()==0 || texture2D->getTextureHeight()==0)
{
texture2D->setTextureSize(_viewport->width(),_viewport->height());
}
}
else if (0 != (texture3D = dynamic_cast<osg::Texture3D*>(texture)))
{
if (texture3D->getTextureWidth()==0 || texture3D->getTextureHeight()==0 || texture3D->getTextureDepth()==0 )
{
// note we dont' have the depth here, so we'll heave to assume that height and depth are the same..
texture3D->setTextureSize(_viewport->width(),_viewport->height(),_viewport->height());
}
}
else if (0 != (textureCubeMap = dynamic_cast<osg::TextureCubeMap*>(texture)))
{
if (textureCubeMap->getTextureWidth()==0 || textureCubeMap->getTextureHeight()==0)
{
textureCubeMap->setTextureSize(_viewport->width(),_viewport->height());
}
}
else if (0 != (textureRectangle = dynamic_cast<osg::TextureRectangle*>(texture)))
{
if (textureRectangle->getTextureWidth()==0 || textureRectangle->getTextureHeight()==0)
{
textureRectangle->setTextureSize(_viewport->width(),_viewport->height());
}
}
}
}

View File

@@ -44,8 +44,8 @@ BEGIN_ABSTRACT_OBJECT_REFLECTOR(osg::Texture1D)
I_Method1(osg::Image *, getImage, IN, unsigned, int);
I_Method1(const osg::Image *, getImage, IN, unsigned, int);
I_Method0(unsigned int, getNumImages);
I_Method1(void, setTextureSize, IN, int, width);
I_Method1(void, getTextureSize, IN, int &, width);
I_Method1(void, setTextureWidth, IN, int, width);
I_Method0(int, getTextureWidth);
I_Method1(void, setSubloadCallback, IN, osg::Texture1D::SubloadCallback *, cb);
I_Method0(osg::Texture1D::SubloadCallback *, getSubloadCallback);
I_Method0(const osg::Texture1D::SubloadCallback *, getSubloadCallback);
@@ -57,8 +57,8 @@ BEGIN_ABSTRACT_OBJECT_REFLECTOR(osg::Texture1D)
I_Property(osg::Image *, Image);
I_WriteOnlyProperty(unsigned int, NumMipmapLevels);
I_Property(osg::Texture1D::SubloadCallback *, SubloadCallback);
I_WriteOnlyProperty(int, TextureSize);
I_ReadOnlyProperty(GLenum, TextureTarget);
I_Property(int, TextureWidth);
I_ReadOnlyProperty(osg::StateAttribute::Type, Type);
END_REFLECTOR

View File

@@ -46,6 +46,12 @@ BEGIN_ABSTRACT_OBJECT_REFLECTOR(osg::Texture3D)
I_Method0(unsigned int, getNumImages);
I_Method3(void, setTextureSize, IN, int, width, IN, int, height, IN, int, depth);
I_Method3(void, getTextureSize, IN, int &, width, IN, int &, height, IN, int &, depth);
I_Method1(void, setTextureWidth, IN, int, width);
I_Method0(int, getTextureWidth);
I_Method1(void, setTextureHeight, IN, int, height);
I_Method0(int, getTextureHeight);
I_Method1(void, setTextureDepth, IN, int, depth);
I_Method0(int, getTextureDepth);
I_Method1(void, setSubloadCallback, IN, osg::Texture3D::SubloadCallback *, cb);
I_Method0(osg::Texture3D::SubloadCallback *, getSubloadCallback);
I_Method0(const osg::Texture3D::SubloadCallback *, getSubloadCallback);
@@ -56,7 +62,10 @@ BEGIN_ABSTRACT_OBJECT_REFLECTOR(osg::Texture3D)
I_Property(osg::Image *, Image);
I_WriteOnlyProperty(unsigned int, NumMipmapLevels);
I_Property(osg::Texture3D::SubloadCallback *, SubloadCallback);
I_Property(int, TextureDepth);
I_Property(int, TextureHeight);
I_ReadOnlyProperty(GLenum, TextureTarget);
I_Property(int, TextureWidth);
I_ReadOnlyProperty(osg::StateAttribute::Type, Type);
END_REFLECTOR

View File

@@ -51,7 +51,10 @@ BEGIN_OBJECT_REFLECTOR(osg::TextureCubeMap)
I_Method0(unsigned int, getNumImages);
I_Method2(unsigned int &, getModifiedCount, IN, unsigned int, face, IN, unsigned int, contextID);
I_Method2(void, setTextureSize, IN, int, width, IN, int, height);
I_Method2(void, getTextureSize, IN, int &, width, IN, int &, height);
I_Method1(void, setTextureWidth, IN, int, width);
I_Method0(int, getTextureWidth);
I_Method1(void, setTextureHeight, IN, int, height);
I_Method0(int, getTextureHeight);
I_Method1(void, setSubloadCallback, IN, osg::TextureCubeMap::SubloadCallback *, cb);
I_Method0(osg::TextureCubeMap::SubloadCallback *, getSubloadCallback);
I_Method0(const osg::TextureCubeMap::SubloadCallback *, getSubloadCallback);
@@ -62,7 +65,9 @@ BEGIN_OBJECT_REFLECTOR(osg::TextureCubeMap)
I_ArrayProperty_G(osg::Image *, Image, Images, unsigned int, void);
I_WriteOnlyProperty(unsigned int, NumMipmapLevels);
I_Property(osg::TextureCubeMap::SubloadCallback *, SubloadCallback);
I_Property(int, TextureHeight);
I_ReadOnlyProperty(GLenum, TextureTarget);
I_Property(int, TextureWidth);
I_ReadOnlyProperty(osg::StateAttribute::Type, Type);
END_REFLECTOR

View File

@@ -46,7 +46,10 @@ BEGIN_ABSTRACT_OBJECT_REFLECTOR(osg::TextureRectangle)
I_Method1(const osg::Image *, getImage, IN, unsigned, int);
I_Method0(unsigned int, getNumImages);
I_Method2(void, setTextureSize, IN, int, width, IN, int, height);
I_Method2(void, getTextureSize, IN, int &, width, IN, int &, height);
I_Method1(void, setTextureWidth, IN, int, width);
I_Method0(int, getTextureWidth);
I_Method1(void, setTextureHeight, IN, int, height);
I_Method0(int, getTextureHeight);
I_Method1(void, setSubloadCallback, IN, osg::TextureRectangle::SubloadCallback *, cb);
I_Method0(osg::TextureRectangle::SubloadCallback *, getSubloadCallback);
I_Method0(const osg::TextureRectangle::SubloadCallback *, getSubloadCallback);
@@ -55,7 +58,9 @@ BEGIN_ABSTRACT_OBJECT_REFLECTOR(osg::TextureRectangle)
I_Method1(void, apply, IN, osg::State &, state);
I_Property(osg::Image *, Image);
I_Property(osg::TextureRectangle::SubloadCallback *, SubloadCallback);
I_Property(int, TextureHeight);
I_ReadOnlyProperty(GLenum, TextureTarget);
I_Property(int, TextureWidth);
I_ReadOnlyProperty(osg::StateAttribute::Type, Type);
END_REFLECTOR