我有一个空的 byteBuffer 分配为
data = ByteBuffer.allocateDirect(layerSize(0, faces - 1, 0, levels - 1) * layers);
按照这个答案,我尝试使用array()
以下方法
public void setData(ByteBuffer data, int layer, int face, int level) {
int offset = offset(layer, face, level);
int levelSize = levelSize(level);
this.data.put(data.array(), offset, levelSize);
}
但我得到:
Caused by: java.lang.UnsupportedOperationException
at java.nio.ByteBuffer.array(ByteBuffer.java:994)
我尝试使用的源字节缓冲区以这种方式读取:
File file = new File(Load.class.getResource(fileName).getFile());
FileInputStream fileInputStream = new FileInputStream(file);
FileChannel fileChannel = fileInputStream.getChannel();
return loadKtx(fileChannel.map(FileChannel.MapMode.READ_ONLY, 0, (int) file.length()));
public static Texture loadKtx(ByteBuffer byteBuffer) throws IOException {
...
byteBuffer.position(offset);
byteBuffer.limit(offset + faceSize);
ByteBuffer data = byteBuffer.slice();
texture.setData(data, layer, face, level);
byteBuffer.position(0);
byteBuffer.limit(byteBuffer.capacity());
有没有比简单的更好的选择
for (int b = 0; b < levelSize; b++) {
this.data.put(offset + b, data.get(b));
}
?
但是,对于感兴趣的人来说,这里的整个项目。