Esempio n. 1
0
//------------------------------------------------------------------------------
static int 
checkMeshCL( OpenSubdiv::FarMesh<OpenSubdiv::OsdVertex>* farmesh,
             const std::vector<float>& coarseverts,
             xyzmesh * refmesh,
             const std::vector<int>& remap ) {

#ifdef OPENSUBDIV_HAS_OPENCL

    static OpenSubdiv::OsdCLComputeController *controller = new OpenSubdiv::OsdCLComputeController(g_clContext, g_clQueue);
    
    OpenSubdiv::OsdCLComputeContext *context = OpenSubdiv::OsdCLComputeContext::Create(farmesh->GetSubdivisionTables(), farmesh->GetVertexEditTables(), g_clContext);
    
    OpenSubdiv::OsdCLGLVertexBuffer * vb = OpenSubdiv::OsdCLGLVertexBuffer::Create(3, farmesh->GetNumVertices(), g_clContext);
    
    vb->UpdateData( & coarseverts[0], 0, (int)coarseverts.size()/3, g_clQueue );
    
    controller->Refine( context, farmesh->GetKernelBatches(), vb );

    // read data back from CL buffer
    size_t dataSize = vb->GetNumVertices() * vb->GetNumElements();
    float* data = new float[dataSize];
    
    clEnqueueReadBuffer (g_clQueue, vb->BindCLBuffer(g_clQueue), CL_TRUE, 0, dataSize * sizeof(float), data, 0, NULL, NULL);
    
    int result = checkVertexBuffer(refmesh, data, vb->GetNumElements(), remap);
    
    delete[] data;
    
    return result;
#else
    return 0;
#endif
}
Esempio n. 2
0
//------------------------------------------------------------------------------
static int 
checkMeshCPUGL( OpenSubdiv::FarMesh<OpenSubdiv::OsdVertex>* farmesh,
                const std::vector<float>& coarseverts,
                xyzmesh * refmesh,
                const std::vector<int>& remap) {
                    
    static OpenSubdiv::OsdCpuComputeController *controller = new OpenSubdiv::OsdCpuComputeController();
    
    OpenSubdiv::OsdCpuComputeContext *context = OpenSubdiv::OsdCpuComputeContext::Create(farmesh->GetSubdivisionTables(), farmesh->GetVertexEditTables());
    
    OpenSubdiv::OsdCpuGLVertexBuffer * vb = OpenSubdiv::OsdCpuGLVertexBuffer::Create(3, farmesh->GetNumVertices());
    
    vb->UpdateData( & coarseverts[0], 0, (int)coarseverts.size()/3 );
    
    controller->Refine( context, farmesh->GetKernelBatches(), vb );
    
    return checkVertexBuffer(refmesh, vb->BindCpuBuffer(), vb->GetNumElements(), remap);
}
Esempio n. 3
0
//------------------------------------------------------------------------------
int checkMesh( char const * msg, char const * shape, int levels, Scheme scheme=kCatmark ) {

    int result =0;

    printf("- %s (scheme=%d)\n", msg, scheme);

    xyzmesh * refmesh = simpleHbr<xyzVV>(shape, scheme, 0);

    refine( refmesh, levels );


    std::vector<float> coarseverts;

    OpenSubdiv::OsdHbrMesh * hmesh = simpleHbr<OpenSubdiv::OsdVertex>(shape, scheme, coarseverts);

    OpenSubdiv::OsdMesh * omesh = new OpenSubdiv::OsdMesh();


    std::vector<int> remap;

    {
        omesh->Create(hmesh, levels, (int)OpenSubdiv::OsdKernelDispatcher::kCPU, /* exact= */ 0, &remap);

        OpenSubdiv::OsdCpuVertexBuffer * vb =
            dynamic_cast<OpenSubdiv::OsdCpuVertexBuffer *>(omesh->InitializeVertexBuffer(3));

        vb->UpdateData( & coarseverts[0], (int)coarseverts.size()/3 );

        omesh->Subdivide( vb, NULL );

        omesh->Synchronize();

        checkVertexBuffer(refmesh, vb, remap);
    }

    delete hmesh;

    return result;
}