Search in sources :

Example 46 with com.jme3.opencl

use of com.jme3.opencl in project jmonkeyengine by jMonkeyEngine.

the class JoclBuffer method mapAsync.

@Override
public com.jme3.opencl.Buffer.AsyncMapping mapAsync(CommandQueue queue, long size, long offset, MappingAccess access) {
    long q = ((JoclCommandQueue) queue).id;
    Utils.pointers[0].rewind();
    Utils.errorBuffer.rewind();
    long flags = Utils.getMappingAccessFlags(access);
    ByteBuffer b = cl.clEnqueueMapBuffer(q, id, CL.CL_FALSE, flags, offset, size, 0, null, Utils.pointers[0], Utils.errorBuffer);
    Utils.checkError(Utils.errorBuffer, "clEnqueueMapBuffer");
    long event = Utils.pointers[0].get(0);
    return new com.jme3.opencl.Buffer.AsyncMapping(new JoclEvent(event), b);
}
Also used : com.jme3.opencl(com.jme3.opencl) com.jogamp.opencl(com.jogamp.opencl) ByteBuffer(java.nio.ByteBuffer)

Example 47 with com.jme3.opencl

use of com.jme3.opencl in project jmonkeyengine by jMonkeyEngine.

the class LwjglContext method initOpenCL.

@SuppressWarnings("unchecked")
protected void initOpenCL() {
    logger.info("Initialize OpenCL wiht LWJGL2");
    try {
        CL.create();
    } catch (LWJGLException ex) {
        logger.log(Level.SEVERE, "Unable to initialize OpenCL", ex);
        return;
    }
    //load platforms and devices
    StringBuilder platformInfos = new StringBuilder();
    ArrayList<LwjglPlatform> platforms = new ArrayList<>();
    for (CLPlatform p : CLPlatform.getPlatforms()) {
        platforms.add(new LwjglPlatform(p));
    }
    platformInfos.append("Available OpenCL platforms:");
    for (int i = 0; i < platforms.size(); ++i) {
        LwjglPlatform platform = platforms.get(i);
        platformInfos.append("\n * Platform ").append(i + 1);
        platformInfos.append("\n *   Name: ").append(platform.getName());
        platformInfos.append("\n *   Vendor: ").append(platform.getVendor());
        platformInfos.append("\n *   Version: ").append(platform.getVersion());
        platformInfos.append("\n *   Profile: ").append(platform.getProfile());
        platformInfos.append("\n *   Supports interop: ").append(platform.hasOpenGLInterop());
        List<LwjglDevice> devices = platform.getDevices();
        platformInfos.append("\n *   Available devices:");
        for (int j = 0; j < devices.size(); ++j) {
            LwjglDevice device = devices.get(j);
            platformInfos.append("\n *    * Device ").append(j + 1);
            platformInfos.append("\n *    *   Name: ").append(device.getName());
            platformInfos.append("\n *    *   Vendor: ").append(device.getVendor());
            platformInfos.append("\n *    *   Version: ").append(device.getVersion());
            platformInfos.append("\n *    *   Profile: ").append(device.getProfile());
            platformInfos.append("\n *    *   Compiler version: ").append(device.getCompilerVersion());
            platformInfos.append("\n *    *   Device type: ").append(device.getDeviceType());
            platformInfos.append("\n *    *   Compute units: ").append(device.getComputeUnits());
            platformInfos.append("\n *    *   Work group size: ").append(device.getMaxiumWorkItemsPerGroup());
            platformInfos.append("\n *    *   Global memory: ").append(device.getGlobalMemorySize()).append("B");
            platformInfos.append("\n *    *   Local memory: ").append(device.getLocalMemorySize()).append("B");
            platformInfos.append("\n *    *   Constant memory: ").append(device.getMaximumConstantBufferSize()).append("B");
            platformInfos.append("\n *    *   Supports double: ").append(device.hasDouble());
            platformInfos.append("\n *    *   Supports half floats: ").append(device.hasHalfFloat());
            platformInfos.append("\n *    *   Supports writable 3d images: ").append(device.hasWritableImage3D());
            platformInfos.append("\n *    *   Supports interop: ").append(device.hasOpenGLInterop());
        }
    }
    logger.info(platformInfos.toString());
    //choose devices
    PlatformChooser chooser = null;
    if (settings.getOpenCLPlatformChooser() != null) {
        try {
            chooser = (PlatformChooser) Class.forName(settings.getOpenCLPlatformChooser()).newInstance();
        } catch (Exception ex) {
            logger.log(Level.WARNING, "unable to instantiate custom PlatformChooser", ex);
        }
    }
    if (chooser == null) {
        chooser = new DefaultPlatformChooser();
    }
    List<? extends Device> choosenDevices = chooser.chooseDevices(platforms);
    List<CLDevice> devices = new ArrayList<>(choosenDevices.size());
    LwjglPlatform platform = null;
    for (Device d : choosenDevices) {
        if (!(d instanceof LwjglDevice)) {
            logger.log(Level.SEVERE, "attempt to return a custom Device implementation from PlatformChooser: {0}", d);
            return;
        }
        LwjglDevice ld = (LwjglDevice) d;
        if (platform == null) {
            platform = ld.getPlatform();
        } else if (platform != ld.getPlatform()) {
            logger.severe("attempt to use devices from different platforms");
            return;
        }
        devices.add(ld.getDevice());
    }
    if (devices.isEmpty()) {
        logger.warning("no devices specified, no OpenCL context created");
        return;
    }
    clPlatform = platform;
    logger.log(Level.INFO, "chosen platform: {0}", platform.getName());
    logger.log(Level.INFO, "chosen devices: {0}", choosenDevices);
    //create context
    try {
        CLContext c = CLContext.create(platform.getPlatform(), devices, null, Display.getDrawable(), null);
        clContext = new com.jme3.opencl.lwjgl.LwjglContext(c, (List<LwjglDevice>) choosenDevices);
    } catch (LWJGLException ex) {
        logger.log(Level.SEVERE, "Unable to create OpenCL context", ex);
        return;
    }
    logger.info("OpenCL context created");
}
Also used : LwjglDevice(com.jme3.opencl.lwjgl.LwjglDevice) Device(com.jme3.opencl.Device) ArrayList(java.util.ArrayList) DefaultPlatformChooser(com.jme3.opencl.DefaultPlatformChooser) PlatformChooser(com.jme3.opencl.PlatformChooser) LWJGLException(org.lwjgl.LWJGLException) RendererException(com.jme3.renderer.RendererException) LwjglDevice(com.jme3.opencl.lwjgl.LwjglDevice) LwjglPlatform(com.jme3.opencl.lwjgl.LwjglPlatform) ArrayList(java.util.ArrayList) List(java.util.List) LWJGLException(org.lwjgl.LWJGLException) DefaultPlatformChooser(com.jme3.opencl.DefaultPlatformChooser)

