Example #1
0
bool Simulation::setup(const GLuint windowWidth, const GLuint windowHeight, const GLuint viewportWidth, const GLuint viewportHeight, AssetLoader& assetLoader)
{   
   setup_rand();
   
   this->windowWidth = windowWidth;
   this->windowHeight = windowHeight;
   this->viewportWidth = viewportWidth;
   this->viewportHeight = viewportHeight;

   const char VertexShaderCode[] = 
      "attribute vec4 a_position;      \n"
      "attribute lowp vec4 a_color;    \n"
      "varying lowp vec4 v_color;      \n"
      "                                \n"
      "void main() {                   \n"
      "   gl_Position = a_position;    \n"
      "   v_color = a_color;           \n"
      "}                               \n";

   const char FragmentShaderCode[] = 
      "precision mediump float;        \n"
      "varying lowp vec4 v_color;      \n"
      "void main() {                   \n"
      "  gl_FragColor = v_color;       \n"
      "}                               \n";

   program = createProgram(VertexShaderCode, FragmentShaderCode);
   if(!program)
   {
      LOGE("Could not create program.");
      return false;
   }

   // Load shader attribute locations
   positionAttribute = glGetAttribLocation(program, "a_position");
   checkGlError("glGetAttribLocation");
   LOGI("glGetAttribLocation(\"a_position\") = %d\n", positionAttribute);

   colorAttribute = glGetAttribLocation(program, "a_color");
   checkGlError("glGetAttribLocation");
   LOGI("glGetAttribLocation(\"a_color\") = %d\n", colorAttribute);

   // Load triangle currentBuffer
   glGenBuffers(1, &vboId);
   checkGlError("glGenBuffers");

   glBindBuffer(GL_ARRAY_BUFFER, vboId);
   checkGlError("glBindBuffer");

   // Set the currentBuffer's data
   glBufferData(GL_ARRAY_BUFFER, Constants::MaximumVertexCount * sizeof(ColorVertex), &currentVertices[0], GL_DYNAMIC_DRAW);
   checkGlError("glBufferData");
      
   // Create image buffers
   const int BufferSize = viewportWidth*viewportHeight*4; /* RGBA format*/
   currentBuffer = new unsigned char[BufferSize];
   std::fill_n(currentBuffer, BufferSize, 0);

   targetBuffer = new unsigned char[BufferSize];
   std::fill_n(targetBuffer, BufferSize, 0);
   
   if(!create_render_target())
   {
      LOGE("Could not create render target!");
      return false;
   }
   
   LOGW("Integer Sizes: %d %d", sizeof(unsigned long), sizeof(unsigned long));
   LOGI("Success engine_init_display");
      
   if(!load_content(assetLoader))
   {
      LOGE("Could not load content!");
      return false;
   }

   create_random_triangles();
   copy_current_to_best_triangles();
   LOGI("Simulation is ready to go.");
   return true;
}
Example #2
0
/* This function determines which input file type is being used,
 * and calls the appropriate read function. If a new type of input
 * file is added to the driver, then a section needs to be added for
 * it here.
 *---------------------------------------------------------------------------*/
static int read_mesh(
  int Proc,
  int Num_Proc,
  PROB_INFO_PTR prob,
  PARIO_INFO_PTR pio_info,
  MESH_INFO_PTR mesh)
{
#ifdef DEBUG_READ_MESH
  int i, tpins, the, tverts, pins, he, verts;
#endif
/* local declarations */
/*-----------------------------Execution Begins------------------------------*/
  if (pio_info->file_type == CHACO_FILE) {
    if (!read_chaco_file(Proc, Num_Proc, prob, pio_info, mesh)) {
        Gen_Error(0, "fatal: Error returned from read_chaco_mesh\n");
        return 0;
    }
  }
  else if (pio_info->file_type == NEMESIS_FILE) {
    if (!read_exoII_file(Proc, Num_Proc, prob, pio_info, mesh)) {
        Gen_Error(0, "fatal: Error returned from read_exoII_mesh\n");
        return 0;
    }
  }
  else if (pio_info->file_type == HYPERGRAPH_FILE) {
    if (!read_hypergraph_file(Proc, Num_Proc, prob, pio_info, mesh)) {
        Gen_Error(0, "fatal: Error returned from read_hypergraph_file\n");
        return 0;
    }
  }
  else if (pio_info->file_type == MATRIXMARKET_FILE) {
    if (!read_mm_file(Proc, Num_Proc, prob, pio_info, mesh)) {
        Gen_Error(0, "fatal: Error returned from read_mm_file\n");
        return 0;
    }
    mm_cleanup(mesh);
  }
  else if (pio_info->file_type == MATRIXMARKET_PLUS_FILE) {
    if (!read_mtxplus_file(Proc, Num_Proc, prob, pio_info, mesh)) {
        Gen_Error(0, "fatal: Error returned from read_mtxplus_file\n");
        return 0;
    }
    /* KDDKDD 3/26/10:  
     * Eventually, we should do cleanup here to address bug 3346.
     * but doing so will change the answer files.
     * mm_cleanup(mesh);
     */
  }
  else if (pio_info->file_type == NO_FILE_POINTS) {
    if (!create_random_input(Proc, Num_Proc, prob, pio_info, mesh)) {
        Gen_Error(0, "fatal: Error returned from create_random_input\n");
        return 0;
    }
  }
  else if (pio_info->file_type == NO_FILE_TRIANGLES) {
    if (!create_random_triangles(Proc, Num_Proc, prob, pio_info, mesh)) {
        Gen_Error(0, "fatal: Error returned from create_random_triangles\n");
        return 0;
    }
  }
  else if (pio_info->file_type == NO_FILE_GRAPH) {
    if (!create_a_graph(Proc, Num_Proc, prob, pio_info, mesh)) {
        Gen_Error(0, "fatal: Error returned from create_a_graph\n");
        return 0;
    }
  }
  else {
    Gen_Error(0, "fatal: Invalid file type.\n");
    return 0;
  }

#ifdef DEBUG_READ_MESH
  for (i=0; i<Num_Proc; i++){
    if (i == Proc){
      printf("Process %d:\n",i);
      print_mesh(Proc, mesh, &pins, &he, &verts);
    }
    MPI_Barrier(MPI_COMM_WORLD);
  }
  MPI_Reduce(&pins, &tpins, 1, MPI_INT, MPI_SUM, 0, MPI_COMM_WORLD);
  MPI_Reduce(&he, &the, 1, MPI_INT, MPI_SUM, 0, MPI_COMM_WORLD);
  MPI_Reduce(&verts, &tverts, 1, MPI_INT, MPI_SUM, 0, MPI_COMM_WORLD);
  if (Proc == 0){
    if (mesh->format == ZOLTAN_COMPRESSED_EDGE){
      printf("Total pins %d, total vertices %d, total rows %d\n",
                 tpins, tverts, the);
    }
    else{
      printf("Total pins %d, total vertices %d, total columns %d\n",
                 tpins, tverts, the);
    }
  }
#endif
  return 1;
}