OGLplus (0.52.0) a C++ wrapper for OpenGL

buffer.hpp
Go to the documentation of this file.
1 
12 #pragma once
13 #ifndef OGLPLUS_DSA_BUFFER_1309301821_HPP
14 #define OGLPLUS_DSA_BUFFER_1309301821_HPP
15 
16 #include <oglplus/buffer.hpp>
18 
19 namespace oglplus {
20 
21 #if OGLPLUS_DOCUMENTATION_ONLY || GL_VERSION_4_5 || GL_ARB_direct_state_access
22 
23 template <>
24 struct ObjGenTag<tag::DirectState, tag::Buffer>
25 {
26  typedef tag::Create Type;
27 };
28 
30 
33 template <>
34 class ObjectOps<tag::DirectState, tag::Buffer>
35  : public ObjZeroOps<tag::DirectState, tag::Buffer>
36 {
37 protected:
38  ObjectOps(void){ }
39 public:
40  GLint GetIntParam(GLenum query) const;
41 
43  struct Property
44  {
46  typedef BufferUsage Usage;
47 
50  };
51 
54 
56 
63  bool Mapped(void) const
64  {
65  return GetIntParam(GL_BUFFER_MAPPED) == GL_TRUE;
66  }
67 
69 
78  void Resize(
79  BufferSize size,
81  )
82  {
83  OGLPLUS_GLFUNC(NamedBufferData)(
84  _name,
85  size.Get(),
86  nullptr,
87  GLenum(usage)
88  );
89  OGLPLUS_CHECK(
90  NamedBufferData,
92  Object(*this).
93  EnumParam(usage)
94  );
95  }
96 
98 
105  void Data(
106  const BufferData& data,
108  ) const
109  {
110  OGLPLUS_GLFUNC(NamedBufferData)(
111  _name,
112  GLsizei(data.Size()),
113  data.Data(),
114  GLenum(usage)
115  );
116  OGLPLUS_CHECK(
117  NamedBufferData,
118  ObjectError,
119  Object(*this).
120  EnumParam(usage)
121  );
122  }
123 
125 
133  void RawData(
134  BufferSize size,
135  const GLvoid* data,
137  ) const
138  {
139  Data(BufferData(size, data), usage);
140  }
141 
143 
151  template <typename GLtype>
152  void Data(
153  GLsizei count,
154  const GLtype* data,
156  ) const
157  {
158  Data(BufferData(count, data), usage);
159  }
160 
162 
167  void SubData(
168  BufferSize offset,
169  const BufferData& data
170  ) const
171  {
172  OGLPLUS_GLFUNC(NamedBufferSubData)(
173  _name,
174  GLintptr(offset.Get()),
175  GLsizei(data.Size()),
176  data.Data()
177  );
178  OGLPLUS_CHECK(
179  NamedBufferSubData,
180  ObjectError,
181  Object(*this)
182  );
183  }
184 
186 
191  template <typename GLtype>
192  void SubData(
193  BufferSize offset,
194  GLsizei count,
195  GLtype* data
196  ) const
197  {
198  SubData(offset, BufferData(count, data));
199  }
200 
201 #if OGLPLUS_DOCUMENTATION_ONLY || GL_VERSION_3_1 || GL_ARB_copy_buffer
202 
210  static void CopySubData(
211  BufferName readbuffer,
212  BufferName writebuffer,
213  BufferSize readoffset,
214  BufferSize writeoffset,
215  BufferSize size
216  )
217  {
218  OGLPLUS_GLFUNC(CopyNamedBufferSubData)(
219  GetGLName(readbuffer),
220  GetGLName(writebuffer),
221  GLintptr(readoffset.Get()),
222  GLintptr(writeoffset.Get()),
223  GLsizeiptr(size.Get())
224  );
225  OGLPLUS_CHECK(
226  CopyNamedBufferSubData,
227  ObjectPairError,
228  Subject(readbuffer).
229  Object(writebuffer)
230  );
231  }
232 #endif // copy buffer
233 
235 
245  template <typename GLtype>
246  void ClearData(
247  PixelDataInternalFormat internal_format,
248  PixelDataFormat format,
249  const GLtype* data
250  ) const
251  {
252  OGLPLUS_GLFUNC(ClearNamedBufferData)(
253  _name,
254  GLenum(internal_format),
255  GLenum(format),
256  GLenum(GetDataType<GLtype>()),
257  data
258  );
259  OGLPLUS_CHECK(
260  ClearNamedBufferData,
261  ObjectError,
262  Object(*this).
263  EnumParam(internal_format)
264  );
265  }
266 
268 
278  template <typename GLtype>
280  PixelDataInternalFormat internal_format,
281  BufferSize offset,
282  BufferSize size,
283  PixelDataFormat format,
284  const GLtype* data
285  ) const
286  {
287  OGLPLUS_GLFUNC(ClearNamedBufferSubData)(
288  _name,
289  GLenum(internal_format),
290  GLintptr(offset.Get()),
291  GLsizeiptr(size.Get()),
292  GLenum(format),
293  GLenum(GetDataType<GLtype>()),
294  data
295  );
296  OGLPLUS_CHECK(
297  ClearNamedBufferSubData,
298  ObjectError,
299  Object(*this).
300  EnumParam(internal_format)
301  );
302  }
303 
304  void Storage(
305  const BufferData& data,
307  ) const
308  {
309  OGLPLUS_GLFUNC(NamedBufferStorage)(
310  _name,
311  GLsizeiptr(data.Size()),
312  data.Data(),
313  GLbitfield(flags)
314  );
315  OGLPLUS_CHECK(
316  NamedBufferStorage,
317  ObjectError,
318  Object(*this)
319  );
320  }
321 
322  void Storage(
323  BufferSize size,
324  const void* data,
325  Bitfield<BufferStorageBit> flags
326  ) const
327  {
328  Storage(BufferData(size, data), flags);
329  }
330 
332 
339  GLsizei Size(void) const
340  {
341  return GLsizei(GetIntParam(GL_BUFFER_SIZE));
342  }
343 
345 
354  BufferUsage Usage(void) const
355  {
356  return BufferUsage(GetIntParam(GL_BUFFER_USAGE));
357  }
358 
360 
370  {
372  GLbitfield(GetIntParam(GL_BUFFER_ACCESS))
373  );
374  }
375 
376 #if OGLPLUS_DOCUMENTATION_ONLY || GL_NV_shader_buffer_load
377 
385  void MakeResident(AccessSpecifier access) const
386  {
387  OGLPLUS_GLFUNC(MakeNamedBufferResidentNV)(
388  _name,
389  GLenum(access)
390  );
391  OGLPLUS_CHECK(
392  MakeNamedBufferResidentNV,
393  ObjectError,
394  Object(*this).
395  EnumParam(access)
396  );
397  }
398 
400 
407  void MakeNonResident(void) const
408  {
409  OGLPLUS_GLFUNC(MakeNamedBufferNonResidentNV)(_name);
410  OGLPLUS_CHECK(
411  MakeNamedBufferNonResidentNV,
412  ObjectError,
413  Object(*this)
414  );
415  }
416 
418 
426  BufferGPUAddress GPUAddress(void) const
427  {
428  GLuint64EXT value = 0;
429  OGLPLUS_GLFUNC(GetNamedBufferParameterui64vNV)(
430  _name,
431  GL_BUFFER_GPU_ADDRESS_NV,
432  &value
433  );
434  OGLPLUS_CHECK(
435  GetNamedBufferParameterui64vNV,
436  ObjectError,
437  Object(*this)
438  );
439  return BufferGPUAddress(value);
440  }
441 #endif
442 };
443 
445 typedef ObjectOps<tag::DirectState, tag::Buffer>
447 
448 // Helper class for syntax sugar operators
449 struct DSABufferOpsAndUsage
450 {
451  DSABufferOps& buf;
452  BufferUsage usage;
453 
454  DSABufferOpsAndUsage(DSABufferOps& b, BufferUsage u)
455  : buf(b)
456  , usage(u)
457  { }
458 };
459 
460 inline DSABufferOpsAndUsage operator << (
461  DSABufferOps& buf,
462  BufferUsage usage
463 )
464 {
465  return DSABufferOpsAndUsage(buf, usage);
466 }
467 
468 // Helper class for syntax sugar operators
469 struct DSABufferOpsAndIdxTgt
470 {
471  DSABufferOps& buf;
472  BufferIndexedTarget target;
473 
474  DSABufferOpsAndIdxTgt(DSABufferOps& b, BufferIndexedTarget t)
475  : buf(b)
476  , target(t)
477  { }
478 };
479 
480 inline DSABufferOpsAndIdxTgt operator << (
481  DSABufferOps& buf,
482  BufferIndexedTarget target
483 )
484 {
485  return DSABufferOpsAndIdxTgt(buf, target);
486 }
487 
488 // Helper class for syntax sugar operators
489 struct DSABufferOpsAndOffset
490 {
491  DSABufferOps& buf;
492  GLintptr offset;
493 
494  DSABufferOpsAndOffset(DSABufferOps& b, GLintptr o)
495  : buf(b)
496  , offset(o)
497  { }
498 };
499 
500 inline DSABufferOpsAndOffset operator + (
501  DSABufferOps& buf,
502  GLintptr offset
503 )
504 {
505  return DSABufferOpsAndOffset(buf, offset);
506 }
507 
508 // syntax-sugar operators
509 
510 // Bind
511 inline DSABufferOps& operator << (
512  DSABufferOps& buf,
513  BufferTarget target
514 )
515 {
516  buf.Bind(target);
517  return buf;
518 }
519 
520 // BindBase
521 inline DSABufferOps& operator << (
522  const DSABufferOpsAndIdxTgt& bat,
523  GLuint index
524 )
525 {
526  bat.buf.BindBase(bat.target, index);
527  return bat.buf;
528 }
529 
530 // Data
531 template <typename GLtype>
532 inline DSABufferOps& operator << (
533  DSABufferOps& buf,
534  const std::vector<GLtype>& data
535 )
536 {
537  buf.Data(data);
538  return buf;
539 }
540 
541 // Data
542 template <typename GLtype>
543 inline DSABufferOps& operator << (
544  DSABufferOpsAndUsage&& bau,
545  const std::vector<GLtype>& data
546 )
547 {
548  bau.buf.Data(data, bau.usage);
549  return bau.buf;
550 }
551 
552 // Data
553 template <typename GLtype, std::size_t Count>
554 inline DSABufferOps& operator << (
555  DSABufferOps& buf,
556  const GLtype (&data)[Count]
557 )
558 {
559  buf.Data(data);
560  return buf;
561 }
562 
563 // Data
564 template <typename GLtype, std::size_t Count>
565 inline DSABufferOps& operator << (
566  DSABufferOpsAndUsage&& bau,
567  const GLtype (&data)[Count]
568 )
569 {
570  bau.buf.Data(data, bau.usage);
571  return bau.buf;
572 }
573 
574 // SubData
575 template <typename GLtype>
576 inline DSABufferOps& operator << (
577  DSABufferOpsAndOffset&& bao,
578  const std::vector<GLtype>& data
579 )
580 {
581  bao.buf.SubData(bao.offset, data);
582  return bao.buf;
583 }
584 
585 // SubData
586 template <typename GLtype, std::size_t Count>
587 inline DSABufferOps& operator << (
588  DSABufferOpsAndOffset&& bao,
589  const GLtype (&data)[Count]
590 )
591 {
592  bao.buf.SubData(bao.offset, data);
593  return bao.buf;
594 }
595 
597 
600 typedef Object<DSABufferOps> DSABuffer;
601 
602 #endif // GL_ARB_direct_state_access
603 
604 } // namespace oglplus
605 
606 #if !OGLPLUS_LINK_LIBRARY || defined(OGLPLUS_IMPLEMENTING_LIBRARY)
607 #include <oglplus/dsa/buffer.ipp>
608 #endif // OGLPLUS_LINK_LIBRARY
609 
610 #endif // include guard
void Data(GLsizei count, const GLtype *data, BufferUsage usage=BufferUsage::StaticDraw) const
Uploads (sets) the buffer data.
Definition: buffer.hpp:152
void MakeNonResident(void) const
Makes this buffer inaccessible to GLSL shaders.
Definition: buffer.hpp:407
void RawData(BufferSize size, const GLvoid *data, BufferUsage usage=BufferUsage::StaticDraw) const
Uploads (sets) the buffer data.
Definition: buffer.hpp:133
void ClearData(PixelDataInternalFormat internal_format, PixelDataFormat format, const GLtype *data) const
Clear the buffer data.
Definition: buffer.hpp:246
Untyped mapping of the buffer to the client address space.
Definition: buffer_map.hpp:219
PixelDataInternalFormat
OpenGL pixel data internal format enumeration.
Definition: pixel_data.hpp:79
void SubData(BufferSize offset, const BufferData &data) const
Uploads (sets) a subrange of the buffer data.
Definition: buffer.hpp:167
This class represents the size of a GPU buffer in bytes.
Definition: buffer_size.hpp:22
BufferUsage
Buffer usage enumeration.
Definition: buffer_usage.hpp:24
BufferMap wrappers with direct state access.
This template serves as a wrapper for OpenGL bitfields.
Definition: bitfield.hpp:56
Implements operations applicable to named (non-zero) objects.
Definition: wrap_tpl.hpp:45
GLuint GetGLName(ObjectName< ObjTag > named)
Returns the GLuint OpenGL name assigned to named object.
Definition: name.hpp:38
void Resize(BufferSize size, BufferUsage usage=BufferUsage::StaticDraw)
Allocates buffer storage to the specified size without any data.
Definition: buffer.hpp:78
AccessSpecifier
Enumeration of access type specifiers.
Definition: access_specifier.hpp:27
BufferUsage Usage
The Buffer usage mode.
Definition: buffer.hpp:46
void Data(const BufferData &data, BufferUsage usage=BufferUsage::StaticDraw) const
Uploads (sets) the buffer data.
Definition: buffer.hpp:105
BufferGPUAddress GPUAddress(void) const
Returns the GPU address of this buffer.
Definition: buffer.hpp:426
PixelDataFormat
OpenGL pixel data format enumeration.
Definition: pixel_data.hpp:50
BufferUsage Usage(void) const
Returns the buffer usage.
Definition: buffer.hpp:354
void ClearSubData(PixelDataInternalFormat internal_format, BufferSize offset, BufferSize size, PixelDataFormat format, const GLtype *data) const
Clear a subrange of the buffer data.
Definition: buffer.hpp:279
Bitfield< BufferMapAccess > Access(void) const
Returns the buffer usage.
Definition: buffer.hpp:369
Implements operations applicable to any object including object 0 (zero)
Definition: fwd.hpp:157
GLsizeiptr Get(void) const
Gets the size in bytes.
Definition: buffer_size.hpp:58
BufferMapAccess
Buffer map access enumeration.
Definition: buffer_map_access.hpp:25
void MakeResident(AccessSpecifier access) const
Makes this buffer accessible to GLSL shaders.
Definition: buffer.hpp:385
static void CopySubData(BufferName readbuffer, BufferName writebuffer, BufferSize readoffset, BufferSize writeoffset, BufferSize size)
Copy data between buffers.
Definition: buffer.hpp:210
Class used for passing the size of and pointer to data to be put in a Buffer.
Definition: buffer_data.hpp:21
BufferIndexedTarget
Buffer indexed bind target.
Definition: buffer_target.hpp:46
DSABufferTypedMap< GLubyte > Map
Mapping of the buffer to the client address space.
Definition: buffer.hpp:53
Exception class for GL object-related errors.
Definition: object.hpp:24
GLsizei Size(void) const
Returns the buffer size.
Definition: buffer.hpp:339
void SubData(BufferSize offset, GLsizei count, GLtype *data) const
Uploads (sets) a subrange of the buffer data.
Definition: buffer.hpp:192
Buffer wrappers.
Object< DSABufferOps > DSABuffer
An oglplus_object encapsulating the OpenGL buffer functionality.
Definition: buffer.hpp:600
bool Mapped(void) const
Returns true if the buffer is mapped.
Definition: buffer.hpp:63
BufferMapAccess MapAccess
The buffer map access mode.
Definition: buffer.hpp:49
void Bind(Target target) const
Binds this buffer to the specified target.
Definition: buffer.hpp:294
A common template for "named" objects like textures, buffers, etc.
Definition: fwd.hpp:136
Class wrapping buffer-related functionality with direct state access.
Definition: buffer.hpp:34
BufferTarget
Buffer bind target.
Definition: buffer_target.hpp:24
ObjectOps< tag::DirectState, tag::Buffer > DSABufferOps
Buffer operations with direct state access.
Definition: buffer.hpp:446

Copyright © 2010-2014 Matúš Chochlík, University of Žilina, Žilina, Slovakia.
<matus.chochlik -at- fri.uniza.sk>
<chochlik -at -gmail.com>
Documentation generated on Mon Sep 22 2014 by Doxygen (version 1.8.6).