/// <summary>
        /// Adds a mesh to the current batch, or to a new one if the current one does not support
        /// it. Whenever the batch changes, <code>onBatchComplete</code> is called for the previous
        /// one.
        /// </summary>
        /// <param name="mesh">The mesh to add to the current(or new) batch.</param>
        /// <param name="state">The render state from which to take the current settings for alpha,
        ///                    modelview matrix, and blend mode.</param>
        /// <param name="subset">The subset of the mesh you want to add, or<code>null</code> for
        ///                    the complete mesh.</param>
        /// <param name="ignoreTransformations">When enabled, the mesh's vertices will be added
        ///                    without transforming them in any way (no matter the value of the
        ///                    state's <code>modelviewMatrix</code></param>
        public void AddMesh(Mesh mesh, RenderState state, MeshSubset subset = null,
                            bool ignoreTransformations = false)
        {
            if (subset == null)
            {
                subset             = SMeshSubset;
                subset.VertexId    = subset.IndexId = 0;
                subset.NumVertices = mesh.NumVertices;
                subset.NumIndices  = mesh.NumIndices;
            }
            else
            {
                if (subset.NumVertices < 0)
                {
                    subset.NumVertices = mesh.NumVertices - subset.VertexId;
                }
                if (subset.NumIndices < 0)
                {
                    subset.NumIndices = mesh.NumIndices - subset.IndexId;
                }
            }

            if (subset.NumVertices > 0)
            {
                if (_currentBatch == null || !_currentBatch.CanAddMesh(mesh, subset.NumVertices))
                {
                    FinishBatch();

                    _currentStyleType       = mesh.Style.Type;
                    _currentBatch           = _batchPool.GetBatch(_currentStyleType);
                    _currentBatch.BlendMode = state != null ? state.BlendMode : mesh.BlendMode;
                    _cacheToken.SetTo(_batches.Count);
                    _batches.Add(_currentBatch);
                }

                Matrix2D matrix = state != null ? state._modelviewMatrix : null;
                float    alpha  = state != null ? state.Alpha : 1.0f;

                _currentBatch.AddMesh(mesh, matrix, alpha, subset, ignoreTransformations);
                _cacheToken.VertexID += subset.NumVertices;
                _cacheToken.IndexID  += subset.NumIndices;
            }
        }
Exemple #2
0
        /** Draws text into a QuadBatch. */
        public void FillMeshBatch(MeshBatch meshBatch, float width, float height, string text,
                                  TextFormat format, TextOptions options = null)
        {
            List <CharLocation> charLocations = ArrangeChars(
                width, height, text, format, options);
            int numChars = charLocations.Count;

            _helperImage.Color = format.Color;

            for (int i = 0; i < numChars; ++i)
            {
                CharLocation charLocation = charLocations[i];
                _helperImage.Texture = charLocation.Char.Texture;
                _helperImage.ReadjustSize();
                _helperImage.X     = charLocation.X;
                _helperImage.Y     = charLocation.Y;
                _helperImage.Scale = charLocation.Scale;
                meshBatch.AddMesh(_helperImage);
            }
        }