Esempio n. 1
0
        public static IDepthStencilState New(VideoTypes videoType, IDisposableResource parent, IDepthStencilStateDesc desc)
        {
            IDepthStencilState api = null;

            #if WIN32
            if (videoType == VideoTypes.D3D9) api = new D3D9.DepthStencilState(parent, desc);
            #endif

            #if WIN32 || WINRT || WP8
            if (videoType == VideoTypes.D3D11) api = new D3D11.DepthStencilState(parent, desc);
            #endif

            #if WIN32 || OSX || LINUX || iOS || ANDROID || NaCl
            if (videoType == VideoTypes.OpenGL) api = new OpenGL.DepthStencilState(parent, desc);
            #endif

            #if XNA
            if (videoType == VideoTypes.XNA) api = new XNA.DepthStencilState(parent, desc);
            #endif

            #if VITA
            if (videoType == VideoTypes.Vita) api = new Vita.DepthStencilState(parent, desc);
            #endif

            if (api == null) Debug.ThrowError("DepthStencilStateAPI", "Unsuported InputType: " + videoType);
            return api;
        }
Esempio n. 2
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);
        }
Esempio n. 3
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);
             }
         }
     });
 }
Esempio n. 4
0
 public MyJob(
     IConfigManager configManager,
     IDisposableResource diposableResource)
 {
     this.configManager     = configManager ?? throw new ArgumentNullException(nameof(configManager));
     this.diposableResource = diposableResource ?? throw new ArgumentNullException(nameof(diposableResource));
 }
Esempio n. 5
0
        public static IMouse New(InputTypes inputType, IDisposableResource parent)
        {
            IMouse api = null;

            #if WIN32
            if (inputType == InputTypes.WinForms) api = new WinForms.Mouse(parent);
            #endif

            #if WINRT
            if (inputType == InputTypes.WinRT) api = new WinRT.Mouse(parent);
            #endif

            #if OSX
            if (inputType == InputTypes.Cocoa) api = new Cocoa.Mouse(parent);
            #endif

            #if LINUX
            if (inputType == InputTypes.X11) api = new X11.Mouse(parent);
            #endif

            #if NaCl
            if (inputType == InputTypes.NaCl) api = new NaCl.Mouse(parent);
            #endif

            if (api == null) Debug.ThrowError("MouseAPI", "Unsuported InputType: " + inputType);
            return api;
        }
Esempio n. 6
0
        public static IVertexBuffer New(VideoTypes videoType, IDisposableResource parent, IBufferLayoutDesc bufferLayoutDesc, BufferUsages usage, VertexBufferTopologys topology, float[] vertices, int[] indices)
        {
            IVertexBuffer api = null;

            #if WIN32
            if (videoType == VideoTypes.D3D9) api = new D3D9.VertexBuffer(parent, bufferLayoutDesc, usage, topology, vertices, indices);
            #endif

            #if WIN32 || WINRT || WP8
            if (videoType == VideoTypes.D3D11) api = new D3D11.VertexBuffer(parent, bufferLayoutDesc, usage, topology, vertices, indices);
            #endif

            #if WIN32 || OSX || LINUX || iOS || ANDROID || NaCl
            if (videoType == VideoTypes.OpenGL) api = new OpenGL.VertexBuffer(parent, bufferLayoutDesc, usage, topology, vertices, indices);
            #endif

            #if XNA
            if (videoType == VideoTypes.XNA) api = new XNA.VertexBuffer(parent, bufferLayoutDesc, usage, topology, vertices, indices);
            #endif

            #if VITA
            if (videoType == VideoTypes.Vita) api = new Vita.VertexBuffer(parent, bufferLayoutDesc, usage, topology, vertices, indices);
            #endif

            if (api == null) Debug.ThrowError("VertexBufferAPI", "Unsuported InputType: " + videoType);
            return api;
        }
Esempio n. 7
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;
        }
