OGLGraphics.h 28 KB

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