opengl_stream_buffer.h (1345B)
1 // SPDX-FileCopyrightText: 2019-2024 Connor McLaughlin <stenzek@gmail.com> 2 // SPDX-License-Identifier: (GPL-3.0 OR PolyForm-Strict-1.0.0) 3 4 #pragma once 5 6 #include "opengl_loader.h" 7 8 #include "common/types.h" 9 10 #include <memory> 11 #include <string_view> 12 #include <tuple> 13 #include <vector> 14 15 class OpenGLStreamBuffer 16 { 17 public: 18 virtual ~OpenGLStreamBuffer(); 19 20 ALWAYS_INLINE GLuint GetGLBufferId() const { return m_buffer_id; } 21 ALWAYS_INLINE GLenum GetGLTarget() const { return m_target; } 22 ALWAYS_INLINE u32 GetSize() const { return m_size; } 23 24 void Bind(); 25 void Unbind(); 26 27 void SetDebugName(std::string_view name); 28 29 struct MappingResult 30 { 31 void* pointer; 32 u32 buffer_offset; 33 u32 index_aligned; // offset / alignment, suitable for base vertex 34 u32 space_aligned; // remaining space / alignment 35 }; 36 37 virtual MappingResult Map(u32 alignment, u32 min_size) = 0; 38 39 /// Returns the position in the buffer *before* the start of used_size. 40 virtual u32 Unmap(u32 used_size) = 0; 41 42 /// Returns the minimum granularity of blocks which sync objects will be created around. 43 virtual u32 GetChunkSize() const = 0; 44 45 static std::unique_ptr<OpenGLStreamBuffer> Create(GLenum target, u32 size); 46 47 protected: 48 OpenGLStreamBuffer(GLenum target, GLuint buffer_id, u32 size); 49 50 GLenum m_target; 51 GLuint m_buffer_id; 52 u32 m_size; 53 };