private void GenerateArrayTexture() { Dictionary <Tile.TileIds, Bitmap> tempTileList = RenderObjects.RenderObjects.CreateTileBitmaps(new Size(256, 256)); theTextureArray = TextureArray.CreateFromBitmaps(new List <Bitmap>(tempTileList.Values)); }
public Sheet2D(SheetType type, TextureArray texture, int TextureArrayIndex) { Type = type; this.texture = texture; Size = texture.Size; textureArrayIndex = TextureArrayIndex; }
public void Dispose() { if (texture != null) { texture.Dispose(); texture = null; } }
public void GenerateMipmaps(int levels) { var oldTex = TextureArray; TextureArray = TextureArray.GenerateMipmapLevels(levels); oldTex.Dispose(); NumMipmaps = levels; }
public void DeleteMipmaps() { var oldTex = TextureArray; TextureArray = TextureArray.CloneMipmapLevel(0); oldTex.Dispose(); NumMipmaps = 1; }
private void AppendTexture(Texture2D texture, int index) { if (SystemInfo.copyTextureSupport.HasFlag(CopyTextureSupport.DifferentTypes)) { UnityEngine.Graphics.CopyTexture(texture, 0, TextureArray, index); } else { TextureArray.SetPixels32(texture.GetPixels32(), index); TextureArray.Apply(true); } }
/// <summary> /// Loads pngs to 2d textures. Create 1 2dtexture for one msdf folder. /// </summary> public void LoadFontTexturesAsPng(string fontname) { FileSystem.IReadOnlyPackage pack; string temp; string p1, p2; if (Game.ModData.Manifest.FontsMSDFBaseFolders == null) { return; } p1 = Game.ModData.Manifest.FontsMSDFBaseFolders[fontname].First; p2 = Game.ModData.Manifest.FontsMSDFBaseFolders[fontname].Second; Texture = Game.Renderer.Context.CreateTexture2DArray(); Texture.scaleFilter = TextureScaleFilter.Linear; Texture.SetEmpty(Size, Size, 127); // просто заготовка gjl 127 слойный массив, каждый слой 96 на 96 пикселей. if (Game.ModData.DefaultFileSystem.TryGetPackageContaining(p2, out pack, out temp)) { foreach (string f in pack.Contents) { using (var stream = pack.GetStream(f)) { Png pic; try { pic = new Png(stream); Texture.SetData(pic.Data, Size, Size, Convert.ToInt32(f.Split('.')[0])); } catch (Exception e) { Console.WriteLine("Error loading char: {0} x {1}", f, Convert.ToInt32(f.Split('.')[0])); } } } } else { Console.WriteLine("MSDF fonts not loaded. Create font folder and write it to mod.yaml Packages for mod=" + Game.ModData.Manifest.Id + " path="); } }
/// <summary> /// Создает текстуру в OPenGL для данного Sheet /// </summary> /// <returns></returns> public ITexture AssignOrGetOrSetDataGLTexture() { if (texture == null) { texture = Game.Renderer.Context.CreateTexture2DArray(); texture.scaleFilter = TextureScaleFilter.Nearest; texture.SetEmpty(Size.Width, Size.Width, 10); dirty = true; } if (data != null && dirty) { //Flush CPU data to GPU data(OpenGL Texture) texture.SetData(data, Size.Width, Size.Width, textureArrayIndex); dirty = false; if (releaseBufferOnCommit) { data = null; } } return(texture); }
/// <summary> /// disposes all opengl related data. /// Component should not be used after this /// </summary> public void Dispose() { TextureArray.Dispose(); }
/// <summary> /// Резервирует место под SPrite в текстуре opengl /// Определяет в какой канал текстуры будут записаны байты /// </summary> /// <param name="imageSize"></param> /// <param name="zRamp"></param> /// <param name="spriteOffset"></param> /// <returns></returns> public Sprite Allocate(Size imageSize, float zRamp, float3 spriteOffset, TextureChannel overrideChannel = TextureChannel.Red) { if (overrideChannel == TextureChannel.RGBA) { channel = TextureChannel.RGBA; //сделано, для случаев, когда спрайты в sequences будут 4 байтовые, то есть из PNG идти. } else { channel = SheetStoreType == SheetType.Indexed ? TextureChannel.Red : TextureChannel.RGBA; // пишем теперь всегда в канал Red } //используется одномерный массив. Поэтому все разбито по Height(row) и смещение внутри row. if (imageSize.Width + p.X > currentSheet2D.Size.Width) //если дошли до смещения равного ширине картинки, то сбрасываем смещение до 0 и делаем переход на высоту равную предыдущей высоте. { p = new int2(0, p.Y + rowHeight); rowHeight = imageSize.Height; } if (imageSize.Height > rowHeight) { rowHeight = imageSize.Height; } if (p.Y + imageSize.Height > currentSheet2D.Size.Height) //если вышли за пределы высоты в одном канале, то переходим в другой канал. и скидываем p=int2.Zero { //когда дошли по конца массива, то переходи в следующий Sheet , а не в канал. //var next = NextChannel(channel); //if (next == null) //{ // NextSheet(); //} //if (next == null) //если закончились каналы внутри текстуры , то создаем новый Sheet. //{ // NextSheet(); // currentSheet2D.ReleaseBuffer(); // currentSheet2D = CreateNewSheet(SheetStoreType, Game.Settings.Graphics.SheetSize); //унаследует TextureArrayIndex в новый Sheet2D // sheetsOnCpu.Add(currentSheet2D); // channel = SheetStoreType == SheetType.Indexed ? TextureChannel.Red : TextureChannel.RGBA; //} //else // channel = next.Value; currentSheet2D.ReleaseBuffer(); textureArray = currentSheet2D.texture; // присваиваем текстуру от первого sheet ,так как текстуры имеютс вязь sheet<->texture NextSheet(); currentSheet2D = CreateNewSheet(SheetStoreType, Game.Settings.Graphics.SheetSize); //унаследует TextureArrayIndex в новый Sheet2D sheetsOnCpu.Add(currentSheet2D); rowHeight = imageSize.Height; p = int2.Zero; } var rect = new Sprite(currentSheet2D, new Rectangle(p.X, p.Y, imageSize.Width, imageSize.Height), zRamp, spriteOffset, channel, BlendMode.Alpha); p += new int2(imageSize.Width, 0); // увеливаем свещение на ширину картинки у p.X параметра return(rect); }
public TextureAtlas(int width, int height, int layers) { Array = new TextureArray(width, height, layers); TextureMap = new Dictionary <string, int>(); }
public FontMSDF() { Texture = new TextureArray(); }