Вы не можете выбрать более 25 тем Темы должны начинаться с буквы или цифры, могут содержать дефисы(-) и должны содержать не более 35 символов.

101 строка
1.8 KiB

  1. //
  2. // Lol Engine
  3. //
  4. // Copyright: (c) 2010-2011 Sam Hocevar <sam@hocevar.net>
  5. // This program is free software; you can redistribute it and/or
  6. // modify it under the terms of the Do What The Fuck You Want To
  7. // Public License, Version 2, as published by Sam Hocevar. See
  8. // http://sam.zoy.org/projects/COPYING.WTFPL for more details.
  9. //
  10. #if defined HAVE_CONFIG_H
  11. # include "config.h"
  12. #endif
  13. #include "core.h"
  14. #include "lolgl.h"
  15. #include "gpu/vbo.h"
  16. using namespace std;
  17. namespace lol
  18. {
  19. /*
  20. * GpuVbo implementation class
  21. */
  22. class GpuVboData
  23. {
  24. friend class GpuVbo;
  25. size_t elemsize, elemcount;
  26. uint8_t *alloc_buffer;
  27. static size_t const GPU_ALIGN = 128;
  28. };
  29. /*
  30. * Public GpuVbo class
  31. */
  32. GpuVbo::GpuVbo()
  33. : data(new GpuVboData())
  34. {
  35. data->elemsize = 0;
  36. data->elemcount = 0;
  37. data->alloc_buffer = 0;
  38. }
  39. void GpuVbo::SetSize(size_t elemsize, size_t elemcount)
  40. {
  41. size_t oldsize = data->elemsize * data->elemcount;
  42. size_t newsize = elemsize * elemcount;
  43. if (newsize == oldsize)
  44. return;
  45. if (oldsize)
  46. delete[] data->alloc_buffer;
  47. data->alloc_buffer = NULL;
  48. if (newsize)
  49. data->alloc_buffer = new uint8_t[newsize + GpuVboData::GPU_ALIGN - 1];
  50. data->elemsize = elemsize;
  51. data->elemcount = elemcount;
  52. }
  53. size_t GpuVbo::GetSize()
  54. {
  55. return data->elemsize * data->elemcount;
  56. }
  57. uint8_t *GpuVbo::GetData()
  58. {
  59. return (uint8_t *)(((uintptr_t)data->alloc_buffer)
  60. & ~((uintptr_t)GpuVboData::GPU_ALIGN - 1));
  61. }
  62. uint8_t const *GpuVbo::GetData() const
  63. {
  64. return (uint8_t const *)(((uintptr_t)data->alloc_buffer)
  65. & ~((uintptr_t)GpuVboData::GPU_ALIGN - 1));
  66. }
  67. void GpuVbo::Bind()
  68. {
  69. }
  70. void GpuVbo::Unbind()
  71. {
  72. }
  73. GpuVbo::~GpuVbo()
  74. {
  75. delete[] data->alloc_buffer;
  76. delete data;
  77. }
  78. } /* namespace lol */