YUV420PGrabber::~YUV420PGrabber() { deleteShader(frag_y); deleteShader(vert_yuv); deleteShader(frag_u); deleteShader(frag_v); deleteShader(frag_pt); deleteProgram(prog_y); deleteProgram(prog_u); deleteProgram(prog_v); deleteProgram(prog_pt); deleteTexture(yuv_tex); deleteTexture(scene_tex); if(scene_fbo) { glDeleteFramebuffers(1, &scene_fbo); } if(scene_depth) { glDeleteRenderbuffers(1, &scene_depth); } if(vao) { #if YUV420P_USE_APPLE_VAO glDeleteVertexArraysAPPLE(1, &vao); #else glDeleteVertexArrays(1, &vao); #endif } if(outfile_set && ofs.is_open()) { ofs.close(); } if(image) { delete[] image; } outfile_set = false; win_w = 0; win_h = 0; vid_w = 0; vid_h = 0; uv_w = 0; uv_h = 0; yuv_tex = 0; scene_fbo = 0; scene_depth = 0; scene_tex = 0; vao = 0; fps = 0; tex_w = 0; tex_h = 0; image = NULL; frame_timeout = 0; frame_prev_timeout = 0; frame_delay = 0; frame_delay_adjusted = 0; frame_diff = 0; frame_diff_avg = 0; }
GLuint Shader::reload(void) { // Loesche den Shader Code aus dem Grafikspeicher und weise allen IDs den Wert 0 zu: deleteShader(); m_VertexShader = 0; m_FragmentShader = 0; m_ShaderProgram = 0; // Create vertex shader m_VertexShader = createShader( GL_VERTEX_SHADER, m_VertexShaderFilename.c_str() ); if(m_VertexShader == 0) { return 0; } // Create fragment shader m_FragmentShader = createShader( GL_FRAGMENT_SHADER, m_FragmentShaderFilename.c_str() ); if(m_FragmentShader == 0) { return 0; } // Generate shader program m_ShaderProgram = createShaderProgram( m_VertexShader, m_FragmentShader ); if(m_ShaderProgram == 0) { return 0; } // No errors return 1; }
ResourceManager::~ResourceManager() { while (!mBufferMap.empty()) { deleteBuffer(mBufferMap.begin()->first); } while (!mProgramMap.empty()) { deleteProgram(mProgramMap.begin()->first); } while (!mShaderMap.empty()) { deleteShader(mShaderMap.begin()->first); } while (!mRenderbufferMap.empty()) { deleteRenderbuffer(mRenderbufferMap.begin()->first); } while (!mTextureMap.empty()) { deleteTexture(mTextureMap.begin()->first); } }
bool loadShaderCode(const char* vertProgramCode, GLuint &vertProgram, const char* fragmentProgramCode, GLuint &fragProgram) { vertProgram = loadShaderFile(vertProgramCode, GL_VERTEX_SHADER); fragProgram = loadShaderFile(fragmentProgramCode, GL_FRAGMENT_SHADER); if (vertProgram == 0) { std::cout << "(initShader) - Could not create vertex shader." << std::endl; deleteShader(); return false; } if (fragProgram == 0) { std::cout << "(initShader) - Could not create fragment shader." << std::endl; deleteShader(); return false; } return true; }
Program::Program(const string& folder, const string& vertex_file, const string& fragment_file, std::initializer_list<std::pair<uint32_t, string>> attributes, std::initializer_list<string> pre_processor) { uint32_t vertexID = compileShader(folder, vertex_file, GL_VERTEX_SHADER, pre_processor); uint32_t fragmentID = compileShader(folder, fragment_file, GL_FRAGMENT_SHADER, pre_processor); m_program = createProgram(vertexID, fragmentID); m_vertex_name = vertex_file; m_fragment_name = fragment_file; for (auto& attribute : attributes) { glBindAttribLocation(m_program, attribute.first, attribute.second.c_str()); } linkProgram(m_program); deleteShader(m_program, vertexID); deleteShader(m_program, fragmentID); }
void GLC_SelectionMaterial::setShaders(QFile& vertex, QFile& fragment, const QGLContext* pContext) { if (m_SelectionShaderHash.contains(pContext)) { deleteShader(pContext); } GLC_Shader* pShader= new GLC_Shader; pShader->setVertexAndFragmentShader(vertex, fragment); m_SelectionShaderHash.insert(pContext, pShader); }
/* Create a new program and links the shader */ GLvoid Shader::linkProgram() { uiProgramID = glCreateProgram(); glAttachShader(uiProgramID, iVertexShaderHandle); glAttachShader(uiProgramID, iFragmentShaderHandle); glLinkProgram(uiProgramID); GLint errorProgram = getLog(uiProgramID); if (errorProgram > 0) { uiProgramID = -1; deleteShader(); return ; } glDetachShader(uiProgramID, iVertexShaderHandle); glDetachShader(uiProgramID, iFragmentShaderHandle); deleteShader(); }
void ShaderProgramManager::reset(const Context *context) { while (!mPrograms.empty()) { deleteProgram(context, mPrograms.begin()->first); } mPrograms.clear(); while (!mShaders.empty()) { deleteShader(context, mShaders.begin()->first); } mShaders.clear(); }
int Shader::remakeShader(GLuint &vShader, GLuint &fShader, GLuint &aProgram) { aProgram = compileShader(vShader, fShader); if (aProgram == 0) { std::cerr << "Failed to compile shader into a program, keeping old shader." << std::endl; return 0; } else { deleteShader(); enactShader(vShader, fShader, aProgram); return 1; } }
void PtexViewer::makeShader() { deleteShader(); const char *vs = "void main( void ) { gl_Position = ftransform(); gl_TexCoord[0] = gl_MultiTexCoord0; }"; const char *fs = "varying vec4 gl_TexCoord[4]; \ uniform sampler2DARRAY tex; \ void main( void ) { \ gl_FragColor = tex2DARRAY(tex,gl_TexCoord[0].xyz);\ }";
void Renderer::clear(){ int index; reset(); apply(); resetTextureUnits(); index = textures.getCount(); while (index--) deleteTexture(index); index = shaders.getCount(); while (index--) deleteShader(index); }
GLvoid Shader::compileShaders(const GLchar *pVertexFilePath, const GLchar *pFragmentFilePath) { iVertexShaderHandle = loadShader(GL_VERTEX_SHADER, pVertexFilePath); assert(iVertexShaderHandle != -1); iFragmentShaderHandle = loadShader(GL_FRAGMENT_SHADER, pFragmentFilePath); if (iFragmentShaderHandle == -1) { glDeleteShader(iVertexShaderHandle); bCompiled = GL_FALSE; return ; } /*if (iVertexShaderHandle ==-1 || iFragmentShaderHandle==-1) { bCompiled=GL_FALSE; return ; }*/ char const* vertexSourcePointer = sVertexShaderCode.c_str(); glShaderSource(iVertexShaderHandle, 1, &vertexSourcePointer, NULL); glCompileShader(iVertexShaderHandle); GLint errorVertex = getLog(iVertexShaderHandle); char const* fragmentSourcePointer = sFragmentShaderCode.c_str(); glShaderSource(iFragmentShaderHandle, 1, &fragmentSourcePointer, NULL); glCompileShader(iFragmentShaderHandle); GLint errorFragment = getLog(iFragmentShaderHandle); if ( (errorVertex > 1) || (errorFragment > 1) ) { bCompiled = GL_FALSE; deleteShader(); return ; } linkProgram(); bCompiled = (uiProgramID != -1); /*if(uiProgramID==-1) { bCompiled=GL_FALSE; return ; } bCompiled=GL_TRUE;*/ }
void initShader() { shaderProgram = glCreateProgram(); // check if operation failed // if (shaderProgram == 0) { std::cout << "(initShader) - Failed creating shader program." << std::endl; return; } GLuint vertexShader = loadShaderFile("../shader/simple.vert", GL_VERTEX_SHADER); if (vertexShader == 0) { std::cout << "(initShader) - Could not create vertex shader." << std::endl; deleteShader(); return; } GLuint fragmentShader = loadShaderFile("../shader/simple.frag", GL_FRAGMENT_SHADER); if (fragmentShader == 0) { std::cout << "(initShader) - Could not create vertex shader." << std::endl; deleteShader(); return; } // successfully loaded and compiled shaders -> attach them to program // glAttachShader(shaderProgram, vertexShader); glAttachShader(shaderProgram, fragmentShader); // mark shaders for deletion after clean up (they will be deleted, when detached from all shader programs) // glDeleteShader(vertexShader); glDeleteShader(fragmentShader); // link shader program // glLinkProgram(shaderProgram); // set address of fragment color output // glBindFragDataLocation(shaderProgram, 0, "color"); }
int main (int argc, char **argv) { glutInit(&argc, argv); // Done TODO: activate stencil buffer // glutInitDisplayMode(GLUT_DOUBLE | GLUT_RGB | GLUT_DEPTH | GLUT_STENCIL); glutInitContextVersion(3,3); glutInitContextFlags(GLUT_FORWARD_COMPATIBLE); glutInitContextProfile(GLUT_CORE_PROFILE); windowWidth = 512; windowHeight = 512; glutInitWindowSize(windowWidth, windowHeight); glutInitWindowPosition(100, 100); glutCreateWindow("Exercise 10 - Shadow Volumes"); glutDisplayFunc(updateGL); glutIdleFunc(idle); glutKeyboardFunc(keyboardEvent); glutMouseFunc(mouseEvent); glutMotionFunc(mouseMoveEvent); glewExperimental = GL_TRUE; GLenum err = glewInit(); if (GLEW_OK != err) { std::cout << "(glewInit) - Error: " << glewGetErrorString(err) << std::endl; } std::cout << "(glewInit) - Using GLEW " << glewGetString(GLEW_VERSION) << std::endl; // init stuff // initGL(); // init matrix stacks with identity // glm_ProjectionMatrix.push(glm::mat4(1)); glm_ModelViewMatrix.push(glm::mat4(1)); initShader(); initScene(); // start render loop // if (enableShader()) { glutMainLoop(); disableShader(); // clean up allocated data // deleteShader(); } return 0; }
int main (int argc, char **argv) { glutInit(&argc, argv); glutInitDisplayMode(GLUT_DOUBLE | GLUT_RGB | GLUT_DEPTH); glutInitContextVersion(3,3); glutInitContextFlags(GLUT_FORWARD_COMPATIBLE); glutInitContextProfile(GLUT_CORE_PROFILE); glutInitWindowSize (512, 512); glutInitWindowPosition (100, 100); glutCreateWindow("Exercise 03 - More Bunnies!"); glutDisplayFunc(updateGL); glutIdleFunc(idle); glutKeyboardFunc(keyboardEvent); glewExperimental = GL_TRUE; GLenum err = glewInit(); if (GLEW_OK != err) { std::cout << "(glewInit) - Error: " << glewGetErrorString(err) << std::endl; } std::cout << "(glewInit) - Using GLEW " << glewGetString(GLEW_VERSION) << std::endl; // init stuff // initGL(); // init matrix stacks // glm_ProjectionMatrix.push(glm::mat4(2.414214, 0.000000, 0.000000, 0.000000, 0.000000, 2.414214, 0.000000, 0.000000, 0.000000, 0.000000, -1.002002, -1.000000, 0.000000, 0.000000, -0.020020, 0.000000)); glm_ModelViewMatrix.push(glm::mat4(0.707107, -0.408248, 0.577350, 0.000000, 0.000000, 0.816497, 0.577350, 0.000000, -0.707107, -0.408248, 0.577350, 0.000000, 0.000000, 0.000000, -1.732051, 1.000000)); initShader(); initScene(); // start render loop // if (enableShader()) { glutMainLoop(); disableShader(); // clean up allocated data // deleteScene(); deleteShader(); } return 0; }
ResourceManager::~ResourceManager() { while (!mBufferMap.empty()) { deleteBuffer(mBufferMap.begin()->first); } while (!mProgramMap.empty()) { deleteProgram(mProgramMap.begin()->first); } while (!mShaderMap.empty()) { deleteShader(mShaderMap.begin()->first); } while (!mRenderbufferMap.empty()) { deleteRenderbuffer(mRenderbufferMap.begin()->first); } while (!mTextureMap.empty()) { deleteTexture(mTextureMap.begin()->first); } while (!mSamplerMap.empty()) { deleteSampler(mSamplerMap.begin()->first); } while (!mFenceSyncMap.empty()) { deleteFenceSync(mFenceSyncMap.begin()->first); } for (auto it = mPathMap.begin(); it != mPathMap.end(); ++it) { const auto *p = it->second; delete p; } }
fsDrawMgr::~fsDrawMgr() { getScreen(INVISIBLE_SCREEN_ID)->moveLast(); while (const fsID* scr_id = m_scr_map.getFirstKeyN()) { fsDelete(getScreen(*scr_id), fsScr); } while (const fsID* tex_id = m_tex_map.getFirstKeyN()) { deleteTexture(*tex_id); } while (const fsID* shd_id = m_shd_map.getFirstKeyN()) { deleteShader(*shd_id); } while (const fsID* lts_id = m_lts_map.getFirstKeyN()) { deleteLightSet(*lts_id); } for (const fsRes* res = fsResMgr::getFirstResourceN(); res; res = fsResMgr::getNextResourceN(res->getID())) { if (res->getExtension() == "TTF" || res->getExtension() == "TTC" || res->getExtension() == "OTF") { fontFinalizer(res->getID(), res->getExtension(), res->getData<void>(), res->getDataSize(), res->getExInfo<void>()); } } if (!fsLowLevelAPI::destroyFreeType()) { fsThrow(ExceptionDestroyFreeTypeFailed); } fsResMgr::removeType("PNG"); fsResMgr::removeType("TTF"); fsResMgr::removeType("TTC"); fsResMgr::removeType("OTF"); }
/* Load and compile the shader,create a new program and link the shader */ GLvoid Shader::compileShaders() { /* Create a vertex shader */ iVertexShaderHandle = glCreateShader(GL_VERTEX_SHADER); assert(iVertexShaderHandle != -1); /* Create a fragment shader */ iFragmentShaderHandle = glCreateShader(GL_FRAGMENT_SHADER); if (iFragmentShaderHandle == -1) { glDeleteShader(iVertexShaderHandle); bCompiled = GL_FALSE; return ; } char const* vertexSourcePointer = sVertexShaderCode.c_str(); glShaderSource(iVertexShaderHandle, 1, &vertexSourcePointer, NULL); glCompileShader(iVertexShaderHandle); GLint errorVertex = getLog(iVertexShaderHandle); char const* fragmentSourcePointer = sFragmentShaderCode.c_str(); glShaderSource(iFragmentShaderHandle, 1, &fragmentSourcePointer, NULL); glCompileShader(iFragmentShaderHandle); GLint errorFragment = getLog(iFragmentShaderHandle); if (errorFragment > 1) { bCompiled = GL_FALSE; deleteShader(); return ; } linkProgram(); bCompiled = (uiProgramID != -1); }
ResourceManager::~ResourceManager() { std::cout << "################ ResourceManager::delete ################" << std::endl; // delete shaders only in destructor. There might be an ubershader. // shaders std::cout << "---------- Delete Shaders ----------" << std::endl; std::map<std::string, Shader*>::iterator shad_it; for (shad_it=_shaders.begin(); shad_it!=_shaders.end(); ++shad_it) { if (shad_it->second != NULL) { //std::cout << shad_it->first << " => " << shad_it->second << '\n'; deleteShader(shad_it->first); } } _shaders.clear(); // cleanup Textures and Meshes this->cleanup(); std::cout << "resourcemanager empty" << std::endl; std::cout << "#####################" << std::endl; std::cout << "resourcemanager closed" << std::endl; }
Material::~Material() { AC_DEBUG << "Material::dtor "<<(void*)this; deleteShader(); }
GLShader* createShader(char* vertSource, char* fragSource, char** attribs, uint32_t attribsCount, char** uniforms, uint32_t uniformCount) { GLShader* result = malloc(sizeof(GLShader)); result->vertShader = glCreateShader(GL_VERTEX_SHADER); result->fragShader = glCreateShader(GL_FRAGMENT_SHADER); result->program = glCreateProgram(); result->uniformCount = uniformCount; result->uniformLocs = malloc(sizeof(GLuint) * uniformCount); glShaderSource(result->vertShader, 1, &vertSource, 0); glShaderSource(result->fragShader, 1, &fragSource, 0); glCompileShader(result->vertShader); GLint compiled = 0; glGetShaderiv(result->vertShader, GL_COMPILE_STATUS, &compiled); if (compiled == GL_FALSE) { GLint maxLength = 0; glGetShaderiv(result->vertShader, GL_INFO_LOG_LENGTH, &maxLength); GLchar* message = (GLchar*)malloc(sizeof(GLchar)*maxLength); glGetShaderInfoLog(result->vertShader, maxLength, &maxLength, message); printf("Vertex Shader failed to compile:\n"); printf("%s\n", message); free(message); deleteShader(result); return NULL; } glCompileShader(result->fragShader); glGetShaderiv(result->fragShader, GL_COMPILE_STATUS, &compiled); if (compiled == GL_FALSE) { GLint maxLength = 0; glGetShaderiv(result->fragShader, GL_INFO_LOG_LENGTH, &maxLength); GLchar* message = (GLchar*)malloc(sizeof(GLchar)*maxLength); glGetShaderInfoLog(result->fragShader, maxLength, &maxLength, message); printf("Fragment Shader failed to compile:\n"); printf("%s\n", message); free(message); deleteShader(result); return NULL; } glAttachShader(result->program, result->vertShader); glAttachShader(result->program, result->fragShader); for (uint32_t i = 0; i < attribsCount; i++) { glBindAttribLocation(result->program, i, attribs[i]); } glLinkProgram(result->program); glValidateProgram(result->program); glUseProgram(result->program); for (uint32_t i = 0; i < uniformCount; i++) { result->uniformLocs[i] = glGetUniformLocation(result->program, uniforms[i]); } glUseProgram(0); return result; }
void initShader() { shaderProgram = glCreateProgram(); // check if operation failed // if (shaderProgram == 0) { std::cout << "(initShader) - Failed creating shader program." << std::endl; return; } GLuint vertexShader = loadShaderFile("../shader/material_and_light.vert", GL_VERTEX_SHADER); if (vertexShader == 0) { std::cout << "(initShader) - Could not create vertex shader." << std::endl; deleteShader(); return; } GLuint fragmentShader = loadShaderFile("../shader/material_and_light.frag", GL_FRAGMENT_SHADER); if (fragmentShader == 0) { std::cout << "(initShader) - Could not create vertex shader." << std::endl; deleteShader(); return; } // successfully loaded and compiled shaders -> attach them to program // glAttachShader(shaderProgram, vertexShader); glAttachShader(shaderProgram, fragmentShader); // mark shaders for deletion after clean up (they will be deleted, when detached from all shader programs) // glDeleteShader(vertexShader); glDeleteShader(fragmentShader); // link shader program // glLinkProgram(shaderProgram); // get log // /*int logMaxLength; glGetProgramiv(shaderProgram, GL_INFO_LOG_LENGTH, &logMaxLength); char log[logMaxLength]; int logLength = 0; glGetProgramInfoLog(shaderProgram, logMaxLength, &logLength, log); if (logLength > 0) { std::cout << "(initShader) - Linker log:\n------------------\n" << log << "\n------------------" << std::endl; }*/ // set address of fragment color output // glBindFragDataLocation(shaderProgram, 0, "color"); // get uniform locations for common variables // uniformLocations["projection"] = glGetUniformLocation(shaderProgram, "projection"); uniformLocations["modelview"] = glGetUniformLocation(shaderProgram, "modelview"); // TODO: insert the uniform locations for all light and material properties // - insert then into the provided map 'uniformLocations' and give them a proper identifier // - when accessing a GLSL uniform within a struct (as used in the provided vertex shader), // use the following technique: glGetUniformLocation(shaderID, "structName.propertyName") // So, when having a struct // struct MyStruct {vec3 MyVector}; // and a uniform declaration // uniform MyStruct MyStructUniform; // you can get the location of MyVector by passing the string "MyStructUniform.MyVector" to // glGetUniformLocation(...) uniformLocations["lightSource.ambient_color"] = glGetUniformLocation(shaderProgram, "lightSource.ambient_color"); uniformLocations["lightSource.diffuse_color"] = glGetUniformLocation(shaderProgram, "lightSource.diffuse_color"); uniformLocations["lightSource.specular_color"] = glGetUniformLocation(shaderProgram, "lightSource.specular_color"); uniformLocations["lightSource.position"] = glGetUniformLocation(shaderProgram, "lightSource.position"); uniformLocations["material.ambient_color"] = glGetUniformLocation(shaderProgram, "material.ambient_color"); uniformLocations["material.diffuse_color"] = glGetUniformLocation(shaderProgram, "material.diffuse_color"); uniformLocations["material.specular_color"] = glGetUniformLocation(shaderProgram, "material.specular_color"); uniformLocations["material.specular_shininess"] = glGetUniformLocation(shaderProgram, "material.specular_shininess"); }
Display::~Display() { // Delete and free shader program. deleteShader(); }
Shader::~Shader(void) { // Delete complete shader program deleteShader(); }
void initShader() { shaderProgram = glCreateProgram(); // check if operation failed // if (shaderProgram == 0) { std::cout << "(initShader) - Failed creating shader program." << std::endl; return; } GLuint vertexShader = loadShaderFile("../shader/texture.vert", GL_VERTEX_SHADER); if (vertexShader == 0) { std::cout << "(initShader) - Could not create vertex shader." << std::endl; deleteShader(); return; } GLuint fragmentShader = loadShaderFile("../shader/texture.frag", GL_FRAGMENT_SHADER); if (fragmentShader == 0) { std::cout << "(initShader) - Could not create vertex shader." << std::endl; deleteShader(); return; } // successfully loaded and compiled shaders -> attach them to program // glAttachShader(shaderProgram, vertexShader); glAttachShader(shaderProgram, fragmentShader); // mark shaders for deletion after clean up (they will be deleted, when detached from all shader programs) // glDeleteShader(vertexShader); glDeleteShader(fragmentShader); // link shader program // glLinkProgram(shaderProgram); // get log // int logMaxLength; glGetProgramiv(shaderProgram, GL_INFO_LOG_LENGTH, &logMaxLength); char log[logMaxLength]; int logLength = 0; glGetProgramInfoLog(shaderProgram, logMaxLength, &logLength, log); if (logLength > 0) { std::cout << "(initShader) - Linker log:\n------------------\n" << log << "\n------------------" << std::endl; } // set address of fragment color output // glBindFragDataLocation(shaderProgram, 0, "color"); // get uniform locations for common variables // uniformLocations["projection"] = glGetUniformLocation(shaderProgram, "projection"); uniformLocations["modelview"] = glGetUniformLocation(shaderProgram, "modelview"); // material unform locations // uniformLocations["material.ambient"] = glGetUniformLocation(shaderProgram, "material.ambient_color"); uniformLocations["material.diffuse"] = glGetUniformLocation(shaderProgram, "material.diffuse_color"); uniformLocations["material.specular"] = glGetUniformLocation(shaderProgram, "material.specular_color"); uniformLocations["material.shininess"] = glGetUniformLocation(shaderProgram, "material.specular_shininess"); // store the uniform locations for all light source properties for (int i = 0; i < 10; ++i) { UniformLocation_Light lightLocation; lightLocation.ambient_color = glGetUniformLocation(shaderProgram, getUniformStructLocStr("lightSource", "ambient_color", i).c_str()); lightLocation.diffuse_color = glGetUniformLocation(shaderProgram, getUniformStructLocStr("lightSource", "diffuse_color", i).c_str()); lightLocation.specular_color = glGetUniformLocation(shaderProgram, getUniformStructLocStr("lightSource", "specular_color", i).c_str()); lightLocation.position = glGetUniformLocation(shaderProgram, getUniformStructLocStr("lightSource", "position", i).c_str()); std::stringstream sstr(""); sstr << "light_" << i; uniformLocations_Lights[sstr.str()] = lightLocation; } uniformLocations["usedLightCount"] = glGetUniformLocation(shaderProgram, "usedLightCount"); // get texture uniform location // uniformLocations["tex"] = glGetUniformLocation(shaderProgram,"tex"); }
Shader::~Shader(void) { // The destructor just cleans up the GPU memory. deleteShader(); }
GLC_Shader::~GLC_Shader() { deleteShader(); }
Shader::~Shader(){ deleteShader(); }