From a010e06bec6a4bec44501c9e9dec509e2f63d1c5 Mon Sep 17 00:00:00 2001 From: Joel Teichroeb Date: Sun, 30 Mar 2014 14:38:52 -0700 Subject: [PATCH] GRIM: Make data in MeshFace private --- engines/grim/gfx_opengl.cpp | 16 ++++++++-------- engines/grim/gfx_opengl_shaders.cpp | 24 ++++++++++++------------ engines/grim/gfx_tinygl.cpp | 16 ++++++++-------- engines/grim/model.cpp | 4 ++-- engines/grim/model.h | 12 ++++++++++++ 5 files changed, 42 insertions(+), 30 deletions(-) diff --git a/engines/grim/gfx_opengl.cpp b/engines/grim/gfx_opengl.cpp index 5edcf00013b..ffda3272fc1 100644 --- a/engines/grim/gfx_opengl.cpp +++ b/engines/grim/gfx_opengl.cpp @@ -328,7 +328,7 @@ void GfxOpenGL::getBoundingBoxPos(const Mesh *model, int *x1, int *y1, int *x2, Math::Vector3d v; float *pVertices; - for (int j = 0; j < model->_faces[i]._numVertices; j++) { + for (int j = 0; j < model->_faces[i].getNumVertices(); j++) { GLdouble modelView[16], projection[16]; GLint viewPort[4]; @@ -336,7 +336,7 @@ void GfxOpenGL::getBoundingBoxPos(const Mesh *model, int *x1, int *y1, int *x2, glGetDoublev(GL_PROJECTION_MATRIX, projection); glGetIntegerv(GL_VIEWPORT, viewPort); - pVertices = model->_vertices + 3 * model->_faces[i]._vertices[j]; + pVertices = model->_vertices + 3 * model->_faces[i].getVertex(j); v.set(*(pVertices), *(pVertices + 1), *(pVertices + 2)); @@ -657,15 +657,15 @@ void GfxOpenGL::drawModelFace(const Mesh *mesh, const MeshFace *face) { float *textureVerts = mesh->_textureVerts; glAlphaFunc(GL_GREATER, 0.5); glEnable(GL_ALPHA_TEST); - glNormal3fv(face->_normal.getData()); + glNormal3fv(face->getNormal().getData()); glBegin(GL_POLYGON); - for (int i = 0; i < face->_numVertices; i++) { - glNormal3fv(vertNormals + 3 * face->_vertices[i]); + for (int i = 0; i < face->getNumVertices(); i++) { + glNormal3fv(vertNormals + 3 * face->getVertex(i)); - if (face->_texVertices) - glTexCoord2fv(textureVerts + 2 * face->_texVertices[i]); + if (face->hasTexture()) + glTexCoord2fv(textureVerts + 2 * face->getTextureVertex(i)); - glVertex3fv(vertices + 3 * face->_vertices[i]); + glVertex3fv(vertices + 3 * face->getVertex(i)); } glEnd(); // Done with transparency-capable objects diff --git a/engines/grim/gfx_opengl_shaders.cpp b/engines/grim/gfx_opengl_shaders.cpp index 4d96f136045..85b543f1657 100644 --- a/engines/grim/gfx_opengl_shaders.cpp +++ b/engines/grim/gfx_opengl_shaders.cpp @@ -735,29 +735,29 @@ void GfxOpenGLS::drawMesh(const Mesh *mesh) { actorShader->use(); actorShader->setUniform("extraMatrix", _matrixStack.top()); - Material *curMaterial = NULL; + const Material *curMaterial = NULL; for (int i = 0; i < mesh->_numFaces;) { const MeshFace *face = &mesh->_faces[i]; - if (face->_light == 0 && !isShadowModeActive()) + if (face->getLight() == 0 && !isShadowModeActive()) disableLights(); - curMaterial = face->_material; + curMaterial = face->getMaterial(); curMaterial->select(); int faces = 0; for (; i < mesh->_numFaces; ++i) { - if (mesh->_faces[i]._material != curMaterial) + if (mesh->_faces[i].getMaterial() != curMaterial) break; - faces += 3 * (mesh->_faces[i]._numVertices - 2); + faces += 3 * (mesh->_faces[i].getNumVertices() - 2); } - bool textured = face->_texVertices && ! _currentShadowArray; + bool textured = face->hasTexture() && !_currentShadowArray; actorShader->setUniform("textured", textured ? GL_TRUE : GL_FALSE); actorShader->setUniform("texScale", Math::Vector2d(_selectedTexture->_width, _selectedTexture->_height)); glDrawArrays(GL_TRIANGLES, *(int *)face->_userData, faces); - if (face->_light == 0 && !isShadowModeActive()) + if (face->getLight() == 0 && !isShadowModeActive()) enableLights(); } } @@ -1673,14 +1673,14 @@ void GfxOpenGLS::createModel(Mesh *mesh) { face->_userData = new uint32; *(uint32 *)face->_userData = meshInfo.size(); - if (face->_numVertices < 3) + if (face->getNumVertices() < 3) continue; -#define VERT(j) (&mesh->_vertices[3*face->_vertices[j]]) -#define TEXVERT(j) (face->_texVertices ? &mesh->_textureVerts[2*face->_texVertices[j]] : zero_texVerts) -#define NORMAL(j) (&mesh->_vertNormals[3*face->_vertices[j]]) +#define VERT(j) (&mesh->_vertices[3 * face->getVertex(j)]) +#define TEXVERT(j) (face->hasTexture() ? &mesh->_textureVerts[2 * face->getTextureVertex(j)] : zero_texVerts) +#define NORMAL(j) (&mesh->_vertNormals[3 * face->getVertex(j)]) - for (int j = 2; j < face->_numVertices; ++j) { + for (int j = 2; j < face->getNumVertices(); ++j) { meshInfo.push_back(GrimVertex(VERT(0), TEXVERT(0), NORMAL(0))); meshInfo.push_back(GrimVertex(VERT(j-1), TEXVERT(j-1), NORMAL(j-1))); meshInfo.push_back(GrimVertex(VERT(j), TEXVERT(j), NORMAL(j))); diff --git a/engines/grim/gfx_tinygl.cpp b/engines/grim/gfx_tinygl.cpp index b1761d5f624..84e0648cbec 100644 --- a/engines/grim/gfx_tinygl.cpp +++ b/engines/grim/gfx_tinygl.cpp @@ -445,7 +445,7 @@ void GfxTinyGL::getBoundingBoxPos(const Mesh *model, int *x1, int *y1, int *x2, Math::Vector3d v; float *pVertices; - for (int j = 0; j < model->_faces[i]._numVertices; j++) { + for (int j = 0; j < model->_faces[i].getNumVertices(); j++) { TGLfloat modelView[16], projection[16]; TGLint viewPort[4]; @@ -453,7 +453,7 @@ void GfxTinyGL::getBoundingBoxPos(const Mesh *model, int *x1, int *y1, int *x2, tglGetFloatv(TGL_PROJECTION_MATRIX, projection); tglGetIntegerv(TGL_VIEWPORT, viewPort); - pVertices = model->_vertices + 3 * model->_faces[i]._vertices[j]; + pVertices = model->_vertices + 3 * model->_faces[i].getVertex(j); v.set(*(pVertices), *(pVertices + 1), *(pVertices + 2)); @@ -782,15 +782,15 @@ void GfxTinyGL::drawModelFace(const Mesh *mesh, const MeshFace *face) { float *vertices = mesh->_vertices; float *vertNormals = mesh->_vertNormals; float *textureVerts = mesh->_textureVerts; - tglNormal3fv(const_cast(face->_normal.getData())); + tglNormal3fv(const_cast(face->getNormal().getData())); tglBegin(TGL_POLYGON); - for (int i = 0; i < face->_numVertices; i++) { - tglNormal3fv(vertNormals + 3 * face->_vertices[i]); + for (int i = 0; i < face->getNumVertices(); i++) { + tglNormal3fv(vertNormals + 3 * face->getVertex(i)); - if (face->_texVertices) - tglTexCoord2fv(textureVerts + 2 * face->_texVertices[i]); + if (face->hasTexture()) + tglTexCoord2fv(textureVerts + 2 * face->getTextureVertex(i)); - tglVertex3fv(vertices + 3 * face->_vertices[i]); + tglVertex3fv(vertices + 3 * face->getVertex(i)); } tglEnd(); } diff --git a/engines/grim/model.cpp b/engines/grim/model.cpp index 0e61e66f517..a38ca522ad4 100644 --- a/engines/grim/model.cpp +++ b/engines/grim/model.cpp @@ -525,7 +525,7 @@ void Mesh::loadText(TextSplitter *ts, Material *materials[]) { int num; float x, y, z; ts->scanString(" %d: %f %f %f", 4, &num, &x, &y, &z); - _faces[num]._normal = Math::Vector3d(x, y, z); + _faces[num].setNormal(Math::Vector3d(x, y, z)); } sortFaces(); } @@ -545,7 +545,7 @@ void Mesh::sortFaces() { continue; for (int other = cur; other < _numFaces; ++other) { - if (_faces[cur]._material == _faces[other]._material && !copied[other]) { + if (_faces[cur].getMaterial() == _faces[other].getMaterial() && !copied[other]) { copied[other] = true; newFaces[writeIdx] = _faces[other]; newMaterialid[writeIdx] = _materialid[other]; diff --git a/engines/grim/model.h b/engines/grim/model.h index 7c22388a21b..5a06acced55 100644 --- a/engines/grim/model.h +++ b/engines/grim/model.h @@ -98,6 +98,17 @@ public: void draw(const Mesh *mesh) const; void changeMaterial(Material *material); + bool hasTexture() const { return _texVertices != nullptr; } + + const Math::Vector3d &getNormal() const { return _normal; } + void setNormal(const Math::Vector3d &normal) { _normal = normal; } + const Material *getMaterial() const { return _material; } + int getNumVertices() const { return _numVertices; } + int getVertex(int i) const { return _vertices[i]; } + int getTextureVertex(int i) const { return _texVertices[i]; } + int getLight() const { return _light; } + +private: Material *_material; int _type, _geo, _light, _tex; float _extraLight; @@ -105,6 +116,7 @@ public: int *_vertices, *_texVertices; Math::Vector3d _normal; +public: void *_userData; };