GPU_element.h 2.7 KB

1234567891011121314151617181920212223242526272829303132333435363738394041424344454647484950515253545556575859606162636465666768697071727374757677787980818283848586878889909192
  1. /*
  2. * This program is free software; you can redistribute it and/or
  3. * modify it under the terms of the GNU General Public License
  4. * as published by the Free Software Foundation; either version 2
  5. * of the License, or (at your option) any later version.
  6. *
  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. *
  12. * You should have received a copy of the GNU General Public License
  13. * along with this program; if not, write to the Free Software Foundation,
  14. * Inc., 51 Franklin Street, Fifth Floor, Boston, MA 02110-1301, USA.
  15. *
  16. * The Original Code is Copyright (C) 2016 by Mike Erwin.
  17. * All rights reserved.
  18. */
  19. /** \file
  20. * \ingroup gpu
  21. *
  22. * GPU element list (AKA index buffer)
  23. */
  24. #ifndef __GPU_ELEMENT_H__
  25. #define __GPU_ELEMENT_H__
  26. #include "GPU_primitive.h"
  27. #define GPU_TRACK_INDEX_RANGE 1
  28. typedef enum {
  29. GPU_INDEX_U16,
  30. GPU_INDEX_U32,
  31. } GPUIndexBufType;
  32. typedef struct GPUIndexBuf {
  33. uint index_len;
  34. #if GPU_TRACK_INDEX_RANGE
  35. GPUIndexBufType index_type;
  36. uint32_t gl_index_type;
  37. uint base_index;
  38. #endif
  39. uint32_t ibo_id; /* 0 indicates not yet sent to VRAM */
  40. void *data; /* non-NULL indicates not yet sent to VRAM */
  41. } GPUIndexBuf;
  42. void GPU_indexbuf_use(GPUIndexBuf *);
  43. uint GPU_indexbuf_size_get(const GPUIndexBuf *);
  44. typedef struct GPUIndexBufBuilder {
  45. uint max_allowed_index;
  46. uint max_index_len;
  47. uint index_len;
  48. GPUPrimType prim_type;
  49. uint *data;
  50. } GPUIndexBufBuilder;
  51. /* supports all primitive types. */
  52. void GPU_indexbuf_init_ex(GPUIndexBufBuilder *, GPUPrimType, uint index_len, uint vertex_len);
  53. /* supports only GPU_PRIM_POINTS, GPU_PRIM_LINES and GPU_PRIM_TRIS. */
  54. void GPU_indexbuf_init(GPUIndexBufBuilder *, GPUPrimType, uint prim_len, uint vertex_len);
  55. void GPU_indexbuf_add_generic_vert(GPUIndexBufBuilder *, uint v);
  56. void GPU_indexbuf_add_primitive_restart(GPUIndexBufBuilder *);
  57. void GPU_indexbuf_add_point_vert(GPUIndexBufBuilder *, uint v);
  58. void GPU_indexbuf_add_line_verts(GPUIndexBufBuilder *, uint v1, uint v2);
  59. void GPU_indexbuf_add_tri_verts(GPUIndexBufBuilder *, uint v1, uint v2, uint v3);
  60. void GPU_indexbuf_add_line_adj_verts(GPUIndexBufBuilder *, uint v1, uint v2, uint v3, uint v4);
  61. GPUIndexBuf *GPU_indexbuf_build(GPUIndexBufBuilder *);
  62. void GPU_indexbuf_build_in_place(GPUIndexBufBuilder *, GPUIndexBuf *);
  63. void GPU_indexbuf_discard(GPUIndexBuf *);
  64. int GPU_indexbuf_primitive_len(GPUPrimType prim_type);
  65. /* Macros */
  66. #define GPU_INDEXBUF_DISCARD_SAFE(elem) \
  67. do { \
  68. if (elem != NULL) { \
  69. GPU_indexbuf_discard(elem); \
  70. elem = NULL; \
  71. } \
  72. } while (0)
  73. #endif /* __GPU_ELEMENT_H__ */