UIBatch.h 3.5 KB

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