From 48ee2e5182d2f657984607dc580f463210a703f0 Mon Sep 17 00:00:00 2001 From: Vicente Adolfo Bolea Sanchez Date: Mon, 23 Mar 2020 19:36:18 -0400 Subject: [PATCH] removed classes related to OpenGL/OSMESA/EGL --- vtkm/rendering/CMakeLists.txt | 60 -- vtkm/rendering/CanvasEGL.cxx | 122 ---- vtkm/rendering/CanvasEGL.h | 49 -- vtkm/rendering/CanvasGL.cxx | 353 ------------ vtkm/rendering/CanvasGL.h | 86 --- vtkm/rendering/CanvasOSMesa.cxx | 120 ---- vtkm/rendering/CanvasOSMesa.h | 54 -- vtkm/rendering/MapperGL.cxx | 534 ------------------ vtkm/rendering/MapperGL.h | 56 -- vtkm/rendering/TextureGL.cxx | 176 ------ vtkm/rendering/TextureGL.h | 47 -- vtkm/rendering/WorldAnnotatorGL.cxx | 163 ------ vtkm/rendering/WorldAnnotatorGL.h | 58 -- vtkm/rendering/testing/CMakeLists.txt | 11 - vtkm/rendering/testing/egl/CMakeLists.txt | 14 - .../testing/egl/UnitTestMapperEGL.cxx | 103 ---- vtkm/rendering/testing/glfw/CMakeLists.txt | 21 - .../testing/glfw/UnitTestMapperGLFW.cxx | 188 ------ vtkm/rendering/testing/glut/CMakeLists.txt | 25 - .../testing/glut/UnitTestMapperGLUT.cxx | 113 ---- vtkm/rendering/testing/osmesa/CMakeLists.txt | 16 - .../testing/osmesa/UnitTestMapperOSMesa.cxx | 56 -- 22 files changed, 2425 deletions(-) delete mode 100644 vtkm/rendering/CanvasEGL.cxx delete mode 100644 vtkm/rendering/CanvasEGL.h delete mode 100644 vtkm/rendering/CanvasGL.cxx delete mode 100644 vtkm/rendering/CanvasGL.h delete mode 100644 vtkm/rendering/CanvasOSMesa.cxx delete mode 100644 vtkm/rendering/CanvasOSMesa.h delete mode 100644 vtkm/rendering/MapperGL.cxx delete mode 100644 vtkm/rendering/MapperGL.h delete mode 100644 vtkm/rendering/TextureGL.cxx delete mode 100644 vtkm/rendering/TextureGL.h delete mode 100644 vtkm/rendering/WorldAnnotatorGL.cxx delete mode 100644 vtkm/rendering/WorldAnnotatorGL.h delete mode 100644 vtkm/rendering/testing/egl/CMakeLists.txt delete mode 100644 vtkm/rendering/testing/egl/UnitTestMapperEGL.cxx delete mode 100644 vtkm/rendering/testing/glfw/CMakeLists.txt delete mode 100644 vtkm/rendering/testing/glfw/UnitTestMapperGLFW.cxx delete mode 100644 vtkm/rendering/testing/glut/CMakeLists.txt delete mode 100644 vtkm/rendering/testing/glut/UnitTestMapperGLUT.cxx delete mode 100644 vtkm/rendering/testing/osmesa/CMakeLists.txt delete mode 100644 vtkm/rendering/testing/osmesa/UnitTestMapperOSMesa.cxx diff --git a/vtkm/rendering/CMakeLists.txt b/vtkm/rendering/CMakeLists.txt index add1b528f..bed5b8a76 100644 --- a/vtkm/rendering/CMakeLists.txt +++ b/vtkm/rendering/CMakeLists.txt @@ -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) diff --git a/vtkm/rendering/CanvasEGL.cxx b/vtkm/rendering/CanvasEGL.cxx deleted file mode 100644 index 14417125c..000000000 --- a/vtkm/rendering/CanvasEGL.cxx +++ /dev/null @@ -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 - -#include -#include -#include -#include -#include - -#include -//#include - -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(this->GetWidth()), - EGL_HEIGHT, static_cast(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 diff --git a/vtkm/rendering/CanvasEGL.h b/vtkm/rendering/CanvasEGL.h deleted file mode 100644 index 56c53e96c..000000000 --- a/vtkm/rendering/CanvasEGL.h +++ /dev/null @@ -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 - -#include - -#include - -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 Internals; -}; -} -} //namespace vtkm::rendering - -#endif //vtk_m_rendering_CanvasEGL_h diff --git a/vtkm/rendering/CanvasGL.cxx b/vtkm/rendering/CanvasGL.cxx deleted file mode 100644 index 5009202ff..000000000 --- a/vtkm/rendering/CanvasGL.cxx +++ /dev/null @@ -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 - -#include -#include -#include -#include -#include -#include -#include -#include - -#include - -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(this->GetWidth()) * (1.f + vl) / 2.f; - vtkm::Float32 _y = static_cast(this->GetHeight()) * (1.f + vb) / 2.f; - vtkm::Float32 _w = static_cast(this->GetWidth()) * (vr - vl) / 2.f; - vtkm::Float32 _h = static_cast(this->GetHeight()) * (vt - vb) / 2.f; - - glViewport(static_cast(_x), - static_cast(_y), - static_cast(_w), - static_cast(_h)); - } - else - { - glViewport( - 0, 0, static_cast(this->GetWidth()), static_cast(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*>(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(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 colors; - colorTable.Sample(n + 1, colors); - - vtkm::Float32 startX = static_cast(bounds.X.Min); - vtkm::Float32 startY = static_cast(bounds.Y.Min); - vtkm::Float32 width = static_cast(bounds.X.Length()); - vtkm::Float32 height = static_cast(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(i) / static_cast(n); - vtkm::Float32 v1 = static_cast(i + 1) / static_cast(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(this); - self->Font = BitmapFontFactory::CreateLiberation2Sans(); - const std::vector& rawpngdata = this->Font.GetRawImageData(); - - std::vector 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 diff --git a/vtkm/rendering/CanvasGL.h b/vtkm/rendering/CanvasGL.h deleted file mode 100644 index 93f9504dc..000000000 --- a/vtkm/rendering/CanvasGL.h +++ /dev/null @@ -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 - -#include -#include -#include - -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 diff --git a/vtkm/rendering/CanvasOSMesa.cxx b/vtkm/rendering/CanvasOSMesa.cxx deleted file mode 100644 index cd790d876..000000000 --- a/vtkm/rendering/CanvasOSMesa.cxx +++ /dev/null @@ -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 - -#include -#include -#include -#include -#ifndef GLAPI -#define GLAPI extern -#endif - -#ifndef GLAPIENTRY -#define GLAPIENTRY -#endif - -#ifndef APIENTRY -#define APIENTRY GLAPIENTRY -#endif -#include - -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(colorBuffer), - GL_FLOAT, - static_cast(this->GetWidth()), - static_cast(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(w)!=this->GetWidth() || - static_cast(h)!=this->GetHeight()) - { - throw vtkm::cont::ErrorBadValue("Wrong width/height in ZBuffer"); - } - vtkm::cont::ArrayHandle::WritePortalType depthPortal = - this->GetDepthBuffer().WritePortal(); - vtkm::Id npixels = this->GetWidth()*this->GetHeight(); - for (vtkm::Id i=0; i - -#include - -#include - -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 Internals; -}; -} -} //namespace vtkm::rendering - -#endif //vtk_m_rendering_CanvasOSMesa_h diff --git a/vtkm/rendering/MapperGL.cxx b/vtkm/rendering/MapperGL.cxx deleted file mode 100644 index 0d223eabe..000000000 --- a/vtkm/rendering/MapperGL.cxx +++ /dev/null @@ -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 - -#include -#include -#include -#include -#include -#include - -#include - -#include - -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 - 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 color1; - vtkm::Vec color2; - vtkm::Vec 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 -struct MapColorAndVerticesInvokeFunctor -{ - vtkm::cont::ArrayHandle TriangleIndices; - vtkm::cont::ColorTable ColorTable; - const vtkm::cont::ArrayHandle Scalar; - const vtkm::Range ScalarRange; - const PtType Vertices; - vtkm::Float32 SMin; - vtkm::Float32 SDiff; - vtkm::cont::ArrayHandle OutColor; - vtkm::cont::ArrayHandle OutVertices; - - VTKM_CONT - MapColorAndVerticesInvokeFunctor(const vtkm::cont::ArrayHandle& indices, - const vtkm::cont::ColorTable& colorTable, - const vtkm::cont::ArrayHandle& scalar, - const vtkm::Range& scalarRange, - const PtType& vertices, - vtkm::Float32 s_min, - vtkm::Float32 s_max, - vtkm::cont::ArrayHandle& out_color, - vtkm::cont::ArrayHandle& 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 - 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 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 -VTKM_CONT void RenderStructuredLineSegments(vtkm::Id numVerts, - const PtType& verts, - const vtkm::cont::ArrayHandle& 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 data; - ct.GetPoint(0, data); - r = static_cast(data[1] * 255.0 + 0.5); - g = static_cast(data[2] * 255.0 + 0.5); - b = static_cast(data[3] * 255.0 + 0.5); - ct.GetPointAlpha(0, data); - a = static_cast(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 -VTKM_CONT void RenderExplicitLineSegments(vtkm::Id numVerts, - const PtType& verts, - const vtkm::cont::ArrayHandle& 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 data; - ct.GetPoint(0, data); - r = static_cast(data[1] * 255.0 + 0.5); - g = static_cast(data[2] * 255.0 + 0.5); - b = static_cast(data[3] * 255.0 + 0.5); - ct.GetPointAlpha(0, data); - a = static_cast(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 -VTKM_CONT void RenderTriangles(MapperGL& mapper, - vtkm::Id numTri, - const PtType& verts, - const vtkm::cont::ArrayHandle& indices, - const vtkm::cont::ArrayHandle& 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 out_vertices, out_color; - out_vertices.Allocate(9 * indices.GetNumberOfValues()); - out_color.Allocate(9 * indices.GetNumberOfValues()); - - vtkm::cont::TryExecute(MapColorAndVerticesInvokeFunctor( - 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(sizeof(vtkm::Float32)); - GLsizeiptr sz = static_cast(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 viewM = camera.CreateViewMatrix(); - vtkm::Matrix 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(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 sf; - sf = scalarField.GetData().Cast>(); - 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(); - RenderStructuredLineSegments(numVerts, verts, sf, colorTable, this->LogarithmY); - } - else if (cellset.IsSameType(vtkm::cont::CellSetSingleType<>()) && - cellset.Cast>().GetCellShapeAsId() == - vtkm::CELL_SHAPE_LINE) - { - vtkm::cont::ArrayHandle verts; - verts = dcoords.Cast>(); - RenderExplicitLineSegments(numVerts, verts, sf, colorTable, this->LogarithmY); - } - else - { - vtkm::cont::ArrayHandle indices; - vtkm::Id numTri; - vtkm::rendering::internal::RunTriangulator(cellset, indices, numTri); - - vtkm::cont::ArrayHandleUniformPointCoordinates uVerts; - vtkm::cont::ArrayHandle eVerts; - - if (dcoords.IsType()) - { - uVerts = dcoords.Cast(); - RenderTriangles(*this, numTri, uVerts, indices, sf, colorTable, scalarRange, camera); - } - else if (dcoords.IsType>()) - { - eVerts = dcoords.Cast>(); - RenderTriangles(*this, numTri, eVerts, indices, sf, colorTable, scalarRange, camera); - } - else if (dcoords.IsType, - vtkm::cont::ArrayHandle, - vtkm::cont::ArrayHandle>>()) - { - vtkm::cont::ArrayHandleCartesianProduct, - vtkm::cont::ArrayHandle, - vtkm::cont::ArrayHandle> - rVerts; - rVerts = dcoords.Cast< - vtkm::cont::ArrayHandleCartesianProduct, - vtkm::cont::ArrayHandle, - vtkm::cont::ArrayHandle>>(); - 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(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 diff --git a/vtkm/rendering/MapperGL.h b/vtkm/rendering/MapperGL.h deleted file mode 100644 index c1b3e40ee..000000000 --- a/vtkm/rendering/MapperGL.h +++ /dev/null @@ -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 -#include -#include -#include -#include - -#include - -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 diff --git a/vtkm/rendering/TextureGL.cxx b/vtkm/rendering/TextureGL.cxx deleted file mode 100644 index e639e0e60..000000000 --- a/vtkm/rendering/TextureGL.cxx +++ /dev/null @@ -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 - -#include - -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& rgba) -{ - this->Internals->Dimension = 2; - std::vector alpha(rgba.size() / 4); - VTKM_ASSERT(width * height == static_cast(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(width), - static_cast(height), - 0, - GL_ALPHA, - GL_UNSIGNED_BYTE, - (void*)(&(alpha[0]))); - } -} -} -} // namespace vtkm::rendering diff --git a/vtkm/rendering/TextureGL.h b/vtkm/rendering/TextureGL.h deleted file mode 100644 index 968df35bd..000000000 --- a/vtkm/rendering/TextureGL.h +++ /dev/null @@ -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 - -#include - -#include -#include - -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& rgba); - -private: - struct InternalsType; - std::shared_ptr Internals; -}; -} -} //namespace vtkm::rendering - -#endif //vtk_m_rendering_TextureGL_h diff --git a/vtkm/rendering/WorldAnnotatorGL.cxx b/vtkm/rendering/WorldAnnotatorGL.cxx deleted file mode 100644 index 0993743cc..000000000 --- a/vtkm/rendering/WorldAnnotatorGL.cxx +++ /dev/null @@ -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 - -#include -#include -#include -#include -#include -#include - -#include - -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 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(this); - self->Font = BitmapFontFactory::CreateLiberation2Sans(); - const std::vector& rawpngdata = this->Font.GetRawImageData(); - - std::vector 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 diff --git a/vtkm/rendering/WorldAnnotatorGL.h b/vtkm/rendering/WorldAnnotatorGL.h deleted file mode 100644 index f027d914a..000000000 --- a/vtkm/rendering/WorldAnnotatorGL.h +++ /dev/null @@ -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 - -#include -#include -#include - -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 diff --git a/vtkm/rendering/testing/CMakeLists.txt b/vtkm/rendering/testing/CMakeLists.txt index 2ab5d75bd..0277ff870 100644 --- a/vtkm/rendering/testing/CMakeLists.txt +++ b/vtkm/rendering/testing/CMakeLists.txt @@ -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() diff --git a/vtkm/rendering/testing/egl/CMakeLists.txt b/vtkm/rendering/testing/egl/CMakeLists.txt deleted file mode 100644 index 3c8b9b3fc..000000000 --- a/vtkm/rendering/testing/egl/CMakeLists.txt +++ /dev/null @@ -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) diff --git a/vtkm/rendering/testing/egl/UnitTestMapperEGL.cxx b/vtkm/rendering/testing/egl/UnitTestMapperEGL.cxx deleted file mode 100644 index 95ba6cb42..000000000 --- a/vtkm/rendering/testing/egl/UnitTestMapperEGL.cxx +++ /dev/null @@ -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 -#include -#include -#include -#include -#include -#include -#include -#include -#include -#include -#include -#include -#include - -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( - maker.Make3DRegularDataSet0(), "pointvar", colorTable, "reg3D.pnm"); - vtkm::rendering::testing::Render( - maker.Make3DRectilinearDataSet0(), "pointvar", colorTable, "rect3D.pnm"); - vtkm::rendering::testing::Render( - maker.Make3DExplicitDataSet4(), "pointvar", colorTable, "expl3D.pnm"); - vtkm::rendering::testing::Render( - maker.Make2DRectilinearDataSet0(), "pointvar", colorTable, "rect2D.pnm"); - vtkm::rendering::testing::Render( - maker.Make1DUniformDataSet0(), "pointvar", vtkm::rendering::Color::white, "uniform1D.pnm"); - vtkm::rendering::testing::Render( - 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( - 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( - 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( - 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); -} diff --git a/vtkm/rendering/testing/glfw/CMakeLists.txt b/vtkm/rendering/testing/glfw/CMakeLists.txt deleted file mode 100644 index 487d1b280..000000000 --- a/vtkm/rendering/testing/glfw/CMakeLists.txt +++ /dev/null @@ -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) - diff --git a/vtkm/rendering/testing/glfw/UnitTestMapperGLFW.cxx b/vtkm/rendering/testing/glfw/UnitTestMapperGLFW.cxx deleted file mode 100644 index 638e89b03..000000000 --- a/vtkm/rendering/testing/glfw/UnitTestMapperGLFW.cxx +++ /dev/null @@ -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 -#include -#include -#include -#include -#include -#include -#include -#include -#include -#include -#include -#include -#include - -// this needs to be included after the vtk-m headers so that we include -// the gl headers in the correct order -#include - -#include -#include - -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(tinyDS.GetField(0).GetNumberOfValues()); - std::vector 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(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(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( - 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(view3d0, "reg3D.pnm"); - else if (which == 1) - vtkm::rendering::testing::Render(view3d1, "rect3D.pnm"); - else if (which == 2) - vtkm::rendering::testing::Render(view3d2, "expl3D.pnm"); - else if (which == 3) - vtkm::rendering::testing::Render(view2d0, "rect2D.pnm"); - else if (which == 4) - vtkm::rendering::testing::Render( - 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); -} diff --git a/vtkm/rendering/testing/glut/CMakeLists.txt b/vtkm/rendering/testing/glut/CMakeLists.txt deleted file mode 100644 index 49563791a..000000000 --- a/vtkm/rendering/testing/glut/CMakeLists.txt +++ /dev/null @@ -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) - diff --git a/vtkm/rendering/testing/glut/UnitTestMapperGLUT.cxx b/vtkm/rendering/testing/glut/UnitTestMapperGLUT.cxx deleted file mode 100644 index 56ea94d44..000000000 --- a/vtkm/rendering/testing/glut/UnitTestMapperGLUT.cxx +++ /dev/null @@ -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 -#include - -#include -#if defined(__APPLE__) -#include -#else -#include -#endif - -#include -#include -#include -#include -#include -#include -#include -#include -#include - -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( - maker.Make3DRegularDataSet0(), "pointvar", colorTable, "reg3D.pnm"); - else if (which == 1) - vtkm::rendering::testing::Render( - maker.Make3DRectilinearDataSet0(), "pointvar", colorTable, "rect3D.pnm"); - else if (which == 2) - vtkm::rendering::testing::Render( - maker.Make3DExplicitDataSet4(), "pointvar", colorTable, "expl3D.pnm"); - else if (which == 3) - vtkm::rendering::testing::Render( - 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); -} diff --git a/vtkm/rendering/testing/osmesa/CMakeLists.txt b/vtkm/rendering/testing/osmesa/CMakeLists.txt deleted file mode 100644 index dc1f15479..000000000 --- a/vtkm/rendering/testing/osmesa/CMakeLists.txt +++ /dev/null @@ -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) - diff --git a/vtkm/rendering/testing/osmesa/UnitTestMapperOSMesa.cxx b/vtkm/rendering/testing/osmesa/UnitTestMapperOSMesa.cxx deleted file mode 100644 index 0b3da87aa..000000000 --- a/vtkm/rendering/testing/osmesa/UnitTestMapperOSMesa.cxx +++ /dev/null @@ -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 -#include -#include -#include -#include -#include -#include -#include -#include -#include -#include -#include - -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( - maker.Make3DRegularDataSet0(), "pointvar", colorTable, "reg3D.pnm"); - vtkm::rendering::testing::Render( - maker.Make3DRectilinearDataSet0(), "pointvar", colorTable, "rect3D.pnm"); - vtkm::rendering::testing::Render( - maker.Make3DExplicitDataSet4(), "pointvar", colorTable, "expl3D.pnm"); - vtkm::rendering::testing::Render( - maker.Make2DRectilinearDataSet0(), "pointvar", colorTable, "rect2D.pnm"); - vtkm::rendering::testing::Render( - maker.Make1DUniformDataSet0(), "pointvar", vtkm::rendering::Color(1, 1, 1, 1), "uniform1D.pnm"); - vtkm::rendering::testing::Render( - 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); -}