2012-06-20 02:01:01 +00:00
|
|
|
//
|
2013-09-26 19:04:57 +00:00
|
|
|
// Copyright 2013 Pixar
|
2012-06-20 02:01:01 +00:00
|
|
|
//
|
2013-09-26 19:04:57 +00:00
|
|
|
// 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:
|
2012-06-20 02:01:01 +00:00
|
|
|
//
|
2013-09-26 19:04:57 +00:00
|
|
|
// 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.
|
2012-06-20 02:01:01 +00:00
|
|
|
//
|
2013-09-26 19:04:57 +00:00
|
|
|
// You may obtain a copy of the Apache License at
|
2012-06-20 02:01:01 +00:00
|
|
|
//
|
2013-09-26 19:04:57 +00:00
|
|
|
// http://www.apache.org/licenses/LICENSE-2.0
|
2013-07-18 21:19:50 +00:00
|
|
|
//
|
2013-09-26 19:04:57 +00:00
|
|
|
// 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.
|
2012-06-20 02:01:01 +00:00
|
|
|
//
|
2012-08-04 02:51:27 +00:00
|
|
|
|
|
|
|
#if defined(__APPLE__)
|
2013-06-26 07:52:57 +00:00
|
|
|
#if defined(OSD_USES_GLEW)
|
|
|
|
#include <GL/glew.h>
|
|
|
|
#else
|
|
|
|
#include <OpenGL/gl3.h>
|
|
|
|
#endif
|
2013-02-08 22:06:44 +00:00
|
|
|
#define GLFW_INCLUDE_GL3
|
|
|
|
#define GLFW_NO_GLU
|
2012-08-04 02:51:27 +00:00
|
|
|
#else
|
|
|
|
#include <stdlib.h>
|
|
|
|
#include <GL/glew.h>
|
2013-02-06 01:05:59 +00:00
|
|
|
#if defined(_WIN32)
|
|
|
|
// XXX Must include windows.h here or GLFW pollutes the global namespace
|
|
|
|
#define WIN32_LEAN_AND_MEAN
|
|
|
|
#include <windows.h>
|
|
|
|
#endif
|
2013-02-01 02:19:56 +00:00
|
|
|
#endif
|
|
|
|
|
2014-09-05 22:07:46 +00:00
|
|
|
#include <GLFW/glfw3.h>
|
|
|
|
GLFWwindow* g_window=0;
|
2012-08-04 02:51:27 +00:00
|
|
|
|
2012-06-20 02:01:01 +00:00
|
|
|
#include <stdio.h>
|
|
|
|
#include <cassert>
|
|
|
|
|
|
|
|
#include <osd/vertex.h>
|
2012-12-11 01:15:13 +00:00
|
|
|
#include <osd/cpuVertexBuffer.h>
|
|
|
|
#include <osd/cpuComputeController.h>
|
|
|
|
#include <osd/cpuComputeContext.h>
|
2012-06-20 02:01:01 +00:00
|
|
|
|
2013-02-03 17:25:22 +00:00
|
|
|
#include <osd/cpuGLVertexBuffer.h>
|
|
|
|
|
2015-03-28 18:18:00 +00:00
|
|
|
#include <far/stencilTablesFactory.h>
|
|
|
|
|
2012-06-20 02:01:01 +00:00
|
|
|
#ifdef OPENSUBDIV_HAS_CUDA
|
|
|
|
#endif
|
|
|
|
|
|
|
|
#ifdef OPENSUBDIV_HAS_OPENCL
|
2013-02-04 20:01:59 +00:00
|
|
|
#include <osd/clComputeContext.h>
|
|
|
|
#include <osd/clComputeController.h>
|
|
|
|
#include <osd/clGLVertexBuffer.h>
|
|
|
|
static cl_context g_clContext;
|
|
|
|
static cl_command_queue g_clQueue;
|
|
|
|
#include "../../examples/common/clInit.h" // XXXX TODO move file out of examples
|
2012-06-20 02:01:01 +00:00
|
|
|
#endif
|
|
|
|
|
2015-03-28 18:18:00 +00:00
|
|
|
|
|
|
|
#include "../../regression/common/cmp_utils.h"
|
2014-09-05 22:07:46 +00:00
|
|
|
#include "../../regression/common/hbr_utils.h"
|
2015-03-28 18:18:00 +00:00
|
|
|
#include "../../regression/common/vtr_utils.h"
|
2012-06-20 02:01:01 +00:00
|
|
|
|
|
|
|
//
|
|
|
|
// Regression testing matching Osd to Hbr
|
|
|
|
//
|
|
|
|
// Notes:
|
|
|
|
// - precision is currently held at 1e-6
|
|
|
|
//
|
|
|
|
// - results cannot be bitwise identical as some vertex interpolations
|
2012-08-04 02:51:27 +00:00
|
|
|
// are not happening in the same order.
|
2012-06-20 02:01:01 +00:00
|
|
|
//
|
|
|
|
// - only vertex interpolation is being tested at the moment.
|
|
|
|
//
|
|
|
|
#define PRECISION 1e-6
|
|
|
|
|
2015-03-28 18:18:00 +00:00
|
|
|
using namespace OpenSubdiv;
|
|
|
|
|
2013-02-03 17:00:28 +00:00
|
|
|
//------------------------------------------------------------------------------
|
|
|
|
enum BackendType {
|
2013-02-06 22:07:47 +00:00
|
|
|
kBackendCPU = 0, // raw CPU
|
2013-02-03 17:00:28 +00:00
|
|
|
kBackendCPUGL = 1, // CPU with GL-backed buffer
|
2013-02-06 22:07:47 +00:00
|
|
|
kBackendCL = 2, // OpenCL
|
2013-02-03 17:00:28 +00:00
|
|
|
kBackendCount
|
|
|
|
};
|
2013-02-06 22:07:47 +00:00
|
|
|
|
|
|
|
static const char* g_BackendNames[kBackendCount] = {
|
2013-02-03 17:00:28 +00:00
|
|
|
"CPU",
|
|
|
|
"CPUGL",
|
2013-02-04 20:01:59 +00:00
|
|
|
"CL",
|
2013-02-03 17:00:28 +00:00
|
|
|
};
|
|
|
|
|
2013-02-06 22:07:47 +00:00
|
|
|
static int g_Backend = -1;
|
2013-02-03 17:00:28 +00:00
|
|
|
|
2012-06-20 02:01:01 +00:00
|
|
|
//------------------------------------------------------------------------------
|
|
|
|
// Vertex class implementation
|
|
|
|
struct xyzVV {
|
2012-08-10 23:40:22 +00:00
|
|
|
|
2012-06-20 02:01:01 +00:00
|
|
|
xyzVV() { }
|
2012-08-10 23:40:22 +00:00
|
|
|
|
2012-06-20 02:01:01 +00:00
|
|
|
xyzVV( int /*i*/ ) { }
|
2012-08-10 23:40:22 +00:00
|
|
|
|
|
|
|
xyzVV( float x, float y, float z ) { _pos[0]=x; _pos[1]=y; _pos[2]=z; }
|
|
|
|
|
|
|
|
xyzVV( const xyzVV & src ) { _pos[0]=src._pos[0]; _pos[1]=src._pos[1]; _pos[2]=src._pos[2]; }
|
|
|
|
|
2012-06-20 02:01:01 +00:00
|
|
|
~xyzVV( ) { }
|
|
|
|
|
2012-08-10 23:40:22 +00:00
|
|
|
void AddWithWeight(const xyzVV& src, float weight, void * =0 ) {
|
|
|
|
_pos[0]+=weight*src._pos[0];
|
|
|
|
_pos[1]+=weight*src._pos[1];
|
|
|
|
_pos[2]+=weight*src._pos[2];
|
|
|
|
}
|
|
|
|
|
2012-06-20 02:01:01 +00:00
|
|
|
void AddVaryingWithWeight(const xyzVV& , float, void * =0 ) { }
|
2012-08-10 23:40:22 +00:00
|
|
|
|
|
|
|
void Clear( void * =0 ) { _pos[0]=_pos[1]=_pos[2]=0.0f; }
|
|
|
|
|
|
|
|
void SetPosition(float x, float y, float z) { _pos[0]=x; _pos[1]=y; _pos[2]=z; }
|
|
|
|
|
|
|
|
void ApplyVertexEdit(const OpenSubdiv::HbrVertexEdit<xyzVV> & edit) {
|
|
|
|
const float *src = edit.GetEdit();
|
|
|
|
switch(edit.GetOperation()) {
|
|
|
|
case OpenSubdiv::HbrHierarchicalEdit<xyzVV>::Set:
|
|
|
|
_pos[0] = src[0];
|
|
|
|
_pos[1] = src[1];
|
|
|
|
_pos[2] = src[2];
|
|
|
|
break;
|
|
|
|
case OpenSubdiv::HbrHierarchicalEdit<xyzVV>::Add:
|
|
|
|
_pos[0] += src[0];
|
|
|
|
_pos[1] += src[1];
|
|
|
|
_pos[2] += src[2];
|
|
|
|
break;
|
|
|
|
case OpenSubdiv::HbrHierarchicalEdit<xyzVV>::Subtract:
|
|
|
|
_pos[0] -= src[0];
|
|
|
|
_pos[1] -= src[1];
|
|
|
|
_pos[2] -= src[2];
|
|
|
|
break;
|
|
|
|
}
|
|
|
|
}
|
|
|
|
|
2012-09-18 01:41:48 +00:00
|
|
|
|
2012-08-04 02:51:27 +00:00
|
|
|
void ApplyMovingVertexEdit(const OpenSubdiv::HbrMovingVertexEdit<xyzVV> &) { }
|
2012-08-10 23:40:22 +00:00
|
|
|
|
|
|
|
const float * GetPos() const { return _pos; }
|
2012-06-20 02:01:01 +00:00
|
|
|
|
2012-08-04 02:51:27 +00:00
|
|
|
private:
|
2012-08-10 23:40:22 +00:00
|
|
|
float _pos[3];
|
2012-06-20 02:01:01 +00:00
|
|
|
};
|
|
|
|
|
|
|
|
//------------------------------------------------------------------------------
|
2013-02-06 22:07:47 +00:00
|
|
|
|
2012-06-20 02:01:01 +00:00
|
|
|
class xyzFV;
|
|
|
|
typedef OpenSubdiv::HbrMesh<xyzVV> xyzmesh;
|
2012-08-04 02:51:27 +00:00
|
|
|
typedef OpenSubdiv::HbrFace<xyzVV> xyzface;
|
|
|
|
typedef OpenSubdiv::HbrVertex<xyzVV> xyzvertex;
|
2012-06-20 02:01:01 +00:00
|
|
|
typedef OpenSubdiv::HbrHalfedge<xyzVV> xyzhalfedge;
|
|
|
|
typedef OpenSubdiv::HbrFaceOperator<xyzVV> xyzFaceOperator;
|
|
|
|
typedef OpenSubdiv::HbrVertexOperator<xyzVV> xyzVertexOperator;
|
|
|
|
|
2015-03-28 18:18:00 +00:00
|
|
|
typedef OpenSubdiv::Far::TopologyRefiner FarTopologyRefiner;
|
2013-02-06 22:07:47 +00:00
|
|
|
|
2012-06-20 02:01:01 +00:00
|
|
|
|
|
|
|
//------------------------------------------------------------------------------
|
2013-02-06 22:07:47 +00:00
|
|
|
int
|
2015-03-28 18:18:00 +00:00
|
|
|
checkVertexBuffer(
|
|
|
|
const FarTopologyRefiner &refiner, xyzmesh * hmesh,
|
|
|
|
const float * vbData, int numElements) {
|
2013-02-06 22:07:47 +00:00
|
|
|
|
2012-08-04 02:51:27 +00:00
|
|
|
int count=0;
|
2012-08-10 23:40:22 +00:00
|
|
|
float deltaAvg[3] = {0.0f, 0.0f, 0.0f},
|
|
|
|
deltaCnt[3] = {0.0f, 0.0f, 0.0f};
|
2012-08-04 02:51:27 +00:00
|
|
|
|
2015-03-28 18:18:00 +00:00
|
|
|
std::vector<xyzVV> hbrVertexData;
|
|
|
|
std::vector<bool> hbrVertexOnBoundaryData;
|
|
|
|
|
|
|
|
// Only care about vertex on boundary conditions if the interpolate boundary
|
|
|
|
// is 'none'
|
|
|
|
std::vector<bool> *hbrVertexOnBoundaryPtr =
|
|
|
|
(hmesh->GetInterpolateBoundaryMethod() ==
|
|
|
|
xyzmesh::k_InterpolateBoundaryNone)
|
|
|
|
? &hbrVertexOnBoundaryData
|
|
|
|
: NULL;
|
|
|
|
|
|
|
|
|
|
|
|
GetReorderedHbrVertexData(refiner, *hmesh, &hbrVertexData,
|
|
|
|
hbrVertexOnBoundaryPtr);
|
|
|
|
|
|
|
|
//int nverts = hmesh->GetNumVertices();
|
|
|
|
int nverts = (int)hbrVertexData.size();
|
|
|
|
|
2012-06-20 02:01:01 +00:00
|
|
|
for (int i=0; i<nverts; ++i) {
|
|
|
|
|
2015-03-28 18:18:00 +00:00
|
|
|
const float * ov = & vbData[ i * numElements ];
|
2012-06-20 02:01:01 +00:00
|
|
|
|
2015-03-28 18:18:00 +00:00
|
|
|
// boundary interpolation rules set to "none" produce "undefined"
|
|
|
|
// vertices on boundary vertices : far does not match hbr for those,
|
|
|
|
// so skip comparison.
|
|
|
|
if (hbrVertexOnBoundaryPtr and (*hbrVertexOnBoundaryPtr)[i])
|
2012-06-20 02:01:01 +00:00
|
|
|
continue;
|
|
|
|
|
2015-03-28 18:18:00 +00:00
|
|
|
const float *hbrPos = hbrVertexData[i].GetPos();
|
2012-06-20 02:01:01 +00:00
|
|
|
|
2015-03-28 18:18:00 +00:00
|
|
|
|
|
|
|
if ( hbrPos[0] != ov[0] )
|
2012-06-20 02:01:01 +00:00
|
|
|
deltaCnt[0]++;
|
2015-03-28 18:18:00 +00:00
|
|
|
if ( hbrPos[1] != ov[1] )
|
2012-06-20 02:01:01 +00:00
|
|
|
deltaCnt[1]++;
|
2015-03-28 18:18:00 +00:00
|
|
|
if ( hbrPos[2] != ov[2] )
|
2012-06-20 02:01:01 +00:00
|
|
|
deltaCnt[2]++;
|
|
|
|
|
2015-03-28 18:18:00 +00:00
|
|
|
float delta[3] = { hbrPos[0] - ov[0],
|
|
|
|
hbrPos[1] - ov[1],
|
|
|
|
hbrPos[2] - ov[2] };
|
2012-06-20 02:01:01 +00:00
|
|
|
|
2012-08-10 23:40:22 +00:00
|
|
|
deltaAvg[0]+=delta[0];
|
|
|
|
deltaAvg[1]+=delta[1];
|
|
|
|
deltaAvg[2]+=delta[2];
|
2012-06-20 02:01:01 +00:00
|
|
|
|
2012-08-10 23:40:22 +00:00
|
|
|
float dist = sqrtf( delta[0]*delta[0]+delta[1]*delta[1]+delta[2]*delta[2]);
|
2012-06-20 02:01:01 +00:00
|
|
|
if ( dist > PRECISION ) {
|
|
|
|
printf("// HbrVertex<T> %d fails : dist=%.10f (%.10f %.10f %.10f)"
|
2015-03-28 18:18:00 +00:00
|
|
|
" (%.10f %.10f %.10f)\n", i, dist, hbrPos[0],
|
|
|
|
hbrPos[1],
|
|
|
|
hbrPos[2],
|
2012-06-20 02:01:01 +00:00
|
|
|
ov[0],
|
|
|
|
ov[1],
|
|
|
|
ov[2] );
|
2012-08-04 02:51:27 +00:00
|
|
|
count++;
|
2012-06-20 02:01:01 +00:00
|
|
|
}
|
|
|
|
}
|
|
|
|
|
|
|
|
if (deltaCnt[0])
|
|
|
|
deltaAvg[0]/=deltaCnt[0];
|
|
|
|
if (deltaCnt[1])
|
|
|
|
deltaAvg[1]/=deltaCnt[1];
|
|
|
|
if (deltaCnt[2])
|
|
|
|
deltaAvg[2]/=deltaCnt[2];
|
|
|
|
|
2012-08-10 23:40:22 +00:00
|
|
|
printf(" delta ratio : (%d/%d %d/%d %d/%d)\n", (int)deltaCnt[0], nverts,
|
|
|
|
(int)deltaCnt[1], nverts,
|
|
|
|
(int)deltaCnt[2], nverts );
|
|
|
|
printf(" average delta : (%.10f %.10f %.10f)\n", deltaAvg[0],
|
|
|
|
deltaAvg[1],
|
|
|
|
deltaAvg[2] );
|
2012-06-20 02:01:01 +00:00
|
|
|
if (count==0)
|
|
|
|
printf(" success !\n");
|
2012-08-04 02:51:27 +00:00
|
|
|
|
2012-06-20 02:01:01 +00:00
|
|
|
return count;
|
|
|
|
}
|
|
|
|
|
2015-03-29 08:27:20 +00:00
|
|
|
//------------------------------------------------------------------------------
|
|
|
|
static void
|
2015-03-29 09:07:00 +00:00
|
|
|
buildStencilTables(
|
2015-03-29 08:27:20 +00:00
|
|
|
const FarTopologyRefiner &refiner,
|
|
|
|
Far::StencilTables const **vertexStencils,
|
|
|
|
Far::StencilTables const **varyingStencils)
|
|
|
|
{
|
|
|
|
Far::StencilTablesFactory::Options soptions;
|
|
|
|
soptions.generateOffsets = true;
|
|
|
|
soptions.generateIntermediateLevels = true;
|
|
|
|
|
|
|
|
*vertexStencils = Far::StencilTablesFactory::Create(refiner, soptions);
|
|
|
|
|
|
|
|
soptions.interpolationMode = Far::StencilTablesFactory::INTERPOLATE_VARYING;
|
|
|
|
*varyingStencils = Far::StencilTablesFactory::Create(refiner, soptions);
|
|
|
|
}
|
|
|
|
|
|
|
|
|
2012-06-20 02:01:01 +00:00
|
|
|
|
|
|
|
//------------------------------------------------------------------------------
|
2013-02-06 22:07:47 +00:00
|
|
|
static int
|
2015-03-28 18:18:00 +00:00
|
|
|
checkMeshCPU( FarTopologyRefiner *refiner,
|
|
|
|
const std::vector<xyzVV>& coarseverts,
|
|
|
|
xyzmesh * refmesh) {
|
2013-02-06 22:07:47 +00:00
|
|
|
|
2015-03-28 18:18:00 +00:00
|
|
|
static Osd::CpuComputeController *controller =
|
|
|
|
new Osd::CpuComputeController();
|
|
|
|
|
|
|
|
|
2015-03-29 08:27:20 +00:00
|
|
|
Far::StencilTables const *vertexStencils;
|
|
|
|
Far::StencilTables const *varyingStencils;
|
2015-03-29 09:07:00 +00:00
|
|
|
buildStencilTables(*refiner, &vertexStencils, &varyingStencils);
|
|
|
|
Osd::CpuComputeContext *context = Osd::CpuComputeContext::Create(
|
|
|
|
vertexStencils, varyingStencils);
|
2015-03-28 18:18:00 +00:00
|
|
|
|
|
|
|
|
2015-03-29 06:53:12 +00:00
|
|
|
assert(coarseverts.size() == refiner->GetNumVerticesTotal());
|
2013-02-06 22:07:47 +00:00
|
|
|
|
2015-03-28 18:18:00 +00:00
|
|
|
Osd::CpuVertexBuffer * vb =
|
|
|
|
Osd::CpuVertexBuffer::Create(3, refiner->GetNumVerticesTotal());
|
2013-02-06 22:07:47 +00:00
|
|
|
|
2015-03-28 18:18:00 +00:00
|
|
|
vb->UpdateData( coarseverts[0].GetPos(), 0, (int)coarseverts.size() );
|
2013-02-06 22:07:47 +00:00
|
|
|
|
2015-03-28 18:18:00 +00:00
|
|
|
Far::KernelBatchVector kernelBatches;
|
|
|
|
kernelBatches.push_back(
|
|
|
|
Far::StencilTablesFactory::Create(*vertexStencils));
|
2013-02-06 22:07:47 +00:00
|
|
|
|
2015-03-28 18:18:00 +00:00
|
|
|
controller->Compute( context, kernelBatches, vb );
|
2015-03-29 08:27:20 +00:00
|
|
|
|
|
|
|
int result = checkVertexBuffer(*refiner, refmesh, vb->BindCpuBuffer(),
|
2015-03-28 18:18:00 +00:00
|
|
|
vb->GetNumElements());
|
2015-03-29 08:27:20 +00:00
|
|
|
|
|
|
|
delete context;
|
|
|
|
delete vertexStencils;
|
|
|
|
delete varyingStencils;
|
|
|
|
delete vb;
|
|
|
|
|
|
|
|
return result;
|
2013-02-03 17:25:22 +00:00
|
|
|
}
|
|
|
|
|
2013-02-06 22:07:47 +00:00
|
|
|
//------------------------------------------------------------------------------
|
|
|
|
static int
|
2015-03-29 08:27:20 +00:00
|
|
|
checkMeshCPUGL(FarTopologyRefiner *refiner,
|
|
|
|
const std::vector<xyzVV>& coarseverts,
|
|
|
|
xyzmesh * refmesh) {
|
|
|
|
|
|
|
|
static Osd::CpuComputeController *controller =
|
|
|
|
new Osd::CpuComputeController();
|
2013-02-06 22:07:47 +00:00
|
|
|
|
2015-03-29 08:27:20 +00:00
|
|
|
Far::StencilTables const *vertexStencils;
|
|
|
|
Far::StencilTables const *varyingStencils;
|
2015-03-29 09:07:00 +00:00
|
|
|
buildStencilTables(*refiner, &vertexStencils, &varyingStencils);
|
|
|
|
Osd::CpuComputeContext *context = Osd::CpuComputeContext::Create(
|
|
|
|
vertexStencils, varyingStencils);
|
2015-03-29 08:27:20 +00:00
|
|
|
|
2013-02-06 22:07:47 +00:00
|
|
|
|
2015-03-29 08:27:20 +00:00
|
|
|
Osd::CpuGLVertexBuffer *vb = Osd::CpuGLVertexBuffer::Create(3,
|
|
|
|
refiner->GetNumVerticesTotal());
|
2013-02-06 22:07:47 +00:00
|
|
|
|
2015-03-29 08:27:20 +00:00
|
|
|
vb->UpdateData( coarseverts[0].GetPos(), 0, (int)coarseverts.size() );
|
|
|
|
|
|
|
|
Far::KernelBatchVector kernelBatches;
|
|
|
|
kernelBatches.push_back(
|
|
|
|
Far::StencilTablesFactory::Create(*vertexStencils));
|
2013-02-06 22:07:47 +00:00
|
|
|
|
2015-03-29 08:27:20 +00:00
|
|
|
controller->Compute( context, kernelBatches, vb );
|
2013-02-06 22:07:47 +00:00
|
|
|
|
2015-03-29 08:27:20 +00:00
|
|
|
int result = checkVertexBuffer(*refiner, refmesh,
|
|
|
|
vb->BindCpuBuffer(), vb->GetNumElements());
|
|
|
|
|
|
|
|
delete context;
|
|
|
|
delete vertexStencils;
|
|
|
|
delete varyingStencils;
|
|
|
|
delete vb;
|
|
|
|
|
|
|
|
return result;
|
2013-02-04 20:01:59 +00:00
|
|
|
}
|
2015-03-29 08:27:20 +00:00
|
|
|
|
2013-02-04 20:01:59 +00:00
|
|
|
|
2013-02-06 22:07:47 +00:00
|
|
|
//------------------------------------------------------------------------------
|
|
|
|
static int
|
2015-03-29 08:27:20 +00:00
|
|
|
checkMeshCL( FarTopologyRefiner *refiner,
|
|
|
|
const std::vector<xyzVV>& coarseverts,
|
|
|
|
xyzmesh * refmesh) {
|
|
|
|
|
2013-02-06 22:07:47 +00:00
|
|
|
#ifdef OPENSUBDIV_HAS_OPENCL
|
2013-02-04 20:01:59 +00:00
|
|
|
|
2015-03-29 09:07:00 +00:00
|
|
|
static Osd::CLComputeController *controller =
|
|
|
|
new Osd::CLComputeController(g_clContext, g_clQueue);
|
|
|
|
|
|
|
|
Far::StencilTables const *vertexStencils;
|
|
|
|
Far::StencilTables const *varyingStencils;
|
|
|
|
buildStencilTables(*refiner, &vertexStencils, &varyingStencils);
|
|
|
|
Osd::CLComputeContext *context = Osd::CLComputeContext::Create(g_clContext,
|
|
|
|
vertexStencils, varyingStencils);
|
|
|
|
|
|
|
|
Osd::CLGLVertexBuffer *vb =
|
|
|
|
Osd::CLGLVertexBuffer::Create(3, refiner->GetNumVerticesTotal(),
|
|
|
|
g_clContext);
|
2013-02-06 22:07:47 +00:00
|
|
|
|
2015-03-29 09:07:00 +00:00
|
|
|
vb->UpdateData( coarseverts[0].GetPos(), 0, (int)coarseverts.size(),
|
|
|
|
g_clQueue );
|
|
|
|
|
|
|
|
Far::KernelBatchVector kernelBatches;
|
|
|
|
kernelBatches.push_back(
|
|
|
|
Far::StencilTablesFactory::Create(*vertexStencils));
|
2013-02-06 22:07:47 +00:00
|
|
|
|
2015-03-29 09:07:00 +00:00
|
|
|
controller->Compute( context, kernelBatches, vb );
|
2013-02-04 20:01:59 +00:00
|
|
|
|
|
|
|
// read data back from CL buffer
|
|
|
|
size_t dataSize = vb->GetNumVertices() * vb->GetNumElements();
|
|
|
|
float* data = new float[dataSize];
|
2013-02-06 22:07:47 +00:00
|
|
|
|
2013-02-04 20:01:59 +00:00
|
|
|
clEnqueueReadBuffer (g_clQueue, vb->BindCLBuffer(g_clQueue), CL_TRUE, 0, dataSize * sizeof(float), data, 0, NULL, NULL);
|
2013-02-06 22:07:47 +00:00
|
|
|
|
2015-03-29 09:07:00 +00:00
|
|
|
int result = checkVertexBuffer(
|
|
|
|
*refiner, refmesh, data, vb->GetNumElements());
|
2013-02-06 22:07:47 +00:00
|
|
|
|
2013-02-04 20:01:59 +00:00
|
|
|
delete[] data;
|
2015-03-29 09:07:00 +00:00
|
|
|
delete context;
|
|
|
|
delete vertexStencils;
|
|
|
|
delete varyingStencils;
|
|
|
|
delete vb;
|
2013-02-06 22:07:47 +00:00
|
|
|
|
2013-02-04 20:01:59 +00:00
|
|
|
return result;
|
2013-02-06 22:07:47 +00:00
|
|
|
#else
|
2013-02-04 20:01:59 +00:00
|
|
|
return 0;
|
2013-02-06 22:07:47 +00:00
|
|
|
#endif
|
2013-02-03 17:25:22 +00:00
|
|
|
}
|
|
|
|
|
|
|
|
//------------------------------------------------------------------------------
|
2013-02-06 22:07:47 +00:00
|
|
|
static int
|
2013-03-19 21:41:49 +00:00
|
|
|
checkMesh( char const * msg, std::string const & shape, int levels, Scheme scheme, int backend ) {
|
2012-06-20 02:01:01 +00:00
|
|
|
|
|
|
|
int result =0;
|
|
|
|
|
|
|
|
printf("- %s (scheme=%d)\n", msg, scheme);
|
2012-08-04 02:51:27 +00:00
|
|
|
|
2015-03-28 18:18:00 +00:00
|
|
|
xyzmesh * refmesh =
|
|
|
|
interpolateHbrVertexData<xyzVV>(shape.c_str(), scheme, levels);
|
2012-08-04 02:51:27 +00:00
|
|
|
|
2015-03-28 18:18:00 +00:00
|
|
|
std::vector<xyzVV> vtrVertexData;
|
2012-06-20 02:01:01 +00:00
|
|
|
|
2015-03-28 18:18:00 +00:00
|
|
|
FarTopologyRefiner *refiner =
|
|
|
|
InterpolateVtrVertexData(shape.c_str(), scheme, levels,
|
|
|
|
vtrVertexData);
|
2012-08-04 02:51:27 +00:00
|
|
|
|
2013-02-03 17:25:22 +00:00
|
|
|
switch (backend) {
|
2015-03-28 18:18:00 +00:00
|
|
|
case kBackendCPU:
|
|
|
|
result = checkMeshCPU(refiner, vtrVertexData, refmesh);
|
|
|
|
break;
|
|
|
|
case kBackendCPUGL:
|
2015-03-29 08:27:20 +00:00
|
|
|
result = checkMeshCPUGL(refiner, vtrVertexData, refmesh);
|
2015-03-28 18:18:00 +00:00
|
|
|
break;
|
|
|
|
case kBackendCL:
|
2015-03-29 08:27:20 +00:00
|
|
|
result = checkMeshCL(refiner, vtrVertexData, refmesh);
|
2015-03-28 18:18:00 +00:00
|
|
|
break;
|
2012-06-20 02:01:01 +00:00
|
|
|
}
|
2012-08-04 02:51:27 +00:00
|
|
|
|
2015-03-28 18:18:00 +00:00
|
|
|
delete refmesh;
|
|
|
|
delete refiner;
|
2012-08-04 02:51:27 +00:00
|
|
|
|
2012-06-20 02:01:01 +00:00
|
|
|
return result;
|
|
|
|
}
|
|
|
|
|
|
|
|
//------------------------------------------------------------------------------
|
2013-02-03 17:07:04 +00:00
|
|
|
int checkBackend(int backend, int levels) {
|
2012-06-20 02:01:01 +00:00
|
|
|
|
2013-02-06 22:07:47 +00:00
|
|
|
printf("*** checking backend : %s\n", g_BackendNames[backend]);
|
2013-02-04 20:01:59 +00:00
|
|
|
|
|
|
|
if (backend == kBackendCL) {
|
2013-02-06 22:07:47 +00:00
|
|
|
#ifdef OPENSUBDIV_HAS_OPENCL
|
2013-02-04 20:01:59 +00:00
|
|
|
if (initCL(&g_clContext, &g_clQueue) == false) {
|
|
|
|
printf(" Cannot initialize OpenCL, skipping...\n");
|
|
|
|
return 0;
|
|
|
|
}
|
2013-02-06 22:07:47 +00:00
|
|
|
#else
|
2013-02-04 20:01:59 +00:00
|
|
|
printf(" No OpenCL available, skipping...\n");
|
|
|
|
return 0;
|
2013-02-06 22:07:47 +00:00
|
|
|
#endif
|
2013-02-04 20:01:59 +00:00
|
|
|
}
|
|
|
|
|
2013-02-03 17:07:04 +00:00
|
|
|
int total = 0;
|
2012-06-20 02:01:01 +00:00
|
|
|
|
|
|
|
#define test_catmark_edgeonly
|
|
|
|
#define test_catmark_edgecorner
|
2013-05-03 02:37:34 +00:00
|
|
|
#define test_catmark_flap
|
2012-06-20 02:01:01 +00:00
|
|
|
#define test_catmark_pyramid
|
|
|
|
#define test_catmark_pyramid_creases0
|
|
|
|
#define test_catmark_pyramid_creases1
|
|
|
|
#define test_catmark_cube
|
|
|
|
#define test_catmark_cube_creases0
|
|
|
|
#define test_catmark_cube_creases1
|
|
|
|
#define test_catmark_cube_corner0
|
|
|
|
#define test_catmark_cube_corner1
|
|
|
|
#define test_catmark_cube_corner2
|
|
|
|
#define test_catmark_cube_corner3
|
|
|
|
#define test_catmark_cube_corner4
|
|
|
|
#define test_catmark_dart_edgeonly
|
|
|
|
#define test_catmark_dart_edgecorner
|
|
|
|
#define test_catmark_tent
|
|
|
|
#define test_catmark_tent_creases0
|
|
|
|
#define test_catmark_tent_creases1
|
2015-03-29 08:27:20 +00:00
|
|
|
|
|
|
|
|
|
|
|
// Hedits don't yet work.
|
|
|
|
//#define test_catmark_square_hedit0
|
|
|
|
//#define test_catmark_square_hedit1
|
|
|
|
//#define test_catmark_square_hedit2
|
|
|
|
//#define test_catmark_square_hedit3
|
|
|
|
|
|
|
|
// Loop doesn't yet work.
|
|
|
|
//#define test_loop_triangle_edgeonly
|
|
|
|
//#define test_loop_triangle_edgecorner
|
|
|
|
//#define test_loop_icosahedron
|
|
|
|
//#define test_loop_cube
|
|
|
|
//#define test_loop_cube_creases0
|
|
|
|
//#define test_loop_cube_creases1
|
2012-06-20 02:01:01 +00:00
|
|
|
|
|
|
|
#define test_bilinear_cube
|
|
|
|
|
|
|
|
|
|
|
|
#ifdef test_catmark_edgeonly
|
|
|
|
#include "../shapes/catmark_edgeonly.h"
|
2013-02-03 17:25:22 +00:00
|
|
|
total += checkMesh( "test_catmark_edgeonly", catmark_edgeonly, levels, kCatmark, backend );
|
2012-06-20 02:01:01 +00:00
|
|
|
#endif
|
|
|
|
|
|
|
|
#ifdef test_catmark_edgecorner
|
|
|
|
#include "../shapes/catmark_edgecorner.h"
|
2013-02-03 17:25:22 +00:00
|
|
|
total += checkMesh( "test_catmark_edgeonly", catmark_edgecorner, levels, kCatmark, backend );
|
2012-06-20 02:01:01 +00:00
|
|
|
#endif
|
|
|
|
|
2013-05-03 02:37:34 +00:00
|
|
|
#ifdef test_catmark_flap
|
|
|
|
#include "../shapes/catmark_flap.h"
|
|
|
|
total += checkMesh( "test_catmark_flap", catmark_flap, levels, kCatmark, backend );
|
|
|
|
#endif
|
|
|
|
|
2012-06-20 02:01:01 +00:00
|
|
|
#ifdef test_catmark_pyramid
|
|
|
|
#include "../shapes/catmark_pyramid.h"
|
2013-02-03 17:25:22 +00:00
|
|
|
total += checkMesh( "test_catmark_pyramid", catmark_pyramid, levels, kCatmark, backend );
|
2012-06-20 02:01:01 +00:00
|
|
|
#endif
|
|
|
|
|
|
|
|
#ifdef test_catmark_pyramid_creases0
|
|
|
|
#include "../shapes/catmark_pyramid_creases0.h"
|
2013-02-03 17:25:22 +00:00
|
|
|
total += checkMesh( "test_catmark_pyramid_creases0", catmark_pyramid_creases0, levels, kCatmark, backend );
|
2012-06-20 02:01:01 +00:00
|
|
|
#endif
|
|
|
|
|
|
|
|
#ifdef test_catmark_pyramid_creases1
|
|
|
|
#include "../shapes/catmark_pyramid_creases1.h"
|
2013-02-03 17:25:22 +00:00
|
|
|
total += checkMesh( "test_catmark_pyramid_creases1", catmark_pyramid_creases1, levels, kCatmark, backend );
|
2012-06-20 02:01:01 +00:00
|
|
|
#endif
|
|
|
|
|
|
|
|
#ifdef test_catmark_cube
|
|
|
|
#include "../shapes/catmark_cube.h"
|
2013-02-03 17:25:22 +00:00
|
|
|
total += checkMesh( "test_catmark_cube", catmark_cube, levels, kCatmark, backend );
|
2012-06-20 02:01:01 +00:00
|
|
|
#endif
|
|
|
|
|
|
|
|
#ifdef test_catmark_cube_creases0
|
|
|
|
#include "../shapes/catmark_cube_creases0.h"
|
2013-02-03 17:25:22 +00:00
|
|
|
total += checkMesh( "test_catmark_cube_creases0", catmark_cube_creases0, levels, kCatmark, backend );
|
2012-06-20 02:01:01 +00:00
|
|
|
#endif
|
|
|
|
|
|
|
|
#ifdef test_catmark_cube_creases1
|
|
|
|
#include "../shapes/catmark_cube_creases1.h"
|
2013-02-03 17:25:22 +00:00
|
|
|
total += checkMesh( "test_catmark_cube_creases1", catmark_cube_creases1, levels, kCatmark, backend );
|
2012-06-20 02:01:01 +00:00
|
|
|
#endif
|
|
|
|
|
|
|
|
#ifdef test_catmark_cube_corner0
|
|
|
|
#include "../shapes/catmark_cube_corner0.h"
|
2013-02-03 17:25:22 +00:00
|
|
|
total += checkMesh( "test_catmark_cube_corner0", catmark_cube_corner0, levels, kCatmark, backend );
|
2012-06-20 02:01:01 +00:00
|
|
|
#endif
|
|
|
|
|
|
|
|
#ifdef test_catmark_cube_corner1
|
|
|
|
#include "../shapes/catmark_cube_corner1.h"
|
2013-02-03 17:25:22 +00:00
|
|
|
total += checkMesh( "test_catmark_cube_corner1", catmark_cube_corner1, levels, kCatmark, backend );
|
2012-06-20 02:01:01 +00:00
|
|
|
#endif
|
|
|
|
|
|
|
|
#ifdef test_catmark_cube_corner2
|
|
|
|
#include "../shapes/catmark_cube_corner2.h"
|
2013-02-03 17:25:22 +00:00
|
|
|
total += checkMesh( "test_catmark_cube_corner2", catmark_cube_corner2, levels, kCatmark, backend );
|
2012-06-20 02:01:01 +00:00
|
|
|
#endif
|
|
|
|
|
|
|
|
#ifdef test_catmark_cube_corner3
|
|
|
|
#include "../shapes/catmark_cube_corner3.h"
|
2013-02-03 17:25:22 +00:00
|
|
|
total += checkMesh( "test_catmark_cube_corner3", catmark_cube_corner3, levels, kCatmark, backend );
|
2012-06-20 02:01:01 +00:00
|
|
|
#endif
|
|
|
|
|
|
|
|
#ifdef test_catmark_cube_corner4
|
|
|
|
#include "../shapes/catmark_cube_corner4.h"
|
2013-02-03 17:25:22 +00:00
|
|
|
total += checkMesh( "test_catmark_cube_corner4", catmark_cube_corner4, levels, kCatmark, backend );
|
2012-06-20 02:01:01 +00:00
|
|
|
#endif
|
|
|
|
|
|
|
|
#ifdef test_catmark_dart_edgecorner
|
|
|
|
#include "../shapes/catmark_dart_edgecorner.h"
|
2013-02-03 17:25:22 +00:00
|
|
|
total += checkMesh( "test_catmark_dart_edgecorner", catmark_dart_edgecorner, levels, kCatmark, backend );
|
2012-06-20 02:01:01 +00:00
|
|
|
#endif
|
|
|
|
|
|
|
|
#ifdef test_catmark_dart_edgeonly
|
|
|
|
#include "../shapes/catmark_dart_edgeonly.h"
|
2013-02-03 17:25:22 +00:00
|
|
|
total += checkMesh( "test_catmark_dart_edgeonly", catmark_dart_edgeonly, levels, kCatmark, backend );
|
2012-06-20 02:01:01 +00:00
|
|
|
#endif
|
|
|
|
|
|
|
|
#ifdef test_catmark_tent
|
|
|
|
#include "../shapes/catmark_tent.h"
|
2013-02-03 17:25:22 +00:00
|
|
|
total += checkMesh( "test_catmark_tent", catmark_tent, levels, kCatmark, backend );
|
2012-06-20 02:01:01 +00:00
|
|
|
#endif
|
|
|
|
|
|
|
|
#ifdef test_catmark_tent_creases0
|
|
|
|
#include "../shapes/catmark_tent_creases0.h"
|
2013-02-03 17:25:22 +00:00
|
|
|
total += checkMesh( "test_catmark_tent_creases0", catmark_tent_creases0, levels, kCatmark, backend );
|
2012-06-20 02:01:01 +00:00
|
|
|
#endif
|
|
|
|
|
|
|
|
#ifdef test_catmark_tent_creases1
|
|
|
|
#include "../shapes/catmark_tent_creases1.h"
|
2013-02-03 17:25:22 +00:00
|
|
|
total += checkMesh( "test_catmark_tent_creases1", catmark_tent_creases1, levels, kCatmark, backend );
|
2012-06-20 02:01:01 +00:00
|
|
|
#endif
|
|
|
|
|
2012-09-18 01:41:48 +00:00
|
|
|
#ifdef test_catmark_square_hedit0
|
|
|
|
#include "../shapes/catmark_square_hedit0.h"
|
2013-02-03 17:25:22 +00:00
|
|
|
total += checkMesh( "test_catmark_square_hedit0", catmark_square_hedit0, levels, kCatmark, backend );
|
2012-09-18 01:41:48 +00:00
|
|
|
#endif
|
|
|
|
|
|
|
|
#ifdef test_catmark_square_hedit1
|
|
|
|
#include "../shapes/catmark_square_hedit1.h"
|
2013-02-03 17:25:22 +00:00
|
|
|
total += checkMesh( "test_catmark_square_hedit1", catmark_square_hedit1, levels, kCatmark, backend );
|
2012-09-18 01:41:48 +00:00
|
|
|
#endif
|
|
|
|
|
|
|
|
#ifdef test_catmark_square_hedit2
|
|
|
|
#include "../shapes/catmark_square_hedit2.h"
|
2013-02-03 17:25:22 +00:00
|
|
|
total += checkMesh( "test_catmark_square_hedit2", catmark_square_hedit2, levels, kCatmark, backend );
|
2012-09-18 01:41:48 +00:00
|
|
|
#endif
|
|
|
|
|
|
|
|
#ifdef test_catmark_square_hedit3
|
|
|
|
#include "../shapes/catmark_square_hedit3.h"
|
2013-02-03 17:25:22 +00:00
|
|
|
total += checkMesh( "test_catmark_square_hedit3", catmark_square_hedit3, levels, kCatmark, backend );
|
2012-09-18 01:41:48 +00:00
|
|
|
#endif
|
2012-06-20 02:01:01 +00:00
|
|
|
|
|
|
|
|
|
|
|
#ifdef test_loop_triangle_edgeonly
|
|
|
|
#include "../shapes/loop_triangle_edgeonly.h"
|
2013-02-03 17:25:22 +00:00
|
|
|
total += checkMesh( "test_loop_triangle_edgeonly", loop_triangle_edgeonly, levels, kLoop, backend );
|
2012-06-20 02:01:01 +00:00
|
|
|
#endif
|
|
|
|
|
|
|
|
#ifdef test_loop_triangle_edgecorner
|
|
|
|
#include "../shapes/loop_triangle_edgecorner.h"
|
2013-02-03 17:25:22 +00:00
|
|
|
total += checkMesh( "test_loop_triangle_edgecorner", loop_triangle_edgecorner, levels, kLoop, backend );
|
2012-06-20 02:01:01 +00:00
|
|
|
#endif
|
|
|
|
|
|
|
|
#ifdef test_loop_saddle_edgeonly
|
|
|
|
#include "../shapes/loop_saddle_edgeonly.h"
|
2013-02-03 17:25:22 +00:00
|
|
|
total += checkMesh( "test_loop_saddle_edgeonly", loop_saddle_edgeonly, levels, kLoop, backend );
|
2012-06-20 02:01:01 +00:00
|
|
|
#endif
|
|
|
|
|
|
|
|
#ifdef test_loop_saddle_edgecorner
|
|
|
|
#include "../shapes/loop_saddle_edgecorner.h"
|
2013-02-03 17:25:22 +00:00
|
|
|
total += checkMesh( "test_loop_saddle_edgecorner", loop_saddle_edgecorner, levels, kLoop, backend );
|
2012-06-20 02:01:01 +00:00
|
|
|
#endif
|
|
|
|
|
|
|
|
#ifdef test_loop_icosahedron
|
|
|
|
#include "../shapes/loop_icosahedron.h"
|
2013-02-03 17:25:22 +00:00
|
|
|
total += checkMesh( "test_loop_icosahedron", loop_icosahedron, levels, kLoop, backend );
|
2012-06-20 02:01:01 +00:00
|
|
|
#endif
|
|
|
|
|
|
|
|
#ifdef test_loop_cube
|
|
|
|
#include "../shapes/loop_cube.h"
|
2013-02-03 17:25:22 +00:00
|
|
|
total += checkMesh( "test_loop_cube", loop_cube, levels, kLoop, backend );
|
2012-06-20 02:01:01 +00:00
|
|
|
#endif
|
|
|
|
|
|
|
|
#ifdef test_loop_cube_creases0
|
|
|
|
#include "../shapes/loop_cube_creases0.h"
|
2013-02-03 17:25:22 +00:00
|
|
|
total += checkMesh( "test_loop_cube_creases0", loop_cube_creases0,levels, kLoop, backend );
|
2012-06-20 02:01:01 +00:00
|
|
|
#endif
|
|
|
|
|
|
|
|
#ifdef test_loop_cube_creases1
|
|
|
|
#include "../shapes/loop_cube_creases1.h"
|
2013-02-03 17:25:22 +00:00
|
|
|
total += checkMesh( "test_loop_cube_creases1", loop_cube_creases1, levels, kLoop, backend );
|
2012-06-20 02:01:01 +00:00
|
|
|
#endif
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
#ifdef test_bilinear_cube
|
|
|
|
#include "../shapes/bilinear_cube.h"
|
2013-02-03 17:25:22 +00:00
|
|
|
total += checkMesh( "test_bilinear_cube", bilinear_cube, levels, kBilinear, backend );
|
2012-06-20 02:01:01 +00:00
|
|
|
#endif
|
|
|
|
|
2013-02-06 22:07:47 +00:00
|
|
|
|
2013-02-04 20:01:59 +00:00
|
|
|
if (backend == kBackendCL) {
|
2013-02-06 22:07:47 +00:00
|
|
|
#ifdef OPENSUBDIV_HAS_OPENCL
|
2013-02-04 20:01:59 +00:00
|
|
|
uninitCL(g_clContext, g_clQueue);
|
2013-02-06 22:07:47 +00:00
|
|
|
#endif
|
2013-02-04 20:01:59 +00:00
|
|
|
}
|
|
|
|
|
2013-02-03 17:07:04 +00:00
|
|
|
return total;
|
|
|
|
}
|
|
|
|
|
|
|
|
//------------------------------------------------------------------------------
|
2013-02-06 22:07:47 +00:00
|
|
|
static void
|
|
|
|
usage(char ** argv) {
|
|
|
|
printf("%s [<options>]\n\n", argv[0]);
|
|
|
|
printf(" Options :\n");
|
|
|
|
|
|
|
|
printf(" -compute <backend>\n");
|
|
|
|
printf(" Compute backend applied (");
|
|
|
|
for (int i=0; i < kBackendCount; ++i)
|
|
|
|
printf("%s ", g_BackendNames[i]);
|
|
|
|
printf(").\n");
|
|
|
|
|
|
|
|
printf(" -help / -h\n");
|
|
|
|
printf(" Displays usage information.");
|
|
|
|
|
|
|
|
}
|
|
|
|
|
|
|
|
//------------------------------------------------------------------------------
|
|
|
|
static void
|
|
|
|
parseArgs(int argc, char ** argv) {
|
|
|
|
|
|
|
|
for (int i=1; i<argc; ++i) {
|
|
|
|
if (not strcmp(argv[i],"-compute")) {
|
|
|
|
|
|
|
|
const char * backend = NULL;
|
|
|
|
|
|
|
|
if (i<(argc-1))
|
|
|
|
backend = argv[++i];
|
|
|
|
|
|
|
|
if (not strcmp(backend, "all")) {
|
|
|
|
g_Backend = -1;
|
|
|
|
} else {
|
|
|
|
bool found = false;
|
|
|
|
for (int i = 0; i < kBackendCount; ++i) {
|
|
|
|
if (not strcmp(backend, g_BackendNames[i])) {
|
|
|
|
g_Backend = i;
|
|
|
|
found = true;
|
|
|
|
break;
|
|
|
|
}
|
|
|
|
}
|
|
|
|
if (not found) {
|
|
|
|
printf("-compute : must be 'all' or one of: ");
|
|
|
|
for (int i = 0; i < kBackendCount; ++i)
|
|
|
|
printf("%s ", g_BackendNames[i]);
|
|
|
|
printf("\n");
|
|
|
|
exit(0);
|
|
|
|
}
|
|
|
|
}
|
|
|
|
} else if ( (not strcmp(argv[i],"-help")) or
|
|
|
|
(not strcmp(argv[i],"-h")) ) {
|
|
|
|
usage(argv);
|
|
|
|
exit(1);
|
|
|
|
} else {
|
|
|
|
usage(argv);
|
|
|
|
exit(0);
|
|
|
|
}
|
|
|
|
}
|
|
|
|
}
|
|
|
|
|
|
|
|
//------------------------------------------------------------------------------
|
|
|
|
int
|
|
|
|
main(int argc, char ** argv) {
|
2013-02-03 17:07:04 +00:00
|
|
|
|
2013-02-04 20:01:59 +00:00
|
|
|
// Run with no args tests default (CPU) backend.
|
|
|
|
// "-backend all" tests all available backends.
|
|
|
|
// "-backend <name>" tests one backend.
|
2013-02-03 17:07:04 +00:00
|
|
|
parseArgs(argc, argv);
|
|
|
|
|
|
|
|
// Make sure we have an OpenGL context : create dummy GLFW window
|
|
|
|
if (not glfwInit()) {
|
|
|
|
printf("Failed to initialize GLFW\n");
|
|
|
|
return 1;
|
|
|
|
}
|
|
|
|
|
|
|
|
int width=10, height=10;
|
|
|
|
|
2013-05-07 21:25:37 +00:00
|
|
|
static const char windowTitle[] = "OpenSubdiv OSD regression";
|
2013-02-03 17:07:04 +00:00
|
|
|
if (not (g_window=glfwCreateWindow(width, height, windowTitle, NULL, NULL))) {
|
2013-02-06 22:07:47 +00:00
|
|
|
printf("Failed to open window.\n");
|
|
|
|
glfwTerminate();
|
|
|
|
return 1;
|
|
|
|
}
|
|
|
|
glfwMakeContextCurrent(g_window);
|
2013-02-03 17:07:04 +00:00
|
|
|
|
2013-06-26 07:52:57 +00:00
|
|
|
#if defined(OSD_USES_GLEW)
|
2013-02-06 22:07:47 +00:00
|
|
|
if (GLenum r = glewInit() != GLEW_OK) {
|
|
|
|
printf("Failed to initialize glew. error = %d\n", r);
|
|
|
|
exit(1);
|
|
|
|
}
|
2013-02-03 17:07:04 +00:00
|
|
|
#endif
|
|
|
|
|
|
|
|
printf("precision : %f\n",PRECISION);
|
|
|
|
|
|
|
|
int levels=5, total=0;
|
|
|
|
|
|
|
|
if (g_Backend == -1) {
|
|
|
|
for (int i = 0; i < kBackendCount; ++i)
|
|
|
|
total += checkBackend (i, levels);
|
|
|
|
} else {
|
|
|
|
total += checkBackend (g_Backend, levels);
|
|
|
|
}
|
|
|
|
|
2013-02-01 02:19:56 +00:00
|
|
|
glfwTerminate();
|
|
|
|
|
2012-06-20 02:01:01 +00:00
|
|
|
if (total==0)
|
|
|
|
printf("All tests passed.\n");
|
|
|
|
else
|
|
|
|
printf("Total failures : %d\n", total);
|
|
|
|
}
|