gl-helpers.c 2.5 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081
  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. bool gl_init_face(GLenum target, GLenum type, uint32_t num_levels,
  16. GLenum format, GLint internal_format, bool compressed,
  17. uint32_t width, uint32_t height, uint32_t size, void ***p_data)
  18. {
  19. bool success = true;
  20. void **data = *p_data;
  21. uint32_t i;
  22. for (i = 0; i < num_levels; i++) {
  23. if (compressed) {
  24. glCompressedTexImage2D(target, i, internal_format,
  25. width, height, 0, size,
  26. data ? *data : NULL);
  27. if (!gl_success("glCompressedTexImage2D"))
  28. success = false;
  29. } else {
  30. glTexImage2D(target, i, internal_format, width, height,
  31. 0, format, type, data ? *data : NULL);
  32. if (!gl_success("glTexImage2D"))
  33. success = false;
  34. }
  35. if (data)
  36. data++;
  37. size /= 4;
  38. width /= 2;
  39. height /= 2;
  40. if (width == 0) width = 1;
  41. if (height == 0) height = 1;
  42. }
  43. *p_data = data;
  44. return success;
  45. }
  46. bool gl_copy_texture(struct gs_device *device,
  47. GLuint src, GLenum src_target,
  48. GLuint dst, GLenum dst_target,
  49. uint32_t width, uint32_t height)
  50. {
  51. bool success = false;
  52. if (device->copy_type == COPY_TYPE_ARB) {
  53. glCopyImageSubData(src, src_target, 0, 0, 0, 0,
  54. dst, dst_target, 0, 0, 0, 0,
  55. width, height, 1);
  56. success = gl_success("glCopyImageSubData");
  57. } else if (device->copy_type == COPY_TYPE_NV) {
  58. glCopyImageSubDataNV(src, src_target, 0, 0, 0, 0,
  59. dst, dst_target, 0, 0, 0, 0,
  60. width, height, 1);
  61. success = gl_success("glCopyImageSubDataNV");
  62. } else if (device->copy_type == COPY_TYPE_FBO_BLIT) {
  63. /* TODO (implement FBOs) */
  64. }
  65. return success;
  66. }