text_buffer_manager.h 2.7 KB

12345678910111213141516171819202122232425262728293031323334353637383940414243444546474849505152535455565758596061626364656667686970717273747576777879808182838485
  1. /* Copyright 2013 Jeremie Roy. All rights reserved.
  2. * License: http://www.opensource.org/licenses/BSD-2-Clause
  3. */
  4. #pragma once
  5. #include "font_manager.h"
  6. BGFX_HANDLE(TextBufferHandle);
  7. /// type of vertex and index buffer to use with a TextBuffer
  8. enum BufferType
  9. {
  10. STATIC,
  11. DYNAMIC ,
  12. TRANSIENT
  13. };
  14. /// special style effect (can be combined)
  15. enum TextStyleFlags
  16. {
  17. STYLE_NORMAL = 0,
  18. STYLE_OVERLINE = 1,
  19. STYLE_UNDERLINE = 1<<1,
  20. STYLE_STRIKE_THROUGH = 1<<2,
  21. STYLE_BACKGROUND = 1<<3,
  22. };
  23. class TextBuffer;
  24. class TextBufferManager
  25. {
  26. public:
  27. TextBufferManager(FontManager* _fontManager = NULL);
  28. ~TextBufferManager();
  29. void init(const char* _shaderPath);
  30. TextBufferHandle createTextBuffer(FontType _type, BufferType _bufferType);
  31. void destroyTextBuffer(TextBufferHandle _handle);
  32. void submitTextBuffer(TextBufferHandle _handle, uint8_t _id, int32_t _depth = 0);
  33. void submitTextBufferMask(TextBufferHandle _handle, uint32_t _viewMask, int32_t _depth = 0);
  34. void setStyle(TextBufferHandle _handle, uint32_t _flags = STYLE_NORMAL);
  35. void setTextColor(TextBufferHandle _handle, uint32_t _rgba = 0x000000FF);
  36. void setBackgroundColor(TextBufferHandle _handle, uint32_t _rgba = 0x000000FF);
  37. void setOverlineColor(TextBufferHandle _handle, uint32_t _rgba = 0x000000FF);
  38. void setUnderlineColor(TextBufferHandle _handle, uint32_t _rgba = 0x000000FF);
  39. void setStrikeThroughColor(TextBufferHandle _handle, uint32_t _rgba = 0x000000FF);
  40. void setPenPosition(TextBufferHandle _handle, float _x, float _y);
  41. /// append an ASCII/utf-8 string to the buffer using current pen position and color
  42. void appendText(TextBufferHandle _handle, FontHandle _fontHandle, const char * _string);
  43. /// append a wide char unicode string to the buffer using current pen position and color
  44. void appendText(TextBufferHandle _handle, FontHandle _fontHandle, const wchar_t * _string);
  45. /// Clear the text buffer and reset its state (pen/color)
  46. void clearTextBuffer(TextBufferHandle _handle);
  47. /// return the size of the text
  48. //Rectangle measureText(FontHandle fontHandle, const char * _string);
  49. //Rectangle measureText(FontHandle fontHandle, const wchar_t * _string);
  50. private:
  51. struct BufferCache
  52. {
  53. uint16_t m_indexBufferHandle;
  54. uint16_t m_vertexBufferHandle;
  55. TextBuffer* m_textBuffer;
  56. BufferType m_bufferType;
  57. FontType m_fontType;
  58. };
  59. BufferCache* m_textBuffers;
  60. bx::HandleAlloc m_textBufferHandles;
  61. FontManager* m_fontManager;
  62. bgfx::VertexDecl m_vertexDecl;
  63. bgfx::UniformHandle u_texColor;
  64. bgfx::UniformHandle u_inverse_gamma;
  65. //shaders program
  66. bgfx::ProgramHandle m_basicProgram;
  67. bgfx::ProgramHandle m_distanceProgram;
  68. bgfx::ProgramHandle m_distanceSubpixelProgram;
  69. };