/// <summary> /// Create texture from pixel array /// </summary> public void LoadImage(Color4[] pixels, int width, int height) { IsStubTexture = false; reloader = new TexturePixelArrayReloader(pixels, width, height); MemoryUsed = 4 * width * height; ImageSize = new Size(width, height); SurfaceSize = ImageSize; uvRect = new Rectangle(0, 0, 1, 1); Window.Current.InvokeOnRendering(() => { var pinnedArray = GCHandle.Alloc(pixels, GCHandleType.Pinned); var pointer = pinnedArray.AddrOfPinnedObject(); PrepareOpenGLTexture(); GL.ActiveTexture(TextureUnit.Texture0); GL.BindTexture(TextureTarget.Texture2D, handle); GL.TexImage2D(TextureTarget.Texture2D, 0, PixelInternalFormat.Rgba, width, height, 0, PixelFormat.Rgba, PixelType.UnsignedByte, pointer); PlatformRenderer.MarkTextureSlotAsDirty(0); PlatformRenderer.CheckErrors(); pinnedArray.Free(); }); }
private void LoadImageHelper(Stream stream, bool createReloader) { reloader = createReloader ? new TextureStreamReloader(stream) : null; Discard(); if (!stream.CanSeek) { stream = new RewindableStream(stream); } using (var reader = new BinaryReader(stream)) { int sign = reader.ReadInt32(); stream.Seek(0, SeekOrigin.Begin); if (sign == PVRMagic) { InitWithPVRTexture(reader); } else if (sign == KTXMagic) { InitWithKTXTexture(reader); } #if WIN || MAC else if (sign == DDSMagic) { InitWithDDSBitmap(reader); } #endif else { InitWithPngOrJpg(stream); } } uvRect = new Rectangle(Vector2.Zero, (Vector2)ImageSize / (Vector2)SurfaceSize); }
/// <summary> /// Create texture from pixel array /// </summary> public void LoadImage(Color4[] pixels, int width, int height) { reloader = new TexturePixelArrayReloader(pixels, width, height); var pinnedArray = GCHandle.Alloc(pixels, GCHandleType.Pinned); var pointer = pinnedArray.AddrOfPinnedObject(); LoadImage(pointer, width, height); pinnedArray.Free(); }
public void LoadImage(string path) { using (var stream = AssetBundle.Current.OpenFileLocalized(path)) { LoadImageHelper(stream, createReloader: false); } reloader = new TextureBundleReloader(path); var maskPath = Path.ChangeExtension(path, ".mask"); if (AssetBundle.Current.FileExists(maskPath)) { OpacityMask = new OpacityMask(maskPath); } }
public void LoadImage(string path, TextureMissingDelegate onTextureMissing = null) { IsStubTexture = false; try { foreach (string textureFileExtension in AffordableTextureFileExtensions) { string tryPath = path + textureFileExtension; if (!AssetBundle.Current.FileExists(tryPath)) { continue; } Stream stream; try { stream = AssetBundle.Current.OpenFileLocalized(tryPath); } catch (System.Exception e) { Console.WriteLine("Can not open file '{0}':\n{1}", path, e); continue; } using (stream) { LoadImageHelper(stream, createReloader: false); } LoadTextureParams(path); var maskPath = path + ".mask"; if (AssetBundle.Current.FileExists(maskPath)) { OpacityMask = new OpacityMask(maskPath); } // Update audio buffers if the audio system performs in the main thread. AudioSystem.Update(); return; } Console.WriteLine("Missing texture '{0}'", path); onTextureMissing?.Invoke(path); LoadStubImage(); } finally { reloader = new TextureBundleReloader(path); } }
internal void LoadStubImage() { TextureParams = TextureParams.Default; OpacityMask = null; var pixels = new Color4[128 * 128]; for (int i = 0; i < 128; i++) { for (int j = 0; j < 128; j++) { pixels[i * 128 + j] = (((i + (j & ~7)) & 8) == 0) ? Color4.Blue : Color4.White; } } LoadImage(pixels, 128, 128); IsStubTexture = true; reloader = new TextureStubReloader(); }