void LitColorMaterial::_lazyInitializeShader() { //this shader contains everything the material can do (it can render something in 3d using a single color) if (!_shader) { //create _shader for lights and _shaderSS for shadows START _shader = new ShaderProgram(); _shader->addShader(GL_VERTEX_SHADER, config::MGE_SHADER_PATH+"litcolor.vs"); _shader->addShader(GL_FRAGMENT_SHADER, config::MGE_SHADER_PATH+"litcolor.fs"); _shader->finalize(); _shaderSS = new ShaderProgram(); _shaderSS->addShader(GL_VERTEX_SHADER, config::MGE_SHADER_PATH+"shadowMap.vs"); _shaderSS->addShader(GL_FRAGMENT_SHADER, config::MGE_SHADER_PATH+"shadowMap.fs"); _shaderSS->finalize(); _light_MVP2 = _shaderSS->getUniformLocation("light_MVP"); _aVertex2 = _shaderSS->getAttribLocation("vertex"); _aUV2 = _shaderSS->getAttribLocation("uv"); //create _shader for lights and _shaderSS for shadows END //SHADOW SHADER: cachee all the uniform and attribute indexes glEnable(GL_DEPTH_TEST); glGenFramebuffers(1, &FBO); for (unsigned int i = 0; i < World::Instance()->sceneLights().size(); ++i) { Texture* texture = Texture::load("ShadowTexture_" + std::to_string(i), true); _shadowTextures.push_back(texture); } glBindTexture(GL_TEXTURE_2D, _shadowTextures.at(0)->getId()); glBindFramebuffer(GL_FRAMEBUFFER, FBO); glFramebufferTexture2D(GL_FRAMEBUFFER, GL_DEPTH_ATTACHMENT, GL_TEXTURE_2D, _shadowTextures.at(0)->getId(), 0); glDrawBuffer(GL_NONE); glReadBuffer(GL_NONE); glBindFramebuffer(GL_FRAMEBUFFER, 0); int i = glCheckFramebufferStatus(GL_FRAMEBUFFER); if(i != GL_FRAMEBUFFER_COMPLETE) { std::cout << "Framebuffer is not OK, status=" << i << std::endl; } //LIGHT SHADER: cachee all the uniform and attribute indexes _uModelMatrix = _shader->getUniformLocation("modelMatrix"); _uViewMatrix = _shader->getUniformLocation("viewMatrix"); _uPerspectiveMatrix = _shader->getUniformLocation("perspectiveMatrix"); _light_MVP = _shader->getUniformLocation("light_MVP"); uCameraPosIndex = _shader->getUniformLocation ("cameraPos"); //eye|camera|view position lightsUniforArraySize = _shader->getUniformLocation ("uniformArraySize"); _aVertex = _shader->getAttribLocation("vertex"); _aNormal = _shader->getAttribLocation("normal"); _aUV = _shader->getAttribLocation("uv"); tempSize = World::Instance()->sceneLights().size(); if (tempSize > 0) { for (int i = 0; i < MAX_LIGHTS_NUM; ++i) { uGlobalAmbientIndex[i] = _shader->getUniformLocation (uniName("globalAmbient",i)); uDiffuseColorIndex[i] = _shader->getUniformLocation (uniName("diffuseColor",i)); uLightPositionIndex[i] = _shader->getUniformLocation (uniName("lightPosition",i)); uConeDirectionIndex[i] = _shader->getUniformLocation (uniName("coneDirection",i)); uConeAnglesIndex[i] = _shader->getUniformLocation (uniName("coneAngle",i)); } } } }
void Program::ExtractUniformData() { Log("\tUniform : "); char tempNameAR[1024]; GLint numUni = 0; glGetProgramInterfaceiv(_program, GL_UNIFORM, GL_ACTIVE_RESOURCES, &numUni); const GLenum propertiesAR[3] = { GL_TYPE, GL_LOCATION, GL_BLOCK_INDEX }; for (int uni = 0; uni < numUni; uni++) { GLint valuesAR[3]; glGetProgramResourceiv(_program, GL_UNIFORM, uni, 3, propertiesAR, 2, NULL, valuesAR); glGetProgramResourceName(_program, GL_UNIFORM, uni, 1024, NULL, tempNameAR); std::string uniName(tempNameAR); _uniforms.insert(std::make_pair(uniName,AttributeInfo(uniName, GLenum(valuesAR[0]), valuesAR[1], GLUtil::SizeofGLSLType(GLenum(valuesAR[0]))))); Log("\t\t" + uniName + " " + ToString(valuesAR[1]) + " " + GLUtil::GLSLTypeToStr(GLenum(valuesAR[0]))); } }