Beispiel #1
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);
            }
        }
Beispiel #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);
        }
Beispiel #3
0
        public Music(DisposableI parent, string fileName)
            : base(parent)
        {
            audio = parent.FindParentOrSelfWithException <Audio>();
            audio.UpdateCallback += Update;

            song = parent.FindParentOrSelfWithException <RootDisposable>().Content.Load <Song>(Streams.StripFileExt(fileName));
            MediaPlayer.IsRepeating = true;
        }
Beispiel #4
0
        public Music(DisposableI parent, string fileName)
            : base(parent)
        {
            audio = parent.FindParentOrSelfWithException<Audio>();
            audio.UpdateCallback += Update;

            song = parent.FindParentOrSelfWithException<RootDisposable>().Content.Load<Song>(Streams.StripFileExt(fileName));
            MediaPlayer.IsRepeating = true;
        }
Beispiel #5
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);
        }
Beispiel #6
0
        public DepthStencil(DisposableI parent, int width, int height, DepthStencilFormats depthStencilFormats)
            : base(parent)
        {
            try
            {
                video = parent.FindParentOrSelfWithException <Video>();

                PixelFormat format = PixelFormat.None;
                switch (depthStencilFormats)
                {
                case DepthStencilFormats.Defualt: format = PixelFormat.Depth16; break;

                case DepthStencilFormats.Depth24Stencil8: format = PixelFormat.Depth24Stencil8; break;

                case DepthStencilFormats.Depth16: format = PixelFormat.Depth16; break;

                case DepthStencilFormats.Depth24: format = PixelFormat.Depth24; break;

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

                depthBuffer = new DepthBuffer(width, height, format);
            }
            catch (Exception e)
            {
                Dispose();
                throw e;
            }
        }
Beispiel #7
0
        public DepthStencil(DisposableI parent, int width, int height, DepthStencilFormats depthStencilFormats)
            : base(parent)
        {
            try
            {
                video = parent.FindParentOrSelfWithException<Video>();

                PixelFormat format = PixelFormat.None;
                switch (depthStencilFormats)
                {
                    case DepthStencilFormats.Defualt: format = PixelFormat.Depth16; break;
                    case DepthStencilFormats.Depth24Stencil8: format = PixelFormat.Depth24Stencil8; break;
                    case DepthStencilFormats.Depth16: format = PixelFormat.Depth16; break;
                    case DepthStencilFormats.Depth24: format = PixelFormat.Depth24; break;

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

                depthBuffer = new DepthBuffer(width, height, format);
            }
            catch (Exception e)
            {
                Dispose();
                throw e;
            }
        }
Beispiel #8
0
        public Mouse(DisposableI parent)
            : base(parent)
        {
            input = parent.FindParentOrSelfWithException <Input>();
            input.UpdateEventCallback += updateEvent;
            input.UpdateCallback      += Update;

            Left   = new Button();
            Middle = new Button();
            Right  = new Button();
        }
Beispiel #9
0
        public Mouse(DisposableI parent)
            : base(parent)
        {
            input = parent.FindParentOrSelfWithException<Input>();
            input.UpdateEventCallback += updateEvent;
            input.UpdateCallback += Update;

            Left = new Button();
            Middle = new Button();
            Right = new Button();
        }
Beispiel #10
0
 private void init(DisposableI parent, BufferLayoutDescI bufferLayoutDesc)
 {
     try
     {
         video        = parent.FindParentOrSelfWithException <Video>();
         vertexBuffer = new VertexBuffer(this, bufferLayoutDesc, BufferUsages.Write, VertexBufferTopologys.Triangle, vertices);
     }
     catch (Exception e)
     {
         Dispose();
         throw e;
     }
 }
Beispiel #11
0
 private void init(DisposableI parent, BufferLayoutDescI bufferLayoutDesc)
 {
     try
     {
         video = parent.FindParentOrSelfWithException<Video>();
         vertexBuffer = new VertexBuffer(this, bufferLayoutDesc, BufferUsages.Write, VertexBufferTopologys.Triangle, vertices);
     }
     catch (Exception e)
     {
         Dispose();
         throw e;
     }
 }
Beispiel #12
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);
        }
