citra/src/video_core/renderer_opengl/gl_stream_buffer.h

47 lines
1.4 KiB
C++
Raw Normal View History

// Copyright 2022 Citra Emulator Project
2018-02-23 10:56:30 +01:00
// Licensed under GPLv2 or any later version
// Refer to the license.txt file included.
#pragma once
#include <tuple>
2018-02-23 10:56:30 +01:00
#include "video_core/renderer_opengl/gl_resource_manager.h"
namespace OpenGL {
2018-02-23 10:56:30 +01:00
class OGLStreamBuffer : private NonCopyable {
public:
explicit OGLStreamBuffer(GLenum target, GLsizeiptr size, bool array_buffer_for_amd,
bool prefer_coherent = false);
~OGLStreamBuffer();
2018-02-23 10:56:30 +01:00
GLuint GetHandle() const;
GLsizeiptr GetSize() const;
2018-02-23 10:56:30 +01:00
/*
* Allocates a linear chunk of memory in the GPU buffer with at least "size" bytes
* and the optional alignment requirement.
* If the buffer is full, the whole buffer is reallocated which invalidates old chunks.
* The return values are the pointer to the new chunk, the offset within the buffer,
* and the invalidation flag for previous chunks.
* The actual used size must be specified on unmapping the chunk.
*/
std::tuple<u8*, GLintptr, bool> Map(GLsizeiptr size, GLintptr alignment = 0);
2018-02-23 10:56:30 +01:00
void Unmap(GLsizeiptr size);
private:
2018-02-23 10:56:30 +01:00
OGLBuffer gl_buffer;
GLenum gl_target;
bool coherent = false;
bool persistent = false;
GLintptr buffer_pos = 0;
GLsizeiptr buffer_size = 0;
GLintptr mapped_offset = 0;
GLsizeiptr mapped_size = 0;
u8* mapped_ptr = nullptr;
2018-02-23 10:56:30 +01:00
};
} // namespace OpenGL