Update code to follow styling and worklet invoker guidelines

This commit is contained in:
Manish Mathai 2021-10-19 10:32:10 -07:00
parent b7470b0afc
commit f7c43960e5
3 changed files with 28 additions and 130 deletions

@ -487,7 +487,7 @@ void Canvas::AddText(const vtkm::Matrix<vtkm::Float32, 4, 4>& transform,
}
vtkm::rendering::Canvas* self = const_cast<vtkm::rendering::Canvas*>(this);
TextRenderer fontRenderer(
vtkm::rendering::TextRenderer fontRenderer(
self, Internals->Font, Internals->FontTexture, this->Internals->TextBatcher.get());
fontRenderer.RenderText(transform, scale, anchor, color, text, depth);
}

@ -10,7 +10,6 @@
#include <vtkm/rendering/LineRendererBatcher.h>
#include <vtkm/worklet/DispatcherMapField.h>
#include <vtkm/worklet/WorkletMapField.h>
namespace vtkm
@ -125,47 +124,6 @@ struct RenderLine : public vtkm::worklet::WorkletMapField
vtkm::Id Width;
vtkm::Id Height;
}; // struct RenderLine
struct RenderLineExecutor
{
using ColorBufferType = vtkm::rendering::Canvas::ColorBufferType;
using DepthBufferType = vtkm::rendering::Canvas::DepthBufferType;
VTKM_CONT
RenderLineExecutor(const PointsArrayHandle& starts,
const PointsArrayHandle& ends,
const ColorsArrayHandle& colors,
vtkm::Id width,
vtkm::Id height,
const ColorBufferType& colorBuffer,
const DepthBufferType& depthBuffer)
: Starts(starts)
, Ends(ends)
, Colors(colors)
, Worklet(width, height)
, ColorBuffer(colorBuffer)
, DepthBuffer(depthBuffer)
{
}
template <typename Device>
VTKM_CONT bool operator()(Device) const
{
VTKM_IS_DEVICE_ADAPTER_TAG(Device);
vtkm::worklet::DispatcherMapField<RenderLine> dispatcher(Worklet);
dispatcher.SetDevice(Device());
dispatcher.Invoke(Starts, Ends, Colors, ColorBuffer, DepthBuffer);
return true;
}
PointsArrayHandle Starts;
PointsArrayHandle Ends;
ColorsArrayHandle Colors;
RenderLine Worklet;
ColorBufferType ColorBuffer;
DepthBufferType DepthBuffer;
}; // struct RenderLineExecutor
} // namespace
LineRendererBatcher::LineRendererBatcher() {}
@ -194,17 +152,17 @@ void LineRendererBatcher::BatchLine(const vtkm::Vec3f_32& start,
void LineRendererBatcher::Render(const vtkm::rendering::Canvas* canvas) const
{
PointsArrayHandle starts = vtkm::cont::make_ArrayHandle(this->Starts);
PointsArrayHandle ends = vtkm::cont::make_ArrayHandle(this->Ends);
ColorsArrayHandle colors = vtkm::cont::make_ArrayHandle(this->Colors);
PointsArrayHandle starts = vtkm::cont::make_ArrayHandle(this->Starts, vtkm::CopyFlag::Off);
PointsArrayHandle ends = vtkm::cont::make_ArrayHandle(this->Ends, vtkm::CopyFlag::Off);
ColorsArrayHandle colors = vtkm::cont::make_ArrayHandle(this->Colors, vtkm::CopyFlag::Off);
vtkm::cont::TryExecute(RenderLineExecutor(starts,
vtkm::cont::Invoker invoker;
invoker(RenderLine(canvas->GetWidth(), canvas->GetHeight()),
starts,
ends,
colors,
canvas->GetWidth(),
canvas->GetHeight(),
canvas->GetColorBuffer(),
canvas->GetDepthBuffer()));
canvas->GetDepthBuffer());
}
}
} // namespace vtkm::rendering

