예제 #1
0
        /// <summary>
        /// Deserializes the object and populates it from the input.
        /// </summary>
        /// <param name="input">Savable input</param>
        /// <exception cref="Tesla.Core.TeslaException">Thrown if creating the underlying implementation fails or the render
        /// system is not set.</exception>
        public void Read(ISavableReader input)
        {
            IRenderSystemProvider renderSystem = input.RenderSystem;

            if (renderSystem == null)
            {
                Dispose();
                throw new TeslaException("Render system provider not set, cannot create graphics resource implementation.");
            }

            base.RenderSystem = renderSystem;
            String            name    = input.ReadString();
            VertexDeclaration decl    = input.ReadSavable <VertexDeclaration>();
            int           vertexCount = input.ReadInt();
            ResourceUsage usage       = input.ReadEnum <ResourceUsage>();

            byte[] byteBuffer = input.ReadByteArray();

            try {
                _impl      = renderSystem.CreateVertexBufferImplementation(decl, vertexCount, usage);
                _impl.Name = name;
                SetData <byte>(byteBuffer);
            } catch (Exception e) {
                Dispose();
                throw new TeslaException("Error creating underlying implementation, see inner exception for details.", e);
            }
        }
예제 #2
0
        /// <summary>
        /// Initializes the engine to use the provided render system provider.
        /// </summary>
        /// <param name="renderSystem">Render system to use</param>
        /// <exception cref="Tesla.Core.TeslaException">Thrown if the render system is null.</exception>
        public static void Initialize(IRenderSystemProvider renderSystem)
        {
            if (renderSystem == null)
            {
                throw new TeslaException("Render system cannot be null.");
            }

            //If re-initing, destroy default render states.
            if (_providers.GetService(_renderSystemType) != null)
            {
                DestroyDefaultRenderStates();
                _providers.RemoveService(_renderSystemType);

                //Add render system to service map and create default render states.
                _providers.AddService(_renderSystemType, renderSystem);
                CreateDefaultRenderStates();

                //Clear the device to the default states.
                renderSystem.Renderer.ClearRenderStates();

                OnReinitialized();
                return;
            }

            //Add render system to service map and create default render states.
            _providers.AddService(_renderSystemType, renderSystem);
            CreateDefaultRenderStates();

            //Clear the device to the default states.
            renderSystem.Renderer.ClearRenderStates();
            OnInitialized();
        }
예제 #3
0
        public SpriteBatch()
        {
            IRenderSystemProvider renderSystem = Engine.Services.GetService <IRenderSystemProvider>();

            _renderer = renderSystem.Renderer;

            _indexBuffer = new IndexBuffer(IndexFormat.SixteenBits, MaxBatchSize * 6, ResourceUsage.Static);

            _vertices     = new VertexPositionColorTexture[MaxBatchSize * 4];
            _vertexBuffer = new VertexBuffer(VertexPositionColorTexture.VertexDeclaration, MaxBatchSize * 4, ResourceUsage.Dynamic);
            _spriteVbPos  = 0;

            _spriteEffect = renderSystem.DefaultContent.Load <Effect>("SpriteEffect.tebo");
            _matrixParam  = _spriteEffect.Parameters["SpriteTransform"];

            _textureComparer     = new TextureComparer(this);
            _frontToBackComparer = new OrthoComparer(this, true);
            _backToFrontComparer = new OrthoComparer(this, false);

            _spriteQueue      = new Sprite[MaxBatchSize];
            _spriteQueueCount = 0;
            _inBeginEnd       = false;
            _sortMode         = SpriteSortMode.Deferred;

            CreateIndexData();
        }
예제 #4
0
        /// <summary>
        /// Deserializes the object and populates it from the input.
        /// </summary>
        /// <param name="input">Savable input</param>
        /// <exception cref="Tesla.Core.TeslaException">Thrown if creating the underlying state implementation fails or the render
        /// system is not set.</exception>
        public override void Read(ISavableReader input)
        {
            IRenderSystemProvider renderSystem = input.RenderSystem;

            if (renderSystem == null)
            {
                Dispose();
                throw new TeslaException("Render system provider not set, cannot create graphics resource implementation.");
            }

            base.RenderSystem = renderSystem;
            try {
                _impl = renderSystem.CreateRasterizerStateImplementation();
            } catch (Exception e) {
                Dispose();
                throw new TeslaException("Error creating underlying implementation, see inner exception for details.", e);
            }

            _impl.Cull                       = input.ReadEnum <CullMode>();
            _impl.VertexWinding              = input.ReadEnum <VertexWinding>();
            _impl.Fill                       = input.ReadEnum <FillMode>();
            _impl.DepthBias                  = input.ReadInt();
            _impl.SlopeScaledDepthBias       = input.ReadSingle();
            _impl.EnableMultiSampleAntiAlias = input.ReadBoolean();
            _impl.EnableScissorTest          = input.ReadBoolean();
        }
