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:
Sasha Szpakowski
2024-02-24 15:45:43 -04:00
parent 1e97e09b28
commit 42812ad521
20 changed files with 588 additions and 216 deletions
+42 -10
View File
@@ -174,6 +174,7 @@ public:
SETTING_MSAA,
SETTING_RENDER_TARGET,
SETTING_COMPUTE_WRITE,
SETTING_VIEW_FORMATS,
SETTING_READABLE,
SETTING_DEBUGNAME,
SETTING_MAX_ENUM
@@ -194,10 +195,22 @@ public:
int msaa = 1;
bool renderTarget = false;
bool computeWrite = false;
bool viewFormats = false;
OptionalBool readable;
std::string debugName;
};
struct ViewSettings
{
Optional<PixelFormat> format;
Optional<TextureType> type;
OptionalInt mipmapStart;
OptionalInt mipmapCount;
OptionalInt layerStart;
OptionalInt layerCount;
std::string debugName;
};
struct Slices
{
public:
@@ -228,10 +241,14 @@ public:
}; // Slices
static int64 totalGraphicsMemory;
struct ViewInfo
{
Texture *texture;
int startMipmap;
int startLayer;
};
Texture(Graphics *gfx, const Settings &settings, const Slices *slices);
virtual ~Texture();
static int64 totalGraphicsMemory;
// Drawable.
void draw(Graphics *gfx, const Matrix4 &m) override;
@@ -255,13 +272,14 @@ public:
virtual ptrdiff_t getRenderTargetHandle() const = 0;
virtual ptrdiff_t getSamplerHandle() const = 0;
TextureType getTextureType() const;
PixelFormat getPixelFormat() const;
MipmapsMode getMipmapsMode() const;
TextureType getTextureType() const { return texType; }
PixelFormat getPixelFormat() const { return format; }
MipmapsMode getMipmapsMode() const { return mipmapsMode; }
bool isRenderTarget() const;
bool isComputeWritable() const;
bool isReadable() const;
bool isRenderTarget() const { return renderTarget; }
bool isComputeWritable() const { return computeWrite; }
bool isReadable() const { return readable; }
bool hasViewFormats() const { return viewFormats; }
bool isCompressed() const;
bool isFormatLinear() const;
@@ -285,11 +303,14 @@ public:
int getRequestedMSAA() const;
virtual int getMSAA() const = 0;
virtual void setSamplerState(const SamplerState &s);
virtual void setSamplerState(const SamplerState &s) = 0;
const SamplerState &getSamplerState() const;
Quad *getQuad() const;
const ViewInfo &getRootViewInfo() const { return rootView; }
const ViewInfo &getParentViewInfo() const { return parentView; }
const std::string &getDebugName() const { return debugName; }
static int getTotalMipmapCount(int w, int h);
@@ -310,6 +331,10 @@ public:
protected:
Texture(Graphics *gfx, const Settings &settings, const Slices *slices);
Texture(Graphics *gfx, Texture *base, const ViewSettings &viewsettings);
virtual ~Texture();
void setGraphicsMemorySize(int64 size);
void uploadImageData(love::image::ImageDataBase *d, int level, int slice, int x, int y);
@@ -318,13 +343,17 @@ protected:
bool supportsGenerateMipmaps(const char *&outReason) const;
virtual void generateMipmapsInternal() = 0;
SamplerState validateSamplerState(SamplerState s) const;
bool validateDimensions(bool throwException) const;
void validatePixelFormat(Graphics *gfx) const;
TextureType texType;
PixelFormat format;
bool renderTarget;
bool computeWrite;
bool viewFormats;
bool readable;
MipmapsMode mipmapsMode;
@@ -349,6 +378,9 @@ protected:
std::string debugName;
ViewInfo rootView;
ViewInfo parentView;
}; // Texture
} // graphics