Example #1
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);
            }
        }
Example #2
0
        /// <summary>
        /// Creates a new instance of <see cref="Texture2D"/>.
        /// </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>
        /// <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 Texture2D(int width, int height, 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.CreateTexture2DImplementation(width, height, genMipMap, format, initialData);
            } catch (Exception e) {
                Dispose();
                throw new TeslaException("Error creating underlying implementation, see inner exception for details.", e);
            }
        }