Add extra skyboxes
[opengl.git] / model.cpp
index c9ecdc16d01e6d1ca72ba6016f42695759cccc41..ee1159532728a0a834705fa9de8eb9dd91c35932 100644 (file)
--- a/model.cpp
+++ b/model.cpp
@@ -1,5 +1,4 @@
 #include "model.hpp"
-#include "error.hpp"
 #include <iostream>
 #include <assimp/postprocess.h>
 #include <glm/gtc/type_ptr.hpp>
@@ -18,7 +17,8 @@ Model::Mesh::Mesh(const aiMesh *aiMesh, GLuint progId) {
                        aiVector3D v = aiMesh->mNormals[i];
                        normals.push_back(glm::vec3(v.x, v.y, v.z));
                } else {
-                       normals.push_back(glm::vec3(0));
+                       std::cerr << "Missing normals" << std::endl;
+                       exit(1);
                }
                if (aiMesh->HasTangentsAndBitangents()) {
                        aiVector3D t = aiMesh->mTangents[i];
@@ -78,17 +78,17 @@ Model::Mesh::Mesh(const aiMesh *aiMesh, GLuint progId) {
        glEnableVertexAttribArray(texCoordLoc);
        glVertexAttribPointer(texCoordLoc, 2, GL_FLOAT, GL_FALSE, 0, 0);
 
-       GLuint tangentLoc = glGetAttribLocation(progId, "tangent");
-       glBindBuffer(GL_ARRAY_BUFFER, tangentVbo);
-       glBufferData(GL_ARRAY_BUFFER, tangents.size() * sizeof(glm::vec3), &tangents[0], GL_STATIC_DRAW);
-       glEnableVertexAttribArray(tangentLoc);
-       glVertexAttribPointer(tangentLoc, 3, GL_FLOAT, GL_FALSE, 0, 0);
+       /* GLuint tangentLoc = glGetAttribLocation(progId, "tangent"); */
+       /* glBindBuffer(GL_ARRAY_BUFFER, tangentVbo); */
+       /* glBufferData(GL_ARRAY_BUFFER, tangents.size() * sizeof(glm::vec3), &tangents[0], GL_STATIC_DRAW); */
+       /* glEnableVertexAttribArray(tangentLoc); */
+       /* glVertexAttribPointer(tangentLoc, 3, GL_FLOAT, GL_FALSE, 0, 0); */
 
-       GLuint bitangentLoc = glGetAttribLocation(progId, "bitangent");
-       glBindBuffer(GL_ARRAY_BUFFER, bitangentVbo);
-       glBufferData(GL_ARRAY_BUFFER, bitangents.size() * sizeof(glm::vec3), &bitangents[0], GL_STATIC_DRAW);
-       glEnableVertexAttribArray(bitangentLoc);
-       glVertexAttribPointer(bitangentLoc, 3, GL_FLOAT, GL_FALSE, 0, 0);
+       /* GLuint bitangentLoc = glGetAttribLocation(progId, "bitangent"); */
+       /* glBindBuffer(GL_ARRAY_BUFFER, bitangentVbo); */
+       /* glBufferData(GL_ARRAY_BUFFER, bitangents.size() * sizeof(glm::vec3), &bitangents[0], GL_STATIC_DRAW); */
+       /* glEnableVertexAttribArray(bitangentLoc); */
+       /* glVertexAttribPointer(bitangentLoc, 3, GL_FLOAT, GL_FALSE, 0, 0); */
 
        glBindBuffer(GL_ELEMENT_ARRAY_BUFFER, indicesVbo);
        glBufferData(GL_ELEMENT_ARRAY_BUFFER, indices.size() * sizeof(GLuint), &indices[0], GL_STATIC_DRAW);
@@ -127,9 +127,17 @@ void Model::Node::draw(    const std::vector<Mesh> &meshes,
                Material material = materials[mesh.materialIndex];
                material.bind();
 
-               glUniform1i(glGetUniformLocation(progId, "skybox"), 5);
+               glUniform1i(glGetUniformLocation(progId, "irradianceMap"), 4);
+               glActiveTexture(GL_TEXTURE4);
+               glBindTexture(GL_TEXTURE_CUBE_MAP, skybox.getIrradianceMap());
+
+               glUniform1i(glGetUniformLocation(progId, "prefilterMap"), 5);
                glActiveTexture(GL_TEXTURE5);
-               glBindTexture(GL_TEXTURE_CUBE_MAP, skybox.getTexture());
+               glBindTexture(GL_TEXTURE_CUBE_MAP, skybox.getPrefilterMap());
+
+               glUniform1i(glGetUniformLocation(progId, "brdfMap"), 6);
+               glActiveTexture(GL_TEXTURE6);
+               glBindTexture(GL_TEXTURE_2D, skybox.getBRDFMap());
                
                glUniformMatrix4fv(modelLoc, 1, GL_FALSE, glm::value_ptr(m));
 
@@ -138,7 +146,7 @@ void Model::Node::draw(     const std::vector<Mesh> &meshes,
        for (Node *child: children) child->draw(meshes, materials, skybox, m);
 }
 
-Model::Model(const std::string &path, Program p, Skybox s): program(p), skybox(s) {
+Model::Model(const std::string &path, Program p): program(p) {
        glUseProgram(p.progId);
        
        const aiScene *scene = importer.ReadFile(path, 
@@ -161,7 +169,7 @@ Model::Model(const std::string &path, Program p, Skybox s): program(p), skybox(s
        root = new Node(*(scene->mRootNode), p.progId);
 }
 
-void Model::draw() const {
+void Model::draw(Skybox skybox) const {
        glUseProgram(program.progId);
        root->draw(meshes, materials, skybox);
        program.validate();