Unbind() public méthode

Stop using this program.
public Unbind ( ) : void
Résultat void
        /// <summary>
        ///
        /// </summary>
        /// <param name="program"></param>
        /// <param name="vaos"></param>
        /// <param name="switchList"></param>
        public void Draw(ShaderProgram program, VertexArrayObject[] vaos, GLSwitchList switchList = null)
        {
            // 绑定shader
            program.Bind();
            program.PushUniforms(); // push new uniform values to GPU side.

            if (switchList != null)
            {
                switchList.On();
            }

            this.Bind();
            foreach (var vao in vaos)
            {
                DrawMode mode = vao.DrawCommand.CurrentMode;
                this.Begin(mode);
                vao.Bind();
                this.Draw(mode);
                vao.Unbind();
                this.End();
            }
            this.Unbind();

            if (switchList != null)
            {
                switchList.Off();
            }

            // 解绑shader
            program.Unbind();
        }
Exemple #2
0
        /// <summary>
        ///
        /// </summary>
        /// <param name="program"></param>
        /// <param name="vao"></param>
        /// <param name="stateList"></param>
        public void Draw(ShaderProgram program, VertexArrayObject vao, GLStateList stateList = null)
        {
            // 绑定shader
            program.Bind();
            program.PushUniforms(); // push new uniform values to GPU side.

            if (stateList != null)
            {
                stateList.On();
            }

            DrawMode mode = vao.IndexBuffer.Mode;

            this.Bind();
            this.Begin(mode);
            vao.Bind();
            this.Draw(mode);
            vao.Unbind();
            this.End();
            this.Unbind();

            if (stateList != null)
            {
                stateList.Off();
            }

            // 解绑shader
            program.Unbind();
        }
Exemple #3
0
        /// <summary>
        ///
        /// </summary>
        /// <param name="controlMode">index buffer is accessable randomly or only by frame.</param>
        /// <param name="transformFeedbackObj"></param>
        public void Render(IndexBuffer.ControlMode controlMode = IndexBuffer.ControlMode.ByFrame, TransformFeedbackObject transformFeedbackObj = null)
        {
            ShaderProgram program   = this.Program;
            GLStateList   stateList = this.StateList;

            // 绑定shader
            program.Bind();
            program.PushUniforms(); // push new uniform values to GPU side.

            stateList.On();

            if (transformFeedbackObj != null)
            {
                transformFeedbackObj.Bind();
                transformFeedbackObj.Begin(this.VertexArrayObject.IndexBuffer.Mode);
                this.VertexArrayObject.Draw(controlMode);
                transformFeedbackObj.End();
                transformFeedbackObj.Unbind();
            }
            else
            {
                this.VertexArrayObject.Draw(controlMode);
            }

            stateList.Off();

            // 解绑shader
            program.Unbind();
        }
Exemple #4
0
        /// <summary>
        ///
        /// </summary>
        /// <param name="transformFeedbackObj"></param>
        public void Render(TransformFeedbackObject transformFeedbackObj = null)
        {
            ShaderProgram program = this.Program;

            // 绑定shader
            program.Bind();
            program.PushUniforms();

            this.StateList.On();

            if (transformFeedbackObj != null)
            {
                transformFeedbackObj.Bind();
                transformFeedbackObj.Begin(this.VertexArrayObject.IndexBuffer.Mode);
            }
            this.VertexArrayObject.Draw();
            if (transformFeedbackObj != null)
            {
                transformFeedbackObj.End();
                transformFeedbackObj.Unbind();
            }

            this.StateList.Off();

            // 解绑shader
            program.Unbind();
        }
