Branch data Line data Source code
1 : : #pragma once
2 : :
3 : : /*
4 : : MIT License
5 : :
6 : : Copyright (c) 2014-2024 Stephane Cuillerdier (aka aiekick)
7 : :
8 : : Permission is hereby granted, free of charge, to any person obtaining a copy
9 : : of this software and associated documentation files (the "Software"), to deal
10 : : in the Software without restriction, including without limitation the rights
11 : : to use, copy, modify, merge, publish, distribute, sublicense, and/or sell
12 : : copies of the Software, and to permit persons to whom the Software is
13 : : furnished to do so, subject to the following conditions:
14 : :
15 : : The above copyright notice and this permission notice shall be included in all
16 : : copies or substantial portions of the Software.
17 : :
18 : : THE SOFTWARE IS PROVIDED "AS IS", WITHOUT WARRANTY OF ANY KIND, EXPRESS OR
19 : : IMPLIED, INCLUDING BUT NOT LIMITED TO THE WARRANTIES OF MERCHANTABILITY,
20 : : FITNESS FOR A PARTICULAR PURPOSE AND NONINFRINGEMENT. IN NO EVENT SHALL THE
21 : : AUTHORS OR COPYRIGHT HOLDERS BE LIABLE FOR ANY CLAIM, DAMAGES OR OTHER
22 : : LIABILITY, WHETHER IN AN ACTION OF CONTRACT, TORT OR OTHERWISE, ARISING FROM,
23 : : OUT OF OR IN CONNECTION WITH THE SOFTWARE OR THE USE OR OTHER DEALINGS IN THE
24 : : SOFTWARE.
25 : : */
26 : :
27 : : // ezGL is part of the ezLibs project : https://github.com/aiekick/ezLibs.git
28 : :
29 : :
30 : : #include "mesh.hpp"
31 : : #include <vector>
32 : : #include <memory>
33 : :
34 : : namespace ez {
35 : : namespace gl {
36 : :
37 : : struct QuadDatas {
38 : : float p[2] = {};
39 : : float t[2] = {};
40 : 0 : QuadDatas(const float& px, const float& py, const float& tx, const float& ty) : p{px, py}, t{tx, ty} {};
41 : : };
42 : :
43 : : class QuadMesh;
44 : : typedef std::shared_ptr<QuadMesh> QuadMeshPtr;
45 : : typedef std::weak_ptr<QuadMesh> QuadMeshWeak;
46 : :
47 : : class QuadMesh : public Mesh<QuadDatas> {
48 : : public:
49 : 0 : static QuadMeshPtr create(float vZero = -1.0f) {
50 : 0 : auto res = std::make_shared<QuadMesh>();
51 : 0 : res->m_This = res;
52 : 0 :
53 : 0 : std::vector<QuadDatas> vertices = {
54 : 0 : QuadDatas(vZero, vZero, 0.0f, 0.0f),
55 : 0 : QuadDatas(1.0f, vZero, 1.0f, 0.0f),
56 : 0 : QuadDatas(1.0f, 1.0f, 1.0f, 1.0f),
57 : 0 : QuadDatas(vZero, 1.0f, 0.0f, 1.0f),
58 : 0 : };
59 : 0 :
60 : 0 : std::vector<uint32_t> indices = {0, 1, 2, 0, 2, 3};
61 : 0 :
62 : 0 : if (!res->init(vertices, {2, 2}, indices, {}, {}, 0, true)) {
63 : 0 : res.reset();
64 : 0 : }
65 : 0 : return res;
66 : 0 : }
67 : :
68 : : private:
69 : : QuadMeshWeak m_This;
70 : : };
71 : :
72 : : } // namespace gl
73 : : } // namespace ez
|