private void DoRender(object sender, PaintEventArgs e) { // Compute the MVP (Model View Projection matrix) { GL.BindBuffer(BufferTarget.UniformBuffer, BufferName[1]);//BufferName[TRANSFORM] var mvpPointer = GL.MapBufferRange(GL.GL_UNIFORM_BUFFER, 0, 64, (uint)(GL.GL_MAP_WRITE_BIT | GL.GL_MAP_INVALIDATE_BUFFER_BIT)); var tmp = new UnmanagedArray <mat4>(1); mat4 projection = this.camera.GetProjectionMat4(); mat4 view = this.camera.GetViewMat4(); //tmp[0] = projection * view; //tmp.CopyTo(Pointer); unsafe { mat4 *array = (mat4 *)mvpPointer.ToPointer(); array[0] = projection * view; } GL.UnmapBuffer(GL.GL_UNIFORM_BUFFER); tmp.Dispose(); } // Clear color buffer //GL.ClearBufferfv(GL_COLOR, 0, &GL.m.vec4(0.0f, 0.0f, 0.0f, 1.0f)[0]); GL.ClearBuffer(GL.GL_COLOR, 0, new float[] { 0.0f, 0.0f, 0.0f, 1.0f }); // First draw, capture the attributes // Disable rasterisation, vertices processing only! GL.Enable(GL.GL_RASTERIZER_DISCARD); transformProgram.Bind(); GL.BindVertexArray(transformArray[0]); //GL.BindBufferBase(GL.GL_UNIFORM_BUFFER, semantic.uniform.TRANSFORM0, BufferName[buffer.TRANSFORM]); GL.BindBufferBase(GL.GL_UNIFORM_BUFFER, 1, BufferName[1]); GL.BindTransformFeedback(GL.GL_TRANSFORM_FEEDBACK, feedbackObj[0]); GL.BeginTransformFeedback(GL.GL_TRIANGLES); GL.DrawArraysInstanced(GL.GL_TRIANGLES, 0, 6, 1);//VertexCount: 6 GL.EndTransformFeedback(); GL.BindTransformFeedback(GL.GL_TRANSFORM_FEEDBACK, 0); GL.Disable(GL.GL_RASTERIZER_DISCARD); // Second draw, reuse the captured attributes feedbackProgram.Bind(); GL.BindVertexArray(feedbackArray[0]); GL.DrawTransformFeedback(GL.GL_TRIANGLES, feedbackObj[0]); }
/// <summary> /// Bind transform feedback object. /// </summary> /// <param name="primitive">Transform feedback primitive type.</param> public void Bind(PrimitiveType primitive, bool resume) { // bind transform feedback object GL.BindTransformFeedback(TransformFeedbackTarget.TransformFeedback, glname); // resume or start transform feedback if (resume) { GL.ResumeTransformFeedback(); } else { GL.BeginTransformFeedback(primitive); } }
//----------------------------------------------------------------------------------------- protected override void OnRenderFrame(FrameEventArgs e) { GL.UseProgram(_updateProgram); GL.Enable(EnableCap.RasterizerDiscard); int iterationIndex = 0; for (int i = _iterationsPerFrame; i != 0; --i) { GL.BindVertexArray(_vaos[iterationIndex & 1]); GL.BindTexture(TextureTarget.TextureBuffer, _tbos[iterationIndex & 1]); iterationIndex++; GL.BindBufferBase(BufferRangeTarget.TransformFeedbackBuffer, 0, _vbos[(int)BufferType.PositionA + (iterationIndex & 1)]); GL.BindBufferBase(BufferRangeTarget.TransformFeedbackBuffer, 1, _vbos[(int)BufferType.VelocityA + (iterationIndex & 1)]); GL.BeginTransformFeedback(BeginFeedbackMode.Points); GL.DrawArrays(BeginMode.Points, 0, Statics.numPoints); GL.EndTransformFeedback(); } GL.Disable(EnableCap.RasterizerDiscard); GL.Viewport(0, 0, Width, Height); GL.ClearBuffer(ClearBuffer.Color, 0, Statics.colorBlack); GL.UseProgram(_renderProgram); if (_drawPointsFlag) { GL.PointSize(4.0f); GL.DrawArrays(BeginMode.Points, 0, Statics.numPoints); } if (_drawLinesFlag) { GL.BindBuffer(BufferTarget.ElementArrayBuffer, _vboIndex); GL.DrawElements(BeginMode.Lines, Statics.numConnections * 2, DrawElementsType.UnsignedInt, 0); } SwapBuffers(); }
public void BeginTransformFeedback(PrimitiveTopology topology) { GL.BeginTransformFeedback(_tfTopology = topology.ConvertToTfType()); _tfEnabled = true; }
public void BeginTransformFeedback(int primitiveMode) { GL.BeginTransformFeedback((TransformFeedbackPrimitiveType)primitiveMode); }
// use to start/end up the bound transform (either default or this one) /// <summary> Start feedback on the primitive type </summary> public static void Begin(TransformFeedbackPrimitiveType t) { GL.BeginTransformFeedback(t); }
/// <summary> /// Start transform feedback operation. /// </summary> /// <param name="primitiveMode">Specify the output type of the primitives that will be recorded into the buffer objects that are bound for transform feedback.</param> public void Begin(TransformFeedbackPrimitiveType primitiveMode) { AssertActive(); GL.BeginTransformFeedback(primitiveMode); }
public static void Draw(PrimitiveType type, int first, int count) { if (count == 0) { return; } if (curVarray == null) { return; } if (curProg == null) { return; } if (curFramebuffer == null) { return; } for (int i = 0; i < textures.Count; i++) { GPUStateMachine.BindTexture(i, textures[i].texTarget, textures[i].id); } for (int i = 0; i < feedbackBufs.Count; i++) { GPUStateMachine.BindBuffer(BufferTarget.TransformFeedbackBuffer, feedbackBufs[i].Item1.id, i, (IntPtr)feedbackBufs[i].Item2, (IntPtr)feedbackBufs[i].Item3); } GPUStateMachine.BindFramebuffer(curFramebuffer.id); if (feedbackBufs.Count > 0) { GL.BeginTransformFeedback((TransformFeedbackPrimitiveType)feedbackPrimitive); } GL.UseProgram(curProg.id); GPUStateMachine.BindVertexArray(curVarray.id); if (curIndices != null) { GPUStateMachine.BindBuffer(BufferTarget.ElementArrayBuffer, curIndices.id); } if (curIndices != null) { GL.DrawElements(type, count, DrawElementsType.UnsignedInt, IntPtr.Zero); } else { GL.DrawArrays(type, first, count); } if (feedbackBufs.Count > 0) { GL.EndTransformFeedback(); } for (int i = 0; i < feedbackBufs.Count; i++) { GPUStateMachine.UnbindBuffer(BufferTarget.TransformFeedbackBuffer, i); } for (int i = 0; i < textures.Count; i++) { GPUStateMachine.UnbindTexture(i, textures[i].texTarget); } textures.Clear(); feedbackBufs.Clear(); }