Ejemplo n.º 1
0
        public static IShader New(VideoTypes videoType, IDisposableResource parent, string filename, ShaderVersions shaderVersion, ShaderFloatingPointQuality vsQuality, ShaderFloatingPointQuality psQuality, Loader.LoadedCallbackMethod loadedCallback)
        {
            IShader api = null;

            #if WIN32
            if (videoType == VideoTypes.D3D9) api = new D3D9.Shader(parent, filename, shaderVersion, vsQuality, psQuality, loadedCallback);
            #endif

            #if WIN32 || WINRT || WP8
            if (videoType == VideoTypes.D3D11) api = new D3D11.Shader(parent, filename, shaderVersion, vsQuality, psQuality, loadedCallback);
            #endif

            #if WIN32 || OSX || LINUX || iOS || ANDROID || NaCl
            if (videoType == VideoTypes.OpenGL) api = new OpenGL.Shader(parent, filename, shaderVersion, vsQuality, psQuality, loadedCallback);
            #endif

            #if XNA
            if (videoType == VideoTypes.XNA) api = new XNA.Shader(parent, filename, shaderVersion, vsQuality, psQuality, loadedCallback);
            #endif

            #if VITA
            if (videoType == VideoTypes.Vita) api = new Vita.Shader(parent, filename, shaderVersion, vsQuality, psQuality, loadedCallback);
            #endif

            if (api == null) Debug.ThrowError("ShaderAPI", "Unsuported InputType: " + videoType);
            return api;
        }
Ejemplo n.º 2
0
        public SoundWAV(DisposableI parent, string fileName, int instanceCount, bool looped, Loader.LoadedCallbackMethod loadedCallback)
            : base(parent)
        {
            try
            {
                audio = parent.FindParentOrSelfWithException<Audio>();
                audio.UpdateCallback += Update;

                loadedFromContent = true;
                sound = parent.FindParentOrSelfWithException<RootDisposable>().Content.Load<SoundEffect>(Streams.StripFileExt(fileName));

                for (int i = 0; i != instanceCount; ++i)
                {
                    inactiveInstances.AddLast(new SoundWAVInstance(this, looped));
                }
            }
            catch (Exception e)
            {
                FailedToLoad = true;
                Loader.AddLoadableException(e);
                Dispose();
                if (loadedCallback != null) loadedCallback(this, false);
                return;
            }

            Loaded = true;
            if (loadedCallback != null) loadedCallback(this, true);
        }
Ejemplo n.º 3
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);
        }
Ejemplo n.º 4
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);
        }
Ejemplo n.º 5
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);
		}
Ejemplo n.º 6
0
		public Model(IDisposableResource parent, SoftwareModel softwareModel, bool loadColors, bool loadUVs, bool loadNormals, string contentDirectory, Dictionary<string,Type> materialTypes, List<MaterialFieldBinder> value1BinderTypes, List<MaterialFieldBinder> value2BinderTypes, List<MaterialFieldBinder> value3BinderTypes, List<MaterialFieldBinder> value4BinderTypes, List<MaterialFieldBinder> textureBinderTypes, Dictionary<string,string> fileExtOverrides, int classicInstanceCount, Loader.LoadedCallbackMethod loadedCallback)
		: base(parent)
		{
			Loader.AddLoadable(this);
			new LoadWaiter(new ILoadable[]{softwareModel},
			delegate(object sender, bool succeeeded)
			{
				if (succeeeded)
				{
					using (var stream = new MemoryStream())
					{
						try
						{
							Model.Save(stream, false, softwareModel, loadColors, loadUVs, loadNormals);
							stream.Position = 0;
						}
						catch (Exception e)
						{
							FailedToLoad = true;
							Dispose();
							if (loadedCallback != null) loadedCallback(this, false);
						}

						if (!FailedToLoad) init(null, stream, contentDirectory, materialTypes, value1BinderTypes, value2BinderTypes, value3BinderTypes, value4BinderTypes, textureBinderTypes, fileExtOverrides, classicInstanceCount, loadedCallback);
					}
				}
				else
				{
					FailedToLoad = true;
					Dispose();
					if (loadedCallback != null) loadedCallback(this, false);
				}
			});
		}
