2014-09-05 22:07:46 +00:00
|
|
|
//
|
|
|
|
// Copyright 2013 Pixar
|
|
|
|
//
|
|
|
|
// Licensed under the Apache License, Version 2.0 (the "Apache License")
|
|
|
|
// with the following modification; you may not use this file except in
|
|
|
|
// compliance with the Apache License and the following modification to it:
|
|
|
|
// Section 6. Trademarks. is deleted and replaced with:
|
|
|
|
//
|
|
|
|
// 6. Trademarks. This License does not grant permission to use the trade
|
|
|
|
// names, trademarks, service marks, or product names of the Licensor
|
|
|
|
// and its affiliates, except as required to comply with Section 4(c) of
|
|
|
|
// the License and to reproduce the content of the NOTICE file.
|
|
|
|
//
|
|
|
|
// You may obtain a copy of the Apache License at
|
|
|
|
//
|
|
|
|
// http://www.apache.org/licenses/LICENSE-2.0
|
|
|
|
//
|
|
|
|
// Unless required by applicable law or agreed to in writing, software
|
|
|
|
// distributed under the Apache License with the above modification is
|
|
|
|
// distributed on an "AS IS" BASIS, WITHOUT WARRANTIES OR CONDITIONS OF ANY
|
|
|
|
// KIND, either express or implied. See the Apache License for the specific
|
|
|
|
// language governing permissions and limitations under the Apache License.
|
|
|
|
//
|
|
|
|
|
|
|
|
#if defined(__APPLE__)
|
|
|
|
#if defined(OSD_USES_GLEW)
|
|
|
|
#include <GL/glew.h>
|
|
|
|
#else
|
|
|
|
#include <OpenGL/gl3.h>
|
|
|
|
#endif
|
|
|
|
#define GLFW_INCLUDE_GL3
|
|
|
|
#define GLFW_NO_GLU
|
|
|
|
#else
|
|
|
|
#include <stdlib.h>
|
|
|
|
#include <GL/glew.h>
|
|
|
|
#if defined(WIN32)
|
|
|
|
#include <GL/wglew.h>
|
|
|
|
#endif
|
|
|
|
#endif
|
|
|
|
|
|
|
|
#include <GLFW/glfw3.h>
|
|
|
|
GLFWwindow* g_window=0;
|
|
|
|
GLFWmonitor* g_primary=0;
|
|
|
|
|
2015-05-19 02:46:22 +00:00
|
|
|
#if _MSC_VER
|
|
|
|
#define snprintf _snprintf
|
2014-09-05 22:07:46 +00:00
|
|
|
#endif
|
|
|
|
|
|
|
|
#include <osd/cpuGLVertexBuffer.h>
|
|
|
|
|
2015-05-22 18:50:01 +00:00
|
|
|
#include <far/patchTableFactory.h>
|
|
|
|
#include <far/stencilTable.h>
|
|
|
|
#include <far/stencilTableFactory.h>
|
2015-05-24 01:56:36 +00:00
|
|
|
#include <far/primvarRefiner.h>
|
2014-09-05 22:07:46 +00:00
|
|
|
|
2015-05-29 00:32:00 +00:00
|
|
|
#include "../../regression/common/vtr_utils.h"
|
2014-09-05 22:07:46 +00:00
|
|
|
#include "../common/stopwatch.h"
|
|
|
|
#include "../common/simple_math.h"
|
2015-05-19 01:04:38 +00:00
|
|
|
#include "../common/glUtils.h"
|
|
|
|
#include "../common/glHud.h"
|
2014-09-05 22:07:46 +00:00
|
|
|
|
|
|
|
#include "init_shapes.h"
|
|
|
|
#include "gl_mesh.h"
|
|
|
|
#include "gl_fontutils.h"
|
|
|
|
|
|
|
|
#include <typeinfo>
|
|
|
|
#include <cfloat>
|
|
|
|
#include <vector>
|
|
|
|
#include <set>
|
|
|
|
#include <fstream>
|
|
|
|
#include <sstream>
|
|
|
|
|
|
|
|
//------------------------------------------------------------------------------
|
2014-11-18 18:57:19 +00:00
|
|
|
int g_level = 3,
|
|
|
|
g_currentShape = 7;
|
2014-09-05 22:07:46 +00:00
|
|
|
|
|
|
|
enum HudCheckBox { kHUD_CB_DISPLAY_CAGE_EDGES,
|
|
|
|
kHUD_CB_DISPLAY_CAGE_VERTS,
|
|
|
|
kHUD_CB_ANIMATE_VERTICES,
|
|
|
|
kHUD_CB_DISPLAY_PATCH_COLOR };
|
|
|
|
|
2015-05-20 02:17:50 +00:00
|
|
|
enum DrawMode { kDRAW_VERTICES,
|
2014-09-05 22:07:46 +00:00
|
|
|
kDRAW_WIREFRAME,
|
|
|
|
kDRAW_FACES };
|
|
|
|
|
|
|
|
|
|
|
|
int g_frame = 0,
|
|
|
|
g_repeatCount = 0;
|
|
|
|
|
|
|
|
// GUI variables
|
|
|
|
int g_fullscreen = 0,
|
|
|
|
g_mbutton[3] = {0, 0, 0},
|
|
|
|
g_running = 1;
|
|
|
|
|
2015-02-26 21:57:47 +00:00
|
|
|
int g_displayPatchColor = 1,
|
|
|
|
g_drawCageEdges = 1,
|
|
|
|
g_drawCageVertices = 0,
|
2015-05-20 02:17:50 +00:00
|
|
|
g_FarDrawMode = kDRAW_FACES,
|
2015-05-19 02:46:22 +00:00
|
|
|
g_FarDrawVertIDs = false,
|
|
|
|
g_FarDrawEdgeIDs = false,
|
|
|
|
g_FarDrawFaceIDs = false,
|
|
|
|
g_FarDrawPtexIDs = false,
|
|
|
|
g_FarDrawEdgeSharpness = false,
|
|
|
|
g_FarDrawGregogyBasis = false,
|
|
|
|
g_FarDrawFVarVerts = false,
|
|
|
|
g_FarDrawFVarPatches = false,
|
|
|
|
g_FarDrawFVarPatchTess = 5,
|
2015-02-26 21:57:47 +00:00
|
|
|
g_numPatches = 0,
|
|
|
|
g_maxValence = 0,
|
|
|
|
g_currentPatch = 0,
|
2015-04-18 00:36:55 +00:00
|
|
|
g_Adaptive = true,
|
|
|
|
g_useStencils = true;
|
2015-02-26 21:57:47 +00:00
|
|
|
|
|
|
|
typedef OpenSubdiv::Sdc::Options SdcOptions;
|
|
|
|
|
|
|
|
SdcOptions::FVarLinearInterpolation g_fvarInterpolation =
|
|
|
|
SdcOptions::FVAR_LINEAR_ALL;
|
2014-09-05 22:07:46 +00:00
|
|
|
|
2014-11-25 20:41:19 +00:00
|
|
|
OpenSubdiv::Far::PatchDescriptor g_currentPatchDesc;
|
2015-02-26 21:57:47 +00:00
|
|
|
OpenSubdiv::Far::PatchDescriptor::Type g_currentFVarPatchType;
|
2014-09-05 22:07:46 +00:00
|
|
|
|
|
|
|
float g_rotate[2] = {0, 0},
|
|
|
|
g_dolly = 5,
|
|
|
|
g_pan[2] = {0, 0},
|
|
|
|
g_center[3] = {0, 0, 0},
|
|
|
|
g_size = 0;
|
|
|
|
|
|
|
|
int g_prev_x = 0,
|
|
|
|
g_prev_y = 0;
|
|
|
|
|
|
|
|
int g_width = 1024,
|
|
|
|
g_height = 1024;
|
|
|
|
|
|
|
|
GLhud g_hud;
|
|
|
|
|
|
|
|
GLFont * g_font=0;
|
|
|
|
|
|
|
|
// performance
|
|
|
|
float g_cpuTime = 0;
|
|
|
|
float g_gpuTime = 0;
|
|
|
|
Stopwatch g_fpsTimer;
|
|
|
|
|
|
|
|
GLuint g_queries[2] = {0, 0};
|
|
|
|
|
|
|
|
GLuint g_transformUB = 0,
|
|
|
|
g_lightingUB = 0;
|
|
|
|
|
|
|
|
struct Transform {
|
|
|
|
float ModelViewMatrix[16];
|
|
|
|
float ProjectionMatrix[16];
|
|
|
|
float ModelViewProjectionMatrix[16];
|
|
|
|
} g_transformData;
|
|
|
|
|
|
|
|
static GLMesh g_base_glmesh,
|
2015-05-19 02:46:22 +00:00
|
|
|
g_far_glmesh;
|
2014-09-05 22:07:46 +00:00
|
|
|
|
|
|
|
|
|
|
|
//------------------------------------------------------------------------------
|
|
|
|
|
|
|
|
typedef OpenSubdiv::Far::TopologyRefiner FTopologyRefiner;
|
|
|
|
typedef OpenSubdiv::Far::TopologyRefinerFactory<Shape> FTopologyRefinerFactory;
|
|
|
|
|
|
|
|
|
|
|
|
//------------------------------------------------------------------------------
|
2015-05-20 02:17:50 +00:00
|
|
|
// Vertex class implementation
|
|
|
|
struct Vertex {
|
2014-09-05 22:07:46 +00:00
|
|
|
|
2015-05-20 02:17:50 +00:00
|
|
|
Vertex() { /* _pos[0]=_pos[1]=_pos[2]=0.0f; */ }
|
2014-09-05 22:07:46 +00:00
|
|
|
|
2015-05-20 02:17:50 +00:00
|
|
|
Vertex( int /*i*/ ) { }
|
2014-09-05 22:07:46 +00:00
|
|
|
|
2015-05-20 02:17:50 +00:00
|
|
|
Vertex( float x, float y, float z ) { _pos[0]=x; _pos[1]=y; _pos[2]=z; }
|
2014-09-05 22:07:46 +00:00
|
|
|
|
2015-05-20 02:17:50 +00:00
|
|
|
Vertex( const Vertex & src ) { _pos[0]=src._pos[0]; _pos[1]=src._pos[1]; _pos[2]=src._pos[2]; }
|
2014-09-05 22:07:46 +00:00
|
|
|
|
2015-05-20 02:17:50 +00:00
|
|
|
~Vertex( ) { }
|
2014-09-05 22:07:46 +00:00
|
|
|
|
2015-05-20 02:17:50 +00:00
|
|
|
void AddWithWeight(Vertex const & src, float weight) {
|
|
|
|
_pos[0]+=weight*src._pos[0];
|
|
|
|
_pos[1]+=weight*src._pos[1];
|
|
|
|
_pos[2]+=weight*src._pos[2];
|
2014-09-05 22:07:46 +00:00
|
|
|
}
|
|
|
|
|
2015-05-20 02:17:50 +00:00
|
|
|
void AddWithWeight(Vertex const & src, float weight, float /* ds */, float /* dt */) {
|
|
|
|
_pos[0]+=weight*src._pos[0];
|
|
|
|
_pos[1]+=weight*src._pos[1];
|
|
|
|
_pos[2]+=weight*src._pos[2];
|
2014-09-05 22:07:46 +00:00
|
|
|
}
|
|
|
|
|
2015-05-20 02:17:50 +00:00
|
|
|
void AddVaryingWithWeight(Vertex const & , float) { }
|
2014-09-05 22:07:46 +00:00
|
|
|
|
2015-05-20 02:17:50 +00:00
|
|
|
void Clear( void * =0 ) { _pos[0]=_pos[1]=_pos[2]=0.0f; }
|
2014-09-05 22:07:46 +00:00
|
|
|
|
2015-05-20 02:17:50 +00:00
|
|
|
void SetPosition(float x, float y, float z) { _pos[0]=x; _pos[1]=y; _pos[2]=z; }
|
2014-09-05 22:07:46 +00:00
|
|
|
|
2015-05-20 02:17:50 +00:00
|
|
|
float const * GetPos() const { return _pos; }
|
2014-09-05 22:07:46 +00:00
|
|
|
|
2015-05-20 02:17:50 +00:00
|
|
|
private:
|
|
|
|
float _pos[3];
|
|
|
|
};
|
2014-09-05 22:07:46 +00:00
|
|
|
|
|
|
|
//------------------------------------------------------------------------------
|
2015-05-19 02:46:22 +00:00
|
|
|
// generate display IDs for Far verts
|
2014-09-05 22:07:46 +00:00
|
|
|
static void
|
|
|
|
createVertNumbers(OpenSubdiv::Far::TopologyRefiner const & refiner,
|
|
|
|
std::vector<Vertex> const & vertexBuffer) {
|
|
|
|
|
|
|
|
int maxlevel = refiner.GetMaxLevel(),
|
|
|
|
firstvert = 0;
|
|
|
|
|
|
|
|
if (refiner.IsUniform()) {
|
|
|
|
for (int i=0; i<maxlevel; ++i) {
|
2015-05-22 02:52:25 +00:00
|
|
|
firstvert += refiner.GetLevel(i).GetNumVertices();
|
2014-09-05 22:07:46 +00:00
|
|
|
}
|
|
|
|
}
|
|
|
|
|
|
|
|
static char buf[16];
|
|
|
|
if (refiner.IsUniform()) {
|
|
|
|
for (int i=firstvert; i<(int)vertexBuffer.size(); ++i) {
|
|
|
|
snprintf(buf, 16, "%d", i);
|
|
|
|
g_font->Print3D(vertexBuffer[i].GetPos(), buf, 1);
|
|
|
|
}
|
|
|
|
} else {
|
|
|
|
|
|
|
|
for (int level=0, vert=0; level<=refiner.GetMaxLevel(); ++level) {
|
2015-05-22 02:52:25 +00:00
|
|
|
for (int i=0; i<refiner.GetLevel(level).GetNumVertices(); ++i, ++vert) {
|
2014-09-05 22:07:46 +00:00
|
|
|
snprintf(buf, 16, "%d", i);
|
|
|
|
g_font->Print3D(vertexBuffer[vert].GetPos(), buf, 1);
|
|
|
|
}
|
|
|
|
}
|
|
|
|
}
|
|
|
|
}
|
|
|
|
|
|
|
|
//------------------------------------------------------------------------------
|
2015-05-19 02:46:22 +00:00
|
|
|
// generate display IDs for Far edges
|
2014-09-05 22:07:46 +00:00
|
|
|
static void
|
|
|
|
createEdgeNumbers(OpenSubdiv::Far::TopologyRefiner const & refiner,
|
|
|
|
std::vector<Vertex> const & vertexBuffer, bool ids=false, bool sharpness=false) {
|
|
|
|
|
|
|
|
if (ids or sharpness) {
|
|
|
|
|
|
|
|
int maxlevel = refiner.GetMaxLevel(),
|
|
|
|
firstvert = 0;
|
|
|
|
|
|
|
|
for (int i=0; i<maxlevel; ++i) {
|
2015-05-22 02:52:25 +00:00
|
|
|
firstvert += refiner.GetLevel(i).GetNumVertices();
|
2014-09-05 22:07:46 +00:00
|
|
|
}
|
|
|
|
|
2015-05-22 02:52:25 +00:00
|
|
|
OpenSubdiv::Far::TopologyLevel const & refLastLevel = refiner.GetLevel(maxlevel);
|
|
|
|
|
2014-09-05 22:07:46 +00:00
|
|
|
static char buf[16];
|
2015-05-22 02:52:25 +00:00
|
|
|
for (int i=0; i<refLastLevel.GetNumEdges(); ++i) {
|
2014-09-05 22:07:46 +00:00
|
|
|
|
|
|
|
Vertex center(0.0f, 0.0f, 0.0f);
|
|
|
|
|
2015-05-22 02:52:25 +00:00
|
|
|
OpenSubdiv::Far::ConstIndexArray const verts = refLastLevel.GetEdgeVertices(i);
|
2014-09-05 22:07:46 +00:00
|
|
|
assert(verts.size()==2);
|
|
|
|
|
|
|
|
center.AddWithWeight(vertexBuffer[firstvert+verts[0]], 0.5f);
|
|
|
|
center.AddWithWeight(vertexBuffer[firstvert+verts[1]], 0.5f);
|
|
|
|
|
|
|
|
if (ids) {
|
|
|
|
snprintf(buf, 16, "%d", i);
|
|
|
|
g_font->Print3D(center.GetPos(), buf, 3);
|
|
|
|
}
|
|
|
|
|
|
|
|
if (sharpness) {
|
2015-05-22 02:52:25 +00:00
|
|
|
float sharpness = refLastLevel.GetEdgeSharpness(i);
|
2014-09-05 22:07:46 +00:00
|
|
|
if (sharpness>0.0f) {
|
|
|
|
snprintf(buf, 16, "%g", sharpness);
|
|
|
|
g_font->Print3D(center.GetPos(), buf, std::min(8,(int)sharpness+4));
|
|
|
|
}
|
|
|
|
}
|
|
|
|
}
|
|
|
|
}
|
|
|
|
}
|
|
|
|
|
|
|
|
//------------------------------------------------------------------------------
|
2015-05-19 02:46:22 +00:00
|
|
|
// generate display IDs for Far faces
|
2014-09-05 22:07:46 +00:00
|
|
|
static void
|
|
|
|
createFaceNumbers(OpenSubdiv::Far::TopologyRefiner const & refiner,
|
|
|
|
std::vector<Vertex> const & vertexBuffer) {
|
|
|
|
|
|
|
|
static char buf[16];
|
|
|
|
|
|
|
|
if (refiner.IsUniform()) {
|
|
|
|
int maxlevel = refiner.GetMaxLevel(),
|
|
|
|
firstvert = 0;
|
|
|
|
|
|
|
|
for (int i=0; i<maxlevel; ++i) {
|
2015-05-22 02:52:25 +00:00
|
|
|
firstvert += refiner.GetLevel(i).GetNumVertices();
|
2014-09-05 22:07:46 +00:00
|
|
|
}
|
|
|
|
|
2015-05-22 02:52:25 +00:00
|
|
|
OpenSubdiv::Far::TopologyLevel const & refLastLevel = refiner.GetLevel(maxlevel);
|
|
|
|
|
|
|
|
for (int face=0; face<refLastLevel.GetNumFaces(); ++face) {
|
2014-09-05 22:07:46 +00:00
|
|
|
|
|
|
|
Vertex center(0.0f, 0.0f, 0.0f);
|
|
|
|
|
2015-05-22 02:52:25 +00:00
|
|
|
OpenSubdiv::Far::ConstIndexArray const verts = refLastLevel.GetFaceVertices(face);
|
2014-09-05 22:07:46 +00:00
|
|
|
|
|
|
|
float weight = 1.0f / (float)verts.size();
|
|
|
|
|
|
|
|
for (int vert=0; vert<verts.size(); ++vert) {
|
|
|
|
center.AddWithWeight(vertexBuffer[firstvert+verts[vert]], weight);
|
|
|
|
}
|
|
|
|
|
|
|
|
snprintf(buf, 16, "%d", face);
|
|
|
|
g_font->Print3D(center.GetPos(), buf, 2);
|
|
|
|
}
|
|
|
|
} else {
|
|
|
|
int maxlevel = refiner.GetMaxLevel(),
|
2015-05-22 02:52:25 +00:00
|
|
|
// patch = refiner.GetLevel(0).GetNumFaces(),
|
|
|
|
firstvert = refiner.GetLevel(0).GetNumVertices();
|
2014-09-05 22:07:46 +00:00
|
|
|
|
|
|
|
for (int level=1; level<=maxlevel; ++level) {
|
|
|
|
|
2015-05-22 02:52:25 +00:00
|
|
|
OpenSubdiv::Far::TopologyLevel const & refLevel = refiner.GetLevel(level);
|
|
|
|
|
|
|
|
int nfaces = refLevel.GetNumFaces();
|
2014-09-05 22:07:46 +00:00
|
|
|
|
|
|
|
for (int face=0; face<nfaces; ++face /*, ++patch */) {
|
|
|
|
|
|
|
|
Vertex center(0.0f, 0.0f, 0.0f);
|
|
|
|
|
2015-05-22 02:52:25 +00:00
|
|
|
OpenSubdiv::Far::ConstIndexArray const verts = refLevel.GetFaceVertices(face);
|
2014-09-05 22:07:46 +00:00
|
|
|
|
|
|
|
float weight = 1.0f / (float)verts.size();
|
|
|
|
|
|
|
|
for (int vert=0; vert<verts.size(); ++vert) {
|
|
|
|
center.AddWithWeight(vertexBuffer[firstvert+verts[vert]], weight);
|
|
|
|
}
|
|
|
|
snprintf(buf, 16, "%d", face);
|
|
|
|
g_font->Print3D(center.GetPos(), buf, 2);
|
|
|
|
}
|
2015-05-22 02:52:25 +00:00
|
|
|
firstvert+=refLevel.GetNumVertices();
|
2014-09-05 22:07:46 +00:00
|
|
|
}
|
|
|
|
}
|
|
|
|
}
|
|
|
|
|
|
|
|
//------------------------------------------------------------------------------
|
2015-05-19 02:46:22 +00:00
|
|
|
// generate display vert IDs for the selected Far patch
|
2014-09-05 22:07:46 +00:00
|
|
|
static void
|
2015-05-22 18:50:01 +00:00
|
|
|
createPatchNumbers(OpenSubdiv::Far::PatchTable const & patchTable,
|
2014-09-05 22:07:46 +00:00
|
|
|
std::vector<Vertex> const & vertexBuffer) {
|
|
|
|
|
|
|
|
if (not g_currentPatch)
|
|
|
|
return;
|
|
|
|
|
2014-11-25 20:41:19 +00:00
|
|
|
int patchID = g_currentPatch-1,
|
|
|
|
patchArray = -1;
|
2014-09-05 22:07:46 +00:00
|
|
|
|
|
|
|
// Find PatchArray containing our patch
|
2015-05-22 18:50:01 +00:00
|
|
|
for (int array=0; array<(int)patchTable.GetNumPatchArrays(); ++array) {
|
|
|
|
int npatches = patchTable.GetNumPatches(array);
|
2014-09-05 22:07:46 +00:00
|
|
|
if (patchID >= npatches) {
|
|
|
|
patchID -= npatches;
|
|
|
|
} else {
|
2014-11-25 20:41:19 +00:00
|
|
|
patchArray = array;
|
2014-09-05 22:07:46 +00:00
|
|
|
break;
|
|
|
|
}
|
|
|
|
}
|
2014-11-25 20:41:19 +00:00
|
|
|
if (patchArray==-1) {
|
2014-09-05 22:07:46 +00:00
|
|
|
return;
|
|
|
|
}
|
|
|
|
|
2015-05-22 18:50:01 +00:00
|
|
|
g_currentPatchDesc = patchTable.GetPatchArrayDescriptor(patchArray);
|
2014-09-05 22:07:46 +00:00
|
|
|
|
2014-12-15 18:23:13 +00:00
|
|
|
OpenSubdiv::Far::ConstIndexArray const cvs =
|
2015-05-22 18:50:01 +00:00
|
|
|
patchTable.GetPatchVertices(patchArray, patchID);
|
2014-09-05 22:07:46 +00:00
|
|
|
|
|
|
|
static char buf[16];
|
2014-11-25 20:41:19 +00:00
|
|
|
for (int i=0; i<cvs.size(); ++i) {
|
2014-09-05 22:07:46 +00:00
|
|
|
snprintf(buf, 16, "%d", i);
|
|
|
|
g_font->Print3D(vertexBuffer[cvs[i]].GetPos(), buf, 1);
|
|
|
|
}
|
|
|
|
}
|
|
|
|
|
2015-02-26 21:57:47 +00:00
|
|
|
//------------------------------------------------------------------------------
|
2015-05-19 02:46:22 +00:00
|
|
|
// generate display vert IDs for the selected Far FVar patch
|
2015-02-26 21:57:47 +00:00
|
|
|
static void
|
2015-05-22 18:50:01 +00:00
|
|
|
createFVarPatchNumbers(OpenSubdiv::Far::PatchTable const & patchTable,
|
2015-02-26 21:57:47 +00:00
|
|
|
std::vector<Vertex> const & fvarBuffer) {
|
|
|
|
|
|
|
|
static int channel = 0;
|
|
|
|
|
|
|
|
int patch = g_currentPatch-1;
|
|
|
|
static char buf[16];
|
|
|
|
|
2015-05-22 18:50:01 +00:00
|
|
|
if (patch>=0 and patch<patchTable.GetNumPatchesTotal()) {
|
2015-02-26 21:57:47 +00:00
|
|
|
|
2015-05-22 18:50:01 +00:00
|
|
|
OpenSubdiv::Far::PatchTable::PatchHandle handle;
|
2015-02-26 21:57:47 +00:00
|
|
|
handle.patchIndex = patch;
|
|
|
|
|
|
|
|
OpenSubdiv::Far::ConstIndexArray const cvs =
|
2015-05-22 18:50:01 +00:00
|
|
|
patchTable.GetFVarPatchValues(channel, handle);
|
2015-02-26 21:57:47 +00:00
|
|
|
|
|
|
|
for (int i=0; i<cvs.size(); ++i) {
|
|
|
|
snprintf(buf, 16, "%d", i);
|
|
|
|
g_font->Print3D(fvarBuffer[cvs[i]].GetPos(), buf, 2);
|
|
|
|
}
|
|
|
|
|
2015-05-22 18:50:01 +00:00
|
|
|
g_currentFVarPatchType = patchTable.GetFVarPatchType(channel, handle);
|
2015-02-26 21:57:47 +00:00
|
|
|
}
|
|
|
|
}
|
|
|
|
|
|
|
|
//------------------------------------------------------------------------------
|
2015-05-19 02:46:22 +00:00
|
|
|
// generate display for Far FVar patches
|
2015-02-26 21:57:47 +00:00
|
|
|
static GLMesh fvarVerts,
|
|
|
|
fvarWire;
|
|
|
|
|
|
|
|
static void
|
|
|
|
createFVarPatches(OpenSubdiv::Far::TopologyRefiner const & refiner,
|
2015-05-22 18:50:01 +00:00
|
|
|
OpenSubdiv::Far::PatchTable const & patchTable,
|
2015-02-26 21:57:47 +00:00
|
|
|
std::vector<Vertex> const & fvarBuffer) {
|
|
|
|
|
|
|
|
assert(not fvarBuffer.empty());
|
|
|
|
|
|
|
|
static int channel = 0;
|
|
|
|
|
2015-05-19 02:46:22 +00:00
|
|
|
if (g_FarDrawFVarVerts) {
|
2015-02-26 21:57:47 +00:00
|
|
|
GLMesh::Options options;
|
|
|
|
options.vertColorMode = GLMesh::VERTCOLOR_BY_LEVEL;
|
2015-05-22 18:50:01 +00:00
|
|
|
fvarVerts.InitializeFVar(options, refiner, &patchTable, channel, 0, (float *)(&fvarBuffer[0]));
|
2015-02-26 21:57:47 +00:00
|
|
|
}
|
|
|
|
|
2015-05-19 02:46:22 +00:00
|
|
|
if (g_FarDrawFVarPatches) {
|
2015-02-26 21:57:47 +00:00
|
|
|
|
|
|
|
// generate uniform tessellation for patches
|
2015-05-19 02:46:22 +00:00
|
|
|
int tessFactor = g_FarDrawFVarPatchTess,
|
2015-05-22 18:50:01 +00:00
|
|
|
npatches = patchTable.GetNumPatchesTotal(),
|
2015-02-26 21:57:47 +00:00
|
|
|
nvertsperpatch = (tessFactor) * (tessFactor),
|
|
|
|
nverts = npatches * nvertsperpatch;
|
|
|
|
|
|
|
|
float * uvs = (float *)alloca(tessFactor);
|
|
|
|
for (int i=0; i<tessFactor; ++i) {
|
|
|
|
uvs[i] = (float)i/(tessFactor-1.0f);
|
|
|
|
}
|
|
|
|
|
|
|
|
std::vector<Vertex> verts(nverts);
|
|
|
|
memset(&verts[0], 0, verts.size()*sizeof(Vertex));
|
|
|
|
|
2015-05-22 18:50:01 +00:00
|
|
|
OpenSubdiv::Far::PatchTable::PatchHandle handle;
|
2015-02-26 21:57:47 +00:00
|
|
|
|
|
|
|
Vertex * vert = &verts[0];
|
|
|
|
for (int patch=0; patch<npatches; ++patch) {
|
|
|
|
for (int i=0; i<tessFactor; ++i) {
|
|
|
|
for (int j=0; j<tessFactor; ++j, ++vert) {
|
|
|
|
handle.patchIndex = patch;
|
2015-05-20 23:40:32 +00:00
|
|
|
// To be replaced with EvaluateBasis() for the appropriate channel:
|
2015-05-22 18:50:01 +00:00
|
|
|
//patchTable.EvaluateFaceVarying(channel, handle, uvs[i], uvs[j], fvarBuffer, *vert);
|
2015-02-26 21:57:47 +00:00
|
|
|
}
|
|
|
|
}
|
|
|
|
}
|
|
|
|
|
|
|
|
GLMesh::Options options;
|
|
|
|
options.edgeColorMode = GLMesh::EDGECOLOR_BY_PATCHTYPE;
|
2015-05-22 18:50:01 +00:00
|
|
|
fvarWire.InitializeFVar(options, refiner, &patchTable, channel, tessFactor, (float *)(&verts[0]));
|
2015-02-26 21:57:47 +00:00
|
|
|
}
|
|
|
|
}
|
|
|
|
|
2014-11-01 00:09:20 +00:00
|
|
|
//------------------------------------------------------------------------------
|
2015-05-19 02:46:22 +00:00
|
|
|
// generate display IDs for Far Gregory basis
|
2014-11-01 00:09:20 +00:00
|
|
|
|
|
|
|
static GLMesh gregoryWire;
|
|
|
|
|
|
|
|
static void
|
2015-05-22 18:50:01 +00:00
|
|
|
createGregoryBasis(OpenSubdiv::Far::PatchTable const & patchTable,
|
2014-11-04 19:14:21 +00:00
|
|
|
std::vector<Vertex> const & vertexBuffer) {
|
2014-11-01 00:09:20 +00:00
|
|
|
|
2014-11-25 20:41:19 +00:00
|
|
|
typedef OpenSubdiv::Far::PatchDescriptor PatchDescriptor;
|
2014-11-01 00:09:20 +00:00
|
|
|
|
2014-11-11 19:28:39 +00:00
|
|
|
int npatches = 0;
|
2015-04-08 01:34:05 +00:00
|
|
|
int patchArray = 0;
|
2015-05-22 18:50:01 +00:00
|
|
|
for (int array=0; array<(int)patchTable.GetNumPatchArrays(); ++array) {
|
|
|
|
if (patchTable.GetPatchArrayDescriptor(array).GetType()==
|
2014-11-25 20:41:19 +00:00
|
|
|
PatchDescriptor::GREGORY_BASIS) {
|
2015-05-22 18:50:01 +00:00
|
|
|
npatches = patchTable.GetNumPatches(array);
|
2015-04-08 01:34:05 +00:00
|
|
|
patchArray = array;
|
2014-11-11 19:28:39 +00:00
|
|
|
break;
|
2014-11-04 19:14:21 +00:00
|
|
|
}
|
2014-11-01 00:09:20 +00:00
|
|
|
}
|
|
|
|
|
2014-11-04 19:14:21 +00:00
|
|
|
int nedges = npatches * 20;
|
|
|
|
std::vector<int> vertsperedge(nedges), edgeindices(nedges*2);
|
|
|
|
|
|
|
|
for (int patch=0; patch<npatches; ++patch) {
|
|
|
|
|
|
|
|
static int basisedges[40] = { 0, 1, 0, 2, 1, 3, 2, 4,
|
2014-11-11 19:28:39 +00:00
|
|
|
5, 6, 5, 7, 6, 8, 7, 9,
|
|
|
|
10, 11, 10, 12, 11, 13, 12, 14,
|
2014-11-04 19:14:21 +00:00
|
|
|
15, 16, 15, 17, 16, 18, 17, 19,
|
|
|
|
1, 7, 6, 12, 11, 17, 16, 2 };
|
|
|
|
|
|
|
|
int offset = patch * 20,
|
|
|
|
* vpe = &vertsperedge[offset],
|
|
|
|
* indices = &edgeindices[patch * 40];
|
2015-04-08 01:34:05 +00:00
|
|
|
|
|
|
|
OpenSubdiv::Far::ConstIndexArray const cvs =
|
2015-05-22 18:50:01 +00:00
|
|
|
patchTable.GetPatchVertices(patchArray, patch);
|
2015-04-08 01:34:05 +00:00
|
|
|
|
2014-11-04 19:14:21 +00:00
|
|
|
for (int i=0; i<20; ++i) {
|
|
|
|
vpe[i] = 2;
|
2015-04-08 01:34:05 +00:00
|
|
|
indices[i*2] = cvs[basisedges[i*2]];
|
|
|
|
indices[i*2+1] = cvs[basisedges[i*2+1]];
|
2014-11-04 19:14:21 +00:00
|
|
|
}
|
|
|
|
|
2015-04-08 01:34:05 +00:00
|
|
|
//Vertex const * verts = &edgeverts[offset];
|
2014-11-04 19:14:21 +00:00
|
|
|
static char buf[16];
|
|
|
|
for (int i=0; i<4; ++i) {
|
2015-04-08 01:34:05 +00:00
|
|
|
int vid = patch * 20 + i * 5;
|
|
|
|
|
|
|
|
const float *P = vertexBuffer[cvs[i*5+0]].GetPos();
|
|
|
|
const float *Ep = vertexBuffer[cvs[i*5+1]].GetPos();
|
|
|
|
const float *Em = vertexBuffer[cvs[i*5+2]].GetPos();
|
|
|
|
const float *Fp = vertexBuffer[cvs[i*5+3]].GetPos();
|
|
|
|
const float *Fm = vertexBuffer[cvs[i*5+4]].GetPos();
|
|
|
|
|
|
|
|
snprintf(buf, 16, " P%d (%d)", i, vid);
|
|
|
|
g_font->Print3D(P, buf, 3);
|
|
|
|
snprintf(buf, 16, " Ep%d (%d)", i, vid+1);
|
|
|
|
g_font->Print3D(Ep, buf, 3);
|
|
|
|
snprintf(buf, 16, " Em%d (%d)", i, vid+2);
|
|
|
|
g_font->Print3D(Em, buf, 3);
|
|
|
|
snprintf(buf, 16, " Fp%d (%d)", i, vid+3);
|
|
|
|
g_font->Print3D(Fp, buf, 3);
|
|
|
|
snprintf(buf, 16, " Fm%d (%d)", i, vid+4);
|
|
|
|
g_font->Print3D(Fm, buf, 3);
|
2014-11-01 00:09:20 +00:00
|
|
|
}
|
|
|
|
}
|
|
|
|
|
|
|
|
GLMesh::Options options;
|
2015-04-08 01:34:05 +00:00
|
|
|
gregoryWire.Initialize(options, (int)vertexBuffer.size(), (int)vertsperedge.size(),
|
|
|
|
&vertsperedge[0], &edgeindices[0], (float const *)&vertexBuffer[0]);
|
2014-11-01 00:09:20 +00:00
|
|
|
}
|
|
|
|
|
2014-09-05 22:07:46 +00:00
|
|
|
//------------------------------------------------------------------------------
|
2015-05-19 02:46:22 +00:00
|
|
|
// generate display IDs for Far faces
|
2014-09-05 22:07:46 +00:00
|
|
|
static void
|
2015-05-22 18:50:01 +00:00
|
|
|
createPtexNumbers(OpenSubdiv::Far::PatchTable const & patchTable,
|
2014-09-05 22:07:46 +00:00
|
|
|
std::vector<Vertex> const & vertexBuffer) {
|
|
|
|
|
2014-11-25 20:41:19 +00:00
|
|
|
typedef OpenSubdiv::Far::PatchDescriptor Descriptor;
|
2014-09-05 22:07:46 +00:00
|
|
|
|
|
|
|
static char buf[16];
|
|
|
|
|
|
|
|
static int regular[4] = {5, 6, 9, 10},
|
|
|
|
gregory[4] = {0, 1, 2, 3};
|
|
|
|
|
2015-05-22 18:50:01 +00:00
|
|
|
for (int array=0; array<(int)patchTable.GetNumPatchArrays(); ++array) {
|
2014-09-05 22:07:46 +00:00
|
|
|
|
2015-05-22 18:50:01 +00:00
|
|
|
for (int patch=0; patch<(int)patchTable.GetNumPatches(array); ++patch) {
|
2014-09-05 22:07:46 +00:00
|
|
|
|
2014-12-15 18:23:13 +00:00
|
|
|
OpenSubdiv::Far::ConstIndexArray const cvs =
|
2015-05-22 18:50:01 +00:00
|
|
|
patchTable.GetPatchVertices(array, patch);
|
2014-09-05 22:07:46 +00:00
|
|
|
|
|
|
|
int * remap = 0;
|
2015-05-22 18:50:01 +00:00
|
|
|
switch (patchTable.GetPatchArrayDescriptor(array).GetType()) {
|
2014-11-25 20:41:19 +00:00
|
|
|
case Descriptor::REGULAR: remap = regular; break;
|
|
|
|
case Descriptor::GREGORY:
|
|
|
|
case Descriptor::GREGORY_BOUNDARY:
|
|
|
|
case Descriptor::GREGORY_BASIS: remap = gregory; break;
|
2014-09-05 22:07:46 +00:00
|
|
|
default:
|
|
|
|
assert(0);
|
|
|
|
}
|
|
|
|
|
|
|
|
Vertex center(0.0f, 0.0f, 0.0f);
|
|
|
|
for (int k=0; k<4; ++k) {
|
|
|
|
center.AddWithWeight(vertexBuffer[cvs[remap[k]]], 0.25f);
|
|
|
|
}
|
|
|
|
|
2015-05-22 18:50:01 +00:00
|
|
|
snprintf(buf, 16, "%d", patchTable.GetPatchParam(array, patch).faceIndex);
|
2014-09-05 22:07:46 +00:00
|
|
|
g_font->Print3D(center.GetPos(), buf, 1);
|
|
|
|
}
|
|
|
|
}
|
|
|
|
}
|
|
|
|
|
|
|
|
//------------------------------------------------------------------------------
|
|
|
|
static void
|
2015-05-19 02:46:22 +00:00
|
|
|
createFarGLMesh(Shape * shape, int maxlevel) {
|
2014-09-05 22:07:46 +00:00
|
|
|
|
|
|
|
Stopwatch s;
|
|
|
|
s.Start();
|
|
|
|
|
2015-04-18 00:36:55 +00:00
|
|
|
using namespace OpenSubdiv;
|
|
|
|
|
2015-05-19 02:46:22 +00:00
|
|
|
// create Far mesh (topology)
|
2015-04-18 00:36:55 +00:00
|
|
|
Sdc::SchemeType sdctype = GetSdcType(*shape);
|
|
|
|
Sdc::Options sdcoptions = GetSdcOptions(*shape);
|
2014-09-05 22:07:46 +00:00
|
|
|
|
2015-02-26 21:57:47 +00:00
|
|
|
sdcoptions.SetFVarLinearInterpolation(g_fvarInterpolation);
|
|
|
|
|
2015-04-18 00:36:55 +00:00
|
|
|
Far::TopologyRefiner * refiner =
|
|
|
|
Far::TopologyRefinerFactory<Shape>::Create(*shape,
|
|
|
|
Far::TopologyRefinerFactory<Shape>::Options(sdctype, sdcoptions));
|
2014-09-05 22:07:46 +00:00
|
|
|
|
|
|
|
if (g_Adaptive) {
|
2015-04-18 00:36:55 +00:00
|
|
|
Far::TopologyRefiner::AdaptiveOptions options(maxlevel);
|
2014-12-23 18:07:24 +00:00
|
|
|
options.useSingleCreasePatch = false;
|
2014-12-30 22:07:24 +00:00
|
|
|
refiner->RefineAdaptive(options);
|
2014-09-05 22:07:46 +00:00
|
|
|
} else {
|
2015-04-18 00:36:55 +00:00
|
|
|
Far::TopologyRefiner::UniformOptions options(maxlevel);
|
2014-12-23 18:07:24 +00:00
|
|
|
options.fullTopologyInLastLevel = true;
|
2014-12-30 22:07:24 +00:00
|
|
|
refiner->RefineUniform(options);
|
2014-09-05 22:07:46 +00:00
|
|
|
}
|
2014-11-11 19:28:39 +00:00
|
|
|
|
2015-04-18 00:36:55 +00:00
|
|
|
int numTotalVerts = refiner->GetNumVerticesTotal();
|
2014-09-05 22:07:46 +00:00
|
|
|
|
2014-11-11 19:28:39 +00:00
|
|
|
//
|
2015-05-22 18:50:01 +00:00
|
|
|
// Patch table
|
2014-11-11 19:28:39 +00:00
|
|
|
//
|
2015-02-26 21:57:47 +00:00
|
|
|
std::vector<Vertex> fvarBuffer;
|
2015-05-22 18:50:01 +00:00
|
|
|
Far::PatchTable * patchTable = 0;
|
2015-05-19 02:46:22 +00:00
|
|
|
bool createFVarWire = g_FarDrawFVarPatches or g_FarDrawFVarVerts;
|
2014-11-11 19:28:39 +00:00
|
|
|
|
2015-04-18 00:36:55 +00:00
|
|
|
if (g_Adaptive) {
|
2015-05-22 18:50:01 +00:00
|
|
|
Far::PatchTableFactory::Options options;
|
2015-02-26 21:57:47 +00:00
|
|
|
options.generateFVarTables = createFVarWire;
|
2015-04-23 23:58:45 +00:00
|
|
|
options.shareEndCapPatchPoints = false;
|
2015-04-18 00:36:55 +00:00
|
|
|
|
2015-05-22 18:50:01 +00:00
|
|
|
patchTable =
|
|
|
|
Far::PatchTableFactory::Create(*refiner, options);
|
2015-04-18 00:36:55 +00:00
|
|
|
|
2015-05-29 19:41:11 +00:00
|
|
|
// increase vertex buffer for the additional local points
|
|
|
|
if (patchTable->GetLocalPointStencilTable()) {
|
|
|
|
numTotalVerts += patchTable->GetLocalPointStencilTable()->GetNumStencils();
|
2015-04-23 23:58:45 +00:00
|
|
|
}
|
2014-11-11 19:28:39 +00:00
|
|
|
|
2015-05-22 18:50:01 +00:00
|
|
|
g_numPatches = patchTable->GetNumPatchesTotal();
|
|
|
|
g_maxValence = patchTable->GetMaxValence();
|
2015-02-26 21:57:47 +00:00
|
|
|
|
|
|
|
if (createFVarWire) {
|
|
|
|
|
|
|
|
// interpolate fvar values
|
|
|
|
|
2015-05-22 18:50:01 +00:00
|
|
|
//Far::FVarPatchTable const * fvarTable =
|
|
|
|
// patchTable->GetFVarPatchTable();
|
|
|
|
//assert(fvarTable);
|
2015-02-26 21:57:47 +00:00
|
|
|
|
|
|
|
int channel = 0;
|
|
|
|
|
|
|
|
// XXXX should use a (u,v) vertex class
|
2015-04-23 23:58:45 +00:00
|
|
|
fvarBuffer.resize(refiner->GetNumFVarValuesTotal(channel), 0);
|
2015-02-26 21:57:47 +00:00
|
|
|
Vertex * values = &fvarBuffer[0];
|
|
|
|
|
2015-05-22 04:38:10 +00:00
|
|
|
int nCoarseValues = refiner->GetLevel(0).GetNumFVarValues(channel);
|
2015-02-26 21:57:47 +00:00
|
|
|
|
|
|
|
for (int i=0; i<nCoarseValues; ++i) {
|
|
|
|
float const * ptr = &shape->uvs[i*2];
|
|
|
|
values[i].SetPosition(ptr[0], ptr[1], 0.0f);
|
|
|
|
}
|
2015-05-30 05:21:50 +00:00
|
|
|
|
|
|
|
int lastLevel = refiner->GetMaxLevel();
|
|
|
|
Vertex * src = values;
|
|
|
|
for (int level = 1; level <= lastLevel; ++level) {
|
|
|
|
Vertex * dst = src + refiner->GetLevel(level-1).GetNumFVarValues(channel);
|
|
|
|
Far::PrimvarRefiner(*refiner).InterpolateFaceVarying(level, src, dst, channel);
|
|
|
|
src = dst;
|
|
|
|
}
|
2015-02-26 21:57:47 +00:00
|
|
|
}
|
2014-11-11 19:28:39 +00:00
|
|
|
}
|
2015-04-08 01:34:05 +00:00
|
|
|
|
2015-04-18 00:36:55 +00:00
|
|
|
//
|
|
|
|
// interpolate vertices
|
|
|
|
//
|
2015-04-08 01:34:05 +00:00
|
|
|
|
|
|
|
// create vertex primvar data buffer
|
|
|
|
std::vector<Vertex> vertexBuffer(numTotalVerts);
|
|
|
|
Vertex * verts = &vertexBuffer[0];
|
|
|
|
|
|
|
|
// copy coarse vertices positions
|
|
|
|
int ncoarseverts = shape->GetNumVertices();
|
|
|
|
for (int i=0; i<ncoarseverts; ++i) {
|
|
|
|
float * ptr = &shape->verts[i*3];
|
|
|
|
verts[i].SetPosition(ptr[0], ptr[1], ptr[2]);
|
|
|
|
}
|
|
|
|
|
2015-04-18 00:36:55 +00:00
|
|
|
s.Start();
|
|
|
|
if (g_useStencils) {
|
|
|
|
//
|
|
|
|
// Stencil interpolation
|
|
|
|
//
|
2015-05-22 18:50:01 +00:00
|
|
|
Far::StencilTable const * stencilTable = 0;
|
|
|
|
Far::StencilTableFactory::Options options;
|
2015-04-18 00:36:55 +00:00
|
|
|
options.generateOffsets=true;
|
|
|
|
options.generateIntermediateLevels=true;
|
2015-05-22 18:50:01 +00:00
|
|
|
stencilTable = Far::StencilTableFactory::Create(*refiner, options);
|
2015-04-18 00:36:55 +00:00
|
|
|
|
2015-05-29 19:41:11 +00:00
|
|
|
// append local point stencils if needed
|
|
|
|
if (patchTable and patchTable->GetLocalPointStencilTable()) {
|
|
|
|
if (Far::StencilTable const * stencilTableWithLocalPoints =
|
|
|
|
Far::StencilTableFactory::AppendLocalPointStencilTable(
|
2015-05-22 18:50:01 +00:00
|
|
|
*refiner, stencilTable,
|
2015-05-29 19:41:11 +00:00
|
|
|
patchTable->GetLocalPointStencilTable())) {
|
2015-05-22 18:50:01 +00:00
|
|
|
delete stencilTable;
|
2015-05-29 19:41:11 +00:00
|
|
|
stencilTable = stencilTableWithLocalPoints;
|
2015-04-18 00:36:55 +00:00
|
|
|
}
|
|
|
|
}
|
|
|
|
|
|
|
|
//
|
|
|
|
// apply stencils
|
|
|
|
//
|
2015-05-22 18:50:01 +00:00
|
|
|
stencilTable->UpdateValues(verts, verts + ncoarseverts);
|
2015-04-18 00:36:55 +00:00
|
|
|
|
2015-05-22 18:50:01 +00:00
|
|
|
delete stencilTable;
|
2015-04-18 00:36:55 +00:00
|
|
|
} else {
|
|
|
|
//
|
|
|
|
// TopologyRefiner interpolation
|
|
|
|
//
|
2015-05-19 02:46:22 +00:00
|
|
|
// populate buffer with Far interpolated vertex data
|
2015-05-30 05:21:50 +00:00
|
|
|
int lastLevel = refiner->GetMaxLevel();
|
|
|
|
Vertex * src = verts;
|
|
|
|
for (int level = 1; level <= lastLevel; ++level) {
|
|
|
|
Vertex * dst = src + refiner->GetLevel(level-1).GetNumVertices();
|
|
|
|
Far::PrimvarRefiner(*refiner).Interpolate(level, src, dst);
|
|
|
|
src = dst;
|
|
|
|
}
|
2015-04-18 00:36:55 +00:00
|
|
|
//printf(" %f ms (interpolate)\n", float(s.GetElapsed())*1000.0f);
|
|
|
|
//printf(" %f ms (total)\n", float(s.GetTotalElapsed())*1000.0f);
|
|
|
|
|
2015-04-23 23:58:45 +00:00
|
|
|
// TODO: endpatch basis conversion comes here
|
2015-04-18 00:36:55 +00:00
|
|
|
}
|
2014-11-11 19:28:39 +00:00
|
|
|
s.Stop();
|
|
|
|
|
|
|
|
//
|
|
|
|
// Misc display
|
|
|
|
//
|
|
|
|
|
2015-05-19 02:46:22 +00:00
|
|
|
//printf("Far time: %f ms (topology)\n", float(s.GetElapsed())*1000.0f);
|
2014-11-11 19:28:39 +00:00
|
|
|
|
2015-05-19 02:46:22 +00:00
|
|
|
if (g_FarDrawVertIDs) {
|
2014-09-05 22:07:46 +00:00
|
|
|
createVertNumbers(*refiner, vertexBuffer);
|
|
|
|
}
|
|
|
|
|
2015-05-19 02:46:22 +00:00
|
|
|
if (g_FarDrawFaceIDs) {
|
2014-09-05 22:07:46 +00:00
|
|
|
createFaceNumbers(*refiner, vertexBuffer);
|
|
|
|
}
|
|
|
|
|
2015-05-22 18:50:01 +00:00
|
|
|
if (g_FarDrawPtexIDs and patchTable) {
|
|
|
|
createPtexNumbers(*patchTable, vertexBuffer);
|
2014-09-05 22:07:46 +00:00
|
|
|
}
|
|
|
|
|
2014-11-18 18:57:19 +00:00
|
|
|
if (g_Adaptive) {
|
2015-05-22 18:50:01 +00:00
|
|
|
createPatchNumbers(*patchTable, vertexBuffer);
|
2014-09-05 22:07:46 +00:00
|
|
|
}
|
|
|
|
|
2015-05-19 02:46:22 +00:00
|
|
|
if (g_Adaptive and g_FarDrawGregogyBasis) {
|
2015-05-22 18:50:01 +00:00
|
|
|
createGregoryBasis(*patchTable, vertexBuffer);
|
2014-11-01 00:09:20 +00:00
|
|
|
}
|
|
|
|
|
2015-02-26 21:57:47 +00:00
|
|
|
if (g_Adaptive and createFVarWire) {
|
2015-05-22 18:50:01 +00:00
|
|
|
createFVarPatches(*refiner, *patchTable, fvarBuffer);
|
|
|
|
createFVarPatchNumbers(*patchTable, fvarBuffer);
|
2015-02-26 21:57:47 +00:00
|
|
|
}
|
|
|
|
|
2015-05-19 02:46:22 +00:00
|
|
|
createEdgeNumbers(*refiner, vertexBuffer, g_FarDrawEdgeIDs!=0, g_FarDrawEdgeSharpness!=0);
|
2014-09-05 22:07:46 +00:00
|
|
|
|
|
|
|
GLMesh::Options options;
|
|
|
|
options.vertColorMode=g_Adaptive ? GLMesh::VERTCOLOR_BY_LEVEL : GLMesh::VERTCOLOR_BY_SHARPNESS;
|
|
|
|
options.edgeColorMode=g_Adaptive ? GLMesh::EDGECOLOR_BY_PATCHTYPE : GLMesh::EDGECOLOR_BY_SHARPNESS;
|
|
|
|
options.faceColorMode=g_Adaptive ? GLMesh::FACECOLOR_BY_PATCHTYPE :GLMesh::FACECOLOR_SOLID;
|
|
|
|
|
2015-05-22 18:50:01 +00:00
|
|
|
g_far_glmesh.Initialize(options, *refiner, patchTable, (float *)&verts[0]);
|
2014-09-05 22:07:46 +00:00
|
|
|
if (g_Adaptive) {
|
2015-05-19 02:46:22 +00:00
|
|
|
g_far_glmesh.SetDiffuseColor(1.0f, 1.0f, 1.0f, 1.0f);
|
2014-09-05 22:07:46 +00:00
|
|
|
} else {
|
2015-05-19 02:46:22 +00:00
|
|
|
g_far_glmesh.SetDiffuseColor(0.75f, 0.9f, 1.0f, 1.0f);
|
2014-09-05 22:07:46 +00:00
|
|
|
}
|
|
|
|
|
|
|
|
|
|
|
|
//setFaceColors(*refiner);
|
|
|
|
|
2015-05-19 02:46:22 +00:00
|
|
|
g_far_glmesh.InitializeDeviceBuffers();
|
2014-09-05 22:07:46 +00:00
|
|
|
|
|
|
|
delete refiner;
|
2015-05-22 18:50:01 +00:00
|
|
|
delete patchTable;
|
2014-09-05 22:07:46 +00:00
|
|
|
}
|
|
|
|
|
|
|
|
//------------------------------------------------------------------------------
|
|
|
|
static void
|
|
|
|
createMeshes(ShapeDesc const & desc, int maxlevel) {
|
|
|
|
|
|
|
|
if (not g_font) {
|
|
|
|
g_font = new GLFont(g_hud.GetFontTexture());
|
|
|
|
}
|
|
|
|
g_font->Clear();
|
|
|
|
|
|
|
|
Shape * shape = Shape::parseObj(desc.data.c_str(), desc.scheme);
|
|
|
|
|
2015-05-19 02:46:22 +00:00
|
|
|
createFarGLMesh(shape, maxlevel);
|
2014-09-05 22:07:46 +00:00
|
|
|
delete shape;
|
|
|
|
}
|
|
|
|
|
|
|
|
//------------------------------------------------------------------------------
|
|
|
|
static void
|
|
|
|
fitFrame() {
|
|
|
|
|
|
|
|
g_pan[0] = g_pan[1] = 0;
|
|
|
|
g_dolly = g_size;
|
|
|
|
}
|
|
|
|
|
|
|
|
//------------------------------------------------------------------------------
|
|
|
|
static void
|
|
|
|
display() {
|
|
|
|
|
|
|
|
g_hud.GetFrameBuffer()->Bind();
|
|
|
|
|
|
|
|
Stopwatch s;
|
|
|
|
s.Start();
|
|
|
|
|
|
|
|
glClear(GL_COLOR_BUFFER_BIT | GL_DEPTH_BUFFER_BIT);
|
|
|
|
|
|
|
|
glViewport(0, 0, g_width, g_height);
|
|
|
|
|
|
|
|
// prepare view matrix
|
|
|
|
double aspect = g_width/(double)g_height;
|
|
|
|
identity(g_transformData.ModelViewMatrix);
|
|
|
|
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);
|
|
|
|
translate(g_transformData.ModelViewMatrix,
|
|
|
|
-g_center[0], -g_center[1], -g_center[2]);
|
|
|
|
perspective(g_transformData.ProjectionMatrix,
|
|
|
|
45.0f, (float)aspect, 0.1f, 500.0f);
|
|
|
|
multMatrix(g_transformData.ModelViewProjectionMatrix,
|
|
|
|
g_transformData.ModelViewMatrix,
|
|
|
|
g_transformData.ProjectionMatrix);
|
|
|
|
|
|
|
|
glEnable(GL_DEPTH_TEST);
|
|
|
|
|
|
|
|
s.Stop();
|
|
|
|
float drawCpuTime = float(s.GetElapsed() * 1000.0f);
|
|
|
|
|
|
|
|
glBindVertexArray(0);
|
|
|
|
|
|
|
|
glUseProgram(0);
|
|
|
|
|
|
|
|
// primitive counting
|
|
|
|
|
|
|
|
glBeginQuery(GL_PRIMITIVES_GENERATED, g_queries[0]);
|
|
|
|
#if defined(GL_VERSION_3_3)
|
|
|
|
glBeginQuery(GL_TIME_ELAPSED, g_queries[1]);
|
|
|
|
#endif
|
|
|
|
|
|
|
|
// Update and bind transform state ---------------------
|
|
|
|
if (! g_transformUB) {
|
|
|
|
glGenBuffers(1, &g_transformUB);
|
|
|
|
glBindBuffer(GL_UNIFORM_BUFFER, g_transformUB);
|
|
|
|
glBufferData(GL_UNIFORM_BUFFER, sizeof(g_transformData), NULL, GL_STATIC_DRAW);
|
|
|
|
};
|
|
|
|
glBindBuffer(GL_UNIFORM_BUFFER, g_transformUB);
|
|
|
|
glBufferSubData(GL_UNIFORM_BUFFER, 0, sizeof(g_transformData), &g_transformData);
|
|
|
|
glBindBuffer(GL_UNIFORM_BUFFER, 0);
|
|
|
|
|
|
|
|
// Update and bind lighting state ----------------------
|
|
|
|
struct Lighting {
|
|
|
|
struct Light {
|
|
|
|
float position[4];
|
|
|
|
float ambient[4];
|
|
|
|
float diffuse[4];
|
|
|
|
float specular[4];
|
|
|
|
} lightSource[2];
|
|
|
|
} lightingData = {
|
|
|
|
{{ { 0.5, 0.2f, 1.0f, 0.0f },
|
|
|
|
{ 0.1f, 0.1f, 0.1f, 1.0f },
|
|
|
|
{ 0.7f, 0.7f, 0.7f, 1.0f },
|
|
|
|
{ 0.8f, 0.8f, 0.8f, 1.0f } },
|
|
|
|
|
|
|
|
{ { -0.8f, 0.4f, -1.0f, 0.0f },
|
|
|
|
{ 0.0f, 0.0f, 0.0f, 1.0f },
|
|
|
|
{ 0.5f, 0.5f, 0.5f, 1.0f },
|
|
|
|
{ 0.8f, 0.8f, 0.8f, 1.0f } }}
|
|
|
|
};
|
|
|
|
if (! g_lightingUB) {
|
|
|
|
glGenBuffers(1, &g_lightingUB);
|
|
|
|
glBindBuffer(GL_UNIFORM_BUFFER, g_lightingUB);
|
|
|
|
glBufferData(GL_UNIFORM_BUFFER, sizeof(lightingData), NULL, GL_STATIC_DRAW);
|
|
|
|
};
|
|
|
|
glBindBuffer(GL_UNIFORM_BUFFER, g_lightingUB);
|
|
|
|
glBufferSubData(GL_UNIFORM_BUFFER, 0, sizeof(lightingData), &lightingData);
|
|
|
|
glBindBuffer(GL_UNIFORM_BUFFER, 0);
|
|
|
|
|
|
|
|
// Draw stuff ------------------------------------------
|
|
|
|
|
|
|
|
// control cage edges & verts
|
|
|
|
if (g_drawCageVertices) {
|
|
|
|
g_base_glmesh.Draw(GLMesh::COMP_VERT, g_transformUB, g_lightingUB);
|
|
|
|
}
|
|
|
|
|
|
|
|
if (g_drawCageEdges) {
|
|
|
|
g_base_glmesh.Draw(GLMesh::COMP_EDGE, g_transformUB, g_lightingUB);
|
|
|
|
}
|
|
|
|
|
2015-05-19 02:46:22 +00:00
|
|
|
// Far mesh
|
2015-05-20 02:17:50 +00:00
|
|
|
GLMesh::Component comp=GLMesh::COMP_VERT;
|
|
|
|
switch (g_FarDrawMode) {
|
|
|
|
case kDRAW_VERTICES : comp=GLMesh::COMP_VERT; break;
|
|
|
|
case kDRAW_WIREFRAME : comp=GLMesh::COMP_EDGE; break;
|
|
|
|
case kDRAW_FACES : comp=GLMesh::COMP_FACE; break;
|
|
|
|
default:
|
|
|
|
assert(0);
|
2014-09-05 22:07:46 +00:00
|
|
|
}
|
2015-05-20 02:17:50 +00:00
|
|
|
g_far_glmesh.Draw(comp, g_transformUB, g_lightingUB);
|
2014-09-05 22:07:46 +00:00
|
|
|
|
2015-05-19 02:46:22 +00:00
|
|
|
if (g_Adaptive and g_FarDrawGregogyBasis) {
|
2014-11-01 00:09:20 +00:00
|
|
|
gregoryWire.Draw(GLMesh::COMP_VERT, g_transformUB, g_lightingUB);
|
|
|
|
gregoryWire.Draw(GLMesh::COMP_EDGE, g_transformUB, g_lightingUB);
|
|
|
|
}
|
|
|
|
|
2015-05-19 02:46:22 +00:00
|
|
|
if (g_Adaptive and g_FarDrawFVarVerts) {
|
2015-02-26 21:57:47 +00:00
|
|
|
fvarVerts.Draw(GLMesh::COMP_VERT, g_transformUB, g_lightingUB);
|
|
|
|
}
|
2015-05-19 02:46:22 +00:00
|
|
|
if (g_Adaptive and g_FarDrawFVarPatches) {
|
2015-02-26 21:57:47 +00:00
|
|
|
fvarWire.Draw(GLMesh::COMP_EDGE, g_transformUB, g_lightingUB);
|
|
|
|
}
|
|
|
|
|
2014-09-05 22:07:46 +00:00
|
|
|
assert(g_font);
|
|
|
|
g_font->Draw(g_transformUB);
|
|
|
|
|
|
|
|
// -----------------------------------------------------
|
|
|
|
|
|
|
|
g_hud.GetFrameBuffer()->ApplyImageShader();
|
|
|
|
|
|
|
|
GLuint numPrimsGenerated = 0;
|
|
|
|
GLuint timeElapsed = 0;
|
|
|
|
glGetQueryObjectuiv(g_queries[0], GL_QUERY_RESULT, &numPrimsGenerated);
|
|
|
|
#if defined(GL_VERSION_3_3)
|
|
|
|
glGetQueryObjectuiv(g_queries[1], GL_QUERY_RESULT, &timeElapsed);
|
|
|
|
#endif
|
|
|
|
|
|
|
|
float drawGpuTime = timeElapsed / 1000.0f / 1000.0f;
|
|
|
|
|
|
|
|
if (g_hud.IsVisible()) {
|
|
|
|
g_fpsTimer.Stop();
|
|
|
|
double fps = 1.0/g_fpsTimer.GetElapsed();
|
|
|
|
g_fpsTimer.Start();
|
|
|
|
|
2014-11-01 00:09:20 +00:00
|
|
|
{ // display selected patch info
|
2015-02-26 21:57:47 +00:00
|
|
|
static char const * patchTypes[13] = { "undefined", "points", "lines",
|
2014-10-29 17:56:55 +00:00
|
|
|
"quads", "tris", "loop", "regular", "single crease", "boundary", "corner",
|
2015-02-26 21:57:47 +00:00
|
|
|
"gregory", "gregory-boundary", "gregory-basis" },
|
|
|
|
* format0 = "Current Patch : %d/%d (%s - %d CVs)",
|
|
|
|
* format1 = "Current Patch : %d/%d (%s - %d CVs) fvar: (%s - %d CVs)";
|
2014-09-05 22:07:46 +00:00
|
|
|
|
|
|
|
if (g_Adaptive and g_currentPatch) {
|
2015-02-26 21:57:47 +00:00
|
|
|
|
2015-05-19 02:46:22 +00:00
|
|
|
if (g_FarDrawFVarPatches or g_FarDrawFVarVerts) {
|
2015-02-26 21:57:47 +00:00
|
|
|
|
|
|
|
g_hud.DrawString(g_width/2-200, 225, format1,
|
|
|
|
g_currentPatch-1, g_numPatches-1,
|
|
|
|
patchTypes[g_currentPatchDesc.GetType()],
|
|
|
|
g_currentPatchDesc.GetNumControlVertices(),
|
|
|
|
patchTypes[g_currentFVarPatchType],
|
|
|
|
OpenSubdiv::Far::PatchDescriptor::GetNumFVarControlVertices(
|
|
|
|
g_currentFVarPatchType));
|
|
|
|
} else {
|
|
|
|
g_hud.DrawString(g_width/2-200, 225, format0,
|
|
|
|
g_currentPatch-1, g_numPatches-1,
|
|
|
|
patchTypes[g_currentPatchDesc.GetType()],
|
|
|
|
g_currentPatchDesc.GetNumControlVertices(),
|
|
|
|
patchTypes[g_currentFVarPatchType]);
|
|
|
|
}
|
2014-09-05 22:07:46 +00:00
|
|
|
}
|
|
|
|
}
|
|
|
|
|
|
|
|
static char const * schemeNames[3] = { "BILINEAR", "CATMARK", "LOOP" };
|
|
|
|
|
|
|
|
g_hud.DrawString(10, -140, "Primitives : %d", numPrimsGenerated);
|
|
|
|
g_hud.DrawString(10, -120, "Scheme : %s", schemeNames[ g_shapes[g_currentShape].scheme ]);
|
|
|
|
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);
|
|
|
|
g_hud.DrawString(10, -40, "CPU Draw : %.3f ms", drawCpuTime);
|
|
|
|
g_hud.DrawString(10, -20, "FPS : %3.1f", fps);
|
|
|
|
|
|
|
|
g_hud.Flush();
|
|
|
|
}
|
|
|
|
glFinish();
|
|
|
|
|
|
|
|
//checkGLErrors("display leave");
|
|
|
|
}
|
|
|
|
|
|
|
|
//------------------------------------------------------------------------------
|
|
|
|
static void
|
|
|
|
motion(GLFWwindow *, double dx, double dy) {
|
|
|
|
int x=(int)dx, y=(int)dy;
|
|
|
|
|
|
|
|
if (g_hud.MouseCapture()) {
|
|
|
|
// check gui
|
|
|
|
g_hud.MouseMotion(x, y);
|
|
|
|
} else if (g_mbutton[0] && !g_mbutton[1] && !g_mbutton[2]) {
|
|
|
|
// orbit
|
|
|
|
g_rotate[0] += x - g_prev_x;
|
|
|
|
g_rotate[1] += y - g_prev_y;
|
|
|
|
} else if (!g_mbutton[0] && !g_mbutton[1] && g_mbutton[2]) {
|
|
|
|
// pan
|
|
|
|
g_pan[0] -= g_dolly*(x - g_prev_x)/g_width;
|
|
|
|
g_pan[1] += g_dolly*(y - g_prev_y)/g_height;
|
|
|
|
} else if ((g_mbutton[0] && !g_mbutton[1] && g_mbutton[2]) or
|
|
|
|
(!g_mbutton[0] && g_mbutton[1] && !g_mbutton[2])) {
|
|
|
|
// dolly
|
|
|
|
g_dolly -= g_dolly*0.01f*(x - g_prev_x);
|
|
|
|
if(g_dolly <= 0.01) g_dolly = 0.01f;
|
|
|
|
}
|
|
|
|
|
|
|
|
g_prev_x = x;
|
|
|
|
g_prev_y = y;
|
|
|
|
}
|
|
|
|
|
|
|
|
//------------------------------------------------------------------------------
|
|
|
|
static void
|
|
|
|
mouse(GLFWwindow *, int button, int state, int /* mods */) {
|
|
|
|
|
|
|
|
if (state == GLFW_RELEASE)
|
|
|
|
g_hud.MouseRelease();
|
|
|
|
|
|
|
|
if (button == 0 && state == GLFW_PRESS && g_hud.MouseClick(g_prev_x, g_prev_y))
|
|
|
|
return;
|
|
|
|
|
|
|
|
if (button < 3) {
|
|
|
|
g_mbutton[button] = (state == GLFW_PRESS);
|
|
|
|
}
|
|
|
|
}
|
|
|
|
|
|
|
|
//------------------------------------------------------------------------------
|
|
|
|
static void
|
|
|
|
reshape(GLFWwindow *, int width, int height) {
|
|
|
|
|
|
|
|
g_width = width;
|
|
|
|
g_height = height;
|
|
|
|
|
|
|
|
int windowWidth = g_width, windowHeight = g_height;
|
|
|
|
|
|
|
|
// window size might not match framebuffer size on a high DPI display
|
|
|
|
glfwGetWindowSize(g_window, &windowWidth, &windowHeight);
|
|
|
|
|
2014-10-24 18:15:19 +00:00
|
|
|
g_hud.Rebuild(windowWidth, windowHeight, width, height);
|
2014-09-05 22:07:46 +00:00
|
|
|
}
|
|
|
|
|
|
|
|
//------------------------------------------------------------------------------
|
|
|
|
void windowClose(GLFWwindow*) {
|
|
|
|
g_running = false;
|
|
|
|
}
|
|
|
|
|
|
|
|
//------------------------------------------------------------------------------
|
|
|
|
static void
|
|
|
|
toggleFullScreen() {
|
|
|
|
// XXXX manuelk : to re-implement from glut
|
|
|
|
}
|
|
|
|
|
|
|
|
//------------------------------------------------------------------------------
|
|
|
|
static void
|
|
|
|
rebuildOsdMeshes() {
|
|
|
|
|
|
|
|
createMeshes(g_shapes[ g_currentShape ], g_level);
|
|
|
|
}
|
|
|
|
|
|
|
|
//------------------------------------------------------------------------------
|
|
|
|
static void
|
|
|
|
keyboard(GLFWwindow *, int key, int /* scancode */, int event, int /* mods */) {
|
|
|
|
|
|
|
|
if (event == GLFW_RELEASE) return;
|
|
|
|
if (g_hud.KeyDown(tolower(key))) return;
|
|
|
|
|
|
|
|
switch (key) {
|
|
|
|
case 'Q': g_running = 0; break;
|
|
|
|
case 'F': fitFrame(); break;
|
|
|
|
|
|
|
|
case '[': if (g_currentPatch > 0) {
|
|
|
|
--g_currentPatch;
|
|
|
|
rebuildOsdMeshes();
|
|
|
|
} break;
|
|
|
|
|
|
|
|
case ']': if (g_currentPatch < g_numPatches) {
|
|
|
|
++g_currentPatch;
|
|
|
|
rebuildOsdMeshes();
|
|
|
|
} break;
|
|
|
|
|
|
|
|
case GLFW_KEY_TAB: toggleFullScreen(); break;
|
|
|
|
case GLFW_KEY_ESCAPE: g_hud.SetVisible(!g_hud.IsVisible()); break;
|
|
|
|
}
|
|
|
|
}
|
|
|
|
|
|
|
|
static void
|
|
|
|
callbackLevel(int l) {
|
|
|
|
|
|
|
|
g_level = l;
|
|
|
|
rebuildOsdMeshes();
|
|
|
|
}
|
|
|
|
|
|
|
|
static void
|
|
|
|
callbackModel(int m) {
|
|
|
|
|
|
|
|
if (m < 0)
|
|
|
|
m = 0;
|
|
|
|
|
|
|
|
if (m >= (int)g_shapes.size())
|
|
|
|
m = (int)g_shapes.size() - 1;
|
|
|
|
|
|
|
|
g_currentShape = m;
|
|
|
|
rebuildOsdMeshes();
|
|
|
|
}
|
|
|
|
|
|
|
|
static void
|
|
|
|
callbackAdaptive(bool checked, int /* a */)
|
|
|
|
{
|
|
|
|
g_Adaptive = checked;
|
|
|
|
rebuildOsdMeshes();
|
|
|
|
}
|
|
|
|
|
2015-04-18 00:36:55 +00:00
|
|
|
static void
|
|
|
|
callbackUseStencils(bool checked, int /* a */)
|
|
|
|
{
|
|
|
|
g_useStencils = checked;
|
|
|
|
rebuildOsdMeshes();
|
|
|
|
}
|
|
|
|
|
2014-09-05 22:07:46 +00:00
|
|
|
static void
|
|
|
|
callbackCheckBox(bool checked, int button) {
|
|
|
|
|
|
|
|
switch (button) {
|
|
|
|
case kHUD_CB_DISPLAY_CAGE_EDGES : g_drawCageEdges = checked; break;
|
|
|
|
case kHUD_CB_DISPLAY_CAGE_VERTS : g_drawCageVertices = checked; break;
|
|
|
|
case kHUD_CB_DISPLAY_PATCH_COLOR: g_displayPatchColor = checked; break;
|
|
|
|
}
|
|
|
|
}
|
|
|
|
|
|
|
|
|
|
|
|
static void
|
2015-05-19 02:46:22 +00:00
|
|
|
callbackFarDrawMode(int m) {
|
2014-09-05 22:07:46 +00:00
|
|
|
|
2015-05-19 02:46:22 +00:00
|
|
|
g_FarDrawMode = m;
|
2014-09-05 22:07:46 +00:00
|
|
|
}
|
|
|
|
|
|
|
|
static void
|
|
|
|
callbackDrawIDs(bool checked, int button) {
|
|
|
|
|
|
|
|
switch (button) {
|
|
|
|
|
2015-05-20 02:17:50 +00:00
|
|
|
case 0: g_FarDrawVertIDs = checked; break;
|
|
|
|
case 1: g_FarDrawEdgeIDs = checked; break;
|
|
|
|
case 2: g_FarDrawFaceIDs = checked; break;
|
|
|
|
case 3: g_FarDrawPtexIDs = checked; break;
|
|
|
|
case 4: g_FarDrawEdgeSharpness = checked; break;
|
|
|
|
case 5: g_FarDrawGregogyBasis = checked; break;
|
2015-02-26 21:57:47 +00:00
|
|
|
|
2015-05-20 02:17:50 +00:00
|
|
|
case 6: g_FarDrawFVarVerts = checked; break;
|
|
|
|
case 7: g_FarDrawFVarPatches = checked; break;
|
2015-02-26 21:57:47 +00:00
|
|
|
|
2014-09-05 22:07:46 +00:00
|
|
|
default: break;
|
|
|
|
}
|
|
|
|
rebuildOsdMeshes();
|
|
|
|
}
|
|
|
|
|
|
|
|
static void
|
|
|
|
callbackScale(float value, int) {
|
|
|
|
|
|
|
|
g_font->SetFontScale(value);
|
|
|
|
}
|
|
|
|
|
2015-02-26 21:57:47 +00:00
|
|
|
static void
|
|
|
|
callbackFVarTess(float value, int) {
|
|
|
|
|
2015-05-19 02:46:22 +00:00
|
|
|
g_FarDrawFVarPatchTess = (int)value;
|
2015-02-26 21:57:47 +00:00
|
|
|
rebuildOsdMeshes();
|
|
|
|
}
|
|
|
|
|
|
|
|
static void
|
|
|
|
callbackFVarInterpolation(int b) {
|
|
|
|
|
|
|
|
switch (b) {
|
|
|
|
|
|
|
|
case SdcOptions::FVAR_LINEAR_NONE :
|
|
|
|
g_fvarInterpolation = SdcOptions::FVAR_LINEAR_NONE; break;
|
|
|
|
|
|
|
|
case SdcOptions::FVAR_LINEAR_CORNERS_ONLY :
|
|
|
|
g_fvarInterpolation = SdcOptions::FVAR_LINEAR_CORNERS_ONLY; break;
|
|
|
|
|
|
|
|
case SdcOptions::FVAR_LINEAR_CORNERS_PLUS1 :
|
|
|
|
g_fvarInterpolation = SdcOptions::FVAR_LINEAR_CORNERS_PLUS1; break;
|
|
|
|
|
|
|
|
case SdcOptions::FVAR_LINEAR_CORNERS_PLUS2 :
|
|
|
|
g_fvarInterpolation = SdcOptions::FVAR_LINEAR_CORNERS_PLUS2; break;
|
|
|
|
|
|
|
|
case SdcOptions::FVAR_LINEAR_BOUNDARIES :
|
|
|
|
g_fvarInterpolation = SdcOptions::FVAR_LINEAR_BOUNDARIES; break;
|
|
|
|
|
|
|
|
case SdcOptions::FVAR_LINEAR_ALL :
|
|
|
|
g_fvarInterpolation = SdcOptions::FVAR_LINEAR_ALL; break;
|
|
|
|
|
|
|
|
}
|
|
|
|
rebuildOsdMeshes();
|
|
|
|
}
|
|
|
|
|
2014-09-05 22:07:46 +00:00
|
|
|
//------------------------------------------------------------------------------
|
|
|
|
static void
|
2015-02-26 21:57:47 +00:00
|
|
|
initHUD() {
|
|
|
|
|
2014-09-05 22:07:46 +00:00
|
|
|
int windowWidth = g_width, windowHeight = g_height;
|
2014-10-24 18:15:19 +00:00
|
|
|
int frameBufferWidth = g_width, frameBufferHeight = g_height;
|
2014-09-05 22:07:46 +00:00
|
|
|
|
|
|
|
// window size might not match framebuffer size on a high DPI display
|
|
|
|
glfwGetWindowSize(g_window, &windowWidth, &windowHeight);
|
2014-10-24 18:15:19 +00:00
|
|
|
glfwGetFramebufferSize(g_window, &frameBufferWidth, &frameBufferHeight);
|
2014-09-05 22:07:46 +00:00
|
|
|
|
2014-10-24 18:15:19 +00:00
|
|
|
g_hud.Init(windowWidth, windowHeight, frameBufferWidth, frameBufferHeight);
|
2014-09-05 22:07:46 +00:00
|
|
|
|
|
|
|
g_hud.SetFrameBuffer(new GLFrameBuffer);
|
|
|
|
|
|
|
|
g_hud.AddCheckBox("Cage Edges (e)", g_drawCageEdges != 0,
|
|
|
|
10, 10, callbackCheckBox, kHUD_CB_DISPLAY_CAGE_EDGES, 'e');
|
|
|
|
g_hud.AddCheckBox("Cage Verts (r)", g_drawCageVertices != 0,
|
|
|
|
10, 30, callbackCheckBox, kHUD_CB_DISPLAY_CAGE_VERTS, 'r');
|
|
|
|
|
2015-05-20 02:17:50 +00:00
|
|
|
|
|
|
|
int pulldown = g_hud.AddPullDown("Far Draw Mode (f)", 10, 195, 250, callbackFarDrawMode, 'f');
|
|
|
|
g_hud.AddPullDownButton(pulldown, "Vertices", 0, g_FarDrawMode==kDRAW_VERTICES);
|
|
|
|
g_hud.AddPullDownButton(pulldown, "Wireframe", 1, g_FarDrawMode==kDRAW_WIREFRAME);
|
|
|
|
g_hud.AddPullDownButton(pulldown, "Faces", 2, g_FarDrawMode==kDRAW_FACES);
|
|
|
|
|
|
|
|
g_hud.AddCheckBox("Vert IDs", g_FarDrawVertIDs!=0, 10, 215, callbackDrawIDs, 0);
|
|
|
|
g_hud.AddCheckBox("Edge IDs", g_FarDrawEdgeIDs!=0, 10, 235, callbackDrawIDs, 1);
|
|
|
|
g_hud.AddCheckBox("Face IDs", g_FarDrawFaceIDs!=0, 10, 255, callbackDrawIDs, 2);
|
|
|
|
g_hud.AddCheckBox("Ptex IDs", g_FarDrawPtexIDs!=0, 10, 275, callbackDrawIDs, 3);
|
|
|
|
g_hud.AddCheckBox("Edge Sharp", g_FarDrawEdgeSharpness!=0, 10, 295, callbackDrawIDs, 4);
|
|
|
|
g_hud.AddCheckBox("Gregory Basis", g_FarDrawGregogyBasis!=0, 10, 315, callbackDrawIDs, 5);
|
2014-09-05 22:07:46 +00:00
|
|
|
|
2015-04-18 00:36:55 +00:00
|
|
|
g_hud.AddCheckBox("Use Stencils (s)", g_useStencils!=0, 10, 350, callbackUseStencils, 0, 's');
|
|
|
|
g_hud.AddCheckBox("Adaptive (`)", g_Adaptive!=0, 10, 370, callbackAdaptive, 0, '`');
|
2014-09-05 22:07:46 +00:00
|
|
|
|
|
|
|
|
2015-04-08 01:34:05 +00:00
|
|
|
g_hud.AddSlider("Font Scale", 0.0f, 0.1f, 0.01f,
|
2014-09-05 22:07:46 +00:00
|
|
|
-900, -50, 100, false, callbackScale, 0);
|
|
|
|
|
|
|
|
for (int i = 1; i < 11; ++i) {
|
|
|
|
char level[16];
|
|
|
|
sprintf(level, "Lv. %d", i);
|
2014-11-18 18:57:19 +00:00
|
|
|
g_hud.AddRadioButton(3, level, i==g_level, 10, 380+i*20, callbackLevel, i, '0'+(i%10));
|
2014-09-05 22:07:46 +00:00
|
|
|
}
|
|
|
|
|
|
|
|
int shapes_pulldown = g_hud.AddPullDown("Shape (N)", -300, 10, 300, callbackModel, 'n');
|
|
|
|
for (int i = 0; i < (int)g_shapes.size(); ++i) {
|
|
|
|
g_hud.AddPullDownButton(shapes_pulldown, g_shapes[i].name.c_str(),i, (g_currentShape==i));
|
|
|
|
}
|
|
|
|
|
2015-05-19 02:46:22 +00:00
|
|
|
g_hud.AddCheckBox("FVar Verts", g_FarDrawFVarVerts!=0, 300, 10, callbackDrawIDs, 10);
|
|
|
|
g_hud.AddCheckBox("FVar Patches", g_FarDrawFVarPatches!=0, 300, 30, callbackDrawIDs, 11);
|
2015-02-26 21:57:47 +00:00
|
|
|
|
2015-05-19 02:46:22 +00:00
|
|
|
g_hud.AddSlider("FVar Tess", 1.0f, 10.0f, (float)g_FarDrawFVarPatchTess,
|
2015-02-26 21:57:47 +00:00
|
|
|
300, 50, 25, true, callbackFVarTess, 0);
|
|
|
|
|
|
|
|
int fvar_pulldown = g_hud.AddPullDown("FVar Interpolation (i)", 300, 90, 250, callbackFVarInterpolation, 'i');
|
|
|
|
g_hud.AddPullDownButton(fvar_pulldown, "FVAR_LINEAR_NONE",
|
|
|
|
SdcOptions::FVAR_LINEAR_NONE, g_fvarInterpolation==SdcOptions::FVAR_LINEAR_NONE);
|
|
|
|
g_hud.AddPullDownButton(fvar_pulldown, "FVAR_LINEAR_CORNERS_ONLY",
|
|
|
|
SdcOptions::FVAR_LINEAR_CORNERS_ONLY, g_fvarInterpolation==SdcOptions::FVAR_LINEAR_CORNERS_ONLY);
|
|
|
|
g_hud.AddPullDownButton(fvar_pulldown, "FVAR_LINEAR_CORNERS_PLUS1",
|
|
|
|
SdcOptions::FVAR_LINEAR_CORNERS_PLUS1, g_fvarInterpolation==SdcOptions::FVAR_LINEAR_CORNERS_PLUS1);
|
|
|
|
g_hud.AddPullDownButton(fvar_pulldown, "FVAR_LINEAR_CORNERS_PLUS2",
|
|
|
|
SdcOptions::FVAR_LINEAR_CORNERS_PLUS2, g_fvarInterpolation==SdcOptions::FVAR_LINEAR_CORNERS_PLUS2);
|
|
|
|
g_hud.AddPullDownButton(fvar_pulldown, "FVAR_LINEAR_BOUNDARIES",
|
|
|
|
SdcOptions::FVAR_LINEAR_BOUNDARIES, g_fvarInterpolation==SdcOptions::FVAR_LINEAR_BOUNDARIES);
|
|
|
|
g_hud.AddPullDownButton(fvar_pulldown, "FVAR_LINEAR_ALL",
|
|
|
|
SdcOptions::FVAR_LINEAR_ALL, g_fvarInterpolation==SdcOptions::FVAR_LINEAR_ALL);
|
|
|
|
|
2014-09-05 22:07:46 +00:00
|
|
|
if (not g_font) {
|
|
|
|
g_font = new GLFont( g_hud.GetFontTexture() );
|
|
|
|
}
|
|
|
|
}
|
|
|
|
|
|
|
|
//------------------------------------------------------------------------------
|
|
|
|
static void
|
|
|
|
initGL() {
|
|
|
|
|
|
|
|
glClearColor(0.1f, 0.1f, 0.1f, 0.0f);
|
|
|
|
glEnable(GL_DEPTH_TEST);
|
|
|
|
glDepthFunc(GL_LEQUAL);
|
|
|
|
glCullFace(GL_BACK);
|
|
|
|
glEnable(GL_CULL_FACE);
|
|
|
|
|
|
|
|
glGenQueries(2, g_queries);
|
|
|
|
}
|
|
|
|
|
|
|
|
//------------------------------------------------------------------------------
|
|
|
|
static void
|
|
|
|
uninitGL() {
|
|
|
|
|
|
|
|
glDeleteQueries(2, g_queries);
|
|
|
|
}
|
|
|
|
|
|
|
|
//------------------------------------------------------------------------------
|
|
|
|
static void
|
|
|
|
idle() {
|
|
|
|
|
|
|
|
if (g_repeatCount != 0 and g_frame >= g_repeatCount)
|
|
|
|
g_running = 0;
|
|
|
|
}
|
|
|
|
|
|
|
|
|
|
|
|
//------------------------------------------------------------------------------
|
|
|
|
static void
|
|
|
|
setGLCoreProfile() {
|
|
|
|
|
|
|
|
#define glfwOpenWindowHint glfwWindowHint
|
|
|
|
#define GLFW_OPENGL_VERSION_MAJOR GLFW_CONTEXT_VERSION_MAJOR
|
|
|
|
#define GLFW_OPENGL_VERSION_MINOR GLFW_CONTEXT_VERSION_MINOR
|
|
|
|
|
|
|
|
glfwOpenWindowHint(GLFW_OPENGL_PROFILE, GLFW_OPENGL_CORE_PROFILE);
|
2015-05-30 05:33:51 +00:00
|
|
|
|
2014-09-05 22:07:46 +00:00
|
|
|
#if not defined(__APPLE__)
|
|
|
|
glfwOpenWindowHint(GLFW_OPENGL_VERSION_MAJOR, 4);
|
2015-05-30 05:33:51 +00:00
|
|
|
|
|
|
|
#ifdef OPENSUBDIV_HAS_GLSL_COMPUTE
|
|
|
|
glfwOpenWindowHint(GLFW_OPENGL_VERSION_MINOR, 3);
|
|
|
|
#else
|
|
|
|
glfwOpenWindowHint(GLFW_OPENGL_VERSION_MINOR, 2);
|
|
|
|
#endif
|
2014-09-05 22:07:46 +00:00
|
|
|
|
|
|
|
#else
|
|
|
|
glfwOpenWindowHint(GLFW_OPENGL_VERSION_MAJOR, 3);
|
|
|
|
glfwOpenWindowHint(GLFW_OPENGL_VERSION_MINOR, 2);
|
|
|
|
#endif
|
|
|
|
glfwOpenWindowHint(GLFW_OPENGL_FORWARD_COMPAT, GL_TRUE);
|
|
|
|
}
|
|
|
|
|
|
|
|
//------------------------------------------------------------------------------
|
|
|
|
int main(int argc, char ** argv)
|
|
|
|
{
|
|
|
|
bool fullscreen = false;
|
|
|
|
std::string str;
|
|
|
|
for (int i = 1; i < argc; ++i) {
|
|
|
|
if (!strcmp(argv[i], "-d"))
|
|
|
|
g_level = atoi(argv[++i]);
|
|
|
|
else if (!strcmp(argv[i], "-c"))
|
|
|
|
g_repeatCount = atoi(argv[++i]);
|
|
|
|
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_shapes.push_back(ShapeDesc(argv[1], str.c_str(), kCatmark));
|
|
|
|
}
|
|
|
|
}
|
|
|
|
}
|
|
|
|
initShapes();
|
|
|
|
|
|
|
|
if (not glfwInit()) {
|
|
|
|
printf("Failed to initialize GLFW\n");
|
|
|
|
return 1;
|
|
|
|
}
|
|
|
|
|
2015-05-19 02:46:22 +00:00
|
|
|
static const char windowTitle[] = "OpenSubdiv farViewer";
|
2014-09-05 22:07:46 +00:00
|
|
|
|
|
|
|
#define CORE_PROFILE
|
|
|
|
#ifdef CORE_PROFILE
|
|
|
|
setGLCoreProfile();
|
|
|
|
#endif
|
|
|
|
|
|
|
|
if (fullscreen) {
|
|
|
|
|
|
|
|
g_primary = glfwGetPrimaryMonitor();
|
|
|
|
|
|
|
|
// apparently glfwGetPrimaryMonitor fails under linux : if no primary,
|
|
|
|
// settle for the first one in the list
|
|
|
|
if (not g_primary) {
|
|
|
|
int count=0;
|
|
|
|
GLFWmonitor ** monitors = glfwGetMonitors(&count);
|
|
|
|
|
|
|
|
if (count)
|
|
|
|
g_primary = monitors[0];
|
|
|
|
}
|
|
|
|
|
|
|
|
if (g_primary) {
|
|
|
|
GLFWvidmode const * vidmode = glfwGetVideoMode(g_primary);
|
|
|
|
g_width = vidmode->width;
|
|
|
|
g_height = vidmode->height;
|
|
|
|
}
|
|
|
|
}
|
|
|
|
|
|
|
|
if (not (g_window=glfwCreateWindow(g_width, g_height, windowTitle,
|
|
|
|
fullscreen and g_primary ? g_primary : NULL, NULL))) {
|
|
|
|
printf("Failed to open window.\n");
|
|
|
|
glfwTerminate();
|
|
|
|
return 1;
|
|
|
|
}
|
|
|
|
glfwMakeContextCurrent(g_window);
|
|
|
|
|
|
|
|
// accommocate high DPI displays (e.g. mac retina displays)
|
|
|
|
glfwGetFramebufferSize(g_window, &g_width, &g_height);
|
|
|
|
glfwSetFramebufferSizeCallback(g_window, reshape);
|
|
|
|
|
|
|
|
glfwSetKeyCallback(g_window, keyboard);
|
|
|
|
glfwSetCursorPosCallback(g_window, motion);
|
|
|
|
glfwSetMouseButtonCallback(g_window, mouse);
|
|
|
|
glfwSetWindowCloseCallback(g_window, windowClose);
|
|
|
|
|
|
|
|
#if defined(OSD_USES_GLEW)
|
|
|
|
#ifdef CORE_PROFILE
|
|
|
|
// this is the only way to initialize glew correctly under core profile context.
|
|
|
|
glewExperimental = true;
|
|
|
|
#endif
|
|
|
|
if (GLenum r = glewInit() != GLEW_OK) {
|
|
|
|
printf("Failed to initialize glew. Error = %s\n", glewGetErrorString(r));
|
|
|
|
exit(1);
|
|
|
|
}
|
|
|
|
#ifdef CORE_PROFILE
|
|
|
|
// clear GL errors which was generated during glewInit()
|
|
|
|
glGetError();
|
|
|
|
#endif
|
|
|
|
#endif
|
|
|
|
|
|
|
|
initGL();
|
|
|
|
|
|
|
|
glfwSwapInterval(0);
|
|
|
|
|
|
|
|
initHUD();
|
|
|
|
rebuildOsdMeshes();
|
|
|
|
|
2015-05-19 01:04:38 +00:00
|
|
|
GLUtils::CheckGLErrors("before loop");
|
2014-09-05 22:07:46 +00:00
|
|
|
while (g_running) {
|
|
|
|
idle();
|
|
|
|
display();
|
|
|
|
|
|
|
|
glfwPollEvents();
|
|
|
|
glfwSwapBuffers(g_window);
|
|
|
|
|
|
|
|
glFinish();
|
|
|
|
}
|
|
|
|
|
|
|
|
uninitGL();
|
|
|
|
glfwTerminate();
|
|
|
|
}
|
|
|
|
|
|
|
|
//------------------------------------------------------------------------------
|