UIBatch.h 3.5 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111
  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. #pragma once
  24. #include "Color.h"
  25. #include "PODVector.h"
  26. #include "Rect.h"
  27. #include "GraphicsDefs.h"
  28. #include <vector>
  29. class PixelShader;
  30. class Graphics;
  31. class Texture;
  32. class UIElement;
  33. class VertexShader;
  34. /// UI rendering quad
  35. struct UIQuad
  36. {
  37. /// Left coordinate
  38. int left_;
  39. /// Top coordinate
  40. int top_;
  41. /// Right coordinate
  42. int right_;
  43. /// Bottom coordinate
  44. int bottom_;
  45. /// Left texture coordinate
  46. short leftUV_;
  47. /// Top texture coordinate
  48. short topUV_;
  49. /// Right texture coordinate
  50. short rightUV_;
  51. /// Bottom texture coordinate
  52. short bottomUV_;
  53. /// Top left color
  54. unsigned topLeftColor_;
  55. /// Top right color
  56. unsigned topRightColor_;
  57. /// Bottom left color
  58. unsigned bottomLeftColor_;
  59. /// Bottom right color
  60. unsigned bottomRightColor_;
  61. };
  62. /// UI rendering draw call
  63. class UIBatch
  64. {
  65. public:
  66. /// Construct with defaults
  67. UIBatch() :
  68. texture_(0),
  69. quads_(0),
  70. quadStart_(0),
  71. quadCount_(0)
  72. {
  73. }
  74. /// Begin adding quads
  75. void Begin(PODVector<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, const Color& color);
  82. /// Merge with another batch
  83. bool Merge(const UIBatch& batch);
  84. /// Draw
  85. void Draw(Graphics* graphics, VertexShader* vs, PixelShader* ps) const;
  86. /// Add or merge a batch
  87. static void AddOrMerge(const UIBatch& batch, PODVector<UIBatch>& batches);
  88. /// Return an interpolated color for an UI element
  89. static unsigned GetInterpolatedColor(UIElement& element, int x, int y);
  90. /// Blending mode
  91. BlendMode blendMode_;
  92. /// Scissor rectangle
  93. IntRect scissor_;
  94. /// Texture
  95. Texture* texture_;
  96. /// Quads
  97. PODVector<UIQuad>* quads_;
  98. /// Quad start index
  99. unsigned quadStart_;
  100. /// Number of quads
  101. unsigned quadCount_;
  102. };