123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102 |
- /**
- * Copyright (c) 2006-2020 LOVE Development Team
- *
- * This software is provided 'as-is', without any express or implied
- * warranty. In no event will the authors be held liable for any damages
- * arising from the use of this software.
- *
- * Permission is granted to anyone to use this software for any purpose,
- * including commercial applications, and to alter it and redistribute it
- * freely, subject to the following restrictions:
- *
- * 1. The origin of this software must not be misrepresented; you must not
- * claim that you wrote the original software. If you use this software
- * in a product, an acknowledgment in the product documentation would be
- * appreciated but is not required.
- * 2. Altered source versions must be plainly marked as such, and must not be
- * misrepresented as being the original software.
- * 3. This notice may not be removed or altered from any source distribution.
- **/
- #include "Buffer.h"
- #include "Graphics.h"
- namespace love
- {
- namespace graphics
- {
- static const Buffer::DataTypeInfo dataTypeInfo[]
- {
- // baseType, isMatrix, components, rows, columns, componentSize, packedAlign, packedSize
- { Buffer::DATA_BASE_FLOAT, false, 1, 0, 0, sizeof(float), 4, 4 }, // DATA_FLOAT
- };
- love::Type Buffer::type("GraphicsBuffer", &Object::type);
- Buffer::Buffer(size_t size, BufferTypeFlags typeflags, BufferUsage usage, uint32 mapflags)
- : size(size)
- , typeFlags(typeflags)
- , usage(usage)
- , mapFlags(mapflags)
- , mapped(false)
- {
- }
- Buffer::Buffer(Graphics *gfx, const Settings &settings, const std::vector<DataMember> &format, size_t arraylength)
- : Buffer(0, settings.typeFlags, settings.usage, settings.mapFlags)
- {
- if (format.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 && format.size() > 1)
- throw love::Exception("test");
- size_t offset = 0;
- size_t stride = 0;
- for (const auto &member : format)
- {
- DataType type = member.type;
- const DataTypeInfo &info = getDataTypeInfo(type);
- if (indexbuffer)
- {
- if (type != DATA_UINT16 && type != DATA_UINT32)
- throw love::Exception("Index buffers only support uint16 and uint32 data types.");
- }
- if (vertexbuffer)
- {
- if (info.isMatrix)
- throw love::Exception("matrix types are not supported in vertex buffers.");
- if (info.baseType == DATA_BASE_BOOL)
- throw love::Exception("bool types are not supported in vertex buffers.");
- if ((info.baseType == DATA_BASE_INT || info.baseType == DATA_BASE_UINT) && !supportsGLSL3)
- throw love::Exception("Integer vertex attribute data types require GLSL 3 support.");
- }
- if (uniformbuffer)
- {
- if (info.componentSize != 4)
- throw love::Exception("");
- }
- }
- }
- Buffer::~Buffer()
- {
- }
- } // graphics
- } // love
|