void MWC64XSeedGenerator::generateRandomSeeds(Buffer<uvec2>* buffer, unsigned int seed, bool useGLSharing /*= true*/, size_t localWorkGroupSize /*= 256*/) {
    if (kernel_ == NULL) {
        return;
    }

    srand(seed);
    // MWC64X random number generator
    BufferRAM* bufferRAM = buffer->getEditableRepresentation<BufferRAM>();
    uvec2* randomNumbers = static_cast<uvec2*>(bufferRAM->getData());
    int nRandomSeeds = static_cast<int>(bufferRAM->getSize());

    for (int i = 0; i < nRandomSeeds; ++i) {
        randomNumbers[i].x = static_cast<cl_uint>(rand());
    }
    // Data will be transferred to OpenCL device before new representation is returned.
    if (useGLSharing) {
        SyncCLGL glSync;
        BufferCLGL* randomSeedBufferCL = buffer->getEditableRepresentation<BufferCLGL>();
        glSync.addToAquireGLObjectList(randomSeedBufferCL);
        glSync.aquireAllObjects();
        generateSeeds(randomSeedBufferCL, nRandomSeeds, localWorkGroupSize);
    } else {
        BufferCLBase* randomSeedBufferCL = buffer->getEditableRepresentation<BufferCL>();
        generateSeeds(randomSeedBufferCL, nRandomSeeds, localWorkGroupSize);
    }
}
示例#2
0
void BufferGL2RAMConverter::update(const DataRepresentation* source,
                                   DataRepresentation* destination) {
    const BufferGL* src = static_cast<const BufferGL*>(source);
    BufferRAM* dst = static_cast<BufferRAM*>(destination);

    dst->setSize(src->getSize());
    src->download(dst->getData());
}
示例#3
0
DataRepresentation* BufferGL2RAMConverter::createFrom(const DataRepresentation* source) {
    const BufferGL* src = static_cast<const BufferGL*>(source);
    BufferRAM* dst = createBufferRAM(src->getSize(), src->getDataFormat(), src->getBufferType(),
                                     src->getBufferUsage());

    if (!dst)
        throw ConverterException(std::string("Cannot convert format from GL to RAM: ") +
                                 src->getDataFormat()->getString(), IvwContext);

    src->download(dst->getData());
    return dst;
}