Esempio n. 8
0
        private void init(IDisposableResource parent, IBufferLayoutDesc bufferLayoutDesc, BufferUsages usage, VertexBufferTopologys topology, float[] vertices, int[] indices)
        {
            try
            {
                var video = parent.FindParentOrSelfWithException <Video>();

                this.topology = topology;
                REIGN_D3DPRIMITIVETYPE topologyType = REIGN_D3DPRIMITIVETYPE.TRIANGLELIST;
                switch (topology)
                {
                case VertexBufferTopologys.Triangle: topologyType = REIGN_D3DPRIMITIVETYPE.TRIANGLELIST; break;

                case VertexBufferTopologys.Line: topologyType = REIGN_D3DPRIMITIVETYPE.LINELIST; break;

                case VertexBufferTopologys.Point: topologyType = REIGN_D3DPRIMITIVETYPE.POINTLIST; break;
                }

                com = new VertexBufferCom(video.com, topologyType);
                var error = com.Init(vertices, REIGN_D3DUSAGE.WRITEONLY, vertexCount, vertexByteSize);
                if (error == VertexBufferErrors.VertexBuffer)
                {
                    Debug.ThrowError("VertexBuffer", "Failed to create VertexBuffer");
                }

                if (indices != null && indices.Length != 0)
                {
                    indexBuffer = new IndexBuffer(this, usage, indices);
                }
            }
            catch (Exception e)
            {
                Dispose();
                throw e;
            }
        }
Esempio n. 9
0
        public BlendState(IDisposableResource parent, IBlendStateDesc desc)
            : base(parent)
        {
            var video = parent.FindParentOrSelfWithException <Video>();

            com = new BlendStateCom(video.com, ((BlendStateDesc)desc).com);
        }
Esempio n. 10
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);
				}
			});
		}
Esempio n. 11
0
        public static IViewPort New(VideoTypes videoType, IDisposableResource parent, Point2 location, Size2 size)
        {
            IViewPort api = null;

            #if WIN32
            if (videoType == VideoTypes.D3D9) api = new D3D9.ViewPort(parent, location, size);
            #endif

            #if WIN32 || WINRT || WP8
            if (videoType == VideoTypes.D3D11) api = new D3D11.ViewPort(parent, location, size);
            #endif

            #if WIN32 || OSX || LINUX || iOS || ANDROID || NaCl
            if (videoType == VideoTypes.OpenGL) api = new OpenGL.ViewPort(parent, location, size);
            #endif

            #if XNA
            if (videoType == VideoTypes.XNA) api = new XNA.ViewPort(parent, location, size);
            #endif

            #if VITA
            if (videoType == VideoTypes.Vita) api = new Vita.ViewPort(parent, location, size);
            #endif

            if (api == null) Debug.ThrowError("ViewPortAPI", "Unsuported InputType: " + videoType);
            return api;
        }
Esempio n. 12
0
        public static IQuickDraw New(VideoTypes videoType, IDisposableResource parent, IBufferLayoutDesc desc)
        {
            IQuickDraw api = null;

            #if WIN32
            if (videoType == VideoTypes.D3D9) api = new D3D9.QuickDraw(parent, desc);
            #endif

            #if WIN32 || WINRT || WP8
            if (videoType == VideoTypes.D3D11) api = new D3D11.QuickDraw(parent, desc);
            #endif

            #if WIN32 || OSX || LINUX || iOS || ANDROID || NaCl
            if (videoType == VideoTypes.OpenGL) api = new OpenGL.QuickDraw(parent, desc);
            #endif

            #if XNA
            if (videoType == VideoTypes.XNA) api = new XNA.QuickDraw(parent, desc);
            #endif

            #if VITA
            if (videoType == VideoTypes.Vita) api = new Vita.QuickDraw(parent, desc);
            #endif

            if (api == null) Debug.ThrowError("QuickDrawAPI", "Unsuported InputType: " + videoType);
            return api;
        }
Esempio n. 13
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;
        }
Esempio n. 14
0
        public DepthStencilState(IDisposableResource parent, IDepthStencilStateDesc desc)
            : base(parent)
        {
            var video = parent.FindParentOrSelfWithException <Video>();

            com = new DepthStencilStateCom(video.com, ((DepthStencilStateDesc)desc).com);
        }
Esempio n. 15
0
 public RootDisposableResource(IDisposableResource disposable)
     : base(disposable)
 {
                 #if XNA && !SILVERLIGHT
     var parent = disposable.FindParentOrSelfWithException <RootDisposableResource>();
     init(parent.Content);
                 #endif
 }
