bool Cc3dProgram::initWithFile(const string&vertShaderFilePath,const string&fragShaderFilePath){ m_vertShaderFilePath=vertShaderFilePath; m_fragShaderFilePath=fragShaderFilePath; //create shader vector<string> _vertShaderFileName=splitStrInTwoByLastDot(vertShaderFilePath); vector<string> _fragShaderFileName=splitStrInTwoByLastDot(fragShaderFilePath); //创建Program GLuint vertShader=createShader(_vertShaderFileName[0].c_str(), _vertShaderFileName[1].c_str()); GLuint fragShader=createShader(_fragShaderFileName[0].c_str(), _fragShaderFileName[1].c_str()); //Calls glCreateProgram, glAttachShader, and glLinkProgram to link the vertex and fragment shaders into a complete program. GLuint programHandle = glCreateProgram(); glAttachShader(programHandle, vertShader); glAttachShader(programHandle, fragShader); //needs to be done prior to linking { glBindAttribLocation(programHandle, ATTRIB_LOC_position_local, "position_local"); glBindAttribLocation(programHandle, ATTRIB_LOC_texCoord, "texCoordIn"); glBindAttribLocation(programHandle, ATTRIB_LOC_normal_local, "normal_local"); } glLinkProgram(programHandle);//link过以后,通过glGet**Location得到的索引就是固定的了 //check and see if there were any link errors GLint linkSuccess; glGetProgramiv(programHandle, GL_LINK_STATUS, &linkSuccess); if (linkSuccess == GL_FALSE) { GLchar messages[1024]; glGetProgramInfoLog(programHandle, sizeof(messages), 0, &messages[0]); C3DASSERT(false,messages); } m_program=programHandle; return true; }
GLuint createShader_plat(const char*shaderName,const char*ext) { //judage shader type: vertex shader or fragment shader GLuint shaderHandle=0; string postFix=ext;//后缀--abc if(postFix == "vert"){//是顶点shader shaderHandle = glCreateShader(GL_VERTEX_SHADER); }else if(postFix == "frag"){ shaderHandle = glCreateShader(GL_FRAGMENT_SHADER); }else{ C3DASSERT(false); } string fileName=string(shaderName)+"."+ext; string filePath=Cc3dFileUtils::sharedFileUtils()->getFullPath(fileName.c_str()); const char*content = textFileRead((char*)filePath.c_str());//文件内容--abc glShaderSource(shaderHandle, 1, &content,NULL); free((char*)content); glCompileShader(shaderHandle); return shaderHandle; }
void getMemStatistics_plat(int&memUsed,int&memFree,int&memTotal){//获得内存统计数据--abc //no implemented yet C3DASSERT(false); }