Commit 9c9677f7 authored by Benedikt Zoennchen's avatar Benedikt Zoennchen

delete duplicated classes

parent 26bd4722
package org.vadere.util.opencl.examples;
import org.apache.log4j.LogManager;
import org.apache.log4j.Logger;
import org.lwjgl.PointerBuffer;
import org.lwjgl.opencl.CL;
import org.lwjgl.opencl.CLCapabilities;
import org.lwjgl.system.MemoryStack;
import java.nio.IntBuffer;
import java.util.ArrayList;
import static org.lwjgl.opencl.CL10.clGetPlatformIDs;
import static org.lwjgl.system.MemoryStack.stackPush;
/**
* Created by bzoennchen on 08.09.17.
*/
public class CLUtils {
public static Logger log = LogManager.getLogger(CLUtils.class);
public static ArrayList<Long> getCLPlatforms() {
MemoryStack stack = stackPush();
IntBuffer pi = stack.mallocInt(1);
InfoUtils.checkCLError(clGetPlatformIDs(null, pi));
if (pi.get(0) == 0) {
log.warn("No OpenCL platform found.");
return new ArrayList<>();
}
PointerBuffer platformIDs = stack.mallocPointer(pi.get(0));
InfoUtils.checkCLError(clGetPlatformIDs(platformIDs, (IntBuffer)null));
ArrayList<Long> platforms = new ArrayList<>(platformIDs.capacity());
for (int i = 0; i < platformIDs.capacity(); i++) {
long platform = platformIDs.get(i);
CLCapabilities caps = CL.createPlatformCapabilities(platform);
if (caps.cl_khr_gl_sharing || caps.cl_APPLE_gl_sharing) {
platforms.add(platform);
}
}
return platforms;
}
}
package org.vadere.util.opencl.examples;
/*
* Copyright LWJGL. All rights reserved.
* License terms: https://www.lwjgl.org/license
*/
import org.lwjgl.*;
import java.io.*;
import java.nio.*;
import java.nio.channels.*;
import java.nio.file.*;
import static org.lwjgl.BufferUtils.*;
public final class IOUtil {
private IOUtil() {
}
private static ByteBuffer resizeBuffer(ByteBuffer buffer, int newCapacity) {
ByteBuffer newBuffer = BufferUtils.createByteBuffer(newCapacity);
buffer.flip();
newBuffer.put(buffer);
return newBuffer;
}
/**
* Reads the specified resource and returns the raw data as a ByteBuffer.
*
* @param resource the resource to read
* @param bufferSize the initial buffer size
*
* @return the resource data
*
* @throws IOException if an IO error occurs
*/
public static ByteBuffer ioResourceToByteBuffer(String resource, int bufferSize) throws IOException {
ByteBuffer buffer;
Path path = Paths.get(resource);
if (Files.isReadable(path)) {
try (SeekableByteChannel fc = Files.newByteChannel(path)) {
buffer = BufferUtils.createByteBuffer((int)fc.size() + 1);
while (fc.read(buffer) != -1) {
;
}
}
} else {
try (
InputStream source = IOUtil.class.getClassLoader().getResourceAsStream(resource);
ReadableByteChannel rbc = Channels.newChannel(source)
) {
buffer = createByteBuffer(bufferSize);
while (true) {
int bytes = rbc.read(buffer);
if (bytes == -1) {
break;
}
if (buffer.remaining() == 0) {
buffer = resizeBuffer(buffer, buffer.capacity() * 2);
}
}
}
}
buffer.flip();
return buffer;
}
}
\ No newline at end of file
Markdown is supported
0% or
You are about to add 0 people to the discussion. Proceed with caution.
Finish editing this message first!
Please register or to comment