Esempio n. 1
0
  protected void initInThread() {
    created.set(true);

    logger.info("OGLESContext create");
    logger.log(Level.INFO, "Running on thread: {0}", Thread.currentThread().getName());

    // Setup unhandled Exception Handler
    Thread.currentThread()
        .setUncaughtExceptionHandler(
            new Thread.UncaughtExceptionHandler() {

              public void uncaughtException(Thread thread, Throwable thrown) {
                listener.handleError("Exception thrown in " + thread.toString(), thrown);
              }
            });

    if (clientOpenGLESVersion < 2) {
      throw new UnsupportedOperationException("OpenGL ES 2.0 is not supported on this device");
    }

    timer = new AndroidTimer();
    renderer = new OGLESShaderRenderer();

    renderer.initialize();
    listener.initialize();

    JmeSystem.setSoftTextDialogInput(this);

    needClose.set(false);
    renderable.set(true);
  }
 /** Test method for {@link imuanalyzer.ui.VisualTouchLineStatistics#getStatistics()}. */
 @Test
 public void testGetStatistics() {
   AssetManager assetManager =
       JmeSystem.newAssetManager(
           Thread.currentThread()
               .getContextClassLoader()
               .getResource("com/jme3/asset/Desktop.cfg"));
   Boxplot3d vstat = new Boxplot3d(assetManager);
   ArrayList<IBoxplotData> stats = new ArrayList<IBoxplotData>();
   stats.add(
       new VectorLineStatistics("Test", Helper.getExampleTouchlineEven(), new ArrayList<Float>()));
   stats.add(
       new VectorLineStatistics("Test", Helper.getExampleTouchlineOdd(), new ArrayList<Float>()));
   vstat.setStatistics(stats);
 }
 private void initOpenCL1() {
   clContext = context.getOpenCLContext();
   Device device = clContext.getDevices().get(0);
   clQueue = clContext.createQueue(device).register();
   // create kernel
   Program program = null;
   File tmpFolder = JmeSystem.getStorageFolder();
   File binaryFile = new File(tmpFolder, getClass().getSimpleName() + ".clc");
   try {
     // attempt to load cached binary
     byte[] bytes = Files.readAllBytes(binaryFile.toPath());
     ByteBuffer bb = BufferUtils.createByteBuffer(bytes);
     program = clContext.createProgramFromBinary(bb, device);
     program.build();
     LOG.info("reuse program from cached binaries");
   } catch (java.nio.file.NoSuchFileException ex) {
     // do nothing, cache was not created yet
   } catch (Exception ex) {
     LOG.log(Level.INFO, "Unable to use cached program binaries", ex);
   }
   if (program == null) {
     // build from sources
     String source =
         ""
             + "__kernel void ScaleKernel(__global float* vb, float scale)\n"
             + "{\n"
             + "  int idx = get_global_id(0);\n"
             + "  float3 pos = vload3(idx, vb);\n"
             + "  pos *= scale;\n"
             + "  vstore3(pos, idx, vb);\n"
             + "}\n";
     program = clContext.createProgramFromSourceCode(source);
     program.build();
     // Save binary
     try {
       ByteBuffer bb = program.getBinary(device);
       byte[] bytes = new byte[bb.remaining()];
       bb.get(bytes);
       Files.write(binaryFile.toPath(), bytes);
     } catch (UnsupportedOperationException | OpenCLException | IOException ex) {
       LOG.log(Level.SEVERE, "Unable to save program binaries", ex);
     }
     LOG.info("create new program from sources");
   }
   program.register();
   kernel = program.createKernel("ScaleKernel").register();
 }
