Exemplo n.º 1
0
        public void ColorRGBAF_Accessor()
        {
            float r = (float)NextComponent(1.0f);
            float g = (float)NextComponent(1.0f);
            float b = (float)NextComponent(1.0f);
            float a = (float)NextComponent(1.0f);

            ColorRGBAF v = new ColorRGBAF(r, g, b, a);
            float      c;

            Assert.DoesNotThrow(() => c = v[0]);
            Assert.DoesNotThrow(() => c = v[1]);
            Assert.DoesNotThrow(() => c = v[2]);
            Assert.DoesNotThrow(() => c = v[3]);
            Assert.Throws <IndexOutOfRangeException>(() => c = v[+4]);
            Assert.Throws <IndexOutOfRangeException>(() => c = v[-1]);

            Assert.DoesNotThrow(() => v[0] = 1.0f);
            Assert.DoesNotThrow(() => v[1] = 1.0f);
            Assert.DoesNotThrow(() => v[2] = 1.0f);
            Assert.DoesNotThrow(() => v[3] = 1.0f);
            Assert.Throws <IndexOutOfRangeException>(() => v[+4] = 0.0f);
            Assert.Throws <IndexOutOfRangeException>(() => v[-1] = 0.0f);

            Assert.DoesNotThrow(() => v[3] = 0.0f);
            Assert.DoesNotThrow(() => v[3] = 1.0f);
            Assert.Throws <InvalidOperationException>(() => v[3] = -1.0f);
            Assert.Throws <InvalidOperationException>(() => v[3] = +1.1f);
        }
Exemplo n.º 2
0
		public ColorRGBA(ColorRGBAF c)
		{
			Red = c.Red;
			Green = c.Green;
			Blue = c.Blue;
			Alpha = c.Alpha;
		}
Exemplo n.º 3
0
        public void ColorRGBAF_OperatorInequality()
        {
            ColorRGBAF v = ColorRGBAF.ColorRed;

            Assert.IsFalse(v != ColorRGBAF.ColorRed);
            Assert.IsTrue(v != ColorRGBAF.ColorGreen);
        }
Exemplo n.º 4
0
        /// <summary>
        /// Draw a character sequence.
        /// </summary>
        /// <param name="ctx">
        /// The <see cref="GraphicsContext"/> used for drawing.
        /// </param>
        /// <param name="modelview">
        /// The <see cref="Matrix4x4"/> the model-view-projection matrix for the first character of <paramref name="s"/>.
        /// </param>
        /// <param name="color">
        /// The <see cref="ColorRGBAF"/> that specifies the glyph color.
        /// </param>
        /// <param name="s">
        /// A <see cref="String"/> that specifies the characters for be drawn.
        /// </param>
        public override void DrawString(GraphicsContext ctx, Matrix4x4 modelview, ColorRGBAF color, string s)
        {
            ModelMatrix charModel = new ModelMatrix(modelview);

            ctx.Bind(_FontProgram);

            _FontProgram.SetUniform(ctx, "glo_UniformColor", color);

            foreach (char c in s)
            {
                Glyph glyph;

                if (_Glyphs.TryGetValue(c, out glyph) == false)
                {
                    continue;
                }

                if (glyph.ElementIndex >= 0)
                {
                    // Set model-view
                    _FontProgram.SetUniform(ctx, "glo_ModelViewProjection", charModel);
                    // Rasterize it
                    _VertexArrays.Draw(ctx, _FontProgram, glyph.ElementIndex);
                }
                // Move next
                charModel.Translate(glyph.GlyphSize.Width, 0.0f);
            }
        }
Exemplo n.º 5
0
        /// <summary>
        /// Draw a character sequence.
        /// </summary>
        /// <param name="ctx">
        /// The <see cref="GraphicsContext"/> used for drawing.
        /// </param>
        /// <param name="modelview">
        /// The <see cref="Matrix4x4f"/> the model-view-projection matrix for the first character of <paramref name="s"/>.
        /// </param>
        /// <param name="color">
        /// The <see cref="ColorRGBAF"/> that specifies the glyph color.
        /// </param>
        /// <param name="s">
        /// A <see cref="String"/> that specifies the characters for be drawn.
        /// </param>
        public override void DrawString(GraphicsContext ctx, Matrix4x4f modelview, ColorRGBAF color, string s)
        {
            List <GlyphModelType> glyphsInstances = GetGlyphsInstances(modelview, s);

            UpdateGlyphBuffer(ctx, glyphsInstances);

            DrawStringCore(ctx, _FontTexture, color, glyphsInstances);
        }
Exemplo n.º 6
0
 /// <summary>
 /// Construct a Material with a specific diffuse color.
 /// </summary>
 /// <param name="diffuse"></param>
 public Material(ColorRGBAF diffuse)
 {
     Ambient   = ColorRGBAF.ColorBlack;
     Emissive  = ColorRGBAF.ColorBlack;
     Diffuse   = diffuse;
     Specular  = ColorRGBAF.ColorBlack;
     Shininess = 32.0f;
 }
