Example #1
0
        private static void init(ShaderI shader, Loader.LoadedCallbackMethod loadedCallback)
        {
            try
            {
                CameraConstant = shader.Variable("Camera"); PositionConstant = shader.Variable("Position"); SizeConstant = shader.Variable("Size"); ColorConstant = shader.Variable("Color");
                var elements = new List <BufferLayoutElement>();
                elements.Add(new BufferLayoutElement(BufferLayoutElementTypes.Vector2, BufferLayoutElementUsages.Position, 0, 0, 0));
                BufferLayoutDesc = BufferLayoutDescAPI.New(elements);
                BufferLayout     = BufferLayoutAPI.New(shader, shader, BufferLayoutDesc);
            }
            catch (Exception e)
            {
                FailedToLoad = true;
                Loader.AddLoadableException(e);
                Dispose();
                if (loadedCallback != null)
                {
                    loadedCallback(null, false);
                }
                return;
            }

            Loaded = true;
            if (loadedCallback != null)
            {
                loadedCallback(null, true);
            }
        }
Example #2
0
        public LoadWaiter(ILoadable[] loadables, Loader.LoadedCallbackMethod loadedCallback)
        {
            this.loadables = loadables;
            LoadedCallback = loadedCallback;

            Loader.AddLoadable(this);
        }
 private void bs_ImageFailed(object sender, ExceptionRoutedEventArgs args)
 {
     FailedToLoad = true;
     Loader.AddLoadableException(new Exception("ImageSilverlight - Failed to load image."));
     if (loadedCallback != null) loadedCallback(this, false);
     loadedCallback = null;
 }
Example #4
0
        private static void init(ShaderI shader, Loader.LoadedCallbackMethod loadedCallback)
        {
            try
            {
                CameraConstant = shader.Variable("Camera"); BillboardTransformConstant = shader.Variable("BillboardTransform"); DiffuseConstant = shader.Resource("Diffuse"); ColorPalletConstant = shader.Variable("ColorPallet"); ScalePalletConstant = shader.Variable("ScalePallet"); TransformsConstant = shader.Variable("Transforms");
                var elements = new List <BufferLayoutElement>();
                elements.Add(new BufferLayoutElement(BufferLayoutElementTypes.Vector3, BufferLayoutElementUsages.Position, 0, 0, 0)); elements.Add(new BufferLayoutElement(BufferLayoutElementTypes.Vector2, BufferLayoutElementUsages.UV, 0, 0, 3));
                BufferLayoutDesc = BufferLayoutDescAPI.New(elements);
                BufferLayout     = BufferLayoutAPI.New(shader, shader, BufferLayoutDesc);
            }
            catch (Exception e)
            {
                FailedToLoad = true;
                Loader.AddLoadableException(e);
                Dispose();
                if (loadedCallback != null)
                {
                    loadedCallback(null, false);
                }
                return;
            }

            Loaded = true;
            if (loadedCallback != null)
            {
                loadedCallback(null, true);
            }
        }
Example #5
0
 public Texture2D(DisposableI parent, string fileName, Loader.LoadedCallbackMethod loadedCallback)
     : base(parent)
 {
                 #if SILVERLIGHT
     Image.New(fileName, false,
               delegate(object sender, bool succeeded)
     {
         if (succeeded)
         {
             var image = (Image)sender;
             init(parent, null, image, image.Size.Width, image.Size.Height, false, MultiSampleTypes.None, image.SurfaceFormat, RenderTargetUsage.PlatformDefault, BufferUsages.Default, false, loadedCallback);
         }
         else
         {
             FailedToLoad = true;
             Dispose();
             if (loadedCallback != null)
             {
                 loadedCallback(this, false);
             }
         }
     });
                 #else
     init(parent, fileName, null, 0, 0, false, MultiSampleTypes.None, SurfaceFormats.Unknown, RenderTargetUsage.PlatformDefault, BufferUsages.Default, false, loadedCallback);
                 #endif
 }
