OGLGraphics.h 24 KB

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