Merge pull request #588 from JavaSaBr/added_lwjgl3_allocator
implemented LWJGL3 BufferAllocatornative-compilation-test
commit
6493337477
@ -0,0 +1,31 @@ |
||||
package com.jme3.util; |
||||
|
||||
import com.jme3.system.Annotations.Internal; |
||||
|
||||
import java.util.logging.Level; |
||||
import java.util.logging.Logger; |
||||
|
||||
/** |
||||
* The factory of buffer allocators. |
||||
* |
||||
* @author JavaSaBR |
||||
*/ |
||||
@Internal |
||||
public class BufferAllocatorFactory { |
||||
|
||||
public static final String PROPERTY_BUFFER_ALLOCATOR_IMPLEMENTATION = "com.jme3.BufferAllocatorImplementation"; |
||||
|
||||
private static final Logger LOGGER = Logger.getLogger(BufferAllocatorFactory.class.getName()); |
||||
|
||||
@Internal |
||||
protected static BufferAllocator create() { |
||||
|
||||
final String className = System.getProperty(PROPERTY_BUFFER_ALLOCATOR_IMPLEMENTATION, ReflectionAllocator.class.getName()); |
||||
try { |
||||
return (BufferAllocator) Class.forName(className).newInstance(); |
||||
} catch (final Throwable e) { |
||||
LOGGER.log(Level.WARNING, "Unable to access {0}", className); |
||||
return new PrimitiveAllocator(); |
||||
} |
||||
} |
||||
} |
@ -0,0 +1,24 @@ |
||||
package com.jme3.util; |
||||
|
||||
import org.lwjgl.system.MemoryUtil; |
||||
|
||||
import java.nio.Buffer; |
||||
import java.nio.ByteBuffer; |
||||
|
||||
/** |
||||
* The implementation of the {@link BufferAllocator} which use {@link MemoryUtil} to manage memory. |
||||
* |
||||
* @author JavaSaBr |
||||
*/ |
||||
public class LWJGLBufferAllocator implements BufferAllocator { |
||||
|
||||
@Override |
||||
public void destroyDirectBuffer(final Buffer buffer) { |
||||
MemoryUtil.memFree(buffer); |
||||
} |
||||
|
||||
@Override |
||||
public ByteBuffer allocate(final int size) { |
||||
return MemoryUtil.memAlloc(size); |
||||
} |
||||
} |
Loading…
Reference in new issue