Exemplo n.º 7
0
        public void ColorRGBAF_Equals_ColorRGBAF()
        {
            ColorRGBAF v = ColorRGBAF.ColorRed;

            Assert.IsTrue(v.Equals(ColorRGBAF.ColorRed));
            Assert.IsFalse(v.Equals(ColorRGBAF.ColorGreen));
            Assert.IsFalse(v.Equals(ColorRGBAF.ColorBlue));
        }
Exemplo n.º 8
0
        /// <summary>
        /// Draw a character sequence.
        /// </summary>
        /// <param name="ctx">
        /// The <see cref="GraphicsContext"/> used for drawing.
        /// </param>
        /// <param name="modelview">
        /// The <see cref="Matrix4x4"/> the model-view-projection matrix for the first character of <paramref name="s"/>.
        /// </param>
        /// <param name="color">
        /// The <see cref="ColorRGBAF"/> that specifies the glyph color.
        /// </param>
        /// <param name="s">
        /// A <see cref="String"/> that specifies the characters for be drawn.
        /// </param>
        public override void DrawString(GraphicsContext ctx, Matrix4x4 modelview, ColorRGBAF color, string s)
        {
            ModelMatrix charModel = new ModelMatrix(modelview);

            ctx.Bind(_FontProgram);

            // Set uniforms
            _FontProgram.SetUniform(ctx, "glo_UniformColor", color);
            _FontProgram.SetUniform(ctx, "glo_FontGlyph", _FontTexture);
            // Set instances
            char[] fontChars = s.ToCharArray();
            uint   instances = 0;

            _GlyphInstances.Map(ctx, BufferAccessARB.WriteOnly);
            try {
                for (int i = 0; i < fontChars.Length; i++)
                {
                    Glyph glyph;

                    if (_GlyphDb.TryGetValue(fontChars[i], out glyph) == false)
                    {
                        continue;
                    }

                    // Set instance information
                    Matrix4x4f modelViewProjection = new Matrix4x4f(
                        new Vertex4f(charModel.GetColumn(0)),
                        new Vertex4f(charModel.GetColumn(1)),
                        new Vertex4f(charModel.GetColumn(2)),
                        new Vertex4f(charModel.GetColumn(3))
                        );
                    Vertex3f glyphVertexParams = new Vertex3f(
                        glyph.GlyphSize.Width, glyph.GlyphSize.Height,
                        glyph.Layer
                        );
                    Vertex2f glyphTexParams = new Vertex2f(
                        glyph.TexScale.Width, glyph.TexScale.Height
                        );

                    _GlyphInstances.SetElement(modelViewProjection, instances, 0);
                    _GlyphInstances.SetElement(glyphVertexParams, instances, 1);
                    _GlyphInstances.SetElement(glyphTexParams, instances, 2);

                    // Count the instance
                    instances++;

                    // Move next
                    charModel.Translate(glyph.GlyphSize.Width, 0.0f);
                }
            } finally {
                _GlyphInstances.Unmap(ctx);
            }
            // Rasterize it
            using (State.BlendState stateBlend = State.BlendState.AlphaBlending) {
                stateBlend.ApplyState(ctx, _FontProgram);
                _VertexArrays.DrawInstanced(ctx, _FontProgram, instances);
            }
        }
Exemplo n.º 9
0
        public void ColorRGBF_CastToRGBA()
        {
            float r = (float)NextComponent(1.0f);
            float g = (float)NextComponent(1.0f);
            float b = (float)NextComponent(1.0f);

            ColorRGBF  v     = new ColorRGBF(r, g, b);
            ColorRGBAF vRGBA = v;
        }
Exemplo n.º 10
0
        public void ColorRGBAF_PixelType()
        {
            float r = (float)NextComponent(1.0f);
            float g = (float)NextComponent(1.0f);
            float b = (float)NextComponent(1.0f);
            float a = (float)NextComponent(1.0f);

            ColorRGBAF v = new ColorRGBAF(r, g, b, a);

            Assert.AreNotEqual(PixelLayout.None, v.PixelType);
        }
Exemplo n.º 11
0
        public void ColorRGBAF_GetHashCode()
        {
            float r = (float)NextComponent(float.MaxValue);
            float g = (float)NextComponent(float.MaxValue);
            float b = (float)NextComponent(float.MaxValue);
            float a = (float)NextComponent(float.MaxValue);

            ColorRGBAF v = new ColorRGBAF(r, g, b, a);

            Assert.DoesNotThrow(() => v.GetHashCode());
        }
Exemplo n.º 12
0
        public void ColorRGBAF_Equals_Object()
        {
            ColorRGBAF v = ColorRGBAF.ColorRed;

            Assert.IsFalse(v.Equals(null));
            Assert.IsFalse(v.Equals(String.Empty));
            Assert.IsFalse(v.Equals(0.0f));

            Assert.IsTrue(v.Equals((object)ColorRGBAF.ColorRed));
            Assert.IsFalse(v.Equals((object)ColorRGBAF.ColorGreen));
            Assert.IsFalse(v.Equals((object)ColorRGBAF.ColorBlue));
        }