Example #6
0
        public static Image New(string filename, bool flip, Loader.LoadedCallbackMethod loadedCallback)
        {
            string ext = Streams.GetFileExt(filename);

            switch (ext.ToLower())
            {
            case ".dds": return(new ImageDDS(filename, flip, loadedCallback));

            case ".atc": return(new ImageDDS(filename, flip, loadedCallback));

            case ".pvr": return(new ImagePVR(filename, flip, loadedCallback));

                                #if !XNA && NaCl
            case ".bmpc": return(new ImageBMPC(filename, flip, loadedCallback));
                                #endif
                                #if (!XNA && !NaCl && !VITA) || SILVERLIGHT
                                #if !WP8
            case ".bmpc": return(new ImageBMPC(filename, flip, loadedCallback));
                                #endif
            case ".png": return(new ImagePNG(filename, flip, loadedCallback));

            case ".jpg": return(new ImageJPG(filename, flip, loadedCallback));

            case ".jpeg": return(new ImageJPG(filename, flip, loadedCallback));

                                #if !iOS && !ANDROID
            case ".bmp": return(new ImageBMP(filename, flip, loadedCallback));
                                #endif
                                #endif
            default:
                Debug.ThrowError("Image", string.Format("File 'ext' {0} not supported.", ext));
                return(null);
            }
        }
Example #7
0
        public SoftwareModel(string filename, Loader.LoadedCallbackMethod loadedCallback)
        {
            string fileType = Streams.GetFileExt(filename).ToLower();

            if (fileType != ".rmx")
            {
                Debug.ThrowError("SoftwareModel", "Unsuported file type: " + fileType);
            }

            new StreamLoader(filename,
                             delegate(object sender, bool succeeded)
            {
                if (succeeded)
                {
                    init(((StreamLoader)sender).LoadedStream, loadedCallback);
                }
                else
                {
                    FailedToLoad = true;
                    if (loadedCallback != null)
                    {
                        loadedCallback(this, false);
                    }
                }
            });
        }
Example #8
0
        private void bs_ImageOpened(object sender, RoutedEventArgs args)
        {
            try
            {
                var image  = (BitmapImage)sender;
                var bitmap = new WriteableBitmap(image);

                int width  = bitmap.PixelWidth;
                int height = bitmap.PixelHeight;
                Mipmaps = new Mipmap[1];
                Size    = new Size2(bitmap.PixelWidth, bitmap.PixelHeight);

                var dataPixels = bitmap.Pixels;
                var data       = new byte[dataPixels.Length * 4];
                int i2         = 0;
                for (int i = 0; i != dataPixels.Length; ++i)
                {
                    var color = new Color4(dataPixels[i]);
                    data[i2]     = color.R;
                    data[i2 + 1] = color.G;
                    data[i2 + 2] = color.B;
                    data[i2 + 3] = color.A;

                    i2 += 4;
                }

                // Flip RB Color bits
                for (i2 = 0; i2 != data.Length; i2 += 4)
                {
                    byte c = data[i2];
                    data[i2]     = data[i2 + 2];
                    data[i2 + 2] = c;
                }

                Mipmaps[0] = new Mipmap(data, width, height, 1, 4);
                if (flip)
                {
                    Mipmaps[0].FlipVertical();
                }
            }
            catch (Exception e)
            {
                FailedToLoad = true;
                Loader.AddLoadableException(e);
                if (loadedCallback != null)
                {
                    loadedCallback(this, false);
                }
                loadedCallback = null;
                return;
            }

            Loaded = true;
            if (loadedCallback != null)
            {
                loadedCallback(this, true);
            }
            loadedCallback = null;
        }
Example #9
0
 private void bs_ImageFailed(object sender, ExceptionRoutedEventArgs args)
 {
     FailedToLoad = true;
     Loader.AddLoadableException(new Exception("ImageSilverlight - Failed to load image."));
     if (loadedCallback != null)
     {
         loadedCallback(this, false);
     }
     loadedCallback = null;
 }
