Ejemplo 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 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);
            }
        }
Ejemplo n.º 2
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);
            }
        }
Ejemplo n.º 3
0
        /// <summary>
        /// Creates a new instance of <see cref="VertexBuffer"/>.
        /// </summary>
        /// <param name="declaration">Vertex declaration that defines the vertex data this buffer will contain</param>
        /// <param name="vertexCount">Number of vertices the buffer will contain</param>
        /// <param name="usage">Buffer usage, either static or dynamic</param>
        /// <exception cref="Tesla.Core.TeslaException">Thrown if creating underlying buffer fails or the render system
        /// was not initialized.</exception>
        public VertexBuffer(VertexDeclaration declaration, int vertexCount, 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.CreateVertexBufferImplementation(declaration, vertexCount, usage);
            } catch (Exception e) {
                Dispose();
                throw new TeslaException("Error creating underlying implementation, see inner exception for details.", e);
            }
        }