Java 有效地从ByteBuffer的一部分填充浮动缓冲区
目前,我正在以以下方式从映射字节缓冲区填充FloatBuffer:Java 有效地从ByteBuffer的一部分填充浮动缓冲区,java,opengl,jogl,floatbuffer,mappedbytebuffer,Java,Opengl,Jogl,Floatbuffer,Mappedbytebuffer,目前,我正在以以下方式从映射字节缓冲区填充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. * @auth
/**
* 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();
}
}
然而,OpenGL中的这个函数会向GPU发送太多数据吗?还是仅仅从当前位置到极限
gl.glBufferData(GL3.GL_ARRAY_BUFFER, vertexes.limit(), vertexes, GL3.GL_STATIC_DRAW);
你为什么要复制数据?我会使用缓冲区。asFloatBuffer@PeterLawrey因为我不想复制整个bytebuffer,只想复制header.fileofs到header.fileofs+header.filelen.buffer.slice.asFloatBuffer的字节?我想你误解了这个问题;当我使用buffer.asFloatBuffer时,新的FloatBuffer还包含我需要的数据后面的所有字节。我想将FloatBuffer发送到OpenGL,只包含顶点数据。
gl.glBufferData(GL3.GL_ARRAY_BUFFER, vertexes.limit(), vertexes, GL3.GL_STATIC_DRAW);