Example #10
0
 private void image_ImageFailed(object sender, ExceptionRoutedEventArgs args)
 {
     FailedToLoad = true;
     if (loadedCallback != null)
     {
         loadedCallback(this, false);
     }
     loadedCallback = null;
     image          = null;
 }
Example #11
0
        public ImageWP8(string fileName, bool flip, Loader.LoadedCallbackMethod loadedCallback)
        {
            Loader.AddLoadable(this);
            this.flip           = flip;
            this.loadedCallback = loadedCallback;

            image              = new BitmapImage();
            image.ImageOpened += image_ImageOpened;
            image.ImageFailed += image_ImageFailed;
            image.UriSource    = new Uri(fileName, UriKind.Relative);
        }
Example #12
0
        public ImageWP8(Stream stream, bool flip, Loader.LoadedCallbackMethod loadedCallback)
        {
            Loader.AddLoadable(this);
            this.flip           = flip;
            this.loadedCallback = loadedCallback;

            image              = new BitmapImage();
            image.ImageOpened += image_ImageOpened;
            image.ImageFailed += image_ImageFailed;
            image.SetSource(stream);
        }
Example #13
0
        public void Dispose()
        {
                        #if NaCl
            loadedCallback = null;
                        #endif

            if (fromFile && LoadedStream != null)
            {
                LoadedStream.Dispose();
                LoadedStream = null;
            }
        }
Example #14
0
        protected override void init(Stream stream, bool flip, Loader.LoadedCallbackMethod loadedCallback)
        {
            this.flip = flip;
            this.loadedCallback = loadedCallback;

            ((SilverlightApplication)OS.CurrentApplication).MainUserControl.Dispatcher.BeginInvoke(delegate
            {
                var image = new BitmapImage();
                image.ImageOpened += bs_ImageOpened;
                image.ImageFailed += bs_ImageFailed;
                image.SetSource(stream);
            });
        }
Example #15
0
        protected override void init(Stream stream, bool flip, Loader.LoadedCallbackMethod loadedCallback)
        {
            this.flip           = flip;
            this.loadedCallback = loadedCallback;

            ((SilverlightApplication)OS.CurrentApplication).MainUserControl.Dispatcher.BeginInvoke(delegate
            {
                var image          = new BitmapImage();
                image.ImageOpened += bs_ImageOpened;
                image.ImageFailed += bs_ImageFailed;
                image.SetSource(stream);
            });
        }
Example #16
0
        protected override void init(Stream stream, bool flip, Loader.LoadedCallbackMethod loadedCallback)
        {
            try
            {
                using (var bitmap = new Bitmap(stream))
                {
                    int width  = bitmap.Width;
                    int height = bitmap.Height;
                    Mipmaps = new Mipmap[1];
                    Size    = new Size2(bitmap.Width, bitmap.Height);

                    var bitmapData = bitmap.LockBits(new Rectangle(0, 0, width, height), ImageLockMode.ReadOnly, PixelFormat.Format32bppArgb);

                    // Copy unmanaged data to managed array
                    int    size = System.Math.Abs(bitmapData.Stride) * height;
                    byte[] data = new byte[size];
                    Marshal.Copy(bitmapData.Scan0, data, 0, size);

                    // Flip RB Color bits
                    for (int i2 = 0; i2 != data.Length; i2 += 4)
                    {
                        byte c = data[i2];
                        data[i2]     = data[i2 + 2];
                        data[i2 + 2] = c;
                    }

                    Mipmaps[0] = new Mipmap(data, width, height, 1, 4);
                    if (flip)
                    {
                        Mipmaps[0].FlipVertical();
                    }
                    bitmap.UnlockBits(bitmapData);
                }
            }
            catch (Exception e)
            {
                FailedToLoad = true;
                Loader.AddLoadableException(e);
                if (loadedCallback != null)
                {
                    loadedCallback(this, false);
                }
                return;
            }

            Loaded = true;
            if (loadedCallback != null)
            {
                loadedCallback(this, true);
            }
        }
