2023-08-13 03:42:02 +00:00
|
|
|
// SPDX-FileCopyrightText: 2019-2023 Connor McLaughlin <stenzek@gmail.com>
|
2022-12-04 11:03:45 +00:00
|
|
|
// SPDX-License-Identifier: (GPL-3.0 OR CC-BY-NC-ND-4.0)
|
|
|
|
|
2019-11-02 12:21:56 +00:00
|
|
|
#pragma once
|
2023-08-13 03:42:02 +00:00
|
|
|
|
|
|
|
#include "opengl_loader.h"
|
|
|
|
|
|
|
|
#include "common/types.h"
|
|
|
|
|
2019-11-02 12:21:56 +00:00
|
|
|
#include <memory>
|
2023-08-13 03:42:02 +00:00
|
|
|
#include <string_view>
|
2019-11-02 12:21:56 +00:00
|
|
|
#include <tuple>
|
|
|
|
#include <vector>
|
|
|
|
|
2023-08-13 03:42:02 +00:00
|
|
|
class OpenGLStreamBuffer
|
2019-11-02 12:21:56 +00:00
|
|
|
{
|
|
|
|
public:
|
2023-08-13 03:42:02 +00:00
|
|
|
virtual ~OpenGLStreamBuffer();
|
2019-11-02 12:21:56 +00:00
|
|
|
|
|
|
|
ALWAYS_INLINE GLuint GetGLBufferId() const { return m_buffer_id; }
|
|
|
|
ALWAYS_INLINE GLenum GetGLTarget() const { return m_target; }
|
|
|
|
ALWAYS_INLINE u32 GetSize() const { return m_size; }
|
|
|
|
|
|
|
|
void Bind();
|
2019-11-02 13:42:44 +00:00
|
|
|
void Unbind();
|
2019-11-02 12:21:56 +00:00
|
|
|
|
2024-05-05 10:21:54 +00:00
|
|
|
void SetDebugName(std::string_view name);
|
2023-08-13 03:42:02 +00:00
|
|
|
|
2019-11-02 12:21:56 +00:00
|
|
|
struct MappingResult
|
|
|
|
{
|
|
|
|
void* pointer;
|
2019-11-03 03:15:17 +00:00
|
|
|
u32 buffer_offset;
|
2019-11-02 12:21:56 +00:00
|
|
|
u32 index_aligned; // offset / alignment, suitable for base vertex
|
|
|
|
u32 space_aligned; // remaining space / alignment
|
|
|
|
};
|
|
|
|
|
2019-11-06 14:08:13 +00:00
|
|
|
virtual MappingResult Map(u32 alignment, u32 min_size) = 0;
|
2019-11-02 12:21:56 +00:00
|
|
|
|
2023-08-13 03:42:02 +00:00
|
|
|
/// Returns the position in the buffer *before* the start of used_size.
|
|
|
|
virtual u32 Unmap(u32 used_size) = 0;
|
|
|
|
|
|
|
|
/// Returns the minimum granularity of blocks which sync objects will be created around.
|
|
|
|
virtual u32 GetChunkSize() const = 0;
|
|
|
|
|
|
|
|
static std::unique_ptr<OpenGLStreamBuffer> Create(GLenum target, u32 size);
|
2019-11-02 12:21:56 +00:00
|
|
|
|
2019-11-06 14:08:13 +00:00
|
|
|
protected:
|
2023-08-13 03:42:02 +00:00
|
|
|
OpenGLStreamBuffer(GLenum target, GLuint buffer_id, u32 size);
|
2019-11-02 12:21:56 +00:00
|
|
|
|
|
|
|
GLenum m_target;
|
|
|
|
GLuint m_buffer_id;
|
|
|
|
u32 m_size;
|
|
|
|
};
|