text_buffer_manager.h 2.7 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990
  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. namespace bgfx_font
  7. {
  8. BGFX_HANDLE(TextBufferHandle);
  9. /// type of vertex and index buffer to use with a TextBuffer
  10. enum BufferType
  11. {
  12. STATIC,
  13. DYNAMIC ,
  14. TRANSIENT
  15. };
  16. /// special style effect (can be combined)
  17. enum TextStyleFlags
  18. {
  19. STYLE_NORMAL = 0,
  20. STYLE_OVERLINE = 1,
  21. STYLE_UNDERLINE = 1<<1,
  22. STYLE_STRIKE_THROUGH = 1<<2,
  23. STYLE_BACKGROUND = 1<<3,
  24. };
  25. class TextBuffer;
  26. class TextBufferManager
  27. {
  28. public:
  29. TextBufferManager(FontManager* fontManager = NULL);
  30. ~TextBufferManager();
  31. void init(const char* shaderPath);
  32. TextBufferHandle createTextBuffer(FontType type, BufferType bufferType);
  33. void destroyTextBuffer(TextBufferHandle handle);
  34. void submitTextBuffer(TextBufferHandle handle, uint8_t id, int32_t depth = 0);
  35. void submitTextBufferMask(TextBufferHandle handle, uint32_t viewMask, int32_t depth = 0);
  36. void setStyle(TextBufferHandle handle, uint32_t flags = STYLE_NORMAL);
  37. void setTextColor(TextBufferHandle handle, uint32_t rgba = 0x000000FF);
  38. void setBackgroundColor(TextBufferHandle handle, uint32_t rgba = 0x000000FF);
  39. void setOverlineColor(TextBufferHandle handle, uint32_t rgba = 0x000000FF);
  40. void setUnderlineColor(TextBufferHandle handle, uint32_t rgba = 0x000000FF);
  41. void setStrikeThroughColor(TextBufferHandle handle, uint32_t rgba = 0x000000FF);
  42. void setPenPosition(TextBufferHandle handle, float x, float y);
  43. /// append an ASCII/utf-8 string to the buffer using current pen position and color
  44. void appendText(TextBufferHandle _handle, FontHandle fontHandle, const char * _string);
  45. /// append a wide char unicode string to the buffer using current pen position and color
  46. void appendText(TextBufferHandle _handle, FontHandle fontHandle, const wchar_t * _string);
  47. /// Clear the text buffer and reset its state (pen/color)
  48. void clearTextBuffer(TextBufferHandle _handle);
  49. /// return the size of the text
  50. //Rectangle measureText(FontHandle fontHandle, const char * _string);
  51. //Rectangle measureText(FontHandle fontHandle, const wchar_t * _string);
  52. private:
  53. struct BufferCache
  54. {
  55. uint16_t indexBufferHandle;
  56. uint16_t vertexBufferHandle;
  57. TextBuffer* textBuffer;
  58. BufferType bufferType;
  59. FontType fontType;
  60. };
  61. BufferCache* m_textBuffers;
  62. bx::HandleAlloc m_textBufferHandles;
  63. FontManager* m_fontManager;
  64. bgfx::VertexDecl m_vertexDecl;
  65. bgfx::UniformHandle m_u_texColor;
  66. bgfx::UniformHandle m_u_inverse_gamma;
  67. //shaders program
  68. bgfx::ProgramHandle m_basicProgram;
  69. bgfx::ProgramHandle m_distanceProgram;
  70. bgfx::ProgramHandle m_distanceSubpixelProgram;
  71. };
  72. }