Esempio n. 16
0
 public RenderTarget(IDisposableResource parent, Image image, int width, int height, bool generateMipmaps, MultiSampleTypes multiSampleType, SurfaceFormats surfaceFormat, DepthStencilFormats depthStencilFormat, RenderTargetUsage renderTargetUsage, BufferUsages usage, Loader.LoadedCallbackMethod loadedCallback)
     : base(parent, image, width, height, generateMipmaps, multiSampleType, surfaceFormat, renderTargetUsage, usage, loadedCallback)
 {
     if (initSuccess)
     {
         initDepthStencil(width, height, depthStencilFormat);
     }
 }
Esempio n. 17
0
 protected IVertexBuffer(IDisposableResource parent, IBufferLayoutDesc bufferLayoutDesc, BufferUsages usage, float[] vertices)
     : base(parent)
 {
     this.usage = usage;
     vertexByteSize = bufferLayoutDesc.ByteSize;
     vertexFloatArraySize = bufferLayoutDesc.FloatCount;
     vertexCount = vertices.Length / vertexFloatArraySize;
 }
 public RootDisposableResource(IDisposableResource disposable)
     : base(disposable)
 {
     #if XNA && !SILVERLIGHT
     var parent = disposable.FindParentOrSelfWithException<RootDisposableResource>();
     init(parent.Content);
     #endif
 }
Esempio n. 19
0
 protected IVertexBuffer(IDisposableResource parent, IBufferLayoutDesc bufferLayoutDesc, BufferUsages usage, float[] vertices)
     : base(parent)
 {
     this.usage           = usage;
     vertexByteSize       = bufferLayoutDesc.ByteSize;
     vertexFloatArraySize = bufferLayoutDesc.FloatCount;
     vertexCount          = vertices.Length / vertexFloatArraySize;
 }
Esempio n. 20
0
        public DepthStencil(IDisposableResource parent, int width, int height, DepthStencilFormats depthStencilFormats)
            : base(parent)
        {
            try
            {
                var video = parent.FindParentOrSelfWithException <Video>();
                Size  = new Size2(width, height);
                SizeF = Size.ToVector2();

                int depthBit = 16, stencilBit = 0;
                switch (depthStencilFormats)
                {
                case DepthStencilFormats.Defualt:
                    depthBit   = 24;
                    stencilBit = 0;
                    break;

                case DepthStencilFormats.Depth24Stencil8:
                    depthBit   = 24;
                    stencilBit = 8;
                    break;

                case DepthStencilFormats.Depth16:
                    depthBit   = 16;
                    stencilBit = 0;
                    break;

                case DepthStencilFormats.Depth24:
                    depthBit   = 24;
                    stencilBit = 0;
                    break;

                case DepthStencilFormats.Depth32:
                    depthBit   = 32;
                    stencilBit = 0;
                    break;

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

                com = new DepthStencilCom();
                var error = com.Init(video.com, width, height, depthBit, stencilBit);

                switch (error)
                {
                case DepthStencilErrors.Textrue: Debug.ThrowError("DepthStencil", "Failed to create Texture2D"); break;

                case DepthStencilErrors.DepthStencilView: Debug.ThrowError("DepthStencil", "Failed to create DepthStencilView"); break;
                }
            }
            catch (Exception e)
            {
                Dispose();
                throw e;
            }
        }
Esempio n. 21
0
        public DepthStencil(IDisposableResource parent, int width, int height, DepthStencilFormats depthStencilFormats)
            : base(parent)
        {
            try
            {
                var video = parent.FindParentOrSelfWithException<Video>();
                Size = new Size2(width, height);
                SizeF = Size.ToVector2();

                int depthBit = 16, stencilBit = 0;
                switch (depthStencilFormats)
                {
                    case DepthStencilFormats.Defualt:
                        depthBit = 24;
                        stencilBit = 0;
                        break;

                    case DepthStencilFormats.Depth24Stencil8:
                        depthBit = 24;
                        stencilBit = 8;
                        break;

                    case DepthStencilFormats.Depth16:
                        depthBit = 16;
                        stencilBit = 0;
                        break;

                    case DepthStencilFormats.Depth24:
                        depthBit = 24;
                        stencilBit = 0;
                        break;

                    case DepthStencilFormats.Depth32:
                        depthBit = 32;
                        stencilBit = 0;
                        break;

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

                com = new DepthStencilCom();
                var error = com.Init(video.com, width, height, depthBit, stencilBit);

                switch (error)
                {
                    case DepthStencilErrors.Textrue: Debug.ThrowError("DepthStencil", "Failed to create Texture2D"); break;
                    case DepthStencilErrors.DepthStencilView: Debug.ThrowError("DepthStencil", "Failed to create DepthStencilView"); break;
                }
            }
            catch (Exception e)
            {
                Dispose();
                throw e;
            }
        }
Esempio n. 22
0
 protected IIndexBuffer(IDisposableResource parent, BufferUsages usage, int[] indices)
     : base(parent)
 {
     this.usage    = usage;
     indexByteSize = sizeof(short);
     indexCount    = indices.Length;
     _32BitIndices = indexCount > short.MaxValue;
     indexByteSize = _32BitIndices ? sizeof(int) : sizeof(short);
 }
Esempio n. 23
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);
         }
 }