Exemplo n.º 13
0
        /// <summary>
        /// Construct a BlendState with separated RGB/Alpha functions.
        /// </summary>
        /// <param name="rgbEquation">
        /// A <see cref="BlendEquationModeEXT"/> flag indicating which equation to used for blending RGB color components.
        /// </param>
        /// <param name="alphaEquation">
        /// A <see cref="BlendEquationModeEXT"/> flag indicating which equation to used for blending Alpha color component.
        /// </param>
        /// <param name="srcRgbFactor">
        /// A <see cref="BlendingFactorSrc"/> that specify the scaling factors applied to the source color (alpha component excluded).
        /// </param>
        /// <param name="srcAlphaFactor">
        /// A <see cref="BlendingFactorSrc"/> that specify the scaling factors applied to only the source alpha component.
        /// </param>
        /// <param name="dstRgbFactor">
        /// A <see cref="BlendingFactorDest"/> that specify the scaling factors applied to the destination color (alpha component excluded).
        /// </param>
        /// <param name="dstAlphaFactor">
        /// A <see cref="BlendingFactorDest"/> that specify the scaling factors applied to only the destination alpha component.
        /// </param>
        /// <param name="constColor">
        /// A <see cref="ColorRGBAF"/> that specify the constant color used in blending functions.
        /// </param>
        public BlendState(BlendEquationModeEXT rgbEquation, BlendEquationModeEXT alphaEquation, BlendingFactorSrc srcRgbFactor, BlendingFactorSrc srcAlphaFactor, BlendingFactorDest dstRgbFactor, BlendingFactorDest dstAlphaFactor, ColorRGBAF constColor)
        {
            if (IsSupportedEquation(rgbEquation) == false)
            {
                throw new ArgumentException("not supported blending equation " + srcRgbFactor, "rgbEquation");
            }
            if (IsSupportedEquation(alphaEquation) == false)
            {
                throw new ArgumentException("not supported blending equation " + alphaEquation, "rgbEquation");
            }
            if (IsSupportedFunction(srcRgbFactor) == false)
            {
                throw new ArgumentException("not supported blending function " + srcRgbFactor, "srcRgbFactor");
            }
            if (IsSupportedFunction(srcAlphaFactor) == false)
            {
                throw new ArgumentException("not supported blending function " + srcAlphaFactor, "srcAlphaFactor");
            }
            if (IsSupportedFunction(dstRgbFactor) == false)
            {
                throw new ArgumentException("not supported blending function " + dstRgbFactor, "dstRgbFactor");
            }
            if (IsSupportedFunction(dstAlphaFactor) == false)
            {
                throw new ArgumentException("not supported blending function " + dstAlphaFactor, "dstAlphaFactor");
            }

            // Blend enabled
            mEnabled = true;

            // Store RGB separate equation
            mRgbEquation = rgbEquation;
            // Store alpha separate equation
            mAlphaEquation = alphaEquation;

            // Store rgb separate function
            mRgbSrcFactor = srcRgbFactor;
            mRgbDstFactor = dstRgbFactor;
            // Store alpha separate function
            mAlphaSrcFactor = srcAlphaFactor;
            mAlphaDstFactor = dstAlphaFactor;
            // Store blend color
            mBlendColor = constColor;

            if (EquationSeparated && !GraphicsContext.CurrentCaps.GlExtensions.BlendEquationSeparate_EXT)
            {
                throw new InvalidOperationException("not supported separated blending equations");
            }
            if (FunctionSeparated && !GraphicsContext.CurrentCaps.GlExtensions.BlendFuncSeparate_EXT)
            {
                throw new InvalidOperationException("not supported separated blending functions");
            }
        }
Exemplo n.º 14
0
        public void ColorRGBAF_TestConstructor1()
        {
            float r = (float)NextComponent(1.0f);
            float g = (float)NextComponent(1.0f);
            float b = (float)NextComponent(1.0f);

            ColorRGBAF v = new ColorRGBAF(r, g, b);

            Assert.AreEqual(r, v.r);
            Assert.AreEqual(g, v.g);
            Assert.AreEqual(b, v.b);
            Assert.AreEqual(1.0f, v.a);
        }
Exemplo n.º 15
0
        /// <summary>
        /// Convert a <see cref="Single[]"/> to <see cref="ColorRGBAF[]"/>.
        /// </summary>
        /// <param name="array">
        /// The <see cref="Single[]"/> to be converted.
        /// </param>
        /// <returns>
        /// It returns the <see cref="ColorRGBAF[]"/> equivalent to <paramref name="array"/>.
        /// </returns>
        public static ColorRGBAF[] ToColorRGBAF(this float[] array)
        {
            int structArrayLength = array.Length / 4;

            ColorRGBAF[] structArray = new ColorRGBAF[structArrayLength];

            for (int i = 0, j = 0; i < structArrayLength; i++, j += 4)
            {
                structArray[i] = new ColorRGBAF(array[j + 0], array[j + 1], array[j + 2], array[j + 3]);
            }

            return(structArray);
        }
Exemplo n.º 16
0
        public void ColorRGBF_CastToRGBA()
        {
            float r = (float)NextComponent(1.0f);
            float g = (float)NextComponent(1.0f);
            float b = (float)NextComponent(1.0f);

            ColorRGBF  v     = new ColorRGBF(r, g, b);
            ColorRGBAF vRGBA = v;

            Assert.AreEqual(v.Red, vRGBA.Red);
            Assert.AreEqual(v.Green, vRGBA.Green);
            Assert.AreEqual(v.Blue, vRGBA.Blue);
            Assert.AreEqual(1.0f, vRGBA.Alpha);
        }
