DrawableProxy2D.h 3.3 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293
  1. //
  2. // Copyright (c) 2008-2014 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 "Drawable.h"
  24. namespace Urho3D
  25. {
  26. class Drawable2D;
  27. class IndexBuffer;
  28. class VertexBuffer;
  29. /// Proxy for 2D visible components.
  30. class URHO3D_API DrawableProxy2D : public Drawable
  31. {
  32. OBJECT(DrawableProxy2D);
  33. public:
  34. /// Construct.
  35. DrawableProxy2D(Context* context);
  36. /// Destruct.
  37. ~DrawableProxy2D();
  38. /// Register object factory.
  39. static void RegisterObject(Context* context);
  40. /// Calculate distance and prepare batches for rendering. May be called from worker thread(s), possibly re-entrantly.
  41. virtual void UpdateBatches(const FrameInfo& frame);
  42. /// Prepare geometry for rendering. Called from a worker thread if possible (no GPU update.)
  43. virtual void UpdateGeometry(const FrameInfo& frame);
  44. /// Return whether a geometry update is necessary, and if it can happen in a worker thread.
  45. virtual UpdateGeometryType GetUpdateGeometryType();
  46. /// Add drawable.
  47. void AddDrawable(Drawable2D* drawable);
  48. /// Remove drawable.
  49. void RemoveDrawable(Drawable2D* drawable);
  50. /// Mark order dirty.
  51. void MarkOrderDirty() { orderDirty_ = true; }
  52. /// Check visibility.
  53. bool CheckVisibility(Drawable2D* drawable) const;
  54. private:
  55. /// Recalculate the world-space bounding box.
  56. virtual void OnWorldBoundingBoxUpdate();
  57. /// Handle view update begin event. Determine Drawable2D's and their batches here.
  58. void HandleBeginViewUpdate(StringHash eventType, VariantMap& eventData);
  59. /// Add batch.
  60. void AddBatch(Material* material, unsigned indexStart, unsigned indexCount, unsigned vertexStart, unsigned vertexCount);
  61. /// Index buffer.
  62. SharedPtr<IndexBuffer> indexBuffer_;
  63. /// Vertex buffer.
  64. SharedPtr<VertexBuffer> vertexBuffer_;
  65. /// Materials.
  66. Vector<SharedPtr<Material> > materials_;
  67. /// Geometries.
  68. Vector<SharedPtr<Geometry> > geometries_;
  69. /// Drawables.
  70. PODVector<Drawable2D*> drawables_;
  71. /// Order dirty.
  72. bool orderDirty_;
  73. /// Frustum for current frame.
  74. const Frustum* frustum_;
  75. /// Frustum bounding box for current frame.
  76. BoundingBox frustumBoundingBox_;
  77. /// Total index count for the current frame.
  78. unsigned indexCount_;
  79. /// Total vertex count for the current frame.
  80. unsigned vertexCount_;
  81. };
  82. }