@ -10,10 +10,6 @@
#include <vtkm/rendering/TextRendererBatcher.h>
#include <vtkm/Transform3D.h>
#include <vtkm/cont/Timer.h>
#include <vtkm/cont/TryExecute.h>
#include <vtkm/worklet/DispatcherMapField.h>
#include <vtkm/worklet/WorkletMapField.h>
namespace vtkm
@ -120,68 +116,8 @@ struct RenderBitmapFont : public vtkm::worklet::WorkletMapField
vtkm::Id Width;
vtkm::Id Height;
}; // struct RenderBitmapFont
struct RenderBitmapFontExecutor
{
using ColorBufferType = vtkm::rendering::Canvas::ColorBufferType;
using DepthBufferType = vtkm::rendering::Canvas::DepthBufferType;
using FontTextureType = vtkm::rendering::TextRendererBatcher::FontTextureType;
using ScreenCoordsArrayHandle = vtkm::rendering::TextRendererBatcher::ScreenCoordsArrayHandle;
using TextureCoordsArrayHandle = vtkm::rendering::TextRendererBatcher::TextureCoordsArrayHandle;
using ColorsArrayHandle = vtkm::rendering::TextRendererBatcher::ColorsArrayHandle;
using DepthsArrayHandle = vtkm::rendering::TextRendererBatcher::DepthsArrayHandle;
VTKM_CONT
RenderBitmapFontExecutor(const ScreenCoordsArrayHandle& screenCoords,
const TextureCoordsArrayHandle& textureCoords,
const FontTextureType& fontTexture,
const ColorsArrayHandle& colors,
const ColorBufferType& colorBuffer,
const DepthBufferType& depthBuffer,
vtkm::Id width,
vtkm::Id height,
const DepthsArrayHandle& depths)
: ScreenCoords(screenCoords)
, TextureCoords(textureCoords)
, FontTexture(fontTexture)
, Colors(colors)
, ColorBuffer(colorBuffer)
, DepthBuffer(depthBuffer)
, Worklet(width, height)
, Depths(depths)
{
}
template <typename Device>
VTKM_CONT bool operator()(Device) const
{
VTKM_IS_DEVICE_ADAPTER_TAG(Device);
vtkm::worklet::DispatcherMapField<RenderBitmapFont> dispatcher(Worklet);
dispatcher.SetDevice(Device());
dispatcher.Invoke(ScreenCoords,
TextureCoords,
Colors,
Depths,
FontTexture.GetExecObjectFactory(),
ColorBuffer,
DepthBuffer);
return true;
}
ScreenCoordsArrayHandle ScreenCoords;
TextureCoordsArrayHandle TextureCoords;
FontTextureType FontTexture;
ColorsArrayHandle Colors;
ColorBufferType ColorBuffer;
DepthBufferType DepthBuffer;
RenderBitmapFont Worklet;
DepthsArrayHandle Depths;
}; // struct RenderBitmapFontExecutor
} // namespace
// TextRendererBatcher::TextRendererBatcher() {}
TextRendererBatcher::TextRendererBatcher(
const vtkm::rendering::Canvas::FontTextureType& fontTexture)
: FontTexture(fontTexture)
@ -207,20 +143,24 @@ void TextRendererBatcher::BatchText(const ScreenCoordsArrayHandle& screenCoords,
void TextRendererBatcher::Render(const vtkm::rendering::Canvas* canvas) const
{
ScreenCoordsArrayHandle screenCoords = vtkm::cont::make_ArrayHandle(this->ScreenCoords);
TextureCoordsArrayHandle textureCoords = vtkm::cont::make_ArrayHandle(this->TextureCoords);
vtkm::cont::ArrayHandle<ColorType> colors = vtkm::cont::make_ArrayHandle(this->Colors);
vtkm::cont::ArrayHandle<vtkm::Float32> depths = vtkm::cont::make_ArrayHandle(this->Depths);
ScreenCoordsArrayHandle screenCoords =
vtkm::cont::make_ArrayHandle(this->ScreenCoords, vtkm::CopyFlag::Off);
TextureCoordsArrayHandle textureCoords =
vtkm::cont::make_ArrayHandle(this->TextureCoords, vtkm::CopyFlag::Off);
vtkm::cont::ArrayHandle<ColorType> colors =
vtkm::cont::make_ArrayHandle(this->Colors, vtkm::CopyFlag::Off);
vtkm::cont::ArrayHandle<vtkm::Float32> depths =
vtkm::cont::make_ArrayHandle(this->Depths, vtkm::CopyFlag::Off);
vtkm::cont::TryExecute(RenderBitmapFontExecutor(screenCoords,
vtkm::cont::Invoker invoker;
invoker(RenderBitmapFont(canvas->GetWidth(), canvas->GetHeight()),
screenCoords,
textureCoords,
this->FontTexture,
colors,
depths,
this->FontTexture.GetExecObjectFactory(),
canvas->GetColorBuffer(),
canvas->GetDepthBuffer(),
canvas->GetWidth(),
canvas->GetHeight(),
depths));
canvas->GetDepthBuffer());
}
}
} // namespace vtkm::rendering