Exemple #1
0
 public void BindTexture(BindTextureData value)
 {
     BindTexture(ref value);
 }
Exemple #2
0
        //public unsafe void SetUniform( string name, Vec4F value )
        //{
        //	var uniform = GpuProgramManager.Instance.RegisterUniform( name, value.GetType(), 1 );
        //	Bgfx.SetUniform( uniform, &value );

        //	//var u = new Uniform( "u_test", UniformType.Vector4 );
        //	//Log.Info( u.ToString() );

        //	//Vec4F r = new Vec4F( 1, 0, 0, 1 );
        //	//Bgfx.SetUniform( u, &r );
        //	//Bgfx.SetUniform( GpuProgramManager.r, &r );
        //}

        //public unsafe void SetUniform( string name, Vec4F[] value )
        //{
        //}

        //static ParameterContainer.ParameterItem GetValueFromContainers( List<ParameterContainer> allContainers, string name )
        //{
        //	for( int n = allContainers.Count - 1; n >= 0; n-- )
        //	{
        //		ParameterContainer c = allContainers[ n ];
        //		ParameterContainer.ParameterItem item = c.GetByName( name );
        //		if( item != null )
        //			return item;
        //	}
        //	return null;
        //}

        public void BindTexture(ref BindTextureData value)
        {
            //!!!!new
            if (value.Texture == null)
            {
                Log.Fatal("ViewportRenderingContext: BindTexture: value.Texture == null.");
            }

            //sampler settings
            TextureFlags flags = TextureFlags.None;

            //adressing mode
            switch (value.AddressingMode)
            {
            case TextureAddressingMode.Mirror:
                flags |= TextureFlags.MirrorU | TextureFlags.MirrorV | TextureFlags.MirrorW;
                break;

            case TextureAddressingMode.Clamp:
                flags |= TextureFlags.ClampU | TextureFlags.ClampV | TextureFlags.ClampW;
                break;

            case TextureAddressingMode.Border:
                flags |= TextureFlags.BorderU | TextureFlags.BorderV | TextureFlags.BorderW;
                break;
            }

            //filtering
            if (value.FilteringMin == FilterOption.Point)
            {
                flags |= TextureFlags.MinFilterPoint;
            }
            else if (value.FilteringMin == FilterOption.Anisotropic)
            {
                flags |= TextureFlags.MinFilterAnisotropic;
            }

            if (value.FilteringMag == FilterOption.Point)
            {
                flags |= TextureFlags.MagFilterPoint;
            }
            else if (value.FilteringMag == FilterOption.Anisotropic)
            {
                flags |= TextureFlags.MagFilterAnisotropic;
            }

            if (value.FilteringMip == FilterOption.Point)
            {
                flags |= TextureFlags.MipFilterPoint;
            }
            //else if( value.filteringMip == FilterOption.Anisotropic )
            //	flags |= TextureFlags.MipFilterAnisotropic;

            flags |= value.AdditionFlags;
            //if( value.texture?.Result?.SourceFormat == PixelFormat.Float32R &&
            //	value.texture?.Result?.ResultSize.X == value.texture?.Result?.ResultSize.Y )
            //	flags |= TextureFlags.BGFX_SAMPLER_COMPARE_LEQUAL;
            //if( value.texture?.Result?.ResultFormat == PixelFormat.Float32R &&
            //	value.texture?.Result?.ResultSize.X == value.texture?.Result?.ResultSize.Y ) // shadow textures need cmp flag for cmp samplers
            //	flags |= TextureFlags.BGFX_SAMPLER_COMPARE_LEQUAL;

            //!!!!impl border color
            //!!!!еще есть настройки MSAA

            var realObject = value.Texture?.Result?.RealObject;

            if (realObject != null)
            {
                Bgfx.SetTexture((byte)value.TextureUnit, Uniform.Invalid, realObject, flags);
            }
        }