Graphics.h 26 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118119120121122123124125126127128129130131132133134135136137138139140141142143144145146147148149150151152153154155156157158159160161162163164165166167168169170171172173174175176177178179180181182183184185186187188189190191192193194195196197198199200201202203204205206207208209210211212213214215216217218219220221222223224225226227228229230231232233234235236237238239240241242243244245246247248249250251252253254255256257258259260261262263264265266267268269270271272273274275276277278279280281282283284285286287288289290291292293294295296297298299300301302303304305306307308309310311312313314315316317318319320321322323324325326327328329330331332333334335336337338339340341342343344345346347348349350351352353354355356357358359360361362363364365366367368369370371372373374375376377378379380381382383384385386387388389390391392393394395396397398399400401402403404405406407408409410411412413414415416417418419420421422423424425426427428429430431432433434435436437438439440441442443444445446447448449450451452453454455456457458459460461462463464465466467468469470471472473474475476477478479480481482483484485486487488489490491492493494495496497498499500501502503504505506507508509510511512513514515516517518519520521522523524525526527528529530531532533534535536537538539540541542543544545546547548549550551552553554555556557558559560561562
  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 "Object.h"
  26. #include "Rect.h"
  27. #include "GraphicsDefs.h"
  28. class Image;
  29. class IndexBuffer;
  30. class Matrix3;
  31. class Matrix4;
  32. class Matrix4x3;
  33. class PixelShader;
  34. class GPUObject;
  35. class GraphicsImpl;
  36. class RenderSurface;
  37. class Texture;
  38. class Texture2D;
  39. class TextureCube;
  40. class Vector3;
  41. class Vector4;
  42. class VertexBuffer;
  43. class VertexDeclaration;
  44. class VertexShader;
  45. static const int IMMEDIATE_BUFFER_DEFAULT_SIZE = 1024;
  46. static const int NUM_SCREEN_BUFFERS = 2;
  47. /// Graphics subsystem. Manages the Direct3D9 device, application window, rendering state and GPU resources
  48. class Graphics : public Object
  49. {
  50. OBJECT(Graphics);
  51. public:
  52. /// Construct
  53. Graphics(Context* context);
  54. /// Destruct. Close the window and release the Direct3D9 device
  55. virtual ~Graphics();
  56. /// Pump operating system messages
  57. void MessagePump();
  58. /// Set window title
  59. void SetWindowTitle(const std::string& windowTitle);
  60. /// Set screen mode. In deferred rendering modes multisampling means edge filtering instead of MSAA
  61. bool SetMode(RenderMode mode, int width, int height, bool fullscreen, bool vsync, int multiSample);
  62. /// Set screen resolution only
  63. bool SetMode(int width, int height);
  64. /// Set rendering mode only
  65. bool SetMode(RenderMode mode);
  66. /// Toggle between full screen and windowed mode
  67. bool ToggleFullscreen();
  68. /// Close the window
  69. void Close();
  70. /// Take a screenshot
  71. bool TakeScreenShot(Image& destImage);
  72. /// Set whether to flush GPU command queue at the end of each frame. Default true
  73. void SetFlushGPU(bool enable);
  74. /// Begin frame rendering
  75. bool BeginFrame();
  76. /// End frame rendering and swap buffers
  77. void EndFrame();
  78. /// Clear any or all of render target, depth buffer and stencil buffer
  79. void Clear(unsigned flags, const Color& color = Color(0.0f, 0.0f, 0.0f, 0.0f), float depth = 1.0f, unsigned stencil = 0);
  80. /// Draw non-indexed geometry
  81. void Draw(PrimitiveType type, unsigned vertexStart, unsigned vertexCount);
  82. /// Draw indexed geometry
  83. void Draw(PrimitiveType type, unsigned indexStart, unsigned indexCount, unsigned minVertex, unsigned vertexCount);
  84. /// Draw indexed, instanced geometry. An instancing vertex buffer must be set
  85. void DrawInstanced(PrimitiveType type, unsigned indexStart, unsigned indexCount, unsigned minVertex, unsigned vertexCount, unsigned instanceCount);
  86. /// Set vertex buffer
  87. void SetVertexBuffer(VertexBuffer* buffer);
  88. /// Set multiple vertex buffers
  89. bool SetVertexBuffers(const std::vector<VertexBuffer*>& buffers, const std::vector<unsigned>& elementMasks, unsigned instanceOffset = 0);
  90. /// Set multiple vertex buffers
  91. bool SetVertexBuffers(const std::vector<SharedPtr<VertexBuffer> >& buffers, const std::vector<unsigned>& elementMasks, unsigned instanceOffset = 0);
  92. /// Set index buffer
  93. void SetIndexBuffer(IndexBuffer* buffer);
  94. /// Set shaders
  95. void SetShaders(VertexShader* vs, PixelShader* ps);
  96. /// Set vertex shader bool parameter
  97. void SetVertexShaderParameter(VSParameter param, const bool* data, unsigned count);
  98. /// Set vertex shader float constants
  99. void SetVertexShaderParameter(VSParameter param, const float* data, unsigned count);
  100. /// Set vertex shader int constants
  101. void SetVertexShaderParameter(VSParameter param, const int* data, unsigned count);
  102. /// Set vertex shader float constant
  103. void SetVertexShaderParameter(VSParameter param, float value);
  104. /// Set vertex shader color constant
  105. void SetVertexShaderParameter(VSParameter param, const Color& color);
  106. /// Set vertex shader 3x3 matrix constant
  107. void SetVertexShaderParameter(VSParameter param, const Matrix3& matrix);
  108. /// Set vertex shader 3D vector constant
  109. void SetVertexShaderParameter(VSParameter param, const Vector3& vector);
  110. /// Set vertex shader 4x4 matrix constant
  111. void SetVertexShaderParameter(VSParameter param, const Matrix4& matrix);
  112. /// Set vertex shader 4D vector constant
  113. void SetVertexShaderParameter(VSParameter param, const Vector4& vector);
  114. /// Set vertex shader 4x3 matrix constant
  115. void SetVertexShaderParameter(VSParameter param, const Matrix4x3& matrix);
  116. /// Set pixel shader bool constants
  117. void SetPixelShaderParameter(PSParameter param, const bool* data, unsigned count);
  118. /// Set pixel shader float constants
  119. void SetPixelShaderParameter(PSParameter param, const float* data, unsigned count);
  120. /// Set pixel shader int constants
  121. void SetPixelShaderParameter(PSParameter param, const int* data, unsigned count);
  122. /// Set pixel shader float constant
  123. void SetPixelShaderParameter(PSParameter param, float value);
  124. /// Set pixel shader color constant
  125. void SetPixelShaderParameter(PSParameter param, const Color& color);
  126. /// Set pixel shader 3x3 matrix constant
  127. void SetPixelShaderParameter(PSParameter param, const Matrix3& matrix);
  128. /// Set pixel shader 3D vector constant
  129. void SetPixelShaderParameter(PSParameter param, const Vector3& vector);
  130. /// Set pixel shader 4x4 matrix constant
  131. void SetPixelShaderParameter(PSParameter param, const Matrix4& matrix);
  132. /// Set pixel shader 3D vector constant
  133. void SetPixelShaderParameter(PSParameter param, const Vector4& vector);
  134. /// Set pixel shader 4x3 matrix constant
  135. void SetPixelShaderParameter(PSParameter param, const Matrix4x3& matrix);
  136. /// Set vertex shader parameter source. Called by VertexShader
  137. void SetVSParameterSource(VSParameter param, const void* source) { lastVSParameterSources_[param] = source; }
  138. /// Set pixel shader parameter source. Called by PixelShader
  139. void SetPSParameterSource(PSParameter param, const void* source) { lastPSParameterSources_[param] = source; }
  140. /// Map vertex shader parameter to a constant Register. Called by VertexShader
  141. void SetVSRegister(VSParameter param, unsigned index) { vsRegisters_[param] = index; }
  142. /// Map pixel shader parameter to a constant Register. Called by PixelShader
  143. void SetPSRegister(PSParameter param, unsigned index) { psRegisters_[param] = index; }
  144. /// Clear remembered shader parameter sources
  145. void ClearLastParameterSources();
  146. /// Clear remembered transform shader parameter sources
  147. void ClearTransformSources();
  148. /// Set texture
  149. void SetTexture(unsigned index, Texture* texture);
  150. /// Set default texture filtering mode
  151. void SetDefaultTextureFilterMode(TextureFilterMode mode);
  152. /// Reset all render targets and depth buffer (render to back buffer and back buffer depth stencil)
  153. void ResetRenderTargets();
  154. /// Reset specific render target
  155. void ResetRenderTarget(unsigned index);
  156. /// Reset depth stencil
  157. void ResetDepthStencil();
  158. /// Set render target
  159. void SetRenderTarget(unsigned index, RenderSurface* renderTarget);
  160. /// Set render target
  161. void SetRenderTarget(unsigned index, Texture2D* renderTexture);
  162. /// Set depth stencil buffer
  163. void SetDepthStencil(RenderSurface* depthStencil);
  164. /// Set depth stencil buffer
  165. void SetDepthStencil(Texture2D* depthTexture);
  166. /// Set viewport
  167. void SetViewport(const IntRect& rect);
  168. /// Set "view texture" to prevent sampling from the destination render target
  169. void SetViewTexture(Texture* texture);
  170. /// Set alpha test
  171. void SetAlphaTest(bool enable, CompareMode mode = CMP_ALWAYS, float alphaRef = 0.5f);
  172. /// Set texture anisotropy
  173. void SetTextureAnisotropy(unsigned level);
  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 stencilMask = M_MAX_UNSIGNED);
  194. /// Set vertex buffer stream frequency
  195. void SetStreamFrequency(unsigned index, unsigned frequency);
  196. /// Reset stream frequencies
  197. void ResetStreamFrequencies();
  198. /// Begin immediate rendering command
  199. bool BeginImmediate(PrimitiveType type, unsigned vertexCount, unsigned elementMask);
  200. /// Define immediate vertex
  201. bool DefineVertex(const Vector3& vertex);
  202. /// Define immediate normal
  203. bool DefineNormal(const Vector3& normal);
  204. /// Define immediate texture coordinate
  205. bool DefineTexCoord(const Vector2& texCoord);
  206. /// Define immediate color
  207. bool DefineColor(const Color& color);
  208. /// Define immediate color
  209. bool DefineColor(unsigned color);
  210. /// End immediate rendering command and render
  211. void EndImmediate();
  212. /// Set force Shader Model 2 flag. Needs to be set before setting initial screen mode to have effect.
  213. void SetForceSM2(bool enable);
  214. /// Return whether rendering initialized
  215. bool IsInitialized() const;
  216. /// Return graphics implementation, which holds the actual Direct3D resources
  217. GraphicsImpl* GetImpl() const { return impl_; }
  218. /// Return window title
  219. const std::string& GetWindowTitle() const { return windowTitle_; }
  220. /// Return rendering mode
  221. RenderMode GetRenderMode() const { return mode_; }
  222. /// Return window width
  223. int GetWidth() const { return width_; }
  224. /// Return window height
  225. int GetHeight() const { return height_; }
  226. /// Return multisample mode (0 = no multisampling)
  227. int GetMultiSample() const { return multiSample_; }
  228. /// Return whether window is fullscreen
  229. bool GetFullscreen() const { return fullscreen_; }
  230. /// Return whether vertical sync is on
  231. bool GetVSync() const { return vsync_; }
  232. /// Return whether GPU command queue is flushed at the end of each frame
  233. bool GetFlushGPU() const { return flushGPU_; }
  234. /// Return whether Direct3D device is lost, and can not yet render. This happens during fullscreen resolution switching
  235. bool IsDeviceLost() const { return deviceLost_; }
  236. /// Return immediate rendering data pointer
  237. unsigned char* GetImmediateDataPtr() const;
  238. /// Return window handle
  239. unsigned GetWindowHandle() 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. Is "NULL" (consume no video memory) if supported
  245. unsigned GetDummyColorFormat() const { return dummyColorFormat_; }
  246. /// Return shadow map depth texture format, or D3DFMT_UNKNOWN if not supported
  247. unsigned GetShadowMapFormat() const { return shadowMapFormat_; }
  248. /// Return 24-bit shadow map depth texture format, or D3DFMT_UNKNOWN if not supported
  249. unsigned GetHiresShadowMapFormat() const { return hiresShadowMapFormat_; }
  250. /// Return whether deferred rendering is supported
  251. bool GetDeferredSupport() const { return deferredSupport_; }
  252. /// Return whether light prepass rendering is supported
  253. bool GetPrepassSupport() const { return prepassSupport_; }
  254. /// Return whether Shader Model 3 is supported
  255. bool GetSM3Support() const { return hasSM3_; }
  256. /// Return whether shadow map depth compare is done in hardware
  257. bool GetHardwareShadowSupport() const { return hardwareShadowSupport_; }
  258. /// Return whether 24-bit shadow maps are supported
  259. bool GetHiresShadowSupport() const { return hiresShadowSupport_; }
  260. /// Return whether stream offset is supported
  261. bool GetStreamOffsetSupport() const { return streamOffsetSupport_; }
  262. /// Return supported fullscreen resolutions
  263. std::vector<IntVector2> GetResolutions() const;
  264. /// Return supported multisampling levels
  265. std::vector<int> GetMultiSampleLevels() const;
  266. /// Return vertex buffer by index
  267. VertexBuffer* GetVertexBuffer(unsigned index) const;
  268. /// Return index buffer
  269. IndexBuffer* GetIndexBuffer() const { return indexBuffer_; }
  270. /// Return vertex declaration
  271. VertexDeclaration* GetVertexDeclaration() const { return vertexDeclaration_; }
  272. /// Return vertex shader
  273. VertexShader* GetVertexShader() const { return vertexShader_; }
  274. /// Return pixel shader
  275. PixelShader* GetPixelShader() const { return pixelShader_; }
  276. /// Return vertex shader parameter index by name
  277. VSParameter GetVSParameter(const std::string& name);
  278. /// Return pixel shader parameter index by name
  279. PSParameter GetPSParameter(const std::string& name);
  280. /// Return texture unit index by name
  281. TextureUnit GetTextureUnit(const std::string& name);
  282. /// Return vertex shader parameter name by index
  283. const std::string& GetVSParameterName(VSParameter parameter);
  284. /// Return vertex pixel parameter name by index
  285. const std::string& GetPSParameterName(PSParameter parameter);
  286. /// Return texture unit name by index
  287. const std::string& GetTextureUnitName(TextureUnit unit);
  288. /// Return vertex shader constant register by parameter index
  289. unsigned GetVSRegister(VSParameter param) { return vsRegisters_[param]; }
  290. /// Return pixel shader constant register by parameter index
  291. unsigned GetPSRegister(PSParameter param) { return psRegisters_[param]; }
  292. /// Return last vertex shader parameter source
  293. const void* GetVSParameterSource(VSParameter param) { return lastVSParameterSources_[param]; }
  294. /// Return last pixel shader parameter source
  295. const void* GetPSParameterSource(PSParameter param) { return lastPSParameterSources_[param]; }
  296. /// Return texture by texture unit index
  297. Texture* GetTexture(unsigned index) const;
  298. /// Return the "view texture"
  299. Texture* GetViewTexture() const { return viewTexture_; }
  300. /// Return default texture filtering mode
  301. TextureFilterMode GetDefaultTextureFilterMode() const { return defaultTextureFilterMode_; }
  302. /// Return render target by index
  303. RenderSurface* GetRenderTarget(unsigned index) const;
  304. /// Return depth stencil buffer
  305. RenderSurface* GetDepthStencil() const { return depthStencil_; }
  306. /// Return the viewport coordinates
  307. IntRect GetViewport() const { return viewport_; }
  308. /// Return whether alpha testing is enabled
  309. bool GetAlphaTest() const { return alphaTest_; }
  310. /// Return alpha test compare mode
  311. CompareMode GetAlphaTestMode() const { return alphaTestMode_; }
  312. /// Return texture anisotropy
  313. unsigned GetTextureAnisotropy() const { return textureAnisotropy_; }
  314. /// Return alpha test reference value
  315. float GetAlphaRef() const { return alphaRef_; }
  316. /// Return blending mode
  317. BlendMode GetBlendMode() const { return blendMode_; }
  318. /// Return whether color write is enabled
  319. bool GetColorWrite() const { return colorWrite_; }
  320. /// Return hardware culling mode
  321. CullMode GetCullMode() const { return cullMode_; }
  322. /// Return depth constant bias
  323. float GetDepthConstantBias() const { return constantDepthBias_; }
  324. /// Return depth slope scaled bias
  325. float GetDepthSlopeScaledBias() const { return slopeScaledDepthBias_; }
  326. /// Return depth compare mode
  327. CompareMode GetDepthTest() const { return depthTestMode_; }
  328. /// Return whether depth write is enabled
  329. bool GetDepthWrite() const { return depthWrite_; }
  330. /// Return polygon fill mode
  331. FillMode GetFillMode() const { return fillMode_; }
  332. /// Return whether stencil test is enabled
  333. bool GetStencilTest() const { return stencilTest_; }
  334. /// Return whether scissor test is enabled
  335. bool GetScissorTest() const { return scissorTest_; }
  336. /// Return scissor rectangle coordinates
  337. const IntRect& GetScissorRect() const { return scissorRect_; }
  338. /// Return stencil compare mode
  339. CompareMode GetStencilTestMode() const { return stencilTestMode_; }
  340. /// Return stencil operation to do if stencil test passes
  341. StencilOp GetStencilPass() const { return stencilPass_; }
  342. /// Return stencil operation to do if stencil test fails
  343. StencilOp GetStencilFail() const { return stencilFail_; }
  344. /// Return stencil operation to do if depth compare fails
  345. StencilOp GetStencilZFail() const { return stencilZFail_; }
  346. /// Return stencil reference value
  347. unsigned GetStencilRef() const { return stencilRef_; }
  348. /// Return stencil compare bitmask
  349. unsigned GetStencilMask() const { return stencilMask_; }
  350. /// Return stream frequency by vertex buffer index
  351. unsigned GetStreamFrequency(unsigned index) const;
  352. /// Return render target width and height
  353. IntVector2 GetRenderTargetDimensions() const;
  354. /// Return diffuse buffer for deferred rendering
  355. Texture2D* GetDiffBuffer() const { return diffBuffer_; }
  356. /// Return normal buffer for deferred rendering
  357. Texture2D* GetNormalBuffer() const { return normalBuffer_; }
  358. /// Return depth buffer for deferred rendering. If reading hardware depth is supported, return a depth texture
  359. Texture2D* GetDepthBuffer() const { return depthBuffer_; }
  360. /// Return screen buffer for post-processing
  361. Texture2D* GetScreenBuffer(unsigned index) const { return screenBuffer_[index & (NUM_SCREEN_BUFFERS - 1)]; }
  362. /// Add a GPU object to keep track of. Called by GPUObject.
  363. void AddGPUObject(GPUObject* object);
  364. /// Remove a GPU object. Called by GPUObject
  365. void RemoveGPUObject(GPUObject* object);
  366. private:
  367. /// Create the application window
  368. bool OpenWindow(int width, int height);
  369. /// Create the Direct3D interface
  370. bool CreateInterface();
  371. /// Create the Direct3D device
  372. bool CreateDevice(unsigned adapter, unsigned deviceType);
  373. /// Create deferred rendering render targets
  374. void CreateRenderTargets();
  375. /// Reset the Direct3D device
  376. void ResetDevice();
  377. /// Notify all GPU resources so they can release themselves as needed
  378. void OnDeviceLost();
  379. /// Notify all GPU resources so they can recreate themselves as needed
  380. void OnDeviceReset();
  381. /// Reset cached rendering state
  382. void ResetCachedState();
  383. /// Initialize shader parameter and texture unit mappings
  384. void InitializeShaderParameters();
  385. /// Handle operating system window message
  386. void HandleWindowMessage(StringHash eventType, VariantMap& eventData);
  387. /// Implementation
  388. GraphicsImpl* impl_;
  389. /// Window title
  390. std::string windowTitle_;
  391. /// Rendering mode
  392. RenderMode mode_;
  393. /// Window width
  394. int width_;
  395. /// Window height
  396. int height_;
  397. /// Multisampling mode
  398. int multiSample_;
  399. /// Stored window X-position
  400. int windowPosX_;
  401. /// Stored window Y-position
  402. int windowPosY_;
  403. /// Fullscreen flag
  404. bool fullscreen_;
  405. /// Vertical sync flag
  406. bool vsync_;
  407. /// Flush GPU command queue flag
  408. bool flushGPU_;
  409. /// Direct3D device lost flag
  410. bool deviceLost_;
  411. /// Query issued (used to flush the GPU command queue) flag
  412. bool queryIssued_;
  413. /// Deferred rendering support flag
  414. bool deferredSupport_;
  415. /// Light prepass support flag
  416. bool prepassSupport_;
  417. /// Hardware shadow map depth compare support flag
  418. bool hardwareShadowSupport_;
  419. /// 24-bit shadow map support flag
  420. bool hiresShadowSupport_;
  421. /// Stream offset support flag
  422. bool streamOffsetSupport_;
  423. /// Shader Model 3 flag
  424. bool hasSM3_;
  425. /// Force Shader Model 2 flag
  426. bool forceSM2_;
  427. /// Number of primitives this frame
  428. unsigned numPrimitives_;
  429. /// Number of batches this frame
  430. unsigned numBatches_;
  431. /// Immediate rendering primitive type
  432. PrimitiveType immediateType_;
  433. /// Immediate vertex buffer start position
  434. unsigned immediateStartPos_;
  435. /// Immediate rendering vertex buffer size
  436. unsigned immediateVertexCount_;
  437. /// Immediate rendering vertex number
  438. unsigned immediateCurrentVertex_;
  439. /// Immediate rendering vertex buffer in use
  440. VertexBuffer* immediateBuffer_;
  441. /// Immediate rendering data pointer
  442. unsigned char* immediateDataPtr_;
  443. /// GPU objects
  444. std::vector<GPUObject*> gpuObjects_;
  445. /// Vertex declarations
  446. std::map<unsigned long long, SharedPtr<VertexDeclaration> > vertexDeclarations_;
  447. /// Immediate rendering vertex buffers by vertex declaration
  448. std::map<unsigned, SharedPtr<VertexBuffer> > immediatevertexBuffer_;
  449. /// Immediate rendering vertex buffer start positions
  450. std::map<unsigned, unsigned> immediateVertexBufferPos_;
  451. /// Deferred rendering diffuse buffer
  452. SharedPtr<Texture2D> diffBuffer_;
  453. /// Deferred rendering normal buffer
  454. SharedPtr<Texture2D> normalBuffer_;
  455. /// Deferred rendering depth buffer
  456. SharedPtr<Texture2D> depthBuffer_;
  457. /// Screen buffers for post processing
  458. SharedPtr<Texture2D> screenBuffer_[NUM_SCREEN_BUFFERS];
  459. /// Shadow map dummy color texture format
  460. unsigned dummyColorFormat_;
  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* vertexBuffer_[MAX_VERTEX_STREAMS];
  467. /// Stream frequencies by vertex buffer
  468. unsigned streamFrequency_[MAX_VERTEX_STREAMS];
  469. /// Stream offsets by vertex buffer
  470. unsigned streamOffset_[MAX_VERTEX_STREAMS];
  471. /// Index buffer in use
  472. IndexBuffer* indexBuffer_;
  473. /// Vertex declaration in use
  474. VertexDeclaration* vertexDeclaration_;
  475. /// Vertex shader in use
  476. VertexShader* vertexShader_;
  477. /// Pixel shader in use
  478. PixelShader* pixelShader_;
  479. /// Vertex shader parameter mappings
  480. std::map<std::string, VSParameter> vsParameters_;
  481. /// Pixel shader parameter mappings
  482. std::map<std::string, PSParameter> psParameters_;
  483. /// Vertex shader constant register mappings
  484. unsigned vsRegisters_[MAX_VS_PARAMETERS];
  485. /// Pixel shader constant register mappings
  486. unsigned psRegisters_[MAX_PS_PARAMETERS];
  487. /// Last vertex shader parameter sources per parameter
  488. const void* lastVSParameterSources_[MAX_VS_PARAMETERS];
  489. /// Last pixel shader parameter sources per parameter
  490. const void* lastPSParameterSources_[MAX_PS_PARAMETERS];
  491. /// Textures in use
  492. Texture* texture_[MAX_TEXTURE_UNITS];
  493. /// "View texture" to prevent sampling the destination render target
  494. Texture* viewTexture_;
  495. /// Texture unit mappings
  496. std::map<std::string, TextureUnit> textureUnits_;
  497. /// Render targets in use
  498. RenderSurface* renderTarget_[MAX_RENDERTARGETS];
  499. /// Depth stencil buffer in use
  500. RenderSurface* depthStencil_;
  501. /// Viewport coordinates
  502. IntRect viewport_;
  503. /// Alpha test enable flag
  504. bool alphaTest_;
  505. /// Alpha test compare mode
  506. CompareMode alphaTestMode_;
  507. /// Alpha test reference value
  508. float alphaRef_;
  509. /// Texture anisotropy level
  510. unsigned textureAnisotropy_;
  511. /// Blending mode
  512. BlendMode blendMode_;
  513. /// Color write enable
  514. bool colorWrite_;
  515. /// Hardware culling mode
  516. CullMode cullMode_;
  517. /// Depth constant bias
  518. float constantDepthBias_;
  519. /// Depth slope scaled bias
  520. float slopeScaledDepthBias_;
  521. /// Depth compare mode
  522. CompareMode depthTestMode_;
  523. /// Depth write enable flag
  524. bool depthWrite_;
  525. /// Polygon fill mode
  526. FillMode fillMode_;
  527. /// Scissor test rectangle
  528. IntRect scissorRect_;
  529. /// Scissor test enable flag
  530. bool scissorTest_;
  531. /// Stencil test compare mode
  532. CompareMode stencilTestMode_;
  533. /// Stencil operation on pass
  534. StencilOp stencilPass_;
  535. /// Stencil operation on fail
  536. StencilOp stencilFail_;
  537. /// Stencil operation on depth fail
  538. StencilOp stencilZFail_;
  539. /// Stencil test enable flag
  540. bool stencilTest_;
  541. /// Stencil test reference value
  542. unsigned stencilRef_;
  543. /// Stencil compare bitmask
  544. unsigned stencilMask_;
  545. /// Default texture filtering mode
  546. TextureFilterMode defaultTextureFilterMode_;
  547. };
  548. /// Register Graphics library objects
  549. void RegisterGraphicsLibrary(Context* context);