Exemple #5
0
        /// <summary>
        ///
        /// </summary>
        /// <param name="controlMode">index buffer is accessable randomly or only by frame.</param>
        /// <param name="transformFeedbackObj"></param>
        public void Render(ControlMode controlMode, TransformFeedbackObject transformFeedbackObj)
        {
            ShaderProgram program   = this.Program;
            GLStateList   stateList = this.StateList;

            // 绑定shader
            program.Bind();
            program.PushUniforms(); // push new uniform values to GPU side.

            stateList.On();

            if (transformFeedbackObj != null)
            {
                transformFeedbackObj.Bind();
                foreach (var vao in this.VertexArrayObjects)
                {
                    transformFeedbackObj.Begin(vao.DrawCommand.Mode);
                    vao.Draw(controlMode);
                    transformFeedbackObj.End();
                }
                transformFeedbackObj.Unbind();
            }
            else
            {
                foreach (var vao in this.VertexArrayObjects)
                {
                    vao.Draw(controlMode);
                }
            }

            stateList.Off();

            // 解绑shader
            program.Unbind();
        }
        private void RenderForPicking(PickingEventArgs arg, ControlMode controlMode, IDrawCommand tmpCmd)
        {
            if (!this.IsInitialized)
            {
                this.Initialize();
            }

            this.polygonModeState.Mode = arg.GeometryType.GetPolygonMode();

            ShaderProgram program = this.PickingRenderUnit.Program;

            // 绑定shader
            program.Bind();
            {
                mat4 projection = arg.Scene.Camera.GetProjectionMatrix();
                mat4 view       = arg.Scene.Camera.GetViewMatrix();
                mat4 model      = this.GetModelMatrix();
                program.glUniform("MVP", projection * view * model);
            }

            this.polygonModeState.On();
            this.lineWidthState.On();
            this.pointSizeState.On();

            PrimitiveRestartState restart = null;
            var hasIndexBuffer            = tmpCmd as IHasIndexBuffer;

            if (hasIndexBuffer != null)
            {
                restart = this.GetPrimitiveRestartState(hasIndexBuffer.IndexBufferObject.ElementType);
            }
            if (restart != null)
            {
                restart.On();
            }
            {
                var  pickable = this as IPickable;
                uint baseId   = pickable.PickingBaseId;
                foreach (var vao in this.PickingRenderUnit.VertexArrayObjects)
                {
                    program.glUniform("pickingBaseId", (int)(baseId));
                    vao.Draw(controlMode, tmpCmd);
                    baseId += (uint)vao.VertexAttributes[0].Buffer.Length;
                }
            }
            if (restart != null)
            {
                restart.Off();
            }

            this.pointSizeState.Off();
            this.lineWidthState.Off();
            this.polygonModeState.Off();

            // 解绑shader
            program.Unbind();
        }
Exemple #7
0
        private void ColorCodedRender(RenderEventArgs arg, IndexBufferPtr temporaryIndexBufferPtr = null)
        {
            UpdatePolygonMode(arg.PickingGeometryType);

            ShaderProgram program = this.Program;

            // 绑定shader
            program.Bind();
            program.SetUniform("pickingBaseId",
                               temporaryIndexBufferPtr == null ? (int)this.PickingBaseId : 0);
            UniformMat4 uniformmMVP4Picking = this.uniformmMVP4Picking;
            bool        mvpUpdated          = uniformmMVP4Picking.Updated;

            if (mvpUpdated)
            {
                uniformmMVP4Picking.SetUniform(program);
            }

            PickingSwitchesOn();
            GLSwitch primitiveRestartIndexSwitch = null;
            var      oneIndexBufferPtr           = temporaryIndexBufferPtr as OneIndexBufferPtr;

            if (oneIndexBufferPtr != null)
            {
                primitiveRestartIndexSwitch = new PrimitiveRestartSwitch(oneIndexBufferPtr);
                primitiveRestartIndexSwitch.On();
            }

            if (this.vertexArrayObject == null)
            {
                var vertexArrayObject = new VertexArrayObject(
                    this.indexBufferPtr, this.positionBufferPtr);
                vertexArrayObject.Create(arg, program);

                this.vertexArrayObject = vertexArrayObject;
            }
            //else
            {
                this.vertexArrayObject.Render(arg, program, temporaryIndexBufferPtr);
            }

            if (oneIndexBufferPtr != null)
            {
                primitiveRestartIndexSwitch.Off();
            }
            PickingSwitchesOff();

            if (mvpUpdated)
            {
                uniformmMVP4Picking.ResetUniform(program);
            }


            // 解绑shader
            program.Unbind();
        }
        //private Stack<UniformArrayVariable> uniformArrayVariableStack = new Stack<UniformArrayVariable>();
        /// <summary>
        ///
        /// </summary>
        /// <param name="arg"></param>
        protected override void DoRender(RenderEventArgs arg)
        {
            ShaderProgram program = this.Program;

            if (program == null)
            {
                return;
            }

            // 绑定shader
            program.Bind();

            SetUniformValues(program);

            SwitchesOn();

            IndexBufferPtr indexBufferPtr = this.indexBufferPtr;

            if (this.vertexArrayObject == null)
            {
                PropertyBufferPtr[] propertyBufferPtrs = this.propertyBufferPtrs;
                if (indexBufferPtr != null && propertyBufferPtrs != null)
                {
                    var vertexArrayObject = new VertexArrayObject(
                        indexBufferPtr, propertyBufferPtrs);
                    vertexArrayObject.Create(arg, program);

                    this.vertexArrayObject = vertexArrayObject;
                }
            }
            {
                VertexArrayObject vertexArrayObject = this.vertexArrayObject;
                if (vertexArrayObject != null)
                {
                    if (vertexArrayObject.IndexBufferPtr != indexBufferPtr)
                    {
                        vertexArrayObject.Render(arg, program, indexBufferPtr);
                    }
                    else
                    {
                        vertexArrayObject.Render(arg, program);
                    }
                }
            }

            SwithesOff();

            ResetUniformValues(program);

            // 解绑shader
            program.Unbind();
        }
