Graphics.h 24 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118119120121122123124125126127128129130131132133134135136137138139140141142143144145146147148149150151152153154155156157158159160161162163164165166167168169170171172173174175176177178179180181182183184185186187188189190191192193194195196197198199200201202203204205206207208209210211212213214215216217218219220221222223224225226227228229230231232233234235236237238239240241242243244245246247248249250251252253254255256257258259260261262263264265266267268269270271272273274275276277278279280281282283284285286287288289290291292293294295296297298299300301302303304305306307308309310311312313314315316317318319320321322323324325326327328329330331332333334335336337338339340341342343344345346347348349350351352353354355356357358359360361362363364365366367368369370371372373374375376377378379380381382383384385386387388389390391392393394395396397398399400401402403404405406407408409410411412413414415416417418419420421422423424425426427428429430431432433434435436437438439440441442443444445446447448449450451452453454455456457458459460461462463464465466467468469470471472473474475476477478479480481482483484485486487488489490491492493494495496497498499500501502503504505506507508509510511512513514515516517518519520521522523524525526527528529530531532533534535536537538
  1. //
  2. // Urho3D Engine
  3. // Copyright (c) 2008-2011 Lasse Öörni
  4. //
  5. // Permission is hereby granted, free of charge, to any person obtaining a copy
  6. // of this software and associated documentation files (the "Software"), to deal
  7. // in the Software without restriction, including without limitation the rights
  8. // to use, copy, modify, merge, publish, distribute, sublicense, and/or sell
  9. // copies of the Software, and to permit persons to whom the Software is
  10. // furnished to do so, subject to the following conditions:
  11. //
  12. // The above copyright notice and this permission notice shall be included in
  13. // all copies or substantial portions of the Software.
  14. //
  15. // THE SOFTWARE IS PROVIDED "AS IS", WITHOUT WARRANTY OF ANY KIND, EXPRESS OR
  16. // IMPLIED, INCLUDING BUT NOT LIMITED TO THE WARRANTIES OF MERCHANTABILITY,
  17. // FITNESS FOR A PARTICULAR PURPOSE AND NONINFRINGEMENT. IN NO EVENT SHALL THE
  18. // AUTHORS OR COPYRIGHT HOLDERS BE LIABLE FOR ANY CLAIM, DAMAGES OR OTHER
  19. // LIABILITY, WHETHER IN AN ACTION OF CONTRACT, TORT OR OTHERWISE, ARISING FROM,
  20. // OUT OF OR IN CONNECTION WITH THE SOFTWARE OR THE USE OR OTHER DEALINGS IN
  21. // THE SOFTWARE.
  22. //
  23. #pragma once
  24. #include "Color.h"
  25. #include "Object.h"
  26. #include "Rect.h"
  27. #include "GraphicsDefs.h"
  28. class Image;
  29. class IndexBuffer;
  30. class Matrix3;
  31. class Matrix4;
  32. class Matrix3x4;
  33. class GPUObject;
  34. class GraphicsImpl;
  35. class RenderSurface;
  36. class ShaderVariation;
  37. class Texture;
  38. class Texture2D;
  39. class TextureCube;
  40. class Vector3;
  41. class Vector4;
  42. class VertexBuffer;
  43. class VertexDeclaration;
  44. static const int IMMEDIATE_BUFFER_DEFAULT_SIZE = 1024;
  45. static const int NUM_SCREEN_BUFFERS = 2;
  46. /// Graphics subsystem. Manages the Direct3D9 device, application window, rendering state and GPU resources
  47. class Graphics : public Object
  48. {
  49. OBJECT(Graphics);
  50. public:
  51. /// Construct
  52. Graphics(Context* context);
  53. /// Destruct. Close the window and release the Direct3D9 device
  54. virtual ~Graphics();
  55. /// Pump operating system messages
  56. void MessagePump();
  57. /// Set window title
  58. void SetWindowTitle(const String& windowTitle);
  59. /// Set screen mode. In deferred rendering modes multisampling means edge filtering instead of MSAA
  60. bool SetMode(RenderMode mode, int width, int height, bool fullscreen, bool vsync, int multiSample);
  61. /// Set screen resolution only
  62. bool SetMode(int width, int height);
  63. /// Set rendering mode only
  64. bool SetMode(RenderMode mode);
  65. /// Toggle between full screen and windowed mode
  66. bool ToggleFullscreen();
  67. /// Close the window
  68. void Close();
  69. /// Take a screenshot
  70. bool TakeScreenShot(Image& destImage);
  71. /// Set whether to flush GPU command queue at the end of each frame. Default true
  72. void SetFlushGPU(bool enable);
  73. /// Begin frame rendering
  74. bool BeginFrame();
  75. /// End frame rendering and swap buffers
  76. void EndFrame();
  77. /// Clear any or all of render target, depth buffer and stencil buffer
  78. void Clear(unsigned flags, const Color& color = Color(0.0f, 0.0f, 0.0f, 0.0f), float depth = 1.0f, unsigned stencil = 0);
  79. /// Draw non-indexed geometry
  80. void Draw(PrimitiveType type, unsigned vertexStart, unsigned vertexCount);
  81. /// Draw indexed geometry
  82. void Draw(PrimitiveType type, unsigned indexStart, unsigned indexCount, unsigned minVertex, unsigned vertexCount);
  83. /// Draw indexed, instanced geometry. An instancing vertex buffer must be set
  84. void DrawInstanced(PrimitiveType type, unsigned indexStart, unsigned indexCount, unsigned minVertex, unsigned vertexCount, unsigned instanceCount);
  85. /// Set vertex buffer
  86. void SetVertexBuffer(VertexBuffer* buffer);
  87. /// Set multiple vertex buffers
  88. bool SetVertexBuffers(const Vector<VertexBuffer*>& buffers, const PODVector<unsigned>& elementMasks, unsigned instanceOffset = 0);
  89. /// Set multiple vertex buffers
  90. bool SetVertexBuffers(const Vector<SharedPtr<VertexBuffer> >& buffers, const PODVector<unsigned>& elementMasks, unsigned instanceOffset = 0);
  91. /// Set index buffer
  92. void SetIndexBuffer(IndexBuffer* buffer);
  93. /// Set shaders
  94. void SetShaders(ShaderVariation* vs, ShaderVariation* ps);
  95. /// Set shader bool parameter
  96. void SetShaderParameter(ShaderParameter param, const bool* data, unsigned count);
  97. /// Set shader float constants
  98. void SetShaderParameter(ShaderParameter param, const float* data, unsigned count);
  99. /// Set shader int constants
  100. void SetShaderParameter(ShaderParameter param, const int* data, unsigned count);
  101. /// Set shader float constant
  102. void SetShaderParameter(ShaderParameter param, float value);
  103. /// Set shader color constant
  104. void SetShaderParameter(ShaderParameter param, const Color& color);
  105. /// Set shader 3x3 matrix constant
  106. void SetShaderParameter(ShaderParameter param, const Matrix3& matrix);
  107. /// Set shader 3D vector constant
  108. void SetShaderParameter(ShaderParameter param, const Vector3& vector);
  109. /// Set shader 4x4 matrix constant
  110. void SetShaderParameter(ShaderParameter param, const Matrix4& matrix);
  111. /// Set shader 4D vector constant
  112. void SetShaderParameter(ShaderParameter param, const Vector4& vector);
  113. /// Set shader 4x3 matrix constant
  114. void SetShaderParameter(ShaderParameter param, const Matrix3x4& matrix);
  115. /// Map shader parameter to a constant register. Called by Shader
  116. void SetShaderRegister(ShaderParameter param, unsigned index) { shaderRegisters_[param] = index; }
  117. /// Check whether a shader parameter in the currently set shaders needs update
  118. bool NeedParameterUpdate(ShaderParameter parameter, const void* source);
  119. /// Check whether the current pixel shader uses a texture unit
  120. bool NeedTextureUnit(TextureUnit unit);
  121. /// Clear remembered shader parameter sources
  122. void ClearLastParameterSources();
  123. /// Clear remembered transform shader parameter sources
  124. void ClearTransformSources();
  125. /// Set texture
  126. void SetTexture(unsigned index, Texture* texture);
  127. /// Set default texture filtering mode
  128. void SetDefaultTextureFilterMode(TextureFilterMode mode);
  129. /// Reset all render targets and depth buffer (render to back buffer and back buffer depth stencil)
  130. void ResetRenderTargets();
  131. /// Reset specific render target
  132. void ResetRenderTarget(unsigned index);
  133. /// Reset depth stencil
  134. void ResetDepthStencil();
  135. /// Set render target
  136. void SetRenderTarget(unsigned index, RenderSurface* renderTarget);
  137. /// Set render target
  138. void SetRenderTarget(unsigned index, Texture2D* renderTexture);
  139. /// Set depth stencil buffer
  140. void SetDepthStencil(RenderSurface* depthStencil);
  141. /// Set depth stencil buffer
  142. void SetDepthStencil(Texture2D* depthTexture);
  143. /// Set viewport
  144. void SetViewport(const IntRect& rect);
  145. /// Set "view texture" to prevent sampling from the destination render target
  146. void SetViewTexture(Texture* texture);
  147. /// Set alpha test
  148. void SetAlphaTest(bool enable, CompareMode mode = CMP_ALWAYS, float alphaRef = 0.5f);
  149. /// Set texture anisotropy
  150. void SetTextureAnisotropy(unsigned level);
  151. /// Set blending mode
  152. void SetBlendMode(BlendMode mode);
  153. /// Set color write on/off
  154. void SetColorWrite(bool enable);
  155. /// Set hardware culling mode
  156. void SetCullMode(CullMode mode);
  157. /// Set depth bias
  158. void SetDepthBias(float constantBias, float slopeScaledBias);
  159. /// Set depth compare
  160. void SetDepthTest(CompareMode mode);
  161. /// Set depth write on/off
  162. void SetDepthWrite(bool enable);
  163. /// Set polygon fill mode
  164. void SetFillMode(FillMode mode);
  165. /// Set scissor test
  166. void SetScissorTest(bool enable, const Rect& rect = Rect::FULL, bool borderInclusive = true);
  167. /// Set scissor test
  168. void SetScissorTest(bool enable, const IntRect& rect);
  169. /// Set stencil test
  170. void SetStencilTest(bool enable, CompareMode mode = CMP_ALWAYS, StencilOp pass = OP_KEEP, StencilOp fail = OP_KEEP, StencilOp zFail = OP_KEEP, unsigned stencilRef = 0, unsigned stencilMask = M_MAX_UNSIGNED);
  171. /// Set vertex buffer stream frequency
  172. void SetStreamFrequency(unsigned index, unsigned frequency);
  173. /// Reset stream frequencies
  174. void ResetStreamFrequencies();
  175. /// Begin immediate rendering command
  176. bool BeginImmediate(PrimitiveType type, unsigned vertexCount, unsigned elementMask);
  177. /// Define immediate vertex
  178. bool DefineVertex(const Vector3& vertex);
  179. /// Define immediate normal
  180. bool DefineNormal(const Vector3& normal);
  181. /// Define immediate texture coordinate
  182. bool DefineTexCoord(const Vector2& texCoord);
  183. /// Define immediate color
  184. bool DefineColor(const Color& color);
  185. /// Define immediate color
  186. bool DefineColor(unsigned color);
  187. /// End immediate rendering command and render
  188. void EndImmediate();
  189. /// Set force Shader Model 2 flag. Needs to be set before setting initial screen mode to have effect.
  190. void SetForceSM2(bool enable);
  191. /// Return whether rendering initialized
  192. bool IsInitialized() const;
  193. /// Return graphics implementation, which holds the actual Direct3D resources
  194. GraphicsImpl* GetImpl() const { return impl_; }
  195. /// Return window title
  196. const String& GetWindowTitle() const { return windowTitle_; }
  197. /// Return rendering mode
  198. RenderMode GetRenderMode() const { return mode_; }
  199. /// Return window width
  200. int GetWidth() const { return width_; }
  201. /// Return window height
  202. int GetHeight() const { return height_; }
  203. /// Return multisample mode (0 = no multisampling)
  204. int GetMultiSample() const { return multiSample_; }
  205. /// Return whether window is fullscreen
  206. bool GetFullscreen() const { return fullscreen_; }
  207. /// Return whether vertical sync is on
  208. bool GetVSync() const { return vsync_; }
  209. /// Return whether GPU command queue is flushed at the end of each frame
  210. bool GetFlushGPU() const { return flushGPU_; }
  211. /// Return whether Direct3D device is lost, and can not yet render. This happens during fullscreen resolution switching
  212. bool IsDeviceLost() const { return deviceLost_; }
  213. /// Return immediate rendering data pointer
  214. unsigned char* GetImmediateDataPtr() const;
  215. /// Return window handle
  216. unsigned GetWindowHandle() const;
  217. /// Return number of primitives drawn this frame
  218. unsigned GetNumPrimitives() const { return numPrimitives_; }
  219. /// Return number of batches drawn this frame
  220. unsigned GetNumBatches() const { return numBatches_; }
  221. /// Return dummy color texture format for shadow maps. Is "NULL" (consume no video memory) if supported
  222. unsigned GetDummyColorFormat() const { return dummyColorFormat_; }
  223. /// Return shadow map depth texture format, or 0 if not supported
  224. unsigned GetShadowMapFormat() const { return shadowMapFormat_; }
  225. /// Return 24-bit shadow map depth texture format, or 0 if not supported
  226. unsigned GetHiresShadowMapFormat() const { return hiresShadowMapFormat_; }
  227. /// Return whether deferred rendering is supported
  228. bool GetDeferredSupport() const { return deferredSupport_; }
  229. /// Return whether light prepass rendering is supported
  230. bool GetPrepassSupport() const { return prepassSupport_; }
  231. /// Return whether Shader Model 3 is supported
  232. bool GetSM3Support() const { return hasSM3_; }
  233. /// Return whether shadow map depth compare is done in hardware
  234. bool GetHardwareShadowSupport() const { return hardwareShadowSupport_; }
  235. /// Return whether 24-bit shadow maps are supported
  236. bool GetHiresShadowSupport() const { return hiresShadowSupport_; }
  237. /// Return whether stream offset is supported
  238. bool GetStreamOffsetSupport() const { return streamOffsetSupport_; }
  239. /// Return supported fullscreen resolutions
  240. PODVector<IntVector2> GetResolutions() const;
  241. /// Return supported multisampling levels
  242. PODVector<int> GetMultiSampleLevels() const;
  243. /// Return vertex buffer by index
  244. VertexBuffer* GetVertexBuffer(unsigned index) const;
  245. /// Return index buffer
  246. IndexBuffer* GetIndexBuffer() const { return indexBuffer_; }
  247. /// Return vertex declaration
  248. VertexDeclaration* GetVertexDeclaration() const { return vertexDeclaration_; }
  249. /// Return vertex shader
  250. ShaderVariation* GetVertexShader() const { return vertexShader_; }
  251. /// Return pixel shader
  252. ShaderVariation* GetPixelShader() const { return pixelShader_; }
  253. /// Return shader parameter index by name
  254. ShaderParameter GetShaderParameter(const String& name);
  255. /// Return texture unit index by name
  256. TextureUnit GetTextureUnit(const String& name);
  257. /// Return shader parameter name by index
  258. const String& GetShaderParameterName(ShaderParameter parameter);
  259. /// Return texture unit name by index
  260. const String& GetTextureUnitName(TextureUnit unit);
  261. /// Return vertex shader constant register by parameter index
  262. unsigned GetVSRegister(ShaderParameter param) { return shaderRegisters_[param]; }
  263. /// Return pixel shader constant register by parameter index
  264. unsigned GetPSRegister(ShaderParameter param) { return shaderRegisters_[param]; }
  265. /// Return texture by texture unit index
  266. Texture* GetTexture(unsigned index) const;
  267. /// Return the "view texture"
  268. Texture* GetViewTexture() const { return viewTexture_; }
  269. /// Return default texture filtering mode
  270. TextureFilterMode GetDefaultTextureFilterMode() const { return defaultTextureFilterMode_; }
  271. /// Return render target by index
  272. RenderSurface* GetRenderTarget(unsigned index) const;
  273. /// Return depth stencil buffer
  274. RenderSurface* GetDepthStencil() const { return depthStencil_; }
  275. /// Return the viewport coordinates
  276. IntRect GetViewport() const { return viewport_; }
  277. /// Return whether alpha testing is enabled
  278. bool GetAlphaTest() const { return alphaTest_; }
  279. /// Return alpha test compare mode
  280. CompareMode GetAlphaTestMode() const { return alphaTestMode_; }
  281. /// Return texture anisotropy
  282. unsigned GetTextureAnisotropy() const { return textureAnisotropy_; }
  283. /// Return alpha test reference value
  284. float GetAlphaRef() const { return alphaRef_; }
  285. /// Return blending mode
  286. BlendMode GetBlendMode() const { return blendMode_; }
  287. /// Return whether color write is enabled
  288. bool GetColorWrite() const { return colorWrite_; }
  289. /// Return hardware culling mode
  290. CullMode GetCullMode() const { return cullMode_; }
  291. /// Return depth constant bias
  292. float GetDepthConstantBias() const { return constantDepthBias_; }
  293. /// Return depth slope scaled bias
  294. float GetDepthSlopeScaledBias() const { return slopeScaledDepthBias_; }
  295. /// Return depth compare mode
  296. CompareMode GetDepthTest() const { return depthTestMode_; }
  297. /// Return whether depth write is enabled
  298. bool GetDepthWrite() const { return depthWrite_; }
  299. /// Return polygon fill mode
  300. FillMode GetFillMode() const { return fillMode_; }
  301. /// Return whether stencil test is enabled
  302. bool GetStencilTest() const { return stencilTest_; }
  303. /// Return whether scissor test is enabled
  304. bool GetScissorTest() const { return scissorTest_; }
  305. /// Return scissor rectangle coordinates
  306. const IntRect& GetScissorRect() const { return scissorRect_; }
  307. /// Return stencil compare mode
  308. CompareMode GetStencilTestMode() const { return stencilTestMode_; }
  309. /// Return stencil operation to do if stencil test passes
  310. StencilOp GetStencilPass() const { return stencilPass_; }
  311. /// Return stencil operation to do if stencil test fails
  312. StencilOp GetStencilFail() const { return stencilFail_; }
  313. /// Return stencil operation to do if depth compare fails
  314. StencilOp GetStencilZFail() const { return stencilZFail_; }
  315. /// Return stencil reference value
  316. unsigned GetStencilRef() const { return stencilRef_; }
  317. /// Return stencil compare bitmask
  318. unsigned GetStencilMask() const { return stencilMask_; }
  319. /// Return stream frequency by vertex buffer index
  320. unsigned GetStreamFrequency(unsigned index) const;
  321. /// Return render target width and height
  322. IntVector2 GetRenderTargetDimensions() const;
  323. /// Return diffuse buffer for deferred rendering
  324. Texture2D* GetDiffBuffer() const { return diffBuffer_; }
  325. /// Return normal buffer for deferred rendering
  326. Texture2D* GetNormalBuffer() const { return normalBuffer_; }
  327. /// Return depth buffer for deferred rendering. If reading hardware depth is supported, return a depth texture
  328. Texture2D* GetDepthBuffer() const { return depthBuffer_; }
  329. /// Return screen buffer for post-processing
  330. Texture2D* GetScreenBuffer(unsigned index) const { return screenBuffers_[index & (NUM_SCREEN_BUFFERS - 1)]; }
  331. /// Add a GPU object to keep track of. Called by GPUObject.
  332. void AddGPUObject(GPUObject* object);
  333. /// Remove a GPU object. Called by GPUObject
  334. void RemoveGPUObject(GPUObject* object);
  335. /// Return the API-specific alpha texture format
  336. static unsigned GetAlphaFormat();
  337. /// Return the API-specific luminance texture format
  338. static unsigned GetLuminanceFormat();
  339. /// Return the API-specific luminance alpha texture format
  340. static unsigned GetLuminanceAlphaFormat();
  341. /// Return the API-specific RGB texture format
  342. static unsigned GetRGBFormat();
  343. /// Return the API-specific RGBA texture format
  344. static unsigned GetRGBAFormat();
  345. /// Return the API-specific deferred rendering depth texture format
  346. static unsigned GetDepthFormat();
  347. private:
  348. /// Create the application window
  349. bool OpenWindow(int width, int height);
  350. /// Create the Direct3D interface
  351. bool CreateInterface();
  352. /// Create the Direct3D device
  353. bool CreateDevice(unsigned adapter, unsigned deviceType);
  354. /// Create deferred rendering render targets
  355. void CreateRenderTargets();
  356. /// Reset the Direct3D device
  357. void ResetDevice();
  358. /// Notify all GPU resources so they can release themselves as needed
  359. void OnDeviceLost();
  360. /// Notify all GPU resources so they can recreate themselves as needed
  361. void OnDeviceReset();
  362. /// Reset cached rendering state
  363. void ResetCachedState();
  364. /// Initialize shader parameter and texture unit mappings
  365. void InitializeShaderParameters();
  366. /// Handle operating system window message
  367. void HandleWindowMessage(StringHash eventType, VariantMap& eventData);
  368. /// Implementation
  369. GraphicsImpl* impl_;
  370. /// Window title
  371. String windowTitle_;
  372. /// Rendering mode
  373. RenderMode mode_;
  374. /// Window width
  375. int width_;
  376. /// Window height
  377. int height_;
  378. /// Multisampling mode
  379. int multiSample_;
  380. /// Stored window X-position
  381. int windowPosX_;
  382. /// Stored window Y-position
  383. int windowPosY_;
  384. /// Fullscreen flag
  385. bool fullscreen_;
  386. /// Vertical sync flag
  387. bool vsync_;
  388. /// Flush GPU command queue flag
  389. bool flushGPU_;
  390. /// Direct3D device lost flag
  391. bool deviceLost_;
  392. /// Query issued (used to flush the GPU command queue) flag
  393. bool queryIssued_;
  394. /// Deferred rendering support flag
  395. bool deferredSupport_;
  396. /// Light prepass support flag
  397. bool prepassSupport_;
  398. /// Hardware shadow map depth compare support flag
  399. bool hardwareShadowSupport_;
  400. /// 24-bit shadow map support flag
  401. bool hiresShadowSupport_;
  402. /// Stream offset support flag
  403. bool streamOffsetSupport_;
  404. /// Shader Model 3 flag
  405. bool hasSM3_;
  406. /// Force Shader Model 2 flag
  407. bool forceSM2_;
  408. /// Number of primitives this frame
  409. unsigned numPrimitives_;
  410. /// Number of batches this frame
  411. unsigned numBatches_;
  412. /// Immediate rendering primitive type
  413. PrimitiveType immediateType_;
  414. /// Immediate vertex buffer start position
  415. unsigned immediateStartPos_;
  416. /// Immediate rendering vertex buffer size
  417. unsigned immediateVertexCount_;
  418. /// Immediate rendering vertex number
  419. unsigned immediateCurrentVertex_;
  420. /// Immediate rendering vertex buffer in use
  421. VertexBuffer* immediateBuffer_;
  422. /// Immediate rendering data pointer
  423. unsigned char* immediateDataPtr_;
  424. /// GPU objects
  425. Vector<GPUObject*> gpuObjects_;
  426. /// Vertex declarations
  427. Map<unsigned long long, SharedPtr<VertexDeclaration> > vertexDeclarations_;
  428. /// Immediate rendering vertex buffers by vertex declaration
  429. Map<unsigned, SharedPtr<VertexBuffer> > immediateVertexBuffers_;
  430. /// Immediate rendering vertex buffer start positions
  431. Map<unsigned, unsigned> immediateVertexBufferPos_;
  432. /// Deferred rendering diffuse buffer
  433. SharedPtr<Texture2D> diffBuffer_;
  434. /// Deferred rendering normal buffer
  435. SharedPtr<Texture2D> normalBuffer_;
  436. /// Deferred rendering depth buffer
  437. SharedPtr<Texture2D> depthBuffer_;
  438. /// Screen buffers for post processing
  439. SharedPtr<Texture2D> screenBuffers_[NUM_SCREEN_BUFFERS];
  440. /// Shadow map dummy color texture format
  441. unsigned dummyColorFormat_;
  442. /// Shadow map depth texture format
  443. unsigned shadowMapFormat_;
  444. /// Shadow map 24-bit depth texture format
  445. unsigned hiresShadowMapFormat_;
  446. /// Vertex buffers in use
  447. VertexBuffer* vertexBuffers_[MAX_VERTEX_STREAMS];
  448. /// Stream frequencies by vertex buffer
  449. unsigned streamFrequencies_[MAX_VERTEX_STREAMS];
  450. /// Stream offsets by vertex buffer
  451. unsigned streamOffsets_[MAX_VERTEX_STREAMS];
  452. /// Index buffer in use
  453. IndexBuffer* indexBuffer_;
  454. /// Vertex declaration in use
  455. VertexDeclaration* vertexDeclaration_;
  456. /// Vertex shader in use
  457. ShaderVariation* vertexShader_;
  458. /// Pixel shader in use
  459. ShaderVariation* pixelShader_;
  460. /// Shader parameter mappings
  461. Map<String, ShaderParameter> shaderParameters_;
  462. /// Shader constant register mappings
  463. unsigned shaderRegisters_[MAX_SHADER_PARAMETERS];
  464. /// Last shader parameter sources per parameter
  465. const void* lastShaderParameterSources_[MAX_SHADER_PARAMETERS];
  466. /// Textures in use
  467. Texture* textures_[MAX_TEXTURE_UNITS];
  468. /// "View texture" to prevent sampling the destination render target
  469. Texture* viewTexture_;
  470. /// Texture unit mappings
  471. Map<String, TextureUnit> textureUnits_;
  472. /// Render targets in use
  473. RenderSurface* renderTargets_[MAX_RENDERTARGETS];
  474. /// Depth stencil buffer in use
  475. RenderSurface* depthStencil_;
  476. /// Viewport coordinates
  477. IntRect viewport_;
  478. /// Alpha test enable flag
  479. bool alphaTest_;
  480. /// Alpha test compare mode
  481. CompareMode alphaTestMode_;
  482. /// Alpha test reference value
  483. float alphaRef_;
  484. /// Texture anisotropy level
  485. unsigned textureAnisotropy_;
  486. /// Blending mode
  487. BlendMode blendMode_;
  488. /// Color write enable
  489. bool colorWrite_;
  490. /// Hardware culling mode
  491. CullMode cullMode_;
  492. /// Depth constant bias
  493. float constantDepthBias_;
  494. /// Depth slope scaled bias
  495. float slopeScaledDepthBias_;
  496. /// Depth compare mode
  497. CompareMode depthTestMode_;
  498. /// Depth write enable flag
  499. bool depthWrite_;
  500. /// Polygon fill mode
  501. FillMode fillMode_;
  502. /// Scissor test rectangle
  503. IntRect scissorRect_;
  504. /// Scissor test enable flag
  505. bool scissorTest_;
  506. /// Stencil test compare mode
  507. CompareMode stencilTestMode_;
  508. /// Stencil operation on pass
  509. StencilOp stencilPass_;
  510. /// Stencil operation on fail
  511. StencilOp stencilFail_;
  512. /// Stencil operation on depth fail
  513. StencilOp stencilZFail_;
  514. /// Stencil test enable flag
  515. bool stencilTest_;
  516. /// Stencil test reference value
  517. unsigned stencilRef_;
  518. /// Stencil compare bitmask
  519. unsigned stencilMask_;
  520. /// Default texture filtering mode
  521. TextureFilterMode defaultTextureFilterMode_;
  522. };
  523. /// Register Graphics library objects
  524. void RegisterGraphicsLibrary(Context* context);