예제 #5
0
        /// <summary>
        /// Creates a new instance of <see cref="SwapChain"/>.
        /// </summary>
        /// <param name="renderSystem">Render system used to create the underlying implementation.</param>
        /// <param name="windowHandle">The handle to the window the swap chain is to bounded to. This is the window that the swap chain
        /// presents to.</param>
        /// <exception cref="System.ArgumentNullException">Thrown if the render system is null.</exception>
        /// <param name="presentParams">The presentation parameters defining how the swap chain should be setup..</param>
        /// <exception cref="System.ArgumentException">Thrown if the presentation parameters are invalid, e.g. bad format or multi sample values.</exception>
        /// <exception cref="Tesla.Core.TeslaException">Thrown if the implementation failed to be created.</exception>
        public SwapChain(IRenderSystemProvider renderSystem, IntPtr windowHandle, PresentationParameters presentParams)
        {
            if (renderSystem == null)
            {
                Dispose();
                throw new ArgumentNullException("renderSystem", "Render system cannot be null.");
            }

            base.RenderSystem = renderSystem;

            //Check format compatibility
            bool goodFormat = renderSystem.DefaultAdapter.QueryBackBufferFormat(presentParams.BackBufferFormat, presentParams.DepthStencilFormat, presentParams.MultiSampleCount);
            int  sampleQual = renderSystem.DefaultAdapter.QueryMultiSampleQualityLevels(presentParams.BackBufferFormat, presentParams.MultiSampleQuality);
            int  levels     = presentParams.MultiSampleQuality;

            if (goodFormat && (levels >= 0 && levels <= sampleQual))
            {
                try {
                    _impl = renderSystem.CreateSwapChainImplementation(windowHandle, presentParams);
                } catch (Exception e) {
                    Dispose();
                    throw new TeslaException("Error creating underlying implementation, see inner exception for details.", e);
                }
            }
            else
            {
                Dispose();
                throw new ArgumentException("Invalid presentation parameters.");
            }
        }
예제 #6
0
        /// <summary>
        /// Deserializes the object and populates it from the input.
        /// </summary>
        /// <param name="input">Savable input</param>
        /// <exception cref="Tesla.Core.TeslaException">Thrown if creating the underlying implementation fails or the render
        /// system is not set.</exception>
        public override void Read(ISavableReader input)
        {
            IRenderSystemProvider renderSystem = input.RenderSystem;

            if (renderSystem == null)
            {
                Dispose();
                throw new TeslaException("Render system provider not set, cannot create graphics resource implementation.");
            }

            base.RenderSystem = renderSystem;

            String        name     = input.ReadString();
            SurfaceFormat format   = input.ReadEnum <SurfaceFormat>();
            int           width    = input.ReadInt();
            int           height   = input.ReadInt();
            int           mipCount = input.ReadInt();

            try {
                _impl = renderSystem.CreateTexture2DImplementation(width, height, mipCount > 1, format, null);
                for (int i = 0; i < mipCount; i++)
                {
                    byte[] byteBuffer = input.ReadByteArray();
                    _impl.SetData <byte>(byteBuffer, i, null, 0, byteBuffer.Length);
                }
            } catch (Exception e) {
                Dispose();
                throw new TeslaException("Error creating underlying implementation, see inner exception for details.", e);
            }
        }
예제 #7
0
 /// <summary>
 /// Initializes a new instance of the <see cref="BinarySavableReader"/> class.
 /// </summary>
 /// <param name="inputStream">The input stream to read from.</param>
 /// <param name="renderSystem">The render system used for creating graphics objects.</param>
 /// <param name="contentManager">The content manager to load auxillary content.</param>
 public BinarySavableReader(Stream inputStream, IRenderSystemProvider renderSystem, ContentManager contentManager)
 {
     _input        = new BinaryReader(inputStream);
     _content      = contentManager;
     _renderSystem = renderSystem;
     _types        = new Dictionary <String, Type>();
     _constructors = new Dictionary <Type, ConstructorInfo>();
 }
