gfxDevice.h 42 KB

1234567891011121314151617181920212223242526272829303132333435363738394041424344454647484950515253545556575859606162636465666768697071727374757677787980818283848586878889909192939495969798991001011021031041051061071081091101111121131141151161171181191201211221231241251261271281291301311321331341351361371381391401411421431441451461471481491501511521531541551561571581591601611621631641651661671681691701711721731741751761771781791801811821831841851861871881891901911921931941951961971981992002012022032042052062072082092102112122132142152162172182192202212222232242252262272282292302312322332342352362372382392402412422432442452462472482492502512522532542552562572582592602612622632642652662672682692702712722732742752762772782792802812822832842852862872882892902912922932942952962972982993003013023033043053063073083093103113123133143153163173183193203213223233243253263273283293303313323333343353363373383393403413423433443453463473483493503513523533543553563573583593603613623633643653663673683693703713723733743753763773783793803813823833843853863873883893903913923933943953963973983994004014024034044054064074084094104114124134144154164174184194204214224234244254264274284294304314324334344354364374384394404414424434444454464474484494504514524534544554564574584594604614624634644654664674684694704714724734744754764774784794804814824834844854864874884894904914924934944954964974984995005015025035045055065075085095105115125135145155165175185195205215225235245255265275285295305315325335345355365375385395405415425435445455465475485495505515525535545555565575585595605615625635645655665675685695705715725735745755765775785795805815825835845855865875885895905915925935945955965975985996006016026036046056066076086096106116126136146156166176186196206216226236246256266276286296306316326336346356366376386396406416426436446456466476486496506516526536546556566576586596606616626636646656666676686696706716726736746756766776786796806816826836846856866876886896906916926936946956966976986997007017027037047057067077087097107117127137147157167177187197207217227237247257267277287297307317327337347357367377387397407417427437447457467477487497507517527537547557567577587597607617627637647657667677687697707717727737747757767777787797807817827837847857867877887897907917927937947957967977987998008018028038048058068078088098108118128138148158168178188198208218228238248258268278288298308318328338348358368378388398408418428438448458468478488498508518528538548558568578588598608618628638648658668678688698708718728738748758768778788798808818828838848858868878888898908918928938948958968978988999009019029039049059069079089099109119129139149159169179189199209219229239249259269279289299309319329339349359369379389399409419429439449459469479489499509519529539549559569579589599609619629639649659669679689699709719729739749759769779789799809819829839849859869879889899909919929939949959969979989991000100110021003100410051006100710081009101010111012101310141015101610171018101910201021102210231024102510261027102810291030103110321033103410351036103710381039104010411042104310441045104610471048104910501051105210531054105510561057105810591060106110621063106410651066106710681069107010711072107310741075107610771078107910801081108210831084108510861087108810891090109110921093109410951096109710981099110011011102110311041105110611071108110911101111111211131114111511161117111811191120112111221123112411251126112711281129113011311132113311341135113611371138113911401141114211431144114511461147114811491150115111521153115411551156115711581159116011611162116311641165116611671168116911701171117211731174117511761177117811791180118111821183118411851186118711881189119011911192119311941195
  1. //-----------------------------------------------------------------------------
  2. // Copyright (c) 2012 GarageGames, LLC
  3. //
  4. // Permission is hereby granted, free of charge, to any person obtaining a copy
  5. // of this software and associated documentation files (the "Software"), to
  6. // deal in the Software without restriction, including without limitation the
  7. // rights to use, copy, modify, merge, publish, distribute, sublicense, and/or
  8. // sell copies of the Software, and to permit persons to whom the Software is
  9. // furnished to do so, subject to the following conditions:
  10. //
  11. // The above copyright notice and this permission notice shall be included in
  12. // all copies or substantial portions of the Software.
  13. //
  14. // THE SOFTWARE IS PROVIDED "AS IS", WITHOUT WARRANTY OF ANY KIND, EXPRESS OR
  15. // IMPLIED, INCLUDING BUT NOT LIMITED TO THE WARRANTIES OF MERCHANTABILITY,
  16. // FITNESS FOR A PARTICULAR PURPOSE AND NONINFRINGEMENT. IN NO EVENT SHALL THE
  17. // AUTHORS OR COPYRIGHT HOLDERS BE LIABLE FOR ANY CLAIM, DAMAGES OR OTHER
  18. // LIABILITY, WHETHER IN AN ACTION OF CONTRACT, TORT OR OTHERWISE, ARISING
  19. // FROM, OUT OF OR IN CONNECTION WITH THE SOFTWARE OR THE USE OR OTHER DEALINGS
  20. // IN THE SOFTWARE.
  21. //-----------------------------------------------------------------------------
  22. #ifndef _GFXDEVICE_H_
  23. #define _GFXDEVICE_H_
  24. #ifndef _GFXADAPTER_H_
  25. #include "gfx/gfxAdapter.h"
  26. #endif
  27. #ifndef _GFXTARGET_H_
  28. #include "gfx/gfxTarget.h"
  29. #endif
  30. #ifndef _GFXVERTEXBUFFER_H_
  31. #include "gfx/gfxVertexBuffer.h"
  32. #endif
  33. #ifndef _GFXSTATEBLOCK_H_
  34. #include "gfx/gfxStateBlock.h"
  35. #endif
  36. #ifndef _GFXSHADER_H_
  37. #include "gfx/gfxShader.h"
  38. #endif
  39. #ifndef _GFXCUBEMAP_H_
  40. #include "gfx/gfxCubemap.h"
  41. #endif
  42. #ifndef _TDICTIONARY_H_
  43. #include "core/util/tDictionary.h"
  44. #endif
  45. #ifndef _TSIGNAL_H_
  46. #include "core/util/tSignal.h"
  47. #endif
  48. #ifndef _GFXDEVICESTATISTICS_H_
  49. #include "gfx/gfxDeviceStatistics.h"
  50. #endif
  51. #ifndef _MATHUTIL_FRUSTUM_H_
  52. #include "math/util/frustum.h"
  53. #endif
  54. #ifndef _PLATFORM_PLATFORMTIMER_H_
  55. #include "platform/platformTimer.h"
  56. #endif
  57. class FontRenderBatcher;
  58. class GFont;
  59. class GFXCardProfiler;
  60. class GFXDrawUtil;
  61. class GFXFence;
  62. class GFXOcclusionQuery;
  63. class GFXPrimitiveBuffer;
  64. class GFXShader;
  65. class GFXStateBlock;
  66. class GFXShaderConstBuffer;
  67. class GFXTextureManager;
  68. // Global macro
  69. #define GFX GFXDevice::get()
  70. #define MAX_MRT_TARGETS 4
  71. //-----------------------------------------------------------------------------
  72. /// GFXDevice is the TSE graphics interface layer. This allows the TSE to
  73. /// do many things, such as use multiple render devices for multi-head systems,
  74. /// and allow a game to render in DirectX 9, OpenGL or any other API which has
  75. /// a GFX implementation seamlessly. There are many concepts in GFX device which
  76. /// may not be familiar to you, especially if you have not used DirectX.
  77. /// @n
  78. /// <b>Buffers</b>
  79. /// There are three types of buffers in GFX: vertex, index and primitive. Please
  80. /// note that index buffers are not accessable outside the GFX layer, they are wrapped
  81. /// by primitive buffers. Primitive buffers will be explained in detail later.
  82. /// Buffers are allocated and deallocated using their associated allocXBuffer and
  83. /// freeXBuffer methods on the device. When a buffer is allocated you pass in a
  84. /// pointer to, depending on the buffer, a vertex type pointer or a U16 pointer.
  85. /// During allocation, this pointer is set to the address of where you should
  86. /// copy in the information for this buffer. You must the tell the GFXDevice
  87. /// that the information is in, and it should prepare the buffer for use by calling
  88. /// the prepare method on it. Dynamic vertex buffer example:
  89. /// @code
  90. /// GFXVertexP *verts; // Making a buffer containing verticies with only position
  91. ///
  92. /// // Allocate a dynamic vertex buffer to hold 3 vertices and use *verts as the location to copy information into
  93. /// GFXVertexBufferHandle vb = GFX->allocVertexBuffer( 3, &verts, true );
  94. ///
  95. /// // Now set the information, we're making a triangle
  96. /// verts[0].point = Point3F( 200.f, 200.f, 0.f );
  97. /// verts[1].point = Point3F( 200.f, 400.f, 0.f );
  98. /// verts[2].point = Point3F( 400.f, 200.f, 0.f );
  99. ///
  100. /// // Tell GFX that the information is in and it should be made ready for use
  101. /// // Note that nothing is done with verts, this should not and MUST NOT be deleted
  102. /// // stored, or otherwise used after prepare is called.
  103. /// GFX->prepare( vb );
  104. ///
  105. /// // Because this is a dynamic vertex buffer, it is only assured to be valid until someone
  106. /// // else allocates a dynamic vertex buffer, so we will render it now
  107. /// GFX->setVertexBuffer( vb );
  108. /// GFX->drawPrimitive( GFXTriangleStrip, 0, 1 );
  109. ///
  110. /// // Now because this is a dynamic vertex buffer it MUST NOT BE FREED you are only
  111. /// // given a handle to a vertex buffer which belongs to the device
  112. /// @endcode
  113. ///
  114. /// To use a static vertex buffer, it is very similar, this is an example using a
  115. /// static primitive buffer:
  116. /// @n
  117. /// This takes place inside a constructor for a class which has a member variable
  118. /// called mPB which is the primitive buffer for the class instance.
  119. /// @code
  120. /// U16 *idx; // This is going to be where to write indices
  121. /// GFXPrimitiveInfo *primitiveInfo; // This will be where to write primitive information
  122. ///
  123. /// // Allocate a primitive buffer with 4 indices, and 1 primitive described for use
  124. /// mPB = GFX->allocPrimitiveBuffer( 4, &idx, 1, &primitiveInfo );
  125. ///
  126. /// // Write the index information, this is going to be for the outline of a triangle using
  127. /// // a line strip
  128. /// idx[0] = 0;
  129. /// idx[1] = 1;
  130. /// idx[2] = 2;
  131. /// idx[3] = 0;
  132. ///
  133. /// // Write the information for the primitive
  134. /// primitiveInfo->indexStart = 0; // Starting with index 0
  135. /// primitiveInfo->minVertex = 0; // The minimum vertex index is 0
  136. /// primitiveInfo->maxVertex = 3; // The maximum vertex index is 3
  137. /// primitiveInfo->primitiveCount = 3; // There are 3 lines we are drawing
  138. /// primitiveInfo->type = GFXLineStrip; // This primitive info describes a line strip
  139. /// @endcode
  140. /// The following code takes place in the destructor for the same class
  141. /// @code
  142. /// // Because this is a static buffer it's our responsibility to free it when we are done
  143. /// GFX->freePrimitiveBuffer( mPB );
  144. /// @endcode
  145. /// This last bit takes place in the rendering function for the class
  146. /// @code
  147. /// // You need to set a vertex buffer as well, primitive buffers contain indexing
  148. /// // information, not vertex information. This is so you could have, say, a static
  149. /// // vertex buffer, and a dynamic primitive buffer.
  150. ///
  151. /// // This sets the primitive buffer to the static buffer we allocated in the constructor
  152. /// GFX->setPrimitiveBuffer( mPB );
  153. ///
  154. /// // Draw the first primitive contained in the set primitive buffer, our primitive buffer
  155. /// // has only one primitive, so we could also technically call GFX->drawPrimitives(); and
  156. /// // get the same result.
  157. /// GFX->drawPrimitive( 0 );
  158. /// @endcode
  159. /// If you need any more examples on how to use these buffers please see the rest of the engine.
  160. /// @n
  161. /// <b>Primitive Buffers</b>
  162. /// @n
  163. /// Primitive buffers wrap and extend the concept of index buffers. The purpose of a primitive
  164. /// buffer is to let objects store all information they have to render their primitives in
  165. /// a central place. Say that a shape is made up of triangle strips and triangle fans, it would
  166. /// still have only one primitive buffer which contained primitive information for each strip
  167. /// and fan. It could then draw itself with one call.
  168. ///
  169. /// TO BE FINISHED LATER
  170. class GFXDevice
  171. {
  172. private:
  173. friend class GFXInit;
  174. friend class GFXPrimitiveBufferHandle;
  175. friend class GFXVertexBufferHandleBase;
  176. friend class GFXTextureObject;
  177. friend class GFXTexHandle;
  178. friend class GFXVertexFormat;
  179. friend class GFXTestFullscreenToggle;
  180. friend class TestGFXTextureCube;
  181. friend class TestGFXRenderTargetCube;
  182. friend class TestGFXRenderTargetStack;
  183. friend class GFXResource;
  184. friend class LightMatInstance; // For stencil interface
  185. //--------------------------------------------------------------------------
  186. // Static GFX interface
  187. //--------------------------------------------------------------------------
  188. public:
  189. enum GFXDeviceEventType
  190. {
  191. /// The device has been created, but not initialized
  192. deCreate,
  193. /// The device has been initialized
  194. deInit,
  195. /// The device is about to be destroyed.
  196. deDestroy,
  197. /// The device has started rendering a frame
  198. deStartOfFrame,
  199. /// The device is about to finish rendering a frame
  200. deEndOfFrame,
  201. /// The device has rendered a frame and ended the scene
  202. dePostFrame,
  203. /// The device has started rendering a frame's field (such as for side-by-side rendering)
  204. deStartOfField,
  205. /// The device is about to finish rendering a frame's field
  206. deEndOfField,
  207. };
  208. typedef Signal <bool (GFXDeviceEventType)> DeviceEventSignal;
  209. static DeviceEventSignal& getDeviceEventSignal();
  210. static GFXDevice *get() { return smGFXDevice; }
  211. static void initConsole();
  212. static bool destroy();
  213. static bool devicePresent() { return (smGFXDevice && smGFXDevice->getAdapterType() != NullDevice); }
  214. private:
  215. /// @name Device management variables
  216. /// @{
  217. static GFXDevice * smGFXDevice; ///< Global GFXDevice
  218. /// @}
  219. //--------------------------------------------------------------------------
  220. // Core GFX interface
  221. //--------------------------------------------------------------------------
  222. public:
  223. enum GFXDeviceRenderStyles
  224. {
  225. RS_Standard = 0,
  226. RS_StereoSideBySide = (1<<0), // Render into current Render Target side-by-side
  227. };
  228. enum GFXDeviceLimits
  229. {
  230. NumStereoPorts = 2
  231. };
  232. private:
  233. /// Adapter for this device.
  234. GFXAdapter mAdapter;
  235. protected:
  236. /// List of valid video modes for this device.
  237. Vector<GFXVideoMode> mVideoModes;
  238. /// The CardProfiler for this device.
  239. GFXCardProfiler *mCardProfiler;
  240. /// Head of the resource list.
  241. ///
  242. /// @see GFXResource
  243. GFXResource *mResourceListHead;
  244. /// Set once the device is active.
  245. bool mCanCurrentlyRender;
  246. /// Set if we're in a mode where we want rendering to occur.
  247. bool mAllowRender;
  248. /// The style of rendering that is to be performed, based on GFXDeviceRenderStyles
  249. U32 mCurrentRenderStyle;
  250. /// The current projection offset. May be used during side-by-side rendering, for example.
  251. Point2F mCurrentProjectionOffset;
  252. /// Eye offset used when using a stereo rendering style
  253. Point3F mStereoEyeOffset[NumStereoPorts];
  254. MatrixF mStereoEyeTransforms[NumStereoPorts];
  255. MatrixF mInverseStereoEyeTransforms[NumStereoPorts];
  256. /// Fov port settings
  257. FovPort mFovPorts[NumStereoPorts];
  258. /// Destination viewports for stereo rendering
  259. RectI mStereoViewports[NumStereoPorts];
  260. /// Destination targets for stereo rendering
  261. GFXTextureTarget* mStereoTargets[NumStereoPorts];
  262. /// This will allow querying to see if a device is initialized and ready to
  263. /// have operations performed on it.
  264. bool mInitialized;
  265. bool mReset;
  266. /// This is called before this, or any other device, is deleted in the global destroy()
  267. /// method. It allows the device to clean up anything while everything is still valid.
  268. virtual void preDestroy();
  269. /// Set the adapter that this device is using. For use by GFXInit::createDevice only.
  270. virtual void setAdapter(const GFXAdapter& adapter) { mAdapter = adapter; }
  271. /// Notify GFXDevice that we are initialized
  272. virtual void deviceInited();
  273. public:
  274. GFXDevice();
  275. virtual ~GFXDevice();
  276. /// Initialize this GFXDevice, optionally specifying a platform window to
  277. /// bind to.
  278. virtual void init( const GFXVideoMode &mode, PlatformWindow *window = NULL ) = 0;
  279. /// Returns true if the scene has begun and its
  280. /// safe to make rendering calls.
  281. /// @see beginScene
  282. /// @see endScene
  283. bool canCurrentlyRender() const { return mCanCurrentlyRender; }
  284. bool recentlyReset(){ return mReset; }
  285. void beginReset(){ mReset = true; }
  286. void finalizeReset(){ mReset = false; }
  287. void setAllowRender( bool render ) { mAllowRender = render; }
  288. inline bool allowRender() const { return mAllowRender; }
  289. /// Retrieve the current rendering style based on GFXDeviceRenderStyles
  290. U32 getCurrentRenderStyle() const { return mCurrentRenderStyle; }
  291. /// Set the current rendering style, based on GFXDeviceRenderStyles
  292. void setCurrentRenderStyle(U32 style) { mCurrentRenderStyle = style; }
  293. /// Set the current projection offset used during stereo rendering
  294. const Point2F& getCurrentProjectionOffset() { return mCurrentProjectionOffset; }
  295. /// Get the current projection offset used during stereo rendering
  296. void setCurrentProjectionOffset(const Point2F& offset) { mCurrentProjectionOffset = offset; }
  297. /// Get the current eye offset used during stereo rendering
  298. const Point3F* getStereoEyeOffsets() { return mStereoEyeOffset; }
  299. const MatrixF* getStereoEyeTransforms() { return mStereoEyeTransforms; }
  300. const MatrixF* getInverseStereoEyeTransforms() { return mInverseStereoEyeTransforms; }
  301. /// Set the current eye offset used during stereo rendering
  302. void setStereoEyeOffsets(Point3F *offsets) { dMemcpy(mStereoEyeOffset, offsets, sizeof(Point3F) * NumStereoPorts); }
  303. void setStereoEyeTransforms(MatrixF *transforms) { dMemcpy(mStereoEyeTransforms, transforms, sizeof(mStereoEyeTransforms)); dMemcpy(mInverseStereoEyeTransforms, transforms, sizeof(mInverseStereoEyeTransforms)); mInverseStereoEyeTransforms[0].inverse(); mInverseStereoEyeTransforms[1].inverse(); }
  304. /// Set the current eye offset used during stereo rendering. Assumes NumStereoPorts are available.
  305. void setStereoFovPort(const FovPort *ports) { dMemcpy(mFovPorts, ports, sizeof(mFovPorts)); }
  306. /// Get the current eye offset used during stereo rendering
  307. const FovPort* getStereoFovPort() { return mFovPorts; }
  308. /// Sets stereo viewports
  309. void setSteroViewports(const RectI *ports) { dMemcpy(mStereoViewports, ports, sizeof(RectI) * NumStereoPorts); }
  310. /// Sets stereo render targets
  311. void setStereoTargets(GFXTextureTarget **targets) { mStereoTargets[0] = targets[0]; mStereoTargets[1] = targets[1]; }
  312. RectI* getStereoViewports() { return mStereoViewports; }
  313. /// Activates a stereo render target, setting the correct viewport to render eye contents.
  314. /// If eyeId is -1, set a viewport encompassing the entire size of the render targets.
  315. void activateStereoTarget(S32 eyeId)
  316. {
  317. if (eyeId == -1)
  318. {
  319. if (mStereoTargets[0])
  320. {
  321. setActiveRenderTarget(mStereoTargets[0], true);
  322. }
  323. }
  324. else
  325. {
  326. if (mStereoTargets[eyeId])
  327. {
  328. setActiveRenderTarget(mStereoTargets[eyeId], false);
  329. }
  330. setViewport(mStereoViewports[eyeId]);
  331. }
  332. }
  333. GFXCardProfiler* getCardProfiler() const { return mCardProfiler; }
  334. /// Returns active graphics adapter type.
  335. virtual GFXAdapterType getAdapterType()=0;
  336. /// Returns the Adapter that was used to create this device
  337. virtual const GFXAdapter& getAdapter() { return mAdapter; }
  338. /// @}
  339. /// @name Debug Methods
  340. /// @{
  341. virtual void enterDebugEvent(ColorI color, const char *name) = 0;
  342. virtual void leaveDebugEvent() = 0;
  343. virtual void setDebugMarker(ColorI color, const char *name) = 0;
  344. /// @}
  345. /// @name Resource debug methods
  346. /// @{
  347. /// Lists how many of each GFX resource (e.g. textures, texture targets, shaders, etc.) GFX is aware of
  348. /// @param unflaggedOnly If true, this method only counts unflagged resources
  349. virtual void listResources(bool unflaggedOnly);
  350. /// Flags all resources GFX is currently aware of
  351. virtual void flagCurrentResources();
  352. /// Clears the flag on all resources GFX is currently aware of
  353. virtual void clearResourceFlags();
  354. /// Dumps a description of the specified resource types to the console
  355. /// @param resNames A string of space separated class names (e.g. "GFXTextureObject GFXTextureTarget GFXShader")
  356. /// to describe to the console
  357. /// @param file A path to the file to write the descriptions to. If it is NULL or "", descriptions are
  358. /// written to the console.
  359. /// @param unflaggedOnly If true, this method only counts unflagged resources
  360. /// @note resNames is case sensitive because there is no dStristr function.
  361. virtual void describeResources(const char* resName, const char* file, bool unflaggedOnly);
  362. /// Returns the current GFXDeviceStatistics, stats are cleared every ::beginScene call.
  363. GFXDeviceStatistics* getDeviceStatistics() { return &mDeviceStatistics; }
  364. protected:
  365. GFXDeviceStatistics mDeviceStatistics;
  366. /// This is a helper method for describeResourcesToFile. It walks through the
  367. /// GFXResource list and sorts it by item type, putting the resources into the proper vector.
  368. /// @see describeResources
  369. virtual void fillResourceVectors(const char* resNames, bool unflaggedOnly, Vector<GFXResource*> &textureObjects,
  370. Vector<GFXResource*> &textureTargets, Vector<GFXResource*> &windowTargets, Vector<GFXResource*> &vertexBuffers,
  371. Vector<GFXResource*> &primitiveBuffers, Vector<GFXResource*> &fences, Vector<GFXResource*> &cubemaps,
  372. Vector<GFXResource*> &shaders, Vector<GFXResource*> &stateblocks);
  373. public:
  374. /// @}
  375. /// @name Video Mode Functions
  376. /// @{
  377. /// Enumerates the supported video modes of the device
  378. virtual void enumerateVideoModes() = 0;
  379. /// Returns the video mode list.
  380. /// @see GFXVideoMode
  381. const Vector<GFXVideoMode>* const getVideoModeList() const { return &mVideoModes; }
  382. /// Returns the first format from the list which meets all
  383. /// the criteria of the texture profile and query options.
  384. virtual GFXFormat selectSupportedFormat(GFXTextureProfile *profile,
  385. const Vector<GFXFormat> &formats, bool texture, bool mustblend, bool mustfilter) = 0;
  386. /// @}
  387. //-----------------------------------------------------------------------------
  388. protected:
  389. /// @name State tracking variables
  390. /// @{
  391. /// Set if ANY state is dirty, including matrices or primitive buffers.
  392. bool mStateDirty;
  393. enum TexDirtyType
  394. {
  395. GFXTDT_Normal,
  396. GFXTDT_Cube
  397. };
  398. GFXTexHandle mCurrentTexture[TEXTURE_STAGE_COUNT];
  399. GFXTexHandle mNewTexture[TEXTURE_STAGE_COUNT];
  400. GFXCubemapHandle mCurrentCubemap[TEXTURE_STAGE_COUNT];
  401. GFXCubemapHandle mNewCubemap[TEXTURE_STAGE_COUNT];
  402. TexDirtyType mTexType[TEXTURE_STAGE_COUNT];
  403. bool mTextureDirty[TEXTURE_STAGE_COUNT];
  404. bool mTexturesDirty;
  405. // This maps a GFXStateBlockDesc hash value to a GFXStateBlockRef
  406. typedef Map<U32, GFXStateBlockRef> StateBlockMap;
  407. StateBlockMap mCurrentStateBlocks;
  408. // This tracks whether or not our state block is dirty.
  409. bool mStateBlockDirty;
  410. GFXStateBlockRef mCurrentStateBlock;
  411. GFXStateBlockRef mNewStateBlock;
  412. GFXShaderConstBuffer *mCurrentShaderConstBuffer;
  413. /// A global forced wireframe mode.
  414. static bool smWireframe;
  415. /// The global vsync state.
  416. static bool smDisableVSync;
  417. /// The forced shader model version if non-zero.
  418. static F32 smForcedPixVersion;
  419. /// Disable all hardware occlusion queries causing
  420. /// them to return only the visibile state.
  421. static bool smDisableOcclusionQuery;
  422. /// @}
  423. /// @name Light Tracking
  424. /// @{
  425. GFXLightInfo mCurrentLight[LIGHT_STAGE_COUNT];
  426. bool mCurrentLightEnable[LIGHT_STAGE_COUNT];
  427. bool mLightDirty[LIGHT_STAGE_COUNT];
  428. bool mLightsDirty;
  429. ColorF mGlobalAmbientColor;
  430. bool mGlobalAmbientColorDirty;
  431. /// @}
  432. /// @name Fixed function material tracking
  433. /// @{
  434. GFXLightMaterial mCurrentLightMaterial;
  435. bool mLightMaterialDirty;
  436. /// @}
  437. /// @name Bitmap modulation and color stack
  438. /// @{
  439. ///
  440. /// @}
  441. /// @see getDeviceSwizzle32
  442. Swizzle<U8, 4> *mDeviceSwizzle32;
  443. /// @see getDeviceSwizzle24
  444. Swizzle<U8, 3> *mDeviceSwizzle24;
  445. //-----------------------------------------------------------------------------
  446. /// @name Matrix managing variables
  447. /// @{
  448. ///
  449. MatrixF mWorldMatrix[WORLD_STACK_MAX];
  450. bool mWorldMatrixDirty;
  451. S32 mWorldStackSize;
  452. MatrixF mProjectionMatrix;
  453. bool mProjectionMatrixDirty;
  454. MatrixF mViewMatrix;
  455. bool mViewMatrixDirty;
  456. MatrixF mTextureMatrix[TEXTURE_STAGE_COUNT];
  457. bool mTextureMatrixDirty[TEXTURE_STAGE_COUNT];
  458. bool mTextureMatrixCheckDirty;
  459. /// @}
  460. /// @name Current frustum planes
  461. /// @{
  462. ///
  463. Frustum mFrustum;
  464. //-----------------------------------------------------------------------------
  465. /// @name Stateblock functions
  466. /// @{
  467. /// Called by GFXDevice to create a device specific stateblock
  468. virtual GFXStateBlockRef createStateBlockInternal(const GFXStateBlockDesc& desc) = 0;
  469. /// Called by GFXDevice to actually set a stateblock.
  470. /// @param force If true, set all states
  471. virtual void setStateBlockInternal(GFXStateBlock* block, bool force) = 0;
  472. /// @}
  473. /// Called by base GFXDevice to actually set a const buffer
  474. virtual void setShaderConstBufferInternal(GFXShaderConstBuffer* buffer) = 0;
  475. virtual void setTextureInternal(U32 textureUnit, const GFXTextureObject*texture) = 0;
  476. virtual void setLightInternal(U32 lightStage, const GFXLightInfo light, bool lightEnable) = 0;
  477. virtual void setGlobalAmbientInternal(ColorF color) = 0;
  478. virtual void setLightMaterialInternal(const GFXLightMaterial mat) = 0;
  479. virtual bool beginSceneInternal() = 0;
  480. virtual void endSceneInternal() = 0;
  481. /// @name State Initialization.
  482. /// @{
  483. /// State initialization. This MUST BE CALLED in setVideoMode after the device
  484. /// is created.
  485. virtual void initStates() = 0;
  486. /// @}
  487. //-----------------------------------------------------------------------------
  488. /// This function must be implemented differently per
  489. /// API and it should set ONLY the current matrix.
  490. /// For example, in OpenGL, there should be NO matrix stack
  491. /// activity, all the stack stuff is managed in the GFX layer.
  492. ///
  493. /// OpenGL does not have separate world and
  494. /// view matrices. It has ModelView which is world * view.
  495. /// You must take this into consideration.
  496. ///
  497. /// @param mtype Which matrix to set, world/view/projection
  498. /// @param mat Matrix to assign
  499. virtual void setMatrix( GFXMatrixType mtype, const MatrixF &mat ) = 0;
  500. //-----------------------------------------------------------------------------
  501. protected:
  502. /// @name Buffer Allocation
  503. /// These methods are implemented per-device and are called by the GFX layer
  504. /// when a user calls an alloc
  505. ///
  506. /// @note Primitive Buffers are NOT implemented per device, they wrap index buffers
  507. /// @{
  508. /// This allocates a vertex buffer and returns a pointer to the allocated buffer.
  509. /// This function should not be called directly - rather it should be used by
  510. /// the GFXVertexBufferHandle class.
  511. virtual GFXVertexBuffer *allocVertexBuffer( U32 numVerts,
  512. const GFXVertexFormat *vertexFormat,
  513. U32 vertSize,
  514. GFXBufferType bufferType,
  515. void* data = NULL ) = 0;
  516. /// Called from GFXVertexFormat to allocate the hardware
  517. /// specific vertex declaration for rendering.
  518. virtual GFXVertexDecl* allocVertexDecl( const GFXVertexFormat *vertexFormat ) = 0;
  519. /// Sets the current vertex declaration on the device.
  520. virtual void setVertexDecl( const GFXVertexDecl *decl ) = 0;
  521. /// Sets the vertex buffer on the device.
  522. virtual void setVertexStream( U32 stream, GFXVertexBuffer *buffer ) = 0;
  523. /// Set the vertex stream frequency on the device.
  524. virtual void setVertexStreamFrequency( U32 stream, U32 frequency ) = 0;
  525. /// The maximum number of supported vertex streams which
  526. /// may be more than the device supports.
  527. static const U32 VERTEX_STREAM_COUNT = 4;
  528. StrongRefPtr<GFXVertexBuffer> mCurrentVertexBuffer[VERTEX_STREAM_COUNT];
  529. bool mVertexBufferDirty[VERTEX_STREAM_COUNT];
  530. U32 mVertexBufferFrequency[VERTEX_STREAM_COUNT];
  531. bool mVertexBufferFrequencyDirty[VERTEX_STREAM_COUNT];
  532. const GFXVertexDecl *mCurrVertexDecl;
  533. bool mVertexDeclDirty;
  534. StrongRefPtr<GFXPrimitiveBuffer> mCurrentPrimitiveBuffer;
  535. bool mPrimitiveBufferDirty;
  536. /// This allocates a primitive buffer and returns a pointer to the allocated buffer.
  537. /// A primitive buffer's type argument refers to the index data - the primitive data will
  538. /// always be preserved from call to call.
  539. ///
  540. /// @note All index buffers use unsigned 16-bit indices.
  541. virtual GFXPrimitiveBuffer *allocPrimitiveBuffer( U32 numIndices,
  542. U32 numPrimitives,
  543. GFXBufferType bufferType,
  544. void* data = NULL ) = 0;
  545. /// @}
  546. //---------------------------------------
  547. // SFX buffer
  548. //---------------------------------------
  549. protected:
  550. GFXTexHandle mFrontBuffer[2];
  551. U32 mCurrentFrontBufferIdx;
  552. //---------------------------------------
  553. // Render target related
  554. //---------------------------------------
  555. /// A stack of previously active render targets.
  556. Vector<GFXTargetRef> mRTStack;
  557. /// The current render target which may or may not
  558. /// not be yet activated.
  559. /// @see mRTDirty
  560. GFXTargetRef mCurrentRT;
  561. /// This tracks a previously activated render target
  562. /// which need to be deactivated.
  563. GFXTargetRef mRTDeactivate;
  564. /// This is set when the current and/or deactivate render
  565. /// targets have changed and the device need to update
  566. /// its state on the next draw/clear.
  567. bool mRTDirty;
  568. /// Updates the render targets and viewport in a device
  569. /// specific manner when they are dirty.
  570. virtual void _updateRenderTargets() = 0;
  571. /// The current viewport rect.
  572. RectI mViewport;
  573. /// If true the viewport has been changed and
  574. /// it must be updated on the next draw/clear.
  575. bool mViewportDirty;
  576. public:
  577. /// @name Texture functions
  578. /// @{
  579. protected:
  580. GFXTextureManager * mTextureManager;
  581. public:
  582. virtual GFXCubemap * createCubemap() = 0;
  583. inline GFXTextureManager *getTextureManager()
  584. {
  585. return mTextureManager;
  586. }
  587. ///@}
  588. /// Swizzle to convert 32bpp bitmaps from RGBA to the native device format.
  589. const Swizzle<U8, 4> *getDeviceSwizzle32() const
  590. {
  591. return mDeviceSwizzle32;
  592. }
  593. /// Swizzle to convert 24bpp bitmaps from RGB to the native device format.
  594. const Swizzle<U8, 3> *getDeviceSwizzle24() const
  595. {
  596. return mDeviceSwizzle24;
  597. }
  598. /// @name Render Target functions
  599. /// @{
  600. /// Allocate a target for doing render to texture operations, with no
  601. /// depth/stencil buffer.
  602. virtual GFXTextureTarget *allocRenderToTextureTarget()=0;
  603. /// Allocate a target for a given window.
  604. virtual GFXWindowTarget *allocWindowTarget(PlatformWindow *window)=0;
  605. /// Store the current render target to restore later.
  606. void pushActiveRenderTarget();
  607. /// Restore the previous render target.
  608. void popActiveRenderTarget();
  609. /// Assign a new active render target.
  610. void setActiveRenderTarget( GFXTarget *target, bool updateViewport=true );
  611. /// Returns the current active render target.
  612. inline GFXTarget* getActiveRenderTarget() { return mCurrentRT; }
  613. ///@}
  614. /// @name Shader functions
  615. /// @{
  616. virtual F32 getPixelShaderVersion() const = 0;
  617. virtual void setPixelShaderVersion( F32 version ) = 0;
  618. /// Returns the number of texture samplers that can be used in a shader rendering pass
  619. virtual U32 getNumSamplers() const = 0;
  620. /// Returns the number of simultaneous render targets supported by the device.
  621. virtual U32 getNumRenderTargets() const = 0;
  622. virtual void setShader( GFXShader *shader, bool force = false ) {}
  623. virtual void disableShaders( bool force = false ) {} // TODO Remove when T3D 4.0
  624. /// Set the buffer! (Actual set happens on the next draw call, just like textures, state blocks, etc)
  625. void setShaderConstBuffer(GFXShaderConstBuffer* buffer);
  626. /// Creates a new empty shader which must be initialized
  627. /// and deleted by the caller.
  628. /// @see GFXShader::init
  629. virtual GFXShader* createShader() = 0;
  630. /// @}
  631. //-----------------------------------------------------------------------------
  632. /// @name Rendering methods
  633. /// @{
  634. ///
  635. virtual void clear( U32 flags, ColorI color, F32 z, U32 stencil ) = 0;
  636. virtual bool beginScene();
  637. virtual void endScene();
  638. virtual void beginField();
  639. virtual void endField();
  640. PlatformTimer *mFrameTime;
  641. virtual GFXTexHandle & getFrontBuffer(){ return mFrontBuffer[mCurrentFrontBufferIdx]; }
  642. void setPrimitiveBuffer( GFXPrimitiveBuffer *buffer );
  643. /// Sets the vertex buffer.
  644. ///
  645. /// When setting the stream 0 vertex buffer it will automatically
  646. /// set its associated vertex format as the active format.
  647. ///
  648. /// @param buffer The vertex buffer or NULL to clear the buffer.
  649. /// @param stream The stream index of the vertex source stream to place the buffer.
  650. /// @param frequency The stream frequency of the vertex buffer.
  651. void setVertexBuffer( GFXVertexBuffer *buffer, U32 stream = 0, U32 frequency = 0 );
  652. /// Sets the current vertex format.
  653. ///
  654. /// This should only be used if the vertex format of the stream 0 vertex
  655. /// buffer is different from the one associated to it. Typically this
  656. /// is used when rendering from multiple vertex streams.
  657. ///
  658. void setVertexFormat( const GFXVertexFormat *vertexFormat );
  659. virtual void drawPrimitive( GFXPrimitiveType primType, U32 vertexStart, U32 primitiveCount ) = 0;
  660. /// The parameters to drawIndexedPrimitive are somewhat complicated. From a raw-data stand point
  661. /// they evaluate to something like the following:
  662. /// @code
  663. /// U16 indicies[] = { 0, 1, 2, 1, 0, 0, 2 };
  664. /// Point3F verts[] = { Point3F( 0.0f, 0.0f, 0.0f ), Point3F( 0.0f, 1.0f, 0.0f ), Point3F( 0.0f, 0.0f, 1.0f ) };
  665. ///
  666. /// GFX->drawIndexedPrimitive( GFXLineList, // Drawing a list of lines, each line is two verts
  667. /// 0, // vertex 0 will be referenced so minIndex = 0
  668. /// 3, // 3 verticies will be used for this draw call
  669. /// 1, // We want index 1 to be the first index used, so indicies 1-6 will be used
  670. /// 3 // Drawing 3 LineList primitives, meaning 6 verts will be drawn
  671. /// );
  672. ///
  673. /// U16 *idxPtr = &indicies[1]; // 1 = startIndex, so the pointer is offset such that:
  674. /// // idxPtr[0] is the same as indicies[1]
  675. ///
  676. /// U32 numVertsToDrawFromBuffer = primitiveCount * 2; // 2 verts define a line in the GFXLineList primitive type (6)
  677. /// @endcode
  678. ///
  679. /// @param primType Type of primitive to draw
  680. ///
  681. /// @param startVertex This defines index zero. Its the offset from the start of
  682. /// the vertex buffer to the first vertex.
  683. ///
  684. /// @param minIndex The smallest index into the vertex stream which will be used for this draw call.
  685. /// This is a zero based index relative to startVertex. It is strictly a performance
  686. /// hint for implementations. No vertex below minIndex will be referenced by this draw
  687. /// call. For device implementors, this should _not_ be used to offset the vertex buffer,
  688. /// or index buffer.
  689. ///
  690. /// @param numVerts The number of verticies which will be referenced in this draw call. This is not
  691. /// the number of verticies which will be drawn. That is a function of 'primType' and
  692. /// 'primitiveCount'.
  693. ///
  694. /// @param startIndex An offset from the start of the index buffer to specify where to start. If
  695. /// 'idxBuffer' is a pointer to an array of integers, this could be written as
  696. /// int *offsetIdx = idxBuffer + startIndex;
  697. ///
  698. /// @param primitiveCount The number of primitives of type 'primType' to draw.
  699. ///
  700. virtual void drawIndexedPrimitive( GFXPrimitiveType primType,
  701. U32 startVertex,
  702. U32 minIndex,
  703. U32 numVerts,
  704. U32 startIndex,
  705. U32 primitiveCount ) = 0;
  706. void drawPrimitive( const GFXPrimitive &prim );
  707. void drawPrimitive( U32 primitiveIndex );
  708. void drawPrimitives();
  709. void drawPrimitiveBuffer( GFXPrimitiveBuffer *buffer );
  710. /// @}
  711. //-----------------------------------------------------------------------------
  712. /// Allocate a fence. The API specific implementation of GFXDevice is responsible
  713. /// to make sure that the proper type is used. GFXGeneralFence should work in
  714. /// all cases.
  715. virtual GFXFence *createFence() = 0;
  716. /// Returns a hardware occlusion query object or NULL
  717. /// if this device does not support them.
  718. virtual GFXOcclusionQuery* createOcclusionQuery() { return NULL; }
  719. /// @name Light Settings
  720. /// NONE of these should be overridden by API implementations
  721. /// because of the state caching stuff.
  722. /// @{
  723. void setLight(U32 stage, GFXLightInfo* light);
  724. void setLightMaterial(const GFXLightMaterial& mat);
  725. void setGlobalAmbientColor(const ColorF& color);
  726. /// @}
  727. /// @name Texture State Settings
  728. /// NONE of these should be overridden by API implementations
  729. /// because of the state caching stuff.
  730. /// @{
  731. ///
  732. void setTexture(U32 stage, GFXTextureObject*texture);
  733. void setCubeTexture( U32 stage, GFXCubemap *cubemap );
  734. inline GFXTextureObject* getCurrentTexture( U32 stage ) { return mCurrentTexture[stage]; }
  735. /// @}
  736. /// @name State Block Interface
  737. /// @{
  738. /// Creates a state block object based on the desc passed in. This object
  739. /// represents an immutable state.
  740. virtual GFXStateBlockRef createStateBlock( const GFXStateBlockDesc &desc );
  741. /// Sets the current stateblock (actually activated in ::updateStates)
  742. virtual void setStateBlock( GFXStateBlock *block );
  743. GFXStateBlock* getStateBlock() { return mNewStateBlock; }
  744. /// This sets a stateblock directly from the description
  745. /// structure. Its acceptable to use this for debug rendering
  746. /// and other low frequency rendering tasks.
  747. virtual void setStateBlockByDesc( const GFXStateBlockDesc &desc );
  748. /// @}
  749. /// @name General state interface
  750. /// @{
  751. /// Sets the dirty Render/Texture/Sampler states from the caching system
  752. void updateStates(bool forceSetAll = false);
  753. /// Returns the forced global wireframe state.
  754. static bool getWireframe() { return smWireframe; }
  755. /// Returns true if the occlusion query is disabled.
  756. static bool getDisableOcclusionQuery() { return smDisableOcclusionQuery; }
  757. /// @}
  758. //-----------------------------------------------------------------------------
  759. /// @name Matrix interface
  760. /// @{
  761. /// Sets the top of the world matrix stack
  762. /// @param newWorld New world matrix to set
  763. void setWorldMatrix( const MatrixF &newWorld );
  764. /// Gets the matrix on the top of the world matrix stack
  765. inline const MatrixF &getWorldMatrix() const { return mWorldMatrix[mWorldStackSize]; }
  766. /// Pushes the world matrix stack and copies the current top
  767. /// matrix to the new top of the stack
  768. void pushWorldMatrix();
  769. /// Pops the world matrix stack
  770. void popWorldMatrix();
  771. /// Sets the projection matrix
  772. /// @param newProj New projection matrix to set
  773. void setProjectionMatrix( const MatrixF &newProj );
  774. /// Gets the projection matrix
  775. inline const MatrixF &getProjectionMatrix() const { return mProjectionMatrix; }
  776. /// Sets the view matrix
  777. /// @param newView New view matrix to set
  778. void setViewMatrix( const MatrixF &newView );
  779. /// Gets the view matrix
  780. inline const MatrixF &getViewMatrix() const { return mViewMatrix; }
  781. /// Multiplies the matrix at the top of the world matrix stack by a matrix
  782. /// and replaces the top of the matrix stack with the result
  783. /// @param mat Matrix to multiply
  784. void multWorld( const MatrixF &mat );
  785. /// Set texture matrix for a sampler
  786. void setTextureMatrix( const U32 stage, const MatrixF &texMat );
  787. /// Set an area of the target to render to.
  788. void setViewport( const RectI &rect );
  789. /// Get the current area of the target we will render to.
  790. const RectI &getViewport() const { return mViewport; }
  791. virtual void setClipRect( const RectI &rect ) = 0;
  792. virtual const RectI &getClipRect() const = 0;
  793. /// Set the projection frustum.
  794. ///
  795. /// @see MathUtils::makeFrustum()
  796. virtual void setFrustum( F32 left, F32 right,
  797. F32 bottom, F32 top,
  798. F32 nearPlane, F32 farPlane,
  799. bool bRotate = true);
  800. ///
  801. virtual void setFrustum( const Frustum& frust,
  802. bool bRotate = true );
  803. /// Get the projection frustum.
  804. void getFrustum( F32 *left,
  805. F32 *right,
  806. F32 *bottom,
  807. F32 *top,
  808. F32 *nearPlane,
  809. F32 *farPlane,
  810. bool *isOrtho ) const;
  811. /// Get the projection frustum.
  812. const Frustum& getFrustum() const { return mFrustum; }
  813. /// This will construct and apply an orthographic projection matrix with the provided parameters
  814. /// @param doRotate If set to true, the resulting matrix will be rotated PI/2 around the X axis
  815. // for support in tsShapeInstance. You probably want to leave this as 'false'.
  816. void setOrtho(F32 left, F32 right, F32 bottom, F32 top, F32 nearPlane, F32 farPlane, bool doRotate = false);
  817. /// Return true if the current frustum uses orthographic projection rather than perspective projection.
  818. bool isFrustumOrtho() const { return mFrustum.isOrtho(); }
  819. /// @}
  820. /// Returns the scale for converting world space
  821. /// units to screen space units... aka pixels.
  822. ///
  823. /// This is the true scale which is best used for GUI
  824. /// drawing. For doing lod calculations you should be
  825. /// using the functions in SceneState which is adjusted
  826. /// for special cases like shadows and reflections.
  827. ///
  828. /// @see SceneState::getWorldToScreenScale()
  829. /// @see SceneState::projectRadius()
  830. ///
  831. Point2F getWorldToScreenScale() const;
  832. public:
  833. enum GenericShaderType
  834. {
  835. GSColor = 0,
  836. GSTexture,
  837. GSModColorTexture,
  838. GSAddColorTexture,
  839. GSTargetRestore,
  840. GS_COUNT
  841. };
  842. /// This is a helper function to set a default shader for rendering GUI elements
  843. /// on systems which do not support fixed-function operations as well as for
  844. /// things which need just generic position/texture/color shaders
  845. ///
  846. /// @param type Type of generic shader, add your own if you need
  847. virtual void setupGenericShaders( GenericShaderType type = GSColor ) {};
  848. /// Get the fill convention for this device
  849. virtual F32 getFillConventionOffset() const = 0;
  850. virtual U32 getMaxDynamicVerts() = 0;
  851. virtual U32 getMaxDynamicIndices() = 0;
  852. virtual void doParanoidStateCheck(){};
  853. /// Get access to this device's drawing utility class.
  854. GFXDrawUtil *getDrawUtil();
  855. #ifndef TORQUE_SHIPPING
  856. /// This is a method designed for debugging. It will allow you to dump the states
  857. /// in the render manager out to a file so that it can be diffed and examined.
  858. void dumpStates( const char *fileName ) const;
  859. #else
  860. void dumpStates( const char *fileName ) const {};
  861. #endif
  862. protected:
  863. GFXDrawUtil *mDrawer;
  864. };
  865. //-----------------------------------------------------------------------------
  866. // Matrix interface
  867. inline void GFXDevice::setWorldMatrix( const MatrixF &newWorld )
  868. {
  869. mWorldMatrixDirty = true;
  870. mStateDirty = true;
  871. mWorldMatrix[mWorldStackSize] = newWorld;
  872. }
  873. inline void GFXDevice::pushWorldMatrix()
  874. {
  875. mWorldMatrixDirty = true;
  876. mStateDirty = true;
  877. mWorldStackSize++;
  878. AssertFatal( mWorldStackSize < WORLD_STACK_MAX, "GFX: Exceeded world matrix stack size" );
  879. mWorldMatrix[mWorldStackSize] = mWorldMatrix[mWorldStackSize - 1];
  880. }
  881. inline void GFXDevice::popWorldMatrix()
  882. {
  883. mWorldMatrixDirty = true;
  884. mStateDirty = true;
  885. mWorldStackSize--;
  886. AssertFatal( mWorldStackSize >= 0, "GFX: Negative WorldStackSize!" );
  887. }
  888. inline void GFXDevice::multWorld( const MatrixF &mat )
  889. {
  890. mWorldMatrixDirty = true;
  891. mStateDirty = true;
  892. mWorldMatrix[mWorldStackSize].mul(mat);
  893. }
  894. inline void GFXDevice::setProjectionMatrix( const MatrixF &newProj )
  895. {
  896. mProjectionMatrixDirty = true;
  897. mStateDirty = true;
  898. mProjectionMatrix = newProj;
  899. }
  900. inline void GFXDevice::setViewMatrix( const MatrixF &newView )
  901. {
  902. mStateDirty = true;
  903. mViewMatrixDirty = true;
  904. mViewMatrix = newView;
  905. }
  906. inline void GFXDevice::setTextureMatrix( const U32 stage, const MatrixF &texMat )
  907. {
  908. AssertFatal( stage < TEXTURE_STAGE_COUNT, "Out of range texture sampler" );
  909. mStateDirty = true;
  910. mTextureMatrixDirty[stage] = true;
  911. mTextureMatrix[stage] = texMat;
  912. mTextureMatrixCheckDirty = true;
  913. }
  914. //-----------------------------------------------------------------------------
  915. // Buffer management
  916. inline void GFXDevice::setVertexBuffer( GFXVertexBuffer *buffer, U32 stream, U32 frequency )
  917. {
  918. AssertFatal( stream < VERTEX_STREAM_COUNT, "GFXDevice::setVertexBuffer - Bad stream index!" );
  919. if ( buffer && stream == 0 )
  920. setVertexFormat( &buffer->mVertexFormat );
  921. if ( buffer != mCurrentVertexBuffer[stream] )
  922. {
  923. mCurrentVertexBuffer[stream] = buffer;
  924. mVertexBufferDirty[stream] = true;
  925. mStateDirty = true;
  926. }
  927. if ( mVertexBufferFrequency[stream] != frequency )
  928. {
  929. mVertexBufferFrequency[stream] = frequency;
  930. mVertexBufferFrequencyDirty[stream] = true;
  931. mStateDirty = true;
  932. }
  933. }
  934. inline void GFXDevice::setVertexFormat( const GFXVertexFormat *vertexFormat )
  935. {
  936. if ( vertexFormat->getDecl() == mCurrVertexDecl )
  937. return;
  938. mCurrVertexDecl = vertexFormat->getDecl();
  939. mVertexDeclDirty = true;
  940. mStateDirty = true;
  941. }
  942. #if defined(TORQUE_DEBUG) && defined(TORQUE_DEBUG_GFX)
  943. #define GFXAssertFatal(x, error) AssertFatal(x, error)
  944. #else
  945. #define GFXAssertFatal(x, error)
  946. #endif
  947. #endif // _GFXDEVICE_H_