Example 48 with com.jme3.opencl

use of com.jme3.opencl in project jmonkeyengine by jMonkeyEngine.

the class FbxNode method getPreferredParent.

/**
     * If this geometry node is deformed by a skeleton, this
     * returns the node containing the skeleton.
     * 
     * In jME3, a mesh can be deformed by a skeleton only if it is 
     * a child of the node containing the skeleton. However, this
     * is not a requirement in FBX, so we have to modify the scene graph
     * of the loaded model to adjust for this.
     * This happens automatically in 
     * {@link #createScene(com.jme3.scene.plugins.fbx.node.FbxNode)}.
     * 
     * @return The model this node would like to be a child of, or null
     * if no preferred parent.
     */
public FbxNode getPreferredParent() {
    if (!(nodeAttribute instanceof FbxMesh)) {
        return null;
    }
    FbxMesh fbxMesh = (FbxMesh) nodeAttribute;
    FbxSkinDeformer deformer = fbxMesh.getSkinDeformer();
    FbxNode preferredParent = null;
    if (deformer != null) {
        for (FbxCluster cluster : deformer.getJmeObject()) {
            FbxLimbNode limb = cluster.getLimb();
            if (preferredParent == null) {
                preferredParent = limb.getSkeletonHolder();
            } else if (preferredParent != limb.getSkeletonHolder()) {
                logger.log(Level.WARNING, "A mesh is being deformed by multiple skeletons. " + "Only one skeleton will work, ignoring other skeletons.");
            }
        }
    }
    return preferredParent;
}
Also used : FbxCluster(com.jme3.scene.plugins.fbx.anim.FbxCluster) FbxMesh(com.jme3.scene.plugins.fbx.mesh.FbxMesh) FbxSkinDeformer(com.jme3.scene.plugins.fbx.anim.FbxSkinDeformer) FbxLimbNode(com.jme3.scene.plugins.fbx.anim.FbxLimbNode)