Esempio n. 24
0
 protected IIndexBuffer(IDisposableResource parent, BufferUsages usage, int[] indices)
     : base(parent)
 {
     this.usage = usage;
     indexByteSize = sizeof(short);
     indexCount = indices.Length;
     _32BitIndices = indexCount > short.MaxValue;
     indexByteSize = _32BitIndices ? sizeof(int) : sizeof(short);
 }
Esempio n. 25
0
        public static void ThrowIfDisposed(this IDisposableResource resource)
        {
            Contract.Requires(resource != null);

            if (resource.IsDisposed)
            {
                throw new ObjectDisposedException(resource.ToString(), "An attempt was made to use a disposed object.");
            }
        }
Esempio n. 26
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);
     }
 }
Esempio n. 27
0
		public Video(IDisposableResource parent, IApplication application, DepthStencilFormats depthStencilFormats, bool vSync)
		: base(parent)
		{
			#if WINRT
			var xamlApp = application as XAMLApplication;
			init(parent, application, depthStencilFormats, vSync, xamlApp != null ? ((XAMLApplication)application).SwapChainPanel : null);
			#else
			init(parent, application, depthStencilFormats, vSync);
			#endif
		}
Esempio n. 28
0
 public Video(IDisposableResource parent, IApplication application, DepthStencilFormats depthStencilFormats, bool vSync)
     : base(parent)
 {
                 #if WINRT
     var xamlApp = application as XAMLApplication;
     init(parent, application, depthStencilFormats, vSync, xamlApp != null ? ((XAMLApplication)application).SwapChainPanel : null);
                 #else
     init(parent, application, depthStencilFormats, vSync);
                 #endif
 }
Esempio n. 29
0
        public Mouse(IDisposableResource parent)
            : base(parent)
        {
            input = parent.FindParentOrSelfWithException<Input>();
            input.UpdateEventCallback += UpdateEvent;
            input.UpdateCallback += Update;

            Left = new PositionButton();
            Middle = new PositionButton();
            Right = new PositionButton();
        }
Esempio n. 30
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);
        }
Esempio n. 31
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);
        }
Esempio n. 32
0
        public Mouse(IDisposableResource parent)
            : base(parent)
        {
            input = parent.FindParentOrSelfWithException <Input>();
            input.UpdateEventCallback += UpdateEvent;
            input.UpdateCallback      += Update;

            Left   = new PositionButton();
            Middle = new PositionButton();
            Right  = new PositionButton();
        }
Esempio n. 33
0
        public static IGamePad New(InputTypes inputType, IDisposableResource parent)
        {
            IGamePad api = null;

            #if XNA
            if (inputType == InputTypes.XNA) api = new XNA.GamePad(disposable);
            #endif

            if (api == null) Debug.ThrowError("GamePadAPI", "Unsuported InputType: " + inputType);
            return api;
        }
Esempio n. 34
0
 public QuickDraw(IDisposableResource parent, IBufferLayoutDesc bufferLayoutDesc)
     : base(parent, bufferLayoutDesc)
 {
     try
     {
         vertexBuffer = new VertexBuffer(this, bufferLayoutDesc, BufferUsages.Write, VertexBufferTopologys.Triangle, vertices);
     }
     catch (Exception e)
     {
         Dispose();
         throw e;
     }
 }
