tr_guisurf.cpp 6.3 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118119120121122123124125126127128129130131132133134135136137138139140141142143144145146147148149150151152153154155156157158159160161162163164165166167168169170171172173174175176177178179180181182183184185186187188189190191192193194195196197198199200201202203204205206207208209210211212213214215216217218219220
  1. /*
  2. ===========================================================================
  3. Doom 3 GPL Source Code
  4. Copyright (C) 1999-2011 id Software LLC, a ZeniMax Media company.
  5. This file is part of the Doom 3 GPL Source Code (?Doom 3 Source Code?).
  6. Doom 3 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 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 Source Code. If not, see <http://www.gnu.org/licenses/>.
  16. In addition, the Doom 3 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 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. #include "../idlib/precompiled.h"
  21. #pragma hdrstop
  22. #include "tr_local.h"
  23. /*
  24. ==========================================================================================
  25. GUI SHADERS
  26. ==========================================================================================
  27. */
  28. /*
  29. ================
  30. R_SurfaceToTextureAxis
  31. Calculates two axis for the surface sutch that a point dotted against
  32. the axis will give a 0.0 to 1.0 range in S and T when inside the gui surface
  33. ================
  34. */
  35. void R_SurfaceToTextureAxis( const srfTriangles_t *tri, idVec3 &origin, idVec3 axis[3] ) {
  36. float area, inva;
  37. float d0[5], d1[5];
  38. idDrawVert *a, *b, *c;
  39. float bounds[2][2];
  40. float boundsOrg[2];
  41. int i, j;
  42. float v;
  43. // find the bounds of the texture
  44. bounds[0][0] = bounds[0][1] = 999999;
  45. bounds[1][0] = bounds[1][1] = -999999;
  46. for ( i = 0 ; i < tri->numVerts ; i++ ) {
  47. for ( j = 0 ; j < 2 ; j++ ) {
  48. v = tri->verts[i].st[j];
  49. if ( v < bounds[0][j] ) {
  50. bounds[0][j] = v;
  51. }
  52. if ( v > bounds[1][j] ) {
  53. bounds[1][j] = v;
  54. }
  55. }
  56. }
  57. // use the floor of the midpoint as the origin of the
  58. // surface, which will prevent a slight misalignment
  59. // from throwing it an entire cycle off
  60. boundsOrg[0] = floor( ( bounds[0][0] + bounds[1][0] ) * 0.5 );
  61. boundsOrg[1] = floor( ( bounds[0][1] + bounds[1][1] ) * 0.5 );
  62. // determine the world S and T vectors from the first drawSurf triangle
  63. a = tri->verts + tri->indexes[0];
  64. b = tri->verts + tri->indexes[1];
  65. c = tri->verts + tri->indexes[2];
  66. VectorSubtract( b->xyz, a->xyz, d0 );
  67. d0[3] = b->st[0] - a->st[0];
  68. d0[4] = b->st[1] - a->st[1];
  69. VectorSubtract( c->xyz, a->xyz, d1 );
  70. d1[3] = c->st[0] - a->st[0];
  71. d1[4] = c->st[1] - a->st[1];
  72. area = d0[3] * d1[4] - d0[4] * d1[3];
  73. if ( area == 0.0 ) {
  74. axis[0].Zero();
  75. axis[1].Zero();
  76. axis[2].Zero();
  77. return; // degenerate
  78. }
  79. inva = 1.0 / area;
  80. axis[0][0] = (d0[0] * d1[4] - d0[4] * d1[0]) * inva;
  81. axis[0][1] = (d0[1] * d1[4] - d0[4] * d1[1]) * inva;
  82. axis[0][2] = (d0[2] * d1[4] - d0[4] * d1[2]) * inva;
  83. axis[1][0] = (d0[3] * d1[0] - d0[0] * d1[3]) * inva;
  84. axis[1][1] = (d0[3] * d1[1] - d0[1] * d1[3]) * inva;
  85. axis[1][2] = (d0[3] * d1[2] - d0[2] * d1[3]) * inva;
  86. idPlane plane;
  87. plane.FromPoints( a->xyz, b->xyz, c->xyz );
  88. axis[2][0] = plane[0];
  89. axis[2][1] = plane[1];
  90. axis[2][2] = plane[2];
  91. // take point 0 and project the vectors to the texture origin
  92. VectorMA( a->xyz, boundsOrg[0] - a->st[0], axis[0], origin );
  93. VectorMA( origin, boundsOrg[1] - a->st[1], axis[1], origin );
  94. }
  95. /*
  96. =================
  97. R_RenderGuiSurf
  98. Create a texture space on the given surface and
  99. call the GUI generator to create quads for it.
  100. =================
  101. */
  102. void R_RenderGuiSurf( idUserInterface *gui, drawSurf_t *drawSurf ) {
  103. idVec3 origin, axis[3];
  104. // for testing the performance hit
  105. if ( r_skipGuiShaders.GetInteger() == 1 ) {
  106. return;
  107. }
  108. // don't allow an infinite recursion loop
  109. if ( tr.guiRecursionLevel == 4 ) {
  110. return;
  111. }
  112. tr.pc.c_guiSurfs++;
  113. // create the new matrix to draw on this surface
  114. R_SurfaceToTextureAxis( drawSurf->geo, origin, axis );
  115. float guiModelMatrix[16];
  116. float modelMatrix[16];
  117. guiModelMatrix[0] = axis[0][0] / 640.0;
  118. guiModelMatrix[4] = axis[1][0] / 480.0;
  119. guiModelMatrix[8] = axis[2][0];
  120. guiModelMatrix[12] = origin[0];
  121. guiModelMatrix[1] = axis[0][1] / 640.0;
  122. guiModelMatrix[5] = axis[1][1] / 480.0;
  123. guiModelMatrix[9] = axis[2][1];
  124. guiModelMatrix[13] = origin[1];
  125. guiModelMatrix[2] = axis[0][2] / 640.0;
  126. guiModelMatrix[6] = axis[1][2] / 480.0;
  127. guiModelMatrix[10] = axis[2][2];
  128. guiModelMatrix[14] = origin[2];
  129. guiModelMatrix[3] = 0;
  130. guiModelMatrix[7] = 0;
  131. guiModelMatrix[11] = 0;
  132. guiModelMatrix[15] = 1;
  133. myGlMultMatrix( guiModelMatrix, drawSurf->space->modelMatrix,
  134. modelMatrix );
  135. tr.guiRecursionLevel++;
  136. // call the gui, which will call the 2D drawing functions
  137. tr.guiModel->Clear();
  138. gui->Redraw( tr.viewDef->renderView.time );
  139. tr.guiModel->EmitToCurrentView( modelMatrix, drawSurf->space->weaponDepthHack );
  140. tr.guiModel->Clear();
  141. tr.guiRecursionLevel--;
  142. }
  143. /*
  144. ================,
  145. R_ReloadGuis_f
  146. Reloads any guis that have had their file timestamps changed.
  147. An optional "all" parameter will cause all models to reload, even
  148. if they are not out of date.
  149. Should we also reload the map models?
  150. ================
  151. */
  152. void R_ReloadGuis_f( const idCmdArgs &args ) {
  153. bool all;
  154. if ( !idStr::Icmp( args.Argv(1), "all" ) ) {
  155. all = true;
  156. common->Printf( "Reloading all gui files...\n" );
  157. } else {
  158. all = false;
  159. common->Printf( "Checking for changed gui files...\n" );
  160. }
  161. uiManager->Reload( all );
  162. }
  163. /*
  164. ================,
  165. R_ListGuis_f
  166. ================
  167. */
  168. void R_ListGuis_f( const idCmdArgs &args ) {
  169. uiManager->ListGuis();
  170. }