bool vogl_material_state::set_material_parameter(uint side, GLenum pname) const { VOGL_FUNC_TRACER const GLenum face = get_face(side); const vogl_state_data *pData = m_params[side].find(pname); if (!pData) { VOGL_ASSERT_ALWAYS; return false; } enum { cMaxElements = 4 }; if (pData->get_num_elements() > cMaxElements) { VOGL_ASSERT_ALWAYS; return false; } if ((pData->get_data_type() == cSTFloat) || (pData->get_data_type() == cSTDouble)) { float fvals[cMaxElements]; pData->get_float(fvals); if (pData->get_num_elements() == 1) GL_ENTRYPOINT(glMaterialf)(face, pname, fvals[0]); else GL_ENTRYPOINT(glMaterialfv)(face, pname, fvals); } else { int ivals[cMaxElements]; pData->get_int(ivals); if (pData->get_num_elements() == 1) GL_ENTRYPOINT(glMateriali)(face, pname, ivals[0]); else GL_ENTRYPOINT(glMaterialiv)(face, pname, ivals); } return !vogl_check_gl_error(); }
int test_new_face( btimer_t* timer, FT_Face face, void* user_data ) { FT_Face bench_face; FT_UNUSED( face ); FT_UNUSED( user_data ); TIMER_START( timer ); if ( !get_face( &bench_face ) ) FT_Done_Face( bench_face ); TIMER_STOP( timer ); return 1; }
face_set_ptr face_manager<T>::get_face_set(const font_set &fset) { std::vector<std::string> const& names = fset.get_face_names(); face_set_ptr face_set = std::make_shared<font_face_set>(); for (std::vector<std::string>::const_iterator name = names.begin(); name != names.end(); ++name) { face_ptr face = get_face(*name); if (face) { face_set->add(face); } #ifdef MAPNIK_LOG else { MAPNIK_LOG_DEBUG(font_engine_freetype) << "Failed to find face '" << *name << "' in font set '" << fset.get_name() << "'\n"; } #endif } return face_set; }
face_set_ptr face_manager::get_face_set(font_set const& fset) { std::vector<std::string> const& names = fset.get_face_names(); face_set_ptr face_set = std::make_unique<font_face_set>(); for (auto const& name : names) { face_ptr face = get_face(name); if (face) { face_set->add(face); } #ifdef MAPNIK_LOG else { MAPNIK_LOG_DEBUG(font_engine_freetype) << "Failed to find face '" << name << "' in font set '" << fset.get_name() << "'\n"; } #endif } return face_set; }
bool get_face (const EschPoint *pt, EschPoint *p1, EschPoint *p2, EschPoint *p3) const { return get_face (pt->x, pt->z, p1, p2, p3); }
int* Cube::get_down() { int face[8] = { 7, 4, 5, 6, // corners 8, 9, 10, 11 }; // edges return get_face(face); }
int* Cube::get_top() { int face[8] = { 0, 3, 2, 1, // corners 2, 1, 0, 3 }; // edges return get_face(face); }
int* Cube::get_left() { int face[8] = { 3, 0, 4, 7, // corners 3, 4, 11, 7 }; // edges return get_face(face); }
int* Cube::get_right() { int face[8] = { 1, 2, 6, 5, // corners 1, 6, 9, 5 }; // edges return get_face(face); }
int* Cube::get_back() { int face[8] = {2, 3, 7, 6, // corners 2, 7, 10, 6 }; // edges return get_face(face); }
int* Cube::get_front() { int face[8] = { 0, 1, 5, 4, // corners 0, 5, 8, 4 }; // edges return get_face(face); }
Mesh::Mesh(char *filename) { unsigned int tmp; unsigned int i,j; unsigned int *f; float *nf; float norm; float *v1, *v2, *v3; float v12[3]; float v13[3]; float *nv; float *n; FILE *file; int error; float c[3] = {0.0,0.0,0.0}; float r; setlocale(LC_ALL,"C"); if((file=fopen(filename,"r"))==NULL) { printf("Unable to read %s\n",filename); } // create mesh vertices = NULL; normals = NULL; colors = NULL; faces = NULL; error = fscanf(file,"OFF\n%d %d %d\n",&(nb_vertices),&(nb_faces),&tmp); if(error==EOF) { printf("Unable to read %s\n",filename); } vertices = (float *)malloc(3*nb_vertices*sizeof(float)); normals = (float *)malloc(3*nb_vertices*sizeof(float)); colors = (float *)malloc(3*nb_vertices*sizeof(float)); faces = (unsigned int *)malloc(3*nb_faces*sizeof(unsigned int)); // reading vertices j = 0; for(i=0;i<nb_vertices;++i) { error = fscanf(file,"%f %f %f\n",&(vertices[j]),&(vertices[j+1]),&(vertices[j+2])); if(error==EOF) { printf("Unable to read vertices of %s\n",filename); // mesh_delete(mesh); // return NULL; } j += 3; } // reading faces j = 0; for(i=0;i<nb_faces;++i) { error = fscanf(file,"%d %d %d %d\n",&tmp,&(faces[j]),&(faces[j+1]),&(faces[j+2])); if(error==EOF) { printf("Unable to read faces of %s\n",filename); // mesh_delete(mesh); // return NULL; } if(tmp!=3) { printf("Error : face %d is not a triangle (%d polygonal face!)\n",i/3,tmp); // mesh_delete(mesh); // return NULL; } j += 3; } fclose(file); // computing center for(i=0;i<nb_vertices*3;i+=3) { c[0] += vertices[i ]; c[1] += vertices[i+1]; c[2] += vertices[i+2]; } center[0] = c[0]/(float)nb_vertices; center[1] = c[1]/(float)nb_vertices; center[2] = c[2]/(float)nb_vertices; // computing radius radius = 0.0; for(i=0;i<nb_vertices*3;i+=3) { c[0] = vertices[i ]-center[0]; c[1] = vertices[i+1]-center[1]; c[2] = vertices[i+2]-center[2]; r = sqrt(c[0]*c[0]+c[1]*c[1]+c[2]*c[2]); radius = r>radius ? r : radius; } // computing normals per faces nf = (float *)malloc(3*nb_faces*sizeof(float)); for(i=0;i<nb_faces;++i) { f = get_face(i); // the three vertices of the current face v1 = get_vertex(f[0]); v2 = get_vertex(f[1]); v3 = get_vertex(f[2]); // the two vectors of the current face v12[0] = v2[0]-v1[0]; v12[1] = v2[1]-v1[1]; v12[2] = v2[2]-v1[2]; v13[0] = v3[0]-v1[0]; v13[1] = v3[1]-v1[1]; v13[2] = v3[2]-v1[2]; // cross product nf[3*i ] = v12[1]*v13[2] - v12[2]*v13[1]; nf[3*i+1] = v12[2]*v13[0] - v12[0]*v13[2]; nf[3*i+2] = v12[0]*v13[1] - v12[1]*v13[0]; // normalization norm = sqrt(nf[3*i]*nf[3*i]+nf[3*i+1]*nf[3*i+1]+nf[3*i+2]*nf[3*i+2]); nf[3*i ] /= norm; nf[3*i+1] /= norm; nf[3*i+2] /= norm; } // computing normals per vertex nv = (float *)malloc(nb_vertices*sizeof(float)); for(i=0;i<nb_vertices;++i) { // initialization normals[3*i ] = 0.0; normals[3*i+1] = 0.0; normals[3*i+2] = 0.0; nv[i] = 0.0; } for(i=0;i<nb_faces;++i) { // face normals average f = get_face(i); n = &(nf[3*i]); normals[3*f[0] ] += nf[3*i ]; normals[3*f[0]+1] += nf[3*i+1]; normals[3*f[0]+2] += nf[3*i+2]; nv[f[0]] ++; normals[3*f[1] ] += nf[3*i ]; normals[3*f[1]+1] += nf[3*i+1]; normals[3*f[1]+2] += nf[3*i+2]; nv[f[1]] ++; normals[3*f[2] ] += nf[3*i ]; normals[3*f[2]+1] += nf[3*i+1]; normals[3*f[2]+2] += nf[3*i+2]; nv[f[2]] ++; } for(i=0;i<nb_vertices;++i) { // normalization normals[3*i ] /= -nv[i]; normals[3*i+1] /= -nv[i]; normals[3*i+2] /= -nv[i]; } free(nf); free(nv); // computing colors as normals for(i=0;i<3*nb_vertices;++i) { colors[i] = (normals[i]+1.0)/2.0; } }
int main(int argc, char** argv) { FT_Face face; long max_bytes = CACHE_SIZE * 1024; char* test_string = NULL; int size = FACE_SIZE; int max_iter = 0; double max_time = BENCH_TIME; int compare_cached = 0; int i; while ( 1 ) { int opt; opt = getopt( argc, argv, "Cc:f:m:pr:s:t:b:" ); if ( opt == -1 ) break; switch ( opt ) { case 'C': compare_cached = 1; break; case 'c': max_iter = atoi( optarg ); break; case 'f': load_flags = strtol( optarg, NULL, 16 ); break; case 'm': max_bytes = atoi( optarg ); max_bytes *= 1024; break; case 'p': preload = 1; break; case 'r': render_mode = (FT_Render_Mode)atoi( optarg ); if ( render_mode >= FT_RENDER_MODE_MAX ) render_mode = FT_RENDER_MODE_NORMAL; break; case 's': size = atoi( optarg ); if ( size <= 0 ) size = 1; else if ( size > 500 ) size = 500; break; case 't': max_time = atof( optarg ); break; case 'b': test_string = optarg; break; default: usage(); break; } } argc -= optind; argv += optind; if ( argc != 1 ) usage(); if ( FT_Init_FreeType( &lib ) ) { fprintf( stderr, "could not initialize font library\n" ); return 1; } filename = *argv; if ( get_face( &face ) ) goto Exit; if ( FT_IS_SCALABLE( face ) ) { if ( FT_Set_Pixel_Sizes( face, size, size ) ) { fprintf( stderr, "failed to set pixel size to %d\n", size ); return 1; } } else size = face->available_sizes[0].width; FTC_Manager_New( lib, 0, 0, max_bytes, face_requester, face, &cache_man ); font_type.face_id = (FTC_FaceID) 1; font_type.width = (short) size; font_type.height = (short) size; font_type.flags = load_flags; for ( i = 0; i < N_FT_BENCH; i++ ) { btest_t test; FT_ULong flags; if ( !TEST( 'a' + i ) ) continue; test.title = NULL; test.bench = NULL; test.cache_first = 0; test.user_data = NULL; switch ( i ) { case FT_BENCH_LOAD_GLYPH: test.title = "Load"; test.bench = test_load; benchmark( face, &test, max_iter, max_time ); if ( compare_cached ) { test.cache_first = 1; test.title = "Load (image cached)"; test.bench = test_image_cache; benchmark( face, &test, max_iter, max_time ); test.title = "Load (sbit cached)"; test.bench = test_sbit_cache; benchmark( face, &test, max_iter, max_time ); } break; case FT_BENCH_LOAD_ADVANCES: test.user_data = &flags; test.title = "Load_Advances (Normal)"; test.bench = test_load_advances; flags = FT_LOAD_DEFAULT; benchmark( face, &test, max_iter, max_time ); test.title = "Load_Advances (Fast)"; test.bench = test_load_advances; flags = FT_LOAD_TARGET_LIGHT; benchmark( face, &test, max_iter, max_time ); break; case FT_BENCH_RENDER: test.title = "Render"; test.bench = test_render; benchmark( face, &test, max_iter, max_time ); break; case FT_BENCH_GET_GLYPH: test.title = "Get_Glyph"; test.bench = test_get_glyph; benchmark( face, &test, max_iter, max_time ); break; case FT_BENCH_GET_CBOX: test.title = "Get_CBox"; test.bench = test_get_cbox; benchmark( face, &test, max_iter, max_time ); break; case FT_BENCH_CMAP: { bcharset_t charset; get_charset( face, &charset ); if ( charset.code ) { test.user_data = (void*)&charset; test.title = "Get_Char_Index"; test.bench = test_get_char_index; benchmark( face, &test, max_iter, max_time ); if ( compare_cached ) { test.cache_first = 1; test.title = "Get_Char_Index (cached)"; test.bench = test_cmap_cache; benchmark( face, &test, max_iter, max_time ); } free( charset.code ); } } break; case FT_BENCH_CMAP_ITER: test.title = "Iterate CMap"; test.bench = test_cmap_iter; benchmark( face, &test, max_iter, max_time ); break; case FT_BENCH_NEW_FACE: test.title = "New_Face"; test.bench = test_new_face; benchmark( face, &test, max_iter, max_time ); break; case FT_BENCH_EMBOLDEN: test.title = "Embolden"; test.bench = test_embolden; benchmark( face, &test, max_iter, max_time ); break; } } Exit: /* The following is a bit subtle: When we call FTC_Manager_Done, this * normally destroys all FT_Face objects that the cache might have created * by calling the face requester. * * However, this little benchmark uses a tricky face requester that * doesn't create a new FT_Face through FT_New_Face but simply pass a * pointer to the one that was previously created. * * If the cache manager has been used before, the call to FTC_Manager_Done * discards our single FT_Face. * * In the case where no cache manager is in place, or if no test was run, * the call to FT_Done_FreeType releases any remaining FT_Face object * anyway. */ if ( cache_man ) FTC_Manager_Done( cache_man ); FT_Done_FreeType( lib ); return 0; }