Exemple #9
0
        private void RenderForPicking(PickingEventArgs arg, IndexBuffer tempIndexBuffer)
        {
            if (!this.IsInitialized)
            {
                this.Initialize();
            }

            this.polygonModeState.Mode = arg.GeometryType.GetPolygonMode();

            ShaderProgram program = this.PickingRenderUnit.Program;

            // 绑定shader
            program.Bind();
            program.glUniform("pickingBaseId", (int)(((IPickable)this).PickingBaseId));
            {
                mat4 projection = arg.Scene.Camera.GetProjectionMatrix();
                mat4 view       = arg.Scene.Camera.GetViewMatrix();
                mat4 model      = this.GetModelMatrix();
                program.glUniform("MVP", projection * view * model);
            }

            this.polygonModeState.On();
            this.lineWidthState.On();
            this.pointSizeState.On();

            var oneIndexBuffer = tempIndexBuffer as OneIndexBuffer;

            if (oneIndexBuffer != null)
            {
                PrimitiveRestartState glState = this.GetPrimitiveRestartState(oneIndexBuffer);
                glState.On();
                this.PickingRenderUnit.VertexArrayObject.Draw(this.ControlMode, tempIndexBuffer);
                glState.Off();
            }
            else
            {
                this.PickingRenderUnit.VertexArrayObject.Draw(this.ControlMode, tempIndexBuffer);
            }

            this.pointSizeState.Off();
            this.lineWidthState.Off();
            this.polygonModeState.Off();

            // 解绑shader
            program.Unbind();
        }
        private void RenderRender(RenderEventArgs e)
        {
            ShaderProgram program = this.shaderProgram;

            // 绑定shader
            program.Bind();

            var updatedUniforms = (from item in this.uniformVariables where item.Updated select item).ToArray();

            foreach (var item in updatedUniforms)
            {
                item.SetUniform(program);
            }

            foreach (var item in switchList)
            {
                item.On();
            }

            if (this.vertexArrayObject == null)
            {
                var vertexArrayObject = new VertexArrayObject(
                    this.indexBufferPtr, this.propertyBufferPtrs);
                vertexArrayObject.Create(e, program);

                this.vertexArrayObject = vertexArrayObject;
            }
            //else
            {
                this.vertexArrayObject.Render(e, program);
            }

            foreach (var item in switchList)
            {
                item.Off();
            }

            foreach (var item in updatedUniforms)
            {
                item.ResetUniform(program); item.Updated = false;
            }

            // 解绑shader
            program.Unbind();
        }
        private void ColorCodedRender(RenderEventArgs arg, IndexBufferPtr temporaryIndexBufferPtr = null)
        {
            UpdatePolygonMode(arg.PickingGeometryType);

            ShaderProgram program = this.Program;

            // 绑定shader
            program.Bind();
            program.SetUniform("pickingBaseId",
                               temporaryIndexBufferPtr == null ? (int)this.PickingBaseId : 0);
            UniformMat4 uniformmMVP4Picking = this.uniformmMVP4Picking;

            {
                mat4 projection = arg.Camera.GetProjectionMatrix();
                mat4 view       = arg.Camera.GetViewMatrix();
                mat4 model      = this.GetModelMatrix();
                uniformmMVP4Picking.Value = projection * view * model;
            }
            uniformmMVP4Picking.SetUniform(program);

            PickingSwitchesOn();
            GLSwitch primitiveRestartIndexSwitch = null;
            var      oneIndexBufferPtr           = temporaryIndexBufferPtr as OneIndexBufferPtr;

            if (oneIndexBufferPtr != null)
            {
                primitiveRestartIndexSwitch = new PrimitiveRestartSwitch(oneIndexBufferPtr);
                primitiveRestartIndexSwitch.On();
            }

            {
                this.vertexArrayObject.Render(arg, program, temporaryIndexBufferPtr);
            }

            if (oneIndexBufferPtr != null)
            {
                primitiveRestartIndexSwitch.Off();
            }
            PickingSwitchesOff();

            //if (mvpUpdated) { uniformmMVP4Picking.ResetUniform(program); }

            // 解绑shader
            program.Unbind();
        }
        private void ColorCodedPickingRender(RenderEventArgs e)
        {
            if (this.pickingShaderProgram == null)
            {
                this.pickingShaderProgram = PickingShaderHelper.GetPickingShaderProgram();
            }

            ShaderProgram program = this.pickingShaderProgram;

            // 绑定shader
            program.Bind();
            var picking = this as IColorCodedPicking;

            // TODO: use uint/int/float or ? use UniformUInt instead
            program.SetUniform("pickingBaseID", picking.PickingBaseID);
            pickingMVP.SetUniform(program);

            foreach (var item in switchList)
            {
                item.On();
            }

            if (this.vertexArrayObject4Picking == null)
            {
                var vertexArrayObject4Picking = new VertexArrayObject(
                    this.indexBufferPtr, this.positionBufferPtr);
                vertexArrayObject4Picking.Create(e, program);

                this.vertexArrayObject4Picking = vertexArrayObject4Picking;
            }
            //else
            {
                this.vertexArrayObject4Picking.Render(e, program);
            }

            foreach (var item in switchList)
            {
                item.Off();
            }

            pickingMVP.ResetUniform(program);

            // 解绑shader
            program.Unbind();
        }