Exemplo n.º 17
0
        /// <summary>
        /// Draw a character sequence.
        /// </summary>
        /// <param name="ctx">
        /// The <see cref="GraphicsContext"/> used for drawing.
        /// </param>
        /// <param name="modelview">
        /// The <see cref="Matrix4x4"/> the model-view-projection matrix for the first character of <paramref name="s"/>.
        /// </param>
        /// <param name="color">
        /// The <see cref="ColorRGBAF"/> that specifies the glyph color.
        /// </param>
        /// <param name="s">
        /// A <see cref="String"/> that specifies the characters for be drawn.
        /// </param>
        public override void DrawString(GraphicsContext ctx, Matrix4x4 modelview, ColorRGBAF color, string s)
        {
            // Draw the string
            DrawStringCore(ctx, modelview, color, s);

            // Shadow effect
            if (_FxShadow != null)
            {
                ModelMatrix shadowModel = new ModelMatrix(modelview);

                shadowModel.Translate(_FxShadow.Offset);

                DrawStringCore(ctx, shadowModel, _FxShadow.Color, s);
            }
        }
Exemplo n.º 18
0
 /// <summary>
 /// Draw a character sequence (base method).
 /// </summary>
 /// <param name="ctx">
 /// The <see cref="GraphicsContext"/> used for drawing.
 /// </param>
 /// <param name="color">
 /// The <see cref="ColorRGBAF"/> that specifies the glyph color.
 /// </param>
 /// <param name="s">
 /// A <see cref="String"/> that specifies the characters for be drawn.
 /// </param>
 private void DrawStringCore(GraphicsContext ctx, TextureArray2d texture, ColorRGBAF color, List <GlyphModelType> glyphInstances)
 {
     if (ctx.Extensions.InstancedArrays)
     {
         DrawStringCore_InstancedArrays(ctx, texture, color, glyphInstances);
     }
     else if (ctx.Extensions.DrawInstanced_ARB)
     {
         DrawStringCore_Instanced(ctx, texture, color, glyphInstances);
     }
     else
     {
         DrawStringCore_Compatibility(ctx, texture, color, glyphInstances);
     }
 }
Exemplo n.º 19
0
        public void ColorRGBAF_CastToVertex4()
        {
            float r = (float)NextComponent(1.0f);
            float g = (float)NextComponent(1.0f);
            float b = (float)NextComponent(1.0f);
            float a = (float)NextComponent(1.0f);

            ColorRGBAF v      = new ColorRGBAF(r, g, b, a);
            Vertex4f   vArray = v;

            Assert.AreEqual(r, vArray.x);
            Assert.AreEqual(g, vArray.y);
            Assert.AreEqual(b, vArray.z);
            Assert.AreEqual(a, vArray.w);
        }
Exemplo n.º 20
0
        public void ColorRGBAF_TestConstructor2()
        {
            Random random = new Random();
            float  r      = (float)NextComponent(random, 1.0f);
            float  g      = (float)NextComponent(random, 1.0f);
            float  b      = (float)NextComponent(random, 1.0f);
            float  a      = (float)NextComponent(random, 1.0f);

            ColorRGBAF v = new ColorRGBAF(r, g, b, a);

            Assert.AreEqual(r, v.r);
            Assert.AreEqual(g, v.g);
            Assert.AreEqual(b, v.b);
            Assert.AreEqual(a, v.a);
        }
Exemplo n.º 21
0
        public void ColorRGBAF_CastToArray()
        {
            float r = (float)NextComponent(1.0f);
            float g = (float)NextComponent(1.0f);
            float b = (float)NextComponent(1.0f);
            float a = (float)NextComponent(1.0f);

            ColorRGBAF v = new ColorRGBAF(r, g, b, a);

            float[] vArray = v;

            Assert.AreEqual(4, vArray.Length);
            Assert.AreEqual(r, vArray[0]);
            Assert.AreEqual(g, vArray[1]);
            Assert.AreEqual(b, vArray[2]);
            Assert.AreEqual(a, vArray[3]);
        }
Exemplo n.º 22
0
        public void ColorRGBAF_Multiply()
        {
            float r = (float)NextComponent(1.0f);
            float g = (float)NextComponent(1.0f);
            float b = (float)NextComponent(1.0f);
            float a = (float)NextComponent(1.0f);

            ColorRGBAF v = new ColorRGBAF(r, g, b, a);
            ColorRGBAF c = v * 0.5f;

            c = c * 2.0f;

            Assert.AreEqual(c.r, v.r, 1.0);
            Assert.AreEqual(c.g, v.g, 1.0);
            Assert.AreEqual(c.b, v.b, 1.0);
            Assert.AreEqual(c.a, v.a, 1.0);
        }
