Beispiel #1
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 #2
0
 public Input(DisposableI parent, XAMLApplication application)
     : base(parent)
 {
     this.applicationI = application;
     this.pageApplication = application;
     application.HandleEvent += updateEvent;
 }
Beispiel #3
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 #4
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 #5
0
 public Input(DisposableI parent, XAMLApplication application)
     : base(parent)
 {
     this.applicationI        = application;
     this.pageApplication     = application;
     application.HandleEvent += updateEvent;
 }
Beispiel #6
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 #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 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
 }
Beispiel #9
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
 }
Beispiel #10
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 #11
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 #12
0
        public unsafe Audio(DisposableI parent)
            : base(parent)
        {
            device = AL.OpenDevice((byte*)0);
            context = AL.CreateContext(device, new int[]{});
            AL.MakeContextCurrent(context);

            AL.Listener3f(AL.POSITION, 0, 0, 0);
            AL.Listener3f(AL.VELOCITY, 0, 0, 0);
            AL.Listener3f(AL.ORIENTATION, 0, 0, -1);
        }
Beispiel #13
0
        public Audio(DisposableI parent)
            : base(parent)
        {
            #if OSX
            component = AudioComponent.FindComponent(AudioTypeOutput.Default);
            #else
            component = AudioComponent.FindComponent(AudioTypeOutput.Remote);
            #endif

            if (component == null) Debug.ThrowError("Audio", "Failed to find AudioComponent");
        }
Beispiel #14
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 #15
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 #16
0
        public unsafe Audio(DisposableI parent)
            : base(parent)
        {
            device  = AL.OpenDevice((byte *)0);
            context = AL.CreateContext(device, new int[] {});
            AL.MakeContextCurrent(context);

            AL.Listener3f(AL.POSITION, 0, 0, 0);
            AL.Listener3f(AL.VELOCITY, 0, 0, 0);
            AL.Listener3f(AL.ORIENTATION, 0, 0, -1);
        }
Beispiel #17
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 #18
0
 public QuickDraw(DisposableI parent, BufferLayoutDescI bufferLayoutDesc)
     : base(parent, bufferLayoutDesc)
 {
     try
     {
         vertexBuffer = new VertexBuffer(this, bufferLayoutDesc, BufferUsages.Write, VertexBufferTopologys.Triangle, vertices);
     }
     catch (Exception e)
     {
         Dispose();
         throw e;
     }
 }
Beispiel #19
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 #20
0
 public QuickDraw(DisposableI parent, BufferLayoutDescI bufferLayoutDesc)
     : base(parent, bufferLayoutDesc)
 {
     try
     {
         vertexBuffer = new VertexBuffer(this, bufferLayoutDesc, BufferUsages.Write, VertexBufferTopologys.Triangle, vertices);
     }
     catch (Exception e)
     {
         Dispose();
         throw e;
     }
 }
Beispiel #21
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 #22
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 #23
0
        public Audio(DisposableI parent)
            : base(parent)
        {
                        #if OSX
            component = AudioComponent.FindComponent(AudioTypeOutput.Default);
                        #else
            component = AudioComponent.FindComponent(AudioTypeOutput.Remote);
                        #endif

            if (component == null)
            {
                Debug.ThrowError("Audio", "Failed to find AudioComponent");
            }
        }
Beispiel #24
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 #25
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 #26
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();
            }
        }
 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);
         }
     });
 }
Beispiel #28
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));
        }
Beispiel #29
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 #30
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 #31
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);
         }
     });
 }
Beispiel #32
0
 public SoundWAV(DisposableI 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);
         }
     });
 }
Beispiel #33
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);
             }
         }
     });
 }
Beispiel #34
0
 public static void Init(DisposableI parent, string contentPath, string tag, ShaderVersions shaderVersion, Loader.LoadedCallbackMethod loadedCallback)
 {
     Shader = ShaderAPI.New(parent, contentPath + tag + "QuickDraw3ColorUV.rs", shaderVersion,
                            delegate(object sender, bool succeeded)
     {
         if (succeeded)
         {
             init((ShaderI)sender, loadedCallback);
         }
         else
         {
             FailedToLoad = true;
             if (loadedCallback != null)
             {
                 loadedCallback(null, false);
             }
         }
     });
 }
Beispiel #35
0
        public Video(DisposableI parent, ApplicationI application, DepthStencilFormats depthStencilFormats, bool vSync)
            : base(parent)
        {
            try
            {
                this.application     = application;
                FileTag              = "Vita_";
                currentPixelTextures = new Texture2D[4];
                currentSamplerStates = new SamplerState[4];

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

                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;
                }

                context            = new GraphicsContext(0, 0, PixelFormat.Rgba, format, MultiSampleMode.None);
                currentFrameBuffer = context.Screen;
                BackBufferSize     = new Size2(currentFrameBuffer.Width, currentFrameBuffer.Height);
                ((VitaApplication)application).Vita_SetFrameSize(currentFrameBuffer.Width, currentFrameBuffer.Height);

                currentEnableMode = EnableMode.None;
                context.Enable(currentEnableMode);
            }
            catch (Exception e)
            {
                Dispose();
                throw e;
            }
        }
