gfxDevice.h 42 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118119120121122123124125126127128129130131132133134135136137138139140141142143144145146147148149150151152153154155156157158159160161162163164165166167168169170171172173174175176177178179180181182183184185186187188189190191192193194195196197198199200201202203204205206207208209210211212213214215216217218219220221222223224225226227228229230231232233234235236237238239240241242243244245246247248249250251252253254255256257258259260261262263264265266267268269270271272273274275276277278279280281282283284285286287288289290291292293294295296297298299300301302303304305306307308309310311312313314315316317318319320321322323324325326327328329330331332333334335336337338339340341342343344345346347348349350351352353354355356357358359360361362363364365366367368369370371372373374375376377378379380381382383384385386387388389390391392393394395396397398399400401402403404405406407408409410411412413414415416417418419420421422423424425426427428429430431432433434435436437438439440441442443444445446447448449450451452453454455456457458459460461462463464465466467468469470471472473474475476477478479480481482483484485486487488489490491492493494495496497498499500501502503504505506507508509510511512513514515516517518519520521522523524525526527528529530531532533534535536537538539540541542543544545546547548549550551552553554555556557558559560561562563564565566567568569570571572573574575576577578579580581582583584585586587588589590591592593594595596597598599600601602603604605606607608609610611612613614615616617618619620621622623624625626627628629630631632633634635636637638639640641642643644645646647648649650651652653654655656657658659660661662663664665666667668669670671672673674675676677678679680681682683684685686687688689690691692693694695696697698699700701702703704705706707708709710711712713714715716717718719720721722723724725726727728729730731732733734735736737738739740741742743744745746747748749750751752753754755756757758759760761762763764765766767768769770771772773774775776777778779780781782783784785786787788789790791792793794795796797798799800801802803804805806807808809810811812813814815816817818819820821822823824825826827828829830831832833834835836837838839840841842843844845846847848849850851852853854855856857858859860861862863864865866867868869870871872873874875876877878879880881882883884885886887888889890891892893894895896897898899900901902903904905906907908909910911912913914915916917918919920921922923924925926927928929930931932933934935936937938939940941942943944945946947948949950951952953954955956957958959960961962963964965966967968969970971972973974975976977978979980981982983984985986987988989990991992993994995996997998999100010011002100310041005100610071008100910101011101210131014101510161017101810191020102110221023102410251026102710281029103010311032103310341035103610371038103910401041104210431044104510461047104810491050105110521053105410551056105710581059106010611062106310641065106610671068106910701071107210731074107510761077107810791080108110821083108410851086108710881089109010911092109310941095109610971098109911001101110211031104110511061107110811091110111111121113111411151116111711181119112011211122112311241125112611271128112911301131113211331134113511361137113811391140114111421143114411451146114711481149115011511152115311541155115611571158115911601161116211631164116511661167116811691170117111721173117411751176117711781179118011811182118311841185118611871188
  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. /// This is called before this, or any other device, is deleted in the global destroy()
  266. /// method. It allows the device to clean up anything while everything is still valid.
  267. virtual void preDestroy();
  268. /// Set the adapter that this device is using. For use by GFXInit::createDevice only.
  269. virtual void setAdapter(const GFXAdapter& adapter) { mAdapter = adapter; }
  270. /// Notify GFXDevice that we are initialized
  271. virtual void deviceInited();
  272. public:
  273. GFXDevice();
  274. virtual ~GFXDevice();
  275. /// Initialize this GFXDevice, optionally specifying a platform window to
  276. /// bind to.
  277. virtual void init( const GFXVideoMode &mode, PlatformWindow *window = NULL ) = 0;
  278. /// Returns true if the scene has begun and its
  279. /// safe to make rendering calls.
  280. /// @see beginScene
  281. /// @see endScene
  282. bool canCurrentlyRender() const { return mCanCurrentlyRender; }
  283. void setAllowRender( bool render ) { mAllowRender = render; }
  284. inline bool allowRender() const { return mAllowRender; }
  285. /// Retrieve the current rendering style based on GFXDeviceRenderStyles
  286. U32 getCurrentRenderStyle() const { return mCurrentRenderStyle; }
  287. /// Set the current rendering style, based on GFXDeviceRenderStyles
  288. void setCurrentRenderStyle(U32 style) { mCurrentRenderStyle = style; }
  289. /// Set the current projection offset used during stereo rendering
  290. const Point2F& getCurrentProjectionOffset() { return mCurrentProjectionOffset; }
  291. /// Get the current projection offset used during stereo rendering
  292. void setCurrentProjectionOffset(const Point2F& offset) { mCurrentProjectionOffset = offset; }
  293. /// Get the current eye offset used during stereo rendering
  294. const Point3F* getStereoEyeOffsets() { return mStereoEyeOffset; }
  295. const MatrixF* getStereoEyeTransforms() { return mStereoEyeTransforms; }
  296. const MatrixF* getInverseStereoEyeTransforms() { return mInverseStereoEyeTransforms; }
  297. /// Set the current eye offset used during stereo rendering
  298. void setStereoEyeOffsets(Point3F *offsets) { dMemcpy(mStereoEyeOffset, offsets, sizeof(Point3F) * NumStereoPorts); }
  299. void setStereoEyeTransforms(MatrixF *transforms) { dMemcpy(mStereoEyeTransforms, transforms, sizeof(mStereoEyeTransforms)); dMemcpy(mInverseStereoEyeTransforms, transforms, sizeof(mInverseStereoEyeTransforms)); mInverseStereoEyeTransforms[0].inverse(); mInverseStereoEyeTransforms[1].inverse(); }
  300. /// Set the current eye offset used during stereo rendering. Assumes NumStereoPorts are available.
  301. void setStereoFovPort(const FovPort *ports) { dMemcpy(mFovPorts, ports, sizeof(mFovPorts)); }
  302. /// Get the current eye offset used during stereo rendering
  303. const FovPort* getStereoFovPort() { return mFovPorts; }
  304. /// Sets stereo viewports
  305. void setSteroViewports(const RectI *ports) { dMemcpy(mStereoViewports, ports, sizeof(RectI) * NumStereoPorts); }
  306. /// Sets stereo render targets
  307. void setStereoTargets(GFXTextureTarget **targets) { mStereoTargets[0] = targets[0]; mStereoTargets[1] = targets[1]; }
  308. RectI* getStereoViewports() { return mStereoViewports; }
  309. /// Activates a stereo render target, setting the correct viewport to render eye contents.
  310. /// If eyeId is -1, set a viewport encompassing the entire size of the render targets.
  311. void activateStereoTarget(S32 eyeId)
  312. {
  313. if (eyeId == -1)
  314. {
  315. if (mStereoTargets[0])
  316. {
  317. setActiveRenderTarget(mStereoTargets[0], true);
  318. }
  319. }
  320. else
  321. {
  322. if (mStereoTargets[eyeId])
  323. {
  324. setActiveRenderTarget(mStereoTargets[eyeId], false);
  325. }
  326. setViewport(mStereoViewports[eyeId]);
  327. }
  328. }
  329. GFXCardProfiler* getCardProfiler() const { return mCardProfiler; }
  330. /// Returns active graphics adapter type.
  331. virtual GFXAdapterType getAdapterType()=0;
  332. /// Returns the Adapter that was used to create this device
  333. virtual const GFXAdapter& getAdapter() { return mAdapter; }
  334. /// @}
  335. /// @name Debug Methods
  336. /// @{
  337. virtual void enterDebugEvent(ColorI color, const char *name) = 0;
  338. virtual void leaveDebugEvent() = 0;
  339. virtual void setDebugMarker(ColorI color, const char *name) = 0;
  340. /// @}
  341. /// @name Resource debug methods
  342. /// @{
  343. /// Lists how many of each GFX resource (e.g. textures, texture targets, shaders, etc.) GFX is aware of
  344. /// @param unflaggedOnly If true, this method only counts unflagged resources
  345. virtual void listResources(bool unflaggedOnly);
  346. /// Flags all resources GFX is currently aware of
  347. virtual void flagCurrentResources();
  348. /// Clears the flag on all resources GFX is currently aware of
  349. virtual void clearResourceFlags();
  350. /// Dumps a description of the specified resource types to the console
  351. /// @param resNames A string of space separated class names (e.g. "GFXTextureObject GFXTextureTarget GFXShader")
  352. /// to describe to the console
  353. /// @param file A path to the file to write the descriptions to. If it is NULL or "", descriptions are
  354. /// written to the console.
  355. /// @param unflaggedOnly If true, this method only counts unflagged resources
  356. /// @note resNames is case sensitive because there is no dStristr function.
  357. virtual void describeResources(const char* resName, const char* file, bool unflaggedOnly);
  358. /// Returns the current GFXDeviceStatistics, stats are cleared every ::beginScene call.
  359. GFXDeviceStatistics* getDeviceStatistics() { return &mDeviceStatistics; }
  360. protected:
  361. GFXDeviceStatistics mDeviceStatistics;
  362. /// This is a helper method for describeResourcesToFile. It walks through the
  363. /// GFXResource list and sorts it by item type, putting the resources into the proper vector.
  364. /// @see describeResources
  365. virtual void fillResourceVectors(const char* resNames, bool unflaggedOnly, Vector<GFXResource*> &textureObjects,
  366. Vector<GFXResource*> &textureTargets, Vector<GFXResource*> &windowTargets, Vector<GFXResource*> &vertexBuffers,
  367. Vector<GFXResource*> &primitiveBuffers, Vector<GFXResource*> &fences, Vector<GFXResource*> &cubemaps,
  368. Vector<GFXResource*> &shaders, Vector<GFXResource*> &stateblocks);
  369. public:
  370. /// @}
  371. /// @name Video Mode Functions
  372. /// @{
  373. /// Enumerates the supported video modes of the device
  374. virtual void enumerateVideoModes() = 0;
  375. /// Returns the video mode list.
  376. /// @see GFXVideoMode
  377. const Vector<GFXVideoMode>* const getVideoModeList() const { return &mVideoModes; }
  378. /// Returns the first format from the list which meets all
  379. /// the criteria of the texture profile and query options.
  380. virtual GFXFormat selectSupportedFormat(GFXTextureProfile *profile,
  381. const Vector<GFXFormat> &formats, bool texture, bool mustblend, bool mustfilter) = 0;
  382. /// @}
  383. //-----------------------------------------------------------------------------
  384. protected:
  385. /// @name State tracking variables
  386. /// @{
  387. /// Set if ANY state is dirty, including matrices or primitive buffers.
  388. bool mStateDirty;
  389. enum TexDirtyType
  390. {
  391. GFXTDT_Normal,
  392. GFXTDT_Cube
  393. };
  394. GFXTexHandle mCurrentTexture[TEXTURE_STAGE_COUNT];
  395. GFXTexHandle mNewTexture[TEXTURE_STAGE_COUNT];
  396. GFXCubemapHandle mCurrentCubemap[TEXTURE_STAGE_COUNT];
  397. GFXCubemapHandle mNewCubemap[TEXTURE_STAGE_COUNT];
  398. TexDirtyType mTexType[TEXTURE_STAGE_COUNT];
  399. bool mTextureDirty[TEXTURE_STAGE_COUNT];
  400. bool mTexturesDirty;
  401. // This maps a GFXStateBlockDesc hash value to a GFXStateBlockRef
  402. typedef Map<U32, GFXStateBlockRef> StateBlockMap;
  403. StateBlockMap mCurrentStateBlocks;
  404. // This tracks whether or not our state block is dirty.
  405. bool mStateBlockDirty;
  406. GFXStateBlockRef mCurrentStateBlock;
  407. GFXStateBlockRef mNewStateBlock;
  408. GFXShaderConstBuffer *mCurrentShaderConstBuffer;
  409. /// A global forced wireframe mode.
  410. static bool smWireframe;
  411. /// The global vsync state.
  412. static bool smDisableVSync;
  413. /// The forced shader model version if non-zero.
  414. static F32 smForcedPixVersion;
  415. /// Disable all hardware occlusion queries causing
  416. /// them to return only the visibile state.
  417. static bool smDisableOcclusionQuery;
  418. /// @}
  419. /// @name Light Tracking
  420. /// @{
  421. GFXLightInfo mCurrentLight[LIGHT_STAGE_COUNT];
  422. bool mCurrentLightEnable[LIGHT_STAGE_COUNT];
  423. bool mLightDirty[LIGHT_STAGE_COUNT];
  424. bool mLightsDirty;
  425. ColorF mGlobalAmbientColor;
  426. bool mGlobalAmbientColorDirty;
  427. /// @}
  428. /// @name Fixed function material tracking
  429. /// @{
  430. GFXLightMaterial mCurrentLightMaterial;
  431. bool mLightMaterialDirty;
  432. /// @}
  433. /// @name Bitmap modulation and color stack
  434. /// @{
  435. ///
  436. /// @}
  437. /// @see getDeviceSwizzle32
  438. Swizzle<U8, 4> *mDeviceSwizzle32;
  439. /// @see getDeviceSwizzle24
  440. Swizzle<U8, 3> *mDeviceSwizzle24;
  441. //-----------------------------------------------------------------------------
  442. /// @name Matrix managing variables
  443. /// @{
  444. ///
  445. MatrixF mWorldMatrix[WORLD_STACK_MAX];
  446. bool mWorldMatrixDirty;
  447. S32 mWorldStackSize;
  448. MatrixF mProjectionMatrix;
  449. bool mProjectionMatrixDirty;
  450. MatrixF mViewMatrix;
  451. bool mViewMatrixDirty;
  452. MatrixF mTextureMatrix[TEXTURE_STAGE_COUNT];
  453. bool mTextureMatrixDirty[TEXTURE_STAGE_COUNT];
  454. bool mTextureMatrixCheckDirty;
  455. /// @}
  456. /// @name Current frustum planes
  457. /// @{
  458. ///
  459. Frustum mFrustum;
  460. //-----------------------------------------------------------------------------
  461. /// @name Stateblock functions
  462. /// @{
  463. /// Called by GFXDevice to create a device specific stateblock
  464. virtual GFXStateBlockRef createStateBlockInternal(const GFXStateBlockDesc& desc) = 0;
  465. /// Called by GFXDevice to actually set a stateblock.
  466. /// @param force If true, set all states
  467. virtual void setStateBlockInternal(GFXStateBlock* block, bool force) = 0;
  468. /// @}
  469. /// Called by base GFXDevice to actually set a const buffer
  470. virtual void setShaderConstBufferInternal(GFXShaderConstBuffer* buffer) = 0;
  471. virtual void setTextureInternal(U32 textureUnit, const GFXTextureObject*texture) = 0;
  472. virtual void setLightInternal(U32 lightStage, const GFXLightInfo light, bool lightEnable) = 0;
  473. virtual void setGlobalAmbientInternal(ColorF color) = 0;
  474. virtual void setLightMaterialInternal(const GFXLightMaterial mat) = 0;
  475. virtual bool beginSceneInternal() = 0;
  476. virtual void endSceneInternal() = 0;
  477. /// @name State Initialization.
  478. /// @{
  479. /// State initialization. This MUST BE CALLED in setVideoMode after the device
  480. /// is created.
  481. virtual void initStates() = 0;
  482. /// @}
  483. //-----------------------------------------------------------------------------
  484. /// This function must be implemented differently per
  485. /// API and it should set ONLY the current matrix.
  486. /// For example, in OpenGL, there should be NO matrix stack
  487. /// activity, all the stack stuff is managed in the GFX layer.
  488. ///
  489. /// OpenGL does not have separate world and
  490. /// view matrices. It has ModelView which is world * view.
  491. /// You must take this into consideration.
  492. ///
  493. /// @param mtype Which matrix to set, world/view/projection
  494. /// @param mat Matrix to assign
  495. virtual void setMatrix( GFXMatrixType mtype, const MatrixF &mat ) = 0;
  496. //-----------------------------------------------------------------------------
  497. protected:
  498. /// @name Buffer Allocation
  499. /// These methods are implemented per-device and are called by the GFX layer
  500. /// when a user calls an alloc
  501. ///
  502. /// @note Primitive Buffers are NOT implemented per device, they wrap index buffers
  503. /// @{
  504. /// This allocates a vertex buffer and returns a pointer to the allocated buffer.
  505. /// This function should not be called directly - rather it should be used by
  506. /// the GFXVertexBufferHandle class.
  507. virtual GFXVertexBuffer *allocVertexBuffer( U32 numVerts,
  508. const GFXVertexFormat *vertexFormat,
  509. U32 vertSize,
  510. GFXBufferType bufferType ) = 0;
  511. /// Called from GFXVertexFormat to allocate the hardware
  512. /// specific vertex declaration for rendering.
  513. virtual GFXVertexDecl* allocVertexDecl( const GFXVertexFormat *vertexFormat ) = 0;
  514. /// Sets the current vertex declaration on the device.
  515. virtual void setVertexDecl( const GFXVertexDecl *decl ) = 0;
  516. /// Sets the vertex buffer on the device.
  517. virtual void setVertexStream( U32 stream, GFXVertexBuffer *buffer ) = 0;
  518. /// Set the vertex stream frequency on the device.
  519. virtual void setVertexStreamFrequency( U32 stream, U32 frequency ) = 0;
  520. /// The maximum number of supported vertex streams which
  521. /// may be more than the device supports.
  522. static const U32 VERTEX_STREAM_COUNT = 4;
  523. StrongRefPtr<GFXVertexBuffer> mCurrentVertexBuffer[VERTEX_STREAM_COUNT];
  524. bool mVertexBufferDirty[VERTEX_STREAM_COUNT];
  525. U32 mVertexBufferFrequency[VERTEX_STREAM_COUNT];
  526. bool mVertexBufferFrequencyDirty[VERTEX_STREAM_COUNT];
  527. const GFXVertexDecl *mCurrVertexDecl;
  528. bool mVertexDeclDirty;
  529. StrongRefPtr<GFXPrimitiveBuffer> mCurrentPrimitiveBuffer;
  530. bool mPrimitiveBufferDirty;
  531. /// This allocates a primitive buffer and returns a pointer to the allocated buffer.
  532. /// A primitive buffer's type argument refers to the index data - the primitive data will
  533. /// always be preserved from call to call.
  534. ///
  535. /// @note All index buffers use unsigned 16-bit indices.
  536. virtual GFXPrimitiveBuffer *allocPrimitiveBuffer( U32 numIndices,
  537. U32 numPrimitives,
  538. GFXBufferType bufferType ) = 0;
  539. /// @}
  540. //---------------------------------------
  541. // SFX buffer
  542. //---------------------------------------
  543. protected:
  544. GFXTexHandle mFrontBuffer[2];
  545. U32 mCurrentFrontBufferIdx;
  546. //---------------------------------------
  547. // Render target related
  548. //---------------------------------------
  549. /// A stack of previously active render targets.
  550. Vector<GFXTargetRef> mRTStack;
  551. /// The current render target which may or may not
  552. /// not be yet activated.
  553. /// @see mRTDirty
  554. GFXTargetRef mCurrentRT;
  555. /// This tracks a previously activated render target
  556. /// which need to be deactivated.
  557. GFXTargetRef mRTDeactivate;
  558. /// This is set when the current and/or deactivate render
  559. /// targets have changed and the device need to update
  560. /// its state on the next draw/clear.
  561. bool mRTDirty;
  562. /// Updates the render targets and viewport in a device
  563. /// specific manner when they are dirty.
  564. virtual void _updateRenderTargets() = 0;
  565. /// The current viewport rect.
  566. RectI mViewport;
  567. /// If true the viewport has been changed and
  568. /// it must be updated on the next draw/clear.
  569. bool mViewportDirty;
  570. public:
  571. /// @name Texture functions
  572. /// @{
  573. protected:
  574. GFXTextureManager * mTextureManager;
  575. public:
  576. virtual GFXCubemap * createCubemap() = 0;
  577. inline GFXTextureManager *getTextureManager()
  578. {
  579. return mTextureManager;
  580. }
  581. ///@}
  582. /// Swizzle to convert 32bpp bitmaps from RGBA to the native device format.
  583. const Swizzle<U8, 4> *getDeviceSwizzle32() const
  584. {
  585. return mDeviceSwizzle32;
  586. }
  587. /// Swizzle to convert 24bpp bitmaps from RGB to the native device format.
  588. const Swizzle<U8, 3> *getDeviceSwizzle24() const
  589. {
  590. return mDeviceSwizzle24;
  591. }
  592. /// @name Render Target functions
  593. /// @{
  594. /// Allocate a target for doing render to texture operations, with no
  595. /// depth/stencil buffer.
  596. virtual GFXTextureTarget *allocRenderToTextureTarget()=0;
  597. /// Allocate a target for a given window.
  598. virtual GFXWindowTarget *allocWindowTarget(PlatformWindow *window)=0;
  599. /// Store the current render target to restore later.
  600. void pushActiveRenderTarget();
  601. /// Restore the previous render target.
  602. void popActiveRenderTarget();
  603. /// Assign a new active render target.
  604. void setActiveRenderTarget( GFXTarget *target, bool updateViewport=true );
  605. /// Returns the current active render target.
  606. inline GFXTarget* getActiveRenderTarget() { return mCurrentRT; }
  607. ///@}
  608. /// @name Shader functions
  609. /// @{
  610. virtual F32 getPixelShaderVersion() const = 0;
  611. virtual void setPixelShaderVersion( F32 version ) = 0;
  612. /// Returns the number of texture samplers that can be used in a shader rendering pass
  613. virtual U32 getNumSamplers() const = 0;
  614. /// Returns the number of simultaneous render targets supported by the device.
  615. virtual U32 getNumRenderTargets() const = 0;
  616. virtual void setShader( GFXShader *shader, bool force = false ) {}
  617. virtual void disableShaders( bool force = false ) {} // TODO Remove when T3D 4.0
  618. /// Set the buffer! (Actual set happens on the next draw call, just like textures, state blocks, etc)
  619. void setShaderConstBuffer(GFXShaderConstBuffer* buffer);
  620. /// Creates a new empty shader which must be initialized
  621. /// and deleted by the caller.
  622. /// @see GFXShader::init
  623. virtual GFXShader* createShader() = 0;
  624. /// @}
  625. //-----------------------------------------------------------------------------
  626. /// @name Rendering methods
  627. /// @{
  628. ///
  629. virtual void clear( U32 flags, ColorI color, F32 z, U32 stencil ) = 0;
  630. virtual bool beginScene();
  631. virtual void endScene();
  632. virtual void beginField();
  633. virtual void endField();
  634. PlatformTimer *mFrameTime;
  635. virtual GFXTexHandle & getFrontBuffer(){ return mFrontBuffer[mCurrentFrontBufferIdx]; }
  636. void setPrimitiveBuffer( GFXPrimitiveBuffer *buffer );
  637. /// Sets the vertex buffer.
  638. ///
  639. /// When setting the stream 0 vertex buffer it will automatically
  640. /// set its associated vertex format as the active format.
  641. ///
  642. /// @param buffer The vertex buffer or NULL to clear the buffer.
  643. /// @param stream The stream index of the vertex source stream to place the buffer.
  644. /// @param frequency The stream frequency of the vertex buffer.
  645. void setVertexBuffer( GFXVertexBuffer *buffer, U32 stream = 0, U32 frequency = 0 );
  646. /// Sets the current vertex format.
  647. ///
  648. /// This should only be used if the vertex format of the stream 0 vertex
  649. /// buffer is different from the one associated to it. Typically this
  650. /// is used when rendering from multiple vertex streams.
  651. ///
  652. void setVertexFormat( const GFXVertexFormat *vertexFormat );
  653. virtual void drawPrimitive( GFXPrimitiveType primType, U32 vertexStart, U32 primitiveCount ) = 0;
  654. /// The parameters to drawIndexedPrimitive are somewhat complicated. From a raw-data stand point
  655. /// they evaluate to something like the following:
  656. /// @code
  657. /// U16 indicies[] = { 0, 1, 2, 1, 0, 0, 2 };
  658. /// Point3F verts[] = { Point3F( 0.0f, 0.0f, 0.0f ), Point3F( 0.0f, 1.0f, 0.0f ), Point3F( 0.0f, 0.0f, 1.0f ) };
  659. ///
  660. /// GFX->drawIndexedPrimitive( GFXLineList, // Drawing a list of lines, each line is two verts
  661. /// 0, // vertex 0 will be referenced so minIndex = 0
  662. /// 3, // 3 verticies will be used for this draw call
  663. /// 1, // We want index 1 to be the first index used, so indicies 1-6 will be used
  664. /// 3 // Drawing 3 LineList primitives, meaning 6 verts will be drawn
  665. /// );
  666. ///
  667. /// U16 *idxPtr = &indicies[1]; // 1 = startIndex, so the pointer is offset such that:
  668. /// // idxPtr[0] is the same as indicies[1]
  669. ///
  670. /// U32 numVertsToDrawFromBuffer = primitiveCount * 2; // 2 verts define a line in the GFXLineList primitive type (6)
  671. /// @endcode
  672. ///
  673. /// @param primType Type of primitive to draw
  674. ///
  675. /// @param startVertex This defines index zero. Its the offset from the start of
  676. /// the vertex buffer to the first vertex.
  677. ///
  678. /// @param minIndex The smallest index into the vertex stream which will be used for this draw call.
  679. /// This is a zero based index relative to startVertex. It is strictly a performance
  680. /// hint for implementations. No vertex below minIndex will be referenced by this draw
  681. /// call. For device implementors, this should _not_ be used to offset the vertex buffer,
  682. /// or index buffer.
  683. ///
  684. /// @param numVerts The number of verticies which will be referenced in this draw call. This is not
  685. /// the number of verticies which will be drawn. That is a function of 'primType' and
  686. /// 'primitiveCount'.
  687. ///
  688. /// @param startIndex An offset from the start of the index buffer to specify where to start. If
  689. /// 'idxBuffer' is a pointer to an array of integers, this could be written as
  690. /// int *offsetIdx = idxBuffer + startIndex;
  691. ///
  692. /// @param primitiveCount The number of primitives of type 'primType' to draw.
  693. ///
  694. virtual void drawIndexedPrimitive( GFXPrimitiveType primType,
  695. U32 startVertex,
  696. U32 minIndex,
  697. U32 numVerts,
  698. U32 startIndex,
  699. U32 primitiveCount ) = 0;
  700. void drawPrimitive( const GFXPrimitive &prim );
  701. void drawPrimitive( U32 primitiveIndex );
  702. void drawPrimitives();
  703. void drawPrimitiveBuffer( GFXPrimitiveBuffer *buffer );
  704. /// @}
  705. //-----------------------------------------------------------------------------
  706. /// Allocate a fence. The API specific implementation of GFXDevice is responsible
  707. /// to make sure that the proper type is used. GFXGeneralFence should work in
  708. /// all cases.
  709. virtual GFXFence *createFence() = 0;
  710. /// Returns a hardware occlusion query object or NULL
  711. /// if this device does not support them.
  712. virtual GFXOcclusionQuery* createOcclusionQuery() { return NULL; }
  713. /// @name Light Settings
  714. /// NONE of these should be overridden by API implementations
  715. /// because of the state caching stuff.
  716. /// @{
  717. void setLight(U32 stage, GFXLightInfo* light);
  718. void setLightMaterial(const GFXLightMaterial& mat);
  719. void setGlobalAmbientColor(const ColorF& color);
  720. /// @}
  721. /// @name Texture State Settings
  722. /// NONE of these should be overridden by API implementations
  723. /// because of the state caching stuff.
  724. /// @{
  725. ///
  726. void setTexture(U32 stage, GFXTextureObject*texture);
  727. void setCubeTexture( U32 stage, GFXCubemap *cubemap );
  728. inline GFXTextureObject* getCurrentTexture( U32 stage ) { return mCurrentTexture[stage]; }
  729. /// @}
  730. /// @name State Block Interface
  731. /// @{
  732. /// Creates a state block object based on the desc passed in. This object
  733. /// represents an immutable state.
  734. virtual GFXStateBlockRef createStateBlock( const GFXStateBlockDesc &desc );
  735. /// Sets the current stateblock (actually activated in ::updateStates)
  736. virtual void setStateBlock( GFXStateBlock *block );
  737. GFXStateBlock* getStateBlock() { return mNewStateBlock; }
  738. /// This sets a stateblock directly from the description
  739. /// structure. Its acceptable to use this for debug rendering
  740. /// and other low frequency rendering tasks.
  741. virtual void setStateBlockByDesc( const GFXStateBlockDesc &desc );
  742. /// @}
  743. /// @name General state interface
  744. /// @{
  745. /// Sets the dirty Render/Texture/Sampler states from the caching system
  746. void updateStates(bool forceSetAll = false);
  747. /// Returns the forced global wireframe state.
  748. static bool getWireframe() { return smWireframe; }
  749. /// Returns true if the occlusion query is disabled.
  750. static bool getDisableOcclusionQuery() { return smDisableOcclusionQuery; }
  751. /// @}
  752. //-----------------------------------------------------------------------------
  753. /// @name Matrix interface
  754. /// @{
  755. /// Sets the top of the world matrix stack
  756. /// @param newWorld New world matrix to set
  757. void setWorldMatrix( const MatrixF &newWorld );
  758. /// Gets the matrix on the top of the world matrix stack
  759. inline const MatrixF &getWorldMatrix() const { return mWorldMatrix[mWorldStackSize]; }
  760. /// Pushes the world matrix stack and copies the current top
  761. /// matrix to the new top of the stack
  762. void pushWorldMatrix();
  763. /// Pops the world matrix stack
  764. void popWorldMatrix();
  765. /// Sets the projection matrix
  766. /// @param newProj New projection matrix to set
  767. void setProjectionMatrix( const MatrixF &newProj );
  768. /// Gets the projection matrix
  769. inline const MatrixF &getProjectionMatrix() const { return mProjectionMatrix; }
  770. /// Sets the view matrix
  771. /// @param newView New view matrix to set
  772. void setViewMatrix( const MatrixF &newView );
  773. /// Gets the view matrix
  774. inline const MatrixF &getViewMatrix() const { return mViewMatrix; }
  775. /// Multiplies the matrix at the top of the world matrix stack by a matrix
  776. /// and replaces the top of the matrix stack with the result
  777. /// @param mat Matrix to multiply
  778. void multWorld( const MatrixF &mat );
  779. /// Set texture matrix for a sampler
  780. void setTextureMatrix( const U32 stage, const MatrixF &texMat );
  781. /// Set an area of the target to render to.
  782. void setViewport( const RectI &rect );
  783. /// Get the current area of the target we will render to.
  784. const RectI &getViewport() const { return mViewport; }
  785. virtual void setClipRect( const RectI &rect ) = 0;
  786. virtual const RectI &getClipRect() const = 0;
  787. /// Set the projection frustum.
  788. ///
  789. /// @see MathUtils::makeFrustum()
  790. virtual void setFrustum( F32 left, F32 right,
  791. F32 bottom, F32 top,
  792. F32 nearPlane, F32 farPlane,
  793. bool bRotate = true);
  794. ///
  795. virtual void setFrustum( const Frustum& frust,
  796. bool bRotate = true );
  797. /// Get the projection frustum.
  798. void getFrustum( F32 *left,
  799. F32 *right,
  800. F32 *bottom,
  801. F32 *top,
  802. F32 *nearPlane,
  803. F32 *farPlane,
  804. bool *isOrtho ) const;
  805. /// Get the projection frustum.
  806. const Frustum& getFrustum() const { return mFrustum; }
  807. /// This will construct and apply an orthographic projection matrix with the provided parameters
  808. /// @param doRotate If set to true, the resulting matrix will be rotated PI/2 around the X axis
  809. // for support in tsShapeInstance. You probably want to leave this as 'false'.
  810. void setOrtho(F32 left, F32 right, F32 bottom, F32 top, F32 nearPlane, F32 farPlane, bool doRotate = false);
  811. /// Return true if the current frustum uses orthographic projection rather than perspective projection.
  812. bool isFrustumOrtho() const { return mFrustum.isOrtho(); }
  813. /// @}
  814. /// Returns the scale for converting world space
  815. /// units to screen space units... aka pixels.
  816. ///
  817. /// This is the true scale which is best used for GUI
  818. /// drawing. For doing lod calculations you should be
  819. /// using the functions in SceneState which is adjusted
  820. /// for special cases like shadows and reflections.
  821. ///
  822. /// @see SceneState::getWorldToScreenScale()
  823. /// @see SceneState::projectRadius()
  824. ///
  825. Point2F getWorldToScreenScale() const;
  826. public:
  827. enum GenericShaderType
  828. {
  829. GSColor = 0,
  830. GSTexture,
  831. GSModColorTexture,
  832. GSAddColorTexture,
  833. GSTargetRestore,
  834. GS_COUNT
  835. };
  836. /// This is a helper function to set a default shader for rendering GUI elements
  837. /// on systems which do not support fixed-function operations as well as for
  838. /// things which need just generic position/texture/color shaders
  839. ///
  840. /// @param type Type of generic shader, add your own if you need
  841. virtual void setupGenericShaders( GenericShaderType type = GSColor ) {};
  842. /// Get the fill convention for this device
  843. virtual F32 getFillConventionOffset() const = 0;
  844. virtual U32 getMaxDynamicVerts() = 0;
  845. virtual U32 getMaxDynamicIndices() = 0;
  846. virtual void doParanoidStateCheck(){};
  847. /// Get access to this device's drawing utility class.
  848. GFXDrawUtil *getDrawUtil();
  849. #ifndef TORQUE_SHIPPING
  850. /// This is a method designed for debugging. It will allow you to dump the states
  851. /// in the render manager out to a file so that it can be diffed and examined.
  852. void dumpStates( const char *fileName ) const;
  853. #else
  854. void dumpStates( const char *fileName ) const {};
  855. #endif
  856. protected:
  857. GFXDrawUtil *mDrawer;
  858. };
  859. //-----------------------------------------------------------------------------
  860. // Matrix interface
  861. inline void GFXDevice::setWorldMatrix( const MatrixF &newWorld )
  862. {
  863. mWorldMatrixDirty = true;
  864. mStateDirty = true;
  865. mWorldMatrix[mWorldStackSize] = newWorld;
  866. }
  867. inline void GFXDevice::pushWorldMatrix()
  868. {
  869. mWorldMatrixDirty = true;
  870. mStateDirty = true;
  871. mWorldStackSize++;
  872. AssertFatal( mWorldStackSize < WORLD_STACK_MAX, "GFX: Exceeded world matrix stack size" );
  873. mWorldMatrix[mWorldStackSize] = mWorldMatrix[mWorldStackSize - 1];
  874. }
  875. inline void GFXDevice::popWorldMatrix()
  876. {
  877. mWorldMatrixDirty = true;
  878. mStateDirty = true;
  879. mWorldStackSize--;
  880. AssertFatal( mWorldStackSize >= 0, "GFX: Negative WorldStackSize!" );
  881. }
  882. inline void GFXDevice::multWorld( const MatrixF &mat )
  883. {
  884. mWorldMatrixDirty = true;
  885. mStateDirty = true;
  886. mWorldMatrix[mWorldStackSize].mul(mat);
  887. }
  888. inline void GFXDevice::setProjectionMatrix( const MatrixF &newProj )
  889. {
  890. mProjectionMatrixDirty = true;
  891. mStateDirty = true;
  892. mProjectionMatrix = newProj;
  893. }
  894. inline void GFXDevice::setViewMatrix( const MatrixF &newView )
  895. {
  896. mStateDirty = true;
  897. mViewMatrixDirty = true;
  898. mViewMatrix = newView;
  899. }
  900. inline void GFXDevice::setTextureMatrix( const U32 stage, const MatrixF &texMat )
  901. {
  902. AssertFatal( stage < TEXTURE_STAGE_COUNT, "Out of range texture sampler" );
  903. mStateDirty = true;
  904. mTextureMatrixDirty[stage] = true;
  905. mTextureMatrix[stage] = texMat;
  906. mTextureMatrixCheckDirty = true;
  907. }
  908. //-----------------------------------------------------------------------------
  909. // Buffer management
  910. inline void GFXDevice::setVertexBuffer( GFXVertexBuffer *buffer, U32 stream, U32 frequency )
  911. {
  912. AssertFatal( stream < VERTEX_STREAM_COUNT, "GFXDevice::setVertexBuffer - Bad stream index!" );
  913. if ( buffer && stream == 0 )
  914. setVertexFormat( &buffer->mVertexFormat );
  915. if ( buffer != mCurrentVertexBuffer[stream] )
  916. {
  917. mCurrentVertexBuffer[stream] = buffer;
  918. mVertexBufferDirty[stream] = true;
  919. mStateDirty = true;
  920. }
  921. if ( mVertexBufferFrequency[stream] != frequency )
  922. {
  923. mVertexBufferFrequency[stream] = frequency;
  924. mVertexBufferFrequencyDirty[stream] = true;
  925. mStateDirty = true;
  926. }
  927. }
  928. inline void GFXDevice::setVertexFormat( const GFXVertexFormat *vertexFormat )
  929. {
  930. if ( vertexFormat->getDecl() == mCurrVertexDecl )
  931. return;
  932. mCurrVertexDecl = vertexFormat->getDecl();
  933. mVertexDeclDirty = true;
  934. mStateDirty = true;
  935. }
  936. #if defined(TORQUE_DEBUG) && defined(TORQUE_DEBUG_GFX)
  937. #define GFXAssertFatal(x, error) AssertFatal(x, error)
  938. #else
  939. #define GFXAssertFatal(x, error)
  940. #endif
  941. #endif // _GFXDEVICE_H_