gl-subsystem.h 4.3 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118119120121122123124125126127128129130131132133134135136137138
  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. #ifndef GL_SUBSYSTEM_H
  15. #define GL_SUBSYSTEM_H
  16. #include "graphics/graphics.h"
  17. #include "glew/include/GL/glew.h"
  18. #include "gl-helpers.h"
  19. #include "gl-exports.h"
  20. struct gl_platform;
  21. struct gl_windowinfo;
  22. static inline GLint convert_gs_format(enum gs_color_format format)
  23. {
  24. switch (format) {
  25. case GS_A8: return GL_RGBA;
  26. case GS_R8: return GL_RED;
  27. case GS_RGBA: return GL_RGBA;
  28. case GS_BGRX: return GL_BGR;
  29. case GS_BGRA: return GL_BGRA;
  30. case GS_R10G10B10A2: return GL_RGBA;
  31. case GS_RGBA16: return GL_RGBA;
  32. case GS_R16: return GL_RED;
  33. case GS_RGBA16F: return GL_RGBA;
  34. case GS_RGBA32F: return GL_RGBA;
  35. case GS_RG16F: return GL_RG;
  36. case GS_RG32F: return GL_RG;
  37. case GS_R16F: return GL_RED;
  38. case GS_R32F: return GL_RED;
  39. case GS_DXT1: return GL_RGB;
  40. case GS_DXT3: return GL_RGBA;
  41. case GS_DXT5: return GL_RGBA;
  42. default: return 0;
  43. }
  44. }
  45. static inline GLint convert_gs_internal_format(enum gs_color_format format)
  46. {
  47. switch (format) {
  48. case GS_A8: return GL_R8; /* NOTE: use GL_TEXTURE_SWIZZLE_x */
  49. case GS_R8: return GL_R8;
  50. case GS_RGBA: return GL_RGBA;
  51. case GS_BGRX: return GL_RGBA;
  52. case GS_BGRA: return GL_RGBA;
  53. case GS_R10G10B10A2: return GL_RGB10_A2;
  54. case GS_RGBA16: return GL_RGBA16;
  55. case GS_R16: return GL_R16;
  56. case GS_RGBA16F: return GL_RGBA16F;
  57. case GS_RGBA32F: return GL_RGBA32F;
  58. case GS_RG16F: return GL_RG16F;
  59. case GS_RG32F: return GL_RG32F;
  60. case GS_R16F: return GL_R16F;
  61. case GS_R32F: return GL_R32F;
  62. case GS_DXT1: return GL_COMPRESSED_RGBA_S3TC_DXT1_EXT;
  63. case GS_DXT3: return GL_COMPRESSED_RGBA_S3TC_DXT3_EXT;
  64. case GS_DXT5: return GL_COMPRESSED_RGBA_S3TC_DXT5_EXT;
  65. default: return 0;
  66. }
  67. }
  68. static inline GLint convert_zstencil_format(enum gs_zstencil_format format)
  69. {
  70. switch (format) {
  71. case GS_Z16: return GL_DEPTH_COMPONENT16;
  72. case GS_Z24_S8: return GL_DEPTH24_STENCIL8;
  73. case GS_Z32F: return GL_DEPTH_COMPONENT32F;
  74. case GS_Z32F_S8X24: return GL_DEPTH32F_STENCIL8;
  75. default: return 0;
  76. }
  77. }
  78. struct gs_texture {
  79. device_t device;
  80. enum gs_texture_type type;
  81. enum gs_color_format format;
  82. GLenum gl_format;
  83. GLint gl_internal_format;
  84. GLuint texture;
  85. uint32_t levels;
  86. bool is_dynamic;
  87. bool is_render_target;
  88. bool gen_mipmaps;
  89. };
  90. struct gs_texture_2d {
  91. struct gs_texture base;
  92. uint32_t width;
  93. uint32_t height;
  94. bool gen_mipmaps;
  95. GLuint unpack_buffer;
  96. };
  97. struct gs_texture_cube {
  98. struct gs_texture base;
  99. uint32_t size;
  100. };
  101. struct gs_swap_chain {
  102. device_t device;
  103. struct gl_windowinfo *wi;
  104. struct gs_init_data info;
  105. };
  106. struct gs_device {
  107. struct gl_platform *plat;
  108. struct gs_swap_chain *cur_swap;
  109. int cur_render_side;
  110. struct gs_texture *cur_render_texture;
  111. };
  112. extern struct gl_platform *gl_platform_create(device_t device,
  113. struct gs_init_data *info);
  114. extern struct gs_swap_chain *gl_platform_getswap(struct gl_platform *platform);
  115. extern void gl_platform_destroy(struct gl_platform *platform);
  116. extern struct gl_windowinfo *gl_windowinfo_create(struct gs_init_data *info);
  117. extern void gl_windowinfo_destroy(struct gl_windowinfo *wi);
  118. #endif