org.lwjgl.PointerBuffer Java Examples

The following examples show how to use org.lwjgl.PointerBuffer. You can vote up the ones you like or vote down the ones you don't like, and go to the original project or source file by following the links above each example. You may check out the related API usage on the sidebar.
Example #1
Source File: LwjglProgram.java    From jmonkeyengine with BSD 3-Clause "New" or "Revised" License 6 votes vote down vote up
@Override
public void build(String args, Device... devices) throws KernelCompilationException {
    PointerBuffer deviceList = null;
    if (devices != null) {
        deviceList = PointerBuffer.allocateDirect(devices.length);
        deviceList.rewind();
        for (Device d : devices) {
            deviceList.put(((LwjglDevice) d).getDevice());
        }
        deviceList.flip();
    }
    int ret = CL10.clBuildProgram(program, deviceList, args, null, 0);
    if (ret != CL10.CL_SUCCESS) {
        String log = Log();
        LOG.log(Level.WARNING, "Unable to compile program:\n{0}", log);
        if (ret == CL10.CL_BUILD_PROGRAM_FAILURE) {
            throw new KernelCompilationException("Failed to build program", ret, log);
        } else {
            Utils.checkError(ret, "clBuildProgram");
        }
    } else {
        LOG.log(Level.INFO, "Program compiled:\n{0}", Log());
    }
}
 
Example #2
Source File: LmdbLwjgl.java    From benchmarks with Apache License 2.0 6 votes vote down vote up
@Setup(Trial)
@Override
public void setup(final BenchmarkParams b) throws IOException {
  super.setup(b, false);
  super.write();

  try (MemoryStack stack = stackPush()) {
    final PointerBuffer pp = stack.mallocPointer(1);

    E(mdb_txn_begin(env, NULL, MDB_RDONLY, pp));
    txn = pp.get(0);

    E(mdb_cursor_open(txn, db, pp));
    c = pp.get(0);
  }
}
 
Example #3
Source File: StaticMeshesLoader.java    From lwjglbook with Apache License 2.0 6 votes vote down vote up
public static Mesh[] load(String resourcePath, String texturesDir, int flags) throws Exception {
    AIScene aiScene = aiImportFile(resourcePath, flags);
    if (aiScene == null) {
        throw new Exception("Error loading model");
    }

    int numMaterials = aiScene.mNumMaterials();
    PointerBuffer aiMaterials = aiScene.mMaterials();
    List<Material> materials = new ArrayList<>();
    for (int i = 0; i < numMaterials; i++) {
        AIMaterial aiMaterial = AIMaterial.create(aiMaterials.get(i));
        processMaterial(aiMaterial, materials, texturesDir);
    }

    int numMeshes = aiScene.mNumMeshes();
    PointerBuffer aiMeshes = aiScene.mMeshes();
    Mesh[] meshes = new Mesh[numMeshes];
    for (int i = 0; i < numMeshes; i++) {
        AIMesh aiMesh = AIMesh.create(aiMeshes.get(i));
        Mesh mesh = processMesh(aiMesh, materials);
        meshes[i] = mesh;
    }

    return meshes;
}
 
Example #4
Source File: AnimMeshesLoader.java    From lwjglbook with Apache License 2.0 6 votes vote down vote up
private static Map<String, Animation> processAnimations(AIScene aiScene, List<Bone> boneList,
        Node rootNode, Matrix4f rootTransformation) {
    Map<String, Animation> animations = new HashMap<>();

    // Process all animations
    int numAnimations = aiScene.mNumAnimations();
    PointerBuffer aiAnimations = aiScene.mAnimations();
    for (int i = 0; i < numAnimations; i++) {
        AIAnimation aiAnimation = AIAnimation.create(aiAnimations.get(i));

        // Calculate transformation matrices for each node
        int numChanels = aiAnimation.mNumChannels();
        PointerBuffer aiChannels = aiAnimation.mChannels();
        for (int j = 0; j < numChanels; j++) {
            AINodeAnim aiNodeAnim = AINodeAnim.create(aiChannels.get(j));
            String nodeName = aiNodeAnim.mNodeName().dataString();
            Node node = rootNode.findByName(nodeName);
            buildTransFormationMatrices(aiNodeAnim, node);
        }

        List<AnimatedFrame> frames = buildAnimationFrames(boneList, rootNode, rootTransformation);
        Animation animation = new Animation(aiAnimation.mName().dataString(), frames, aiAnimation.mDuration());
        animations.put(animation.getName(), animation);
    }
    return animations;
}
 
