2012-05-13 17:09:18 +00:00
|
|
|
/*
|
|
|
|
* Copyright (C) 2011-2011 Gregory hainaut
|
|
|
|
* Copyright (C) 2007-2009 Gabest
|
|
|
|
*
|
|
|
|
* This Program is free software; you can redistribute it and/or modify
|
|
|
|
* it under the terms of the GNU General Public License as published by
|
|
|
|
* the Free Software Foundation; either version 2, or (at your option)
|
|
|
|
* any later version.
|
|
|
|
*
|
|
|
|
* This Program is distributed in the hope that it will be useful,
|
|
|
|
* but WITHOUT ANY WARRANTY; without even the implied warranty of
|
|
|
|
* MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
|
|
|
|
* GNU General Public License for more details.
|
|
|
|
*
|
|
|
|
* You should have received a copy of the GNU General Public License
|
|
|
|
* along with GNU Make; see the file COPYING. If not, write to
|
2012-09-09 18:16:11 +00:00
|
|
|
* the Free Software Foundation, Inc., 51 Franklin Street, Fifth Floor, Boston, MA 02110-1301, USA USA.
|
2012-05-13 17:09:18 +00:00
|
|
|
* http://www.gnu.org/copyleft/gpl.html
|
|
|
|
*
|
|
|
|
*/
|
|
|
|
|
|
|
|
#pragma once
|
|
|
|
|
2013-08-05 20:25:25 +00:00
|
|
|
#include "GLState.h"
|
|
|
|
|
2012-05-13 17:09:18 +00:00
|
|
|
class GSUniformBufferOGL {
|
|
|
|
GLuint buffer; // data object
|
|
|
|
GLuint index; // GLSL slot
|
2013-01-10 13:13:59 +00:00
|
|
|
uint32 size; // size of the data
|
2012-05-13 17:09:18 +00:00
|
|
|
|
|
|
|
public:
|
2013-01-10 13:13:59 +00:00
|
|
|
GSUniformBufferOGL(GLuint index, uint32 size) : index(index)
|
2012-05-13 17:09:18 +00:00
|
|
|
, size(size)
|
|
|
|
{
|
2013-05-19 09:19:20 +00:00
|
|
|
gl_GenBuffers(1, &buffer);
|
2012-05-13 17:09:18 +00:00
|
|
|
bind();
|
|
|
|
allocate();
|
|
|
|
attach();
|
|
|
|
}
|
|
|
|
|
|
|
|
void bind()
|
|
|
|
{
|
2013-08-05 20:25:25 +00:00
|
|
|
if (GLState::ubo != buffer) {
|
|
|
|
GLState::ubo = buffer;
|
|
|
|
gl_BindBuffer(GL_UNIFORM_BUFFER, buffer);
|
|
|
|
}
|
2012-05-13 17:09:18 +00:00
|
|
|
}
|
|
|
|
|
|
|
|
void allocate()
|
|
|
|
{
|
2013-07-19 19:25:50 +00:00
|
|
|
gl_BufferData(GL_UNIFORM_BUFFER, size, NULL, GL_STREAM_DRAW);
|
2012-05-13 17:09:18 +00:00
|
|
|
}
|
|
|
|
|
|
|
|
void attach()
|
|
|
|
{
|
2013-07-19 19:25:50 +00:00
|
|
|
gl_BindBufferBase(GL_UNIFORM_BUFFER, index, buffer);
|
2012-05-13 17:09:18 +00:00
|
|
|
}
|
|
|
|
|
|
|
|
void upload(const void* src)
|
|
|
|
{
|
2013-08-05 20:25:25 +00:00
|
|
|
bind();
|
2013-06-07 19:16:27 +00:00
|
|
|
// glMapBufferRange allow to set various parameter but the call is
|
|
|
|
// synchronous whereas glBufferSubData could be asynchronous.
|
|
|
|
// TODO: investigate the extension ARB_invalidate_subdata
|
2013-07-19 19:25:50 +00:00
|
|
|
gl_BufferSubData(GL_UNIFORM_BUFFER, 0, size, src);
|
2012-05-13 17:09:18 +00:00
|
|
|
}
|
|
|
|
|
|
|
|
~GSUniformBufferOGL() {
|
2013-05-19 09:19:20 +00:00
|
|
|
gl_DeleteBuffers(1, &buffer);
|
2012-05-13 17:09:18 +00:00
|
|
|
}
|
|
|
|
};
|