Ejemplo n.º 1
0
        /// <summary>
        /// Multiplies a range of alpha values with a certain factor.
        /// </summary>
        public void ScaleAlphaBy(float factor, int index, int numVertices)
        {
            if (index < 0 || index >= _numVertices)
            {
                throw new IndexOutOfRangeException("Invalid vertex index");
            }

            if (factor == 1.0f)
            {
                return;
            }

            int minAlpha = _premultipliedAlpha ? (int)(MIN_ALPHA * 255.0f) : 0;

            for (int i = index; i < index + numVertices; ++i)
            {
                VertexColor vertexColor = _vertexColors[i];
                byte        newAlpha    = Convert.ToByte(NumberUtil.Clamp(vertexColor.A * factor, minAlpha, 255));

                if (_premultipliedAlpha)
                {
                    vertexColor      = VertexColorHelper.UnmultiplyAlpha(vertexColor);
                    vertexColor.A    = newAlpha;
                    _vertexColors[i] = VertexColorHelper.PremultiplyAlpha(vertexColor);
                }
                else
                {
                    _vertexColors[i] = VertexColorHelper.CreateVertexColor(vertexColor.R, vertexColor.G, vertexColor.B, newAlpha);
                }
            }
        }
Ejemplo n.º 2
0
 public void CompareVertexColor (VertexColor expected, VertexColor v2)
 {
     if (expected.R != v2.R || expected.B != v2.B || expected.G != v2.G || expected.A != v2.A)
     {
         Assert.Fail("Excepted: " + expected.R + " " + expected.G + " " + expected.B + " " + expected.A + " " +
             " actual: " + v2.R + " " + v2.G + " " + v2.B + " " + v2.A);
     }
 }
Ejemplo n.º 3
0
        /// <summary>
        /// Updates the color of a vertex. The method always expects non-premultiplied alpha values.
        /// </summary>
        public void SetColor(uint color, float alpha, int atIndex)
        {
            if (atIndex < 0 || atIndex >= _numVertices)
            {
                throw new IndexOutOfRangeException("Invalid vertex index");
            }

            alpha = NumberUtil.Clamp(alpha, _premultipliedAlpha ? MIN_ALPHA : 0.0f, 1.0f);

            VertexColor vertexColor = VertexColorHelper.CreateVertexColor(color, alpha);

            _vertexColors[atIndex] = _premultipliedAlpha ? VertexColorHelper.PremultiplyAlpha(vertexColor) : vertexColor;
        }
Ejemplo n.º 4
0
        /// <summary>
        /// Returns the RGB color of a vertex (without premultiplied alpha).
        /// </summary>
        public uint ColorAt(int index)
        {
            if (index < 0 || index >= _numVertices)
            {
                throw new IndexOutOfRangeException("Invalid vertex index");
            }

            VertexColor vertexColor = _vertexColors[index];

            if (_premultipliedAlpha)
            {
                vertexColor = VertexColorHelper.UnmultiplyAlpha(vertexColor);
            }

            return(ColorUtil.GetRGB(vertexColor.R, vertexColor.G, vertexColor.B));
        }