Example #1
0
        ///// <summary>
        ///// Create a new GeometryBuffer and return a reference to it.  You should
        ///// remove the GeometryBuffer from any RenderQueues and call
        ///// destroyGeometryBuffer when you want to destroy the GeometryBuffer.
        ///// </summary>
        ///// <returns>
        ///// GeometryBuffer object.
        ///// </returns>
        //public abstract GeometryBuffer CreateGeometryBuffer();

        /// <summary>
        /// Destroy a GeometryBuffer that was returned when calling the
        /// createGeometryBuffer function.  Before destroying any GeometryBuffer
        /// you should ensure that it has been removed from any RenderQueue that
        /// was using it.
        /// </summary>
        /// <param name="buffer">
        /// The GeometryBuffer object to be destroyed.
        /// </param>
        public void DestroyGeometryBuffer(GeometryBuffer buffer)
        {
#if DEBUG
            if (!d_geometryBuffers.Contains(buffer))
            {
                return;
            }
#endif
            d_geometryBuffers.Remove(buffer);
            buffer.Dispose();
        }
Example #2
0
        public override void AddToRenderGeometry(GeometryBuffer geomBuffer, ref Rectf renderArea, ref Rectf?clipArea, ColourRect colours)
        {
            Rectf texRect = Rectf.Zero, finalRect;
            var   isFullClipped = CalculateTextureAndRenderAreas(renderArea, ref clipArea, out finalRect, ref texRect);

            if (isFullClipped)
            {
                return;
            }
            var vbuffer = new TexturedColouredVertex[6];

            CreateTexturedQuadVertices(vbuffer, colours, ref finalRect, ref texRect);
            geomBuffer.AppendGeometry(vbuffer);
        }
Example #3
0
        /// <summary>
        ///
        /// </summary>
        /// <param name="text"></param>
        /// <param name="nextGlyphPosX">
        /// The x-coordinate where subsequent text should be rendered to ensure correct
        /// positioning (which is not possible to determine accurately by using the
        /// extent measurement functions).</param>
        /// <param name="position"></param>
        /// <param name="clipRect"></param>
        /// <param name="clippingEnabled"></param>
        /// <param name="colours"></param>
        /// <param name="spaceExtra"></param>
        /// <param name="xScale"></param>
        /// <param name="yScale"></param>
        /// <returns>
        /// Returns a list of GeometryBuffers representing the render geometry of the text.
        /// </returns>
        public List <GeometryBuffer> CreateRenderGeometryForText(string text,
                                                                 out float nextGlyphPosX,
                                                                 Lunatics.Mathematics.Vector2 position,
                                                                 Rectf?clipRect,
                                                                 bool clippingEnabled,
                                                                 ColourRect colours,
                                                                 float spaceExtra = 0.0f,
                                                                 float xScale     = 1.0f,
                                                                 float yScale     = 1.0f)
        {
            var            baseY              = position.Y + GetBaseline(yScale);
            var            glyphPos           = position;
            var            lastChar           = (char)0;
            var            geomBuffers        = new List <GeometryBuffer>();
            GeometryBuffer textGeometryBuffer = null;

            var imgRenderSettings = new ImageRenderSettings(Rectf.Zero, clipRect, clippingEnabled, colours);

            foreach (var c in text)
            {
                var glyph = GetGlyphData(c);
                if (glyph != null)
                {
                    var img = glyph.GetImage();
                    glyphPos.X += GetKerningAmount(lastChar, c);
                    glyphPos.Y  = baseY - (img.GetRenderedOffset().Y - img.GetRenderedOffset().Y *yScale);

                    imgRenderSettings.DestArea = new Rectf(glyphPos, glyph.GetSize(xScale, yScale));

                    if (textGeometryBuffer == null)
                    {
                        var currentGeombuffs = img.CreateRenderGeometry(imgRenderSettings);
                        Debug.Assert(currentGeombuffs.Count <= 1, "Glyphs are expected to be built from a single GeometryBuffer (or none)");
                        if (currentGeombuffs.Count == 1)
                        {
                            textGeometryBuffer = currentGeombuffs[0];
                        }
                    }
                    else
                    {
                        // Else we add geometry to the rendering batch of the existing geometry
                        img.AddToRenderGeometry(textGeometryBuffer, ref imgRenderSettings.DestArea, ref clipRect, colours);
                    }

                    glyphPos.X += glyph.GetAdvance(xScale);
                    // apply extra spacing to space chars
                    if (c == ' ')
                    {
                        glyphPos.X += spaceExtra;
                    }
                }

                lastChar = c;
            }

            if (textGeometryBuffer != null)
            {
                geomBuffers.Add(textGeometryBuffer);
            }

            nextGlyphPosX = glyphPos.X;

            // Adding a single geometry buffer containing the batched glyphs
            return(geomBuffers);
        }
