コード例 #1
0
ファイル: mesh.cpp プロジェクト: Gnurou/glmark2
/**
 * Builds a vertex buffer object containing the mesh vertex data.
 *
 * The way the VBO is constructed is affected by the current interleave
 * value (::interleave()) and the vbo usage hint (::vbo_usage()).
 */
void
Mesh::build_vbo()
{
    delete_array();
    build_array();

    int nvertices = vertices_.size();

    attrib_data_ptr_.clear();

    GLenum buffer_usage;
    if (vbo_usage_ == Mesh::VBOUsageStream)
        buffer_usage = GL_STREAM_DRAW;
    else if (vbo_usage_ == Mesh::VBOUsageDynamic)
        buffer_usage = GL_DYNAMIC_DRAW;
    else /* if (vbo_usage_ == Mesh::VBOUsageStatic) */
        buffer_usage = GL_STATIC_DRAW;

    if (!interleave_) {
        /* Create a vbo for each attribute */
        for (std::vector<std::pair<int, int> >::const_iterator ai = vertex_format_.begin();
             ai != vertex_format_.end();
             ai++)
        {
            float *data = vertex_arrays_[ai - vertex_format_.begin()];
            GLuint vbo;

            glGenBuffers(1, &vbo);
            glBindBuffer(GL_ARRAY_BUFFER, vbo);
            glBufferData(GL_ARRAY_BUFFER, nvertices * ai->first * sizeof(float),
                         data, buffer_usage);

            vbos_.push_back(vbo);
            attrib_data_ptr_.push_back(0);
        }

        vertex_stride_ = 0;
    }
    else {
        GLuint vbo;
        /* Create a single vbo to store all attribute data */
        glGenBuffers(1, &vbo);
        glBindBuffer(GL_ARRAY_BUFFER, vbo);

        glBufferData(GL_ARRAY_BUFFER, nvertices * vertex_size_ * sizeof(float),
                     vertex_arrays_[0], GL_STATIC_DRAW);

        glBindBuffer(GL_ARRAY_BUFFER, 0);

        for (size_t i = 0; i < vertex_format_.size(); i++) {
            attrib_data_ptr_.push_back(reinterpret_cast<float *>(sizeof(float) * vertex_format_[i].second));
            vbos_.push_back(vbo);
        }
        vertex_stride_ = vertex_size_ * sizeof(float);
    }

    delete_array();
}
コード例 #2
0
ファイル: selbox.c プロジェクト: BADSEC/multitail
proginfo * select_subwindow(int f_index, int what_help, char *heading)
{
	proginfo *cur = NULL;
	char **list;
	int list_n, index, loop;

	if (f_index == -1)
		return NULL;

	list_n = create_subwindow_list(f_index, &list);

	index = selection_box((void **)list, NULL, list_n, SEL_SUBWIN, what_help, heading);

	if (index != -1)
	{
		cur = &pi[f_index];
		for(loop=0; loop<index; loop++)
		{
			cur = cur -> next;
		}
	}

	delete_array(list, list_n);

	return cur;
}
コード例 #3
0
ファイル: delarr.c プロジェクト: hanjiabao/research
int main(int argc , char *argv[])
{
	int a[] = {0,6,7,8,6,1,5,7,8,2};
	int i;
	int len;
	int ret = 0;

	len = sizeof(a)/sizeof(int); // a表示占用的内存空间
	
	for (i = 0; i < len;i++)
	{
		ret = find_array(a,i); //遇到了一个 返回1 没有0
		if (ret == 1)
		{
			delete_array(a,i,len);//a 数组 i 位置 len 长度
			len--;
			i--; //这里要讲清楚 这个是为了检查刚刚赋值过来的数值 与前面的数值是否有重复
		}
	}

	for (i = 0;i < len;i++)
	{
		printf("%d\n",a[i]); 
	}

	return 0;

}
コード例 #4
0
ファイル: generate.c プロジェクト: timothy-king/SummerClass11
int main(int argc, const char* argv[]) {

  gmp_randstate_t state;
  data_arr source;
  mpz_t seed;
  uint32_t min, max, n;


  mpz_init(seed);

  parse_input(argc, argv, seed, &min, &max);

  gmp_randinit_default(state);
  gmp_randseed(state, seed);

  n = rand_range(state, min, max);

  fprintf(stderr, "%u\n",n);
  source = make_array(n);

  generate_random_arr(n, source, state);
  
  
  fprint_array(stdout, source, n);

  gmp_randclear(state);
  delete_array(source, n);
  mpz_clear(seed);
  return 0;
}
コード例 #5
0
ファイル: circuit.c プロジェクト: david-redick/lwmapgen
void circuit()
{
     int r, c;
     int do_cut;
     int radius;
     int centerx, centery;


     clear_invert_map();

     grid = (char **) new_grid(map.num_row, map.num_col, sizeof(char));
     count = (int *) new_array(map.num_row, sizeof(int));

     radius = (map.sec_width > map.sec_height ? map.sec_width : map.sec_height)/4.0;
     radius = (radius == 0 ? 1 : radius );

     line_size = (map.sec_width > map.sec_height ? map.sec_width : map.sec_height)/4.0;
     line_size = (line_size == 0 ? 1 : line_size);

     for( r = 0; r < map.num_row; r++ )
     {
          count[r] = 0;
          for( c = 0; c < map.num_col; c++ )
          {
               if( (r == 0 || r == map.num_row-1)
               && (c == 0 || c == map.num_col/2 || c == map.num_col-1) )
                    do_cut = 1;
               else
                    do_cut = rand()%4;

               if( do_cut != 1 )
               {
                    grid[r][c] = 0;
                    continue;
               }

               section_center(&centerx, &centery, r, c);
               circlefill(map.map, centerx, centery, radius, 255);

               grid[r][c] = 1;
               count[r]++;
          }
     }


     connect_rows();
     connect_front();
     connect_back();
     connect_mid();

     delete_grid((void **)grid, map.num_row);
     delete_array(count);

     /* redraw outline */
     /* TODO: once in a while if cuts off the edge.. */
     rect(map.map, 0, 0, map.width-1, map.height-1, 0);

return;
}
コード例 #6
0
int main ()
{
	int notpassed = 0;
	int passed = 0;
	
	struct array array1;
	
	check (init_array (&array1))
	
	test (add_element (&array1, 1), NO_ERRORS)
	
	test (add_element (&array1, 8), NO_ERRORS)
	
	test (change_element(&array1, 12, 33), WRITE_TO_UNALLOCATED_MEMORY)
	
	test (change_element(&array1, 1, 33), NO_ERRORS)
	
	test (add_element (&array1, 41), NO_ERRORS)
	
	test (add_element (&array1, 3), NO_ERRORS)
	
	test (add_element (&array1, 9), NO_ERRORS)
	
	
	test (elements_sum (&array1), NO_ERRORS)
	
	test (add_element (&array1, 13), NO_ERRORS)
	
	test (verbose_full_print (&array1), NO_ERRORS)
	
	test (remove_element (&array1, 4), NO_ERRORS)
	
	test (print_array (&array1), NO_ERRORS)
	
	test (find_element(&array1, 120), ELEMENT_NOT_FOUND)
	
	test (print_array (&array1), NO_ERRORS)
	
	test (print_array (&array1), NO_ERRORS)
	
	test (print_element(&array1, 40), GARBAGE_READ)
	
	test (zero_array   (&array1), NO_ERRORS)
	
	test (print_array (&array1), NO_ERRORS)
	
	printf ("datalen = %i, memlen = %i\n", get_datalen (&array1), get_memlen (&array1));
	
	for (int i = 0; i < 305; i ++)
		check (add_element (&array1, 41)); 
	
	printf ("Passed %i, not passed %i.\n", passed, notpassed);
	
	test (delete_array (&array1), NO_ERRORS)
	
	print_exit_message ();
	
	return 0;
}
コード例 #7
0
void PtrFreeScene :: translate_geometry() {
  //mesh_first_triangle_offset.resize(0);
  delete_array(mesh_first_triangle_offset);
  const uint n_vertices  = data_set->GetTotalVertexCount();
  const uint n_triangles = data_set->GetTotalTriangleCount();

  // translate mesh normals, colors and uvs
  this->vertex_count = n_vertices;
  this->normals_count = n_vertices;
  this->colors_count = n_vertices;
  this->uvs_count = n_vertices;
  this->triangles_count = n_triangles;

  reset_array(this->vertexes, this->vertex_count);
  reset_array(this->normals, this->normals_count);
  reset_array(this->colors, this->colors_count);
  reset_array(this->uvs, this->uvs_count);
  reset_array(this->triangles, this->triangles_count);
  //normals.resize(n_vertices);
  //colors.resize(n_vertices);
  //uvs.resize(n_vertices);
  uint index = 0;

  // aux data to later translate triangles
  uint *mesh_offsets = new uint[original_scene->objects.size()];
  uint v_index = 0;

  for (uint i = 0; i < original_scene->objects.size(); ++i) {
    const luxrays::ExtMesh* mesh = original_scene->objects[i];

    mesh_offsets[i] = v_index;
    for(uint j = 0; j < mesh->GetTotalVertexCount(); ++j) {
      normals[index]  = Normal(mesh->GetNormal(j));
      colors[index]   = Spectrum(mesh->GetColor(j));
      uvs[index]      = (mesh->HasUVs()) ? mesh->GetUV(j) : UV(0.f, 0.f);
      vertexes[index] = Point(mesh->GetVertex(j));
      index++;
    }
    v_index += mesh->GetTotalVertexCount();
  }

  // translate mesh triangles
  //triangles.resize(n_triangles);
  index = 0;
  for(uint i = 0; i < original_scene->objects.size(); ++i) {
    const luxrays::ExtMesh* mesh   = original_scene->objects[i];
    const luxrays::Triangle *mtris = mesh->GetTriangles();
    const uint moffset = mesh_offsets[i];
    for (uint j = 0; j < mesh->GetTotalTriangleCount(); ++j) {
      triangles[index++] = Triangle(
          mtris[j].v[0] + moffset,
          mtris[j].v[1] + moffset,
          mtris[j].v[2] + moffset);
    }
  }

  delete[] mesh_offsets;
}
コード例 #8
0
ファイル: ebpf_runtime_test.c プロジェクト: ederollora/p4c
void *run_and_record_output(packet_filter ebpf_filter, const char *pcap_base, pcap_list_t *pkt_list, int debug) {
    /* Create an array of packet lists */
    pcap_list_array_t *output_array = allocate_pkt_list_array();
    /* Feed the packets into our "loaded" program */
    pcap_list_t *output_pkts = feed_packets(ebpf_filter, pkt_list, debug);
    /* Split the output packet list by interface. This destroys the list. */
    output_array = split_and_delete_list(output_pkts, output_array);
    /* Write each list to a separate pcap output file */
    write_pkts_to_pcaps(pcap_base, output_array, debug);
    /* Delete the array, including the data it is holding */
    delete_array(output_array);
}
コード例 #9
0
ファイル: mesh.cpp プロジェクト: Gnurou/glmark2
/**
 * Resets a Mesh object to its initial, empty state.
 */
