OGLGraphics.h 25 KB

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