RenderInterfaceDirectx10.h 3.8 KB

12345678910111213141516171819202122232425262728293031323334353637383940414243444546474849505152535455565758596061626364656667686970717273747576777879808182838485868788899091929394959697
  1. #ifndef RENDERINTERFACEDIRECTX_H
  2. #define RENDERINTERFACEDIRECTX_H
  3. #include <Rocket/Core/RenderInterface.h>
  4. #include "../../../shell/include/ShellRenderInterfaceExtensions.h"
  5. #include <d3d10.h>
  6. #include <d3dx10.h>
  7. /**
  8. A sample render interface for Rocket into DirectX 10.
  9. TODO:
  10. 1) Constant Buffers for variables
  11. @author Brian McDonald
  12. */
  13. class RenderInterfaceDirectX10 : public Rocket::Core::RenderInterface, public ShellRenderInterfaceExtensions
  14. {
  15. public:
  16. RenderInterfaceDirectX10();
  17. virtual ~RenderInterfaceDirectX10(void);
  18. /// Called by Rocket when it wants to render geometry that it does not wish to optimise.
  19. virtual void RenderGeometry(Rocket::Core::Vertex* vertices, int num_vertices, int* indices, int num_indices, Rocket::Core::TextureHandle texture, const Rocket::Core::Vector2f& translation);
  20. /// Called by Rocket when it wants to compile geometry it believes will be static for the forseeable future.
  21. virtual Rocket::Core::CompiledGeometryHandle CompileGeometry(Rocket::Core::Vertex* vertices, int num_vertices, int* indices, int num_indices, Rocket::Core::TextureHandle texture);
  22. /// Called by Rocket when it wants to render application-compiled geometry.
  23. virtual void RenderCompiledGeometry(Rocket::Core::CompiledGeometryHandle geometry, const Rocket::Core::Vector2f& translation);
  24. /// Called by Rocket when it wants to release application-compiled geometry.
  25. virtual void ReleaseCompiledGeometry(Rocket::Core::CompiledGeometryHandle geometry);
  26. /// Called by Rocket when it wants to enable or disable scissoring to clip content.
  27. virtual void EnableScissorRegion(bool enable);
  28. /// Called by Rocket when it wants to change the scissor region.
  29. virtual void SetScissorRegion(int x, int y, int width, int height);
  30. /// Called by Rocket when a texture is required by the library.
  31. virtual bool LoadTexture(Rocket::Core::TextureHandle& texture_handle, Rocket::Core::Vector2i& texture_dimensions, const Rocket::Core::String& source);
  32. /// Called by Rocket when a texture is required to be built from an internally-generated sequence of pixels.
  33. virtual bool GenerateTexture(Rocket::Core::TextureHandle& texture_handle, const byte* source, const Rocket::Core::Vector2i& source_dimensions);
  34. /// Called by Rocket when a loaded texture is no longer required.
  35. virtual void ReleaseTexture(Rocket::Core::TextureHandle texture_handle);
  36. /// Returns the native horizontal texel offset for the renderer.
  37. float GetHorizontalTexelOffset();
  38. /// Returns the native vertical texel offset for the renderer.
  39. float GetVerticalTexelOffset();
  40. //loads the effect from memory
  41. void setupEffect();
  42. // ShellRenderInterfaceExtensions
  43. virtual void SetViewport(int width, int height);
  44. virtual void SetContext(void *context);
  45. virtual bool AttachToNative(void *nativeWindow);
  46. virtual void DetachFromNative(void);
  47. virtual void PrepareRenderBuffer(void);
  48. virtual void PresentRenderBuffer(void);
  49. private:
  50. // Rocket Context, needed for when the shell window is resized so we can update the Rocket::Core::Context
  51. // dimensions
  52. void *m_rocket_context;
  53. //The D3D 10 Device
  54. ID3D10Device * m_pD3D10Device;
  55. //The Effect we are using to render GUI
  56. ID3D10Effect * m_pEffect;
  57. //The Current technique
  58. ID3D10EffectTechnique* m_pTechnique;
  59. //The Vertex Layout
  60. ID3D10InputLayout* m_pVertexLayout;
  61. //Swap Chain
  62. IDXGISwapChain* m_pSwapChain;
  63. //Render Target
  64. ID3D10RenderTargetView* m_pRenderTargetView;
  65. //Effect variables, used to send variables to the effect
  66. ID3D10EffectMatrixVariable * m_pProjectionMatrixVariable;
  67. ID3D10EffectMatrixVariable * m_pWorldMatrixVariable;
  68. ID3D10EffectShaderResourceVariable *m_pDiffuseTextureVariable;
  69. //Matrices
  70. D3DXMATRIX m_matProjection;
  71. D3DXMATRIX m_matWorld;
  72. //Renderstate Blocks
  73. ID3D10RasterizerState *m_pScissorTestEnable;
  74. ID3D10RasterizerState *m_pScissorTestDisable;
  75. };
  76. #endif