Interaction.h 5.5 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118119120121122123124125126127128129130131132133134135136137138139140141142143144145146147148
  1. /*
  2. ===========================================================================
  3. Doom 3 BFG Edition GPL Source Code
  4. Copyright (C) 1993-2012 id Software LLC, a ZeniMax Media company.
  5. This file is part of the Doom 3 BFG Edition GPL Source Code ("Doom 3 BFG Edition Source Code").
  6. Doom 3 BFG Edition Source Code is free software: you can redistribute it and/or modify
  7. it under the terms of the GNU General Public License as published by
  8. the Free Software Foundation, either version 3 of the License, or
  9. (at your option) any later version.
  10. Doom 3 BFG Edition Source Code is distributed in the hope that it will be useful,
  11. but WITHOUT ANY WARRANTY; without even the implied warranty of
  12. MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
  13. GNU General Public License for more details.
  14. You should have received a copy of the GNU General Public License
  15. along with Doom 3 BFG Edition Source Code. If not, see <http://www.gnu.org/licenses/>.
  16. In addition, the Doom 3 BFG Edition Source Code is also subject to certain additional terms. You should have received a copy of these additional terms immediately following the terms and conditions of the GNU General Public License which accompanied the Doom 3 BFG Edition Source Code. If not, please request a copy in writing from id Software at the address below.
  17. If you have questions concerning this license or the applicable additional terms, you may contact in writing id Software LLC, c/o ZeniMax Media Inc., Suite 120, Rockville, Maryland 20850 USA.
  18. ===========================================================================
  19. */
  20. #ifndef __INTERACTION_H__
  21. #define __INTERACTION_H__
  22. /*
  23. ===============================================================================
  24. Interaction between static entityDef surfaces and a static lightDef.
  25. Interactions with no lightTris and no shadowTris are still
  26. valid, because they show that a given entityDef / lightDef
  27. do not interact, even though they share one or more areas.
  28. ===============================================================================
  29. */
  30. #define LIGHT_CULL_ALL_FRONT ((byte *)-1)
  31. #define LIGHT_CLIP_EPSILON 0.1f
  32. // enabling this define allows the precise inside shadow volume test
  33. // to be performed on interaction (static) shadow volumes
  34. #define KEEP_INTERACTION_CPU_DATA
  35. struct srfCullInfo_t {
  36. // For each triangle a byte set to 1 if facing the light origin.
  37. byte * facing;
  38. // For each vertex a byte with the bits [0-5] set if the
  39. // vertex is at the back side of the corresponding clip plane.
  40. // If the 'cullBits' pointer equals LIGHT_CULL_ALL_FRONT all
  41. // vertices are at the front of all the clip planes.
  42. byte * cullBits;
  43. // Clip planes in surface space used to calculate the cull bits.
  44. idPlane localClipPlanes[6];
  45. };
  46. // Pre-generated shadow volumes from dmap are not present in surfaceInteraction_t,
  47. // they are added separately.
  48. struct surfaceInteraction_t {
  49. // The vertexes for light tris will always come from ambient triangles.
  50. // For interactions created at load time, the indexes will be uniquely
  51. // generated in static vertex memory.
  52. int numLightTrisIndexes;
  53. vertCacheHandle_t lightTrisIndexCache;
  54. // shadow volume triangle surface
  55. int numShadowIndexes;
  56. int numShadowIndexesNoCaps; // if the view is outside the shadow, this can be used
  57. triIndex_t * shadowIndexes; // only != NULL if KEEP_INTERACTION_CPU_DATA is defined
  58. vertCacheHandle_t shadowIndexCache;
  59. };
  60. class idRenderEntityLocal;
  61. class idRenderLightLocal;
  62. class idInteraction {
  63. public:
  64. // this may be 0 if the light and entity do not actually intersect
  65. // -1 = an untested interaction
  66. int numSurfaces;
  67. // if there is a whole-entity optimized shadow hull, it will
  68. // be present as a surfaceInteraction_t with a NULL ambientTris, but
  69. // possibly having a shader to specify the shadow sorting order
  70. // (FIXME: actually try making shadow hulls? we never did.)
  71. surfaceInteraction_t * surfaces;
  72. // get space from here, if NULL, it is a pre-generated shadow volume from dmap
  73. idRenderEntityLocal * entityDef;
  74. idRenderLightLocal * lightDef;
  75. idInteraction * lightNext; // for lightDef chains
  76. idInteraction * lightPrev;
  77. idInteraction * entityNext; // for entityDef chains
  78. idInteraction * entityPrev;
  79. bool staticInteraction; // true if the interaction was created at map load time in static buffer space
  80. public:
  81. idInteraction();
  82. // because these are generated and freed each game tic for active elements all
  83. // over the world, we use a custom pool allocater to avoid memory allocation overhead
  84. // and fragmentation
  85. static idInteraction * AllocAndLink( idRenderEntityLocal *edef, idRenderLightLocal *ldef );
  86. // unlinks from the entity and light, frees all surfaceInteractions,
  87. // and puts it back on the free list
  88. void UnlinkAndFree();
  89. // free the interaction surfaces
  90. void FreeSurfaces();
  91. // makes the interaction empty for when the light and entity do not actually intersect
  92. // all empty interactions are linked at the end of the light's and entity's interaction list
  93. void MakeEmpty();
  94. // returns true if the interaction is empty
  95. bool IsEmpty() const { return ( numSurfaces == 0 ); }
  96. // returns true if the interaction is not yet completely created
  97. bool IsDeferred() const { return ( numSurfaces == -1 ); }
  98. // returns true if the interaction has shadows
  99. bool HasShadows() const;
  100. // called by GenerateAllInteractions
  101. void CreateStaticInteraction();
  102. private:
  103. // unlink from entity and light lists
  104. void Unlink();
  105. };
  106. void R_ShowInteractionMemory_f( const idCmdArgs &args );
  107. #endif /* !__INTERACTION_H__ */