Esempio n. 35
0
 public QuickDraw(IDisposableResource parent, IBufferLayoutDesc bufferLayoutDesc)
     : base(parent, bufferLayoutDesc)
 {
     try
     {
         vertexBuffer = new VertexBuffer(this, bufferLayoutDesc, BufferUsages.Write, VertexBufferTopologys.Triangle, vertices);
     }
     catch (Exception e)
     {
         Dispose();
         throw e;
     }
 }
Esempio n. 36
0
        public static IMusic New(AudioTypes audioType, IDisposableResource parent, string filename)
        {
            IMusic api = null;

            #if XNA
            if (audioType == AudioTypes.XNA) api = new XNA.Music(parent, filename);
            #endif

            if (audioType == AudioTypes.Dumby) api = new Dumby.Music(parent, filename);

            if (api == null) Debug.ThrowError("MusicAPI", "Unsuported InputType: " + audioType);
            return api;
        }
Esempio n. 37
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, bool lockable, Loader.LoadedCallbackMethod loadedCallback)
        {
            initSuccess = base.init(parent, image, width, height, generateMipmaps, multiSampleType, surfaceFormat, renderTargetUsage, usage, true, lockable, 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, com, width, height, 0, video.surfaceFormat(surfaceFormat), usage == BufferUsages.Read, lockable);

                switch (error)
                {
                case RenderTargetError.RenderTarget: Debug.ThrowError("RenderTarget", "Failed to create RenderTarget"); 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);
        }
Esempio n. 38
0
        public Keyboard(IDisposableResource 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();
            }
        }
Esempio n. 39
0
        public Keyboard(IDisposableResource 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();
            }
        }
Esempio n. 40
0
        public unsafe IndexBuffer(IDisposableResource parent, BufferUsages bufferUsage, int[] indices)
            : base(parent, bufferUsage, indices)
        {
            try
            {
                video = parent.FindParentOrSelfWithException <Video>();

                uint vPtr = 0;
                GL.GenBuffers(1, &vPtr);
                indexBuffer = vPtr;
                if (indexBuffer == 0)
                {
                    Debug.ThrowError("IndexBuffer", "Failed to create IndexBuffer");
                }

                GL.BindBuffer(GL.ELEMENT_ARRAY_BUFFER, indexBuffer);
                if (_32BitIndices)
                {
                    fixed(int *indicesPtr = indices)
                    {
                        var bufferSize = new IntPtr(indexByteSize * indexCount);

                        GL.BufferData(GL.ELEMENT_ARRAY_BUFFER, bufferSize, indicesPtr, GL.STATIC_DRAW);
                    }
                }
                else
                {
                    var indices16Bit = new short[indices.Length];
                    for (int i = 0; i != indices.Length; ++i)
                    {
                        indices16Bit[i] = (short)indices[i];
                    }

                    fixed(short *indicesPtr = indices16Bit)
                    {
                        var bufferSize = new IntPtr(indexByteSize * indexCount);

                        GL.BufferData(GL.ELEMENT_ARRAY_BUFFER, bufferSize, indicesPtr, GL.STATIC_DRAW);
                    }
                }

                Video.checkForError();
            }
            catch (Exception e)
            {
                Dispose();
                throw e;
            }
        }
Esempio n. 41
0
        public static ITouchScreen New(InputTypes inputType, IDisposableResource parent)
        {
            ITouchScreen api = null;

            #if iOS
            if (inputType == InputTypes.Cocoa) TouchScreenAPI.Init(Reign.Input.Cocoa.TouchScreen.New);
            #endif

            #if ANDROID
            if (inputType == InputTypes.Android) TouchScreenAPI.Init(Reign.Input.Android.TouchScreen.New);
            #endif

            if (api == null) Debug.ThrowError("TouchScreenAPI", "Unsuported InputType: " + inputType);
            return api;
        }
Esempio n. 42
0
        public BufferLayout(IDisposableResource parent, IShader shader, IBufferLayoutDesc desc)
            : base(parent)
        {
            video = parent.FindParentOrSelfWithException<Video>();
            this.shader = (Shader)shader;
            enabledStreamIndices = new bool[2];

            streamBytesSizes = desc.StreamBytesSizes;
            layout = ((BufferLayoutDesc)desc).desc;
            attribLocations = new int[layout.Length];
            for (int i = 0; i != layout.Length; ++i)
            {
                attribLocations[i] = GL.GetAttribLocation(this.shader.program, layout[i].Name);
                Video.checkForError();
            }
        }
