mirror of
https://github.com/love2d/love.git
synced 2026-08-12 08:30:56 +02:00
Remove the need for copysource and copydest buffer usage flags.
This commit is contained in:
@@ -46,14 +46,10 @@ Buffer::Buffer(Graphics *gfx, const Settings &settings, const std::vector<DataDe
|
||||
const auto &caps = gfx->getCapabilities();
|
||||
bool supportsGLSL3 = caps.features[Graphics::FEATURE_GLSL3];
|
||||
|
||||
bool indexbuffer = settings.usageFlags & BUFFERUSAGEFLAG_INDEX;
|
||||
bool vertexbuffer = settings.usageFlags & BUFFERUSAGEFLAG_VERTEX;
|
||||
bool texelbuffer = settings.usageFlags & BUFFERUSAGEFLAG_TEXEL;
|
||||
bool storagebuffer = settings.usageFlags & BUFFERUSAGEFLAG_SHADER_STORAGE;
|
||||
bool copydest = settings.usageFlags & BUFFERUSAGEFLAG_COPY_DEST;
|
||||
|
||||
if (!indexbuffer && !vertexbuffer && !texelbuffer && !storagebuffer)
|
||||
throw love::Exception("Buffer must be created with at least one buffer type (index, vertex, texel, or shaderstorage).");
|
||||
bool indexbuffer = usageFlags & BUFFERUSAGEFLAG_INDEX;
|
||||
bool vertexbuffer = usageFlags & BUFFERUSAGEFLAG_VERTEX;
|
||||
bool texelbuffer = usageFlags & BUFFERUSAGEFLAG_TEXEL;
|
||||
bool storagebuffer = usageFlags & BUFFERUSAGEFLAG_SHADER_STORAGE;
|
||||
|
||||
if (texelbuffer && !caps.features[Graphics::FEATURE_TEXEL_BUFFER])
|
||||
throw love::Exception("Texel buffers are not supported on this system.");
|
||||
@@ -61,8 +57,8 @@ Buffer::Buffer(Graphics *gfx, const Settings &settings, const std::vector<DataDe
|
||||
if (storagebuffer && !caps.features[Graphics::FEATURE_GLSL4])
|
||||
throw love::Exception("Shader Storage buffers are not supported on this system (GLSL 4 support is necessary.)");
|
||||
|
||||
if (copydest && dataUsage == BUFFERDATAUSAGE_STREAM)
|
||||
throw love::Exception("Buffers created with 'stream' data usage cannot be used as a copy destination.");
|
||||
if (storagebuffer && dataUsage == BUFFERDATAUSAGE_STREAM)
|
||||
throw love::Exception("Buffers created with 'stream' data usage cannot be used as a shader storage buffer.");
|
||||
|
||||
size_t offset = 0;
|
||||
size_t stride = 0;
|
||||
|
||||
@@ -1058,15 +1058,12 @@ void Graphics::copyBuffer(Buffer *source, Buffer *dest, size_t sourceoffset, siz
|
||||
if (!capabilities.features[FEATURE_COPY_BUFFER])
|
||||
throw love::Exception("Buffer copying is not supported on this system.");
|
||||
|
||||
if (!(source->getUsageFlags() & BUFFERUSAGEFLAG_COPY_SOURCE))
|
||||
throw love::Exception("Copy source buffer must be created with the copysource flag.");
|
||||
|
||||
if (!(dest->getUsageFlags() & BUFFERUSAGEFLAG_COPY_DEST))
|
||||
throw love::Exception("Copy destination buffer must be created with the copydest flag.");
|
||||
|
||||
Range sourcerange(sourceoffset, size);
|
||||
Range destrange(destoffset, size);
|
||||
|
||||
if (dest->getDataUsage() == BUFFERDATAUSAGE_STREAM)
|
||||
throw love::Exception("Buffers created with 'stream' data usage cannot be used as a copy destination.");
|
||||
|
||||
if (sourcerange.getMax() >= source->getSize())
|
||||
throw love::Exception("Buffer copy source offset and size doesn't fit within the source Buffer's size.");
|
||||
|
||||
|
||||
@@ -80,10 +80,6 @@ Buffer::Buffer(love::graphics::Graphics *gfx, const Settings &settings, const st
|
||||
mapUsage = BUFFERUSAGE_INDEX;
|
||||
else if (usageFlags & BUFFERUSAGEFLAG_SHADER_STORAGE)
|
||||
mapUsage = BUFFERUSAGE_SHADER_STORAGE;
|
||||
else if (usageFlags & BUFFERUSAGEFLAG_COPY_SOURCE)
|
||||
mapUsage = BUFFERUSAGE_COPY_SOURCE;
|
||||
else if (usageFlags & BUFFERUSAGEFLAG_COPY_DEST)
|
||||
mapUsage = BUFFERUSAGE_COPY_DEST;
|
||||
|
||||
target = OpenGL::getGLBufferType(mapUsage);
|
||||
|
||||
@@ -261,8 +257,9 @@ void Buffer::fill(size_t offset, size_t size, const void *data)
|
||||
|
||||
void Buffer::copyTo(love::graphics::Buffer *dest, size_t sourceoffset, size_t destoffset, size_t size)
|
||||
{
|
||||
gl.bindBuffer(BUFFERUSAGE_COPY_SOURCE, buffer);
|
||||
gl.bindBuffer(BUFFERUSAGE_COPY_DEST, ((Buffer *) dest)->buffer);
|
||||
// TODO: tracked state for these bind types?
|
||||
glBindBuffer(GL_COPY_READ_BUFFER, buffer);
|
||||
glBindBuffer(GL_COPY_WRITE_BUFFER, ((Buffer *) dest)->buffer);
|
||||
|
||||
glCopyBufferSubData(GL_COPY_READ_BUFFER, GL_COPY_WRITE_BUFFER, sourceoffset, destoffset, size);
|
||||
}
|
||||
|
||||
@@ -497,8 +497,7 @@ static bool computeDispatchBarriers(Shader *shader, GLbitfield &preDispatchBarri
|
||||
if (usage & BUFFERUSAGEFLAG_VERTEX)
|
||||
postDispatchBarriers |= GL_VERTEX_ATTRIB_ARRAY_BARRIER_BIT;
|
||||
|
||||
if (usage & (BUFFERUSAGEFLAG_COPY_SOURCE | BUFFERUSAGEFLAG_COPY_DEST))
|
||||
postDispatchBarriers |= GL_PIXEL_BUFFER_BARRIER_BIT;
|
||||
postDispatchBarriers |= GL_PIXEL_BUFFER_BARRIER_BIT;
|
||||
}
|
||||
|
||||
for (const auto &binding : shader->getStorageTextureBindings())
|
||||
|
||||
@@ -666,8 +666,6 @@ GLenum OpenGL::getGLBufferType(BufferUsage usage)
|
||||
case BUFFERUSAGE_INDEX: return GL_ELEMENT_ARRAY_BUFFER;
|
||||
case BUFFERUSAGE_TEXEL: return GL_TEXTURE_BUFFER;
|
||||
case BUFFERUSAGE_SHADER_STORAGE: return GL_SHADER_STORAGE_BUFFER;
|
||||
case BUFFERUSAGE_COPY_SOURCE: return GL_COPY_READ_BUFFER;
|
||||
case BUFFERUSAGE_COPY_DEST: return GL_COPY_WRITE_BUFFER;
|
||||
case BUFFERUSAGE_MAX_ENUM: return GL_ZERO;
|
||||
}
|
||||
|
||||
@@ -1483,9 +1481,6 @@ bool OpenGL::isBufferUsageSupported(BufferUsage usage) const
|
||||
return GLAD_VERSION_3_1;
|
||||
case BUFFERUSAGE_SHADER_STORAGE:
|
||||
return (GLAD_VERSION_4_3 && isCoreProfile()) || GLAD_ES_VERSION_3_1;
|
||||
case BUFFERUSAGE_COPY_SOURCE:
|
||||
case BUFFERUSAGE_COPY_DEST:
|
||||
return GLAD_VERSION_3_1 || GLAD_ES_VERSION_3_0;
|
||||
case BUFFERUSAGE_MAX_ENUM:
|
||||
return false;
|
||||
}
|
||||
@@ -1530,6 +1525,11 @@ bool OpenGL::isMultiFormatMRTSupported() const
|
||||
return getMaxRenderTargets() > 1 && (GLAD_ES_VERSION_3_0 || GLAD_VERSION_3_0 || GLAD_ARB_framebuffer_object);
|
||||
}
|
||||
|
||||
bool OpenGL::isCopyBufferSupported() const
|
||||
{
|
||||
return GLAD_VERSION_3_1 || GLAD_ES_VERSION_3_0;
|
||||
}
|
||||
|
||||
int OpenGL::getMax2DTextureSize() const
|
||||
{
|
||||
return std::max(max2DTextureSize, 1);
|
||||
|
||||
@@ -371,6 +371,7 @@ public:
|
||||
bool isSamplerLODBiasSupported() const;
|
||||
bool isBaseVertexSupported() const;
|
||||
bool isMultiFormatMRTSupported() const;
|
||||
bool isCopyBufferSupported() const;
|
||||
|
||||
/**
|
||||
* Returns the maximum supported width or height of a texture.
|
||||
|
||||
@@ -343,8 +343,6 @@ STRINGMAP_BEGIN(BufferUsage, BUFFERUSAGE_MAX_ENUM, bufferUsageName)
|
||||
{ "index", BUFFERUSAGE_INDEX },
|
||||
{ "texel", BUFFERUSAGE_TEXEL },
|
||||
{ "shaderstorage", BUFFERUSAGE_SHADER_STORAGE },
|
||||
{ "copysource", BUFFERUSAGE_COPY_SOURCE },
|
||||
{ "copydest", BUFFERUSAGE_COPY_DEST },
|
||||
}
|
||||
STRINGMAP_END(BufferUsage, BUFFERUSAGE_MAX_ENUM, bufferUsageName)
|
||||
|
||||
|
||||
@@ -60,8 +60,6 @@ enum BufferUsage
|
||||
BUFFERUSAGE_INDEX,
|
||||
BUFFERUSAGE_TEXEL,
|
||||
BUFFERUSAGE_SHADER_STORAGE,
|
||||
BUFFERUSAGE_COPY_SOURCE,
|
||||
BUFFERUSAGE_COPY_DEST,
|
||||
BUFFERUSAGE_MAX_ENUM
|
||||
};
|
||||
|
||||
@@ -72,8 +70,6 @@ enum BufferUsageFlags
|
||||
BUFFERUSAGEFLAG_INDEX = 1 << BUFFERUSAGE_INDEX,
|
||||
BUFFERUSAGEFLAG_TEXEL = 1 << BUFFERUSAGE_TEXEL,
|
||||
BUFFERUSAGEFLAG_SHADER_STORAGE = 1 << BUFFERUSAGE_SHADER_STORAGE,
|
||||
BUFFERUSAGEFLAG_COPY_SOURCE = 1 << BUFFERUSAGE_COPY_SOURCE,
|
||||
BUFFERUSAGEFLAG_COPY_DEST = 1 << BUFFERUSAGE_COPY_DEST,
|
||||
};
|
||||
|
||||
enum IndexDataType
|
||||
|
||||
Reference in New Issue
Block a user