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


C++ QOpenGLFunctions::glBindFramebuffer方法代码示例

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


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

示例1: composeSurface

GLuint QWindowCompositor::composeSurface(QWaylandSurface *surface)
{
    GLuint texture = 0;

    QSize windowSize = surface->size();
    surface->advanceBufferQueue();

    QOpenGLFunctions *functions = QOpenGLContext::currentContext()->functions();
    functions->glBindFramebuffer(GL_FRAMEBUFFER, m_surface_fbo);

    if (surface->type() == QWaylandSurface::Shm) {
        texture = m_textureCache->bindTexture(QOpenGLContext::currentContext(),surface->image());
    } else if (surface->type() == QWaylandSurface::Texture) {
        texture = surface->texture(QOpenGLContext::currentContext());
    }

    functions->glFramebufferTexture2D(GL_FRAMEBUFFER, GL_COLOR_ATTACHMENT0,
                                       GL_TEXTURE_2D, texture, 0);
    paintChildren(surface, surface,windowSize);
    functions->glFramebufferTexture2D(GL_FRAMEBUFFER, GL_COLOR_ATTACHMENT0,
                                       GL_TEXTURE_2D,0, 0);

    functions->glBindFramebuffer(GL_FRAMEBUFFER, 0);
    return texture;
}
开发者ID:locusf,项目名称:qtwayland,代码行数:25,代码来源:qwindowcompositor.cpp

示例2: newResources

void TFInteg2DGL::integrate(const float *colormap, int resolution, float basesize, float stepsize)
{
    if (!texFull || resolution != texFull->width())
        newResources(resolution);
    QOpenGLFunctions* f = QOpenGLContext::currentContext()->functions();
    tex1d->setData(QOpenGLTexture::RGBA, QOpenGLTexture::Float32, colormap);
    // framebuffer object
    GLint oFbo, viewport[4], activeTex, oTex;
    newFbo();
    f->glGetIntegerv(GL_FRAMEBUFFER_BINDING, &oFbo);
    f->glBindFramebuffer(GL_FRAMEBUFFER, *fbo);
    f->glClear(GL_COLOR_BUFFER_BIT);
    // viewport
    f->glGetIntegerv(GL_VIEWPORT, viewport);
    f->glViewport(0, 0, resolution, resolution);
    // 1d texture
    f->glGetIntegerv(GL_ACTIVE_TEXTURE, &activeTex);
    f->glActiveTexture(GL_TEXTURE0);
    f->glGetIntegerv(GL_TEXTURE_1D, &oTex);
    f->glBindTexture(GL_TEXTURE_1D, tex1d->textureId());
    // paint
    painter.recreateVAO();
    painter.paint("tf1d", 0, "resolution", resolution, "basesize", basesize, "segLen", stepsize);
    // clean
    f->glActiveTexture(GL_TEXTURE0);
    f->glBindTexture(GL_TEXTURE_1D, oTex);
    f->glActiveTexture(activeTex);

//    std::unique_ptr<GLubyte[]> pixels(new GLubyte [resolution * resolution * 4]);
//    f->glReadPixels(0, 0, resolution, resolution, GL_RGBA, GL_UNSIGNED_BYTE, pixels.get());
//    QImage image(pixels.get(), resolution, resolution, QImage::Format_RGBA8888);
//    static QLabel label;
//    label.resize(resolution, resolution);
//    label.setPixmap(QPixmap::fromImage(image.mirrored()));
//    label.show();

    f->glViewport(viewport[0], viewport[1], viewport[2], viewport[3]);
    f->glBindFramebuffer(GL_FRAMEBUFFER, oFbo);
}
开发者ID:chrisyeshi,项目名称:VolRen,代码行数:39,代码来源:tfinteg2dgl.cpp

示例3: composeSurface

GLuint QtwaylandSurfaceNode::composeSurface(QWaylandSurface *surface, OpenGLData *glData)
{
    glData->m_textureBlitter->bind();
    GLuint texture = 0;

    QOpenGLFunctions *functions = QOpenGLContext::currentContext()->functions();
    functions->glBindFramebuffer(GL_FRAMEBUFFER, glData->m_surface_fbo);

    if (surface->type() == QWaylandSurface::Shm) {
        texture = glData->m_textureCache->bindTexture(QOpenGLContext::currentContext(),surface->image());
    } else if (surface->type() == QWaylandSurface::Texture) {
        texture = surface->texture(QOpenGLContext::currentContext());
    }

    functions->glFramebufferTexture2D(GL_FRAMEBUFFER, GL_COLOR_ATTACHMENT0,
                                       GL_TEXTURE_2D, texture, 0);
    paintChildren(surface,surface, glData);
    functions->glFramebufferTexture2D(GL_FRAMEBUFFER, GL_COLOR_ATTACHMENT0,
                                       GL_TEXTURE_2D,0, 0);

    functions->glBindFramebuffer(GL_FRAMEBUFFER, 0);
    glData->m_textureBlitter->release();
    return texture;
}
开发者ID:57-Wolve,项目名称:motorcar,代码行数:24,代码来源:qtwaylandsurfacenode.cpp

示例4: saveTexture