Beispiel #13
0
        public Keyboard(DisposableI parent)
            : base(parent)
        {
            input = parent.FindParentOrSelfWithException<Input>();
            input.UpdateEventCallback += updateEvent;
            input.UpdateCallback += Update;

            keys = new bool[256];
            buttons = new Button[256];
            for (int i = 0; i != 256; ++i)
            {
                buttons[i] = new Button();
            }
        }
Beispiel #14
0
        public Keyboard(DisposableI parent)
            : base(parent)
        {
            input = parent.FindParentOrSelfWithException <Input>();
            input.UpdateEventCallback += UpdateEvent;
            input.UpdateCallback      += Update;

            keys    = new bool[256];
            buttons = new Button[256];
            for (int i = 0; i != 256; ++i)
            {
                buttons[i] = new Button();
            }
        }
Beispiel #15
0
        public TouchScreen(DisposableI parent)
            : base(parent)
        {
            input = parent.FindParentOrSelfWithException<Input>();
            input.UpdateEventCallback += UpdateEvent;
            input.UpdateCallback += Update;

            Touches = new Touch[ApplicationEvent.TouchCount];
            touchOn = new bool[ApplicationEvent.TouchCount];
            touchLocations = new Vector2[ApplicationEvent.TouchCount];
            for (int i = 0; i != ApplicationEvent.TouchCount; ++i)
            {
                Touches[i] = new Touch();
                touchLocations[i] = new Vector2();
            }
        }
Beispiel #16
0
        public TouchScreen(DisposableI parent)
            : base(parent)
        {
            input = parent.FindParentOrSelfWithException <Input>();
            input.UpdateEventCallback += UpdateEvent;
            input.UpdateCallback      += Update;

            Touches        = new Touch[ApplicationEvent.TouchCount];
            touchOn        = new bool[ApplicationEvent.TouchCount];
            touchLocations = new Vector2[ApplicationEvent.TouchCount];
            for (int i = 0; i != ApplicationEvent.TouchCount; ++i)
            {
                Touches[i]        = new Touch();
                touchLocations[i] = new Vector2();
            }
        }
Beispiel #17
0
        private void init(DisposableI parent, BufferLayoutDescI bufferLayoutDesc, BufferUsages bufferUsage, VertexBufferTopologys vertexBufferTopology, float[] vertices, int[] indices)
        {
            try
            {
                video    = parent.FindParentOrSelfWithException <Video>();
                Topology = vertexBufferTopology;

                var format = new G.VertexFormat[bufferLayoutDesc.Elements.Count];
                for (int i = 0; i != bufferLayoutDesc.Elements.Count; ++i)
                {
                    switch (bufferLayoutDesc.Elements[i].FloatCount)
                    {
                    case 1: format[i] = G.VertexFormat.Float; break;

                    case 2: format[i] = G.VertexFormat.Float2; break;

                    case 3: format[i] = G.VertexFormat.Float3; break;

                    case 4: format[i] = G.VertexFormat.Float4; break;
                    }
                }

                if (indices != null && indices.Length != 0)
                {
                    vertexBuffer = new G.VertexBuffer(vertexCount, indices.Length, format);

                    indexCount = indices.Length;
                    var indicesShort = new ushort[indexCount];
                    for (int i = 0; i != indexCount; ++i)
                    {
                        indicesShort[i] = (ushort)indices[i];
                    }
                    vertexBuffer.SetIndices(indicesShort);
                }
                else
                {
                    vertexBuffer = new G.VertexBuffer(vertexCount, format);
                }
                vertexBuffer.SetVertices(vertices);
            }
            catch (Exception e)
            {
                Dispose();
                throw e;
            }
        }
Beispiel #18
0
        protected virtual bool init(DisposableI parent, string fileName, 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)
                {
                    generateMipmaps = false;
                }

                if (fileName != null)
                {
                    texture = new G.Texture2D("/Application/" + fileName, generateMipmaps);
                }
                else
                {
                    texture = new G.Texture2D(width, height, generateMipmaps, Video.surfaceFormat(surfaceFormat), isRenderTarget ? G.PixelBufferOption.Renderable : G.PixelBufferOption.None);
                }
            }
            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);
        }
Beispiel #19
0
        private void init(DisposableI parent, ShaderI shader, BufferLayoutDescI inputLayoutDesc, bool construct)
        {
            if (!construct)
            {
                return;
            }

            try
            {
                video = parent.FindParentOrSelfWithException <Video>();

                var inputLayoutDescTEMP = (BufferLayoutDesc)inputLayoutDesc;
                layout = new VertexDeclaration(inputLayoutDescTEMP.desc);
            }
            catch (Exception e)
            {
                Dispose();
                throw e;
            }
        }
