UIBatch.h 4.0 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118119
  1. //
  2. // Copyright (c) 2008-2013 the Urho3D project.
  3. //
  4. // Permission is hereby granted, free of charge, to any person obtaining a copy
  5. // of this software and associated documentation files (the "Software"), to deal
  6. // in the Software without restriction, including without limitation the rights
  7. // to use, copy, modify, merge, publish, distribute, sublicense, and/or sell
  8. // copies of the Software, and to permit persons to whom the Software is
  9. // furnished to do so, subject to the following conditions:
  10. //
  11. // The above copyright notice and this permission notice shall be included in
  12. // all copies or substantial portions of the Software.
  13. //
  14. // THE SOFTWARE IS PROVIDED "AS IS", WITHOUT WARRANTY OF ANY KIND, EXPRESS OR
  15. // IMPLIED, INCLUDING BUT NOT LIMITED TO THE WARRANTIES OF MERCHANTABILITY,
  16. // FITNESS FOR A PARTICULAR PURPOSE AND NONINFRINGEMENT. IN NO EVENT SHALL THE
  17. // AUTHORS OR COPYRIGHT HOLDERS BE LIABLE FOR ANY CLAIM, DAMAGES OR OTHER
  18. // LIABILITY, WHETHER IN AN ACTION OF CONTRACT, TORT OR OTHERWISE, ARISING FROM,
  19. // OUT OF OR IN CONNECTION WITH THE SOFTWARE OR THE USE OR OTHER DEALINGS IN
  20. // THE SOFTWARE.
  21. //
  22. #pragma once
  23. #include "Color.h"
  24. #include "GraphicsDefs.h"
  25. #include "Rect.h"
  26. namespace Urho3D
  27. {
  28. class PixelShader;
  29. class Graphics;
  30. class ShaderVariation;
  31. class Texture;
  32. class UIElement;
  33. /// %UI rendering quad.
  34. struct UIQuad
  35. {
  36. /// Construct with defaults.
  37. UIQuad();
  38. /// Construct.
  39. UIQuad(const UIElement& element, int x, int y, int width, int height, int texOffsetX, int texOffsetY,
  40. int texWidth = 0, int texHeight = 0, Color* color = 0);
  41. /// Return an interpolated color for an UI element.
  42. static unsigned GetInterpolatedColor(const UIElement& element, int x, int y);
  43. /// Left coordinate.
  44. int left_;
  45. /// Top coordinate.
  46. int top_;
  47. /// Right coordinate.
  48. int right_;
  49. /// Bottom coordinate.
  50. int bottom_;
  51. /// Left texture coordinate.
  52. short leftUV_;
  53. /// Top texture coordinate.
  54. short topUV_;
  55. /// Right texture coordinate.
  56. short rightUV_;
  57. /// Bottom texture coordinate.
  58. short bottomUV_;
  59. /// Top left color.
  60. unsigned topLeftColor_;
  61. /// Top right color.
  62. unsigned topRightColor_;
  63. /// Bottom left color.
  64. unsigned bottomLeftColor_;
  65. /// Bottom right color.
  66. unsigned bottomRightColor_;
  67. /// Defined flag.
  68. bool defined_;
  69. };
  70. /// %UI rendering draw call.
  71. class UIBatch
  72. {
  73. public:
  74. /// Construct with defaults.
  75. UIBatch();
  76. /// Construct
  77. UIBatch(BlendMode blendMode, const IntRect& scissor, Texture* texture, PODVector<UIQuad>* quads);
  78. /// Begin adding quads.
  79. void Begin(PODVector<UIQuad>* quads);
  80. /// Add a quad.
  81. void AddQuad(const UIElement& element, int x, int y, int width, int height, int texOffsetX, int texOffsetY);
  82. /// Add a quad with scaled texture.
  83. void AddQuad(const UIElement& element, int x, int y, int width, int height, int texOffsetX, int texOffsetY, int texWidth, int texHeight);
  84. /// Add a quad with tiled texture.
  85. void AddQuad(const UIElement& element, int x, int y, int width, int height, int texOffsetX, int texOffsetY, int texWidth, int texHeight, bool tiled);
  86. /// Add a quad with custom color.
  87. void AddQuad(const UIElement& element, int x, int y, int width, int height, int texOffsetX, int texOffsetY, int texWidth, int texHeight, const Color& color);
  88. /// Merge with another batch.
  89. bool Merge(const UIBatch& batch);
  90. /// Update the vertex data.
  91. void UpdateGeometry(Graphics* graphics, void* lockedData);
  92. /// Add or merge a batch.
  93. static void AddOrMerge(const UIBatch& batch, PODVector<UIBatch>& batches);
  94. /// Blending mode.
  95. BlendMode blendMode_;
  96. /// Scissor rectangle.
  97. IntRect scissor_;
  98. /// Texture.
  99. Texture* texture_;
  100. /// Quads.
  101. PODVector<UIQuad>* quads_;
  102. /// Quad start index.
  103. unsigned quadStart_;
  104. /// Number of quads.
  105. unsigned quadCount_;
  106. };
  107. }