Exemplo n.º 23
0
        public void ColorRGBAF_CastFromColor()
        {
            const double Epsilon = 1e-2;

            double r = NextComponent(1.0);
            double g = NextComponent(1.0);
            double b = NextComponent(1.0);
            double a = NextComponent(1.0);

            Color c = Color.FromArgb((int)(a * byte.MaxValue), (int)(r * byte.MaxValue), (int)(g * byte.MaxValue), (int)(b * byte.MaxValue));

            ColorRGBAF v = (ColorRGBAF)c;

            Assert.AreEqual((float)r, v[0], Epsilon);
            Assert.AreEqual((float)g, v[1], Epsilon);
            Assert.AreEqual((float)b, v[2], Epsilon);
            Assert.AreEqual((float)a, v[3], Epsilon);
        }
Exemplo n.º 24
0
        /// <summary>
        /// Merge this state with another one.
        /// </summary>
        /// <param name="state">
        /// A <see cref="IGraphicsState"/> having the same <see cref="StateIdentifier"/> of this state.
        /// </param>
        public override void Merge(IGraphicsState state)
        {
            if (state == null)
            {
                throw new ArgumentNullException("state");
            }

            BlendState otherState = state as BlendState;

            if (otherState == null)
            {
                throw new ArgumentException("not a BlendState", "state");
            }

            mEnabled        = otherState.mEnabled;
            mRgbEquation    = otherState.mRgbEquation;
            mAlphaEquation  = otherState.mAlphaEquation;
            mRgbSrcFactor   = otherState.mRgbSrcFactor;
            mAlphaSrcFactor = otherState.mAlphaSrcFactor;
            mRgbDstFactor   = otherState.mRgbDstFactor;
            mAlphaDstFactor = otherState.mAlphaDstFactor;
            mBlendColor     = otherState.mBlendColor;
        }
Exemplo n.º 25
0
		/// <summary>
		/// Set the color used for clearing this GraphicsSurface color buffer.
		/// </summary>
		/// <param name="color">
		/// A <see cref="ColorRGBAF"/> which holds the RGBA values used for clearing
		/// this GraphicsSurface color buffer.
		/// </param>
		public void SetClearColor(ColorRGBAF color)
		{
			// Store clear color
			mClearColor = color;
		}
 /// <summary>
 /// Set uniform state variable (variant type variable)
 /// </summary>
 /// <param name="ctx">
 /// A <see cref="GraphicsContext"/> used for operations.
 /// </param>
 /// <param name="uniformName">
 /// A <see cref="String"/> that specify the variable name in the shader source.
 /// </param>
 /// <param name="v">
 /// A <see cref="ColorRGBAF"/> holding the uniform variabile data.
 /// </param>
 public void SetVariantUniform(GraphicsContext ctx, string uniformName, ColorRGBAF v)
 {
     SetVariantUniform(ctx, uniformName, v.r, v.g, v.b, v.a);
 }
Exemplo n.º 27
0
 /// <summary>
 /// Set the color used for clearing this GraphicsSurface color buffer.
 /// </summary>
 /// <param name="color">
 /// A <see cref="ColorRGBAF"/> which holds the RGBA values used for clearing
 /// this GraphicsSurface color buffer.
 /// </param>
 public void SetClearColor(ColorRGBAF color)
 {
     // Store clear color
     mClearColor = color;
 }
Exemplo n.º 28
0
        /// <summary>
        /// Draw a character sequence.
        /// </summary>
        /// <param name="ctx">
        /// The <see cref="GraphicsContext"/> used for drawing.
        /// </param>
        /// <param name="modelview">
        /// The <see cref="Matrix4x4"/> the model-view-projection matrix for the first character of <paramref name="s"/>.
        /// </param>
        /// <param name="color">
        /// The <see cref="ColorRGBAF"/> that specifies the glyph color.
        /// </param>
        /// <param name="s">
        /// A <see cref="String"/> that specifies the characters for be drawn.
        /// </param>
        private void DrawStringCore(GraphicsContext ctx, Matrix4x4 modelview, ColorRGBAF color, string s)
        {
            ModelMatrix charModel = new ModelMatrix(modelview);

            ctx.Bind(_FontProgram);

            _FontProgram.SetUniform(ctx, "glo_UniformColor", color);

            if (ctx.Extensions.ShaderDrawParameters_ARB)
            {
                List <VertexArrayObject.IElement> glyphElements = new List <VertexArrayObject.IElement>();
                int drawInstanceId = 0;

                foreach (char c in s)
                {
                    Glyph glyph;

                    if (_Glyphs.TryGetValue(c, out glyph) == false)
                    {
                        continue;
                    }

                    if (glyph.ElementIndex >= 0)
                    {
                        // Collect draw instance element
                        glyphElements.Add(_VertexArrays.GetElementArray(glyph.ElementIndex));
                        // Set model-view
                        _FontProgram.SetUniform(ctx, "glo_CharModelViewProjection[" + drawInstanceId + "]", charModel);
                        // Next instance
                        drawInstanceId++;
                    }
                    // Move next
                    charModel.Translate(glyph.GlyphSize.Width, 0.0f);
                }

                // Draw using Multi-Draw primitive
                VertexArrayObject.IElement multiElement = _VertexArrays.CombineArrayElements(glyphElements);

                _VertexArrays.Draw(ctx, _FontProgram, multiElement);
            }
            else
            {
                foreach (char c in s)
                {
                    Glyph glyph;

                    if (_Glyphs.TryGetValue(c, out glyph) == false)
                    {
                        continue;
                    }

                    if (glyph.ElementIndex >= 0)
                    {
                        // Set model-view
                        _FontProgram.SetUniform(ctx, "glo_ModelViewProjection", charModel);
                        // Rasterize it
                        _VertexArrays.Draw(ctx, _FontProgram, glyph.ElementIndex);
                    }
                    // Move next
                    charModel.Translate(glyph.GlyphSize.Width, 0.0f);
                }
            }
        }
