cevfx.cpp 39 KB

12345678910111213141516171819202122232425262728293031323334353637383940414243444546474849505152535455565758596061626364656667686970717273747576777879808182838485868788899091929394959697989910010110210310410510610710810911011111211311411511611711811912012112212312412512612712812913013113213313413513613713813914014114214314414514614714814915015115215315415515615715815916016116216316416516616716816917017117217317417517617717817918018118218318418518618718818919019119219319419519619719819920020120220320420520620720820921021121221321421521621721821922022122222322422522622722822923023123223323423523623723823924024124224324424524624724824925025125225325425525625725825926026126226326426526626726826927027127227327427527627727827928028128228328428528628728828929029129229329429529629729829930030130230330430530630730830931031131231331431531631731831932032132232332432532632732832933033133233333433533633733833934034134234334434534634734834935035135235335435535635735835936036136236336436536636736836937037137237337437537637737837938038138238338438538638738838939039139239339439539639739839940040140240340440540640740840941041141241341441541641741841942042142242342442542642742842943043143243343443543643743843944044144244344444544644744844945045145245345445545645745845946046146246346446546646746846947047147247347447547647747847948048148248348448548648748848949049149249349449549649749849950050150250350450550650750850951051151251351451551651751851952052152252352452552652752852953053153253353453553653753853954054154254354454554654754854955055155255355455555655755855956056156256356456556656756856957057157257357457557657757857958058158258358458558658758858959059159259359459559659759859960060160260360460560660760860961061161261361461561661761861962062162262362462562662762862963063163263363463563663763863964064164264364464564664764864965065165265365465565665765865966066166266366466566666766866967067167267367467567667767867968068168268368468568668768868969069169269369469569669769869970070170270370470570670770870971071171271371471571671771871972072172272372472572672772872973073173273373473573673773873974074174274374474574674774874975075175275375475575675775875976076176276376476576676776876977077177277377477577677777877978078178278378478578678778878979079179279379479579679779879980080180280380480580680780880981081181281381481581681781881982082182282382482582682782882983083183283383483583683783883984084184284384484584684784884985085185285385485585685785885986086186286386486586686786886987087187287387487587687787887988088188288388488588688788888989089189289389489589689789889990090190290390490590690790890991091191291391491591691791891992092192292392492592692792892993093193293393493593693793893994094194294394494594694794894995095195295395495595695795895996096196296396496596696796896997097197297397497597697797897998098198298398498598698798898999099199299399499599699799899910001001100210031004100510061007100810091010101110121013101410151016101710181019102010211022102310241025102610271028102910301031103210331034103510361037103810391040104110421043104410451046104710481049105010511052105310541055105610571058105910601061106210631064106510661067106810691070107110721073107410751076107710781079108010811082108310841085108610871088108910901091109210931094109510961097109810991100110111021103110411051106110711081109111011111112111311141115111611171118111911201121112211231124112511261127112811291130113111321133113411351136113711381139114011411142114311441145114611471148114911501151115211531154115511561157115811591160116111621163116411651166116711681169117011711172117311741175117611771178117911801181118211831184118511861187118811891190119111921193119411951196119711981199120012011202120312041205120612071208120912101211121212131214121512161217
  1. //---------------------------------------------------------------------------
  2. //
  3. // cevfx.cpp - This file contains the code for the VFX Shape Element
  4. //
  5. //---------------------------------------------------------------------------//
  6. // Copyright (C) Microsoft Corporation. All rights reserved. //
  7. //===========================================================================//
  8. //---------------------------------------------------------------------------
  9. // Include files
  10. #ifndef CEVFX_H
  11. #include "cevfx.h"
  12. #endif
  13. #ifndef SCALE_H
  14. #include "scale.h"
  15. #endif
  16. #ifndef VPORT_H
  17. #include "vport.h"
  18. #endif
  19. #ifndef VFX_H
  20. #include "vfx.h"
  21. #endif
  22. #ifndef HEAP_H
  23. #include "heap.h"
  24. #endif
  25. #ifndef TGL_H
  26. #include "tgl.h"
  27. #endif
  28. #ifndef CAMERA_H
  29. #include "camera.h"
  30. #endif
  31. #ifndef CLIP_H
  32. #include "clip.h"
  33. #endif
  34. extern void AG_shape_translate_transform(PANE *globalPane, void *shapeTable,LONG frameNum, LONG hotX, LONG hotY,void *tempBuffer,LONG reverse, LONG scaleUp);
  35. extern void AG_shape_transform(PANE *globalPane, void *shapeTable,LONG frameNum, LONG hotX, LONG hotY, void *tempBuffer,LONG reverse, LONG scaleUp);
  36. extern void AG_shape_lookaside( UBYTE *table );
  37. extern void AG_shape_draw (PANE *pane, void *shape_table,LONG shape_number, LONG hotX, LONG hotY);
  38. extern void AG_shape_translate_draw (PANE *pane, void *shape_table,LONG shape_number, LONG hotX, LONG hotY);
  39. void memclear(void *Dest,int Length);
  40. //---------------------------------------------------------------------------
  41. // Static Globals
  42. MemoryPtr shapeBuffer16 = NULL;
  43. MemoryPtr shapeBuffer32 = NULL;
  44. MemoryPtr shapeBuffer64 = NULL;
  45. MemoryPtr shapeBuffer128 = NULL;
  46. MemoryPtr shapeBuffer256 = NULL;
  47. //---------------------------------------------------------------------------
  48. VFXElement::VFXElement (MemoryPtr _shape, long _x, long _y, long frame, bool rev, MemoryPtr fTable, bool noScale, bool upScale) : Element(-_y)
  49. {
  50. shapeTable = _shape;
  51. x = _x;
  52. y = _y;
  53. frameNum = frame;
  54. reverse = rev;
  55. fadeTable = fTable;
  56. noScaleDraw = noScale;
  57. scaleUp = upScale;
  58. //-------------------------------------
  59. // Integrity Check here.
  60. long result = VFX_shape_count(shapeTable);
  61. if (result <= frameNum)
  62. {
  63. frameNum = result-1;
  64. }
  65. #ifdef _DEBUG
  66. result = VFX_shape_bounds(shapeTable,frameNum);
  67. long xMax = result>>16;
  68. long yMax = result & 0x0000ffff;
  69. #define MAX_X 360
  70. #define MAX_Y 360
  71. if ((yMax * xMax) >= (MAX_Y * MAX_X))
  72. {
  73. return;
  74. }
  75. #endif
  76. }
  77. //---------------------------------------------------------------------------
  78. VFXElement::VFXElement (MemoryPtr _shape, float _x, float _y, long frame, bool rev, MemoryPtr fTable, bool noScale, bool upScale) : Element(-_y)
  79. {
  80. shapeTable = _shape;
  81. x = _x;
  82. y = _y;
  83. frameNum = frame;
  84. reverse = rev;
  85. fadeTable = fTable;
  86. noScaleDraw = noScale;
  87. scaleUp = upScale;
  88. //-------------------------------------
  89. // Integrity Check here.
  90. #define MAX_X 360
  91. #define MAX_Y 360
  92. long result = VFX_shape_count(shapeTable);
  93. if (result <= frameNum)
  94. {
  95. frameNum = result-1;
  96. }
  97. #ifdef _DEBUG
  98. result = VFX_shape_bounds(shapeTable,frameNum);
  99. long xMax = result>>16;
  100. long yMax = result & 0x0000ffff;
  101. if ((yMax * xMax) >= (MAX_Y * MAX_X))
  102. {
  103. return;
  104. }
  105. #endif
  106. }
  107. extern MemoryPtr tempBuffer;
  108. //---------------------------------------------------------------------------
  109. void VFXElement::draw (void)
  110. {
  111. if (!noScaleDraw)
  112. scaleDraw (shapeTable, frameNum, x, y, reverse, fadeTable, scaleUp);
  113. else
  114. {
  115. //----------------------------------------------------------------
  116. // Check if shape is actually valid.
  117. if ((*(int*)shapeTable!=*(int*)"1.10"))
  118. return;
  119. if (!reverse)
  120. {
  121. if (!fadeTable)
  122. AG_shape_draw(globalPane,shapeTable,frameNum,x,y);
  123. else
  124. {
  125. AG_shape_lookaside(fadeTable);
  126. AG_shape_translate_draw(globalPane,shapeTable,frameNum,x,y);
  127. }
  128. }
  129. else //45Pixel mechs dealt with here.
  130. {
  131. if (!tempBuffer)
  132. tempBuffer = (MemoryPtr)systemHeap->Malloc(MAX_X * MAX_Y);
  133. if (fadeTable)
  134. {
  135. AG_shape_lookaside(fadeTable);
  136. AG_shape_translate_transform(globalPane,shapeTable,frameNum,x,y,tempBuffer,reverse,TRUE);
  137. }
  138. else
  139. {
  140. AG_shape_transform(globalPane,shapeTable,frameNum,x,y,tempBuffer,reverse,TRUE);
  141. }
  142. }
  143. }
  144. }
  145. long mechRGBLookup[56] =
  146. {
  147. (0x00) + (0x00<<8) + (0x00<<16) + (0x00<<24), //0
  148. (0x00) + (0x00<<8) + (0x00<<16) + (0x00<<24), //1
  149. (0x00) + (0x00<<8) + (0x00<<16) + (0x00<<24), //2
  150. (0x00) + (0x00<<8) + (0x00<<16) + (0x00<<24), //3
  151. (0x00) + (0x00<<8) + (0x00<<16) + (0x00<<24), //4
  152. (0x00) + (0x00<<8) + (0x00<<16) + (0x00<<24), //5
  153. (0x00) + (0x00<<8) + (0x00<<16) + (0x00<<24), //6
  154. (0x00) + (0x00<<8) + (0x00<<16) + (0x00<<24), //7
  155. (0x00) + (0x00<<8) + (0x00<<16) + (0x00<<24), //8
  156. (0x00) + (0x00<<8) + (0x00<<16) + (0x00<<24), //9
  157. (0x00) + (0x00<<8) + (0x00<<16) + (0x00<<24), //10
  158. (0x00) + (0x00<<8) + (0x00<<16) + (0x00<<24), //11
  159. (0x00) + (0x00<<8) + (0x00<<16) + (0x00<<24), //12
  160. (0x00) + (0x00<<8) + (0x00<<16) + (0x00<<24), //13
  161. (0x00) + (0x00<<8) + (0x00<<16) + (0x00<<24), //14
  162. (0x00) + (0x00<<8) + (0x00<<16) + (0x00<<24), //15
  163. (0x00) + (0x10<<8) + (0x00<<16) + (0xff<<24), //16
  164. (0x00) + (0x20<<8) + (0x00<<16) + (0xff<<24), //17
  165. (0x00) + (0x30<<8) + (0x00<<16) + (0xff<<24), //18
  166. (0x00) + (0x40<<8) + (0x00<<16) + (0xff<<24), //19
  167. (0x00) + (0x50<<8) + (0x00<<16) + (0xff<<24), //20
  168. (0x00) + (0x60<<8) + (0x00<<16) + (0xff<<24), //21
  169. (0x00) + (0x70<<8) + (0x00<<16) + (0xff<<24), //22
  170. (0x00) + (0x80<<8) + (0x00<<16) + (0xff<<24), //23
  171. (0x00) + (0x90<<8) + (0x00<<16) + (0xff<<24), //24
  172. (0x00) + (0xA0<<8) + (0x00<<16) + (0xff<<24), //25
  173. (0x00) + (0xB0<<8) + (0x00<<16) + (0xff<<24), //26
  174. (0x00) + (0xC0<<8) + (0x00<<16) + (0xff<<24), //27
  175. (0x00) + (0xD0<<8) + (0x00<<16) + (0xff<<24), //28
  176. (0x00) + (0xE0<<8) + (0x00<<16) + (0xff<<24), //29
  177. (0x00) + (0xF0<<8) + (0x00<<16) + (0xff<<24), //30
  178. (0x00) + (0xFF<<8) + (0x00<<16) + (0xff<<24), //31
  179. (0x00) + (0x00<<8) + (0x00<<16) + (0x00<<24), //32
  180. (0x00) + (0x00<<8) + (0x00<<16) + (0x00<<24), //33
  181. (0x00) + (0x00<<8) + (0x00<<16) + (0x00<<24), //34
  182. (0x00) + (0x00<<8) + (0x00<<16) + (0x00<<24), //35
  183. (0x00) + (0x00<<8) + (0x00<<16) + (0x00<<24), //36
  184. (0x00) + (0x00<<8) + (0x00<<16) + (0x00<<24), //37
  185. (0x00) + (0x00<<8) + (0x00<<16) + (0x00<<24), //38
  186. (0x00) + (0x00<<8) + (0x00<<16) + (0x00<<24), //39
  187. (0x20) + (0x00<<8) + (0x00<<16) + (0xff<<24), //40
  188. (0x40) + (0x00<<8) + (0x00<<16) + (0xff<<24), //41
  189. (0x60) + (0x00<<8) + (0x00<<16) + (0xff<<24), //42
  190. (0x80) + (0x00<<8) + (0x00<<16) + (0xff<<24), //43
  191. (0xA0) + (0x00<<8) + (0x00<<16) + (0xff<<24), //44
  192. (0xC0) + (0x00<<8) + (0x00<<16) + (0xff<<24), //45
  193. (0xE0) + (0x00<<8) + (0x00<<16) + (0xff<<24), //46
  194. (0xFF) + (0x00<<8) + (0x00<<16) + (0xff<<24), //47
  195. (0x00) + (0x00<<8) + (0x20<<16) + (0xff<<24), //48
  196. (0x00) + (0x00<<8) + (0x40<<16) + (0xff<<24), //49
  197. (0x00) + (0x00<<8) + (0x60<<16) + (0xff<<24), //50
  198. (0x00) + (0x00<<8) + (0x80<<16) + (0xff<<24), //51
  199. (0x00) + (0x00<<8) + (0xA0<<16) + (0xff<<24), //52
  200. (0x00) + (0x00<<8) + (0xC0<<16) + (0xff<<24), //53
  201. (0x00) + (0x00<<8) + (0xE0<<16) + (0xff<<24), //54
  202. (0x00) + (0x00<<8) + (0xFF<<16) + (0xff<<24), //55
  203. };
  204. long mechRGBLookup2[56] =
  205. {
  206. (0x00) + (0x00<<8) + (0x00<<16) + (0x00<<24), //0
  207. (0x00) + (0x00<<8) + (0x00<<16) + (0x00<<24), //1
  208. (0x00) + (0x00<<8) + (0x00<<16) + (0x00<<24), //2
  209. (0x00) + (0x00<<8) + (0x00<<16) + (0x00<<24), //3
  210. (0x00) + (0x00<<8) + (0x00<<16) + (0x00<<24), //4
  211. (0x00) + (0x00<<8) + (0x00<<16) + (0x00<<24), //5
  212. (0x00) + (0x00<<8) + (0x00<<16) + (0x00<<24), //6
  213. (0x00) + (0x00<<8) + (0x00<<16) + (0x00<<24), //7
  214. (0x00) + (0x00<<8) + (0x00<<16) + (0x00<<24), //8
  215. (0x00) + (0x00<<8) + (0x00<<16) + (0x00<<24), //9
  216. (0x00) + (0x00<<8) + (0x00<<16) + (0x00<<24), //10
  217. (0x00) + (0x00<<8) + (0x00<<16) + (0x00<<24), //11
  218. (0x00) + (0x00<<8) + (0x00<<16) + (0x00<<24), //12
  219. (0x00) + (0x00<<8) + (0x00<<16) + (0x00<<24), //13
  220. (0x00) + (0x00<<8) + (0x00<<16) + (0x00<<24), //14
  221. (0x00) + (0x00<<8) + (0x00<<16) + (0x00<<24), //15
  222. ( 104) + ( 104<<8) + ( 104<<16) + (0xff<<24), //16
  223. ( 112) + ( 112<<8) + ( 112<<16) + (0xff<<24), //17
  224. ( 120) + ( 120<<8) + ( 120<<16) + (0xff<<24), //18
  225. ( 128) + ( 128<<8) + ( 128<<16) + (0xff<<24), //19
  226. ( 136) + ( 136<<8) + ( 136<<16) + (0xff<<24), //20
  227. ( 144) + ( 144<<8) + ( 144<<16) + (0xff<<24), //21
  228. ( 156) + ( 156<<8) + ( 156<<16) + (0xff<<24), //22
  229. ( 168) + ( 168<<8) + ( 168<<16) + (0xff<<24), //23
  230. ( 180) + ( 180<<8) + ( 180<<16) + (0xff<<24), //24
  231. ( 196) + ( 196<<8) + ( 196<<16) + (0xff<<24), //25
  232. ( 208) + ( 208<<8) + ( 208<<16) + (0xff<<24), //26
  233. ( 224) + ( 224<<8) + ( 224<<16) + (0xff<<24), //27
  234. ( 236) + ( 236<<8) + ( 236<<16) + (0xff<<24), //28
  235. ( 248) + ( 248<<8) + ( 248<<16) + (0xff<<24), //29
  236. ( 255) + ( 255<<8) + ( 255<<16) + (0xff<<24), //30
  237. ( 255) + ( 255<<8) + ( 255<<16) + (0xff<<24), //31
  238. (0x00) + (0x00<<8) + (0x00<<16) + (0x00<<24), //32
  239. (0x00) + (0x00<<8) + (0x00<<16) + (0x00<<24), //33
  240. (0x00) + (0x00<<8) + (0x00<<16) + (0x00<<24), //34
  241. (0x00) + (0x00<<8) + (0x00<<16) + (0x00<<24), //35
  242. (0x00) + (0x00<<8) + (0x00<<16) + (0x00<<24), //36
  243. (0x00) + (0x00<<8) + (0x00<<16) + (0x00<<24), //37
  244. (0x00) + (0x00<<8) + (0x00<<16) + (0x00<<24), //38
  245. (0x00) + (0x00<<8) + (0x00<<16) + (0x00<<24), //39
  246. ( 28) + ( 36<<8) + ( 48<<16) + (0xff<<24), //40
  247. ( 60) + ( 68<<8) + ( 76<<16) + (0xff<<24), //41
  248. ( 96) + ( 100<<8) + ( 104<<16) + (0xff<<24), //42
  249. ( 132) + ( 132<<8) + ( 136<<16) + (0xff<<24), //43
  250. ( 148) + ( 152<<8) + ( 156<<16) + (0xff<<24), //44
  251. ( 168) + ( 172<<8) + ( 176<<16) + (0xff<<24), //45
  252. ( 184) + ( 192<<8) + ( 196<<16) + (0xff<<24), //46
  253. ( 204) + ( 212<<8) + ( 220<<16) + (0xff<<24), //47
  254. ( 44) + ( 52<<8) + ( 60<<16) + (0xff<<24), //48
  255. ( 44) + ( 52<<8) + ( 88<<16) + (0xff<<24), //49
  256. ( 44) + ( 52<<8) + ( 116<<16) + (0xff<<24), //50
  257. ( 48) + ( 56<<8) + ( 148<<16) + (0xff<<24), //51
  258. ( 48) + ( 64<<8) + ( 172<<16) + (0xff<<24), //52
  259. ( 52) + ( 72<<8) + ( 196<<16) + (0xff<<24), //53
  260. ( 56) + ( 80<<8) + ( 220<<16) + (0xff<<24), //54
  261. ( 92) + ( 116<<8) + ( 255<<16) + (0xff<<24), //55
  262. };
  263. long mechCmdr1PaletteLookup[256];
  264. //---------------------------------------------------------------------------
  265. void VFXShapeElement::init (MemoryPtr _shape, long _x, long _y, long frame, bool rev, unsigned long *fTable, float _z, float tZ)
  266. {
  267. gosASSERT(_shape != NULL);
  268. long i=0;
  269. while (shapeTable[i] != NULL)
  270. i++;
  271. gosASSERT(i < MAX_ELEMENT_SHAPES);
  272. shapeTable[i] = _shape;
  273. frameNum[i] = frame;
  274. reverse[i] = rev;
  275. if (!i)
  276. {
  277. x = _x;
  278. y = _y;
  279. fadeTable = fTable;
  280. z = _z;
  281. topZ = tZ;
  282. }
  283. }
  284. //---------------------------------------------------------------------------
  285. long VFXShapeElement::getTextureHandle (long height)
  286. {
  287. DWORD textureResult = 0;
  288. if (height == -1)
  289. {
  290. //-----------------------------------------------
  291. // We need to take the shape bounds and find the
  292. // smallest texture buffer that will hold it.
  293. // Create an empty Keyed buffer for now.
  294. long textureSize = VFX_shape_bounds(shapeTable[0],frameNum[0]);
  295. long xRes = textureSize >> 16;
  296. long yRes = textureSize & 0x0000ffff;
  297. if ((xRes < 16) && (yRes < 16))
  298. {
  299. textureResult = gos_NewEmptyTexture(gos_Texture_Keyed,"ShapeTable",16,gosHint_DisableMipmap);
  300. }
  301. else if ((xRes < 32) && (yRes < 32))
  302. {
  303. textureResult = gos_NewEmptyTexture(gos_Texture_Keyed,"ShapeTable",32,gosHint_DisableMipmap);
  304. }
  305. else if ((xRes < 64) && (yRes < 64))
  306. {
  307. textureResult = gos_NewEmptyTexture(gos_Texture_Keyed,"ShapeTable",64,gosHint_DisableMipmap);
  308. }
  309. else if ((xRes < 128) && (yRes < 128))
  310. {
  311. textureResult = gos_NewEmptyTexture(gos_Texture_Keyed,"ShapeTable",128,gosHint_DisableMipmap);
  312. }
  313. else if ((xRes < 256) && (yRes < 256))
  314. {
  315. textureResult = gos_NewEmptyTexture(gos_Texture_Keyed,"ShapeTable",256,gosHint_DisableMipmap);
  316. }
  317. }
  318. else
  319. {
  320. textureResult = gos_NewEmptyTexture(gos_Texture_Keyed,"ShapeTable",height,gosHint_DisableMipmap);
  321. }
  322. textureMemoryHandle = textureResult;
  323. actualHeight = height;
  324. //-------------------------------------------------------------------
  325. // Try setting up the texture buffer here instead of right before
  326. // we force D3D to draw the damned thing. Maybe helps LockTexture?
  327. drawShape();
  328. return textureResult;
  329. }
  330. //-------------------------------------------------------------------------------------------
  331. void VFXShapeElement::drawShape (void)
  332. {
  333. //-------------------------------------------------------------------------------------------
  334. // -Create a buffer to hold the shapes.
  335. // -Draw all of the shapes to the buffer in order received.
  336. // -Get Pointer to Locked texture RAM.
  337. // -Copy 8Bit buffer to Texture Buffer using fTable passed in or default if fTable is NULL
  338. // -Unlock Texture RAM!
  339. // draw in Draw Function now. Not here. Give texture a chance to settle in before drawing.
  340. PANE gPane;
  341. WINDOW gWindow;
  342. gPane.window = &gWindow;
  343. gPane.x0 = gPane.y0 = 0;
  344. gWindow.stencil = gWindow.shadow = NULL;
  345. long textureWidth = 0;
  346. long maxFrames = VFX_shape_count(shapeTable[0]);
  347. if (frameNum[0] >= maxFrames)
  348. frameNum[0] = maxFrames-1;
  349. long textureSize = VFX_shape_bounds(shapeTable[0],frameNum[0]);
  350. long xRes = textureSize >> 16;
  351. long yRes = textureSize & 0x0000ffff;
  352. if (actualHeight == -1)
  353. {
  354. if ((xRes < 16) && (yRes < 16))
  355. {
  356. if (!shapeBuffer16)
  357. shapeBuffer16 = (MemoryPtr)systemHeap->Malloc(16*16);
  358. gWindow.buffer = shapeBuffer16;
  359. memset(gWindow.buffer,0,16*16);
  360. gPane.x1 = gPane.y1 = 16;
  361. gWindow.x_max = gWindow.y_max = 15;
  362. textureWidth = 16;
  363. }
  364. else if ((xRes < 32) && (yRes < 32))
  365. {
  366. if (!shapeBuffer32)
  367. shapeBuffer32 = (MemoryPtr)systemHeap->Malloc(32*32);
  368. gWindow.buffer = shapeBuffer32;
  369. memset(gWindow.buffer,0,32*32);
  370. gPane.x1 = gPane.y1 = 32;
  371. gWindow.x_max = gWindow.y_max = 31;
  372. textureWidth = 32;
  373. }
  374. else if ((xRes < 64) && (yRes < 64))
  375. {
  376. if (!shapeBuffer64)
  377. shapeBuffer64 = (MemoryPtr)systemHeap->Malloc(64*64);
  378. gWindow.buffer = shapeBuffer64;
  379. memset(gWindow.buffer,0,64*64);
  380. gPane.x1 = gPane.y1 = 64;
  381. gWindow.x_max = gWindow.y_max = 63;
  382. textureWidth = 64;
  383. }
  384. else if ((xRes < 128) && (yRes < 128))
  385. {
  386. if (!shapeBuffer128)
  387. shapeBuffer128 = (MemoryPtr)systemHeap->Malloc(128*128);
  388. gWindow.buffer = shapeBuffer128;
  389. memset(gWindow.buffer,0,128*128);
  390. gPane.x1 = gPane.y1 = 128;
  391. gWindow.x_max = gWindow.y_max = 127;
  392. textureWidth = 128;
  393. }
  394. else if ((xRes < 256) && (yRes < 256))
  395. {
  396. if (!shapeBuffer256)
  397. shapeBuffer256 = (MemoryPtr)systemHeap->Malloc(256*256);
  398. gWindow.buffer = shapeBuffer256;
  399. memset(gWindow.buffer,0,256*256);
  400. gPane.x1 = gPane.y1 = 256;
  401. gWindow.x_max = gWindow.y_max = 255;
  402. textureWidth = 256;
  403. }
  404. }
  405. else
  406. {
  407. switch (actualHeight)
  408. {
  409. case 16:
  410. if (!shapeBuffer16)
  411. shapeBuffer16 = (MemoryPtr)systemHeap->Malloc(16*16);
  412. gWindow.buffer = shapeBuffer16;
  413. break;
  414. case 32:
  415. if (!shapeBuffer32)
  416. shapeBuffer32 = (MemoryPtr)systemHeap->Malloc(32*32);
  417. gWindow.buffer = shapeBuffer32;
  418. break;
  419. case 64:
  420. if (!shapeBuffer64)
  421. shapeBuffer64 = (MemoryPtr)systemHeap->Malloc(64*64);
  422. gWindow.buffer = shapeBuffer64;
  423. break;
  424. case 128:
  425. if (!shapeBuffer128)
  426. shapeBuffer128 = (MemoryPtr)systemHeap->Malloc(128*128);
  427. gWindow.buffer = shapeBuffer128;
  428. break;
  429. case 256:
  430. if (!shapeBuffer256)
  431. shapeBuffer256 = (MemoryPtr)systemHeap->Malloc(256*256);
  432. gWindow.buffer = shapeBuffer256;
  433. break;
  434. }
  435. memset(gWindow.buffer,0,actualHeight*actualHeight);
  436. gPane.x1 = gPane.y1 = actualHeight;
  437. gWindow.x_max = gWindow.y_max = actualHeight-1;
  438. textureWidth = actualHeight;
  439. }
  440. //------------------------------------------
  441. // Draw the shapes in order to the buffer
  442. long i=0;
  443. xHS = 0.0;
  444. yHS = 0.0;
  445. float uxHS= 0.0, uyHS = 0.0;
  446. textureFactor = float(textureWidth) * Camera::globalScaleFactor;
  447. if (!tempBuffer)
  448. tempBuffer = (MemoryPtr)systemHeap->Malloc(MAX_X * MAX_Y);
  449. while (shapeTable[i] && (i < MAX_ELEMENT_SHAPES))
  450. {
  451. long oldHSX, oldHSY;
  452. long HS = VFX_shape_origin(shapeTable[i],frameNum[i]);
  453. oldHSX = HS >> 16;
  454. oldHSY = HS & 0x0000ffff;
  455. uxHS = float(textureWidth) * oldHSX / xRes;
  456. uyHS = float(textureWidth) * oldHSY / yRes;
  457. xHS = uxHS * Camera::globalScaleFactor;
  458. yHS = uyHS * Camera::globalScaleFactor;
  459. AG_shape_transform(&gPane,shapeTable[i],frameNum[i],uxHS,uyHS,tempBuffer,reverse[i],TRUE);
  460. i++;
  461. }
  462. //-------------------
  463. // Lock the texture.
  464. TEXTUREPTR textureData;
  465. gos_LockTexture(textureMemoryHandle, 0, 0, &textureData);
  466. //-------------------------------------------------------
  467. // Copy 8 bit data to 32 bit texture surface using table
  468. // Could easily assemblify and much improve speed!
  469. DWORD *textureMemory = textureData.pTexture;
  470. MemoryPtr bufferMemory = gWindow.buffer;
  471. if (fadeTable)
  472. {
  473. for (i=0;i<textureWidth;i++)
  474. {
  475. for (long j=0;j<textureWidth;j++)
  476. {
  477. *textureMemory = fadeTable[*bufferMemory];
  478. bufferMemory++;
  479. textureMemory++;
  480. }
  481. }
  482. }
  483. else
  484. {
  485. memclear(textureMemory,textureWidth * textureWidth); //Nothing to draw. Wipe it.
  486. }
  487. //------------------------
  488. // Unlock the texture
  489. gos_UnLockTexture(textureMemoryHandle);
  490. }
  491. //---------------------------------------------------------------------------
  492. void VFXShapeElement::setTextureHandle (DWORD handle, long height)
  493. {
  494. textureMemoryHandle = handle;
  495. actualHeight = height;
  496. //-------------------------------------------------------------------
  497. // Try setting up the texture buffer here instead of right before
  498. // we force D3D to draw the damned thing. Maybe helps LockTexture?
  499. drawShape();
  500. }
  501. //---------------------------------------------------------------------------
  502. void VFXShapeElement::draw (void)
  503. {
  504. //-------------------------------------
  505. // Clip and Draw Top Triangle First
  506. gos_VERTEX gVertex[3];
  507. gVertex[0].x = x - xHS;
  508. gVertex[0].y = y - yHS;
  509. gVertex[0].z = z;//topZ;
  510. gVertex[0].rhw = 0.5;
  511. gVertex[0].u = 0.0;
  512. gVertex[0].v = 0.0;
  513. gVertex[0].argb = lightRGB;
  514. gVertex[0].frgb = fogRGB;
  515. gVertex[1].x = gVertex[0].x+textureFactor;
  516. gVertex[1].y = gVertex[0].y;
  517. gVertex[1].z = z;//topZ;
  518. gVertex[1].rhw = 0.5;
  519. gVertex[1].u = 1.0;
  520. gVertex[1].v = 0.0;
  521. gVertex[1].argb = lightRGB;
  522. gVertex[1].frgb = fogRGB;
  523. gVertex[2].x = gVertex[0].x+textureFactor;
  524. gVertex[2].y = gVertex[0].y+textureFactor;
  525. gVertex[2].z = topZ;//z;
  526. gVertex[2].rhw = 0.5;
  527. gVertex[2].u = 1.0;
  528. gVertex[2].v = 1.0;
  529. gVertex[2].argb = lightRGB;
  530. gVertex[2].frgb = fogRGB;
  531. gos_SetRenderState( gos_State_Filter, gos_FilterNone );
  532. gos_SetRenderState( gos_State_AlphaMode, gos_Alpha_OneZero );
  533. gos_SetRenderState( gos_State_Specular, false );
  534. gos_SetRenderState( gos_State_AlphaTest, TRUE );
  535. gos_SetRenderState( gos_State_Texture, textureMemoryHandle );
  536. if ((gVertex[0].z >= 0.0f) &&
  537. (gVertex[0].z < 1.0f) &&
  538. (gVertex[1].z >= 0.0f) &&
  539. (gVertex[1].z < 1.0f) &&
  540. (gVertex[2].z >= 0.0f) &&
  541. (gVertex[2].z < 1.0f))
  542. {
  543. //-----------------------------------------------------------------------------
  544. // Reject Any triangle which has vertices off screeen in software for now.
  545. // Do real cliping in geometry layer for software and hardware that needs it!
  546. gos_DrawTriangles(gVertex, 3);
  547. }
  548. //----------------------------------------
  549. // clip and draw bottom triangle
  550. gVertex[1].x = gVertex[2].x;
  551. gVertex[1].y = gVertex[2].y;
  552. gVertex[1].z = gVertex[2].z;
  553. gVertex[1].rhw = gVertex[2].rhw;
  554. gVertex[1].u = gVertex[2].u;
  555. gVertex[1].v = gVertex[2].v;
  556. gVertex[1].argb = gVertex[2].argb;
  557. gVertex[1].frgb = gVertex[2].frgb;
  558. gVertex[2].x = gVertex[0].x;
  559. gVertex[2].y = gVertex[0].y+textureFactor;
  560. gVertex[2].z = topZ;//z;
  561. gVertex[2].rhw = 0.5;
  562. gVertex[2].u = 0.0;
  563. gVertex[2].v = 1.0;
  564. gVertex[2].argb = lightRGB;
  565. gVertex[2].frgb = fogRGB;
  566. if ((gVertex[0].z >= 0.0f) &&
  567. (gVertex[0].z < 1.0f) &&
  568. (gVertex[1].z >= 0.0f) &&
  569. (gVertex[1].z < 1.0f) &&
  570. (gVertex[2].z >= 0.0f) &&
  571. (gVertex[2].z < 1.0f))
  572. {
  573. //-----------------------------------------------------------------------------
  574. // Reject Any triangle which has vertices off screeen in software for now.
  575. // Do real cliping in geometry layer for software and hardware that needs it!
  576. gos_DrawTriangles(gVertex, 3);
  577. }
  578. //-------------------------------------------
  579. // Reset shapeTable Data after draw!
  580. // Everything else is reset during INIT call!
  581. shapeTable[0] = shapeTable[1] = shapeTable[2] = shapeTable[3] = NULL;
  582. }
  583. //---------------------------------------------------------------------------
  584. // class TextureElement
  585. void TextureElement::init (DWORD textureHandle, long _x, long _y, long hsx, long hsy, float tW, float _z, float tZ)
  586. {
  587. x = _x;
  588. y = _y;
  589. z = _z;
  590. topZ = tZ;
  591. xHS = hsx;
  592. yHS = hsy;
  593. tWidth = tW;
  594. textureMemoryHandle = textureHandle;
  595. }
  596. //---------------------------------------------------------------------------
  597. void TextureElement::draw (void)
  598. {
  599. //-------------------------------------
  600. // Nothing else to do with this bUt
  601. // -gosDraw!
  602. float textureFactor = float(tWidth) * Camera::globalScaleFactor;
  603. xHS *= Camera::globalScaleFactor;
  604. yHS *= Camera::globalScaleFactor;
  605. //----------------------------
  606. // Clip and draw top triangle
  607. gos_VERTEX gVertex[3];
  608. gVertex[0].x = x - xHS;
  609. gVertex[0].y = y - yHS;
  610. gVertex[0].z = topZ;
  611. gVertex[0].rhw = 0.5;
  612. gVertex[0].u = 0.0;
  613. gVertex[0].v = 0.0;
  614. gVertex[0].argb = lightRGB;
  615. gVertex[0].frgb = fogRGB;
  616. gVertex[1].x = gVertex[0].x+textureFactor;
  617. gVertex[1].y = gVertex[0].y;
  618. gVertex[1].z = topZ;
  619. gVertex[1].rhw = 0.5;
  620. gVertex[1].u = 1.0;
  621. gVertex[1].v = 0.0;
  622. gVertex[1].argb = lightRGB;
  623. gVertex[1].frgb = fogRGB;
  624. gVertex[2].x = gVertex[0].x+textureFactor;
  625. gVertex[2].y = gVertex[0].y+textureFactor;
  626. gVertex[2].z = z;
  627. gVertex[2].rhw = 0.5;
  628. gVertex[2].u = 1.0;
  629. gVertex[2].v = 1.0;
  630. gVertex[2].argb = lightRGB;
  631. gVertex[2].frgb = fogRGB;
  632. //--------------------------------
  633. //Set States for Software Renderer
  634. gos_SetRenderState( gos_State_Texture, textureMemoryHandle );
  635. if (Environment.Renderer == 3)
  636. {
  637. gos_SetRenderState( gos_State_AlphaMode, gos_Alpha_OneZero);
  638. gos_SetRenderState( gos_State_ShadeMode, gos_ShadeGouraud);
  639. gos_SetRenderState( gos_State_MonoEnable, 1);
  640. gos_SetRenderState( gos_State_Perspective, 0);
  641. gos_SetRenderState( gos_State_Clipping, 0);
  642. gos_SetRenderState( gos_State_AlphaTest, 0);
  643. gos_SetRenderState( gos_State_Specular, 0);
  644. gos_SetRenderState( gos_State_Dither, 0);
  645. gos_SetRenderState( gos_State_TextureMapBlend, gos_BlendModulate);
  646. gos_SetRenderState( gos_State_Filter, gos_FilterNone);
  647. gos_SetRenderState( gos_State_TextureAddress, gos_TextureClamp );
  648. }
  649. //--------------------------------
  650. //Set States for Hardware Renderer
  651. else
  652. {
  653. gos_SetRenderState( gos_State_AlphaMode, gos_Alpha_OneZero);
  654. gos_SetRenderState( gos_State_ShadeMode, gos_ShadeGouraud);
  655. gos_SetRenderState( gos_State_MonoEnable, 0);
  656. gos_SetRenderState( gos_State_Perspective, 1);
  657. gos_SetRenderState( gos_State_Clipping, 2);
  658. gos_SetRenderState( gos_State_AlphaTest, 0);
  659. gos_SetRenderState( gos_State_Specular, 0);
  660. gos_SetRenderState( gos_State_Dither, 1);
  661. gos_SetRenderState( gos_State_TextureMapBlend, gos_BlendModulate);
  662. gos_SetRenderState( gos_State_Filter, gos_FilterBiLinear);
  663. gos_SetRenderState( gos_State_TextureAddress, gos_TextureClamp );
  664. }
  665. if ((gVertex[0].z >= 0.0f) &&
  666. (gVertex[0].z < 1.0f) &&
  667. (gVertex[1].z >= 0.0f) &&
  668. (gVertex[1].z < 1.0f) &&
  669. (gVertex[2].z >= 0.0f) &&
  670. (gVertex[2].z < 1.0f))
  671. {
  672. //-----------------------------------------------------------------------------
  673. // Reject Any triangle which has vertices off screeen in software for now.
  674. // Do real cliping in geometry layer for software and hardware that needs it!
  675. gos_DrawTriangles(gVertex, 3);
  676. }
  677. //---------------------------------------
  678. // Clip and draw Bottom Triangle
  679. gVertex[1].x = gVertex[2].x;
  680. gVertex[1].y = gVertex[2].y;
  681. gVertex[1].z = gVertex[2].z;
  682. gVertex[1].rhw = gVertex[2].rhw;
  683. gVertex[1].u = gVertex[2].u;
  684. gVertex[1].v = gVertex[2].v;
  685. gVertex[1].argb = gVertex[2].argb;
  686. gVertex[1].frgb = gVertex[2].frgb;
  687. gVertex[2].x = gVertex[0].x;
  688. gVertex[2].y = gVertex[0].y+textureFactor;
  689. gVertex[2].z = z;
  690. gVertex[2].rhw = 0.5;
  691. gVertex[2].u = 0.0;
  692. gVertex[2].v = 1.0;
  693. gVertex[2].argb = lightRGB;
  694. gVertex[2].frgb = fogRGB;
  695. if ((gVertex[0].z >= 0.0f) &&
  696. (gVertex[0].z < 1.0f) &&
  697. (gVertex[1].z >= 0.0f) &&
  698. (gVertex[1].z < 1.0f) &&
  699. (gVertex[2].z >= 0.0f) &&
  700. (gVertex[2].z < 1.0f))
  701. {
  702. //-----------------------------------------------------------------------------
  703. // Reject Any triangle which has vertices off screeen in software for now.
  704. // Do real cliping in geometry layer for software and hardware that needs it!
  705. gos_DrawTriangles(gVertex, 3);
  706. }
  707. }
  708. //---------------------------------------------------------------------------
  709. // class PolygonQuadElement
  710. void PolygonQuadElement::init (gos_VERTEX *v)
  711. {
  712. vertices[0] = v[0];
  713. vertices[1] = v[1];
  714. vertices[2] = v[2];
  715. vertices[3] = v[3];
  716. //------------------------------------------
  717. // Calc Average Depth here.
  718. depth = -(v[0].y + v[1].y + v[2].y + v[3].y) / 4.0;
  719. }
  720. //---------------------------------------------------------------------------
  721. void PolygonQuadElement::draw (void)
  722. {
  723. //-------------------------------------
  724. // nothing else to do with this bUt
  725. // -gosDraw!
  726. //------------------------
  727. // Draw em!
  728. //--------------------------------
  729. //Set States for Software Renderer
  730. if (Environment.Renderer == 3)
  731. {
  732. gos_SetRenderState( gos_State_AlphaMode, gos_Alpha_OneZero);
  733. gos_SetRenderState( gos_State_ShadeMode, gos_ShadeGouraud);
  734. gos_SetRenderState( gos_State_MonoEnable, 1);
  735. gos_SetRenderState( gos_State_Perspective, 0);
  736. gos_SetRenderState( gos_State_Clipping, 0);
  737. gos_SetRenderState( gos_State_AlphaTest, 0);
  738. gos_SetRenderState( gos_State_Specular, 0);
  739. gos_SetRenderState( gos_State_Dither, 0);
  740. gos_SetRenderState( gos_State_TextureMapBlend, gos_BlendModulate);
  741. gos_SetRenderState( gos_State_Filter, gos_FilterNone);
  742. // gos_SetRenderState( gos_State_TextureAddress, gos_TextureClamp );
  743. gos_SetRenderState( gos_State_Texture, 0);
  744. }
  745. //--------------------------------
  746. //Set States for Hardware Renderer
  747. else
  748. {
  749. gos_SetRenderState( gos_State_AlphaMode, gos_Alpha_AlphaInvAlpha);
  750. gos_SetRenderState( gos_State_ShadeMode, gos_ShadeGouraud);
  751. gos_SetRenderState( gos_State_MonoEnable, 0);
  752. gos_SetRenderState( gos_State_Perspective, 1);
  753. gos_SetRenderState( gos_State_Clipping, 2);
  754. gos_SetRenderState( gos_State_AlphaTest, 1);
  755. gos_SetRenderState( gos_State_Specular, 0);
  756. gos_SetRenderState( gos_State_Dither, 1);
  757. gos_SetRenderState( gos_State_TextureMapBlend, gos_BlendModulate);
  758. gos_SetRenderState( gos_State_Filter, gos_FilterBiLinear);
  759. // gos_SetRenderState( gos_State_TextureAddress, gos_TextureClamp );
  760. gos_SetRenderState( gos_State_Texture, 0);
  761. gos_SetRenderState( gos_State_ZCompare, 1);
  762. gos_SetRenderState( gos_State_ZWrite, 1);
  763. }
  764. //----------------------------------------
  765. // Clip and draw top triangle
  766. gos_VERTEX gVertex[3];
  767. memcpy(gVertex,vertices,sizeof(gos_VERTEX) * 3);
  768. if ((gVertex[0].z >= 0.0f) &&
  769. (gVertex[0].z < 1.0f) &&
  770. (gVertex[1].z >= 0.0f) &&
  771. (gVertex[1].z < 1.0f) &&
  772. (gVertex[2].z >= 0.0f) &&
  773. (gVertex[2].z < 1.0f))
  774. {
  775. //-----------------------------------------------------------------------------
  776. // Reject Any triangle which has vertices off screeen in software for now.
  777. // Do real cliping in geometry layer for software and hardware that needs it!
  778. gos_DrawTriangles(gVertex, 3);
  779. }
  780. //---------------------------------------
  781. // Clip and draw Bottom Triangle
  782. gVertex[1].x = gVertex[2].x;
  783. gVertex[1].y = gVertex[2].y;
  784. gVertex[1].z = gVertex[2].z;
  785. gVertex[1].rhw = gVertex[2].rhw;
  786. gVertex[1].u = gVertex[2].u;
  787. gVertex[1].v = gVertex[2].v;
  788. gVertex[1].argb = gVertex[2].argb;
  789. gVertex[1].frgb = gVertex[2].frgb;
  790. gVertex[2].x = vertices[3].x;
  791. gVertex[2].y = vertices[3].y;
  792. gVertex[2].z = vertices[3].z;
  793. gVertex[2].rhw = vertices[3].rhw;
  794. gVertex[2].u = vertices[3].u;
  795. gVertex[2].v = vertices[3].v;
  796. gVertex[2].argb = vertices[3].argb;
  797. gVertex[2].frgb = vertices[3].frgb;
  798. if ((gVertex[0].z >= 0.0f) &&
  799. (gVertex[0].z < 1.0f) &&
  800. (gVertex[1].z >= 0.0f) &&
  801. (gVertex[1].z < 1.0f) &&
  802. (gVertex[2].z >= 0.0f) &&
  803. (gVertex[2].z < 1.0f))
  804. {
  805. //-----------------------------------------------------------------------------
  806. // Reject Any triangle which has vertices off screeen in software for now.
  807. // Do real cliping in geometry layer for software and hardware that needs it!
  808. gos_DrawTriangles(gVertex, 3);
  809. }
  810. }
  811. //---------------------------------------------------------------------------
  812. // class PolygonTriElement
  813. void PolygonTriElement::init (gos_VERTEX *v)
  814. {
  815. vertices[0] = v[0];
  816. vertices[1] = v[1];
  817. vertices[2] = v[2];
  818. //------------------------------------------
  819. // Calc Average Depth here.
  820. depth = -(v[0].y + v[1].y + v[2].y) / 3.0;
  821. }
  822. //---------------------------------------------------------------------------
  823. void PolygonTriElement::draw (void)
  824. {
  825. //-------------------------------------
  826. // nothing else to do with this bUt
  827. // -gosDraw!
  828. //------------------------
  829. // Draw em!
  830. //--------------------------------
  831. //Set States for Software Renderer
  832. if (Environment.Renderer == 3)
  833. {
  834. gos_SetRenderState( gos_State_AlphaMode, gos_Alpha_OneZero);
  835. gos_SetRenderState( gos_State_ShadeMode, gos_ShadeGouraud);
  836. gos_SetRenderState( gos_State_MonoEnable, 1);
  837. gos_SetRenderState( gos_State_Perspective, 0);
  838. gos_SetRenderState( gos_State_Clipping, 0);
  839. gos_SetRenderState( gos_State_AlphaTest, 0);
  840. gos_SetRenderState( gos_State_Specular, 0);
  841. gos_SetRenderState( gos_State_Dither, 0);
  842. gos_SetRenderState( gos_State_TextureMapBlend, gos_BlendModulate);
  843. gos_SetRenderState( gos_State_Filter, gos_FilterNone);
  844. // gos_SetRenderState( gos_State_TextureAddress, gos_TextureClamp );
  845. gos_SetRenderState( gos_State_Texture, 0);
  846. }
  847. //--------------------------------
  848. //Set States for Hardware Renderer
  849. else
  850. {
  851. gos_SetRenderState( gos_State_AlphaMode, gos_Alpha_OneZero);
  852. gos_SetRenderState( gos_State_ShadeMode, gos_ShadeGouraud);
  853. gos_SetRenderState( gos_State_MonoEnable, 0);
  854. gos_SetRenderState( gos_State_Perspective, 1);
  855. gos_SetRenderState( gos_State_Clipping, 2);
  856. gos_SetRenderState( gos_State_AlphaTest, 0);
  857. gos_SetRenderState( gos_State_Specular, 0);
  858. gos_SetRenderState( gos_State_Dither, 1);
  859. gos_SetRenderState( gos_State_TextureMapBlend, gos_BlendModulate);
  860. gos_SetRenderState( gos_State_Filter, gos_FilterBiLinear);
  861. // gos_SetRenderState( gos_State_TextureAddress, gos_TextureClamp );
  862. gos_SetRenderState( gos_State_Texture, 0);
  863. }
  864. //----------------------------------------
  865. // Clip and draw top triangle
  866. gos_VERTEX gVertex[3];
  867. memcpy(gVertex,vertices,sizeof(gos_VERTEX) * 3);
  868. if ((gVertex[0].z >= 0.0f) &&
  869. (gVertex[0].z < 1.0f) &&
  870. (gVertex[1].z >= 0.0f) &&
  871. (gVertex[1].z < 1.0f) &&
  872. (gVertex[2].z >= 0.0f) &&
  873. (gVertex[2].z < 1.0f))
  874. {
  875. //-----------------------------------------------------------------------------
  876. // Reject Any triangle which has vertices off screeen in software for now.
  877. // Do real cliping in geometry layer for software and hardware that needs it!
  878. gos_DrawTriangles(gVertex, 3);
  879. }
  880. }
  881. //---------------------------------------------------------------------------
  882. //class TexturedPolygonQuadElement : public PolygonQuadElement
  883. void TexturedPolygonQuadElement::init (gos_VERTEX *v, DWORD tHandle, bool writez, bool compz)
  884. {
  885. PolygonQuadElement::init(v);
  886. textureHandle = tHandle;
  887. zWrite = writez;
  888. zComp = compz;
  889. }
  890. //---------------------------------------------------------------------------
  891. void TexturedPolygonQuadElement::draw (void)
  892. {
  893. //-------------------------------------
  894. // nothing else to do with this bUt
  895. // -gosDraw!
  896. //------------------------
  897. // Draw em!
  898. //--------------------------------
  899. //Set States for Software Renderer
  900. if (Environment.Renderer == 3)
  901. {
  902. gos_SetRenderState( gos_State_AlphaMode, gos_Alpha_OneZero);
  903. gos_SetRenderState( gos_State_ShadeMode, gos_ShadeGouraud);
  904. gos_SetRenderState( gos_State_MonoEnable, 1);
  905. gos_SetRenderState( gos_State_Perspective, 0);
  906. gos_SetRenderState( gos_State_Clipping, 0);
  907. gos_SetRenderState( gos_State_AlphaTest, 0);
  908. gos_SetRenderState( gos_State_Specular, 0);
  909. gos_SetRenderState( gos_State_Dither, 0);
  910. gos_SetRenderState( gos_State_TextureMapBlend, gos_BlendModulate);
  911. gos_SetRenderState( gos_State_Filter, gos_FilterNone);
  912. gos_SetRenderState( gos_State_TextureAddress, gos_TextureClamp );
  913. gos_SetRenderState( gos_State_ZCompare, zComp);
  914. gos_SetRenderState( gos_State_ZWrite, zWrite);
  915. }
  916. //--------------------------------
  917. //Set States for Hardware Renderer
  918. else
  919. {
  920. gos_SetRenderState( gos_State_AlphaMode, gos_Alpha_AlphaInvAlpha);
  921. gos_SetRenderState( gos_State_ShadeMode, gos_ShadeGouraud);
  922. gos_SetRenderState( gos_State_MonoEnable, 0);
  923. gos_SetRenderState( gos_State_Perspective, 1);
  924. gos_SetRenderState( gos_State_Clipping, 2);
  925. gos_SetRenderState( gos_State_AlphaTest, 1);
  926. gos_SetRenderState( gos_State_Specular, 0);
  927. gos_SetRenderState( gos_State_Dither, 1);
  928. gos_SetRenderState( gos_State_TextureMapBlend, gos_BlendModulate);
  929. gos_SetRenderState( gos_State_Filter, gos_FilterBiLinear);
  930. gos_SetRenderState( gos_State_TextureAddress, gos_TextureClamp );
  931. gos_SetRenderState( gos_State_ZCompare, zComp);
  932. gos_SetRenderState( gos_State_ZWrite, zWrite);
  933. }
  934. if (textureHandle == 0xffffffff)
  935. {
  936. gos_SetRenderState( gos_State_Texture, 0 );
  937. gos_SetRenderState( gos_State_Filter, gos_FilterNone );
  938. }
  939. else
  940. gos_SetRenderState( gos_State_Texture, textureHandle );
  941. //----------------------------------------
  942. // Clip and draw top triangle
  943. gos_VERTEX gVertex[3];
  944. memcpy(gVertex,vertices,sizeof(gos_VERTEX) * 3);
  945. if ((gVertex[0].z >= 0.0f) &&
  946. (gVertex[0].z < 1.0f) &&
  947. (gVertex[1].z >= 0.0f) &&
  948. (gVertex[1].z < 1.0f) &&
  949. (gVertex[2].z >= 0.0f) &&
  950. (gVertex[2].z < 1.0f))
  951. {
  952. //-----------------------------------------------------------------------------
  953. // Reject Any triangle which has vertices off screeen in software for now.
  954. // Do real cliping in geometry layer for software and hardware that needs it!
  955. gos_DrawTriangles(gVertex, 3);
  956. }
  957. //---------------------------------------
  958. // Clip and draw Bottom Triangle
  959. gVertex[1].x = gVertex[2].x;
  960. gVertex[1].y = gVertex[2].y;
  961. gVertex[1].z = gVertex[2].z;
  962. gVertex[1].rhw = gVertex[2].rhw;
  963. gVertex[1].u = gVertex[2].u;
  964. gVertex[1].v = gVertex[2].v;
  965. gVertex[1].argb = gVertex[2].argb;
  966. gVertex[1].frgb = gVertex[2].frgb;
  967. gVertex[2].x = vertices[3].x;
  968. gVertex[2].y = vertices[3].y;
  969. gVertex[2].z = vertices[3].z;
  970. gVertex[2].rhw = vertices[3].rhw;
  971. gVertex[2].u = vertices[3].u;
  972. gVertex[2].v = vertices[3].v;
  973. gVertex[2].argb = vertices[3].argb;
  974. gVertex[2].frgb = vertices[3].frgb;
  975. if ((gVertex[0].z >= 0.0f) &&
  976. (gVertex[0].z < 1.0f) &&
  977. (gVertex[1].z >= 0.0f) &&
  978. (gVertex[1].z < 1.0f) &&
  979. (gVertex[2].z >= 0.0f) &&
  980. (gVertex[2].z < 1.0f))
  981. {
  982. //-----------------------------------------------------------------------------
  983. // Reject Any triangle which has vertices off screeen in software for now.
  984. // Do real cliping in geometry layer for software and hardware that needs it!
  985. gos_DrawTriangles(gVertex, 3);
  986. }
  987. }
  988. //---------------------------------------------------------------------------
  989. //class TexturedPolygonTriElement : public PolygonTriElement
  990. void TexturedPolygonTriElement::init (gos_VERTEX *v, DWORD tHandle)
  991. {
  992. PolygonTriElement::init(v);
  993. textureHandle = tHandle;
  994. }
  995. //---------------------------------------------------------------------------
  996. void TexturedPolygonTriElement::draw (void)
  997. {
  998. //-------------------------------------
  999. // nothing else to do with this bUt
  1000. // -gosDraw!
  1001. //------------------------
  1002. // Draw em!
  1003. //--------------------------------
  1004. //Set States for Software Renderer
  1005. if (Environment.Renderer == 3)
  1006. {
  1007. gos_SetRenderState( gos_State_AlphaMode, gos_Alpha_OneZero);
  1008. gos_SetRenderState( gos_State_ShadeMode, gos_ShadeGouraud);
  1009. gos_SetRenderState( gos_State_MonoEnable, 1);
  1010. gos_SetRenderState( gos_State_Perspective, 0);
  1011. gos_SetRenderState( gos_State_Clipping, 0);
  1012. gos_SetRenderState( gos_State_AlphaTest, 0);
  1013. gos_SetRenderState( gos_State_Specular, 0);
  1014. gos_SetRenderState( gos_State_Dither, 0);
  1015. gos_SetRenderState( gos_State_TextureMapBlend, gos_BlendModulate);
  1016. gos_SetRenderState( gos_State_Filter, gos_FilterNone);
  1017. gos_SetRenderState( gos_State_TextureAddress, gos_TextureClamp );
  1018. }
  1019. //--------------------------------
  1020. //Set States for Hardware Renderer
  1021. else
  1022. {
  1023. gos_SetRenderState( gos_State_AlphaMode, gos_Alpha_OneZero);
  1024. gos_SetRenderState( gos_State_ShadeMode, gos_ShadeGouraud);
  1025. gos_SetRenderState( gos_State_MonoEnable, 0);
  1026. gos_SetRenderState( gos_State_Perspective, 1);
  1027. gos_SetRenderState( gos_State_Clipping, 2);
  1028. gos_SetRenderState( gos_State_AlphaTest, 0);
  1029. gos_SetRenderState( gos_State_Specular, 0);
  1030. gos_SetRenderState( gos_State_Dither, 1);
  1031. gos_SetRenderState( gos_State_TextureMapBlend, gos_BlendModulate);
  1032. gos_SetRenderState( gos_State_Filter, gos_FilterBiLinear);
  1033. gos_SetRenderState( gos_State_TextureAddress, gos_TextureClamp );
  1034. }
  1035. if (textureHandle == 0xffffffff)
  1036. {
  1037. gos_SetRenderState( gos_State_Texture, 0 );
  1038. gos_SetRenderState( gos_State_Filter, gos_FilterNone );
  1039. }
  1040. else
  1041. gos_SetRenderState( gos_State_Texture, textureHandle );
  1042. //----------------------------------------
  1043. // Clip and draw top triangle
  1044. gos_VERTEX gVertex[3];
  1045. memcpy(gVertex,vertices,sizeof(gos_VERTEX) * 3);
  1046. if ((gVertex[0].z >= 0.0f) &&
  1047. (gVertex[0].z < 1.0f) &&
  1048. (gVertex[1].z >= 0.0f) &&
  1049. (gVertex[1].z < 1.0f) &&
  1050. (gVertex[2].z >= 0.0f) &&
  1051. (gVertex[2].z < 1.0f))
  1052. {
  1053. //-----------------------------------------------------------------------------
  1054. // Reject Any triangle which has vertices off screeen in software for now.
  1055. // Do real cliping in geometry layer for software and hardware that needs it!
  1056. gos_DrawTriangles(gVertex, 3);
  1057. }
  1058. }
  1059. //---------------------------------------------------------------------------