Terrain doesnt render correctly

The core of this issue was the unlock on the GFXGLTextureObject

Few other bug fixes around setting a texture binding to 0, notice in clear function we now also clear the glprogram and the buffers. This seems to fix most of the warnings around id 131204

This warning was triggered every frame, now it just triggers when a shader expects a texture but none is active.
This commit is contained in:
marauder2k7 2026-04-10 06:42:45 +01:00
parent 5796f0ea07
commit 93b5a8d22e
4 changed files with 39 additions and 78 deletions

View file

@ -1094,7 +1094,7 @@ void ScatterSky::_render( ObjectRenderInst *ri, SceneRenderState *state, BaseMat
}
else
{
GFX->setCubeTexture( 0, NULL );
GFX->setTexture( 0, NULL );
mShaderConsts->setSafe( mUseCubemapSC, 0.0f );
}

View file

@ -640,6 +640,10 @@ void GFXGLDevice::copyResource(GFXTextureObject* pDst, GFXCubemap* pSrc, const U
void GFXGLDevice::clear(U32 flags, const LinearColorF& color, F32 z, U32 stencil)
{
glUseProgram(0);
mCurrentShader = NULL;
mCurrentConstBuffer = NULL;
// Make sure we have flushed our render target state.
_updateRenderTargets();

View file

@ -480,10 +480,9 @@ bool GFXGLTextureManager::_loadTexture(GFXTextureObject *aTexture, GBitmap *pDL)
}
}
if(!ImageUtil::isCompressedFormat(pDL->getFormat()))
if (mipLevels > 1 && !ImageUtil::isCompressedFormat(pDL->getFormat()))
glGenerateMipmap(texture->getBinding());
glBindTexture(target, 0);
return true;
}
@ -560,10 +559,9 @@ bool GFXGLTextureManager::_loadTexture(GFXTextureObject *aTexture, DDSFile *dds)
}
}
if (numMips != 1 && !isCompressed)
if (numMips > 1 && !isCompressed)
glGenerateMipmap(texture->getBinding());
glBindTexture(target, 0);
return true;
}
@ -608,7 +606,7 @@ bool GFXGLTextureManager::_refreshTexture(GFXTextureObject *texture)
_loadTexture(texture, texture->mBitmap);
if(texture->mDDS)
return false;
_loadTexture(texture, texture->mDDS);
usedStrategies++;
}

View file

