Пример #1
0
void Shader::check_shader(GLuint ShaderID,GLint &Result,int &InfoLogLength) {
    glGetShaderiv(ShaderID,GL_COMPILE_STATUS,&Result);
    glGetShaderiv(ShaderID,GL_INFO_LOG_LENGTH,&InfoLogLength);
    std::vector<char> ShaderErrorMessage(InfoLogLength);
    glGetShaderInfoLog(ShaderID,InfoLogLength, NULL,&ShaderErrorMessage[0]);
    if(strcmp(&ShaderErrorMessage[0],""))fprintf(stdout, "%s\n", &ShaderErrorMessage[0]);
}
Пример #2
0
/*Get the log*/
GLint ShaderProgram::getLog(int type)
{
	GLint iResult=GL_FALSE;
	GLint iInfoLogLength;

	glGetShaderiv(type,GL_COMPILE_STATUS,&iResult);
	glGetShaderiv(type,GL_INFO_LOG_LENGTH,&iInfoLogLength);
	if (iInfoLogLength>0)
	{
		std::vector<char> ShaderErrorMessage(iInfoLogLength+1);
		glGetShaderInfoLog(type, iInfoLogLength, NULL, &ShaderErrorMessage[0]);
		printf("%s\n", &ShaderErrorMessage[0]);
	}
	return iInfoLogLength;
}
Пример #3
0
void Shader::load(std::string filename) {
    std::string ShaderCode = this->loadCode(filename);

    GLint Result = GL_FALSE;
    int InfoLogLength;
 
    // Compile Shader
    std::cout << "Compiling shader : " << filename << std::endl;
    char const * SourcePointer = ShaderCode.c_str();
    glShaderSource(this->id, 1, &SourcePointer , NULL);
    glCompileShader(this->id);
 
    // Check Shader
    glGetShaderiv(this->id, GL_COMPILE_STATUS, &Result);
    glGetShaderiv(this->id, GL_INFO_LOG_LENGTH, &InfoLogLength);
    std::vector<char> ShaderErrorMessage(InfoLogLength);
    glGetShaderInfoLog(this->id, InfoLogLength, NULL, &ShaderErrorMessage[0]);
    fprintf(stdout, "%s\n", &ShaderErrorMessage[0]);
}
Пример #4
0
void Shader::Compile(std::string Filename)
{
    ID = glCreateShader(type);

    std::string ShaderCode;
    std::ifstream ShaderStream;

    // Load shader source code
    ShaderStream.open(Filename.c_str(), std::ios::in );

    if(ShaderStream.is_open() )
    {
        std::string line = "";
        while(getline(ShaderStream, line))
        {
            ShaderCode += line + "\n";
        }
        ShaderStream.close();
    }
    else
        cerr << "Could not open shader \"" << Filename << "\"" << endl;

    GLint Result = GL_FALSE;
    int InfoLogLength;

    // Compile Shader
    cout << "Compiling shader : " << Filename << endl;
    char const * SourcePointer = ShaderCode.c_str();
    glShaderSource(ID, 1, &SourcePointer , NULL);
    glCompileShader(ID);

    // Check Shader
    glGetShaderiv(ID, GL_COMPILE_STATUS, &Result);
    glGetShaderiv(ID, GL_INFO_LOG_LENGTH, &InfoLogLength);
    std::vector<char> ShaderErrorMessage(InfoLogLength);
    glGetShaderInfoLog(ID, InfoLogLength, NULL, &ShaderErrorMessage[0]);
    string t(ShaderErrorMessage.begin(), ShaderErrorMessage.end() );
    cout << t << endl;

}
Пример #5
0
void Shader::Add(char * path, GLenum type)
{


    GLuint ShaderID = glCreateShader(type);
    std::string ShaderCode = AString::LoadFileToString(path);




    std::string sub = "#include";
    std::string sub2 = "\"";
    std::string s_path = std::string(path);
    size_t pos = ShaderCode.find(sub, 0);


    while (pos != std::string::npos)
    {


        size_t f_pos = pos;
        size_t t_pos = ShaderCode.find(sub2, pos + 1);
        pos = ShaderCode.find(sub2, t_pos + 1);

        std::string t_file = s_path.substr(0, s_path.find_last_of("//") + 1) + ShaderCode.substr(t_pos + 1, pos - (t_pos + 1));
        ShaderCode.erase(f_pos, pos - f_pos + 1);
        ShaderCode.insert(f_pos, AString::LoadFileToString(AString::char_to_str(t_file)));
        pos = ShaderCode.find(sub, f_pos + 1);


    }




    GLint Result = GL_FALSE;
    int InfoLogLength;



    printf("Compiling shader : %s\n", path);
    char const * SourcePointer = ShaderCode.c_str();
    glShaderSource(ShaderID, 1, &SourcePointer, NULL);
    glCompileShader(ShaderID);




    glGetShaderiv(ShaderID, GL_COMPILE_STATUS, &Result);
    glGetShaderiv(ShaderID, GL_INFO_LOG_LENGTH, &InfoLogLength);
    if (InfoLogLength > 0)
    {
        std::vector<char> ShaderErrorMessage(InfoLogLength + 1);
        glGetShaderInfoLog(ShaderID, InfoLogLength, NULL, &ShaderErrorMessage[0]);
        printf("%s\n", &ShaderErrorMessage[0]);
    }



    glAttachShader(this->program, ShaderID);
    glDeleteShader(ShaderID);




}