Example #5
Source File: StaticMeshesLoader.java    From lwjglbook with Apache License 2.0 6 votes vote down vote up
public static Mesh[] load(String resourcePath, String texturesDir, int flags) throws Exception {
    AIScene aiScene = aiImportFile(resourcePath, flags);
    if (aiScene == null) {
        throw new Exception("Error loading model");
    }

    int numMaterials = aiScene.mNumMaterials();
    PointerBuffer aiMaterials = aiScene.mMaterials();
    List<Material> materials = new ArrayList<>();
    for (int i = 0; i < numMaterials; i++) {
        AIMaterial aiMaterial = AIMaterial.create(aiMaterials.get(i));
        processMaterial(aiMaterial, materials, texturesDir);
    }

    int numMeshes = aiScene.mNumMeshes();
    PointerBuffer aiMeshes = aiScene.mMeshes();
    Mesh[] meshes = new Mesh[numMeshes];
    for (int i = 0; i < numMeshes; i++) {
        AIMesh aiMesh = AIMesh.create(aiMeshes.get(i));
        Mesh mesh = processMesh(aiMesh, materials);
        meshes[i] = mesh;
    }

    return meshes;
}
 
Example #6
Source File: StaticMeshesLoader.java    From lwjglbook with Apache License 2.0 6 votes vote down vote up
public static Mesh[] load(String resourcePath, String texturesDir, int flags) throws Exception {
    AIScene aiScene = aiImportFile(resourcePath, flags);
    if (aiScene == null) {
        throw new Exception("Error loading model [resourcePath: "  + resourcePath + ", texturesDir:" + texturesDir + "]");
    }

    int numMaterials = aiScene.mNumMaterials();
    PointerBuffer aiMaterials = aiScene.mMaterials();
    List<Material> materials = new ArrayList<>();
    for (int i = 0; i < numMaterials; i++) {
        AIMaterial aiMaterial = AIMaterial.create(aiMaterials.get(i));
        processMaterial(aiMaterial, materials, texturesDir);
    }

    int numMeshes = aiScene.mNumMeshes();
    PointerBuffer aiMeshes = aiScene.mMeshes();
    Mesh[] meshes = new Mesh[numMeshes];
    for (int i = 0; i < numMeshes; i++) {
        AIMesh aiMesh = AIMesh.create(aiMeshes.get(i));
        Mesh mesh = processMesh(aiMesh, materials);
        meshes[i] = mesh;
    }

    return meshes;
}
 
Example #7
Source File: LWJGUIDialog.java    From LWJGUI with MIT License 6 votes vote down vote up
/**
 * Opens a file open dialog.
 * 
 * @param title window title
 * @param defaultPath default file path
 * @param filterDescription description of the accepted file extension(s)
 * @param acceptedFileExtension the first accepted file extension (example: "txt", use * for all)
 * @param additionalAcceptedFileExtensions any additional accepted file extensions
 * 
 * @return the selected file
 */
public static File showOpenFileDialog(String title, File defaultPath, String filterDescription, String acceptedFileExtension, String... additionalAcceptedFileExtensions){

	MemoryStack stack = MemoryStack.stackPush();

	PointerBuffer filters = stack.mallocPointer(1 + additionalAcceptedFileExtensions.length);

       filters.put(stack.UTF8("*." + acceptedFileExtension));
       for(int i = 0; i < additionalAcceptedFileExtensions.length; i++){
		filters.put(stack.UTF8("*." + additionalAcceptedFileExtensions[i]));
       }

       filters.flip();

       defaultPath = defaultPath.getAbsoluteFile();
       String defaultString = defaultPath.getAbsolutePath();
       if(defaultPath.isDirectory() && !defaultString.endsWith(File.separator)){
       	defaultString += File.separator;
       }
       
       String result = TinyFileDialogs.tinyfd_openFileDialog(title, defaultString, filters, filterDescription, false);

	stack.pop();

	return result != null ? new File(result) : null; 
}
 
