コード例 #1
0
ファイル: Geometry.cpp プロジェクト: ospray/OSPRay
    void Geometry::postCommit(RenderContext &)
    {
      auto ospGeometry = valueAs<OSPGeometry>();

      if (hasChild("material") && !hasChild("materialList")) {
        // XXX FIXME never happens
        ospSetMaterial(ospGeometry, child("material").valueAs<OSPMaterial>());
      }

      auto materialListNode = child("materialList").nodeAs<MaterialList>();
      const auto &materialList = materialListNode->nodes;
      if (!materialList.empty()) {
        std::vector<OSPObject> mats;
        for (auto mat : materialList) {
          auto m = mat->valueAs<OSPObject>();
          if (m)
            mats.push_back(m);
        }
        auto ospMaterialList = ospNewData(mats.size(), OSP_OBJECT, mats.data());
        ospCommit(ospMaterialList);
        ospSetData(valueAs<OSPObject>(), "materialList", ospMaterialList);
        ospRelease(ospMaterialList);
      }

      ospCommit(ospGeometry);
    }
コード例 #2
0
ファイル: GLFWOSPRayWindow.cpp プロジェクト: ospray/OSPRay
void GLFWOSPRayWindow::reshape(const ospcommon::vec2i &newWindowSize)
{
  windowSize = newWindowSize;

  // release the current frame buffer, if it exists
  if (framebuffer)
    ospRelease(framebuffer);

  // create new frame buffer
  framebuffer = ospNewFrameBuffer(*reinterpret_cast<osp::vec2i *>(&windowSize),
                                  OSP_FB_SRGBA,
                                  OSP_FB_COLOR | OSP_FB_ACCUM);

  // reset OpenGL viewport and orthographic projection
  glViewport(0, 0, windowSize.x, windowSize.y);

  glMatrixMode(GL_PROJECTION);
  glLoadIdentity();
  glOrtho(0.0, windowSize.x, 0.0, windowSize.y, -1.0, 1.0);

  // update camera
  arcballCamera->updateWindowSize(windowSize);

  ospSetf(camera, "aspect", windowSize.x / float(windowSize.y));
  ospCommit(camera);
}
コード例 #3
0
ファイル: FrameBuffer.cpp プロジェクト: ospray/OSPRay
    void ospray::sg::FrameBuffer::updateFB()
    {
      // workaround insufficient detection of new framebuffer in sg::Frame:
      // create the new FB first and release the old afterwards to ensure a
      // different address / handle
      auto oldFrameBuffer = ospFrameBuffer;

      committed_size = child("size").valueAs<vec2i>();

      committed_format = OSP_FB_NONE;
      auto key = child("colorFormat").valueAs<std::string>();
      for(auto const& el : colorFormats)
        if (el.first == key) {
          committed_format = el.second;
          break;
        }
#ifdef OSPRAY_APPS_ENABLE_DENOISER
      useDenoiser = child("useDenoiser").valueAs<bool>();
      if (useDenoiser)
        committed_format = OSP_FB_RGBA32F;
#endif

      auto useAccum    = child("useAccumBuffer").valueAs<bool>();
      auto useVariance = child("useVarianceBuffer").valueAs<bool>();
      ospFrameBuffer = ospNewFrameBuffer((osp::vec2i&)committed_size, committed_format,
                                         OSP_FB_COLOR |
#ifdef OSPRAY_APPS_ENABLE_DENOISER
          (useDenoiser ? OSP_FB_NORMAL | OSP_FB_ALBEDO : 0) |
#endif
                                         (useAccum ? OSP_FB_ACCUM : 0) |
                                         (useVariance ? OSP_FB_VARIANCE : 0));
      setValue(ospFrameBuffer);
      ospRelease(oldFrameBuffer);
      toneMapperActive = false;
    }
コード例 #4
0
ファイル: OSPRayMaterial.cpp プロジェクト: chevtche/Brayns
void OSPRayMaterial::commit(const std::string& renderer)
{
    if (!isModified())
        return;
    ospRelease(_ospMaterial);
    _ospMaterial = ospNewMaterial2(renderer.c_str(), "default_material");
    markModified(false); // Ensure commit recreates the ISPC object
    commit();
}
コード例 #5
0
ファイル: Model.cpp プロジェクト: ospray/OSPRay
 void Model::preCommit(RenderContext &ctx)
 {
   auto model = valueAs<OSPModel>();
   if (model) {
     ospRelease(model);
     child("dynamicScene").markAsModified();
     child("compactMode").markAsModified();
     child("robustMode").markAsModified();
   }
   model = ospNewModel();
   setValue(model);
   stashedModel = ctx.currentOSPModel;
   ctx.currentOSPModel = model;
 }