예제 #8
0
        /// <summary>
        /// Deserializes the object and populates it from the input.
        /// </summary>
        /// <param name="input">Savable input</param>
        /// <exception cref="Tesla.Core.TeslaException">Thrown if creating the underlying state implementation fails or the render
        /// system is not set.</exception>
        public override void Read(Content.ISavableReader input)
        {
            IRenderSystemProvider renderSystem = input.RenderSystem;

            if (renderSystem == null)
            {
                Dispose();
                throw new TeslaException("Render system provider not set, cannot create graphics resource implementation.");
            }

            base.RenderSystem = renderSystem;
            try {
                _impl = renderSystem.CreateBlendStateImplementation();
            } catch (Exception e) {
                Dispose();
                throw new TeslaException("Error creating underlying implementation, see inner exception for details.", e);
            }

            _impl.AlphaBlendFunction    = input.ReadEnum <BlendFunction>();
            _impl.AlphaSourceBlend      = input.ReadEnum <Blend>();
            _impl.AlphaDestinationBlend = input.ReadEnum <Blend>();

            _impl.ColorBlendFunction    = input.ReadEnum <BlendFunction>();
            _impl.ColorSourceBlend      = input.ReadEnum <Blend>();
            _impl.ColorDestinationBlend = input.ReadEnum <Blend>();

            _impl.BlendFactor     = input.ReadColor();
            _impl.MultiSampleMask = input.ReadInt();

            int numBlends = _impl.BlendEnableCount;
            int numMasks  = _impl.ColorWriteChannelsCount;

            //Need to be careful here, this can change across different implementations. Just read in what we can and move on.
            int readNumBlends = input.ReadInt();

            for (int i = 0; i < numBlends; i++)
            {
                _impl.SetBlendEnable(i, input.ReadBoolean());
            }

            int readNumMasks = input.ReadInt();

            for (int i = 0; i < numMasks; i++)
            {
                _impl.SetWriteChannels(i, (ColorWriteChannels)input.ReadInt());
            }
        }
예제 #9
0
        /// <summary>
        /// Creates a new instance of <see cref="RenderTargetCube"/>.
        /// </summary>
        /// <param name="renderSystem">Render system used to create the underlying implementation.</param>
        /// <param name="size">The size (width/height) of each cube face.</param>
        /// <exception cref="System.ArgumentNullException">Thrown if the render system is null.</exception>
        /// <exception cref="Tesla.Core.TeslaException">Thrown if creating the underlying texture fails.</exception>
        public RenderTargetCube(IRenderSystemProvider renderSystem, int size)
        {
            if (renderSystem == null)
            {
                Dispose();
                throw new ArgumentNullException("renderSystem", "Render system cannot be null.");
            }

            base.RenderSystem = renderSystem;

            try {
                _impl = renderSystem.CreateRenderTargetCubeImplementation(size, false, SurfaceFormat.Color, DepthFormat.None, 1, RenderTargetUsage.DiscardContents);
            } catch (Exception e) {
                Dispose();
                throw new TeslaException("Error creating underlying implementation, see inner exception for details.", e);
            }
        }
예제 #10
0
        /// <summary>
        /// Creates a new instance of <see cref="IndexBuffer"/>.
        /// </summary>
        /// <param name="renderSystem">Render system used to create the underlying implementation.</param>
        /// <param name="format">The index format.</param>
        /// <param name="indexCount">The number of indices the buffer will contain.</param>
        /// <param name="usage">The resource usage specifying the type of memory the buffer should use.</param>
        /// <exception cref="System.ArgumentNullException">Thrown if the render system is null.</exception>
        /// <exception cref="Tesla.Core.TeslaException">Thrown if creating underlying buffer fails.</exception>
        public IndexBuffer(IRenderSystemProvider renderSystem, IndexFormat format, int indexCount, ResourceUsage usage)
        {
            if (renderSystem == null)
            {
                Dispose();
                throw new ArgumentNullException("renderSystem", "Render system cannot be null.");
            }

            base.RenderSystem = renderSystem;

            try {
                _impl = renderSystem.CreateIndexBufferImplementation(format, indexCount, usage);
            } catch (Exception e) {
                Dispose();
                throw new TeslaException("Error creating underlying implementation, see inner exception for details.", e);
            }
        }
예제 #11
0
        /// <summary>
        /// Creates a new instance of <see cref="TextureCube"/>.
        /// </summary>
        /// <param name="renderSystem">Render system used to create the underlying implementation.</param>
        /// <param name="size">The size (width/height) of each cube face.</param>
        /// <param name="genMipMap">True if mip levels should be generated.</param>
        /// <param name="format">The surface format.</param>
        /// <exception cref="System.ArgumentNullException">Thrown if the render system is null.</exception>
        /// <exception cref="Tesla.Core.TeslaException">Thrown if creating the underlying texture fails.</exception>
        public TextureCube(IRenderSystemProvider renderSystem, int size, bool genMipMap, SurfaceFormat format)
        {
            if (renderSystem == null)
            {
                Dispose();
                throw new ArgumentNullException("renderSystem", "Render system cannot be null.");
            }

            base.RenderSystem = renderSystem;

            try {
                _impl = renderSystem.CreateTextureCubeImplementation(size, genMipMap, format, null);
            } catch (Exception e) {
                Dispose();
                throw new TeslaException("Error creating underlying implementation, see inner exception for details.", e);
            }
        }
