gl-helpers.c 1.6 KB

1234567891011121314151617181920212223242526272829303132333435363738394041424344454647484950515253
  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 upload_face(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(type, i, internal_format,
  25. width, height, 0, size, *data);
  26. if (!gl_success("glCompressedTexImage2D"))
  27. success = false;
  28. } else {
  29. glTexImage2D(type, i, internal_format, width, height, 0,
  30. format, GL_UNSIGNED_BYTE, *data);
  31. if (!gl_success("glTexImage2D"))
  32. success = false;
  33. }
  34. data++;
  35. size /= 4;
  36. width /= 2;
  37. height /= 2;
  38. if (width == 0) width = 1;
  39. if (height == 0) height = 1;
  40. }
  41. *p_data = data;
  42. return success;
  43. }