Enhance OpenGLBuffer with more buffer types and features

- Add OpenGLBufferType enum (Vertex, Index, Uniform, CopyRead, CopyWrite, etc.)
- Add Initialize() method with buffer type parameter
- Add Map/Unmap for direct buffer access
- Add SetData for dynamic updates
- Add BindBase for buffer binding to indexed targets
- Add GetType and IsDynamic getters
This commit is contained in:
2026-03-17 02:08:49 +08:00
parent 4c9c03e1a7
commit 56c32bfbde
2 changed files with 90 additions and 20 deletions

View File

@@ -6,25 +6,47 @@
namespace XCEngine {
namespace RHI {
enum class OpenGLBufferType {
Vertex,
Index,
Uniform,
CopyRead,
CopyWrite,
AtomicCounter,
DispatchIndirect,
DrawIndirect,
ShaderBindingTable
};
class OpenGLBuffer {
public:
OpenGLBuffer();
~OpenGLBuffer();
bool Initialize(OpenGLBufferType type, size_t size, const void* data = nullptr, bool dynamic = false);
bool InitializeVertexBuffer(const void* data, size_t size);
bool InitializeIndexBuffer(const void* data, size_t size);
void Shutdown();
void Bind() const;
void Unbind() const;
void BindBase(unsigned int target, unsigned int index) const;
void* Map();
void Unmap();
void SetData(const void* data, size_t size, size_t offset = 0);
unsigned int GetID() const { return m_buffer; }
size_t GetSize() const { return m_size; }
OpenGLBufferType GetType() const { return m_type; }
bool IsDynamic() const { return m_dynamic; }
private:
unsigned int m_buffer;
size_t m_size;
bool m_isIndexBuffer;
bool m_dynamic;
OpenGLBufferType m_type;
};
} // namespace RHI