/opengles/src/Buffer.h

http://ftk.googlecode.com/ · C Header · 107 lines · 53 code · 19 blank · 35 comment · 6 complexity · 92f0bb92d4a0ba32c0b470e75195a01f MD5 · raw file

  1. #ifndef EGL_BUFFER_H
  2. #define EGL_BUFFER_H 1
  3. // ==========================================================================
  4. //
  5. // Buffer.h Buffer Object Class for 3D Rendering Library
  6. //
  7. // --------------------------------------------------------------------------
  8. //
  9. // 08-30-2004 Hans-Martin Will initial version
  10. //
  11. // --------------------------------------------------------------------------
  12. //
  13. // Copyright (c) 2004, Hans-Martin Will. All rights reserved.
  14. //
  15. // Redistribution and use in source and binary forms, with or without
  16. // modification, are permitted provided that the following conditions are
  17. // met:
  18. //
  19. // * Redistributions of source code must retain the above copyright
  20. // notice, this list of conditions and the following disclaimer.
  21. // * Redistributions in binary form must reproduce the above copyright
  22. // notice, this list of conditions and the following disclaimer in the
  23. // documentation and/or other materials provided with the distribution.
  24. //
  25. // THIS SOFTWARE IS PROVIDED BY THE COPYRIGHT HOLDERS AND CONTRIBUTORS "AS IS"
  26. // AND ANY EXPRESS OR IMPLIED WARRANTIES, INCLUDING, BUT NOT LIMITED TO, THE
  27. // IMPLIED WARRANTIES OF MERCHANTABILITY AND FITNESS FOR A PARTICULAR PURPOSE
  28. // ARE DISCLAIMED. IN NO EVENT SHALL THE COPYRIGHT OWNER OR CONTRIBUTORS BE
  29. // LIABLE FOR ANY DIRECT, INDIRECT, INCIDENTAL, SPECIAL, EXEMPLARY,
  30. // OR CONSEQUENTIAL DAMAGES (INCLUDING, BUT NOT LIMITED TO, PROCUREMENT OF
  31. // SUBSTITUTE GOODS OR SERVICES; LOSS OF USE, DATA, OR PROFITS; OR BUSINESS
  32. // INTERRUPTION) HOWEVER CAUSED AND ON ANY THEORY OF LIABILITY, WHETHER IN
  33. // CONTRACT, STRICT LIABILITY, OR TORT (INCLUDING NEGLIGENCE OR OTHERWISE)
  34. // ARISING IN ANY WAY OUT OF THE USE OF THIS SOFTWARE, EVEN IF ADVISED OF
  35. // THE POSSIBILITY OF SUCH DAMAGE.
  36. //
  37. // ==========================================================================
  38. #include "OGLES.h"
  39. #include "GLES/gl.h"
  40. namespace EGL {
  41. enum BufferUsage {
  42. BufferUsageStaticDraw,
  43. BufferUsageDynamicDraw
  44. };
  45. class Buffer {
  46. public:
  47. Buffer(): m_Data(0), m_Size(0), m_Usage(BufferUsageStaticDraw) { }
  48. ~Buffer() {
  49. Deallocate();
  50. }
  51. bool Allocate(size_t size, BufferUsage usage) {
  52. Deallocate();
  53. if (size) {
  54. m_Data = malloc(size);
  55. if (m_Data == 0) {
  56. return false;
  57. } else {
  58. m_Size = size;
  59. m_Usage = usage;
  60. return true;
  61. }
  62. } else {
  63. return true;
  64. }
  65. }
  66. void Deallocate() {
  67. if (m_Data) {
  68. free(m_Data);
  69. m_Data = 0;
  70. m_Size = 0;
  71. }
  72. }
  73. void * GetData() const {
  74. return m_Data;
  75. }
  76. size_t GetSize() const {
  77. return m_Size;
  78. }
  79. BufferUsage GetUsage() const {
  80. return m_Usage;
  81. }
  82. private:
  83. void * m_Data;
  84. size_t m_Size;
  85. BufferUsage m_Usage;
  86. };
  87. }
  88. #endif //ndef EGL_BUFFER_H