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

Simplify texture descriptor #17

Closed LukasBanana closed 6 years ago

LukasBanana commented 6 years ago

This is a concept for a new and simplied TextureDescriptor that applies to the new rendering APIs. Instead of having multiple nested structures for 1D, 2D, 3D, 2DMS and Cube textures, there is only one descriptor for all types of texutres:

struct TextureDescriptor {
    TextureType   type    = TextureType::Undefined;
    Format        format  = Format::Undefined;
    long          flags   = TextureFlags::Default;
    std::uint32_t width   = 1;
    std::uint32_t height  = 1;
    std::uint32_t depth   = 1;
    std::uint32_t layers  = 1;
    std::uint32_t samples = 1;
};

The member bool TextureDescriptor::Texture2DMS::fixedSamples can be replaced by a new flags entry to the TextureFlags enum.

Usage example:

// 1D array texture
LLGL::TextureDescriptor myTex1DDesc;
myTex1DDesc.type   = LLGL::TextureType::Texture1DArray;
myTex1DDesc.width  = 128;
myTex1DDesc.layers = 64;
auto myTex1D = myRenderer->CreateTexture(myTex1DDesc);

// Cube texture
LLGL::TextureDescriptor myTexCubeDesc;
myTexCubeDesc.type   = LLGL::TextureType::TextureCube;
myTexCubeDesc.width  = 32;
myTexCubeDesc.height = 32; // must be equal to width!
myTexCubeDesc.layers = 1; // automatically multiplied by 6 (one for each cube face)
auto myTexCube = myRenderer->CreateTexture(myTexCubeDesc);
LukasBanana commented 6 years ago

Done with a5accb8.

LukasBanana commented 6 years ago

Instead of the individual members width, height, and depth in the descriptor, the Extent3D struct should be used. Moreover, instead of the flag GenerateMips, a member mipLevels should be added, to also allow something inbetween of the minimum and maximum MIP-map count, e.g. 3 levels for a 512x512 texture (which has typically 10 mip levels).

struct TextureDescriptor {
    TextureType   type        = TextureType::Undefined;
    Format        format      = Format::Undefined;
    long          flags       = TextureFlags::Default;
    Extent3D      extent      = { 1, 1, 1 };
    std::uint32_t arrayLayers = 1; // renamed from "layers"
    std::uint32_t mipLevels   = 0; // 0 => generate full MIP-chain, 1 => no mip-mapping used
    std::uint32_t samples     = 1;
};
LukasBanana commented 6 years ago

Done with 01d155e.