예제 #12
0
        /// <summary>
        /// Creates a new instance of <see cref="VertexBuffer"/>.
        /// </summary>
        /// <param name="renderSystem">Render system used to create the underlying implementation.</param>
        /// <param name="declaration">Vertex declaration that defines the vertex data of this buffer</param>
        /// <param name="usage">Buffer usage, either static or dynamic</param>
        /// <param name="data">Vertex data</param>
        /// <exception cref="System.ArgumentNullException">Thrown if the render system is null.</exception>
        /// <exception cref="Tesla.Core.TeslaException">Thrown if creating or writing to the underlying buffer fails.</exception>
        public VertexBuffer(IRenderSystemProvider renderSystem, VertexDeclaration declaration, ResourceUsage usage, DataBuffer data)
        {
            if (renderSystem == null)
            {
                Dispose();
                throw new ArgumentNullException("renderSystem", "Render system cannot be null.");
            }

            base.RenderSystem = renderSystem;

            try {
                _impl = renderSystem.CreateVertexBufferImplementation(declaration, usage, data);
            } catch (Exception e) {
                Dispose();
                throw new TeslaException("Error creating underlying implementation, see inner exception for details.", e);
            }
        }
예제 #13
0
        /// <summary>
        /// Creates a new instance of <see cref="RenderTarget2D"/>.
        /// </summary>
        /// <param name="renderSystem">Render system used to create the underlying implementation.</param>
        /// <param name="width">The target width in pixels.</param>
        /// <param name="height">The target height in pixels.</param>
        /// <param name="genMipMap">True if a mipmap chain should be generated or not.</param>
        /// <param name="format">The surface  format.</param>
        /// <param name="depthFormat">The depth format for the depth-stencil buffer.</param>
        /// <param name="multiSampleCount">The number of sample locations for multisampling</param>
        /// <param name="usage">Sets the render target's behavior.</param>
        /// <exception cref="System.ArgumentNullException">Thrown if the render system is null.</exception>
        /// <exception cref="Tesla.Core.TeslaException">Thrown if creating the underlying render target fails.</exception>
        public RenderTarget2D(IRenderSystemProvider renderSystem, int width, int height, bool genMipMap, SurfaceFormat format, DepthFormat depthFormat, int multiSampleCount, RenderTargetUsage usage)
        {
            if (renderSystem == null)
            {
                Dispose();
                throw new ArgumentNullException("renderSystem", "Render system cannot be null.");
            }

            base.RenderSystem = renderSystem;

            try {
                _impl = renderSystem.CreateRenderTarget2DImplementation(width, height, genMipMap, format, depthFormat, multiSampleCount, usage);
            } catch (Exception e) {
                Dispose();
                throw new TeslaException("Error creating underlying implementation, see inner exception for details.", e);
            }
        }
예제 #14
0
        /// <summary>
        /// Creates a new instance of <see cref="Texture3D"/>.
        /// </summary>
        /// <param name="renderSystem">Render system used to create the underlying implementation.</param>
        /// <param name="width">The width of the texture in pixels.</param>
        /// <param name="height">The height of the texture in pixels.</param>
        /// <param name="depth">The depth of the texture in pixels.</param>
        /// <param name="genMipMap">Whether or not mip maps should be generated. If so, the levels are created.</param>
        /// <param name="format">The surface format.</param>
        /// <param name="initialData">The data to initialize the first mip level to.</param>
        /// <exception cref="Tesla.Core.TeslaException">Thrown if creating the underlying texture fails or the render
        /// system was not initialized.</exception>
        public Texture3D(IRenderSystemProvider renderSystem, int width, int height, int depth, bool genMipMap, SurfaceFormat format, DataBuffer initialData)
        {
            if (renderSystem == null)
            {
                Dispose();
                throw new TeslaException("Render system provider not set, cannot create graphics resource implementation.");
            }

            base.RenderSystem = renderSystem;

            try {
                _impl = renderSystem.CreateTexture3DImplementation(width, height, depth, genMipMap, format, initialData);
            } catch (Exception e) {
                Dispose();
                throw new TeslaException("Error creating underlying implementation, see inner exception for details.", e);
            }
        }