Ejemplo n.º 7
0
        protected override void init(DisposableI parent, Stream stream, int instanceCount, bool looped, Loader.LoadedCallbackMethod loadedCallback)
        {
            base.init(parent, stream, instanceCount, looped, loadedCallback);

            try
            {
                audio = parent.FindParentOrSelfWithException<Audio>();
                audio.UpdateCallback += Update;
                this.data = base.data;
                this.channels = base.channels;
                this.bitDepth = base.bitDepth;

                desc = AudioUnitUtils.AUCanonicalASBD(sampleRate, channels);
                desc.FormatFlags = (AudioFormatFlags)((int)AudioFormatFlags.IsSignedInteger | (int)AudioFormatFlags.IsPacked | (int)AudioFormatFlags.IsNonInterleaved);

                for (int i = 0; i != instanceCount; ++i)
                {
                    inactiveInstances.AddLast(new SoundWAVInstance(this, looped));
                }
            }
            catch (Exception e)
            {
                FailedToLoad = true;
                Loader.AddLoadableException(e);
                Dispose();
                if (loadedCallback != null) loadedCallback(this, false);
                return;
            }

            Loaded = true;
            if (loadedCallback != null) loadedCallback(this, true);
        }
Ejemplo n.º 8
0
        public static ITexture2D New(VideoTypes videoType, IDisposableResource parent, Image image, int width, int height, bool generateMipmaps, MultiSampleTypes multiSampleType, SurfaceFormats surfaceFormat, RenderTargetUsage renderTargetUsage, BufferUsages usage, Loader.LoadedCallbackMethod loadedCallback)
        {
            ITexture2D api = null;

            #if WIN32
            if (videoType == VideoTypes.D3D9) api = new D3D9.Texture2D(parent, image, width, height, generateMipmaps, multiSampleType, surfaceFormat, renderTargetUsage, usage, loadedCallback);
            #endif

            #if WIN32 || WINRT || WP8
            if (videoType == VideoTypes.D3D11) api = new D3D11.Texture2D(parent, image, width, height, generateMipmaps, multiSampleType, surfaceFormat, renderTargetUsage, usage, loadedCallback);
            #endif

            #if WIN32 || OSX || LINUX || iOS || ANDROID || NaCl
            if (videoType == VideoTypes.OpenGL) api = new OpenGL.Texture2D(parent, image, width, height, generateMipmaps, multiSampleType, surfaceFormat, renderTargetUsage, usage, loadedCallback);
            #endif

            #if XNA
            if (videoType == VideoTypes.XNA) api = new XNA.Texture2D(parent, image, width, height, generateMipmaps, multiSampleType, surfaceFormat, renderTargetUsage, usage, loadedCallback);
            #endif

            #if VITA
            if (videoType == VideoTypes.Vita) api = new Vita.Texture2D(parent, image, width, height, generateMipmaps, multiSampleType, surfaceFormat, renderTargetUsage, usage, loadedCallback);
            #endif

            if (api == null) Debug.ThrowError("Texture2DAPI", "Unsuported InputType: " + videoType);
            return api;
        }
Ejemplo n.º 9
0
        protected override void init(IDisposableResource parent, Stream stream, int instanceCount, bool looped, Loader.LoadedCallbackMethod loadedCallback)
        {
            base.init(parent, stream, instanceCount, looped, loadedCallback);

            try
            {
                audio = parent.FindParentOrSelfWithException<Audio>();
                audio.UpdateCallback += Update;

                com = new SoundWAVCom();
                var error = com.Init(audio.com, data, formatCode, channels, sampleRate, formatAvgBytesPerSec, formatBlockAlign, bitDepth, formatExtraSize);
                data = null;

                for (int i = 0; i != instanceCount; ++i)
                {
                    inactiveInstances.AddLast(new SoundWAVInstance(this, looped));
                }
            }
            catch (Exception e)
            {
                FailedToLoad = true;
                Loader.AddLoadableException(e);
                Dispose();
                if (loadedCallback != null) loadedCallback(this, false);
                return;
            }

            Loaded = true;
            if (loadedCallback != null) loadedCallback(this, true);
        }