Example 49 with com.jme3.opencl

use of com.jme3.opencl in project jmonkeyengine by jMonkeyEngine.

the class SceneLoader method parseEntity.

private void parseEntity(Attributes attribs) throws SAXException {
    String name = attribs.getValue("name");
    if (name == null) {
        name = "OgreEntity-" + (++nodeIdx);
    } else {
        name += "-entity";
    }
    String meshFile = attribs.getValue("meshFile");
    if (meshFile == null) {
        throw new SAXException("Required attribute 'meshFile' missing for 'entity' node");
    }
    // TODO: Not currently used
    String materialName = attribs.getValue("materialName");
    if (folderName != null) {
        meshFile = folderName + meshFile;
    }
    // NOTE: append "xml" since its assumed mesh files are binary in dotScene
    meshFile += ".xml";
    entityNode = new com.jme3.scene.Node(name);
    OgreMeshKey meshKey = new OgreMeshKey(meshFile, materialList);
    try {
        try {
            Spatial ogreMesh = (Spatial) meshLoader.load(assetManager.locateAsset(meshKey));
            entityNode.attachChild(ogreMesh);
        } catch (IOException e) {
            throw new AssetNotFoundException(meshKey.toString());
        }
    } catch (AssetNotFoundException ex) {
        if (ex.getMessage().equals(meshFile)) {
            logger.log(Level.WARNING, "Cannot locate {0} for scene {1}", new Object[] { meshKey, key });
            // Attach placeholder asset.
            Spatial model = PlaceholderAssets.getPlaceholderModel(assetManager);
            model.setKey(key);
            entityNode.attachChild(model);
        } else {
            throw ex;
        }
    }
    node.attachChild(entityNode);
    node = null;
}
Also used : Spatial(com.jme3.scene.Spatial) IOException(java.io.IOException) SAXException(org.xml.sax.SAXException)

Example 50 with com.jme3.opencl

use of com.jme3.opencl in project jmonkeyengine by jMonkeyEngine.

the class J3MExporter method save.

@Override
public void save(Savable object, OutputStream f) throws IOException {
    if (!(object instanceof Material)) {
        throw new IllegalArgumentException("J3MExporter can only save com.jme3.material.Material class");
    }
    OutputStreamWriter out = new OutputStreamWriter(f, Charset.forName("UTF-8"));
    rootCapsule.clear();
    object.write(this);
    rootCapsule.writeToStream(out);
    out.flush();
}
Also used : Material(com.jme3.material.Material) OutputStreamWriter(java.io.OutputStreamWriter)

Aggregations

ByteBuffer (java.nio.ByteBuffer)8 Vector3f (com.jme3.math.Vector3f)7 ColorRGBA (com.jme3.math.ColorRGBA)6 Material (com.jme3.material.Material)5 com.jme3.opencl (com.jme3.opencl)5 Geometry (com.jme3.scene.Geometry)5 BitmapText (com.jme3.font.BitmapText)4 RendererException (com.jme3.renderer.RendererException)4 Texture (com.jme3.texture.Texture)4 ArrayList (java.util.ArrayList)4 BitmapFont (com.jme3.font.BitmapFont)3 Matrix4f (com.jme3.math.Matrix4f)3 DefaultPlatformChooser (com.jme3.opencl.DefaultPlatformChooser)3 Device (com.jme3.opencl.Device)3 PlatformChooser (com.jme3.opencl.PlatformChooser)3 AppSettings (com.jme3.system.AppSettings)3 Image (com.jme3.texture.Image)3 TextureCubeMap (com.jme3.texture.TextureCubeMap)3 CubeMapWrapper (com.jme3.environment.util.CubeMapWrapper)2 AmbientLight (com.jme3.light.AmbientLight)2