2
0

UIBatch.h 3.5 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114
  1. //
  2. // Urho3D Engine
  3. // Copyright (c) 2008-2011 Lasse Öörni
  4. //
  5. // Permission is hereby granted, free of charge, to any person obtaining a copy
  6. // of this software and associated documentation files (the "Software"), to deal
  7. // in the Software without restriction, including without limitation the rights
  8. // to use, copy, modify, merge, publish, distribute, sublicense, and/or sell
  9. // copies of the Software, and to permit persons to whom the Software is
  10. // furnished to do so, subject to the following conditions:
  11. //
  12. // The above copyright notice and this permission notice shall be included in
  13. // all copies or substantial portions of the Software.
  14. //
  15. // THE SOFTWARE IS PROVIDED "AS IS", WITHOUT WARRANTY OF ANY KIND, EXPRESS OR
  16. // IMPLIED, INCLUDING BUT NOT LIMITED TO THE WARRANTIES OF MERCHANTABILITY,
  17. // FITNESS FOR A PARTICULAR PURPOSE AND NONINFRINGEMENT. IN NO EVENT SHALL THE
  18. // AUTHORS OR COPYRIGHT HOLDERS BE LIABLE FOR ANY CLAIM, DAMAGES OR OTHER
  19. // LIABILITY, WHETHER IN AN ACTION OF CONTRACT, TORT OR OTHERWISE, ARISING FROM,
  20. // OUT OF OR IN CONNECTION WITH THE SOFTWARE OR THE USE OR OTHER DEALINGS IN
  21. // THE SOFTWARE.
  22. //
  23. #ifndef UI_UIBATCH_H
  24. #define UI_UIBATCH_H
  25. #include "Color.h"
  26. #include "Rect.h"
  27. #include "RendererDefs.h"
  28. #include <vector>
  29. class PixelShader;
  30. class Renderer;
  31. class Texture;
  32. class UIElement;
  33. class VertexShader;
  34. //! UI rendering quad
  35. struct UIQuad
  36. {
  37. //! Left coordinate
  38. int mLeft;
  39. //! Top coordinate
  40. int mTop;
  41. //! Right coordinate
  42. int mRight;
  43. //! Bottom coordinate
  44. int mBottom;
  45. //! Left texture coordinate
  46. short mLeftUV;
  47. //! Top texture coordinate
  48. short mTopUV;
  49. //! Right texture coordinate
  50. short mRightUV;
  51. //! Bottom texture coordinate
  52. short mBottomUV;
  53. //! Top left color
  54. unsigned mTopLeftColor;
  55. //! Top right color
  56. unsigned mTopRightColor;
  57. //! Bottom left color
  58. unsigned mBottomLeftColor;
  59. //! Bottom right color
  60. unsigned mBottomRightColor;
  61. };
  62. //! Describes an UI rendering draw call
  63. class UIBatch
  64. {
  65. public:
  66. //! Construct with defaults
  67. UIBatch() :
  68. mTexture(0),
  69. mQuads(0),
  70. mQuadStart(0),
  71. mQuadCount(0)
  72. {
  73. }
  74. //! Begin adding quads
  75. void begin(std::vector<UIQuad>* quads);
  76. //! Add a quad
  77. void addQuad(UIElement& element, int x, int y, int width, int height, int texOffsetX, int texOffsetY);
  78. //! Add a quad with scaled texture
  79. void addQuad(UIElement& element, int x, int y, int width, int height, int texOffsetX, int texOffsetY, int texWidth, int texHeight);
  80. //! Add a quad with custom color
  81. void addQuad(UIElement& element, int x, int y, int width, int height, int texOffsetX, int texOffsetY, int texWidth, int texHeight,
  82. const Color& color);
  83. //! Merge with another batch
  84. bool merge(const UIBatch& batch);
  85. //! Draw
  86. void draw(Renderer* renderer, VertexShader* vs, PixelShader* ps) const;
  87. //! Add or merge a batch
  88. static void addOrMerge(const UIBatch& batch, std::vector<UIBatch>& batches);
  89. //! Return an interpolated color for an UI element
  90. static unsigned getInterpolatedColor(UIElement& element, int x, int y);
  91. //! Blending mode
  92. BlendMode mBlendMode;
  93. //! Scissor rectangle
  94. IntRect mScissor;
  95. //! Texture
  96. Texture* mTexture;
  97. //! Quads
  98. std::vector<UIQuad>* mQuads;
  99. //! Quad start index
  100. unsigned mQuadStart;
  101. //! Number of quads
  102. unsigned mQuadCount;
  103. };
  104. #endif // UI_UIBATCH_H