Ejemplo n.º 10
0
		protected override void init(Stream stream, bool flip, Loader.LoadedCallbackMethod loadedCallback)
		{
			ImageType = ImageTypes.BMP;
			ImageFormat = ImageFormats.BMP;
			SurfaceFormat = SurfaceFormats.RGBAx8;

			base.init(stream, flip, loadedCallback);
		}
Ejemplo n.º 11
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);
     }
 }
Ejemplo n.º 12
0
        public SoundWAV(IDisposableResource parent, string filename, int instanceCount, bool looped, Loader.LoadedCallbackMethod loadedCallback)
            : base(parent)
        {
            for (int i = 0; i != instanceCount; ++i)
            {
                inactiveInstances.AddLast(new SoundWAVInstance(this, looped));
            }

            Loaded = true;
            if (loadedCallback != null) loadedCallback(this, true);
        }
Ejemplo n.º 13
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);
            });
        }
Ejemplo n.º 14
0
        protected unsafe override void init(DisposableI parent, Stream stream, int instanceCount, bool looped, Loader.LoadedCallbackMethod loadedCallback)
        {
            base.init(parent, stream, instanceCount, looped, loadedCallback);

            try
            {
                audio = parent.FindParentOrSelfWithException<Audio>();
                audio.UpdateCallback += Update;

                // Gen buffer
                uint bufferTEMP = 0;
                AL.GenBuffers(1, &bufferTEMP);
                buffer = bufferTEMP;
                if (buffer == 0) Debug.ThrowError("SoundWAV", "Failed to create buffer");

                // load wav data
                int format = 0;
                if (bitDepth == 16)
                {
                    if (channels == 2) format = AL.FORMAT_STEREO16;
                    else format = AL.FORMAT_MONO16;
                }
                else
                {
                    if (channels == 2) format = AL.FORMAT_STEREO8;
                    else format = AL.FORMAT_MONO8;
                }
                fixed (byte* dataPtr = data)
                {
                    AL.BufferData(buffer, format, dataPtr, data.Length, sampleRate);
                }
                data = null;

                // create instances
                for (int i = 0; i != instanceCount; ++i)
                {
                    inactiveInstances.AddLast(new SoundWAVInstance(this, looped));
                }
            }
            catch (Exception e)
            {
                FailedToLoad = true;
                Loader.AddLoadableException(e);
                Dispose();
                if (loadedCallback != null) loadedCallback(this, false);
                return;
            }

            Loaded = true;
            if (loadedCallback != null) loadedCallback(this, true);
        }
Ejemplo n.º 15
0
 public static void Init(DisposableI parent, string contentPath, string tag, ShaderVersions shaderVersion, Loader.LoadedCallbackMethod loadedCallback)
 {
     Shader = ShaderAPI.New(parent, contentPath + tag + "QuickDraw3Color.rs", shaderVersion,
     delegate(object sender, bool succeeded)
     {
         if (succeeded)
         {
             init((ShaderI)sender, loadedCallback);
         }
         else
         {
             FailedToLoad = true;
             if (loadedCallback != null) loadedCallback(null, false);
         }
     });
 }
Ejemplo n.º 16
0
 public ImageOSX(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);
         }
     });
 }
Ejemplo n.º 17
0
 public SoundWAV(IDisposableResource parent, string filename, int instanceCount, bool looped, Loader.LoadedCallbackMethod loadedCallback)
     : base(parent)
 {
     new StreamLoader(filename,
     delegate(object sender,  bool succeeded)
     {
         if (succeeded)
         {
             init(parent, ((StreamLoader)sender).LoadedStream, instanceCount, looped, loadedCallback);
         }
         else
         {
             FailedToLoad = true;
             Dispose();
             if (loadedCallback != null) loadedCallback(this, false);
         }
     });
 }
Ejemplo n.º 18
0
 public Font(DisposableI parent, ShaderI shader, Texture2DI texture, string metricsFileName, Loader.LoadedCallbackMethod loadedCallback)
     : base(parent)
 {
     new StreamLoader(metricsFileName,
     delegate(object sender, bool succeeded)
     {
         if (succeeded)
         {
             init(shader, texture, ((StreamLoader)sender).LoadedStream, metricsFileName, loadedCallback);
         }
         else
         {
             FailedToLoad = true;
             Dispose();
             if (loadedCallback != null) loadedCallback(this, false);
         }
     });
 }
