aboutsummaryrefslogtreecommitdiff
path: root/src/main/java/makamys/neodymium/renderer/Mesh.java
blob: 74a1678d88a5685ca0bb9b084876c16cdf915190 (plain)
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
package makamys.neodymium.renderer;

import java.nio.ByteBuffer;
import java.nio.IntBuffer;

import makamys.neodymium.util.Util;

/** A generic mesh that can be sent to the GPU for rendering. */
public abstract class Mesh {
	
    /** Can be null, unless gpuStatus is SENT */
	public ByteBuffer buffer;
	public int quadCount;
	public boolean visible;
	public GPUStatus gpuStatus = GPUStatus.UNSENT;
	public int iFirst = -1, iCount = -1;
	public int offset = -1;
	public int pass;
	int x, y, z;
	public QuadNormal normal = QuadNormal.NONE;
	
	public abstract int getStride();
	
	public double distSq(double x2, double y2, double z2) {
	    return Util.distSq(x, y, z, x2, y2, z2);
	}
	
	public int bufferSize() {
	    return buffer == null ? 0 : buffer.limit();
	}
	
	public int getEnd() {
	    return offset + bufferSize();
	}
	
	public void prepareBuffer() {}
	public void destroyBuffer() {}
	
	public void update() {}
	
	public static enum GPUStatus {
	    UNSENT, SENT, PENDING_DELETE
	}

    public void writeToIndexBuffer(IntBuffer piFirst, IntBuffer piCount, int[] renderedMeshesReturn,
            int[] renderedQuadsReturn, int cameraXDiv, int cameraYDiv, int cameraZDiv) {
        renderedMeshesReturn[0] = 1;
        renderedQuadsReturn[0] = quadCount;
        piFirst.put(iFirst);
        piCount.put(iCount);
    }
}