Example #17
0
        protected override void init(Stream stream, bool flip, Loader.LoadedCallbackMethod loadedCallback)
        {
            try
            {
                using (var bitmap = Android.Graphics.BitmapFactory.DecodeStream(stream))
                {
                    int width  = bitmap.Width;
                    int height = bitmap.Height;
                    Mipmaps = new Mipmap[1];
                    Size    = new Size2(bitmap.Width, bitmap.Height);

                    var pixels = new int[width * height];
                    bitmap.GetPixels(pixels, 0, width, 0, 0, width, height);

                    // Convert to bytes
                    var data = new byte[pixels.Length * 4];
                    int i3   = 0;
                    for (int i2 = 0; i2 != pixels.Length; ++i2)
                    {
                        data[i3]     = (byte)Color.GetRedComponent(pixels[i2]);
                        data[i3 + 1] = (byte)Color.GetGreenComponent(pixels[i2]);
                        data[i3 + 2] = (byte)Color.GetBlueComponent(pixels[i2]);
                        data[i3 + 3] = (byte)Color.GetAlphaComponent(pixels[i2]);
                        i3          += 4;
                    }

                    Mipmaps[0] = new Mipmap(data, width, height, 1, 4);
                    if (flip)
                    {
                        Mipmaps[0].FlipVertical();
                    }
                }
            }
            catch (Exception e)
            {
                FailedToLoad = true;
                Loader.AddLoadableException(e);
                if (loadedCallback != null)
                {
                    loadedCallback(this, false);
                }
                return;
            }

            Loaded = true;
            if (loadedCallback != null)
            {
                loadedCallback(this, true);
            }
        }
Example #18
0
        protected override void init(Stream stream, bool flip, Loader.LoadedCallbackMethod loadedCallback)
        {
            try
            {
                var bitmap = new WriteableBitmap(image);
                var pixels = bitmap.Pixels;
                var data   = new byte[pixels.Length * 4];
                int i2     = 0;
                for (int i = 0; i != pixels.Length; ++i)
                {
                    Color4 color = new Color4(pixels[i]);
                    data[i2]     = color.R;
                    data[i2 + 1] = color.G;
                    data[i2 + 2] = color.B;
                    data[i2 + 3] = color.A;
                    i2          += 4;
                }

                int width  = (int)bitmap.PixelWidth;
                int height = (int)bitmap.PixelHeight;
                Mipmaps = new Mipmap[1];
                Size    = new Size2(width, height);

                Mipmaps[0] = new Mipmap(data, width, height, 1, 4);
                if (flip)
                {
                    Mipmaps[0].FlipVertical();
                }
            }
            catch (Exception e)
            {
                FailedToLoad = true;
                Loader.AddLoadableException(e);
                if (loadedCallback != null)
                {
                    loadedCallback(this, false);
                }
                loadedCallback = null;
                image          = null;
                return;
            }

            Loaded = true;
            if (loadedCallback != null)
            {
                loadedCallback(this, true);
            }
            loadedCallback = null;
            image          = null;
        }
Example #19
0
        private void init(string filename, Stream stream, Loader.LoadedCallbackMethod loadedCallback)
                #endif
        {
            try
            {
                if (filename != null)
                {
                    fromFile = true;
                                        #if WINRT || WP8
                    LoadedStream = await Streams.OpenFile(filename);
                                        #elif NaCl
                    this.loadedCallback = loadedCallback;

                    filename = filename.Replace('\\', '/');
                    file     = new NaClFile(filename);
                    Streams.NaClFileLoadedCallback += fileLoaded;
                    Streams.addPendingFile(file);
                    Loader.AddLoadable(this);

                    return;
                                        #else
                    LoadedStream = Streams.OpenFile(filename);
                                        #endif
                }
                else
                {
                    fromFile     = false;
                    LoadedStream = stream;
                }
            }
            catch (Exception e)
            {
                FailedToLoad = true;
                Loader.AddLoadableException(e);
                Dispose();
                if (loadedCallback != null)
                {
                    loadedCallback(this, false);
                }
                return;
            }

            Loaded = true;
            if (loadedCallback != null)
            {
                loadedCallback(this, true);
            }
        }