Ejemplo n.º 19
0
		public Model(IDisposableResource parent, string filename, string contentDirectory, Dictionary<string,Type> materialTypes, List<MaterialFieldBinder> value1BinderTypes, List<MaterialFieldBinder> value2BinderTypes, List<MaterialFieldBinder> value3BinderTypes, List<MaterialFieldBinder> value4BinderTypes, List<MaterialFieldBinder> textureBinderTypes, Dictionary<string,string> fileExtOverrides, int classicInstanceCount, Loader.LoadedCallbackMethod loadedCallback)
		: base(parent)
		{
			Loader.AddLoadable(this);
			new StreamLoader(filename,
			delegate(object sender, bool succeeded)
			{
				if (succeeded)
				{
					init(filename, ((StreamLoader)sender).LoadedStream, contentDirectory, materialTypes, value1BinderTypes, value2BinderTypes, value3BinderTypes, value4BinderTypes, textureBinderTypes, fileExtOverrides, classicInstanceCount, loadedCallback);
				}
				else
				{
					FailedToLoad = true;
					Dispose();
					if (loadedCallback != null) loadedCallback(this, false);
				}
			});
		}
Ejemplo n.º 20
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);
                }
            });
        }
Ejemplo n.º 21
0
 public Texture2D(IDisposableResource parent, string filename, int width, int height, bool generateMipmaps, MultiSampleTypes multiSampleType, SurfaceFormats surfaceFormat, RenderTargetUsage renderTargetUsage, BufferUsages usage, Loader.LoadedCallbackMethod loadedCallback)
     : base(parent)
 {
     Image.New(filename, false,
     delegate (object sender, bool succeeded)
     {
         if (succeeded)
         {
             var image = (Image)sender;
             init(parent, image, image.Size.Width, image.Size.Height, generateMipmaps, MultiSampleTypes.None, image.SurfaceFormat, RenderTargetUsage.PlatformDefault, usage, false, loadedCallback);
         }
         else
         {
             FailedToLoad = true;
             Dispose();
             if (loadedCallback != null) loadedCallback(this, false);
         }
     });
 }
Ejemplo n.º 22
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);
		}
Ejemplo n.º 23
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);
        }
Ejemplo n.º 24
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);
				}
			});
		}
Ejemplo n.º 25
0
 public Shader(DisposableI parent, string fileName, ShaderVersions shaderVersion, ShaderFloatingPointQuality vsQuality, ShaderFloatingPointQuality psQuality, Loader.LoadedCallbackMethod loadedCallback)
     : base(parent)
 {
     #if SILVERLIGHT
     new StreamLoader(Streams.StripFileExt(fileName) + ".mrs",
     delegate(object sender, bool succeeded)
     {
         if (succeeded)
         {
             init(fileName, ((StreamLoader)sender).LoadedStream, shaderVersion, loadedCallback);
         }
         else
         {
             FailedToLoad = true;
             Dispose();
             if (loadedCallback != null) loadedCallback(this, false);
         }
     });
     #else
     init(fileName, null, shaderVersion, loadedCallback);
     #endif
 }
Ejemplo n.º 26
0
        protected override bool init(IDisposableResource parent, Image image, int width, int height, bool generateMipmaps, MultiSampleTypes multiSampleType, SurfaceFormats surfaceFormat, RenderTargetUsage renderTargetUsage, BufferUsages usage, bool isRenderTarget, Loader.LoadedCallbackMethod loadedCallback)
        {
            initSuccess = base.init(parent, image, width, height, generateMipmaps, multiSampleType, surfaceFormat, renderTargetUsage, usage, true, loadedCallback);
            if (!initSuccess) return false;

            try
            {
                if (usage == BufferUsages.Write) Debug.ThrowError("RenderTarget", "Only Textures may be writable");

                if (image != null)
                {
                    width = image.Size.Width;
                    height = image.Size.Height;
                    surfaceFormat = image.SurfaceFormat;
                }

                renderTargetCom = new RenderTargetCom();
                var error = renderTargetCom.Init(video.com, width, height, com, 0, video.surfaceFormat(surfaceFormat), usage == BufferUsages.Read);

                switch (error)
                {
                    case RenderTargetError.RenderTargetView: Debug.ThrowError("RenderTarget", "Failed to create RenderTargetView"); break;
                    case RenderTargetError.StagingTexture: Debug.ThrowError("RenderTarget", "Failed to create Staging Texture"); break;
                }
            }
            catch (Exception e)
            {
                FailedToLoad = true;
                Loader.AddLoadableException(e);
                Dispose();
                if (loadedCallback != null) loadedCallback(this, false);
                return false;
            }

            Loaded = true;
            if (loadedCallback != null) loadedCallback(this, true);
            return true;
        }
