vbo.d 2.0 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687
  1. // Written in the D programming language.
  2. /**
  3. Copyright: Copyright Felix 'Zoadian' Hufnagel 2014-.
  4. License: $(WEB http://www.gnu.org/licenses/lgpl.html, LGPLv3).
  5. Authors: $(WEB zoadian.de, Felix 'Zoadian' Hufnagel)
  6. */
  7. module three.gl.vbo;
  8. import derelict.opengl3.gl3;
  9. import three.gl.util;
  10. //==============================================================================
  11. ///
  12. enum VertexBufferObjectTarget {
  13. Array = GL_ARRAY_BUFFER,
  14. AtomicCounter = GL_ATOMIC_COUNTER_BUFFER,
  15. CopyRead= GL_COPY_READ_BUFFER,
  16. CopyWrite = GL_COPY_WRITE_BUFFER,
  17. DrawIndirect = GL_DRAW_INDIRECT_BUFFER,
  18. DispatchIndirect = GL_DISPATCH_INDIRECT_BUFFER,
  19. ElementArray = GL_ELEMENT_ARRAY_BUFFER,
  20. PixelPack = GL_PIXEL_PACK_BUFFER,
  21. PixelUnpack = GL_PIXEL_UNPACK_BUFFER,
  22. ShaderStorage = GL_SHADER_STORAGE_BUFFER,
  23. Texture = GL_TEXTURE_BUFFER,
  24. TransformFeedback = GL_TRANSFORM_FEEDBACK_BUFFER,
  25. Uniform = GL_UNIFORM_BUFFER
  26. }
  27. //==============================================================================
  28. ///
  29. enum BufferUsageHint {
  30. StreamDraw = GL_STREAM_DRAW,
  31. StreamRead = GL_STREAM_READ,
  32. StreamCopy = GL_STREAM_COPY,
  33. StaticDraw = GL_STATIC_DRAW,
  34. StaticRead = GL_STATIC_READ,
  35. StaticCopy = GL_STATIC_COPY,
  36. DynamicDraw = GL_DYNAMIC_DRAW,
  37. DynamicRead = GL_DYNAMIC_READ,
  38. DynamicCopy = GL_DYNAMIC_COPY
  39. }
  40. //==============================================================================
  41. ///
  42. final class VertexBufferObject(VertexBufferObjectTarget target) {
  43. private:
  44. uint _id;
  45. public:
  46. ///
  47. this() {
  48. check!glGenBuffers(1, &this._id);
  49. }
  50. ///
  51. ~this() {
  52. check!glDeleteBuffers(1, &this._id);
  53. }
  54. public:
  55. ///
  56. void bind() {
  57. assert(this.isValid);
  58. check!glBindBuffer(target, this._id);
  59. }
  60. ///
  61. static unbind() {
  62. check!glBindBuffer(target, 0);
  63. }
  64. public:
  65. ///
  66. @property bool isValid() const @safe nothrow {
  67. return (this._id > 0);
  68. }
  69. }
  70. private void _isVertexBufferObject(T...)(VertexBufferObject!(T) t) {}
  71. enum isVertexBufferObject(T) = is(typeof(_isVertexBufferObject(T.init)));