Ejemplo n.º 1
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)));
  }
Ejemplo n.º 2
0
  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)));
  }
Ejemplo n.º 3
0
  memory_v* device_t<COI>::malloc(const uintptr_t bytes,
                                  void *source){
    OCCA_EXTRACT_DATA(COI, Device);

    memory_v *mem = new memory_t<COI>;

    mem->dev    = dev;
    mem->handle = new coiMemory;
    mem->size   = bytes;

    OCCA_COI_CHECK("Device: Malloc",
                   COIBufferCreate(bytes,
                                   COI_BUFFER_NORMAL,
                                   0,
                                   source,
                                   1,
                                   &(data_.chiefID),
                                   (coiMemory*) mem->handle) );

    return mem;
  }
Ejemplo n.º 4
0
  /* set scene to use */
  void set_scene (OBJScene* scene)
  {
    COIRESULT result;
    COIBUFFER buffers[5];
    COI_ACCESS_FLAGS flags[5] = { COI_SINK_READ, COI_SINK_READ, COI_SINK_READ, COI_SINK_READ, COI_SINK_READ };

    /* send materials */
    size_t materialBytes = max(size_t(16),scene->materials.size()*sizeof(OBJScene::Material));
    void* materialPtr = scene->materials.size() ? &scene->materials.front() : NULL;
    result = COIBufferCreate(materialBytes,COI_BUFFER_STREAMING_TO_SINK,0,materialPtr,1,&process,&buffers[0]);
    if (result != COI_SUCCESS) throw std::runtime_error("COIBufferCreate failed: " + std::string(COIResultGetName(result)));

    /* send ambient lights */
    COIBUFFER ambientLightsBuffer;
    size_t ambientLightsBytes = max(size_t(16),scene->ambientLights.size()*sizeof(OBJScene::AmbientLight));
    void* ambientLightsPtr = scene->ambientLights.size() ? &scene->ambientLights.front() : NULL;
    result = COIBufferCreate(ambientLightsBytes,COI_BUFFER_STREAMING_TO_SINK,0,ambientLightsPtr,1,&process,&buffers[1]);
    if (result != COI_SUCCESS) throw std::runtime_error("COIBufferCreate failed: " + std::string(COIResultGetName(result)));

    /* send point lights */
    COIBUFFER pointLightsBuffer;
    size_t pointLightsBytes = max(size_t(16),scene->pointLights.size()*sizeof(OBJScene::PointLight));
    void* pointLightsPtr = scene->pointLights.size() ? &scene->pointLights.front() : NULL;
    result = COIBufferCreate(pointLightsBytes,COI_BUFFER_STREAMING_TO_SINK,0,pointLightsPtr,1,&process,&buffers[2]);
    if (result != COI_SUCCESS) throw std::runtime_error("COIBufferCreate failed: " + std::string(COIResultGetName(result)));

    /* send directional lights */
    COIBUFFER directionalLightsBuffer;
    size_t directionalLightsBytes = max(size_t(16),scene->directionalLights.size()*sizeof(OBJScene::DirectionalLight));
    void* directionalLightsPtr = scene->directionalLights.size() ? &scene->directionalLights.front() : NULL;
    result = COIBufferCreate(directionalLightsBytes,COI_BUFFER_STREAMING_TO_SINK,0,directionalLightsPtr,1,&process,&buffers[3]);
    if (result != COI_SUCCESS) throw std::runtime_error("COIBufferCreate failed: " + std::string(COIResultGetName(result)));

    /* send distant lights */
    COIBUFFER distantLightsBuffer;
    size_t distantLightsBytes = max(size_t(16),scene->distantLights.size()*sizeof(OBJScene::DistantLight));
    void* distantLightsPtr = scene->distantLights.size() ? &scene->distantLights.front() : NULL;
    result = COIBufferCreate(distantLightsBytes,COI_BUFFER_STREAMING_TO_SINK,0,distantLightsPtr,1,&process,&buffers[4]);
    if (result != COI_SUCCESS) throw std::runtime_error("COIBufferCreate failed: " + std::string(COIResultGetName(result)));
    
    CreateSceneData parms;
    parms.numMaterials = scene->materials.size();
    parms.numMeshes    = scene->meshes.size();
    parms.numHairSets  = scene->hairsets.size();
    parms.numAmbientLights = scene->ambientLights.size();
    parms.numPointLights = scene->pointLights.size();
    parms.numDirectionalLights = scene->directionalLights.size();
    parms.numDistantLights = scene->distantLights.size();

#if 0
    DBG_PRINT(  scene->ambientLights.size() );
    DBG_PRINT(  scene->pointLights.size() );
    DBG_PRINT(  scene->directionalLights.size() );
    DBG_PRINT(  scene->distantLights.size() );

#endif
    COIEVENT event;
    memset(&event,0,sizeof(event));

    /* run set scene runfunction */
    result = COIPipelineRunFunction (pipeline, runCreateScene, 5, buffers, 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(materialBuffer);
    // if (result != COI_SUCCESS) throw std::runtime_error("COIPipelineRunFunction failed: "+std::string(COIResultGetName(result)));

    /* send all meshes */
    for (size_t i=0; i<scene->meshes.size(); i++) 
      send_mesh(scene->meshes[i]);

    /* send all hairsets */
    for (size_t i=0; i<scene->hairsets.size(); i++) 
      send_hairset(scene->hairsets[i]);
  }