gl-zstencil.c 1.9 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566
  1. /******************************************************************************
  2. Copyright (C) 2013 by Hugh Bailey <[email protected]>
  3. This program is free software: you can redistribute it and/or modify
  4. it under the terms of the GNU General Public License as published by
  5. the Free Software Foundation, either version 3 of the License, or
  6. (at your option) any later version.
  7. This program is distributed in the hope that it will be useful,
  8. but WITHOUT ANY WARRANTY; without even the implied warranty of
  9. MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
  10. GNU General Public License for more details.
  11. You should have received a copy of the GNU General Public License
  12. along with this program. If not, see <http://www.gnu.org/licenses/>.
  13. ******************************************************************************/
  14. #include "gl-subsystem.h"
  15. static bool gl_init_zsbuffer(struct gs_zstencil_buffer *zs, uint32_t width,
  16. uint32_t height)
  17. {
  18. glGenRenderbuffers(1, &zs->buffer);
  19. if (!gl_success("glGenRenderbuffers"))
  20. return false;
  21. if (!gl_bind_renderbuffer(GL_RENDERBUFFER, zs->buffer))
  22. return false;
  23. glRenderbufferStorage(GL_RENDERBUFFER, zs->format, width, height);
  24. if (!gl_success("glRenderbufferStorage"))
  25. return false;
  26. gl_bind_renderbuffer(GL_RENDERBUFFER, 0);
  27. return true;
  28. }
  29. zstencil_t device_create_zstencil(device_t device, uint32_t width,
  30. uint32_t height, enum gs_zstencil_format format)
  31. {
  32. struct gs_zstencil_buffer *zs;
  33. zs = bmalloc(sizeof(struct gs_zstencil_buffer));
  34. memset(zs, 0, sizeof(struct gs_zstencil_buffer));
  35. zs->format = convert_zstencil_format(format);
  36. if (!gl_init_zsbuffer(zs, width, height)) {
  37. blog(LOG_ERROR, "device_create_zstencil (GL) failed");
  38. zstencil_destroy(zs);
  39. return NULL;
  40. }
  41. return zs;
  42. }
  43. void zstencil_destroy(zstencil_t zs)
  44. {
  45. if (zs) {
  46. if (zs->buffer) {
  47. glDeleteRenderbuffers(1, &zs->buffer);
  48. gl_success("glDeleteRenderbuffers");
  49. }
  50. bfree(zs);
  51. }
  52. }