OS X上的OpenGL版本支持

时间:2013-11-14 23:13:42

标签: c++ macos qt opengl

我尝试以现代管道实现的方式在OS X 10.9上使用Qt(v5.1.1)编写OpenGL项目。但是,我从教程中重建程序遇到了一些问题,例如: http://qt-project.org/wiki/How_to_use_OpenGL_Core_Profile_with_Qt

简单的三角形没有出现,但没有警告,程序本身就显示出来了。我怀疑我的mac可能不支持GLSL。所以我找了一种方法来打印一些信息。我发现有类似问题的人就是这样做的。

#include <QApplication>
#include <QGLFormat>
#include "glwidget.h"

int main(int argc, char* argv[])
{
    QApplication mApplication(argc, argv);

    QGLFormat mGlFormat;
    mGlFormat.setVersion(3, 3);
    mGlFormat.setProfile(QGLFormat::CoreProfile);
    mGlFormat.setSampleBuffers(true);

    qDebug() << "OpenGL context QFlags " << mGlFormat.openGLVersionFlags();
    qDebug() << "OpenGL context " << mGlFormat;

    GLWidget mWidget(mGlFormat);
    mWidget.show();

    qDebug() << "OpenGL context" << mWidget.format();
    qDebug() << "Driver Version String:" << glGetString(GL_VERSION);

    return mApplication.exec();
}

我得到了结果。

  

OpenGL上下文QFlags QFlags(0x1 | 0x2 | 0x4 | 0x8 | 0x10 | 0x20 | 0x40 | 0x1000 | 0x2000 | 0x4000 | 0x8000)

     

OpenGL上下文QGLFormat(选项QFlags(0x1 | 0x2 | 0x4 | 0x20 | 0x80 | 0x200 | 0x400),plane 0,depthBufferSize -1,accumBufferSize -1,stencilBufferSize -1,redBufferSize -1,greenBufferSize -1,blueBufferSize - 1,alphaBufferSize -1,样本-1,swapInterval -1,majorVersion 3,minorVersion 3,profile 1)

     

OpenGL上下文QGLFormat(选项QFlags(0x1 | 0x2 | 0x4 | 0x20 | 0x80 | 0x200 | 0x400),plane 0,depthBufferSize 1,accumBufferSize -1,stencilBufferSize 1,redBufferSize -1,greenBufferSize -1,blueBufferSize -1, alphaBufferSize -1,samples 4,swapInterval -1,majorVersion 3,minorVersion 3,profile 1)

     

驱动程序版本字符串:0x10800e6be

即使我不确定这个的确切含义,从这个想法的来源写的,似乎0x8000意味着首先支持OpenGL 3.3但是因为后来的标志只有0x400版本支持在路上不知何故丢失了。

我的显卡是NVIDIA GeForce 9400M 256 MB,应该支持OpenGL 3.3。 https://developer.apple.com/graphicsimaging/opengl/capabilities/

  • 这是否意味着我无法在这些配置下使用GLSL?
  • 如果是这样,是否可以升级某些库或图形驱动程序?
  • 在不支持核心配置文件的计算机上启动时使用核心配置文件的应用程序会发生什么?

类似的帖子 Can't set desired OpenGL version in QGLWidget

1 个答案:

答案 0 :(得分:3)

似乎我不是唯一一个与tutorial挣扎的人,我找到了解决方案here。即使提到它,也缺少绑定VAO的教程的源代码。

  

在m_shader.setAttributeBuffer:

之前的initializeGL中添加它
uint vao;

typedef void (APIENTRY *_glGenVertexArrays) (GLsizei, GLuint*);
typedef void (APIENTRY *_glBindVertexArray) (GLuint);

_glGenVertexArrays glGenVertexArrays;
_glBindVertexArray glBindVertexArray;

glGenVertexArrays = (_glGenVertexArrays) QGLWidget::context()->getProcAddress("glGenVertexArrays");
glBindVertexArray = (_glBindVertexArray) QGLWidget::context()->getProcAddress("glBindVertexArray");

glGenVertexArrays(1, &vao);
glBindVertexArray(vao);
相关问题