vbo.d 1.9 KB

12345678910111213141516171819202122232425262728293031323334353637383940414243444546474849505152535455565758596061626364656667686970717273747576777879808182
  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 {
  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(VertexBufferObjectTarget target) {
  57. check!glBindBuffer(target, this._id);
  58. }
  59. ///
  60. static unbind(VertexBufferObjectTarget target = VertexBufferObjectTarget.Array) {
  61. check!glBindBuffer(target, 0);
  62. }
  63. public:
  64. ///
  65. @property bool isValid() const @safe nothrow {
  66. return (this._id > 0);
  67. }
  68. }