Ion
 All Classes Namespaces Files Functions Variables Typedefs Enumerations Enumerator Friends Macros Pages
shape.h
Go to the documentation of this file.
1 
18 #ifndef ION_GFX_SHAPE_H_
19 #define ION_GFX_SHAPE_H_
20 
21 #include <string>
22 
23 #include "ion/base/referent.h"
24 #include "ion/gfx/attributearray.h"
25 #include "ion/gfx/indexbuffer.h"
26 #include "ion/math/range.h"
27 
28 namespace ion {
29 namespace gfx {
30 
32 class ION_API Shape : public base::Referent {
33  public:
40  kTriangles, // Default.
43  };
44 
45  Shape();
46 
48  const std::string& GetLabel() const { return label_; }
49  void SetLabel(const std::string& label) { label_ = label; }
50 
52  void SetPrimitiveType(PrimitiveType type) { primitive_type_ = type; }
53  PrimitiveType GetPrimitiveType() const { return primitive_type_; }
54 
56  void SetAttributeArray(const AttributeArrayPtr& attribute_array) {
57  attribute_array_ = attribute_array;
58  }
60  return attribute_array_;
61  }
62 
65  void SetIndexBuffer(const IndexBufferPtr& index_buffer) {
66  index_buffer_ = index_buffer;
67  }
68  const IndexBufferPtr& GetIndexBuffer() const {
69  return index_buffer_;
70  }
71 
80  size_t AddVertexRange(const math::Range1i& range);
84  void SetVertexRange(size_t i, const math::Range1i& range);
86  void ClearVertexRanges() { vertex_ranges_.clear(); }
89  const math::Range1i GetVertexRange(size_t i) const;
91  size_t GetVertexRangeCount() const { return vertex_ranges_.size(); }
94  void EnableVertexRange(size_t i, bool enable);
97  bool IsVertexRangeEnabled(size_t i) const;
98 
104  void SetInstanceCount(int count) { instance_count_ = count; }
106  int GetInstanceCount() const { return instance_count_; }
107 
113  void SetVertexRangeInstanceCount(size_t i, int instance_count);
115  int GetVertexRangeInstanceCount(size_t i) const;
116 
117  protected:
120  ~Shape() override;
121 
122  private:
126  struct VertexRange {
127  VertexRange() : is_enabled(false), instance_count(0) {} // For STL only.
128  VertexRange(const math::Range1i& range_in, bool is_enabled_in,
129  int instance_count_in)
130  : range(range_in),
131  is_enabled(is_enabled_in),
132  instance_count(instance_count_in) {}
133  math::Range1i range;
134  bool is_enabled;
139  int instance_count;
140  };
141 
144  bool CheckRangeIndex(size_t i, const char* name) const;
145 
147  PrimitiveType primitive_type_;
149  AttributeArrayPtr attribute_array_;
152  IndexBufferPtr index_buffer_;
154  base::AllocVector<VertexRange> vertex_ranges_;
160  int instance_count_;
163  std::string label_;
164 };
165 
168 
169 } // namespace gfx
170 } // namespace ion
171 
172 #endif // ION_GFX_SHAPE_H_
void SetPrimitiveType(PrimitiveType type)
Sets/returns the type of primitive to draw.
Definition: shape.h:52
PrimitiveType GetPrimitiveType() const
Definition: shape.h:53
std::string type
Definition: printer.cc:353
base::ReferentPtr< Shape >::Type ShapePtr
Convenience typedef for shared pointer to a Shape.
Definition: shape.h:167
Range< 1, int32 > Range1i
Definition: range.h:363
void SetInstanceCount(int count)
Sets the instance count of the shape.
Definition: shape.h:104
size_t GetVertexRangeCount() const
Returns the number of vertex ranges in the Shape.
Definition: shape.h:91
std::string label
Definition: printer.cc:354
Thread-safe abstract base class.
Definition: referent.h:49
base::ReferentPtr< IndexBuffer >::Type IndexBufferPtr
Definition: indexbuffer.h:38
void SetAttributeArray(const AttributeArrayPtr &attribute_array)
Sets/returns the vertices used to create the primitives.
Definition: shape.h:56
A Shape object represents a shape (vertices + indices) to draw.
Definition: shape.h:32
void SetIndexBuffer(const IndexBufferPtr &index_buffer)
Sets/returns the index buffer.
Definition: shape.h:65
std::string name
Definition: printer.cc:324
PrimitiveType
Supported primitive types.
Definition: shape.h:35
void ClearVertexRanges()
Removes all ranges from the Shape.
Definition: shape.h:86
int GetInstanceCount() const
Returns the instance count that the shape is set to.
Definition: shape.h:106
base::ReferentPtr< AttributeArray >::Type AttributeArrayPtr
Convenience typedef for shared pointer to a AttributeArray.
const AttributeArrayPtr & GetAttributeArray() const
Definition: shape.h:59
const IndexBufferPtr & GetIndexBuffer() const
Definition: shape.h:68
void SetLabel(const std::string &label)
Definition: shape.h:49
const std::string & GetLabel() const
Returns/sets the label of this.
Definition: shape.h:48
A SharedPtr is a smart shared pointer to an instance of some class that implements reference counting...
Definition: sharedptr.h:60