mirror of
https://github.com/overte-org/overte.git
synced 2025-08-06 18:50:00 +02:00
Merge pull request #3684 from samcake/temp0
Introduction of the Context and Backend class and the OpenGL version: the GLBackend
This commit is contained in:
commit
7ea4c760e7
11 changed files with 967 additions and 824 deletions
|
@ -80,6 +80,7 @@
|
||||||
#include "devices/TV3DManager.h"
|
#include "devices/TV3DManager.h"
|
||||||
|
|
||||||
#include "renderer/ProgramObject.h"
|
#include "renderer/ProgramObject.h"
|
||||||
|
#include "gpu/Batch.h"
|
||||||
|
|
||||||
#include "scripting/AccountScriptingInterface.h"
|
#include "scripting/AccountScriptingInterface.h"
|
||||||
#include "scripting/AudioDeviceScriptingInterface.h"
|
#include "scripting/AudioDeviceScriptingInterface.h"
|
||||||
|
@ -588,6 +589,7 @@ void Application::initializeGL() {
|
||||||
}
|
}
|
||||||
|
|
||||||
void Application::paintGL() {
|
void Application::paintGL() {
|
||||||
|
PROFILE_RANGE(__FUNCTION__);
|
||||||
PerformanceTimer perfTimer("paintGL");
|
PerformanceTimer perfTimer("paintGL");
|
||||||
|
|
||||||
PerformanceWarning::setSuppressShortTimings(Menu::getInstance()->isOptionChecked(MenuOption::SuppressShortTimings));
|
PerformanceWarning::setSuppressShortTimings(Menu::getInstance()->isOptionChecked(MenuOption::SuppressShortTimings));
|
||||||
|
@ -2841,6 +2843,7 @@ QImage Application::renderAvatarBillboard() {
|
||||||
}
|
}
|
||||||
|
|
||||||
void Application::displaySide(Camera& whichCamera, bool selfAvatarOnly) {
|
void Application::displaySide(Camera& whichCamera, bool selfAvatarOnly) {
|
||||||
|
PROFILE_RANGE(__FUNCTION__);
|
||||||
PerformanceTimer perfTimer("display");
|
PerformanceTimer perfTimer("display");
|
||||||
PerformanceWarning warn(Menu::getInstance()->isOptionChecked(MenuOption::PipelineWarnings), "Application::displaySide()");
|
PerformanceWarning warn(Menu::getInstance()->isOptionChecked(MenuOption::PipelineWarnings), "Application::displaySide()");
|
||||||
// transform by eye offset
|
// transform by eye offset
|
||||||
|
@ -3000,6 +3003,7 @@ void Application::displaySide(Camera& whichCamera, bool selfAvatarOnly) {
|
||||||
}
|
}
|
||||||
|
|
||||||
{
|
{
|
||||||
|
PROFILE_RANGE("DeferredLighting");
|
||||||
PerformanceTimer perfTimer("lighting");
|
PerformanceTimer perfTimer("lighting");
|
||||||
_deferredLightingEffect.render();
|
_deferredLightingEffect.render();
|
||||||
}
|
}
|
||||||
|
|
|
@ -12,19 +12,13 @@
|
||||||
|
|
||||||
#include <QDebug>
|
#include <QDebug>
|
||||||
|
|
||||||
#define ADD_COMMAND(call) _commands.push_back(COMMAND_##call); _commandCalls.push_back(&gpu::Batch::do_##call); _commandOffsets.push_back(_params.size());
|
//#define ADD_COMMAND(call) _commands.push_back(COMMAND_##call); _commandCalls.push_back(&gpu::Batch::do_##call); _commandOffsets.push_back(_params.size());
|
||||||
|
#define ADD_COMMAND(call) _commands.push_back(COMMAND_##call); _commandOffsets.push_back(_params.size());
|
||||||
//#define DO_IT_NOW(call, offset) runLastCommand();
|
|
||||||
#define DO_IT_NOW(call, offset)
|
|
||||||
|
|
||||||
//#define CHECK_GL_ERROR() ::gpu::backend::checkGLError()
|
|
||||||
#define CHECK_GL_ERROR()
|
|
||||||
|
|
||||||
using namespace gpu;
|
using namespace gpu;
|
||||||
|
|
||||||
Batch::Batch() :
|
Batch::Batch() :
|
||||||
_commands(),
|
_commands(),
|
||||||
_commandCalls(),
|
|
||||||
_commandOffsets(),
|
_commandOffsets(),
|
||||||
_params(),
|
_params(),
|
||||||
_resources(),
|
_resources(),
|
||||||
|
@ -36,7 +30,6 @@ Batch::~Batch() {
|
||||||
|
|
||||||
void Batch::clear() {
|
void Batch::clear() {
|
||||||
_commands.clear();
|
_commands.clear();
|
||||||
_commandCalls.clear();
|
|
||||||
_commandOffsets.clear();
|
_commandOffsets.clear();
|
||||||
_params.clear();
|
_params.clear();
|
||||||
_resources.clear();
|
_resources.clear();
|
||||||
|
@ -66,56 +59,6 @@ uint32 Batch::cacheData(uint32 size, const void* data) {
|
||||||
return offset;
|
return offset;
|
||||||
}
|
}
|
||||||
|
|
||||||
#define CASE_COMMAND(call) case COMMAND_##call: { do_##call(offset); } break;
|
|
||||||
|
|
||||||
void Batch::runCommand(Command com, uint32 offset) {
|
|
||||||
switch (com) {
|
|
||||||
CASE_COMMAND(draw);
|
|
||||||
CASE_COMMAND(drawIndexed);
|
|
||||||
CASE_COMMAND(drawInstanced);
|
|
||||||
CASE_COMMAND(drawIndexedInstanced);
|
|
||||||
CASE_COMMAND(glEnable);
|
|
||||||
CASE_COMMAND(glDisable);
|
|
||||||
CASE_COMMAND(glEnableClientState);
|
|
||||||
CASE_COMMAND(glDisableClientState);
|
|
||||||
CASE_COMMAND(glCullFace);
|
|
||||||
CASE_COMMAND(glAlphaFunc);
|
|
||||||
CASE_COMMAND(glDepthFunc);
|
|
||||||
CASE_COMMAND(glDepthMask);
|
|
||||||
CASE_COMMAND(glDepthRange);
|
|
||||||
CASE_COMMAND(glBindBuffer);
|
|
||||||
CASE_COMMAND(glBindTexture);
|
|
||||||
CASE_COMMAND(glActiveTexture);
|
|
||||||
CASE_COMMAND(glDrawBuffers);
|
|
||||||
CASE_COMMAND(glUseProgram);
|
|
||||||
CASE_COMMAND(glUniform1f);
|
|
||||||
CASE_COMMAND(glUniformMatrix4fv);
|
|
||||||
CASE_COMMAND(glMatrixMode);
|
|
||||||
CASE_COMMAND(glPushMatrix);
|
|
||||||
CASE_COMMAND(glPopMatrix);
|
|
||||||
CASE_COMMAND(glMultMatrixf);
|
|
||||||
CASE_COMMAND(glLoadMatrixf);
|
|
||||||
CASE_COMMAND(glLoadIdentity);
|
|
||||||
CASE_COMMAND(glRotatef);
|
|
||||||
CASE_COMMAND(glScalef);
|
|
||||||
CASE_COMMAND(glTranslatef);
|
|
||||||
CASE_COMMAND(glDrawArrays);
|
|
||||||
CASE_COMMAND(glDrawRangeElements);
|
|
||||||
CASE_COMMAND(glColorPointer);
|
|
||||||
CASE_COMMAND(glNormalPointer);
|
|
||||||
CASE_COMMAND(glTexCoordPointer);
|
|
||||||
CASE_COMMAND(glVertexPointer);
|
|
||||||
CASE_COMMAND(glVertexAttribPointer);
|
|
||||||
CASE_COMMAND(glEnableVertexAttribArray);
|
|
||||||
CASE_COMMAND(glDisableVertexAttribArray);
|
|
||||||
CASE_COMMAND(glColor4f);
|
|
||||||
CASE_COMMAND(glMaterialf);
|
|
||||||
CASE_COMMAND(glMaterialfv);
|
|
||||||
default:
|
|
||||||
break;
|
|
||||||
}
|
|
||||||
}
|
|
||||||
|
|
||||||
void Batch::draw(Primitive primitiveType, int nbVertices, int startVertex) {
|
void Batch::draw(Primitive primitiveType, int nbVertices, int startVertex) {
|
||||||
ADD_COMMAND(draw);
|
ADD_COMMAND(draw);
|
||||||
|
|
||||||
|
@ -152,605 +95,5 @@ void Batch::drawIndexedInstanced(uint32 nbInstances, Primitive primitiveType, in
|
||||||
_params.push_back(nbInstances);
|
_params.push_back(nbInstances);
|
||||||
}
|
}
|
||||||
|
|
||||||
// TODO: As long as we have gl calls explicitely issued from interface
|
|
||||||
// code, we need to be able to record and batch these calls. THe long
|
|
||||||
// term strategy is to get rid of any GL calls in favor of the HIFI GPU API
|
|
||||||
|
|
||||||
void Batch::_glEnable(GLenum cap) {
|
|
||||||
ADD_COMMAND(glEnable);
|
|
||||||
|
|
||||||
_params.push_back(cap);
|
|
||||||
|
|
||||||
DO_IT_NOW(_glEnable, 1);
|
|
||||||
}
|
|
||||||
void Batch::do_glEnable(uint32 paramOffset) {
|
|
||||||
glEnable(_params[paramOffset]._uint);
|
|
||||||
CHECK_GL_ERROR();
|
|
||||||
}
|
|
||||||
|
|
||||||
void Batch::_glDisable(GLenum cap) {
|
|
||||||
ADD_COMMAND(glDisable);
|
|
||||||
|
|
||||||
_params.push_back(cap);
|
|
||||||
|
|
||||||
DO_IT_NOW(_glDisable, 1);
|
|
||||||
}
|
|
||||||
void Batch::do_glDisable(uint32 paramOffset) {
|
|
||||||
glDisable(_params[paramOffset]._uint);
|
|
||||||
CHECK_GL_ERROR();
|
|
||||||
}
|
|
||||||
|
|
||||||
void Batch::_glEnableClientState(GLenum array) {
|
|
||||||
ADD_COMMAND(glEnableClientState);
|
|
||||||
|
|
||||||
_params.push_back(array);
|
|
||||||
|
|
||||||
DO_IT_NOW(_glEnableClientState, 1 );
|
|
||||||
}
|
|
||||||
void Batch::do_glEnableClientState(uint32 paramOffset) {
|
|
||||||
glEnableClientState(_params[paramOffset]._uint);
|
|
||||||
CHECK_GL_ERROR();
|
|
||||||
}
|
|
||||||
|
|
||||||
void Batch::_glDisableClientState(GLenum array) {
|
|
||||||
ADD_COMMAND(glDisableClientState);
|
|
||||||
|
|
||||||
_params.push_back(array);
|
|
||||||
|
|
||||||
DO_IT_NOW(_glDisableClientState, 1);
|
|
||||||
}
|
|
||||||
void Batch::do_glDisableClientState(uint32 paramOffset) {
|
|
||||||
glDisableClientState(_params[paramOffset]._uint);
|
|
||||||
CHECK_GL_ERROR();
|
|
||||||
}
|
|
||||||
|
|
||||||
void Batch::_glCullFace(GLenum mode) {
|
|
||||||
ADD_COMMAND(glCullFace);
|
|
||||||
|
|
||||||
_params.push_back(mode);
|
|
||||||
|
|
||||||
DO_IT_NOW(_glCullFace, 1);
|
|
||||||
}
|
|
||||||
void Batch::do_glCullFace(uint32 paramOffset) {
|
|
||||||
glCullFace(_params[paramOffset]._uint);
|
|
||||||
CHECK_GL_ERROR();
|
|
||||||
}
|
|
||||||
|
|
||||||
void Batch::_glAlphaFunc(GLenum func, GLclampf ref) {
|
|
||||||
ADD_COMMAND(glAlphaFunc);
|
|
||||||
|
|
||||||
_params.push_back(ref);
|
|
||||||
_params.push_back(func);
|
|
||||||
|
|
||||||
DO_IT_NOW(_glAlphaFunc, 2);
|
|
||||||
}
|
|
||||||
void Batch::do_glAlphaFunc(uint32 paramOffset) {
|
|
||||||
glAlphaFunc(
|
|
||||||
_params[paramOffset + 1]._uint,
|
|
||||||
_params[paramOffset + 0]._float);
|
|
||||||
CHECK_GL_ERROR();
|
|
||||||
}
|
|
||||||
|
|
||||||
void Batch::_glDepthFunc(GLenum func) {
|
|
||||||
ADD_COMMAND(glDepthFunc);
|
|
||||||
|
|
||||||
_params.push_back(func);
|
|
||||||
|
|
||||||
DO_IT_NOW(_glDepthFunc, 1);
|
|
||||||
}
|
|
||||||
void Batch::do_glDepthFunc(uint32 paramOffset) {
|
|
||||||
glDepthFunc(_params[paramOffset]._uint);
|
|
||||||
CHECK_GL_ERROR();
|
|
||||||
}
|
|
||||||
|
|
||||||
void Batch::_glDepthMask(GLboolean flag) {
|
|
||||||
ADD_COMMAND(glDepthMask);
|
|
||||||
|
|
||||||
_params.push_back(flag);
|
|
||||||
|
|
||||||
DO_IT_NOW(_glDepthMask, 1);
|
|
||||||
}
|
|
||||||
void Batch::do_glDepthMask(uint32 paramOffset) {
|
|
||||||
glDepthMask(_params[paramOffset]._uint);
|
|
||||||
CHECK_GL_ERROR();
|
|
||||||
}
|
|
||||||
|
|
||||||
void Batch::_glDepthRange(GLclampd zNear, GLclampd zFar) {
|
|
||||||
ADD_COMMAND(glDepthRange);
|
|
||||||
|
|
||||||
_params.push_back(zFar);
|
|
||||||
_params.push_back(zNear);
|
|
||||||
|
|
||||||
DO_IT_NOW(_glDepthRange, 2);
|
|
||||||
}
|
|
||||||
void Batch::do_glDepthRange(uint32 paramOffset) {
|
|
||||||
glDepthRange(
|
|
||||||
_params[paramOffset + 1]._double,
|
|
||||||
_params[paramOffset + 0]._double);
|
|
||||||
CHECK_GL_ERROR();
|
|
||||||
}
|
|
||||||
|
|
||||||
void Batch::_glBindBuffer(GLenum target, GLuint buffer) {
|
|
||||||
ADD_COMMAND(glBindBuffer);
|
|
||||||
|
|
||||||
_params.push_back(buffer);
|
|
||||||
_params.push_back(target);
|
|
||||||
|
|
||||||
DO_IT_NOW(_glBindBuffer, 2);
|
|
||||||
}
|
|
||||||
void Batch::do_glBindBuffer(uint32 paramOffset) {
|
|
||||||
glBindBuffer(
|
|
||||||
_params[paramOffset + 1]._uint,
|
|
||||||
_params[paramOffset + 0]._uint);
|
|
||||||
CHECK_GL_ERROR();
|
|
||||||
}
|
|
||||||
|
|
||||||
void Batch::_glBindTexture(GLenum target, GLuint texture) {
|
|
||||||
ADD_COMMAND(glBindTexture);
|
|
||||||
|
|
||||||
_params.push_back(texture);
|
|
||||||
_params.push_back(target);
|
|
||||||
|
|
||||||
DO_IT_NOW(_glBindTexture, 2);
|
|
||||||
}
|
|
||||||
void Batch::do_glBindTexture(uint32 paramOffset) {
|
|
||||||
glBindTexture(
|
|
||||||
_params[paramOffset + 1]._uint,
|
|
||||||
_params[paramOffset + 0]._uint);
|
|
||||||
CHECK_GL_ERROR();
|
|
||||||
}
|
|
||||||
|
|
||||||
void Batch::_glActiveTexture(GLenum texture) {
|
|
||||||
ADD_COMMAND(glActiveTexture);
|
|
||||||
|
|
||||||
_params.push_back(texture);
|
|
||||||
|
|
||||||
DO_IT_NOW(_glActiveTexture, 1);
|
|
||||||
}
|
|
||||||
void Batch::do_glActiveTexture(uint32 paramOffset) {
|
|
||||||
glActiveTexture(_params[paramOffset]._uint);
|
|
||||||
CHECK_GL_ERROR();
|
|
||||||
}
|
|
||||||
|
|
||||||
void Batch::_glDrawBuffers(GLsizei n, const GLenum* bufs) {
|
|
||||||
ADD_COMMAND(glDrawBuffers);
|
|
||||||
|
|
||||||
_params.push_back(cacheData(n * sizeof(GLenum), bufs));
|
|
||||||
_params.push_back(n);
|
|
||||||
|
|
||||||
DO_IT_NOW(_glDrawBuffers, 2);
|
|
||||||
}
|
|
||||||
void Batch::do_glDrawBuffers(uint32 paramOffset) {
|
|
||||||
glDrawBuffers(
|
|
||||||
_params[paramOffset + 1]._uint,
|
|
||||||
(const GLenum*) editData(_params[paramOffset + 0]._uint));
|
|
||||||
CHECK_GL_ERROR();
|
|
||||||
}
|
|
||||||
|
|
||||||
void Batch::_glUseProgram(GLuint program) {
|
|
||||||
ADD_COMMAND(glUseProgram);
|
|
||||||
|
|
||||||
_params.push_back(program);
|
|
||||||
|
|
||||||
DO_IT_NOW(_glUseProgram, 1);
|
|
||||||
}
|
|
||||||
void Batch::do_glUseProgram(uint32 paramOffset) {
|
|
||||||
glUseProgram(_params[paramOffset]._uint);
|
|
||||||
CHECK_GL_ERROR();
|
|
||||||
}
|
|
||||||
|
|
||||||
void Batch::_glUniform1f(GLint location, GLfloat v0) {
|
|
||||||
ADD_COMMAND(glUniform1f);
|
|
||||||
|
|
||||||
_params.push_back(v0);
|
|
||||||
_params.push_back(location);
|
|
||||||
|
|
||||||
DO_IT_NOW(_glUniform1f, 1);
|
|
||||||
}
|
|
||||||
void Batch::do_glUniform1f(uint32 paramOffset) {
|
|
||||||
glUniform1f(
|
|
||||||
_params[paramOffset + 1]._int,
|
|
||||||
_params[paramOffset + 0]._float);
|
|
||||||
CHECK_GL_ERROR();
|
|
||||||
}
|
|
||||||
|
|
||||||
void Batch::_glUniformMatrix4fv(GLint location, GLsizei count, GLboolean transpose, const GLfloat* value) {
|
|
||||||
ADD_COMMAND(glUniformMatrix4fv);
|
|
||||||
|
|
||||||
const int MATRIX4_SIZE = 16 * sizeof(float);
|
|
||||||
_params.push_back(cacheData(count * MATRIX4_SIZE, value));
|
|
||||||
_params.push_back(transpose);
|
|
||||||
_params.push_back(count);
|
|
||||||
_params.push_back(location);
|
|
||||||
|
|
||||||
DO_IT_NOW(_glUniformMatrix4fv, 4);
|
|
||||||
}
|
|
||||||
void Batch::do_glUniformMatrix4fv(uint32 paramOffset) {
|
|
||||||
glUniformMatrix4fv(
|
|
||||||
_params[paramOffset + 3]._int,
|
|
||||||
_params[paramOffset + 2]._uint,
|
|
||||||
_params[paramOffset + 1]._uint,
|
|
||||||
(const GLfloat*) editData(_params[paramOffset + 0]._uint));
|
|
||||||
CHECK_GL_ERROR();
|
|
||||||
}
|
|
||||||
|
|
||||||
void Batch::_glMatrixMode(GLenum mode) {
|
|
||||||
ADD_COMMAND(glMatrixMode);
|
|
||||||
|
|
||||||
_params.push_back(mode);
|
|
||||||
|
|
||||||
DO_IT_NOW(_glMatrixMode, 1);
|
|
||||||
}
|
|
||||||
void Batch::do_glMatrixMode(uint32 paramOffset) {
|
|
||||||
glMatrixMode(_params[paramOffset]._uint);
|
|
||||||
CHECK_GL_ERROR();
|
|
||||||
}
|
|
||||||
|
|
||||||
void Batch::_glPushMatrix() {
|
|
||||||
ADD_COMMAND(glPushMatrix);
|
|
||||||
|
|
||||||
DO_IT_NOW(_glPushMatrix, 0);
|
|
||||||
}
|
|
||||||
void Batch::do_glPushMatrix(uint32 paramOffset) {
|
|
||||||
glPushMatrix();
|
|
||||||
CHECK_GL_ERROR();
|
|
||||||
}
|
|
||||||
|
|
||||||
void Batch::_glPopMatrix() {
|
|
||||||
ADD_COMMAND(glPopMatrix);
|
|
||||||
|
|
||||||
DO_IT_NOW(_glPopMatrix, 0);
|
|
||||||
}
|
|
||||||
void Batch::do_glPopMatrix(uint32 paramOffset) {
|
|
||||||
glPopMatrix();
|
|
||||||
CHECK_GL_ERROR();
|
|
||||||
}
|
|
||||||
|
|
||||||
void Batch::_glMultMatrixf(const GLfloat *m) {
|
|
||||||
ADD_COMMAND(glMultMatrixf);
|
|
||||||
|
|
||||||
const int MATRIX4_SIZE = 16 * sizeof(float);
|
|
||||||
_params.push_back(cacheData(MATRIX4_SIZE, m));
|
|
||||||
|
|
||||||
DO_IT_NOW(_glMultMatrixf, 1);
|
|
||||||
}
|
|
||||||
void Batch::do_glMultMatrixf(uint32 paramOffset) {
|
|
||||||
glMultMatrixf((const GLfloat*) editData(_params[paramOffset]._uint));
|
|
||||||
CHECK_GL_ERROR();
|
|
||||||
}
|
|
||||||
|
|
||||||
void Batch::_glLoadMatrixf(const GLfloat *m) {
|
|
||||||
ADD_COMMAND(glLoadMatrixf);
|
|
||||||
|
|
||||||
const int MATRIX4_SIZE = 16 * sizeof(float);
|
|
||||||
_params.push_back(cacheData(MATRIX4_SIZE, m));
|
|
||||||
|
|
||||||
DO_IT_NOW(_glLoadMatrixf, 1);
|
|
||||||
}
|
|
||||||
void Batch::do_glLoadMatrixf(uint32 paramOffset) {
|
|
||||||
glLoadMatrixf((const GLfloat*)editData(_params[paramOffset]._uint));
|
|
||||||
CHECK_GL_ERROR();
|
|
||||||
}
|
|
||||||
|
|
||||||
void Batch::_glLoadIdentity(void) {
|
|
||||||
ADD_COMMAND(glLoadIdentity);
|
|
||||||
|
|
||||||
DO_IT_NOW(_glLoadIdentity, 0);
|
|
||||||
}
|
|
||||||
void Batch::do_glLoadIdentity(uint32 paramOffset) {
|
|
||||||
glLoadIdentity();
|
|
||||||
CHECK_GL_ERROR();
|
|
||||||
}
|
|
||||||
|
|
||||||
void Batch::_glRotatef(GLfloat angle, GLfloat x, GLfloat y, GLfloat z) {
|
|
||||||
ADD_COMMAND(glRotatef);
|
|
||||||
|
|
||||||
_params.push_back(z);
|
|
||||||
_params.push_back(y);
|
|
||||||
_params.push_back(x);
|
|
||||||
_params.push_back(angle);
|
|
||||||
|
|
||||||
DO_IT_NOW(_glRotatef, 4);
|
|
||||||
}
|
|
||||||
void Batch::do_glRotatef(uint32 paramOffset) {
|
|
||||||
glRotatef(
|
|
||||||
_params[paramOffset + 3]._float,
|
|
||||||
_params[paramOffset + 2]._float,
|
|
||||||
_params[paramOffset + 1]._float,
|
|
||||||
_params[paramOffset + 0]._float);
|
|
||||||
CHECK_GL_ERROR();
|
|
||||||
}
|
|
||||||
|
|
||||||
void Batch::_glScalef(GLfloat x, GLfloat y, GLfloat z) {
|
|
||||||
ADD_COMMAND(glScalef);
|
|
||||||
|
|
||||||
_params.push_back(z);
|
|
||||||
_params.push_back(y);
|
|
||||||
_params.push_back(x);
|
|
||||||
|
|
||||||
DO_IT_NOW(_glScalef, 3);
|
|
||||||
}
|
|
||||||
void Batch::do_glScalef(uint32 paramOffset) {
|
|
||||||
glScalef(
|
|
||||||
_params[paramOffset + 2]._float,
|
|
||||||
_params[paramOffset + 1]._float,
|
|
||||||
_params[paramOffset + 0]._float);
|
|
||||||
CHECK_GL_ERROR();
|
|
||||||
}
|
|
||||||
|
|
||||||
void Batch::_glTranslatef(GLfloat x, GLfloat y, GLfloat z) {
|
|
||||||
ADD_COMMAND(glTranslatef);
|
|
||||||
|
|
||||||
_params.push_back(z);
|
|
||||||
_params.push_back(y);
|
|
||||||
_params.push_back(x);
|
|
||||||
|
|
||||||
DO_IT_NOW(_glTranslatef, 3);
|
|
||||||
}
|
|
||||||
void Batch::do_glTranslatef(uint32 paramOffset) {
|
|
||||||
glTranslatef(
|
|
||||||
_params[paramOffset + 2]._float,
|
|
||||||
_params[paramOffset + 1]._float,
|
|
||||||
_params[paramOffset + 0]._float);
|
|
||||||
CHECK_GL_ERROR();
|
|
||||||
}
|
|
||||||
|
|
||||||
void Batch::_glDrawArrays(GLenum mode, GLint first, GLsizei count) {
|
|
||||||
ADD_COMMAND(glDrawArrays);
|
|
||||||
|
|
||||||
_params.push_back(count);
|
|
||||||
_params.push_back(first);
|
|
||||||
_params.push_back(mode);
|
|
||||||
|
|
||||||
DO_IT_NOW(_glDrawArrays, 3);
|
|
||||||
}
|
|
||||||
void Batch::do_glDrawArrays(uint32 paramOffset) {
|
|
||||||
glDrawArrays(
|
|
||||||
_params[paramOffset + 2]._uint,
|
|
||||||
_params[paramOffset + 1]._int,
|
|
||||||
_params[paramOffset + 0]._int);
|
|
||||||
CHECK_GL_ERROR();
|
|
||||||
}
|
|
||||||
|
|
||||||
void Batch::_glDrawRangeElements(GLenum mode, GLuint start, GLuint end, GLsizei count, GLenum type, const void *indices) {
|
|
||||||
ADD_COMMAND(glDrawRangeElements);
|
|
||||||
|
|
||||||
_params.push_back(cacheResource(indices));
|
|
||||||
_params.push_back(type);
|
|
||||||
_params.push_back(count);
|
|
||||||
_params.push_back(end);
|
|
||||||
_params.push_back(start);
|
|
||||||
_params.push_back(mode);
|
|
||||||
|
|
||||||
DO_IT_NOW(_glDrawRangeElements, 6);
|
|
||||||
}
|
|
||||||
void Batch::do_glDrawRangeElements(uint32 paramOffset) {
|
|
||||||
glDrawRangeElements(
|
|
||||||
_params[paramOffset + 5]._uint,
|
|
||||||
_params[paramOffset + 4]._uint,
|
|
||||||
_params[paramOffset + 3]._uint,
|
|
||||||
_params[paramOffset + 2]._int,
|
|
||||||
_params[paramOffset + 1]._uint,
|
|
||||||
editResource(_params[paramOffset + 0]._uint)->_pointer);
|
|
||||||
CHECK_GL_ERROR();
|
|
||||||
}
|
|
||||||
|
|
||||||
void Batch::_glColorPointer(GLint size, GLenum type, GLsizei stride, const void *pointer) {
|
|
||||||
ADD_COMMAND(glColorPointer);
|
|
||||||
|
|
||||||
_params.push_back(cacheResource(pointer));
|
|
||||||
_params.push_back(stride);
|
|
||||||
_params.push_back(type);
|
|
||||||
_params.push_back(size);
|
|
||||||
|
|
||||||
DO_IT_NOW(_glColorPointer, 4);
|
|
||||||
}
|
|
||||||
void Batch::do_glColorPointer(uint32 paramOffset) {
|
|
||||||
glColorPointer(
|
|
||||||
_params[paramOffset + 3]._int,
|
|
||||||
_params[paramOffset + 2]._uint,
|
|
||||||
_params[paramOffset + 1]._int,
|
|
||||||
editResource(_params[paramOffset + 0]._uint)->_pointer);
|
|
||||||
CHECK_GL_ERROR();
|
|
||||||
}
|
|
||||||
|
|
||||||
void Batch::_glNormalPointer(GLenum type, GLsizei stride, const void *pointer) {
|
|
||||||
ADD_COMMAND(glNormalPointer);
|
|
||||||
|
|
||||||
_params.push_back(cacheResource(pointer));
|
|
||||||
_params.push_back(stride);
|
|
||||||
_params.push_back(type);
|
|
||||||
|
|
||||||
DO_IT_NOW(_glNormalPointer, 3);
|
|
||||||
}
|
|
||||||
void Batch::do_glNormalPointer(uint32 paramOffset) {
|
|
||||||
glNormalPointer(
|
|
||||||
_params[paramOffset + 2]._uint,
|
|
||||||
_params[paramOffset + 1]._int,
|
|
||||||
editResource(_params[paramOffset + 0]._uint)->_pointer);
|
|
||||||
CHECK_GL_ERROR();
|
|
||||||
}
|
|
||||||
|
|
||||||
void Batch::_glTexCoordPointer(GLint size, GLenum type, GLsizei stride, const void *pointer) {
|
|
||||||
ADD_COMMAND(glTexCoordPointer);
|
|
||||||
|
|
||||||
_params.push_back(cacheResource(pointer));
|
|
||||||
_params.push_back(stride);
|
|
||||||
_params.push_back(type);
|
|
||||||
_params.push_back(size);
|
|
||||||
|
|
||||||
DO_IT_NOW(_glTexCoordPointer, 4);
|
|
||||||
}
|
|
||||||
void Batch::do_glTexCoordPointer(uint32 paramOffset) {
|
|
||||||
glTexCoordPointer(
|
|
||||||
_params[paramOffset + 3]._int,
|
|
||||||
_params[paramOffset + 2]._uint,
|
|
||||||
_params[paramOffset + 1]._int,
|
|
||||||
editResource(_params[paramOffset + 0]._uint)->_pointer);
|
|
||||||
CHECK_GL_ERROR();
|
|
||||||
}
|
|
||||||
|
|
||||||
void Batch::_glVertexPointer(GLint size, GLenum type, GLsizei stride, const void *pointer) {
|
|
||||||
ADD_COMMAND(glVertexPointer);
|
|
||||||
|
|
||||||
_params.push_back(cacheResource(pointer));
|
|
||||||
_params.push_back(stride);
|
|
||||||
_params.push_back(type);
|
|
||||||
_params.push_back(size);
|
|
||||||
|
|
||||||
DO_IT_NOW(_glVertexPointer, 4);
|
|
||||||
}
|
|
||||||
void Batch::do_glVertexPointer(uint32 paramOffset) {
|
|
||||||
glVertexPointer(
|
|
||||||
_params[paramOffset + 3]._int,
|
|
||||||
_params[paramOffset + 2]._uint,
|
|
||||||
_params[paramOffset + 1]._int,
|
|
||||||
editResource(_params[paramOffset + 0]._uint)->_pointer);
|
|
||||||
CHECK_GL_ERROR();
|
|
||||||
}
|
|
||||||
|
|
||||||
|
|
||||||
void Batch::_glVertexAttribPointer(GLuint index, GLint size, GLenum type, GLboolean normalized, GLsizei stride, const void *pointer) {
|
|
||||||
ADD_COMMAND(glVertexAttribPointer);
|
|
||||||
|
|
||||||
_params.push_back(cacheResource(pointer));
|
|
||||||
_params.push_back(stride);
|
|
||||||
_params.push_back(normalized);
|
|
||||||
_params.push_back(type);
|
|
||||||
_params.push_back(size);
|
|
||||||
_params.push_back(index);
|
|
||||||
|
|
||||||
DO_IT_NOW(_glVertexAttribPointer, 6);
|
|
||||||
}
|
|
||||||
void Batch::do_glVertexAttribPointer(uint32 paramOffset) {
|
|
||||||
glVertexAttribPointer(
|
|
||||||
_params[paramOffset + 5]._uint,
|
|
||||||
_params[paramOffset + 4]._int,
|
|
||||||
_params[paramOffset + 3]._uint,
|
|
||||||
_params[paramOffset + 2]._uint,
|
|
||||||
_params[paramOffset + 1]._int,
|
|
||||||
editResource(_params[paramOffset + 0]._uint)->_pointer);
|
|
||||||
CHECK_GL_ERROR();
|
|
||||||
}
|
|
||||||
|
|
||||||
void Batch::_glEnableVertexAttribArray(GLint location) {
|
|
||||||
ADD_COMMAND(glEnableVertexAttribArray);
|
|
||||||
|
|
||||||
_params.push_back(location);
|
|
||||||
|
|
||||||
DO_IT_NOW(_glEnableVertexAttribArray, 1);
|
|
||||||
}
|
|
||||||
void Batch::do_glEnableVertexAttribArray(uint32 paramOffset) {
|
|
||||||
glEnableVertexAttribArray(_params[paramOffset]._uint);
|
|
||||||
CHECK_GL_ERROR();
|
|
||||||
}
|
|
||||||
|
|
||||||
void Batch::_glDisableVertexAttribArray(GLint location) {
|
|
||||||
ADD_COMMAND(glDisableVertexAttribArray);
|
|
||||||
|
|
||||||
_params.push_back(location);
|
|
||||||
|
|
||||||
DO_IT_NOW(_glDisableVertexAttribArray, 1);
|
|
||||||
}
|
|
||||||
void Batch::do_glDisableVertexAttribArray(uint32 paramOffset) {
|
|
||||||
glDisableVertexAttribArray(_params[paramOffset]._uint);
|
|
||||||
CHECK_GL_ERROR();
|
|
||||||
}
|
|
||||||
|
|
||||||
void Batch::_glColor4f(GLfloat red, GLfloat green, GLfloat blue, GLfloat alpha) {
|
|
||||||
ADD_COMMAND(glColor4f);
|
|
||||||
|
|
||||||
_params.push_back(alpha);
|
|
||||||
_params.push_back(blue);
|
|
||||||
_params.push_back(green);
|
|
||||||
_params.push_back(red);
|
|
||||||
|
|
||||||
DO_IT_NOW(_glColor4f, 4);
|
|
||||||
}
|
|
||||||
void Batch::do_glColor4f(uint32 paramOffset) {
|
|
||||||
glColor4f(
|
|
||||||
_params[paramOffset + 3]._float,
|
|
||||||
_params[paramOffset + 2]._float,
|
|
||||||
_params[paramOffset + 1]._float,
|
|
||||||
_params[paramOffset + 0]._float);
|
|
||||||
CHECK_GL_ERROR();
|
|
||||||
}
|
|
||||||
|
|
||||||
void Batch::_glMaterialf(GLenum face, GLenum pname, GLfloat param) {
|
|
||||||
ADD_COMMAND(glMaterialf);
|
|
||||||
|
|
||||||
_params.push_back(param);
|
|
||||||
_params.push_back(pname);
|
|
||||||
_params.push_back(face);
|
|
||||||
|
|
||||||
DO_IT_NOW(_glMaterialf, 3);
|
|
||||||
}
|
|
||||||
void Batch::do_glMaterialf(uint32 paramOffset) {
|
|
||||||
glMaterialf(
|
|
||||||
_params[paramOffset + 2]._uint,
|
|
||||||
_params[paramOffset + 1]._uint,
|
|
||||||
_params[paramOffset + 0]._float);
|
|
||||||
CHECK_GL_ERROR();
|
|
||||||
}
|
|
||||||
|
|
||||||
void Batch::_glMaterialfv(GLenum face, GLenum pname, const GLfloat *params) {
|
|
||||||
ADD_COMMAND(glMaterialfv);
|
|
||||||
|
|
||||||
_params.push_back(cacheData(4 * sizeof(float), params));
|
|
||||||
_params.push_back(pname);
|
|
||||||
_params.push_back(face);
|
|
||||||
|
|
||||||
DO_IT_NOW(_glMaterialfv, 3);
|
|
||||||
}
|
|
||||||
void Batch::do_glMaterialfv(uint32 paramOffset) {
|
|
||||||
glMaterialfv(
|
|
||||||
_params[paramOffset + 2]._uint,
|
|
||||||
_params[paramOffset + 1]._uint,
|
|
||||||
(const GLfloat*) editData(_params[paramOffset + 0]._uint));
|
|
||||||
CHECK_GL_ERROR();
|
|
||||||
}
|
|
||||||
|
|
||||||
|
|
||||||
|
|
||||||
void backend::renderBatch(Batch& batch) {
|
|
||||||
uint32 numCommands = batch._commands.size();
|
|
||||||
Batch::CommandCall* call = batch._commandCalls.data();
|
|
||||||
Batch::CommandOffsets::value_type* offset = batch._commandOffsets.data();
|
|
||||||
|
|
||||||
for (int i = 0; i < numCommands; i++) {
|
|
||||||
(batch.*(*call))(*offset);
|
|
||||||
call++;
|
|
||||||
offset++;
|
|
||||||
}
|
|
||||||
}
|
|
||||||
|
|
||||||
void backend::checkGLError() {
|
|
||||||
GLenum error = glGetError();
|
|
||||||
if (!error) {
|
|
||||||
return;
|
|
||||||
} else {
|
|
||||||
switch (error) {
|
|
||||||
case GL_INVALID_ENUM:
|
|
||||||
qDebug() << "An unacceptable value is specified for an enumerated argument.The offending command is ignored and has no other side effect than to set the error flag.";
|
|
||||||
break;
|
|
||||||
case GL_INVALID_VALUE:
|
|
||||||
qDebug() << "A numeric argument is out of range.The offending command is ignored and has no other side effect than to set the error flag";
|
|
||||||
break;
|
|
||||||
case GL_INVALID_OPERATION:
|
|
||||||
qDebug() << "The specified operation is not allowed in the current state.The offending command is ignored and has no other side effect than to set the error flag..";
|
|
||||||
break;
|
|
||||||
case GL_INVALID_FRAMEBUFFER_OPERATION:
|
|
||||||
qDebug() << "The framebuffer object is not complete.The offending command is ignored and has no other side effect than to set the error flag.";
|
|
||||||
break;
|
|
||||||
case GL_OUT_OF_MEMORY:
|
|
||||||
qDebug() << "There is not enough memory left to execute the command.The state of the GL is undefined, except for the state of the error flags, after this error is recorded.";
|
|
||||||
break;
|
|
||||||
case GL_STACK_UNDERFLOW:
|
|
||||||
qDebug() << "An attempt has been made to perform an operation that would cause an internal stack to underflow.";
|
|
||||||
break;
|
|
||||||
case GL_STACK_OVERFLOW:
|
|
||||||
qDebug() << "An attempt has been made to perform an operation that would cause an internal stack to overflow.";
|
|
||||||
break;
|
|
||||||
}
|
|
||||||
}
|
|
||||||
}
|
|
|
@ -35,15 +35,6 @@
|
||||||
|
|
||||||
namespace gpu {
|
namespace gpu {
|
||||||
|
|
||||||
class Batch;
|
|
||||||
// TODO: move the backend namespace into dedicated files, for now we keep it close to the gpu objects definition for convenience
|
|
||||||
namespace backend {
|
|
||||||
|
|
||||||
void renderBatch(Batch& batch);
|
|
||||||
|
|
||||||
void checkGLError();
|
|
||||||
};
|
|
||||||
|
|
||||||
class Buffer;
|
class Buffer;
|
||||||
class Resource;
|
class Resource;
|
||||||
typedef int Stamp;
|
typedef int Stamp;
|
||||||
|
@ -76,6 +67,9 @@ public:
|
||||||
// TODO: As long as we have gl calls explicitely issued from interface
|
// TODO: As long as we have gl calls explicitely issued from interface
|
||||||
// code, we need to be able to record and batch these calls. THe long
|
// code, we need to be able to record and batch these calls. THe long
|
||||||
// term strategy is to get rid of any GL calls in favor of the HIFI GPU API
|
// term strategy is to get rid of any GL calls in favor of the HIFI GPU API
|
||||||
|
// For now, instead of calling the raw glCall, use the equivalent call on the batch so the call is beeing recorded
|
||||||
|
// THe implementation of these functions is in GLBackend.cpp
|
||||||
|
|
||||||
void _glEnable(GLenum cap);
|
void _glEnable(GLenum cap);
|
||||||
void _glDisable(GLenum cap);
|
void _glDisable(GLenum cap);
|
||||||
|
|
||||||
|
@ -128,8 +122,6 @@ public:
|
||||||
void _glMaterialfv(GLenum face, GLenum pname, const GLfloat *params);
|
void _glMaterialfv(GLenum face, GLenum pname, const GLfloat *params);
|
||||||
|
|
||||||
|
|
||||||
protected:
|
|
||||||
|
|
||||||
enum Command {
|
enum Command {
|
||||||
COMMAND_draw = 0,
|
COMMAND_draw = 0,
|
||||||
COMMAND_drawIndexed,
|
COMMAND_drawIndexed,
|
||||||
|
@ -196,12 +188,14 @@ protected:
|
||||||
|
|
||||||
COMMAND_glMaterialf,
|
COMMAND_glMaterialf,
|
||||||
COMMAND_glMaterialfv,
|
COMMAND_glMaterialfv,
|
||||||
|
|
||||||
|
NUM_COMMANDS,
|
||||||
};
|
};
|
||||||
typedef std::vector<Command> Commands;
|
typedef std::vector<Command> Commands;
|
||||||
typedef void (Batch::*CommandCall)(uint32);
|
|
||||||
typedef std::vector<CommandCall> CommandCalls;
|
|
||||||
typedef std::vector<uint32> CommandOffsets;
|
typedef std::vector<uint32> CommandOffsets;
|
||||||
|
|
||||||
|
const Commands& getCommands() const { return _commands; }
|
||||||
|
const CommandOffsets& getCommandOffsets() const { return _commandOffsets; }
|
||||||
|
|
||||||
class Param {
|
class Param {
|
||||||
public:
|
public:
|
||||||
|
@ -219,6 +213,8 @@ protected:
|
||||||
};
|
};
|
||||||
typedef std::vector<Param> Params;
|
typedef std::vector<Param> Params;
|
||||||
|
|
||||||
|
const Params& getParams() const { return _params; }
|
||||||
|
|
||||||
class ResourceCache {
|
class ResourceCache {
|
||||||
public:
|
public:
|
||||||
union {
|
union {
|
||||||
|
@ -233,13 +229,6 @@ protected:
|
||||||
typedef unsigned char Byte;
|
typedef unsigned char Byte;
|
||||||
typedef std::vector<Byte> Bytes;
|
typedef std::vector<Byte> Bytes;
|
||||||
|
|
||||||
Commands _commands;
|
|
||||||
CommandCalls _commandCalls;
|
|
||||||
CommandOffsets _commandOffsets;
|
|
||||||
Params _params;
|
|
||||||
Resources _resources;
|
|
||||||
Bytes _data;
|
|
||||||
|
|
||||||
uint32 cacheResource(Resource* res);
|
uint32 cacheResource(Resource* res);
|
||||||
uint32 cacheResource(const void* pointer);
|
uint32 cacheResource(const void* pointer);
|
||||||
ResourceCache* editResource(uint32 offset) {
|
ResourceCache* editResource(uint32 offset) {
|
||||||
|
@ -255,79 +244,12 @@ protected:
|
||||||
return (_data.data() + offset);
|
return (_data.data() + offset);
|
||||||
}
|
}
|
||||||
|
|
||||||
void runCommand(uint32 index) {
|
Commands _commands;
|
||||||
uint32 offset = _commandOffsets[index];
|
CommandOffsets _commandOffsets;
|
||||||
CommandCall call = _commandCalls[index];
|
Params _params;
|
||||||
(this->*(call))(offset);
|
Resources _resources;
|
||||||
}
|
Bytes _data;
|
||||||
|
protected:
|
||||||
void runLastCommand() {
|
|
||||||
uint32 index = _commands.size() - 1;
|
|
||||||
runCommand(index);
|
|
||||||
}
|
|
||||||
|
|
||||||
void runCommand(Command com, uint32 offset);
|
|
||||||
|
|
||||||
void do_draw(uint32 paramOffset) {}
|
|
||||||
void do_drawIndexed(uint32 paramOffset) {}
|
|
||||||
void do_drawInstanced(uint32 paramOffset) {}
|
|
||||||
void do_drawIndexedInstanced(uint32 paramOffset) {}
|
|
||||||
|
|
||||||
// TODO: As long as we have gl calls explicitely issued from interface
|
|
||||||
// code, we need to be able to record and batch these calls. THe long
|
|
||||||
// term strategy is to get rid of any GL calls in favor of the HIFI GPU API
|
|
||||||
void do_glEnable(uint32 paramOffset);
|
|
||||||
void do_glDisable(uint32 paramOffset);
|
|
||||||
|
|
||||||
void do_glEnableClientState(uint32 paramOffset);
|
|
||||||
void do_glDisableClientState(uint32 paramOffset);
|
|
||||||
|
|
||||||
void do_glCullFace(uint32 paramOffset);
|
|
||||||
void do_glAlphaFunc(uint32 paramOffset);
|
|
||||||
|
|
||||||
void do_glDepthFunc(uint32 paramOffset);
|
|
||||||
void do_glDepthMask(uint32 paramOffset);
|
|
||||||
void do_glDepthRange(uint32 paramOffset);
|
|
||||||
|
|
||||||
void do_glBindBuffer(uint32 paramOffset);
|
|
||||||
|
|
||||||
void do_glBindTexture(uint32 paramOffset);
|
|
||||||
void do_glActiveTexture(uint32 paramOffset);
|
|
||||||
|
|
||||||
void do_glDrawBuffers(uint32 paramOffset);
|
|
||||||
|
|
||||||
void do_glUseProgram(uint32 paramOffset);
|
|
||||||
void do_glUniform1f(uint32 paramOffset);
|
|
||||||
void do_glUniformMatrix4fv(uint32 paramOffset);
|
|
||||||
|
|
||||||
void do_glMatrixMode(uint32 paramOffset);
|
|
||||||
void do_glPushMatrix(uint32 paramOffset);
|
|
||||||
void do_glPopMatrix(uint32 paramOffset);
|
|
||||||
void do_glMultMatrixf(uint32 paramOffset);
|
|
||||||
void do_glLoadMatrixf(uint32 paramOffset);
|
|
||||||
void do_glLoadIdentity(uint32 paramOffset);
|
|
||||||
void do_glRotatef(uint32 paramOffset);
|
|
||||||
void do_glScalef(uint32 paramOffset);
|
|
||||||
void do_glTranslatef(uint32 paramOffset);
|
|
||||||
|
|
||||||
void do_glDrawArrays(uint32 paramOffset);
|
|
||||||
void do_glDrawRangeElements(uint32 paramOffset);
|
|
||||||
|
|
||||||
void do_glColorPointer(uint32 paramOffset);
|
|
||||||
void do_glNormalPointer(uint32 paramOffset);
|
|
||||||
void do_glTexCoordPointer(uint32 paramOffset);
|
|
||||||
void do_glVertexPointer(uint32 paramOffset);
|
|
||||||
|
|
||||||
void do_glVertexAttribPointer(uint32 paramOffset);
|
|
||||||
void do_glEnableVertexAttribArray(uint32 paramOffset);
|
|
||||||
void do_glDisableVertexAttribArray(uint32 paramOffset);
|
|
||||||
|
|
||||||
void do_glColor4f(uint32 paramOffset);
|
|
||||||
|
|
||||||
void do_glMaterialf(uint32 paramOffset);
|
|
||||||
void do_glMaterialfv(uint32 paramOffset);
|
|
||||||
|
|
||||||
friend void backend::renderBatch(Batch& batch);
|
|
||||||
};
|
};
|
||||||
|
|
||||||
};
|
};
|
||||||
|
|
12
interface/src/gpu/Context.cpp
Normal file
12
interface/src/gpu/Context.cpp
Normal file
|
@ -0,0 +1,12 @@
|
||||||
|
//
|
||||||
|
// Context.cpp
|
||||||
|
// interface/src/gpu
|
||||||
|
//
|
||||||
|
// Created by Sam Gateau on 10/27/2014.
|
||||||
|
// Copyright 2014 High Fidelity, Inc.
|
||||||
|
//
|
||||||
|
// Distributed under the Apache License, Version 2.0.
|
||||||
|
// See the accompanying file LICENSE or http://www.apache.org/licenses/LICENSE-2.0.html
|
||||||
|
//
|
||||||
|
#include "Context.h"
|
||||||
|
|
62
interface/src/gpu/Context.h
Normal file
62
interface/src/gpu/Context.h
Normal file
|
@ -0,0 +1,62 @@
|
||||||
|
//
|
||||||
|
// Context.h
|
||||||
|
// interface/src/gpu
|
||||||
|
//
|
||||||
|
// Created by Sam Gateau on 10/27/2014.
|
||||||
|
// Copyright 2014 High Fidelity, Inc.
|
||||||
|
//
|
||||||
|
// Distributed under the Apache License, Version 2.0.
|
||||||
|
// See the accompanying file LICENSE or http://www.apache.org/licenses/LICENSE-2.0.html
|
||||||
|
//
|
||||||
|
#ifndef hifi_gpu_Context_h
|
||||||
|
#define hifi_gpu_Context_h
|
||||||
|
|
||||||
|
#include <assert.h>
|
||||||
|
#include "InterfaceConfig.h"
|
||||||
|
|
||||||
|
#include "gpu/Resource.h"
|
||||||
|
|
||||||
|
namespace gpu {
|
||||||
|
|
||||||
|
class GPUObject {
|
||||||
|
public:
|
||||||
|
GPUObject() {}
|
||||||
|
~GPUObject() {}
|
||||||
|
};
|
||||||
|
|
||||||
|
class Batch;
|
||||||
|
|
||||||
|
class Backend {
|
||||||
|
public:
|
||||||
|
|
||||||
|
template< typename T >
|
||||||
|
static void setGPUObject(const Buffer& buffer, T* bo) {
|
||||||
|
buffer.setGPUObject(reinterpret_cast<GPUObject*>(bo));
|
||||||
|
}
|
||||||
|
template< typename T >
|
||||||
|
static T* getGPUObject(const Buffer& buffer) {
|
||||||
|
return reinterpret_cast<T*>(buffer.getGPUObject());
|
||||||
|
}
|
||||||
|
|
||||||
|
void syncGPUObject(const Buffer& buffer);
|
||||||
|
|
||||||
|
protected:
|
||||||
|
|
||||||
|
};
|
||||||
|
|
||||||
|
class Context {
|
||||||
|
public:
|
||||||
|
Context();
|
||||||
|
Context(const Context& context);
|
||||||
|
~Context();
|
||||||
|
|
||||||
|
void enqueueBatch(Batch& batch);
|
||||||
|
|
||||||
|
protected:
|
||||||
|
|
||||||
|
};
|
||||||
|
|
||||||
|
|
||||||
|
};
|
||||||
|
|
||||||
|
#endif
|
741
interface/src/gpu/GLBackend.cpp
Normal file
741
interface/src/gpu/GLBackend.cpp
Normal file
|
@ -0,0 +1,741 @@
|
||||||
|
//
|
||||||
|
// GLBackend.cpp
|
||||||
|
// interface/src/gpu
|
||||||
|
//
|
||||||
|
// Created by Sam Gateau on 10/27/2014.
|
||||||
|
// Copyright 2014 High Fidelity, Inc.
|
||||||
|
//
|
||||||
|
// Distributed under the Apache License, Version 2.0.
|
||||||
|
// See the accompanying file LICENSE or http://www.apache.org/licenses/LICENSE-2.0.html
|
||||||
|
//
|
||||||
|
#include "GLBackend.h"
|
||||||
|
|
||||||
|
#include <QDebug>
|
||||||
|
|
||||||
|
#include "gpu/Batch.h"
|
||||||
|
|
||||||
|
using namespace gpu;
|
||||||
|
|
||||||
|
GLBackend::CommandCall GLBackend::_commandCalls[Batch::NUM_COMMANDS] =
|
||||||
|
{
|
||||||
|
(&::gpu::GLBackend::do_glEnable),
|
||||||
|
(&::gpu::GLBackend::do_glDisable),
|
||||||
|
|
||||||
|
(&::gpu::GLBackend::do_glEnableClientState),
|
||||||
|
(&::gpu::GLBackend::do_glDisableClientState),
|
||||||
|
|
||||||
|
(&::gpu::GLBackend::do_glCullFace),
|
||||||
|
(&::gpu::GLBackend::do_glAlphaFunc),
|
||||||
|
|
||||||
|
(&::gpu::GLBackend::do_glDepthFunc),
|
||||||
|
(&::gpu::GLBackend::do_glDepthMask),
|
||||||
|
(&::gpu::GLBackend::do_glDepthRange),
|
||||||
|
|
||||||
|
(&::gpu::GLBackend::do_glBindBuffer),
|
||||||
|
|
||||||
|
(&::gpu::GLBackend::do_glBindTexture),
|
||||||
|
(&::gpu::GLBackend::do_glActiveTexture),
|
||||||
|
|
||||||
|
(&::gpu::GLBackend::do_glDrawBuffers),
|
||||||
|
|
||||||
|
(&::gpu::GLBackend::do_glUseProgram),
|
||||||
|
(&::gpu::GLBackend::do_glUniform1f),
|
||||||
|
(&::gpu::GLBackend::do_glUniformMatrix4fv),
|
||||||
|
|
||||||
|
(&::gpu::GLBackend::do_glMatrixMode),
|
||||||
|
(&::gpu::GLBackend::do_glPushMatrix),
|
||||||
|
(&::gpu::GLBackend::do_glPopMatrix),
|
||||||
|
(&::gpu::GLBackend::do_glMultMatrixf),
|
||||||
|
(&::gpu::GLBackend::do_glLoadMatrixf),
|
||||||
|
(&::gpu::GLBackend::do_glLoadIdentity),
|
||||||
|
(&::gpu::GLBackend::do_glRotatef),
|
||||||
|
(&::gpu::GLBackend::do_glScalef),
|
||||||
|
(&::gpu::GLBackend::do_glTranslatef),
|
||||||
|
|
||||||
|
(&::gpu::GLBackend::do_glDrawArrays),
|
||||||
|
(&::gpu::GLBackend::do_glDrawRangeElements),
|
||||||
|
|
||||||
|
(&::gpu::GLBackend::do_glColorPointer),
|
||||||
|
(&::gpu::GLBackend::do_glNormalPointer),
|
||||||
|
(&::gpu::GLBackend::do_glTexCoordPointer),
|
||||||
|
(&::gpu::GLBackend::do_glVertexPointer),
|
||||||
|
|
||||||
|
(&::gpu::GLBackend::do_glVertexAttribPointer),
|
||||||
|
(&::gpu::GLBackend::do_glEnableVertexAttribArray),
|
||||||
|
(&::gpu::GLBackend::do_glDisableVertexAttribArray),
|
||||||
|
|
||||||
|
(&::gpu::GLBackend::do_glColor4f),
|
||||||
|
|
||||||
|
(&::gpu::GLBackend::do_glMaterialf),
|
||||||
|
(&::gpu::GLBackend::do_glMaterialfv),
|
||||||
|
};
|
||||||
|
|
||||||
|
|
||||||
|
GLBackend::GLBackend() {
|
||||||
|
|
||||||
|
}
|
||||||
|
|
||||||
|
GLBackend::~GLBackend() {
|
||||||
|
|
||||||
|
}
|
||||||
|
|
||||||
|
void GLBackend::renderBatch(Batch& batch) {
|
||||||
|
uint32 numCommands = batch.getCommands().size();
|
||||||
|
const Batch::Commands::value_type* command = batch.getCommands().data();
|
||||||
|
const Batch::CommandOffsets::value_type* offset = batch.getCommandOffsets().data();
|
||||||
|
|
||||||
|
GLBackend backend;
|
||||||
|
|
||||||
|
for (int i = 0; i < numCommands; i++) {
|
||||||
|
CommandCall call = _commandCalls[((*command) - Batch::COMMAND_glEnable)];
|
||||||
|
(backend.*(call))(batch, *offset);
|
||||||
|
command++;
|
||||||
|
offset++;
|
||||||
|
}
|
||||||
|
}
|
||||||
|
|
||||||
|
void GLBackend::checkGLError() {
|
||||||
|
GLenum error = glGetError();
|
||||||
|
if (!error) {
|
||||||
|
return;
|
||||||
|
}
|
||||||
|
else {
|
||||||
|
switch (error) {
|
||||||
|
case GL_INVALID_ENUM:
|
||||||
|
qDebug() << "An unacceptable value is specified for an enumerated argument.The offending command is ignored and has no other side effect than to set the error flag.";
|
||||||
|
break;
|
||||||
|
case GL_INVALID_VALUE:
|
||||||
|
qDebug() << "A numeric argument is out of range.The offending command is ignored and has no other side effect than to set the error flag";
|
||||||
|
break;
|
||||||
|
case GL_INVALID_OPERATION:
|
||||||
|
qDebug() << "The specified operation is not allowed in the current state.The offending command is ignored and has no other side effect than to set the error flag..";
|
||||||
|
break;
|
||||||
|
case GL_INVALID_FRAMEBUFFER_OPERATION:
|
||||||
|
qDebug() << "The framebuffer object is not complete.The offending command is ignored and has no other side effect than to set the error flag.";
|
||||||
|
break;
|
||||||
|
case GL_OUT_OF_MEMORY:
|
||||||
|
qDebug() << "There is not enough memory left to execute the command.The state of the GL is undefined, except for the state of the error flags, after this error is recorded.";
|
||||||
|
break;
|
||||||
|
case GL_STACK_UNDERFLOW:
|
||||||
|
qDebug() << "An attempt has been made to perform an operation that would cause an internal stack to underflow.";
|
||||||
|
break;
|
||||||
|
case GL_STACK_OVERFLOW:
|
||||||
|
qDebug() << "An attempt has been made to perform an operation that would cause an internal stack to overflow.";
|
||||||
|
break;
|
||||||
|
}
|
||||||
|
}
|
||||||
|
}
|
||||||
|
|
||||||
|
|
||||||
|
// TODO: As long as we have gl calls explicitely issued from interface
|
||||||
|
// code, we need to be able to record and batch these calls. THe long
|
||||||
|
// term strategy is to get rid of any GL calls in favor of the HIFI GPU API
|
||||||
|
|
||||||
|
//#define ADD_COMMAND(call) _commands.push_back(COMMAND_##call); _commandCalls.push_back(&gpu::Batch::do_##call); _commandOffsets.push_back(_params.size());
|
||||||
|
#define ADD_COMMAND(call) _commands.push_back(COMMAND_##call); _commandOffsets.push_back(_params.size());
|
||||||
|
//#define ADD_COMMAND_GL(call) _commands.push_back(COMMAND_##call); _commandCalls.push_back(&gpu::GLBackend::do_##call); _commandOffsets.push_back(_params.size());
|
||||||
|
#define ADD_COMMAND_GL(call) _commands.push_back(COMMAND_##call); _commandOffsets.push_back(_params.size());
|
||||||
|
|
||||||
|
//#define DO_IT_NOW(call, offset) runLastCommand();
|
||||||
|
#define DO_IT_NOW(call, offset)
|
||||||
|
|
||||||
|
//#define CHECK_GL_ERROR() ::gpu::backend::checkGLError()
|
||||||
|
#define CHECK_GL_ERROR()
|
||||||
|
|
||||||
|
void Batch::_glEnable(GLenum cap) {
|
||||||
|
ADD_COMMAND(glEnable);
|
||||||
|
|
||||||
|
_params.push_back(cap);
|
||||||
|
|
||||||
|
DO_IT_NOW(_glEnable, 1);
|
||||||
|
}
|
||||||
|
void GLBackend::do_glEnable(Batch& batch, uint32 paramOffset) {
|
||||||
|
glEnable(batch._params[paramOffset]._uint);
|
||||||
|
CHECK_GL_ERROR();
|
||||||
|
}
|
||||||
|
|
||||||
|
void Batch::_glDisable(GLenum cap) {
|
||||||
|
ADD_COMMAND(glDisable);
|
||||||
|
|
||||||
|
_params.push_back(cap);
|
||||||
|
|
||||||
|
DO_IT_NOW(_glDisable, 1);
|
||||||
|
}
|
||||||
|
void GLBackend::do_glDisable(Batch& batch, uint32 paramOffset) {
|
||||||
|
glDisable(batch._params[paramOffset]._uint);
|
||||||
|
CHECK_GL_ERROR();
|
||||||
|
}
|
||||||
|
|
||||||
|
void Batch::_glEnableClientState(GLenum array) {
|
||||||
|
ADD_COMMAND(glEnableClientState);
|
||||||
|
|
||||||
|
_params.push_back(array);
|
||||||
|
|
||||||
|
DO_IT_NOW(_glEnableClientState, 1);
|
||||||
|
}
|
||||||
|
void GLBackend::do_glEnableClientState(Batch& batch, uint32 paramOffset) {
|
||||||
|
glEnableClientState(batch._params[paramOffset]._uint);
|
||||||
|
CHECK_GL_ERROR();
|
||||||
|
}
|
||||||
|
|
||||||
|
void Batch::_glDisableClientState(GLenum array) {
|
||||||
|
ADD_COMMAND(glDisableClientState);
|
||||||
|
|
||||||
|
_params.push_back(array);
|
||||||
|
|
||||||
|
DO_IT_NOW(_glDisableClientState, 1);
|
||||||
|
}
|
||||||
|
void GLBackend::do_glDisableClientState(Batch& batch, uint32 paramOffset) {
|
||||||
|
glDisableClientState(batch._params[paramOffset]._uint);
|
||||||
|
CHECK_GL_ERROR();
|
||||||
|
}
|
||||||
|
|
||||||
|
void Batch::_glCullFace(GLenum mode) {
|
||||||
|
ADD_COMMAND(glCullFace);
|
||||||
|
|
||||||
|
_params.push_back(mode);
|
||||||
|
|
||||||
|
DO_IT_NOW(_glCullFace, 1);
|
||||||
|
}
|
||||||
|
void GLBackend::do_glCullFace(Batch& batch, uint32 paramOffset) {
|
||||||
|
glCullFace(batch._params[paramOffset]._uint);
|
||||||
|
CHECK_GL_ERROR();
|
||||||
|
}
|
||||||
|
|
||||||
|
void Batch::_glAlphaFunc(GLenum func, GLclampf ref) {
|
||||||
|
ADD_COMMAND(glAlphaFunc);
|
||||||
|
|
||||||
|
_params.push_back(ref);
|
||||||
|
_params.push_back(func);
|
||||||
|
|
||||||
|
DO_IT_NOW(_glAlphaFunc, 2);
|
||||||
|
}
|
||||||
|
void GLBackend::do_glAlphaFunc(Batch& batch, uint32 paramOffset) {
|
||||||
|
glAlphaFunc(
|
||||||
|
batch._params[paramOffset + 1]._uint,
|
||||||
|
batch._params[paramOffset + 0]._float);
|
||||||
|
CHECK_GL_ERROR();
|
||||||
|
}
|
||||||
|
|
||||||
|
void Batch::_glDepthFunc(GLenum func) {
|
||||||
|
ADD_COMMAND(glDepthFunc);
|
||||||
|
|
||||||
|
_params.push_back(func);
|
||||||
|
|
||||||
|
DO_IT_NOW(_glDepthFunc, 1);
|
||||||
|
}
|
||||||
|
void GLBackend::do_glDepthFunc(Batch& batch, uint32 paramOffset) {
|
||||||
|
glDepthFunc(batch._params[paramOffset]._uint);
|
||||||
|
CHECK_GL_ERROR();
|
||||||
|
}
|
||||||
|
|
||||||
|
void Batch::_glDepthMask(GLboolean flag) {
|
||||||
|
ADD_COMMAND(glDepthMask);
|
||||||
|
|
||||||
|
_params.push_back(flag);
|
||||||
|
|
||||||
|
DO_IT_NOW(_glDepthMask, 1);
|
||||||
|
}
|
||||||
|
void GLBackend::do_glDepthMask(Batch& batch, uint32 paramOffset) {
|
||||||
|
glDepthMask(batch._params[paramOffset]._uint);
|
||||||
|
CHECK_GL_ERROR();
|
||||||
|
}
|
||||||
|
|
||||||
|
void Batch::_glDepthRange(GLclampd zNear, GLclampd zFar) {
|
||||||
|
ADD_COMMAND(glDepthRange);
|
||||||
|
|
||||||
|
_params.push_back(zFar);
|
||||||
|
_params.push_back(zNear);
|
||||||
|
|
||||||
|
DO_IT_NOW(_glDepthRange, 2);
|
||||||
|
}
|
||||||
|
void GLBackend::do_glDepthRange(Batch& batch, uint32 paramOffset) {
|
||||||
|
glDepthRange(
|
||||||
|
batch._params[paramOffset + 1]._double,
|
||||||
|
batch._params[paramOffset + 0]._double);
|
||||||
|
CHECK_GL_ERROR();
|
||||||
|
}
|
||||||
|
|
||||||
|
void Batch::_glBindBuffer(GLenum target, GLuint buffer) {
|
||||||
|
ADD_COMMAND(glBindBuffer);
|
||||||
|
|
||||||
|
_params.push_back(buffer);
|
||||||
|
_params.push_back(target);
|
||||||
|
|
||||||
|
DO_IT_NOW(_glBindBuffer, 2);
|
||||||
|
}
|
||||||
|
void GLBackend::do_glBindBuffer(Batch& batch, uint32 paramOffset) {
|
||||||
|
glBindBuffer(
|
||||||
|
batch._params[paramOffset + 1]._uint,
|
||||||
|
batch._params[paramOffset + 0]._uint);
|
||||||
|
CHECK_GL_ERROR();
|
||||||
|
}
|
||||||
|
|
||||||
|
void Batch::_glBindTexture(GLenum target, GLuint texture) {
|
||||||
|
ADD_COMMAND(glBindTexture);
|
||||||
|
|
||||||
|
_params.push_back(texture);
|
||||||
|
_params.push_back(target);
|
||||||
|
|
||||||
|
DO_IT_NOW(_glBindTexture, 2);
|
||||||
|
}
|
||||||
|
void GLBackend::do_glBindTexture(Batch& batch, uint32 paramOffset) {
|
||||||
|
glBindTexture(
|
||||||
|
batch._params[paramOffset + 1]._uint,
|
||||||
|
batch._params[paramOffset + 0]._uint);
|
||||||
|
CHECK_GL_ERROR();
|
||||||
|
}
|
||||||
|
|
||||||
|
void Batch::_glActiveTexture(GLenum texture) {
|
||||||
|
ADD_COMMAND(glActiveTexture);
|
||||||
|
|
||||||
|
_params.push_back(texture);
|
||||||
|
|
||||||
|
DO_IT_NOW(_glActiveTexture, 1);
|
||||||
|
}
|
||||||
|
void GLBackend::do_glActiveTexture(Batch& batch, uint32 paramOffset) {
|
||||||
|
glActiveTexture(batch._params[paramOffset]._uint);
|
||||||
|
CHECK_GL_ERROR();
|
||||||
|
}
|
||||||
|
|
||||||
|
void Batch::_glDrawBuffers(GLsizei n, const GLenum* bufs) {
|
||||||
|
ADD_COMMAND(glDrawBuffers);
|
||||||
|
|
||||||
|
_params.push_back(cacheData(n * sizeof(GLenum), bufs));
|
||||||
|
_params.push_back(n);
|
||||||
|
|
||||||
|
DO_IT_NOW(_glDrawBuffers, 2);
|
||||||
|
}
|
||||||
|
void GLBackend::do_glDrawBuffers(Batch& batch, uint32 paramOffset) {
|
||||||
|
glDrawBuffers(
|
||||||
|
batch._params[paramOffset + 1]._uint,
|
||||||
|
(const GLenum*)batch.editData(batch._params[paramOffset + 0]._uint));
|
||||||
|
CHECK_GL_ERROR();
|
||||||
|
}
|
||||||
|
|
||||||
|
void Batch::_glUseProgram(GLuint program) {
|
||||||
|
ADD_COMMAND(glUseProgram);
|
||||||
|
|
||||||
|
_params.push_back(program);
|
||||||
|
|
||||||
|
DO_IT_NOW(_glUseProgram, 1);
|
||||||
|
}
|
||||||
|
void GLBackend::do_glUseProgram(Batch& batch, uint32 paramOffset) {
|
||||||
|
glUseProgram(batch._params[paramOffset]._uint);
|
||||||
|
CHECK_GL_ERROR();
|
||||||
|
}
|
||||||
|
|
||||||
|
void Batch::_glUniform1f(GLint location, GLfloat v0) {
|
||||||
|
ADD_COMMAND(glUniform1f);
|
||||||
|
|
||||||
|
_params.push_back(v0);
|
||||||
|
_params.push_back(location);
|
||||||
|
|
||||||
|
DO_IT_NOW(_glUniform1f, 1);
|
||||||
|
}
|
||||||
|
void GLBackend::do_glUniform1f(Batch& batch, uint32 paramOffset) {
|
||||||
|
glUniform1f(
|
||||||
|
batch._params[paramOffset + 1]._int,
|
||||||
|
batch._params[paramOffset + 0]._float);
|
||||||
|
CHECK_GL_ERROR();
|
||||||
|
}
|
||||||
|
|
||||||
|
void Batch::_glUniformMatrix4fv(GLint location, GLsizei count, GLboolean transpose, const GLfloat* value) {
|
||||||
|
ADD_COMMAND(glUniformMatrix4fv);
|
||||||
|
|
||||||
|
const int MATRIX4_SIZE = 16 * sizeof(float);
|
||||||
|
_params.push_back(cacheData(count * MATRIX4_SIZE, value));
|
||||||
|
_params.push_back(transpose);
|
||||||
|
_params.push_back(count);
|
||||||
|
_params.push_back(location);
|
||||||
|
|
||||||
|
DO_IT_NOW(_glUniformMatrix4fv, 4);
|
||||||
|
}
|
||||||
|
void GLBackend::do_glUniformMatrix4fv(Batch& batch, uint32 paramOffset) {
|
||||||
|
glUniformMatrix4fv(
|
||||||
|
batch._params[paramOffset + 3]._int,
|
||||||
|
batch._params[paramOffset + 2]._uint,
|
||||||
|
batch._params[paramOffset + 1]._uint,
|
||||||
|
(const GLfloat*)batch.editData(batch._params[paramOffset + 0]._uint));
|
||||||
|
CHECK_GL_ERROR();
|
||||||
|
}
|
||||||
|
|
||||||
|
void Batch::_glMatrixMode(GLenum mode) {
|
||||||
|
ADD_COMMAND(glMatrixMode);
|
||||||
|
|
||||||
|
_params.push_back(mode);
|
||||||
|
|
||||||
|
DO_IT_NOW(_glMatrixMode, 1);
|
||||||
|
}
|
||||||
|
void GLBackend::do_glMatrixMode(Batch& batch, uint32 paramOffset) {
|
||||||
|
glMatrixMode(batch._params[paramOffset]._uint);
|
||||||
|
CHECK_GL_ERROR();
|
||||||
|
}
|
||||||
|
|
||||||
|
void Batch::_glPushMatrix() {
|
||||||
|
ADD_COMMAND(glPushMatrix);
|
||||||
|
|
||||||
|
DO_IT_NOW(_glPushMatrix, 0);
|
||||||
|
}
|
||||||
|
void GLBackend::do_glPushMatrix(Batch& batch, uint32 paramOffset) {
|
||||||
|
glPushMatrix();
|
||||||
|
CHECK_GL_ERROR();
|
||||||
|
}
|
||||||
|
|
||||||
|
void Batch::_glPopMatrix() {
|
||||||
|
ADD_COMMAND(glPopMatrix);
|
||||||
|
|
||||||
|
DO_IT_NOW(_glPopMatrix, 0);
|
||||||
|
}
|
||||||
|
void GLBackend::do_glPopMatrix(Batch& batch, uint32 paramOffset) {
|
||||||
|
glPopMatrix();
|
||||||
|
CHECK_GL_ERROR();
|
||||||
|
}
|
||||||
|
|
||||||
|
void Batch::_glMultMatrixf(const GLfloat *m) {
|
||||||
|
ADD_COMMAND(glMultMatrixf);
|
||||||
|
|
||||||
|
const int MATRIX4_SIZE = 16 * sizeof(float);
|
||||||
|
_params.push_back(cacheData(MATRIX4_SIZE, m));
|
||||||
|
|
||||||
|
DO_IT_NOW(_glMultMatrixf, 1);
|
||||||
|
}
|
||||||
|
void GLBackend::do_glMultMatrixf(Batch& batch, uint32 paramOffset) {
|
||||||
|
glMultMatrixf((const GLfloat*)batch.editData(batch._params[paramOffset]._uint));
|
||||||
|
CHECK_GL_ERROR();
|
||||||
|
}
|
||||||
|
|
||||||
|
void Batch::_glLoadMatrixf(const GLfloat *m) {
|
||||||
|
ADD_COMMAND(glLoadMatrixf);
|
||||||
|
|
||||||
|
const int MATRIX4_SIZE = 16 * sizeof(float);
|
||||||
|
_params.push_back(cacheData(MATRIX4_SIZE, m));
|
||||||
|
|
||||||
|
DO_IT_NOW(_glLoadMatrixf, 1);
|
||||||
|
}
|
||||||
|
void GLBackend::do_glLoadMatrixf(Batch& batch, uint32 paramOffset) {
|
||||||
|
glLoadMatrixf((const GLfloat*)batch.editData(batch._params[paramOffset]._uint));
|
||||||
|
CHECK_GL_ERROR();
|
||||||
|
}
|
||||||
|
|
||||||
|
void Batch::_glLoadIdentity(void) {
|
||||||
|
ADD_COMMAND(glLoadIdentity);
|
||||||
|
|
||||||
|
DO_IT_NOW(_glLoadIdentity, 0);
|
||||||
|
}
|
||||||
|
void GLBackend::do_glLoadIdentity(Batch& batch, uint32 paramOffset) {
|
||||||
|
glLoadIdentity();
|
||||||
|
CHECK_GL_ERROR();
|
||||||
|
}
|
||||||
|
|
||||||
|
void Batch::_glRotatef(GLfloat angle, GLfloat x, GLfloat y, GLfloat z) {
|
||||||
|
ADD_COMMAND(glRotatef);
|
||||||
|
|
||||||
|
_params.push_back(z);
|
||||||
|
_params.push_back(y);
|
||||||
|
_params.push_back(x);
|
||||||
|
_params.push_back(angle);
|
||||||
|
|
||||||
|
DO_IT_NOW(_glRotatef, 4);
|
||||||
|
}
|
||||||
|
void GLBackend::do_glRotatef(Batch& batch, uint32 paramOffset) {
|
||||||
|
glRotatef(
|
||||||
|
batch._params[paramOffset + 3]._float,
|
||||||
|
batch._params[paramOffset + 2]._float,
|
||||||
|
batch._params[paramOffset + 1]._float,
|
||||||
|
batch._params[paramOffset + 0]._float);
|
||||||
|
CHECK_GL_ERROR();
|
||||||
|
}
|
||||||
|
|
||||||
|
void Batch::_glScalef(GLfloat x, GLfloat y, GLfloat z) {
|
||||||
|
ADD_COMMAND(glScalef);
|
||||||
|
|
||||||
|
_params.push_back(z);
|
||||||
|
_params.push_back(y);
|
||||||
|
_params.push_back(x);
|
||||||
|
|
||||||
|
DO_IT_NOW(_glScalef, 3);
|
||||||
|
}
|
||||||
|
void GLBackend::do_glScalef(Batch& batch, uint32 paramOffset) {
|
||||||
|
glScalef(
|
||||||
|
batch._params[paramOffset + 2]._float,
|
||||||
|
batch._params[paramOffset + 1]._float,
|
||||||
|
batch._params[paramOffset + 0]._float);
|
||||||
|
CHECK_GL_ERROR();
|
||||||
|
}
|
||||||
|
|
||||||
|
void Batch::_glTranslatef(GLfloat x, GLfloat y, GLfloat z) {
|
||||||
|
ADD_COMMAND(glTranslatef);
|
||||||
|
|
||||||
|
_params.push_back(z);
|
||||||
|
_params.push_back(y);
|
||||||
|
_params.push_back(x);
|
||||||
|
|
||||||
|
DO_IT_NOW(_glTranslatef, 3);
|
||||||
|
}
|
||||||
|
void GLBackend::do_glTranslatef(Batch& batch, uint32 paramOffset) {
|
||||||
|
glTranslatef(
|
||||||
|
batch._params[paramOffset + 2]._float,
|
||||||
|
batch._params[paramOffset + 1]._float,
|
||||||
|
batch._params[paramOffset + 0]._float);
|
||||||
|
CHECK_GL_ERROR();
|
||||||
|
}
|
||||||
|
|
||||||
|
void Batch::_glDrawArrays(GLenum mode, GLint first, GLsizei count) {
|
||||||
|
ADD_COMMAND(glDrawArrays);
|
||||||
|
|
||||||
|
_params.push_back(count);
|
||||||
|
_params.push_back(first);
|
||||||
|
_params.push_back(mode);
|
||||||
|
|
||||||
|
DO_IT_NOW(_glDrawArrays, 3);
|
||||||
|
}
|
||||||
|
void GLBackend::do_glDrawArrays(Batch& batch, uint32 paramOffset) {
|
||||||
|
glDrawArrays(
|
||||||
|
batch._params[paramOffset + 2]._uint,
|
||||||
|
batch._params[paramOffset + 1]._int,
|
||||||
|
batch._params[paramOffset + 0]._int);
|
||||||
|
CHECK_GL_ERROR();
|
||||||
|
}
|
||||||
|
|
||||||
|
void Batch::_glDrawRangeElements(GLenum mode, GLuint start, GLuint end, GLsizei count, GLenum type, const void *indices) {
|
||||||
|
ADD_COMMAND(glDrawRangeElements);
|
||||||
|
|
||||||
|
_params.push_back(cacheResource(indices));
|
||||||
|
_params.push_back(type);
|
||||||
|
_params.push_back(count);
|
||||||
|
_params.push_back(end);
|
||||||
|
_params.push_back(start);
|
||||||
|
_params.push_back(mode);
|
||||||
|
|
||||||
|
DO_IT_NOW(_glDrawRangeElements, 6);
|
||||||
|
}
|
||||||
|
void GLBackend::do_glDrawRangeElements(Batch& batch, uint32 paramOffset) {
|
||||||
|
glDrawRangeElements(
|
||||||
|
batch._params[paramOffset + 5]._uint,
|
||||||
|
batch._params[paramOffset + 4]._uint,
|
||||||
|
batch._params[paramOffset + 3]._uint,
|
||||||
|
batch._params[paramOffset + 2]._int,
|
||||||
|
batch._params[paramOffset + 1]._uint,
|
||||||
|
batch.editResource(batch._params[paramOffset + 0]._uint)->_pointer);
|
||||||
|
CHECK_GL_ERROR();
|
||||||
|
}
|
||||||
|
|
||||||
|
void Batch::_glColorPointer(GLint size, GLenum type, GLsizei stride, const void *pointer) {
|
||||||
|
ADD_COMMAND(glColorPointer);
|
||||||
|
|
||||||
|
_params.push_back(cacheResource(pointer));
|
||||||
|
_params.push_back(stride);
|
||||||
|
_params.push_back(type);
|
||||||
|
_params.push_back(size);
|
||||||
|
|
||||||
|
DO_IT_NOW(_glColorPointer, 4);
|
||||||
|
}
|
||||||
|
void GLBackend::do_glColorPointer(Batch& batch, uint32 paramOffset) {
|
||||||
|
glColorPointer(
|
||||||
|
batch._params[paramOffset + 3]._int,
|
||||||
|
batch._params[paramOffset + 2]._uint,
|
||||||
|
batch._params[paramOffset + 1]._int,
|
||||||
|
batch.editResource(batch._params[paramOffset + 0]._uint)->_pointer);
|
||||||
|
CHECK_GL_ERROR();
|
||||||
|
}
|
||||||
|
|
||||||
|
void Batch::_glNormalPointer(GLenum type, GLsizei stride, const void *pointer) {
|
||||||
|
ADD_COMMAND(glNormalPointer);
|
||||||
|
|
||||||
|
_params.push_back(cacheResource(pointer));
|
||||||
|
_params.push_back(stride);
|
||||||
|
_params.push_back(type);
|
||||||
|
|
||||||
|
DO_IT_NOW(_glNormalPointer, 3);
|
||||||
|
}
|
||||||
|
void GLBackend::do_glNormalPointer(Batch& batch, uint32 paramOffset) {
|
||||||
|
glNormalPointer(
|
||||||
|
batch._params[paramOffset + 2]._uint,
|
||||||
|
batch._params[paramOffset + 1]._int,
|
||||||
|
batch.editResource(batch._params[paramOffset + 0]._uint)->_pointer);
|
||||||
|
CHECK_GL_ERROR();
|
||||||
|
}
|
||||||
|
|
||||||
|
void Batch::_glTexCoordPointer(GLint size, GLenum type, GLsizei stride, const void *pointer) {
|
||||||
|
ADD_COMMAND(glTexCoordPointer);
|
||||||
|
|
||||||
|
_params.push_back(cacheResource(pointer));
|
||||||
|
_params.push_back(stride);
|
||||||
|
_params.push_back(type);
|
||||||
|
_params.push_back(size);
|
||||||
|
|
||||||
|
DO_IT_NOW(_glTexCoordPointer, 4);
|
||||||
|
}
|
||||||
|
void GLBackend::do_glTexCoordPointer(Batch& batch, uint32 paramOffset) {
|
||||||
|
glTexCoordPointer(
|
||||||
|
batch._params[paramOffset + 3]._int,
|
||||||
|
batch._params[paramOffset + 2]._uint,
|
||||||
|
batch._params[paramOffset + 1]._int,
|
||||||
|
batch.editResource(batch._params[paramOffset + 0]._uint)->_pointer);
|
||||||
|
CHECK_GL_ERROR();
|
||||||
|
}
|
||||||
|
|
||||||
|
void Batch::_glVertexPointer(GLint size, GLenum type, GLsizei stride, const void *pointer) {
|
||||||
|
ADD_COMMAND(glVertexPointer);
|
||||||
|
|
||||||
|
_params.push_back(cacheResource(pointer));
|
||||||
|
_params.push_back(stride);
|
||||||
|
_params.push_back(type);
|
||||||
|
_params.push_back(size);
|
||||||
|
|
||||||
|
DO_IT_NOW(_glVertexPointer, 4);
|
||||||
|
}
|
||||||
|
void GLBackend::do_glVertexPointer(Batch& batch, uint32 paramOffset) {
|
||||||
|
glVertexPointer(
|
||||||
|
batch._params[paramOffset + 3]._int,
|
||||||
|
batch._params[paramOffset + 2]._uint,
|
||||||
|
batch._params[paramOffset + 1]._int,
|
||||||
|
batch.editResource(batch._params[paramOffset + 0]._uint)->_pointer);
|
||||||
|
CHECK_GL_ERROR();
|
||||||
|
}
|
||||||
|
|
||||||
|
|
||||||
|
void Batch::_glVertexAttribPointer(GLuint index, GLint size, GLenum type, GLboolean normalized, GLsizei stride, const void *pointer) {
|
||||||
|
ADD_COMMAND(glVertexAttribPointer);
|
||||||
|
|
||||||
|
_params.push_back(cacheResource(pointer));
|
||||||
|
_params.push_back(stride);
|
||||||
|
_params.push_back(normalized);
|
||||||
|
_params.push_back(type);
|
||||||
|
_params.push_back(size);
|
||||||
|
_params.push_back(index);
|
||||||
|
|
||||||
|
DO_IT_NOW(_glVertexAttribPointer, 6);
|
||||||
|
}
|
||||||
|
void GLBackend::do_glVertexAttribPointer(Batch& batch, uint32 paramOffset) {
|
||||||
|
glVertexAttribPointer(
|
||||||
|
batch._params[paramOffset + 5]._uint,
|
||||||
|
batch._params[paramOffset + 4]._int,
|
||||||
|
batch._params[paramOffset + 3]._uint,
|
||||||
|
batch._params[paramOffset + 2]._uint,
|
||||||
|
batch._params[paramOffset + 1]._int,
|
||||||
|
batch.editResource(batch._params[paramOffset + 0]._uint)->_pointer);
|
||||||
|
CHECK_GL_ERROR();
|
||||||
|
}
|
||||||
|
|
||||||
|
void Batch::_glEnableVertexAttribArray(GLint location) {
|
||||||
|
ADD_COMMAND(glEnableVertexAttribArray);
|
||||||
|
|
||||||
|
_params.push_back(location);
|
||||||
|
|
||||||
|
DO_IT_NOW(_glEnableVertexAttribArray, 1);
|
||||||
|
}
|
||||||
|
void GLBackend::do_glEnableVertexAttribArray(Batch& batch, uint32 paramOffset) {
|
||||||
|
glEnableVertexAttribArray(batch._params[paramOffset]._uint);
|
||||||
|
CHECK_GL_ERROR();
|
||||||
|
}
|
||||||
|
|
||||||
|
void Batch::_glDisableVertexAttribArray(GLint location) {
|
||||||
|
ADD_COMMAND(glDisableVertexAttribArray);
|
||||||
|
|
||||||
|
_params.push_back(location);
|
||||||
|
|
||||||
|
DO_IT_NOW(_glDisableVertexAttribArray, 1);
|
||||||
|
}
|
||||||
|
void GLBackend::do_glDisableVertexAttribArray(Batch& batch, uint32 paramOffset) {
|
||||||
|
glDisableVertexAttribArray(batch._params[paramOffset]._uint);
|
||||||
|
CHECK_GL_ERROR();
|
||||||
|
}
|
||||||
|
|
||||||
|
void Batch::_glColor4f(GLfloat red, GLfloat green, GLfloat blue, GLfloat alpha) {
|
||||||
|
ADD_COMMAND(glColor4f);
|
||||||
|
|
||||||
|
_params.push_back(alpha);
|
||||||
|
_params.push_back(blue);
|
||||||
|
_params.push_back(green);
|
||||||
|
_params.push_back(red);
|
||||||
|
|
||||||
|
DO_IT_NOW(_glColor4f, 4);
|
||||||
|
}
|
||||||
|
void GLBackend::do_glColor4f(Batch& batch, uint32 paramOffset) {
|
||||||
|
glColor4f(
|
||||||
|
batch._params[paramOffset + 3]._float,
|
||||||
|
batch._params[paramOffset + 2]._float,
|
||||||
|
batch._params[paramOffset + 1]._float,
|
||||||
|
batch._params[paramOffset + 0]._float);
|
||||||
|
CHECK_GL_ERROR();
|
||||||
|
}
|
||||||
|
|
||||||
|
void Batch::_glMaterialf(GLenum face, GLenum pname, GLfloat param) {
|
||||||
|
ADD_COMMAND(glMaterialf);
|
||||||
|
|
||||||
|
_params.push_back(param);
|
||||||
|
_params.push_back(pname);
|
||||||
|
_params.push_back(face);
|
||||||
|
|
||||||
|
DO_IT_NOW(_glMaterialf, 3);
|
||||||
|
}
|
||||||
|
void GLBackend::do_glMaterialf(Batch& batch, uint32 paramOffset) {
|
||||||
|
glMaterialf(
|
||||||
|
batch._params[paramOffset + 2]._uint,
|
||||||
|
batch._params[paramOffset + 1]._uint,
|
||||||
|
batch._params[paramOffset + 0]._float);
|
||||||
|
CHECK_GL_ERROR();
|
||||||
|
}
|
||||||
|
|
||||||
|
void Batch::_glMaterialfv(GLenum face, GLenum pname, const GLfloat *params) {
|
||||||
|
ADD_COMMAND(glMaterialfv);
|
||||||
|
|
||||||
|
_params.push_back(cacheData(4 * sizeof(float), params));
|
||||||
|
_params.push_back(pname);
|
||||||
|
_params.push_back(face);
|
||||||
|
|
||||||
|
DO_IT_NOW(_glMaterialfv, 3);
|
||||||
|
}
|
||||||
|
void GLBackend::do_glMaterialfv(Batch& batch, uint32 paramOffset) {
|
||||||
|
glMaterialfv(
|
||||||
|
batch._params[paramOffset + 2]._uint,
|
||||||
|
batch._params[paramOffset + 1]._uint,
|
||||||
|
(const GLfloat*)batch.editData(batch._params[paramOffset + 0]._uint));
|
||||||
|
CHECK_GL_ERROR();
|
||||||
|
}
|
||||||
|
|
||||||
|
GLBackend::GLBuffer::GLBuffer() :
|
||||||
|
_stamp(0),
|
||||||
|
_buffer(0),
|
||||||
|
_size(0)
|
||||||
|
{}
|
||||||
|
|
||||||
|
GLBackend::GLBuffer::~GLBuffer() {
|
||||||
|
if (_buffer != 0) {
|
||||||
|
glDeleteBuffers(1, &_buffer);
|
||||||
|
}
|
||||||
|
}
|
||||||
|
|
||||||
|
void GLBackend::syncGPUObject(const Buffer& buffer) {
|
||||||
|
GLBuffer* object = Backend::getGPUObject<GLBackend::GLBuffer>(buffer);
|
||||||
|
|
||||||
|
if (object && (object->_stamp == buffer.getSysmem().getStamp())) {
|
||||||
|
return;
|
||||||
|
}
|
||||||
|
|
||||||
|
// need to have a gpu object?
|
||||||
|
if (!object) {
|
||||||
|
object = new GLBuffer();
|
||||||
|
glGenBuffers(1, &object->_buffer);
|
||||||
|
Backend::setGPUObject(buffer, object);
|
||||||
|
}
|
||||||
|
|
||||||
|
// Now let's update the content of the bo with the sysmem version
|
||||||
|
// TODO: in the future, be smarter about when to actually upload the glBO version based on the data that did change
|
||||||
|
//if () {
|
||||||
|
glBindBuffer(GL_ARRAY_BUFFER, object->_buffer);
|
||||||
|
glBufferData(GL_ARRAY_BUFFER, buffer.getSysmem().getSize(), buffer.getSysmem().readData(), GL_DYNAMIC_DRAW);
|
||||||
|
glBindBuffer(GL_ARRAY_BUFFER, 0);
|
||||||
|
object->_stamp = buffer.getSysmem().getStamp();
|
||||||
|
object->_size = buffer.getSysmem().getSize();
|
||||||
|
//}
|
||||||
|
}
|
||||||
|
|
||||||
|
|
||||||
|
|
||||||
|
GLuint GLBackend::getBufferID(const Buffer& buffer) {
|
||||||
|
GLBackend::syncGPUObject(buffer);
|
||||||
|
return Backend::getGPUObject<GLBackend::GLBuffer>(buffer)->_buffer;
|
||||||
|
}
|
110
interface/src/gpu/GLBackend.h
Normal file
110
interface/src/gpu/GLBackend.h
Normal file
|
@ -0,0 +1,110 @@
|
||||||
|
//
|
||||||
|
// GLBackend.h
|
||||||
|
// interface/src/gpu
|
||||||
|
//
|
||||||
|
// Created by Sam Gateau on 10/27/2014.
|
||||||
|
// Copyright 2014 High Fidelity, Inc.
|
||||||
|
//
|
||||||
|
// Distributed under the Apache License, Version 2.0.
|
||||||
|
// See the accompanying file LICENSE or http://www.apache.org/licenses/LICENSE-2.0.html
|
||||||
|
//
|
||||||
|
#ifndef hifi_gpu_GLBackend_h
|
||||||
|
#define hifi_gpu_GLBackend_h
|
||||||
|
|
||||||
|
#include <assert.h>
|
||||||
|
#include "InterfaceConfig.h"
|
||||||
|
|
||||||
|
#include "gpu/Context.h"
|
||||||
|
#include "gpu/Batch.h"
|
||||||
|
|
||||||
|
namespace gpu {
|
||||||
|
|
||||||
|
class GLBackend : public Backend {
|
||||||
|
public:
|
||||||
|
|
||||||
|
GLBackend();
|
||||||
|
~GLBackend();
|
||||||
|
|
||||||
|
static void renderBatch(Batch& batch);
|
||||||
|
|
||||||
|
static void checkGLError();
|
||||||
|
|
||||||
|
|
||||||
|
class GLBuffer {
|
||||||
|
public:
|
||||||
|
Stamp _stamp;
|
||||||
|
GLuint _buffer;
|
||||||
|
GLuint _size;
|
||||||
|
|
||||||
|
GLBuffer();
|
||||||
|
~GLBuffer();
|
||||||
|
};
|
||||||
|
static void syncGPUObject(const Buffer& buffer);
|
||||||
|
|
||||||
|
static GLuint getBufferID(const Buffer& buffer);
|
||||||
|
|
||||||
|
protected:
|
||||||
|
|
||||||
|
// TODO: As long as we have gl calls explicitely issued from interface
|
||||||
|
// code, we need to be able to record and batch these calls. THe long
|
||||||
|
// term strategy is to get rid of any GL calls in favor of the HIFI GPU API
|
||||||
|
void do_glEnable(Batch& batch, uint32 paramOffset);
|
||||||
|
void do_glDisable(Batch& batch, uint32 paramOffset);
|
||||||
|
|
||||||
|
void do_glEnableClientState(Batch& batch, uint32 paramOffset);
|
||||||
|
void do_glDisableClientState(Batch& batch, uint32 paramOffset);
|
||||||
|
|
||||||
|
void do_glCullFace(Batch& batch, uint32 paramOffset);
|
||||||
|
void do_glAlphaFunc(Batch& batch, uint32 paramOffset);
|
||||||
|
|
||||||
|
void do_glDepthFunc(Batch& batch, uint32 paramOffset);
|
||||||
|
void do_glDepthMask(Batch& batch, uint32 paramOffset);
|
||||||
|
void do_glDepthRange(Batch& batch, uint32 paramOffset);
|
||||||
|
|
||||||
|
void do_glBindBuffer(Batch& batch, uint32 paramOffset);
|
||||||
|
|
||||||
|
void do_glBindTexture(Batch& batch, uint32 paramOffset);
|
||||||
|
void do_glActiveTexture(Batch& batch, uint32 paramOffset);
|
||||||
|
|
||||||
|
void do_glDrawBuffers(Batch& batch, uint32 paramOffset);
|
||||||
|
|
||||||
|
void do_glUseProgram(Batch& batch, uint32 paramOffset);
|
||||||
|
void do_glUniform1f(Batch& batch, uint32 paramOffset);
|
||||||
|
void do_glUniformMatrix4fv(Batch& batch, uint32 paramOffset);
|
||||||
|
|
||||||
|
void do_glMatrixMode(Batch& batch, uint32 paramOffset);
|
||||||
|
void do_glPushMatrix(Batch& batch, uint32 paramOffset);
|
||||||
|
void do_glPopMatrix(Batch& batch, uint32 paramOffset);
|
||||||
|
void do_glMultMatrixf(Batch& batch, uint32 paramOffset);
|
||||||
|
void do_glLoadMatrixf(Batch& batch, uint32 paramOffset);
|
||||||
|
void do_glLoadIdentity(Batch& batch, uint32 paramOffset);
|
||||||
|
void do_glRotatef(Batch& batch, uint32 paramOffset);
|
||||||
|
void do_glScalef(Batch& batch, uint32 paramOffset);
|
||||||
|
void do_glTranslatef(Batch& batch, uint32 paramOffset);
|
||||||
|
|
||||||
|
void do_glDrawArrays(Batch& batch, uint32 paramOffset);
|
||||||
|
void do_glDrawRangeElements(Batch& batch, uint32 paramOffset);
|
||||||
|
|
||||||
|
void do_glColorPointer(Batch& batch, uint32 paramOffset);
|
||||||
|
void do_glNormalPointer(Batch& batch, uint32 paramOffset);
|
||||||
|
void do_glTexCoordPointer(Batch& batch, uint32 paramOffset);
|
||||||
|
void do_glVertexPointer(Batch& batch, uint32 paramOffset);
|
||||||
|
|
||||||
|
void do_glVertexAttribPointer(Batch& batch, uint32 paramOffset);
|
||||||
|
void do_glEnableVertexAttribArray(Batch& batch, uint32 paramOffset);
|
||||||
|
void do_glDisableVertexAttribArray(Batch& batch, uint32 paramOffset);
|
||||||
|
|
||||||
|
void do_glColor4f(Batch& batch, uint32 paramOffset);
|
||||||
|
|
||||||
|
void do_glMaterialf(Batch& batch, uint32 paramOffset);
|
||||||
|
void do_glMaterialfv(Batch& batch, uint32 paramOffset);
|
||||||
|
|
||||||
|
typedef void (GLBackend::*CommandCall)(Batch&, uint32);
|
||||||
|
static CommandCall _commandCalls[Batch::NUM_COMMANDS];
|
||||||
|
|
||||||
|
};
|
||||||
|
|
||||||
|
|
||||||
|
};
|
||||||
|
|
||||||
|
#endif
|
|
@ -182,39 +182,3 @@ Buffer::Size Buffer::append(Size size, const Byte* data) {
|
||||||
return editSysmem().append( size, data);
|
return editSysmem().append( size, data);
|
||||||
}
|
}
|
||||||
|
|
||||||
namespace gpu {
|
|
||||||
namespace backend {
|
|
||||||
|
|
||||||
BufferObject::~BufferObject() {
|
|
||||||
if (_buffer!=0) {
|
|
||||||
glDeleteBuffers(1, &_buffer);
|
|
||||||
}
|
|
||||||
}
|
|
||||||
|
|
||||||
void syncGPUObject(const Buffer& buffer) {
|
|
||||||
BufferObject* object = buffer.getGPUObject();
|
|
||||||
|
|
||||||
if (object && (object->_stamp == buffer.getSysmem().getStamp())) {
|
|
||||||
return;
|
|
||||||
}
|
|
||||||
|
|
||||||
// need to have a gpu object?
|
|
||||||
if (!object) {
|
|
||||||
object = new BufferObject();
|
|
||||||
glGenBuffers(1, &object->_buffer);
|
|
||||||
buffer.setGPUObject(object);
|
|
||||||
}
|
|
||||||
|
|
||||||
// Now let's update the content of the bo with the sysmem version
|
|
||||||
// TODO: in the future, be smarter about when to actually upload the glBO version based on the data that did change
|
|
||||||
//if () {
|
|
||||||
glBindBuffer(GL_ARRAY_BUFFER, object->_buffer);
|
|
||||||
glBufferData(GL_ARRAY_BUFFER, buffer.getSysmem().getSize(), buffer.getSysmem().readData(), GL_DYNAMIC_DRAW);
|
|
||||||
glBindBuffer(GL_ARRAY_BUFFER, 0);
|
|
||||||
object->_stamp = buffer.getSysmem().getStamp();
|
|
||||||
object->_size = buffer.getSysmem().getSize();
|
|
||||||
//}
|
|
||||||
}
|
|
||||||
|
|
||||||
};
|
|
||||||
};
|
|
||||||
|
|
|
@ -14,31 +14,13 @@
|
||||||
#include <assert.h>
|
#include <assert.h>
|
||||||
#include "InterfaceConfig.h"
|
#include "InterfaceConfig.h"
|
||||||
|
|
||||||
|
|
||||||
namespace gpu {
|
namespace gpu {
|
||||||
|
|
||||||
class Buffer;
|
class GPUObject;
|
||||||
|
|
||||||
typedef int Stamp;
|
typedef int Stamp;
|
||||||
|
|
||||||
// TODO: move the backend namespace into dedicated files, for now we keep it close to the gpu objects definition for convenience
|
|
||||||
namespace backend {
|
|
||||||
|
|
||||||
class BufferObject {
|
|
||||||
public:
|
|
||||||
Stamp _stamp;
|
|
||||||
GLuint _buffer;
|
|
||||||
GLuint _size;
|
|
||||||
|
|
||||||
BufferObject() :
|
|
||||||
_stamp(0),
|
|
||||||
_buffer(0),
|
|
||||||
_size(0)
|
|
||||||
{}
|
|
||||||
|
|
||||||
~BufferObject();
|
|
||||||
};
|
|
||||||
void syncGPUObject(const Buffer& buffer);
|
|
||||||
};
|
|
||||||
|
|
||||||
class Resource {
|
class Resource {
|
||||||
public:
|
public:
|
||||||
typedef unsigned char Byte;
|
typedef unsigned char Byte;
|
||||||
|
@ -121,8 +103,8 @@ public:
|
||||||
~Buffer();
|
~Buffer();
|
||||||
|
|
||||||
// The size in bytes of data stored in the buffer
|
// The size in bytes of data stored in the buffer
|
||||||
inline Size getSize() const { return getSysmem().getSize(); }
|
Size getSize() const { return getSysmem().getSize(); }
|
||||||
inline const Byte* getData() const { return getSysmem().readData(); }
|
const Byte* getData() const { return getSysmem().readData(); }
|
||||||
|
|
||||||
// Resize the buffer
|
// Resize the buffer
|
||||||
// Keep previous data [0 to min(pSize, mSize)]
|
// Keep previous data [0 to min(pSize, mSize)]
|
||||||
|
@ -141,26 +123,26 @@ public:
|
||||||
// \return the number of bytes copied
|
// \return the number of bytes copied
|
||||||
Size append(Size size, const Byte* data);
|
Size append(Size size, const Byte* data);
|
||||||
|
|
||||||
// this is a temporary hack so the current rendering code can access the underneath gl Buffer Object
|
// Access the sysmem object.
|
||||||
// TODO: remove asap, when the backend is doing more of the gl features
|
const Sysmem& getSysmem() const { assert(_sysmem); return (*_sysmem); }
|
||||||
inline GLuint getGLBufferObject() const { backend::syncGPUObject(*this); return getGPUObject()->_buffer; }
|
|
||||||
|
|
||||||
protected:
|
protected:
|
||||||
|
|
||||||
Sysmem* _sysmem;
|
Sysmem* _sysmem;
|
||||||
|
|
||||||
typedef backend::BufferObject GPUObject;
|
mutable GPUObject* _gpuObject;
|
||||||
mutable backend::BufferObject* _gpuObject;
|
|
||||||
|
|
||||||
inline const Sysmem& getSysmem() const { assert(_sysmem); return (*_sysmem); }
|
Sysmem& editSysmem() { assert(_sysmem); return (*_sysmem); }
|
||||||
inline Sysmem& editSysmem() { assert(_sysmem); return (*_sysmem); }
|
|
||||||
|
|
||||||
inline GPUObject* getGPUObject() const { return _gpuObject; }
|
// This shouldn't be used by anything else than the Backend class with the proper casting.
|
||||||
inline void setGPUObject(GPUObject* gpuObject) const { _gpuObject = gpuObject; }
|
void setGPUObject(GPUObject* gpuObject) const { _gpuObject = gpuObject; }
|
||||||
|
GPUObject* getGPUObject() const { return _gpuObject; }
|
||||||
|
|
||||||
friend void backend::syncGPUObject(const Buffer& buffer);
|
friend class Backend;
|
||||||
};
|
};
|
||||||
|
|
||||||
};
|
};
|
||||||
|
|
||||||
|
|
||||||
#endif
|
#endif
|
||||||
|
|
|
@ -27,6 +27,7 @@
|
||||||
#include "Model.h"
|
#include "Model.h"
|
||||||
|
|
||||||
#include "gpu/Batch.h"
|
#include "gpu/Batch.h"
|
||||||
|
#include "gpu/GLBackend.h"
|
||||||
#define GLBATCH( call ) batch._##call
|
#define GLBATCH( call ) batch._##call
|
||||||
//#define GLBATCH( call ) call
|
//#define GLBATCH( call ) call
|
||||||
|
|
||||||
|
@ -578,7 +579,7 @@ bool Model::render(float alpha, RenderMode mode, RenderArgs* args) {
|
||||||
// Render!
|
// Render!
|
||||||
{
|
{
|
||||||
PROFILE_RANGE("render Batch");
|
PROFILE_RANGE("render Batch");
|
||||||
::gpu::backend::renderBatch(batch);
|
::gpu::GLBackend::renderBatch(batch);
|
||||||
batch.clear();
|
batch.clear();
|
||||||
}
|
}
|
||||||
|
|
||||||
|
|
|
@ -24,6 +24,8 @@
|
||||||
#include "glm/glm.hpp"
|
#include "glm/glm.hpp"
|
||||||
#include <glm/gtc/matrix_transform.hpp>
|
#include <glm/gtc/matrix_transform.hpp>
|
||||||
|
|
||||||
|
#include "gpu/GLBackend.h"
|
||||||
|
|
||||||
|
|
||||||
// the width/height of the cached glyph textures
|
// the width/height of the cached glyph textures
|
||||||
const int IMAGE_SIZE = 256;
|
const int IMAGE_SIZE = 256;
|
||||||
|
@ -297,8 +299,8 @@ void TextRenderer::drawBatch() {
|
||||||
// TODO: Apply the correct font atlas texture, for now only one texture per TextRenderer so it should be good
|
// TODO: Apply the correct font atlas texture, for now only one texture per TextRenderer so it should be good
|
||||||
glBindTexture(GL_TEXTURE_2D, _currentTextureID);
|
glBindTexture(GL_TEXTURE_2D, _currentTextureID);
|
||||||
|
|
||||||
GLuint vbo = _glyphsBuffer.getGLBufferObject();
|
GLuint vbo = gpu::GLBackend::getBufferID(_glyphsBuffer);
|
||||||
GLuint colorvbo = _glyphsColorBuffer.getGLBufferObject();
|
GLuint colorvbo = gpu::GLBackend::getBufferID(_glyphsColorBuffer);
|
||||||
|
|
||||||
glEnableClientState(GL_VERTEX_ARRAY);
|
glEnableClientState(GL_VERTEX_ARRAY);
|
||||||
glEnableClientState(GL_TEXTURE_COORD_ARRAY);
|
glEnableClientState(GL_TEXTURE_COORD_ARRAY);
|
||||||
|
|
Loading…
Reference in a new issue