KJB
 All Classes Namespaces Files Functions Variables Typedefs Enumerations Enumerator Friends Macros Groups Pages
gr_opengl_object.h
Go to the documentation of this file.
1 /* $Id: gr_opengl_object.h 18278 2014-11-25 01:42:10Z ksimek $ */
2 /* {{{=========================================================================== *
3  |
4  | Copyright (c) 1994-2010 by Kobus Barnard (author)
5  |
6  | Personal and educational use of this code is granted, provided that this
7  | header is kept intact, and that the authorship is not misrepresented, that
8  | its use is acknowledged in publications, and relevant papers are cited.
9  |
10  | For other use contact the author (kobus AT cs DOT arizona DOT edu).
11  |
12  | Please note that the code in this file has not necessarily been adequately
13  | tested. Naturally, there is no guarantee of performance, support, or fitness
14  | for any particular task. Nonetheless, I am interested in hearing about
15  | problems that you encounter.
16  |
17  | Author: Kyle Simek
18  * =========================================================================== }}}*/
19 
20 // vim: tabstop=4 shiftwidth=4 foldmethod=marker
21 
22 #ifndef KJB_GR_OPENGL_OBJECT
23 #define KJB_GR_OPENGL_OBJECT
24 
25 #ifdef KJB_HAVE_OPENGL
27 
28 #include <l_cpp/l_exception.h>
29 
31 
32 #ifdef DEBUGGING
33 #include <gr_cpp/gr_glut.h>
34 #endif
35 
36 #include <map>
37 
51 namespace kjb
52 {
53 namespace opengl
54 {
55 
65 #ifdef KJB_HAVE_GLEW
66 class Renderbuffer
67 {
68 public:
74  explicit Renderbuffer(GLuint renderbuffer_id);
75 
76  Renderbuffer();
77 
78  void allocate(GLenum internal_format, GLsizei width, GLsizei height);
79 
80  ~Renderbuffer();
81 
85  void bind() const;
86 
92  void unbind() const;
93 
94 
99  operator GLuint() const;
100 
101  GLuint get() const;
102 private:
103  // no copy
104  Renderbuffer(const Renderbuffer&){}
105  Renderbuffer& operator=(const Renderbuffer&){return *this;}
106 
107  GLuint handle_;
108 };
109 #endif /* HAVE_GLEW */
110 
124 #ifdef KJB_HAVE_GLEW
125 class Framebuffer_object
126 {
127 public:
128  Framebuffer_object();
129 
134  explicit Framebuffer_object(GLuint fbo_id);
135 
139  ~Framebuffer_object();
140 
141  void attach(const Renderbuffer& renderbuffer, GLenum target);
142 
143  void attach(const Texture& texture, GLenum target);
144 
145  void attach_color(const Renderbuffer& renderbuffer, int i = 0);
146 
147  void attach_depth(const Renderbuffer& renderbuffer);
148 
149  void attach_stencil(const Renderbuffer& renderbuffer);
150 
151 
152  void attach_color(const Texture& texture, int i = 0);
153 
154  void attach_depth(const Texture& texture);
155 
156  void attach_stencil(const Texture& texture);
157 
162  void check() const;
163 
167  void bind() const;
168 
174  void unbind() const;
175 
180  operator GLuint() const;
181 
182  GLuint get() const;
183 private:
184  GLuint handle_;
185 };
186 #endif /* KJB_HAVE_GLEW */
187 
196 #ifdef KJB_HAVE_GLEW
197 class Buffer
198 {
199  // copying not allowed, shared pointers are a possible alternative
200  Buffer(const Buffer& ) {}; // no copying; will cause double-free
201  Buffer& operator=(const Buffer& ) {return *this;}; // no copying; will cause double-free
202 public:
207  Buffer(GLuint buffer_id);
208 
209  Buffer();
210 
221  void allocate(GLenum type, int size, GLvoid* data, GLenum usage_hint);
222 
235  void allocate(GLenum type, int size, GLenum usage);
236 
237  void copy(size_t offset, size_t size, GLvoid* data);
238 
239  ~Buffer();
240 
241  void bind() const;
242 
250  void bind(GLenum type) const;
251 
252  void unbind() const;
253 
257  void unbind(GLenum type) const;
258 
263  operator GLuint() const;
264 
265  GLuint get() const;
266 public:
267  GLuint handle_;
268  GLenum type_;
269 };
270 
271 
272 void allocate_grayscale_color_buffer(::kjb::opengl::Renderbuffer& color, int width, int height);
273 
274 #endif /* HAVE_GLEW */
275 
276 
277 
278 } // namespace opengl
279 } // namespace kjb
280 
281 #endif /* HAVE_OPENGL */
282 #endif
int GLenum
Definition: gr_opengl_headers.h:65
height
Definition: APPgetLargeConnectedEdges.m:33
int GLuint
Definition: gr_opengl_headers.h:64
get the indices of edges in each direction for i
Definition: APPgetLargeConnectedEdges.m:48
Support for error handling exception classes in libKJB.