GuiModel.cpp 18 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118119120121122123124125126127128129130131132133134135136137138139140141142143144145146147148149150151152153154155156157158159160161162163164165166167168169170171172173174175176177178179180181182183184185186187188189190191192193194195196197198199200201202203204205206207208209210211212213214215216217218219220221222223224225226227228229230231232233234235236237238239240241242243244245246247248249250251252253254255256257258259260261262263264265266267268269270271272273274275276277278279280281282283284285286287288289290291292293294295296297298299300301302303304305306307308309310311312313314315316317318319320321322323324325326327328329330331332333334335336337338339340341342343344345346347348349350351352353354355356357358359360361362363364365366367368369370371372373374375376377378379380381382383384385386387388389390391392393394395396397398399400401402403404405406407408409410411412413414415416417418419420421422423424425426427428429430431432433434435436437438439440441442443444445446447448449450451452453454455456457458459460461462463464465466467468469470471472473474475476477478479480481482483484485486487488489490491492493494495496497498499500501502503504505506507508509510511512513514515516517518519520521522523524525526527528529530531532533534535536537538539540541542543544545546547548549550551552553554555556557558559560561562563564565566567568569570571572573574575576577578579580581582583584585586587588589590591592593594595596597598599600601602603604605606607608609610611612613614615616617618619620621622623624625626627628629630631632633634635636637638639640641642643644645646647648649650651652653
  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. idGuiModel::idGuiModel
  26. ================
  27. */
  28. idGuiModel::idGuiModel() {
  29. indexes.SetGranularity( 1000 );
  30. verts.SetGranularity( 1000 );
  31. }
  32. /*
  33. ================
  34. idGuiModel::Clear
  35. Begins collecting draw commands into surfaces
  36. ================
  37. */
  38. void idGuiModel::Clear() {
  39. surfaces.SetNum( 0, false );
  40. indexes.SetNum( 0, false );
  41. verts.SetNum( 0, false );
  42. AdvanceSurf();
  43. }
  44. /*
  45. ================
  46. idGuiModel::WriteToDemo
  47. ================
  48. */
  49. void idGuiModel::WriteToDemo( idDemoFile *demo ) {
  50. int i, j;
  51. i = verts.Num();
  52. demo->WriteInt( i );
  53. for ( j = 0; j < i; j++ )
  54. {
  55. demo->WriteVec3( verts[j].xyz );
  56. demo->WriteVec2( verts[j].st );
  57. demo->WriteVec3( verts[j].normal );
  58. demo->WriteVec3( verts[j].tangents[0] );
  59. demo->WriteVec3( verts[j].tangents[1] );
  60. demo->WriteUnsignedChar( verts[j].color[0] );
  61. demo->WriteUnsignedChar( verts[j].color[1] );
  62. demo->WriteUnsignedChar( verts[j].color[2] );
  63. demo->WriteUnsignedChar( verts[j].color[3] );
  64. }
  65. i = indexes.Num();
  66. demo->WriteInt( i );
  67. for ( j = 0; j < i; j++ ) {
  68. demo->WriteInt(indexes[j] );
  69. }
  70. i = surfaces.Num();
  71. demo->WriteInt( i );
  72. for ( j = 0 ; j < i ; j++ ) {
  73. guiModelSurface_t *surf = &surfaces[j];
  74. demo->WriteInt( (int&)surf->material );
  75. demo->WriteFloat( surf->color[0] );
  76. demo->WriteFloat( surf->color[1] );
  77. demo->WriteFloat( surf->color[2] );
  78. demo->WriteFloat( surf->color[3] );
  79. demo->WriteInt( surf->firstVert );
  80. demo->WriteInt( surf->numVerts );
  81. demo->WriteInt( surf->firstIndex );
  82. demo->WriteInt( surf->numIndexes );
  83. demo->WriteHashString( surf->material->GetName() );
  84. }
  85. }
  86. /*
  87. ================
  88. idGuiModel::ReadFromDemo
  89. ================
  90. */
  91. void idGuiModel::ReadFromDemo( idDemoFile *demo ) {
  92. int i, j;
  93. i = verts.Num();
  94. demo->ReadInt( i );
  95. verts.SetNum( i, false );
  96. for ( j = 0; j < i; j++ )
  97. {
  98. demo->ReadVec3( verts[j].xyz );
  99. demo->ReadVec2( verts[j].st );
  100. demo->ReadVec3( verts[j].normal );
  101. demo->ReadVec3( verts[j].tangents[0] );
  102. demo->ReadVec3( verts[j].tangents[1] );
  103. demo->ReadUnsignedChar( verts[j].color[0] );
  104. demo->ReadUnsignedChar( verts[j].color[1] );
  105. demo->ReadUnsignedChar( verts[j].color[2] );
  106. demo->ReadUnsignedChar( verts[j].color[3] );
  107. }
  108. i = indexes.Num();
  109. demo->ReadInt( i );
  110. indexes.SetNum( i, false );
  111. for ( j = 0; j < i; j++ ) {
  112. demo->ReadInt(indexes[j] );
  113. }
  114. i = surfaces.Num();
  115. demo->ReadInt( i );
  116. surfaces.SetNum( i, false );
  117. for ( j = 0 ; j < i ; j++ ) {
  118. guiModelSurface_t *surf = &surfaces[j];
  119. demo->ReadInt( (int&)surf->material );
  120. demo->ReadFloat( surf->color[0] );
  121. demo->ReadFloat( surf->color[1] );
  122. demo->ReadFloat( surf->color[2] );
  123. demo->ReadFloat( surf->color[3] );
  124. demo->ReadInt( surf->firstVert );
  125. demo->ReadInt( surf->numVerts );
  126. demo->ReadInt( surf->firstIndex );
  127. demo->ReadInt( surf->numIndexes );
  128. surf->material = declManager->FindMaterial( demo->ReadHashString() );
  129. }
  130. }
  131. /*
  132. ================
  133. EmitSurface
  134. ================
  135. */
  136. void idGuiModel::EmitSurface( guiModelSurface_t *surf, float modelMatrix[16], float modelViewMatrix[16], bool depthHack ) {
  137. srfTriangles_t *tri;
  138. if ( surf->numVerts == 0 ) {
  139. return; // nothing in the surface
  140. }
  141. // copy verts and indexes
  142. tri = (srfTriangles_t *)R_ClearedFrameAlloc( sizeof( *tri ) );
  143. tri->numIndexes = surf->numIndexes;
  144. tri->numVerts = surf->numVerts;
  145. tri->indexes = (glIndex_t *)R_FrameAlloc( tri->numIndexes * sizeof( tri->indexes[0] ) );
  146. memcpy( tri->indexes, &indexes[surf->firstIndex], tri->numIndexes * sizeof( tri->indexes[0] ) );
  147. // we might be able to avoid copying these and just let them reference the list vars
  148. // but some things, like deforms and recursive
  149. // guis, need to access the verts in cpu space, not just through the vertex range
  150. tri->verts = (idDrawVert *)R_FrameAlloc( tri->numVerts * sizeof( tri->verts[0] ) );
  151. memcpy( tri->verts, &verts[surf->firstVert], tri->numVerts * sizeof( tri->verts[0] ) );
  152. // move the verts to the vertex cache
  153. tri->ambientCache = vertexCache.AllocFrameTemp( tri->verts, tri->numVerts * sizeof( tri->verts[0] ) );
  154. // if we are out of vertex cache, don't create the surface
  155. if ( !tri->ambientCache ) {
  156. return;
  157. }
  158. renderEntity_t renderEntity;
  159. memset( &renderEntity, 0, sizeof( renderEntity ) );
  160. memcpy( renderEntity.shaderParms, surf->color, sizeof( surf->color ) );
  161. viewEntity_t *guiSpace = (viewEntity_t *)R_ClearedFrameAlloc( sizeof( *guiSpace ) );
  162. memcpy( guiSpace->modelMatrix, modelMatrix, sizeof( guiSpace->modelMatrix ) );
  163. memcpy( guiSpace->modelViewMatrix, modelViewMatrix, sizeof( guiSpace->modelViewMatrix ) );
  164. guiSpace->weaponDepthHack = depthHack;
  165. // add the surface, which might recursively create another gui
  166. R_AddDrawSurf( tri, guiSpace, &renderEntity, surf->material, tr.viewDef->scissor );
  167. }
  168. /*
  169. ====================
  170. EmitToCurrentView
  171. ====================
  172. */
  173. void idGuiModel::EmitToCurrentView( float modelMatrix[16], bool depthHack ) {
  174. float modelViewMatrix[16];
  175. myGlMultMatrix( modelMatrix, tr.viewDef->worldSpace.modelViewMatrix,
  176. modelViewMatrix );
  177. for ( int i = 0 ; i < surfaces.Num() ; i++ ) {
  178. EmitSurface( &surfaces[i], modelMatrix, modelViewMatrix, depthHack );
  179. }
  180. }
  181. /*
  182. ================
  183. idGuiModel::EmitFullScreen
  184. Creates a view that covers the screen and emit the surfaces
  185. ================
  186. */
  187. void idGuiModel::EmitFullScreen( void ) {
  188. viewDef_t *viewDef;
  189. if ( surfaces[0].numVerts == 0 ) {
  190. return;
  191. }
  192. viewDef = (viewDef_t *)R_ClearedFrameAlloc( sizeof( *viewDef ) );
  193. // for gui editor
  194. if ( !tr.viewDef || !tr.viewDef->isEditor ) {
  195. viewDef->renderView.x = 0;
  196. viewDef->renderView.y = 0;
  197. viewDef->renderView.width = SCREEN_WIDTH;
  198. viewDef->renderView.height = SCREEN_HEIGHT;
  199. tr.RenderViewToViewport( &viewDef->renderView, &viewDef->viewport );
  200. viewDef->scissor.x1 = 0;
  201. viewDef->scissor.y1 = 0;
  202. viewDef->scissor.x2 = viewDef->viewport.x2 - viewDef->viewport.x1;
  203. viewDef->scissor.y2 = viewDef->viewport.y2 - viewDef->viewport.y1;
  204. } else {
  205. viewDef->renderView.x = tr.viewDef->renderView.x;
  206. viewDef->renderView.y = tr.viewDef->renderView.y;
  207. viewDef->renderView.width = tr.viewDef->renderView.width;
  208. viewDef->renderView.height = tr.viewDef->renderView.height;
  209. viewDef->viewport.x1 = tr.viewDef->renderView.x;
  210. viewDef->viewport.x2 = tr.viewDef->renderView.x + tr.viewDef->renderView.width;
  211. viewDef->viewport.y1 = tr.viewDef->renderView.y;
  212. viewDef->viewport.y2 = tr.viewDef->renderView.y + tr.viewDef->renderView.height;
  213. viewDef->scissor.x1 = tr.viewDef->scissor.x1;
  214. viewDef->scissor.y1 = tr.viewDef->scissor.y1;
  215. viewDef->scissor.x2 = tr.viewDef->scissor.x2;
  216. viewDef->scissor.y2 = tr.viewDef->scissor.y2;
  217. }
  218. viewDef->floatTime = tr.frameShaderTime;
  219. // qglOrtho( 0, 640, 480, 0, 0, 1 ); // always assume 640x480 virtual coordinates
  220. viewDef->projectionMatrix[0] = 2.0f / 640.0f;
  221. viewDef->projectionMatrix[5] = -2.0f / 480.0f;
  222. viewDef->projectionMatrix[10] = -2.0f / 1.0f;
  223. viewDef->projectionMatrix[12] = -1.0f;
  224. viewDef->projectionMatrix[13] = 1.0f;
  225. viewDef->projectionMatrix[14] = -1.0f;
  226. viewDef->projectionMatrix[15] = 1.0f;
  227. viewDef->worldSpace.modelViewMatrix[0] = 1.0f;
  228. viewDef->worldSpace.modelViewMatrix[5] = 1.0f;
  229. viewDef->worldSpace.modelViewMatrix[10] = 1.0f;
  230. viewDef->worldSpace.modelViewMatrix[15] = 1.0f;
  231. viewDef->maxDrawSurfs = surfaces.Num();
  232. viewDef->drawSurfs = (drawSurf_t **)R_FrameAlloc( viewDef->maxDrawSurfs * sizeof( viewDef->drawSurfs[0] ) );
  233. viewDef->numDrawSurfs = 0;
  234. viewDef_t *oldViewDef = tr.viewDef;
  235. tr.viewDef = viewDef;
  236. // add the surfaces to this view
  237. for ( int i = 0 ; i < surfaces.Num() ; i++ ) {
  238. EmitSurface( &surfaces[i], viewDef->worldSpace.modelMatrix, viewDef->worldSpace.modelViewMatrix, false );
  239. }
  240. tr.viewDef = oldViewDef;
  241. // add the command to draw this view
  242. R_AddDrawViewCmd( viewDef );
  243. }
  244. /*
  245. =============
  246. AdvanceSurf
  247. =============
  248. */
  249. void idGuiModel::AdvanceSurf() {
  250. guiModelSurface_t s;
  251. if ( surfaces.Num() ) {
  252. s.color[0] = surf->color[0];
  253. s.color[1] = surf->color[1];
  254. s.color[2] = surf->color[2];
  255. s.color[3] = surf->color[3];
  256. s.material = surf->material;
  257. } else {
  258. s.color[0] = 1;
  259. s.color[1] = 1;
  260. s.color[2] = 1;
  261. s.color[3] = 1;
  262. s.material = tr.defaultMaterial;
  263. }
  264. s.numIndexes = 0;
  265. s.firstIndex = indexes.Num();
  266. s.numVerts = 0;
  267. s.firstVert = verts.Num();
  268. surfaces.Append( s );
  269. surf = &surfaces[ surfaces.Num() - 1 ];
  270. }
  271. /*
  272. =============
  273. SetColor
  274. =============
  275. */
  276. void idGuiModel::SetColor( float r, float g, float b, float a ) {
  277. if ( !glConfig.isInitialized ) {
  278. return;
  279. }
  280. if ( r == surf->color[0] && g == surf->color[1]
  281. && b == surf->color[2] && a == surf->color[3] ) {
  282. return; // no change
  283. }
  284. if ( surf->numVerts ) {
  285. AdvanceSurf();
  286. }
  287. // change the parms
  288. surf->color[0] = r;
  289. surf->color[1] = g;
  290. surf->color[2] = b;
  291. surf->color[3] = a;
  292. }
  293. /*
  294. =============
  295. DrawStretchPic
  296. =============
  297. */
  298. void idGuiModel::DrawStretchPic( const idDrawVert *dverts, const glIndex_t *dindexes, int vertCount, int indexCount, const idMaterial *hShader,
  299. bool clip, float min_x, float min_y, float max_x, float max_y ) {
  300. if ( !glConfig.isInitialized ) {
  301. return;
  302. }
  303. if ( !( dverts && dindexes && vertCount && indexCount && hShader ) ) {
  304. return;
  305. }
  306. // break the current surface if we are changing to a new material
  307. if ( hShader != surf->material ) {
  308. if ( surf->numVerts ) {
  309. AdvanceSurf();
  310. }
  311. const_cast<idMaterial *>(hShader)->EnsureNotPurged(); // in case it was a gui item started before a level change
  312. surf->material = hShader;
  313. }
  314. // add the verts and indexes to the current surface
  315. if ( clip ) {
  316. int i, j;
  317. // FIXME: this is grim stuff, and should be rewritten if we have any significant
  318. // number of guis asking for clipping
  319. idFixedWinding w;
  320. for ( i = 0; i < indexCount; i += 3 ) {
  321. w.Clear();
  322. w.AddPoint(idVec5(dverts[dindexes[i]].xyz.x, dverts[dindexes[i]].xyz.y, dverts[dindexes[i]].xyz.z, dverts[dindexes[i]].st.x, dverts[dindexes[i]].st.y));
  323. w.AddPoint(idVec5(dverts[dindexes[i+1]].xyz.x, dverts[dindexes[i+1]].xyz.y, dverts[dindexes[i+1]].xyz.z, dverts[dindexes[i+1]].st.x, dverts[dindexes[i+1]].st.y));
  324. w.AddPoint(idVec5(dverts[dindexes[i+2]].xyz.x, dverts[dindexes[i+2]].xyz.y, dverts[dindexes[i+2]].xyz.z, dverts[dindexes[i+2]].st.x, dverts[dindexes[i+2]].st.y));
  325. for ( j = 0; j < 3; j++ ) {
  326. if ( w[j].x < min_x || w[j].x > max_x ||
  327. w[j].y < min_y || w[j].y > max_y ) {
  328. break;
  329. }
  330. }
  331. if ( j < 3 ) {
  332. idPlane p;
  333. p.Normal().y = p.Normal().z = 0.0f; p.Normal().x = 1.0f; p.SetDist( min_x );
  334. w.ClipInPlace( p );
  335. p.Normal().y = p.Normal().z = 0.0f; p.Normal().x = -1.0f; p.SetDist( -max_x );
  336. w.ClipInPlace( p );
  337. p.Normal().x = p.Normal().z = 0.0f; p.Normal().y = 1.0f; p.SetDist( min_y );
  338. w.ClipInPlace( p );
  339. p.Normal().x = p.Normal().z = 0.0f; p.Normal().y = -1.0f; p.SetDist( -max_y );
  340. w.ClipInPlace( p );
  341. }
  342. int numVerts = verts.Num();
  343. verts.SetNum( numVerts + w.GetNumPoints(), false );
  344. for ( j = 0 ; j < w.GetNumPoints() ; j++ ) {
  345. idDrawVert *dv = &verts[numVerts+j];
  346. dv->xyz.x = w[j].x;
  347. dv->xyz.y = w[j].y;
  348. dv->xyz.z = w[j].z;
  349. dv->st.x = w[j].s;
  350. dv->st.y = w[j].t;
  351. dv->normal.Set(0, 0, 1);
  352. dv->tangents[0].Set(1, 0, 0);
  353. dv->tangents[1].Set(0, 1, 0);
  354. }
  355. surf->numVerts += w.GetNumPoints();
  356. for ( j = 2; j < w.GetNumPoints(); j++ ) {
  357. indexes.Append( numVerts - surf->firstVert );
  358. indexes.Append( numVerts + j - 1 - surf->firstVert );
  359. indexes.Append( numVerts + j - surf->firstVert );
  360. surf->numIndexes += 3;
  361. }
  362. }
  363. } else {
  364. int numVerts = verts.Num();
  365. int numIndexes = indexes.Num();
  366. verts.AssureSize( numVerts + vertCount );
  367. indexes.AssureSize( numIndexes + indexCount );
  368. surf->numVerts += vertCount;
  369. surf->numIndexes += indexCount;
  370. for ( int i = 0; i < indexCount; i++ ) {
  371. indexes[numIndexes + i] = numVerts + dindexes[i] - surf->firstVert;
  372. }
  373. memcpy( &verts[numVerts], dverts, vertCount * sizeof( verts[0] ) );
  374. }
  375. }
  376. /*
  377. =============
  378. DrawStretchPic
  379. x/y/w/h are in the 0,0 to 640,480 range
  380. =============
  381. */
  382. void idGuiModel::DrawStretchPic( float x, float y, float w, float h, float s1, float t1, float s2, float t2, const idMaterial *hShader ) {
  383. idDrawVert verts[4];
  384. glIndex_t indexes[6];
  385. if ( !glConfig.isInitialized ) {
  386. return;
  387. }
  388. if ( !hShader ) {
  389. return;
  390. }
  391. // clip to edges, because the pic may be going into a guiShader
  392. // instead of full screen
  393. if ( x < 0 ) {
  394. s1 += ( s2 - s1 ) * -x / w;
  395. w += x;
  396. x = 0;
  397. }
  398. if ( y < 0 ) {
  399. t1 += ( t2 - t1 ) * -y / h;
  400. h += y;
  401. y = 0;
  402. }
  403. if ( x + w > 640 ) {
  404. s2 -= ( s2 - s1 ) * ( x + w - 640 ) / w;
  405. w = 640 - x;
  406. }
  407. if ( y + h > 480 ) {
  408. t2 -= ( t2 - t1 ) * ( y + h - 480 ) / h;
  409. h = 480 - y;
  410. }
  411. if ( w <= 0 || h <= 0 ) {
  412. return; // completely clipped away
  413. }
  414. indexes[0] = 3;
  415. indexes[1] = 0;
  416. indexes[2] = 2;
  417. indexes[3] = 2;
  418. indexes[4] = 0;
  419. indexes[5] = 1;
  420. verts[0].xyz[0] = x;
  421. verts[0].xyz[1] = y;
  422. verts[0].xyz[2] = 0;
  423. verts[0].st[0] = s1;
  424. verts[0].st[1] = t1;
  425. verts[0].normal[0] = 0;
  426. verts[0].normal[1] = 0;
  427. verts[0].normal[2] = 1;
  428. verts[0].tangents[0][0] = 1;
  429. verts[0].tangents[0][1] = 0;
  430. verts[0].tangents[0][2] = 0;
  431. verts[0].tangents[1][0] = 0;
  432. verts[0].tangents[1][1] = 1;
  433. verts[0].tangents[1][2] = 0;
  434. verts[1].xyz[0] = x + w;
  435. verts[1].xyz[1] = y;
  436. verts[1].xyz[2] = 0;
  437. verts[1].st[0] = s2;
  438. verts[1].st[1] = t1;
  439. verts[1].normal[0] = 0;
  440. verts[1].normal[1] = 0;
  441. verts[1].normal[2] = 1;
  442. verts[1].tangents[0][0] = 1;
  443. verts[1].tangents[0][1] = 0;
  444. verts[1].tangents[0][2] = 0;
  445. verts[1].tangents[1][0] = 0;
  446. verts[1].tangents[1][1] = 1;
  447. verts[1].tangents[1][2] = 0;
  448. verts[2].xyz[0] = x + w;
  449. verts[2].xyz[1] = y + h;
  450. verts[2].xyz[2] = 0;
  451. verts[2].st[0] = s2;
  452. verts[2].st[1] = t2;
  453. verts[2].normal[0] = 0;
  454. verts[2].normal[1] = 0;
  455. verts[2].normal[2] = 1;
  456. verts[2].tangents[0][0] = 1;
  457. verts[2].tangents[0][1] = 0;
  458. verts[2].tangents[0][2] = 0;
  459. verts[2].tangents[1][0] = 0;
  460. verts[2].tangents[1][1] = 1;
  461. verts[2].tangents[1][2] = 0;
  462. verts[3].xyz[0] = x;
  463. verts[3].xyz[1] = y + h;
  464. verts[3].xyz[2] = 0;
  465. verts[3].st[0] = s1;
  466. verts[3].st[1] = t2;
  467. verts[3].normal[0] = 0;
  468. verts[3].normal[1] = 0;
  469. verts[3].normal[2] = 1;
  470. verts[3].tangents[0][0] = 1;
  471. verts[3].tangents[0][1] = 0;
  472. verts[3].tangents[0][2] = 0;
  473. verts[3].tangents[1][0] = 0;
  474. verts[3].tangents[1][1] = 1;
  475. verts[3].tangents[1][2] = 0;
  476. DrawStretchPic( &verts[0], &indexes[0], 4, 6, hShader, false, 0.0f, 0.0f, 640.0f, 480.0f );
  477. }
  478. /*
  479. =============
  480. DrawStretchTri
  481. x/y/w/h are in the 0,0 to 640,480 range
  482. =============
  483. */
  484. void idGuiModel::DrawStretchTri( idVec2 p1, idVec2 p2, idVec2 p3, idVec2 t1, idVec2 t2, idVec2 t3, const idMaterial *material ) {
  485. idDrawVert tempVerts[3];
  486. glIndex_t tempIndexes[3];
  487. int vertCount = 3;
  488. int indexCount = 3;
  489. if ( !glConfig.isInitialized ) {
  490. return;
  491. }
  492. if ( !material ) {
  493. return;
  494. }
  495. tempIndexes[0] = 1;
  496. tempIndexes[1] = 0;
  497. tempIndexes[2] = 2;
  498. tempVerts[0].xyz[0] = p1.x;
  499. tempVerts[0].xyz[1] = p1.y;
  500. tempVerts[0].xyz[2] = 0;
  501. tempVerts[0].st[0] = t1.x;
  502. tempVerts[0].st[1] = t1.y;
  503. tempVerts[0].normal[0] = 0;
  504. tempVerts[0].normal[1] = 0;
  505. tempVerts[0].normal[2] = 1;
  506. tempVerts[0].tangents[0][0] = 1;
  507. tempVerts[0].tangents[0][1] = 0;
  508. tempVerts[0].tangents[0][2] = 0;
  509. tempVerts[0].tangents[1][0] = 0;
  510. tempVerts[0].tangents[1][1] = 1;
  511. tempVerts[0].tangents[1][2] = 0;
  512. tempVerts[1].xyz[0] = p2.x;
  513. tempVerts[1].xyz[1] = p2.y;
  514. tempVerts[1].xyz[2] = 0;
  515. tempVerts[1].st[0] = t2.x;
  516. tempVerts[1].st[1] = t2.y;
  517. tempVerts[1].normal[0] = 0;
  518. tempVerts[1].normal[1] = 0;
  519. tempVerts[1].normal[2] = 1;
  520. tempVerts[1].tangents[0][0] = 1;
  521. tempVerts[1].tangents[0][1] = 0;
  522. tempVerts[1].tangents[0][2] = 0;
  523. tempVerts[1].tangents[1][0] = 0;
  524. tempVerts[1].tangents[1][1] = 1;
  525. tempVerts[1].tangents[1][2] = 0;
  526. tempVerts[2].xyz[0] = p3.x;
  527. tempVerts[2].xyz[1] = p3.y;
  528. tempVerts[2].xyz[2] = 0;
  529. tempVerts[2].st[0] = t3.x;
  530. tempVerts[2].st[1] = t3.y;
  531. tempVerts[2].normal[0] = 0;
  532. tempVerts[2].normal[1] = 0;
  533. tempVerts[2].normal[2] = 1;
  534. tempVerts[2].tangents[0][0] = 1;
  535. tempVerts[2].tangents[0][1] = 0;
  536. tempVerts[2].tangents[0][2] = 0;
  537. tempVerts[2].tangents[1][0] = 0;
  538. tempVerts[2].tangents[1][1] = 1;
  539. tempVerts[2].tangents[1][2] = 0;
  540. // break the current surface if we are changing to a new material
  541. if ( material != surf->material ) {
  542. if ( surf->numVerts ) {
  543. AdvanceSurf();
  544. }
  545. const_cast<idMaterial *>(material)->EnsureNotPurged(); // in case it was a gui item started before a level change
  546. surf->material = material;
  547. }
  548. int numVerts = verts.Num();
  549. int numIndexes = indexes.Num();
  550. verts.AssureSize( numVerts + vertCount );
  551. indexes.AssureSize( numIndexes + indexCount );
  552. surf->numVerts += vertCount;
  553. surf->numIndexes += indexCount;
  554. for ( int i = 0; i < indexCount; i++ ) {
  555. indexes[numIndexes + i] = numVerts + tempIndexes[i] - surf->firstVert;
  556. }
  557. memcpy( &verts[numVerts], tempVerts, vertCount * sizeof( verts[0] ) );
  558. }