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();
        }
示例#2
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();
        }
        /// <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();
        }