예제 #15
0
        /// <summary>
        /// Creates a new instance of <see cref="Texture2D"/>. This creates an empty texture
        /// with <see cref="SurfaceFormat.Color"/>.
        /// </summary>
        /// <param name="renderSystem">Render system used to create the underlying implementation.</param>
        /// <param name="width">The width of the texture in pixels.</param>
        /// <param name="height">The height of the texture in pixels.</param>
        /// <exception cref="System.ArgumentNullException">Thrown if the render system is null.</exception>
        /// <exception cref="Tesla.Core.TeslaException">Thrown if creating the underlying texture fails.</exception>
        public Texture2D(IRenderSystemProvider renderSystem, int width, int height)
        {
            if (renderSystem == null)
            {
                Dispose();
                throw new ArgumentNullException("renderSystem", "Render system cannot be null.");
            }

            base.RenderSystem = renderSystem;

            try {
                _impl = renderSystem.CreateTexture2DImplementation(width, height, false, SurfaceFormat.Color, null);
            } catch (Exception e) {
                Dispose();
                throw new TeslaException("Error creating underlying implementation, see inner exception for details.", e);
            }
        }
예제 #16
0
        /// <summary>
        /// Creates a new instance of <see cref="Texture2D"/>.
        /// </summary>
        /// <param name="renderSystem">Render system used to create the underlying implementation.</param>
        /// <param name="width">The width of the texture in pixels.</param>
        /// <param name="height">The height of the texture in pixels.</param>
        /// <param name="genMipMap">Whether or not mip maps should be generated. If so, the levels are created.</param>
        /// <param name="format">The surface format.</param>
        /// <param name="initialData">The data to initialize the first mip level to.</param>
        /// <exception cref="System.ArgumentNullException">Thrown if the render system is null.</exception>
        /// <exception cref="Tesla.Core.TeslaException">Thrown if creating or writing to the underlying texture fails.</exception>
        public Texture2D(IRenderSystemProvider renderSystem, int width, int height, bool genMipMap, SurfaceFormat format, DataBuffer initialData)
        {
            if (renderSystem == null)
            {
                Dispose();
                throw new ArgumentNullException("renderSystem", "Render system cannot be null.");
            }

            base.RenderSystem = renderSystem;

            try {
                _impl = renderSystem.CreateTexture2DImplementation(width, height, genMipMap, format, initialData);
            } catch (Exception e) {
                Dispose();
                throw new TeslaException("Error creating underlying implementation, see inner exception for details.", e);
            }
        }
예제 #17
0
        /// <summary>
        /// Creates a new instance of <see cref="Texture1D"/>. This creates an empty texture.
        /// </summary>
        /// <param name="renderSystem">Render system used to create the underlying implementation.</param>
        /// <param name="width">The width of the texture in pixels.</param>
        /// <exception cref="Tesla.Core.TeslaException">Thrown if creating the underlying texture fails or the render
        /// system was not initialized.</exception>
        public Texture1D(IRenderSystemProvider renderSystem, int width)
        {
            if (renderSystem == null)
            {
                Dispose();
                throw new TeslaException("Render system provider not set, cannot create graphics resource implementation.");
            }

            base.RenderSystem = renderSystem;

            try {
                _impl = renderSystem.CreateTexture1DImplementation(width, false, SurfaceFormat.Color, null);
            } catch (Exception e) {
                Dispose();
                throw new TeslaException("Error creating underlying implementation, see inner exception for details.", e);
            }
        }
예제 #18
0
파일: Effect.cs 프로젝트: chuz/tesla-engine
        /// <summary>
        /// Creates a new Effect from the specified compiled shader byte code.
        /// </summary>
        /// <param name="renderSystem">Render system used to create the underlying implementation.</param>
        /// <param name="shaderByteCode">Compiled byte code</param>
        /// <exception cref="System.ArgumentNullException">Thrown if the render system is null.</exception>
        /// <exception cref="Tesla.Core.TeslaException">Thrown if creating the underlying state implementation fails.</exception>
        public Effect(IRenderSystemProvider renderSystem, byte[] shaderByteCode)
        {
            if (renderSystem == null)
            {
                Dispose();
                throw new ArgumentNullException("renderSystem", "Render system cannot be null.");
            }

            base.RenderSystem = renderSystem;

            try {
                _impl           = renderSystem.CreateEffectImplementation(shaderByteCode);
                _cachedByteCode = shaderByteCode;
            } catch (Exception e) {
                Dispose();
                throw new TeslaException("Error creating underlying implementation, see inner exception for details.", e);
            }
        }