Exemple #13
0
        protected override void DoRender(RenderEventArgs arg)
        {
            UpdatePolygonMode(arg.PickingGeometryType);

            ShaderProgram program = this.shaderProgram;

            // 绑定shader
            program.Bind();
            program.SetUniform("pickingBaseId", (int)this.PickingBaseId);
            UniformMat4 uniformmMVP4Picking = this.uniformmMVP4Picking;
            bool        mvpUpdated          = uniformmMVP4Picking.Updated;

            if (mvpUpdated)
            {
                uniformmMVP4Picking.SetUniform(program);
            }

            PickingSwitchesOn();

            if (this.vertexArrayObject == null)
            {
                var vertexArrayObject4Picking = new VertexArrayObject(
                    this.indexBufferPtr, this.positionBufferPtr);
                vertexArrayObject4Picking.Create(arg, program);

                this.vertexArrayObject = vertexArrayObject4Picking;
            }
            //else
            {
                this.vertexArrayObject.Render(arg, program);
            }

            PickingSwitchesOff();

            if (mvpUpdated)
            {
                uniformmMVP4Picking.ResetUniform(program);
            }


            // 解绑shader
            program.Unbind();
        }
        /// <summary>
        /// render with specified index buffer.
        /// </summary>
        /// <param name="arg"></param>
        /// <param name="temporaryIndexBuffer"></param>
        private void Render4Picking(RenderEventArgs arg, IndexBuffer temporaryIndexBuffer)
        {
            UpdatePolygonMode(arg.PickingGeometryType);

            ShaderProgram program = this.Program;

            // 绑定shader
            program.Bind();
            program.glUniform("pickingBaseId", 0);
            UniformMat4 uniformmMVP4Picking = this.uniformmMVP4Picking;

            {
                mat4 projection = arg.Camera.GetProjectionMatrix();
                mat4 view       = arg.Camera.GetViewMatrix();
                mat4 model      = this.GetModelMatrix().Value;
                uniformmMVP4Picking.Value = projection * view * model;
            }
            uniformmMVP4Picking.SetUniform(program);

            PickingStateesOn();
            var oneIndexBuffer = temporaryIndexBuffer as OneIndexBuffer;

            if (oneIndexBuffer != null)
            {
                PrimitiveRestartState glState = this.GetPrimitiveRestartState(oneIndexBuffer);
                glState.On();
                this.vertexArrayObject.Render(arg, program, temporaryIndexBuffer);
                glState.Off();
            }
            else
            {
                this.vertexArrayObject.Render(arg, program, temporaryIndexBuffer);
            }
            PickingStateesOff();

            //if (mvpUpdated) { uniformmMVP4Picking.ResetUniform(program); }

            // 解绑shader
            program.Unbind();
        }
        /// <summary>
        ///
        /// </summary>
        /// <param name="arg"></param>
        public void Render4Picking(RenderEventArgs arg)
        {
            if (!this.IsInitialized)
            {
                this.Initialize();
            }

            UpdatePolygonMode(arg.PickingGeometryType);

            ShaderProgram program = this.Program;

            // 绑定shader
            program.Bind();
            program.glUniform("pickingBaseId",
                              (int)this.PickingBaseId);
            UniformMat4 uniformmMVP4Picking = this.uniformmMVP4Picking;

            {
                mat4 projection = arg.Camera.GetProjectionMatrix();
                mat4 view       = arg.Camera.GetViewMatrix();
                mat4 model      = this.GetModelMatrix().Value;
                uniformmMVP4Picking.Value = projection * view * model;
            }
            uniformmMVP4Picking.SetUniform(program);

            PickingStateesOn();

            this.vertexArrayObject.Render(arg, program);

            PickingStateesOff();

            //if (mvpUpdated) { uniformmMVP4Picking.ResetUniform(program); }

            // 解绑shader
            program.Unbind();
        }
