2018-03-19 22:10:59 +01:00
|
|
|
// Copyright 2018 Citra Emulator Project
|
|
|
|
// Licensed under GPLv2 or any later version
|
|
|
|
// Refer to the license.txt file included.
|
|
|
|
|
2018-08-21 05:24:27 +02:00
|
|
|
#pragma once
|
|
|
|
|
2018-08-09 21:31:46 +02:00
|
|
|
#include <tuple>
|
2018-03-19 22:10:59 +01:00
|
|
|
#include <glad/glad.h>
|
|
|
|
#include "common/common_types.h"
|
|
|
|
#include "video_core/renderer_opengl/gl_resource_manager.h"
|
|
|
|
|
2018-08-21 10:18:27 +02:00
|
|
|
namespace OpenGL {
|
|
|
|
|
2018-03-19 22:10:59 +01:00
|
|
|
class OGLStreamBuffer : private NonCopyable {
|
|
|
|
public:
|
2019-01-06 06:07:20 +01:00
|
|
|
explicit OGLStreamBuffer(GLsizeiptr size, bool vertex_data_usage, bool prefer_coherent = false);
|
2018-08-09 21:31:46 +02:00
|
|
|
~OGLStreamBuffer();
|
2018-03-19 22:10:59 +01:00
|
|
|
|
|
|
|
GLuint GetHandle() const;
|
2018-08-09 21:31:46 +02:00
|
|
|
GLsizeiptr GetSize() const;
|
|
|
|
|
|
|
|
/*
|
|
|
|
* 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-03-19 22:10:59 +01:00
|
|
|
|
2018-08-09 21:31:46 +02:00
|
|
|
void Unmap(GLsizeiptr size);
|
2018-03-19 22:10:59 +01:00
|
|
|
|
2018-08-09 21:31:46 +02:00
|
|
|
private:
|
2018-03-19 22:10:59 +01:00
|
|
|
OGLBuffer gl_buffer;
|
|
|
|
|
2018-08-09 21:31:46 +02:00
|
|
|
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-03-19 22:10:59 +01:00
|
|
|
};
|
2018-08-21 10:18:27 +02:00
|
|
|
|
|
|
|
} // namespace OpenGL
|