Esempio n. 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 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           depth    = input.ReadInt();
            int           mipCount = input.ReadInt();

            try {
                _impl = renderSystem.CreateTexture3DImplementation(width, height, depth, mipCount > 1, format, null);
                for (int i = 0; i < mipCount; i++)
                {
                    byte[] byteBuffer = input.ReadByteArray();
                    _impl.SetData <byte>(byteBuffer, i, 0, width, 0, height, 0, depth, 0, byteBuffer.Length);
                    width  = System.Math.Max(width >> 1, 1);
                    height = System.Math.Max(height >> 1, 1);
                    depth  = System.Math.Max(depth >> 1, 1);
                }
            } catch (Exception e) {
                Dispose();
                throw new TeslaException("Error creating underlying implementation, see inner exception for details.", e);
            }
        }
Esempio n. 2
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);
            }
        }
Esempio n. 3
0
        /// <summary>
        /// Creates a new instance of <see cref="Texture3D"/>. 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="depth">The depth 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 Texture3D(int width, int height, int depth)
        {
            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.CreateTexture3DImplementation(width, height, depth, false, SurfaceFormat.Color, null);
            } catch (Exception e) {
                Dispose();
                throw new TeslaException("Error creating underlying implementation, see inner exception for details.", e);
            }
        }