18 #ifndef ION_GFX_BUFFEROBJECT_H_
19 #define ION_GFX_BUFFEROBJECT_H_
25 #include "ion/external/gtest/gunit_prod.h"
71 kDataChanged = kNumBaseChanges,
113 : range(range_in), data(data_in), read_offset(0) {
118 uint32 read_offset_in)
119 : range(range_in), read_offset(read_offset_in), src(src_in) {}
143 : component_count(0U),
148 const size_t offset_in)
149 : component_count(count_in),
150 byte_offset(offset_in),
179 const size_t byte_offset);
183 const Spec& GetSpec(
const size_t spec_index)
const;
198 old_data->RemoveReceiver(
this);
200 new_data->AddReceiver(
this);
201 data_.Set(BufferData(data, struct_size, count, usage));
213 if (!byte_range.IsEmpty() && data.
Get() && data->GetData()) {
216 sub_data_changed_.Set(
true);
217 sub_data_changed_.Set(
false);
228 uint32 read_offset) {
229 if (src.
Get() && !dst_byte_range.IsEmpty()) {
233 dst_byte_range, read_offset));
235 sub_data_changed_.Set(
true);
236 sub_data_changed_.Set(
false);
251 return mapped_data_.pointer;
257 size_t GetCount()
const {
return data_.Get().count; }
278 usage(kStaticDraw) {}
281 const size_t struct_size_in,
282 const size_t count_in,
const UsageMode usage_in)
284 struct_size(struct_size_in),
292 inline bool operator !=(
const BufferData& other)
const {
307 struct MappedBufferData {
317 BufferObject::MappedBufferData::DataSource>()),
324 DataSource data_source;
330 void OnNotify(
const base::Notifier* notifier)
override;
334 MappedBufferData::DataSource data_source,
bool read_only) {
335 mapped_data_.range = range;
336 mapped_data_.pointer =
pointer;
337 mapped_data_.data_source = data_source;
338 mapped_data_.read_only = read_only;
342 const MappedBufferData& GetMappedData()
const {
347 base::AllocVector<Spec> specs_;
350 Field<BufferData> data_;
357 mutable base::AllocVector<BufferSubData> sub_data_;
361 Field<bool> sub_data_changed_;
366 MappedBufferData mapped_data_;
372 FRIEND_TEST(BufferObjectTest, MappedData);
373 FRIEND_TEST(RendererTest, MappedBuffer);
385 const size_t spec_index_in)
401 #endif // ION_GFX_BUFFEROBJECT_H_
bool operator==(const BufferObjectElement &other) const
ComponentType type
The type of each component.
size_t GetSpecCount() const
Gets the number of Specs in the BufferObject.
size_t GetCount() const
Gets the number of structs in the buffer.
BufferObjectPtr src
Source BufferObject for CopySubData, NULL is interpreted as this BufferObject.
Changes
Changes that affect the resource.
size_t byte_offset
The offset of the element defined by this Spec in the data type.
Spec(const ComponentType type_in, const size_t count_in, const size_t offset_in)
BufferSubData(const math::Range1ui &range_in, const base::DataContainerPtr &data_in)
base::DataContainerPtr data
Source data for copy. If NULL source data is taken from src.
Range< 1, uint32 > Range1ui
const BufferObjectPtr buffer_object
Structure for clients to use to encapsulate Elements.
Spec()
Default constructor for STL.
void SetData(const base::DataContainerPtr &data, const size_t struct_size, const size_t count, UsageMode usage)
Sets data container, the size of the structure in bytes, and the number of structures.
The DataContainer class encapsulates arbitrary user data passed to Ion.
T * Get() const
Returns a raw pointer to the instance, which may be NULL.
BufferObjectElement()
Default constructor for templates.
A BufferObject describes a generic array of data used, for example, to describe the vertices in a Sha...
const base::DataContainerPtr & GetData() const
Gets the data container.
uint32 read_offset
Read offset in bytes into data or src.
These are necessary since each column of a matrix must be sent to OpenGL separately and we must know ...
size_t GetStructSize() const
Gets the size of one structure, in bytes.
Specifies a destination byte range, read byte offset, and source BufferObject or DataContainer for Bu...
bool operator==(const Spec &other) const
UsageMode GetUsageMode() const
Gets the usage mode of the data.
ComponentType
The type of the components of a spec.
size_t component_count
The number of components.
void CopySubData(const BufferObjectPtr &src, const math::Range1ui &dst_byte_range, uint32 read_offset)
Adds a byte range of data that should be copied from src to this BufferObject.
EnumType InvalidEnumValue()
InvalidEnumValue() returns an invalid enum value, assuming that -1 is not a valid value...
Target GetTarget() const
Gets the buffer target.
BufferSubData(const BufferObjectPtr &src_in, const math::Range1ui &range_in, uint32 read_offset_in)
const base::AllocVector< BufferSubData > & GetSubData() const
Returns all sub-data ranges; may be an empty vector.
math::Range1ui range
Destination byte range of copy.
bool operator!=(const StlAllocator< T1 > &lhs, const StlAllocator< T2 > &rhs)
base::ReferentPtr< DataContainer >::Type DataContainerPtr
base::ReferentPtr< BufferObject >::Type BufferObjectPtr
Convenience typedef for shared pointer to a BufferObject.
void SetSubData(const math::Range1ui &byte_range, const base::DataContainerPtr &data)
Marks that the specified byte range of the BufferObject's data should be updated with the passed data...
void * GetMappedPointer() const
Returns the mapped data pointer of the buffer, which will be NULL if the buffer has not been mapped w...
A SharedPtr is a smart shared pointer to an instance of some class that implements reference counting...
void ClearSubData() const
Clears the vector of sub-data.
The Renderer class handles rendering ION scene graphs using OpenGL.
BufferObjectElement(const BufferObjectPtr &buffer_in, const size_t spec_index_in)
ResourceHolder is an internal base class for objects that hold resources managed by an outside entity...
This class can be used in place of std::vector to allow an Ion Allocator to be used for memory alloca...