예제 #19
0
        /// <summary>
        /// Creates a new instance of <see cref="IndexBuffer"/>.
        /// </summary>
        /// <param name="data">The index data.</param>
        /// <param name="usage">The resource usage specifying the type of memory the buffer should use.</param>
        /// <exception cref="Tesla.Core.TeslaException">Thrown if creating underlying buffer fails or the render system
        /// was not initialized.</exception>
        public IndexBuffer(DataBuffer <short> data, ResourceUsage usage)
        {
            IRenderSystemProvider renderSystem = Engine.Services.GetService <IRenderSystemProvider>();

            if (renderSystem == null)
            {
                Dispose();
                throw new TeslaException("Render system provider not set, cannot create graphics resource implementation.");
            }

            base.RenderSystem = renderSystem;
            try {
                _impl = renderSystem.CreateIndexBufferImplementation(data, usage);
            } catch (Exception e) {
                Dispose();
                throw new TeslaException("Error creating underlying implementation, see inner exception for details.", e);
            }
        }
예제 #20
0
        /// <summary>
        /// Creates a new instance of <see cref="Texture2D"/>. This creates an empty texture.
        /// </summary>
        /// <param name="width">The width of the texture in pixels.</param>
        /// <param name="height">The height of the texture in pixels.</param>
        /// <param name="genMipMap">Whether or not mip maps should be generated. If so, the levels are created.</param>
        /// <param name="format">The surface format.</param>
        /// <exception cref="Tesla.Core.TeslaException">Thrown if creating the underlying texture fails or the render
        /// system was not initialized.</exception>
        public Texture2D(int width, int height, bool genMipMap, SurfaceFormat format)
        {
            IRenderSystemProvider renderSystem = Engine.Services.GetService <IRenderSystemProvider>();

            if (renderSystem == null)
            {
                Dispose();
                throw new TeslaException("Render system provider not set, cannot create graphics resource implementation.");
            }

            base.RenderSystem = renderSystem;

            try {
                _impl = renderSystem.CreateTexture2DImplementation(width, height, genMipMap, format, null);
            } catch (Exception e) {
                Dispose();
                throw new TeslaException("Error creating underlying implementation, see inner exception for details.", e);
            }
        }
예제 #21
0
        /// <summary>
        /// Creates a new instance of <see cref="RenderTarget2D"/> with format <see cref="SurfaceFormat.Color"/>.
        /// </summary>
        /// <param name="width">The target width in pixels.</param>
        /// <param name="height">The target height in pixels.</param>
        /// <exception cref="Tesla.Core.TeslaException">Thrown if creating the underlying render target fails or the render
        /// system was not initialized.</exception>
        public RenderTarget2D(int width, int height)
        {
            IRenderSystemProvider renderSystem = Engine.Services.GetService <IRenderSystemProvider>();

            if (renderSystem == null)
            {
                Dispose();
                throw new TeslaException("Render system provider not set, cannot create graphics resource implementation.");
            }

            base.RenderSystem = renderSystem;

            try {
                _impl = renderSystem.CreateRenderTarget2DImplementation(width, height, false, SurfaceFormat.Color, DepthFormat.None, 0, RenderTargetUsage.DiscardContents);
            } catch (Exception e) {
                Dispose();
                throw new TeslaException("Error creating underlying implementation, see inner exception for details.", e);
            }
        }
예제 #22
0
        /// <summary>
        /// Creates a new instance of <see cref="BlendState"/> with default values.
        /// </summary>
        /// <param name="renderSystem">Render system used to create the underlying implementation.</param>
        /// <exception cref="System.ArgumentNullException">Thrown if the render system is null.</exception>
        /// <exception cref="Tesla.Core.TeslaException">Thrown if creating the underlying state implementation fails.</exception>
        public BlendState(IRenderSystemProvider renderSystem)
        {
            if (renderSystem == null)
            {
                Dispose();
                throw new ArgumentNullException("renderSystem", "Render system cannot be null.");
            }

            base.RenderSystem = renderSystem;

            try {
                _impl = renderSystem.CreateBlendStateImplementation();
            } catch (Exception e) {
                Dispose();
                throw new TeslaException("Error creating underlying implementation, see inner exception for details.", e);
            }

            SetDefaults();
        }
예제 #23
0
        /// <summary>
        /// Creates a new instance of <see cref="RenderTargetCube"/>.
        /// </summary>
        /// <param name="size">The size (width/height) of each cube face.</param>
        /// <param name="genMipMap">True if mip levels should be generated.</param>
        /// <param name="format">The surface format.</param>
        /// <param name="depthFormat">The depth format</param>
        /// <exception cref="Tesla.Core.TeslaException">Thrown if creating the underlying render target fails or the render
        /// system was not initialized.</exception>
        public RenderTargetCube(int size, bool genMipMap, SurfaceFormat format, DepthFormat depthFormat)
        {
            IRenderSystemProvider renderSystem = Engine.Services.GetService <IRenderSystemProvider>();

            if (renderSystem == null)
            {
                Dispose();
                throw new TeslaException("Render system provider not set, cannot create graphics resource implementation.");
            }

            base.RenderSystem = renderSystem;

            try {
                _impl = renderSystem.CreateRenderTargetCubeImplementation(size, genMipMap, format, depthFormat, 0, RenderTargetUsage.DiscardContents);
            } catch (Exception e) {
                Dispose();
                throw new TeslaException("Error creating underlying implementation, see inner exception for details.", e);
            }
        }
