• CompileGLShader


    //-----------------------------------------------------------------------------
    // Purpose: Compiles a GL shader program and returns the handle. Returns 0 if
    //            the shader couldn't be compiled for some reason.
    //-----------------------------------------------------------------------------
    GLuint CMainApplication::CompileGLShader( const char *pchShaderName, const char *pchVertexShader, const char *pchFragmentShader )
    {
        GLuint unProgramID = glCreateProgram();

        GLuint nSceneVertexShader = glCreateShader(GL_VERTEX_SHADER);
        glShaderSource( nSceneVertexShader, 1, &pchVertexShader, NULL);
        glCompileShader( nSceneVertexShader );

        GLint vShaderCompiled = GL_FALSE;
        glGetShaderiv( nSceneVertexShader, GL_COMPILE_STATUS, &vShaderCompiled);
        if ( vShaderCompiled != GL_TRUE)
        {
            dprintf("%s - Unable to compile vertex shader %d! ", pchShaderName, nSceneVertexShader);
            glDeleteProgram( unProgramID );
            glDeleteShader( nSceneVertexShader );
            return 0;
        }
        glAttachShader( unProgramID, nSceneVertexShader);
        glDeleteShader( nSceneVertexShader ); // the program hangs onto this once it's attached

        GLuint  nSceneFragmentShader = glCreateShader(GL_FRAGMENT_SHADER);
        glShaderSource( nSceneFragmentShader, 1, &pchFragmentShader, NULL);
        glCompileShader( nSceneFragmentShader );

        GLint fShaderCompiled = GL_FALSE;
        glGetShaderiv( nSceneFragmentShader, GL_COMPILE_STATUS, &fShaderCompiled);
        if (fShaderCompiled != GL_TRUE)
        {
            dprintf("%s - Unable to compile fragment shader %d! ", pchShaderName, nSceneFragmentShader );
            glDeleteProgram( unProgramID );
            glDeleteShader( nSceneFragmentShader );
            return 0;    
        }

        glAttachShader( unProgramID, nSceneFragmentShader );
        glDeleteShader( nSceneFragmentShader ); // the program hangs onto this once it's attached

        glLinkProgram( unProgramID );

        GLint programSuccess = GL_TRUE;
        glGetProgramiv( unProgramID, GL_LINK_STATUS, &programSuccess);
        if ( programSuccess != GL_TRUE )
        {
            dprintf("%s - Error linking program %d! ", pchShaderName, unProgramID);
            glDeleteProgram( unProgramID );
            return 0;
        }

        glUseProgram( unProgramID );
        glUseProgram( 0 );

        return unProgramID;
    }

  • 相关阅读:
    tcpdump 抓包
    mysql常用日期函数
    接口自动化测试,一键快速校验接口返回值全部字段
    实训项目
    vue proxyTable 代理方式 解决 跨域pathRewrite
    cookie, session, token 发展史
    Failed to set locale, defaulting to C.UTF-8
    java String与Integer的相互转化
    java LocalDateTime 常用 转换 方法
    Java命令里面的EQ、NE、GT、LT、GE、LE分别代表含义
  • 原文地址:https://www.cnblogs.com/mazhenyu/p/6544126.html
Copyright © 2020-2023  润新知