You can not select more than 25 topics Topics must start with a letter or number, can include dashes ('-') and can be up to 35 characters long.
 
 
 

109 lines
2.1 KiB

  1. //
  2. // Lol Engine
  3. //
  4. // Copyright © 2010—2017 Sam Hocevar <sam@hocevar.net>
  5. //
  6. // Lol Engine is free software. It comes without any warranty, to
  7. // the extent permitted by applicable law. You can redistribute it
  8. // and/or modify it under the terms of the Do What the Fuck You Want
  9. // to Public License, Version 2, as published by the WTFPL Task Force.
  10. // See http://www.wtfpl.net/ for more details.
  11. //
  12. #include <lol/engine-internal.h>
  13. // FIXME: fine-tune this define
  14. #if defined LOL_USE_GLEW || defined HAVE_GL_2X || defined HAVE_GLES_2X
  15. #include "lolgl.h"
  16. namespace lol
  17. {
  18. //
  19. // The IndexBufferData class
  20. // -------------------------
  21. //
  22. class IndexBufferData
  23. {
  24. friend class IndexBuffer;
  25. size_t m_size;
  26. GLuint m_ibo;
  27. uint8_t *m_memory;
  28. };
  29. //
  30. // The IndexBuffer class
  31. // ----------------------
  32. //
  33. IndexBuffer::IndexBuffer(size_t size)
  34. : m_data(new IndexBufferData)
  35. {
  36. m_data->m_size = size;
  37. if (!size)
  38. return;
  39. glGenBuffers(1, &m_data->m_ibo);
  40. m_data->m_memory = new uint8_t[size];
  41. }
  42. IndexBuffer::~IndexBuffer()
  43. {
  44. if (m_data->m_size)
  45. {
  46. glDeleteBuffers(1, &m_data->m_ibo);
  47. delete[] m_data->m_memory;
  48. }
  49. delete m_data;
  50. }
  51. size_t IndexBuffer::GetSize()
  52. {
  53. return m_data->m_size;
  54. }
  55. void *IndexBuffer::Lock(size_t offset, size_t size)
  56. {
  57. if (!m_data->m_size)
  58. return nullptr;
  59. UNUSED(size);
  60. return m_data->m_memory + offset;
  61. }
  62. void IndexBuffer::Unlock()
  63. {
  64. if (!m_data->m_size)
  65. return;
  66. glBindBuffer(GL_ELEMENT_ARRAY_BUFFER, m_data->m_ibo);
  67. glBufferData(GL_ELEMENT_ARRAY_BUFFER, m_data->m_size, m_data->m_memory,
  68. GL_STATIC_DRAW);
  69. }
  70. void IndexBuffer::Bind()
  71. {
  72. if (!m_data->m_size)
  73. return;
  74. glBindBuffer(GL_ELEMENT_ARRAY_BUFFER, m_data->m_ibo);
  75. /* XXX: not necessary because we kept track of the size */
  76. //int size;
  77. //glGetBufferParameteriv(GL_ELEMENT_ARRAY_BUFFER, GL_BUFFER_SIZE, &size);
  78. }
  79. void IndexBuffer::Unbind()
  80. {
  81. if (!m_data->m_size)
  82. return;
  83. glBindBuffer(GL_ELEMENT_ARRAY_BUFFER, 0);
  84. }
  85. } /* namespace lol */
  86. #endif