Restructured the way that applyTexParameters() is applied to address issues with Intel drivers not handling mipmap generations unless the tex parameters are reapplied on new upload of data.

This commit is contained in:
Robert Osfield 2018-02-27 17:35:13 +00:00
parent 39881b5576
commit 7b6eedbdf4
5 changed files with 45 additions and 13 deletions

View File

@ -160,10 +160,10 @@ void Texture1D::apply(State& state) const
{ {
textureObject->bind(); textureObject->bind();
if (getTextureParameterDirty(state.getContextID())) applyTexParameters(GL_TEXTURE_1D,state);
if (_subloadCallback.valid()) if (_subloadCallback.valid())
{ {
applyTexParameters(GL_TEXTURE_1D,state);
_subloadCallback->subload(*this,state); _subloadCallback->subload(*this,state);
} }
else if (_image.valid() && getModifiedCount(contextID) != _image->getModifiedCount()) else if (_image.valid() && getModifiedCount(contextID) != _image->getModifiedCount())
@ -171,9 +171,14 @@ void Texture1D::apply(State& state) const
// update the modified count to show that it is up to date. // update the modified count to show that it is up to date.
getModifiedCount(contextID) = _image->getModifiedCount(); getModifiedCount(contextID) = _image->getModifiedCount();
applyTexParameters(GL_TEXTURE_1D,state);
applyTexImage1D(GL_TEXTURE_1D,_image.get(),state, _textureWidth, _numMipmapLevels); applyTexImage1D(GL_TEXTURE_1D,_image.get(),state, _textureWidth, _numMipmapLevels);
} }
if (getTextureParameterDirty(state.getContextID()))
applyTexParameters(GL_TEXTURE_1D,state);
} }
else if (_subloadCallback.valid()) else if (_subloadCallback.valid())
{ {

View File

@ -193,11 +193,10 @@ void Texture2D::apply(State& state) const
{ {
textureObject->bind(); textureObject->bind();
if (getTextureParameterDirty(state.getContextID()))
applyTexParameters(GL_TEXTURE_2D,state);
if (_subloadCallback.valid()) if (_subloadCallback.valid())
{ {
applyTexParameters(GL_TEXTURE_2D,state);
_subloadCallback->subload(*this,state); _subloadCallback->subload(*this,state);
} }
else if (_image.valid() && getModifiedCount(contextID) != _image->getModifiedCount()) else if (_image.valid() && getModifiedCount(contextID) != _image->getModifiedCount())
@ -205,6 +204,8 @@ void Texture2D::apply(State& state) const
// update the modified tag to show that it is up to date. // update the modified tag to show that it is up to date.
getModifiedCount(contextID) = _image->getModifiedCount(); getModifiedCount(contextID) = _image->getModifiedCount();
applyTexParameters(GL_TEXTURE_2D,state);
applyTexImage2D_subload(state,GL_TEXTURE_2D,_image.get(), applyTexImage2D_subload(state,GL_TEXTURE_2D,_image.get(),
_textureWidth, _textureHeight, _internalFormat, _numMipmapLevels); _textureWidth, _textureHeight, _internalFormat, _numMipmapLevels);
} }
@ -213,6 +214,9 @@ void Texture2D::apply(State& state) const
_readPBuffer->bindPBufferToTexture(GL_FRONT); _readPBuffer->bindPBufferToTexture(GL_FRONT);
} }
if (getTextureParameterDirty(state.getContextID()))
applyTexParameters(GL_TEXTURE_2D,state);
} }
else if (_subloadCallback.valid()) else if (_subloadCallback.valid())
{ {

View File

@ -278,16 +278,16 @@ void Texture2DArray::apply(State& state) const
// bind texture object // bind texture object
textureObject->bind(); textureObject->bind();
// if texture parameters changed, then reset them
if (getTextureParameterDirty(state.getContextID())) applyTexParameters(GL_TEXTURE_2D_ARRAY_EXT,state);
// if subload is specified, then use it to subload the images to GPU memory // if subload is specified, then use it to subload the images to GPU memory
if (_subloadCallback.valid()) if (_subloadCallback.valid())
{ {
applyTexParameters(GL_TEXTURE_2D_ARRAY_EXT,state);
_subloadCallback->subload(*this,state); _subloadCallback->subload(*this,state);
} }
else else
{ {
bool applyParameters = true;
GLsizei n = 0; GLsizei n = 0;
for(Images::const_iterator itr = _images.begin(); for(Images::const_iterator itr = _images.begin();
itr != _images.end(); itr != _images.end();
@ -299,13 +299,23 @@ void Texture2DArray::apply(State& state) const
if (getModifiedCount(n,contextID) != image->getModifiedCount()) if (getModifiedCount(n,contextID) != image->getModifiedCount())
{ {
getModifiedCount(n,contextID) = image->getModifiedCount(); getModifiedCount(n,contextID) = image->getModifiedCount();
if (applyParameters)
{
applyTexParameters(GL_TEXTURE_2D_ARRAY_EXT,state);
applyParameters = false;
}
applyTexImage2DArray_subload(state, image, n, _textureWidth, _textureHeight, image->r(), _internalFormat, _numMipmapLevels); applyTexImage2DArray_subload(state, image, n, _textureWidth, _textureHeight, image->r(), _internalFormat, _numMipmapLevels);
} }
n += image->r(); n += image->r();
} }
} }
} }
// if texture parameters changed, then reset them
if (getTextureParameterDirty(state.getContextID()))
applyTexParameters(GL_TEXTURE_2D_ARRAY_EXT,state);
} }
// there is no texture object, but exists a subload callback, so use it to upload images // there is no texture object, but exists a subload callback, so use it to upload images

