11#ifndef FOOLSENGINE_INSTANCE
12#define FOOLSENGINE_INSTANCE
111 std::size_t componentSize;
117 case GL_UNSIGNED_INT:
118 componentSize =
sizeof(GLfloat);
122 assert(
false &&
"Unrecognized or unsupported type");
124 return componentSize;
159 std::size_t stride {0};
161 stride += attribute.mSize;
174 std::size_t baseOffset {0};
175 for(std::size_t i{0} ; i < attributeIndex; ++i) {
191 std::size_t myAttributeIndex {0};
324 {
"modelMatrixCol0", FIXED_MATRIXMODEL, 4, GL_FLOAT},
325 {
"modelMatrixCol1", FIXED_MATRIXMODEL+1, 4, GL_FLOAT},
326 {
"modelMatrixCol2", FIXED_MATRIXMODEL+2, 4, GL_FLOAT},
327 {
"modelMatrixCol3", FIXED_MATRIXMODEL+3, 4, GL_FLOAT},
342 BuiltinModelMatrixAllocator(std::vector<glm::mat4> modelMatrices)
345 mModelMatrices{modelMatrices}
349 virtual void upload()
override;
352 std::vector<glm::mat4> mModelMatrices;
Class that is responsible for taking an instance layout and correctly uploading it to the GPU.
Definition instance.hpp:217
BaseInstanceAllocator(const InstanceLayout &instanceLayout)
Construct a new base instance allocator object.
Definition instance.hpp:224
bool isUploaded()
Tests whether the attribute data associated with this allocator has been uploaded to memory.
Definition instance.hpp:266
GLuint mVertexBufferIndex
The OpenGL handle associated with the buffer that this object's instance data has been storerd on.
Definition instance.hpp:279
virtual ~BaseInstanceAllocator()
Destroys the allocator object.
Definition instance.cpp:7
void unload()
Deallocates instance data from GPU, deletes the associated vertex buffer.
Definition instance.cpp:24
void _upload()
Method which calls the override for upload() defined by a subclass.
Definition instance.cpp:16
void bind(const InstanceLayout &shaderInstanceLayout)
Binds a (subset of) this object's instance attributes to the currently active shader.
Definition instance.cpp:101
InstanceLayout mInstanceLayout
The layout associated with this allocator.
Definition instance.hpp:308
virtual void upload()=0
Uploads this object's attribute data to GPU memory.
void setAttributePointers(const InstanceLayout &shaderInstanceLayout, std::size_t startingOffset=0)
Sets attribute pointers per the data contained in the instance layout.
Definition instance.cpp:33
InstanceLayout getInstanceLayout() const
Gets the instance attribute layout for this object.
Definition instance.cpp:12
bool mUploaded
Whether or not the instance data associated with this allocator has been uploaded.
Definition instance.hpp:314
void unbind()
Unbinds this object's instance attributes.
Definition instance.cpp:117
virtual void upload() override
Uploads this object's attribute data to GPU memory.
Definition instance.cpp:121
DefaultInstanceAttributeLocations
Attribute locations, per existing shaders.
Definition instance.hpp:26
static InstanceLayout BuiltinModelMatrixLayout
The layout of the in-built model matrix instance attribute, present on pretty much every engine-defin...
Definition instance.hpp:322
Namespace containing all class definitions and functions related to the ToyMaker engine.
Definition camera_system.hpp:20
const GLenum mType
The underlying OpenGL type of the attribute.
Definition instance.hpp:73
InstanceAttributeDescriptor(const std::string &name, const GLint layoutLocation, GLuint nComponents, GLenum type=GL_FLOAT)
Constructs a new instance attribute descriptor.
Definition instance.hpp:45
const GLuint mNComponents
The number or components or dimensions that represent this attribute.
Definition instance.hpp:67
const GLint mLayoutLocation
The OpenGL shader attribute location of this attribute.
Definition instance.hpp:61
const std::string mName
Name of the attribute.
Definition instance.hpp:55
const std::size_t mSize
The size of the attribute, computed as size of mType * mNComponents.
Definition instance.hpp:79
bool operator==(const InstanceAttributeDescriptor &other) const
Compares two vertex attributes for equality.
Definition instance.hpp:92
static std::size_t GetGLTypeSize(GLenum type)
Returns the size of a few known OpenGL component types, throws an error otherwise.
Definition instance.hpp:110
Object representing the layout of one set of related attributes representing (presumably) one object ...
Definition instance.hpp:135
std::vector< InstanceAttributeDescriptor > mAttributeList
The list of attribute descriptors that make up this InstanceLayout.
Definition instance.hpp:207
bool isSubsetOf(const InstanceLayout &other) const
Tests whether another InstanceLayout has the same attributes in the same order as this one,...
Definition instance.hpp:188
std::vector< InstanceAttributeDescriptor > getAttributeList() const
Returns this layout's attribute list.
Definition instance.hpp:149
std::size_t computeRelativeOffset(std::size_t attributeIndex) const
Computes the offset of a specific attribute from the start of the instance, in bytes.
Definition instance.hpp:172
std::size_t computeStride() const
Computes the stride for this layout, i.e., the number of bytes separating the start of one instance's...
Definition instance.hpp:158
InstanceLayout(const std::vector< InstanceAttributeDescriptor > &attributeList)
Constructs a new instance layout object.
Definition instance.hpp:142