Exemple #1
0
        protected override void FlushToBuffer()
        {
            if (
                (_Buffer != null) &&
                (
                    (_Buffer.VertexCount < _VertexArray.Length) ||
                    (_Buffer.IndexCount < _IndexArray.Length)
                )
                )
            {
                DisposeResource(_Buffer);
                _Buffer = null;
            }

            if (_VertexArray.Length >= UInt16.MaxValue)
            {
                throw new InvalidOperationException("Too many vertices");
            }

            if (_Buffer == null)
            {
                _Buffer = new Sce.PlayStation.Core.Graphics.VertexBuffer(_VertexArray.Length, _IndexArray.Length, VertexFormat);
            }

            _Buffer.SetVertices(_VertexArray, 0, 0, _VertexCount);
            _Buffer.SetIndices(_IndexArray, 0, 0, _IndexCount);
        }
Exemple #2
0
 public override void Dispose()
 {
     disposeChilderen();
     if (vertexBuffer != null)
     {
         vertexBuffer.Dispose();
         vertexBuffer = null;
     }
     base.Dispose();
 }
Exemple #3
0
        private void init(DisposableI parent, BufferLayoutDescI bufferLayoutDesc, BufferUsages bufferUsage, VertexBufferTopologys vertexBufferTopology, float[] vertices, int[] indices)
        {
            try
            {
                video    = parent.FindParentOrSelfWithException <Video>();
                Topology = vertexBufferTopology;

                var format = new G.VertexFormat[bufferLayoutDesc.Elements.Count];
                for (int i = 0; i != bufferLayoutDesc.Elements.Count; ++i)
                {
                    switch (bufferLayoutDesc.Elements[i].FloatCount)
                    {
                    case 1: format[i] = G.VertexFormat.Float; break;

                    case 2: format[i] = G.VertexFormat.Float2; break;

                    case 3: format[i] = G.VertexFormat.Float3; break;

                    case 4: format[i] = G.VertexFormat.Float4; break;
                    }
                }

                if (indices != null && indices.Length != 0)
                {
                    vertexBuffer = new G.VertexBuffer(vertexCount, indices.Length, format);

                    indexCount = indices.Length;
                    var indicesShort = new ushort[indexCount];
                    for (int i = 0; i != indexCount; ++i)
                    {
                        indicesShort[i] = (ushort)indices[i];
                    }
                    vertexBuffer.SetIndices(indicesShort);
                }
                else
                {
                    vertexBuffer = new G.VertexBuffer(vertexCount, format);
                }
                vertexBuffer.SetVertices(vertices);
            }
            catch (Exception e)
            {
                Dispose();
                throw e;
            }
        }
        internal PssVertexBuffer GetVertexBuffer(VertexFormat[] vertexFormat, int requiredVertexLength, int requiredIndexLength)
        {
            int             bestMatchIndex = -1;
            PssVertexBuffer bestMatch      = null;

            //Search for a good one
            for (int i = _availableVertexBuffers.Count - 1; i >= 0; i--)
            {
                var buf = _availableVertexBuffers[i];

                // Check there is enough space
                if (buf.VertexCount != requiredVertexLength)
                {
                    continue;
                }
                if (requiredIndexLength == 0 && buf.IndexCount != 0)
                {
                    continue;
                }
                if (requiredIndexLength > 0 && buf.IndexCount != requiredIndexLength)
                {
                    continue;
                }

                // Check VertexFormat is the same
                var bufFormats = buf.Formats;
                if (vertexFormat.Length != bufFormats.Length)
                {
                    continue;
                }
                bool allEqual = true;
                for (int j = 0; j < bufFormats.Length; j++)
                {
                    if (vertexFormat[j] != bufFormats[j])
                    {
                        allEqual = false;
                        break;
                    }
                }
                if (!allEqual)
                {
                    continue;
                }

                //this one is acceptable

                //No current best or this one is smaller than the current best
                if (bestMatch == null || (buf.IndexCount + buf.VertexCount) < (bestMatch.IndexCount + bestMatch.VertexCount))
                {
                    bestMatch      = buf;
                    bestMatchIndex = i;
                }
            }

            if (bestMatch != null)
            {
                return(bestMatch);
            }
            else
            {
                //Create one
                bestMatch = new PssVertexBuffer(requiredVertexLength, requiredIndexLength, vertexFormat);
            }
            _usedVertexBuffers.Add(bestMatch);

            return(bestMatch);
        }