text_buffer_manager.h 3.6 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111
  1. /*
  2. * Copyright 2013 Jeremie Roy. All rights reserved.
  3. * License: https://github.com/bkaradzic/bgfx#license-bsd-2-clause
  4. */
  5. #ifndef TEXT_BUFFER_MANAGER_H_HEADER_GUARD
  6. #define TEXT_BUFFER_MANAGER_H_HEADER_GUARD
  7. #include "font_manager.h"
  8. BGFX_HANDLE(TextBufferHandle)
  9. #define MAX_TEXT_BUFFER_COUNT 64
  10. /// type of vertex and index buffer to use with a TextBuffer
  11. struct BufferType
  12. {
  13. enum Enum
  14. {
  15. Static,
  16. Dynamic,
  17. Transient,
  18. };
  19. };
  20. /// special style effect (can be combined)
  21. enum TextStyleFlags
  22. {
  23. STYLE_NORMAL = 0,
  24. STYLE_OVERLINE = 1,
  25. STYLE_UNDERLINE = 1 << 1,
  26. STYLE_STRIKE_THROUGH = 1 << 2,
  27. STYLE_BACKGROUND = 1 << 3,
  28. };
  29. struct TextRectangle
  30. {
  31. float width, height;
  32. };
  33. class TextBuffer;
  34. class TextBufferManager
  35. {
  36. public:
  37. TextBufferManager(FontManager* _fontManager);
  38. ~TextBufferManager();
  39. TextBufferHandle createTextBuffer(uint32_t _type, BufferType::Enum _bufferType);
  40. void destroyTextBuffer(TextBufferHandle _handle);
  41. void submitTextBuffer(TextBufferHandle _handle, bgfx::ViewId _id, int32_t _depth = 0);
  42. void setStyle(TextBufferHandle _handle, uint32_t _flags = STYLE_NORMAL);
  43. void setTextColor(TextBufferHandle _handle, uint32_t _rgba = 0x000000FF);
  44. void setBackgroundColor(TextBufferHandle _handle, uint32_t _rgba = 0x000000FF);
  45. void setOverlineColor(TextBufferHandle _handle, uint32_t _rgba = 0x000000FF);
  46. void setUnderlineColor(TextBufferHandle _handle, uint32_t _rgba = 0x000000FF);
  47. void setStrikeThroughColor(TextBufferHandle _handle, uint32_t _rgba = 0x000000FF);
  48. void setOutlineWidth(TextBufferHandle _handle, float _outlineWidth = 3.0f);
  49. void setOutlineColor(TextBufferHandle _handle, uint32_t _rgba = 0x000000FF);
  50. void setDropShadowOffset(TextBufferHandle _handle, float _u, float _v);
  51. void setDropShadowColor(TextBufferHandle _handle, uint32_t _rgba = 0x000000FF);
  52. void setDropShadowSoftener(TextBufferHandle _handle, float smoother = 1.0f);
  53. void setPenPosition(TextBufferHandle _handle, float _x, float _y);
  54. /// Append an ASCII/utf-8 string to the buffer using current pen position and color.
  55. void appendText(TextBufferHandle _handle, FontHandle _fontHandle, const char* _string, const char* _end = NULL);
  56. /// Append a wide char unicode string to the buffer using current pen position and color.
  57. void appendText(TextBufferHandle _handle, FontHandle _fontHandle, const wchar_t* _string, const wchar_t* _end = NULL);
  58. /// Append a whole face of the atlas cube, mostly used for debugging and visualizing atlas.
  59. void appendAtlasFace(TextBufferHandle _handle, uint16_t _faceIndex);
  60. /// Clear the text buffer and reset its state (pen/color).
  61. void clearTextBuffer(TextBufferHandle _handle);
  62. /// Return the rectangular size of the current text buffer (including all its content).
  63. TextRectangle getRectangle(TextBufferHandle _handle) const;
  64. private:
  65. struct BufferCache
  66. {
  67. uint16_t indexBufferHandleIdx;
  68. uint16_t vertexBufferHandleIdx;
  69. TextBuffer* textBuffer;
  70. BufferType::Enum bufferType;
  71. uint32_t fontType;
  72. };
  73. BufferCache* m_textBuffers;
  74. bx::HandleAllocT<MAX_TEXT_BUFFER_COUNT> m_textBufferHandles;
  75. FontManager* m_fontManager;
  76. bgfx::VertexLayout m_vertexLayout;
  77. bgfx::UniformHandle s_texColor;
  78. bgfx::UniformHandle u_dropShadowColor;
  79. bgfx::UniformHandle u_params;
  80. bgfx::ProgramHandle m_basicProgram;
  81. bgfx::ProgramHandle m_distanceProgram;
  82. bgfx::ProgramHandle m_distanceSubpixelProgram;
  83. bgfx::ProgramHandle m_distanceOutlineProgram;
  84. bgfx::ProgramHandle m_distanceOutlineImageProgram;
  85. bgfx::ProgramHandle m_distanceDropShadowProgram;
  86. bgfx::ProgramHandle m_distanceDropShadowImageProgram;
  87. bgfx::ProgramHandle m_distanceOutlineDropShadowImageProgram;
  88. };
  89. #endif // TEXT_BUFFER_MANAGER_H_HEADER_GUARD