Allow creating a mipmapped texture with less than the full mip range.

When creating a texture with user-specified mipmaps, it no longer errors if all mipmaps down to 1x1 aren't present.

Added a 'mipmapcount' field to the settings table in newImage and friends (only used when mipmaps are enabled for the texture.) If it's set, only mipmap levels up to the specified count will be created instead of always creating the full range.

Old OpenGL ES 2 devices don't support loading a mipmapped texture without the full mipmap range, so there's a new 'mipmaprange' boolean field in the table returned by love.graphics.getSupported.
This commit is contained in:
Sasha Szpakowski
2023-01-29 16:02:39 -04:00
parent 8706f0ef6a
commit defe811f62
10 changed files with 48 additions and 11 deletions
+2 -1
View File
@@ -1661,7 +1661,8 @@ void Graphics::initCapabilities()
capabilities.features[FEATURE_COPY_BUFFER_TO_TEXTURE] = gl.isCopyBufferToTextureSupported();
capabilities.features[FEATURE_COPY_TEXTURE_TO_BUFFER] = gl.isCopyTextureToBufferSupported();
capabilities.features[FEATURE_COPY_RENDER_TARGET_TO_BUFFER] = gl.isCopyRenderTargetToBufferSupported();
static_assert(FEATURE_MAX_ENUM == 17, "Graphics::initCapabilities must be updated when adding a new graphics feature!");
capabilities.features[FEATURE_MIPMAP_RANGE] = GLAD_VERSION_1_2 || GLAD_ES_VERSION_3_0;
static_assert(FEATURE_MAX_ENUM == 18, "Graphics::initCapabilities must be updated when adding a new graphics feature!");
capabilities.limits[LIMIT_POINT_SIZE] = gl.getMaxPointSize();
capabilities.limits[LIMIT_TEXTURE_SIZE] = gl.getMax2DTextureSize();
+6
View File
@@ -1388,6 +1388,12 @@ bool OpenGL::rawTexStorage(TextureType target, int levels, PixelFormat pixelform
GLenum gltarget = getGLTextureType(target);
TextureFormat fmt = convertPixelFormat(pixelformat, false, isSRGB);
// This shouldn't be needed for glTexStorage, but some drivers don't follow
// the spec apparently.
// https://stackoverflow.com/questions/13859061/does-an-immutable-texture-need-a-gl-texture-max-level
if (GLAD_VERSION_1_2 || GLAD_ES_VERSION_3_0)
glTexParameteri(gltarget, GL_TEXTURE_MAX_LEVEL, levels - 1);
if (fmt.swizzled)
{
glTexParameteri(gltarget, GL_TEXTURE_SWIZZLE_R, fmt.swizzle[0]);
+4
View File
@@ -264,6 +264,10 @@ void Texture::createTexture()
if (!isCompressed())
gl.rawTexStorage(texType, mipcount, format, sRGB, pixelWidth, pixelHeight, texType == TEXTURE_VOLUME ? depth : layers);
// rawTexStorage handles this for uncompressed textures.
if (isCompressed() && (GLAD_VERSION_1_1 || GLAD_ES_VERSION_3_0))
glTexParameteri(gltype, GL_TEXTURE_MAX_LEVEL, mipcount - 1);
int w = pixelWidth;
int h = pixelHeight;
int d = depth;