当前位置: 首页>>代码示例>>C++>>正文


C++ GLContext::fLinkProgram方法代码示例

本文整理汇总了C++中GLContext::fLinkProgram方法的典型用法代码示例。如果您正苦于以下问题:C++ GLContext::fLinkProgram方法的具体用法?C++ GLContext::fLinkProgram怎么用?C++ GLContext::fLinkProgram使用的例子?那么, 这里精选的方法代码示例或许可以为您提供帮助。您也可以进一步了解该方法所在GLContext的用法示例。


在下文中一共展示了GLContext::fLinkProgram方法的1个代码示例,这些例子默认根据受欢迎程度排序。您可以为喜欢或者感觉有用的代码点赞,您的评价将有助于系统推荐出更棒的C++代码示例。

示例1: main

void
GLBlitTextureImageHelper::UseBlitProgram()
{
    GLContext *gl = mCompositor->gl();
    if (mBlitProgram) {
        gl->fUseProgram(mBlitProgram);
        return;
    }

    mBlitProgram = gl->fCreateProgram();

    GLuint shaders[2];
    shaders[0] = gl->fCreateShader(LOCAL_GL_VERTEX_SHADER);
    shaders[1] = gl->fCreateShader(LOCAL_GL_FRAGMENT_SHADER);

    const char *blitVSSrc =
        "attribute vec2 aVertex;"
        "attribute vec2 aTexCoord;"
        "varying vec2 vTexCoord;"
        "void main() {"
        "  vTexCoord = aTexCoord;"
        "  gl_Position = vec4(aVertex, 0.0, 1.0);"
        "}";
    const char *blitFSSrc = "#ifdef GL_ES\nprecision mediump float;\n#endif\n"
        "uniform sampler2D uSrcTexture;"
        "varying vec2 vTexCoord;"
        "void main() {"
        "  gl_FragColor = texture2D(uSrcTexture, vTexCoord);"
        "}";

    gl->fShaderSource(shaders[0], 1, (const GLchar**) &blitVSSrc, nullptr);
    gl->fShaderSource(shaders[1], 1, (const GLchar**) &blitFSSrc, nullptr);

    for (int i = 0; i < 2; ++i) {
        GLint success, len = 0;

        gl->fCompileShader(shaders[i]);
        gl->fGetShaderiv(shaders[i], LOCAL_GL_COMPILE_STATUS, &success);
        NS_ASSERTION(success, "Shader compilation failed!");

        if (!success) {
            nsAutoCString log;
            gl->fGetShaderiv(shaders[i], LOCAL_GL_INFO_LOG_LENGTH, (GLint*) &len);
            log.SetCapacity(len);
            gl->fGetShaderInfoLog(shaders[i], len, (GLint*) &len, (char*) log.BeginWriting());
            log.SetLength(len);

            printf_stderr("Shader %d compilation failed:\n%s\n", i, log.get());
            return;
        }

        gl->fAttachShader(mBlitProgram, shaders[i]);
        gl->fDeleteShader(shaders[i]);
    }

    gl->fBindAttribLocation(mBlitProgram, 0, "aVertex");
    gl->fBindAttribLocation(mBlitProgram, 1, "aTexCoord");

    gl->fLinkProgram(mBlitProgram);

    GLint success, len = 0;
    gl->fGetProgramiv(mBlitProgram, LOCAL_GL_LINK_STATUS, &success);
    NS_ASSERTION(success, "Shader linking failed!");

    if (!success) {
        nsAutoCString log;
        gl->fGetProgramiv(mBlitProgram, LOCAL_GL_INFO_LOG_LENGTH, (GLint*) &len);
        log.SetCapacity(len);
        gl->fGetProgramInfoLog(mBlitProgram, len, (GLint*) &len, (char*) log.BeginWriting());
        log.SetLength(len);

        printf_stderr("Program linking failed:\n%s\n", log.get());
        return;
    }

    gl->fUseProgram(mBlitProgram);
    gl->fUniform1i(gl->fGetUniformLocation(mBlitProgram, "uSrcTexture"), 0);
}
开发者ID:msliu,项目名称:gecko-dev,代码行数:78,代码来源:GLBlitTextureImageHelper.cpp


注:本文中的GLContext::fLinkProgram方法示例由纯净天空整理自Github/MSDocs等开源代码及文档管理平台,相关代码片段筛选自各路编程大神贡献的开源项目,源码版权归原作者所有,传播和使用请参考对应项目的License;未经允许,请勿转载。