void memory_t<COI>::free(){ OCCA_COI_CHECK("Memory: free", COIBufferDestroy( *((coiMemory*) handle) ) ); delete handle; size = 0; }
void send_hairset (OBJScene::HairSet* hairset) { COIRESULT result; struct { COIBUFFER position; //!< vertex position array COIBUFFER hairs; //!< hair array } buffers; size_t positionBytes = max(size_t(16),hairset->v.size()*sizeof(Vec3fa)); void* positionPtr = hairset->v.size() ? &hairset->v.front() : NULL; result = COIBufferCreate(positionBytes,COI_BUFFER_STREAMING_TO_SINK,0,positionPtr,1,&process,&buffers.position); if (result != COI_SUCCESS) throw std::runtime_error("COIBufferCreate failed: " + std::string(COIResultGetName(result))); size_t hairsBytes = max(size_t(16),hairset->hairs.size()*sizeof(OBJScene::Hair)); void* hairsPtr = hairset->hairs.size() ? &hairset->hairs.front() : NULL; result = COIBufferCreate(hairsBytes,COI_BUFFER_STREAMING_TO_SINK,0,hairsPtr,1,&process,&buffers.hairs); if (result != COI_SUCCESS) throw std::runtime_error("COIBufferCreate failed: " + std::string(COIResultGetName(result))); CreateHairSetData parms; parms.numVertices = hairset->v.size(); parms.numHairs = hairset->hairs.size(); COI_ACCESS_FLAGS flags[2] = { COI_SINK_READ, COI_SINK_READ}; COIEVENT event; memset(&event,0,sizeof(event)); /* run set scene runfunction */ result = COIPipelineRunFunction (pipeline, runCreateHairSet, 2, &buffers.position, flags, 0, NULL, &parms, sizeof(parms), NULL, 0, &event); if (result != COI_SUCCESS) throw std::runtime_error("COIPipelineRunFunction failed: "+std::string(COIResultGetName(result))); result = COIEventWait(1,&event,-1,1,NULL,NULL); if (result != COI_SUCCESS) throw std::runtime_error("COIEventWait failed: "+std::string(COIResultGetName(result))); /* destroy buffers again */ result = COIBufferDestroy(buffers.position); if (result != COI_SUCCESS) throw std::runtime_error("COIPipelineRunFunction failed: "+std::string(COIResultGetName(result))); result = COIBufferDestroy(buffers.hairs); if (result != COI_SUCCESS) throw std::runtime_error("COIPipelineRunFunction failed: "+std::string(COIResultGetName(result))); }
void resize(int32_t width, int32_t height) { COIRESULT result; if (g_width == width && g_height == height) return; /* destroy old framebuffer */ if (g_width != -1 && g_height != -1) { result = COIBufferDestroy(frameBuffer); if (result != COI_SUCCESS) throw std::runtime_error("COIBufferDestroy failed: "+std::string(COIResultGetName(result))); } /* create new framebuffer */ g_width = width; g_height = height; result = COIBufferCreate (width*height*4, COI_BUFFER_NORMAL, COI_OPTIMIZE_SOURCE_READ|COI_OPTIMIZE_SINK_WRITE|COI_OPTIMIZE_HUGE_PAGE_SIZE, NULL, 1, &process, &frameBuffer); if (result != COI_SUCCESS) throw std::runtime_error("COIBufferCreate failed: " + std::string(COIResultGetName(result))); }
void send_mesh (OBJScene::Mesh* mesh) { COIRESULT result; struct { COIBUFFER position; //!< vertex position array COIBUFFER normal; //!< vertex normal array COIBUFFER texcoord; //!< vertex texcoord array COIBUFFER triangle; //!< list of triangles } buffers; assert( mesh->v.size() ); assert( mesh->triangles.size() ); if (mesh->vn.size() == 0) for (size_t i=0;i<4;i++) mesh->vn.push_back(Vec3f(0.0f,0.0f,0.0f)); if (mesh->vt.size() == 0) for (size_t i=0;i<2;i++) mesh->vt.push_back(Vec2f(0.0f,0.0f)); assert( mesh->vn.size() ); assert( mesh->vt.size() ); size_t positionBytes = max(size_t(16),mesh->v.size()*sizeof(Vec3fa)); void* positionPtr = mesh->v.size() ? &mesh->v.front() : NULL; //result = COIBufferCreate(positionBytes,COI_BUFFER_STREAMING_TO_SINK,0,positionPtr,1,&process,&buffers.position); result = COIBufferCreateFromMemory(positionBytes,COI_BUFFER_NORMAL,0,positionPtr,1,&process,&buffers.position); if (result != COI_SUCCESS) throw std::runtime_error("COIBufferCreate failed: " + std::string(COIResultGetName(result))); size_t normalBytes = max(size_t(16),mesh->vn.size()*sizeof(Vec3fa)); void* normalPtr = mesh->vn.size() ? &mesh->vn.front() : NULL; //result = COIBufferCreate(normalBytes,COI_BUFFER_STREAMING_TO_SINK,0,normalPtr,1,&process,&buffers.normal); result = COIBufferCreateFromMemory(normalBytes,COI_BUFFER_NORMAL,0,normalPtr,1,&process,&buffers.normal); if (result != COI_SUCCESS) throw std::runtime_error("COIBufferCreate failed: " + std::string(COIResultGetName(result))); size_t texcoordBytes = max(size_t(16),mesh->vt.size()*sizeof(Vec2f)); void* texcoordPtr = mesh->vt.size() ? &mesh->vt.front() : NULL; //result = COIBufferCreate(texcoordBytes,COI_BUFFER_STREAMING_TO_SINK,0,texcoordPtr,1,&process,&buffers.texcoord); result = COIBufferCreateFromMemory(texcoordBytes,COI_BUFFER_NORMAL,0,texcoordPtr,1,&process,&buffers.texcoord); if (result != COI_SUCCESS) throw std::runtime_error("COIBufferCreate failed: " + std::string(COIResultGetName(result))); size_t triangleBytes = max(size_t(16),mesh->triangles.size()*sizeof(OBJScene::Triangle)); void* trianglePtr = mesh->triangles.size() ? &mesh->triangles.front() : NULL; //result = COIBufferCreate(triangleBytes,COI_BUFFER_STREAMING_TO_SINK,0,trianglePtr,1,&process,&buffers.triangle); result = COIBufferCreateFromMemory(triangleBytes,COI_BUFFER_NORMAL,0,trianglePtr,1,&process,&buffers.triangle); if (result != COI_SUCCESS) throw std::runtime_error("COIBufferCreate failed: " + std::string(COIResultGetName(result))); CreateMeshData parms; parms.numVertices = mesh->v.size(); parms.numTriangles = mesh->triangles.size(); parms.dir = normalize(Vec3f(drand48(),drand48(),drand48())-Vec3f(0.5f)); parms.offset = 5.0f*drand48(); COI_ACCESS_FLAGS flags[4] = { COI_SINK_READ, COI_SINK_READ, COI_SINK_READ, COI_SINK_READ }; COIEVENT event; memset(&event,0,sizeof(event)); /* run set scene runfunction */ result = COIPipelineRunFunction (pipeline, runCreateMesh, 4, &buffers.position, flags, 0, NULL, &parms, sizeof(parms), NULL, 0, &event); if (result != COI_SUCCESS) throw std::runtime_error("COIPipelineRunFunction failed: "+std::string(COIResultGetName(result))); result = COIEventWait(1,&event,-1,1,NULL,NULL); if (result != COI_SUCCESS) throw std::runtime_error("COIEventWait failed: "+std::string(COIResultGetName(result))); /* destroy buffers again */ result = COIBufferDestroy(buffers.position); if (result != COI_SUCCESS) throw std::runtime_error("COIPipelineRunFunction failed: "+std::string(COIResultGetName(result))); result = COIBufferDestroy(buffers.normal); if (result != COI_SUCCESS) throw std::runtime_error("COIPipelineRunFunction failed: "+std::string(COIResultGetName(result))); result = COIBufferDestroy(buffers.texcoord); if (result != COI_SUCCESS) throw std::runtime_error("COIPipelineRunFunction failed: "+std::string(COIResultGetName(result))); result = COIBufferDestroy(buffers.triangle); if (result != COI_SUCCESS) throw std::runtime_error("COIPipelineRunFunction failed: "+std::string(COIResultGetName(result))); }