Slow framerates and slowdown
in
Core Library Questions
•
1 year ago
Hey everyone,
I'm working on a project at the moment with lots and lots of data, reading from a text file. The problem I'm having is really low framerates and then a slowdown - starting on 9fps and then getting slower and slower, tending towards 0fps. The points are being plotted with an opengl vertex buffer object (but this isn't the problem, the framerate was the same before I switched to opengl calls).
VisualVM blames my function drawData(). The code for the entire class that function is in is below. Is there a gaping problem here? Is a slowdown a sign of a bad loop or something, or does it just happen if it's all too much?
- //This is GOD, the class for a Geospatially Overlaid Dataset.
- //It takes a data input, parses it and draws it.
- class GOD {
- private String name;
- private String source;
- private String path;
- private String filetype;
- private String seperator;
- private int fieldCount;
- private HashMap metaValues;
- private XMLElement metaData;
- private String[][] godLayerData;
- private int datasetSize;
- FloatBuffer vertexBuffer;
- FloatBuffer colourBuffer;
- GOD(XMLElement GODLayer) {
- metaData = GODLayer;
- loadData();
- initialiseOpenGLBuffer();
- }
- void getMetadata() {
- name = metaData.getChild("name").getContent();
- source = metaData.getChild("source").getContent();
- path = metaData.getChild("path").getContent();
- filetype = metaData.getChild("filetype").getContent();
- seperator = metaData.getChild("seperator").getContent();
- fieldCount = metaData.getChild("values").getChildCount();
- metaValues = new HashMap(fieldCount, 1);
- for (int i=0;i<fieldCount;i++) {
- metaValues.put(metaData.getChild("values").getChild(i).getContent(), str(i));
- }
- }
- void loadData() {
- getMetadata();
- if (filetype==null) {
- println("filetype for "+name+" is either not set or caught");
- }
- else if (filetype!=null) {
- if (filetype.equals("csv")) {
- String[] rawLines = loadStrings(path);
- int ii=rawLines.length;
- datasetSize = ii-1;
- godLayerData = new String[datasetSize][fieldCount];
- for (int i=1;i<ii;i++) {
- String[] splitLine = split(rawLines[i], seperator);
- for (int j=0;j<fieldCount;j++) {
- godLayerData[i-1][j] = splitLine[j];
- }
- }
- }
- else {
- println("filetype '"+filetype+"' is not recognised");
- }
- }
- }
- void initialiseOpenGLBuffer() {
- vertexBuffer = BufferUtil.newFloatBuffer(datasetSize*3); //space in the buffer for x,y,z positions
- colourBuffer = BufferUtil.newFloatBuffer(datasetSize*4); //space in the buffer for r,g,b,a values
- for (int i = 0; i < datasetSize; i++) {
- // r,g,b,a
- colourBuffer.put(1);
- colourBuffer.put(0);
- colourBuffer.put(0);
- colourBuffer.put(0.4);
- }
- colourBuffer.rewind();
- PGraphicsOpenGL pgl = (PGraphicsOpenGL) g;
- GL gl = pgl.beginGL();
- gl.glEnableClientState(GL.GL_VERTEX_ARRAY);
- gl.glVertexPointer(3, GL.GL_FLOAT, 0, vertexBuffer);
- gl.glEnableClientState(GL.GL_COLOR_ARRAY);
- gl.glColorPointer(4, GL.GL_FLOAT, 0, colourBuffer);
- gl.glPointSize(1);
- pgl.endGL();
- }
- void drawData() {
- int latitudeIndex = int(metaValues.get("latitude").toString());
- int longitudeIndex = int(metaValues.get("longitude").toString());
- for (int j=datasetSize-1;j>-1;j--) {
- float latitude = float(godLayerData[j][latitudeIndex]);
- float longitude = float(godLayerData[j][longitudeIndex]);
- PVector spaceLoc = equator.returnGlobeCoordinate(latitude, longitude);
- vertexBuffer.put(spaceLoc.x);
- vertexBuffer.put(spaceLoc.y);
- vertexBuffer.put(spaceLoc.z);
- }
- vertexBuffer.rewind();
- PGraphicsOpenGL pgl = (PGraphicsOpenGL) g;
- GL gl = pgl.beginGL();
- gl.glColorPointer(4, GL.GL_FLOAT, 0, colourBuffer);
- gl.glVertexPointer(3, GL.GL_FLOAT, 0, vertexBuffer);
- gl.glDrawArrays(GL.GL_POINTS, 0, datasetSize);
- pgl.endGL();
- }
- }
The PVector function is also here below, maybe the problem is in the maths here:
- PVector returnGlobeCoordinate(float latitude, float longitude) {
- float lat = latitude;
- float lng = longitude;
- lat = radians(lat);
- lng = radians(lng);
- float pX = pRadius * cos(lat) * cos(lng);
- float pY = pRadius * sin(lat);
- float pZ = pRadius * cos(lat) * sin(lng);
- PVector outputPVector = new PVector(int(pX), int(pY), int(pZ));
- return outputPVector;
- }
datasetSize is about 2,000,000 for one of the datasets (20 for the only other one currently in there). Is that just too much for a loop to run every frame? But then why does it get slower and slower? Or is it just graphics? surely 2,000,000 points should be able to render faster than this, especially when I'm using a vertex buffer object?
Thanks so much!
1