Ejemplo n.º 1
0
        public override void DrawWireframe(Vector4 color, float tickness = 0.02F)
        {
            //Mesh / Sprite design is a little "spaghetti" dish
            //In order to make DrawWireframe compliant with Sprite
            //has been applied the following workaround:
            //1. Make a backup of Sprite specific configuration
            //2. Apply Mesh configuration
            //3. Execute DrawWireframe call
            //4. Restore Sprite configuration

            //1. Sprite Backup
            Shader          shaderBkp = shader;
            ShaderSetupHook hookBkp   = shaderSetupHook;

            //2. Set Mesh configuration
            shader = Mesh.simpleShader;
            shader.Use();
            hasVertexColors = true;
            shaderSetupHook = null;

            //3. Call
            base.DrawWireframe(color, tickness);

            //4. Restore backup
            hasVertexColors = false;
            shader          = shaderBkp;
            shader.Use();
            shaderSetupHook = hookBkp;
        }
Ejemplo n.º 2
0
        // simple draw without textures (useful for subclasses)
        public void Draw(ShaderSetupHook hook = null)
        {
            if (this.v == null)
            {
                return;
            }
            this.Bind();
            // upload fake uvs (if required) to avoid crashes
            if (this.uv == null)
            {
                this.uv = new float[this.v.Length];
                this.UpdateUV();
            }
            // upload fake vcs (if required) to avoid crashes
            if (this.vc == null && this.hasVertexColors)
            {
                this.vc = new float[(this.v.Length / numberOfAxis) * 4];
                this.UpdateVertexColor();
            }
            // clear current texture
            Graphics.BindTextureToUnit(0, 0);
            if (this.requireUseTexture)
            {
                this.shader.SetUniform("use_texture", -1f);
            }

            this.shader.Use();
            if (hook != null)
            {
                hook(this);
            }
            else if (this.shaderSetupHook != null)
            {
                this.shaderSetupHook(this);
            }

            this.ApplyMatrix();
            if (instances <= 1)
            {
                Graphics.DrawArrays(this.v.Length / numberOfAxis);
            }
            else
            {
                Graphics.DrawArraysInstanced(this.v.Length / numberOfAxis, instances);
            }
        }
Ejemplo n.º 3
0
        // simple draw without textures (useful for subclasses)
        public void Draw(ShaderSetupHook hook = null)
        {
            if (this.v == null)
                return;
            // upload fake uvs (if required) to avoid crashes
            if (this.uv == null)
            {
                this.uv = new float[this.v.Length];
                this.UpdateUV();
            }
            // upload fake vcs (if required) to avoid crashes
            if (this.vc == null && this.hasVertexColors)
            {
                this.vc = new float[this.v.Length * 2];
                this.UpdateVertexColor();
            }
            this.Bind();
            // clear current texture
            GL.ActiveTexture(TextureUnit.Texture0);
            GL.BindTexture(TextureTarget.Texture2D, 0);
            if (this.requireUseTexture)
                this.shader.SetUniform("use_texture", -1f);

            this.shader.Use();
            if (hook != null)
            {
                hook(this);
            }
            else if (this.shaderSetupHook != null)
            {
                this.shaderSetupHook(this);
            }

            this.ApplyMatrix();
            if (instances <= 1)
            {
            #if !__MOBILE__
                GL.DrawArrays(PrimitiveType.Triangles, 0, this.v.Length / 2);
            #else
                GL.DrawArrays(BeginMode.Triangles, 0, this.v.Length / 2);
            #endif
            }
            else
            {
                GL.DrawArraysInstanced(PrimitiveType.Triangles, 0, this.v.Length / 2, instances);
            }
        }