D3D9Graphics.h 27 KB

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