Пример #1
0
        /// <summary>
        /// Draw a sprite at a position with a size
        /// </summary>
        /// <param name="sprite"></param>
        /// <param name="position"></param>
        /// <param name="size"></param>
        /// <param name="color"></param>
        /// <param name="blendType"></param>
        /// <exception cref="InvalidOperationException"></exception>
        /// <exception cref="NullReferenceException"></exception>
        public void DrawSprite(Sprite sprite, Vector3 <float> position, Vector2 <float> size, VulpineLib.Util.Color color, BlendType blendType)
        {
            Assert();

            if (!Drawing)
            {
                throw new InvalidOperationException("Not drawing; Begin() must be called first");
            }
            var spriteSet = sprite.SpriteSet;

            // If this Sprite's SpriteSet is not the same as the cached previous one, then
            //  update the cache to the new one and bind the new one's texture
            if (spriteSet.Texture != LastSpriteSet?.Texture)
            {
                if (spriteSet.Texture == null)
                {
                    throw new NullReferenceException($"Sprite's SpriteSet ({sprite.SpriteSet.Name}) has a null Texture");
                }
                spriteSet.Texture.BindDiffuse();
                LastSpriteSet = spriteSet;
            }
            // If this Sprite is not the same as the cached previous one, then
            //  update the cache to the new one and set the relevant shader uniforms
            if (sprite != LastSprite !)
            {
                sprite.ShaderProgram.Bind();
                sprite.ShaderProgram.SetTextureSource(sprite.TopLeftCoord, sprite.SizeCoord);
                LastSprite = sprite;
            }
            // Bind the BlendType
            blendType.Bind();
            // Set the model color
            sprite.ShaderProgram.SetModelColor(color);
            // Set the model position and scale
            sprite.ShaderProgram.SetPositionScale(
                position,
                new Vector3 <float>(size.X, size.Y, 0f)
                );
            // Draw 4 vertices
            GL.DrawArrays(PrimitiveType.TriangleStrip, 0, 4);
            State.CheckError();
        }
Пример #2
0
        /// <summary>
        /// Draw a mesh
        /// </summary>
        /// <param name="mesh"></param>
        /// <param name="transform"></param>
        /// <param name="color"></param>
        /// <param name="blendType"></param>
        public void DrawMesh(GPUMesh <T> mesh, ref Matrix4 <float> transform, VulpineLib.Util.Color color, BlendType blendType)
        {
            Assert();

            if (!Drawing)
            {
                throw new InvalidOperationException("Not drawing; Begin() must be called first");
            }
            if (mesh != LastMesh !)
            {
                mesh.Bind();
                LastMesh = mesh;
            }
            // Bind the BlendType
            blendType.Bind();
            // Set the model color
            mesh.ShaderProgram.SetModelColor(color);
            // Set the model matrix
            mesh.ShaderProgram.SetModelMatrix(ref transform);
            // Draw
            mesh.Draw();
            State.CheckError();
        }