VisuTwin Canvas
C++ 3D Engine — Metal Backend
Loading...
Searching...
No Matches
quadRender.cpp
Go to the documentation of this file.
1// SPDX-License-Identifier: Apache-2.0
2// Copyright 2025-2026 Arnis Lektauers
3//
4//
5#include "quadRender.h"
6
8
9namespace visutwin::canvas
10{
11 QuadRender::QuadRender(const std::shared_ptr<Shader>& shader)
12 : _shader(shader)
13 {
14 }
15
16 void QuadRender::render(const Vector4* viewport, const Vector4* scissor) const
17 {
18 if (!_shader) {
19 return;
20 }
21
22 auto* const rawDevice = _shader ? _shader->graphicsDevice() : nullptr;
23 if (!rawDevice) {
24 return;
25 }
26
27 const auto* const device = rawDevice;
28
29 float oldVx = 0.0f;
30 float oldVy = 0.0f;
31 float oldVw = 0.0f;
32 float oldVh = 0.0f;
33 int oldSx = 0;
34 int oldSy = 0;
35 int oldSw = 0;
36 int oldSh = 0;
37
38 if (viewport) {
39 oldVx = device->vx();
40 oldVy = device->vy();
41 oldVw = device->vw();
42 oldVh = device->vh();
43 oldSx = device->sx();
44 oldSy = device->sy();
45 oldSw = device->sw();
46 oldSh = device->sh();
47
48 const Vector4 effectiveScissor = scissor ? *scissor : *viewport;
49 rawDevice->setViewport(viewport->getX(), viewport->getY(), viewport->getZ(), viewport->getW());
50 rawDevice->setScissor(static_cast<int>(effectiveScissor.getX()), static_cast<int>(effectiveScissor.getY()),
51 static_cast<int>(effectiveScissor.getZ()), static_cast<int>(effectiveScissor.getW()));
52 }
53
54 rawDevice->setVertexBuffer(rawDevice->quadVertexBuffer());
55 rawDevice->setShader(_shader);
56 // DEVIATION: UBO / bind-group setup from upstream QuadRender is not implemented in this backend yet.
57 rawDevice->setQuadRenderActive(true);
58
59 Primitive quadPrimitive;
60 quadPrimitive.type = PRIMITIVE_TRISTRIP;
61 quadPrimitive.base = 0;
62 quadPrimitive.baseVertex = 0;
63 quadPrimitive.count = 4;
64 quadPrimitive.indexed = false;
65
66 rawDevice->draw(quadPrimitive, nullptr, 1, -1, true, true);
67 rawDevice->setQuadRenderActive(false);
68 rawDevice->clearQuadTextureBindings();
69
70 if (viewport) {
71 rawDevice->setViewport(oldVx, oldVy, oldVw, oldVh);
72 rawDevice->setScissor(oldSx, oldSy, oldSw, oldSh);
73 }
74 }
75}
void render(const Vector4 *viewport=nullptr, const Vector4 *scissor=nullptr) const
QuadRender(const std::shared_ptr< Shader > &shader)
@ PRIMITIVE_TRISTRIP
Definition mesh.h:24
Describes how vertex and index data should be interpreted for a draw call.
Definition mesh.h:33
PrimitiveType type
Definition mesh.h:34
4D vector for homogeneous coordinates, color values, and SIMD operations.
Definition vector4.h:20
float getX() const
Definition vector4.h:85
float getY() const
Definition vector4.h:98