Example #20
0
        protected override async void init(Stream stream, bool flip, Loader.LoadedCallbackMethod loadedCallback)
        {
            try
            {
                using (var memoryStream = new InMemoryRandomAccessStream())
                {
                    await RandomAccessStream.CopyAsync(stream.AsInputStream(), memoryStream);

                    var decoder = await BitmapDecoder.CreateAsync(memoryStream);

                    var frame = await decoder.GetFrameAsync(0);

                    var transform = new BitmapTransform();
                    transform.InterpolationMode = BitmapInterpolationMode.NearestNeighbor;
                    transform.Rotation          = BitmapRotation.None;
                    var dataProvider = await decoder.GetPixelDataAsync(BitmapPixelFormat.Rgba8, BitmapAlphaMode.Straight, transform, ExifOrientationMode.IgnoreExifOrientation, ColorManagementMode.ColorManageToSRgb);

                    var data = dataProvider.DetachPixelData();

                    int width  = (int)decoder.PixelWidth;
                    int height = (int)decoder.PixelHeight;
                    Mipmaps = new Mipmap[1];
                    Size    = new Size2(width, height);

                    Mipmaps[0] = new Mipmap(data, width, height, 1, 4);
                    if (flip)
                    {
                        Mipmaps[0].FlipVertical();
                    }
                }
            }
            catch (Exception e)
            {
                FailedToLoad = true;
                Loader.AddLoadableException(e);
                if (loadedCallback != null)
                {
                    loadedCallback(this, false);
                }
                return;
            }

            Loaded = true;
            if (loadedCallback != null)
            {
                loadedCallback(this, true);
            }
        }
Example #21
0
        public static Texture2D NewReference(DisposableI parent, string fileName, Loader.LoadedCallbackMethod loadedCallback)
        {
            var texture = parent.FindChild <Texture2D>
                          (
                "NewReference",
                new ConstructorParam(typeof(DisposableI), parent),
                new ConstructorParam(typeof(string), fileName),
                new ConstructorParam(typeof(Loader.LoadedCallbackMethod), null)
                          );

            if (texture != null)
            {
                ++texture.referenceCount;
                return(texture);
            }
            return(new Texture2D(parent, fileName, loadedCallback));
        }
Example #22
0
        private void fileLoaded(NaClFile file)
        {
            if (file.ID == this.file.ID)
            {
                Streams.NaClFileLoadedCallback -= fileLoaded;

                if (file.FailedToLoad)
                {
                    FailedToLoad = true;
                    if (loadedCallback != null)
                    {
                        loadedCallback(this, false);
                    }
                    loadedCallback = null;
                    Dispose();
                    return;
                }

                try
                {
                    LoadedStream          = new MemoryStream(file.Data);
                    LoadedStream.Position = 0;
                }
                catch (Exception e)
                {
                    FailedToLoad = true;
                    Loader.AddLoadableException(e);
                    if (loadedCallback != null)
                    {
                        loadedCallback(this, false);
                    }
                    loadedCallback = null;
                    Dispose();
                    return;
                }

                Loaded = true;
                if (loadedCallback != null)
                {
                    loadedCallback(this, true);
                }
                loadedCallback = null;
            }
        }
