OGLGraphics.h 28 KB

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