bsp.h 1.8 KB

1234567891011121314151617181920212223242526272829303132333435363738394041424344454647484950515253545556575859606162636465666768697071727374757677787980818283848586878889909192
  1. #pragma once
  2. #include "material.h"
  3. #include "render.h"
  4. #include "atto/math.h"
  5. #include "common.h"
  6. struct AABB { struct AVec3f min, max; };
  7. struct BSPModelVertex {
  8. struct AVec3f vertex;
  9. //struct AVec3f normal;
  10. struct AVec2f lightmap_uv;
  11. struct AVec2f tex_uv;
  12. struct { uint8_t r, g, b; } average_color;
  13. };
  14. struct BSPDraw {
  15. const Material *material;
  16. unsigned int start, count;
  17. unsigned int vbo_offset;
  18. };
  19. #define BSP_LANDMARK_NAME_LENGTH 64
  20. #define BSP_MAX_LANDMARKS 32
  21. typedef struct BSPLandmark {
  22. char name[BSP_LANDMARK_NAME_LENGTH];
  23. struct AVec3f origin;
  24. } BSPLandmark;
  25. struct BSPDrawSet {
  26. int draws_count;
  27. struct BSPDraw *draws;
  28. };
  29. typedef enum {
  30. BSPSkyboxDir_RT,
  31. BSPSkyboxDir_LF,
  32. BSPSkyboxDir_FT,
  33. BSPSkyboxDir_BK,
  34. BSPSkyboxDir_UP,
  35. BSPSkyboxDir_DN,
  36. BSPSkyboxDir_COUNT
  37. } BSPSkyboxDir;
  38. struct BSPModel {
  39. struct AABB aabb;
  40. RTexture lightmap;
  41. RBuffer vbo, ibo;
  42. const Material *skybox[BSPSkyboxDir_COUNT];
  43. struct BSPDrawSet detailed;
  44. struct BSPDrawSet coarse;
  45. struct BSPLandmark landmarks[BSP_MAX_LANDMARKS];
  46. int landmarks_count;
  47. struct AVec3f player_start;
  48. };
  49. struct ICollection;
  50. struct MemoryPool;
  51. struct Stack;
  52. typedef struct BSPLoadModelContext {
  53. struct ICollection *collection;
  54. struct Stack *persistent;
  55. struct Stack *tmp;
  56. /* allocated by caller, populated by callee */
  57. struct BSPModel *model;
  58. StringView name;
  59. StringView prev_map_name, next_map_name;
  60. } BSPLoadModelContext;
  61. typedef enum BSPLoadResult {
  62. BSPLoadResult_Success,
  63. BSPLoadResult_ErrorFileOpen,
  64. BSPLoadResult_ErrorFileFormat,
  65. BSPLoadResult_ErrorMemory,
  66. BSPLoadResult_ErrorTempMemory,
  67. BSPLoadResult_ErrorCapabilities
  68. } BSPLoadResult;
  69. /* should be called AFTER renderInit() */
  70. void bspInit();
  71. enum BSPLoadResult bspLoadWorldspawn(BSPLoadModelContext context);
  72. void openSourceAddMap(StringView name);