@ -102,79 +102,36 @@ GFXLockedRect* GFXGLTextureObject::lock(U32 mipLevel /*= 0*/, RectI* inRect /*=
void GFXGLTextureObject::unlock(U32 mipLevel /*= 0*/, U32 faceIndex /*= 0*/)
{
if (!mLockedRect.bits)
return;
if (!mLockedRect.bits)
return;
PROFILE_SCOPE(GFXGLTextureObject_unlock);
// I know this is in unlock, but in GL we actually do our submission in unlock.
PROFILE_SCOPE(GFXGLTextureObject_lockRT);
PRESERVE_TEXTURE(mBinding);
glBindTexture(mBinding, mHandle);
PRESERVE_TEXTURE(mBinding);
glBindTexture(mBinding, mHandle);
glBindBuffer(GL_PIXEL_UNPACK_BUFFER, mBuffer);
glBufferData(GL_PIXEL_UNPACK_BUFFER, (mLockedRectRect.extent.x + 1) * (mLockedRectRect.extent.y + 1) * mBytesPerTexel, mFrameAllocatorPtr, GL_STREAM_DRAW);
S32 z = getDepth();
if (mBinding == GL_TEXTURE_3D)
glTexSubImage3D(mBinding, mipLevel, mLockedRectRect.point.x, mLockedRectRect.point.y, z,
mLockedRectRect.extent.x, mLockedRectRect.extent.y, z, GFXGLTextureFormat[mFormat], GFXGLTextureType[mFormat], NULL);
else if (mBinding == GL_TEXTURE_2D)
glTexSubImage2D(mBinding, mipLevel, mLockedRectRect.point.x, mLockedRectRect.point.y,
mLockedRectRect.extent.x, mLockedRectRect.extent.y, GFXGLTextureFormat[mFormat], GFXGLTextureType[mFormat], NULL);
else if (mBinding == GL_TEXTURE_1D)
glTexSubImage1D(mBinding, mipLevel, (mLockedRectRect.point.x > 1 ? mLockedRectRect.point.x : mLockedRectRect.point.y),
(mLockedRectRect.extent.x > 1 ? mLockedRectRect.extent.x : mLockedRectRect.extent.y), GFXGLTextureFormat[mFormat], GFXGLTextureType[mFormat], NULL);
// --- Save pixel store state ---
GLint prevUnpackAlign;
glGetIntegerv(GL_UNPACK_ALIGNMENT, &prevUnpackAlign);
glBindBuffer(GL_PIXEL_UNPACK_BUFFER, 0);
glPixelStorei(GL_UNPACK_ALIGNMENT, 1);
const U32 width = mLockedRectRect.extent.x;
const U32 height = mLockedRectRect.extent.y;
const U32 depth = getDepth();
if (mBinding == GL_TEXTURE_3D)
{
glTexSubImage3D(
mBinding,
mipLevel,
mLockedRectRect.point.x,
mLockedRectRect.point.y,
0,
width,
height,
depth,
GFXGLTextureFormat[mFormat],
GFXGLTextureType[mFormat],
mLockedRect.bits
);
}
else if (mBinding == GL_TEXTURE_2D)
{
glTexSubImage2D(
mBinding,
mipLevel,
mLockedRectRect.point.x,
mLockedRectRect.point.y,
width,
height,
GFXGLTextureFormat[mFormat],
GFXGLTextureType[mFormat],
mLockedRect.bits
);
}
else if (mBinding == GL_TEXTURE_1D)
{
glTexSubImage1D(
mBinding,
mipLevel,
mLockedRectRect.point.x,
width,
GFXGLTextureFormat[mFormat],
GFXGLTextureType[mFormat],
mLockedRect.bits
);
}
// --- Restore state ---
glPixelStorei(GL_UNPACK_ALIGNMENT, prevUnpackAlign);
mLockedRect.bits = NULL;
FrameAllocator::setWaterMark(mFrameAllocatorMark);
mFrameAllocatorMark = 0;
mFrameAllocatorPtr = NULL;
#ifdef TORQUE_DEBUG
glCheckErrors();
mLockedRect.bits = NULL;
#if TORQUE_DEBUG
AssertFatal(mFrameAllocatorMarkGuard == FrameAllocator::getWaterMark(), "");
#endif
FrameAllocator::setWaterMark(mFrameAllocatorMark);
mFrameAllocatorMark = 0;
mFrameAllocatorPtr = NULL;
}
void GFXGLTextureObject::release()
@ -281,7 +238,6 @@ bool GFXGLTextureObject::copyToBmp(GBitmap * bmp)
} // face
} // mip
glBindTexture(mBinding, 0);
return true;
}
@ -298,6 +254,9 @@ void GFXGLTextureObject::updateTextureSlot(const GFXTexHandle& texHandle, const
const GLenum srcTarget = srcTex->getBinding(); // source binding
const bool srcIsCube = (srcTarget == GL_TEXTURE_CUBE_MAP || srcTarget == GL_TEXTURE_CUBE_MAP_ARRAY);
PRESERVE_TEXTURE(srcTarget);
PRESERVE_TEXTURE(dstTarget);
// Determine list of faces to copy from source
U32 firstFace = 0;
U32 faceCount = 1;
@ -435,9 +394,6 @@ void GFXGLTextureObject::updateTextureSlot(const GFXTexHandle& texHandle, const
GFXGLTextureFormat[mFormat], GFXGLTextureType[mFormat], buffer);
}
}
glBindTexture(dstTarget, 0);
glBindTexture(srcTarget, 0);
}
}
@ -462,6 +418,9 @@ void GFXGLTextureObject::initSamplerState(const GFXSamplerStateDesc &ssd)
void GFXGLTextureObject::bind(U32 textureUnit)
{
if (!mHandle || mIsZombie)
return;
glActiveTexture(GL_TEXTURE0 + textureUnit);
glBindTexture(mBinding, mHandle);
GFXGL->getOpenglCache()->setCacheBindedTex(textureUnit, mBinding, mHandle);