Exemplo n.º 29
0
		/// <summary>
		/// Construct a BlendState with separated RGB/Alpha functions.
		/// </summary>
		/// <param name="rgbEquation">
		/// A <see cref="BlendEquationModeEXT"/> flag indicating which equation to used for blending RGB color components.
		/// </param>
		/// <param name="alphaEquation">
		/// A <see cref="BlendEquationModeEXT"/> flag indicating which equation to used for blending Alpha color component.
		/// </param>
		/// <param name="srcRgbFactor">
		/// A <see cref="BlendingFactorSrc"/> that specify the scaling factors applied to the source color (alpha component excluded).
		/// </param>
		/// <param name="srcAlphaFactor">
		/// A <see cref="BlendingFactorSrc"/> that specify the scaling factors applied to only the source alpha component.
		/// </param>
		/// <param name="dstRgbFactor">
		/// A <see cref="BlendingFactorDest"/> that specify the scaling factors applied to the destination color (alpha component excluded).
		/// </param>
		/// <param name="dstAlphaFactor">
		/// A <see cref="BlendingFactorDest"/> that specify the scaling factors applied to only the destination alpha component.
		/// </param>
		/// <param name="constColor">
		/// A <see cref="ColorRGBAF"/> that specify the constant color used in blending functions.
		/// </param>
		public BlendState(BlendEquationModeEXT rgbEquation, BlendEquationModeEXT alphaEquation, BlendingFactorSrc srcRgbFactor, BlendingFactorSrc srcAlphaFactor, BlendingFactorDest dstRgbFactor, BlendingFactorDest dstAlphaFactor, ColorRGBAF constColor)
		{
			if (IsSupportedEquation(rgbEquation) == false)
				throw new ArgumentException("not supported blending equation " + srcRgbFactor, "rgbEquation");
			if (IsSupportedEquation(alphaEquation) == false)
				throw new ArgumentException("not supported blending equation " + alphaEquation, "rgbEquation");
			if (IsSupportedFunction(srcRgbFactor) == false)
				throw new ArgumentException("not supported blending function " + srcRgbFactor, "srcRgbFactor");
			if (IsSupportedFunction(srcAlphaFactor) == false)
				throw new ArgumentException("not supported blending function " + srcAlphaFactor, "srcAlphaFactor");
			if (IsSupportedFunction(dstRgbFactor) == false)
				throw new ArgumentException("not supported blending function " + dstRgbFactor, "dstRgbFactor");
			if (IsSupportedFunction(dstAlphaFactor) == false)
				throw new ArgumentException("not supported blending function " + dstAlphaFactor, "dstAlphaFactor");

			// Blend enabled
			mEnabled = true;

			// Store RGB separate equation
			mRgbEquation = rgbEquation;
			// Store alpha separate equation
			mAlphaEquation = alphaEquation;

			// Store rgb separate function
			mRgbSrcFactor = srcRgbFactor;
			mRgbDstFactor = dstRgbFactor;
			// Store alpha separate function
			mAlphaSrcFactor = srcAlphaFactor;
			mAlphaDstFactor = dstAlphaFactor;
			// Store blend color
			mBlendColor = constColor;

			if (EquationSeparated && !GraphicsContext.CurrentCaps.GlExtensions.BlendEquationSeparate_EXT)
				throw new InvalidOperationException("not supported separated blending equations");
			if (FunctionSeparated && !GraphicsContext.CurrentCaps.GlExtensions.BlendFuncSeparate_EXT)
				throw new InvalidOperationException("not supported separated blending functions");
		}