void
Mesh::reset()
{
    delete_array();
    delete_vbo();

    vertices_.clear();
    vertex_format_.clear();
    attrib_locations_.clear();
    attrib_data_ptr_.clear();
    vertex_size_ = 0;
    vertex_stride_ = 0;
}
コード例 #10
0
ファイル: selbox.c プロジェクト: BADSEC/multitail
char * select_file(char *input, int what_help)
{
	char **list = NULL, *isdir = NULL, *path = NULL;
	char *new_fname = NULL;
	struct stat64 statbuf;
	int list_n, index;
	int strbufsize = find_path_max();

	list_n = match_files(input, &path, &list, &isdir);
	if (list_n == 0)
	{
		myfree(path);
		flash();
		return NULL;
	}

	index = selection_box((void **)list, isdir, list_n, SEL_FILES, what_help, NULL);
	if (index != -1)
	{
		new_fname = (char *)mymalloc(strbufsize + 1);

		snprintf(new_fname, strbufsize, "%s%s", path, list[index]);

		if (stat64(new_fname, &statbuf) == -1)
		{
			myfree(new_fname);
			new_fname = NULL;
			flash();
		}
		else
		{
			if (S_ISDIR(statbuf.st_mode))
			{
				strncat(new_fname, "/", strbufsize);
			}
		}
	}

	delete_array(list, list_n);

	myfree(isdir);
	myfree(path);

	return new_fname;
}
コード例 #11
0
void main()
{
	int number;
	int position;
	char element[s];

	printf("\n Input the number of elements in the array:");
	scanf("%d", &number);
	fflush(stdin);
	input(employ, number);
	printf("\n Entered list is as follows:\n");

	display(employ, number);
	fflush(stdin);
	printf("\n Input the position from where you want delete an element:");
	scanf("%d", &position);

	number = delete_array(employ, number, position, element);
	display(employ,number);
	return;
}
コード例 #12
0
void PtrFreeScene :: compile_geometry() {

  // clear vectors
  delete_array(mesh_ids);
  delete_array(vertexes);
  delete_array(normals);
  delete_array(colors);
  delete_array(uvs);
  delete_array(triangles);
  delete_array(mesh_descs);
  delete_array(mesh_first_triangle_offset);

  this->mesh_count = original_scene->objects.size();//data_set->meshes.size();

  // copy mesh_id_table
  // TODO check if this is valid
  //mesh_ids.resize(data_set->meshes.size());
  this->mesh_ids = new uint[data_set->totalTriangleCount];
  //this->mesh_ids = data_set->GetMeshIDTable();
  for(unsigned i = 0; i < data_set->totalTriangleCount; ++i)
    this->mesh_ids[i] = data_set->GetMeshIDTable()[i]; // TODO probably change this to a memcpy

  // get scene bsphere
  this->bsphere = data_set->GetPPMBSphere();

  // check used accelerator type
  if (accel_type == ppm::ACCEL_QBVH) {
    const lux_ext_mesh_list_t meshs = original_scene->objects;
    compile_mesh_first_triangle_offset(meshs);
    translate_geometry_qbvh(meshs);
  } else {
    cout << "here" << endl;
    translate_geometry();
//    throw string("Unsupported accelerator type ").append(config.accel_name);
  }

}
コード例 #13
0
ファイル: main.cpp プロジェクト: NIA/D3DLighting
INT WINAPI wWinMain( HINSTANCE, HINSTANCE, LPWSTR, INT )
{
    srand( static_cast<unsigned>( time(NULL) ) );
    
    SkinningVertex * cylinder_vertices = NULL;
    Index * cylinder_indices = NULL;
    Vertex * tesselated_vertices = NULL;
    Index * tesselated_indices = NULL;
    try
    {
        Application app;

        VertexShader skinning_shader(app.get_device(), SKINNING_VERTEX_DECL_ARRAY, SKINNING_SHADER_FILENAME);
        VertexShader morphing_shader(app.get_device(), VERTEX_DECL_ARRAY, MORPHING_SHADER_FILENAME);
        
        // -------------------------- C y l i n d e r -----------------------

        cylinder_vertices = new SkinningVertex[CYLINDER_VERTICES_COUNT];
        cylinder_indices = new Index[CYLINDER_INDICES_COUNT];

        float height = 2.0f;
        cylinder( 0.7f, height,
                  colors, colors_count,
                  cylinder_vertices, cylinder_indices );

        SkinningModel cylinder1(app.get_device(),
                                D3DPT_TRIANGLESTRIP,
                                skinning_shader,
                                cylinder_vertices,
                                CYLINDER_VERTICES_COUNT,
                                cylinder_indices,
                                CYLINDER_INDICES_COUNT,
                                CYLINDER_INDICES_COUNT - 2,
                                D3DXVECTOR3(0.5f, 0.5f, -height/2),
                                D3DXVECTOR3(0,0,0),
                                D3DXVECTOR3(0,0,-1));

        height = 2.3f;
        cylinder( 0.3f, height,
                  &SECOND_CYLINDER_COLOR, 1,
                  cylinder_vertices, cylinder_indices );

        SkinningModel cylinder2(app.get_device(),
                                D3DPT_TRIANGLESTRIP,
                                skinning_shader,
                                cylinder_vertices,
                                CYLINDER_VERTICES_COUNT,
                                cylinder_indices,
                                CYLINDER_INDICES_COUNT,
                                CYLINDER_INDICES_COUNT - 2,
                                D3DXVECTOR3(-1.0f, 0.5f, height/2),
                                D3DXVECTOR3(D3DX_PI,0,-D3DX_PI/4),
                                D3DXVECTOR3(0,0,1));

        
        // -------------------------- P y r a m i d -----------------------
        const Index PLANES_PER_PYRAMID = 8;
        const D3DXVECTOR3 normal_up(0,0,1);
        const Vertex pyramid_vertices[]=
        {
            Vertex(D3DXVECTOR3(  0.5f, -0.5f,  0.00f ),normal_up),
            Vertex(D3DXVECTOR3( -0.5f, -0.5f,  0.00f ),normal_up),
            Vertex(D3DXVECTOR3( -0.5f,  0.5f,  0.00f ),normal_up),
            Vertex(D3DXVECTOR3(  0.5f,  0.5f,  0.00f ),normal_up),
            Vertex(D3DXVECTOR3(  0.0f,  0.0f,  0.7071f ),normal_up),
            Vertex(D3DXVECTOR3(  0.0f,  0.0f, -0.7071f ),normal_up),
        };
        const Index pyramid_indices[PLANES_PER_PYRAMID*VERTICES_PER_TRIANGLE] =
        {
            0, 4, 3,
            3, 4, 2,
            2, 4, 1,
            1, 4, 0,

            0, 3, 5,
            3, 2, 5,
            2, 1, 5,
            1, 0, 5,
        };

        const Index ALL_TESSELATED_VERTICES_COUNT = PLANES_PER_PYRAMID*TESSELATED_VERTICES_COUNT; // per 8 tessellated triangles
        const DWORD ALL_TESSELATED_INDICES_COUNT = PLANES_PER_PYRAMID*TESSELATED_INDICES_COUNT; // per 8 tessellated triangles

        tesselated_vertices = new Vertex[ALL_TESSELATED_VERTICES_COUNT];
        tesselated_indices = new Index[ALL_TESSELATED_INDICES_COUNT];

        for( DWORD i = 0; i < PLANES_PER_PYRAMID; ++i )
        {
            tessellate( pyramid_vertices, pyramid_indices, i*VERTICES_PER_TRIANGLE,
                        &tesselated_vertices[i*TESSELATED_VERTICES_COUNT], i*TESSELATED_VERTICES_COUNT,
                        &tesselated_indices[i*TESSELATED_INDICES_COUNT], SPHERE_COLOR );
        }
        
        MorphingModel pyramid( app.get_device(),
                               D3DPT_TRIANGLELIST,
                               morphing_shader,
                               tesselated_vertices,
                               ALL_TESSELATED_VERTICES_COUNT,
                               tesselated_indices,
                               ALL_TESSELATED_INDICES_COUNT,
                               ALL_TESSELATED_INDICES_COUNT/VERTICES_PER_TRIANGLE,
                               D3DXVECTOR3(0, -1.3f, -0.2f),
                               D3DXVECTOR3(0,0,0),
                               0.7071f);

        app.add_model(cylinder1);
        app.add_model(cylinder2);
        app.add_model(pyramid);
        app.run();
        delete_array(&tesselated_indices);
        delete_array(&tesselated_vertices);
        delete_array(&cylinder_indices);
        delete_array(&cylinder_vertices);
    }
    catch(RuntimeError &e)
    {
        delete_array(&tesselated_indices);
        delete_array(&tesselated_vertices);
        delete_array(&cylinder_indices);
        delete_array(&cylinder_vertices);
        const TCHAR *MESSAGE_BOX_TITLE = _T("Lighting error!");
        MessageBox(NULL, e.message(), MESSAGE_BOX_TITLE, MB_OK | MB_ICONERROR);
        return -1;
    }
    return 0;
}
コード例 #14
0
DistanceSet::~DistanceSet()
{
	delete_array(distances, points.size());
	delete_array(durations, points.size());
}
コード例 #15
0
void PtrFreeScene :: compile_texture_maps() {
  delete_array(tex_maps);
  delete_array(rgb_tex);
  delete_array(alpha_tex);
  delete_array(mesh_texs);
  delete_array(bump_map);
  delete_array(bump_map_scales);
  delete_array(normal_map);
  this->tex_maps_count = 0;

  // translate mesh texture maps
  std::vector<luxrays::TextureMap*> tms;
  original_scene->texMapCache->GetTexMaps(tms);
  // compute amount of RAM to allocate
  //uint rgb_tex_size = 0;
  //uint alpha_tex_size = 0;
  this->rgb_tex_count = 0;
  this->alpha_tex_count = 0;
  for(uint i = 0; i < tms.size(); ++i) {
    luxrays::TextureMap* tm = tms[i];
    const uint pixel_count = tm->GetWidth() * tm->GetHeight();
    this->rgb_tex_count += pixel_count;
    if (tm->HasAlpha())
      this->alpha_tex_count += pixel_count;
  }

  // allocate texture map
  if ((this->rgb_tex_count > 0) || (this->alpha_tex_count) > 0) {
    this->tex_maps_count = tms.size();
    reset_array(this->tex_maps, this->tex_maps_count);
    //tex_maps.resize(tms.size());

    if (this->rgb_tex_count > 0) {
      uint rgb_offset = 0;
      //rgb_tex.resize(rgb_tex_size);
      reset_array(this->rgb_tex, this->rgb_tex_count);
      for(uint i = 0; i < tms.size(); ++i) {
        luxrays::TextureMap* tm = tms[i];
        const uint pixel_count = tm->GetWidth() * tm->GetHeight();
        // TODO memcpy safe?
        memcpy(&rgb_tex[rgb_offset], tm->GetPixels(), pixel_count * sizeof(Spectrum));
        this->tex_maps[i].rgb_offset = rgb_offset;
        rgb_offset += pixel_count;
      }
    }

    if (this->alpha_tex_count > 0) {
      uint alpha_offset = 0;
      //alpha_tex.resize(alpha_tex_size);
      reset_array(this->alpha_tex, this->alpha_tex_count);
      for(uint i = 0; i < tms.size(); ++i) {
        luxrays::TextureMap* tm = tms[i];
        const uint pixel_count = tm->GetWidth() * tm->GetHeight();

        if (tm->HasAlpha()) {
          memcpy(&alpha_tex[alpha_offset], tm->GetAlphas(), pixel_count * sizeof(float));
          this->tex_maps[i].alpha_offset = alpha_offset;
          alpha_offset += pixel_count;
        } else {
          this->tex_maps[i].alpha_offset = PPM_NONE;
        }
      }
    }

    // translate texture map description
    for(uint i = 0; i < tms.size(); ++i) {
      luxrays::TextureMap* tm = tms[i];
      this->tex_maps[i].width = tm->GetWidth();
      this->tex_maps[i].height = tm->GetHeight();
    }

    // translate mesh texture indexes
    //const uint mesh_count = mesh_mats.size();
    //mesh_texs.resize(mesh_count);
    reset_array(this->mesh_texs, this->mesh_materials_count);
    for(uint i = 0; i < this->mesh_materials_count; ++i) {
      luxrays::TexMapInstance* t = original_scene->objectTexMaps[i];

      if (t) { // look for the index
        uint index = 0;
        for(uint j = 0; j < tms.size(); ++j) {
          if (t->GetTexMap() == tms[j]) {
            index = j;
            break;
          }
        }
        this->mesh_texs[i] = index;
      } else {
        this->mesh_texs[i] = PPM_NONE;
      }
    }

    // translate mesh bump map indexes
    bool has_bump_mapping = false;
    //bump_map.resize(mesh_count);
    reset_array(this->bump_map, this->mesh_materials_count);
    for(uint i = 0; i < this->mesh_materials_count; ++i) {
      luxrays::BumpMapInstance* bm = original_scene->objectBumpMaps[i];

      if (bm) { // look for the index
        uint index = 0;
        for(uint j = 0; j < tms.size(); ++j) {
          if (bm->GetTexMap() == tms[j]) {
            index = j;
            break;
          }
        }
        this->bump_map[i] = index;
        has_bump_mapping = true;
      } else {
        this->bump_map[i] = PPM_NONE;
      }
    }

    if (has_bump_mapping) {
      //bump_map_scales.resize(mesh_count);
      reset_array(this->bump_map_scales, this->mesh_materials_count);
      for(uint i = 0; i < mesh_count; ++i) {
        luxrays::BumpMapInstance* bm = original_scene->objectBumpMaps[i];

        if (bm)
          this->bump_map_scales[i] = bm->GetScale();
        else
          this->bump_map_scales[i] = 1.f;
      }
    }

    // translate mesh normal map indices
    //unused? bool has_normal_mapping = false;
    //normal_map.resize(mesh_count);
    reset_array(this->normal_map, this->mesh_materials_count);
    for(uint i = 0; i < mesh_count; ++i) {
      luxrays::NormalMapInstance* nm = original_scene->objectNormalMaps[i];

      if (nm) { // look for the index
        uint index = 0;
        for(uint j = 0; j < tms.size(); ++j) {
          if (nm->GetTexMap() == tms[j]) {
            index = j;
            break;
          }
        }
        this->normal_map[i] = index;
        //has_normal_mapping = true;
      } else {
        this->normal_map[i] = PPM_NONE;
      }
    }
  }
}
コード例 #16
0
// Parse a Python object as a sequence of either QVector[234]D or
// QMatrix[234]x[234] instances, or a sequence of sequence of floats and return
// an array that can be passed to QOpenGLShaderProgram::setUniformValueArray().
// The array is destroyed only when the shader is garbage collected or when
// replaced by another array.
const void *qpyopengl_uniform_value_array(PyObject *values, PyObject *shader,
        PyObject *key, const sipTypeDef **array_type, int *array_len,
        int *tsize, sipErrorState *estate)
{
    // Check the key was created correctly.
    if (!key)
    {
        *estate = sipErrorFail;
        return 0;
    }

    // Get the dict that holds the converted arrays.
    PyObject *dict = ((sipSimpleWrapper *)shader)->user;

    if (!dict)
    {
        dict = PyDict_New();

        if (!dict)
        {
            Py_DECREF(key);

            *estate = sipErrorFail;
            return 0;
        }

        ((sipSimpleWrapper *)shader)->user = dict;
    }

    // Check that values is a non-empty sequence.
    values = PySequence_Fast(values,
            "a uniform value array must be a sequence");

    if (!values)
    {
        Py_DECREF(key);

        *estate = sipErrorContinue;
        return 0;
    }

    SIP_SSIZE_T nr_items = PySequence_Fast_GET_SIZE(values);

    if (nr_items < 1)
    {
        PyErr_SetString(PyExc_TypeError,
                "a uniform value array must have at least one element");

        Py_DECREF(key);
        Py_DECREF(values);

        *estate = sipErrorFail;
        return 0;
    }

    // The first element determines the type expected.
    PyObject *itm = PySequence_Fast_GET_ITEM(values, 0);

    const sipTypeDef *td;
    SIP_SSIZE_T nr_dim = 0;
    void *array;

    if (sipCanConvertToType(itm, sipType_QVector2D, SIP_NOT_NONE))
    {
        td = sipType_QVector2D;
        array = new QVector2D[nr_items];
    }
    else if (sipCanConvertToType(itm, sipType_QVector3D, SIP_NOT_NONE))
    {
        td = sipType_QVector3D;
        array = new QVector3D[nr_items];
    }
    else if (sipCanConvertToType(itm, sipType_QVector4D, SIP_NOT_NONE))
    {
        td = sipType_QVector4D;
        array = new QVector4D[nr_items];
    }
    else if (sipCanConvertToType(itm, sipType_QMatrix2x2, SIP_NOT_NONE))
    {
        td = sipType_QMatrix2x2;
        array = new QMatrix2x2[nr_items];
    }
    else if (sipCanConvertToType(itm, sipType_QMatrix2x3, SIP_NOT_NONE))
    {
        td = sipType_QMatrix2x3;
        array = new QMatrix2x3[nr_items];
    }
    else if (sipCanConvertToType(itm, sipType_QMatrix2x4, SIP_NOT_NONE))
    {
        td = sipType_QMatrix2x4;
        array = new QMatrix2x4[nr_items];
    }
    else if (sipCanConvertToType(itm, sipType_QMatrix3x2, SIP_NOT_NONE))
    {
        td = sipType_QMatrix3x2;
        array = new QMatrix3x2[nr_items];
    }
    else if (sipCanConvertToType(itm, sipType_QMatrix3x3, SIP_NOT_NONE))
    {
        td = sipType_QMatrix3x3;
        array = new QMatrix3x3[nr_items];
    }
    else if (sipCanConvertToType(itm, sipType_QMatrix3x4, SIP_NOT_NONE))
    {
        td = sipType_QMatrix3x4;
        array = new QMatrix3x4[nr_items];
    }
    else if (sipCanConvertToType(itm, sipType_QMatrix4x2, SIP_NOT_NONE))
    {
        td = sipType_QMatrix4x2;
        array = new QMatrix4x2[nr_items];
    }
    else if (sipCanConvertToType(itm, sipType_QMatrix4x3, SIP_NOT_NONE))
    {
        td = sipType_QMatrix4x3;
        array = new QMatrix4x3[nr_items];
    }
    else if (sipCanConvertToType(itm, sipType_QMatrix4x4, SIP_NOT_NONE))
    {
        td = sipType_QMatrix4x4;
        array = new QMatrix4x4[nr_items];
    }
    else if (PySequence_Check(itm) && (nr_dim = PySequence_Size(itm)) >= 1)
    {
        td = 0;
        array = new GLfloat[nr_items * nr_dim];
    }
    else
    {
        PyErr_SetString(PyExc_TypeError,
                "a uniform value array must be a sequence of QVector2D, "
                "QVector3D, QVector4D, QMatrix2x2, QMatrix2x3, QMatrix2x4, "
                "QMatrix3x2, QMatrix3x3, QMatrix3x4, QMatrix4x2, QMatrix4x3, "
                "QMatrix4x4, or a sequence of sequences of floats");

        Py_DECREF(key);
        Py_DECREF(values);

        *estate = sipErrorFail;
        return 0;
    }

    // Convert the values.
    for (SIP_SSIZE_T i = 0; i < nr_items; ++i)
    {
        int iserr = 0;

        itm = PySequence_Fast_GET_ITEM(values, i);

        if (td)
        {
            void *cpp;

            cpp = sipForceConvertToType(itm, td, 0,
                    SIP_NOT_NONE | SIP_NO_CONVERTORS, 0, &iserr);

            if (iserr)
            {
                PyErr_Format(PyExc_TypeError,
                        "uniform value array elements should all be '%s', not "
                        "'%s'",
                        sipTypeAsPyTypeObject(td)->tp_name,
                        Py_TYPE(itm)->tp_name);
            }
            else if (td == sipType_QVector2D)
            {
                QVector2D *a = reinterpret_cast<QVector2D *>(array);

                a[i] = *reinterpret_cast<QVector2D *>(cpp);
            }
            else if (td == sipType_QVector3D)
            {
                QVector3D *a = reinterpret_cast<QVector3D *>(array);

                a[i] = *reinterpret_cast<QVector3D *>(cpp);
            }
            else if (td == sipType_QVector4D)
            {
                QVector4D *a = reinterpret_cast<QVector4D *>(array);

                a[i] = *reinterpret_cast<QVector4D *>(cpp);
            }
            else if (td == sipType_QMatrix2x2)
            {
                QMatrix2x2 *a = reinterpret_cast<QMatrix2x2 *>(array);

                a[i] = *reinterpret_cast<QMatrix2x2 *>(cpp);
            }
            else if (td == sipType_QMatrix2x3)
            {
                QMatrix2x3 *a = reinterpret_cast<QMatrix2x3 *>(array);

                a[i] = *reinterpret_cast<QMatrix2x3 *>(cpp);
            }
            else if (td == sipType_QMatrix2x4)
            {
                QMatrix2x4 *a = reinterpret_cast<QMatrix2x4 *>(array);

                a[i] = *reinterpret_cast<QMatrix2x4 *>(cpp);
            }
            else if (td == sipType_QMatrix3x2)
            {
                QMatrix3x2 *a = reinterpret_cast<QMatrix3x2 *>(array);

                a[i] = *reinterpret_cast<QMatrix3x2 *>(cpp);
            }
            else if (td == sipType_QMatrix3x3)
            {
                QMatrix3x3 *a = reinterpret_cast<QMatrix3x3 *>(array);

                a[i] = *reinterpret_cast<QMatrix3x3 *>(cpp);
            }
            else if (td == sipType_QMatrix3x4)
            {
                QMatrix3x4 *a = reinterpret_cast<QMatrix3x4 *>(array);

                a[i] = *reinterpret_cast<QMatrix3x4 *>(cpp);
            }
            else if (td == sipType_QMatrix4x2)
            {
                QMatrix4x2 *a = reinterpret_cast<QMatrix4x2 *>(array);

                a[i] = *reinterpret_cast<QMatrix4x2 *>(cpp);
            }
            else if (td == sipType_QMatrix4x3)
            {
                QMatrix4x3 *a = reinterpret_cast<QMatrix4x3 *>(array);

                a[i] = *reinterpret_cast<QMatrix4x3 *>(cpp);
            }
            else if (td == sipType_QMatrix4x4)
            {
                QMatrix4x4 *a = reinterpret_cast<QMatrix4x4 *>(array);

                a[i] = *reinterpret_cast<QMatrix4x4 *>(cpp);
            }
        }
        else
        {
            itm = PySequence_Fast(itm,
                    "uniform value array elements should all be sequences");

            if (itm)
            {
                if (PySequence_Fast_GET_SIZE(itm) != nr_dim)
                {
                    PyErr_Format(PyExc_TypeError,
                            "uniform value array elements should all be "
                            "sequences of length "
#if PY_VERSION_HEX >= 0x02050000
                            "%zd",
#else
                            "%d",
#endif
                            nr_dim);

                    Py_DECREF(itm);
                    iserr = 1;
                }
                else
                {
                    GLfloat *ap = reinterpret_cast<GLfloat *>(array);

                    PyErr_Clear();

                    for (SIP_SSIZE_T j = 0; j < nr_dim; ++j)
                        *ap++ = PyFloat_AsDouble(
                                PySequence_Fast_GET_ITEM(itm, j));

                    if (PyErr_Occurred())
                    {
                        PyErr_SetString(PyExc_TypeError,
                                "uniform value array elements should all be "
                                "sequences of floats");

                        Py_DECREF(itm);
                        iserr = 1;
                    }
                }
            }
            else
            {
                iserr = 1;
            }
        }

        if (iserr)
        {
            Py_DECREF(key);
            Py_DECREF(values);
            delete_array(array, td);

            *estate = sipErrorFail;
            return 0;
        }
    }

    Py_DECREF(values);

    // Wrap the array in a Python object so that it won't leak.
#if defined(SIP_USE_PYCAPSULE)
    PyObject *array_obj = PyCapsule_New(array, 0, array_dtor);

    if (array_obj && PyCapsule_SetContext(array_obj, const_cast<sipTypeDef *>(td)) != 0)
    {
        Py_DECREF(array_obj);
        array_obj = 0;
    }
#else
    PyObject *array_obj = PyCObject_FromVoidPtrAndDesc(array, const_cast<sipTypeDef *>(td), array_dtor);
#endif

    if (!array_obj)
    {
        Py_DECREF(key);
        delete_array(array, td);

        *estate = sipErrorFail;
        return 0;
    }

    int rc = PyDict_SetItem(dict, key, array_obj);

    Py_DECREF(key);
    Py_DECREF(array_obj);

    if (rc < 0)
    {
        *estate = sipErrorFail;
        return 0;
    }

    *array_type = td;
    *array_len = nr_items;
    *tsize = nr_dim;

    return array;
}
コード例 #17
0
static void array_dtor(void *array, void *td)
{
    delete_array(array, reinterpret_cast<const sipTypeDef *>(td));
}
コード例 #18
0
static void array_dtor(PyObject *capsule)
{
    delete_array(PyCapsule_GetPointer(capsule, 0),
            reinterpret_cast<const sipTypeDef *>(
                    PyCapsule_GetContext(capsule)));
}
コード例 #19
0
ファイル: parser.cpp プロジェクト: jkhoogland/jsonpack
//---------------------------------------------------------------------------------------------------
bool parser::value( array_t &elemets)
{
    if( _tk == JTK_INTEGER ||
            _tk == JTK_REAL ||
            _tk == JTK_STRING_LITERAL ||
            _tk == JTK_TRUE ||
            _tk == JTK_FALSE ||
            _tk == JTK_NULL ) //literals
    {

        /**
         * Add value into the vector
         */
        jsonpack::value vpos = _s.get_last_value(_tk == JTK_STRING_LITERAL);
        vpos._pos._type = _tk;
        elemets.push_back(vpos);

        advance();
        return true;
    }

    if( _tk == JTK_OPEN_KEY )
    {
        advance();

        object_t* new_obj = new object_t();  // create obj

        bool object_ok = item_list(*new_obj);          //fill obj
        
        if(object_ok)
        {
            jsonpack::value p;                                  //create value width field _obj
            p._obj = new_obj;
            p._field = _OBJ;

            elemets.push_back(p);                               // add to the map

            return match(JTK_CLOSE_KEY);
        }

        delete_object(new_obj);
        return false;
    }

    if( _tk == JTK_OPEN_BRACKET )
    {
        advance();

        array_t* new_array = new array_t();   // create arr

        bool array_ok = array_list(*new_array);         // fill arr
        if(array_ok)
        {
            jsonpack::value p;                                  //create value width field _arr
            p._arr = new_array;
            p._field = _ARR;

            elemets.push_back(p);                               // add to the vector

            return match(JTK_CLOSE_BRACKET);
        }
        delete_array(new_array);
        return false;
    }

    return false;
}
コード例 #20
0
void
test_op_assign (const T*,
                std::valarray<T>&
                (std::valarray<T>::*op_assign)(const std::valarray<T>&),
                const char *tname,     // T's type name
                const char *opname,    // which assignment operator
                int         line,      // test case line number
                const char *lhs_str,   // left hand side of assignment
                const char *rhs_str,   // right hand side of assignment
                const char *res_str)   // result of assignment
{
    std::size_t nelems = 0;
    std::size_t tmp;

    // create an array of values of type T from the string lhs_str
    // representing the left-hand side argument of the assignment
    const T* const lhs_array = make_array ((const T*)0, lhs_str, &nelems);

    // create an array of values of type T from the string rhs_str
    // representing the right-hand side argument of the assignment
    const T* const rhs_array = make_array ((const T*)0, rhs_str, &tmp);

    // both arguments of the assignment must have the same size
    RW_ASSERT (tmp == nelems);

    // create an array of values of type T from the string res_str
    // representing the result of the assignment
    const T* const res_array = make_array ((const T*)0, res_str, &tmp);

    // the result of the assignment must have the same size as both
    // arguments
    RW_ASSERT (tmp == nelems);

    // construct valarray arguments from the arrays created above
    /* const */ std::valarray<T> lhs_va (lhs_array, nelems);
    const       std::valarray<T> rhs_va (rhs_array, nelems);

    char*       fname = 0;
    std::size_t size  = 0;

    // pointer to a counter keeping track of all objects of type T
    // in existence (non-null only for T=UserClass)
    const std::size_t* const pcounter = count ((const T*)0);

    // get the number of objects of type T (only possible for user
    // defined T) before invoking the operator
    std::size_t nobjects = pcounter ? *pcounter : 0;

    // format the name of the function call to be used in diagnostic
    // messages below
    rw_asnprintf (&fname, &size,
                  "valarray<%s>(%s) %s std::valarray<%1$s>(%s)",
                  tname, lhs_str, opname, rhs_str);

    // invoke the assignment operator through the member pointer
    std::valarray<T> &res = (lhs_va.*op_assign)(rhs_va);

    // verify that the resturned reference refers to the assignee
    rw_assert (&res == &lhs_va, 0, line,
               "line %d == %#p, got %#p",
               __LINE__, fname, &lhs_va, &res);
    

    // verify the size of the array
    rw_assert (lhs_va.size () == nelems, 0, line,
               "line %d. %s.size() == %zu, got %zu",
               __LINE__, fname, nelems, lhs_va.size ());

    if (pcounter) {
        // verify that the assignment didn't leak any objects
        nobjects = *pcounter - nobjects;
        
        rw_assert (0 == nobjects, 0, line,
                   "line %d. %s constucted %zu objects, expected %zu",
                   __LINE__, fname, nobjects, nelems);
    }

    // verify the element values
    for (std::size_t i = 0; i != nelems; ++i) {
        if (!rw_assert (lhs_va [i] == res_array [i], 0, line,
                        "line %d. %s: element at index %zu == %d, got %d",
                        __LINE__, fname, i, value (res_array [i]),
                        value (lhs_va [i])))
            break;

    }

    delete_array (lhs_array, nelems);
    delete_array (rhs_array, nelems);

    std::free (fname);
}
コード例 #21
0
// returns an array of size elements of type UserClass
// constructed from a string of comma-separated values
UserClass*
make_array (const UserClass*, const char *s, std::size_t *psize)
{
    std::size_t bufsize = 0;   // capacity of buffer
    std::size_t nelems  = 0;   // number of elements in buffer

    if (psize)
        *psize = 0;

    if (0 == s)
        s = "";

    UserClass* buf = 0;

    while (*s) {

        // get the next value from the string
        char *end = 0;
        const double val = std::strtod (s, &end);

        unsigned long repeat = 1;
        
        if ('@' == *end) {
            // process repeat directive (e.g., "123@5" expands into
            // 5 copies of the number 123)
            char *e = 0;
            repeat = std::strtoul (++end, &e, 10);

            // skip trailing whitespace
            for (; ' ' == *end; ++end);

            // the next character must be either a NUL or comma
            RW_ASSERT ('\0' == *e || ',' == *e);

            if (',' == *e)
                ++e;

            s = e;
        }
        else {
            // skip trailing whitespace
            for (; ' ' == *end; ++end);

            // the next character must be NUL or  a comma
            RW_ASSERT ('\0' == *end || ',' == *end);

            s = end;
            if (*s)
                ++s;
        }

        while (repeat--) {

            if (nelems == bufsize) {
                static const std::size_t size = sizeof (UserClass);

                void* const raw = operator new ((bufsize + 1) * 2 * size);
                UserClass* const tmp = _RWSTD_STATIC_CAST (UserClass*, raw);

                for (std::size_t i = 0; i != nelems; ++i)
                    new (tmp +i) UserClass (buf [i]);

                bufsize = (bufsize + 1) * 2;

                delete_array (buf, nelems);
                buf = tmp;
            }

            new (buf + nelems) UserClass ();
            buf [nelems].data_.val_ = int (val);
            ++nelems;
        }
    }

    if (psize)
        *psize = nelems;

    return buf;
}
コード例 #22
0
ファイル: 26.valarray.cons.cpp プロジェクト: Flameeyes/stdcxx
void
test_ctor (const T*, const char *tname, CtorId which, bool copy,
           int line, const char *str, std::size_t nelems)
{
    std::valarray<T> *pva = 0;

    T* const array = make_array ((const T*)0, str, &nelems);

    char*       fname = 0;
    std::size_t size  = 0;

    // pointer to a counter keepint track of all objects of type T
    // in existence (non-null only for T=UserClass)
    const std::size_t* const pcounter = count ((const T*)0);

    // get the number of objects of type T before invoking the ctor
    std::size_t nobjects = pcounter ? *pcounter : 0;

    switch (which) {

    case DefaultCtor:
        rw_asnprintf (&fname, &size, "valarray<%s>::valarray()", tname);
        pva = new std::valarray<T>;
        break;

    case SizeCtor:
        rw_asnprintf (&fname, &size,
                      "valarray<%s>::valarray(size_t = %zu)",
                      tname, nelems);
        pva = new std::valarray<T>(nelems);
        break;

    case ValueCtor: {
        rw_asnprintf (&fname, &size,
                      "valarray<%s>::valarray(const %1$s& = %1$s(%d), "
                      "size_t = %zu)",
                      tname, value (array [0]), nelems);
        pva = new std::valarray<T>(array [0], nelems);
        break;
    }

    case ArrayCtor: {
        rw_asnprintf (&fname, &size,
                      "valarray<%s>::valarray(const %1$s* = {%s}, "
                      "size_t = %zu)",
                      tname, str, nelems);
        pva = new std::valarray<T>(array, nelems);
        break;
    }

    }

    std::valarray<T> *psave = 0;

    if (copy) {
        char *tmpbuf        = 0;
        std::size_t tmpsize = 0;

        rw_asnprintf (&tmpbuf, &tmpsize, "valarray<%s>::valarray(%s)",
                      tname, fname);

        std::free (fname);
        fname = tmpbuf;
        size  = tmpsize;

        // replace the stored object counter value
        nobjects = pcounter ? *pcounter : 0;

        // save the original and replace it with the new array
        psave = pva;

        // invoke the copy ctor
        pva = new std::valarray<T>(*pva);
    }
        
    // verify the size of the array
    rw_assert (pva->size () == nelems, 0, line,
               "line %d. %s.size() == %zu, got %zu",
               __LINE__, fname, nelems, pva->size ());

    if (pcounter) {
        // compute the number of objects of type T constructed
        // by the ctor (valid only for T=UserClass)
        nobjects = *pcounter - nobjects;
        
        rw_assert (nobjects == nelems, 0, line,
                   "line %d. %s constucted %zu objects, expected %zu",
                   __LINE__, fname, nobjects, nelems);
    }

    // verify the element values
    for (std::size_t i = 0; i != nelems; ++i) {
        if (!((*pva)[i] == array [i])) {
            rw_assert (i == nelems, 0, line,
                       "line %d. %s[%zu] == %s(%d), got %4$s(%d)",
                       __LINE__, fname, i, tname,
                       value (array [i]), value ((*pva)[i]));

            break;
        }
    }

    delete_array (array, nelems);

    // get the number of objects of type T before invoking the dtor
    nobjects = pcounter ? *pcounter : 0;

    delete pva;

    if (pcounter) {
        // compute the number of objects of type T destroyed by the dtor
        nobjects = nobjects - *pcounter;

        // verify that all objects constructed by the ctor have been
        // destroyed (i.e., none leaked)
        rw_assert (nobjects == nelems, 0, line,
                   "line %d. %s dtor destroyed %zu objects, expected %zu",
                   __LINE__, fname, nobjects, nelems);
    }

    delete psave;
    std::free (fname);
}