Example #8
Source File: AnimMeshesLoader.java    From lwjglbook with Apache License 2.0 6 votes vote down vote up
private static Map<String, Animation> processAnimations(AIScene aiScene, List<Bone> boneList,
        Node rootNode, Matrix4f rootTransformation) {
    Map<String, Animation> animations = new HashMap<>();

    // Process all animations
    int numAnimations = aiScene.mNumAnimations();
    PointerBuffer aiAnimations = aiScene.mAnimations();
    for (int i = 0; i < numAnimations; i++) {
        AIAnimation aiAnimation = AIAnimation.create(aiAnimations.get(i));

        // Calculate transformation matrices for each node
        int numChanels = aiAnimation.mNumChannels();
        PointerBuffer aiChannels = aiAnimation.mChannels();
        for (int j = 0; j < numChanels; j++) {
            AINodeAnim aiNodeAnim = AINodeAnim.create(aiChannels.get(j));
            String nodeName = aiNodeAnim.mNodeName().dataString();
            Node node = rootNode.findByName(nodeName);
            buildTransFormationMatrices(aiNodeAnim, node);
        }

        List<AnimatedFrame> frames = buildAnimationFrames(boneList, rootNode, rootTransformation);
        Animation animation = new Animation(aiAnimation.mName().dataString(), frames, aiAnimation.mDuration());
        animations.put(animation.getName(), animation);
    }
    return animations;
}
 
Example #9
Source File: ClearScreenDemo.java    From lwjgl3-swt with MIT License 6 votes vote down vote up
/**
 * This method will enumerate the physical devices (i.e. GPUs) the system has available for us, and will just return
 * the first one. 
 */
private static VkPhysicalDevice getFirstPhysicalDevice(VkInstance instance) {
    IntBuffer pPhysicalDeviceCount = memAllocInt(1);
    int err = vkEnumeratePhysicalDevices(instance, pPhysicalDeviceCount, null);
    if (err != VK_SUCCESS) {
        throw new AssertionError("Failed to get number of physical devices: " + translateVulkanResult(err));
    }
    PointerBuffer pPhysicalDevices = memAllocPointer(pPhysicalDeviceCount.get(0));
    err = vkEnumeratePhysicalDevices(instance, pPhysicalDeviceCount, pPhysicalDevices);
    long physicalDevice = pPhysicalDevices.get(0);
    memFree(pPhysicalDeviceCount);
    memFree(pPhysicalDevices);
    if (err != VK_SUCCESS) {
        throw new AssertionError("Failed to get physical devices: " + translateVulkanResult(err));
    }
    return new VkPhysicalDevice(physicalDevice, instance);
}
 
Example #10
Source File: ClearScreenDemo.java    From lwjgl3-swt with MIT License 6 votes vote down vote up
private static VkCommandBuffer createCommandBuffer(VkDevice device, long commandPool) {
    VkCommandBufferAllocateInfo cmdBufAllocateInfo = VkCommandBufferAllocateInfo.calloc()
            .sType(VK_STRUCTURE_TYPE_COMMAND_BUFFER_ALLOCATE_INFO)
            .commandPool(commandPool)
            .level(VK_COMMAND_BUFFER_LEVEL_PRIMARY)
            .commandBufferCount(1);
    PointerBuffer pCommandBuffer = memAllocPointer(1);
    int err = vkAllocateCommandBuffers(device, cmdBufAllocateInfo, pCommandBuffer);
    cmdBufAllocateInfo.free();
    long commandBuffer = pCommandBuffer.get(0);
    memFree(pCommandBuffer);
    if (err != VK_SUCCESS) {
        throw new AssertionError("Failed to allocate command buffer: " + translateVulkanResult(err));
    }
    return new VkCommandBuffer(commandBuffer, device);
}
 
Example #11
Source File: ClearScreenDemo.java    From lwjgl3-swt with MIT License 6 votes vote down vote up
private static void submitCommandBuffer(VkQueue queue, VkCommandBuffer commandBuffer) {
    if (commandBuffer == null || commandBuffer.address() == NULL)
        return;
    VkSubmitInfo submitInfo = VkSubmitInfo.calloc()
            .sType(VK_STRUCTURE_TYPE_SUBMIT_INFO);
    PointerBuffer pCommandBuffers = memAllocPointer(1)
            .put(commandBuffer)
            .flip();
    submitInfo.pCommandBuffers(pCommandBuffers);
    int err = vkQueueSubmit(queue, submitInfo, VK_NULL_HANDLE);
    memFree(pCommandBuffers);
    submitInfo.free();
    if (err != VK_SUCCESS) {
        throw new AssertionError("Failed to submit command buffer: " + translateVulkanResult(err));
    }
}
 
Example #12
Source File: PrimaryCmdBuffer.java    From oreon-engine with GNU General Public License v3.0 6 votes vote down vote up
public void record(long renderPass, long frameBuffer,
		int width, int height, int colorAttachmentCount, int depthAttachment,
		PointerBuffer secondaryCmdBuffers){
	
	beginRecord(VK_COMMAND_BUFFER_USAGE_RENDER_PASS_CONTINUE_BIT);
	beginRenderPassCmd(renderPass, frameBuffer, width, height,
			colorAttachmentCount, depthAttachment,
			VK_SUBPASS_CONTENTS_SECONDARY_COMMAND_BUFFERS);
	
	if (secondaryCmdBuffers != null){
		recordSecondaryCmdBuffers(secondaryCmdBuffers);
	}
	
	endRenderPassCmd();
    finishRecord();
}
 
