OGLGraphics.h 25 KB

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