Example #23
0
        protected override void init(Stream stream, bool flip, Loader.LoadedCallbackMethod loadedCallback)
        {
            try
            {
                using (var image = NSImage.FromStream(stream))
                {
                    var rep    = image.Representations()[0];
                    int width  = rep.PixelsWide;
                    int height = rep.PixelsHigh;
                    Mipmaps = new Mipmap[1];
                    Size    = new Size2(width, height);

                    var data      = new byte[width * height * 4];
                    var emptyRect = RectangleF.Empty;
                    using (CGContext imageContext = new CGBitmapContext(data, width, height, 8, width * 4, CGColorSpace.CreateDeviceRGB(), CGImageAlphaInfo.PremultipliedLast))
                        using (var cgImage = image.AsCGImage(ref emptyRect, null, null))
                        {
                            imageContext.DrawImage(new RectangleF(0, 0, width, height), cgImage);

                            Mipmaps[0] = new Mipmap(data, width, height, 1, 4);
                            if (flip)
                            {
                                Mipmaps[0].FlipVertical();
                            }
                        }
                }
            }
            catch (Exception e)
            {
                FailedToLoad = true;
                Loader.AddLoadableException(e);
                if (loadedCallback != null)
                {
                    loadedCallback(this, false);
                }
                return;
            }

            Loaded = true;
            if (loadedCallback != null)
            {
                loadedCallback(this, true);
            }
        }
Example #24
0
 public ImageIOS(string fileName, bool flip, Loader.LoadedCallbackMethod loadedCallback)
 {
     new StreamLoader(fileName,
                      delegate(object sender, bool succeeded)
     {
         if (succeeded)
         {
             init(((StreamLoader)sender).LoadedStream, flip, loadedCallback);
         }
         else
         {
             FailedToLoad = true;
             if (loadedCallback != null)
             {
                 loadedCallback(this, false);
             }
         }
     });
 }
Example #25
0
        protected override void init(Stream stream, bool flip, Loader.LoadedCallbackMethod loadedCallback)
        {
            try
            {
                using (var imageData = NSData.FromStream(stream))
                    using (var image = UIImage.LoadFromData(imageData))
                    {
                        int width  = (int)image.Size.Width;
                        int height = (int)image.Size.Height;
                        Mipmaps = new Mipmap[1];
                        Size    = new Size2(width, height);

                        var data = new byte[width * height * 4];
                        using (CGContext imageContext = new CGBitmapContext(data, width, height, 8, width * 4, CGColorSpace.CreateDeviceRGB(), CGImageAlphaInfo.PremultipliedLast))
                        {
                            imageContext.DrawImage(new RectangleF(0, 0, width, height), image.CGImage);

                            Mipmaps[0] = new Mipmap(data, width, height, 1, 4);
                            if (flip)
                            {
                                Mipmaps[0].FlipVertical();
                            }
                        }
                    }
            }
            catch (Exception e)
            {
                FailedToLoad = true;
                Loader.AddLoadableException(e);
                if (loadedCallback != null)
                {
                    loadedCallback(this, false);
                }
                return;
            }

            Loaded = true;
            if (loadedCallback != null)
            {
                loadedCallback(this, true);
            }
        }
Example #26
0
 public static void Init(DisposableI parent, string contentPath, string tag, ShaderVersions shaderVersion, ShaderFloatingPointQuality vsQuality, ShaderFloatingPointQuality psQuality, Loader.LoadedCallbackMethod loadedCallback)
 {
     Shader = ShaderAPI.New(parent, contentPath + tag + "UISolidColor.rs", shaderVersion, vsQuality, psQuality,
                            delegate(object sender, bool succeeded)
     {
         if (succeeded)
         {
             init((ShaderI)sender, loadedCallback);
         }
         else
         {
             FailedToLoad = true;
             if (loadedCallback != null)
             {
                 loadedCallback(null, false);
             }
         }
     });
 }
Example #27
0
		public void Dispose()
		{
			#if NaCl
			loadedCallback = null;
			#endif
		
			if (fromFile && LoadedStream != null)
			{
				LoadedStream.Dispose();
				LoadedStream = null;
			}
		}
