D3D9Graphics.h 24 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118119120121122123124125126127128129130131132133134135136137138139140141142143144145146147148149150151152153154155156157158159160161162163164165166167168169170171172173174175176177178179180181182183184185186187188189190191192193194195196197198199200201202203204205206207208209210211212213214215216217218219220221222223224225226227228229230231232233234235236237238239240241242243244245246247248249250251252253254255256257258259260261262263264265266267268269270271272273274275276277278279280281282283284285286287288289290291292293294295296297298299300301302303304305306307308309310311312313314315316317318319320321322323324325326327328329330331332333334335336337338339340341342343344345346347348349350351352353354355356357358359360361362363364365366367368369370371372373374375376377378379380381382383384385386387388389390391392393394395396397398399400401402403404405406407408409410411412413414415416417418419420421422423424425426427428429430431432433434435436437438439440441442443444445446447448449450451452453454455456457458459460461462463464465466467468469470471472473474475476477478479480481482483484485486487488489490491492493494495496497498499500501502503504505506507508509510511512513514515516517518519520521522523524525526527528529530531532533534535536537538539540541542543544545546547548549550551
  1. //
  2. // Copyright (c) 2008-2013 the Urho3D project.
  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 deal
  6. // in the Software without restriction, including without limitation the rights
  7. // to use, copy, modify, merge, publish, distribute, sublicense, and/or sell
  8. // 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 FROM,
  19. // OUT OF OR IN CONNECTION WITH THE SOFTWARE OR THE USE OR OTHER DEALINGS IN
  20. // THE SOFTWARE.
  21. //
  22. #pragma once
  23. #include "ArrayPtr.h"
  24. #include "Color.h"
  25. #include "Image.h"
  26. #include "Object.h"
  27. #include "Rect.h"
  28. #include "GraphicsDefs.h"
  29. namespace Urho3D
  30. {
  31. class Image;
  32. class IndexBuffer;
  33. class Matrix3;
  34. class Matrix4;
  35. class Matrix3x4;
  36. class GPUObject;
  37. class GraphicsImpl;
  38. class RenderSurface;
  39. class ShaderVariation;
  40. class Texture;
  41. class Texture2D;
  42. class TextureCube;
  43. class Vector3;
  44. class Vector4;
  45. class VertexBuffer;
  46. class VertexDeclaration;
  47. struct ShaderParameter;
  48. /// CPU-side scratch buffer for vertex data updates.
  49. struct ScratchBuffer
  50. {
  51. ScratchBuffer() :
  52. size_(0),
  53. reserved_(false)
  54. {
  55. }
  56. /// Buffer data.
  57. SharedArrayPtr<unsigned char> data_;
  58. /// Data size.
  59. unsigned size_;
  60. /// Reserved flag.
  61. bool reserved_;
  62. };
  63. /// %Graphics subsystem. Manages the application window, rendering state and GPU resources.
  64. class URHO3D_API Graphics : public Object
  65. {
  66. OBJECT(Graphics);
  67. public:
  68. /// Construct.
  69. Graphics(Context* context);
  70. /// Destruct. Release the Direct3D9 device and close the window.
  71. virtual ~Graphics();
  72. /// Set external window handle. Only effective before setting the initial screen mode.
  73. void SetExternalWindow(void* window);
  74. /// Set window title.
  75. void SetWindowTitle(const String& windowTitle);
  76. /// Set window position.
  77. void SetWindowPosition(const IntVector2& position);
  78. /// Set window position.
  79. void SetWindowPosition(int x, int y);
  80. /// Set screen mode. Return true if successful.
  81. bool SetMode(int width, int height, bool fullscreen, bool resizable, bool vsync, bool tripleBuffer, int multiSample);
  82. /// Set screen resolution only. Return true if successful.
  83. bool SetMode(int width, int height);
  84. /// Set whether the main window uses sRGB conversion on write.
  85. void SetSRGB(bool enable);
  86. /// Set whether to flush the GPU command buffer to prevent multiple frames being queued and uneven frame timesteps. Default off, may decrease performance if enabled.
  87. void SetFlushGPU(bool enable);
  88. /// Toggle between full screen and windowed mode. Return true if successful.
  89. bool ToggleFullscreen();
  90. /// Close the window.
  91. void Close();
  92. /// Take a screenshot. Return true if successful.
  93. bool TakeScreenShot(Image& destImage);
  94. /// Begin frame rendering. Return true if device available and can render.
  95. bool BeginFrame();
  96. /// End frame rendering and swap buffers.
  97. void EndFrame();
  98. /// Clear any or all of rendertarget, depth buffer and stencil buffer.
  99. void Clear(unsigned flags, const Color& color = Color(0.0f, 0.0f, 0.0f, 0.0f), float depth = 1.0f, unsigned stencil = 0);
  100. /// Resolve multisampled backbuffer to a texture rendertarget.
  101. bool ResolveToTexture(Texture2D* destination, const IntRect& viewport);
  102. /// Draw non-indexed geometry.
  103. void Draw(PrimitiveType type, unsigned vertexStart, unsigned vertexCount);
  104. /// Draw indexed geometry.
  105. void Draw(PrimitiveType type, unsigned indexStart, unsigned indexCount, unsigned minVertex, unsigned vertexCount);
  106. /// Draw indexed, instanced geometry. An instancing vertex buffer must be set.
  107. void DrawInstanced(PrimitiveType type, unsigned indexStart, unsigned indexCount, unsigned minVertex, unsigned vertexCount, unsigned instanceCount);
  108. /// Set vertex buffer.
  109. void SetVertexBuffer(VertexBuffer* buffer);
  110. /// Set multiple vertex buffers.
  111. bool SetVertexBuffers(const PODVector<VertexBuffer*>& buffers, const PODVector<unsigned>& elementMasks, unsigned instanceOffset = 0);
  112. /// Set multiple vertex buffers.
  113. bool SetVertexBuffers(const Vector<SharedPtr<VertexBuffer> >& buffers, const PODVector<unsigned>& elementMasks, unsigned instanceOffset = 0);
  114. /// Set index buffer.
  115. void SetIndexBuffer(IndexBuffer* buffer);
  116. /// Set shaders.
  117. void SetShaders(ShaderVariation* vs, ShaderVariation* ps);
  118. /// Set shader float constants.
  119. void SetShaderParameter(StringHash param, const float* data, unsigned count);
  120. /// Set shader float constant.
  121. void SetShaderParameter(StringHash param, float value);
  122. /// Set shader boolean constant.
  123. void SetShaderParameter(StringHash param, bool value);
  124. /// Set shader color constant.
  125. void SetShaderParameter(StringHash param, const Color& color);
  126. /// Set shader 2D vector constant.
  127. void SetShaderParameter(StringHash param, const Vector2& vector);
  128. /// Set shader 3x3 matrix constant.
  129. void SetShaderParameter(StringHash param, const Matrix3& matrix);
  130. /// Set shader 3D vector constant.
  131. void SetShaderParameter(StringHash param, const Vector3& vector);
  132. /// Set shader 4x4 matrix constant.
  133. void SetShaderParameter(StringHash param, const Matrix4& matrix);
  134. /// Set shader 4D vector constant.
  135. void SetShaderParameter(StringHash param, const Vector4& vector);
  136. /// Set shader 3x4 matrix constant.
  137. void SetShaderParameter(StringHash param, const Matrix3x4& matrix);
  138. /// Set shader constant from a variant. Supported variant types: bool, float, vector2, vector3, vector4, color.
  139. void SetShaderParameter(StringHash param, const Variant& value);
  140. /// Register a shader parameter globally. Called by Shader.
  141. void RegisterShaderParameter(StringHash param, const ShaderParameter& definition);
  142. /// Check whether a shader parameter group needs update. Does not actually check whether parameters exist in the shaders.
  143. bool NeedParameterUpdate(ShaderParameterGroup group, const void* source);
  144. /// Check whether a shader parameter exists on the currently set shaders.
  145. bool HasShaderParameter(ShaderType type, StringHash param);
  146. /// Check whether the current pixel shader uses a texture unit.
  147. bool HasTextureUnit(TextureUnit unit);
  148. /// Clear remembered shader parameter source group.
  149. void ClearParameterSource(ShaderParameterGroup group);
  150. /// Clear remembered shader parameter sources.
  151. void ClearParameterSources();
  152. /// Clear remembered transform shader parameter sources.
  153. void ClearTransformSources();
  154. /// Set texture.
  155. void SetTexture(unsigned index, Texture* texture);
  156. /// Set default texture filtering mode.
  157. void SetDefaultTextureFilterMode(TextureFilterMode mode);
  158. /// Set texture anisotropy.
  159. void SetTextureAnisotropy(unsigned level);
  160. /// Reset all rendertargets, depth-stencil surface and viewport.
  161. void ResetRenderTargets();
  162. /// Reset specific rendertarget.
  163. void ResetRenderTarget(unsigned index);
  164. /// Reset depth-stencil surface.
  165. void ResetDepthStencil();
  166. /// Set rendertarget.
  167. void SetRenderTarget(unsigned index, RenderSurface* renderTarget);
  168. /// Set rendertarget.
  169. void SetRenderTarget(unsigned index, Texture2D* texture);
  170. /// Set depth-stencil surface.
  171. void SetDepthStencil(RenderSurface* depthStencil);
  172. /// Set depth-stencil surface.
  173. void SetDepthStencil(Texture2D* texture);
  174. /// Set view texture (deferred rendering final output rendertarget) to prevent it from being sampled.
  175. void SetViewTexture(Texture* texture);
  176. /// Set viewport.
  177. void SetViewport(const IntRect& rect);
  178. /// Set blending mode.
  179. void SetBlendMode(BlendMode mode);
  180. /// Set color write on/off.
  181. void SetColorWrite(bool enable);
  182. /// Set hardware culling mode.
  183. void SetCullMode(CullMode mode);
  184. /// Set depth bias.
  185. void SetDepthBias(float constantBias, float slopeScaledBias);
  186. /// Set depth compare.
  187. void SetDepthTest(CompareMode mode);
  188. /// Set depth write on/off.
  189. void SetDepthWrite(bool enable);
  190. /// Set polygon fill mode.
  191. void SetFillMode(FillMode mode);
  192. /// Set scissor test.
  193. void SetScissorTest(bool enable, const Rect& rect = Rect::FULL, bool borderInclusive = true);
  194. /// Set scissor test.
  195. void SetScissorTest(bool enable, const IntRect& rect);
  196. /// Set stencil test.
  197. void SetStencilTest(bool enable, CompareMode mode = CMP_ALWAYS, StencilOp pass = OP_KEEP, StencilOp fail = OP_KEEP, StencilOp zFail = OP_KEEP, unsigned stencilRef = 0, unsigned compareMask = M_MAX_UNSIGNED, unsigned writeMask = M_MAX_UNSIGNED);
  198. /// Set vertex buffer stream frequency.
  199. void SetStreamFrequency(unsigned index, unsigned frequency);
  200. /// Reset stream frequencies.
  201. void ResetStreamFrequencies();
  202. /// Set force Shader Model 2 flag. Only effective before setting the initial screen mode.
  203. void SetForceSM2(bool enable);
  204. /// Return whether rendering initialized.
  205. bool IsInitialized() const;
  206. /// Return graphics implementation, which holds the actual API-specific resources.
  207. GraphicsImpl* GetImpl() const { return impl_; }
  208. /// Return OS-specific external window handle. Null if not in use.
  209. void* GetExternalWindow() const { return externalWindow_; }
  210. /// Return window title.
  211. const String& GetWindowTitle() const { return windowTitle_; }
  212. /// Return window position.
  213. IntVector2 GetWindowPosition() const;
  214. /// Return window width.
  215. int GetWidth() const { return width_; }
  216. /// Return window height.
  217. int GetHeight() const { return height_; }
  218. /// Return multisample mode (1 = no multisampling.)
  219. int GetMultiSample() const { return multiSample_; }
  220. /// Return whether window is fullscreen.
  221. bool GetFullscreen() const { return fullscreen_; }
  222. /// Return whether window is resizable.
  223. bool GetResizable() const { return resizable_; }
  224. /// Return whether vertical sync is on.
  225. bool GetVSync() const { return vsync_; }
  226. /// Return whether triple buffering is enabled.
  227. bool GetTripleBuffer() const { return tripleBuffer_; }
  228. /// Return whether the main window is using sRGB conversion on write.
  229. bool GetSRGB() const { return sRGB_; }
  230. /// Return whether the GPU command buffer is flushed each frame.
  231. bool GetFlushGPU() const { return flushGPU_; }
  232. /// Return whether Direct3D device is lost, and can not yet render. This happens during fullscreen resolution switching.
  233. bool IsDeviceLost() const { return deviceLost_; }
  234. /// Return number of primitives drawn this frame.
  235. unsigned GetNumPrimitives() const { return numPrimitives_; }
  236. /// Return number of batches drawn this frame.
  237. unsigned GetNumBatches() const { return numBatches_; }
  238. /// Return dummy color texture format for shadow maps. Is "NULL" (consume no video memory) if supported.
  239. unsigned GetDummyColorFormat() const { return dummyColorFormat_; }
  240. /// Return shadow map depth texture format, or 0 if not supported.
  241. unsigned GetShadowMapFormat() const { return shadowMapFormat_; }
  242. /// Return 24-bit shadow map depth texture format, or 0 if not supported.
  243. unsigned GetHiresShadowMapFormat() const { return hiresShadowMapFormat_; }
  244. /// Return whether Shader Model 3 is supported.
  245. bool GetSM3Support() const { return hasSM3_; }
  246. /// Return whether hardware instancing is supported.
  247. bool GetInstancingSupport() const { return hasSM3_; }
  248. /// Return whether light pre-pass rendering is supported.
  249. bool GetLightPrepassSupport() const { return lightPrepassSupport_; }
  250. /// Return whether deferred rendering is supported.
  251. bool GetDeferredSupport() const { return deferredSupport_; }
  252. /// Return whether shadow map depth compare is done in hardware.
  253. bool GetHardwareShadowSupport() const { return hardwareShadowSupport_; }
  254. /// Return whether stream offset is supported.
  255. bool GetStreamOffsetSupport() const { return streamOffsetSupport_; }
  256. /// Return whether sRGB conversion on texture sampling is supported.
  257. bool GetSRGBSupport() const { return sRGBSupport_; }
  258. /// Return whether sRGB conversion on rendertarget writing is supported.
  259. bool GetSRGBWriteSupport() const { return sRGBWriteSupport_; }
  260. /// Return supported fullscreen resolutions.
  261. PODVector<IntVector2> GetResolutions() const;
  262. /// Return supported multisampling levels.
  263. PODVector<int> GetMultiSampleLevels() const;
  264. /// Return the desktop resolution.
  265. IntVector2 GetDesktopResolution() const;
  266. /// Return hardware format for a compressed image format, or 0 if unsupported.
  267. unsigned GetFormat(CompressedFormat format) const;
  268. /// Return vertex buffer by index.
  269. VertexBuffer* GetVertexBuffer(unsigned index) const;
  270. /// Return current index buffer.
  271. IndexBuffer* GetIndexBuffer() const { return indexBuffer_; }
  272. /// Return current vertex declaration.
  273. VertexDeclaration* GetVertexDeclaration() const { return vertexDeclaration_; }
  274. /// Return current vertex shader.
  275. ShaderVariation* GetVertexShader() const { return vertexShader_; }
  276. /// Return current pixel shader.
  277. ShaderVariation* GetPixelShader() const { return pixelShader_; }
  278. /// Return texture unit index by name.
  279. TextureUnit GetTextureUnit(const String& name);
  280. /// Return current texture by texture unit index.
  281. Texture* GetTexture(unsigned index) const;
  282. /// Return default texture filtering mode.
  283. TextureFilterMode GetDefaultTextureFilterMode() const { return defaultTextureFilterMode_; }
  284. /// Return current rendertarget by index.
  285. RenderSurface* GetRenderTarget(unsigned index) const;
  286. /// Return current depth-stencil surface.
  287. RenderSurface* GetDepthStencil() const { return depthStencil_; }
  288. /// Return the viewport coordinates.
  289. IntRect GetViewport() const { return viewport_; }
  290. /// Return texture anisotropy.
  291. unsigned GetTextureAnisotropy() const { return textureAnisotropy_; }
  292. /// Return blending mode.
  293. BlendMode GetBlendMode() const { return blendMode_; }
  294. /// Return whether color write is enabled.
  295. bool GetColorWrite() const { return colorWrite_; }
  296. /// Return hardware culling mode.
  297. CullMode GetCullMode() const { return cullMode_; }
  298. /// Return depth constant bias.
  299. float GetDepthConstantBias() const { return constantDepthBias_; }
  300. /// Return depth slope scaled bias.
  301. float GetDepthSlopeScaledBias() const { return slopeScaledDepthBias_; }
  302. /// Return depth compare mode.
  303. CompareMode GetDepthTest() const { return depthTestMode_; }
  304. /// Return whether depth write is enabled.
  305. bool GetDepthWrite() const { return depthWrite_; }
  306. /// Return polygon fill mode.
  307. FillMode GetFillMode() const { return fillMode_; }
  308. /// Return whether stencil test is enabled.
  309. bool GetStencilTest() const { return stencilTest_; }
  310. /// Return whether scissor test is enabled.
  311. bool GetScissorTest() const { return scissorTest_; }
  312. /// Return scissor rectangle coordinates.
  313. const IntRect& GetScissorRect() const { return scissorRect_; }
  314. /// Return stencil compare mode.
  315. CompareMode GetStencilTestMode() const { return stencilTestMode_; }
  316. /// Return stencil operation to do if stencil test passes.
  317. StencilOp GetStencilPass() const { return stencilPass_; }
  318. /// Return stencil operation to do if stencil test fails.
  319. StencilOp GetStencilFail() const { return stencilFail_; }
  320. /// Return stencil operation to do if depth compare fails.
  321. StencilOp GetStencilZFail() const { return stencilZFail_; }
  322. /// Return stencil reference value.
  323. unsigned GetStencilRef() const { return stencilRef_; }
  324. /// Return stencil compare bitmask.
  325. unsigned GetStencilCompareMask() const { return stencilCompareMask_; }
  326. /// Return stencil write bitmask.
  327. unsigned GetStencilWriteMask() const { return stencilWriteMask_; }
  328. /// Return stream frequency by vertex buffer index.
  329. unsigned GetStreamFrequency(unsigned index) const;
  330. /// Return rendertarget width and height.
  331. IntVector2 GetRenderTargetDimensions() const;
  332. /// Return force Shader Model 2 flag.
  333. bool GetForceSM2() const { return forceSM2_; }
  334. /// Window was resized through user interaction. Called by Input subsystem.
  335. void WindowResized();
  336. /// Add a GPU object to keep track of. Called by GPUObject.
  337. void AddGPUObject(GPUObject* object);
  338. /// Remove a GPU object. Called by GPUObject.
  339. void RemoveGPUObject(GPUObject* object);
  340. /// Reserve a CPU-side scratch buffer.
  341. void* ReserveScratchBuffer(unsigned size);
  342. /// Free a CPU-side scratch buffer.
  343. void FreeScratchBuffer(void* buffer);
  344. /// Clean up too large scratch buffers.
  345. void CleanupScratchBuffers();
  346. /// Return the API-specific alpha texture format.
  347. static unsigned GetAlphaFormat();
  348. /// Return the API-specific luminance texture format.
  349. static unsigned GetLuminanceFormat();
  350. /// Return the API-specific luminance alpha texture format.
  351. static unsigned GetLuminanceAlphaFormat();
  352. /// Return the API-specific RGB texture format.
  353. static unsigned GetRGBFormat();
  354. /// Return the API-specific RGBA texture format.
  355. static unsigned GetRGBAFormat();
  356. /// Return the API-specific RGBA 16-bit texture format.
  357. static unsigned GetRGBA16Format();
  358. /// Return the API-specific RGBA 16-bit float texture format.
  359. static unsigned GetRGBAFloat16Format();
  360. /// Return the API-specific RGBA 32-bit float texture format.
  361. static unsigned GetRGBAFloat32Format();
  362. /// Return the API-specific RG 16-bit texture format.
  363. static unsigned GetRG16Format();
  364. /// Return the API-specific RG 16-bit float texture format.
  365. static unsigned GetRGFloat16Format();
  366. /// Return the API-specific RG 32-bit float texture format.
  367. static unsigned GetRGFloat32Format();
  368. /// Return the API-specific single channel 16-bit float texture format.
  369. static unsigned GetFloat16Format();
  370. /// Return the API-specific single channel 32-bit float texture format.
  371. static unsigned GetFloat32Format();
  372. /// Return the API-specific linear depth texture format.
  373. static unsigned GetLinearDepthFormat();
  374. /// Return the API-specific hardware depth-stencil texture format.
  375. static unsigned GetDepthStencilFormat();
  376. /// Return the API-specific texture format from a textual description, for example "rgb".
  377. static unsigned GetFormat(const String& formatName);
  378. private:
  379. /// Create the application window.
  380. bool OpenWindow(int width, int height, bool resizable);
  381. /// Adjust the window for new resolution and fullscreen mode.
  382. void AdjustWindow(int& newWidth, int& newHeight, bool& newFullscreen);
  383. /// Create the Direct3D interface.
  384. bool CreateInterface();
  385. /// Create the Direct3D device.
  386. bool CreateDevice(unsigned adapter, unsigned deviceType);
  387. /// Check supported rendering features.
  388. void CheckFeatureSupport();
  389. /// Reset the Direct3D device.
  390. void ResetDevice();
  391. /// Notify all GPU resources so they can release themselves as needed.
  392. void OnDeviceLost();
  393. /// Notify all GPU resources so they can recreate themselves as needed.
  394. void OnDeviceReset();
  395. /// Reset cached rendering state.
  396. void ResetCachedState();
  397. /// Initialize texture unit mappings.
  398. void SetTextureUnitMappings();
  399. /// Implementation.
  400. GraphicsImpl* impl_;
  401. /// Window title.
  402. String windowTitle_;
  403. /// External window, null if not in use (default.)
  404. void* externalWindow_;
  405. /// Window width.
  406. int width_;
  407. /// Window height.
  408. int height_;
  409. /// Multisampling mode.
  410. int multiSample_;
  411. /// Fullscreen flag.
  412. bool fullscreen_;
  413. /// Resizable flag.
  414. bool resizable_;
  415. /// Vertical sync flag.
  416. bool vsync_;
  417. /// Triple buffering flag.
  418. bool tripleBuffer_;
  419. /// Flush GPU command buffer flag.
  420. bool flushGPU_;
  421. /// sRGB conversion on write flag for the main window.
  422. bool sRGB_;
  423. /// Direct3D device lost flag.
  424. bool deviceLost_;
  425. /// Flush query issued flag.
  426. bool queryIssued_;
  427. /// Light pre-pass rendering support flag.
  428. bool lightPrepassSupport_;
  429. /// Deferred rendering support flag.
  430. bool deferredSupport_;
  431. /// Hardware shadow map depth compare support flag.
  432. bool hardwareShadowSupport_;
  433. /// Stream offset support flag.
  434. bool streamOffsetSupport_;
  435. /// sRGB conversion on read support flag.
  436. bool sRGBSupport_;
  437. /// sRGB conversion on write support flag.
  438. bool sRGBWriteSupport_;
  439. /// Shader Model 3 flag.
  440. bool hasSM3_;
  441. /// Force Shader Model 2 flag.
  442. bool forceSM2_;
  443. /// Number of primitives this frame.
  444. unsigned numPrimitives_;
  445. /// Number of batches this frame.
  446. unsigned numBatches_;
  447. /// Largest scratch buffer request this frame.
  448. unsigned maxScratchBufferRequest_;
  449. /// GPU objects.
  450. Vector<GPUObject*> gpuObjects_;
  451. /// Scratch buffers.
  452. Vector<ScratchBuffer> scratchBuffers_;
  453. /// Vertex declarations.
  454. HashMap<unsigned long long, SharedPtr<VertexDeclaration> > vertexDeclarations_;
  455. /// Shadow map dummy color texture format.
  456. unsigned dummyColorFormat_;
  457. /// Shadow map depth texture format.
  458. unsigned shadowMapFormat_;
  459. /// Shadow map 24-bit depth texture format.
  460. unsigned hiresShadowMapFormat_;
  461. /// Vertex buffers in use.
  462. VertexBuffer* vertexBuffers_[MAX_VERTEX_STREAMS];
  463. /// Stream frequencies by vertex buffer.
  464. unsigned streamFrequencies_[MAX_VERTEX_STREAMS];
  465. /// Stream offsets by vertex buffer.
  466. unsigned streamOffsets_[MAX_VERTEX_STREAMS];
  467. /// Index buffer in use.
  468. IndexBuffer* indexBuffer_;
  469. /// Vertex declaration in use.
  470. VertexDeclaration* vertexDeclaration_;
  471. /// Vertex shader in use.
  472. ShaderVariation* vertexShader_;
  473. /// Pixel shader in use.
  474. ShaderVariation* pixelShader_;
  475. /// All known shader parameters.
  476. HashMap<StringHash, ShaderParameter> shaderParameters_;
  477. /// Textures in use.
  478. Texture* textures_[MAX_TEXTURE_UNITS];
  479. /// Texture unit mappings.
  480. HashMap<String, TextureUnit> textureUnits_;
  481. /// Rendertargets in use.
  482. RenderSurface* renderTargets_[MAX_RENDERTARGETS];
  483. /// Depth-stencil surface in use.
  484. RenderSurface* depthStencil_;
  485. /// View texture.
  486. Texture* viewTexture_;
  487. /// Viewport coordinates.
  488. IntRect viewport_;
  489. /// Texture anisotropy level.
  490. unsigned textureAnisotropy_;
  491. /// Blending mode.
  492. BlendMode blendMode_;
  493. /// Color write enable.
  494. bool colorWrite_;
  495. /// Hardware culling mode.
  496. CullMode cullMode_;
  497. /// Depth constant bias.
  498. float constantDepthBias_;
  499. /// Depth slope scaled bias.
  500. float slopeScaledDepthBias_;
  501. /// Depth compare mode.
  502. CompareMode depthTestMode_;
  503. /// Depth write enable flag.
  504. bool depthWrite_;
  505. /// Polygon fill mode.
  506. FillMode fillMode_;
  507. /// Scissor test rectangle.
  508. IntRect scissorRect_;
  509. /// Scissor test enable flag.
  510. bool scissorTest_;
  511. /// Stencil test compare mode.
  512. CompareMode stencilTestMode_;
  513. /// Stencil operation on pass.
  514. StencilOp stencilPass_;
  515. /// Stencil operation on fail.
  516. StencilOp stencilFail_;
  517. /// Stencil operation on depth fail.
  518. StencilOp stencilZFail_;
  519. /// Stencil test enable flag.
  520. bool stencilTest_;
  521. /// Stencil test reference value.
  522. unsigned stencilRef_;
  523. /// Stencil compare bitmask.
  524. unsigned stencilCompareMask_;
  525. /// Stencil write bitmask.
  526. unsigned stencilWriteMask_;
  527. /// Default texture filtering mode.
  528. TextureFilterMode defaultTextureFilterMode_;
  529. /// Remembered shader parameter sources.
  530. const void* shaderParameterSources_[MAX_SHADER_PARAMETER_GROUPS];
  531. };
  532. /// Register Graphics library objects.
  533. void URHO3D_API RegisterGraphicsLibrary(Context* context);
  534. }