Example #4
0
 /// <summary>
 /// Appends additional render geometry for this image to an GeometryBuffers.
 /// The GeometryBuffer must be created beforehand and must feature render
 /// settings that allow adding this image geometry into the same render batch.
 /// Batching compatibility has to be ensured before this call.
 /// </summary>
 /// <param name="geomBuffer">
 /// The existing GeometryBuffers to which the new render geometry will be appended.
 /// </param>
 /// <param name="renderArea">
 /// The target area at which the image should be rendered.
 /// </param>
 /// <param name="clipAreaColourRect">
 /// </param>
 /// <param name="colours">
 /// Multiplicative colours to be applied to the text.
 /// </param>
 public abstract void AddToRenderGeometry(GeometryBuffer geomBuffer, ref Rectf renderArea, ref Rectf?clipAreaColourRect, ColourRect colours);
Example #5
0
 /// <summary>
 /// Take point \a p_in unproject it and put the result in \a p_out.
 /// Resulting point is local to GeometryBuffer \a buff.
 /// </summary>
 /// <param name="buff"></param>
 /// <param name="pIn"></param>
 /// <param name="pOut"></param>
 public abstract void UnprojectPoint(GeometryBuffer buff,
                                     Lunatics.Mathematics.Vector2 pIn,
                                     out Lunatics.Mathematics.Vector2 pOut);
Example #6
0
 /// <summary>
 /// Draw geometry from the given GeometryBuffer onto the surface that
 /// this RenderTarget represents.
 /// </summary>
 /// <param name="buffer">
 /// GeometryBuffer object holding the geometry that should be drawn to the
 /// RenderTarget.
 /// </param>
 public virtual void Draw(GeometryBuffer buffer)
 {
     buffer.Draw();
 }
 /// <summary>
 /// Remove the specified GeometryBuffer from the specified queue.
 /// </summary>
 /// <param name="queue">
 /// One of the RenderQueueID enumerated values indicating which prioritised
 /// queue the GeometryBuffer should be removed from.
 /// </param>
 /// <param name="buffer">
 /// GeometryBuffer object to be removed from the specified rendering queue.
 /// </param>
 public void RemoveGeometryBuffer(RenderQueueId queue, GeometryBuffer buffer)
 {
     d_queues[queue].RemoveGeometryBuffer(buffer);
 }
 /// <summary>
 /// Add the specified GeometryBuffer to the specified queue for rendering
 /// when the RenderingSurface is drawn.
 /// </summary>
 /// <param name="queue">
 /// One of the RenderQueueID enumerated values indicating which prioritised
 /// queue the GeometryBuffer should be added to.
 /// </param>
 /// <param name="buffer">
 /// GeometryBuffer object to be added to the specified rendering queue.
 /// </param>
 /// <remarks>
 /// The RenderingSurface does not take ownership of the <see cref="GeometryBuffer"/>, and
 /// does not destroy it when the RenderingSurface geometry is cleared. Rather, the
 /// RenderingSurface is just maintaining a list of thigs to be  drawn; the actual
 /// GeometryBuffers can be re-used by whichever object \e does own them, and even changed
 /// or updated while still "attached" to a RenderingSurface.
 /// </remarks>
 public void AddGeometryBuffer(RenderQueueId queue, GeometryBuffer buffer)
 {
     d_queues[queue].AddGeometryBuffer(buffer);
 }
Example #9
0
 /// <summary>
 /// Remove a GeometryBuffer previously queued for drawing.  If the specified
 /// GeometryBuffer is not added to the queue, no action is taken. The
 /// removed GeometryBuffer is not destroyed or modified in any way.
 /// </summary>
 /// <param name="buffer">
 /// GeometryBuffer to be removed from the queue.
 /// </param>
 public void RemoveGeometryBuffer(GeometryBuffer buffer)
 {
     _buffers.Remove(buffer);
 }
Example #10
0
 /// <summary>
 /// Add a GeometryBuffer to the RenderQueue. Ownership of the
 /// GeometryBuffer does not pass to the RenderQueue.
 /// </summary>
 /// <param name="buffer">
 /// GeometryBuffer that is to be added to the RenderQueue for later drawing.
 /// </param>
 public void AddGeometryBuffer(GeometryBuffer buffer)
 {
     _buffers.Add(buffer);
 }
Example #11
0
 /// <summary>
 /// Adds a created GeometryBuffer, which was returned when calling one of the
 /// createGeometryBuffer functions, to the list of GeometryBuffers.
 /// </summary>
 /// <param name="geometryBuffer">
 /// The GeometryBuffer object to be destroyed.
 /// </param>
 protected void AddGeometryBuffer(GeometryBuffer geometryBuffer)
 {
     d_geometryBuffers.Add(geometryBuffer);
 }