bsp.h 1.5 KB

1234567891011121314151617181920212223242526272829303132333435363738394041424344454647484950515253545556575859606162636465666768697071727374757677787980
  1. #pragma once
  2. #include "material.h"
  3. #include "render.h"
  4. #include "atto/math.h"
  5. struct Material;
  6. struct AABB { struct AVec3f min, max; };
  7. struct Plane { struct AVec3f n; float d; };
  8. struct BSPModelVertex {
  9. struct AVec3f vertex;
  10. struct AVec3f normal;
  11. struct AVec2f lightmap_uv;
  12. struct AVec2f tex_uv;
  13. };
  14. struct BSPDraw {
  15. const struct Material *material;
  16. unsigned int start, count;
  17. };
  18. /* TODO
  19. struct BSPNode {
  20. struct AABB aabb;
  21. struct {
  22. struct BSPDraw *p;
  23. unsigned n;
  24. } draw;
  25. struct Plane plane;
  26. int left, right;
  27. };
  28. */
  29. #define BSP_LANDMARK_NAME_LENGTH 64
  30. #define BSP_MAX_LANDMARKS 32
  31. struct BSPLandmark {
  32. char name[BSP_LANDMARK_NAME_LENGTH];
  33. struct AVec3f origin;
  34. };
  35. struct BSPModel {
  36. struct AABB aabb;
  37. RTexture lightmap;
  38. RBuffer vbo, ibo;
  39. int draws_count;
  40. struct BSPDraw *draws;
  41. struct BSPLandmark landmarks[BSP_MAX_LANDMARKS];
  42. int landmarks_count;
  43. struct AVec3f player_start;
  44. };
  45. struct ICollection;
  46. struct MemoryPool;
  47. struct Stack;
  48. struct BSPLoadModelContext {
  49. struct ICollection *collection;
  50. struct Stack *persistent;
  51. struct Stack *tmp;
  52. /* allocated by caller, populated by callee */
  53. struct BSPModel *model;
  54. };
  55. enum BSPLoadResult {
  56. BSPLoadResult_Success,
  57. BSPLoadResult_ErrorFileOpen,
  58. BSPLoadResult_ErrorFileFormat,
  59. BSPLoadResult_ErrorMemory,
  60. BSPLoadResult_ErrorTempMemory,
  61. BSPLoadResult_ErrorCapabilities
  62. };
  63. enum BSPLoadResult bspLoadWorldspawn(struct BSPLoadModelContext context, const char *mapname);
  64. void openSourceAddMap(const char* mapname, int mapname_length);