Merge pull request #1096 from barfowl/examples_gl_args

Updated GL examples for common command line arguments
This commit is contained in:
George ElKoura 2019-04-25 13:25:44 -07:00 committed by GitHub
commit 3875be6b99
No known key found for this signature in database
GPG Key ID: 4AEE18F83AFDEB23
12 changed files with 193 additions and 261 deletions

View File

@ -35,7 +35,7 @@ SYNOPSIS
.. parsed-literal::
:class: codefhead
**glEvalLimit** [**-f**] [**-u**] [**-a**] [**-l** *refinement level*]
**glEvalLimit** [**-f**] [**-yup**] [**-u**] [**-a**] [**-l** *refinement level*]
*objfile(s)* [**-catmark**] [**-loop**] [**-bilinear**]
DESCRIPTION

View File

@ -35,7 +35,7 @@ SYNOPSIS
.. parsed-literal::
:class: codefhead
**glPaintTest** [**-f**] [**-l** *adaptive refinement level*]
**glPaintTest** [**-f**] [**-yup**] [**-l** *adaptive refinement level*]
*objfile(s)* [**-catmark**] [**-loop**]

View File

@ -35,7 +35,7 @@ SYNOPSIS
.. parsed-literal::
:class: codefhead
**glPtexViewer** [**-f**] [**-u**] [**-a**] [**-l** *isolation level*] [**-c** *animation loops*] [**-y**]
**glPtexViewer** [**-f**] [**-yup**] [**-u**] [**-a**] [**-l** *isolation level*] [**-c** *animation loops*]
[**-e** *environment map*] [**-d** *HDR diffuse map*] [**-s** *HDR specular map*]
[**--disp** *displacement scale*] [**--bump** *bump scale*]
*ptex color file*
@ -63,9 +63,6 @@ See the description of the
`common comand line options <code_examples.html#common-command-line-options>`__
for the subset of common options supported here.
**-y**
Swap Z-up geometry to Y-UP.
**-e** *environment map*
A low dynamic range spherical environment map used as a background. Ideally,
a color-normalized version of the HDR light probe.

View File

@ -35,7 +35,7 @@ SYNOPSIS
.. parsed-literal::
:class: codefhead
**glStencilViewer** [**-f**] [**-u**] [**-a**] [**-l** *refinement level*]
**glStencilViewer** [**-f**] [**-yup**] [**-u**] [**-a**] [**-l** *refinement level*]
*objfile(s)* [**-catmark**] [**-loop**] [**-bilinear**]
DESCRIPTION

View File

