Circular cursor + dragging
[opengl.git] / skybox.cpp
index d668d76d7025fc1f865ba477632ade63b72d7f85..1c99e9588e1c1abd182525ae1bf537607ab2325d 100644 (file)
@@ -6,8 +6,8 @@ template <std::size_t N>
 GLuint setupVertices(GLuint progId, std::array<glm::vec3, N> vertices, bool reverse = false);
 
 // matrices used when capturing various environment maps
-glm::mat4 captureProj = glm::perspective(glm::radians(90.f), 1.f, 0.1f, 10.f);
-glm::mat4 captureViews[] = {
+const glm::mat4 captureProj = glm::perspective(glm::radians(90.f), 1.f, 0.1f, 10.f);
+const glm::mat4 captureViews[] = {
        glm::lookAt(glm::vec3(0, 0, 0), glm::vec3( 1,  0,  0), glm::vec3(0, -1,  0)),
        glm::lookAt(glm::vec3(0, 0, 0), glm::vec3(-1,  0,  0), glm::vec3(0, -1,  0)),
        glm::lookAt(glm::vec3(0, 0, 0), glm::vec3( 0,  1,  0), glm::vec3(0,  0,  1)),
@@ -19,7 +19,7 @@ glm::mat4 captureViews[] = {
 void Skybox::generatePrefilterMap() const {
        glBindTexture(GL_TEXTURE_CUBE_MAP, prefilterTexId);
        for (GLuint i = 0; i < 6; i++)
-               glTexImage2D(GL_TEXTURE_CUBE_MAP_POSITIVE_X + i, 0 , GL_RGB16F, 128, 128, 0, GL_RGB, GL_FLOAT, nullptr);
+               glTexImage2D(GL_TEXTURE_CUBE_MAP_POSITIVE_X + i, 0 , GL_RGB16F, 128, 128, 0, GL_RGB, GL_HALF_FLOAT, nullptr);
        glTexParameteri(GL_TEXTURE_CUBE_MAP, GL_TEXTURE_WRAP_S, GL_CLAMP_TO_EDGE);
        glTexParameteri(GL_TEXTURE_CUBE_MAP, GL_TEXTURE_WRAP_T, GL_CLAMP_TO_EDGE);
        glTexParameteri(GL_TEXTURE_CUBE_MAP, GL_TEXTURE_WRAP_R, GL_CLAMP_TO_EDGE);
@@ -35,7 +35,7 @@ void Skybox::generatePrefilterMap() const {
        glActiveTexture(GL_TEXTURE0);
        glBindTexture(GL_TEXTURE_CUBE_MAP, cubemapTexId);
        
-       setupVertices(prefilterProg.progId, cube());
+       setupVertices(prefilterProg.progId, cubeArray());
        
        glBindFramebuffer(GL_FRAMEBUFFER, captureFBO);
        constexpr GLuint MAX_MIP_LEVELS = 5;
@@ -95,7 +95,7 @@ Skybox::Skybox(const Image img): program("skyboxvert.glsl", "skyboxfrag.glsl") {
        
        glBindTexture(GL_TEXTURE_2D, hdrTexId);
 
-       glTexImage2D(GL_TEXTURE_2D, 0, GL_RGB16F, img.width(), img.height(), 0, GL_RGB, GL_HALF_FLOAT, (uint16_t*)img.data());
+       glTexImage2D(GL_TEXTURE_2D, 0, img.internalFormat(), img.width(), img.height(), 0, img.format(), img.type(), img.data());
 
        glTexParameteri(GL_TEXTURE_2D, GL_TEXTURE_MIN_FILTER, GL_LINEAR);
        glTexParameteri(GL_TEXTURE_2D, GL_TEXTURE_MAG_FILTER, GL_LINEAR);
@@ -116,7 +116,7 @@ Skybox::Skybox(const Image img): program("skyboxvert.glsl", "skyboxfrag.glsl") {
        // setup cubemap texture
        glBindTexture(GL_TEXTURE_CUBE_MAP, cubemapTexId);
        for (GLuint i = 0; i < 6; i++)
-               glTexImage2D(GL_TEXTURE_CUBE_MAP_POSITIVE_X + i, 0, GL_RGB16F, CUBEMAP_WIDTH, CUBEMAP_HEIGHT, 0, GL_RGB, GL_FLOAT, nullptr);
+               glTexImage2D(GL_TEXTURE_CUBE_MAP_POSITIVE_X + i, 0, GL_RGB16F, CUBEMAP_WIDTH, CUBEMAP_HEIGHT, 0, GL_RGB, GL_HALF_FLOAT, nullptr);
        glTexParameteri(GL_TEXTURE_CUBE_MAP, GL_TEXTURE_WRAP_S, GL_CLAMP_TO_EDGE);
        glTexParameteri(GL_TEXTURE_CUBE_MAP, GL_TEXTURE_WRAP_T, GL_CLAMP_TO_EDGE);
        glTexParameteri(GL_TEXTURE_CUBE_MAP, GL_TEXTURE_WRAP_R, GL_CLAMP_TO_EDGE);
@@ -124,7 +124,7 @@ Skybox::Skybox(const Image img): program("skyboxvert.glsl", "skyboxfrag.glsl") {
        glTexParameteri(GL_TEXTURE_CUBE_MAP, GL_TEXTURE_MAG_FILTER, GL_LINEAR);
 
        // generate vertices
-       setupVertices(equiProg.progId, cube());
+       setupVertices(equiProg.progId, cubeArray());
 
        // render the cube
 
@@ -145,7 +145,7 @@ Skybox::Skybox(const Image img): program("skyboxvert.glsl", "skyboxfrag.glsl") {
        // setup irradiance map texture
        glBindTexture(GL_TEXTURE_CUBE_MAP, irradianceTexId);
        for (GLuint i = 0; i < 6; i++)
-               glTexImage2D(GL_TEXTURE_CUBE_MAP_POSITIVE_X + i, 0, GL_RGB16F, 32, 32, 0, GL_RGB, GL_FLOAT, nullptr);
+               glTexImage2D(GL_TEXTURE_CUBE_MAP_POSITIVE_X + i, 0, GL_RGB16F, 32, 32, 0, GL_RGB, GL_HALF_FLOAT, nullptr);
        glTexParameteri(GL_TEXTURE_CUBE_MAP, GL_TEXTURE_WRAP_S, GL_CLAMP_TO_EDGE);
        glTexParameteri(GL_TEXTURE_CUBE_MAP, GL_TEXTURE_WRAP_T, GL_CLAMP_TO_EDGE);
        glTexParameteri(GL_TEXTURE_CUBE_MAP, GL_TEXTURE_WRAP_R, GL_CLAMP_TO_EDGE);
@@ -165,7 +165,7 @@ Skybox::Skybox(const Image img): program("skyboxvert.glsl", "skyboxfrag.glsl") {
        glBindTexture(GL_TEXTURE_CUBE_MAP, cubemapTexId);
 
        // generate vertices
-       setupVertices(irradianceProg.progId, cube());
+       setupVertices(irradianceProg.progId, cubeArray());
 
        // render irradiance map
        glViewport(0, 0, 32, 32);
@@ -186,7 +186,7 @@ Skybox::Skybox(const Image img): program("skyboxvert.glsl", "skyboxfrag.glsl") {
        glDepthFunc(GL_LEQUAL);
 
        // reverse so facing inside out
-       vao = setupVertices(program.progId, cube(), true);
+       vao = setupVertices(program.progId, cubeArray(), true);
 
        // restore default framebuffer
        glBindFramebuffer(GL_FRAMEBUFFER, 0);
@@ -207,8 +207,6 @@ void Skybox::draw(glm::mat4 proj, glm::mat4 view) const {
        glActiveTexture(GL_TEXTURE0);
        glBindTexture(GL_TEXTURE_CUBE_MAP, cubemapTexId);
        glDrawArrays(GL_TRIANGLES, 0, 36);
-
-       if (glGetError()) exit(1);
 }
 
 template <std::size_t N>