ended mesh refactoring
This commit is contained in:
parent
b303c4b1ff
commit
160ebc0d2d
@ -86,26 +86,24 @@ void ForwardModule::lightPass(Camera* myCamera, Scene* scene, Light* light)
|
||||
for(SceneIterator<GeometryNode*>* geometryIt = scene->getGeometry();
|
||||
geometryIt->isValid(); geometryIt->next())
|
||||
{
|
||||
// compute matrix attributes
|
||||
GeometryNode* node = geometryIt->getItem();
|
||||
glm::mat4 modelViewMatrix = myCamera->getViewMatrix() * node->modelMatrix;
|
||||
glm::mat4 mvp = myCamera->getProjectionMatrix() * modelViewMatrix;
|
||||
glm::mat4 normalMatrix = glm::transpose(glm::inverse(modelViewMatrix));
|
||||
if(light != NULL && light->isShadowCaster())
|
||||
Material* mat = node->mesh->material;
|
||||
if(mat->getFlags() == geometryFlagList[i]) // if flag matches material
|
||||
{
|
||||
glm::mat4 lightMVP = Light::biasMatrix * light->getProjectionMatrix() * light->getViewMatrix() * node->modelMatrix;
|
||||
shader->bindMat4(shader->getLocation("lightMVP"), lightMVP);
|
||||
}
|
||||
shader->bindMat4(shader->getLocation("viewMatrix"), myCamera->getViewMatrix());
|
||||
shader->bindMat4(shader->getLocation("modelViewMatrix"), modelViewMatrix);
|
||||
shader->bindMat3(shader->getLocation("normalMatrix"), glm::mat3(normalMatrix));
|
||||
shader->bindMat4(shader->getLocation("MVP"), mvp);
|
||||
// loop over material groups
|
||||
for(int j=0; j<node->mesh->indiceGroups.size(); ++j)
|
||||
{
|
||||
Material* mat = node->getMesh()->indiceGroups[j].material;
|
||||
if(mat->getFlags() == geometryFlagList[i])
|
||||
node->mesh->draw(shader);
|
||||
// compute matrix attributes
|
||||
glm::mat4 modelViewMatrix = myCamera->getViewMatrix() * node->modelMatrix;
|
||||
glm::mat4 mvp = myCamera->getProjectionMatrix() * modelViewMatrix;
|
||||
glm::mat4 normalMatrix = glm::transpose(glm::inverse(modelViewMatrix));
|
||||
if(light != NULL && light->isShadowCaster())
|
||||
{
|
||||
glm::mat4 lightMVP = Light::biasMatrix * light->getProjectionMatrix() * light->getViewMatrix() * node->modelMatrix;
|
||||
shader->bindMat4(shader->getLocation("lightMVP"), lightMVP);
|
||||
}
|
||||
shader->bindMat4(shader->getLocation("viewMatrix"), myCamera->getViewMatrix());
|
||||
shader->bindMat4(shader->getLocation("modelViewMatrix"), modelViewMatrix);
|
||||
shader->bindMat3(shader->getLocation("normalMatrix"), glm::mat3(normalMatrix));
|
||||
shader->bindMat4(shader->getLocation("MVP"), mvp);
|
||||
node->mesh->draw(shader);
|
||||
}
|
||||
}
|
||||
}
|
||||
@ -134,12 +132,11 @@ void ForwardModule::compileShaders(Scene* scene)
|
||||
for(int i=0; i<nb_geometry_flags; ++i)
|
||||
geometryFlags[i] = false;
|
||||
|
||||
for(SceneIterator<PhongEntity*>* entityIt = scene->getGeometry();
|
||||
entityIt->isValid(); entityIt->next())
|
||||
for(SceneIterator<GeometryNode*>* geometryIt = scene->getGeometry();
|
||||
geometryIt->isValid(); geometryIt->next())
|
||||
{
|
||||
Mesh* m = entityIt->getItem()->getMesh();
|
||||
for(Mesh::Group &g : m->indiceGroups)
|
||||
geometryFlags[g.material->getFlags()] = true;
|
||||
Mesh* m = geometryIt->getItem()->mesh;
|
||||
geometryFlags[m->material->getFlags()] = true;
|
||||
}
|
||||
for(int i=0; i<nb_geometry_flags; ++i)
|
||||
{
|
||||
|
@ -102,31 +102,28 @@ void Light::generateShadowMap(Scene* scene)
|
||||
glAssert(glEnable(GL_DEPTH_TEST));
|
||||
glAssert(glDepthFunc(GL_LESS));
|
||||
glAssert(glCullFace(GL_FRONT));
|
||||
for(SceneIterator<PhongEntity*>* entityIt = scene->getGeometry();
|
||||
entityIt->isValid(); entityIt->next())
|
||||
for(SceneIterator<GeometryNode*>* geometryIt = scene->getGeometry();
|
||||
geometryIt->isValid(); geometryIt->next())
|
||||
{
|
||||
// compute matrix attributes
|
||||
PhongEntity* entity = entityIt->getItem();
|
||||
glm::mat4 lightMVP = getProjectionMatrix() * (getViewMatrix() * entity->modelMatrix);
|
||||
GeometryNode* node = geometryIt->getItem();
|
||||
glm::mat4 lightMVP = getProjectionMatrix() * (getViewMatrix() * node->modelMatrix);
|
||||
// loop over material groups
|
||||
for(int j=0; j<entity->getMesh()->indiceGroups.size(); ++j)
|
||||
Material* mat = node->mesh->material;
|
||||
if(mat->getFlags() & ALPHA_MASK_FLAG)
|
||||
{
|
||||
Material* mat = entity->getMesh()->indiceGroups[j].material;
|
||||
if(mat->getFlags() & ALPHA_MASK_FLAG)
|
||||
{
|
||||
PhongMaterial* pmat = (PhongMaterial*)mat;
|
||||
shaders[1]->bind();
|
||||
pmat->alpha_mask->bind(ALPHA_MASK);
|
||||
shaders[1]->bindMat4(shaders[1]->getLocation("MVP"), lightMVP);
|
||||
shaders[1]->bindInteger(shaders[1]->getLocation("alphaMask"), ALPHA_MASK);
|
||||
entity->drawGroup(j, false, true, false);
|
||||
}
|
||||
else
|
||||
{
|
||||
entity->drawGroup(j, false, false, false);
|
||||
shaders[0]->bind();
|
||||
shaders[0]->bindMat4(shaders[1]->getLocation("MVP"), lightMVP);
|
||||
}
|
||||
PhongMaterial* pmat = (PhongMaterial*)mat;
|
||||
shaders[1]->bind();
|
||||
pmat->alpha_mask->bind(ALPHA_MASK);
|
||||
shaders[1]->bindMat4(shaders[1]->getLocation("MVP"), lightMVP);
|
||||
shaders[1]->bindInteger(shaders[1]->getLocation("alphaMask"), ALPHA_MASK);
|
||||
node->mesh->draw(shaders[1], false, true, false);
|
||||
}
|
||||
else
|
||||
{
|
||||
shaders[0]->bind();
|
||||
shaders[0]->bindMat4(shaders[1]->getLocation("MVP"), lightMVP);
|
||||
node->mesh->draw(shaders[0], false, false, false);
|
||||
}
|
||||
}
|
||||
glAssert(glCullFace(GL_BACK));
|
||||
|
15
src/mesh.cpp
15
src/mesh.cpp
@ -3,6 +3,9 @@
|
||||
#include <set>
|
||||
#include "glassert.h"
|
||||
#include "sparrowrenderer.h"
|
||||
#include "material.h"
|
||||
|
||||
#define BUFFER_OFFSET(i) ((char *)NULL + (i))
|
||||
|
||||
Mesh::Mesh() :
|
||||
material(NULL),
|
||||
@ -28,11 +31,11 @@ void Mesh::initGL(bool isDynamic)
|
||||
glAssert(glBindVertexArray(vao));
|
||||
|
||||
nb_buffers = 2; // positions and indices buffers
|
||||
if(mesh->hasNormals())
|
||||
if(hasNormals())
|
||||
++nb_buffers;
|
||||
if(mesh->hasTexCoords())
|
||||
if(hasTexCoords())
|
||||
++nb_buffers;
|
||||
if(mesh->hasTangents())
|
||||
if(hasTangents())
|
||||
++nb_buffers;
|
||||
|
||||
// create VBOs
|
||||
@ -75,7 +78,7 @@ void Mesh::initGL(bool isDynamic)
|
||||
void Mesh::draw(Shader* shader, bool drawNormals, bool drawTexCoord, bool drawTangents)
|
||||
{
|
||||
bool crappy = (shader == NULL);
|
||||
material.bindAttributes(shader);
|
||||
material->bindAttributes(shader);
|
||||
glAssert(glBindVertexArray(vao));
|
||||
glAssert(glBindBuffer(GL_ARRAY_BUFFER, vbo[POSITION_BUFFER]));
|
||||
if(crappy)
|
||||
@ -154,7 +157,7 @@ struct VertexComparator
|
||||
{
|
||||
// c'est plutot crade mais j'ai pas trouve d'autre moyen pour le moment
|
||||
static Mesh* mesh;
|
||||
static void setMesh(MeshBuilder* m) {VertexComparator::mesh = m;}
|
||||
static void setMesh(Mesh* m) {VertexComparator::mesh = m;}
|
||||
|
||||
bool operator() (const int& vertId1, const int& vertId2) const
|
||||
{
|
||||
@ -198,7 +201,7 @@ void Mesh::mergeVertices()
|
||||
{
|
||||
if(indices[i] >= positions.size())
|
||||
indices[i] = swapped[swappedOffset - indices[i]];
|
||||
std::pair<std::set<int,VertexComparator>::iterator,bool> ret = vertexSet.insert(g.indices[i]);
|
||||
std::pair<std::set<int,VertexComparator>::iterator,bool> ret = vertexSet.insert(indices[i]);
|
||||
if(!ret.second) // duplicate found
|
||||
{
|
||||
// updating indices references
|
||||
|
@ -13,6 +13,7 @@ struct Mesh
|
||||
{
|
||||
protected:
|
||||
|
||||
public: // TODO : see if there is a way to set this protected
|
||||
// geometry data
|
||||
|
||||
typedef struct
|
||||
@ -21,6 +22,7 @@ protected:
|
||||
glm::vec3 binormal;
|
||||
} Tangents;
|
||||
|
||||
|
||||
Material* material;
|
||||
|
||||
std::vector<glm::vec3> positions;
|
||||
@ -29,6 +31,8 @@ protected:
|
||||
std::vector<Tangents> tangents;
|
||||
std::vector<unsigned int> indices;
|
||||
|
||||
protected:
|
||||
|
||||
// opengl
|
||||
|
||||
enum {
|
||||
|
Loading…
x
Reference in New Issue
Block a user