本文整理汇总了C++中QOpenGLFramebufferObjectFormat::setSamples方法的典型用法代码示例。如果您正苦于以下问题:C++ QOpenGLFramebufferObjectFormat::setSamples方法的具体用法?C++ QOpenGLFramebufferObjectFormat::setSamples怎么用?C++ QOpenGLFramebufferObjectFormat::setSamples使用的例子?那么, 这里精选的方法代码示例或许可以为您提供帮助。您也可以进一步了解该方法所在类QOpenGLFramebufferObjectFormat
的用法示例。
在下文中一共展示了QOpenGLFramebufferObjectFormat::setSamples方法的11个代码示例,这些例子默认根据受欢迎程度排序。您可以为喜欢或者感觉有用的代码点赞,您的评价将有助于系统推荐出更棒的C++代码示例。
示例1: QOpenGLFramebufferObject
QOpenGLFramebufferObject *createFramebufferObject(const QSize &size)
{
QOpenGLFramebufferObjectFormat format;
format.setAttachment(QOpenGLFramebufferObject::CombinedDepthStencil);
format.setSamples(4);
return new QOpenGLFramebufferObject(size, format);
}
示例2: initializeGL
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;
}
示例3: render
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();
}
示例4: 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;
}
示例5:
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;
}
示例6: makeCurrent
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;
}
示例7: sipNoMethod
static PyObject *meth_QOpenGLFramebufferObjectFormat_setSamples(PyObject *sipSelf, PyObject *sipArgs)
{
PyObject *sipParseErr = NULL;
{
int a0;
QOpenGLFramebufferObjectFormat *sipCpp;
if (sipParseArgs(&sipParseErr, sipArgs, "Bi", &sipSelf, sipType_QOpenGLFramebufferObjectFormat, &sipCpp, &a0))
{
sipCpp->setSamples(a0);
Py_INCREF(Py_None);
return Py_None;
}
}
/* Raise an exception if the arguments couldn't be parsed. */
sipNoMethod(sipParseErr, sipName_QOpenGLFramebufferObjectFormat, sipName_setSamples, doc_QOpenGLFramebufferObjectFormat_setSamples);
return NULL;
}
示例8: paintGL
void GLWidget::paintGL()
{
QOpenGLFunctions* f = openglContext()->functions();
int width = this->width() * devicePixelRatio();
int height = this->height() * devicePixelRatio();
glDisable(GL_BLEND);
glDisable(GL_DEPTH_TEST);
glDepthMask(GL_FALSE);
glViewport(0, 0, width, height);
check_error(f);
QColor color(KdenliveSettings::window_background()); //= QPalette().color(QPalette::Window);
glClearColor(color.redF(), color.greenF(), color.blueF(), color.alphaF());
glClear(GL_COLOR_BUFFER_BIT);
check_error(f);
if (!m_texture[0]) return;
// Bind textures.
for (int i = 0; i < 3; ++i) {
if (m_texture[i]) {
glActiveTexture(GL_TEXTURE0 + i);
glBindTexture(GL_TEXTURE_2D, m_texture[i]);
check_error(f);
}
}
// Init shader program.
m_shader->bind();
if (m_glslManager) {
m_shader->setUniformValue(m_textureLocation[0], 0);
} else {
m_shader->setUniformValue(m_textureLocation[0], 0);
m_shader->setUniformValue(m_textureLocation[1], 1);
m_shader->setUniformValue(m_textureLocation[2], 2);
m_shader->setUniformValue(m_colorspaceLocation, m_monitorProfile->colorspace());
}
check_error(f);
// Setup an orthographic projection.
QMatrix4x4 projection;
projection.scale(2.0f / width, 2.0f / height);
m_shader->setUniformValue(m_projectionLocation, projection);
check_error(f);
// Set model view.
QMatrix4x4 modelView;
if (m_zoom != 1.0) {
if (offset().x() || offset().y())
modelView.translate(-offset().x() * devicePixelRatio(),
offset().y() * devicePixelRatio());
modelView.scale(zoom(), zoom());
}
m_shader->setUniformValue(m_modelViewLocation, modelView);
check_error(f);
// Provide vertices of triangle strip.
QVector<QVector2D> vertices;
width = m_rect.width() * devicePixelRatio();
height = m_rect.height() * devicePixelRatio();
vertices << QVector2D(float(-width)/2.0f, float(-height)/2.0f);
vertices << QVector2D(float(-width)/2.0f, float( height)/2.0f);
vertices << QVector2D(float( width)/2.0f, float(-height)/2.0f);
vertices << QVector2D(float( width)/2.0f, float( height)/2.0f);
m_shader->enableAttributeArray(m_vertexLocation);
check_error(f);
m_shader->setAttributeArray(m_vertexLocation, vertices.constData());
check_error(f);
// Provide texture coordinates.
QVector<QVector2D> texCoord;
texCoord << QVector2D(0.0f, 1.0f);
texCoord << QVector2D(0.0f, 0.0f);
texCoord << QVector2D(1.0f, 1.0f);
texCoord << QVector2D(1.0f, 0.0f);
m_shader->enableAttributeArray(m_texCoordLocation);
check_error(f);
m_shader->setAttributeArray(m_texCoordLocation, texCoord.constData());
check_error(f);
// Render
glDrawArrays(GL_TRIANGLE_STRIP, 0, vertices.size());
check_error(f);
// Render RGB frame for analysis
if (sendFrameForAnalysis) {
if (!m_fbo || m_fbo->size() != QSize(width, height)) {
delete m_fbo;
QOpenGLFramebufferObjectFormat f;
f.setSamples(0);
f.setInternalTextureFormat(GL_RGB); //GL_RGBA32F); // which one is the fastest ?
m_fbo = new QOpenGLFramebufferObject(width, height, f); //GL_TEXTURE_2D);
}
m_fbo->bind();
glViewport(0, 0, width, height);
projection.scale((double) this->width() / width, (double) this->height() / height);
m_shader->setUniformValue(m_projectionLocation, projection);
glDrawArrays(GL_TRIANGLE_STRIP, 0, vertices.size());
check_error(f);
m_fbo->release();
//.........这里部分代码省略.........
示例9: grab
void SSGQuickLayer::grab()
{
if (!m_item || m_size.isNull()) {
delete m_fbo;
delete m_secondaryFbo;
m_fbo = m_secondaryFbo = 0;
m_depthStencilBuffer.clear();
m_dirtyTexture = false;
return;
}
QSGNode *root = m_item;
while (root->firstChild() && root->type() != QSGNode::RootNodeType)
root = root->firstChild();
if (root->type() != QSGNode::RootNodeType)
return;
if (!m_renderer) {
m_renderer = m_context->createRenderer();
connect(m_renderer, SIGNAL(sceneGraphChanged()), this, SLOT(markDirtyTexture()));
}
m_renderer->setDevicePixelRatio(m_device_pixel_ratio);
m_renderer->setRootNode(static_cast<QSGRootNode *>(root));
QOpenGLFunctions *funcs = QOpenGLContext::currentContext()->functions();
bool deleteFboLater = false;
if (!m_fbo || m_fbo->size() != m_size || m_fbo->format().internalTextureFormat() != m_format
|| (!m_fbo->format().mipmap() && m_mipmap))
{
if (!m_multisamplingChecked) {
if (m_context->openglContext()->format().samples() <= 1) {
m_multisampling = false;
} else {
const QSet<QByteArray> extensions = m_context->openglContext()->extensions();
m_multisampling = extensions.contains(QByteArrayLiteral("GL_EXT_framebuffer_multisample"))
&& extensions.contains(QByteArrayLiteral("GL_EXT_framebuffer_blit"));
}
m_multisamplingChecked = true;
}
if (m_multisampling) {
// Don't delete the FBO right away in case it is used recursively.
deleteFboLater = true;
delete m_secondaryFbo;
QOpenGLFramebufferObjectFormat format;
format.setInternalTextureFormat(m_format);
format.setSamples(m_context->openglContext()->format().samples());
m_secondaryFbo = new QOpenGLFramebufferObject(m_size, format);
m_depthStencilBuffer = m_context->depthStencilBufferForFbo(m_secondaryFbo);
} else {
QOpenGLFramebufferObjectFormat format;
format.setInternalTextureFormat(m_format);
format.setMipmap(m_mipmap);
if (m_recursive) {
deleteFboLater = true;
delete m_secondaryFbo;
m_secondaryFbo = new QOpenGLFramebufferObject(m_size, format);
funcs->glBindTexture(GL_TEXTURE_2D, m_secondaryFbo->texture());
updateBindOptions(true);
m_depthStencilBuffer = m_context->depthStencilBufferForFbo(m_secondaryFbo);
} else {
delete m_fbo;
delete m_secondaryFbo;
m_fbo = new QOpenGLFramebufferObject(m_size, format);
m_secondaryFbo = 0;
funcs->glBindTexture(GL_TEXTURE_2D, m_fbo->texture());
updateBindOptions(true);
m_depthStencilBuffer = m_context->depthStencilBufferForFbo(m_fbo);
}
}
}
if (m_recursive && !m_secondaryFbo) {
// m_fbo already created, m_recursive was just set.
Q_ASSERT(m_fbo);
Q_ASSERT(!m_multisampling);
m_secondaryFbo = new QOpenGLFramebufferObject(m_size, m_fbo->format());
funcs->glBindTexture(GL_TEXTURE_2D, m_secondaryFbo->texture());
updateBindOptions(true);
}
// Render texture.
root->markDirty(QSGNode::DirtyForceUpdate); // Force matrix, clip and opacity update.
m_renderer->nodeChanged(root, QSGNode::DirtyForceUpdate); // Force render list update.
#ifdef QSG_DEBUG_FBO_OVERLAY
if (qmlFboOverlay()) {
if (!m_debugOverlay)
m_debugOverlay = new QSGSimpleRectNode();
m_debugOverlay->setRect(QRectF(0, 0, m_size.width(), m_size.height()));
m_debugOverlay->setColor(QColor(0xff, 0x00, 0x80, 0x40));
root->appendChildNode(m_debugOverlay);
}
#endif
m_dirtyTexture = false;
m_renderer->setDeviceRect(m_size);
m_renderer->setViewportRect(m_size);
QRectF mirrored(m_mirrorHorizontal ? m_rect.right() : m_rect.left(),
//.........这里部分代码省略.........
示例10: updateRenderTarget
void QSGPainterNode::updateRenderTarget()
{
if (!m_extensionsChecked) {
const QSet<QByteArray> extensions = m_context->openglContext()->extensions();
m_multisamplingSupported = extensions.contains(QByteArrayLiteral("GL_EXT_framebuffer_multisample"))
&& extensions.contains(QByteArrayLiteral("GL_EXT_framebuffer_blit"));
m_extensionsChecked = true;
}
m_dirtyContents = true;
QQuickPaintedItem::RenderTarget oldTarget = m_actualRenderTarget;
if (m_preferredRenderTarget == QQuickPaintedItem::Image) {
m_actualRenderTarget = QQuickPaintedItem::Image;
} else {
if (!m_multisamplingSupported && m_smoothPainting)
m_actualRenderTarget = QQuickPaintedItem::Image;
else
m_actualRenderTarget = m_preferredRenderTarget;
}
if (oldTarget != m_actualRenderTarget) {
m_image = QImage();
delete m_fbo;
delete m_multisampledFbo;
delete m_gl_device;
m_fbo = m_multisampledFbo = 0;
m_gl_device = 0;
}
if (m_actualRenderTarget == QQuickPaintedItem::FramebufferObject ||
m_actualRenderTarget == QQuickPaintedItem::InvertedYFramebufferObject) {
const QOpenGLContext *ctx = m_context->openglContext();
if (m_fbo && !m_dirtyGeometry && (!ctx->format().samples() || !m_multisamplingSupported))
return;
if (m_fboSize.isEmpty())
updateFBOSize();
delete m_fbo;
delete m_multisampledFbo;
m_fbo = m_multisampledFbo = 0;
if (m_gl_device)
m_gl_device->setSize(m_fboSize);
if (m_smoothPainting && ctx->format().samples() && m_multisamplingSupported) {
{
QOpenGLFramebufferObjectFormat format;
format.setAttachment(QOpenGLFramebufferObject::CombinedDepthStencil);
format.setSamples(8);
m_multisampledFbo = new QOpenGLFramebufferObject(m_fboSize, format);
}
{
QOpenGLFramebufferObjectFormat format;
format.setAttachment(QOpenGLFramebufferObject::NoAttachment);
m_fbo = new QOpenGLFramebufferObject(m_fboSize, format);
}
} else {
QOpenGLFramebufferObjectFormat format;
format.setAttachment(QOpenGLFramebufferObject::CombinedDepthStencil);
m_fbo = new QOpenGLFramebufferObject(m_fboSize, format);
}
} else {
if (!m_image.isNull() && !m_dirtyGeometry)
return;
m_image = QImage(m_size, QImage::Format_ARGB32_Premultiplied);
m_image.fill(Qt::transparent);
}
QSGPainterTexture *texture = new QSGPainterTexture;
if (m_actualRenderTarget == QQuickPaintedItem::Image) {
texture->setOwnsTexture(true);
texture->setTextureSize(m_size);
} else {
texture->setTextureId(m_fbo->texture());
texture->setOwnsTexture(false);
texture->setTextureSize(m_fboSize);
}
if (m_texture)
delete m_texture;
texture->setTextureSize(m_size);
m_texture = texture;
}
示例11: main
//.........这里部分代码省略.........
OnScreenWidget<QWidget> *qWidget =
new OnScreenWidget<QWidget>(files.at(j));
qWidget->setVerboseMode(verboseMode);
qWidget->setType(type);
qWidget->setCheckersBackground(checkers_background);
qWidget->m_commands = content;
qWidget->resize(width, height);
qWidget->show();
activeWidget = qWidget;
break;
}
case ImageWidgetType:
{
OnScreenWidget<QWidget> *qWidget = new OnScreenWidget<QWidget>(files.at(j));
qWidget->setVerboseMode(verboseMode);
qWidget->setType(type);
qWidget->setCheckersBackground(checkers_background);
qWidget->m_commands = content;
qWidget->resize(width, height);
qWidget->show();
activeWidget = qWidget;
break;
}
#ifndef QT_NO_OPENGL
case OpenGLBufferType:
{
QWindow win;
win.setSurfaceType(QSurface::OpenGLSurface);
win.create();
QOpenGLFramebufferObjectFormat fmt;
fmt.setAttachment(QOpenGLFramebufferObject::CombinedDepthStencil);
fmt.setSamples(4);
QOpenGLContext ctx;
ctx.create();
ctx.makeCurrent(&win);
QOpenGLFramebufferObject fbo(width, height, fmt);
fbo.bind();
QOpenGLPaintDevice pdev(width, height);
QPainter pt(&pdev);
pcmd.setPainter(&pt);
pcmd.setFilePath(fileinfo.absolutePath());
pcmd.runCommands();
pt.end();
QImage image = fbo.toImage();
QLabel *label = createLabel();
label->setPixmap(QPixmap::fromImage(image));
label->resize(label->sizeHint());
label->show();
activeWidget = label;
break;
}
case OpenGLType:
{
OnScreenWidget<QGLWidget> *qGLWidget = new OnScreenWidget<QGLWidget>(files.at(j));
qGLWidget->setVerboseMode(verboseMode);
qGLWidget->setType(type);
qGLWidget->setCheckersBackground(checkers_background);
qGLWidget->m_commands = content;
qGLWidget->resize(width, height);
qGLWidget->show();
activeWidget = qGLWidget;