D3D9Graphics.h 28 KB

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