diff --git a/examples/glEvalLimit/glEvalLimit.cpp b/examples/glEvalLimit/glEvalLimit.cpp index 181f1d17..b350f11f 100644 --- a/examples/glEvalLimit/glEvalLimit.cpp +++ b/examples/glEvalLimit/glEvalLimit.cpp @@ -131,9 +131,9 @@ std::vector g_orgPositions, int g_currentShape = 0, g_adaptive = 1, - g_level = 3, + g_level = 2, g_kernel = kCPU, - g_endCap = kEndCapBSplineBasis, + g_endCap = kEndCapGregoryBasis, g_infSharpPatch = 0, g_numElements = 3; @@ -1223,8 +1223,8 @@ keyboard(GLFWwindow *, int key, int /* scancode */, int event, int /* mods */) { //------------------------------------------------------------------------------ static void callbackError(OpenSubdiv::Far::ErrorType err, const char *message) { - printf("Error: %d\n", err); - printf("%s", message); + printf("OpenSubdiv Error: %d\n", err); + printf(" %s\n", message); } //------------------------------------------------------------------------------ @@ -1382,10 +1382,10 @@ initHUD() { int endcap_pulldown = g_hud.AddPullDown("End cap (E)", 10, 150, 200, callbackEndCap, 'e'); - g_hud.AddPullDownButton(endcap_pulldown, "BSpline", + g_hud.AddPullDownButton(endcap_pulldown, "Regular", kEndCapBSplineBasis, g_endCap == kEndCapBSplineBasis); - g_hud.AddPullDownButton(endcap_pulldown, "GregoryBasis", + g_hud.AddPullDownButton(endcap_pulldown, "Gregory", kEndCapGregoryBasis, g_endCap == kEndCapGregoryBasis); @@ -1442,36 +1442,39 @@ int main(int argc, char **argv) { bool fullscreen = false; Scheme defaultScheme = kCatmark; - std::string str; + std::vector objfiles; for (int i = 1; i < argc; ++i) { - if (!strcmp(argv[i], "-u")) { + if (strstr(argv[i], ".obj")) { + objfiles.push_back(argv[i]); + } else if (!strcmp(argv[i], "-a")) { + g_adaptive = true; + } else if (!strcmp(argv[i], "-u")) { g_adaptive = false; - } - else if (!strcmp(argv[i], "-d")) { + } else if (!strcmp(argv[i], "-l")) { if (++i < argc) g_level = atoi(argv[i]); - } - else if (!strcmp(argv[i], "-f")) { + } else if (!strcmp(argv[i], "-f")) { fullscreen = true; - } - else if (!strcmp(argv[i], "-bilinear")) { + } else if (!strcmp(argv[i], "-bilinear")) { defaultScheme = kBilinear; - } - else if (!strcmp(argv[i], "-catmark")) { + } else if (!strcmp(argv[i], "-catmark")) { defaultScheme = kCatmark; - } - else if (!strcmp(argv[i], "-loop")) { + } else if (!strcmp(argv[i], "-loop")) { defaultScheme = kLoop; + } else { + printf("Warning: unrecognized argument '%s' ignored\n", argv[i]); } - else { - std::ifstream ifs(argv[i]); - if (ifs) { - std::stringstream ss; - ss << ifs.rdbuf(); - ifs.close(); - str = ss.str(); - g_defaultShapes.push_back(ShapeDesc(argv[i], str.c_str(), defaultScheme)); - } + } + for (int i = 0; i < (int)objfiles.size(); ++i) { + std::ifstream ifs(objfiles[i]); + if (ifs) { + std::stringstream ss; + ss << ifs.rdbuf(); + ifs.close(); + std::string str = ss.str(); + g_defaultShapes.push_back(ShapeDesc(objfiles[i], str.c_str(), defaultScheme)); + } else { + printf("Warning: cannot open shape file '%s'\n", objfiles[i]); } } diff --git a/examples/glEvalLimit/init_shapes.h b/examples/glEvalLimit/init_shapes.h index d21e7077..78d33a70 100644 --- a/examples/glEvalLimit/init_shapes.h +++ b/examples/glEvalLimit/init_shapes.h @@ -40,6 +40,7 @@ static std::vector g_defaultShapes; //------------------------------------------------------------------------------ static void initShapes() { + g_defaultShapes.push_back( ShapeDesc("catmark_cube", catmark_cube, kCatmark ) ); g_defaultShapes.push_back( ShapeDesc("catmark_cube_corner0", catmark_cube_corner0, kCatmark ) ); g_defaultShapes.push_back( ShapeDesc("catmark_cube_corner1", catmark_cube_corner1, kCatmark ) ); g_defaultShapes.push_back( ShapeDesc("catmark_cube_corner2", catmark_cube_corner2, kCatmark ) ); @@ -48,22 +49,14 @@ static void initShapes() { g_defaultShapes.push_back( ShapeDesc("catmark_cube_creases0", catmark_cube_creases0, kCatmark ) ); g_defaultShapes.push_back( ShapeDesc("catmark_cube_creases1", catmark_cube_creases1, kCatmark ) ); g_defaultShapes.push_back( ShapeDesc("catmark_cube_creases2", catmark_cube_creases2, kCatmark ) ); - g_defaultShapes.push_back( ShapeDesc("catmark_cube", catmark_cube, kCatmark ) ); g_defaultShapes.push_back( ShapeDesc("catmark_dart_edgecorner", catmark_dart_edgecorner, kCatmark ) ); g_defaultShapes.push_back( ShapeDesc("catmark_dart_edgeonly", catmark_dart_edgeonly, kCatmark ) ); g_defaultShapes.push_back( ShapeDesc("catmark_edgecorner", catmark_edgecorner, kCatmark ) ); g_defaultShapes.push_back( ShapeDesc("catmark_edgeonly", catmark_edgeonly, kCatmark ) ); - g_defaultShapes.push_back( ShapeDesc("catmark_chaikin0", catmark_chaikin0, kCatmark ) ); - g_defaultShapes.push_back( ShapeDesc("catmark_chaikin1", catmark_chaikin1, kCatmark ) ); - g_defaultShapes.push_back( ShapeDesc("catmark_chaikin2", catmark_chaikin2, kCatmark ) ); + g_defaultShapes.push_back( ShapeDesc("catmark_quadstrips", catmark_quadstrips, kCatmark ) ); g_defaultShapes.push_back( ShapeDesc("catmark_single_crease", catmark_single_crease, kCatmark ) ); g_defaultShapes.push_back( ShapeDesc("catmark_inf_crease0", catmark_inf_crease0, kCatmark ) ); g_defaultShapes.push_back( ShapeDesc("catmark_fan", catmark_fan, kCatmark ) ); - g_defaultShapes.push_back( ShapeDesc("catmark_flap", catmark_flap, kCatmark ) ); - g_defaultShapes.push_back( ShapeDesc("catmark_flap2", catmark_flap2, kCatmark ) ); - g_defaultShapes.push_back( ShapeDesc("catmark_fvar_bound0", catmark_fvar_bound0, kCatmark ) ); - g_defaultShapes.push_back( ShapeDesc("catmark_fvar_bound1", catmark_fvar_bound1, kCatmark ) ); - g_defaultShapes.push_back( ShapeDesc("catmark_fvar_bound2", catmark_fvar_bound2, kCatmark ) ); g_defaultShapes.push_back( ShapeDesc("catmark_gregory_test1", catmark_gregory_test1, kCatmark ) ); g_defaultShapes.push_back( ShapeDesc("catmark_gregory_test2", catmark_gregory_test2, kCatmark ) ); g_defaultShapes.push_back( ShapeDesc("catmark_gregory_test3", catmark_gregory_test3, kCatmark ) ); @@ -81,16 +74,29 @@ static void initShapes() { g_defaultShapes.push_back( ShapeDesc("catmark_tent", catmark_tent, kCatmark ) ); g_defaultShapes.push_back( ShapeDesc("catmark_torus", catmark_torus, kCatmark ) ); g_defaultShapes.push_back( ShapeDesc("catmark_torus_creases0", catmark_torus_creases0, kCatmark ) ); -// g_defaultShapes.push_back( ShapeDesc("catmark_square_hedit0", catmark_square_hedit0, kCatmark ) ); -// g_defaultShapes.push_back( ShapeDesc("catmark_square_hedit1", catmark_square_hedit1, kCatmark ) ); -// g_defaultShapes.push_back( ShapeDesc("catmark_square_hedit2", catmark_square_hedit2, kCatmark ) ); -// g_defaultShapes.push_back( ShapeDesc("catmark_square_hedit3", catmark_square_hedit3, kCatmark ) ); g_defaultShapes.push_back( ShapeDesc("catmark_bishop", catmark_bishop, kCatmark ) ); g_defaultShapes.push_back( ShapeDesc("catmark_car", catmark_car, kCatmark ) ); g_defaultShapes.push_back( ShapeDesc("catmark_helmet", catmark_helmet, kCatmark ) ); g_defaultShapes.push_back( ShapeDesc("catmark_pawn", catmark_pawn, kCatmark ) ); g_defaultShapes.push_back( ShapeDesc("catmark_rook", catmark_rook, kCatmark ) ); - g_defaultShapes.push_back( ShapeDesc("bilinear_cube", bilinear_cube, kBilinear) ); + g_defaultShapes.push_back( ShapeDesc("loop_cube", loop_cube, kLoop ) ); + g_defaultShapes.push_back( ShapeDesc("loop_cubes_semisharp", loop_cubes_semisharp, kLoop ) ); + g_defaultShapes.push_back( ShapeDesc("loop_cubes_infsharp", loop_cubes_infsharp, kLoop ) ); + g_defaultShapes.push_back( ShapeDesc("loop_cube_asymmetric", loop_cube_asymmetric, kLoop ) ); + g_defaultShapes.push_back( ShapeDesc("loop_triangle_edgecorner", loop_triangle_edgecorner, kLoop ) ); + g_defaultShapes.push_back( ShapeDesc("loop_triangle_edgeonly", loop_triangle_edgeonly, kLoop ) ); + g_defaultShapes.push_back( ShapeDesc("loop_xord_interior", loop_xord_interior, kLoop ) ); + g_defaultShapes.push_back( ShapeDesc("loop_xord_boundary", loop_xord_boundary, kLoop ) ); + g_defaultShapes.push_back( ShapeDesc("loop_icosahedron", loop_icosahedron, kLoop ) ); + g_defaultShapes.push_back( ShapeDesc("loop_icos_semisharp", loop_icos_semisharp, kLoop ) ); + g_defaultShapes.push_back( ShapeDesc("loop_icos_infsharp", loop_icos_infsharp, kLoop ) ); + g_defaultShapes.push_back( ShapeDesc("loop_pole8", loop_pole8, kLoop ) ); + g_defaultShapes.push_back( ShapeDesc("loop_pole64", loop_pole64, kLoop ) ); + + g_defaultShapes.push_back( ShapeDesc("bilinear_cube", bilinear_cube, kBilinear ) ); + g_defaultShapes.push_back( ShapeDesc("bilinear_nonplanar", bilinear_nonplanar, kBilinear ) ); + g_defaultShapes.push_back( ShapeDesc("bilinear_nonquads0", bilinear_nonquads0, kBilinear ) ); + g_defaultShapes.push_back( ShapeDesc("bilinear_nonquads1", bilinear_nonquads1, kBilinear ) ); } //------------------------------------------------------------------------------ diff --git a/examples/glFVarViewer/glFVarViewer.cpp b/examples/glFVarViewer/glFVarViewer.cpp index c8f979f8..b5b03621 100644 --- a/examples/glFVarViewer/glFVarViewer.cpp +++ b/examples/glFVarViewer/glFVarViewer.cpp @@ -79,7 +79,7 @@ OpenSubdiv::Sdc::Options::FVarLinearInterpolation g_fvarBoundary = int g_fullscreen = 0, g_freeze = 0, g_displayStyle = kWireShaded, - g_adaptive = 0, + g_adaptive = 1, g_mbutton[3] = {0, 0, 0}, g_mouseUvView = 0, g_running = 1; @@ -1140,7 +1140,7 @@ initHUD() { g_hud.AddPullDownButton(endcap_pulldown, "Regular", kEndCapBSplineBasis, g_endCap == kEndCapBSplineBasis); - g_hud.AddPullDownButton(endcap_pulldown, "GregoryBasis", + g_hud.AddPullDownButton(endcap_pulldown, "Gregory", kEndCapGregoryBasis, g_endCap == kEndCapGregoryBasis); @@ -1206,8 +1206,8 @@ idle() { //------------------------------------------------------------------------------ static void callbackError(OpenSubdiv::Far::ErrorType err, const char *message) { - printf("Error: %d\n", err); - printf("%s", message); + printf("OpenSubdiv Error: %d\n", err); + printf(" %s\n", message); } //------------------------------------------------------------------------------ @@ -1233,10 +1233,16 @@ int main(int argc, char ** argv) { bool fullscreen = false; Scheme defaultScheme = kCatmark; - std::string str; + std::vector objfiles; for (int i = 1; i < argc; ++i) { - if (!strcmp(argv[i], "-d")) { + if (strstr(argv[i], ".obj")) { + objfiles.push_back(argv[i]); + } else if (!strcmp(argv[i], "-a")) { + g_adaptive = true; + } else if (!strcmp(argv[i], "-u")) { + g_adaptive = false; + } else if (!strcmp(argv[i], "-l")) { if (++i < argc) g_level = parseIntArg(argv[i], g_level); } else if (!strcmp(argv[i], "-c")) { if (++i < argc) g_repeatCount = parseIntArg(argv[i], g_repeatCount); @@ -1248,19 +1254,20 @@ int main(int argc, char ** argv) { defaultScheme = kCatmark; } else if (!strcmp(argv[i], "-loop")) { defaultScheme = kLoop; - } else if (argv[i][0] == '-') { - printf("Warning: unrecognized option '%s' ignored\n", argv[i]); } else { - std::ifstream ifs(argv[i]); - if (ifs) { - std::stringstream ss; - ss << ifs.rdbuf(); - ifs.close(); - str = ss.str(); - g_defaultShapes.push_back(ShapeDesc(argv[i], str.c_str(), defaultScheme)); - } else { - printf("Warning: cannot open shape file '%s'\n", argv[i]); - } + printf("Warning: unrecognized argument '%s' ignored\n", argv[i]); + } + } + for (int i = 0; i < (int)objfiles.size(); ++i) { + std::ifstream ifs(objfiles[i]); + if (ifs) { + std::stringstream ss; + ss << ifs.rdbuf(); + ifs.close(); + std::string str = ss.str(); + g_defaultShapes.push_back(ShapeDesc(objfiles[i], str.c_str(), defaultScheme)); + } else { + printf("Warning: cannot open shape file '%s'\n", objfiles[i]); } } diff --git a/examples/glFVarViewer/init_shapes.h b/examples/glFVarViewer/init_shapes.h index 99679e92..16998312 100644 --- a/examples/glFVarViewer/init_shapes.h +++ b/examples/glFVarViewer/init_shapes.h @@ -44,6 +44,7 @@ static void initShapes() { // Note that any shapes added here must have UVs -- loading a shape without UVs is a fatal // error and will result in termination when it is selected. // + g_defaultShapes.push_back( ShapeDesc("catmark_cube", catmark_cube, kCatmark ) ); g_defaultShapes.push_back( ShapeDesc("catmark_cube_corner0", catmark_cube_corner0, kCatmark ) ); g_defaultShapes.push_back( ShapeDesc("catmark_cube_corner1", catmark_cube_corner1, kCatmark ) ); g_defaultShapes.push_back( ShapeDesc("catmark_cube_corner2", catmark_cube_corner2, kCatmark ) ); @@ -51,16 +52,12 @@ static void initShapes() { g_defaultShapes.push_back( ShapeDesc("catmark_cube_corner4", catmark_cube_corner4, kCatmark ) ); g_defaultShapes.push_back( ShapeDesc("catmark_cube_creases0", catmark_cube_creases0, kCatmark ) ); g_defaultShapes.push_back( ShapeDesc("catmark_cube_creases1", catmark_cube_creases1, kCatmark ) ); - g_defaultShapes.push_back( ShapeDesc("catmark_cube", catmark_cube, kCatmark ) ); g_defaultShapes.push_back( ShapeDesc("catmark_dart_edgecorner", catmark_dart_edgecorner, kCatmark ) ); g_defaultShapes.push_back( ShapeDesc("catmark_dart_edgeonly", catmark_dart_edgeonly, kCatmark ) ); g_defaultShapes.push_back( ShapeDesc("catmark_edgecorner", catmark_edgecorner, kCatmark ) ); g_defaultShapes.push_back( ShapeDesc("catmark_edgeonly", catmark_edgeonly, kCatmark ) ); - g_defaultShapes.push_back( ShapeDesc("catmark_chaikin0", catmark_chaikin0, kCatmark ) ); - g_defaultShapes.push_back( ShapeDesc("catmark_chaikin1", catmark_chaikin1, kCatmark ) ); + g_defaultShapes.push_back( ShapeDesc("catmark_quadstrips", catmark_quadstrips, kCatmark ) ); g_defaultShapes.push_back( ShapeDesc("catmark_fan", catmark_fan, kCatmark ) ); - g_defaultShapes.push_back( ShapeDesc("catmark_flap", catmark_flap, kCatmark ) ); - g_defaultShapes.push_back( ShapeDesc("catmark_flap2", catmark_flap2, kCatmark ) ); g_defaultShapes.push_back( ShapeDesc("catmark_fvar_bound0", catmark_fvar_bound0, kCatmark ) ); g_defaultShapes.push_back( ShapeDesc("catmark_fvar_bound1", catmark_fvar_bound1, kCatmark ) ); g_defaultShapes.push_back( ShapeDesc("catmark_fvar_bound2", catmark_fvar_bound2, kCatmark ) ); @@ -84,27 +81,26 @@ static void initShapes() { g_defaultShapes.push_back( ShapeDesc("catmark_tent", catmark_tent, kCatmark ) ); g_defaultShapes.push_back( ShapeDesc("catmark_torus", catmark_torus, kCatmark ) ); g_defaultShapes.push_back( ShapeDesc("catmark_torus_creases0", catmark_torus_creases0, kCatmark ) ); -// g_defaultShapes.push_back( ShapeDesc("catmark_square_hedit0", catmark_square_hedit0, kCatmark ) ); -// g_defaultShapes.push_back( ShapeDesc("catmark_square_hedit1", catmark_square_hedit1, kCatmark ) ); -// g_defaultShapes.push_back( ShapeDesc("catmark_square_hedit2", catmark_square_hedit2, kCatmark ) ); -// g_defaultShapes.push_back( ShapeDesc("catmark_square_hedit3", catmark_square_hedit3, kCatmark ) ); - g_defaultShapes.push_back( ShapeDesc("catmark_bishop", catmark_bishop, kCatmark ) ); - g_defaultShapes.push_back( ShapeDesc("catmark_car", catmark_car, kCatmark ) ); - g_defaultShapes.push_back( ShapeDesc("catmark_helmet", catmark_helmet, kCatmark ) ); - g_defaultShapes.push_back( ShapeDesc("catmark_pawn", catmark_pawn, kCatmark ) ); - g_defaultShapes.push_back( ShapeDesc("catmark_rook", catmark_rook, kCatmark ) ); - g_defaultShapes.push_back( ShapeDesc("bilinear_cube", bilinear_cube, kBilinear ) ); - - g_defaultShapes.push_back( ShapeDesc("loop_cube_creases0", loop_cube_creases0, kLoop ) ); - g_defaultShapes.push_back( ShapeDesc("loop_cube_creases1", loop_cube_creases1, kLoop ) ); g_defaultShapes.push_back( ShapeDesc("loop_cube", loop_cube, kLoop ) ); - g_defaultShapes.push_back( ShapeDesc("loop_icosahedron", loop_icosahedron, kLoop ) ); - g_defaultShapes.push_back( ShapeDesc("loop_saddle_edgecorner", loop_saddle_edgecorner, kLoop ) ); - g_defaultShapes.push_back( ShapeDesc("loop_saddle_edgeonly", loop_saddle_edgeonly, kLoop ) ); + g_defaultShapes.push_back( ShapeDesc("loop_cubes_semisharp", loop_cubes_semisharp, kLoop ) ); + g_defaultShapes.push_back( ShapeDesc("loop_cubes_infsharp", loop_cubes_infsharp, kLoop ) ); + g_defaultShapes.push_back( ShapeDesc("loop_cube_asymmetric", loop_cube_asymmetric, kLoop ) ); g_defaultShapes.push_back( ShapeDesc("loop_triangle_edgecorner", loop_triangle_edgecorner, kLoop ) ); g_defaultShapes.push_back( ShapeDesc("loop_triangle_edgeonly", loop_triangle_edgeonly, kLoop ) ); - g_defaultShapes.push_back( ShapeDesc("loop_chaikin0", loop_chaikin0, kLoop ) ); - g_defaultShapes.push_back( ShapeDesc("loop_chaikin1", loop_chaikin1, kLoop ) ); + g_defaultShapes.push_back( ShapeDesc("loop_xord_interior", loop_xord_interior, kLoop ) ); + g_defaultShapes.push_back( ShapeDesc("loop_xord_boundary", loop_xord_boundary, kLoop ) ); + g_defaultShapes.push_back( ShapeDesc("loop_fvar_bound0", loop_fvar_bound0, kLoop ) ); + g_defaultShapes.push_back( ShapeDesc("loop_fvar_bound1", loop_fvar_bound1, kLoop ) ); + g_defaultShapes.push_back( ShapeDesc("loop_fvar_bound2", loop_fvar_bound2, kLoop ) ); + g_defaultShapes.push_back( ShapeDesc("loop_fvar_bound3", loop_fvar_bound3, kLoop ) ); + g_defaultShapes.push_back( ShapeDesc("loop_icosahedron", loop_icosahedron, kLoop ) ); + g_defaultShapes.push_back( ShapeDesc("loop_icos_semisharp", loop_icos_semisharp, kLoop ) ); + g_defaultShapes.push_back( ShapeDesc("loop_icos_infsharp", loop_icos_infsharp, kLoop ) ); + + g_defaultShapes.push_back( ShapeDesc("bilinear_cube", bilinear_cube, kBilinear ) ); + g_defaultShapes.push_back( ShapeDesc("bilinear_nonplanar", bilinear_nonplanar, kBilinear ) ); + g_defaultShapes.push_back( ShapeDesc("bilinear_nonquads0", bilinear_nonquads0, kBilinear ) ); + g_defaultShapes.push_back( ShapeDesc("bilinear_nonquads1", bilinear_nonquads1, kBilinear ) ); } //------------------------------------------------------------------------------ diff --git a/examples/glImaging/glImaging.cpp b/examples/glImaging/glImaging.cpp index 48711ab7..7f36cef4 100644 --- a/examples/glImaging/glImaging.cpp +++ b/examples/glImaging/glImaging.cpp @@ -104,6 +104,24 @@ public: ss << "#define PRIM_TRI\n"; } + // need for patch color-coding : we need these defines in the fragment shader + if (type == Far::PatchDescriptor::GREGORY) { + ss << "#define OSD_PATCH_GREGORY\n"; + } else if (type == Far::PatchDescriptor::GREGORY_BOUNDARY) { + ss << "#define OSD_PATCH_GREGORY_BOUNDARY\n"; + } else if (type == Far::PatchDescriptor::GREGORY_BASIS) { + ss << "#define OSD_PATCH_GREGORY_BASIS\n"; + } else if (type == Far::PatchDescriptor::LOOP) { + ss << "#define OSD_PATCH_LOOP\n"; + } else if (type == Far::PatchDescriptor::GREGORY_TRIANGLE) { + ss << "#define OSD_PATCH_GREGORY_TRIANGLE\n"; + } + if (type == Far::PatchDescriptor::TRIANGLES || + type == Far::PatchDescriptor::LOOP || + type == Far::PatchDescriptor::GREGORY_TRIANGLE) { + ss << "#define LOOP\n"; + } + if (desc.IsAdaptive()) { ss << "#define SMOOTH_NORMALS\n"; } @@ -295,13 +313,11 @@ void runTest(ShapeDesc const &shapeDesc, std::string const &kernel, *shape, Far::TopologyRefinerFactory::Options(sdctype, sdcoptions)); - // Adaptive refinement currently supported only for catmull-clark scheme - bool doAdaptive = adaptive && (shapeDesc.scheme == kCatmark); bool interleaveVarying = true; bool doSingleCreasePatch = true; Osd::MeshBitset bits; - bits.set(Osd::MeshAdaptive, doAdaptive); + bits.set(Osd::MeshAdaptive, adaptive); bits.set(Osd::MeshUseSingleCreasePatch, doSingleCreasePatch); bits.set(Osd::MeshInterleaveVarying, interleaveVarying); bits.set(Osd::MeshFVarData, false); @@ -445,7 +461,8 @@ void runTest(ShapeDesc const &shapeDesc, std::string const &kernel, static void usage(const char *program) { std::cout << "Usage %s : " << program << "\n" - << " -a : adaptive refinement\n" + << " -a : adaptive refinement (default)\n" + << " -u : uniform refinement\n" << " -l : isolation level (default = 2)\n" << " -t : tessellation level (default = 1)\n" << " -w : write images to PNG as\n" @@ -464,7 +481,7 @@ int main(int argc, char ** argv) { int tessLevel = 1; int isolationLevel = 2; bool writeToFile = false; - bool adaptive = false; + bool adaptive = true; std::string prefix; std::string displayMode = "PATCH_TYPE"; std::vector kernels; @@ -472,6 +489,8 @@ int main(int argc, char ** argv) { for (int i = 1; i < argc; ++i) { if (!strcmp(argv[i], "-a")) { adaptive = true; + } else if (!strcmp(argv[i], "-u")) { + adaptive = false; } else if (!strcmp(argv[i], "-l")) { isolationLevel = atoi(argv[++i]); } else if (!strcmp(argv[i], "-k")) { diff --git a/examples/glImaging/init_shapes.h b/examples/glImaging/init_shapes.h index 3a434d05..c502d859 100644 --- a/examples/glImaging/init_shapes.h +++ b/examples/glImaging/init_shapes.h @@ -40,6 +40,7 @@ static std::vector g_shapes; //------------------------------------------------------------------------------ static void initShapes() { + g_shapes.push_back( ShapeDesc("catmark_cube", catmark_cube, kCatmark ) ); g_shapes.push_back( ShapeDesc("catmark_cube_corner0", catmark_cube_corner0, kCatmark ) ); g_shapes.push_back( ShapeDesc("catmark_cube_corner1", catmark_cube_corner1, kCatmark ) ); g_shapes.push_back( ShapeDesc("catmark_cube_corner2", catmark_cube_corner2, kCatmark ) ); @@ -48,17 +49,15 @@ static void initShapes() { g_shapes.push_back( ShapeDesc("catmark_cube_creases0", catmark_cube_creases0, kCatmark ) ); g_shapes.push_back( ShapeDesc("catmark_cube_creases1", catmark_cube_creases1, kCatmark ) ); g_shapes.push_back( ShapeDesc("catmark_cube_creases2", catmark_cube_creases2, kCatmark ) ); - g_shapes.push_back( ShapeDesc("catmark_cube", catmark_cube, kCatmark ) ); g_shapes.push_back( ShapeDesc("catmark_dart_edgecorner", catmark_dart_edgecorner, kCatmark ) ); g_shapes.push_back( ShapeDesc("catmark_dart_edgeonly", catmark_dart_edgeonly, kCatmark ) ); g_shapes.push_back( ShapeDesc("catmark_edgecorner", catmark_edgecorner, kCatmark ) ); g_shapes.push_back( ShapeDesc("catmark_edgeonly", catmark_edgeonly, kCatmark ) ); + g_shapes.push_back( ShapeDesc("catmark_quadstrips", catmark_quadstrips, kCatmark ) ); g_shapes.push_back( ShapeDesc("catmark_chaikin0", catmark_chaikin0, kCatmark ) ); g_shapes.push_back( ShapeDesc("catmark_chaikin1", catmark_chaikin1, kCatmark ) ); g_shapes.push_back( ShapeDesc("catmark_chaikin2", catmark_chaikin2, kCatmark ) ); g_shapes.push_back( ShapeDesc("catmark_fan", catmark_fan, kCatmark ) ); - g_shapes.push_back( ShapeDesc("catmark_flap", catmark_flap, kCatmark ) ); - g_shapes.push_back( ShapeDesc("catmark_flap2", catmark_flap2, kCatmark ) ); g_shapes.push_back( ShapeDesc("catmark_fvar_bound0", catmark_fvar_bound0, kCatmark ) ); g_shapes.push_back( ShapeDesc("catmark_fvar_bound1", catmark_fvar_bound1, kCatmark ) ); g_shapes.push_back( ShapeDesc("catmark_fvar_bound2", catmark_fvar_bound2, kCatmark ) ); @@ -90,17 +89,29 @@ static void initShapes() { g_shapes.push_back( ShapeDesc("catmark_pawn", catmark_pawn, kCatmark ) ); g_shapes.push_back( ShapeDesc("catmark_rook", catmark_rook, kCatmark ) ); - g_shapes.push_back( ShapeDesc("bilinear_cube", bilinear_cube, kBilinear ) ); - - g_shapes.push_back( ShapeDesc("loop_cube_creases0", loop_cube_creases0, kLoop ) ); - g_shapes.push_back( ShapeDesc("loop_cube_creases1", loop_cube_creases1, kLoop ) ); g_shapes.push_back( ShapeDesc("loop_cube", loop_cube, kLoop ) ); - g_shapes.push_back( ShapeDesc("loop_icosahedron", loop_icosahedron, kLoop ) ); - g_shapes.push_back( ShapeDesc("loop_saddle_edgecorner", loop_saddle_edgecorner, kLoop ) ); - g_shapes.push_back( ShapeDesc("loop_saddle_edgeonly", loop_saddle_edgeonly, kLoop ) ); + g_shapes.push_back( ShapeDesc("loop_cubes_semisharp", loop_cubes_semisharp, kLoop ) ); + g_shapes.push_back( ShapeDesc("loop_cubes_infsharp", loop_cubes_infsharp, kLoop ) ); + g_shapes.push_back( ShapeDesc("loop_cube_asymmetric", loop_cube_asymmetric, kLoop ) ); g_shapes.push_back( ShapeDesc("loop_triangle_edgecorner", loop_triangle_edgecorner, kLoop ) ); g_shapes.push_back( ShapeDesc("loop_triangle_edgeonly", loop_triangle_edgeonly, kLoop ) ); + g_shapes.push_back( ShapeDesc("loop_xord_interior", loop_xord_interior, kLoop ) ); + g_shapes.push_back( ShapeDesc("loop_xord_boundary", loop_xord_boundary, kLoop ) ); + g_shapes.push_back( ShapeDesc("loop_icosahedron", loop_icosahedron, kLoop ) ); + g_shapes.push_back( ShapeDesc("loop_icos_semisharp", loop_icos_semisharp, kLoop ) ); + g_shapes.push_back( ShapeDesc("loop_icos_infsharp", loop_icos_infsharp, kLoop ) ); + g_shapes.push_back( ShapeDesc("loop_fvar_bound0", loop_fvar_bound0, kLoop ) ); + g_shapes.push_back( ShapeDesc("loop_fvar_bound1", loop_fvar_bound1, kLoop ) ); + g_shapes.push_back( ShapeDesc("loop_fvar_bound2", loop_fvar_bound2, kLoop ) ); + g_shapes.push_back( ShapeDesc("loop_fvar_bound3", loop_fvar_bound3, kLoop ) ); g_shapes.push_back( ShapeDesc("loop_chaikin0", loop_chaikin0, kLoop ) ); g_shapes.push_back( ShapeDesc("loop_chaikin1", loop_chaikin1, kLoop ) ); + g_shapes.push_back( ShapeDesc("loop_pole8", loop_pole8, kLoop ) ); + g_shapes.push_back( ShapeDesc("loop_pole64", loop_pole64, kLoop ) ); + + g_shapes.push_back( ShapeDesc("bilinear_cube", bilinear_cube, kBilinear ) ); + g_shapes.push_back( ShapeDesc("bilinear_nonplanar", bilinear_nonplanar, kBilinear ) ); + g_shapes.push_back( ShapeDesc("bilinear_nonquads0", bilinear_nonquads0, kBilinear ) ); + g_shapes.push_back( ShapeDesc("bilinear_nonquads1", bilinear_nonquads1, kBilinear ) ); } //------------------------------------------------------------------------------ diff --git a/examples/glImaging/shader.glsl b/examples/glImaging/shader.glsl index 8ad8ec19..081bdf06 100644 --- a/examples/glImaging/shader.glsl +++ b/examples/glImaging/shader.glsl @@ -320,11 +320,11 @@ getAdaptivePatchColor(ivec3 patchParam) vec4(0.0f, 0.8f, 0.75f, 1.0f), // boundary pattern 4 vec4(0.0f, 1.0f, 0.0f, 1.0f), // corner - vec4(0.25f, 0.25f, 0.25f, 1.0f), // corner pattern 0 - vec4(0.25f, 0.25f, 0.25f, 1.0f), // corner pattern 1 - vec4(0.25f, 0.25f, 0.25f, 1.0f), // corner pattern 2 - vec4(0.25f, 0.25f, 0.25f, 1.0f), // corner pattern 3 - vec4(0.25f, 0.25f, 0.25f, 1.0f), // corner pattern 4 + vec4(0.5f, 1.0f, 0.5f, 1.0f), // corner pattern 0 + vec4(0.5f, 1.0f, 0.5f, 1.0f), // corner pattern 1 + vec4(0.5f, 1.0f, 0.5f, 1.0f), // corner pattern 2 + vec4(0.5f, 1.0f, 0.5f, 1.0f), // corner pattern 3 + vec4(0.5f, 1.0f, 0.5f, 1.0f), // corner pattern 4 vec4(1.0f, 1.0f, 0.0f, 1.0f), // gregory vec4(1.0f, 1.0f, 0.0f, 1.0f), // gregory @@ -354,11 +354,11 @@ getAdaptivePatchColor(ivec3 patchParam) if (edgeCount == 1) { patchType = 2; // BOUNDARY } - if (edgeCount == 2) { - patchType = 3; // CORNER + if (edgeCount > 1) { + patchType = 3; // CORNER (not correct for patches that are not isolated) } -#if defined OSD_PATCH_ENABLE_SINGLE_CREASE +#if defined(OSD_PATCH_ENABLE_SINGLE_CREASE) && !defined(LOOP) // check this after boundary/corner since single crease patch also has edgeCount. if (inpt.vSegments.y > 0) { patchType = 1; @@ -369,6 +369,8 @@ getAdaptivePatchColor(ivec3 patchParam) patchType = 5; #elif defined OSD_PATCH_GREGORY_BASIS patchType = 6; +#elif defined OSD_PATCH_GREGORY_TRIANGLE + patchType = 6; #endif int pattern = bitCount(OsdGetPatchTransitionMask(patchParam)); diff --git a/examples/glPaintTest/glPaintTest.cpp b/examples/glPaintTest/glPaintTest.cpp index e741ea39..9e3d4dd4 100644 --- a/examples/glPaintTest/glPaintTest.cpp +++ b/examples/glPaintTest/glPaintTest.cpp @@ -207,6 +207,9 @@ createOsdMesh() { OpenSubdiv::Sdc::SchemeType sdctype = GetSdcType(*shape); OpenSubdiv::Sdc::Options sdcoptions = GetSdcOptions(*shape); + // Recall this application should not accept or include Bilinear shapes + assert(sdctype != OpenSubdiv::Sdc::SCHEME_BILINEAR); + OpenSubdiv::Far::TopologyRefiner * refiner = OpenSubdiv::Far::TopologyRefinerFactory::Create(*shape, OpenSubdiv::Far::TopologyRefinerFactory::Options(sdctype, sdcoptions)); @@ -221,6 +224,7 @@ createOsdMesh() { bool doAdaptive = true; OpenSubdiv::Osd::MeshBitset bits; bits.set(OpenSubdiv::Osd::MeshAdaptive, doAdaptive); + bits.set(OpenSubdiv::Osd::MeshEndCapGregoryBasis, true); g_mesh = new OpenSubdiv::Osd::Mesh objfiles; + for (int i = 1; i < argc; ++i) { - if (!strcmp(argv[i], "-d")) + if (strstr(argv[i], ".obj")) { + objfiles.push_back(argv[i]); + } else if (!strcmp(argv[i], "-l")) { g_level = atoi(argv[++i]); - else if (!strcmp(argv[i], "-f")) + } else if (!strcmp(argv[i], "-f")) { fullscreen = true; - else { - std::ifstream ifs(argv[1]); - if (ifs) { - std::stringstream ss; - ss << ifs.rdbuf(); - ifs.close(); - str = ss.str(); - g_defaultShapes.push_back(ShapeDesc(argv[1], str.c_str(), kCatmark)); - } + } else if (!strcmp(argv[i], "-catmark")) { + defaultScheme = kCatmark; + } else if (!strcmp(argv[i], "-loop")) { + defaultScheme = kLoop; + } else if (!strcmp(argv[i], "-bilinear")) { + printf("Warning: -bilinear ignored, Bilinear shapes not supported\n"); + } else { + printf("Warning: unrecognized argument '%s' ignored\n", argv[i]); } } + for (int i = 0; i < (int)objfiles.size(); ++i) { + std::ifstream ifs(objfiles[i]); + if (ifs) { + std::stringstream ss; + ss << ifs.rdbuf(); + ifs.close(); + std::string str = ss.str(); + g_defaultShapes.push_back(ShapeDesc(objfiles[i], str.c_str(), defaultScheme)); + } else { + printf("Warning: cannot open shape file '%s'\n", objfiles[i]); + } + } + initShapes(); OpenSubdiv::Far::SetErrorCallback(callbackError); diff --git a/examples/glPaintTest/init_shapes.h b/examples/glPaintTest/init_shapes.h index 5b4e9127..e07a22b6 100644 --- a/examples/glPaintTest/init_shapes.h +++ b/examples/glPaintTest/init_shapes.h @@ -39,6 +39,7 @@ static std::vector g_defaultShapes; //------------------------------------------------------------------------------ static void initShapes() { + g_defaultShapes.push_back( ShapeDesc("catmark_cube", catmark_cube, kCatmark ) ); g_defaultShapes.push_back( ShapeDesc("catmark_cube_corner0", catmark_cube_corner0, kCatmark ) ); g_defaultShapes.push_back( ShapeDesc("catmark_cube_corner1", catmark_cube_corner1, kCatmark ) ); g_defaultShapes.push_back( ShapeDesc("catmark_cube_corner2", catmark_cube_corner2, kCatmark ) ); @@ -46,17 +47,12 @@ static void initShapes() { g_defaultShapes.push_back( ShapeDesc("catmark_cube_corner4", catmark_cube_corner4, kCatmark ) ); g_defaultShapes.push_back( ShapeDesc("catmark_cube_creases0", catmark_cube_creases0, kCatmark ) ); g_defaultShapes.push_back( ShapeDesc("catmark_cube_creases1", catmark_cube_creases1, kCatmark ) ); - g_defaultShapes.push_back( ShapeDesc("catmark_cube", catmark_cube, kCatmark ) ); g_defaultShapes.push_back( ShapeDesc("catmark_dart_edgecorner", catmark_dart_edgecorner, kCatmark ) ); g_defaultShapes.push_back( ShapeDesc("catmark_dart_edgeonly", catmark_dart_edgeonly, kCatmark ) ); g_defaultShapes.push_back( ShapeDesc("catmark_edgecorner", catmark_edgecorner, kCatmark ) ); g_defaultShapes.push_back( ShapeDesc("catmark_edgeonly", catmark_edgeonly, kCatmark ) ); - g_defaultShapes.push_back( ShapeDesc("catmark_chaikin0", catmark_chaikin0, kCatmark ) ); - g_defaultShapes.push_back( ShapeDesc("catmark_chaikin1", catmark_chaikin1, kCatmark ) ); - g_defaultShapes.push_back( ShapeDesc("catmark_chaikin2", catmark_chaikin2, kCatmark ) ); + g_defaultShapes.push_back( ShapeDesc("catmark_quadstrips", catmark_quadstrips, kCatmark ) ); g_defaultShapes.push_back( ShapeDesc("catmark_fan", catmark_fan, kCatmark ) ); - g_defaultShapes.push_back( ShapeDesc("catmark_flap", catmark_flap, kCatmark ) ); - g_defaultShapes.push_back( ShapeDesc("catmark_flap2", catmark_flap2, kCatmark ) ); g_defaultShapes.push_back( ShapeDesc("catmark_gregory_test1", catmark_gregory_test1, kCatmark ) ); g_defaultShapes.push_back( ShapeDesc("catmark_gregory_test2", catmark_gregory_test2, kCatmark ) ); g_defaultShapes.push_back( ShapeDesc("catmark_gregory_test3", catmark_gregory_test3, kCatmark ) ); @@ -76,5 +72,19 @@ static void initShapes() { g_defaultShapes.push_back( ShapeDesc("catmark_helmet", catmark_helmet, kCatmark ) ); g_defaultShapes.push_back( ShapeDesc("catmark_pawn", catmark_pawn, kCatmark ) ); g_defaultShapes.push_back( ShapeDesc("catmark_rook", catmark_rook, kCatmark ) ); + + g_defaultShapes.push_back( ShapeDesc("loop_cube", loop_cube, kLoop ) ); + g_defaultShapes.push_back( ShapeDesc("loop_cubes_semisharp", loop_cubes_semisharp, kLoop ) ); + g_defaultShapes.push_back( ShapeDesc("loop_cubes_infsharp", loop_cubes_infsharp, kLoop ) ); + g_defaultShapes.push_back( ShapeDesc("loop_cube_asymmetric", loop_cube_asymmetric, kLoop ) ); + g_defaultShapes.push_back( ShapeDesc("loop_triangle_edgecorner", loop_triangle_edgecorner, kLoop ) ); + g_defaultShapes.push_back( ShapeDesc("loop_triangle_edgeonly", loop_triangle_edgeonly, kLoop ) ); + g_defaultShapes.push_back( ShapeDesc("loop_xord_interior", loop_xord_interior, kLoop ) ); + g_defaultShapes.push_back( ShapeDesc("loop_xord_boundary", loop_xord_boundary, kLoop ) ); + g_defaultShapes.push_back( ShapeDesc("loop_icosahedron", loop_icosahedron, kLoop ) ); + g_defaultShapes.push_back( ShapeDesc("loop_icos_semisharp", loop_icos_semisharp, kLoop ) ); + g_defaultShapes.push_back( ShapeDesc("loop_icos_infsharp", loop_icos_infsharp, kLoop ) ); + + // REMEMBER: no Bilinear shapes here -- application requires a tessellation shader } //------------------------------------------------------------------------------ diff --git a/examples/glPtexViewer/glPtexViewer.cpp b/examples/glPtexViewer/glPtexViewer.cpp index 77139022..2223e686 100644 --- a/examples/glPtexViewer/glPtexViewer.cpp +++ b/examples/glPtexViewer/glPtexViewer.cpp @@ -180,7 +180,7 @@ int g_fullscreen = 0, g_wire = DISPLAY_SHADED, g_drawNormals = 0, g_mbutton[3] = {0, 0, 0}, - g_level = 1, + g_level = 2, g_tessLevel = 2, g_kernel = kCPU, g_scheme = 0, @@ -195,7 +195,7 @@ float g_moveScale = 0.0f, g_displacementScale = 1.0f, g_mipmapBias = 0.0; -bool g_adaptive = false, +bool g_adaptive = true, g_yup = false, g_patchCull = true, g_screenSpaceTess = true, @@ -441,6 +441,7 @@ createPTexGeo(PtexTexture * r) { Shape * shape = new Shape; shape->scheme = kCatmark; + assert(r->meshType() == Ptex::mt_quad); shape->verts.resize(nvp); for (int i=0; imeshType() == Ptex::mt_triangle) { + printf("Error in %s: triangular Ptex not yet supported\n", filename); + exit(1); + } size_t targetMemory = memLimit * 1024 * 1024; // MB @@ -872,6 +885,10 @@ createOsdMesh(int level, int kernel) { printf("Error in reading %s\n", g_ptexColorFilename); exit(1); } + if (ptexColor->meshType() == Ptex::mt_triangle) { + printf("Error in %s: triangular Ptex not yet supported\n", g_ptexColorFilename); + exit(1); + } // generate Shape representation from ptex Shape * shape = createPTexGeo(ptexColor); @@ -900,11 +917,8 @@ createOsdMesh(int level, int kernel) { delete g_mesh; g_mesh = NULL; - // Adaptive refinement currently supported only for catmull-clark scheme - bool doAdaptive = (g_adaptive != 0 && g_scheme == 0); - OpenSubdiv::Osd::MeshBitset bits; - bits.set(OpenSubdiv::Osd::MeshAdaptive, doAdaptive); + bits.set(OpenSubdiv::Osd::MeshAdaptive, g_adaptive); bits.set(OpenSubdiv::Osd::MeshEndCapGregoryBasis, true); int numVertexElements = g_adaptive ? 3 : 6; @@ -1423,7 +1437,7 @@ display() { g_hud.DrawString(10, -160, "Primitives : %d", numPrimsGenerated); } g_hud.DrawString(10, -140, "Vertices : %d", g_mesh->GetNumVertices()); - g_hud.DrawString(10, -120, "Scheme : %s", g_scheme == 0 ? "CATMARK" : "LOOP"); + g_hud.DrawString(10, -120, "Scheme : %s", g_scheme == 0 ? "CATMARK" : "BILINEAR"); g_hud.DrawString(10, -100, "GPU Kernel : %.3f ms", g_gpuTime); g_hud.DrawString(10, -80, "CPU Kernel : %.3f ms", g_cpuTime); g_hud.DrawString(10, -60, "GPU Draw : %.3f ms", drawGpuTime); @@ -1703,8 +1717,8 @@ void usage(const char *program) { //------------------------------------------------------------------------------ static void callbackError(OpenSubdiv::Far::ErrorType err, const char *message) { - printf("Error: %d\n", err); - printf("%s", message); + printf("OpenSubdiv Error: %d\n", err); + printf(" %s\n", message); } //------------------------------------------------------------------------------ @@ -1727,6 +1741,10 @@ int main(int argc, char ** argv) { for (int i = 1; i < argc; ++i) { if (strstr(argv[i], ".obj")) animobjs.push_back(argv[i]); + else if (!strcmp(argv[i], "-a")) + g_adaptive = true; + else if (!strcmp(argv[i], "-u")) + g_adaptive = false; else if (!strcmp(argv[i], "-l")) g_level = atoi(argv[++i]); else if (!strcmp(argv[i], "-c")) @@ -1847,7 +1865,7 @@ int main(int argc, char ** argv) { reshape(); // activate feature adaptive tessellation if OSD supports it - g_adaptive = GLUtils::SupportsAdaptiveTessellation(); + g_adaptive = g_adaptive && GLUtils::SupportsAdaptiveTessellation(); int windowWidth = g_width, windowHeight = g_height; diff --git a/examples/glPtexViewer/shader.glsl b/examples/glPtexViewer/shader.glsl index 486e676d..aa6e313d 100644 --- a/examples/glPtexViewer/shader.glsl +++ b/examples/glPtexViewer/shader.glsl @@ -437,11 +437,11 @@ GetOverrideColor(ivec3 patchParam) vec4(0.0f, 0.8f, 0.75f, 1.0f), // boundary pattern 4 vec4(0.0f, 1.0f, 0.0f, 1.0f), // corner - vec4(0.25f, 0.25f, 0.25f, 1.0f), // corner pattern 0 - vec4(0.25f, 0.25f, 0.25f, 1.0f), // corner pattern 1 - vec4(0.25f, 0.25f, 0.25f, 1.0f), // corner pattern 2 - vec4(0.25f, 0.25f, 0.25f, 1.0f), // corner pattern 3 - vec4(0.25f, 0.25f, 0.25f, 1.0f), // corner pattern 4 + vec4(0.5f, 1.0f, 0.5f, 1.0f), // corner pattern 0 + vec4(0.5f, 1.0f, 0.5f, 1.0f), // corner pattern 1 + vec4(0.5f, 1.0f, 0.5f, 1.0f), // corner pattern 2 + vec4(0.5f, 1.0f, 0.5f, 1.0f), // corner pattern 3 + vec4(0.5f, 1.0f, 0.5f, 1.0f), // corner pattern 4 vec4(1.0f, 1.0f, 0.0f, 1.0f), // gregory vec4(1.0f, 1.0f, 0.0f, 1.0f), // gregory @@ -466,8 +466,18 @@ GetOverrideColor(ivec3 patchParam) ); int patchType = 0; -#if defined OSD_PATCH_SINGLE_CREASE - if (inpt.sharpness > 0) { + + int edgeCount = bitCount(OsdGetPatchBoundaryMask(patchParam)); + if (edgeCount == 1) { + patchType = 2; // BOUNDARY + } + if (edgeCount > 1) { + patchType = 3; // CORNER (not correct for patches that are not isolated) + } + +#if defined(OSD_PATCH_ENABLE_SINGLE_CREASE) && !defined(LOOP) + // check this after boundary/corner since single crease patch also has edgeCount. + if (inpt.vSegments.y > 0) { patchType = 1; } #elif defined OSD_PATCH_GREGORY @@ -476,16 +486,10 @@ GetOverrideColor(ivec3 patchParam) patchType = 5; #elif defined OSD_PATCH_GREGORY_BASIS patchType = 6; +#elif defined OSD_PATCH_GREGORY_TRIANGLE + patchType = 6; #endif - int edgeCount = bitCount(OsdGetPatchBoundaryMask(patchParam)); - if (edgeCount == 1) { - patchType = 2; // BOUNDARY - } - if (edgeCount == 2) { - patchType = 3; // CORNER - } - int pattern = bitCount(OsdGetPatchTransitionMask(patchParam)); return patchColors[6*patchType + pattern]; diff --git a/examples/glShareTopology/glShareTopology.cpp b/examples/glShareTopology/glShareTopology.cpp index e3283600..77e2785c 100644 --- a/examples/glShareTopology/glShareTopology.cpp +++ b/examples/glShareTopology/glShareTopology.cpp @@ -146,7 +146,7 @@ float g_cpuTime = 0; float g_gpuTime = 0; Stopwatch g_fpsTimer; -int g_level = 1; +int g_level = 2; int g_tessLevel = 1; int g_tessLevelMin = 1; int g_frame = 0; @@ -372,6 +372,15 @@ public: ss << "#define OSD_PATCH_GREGORY_BOUNDARY\n"; } else if (type == Far::PatchDescriptor::GREGORY_BASIS) { ss << "#define OSD_PATCH_GREGORY_BASIS\n"; + } else if (type == Far::PatchDescriptor::LOOP) { + ss << "#define OSD_PATCH_LOOP\n"; + } else if (type == Far::PatchDescriptor::GREGORY_TRIANGLE) { + ss << "#define OSD_PATCH_GREGORY_TRIANGLE\n"; + } + if (type == Far::PatchDescriptor::TRIANGLES || + type == Far::PatchDescriptor::LOOP || + type == Far::PatchDescriptor::GREGORY_TRIANGLE) { + ss << "#define LOOP\n"; } // for legacy gregory @@ -1107,10 +1116,10 @@ initHUD() { int endcap_pulldown = g_hud.AddPullDown( "End cap (E)", 10, 210, 200, callbackEndCap, 'e'); - g_hud.AddPullDownButton(endcap_pulldown, "BSpline", + g_hud.AddPullDownButton(endcap_pulldown, "Regular", SceneBase::kEndCapBSplineBasis, g_options.endCap == SceneBase::kEndCapBSplineBasis); - g_hud.AddPullDownButton(endcap_pulldown, "GregoryBasis", + g_hud.AddPullDownButton(endcap_pulldown, "Gregory", SceneBase::kEndCapGregoryBasis, g_options.endCap == SceneBase::kEndCapGregoryBasis); } @@ -1119,7 +1128,7 @@ initHUD() { for (int i = 1; i < 11; ++i) { char level[16]; sprintf(level, "Lv. %d", i); - g_hud.AddRadioButton(3, level, i==2, 10, 210+i*20, callbackLevel, i, '0'+(i%10)); + g_hud.AddRadioButton(3, level, i==g_level, 10, 210+i*20, callbackLevel, i, '0'+(i%10)); } g_hud.Rebuild(windowWidth, windowHeight, frameBufferWidth, frameBufferHeight); @@ -1153,8 +1162,8 @@ idle() { //------------------------------------------------------------------------------ static void callbackError(Far::ErrorType err, const char *message) { - printf("Error: %d\n", err); - printf("%s", message); + printf("OpenSubdiv Error: %d\n", err); + printf(" %s\n", message); } //------------------------------------------------------------------------------ @@ -1168,8 +1177,12 @@ int main(int argc, char ** argv) { std::string str; for (int i = 1; i < argc; ++i) { - if (!strcmp(argv[i], "-d")) { + if (!strcmp(argv[i], "-l")) { g_level = atoi(argv[++i]); + } else if (!strcmp(argv[i], "-a")) { + g_options.adaptive = true; + } else if (!strcmp(argv[i], "-u")) { + g_options.adaptive = false; } } Far::SetErrorCallback(callbackError); @@ -1217,9 +1230,6 @@ int main(int argc, char ** argv) { #endif #endif - // activate feature adaptive tessellation if OSD supports it - g_options.adaptive = true; - initShapes(); initGL(); diff --git a/examples/glShareTopology/init_shapes.h b/examples/glShareTopology/init_shapes.h index 0289e23b..8d9ab2b5 100644 --- a/examples/glShareTopology/init_shapes.h +++ b/examples/glShareTopology/init_shapes.h @@ -41,6 +41,7 @@ static std::vector g_defaultShapes; //------------------------------------------------------------------------------ static void initShapes() { + g_defaultShapes.push_back( ShapeDesc("catmark_cube", catmark_cube, kCatmark ) ); g_defaultShapes.push_back( ShapeDesc("catmark_cube_corner0", catmark_cube_corner0, kCatmark ) ); g_defaultShapes.push_back( ShapeDesc("catmark_cube_corner1", catmark_cube_corner1, kCatmark ) ); g_defaultShapes.push_back( ShapeDesc("catmark_cube_corner2", catmark_cube_corner2, kCatmark ) ); @@ -49,17 +50,15 @@ static void initShapes() { g_defaultShapes.push_back( ShapeDesc("catmark_cube_creases0", catmark_cube_creases0, kCatmark ) ); g_defaultShapes.push_back( ShapeDesc("catmark_cube_creases1", catmark_cube_creases1, kCatmark ) ); g_defaultShapes.push_back( ShapeDesc("catmark_cube_creases2", catmark_cube_creases2, kCatmark ) ); - g_defaultShapes.push_back( ShapeDesc("catmark_cube", catmark_cube, kCatmark ) ); g_defaultShapes.push_back( ShapeDesc("catmark_dart_edgecorner", catmark_dart_edgecorner, kCatmark ) ); g_defaultShapes.push_back( ShapeDesc("catmark_dart_edgeonly", catmark_dart_edgeonly, kCatmark ) ); g_defaultShapes.push_back( ShapeDesc("catmark_edgecorner", catmark_edgecorner, kCatmark ) ); g_defaultShapes.push_back( ShapeDesc("catmark_edgeonly", catmark_edgeonly, kCatmark ) ); + g_defaultShapes.push_back( ShapeDesc("catmark_quadstrips", catmark_quadstrips, kCatmark ) ); g_defaultShapes.push_back( ShapeDesc("catmark_chaikin0", catmark_chaikin0, kCatmark ) ); g_defaultShapes.push_back( ShapeDesc("catmark_chaikin1", catmark_chaikin1, kCatmark ) ); g_defaultShapes.push_back( ShapeDesc("catmark_chaikin2", catmark_chaikin2, kCatmark ) ); g_defaultShapes.push_back( ShapeDesc("catmark_fan", catmark_fan, kCatmark ) ); - g_defaultShapes.push_back( ShapeDesc("catmark_flap", catmark_flap, kCatmark ) ); - g_defaultShapes.push_back( ShapeDesc("catmark_flap2", catmark_flap2, kCatmark ) ); g_defaultShapes.push_back( ShapeDesc("catmark_fvar_bound0", catmark_fvar_bound0, kCatmark ) ); g_defaultShapes.push_back( ShapeDesc("catmark_fvar_bound1", catmark_fvar_bound1, kCatmark ) ); g_defaultShapes.push_back( ShapeDesc("catmark_fvar_bound2", catmark_fvar_bound2, kCatmark ) ); @@ -87,30 +86,31 @@ static void initShapes() { g_defaultShapes.push_back( ShapeDesc("catmark_torus_creases0", catmark_torus_creases0, kCatmark ) ); g_defaultShapes.push_back( ShapeDesc("catmark_smoothtris0", catmark_smoothtris0, kCatmark ) ); g_defaultShapes.push_back( ShapeDesc("catmark_smoothtris1", catmark_smoothtris1, kCatmark ) ); -// g_defaultShapes.push_back( ShapeDesc("catmark_square_hedit0", catmark_square_hedit0, kCatmark ) ); -// g_defaultShapes.push_back( ShapeDesc("catmark_square_hedit1", catmark_square_hedit1, kCatmark ) ); -// g_defaultShapes.push_back( ShapeDesc("catmark_square_hedit2", catmark_square_hedit2, kCatmark ) ); -// g_defaultShapes.push_back( ShapeDesc("catmark_square_hedit3", catmark_square_hedit3, kCatmark ) ); g_defaultShapes.push_back( ShapeDesc("catmark_bishop", catmark_bishop, kCatmark ) ); g_defaultShapes.push_back( ShapeDesc("catmark_car", catmark_car, kCatmark ) ); g_defaultShapes.push_back( ShapeDesc("catmark_helmet", catmark_helmet, kCatmark ) ); g_defaultShapes.push_back( ShapeDesc("catmark_pawn", catmark_pawn, kCatmark ) ); g_defaultShapes.push_back( ShapeDesc("catmark_rook", catmark_rook, kCatmark ) ); -#if 0 - g_defaultShapes.push_back( ShapeDesc("bilinear_cube", bilinear_cube, kBilinear ) ); - - - g_defaultShapes.push_back( ShapeDesc("loop_cube_creases0", loop_cube_creases0, kLoop ) ); - g_defaultShapes.push_back( ShapeDesc("loop_cube_creases1", loop_cube_creases1, kLoop ) ); g_defaultShapes.push_back( ShapeDesc("loop_cube", loop_cube, kLoop ) ); - g_defaultShapes.push_back( ShapeDesc("loop_icosahedron", loop_icosahedron, kLoop ) ); - g_defaultShapes.push_back( ShapeDesc("loop_saddle_edgecorner", loop_saddle_edgecorner, kLoop ) ); - g_defaultShapes.push_back( ShapeDesc("loop_saddle_edgeonly", loop_saddle_edgeonly, kLoop ) ); + g_defaultShapes.push_back( ShapeDesc("loop_cubes_semisharp", loop_cubes_semisharp, kLoop ) ); + g_defaultShapes.push_back( ShapeDesc("loop_cubes_infsharp", loop_cubes_infsharp, kLoop ) ); + g_defaultShapes.push_back( ShapeDesc("loop_cube_asymmetric", loop_cube_asymmetric, kLoop ) ); g_defaultShapes.push_back( ShapeDesc("loop_triangle_edgecorner", loop_triangle_edgecorner, kLoop ) ); g_defaultShapes.push_back( ShapeDesc("loop_triangle_edgeonly", loop_triangle_edgeonly, kLoop ) ); + g_defaultShapes.push_back( ShapeDesc("loop_xord_interior", loop_xord_interior, kLoop ) ); + g_defaultShapes.push_back( ShapeDesc("loop_xord_boundary", loop_xord_boundary, kLoop ) ); + g_defaultShapes.push_back( ShapeDesc("loop_icosahedron", loop_icosahedron, kLoop ) ); + g_defaultShapes.push_back( ShapeDesc("loop_icos_semisharp", loop_icos_semisharp, kLoop ) ); + g_defaultShapes.push_back( ShapeDesc("loop_icos_infsharp", loop_icos_infsharp, kLoop ) ); g_defaultShapes.push_back( ShapeDesc("loop_chaikin0", loop_chaikin0, kLoop ) ); g_defaultShapes.push_back( ShapeDesc("loop_chaikin1", loop_chaikin1, kLoop ) ); -#endif + g_defaultShapes.push_back( ShapeDesc("loop_pole8", loop_pole8, kLoop ) ); + g_defaultShapes.push_back( ShapeDesc("loop_pole64", loop_pole64, kLoop ) ); + + g_defaultShapes.push_back( ShapeDesc("bilinear_cube", bilinear_cube, kBilinear ) ); + g_defaultShapes.push_back( ShapeDesc("bilinear_nonplanar", bilinear_nonplanar, kBilinear ) ); + g_defaultShapes.push_back( ShapeDesc("bilinear_nonquads0", bilinear_nonquads0, kBilinear ) ); + g_defaultShapes.push_back( ShapeDesc("bilinear_nonquads1", bilinear_nonquads1, kBilinear ) ); } //------------------------------------------------------------------------------ diff --git a/examples/glShareTopology/sceneBase.h b/examples/glShareTopology/sceneBase.h index eba71464..49238215 100644 --- a/examples/glShareTopology/sceneBase.h +++ b/examples/glShareTopology/sceneBase.h @@ -38,7 +38,7 @@ public: kEndCapGregoryBasis }; struct Options { - Options() : adaptive(true), endCap(kEndCapBSplineBasis) { } + Options() : adaptive(true), endCap(kEndCapGregoryBasis) { } bool adaptive; int endCap; diff --git a/examples/glShareTopology/shader.glsl b/examples/glShareTopology/shader.glsl index 0268e1aa..d4dca72a 100644 --- a/examples/glShareTopology/shader.glsl +++ b/examples/glShareTopology/shader.glsl @@ -386,11 +386,11 @@ getAdaptivePatchColor(ivec3 patchParam) vec4(0.0f, 0.8f, 0.75f, 1.0f), // boundary pattern 4 vec4(0.0f, 1.0f, 0.0f, 1.0f), // corner - vec4(0.25f, 0.25f, 0.25f, 1.0f), // corner pattern 0 - vec4(0.25f, 0.25f, 0.25f, 1.0f), // corner pattern 1 - vec4(0.25f, 0.25f, 0.25f, 1.0f), // corner pattern 2 - vec4(0.25f, 0.25f, 0.25f, 1.0f), // corner pattern 3 - vec4(0.25f, 0.25f, 0.25f, 1.0f), // corner pattern 4 + vec4(0.5f, 1.0f, 0.5f, 1.0f), // corner pattern 0 + vec4(0.5f, 1.0f, 0.5f, 1.0f), // corner pattern 1 + vec4(0.5f, 1.0f, 0.5f, 1.0f), // corner pattern 2 + vec4(0.5f, 1.0f, 0.5f, 1.0f), // corner pattern 3 + vec4(0.5f, 1.0f, 0.5f, 1.0f), // corner pattern 4 vec4(1.0f, 1.0f, 0.0f, 1.0f), // gregory vec4(1.0f, 1.0f, 0.0f, 1.0f), // gregory @@ -415,27 +415,32 @@ getAdaptivePatchColor(ivec3 patchParam) ); int patchType = 0; -#if defined OSD_PATCH_GREGORY - patchType = 4; -#elif defined OSD_PATCH_GREGORY_BOUNDARY - patchType = 5; -#elif defined OSD_PATCH_GREGORY_BASIS - patchType = 6; -#endif int edgeCount = bitCount(OsdGetPatchBoundaryMask(patchParam)); if (edgeCount == 1) { patchType = 2; // BOUNDARY } - if (edgeCount == 2) { - patchType = 3; // CORNER + if (edgeCount > 1) { + patchType = 3; // CORNER (not correct for patches that are not isolated) } - int pattern = bitCount(OsdGetPatchTransitionMask(patchParam)); -#ifdef OSD_PATCH_ENABLE_SINGLE_CREASE - if (inpt.sharpness > 0) pattern += 6; +#if defined(OSD_PATCH_ENABLE_SINGLE_CREASE) && !defined(LOOP) + // check this after boundary/corner since single crease patch also has edgeCount. + if (inpt.vSegments.y > 0) { + patchType = 1; + } +#elif defined OSD_PATCH_GREGORY + patchType = 4; +#elif defined OSD_PATCH_GREGORY_BOUNDARY + patchType = 5; +#elif defined OSD_PATCH_GREGORY_BASIS + patchType = 6; +#elif defined OSD_PATCH_GREGORY_TRIANGLE + patchType = 6; #endif + int pattern = bitCount(OsdGetPatchTransitionMask(patchParam)); + return patchColors[6*patchType + pattern]; } diff --git a/examples/glStencilViewer/glStencilViewer.cpp b/examples/glStencilViewer/glStencilViewer.cpp index ecccf2b0..cece319b 100644 --- a/examples/glStencilViewer/glStencilViewer.cpp +++ b/examples/glStencilViewer/glStencilViewer.cpp @@ -106,7 +106,7 @@ enum HudCheckBox { kHUD_CB_DISPLAY_CONTROL_MESH_EDGES, kHUD_CB_INF_SHARP_PATCH }; int g_kernel = kCPU, - g_isolationLevel = 5; // max level of extraordinary feature isolation + g_isolationLevel = 2; // max level of extraordinary feature isolation int g_running = 1, g_width = 1024, @@ -1061,36 +1061,39 @@ int main(int argc, char **argv) { bool fullscreen = false; Scheme defaultScheme = kCatmark; - std::string str; + std::vector objfiles; for (int i = 1; i < argc; ++i) { - if (!strcmp(argv[i], "-u")) { + if (strstr(argv[i], ".obj")) { + objfiles.push_back(argv[i]); + } else if (!strcmp(argv[i], "-a")) { + g_adaptive = true; + } else if (!strcmp(argv[i], "-u")) { g_adaptive = false; - } - if (!strcmp(argv[i], "-d")) { + } else if (!strcmp(argv[i], "-l")) { g_isolationLevel = atoi(argv[++i]); - } - else if (!strcmp(argv[i], "-f")) { + } else if (!strcmp(argv[i], "-f")) { fullscreen = true; - } - else if (!strcmp(argv[i], "-bilinear")) { + } else if (!strcmp(argv[i], "-bilinear")) { defaultScheme = kBilinear; - } - else if (!strcmp(argv[i], "-catmark")) { + } else if (!strcmp(argv[i], "-catmark")) { defaultScheme = kCatmark; - } - else if (!strcmp(argv[i], "-loop")) { + } else if (!strcmp(argv[i], "-loop")) { defaultScheme = kLoop; + } else { + printf("Warning: unrecognized argument '%s' ignored\n", argv[i]); } - else { - std::ifstream ifs(argv[i]); - if (ifs) { - std::stringstream ss; - ss << ifs.rdbuf(); - ifs.close(); - str = ss.str(); - g_defaultShapes.push_back(ShapeDesc(argv[i], str.c_str(), defaultScheme)); - } + } + for (int i = 0; i < (int)objfiles.size(); ++i) { + std::ifstream ifs(objfiles[i]); + if (ifs) { + std::stringstream ss; + ss << ifs.rdbuf(); + ifs.close(); + std::string str = ss.str(); + g_defaultShapes.push_back(ShapeDesc(objfiles[i], str.c_str(), defaultScheme)); + } else { + printf("Warning: cannot open shape file '%s'\n", objfiles[i]); } } diff --git a/examples/glStencilViewer/init_shapes.h b/examples/glStencilViewer/init_shapes.h index aa9583ee..a2cdd867 100644 --- a/examples/glStencilViewer/init_shapes.h +++ b/examples/glStencilViewer/init_shapes.h @@ -39,8 +39,7 @@ static std::vector g_defaultShapes; //------------------------------------------------------------------------------ static void initShapes() { -// g_defaultShapes.push_back( ShapeDesc("bilinear_cube", bilinear_cube, kBilinear) ); - + g_defaultShapes.push_back( ShapeDesc("catmark_cube", catmark_cube, kCatmark ) ); g_defaultShapes.push_back( ShapeDesc("catmark_cube_corner0", catmark_cube_corner0, kCatmark ) ); g_defaultShapes.push_back( ShapeDesc("catmark_cube_corner1", catmark_cube_corner1, kCatmark ) ); g_defaultShapes.push_back( ShapeDesc("catmark_cube_corner2", catmark_cube_corner2, kCatmark ) ); @@ -48,17 +47,12 @@ static void initShapes() { g_defaultShapes.push_back( ShapeDesc("catmark_cube_corner4", catmark_cube_corner4, kCatmark ) ); g_defaultShapes.push_back( ShapeDesc("catmark_cube_creases0", catmark_cube_creases0, kCatmark ) ); g_defaultShapes.push_back( ShapeDesc("catmark_cube_creases1", catmark_cube_creases1, kCatmark ) ); - g_defaultShapes.push_back( ShapeDesc("catmark_cube", catmark_cube, kCatmark ) ); g_defaultShapes.push_back( ShapeDesc("catmark_dart_edgecorner", catmark_dart_edgecorner, kCatmark ) ); g_defaultShapes.push_back( ShapeDesc("catmark_dart_edgeonly", catmark_dart_edgeonly, kCatmark ) ); g_defaultShapes.push_back( ShapeDesc("catmark_edgecorner", catmark_edgecorner, kCatmark ) ); g_defaultShapes.push_back( ShapeDesc("catmark_edgeonly", catmark_edgeonly, kCatmark ) ); - g_defaultShapes.push_back( ShapeDesc("catmark_chaikin0", catmark_chaikin0, kCatmark ) ); - g_defaultShapes.push_back( ShapeDesc("catmark_chaikin1", catmark_chaikin1, kCatmark ) ); - g_defaultShapes.push_back( ShapeDesc("catmark_chaikin2", catmark_chaikin2, kCatmark ) ); + g_defaultShapes.push_back( ShapeDesc("catmark_quadstrips", catmark_quadstrips, kCatmark ) ); g_defaultShapes.push_back( ShapeDesc("catmark_fan", catmark_fan, kCatmark ) ); - g_defaultShapes.push_back( ShapeDesc("catmark_flap", catmark_flap, kCatmark ) ); - g_defaultShapes.push_back( ShapeDesc("catmark_flap2", catmark_flap2, kCatmark ) ); g_defaultShapes.push_back( ShapeDesc("catmark_gregory_test1", catmark_gregory_test1, kCatmark ) ); g_defaultShapes.push_back( ShapeDesc("catmark_gregory_test2", catmark_gregory_test2, kCatmark ) ); g_defaultShapes.push_back( ShapeDesc("catmark_gregory_test3", catmark_gregory_test3, kCatmark ) ); @@ -76,27 +70,29 @@ static void initShapes() { g_defaultShapes.push_back( ShapeDesc("catmark_tent", catmark_tent, kCatmark ) ); g_defaultShapes.push_back( ShapeDesc("catmark_torus", catmark_torus, kCatmark ) ); g_defaultShapes.push_back( ShapeDesc("catmark_torus_creases0", catmark_torus_creases0, kCatmark ) ); -// g_defaultShapes.push_back( ShapeDesc("catmark_square_hedit0", catmark_square_hedit0, kCatmark ) ); -// g_defaultShapes.push_back( ShapeDesc("catmark_square_hedit1", catmark_square_hedit1, kCatmark ) ); -// g_defaultShapes.push_back( ShapeDesc("catmark_square_hedit2", catmark_square_hedit2, kCatmark ) ); -// g_defaultShapes.push_back( ShapeDesc("catmark_square_hedit3", catmark_square_hedit3, kCatmark ) ); g_defaultShapes.push_back( ShapeDesc("catmark_bishop", catmark_bishop, kCatmark ) ); g_defaultShapes.push_back( ShapeDesc("catmark_car", catmark_car, kCatmark ) ); g_defaultShapes.push_back( ShapeDesc("catmark_helmet", catmark_helmet, kCatmark ) ); g_defaultShapes.push_back( ShapeDesc("catmark_pawn", catmark_pawn, kCatmark ) ); g_defaultShapes.push_back( ShapeDesc("catmark_rook", catmark_rook, kCatmark ) ); -// g_defaultShapes.push_back( ShapeDesc("bilinear_cube", bilinear_cube, kBilinear ) ); + g_defaultShapes.push_back( ShapeDesc("loop_cube", loop_cube, kLoop ) ); + g_defaultShapes.push_back( ShapeDesc("loop_cubes_semisharp", loop_cubes_semisharp, kLoop ) ); + g_defaultShapes.push_back( ShapeDesc("loop_cubes_infsharp", loop_cubes_infsharp, kLoop ) ); + g_defaultShapes.push_back( ShapeDesc("loop_cube_asymmetric", loop_cube_asymmetric, kLoop ) ); + g_defaultShapes.push_back( ShapeDesc("loop_triangle_edgecorner", loop_triangle_edgecorner, kLoop ) ); + g_defaultShapes.push_back( ShapeDesc("loop_triangle_edgeonly", loop_triangle_edgeonly, kLoop ) ); + g_defaultShapes.push_back( ShapeDesc("loop_xord_interior", loop_xord_interior, kLoop ) ); + g_defaultShapes.push_back( ShapeDesc("loop_xord_boundary", loop_xord_boundary, kLoop ) ); + g_defaultShapes.push_back( ShapeDesc("loop_icosahedron", loop_icosahedron, kLoop ) ); + g_defaultShapes.push_back( ShapeDesc("loop_icos_semisharp", loop_icos_semisharp, kLoop ) ); + g_defaultShapes.push_back( ShapeDesc("loop_icos_infsharp", loop_icos_infsharp, kLoop ) ); + g_defaultShapes.push_back( ShapeDesc("loop_pole8", loop_pole8, kLoop ) ); + g_defaultShapes.push_back( ShapeDesc("loop_pole64", loop_pole64, kLoop ) ); -// g_defaultShapes.push_back( ShapeDesc("loop_cube_creases0", loop_cube_creases0, kLoop ) ); -// g_defaultShapes.push_back( ShapeDesc("loop_cube_creases1", loop_cube_creases1, kLoop ) ); -// g_defaultShapes.push_back( ShapeDesc("loop_cube", loop_cube, kLoop ) ); -// g_defaultShapes.push_back( ShapeDesc("loop_icosahedron", loop_icosahedron, kLoop ) ); -// g_defaultShapes.push_back( ShapeDesc("loop_saddle_edgecorner", loop_saddle_edgecorner, kLoop ) ); -// g_defaultShapes.push_back( ShapeDesc("loop_saddle_edgeonly", loop_saddle_edgeonly, kLoop ) ); -// g_defaultShapes.push_back( ShapeDesc("loop_triangle_edgecorner", loop_triangle_edgecorner, kLoop ) ); -// g_defaultShapes.push_back( ShapeDesc("loop_triangle_edgeonly", loop_triangle_edgeonly, kLoop ) ); -// g_defaultShapes.push_back( ShapeDesc("loop_chaikin0", loop_chaikin0, kLoop ) ); -// g_defaultShapes.push_back( ShapeDesc("loop_chaikin1", loop_chaikin1, kLoop ) ); + g_defaultShapes.push_back( ShapeDesc("bilinear_cube", bilinear_cube, kBilinear ) ); + g_defaultShapes.push_back( ShapeDesc("bilinear_nonplanar", bilinear_nonplanar, kBilinear ) ); + g_defaultShapes.push_back( ShapeDesc("bilinear_nonquads0", bilinear_nonquads0, kBilinear ) ); + g_defaultShapes.push_back( ShapeDesc("bilinear_nonquads1", bilinear_nonquads1, kBilinear ) ); } //------------------------------------------------------------------------------ diff --git a/examples/glViewer/glViewer.cpp b/examples/glViewer/glViewer.cpp index 94398a0a..92fc7127 100644 --- a/examples/glViewer/glViewer.cpp +++ b/examples/glViewer/glViewer.cpp @@ -71,6 +71,7 @@ GLFWmonitor* g_primary=0; #include OpenSubdiv::Osd::GLMeshInterface *g_mesh = NULL; OpenSubdiv::Osd::GLLegacyGregoryPatchTable *g_legacyGregoryPatchTable = NULL; +bool g_legacyGregoryEnabled = false; #include "../../regression/common/far_utils.h" #include "../common/glHud.h" @@ -183,7 +184,7 @@ int g_fullscreen = 0, g_shadingMode = kShadingPatchType, g_displayStyle = kDisplayStyleWireOnShaded, g_adaptive = 1, - g_endCap = kEndCapBSplineBasis, + g_endCap = kEndCapGregoryBasis, g_smoothCornerPatch = 0, g_singleCreasePatch = 1, g_infSharpPatch = 0, @@ -1199,7 +1200,7 @@ display() { if (g_displayPatchCounts) { int x = -420; - int y = -180; + int y = g_legacyGregoryEnabled ? -180 : -140; g_hud.DrawString(x, y, "Quads : %d", patchCount[Descriptor::QUADS]); y += 20; g_hud.DrawString(x, y, "Triangles : %d", @@ -1208,10 +1209,12 @@ display() { patchCount[Descriptor::REGULAR]); y+= 20; g_hud.DrawString(x, y, "Loop : %d", patchCount[Descriptor::LOOP]); y+= 20; - g_hud.DrawString(x, y, "Gregory : %d", - patchCount[Descriptor::GREGORY]); y+= 20; - g_hud.DrawString(x, y, "Gregory Boundary : %d", - patchCount[Descriptor::GREGORY_BOUNDARY]); y+= 20; + if (g_legacyGregoryEnabled) { + g_hud.DrawString(x, y, "Gregory : %d", + patchCount[Descriptor::GREGORY]); y+= 20; + g_hud.DrawString(x, y, "Gregory Boundary : %d", + patchCount[Descriptor::GREGORY_BOUNDARY]); y+= 20; + } g_hud.DrawString(x, y, "Gregory Basis : %d", patchCount[Descriptor::GREGORY_BASIS]); y+= 20; g_hud.DrawString(x, y, "Gregory Triangle : %d", @@ -1581,9 +1584,11 @@ initHUD() { g_hud.AddPullDownButton(endcap_pulldown, "Gregory", kEndCapGregoryBasis, g_endCap == kEndCapGregoryBasis); - g_hud.AddPullDownButton(endcap_pulldown, "LegacyGregory", - kEndCapLegacyGregory, - g_endCap == kEndCapLegacyGregory); + if (g_legacyGregoryEnabled) { + g_hud.AddPullDownButton(endcap_pulldown, "LegacyGregory", + kEndCapLegacyGregory, + g_endCap == kEndCapLegacyGregory); + } } for (int i = 1; i < 11; ++i) { @@ -1632,8 +1637,8 @@ idle() { //------------------------------------------------------------------------------ static void callbackErrorOsd(OpenSubdiv::Far::ErrorType err, const char *message) { - printf("Error: %d\n", err); - printf("%s", message); + printf("OpenSubdiv Error: %d\n", err); + printf(" %s\n", message); } //------------------------------------------------------------------------------ @@ -1648,54 +1653,59 @@ int main(int argc, char ** argv) { bool fullscreen = false; Scheme defaultScheme = kCatmark; - std::string str; - std::vector animobjs; + std::vector objfiles; + bool objAnimFlag = false; for (int i = 1; i < argc; ++i) { if (strstr(argv[i], ".obj")) { - animobjs.push_back(argv[i]); - } - else if (!strcmp(argv[i], "-axis")) { - g_axis = false; - } - else if (!strcmp(argv[i], "-u")) { + objfiles.push_back(argv[i]); + } else if (!strcmp(argv[i], "-a")) { + g_adaptive = true; + } else if (!strcmp(argv[i], "-u")) { g_adaptive = false; - } - else if (!strcmp(argv[i], "-d")) { + } else if (!strcmp(argv[i], "-l")) { if (++i < argc) g_level = atoi(argv[i]); - } - else if (!strcmp(argv[i], "-c")) { + } else if (!strcmp(argv[i], "-axis")) { + g_axis = false; + } else if (!strcmp(argv[i], "-c")) { if (++i < argc) g_repeatCount = atoi(argv[i]); - } - else if (!strcmp(argv[i], "-f")) { + } else if (!strcmp(argv[i], "-f")) { fullscreen = true; - } - else if (!strcmp(argv[i], "-bilinear")) { + } else if (!strcmp(argv[i], "-anim")) { + objAnimFlag = true; + } else if (!strcmp(argv[i], "-bilinear")) { defaultScheme = kBilinear; - } - else if (!strcmp(argv[i], "-catmark")) { + } else if (!strcmp(argv[i], "-catmark")) { defaultScheme = kCatmark; - } - else if (!strcmp(argv[i], "-loop")) { + } else if (!strcmp(argv[i], "-loop")) { defaultScheme = kLoop; - } - else { - std::ifstream ifs(argv[i]); - if (ifs) { - std::stringstream ss; - ss << ifs.rdbuf(); - ifs.close(); - str = ss.str(); - g_defaultShapes.push_back(ShapeDesc(argv[i], str.c_str(), defaultScheme)); - } + } else if (!strcmp(argv[i], "-lg")) { + g_legacyGregoryEnabled = true; + } else { + printf("Warning: unrecognized argument '%s' ignored\n", argv[i]); } } - if (! animobjs.empty()) { - - g_defaultShapes.push_back(ShapeDesc(animobjs[0], "", defaultScheme)); - - g_objAnim = ObjAnim::Create(animobjs, g_axis, defaultScheme); + if (! objfiles.empty()) { + if (objAnimFlag) { + g_objAnim = ObjAnim::Create(objfiles, g_axis, defaultScheme); + if (g_objAnim) { + g_defaultShapes.push_back(ShapeDesc(objfiles[0], "", defaultScheme)); + } + } else { + for (int i = 0; i < (int)objfiles.size(); ++i) { + std::ifstream ifs(objfiles[i]); + if (ifs) { + std::stringstream ss; + ss << ifs.rdbuf(); + ifs.close(); + std::string str = ss.str(); + g_defaultShapes.push_back(ShapeDesc(objfiles[i], str.c_str(), defaultScheme)); + } else { + printf("Warning: cannot open shape file '%s'\n", objfiles[i]); + } + } + } } initShapes(); diff --git a/examples/glViewer/init_shapes.h b/examples/glViewer/init_shapes.h index 39546ac1..6be7a2b1 100644 --- a/examples/glViewer/init_shapes.h +++ b/examples/glViewer/init_shapes.h @@ -41,6 +41,7 @@ static std::vector g_defaultShapes; //------------------------------------------------------------------------------ static void initShapes() { + g_defaultShapes.push_back( ShapeDesc("catmark_cube", catmark_cube, kCatmark ) ); g_defaultShapes.push_back( ShapeDesc("catmark_cube_corner0", catmark_cube_corner0, kCatmark ) ); g_defaultShapes.push_back( ShapeDesc("catmark_cube_corner1", catmark_cube_corner1, kCatmark ) ); g_defaultShapes.push_back( ShapeDesc("catmark_cube_corner2", catmark_cube_corner2, kCatmark ) ); @@ -49,11 +50,11 @@ static void initShapes() { g_defaultShapes.push_back( ShapeDesc("catmark_cube_creases0", catmark_cube_creases0, kCatmark ) ); g_defaultShapes.push_back( ShapeDesc("catmark_cube_creases1", catmark_cube_creases1, kCatmark ) ); g_defaultShapes.push_back( ShapeDesc("catmark_cube_creases2", catmark_cube_creases2, kCatmark ) ); - g_defaultShapes.push_back( ShapeDesc("catmark_cube", catmark_cube, kCatmark ) ); g_defaultShapes.push_back( ShapeDesc("catmark_dart_edgecorner", catmark_dart_edgecorner, kCatmark ) ); g_defaultShapes.push_back( ShapeDesc("catmark_dart_edgeonly", catmark_dart_edgeonly, kCatmark ) ); g_defaultShapes.push_back( ShapeDesc("catmark_edgecorner", catmark_edgecorner, kCatmark ) ); g_defaultShapes.push_back( ShapeDesc("catmark_edgeonly", catmark_edgeonly, kCatmark ) ); + g_defaultShapes.push_back( ShapeDesc("catmark_quadstrips", catmark_quadstrips, kCatmark ) ); g_defaultShapes.push_back( ShapeDesc("catmark_chaikin0", catmark_chaikin0, kCatmark ) ); g_defaultShapes.push_back( ShapeDesc("catmark_chaikin1", catmark_chaikin1, kCatmark ) ); g_defaultShapes.push_back( ShapeDesc("catmark_chaikin2", catmark_chaikin2, kCatmark ) ); @@ -61,11 +62,6 @@ static void initShapes() { g_defaultShapes.push_back( ShapeDesc("catmark_inf_crease0", catmark_inf_crease0, kCatmark ) ); g_defaultShapes.push_back( ShapeDesc("catmark_inf_crease1", catmark_inf_crease1, kCatmark ) ); g_defaultShapes.push_back( ShapeDesc("catmark_fan", catmark_fan, kCatmark ) ); - g_defaultShapes.push_back( ShapeDesc("catmark_flap", catmark_flap, kCatmark ) ); - g_defaultShapes.push_back( ShapeDesc("catmark_flap2", catmark_flap2, kCatmark ) ); - g_defaultShapes.push_back( ShapeDesc("catmark_fvar_bound0", catmark_fvar_bound0, kCatmark ) ); - g_defaultShapes.push_back( ShapeDesc("catmark_fvar_bound1", catmark_fvar_bound1, kCatmark ) ); - g_defaultShapes.push_back( ShapeDesc("catmark_fvar_bound2", catmark_fvar_bound2, kCatmark ) ); g_defaultShapes.push_back( ShapeDesc("catmark_gregory_test0", catmark_gregory_test0, kCatmark ) ); g_defaultShapes.push_back( ShapeDesc("catmark_gregory_test1", catmark_gregory_test1, kCatmark ) ); g_defaultShapes.push_back( ShapeDesc("catmark_gregory_test2", catmark_gregory_test2, kCatmark ) ); @@ -96,30 +92,31 @@ static void initShapes() { g_defaultShapes.push_back( ShapeDesc("catmark_torus_creases0", catmark_torus_creases0, kCatmark ) ); g_defaultShapes.push_back( ShapeDesc("catmark_smoothtris0", catmark_smoothtris0, kCatmark ) ); g_defaultShapes.push_back( ShapeDesc("catmark_smoothtris1", catmark_smoothtris1, kCatmark ) ); -// g_defaultShapes.push_back( ShapeDesc("catmark_square_hedit0", catmark_square_hedit0, kCatmark ) ); -// g_defaultShapes.push_back( ShapeDesc("catmark_square_hedit1", catmark_square_hedit1, kCatmark ) ); -// g_defaultShapes.push_back( ShapeDesc("catmark_square_hedit2", catmark_square_hedit2, kCatmark ) ); -// g_defaultShapes.push_back( ShapeDesc("catmark_square_hedit3", catmark_square_hedit3, kCatmark ) ); g_defaultShapes.push_back( ShapeDesc("catmark_bishop", catmark_bishop, kCatmark ) ); g_defaultShapes.push_back( ShapeDesc("catmark_car", catmark_car, kCatmark ) ); g_defaultShapes.push_back( ShapeDesc("catmark_helmet", catmark_helmet, kCatmark ) ); g_defaultShapes.push_back( ShapeDesc("catmark_pawn", catmark_pawn, kCatmark ) ); g_defaultShapes.push_back( ShapeDesc("catmark_rook", catmark_rook, kCatmark ) ); - g_defaultShapes.push_back( ShapeDesc("bilinear_cube", bilinear_cube, kBilinear ) ); - - g_defaultShapes.push_back( ShapeDesc("loop_cube_creases0", loop_cube_creases0, kLoop ) ); - g_defaultShapes.push_back( ShapeDesc("loop_cube_creases1", loop_cube_creases1, kLoop ) ); g_defaultShapes.push_back( ShapeDesc("loop_cube", loop_cube, kLoop ) ); - g_defaultShapes.push_back( ShapeDesc("loop_icosahedron", loop_icosahedron, kLoop ) ); - g_defaultShapes.push_back( ShapeDesc("loop_saddle_edgecorner", loop_saddle_edgecorner, kLoop ) ); - g_defaultShapes.push_back( ShapeDesc("loop_saddle_edgeonly", loop_saddle_edgeonly, kLoop ) ); + g_defaultShapes.push_back( ShapeDesc("loop_cubes_semisharp", loop_cubes_semisharp, kLoop ) ); + g_defaultShapes.push_back( ShapeDesc("loop_cubes_infsharp", loop_cubes_infsharp, kLoop ) ); + g_defaultShapes.push_back( ShapeDesc("loop_cube_asymmetric", loop_cube_asymmetric, kLoop ) ); g_defaultShapes.push_back( ShapeDesc("loop_triangle_edgecorner", loop_triangle_edgecorner, kLoop ) ); g_defaultShapes.push_back( ShapeDesc("loop_triangle_edgeonly", loop_triangle_edgeonly, kLoop ) ); + g_defaultShapes.push_back( ShapeDesc("loop_xord_interior", loop_xord_interior, kLoop ) ); + g_defaultShapes.push_back( ShapeDesc("loop_xord_boundary", loop_xord_boundary, kLoop ) ); + g_defaultShapes.push_back( ShapeDesc("loop_icosahedron", loop_icosahedron, kLoop ) ); + g_defaultShapes.push_back( ShapeDesc("loop_icos_semisharp", loop_icos_semisharp, kLoop ) ); + g_defaultShapes.push_back( ShapeDesc("loop_icos_infsharp", loop_icos_infsharp, kLoop ) ); g_defaultShapes.push_back( ShapeDesc("loop_chaikin0", loop_chaikin0, kLoop ) ); g_defaultShapes.push_back( ShapeDesc("loop_chaikin1", loop_chaikin1, kLoop ) ); g_defaultShapes.push_back( ShapeDesc("loop_pole8", loop_pole8, kLoop ) ); g_defaultShapes.push_back( ShapeDesc("loop_pole64", loop_pole64, kLoop ) ); - g_defaultShapes.push_back( ShapeDesc("loop_pole360", loop_pole360, kLoop ) ); + + g_defaultShapes.push_back( ShapeDesc("bilinear_cube", bilinear_cube, kBilinear ) ); + g_defaultShapes.push_back( ShapeDesc("bilinear_nonplanar", bilinear_nonplanar, kBilinear ) ); + g_defaultShapes.push_back( ShapeDesc("bilinear_nonquads0", bilinear_nonquads0, kBilinear ) ); + g_defaultShapes.push_back( ShapeDesc("bilinear_nonquads1", bilinear_nonquads1, kBilinear ) ); } //------------------------------------------------------------------------------