Exemplo n.º 30
0
		/// <summary>
		/// Construct the current BlendState.
		/// </summary>
		/// <param name="ctx">
		/// A <see cref="GraphicsContext"/> defining this GraphicsState.
		/// </param>
		public BlendState(GraphicsContext ctx)
		{
			if (ctx == null)
				throw new ArgumentNullException("ctx");

			int blendRgbEquation, blendAlphaEquation;
			int blendRgbSrcFunct, blendAlphaSrcFunct;
			int blendRgbDstFunct, blendAlphaDstFunct;

			// Blend enabled
			mEnabled = Gl.IsEnabled(EnableCap.Blend);

			if (ctx.Caps.GlExtensions.BlendEquationSeparate_EXT) {
				// Blend equation (RGB)
				Gl.Get(Gl.BLEND_EQUATION_RGB, out blendRgbEquation);
				// Blend equation (Alpha)
				Gl.Get(Gl.BLEND_EQUATION_ALPHA, out blendAlphaEquation);
			} else {
				if (ctx.Caps.GlExtensions.BlendMinmax_EXT) {
					// Blend equation (RGBA)
					Gl.Get(GetPName.BlendEquation, out blendRgbEquation);
					// Alpha equation is the same for RGB!
					blendAlphaEquation = blendRgbEquation;
				} else {
					blendRgbEquation = blendAlphaEquation = (int)BlendEquationModeEXT.FuncAdd;
				}
			}

			if (ctx.Caps.GlExtensions.BlendFuncSeparate_EXT) {
				// Blend source function (RGB)
				Gl.Get(Gl.BLEND_SRC_RGB, out blendRgbSrcFunct);
				// Blend source function (Alpha)
				Gl.Get(Gl.BLEND_SRC_ALPHA, out blendAlphaSrcFunct);
				// Blend destination function (RGB)
				Gl.Get(Gl.BLEND_DST_RGB, out blendRgbDstFunct);
				// Blend destination function (Alpha)
				Gl.Get(Gl.BLEND_DST_ALPHA, out blendAlphaDstFunct);
			} else {
				// Blend source function (RGBA)
				Gl.Get(GetPName.BlendSrc, out blendRgbSrcFunct);
				blendAlphaSrcFunct = blendRgbSrcFunct;
				// Blend destination function (RGBA)
				Gl.Get(GetPName.BlendDst, out blendRgbDstFunct);
				blendAlphaDstFunct = blendRgbDstFunct;
			}

			// Store blending equation
			mRgbEquation = (BlendEquationModeEXT)blendRgbEquation;
			mAlphaEquation = (BlendEquationModeEXT)blendAlphaEquation;

			// Store blending function
			mRgbSrcFactor = (BlendingFactorSrc)blendRgbSrcFunct;
			mAlphaSrcFactor = (BlendingFactorSrc)blendAlphaSrcFunct;
			mRgbDstFactor = (BlendingFactorDest)blendRgbDstFunct;
			mAlphaDstFactor = (BlendingFactorDest)blendAlphaDstFunct;

			// Store blend color
			if (ctx.Caps.GlExtensions.BlendColor_EXT) {
				float[] blendColor = new float[4];

				Gl.Get(GetPName.BlendColor, blendColor);

				mBlendColor = new ColorRGBAF(blendColor[0], blendColor[1], blendColor[2], blendColor[3]);
			}
		}
Exemplo n.º 31
0
		/// <summary>
		/// Merge this state with another one.
		/// </summary>
		/// <param name="state">
		/// A <see cref="IGraphicsState"/> having the same <see cref="StateIdentifier"/> of this state.
		/// </param>
		public override void Merge(IGraphicsState state)
		{
			if (state == null)
				throw new ArgumentNullException("state");

			BlendState otherState = state as BlendState;

			if (otherState == null)
				throw new ArgumentException("not a BlendState", "state");

			mEnabled = otherState.mEnabled;
			mRgbEquation = otherState.mRgbEquation;
			mAlphaEquation = otherState.mAlphaEquation;
			mRgbSrcFactor = otherState.mRgbSrcFactor;
			mAlphaSrcFactor = otherState.mAlphaSrcFactor;
			mRgbDstFactor = otherState.mRgbDstFactor;
			mAlphaDstFactor = otherState.mAlphaDstFactor;
			mBlendColor = otherState.mBlendColor;
		}
Exemplo n.º 32
0
		/// <summary>
		/// Construct a BlendState with unified RGB/Alpha function.
		/// </summary>
		/// <param name="equation">
		/// A <see cref="BlendEquationModeEXT"/> flag indicating which equation to used for blending.
		/// </param>
		/// <param name="srcFactor">
		/// A <see cref="BlendingFactorSrc"/> that specify the scaling factors applied to the source color (including alpha).
		/// </param>
		/// <param name="dstFactor">
		/// A <see cref="BlendingFactorDest"/> that specify the scaling factors applied to the destination color (including alpha).
		/// </param>
		/// <param name="constColor">
		/// A <see cref="ColorRGBAF"/> that specify the constant color used in blending functions.
		/// </param>
		public BlendState(BlendEquationModeEXT equation, BlendingFactorSrc srcFactor, BlendingFactorDest dstFactor, ColorRGBAF constColor)
			: this(equation, equation, srcFactor, srcFactor, dstFactor, dstFactor, constColor)
		{
			
		}
 /// <summary>
 /// Set uniform state variable (variant type variable)
 /// </summary>
 /// <param name="ctx">
 /// A <see cref="GraphicsContext"/> used for operations.
 /// </param>
 /// <param name="uniformName">
 /// A <see cref="String"/> that specify the variable name in the shader source.
 /// </param>
 /// <param name="v">
 /// A <see cref="ColorRGBAF"/> holding the uniform variabile data.
 /// </param>
 public void SetVariantUniform(GraphicsContext ctx, string uniformName, ColorRGBAF v)
 {
     SetVariantUniform(ctx, uniformName, v.Red, v.Green, v.Blue, v.Alpha);
 }
