D3D9Graphics.h 28 KB

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