From 705d9e38753e4776502969d6a460cc7fbaced07e Mon Sep 17 00:00:00 2001 From: Faerbit Date: Mon, 9 Feb 2015 14:26:04 +0100 Subject: [PATCH] Changed cube map shadows sampler to a sampler array. --- CMakeLists.txt | 4 ++-- Shader/phong.fsh | 4 ++-- graphics.cc | 9 +++++++-- graphics.hh | 1 + 4 files changed, 12 insertions(+), 6 deletions(-) diff --git a/CMakeLists.txt b/CMakeLists.txt index caf8bbb..b4e6f5e 100644 --- a/CMakeLists.txt +++ b/CMakeLists.txt @@ -6,8 +6,8 @@ add_subdirectory(converter) PROJECT(MarbleRaceGroupC) # ACGL setup -SET(ACGL_OPENGL_SUPPORT CORE_32) -ADD_DEFINITIONS(-DACGL_OPENGL_VERSION_32) +SET(ACGL_OPENGL_SUPPORT CORE_40) +ADD_DEFINITIONS(-DACGL_OPENGL_VERSION_40) ADD_DEFINITIONS(-DACGL_OPENGL_PROFILE_CORE) # create the newest availabe OpenGL context, independent of the ACGL version: #ADD_DEFINITIONS(-DGLFW_OPENGL_LATEST_VERSION) diff --git a/Shader/phong.fsh b/Shader/phong.fsh index 984b17d..95afb30 100644 --- a/Shader/phong.fsh +++ b/Shader/phong.fsh @@ -9,7 +9,7 @@ out vec4 oColor; uniform sampler2D uTexture; uniform sampler2DShadow shadowMap; -uniform samplerCubeShadow shadowMap_cube; +uniform samplerCubeShadow shadowMap_cube[1]; uniform vec3 ambientColor; uniform float ambientFactor; uniform float diffuseFactor; @@ -113,7 +113,7 @@ void main() specularColor += clamp(pow((dot((cameraVector+lightVector),normalize(vNormal))/(length(cameraVector+lightVector)*length(normalize(vNormal)))),shininess), 0.0, 1.0) *specularFactor*intensity*lightColors[i]; if (i == 0) { - visibility = samplePointShadow(shadowMap_cube, lightDirection); + visibility = samplePointShadow(shadowMap_cube[0], lightDirection); } } /*float value = texture(shadowMap_cube, lightDirection); diff --git a/graphics.cc b/graphics.cc index bebcc31..94e27b1 100644 --- a/graphics.cc +++ b/graphics.cc @@ -66,6 +66,9 @@ void Graphics::init(Level* level) { } framebuffer_cube = SharedFrameBufferObject(new FrameBufferObject()); + + glGetIntegerv(GL_MAX_COMBINED_TEXTURE_IMAGE_UNITS, &number_of_texture_units); + printf("Your graphics card supports %d texture units.\n", number_of_texture_units); } glm::uvec2 Graphics::getWindowSize() { @@ -98,7 +101,6 @@ void Graphics::render(double time) std::vector viewMatrixVector = std::vector(); viewMatrixVector.push_back(viewMatrix); level->render(depthShader, false, &depthViewProjectionMatrix_face, &viewMatrixVector); - level->render(depthShader, false, &viewMatrix); if (!framebuffer_cube->isFrameBufferObjectComplete()) { printf("Framebuffer incomplete, unknown error occured during shadow generation!\n"); } @@ -125,7 +127,10 @@ void Graphics::render(double time) lightingShader->use(); if (level->getLights()->size() > 0) { - lightingShader->setTexture("shadowMap_cube", depth_cubeMaps.at(0), 4); + glActiveTexture(GL_TEXTURE0+2); + glBindTexture(GL_TEXTURE_CUBE_MAP, depth_cubeMaps.at(0)->getObjectName()); + GLint textureUnits[1] = {2}; + glUniform1iv(lightingShader->getUniformLocation("shadowMap_cube"), 1, textureUnits); } //set lighting parameters diff --git a/graphics.hh b/graphics.hh index 0d11513..6c3d7e2 100644 --- a/graphics.hh +++ b/graphics.hh @@ -33,6 +33,7 @@ class Graphics { ACGL::OpenGL::SharedFrameBufferObject framebuffer_cube; static const int cube_size; Level* level; + int number_of_texture_units = 0; }; #endif