Ejemplo n.º 27
0
 public Texture2D(DisposableI parent, string fileName, bool generateMipmaps, BufferUsages usage, 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, generateMipmaps, MultiSampleTypes.None, SurfaceFormats.Unknown, RenderTargetUsage.PlatformDefault, usage, false, loadedCallback);
         }
         else
         {
             FailedToLoad = true;
             Dispose();
             if (loadedCallback != null) loadedCallback(this, false);
         }
     });
     #else
     init(parent, fileName, null, 0, 0, generateMipmaps, MultiSampleTypes.None, SurfaceFormats.Unknown, RenderTargetUsage.PlatformDefault, usage, false, loadedCallback);
     #endif
 }
Ejemplo n.º 28
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);
		}
Ejemplo n.º 29
0
		private async void init(string filename, Stream stream, ShaderVersions shaderVersion, ShaderFloatingPointQuality vsQuality, ShaderFloatingPointQuality psQuality, Loader.LoadedCallbackMethod loadedCallback)
Ejemplo n.º 30
0
        protected override bool init(DisposableI parent, string fileName, Image image, int width, int height, bool generateMipmaps, MultiSampleTypes multiSampleType, SurfaceFormats surfaceFormat, RenderTargetUsage renderTargetUsage, BufferUsages usage, bool isRenderTarget, Loader.LoadedCallbackMethod loadedCallback)
        {
            if (!base.init(parent, fileName, image, width, height, false, multiSampleType, surfaceFormat, renderTargetUsage, usage, true, loadedCallback)) return false;

            try
            {
                if (usage == BufferUsages.Write) Debug.ThrowError("RenderTarget", "Only Textures may be writable");

                if (fileName == null)
                {
                    // TODO: handle multiSampleType types
                    #if SILVERLIGHT
                    var xUsage = X.RenderTargetUsage.PreserveContents;
                    #else
                    var xUsage = X.RenderTargetUsage.PlatformContents;
                    #endif
                    switch (renderTargetUsage)
                    {
                        case RenderTargetUsage.PlatformDefault:
                            #if SILVERLIGHT
                            xUsage = X.RenderTargetUsage.PreserveContents;
                            #else
                            xUsage = X.RenderTargetUsage.PlatformContents;
                            #endif
                            break;

                        case RenderTargetUsage.PreserveContents: xUsage = X.RenderTargetUsage.PreserveContents; break;
                        case RenderTargetUsage.DiscardContents: xUsage = X.RenderTargetUsage.DiscardContents; break;
                    }

                    X.DepthFormat format = X.DepthFormat.None;
                    if (initDepthStencilFormat != DepthStencilFormats.None)
                    {
                        switch (initDepthStencilFormat)
                        {
                            case DepthStencilFormats.Defualt: format = X.DepthFormat.Depth24; break;
                            case DepthStencilFormats.Depth24Stencil8: format = X.DepthFormat.Depth24Stencil8; break;
                            case DepthStencilFormats.Depth16: format = X.DepthFormat.Depth16; break;
                            case DepthStencilFormats.Depth24: format = X.DepthFormat.Depth24; break;

                            default:
                                Debug.ThrowError("RenderTarget", "Unsuported DepthStencilFormat type");
                                break;
                        }
                    }

                    renderTarget = new X.RenderTarget2D(video.Device, width, height, false, Video.surfaceFormat(surfaceFormat), format, 0, xUsage);
                }
                else
                {
                    Debug.ThrowError("RenderTarget", "(Load image data into RenderTarget Texture) -- Not implemented yet...");
                }

                texture = renderTarget;
            }
            catch (Exception e)
            {
                FailedToLoad = true;
                Loader.AddLoadableException(e);
                Dispose();
                if (loadedCallback != null) loadedCallback(this, false);
                return false;
            }

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