mirror of
https://github.com/love2d/love.git
synced 2026-08-17 19:23:38 +02:00
Add texture views. Fixes #2022.
Add love.graphics.newTextureView(basetexture, viewsettings). Requires GLSL4 support. Add 'viewformats' boolean setting to texture setting tables. Add Texture:hasViewFormats. The viewsettings table has the following fields: format = nil, -- set this to a pixel format to override the base format. It must have the same number of bytes per pixel as the original, and the 'viewformats' setting on the original texture must be true for this to work. Cannot be used for compressed or depth/stencil textures. type = nil, -- set this to a texture type to override the base texture type. 2d base textures can make [2d, array] views. [array, cube] base textures can make [2d, array, cube] views. mipmapstart = nil, -- set to a number to use a less detailed mipmap level as a base. mipmapcount = nil, -- set to a number to override the number of mipmaps in the texture view. layerstart = nil, -- set to a number to use a specific layer or cube face as a base. layers = nil, -- set to a number to override the number of layers in an array texture view.
This commit is contained in:
@@ -43,10 +43,6 @@ static MTLTextureType getMTLTextureType(TextureType type, int msaa)
|
||||
|
||||
Texture::Texture(love::graphics::Graphics *gfxbase, id<MTLDevice> device, const Settings &settings, const Slices *data)
|
||||
: love::graphics::Texture(gfxbase, settings, data)
|
||||
, texture(nil)
|
||||
, msaaTexture(nil)
|
||||
, sampler(nil)
|
||||
, actualMSAASamples(1)
|
||||
{ @autoreleasepool {
|
||||
auto gfx = (Graphics *) gfxbase;
|
||||
|
||||
@@ -80,6 +76,8 @@ Texture::Texture(love::graphics::Graphics *gfxbase, id<MTLDevice> device, const
|
||||
desc.usage |= MTLTextureUsageRenderTarget;
|
||||
if (computeWrite)
|
||||
desc.usage |= MTLTextureUsageShaderWrite;
|
||||
if (viewFormats)
|
||||
desc.usage |= MTLTextureUsagePixelFormatView;
|
||||
|
||||
texture = [device newTextureWithDescriptor:desc];
|
||||
|
||||
@@ -212,6 +210,41 @@ Texture::Texture(love::graphics::Graphics *gfxbase, id<MTLDevice> device, const
|
||||
setSamplerState(samplerState);
|
||||
}}
|
||||
|
||||
Texture::Texture(love::graphics::Graphics *gfx, id<MTLDevice> device, love::graphics::Texture *base, const Texture::ViewSettings &viewsettings)
|
||||
: love::graphics::Texture(gfx, base, viewsettings)
|
||||
{
|
||||
id<MTLTexture> basetex = ((Texture *) base)->texture;
|
||||
auto formatdesc = Metal::convertPixelFormat(device, format);
|
||||
int slices = texType == TEXTURE_CUBE ? 6 : getLayerCount();
|
||||
|
||||
if (formatdesc.swizzled)
|
||||
{
|
||||
if (@available(macOS 10.15, iOS 13, *))
|
||||
{
|
||||
texture = [basetex newTextureViewWithPixelFormat:formatdesc.format
|
||||
textureType:getMTLTextureType(texType, 1)
|
||||
levels:NSMakeRange(parentView.startMipmap, mipmapCount)
|
||||
slices:NSMakeRange(parentView.startLayer, slices)
|
||||
swizzle:formatdesc.swizzle];
|
||||
}
|
||||
}
|
||||
else
|
||||
{
|
||||
texture = [basetex newTextureViewWithPixelFormat:formatdesc.format
|
||||
textureType:getMTLTextureType(texType, 1)
|
||||
levels:NSMakeRange(parentView.startMipmap, mipmapCount)
|
||||
slices:NSMakeRange(parentView.startLayer, slices)];
|
||||
}
|
||||
|
||||
if (texture == nil)
|
||||
throw love::Exception("Could not create Metal texture view.");
|
||||
|
||||
if (!debugName.empty())
|
||||
texture.label = @(debugName.c_str());
|
||||
|
||||
setSamplerState(samplerState);
|
||||
}
|
||||
|
||||
Texture::~Texture()
|
||||
{ @autoreleasepool {
|
||||
texture = nil;
|
||||
@@ -340,10 +373,8 @@ void Texture::setSamplerState(const SamplerState &s)
|
||||
if (s.depthSampleMode.hasValue && !Graphics::getInstance()->isDepthCompareSamplerSupported())
|
||||
throw love::Exception("Depth comparison sampling in shaders is not supported on this system.");
|
||||
|
||||
// Base class does common validation and assigns samplerState.
|
||||
love::graphics::Texture::setSamplerState(s);
|
||||
|
||||
sampler = Graphics::getInstance()->getCachedSampler(s);
|
||||
samplerState = validateSamplerState(s);
|
||||
sampler = Graphics::getInstance()->getCachedSampler(samplerState);
|
||||
}}
|
||||
|
||||
} // metal
|
||||
|
||||
Reference in New Issue
Block a user