mirror of
https://github.com/thorvg/thorvg.git
synced 2025-06-20 15:03:25 +00:00

[issues 1479: pictures](https://github.com/thorvg/thorvg/issues/1479) auto picture = tvg::Picture::gen(); picture->load("images/test.png"); picture->translate(0, 0); picture->size(100, 100); picture->opacity(255); canvas->push(std::move(picture));
97 lines
3.9 KiB
C++
97 lines
3.9 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_RENDER_DATA_H_
|
|
#define _TVG_WG_RENDER_DATA_H_
|
|
|
|
#include "tvgWgPipelineSolid.h"
|
|
#include "tvgWgPipelineLinear.h"
|
|
#include "tvgWgPipelineRadial.h"
|
|
#include "tvgWgPipelineImage.h"
|
|
#include "tvgWgGeometry.h"
|
|
|
|
class WgGeometryData {
|
|
public:
|
|
WGPUBuffer mBufferVertex{};
|
|
WGPUBuffer mBufferTexCoords{};
|
|
WGPUBuffer mBufferIndex{};
|
|
size_t mVertexCount{};
|
|
size_t mIndexCount{};
|
|
public:
|
|
WgGeometryData() {}
|
|
virtual ~WgGeometryData() { release(); }
|
|
|
|
void initialize(WGPUDevice device) {};
|
|
void draw(WGPURenderPassEncoder renderPassEncoder);
|
|
void drawImage(WGPURenderPassEncoder renderPassEncoder);
|
|
void update(WGPUDevice device, WGPUQueue queue, WgVertexList* vertexList);
|
|
void update(WGPUDevice device, WGPUQueue queue, float* vertexData, size_t vertexCount, uint32_t* indexData, size_t indexCount);
|
|
void update(WGPUDevice device, WGPUQueue queue, float* vertexData, float* texCoordsData, size_t vertexCount, uint32_t* indexData, size_t indexCount);
|
|
void release();
|
|
};
|
|
|
|
class WgRenderData {
|
|
public:
|
|
virtual void initialize(WGPUDevice device) {};
|
|
virtual void release() = 0;
|
|
};
|
|
|
|
struct WgRenderDataShapeSettings {
|
|
WgPipelineBindGroupSolid mPipelineBindGroupSolid{};
|
|
WgPipelineBindGroupLinear mPipelineBindGroupLinear{};
|
|
WgPipelineBindGroupRadial mPipelineBindGroupRadial{};
|
|
|
|
WgPipelineBase* mPipelineBase{}; // external
|
|
WgPipelineBindGroup* mPipelineBindGroup{}; // external
|
|
|
|
// update render shape settings defined by flags and fill settings
|
|
void update(WGPUQueue queue, const Fill* fill, const RenderUpdateFlag flags,
|
|
const RenderTransform* transform, const float* viewMatrix, const uint8_t* color,
|
|
WgPipelineLinear& linear, WgPipelineRadial& radial, WgPipelineSolid& solid);
|
|
void release();
|
|
};
|
|
|
|
class WgRenderDataShape: public WgRenderData {
|
|
public:
|
|
Array<WgGeometryData*> mGeometryDataShape;
|
|
Array<WgGeometryData*> mGeometryDataStroke;
|
|
Array<WgGeometryData*> mGeometryDataImage;
|
|
|
|
WgRenderDataShapeSettings mRenderSettingsShape;
|
|
WgRenderDataShapeSettings mRenderSettingsStroke;
|
|
WgPipelineBindGroupImage mPipelineBindGroupImage;
|
|
public:
|
|
WgRenderDataShape() {}
|
|
|
|
void release() override;
|
|
void releaseRenderData();
|
|
|
|
void tesselate(WGPUDevice device, WGPUQueue queue, Surface* surface, const RenderMesh* mesh);
|
|
void tesselate(WGPUDevice device, WGPUQueue queue, const RenderShape& rshape);
|
|
void stroke(WGPUDevice device, WGPUQueue queue, const RenderShape& rshape);
|
|
private:
|
|
void decodePath(const RenderShape& rshape, Array<WgVertexList*>& outlines);
|
|
void strokeSegments(const RenderShape& rshape, Array<WgVertexList*>& outlines, Array<WgVertexList*>& segments);
|
|
void strokeSublines(const RenderShape& rshape, Array<WgVertexList*>& outlines, WgVertexList& strokes);
|
|
};
|
|
|
|
#endif //_TVG_WG_RENDER_DATA_H_
|