mirror of
https://github.com/thorvg/thorvg.git
synced 2025-06-14 12:04:29 +00:00

[issues 1479: Shape](https://github.com/thorvg/thorvg/issues/1479) In order to build you need third party libraries. Before you start please read this: [LearnWebGPU](https://eliemichel.github.io/LearnWebGPU/getting-started/hello-webgpu.html) Usage example: // init glfw glfwInit(); // create a windowed mode window and its opengl context glfwWindowHint(GLFW_CLIENT_API, GLFW_NO_API); GLFWwindow* window = glfwCreateWindow(800, 800, "WebGPU base app", nullptr, nullptr); // get window size int width{}, height{}; glfwGetWindowSize(window, &width, &height); // init engine webgpu tvg::Initializer::init(tvg::CanvasEngine::Wg, 0); // create wg canvas auto canvasWg = tvg::WgCanvas::gen(); canvas_wg->target(glfwGetWin32Window(window), width, height); //Test for Stroke Dash for Arc, Circle, Rect auto shape = tvg::Shape::gen(); shape->appendArc(70, 600, 160, 10, 30, true); shape->appendCircle(70, 700, 20, 60); shape->appendRect(130, 710, 100, 40); shape->strokeFill(255, 0, 0); shape->strokeWidth(5); shape->strokeJoin(tvg::StrokeJoin::Round); shape->strokeCap(tvg::StrokeCap::Round); if (canvas_wg->push(std::move(shape)) != tvg::Result::Success) return; while (!glfwWindowShouldClose(window)) { // webgpu canvas_wg->draw(); canvas_wg->sync(); // pull events glfwPollEvents(); } // terminate engine and window tvg::Initializer::term(tvg::CanvasEngine::Wg); glfwDestroyWindow(window); glfwTerminate();
91 lines
3.6 KiB
C++
91 lines
3.6 KiB
C++
/*
|
|
* Copyright (c) 2023 the ThorVG project. All rights reserved.
|
|
|
|
* Permission is hereby granted, free of charge, to any person obtaining a copy
|
|
* of this software and associated documentation files (the "Software"), to deal
|
|
* in the Software without restriction, including without limitation the rights
|
|
* to use, copy, modify, merge, publish, distribute, sublicense, and/or sell
|
|
* copies of the Software, and to permit persons to whom the Software is
|
|
* furnished to do so, subject to the following conditions:
|
|
|
|
* The above copyright notice and this permission notice shall be included in all
|
|
* copies or substantial portions of the Software.
|
|
|
|
* THE SOFTWARE IS PROVIDED "AS IS", WITHOUT WARRANTY OF ANY KIND, EXPRESS OR
|
|
* IMPLIED, INCLUDING BUT NOT LIMITED TO THE WARRANTIES OF MERCHANTABILITY,
|
|
* FITNESS FOR A PARTICULAR PURPOSE AND NONINFRINGEMENT. IN NO EVENT SHALL THE
|
|
* AUTHORS OR COPYRIGHT HOLDERS BE LIABLE FOR ANY CLAIM, DAMAGES OR OTHER
|
|
* LIABILITY, WHETHER IN AN ACTION OF CONTRACT, TORT OR OTHERWISE, ARISING FROM,
|
|
* OUT OF OR IN CONNECTION WITH THE SOFTWARE OR THE USE OR OTHER DEALINGS IN THE
|
|
* SOFTWARE.
|
|
*/
|
|
|
|
#ifndef _TVG_WG_RENDERER_H_
|
|
#define _TVG_WG_RENDERER_H_
|
|
|
|
#include "tvgWgPipelineEmpty.h"
|
|
#include "tvgWgPipelineStroke.h"
|
|
#include "tvgWgRenderData.h"
|
|
|
|
class WgRenderer : public RenderMethod
|
|
{
|
|
private:
|
|
WgRenderer();
|
|
~WgRenderer();
|
|
private:
|
|
void initialize();
|
|
void release();
|
|
public:
|
|
RenderData prepare(const RenderShape& rshape, RenderData data, const RenderTransform* transform, Array<RenderData>& clips, uint8_t opacity, RenderUpdateFlag flags, bool clipper);
|
|
RenderData prepare(const Array<RenderData>& scene, RenderData data, const RenderTransform* transform, Array<RenderData>& clips, uint8_t opacity, RenderUpdateFlag flags);
|
|
RenderData prepare(Surface* surface, const RenderMesh* mesh, RenderData data, const RenderTransform* transform, Array<RenderData>& clips, uint8_t opacity, RenderUpdateFlag flags);
|
|
bool preRender();
|
|
bool renderShape(RenderData data);
|
|
bool renderImage(RenderData data);
|
|
bool postRender();
|
|
bool dispose(RenderData data);
|
|
RenderRegion region(RenderData data);
|
|
RenderRegion viewport();
|
|
bool viewport(const RenderRegion& vp);
|
|
bool blend(BlendMethod method);
|
|
ColorSpace colorSpace();
|
|
|
|
bool clear();
|
|
bool sync();
|
|
|
|
bool target(uint32_t* buffer, uint32_t stride, uint32_t w, uint32_t h);
|
|
bool target(void* window, uint32_t w, uint32_t h); // temporary solution
|
|
Compositor* target(const RenderRegion& region, ColorSpace cs);
|
|
bool beginComposite(Compositor* cmp, CompositeMethod method, uint8_t opacity);
|
|
bool endComposite(Compositor* cmp);
|
|
public:
|
|
static WgRenderer* gen();
|
|
static bool init(uint32_t threads);
|
|
static bool term();
|
|
private:
|
|
Array<RenderData> mRenderDatas{};
|
|
private:
|
|
Surface mTargetSurface = { nullptr, 0, 0, 0, ColorSpace::Unsupported, true };
|
|
float mViewMatrix[16]{};
|
|
// basic webgpu instances (TODO: create separated entity)
|
|
WGPUInstance mInstance{};
|
|
WGPUAdapter mAdapter{};
|
|
WGPUDevice mDevice{};
|
|
WGPUQueue mQueue{};
|
|
// webgpu surface handles (TODO: create separated entity)
|
|
WGPUSurface mSurface{};
|
|
WGPUSwapChain mSwapChain{};
|
|
WGPUTexture mStencilTex{};
|
|
WGPUTextureView mStencilTexView{};
|
|
private:
|
|
WgPipelineEmpty mPipelineEmpty;
|
|
WgPipelineStroke mPipelineStroke;
|
|
WgPipelineSolid mPipelineSolid;
|
|
WgPipelineLinear mPipelineLinear;
|
|
WgPipelineRadial mPipelineRadial;
|
|
WgGeometryData mGeometryDataWindow;
|
|
WgPipelineBindGroupEmpty mPipelineBindGroupEmpty;
|
|
WgPipelineBindGroupStroke mPipelineBindGroupStroke;
|
|
};
|
|
|
|
#endif /* _TVG_WG_RENDERER_H_ */
|