From d13283192fe41e8068e2e3c3303d514b7b00bf57 Mon Sep 17 00:00:00 2001 From: Sam Gateau Date: Wed, 22 Oct 2014 14:07:15 -0700 Subject: [PATCH 01/13] Fix the bug happening on mac due to order in which parmaeters are evaluated for all of the gl calls, now fixed with an order independant code --- interface/src/gpu/Batch.cpp | 301 ++++++++++++++++++++++--------- interface/src/gpu/Batch.h | 86 ++++----- interface/src/renderer/Model.cpp | 2 +- 3 files changed, 260 insertions(+), 129 deletions(-) diff --git a/interface/src/gpu/Batch.cpp b/interface/src/gpu/Batch.cpp index 8a094d1024..8b36ef8b33 100644 --- a/interface/src/gpu/Batch.cpp +++ b/interface/src/gpu/Batch.cpp @@ -17,6 +17,8 @@ //#define DO_IT_NOW(call, offset) runLastCommand(); #define DO_IT_NOW(call, offset) +#define CHECK_GL_ERROR() ::gpu::backend::checkGLError() + using namespace gpu; Batch::Batch() : @@ -158,8 +160,9 @@ void Batch::_glEnable(GLenum cap) { DO_IT_NOW(_glEnable, 1); } -void Batch::do_glEnable(uint32& paramOffset) { - glEnable(_params[paramOffset++]._uint); +void Batch::do_glEnable(uint32 paramOffset) { + glEnable(_params[paramOffset]._uint); + CHECK_GL_ERROR(); } void Batch::_glDisable(GLenum cap) { @@ -169,8 +172,9 @@ void Batch::_glDisable(GLenum cap) { DO_IT_NOW(_glDisable, 1); } -void Batch::do_glDisable(uint32& paramOffset) { - glDisable(_params[paramOffset++]._uint); +void Batch::do_glDisable(uint32 paramOffset) { + glDisable(_params[paramOffset]._uint); + CHECK_GL_ERROR(); } void Batch::_glEnableClientState(GLenum array) { @@ -180,8 +184,9 @@ void Batch::_glEnableClientState(GLenum array) { DO_IT_NOW(_glEnableClientState, 1 ); } -void Batch::do_glEnableClientState(uint32& paramOffset) { - glEnableClientState(_params[paramOffset++]._uint); +void Batch::do_glEnableClientState(uint32 paramOffset) { + glEnableClientState(_params[paramOffset]._uint); + CHECK_GL_ERROR(); } void Batch::_glDisableClientState(GLenum array) { @@ -191,8 +196,9 @@ void Batch::_glDisableClientState(GLenum array) { DO_IT_NOW(_glDisableClientState, 1); } -void Batch::do_glDisableClientState(uint32& paramOffset) { - glDisableClientState(_params[paramOffset++]._uint); +void Batch::do_glDisableClientState(uint32 paramOffset) { + glDisableClientState(_params[paramOffset]._uint); + CHECK_GL_ERROR(); } void Batch::_glCullFace(GLenum mode) { @@ -202,8 +208,9 @@ void Batch::_glCullFace(GLenum mode) { DO_IT_NOW(_glCullFace, 1); } -void Batch::do_glCullFace(uint32& paramOffset) { - glCullFace(_params[paramOffset++]._uint); +void Batch::do_glCullFace(uint32 paramOffset) { + glCullFace(_params[paramOffset]._uint); + CHECK_GL_ERROR(); } void Batch::_glAlphaFunc(GLenum func, GLclampf ref) { @@ -214,8 +221,11 @@ void Batch::_glAlphaFunc(GLenum func, GLclampf ref) { DO_IT_NOW(_glAlphaFunc, 2); } -void Batch::do_glAlphaFunc(uint32& paramOffset) { - glAlphaFunc(_params[paramOffset++]._uint, _params[paramOffset++]._float); +void Batch::do_glAlphaFunc(uint32 paramOffset) { + glAlphaFunc( + _params[paramOffset + 1]._uint, + _params[paramOffset + 0]._float); + CHECK_GL_ERROR(); } void Batch::_glDepthFunc(GLenum func) { @@ -225,8 +235,9 @@ void Batch::_glDepthFunc(GLenum func) { DO_IT_NOW(_glDepthFunc, 1); } -void Batch::do_glDepthFunc(uint32& paramOffset) { - glDepthFunc(_params[paramOffset++]._uint); +void Batch::do_glDepthFunc(uint32 paramOffset) { + glDepthFunc(_params[paramOffset]._uint); + CHECK_GL_ERROR(); } void Batch::_glDepthMask(GLboolean flag) { @@ -236,8 +247,9 @@ void Batch::_glDepthMask(GLboolean flag) { DO_IT_NOW(_glDepthMask, 1); } -void Batch::do_glDepthMask(uint32& paramOffset) { - glDepthMask(_params[paramOffset++]._uint); +void Batch::do_glDepthMask(uint32 paramOffset) { + glDepthMask(_params[paramOffset]._uint); + CHECK_GL_ERROR(); } void Batch::_glDepthRange(GLclampd zNear, GLclampd zFar) { @@ -248,8 +260,11 @@ void Batch::_glDepthRange(GLclampd zNear, GLclampd zFar) { DO_IT_NOW(_glDepthRange, 2); } -void Batch::do_glDepthRange(uint32& paramOffset) { - glDepthRange(_params[paramOffset++]._double, _params[paramOffset++]._double); +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) { @@ -260,8 +275,11 @@ void Batch::_glBindBuffer(GLenum target, GLuint buffer) { DO_IT_NOW(_glBindBuffer, 2); } -void Batch::do_glBindBuffer(uint32& paramOffset) { - glBindBuffer(_params[paramOffset++]._uint, _params[paramOffset++]._uint); +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) { @@ -272,8 +290,11 @@ void Batch::_glBindTexture(GLenum target, GLuint texture) { DO_IT_NOW(_glBindTexture, 2); } -void Batch::do_glBindTexture(uint32& paramOffset) { - glBindTexture(_params[paramOffset++]._uint, _params[paramOffset++]._uint); +void Batch::do_glBindTexture(uint32 paramOffset) { + glBindTexture( + _params[paramOffset + 1]._uint, + _params[paramOffset + 0]._uint); + CHECK_GL_ERROR(); } void Batch::_glActiveTexture(GLenum texture) { @@ -283,8 +304,9 @@ void Batch::_glActiveTexture(GLenum texture) { DO_IT_NOW(_glActiveTexture, 1); } -void Batch::do_glActiveTexture(uint32& paramOffset) { - glActiveTexture(_params[paramOffset++]._uint); +void Batch::do_glActiveTexture(uint32 paramOffset) { + glActiveTexture(_params[paramOffset]._uint); + CHECK_GL_ERROR(); } void Batch::_glDrawBuffers(GLsizei n, const GLenum* bufs) { @@ -295,8 +317,11 @@ void Batch::_glDrawBuffers(GLsizei n, const GLenum* bufs) { DO_IT_NOW(_glDrawBuffers, 2); } -void Batch::do_glDrawBuffers(uint32& paramOffset) { - glDrawBuffers(_params[paramOffset++]._uint, (const GLenum*) editData(_params[paramOffset++]._uint)); +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) { @@ -306,8 +331,9 @@ void Batch::_glUseProgram(GLuint program) { DO_IT_NOW(_glUseProgram, 1); } -void Batch::do_glUseProgram(uint32& paramOffset) { - glUseProgram(_params[paramOffset++]._uint); +void Batch::do_glUseProgram(uint32 paramOffset) { + glUseProgram(_params[paramOffset]._uint); + CHECK_GL_ERROR(); } void Batch::_glUniform1f(GLint location, GLfloat v0) { @@ -318,8 +344,11 @@ void Batch::_glUniform1f(GLint location, GLfloat v0) { DO_IT_NOW(_glUniform1f, 1); } -void Batch::do_glUniform1f(uint32& paramOffset) { - glUniform1f(_params[paramOffset++]._int, _params[paramOffset++]._float); +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) { @@ -333,9 +362,13 @@ void Batch::_glUniformMatrix4fv(GLint location, GLsizei count, GLboolean transpo DO_IT_NOW(_glUniformMatrix4fv, 4); } -void Batch::do_glUniformMatrix4fv(uint32& paramOffset) { - glUniformMatrix4fv(_params[paramOffset++]._int, _params[paramOffset++]._uint, - _params[paramOffset++]._uint, (const GLfloat*) editData(_params[paramOffset++]._uint)); +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) { @@ -345,8 +378,9 @@ void Batch::_glMatrixMode(GLenum mode) { DO_IT_NOW(_glMatrixMode, 1); } -void Batch::do_glMatrixMode(uint32& paramOffset) { - glMatrixMode(_params[paramOffset++]._uint); +void Batch::do_glMatrixMode(uint32 paramOffset) { + glMatrixMode(_params[paramOffset]._uint); + CHECK_GL_ERROR(); } void Batch::_glPushMatrix() { @@ -354,8 +388,9 @@ void Batch::_glPushMatrix() { DO_IT_NOW(_glPushMatrix, 0); } -void Batch::do_glPushMatrix(uint32& paramOffset) { +void Batch::do_glPushMatrix(uint32 paramOffset) { glPushMatrix(); + CHECK_GL_ERROR(); } void Batch::_glPopMatrix() { @@ -363,8 +398,9 @@ void Batch::_glPopMatrix() { DO_IT_NOW(_glPopMatrix, 0); } -void Batch::do_glPopMatrix(uint32& paramOffset) { +void Batch::do_glPopMatrix(uint32 paramOffset) { glPopMatrix(); + CHECK_GL_ERROR(); } void Batch::_glMultMatrixf(const GLfloat *m) { @@ -375,8 +411,9 @@ void Batch::_glMultMatrixf(const GLfloat *m) { DO_IT_NOW(_glMultMatrixf, 1); } -void Batch::do_glMultMatrixf(uint32& paramOffset) { - glMultMatrixf((const GLfloat*) editData(_params[paramOffset++]._uint)); +void Batch::do_glMultMatrixf(uint32 paramOffset) { + glMultMatrixf((const GLfloat*) editData(_params[paramOffset]._uint)); + CHECK_GL_ERROR(); } void Batch::_glLoadMatrixf(const GLfloat *m) { @@ -387,8 +424,9 @@ void Batch::_glLoadMatrixf(const GLfloat *m) { DO_IT_NOW(_glLoadMatrixf, 1); } -void Batch::do_glLoadMatrixf(uint32& paramOffset) { - glLoadMatrixf((const GLfloat*)editData(_params[paramOffset++]._uint)); +void Batch::do_glLoadMatrixf(uint32 paramOffset) { + glLoadMatrixf((const GLfloat*)editData(_params[paramOffset]._uint)); + CHECK_GL_ERROR(); } void Batch::_glLoadIdentity(void) { @@ -396,8 +434,9 @@ void Batch::_glLoadIdentity(void) { DO_IT_NOW(_glLoadIdentity, 0); } -void Batch::do_glLoadIdentity(uint32& paramOffset) { +void Batch::do_glLoadIdentity(uint32 paramOffset) { glLoadIdentity(); + CHECK_GL_ERROR(); } void Batch::_glRotatef(GLfloat angle, GLfloat x, GLfloat y, GLfloat z) { @@ -410,8 +449,13 @@ void Batch::_glRotatef(GLfloat angle, GLfloat x, GLfloat y, GLfloat z) { DO_IT_NOW(_glRotatef, 4); } -void Batch::do_glRotatef(uint32& paramOffset) { - glRotatef(_params[paramOffset++]._float, _params[paramOffset++]._float, _params[paramOffset++]._float, _params[paramOffset++]._float); +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) { @@ -423,8 +467,12 @@ void Batch::_glScalef(GLfloat x, GLfloat y, GLfloat z) { DO_IT_NOW(_glScalef, 3); } -void Batch::do_glScalef(uint32& paramOffset) { - glScalef(_params[paramOffset++]._float, _params[paramOffset++]._float, _params[paramOffset++]._float); +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) { @@ -436,8 +484,12 @@ void Batch::_glTranslatef(GLfloat x, GLfloat y, GLfloat z) { DO_IT_NOW(_glTranslatef, 3); } -void Batch::do_glTranslatef(uint32& paramOffset) { - glTranslatef(_params[paramOffset++]._float, _params[paramOffset++]._float, _params[paramOffset++]._float); +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) { @@ -449,8 +501,12 @@ void Batch::_glDrawArrays(GLenum mode, GLint first, GLsizei count) { DO_IT_NOW(_glDrawArrays, 3); } -void Batch::do_glDrawArrays(uint32& paramOffset) { - glDrawArrays(_params[paramOffset++]._uint, _params[paramOffset++]._int, _params[paramOffset++]._int); +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) { @@ -463,14 +519,17 @@ void Batch::_glDrawRangeElements(GLenum mode, GLuint start, GLuint end, GLsizei _params.push_back(start); _params.push_back(mode); - //do_glDrawRangeElements(_commandOffsets.back()); - // runCommand(_commands.size() - 1); DO_IT_NOW(_glDrawRangeElements, 6); } -void Batch::do_glDrawRangeElements(uint32& paramOffset) { - glDrawRangeElements(_params[paramOffset++]._uint, _params[paramOffset++]._uint, - _params[paramOffset++]._uint, _params[paramOffset++]._int, - _params[paramOffset++]._uint, editResource(_params[paramOffset++]._uint)->_pointer); +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) { @@ -483,9 +542,13 @@ void Batch::_glColorPointer(GLint size, GLenum type, GLsizei stride, const void DO_IT_NOW(_glColorPointer, 4); } -void Batch::do_glColorPointer(uint32& paramOffset) { - glColorPointer(_params[paramOffset++]._int, _params[paramOffset++]._uint, - _params[paramOffset++]._int, editResource(_params[paramOffset++]._uint)->_pointer); +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) { @@ -497,9 +560,12 @@ void Batch::_glNormalPointer(GLenum type, GLsizei stride, const void *pointer) { DO_IT_NOW(_glNormalPointer, 3); } -void Batch::do_glNormalPointer(uint32& paramOffset) { - glNormalPointer(_params[paramOffset++]._uint, _params[paramOffset++]._int, - editResource(_params[paramOffset++]._uint)->_pointer); +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) { @@ -512,9 +578,13 @@ void Batch::_glTexCoordPointer(GLint size, GLenum type, GLsizei stride, const vo DO_IT_NOW(_glTexCoordPointer, 4); } -void Batch::do_glTexCoordPointer(uint32& paramOffset) { - glTexCoordPointer(_params[paramOffset++]._int, _params[paramOffset++]._uint, - _params[paramOffset++]._int, editResource(_params[paramOffset++]._uint)->_pointer); +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) { @@ -527,9 +597,13 @@ void Batch::_glVertexPointer(GLint size, GLenum type, GLsizei stride, const voi DO_IT_NOW(_glVertexPointer, 4); } -void Batch::do_glVertexPointer(uint32& paramOffset) { - glVertexPointer(_params[paramOffset++]._int, _params[paramOffset++]._uint, - _params[paramOffset++]._int, editResource(_params[paramOffset++]._uint)->_pointer); +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(); } @@ -545,14 +619,17 @@ void Batch::_glVertexAttribPointer(GLuint index, GLint size, GLenum type, GLbool DO_IT_NOW(_glVertexAttribPointer, 6); } -void Batch::do_glVertexAttribPointer(uint32& paramOffset) { - glVertexAttribPointer(_params[paramOffset++]._uint, _params[paramOffset++]._int, - _params[paramOffset++]._uint, _params[paramOffset++]._uint, - _params[paramOffset++]._int, editResource(_params[paramOffset++]._uint)->_pointer); +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); @@ -560,8 +637,9 @@ void Batch::_glEnableVertexAttribArray(GLint location) { DO_IT_NOW(_glEnableVertexAttribArray, 1); } -void Batch::do_glEnableVertexAttribArray(uint32& paramOffset) { - glEnableVertexAttribArray(_params[paramOffset++]._uint); +void Batch::do_glEnableVertexAttribArray(uint32 paramOffset) { + glEnableVertexAttribArray(_params[paramOffset]._uint); + CHECK_GL_ERROR(); } void Batch::_glDisableVertexAttribArray(GLint location) { @@ -571,8 +649,9 @@ void Batch::_glDisableVertexAttribArray(GLint location) { DO_IT_NOW(_glDisableVertexAttribArray, 1); } -void Batch::do_glDisableVertexAttribArray(uint32& paramOffset) { - glDisableVertexAttribArray(_params[paramOffset++]._uint); +void Batch::do_glDisableVertexAttribArray(uint32 paramOffset) { + glDisableVertexAttribArray(_params[paramOffset]._uint); + CHECK_GL_ERROR(); } void Batch::_glColor4f(GLfloat red, GLfloat green, GLfloat blue, GLfloat alpha) { @@ -585,8 +664,13 @@ void Batch::_glColor4f(GLfloat red, GLfloat green, GLfloat blue, GLfloat alpha) DO_IT_NOW(_glColor4f, 4); } -void Batch::do_glColor4f(uint32& paramOffset) { - glColor4f(_params[paramOffset++]._float, _params[paramOffset++]._float, _params[paramOffset++]._float, _params[paramOffset++]._float); +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) { @@ -598,8 +682,12 @@ void Batch::_glMaterialf(GLenum face, GLenum pname, GLfloat param) { DO_IT_NOW(_glMaterialf, 3); } -void Batch::do_glMaterialf(uint32& paramOffset) { - glMaterialf(_params[paramOffset++]._uint, _params[paramOffset++]._uint, _params[paramOffset++]._float); +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) { @@ -611,14 +699,55 @@ void Batch::_glMaterialfv(GLenum face, GLenum pname, const GLfloat *params) { DO_IT_NOW(_glMaterialfv, 3); } -void Batch::do_glMaterialfv(uint32& paramOffset) { - glMaterialfv(_params[paramOffset++]._uint, _params[paramOffset++]._uint, (const GLfloat*) editData(_params[paramOffset++]._uint)); +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) { - for (int i = 0; i < batch._commands.size(); i++) { - batch.runCommand(i); + 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; + } + } +} \ No newline at end of file diff --git a/interface/src/gpu/Batch.h b/interface/src/gpu/Batch.h index 60c9c2d645..ad5246f9b6 100644 --- a/interface/src/gpu/Batch.h +++ b/interface/src/gpu/Batch.h @@ -23,6 +23,8 @@ class Batch; namespace backend { void renderBatch(Batch& batch); + + void checkGLError(); }; class Buffer; @@ -179,7 +181,7 @@ protected: COMMAND_glMaterialfv, }; typedef std::vector Commands; - typedef void (Batch::*CommandCall)(uint32&); + typedef void (Batch::*CommandCall)(uint32); typedef std::vector CommandCalls; typedef std::vector CommandOffsets; @@ -249,64 +251,64 @@ protected: 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) {} + 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_glEnable(uint32 paramOffset); + void do_glDisable(uint32 paramOffset); - void do_glEnableClientState(uint32& paramOffset); - void do_glDisableClientState(uint32& paramOffset); + void do_glEnableClientState(uint32 paramOffset); + void do_glDisableClientState(uint32 paramOffset); - void do_glCullFace(uint32& paramOffset); - void do_glAlphaFunc(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_glDepthFunc(uint32 paramOffset); + void do_glDepthMask(uint32 paramOffset); + void do_glDepthRange(uint32 paramOffset); - void do_glBindBuffer(uint32& paramOffset); + void do_glBindBuffer(uint32 paramOffset); - void do_glBindTexture(uint32& paramOffset); - void do_glActiveTexture(uint32& paramOffset); + void do_glBindTexture(uint32 paramOffset); + void do_glActiveTexture(uint32 paramOffset); - void do_glDrawBuffers(uint32& paramOffset); + void do_glDrawBuffers(uint32 paramOffset); - void do_glUseProgram(uint32& paramOffset); - void do_glUniform1f(uint32& paramOffset); - void do_glUniformMatrix4fv(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_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_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_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_glVertexAttribPointer(uint32 paramOffset); + void do_glEnableVertexAttribArray(uint32 paramOffset); + void do_glDisableVertexAttribArray(uint32 paramOffset); - void do_glColor4f(uint32& paramOffset); + void do_glColor4f(uint32 paramOffset); - void do_glMaterialf(uint32& paramOffset); - void do_glMaterialfv(uint32& paramOffset); + void do_glMaterialf(uint32 paramOffset); + void do_glMaterialfv(uint32 paramOffset); friend void backend::renderBatch(Batch& batch); }; diff --git a/interface/src/renderer/Model.cpp b/interface/src/renderer/Model.cpp index 739f5d75b1..0dd31c1785 100644 --- a/interface/src/renderer/Model.cpp +++ b/interface/src/renderer/Model.cpp @@ -1819,7 +1819,7 @@ int Model::renderMeshes(gpu::Batch& batch, RenderMode mode, bool translucent, fl GLBATCH(glMaterialfv)(GL_FRONT, GL_AMBIENT, (const float*)&diffuse); GLBATCH(glMaterialfv)(GL_FRONT, GL_DIFFUSE, (const float*)&diffuse); GLBATCH(glMaterialfv)(GL_FRONT, GL_SPECULAR, (const float*)&specular); - GLBATCH(glMaterialf)(GL_FRONT, GL_SHININESS, part.shininess); + GLBATCH(glMaterialf)(GL_FRONT, GL_SHININESS, (part.shininess > 128.f ? 128.f: part.shininess)); Texture* diffuseMap = networkPart.diffuseTexture.data(); if (mesh.isEye && diffuseMap) { From 04416ff40cd8ae334a4acac9a869a5e9849c71c9 Mon Sep 17 00:00:00 2001 From: Stephen Birarda Date: Wed, 22 Oct 2014 17:27:42 -0700 Subject: [PATCH 02/13] fix for DataWebPage hifi link handling --- interface/src/ui/DataWebPage.cpp | 18 +++++++++++++++--- interface/src/ui/DataWebPage.h | 1 + 2 files changed, 16 insertions(+), 3 deletions(-) diff --git a/interface/src/ui/DataWebPage.cpp b/interface/src/ui/DataWebPage.cpp index 812489a34d..b8b6649276 100644 --- a/interface/src/ui/DataWebPage.cpp +++ b/interface/src/ui/DataWebPage.cpp @@ -9,6 +9,9 @@ // See the accompanying file LICENSE or http://www.apache.org/licenses/LICENSE-2.0.html // +#include + +#include #include #include "DataWebPage.h" @@ -19,13 +22,22 @@ DataWebPage::DataWebPage(QObject* parent) : // use an OAuthNetworkAccessManager instead of regular QNetworkAccessManager so our requests are authed setNetworkAccessManager(OAuthNetworkAccessManager::getInstance()); - // have the page delegate external links so they can be captured by the Application in case they are a hifi link - setLinkDelegationPolicy(QWebPage::DelegateExternalLinks); - // give the page an empty stylesheet settings()->setUserStyleSheetUrl(QUrl()); } void DataWebPage::javaScriptConsoleMessage(const QString& message, int lineNumber, const QString& sourceID) { qDebug() << "JS console message at line" << lineNumber << "from" << sourceID << "-" << message; +} + +bool DataWebPage::acceptNavigationRequest(QWebFrame* frame, const QNetworkRequest& request, QWebPage::NavigationType type) { + + if (!request.url().toString().startsWith(HIFI_URL_SCHEME)) { + return true; + } else { + // this is a hifi URL - have the AddressManager handle it + QMetaObject::invokeMethod(&AddressManager::getInstance(), "handleLookupString", + Qt::AutoConnection, Q_ARG(const QString&, request.url().toString())); + return false; + } } \ No newline at end of file diff --git a/interface/src/ui/DataWebPage.h b/interface/src/ui/DataWebPage.h index 72fcbb5992..6d89077a33 100644 --- a/interface/src/ui/DataWebPage.h +++ b/interface/src/ui/DataWebPage.h @@ -19,6 +19,7 @@ public: DataWebPage(QObject* parent = 0); protected: void javaScriptConsoleMessage(const QString & message, int lineNumber, const QString & sourceID); + bool acceptNavigationRequest(QWebFrame* frame, const QNetworkRequest& request, QWebPage::NavigationType type); }; #endif // hifi_DataWebPage_h \ No newline at end of file From 631419d23c62739f7927593fe7e67b32e1de0723 Mon Sep 17 00:00:00 2001 From: Andrzej Kapolka Date: Wed, 22 Oct 2014 18:22:21 -0700 Subject: [PATCH 03/13] Tweaks to heightfield conversion. --- .../shaders/metavoxel_heightfield_base.vert | 13 +++--- .../metavoxels/src/MetavoxelMessages.cpp | 43 ++++++++++++------- 2 files changed, 35 insertions(+), 21 deletions(-) diff --git a/interface/resources/shaders/metavoxel_heightfield_base.vert b/interface/resources/shaders/metavoxel_heightfield_base.vert index f097426e13..5486f5fa67 100644 --- a/interface/resources/shaders/metavoxel_heightfield_base.vert +++ b/interface/resources/shaders/metavoxel_heightfield_base.vert @@ -26,11 +26,14 @@ varying vec4 normal; void main(void) { // transform and store the normal for interpolation vec2 heightCoord = gl_MultiTexCoord0.st; - float deltaX = texture2D(heightMap, heightCoord - vec2(heightScale, 0.0)).r - - texture2D(heightMap, heightCoord + vec2(heightScale, 0.0)).r; - float deltaZ = texture2D(heightMap, heightCoord - vec2(0.0, heightScale)).r - - texture2D(heightMap, heightCoord + vec2(0.0, heightScale)).r; - normal = normalize(gl_ModelViewMatrix * vec4(deltaX, heightScale, deltaZ, 0.0)); + vec4 neighborHeights = vec4(texture2D(heightMap, heightCoord - vec2(heightScale, 0.0)).r, + texture2D(heightMap, heightCoord + vec2(heightScale, 0.0)).r, + texture2D(heightMap, heightCoord - vec2(0.0, heightScale)).r, + texture2D(heightMap, heightCoord + vec2(0.0, heightScale)).r); + vec4 neighborsZero = step(1.0 / 255.0, neighborHeights); + normal = normalize(gl_ModelViewMatrix * vec4( + (neighborHeights.x - neighborHeights.y) * neighborsZero.x * neighborsZero.y, heightScale, + (neighborHeights.z - neighborHeights.w) * neighborsZero.z * neighborsZero.w, 0.0)); // add the height to the position float height = texture2D(heightMap, heightCoord).r; diff --git a/libraries/metavoxels/src/MetavoxelMessages.cpp b/libraries/metavoxels/src/MetavoxelMessages.cpp index d9c60f3f12..2d1e03fc69 100644 --- a/libraries/metavoxels/src/MetavoxelMessages.cpp +++ b/libraries/metavoxels/src/MetavoxelMessages.cpp @@ -1062,6 +1062,13 @@ int HeightfieldClearFetchVisitor::visit(MetavoxelInfo& info) { HeightfieldHeightDataPointer newHeightPointer(new HeightfieldHeightData(contents)); info.outputValues[0] = AttributeValue(_outputs.at(0), encodeInline(newHeightPointer)); + // allow a border for what we clear in terms of color/material + innerBounds.minimum.x += increment; + innerBounds.minimum.z += increment; + innerBounds.maximum.x -= increment; + innerBounds.maximum.z -= increment; + innerOverlap = bounds.getIntersection(innerBounds); + HeightfieldColorDataPointer colorPointer = info.inputValues.at(1).getInlineValue(); if (colorPointer) { contents = colorPointer->getContents(); @@ -1087,14 +1094,16 @@ int HeightfieldClearFetchVisitor::visit(MetavoxelInfo& info) { destY = (innerOverlap.minimum.z - info.minimum.z) * heightScale; destWidth = glm::ceil((innerOverlap.maximum.x - innerOverlap.minimum.x) * heightScale); destHeight = glm::ceil((innerOverlap.maximum.z - innerOverlap.minimum.z) * heightScale); - dest = contents.data() + (destY * size + destX) * DataBlock::COLOR_BYTES; - - for (int y = 0; y < destHeight; y++, dest += size * DataBlock::COLOR_BYTES) { - memset(dest, 0, destWidth * DataBlock::COLOR_BYTES); + if (destWidth > 0 && destHeight > 0) { + dest = contents.data() + (destY * size + destX) * DataBlock::COLOR_BYTES; + + for (int y = 0; y < destHeight; y++, dest += size * DataBlock::COLOR_BYTES) { + memset(dest, 0, destWidth * DataBlock::COLOR_BYTES); + } + + HeightfieldColorDataPointer newColorPointer(new HeightfieldColorData(contents)); + info.outputValues[1] = AttributeValue(_outputs.at(1), encodeInline(newColorPointer)); } - - HeightfieldColorDataPointer newColorPointer(new HeightfieldColorData(contents)); - info.outputValues[1] = AttributeValue(_outputs.at(1), encodeInline(newColorPointer)); } HeightfieldMaterialDataPointer materialPointer = info.inputValues.at(2).getInlineValue(); @@ -1134,16 +1143,18 @@ int HeightfieldClearFetchVisitor::visit(MetavoxelInfo& info) { destY = (innerOverlap.minimum.z - info.minimum.z) * heightScale; destWidth = glm::ceil((innerOverlap.maximum.x - innerOverlap.minimum.x) * heightScale); destHeight = glm::ceil((innerOverlap.maximum.z - innerOverlap.minimum.z) * heightScale); - dest = (uchar*)contents.data() + destY * size + destX; - - for (int y = 0; y < destHeight; y++, dest += size) { - memset(dest, 0, destWidth); + if (destWidth > 0 && destHeight > 0) { + dest = (uchar*)contents.data() + destY * size + destX; + + for (int y = 0; y < destHeight; y++, dest += size) { + memset(dest, 0, destWidth); + } + + clearUnusedMaterials(materials, contents); + HeightfieldMaterialDataPointer newMaterialPointer(new HeightfieldMaterialData(contents, materials)); + info.outputValues[2] = AttributeValue(_outputs.at(2), + encodeInline(newMaterialPointer)); } - - clearUnusedMaterials(materials, contents); - HeightfieldMaterialDataPointer newMaterialPointer(new HeightfieldMaterialData(contents, materials)); - info.outputValues[2] = AttributeValue(_outputs.at(2), - encodeInline(newMaterialPointer)); } return STOP_RECURSION; From 1d68413b663475e633ab90a2b6d58877b3bcd5be Mon Sep 17 00:00:00 2001 From: Philip Rosedale Date: Thu, 23 Oct 2014 11:43:13 -0700 Subject: [PATCH 04/13] Audio-only mouth uses multiple blend shapes --- interface/src/avatar/Head.cpp | 19 +++++++++++++++++++ interface/src/avatar/Head.h | 3 +++ interface/src/devices/Faceshift.cpp | 12 ++++++++++-- interface/src/devices/Faceshift.h | 10 ++++++++-- 4 files changed, 40 insertions(+), 4 deletions(-) diff --git a/interface/src/avatar/Head.cpp b/interface/src/avatar/Head.cpp index bc557bdb57..31f08d9eae 100644 --- a/interface/src/avatar/Head.cpp +++ b/interface/src/avatar/Head.cpp @@ -166,6 +166,7 @@ void Head::simulate(float deltaTime, bool isMine, bool billboard) { } // use data to update fake Faceshift blendshape coefficients + const float JAW_OPEN_SCALE = 0.015f; const float JAW_OPEN_RATE = 0.9f; const float JAW_CLOSE_RATE = 0.90f; @@ -177,10 +178,28 @@ void Head::simulate(float deltaTime, bool isMine, bool billboard) { } _audioJawOpen = glm::clamp(_audioJawOpen, 0.0f, 1.0f); + // _mouth2 = "mmmm" shape + // _mouth3 = "funnel" shape + // _mouth4 = "smile" shape + const float FUNNEL_PERIOD = 0.985f; + const float FUNNEL_RANDOM_PERIOD = 0.01f; + const float MMMM_POWER = 0.25f; + const float MMMM_PERIOD = 0.91f; + const float MMMM_RANDOM_PERIOD = 0.15f; + const float SMILE_PERIOD = 0.925f; + const float SMILE_RANDOM_PERIOD = 0.05f; + + _mouth3 = glm::mix(_audioJawOpen, _mouth3, FUNNEL_PERIOD + randFloat() * FUNNEL_RANDOM_PERIOD); + _mouth2 = glm::mix(_audioJawOpen * MMMM_POWER, _mouth2, MMMM_PERIOD + randFloat() * MMMM_RANDOM_PERIOD); + _mouth4 = glm::mix(_audioJawOpen, _mouth4, SMILE_PERIOD + randFloat() * SMILE_RANDOM_PERIOD); + Application::getInstance()->getFaceshift()->updateFakeCoefficients(_leftEyeBlink, _rightEyeBlink, _browAudioLift, _audioJawOpen, + _mouth2, + _mouth3, + _mouth4, _blendshapeCoefficients); } diff --git a/interface/src/avatar/Head.h b/interface/src/avatar/Head.h index bc4142eab0..57d74adaf0 100644 --- a/interface/src/avatar/Head.h +++ b/interface/src/avatar/Head.h @@ -129,6 +129,9 @@ private: float _longTermAverageLoudness; float _audioAttack; float _audioJawOpen; + float _mouth2; + float _mouth3; + float _mouth4; glm::vec3 _angularVelocity; bool _renderLookatVectors; glm::vec3 _saccade; diff --git a/interface/src/devices/Faceshift.cpp b/interface/src/devices/Faceshift.cpp index 74e36a98d1..0f1f792157 100644 --- a/interface/src/devices/Faceshift.cpp +++ b/interface/src/devices/Faceshift.cpp @@ -125,8 +125,13 @@ void Faceshift::reset() { } void Faceshift::updateFakeCoefficients(float leftBlink, float rightBlink, float browUp, - float jawOpen, QVector& coefficients) const { - coefficients.resize(max((int)coefficients.size(), _jawOpenIndex + 1)); + float jawOpen, float mouth2, float mouth3, float mouth4, QVector& coefficients) const { + const int MMMM_BLENDSHAPE = 34; + const int FUNNEL_BLENDSHAPE = 40; + const int SMILE_LEFT_BLENDSHAPE = 28; + const int SMILE_RIGHT_BLENDSHAPE = 29; + coefficients.resize(max((int)coefficients.size(), FUNNEL_BLENDSHAPE + 1)); + coefficients.resize(max((int)coefficients.size(), 48)); qFill(coefficients.begin(), coefficients.end(), 0.0f); coefficients[_leftBlinkIndex] = leftBlink; coefficients[_rightBlinkIndex] = rightBlink; @@ -134,6 +139,9 @@ void Faceshift::updateFakeCoefficients(float leftBlink, float rightBlink, float coefficients[_browUpLeftIndex] = browUp; coefficients[_browUpRightIndex] = browUp; coefficients[_jawOpenIndex] = jawOpen; + coefficients[SMILE_LEFT_BLENDSHAPE] = coefficients[SMILE_RIGHT_BLENDSHAPE] = mouth4; + coefficients[MMMM_BLENDSHAPE] = mouth2; + coefficients[FUNNEL_BLENDSHAPE] = mouth3; } void Faceshift::setTCPEnabled(bool enabled) { diff --git a/interface/src/devices/Faceshift.h b/interface/src/devices/Faceshift.h index e7d87827eb..3b4092c099 100644 --- a/interface/src/devices/Faceshift.h +++ b/interface/src/devices/Faceshift.h @@ -61,8 +61,14 @@ public: void update(); void reset(); - void updateFakeCoefficients(float leftBlink, float rightBlink, float browUp, - float jawOpen, QVector& coefficients) const; + void updateFakeCoefficients(float leftBlink, + float rightBlink, + float browUp, + float jawOpen, + float mouth2, + float mouth3, + float mouth4, + QVector& coefficients) const; signals: From 9394f72b18353e6c6ea887176af8dc286c22d483 Mon Sep 17 00:00:00 2001 From: Philip Rosedale Date: Thu, 23 Oct 2014 11:55:06 -0700 Subject: [PATCH 05/13] clarify fake blendshape array size --- interface/src/devices/Faceshift.cpp | 5 +++-- 1 file changed, 3 insertions(+), 2 deletions(-) diff --git a/interface/src/devices/Faceshift.cpp b/interface/src/devices/Faceshift.cpp index 0f1f792157..fb74f416a9 100644 --- a/interface/src/devices/Faceshift.cpp +++ b/interface/src/devices/Faceshift.cpp @@ -130,8 +130,9 @@ void Faceshift::updateFakeCoefficients(float leftBlink, float rightBlink, float const int FUNNEL_BLENDSHAPE = 40; const int SMILE_LEFT_BLENDSHAPE = 28; const int SMILE_RIGHT_BLENDSHAPE = 29; - coefficients.resize(max((int)coefficients.size(), FUNNEL_BLENDSHAPE + 1)); - coefficients.resize(max((int)coefficients.size(), 48)); + const int MAX_FAKE_BLENDSHAPE = 40; // Largest modified blendshape from above and below + + coefficients.resize(max((int)coefficients.size(), MAX_FAKE_BLENDSHAPE + 1)); qFill(coefficients.begin(), coefficients.end(), 0.0f); coefficients[_leftBlinkIndex] = leftBlink; coefficients[_rightBlinkIndex] = rightBlink; From 34cba5c031b404b2812f186080ca02d95994aaab Mon Sep 17 00:00:00 2001 From: Andrzej Kapolka Date: Thu, 23 Oct 2014 13:16:43 -0700 Subject: [PATCH 06/13] Added options to selectively toggle heightfield/dual contour surface rendering. --- interface/src/Menu.cpp | 2 ++ interface/src/Menu.h | 2 ++ interface/src/MetavoxelSystem.cpp | 53 +++++++++++++++---------------- 3 files changed, 30 insertions(+), 27 deletions(-) diff --git a/interface/src/Menu.cpp b/interface/src/Menu.cpp index 11ab5769cb..d7b47a549d 100644 --- a/interface/src/Menu.cpp +++ b/interface/src/Menu.cpp @@ -432,6 +432,8 @@ Menu::Menu() : QMenu* metavoxelOptionsMenu = developerMenu->addMenu("Metavoxels"); addCheckableActionToQMenuAndActionHash(metavoxelOptionsMenu, MenuOption::DisplayHermiteData, 0, false, Application::getInstance()->getMetavoxels(), SLOT(refreshVoxelData())); + addCheckableActionToQMenuAndActionHash(metavoxelOptionsMenu, MenuOption::RenderHeightfields, 0, true); + addCheckableActionToQMenuAndActionHash(metavoxelOptionsMenu, MenuOption::RenderDualContourSurfaces, 0, true); addActionToQMenuAndActionHash(metavoxelOptionsMenu, MenuOption::NetworkSimulator, 0, this, SLOT(showMetavoxelNetworkSimulator())); diff --git a/interface/src/Menu.h b/interface/src/Menu.h index 80f7f1e006..66755f0e5b 100644 --- a/interface/src/Menu.h +++ b/interface/src/Menu.h @@ -446,8 +446,10 @@ namespace MenuOption { const QString Quit = "Quit"; const QString ReloadAllScripts = "Reload All Scripts"; const QString RenderBoundingCollisionShapes = "Show Bounding Collision Shapes"; + const QString RenderDualContourSurfaces = "Render Dual Contour Surfaces"; const QString RenderFocusIndicator = "Show Eye Focus"; const QString RenderHeadCollisionShapes = "Show Head Collision Shapes"; + const QString RenderHeightfields = "Render Heightfields"; const QString RenderLookAtVectors = "Show Look-at Vectors"; const QString RenderSkeletonCollisionShapes = "Show Skeleton Collision Shapes"; const QString RenderResolution = "Scale Resolution"; diff --git a/interface/src/MetavoxelSystem.cpp b/interface/src/MetavoxelSystem.cpp index 8166c3938c..2071ea8c3d 100644 --- a/interface/src/MetavoxelSystem.cpp +++ b/interface/src/MetavoxelSystem.cpp @@ -2772,40 +2772,39 @@ void DefaultMetavoxelRendererImplementation::render(MetavoxelData& data, Metavox glColor4f(1.0f, 1.0f, 1.0f, 1.0f); - _baseHeightfieldProgram.bind(); - - glEnableClientState(GL_TEXTURE_COORD_ARRAY); - - BufferRenderVisitor heightfieldRenderVisitor(Application::getInstance()->getMetavoxels()->getHeightfieldBufferAttribute()); - data.guide(heightfieldRenderVisitor); - - _baseHeightfieldProgram.release(); - - glActiveTexture(GL_TEXTURE2); - glBindTexture(GL_TEXTURE_2D, 0); - glActiveTexture(GL_TEXTURE0); + if (Menu::getInstance()->isOptionChecked(MenuOption::RenderHeightfields)) { + _baseHeightfieldProgram.bind(); - glDisableClientState(GL_TEXTURE_COORD_ARRAY); - glDisableClientState(GL_VERTEX_ARRAY); + glEnableClientState(GL_TEXTURE_COORD_ARRAY); + + BufferRenderVisitor heightfieldRenderVisitor(Application::getInstance()->getMetavoxels()->getHeightfieldBufferAttribute()); + data.guide(heightfieldRenderVisitor); + + glDisableClientState(GL_TEXTURE_COORD_ARRAY); + + _baseHeightfieldProgram.release(); + } - glEnableClientState(GL_VERTEX_ARRAY); - glEnableClientState(GL_COLOR_ARRAY); - glEnableClientState(GL_NORMAL_ARRAY); - - _baseVoxelProgram.bind(); - - BufferRenderVisitor voxelRenderVisitor(Application::getInstance()->getMetavoxels()->getVoxelBufferAttribute()); - data.guide(voxelRenderVisitor); - - _baseVoxelProgram.release(); + if (Menu::getInstance()->isOptionChecked(MenuOption::RenderDualContourSurfaces)) { + glEnableClientState(GL_COLOR_ARRAY); + glEnableClientState(GL_NORMAL_ARRAY); + + _baseVoxelProgram.bind(); + + BufferRenderVisitor voxelRenderVisitor(Application::getInstance()->getMetavoxels()->getVoxelBufferAttribute()); + data.guide(voxelRenderVisitor); + + _baseVoxelProgram.release(); + + glDisableClientState(GL_COLOR_ARRAY); + glDisableClientState(GL_NORMAL_ARRAY); + } glDisable(GL_ALPHA_TEST); glDisable(GL_CULL_FACE); glEnable(GL_BLEND); - + glDisableClientState(GL_VERTEX_ARRAY); - glDisableClientState(GL_COLOR_ARRAY); - glDisableClientState(GL_NORMAL_ARRAY); Application::getInstance()->getTextureCache()->setPrimaryDrawBuffers(true, false); } From ef0a400dcbd18d9b45eb8b4086f29154dae7e53a Mon Sep 17 00:00:00 2001 From: Andrzej Kapolka Date: Thu, 23 Oct 2014 13:37:11 -0700 Subject: [PATCH 07/13] Fix for clearing empty nodes. --- .../metavoxels/src/MetavoxelMessages.cpp | 78 ++++++++++--------- 1 file changed, 41 insertions(+), 37 deletions(-) diff --git a/libraries/metavoxels/src/MetavoxelMessages.cpp b/libraries/metavoxels/src/MetavoxelMessages.cpp index 2d1e03fc69..d92dc4bd5a 100644 --- a/libraries/metavoxels/src/MetavoxelMessages.cpp +++ b/libraries/metavoxels/src/MetavoxelMessages.cpp @@ -1049,19 +1049,14 @@ int HeightfieldClearFetchVisitor::visit(MetavoxelInfo& info) { } // if all is gone, clear the node - if (!foundNonZero) { - info.outputValues[0] = AttributeValue(_outputs.at(0), - encodeInline(HeightfieldHeightDataPointer())); - info.outputValues[1] = AttributeValue(_outputs.at(1), - encodeInline(HeightfieldColorDataPointer())); - info.outputValues[2] = AttributeValue(_outputs.at(2), - encodeInline(HeightfieldMaterialDataPointer())); - return STOP_RECURSION; + if (foundNonZero) { + HeightfieldHeightDataPointer newHeightPointer(new HeightfieldHeightData(contents)); + info.outputValues[0] = AttributeValue(_outputs.at(0), encodeInline(newHeightPointer)); + + } else { + info.outputValues[0] = AttributeValue(_outputs.at(0)); } - HeightfieldHeightDataPointer newHeightPointer(new HeightfieldHeightData(contents)); - info.outputValues[0] = AttributeValue(_outputs.at(0), encodeInline(newHeightPointer)); - // allow a border for what we clear in terms of color/material innerBounds.minimum.x += increment; innerBounds.minimum.z += increment; @@ -1090,19 +1085,24 @@ int HeightfieldClearFetchVisitor::visit(MetavoxelInfo& info) { memcpy(dest, src, destWidth * DataBlock::COLOR_BYTES); } - destX = (innerOverlap.minimum.x - info.minimum.x) * heightScale; - destY = (innerOverlap.minimum.z - info.minimum.z) * heightScale; - destWidth = glm::ceil((innerOverlap.maximum.x - innerOverlap.minimum.x) * heightScale); - destHeight = glm::ceil((innerOverlap.maximum.z - innerOverlap.minimum.z) * heightScale); - if (destWidth > 0 && destHeight > 0) { - dest = contents.data() + (destY * size + destX) * DataBlock::COLOR_BYTES; - - for (int y = 0; y < destHeight; y++, dest += size * DataBlock::COLOR_BYTES) { - memset(dest, 0, destWidth * DataBlock::COLOR_BYTES); + if (foundNonZero) { + destX = (innerOverlap.minimum.x - info.minimum.x) * heightScale; + destY = (innerOverlap.minimum.z - info.minimum.z) * heightScale; + destWidth = glm::ceil((innerOverlap.maximum.x - innerOverlap.minimum.x) * heightScale); + destHeight = glm::ceil((innerOverlap.maximum.z - innerOverlap.minimum.z) * heightScale); + if (destWidth > 0 && destHeight > 0) { + dest = contents.data() + (destY * size + destX) * DataBlock::COLOR_BYTES; + + for (int y = 0; y < destHeight; y++, dest += size * DataBlock::COLOR_BYTES) { + memset(dest, 0, destWidth * DataBlock::COLOR_BYTES); + } + + HeightfieldColorDataPointer newColorPointer(new HeightfieldColorData(contents)); + info.outputValues[1] = AttributeValue(_outputs.at(1), + encodeInline(newColorPointer)); } - - HeightfieldColorDataPointer newColorPointer(new HeightfieldColorData(contents)); - info.outputValues[1] = AttributeValue(_outputs.at(1), encodeInline(newColorPointer)); + } else { + info.outputValues[1] = AttributeValue(_outputs.at(1)); } } @@ -1139,21 +1139,25 @@ int HeightfieldClearFetchVisitor::visit(MetavoxelInfo& info) { } } - destX = (innerOverlap.minimum.x - info.minimum.x) * heightScale; - destY = (innerOverlap.minimum.z - info.minimum.z) * heightScale; - destWidth = glm::ceil((innerOverlap.maximum.x - innerOverlap.minimum.x) * heightScale); - destHeight = glm::ceil((innerOverlap.maximum.z - innerOverlap.minimum.z) * heightScale); - if (destWidth > 0 && destHeight > 0) { - dest = (uchar*)contents.data() + destY * size + destX; - - for (int y = 0; y < destHeight; y++, dest += size) { - memset(dest, 0, destWidth); + if (foundNonZero) { + destX = (innerOverlap.minimum.x - info.minimum.x) * heightScale; + destY = (innerOverlap.minimum.z - info.minimum.z) * heightScale; + destWidth = glm::ceil((innerOverlap.maximum.x - innerOverlap.minimum.x) * heightScale); + destHeight = glm::ceil((innerOverlap.maximum.z - innerOverlap.minimum.z) * heightScale); + if (destWidth > 0 && destHeight > 0) { + dest = (uchar*)contents.data() + destY * size + destX; + + for (int y = 0; y < destHeight; y++, dest += size) { + memset(dest, 0, destWidth); + } + + clearUnusedMaterials(materials, contents); + HeightfieldMaterialDataPointer newMaterialPointer(new HeightfieldMaterialData(contents, materials)); + info.outputValues[2] = AttributeValue(_outputs.at(2), + encodeInline(newMaterialPointer)); } - - clearUnusedMaterials(materials, contents); - HeightfieldMaterialDataPointer newMaterialPointer(new HeightfieldMaterialData(contents, materials)); - info.outputValues[2] = AttributeValue(_outputs.at(2), - encodeInline(newMaterialPointer)); + } else { + info.outputValues[2] = AttributeValue(_outputs.at(2)); } } From 20c862d199b80d01eecbf157453d987240d6ab0e Mon Sep 17 00:00:00 2001 From: Atlante45 Date: Thu, 23 Oct 2014 14:35:24 -0700 Subject: [PATCH 08/13] Fix player loop --- libraries/avatars/src/Player.cpp | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) diff --git a/libraries/avatars/src/Player.cpp b/libraries/avatars/src/Player.cpp index 35a822f11b..47d1b04421 100644 --- a/libraries/avatars/src/Player.cpp +++ b/libraries/avatars/src/Player.cpp @@ -212,7 +212,7 @@ void Player::loadRecording(RecordingPointer recording) { void Player::play() { computeCurrentFrame(); - if (_currentFrame < 0 || (_currentFrame >= _recording->getFrameNumber() - 1)) { + if (_currentFrame < 0 || (_currentFrame >= _recording->getFrameNumber() - 2)) { // -2 because of interpolation if (_loop) { loopRecording(); } else { From d92c03364ad0a401e37c8f048bbc8639d74d8b46 Mon Sep 17 00:00:00 2001 From: Sam Gateau Date: Thu, 23 Oct 2014 14:53:43 -0700 Subject: [PATCH 09/13] Improve comment regarding the replacement of the QGLProgram->bind() --- interface/src/renderer/Model.cpp | 11 +---------- 1 file changed, 1 insertion(+), 10 deletions(-) diff --git a/interface/src/renderer/Model.cpp b/interface/src/renderer/Model.cpp index 0dd31c1785..131c600dc1 100644 --- a/interface/src/renderer/Model.cpp +++ b/interface/src/renderer/Model.cpp @@ -1649,20 +1649,11 @@ int Model::renderMeshes(gpu::Batch& batch, RenderMode mode, bool translucent, fl ProgramObject* activeProgram = program; Locations* activeLocations = locations; - // Try to use the Batch - //gpu::Batch batch; - - /*if (isSkinned) { - skinProgram->bind(); - activeProgram = skinProgram; - activeLocations = skinLocations; - } else { - program->bind(); - }*/ if (isSkinned) { activeProgram = skinProgram; activeLocations = skinLocations; } + // This code replace the "bind()" on the QGLProgram if (!activeProgram->isLinked()) { activeProgram->link(); } From 27d9de0cba6fbdc862a165161a09e56fc89a3246 Mon Sep 17 00:00:00 2001 From: Andrzej Kapolka Date: Thu, 23 Oct 2014 16:01:51 -0700 Subject: [PATCH 10/13] More gradual improvements to heightfield voxelization. --- libraries/metavoxels/src/MetavoxelData.cpp | 35 +++++++++++++++++-- .../metavoxels/src/MetavoxelMessages.cpp | 9 +++-- 2 files changed, 39 insertions(+), 5 deletions(-) diff --git a/libraries/metavoxels/src/MetavoxelData.cpp b/libraries/metavoxels/src/MetavoxelData.cpp index 5b00c6531f..2bd28de784 100644 --- a/libraries/metavoxels/src/MetavoxelData.cpp +++ b/libraries/metavoxels/src/MetavoxelData.cpp @@ -2486,8 +2486,39 @@ bool Heightfield::intersects(const glm::vec3& start, const glm::vec3& end, float if (!getBounds().findRayIntersection(start, direction, rayDistance) || rayDistance > 1.0f) { return false; } - glm::vec3 entry = (start + direction * rayDistance - getBounds().minimum) / _increment; - direction /= _increment; + glm::vec3 entry = start + direction * rayDistance; + const float DISTANCE_THRESHOLD = 0.001f; + if (glm::abs(entry.x - getBounds().minimum.x) < DISTANCE_THRESHOLD) { + normal = glm::vec3(-1.0f, 0.0f, 0.0f); + distance = rayDistance; + return true; + + } else if (glm::abs(entry.x - getBounds().maximum.x) < DISTANCE_THRESHOLD) { + normal = glm::vec3(1.0f, 0.0f, 0.0f); + distance = rayDistance; + return true; + + } else if (glm::abs(entry.y - getBounds().minimum.y) < DISTANCE_THRESHOLD) { + normal = glm::vec3(0.0f, -1.0f, 0.0f); + distance = rayDistance; + return true; + + } else if (glm::abs(entry.y - getBounds().maximum.y) < DISTANCE_THRESHOLD) { + normal = glm::vec3(0.0f, 1.0f, 0.0f); + distance = rayDistance; + return true; + + } else if (glm::abs(entry.z - getBounds().minimum.z) < DISTANCE_THRESHOLD) { + normal = glm::vec3(0.0f, 0.0f, -1.0f); + distance = rayDistance; + return true; + + } else if (glm::abs(entry.z - getBounds().maximum.z) < DISTANCE_THRESHOLD) { + normal = glm::vec3(0.0f, 0.0f, 1.0f); + distance = rayDistance; + return true; + } + entry = (entry - getBounds().minimum) / _increment; glm::vec3 floors = glm::floor(entry); glm::vec3 ceils = glm::ceil(entry); if (floors.x == ceils.x) { diff --git a/libraries/metavoxels/src/MetavoxelMessages.cpp b/libraries/metavoxels/src/MetavoxelMessages.cpp index d92dc4bd5a..549931e030 100644 --- a/libraries/metavoxels/src/MetavoxelMessages.cpp +++ b/libraries/metavoxels/src/MetavoxelMessages.cpp @@ -998,10 +998,13 @@ int HeightfieldClearFetchVisitor::visit(MetavoxelInfo& info) { _spannerBounds.maximum = (glm::ceil(_bounds.maximum / increment) + glm::vec3(1.0f, 0.0f, 1.0f)) * increment; _spannerBounds.minimum.y = bounds.minimum.y; _spannerBounds.maximum.y = bounds.maximum.y; - _heightfieldWidth = (int)glm::round((_spannerBounds.maximum.x - _spannerBounds.minimum.x) / increment) + 1; - _heightfieldHeight = (int)glm::round((_spannerBounds.maximum.z - _spannerBounds.minimum.z) / increment) + 1; + _heightfieldWidth = (int)glm::round((_spannerBounds.maximum.x - _spannerBounds.minimum.x) / increment); + _heightfieldHeight = (int)glm::round((_spannerBounds.maximum.z - _spannerBounds.minimum.z) / increment); int heightfieldArea = _heightfieldWidth * _heightfieldHeight; - _spanner = spanner = new Heightfield(_spannerBounds, increment, QByteArray(heightfieldArea, 0), + Box innerBounds = _spannerBounds; + innerBounds.maximum.x -= increment; + innerBounds.maximum.z -= increment; + _spanner = spanner = new Heightfield(innerBounds, increment, QByteArray(heightfieldArea, 0), QByteArray(heightfieldArea * DataBlock::COLOR_BYTES, 0), QByteArray(heightfieldArea, 0), QVector()); } From fd23fb66abeaa7c67829d7ec3b51cf9713b08204 Mon Sep 17 00:00:00 2001 From: Stephen Birarda Date: Fri, 24 Oct 2014 10:42:29 -0700 Subject: [PATCH 11/13] bubble up ATL_INCLUDE_DIRS from FindATL module --- cmake/modules/FindATL.cmake | 9 ++++++--- 1 file changed, 6 insertions(+), 3 deletions(-) diff --git a/cmake/modules/FindATL.cmake b/cmake/modules/FindATL.cmake index f95b0267eb..24a21643d6 100644 --- a/cmake/modules/FindATL.cmake +++ b/cmake/modules/FindATL.cmake @@ -16,8 +16,11 @@ # if (WIN32) - find_library(ATL_LIBRARY_RELEASE atls PATH_SUFFIXES "7600.16385.1/lib/ATL/i386" HINTS "C:\\WinDDK") - find_library(ATL_LIBRARY_DEBUG atlsd PATH_SUFFIXES "7600.16385.1/lib/ATL/i386" HINTS "C:\\WinDDK") + set(ATL_SEARCH_DIRS "C:\\WinDDK") + find_path(ATL_INCLUDE_DIRS atlbase.h PATH_SUFFIXES "7600.16385.1/inc/atl71" HINTS ${ATL_SEARCH_DIRS}) + + find_library(ATL_LIBRARY_RELEASE atls PATH_SUFFIXES "7600.16385.1/lib/ATL/i386" HINTS ${ATL_SEARCH_DIRS}) + find_library(ATL_LIBRARY_DEBUG atlsd PATH_SUFFIXES "7600.16385.1/lib/ATL/i386" HINTS ${ATL_SEARCH_DIRS}) include(SelectLibraryConfigurations) select_library_configurations(ATL) @@ -26,4 +29,4 @@ endif () set(ATL_LIBRARIES "${ATL_LIBRARY}") include(FindPackageHandleStandardArgs) -find_package_handle_standard_args(ATL DEFAULT_MSG ATL_LIBRARIES) \ No newline at end of file +find_package_handle_standard_args(ATL DEFAULT_MSG ATL_LIBRARIES ATL_INCLUDE_DIRS) \ No newline at end of file From 30aa23e5cd91c6055f469b6c795504d76ab1f977 Mon Sep 17 00:00:00 2001 From: Stephen Birarda Date: Fri, 24 Oct 2014 10:45:06 -0700 Subject: [PATCH 12/13] message include dir for ATL when found --- cmake/modules/FindATL.cmake | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) diff --git a/cmake/modules/FindATL.cmake b/cmake/modules/FindATL.cmake index 24a21643d6..b32a2a4c70 100644 --- a/cmake/modules/FindATL.cmake +++ b/cmake/modules/FindATL.cmake @@ -29,4 +29,4 @@ endif () set(ATL_LIBRARIES "${ATL_LIBRARY}") include(FindPackageHandleStandardArgs) -find_package_handle_standard_args(ATL DEFAULT_MSG ATL_LIBRARIES ATL_INCLUDE_DIRS) \ No newline at end of file +find_package_handle_standard_args(ATL DEFAULT_MSG ATL_INCLUDE_DIRS ATL_LIBRARIES) \ No newline at end of file From c172f628fc85d1bbe8b39f755f5dfd5dc9378055 Mon Sep 17 00:00:00 2001 From: Stephen Birarda Date: Fri, 24 Oct 2014 11:12:55 -0700 Subject: [PATCH 13/13] repairs to FindATL indenting --- cmake/modules/FindATL.cmake | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) diff --git a/cmake/modules/FindATL.cmake b/cmake/modules/FindATL.cmake index b32a2a4c70..ecb9078d82 100644 --- a/cmake/modules/FindATL.cmake +++ b/cmake/modules/FindATL.cmake @@ -19,7 +19,7 @@ if (WIN32) set(ATL_SEARCH_DIRS "C:\\WinDDK") find_path(ATL_INCLUDE_DIRS atlbase.h PATH_SUFFIXES "7600.16385.1/inc/atl71" HINTS ${ATL_SEARCH_DIRS}) - find_library(ATL_LIBRARY_RELEASE atls PATH_SUFFIXES "7600.16385.1/lib/ATL/i386" HINTS ${ATL_SEARCH_DIRS}) + find_library(ATL_LIBRARY_RELEASE atls PATH_SUFFIXES "7600.16385.1/lib/ATL/i386" HINTS ${ATL_SEARCH_DIRS}) find_library(ATL_LIBRARY_DEBUG atlsd PATH_SUFFIXES "7600.16385.1/lib/ATL/i386" HINTS ${ATL_SEARCH_DIRS}) include(SelectLibraryConfigurations)