CpuSmoothNormalContext::CpuSmoothNormalContext(
    Far::TopologyRefiner const & refiner, int level, bool resetMemory) :
        _numVertices(0), _resetMemory(resetMemory) {

    int nfaces = refiner.GetNumFaces(level),
        nverts = nfaces * 4;

    _faceVerts.resize(nverts);
    Far::Index * dest = &_faceVerts[0];

    for (int face=0; face<nfaces; ++face, dest+=4) {
        Far::ConstIndexArray fverts = refiner.GetFaceVertices(level, face);
        memcpy(dest, fverts.begin(), 4 * sizeof(Far::Index));
    }
}
예제 #2
0
CpuPatchTable::CpuPatchTable(const Far::PatchTable *farPatchTable) {
    int nPatchArrays = farPatchTable->GetNumPatchArrays();

    // count
    int numPatches = 0;
    int numIndices = 0;
    for (int j = 0; j < nPatchArrays; ++j) {
        int nPatch = farPatchTable->GetNumPatches(j);
        int nCV = farPatchTable->GetPatchArrayDescriptor(j).GetNumControlVertices();
        numPatches += nPatch;
        numIndices += nPatch * nCV;
    }
    _patchArrays.reserve(nPatchArrays);
    _indexBuffer.reserve(numIndices);

    _varyingPatchArrays.reserve(nPatchArrays);
    _varyingIndexBuffer.reserve(
        numPatches*farPatchTable->GetVaryingPatchDescriptor().GetNumControlVertices());

    _fvarPatchArrays.resize(farPatchTable->GetNumFVarChannels());
    _fvarIndexBuffers.resize(farPatchTable->GetNumFVarChannels());
    _fvarParamBuffers.resize(farPatchTable->GetNumFVarChannels());
    for (int fvc=0; fvc<farPatchTable->GetNumFVarChannels(); ++fvc) {
        _fvarPatchArrays[fvc].reserve(nPatchArrays);
        _fvarIndexBuffers[fvc].reserve(
            numPatches*farPatchTable->GetFVarPatchDescriptor(fvc).GetNumControlVertices());
        _fvarParamBuffers[fvc].reserve(numPatches);
    }
    _patchParamBuffer.reserve(numPatches);

    // for each patchArray
    for (int j = 0; j < nPatchArrays; ++j) {
        PatchArray patchArray(farPatchTable->GetPatchArrayDescriptor(j),
                              farPatchTable->GetNumPatches(j),
                              (int)_indexBuffer.size(),
                              (int)_patchParamBuffer.size());
        _patchArrays.push_back(patchArray);

        // indices
        Far::ConstIndexArray indices = farPatchTable->GetPatchArrayVertices(j);
        _indexBuffer.insert(_indexBuffer.end(), indices.begin(), indices.end());

        // varying
        PatchArray varyingPatchArray(
            farPatchTable->GetVaryingPatchDescriptor(), numPatches, 0, 0);
        _varyingPatchArrays.push_back(varyingPatchArray);
        Far::ConstIndexArray
        varyingIndices = farPatchTable->GetPatchArrayVaryingVertices(j);
        _varyingIndexBuffer.insert(_varyingIndexBuffer.end(),
                                   varyingIndices.begin(), varyingIndices.end());

        // face-varying
        for (int fvc=0; fvc<farPatchTable->GetNumFVarChannels(); ++fvc) {
            PatchArray fvarPatchArray(
                farPatchTable->GetFVarPatchDescriptor(fvc), numPatches, 0, 0);
            _fvarPatchArrays[fvc].push_back(fvarPatchArray);

            Far::ConstIndexArray
            fvarIndices = farPatchTable->GetPatchArrayFVarValues(j, fvc);
            _fvarIndexBuffers[fvc].insert(_fvarIndexBuffers[fvc].end(),
                                          fvarIndices.begin(), fvarIndices.end());

            // face-varying param
            Far::ConstPatchParamArray
            fvarParam = farPatchTable->GetPatchArrayFVarPatchParams(j, fvc);
            for (int k = 0; k < numPatches; ++k) {
                PatchParam param;
                //param.patchParam = patchParamTable[patchIndex];
                param.field0 = fvarParam[k].field0;
                param.field1 = fvarParam[k].field1;
                param.sharpness = 0.0f;
                _fvarParamBuffers[fvc].push_back(param);
            }
        }

        // patchParams bundling
        // XXX: this process won't be needed if Far::PatchParam includes
        // sharpness.
#if 0
        // XXX: we need sharpness interface for patcharray or put sharpness
        //      into patchParam.
        Far::ConstPatchParamArray patchParams =
            farPatchTable->GetPatchParams(j);
        for (int k = 0; k < patchParams.size(); ++k) {
            float sharpness = 0.0;
            _patchParamBuffer.push_back(patchParams[k].field0);
            _patchParamBuffer.push_back(patchParams[k].field1);
            _patchParamBuffer.push_back(*((unsigned int *)&sharpness));
        }
#else
        // XXX: workaround. GetPatchParamTable() will be deprecated though.
        Far::PatchParamTable const & patchParamTable =
            farPatchTable->GetPatchParamTable();
        std::vector<Far::Index> const &sharpnessIndexTable =
            farPatchTable->GetSharpnessIndexTable();
        int numPatchesJ = farPatchTable->GetNumPatches(j);
        for (int k = 0; k < numPatchesJ; ++k) {
            float sharpness = 0.0;
            int patchIndex = (int)_patchParamBuffer.size();
            if (patchIndex < (int)sharpnessIndexTable.size()) {
                int sharpnessIndex = sharpnessIndexTable[patchIndex];
                if (sharpnessIndex >= 0)
                    sharpness = farPatchTable->GetSharpnessValues()[sharpnessIndex];
            }
            PatchParam param;
            //param.patchParam = patchParamTable[patchIndex];
            param.field0 = patchParamTable[patchIndex].field0;
            param.field1 = patchParamTable[patchIndex].field1;
            param.sharpness = sharpness;
            _patchParamBuffer.push_back(param);
        }
#endif
    }
}