Beispiel #20
0
        public GamePad(DisposableI parent, GamePadControllers controller)
            : base(parent)
        {
            input = parent.FindParentOrSelfWithException <Input>();
            input.UpdateCallback += Update;

            switch (controller)
            {
            case GamePadControllers.All: useAllControllers = true; break;

            case GamePadControllers.One: playerIndex = F.PlayerIndex.One; break;

            case GamePadControllers.Two: playerIndex = F.PlayerIndex.Two; break;

            case GamePadControllers.Three: playerIndex = F.PlayerIndex.Three; break;

            case GamePadControllers.Four: playerIndex = F.PlayerIndex.Four; break;

            default: Debug.ThrowError("GamePad", "Unsuported controller"); break;
            }

            Back             = new Button();
            Start            = new Button();
            A                = new Button();
            B                = new Button();
            X                = new Button();
            Y                = new Button();
            LeftBumper       = new Button();
            RightBumper      = new Button();
            LeftStickButton  = new Button();
            RightStickButton = new Button();
            DLeft            = new Button();
            DRight           = new Button();
            DDown            = new Button();
            DUp              = new Button();
            LeftTrigger      = new Trigger();
            RightTrigger     = new Trigger();

            LeftStick  = new Vector2();
            RightStick = new Vector2();
        }
Beispiel #21
0
        public IndexBuffer(DisposableI parent, BufferUsages bufferUsage, int[] indices)
            : base(parent, bufferUsage, indices)
        {
            try
            {
                video = parent.FindParentOrSelfWithException <Video>();

                                #if SILVERLIGHT
                X.IndexElementSize elementSize = X.IndexElementSize.SixteenBits;
                                #else
                X.IndexElementSize elementSize = _32BitIndices ? X.IndexElementSize.ThirtyTwoBits : X.IndexElementSize.SixteenBits;
                                #endif
                indexBuffer = new X.IndexBuffer(video.Device, elementSize, indices.Length, X.BufferUsage.WriteOnly);
                Update(indices, indexCount);
            }
            catch (Exception e)
            {
                Dispose();
                throw e;
            }
        }
Beispiel #22
0
        public IndexBuffer(DisposableI parent, BufferUsages bufferUsage, int[] indices)
            : base(parent, bufferUsage, indices)
        {
            try
            {
                video = parent.FindParentOrSelfWithException<Video>();

                #if SILVERLIGHT
                X.IndexElementSize elementSize = X.IndexElementSize.SixteenBits;
                #else
                X.IndexElementSize elementSize = _32BitIndices ? X.IndexElementSize.ThirtyTwoBits : X.IndexElementSize.SixteenBits;
                #endif
                indexBuffer = new X.IndexBuffer(video.Device, elementSize, indices.Length, X.BufferUsage.WriteOnly);
                Update(indices, indexCount);
            }
            catch (Exception e)
            {
                Dispose();
                throw e;
            }
        }
Beispiel #23
0
        private void init(DisposableI parent, BufferLayoutDescI bufferLayoutDesc, BufferUsages bufferUsage, VertexBufferTopologys vertexBufferTopology, float[] vertices, int[] indices)
        {
            try
            {
                video        = parent.FindParentOrSelfWithException <Video>();
                Topology     = vertexBufferTopology;
                bufferLayout = new BufferLayout(this, null, bufferLayoutDesc, true);

                vertexBuffer = new X.VertexBuffer(video.Device, bufferLayout.layout, vertexCount, X.BufferUsage.WriteOnly);
                Update(vertices, vertexCount);

                if (indices != null && indices.Length != 0)
                {
                    indexBuffer = new IndexBuffer(this, usage, indices);
                }
            }
            catch (Exception e)
            {
                Dispose();
                throw e;
            }
        }
Beispiel #24
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);
            }
        }
