本文整理汇总了C++中QOpenGLFramebufferObjectFormat类的典型用法代码示例。如果您正苦于以下问题:C++ QOpenGLFramebufferObjectFormat类的具体用法?C++ QOpenGLFramebufferObjectFormat怎么用?C++ QOpenGLFramebufferObjectFormat使用的例子?那么, 这里精选的类代码示例或许可以为您提供帮助。
在下文中一共展示了QOpenGLFramebufferObjectFormat类的15个代码示例,这些例子默认根据受欢迎程度排序。您可以为喜欢或者感觉有用的代码点赞,您的评价将有助于系统推荐出更棒的C++代码示例。
示例1:
QOpenGLFramebufferObject::QOpenGLFramebufferObject(const QSize &size, const QOpenGLFramebufferObjectFormat &format)
: d_ptr(new QOpenGLFramebufferObjectPrivate)
{
Q_D(QOpenGLFramebufferObject);
d->init(this, size, format.attachment(), format.textureTarget(), format.internalTextureFormat(),
format.samples(), format.mipmap());
}
示例2: QOpenGLFramebufferObject
QOpenGLFramebufferObject *createFramebufferObject(const QSize &size)
{
QOpenGLFramebufferObjectFormat format;
format.setAttachment(QOpenGLFramebufferObject::CombinedDepthStencil);
format.setSamples(4);
return new QOpenGLFramebufferObject(size, format);
}
示例3: QSize
QOpenGLFramebufferObject::QOpenGLFramebufferObject(int width, int height, const QOpenGLFramebufferObjectFormat &format)
: d_ptr(new QOpenGLFramebufferObjectPrivate)
{
Q_D(QOpenGLFramebufferObject);
d->init(this, QSize(width, height), format.attachment(), format.textureTarget(),
format.internalTextureFormat(), format.samples(), format.mipmap());
}
示例4: QFETCH
void tst_QOpenGL::fboSimpleRendering()
{
QFETCH(int, surfaceClass);
QScopedPointer<QSurface> surface(createSurface(surfaceClass));
QOpenGLContext ctx;
ctx.create();
ctx.makeCurrent(surface.data());
if (!QOpenGLFramebufferObject::hasOpenGLFramebufferObjects())
QSKIP("QOpenGLFramebufferObject not supported on this platform");
// No multisample with combined depth/stencil attachment:
QOpenGLFramebufferObjectFormat fboFormat;
fboFormat.setAttachment(QOpenGLFramebufferObject::NoAttachment);
QOpenGLFramebufferObject *fbo = new QOpenGLFramebufferObject(200, 100, fboFormat);
fbo->bind();
glClearColor(1.0, 0.0, 0.0, 1.0);
glClear(GL_COLOR_BUFFER_BIT);
glFinish();
QImage fb = fbo->toImage().convertToFormat(QImage::Format_RGB32);
QImage reference(fb.size(), QImage::Format_RGB32);
reference.fill(0xffff0000);
QFUZZY_COMPARE_IMAGES(fb, reference);
delete fbo;
}
示例5: Q_UNUSED
void RenderSurface::render(QPainter *painter)
{
Q_UNUSED(painter);
QOpenGLFramebufferObjectFormat fboFormat;
fboFormat.setSamples(1);
fboFormat.setAttachment(QOpenGLFramebufferObject::CombinedDepthStencil);
const QRect drawRect(0, 0, m_outWidth, m_outHeight);
const QSize drawRectSize = drawRect.size();
QOpenGLFramebufferObject fbo(drawRectSize, fboFormat);
fbo.bind();
glViewport(0, 0, m_outWidth, m_outHeight);
glClear(GL_COLOR_BUFFER_BIT);
glClearColor(0.0f, 0.0f, 0.0f, 1.0f);
glEnable(GL_BLEND);
glBlendFuncSeparate(GL_ONE, GL_ZERO, GL_ZERO, GL_ONE);
m_program->bind();
int texCount = 0;
for (size_t i = 0; i < sp.size(); ++i) {
if (sp[i].bind == ShaderParameter::BindTextureSampler) {
textures[sp[i].name].obj->bind(texCount);
m_program->setUniformValue(sp[i].name.c_str(), texCount);
texCount++;
} else if (sp[i].bind == ShaderParameter::BindTextureResolution) {
const QImage& image = textures[sp[i].texture].image;
m_program->setUniformValue(sp[i].name.c_str(), QVector2D(image.width(),image.height()));
} else if (sp[i].bind == ShaderParameter::BindGlobalTime) {
m_program->setUniformValue(sp[i].name.c_str(), m_globalTime);
} else if (sp[i].bind == ShaderParameter::BindOutputResolution) {
m_program->setUniformValue(sp[i].name.c_str(), QVector2D(m_outWidth,m_outHeight));
}
}
GLfloat vertices[] = {
-1.0f, -1.0f, 0.0f,
1.0f, -1.0f, 0.0f,
-1.0f, 1.0f, 0.0f,
1.0f, 1.0f, 0.0f
};
glVertexAttribPointer(m_posAttr, 3, GL_FLOAT, GL_FALSE, 0, vertices);
glEnableVertexAttribArray(0);
glDrawArrays(GL_TRIANGLE_STRIP, 0, 4);
glDisableVertexAttribArray(0);
m_program->release();
imageFrame = fbo.toImage();
}
示例6: qFatal
void TApplication::initializeGL() {
// Init shaders
if (!Shader.addShaderFromSourceFile(QGLShader::Vertex, "vert.glsl")) {
qFatal("failed to load shader vert.glsl");
}
if (!Shader.addShaderFromSourceFile(QGLShader::Fragment, "frag.glsl")) {
qFatal("failed to load shader frag.glsl");
}
if (!Shader.link()) {
qFatal("failed to link shader planet");
}
if (!Shader.bind()) {
qFatal("failed to bind shader");
}
// Init framebuffers
QOpenGLFramebufferObjectFormat format;
format.setAttachment(QOpenGLFramebufferObject::CombinedDepthStencil);
format.setSamples(8);
Fbo.reset(new QOpenGLFramebufferObject(WINDOW_WIDTH, WINDOW_HEIGHT, format));
QOpenGLFramebufferObjectFormat format1;
format.setAttachment(QOpenGLFramebufferObject::CombinedDepthStencil);
Fbo1.reset(new QOpenGLFramebufferObject(WINDOW_WIDTH, WINDOW_HEIGHT, format1));
// Load model and textures
Obj = LoadJsonModel("model.json");
ObjectSize = Obj.size();
VertexBuff.reset(new QOpenGLBuffer(QOpenGLBuffer::VertexBuffer));
VertexBuff->create();
VertexBuff->bind();
VertexBuff->setUsagePattern(QOpenGLBuffer::StaticDraw);
VertexBuff->allocate(Obj.data(), Obj.size() * sizeof(TVertex));
VertexBuff->release();
Texture.reset(new QOpenGLTexture(QImage("diffuse.jpg")));
Texture->bind();
glTexParameteri(GL_TEXTURE_2D, GL_TEXTURE_MAG_FILTER, GL_LINEAR_MIPMAP_LINEAR);
glTexParameteri(GL_TEXTURE_2D, GL_TEXTURE_MIN_FILTER, GL_LINEAR_MIPMAP_LINEAR);
Texture->release();
NormalMap.reset(new QOpenGLTexture(QImage("normal.jpg")));
NormalMap->bind();
glTexParameteri(GL_TEXTURE_2D, GL_TEXTURE_MAG_FILTER, GL_LINEAR_MIPMAP_LINEAR);
glTexParameteri(GL_TEXTURE_2D, GL_TEXTURE_MIN_FILTER, GL_LINEAR_MIPMAP_LINEAR);
NormalMap->release();
// Initial angles
AngleX = 0;
AngleY = 0;
AngleZ = 0;
Paused = false;
}
示例7: createFramebufferObject
QOpenGLFramebufferObject* QQuickMapboxGLRenderer::createFramebufferObject(const QSize &size)
{
m_map->resize(size);
QOpenGLFramebufferObjectFormat format;
format.setAttachment(QOpenGLFramebufferObject::CombinedDepthStencil);
return new QOpenGLFramebufferObject(size, format);
}
示例8: createFramebufferObject
QOpenGLFramebufferObject* COglRenderer::createFramebufferObject(const QSize &size)
{
// create opengl FBO
QOpenGLFramebufferObjectFormat format;
format.setAttachment(QOpenGLFramebufferObject::CombinedDepthStencil);
format.setSamples(4);
m_oglFBO = new QOpenGLFramebufferObject(size, format);
// return opengl FBO
return m_oglFBO;
}
示例9: create
void CombinedTexture::create()
{
if (m_framebuffer)
delete m_framebuffer;
QOpenGLFramebufferObjectFormat format;
format.setMipmap(true);
m_framebuffer = new QOpenGLFramebufferObject(m_width, m_height, format);
m_framebuffer->bind();
glViewport(0, 0, m_width, m_height);
glClearColor(0.0f, 0.0f, 0.0f, 1.0f);
glClear(GL_COLOR_BUFFER_BIT);
glEnable(GL_TEXTURE_2D);
glEnable(GL_ALPHA_TEST);
for (int i = 0; i < m_textures.size(); i++) {
Texture *texture = m_textures.at(i).first;
float *position = m_textures.at(i).second;
texture->bind();
glBegin(GL_QUADS);
glTexCoord2f(0.0f, 0.0f);
glVertex3f(position[0], position[1], 0.0f);
glTexCoord2f(1.0f, 0.0f);
glVertex3f(position[2], position[1], 0.0f);
glTexCoord2f(1.0f, 1.0f);
glVertex3f(position[2], position[3], 0.0f);
glTexCoord2f(0.0f, 1.0f);
glVertex3f(position[0], position[3], 0.0f);
glEnd();
}
m_framebuffer->release();
glBindTexture(GL_TEXTURE_2D, m_framebuffer->texture());
glTexParameteri(GL_TEXTURE_2D, GL_TEXTURE_MIN_FILTER, GL_LINEAR_MIPMAP_LINEAR);
glTexParameteri(GL_TEXTURE_2D, GL_TEXTURE_MAG_FILTER, GL_LINEAR);
QOpenGLFunctions gl(QOpenGLContext::currentContext());
gl.initializeOpenGLFunctions();
gl.glGenerateMipmap(GL_TEXTURE_2D);
m_created = true;
}
示例10: _createMultisampledFBO
std::unique_ptr<QOpenGLFramebufferObject>
_createMultisampledFBO( const QSize& size )
{
QOpenGLFramebufferObjectFormat format;
format.setAttachment( QOpenGLFramebufferObject::CombinedDepthStencil );
format.setSamples( MULTI_SAMPLE_ANTI_ALIASING_SAMPLES );
auto fbo = make_unique<QOpenGLFramebufferObject>( size, format );
fbo->bind();
auto gl = QOpenGLContext::currentContext()->functions();
gl->glClearColor( 0.0f, 0.0f, 0.0f, 0.0f );
gl->glClear( GL_COLOR_BUFFER_BIT );
fbo->release();
return fbo;
}
示例11: initialize
void Renderer::render() {
if (context == 0)
initialize();
if (newSize != size || reset) {
frame = 0;
reset = false;
size = newSize;
context->makeCurrent(this);
glViewport(0, 0, size.width(), size.height());
QOpenGLFramebufferObjectFormat fboFormat;
fboFormat.setInternalTextureFormat(GL_RGB32F);
delete backBuffer;
backBuffer = new QOpenGLFramebufferObject(size, fboFormat);
delete frameBuffer;
frameBuffer = new QOpenGLFramebufferObject(size, fboFormat);
context->doneCurrent();
}
if (backBuffer == 0 || frameBuffer == 0 || shader == 0)
return;
context->makeCurrent(this);
if (!shader->isCompiled())
shader->compile();
GLfloat elapsed = (GLfloat)time.elapsed() / 1000.f;
draw(shader->getMainProgram(), backBuffer, elapsed);
if (shader->usePostProcessing())
draw(shader->getPostProgram(), frameBuffer, elapsed);
emit updatePixmap((shader->usePostProcessing() ? frameBuffer : backBuffer)->toImage());
frame++;
context->doneCurrent();
}
示例12: defined
// NOTE: This tests that CombinedDepthStencil attachment works by assuming the
// GL2 engine is being used and is implemented the same way as it was when
// this autotest was written. If this is not the case, there may be some
// false-positives: I.e. The test passes when either the depth or stencil
// buffer is actually missing. But that's probably ok anyway.
void tst_QOpenGL::fboRendering()
{
#if defined(Q_OS_LINUX) && defined(Q_CC_GNU) && !defined(__x86_64__)
QSKIP("QTBUG-22617");
#endif
QFETCH(int, surfaceClass);
QScopedPointer<QSurface> surface(createSurface(surfaceClass));
QOpenGLContext ctx;
QVERIFY(ctx.create());
QVERIFY(ctx.makeCurrent(surface.data()));
if (!QOpenGLFramebufferObject::hasOpenGLFramebufferObjects())
QSKIP("QOpenGLFramebufferObject not supported on this platform");
// No multisample with combined depth/stencil attachment:
QOpenGLFramebufferObjectFormat fboFormat;
fboFormat.setAttachment(QOpenGLFramebufferObject::CombinedDepthStencil);
// Uncomplicate things by using NPOT:
const QSize size(256, 128);
QOpenGLFramebufferObject fbo(size, fboFormat);
if (fbo.attachment() != QOpenGLFramebufferObject::CombinedDepthStencil)
QSKIP("FBOs missing combined depth~stencil support");
QVERIFY(fbo.bind());
QPainter fboPainter;
QOpenGLPaintDevice device(fbo.width(), fbo.height());
bool painterBegun = fboPainter.begin(&device);
QVERIFY(painterBegun);
qt_opengl_draw_test_pattern(&fboPainter, fbo.width(), fbo.height());
fboPainter.end();
const QImage fb = fbo.toImage().convertToFormat(QImage::Format_RGB32);
QCOMPARE(fb.size(), size);
qt_opengl_check_test_pattern(fb);
}
示例13: QOpenGLFramebufferObject
void QQuickContext2DFBOTile::setRect(const QRect& r)
{
if (m_rect == r)
return;
m_rect = r;
m_dirty = true;
if (!m_fbo || m_fbo->size() != r.size()) {
QOpenGLFramebufferObjectFormat format;
format.setAttachment(QOpenGLFramebufferObject::CombinedDepthStencil);
format.setInternalTextureFormat(GL_RGBA);
format.setMipmap(false);
if (m_painter.isActive())
m_painter.end();
delete m_fbo;
m_fbo = new QOpenGLFramebufferObject(r.size(), format);
}
}
示例14: QFETCH
void tst_QOpenGL::fboTextureOwnership()
{
QFETCH(int, surfaceClass);
QScopedPointer<QSurface> surface(createSurface(surfaceClass));
QOpenGLContext ctx;
QVERIFY(ctx.create());
ctx.makeCurrent(surface.data());
if (!QOpenGLFramebufferObject::hasOpenGLFramebufferObjects())
QSKIP("QOpenGLFramebufferObject not supported on this platform");
QOpenGLFramebufferObjectFormat fboFormat;
fboFormat.setAttachment(QOpenGLFramebufferObject::NoAttachment);
QOpenGLFramebufferObject *fbo = new QOpenGLFramebufferObject(200, 100, fboFormat);
QVERIFY(fbo->texture() != 0);
fbo->bind();
// pull out the texture
GLuint texture = fbo->takeTexture();
QVERIFY(texture != 0);
QVERIFY(fbo->texture() == 0);
// verify that the next bind() creates a new texture
fbo->bind();
QVERIFY(fbo->texture() != 0 && fbo->texture() != texture);
glClearColor(1.0, 0.0, 0.0, 1.0);
glClear(GL_COLOR_BUFFER_BIT);
glFinish();
QImage fb = fbo->toImage().convertToFormat(QImage::Format_RGB32);
QImage reference(fb.size(), QImage::Format_RGB32);
reference.fill(0xffff0000);
QFUZZY_COMPARE_IMAGES(fb, reference);
glDeleteTextures(1, &texture);
delete fbo;
}
示例15: Q_D
bool QGLPixelBuffer::makeCurrent()
{
Q_D(QGLPixelBuffer);
if (d->invalid)
return false;
d->qctx->makeCurrent();
if (!d->fbo) {
QOpenGLFramebufferObjectFormat format;
if (d->req_format.stencil())
format.setAttachment(QOpenGLFramebufferObject::CombinedDepthStencil);
else if (d->req_format.depth())
format.setAttachment(QOpenGLFramebufferObject::Depth);
if (d->req_format.sampleBuffers())
format.setSamples(d->req_format.samples());
d->fbo = new QOpenGLFramebufferObject(d->req_size, format);
d->fbo->bind();
d->glDevice.setFbo(d->fbo->handle());
QOpenGLContext::currentContext()->functions()->glViewport(0, 0, d->req_size.width(), d->req_size.height());
}
return true;
}