Esempio n. 43
0
        public BufferLayout(IDisposableResource parent, IShader shader, IBufferLayoutDesc desc)
            : base(parent)
        {
            video                = parent.FindParentOrSelfWithException <Video>();
            this.shader          = (Shader)shader;
            enabledStreamIndices = new bool[2];

            streamBytesSizes = desc.StreamBytesSizes;
            layout           = ((BufferLayoutDesc)desc).desc;
            attribLocations  = new int[layout.Length];
            for (int i = 0; i != layout.Length; ++i)
            {
                attribLocations[i] = GL.GetAttribLocation(this.shader.program, layout[i].Name);
                Video.checkForError();
            }
        }
Esempio n. 44
0
        public MyJob(
            IConfigManager configManager,
            IDisposableResource diposableResource)
        {
            if (configManager == null)
            {
                throw new ArgumentNullException("configManager");
            }

            if (diposableResource == null)
            {
                throw new ArgumentNullException("diposableResource");
            }

            this.configManager = configManager;
            this.diposableResource = diposableResource;
        }
Esempio n. 45
0
        public MyJob(
            IConfigManager configManager,
            IDisposableResource diposableResource)
        {
            if (configManager == null)
            {
                throw new ArgumentNullException("configManager");
            }

            if (diposableResource == null)
            {
                throw new ArgumentNullException("diposableResource");
            }

            this.configManager     = configManager;
            this.diposableResource = diposableResource;
        }
Esempio n. 46
0
        public BufferLayout(IDisposableResource parent, IShader shader, IBufferLayoutDesc desc)
            : base(parent)
        {
            try
            {
                var video = parent.FindParentOrSelfWithException<Video>();
                com = new BufferLayoutCom();
                var error = com.Init(video.com, ((Shader)shader).vertex.com, ((BufferLayoutDesc)desc).com);

                if (error == BufferLayoutErrors.InputLayout) Debug.ThrowError("BufferLayout", "Failed to create InputLayout");
            }
            catch (Exception e)
            {
                Dispose();
                throw e;
            }
        }
Esempio n. 47
0
        public static IGamePad New(InputTypes inputType, IDisposableResource parent)
        {
            IGamePad api = null;

                        #if XNA
            if (inputType == InputTypes.XNA)
            {
                api = new XNA.GamePad(disposable);
            }
                        #endif

            if (api == null)
            {
                Debug.ThrowError("GamePadAPI", "Unsuported InputType: " + inputType);
            }
            return(api);
        }
Esempio n. 48
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);
        }
Esempio n. 49
0
        public ShaderModel(IDisposableResource parent, string code, ShaderVersions shaderVersion, ShaderTypes shaderType)
            : base(parent)
        {
            try
            {
                var video = parent.FindParentOrSelfWithException <Video>();

                string shaderLvl = "";
                switch (shaderVersion)
                {
                case ShaderVersions.HLSL_2_0: shaderLvl = "_2_0"; break;

                case ShaderVersions.HLSL_2_a: shaderLvl = "_2_a"; break;

                case ShaderVersions.HLSL_3_0: shaderLvl = "_3_0"; break;

                default: Debug.ThrowError("ShaderModel", "Unsuported ShaderVersion: " + shaderVersion); break;
                }
                string shaderVersionType = shaderType.ToString().ToLower() + shaderLvl;

                com = new ShaderModelCom();
                var    codePtr = Marshal.StringToHGlobalAnsi(code);
                var    shaderVersionTypePtr = Marshal.StringToHGlobalAnsi(shaderVersionType);
                string errorText;
                var    error = com.Init(video.com, codePtr, code.Length, shaderVersionTypePtr, out errorText);
                if (codePtr != IntPtr.Zero)
                {
                    Marshal.FreeHGlobal(codePtr);
                }
                if (shaderVersionTypePtr != IntPtr.Zero)
                {
                    Marshal.FreeHGlobal(shaderVersionTypePtr);
                }

                switch (error)
                {
                case ShaderModelErrors.Compile: Debug.ThrowError("ShaderModel", string.Format("Failed to compile {0} shader: Errors: {1}", shaderType == ShaderTypes.VS ? "vs" : "ps", errorText)); break;
                }
            }
            catch (Exception e)
            {
                Dispose();
                throw e;
            }
        }
