Debian Codegraph @

src/Gui/GLBuffer.h

raw
1 /***************************************************************************
2 * Copyright (c) 2018 Werner Mayer <wmayer[at]users.sourceforge.net> *
3 * *
4 * This file is part of the FreeCAD CAx development system. *
5 * *
6 * This library is free software; you can redistribute it and/or *
7 * modify it under the terms of the GNU Library General Public *
8 * License as published by the Free Software Foundation; either *
9 * version 2 of the License, or (at your option) any later version. *
10 * *
11 * This library is distributed in the hope that it will be useful, *
12 * but WITHOUT ANY WARRANTY; without even the implied warranty of *
13 * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the *
14 * GNU Library General Public License for more details. *
15 * *
16 * You should have received a copy of the GNU Library General Public *
17 * License along with this library; see the file COPYING.LIB. If not, *
18 * write to the Free Software Foundation, Inc., 59 Temple Place, *
19 * Suite 330, Boston, MA 02111-1307, USA *
20 * *
21 ***************************************************************************/
22
23
24 #ifndef GUI_GLBUFFER_H
25 #define GUI_GLBUFFER_H
26
27 #include <FCGlobal.h>
28 #include <map>
29 #include <Inventor/C/glue/gl.h>
30
31 namespace Gui
32 {
33
34 class GuiExport OpenGLBuffer
35 {
36 public:
37 OpenGLBuffer(GLenum type);
38 ~OpenGLBuffer();
39
40 static bool isVBOSupported(uint32_t ctx);
41
42 void setCurrentContext(uint32_t ctx);
43 bool create();
44 bool isCreated() const;
45
46 void destroy();
47 void allocate(const void* data, int count);
48 bool bind();
49 void release();
50 GLuint getBufferId() const;
51 uint32_t getBoundContext() const;
52 int size() const;
53
54 private:
55 static void context_destruction_cb(uint32_t context, void* userdata);
56 static void buffer_delete(void* closure, uint32_t contextid);
57
58 GLenum target;
59 GLuint bufferId;
60 uint32_t context;
61 uint32_t currentContext;
62 const cc_glglue* glue;
63 };
64
65 class GuiExport OpenGLMultiBuffer
66 {
67 public:
68 OpenGLMultiBuffer(GLenum type);
69 ~OpenGLMultiBuffer();
70
71 void setCurrentContext(uint32_t ctx);
72 bool create();
73 bool isCreated(uint32_t ctx) const;
74
75 void destroy();
76 void allocate(const void* data, int count);
77 bool bind();
78 void release();
79 GLuint getBufferId() const;
80 int size() const;
81
82 private:
83 static void context_destruction_cb(uint32_t context, void* userdata);
84 static void buffer_delete(void* closure, uint32_t contextid);
85
86 GLenum target;
87 // map context to buffer id
88 std::map<uint32_t, GLuint> bufs;
89 GLuint* currentBuf;
90 uint32_t currentContext;
91 const cc_glglue* glue;
92 };
93
94 } // namespace Gui
95
96 #endif // GUI_GLBUFFER_H