From c076d5ad083170a3198588a6a944da08419650a3 Mon Sep 17 00:00:00 2001 From: rdb Date: Tue, 7 Feb 2023 12:26:41 +0100 Subject: [PATCH] showbase: Don't return same texture object if loaded with different settings Follow-up to #1105 --- direct/src/showbase/Loader.py | 70 ++++++++++++++++++----------------- 1 file changed, 37 insertions(+), 33 deletions(-) diff --git a/direct/src/showbase/Loader.py b/direct/src/showbase/Loader.py index 0c752d0a33..b0a8594f08 100644 --- a/direct/src/showbase/Loader.py +++ b/direct/src/showbase/Loader.py @@ -718,23 +718,24 @@ class Loader(DirectObject): flags &= ~LoaderOptions.TFMultiview loaderOptions.setTextureFlags(flags) + sampler = SamplerState() + if minfilter is not None: + sampler.setMinfilter(minfilter) + if magfilter is not None: + sampler.setMagfilter(magfilter) + if anisotropicDegree is not None: + sampler.setAnisotropicDegree(anisotropicDegree) + if alphaPath is None: assert Loader.notify.debug("Loading texture: %s" % (texturePath)) - texture = TexturePool.loadTexture(texturePath, 0, readMipmaps, loaderOptions) + texture = TexturePool.loadTexture(texturePath, 0, readMipmaps, loaderOptions, sampler) else: assert Loader.notify.debug("Loading texture: %s %s" % (texturePath, alphaPath)) - texture = TexturePool.loadTexture(texturePath, alphaPath, 0, 0, readMipmaps, loaderOptions) + texture = TexturePool.loadTexture(texturePath, alphaPath, 0, 0, readMipmaps, loaderOptions, sampler) if not texture and not okMissing: message = 'Could not load texture: %s' % (texturePath) raise IOError(message) - if minfilter is not None: - texture.setMinfilter(minfilter) - if magfilter is not None: - texture.setMagfilter(magfilter) - if anisotropicDegree is not None: - texture.setAnisotropicDegree(anisotropicDegree) - return texture def load3DTexture(self, texturePattern, readMipmaps = False, okMissing = False, @@ -780,18 +781,19 @@ class Loader(DirectObject): loaderOptions.setTextureFlags(flags) loaderOptions.setTextureNumViews(numViews) - texture = TexturePool.load3dTexture(texturePattern, readMipmaps, loaderOptions) + sampler = SamplerState() + if minfilter is not None: + sampler.setMinfilter(minfilter) + if magfilter is not None: + sampler.setMagfilter(magfilter) + if anisotropicDegree is not None: + sampler.setAnisotropicDegree(anisotropicDegree) + + texture = TexturePool.load3dTexture(texturePattern, readMipmaps, loaderOptions, sampler) if not texture and not okMissing: message = 'Could not load 3-D texture: %s' % (texturePattern) raise IOError(message) - if minfilter is not None: - texture.setMinfilter(minfilter) - if magfilter is not None: - texture.setMagfilter(magfilter) - if anisotropicDegree is not None: - texture.setAnisotropicDegree(anisotropicDegree) - return texture def load2DTextureArray(self, texturePattern, readMipmaps = False, okMissing = False, @@ -837,18 +839,19 @@ class Loader(DirectObject): loaderOptions.setTextureFlags(flags) loaderOptions.setTextureNumViews(numViews) - texture = TexturePool.load2dTextureArray(texturePattern, readMipmaps, loaderOptions) + sampler = SamplerState() + if minfilter is not None: + sampler.setMinfilter(minfilter) + if magfilter is not None: + sampler.setMagfilter(magfilter) + if anisotropicDegree is not None: + sampler.setAnisotropicDegree(anisotropicDegree) + + texture = TexturePool.load2dTextureArray(texturePattern, readMipmaps, loaderOptions, sampler) if not texture and not okMissing: message = 'Could not load 2-D texture array: %s' % (texturePattern) raise IOError(message) - if minfilter is not None: - texture.setMinfilter(minfilter) - if magfilter is not None: - texture.setMagfilter(magfilter) - if anisotropicDegree is not None: - texture.setAnisotropicDegree(anisotropicDegree) - return texture def loadCubeMap(self, texturePattern, readMipmaps = False, okMissing = False, @@ -890,18 +893,19 @@ class Loader(DirectObject): flags &= ~LoaderOptions.TFMultiview loaderOptions.setTextureFlags(flags) - texture = TexturePool.loadCubeMap(texturePattern, readMipmaps, loaderOptions) + sampler = SamplerState() + if minfilter is not None: + sampler.setMinfilter(minfilter) + if magfilter is not None: + sampler.setMagfilter(magfilter) + if anisotropicDegree is not None: + sampler.setAnisotropicDegree(anisotropicDegree) + + texture = TexturePool.loadCubeMap(texturePattern, readMipmaps, loaderOptions, sampler) if not texture and not okMissing: message = 'Could not load cube map: %s' % (texturePattern) raise IOError(message) - if minfilter is not None: - texture.setMinfilter(minfilter) - if magfilter is not None: - texture.setMagfilter(magfilter) - if anisotropicDegree is not None: - texture.setAnisotropicDegree(anisotropicDegree) - return texture def unloadTexture(self, texture):