1
1

vbo.d 2.1 KB

1234567891011121314151617181920212223242526272829303132333435363738394041424344454647484950515253545556575859606162636465666768697071727374757677787980818283848586878889
  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. import std.stdio;
  41. //==============================================================================
  42. ///
  43. final class VertexBufferObject(VertexBufferObjectTarget target) {
  44. private:
  45. uint _id;
  46. public:
  47. ///
  48. this() {
  49. check!glGenBuffers(1, &this._id);
  50. writeln("vbo created: ", this._id);
  51. }
  52. ///
  53. ~this() {
  54. check!glDeleteBuffers(1, &this._id);
  55. writeln("vbo destroyed: ", this._id);
  56. }
  57. public:
  58. ///
  59. void bind() {
  60. assert(this.isValid);
  61. check!glBindBuffer(target, this._id);
  62. }
  63. ///
  64. static unbind() {
  65. check!glBindBuffer(target, 0);
  66. }
  67. public:
  68. ///
  69. @property bool isValid() const @safe nothrow {
  70. return (this._id > 0);
  71. }
  72. }
  73. private void _isVertexBufferObject(T...)(VertexBufferObject!(T) t) {}
  74. enum isVertexBufferObject(T) = is(typeof(_isVertexBufferObject(T.init)));