Example #13
Source File: PrimaryCmdBuffer.java    From oreon-engine with GNU General Public License v3.0 6 votes vote down vote up
public void record(long renderPass, long frameBuffer,
		int width, int height, int colorAttachmentCount, int depthAttachment,
		Vec3f clearColor, PointerBuffer secondaryCmdBuffers){
	
	beginRecord(VK_COMMAND_BUFFER_USAGE_RENDER_PASS_CONTINUE_BIT);
	beginRenderPassCmd(renderPass, frameBuffer, width, height,
			colorAttachmentCount, depthAttachment,
			VK_SUBPASS_CONTENTS_SECONDARY_COMMAND_BUFFERS,
			clearColor);
	if (secondaryCmdBuffers != null){
		recordSecondaryCmdBuffers(secondaryCmdBuffers);
	}
	
	endRenderPassCmd();
    finishRecord();
}
 
Example #14
Source File: VkUtil.java    From oreon-engine with GNU General Public License v3.0 6 votes vote down vote up
public static PointerBuffer createPointerBuffer(Collection<CommandBuffer> commandBuffers){
  	
  	if (commandBuffers.size() == 0){
  		log.info("createPointerBuffer: commandBuffers empty");
  		return null;
  	}
  	
  	PointerBuffer cmdBuffersPointer = memAllocPointer(commandBuffers.size());

for (CommandBuffer cmdBuffer : commandBuffers){
	cmdBuffersPointer.put(cmdBuffer.getHandlePointer());
}

cmdBuffersPointer.flip();

return cmdBuffersPointer;
  }
 
Example #15
Source File: LwjglProgram.java    From jmonkeyengine with BSD 3-Clause "New" or "Revised" License 6 votes vote down vote up
@Override
public void build(String args, Device... devices) throws KernelCompilationException {
    PointerBuffer deviceList = null;
    if (devices != null) {
        deviceList = PointerBuffer.allocateDirect(devices.length);
        deviceList.rewind();
        for (Device d : devices) {
            deviceList.put(((LwjglDevice) d).device.getPointer());
        }
        deviceList.flip();
    }
    int ret = CL10.clBuildProgram(program, deviceList, args, null);
    if (ret != CL10.CL_SUCCESS) {
        String log = Log();
        LOG.log(Level.WARNING, "Unable to compile program:\n{0}", log);
        if (ret == CL10.CL_BUILD_PROGRAM_FAILURE) {
            throw new KernelCompilationException("Failed to build program", ret, log);
        } else {
            Utils.checkError(ret, "clBuildProgram");
        }
    } else {
        LOG.log(Level.INFO, "Program compiled:\n{0}", Log());
    }
}
 
Example #16
Source File: LwjglKernel.java    From jmonkeyengine with BSD 3-Clause "New" or "Revised" License 6 votes vote down vote up
@Override
 public Event Run(CommandQueue queue) {
     Utils.pointerBuffers[0].rewind();
     Utils.pointerBuffers[1].rewind();
     Utils.pointerBuffers[1].put(globalWorkSize.getSizes());
     Utils.pointerBuffers[1].position(0);
     PointerBuffer p2 = null;
     if (workGroupSize.getSizes()[0] > 0) {
         p2 = Utils.pointerBuffers[2].rewind();
         p2.put(workGroupSize.getSizes());
         p2.position(0);
     }
     CLCommandQueue q = ((LwjglCommandQueue) queue).getQueue();
     int ret = CL10.clEnqueueNDRangeKernel(q, kernel,
globalWorkSize.getDimension(), null, Utils.pointerBuffers[1],
p2, null, Utils.pointerBuffers[0]);
     Utils.checkError(ret, "clEnqueueNDRangeKernel");
     return new LwjglEvent(q.getCLEvent(Utils.pointerBuffers[0].get(0)));
 }
 