void QSGDistanceFieldGlyphCache::saveTexture(GLuint textureId, int width, int height) const
{
    QOpenGLFunctions *functions = QOpenGLContext::currentContext()->functions();

    GLuint fboId;
    functions->glGenFramebuffers(1, &fboId);

    GLuint tmpTexture = 0;
    functions->glGenTextures(1, &tmpTexture);
    functions->glBindTexture(GL_TEXTURE_2D, tmpTexture);
    functions->glTexImage2D(GL_TEXTURE_2D, 0, GL_RGBA, width, height, 0, GL_RGBA, GL_UNSIGNED_BYTE, NULL);
    functions->glTexParameterf(GL_TEXTURE_2D, GL_TEXTURE_MIN_FILTER, GL_NEAREST);
    functions->glTexParameterf(GL_TEXTURE_2D, GL_TEXTURE_MAG_FILTER, GL_NEAREST);
    functions->glTexParameterf(GL_TEXTURE_2D, GL_TEXTURE_WRAP_S, GL_CLAMP_TO_EDGE);
    functions->glTexParameterf(GL_TEXTURE_2D, GL_TEXTURE_WRAP_T, GL_CLAMP_TO_EDGE);
    functions->glBindTexture(GL_TEXTURE_2D, 0);

    functions->glBindFramebuffer(GL_FRAMEBUFFER_EXT, fboId);
    functions->glFramebufferTexture2D(GL_FRAMEBUFFER_EXT, GL_COLOR_ATTACHMENT0_EXT, GL_TEXTURE_2D,
                                      tmpTexture, 0);

    functions->glActiveTexture(GL_TEXTURE0);
    functions->glBindTexture(GL_TEXTURE_2D, textureId);

    functions->glDisable(GL_STENCIL_TEST);
    functions->glDisable(GL_DEPTH_TEST);
    functions->glDisable(GL_SCISSOR_TEST);
    functions->glDisable(GL_BLEND);

    GLfloat textureCoordinateArray[8];
    textureCoordinateArray[0] = 0.0f;
    textureCoordinateArray[1] = 0.0f;
    textureCoordinateArray[2] = 1.0f;
    textureCoordinateArray[3] = 0.0f;
    textureCoordinateArray[4] = 1.0f;
    textureCoordinateArray[5] = 1.0f;
    textureCoordinateArray[6] = 0.0f;
    textureCoordinateArray[7] = 1.0f;

    GLfloat vertexCoordinateArray[8];
    vertexCoordinateArray[0] = -1.0f;
    vertexCoordinateArray[1] = -1.0f;
    vertexCoordinateArray[2] =  1.0f;
    vertexCoordinateArray[3] = -1.0f;
    vertexCoordinateArray[4] =  1.0f;
    vertexCoordinateArray[5] =  1.0f;
    vertexCoordinateArray[6] = -1.0f;
    vertexCoordinateArray[7] =  1.0f;

    functions->glViewport(0, 0, width, height);
    functions->glVertexAttribPointer(0, 2, GL_FLOAT, GL_FALSE, 0, vertexCoordinateArray);
    functions->glVertexAttribPointer(1, 2, GL_FLOAT, GL_FALSE, 0, textureCoordinateArray);

    {
        static const char *vertexShaderSource =
                "attribute vec4      vertexCoordsArray; \n"
                "attribute vec2      textureCoordArray; \n"
                "varying   vec2      textureCoords;     \n"
                "void main(void) \n"
                "{ \n"
                "    gl_Position = vertexCoordsArray;   \n"
                "    textureCoords = textureCoordArray; \n"
                "} \n";

        static const char *fragmentShaderSource =
                "varying   vec2      textureCoords; \n"
                "uniform   sampler2D         texture;       \n"
                "void main() \n"
                "{ \n"
                "    gl_FragColor = texture2D(texture, textureCoords); \n"
                "} \n";

        GLuint vertexShader = functions->glCreateShader(GL_VERTEX_SHADER);
        GLuint fragmentShader = functions->glCreateShader(GL_FRAGMENT_SHADER);

        if (vertexShader == 0 || fragmentShader == 0) {
            GLenum error = functions->glGetError();
            qWarning("QSGDistanceFieldGlyphCache::saveTexture: Failed to create shaders. (GL error: %x)",
                     error);
            return;
        }

        functions->glShaderSource(vertexShader, 1, &vertexShaderSource, NULL);
        functions->glShaderSource(fragmentShader, 1, &fragmentShaderSource, NULL);
        functions->glCompileShader(vertexShader);

        GLint len = 1;
        functions->glGetShaderiv(vertexShader, GL_INFO_LOG_LENGTH, &len);

        char infoLog[2048];
        functions->glGetShaderInfoLog(vertexShader, 2048, NULL, infoLog);
        if (qstrlen(infoLog) > 0)
            qWarning("Problems compiling vertex shader:\n %s", infoLog);

        functions->glCompileShader(fragmentShader);
        functions->glGetShaderInfoLog(fragmentShader, 2048, NULL, infoLog);
        if (qstrlen(infoLog) > 0)
            qWarning("Problems compiling fragment shader:\n %s", infoLog);

        GLuint shaderProgram = functions->glCreateProgram();
//.........这里部分代码省略.........
开发者ID:RobinWuDev,项目名称:Qt,代码行数:101,代码来源:qsgadaptationlayer.cpp


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