예제 #24
0
        /// <summary>
        /// Creates a new instance of <see cref="TextureCube"/>.
        /// </summary>
        /// <param name="size">The size (width/height) of each cube face.</param>
        /// <param name="genMipMap">True if mip levels should be generated.</param>
        /// <param name="format">The surface format.</param>
        /// <param name="initialData">The initial data for the first mip level.</param>
        /// <exception cref="Tesla.Core.TeslaException">Thrown if creating the underlying texture fails or the render
        /// system was not initialized.</exception>
        public TextureCube(int size, bool genMipMap, SurfaceFormat format, DataBuffer[] initialData)
        {
            IRenderSystemProvider renderSystem = Engine.Services.GetService <IRenderSystemProvider>();

            if (renderSystem == null)
            {
                Dispose();
                throw new TeslaException("Render system provider not set, cannot create graphics resource implementation.");
            }

            base.RenderSystem = renderSystem;

            try {
                _impl = renderSystem.CreateTextureCubeImplementation(size, genMipMap, format, initialData);
            } catch (Exception e) {
                Dispose();
                throw new TeslaException("Error creating underlying implementation, see inner exception for details.", e);
            }
        }
예제 #25
0
파일: Effect.cs 프로젝트: chuz/tesla-engine
        /// <summary>
        /// Creates a new Effect from the specified compiled shader byte code.
        /// </summary>
        /// <param name="shaderByteCode">Compiled byte code</param>
        /// <exception cref="Tesla.Core.TeslaException">Thrown if creating the underlying effect implementation fails.</exception>
        public Effect(byte[] shaderByteCode)
        {
            IRenderSystemProvider renderSystem = Engine.Services.GetService <IRenderSystemProvider>();

            if (renderSystem == null)
            {
                Dispose();
                throw new TeslaException("Render system provider not set, cannot create graphics resource implementation.");
            }

            base.RenderSystem = renderSystem;

            try {
                _impl           = renderSystem.CreateEffectImplementation(shaderByteCode);
                _cachedByteCode = shaderByteCode;
            } catch (Exception e) {
                Dispose();
                throw new TeslaException("Error creating underlying implementation, see inner exception for details.", e);
            }
        }
예제 #26
0
        /// <summary>
        /// Creates a new instance of <see cref="BlendState"/> with default values.
        /// </summary>
        /// <exception cref="Tesla.Core.TeslaException">Thrown if creating the underlying state implementation fails.</exception>
        public BlendState()
        {
            IRenderSystemProvider renderSystem = Engine.Services.GetService <IRenderSystemProvider>();

            if (renderSystem == null)
            {
                Dispose();
                throw new TeslaException("Render system provider not set, cannot create graphics resource implementation.");
            }

            base.RenderSystem = renderSystem;

            try {
                _impl = renderSystem.CreateBlendStateImplementation();
            } catch (Exception e) {
                Dispose();
                throw new TeslaException("Error creating underlying implementation, see inner exception for details.", e);
            }

            SetDefaults();
        }
예제 #27
0
        /// <summary>
        /// Creates a new instance of <see cref="Texture1D"/>. This creates an empty texture.
        /// </summary>
        /// <param name="renderSystem">Render system used to create the underlying implementation.</param>
        /// <param name="width">The width of the texture in pixels.</param>
        /// <param name="genMipMap">Whether or not mip maps should be generated. If so, the levels are created.</param>
        /// <param name="format">The surface format.</param>
        /// <exception cref="Tesla.Core.TeslaException">Thrown if creating the underlying texture fails or the render
        /// system was not initialized.</exception>
        /// <exception cref="System.InvalidOperationException">Thrown if the texture does not support the format.</exception>
        public Texture1D(IRenderSystemProvider renderSystem, int width, bool genMipMap, SurfaceFormat format)
        {
            if (renderSystem == null)
            {
                Dispose();
                throw new TeslaException("Render system provider not set, cannot create graphics resource implementation.");
            }

            if (!renderSystem.Renderer.Adapter.QueryTextureFormat(format, TextureDimensions.One))
            {
                throw new InvalidOperationException(String.Format("Texture1D does not support {0} format", format));
            }

            base.RenderSystem = renderSystem;
            try {
                _impl = renderSystem.CreateTexture1DImplementation(width, genMipMap, format, null);
            } catch (Exception e) {
                Dispose();
                throw new TeslaException("Error creating underlying implementation, see inner exception for details.", e);
            }
        }
