mirror of
https://github.com/love2d/love.git
synced 2026-08-16 00:02:12 +02:00
Meshes expose GraphicsBuffers, part 2
This commit is contained in:
@@ -28,56 +28,62 @@ namespace graphics
|
||||
|
||||
love::Type Buffer::type("GraphicsBuffer", &Object::type);
|
||||
|
||||
Buffer::Buffer(size_t size, BufferTypeFlags typeflags, BufferUsage usage, uint32 mapflags)
|
||||
Buffer::Buffer(const Settings &settings, const void */*data*/, size_t size)
|
||||
: arrayLength(0)
|
||||
, arrayStride(0)
|
||||
, size(size)
|
||||
, typeFlags(typeflags)
|
||||
, usage(usage)
|
||||
, mapFlags(mapflags)
|
||||
, typeFlags(settings.typeFlags)
|
||||
, usage(settings.usage)
|
||||
, mapFlags(settings.mapFlags)
|
||||
, mapped(false)
|
||||
{
|
||||
}
|
||||
|
||||
Buffer::Buffer(Graphics *gfx, const Settings &settings, const std::vector<DataMember> &dataMembers, size_t arraylength)
|
||||
: Buffer(0, settings.typeFlags, settings.usage, settings.mapFlags)
|
||||
Buffer::Buffer(Graphics *gfx, const Settings &settings, const std::vector<DataDeclaration> &bufferformat, const void *data, size_t size, size_t arraylength)
|
||||
: Buffer(settings, data, size)
|
||||
{
|
||||
if (dataMembers.size() == 0)
|
||||
throw love::Exception("Data format must contain values.");
|
||||
if (size == 0 && arraylength == 0)
|
||||
throw love::Exception("Size or array length must be specified.");
|
||||
|
||||
this->dataMembers = dataMembers;
|
||||
if (bufferformat.size() == 0)
|
||||
throw love::Exception("Data format must contain values.");
|
||||
|
||||
bool supportsGLSL3 = gfx->getCapabilities().features[Graphics::FEATURE_GLSL3];
|
||||
|
||||
bool uniformbuffer = settings.typeFlags & BUFFERFLAG_UNIFORM;
|
||||
bool indexbuffer = settings.typeFlags & BUFFERFLAG_INDEX;
|
||||
bool vertexbuffer = settings.typeFlags & BUFFERFLAG_VERTEX;
|
||||
bool ssbuffer = settings.typeFlags & BUFFERFLAG_SHADER_STORAGE;
|
||||
|
||||
if (indexbuffer && dataMembers.size() > 1)
|
||||
throw love::Exception("test");
|
||||
bool uniformbuffer = settings.typeFlags & TYPEFLAG_UNIFORM;
|
||||
bool indexbuffer = settings.typeFlags & TYPEFLAG_INDEX;
|
||||
bool vertexbuffer = settings.typeFlags & TYPEFLAG_VERTEX;
|
||||
bool ssbuffer = settings.typeFlags & TYPEFLAG_SHADER_STORAGE;
|
||||
|
||||
size_t offset = 0;
|
||||
size_t stride = 0;
|
||||
|
||||
for (const auto &member : dataMembers)
|
||||
for (const auto &decl : bufferformat)
|
||||
{
|
||||
DataFormat format = member.format;
|
||||
const DataFormatInfo &info = getDataFormatInfo(format);
|
||||
DataMember member(decl);
|
||||
|
||||
DataFormat format = member.decl.format;
|
||||
const DataFormatInfo &info = member.info;
|
||||
|
||||
if (indexbuffer)
|
||||
{
|
||||
if (format != DATAFORMAT_UINT16 && format != DATAFORMAT_UINT32)
|
||||
throw love::Exception("Index buffers only support uint16 and uint32 data types.");
|
||||
|
||||
if (bufferformat.size() > 1)
|
||||
throw love::Exception("Index buffers only support a single value per element.");
|
||||
}
|
||||
|
||||
if (vertexbuffer)
|
||||
{
|
||||
if (decl.arraySize > 0)
|
||||
throw love::Exception("Arrays are not supported in vertex buffers.");
|
||||
|
||||
if (info.isMatrix)
|
||||
throw love::Exception("matrix types are not supported in vertex buffers.");
|
||||
throw love::Exception("Matrix types are not supported in vertex buffers.");
|
||||
|
||||
if (info.baseType == DATA_BASETYPE_BOOL)
|
||||
throw love::Exception("bool types are not supported in vertex buffers.");
|
||||
throw love::Exception("Bool types are not supported in vertex buffers.");
|
||||
|
||||
if ((info.baseType == DATA_BASETYPE_INT || info.baseType == DATA_BASETYPE_UINT) && !supportsGLSL3)
|
||||
throw love::Exception("Integer vertex attribute data types require GLSL 3 support.");
|
||||
@@ -88,11 +94,30 @@ Buffer::Buffer(Graphics *gfx, const Settings &settings, const std::vector<DataMe
|
||||
if (info.componentSize != 4)
|
||||
throw love::Exception("");
|
||||
}
|
||||
|
||||
|
||||
// TODO: alignment
|
||||
member.offset = offset;
|
||||
offset += member.info.size;
|
||||
|
||||
dataMembers.push_back(member);
|
||||
}
|
||||
|
||||
if (size != 0)
|
||||
{
|
||||
size_t remainder = size % stride;
|
||||
if (remainder > 0)
|
||||
size += stride - remainder;
|
||||
arraylength = size / stride;
|
||||
}
|
||||
else
|
||||
{
|
||||
size = arraylength * stride;
|
||||
}
|
||||
|
||||
this->arrayLength = arraylength;
|
||||
this->arrayStride = stride;
|
||||
this->size = stride * arraylength;
|
||||
this->arrayLength = arraylength;
|
||||
this->size = size;
|
||||
}
|
||||
|
||||
Buffer::~Buffer()
|
||||
@@ -103,7 +128,7 @@ int Buffer::getDataMemberIndex(const std::string &name) const
|
||||
{
|
||||
for (size_t i = 0; i < dataMembers.size(); i++)
|
||||
{
|
||||
if (dataMembers[i].name == name)
|
||||
if (dataMembers[i].decl.name == name)
|
||||
return (int) i;
|
||||
}
|
||||
|
||||
|
||||
Reference in New Issue
Block a user