protected void cleanupRender() { compileState = COMP_STATUS.DO_NOT_RENDER; vert = null; ind = null; if (VBOIDs != null) { GL.DeleteBuffers(2, VBOIDs); VBOIDs = null; } }
public void drawRender() { //Console.Out.WriteLine("Draw chunk: " + Location.X + ", " + Location.Y); switch (compileState) { case COMP_STATUS.NEEDS_TO_BE_MADE: { compileState = COMP_STATUS.CURRENTLY_MAKING; makeThread.Start(); return; } case COMP_STATUS.NEEDS_TO_BE_COMPILED: { compileRender(); compileState = COMP_STATUS.READY_TO_RENDER; return; } case COMP_STATUS.READY_TO_RENDER: { /*if (this as Chunk != null) { * Console.Out.WriteLine("Draw chunk: {0}, {1} VBO:[{2}, {3}] elCount={4}", (this as Chunk).Location.X, (this as Chunk).Location.Y, VBOIDs[0], VBOIDs[1], elementCount); * }else if (this as Actor != null) { * Console.Out.WriteLine("Draw actor: {0} VBO:[{1}, {2}] elCount={3}", (this as Actor).ID, VBOIDs[0], VBOIDs[1], elementCount); * }*/ TryGL.Call(() => GL.BindBuffer(BufferTarget.ArrayBuffer, VBOIDs[0])); TryGL.Call(() => GL.BindBuffer(BufferTarget.ElementArrayBuffer, VBOIDs[1])); TryGL.Call(() => GL.EnableVertexAttribArray(0)); //Positions TryGL.Call(() => GL.VertexAttribPointer(0, 3, VertexAttribPointerType.Float, false, Vertex.StrideToEnd, Vertex.StrideToPosition)); TryGL.Call(() => GL.EnableVertexAttribArray(1)); //UV TryGL.Call(() => GL.VertexAttribPointer(1, 3, VertexAttribPointerType.Float, false, Vertex.StrideToEnd, Vertex.StrideToUV)); TryGL.Call(() => GL.EnableVertexAttribArray(2)); //Normals TryGL.Call(() => GL.VertexAttribPointer(2, 3, VertexAttribPointerType.Float, false, Vertex.StrideToEnd, Vertex.StrideToNormal)); TryGL.Call(() => GL.DrawElements(PrimitiveType.Triangles, elementCount, DrawElementsType.UnsignedInt, (IntPtr)null)); //GL.BindBuffer(BufferTarget.ArrayBuffer, 0); //GL.BindBuffer(BufferTarget.ElementArrayBuffer, 0); return; } case COMP_STATUS.NEEDS_TO_BE_REMOVED: { cleanupRender(); return; } } }
private void privateMakeRender() { makeRender(); compileState = COMP_STATUS.NEEDS_TO_BE_COMPILED; }