mirror of
https://github.com/lubosz/overte.git
synced 2025-04-23 09:33:45 +02:00
Introduce a cache bit in networkGemometry to capture the status of texture LOaded and avoid requiring everything once everything is loaded and get rid of the Transform stack calls on gl from gpu
This commit is contained in:
parent
3e8f7dc3da
commit
b9fd116dbf
6 changed files with 40 additions and 176 deletions
|
@ -129,17 +129,7 @@ public:
|
|||
void _glUniform1f(GLint location, GLfloat v0);
|
||||
void _glUniform2f(GLint location, GLfloat v0, GLfloat v1);
|
||||
void _glUniform4fv(GLint location, GLsizei count, const GLfloat* value);
|
||||
void _glUniformMatrix4fv(GLint location, GLsizei count, GLboolean transpose, const GLfloat* value);
|
||||
|
||||
void _glMatrixMode(GLenum mode);
|
||||
void _glPushMatrix();
|
||||
void _glPopMatrix();
|
||||
void _glMultMatrixf(const GLfloat *m);
|
||||
void _glLoadMatrixf(const GLfloat *m);
|
||||
void _glLoadIdentity(void);
|
||||
void _glRotatef(GLfloat angle, GLfloat x, GLfloat y, GLfloat z);
|
||||
void _glScalef(GLfloat x, GLfloat y, GLfloat z);
|
||||
void _glTranslatef(GLfloat x, GLfloat y, GLfloat z);
|
||||
void _glUniformMatrix4fv(GLint location, GLsizei count, GLboolean transpose, const GLfloat* value);
|
||||
|
||||
void _glDrawArrays(GLenum mode, GLint first, GLsizei count);
|
||||
void _glDrawRangeElements(GLenum mode, GLuint start, GLuint end, GLsizei count, GLenum type, const void *indices);
|
||||
|
@ -201,16 +191,6 @@ public:
|
|||
COMMAND_glUniform4fv,
|
||||
COMMAND_glUniformMatrix4fv,
|
||||
|
||||
COMMAND_glMatrixMode,
|
||||
COMMAND_glPushMatrix,
|
||||
COMMAND_glPopMatrix,
|
||||
COMMAND_glMultMatrixf,
|
||||
COMMAND_glLoadMatrixf,
|
||||
COMMAND_glLoadIdentity,
|
||||
COMMAND_glRotatef,
|
||||
COMMAND_glScalef,
|
||||
COMMAND_glTranslatef,
|
||||
|
||||
COMMAND_glDrawArrays,
|
||||
COMMAND_glDrawRangeElements,
|
||||
|
||||
|
|
|
@ -54,16 +54,6 @@ GLBackend::CommandCall GLBackend::_commandCalls[Batch::NUM_COMMANDS] =
|
|||
(&::gpu::GLBackend::do_glUniform4fv),
|
||||
(&::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),
|
||||
|
||||
|
@ -747,127 +737,6 @@ void GLBackend::do_glUniformMatrix4fv(Batch& batch, uint32 paramOffset) {
|
|||
CHECK_GL_ERROR();
|
||||
}
|
||||
|
||||
void Batch::_glMatrixMode(GLenum mode) {
|
||||
ADD_COMMAND_GL(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_GL(glPushMatrix);
|
||||
|
||||
DO_IT_NOW(_glPushMatrix, 0);
|
||||
}
|
||||
void GLBackend::do_glPushMatrix(Batch& batch, uint32 paramOffset) {
|
||||
glPushMatrix();
|
||||
CHECK_GL_ERROR();
|
||||
}
|
||||
|
||||
void Batch::_glPopMatrix() {
|
||||
ADD_COMMAND_GL(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_GL(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_GL(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_GL(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_GL(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_GL(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_GL(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_GL(glDrawArrays);
|
||||
|
||||
|
|
|
@ -175,17 +175,7 @@ protected:
|
|||
void do_glUniform1f(Batch& batch, uint32 paramOffset);
|
||||
void do_glUniform2f(Batch& batch, uint32 paramOffset);
|
||||
void do_glUniform4fv(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_glUniformMatrix4fv(Batch& batch, uint32 paramOffset);
|
||||
|
||||
void do_glDrawArrays(Batch& batch, uint32 paramOffset);
|
||||
void do_glDrawRangeElements(Batch& batch, uint32 paramOffset);
|
||||
|
|
|
@ -1753,15 +1753,18 @@ bool NetworkGeometry::isLoadedWithTextures() const {
|
|||
if (!isLoaded()) {
|
||||
return false;
|
||||
}
|
||||
foreach (const NetworkMesh& mesh, _meshes) {
|
||||
foreach (const NetworkMeshPart& part, mesh.parts) {
|
||||
if ((part.diffuseTexture && !part.diffuseTexture->isLoaded()) ||
|
||||
(part.normalTexture && !part.normalTexture->isLoaded()) ||
|
||||
(part.specularTexture && !part.specularTexture->isLoaded()) ||
|
||||
(part.emissiveTexture && !part.emissiveTexture->isLoaded())) {
|
||||
return false;
|
||||
if (!_isLoadedWithTextures) {
|
||||
foreach (const NetworkMesh& mesh, _meshes) {
|
||||
foreach (const NetworkMeshPart& part, mesh.parts) {
|
||||
if ((part.diffuseTexture && !part.diffuseTexture->isLoaded()) ||
|
||||
(part.normalTexture && !part.normalTexture->isLoaded()) ||
|
||||
(part.specularTexture && !part.specularTexture->isLoaded()) ||
|
||||
(part.emissiveTexture && !part.emissiveTexture->isLoaded())) {
|
||||
return false;
|
||||
}
|
||||
}
|
||||
}
|
||||
_isLoadedWithTextures = true;
|
||||
}
|
||||
return true;
|
||||
}
|
||||
|
@ -1938,6 +1941,7 @@ void NetworkGeometry::setTextureWithNameToURL(const QString& name, const QUrl& u
|
|||
// we don't have meshes downloaded yet, so hold this texture as pending
|
||||
_pendingTextureChanges.insert(name, url);
|
||||
}
|
||||
_isLoadedWithTextures = false;
|
||||
}
|
||||
|
||||
QStringList NetworkGeometry::getTextureNames() const {
|
||||
|
|
|
@ -339,6 +339,8 @@ private:
|
|||
QHash<QWeakPointer<Animation>, QVector<int> > _jointMappings;
|
||||
|
||||
QHash<QString, QUrl> _pendingTextureChanges;
|
||||
|
||||
mutable bool _isLoadedWithTextures = false;
|
||||
};
|
||||
|
||||
/// The state associated with a single mesh part.
|
||||
|
|
|
@ -686,7 +686,7 @@ bool Model::renderCore(float alpha, RenderMode mode, RenderArgs* args) {
|
|||
// Let's introduce a gpu::Batch to capture all the calls to the graphics api
|
||||
_renderBatch.clear();
|
||||
gpu::Batch& batch = _renderBatch;
|
||||
GLBATCH(glPushMatrix)();
|
||||
//GLBATCH(glPushMatrix)();
|
||||
|
||||
// Capture the view matrix once for the rendering of this model
|
||||
if (_transforms.empty()) {
|
||||
|
@ -835,12 +835,23 @@ bool Model::renderCore(float alpha, RenderMode mode, RenderArgs* args) {
|
|||
GLBATCH(glBindBuffer)(GL_ELEMENT_ARRAY_BUFFER, 0);
|
||||
GLBATCH(glBindTexture)(GL_TEXTURE_2D, 0);
|
||||
|
||||
GLBATCH(glPopMatrix)();
|
||||
//GLBATCH(glPopMatrix)();
|
||||
|
||||
// Render!
|
||||
{
|
||||
PROFILE_RANGE("render Batch");
|
||||
|
||||
#if defined(ANDROID)
|
||||
#else
|
||||
glPushMatrix();
|
||||
#endif
|
||||
|
||||
::gpu::GLBackend::renderBatch(batch);
|
||||
|
||||
#if defined(ANDROID)
|
||||
#else
|
||||
glPopMatrix();
|
||||
#endif
|
||||
}
|
||||
|
||||
// restore all the default material settings
|
||||
|
@ -1638,7 +1649,7 @@ void Model::startScene(RenderArgs::RenderSide renderSide) {
|
|||
}
|
||||
|
||||
void Model::setupBatchTransform(gpu::Batch& batch) {
|
||||
GLBATCH(glPushMatrix)();
|
||||
//GLBATCH(glPushMatrix)();
|
||||
|
||||
// Capture the view matrix once for the rendering of this model
|
||||
if (_transforms.empty()) {
|
||||
|
@ -1811,7 +1822,17 @@ void Model::endScene(RenderMode mode, RenderArgs* args) {
|
|||
// Render!
|
||||
{
|
||||
PROFILE_RANGE("render Batch");
|
||||
#if defined(ANDROID)
|
||||
#else
|
||||
glPushMatrix();
|
||||
#endif
|
||||
|
||||
::gpu::GLBackend::renderBatch(_sceneRenderBatch);
|
||||
|
||||
#if defined(ANDROID)
|
||||
#else
|
||||
glPopMatrix();
|
||||
#endif
|
||||
}
|
||||
|
||||
// restore all the default material settings
|
||||
|
@ -2271,7 +2292,7 @@ int Model::renderMeshesForModelsInScene(gpu::Batch& batch, RenderMode mode, bool
|
|||
}
|
||||
model->setupBatchTransform(batch);
|
||||
meshPartsRendered += model->renderMeshesFromList(list, batch, mode, translucent, alphaThreshold, args, locations, skinLocations);
|
||||
GLBATCH(glPopMatrix)();
|
||||
//GLBATCH(glPopMatrix)();
|
||||
}
|
||||
}
|
||||
}
|
||||
|
@ -2437,11 +2458,9 @@ int Model::renderMeshesFromList(QVector<int>& list, gpu::Batch& batch, RenderMod
|
|||
}
|
||||
static bool showDiffuse = true;
|
||||
if (showDiffuse && diffuseMap) {
|
||||
// GLBATCH(glBindTexture)(GL_TEXTURE_2D, diffuseMap->getID());
|
||||
batch.setUniformTexture(0, diffuseMap->getGPUTexture());
|
||||
|
||||
} else {
|
||||
// GLBATCH(glBindTexture)(GL_TEXTURE_2D, textureCache->getWhiteTextureID());
|
||||
batch.setUniformTexture(0, textureCache->getWhiteTexture());
|
||||
}
|
||||
|
||||
|
|
Loading…
Reference in a new issue