From ffcfaf9a2c6968e1a6a41a7f7068a6c5434757e3 Mon Sep 17 00:00:00 2001 From: Faerbit Date: Mon, 15 Dec 2014 14:57:18 +0100 Subject: [PATCH] Commiting broken shit, because stuff. --- graphics.cc | 46 +++++++++++++++++++++++----------------------- graphics.hh | 1 + 2 files changed, 24 insertions(+), 23 deletions(-) diff --git a/graphics.cc b/graphics.cc index 8f35b41..55e236d 100644 --- a/graphics.cc +++ b/graphics.cc @@ -70,17 +70,18 @@ void Graphics::init(Level* level) { framebuffer_far->setDepthTexture(depthTexture_far); framebuffer_far->validate(); - depth_cubeMaps = std::vector(level->getLights()->size()); - for (unsigned int i = 0; isetMinFilter(GL_NEAREST); - depth_cubeMaps.at(i)->setMagFilter(GL_NEAREST); - depth_cubeMaps.at(i)->setWrapS(GL_CLAMP_TO_EDGE); - depth_cubeMaps.at(i)->setWrapT(GL_CLAMP_TO_EDGE); - depth_cubeMaps.at(i)->setCompareMode(GL_COMPARE_REF_TO_TEXTURE); - } - framebuffer_cube = SharedFrameBufferObject(new FrameBufferObject()); + glGenTextures(1, &cubeMapArrays); + glBindTexture(GL_TEXTURE_CUBE_MAP_ARRAY, cubeMapArrays); + for (unsigned int i_pointlight = 0; i_pointlightgetLights()->size(); i_pointlight++) { + glTexImage3D(GL_TEXTURE_CUBE_MAP_ARRAY, i_pointlight, GL_RED, cube_size, cube_size, level->getLights()->size()*6, 0, GL_RED, GL_FLOAT, NULL); + } + glTexParameteri(GL_TEXTURE_CUBE_MAP_ARRAY, GL_TEXTURE_MIN_FILTER, GL_NEAREST); + glTexParameteri(GL_TEXTURE_CUBE_MAP_ARRAY, GL_TEXTURE_MAG_FILTER, GL_NEAREST); + glTexParameteri(GL_TEXTURE_CUBE_MAP_ARRAY, GL_TEXTURE_WRAP_S, GL_CLAMP_TO_EDGE); + glTexParameteri(GL_TEXTURE_CUBE_MAP_ARRAY, GL_TEXTURE_WRAP_T, GL_CLAMP_TO_EDGE); + glTexParameteri(GL_TEXTURE_CUBE_MAP_ARRAY, GL_TEXTURE_WRAP_R, GL_CLAMP_TO_EDGE); + glTexParameteri(GL_TEXTURE_CUBE_MAP_ARRAY, GL_TEXTURE_COMPARE_MODE, GL_COMPARE_REF_TO_TEXTURE); } GLFWwindow* Graphics::getWindow() { @@ -105,17 +106,16 @@ void Graphics::render() for (unsigned int i_pointlight = 0; i_pointlightgetLights()->size(); i_pointlight++) { // render each side of the cube for (int i_face = 0; i_face<6; i_face++) { - glFramebufferTexture2D(GL_FRAMEBUFFER, GL_DEPTH_ATTACHMENT, GL_TEXTURE_CUBE_MAP_POSITIVE_X + i_face, depth_cubeMaps.at(i_pointlight)->getObjectName(), 0); - glClear(GL_DEPTH_BUFFER_BIT); + //glFramebufferTextureLayer(GL_DRAW_FRAMEBUFFER, GL_DEPTH_ATTACHMENT, cubeMapArrays, i_pointlight, i_face); + glClear(GL_COLOR_BUFFER_BIT | GL_DEPTH_BUFFER_BIT); glm::mat4 depthViewProjectionMatrix_face = depthProjectionMatrix_pointlights * glm::lookAt(level->getLights()->at(i_pointlight).getPosition(), level->getLights()->at(i_pointlight).getPosition() + looking_directions[i_face], glm::vec3(0.0f, 1.0f, 0.0f)); - depthShader->setUniform("viewProjectionMatrix", depthViewProjectionMatrix_face); - level->render(depthShader, false, &depthViewProjectionMatrix_face); - if (!framebuffer_cube->isFrameBufferObjectComplete()) { - printf("Framebuffer incomplete, unknown error occured during shadow generation!\n"); - } + //level->render(depthShader, false, &depthViewProjectionMatrix_face); } } + if (!framebuffer_cube->isFrameBufferObjectComplete()) { + printf("Framebuffer incomplete, unknown error occured during shadow generation!\n"); + } // render depth texture for sun glViewport(0, 0, windowSize.x, windowSize.y); // near pass @@ -125,9 +125,9 @@ void Graphics::render() glm::mat4 depthViewProjectionMatrix_near = glm::ortho(-5, 5, -5, 5, -5, 5) * glm::lookAt(sunVector, level->getCameraCenter()->getPosition(), glm::vec3(0,1,0)); level->render(depthShader, false, &depthViewProjectionMatrix_near); - if (!framebuffer_near->isFrameBufferObjectComplete()) { + /*if (!framebuffer_near->isFrameBufferObjectComplete()) { printf("Framebuffer incomplete, unknown error occured during shadow generation!\n"); - } + }*/ // middle pass framebuffer_middle->bind(); @@ -135,9 +135,9 @@ void Graphics::render() glm::mat4 depthViewProjectionMatrix_middle = glm::ortho(-20, 20, -20, 20, -20, 20) * glm::lookAt(sunVector, level->getCameraCenter()->getPosition(), glm::vec3(0,1,0)); level->render(depthShader, false, &depthViewProjectionMatrix_middle); - if (!framebuffer_middle->isFrameBufferObjectComplete()) { + /*if (!framebuffer_middle->isFrameBufferObjectComplete()) { printf("Framebuffer incomplete, unknown error occured during shadow generation!\n"); - } + }*/ // far pass framebuffer_far->bind(); @@ -145,9 +145,9 @@ void Graphics::render() glm::mat4 depthViewProjectionMatrix_far = glm::ortho(-farPlane/2.0f, farPlane/2.0f, -farPlane/2.0f, farPlane/2.0f, -farPlane/2.0f, farPlane/2.0f) * glm::lookAt(sunVector, level->getCameraCenter()->getPosition(), glm::vec3(0,1,0)); level->render(depthShader, false, &depthViewProjectionMatrix_far); - if (!framebuffer_far->isFrameBufferObjectComplete()) { + /*if (!framebuffer_far->isFrameBufferObjectComplete()) { printf("Framebuffer incomplete, unknown error occured during shadow generation!\n"); - } + }*/ // final render pass glBindFramebuffer(GL_FRAMEBUFFER, 0); diff --git a/graphics.hh b/graphics.hh index 416f5ce..353d91a 100644 --- a/graphics.hh +++ b/graphics.hh @@ -38,6 +38,7 @@ class Graphics { ACGL::OpenGL::SharedFrameBufferObject framebuffer_cube; static const int cube_size; Level* level; + GLuint cubeMapArrays; }; #endif