OGLGraphics.h 26 KB

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