public void Render(SharpGL.OpenGL gl, SharpGL.SceneGraph.Core.RenderMode renderMode) { // update matrix and bind shader program mat4 projectionMatrix = camera.GetProjectionMat4(); mat4 viewMatrix = camera.GetViewMat4(); mat4 modelMatrix = glm.scale(mat4.identity(), new vec3(1, 1, this.ZAxisScale)); shaderProgram.Bind(gl); shaderProgram.SetUniformMatrix4(gl, strprojectionMatrix, projectionMatrix.to_array()); shaderProgram.SetUniformMatrix4(gl, strviewMatrix, viewMatrix.to_array()); shaderProgram.SetUniformMatrix4(gl, strmodelMatrix, modelMatrix.to_array()); gl.BindVertexArray(vao[0]); // 启用Primitive restart gl.Enable(OpenGL.GL_PRIMITIVE_RESTART); gl.PrimitiveRestartIndex(uint.MaxValue);// 截断图元(四边形带、三角形带等)的索引值。 //GL.DrawArrays(primitiveMode, 0, vertexCount); gl.DrawElements((uint)primitiveMode, vertexCount + (this.pipe.Count - 1) * 2, OpenGL.GL_UNSIGNED_INT, IntPtr.Zero); gl.BindVertexArray(0); gl.Disable(OpenGL.GL_PRIMITIVE_RESTART); // unbind shader program shaderProgram.Unbind(gl); }
public void RenderWithStruct(SharpGL.OpenGL gl, SharpGL.SceneGraph.Core.RenderMode renderMode) { //if (!this.IsRenderable()) //return; ShaderProgram shader = this.shader; //GetShader(gl, renderMode); shader.Bind(gl); // 用VAO+EBO进行渲染。 // Bind the out vertex array. //gl.BindVertexArray(vao[0]); gl.BindVertexArray(vertexArrayObject); // Draw the square. //gl.BindBuffer(OpenGL.GL_ELEMENT_ARRAY_BUFFER, ebo[0]); gl.BindBuffer(OpenGL.GL_ELEMENT_ARRAY_BUFFER, this.triangleBufferObject); // 启用Primitive restart gl.Enable(OpenGL.GL_PRIMITIVE_RESTART); gl.PrimitiveRestartIndex(uint.MaxValue);// 截断图元(四边形带、三角形带等)的索引值。 gl.DrawElements(this.primitiveMode, this.triangleIndexCount, OpenGL.GL_UNSIGNED_INT, IntPtr.Zero); // Unbind our vertex array and shader. gl.BindVertexArray(0); gl.Disable(OpenGL.GL_PRIMITIVE_RESTART); shader.Unbind(gl); }
public void Render(SharpGL.OpenGL gl, SharpGL.SceneGraph.Core.RenderMode renderMode) { gl.BindVertexArray(vao[0]); gl.DrawArrays((uint)primitiveMode, 0, vertexCount); gl.BindVertexArray(0); }
public void Render(SharpGL.OpenGL gl, SharpGL.SceneGraph.Core.RenderMode renderMode) { gl.BindVertexArray(vao[0]); //GL.DrawArrays(primitiveMode, 0, vertexCount); gl.DrawElements((uint)primitiveMode, faceCount * 2 + 2, OpenGL.GL_UNSIGNED_INT, IntPtr.Zero); gl.BindVertexArray(0); }
/// <summary> /// 渲染此元素。 /// </summary> /// <param name="gl"></param> /// <param name="renderMode"></param> public virtual void Render(SharpGL.OpenGL gl, SharpGL.SceneGraph.Core.RenderMode renderMode) { if (!this.isInitialized) { this.Initialize(gl); this.isInitialized = true; } BeforeRendering(gl, renderMode); if (this.method == 1) { this.RenderZhuwei(gl, renderMode); } if (this.method == 2) { this.RenderWithStruct(gl, renderMode); } AfterRendering(gl, renderMode); }
/// <summary> /// 渲染此元素。 /// </summary> /// <param name="gl"></param> /// <param name="renderMode"></param> public virtual void Render(SharpGL.OpenGL gl, SharpGL.SceneGraph.Core.RenderMode renderMode) { BeforeRendering(gl, renderMode); ShaderProgram shader = this.shaderProgram;// GetShader(gl, renderMode); shader.Bind(gl); // 用VAO+EBO进行渲染。 // Bind the out vertex array. gl.BindVertexArray(vao[0]); gl.DrawArrays(this.primitiveMode, 0, this.primitiveCount); // Unbind our vertex array and shader. gl.BindVertexArray(0); shader.Unbind(gl); AfterRendering(gl, renderMode); }
/// <summary> /// 在IRenderable.Render()执行完毕时会调用此方法。 /// </summary> /// <param name="gl"></param> /// <param name="renderMode"></param> protected abstract void AfterRendering(SharpGL.OpenGL gl, SharpGL.SceneGraph.Core.RenderMode renderMode);