private void CreateImmutableStorage() { TextureTarget target = _info.Target.Convert(); GL.ActiveTexture(TextureUnit.Texture0); GL.BindTexture(target, Handle); FormatInfo format = FormatTable.GetFormatInfo(_info.Format); SizedInternalFormat internalFormat; if (format.IsCompressed) { internalFormat = (SizedInternalFormat)format.PixelFormat; } else { internalFormat = (SizedInternalFormat)format.PixelInternalFormat; } switch (_info.Target) { case Target.Texture1D: GL.TexStorage1D( TextureTarget1d.Texture1D, _info.Levels, internalFormat, _info.Width); break; case Target.Texture1DArray: GL.TexStorage2D( TextureTarget2d.Texture1DArray, _info.Levels, internalFormat, _info.Width, _info.Height); break; case Target.Texture2D: GL.TexStorage2D( TextureTarget2d.Texture2D, _info.Levels, internalFormat, _info.Width, _info.Height); break; case Target.Texture2DArray: GL.TexStorage3D( TextureTarget3d.Texture2DArray, _info.Levels, internalFormat, _info.Width, _info.Height, _info.Depth); break; case Target.Texture2DMultisample: GL.TexStorage2DMultisample( TextureTargetMultisample2d.Texture2DMultisample, _info.Samples, internalFormat, _info.Width, _info.Height, true); break; case Target.Texture2DMultisampleArray: GL.TexStorage3DMultisample( TextureTargetMultisample3d.Texture2DMultisampleArray, _info.Samples, internalFormat, _info.Width, _info.Height, _info.Depth, true); break; case Target.Texture3D: GL.TexStorage3D( TextureTarget3d.Texture3D, _info.Levels, internalFormat, _info.Width, _info.Height, _info.Depth); break; case Target.Cubemap: GL.TexStorage2D( TextureTarget2d.TextureCubeMap, _info.Levels, internalFormat, _info.Width, _info.Height); break; case Target.CubemapArray: GL.TexStorage3D( (TextureTarget3d)All.TextureCubeMapArray, _info.Levels, internalFormat, _info.Width, _info.Height, _info.Depth); break; default: Logger.PrintDebug(LogClass.Gpu, $"Invalid or unsupported texture target: {target}."); break; } }
private static void Add(Format format, FormatInfo info) { Table[(int)format] = info; }
private void SetData(IntPtr data, int size) { TextureTarget target = Target.Convert(); Bind(target, 0); FormatInfo format = FormatTable.GetFormatInfo(Info.Format); int width = Info.Width; int height = Info.Height; int depth = Info.Depth; int offset = 0; for (int level = 0; level < Info.Levels; level++) { int mipSize = Info.GetMipSize(level); int endOffset = offset + mipSize; if ((uint)endOffset > (uint)size) { return; } switch (Info.Target) { case Target.Texture1D: if (format.IsCompressed) { GL.CompressedTexSubImage1D( target, level, 0, width, format.PixelFormat, mipSize, data); } else { GL.TexSubImage1D( target, level, 0, width, format.PixelFormat, format.PixelType, data); } break; case Target.Texture1DArray: case Target.Texture2D: if (format.IsCompressed) { GL.CompressedTexSubImage2D( target, level, 0, 0, width, height, format.PixelFormat, mipSize, data); } else { GL.TexSubImage2D( target, level, 0, 0, width, height, format.PixelFormat, format.PixelType, data); } break; case Target.Texture2DArray: case Target.Texture3D: case Target.CubemapArray: if (format.IsCompressed) { GL.CompressedTexSubImage3D( target, level, 0, 0, 0, width, height, depth, format.PixelFormat, mipSize, data); } else { GL.TexSubImage3D( target, level, 0, 0, 0, width, height, depth, format.PixelFormat, format.PixelType, data); } break; case Target.Cubemap: int faceOffset = 0; for (int face = 0; face < 6; face++, faceOffset += mipSize / 6) { if (format.IsCompressed) { GL.CompressedTexSubImage2D( TextureTarget.TextureCubeMapPositiveX + face, level, 0, 0, width, height, format.PixelFormat, mipSize / 6, data + faceOffset); } else { GL.TexSubImage2D( TextureTarget.TextureCubeMapPositiveX + face, level, 0, 0, width, height, format.PixelFormat, format.PixelType, data + faceOffset); } } break; } data += mipSize; offset += mipSize; width = Math.Max(1, width >> 1); height = Math.Max(1, height >> 1); if (Target == Target.Texture3D) { depth = Math.Max(1, depth >> 1); } } }