VTK  9.7.20261114
vtkWebGPUContextDevice2D.h
Go to the documentation of this file.
1// SPDX-FileCopyrightText: Copyright (c) Ken Martin, Will Schroeder, Bill Lorensen
2// SPDX-License-Identifier: BSD-3-Clause
3
12
13#ifndef vtkWebGPUContextDevice2D_h
14#define vtkWebGPUContextDevice2D_h
15
16#include "vtkContextDevice2D.h"
17#include "vtkRenderingWebGPUModule.h" // for export macro
18#include "vtk_wgpu.h" // for webgpu type
19#include <cstdint> // For std::uintptr_t
20
21VTK_ABI_NAMESPACE_BEGIN
22
23class vtkImageData;
24class vtkMatrix3x3;
25class vtkMatrix4x4;
26class vtkPolyData;
27class vtkTransform;
30class vtkRenderer;
31
32class VTKRENDERINGWEBGPU_EXPORT vtkWebGPUContextDevice2D : public vtkContextDevice2D
33{
34public:
36 void PrintSelf(ostream& os, vtkIndent indent) override;
37
42
47 void Begin(vtkViewport* viewport) override;
48
52 void End() override;
53
57 void Flush();
58
60
66
68
71 void BufferIdModeBegin(vtkAbstractContextBufferId* /*bufferId*/) override { /*noop*/ }
72 void BufferIdModeEnd() override { /*noop*/ }
73 void ReleaseCache(std::uintptr_t /*cacheIdentifier*/) override { /*noop*/ }
75
81 void DrawPoly(float* points, int n, unsigned char* colors = nullptr, int nc_comps = 0) override;
82
89 void DrawLines(float* points, int n, unsigned char* colors = nullptr, int nc_comps = 0) override;
90
96 void DrawPoints(float* points, int n, unsigned char* colors = nullptr, int nc_comps = 0) override;
98 vtkDataArray* positions, vtkUnsignedCharArray* colors, std::uintptr_t cacheIdentifier) override;
99
106 void DrawPointSprites(vtkImageData* sprite, float* points, int n, unsigned char* colors = nullptr,
107 int nc_comps = 0) override;
109 std::uintptr_t cacheIdentifier) override;
110
119 void DrawMarkers(int shape, bool highlight, float* points, int n, unsigned char* colors = nullptr,
120 int nc_comps = 0) override;
121 void DrawMarkers(int shape, bool highlight, vtkDataArray* positions, vtkUnsignedCharArray* colors,
122 std::uintptr_t cacheIdentifier) override;
123
127 void DrawQuad(float* points, int n) override;
128
132 void DrawQuadStrip(float* points, int n) override;
133
137 void DrawPolygon(float* points, int n) override;
138
143 float* points, int numPoints, unsigned char* colors = nullptr, int nc_comps = 0) override;
144
148 void DrawEllipseWedge(float x, float y, float outRx, float outRy, float inRx, float inRy,
149 float startAngle, float stopAngle) override;
150
155 float x, float y, float rX, float rY, float startAngle, float stopAngle) override;
156
160 void DrawString(float* point, const vtkStdString& string) override;
161
165 void ComputeStringBounds(const vtkStdString& string, float bounds[4]) override;
166
170 void ComputeJustifiedStringBounds(const char* string, float bounds[4]) override;
171
175 void DrawMathTextString(float point[2], const vtkStdString& string) override;
176
180 void DrawImage(float p[2], float scale, vtkImageData* image) override;
181
185 void DrawImage(const vtkRectf& pos, vtkImageData* image) override;
186
190 void DrawPolyData(float p[2], float scale, vtkPolyData* polyData, vtkUnsignedCharArray* colors,
191 int scalarMode) override;
192
196 void SetColor4(unsigned char color[4]) override;
197
201 virtual void SetColor(unsigned char color[3]);
202
206 void SetTexture(vtkImageData* image, int properties = 0) override;
207
211 void SetPointSize(float size) override;
212
216 void SetLineWidth(float width) override;
217
221 void SetLineType(int type) override;
222
229 void SetClipping(int* x) override;
230
237 void EnableClipping(bool enable) override;
238
242 void MultiplyMatrix(vtkMatrix3x3* m) override;
243
247 void SetMatrix(vtkMatrix3x3* m) override;
248
252 void GetMatrix(vtkMatrix3x3* m) override;
253
257 void PushMatrix() override;
258
262 void PopMatrix() override;
263
269 virtual void ReleaseGraphicsResources(vtkWindow* /*window*/);
270
271protected:
274
277
278 class Private;
280
283
284 bool InRender = false;
285
286private:
288 void operator=(const vtkWebGPUContextDevice2D&) = delete;
289
290 void UpdateCameraUniforms();
291 void UpdatePaintUniforms(const unsigned char color[4]);
292
296 WGPURenderPipeline CreatePipelineWithConstants(float haveTCoordsVal = 0.0f,
297 float haveLinesVal = 0.0f, WGPUPrimitiveTopology topology = WGPUPrimitiveTopology_TriangleList);
298
302 vtkImageData* GenerateMarker(int shape, int width, bool highlight);
303
308 void ApplyScissorRect(WGPURenderPassEncoder passEncoder);
309
311
316 void DrawThickLines(
317 float* points, int n, unsigned char* colors, int nc, const std::vector<float>& distances);
318
322 void DrawThinLines(
323 float* points, int n, unsigned char* colors, int nc, const std::vector<float>& distances);
325};
326
327VTK_ABI_NAMESPACE_END
328
329#endif // vtkWebGPUContextDevice2D_h
2D array of ids, used for picking.
topologically and geometrically regular array of data
a simple class to control print indentation
Definition vtkIndent.h:108
represent and manipulate 3x3 transformation matrices
represent and manipulate 4x4 transformation matrices
concrete dataset represents vertices, lines, polygons, and triangle strips
abstract specification for renderers
Wrapper around std::string to keep symbols short.
describes linear transformations via a 4x4 matrix
dynamic, self-adjusting array of unsigned char
abstract specification for Viewports
Definition vtkViewport.h:66
Container for vtkWebGPUContextDevice2D internal state.
void PushMatrix() override
Push the current matrix onto the stack.
void End() override
Ends the 2D rendering pass and cleans up temporary render state.
void SetMatrix(vtkMatrix3x3 *m) override
Set the model view matrix for the display.
void InitializeTexture()
Initialize Device Resources: Uniforms, BindGroups, Pipelines, and Textures.
vtkWebGPURenderWindow * RenderWindow
virtual void SetColor(unsigned char color[3])
Set the color for the device using unsigned char of length 3, RGB.
void DrawMarkers(int shape, bool highlight, vtkDataArray *positions, vtkUnsignedCharArray *colors, std::uintptr_t cacheIdentifier) override
void DrawPointSprites(vtkImageData *sprite, float *points, int n, unsigned char *colors=nullptr, int nc_comps=0) override
Draw a series of point sprites, images centred at the points supplied.
void DrawImage(const vtkRectf &pos, vtkImageData *image) override
Render an image data object within a specified 2D rectangle.
void DrawMarkers(int shape, bool highlight, float *points, int n, unsigned char *colors=nullptr, int nc_comps=0) override
Draw markers of a specified shape at multiple 2D positions.
static vtkWebGPUContextDevice2D * New()
Creates a 2D Painter object.
void DrawEllipticArc(float x, float y, float rX, float rY, float startAngle, float stopAngle) override
Draw an open elliptical arc line segment.
void SetLineType(int type) override
Set the line type type (using anonymous enum in vtkPen).
void DrawQuad(float *points, int n) override
Draw a quad using the 4 specified points.
void SetTexture(vtkImageData *image, int properties=0) override
Set the texture for the device, it is used to fill the polygons.
void ReleaseCache(std::uintptr_t) override
Noop method.
void DrawPoints(float *points, int n, unsigned char *colors=nullptr, int nc_comps=0) override
Draw a series of points - fastest code path due to memory layout of the coordinates.
virtual void ReleaseGraphicsResources(vtkWindow *)
Release any graphics resources that are being consumed by this device.
void ComputeStringBounds(const vtkStdString &string, float bounds[4]) override
Compute the bounding box dimensions for a given text string.
bool InitializeDeviceResources()
Initialize Device Resources: Uniforms, BindGroups, Pipelines, and Textures.
void DrawPoints(vtkDataArray *positions, vtkUnsignedCharArray *colors, std::uintptr_t cacheIdentifier) override
void BufferIdModeEnd() override
Noop method.
void ComputeJustifiedStringBounds(const char *string, float bounds[4]) override
Compute justified bounding box dimensions for a C-style string.
void DrawEllipseWedge(float x, float y, float outRx, float outRy, float inRx, float inRy, float startAngle, float stopAngle) override
Draw an elliptical wedge (pie slice) defined by radii and angles.
void DrawPointSprites(vtkImageData *sprite, vtkDataArray *positions, vtkUnsignedCharArray *colors, std::uintptr_t cacheIdentifier) override
void DrawColoredPolygon(float *points, int numPoints, unsigned char *colors=nullptr, int nc_comps=0) override
Draw a filled polygon with optional per-vertex or per-polygon colors.
void DrawPolyData(float p[2], float scale, vtkPolyData *polyData, vtkUnsignedCharArray *colors, int scalarMode) override
Render a vtkPolyData geometry mesh (lines and polygons) with offset and scale.
void PopMatrix() override
Pop the current matrix off of the stack.
void SetLineWidth(float width) override
Set the line width for glyphs/sprites.
void DrawPolygon(float *points, int n) override
Draw a filled convex polygon defined by points.
void Begin(vtkViewport *viewport) override
Begins the 2D rendering pass for the given viewport.
void DrawMathTextString(float point[2], const vtkStdString &string) override
Render a math equation string (MathText format) at the given point.
void DrawString(float *point, const vtkStdString &string) override
Render a text string at the specified world coordinate point.
void SetColor4(unsigned char color[4]) override
Set the color for the device using unsigned char of length 4, RGBA.
void DrawQuadStrip(float *points, int n) override
Draw a quad strip using a sequence of points.
void MultiplyMatrix(vtkMatrix3x3 *m) override
Multiply the current model view matrix by the supplied one.
void PrintSelf(ostream &os, vtkIndent indent) override
Methods invoked by print to print information about the object including superclasses.
~vtkWebGPUContextDevice2D() override
void EnableClipping(bool enable) override
Enable or disable clipping.
void GetMatrix(vtkMatrix3x3 *m) override
Set the model view matrix for the display.
void BufferIdModeBegin(vtkAbstractContextBufferId *) override
Noop method.
void SetClipping(int *x) override
Set the clipping rectangle for the 2D context.
void SetPointSize(float size) override
Set the point size for glyphs/sprites.
void DrawLines(float *points, int n, unsigned char *colors=nullptr, int nc_comps=0) override
Draw lines using the points - memory layout is as follows: l1p1,l1p2,l2p1,l2p2... The lines will be c...
void DrawPoly(float *points, int n, unsigned char *colors=nullptr, int nc_comps=0) override
Draw a poly line using the points - fastest code path due to memory layout of the coordinates.
void DrawImage(float p[2], float scale, vtkImageData *image) override
Render an image data object scaled and positioned at a given point.
void Flush()
Flushes the internal batched vertex buffer to the WebGPU rendering pipeline.
WebGPU rendering window.
window superclass for vtkRenderWindow
Definition vtkWindow.h:62
#define vtkDataArray