0

目前我正在通过以下方式从映射字节缓冲区填充 FloatBuffer:

/**
 * The vertex lump (Lump 3) is an array of coordinates of all the vertices (corners)    of brushes in the map geometry. 
 * Each vertex is a Vector of 3 floats (x, y, and z), giving 12 bytes per vertex. 
 * @author Jurian
 *
 */
public class VertexLump extends Lump {
    public final FloatBuffer vertexes;

    /**
     * @param buffer Little-Endian buffer with actual data
     * @param bsp Used for referencing the header with position and length of vertex data
     */
    public VertexLump(MappedByteBuffer buffer, ValveBSP bsp) {
        super(buffer, bsp.headers[LumpType.LUMP_VERTEXES.index]);
        //MappedByteBuffer is set to correct position in super()
        vertexes = FloatBuffer.allocate(header.filelen / (Buffers.SIZEOF_FLOAT));
        for(int i = 0; i < vertexes.capacity(); i++) {
            vertexes.put(buffer.getFloat());
        }
        vertexes.flip();
    }
}

但我怀疑有更好的方法来做到这一点,而不是遍历所有位置。缓冲区中可以有很多顶点(最多 65536)。

这似乎有效:

public VertexLump(MappedByteBuffer buffer, ValveBSP bsp) {
    super(buffer, bsp.headers[LumpType.LUMP_VERTEXES.index]);
    vertexes = buffer.asFloatBuffer();
    vertexes.limit(header.filelen / Buffers.SIZEOF_FLOAT);
}

但是,OpenGL 中的这个函数会向 GPU 发送太多数据吗?还是只是从当前位置到极限?

gl.glBufferData(GL3.GL_ARRAY_BUFFER, vertexes.limit(), vertexes, GL3.GL_STATIC_DRAW);
4

0 回答 0