@ -35,17 +35,13 @@ const ObjAnim *
PopulateAnimShapes(const ArgOptions &args,
std::vector<ShapeDesc> *defaultShapes)
{
if (!defaultShapes)
return NULL;
if (args.GetObjFiles().empty())
return NULL;
const ObjAnim *objAnim = ObjAnim::Create(args.GetObjFiles(),
args.GetDefaultScheme());
if (objAnim) {
if (objAnim && defaultShapes) {
defaultShapes->push_back(ShapeDesc(args.GetObjFiles()[0], "",
args.GetDefaultScheme()));
}

View File

@ -39,7 +39,7 @@ namespace ViewerArgsUtils {
// defaultShapes vector, treating the objs as an animated series, returning
// an ObjAnim object.
const ObjAnim *PopulateAnimShapes(const ArgOptions &args,
std::vector<ShapeDesc> *defaultShapes);
std::vector<ShapeDesc> *defaultShapes = 0);
// From the list of obj files in args, populates the
// defaultShapes vector.

View File

@ -80,6 +80,8 @@ GLFWmonitor* g_primary=0;
#include <opensubdiv/far/error.h>
#include "../../regression/common/far_utils.h"
#include "../common/argOptions.h"
#include "../common/viewerArgsUtils.h"
#include "../common/stopwatch.h"
#include "../common/simple_math.h"
#include "../common/glControlMeshDisplay.h"
@ -106,7 +108,8 @@ enum KernelType { kCPU = 0,
kGLXFB = 5,
kGLCompute = 6 };
enum EndCap { kEndCapBSplineBasis,
enum EndCap { kEndCapBilinearBasis,
kEndCapBSplineBasis,
kEndCapGregoryBasis };
enum HudCheckBox { kHUD_CB_DISPLAY_CONTROL_MESH_EDGES,
@ -116,6 +119,8 @@ enum HudCheckBox { kHUD_CB_DISPLAY_CONTROL_MESH_EDGES,
kHUD_CB_RANDOM_START,
kHUD_CB_FREEZE,
kHUD_CB_ADAPTIVE,
kHUD_CB_SMOOTH_CORNER_PATCH,
kHUD_CB_SINGLE_CREASE_PATCH,
kHUD_CB_INF_SHARP_PATCH };
enum DrawMode { kUV,
@ -134,6 +139,8 @@ int g_currentShape = 0,
g_level = 2,
g_kernel = kCPU,
g_endCap = kEndCapGregoryBasis,
g_smoothCornerPatch = 0,
g_singleCreasePatch = 0,
g_infSharpPatch = 0,
g_numElements = 3;
@ -156,6 +163,8 @@ float g_rotate[2] = {0, 0},
g_size = 0,
g_moveScale = 0.0f;
bool g_yup = false;
GLuint g_transformUB = 0,
g_transformBinding = 0;
@ -658,14 +667,13 @@ createOsdMesh(ShapeDesc const & shapeDesc, int level) {
bool hasFVarData = !shape->uvs.empty();
{
bool doInfSharpPatch = (g_infSharpPatch!=0 && g_adaptive);
if (g_adaptive) {
// Apply feature adaptive refinement to the mesh so that we can use the
// limit evaluation API features.
Far::TopologyRefiner::AdaptiveOptions options(level);
options.considerFVarChannels = hasFVarData;
options.useInfSharpPatch = doInfSharpPatch;
options.useSingleCreasePatch = g_singleCreasePatch;
options.useInfSharpPatch = g_infSharpPatch;
topologyRefiner->RefineAdaptive(options);
} else {
Far::TopologyRefiner::UniformOptions options(level);
@ -695,14 +703,19 @@ createOsdMesh(ShapeDesc const & shapeDesc, int level) {
// Generate bi-cubic patch table for the limit surface
Far::PatchTableFactory::Options poptions(level);
if (g_endCap == kEndCapBSplineBasis) {
if (g_endCap == kEndCapBilinearBasis) {
poptions.SetEndCapType(
Far::PatchTableFactory::Options::ENDCAP_BILINEAR_BASIS);
} else if (g_endCap == kEndCapBSplineBasis) {
poptions.SetEndCapType(
Far::PatchTableFactory::Options::ENDCAP_BSPLINE_BASIS);
} else {
poptions.SetEndCapType(
Far::PatchTableFactory::Options::ENDCAP_GREGORY_BASIS);
}
poptions.useInfSharpPatch = doInfSharpPatch;
poptions.generateLegacySharpCornerPatches = !g_smoothCornerPatch;
poptions.useSingleCreasePatch = g_singleCreasePatch;
poptions.useInfSharpPatch = g_infSharpPatch;
poptions.generateFVarTables = hasFVarData;
poptions.generateFVarLegacyLinearPatches = false;
poptions.includeFVarBaseLevelIndices = true;;
@ -1053,7 +1066,9 @@ display() {
translate(g_transformData.ModelViewMatrix, -g_pan[0], -g_pan[1], -g_dolly);
rotate(g_transformData.ModelViewMatrix, g_rotate[1], 1, 0, 0);
rotate(g_transformData.ModelViewMatrix, g_rotate[0], 0, 1, 0);
rotate(g_transformData.ModelViewMatrix, -90, 1, 0, 0);
if (!g_yup) {
rotate(g_transformData.ModelViewMatrix, -90, 1, 0, 0);
}
translate(g_transformData.ModelViewMatrix,
-g_center[0], -g_center[1], -g_center[2]);
perspective(g_transformData.ProjectionMatrix,
@ -1314,6 +1329,14 @@ callbackCheckBox(bool checked, int button) {
g_adaptive = checked;
createOsdMesh(g_defaultShapes[g_currentShape], g_level);
break;
case kHUD_CB_SMOOTH_CORNER_PATCH:
g_smoothCornerPatch = checked;
createOsdMesh(g_defaultShapes[g_currentShape], g_level);
return;
case kHUD_CB_SINGLE_CREASE_PATCH:
g_singleCreasePatch = checked;
createOsdMesh(g_defaultShapes[g_currentShape], g_level);
return;
case kHUD_CB_INF_SHARP_PATCH:
g_infSharpPatch = checked;
createOsdMesh(g_defaultShapes[g_currentShape], g_level);
@ -1377,18 +1400,6 @@ initHUD() {
}
#endif
g_hud.AddCheckBox("Inf Sharp Patch (I)", g_infSharpPatch!=0,
10, 130, callbackCheckBox, kHUD_CB_INF_SHARP_PATCH, 'i');
int endcap_pulldown = g_hud.AddPullDown("End cap (E)", 10, 150, 200,
callbackEndCap, 'e');
g_hud.AddPullDownButton(endcap_pulldown, "Regular",
kEndCapBSplineBasis,
g_endCap == kEndCapBSplineBasis);
g_hud.AddPullDownButton(endcap_pulldown, "Gregory",
kEndCapGregoryBasis,
g_endCap == kEndCapGregoryBasis);
int shading_pulldown = g_hud.AddPullDown("Shading (W)", 250, 10, 250, callbackDisplayVaryingColors, 'w');
g_hud.AddPullDownButton(shading_pulldown, "(u,v)", kUV, g_drawMode==kUV);
g_hud.AddPullDownButton(shading_pulldown, "Varying", kVARYING, g_drawMode==kVARYING);
@ -1397,12 +1408,28 @@ initHUD() {
g_hud.AddPullDownButton(shading_pulldown, "FaceVarying", kFACEVARYING, g_drawMode==kFACEVARYING);
g_hud.AddPullDownButton(shading_pulldown, "Mean Curvature", kMEAN_CURVATURE, g_drawMode==kMEAN_CURVATURE);
g_hud.AddCheckBox("Adaptive (`)", g_adaptive != 0, 10, 190, callbackCheckBox, kHUD_CB_ADAPTIVE, '`');
g_hud.AddCheckBox("Adaptive (`)", g_adaptive != 0, 10, 150, callbackCheckBox, kHUD_CB_ADAPTIVE, '`');
g_hud.AddCheckBox("Smooth Corner Patch (O)", g_smoothCornerPatch!=0,
10, 170, callbackCheckBox, kHUD_CB_SMOOTH_CORNER_PATCH, 'o');
// g_hud.AddCheckBox("Single Crease Patch (S)", g_singleCreasePatch!=0,
// 10, 190, callbackCheckBox, kHUD_CB_SINGLE_CREASE_PATCH, 's');
g_hud.AddCheckBox("Inf Sharp Patch (I)", g_infSharpPatch!=0,
10, 190, callbackCheckBox, kHUD_CB_INF_SHARP_PATCH, 'i');
int endcap_pulldown = g_hud.AddPullDown("End cap (E)", 10, 230, 200,
callbackEndCap, 'e');
g_hud.AddPullDownButton(endcap_pulldown, "Linear", kEndCapBilinearBasis,
g_endCap == kEndCapBilinearBasis);
g_hud.AddPullDownButton(endcap_pulldown, "Regular", kEndCapBSplineBasis,
g_endCap == kEndCapBSplineBasis);
g_hud.AddPullDownButton(endcap_pulldown, "Gregory", kEndCapGregoryBasis,
g_endCap == kEndCapGregoryBasis);
for (int i = 1; i < 11; ++i) {
char level[16];
sprintf(level, "Lv. %d", i);
g_hud.AddRadioButton(3, level, i==g_level, 10, 210+i*20, callbackLevel, i, '0'+(i%10));
g_hud.AddRadioButton(3, level, i==g_level, 10, 270+i*20, callbackLevel, i, '0'+(i%10));
}
int pulldown_handle = g_hud.AddPullDown("Shape (N)", -300, 10, 300, callbackModel, 'n');
@ -1440,48 +1467,22 @@ callbackErrorGLFW(int error, const char* description) {
//------------------------------------------------------------------------------
int main(int argc, char **argv) {
bool fullscreen = false;
Scheme defaultScheme = kCatmark;
std::vector<char const *> objfiles;
ArgOptions args;
for (int i = 1; i < argc; ++i) {
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 = atoi(argv[i]);
} else if (!strcmp(argv[i], "-f")) {
fullscreen = true;
} else if (!strcmp(argv[i], "-bilinear")) {
defaultScheme = kBilinear;
} else if (!strcmp(argv[i], "-catmark")) {
defaultScheme = kCatmark;
} else if (!strcmp(argv[i], "-loop")) {
defaultScheme = kLoop;
} 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]);
}
}
args.Parse(argc, argv);
args.PrintUnrecognizedArgsWarnings();
Far::SetErrorCallback(callbackError);
g_yup = args.GetYUp();
g_adaptive = args.GetAdaptive();
g_level = args.GetLevel();
g_repeatCount = args.GetRepeatCount();
ViewerArgsUtils::PopulateShapes(args, &g_defaultShapes);
initShapes();
Far::SetErrorCallback(callbackError);
glfwSetErrorCallback(callbackErrorGLFW);
if (! glfwInit()) {
printf("Failed to initialize GLFW\n");
@ -1492,7 +1493,7 @@ int main(int argc, char **argv) {
GLUtils::SetMinimumGLVersion();
if (fullscreen) {
if (args.GetFullScreen()) {
g_primary = glfwGetPrimaryMonitor();
@ -1514,7 +1515,7 @@ int main(int argc, char **argv) {
}
if (! (g_window=glfwCreateWindow(g_width, g_height, windowTitle,
fullscreen && g_primary ? g_primary : NULL, NULL))) {
args.GetFullScreen() && g_primary ? g_primary : NULL, NULL))) {
std::cerr << "Failed to create OpenGL context.\n";
glfwTerminate();
return 1;

View File

@ -69,6 +69,7 @@
#include <opensubdiv/osd/glMesh.h>
#include "../../regression/common/far_utils.h"
#include "../common/argOptions.h"
#include "../common/patchColors.h"
#include "../common/stb_image_write.h" // common.obj has an implementation.
#include "../common/glShaderCache.h"
@ -459,7 +460,7 @@ void runTest(ShapeDesc const &shapeDesc, std::string const &kernel,
static void usage(const char *program) {
std::cout
<< "Usage %s : " << program << "\n"
<< "Usage: " << program << "\n"
<< " -a : adaptive refinement (default)\n"
<< " -u : uniform refinement\n"
<< " -l <isolation level> : isolation level (default = 2)\n"
@ -485,30 +486,34 @@ int main(int argc, char ** argv) {
std::string displayMode = "PATCH_TYPE";
std::vector<std::string> kernels;
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")) {
std::stringstream ss(argv[++i]);
ArgOptions args;
args.Parse(argc, argv);
adaptive = args.GetAdaptive();
isolationLevel = args.GetLevel();
// Parse remaining args
const std::vector<const char *> &argvRem = args.GetRemainingArgs();
for (size_t i = 0; i < argvRem.size(); ++i) {
if (!strcmp(argvRem[i], "-k")) {
std::stringstream ss(argvRem[++i]);
std::string kernel;
while(std::getline(ss, kernel, ',')) {
kernels.push_back(kernel);
}
} else if (!strcmp(argv[i], "-t")) {
tessLevel = atoi(argv[++i]);
} else if (!strcmp(argv[i], "-w")) {
} else if (!strcmp(argvRem[i], "-t")) {
tessLevel = atoi(argvRem[++i]);
} else if (!strcmp(argvRem[i], "-w")) {
writeToFile = true;
prefix = argv[++i];
} else if (!strcmp(argv[i], "-s")) {
width = atoi(argv[++i]);
height = atoi(argv[++i]);
} else if (!strcmp(argv[i], "-d")) {
displayMode = argv[++i];
prefix = argvRem[++i];
} else if (!strcmp(argvRem[i], "-s")) {
width = atoi(argvRem[++i]);
height = atoi(argvRem[++i]);
} else if (!strcmp(argvRem[i], "-d")) {
displayMode = argvRem[++i];
} else {
args.PrintUnrecognizedArgWarning(argvRem[i]);
usage(argv[0]);
return 1;
}

View File

@ -37,6 +37,8 @@ GLFWmonitor* g_primary=0;
OpenSubdiv::Osd::GLMeshInterface *g_mesh;
#include "../../regression/common/far_utils.h"
#include "../common/argOptions.h"
#include "../common/viewerArgsUtils.h"
#include "../common/stopwatch.h"
#include "../common/simple_math.h"
#include "../common/glHud.h"
@ -64,6 +66,8 @@ float g_rotate[2] = {0, 0},
g_center[3] = {0, 0, 0},
g_size = 0;
bool g_yup = false;
int g_prev_x = 0,
g_prev_y = 0;
@ -114,16 +118,6 @@ GLuint g_ptexPages = 0,
int g_pageSize = 512;
struct SimpleShape {
std::string name;
Scheme scheme;
std::string data;
SimpleShape() { }
SimpleShape( std::string const & idata, char const * iname, Scheme ischeme )
: name(iname), scheme(ischeme), data(idata) { }
};
int g_currentShape = 0;
#define NUM_FPS_TIME_SAMPLES 6
@ -628,7 +622,9 @@ display() {
translate(g_transformData.ModelViewMatrix, -g_pan[0], -g_pan[1], -g_dolly);
rotate(g_transformData.ModelViewMatrix, g_rotate[1], 1, 0, 0);
rotate(g_transformData.ModelViewMatrix, g_rotate[0], 0, 1, 0);
rotate(g_transformData.ModelViewMatrix, -90, 1, 0, 0);
if (!g_yup) {
rotate(g_transformData.ModelViewMatrix, -90, 1, 0, 0);
}
translate(g_transformData.ModelViewMatrix,
-g_center[0], -g_center[1], -g_center[2]);
perspective(g_transformData.ProjectionMatrix,
@ -1082,41 +1078,18 @@ callbackErrorGLFW(int error, const char* description) {
int main(int argc, char ** argv) {
bool fullscreen = false;
Scheme defaultScheme = kCatmark;
std::vector<char const *> objfiles;
ArgOptions args;
for (int i = 1; i < argc; ++i) {
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")) {
fullscreen = true;
} 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]);
}
}
args.Parse(argc, argv);
args.PrintUnrecognizedArgsWarnings();
g_yup = args.GetYUp();
g_level = args.GetLevel();
ViewerArgsUtils::PopulateShapes(args, &g_defaultShapes);
initShapes();
OpenSubdiv::Far::SetErrorCallback(callbackError);
glfwSetErrorCallback(callbackErrorGLFW);
@ -1129,7 +1102,7 @@ int main(int argc, char ** argv) {
GLUtils::SetMinimumGLVersion();
if (fullscreen) {
if (args.GetFullScreen()) {
g_primary = glfwGetPrimaryMonitor();
@ -1151,7 +1124,7 @@ int main(int argc, char ** argv) {
}
if (! (g_window=glfwCreateWindow(g_width, g_height, windowTitle,
fullscreen && g_primary ? g_primary : NULL, NULL))) {
args.GetFullScreen() && g_primary ? g_primary : NULL, NULL))) {
printf("Failed to open window.\n");
glfwTerminate();
return 1;

View File

@ -93,6 +93,8 @@ OpenSubdiv::Osd::GLMeshInterface *g_mesh;
#include "PtexUtils.h"
#include "../../regression/common/far_utils.h"
#include "../common/argOptions.h"
#include "../common/objAnim.h"
#include "../common/stopwatch.h"
#include "../common/simple_math.h"
#include "../common/glControlMeshDisplay.h"
@ -244,7 +246,7 @@ float g_animTime = 0;
std::vector<float> g_positions,
g_normals;
std::vector<std::vector<float> > g_animPositions;
ObjAnim const * g_objAnim = 0;
GLuint g_queries[2] = {0, 0};
GLuint g_vao = 0;
@ -346,23 +348,13 @@ updateGeom() {
int nverts = (int)g_positions.size() / 3;
if (g_moveScale && g_adaptive && !g_animPositions.empty()) {
// baked animation only works with adaptive for now
// (since non-adaptive requires normals)
int nkey = (int)g_animPositions.size();
const float fps = 24.0f;
float p = fmodf(g_animTime * fps, (float)nkey);
int key = (int)p;
float b = p - key;
if (g_moveScale && g_adaptive && g_objAnim) {
std::vector<float> vertex;
vertex.reserve(nverts*3);
for (int i = 0; i < nverts*3; ++i) {
float p0 = g_animPositions[key][i];
float p1 = g_animPositions[(key+1)%nkey][i];
vertex.push_back(p0*(1-b) + p1*b);
}
g_objAnim->InterpolatePositions(g_animTime, &vertex[0], 3);
g_mesh->UpdateVertexBuffer(&vertex[0], 0, nverts);
} else {
@ -1117,8 +1109,9 @@ updateConstantUniformBlock() {
translate(constantData.ModelViewMatrix, -g_pan[0], -g_pan[1], -g_dolly);
rotate(constantData.ModelViewMatrix, g_rotate[1], 1, 0, 0);
rotate(constantData.ModelViewMatrix, g_rotate[0], 0, 1, 0);
if (g_yup)
if (!g_yup) {
rotate(constantData.ModelViewMatrix, -90, 1, 0, 0);
}
translate(constantData.ModelViewMatrix, -g_center[0], -g_center[1], -g_center[2]);
perspective(constantData.ProjectionMatrix, 45.0f, (float)aspect, g_size*0.001f,
g_size+g_dolly);
@ -1708,7 +1701,7 @@ void usage(const char *program) {
printf(" -d <diffseEnvMap.hdr> : diffuse environment map for IBL\n");
printf(" -e <specularEnvMap.hdr> : specular environment map for IBL\n");
printf(" -s <shaderfile.glsl> : custom shader file\n");
printf(" -y : Y-up model\n");
printf(" -yup : Y-up model\n");
printf(" -m level : max mipmap level (default=10)\n");
printf(" -x <ptex limit MB> : ptex target memory size\n");
printf(" --disp <scale> : Displacement scale\n");
@ -1730,55 +1723,53 @@ callbackErrorGLFW(int error, const char* description) {
//------------------------------------------------------------------------------
int main(int argc, char ** argv) {
std::vector<std::string> animobjs;
ArgOptions args;
args.Parse(argc, argv);
const std::vector<const char *> &animobjs = args.GetObjFiles();
bool fullscreen = args.GetFullScreen();
g_yup = args.GetYUp();
g_adaptive = args.GetAdaptive();
g_level = args.GetLevel();
g_repeatCount = args.GetRepeatCount();
// Retrieve and parse remaining args:
const std::vector<const char *> &argvRem = args.GetRemainingArgs();
const char *diffuseEnvironmentMap = NULL, *specularEnvironmentMap = NULL;
const char *colorFilename = NULL, *displacementFilename = NULL,
*occlusionFilename = NULL, *specularFilename = NULL;
int memLimit = 0, colorMem = 0, displacementMem = 0,
occlusionMem = 0, specularMem = 0;
bool fullscreen = false;
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"))
g_repeatCount = atoi(argv[++i]);
else if (!strcmp(argv[i], "-d"))
diffuseEnvironmentMap = argv[++i];
else if (!strcmp(argv[i], "-e"))
specularEnvironmentMap = argv[++i];
else if (!strcmp(argv[i], "-s"))
g_shaderFilename = argv[++i];
else if (!strcmp(argv[i], "-f"))
fullscreen = true;
else if (!strcmp(argv[i], "-y"))
g_yup = true;
else if (!strcmp(argv[i], "-m"))
g_maxMipmapLevels = atoi(argv[++i]);
else if (!strcmp(argv[i], "-x"))
memLimit = atoi(argv[++i]);
else if (!strcmp(argv[i], "--disp"))
g_displacementScale = (float)atof(argv[++i]);
for (size_t i = 0; i < argvRem.size(); ++i) {
if (!strcmp(argvRem[i], "-d"))
diffuseEnvironmentMap = argvRem[++i];
else if (!strcmp(argvRem[i], "-e"))
specularEnvironmentMap = argvRem[++i];
else if (!strcmp(argvRem[i], "-s"))
g_shaderFilename = argvRem[++i];
else if (!strcmp(argvRem[i], "-m"))
g_maxMipmapLevels = atoi(argvRem[++i]);
else if (!strcmp(argvRem[i], "-x"))
memLimit = atoi(argvRem[++i]);
else if (!strcmp(argvRem[i], "--disp"))
g_displacementScale = (float)atof(argvRem[++i]);
else if (colorFilename == NULL) {
colorFilename = argv[i];
colorFilename = argvRem[i];
colorMem = memLimit;
} else if (displacementFilename == NULL) {
displacementFilename = argv[i];
displacementFilename = argvRem[i];
displacementMem = memLimit;
g_displacement = DISPLACEMENT_BILINEAR;
g_normal = NORMAL_BIQUADRATIC;
} else if (occlusionFilename == NULL) {
occlusionFilename = argv[i];
occlusionFilename = argvRem[i];
occlusionMem = memLimit;
g_occlusion = 1;
} else if (specularFilename == NULL) {
specularFilename = argv[i];
specularFilename = argvRem[i];
specularMem = memLimit;
g_specular = 1;
}
@ -2034,30 +2025,21 @@ int main(int argc, char ** argv) {
// load animation obj sequences (optional)
if (!animobjs.empty()) {
for (int i = 0; i < (int)animobjs.size(); ++i) {
std::ifstream ifs(animobjs[i].c_str());
if (ifs) {
std::stringstream ss;
ss << ifs.rdbuf();
ifs.close();
printf("Reading %s\r", animobjs[i].c_str());
std::string str = ss.str();
Shape *shape = Shape::parseObj(str.c_str(), kCatmark);
if (shape->verts.size() != g_positions.size()) {
printf("Error: vertex count doesn't match.\n");
goto error;
}
g_animPositions.push_back(shape->verts);
delete shape;
} else {
printf("Error in reading %s\n", animobjs[i].c_str());
goto error;
}
// The Scheme passed here should ideally match the Ptex geometry (not the
// defaults from the command line), but only the vertex positions of the
// ObjAnim are used, so it is effectively ignored
g_objAnim = ObjAnim::Create(animobjs, kCatmark);
if (g_objAnim == 0) {
printf("Error in reading animation Obj file sequence\n");
goto error;
}
printf("\n");
const Shape *animShape = g_objAnim->GetShape();
if (animShape->verts.size() != g_positions.size()) {
printf("Error in animation sequence, does not match ptex vertex count\n");
goto error;
}
glBindBuffer(GL_ARRAY_BUFFER, 0);
}

View File

@ -71,6 +71,7 @@ GLFWmonitor* g_primary=0;
#include "../../regression/common/far_utils.h"
#include "init_shapes.h"
#include "../common/argOptions.h"
#include "../common/stopwatch.h"
#include "../common/simple_math.h"
#include "../common/glHud.h"
@ -1172,16 +1173,14 @@ callbackErrorGLFW(int error, const char* description) {
int main(int argc, char ** argv) {
std::string str;
for (int i = 1; i < argc; ++i) {
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;
}
}
ArgOptions args;
args.Parse(argc, argv);
args.PrintUnrecognizedArgsWarnings();
g_options.adaptive = args.GetAdaptive();
g_level = args.GetLevel();
Far::SetErrorCallback(callbackError);
glfwSetErrorCallback(callbackErrorGLFW);

View File

@ -29,6 +29,8 @@ GLFWwindow* g_window=0;
GLFWmonitor* g_primary=0;
#include "../../regression/common/far_utils.h"
#include "../common/argOptions.h"
#include "../common/viewerArgsUtils.h"
#include "../common/stopwatch.h"
#include "../common/simple_math.h"
#include "../common/glHud.h"
@ -111,13 +113,12 @@ int g_kernel = kCPU,
int g_running = 1,
g_width = 1024,
g_height = 1024,
g_fullscreen = 0,
g_prev_x = 0,
g_prev_y = 0,
g_mbutton[3] = {0, 0, 0},
g_frame=0,
g_freeze=0,
g_repeatCount;
g_repeatCount=0;
bool g_adaptive=true,
g_infSharpPatch=false;
@ -129,6 +130,8 @@ float g_rotate[2] = {0, 0},
g_size = 0,
g_moveScale = 0.0f;
bool g_yup = false;
struct Transform {
float ModelViewMatrix[16];
float ProjectionMatrix[16];
@ -730,7 +733,9 @@ display() {
translate(g_transformData.ModelViewMatrix, -g_pan[0], -g_pan[1], -g_dolly);
rotate(g_transformData.ModelViewMatrix, g_rotate[1], 1, 0, 0);
rotate(g_transformData.ModelViewMatrix, g_rotate[0], 0, 1, 0);
rotate(g_transformData.ModelViewMatrix, -90, 1, 0, 0);
if (!g_yup) {
rotate(g_transformData.ModelViewMatrix, -90, 1, 0, 0);
}
translate(g_transformData.ModelViewMatrix,
-g_center[0], -g_center[1], -g_center[2]);
perspective(g_transformData.ProjectionMatrix,
@ -1059,43 +1064,17 @@ callbackErrorGLFW(int error, const char* description) {
//------------------------------------------------------------------------------
int main(int argc, char **argv) {
bool fullscreen = false;
Scheme defaultScheme = kCatmark;
std::vector<char const *> objfiles;
ArgOptions args;
for (int i = 1; i < argc; ++i) {
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")) {
g_isolationLevel = atoi(argv[++i]);
} else if (!strcmp(argv[i], "-f")) {
fullscreen = true;
} else if (!strcmp(argv[i], "-bilinear")) {
defaultScheme = kBilinear;
} else if (!strcmp(argv[i], "-catmark")) {
defaultScheme = kCatmark;
} else if (!strcmp(argv[i], "-loop")) {
defaultScheme = kLoop;
} 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]);
}
}
args.Parse(argc, argv);
args.PrintUnrecognizedArgsWarnings();
g_yup = args.GetYUp();
g_adaptive = args.GetAdaptive();
g_isolationLevel = args.GetLevel();
g_repeatCount = args.GetRepeatCount();
ViewerArgsUtils::PopulateShapes(args, &g_defaultShapes);
initShapes();
@ -1109,7 +1088,7 @@ int main(int argc, char **argv) {
GLUtils::SetMinimumGLVersion();
if (fullscreen) {
if (args.GetFullScreen()) {
g_primary = glfwGetPrimaryMonitor();
@ -1131,7 +1110,7 @@ int main(int argc, char **argv) {
}
if (! (g_window=glfwCreateWindow(g_width, g_height, windowTitle,
fullscreen && g_primary ? g_primary : NULL, NULL))) {
args.GetFullScreen() && g_primary ? g_primary : NULL, NULL))) {
std::cerr << "Failed to create OpenGL context.\n";
glfwTerminate();
return 1;