mirror of
https://gitlab.kitware.com/vtk/vtk-m
synced 2024-09-16 17:22:55 +00:00
Merge topic 'fix-303-remove-opengl-rendering-classes'
48ee2e518 removed classes related to OpenGL/OSMESA/EGL Acked-by: Kitware Robot <kwrobot@kitware.com> Acked-by: Matt Larsen <larsen30@llnl.gov> Merge-request: !2010
This commit is contained in:
commit
048652e25b
@ -16,23 +16,6 @@ if(NOT VTKm_ENABLE_RENDERING)
|
||||
return()
|
||||
endif()
|
||||
|
||||
# determine what context(s) for rendering we want to build
|
||||
vtkm_option(VTKm_ENABLE_GL_CONTEXT "Enable GL context for vtkm rendering" OFF)
|
||||
if(UNIX AND NOT APPLE)
|
||||
vtkm_option(VTKm_ENABLE_OSMESA_CONTEXT "Enable OSMesa context for vtkm rendering" OFF)
|
||||
vtkm_option(VTKm_ENABLE_EGL_CONTEXT "Enable EGL context for vtkm rendering" OFF)
|
||||
mark_as_advanced(VTKm_ENABLE_OSMESA_CONTEXT)
|
||||
mark_as_advanced(VTKm_ENABLE_EGL_CONTEXT)
|
||||
endif()
|
||||
if(VTKm_ENABLE_GL_CONTEXT AND VTKm_ENABLE_OSMESA_CONTEXT)
|
||||
message(FATAL_ERROR "VTK-m GL and OSMesa contexts are mutually exclusive")
|
||||
endif()
|
||||
if(VTKm_ENABLE_GL_CONTEXT AND VTKm_ENABLE_EGL_CONTEXT)
|
||||
message(FATAL_ERROR "VTK-m GL and EGL contexts are mutually exclusive")
|
||||
endif()
|
||||
if(VTKm_ENABLE_EGL_CONTEXT AND VTKm_ENABLE_OSMESA_CONTEXT)
|
||||
message(FATAL_ERROR "VTK-m EGL and OSMesa contexts are mutually exclusive")
|
||||
endif()
|
||||
|
||||
set(headers
|
||||
Actor.h
|
||||
@ -144,37 +127,7 @@ set(device_sources
|
||||
raytracing/VolumeRendererStructured.cxx
|
||||
)
|
||||
|
||||
# Note that EGL and OSMesa Canvas depend on the GL version being built. Only
|
||||
# the None backend supports not building the opengl version
|
||||
set(opengl_headers
|
||||
CanvasGL.h
|
||||
MapperGL.h
|
||||
TextureGL.h
|
||||
WorldAnnotatorGL.h
|
||||
)
|
||||
|
||||
set(opengl_sources
|
||||
CanvasGL.cxx
|
||||
MapperGL.cxx
|
||||
TextureGL.cxx
|
||||
WorldAnnotatorGL.cxx
|
||||
)
|
||||
|
||||
set(egl_headers
|
||||
CanvasEGL.h
|
||||
)
|
||||
|
||||
set(egl_sources
|
||||
CanvasEGL.cxx
|
||||
)
|
||||
|
||||
set(osmesa_headers
|
||||
CanvasOSMesa.h
|
||||
)
|
||||
|
||||
set(osmesa_sources
|
||||
CanvasOSMesa.cxx
|
||||
)
|
||||
|
||||
#-----------------------------------------------------------------------------
|
||||
vtkm_library(
|
||||
@ -184,19 +137,6 @@ vtkm_library(
|
||||
DEVICE_SOURCES ${device_sources}
|
||||
)
|
||||
|
||||
# Install all headers no matter what backend was selected
|
||||
vtkm_declare_headers(${opengl_headers})
|
||||
vtkm_declare_headers(${osmesa_headers})
|
||||
vtkm_declare_headers(${egl_headers})
|
||||
|
||||
if(VTKm_ENABLE_GL_CONTEXT)
|
||||
target_sources(vtkm_rendering PRIVATE ${opengl_sources})
|
||||
elseif(VTKm_ENABLE_OSMESA_CONTEXT)
|
||||
target_sources(vtkm_rendering PRIVATE ${opengl_sources} ${osmesa_sources})
|
||||
elseif(VTKm_ENABLE_EGL_CONTEXT)
|
||||
target_sources(vtkm_rendering PRIVATE ${opengl_sources} ${egl_sources})
|
||||
endif()
|
||||
|
||||
#-----------------------------------------------------------------------------
|
||||
target_link_libraries(vtkm_rendering PUBLIC vtkm_filter vtkm_io)
|
||||
if(UNIX AND NOT APPLE)
|
||||
|
@ -1,122 +0,0 @@
|
||||
//============================================================================
|
||||
// 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.
|
||||
//============================================================================
|
||||
|
||||
#include <vtkm/rendering/CanvasEGL.h>
|
||||
|
||||
#include <vtkm/Types.h>
|
||||
#include <vtkm/cont/ArrayPortalToIterators.h>
|
||||
#include <vtkm/rendering/CanvasGL.h>
|
||||
#include <vtkm/rendering/Color.h>
|
||||
#include <vtkm/rendering/internal/OpenGLHeaders.h>
|
||||
|
||||
#include <EGL/egl.h>
|
||||
//#include <GL/gl.h>
|
||||
|
||||
namespace vtkm
|
||||
{
|
||||
namespace rendering
|
||||
{
|
||||
|
||||
namespace detail
|
||||
{
|
||||
|
||||
struct CanvasEGLInternals
|
||||
{
|
||||
EGLContext Context;
|
||||
EGLDisplay Display;
|
||||
EGLSurface Surface;
|
||||
};
|
||||
|
||||
} // namespace detail
|
||||
|
||||
CanvasEGL::CanvasEGL(vtkm::Id width, vtkm::Id height)
|
||||
: CanvasGL(width, height)
|
||||
, Internals(new detail::CanvasEGLInternals)
|
||||
{
|
||||
this->Internals->Context = nullptr;
|
||||
this->ResizeBuffers(width, height);
|
||||
}
|
||||
|
||||
CanvasEGL::~CanvasEGL()
|
||||
{
|
||||
}
|
||||
|
||||
void CanvasEGL::Initialize()
|
||||
{
|
||||
this->Internals->Display = eglGetDisplay(EGL_DEFAULT_DISPLAY);
|
||||
if (!(this->Internals->Display))
|
||||
{
|
||||
throw vtkm::cont::ErrorBadValue("Failed to get EGL display");
|
||||
}
|
||||
EGLint major, minor;
|
||||
if (!(eglInitialize(this->Internals->Display, &major, &minor)))
|
||||
{
|
||||
throw vtkm::cont::ErrorBadValue("Failed to initialize EGL display");
|
||||
}
|
||||
|
||||
const EGLint cfgAttrs[] = { EGL_SURFACE_TYPE,
|
||||
EGL_PBUFFER_BIT,
|
||||
EGL_BLUE_SIZE,
|
||||
8,
|
||||
EGL_GREEN_SIZE,
|
||||
8,
|
||||
EGL_RED_SIZE,
|
||||
8,
|
||||
EGL_DEPTH_SIZE,
|
||||
8,
|
||||
EGL_RENDERABLE_TYPE,
|
||||
EGL_OPENGL_BIT,
|
||||
EGL_NONE };
|
||||
|
||||
EGLint nCfgs;
|
||||
EGLConfig cfg;
|
||||
if (!(eglChooseConfig(this->Internals->Display, cfgAttrs, &cfg, 1, &nCfgs)) || (nCfgs == 0))
|
||||
{
|
||||
throw vtkm::cont::ErrorBadValue("Failed to get EGL config");
|
||||
}
|
||||
|
||||
const EGLint pbAttrs[] = {
|
||||
EGL_WIDTH, static_cast<EGLint>(this->GetWidth()),
|
||||
EGL_HEIGHT, static_cast<EGLint>(this->GetHeight()),
|
||||
EGL_NONE,
|
||||
};
|
||||
|
||||
this->Internals->Surface = eglCreatePbufferSurface(this->Internals->Display, cfg, pbAttrs);
|
||||
if (!this->Internals->Surface)
|
||||
{
|
||||
throw vtkm::cont::ErrorBadValue("Failed to create EGL PBuffer surface");
|
||||
}
|
||||
eglBindAPI(EGL_OPENGL_API);
|
||||
this->Internals->Context =
|
||||
eglCreateContext(this->Internals->Display, cfg, EGL_NO_CONTEXT, nullptr);
|
||||
if (!this->Internals->Context)
|
||||
{
|
||||
throw vtkm::cont::ErrorBadValue("Failed to create EGL context");
|
||||
}
|
||||
if (!(eglMakeCurrent(this->Internals->Display,
|
||||
this->Internals->Surface,
|
||||
this->Internals->Surface,
|
||||
this->Internals->Context)))
|
||||
{
|
||||
throw vtkm::cont::ErrorBadValue("Failed to create EGL context current");
|
||||
}
|
||||
}
|
||||
|
||||
void CanvasEGL::Activate()
|
||||
{
|
||||
glEnable(GL_DEPTH_TEST);
|
||||
}
|
||||
|
||||
vtkm::rendering::Canvas* CanvasEGL::NewCopy() const
|
||||
{
|
||||
return new vtkm::rendering::CanvasEGL(*this);
|
||||
}
|
||||
}
|
||||
} // namespace vtkm::rendering
|
@ -1,49 +0,0 @@
|
||||
//============================================================================
|
||||
// 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.
|
||||
//============================================================================
|
||||
#ifndef vtk_m_rendering_CanvasEGL_h
|
||||
#define vtk_m_rendering_CanvasEGL_h
|
||||
|
||||
#include <vtkm/rendering/vtkm_rendering_export.h>
|
||||
|
||||
#include <vtkm/rendering/CanvasGL.h>
|
||||
|
||||
#include <memory>
|
||||
|
||||
namespace vtkm
|
||||
{
|
||||
namespace rendering
|
||||
{
|
||||
|
||||
namespace detail
|
||||
{
|
||||
|
||||
struct CanvasEGLInternals;
|
||||
}
|
||||
|
||||
class VTKM_RENDERING_EXPORT CanvasEGL : public CanvasGL
|
||||
{
|
||||
public:
|
||||
CanvasEGL(vtkm::Id width = 1024, vtkm::Id height = 1024);
|
||||
|
||||
~CanvasEGL();
|
||||
|
||||
virtual void Initialize() override;
|
||||
|
||||
virtual void Activate() override;
|
||||
|
||||
vtkm::rendering::Canvas* NewCopy() const override;
|
||||
|
||||
private:
|
||||
std::shared_ptr<detail::CanvasEGLInternals> Internals;
|
||||
};
|
||||
}
|
||||
} //namespace vtkm::rendering
|
||||
|
||||
#endif //vtk_m_rendering_CanvasEGL_h
|
@ -1,353 +0,0 @@
|
||||
//============================================================================
|
||||
// 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.
|
||||
//============================================================================
|
||||
|
||||
#include <vtkm/rendering/CanvasGL.h>
|
||||
|
||||
#include <vtkm/rendering/BitmapFontFactory.h>
|
||||
#include <vtkm/rendering/Camera.h>
|
||||
#include <vtkm/rendering/Canvas.h>
|
||||
#include <vtkm/rendering/Color.h>
|
||||
#include <vtkm/rendering/DecodePNG.h>
|
||||
#include <vtkm/rendering/MatrixHelpers.h>
|
||||
#include <vtkm/rendering/WorldAnnotatorGL.h>
|
||||
#include <vtkm/rendering/internal/OpenGLHeaders.h>
|
||||
|
||||
#include <vtkm/cont/ColorTable.hxx>
|
||||
|
||||
namespace vtkm
|
||||
{
|
||||
namespace rendering
|
||||
{
|
||||
|
||||
CanvasGL::CanvasGL(vtkm::Id width, vtkm::Id height)
|
||||
: Canvas(width, height)
|
||||
{
|
||||
}
|
||||
|
||||
CanvasGL::~CanvasGL()
|
||||
{
|
||||
}
|
||||
|
||||
void CanvasGL::Initialize()
|
||||
{
|
||||
// Nothing to initialize
|
||||
}
|
||||
|
||||
void CanvasGL::Activate()
|
||||
{
|
||||
GLint viewport[4];
|
||||
glGetIntegerv(GL_VIEWPORT, viewport);
|
||||
this->ResizeBuffers(viewport[2], viewport[3]);
|
||||
|
||||
glEnable(GL_DEPTH_TEST);
|
||||
}
|
||||
|
||||
void CanvasGL::Clear()
|
||||
{
|
||||
vtkm::rendering::Color backgroundColor = this->GetBackgroundColor();
|
||||
glClearColor(backgroundColor.Components[0],
|
||||
backgroundColor.Components[1],
|
||||
backgroundColor.Components[2],
|
||||
1.0f);
|
||||
glClear(GL_COLOR_BUFFER_BIT | GL_DEPTH_BUFFER_BIT);
|
||||
}
|
||||
|
||||
void CanvasGL::Finish()
|
||||
{
|
||||
glFinish();
|
||||
}
|
||||
|
||||
vtkm::rendering::Canvas* CanvasGL::NewCopy() const
|
||||
{
|
||||
return new vtkm::rendering::CanvasGL(*this);
|
||||
}
|
||||
|
||||
void CanvasGL::SetViewToWorldSpace(const vtkm::rendering::Camera& camera, bool clip)
|
||||
{
|
||||
vtkm::Float32 oglP[16], oglM[16];
|
||||
|
||||
MatrixHelpers::CreateOGLMatrix(camera.CreateProjectionMatrix(this->GetWidth(), this->GetHeight()),
|
||||
oglP);
|
||||
glMatrixMode(GL_PROJECTION);
|
||||
glLoadMatrixf(oglP);
|
||||
MatrixHelpers::CreateOGLMatrix(camera.CreateViewMatrix(), oglM);
|
||||
glMatrixMode(GL_MODELVIEW);
|
||||
glLoadMatrixf(oglM);
|
||||
|
||||
this->SetViewportClipping(camera, clip);
|
||||
}
|
||||
|
||||
void CanvasGL::SetViewToScreenSpace(const vtkm::rendering::Camera& camera, bool clip)
|
||||
{
|
||||
vtkm::Float32 oglP[16] = { 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0 };
|
||||
vtkm::Float32 oglM[16] = { 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0 };
|
||||
|
||||
oglP[0 * 4 + 0] = 1.;
|
||||
oglP[1 * 4 + 1] = 1.;
|
||||
oglP[2 * 4 + 2] = -1.;
|
||||
oglP[3 * 4 + 3] = 1.;
|
||||
|
||||
glMatrixMode(GL_PROJECTION);
|
||||
glLoadMatrixf(oglP);
|
||||
|
||||
oglM[0 * 4 + 0] = 1.;
|
||||
oglM[1 * 4 + 1] = 1.;
|
||||
oglM[2 * 4 + 2] = 1.;
|
||||
oglM[3 * 4 + 3] = 1.;
|
||||
|
||||
glMatrixMode(GL_MODELVIEW);
|
||||
glLoadMatrixf(oglM);
|
||||
|
||||
this->SetViewportClipping(camera, clip);
|
||||
}
|
||||
|
||||
void CanvasGL::SetViewportClipping(const vtkm::rendering::Camera& camera, bool clip)
|
||||
{
|
||||
if (clip)
|
||||
{
|
||||
vtkm::Float32 vl, vr, vb, vt;
|
||||
camera.GetRealViewport(this->GetWidth(), this->GetHeight(), vl, vr, vb, vt);
|
||||
vtkm::Float32 _x = static_cast<vtkm::Float32>(this->GetWidth()) * (1.f + vl) / 2.f;
|
||||
vtkm::Float32 _y = static_cast<vtkm::Float32>(this->GetHeight()) * (1.f + vb) / 2.f;
|
||||
vtkm::Float32 _w = static_cast<vtkm::Float32>(this->GetWidth()) * (vr - vl) / 2.f;
|
||||
vtkm::Float32 _h = static_cast<vtkm::Float32>(this->GetHeight()) * (vt - vb) / 2.f;
|
||||
|
||||
glViewport(static_cast<GLint>(_x),
|
||||
static_cast<GLint>(_y),
|
||||
static_cast<GLsizei>(_w),
|
||||
static_cast<GLsizei>(_h));
|
||||
}
|
||||
else
|
||||
{
|
||||
glViewport(
|
||||
0, 0, static_cast<GLsizei>(this->GetWidth()), static_cast<GLsizei>(this->GetHeight()));
|
||||
}
|
||||
}
|
||||
|
||||
void CanvasGL::RefreshColorBuffer() const
|
||||
{
|
||||
GLint viewport[4];
|
||||
glGetIntegerv(GL_VIEWPORT, viewport);
|
||||
VTKM_ASSERT(viewport[2] == this->GetWidth());
|
||||
VTKM_ASSERT(viewport[3] == this->GetHeight());
|
||||
|
||||
glReadPixels(viewport[0],
|
||||
viewport[1],
|
||||
viewport[2],
|
||||
viewport[3],
|
||||
GL_RGBA,
|
||||
GL_FLOAT,
|
||||
const_cast<vtkm::Vec<float, 4>*>(this->GetColorBuffer().GetStorage().GetArray()));
|
||||
}
|
||||
|
||||
void CanvasGL::RefreshDepthBuffer() const
|
||||
{
|
||||
GLint viewport[4];
|
||||
glGetIntegerv(GL_VIEWPORT, viewport);
|
||||
VTKM_ASSERT(viewport[2] == this->GetWidth());
|
||||
VTKM_ASSERT(viewport[3] == this->GetHeight());
|
||||
|
||||
glReadPixels(viewport[0],
|
||||
viewport[1],
|
||||
viewport[2],
|
||||
viewport[3],
|
||||
GL_DEPTH_COMPONENT,
|
||||
GL_FLOAT,
|
||||
const_cast<vtkm::Float32*>(this->GetDepthBuffer().GetStorage().GetArray()));
|
||||
}
|
||||
|
||||
void CanvasGL::AddColorSwatch(const vtkm::Vec2f_64& point0,
|
||||
const vtkm::Vec2f_64& point1,
|
||||
const vtkm::Vec2f_64& point2,
|
||||
const vtkm::Vec2f_64& point3,
|
||||
const vtkm::rendering::Color& color) const
|
||||
{
|
||||
glDisable(GL_DEPTH_TEST);
|
||||
glDisable(GL_LIGHTING);
|
||||
|
||||
glBegin(GL_QUADS);
|
||||
glColor3f(color.Components[0], color.Components[1], color.Components[2]);
|
||||
glTexCoord1f(0);
|
||||
glVertex3f(float(point0[0]), float(point0[1]), .99f);
|
||||
glVertex3f(float(point1[0]), float(point1[1]), .99f);
|
||||
|
||||
glTexCoord1f(1);
|
||||
glVertex3f(float(point2[0]), float(point2[1]), .99f);
|
||||
glVertex3f(float(point3[0]), float(point3[1]), .99f);
|
||||
glEnd();
|
||||
}
|
||||
|
||||
void CanvasGL::AddLine(const vtkm::Vec2f_64& point0,
|
||||
const vtkm::Vec2f_64& point1,
|
||||
vtkm::Float32 linewidth,
|
||||
const vtkm::rendering::Color& color) const
|
||||
{
|
||||
glDisable(GL_DEPTH_TEST);
|
||||
glDisable(GL_LIGHTING);
|
||||
glColor3f(color.Components[0], color.Components[1], color.Components[2]);
|
||||
|
||||
glLineWidth(linewidth);
|
||||
|
||||
glBegin(GL_LINES);
|
||||
glVertex2f(float(point0[0]), float(point0[1]));
|
||||
glVertex2f(float(point1[0]), float(point1[1]));
|
||||
glEnd();
|
||||
}
|
||||
|
||||
void CanvasGL::AddColorBar(const vtkm::Bounds& bounds,
|
||||
const vtkm::cont::ColorTable& colorTable,
|
||||
bool horizontal) const
|
||||
{
|
||||
const int n = 256;
|
||||
//map through the color table for our 256 + 1 points as the first step
|
||||
vtkm::cont::ArrayHandle<vtkm::Vec3ui_8> colors;
|
||||
colorTable.Sample(n + 1, colors);
|
||||
|
||||
vtkm::Float32 startX = static_cast<vtkm::Float32>(bounds.X.Min);
|
||||
vtkm::Float32 startY = static_cast<vtkm::Float32>(bounds.Y.Min);
|
||||
vtkm::Float32 width = static_cast<vtkm::Float32>(bounds.X.Length());
|
||||
vtkm::Float32 height = static_cast<vtkm::Float32>(bounds.Y.Length());
|
||||
glDisable(GL_DEPTH_TEST);
|
||||
glDisable(GL_LIGHTING);
|
||||
glBegin(GL_QUADS);
|
||||
|
||||
auto colorPortal = colors.ReadPortal();
|
||||
|
||||
for (int i = 0; i < n; i++)
|
||||
{
|
||||
vtkm::Float32 v0 = static_cast<vtkm::Float32>(i) / static_cast<vtkm::Float32>(n);
|
||||
vtkm::Float32 v1 = static_cast<vtkm::Float32>(i + 1) / static_cast<vtkm::Float32>(n);
|
||||
auto c0 = colorPortal.Get(i);
|
||||
auto c1 = colorPortal.Get(i + 1);
|
||||
if (horizontal)
|
||||
{
|
||||
vtkm::Float32 x0 = startX + width * v0;
|
||||
vtkm::Float32 x1 = startX + width * v1;
|
||||
vtkm::Float32 y0 = startY;
|
||||
vtkm::Float32 y1 = startY + height;
|
||||
glColor3ub(c0[0], c0[1], c0[2]);
|
||||
glVertex2f(x0, y0);
|
||||
glVertex2f(x0, y1);
|
||||
glColor3ub(c1[0], c1[1], c1[2]);
|
||||
glVertex2f(x1, y1);
|
||||
glVertex2f(x1, y0);
|
||||
}
|
||||
else // vertical
|
||||
{
|
||||
vtkm::Float32 x0 = startX;
|
||||
vtkm::Float32 x1 = startX + width;
|
||||
vtkm::Float32 y0 = startY + height * v0;
|
||||
vtkm::Float32 y1 = startY + height * v1;
|
||||
glColor3ub(c0[0], c0[1], c0[2]);
|
||||
glVertex2f(x0, y1);
|
||||
glVertex2f(x1, y1);
|
||||
glColor3ub(c1[0], c1[1], c1[2]);
|
||||
glVertex2f(x1, y0);
|
||||
glVertex2f(x0, y0);
|
||||
}
|
||||
}
|
||||
glEnd();
|
||||
}
|
||||
|
||||
void CanvasGL::AddText(const vtkm::Vec2f_32& position,
|
||||
vtkm::Float32 scale,
|
||||
vtkm::Float32 angle,
|
||||
vtkm::Float32 windowAspect,
|
||||
const vtkm::Vec2f_32& anchor,
|
||||
const vtkm::rendering::Color& color,
|
||||
const std::string& text) const
|
||||
{
|
||||
glPushMatrix();
|
||||
glTranslatef(position[0], position[1], 0);
|
||||
glScalef(1.f / windowAspect, 1, 1);
|
||||
glRotatef(angle, 0, 0, 1);
|
||||
glColor3f(color.Components[0], color.Components[1], color.Components[2]);
|
||||
this->RenderText(scale, anchor, text);
|
||||
glPopMatrix();
|
||||
}
|
||||
|
||||
vtkm::rendering::WorldAnnotator* CanvasGL::CreateWorldAnnotator() const
|
||||
{
|
||||
return new vtkm::rendering::WorldAnnotatorGL(this);
|
||||
}
|
||||
|
||||
void CanvasGL::RenderText(vtkm::Float32 scale,
|
||||
const vtkm::Vec2f_32& anchor,
|
||||
const std::string& text) const
|
||||
{
|
||||
if (!this->FontTexture.Valid())
|
||||
{
|
||||
// When we load a font, we save a reference to it for the next time we
|
||||
// use it. Although technically we are changing the state, the logical
|
||||
// state does not change, so we go ahead and do it in this const
|
||||
// function.
|
||||
vtkm::rendering::CanvasGL* self = const_cast<vtkm::rendering::CanvasGL*>(this);
|
||||
self->Font = BitmapFontFactory::CreateLiberation2Sans();
|
||||
const std::vector<unsigned char>& rawpngdata = this->Font.GetRawImageData();
|
||||
|
||||
std::vector<unsigned char> rgba;
|
||||
unsigned long width, height;
|
||||
int error = vtkm::rendering::DecodePNG(rgba, width, height, &rawpngdata[0], rawpngdata.size());
|
||||
if (error != 0)
|
||||
{
|
||||
return;
|
||||
}
|
||||
|
||||
self->FontTexture.CreateAlphaFromRGBA(int(width), int(height), rgba);
|
||||
}
|
||||
|
||||
this->FontTexture.Enable();
|
||||
|
||||
glDepthMask(GL_FALSE);
|
||||
glBlendFunc(GL_SRC_ALPHA, GL_ONE_MINUS_SRC_ALPHA);
|
||||
glEnable(GL_BLEND);
|
||||
glTexEnvf(GL_TEXTURE_ENV, GL_TEXTURE_ENV_MODE, GL_MODULATE);
|
||||
glDisable(GL_LIGHTING);
|
||||
//glTexEnvf(GL_TEXTURE_FILTER_CONTROL, GL_TEXTURE_LOD_BIAS, -.5);
|
||||
|
||||
glBegin(GL_QUADS);
|
||||
|
||||
vtkm::Float32 textwidth = this->Font.GetTextWidth(text);
|
||||
|
||||
vtkm::Float32 fx = -(.5f + .5f * anchor[0]) * textwidth;
|
||||
vtkm::Float32 fy = -(.5f + .5f * anchor[1]);
|
||||
vtkm::Float32 fz = 0;
|
||||
for (unsigned int i = 0; i < text.length(); ++i)
|
||||
{
|
||||
char c = text[i];
|
||||
char nextchar = (i < text.length() - 1) ? text[i + 1] : 0;
|
||||
|
||||
vtkm::Float32 vl, vr, vt, vb;
|
||||
vtkm::Float32 tl, tr, tt, tb;
|
||||
this->Font.GetCharPolygon(c, fx, fy, vl, vr, vt, vb, tl, tr, tt, tb, nextchar);
|
||||
|
||||
glTexCoord2f(tl, 1.f - tt);
|
||||
glVertex3f(scale * vl, scale * vt, fz);
|
||||
|
||||
glTexCoord2f(tl, 1.f - tb);
|
||||
glVertex3f(scale * vl, scale * vb, fz);
|
||||
|
||||
glTexCoord2f(tr, 1.f - tb);
|
||||
glVertex3f(scale * vr, scale * vb, fz);
|
||||
|
||||
glTexCoord2f(tr, 1.f - tt);
|
||||
glVertex3f(scale * vr, scale * vt, fz);
|
||||
}
|
||||
|
||||
glEnd();
|
||||
|
||||
this->FontTexture.Disable();
|
||||
|
||||
//glTexEnvf(GL_TEXTURE_FILTER_CONTROL, GL_TEXTURE_LOD_BIAS, 0);
|
||||
glDepthMask(GL_TRUE);
|
||||
glDisable(GL_ALPHA_TEST);
|
||||
}
|
||||
}
|
||||
} // namespace vtkm::rendering
|
@ -1,86 +0,0 @@
|
||||
//============================================================================
|
||||
// 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.
|
||||
//============================================================================
|
||||
#ifndef vtk_m_rendering_CanvasGL_h
|
||||
#define vtk_m_rendering_CanvasGL_h
|
||||
|
||||
#include <vtkm/rendering/vtkm_rendering_export.h>
|
||||
|
||||
#include <vtkm/rendering/BitmapFont.h>
|
||||
#include <vtkm/rendering/Canvas.h>
|
||||
#include <vtkm/rendering/TextureGL.h>
|
||||
|
||||
namespace vtkm
|
||||
{
|
||||
namespace rendering
|
||||
{
|
||||
|
||||
class VTKM_RENDERING_EXPORT CanvasGL : public Canvas
|
||||
{
|
||||
public:
|
||||
CanvasGL(vtkm::Id width = 1024, vtkm::Id height = 1024);
|
||||
|
||||
~CanvasGL();
|
||||
|
||||
void Initialize() override;
|
||||
|
||||
void Activate() override;
|
||||
|
||||
void Clear() override;
|
||||
|
||||
void Finish() override;
|
||||
|
||||
vtkm::rendering::Canvas* NewCopy() const override;
|
||||
|
||||
void SetViewToWorldSpace(const vtkm::rendering::Camera& camera, bool clip) override;
|
||||
|
||||
void SetViewToScreenSpace(const vtkm::rendering::Camera& camera, bool clip) override;
|
||||
|
||||
void SetViewportClipping(const vtkm::rendering::Camera& camera, bool clip) override;
|
||||
|
||||
void RefreshColorBuffer() const override;
|
||||
|
||||
virtual void RefreshDepthBuffer() const override;
|
||||
|
||||
vtkm::rendering::WorldAnnotator* CreateWorldAnnotator() const override;
|
||||
|
||||
protected:
|
||||
void AddLine(const vtkm::Vec2f_64& point0,
|
||||
const vtkm::Vec2f_64& point1,
|
||||
vtkm::Float32 linewidth,
|
||||
const vtkm::rendering::Color& color) const override;
|
||||
|
||||
void AddColorBar(const vtkm::Bounds& bounds,
|
||||
const vtkm::cont::ColorTable& colorTable,
|
||||
bool horizontal) const override;
|
||||
|
||||
void AddColorSwatch(const vtkm::Vec2f_64& point0,
|
||||
const vtkm::Vec2f_64& point1,
|
||||
const vtkm::Vec2f_64& point2,
|
||||
const vtkm::Vec2f_64& point3,
|
||||
const vtkm::rendering::Color& color) const override;
|
||||
|
||||
void AddText(const vtkm::Vec2f_32& position,
|
||||
vtkm::Float32 scale,
|
||||
vtkm::Float32 angle,
|
||||
vtkm::Float32 windowAspect,
|
||||
const vtkm::Vec2f_32& anchor,
|
||||
const vtkm::rendering::Color& color,
|
||||
const std::string& text) const override;
|
||||
|
||||
private:
|
||||
vtkm::rendering::BitmapFont Font;
|
||||
vtkm::rendering::TextureGL FontTexture;
|
||||
|
||||
void RenderText(vtkm::Float32 scale, const vtkm::Vec2f_32& anchor, const std::string& text) const;
|
||||
};
|
||||
}
|
||||
} //namespace vtkm::rendering
|
||||
|
||||
#endif //vtk_m_rendering_CanvasGL_h
|
@ -1,120 +0,0 @@
|
||||
//============================================================================
|
||||
// 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.
|
||||
//============================================================================
|
||||
|
||||
#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>
|
||||
#ifndef GLAPI
|
||||
#define GLAPI extern
|
||||
#endif
|
||||
|
||||
#ifndef GLAPIENTRY
|
||||
#define GLAPIENTRY
|
||||
#endif
|
||||
|
||||
#ifndef APIENTRY
|
||||
#define APIENTRY GLAPIENTRY
|
||||
#endif
|
||||
#include <GL/osmesa.h>
|
||||
|
||||
namespace vtkm
|
||||
{
|
||||
namespace rendering
|
||||
{
|
||||
|
||||
namespace detail
|
||||
{
|
||||
|
||||
struct CanvasOSMesaInternals
|
||||
{
|
||||
OSMesaContext Context;
|
||||
};
|
||||
|
||||
} // namespace detail
|
||||
|
||||
CanvasOSMesa::CanvasOSMesa(vtkm::Id width, vtkm::Id height)
|
||||
: CanvasGL(width, height)
|
||||
, Internals(new detail::CanvasOSMesaInternals)
|
||||
{
|
||||
this->Internals->Context = nullptr;
|
||||
this->ResizeBuffers(width, height);
|
||||
}
|
||||
|
||||
CanvasOSMesa::~CanvasOSMesa()
|
||||
{
|
||||
}
|
||||
|
||||
void CanvasOSMesa::Initialize()
|
||||
{
|
||||
this->Internals->Context = OSMesaCreateContextExt(OSMESA_RGBA, 32, 0, 0, nullptr);
|
||||
|
||||
if (!this->Internals->Context)
|
||||
{
|
||||
throw vtkm::cont::ErrorBadValue("OSMesa context creation failed.");
|
||||
}
|
||||
vtkm::Vec4f_32* colorBuffer = this->GetColorBuffer().GetStorage().GetArray();
|
||||
if (!OSMesaMakeCurrent(this->Internals->Context,
|
||||
reinterpret_cast<vtkm::Float32*>(colorBuffer),
|
||||
GL_FLOAT,
|
||||
static_cast<GLsizei>(this->GetWidth()),
|
||||
static_cast<GLsizei>(this->GetHeight())))
|
||||
{
|
||||
throw vtkm::cont::ErrorBadValue("OSMesa context activation failed.");
|
||||
}
|
||||
}
|
||||
|
||||
void CanvasOSMesa::RefreshColorBuffer() const
|
||||
{
|
||||
// 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();
|
||||
|
||||
// This is disabled because it is handled in RefreshDepthBuffer
|
||||
#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())
|
||||
{
|
||||
throw vtkm::cont::ErrorBadValue("Wrong width/height in ZBuffer");
|
||||
}
|
||||
vtkm::cont::ArrayHandle<vtkm::Float32>::WritePortalType depthPortal =
|
||||
this->GetDepthBuffer().WritePortal();
|
||||
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
|
||||
}
|
||||
|
||||
vtkm::rendering::Canvas* CanvasOSMesa::NewCopy() const
|
||||
{
|
||||
return new vtkm::rendering::CanvasOSMesa(*this);
|
||||
}
|
||||
}
|
||||
} // namespace vtkm::rendering
|
@ -1,54 +0,0 @@
|
||||
//============================================================================
|
||||
// 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.
|
||||
//============================================================================
|
||||
#ifndef vtk_m_rendering_CanvasOSMesa_h
|
||||
#define vtk_m_rendering_CanvasOSMesa_h
|
||||
|
||||
#include <vtkm/rendering/vtkm_rendering_export.h>
|
||||
|
||||
#include <vtkm/rendering/CanvasGL.h>
|
||||
|
||||
#include <memory>
|
||||
|
||||
namespace vtkm
|
||||
{
|
||||
namespace rendering
|
||||
{
|
||||
|
||||
namespace detail
|
||||
{
|
||||
|
||||
struct CanvasOSMesaInternals;
|
||||
|
||||
} // namespace detail
|
||||
|
||||
class VTKM_RENDERING_EXPORT CanvasOSMesa : public CanvasGL
|
||||
{
|
||||
public:
|
||||
CanvasOSMesa(vtkm::Id width = 1024, vtkm::Id height = 1024);
|
||||
|
||||
~CanvasOSMesa();
|
||||
|
||||
virtual void Initialize() override;
|
||||
|
||||
virtual void RefreshColorBuffer() const override;
|
||||
|
||||
virtual void Activate() override;
|
||||
|
||||
virtual void Finish() override;
|
||||
|
||||
vtkm::rendering::Canvas* NewCopy() const override;
|
||||
|
||||
private:
|
||||
std::shared_ptr<detail::CanvasOSMesaInternals> Internals;
|
||||
};
|
||||
}
|
||||
} //namespace vtkm::rendering
|
||||
|
||||
#endif //vtk_m_rendering_CanvasOSMesa_h
|
@ -1,534 +0,0 @@
|
||||
//============================================================================
|
||||
// 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.
|
||||
//============================================================================
|
||||
|
||||
#include <vtkm/rendering/MapperGL.h>
|
||||
|
||||
#include <vtkm/cont/ArrayHandleIndex.h>
|
||||
#include <vtkm/cont/TryExecute.h>
|
||||
#include <vtkm/rendering/internal/OpenGLHeaders.h>
|
||||
#include <vtkm/rendering/internal/RunTriangulator.h>
|
||||
#include <vtkm/worklet/DispatcherMapField.h>
|
||||
#include <vtkm/worklet/WorkletMapField.h>
|
||||
|
||||
#include <vtkm/exec/ColorTable.h>
|
||||
|
||||
#include <vector>
|
||||
|
||||
namespace vtkm
|
||||
{
|
||||
namespace rendering
|
||||
{
|
||||
|
||||
namespace
|
||||
{
|
||||
|
||||
using Id4Type = TypeListId4;
|
||||
|
||||
class MapColorAndVertices : public vtkm::worklet::WorkletMapField
|
||||
{
|
||||
public:
|
||||
const vtkm::exec::ColorTableBase* ColorTable;
|
||||
const vtkm::Float32 SMin, SDiff;
|
||||
|
||||
VTKM_CONT
|
||||
MapColorAndVertices(const vtkm::exec::ColorTableBase* table,
|
||||
vtkm::Float32 sMin,
|
||||
vtkm::Float32 sDiff)
|
||||
: ColorTable(table)
|
||||
, SMin(sMin)
|
||||
, SDiff(sDiff)
|
||||
{
|
||||
}
|
||||
using ControlSignature = void(FieldIn vertexId,
|
||||
WholeArrayIn indices,
|
||||
WholeArrayIn scalar,
|
||||
WholeArrayIn verts,
|
||||
WholeArrayOut out_color,
|
||||
WholeArrayOut out_vertices);
|
||||
using ExecutionSignature = void(_1, _2, _3, _4, _5, _6);
|
||||
|
||||
template <typename InputArrayIndexPortalType,
|
||||
typename InputArrayPortalType,
|
||||
typename InputArrayV3PortalType,
|
||||
typename OutputArrayPortalType>
|
||||
VTKM_EXEC void operator()(const vtkm::Id& i,
|
||||
InputArrayIndexPortalType& indices,
|
||||
const InputArrayPortalType& scalar,
|
||||
const InputArrayV3PortalType& verts,
|
||||
OutputArrayPortalType& c_array,
|
||||
OutputArrayPortalType& v_array) const
|
||||
{
|
||||
vtkm::Id4 idx = indices.Get(i);
|
||||
vtkm::Id i1 = idx[1];
|
||||
vtkm::Id i2 = idx[2];
|
||||
vtkm::Id i3 = idx[3];
|
||||
|
||||
vtkm::Vec3f_32 p1 = verts.Get(idx[1]);
|
||||
vtkm::Vec3f_32 p2 = verts.Get(idx[2]);
|
||||
vtkm::Vec3f_32 p3 = verts.Get(idx[3]);
|
||||
|
||||
vtkm::Float32 s;
|
||||
vtkm::Vec<float, 3> color1;
|
||||
vtkm::Vec<float, 3> color2;
|
||||
vtkm::Vec<float, 3> color3;
|
||||
|
||||
if (SDiff == 0)
|
||||
{
|
||||
s = 0;
|
||||
color1 = ColorTable->MapThroughColorSpace(s);
|
||||
color2 = ColorTable->MapThroughColorSpace(s);
|
||||
color3 = ColorTable->MapThroughColorSpace(s);
|
||||
}
|
||||
else
|
||||
{
|
||||
s = scalar.Get(i1);
|
||||
s = (s - SMin) / SDiff;
|
||||
color1 = ColorTable->MapThroughColorSpace(s);
|
||||
|
||||
s = scalar.Get(i2);
|
||||
s = (s - SMin) / SDiff;
|
||||
color2 = ColorTable->MapThroughColorSpace(s);
|
||||
|
||||
s = scalar.Get(i3);
|
||||
s = (s - SMin) / SDiff;
|
||||
color3 = ColorTable->MapThroughColorSpace(s);
|
||||
}
|
||||
|
||||
const vtkm::Id offset = 9;
|
||||
|
||||
v_array.Set(i * offset, p1[0]);
|
||||
v_array.Set(i * offset + 1, p1[1]);
|
||||
v_array.Set(i * offset + 2, p1[2]);
|
||||
c_array.Set(i * offset, color1[0]);
|
||||
c_array.Set(i * offset + 1, color1[1]);
|
||||
c_array.Set(i * offset + 2, color1[2]);
|
||||
|
||||
v_array.Set(i * offset + 3, p2[0]);
|
||||
v_array.Set(i * offset + 4, p2[1]);
|
||||
v_array.Set(i * offset + 5, p2[2]);
|
||||
c_array.Set(i * offset + 3, color2[0]);
|
||||
c_array.Set(i * offset + 4, color2[1]);
|
||||
c_array.Set(i * offset + 5, color2[2]);
|
||||
|
||||
v_array.Set(i * offset + 6, p3[0]);
|
||||
v_array.Set(i * offset + 7, p3[1]);
|
||||
v_array.Set(i * offset + 8, p3[2]);
|
||||
c_array.Set(i * offset + 6, color3[0]);
|
||||
c_array.Set(i * offset + 7, color3[1]);
|
||||
c_array.Set(i * offset + 8, color3[2]);
|
||||
}
|
||||
};
|
||||
|
||||
template <typename PtType>
|
||||
struct MapColorAndVerticesInvokeFunctor
|
||||
{
|
||||
vtkm::cont::ArrayHandle<vtkm::Id4> TriangleIndices;
|
||||
vtkm::cont::ColorTable ColorTable;
|
||||
const vtkm::cont::ArrayHandle<vtkm::Float32> Scalar;
|
||||
const vtkm::Range ScalarRange;
|
||||
const PtType Vertices;
|
||||
vtkm::Float32 SMin;
|
||||
vtkm::Float32 SDiff;
|
||||
vtkm::cont::ArrayHandle<vtkm::Float32> OutColor;
|
||||
vtkm::cont::ArrayHandle<vtkm::Float32> OutVertices;
|
||||
|
||||
VTKM_CONT
|
||||
MapColorAndVerticesInvokeFunctor(const vtkm::cont::ArrayHandle<vtkm::Id4>& indices,
|
||||
const vtkm::cont::ColorTable& colorTable,
|
||||
const vtkm::cont::ArrayHandle<Float32>& scalar,
|
||||
const vtkm::Range& scalarRange,
|
||||
const PtType& vertices,
|
||||
vtkm::Float32 s_min,
|
||||
vtkm::Float32 s_max,
|
||||
vtkm::cont::ArrayHandle<Float32>& out_color,
|
||||
vtkm::cont::ArrayHandle<Float32>& out_vertices)
|
||||
: TriangleIndices(indices)
|
||||
, ColorTable(colorTable)
|
||||
, Scalar(scalar)
|
||||
, ScalarRange(scalarRange)
|
||||
, Vertices(vertices)
|
||||
, SMin(s_min)
|
||||
, SDiff(s_max - s_min)
|
||||
, OutColor(out_color)
|
||||
, OutVertices(out_vertices)
|
||||
{
|
||||
}
|
||||
|
||||
template <typename Device>
|
||||
VTKM_CONT bool operator()(Device device) const
|
||||
{
|
||||
VTKM_IS_DEVICE_ADAPTER_TAG(Device);
|
||||
|
||||
vtkm::cont::Token token;
|
||||
MapColorAndVertices worklet(
|
||||
this->ColorTable.PrepareForExecution(device, token), this->SMin, this->SDiff);
|
||||
vtkm::worklet::DispatcherMapField<MapColorAndVertices> dispatcher(worklet);
|
||||
dispatcher.SetDevice(Device{});
|
||||
|
||||
vtkm::cont::ArrayHandleIndex indexArray(this->TriangleIndices.GetNumberOfValues());
|
||||
dispatcher.Invoke(indexArray,
|
||||
this->TriangleIndices,
|
||||
this->Scalar,
|
||||
this->Vertices,
|
||||
this->OutColor,
|
||||
this->OutVertices);
|
||||
return true;
|
||||
}
|
||||
};
|
||||
|
||||
template <typename PtType>
|
||||
VTKM_CONT void RenderStructuredLineSegments(vtkm::Id numVerts,
|
||||
const PtType& verts,
|
||||
const vtkm::cont::ArrayHandle<vtkm::Float32>& scalar,
|
||||
vtkm::cont::ColorTable ct,
|
||||
bool logY)
|
||||
{
|
||||
glDisable(GL_DEPTH_TEST);
|
||||
glDisable(GL_LIGHTING);
|
||||
glLineWidth(1);
|
||||
vtkm::UInt8 r, g, b, a;
|
||||
|
||||
//This is horrible as the color table API isn't designed for users to query
|
||||
//on a single value basis. We use the GetPoint and GetPointAlpha escape hatches
|
||||
//and manually convert from float to uchar
|
||||
vtkm::Vec<double, 4> data;
|
||||
ct.GetPoint(0, data);
|
||||
r = static_cast<vtkm::UInt8>(data[1] * 255.0 + 0.5);
|
||||
g = static_cast<vtkm::UInt8>(data[2] * 255.0 + 0.5);
|
||||
b = static_cast<vtkm::UInt8>(data[3] * 255.0 + 0.5);
|
||||
ct.GetPointAlpha(0, data);
|
||||
a = static_cast<vtkm::UInt8>(data[1] * 255.0 + 0.5);
|
||||
|
||||
glColor4ub(r, g, b, a);
|
||||
glBegin(GL_LINE_STRIP);
|
||||
for (int i = 0; i < numVerts; i++)
|
||||
{
|
||||
vtkm::Vec3f_32 pt = verts.ReadPortal().Get(i);
|
||||
vtkm::Float32 s = scalar.ReadPortal().Get(i);
|
||||
if (logY)
|
||||
s = vtkm::Float32(log10(s));
|
||||
glVertex3f(pt[0], s, 0.0f);
|
||||
}
|
||||
glEnd();
|
||||
}
|
||||
|
||||
template <typename PtType>
|
||||
VTKM_CONT void RenderExplicitLineSegments(vtkm::Id numVerts,
|
||||
const PtType& verts,
|
||||
const vtkm::cont::ArrayHandle<vtkm::Float32>& scalar,
|
||||
vtkm::cont::ColorTable ct,
|
||||
bool logY)
|
||||
{
|
||||
glDisable(GL_DEPTH_TEST);
|
||||
glDisable(GL_LIGHTING);
|
||||
glLineWidth(1);
|
||||
vtkm::UInt8 r, g, b, a;
|
||||
//This is horrible as the color table API isn't designed for users to query
|
||||
//on a single value basis. We use the GetPoint and GetPointAlpha escape hatches
|
||||
//and manually convert from float to uchar
|
||||
vtkm::Vec<double, 4> data;
|
||||
ct.GetPoint(0, data);
|
||||
r = static_cast<vtkm::UInt8>(data[1] * 255.0 + 0.5);
|
||||
g = static_cast<vtkm::UInt8>(data[2] * 255.0 + 0.5);
|
||||
b = static_cast<vtkm::UInt8>(data[3] * 255.0 + 0.5);
|
||||
ct.GetPointAlpha(0, data);
|
||||
a = static_cast<vtkm::UInt8>(data[1] * 255.0 + 0.5);
|
||||
|
||||
glColor4ub(r, g, b, a);
|
||||
glBegin(GL_LINE_STRIP);
|
||||
for (int i = 0; i < numVerts; i++)
|
||||
{
|
||||
vtkm::Vec3f_32 pt = verts.ReadPortal().Get(i);
|
||||
vtkm::Float32 s = scalar.ReadPortal().Get(i);
|
||||
if (logY)
|
||||
s = vtkm::Float32(log10(s));
|
||||
glVertex3f(pt[0], s, 0.0f);
|
||||
}
|
||||
glEnd();
|
||||
}
|
||||
|
||||
template <typename PtType>
|
||||
VTKM_CONT void RenderTriangles(MapperGL& mapper,
|
||||
vtkm::Id numTri,
|
||||
const PtType& verts,
|
||||
const vtkm::cont::ArrayHandle<vtkm::Id4>& indices,
|
||||
const vtkm::cont::ArrayHandle<vtkm::Float32>& scalar,
|
||||
const vtkm::cont::ColorTable& ct,
|
||||
const vtkm::Range& scalarRange,
|
||||
const vtkm::rendering::Camera& camera)
|
||||
{
|
||||
if (!mapper.loaded)
|
||||
{
|
||||
// The glewExperimental global switch can be turned on by setting it to
|
||||
// GL_TRUE before calling glewInit(), which ensures that all extensions
|
||||
// with valid entry points will be exposed. This is needed as the glut
|
||||
// context that is being created is not a valid 'core' context but
|
||||
// instead a 'compatibility' context
|
||||
//
|
||||
glewExperimental = GL_TRUE;
|
||||
GLenum GlewInitResult = glewInit();
|
||||
if (GlewInitResult)
|
||||
std::cerr << "ERROR: " << glewGetErrorString(GlewInitResult) << std::endl;
|
||||
mapper.loaded = true;
|
||||
|
||||
vtkm::Float32 sMin = vtkm::Float32(scalarRange.Min);
|
||||
vtkm::Float32 sMax = vtkm::Float32(scalarRange.Max);
|
||||
vtkm::cont::ArrayHandle<vtkm::Float32> out_vertices, out_color;
|
||||
out_vertices.Allocate(9 * indices.GetNumberOfValues());
|
||||
out_color.Allocate(9 * indices.GetNumberOfValues());
|
||||
|
||||
vtkm::cont::TryExecute(MapColorAndVerticesInvokeFunctor<PtType>(
|
||||
indices, ct, scalar, scalarRange, verts, sMin, sMax, out_color, out_vertices));
|
||||
|
||||
|
||||
vtkm::Id vtx_cnt = out_vertices.GetNumberOfValues();
|
||||
vtkm::Float32* v_ptr = out_vertices.GetStorage().GetArray();
|
||||
vtkm::Float32* c_ptr = out_color.GetStorage().GetArray();
|
||||
|
||||
vtkm::Id floatSz = static_cast<vtkm::Id>(sizeof(vtkm::Float32));
|
||||
GLsizeiptr sz = static_cast<GLsizeiptr>(vtx_cnt * floatSz);
|
||||
|
||||
GLuint points_vbo = 0;
|
||||
glGenBuffers(1, &points_vbo);
|
||||
glBindBuffer(GL_ARRAY_BUFFER, points_vbo);
|
||||
glBufferData(GL_ARRAY_BUFFER, sz, v_ptr, GL_STATIC_DRAW);
|
||||
|
||||
GLuint colours_vbo = 0;
|
||||
glGenBuffers(1, &colours_vbo);
|
||||
glBindBuffer(GL_ARRAY_BUFFER, colours_vbo);
|
||||
glBufferData(GL_ARRAY_BUFFER, sz, c_ptr, GL_STATIC_DRAW);
|
||||
|
||||
mapper.vao = 0;
|
||||
glGenVertexArrays(1, &mapper.vao);
|
||||
glBindVertexArray(mapper.vao);
|
||||
glBindBuffer(GL_ARRAY_BUFFER, points_vbo);
|
||||
glVertexAttribPointer(0, 3, GL_FLOAT, GL_FALSE, 0, nullptr);
|
||||
glBindBuffer(GL_ARRAY_BUFFER, colours_vbo);
|
||||
glVertexAttribPointer(1, 3, GL_FLOAT, GL_FALSE, 0, nullptr);
|
||||
|
||||
glEnableVertexAttribArray(0);
|
||||
glEnableVertexAttribArray(1);
|
||||
|
||||
const char* vertex_shader = "#version 120\n"
|
||||
"attribute vec3 vertex_position;"
|
||||
"attribute vec3 vertex_color;"
|
||||
"varying vec3 ourColor;"
|
||||
"uniform mat4 mv_matrix;"
|
||||
"uniform mat4 p_matrix;"
|
||||
|
||||
"void main() {"
|
||||
" gl_Position = p_matrix*mv_matrix * vec4(vertex_position, 1.0);"
|
||||
" ourColor = vertex_color;"
|
||||
"}";
|
||||
const char* fragment_shader = "#version 120\n"
|
||||
"varying vec3 ourColor;"
|
||||
"void main() {"
|
||||
" gl_FragColor = vec4 (ourColor, 1.0);"
|
||||
"}";
|
||||
|
||||
GLuint vs = glCreateShader(GL_VERTEX_SHADER);
|
||||
glShaderSource(vs, 1, &vertex_shader, nullptr);
|
||||
glCompileShader(vs);
|
||||
GLint isCompiled = 0;
|
||||
glGetShaderiv(vs, GL_COMPILE_STATUS, &isCompiled);
|
||||
if (isCompiled == GL_FALSE)
|
||||
{
|
||||
GLint maxLength = 0;
|
||||
glGetShaderiv(vs, GL_INFO_LOG_LENGTH, &maxLength);
|
||||
|
||||
std::string msg;
|
||||
if (maxLength <= 0)
|
||||
msg = "No error message";
|
||||
else
|
||||
{
|
||||
// The maxLength includes the nullptr character
|
||||
GLchar* strInfoLog = new GLchar[maxLength + 1];
|
||||
glGetShaderInfoLog(vs, maxLength, &maxLength, strInfoLog);
|
||||
msg = std::string(strInfoLog);
|
||||
delete[] strInfoLog;
|
||||
}
|
||||
throw vtkm::cont::ErrorBadValue("Shader compile error:" + msg);
|
||||
}
|
||||
|
||||
GLuint fs = glCreateShader(GL_FRAGMENT_SHADER);
|
||||
glShaderSource(fs, 1, &fragment_shader, nullptr);
|
||||
glCompileShader(fs);
|
||||
glGetShaderiv(fs, GL_COMPILE_STATUS, &isCompiled);
|
||||
if (isCompiled == GL_FALSE)
|
||||
{
|
||||
GLint maxLength = 0;
|
||||
glGetShaderiv(fs, GL_INFO_LOG_LENGTH, &maxLength);
|
||||
|
||||
std::string msg;
|
||||
if (maxLength <= 0)
|
||||
msg = "No error message";
|
||||
else
|
||||
{
|
||||
// The maxLength includes the nullptr character
|
||||
GLchar* strInfoLog = new GLchar[maxLength + 1];
|
||||
glGetShaderInfoLog(vs, maxLength, &maxLength, strInfoLog);
|
||||
msg = std::string(strInfoLog);
|
||||
delete[] strInfoLog;
|
||||
}
|
||||
throw vtkm::cont::ErrorBadValue("Shader compile error:" + msg);
|
||||
}
|
||||
|
||||
mapper.shader_programme = glCreateProgram();
|
||||
if (mapper.shader_programme > 0)
|
||||
{
|
||||
glAttachShader(mapper.shader_programme, fs);
|
||||
glAttachShader(mapper.shader_programme, vs);
|
||||
glBindAttribLocation(mapper.shader_programme, 0, "vertex_position");
|
||||
glBindAttribLocation(mapper.shader_programme, 1, "vertex_color");
|
||||
|
||||
glLinkProgram(mapper.shader_programme);
|
||||
GLint linkStatus;
|
||||
glGetProgramiv(mapper.shader_programme, GL_LINK_STATUS, &linkStatus);
|
||||
if (!linkStatus)
|
||||
{
|
||||
char log[2048];
|
||||
GLsizei len;
|
||||
glGetProgramInfoLog(mapper.shader_programme, 2048, &len, log);
|
||||
std::string msg = std::string("Shader program link failed: ") + std::string(log);
|
||||
throw vtkm::cont::ErrorBadValue(msg);
|
||||
}
|
||||
}
|
||||
}
|
||||
|
||||
if (mapper.shader_programme > 0)
|
||||
{
|
||||
vtkm::Id width = mapper.GetCanvas()->GetWidth();
|
||||
vtkm::Id height = mapper.GetCanvas()->GetWidth();
|
||||
vtkm::Matrix<vtkm::Float32, 4, 4> viewM = camera.CreateViewMatrix();
|
||||
vtkm::Matrix<vtkm::Float32, 4, 4> projM = camera.CreateProjectionMatrix(width, height);
|
||||
|
||||
MatrixHelpers::CreateOGLMatrix(viewM, mapper.mvMat);
|
||||
MatrixHelpers::CreateOGLMatrix(projM, mapper.pMat);
|
||||
|
||||
glUseProgram(mapper.shader_programme);
|
||||
GLint mvID = glGetUniformLocation(mapper.shader_programme, "mv_matrix");
|
||||
glUniformMatrix4fv(mvID, 1, GL_FALSE, mapper.mvMat);
|
||||
GLint pID = glGetUniformLocation(mapper.shader_programme, "p_matrix");
|
||||
glUniformMatrix4fv(pID, 1, GL_FALSE, mapper.pMat);
|
||||
glBindVertexArray(mapper.vao);
|
||||
glDrawArrays(GL_TRIANGLES, 0, static_cast<GLsizei>(numTri * 3));
|
||||
glUseProgram(0);
|
||||
}
|
||||
}
|
||||
|
||||
} // anonymous namespace
|
||||
|
||||
MapperGL::MapperGL()
|
||||
: Canvas(nullptr)
|
||||
, loaded(false)
|
||||
{
|
||||
}
|
||||
|
||||
MapperGL::~MapperGL()
|
||||
{
|
||||
}
|
||||
|
||||
void MapperGL::RenderCells(const vtkm::cont::DynamicCellSet& cellset,
|
||||
const vtkm::cont::CoordinateSystem& coords,
|
||||
const vtkm::cont::Field& scalarField,
|
||||
const vtkm::cont::ColorTable& colorTable,
|
||||
const vtkm::rendering::Camera& camera,
|
||||
const vtkm::Range& scalarRange)
|
||||
{
|
||||
vtkm::cont::ArrayHandle<vtkm::Float32> sf;
|
||||
sf = scalarField.GetData().Cast<vtkm::cont::ArrayHandle<vtkm::Float32>>();
|
||||
auto dcoords = coords.GetData();
|
||||
vtkm::Id numVerts = coords.GetNumberOfPoints();
|
||||
|
||||
//Handle 1D cases.
|
||||
if (cellset.IsSameType(vtkm::cont::CellSetStructured<1>()))
|
||||
{
|
||||
vtkm::cont::ArrayHandleUniformPointCoordinates verts;
|
||||
verts = dcoords.Cast<vtkm::cont::ArrayHandleUniformPointCoordinates>();
|
||||
RenderStructuredLineSegments(numVerts, verts, sf, colorTable, this->LogarithmY);
|
||||
}
|
||||
else if (cellset.IsSameType(vtkm::cont::CellSetSingleType<>()) &&
|
||||
cellset.Cast<vtkm::cont::CellSetSingleType<>>().GetCellShapeAsId() ==
|
||||
vtkm::CELL_SHAPE_LINE)
|
||||
{
|
||||
vtkm::cont::ArrayHandle<vtkm::Vec3f_32> verts;
|
||||
verts = dcoords.Cast<vtkm::cont::ArrayHandle<vtkm::Vec3f_32>>();
|
||||
RenderExplicitLineSegments(numVerts, verts, sf, colorTable, this->LogarithmY);
|
||||
}
|
||||
else
|
||||
{
|
||||
vtkm::cont::ArrayHandle<vtkm::Id4> indices;
|
||||
vtkm::Id numTri;
|
||||
vtkm::rendering::internal::RunTriangulator(cellset, indices, numTri);
|
||||
|
||||
vtkm::cont::ArrayHandleUniformPointCoordinates uVerts;
|
||||
vtkm::cont::ArrayHandle<vtkm::Vec3f_32> eVerts;
|
||||
|
||||
if (dcoords.IsType<vtkm::cont::ArrayHandleUniformPointCoordinates>())
|
||||
{
|
||||
uVerts = dcoords.Cast<vtkm::cont::ArrayHandleUniformPointCoordinates>();
|
||||
RenderTriangles(*this, numTri, uVerts, indices, sf, colorTable, scalarRange, camera);
|
||||
}
|
||||
else if (dcoords.IsType<vtkm::cont::ArrayHandle<vtkm::Vec3f_32>>())
|
||||
{
|
||||
eVerts = dcoords.Cast<vtkm::cont::ArrayHandle<vtkm::Vec3f_32>>();
|
||||
RenderTriangles(*this, numTri, eVerts, indices, sf, colorTable, scalarRange, camera);
|
||||
}
|
||||
else if (dcoords.IsType<vtkm::cont::ArrayHandleCartesianProduct<
|
||||
vtkm::cont::ArrayHandle<vtkm::FloatDefault>,
|
||||
vtkm::cont::ArrayHandle<vtkm::FloatDefault>,
|
||||
vtkm::cont::ArrayHandle<vtkm::FloatDefault>>>())
|
||||
{
|
||||
vtkm::cont::ArrayHandleCartesianProduct<vtkm::cont::ArrayHandle<vtkm::FloatDefault>,
|
||||
vtkm::cont::ArrayHandle<vtkm::FloatDefault>,
|
||||
vtkm::cont::ArrayHandle<vtkm::FloatDefault>>
|
||||
rVerts;
|
||||
rVerts = dcoords.Cast<
|
||||
vtkm::cont::ArrayHandleCartesianProduct<vtkm::cont::ArrayHandle<vtkm::FloatDefault>,
|
||||
vtkm::cont::ArrayHandle<vtkm::FloatDefault>,
|
||||
vtkm::cont::ArrayHandle<vtkm::FloatDefault>>>();
|
||||
RenderTriangles(*this, numTri, rVerts, indices, sf, colorTable, scalarRange, camera);
|
||||
}
|
||||
}
|
||||
glFinish();
|
||||
glFlush();
|
||||
}
|
||||
|
||||
void MapperGL::StartScene()
|
||||
{
|
||||
// Nothing needs to be done.
|
||||
}
|
||||
|
||||
void MapperGL::EndScene()
|
||||
{
|
||||
// Nothing needs to be done.
|
||||
}
|
||||
|
||||
void MapperGL::SetCanvas(vtkm::rendering::Canvas* c)
|
||||
{
|
||||
if (c != nullptr)
|
||||
{
|
||||
this->Canvas = dynamic_cast<vtkm::rendering::CanvasGL*>(c);
|
||||
if (this->Canvas == nullptr)
|
||||
throw vtkm::cont::ErrorBadValue("Bad canvas type for MapperGL. Must be CanvasGL");
|
||||
}
|
||||
}
|
||||
|
||||
vtkm::rendering::Canvas* MapperGL::GetCanvas() const
|
||||
{
|
||||
return this->Canvas;
|
||||
}
|
||||
|
||||
vtkm::rendering::Mapper* MapperGL::NewCopy() const
|
||||
{
|
||||
return new vtkm::rendering::MapperGL(*this);
|
||||
}
|
||||
}
|
||||
} // namespace vtkm::rendering
|
@ -1,56 +0,0 @@
|
||||
//============================================================================
|
||||
// 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.
|
||||
//============================================================================
|
||||
#ifndef vtk_m_rendering_MapperGL_h
|
||||
#define vtk_m_rendering_MapperGL_h
|
||||
|
||||
#include <vtkm/cont/ColorTable.h>
|
||||
#include <vtkm/cont/CoordinateSystem.h>
|
||||
#include <vtkm/rendering/Camera.h>
|
||||
#include <vtkm/rendering/CanvasGL.h>
|
||||
#include <vtkm/rendering/Mapper.h>
|
||||
|
||||
#include <vtkm/rendering/internal/OpenGLHeaders.h>
|
||||
|
||||
namespace vtkm
|
||||
{
|
||||
namespace rendering
|
||||
{
|
||||
|
||||
class VTKM_RENDERING_EXPORT MapperGL : public Mapper
|
||||
{
|
||||
public:
|
||||
MapperGL();
|
||||
|
||||
~MapperGL();
|
||||
|
||||
void RenderCells(const vtkm::cont::DynamicCellSet& cellset,
|
||||
const vtkm::cont::CoordinateSystem& coords,
|
||||
const vtkm::cont::Field& scalarField,
|
||||
const vtkm::cont::ColorTable& colorTable,
|
||||
const vtkm::rendering::Camera&,
|
||||
const vtkm::Range& scalarRange) override;
|
||||
|
||||
void StartScene() override;
|
||||
void EndScene() override;
|
||||
void SetCanvas(vtkm::rendering::Canvas* canvas) override;
|
||||
virtual vtkm::rendering::Canvas* GetCanvas() const override;
|
||||
|
||||
vtkm::rendering::Mapper* NewCopy() const override;
|
||||
|
||||
vtkm::rendering::CanvasGL* Canvas;
|
||||
GLuint shader_programme;
|
||||
GLfloat mvMat[16], pMat[16];
|
||||
bool loaded;
|
||||
GLuint vao;
|
||||
};
|
||||
}
|
||||
} //namespace vtkm::rendering
|
||||
|
||||
#endif //vtk_m_rendering_MapperGL_h
|
@ -1,176 +0,0 @@
|
||||
//============================================================================
|
||||
// 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.
|
||||
//============================================================================
|
||||
|
||||
#include <vtkm/rendering/TextureGL.h>
|
||||
|
||||
#include <vtkm/rendering/internal/OpenGLHeaders.h>
|
||||
|
||||
namespace vtkm
|
||||
{
|
||||
namespace rendering
|
||||
{
|
||||
|
||||
struct TextureGL::InternalsType
|
||||
{
|
||||
GLuint Id;
|
||||
int Dimension;
|
||||
bool MIPMap;
|
||||
bool Linear2D;
|
||||
bool LinearMIP;
|
||||
|
||||
VTKM_CONT
|
||||
InternalsType()
|
||||
: Id(0)
|
||||
, Dimension(0)
|
||||
, MIPMap(false)
|
||||
, Linear2D(true)
|
||||
, LinearMIP(true)
|
||||
{
|
||||
}
|
||||
|
||||
VTKM_CONT
|
||||
~InternalsType()
|
||||
{
|
||||
if (this->Id != 0)
|
||||
{
|
||||
glDeleteTextures(1, &this->Id);
|
||||
}
|
||||
}
|
||||
};
|
||||
|
||||
TextureGL::TextureGL()
|
||||
: Internals(new InternalsType)
|
||||
{
|
||||
}
|
||||
|
||||
TextureGL::~TextureGL()
|
||||
{
|
||||
}
|
||||
|
||||
bool TextureGL::Valid() const
|
||||
{
|
||||
return (this->Internals->Id != 0);
|
||||
}
|
||||
|
||||
void TextureGL::Enable() const
|
||||
{
|
||||
if (!this->Valid())
|
||||
{
|
||||
return;
|
||||
}
|
||||
|
||||
if (this->Internals->Dimension == 1)
|
||||
{
|
||||
// no this->Internals->MIPMapping for 1D (at the moment)
|
||||
glBindTexture(GL_TEXTURE_1D, this->Internals->Id);
|
||||
glTexParameteri(GL_TEXTURE_1D, GL_TEXTURE_WRAP_S, GL_CLAMP);
|
||||
if (this->Internals->Linear2D)
|
||||
{
|
||||
glTexParameteri(GL_TEXTURE_1D, GL_TEXTURE_MAG_FILTER, GL_LINEAR);
|
||||
glTexParameteri(GL_TEXTURE_1D, GL_TEXTURE_MIN_FILTER, GL_LINEAR);
|
||||
}
|
||||
else
|
||||
{
|
||||
glTexParameteri(GL_TEXTURE_1D, GL_TEXTURE_MAG_FILTER, GL_NEAREST);
|
||||
glTexParameteri(GL_TEXTURE_1D, GL_TEXTURE_MIN_FILTER, GL_NEAREST);
|
||||
}
|
||||
glEnable(GL_TEXTURE_1D);
|
||||
}
|
||||
else if (this->Internals->Dimension == 2)
|
||||
{
|
||||
glBindTexture(GL_TEXTURE_2D, this->Internals->Id);
|
||||
glTexParameteri(GL_TEXTURE_2D, GL_TEXTURE_WRAP_S, GL_CLAMP);
|
||||
glTexParameteri(GL_TEXTURE_2D, GL_TEXTURE_WRAP_T, GL_CLAMP);
|
||||
if (this->Internals->Linear2D)
|
||||
{
|
||||
glTexParameteri(GL_TEXTURE_2D, GL_TEXTURE_MAG_FILTER, GL_LINEAR);
|
||||
if (!this->Internals->MIPMap)
|
||||
glTexParameteri(GL_TEXTURE_2D, GL_TEXTURE_MIN_FILTER, GL_LINEAR);
|
||||
else if (this->Internals->LinearMIP)
|
||||
glTexParameteri(GL_TEXTURE_2D, GL_TEXTURE_MIN_FILTER, GL_LINEAR_MIPMAP_LINEAR);
|
||||
else
|
||||
glTexParameteri(GL_TEXTURE_2D, GL_TEXTURE_MIN_FILTER, GL_LINEAR_MIPMAP_NEAREST);
|
||||
}
|
||||
else
|
||||
{
|
||||
glTexParameteri(GL_TEXTURE_2D, GL_TEXTURE_MAG_FILTER, GL_NEAREST);
|
||||
if (!this->Internals->MIPMap)
|
||||
glTexParameteri(GL_TEXTURE_2D, GL_TEXTURE_MIN_FILTER, GL_NEAREST);
|
||||
else if (this->Internals->LinearMIP)
|
||||
glTexParameteri(GL_TEXTURE_2D, GL_TEXTURE_MIN_FILTER, GL_NEAREST_MIPMAP_LINEAR);
|
||||
else
|
||||
glTexParameteri(GL_TEXTURE_2D, GL_TEXTURE_MIN_FILTER, GL_NEAREST_MIPMAP_NEAREST);
|
||||
}
|
||||
glEnable(GL_TEXTURE_2D);
|
||||
}
|
||||
else
|
||||
{
|
||||
// Fail silently for invalid dimension.
|
||||
}
|
||||
}
|
||||
|
||||
void TextureGL::Disable() const
|
||||
{
|
||||
if (this->Internals->Dimension == 1)
|
||||
{
|
||||
glDisable(GL_TEXTURE_1D);
|
||||
}
|
||||
else if (this->Internals->Dimension == 2)
|
||||
{
|
||||
glDisable(GL_TEXTURE_2D);
|
||||
}
|
||||
else
|
||||
{
|
||||
// Fail silently for invalid dimension
|
||||
}
|
||||
}
|
||||
|
||||
void TextureGL::CreateAlphaFromRGBA(vtkm::Id width,
|
||||
vtkm::Id height,
|
||||
const std::vector<unsigned char>& rgba)
|
||||
{
|
||||
this->Internals->Dimension = 2;
|
||||
std::vector<unsigned char> alpha(rgba.size() / 4);
|
||||
VTKM_ASSERT(width * height == static_cast<vtkm::Id>(alpha.size()));
|
||||
for (std::size_t i = 0; i < alpha.size(); i++)
|
||||
{
|
||||
alpha[i] = rgba[i * 4 + 3];
|
||||
}
|
||||
|
||||
if (this->Internals->Id == 0)
|
||||
{
|
||||
glGenTextures(1, &this->Internals->Id);
|
||||
}
|
||||
|
||||
if (this->Internals->Dimension == 1)
|
||||
{
|
||||
glBindTexture(GL_TEXTURE_1D, this->Internals->Id);
|
||||
}
|
||||
else if (this->Internals->Dimension == 2)
|
||||
{
|
||||
glBindTexture(GL_TEXTURE_2D, this->Internals->Id);
|
||||
//#define HW_MIPMAPS
|
||||
#ifdef HW_MIPMAPS
|
||||
mpimap = true;
|
||||
glTexParameteri(GL_TEXTURE_2D, GL_GENERATE_MIPMAP_SGIS, GL_TRUE);
|
||||
#endif
|
||||
glTexImage2D(GL_TEXTURE_2D,
|
||||
0,
|
||||
GL_ALPHA,
|
||||
static_cast<GLsizei>(width),
|
||||
static_cast<GLsizei>(height),
|
||||
0,
|
||||
GL_ALPHA,
|
||||
GL_UNSIGNED_BYTE,
|
||||
(void*)(&(alpha[0])));
|
||||
}
|
||||
}
|
||||
}
|
||||
} // namespace vtkm::rendering
|
@ -1,47 +0,0 @@
|
||||
//============================================================================
|
||||
// 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.
|
||||
//============================================================================
|
||||
#ifndef vtk_m_TextureGL_h
|
||||
#define vtk_m_TextureGL_h
|
||||
|
||||
#include <vtkm/rendering/vtkm_rendering_export.h>
|
||||
|
||||
#include <vtkm/Types.h>
|
||||
|
||||
#include <memory>
|
||||
#include <vector>
|
||||
|
||||
namespace vtkm
|
||||
{
|
||||
namespace rendering
|
||||
{
|
||||
|
||||
class VTKM_RENDERING_EXPORT TextureGL
|
||||
{
|
||||
public:
|
||||
TextureGL();
|
||||
|
||||
~TextureGL();
|
||||
|
||||
bool Valid() const;
|
||||
|
||||
void Enable() const;
|
||||
|
||||
void Disable() const;
|
||||
|
||||
void CreateAlphaFromRGBA(vtkm::Id width, vtkm::Id height, const std::vector<unsigned char>& rgba);
|
||||
|
||||
private:
|
||||
struct InternalsType;
|
||||
std::shared_ptr<InternalsType> Internals;
|
||||
};
|
||||
}
|
||||
} //namespace vtkm::rendering
|
||||
|
||||
#endif //vtk_m_rendering_TextureGL_h
|
@ -1,163 +0,0 @@
|
||||
//============================================================================
|
||||
// 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.
|
||||
//============================================================================
|
||||
|
||||
#include <vtkm/rendering/WorldAnnotatorGL.h>
|
||||
|
||||
#include <vtkm/Matrix.h>
|
||||
#include <vtkm/rendering/BitmapFontFactory.h>
|
||||
#include <vtkm/rendering/Color.h>
|
||||
#include <vtkm/rendering/DecodePNG.h>
|
||||
#include <vtkm/rendering/MatrixHelpers.h>
|
||||
#include <vtkm/rendering/Scene.h>
|
||||
|
||||
#include <vtkm/rendering/internal/OpenGLHeaders.h>
|
||||
|
||||
namespace vtkm
|
||||
{
|
||||
namespace rendering
|
||||
{
|
||||
|
||||
WorldAnnotatorGL::WorldAnnotatorGL(const vtkm::rendering::Canvas* canvas)
|
||||
: WorldAnnotator(canvas)
|
||||
{
|
||||
}
|
||||
|
||||
WorldAnnotatorGL::~WorldAnnotatorGL()
|
||||
{
|
||||
}
|
||||
|
||||
void WorldAnnotatorGL::AddLine(const vtkm::Vec3f_64& point0,
|
||||
const vtkm::Vec3f_64& point1,
|
||||
vtkm::Float32 lineWidth,
|
||||
const vtkm::rendering::Color& color,
|
||||
bool inFront) const
|
||||
{
|
||||
if (inFront)
|
||||
{
|
||||
glDepthRange(-.0001, .9999);
|
||||
}
|
||||
|
||||
glDisable(GL_LIGHTING);
|
||||
glEnable(GL_DEPTH_TEST);
|
||||
|
||||
glColor3f(color.Components[0], color.Components[1], color.Components[2]);
|
||||
|
||||
glLineWidth(lineWidth);
|
||||
|
||||
glBegin(GL_LINES);
|
||||
glVertex3d(point0[0], point0[1], point0[2]);
|
||||
glVertex3d(point1[0], point1[1], point1[2]);
|
||||
glEnd();
|
||||
|
||||
if (inFront)
|
||||
{
|
||||
glDepthRange(0, 1);
|
||||
}
|
||||
}
|
||||
|
||||
void WorldAnnotatorGL::AddText(const vtkm::Vec3f_32& origin,
|
||||
const vtkm::Vec3f_32& right,
|
||||
const vtkm::Vec3f_32& up,
|
||||
vtkm::Float32 scale,
|
||||
const vtkm::Vec2f_32& anchor,
|
||||
const vtkm::rendering::Color& color,
|
||||
const std::string& text,
|
||||
const vtkm::Float32 vtkmNotUsed(depth)) const
|
||||
{
|
||||
|
||||
vtkm::Vec3f_32 n = vtkm::Cross(right, up);
|
||||
vtkm::Normalize(n);
|
||||
|
||||
vtkm::Matrix<vtkm::Float32, 4, 4> m;
|
||||
m = MatrixHelpers::WorldMatrix(origin, right, up, n);
|
||||
|
||||
vtkm::Float32 ogl[16];
|
||||
MatrixHelpers::CreateOGLMatrix(m, ogl);
|
||||
glPushMatrix();
|
||||
glMultMatrixf(ogl);
|
||||
glColor3f(color.Components[0], color.Components[1], color.Components[2]);
|
||||
this->RenderText(scale, anchor[0], anchor[1], text);
|
||||
glPopMatrix();
|
||||
}
|
||||
|
||||
void WorldAnnotatorGL::RenderText(vtkm::Float32 scale,
|
||||
vtkm::Float32 anchorx,
|
||||
vtkm::Float32 anchory,
|
||||
std::string text) const
|
||||
{
|
||||
if (!this->FontTexture.Valid())
|
||||
{
|
||||
// When we load a font, we save a reference to it for the next time we
|
||||
// use it. Although technically we are changing the state, the logical
|
||||
// state does not change, so we go ahead and do it in this const
|
||||
// function.
|
||||
vtkm::rendering::WorldAnnotatorGL* self = const_cast<vtkm::rendering::WorldAnnotatorGL*>(this);
|
||||
self->Font = BitmapFontFactory::CreateLiberation2Sans();
|
||||
const std::vector<unsigned char>& rawpngdata = this->Font.GetRawImageData();
|
||||
|
||||
std::vector<unsigned char> rgba;
|
||||
unsigned long width, height;
|
||||
int error = vtkm::rendering::DecodePNG(rgba, width, height, &rawpngdata[0], rawpngdata.size());
|
||||
if (error != 0)
|
||||
{
|
||||
return;
|
||||
}
|
||||
|
||||
self->FontTexture.CreateAlphaFromRGBA(int(width), int(height), rgba);
|
||||
}
|
||||
|
||||
this->FontTexture.Enable();
|
||||
|
||||
glDepthMask(GL_FALSE);
|
||||
glBlendFunc(GL_SRC_ALPHA, GL_ONE_MINUS_SRC_ALPHA);
|
||||
glEnable(GL_BLEND);
|
||||
glTexEnvf(GL_TEXTURE_ENV, GL_TEXTURE_ENV_MODE, GL_MODULATE);
|
||||
glDisable(GL_LIGHTING);
|
||||
//glTexEnvf(GL_TEXTURE_FILTER_CONTROL, GL_TEXTURE_LOD_BIAS, -.5);
|
||||
|
||||
glBegin(GL_QUADS);
|
||||
|
||||
vtkm::Float32 textwidth = this->Font.GetTextWidth(text);
|
||||
|
||||
vtkm::Float32 fx = -(.5f + .5f * anchorx) * textwidth;
|
||||
vtkm::Float32 fy = -(.5f + .5f * anchory);
|
||||
vtkm::Float32 fz = 0;
|
||||
for (unsigned int i = 0; i < text.length(); ++i)
|
||||
{
|
||||
char c = text[i];
|
||||
char nextchar = (i < text.length() - 1) ? text[i + 1] : 0;
|
||||
|
||||
vtkm::Float32 vl, vr, vt, vb;
|
||||
vtkm::Float32 tl, tr, tt, tb;
|
||||
this->Font.GetCharPolygon(c, fx, fy, vl, vr, vt, vb, tl, tr, tt, tb, nextchar);
|
||||
|
||||
glTexCoord2f(tl, 1.f - tt);
|
||||
glVertex3f(scale * vl, scale * vt, fz);
|
||||
|
||||
glTexCoord2f(tl, 1.f - tb);
|
||||
glVertex3f(scale * vl, scale * vb, fz);
|
||||
|
||||
glTexCoord2f(tr, 1.f - tb);
|
||||
glVertex3f(scale * vr, scale * vb, fz);
|
||||
|
||||
glTexCoord2f(tr, 1.f - tt);
|
||||
glVertex3f(scale * vr, scale * vt, fz);
|
||||
}
|
||||
|
||||
glEnd();
|
||||
|
||||
this->FontTexture.Disable();
|
||||
|
||||
//glTexEnvf(GL_TEXTURE_FILTER_CONTROL, GL_TEXTURE_LOD_BIAS, 0);
|
||||
glDepthMask(GL_TRUE);
|
||||
glDisable(GL_ALPHA_TEST);
|
||||
}
|
||||
}
|
||||
} // namespace vtkm::rendering
|
@ -1,58 +0,0 @@
|
||||
//============================================================================
|
||||
// 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.
|
||||
//============================================================================
|
||||
#ifndef vtk_m_rendering_WorldAnnotatorGL_h
|
||||
#define vtk_m_rendering_WorldAnnotatorGL_h
|
||||
|
||||
#include <vtkm/rendering/WorldAnnotator.h>
|
||||
|
||||
#include <vtkm/rendering/BitmapFont.h>
|
||||
#include <vtkm/rendering/Canvas.h>
|
||||
#include <vtkm/rendering/TextureGL.h>
|
||||
|
||||
namespace vtkm
|
||||
{
|
||||
namespace rendering
|
||||
{
|
||||
|
||||
class VTKM_RENDERING_EXPORT WorldAnnotatorGL : public WorldAnnotator
|
||||
{
|
||||
public:
|
||||
WorldAnnotatorGL(const vtkm::rendering::Canvas* canvas);
|
||||
|
||||
~WorldAnnotatorGL();
|
||||
|
||||
void AddLine(const vtkm::Vec3f_64& point0,
|
||||
const vtkm::Vec3f_64& point1,
|
||||
vtkm::Float32 lineWidth,
|
||||
const vtkm::rendering::Color& color,
|
||||
bool inFront) const override;
|
||||
|
||||
void AddText(const vtkm::Vec3f_32& origin,
|
||||
const vtkm::Vec3f_32& right,
|
||||
const vtkm::Vec3f_32& up,
|
||||
vtkm::Float32 scale,
|
||||
const vtkm::Vec2f_32& anchor,
|
||||
const vtkm::rendering::Color& color,
|
||||
const std::string& text,
|
||||
const vtkm::Float32 depth = 0.f) const override;
|
||||
|
||||
private:
|
||||
BitmapFont Font;
|
||||
TextureGL FontTexture;
|
||||
|
||||
void RenderText(vtkm::Float32 scale,
|
||||
vtkm::Float32 anchorx,
|
||||
vtkm::Float32 anchory,
|
||||
std::string text) const;
|
||||
};
|
||||
}
|
||||
} //namespace vtkm::rendering
|
||||
|
||||
#endif // vtk_m_rendering_WorldAnnotatorGL_h
|
@ -28,14 +28,3 @@ set(unit_tests
|
||||
)
|
||||
|
||||
vtkm_unit_tests(SOURCES ${unit_tests} ALL_BACKENDS LIBRARIES vtkm_rendering)
|
||||
|
||||
if(VTKm_ENABLE_GL_CONTEXT)
|
||||
# message(STATUS "rendering testing/glfw needs a FindGLFW")
|
||||
# message(STATUS "rendering testing/glut needs compile corrections")
|
||||
# add_subdirectory(glfw)
|
||||
# add_subdirectory(glut)
|
||||
elseif(VTKm_ENABLE_OSMESA_CONTEXT)
|
||||
add_subdirectory(osmesa)
|
||||
elseif(VTKm_ENABLE_EGL_CONTEXT)
|
||||
add_subdirectory(egl)
|
||||
endif()
|
||||
|
@ -1,14 +0,0 @@
|
||||
##============================================================================
|
||||
## 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.
|
||||
##============================================================================
|
||||
|
||||
set(unit_tests
|
||||
UnitTestMapperEGL.cxx
|
||||
)
|
||||
vtkm_unit_tests(SOURCES ${unit_tests} LIBRARIES vtkm_rendering)
|
@ -1,103 +0,0 @@
|
||||
//============================================================================
|
||||
// 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.
|
||||
//============================================================================
|
||||
#include <vtkm/Bounds.h>
|
||||
#include <vtkm/cont/DataSetFieldAdd.h>
|
||||
#include <vtkm/cont/DeviceAdapter.h>
|
||||
#include <vtkm/cont/testing/MakeTestDataSet.h>
|
||||
#include <vtkm/cont/testing/Testing.h>
|
||||
#include <vtkm/rendering/Actor.h>
|
||||
#include <vtkm/rendering/CanvasEGL.h>
|
||||
#include <vtkm/rendering/Color.h>
|
||||
#include <vtkm/rendering/MapperGL.h>
|
||||
#include <vtkm/rendering/Scene.h>
|
||||
#include <vtkm/rendering/View1D.h>
|
||||
#include <vtkm/rendering/View2D.h>
|
||||
#include <vtkm/rendering/View3D.h>
|
||||
#include <vtkm/rendering/testing/RenderTest.h>
|
||||
|
||||
namespace
|
||||
{
|
||||
|
||||
void RenderTests()
|
||||
{
|
||||
using M = vtkm::rendering::MapperGL;
|
||||
using C = vtkm::rendering::CanvasEGL;
|
||||
using V3 = vtkm::rendering::View3D;
|
||||
using V2 = vtkm::rendering::View2D;
|
||||
using V1 = vtkm::rendering::View1D;
|
||||
|
||||
vtkm::cont::DataSetFieldAdd dsf;
|
||||
vtkm::cont::testing::MakeTestDataSet maker;
|
||||
vtkm::cont::ColorTable colorTable("inferno");
|
||||
|
||||
vtkm::rendering::testing::Render<M, C, V3>(
|
||||
maker.Make3DRegularDataSet0(), "pointvar", colorTable, "reg3D.pnm");
|
||||
vtkm::rendering::testing::Render<M, C, V3>(
|
||||
maker.Make3DRectilinearDataSet0(), "pointvar", colorTable, "rect3D.pnm");
|
||||
vtkm::rendering::testing::Render<M, C, V3>(
|
||||
maker.Make3DExplicitDataSet4(), "pointvar", colorTable, "expl3D.pnm");
|
||||
vtkm::rendering::testing::Render<M, C, V2>(
|
||||
maker.Make2DRectilinearDataSet0(), "pointvar", colorTable, "rect2D.pnm");
|
||||
vtkm::rendering::testing::Render<M, C, V1>(
|
||||
maker.Make1DUniformDataSet0(), "pointvar", vtkm::rendering::Color::white, "uniform1D.pnm");
|
||||
vtkm::rendering::testing::Render<M, C, V1>(
|
||||
maker.Make1DExplicitDataSet0(), "pointvar", vtkm::rendering::Color::white, "expl1D.pnm");
|
||||
|
||||
vtkm::cont::DataSet ds = maker.Make1DUniformDataSet0();
|
||||
vtkm::Int32 nVerts = ds.GetField(0).GetNumberOfValues();
|
||||
vtkm::Float32 vars[nVerts];
|
||||
vtkm::Float32 smallVal = 1.000;
|
||||
for (vtkm::Int32 i = 0; i <= nVerts; i++)
|
||||
{
|
||||
vars[i] = smallVal;
|
||||
smallVal += .01;
|
||||
}
|
||||
dsf.AddPointField(ds, "smallScaledYAxis", vars, nVerts);
|
||||
vtkm::rendering::testing::Render<M, C, V1>(
|
||||
ds, "smallScaledYAxis", vtkm::rendering::Color::white, "uniform1DSmallScaledYAxis.pnm");
|
||||
|
||||
// Test to demonstrate that straight horizontal lines can be drawn
|
||||
ds = maker.Make1DUniformDataSet0();
|
||||
nVerts = ds.GetField(0).GetNumberOfValues();
|
||||
vtkm::Float32 largeVal = 1e-16;
|
||||
for (vtkm::Int32 i = 0; i <= nVerts; i++)
|
||||
{
|
||||
vars[i] = largeVal;
|
||||
}
|
||||
dsf.AddPointField(ds, "straightLine", vars, nVerts);
|
||||
vtkm::rendering::testing::Render<M, C, V1>(
|
||||
ds, "straightLine", vtkm::rendering::Color::white, "uniform1DStraightLine.pnm");
|
||||
|
||||
|
||||
ds = maker.Make1DUniformDataSet0();
|
||||
nVerts = ds.GetField(0).GetNumberOfValues();
|
||||
largeVal = 1;
|
||||
for (vtkm::Int32 i = 0; i <= nVerts; i++)
|
||||
{
|
||||
vars[i] = largeVal;
|
||||
if (i < 2)
|
||||
{
|
||||
largeVal *= 100;
|
||||
}
|
||||
else
|
||||
{
|
||||
largeVal /= 2.25;
|
||||
}
|
||||
}
|
||||
dsf.AddPointField(ds, "logScaledYAxis", vars, nVerts);
|
||||
vtkm::rendering::testing::Render<M, C, V1>(
|
||||
ds, "logScaledYAxis", vtkm::rendering::Color::white, "uniform1DLogScaledYAxis.pnm", true);
|
||||
}
|
||||
} //namespace
|
||||
|
||||
int UnitTestMapperEGL(int argc, char* argv[])
|
||||
{
|
||||
return vtkm::cont::testing::Testing::Run(RenderTests, argc, argv);
|
||||
}
|
@ -1,21 +0,0 @@
|
||||
##============================================================================
|
||||
## 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.
|
||||
##============================================================================
|
||||
find_package(GLFW QUIET)
|
||||
if(NOT TARGET GLFW::GLFW)
|
||||
return()
|
||||
endif()
|
||||
|
||||
set(unit_tests
|
||||
UnitTestMapperGLFW.cxx
|
||||
)
|
||||
vtkm_unit_tests(SOURCES ${unit_tests}
|
||||
TEST_ARGS -B
|
||||
LIBRARIES vtkm_rendering GLFW::GLFW)
|
||||
|
@ -1,188 +0,0 @@
|
||||
//============================================================================
|
||||
// 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.
|
||||
//============================================================================
|
||||
#include <vtkm/Bounds.h>
|
||||
#include <vtkm/cont/DataSetFieldAdd.h>
|
||||
#include <vtkm/cont/DeviceAdapter.h>
|
||||
#include <vtkm/cont/testing/MakeTestDataSet.h>
|
||||
#include <vtkm/cont/testing/Testing.h>
|
||||
#include <vtkm/rendering/Actor.h>
|
||||
#include <vtkm/rendering/CanvasGL.h>
|
||||
#include <vtkm/rendering/Color.h>
|
||||
#include <vtkm/rendering/MapperGL.h>
|
||||
#include <vtkm/rendering/Scene.h>
|
||||
#include <vtkm/rendering/View1D.h>
|
||||
#include <vtkm/rendering/View2D.h>
|
||||
#include <vtkm/rendering/View3D.h>
|
||||
#include <vtkm/rendering/testing/RenderTest.h>
|
||||
|
||||
// this needs to be included after the vtk-m headers so that we include
|
||||
// the gl headers in the correct order
|
||||
#include <GLFW/glfw3.h>
|
||||
|
||||
#include <cstring>
|
||||
#include <string>
|
||||
|
||||
namespace
|
||||
{
|
||||
static constexpr vtkm::Id WIDTH = 512, HEIGHT = 512;
|
||||
static vtkm::Id which = 0, NUM_DATASETS = 5;
|
||||
static bool done = false;
|
||||
static bool batch = false;
|
||||
|
||||
static void keyCallback(GLFWwindow* vtkmNotUsed(window),
|
||||
int key,
|
||||
int vtkmNotUsed(scancode),
|
||||
int action,
|
||||
int vtkmNotUsed(mods))
|
||||
{
|
||||
if (key == GLFW_KEY_ESCAPE)
|
||||
done = true;
|
||||
if (action == 1)
|
||||
which = (which + 1) % NUM_DATASETS;
|
||||
}
|
||||
|
||||
void RenderTests()
|
||||
{
|
||||
std::cout << "Press any key to cycle through datasets. ESC to quit." << std::endl;
|
||||
|
||||
using MapperType = vtkm::rendering::MapperGL;
|
||||
using CanvasType = vtkm::rendering::CanvasGL;
|
||||
using View3DType = vtkm::rendering::View3D;
|
||||
using View2DType = vtkm::rendering::View2D;
|
||||
using View1DType = vtkm::rendering::View1D;
|
||||
|
||||
vtkm::cont::DataSetFieldAdd dsf;
|
||||
vtkm::cont::testing::MakeTestDataSet maker;
|
||||
vtkm::cont::ColorTable colorTable("inferno");
|
||||
|
||||
glfwInit();
|
||||
GLFWwindow* window = glfwCreateWindow(WIDTH, HEIGHT, "GLFW Test", nullptr, nullptr);
|
||||
glfwMakeContextCurrent(window);
|
||||
glfwSetKeyCallback(window, keyCallback);
|
||||
|
||||
CanvasType canvas[5] = { CanvasType(512, 512),
|
||||
CanvasType(512, 512),
|
||||
CanvasType(512, 512),
|
||||
CanvasType(512, 512),
|
||||
CanvasType(512, 512) };
|
||||
vtkm::rendering::Scene scene[5];
|
||||
vtkm::cont::DataSet ds[5];
|
||||
MapperType mapper[5];
|
||||
vtkm::rendering::Camera camera[5];
|
||||
|
||||
ds[0] = maker.Make3DRegularDataSet0();
|
||||
ds[1] = maker.Make3DRectilinearDataSet0();
|
||||
ds[2] = maker.Make3DExplicitDataSet4();
|
||||
ds[3] = maker.Make2DRectilinearDataSet0();
|
||||
//create 1D uniform DS with tiny Y axis
|
||||
vtkm::cont::DataSet tinyDS = maker.Make1DUniformDataSet0();
|
||||
const std::size_t nVerts = static_cast<std::size_t>(tinyDS.GetField(0).GetNumberOfValues());
|
||||
std::vector<vtkm::Float32> vars(nVerts);
|
||||
float smallVal = 1.000;
|
||||
for (std::size_t i = 0; i < nVerts; i++)
|
||||
{
|
||||
vars[i] = smallVal;
|
||||
smallVal += .01f;
|
||||
}
|
||||
dsf.AddPointField(tinyDS, "smallScaledXAxis", vars);
|
||||
ds[4] = tinyDS;
|
||||
tinyDS.PrintSummary(std::cerr);
|
||||
|
||||
std::string fldNames[5];
|
||||
fldNames[0] = "pointvar";
|
||||
fldNames[1] = "pointvar";
|
||||
fldNames[2] = "pointvar";
|
||||
fldNames[3] = "pointvar";
|
||||
fldNames[4] = "smallScaledXAxis";
|
||||
|
||||
for (int i = 0; i < NUM_DATASETS; i++)
|
||||
{
|
||||
if (i < 3)
|
||||
{
|
||||
scene[i].AddActor(vtkm::rendering::Actor(ds[i].GetCellSet(),
|
||||
ds[i].GetCoordinateSystem(),
|
||||
ds[i].GetField(fldNames[i].c_str()),
|
||||
colorTable));
|
||||
vtkm::rendering::testing::SetCamera<View3DType>(camera[i],
|
||||
ds[i].GetCoordinateSystem().GetBounds());
|
||||
}
|
||||
else if (i == 3)
|
||||
{
|
||||
scene[i].AddActor(vtkm::rendering::Actor(ds[i].GetCellSet(),
|
||||
ds[i].GetCoordinateSystem(),
|
||||
ds[i].GetField(fldNames[i].c_str()),
|
||||
colorTable));
|
||||
vtkm::rendering::testing::SetCamera<View2DType>(camera[i],
|
||||
ds[i].GetCoordinateSystem().GetBounds());
|
||||
}
|
||||
else
|
||||
{
|
||||
scene[i].AddActor(vtkm::rendering::Actor(ds[i].GetCellSet(),
|
||||
ds[i].GetCoordinateSystem(),
|
||||
ds[i].GetField(fldNames[i].c_str()),
|
||||
vtkm::rendering::Color::white));
|
||||
vtkm::rendering::testing::SetCamera<View1DType>(
|
||||
camera[i], ds[i].GetCoordinateSystem().GetBounds(), ds[i].GetField(fldNames[i].c_str()));
|
||||
}
|
||||
}
|
||||
|
||||
View3DType view3d0(
|
||||
scene[0], mapper[0], canvas[0], camera[0], vtkm::rendering::Color(0.2f, 0.2f, 0.2f, 1.0f));
|
||||
View3DType view3d1(
|
||||
scene[1], mapper[1], canvas[1], camera[1], vtkm::rendering::Color(0.2f, 0.2f, 0.2f, 1.0f));
|
||||
View3DType view3d2(
|
||||
scene[2], mapper[2], canvas[2], camera[2], vtkm::rendering::Color(0.2f, 0.2f, 0.2f, 1.0f));
|
||||
View2DType view2d0(
|
||||
scene[3], mapper[3], canvas[3], camera[3], vtkm::rendering::Color(0.2f, 0.2f, 0.2f, 1.0f));
|
||||
View1DType view1d0(
|
||||
scene[4], mapper[4], canvas[4], camera[4], vtkm::rendering::Color(0.2f, 0.2f, 0.2f, 1.0f));
|
||||
|
||||
while (!glfwWindowShouldClose(window) && !done)
|
||||
{
|
||||
glfwPollEvents();
|
||||
|
||||
if (which == 0)
|
||||
vtkm::rendering::testing::Render<MapperType, CanvasType, View3DType>(view3d0, "reg3D.pnm");
|
||||
else if (which == 1)
|
||||
vtkm::rendering::testing::Render<MapperType, CanvasType, View3DType>(view3d1, "rect3D.pnm");
|
||||
else if (which == 2)
|
||||
vtkm::rendering::testing::Render<MapperType, CanvasType, View3DType>(view3d2, "expl3D.pnm");
|
||||
else if (which == 3)
|
||||
vtkm::rendering::testing::Render<MapperType, CanvasType, View2DType>(view2d0, "rect2D.pnm");
|
||||
else if (which == 4)
|
||||
vtkm::rendering::testing::Render<MapperType, CanvasType, View1DType>(
|
||||
view1d0, "uniform1DSmallScaledXAxis.pnm");
|
||||
glfwSwapBuffers(window);
|
||||
|
||||
if (batch)
|
||||
{
|
||||
which++;
|
||||
if (which >= NUM_DATASETS)
|
||||
{
|
||||
break;
|
||||
}
|
||||
}
|
||||
}
|
||||
|
||||
glfwDestroyWindow(window);
|
||||
}
|
||||
} //namespace
|
||||
|
||||
int UnitTestMapperGLFW(int argc, char* argv[])
|
||||
{
|
||||
if (argc > 1)
|
||||
{
|
||||
if (strcmp(argv[1], "-B") == 0)
|
||||
{
|
||||
batch = true;
|
||||
}
|
||||
}
|
||||
return vtkm::cont::testing::Testing::Run(RenderTests);
|
||||
}
|
@ -1,25 +0,0 @@
|
||||
##============================================================================
|
||||
## 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.
|
||||
##============================================================================
|
||||
if(NOT TARGET GLUT::GLUT)
|
||||
find_package(GLUT QUIET)
|
||||
|
||||
if(NOT TARGET GLUT::GLUT)
|
||||
return()
|
||||
endif()
|
||||
endif()
|
||||
|
||||
set(unit_tests
|
||||
UnitTestMapperGLUT.cxx
|
||||
)
|
||||
|
||||
vtkm_unit_tests(SOURCES ${unit_tests}
|
||||
TEST_ARGS -B
|
||||
LIBRARIES vtkm_rendering GLUT::GLUT)
|
||||
|
@ -1,113 +0,0 @@
|
||||
//============================================================================
|
||||
// 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.
|
||||
//============================================================================
|
||||
#include <vtkm/Bounds.h>
|
||||
#include <vtkm/cont/testing/MakeTestDataSet.h>
|
||||
|
||||
#include <GL/glew.h>
|
||||
#if defined(__APPLE__)
|
||||
#include <GLUT/glut.h>
|
||||
#else
|
||||
#include <GL/glut.h>
|
||||
#endif
|
||||
|
||||
#include <string.h>
|
||||
#include <vtkm/cont/DeviceAdapter.h>
|
||||
#include <vtkm/cont/testing/Testing.h>
|
||||
#include <vtkm/rendering/Actor.h>
|
||||
#include <vtkm/rendering/CanvasGL.h>
|
||||
#include <vtkm/rendering/MapperGL.h>
|
||||
#include <vtkm/rendering/Scene.h>
|
||||
#include <vtkm/rendering/View.h>
|
||||
#include <vtkm/rendering/testing/RenderTest.h>
|
||||
|
||||
namespace
|
||||
{
|
||||
static constexpr vtkm::Id WIDTH = 512, HEIGHT = 512;
|
||||
static vtkm::Id windowID, which = 0, NUM_DATASETS = 4;
|
||||
static bool done = false;
|
||||
static bool batch = false;
|
||||
|
||||
static void keyboardCall(unsigned char key, int vtkmNotUsed(x), int vtkmNotUsed(y))
|
||||
{
|
||||
if (key == 27)
|
||||
glutDestroyWindow(windowID);
|
||||
else
|
||||
{
|
||||
which = (which + 1) % NUM_DATASETS;
|
||||
glutPostRedisplay();
|
||||
}
|
||||
}
|
||||
|
||||
static void displayCall()
|
||||
{
|
||||
vtkm::cont::testing::MakeTestDataSet maker;
|
||||
vtkm::cont::ColorTable colorTable("inferno");
|
||||
|
||||
using M = vtkm::rendering::MapperGL;
|
||||
using C = vtkm::rendering::CanvasGL;
|
||||
using V3 = vtkm::rendering::View3D;
|
||||
using V2 = vtkm::rendering::View2D;
|
||||
|
||||
if (which == 0)
|
||||
vtkm::rendering::testing::Render<M, C, V3>(
|
||||
maker.Make3DRegularDataSet0(), "pointvar", colorTable, "reg3D.pnm");
|
||||
else if (which == 1)
|
||||
vtkm::rendering::testing::Render<M, C, V3>(
|
||||
maker.Make3DRectilinearDataSet0(), "pointvar", colorTable, "rect3D.pnm");
|
||||
else if (which == 2)
|
||||
vtkm::rendering::testing::Render<M, C, V3>(
|
||||
maker.Make3DExplicitDataSet4(), "pointvar", colorTable, "expl3D.pnm");
|
||||
else if (which == 3)
|
||||
vtkm::rendering::testing::Render<M, C, V2>(
|
||||
maker.Make2DRectilinearDataSet0(), "pointvar", colorTable, "rect2D.pnm");
|
||||
glutSwapBuffers();
|
||||
}
|
||||
|
||||
void batchIdle()
|
||||
{
|
||||
which++;
|
||||
if (which >= NUM_DATASETS)
|
||||
glutDestroyWindow(windowID);
|
||||
else
|
||||
glutPostRedisplay();
|
||||
}
|
||||
|
||||
void RenderTests()
|
||||
{
|
||||
if (!batch)
|
||||
std::cout << "Press any key to cycle through datasets. ESC to quit." << std::endl;
|
||||
|
||||
int argc = 0;
|
||||
char* argv = nullptr;
|
||||
glutInit(&argc, &argv);
|
||||
glutInitDisplayMode(GLUT_RGB | GLUT_DOUBLE | GLUT_DEPTH);
|
||||
glutInitWindowSize(WIDTH, HEIGHT);
|
||||
windowID = glutCreateWindow("GLUT test");
|
||||
glutDisplayFunc(displayCall);
|
||||
glutKeyboardFunc(keyboardCall);
|
||||
if (batch)
|
||||
glutIdleFunc(batchIdle);
|
||||
|
||||
glutMainLoop();
|
||||
}
|
||||
|
||||
} //namespace
|
||||
|
||||
int UnitTestMapperGLUT(int argc, char* argv[])
|
||||
{
|
||||
if (argc > 1)
|
||||
{
|
||||
if (strcmp(argv[1], "-B") == 0)
|
||||
{
|
||||
batch = true;
|
||||
}
|
||||
}
|
||||
return vtkm::cont::testing::Testing::Run(RenderTests);
|
||||
}
|
@ -1,16 +0,0 @@
|
||||
##============================================================================
|
||||
## 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.
|
||||
##============================================================================
|
||||
|
||||
set(unit_tests
|
||||
UnitTestMapperOSMesa.cxx
|
||||
)
|
||||
|
||||
vtkm_unit_tests(SOURCES ${unit_tests} LIBRARIES vtkm_rendering)
|
||||
|
@ -1,56 +0,0 @@
|
||||
//============================================================================
|
||||
// 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.
|
||||
//============================================================================
|
||||
#include <vtkm/Bounds.h>
|
||||
#include <vtkm/cont/DeviceAdapter.h>
|
||||
#include <vtkm/cont/testing/MakeTestDataSet.h>
|
||||
#include <vtkm/cont/testing/Testing.h>
|
||||
#include <vtkm/rendering/Actor.h>
|
||||
#include <vtkm/rendering/CanvasOSMesa.h>
|
||||
#include <vtkm/rendering/Color.h>
|
||||
#include <vtkm/rendering/MapperGL.h>
|
||||
#include <vtkm/rendering/Scene.h>
|
||||
#include <vtkm/rendering/View2D.h>
|
||||
#include <vtkm/rendering/View3D.h>
|
||||
#include <vtkm/rendering/testing/RenderTest.h>
|
||||
|
||||
namespace
|
||||
{
|
||||
|
||||
void RenderTests()
|
||||
{
|
||||
using M = vtkm::rendering::MapperGL;
|
||||
using C = vtkm::rendering::CanvasOSMesa;
|
||||
using V3 = vtkm::rendering::View3D;
|
||||
using V2 = vtkm::rendering::View2D;
|
||||
using V1 = vtkm::rendering::View1D;
|
||||
|
||||
vtkm::cont::testing::MakeTestDataSet maker;
|
||||
vtkm::cont::ColorTable colorTable("inferno");
|
||||
|
||||
vtkm::rendering::testing::Render<M, C, V3>(
|
||||
maker.Make3DRegularDataSet0(), "pointvar", colorTable, "reg3D.pnm");
|
||||
vtkm::rendering::testing::Render<M, C, V3>(
|
||||
maker.Make3DRectilinearDataSet0(), "pointvar", colorTable, "rect3D.pnm");
|
||||
vtkm::rendering::testing::Render<M, C, V3>(
|
||||
maker.Make3DExplicitDataSet4(), "pointvar", colorTable, "expl3D.pnm");
|
||||
vtkm::rendering::testing::Render<M, C, V2>(
|
||||
maker.Make2DRectilinearDataSet0(), "pointvar", colorTable, "rect2D.pnm");
|
||||
vtkm::rendering::testing::Render<M, C, V1>(
|
||||
maker.Make1DUniformDataSet0(), "pointvar", vtkm::rendering::Color(1, 1, 1, 1), "uniform1D.pnm");
|
||||
vtkm::rendering::testing::Render<M, C, V1>(
|
||||
maker.Make1DExplicitDataSet0(), "pointvar", vtkm::rendering::Color(1, 1, 1, 1), "expl1D.pnm");
|
||||
}
|
||||
|
||||
} //namespace
|
||||
|
||||
int UnitTestMapperOSMesa(int argc, char* argv[])
|
||||
{
|
||||
return vtkm::cont::testing::Testing::Run(RenderTests, argc, argv);
|
||||
}
|
Loading…
Reference in New Issue
Block a user