Esempio n. 50
0
        public static IDepthStencilState New(VideoTypes videoType, IDisposableResource parent, IDepthStencilStateDesc desc)
        {
            IDepthStencilState api = null;

                        #if WIN32
            if (videoType == VideoTypes.D3D9)
            {
                api = new D3D9.DepthStencilState(parent, desc);
            }
                        #endif

                        #if WIN32 || WINRT || WP8
            if (videoType == VideoTypes.D3D11)
            {
                api = new D3D11.DepthStencilState(parent, desc);
            }
                        #endif

                        #if WIN32 || OSX || LINUX || iOS || ANDROID || NaCl
            if (videoType == VideoTypes.OpenGL)
            {
                api = new OpenGL.DepthStencilState(parent, desc);
            }
                        #endif

                        #if XNA
            if (videoType == VideoTypes.XNA)
            {
                api = new XNA.DepthStencilState(parent, desc);
            }
                        #endif

                        #if VITA
            if (videoType == VideoTypes.Vita)
            {
                api = new Vita.DepthStencilState(parent, desc);
            }
                        #endif

            if (api == null)
            {
                Debug.ThrowError("DepthStencilStateAPI", "Unsuported InputType: " + videoType);
            }
            return(api);
        }
Esempio n. 51
0
        public static IViewPort New(VideoTypes videoType, IDisposableResource parent, Point2 location, Size2 size)
        {
            IViewPort api = null;

                        #if WIN32
            if (videoType == VideoTypes.D3D9)
            {
                api = new D3D9.ViewPort(parent, location, size);
            }
                        #endif

                        #if WIN32 || WINRT || WP8
            if (videoType == VideoTypes.D3D11)
            {
                api = new D3D11.ViewPort(parent, location, size);
            }
                        #endif

                        #if WIN32 || OSX || LINUX || iOS || ANDROID || NaCl
            if (videoType == VideoTypes.OpenGL)
            {
                api = new OpenGL.ViewPort(parent, location, size);
            }
                        #endif

                        #if XNA
            if (videoType == VideoTypes.XNA)
            {
                api = new XNA.ViewPort(parent, location, size);
            }
                        #endif

                        #if VITA
            if (videoType == VideoTypes.Vita)
            {
                api = new Vita.ViewPort(parent, location, size);
            }
                        #endif

            if (api == null)
            {
                Debug.ThrowError("ViewPortAPI", "Unsuported InputType: " + videoType);
            }
            return(api);
        }
Esempio n. 52
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);
        }
Esempio n. 53
0
        public static IMouse New(InputTypes inputType, IDisposableResource parent)
        {
            IMouse api = null;

                        #if WIN32
            if (inputType == InputTypes.WinForms)
            {
                api = new WinForms.Mouse(parent);
            }
                        #endif

                        #if WINRT
            if (inputType == InputTypes.WinRT)
            {
                api = new WinRT.Mouse(parent);
            }
                        #endif

                        #if OSX
            if (inputType == InputTypes.Cocoa)
            {
                api = new Cocoa.Mouse(parent);
            }
                        #endif

                        #if LINUX
            if (inputType == InputTypes.X11)
            {
                api = new X11.Mouse(parent);
            }
                        #endif

                        #if NaCl
            if (inputType == InputTypes.NaCl)
            {
                api = new NaCl.Mouse(parent);
            }
                        #endif

            if (api == null)
            {
                Debug.ThrowError("MouseAPI", "Unsuported InputType: " + inputType);
            }
            return(api);
        }
Esempio n. 54
0
        public static IQuickDraw New(VideoTypes videoType, IDisposableResource parent, IBufferLayoutDesc desc)
        {
            IQuickDraw api = null;

                        #if WIN32
            if (videoType == VideoTypes.D3D9)
            {
                api = new D3D9.QuickDraw(parent, desc);
            }
                        #endif

                        #if WIN32 || WINRT || WP8
            if (videoType == VideoTypes.D3D11)
            {
                api = new D3D11.QuickDraw(parent, desc);
            }
                        #endif

                        #if WIN32 || OSX || LINUX || iOS || ANDROID || NaCl
            if (videoType == VideoTypes.OpenGL)
            {
                api = new OpenGL.QuickDraw(parent, desc);
            }
                        #endif

                        #if XNA
            if (videoType == VideoTypes.XNA)
            {
                api = new XNA.QuickDraw(parent, desc);
            }
                        #endif

                        #if VITA
            if (videoType == VideoTypes.Vita)
            {
                api = new Vita.QuickDraw(parent, desc);
            }
                        #endif

            if (api == null)
            {
                Debug.ThrowError("QuickDrawAPI", "Unsuported InputType: " + videoType);
            }
            return(api);
        }