Esempio n. 4
0
  /** Does LWJGL display initialization in the OpenGL thread */
  protected boolean initInThread() {
    try {
      if (!JmeSystem.isLowPermissions()) {
        // Enable uncaught exception handler only for current thread
        Thread.currentThread()
            .setUncaughtExceptionHandler(
                new Thread.UncaughtExceptionHandler() {
                  public void uncaughtException(Thread thread, Throwable thrown) {
                    listener.handleError(
                        "Uncaught exception thrown in " + thread.toString(), thrown);
                    if (needClose.get()) {
                      // listener.handleError() has requested the
                      // context to close. Satisfy request.
                      deinitInThread();
                    }
                  }
                });
      }

      // For canvas, this will create a pbuffer,
      // allowing us to query information.
      // When the canvas context becomes available, it will
      // be replaced seamlessly.
      createContext(settings);
      printContextInitInfo();

      created.set(true);
      super.internalCreate();
    } catch (Exception ex) {
      try {
        if (Display.isCreated()) Display.destroy();
      } catch (Exception ex2) {
        logger.log(Level.WARNING, null, ex2);
      }

      listener.handleError("Failed to create display", ex);
      return false; // if we failed to create display, do not continue
    }

    listener.initialize();
    return true;
  }
  @Override
  public void start() {
    // set some default settings in-case
    // settings dialog is not shown
    boolean loadSettings = false;
    if (settings == null) {
      setSettings(new AppSettings(true));
      loadSettings = true;
    }

    // show settings dialog
    if (showSettings) {
      if (!JmeSystem.showSettingsDialog(settings, loadSettings)) {
        return;
      }
    }
    // re-setting settings they can have been merged from the registry.
    setSettings(settings);
    super.start();
  }
  public static void main(String[] args) {
    AssetManager assetManager =
        JmeSystem.newAssetManager(
            TestMaterialCompare.class.getResource("/com/jme3/asset/Desktop.cfg"));

    // Cloned materials
    Material mat1 = new Material(assetManager, "Common/MatDefs/Misc/Unshaded.j3md");
    mat1.setName("mat1");
    mat1.setColor("Color", ColorRGBA.Blue);

    Material mat2 = mat1.clone();
    mat2.setName("mat2");
    testEquality(mat1, mat2, true);

    // Cloned material with different render states
    Material mat3 = mat1.clone();
    mat3.setName("mat3");
    mat3.getAdditionalRenderState().setBlendMode(BlendMode.ModulateX2);
    testEquality(mat1, mat3, false);

    // Two separately loaded materials
    Material mat4 = assetManager.loadMaterial("Models/Sign Post/Sign Post.j3m");
    mat4.setName("mat4");
    Material mat5 = assetManager.loadMaterial("Models/Sign Post/Sign Post.j3m");
    mat5.setName("mat5");
    testEquality(mat4, mat5, true);

    // Comparing same textures
    TextureKey originalKey =
        (TextureKey) mat4.getTextureParam("DiffuseMap").getTextureValue().getKey();
    TextureKey tex1key = new TextureKey("Models/Sign Post/Sign Post.jpg", false);
    tex1key.setGenerateMips(true);

    // Texture keys from the original and the loaded texture
    // must be identical, otherwise the resultant textures not identical
    // and thus materials are not identical!
    if (!originalKey.equals(tex1key)) {
      System.out.println("TEXTURE KEYS ARE NOT EQUAL");
    }

    Texture tex1 = assetManager.loadTexture(tex1key);
    mat4.setTexture("DiffuseMap", tex1);
    testEquality(mat4, mat5, true);

    // Change some stuff on the texture and compare, materials no longer equal
    tex1.setWrap(Texture.WrapMode.MirroredRepeat);
    testEquality(mat4, mat5, false);

    // Comparing different textures
    Texture tex2 = assetManager.loadTexture("Interface/Logo/Monkey.jpg");
    mat4.setTexture("DiffuseMap", tex2);
    testEquality(mat4, mat5, false);

    // Two materials created the same way
    Material mat6 = new Material(assetManager, "Common/MatDefs/Misc/Unshaded.j3md");
    mat6.setName("mat6");
    mat6.setColor("Color", ColorRGBA.Blue);
    testEquality(mat1, mat6, true);

    // Changing a material param
    mat6.setColor("Color", ColorRGBA.Green);
    testEquality(mat1, mat6, false);
  }
Esempio n. 7
0
  /**
   * Check that we have all we need to run this app
   *
   * @param app the app (we need asset managers etc.)
   * @return true if the app is ok for running!
   * @throws InterruptedException lots of threads waiting
   */
  private static boolean checkSetup(final Main app) throws InterruptedException {

    boolean saveSetup = false;

    // First and foremost, the folder
    if (!checkDkFolder(dkIIFolder)) {
      logger.info("Dungeon Keeper II folder not found or valid! Prompting user!");
      saveSetup = true;

      // Let the user select
      setLookNFeel();
      DKFolderSelector frame =
          new DKFolderSelector() {
            @Override
            protected void continueOk(String path) {
              if (!path.endsWith(File.separator)) {
                dkIIFolder = path.concat(File.separator);
              }
              app.getSettings().putString(DKII_FOLDER_KEY, dkIIFolder);
              folderOk = true;
            }
          };
      openFrameAndWait(frame);
    } else {
      folderOk = true;
    }

    // If the folder is ok, check the conversion
    if (folderOk && (AssetsConverter.conversionNeeded(app.getSettings()))) {
      logger.info("Need to convert the assets!");
      saveSetup = true;

      // Convert
      setLookNFeel();
      AssetManager assetManager =
          JmeSystem.newAssetManager(
              Thread.currentThread()
                  .getContextClassLoader()
                  .getResource(
                      "com/jme3/asset/Desktop.cfg")); // Get temporary asset manager instance since
      // we not yet have one ourselves
      assetManager.registerLocator(AssetsConverter.getAssetsFolder(), FileLocator.class);
      DKConverter frame =
          new DKConverter(dkIIFolder, assetManager) {
            @Override
            protected void continueOk() {
              AssetsConverter.setConversionSettings(app.getSettings());
              conversionOk = true;
            }
          };
      openFrameAndWait(frame);
    } else if (folderOk) {
      conversionOk = true;
    }

    // If everything is ok, we might need to save the setup
    boolean result = (folderOk && conversionOk);
    if (result && saveSetup) {
      try {
        app.getSettings().save(new FileOutputStream(new File(SETTINGS_FILE)));
      } catch (IOException ex) {
        Logger.getLogger(Main.class.getName())
            .log(Level.WARNING, "Settings file failed to save!", ex);
      }
    }

    return result;
  }
 public static void main(String[] args) {
   AssetManager assetManager = JmeSystem.newAssetManager();
   assetManager.registerLocator("/", ClasspathLocator.class);
   assetManager.registerLoader(TextLoader.class, "fnt");
   System.out.println(assetManager.loadAsset("Interface/Fonts/Console.fnt"));
 }