Example #17
Source File: LwjglKernel.java    From jmonkeyengine with BSD 3-Clause "New" or "Revised" License 6 votes vote down vote up
@Override
 public void RunNoEvent(CommandQueue queue) {
     Utils.pointerBuffers[1].rewind();
     Utils.pointerBuffers[1].put(globalWorkSize.getSizes());
     Utils.pointerBuffers[1].position(0);
     PointerBuffer p2 = null;
     if (workGroupSize.getSizes()[0] > 0) {
         p2 = Utils.pointerBuffers[2].rewind();
         p2.put(workGroupSize.getSizes());
         p2.position(0);
     }
     CLCommandQueue q = ((LwjglCommandQueue) queue).getQueue();
     int ret = CL10.clEnqueueNDRangeKernel(q, kernel,
globalWorkSize.getDimension(), null, Utils.pointerBuffers[1],
p2, null, null);
     Utils.checkError(ret, "clEnqueueNDRangeKernel");
 }
 
Example #18
Source File: LwjglContext.java    From jmonkeyengine with BSD 3-Clause "New" or "Revised" License 6 votes vote down vote up
/**
 * Returns a list of the available platforms, filtered by the specified
 * filter.
 * <p>
 * Copied from the old release
 *
 * @return the available platforms
 */
private static long[] getPlatforms() {
    try (MemoryStack stack = MemoryStack.stackPush()) {

        final IntBuffer countBuffer = stack.callocInt(1);
        int errcode = CL10.clGetPlatformIDs(null, countBuffer);
        Utils.checkError(errcode, "clGetDeviceIDs");

        final int count = countBuffer.get();
        final PointerBuffer pointer = stack.callocPointer(count);

        errcode = CL10.clGetPlatformIDs(pointer, (IntBuffer) null);
        Utils.checkError(errcode, "clGetDeviceIDs");

        final long[] platformIDs = new long[count];
        for (int i = 0; i < count; i++) {
            platformIDs[i] = pointer.get();
        }

        return platformIDs;
    }
}
 
Example #19
Source File: LwjglKernel.java    From jmonkeyengine with BSD 3-Clause "New" or "Revised" License 6 votes vote down vote up
@Override
 public void RunNoEvent(CommandQueue queue) {
     Utils.pointerBuffers[1].rewind();
     Utils.pointerBuffers[1].put(globalWorkSize.getSizes());
     Utils.pointerBuffers[1].position(0);
     PointerBuffer p2 = null;
     if (workGroupSize.getSizes()[0] > 0) {
         p2 = Utils.pointerBuffers[2].rewind();
         p2.put(workGroupSize.getSizes());
         p2.position(0);
     }
     long q = ((LwjglCommandQueue) queue).getQueue();
     int ret = CL10.clEnqueueNDRangeKernel(q, kernel,
globalWorkSize.getDimension(), null, Utils.pointerBuffers[1],
p2, null, null);
     Utils.checkError(ret, "clEnqueueNDRangeKernel");
 }
 
Example #20
Source File: LwjglKernel.java    From jmonkeyengine with BSD 3-Clause "New" or "Revised" License 6 votes vote down vote up
@Override
 public Event Run(CommandQueue queue) {
     Utils.pointerBuffers[0].rewind();
     Utils.pointerBuffers[1].rewind();
     Utils.pointerBuffers[1].put(globalWorkSize.getSizes());
     Utils.pointerBuffers[1].position(0);
     PointerBuffer p2 = null;
     if (workGroupSize.getSizes()[0] > 0) {
         p2 = Utils.pointerBuffers[2].rewind();
         p2.put(workGroupSize.getSizes());
         p2.position(0);
     }
     long q = ((LwjglCommandQueue) queue).getQueue();
     int ret = CL10.clEnqueueNDRangeKernel(q, kernel,
globalWorkSize.getDimension(), null, Utils.pointerBuffers[1],
p2, null, Utils.pointerBuffers[0]);
     Utils.checkError(ret, "clEnqueueNDRangeKernel");
     return new LwjglEvent(Utils.pointerBuffers[0].get(0));
 }
 
Example #21
Source File: LmdbLwjgl.java    From benchmarks with Apache License 2.0 5 votes vote down vote up
public void setup(final BenchmarkParams b, final boolean sync) throws
    IOException {
  super.setup(b);

  try (MemoryStack stack = stackPush()) {
    final PointerBuffer pp = stack.mallocPointer(1);

    E(mdb_env_create(pp));
    env = pp.get(0);

    E(mdb_env_set_maxdbs(env, 1));
    E(mdb_env_set_maxreaders(env, 2));
    E(mdb_env_set_mapsize(env, mapSize(num, valSize)));

    // Open environment
    E(mdb_env_open(env, tmp.getPath(), envFlags(writeMap, sync), POSIX_MODE));

    // Open database
    E(mdb_txn_begin(env, NULL, 0, pp));
    final long txn = pp.get(0);

    final IntBuffer ip = stack.mallocInt(1);
    E(mdb_dbi_open(txn, "db", dbiFlags(intKey), ip));
    db = ip.get(0);

    mdb_txn_commit(txn);
  }
}
 
Example #22
Source File: LwjglProgram.java    From jmonkeyengine with BSD 3-Clause "New" or "Revised" License 5 votes vote down vote up
@Override
public ByteBuffer getBinary(Device d) {
    //throw new UnsupportedOperationException("Not supported yet, would crash the JVM");
    
    LwjglDevice device = (LwjglDevice) d;
    int numDevices = Info.clGetProgramInfoInt(program, CL10.CL_PROGRAM_NUM_DEVICES);
    
    PointerBuffer devices = PointerBuffer.allocateDirect(numDevices);
    int ret = CL10.clGetProgramInfo(program, CL10.CL_PROGRAM_DEVICES, devices, null);
    Utils.checkError(ret, "clGetProgramInfo: CL_PROGRAM_DEVICES");
    int index = -1;
    for (int i=0; i<numDevices; ++i) {
        if (devices.get(i) == device.getDevice()) {
            index = i;
        }
    }
    if (index == -1) {
         throw new com.jme3.opencl.OpenCLException("Program was not built against the specified device "+device);
    }
    
    PointerBuffer sizes = PointerBuffer.allocateDirect(numDevices);
    ret = CL10.clGetProgramInfo(program, CL10.CL_PROGRAM_BINARY_SIZES, sizes, null);
    Utils.checkError(ret, "clGetProgramInfo: CL_PROGRAM_BINARY_SIZES");
    int size = (int) sizes.get(index);
    
    PointerBuffer binaryPointers = PointerBuffer.allocateDirect(numDevices);
    for (int i=0; i<binaryPointers.capacity(); ++i) {
        binaryPointers.put(0L);
    }
    binaryPointers.rewind();
    ByteBuffer binaries = ByteBuffer.allocateDirect(size);
    binaryPointers.put(index, binaries);
    
    //Fixme: why the hell does this line throw a segfault ?!?
    ret = CL10.clGetProgramInfo(program, CL10.CL_PROGRAM_BINARIES, binaryPointers, null);
    Utils.checkError(ret, "clGetProgramInfo: CL_PROGRAM_BINARIES");
    
    return binaries;
}
 
Example #23
Source File: LwjglDevice.java    From jmonkeyengine with BSD 3-Clause "New" or "Revised" License 5 votes vote down vote up
@Override
public long[] getMaximumWorkItemSizes() {
    int dim = (int) getMaximumWorkItemDimensions();
    PointerBuffer sizes = PointerBuffer.allocateDirect(dim);
    Info.clGetDeviceInfoPointers(device, CL10.CL_DEVICE_MAX_WORK_ITEM_SIZES, sizes);
    long[] sx = new long[dim];
    sizes.get(sx);
    return sx;
}
 
Example #24
Source File: LwjglProgram.java    From jmonkeyengine with BSD 3-Clause "New" or "Revised" License 5 votes vote down vote up
@Override
public Kernel[] createAllKernels() {
    Utils.tempBuffers[0].b16i.rewind();
    int ret = CL10.clCreateKernelsInProgram(program, null, Utils.tempBuffers[0].b16i);
    Utils.checkError(ret, "clCreateKernelsInProgram");
    int count = Utils.tempBuffers[0].b16i.get(0);
    PointerBuffer buf = PointerBuffer.allocateDirect(count);
    ret = CL10.clCreateKernelsInProgram(program, buf, (IntBuffer) null);
    Utils.checkError(ret, "clCreateKernelsInProgram");
    Kernel[] kx = new Kernel[count];
    for (int i=0; i<count; ++i) {
        kx[i] = new LwjglKernel(buf.get());
    }
    return kx;
}
 
Example #25
Source File: EGLContextCreator.java    From settlers-remake with MIT License 5 votes vote down vote up
private void setEGLDebugFunction(boolean info, boolean warning, boolean error_arg, boolean critical) {
	try(MemoryStack stack = MemoryStack.stackPush()) {

		IntBuffer debug = stack.ints(
				KHRDebug.EGL_DEBUG_MSG_CRITICAL_KHR, critical ? EGL10.EGL_TRUE : EGL10.EGL_FALSE,
				KHRDebug.EGL_DEBUG_MSG_ERROR_KHR, error_arg ? EGL10.EGL_TRUE : EGL10.EGL_FALSE,
				KHRDebug.EGL_DEBUG_MSG_WARN_KHR, warning ? EGL10.EGL_TRUE : EGL10.EGL_FALSE,
				KHRDebug.EGL_DEBUG_MSG_INFO_KHR, info ? EGL10.EGL_TRUE : EGL10.EGL_FALSE
		);

		PointerBuffer bfr = stack.pointers(MemoryUtil.memAddress(debug));

		KHRDebug.eglDebugMessageControlKHR(
				(error, command, messageType, threadLabel, objectLabel, message) -> {
					String command_str = EGLDebugMessageKHRCallback.getCommand(command);
					String message_str = EGLDebugMessageKHRCallback.getMessage(message);

					System.out.println("[EGL] Debug Message");
					System.out.println("    error: " + error);
					System.out.println("    command: " + command_str);
					System.out.println("    messageType: " + messageType);
					System.out.println("    threadLabel: " + threadLabel);
					System.out.println("    objectLabel: " + objectLabel);
					System.out.println("    message: " + message_str);
				}, bfr);

	}
	System.out.println("egl error: " + EGL10.eglGetError());
}
 
Example #26
Source File: AnimMeshesLoader.java    From lwjglbook with Apache License 2.0 5 votes vote down vote up
public static AnimGameItem loadAnimGameItem(String resourcePath, String texturesDir, int flags)
        throws Exception {
    AIScene aiScene = aiImportFile(resourcePath, flags);
    if (aiScene == null) {
        throw new Exception("Error loading model");
    }

    int numMaterials = aiScene.mNumMaterials();
    PointerBuffer aiMaterials = aiScene.mMaterials();
    List<Material> materials = new ArrayList<>();
    for (int i = 0; i < numMaterials; i++) {
        AIMaterial aiMaterial = AIMaterial.create(aiMaterials.get(i));
        processMaterial(aiMaterial, materials, texturesDir);
    }

    List<Bone> boneList = new ArrayList<>();
    int numMeshes = aiScene.mNumMeshes();
    PointerBuffer aiMeshes = aiScene.mMeshes();
    Mesh[] meshes = new Mesh[numMeshes];
    for (int i = 0; i < numMeshes; i++) {
        AIMesh aiMesh = AIMesh.create(aiMeshes.get(i));
        Mesh mesh = processMesh(aiMesh, materials, boneList);
        meshes[i] = mesh;
    }

    AINode aiRootNode = aiScene.mRootNode();
    Matrix4f rootTransfromation = AnimMeshesLoader.toMatrix(aiRootNode.mTransformation());
    Node rootNode = processNodesHierarchy(aiRootNode, null);
    Map<String, Animation> animations = processAnimations(aiScene, boneList, rootNode, rootTransfromation);
    AnimGameItem item = new AnimGameItem(meshes, animations);

    return item;
}
 
Example #27
Source File: EGLContextCreator.java    From settlers-remake with MIT License 5 votes vote down vote up
protected void initStatic() {
	if(egl_display != 0) return;

	egl_display = EGL10.eglGetDisplay(EGL14.EGL_DEFAULT_DISPLAY);
	EGL10.eglInitialize(egl_display, new int[] {1}, new int[] {1});
	EGLCapabilities caps = EGL.createDisplayCapabilities(egl_display);

	if(debug && caps.EGL_KHR_debug) setEGLDebugFunction(true, true, true, true);

	if(!caps.EGL14 || !EGL12.eglBindAPI(EGL14.EGL_OPENGL_API)) throw new Error("could not bind OpenGL");

	int[] attrs = {EGL13.EGL_CONFORMANT, EGL14.EGL_OPENGL_BIT,
			EGL10.EGL_STENCIL_SIZE, 1,
			EGL10.EGL_NONE};
	PointerBuffer cfgs = BufferUtils.createPointerBuffer(1);
	int[] num_config = new int[1];

	EGL10.eglChooseConfig(egl_display, attrs, cfgs, num_config);
	if(num_config[0] == 0) throw new Error("could not found egl configs!");
	egl_config = cfgs.get(0);

	int i = debug ? 0 : 4;
	while(egl_context == 0 && ctx_attrs.length > i) {
		int[] current_ctx_attrs = ctx_attrs[i];

		egl_context = EGL10.eglCreateContext(egl_display, egl_config, 0, current_ctx_attrs);
		i++;
		if(egl_context != 0 && EGL10.eglGetError() != EGL10.EGL_SUCCESS) {
			EGL10.eglDestroyContext(egl_display, egl_context);
			egl_context = 0;
		}
	}
}
 
