/// <summary> /// Allocates texture storage. Does not bind the texture to the specified target, it needs to be bound by the user in advance. /// </summary> /// <param name="format">The internal format of the texture data</param> /// <param name="width">Texture image width</param> /// <param name="height">Texture image height</param> /// <param name="levels">The number of levels. Use 0 to automatically compute level count.</param> protected void TexStorage2D(SizedInternalFormatGlob format, int width, int height, int levels = 0) { if (levels < 1) { levels = CountLevels(width, height); } GL.TexStorage2D((TextureTarget2d)Target, levels, (SizedInternalFormat)format, width, height); OnTextureStorage(format, levels, 1, width, height); }
void OnTextureStorage(SizedInternalFormatGlob format, int levels, int samples, int width, int height = 0, int depth = 0) { Format = format; Levels = levels; Samples = samples; StorageWidth = width; StorageHeight = height; StorageDepth = depth; ViewBase = null; ViewMinLevel = -1; ViewNumLevels = -1; ViewMinLayer = -1; ViewNumLayers = -1; Utils.SetObjectLabel(ObjectLabelIdentifier.Texture, Handle, Name); }
// TODO: test texture views /// <summary> /// Important: do not assign a TextureTarget to the texture before calling TextureView // TODO: proč? /// </summary> /// <param name="origTexture"></param> /// <param name="format"></param> /// <param name="minLevel"></param> /// <param name="numLevels"></param> /// <param name="minLayer"></param> /// <param name="numLayers"></param> protected void TextureView(Texture origTexture, SizedInternalFormatGlob format, int minLevel, int numLevels, int minLayer, int numLayers) { GL.TextureView(Handle, Target, origTexture.Handle, (PixelInternalFormat)format, minLevel, numLevels, minLayer, numLayers); Format = format; Levels = numLevels; Samples = origTexture.Samples; StorageWidth = origTexture.StorageWidth >> minLevel; StorageHeight = origTexture.StorageHeight >> minLevel; StorageDepth = origTexture.StorageDepth >> minLevel; ViewBase = origTexture; ViewMinLevel = minLevel; ViewNumLevels = numLevels; ViewMinLayer = minLayer; ViewNumLayers = numLayers; }
/// <summary> /// Allocates multisample texture storage. Does not bind the texture to the specified target, it needs to be bound by the user in advance. /// </summary> /// <param name="format">The internal format of the texture data</param> /// <param name="samples">The sample count of each texture texel</param> /// <param name="width">Texture image width</param> /// <param name="height">Texture image height</param> /// <param name="depth">Texture image depth</param> protected void TexStorage3DMultisample(SizedInternalFormatGlob format, int samples, int width, int height, int depth, bool fixedLocations) { GL.TexStorage3DMultisample((TextureTargetMultisample3d)Target, samples, (SizedInternalFormat)format, width, height, depth, fixedLocations); OnTextureStorage(format, 1, samples, width, height, depth); }
// TODO: texture views public Texture2D(Device device, string name, SizedInternalFormatGlob format, Texture origTexture, int minLevel, int numLevels, int minLayer = 0) : base(TextureTarget.Texture2D, name) { // Texture view - no need to bind TextureView(origTexture, format, minLevel, numLevels, minLayer, 1); }
// TODO /// <summary> /// Creates a Texture2D using immutable storage. /// </summary> /// <param name="device">Glob device</param> /// <param name="name">Debug label</param> /// <param name="format">Texture internal format</param> /// <param name="width">Width in texels</param> /// <param name="height">Height in texels</param> /// <param name="levels">Number of mip level. Special values: 1 for the base level only, 0 to compute number of mip levels automatically from texture dimensions.</param> public Texture2D(Device device, string name, SizedInternalFormatGlob format, int width, int height, int levels = 0) : base(TextureTarget.Texture2D, name) { device.BindTexture(Target, Handle); TexStorage2D(format, width, height, levels); }
public Texture3D(Device device, string name, SizedInternalFormatGlob format, Texture origTexture, int minLevel, int numLevels, int minLayer = 0, int numLayers = 1) : base(TextureTarget.Texture3D, name) { //state.TextureUnit.BindTexture(Target, Handle); TextureView(origTexture, format, minLevel, numLevels, minLayer, numLayers); }