/** * Loads one or more meshes at the specified resource path with * the textures at the specified texture path with the specified flags. * * @param resourcePath - Path for the mesh resource to load. * @param texturesDir - Path for the textures to use for the mesh. * @param flags - Flags for the Assimp importer to use. * * @return Mesh array with the loaded meshes. * * @throws Exception */ public static Mesh[] load(String resourcePath, String texturesDir, int flags) throws Exception { AIScene aiScene = Assimp.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; }
public static int glCreateShaderProgramv(int type, PointerBuffer strings) { int shader = org.lwjgl.opengl.ARBSeparateShaderObjects.glCreateShaderProgramv(type, strings); if (TRACE.enabled) { /* Log the shader source */ StringBuilder sb = new StringBuilder(); if (strings != null) { int stringsPos = strings.position(); for (int i = 0; i < strings.remaining(); i++) { String source = org.lwjgl.system.MemoryUtil.memASCII(strings.get(stringsPos + i)); sb.append(source); } } trace("Shader source for shader [" + shader + "]:\n" + sb.toString()); } return shader; }
public static int glCreateShaderProgramv(int type, PointerBuffer strings) { int shader = org.lwjgl.opengl.GL41.glCreateShaderProgramv(type, strings); if (TRACE.enabled) { /* Log the shader source */ StringBuilder sb = new StringBuilder(); if (strings != null) { int stringsPos = strings.position(); for (int i = 0; i < strings.remaining(); i++) { String source = org.lwjgl.system.MemoryUtil.memASCII(strings.get(stringsPos + i)); sb.append(source); } } trace("Shader source for shader [" + shader + "]:\n" + sb.toString()); } return shader; }
private long create(int depth, GLData attribs, GLData effective) throws AWTException { int screen = X11.XDefaultScreen(display); IntBuffer attrib_list = BufferUtils.createIntBuffer(16 * 2); attrib_list.put(GLX_DRAWABLE_TYPE).put(GLX_WINDOW_BIT); attrib_list.put(GLX_RENDER_TYPE).put(GLX_RGBA_BIT); attrib_list.put(GLX_RED_SIZE).put(attribs.redSize); attrib_list.put(GLX_GREEN_SIZE).put(attribs.greenSize); attrib_list.put(GLX_BLUE_SIZE).put(attribs.blueSize); attrib_list.put(GLX_DEPTH_SIZE).put(attribs.depthSize); if (attribs.doubleBuffer) attrib_list.put(GLX_DOUBLEBUFFER).put(1); attrib_list.put(0); attrib_list.flip(); PointerBuffer fbConfigs = glXChooseFBConfig(display, screen, attrib_list); if (fbConfigs == null || fbConfigs.capacity() == 0) { // No framebuffer configurations supported! throw new AWTException("No supported framebuffer configurations found"); } long context = glXCreateNewContext(display, fbConfigs.get(0), GLX_RGBA_TYPE, NULL, true); return context; }
/** * Calculates the number of bytes in the specified cl_mem image region. * This implementation assumes 1 byte per element, because we cannot the * image type. * * @param region the image region * @param row_pitch the row pitch * @param slice_pitch the slice pitch * * @return the region size in bytes */ static int calculateImageSize(final PointerBuffer region, long row_pitch, long slice_pitch) { if ( !LWJGLUtil.CHECKS ) return 0; final long w = region.get(0); final long h = region.get(1); final long d = region.get(2); if ( LWJGLUtil.DEBUG && (w < 1 || h < 1 || d < 1) ) throw new IllegalArgumentException("Invalid cl_mem image region dimensions: " + w + " x " + h + " x " + d); if ( row_pitch == 0 ) row_pitch = w; else if ( LWJGLUtil.DEBUG && row_pitch < w ) throw new IllegalArgumentException("Invalid row pitch specified: " + row_pitch); if ( slice_pitch == 0 ) slice_pitch = row_pitch * h; else if ( LWJGLUtil.DEBUG && slice_pitch < (row_pitch * h) ) throw new IllegalArgumentException("Invalid slice pitch specified: " + slice_pitch); return (int)(slice_pitch * d); }
public static PrimitiveType.Kind getPrimitiveKindFromBufferClass(Class c) { if ( IntBuffer.class.equals(c) ) return PrimitiveType.Kind.INT; else if ( DoubleBuffer.class.equals(c) ) return PrimitiveType.Kind.DOUBLE; else if ( ShortBuffer.class.equals(c) ) return PrimitiveType.Kind.SHORT; else if ( ByteBuffer.class.equals(c) || PointerBuffer.class.equals(c) ) return PrimitiveType.Kind.BYTE; else if ( FloatBuffer.class.equals(c) ) return PrimitiveType.Kind.FLOAT; else if ( LongBuffer.class.equals(c) ) return PrimitiveType.Kind.LONG; else throw new RuntimeException(c + " is not allowed"); }
public void visitClassType(ClassType t) { is_indirect = true; Class<?> c = getClassFromType(t); if ( String.class.equals(c) ) { native_types = new ArrayList<Class>(); native_types.add(type_map.getStringElementType()); } else if ( Buffer.class.equals(c) ) { native_types = new ArrayList<Class>(); native_types.add(type_map.getVoidType()); } else if ( Buffer.class.isAssignableFrom(c) ) { PrimitiveType.Kind kind = getPrimitiveKindFromBufferClass(c); getNativeTypeFromAnnotatedPrimitiveType(kind); } else if ( PointerBuffer.class.isAssignableFrom(c) ) { native_types = new ArrayList<Class>(); native_types.add(PointerBuffer.class); } else if ( org.lwjgl.PointerWrapper.class.isAssignableFrom(c) ) { native_types = new ArrayList<Class>(); native_types.add(PointerWrapper.class); is_indirect = false; } else throw new RuntimeException(t + " is not allowed"); }
private static Class[] getValidBufferTypes(Class type) { if ( type.equals(IntBuffer.class) ) return new Class[] { cl_int.class, cl_uint.class }; else if ( type.equals(FloatBuffer.class) ) return new Class[] { cl_float.class }; else if ( type.equals(ByteBuffer.class) ) return new Class[] { cl_byte.class, cl_char.class, cl_uchar.class, cl_void.class }; else if ( type.equals(ShortBuffer.class) ) return new Class[] { cl_short.class }; else if ( type.equals(DoubleBuffer.class) ) return new Class[] { cl_double.class }; else if ( type.equals(LongBuffer.class) ) return new Class[] { cl_long.class }; else if ( type.equals(PointerBuffer.class) ) return new Class[] { size_t.class }; else return new Class[] { }; }
public Class[] getValidAnnotationTypes(Class type) { Class[] valid_types; if ( Buffer.class.isAssignableFrom(type) || PointerBuffer.class.isAssignableFrom(type) ) valid_types = getValidBufferTypes(type); else if ( type.isPrimitive() ) valid_types = getValidPrimitiveTypes(type); else if ( String.class.equals(type) ) valid_types = new Class[] { cl_byte.class }; else if ( org.lwjgl.PointerWrapper.class.isAssignableFrom(type) ) valid_types = new Class[] { PointerWrapper.class }; else if ( ByteBuffer[].class == type ) valid_types = new Class[] { cl_char.class, cl_uchar.class }; else if ( void.class.equals(type) ) valid_types = new Class[] { GLreturn.class }; else valid_types = new Class[] { }; return valid_types; }
public void visitClassType(ClassType t) { Class type = NativeTypeTranslator.getClassFromType(t); if ( org.lwjgl.PointerWrapper.class.isAssignableFrom(type) || (Utils.isAddressableType(type) && !String.class.equals(type)) ) signature.append("J"); else { String type_name; if ( (CharSequence.class.isAssignableFrom(type) && !String.class.equals(type)) || CharSequence[].class.isAssignableFrom(type) || PointerBuffer.class.isAssignableFrom(type) ) type_name = ByteBuffer.class.getName(); else type_name = t.getDeclaration().getQualifiedName(); signature.append("L"); signature.append(getNativeNameFromClassName(type_name)); signature.append(";"); } }
/** LWJGL requires CL_CONTEXT_PLATFORM to be present in the cl_context_properties buffer. */ @Alternate("clCreateContext") @Code( tryBlock = true, // Create a GlobalRef to the callback object. javaBeforeNative = "\t\tlong user_data = pfn_notify == null || pfn_notify.isCustom() ? 0 : CallbackUtil.createGlobalRef(pfn_notify);", // Associate context with the GlobalRef, so we can delete it later. javaFinally = "\t\t\tif ( __result != null ) __result.setContextCallback(user_data);" ) @Check(value = "errcode_ret", canBeNull = true) @PointerWrapper(value = "cl_context", params = "APIUtil.getCLPlatform(properties)") CLContext clCreateContext(@NullTerminated @Check("3") @Const @NativeType("cl_context_properties") PointerBuffer properties, @Constant("1") @cl_uint int num_devices, @Constant(value = "APIUtil.getPointer(device)", keepParam = true) CLDevice device, @PointerWrapper(value = "cl_create_context_callback", canBeNull = true) CLContextCallback pfn_notify, @Constant("user_data") @PointerWrapper("void *") long user_data, @OutParameter @Check(value = "1", canBeNull = true) @cl_int IntBuffer errcode_ret);
@Code(javaAfterNative = "\t\tif ( __result == CL_SUCCESS ) command_queue.registerCLEvent(event);") @cl_int int clEnqueueReadBuffer(@PointerWrapper("cl_command_queue") CLCommandQueue command_queue, @PointerWrapper("cl_mem") CLMem buffer, @cl_bool int blocking_read, @size_t long offset, @AutoSize("ptr") @size_t long size, @OutParameter @cl_byte @cl_short @cl_int @cl_long @cl_float @cl_double Buffer ptr, @AutoSize(value = "event_wait_list", canBeNull = true) @cl_uint int num_events_in_wait_list, @Check(canBeNull = true) @Const @NativeType("cl_event") PointerBuffer event_wait_list, @OutParameter @Check(value = "1", canBeNull = true) @NativeType("cl_event") PointerBuffer event);
@Code(javaAfterNative = "\t\tif ( __result == CL_SUCCESS ) command_queue.registerCLEvent(event);") @cl_int int clEnqueueWriteBuffer(@PointerWrapper("cl_command_queue") CLCommandQueue command_queue, @PointerWrapper("cl_mem") CLMem buffer, @cl_bool int blocking_write, @size_t long offset, @AutoSize("ptr") @size_t long size, @Const @cl_byte @cl_short @cl_int @cl_long @cl_float @cl_double Buffer ptr, @AutoSize(value = "event_wait_list", canBeNull = true) @cl_uint int num_events_in_wait_list, @Check(canBeNull = true) @Const @NativeType("cl_event") PointerBuffer event_wait_list, @OutParameter @Check(value = "1", canBeNull = true) @NativeType("cl_event") PointerBuffer event);
@Code(javaAfterNative = "\t\tif ( __result == CL_SUCCESS ) command_queue.registerCLEvent(event);") @cl_int int clEnqueueReadImage(@PointerWrapper("cl_command_queue") CLCommandQueue command_queue, @PointerWrapper("cl_mem") CLMem image, @cl_bool int blocking_read, @Check("3") @Const @NativeType("size_t") PointerBuffer origin, @Check("3") @Const @NativeType("size_t") PointerBuffer region, @size_t long row_pitch, @size_t long slice_pitch, @OutParameter @Check("CLChecks.calculateImageSize(region, row_pitch, slice_pitch)") @cl_byte @cl_short @cl_int @cl_float Buffer ptr, @AutoSize(value = "event_wait_list", canBeNull = true) @cl_uint int num_events_in_wait_list, @Check(canBeNull = true) @Const @NativeType("cl_event") PointerBuffer event_wait_list, @OutParameter @Check(value = "1", canBeNull = true) @NativeType("cl_event") PointerBuffer event);
@Code(javaAfterNative = "\t\tif ( __result == CL_SUCCESS ) command_queue.registerCLEvent(event);") @cl_int int clEnqueueWriteImage(@PointerWrapper("cl_command_queue") CLCommandQueue command_queue, @PointerWrapper("cl_mem") CLMem image, @cl_bool int blocking_write, @Check("3") @Const @NativeType("size_t") PointerBuffer origin, @Check("3") @Const @NativeType("size_t") PointerBuffer region, @size_t long input_row_pitch, @size_t long input_slice_pitch, @Check("CLChecks.calculateImageSize(region, input_row_pitch, input_slice_pitch)") @Const @cl_byte @cl_short @cl_int @cl_float Buffer ptr, @AutoSize(value = "event_wait_list", canBeNull = true) @cl_uint int num_events_in_wait_list, @Check(canBeNull = true) @Const @NativeType("cl_event") PointerBuffer event_wait_list, @OutParameter @Check(value = "1", canBeNull = true) @NativeType("cl_event") PointerBuffer event);
@Code(javaAfterNative = "\t\tif ( __result != null ) command_queue.registerCLEvent(event);") @Check(value = "errcode_ret", canBeNull = true) @cl_void @AutoSize(value = "extcl_CalculateImageSize(region_address, *image_row_pitch_address, image_slice_pitch_address == NULL ? 0 : *image_slice_pitch_address)", isNative = true) ByteBuffer clEnqueueMapImage(@PointerWrapper("cl_command_queue") CLCommandQueue command_queue, @PointerWrapper("cl_mem") CLMem image, @cl_bool int blocking_map, @NativeType("cl_map_flags") long map_flags, @Check("3") @Const @NativeType("size_t") PointerBuffer origin, @Check("3") @Const @NativeType("size_t") PointerBuffer region, @OutParameter @Check("1") @NativeType("size_t") PointerBuffer image_row_pitch, @OutParameter @Check(value = "1", canBeNull = true) @NativeType("size_t") PointerBuffer image_slice_pitch, @AutoSize(value = "event_wait_list", canBeNull = true) @cl_uint int num_events_in_wait_list, @Check(canBeNull = true) @Const @NativeType("cl_event") PointerBuffer event_wait_list, @OutParameter @Check(value = "1", canBeNull = true) @NativeType("cl_event") PointerBuffer event, @OutParameter @Check(value = "1", canBeNull = true) @cl_int IntBuffer errcode_ret);
@Alternate("clBuildProgram") @Code( tryBlock = true, // Create a GlobalRef to the callback object. javaBeforeNative = "\t\tlong user_data = CallbackUtil.createGlobalRef(pfn_notify);\n" + "\t\tif ( pfn_notify != null ) pfn_notify.setContext(program.getParent());", // Check if we need to delete the GlobalRef. javaFinally = "\t\t\tCallbackUtil.checkCallback(__result, user_data);" ) @cl_int int clBuildProgram(@PointerWrapper("cl_program") CLProgram program, @AutoSize(value = "device_list", canBeNull = true) @cl_uint int num_devices, @Check(canBeNull = true) @Const @NativeType("cl_device_id") PointerBuffer device_list, @NullTerminated @Const CharSequence options, @PointerWrapper(value = "cl_program_callback", canBeNull = true) CLBuildProgramCallback pfn_notify, @Constant("user_data") @PointerWrapper("void *") long user_data);
/** * Returns the handle to the first physical device connected to the system. * * @param instance The instance of the vulkan * * @return The handle to the first physical device. */ public static VkPhysicalDevice getFirstPhysicalDevice(VkInstance instance) { IntBuffer gpuCount = memAllocInt(1); vkEnumeratePhysicalDevices(instance, gpuCount, null); PointerBuffer devices = memAllocPointer(gpuCount.get(0)); vkEnumeratePhysicalDevices(instance, gpuCount, devices); VkPhysicalDevice firstPhysicalDevice = new VkPhysicalDevice(devices.get(0), instance); memFree(gpuCount); memFree(devices); return firstPhysicalDevice; }
@Code(javaAfterNative = "\t\tif ( __result == CL10.CL_SUCCESS ) command_queue.registerCLEvent(event);") @cl_int int clEnqueueReadBufferRect(@PointerWrapper("cl_command_queue") CLCommandQueue command_queue, @PointerWrapper("cl_mem") CLMem buffer, @cl_bool int blocking_read, @Const @Check("3") @NativeType("size_t") PointerBuffer buffer_offset, @Const @Check("3") @NativeType("size_t") PointerBuffer host_offset, @Const @Check("3") @NativeType("size_t") PointerBuffer region, @size_t long buffer_row_pitch, @size_t long buffer_slice_pitch, @size_t long host_row_pitch, @size_t long host_slice_pitch, @OutParameter @Check("CLChecks.calculateBufferRectSize(host_offset, region, host_row_pitch, host_slice_pitch)") @cl_byte @cl_short @cl_int @cl_long @cl_float @cl_double Buffer ptr, @AutoSize(value = "event_wait_list", canBeNull = true) @cl_uint int num_events_in_wait_list, @Const @Check(canBeNull = true) @NativeType("cl_event") PointerBuffer event_wait_list, @OutParameter @Check(value = "1", canBeNull = true) @NativeType("cl_event") PointerBuffer event);
@Code(javaAfterNative = "\t\tif ( __result == CL10.CL_SUCCESS ) command_queue.registerCLEvent(event);") @cl_int int clEnqueueWriteBufferRect(@PointerWrapper("cl_command_queue") CLCommandQueue command_queue, @PointerWrapper("cl_mem") CLMem buffer, @cl_bool int blocking_write, @Const @Check("3") @NativeType("size_t") PointerBuffer buffer_offset, @Const @Check("3") @NativeType("size_t") PointerBuffer host_offset, @Const @Check("3") @NativeType("size_t") PointerBuffer region, @size_t long buffer_row_pitch, @size_t long buffer_slice_pitch, @size_t long host_row_pitch, @size_t long host_slice_pitch, @Const @Check("CLChecks.calculateBufferRectSize(host_offset, region, host_row_pitch, host_slice_pitch)") @cl_byte @cl_short @cl_int @cl_long @cl_float @cl_double Buffer ptr, @AutoSize(value = "event_wait_list", canBeNull = true) @cl_uint int num_events_in_wait_list, @Const @Check(canBeNull = true) @NativeType("cl_event") PointerBuffer event_wait_list, @OutParameter @Check(value = "1", canBeNull = true) @NativeType("cl_event") PointerBuffer event);
public static MethodCall paramGlfwMonitor(MethodCall mc, long monitor) { PointerBuffer monitors = org.lwjgl.glfw.GLFW.glfwGetMonitors(); for (int i = 0; i < monitors.remaining(); i++) { long m = monitors.get(i); if (m == monitor) { mc.paramEnum("monitor[" + i + "]"); return mc; } } mc.param(monitor); return mc; }
public static long returnValueGlfwMonitor(long monitor, MethodCall mc) { PointerBuffer monitors = org.lwjgl.glfw.GLFW.glfwGetMonitors(); for (int i = 0; i < monitors.remaining(); i++) { long m = monitors.get(i); if (m == monitor) { mc.returnValueEnum("monitor[" + i + "]"); return monitor; } } mc.returnValue(monitor); return monitor; }
public static void checkGlfwMonitor(long monitor) { if (monitor == 0L) return; PointerBuffer pb = org.lwjgl.glfw.GLFW.glfwGetMonitors(); for (int i = 0; i < pb.remaining(); i++) { if (pb.get(i) == monitor) return; } throwIAEOrLogError("Provided 'monitor' argument is not a valid GLFW monitor handle: " + monitor); }
private String printBuffer(PointerBuffer buffer) { long address = MemoryUtil.memAddress0(buffer); int pos = buffer.position(); int lim = buffer.limit(); int cap = buffer.capacity(); if (pos == 0 && lim == cap) return "PointerBuffer[0x" + Long.toString(address, 16) + ", " + lim + "]"; else return "PointerBuffer[0x" + Long.toString(address, 16) + ", " + pos + ", " + lim + ", " + cap + "]"; }
public void save() { PointerBuffer filterP = PointerBuffer.allocateDirect(1); filterP.put(MemStack.wrap("*.krpf")); filterP.rewind(); String path = TinyFileDialogs.tinyfd_saveFileDialog("Save Project", null, filterP, null); MemStack.pop(); if (path != null) { if (!path.toLowerCase().endsWith(".krpf")) path += ".krpf"; try (DataOutputStream out = new DataOutputStream(new FileOutputStream(path))) { out.writeUTF("Kr\u00E4ftig"); properties.save(out); space.save(out); closeMenu(); } catch (Exception e) { TinyFileDialogs.tinyfd_messageBox("Kr\u00E4ftig Audio", "Failed to save project: " + e.toString(), "ok", "error", false); } } }
/** * 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; }
public static void create() { PointerBuffer displayPointers = glfwGetMonitors(); Display.displays = new ArrayList<>(); for(int i = 0; i < displayPointers.limit(); i++) { long id = displayPointers.get(i); Display.displays.add(new Display(id)); } glfwSetMonitorCallback(new DisplayCallback()); }
/** * Loads a model file and a texture to a {@link TexturedModel}. This method requires flags that will determine how * how the mesh is handled. * * @param modelPath Path to the model * @param texturePath Path to the texture. If the model contains a material library, * the material library should point to the texture's folder. * @param flags Flags separated by the Binary OR operator, "|" * @return Array of {@link TexturedModel}s that were contained by the * model file. */ public static TexturedModel[] load(String modelPath, String texturePath, int flags) { AIScene aiScene = aiImportFile(modelPath, flags); if (aiScene == null) throw new RuntimeException("Could not load model: " + modelPath + "\nWith flags " + flags); int numMaterials = aiScene.mNumMaterials(); PointerBuffer aiMaterials = aiScene.mMaterials(); List<Material> materials = new ArrayList<Material>(); for (int i = 0; i < numMaterials; i++) { AIMaterial aiMaterial = AIMaterial.create(aiMaterials.get(i)); processMat(aiMaterial, materials, texturePath); } int numMeshes = aiScene.mNumMeshes(); PointerBuffer aiMeshes = aiScene.mMeshes(); TexturedModel[] meshes = new TexturedModel[numMeshes]; for (int i = 0; i < numMeshes; i++) { AIMesh aiMesh = AIMesh.create(aiMeshes.get(i)); TexturedModel mesh = processStaticMesh(aiMesh, materials); String name = modelPath.split("/")[modelPath.split("/").length - 1]; String tex = texturePath.split("/")[texturePath.split("/").length - 1]; DBObject obj = new DBObject(name, DBObjectType.MODEL); obj.addArray(DBArray.createFloatArray("vertices", mesh.getModelData().getVertices())); obj.addArray(DBArray.createFloatArray("textureCoords", mesh.getModelData().getTextureCoords())); obj.addArray(DBArray.createFloatArray("normals", mesh.getModelData().getNormals())); obj.addArray(DBArray.createIntegerArray("indices", mesh.getModelData().getIndices())); obj.addString(DBString.create("texture", tex)); AssetCache.db.addObject(obj); meshes[i] = mesh; } AssetCache.db.serialize("assets.lum"); return meshes; }
public final void setCLSharingProperties(final PointerBuffer properties) throws LWJGLException { synchronized ( SYNC_LOCK ) { if ( context == null ) throw new IllegalStateException("Canvas not yet displayable"); context.setCLSharingProperties(properties); } }
/** * Calculates the number of bytes in the specified cl_mem buffer rectangle region. * * @param offset the host offset * @param region the rectangle region * @param row_pitch the host row pitch * @param slice_pitch the host slice pitch * * @return the region size in bytes */ static int calculateBufferRectSize(final PointerBuffer offset, final PointerBuffer region, long row_pitch, long slice_pitch) { if ( !LWJGLUtil.CHECKS ) return 0; final long x = offset.get(0); final long y = offset.get(1); final long z = offset.get(2); if ( LWJGLUtil.DEBUG && (x < 0 || y < 0 || z < 0) ) throw new IllegalArgumentException("Invalid cl_mem host offset: " + x + ", " + y + ", " + z); final long w = region.get(0); final long h = region.get(1); final long d = region.get(2); if ( LWJGLUtil.DEBUG && (w < 1 || h < 1 || d < 1) ) throw new IllegalArgumentException("Invalid cl_mem rectangle region dimensions: " + w + " x " + h + " x " + d); if ( row_pitch == 0 ) row_pitch = w; else if ( LWJGLUtil.DEBUG && row_pitch < w ) throw new IllegalArgumentException("Invalid host row pitch specified: " + row_pitch); if ( slice_pitch == 0 ) slice_pitch = row_pitch * h; else if ( LWJGLUtil.DEBUG && slice_pitch < (row_pitch * h) ) throw new IllegalArgumentException("Invalid host slice pitch specified: " + slice_pitch); return (int)((z * slice_pitch + y * row_pitch + x) + (w * h * d)); }
@Override public File openDialog(String title, String defaultPath, String[] filterPatterns, String filterDescription) { String result = null; //fix file path characters if (Utils.isWindows()) { defaultPath = defaultPath.replace("/", "\\"); } else { defaultPath = defaultPath.replace("\\", "/"); } if (filterPatterns != null && filterPatterns.length > 0) { try (MemoryStack stack = stackPush()) { PointerBuffer pointerBuffer = stack.mallocPointer(filterPatterns.length); for (String filterPattern : filterPatterns) { pointerBuffer.put(stack.UTF8(filterPattern)); } pointerBuffer.flip(); result = org.lwjgl.util.tinyfd.TinyFileDialogs.tinyfd_openFileDialog(title, defaultPath, pointerBuffer, filterDescription, false); } } else { result = org.lwjgl.util.tinyfd.TinyFileDialogs.tinyfd_openFileDialog(title, defaultPath, null, filterDescription, false); } if (result != null) { return new File(result); } else { return null; } }
/** * Called from <code>clGetDeviceIDs</code> to register new devices. * * @param devices a buffer containing CLDevice pointers. */ void registerCLDevices(final PointerBuffer devices, final IntBuffer num_devices) { final int pos = devices.position(); final int count = min(num_devices.get(num_devices.position()), devices.remaining()); // We can't depend on .remaining() for ( int i = 0; i < count; i++ ) { final long id = devices.get(pos + i); if ( !clDevices.hasObject(id) ) new CLDevice(id, this); } }
/** * Called from <code>clGetContextInfo</code> to register new devices. * * @param devices a buffer containing CLDevice pointers. */ void registerCLDevices(final ByteBuffer devices, final PointerBuffer num_devices) { final int pos = devices.position(); final int count = min((int)num_devices.get(num_devices.position()), devices.remaining()) / PointerBuffer.getPointerSize(); // We can't depend on .remaining() for ( int i = 0; i < count; i++ ) { final int offset = pos + (i * PointerBuffer.getPointerSize()); final long id = PointerBuffer.is64Bit() ? devices.getLong(offset) : devices.getInt(offset); if ( !clDevices.hasObject(id) ) new CLDevice(id, this); } }
/** * Called from clCreateKernelsInProgram to register new CLKernels. * * @param kernels a buffer containing CLKernel pointers. */ void registerCLKernels(final PointerBuffer kernels) { for ( int i = kernels.position(); i < kernels.limit(); i++ ) { final long pointer = kernels.get(i); if ( pointer != 0 ) new CLKernel(pointer, this); } }
/** * Called from clCreateSubDevicesEXT to register new sub-devices. * * @param devices a buffer containing CLDevice pointers. */ void registerSubCLDevices(final PointerBuffer devices) { for ( int i = devices.position(); i < devices.limit(); i++ ) { final long pointer = devices.get(i); if ( pointer != 0 ) new CLDevice(pointer, this); } }
public long getInfoSize(final T object, final int param_name) { object.checkValid(); final PointerBuffer buffer = APIUtil.getBufferPointer(); getInfo(object, param_name, buffer.getBuffer(), null); return buffer.get(0); }
public long[] getInfoSizeArray(final T object, final int param_name) { object.checkValid(); final int size = getInfoSizeArraySize(object, param_name); final PointerBuffer buffer = APIUtil.getBufferPointer(size); getInfo(object, param_name, buffer.getBuffer(), null); final long[] array = new long[size]; for ( int i = 0; i < size; i++ ) array[i] = buffer.get(i); return array; }
protected final int getSizeRet(final T object, final int param_name) { final PointerBuffer bytes = APIUtil.getBufferPointer(); final int errcode = getInfo(object, param_name, null, bytes); if ( errcode != CL_SUCCESS ) throw new IllegalArgumentException("Invalid parameter specified: " + LWJGLUtil.toHexString(param_name)); return (int)bytes.get(0); }
private static boolean generateParameterJava(PrintWriter writer, ParameterDeclaration param, TypeInfo type_info, boolean native_stub, final boolean printTypes, boolean first_parameter, Mode mode) { Class buffer_type = Utils.getNIOBufferType(param.getType()); if (!first_parameter) writer.print(", "); BufferObject bo_annotation = param.getAnnotation(BufferObject.class); if (bo_annotation != null && mode == Mode.BUFFEROBJECT) { if (buffer_type == null) throw new RuntimeException("type of " + param + " is not a nio Buffer parameter but is annotated as buffer object"); if ( printTypes ) writer.print("long "); writer.print(param.getSimpleName() + Utils.BUFFER_OBJECT_PARAMETER_POSTFIX); } else { if ( native_stub && param.getAnnotation(PointerWrapper.class) != null ) writer.print("long "); else { Class type = type_info.getType(); if ( native_stub && (type == CharSequence.class || type == CharSequence[].class || type == PointerBuffer.class || Buffer.class.isAssignableFrom(type) ) ) writer.print("long "); else if ( printTypes ) writer.print(type_info.getType().getSimpleName() + " "); } AutoSize auto_size_annotation = param.getAnnotation(AutoSize.class); if ( auto_size_annotation != null ) writer.print(auto_size_annotation.value() + "_"); writer.print(param.getSimpleName()); } return false; }
public void visitClassType(ClassType t) { final Class<?> type = Utils.getJavaType(t); if ( Buffer.class.isAssignableFrom(type) || PointerBuffer.class.isAssignableFrom(type) ) { signature.append("jlong"); objectReturn = true; } else signature.append("jobject"); }