LukasBanana / LLGL

Low Level Graphics Library (LLGL) is a thin abstraction layer for the modern graphics APIs OpenGL, Direct3D, Vulkan, and Metal
BSD 3-Clause "New" or "Revised" License
2.05k stars 139 forks source link

Texture views #15

Closed LukasBanana closed 4 years ago

LukasBanana commented 6 years ago

Add the following functions to support texture resource views:

class RenderSystem {
    // Creates a resource view for the source texture
    // using the same <Texture> interface for seamless interoperability.
    Texture* CreateTextureView(Texture& sourceTexture, const TextureViewDescriptor& desc);
    /* ... */
};
class Texture {
    // Returns true if this texture is a resource view and not the original texture
    bool IsResourceView() const;
    /* ... */
};

This will also replace the secondary version of the GenerateMips function (which currently generates resource views on demand).

For OpenGL, this is only supported if the GL_ARB_texture_view extension is available on the host platform. For D3D11, D3D12, and Vulkan there is a respective resource view interface (e.g. VkImageView or ID3D11ShaderResourceView). For Metal, the same interface MTLTexture is used for both textures and texture-views.

Only the debug layer will keep track of all resource views that refer to a source texture. When a source texture is released, and any of its resource views is still used, the debug layer will throw an error message.

EDIT: Instead of making texture views part of the Texture interface, they are probably better suited for the ResourceHeap interface. Also simplifies the way of creating multiple different views of the same texture object.

LukasBanana commented 4 years ago

Implemented texture-views in form of TextureViewDescriptor: