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(); }
/// <summary> /// /// </summary> /// <param name="program"></param> protected override void DoSetUniform(ShaderProgram program) { glActiveTexture(value.activeTextureIndex + OpenGL.GL_TEXTURE0); //OpenGL.BindTexture(OpenGL.GL_TEXTURE_2D, value.TextureId); OpenGL.BindTexture(value.target, value.TextureId); this.Location = program.glUniform(VarName, (int)value.activeTextureIndex); }
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> /// /// </summary> /// <param name="program"></param> protected override void DoSetUniform(ShaderProgram program) { if (activeTexture == null) { activeTexture = GL.Instance.GetDelegateFor("glActiveTexture", GLDelegates.typeof_void_uint) as GLDelegates.void_uint; } activeTexture(value.activeTextureIndex + GL.GL_TEXTURE0); //OpenGL.BindTexture(GL.GL_TEXTURE_2D, value.TextureId); GL.Instance.BindTexture(value.target, value.TextureId); this.Location = program.glUniform(VarName, (int)value.activeTextureIndex); }
/// <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(); }