Example #28
0
		private void init(string filename, Stream stream, Loader.LoadedCallbackMethod loadedCallback)
		#endif
		{
			try
			{
				if (filename != null)
				{
					fromFile = true;
					#if WINRT || WP8
					LoadedStream = await Streams.OpenFile(filename);
					#elif NaCl
					this.loadedCallback = loadedCallback;
					
					filename = filename.Replace('\\', '/');
					file = new NaClFile(filename);
					Streams.NaClFileLoadedCallback += fileLoaded;
					Streams.addPendingFile(file);
					Loader.AddLoadable(this);
					
					return;
					#else
					LoadedStream = Streams.OpenFile(filename);
					#endif
				}
				else
				{
					fromFile = false;
					LoadedStream = stream;
				}
			}
			catch (Exception e)
			{
				FailedToLoad = true;
				Loader.AddLoadableException(e);
				Dispose();
				if (loadedCallback != null) loadedCallback(this, false);
				return;
			}

			Loaded = true;
			if (loadedCallback != null) loadedCallback(this, true);
		}
Example #29
0
        private void init(string filename, Stream stream, ShaderVersions shaderVersion, Loader.LoadedCallbackMethod loadedCallback)
        {
            try
            {
                video = Parent.FindParentOrSelfWithException <Video>();

                var code = getShaders(stream);
                vertex = new VertexShader(this, code[0], (shaderVersion == ShaderVersions.Max) ? video.Caps.MaxVertexShaderVersion : shaderVersion);
                pixel  = new PixelShader(this, code[1], (shaderVersion == ShaderVersions.Max) ? video.Caps.MaxPixelShaderVersion : shaderVersion);

                variables = new List <ShaderVariable>();
                resources = new List <ShaderResource>();
            }
            catch (Exception e)
            {
                FailedToLoad = true;
                Loader.AddLoadableException(e);
                Dispose();
                if (loadedCallback != null)
                {
                    loadedCallback(this, false);
                }
                return;
            }

            Loaded = true;
            if (loadedCallback != null)
            {
                loadedCallback(this, true);
            }
        }
Example #30
0
        private void init(string filename, Stream stream, ShaderVersions shaderVersion, ShaderFloatingPointQuality vsQuality, ShaderFloatingPointQuality psQuality, Loader.LoadedCallbackMethod loadedCallback)
                #endif
        {
            try
            {
                video = Parent.FindParentOrSelfWithException <Video>();

                                #if WIN32
                shaderVersion = (shaderVersion == ShaderVersions.Max) ? video.Cap.MaxShaderVersion : shaderVersion;
                var code = getShaders(stream);
                vertex = new VertexShader(this, code[0], shaderVersion);
                pixel  = new PixelShader(this, code[1], shaderVersion);
                                #else
                await getReflections(filename);

                var code = getShaders(stream);
                vertex = new VertexShader(this, code[0]);
                pixel  = new PixelShader(this, code[1]);
                                #endif

                variables = new List <ShaderVariable>();
                resources = new List <ShaderResource>();
            }
            catch (Exception e)
            {
                FailedToLoad = true;
                Loader.AddLoadableException(e);
                Dispose();
                if (loadedCallback != null)
                {
                    loadedCallback(this, false);
                }
                return;
            }

            Loaded = true;
            if (loadedCallback != null)
            {
                loadedCallback(this, true);
            }
        }
Example #31
0
 private async void init(string filename, Stream stream, ShaderVersions shaderVersion, ShaderFloatingPointQuality vsQuality, ShaderFloatingPointQuality psQuality, Loader.LoadedCallbackMethod loadedCallback)
Example #32
0
 public Shader(IDisposableResource parent, string filename, ShaderVersions shaderVersion, ShaderFloatingPointQuality vsQuality, ShaderFloatingPointQuality psQuality, Loader.LoadedCallbackMethod loadedCallback)
     : base(parent)
 {
                 #if WINRT || WP8
     Loader.AddLoadable(this);
     filename = Streams.StripFileExt(filename) + ".mrs";
                 #endif
     new StreamLoader(filename,
                      delegate(object sender, bool succeeded)
     {
         if (succeeded)
         {
             init(filename, ((StreamLoader)sender).LoadedStream, shaderVersion, vsQuality, psQuality, loadedCallback);
         }
         else
         {
             FailedToLoad = true;
             Dispose();
             if (loadedCallback != null)
             {
                 loadedCallback(this, false);
             }
         }
     });
 }
