D3D9Graphics.h 28 KB

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