コード例 #6
0
ファイル: OSPRayMaterial.cpp プロジェクト: chevtche/Brayns
void OSPRayMaterial::commit()
{
    // Do nothing until this material is instanced for a specific renderer
    if (!_ospMaterial || !isModified())
        return;

    if (getCurrentType() == "simulation")
        osphelper::set(_ospMaterial, "apply_simulation", 1);
    else
        ospRemoveParam(_ospMaterial, "apply_simulation");

    osphelper::set(_ospMaterial, "kd", Vector3f(_diffuseColor));
    osphelper::set(_ospMaterial, "ks", Vector3f(_specularColor));
    osphelper::set(_ospMaterial, "ns", static_cast<float>(_specularExponent));
    osphelper::set(_ospMaterial, "d", static_cast<float>(_opacity));
    osphelper::set(_ospMaterial, "refraction",
                   static_cast<float>(_refractionIndex));
    osphelper::set(_ospMaterial, "reflection",
                   static_cast<float>(_reflectionIndex));
    osphelper::set(_ospMaterial, "a", static_cast<float>(_emission));
    osphelper::set(_ospMaterial, "glossiness", static_cast<float>(_glossiness));
    osphelper::set(_ospMaterial, "skybox", _isBackGroundMaterial);

    // Properties
    toOSPRayProperties(*this, _ospMaterial);

    // Textures
    for (const auto& textureType : textureTypeMaterialAttribute)
        ospSetObject(_ospMaterial, textureType.attribute.c_str(), nullptr);

    for (const auto& textureDescriptor : _textureDescriptors)
    {
        const auto texType = textureDescriptor.first;
        auto texture = getTexture(texType);
        if (texture)
        {
            auto ospTexture = _createOSPTexture2D(texture);
            const auto str =
                textureTypeMaterialAttribute[texType].attribute.c_str();
            ospSetObject(_ospMaterial, str, ospTexture);
            ospRelease(ospTexture);
        }
    }

    ospCommit(_ospMaterial);
    resetModified();
}
コード例 #7
0
ファイル: OSPRayMaterial.cpp プロジェクト: chevtche/Brayns
OSPTexture OSPRayMaterial::_createOSPTexture2D(Texture2DPtr texture)
{
    OSPTextureFormat type = OSP_TEXTURE_R8; // smallest valid type as default
    if (texture->getDepth() == 1)
    {
        if (texture->getNbChannels() == 1)
            type = OSP_TEXTURE_R8;
        if (texture->getNbChannels() == 3)
            type = OSP_TEXTURE_RGB8;
        if (texture->getNbChannels() == 4)
            type = OSP_TEXTURE_RGBA8;
    }
    else if (texture->getDepth() == 4)
    {
        if (texture->getNbChannels() == 1)
            type = OSP_TEXTURE_R32F;
        if (texture->getNbChannels() == 3)
            type = OSP_TEXTURE_RGB32F;
        if (texture->getNbChannels() == 4)
            type = OSP_TEXTURE_RGBA32F;
    }

    BRAYNS_DEBUG << "Creating OSPRay texture from " << texture->getFilename()
                 << ": " << texture->getWidth() << "x" << texture->getHeight()
                 << "x" << (int)type << std::endl;

    OSPTexture ospTexture = ospNewTexture("texture2d");

    const Vector2i size{int(texture->getWidth()), int(texture->getHeight())};

    osphelper::set(ospTexture, "type", static_cast<int>(type));
    osphelper::set(ospTexture, "size", size);
    auto textureData =
        ospNewData(texture->getSizeInBytes(), OSP_RAW, texture->getRawData(),
                   OSP_DATA_SHARED_BUFFER);
    ospSetObject(ospTexture, "data", textureData);
    ospRelease(textureData);
    ospCommit(ospTexture);

    return ospTexture;
}
コード例 #8
0
ファイル: Renderer.cpp プロジェクト: TACC/VolViewer
Renderer::~Renderer()
{
	delete window;
	ospRelease(renderer);
}
コード例 #9
0
ファイル: Node.cpp プロジェクト: ospray/OSPRay
 Node::~Node()
 {
   // Call ospRelease() if the value is an OSPObject handle
   if (valueIsType<OSPObject>())
     ospRelease(valueAs<OSPObject>());
 }
コード例 #10
0
ファイル: OSPRayMaterial.cpp プロジェクト: chevtche/Brayns
OSPRayMaterial::~OSPRayMaterial()
{
    ospRelease(_ospMaterial);
}