Search in sources :

Example 86 with Type

use of com.jme3.scene.VertexBuffer.Type in project jmonkeyengine by jMonkeyEngine.

the class ShaderNodeLoaderDelegate method updateRightFromUniforms.

/**
     * updates the right variable of the given mapping from a MatParam (a
     * WorldParam) it checks if the uniform hasn't already been loaded, add it
     * to the maps if not.
     *
     * @param param the MatParam
     * @param mapping the mapping
     * @param map the map of uniforms to search into
     * @return true if the param was added to the map
     */
public boolean updateRightFromUniforms(MatParam param, VariableMapping mapping, Map<String, DeclaredVariable> map, Statement statement) throws MatParseException {
    ShaderNodeVariable right = mapping.getRightVariable();
    DeclaredVariable dv = map.get(param.getPrefixedName());
    if (dv == null) {
        right.setType(param.getVarType().getGlslType());
        right.setName(param.getPrefixedName());
        if (mapping.getLeftVariable().getMultiplicity() != null) {
            if (!param.getVarType().name().endsWith("Array")) {
                throw new MatParseException(param.getName() + " is not of Array type", statement);
            }
            String multiplicity = mapping.getLeftVariable().getMultiplicity();
            try {
                Integer.parseInt(multiplicity);
            } catch (NumberFormatException nfe) {
                //multiplicity is not an int attempting to find for a material parameter.
                MatParam mp = findMatParam(multiplicity);
                if (mp != null) {
                    addDefine(multiplicity, VarType.Int);
                    multiplicity = multiplicity.toUpperCase();
                } else {
                    throw new MatParseException("Wrong multiplicity for variable" + mapping.getLeftVariable().getName() + ". " + multiplicity + " should be an int or a declared material parameter.", statement);
                }
            }
            right.setMultiplicity(multiplicity);
        }
        dv = new DeclaredVariable(right);
        map.put(right.getName(), dv);
        dv.addNode(shaderNode);
        mapping.setRightVariable(right);
        return true;
    }
    dv.addNode(shaderNode);
    mapping.setRightVariable(dv.var);
    return false;
}
Also used : MatParam(com.jme3.material.MatParam) ShaderNodeVariable(com.jme3.shader.ShaderNodeVariable)

Example 87 with Type

use of com.jme3.scene.VertexBuffer.Type in project jmonkeyengine by jMonkeyEngine.

the class TestBitmapFont method simpleInitApp.

@Override
public void simpleInitApp() {
    inputManager.addMapping("WordWrap", new KeyTrigger(KeyInput.KEY_TAB));
    inputManager.addListener(keyListener, "WordWrap");
    inputManager.addRawInputListener(textListener);
    BitmapFont fnt = assetManager.loadFont("Interface/Fonts/Default.fnt");
    txt = new BitmapText(fnt, false);
    txt.setBox(new Rectangle(0, 0, settings.getWidth(), settings.getHeight()));
    txt.setSize(fnt.getPreferredSize() * 2f);
    txt.setText(txtB);
    txt.setLocalTranslation(0, txt.getHeight(), 0);
    guiNode.attachChild(txt);
    txt2 = new BitmapText(fnt, false);
    txt2.setSize(fnt.getPreferredSize() * 1.2f);
    txt2.setText("Text without restriction. \nText without restriction. Text without restriction. Text without restriction");
    txt2.setLocalTranslation(0, txt2.getHeight(), 0);
    guiNode.attachChild(txt2);
    txt3 = new BitmapText(fnt, false);
    txt3.setBox(new Rectangle(0, 0, settings.getWidth(), 0));
    txt3.setText("Press Tab to toggle word-wrap. type text and enter to input text");
    txt3.setLocalTranslation(0, settings.getHeight() / 2, 0);
    guiNode.attachChild(txt3);
}
Also used : BitmapText(com.jme3.font.BitmapText) KeyTrigger(com.jme3.input.controls.KeyTrigger) Rectangle(com.jme3.font.Rectangle) BitmapFont(com.jme3.font.BitmapFont)

Example 88 with Type

use of com.jme3.scene.VertexBuffer.Type 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 89 with Type

use of com.jme3.scene.VertexBuffer.Type in project jmonkeyengine by jMonkeyEngine.

the class CollectionSerializer method readObject.

@SuppressWarnings("unchecked")
public <T> T readObject(ByteBuffer data, Class<T> c) throws IOException {
    int length = data.getInt();
    Collection collection;
    try {
        collection = (Collection) c.newInstance();
    } catch (Exception e) {
        log.log(Level.FINE, "[Serializer][???] Could not determine collection type. Using ArrayList.");
        collection = new ArrayList(length);
    }
    if (length == 0)
        return (T) collection;
    if (data.get() == (byte) 1) {
        SerializerRegistration reg = Serializer.readClass(data);
        Class clazz = reg.getType();
        Serializer serializer = reg.getSerializer();
        for (int i = 0; i != length; ++i) {
            collection.add(serializer.readObject(data, clazz));
        }
    } else {
        for (int i = 0; i != length; ++i) {
            collection.add(Serializer.readClassAndObject(data));
        }
    }
    return (T) collection;
}
Also used : ArrayList(java.util.ArrayList) Collection(java.util.Collection) IOException(java.io.IOException) SerializerRegistration(com.jme3.network.serializing.SerializerRegistration) Serializer(com.jme3.network.serializing.Serializer)

Example 90 with Type

use of com.jme3.scene.VertexBuffer.Type in project jmonkeyengine by jMonkeyEngine.

the class SerializerRegistrationsMessage method compile.

public static void compile() {
    // Let's just see what they are here
    List<Registration> list = new ArrayList<Registration>();
    for (SerializerRegistration reg : Serializer.getSerializerRegistrations()) {
        Class type = reg.getType();
        if (ignore.contains(type))
            continue;
        if (type.isPrimitive())
            continue;
        list.add(new Registration(reg));
    }
    if (log.isLoggable(Level.FINE)) {
        log.log(Level.FINE, "Number of registered classes:{0}", list.size());
        for (Registration reg : list) {
            log.log(Level.FINE, "    {0}", reg);
        }
    }
    compiled = list.toArray(new Registration[list.size()]);
    INSTANCE = new SerializerRegistrationsMessage(compiled);
    Serializer.setReadOnly(true);
}
Also used : SerializerRegistration(com.jme3.network.serializing.SerializerRegistration) SerializerRegistration(com.jme3.network.serializing.SerializerRegistration)

Aggregations

ArrayList (java.util.ArrayList)18 Structure (com.jme3.scene.plugins.blender.file.Structure)12 Vector3f (com.jme3.math.Vector3f)11 Pointer (com.jme3.scene.plugins.blender.file.Pointer)10 IOException (java.io.IOException)10 List (java.util.List)9 ColorRGBA (com.jme3.math.ColorRGBA)8 Texture (com.jme3.texture.Texture)8 Geometry (com.jme3.scene.Geometry)6 Image (com.jme3.texture.Image)6 BoundingBox (com.jme3.bounding.BoundingBox)5 BoundingSphere (com.jme3.bounding.BoundingSphere)5 Light (com.jme3.light.Light)5 TemporalMesh (com.jme3.scene.plugins.blender.meshes.TemporalMesh)5 Uniform (com.jme3.shader.Uniform)5 Material (com.jme3.material.Material)4 Quaternion (com.jme3.math.Quaternion)4 Transform (com.jme3.math.Transform)4 Mesh (com.jme3.scene.Mesh)4 BlenderFileException (com.jme3.scene.plugins.blender.file.BlenderFileException)4