X-Git-Url: http://git.lukelau.me/?p=opengl.git;a=blobdiff_plain;f=skybox.cpp;h=1c99e9588e1c1abd182525ae1bf537607ab2325d;hp=3bf5f40ed679346a5babbc1f3190451f2976c925;hb=b91a0d30ae6484b6c4d981aeafa8d4996c98effe;hpb=ceae87033f199ea0288399b5876fa4d1451eae3e diff --git a/skybox.cpp b/skybox.cpp index 3bf5f40..1c99e95 100644 --- a/skybox.cpp +++ b/skybox.cpp @@ -6,8 +6,8 @@ template GLuint setupVertices(GLuint progId, std::array 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; @@ -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