Example #33
0
 private void finish()
 {
     LoadedCallback = null;
 }
Example #34
0
		private void fileLoaded(NaClFile file)
		{
			if (file.ID == this.file.ID)
			{
				Streams.NaClFileLoadedCallback -= fileLoaded;
				
				if (file.FailedToLoad)
				{
					FailedToLoad = true;
					if (loadedCallback != null) loadedCallback(this, false);
					loadedCallback = null;
					Dispose();
					return;
				}
				
				try
				{
					LoadedStream = new MemoryStream(file.Data);
					LoadedStream.Position = 0;
				}
				catch (Exception e)
				{
					FailedToLoad = true;
					Loader.AddLoadableException(e);
					if (loadedCallback != null) loadedCallback(this, false);
					loadedCallback = null;
					Dispose();
					return;
				}
				
				Loaded = true;
				if (loadedCallback != null) loadedCallback(this, true);
				loadedCallback = null;
			}
		}
Example #35
0
 public Shader(IDisposableResource parent, string filename, ShaderVersions shaderVersion, ShaderFloatingPointQuality vsQuality, ShaderFloatingPointQuality psQuality, Loader.LoadedCallbackMethod loadedCallback)
     : base(parent)
 {
     new StreamLoader(filename,
                      delegate(object sender, bool succeeded)
     {
         if (succeeded)
         {
             init(filename, ((StreamLoader)sender).LoadedStream, shaderVersion, loadedCallback);
         }
         else
         {
             FailedToLoad = true;
             Dispose();
             if (loadedCallback != null)
             {
                 loadedCallback(this, false);
             }
         }
     });
 }
Example #36
0
 protected virtual void init(IDisposableResource parent, Stream stream, int instanceCount, bool looped, Loader.LoadedCallbackMethod loadedCallback)
 {
     using (stream)
         using (var reader = new BinaryReader(stream))
         {
             readMetaData(stream, reader);
             data = reader.ReadBytes(dataSize);
         }
 }
Example #37
0
        private void bs_ImageOpened(object sender, RoutedEventArgs args)
        {
            try
            {
                var image = (BitmapImage)sender;
                var bitmap = new WriteableBitmap(image);

                int width = bitmap.PixelWidth;
                int height = bitmap.PixelHeight;
                Mipmaps = new Mipmap[1];
                Size = new Size2(bitmap.PixelWidth, bitmap.PixelHeight);

                var dataPixels = bitmap.Pixels;
                var data = new byte[dataPixels.Length * 4];
                int i2 = 0;
                for (int i = 0; i != dataPixels.Length; ++i)
                {
                    var color = new Color4(dataPixels[i]);
                    data[i2] = color.R;
                    data[i2+1] = color.G;
                    data[i2+2] = color.B;
                    data[i2+3] = color.A;

                    i2 += 4;
                }

                // Flip RB Color bits
                for (i2 = 0; i2 != data.Length; i2 += 4)
                {
                    byte c = data[i2];
                    data[i2] = data[i2+2];
                    data[i2+2] = c;
                }

                Mipmaps[0] = new Mipmap(data, width, height, 1, 4);
                if (flip) Mipmaps[0].FlipVertical();
            }
            catch (Exception e)
            {
                FailedToLoad = true;
                Loader.AddLoadableException(e);
                if (loadedCallback != null) loadedCallback(this, false);
                loadedCallback = null;
                return;
            }

            Loaded = true;
            if (loadedCallback != null) loadedCallback(this, true);
            loadedCallback = null;
        }