mirror of
https://github.com/love2d/love.git
synced 2026-08-16 16:20:42 +02:00
Restructure some internal vertex buffer binding code to be closer to how graphics APIs actually behave.
This commit is contained in:
@@ -36,7 +36,7 @@ namespace graphics
|
||||
|
||||
class Resource;
|
||||
|
||||
// Vertex attribute indices used in shaders by LOVE. The values map to OpenGL
|
||||
// Vertex attribute indices used in shaders by LOVE. The values map to GPU
|
||||
// generic vertex attribute indices.
|
||||
enum VertexAttribID
|
||||
{
|
||||
@@ -189,11 +189,11 @@ struct XYf_STPf_RGBAub
|
||||
Color color;
|
||||
};
|
||||
|
||||
struct Buffers
|
||||
struct BufferBindings
|
||||
{
|
||||
static const unsigned int MAX = 32;
|
||||
static const uint32 MAX = 32;
|
||||
|
||||
uint32 usebits = 0;
|
||||
uint32 useBits = 0;
|
||||
|
||||
struct
|
||||
{
|
||||
@@ -201,33 +201,40 @@ struct Buffers
|
||||
size_t offset;
|
||||
} info[MAX];
|
||||
|
||||
void set(unsigned int index, Resource *r, size_t offset)
|
||||
void set(uint32 index, Resource *r, size_t offset)
|
||||
{
|
||||
usebits |= (1u << index);
|
||||
useBits |= (1u << index);
|
||||
info[index] = {r, offset};
|
||||
}
|
||||
|
||||
void disable(unsigned int index) { usebits &= (1u << index); }
|
||||
void clear() { usebits = 0; }
|
||||
void disable(uint32 index) { useBits &= (1u << index); }
|
||||
void clear() { useBits = 0; }
|
||||
};
|
||||
|
||||
struct AttributeInfo
|
||||
{
|
||||
uint8 bufferindex;
|
||||
DataType type : 8;
|
||||
uint16 components;
|
||||
uint16 offsetfromvertex;
|
||||
uint8 bufferIndex;
|
||||
DataType type : 4;
|
||||
uint8 components : 4;
|
||||
uint16 offsetFromVertex;
|
||||
};
|
||||
|
||||
static_assert(sizeof(AttributeInfo) == 4, "AttributeInfo struct size should be 4 bytes");
|
||||
|
||||
struct BufferLayout
|
||||
{
|
||||
uint16 stride;
|
||||
};
|
||||
|
||||
struct Attributes
|
||||
{
|
||||
static const unsigned int MAX = 32;
|
||||
static const uint32 MAX = 32;
|
||||
|
||||
uint32 enablebits = 0;
|
||||
uint32 instancebits = 0;
|
||||
uint32 enableBits = 0; // indexed by attribute
|
||||
uint32 instanceBits = 0; // indexed by buffer
|
||||
|
||||
AttributeInfo attribs[MAX];
|
||||
BufferLayout bufferLayouts[BufferBindings::MAX];
|
||||
|
||||
Attributes() {}
|
||||
Attributes(CommonFormat format, uint8 bufferindex)
|
||||
@@ -235,42 +242,46 @@ struct Attributes
|
||||
setCommonFormat(format, bufferindex);
|
||||
}
|
||||
|
||||
void set(unsigned int index, DataType type, uint16 components, uint16 offsetfromvertex, uint16 stride, uint8 bufferindex, AttributeStep step = STEP_PER_VERTEX)
|
||||
void set(uint32 index, DataType type, uint8 components, uint16 offsetfromvertex, uint8 bufferindex)
|
||||
{
|
||||
uint32 bit = (1u << index);
|
||||
enableBits |= (1u << index);
|
||||
|
||||
enablebits |= bit;
|
||||
|
||||
if (step == STEP_PER_INSTANCE)
|
||||
instancebits |= bit;
|
||||
else
|
||||
instancebits &= ~bit;
|
||||
|
||||
attribs[index].bufferindex = bufferindex;
|
||||
attribs[index].bufferIndex = bufferindex;
|
||||
attribs[index].type = type;
|
||||
attribs[index].components = components;
|
||||
attribs[index].offsetfromvertex = offsetfromvertex;
|
||||
attribs[index].stride = stride;
|
||||
attribs[index].offsetFromVertex = offsetfromvertex;
|
||||
}
|
||||
|
||||
void disable(unsigned int index)
|
||||
void setBufferLayout(uint32 bufferindex, uint16 stride, AttributeStep step = STEP_PER_VERTEX)
|
||||
{
|
||||
enablebits &= ~(1u << index);
|
||||
uint32 bufferbit = (1u << bufferindex);
|
||||
|
||||
if (step == STEP_PER_INSTANCE)
|
||||
instanceBits |= bufferbit;
|
||||
else
|
||||
instanceBits &= ~bufferbit;
|
||||
|
||||
bufferLayouts[bufferindex].stride = stride;
|
||||
}
|
||||
|
||||
void disable(uint32 index)
|
||||
{
|
||||
enableBits &= ~(1u << index);
|
||||
}
|
||||
|
||||
void clear()
|
||||
{
|
||||
enablebits = 0;
|
||||
enableBits = 0;
|
||||
}
|
||||
|
||||
bool isEnabled(unsigned int index) const
|
||||
bool isEnabled(uint32 index) const
|
||||
{
|
||||
return (enablebits & (1u << index)) != 0;
|
||||
return (enableBits & (1u << index)) != 0;
|
||||
}
|
||||
|
||||
AttributeStep getStep(unsigned int index) const
|
||||
AttributeStep getBufferStep(uint32 index) const
|
||||
{
|
||||
return (instancebits & (1u << index)) != 0 ? STEP_PER_INSTANCE : STEP_PER_VERTEX;
|
||||
return (instanceBits & (1u << index)) != 0 ? STEP_PER_INSTANCE : STEP_PER_VERTEX;
|
||||
}
|
||||
|
||||
void setCommonFormat(CommonFormat format, uint8 bufferindex);
|
||||
|
||||
Reference in New Issue
Block a user