OGLGraphics.h 23 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118119120121122123124125126127128129130131132133134135136137138139140141142143144145146147148149150151152153154155156157158159160161162163164165166167168169170171172173174175176177178179180181182183184185186187188189190191192193194195196197198199200201202203204205206207208209210211212213214215216217218219220221222223224225226227228229230231232233234235236237238239240241242243244245246247248249250251252253254255256257258259260261262263264265266267268269270271272273274275276277278279280281282283284285286287288289290291292293294295296297298299300301302303304305306307308309310311312313314315316317318319320321322323324325326327328329330331332333334335336337338339340341342343344345346347348349350351352353354355356357358359360361362363364365366367368369370371372373374375376377378379380381382383384385386387388389390391392393394395396397398399400401402403404405406407408409410411412413414415416417418419420421422423424425426427428429430431432433434435436437438439440441442443444445446447448449450451452453454455456457458459460461462463464465466467468469470471472473474475476477478479480481482483484485486487488489490491492493494495496497498499500501502503504505506507508509510511512513514515516517518519520521522523524525526527528529530
  1. //
  2. // Urho3D Engine
  3. // Copyright (c) 2008-2011 Lasse Öörni
  4. //
  5. // Permission is hereby granted, free of charge, to any person obtaining a copy
  6. // of this software and associated documentation files (the "Software"), to deal
  7. // in the Software without restriction, including without limitation the rights
  8. // to use, copy, modify, merge, publish, distribute, sublicense, and/or sell
  9. // copies of the Software, and to permit persons to whom the Software is
  10. // furnished to do so, subject to the following conditions:
  11. //
  12. // The above copyright notice and this permission notice shall be included in
  13. // all copies or substantial portions of the Software.
  14. //
  15. // THE SOFTWARE IS PROVIDED "AS IS", WITHOUT WARRANTY OF ANY KIND, EXPRESS OR
  16. // IMPLIED, INCLUDING BUT NOT LIMITED TO THE WARRANTIES OF MERCHANTABILITY,
  17. // FITNESS FOR A PARTICULAR PURPOSE AND NONINFRINGEMENT. IN NO EVENT SHALL THE
  18. // AUTHORS OR COPYRIGHT HOLDERS BE LIABLE FOR ANY CLAIM, DAMAGES OR OTHER
  19. // LIABILITY, WHETHER IN AN ACTION OF CONTRACT, TORT OR OTHERWISE, ARISING FROM,
  20. // OUT OF OR IN CONNECTION WITH THE SOFTWARE OR THE USE OR OTHER DEALINGS IN
  21. // THE SOFTWARE.
  22. //
  23. #pragma once
  24. #include "Color.h"
  25. #include "Matrix3x4.h"
  26. #include "Object.h"
  27. #include "Rect.h"
  28. #include "GraphicsDefs.h"
  29. class Image;
  30. class IndexBuffer;
  31. class Matrix3;
  32. class Matrix4;
  33. class Matrix3x4;
  34. class GPUObject;
  35. class GraphicsImpl;
  36. class RenderSurface;
  37. class ShaderProgram;
  38. class ShaderVariation;
  39. class Texture;
  40. class Texture2D;
  41. class TextureCube;
  42. class Vector3;
  43. class Vector4;
  44. class VertexBuffer;
  45. static const int IMMEDIATE_BUFFER_DEFAULT_SIZE = 1024;
  46. static const int NUM_SCREEN_BUFFERS = 2;
  47. typedef Map<Pair<ShaderVariation*, ShaderVariation*>, SharedPtr<ShaderProgram> > ShaderProgramMap;
  48. /// Graphics subsystem. Manages the application window, rendering state and GPU resources
  49. class Graphics : public Object
  50. {
  51. OBJECT(Graphics);
  52. public:
  53. /// Construct
  54. Graphics(Context* context_);
  55. /// Destruct. Close the window and release the Direct3D9 device
  56. virtual ~Graphics();
  57. /// Pump operating system messages
  58. void MessagePump();
  59. /// Set window title
  60. void SetWindowTitle(const String& windowTitle);
  61. /// Set screen mode. In deferred rendering modes multisampling means edge filtering instead of MSAA
  62. bool SetMode(RenderMode mode, int width, int height, bool fullscreen, bool vsync, int multiSample);
  63. /// Set screen resolution only
  64. bool SetMode(int width, int height);
  65. /// Set rendering mode only
  66. bool SetMode(RenderMode mode);
  67. /// Toggle between full screen and windowed mode
  68. bool ToggleFullscreen();
  69. /// Close the window
  70. void Close();
  71. /// Take a screenshot
  72. bool TakeScreenShot(Image& destImage);
  73. /// Set whether to flush GPU command queue at the end of each frame. Default true
  74. void SetFlushGPU(bool enable);
  75. /// Begin frame rendering
  76. bool BeginFrame();
  77. /// End frame rendering and swap buffers
  78. void EndFrame();
  79. /// Clear any or all of render target, depth buffer and stencil buffer
  80. void Clear(unsigned flags, const Color& color = Color(0.0f, 0.0f, 0.0f, 0.0f), float depth = 1.0f, unsigned stencil = 0);
  81. /// Draw non-indexed geometry
  82. void Draw(PrimitiveType type, unsigned vertexStart, unsigned vertexCount);
  83. /// Draw indexed geometry
  84. void Draw(PrimitiveType type, unsigned indexStart, unsigned indexCount, unsigned minVertex, unsigned vertexCount);
  85. /// Draw indexed, instanced geometry. No-op on OpenGL
  86. void DrawInstanced(PrimitiveType type, unsigned indexStart, unsigned indexCount, unsigned minVertex, unsigned vertexCount, unsigned instanceCount);
  87. /// Set vertex buffer
  88. void SetVertexBuffer(VertexBuffer* buffer);
  89. /// Set multiple vertex buffers
  90. bool SetVertexBuffers(const Vector<VertexBuffer*>& buffers, const PODVector<unsigned>& elementMasks, unsigned instanceOffset = 0);
  91. /// Set multiple vertex buffers
  92. bool SetVertexBuffers(const Vector<SharedPtr<VertexBuffer> >& buffers, const PODVector<unsigned>& elementMasks, unsigned instanceOffset = 0);
  93. /// Set index buffer
  94. void SetIndexBuffer(IndexBuffer* buffer);
  95. /// Set shaders
  96. void SetShaders(ShaderVariation* vs, ShaderVariation* ps);
  97. /// Set shader bool constants
  98. void SetShaderParameter(ShaderParameter param, const bool* data, unsigned count);
  99. /// Set shader float constants
  100. void SetShaderParameter(ShaderParameter param, const float* data, unsigned count);
  101. /// Set shader int constants
  102. void SetShaderParameter(ShaderParameter param, const int* data, unsigned count);
  103. /// Set shader float constant
  104. void SetShaderParameter(ShaderParameter param, float value);
  105. /// Set shader color constant
  106. void SetShaderParameter(ShaderParameter param, const Color& color);
  107. /// Set shader 3x3 matrix constant
  108. void SetShaderParameter(ShaderParameter param, const Matrix3& matrix);
  109. /// Set shader 3D vector constant
  110. void SetShaderParameter(ShaderParameter param, const Vector3& vector);
  111. /// Set shader 4x4 matrix constant
  112. void SetShaderParameter(ShaderParameter param, const Matrix4& matrix);
  113. /// Set shader 4D vector constant
  114. void SetShaderParameter(ShaderParameter param, const Vector4& vector);
  115. /// Set shader 4x3 matrix constant
  116. void SetShaderParameter(ShaderParameter param, const Matrix3x4& matrix);
  117. /// Check whether a shader parameter in the currently set shaders needs update
  118. bool NeedParameterUpdate(ShaderParameter param, const void* source);
  119. /// Check whether the current pixel shader uses a texture unit
  120. bool NeedTextureUnit(TextureUnit unit);
  121. /// Clear remembered shader parameter sources
  122. void ClearLastParameterSources();
  123. /// Clear remembered transform shader parameter sources
  124. void ClearTransformSources();
  125. /// Clean up unused shader programs
  126. void CleanupShaderPrograms();
  127. /// Set texture
  128. void SetTexture(unsigned index, Texture* texture);
  129. /// Bind texture unit 0 for update. Called by Texture
  130. void SetTextureForUpdate(Texture* texture);
  131. /// Set default texture filtering mode
  132. void SetDefaultTextureFilterMode(TextureFilterMode mode);
  133. /// Set texture anisotropy
  134. void SetTextureAnisotropy(unsigned level);
  135. /// Dirty texture parameters of all textures (when global settings change)
  136. void SetTextureParametersDirty();
  137. /// Reset all render targets and depth buffer (render to back buffer and back buffer depth stencil)
  138. void ResetRenderTargets();
  139. /// Reset specific render target
  140. void ResetRenderTarget(unsigned index);
  141. /// Reset depth stencil
  142. void ResetDepthStencil();
  143. /// Set render target
  144. void SetRenderTarget(unsigned index, RenderSurface* renderTarget);
  145. /// Set render target
  146. void SetRenderTarget(unsigned index, Texture2D* renderTexture);
  147. /// Set depth stencil buffer
  148. void SetDepthStencil(RenderSurface* depthStencil);
  149. /// Set depth stencil buffer
  150. void SetDepthStencil(Texture2D* depthTexture);
  151. /// Set viewport
  152. void SetViewport(const IntRect& rect);
  153. /// Set "view texture" to prevent sampling from the destination render target
  154. void SetViewTexture(Texture* texture);
  155. /// Set alpha test
  156. void SetAlphaTest(bool enable, CompareMode mode = CMP_ALWAYS, float alphaRef = 0.5f);
  157. /// Set blending mode
  158. void SetBlendMode(BlendMode mode);
  159. /// Set color write on/off
  160. void SetColorWrite(bool enable);
  161. /// Set hardware culling mode
  162. void SetCullMode(CullMode mode);
  163. /// Set depth bias
  164. void SetDepthBias(float constantBias, float slopeScaledBias);
  165. /// Set depth compare
  166. void SetDepthTest(CompareMode mode);
  167. /// Set depth write on/off
  168. void SetDepthWrite(bool enable);
  169. /// Set polygon fill mode
  170. void SetFillMode(FillMode mode);
  171. /// Set scissor test
  172. void SetScissorTest(bool enable, const Rect& rect = Rect::FULL, bool borderInclusive = true);
  173. /// Set scissor test
  174. void SetScissorTest(bool enable, const IntRect& rect);
  175. /// Set stencil test
  176. void SetStencilTest(bool enable, CompareMode mode = CMP_ALWAYS, StencilOp pass = OP_KEEP, StencilOp fail = OP_KEEP, StencilOp zFail = OP_KEEP, unsigned stencilRef = 0, unsigned stencilMask = M_MAX_UNSIGNED);
  177. /// Set vertex buffer stream frequency. No-op on OpenGL
  178. void SetStreamFrequency(unsigned index, unsigned frequency);
  179. /// Reset stream frequencies. No-op on OpenGL
  180. void ResetStreamFrequencies();
  181. /// Begin immediate rendering command
  182. bool BeginImmediate(PrimitiveType type, unsigned vertexCount, unsigned elementMask);
  183. /// Define immediate vertex
  184. bool DefineVertex(const Vector3& vertex);
  185. /// Define immediate normal
  186. bool DefineNormal(const Vector3& normal);
  187. /// Define immediate texture coordinate
  188. bool DefineTexCoord(const Vector2& texCoord);
  189. /// Define immediate color
  190. bool DefineColor(const Color& color);
  191. /// Define immediate color
  192. bool DefineColor(unsigned color);
  193. /// End immediate rendering command and render
  194. void EndImmediate();
  195. /// Set force Shader Model 2 flag. No effect on OpenGL
  196. void SetForceSM2(bool enable);
  197. /// Return whether rendering initialized
  198. bool IsInitialized() const;
  199. /// Return graphics implementation, which holds the actual API-specific resources
  200. GraphicsImpl* GetImpl() const { return impl_; }
  201. /// Return window title
  202. const String& GetWindowTitle() const { return windowTitle_; }
  203. /// Return rendering mode
  204. RenderMode GetRenderMode() const { return mode_; }
  205. /// Return window width
  206. int GetWidth() const { return width_; }
  207. /// Return window height
  208. int GetHeight() const { return height_; }
  209. /// Return multisample mode (0 = no multisampling)
  210. int GetMultiSample() const { return multiSample_; }
  211. /// Return whether window is fullscreen
  212. bool GetFullscreen() const { return fullscreen_; }
  213. /// Return whether vertical sync is on
  214. bool GetVSync() const { return vsync_; }
  215. /// Return whether GPU command queue is flushed at the end of each frame
  216. bool GetFlushGPU() const { return flushGPU_; }
  217. /// Return whether device is lost, and can not yet render. Always false on OpenGL
  218. bool IsDeviceLost() const { return false; }
  219. /// Return immediate rendering data pointer
  220. unsigned char* GetImmediateDataPtr() const;
  221. /// Return window handle
  222. unsigned GetWindowHandle() const;
  223. /// Return number of primitives drawn this frame
  224. unsigned GetNumPrimitives() const { return numPrimitives_; }
  225. /// Return number of batches drawn this frame
  226. unsigned GetNumBatches() const { return numBatches_; }
  227. /// Return dummy color texture format for shadow maps. Is always 0 on OpenGL
  228. unsigned GetDummyColorFormat() const { return 0; }
  229. /// Return shadow map depth texture format, or 0 if not supported
  230. unsigned GetShadowMapFormat() const { return shadowMapFormat_; }
  231. /// Return 24-bit shadow map depth texture format, or 0 if not supported
  232. unsigned GetHiresShadowMapFormat() const { return hiresShadowMapFormat_; }
  233. /// Return whether texture render targets are supported
  234. bool GetRenderTextureSupport() const;
  235. /// Return whether deferred rendering is supported
  236. bool GetDeferredSupport() const { return deferredSupport_; }
  237. /// Return whether light prepass rendering is supported
  238. bool GetPrepassSupport() const { return prepassSupport_; }
  239. /// Return whether Shader Model 3 is supported. Always false on OpenGL
  240. bool GetSM3Support() const { return false; }
  241. /// Return whether shadow map depth compare is done in hardware. Always false on OpenGL to avoid the HW suffix in shaders
  242. bool GetHardwareShadowSupport() const { return false; }
  243. /// Return whether 24-bit shadow maps are supported. Assume true on OpenGL
  244. bool GetHiresShadowSupport() const { return true; }
  245. /// Return whether stream offset is supported. Always false on OpenGL
  246. bool GetStreamOffsetSupport() const { return false; }
  247. /// Return supported fullscreen resolutions
  248. PODVector<IntVector2> GetResolutions() const;
  249. /// Return supported multisampling levels
  250. PODVector<int> GetMultiSampleLevels() const;
  251. /// Return vertex buffer by index
  252. VertexBuffer* GetVertexBuffer(unsigned index) const;
  253. /// Return index buffer
  254. IndexBuffer* GetIndexBuffer() const { return indexBuffer_; }
  255. /// Return vertex shader
  256. ShaderVariation* GetVertexShader() const { return vertexShader_; }
  257. /// Return pixel shader
  258. ShaderVariation* GetPixelShader() const { return pixelShader_; }
  259. /// Return shader program
  260. ShaderProgram* GetShaderProgram() const { return shaderProgram_; }
  261. /// Return shader parameter index by name
  262. ShaderParameter GetShaderParameter(const String& name);
  263. /// Return texture unit index by name
  264. TextureUnit GetTextureUnit(const String& name);
  265. /// Return shader parameter name by index
  266. const String& GetShaderParameterName(ShaderParameter parameter);
  267. /// Return texture unit name by index
  268. const String& GetTextureUnitName(TextureUnit unit);
  269. /// Return texture by texture unit index
  270. Texture* GetTexture(unsigned index) const;
  271. /// Return the "view texture"
  272. Texture* GetViewTexture() const { return viewTexture_; }
  273. /// Return default texture filtering mode
  274. TextureFilterMode GetDefaultTextureFilterMode() const { return defaultTextureFilterMode_; }
  275. /// Return render target by index
  276. RenderSurface* GetRenderTarget(unsigned index) const;
  277. /// Return depth stencil buffer
  278. RenderSurface* GetDepthStencil() const { return depthStencil_; }
  279. /// Return the viewport coordinates
  280. IntRect GetViewport() const { return viewport_; }
  281. /// Return whether alpha testing is enabled
  282. bool GetAlphaTest() const { return alphaTest_; }
  283. /// Return alpha test compare mode
  284. CompareMode GetAlphaTestMode() const { return alphaTestMode_; }
  285. /// Return texture anisotropy
  286. unsigned GetTextureAnisotropy() const { return textureAnisotropy_; }
  287. /// Return alpha test reference value
  288. float GetAlphaRef() const { return alphaRef_; }
  289. /// Return blending mode
  290. BlendMode GetBlendMode() const { return blendMode_; }
  291. /// Return whether color write is enabled
  292. bool GetColorWrite() const { return colorWrite_; }
  293. /// Return hardware culling mode
  294. CullMode GetCullMode() const { return cullMode_; }
  295. /// Return depth constant bias
  296. float GetDepthConstantBias() const { return constantDepthBias_; }
  297. /// Return depth slope scaled bias
  298. float GetDepthSlopeScaledBias() const { return slopeScaledDepthBias_; }
  299. /// Return depth compare mode
  300. CompareMode GetDepthTest() const { return depthTestMode_; }
  301. /// Return whether depth write is enabled
  302. bool GetDepthWrite() const { return depthWrite_; }
  303. /// Return polygon fill mode
  304. FillMode GetFillMode() const { return fillMode_; }
  305. /// Return whether stencil test is enabled
  306. bool GetStencilTest() const { return stencilTest_; }
  307. /// Return whether scissor test is enabled
  308. bool GetScissorTest() const { return scissorTest_; }
  309. /// Return scissor rectangle coordinates
  310. const IntRect& GetScissorRect() const { return scissorRect_; }
  311. /// Return stencil compare mode
  312. CompareMode GetStencilTestMode() const { return stencilTestMode_; }
  313. /// Return stencil operation to do if stencil test passes
  314. StencilOp GetStencilPass() const { return stencilPass_; }
  315. /// Return stencil operation to do if stencil test fails
  316. StencilOp GetStencilFail() const { return stencilFail_; }
  317. /// Return stencil operation to do if depth compare fails
  318. StencilOp GetStencilZFail() const { return stencilZFail_; }
  319. /// Return stencil reference value
  320. unsigned GetStencilRef() const { return stencilRef_; }
  321. /// Return stencil compare bitmask
  322. unsigned GetStencilMask() const { return stencilMask_; }
  323. /// Return stream frequency by vertex buffer index. Always returns 0 on OpenGL
  324. unsigned GetStreamFrequency(unsigned index) const { return 0; }
  325. /// Return render target width and height
  326. IntVector2 GetRenderTargetDimensions() const;
  327. /// Return diffuse buffer for deferred rendering
  328. Texture2D* GetDiffBuffer() const { return diffBuffer_; }
  329. /// Return normal buffer for deferred rendering
  330. Texture2D* GetNormalBuffer() const { return normalBuffer_; }
  331. /// Return depth buffer for deferred rendering. If reading hardware depth is supported, return a depth texture
  332. Texture2D* GetDepthBuffer() const { return depthBuffer_; }
  333. /// Return screen buffer for post-processing
  334. Texture2D* GetScreenBuffer(unsigned index) const { return screenBuffers_[index & (NUM_SCREEN_BUFFERS - 1)]; }
  335. /// Add a GPU object to keep track of. Called by GPUObject.
  336. void AddGPUObject(GPUObject* object);
  337. /// Remove a GPU object. Called by GPUObject
  338. void RemoveGPUObject(GPUObject* object);
  339. /// Return the API-specific alpha texture format
  340. static unsigned GetAlphaFormat();
  341. /// Return the API-specific luminance texture format
  342. static unsigned GetLuminanceFormat();
  343. /// Return the API-specific luminance alpha texture format
  344. static unsigned GetLuminanceAlphaFormat();
  345. /// Return the API-specific RGB texture format
  346. static unsigned GetRGBFormat();
  347. /// Return the API-specific RGBA texture format
  348. static unsigned GetRGBAFormat();
  349. /// Return the API-specific depth texture format. Includes a stencil if possible
  350. static unsigned GetDepthFormat();
  351. private:
  352. /// Create the application window. Return true if successful
  353. bool OpenWindow(int width, int height);
  354. /// Change to a fullscreen mode. Return true if successful
  355. bool SetScreenMode(int newWidth, int newHeight);
  356. /// Restore desktop mode
  357. void RestoreScreenMode();
  358. /// Adjust the window for new resolution and fullscreen mode
  359. void AdjustWindow(int newWidth, int newHeight, bool newFullscreen);
  360. /// Create deferred rendering render targets
  361. void CreateRenderTargets();
  362. /// Reset cached rendering state
  363. void ResetCachedState();
  364. /// Set draw buffer(s) on the FBO
  365. void SetDrawBuffers();
  366. /// Initialize shader parameter and texture unit mappings
  367. void InitializeShaderParameters();
  368. /// Handle operating system window message
  369. void HandleWindowMessage(StringHash eventType, VariantMap& eventData);
  370. /// Handle application activation state change
  371. void HandleActivation(StringHash eventType, VariantMap& eventData);
  372. /// Implementation
  373. GraphicsImpl* impl_;
  374. /// Window title
  375. String windowTitle_;
  376. /// Rendering mode
  377. RenderMode mode_;
  378. /// Window width
  379. int width_;
  380. /// Window height
  381. int height_;
  382. /// Multisampling mode
  383. int multiSample_;
  384. /// Stored window X-position
  385. int windowPosX_;
  386. /// Stored window Y-position
  387. int windowPosY_;
  388. /// Fullscreen flag
  389. bool fullscreen_;
  390. /// Vertical sync flag
  391. bool vsync_;
  392. /// Flush GPU command queue flag
  393. bool flushGPU_;
  394. /// Fullscreen mode set -flag
  395. bool fullscreenModeSet_;
  396. /// In screen mode change -flag
  397. bool inModeChange_;
  398. /// Deferred rendering support flag
  399. bool deferredSupport_;
  400. /// Light prepass support flag
  401. bool prepassSupport_;
  402. /// Number of primitives this frame
  403. unsigned numPrimitives_;
  404. /// Number of batches this frame
  405. unsigned numBatches_;
  406. /// Immediate rendering primitive type
  407. PrimitiveType immediateType_;
  408. /// Immediate vertex buffer start position
  409. unsigned immediateStartPos_;
  410. /// Immediate rendering vertex buffer size
  411. unsigned immediateVertexCount_;
  412. /// Immediate rendering vertex number
  413. unsigned immediateCurrentVertex_;
  414. /// Immediate rendering vertex buffer in use
  415. VertexBuffer* immediateBuffer_;
  416. /// Immediate rendering data pointer
  417. unsigned char* immediateDataPtr_;
  418. /// GPU objects
  419. Vector<GPUObject*> gpuObjects_;
  420. /// Immediate rendering vertex buffers by vertex element mask
  421. Map<unsigned, SharedPtr<VertexBuffer> > immediateVertexBuffers_;
  422. /// Immediate rendering vertex buffer start positions
  423. Map<unsigned, unsigned> immediateVertexBufferPos_;
  424. /// Deferred rendering diffuse buffer
  425. SharedPtr<Texture2D> diffBuffer_;
  426. /// Deferred rendering normal buffer
  427. SharedPtr<Texture2D> normalBuffer_;
  428. /// Deferred rendering depth buffer
  429. SharedPtr<Texture2D> depthBuffer_;
  430. /// Screen buffers for post processing
  431. SharedPtr<Texture2D> screenBuffers_[NUM_SCREEN_BUFFERS];
  432. /// Shadow map depth texture format
  433. unsigned shadowMapFormat_;
  434. /// Shadow map 24-bit depth texture format
  435. unsigned hiresShadowMapFormat_;
  436. /// Vertex buffers in use
  437. VertexBuffer* vertexBuffers_[MAX_VERTEX_STREAMS];
  438. /// Element mask in use
  439. unsigned elementMasks_[MAX_VERTEX_STREAMS];
  440. /// Index buffer in use
  441. IndexBuffer* indexBuffer_;
  442. /// Vertex shader in use
  443. ShaderVariation* vertexShader_;
  444. /// Pixel shader in use
  445. ShaderVariation* pixelShader_;
  446. /// Shader program in use
  447. ShaderProgram* shaderProgram_;
  448. /// Shader parameter mappings
  449. Map<String, ShaderParameter> shaderParameters_;
  450. /// Linked shader programs
  451. ShaderProgramMap shaderPrograms_;
  452. /// Last shader parameter sources per parameter
  453. const void* lastShaderParameterSources_[MAX_SHADER_PARAMETERS];
  454. /// Textures in use
  455. Texture* textures_[MAX_TEXTURE_UNITS];
  456. /// OpenGL texture types in use
  457. unsigned textureTypes_[MAX_TEXTURE_UNITS];
  458. /// "View texture" to prevent sampling the destination render target
  459. Texture* viewTexture_;
  460. /// Texture unit mappings
  461. Map<String, TextureUnit> textureUnits_;
  462. /// Render targets in use
  463. RenderSurface* renderTargets_[MAX_RENDERTARGETS];
  464. /// Depth stencil buffer in use
  465. RenderSurface* depthStencil_;
  466. /// Viewport coordinates
  467. IntRect viewport_;
  468. /// Alpha test enable flag
  469. bool alphaTest_;
  470. /// Alpha test compare mode
  471. CompareMode alphaTestMode_;
  472. /// Alpha test reference value
  473. float alphaRef_;
  474. /// Texture anisotropy level
  475. unsigned textureAnisotropy_;
  476. /// Blending mode
  477. BlendMode blendMode_;
  478. /// Color write enable
  479. bool colorWrite_;
  480. /// Hardware culling mode
  481. CullMode cullMode_;
  482. /// Depth constant bias
  483. float constantDepthBias_;
  484. /// Depth slope scaled bias
  485. float slopeScaledDepthBias_;
  486. /// Depth compare mode
  487. CompareMode depthTestMode_;
  488. /// Depth write enable flag
  489. bool depthWrite_;
  490. /// Polygon fill mode
  491. FillMode fillMode_;
  492. /// Scissor test rectangle
  493. IntRect scissorRect_;
  494. /// Scissor test enable flag
  495. bool scissorTest_;
  496. /// Stencil test compare mode
  497. CompareMode stencilTestMode_;
  498. /// Stencil operation on pass
  499. StencilOp stencilPass_;
  500. /// Stencil operation on fail
  501. StencilOp stencilFail_;
  502. /// Stencil operation on depth fail
  503. StencilOp stencilZFail_;
  504. /// Stencil test enable flag
  505. bool stencilTest_;
  506. /// Stencil test reference value
  507. unsigned stencilRef_;
  508. /// Stencil compare bitmask
  509. unsigned stencilMask_;
  510. /// Default texture filtering mode
  511. TextureFilterMode defaultTextureFilterMode_;
  512. /// Map for additional depth textures, to emulate Direct3D9 ability to mix rendertarget and backbuffer rendering
  513. Map<int, SharedPtr<Texture2D> > depthTextures_;
  514. };
  515. /// Register Graphics library objects
  516. void RegisterGraphicsLibrary(Context* context_);