OpenGL: refactor all of our StreamBuffers

The old way was to use big switch/case statements based on a type of buffer.
The new one is to use inheritance.

This change prohibits us to change the buffer type while running, but I doubt we'll ever do so.
Performance should also be a bit better. Also a nice cleanup.

Added some comments about this different kind of buffers.
This commit is contained in:
degasus
2014-01-23 00:47:49 +01:00
parent be1fee6d74
commit 128fcdac26
4 changed files with 373 additions and 256 deletions

View File

@ -5,6 +5,7 @@
#ifndef STREAMBUFFER_H
#define STREAMBUFFER_H
#include <utility>
#include "VideoCommon.h"
#include "FramebufferManager.h"
#include "GLUtil.h"
@ -17,39 +18,41 @@
namespace OGL
{
enum StreamType {
MAP_AND_ORPHAN = (1 << 1),
MAP_AND_SYNC = (1 << 2),
PINNED_MEMORY = (1 << 3),
BUFFERSUBDATA = (1 << 4),
BUFFERDATA = (1 << 5),
BUFFERSTORAGE = (1 << 6),
};
class StreamBuffer {
public:
static StreamBuffer* Create(u32 type, size_t size);
virtual ~StreamBuffer();
/* This mapping function will return a pair of:
* - the pointer to the mapped buffer
* - the offset into the real gpu buffer (always multiple of stride)
* On mapping, the maximum of size for allocation has to be set.
* The size really pushed into this fifo only has to be known on Unmapping.
* Mapping invalidates the current buffer content,
* so it isn't allowed to access the old content any more.
*/
virtual std::pair<u8*, size_t> Map(size_t size, u32 stride = 0) = 0;
virtual void Unmap(size_t used_size) = 0;
const u32 m_buffer;
protected:
StreamBuffer(u32 type, size_t size);
~StreamBuffer();
u8* Map(size_t size, u32 stride = 0);
size_t Unmap(size_t used_size); // returns the offset of the beginning of the uploaded block
inline u32 getBuffer() { return m_buffer; }
private:
void Init();
void Shutdown();
void CreateFences();
void DeleteFences();
void AllocMemory(size_t size);
void Align(u32 stride);
StreamType m_uploadtype;
u32 m_buffer;
u32 m_buffertype;
size_t m_size;
u8 *pointer;
const u32 m_buffertype;
const size_t m_size;
size_t m_iterator;
size_t m_used_iterator;
size_t m_free_iterator;
private:
GLsync *fences;
};