Example #28
Source File: GLXContextCreator.java    From settlers-remake with MIT License 5 votes vote down vote up
@Override
protected void onInit() {
	int screen = X11.XDefaultScreen(windowConnection);

	int[] xvi_attrs = new int[]{
			GLX.GLX_RGBA,
			GLX.GLX_DOUBLEBUFFER,
			GLX.GLX_STENCIL_SIZE, 1,
			0};

	GLXCapabilities glxcaps = GL.createCapabilitiesGLX(windowConnection, screen);
	if(glxcaps.GLX13 && glxcaps.GLX_ARB_create_context && glxcaps.GLX_ARB_create_context_profile) {
		PointerBuffer fbc = GLX13.glXChooseFBConfig(windowConnection, screen, new int[] {0});
		if(fbc == null || fbc.capacity() < 1) throw new Error("GLX could not find any FBConfig!");

		int i = debug ? 0 : 3;
		while(context == 0 && ctx_attrs.length > i) {
			context = GLXARBCreateContext.glXCreateContextAttribsARB(windowConnection, fbc.get(), 0, true, ctx_attrs[i]);
		}
	} else {
		if(debug) throw new Error("GLX could not create a debug context!");

		XVisualInfo xvi = GLX.glXChooseVisual(windowConnection, screen, xvi_attrs);
		context = GLX.glXCreateContext(windowConnection, xvi, 0, true);
	}
	if (context == 0) throw new Error("Could not create GLX context!");
	parent.wrapNewContext();
}
 
Example #29
Source File: Lwjgl3Mini2DxGraphics.java    From mini2Dx with Apache License 2.0 5 votes vote down vote up
@Override
public Monitor[] getMonitors() {
	PointerBuffer glfwMonitors = GLFW.glfwGetMonitors();
	Monitor[] monitors = new Monitor[glfwMonitors.limit()];
	for (int i = 0; i < glfwMonitors.limit(); i++) {
		monitors[i] = Lwjgl3ApplicationConfiguration.toLwjgl3Monitor(glfwMonitors.get(i));
	}
	return monitors;
}
 
Example #30
Source File: SimpleDemo.java    From lwjgl3-awt with MIT License 5 votes vote down vote up
/**
 * Create a Vulkan instance using LWJGL 3.
 * 
 * @return the VkInstance handle
 */
private static VkInstance createInstance() {
    VkApplicationInfo appInfo = VkApplicationInfo.calloc()
            .sType(VK_STRUCTURE_TYPE_APPLICATION_INFO)
            .pApplicationName(memUTF8("AWT Vulkan Demo"))
            .pEngineName(memUTF8(""))
            .apiVersion(VK_MAKE_VERSION(1, 0, 2));
    ByteBuffer VK_KHR_SURFACE_EXTENSION = memUTF8(VK_KHR_SURFACE_EXTENSION_NAME);
    ByteBuffer VK_KHR_OS_SURFACE_EXTENSION;
    if (Platform.get() == Platform.WINDOWS)
        VK_KHR_OS_SURFACE_EXTENSION = memUTF8(VK_KHR_WIN32_SURFACE_EXTENSION_NAME);
    else
        VK_KHR_OS_SURFACE_EXTENSION = memUTF8(VK_KHR_XLIB_SURFACE_EXTENSION_NAME);
    PointerBuffer ppEnabledExtensionNames = memAllocPointer(2);
    ppEnabledExtensionNames.put(VK_KHR_SURFACE_EXTENSION);
    ppEnabledExtensionNames.put(VK_KHR_OS_SURFACE_EXTENSION);
    ppEnabledExtensionNames.flip();
    VkInstanceCreateInfo pCreateInfo = VkInstanceCreateInfo.calloc()
            .sType(VK_STRUCTURE_TYPE_INSTANCE_CREATE_INFO)
            .pNext(0L)
            .pApplicationInfo(appInfo);
    if (ppEnabledExtensionNames.remaining() > 0) {
        pCreateInfo.ppEnabledExtensionNames(ppEnabledExtensionNames);
    }
    PointerBuffer pInstance = MemoryUtil.memAllocPointer(1);
    int err = vkCreateInstance(pCreateInfo, null, pInstance);
    if (err != VK_SUCCESS) {
        throw new RuntimeException("Failed to create VkInstance: " + translateVulkanResult(err));
    }
    long instance = pInstance.get(0);
    memFree(pInstance);
    VkInstance ret = new VkInstance(instance, pCreateInfo);
    memFree(ppEnabledExtensionNames);
    memFree(VK_KHR_OS_SURFACE_EXTENSION);
    memFree(VK_KHR_SURFACE_EXTENSION);
    appInfo.free();
    return ret;
}