RenderInterfaceSFML.h 3.9 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990
  1. /*
  2. * This source file is part of RmlUi, the HTML/CSS Interface Middleware
  3. *
  4. * For the latest information, see http://github.com/mikke89/RmlUi
  5. *
  6. * Copyright (c) 2008-2010 Nuno Silva
  7. * Copyright (c) 2019 The RmlUi Team, and contributors
  8. *
  9. * Permission is hereby granted, free of charge, to any person obtaining a copy
  10. * of this software and associated documentation files (the "Software"), to deal
  11. * in the Software without restriction, including without limitation the rights
  12. * to use, copy, modify, merge, publish, distribute, sublicense, and/or sell
  13. * copies of the Software, and to permit persons to whom the Software is
  14. * furnished to do so, subject to the following conditions:
  15. *
  16. * The above copyright notice and this permission notice shall be included in
  17. * all copies or substantial portions of the Software.
  18. *
  19. * THE SOFTWARE IS PROVIDED "AS IS", WITHOUT WARRANTY OF ANY KIND, EXPRESS OR
  20. * IMPLIED, INCLUDING BUT NOT LIMITED TO THE WARRANTIES OF MERCHANTABILITY,
  21. * FITNESS FOR A PARTICULAR PURPOSE AND NONINFRINGEMENT. IN NO EVENT SHALL THE
  22. * AUTHORS OR COPYRIGHT HOLDERS BE LIABLE FOR ANY CLAIM, DAMAGES OR OTHER
  23. * LIABILITY, WHETHER IN AN ACTION OF CONTRACT, TORT OR OTHERWISE, ARISING FROM,
  24. * OUT OF OR IN CONNECTION WITH THE SOFTWARE OR THE USE OR OTHER DEALINGS IN
  25. * THE SOFTWARE.
  26. *
  27. */
  28. #ifndef RENDERINTERFACESFML_H
  29. #define RENDERINTERFACESFML_H
  30. // NOTE: uncomment this only when you want to use the
  31. // OpenGL Extension Wrangler Library (GLEW)
  32. //#define ENABLE_GLEW
  33. // if the OpenGL Extension Wrangler Library (GLEW) should be used include it
  34. #ifdef ENABLE_GLEW
  35. #include <GL/glew.h>
  36. #endif
  37. #include <RmlUi/Core/RenderInterface.h>
  38. #include <SFML/Graphics.hpp>
  39. // if the OpenGL Extension Wrangler Library (GLEW) should not be used
  40. // include the standard OpenGL library
  41. #ifndef ENABLE_GLEW
  42. #include "../../../shell/include/ShellOpenGL.h"
  43. #endif
  44. class RmlUiSFMLRenderer : public Rml::Core::RenderInterface
  45. {
  46. public:
  47. RmlUiSFMLRenderer();
  48. /// Sets the window
  49. void SetWindow(sf::RenderWindow *Window);
  50. /// Returns the currently assigned window
  51. sf::RenderWindow *GetWindow();
  52. /// Resizes the viewport automatically
  53. void Resize();
  54. /// Called by RmlUi when it wants to render geometry that it does not wish to optimise.
  55. void RenderGeometry(Rml::Core::Vertex* vertices, int num_vertices, int* indices, int num_indices, Rml::Core::TextureHandle texture, const Rml::Core::Vector2f& translation) override;
  56. /// Called by RmlUi when it wants to compile geometry it believes will be static for the forseeable future.
  57. Rml::Core::CompiledGeometryHandle CompileGeometry(Rml::Core::Vertex* vertices, int num_vertices, int* indices, int num_indices, Rml::Core::TextureHandle texture) override;
  58. /// Called by RmlUi when it wants to render application-compiled geometry.
  59. void RenderCompiledGeometry(Rml::Core::CompiledGeometryHandle geometry, const Rml::Core::Vector2f& translation) override;
  60. /// Called by RmlUi when it wants to release application-compiled geometry.
  61. void ReleaseCompiledGeometry(Rml::Core::CompiledGeometryHandle geometry) override;
  62. /// Called by RmlUi when it wants to enable or disable scissoring to clip content.
  63. void EnableScissorRegion(bool enable) override;
  64. /// Called by RmlUi when it wants to change the scissor region.
  65. void SetScissorRegion(int x, int y, int width, int height) override;
  66. /// Called by RmlUi when a texture is required by the library.
  67. bool LoadTexture(Rml::Core::TextureHandle& texture_handle, Rml::Core::Vector2i& texture_dimensions, const Rml::Core::String& source) override;
  68. /// Called by RmlUi when a texture is required to be built from an internally-generated sequence of pixels.
  69. bool GenerateTexture(Rml::Core::TextureHandle& texture_handle, const Rml::Core::byte* source, const Rml::Core::Vector2i& source_dimensions) override;
  70. /// Called by RmlUi when a loaded texture is no longer required.
  71. void ReleaseTexture(Rml::Core::TextureHandle texture_handle) override;
  72. private:
  73. sf::RenderWindow *MyWindow;
  74. };
  75. #endif