Exemplo n.º 34
0
        /// <summary>
        /// Draw a character sequence (base method).
        /// </summary>
        /// <param name="ctx">
        /// The <see cref="GraphicsContext"/> used for drawing.
        /// </param>
        /// <param name="color">
        /// The <see cref="ColorRGBAF"/> that specifies the glyph color.
        /// </param>
        /// <param name="s">
        /// A <see cref="String"/> that specifies the characters for be drawn.
        /// </param>
        private void DrawStringCore_InstancedArrays(GraphicsContext ctx, TextureArray2d texture, ColorRGBAF color, List <GlyphModelType> glyphInstances)
        {
            ctx.Bind(_FontProgram);

            // Set uniforms
            _FontProgram.SetUniform(ctx, "glo_UniformColor", color);
            _FontProgram.SetUniform(ctx, "glo_FontGlyph", texture);

            // Rasterize it
            State.BlendState.AlphaBlending.Apply(ctx, _FontProgram);

            _VertexArrays.DrawInstanced(ctx, _FontProgram, (uint)glyphInstances.Count);
        }
Exemplo n.º 35
0
        /// <summary>
        /// Draw a character sequence (base method).
        /// </summary>
        /// <param name="ctx">
        /// The <see cref="GraphicsContext"/> used for drawing.
        /// </param>
        /// <param name="modelview">
        /// The <see cref="Matrix4x4"/> the model-view-projection matrix for the first character of <paramref name="s"/>.
        /// </param>
        /// <param name="color">
        /// The <see cref="ColorRGBAF"/> that specifies the glyph color.
        /// </param>
        /// <param name="s">
        /// A <see cref="String"/> that specifies the characters for be drawn.
        /// </param>
        private void DrawStringCore_Instanced(GraphicsContext ctx, TextureArray2d texture, ColorRGBAF color, List <GlyphModelType> glyphsInstances)
        {
            ctx.Bind(_FontProgram);

            // Set uniforms
            _FontProgram.SetUniform(ctx, "glo_UniformColor", color);
            _FontProgram.SetUniform(ctx, "glo_FontGlyph", texture);

            // Set instances
            if (_GlyphUniformBuffer == null)
            {
                // Set instances
                for (int i = 0; i < glyphsInstances.Count; i++)
                {
                    string structName = "glo_Glyphs[" + i + "]";

                    _FontProgram.SetUniform(ctx, structName + ".ModelViewProjection", glyphsInstances[i].ModelViewProjection);
                    _FontProgram.SetUniform(ctx, structName + ".VertexParams", glyphsInstances[i].VertexParams);
                    _FontProgram.SetUniform(ctx, structName + ".TexParams", glyphsInstances[i].TexParams);
                }
            }
            else
            {
                // Bind uniform block
                // Note: already updated by DrawString
                _FontProgram.SetUniformBlock(ctx, "Glyphs", _GlyphUniformBuffer);
            }

            // Rasterize it
            State.BlendState.AlphaBlending.Apply(ctx, _FontProgram);

            _VertexArrays.DrawInstanced(ctx, _FontProgram, (uint)glyphsInstances.Count);
        }
Exemplo n.º 36
0
        /// <summary>
        /// Draw a character sequence (base method).
        /// </summary>
        /// <param name="ctx">
        /// The <see cref="GraphicsContext"/> used for drawing.
        /// </param>
        /// <param name="color">
        /// The <see cref="ColorRGBAF"/> that specifies the glyph color.
        /// </param>
        /// <param name="s">
        /// A <see cref="String"/> that specifies the characters for be drawn.
        /// </param>
        private void DrawStringCore_Compatibility(GraphicsContext ctx, TextureArray2d texture, ColorRGBAF color, List <GlyphModelType> glyphsInstances)
        {
            ctx.Bind(_FontProgram);

            // Set uniforms
            _FontProgram.SetUniform(ctx, "glo_UniformColor", color);
            _FontProgram.SetUniform(ctx, "glo_FontGlyph", texture);

            // Rasterize it
            State.BlendState.AlphaBlending.Apply(ctx, _FontProgram);

            for (int i = 0; i < glyphsInstances.Count; i++)
            {
                _FontProgram.SetUniform(ctx, "glo_ModelViewProjection", glyphsInstances[i].ModelViewProjection);
                _FontProgram.SetUniform(ctx, "glo_VertexParams", glyphsInstances[i].VertexParams);
                _FontProgram.SetUniform(ctx, "glo_TexParams", glyphsInstances[i].TexParams);

                _VertexArrays.Draw(ctx, _FontProgram);
            }
        }
		/// <summary>
		/// Set uniform state variable (variant type variable)
		/// </summary>
		/// <param name="ctx">
		/// A <see cref="GraphicsContext"/> used for operations.
		/// </param>
		/// <param name="uniformName">
		/// A <see cref="String"/> that specify the variable name in the shader source.
		/// </param>
		/// <param name="v">
		/// A <see cref="ColorRGBAF"/> holding the uniform variabile data.
		/// </param>
		public void SetVariantUniform(GraphicsContext ctx, string uniformName, ColorRGBAF v)
		{
			SetVariantUniform(ctx, uniformName, v.Red, v.Green, v.Blue, v.Alpha);
		}