View File

@ -241,10 +241,10 @@ void Texture3D::apply(State& state) const
// we have a valid image // we have a valid image
textureObject->bind(); textureObject->bind();
if (getTextureParameterDirty(state.getContextID())) applyTexParameters(GL_TEXTURE_3D,state);
if (_subloadCallback.valid()) if (_subloadCallback.valid())
{ {
applyTexParameters(GL_TEXTURE_3D,state);
_subloadCallback->subload(*this,state); _subloadCallback->subload(*this,state);
} }
else if (_image.get() && getModifiedCount(contextID) != _image->getModifiedCount()) else if (_image.get() && getModifiedCount(contextID) != _image->getModifiedCount())
@ -252,11 +252,16 @@ void Texture3D::apply(State& state) const
// update the modified count to show that it is up to date. // update the modified count to show that it is up to date.
getModifiedCount(contextID) = _image->getModifiedCount(); getModifiedCount(contextID) = _image->getModifiedCount();
applyTexParameters(GL_TEXTURE_3D,state);
computeRequiredTextureDimensions(state,*_image,_textureWidth, _textureHeight, _textureDepth,_numMipmapLevels); computeRequiredTextureDimensions(state,*_image,_textureWidth, _textureHeight, _textureDepth,_numMipmapLevels);
applyTexImage3D(GL_TEXTURE_3D,_image.get(),state, _textureWidth, _textureHeight, _textureDepth,_numMipmapLevels); applyTexImage3D(GL_TEXTURE_3D,_image.get(),state, _textureWidth, _textureHeight, _textureDepth,_numMipmapLevels);
} }
if (getTextureParameterDirty(state.getContextID()))
applyTexParameters(GL_TEXTURE_3D,state);
} }
else if (_subloadCallback.valid()) else if (_subloadCallback.valid())
{ {

View File

@ -233,24 +233,32 @@ void TextureCubeMap::apply(State& state) const
{ {
textureObject->bind(); textureObject->bind();
if (getTextureParameterDirty(state.getContextID())) applyTexParameters(GL_TEXTURE_CUBE_MAP,state);
if (_subloadCallback.valid()) if (_subloadCallback.valid())
{ {
applyTexParameters(GL_TEXTURE_CUBE_MAP,state);
_subloadCallback->subload(*this,state); _subloadCallback->subload(*this,state);
} }
else else
{ {
bool applyParameters = true;
for (int n=0; n<6; n++) for (int n=0; n<6; n++)
{ {
const osg::Image* image = _images[n].get(); const osg::Image* image = _images[n].get();
if (image && getModifiedCount((Face)n,contextID) != image->getModifiedCount()) if (image && getModifiedCount((Face)n,contextID) != image->getModifiedCount())
{ {
getModifiedCount((Face)n,contextID) = image->getModifiedCount(); getModifiedCount((Face)n,contextID) = image->getModifiedCount();
if (applyParameters)
{
applyTexParameters(GL_TEXTURE_CUBE_MAP,state);
applyParameters = false;
}
applyTexImage2D_subload( state, faceTarget[n], _images[n].get(), _textureWidth, _textureHeight, _internalFormat, _numMipmapLevels); applyTexImage2D_subload( state, faceTarget[n], _images[n].get(), _textureWidth, _textureHeight, _internalFormat, _numMipmapLevels);
} }
} }
} }
if (getTextureParameterDirty(state.getContextID()))
applyTexParameters(GL_TEXTURE_CUBE_MAP,state);
} }
else if (_subloadCallback.valid()) else if (_subloadCallback.valid())