2016-08-26 21:58:21 +00:00
|
|
|
//============================================================================
|
|
|
|
// Copyright (c) Kitware, Inc.
|
|
|
|
// All rights reserved.
|
|
|
|
// See LICENSE.txt for details.
|
|
|
|
// This software is distributed WITHOUT ANY WARRANTY; without even
|
|
|
|
// the implied warranty of MERCHANTABILITY or FITNESS FOR A PARTICULAR
|
|
|
|
// PURPOSE. See the above copyright notice for more information.
|
|
|
|
//
|
2017-09-20 21:33:44 +00:00
|
|
|
// Copyright 2016 National Technology & Engineering Solutions of Sandia, LLC (NTESS).
|
2016-08-26 21:58:21 +00:00
|
|
|
// Copyright 2016 UT-Battelle, LLC.
|
|
|
|
// Copyright 2016 Los Alamos National Security.
|
|
|
|
//
|
2017-09-20 21:33:44 +00:00
|
|
|
// Under the terms of Contract DE-NA0003525 with NTESS,
|
2016-08-26 21:58:21 +00:00
|
|
|
// the U.S. Government retains certain rights in this software.
|
|
|
|
//
|
|
|
|
// Under the terms of Contract DE-AC52-06NA25396 with Los Alamos National
|
|
|
|
// Laboratory (LANL), the U.S. Government retains certain rights in
|
|
|
|
// this software.
|
|
|
|
//============================================================================
|
|
|
|
|
|
|
|
#include <vtkm/rendering/CanvasOSMesa.h>
|
|
|
|
|
|
|
|
#include <vtkm/Types.h>
|
|
|
|
#include <vtkm/rendering/CanvasGL.h>
|
|
|
|
#include <vtkm/rendering/Color.h>
|
|
|
|
#include <vtkm/rendering/internal/OpenGLHeaders.h>
|
2016-09-22 20:44:52 +00:00
|
|
|
#ifndef GLAPI
|
|
|
|
#define GLAPI extern
|
|
|
|
#endif
|
2016-08-26 21:58:21 +00:00
|
|
|
|
2016-09-22 20:44:52 +00:00
|
|
|
#ifndef GLAPIENTRY
|
|
|
|
#define GLAPIENTRY
|
|
|
|
#endif
|
|
|
|
|
|
|
|
#ifndef APIENTRY
|
|
|
|
#define APIENTRY GLAPIENTRY
|
|
|
|
#endif
|
2016-08-26 21:58:21 +00:00
|
|
|
#include <GL/osmesa.h>
|
|
|
|
|
2017-05-18 14:29:41 +00:00
|
|
|
namespace vtkm
|
|
|
|
{
|
|
|
|
namespace rendering
|
|
|
|
{
|
2016-08-26 21:58:21 +00:00
|
|
|
|
2017-05-18 14:29:41 +00:00
|
|
|
namespace detail
|
|
|
|
{
|
2016-08-26 21:58:21 +00:00
|
|
|
|
|
|
|
struct CanvasOSMesaInternals
|
|
|
|
{
|
|
|
|
OSMesaContext Context;
|
|
|
|
};
|
|
|
|
|
|
|
|
} // namespace detail
|
|
|
|
|
|
|
|
CanvasOSMesa::CanvasOSMesa(vtkm::Id width, vtkm::Id height)
|
2017-05-18 14:29:41 +00:00
|
|
|
: CanvasGL(width, height)
|
|
|
|
, Internals(new detail::CanvasOSMesaInternals)
|
2016-08-26 21:58:21 +00:00
|
|
|
{
|
|
|
|
this->Internals->Context = nullptr;
|
|
|
|
this->ResizeBuffers(width, height);
|
|
|
|
}
|
|
|
|
|
|
|
|
CanvasOSMesa::~CanvasOSMesa()
|
|
|
|
{
|
|
|
|
}
|
|
|
|
|
|
|
|
void CanvasOSMesa::Initialize()
|
|
|
|
{
|
2017-05-18 14:29:41 +00:00
|
|
|
this->Internals->Context = OSMesaCreateContextExt(OSMESA_RGBA, 32, 0, 0, nullptr);
|
2016-09-22 20:44:52 +00:00
|
|
|
|
2016-08-26 21:58:21 +00:00
|
|
|
if (!this->Internals->Context)
|
|
|
|
{
|
2017-01-09 21:15:32 +00:00
|
|
|
throw vtkm::cont::ErrorBadValue("OSMesa context creation failed.");
|
2016-08-26 21:58:21 +00:00
|
|
|
}
|
2017-05-18 14:29:41 +00:00
|
|
|
vtkm::Vec<vtkm::Float32, 4>* colorBuffer = this->GetColorBuffer().GetStorage().GetArray();
|
2017-05-26 17:53:28 +00:00
|
|
|
if (!OSMesaMakeCurrent(this->Internals->Context,
|
|
|
|
reinterpret_cast<vtkm::Float32*>(colorBuffer),
|
|
|
|
GL_FLOAT,
|
|
|
|
static_cast<GLsizei>(this->GetWidth()),
|
2016-08-26 21:58:21 +00:00
|
|
|
static_cast<GLsizei>(this->GetHeight())))
|
|
|
|
{
|
2017-01-09 21:15:32 +00:00
|
|
|
throw vtkm::cont::ErrorBadValue("OSMesa context activation failed.");
|
2016-08-26 21:58:21 +00:00
|
|
|
}
|
|
|
|
}
|
|
|
|
|
2016-09-01 18:33:28 +00:00
|
|
|
void CanvasOSMesa::RefreshColorBuffer() const
|
2016-08-26 21:58:21 +00:00
|
|
|
{
|
|
|
|
// Override superclass because our OSMesa implementation renders right
|
|
|
|
// to the color buffer.
|
|
|
|
}
|
|
|
|
|
|
|
|
void CanvasOSMesa::Activate()
|
|
|
|
{
|
|
|
|
glEnable(GL_DEPTH_TEST);
|
|
|
|
}
|
|
|
|
|
|
|
|
void CanvasOSMesa::Finish()
|
|
|
|
{
|
|
|
|
this->CanvasGL::Finish();
|
|
|
|
|
2017-05-18 14:29:41 +00:00
|
|
|
// This is disabled because it is handled in RefreshDepthBuffer
|
2016-08-26 21:58:21 +00:00
|
|
|
#if 0
|
|
|
|
//Copy zbuff into floating point array.
|
|
|
|
unsigned int *raw_zbuff;
|
|
|
|
int zbytes, w, h;
|
|
|
|
GLboolean ret;
|
|
|
|
ret = OSMesaGetDepthBuffer(this->Internals->Context, &w, &h, &zbytes, (void**)&raw_zbuff);
|
|
|
|
if (!ret ||
|
|
|
|
static_cast<vtkm::Id>(w)!=this->GetWidth() ||
|
|
|
|
static_cast<vtkm::Id>(h)!=this->GetHeight())
|
|
|
|
{
|
2017-01-09 21:15:32 +00:00
|
|
|
throw vtkm::cont::ErrorBadValue("Wrong width/height in ZBuffer");
|
2016-08-26 21:58:21 +00:00
|
|
|
}
|
|
|
|
vtkm::cont::ArrayHandle<vtkm::Float32>::PortalControl depthPortal =
|
|
|
|
this->GetDepthBuffer().GetPortalControl();
|
|
|
|
vtkm::Id npixels = this->GetWidth()*this->GetHeight();
|
|
|
|
for (vtkm::Id i=0; i<npixels; i++)
|
|
|
|
for (std::size_t i=0; i<npixels; i++)
|
|
|
|
{
|
|
|
|
depthPortal.Set(i, float(raw_zbuff[i]) / float(UINT_MAX));
|
|
|
|
}
|
|
|
|
#endif
|
|
|
|
}
|
|
|
|
|
2017-05-18 14:29:41 +00:00
|
|
|
vtkm::rendering::Canvas* CanvasOSMesa::NewCopy() const
|
2016-09-01 18:33:28 +00:00
|
|
|
{
|
|
|
|
return new vtkm::rendering::CanvasOSMesa(*this);
|
|
|
|
}
|
2016-08-26 21:58:21 +00:00
|
|
|
}
|
|
|
|
} // namespace vtkm::rendering
|