Added applyTexImage_subload() implemention into TextureRectangle class

to provide automatic support for texture subloading.
This commit is contained in:
Robert Osfield
2003-08-18 19:36:50 +00:00
parent c334279935
commit 0685c2a852
2 changed files with 48 additions and 3 deletions

View File

@@ -96,7 +96,8 @@ class SG_EXPORT TextureRectangle : public Texture
void applyTexParameters(GLenum target, State& state) const;
void applyTexImage(GLenum target, Image* image, State& state, GLsizei& inwidth, GLsizei& inheight) const;
void applyTexImage_load(GLenum target, Image* image, State& state, GLsizei& inwidth, GLsizei& inheight) const;
void applyTexImage_subload(GLenum target, Image* image, State& state, GLsizei& inwidth, GLsizei& inheight) const;
// not ideal that _image is mutable, but its required since
// Image::ensureDimensionsArePowerOfTwo() can only be called

View File

@@ -113,7 +113,16 @@ void TextureRectangle::apply(State& state) const
applyTexParameters(GL_TEXTURE_RECTANGLE_NV, state);
if (_subloadCallback.valid())
{
_subloadCallback->subload(*this, state);
}
else if (_image.valid() && getModifiedTag(contextID) != _image->getModifiedTag())
{
applyTexImage_subload(GL_TEXTURE_RECTANGLE_NV, _image.get(), state, _textureWidth, _textureHeight);
// update the modified tag to show that it is upto date.
getModifiedTag(contextID) = _image->getModifiedTag();
}
}
else if (_subloadCallback.valid())
{
@@ -143,7 +152,7 @@ void TextureRectangle::apply(State& state) const
applyTexParameters(GL_TEXTURE_RECTANGLE_NV, state);
applyTexImage(GL_TEXTURE_RECTANGLE_NV, _image.get(), state, _textureWidth, _textureHeight);
applyTexImage_load(GL_TEXTURE_RECTANGLE_NV, _image.get(), state, _textureWidth, _textureHeight);
textureObject->setAllocated(1,_internalFormat,_textureWidth,_textureHeight,1,0);
@@ -174,7 +183,7 @@ void TextureRectangle::applyTexParameters(GLenum target, State& state) const
getTextureParameterDirty(contextID) = false;
}
void TextureRectangle::applyTexImage(GLenum target, Image* image, State& state, GLsizei& inwidth, GLsizei& inheight) const
void TextureRectangle::applyTexImage_load(GLenum target, Image* image, State& state, GLsizei& inwidth, GLsizei& inheight) const
{
// if we don't have a valid image we can't create a texture!
if (!image || !image->data())
@@ -203,6 +212,41 @@ void TextureRectangle::applyTexImage(GLenum target, Image* image, State& state,
inheight = image->t();
}
void TextureRectangle::applyTexImage_subload(GLenum target, Image* image, State& state, GLsizei& inwidth, GLsizei& inheight) const
{
// if we don't have a valid image we can't create a texture!
if (!image || !image->data())
return;
if (image->s()!=inwidth || image->t()!=inheight)
{
applyTexImage_load(target, image, state, inwidth, inheight);
return;
}
// get the contextID (user defined ID of 0 upwards) for the
// current OpenGL context.
const unsigned int contextID = state.getContextID();
// update the modified tag to show that it is upto date.
getModifiedTag(contextID) = image->getModifiedTag();
// compute the internal texture format, sets _internalFormat.
computeInternalFormat();
glPixelStorei(GL_UNPACK_ALIGNMENT, image->getPacking());
// UH: ignoring compressed for now.
glTexSubImage2D(target, 0,
0,0,
image->s(), image->t(),
(GLenum)image->getPixelFormat(),
(GLenum)image->getDataType(),
image->data());
}
void TextureRectangle::computeInternalFormat() const
{
if (_image.valid())