Beispiel #25
0
        public GamePad(DisposableI parent, GamePadControllers controller)
            : base(parent)
        {
            input = parent.FindParentOrSelfWithException<Input>();
            input.UpdateCallback += Update;

            switch (controller)
            {
                case GamePadControllers.All: useAllControllers = true; break;
                case GamePadControllers.One: playerIndex = F.PlayerIndex.One; break;
                case GamePadControllers.Two: playerIndex = F.PlayerIndex.Two; break;
                case GamePadControllers.Three: playerIndex = F.PlayerIndex.Three; break;
                case GamePadControllers.Four: playerIndex = F.PlayerIndex.Four; break;
                default: Debug.ThrowError("GamePad", "Unsuported controller"); break;
            }

            Back = new Button();
            Start = new Button();
            A = new Button();
            B = new Button();
            X = new Button();
            Y = new Button();
            LeftBumper = new Button();
            RightBumper = new Button();
            LeftStickButton = new Button();
            RightStickButton = new Button();
            DLeft = new Button();
            DRight = new Button();
            DDown = new Button();
            DUp = new Button();
            LeftTrigger = new Trigger();
            RightTrigger = new Trigger();

            LeftStick = new Vector2();
            RightStick = new Vector2();
        }
Beispiel #26
0
        protected override void init(DisposableI parent, System.IO.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.sampleRate       = base.sampleRate;
                this.bitDepth         = base.bitDepth;

                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);
            }
        }
Beispiel #27
0
 public RasterizerState(DisposableI parent, RasterizerStateDescI desc)
     : base(parent)
 {
     this.video = parent.FindParentOrSelfWithException <Video>();
     this.desc  = (RasterizerStateDesc)desc;
 }
Beispiel #28
0
        protected virtual bool init(DisposableI parent, string fileName, 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) generateMipmaps = false;

                if (fileName != null)
                {
                    texture = new G.Texture2D("/Application/" + fileName, generateMipmaps);
                }
                else
                {
                    texture = new G.Texture2D(width, height, generateMipmaps, Video.surfaceFormat(surfaceFormat), isRenderTarget ? G.PixelBufferOption.Renderable : G.PixelBufferOption.None);
                }
            }
            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;
        }
 public DepthStencilState(DisposableI parent, DepthStencilStateDescI desc)
     : base(parent)
 {
     video = parent.FindParentOrSelfWithException<Video>();
     this.desc = (DepthStencilStateDesc)desc;
 }
Beispiel #30
0
 public SamplerState(DisposableI parent, SamplerStateDescI desc)
     : base(parent)
 {
     video     = parent.FindParentOrSelfWithException <Video>();
     this.desc = (SamplerStateDesc)desc;
 }
Beispiel #31
0
        private void init(DisposableI parent, BufferLayoutDescI bufferLayoutDesc, BufferUsages bufferUsage, VertexBufferTopologys vertexBufferTopology, float[] vertices, int[] indices)
        {
            try
            {
                video = parent.FindParentOrSelfWithException<Video>();
                Topology = vertexBufferTopology;
                bufferLayout = new BufferLayout(this, null, bufferLayoutDesc, true);

                vertexBuffer = new X.VertexBuffer(video.Device, bufferLayout.layout, vertexCount, X.BufferUsage.WriteOnly);
                Update(vertices, vertexCount);

                if (indices != null && indices.Length != 0) indexBuffer = new IndexBuffer(this, usage, indices);
            }
            catch (Exception e)
            {
                Dispose();
                throw e;
            }
        }
Beispiel #32
0
        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);
        }
 public RasterizerState(DisposableI parent, RasterizerStateDescI desc)
     : base(parent)
 {
     this.video = parent.FindParentOrSelfWithException<Video>();
     this.desc = (RasterizerStateDesc)desc;
 }
Beispiel #34
0
 public DepthStencilState(DisposableI parent, DepthStencilStateDescI desc)
     : base(parent)
 {
     video     = parent.FindParentOrSelfWithException <Video>();
     this.desc = (DepthStencilStateDesc)desc;
 }
Beispiel #35
0
 public SamplerState(DisposableI parent, SamplerStateDescI desc)
     : base(parent)
 {
     video = parent.FindParentOrSelfWithException<Video>();
     this.desc = (SamplerStateDesc)desc;
 }
Beispiel #36
0
        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;
        }
Beispiel #37
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);
            }
        }
Beispiel #38
0
 public BufferLayout(DisposableI parent, ShaderI shader, BufferLayoutDescI desc)
     : base(parent)
 {
     video     = parent.FindParentOrSelfWithException <Video>();
     this.desc = (BufferLayoutDesc)desc;
 }