예제 #28
0
        /// <summary>
        /// Deserializes the object and populates it from the input.
        /// </summary>
        /// <param name="input">Savable input</param>
        /// <exception cref="Tesla.Core.TeslaException">Thrown if creating the underlying state implementation fails or the render
        /// system is not set.</exception>
        public override void Read(Content.ISavableReader input)
        {
            IRenderSystemProvider renderSystem = input.RenderSystem;

            if (renderSystem == null)
            {
                Dispose();
                throw new TeslaException("Render system provider not set, cannot create graphics resource implementation.");
            }

            base.RenderSystem = renderSystem;
            try {
                _impl = renderSystem.CreateDepthStencilStateImplementation();
            } catch (Exception e) {
                Dispose();
                throw new TeslaException("Error creating underlying implementation, see inner exception for details.", e);
            }

            _impl.DepthEnable      = input.ReadBoolean();
            _impl.DepthWriteEnable = input.ReadBoolean();
            _impl.DepthFunction    = input.ReadEnum <ComparisonFunction>();
            _impl.StencilEnable    = input.ReadBoolean();
            _impl.ReferenceStencil = input.ReadInt();
            _impl.CounterClockwiseStencilFunction  = input.ReadEnum <ComparisonFunction>();
            _impl.CounterClockwiseStencilDepthFail = input.ReadEnum <StencilOperation>();
            _impl.CounterClockwiseStencilFail      = input.ReadEnum <StencilOperation>();
            _impl.CounterClockwiseStencilPass      = input.ReadEnum <StencilOperation>();
            _impl.StencilFunction       = input.ReadEnum <ComparisonFunction>();
            _impl.StencilDepthFail      = input.ReadEnum <StencilOperation>();
            _impl.StencilFail           = input.ReadEnum <StencilOperation>();
            _impl.StencilPass           = input.ReadEnum <StencilOperation>();
            _impl.TwoSidedStencilEnable = input.ReadBoolean();
            _impl.StencilReadMask       = input.ReadInt();
            _impl.StencilWriteMask      = input.ReadInt();

            this.BindRenderState();
        }
예제 #29
0
파일: Effect.cs 프로젝트: chuz/tesla-engine
        /// <summary>
        /// Deserializes this Effect.
        /// </summary>
        /// <param name="input">Input to read from</param>
        /// <exception cref="Tesla.Core.TeslaException">Thrown if creating the underlying effect implementation fails or the render
        /// system is not set.</exception>
        public void Read(ISavableReader input)
        {
            IRenderSystemProvider renderSystem = input.RenderSystem;

            if (renderSystem == null)
            {
                Dispose();
                throw new TeslaException("Render system provider not set, cannot create graphics resource implementation.");
            }

            base.RenderSystem = renderSystem;

            String name = input.ReadString();

            _cachedByteCode = input.ReadByteArray();

            try {
                _impl      = renderSystem.CreateEffectImplementation(_cachedByteCode);
                _impl.Name = name;
            } catch (Exception e) {
                Dispose();
                throw new TeslaException("Error creating underlying implementation, see inner exception for details.", e);
            }
        }
예제 #30
0
        /// <summary>
        /// Deserializes the object and populates it from the input.
        /// </summary>
        /// <param name="input">Savable input</param>
        /// <exception cref="Tesla.Core.TeslaException">Thrown if creating the underlying state implementation fails or the render
        /// system is not set.</exception>
        public override void Read(ISavableReader input)
        {
            IRenderSystemProvider renderSystem = input.RenderSystem;

            if (renderSystem == null)
            {
                Dispose();
                throw new TeslaException("Render system provider not set, cannot create graphics resource implementation.");
            }

            base.RenderSystem = renderSystem;
            try {
                _impl = renderSystem.CreateSamplerStateImplementation();
            } catch (Exception e) {
                Dispose();
                throw new TeslaException("Error creating underlying implementation, see inner exception for details.", e);
            }
            _impl.AddressU = input.ReadEnum <TextureAddressMode>();
            _impl.AddressV = input.ReadEnum <TextureAddressMode>();
            _impl.AddressW = input.ReadEnum <TextureAddressMode>();
            _impl.Filter   = input.ReadEnum <TextureFilter>();
            _impl.MipMapLevelOfDetailBias = input.ReadSingle();
            _impl.MaxAnisotropy           = input.ReadInt();
        }