コード例 #1
0
ファイル: Texture2D.cs プロジェクト: reignstudios/ReignSDK
        protected virtual 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)
        {
            try
            {
                if (usage == BufferUsages.Read && !isRenderTarget) Debug.ThrowError("Texture2D", "Only RenderTargets may be readable");

                video = parent.FindParentOrSelfWithException<Video>();

                if (!isRenderTarget)
                {
                    if (fileName != null || image != null)
                    {
                        #if SILVERLIGHT
                        texture = new X.Texture2D(video.Device, image.Size.Width, image.Size.Height, image.Mipmaps.Length != 0, Video.surfaceFormat(surfaceFormat));
                        for (int i = 0; i != image.Mipmaps.Length; ++i)
                        {
                            var mipmap = image.Mipmaps[i];
                            texture.SetData<byte>(i, null, mipmap.Data, 0, mipmap.Data.Length);
                        }
                        #else
                        texture = parent.FindParentOrSelfWithException<RootDisposable>().Content.Load<X.Texture2D>(Streams.StripFileExt(fileName));
                        loadedFromContentManager = true;
                        #endif
                    }
                    else
                    {
                        texture = new X.Texture2D(video.Device, width, height, generateMipmaps, Video.surfaceFormat(surfaceFormat));
                    }

                    Size = new Size2(texture.Width, texture.Height);
                    PixelByteSize = Image.CalculatePixelByteSize(surfaceFormat, texture.Width, texture.Height);
                }
                else
                {
                    Size = new Size2(width, height);
                    PixelByteSize = Image.CalculatePixelByteSize(surfaceFormat, width, height);
                }

                TexelOffset = (1 / Size.ToVector2()) * .5f;
                SizeF = Size.ToVector2();
            }
            catch (Exception e)
            {
                FailedToLoad = true;
                Loader.AddLoadableException(e);
                Dispose();
                if (loadedCallback != null) loadedCallback(this, false);
                return false;
            }

            if (!isRenderTarget)
            {
                Loaded = true;
                if (loadedCallback != null) loadedCallback(this, true);
            }
            return true;
        }
コード例 #2
0
ファイル: Texture2D.cs プロジェクト: reignstudios/ReignSDK
 public override void Dispose()
 {
     disposeChilderen();
     if (texture != null && !loadedFromContentManager)
     {
         texture.Dispose();
         texture = null;
     }
     base.Dispose();
 }