Beispiel #36
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 #37
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 #38
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 #39
0
        public Video(DisposableI parent, ApplicationI application, DepthStencilFormats depthStencilFormats, bool vSync)
            : base(parent)
        {
            if (depthStencilFormats != DepthStencilFormats.Defualt)
            {
                Debug.ThrowError("Video", "Only a Defualt DepthStenicFormat may be used in XNA here");
            }

            this.application = application;
            Device           = application.GraphicsDevice;
            defualtStates();

                        #if SILVERLIGHT
            FileTag = "Silverlight_";
                        #else
            FileTag = "XNA_";
                        #endif
            BackBufferSize = application.FrameSize;

            backBuffers = Device.GetRenderTargets();
        }
Beispiel #40
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 #41
0
 public SoundWAV(DisposableI 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);
             }
         }
     });
 }
Beispiel #42
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);
             }
         }
     });
 }
Beispiel #43
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
 }
Beispiel #44
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 #45
0
        public Video(DisposableI parent, ApplicationI application, DepthStencilFormats depthStencilFormats, bool vSync)
            : base(parent)
        {
            try
            {
                this.application = application;
                FileTag = "Vita_";
                currentPixelTextures = new Texture2D[4];
                currentSamplerStates = new SamplerState[4];

                PixelFormat format = PixelFormat.None;
                switch (depthStencilFormats)
                {
                    case DepthStencilFormats.None: format = PixelFormat.None; break;
                    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;
                }

                context = new GraphicsContext(0, 0, PixelFormat.Rgba, format, MultiSampleMode.None);
                currentFrameBuffer = context.Screen;
                BackBufferSize = new Size2(currentFrameBuffer.Width, currentFrameBuffer.Height);
                ((VitaApplication)application).Vita_SetFrameSize(currentFrameBuffer.Width, currentFrameBuffer.Height);

                currentEnableMode = EnableMode.None;
                context.Enable(currentEnableMode);
            }
            catch (Exception e)
            {
                Dispose();
                throw e;
            }
        }
Beispiel #46
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 #47
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
 }
Beispiel #48
0
        protected override 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)
        {
            if (!base.init(parent, fileName, width, height, false, multiSampleType, surfaceFormat, renderTargetUsage, usage, true, loadedCallback))
            {
                return(false);
            }

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

                frameBuffer = new G.FrameBuffer();
                frameBuffer.SetColorTarget(texture, 0);
            }
            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);
        }
Beispiel #49
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 #50
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 #51
0
 public static RenderTarget New(DisposableI parent, int width, int height, MultiSampleTypes multiSampleType, SurfaceFormats surfaceFormat, DepthStencilFormats depthStencilFormat, BufferUsages usage, RenderTargetUsage renderTargetUsage, Loader.LoadedCallbackMethod loadedCallback)
 {
     return new RenderTarget(parent, width, height, multiSampleType, surfaceFormat, depthStencilFormat, usage, renderTargetUsage, loadedCallback);
 }
Beispiel #52
0
 internal BufferLayout(DisposableI parent, ShaderI shader, BufferLayoutDescI inputLayoutDesc, bool construct)
     : base(parent)
 {
     init(parent, shader, inputLayoutDesc, construct);
 }
Beispiel #53
0
 public static TouchScreen New(DisposableI parent)
 {
     return new TouchScreen(parent);
 }
Beispiel #54
0
 public static Keyboard New(DisposableI parent)
 {
     return new Keyboard(parent);
 }
Beispiel #55
0
 public Audio(DisposableI parent)
     : base(parent)
 {
 }
Beispiel #56
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;
        }
Beispiel #57
0
 public static RenderTarget New(DisposableI parent, string fileName, MultiSampleTypes multiSampleType, BufferUsages usage, RenderTargetUsage renderTargetUsage, Loader.LoadedCallbackMethod loadedCallback)
 {
     return new RenderTarget(parent, fileName, multiSampleType, usage, renderTargetUsage, loadedCallback);
 }
Beispiel #58
0
 public static Music New(DisposableI parent, string fileName)
 {
     return new Music(parent, fileName);
 }
Beispiel #59
0
 public RenderTarget(DisposableI parent, string fileName, MultiSampleTypes multiSampleType, BufferUsages usage, RenderTargetUsage renderTargetUsage, Loader.LoadedCallbackMethod loadedCallback)
     : base(parent, fileName, false, usage, loadedCallback)
 {
 }
Beispiel #60
0
 public RenderTarget(DisposableI parent, int width, int height, MultiSampleTypes multiSampleType, SurfaceFormats surfaceFormat, DepthStencilFormats depthStencilFormat, BufferUsages usage, RenderTargetUsage renderTargetUsage, Loader.LoadedCallbackMethod loadedCallback)
     : base(parent, width, height, surfaceFormat, usage, loadedCallback)
 {
     initDepthStencilFormat = depthStencilFormat;
 }