public void RenderBeforeChildren(RenderEventArgs arg) { TransformFeedbackObject tf = transformFeedbackObjects[(currentIndex + 1) % 2]; // update content at (currentIndex + 1) { GL.Instance.Enable(GL.GL_RASTERIZER_DISCARD); RenderMethod method = this.RenderUnit.Methods[currentIndex]; ShaderProgram program = method.Program; //program.SetUniform("xxx", value); method.Render(tf); // update buffers and record output to tf's binding. GL.Instance.Disable(GL.GL_RASTERIZER_DISCARD); } // render at (currentIndex + 1) { RenderMethod method = this.RenderUnit.Methods[(currentIndex + 1) % 2 + 2]; ShaderProgram program = method.Program; ICamera camera = arg.Camera; mat4 projection = camera.GetProjectionMatrix(); mat4 view = camera.GetViewMatrix(); mat4 model = this.GetModelMatrix(); program.SetUniform(mvpMatrix, projection * view * model); //unit.Render(); // this method must specify vertex count. tf.Draw(method); // render updated buffers without specifying vertex count. } // exchange { currentIndex = (currentIndex + 1) % 2; } }
protected override void DoInitialize() { base.DoInitialize(); for (int i = 0; i < 2; i++) { var tf = new TransformFeedbackObject(); RenderMethod method = this.RenderUnit.Methods[i]; VertexShaderAttribute[] attributes = method.VertexArrayObject.VertexAttributes; for (uint t = 0; t < attributes.Length; t++) { tf.BindBuffer(t, attributes[t].Buffer); } this.transformFeedbackObjects[i] = tf; } }
protected override void DoInitialize() { base.DoInitialize(); for (int i = 0; i < 2; i++) { var tfo = new TransformFeedbackObject(); RenderMethod method = this.RenderUnit.Methods[i]; VertexArrayObject vao = method.VertexArrayObjects[0]; // only one element here. VertexShaderAttribute[] attributes = vao.VertexAttributes; for (uint bindingPointIndex = 0; bindingPointIndex < attributes.Length; bindingPointIndex++) { tfo.BindBuffer(bindingPointIndex, attributes[bindingPointIndex].Buffer); } this.transformFeedbackObjects[i] = tfo; } }
public void RenderBeforeChildren(RenderEventArgs arg) { TransformFeedbackObject tfo = transformFeedbackObjects[(currentIndex + 1) % 2]; // update { if (this.firstRendering) { this.lastTime = DateTime.Now; this.firstRendering = false; } var now = DateTime.Now; float seconds = (float)now.Subtract(this.lastTime).TotalSeconds; this.lastTime = now; GL.Instance.Enable(GL.GL_RASTERIZER_DISCARD); RenderMethod method = this.RenderUnit.Methods[currentIndex]; ShaderProgram program = method.Program; // set the uniforms program.SetUniform("gravity", gravity); program.SetUniform("deltaTime", seconds); method.Render(tfo); // update buffers and record output to tf's binding. GL.Instance.Disable(GL.GL_RASTERIZER_DISCARD); } // render { RenderMethod method = this.RenderUnit.Methods[(currentIndex + 1) % 2 + 2]; ShaderProgram program = method.Program; ICamera camera = arg.Camera; mat4 projection = camera.GetProjectionMatrix(); mat4 view = camera.GetViewMatrix(); mat4 model = this.GetModelMatrix(); program.SetUniform("projectionMat", projection); program.SetUniform("viewMat", view * model); //unit.Render(); // this method requires specified vertes count. tfo.Draw(method); // render updated buffers without specifying vertex count. } // exchange { currentIndex = (currentIndex + 1) % 2; } }
protected override void DoInitialize() { base.DoInitialize(); for (int i = 0; i < 2; i++) { var tf = new TransformFeedbackObject(); RenderMethod method = this.RenderUnit.Methods[i]; // make sure there is only one vao in this case. foreach (var vao in method.VertexArrayObjects) { VertexShaderAttribute[] attributes = vao.VertexAttributes; for (uint t = 0; t < attributes.Length; t++) { tf.BindBuffer(t, attributes[t].Buffer); } } this.transformFeedbackObjects[i] = tf; } }
public override void RenderBeforeChildren(RenderEventArgs arg) { TransformFeedbackObject tf = transformFeedbackObjects[(currentIndex + 1) % 2]; // update { GL.Instance.Enable(GL.GL_RASTERIZER_DISCARD); RenderMethod method = this.RenderUnit.Methods[currentIndex]; ShaderProgram program = method.Program; // set the uniforms program.SetUniform("center", center); program.SetUniform("radius", radius); program.SetUniform("g", g); program.SetUniform("dt", dt); program.SetUniform("bounce", bounce); program.SetUniform("seed", random.Next()); method.Render(ControlMode.ByFrame, tf); // update buffers and record output to tf's binding. GL.Instance.Disable(GL.GL_RASTERIZER_DISCARD); } // render { RenderMethod method = this.RenderUnit.Methods[(currentIndex + 1) % 2 + 2]; ShaderProgram program = method.Program; ICamera camera = arg.CameraStack.Peek(); mat4 projection = camera.GetProjectionMatrix(); mat4 view = camera.GetViewMatrix(); mat4 model = this.GetModelMatrix(); program.SetUniform("Projection", projection); program.SetUniform("View", view * model); //unit.Render(); // this methos must specify vertes count. tf.Draw(method); // render updated buffersi without specifying vertex count. } // exchange { currentIndex = (currentIndex + 1) % 2; } }
public TransformFeedbackCalculator(int maxItemCount) { this.MaxItemCount = maxItemCount; var program = new ShaderProgram(); //program.Initialize(varyings, ShaderProgram.BufferMode.InterLeaved, vertexShader); var varyings = new string[] { "outValue" }; glTransformFeedbackVaryings(program.ProgramId, varyings.Length, varyings, GL.GL_INTERLEAVED_ATTRIBS); var vertexShader = new VertexShader(vertexCode); vertexShader.Initialize(); glAttachShader(program.ProgramId, vertexShader.ShaderId); glLinkProgram(program.ProgramId); program.CheckLinkStatus(); VertexBuffer vbo = VertexBuffer.Create(typeof(float), maxItemCount, VBOConfig.Float, BufferUsage.StaticDraw); var drawCmd = new DrawArraysCmd(DrawMode.Points, maxItemCount); var vao = new VertexArrayObject(drawCmd, program, new VertexShaderAttribute[] { new VertexShaderAttribute(vbo, "inValue") }); uint index = 0; VertexBuffer tbo = VertexBuffer.Create(typeof(float), maxItemCount, VBOConfig.Float, BufferUsage.StaticRead); //glBindBufferBase(GL.GL_TRANSFORM_FEEDBACK_BUFFER, index, tbo.BufferId); var tfo = new TransformFeedbackObject(); tfo.BindBuffer(index, tbo); { this.program = program; this.inputBuffer = vbo; this.outputBuffer = tbo; this.vao = vao; this.drawCommand = drawCmd; this.tfo = tfo; } }