136 : attributes_(attributes) {
137 calculateOffsetsAndStride();
141 : attributes_(
std::move(attributes)) {
142 calculateOffsetsAndStride();
149 const std::vector<VertexAttribute>&
getAttributes()
const {
return attributes_; }
158 std::vector<VertexAttribute>::iterator
begin() {
return attributes_.begin(); }
159 std::vector<VertexAttribute>::iterator
end() {
return attributes_.end(); }
160 std::vector<VertexAttribute>::const_iterator
begin()
const {
return attributes_.begin(); }
161 std::vector<VertexAttribute>::const_iterator
end()
const {
return attributes_.end(); }
167 void calculateOffsetsAndStride() {
170 for (
auto& attr : attributes_) {
171 attr.offset = offset;
173 stride_ += attr.size;
177 std::vector<VertexAttribute> attributes_;
212 return createRaw(device, content, data.data(),
static_cast<u32>(data.size_bytes()));
220 return create(device, content, std::span<const T>(data));
226 template<
typename T, usize N>
228 return create(device, content, std::span<const T>(data, N));
250 setDataRaw(data.data(),
static_cast<u32>(data.size_bytes()));
258 setData(std::span<const T>(data));
264 template<
typename T, usize N>
266 setData(std::span<const T>(data, N));
354 return create(device, content, indices.data(),
static_cast<u32>(indices.size()));
359 return create(device, content, indices.data(),
static_cast<u32>(indices.size()));
364 return create(device, content, std::span<const u32>(indices));
369 return create(device, content, std::span<const u16>(indices));
399 bool is16Bit_ =
false;
Who restores a GPU object's contents after the device is lost.
Backend-agnostic graphics enumerations.
Core type definitions and utilities for ESEngine.
A content policy. provider names who refills a Sourced object and key what it refills; both are the p...
Abstract graphics device interface.
BufferHandle handle() const
Gets the device buffer handle.
IndexBuffer & operator=(const IndexBuffer &)=delete
static Unique< IndexBuffer > create(GfxDevice &device, GfxContent content, const std::vector< u16 > &indices)
Creates an index buffer from a vector of 16-bit indices.
static Unique< IndexBuffer > create(GfxDevice &device, GfxContent content, const std::vector< u32 > &indices)
Creates an index buffer from a vector of 32-bit indices.
static Unique< IndexBuffer > create(GfxDevice &device, GfxContent content, std::span< const u32 > indices)
Creates an index buffer from a span of 32-bit indices.
static Unique< IndexBuffer > create(GfxDevice &device, GfxContent content, std::span< const u16 > indices)
Creates an index buffer from a span of 16-bit indices.
u32 getCount() const
Gets the number of indices.
IndexBuffer(const IndexBuffer &)=delete
bool is16Bit() const
Returns true if using 16-bit indices.
void setSubDataRaw(const void *data, u32 sizeBytes, u32 offsetBytes)
Updates a portion of buffer data with offset (internal use).
static Unique< VertexBuffer > createRaw(GfxDevice &device, GfxContent content, const void *data, u32 sizeBytes)
Creates a buffer from raw data pointer for internal use.
VertexBuffer(const VertexBuffer &)=delete
void setDataRaw(const void *data, u32 sizeBytes)
Updates buffer data from raw pointer (internal use).
BufferHandle handle() const
Gets the device buffer handle.
VertexBuffer & operator=(const VertexBuffer &)=delete
void setData(const T(&data)[N])
Updates buffer data from a C array.
static Unique< VertexBuffer > create(GfxDevice &device, GfxContent content, const T(&data)[N])
Creates a static buffer from a C array.
const VertexLayout & getLayout() const
Gets the vertex layout.
static Unique< VertexBuffer > create(GfxDevice &device, GfxContent content, std::span< const T > data)
Creates a static buffer from a span.
void setData(std::span< const T > data)
Updates buffer data from a span.
void setLayout(const VertexLayout &layout)
Sets the vertex layout.
void setData(const std::vector< T > &data)
Updates buffer data from a vector.
static Unique< VertexBuffer > create(GfxDevice &device, GfxContent content, const std::vector< T > &data)
Creates a static buffer from a vector.
Describes the layout of vertex data in a buffer.
std::vector< VertexAttribute >::iterator end()
VertexLayout(std::vector< VertexAttribute > attributes)
std::vector< VertexAttribute >::const_iterator begin() const
u32 getStride() const
Gets the stride (total size) of one vertex.
const std::vector< VertexAttribute > & getAttributes() const
Gets all vertex attributes.
std::vector< VertexAttribute >::const_iterator end() const
VertexLayout(std::initializer_list< VertexAttribute > attributes)
Constructs layout from initializer list.
VertexLayout()=default
Default constructor (empty layout).
std::vector< VertexAttribute >::iterator begin()
ShaderDataType
Vertex attribute data types.
@ UByte4N
4 unsigned bytes, normalized to [0,1] vec4
u32 shaderDataTypeSize(ShaderDataType type)
Gets the size in bytes of a shader data type.
std::unique_ptr< T > Unique
Unique ownership smart pointer.
std::uint32_t u32
Unsigned 32-bit integer.
u32 shaderDataTypeComponentCount(ShaderDataType type)
Gets the component count of a shader data type.
std::uint16_t u16
Unsigned 16-bit integer.
VertexAttribute()=default
Default constructor.
VertexAttribute(ShaderDataType type, const std::string &name, bool normalized=false)
Constructs a vertex attribute.
u32 offset
Byte offset within the vertex.
bool normalized
Whether to normalize integer data to [0,1] or [-1,1].
std::string name
Attribute name (for debugging).
ShaderDataType type
Data type of the attribute.