Esempio n. 55
0
        public static IVertexBuffer New(VideoTypes videoType, IDisposableResource parent, IBufferLayoutDesc bufferLayoutDesc, BufferUsages usage, VertexBufferTopologys topology, float[] vertices, int[] indices)
        {
            IVertexBuffer api = null;

                        #if WIN32
            if (videoType == VideoTypes.D3D9)
            {
                api = new D3D9.VertexBuffer(parent, bufferLayoutDesc, usage, topology, vertices, indices);
            }
                        #endif

                        #if WIN32 || WINRT || WP8
            if (videoType == VideoTypes.D3D11)
            {
                api = new D3D11.VertexBuffer(parent, bufferLayoutDesc, usage, topology, vertices, indices);
            }
                        #endif

                        #if WIN32 || OSX || LINUX || iOS || ANDROID || NaCl
            if (videoType == VideoTypes.OpenGL)
            {
                api = new OpenGL.VertexBuffer(parent, bufferLayoutDesc, usage, topology, vertices, indices);
            }
                        #endif

                        #if XNA
            if (videoType == VideoTypes.XNA)
            {
                api = new XNA.VertexBuffer(parent, bufferLayoutDesc, usage, topology, vertices, indices);
            }
                        #endif

                        #if VITA
            if (videoType == VideoTypes.Vita)
            {
                api = new Vita.VertexBuffer(parent, bufferLayoutDesc, usage, topology, vertices, indices);
            }
                        #endif

            if (api == null)
            {
                Debug.ThrowError("VertexBufferAPI", "Unsuported InputType: " + videoType);
            }
            return(api);
        }
Esempio n. 56
0
        public DepthStencilState(IDisposableResource parent, IDepthStencilStateDesc desc)
            : base(parent)
        {
            try
            {
                var video = parent.FindParentOrSelfWithException<Video>();

                com = new DepthStencilStateCom();
                var error = com.Init(video.com, ((DepthStencilStateDesc)desc).com);

                if (error == DepthStencilStateError.DepthStencil) Debug.ThrowError("DepthStencil", "Failed to create DepthStencil");
            }
            catch (Exception e)
            {
                Dispose();
                throw e;
            }
        }
Esempio n. 57
0
 public IndexBuffer(IDisposableResource parent, BufferUsages usage, int[] indices)
     : base(parent, usage, indices)
 {
     try
     {
         var video = parent.FindParentOrSelfWithException<Video>();
         com = new IndexBufferCom(video.com);
         var bufferUsage = (usage == BufferUsages.Write) ? REIGN_D3D11_USAGE.DYNAMIC : REIGN_D3D11_USAGE.DEFAULT;
         var cpuUsage = (usage == BufferUsages.Write) ? REIGN_D3D11_CPU_ACCESS_FLAG.WRITE : (REIGN_D3D11_CPU_ACCESS_FLAG)0;
         var error = com.Init(indices, indexCount, indexByteSize, bufferUsage, cpuUsage, _32BitIndices);
         if (error == IndexBufferErrors.Buffer) Debug.ThrowError("IndexBuffer", "Failed to create Buffer");
     }
     catch (Exception e)
     {
         Dispose();
         throw e;
     }
 }
Esempio n. 58
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);
         }
     });
 }
Esempio n. 59
0
 public Font(IDisposableResource parent, IShader shader, ITexture2D 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);
         }
     });
 }
Esempio n. 60
0
        public BlendState(IDisposableResource parent, IBlendStateDesc desc)
            : base(parent)
        {
            try
            {
                var video = parent.FindParentOrSelfWithException<Video>();

                com = new BlendStateCom();
                var error = com.Init(video.com, ((BlendStateDesc)desc).com);

                if (error == BlendStateError.BlendState) Debug.ThrowError("BlendState", "Failed to create BlendState");
            }
            catch (Exception e)
            {
                Dispose();
                throw e;
            }
        }