bsp.h 1.8 KB

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