RenderInterface.h 7.7 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118119120121122123124125126127128129130131132133134135136137138139140141142143
  1. /*
  2. * This source file is part of libRocket, the HTML/CSS Interface Middleware
  3. *
  4. * For the latest information, see http://www.librocket.com
  5. *
  6. * Copyright (c) 2008-2010 CodePoint Ltd, Shift Technology Ltd
  7. *
  8. * Permission is hereby granted, free of charge, to any person obtaining a copy
  9. * of this software and associated documentation files (the "Software"), to deal
  10. * in the Software without restriction, including without limitation the rights
  11. * to use, copy, modify, merge, publish, distribute, sublicense, and/or sell
  12. * copies of the Software, and to permit persons to whom the Software is
  13. * furnished to do so, subject to the following conditions:
  14. *
  15. * The above copyright notice and this permission notice shall be included in
  16. * all copies or substantial portions of the Software.
  17. *
  18. * THE SOFTWARE IS PROVIDED "AS IS", WITHOUT WARRANTY OF ANY KIND, EXPRESS OR
  19. * IMPLIED, INCLUDING BUT NOT LIMITED TO THE WARRANTIES OF MERCHANTABILITY,
  20. * FITNESS FOR A PARTICULAR PURPOSE AND NONINFRINGEMENT. IN NO EVENT SHALL THE
  21. * AUTHORS OR COPYRIGHT HOLDERS BE LIABLE FOR ANY CLAIM, DAMAGES OR OTHER
  22. * LIABILITY, WHETHER IN AN ACTION OF CONTRACT, TORT OR OTHERWISE, ARISING FROM,
  23. * OUT OF OR IN CONNECTION WITH THE SOFTWARE OR THE USE OR OTHER DEALINGS IN
  24. * THE SOFTWARE.
  25. *
  26. */
  27. #ifndef ROCKETCORERENDERINTERFACE_H
  28. #define ROCKETCORERENDERINTERFACE_H
  29. #include "ReferenceCountable.h"
  30. #include "Header.h"
  31. #include "Texture.h"
  32. #include "Vertex.h"
  33. #include "Types.h"
  34. namespace Rocket {
  35. namespace Core {
  36. class Context;
  37. /**
  38. The abstract base class for application-specific rendering implementation. Your application must provide a concrete
  39. implementation of this class and install it through Core::SetRenderInterface() in order for anything to be rendered.
  40. @author Peter Curry
  41. */
  42. class ROCKETCORE_API RenderInterface : public ReferenceCountable
  43. {
  44. public:
  45. RenderInterface();
  46. virtual ~RenderInterface();
  47. /// Called by Rocket when it wants to render geometry that the application does not wish to optimise. Note that
  48. /// Rocket renders everything as triangles.
  49. /// @param[in] vertices The geometry's vertex data.
  50. /// @param[in] num_vertices The number of vertices passed to the function.
  51. /// @param[in] indices The geometry's index data.
  52. /// @param[in] num_indices The number of indices passed to the function. This will always be a multiple of three.
  53. /// @param[in] texture The texture to be applied to the geometry. This may be NULL, in which case the geometry is untextured.
  54. /// @param[in] translation The translation to apply to the geometry.
  55. virtual void RenderGeometry(Vertex* vertices, int num_vertices, int* indices, int num_indices, TextureHandle texture, const Vector2f& translation) = 0;
  56. /// Called by Rocket when it wants to compile geometry it believes will be static for the forseeable future.
  57. /// If supported, this should be return a pointer to an optimised, application-specific version of the data. If
  58. /// not, do not override the function or return NULL; the simpler RenderGeometry() will be called instead.
  59. /// @param[in] vertices The geometry's vertex data.
  60. /// @param[in] num_vertices The number of vertices passed to the function.
  61. /// @param[in] indices The geometry's index data.
  62. /// @param[in] num_indices The number of indices passed to the function. This will always be a multiple of three.
  63. /// @param[in] texture The texture to be applied to the geometry. This may be NULL, in which case the geometry is untextured.
  64. /// @return The application-specific compiled geometry. Compiled geometry will be stored and rendered using RenderCompiledGeometry() in future calls, and released with ReleaseCompiledGeometry() when it is no longer needed.
  65. virtual CompiledGeometryHandle CompileGeometry(Vertex* vertices, int num_vertices, int* indices, int num_indices, TextureHandle texture);
  66. /// Called by Rocket when it wants to render application-compiled geometry.
  67. /// @param[in] geometry The application-specific compiled geometry to render.
  68. /// @param[in] translation The translation to apply to the geometry.
  69. virtual void RenderCompiledGeometry(CompiledGeometryHandle geometry, const Vector2f& translation);
  70. /// Called by Rocket when it wants to release application-compiled geometry.
  71. /// @param[in] geometry The application-specific compiled geometry to release.
  72. virtual void ReleaseCompiledGeometry(CompiledGeometryHandle geometry);
  73. /// Called by Rocket when it wants to enable or disable scissoring to clip content.
  74. /// @param[in] enable True if scissoring is to enabled, false if it is to be disabled.
  75. virtual void EnableScissorRegion(bool enable) = 0;
  76. /// Called by Rocket when it wants to change the scissor region.
  77. /// @param[in] x The left-most pixel to be rendered. All pixels to the left of this should be clipped.
  78. /// @param[in] y The top-most pixel to be rendered. All pixels to the top of this should be clipped.
  79. /// @param[in] width The width of the scissored region. All pixels to the right of (x + width) should be clipped.
  80. /// @param[in] height The height of the scissored region. All pixels to below (y + height) should be clipped.
  81. virtual void SetScissorRegion(int x, int y, int width, int height) = 0;
  82. /// Called by Rocket when a texture is required by the library.
  83. /// @param[out] texture_handle The handle to write the texture handle for the loaded texture to.
  84. /// @param[out] texture_dimensions The variable to write the dimensions of the loaded texture.
  85. /// @param[in] source The application-defined image source, joined with the path of the referencing document.
  86. /// @return True if the load attempt succeeded and the handle and dimensions are valid, false if not.
  87. virtual bool LoadTexture(TextureHandle& texture_handle, Vector2i& texture_dimensions, const String& source);
  88. /// Called by Rocket when a texture is required to be built from an internally-generated sequence of pixels.
  89. /// @param[out] texture_handle The handle to write the texture handle for the generated texture to.
  90. /// @param[in] source The raw 8-bit texture data. Each pixel is made up of four 8-bit values, indicating red, green, blue and alpha in that order.
  91. /// @param[in] source_dimensions The dimensions, in pixels, of the source data.
  92. /// @return True if the texture generation succeeded and the handle is valid, false if not.
  93. virtual bool GenerateTexture(TextureHandle& texture_handle, const byte* source, const Vector2i& source_dimensions);
  94. /// Called by Rocket when a loaded texture is no longer required.
  95. /// @param texture The texture handle to release.
  96. virtual void ReleaseTexture(TextureHandle texture);
  97. /// Returns the native horizontal texel offset for the renderer.
  98. /// @return The renderer's horizontal texel offset. The default implementation returns 0.
  99. virtual float GetHorizontalTexelOffset();
  100. /// Returns the native vertical texel offset for the renderer.
  101. /// @return The renderer's vertical texel offset. The default implementation returns 0.
  102. virtual float GetVerticalTexelOffset();
  103. /// Called by Rocket when it wants to set the current transform matrix to a new matrix.
  104. /// @param[in] transform The new transform to apply.
  105. virtual void PushTransform(const Matrix4f& transform);
  106. /// Called by Rocket when it wants to revert the latest transform change.
  107. /// @param[in] transform This is the transform to unapply.
  108. /// It always equals the argument of the latest call to PushTransform().
  109. virtual void PopTransform(const Matrix4f& transform);
  110. /// Called when this render interface is released.
  111. virtual void Release();
  112. /// Get the context currently being rendered. This is only valid during RenderGeometry,
  113. /// CompileGeometry, RenderCompiledGeometry, EnableScissorRegion and SetScissorRegion.
  114. Context* GetContext() const;
  115. protected:
  116. virtual void OnReferenceDeactivate();
  117. private:
  118. Context* context;
  119. friend class Context;
  120. };
  121. }
  122. }
  123. #endif