Exemple #16
0
        protected override void DoRender(RenderEventArgs arg)
        {
            ShaderProgram program = this.shaderProgram;

            if (program == null)
            {
                return;
            }

            // 绑定shader
            program.Bind();

            var updatedUniforms = (from item in this.uniformVariables where item.Updated select item).ToArray();

            foreach (var item in updatedUniforms)
            {
                item.SetUniform(program);
            }

            int count = this.switchList.Count;

            for (int i = 0; i < count; i++)
            {
                this.switchList[i].On();
            }

            IndexBufferPtr indexBufferPtr = this.indexBufferPtr;

            if (this.vertexArrayObject == null)
            {
                PropertyBufferPtr[] propertyBufferPtrs = this.propertyBufferPtrs;
                if (indexBufferPtr != null && propertyBufferPtrs != null)
                {
                    var vertexArrayObject = new VertexArrayObject(
                        indexBufferPtr, propertyBufferPtrs);
                    vertexArrayObject.Create(arg, program);

                    this.vertexArrayObject = vertexArrayObject;
                }
            }
            {
                VertexArrayObject vertexArrayObject = this.vertexArrayObject;
                if (vertexArrayObject != null)
                {
                    if (vertexArrayObject.IndexBufferPtr != indexBufferPtr)
                    {
                        vertexArrayObject.IndexBufferPtr = indexBufferPtr;
                    }
                    vertexArrayObject.Render(arg, program);
                }
            }

            for (int i = count - 1; i >= 0; i--)
            {
                this.switchList[i].Off();
            }

            foreach (var item in updatedUniforms)
            {
                item.ResetUniform(program);
            }

            // 解绑shader
            program.Unbind();
        }