1 /*
2  * Copyright (C) 2020 Linux Studio Plugins Project <https://lsp-plug.in/>
3  *           (C) 2020 Vladimir Sadovnikov <sadko4u@gmail.com>
4  *
5  * This file is part of lsp-plugins
6  * Created on: 14 мая 2019 г.
7  *
8  * lsp-plugins is free software: you can redistribute it and/or modify
9  * it under the terms of the GNU Lesser General Public License as published by
10  * the Free Software Foundation, either version 3 of the License, or
11  * any later version.
12  *
13  * lsp-plugins is distributed in the hope that it will be useful,
14  * but WITHOUT ANY WARRANTY; without even the implied warranty of
15  * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE.  See the
16  * GNU Lesser General Public License for more details.
17  *
18  * You should have received a copy of the GNU Lesser General Public License
19  * along with lsp-plugins. If not, see <https://www.gnu.org/licenses/>.
20  */
21 
22 #ifndef UI_TK_WIDGETS_3D_LSPMESH3D_H_
23 #define UI_TK_WIDGETS_3D_LSPMESH3D_H_
24 
25 namespace lsp
26 {
27     namespace tk
28     {
29         class LSPMesh3D: public LSPObject3D
30         {
31             public:
32                 static const w_class_t    metadata;
33 
34                 enum layer_type_t
35                 {
36                     LT_TRIANGLES,
37                     LT_LINES
38                 };
39 
40                 typedef struct mesh_layer_t
41                 {
42                     layer_type_t    type;
43                     point3d_t      *mesh;           // Original data
44                     vector3d_t     *normals;        // Normal data
45                     point3d_t      *vbuffer;        // Vertex Buffer for rendering
46                     vector3d_t     *nbuffer;        // Normal Buffer for rendering
47                     size_t          primitives;     // Number of primitives
48                     size_t          draw;           // Number of primitives to draw
49                     bool            rebuild;        // Rebuild flag
50                     void           *pdata;          // Allocation pointer
51                 } mesh_layer_t;
52 
53             protected:
54                 LSPColor        sColor;
55                 LSPColor        sLineColor;
56                 matrix3d_t      sMatrix;
57 
58                 point3d_t       sPov;
59 
60                 cstorage<mesh_layer_t> vLayers;
61 
62             protected:
63                 void        do_destroy();
64                 void        rebuild_triangles(mesh_layer_t *layer);
65                 void        rebuild_lines(mesh_layer_t *layer);
66                 void        mark_for_rebuild();
67 
68                 static status_t slot_draw3d(LSPWidget *sender, void *ptr, void *data);
69 
70             public:
71                 explicit LSPMesh3D(LSPDisplay *dpy);
72                 virtual ~LSPMesh3D();
73 
74                 virtual status_t        init();
75                 virtual void            destroy();
76 
77             public:
color()78                 inline LSPColor            *color()                     { return &sColor;           };
line_color()79                 inline LSPColor            *line_color()                { return &sLineColor;       };
80 
81                 void                        get_position(point3d_t *dst);
get_view_point(point3d_t * dst)82                 inline void                 get_view_point(point3d_t *dst) { *dst = sPov;           };
83 
84             public:
85                 void clear();
86 
87                 status_t add_triangles(const point3d_t *mesh, const point3d_t *normals, size_t items);
add_triangles(const point3d_t * mesh,size_t items)88                 inline status_t add_triangles(const point3d_t *mesh, size_t items) { return add_triangles(mesh, NULL, items); }
89                 status_t add_lines(const point3d_t *mesh, size_t items);
90 
91                 void set_transform(const matrix3d_t *matrix);
92 
93             public:
94                 virtual void render(IR3DBackend *r3d);
95 
96                 virtual void set_view_point(const point3d_t *pov);
97 
98                 virtual status_t on_draw3d(IR3DBackend *r3d);
99         };
100 
101     } /* namespace tk */
102 } /* namespace lsp */
103 
104 #endif /* UI_TK_WIDGETS_3D_LSPMESH3D_H_ */
105