D3D9Graphics.h 28 KB

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