Merge pull request #1711 from marauder2k9-torque/GLFix-BlackTerrain-issue
Some checks failed
Linux Build / Ubuntu Latest GCC (push) Has been cancelled
MacOSX Build / MacOSX Latest Clang (push) Has been cancelled
Windows Build / Windows Latest MSVC (push) Has been cancelled

OPENGL: Terrain doesnt render correctly
This commit is contained in:
Brian Roberts 2026-04-11 18:12:37 -05:00 committed by GitHub
commit 12dddd07b5
No known key found for this signature in database
GPG key ID: B5690EEEBB952194
5 changed files with 447 additions and 549 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 );
}

File diff suppressed because it is too large Load diff

View file

@ -57,6 +57,24 @@
#include "gfx/gl/tGL/tXGL.h"
#endif
#pragma region GL WARNINGS
// #131204 - Texture state usage warning: The texture object (0) bound to texture image unit 0
#define GL_LOW_WARN_TEXTURE_STATE 131204
// #131169 - Framebuffer detailed info: The driver allocated storage for renderbuffer 2. (severity: low)
#define GL_LOW_WARN_FRAMEBUFFER 131169
// #131185 - Buffer detailed info: Buffer object 1 (bound to GL_ELEMENT_ARRAY_BUFFER_ARB, usage hint is GL_ENUM_88e4)
// will use VIDEO memory as the source for buffer object operations. (severity: low)
#define GL_LOW_WARN_VIDEO_MEMORY 131185
// #131218 - Program/shader state performance warning: Vertex shader in program #
// is being recompiled based on GL state. (severity: medium)
#define GL_MED_WARN_PERFORMANCE_RECOMPILE 131218
#pragma endregion
GFXAdapter::CreateDeviceInstanceDelegate GFXGLDevice::mCreateDeviceInstance(GFXGLDevice::createInstance);
GFXDevice *GFXGLDevice::createInstance( U32 adapterIndex )
@ -104,6 +122,10 @@ void APIENTRY glDebugCallback(
if (severity == GL_DEBUG_SEVERITY_NOTIFICATION)
return;
// Silence: Texture state usage warning: The texture object (0) bound to texture image unit 0
if (id == GL_LOW_WARN_TEXTURE_STATE)
return;
const char* srcStr = "UNKNOWN";
const char* typeStr = "UNKNOWN";
const char* sevStr = "UNKNOWN";

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);