- iOS/Objective-C 元类和类别
- objective-c - -1001 错误,当 NSURLSession 通过 httpproxy 和/etc/hosts
- java - 使用网络类获取 url 地址
- ios - 推送通知中不播放声音
我正在执行以下代码来创建核心配置文件 OpenGL 上下文。
具体来说,我是:
wglCreateContextAttribsARB
在第二个窗口中创建第二个上下文,特别是使用核心配置文件。代码:
WNDCLASSW wcDummy = {0};
wcDummy.lpfnWndProc = +[](HWND hWnd, UINT message, WPARAM wParam, LPARAM lParam){return DefWindowProcW(hWnd, message, wParam, lParam);};
wcDummy.hInstance = GetModuleHandle(0);
wcDummy.hbrBackground = (HBRUSH)(COLOR_BACKGROUND);
wcDummy.lpszClassName = L"Dummy";
wcDummy.style = CS_OWNDC;
if(!RegisterClassW(&wcDummy))
{
get_and_print_error();
return false;
}
HWND windowDummy = CreateWindowW(wcDummy.lpszClassName, title.c_str(), WS_DISABLED, 0, 0, 640, 480, 0, 0, wcDummy.hInstance, NULL);
if(windowDummy == NULL)
{
get_and_print_error();
return false;
}
PIXELFORMATDESCRIPTOR pfdDummy =
{
sizeof(PIXELFORMATDESCRIPTOR),
1,
PFD_DRAW_TO_WINDOW | PFD_SUPPORT_OPENGL | PFD_DOUBLEBUFFER,
PFD_TYPE_RGBA,
32,
0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0,
24,
8,
0, 0, 0, 0, 0, 0
};
HDC dummyDrawingContext = GetDC(windowDummy);
INT pixelFormatDummy = ChoosePixelFormat(dummyDrawingContext, &pfdDummy);
SetPixelFormat(dummyDrawingContext, pixelFormatDummy, &pfdDummy);
HGLRC dummyContext = wglCreateContext(dummyDrawingContext);
wglMakeCurrent(dummyDrawingContext, dummyContext);
if(wglGetCurrentContext() != NULL)
{
load_gl_functions();
}
else
return false;
PFNWGLCREATECONTEXTATTRIBSARBPROC wglCreateContextAttribsARB = nullptr;
GLint64 numExtensions;
glGetInteger64v(GL_NUM_EXTENSIONS, &numExtensions);
std::cout << "Available Extensions:\n";
for(GLint64 i = 0; i < numExtensions; ++i)
{
const GLubyte* extensionName = glGetStringi(GL_EXTENSIONS, i);
std::cout << "\n\t" << (const char*)extensionName;
if(std::strcmp((const char*)extensionName, "WGL_ARB_create_context") == 0)
{
wglCreateContextAttribsARB = (PFNWGLCREATECONTEXTATTRIBSARBPROC)wglGetProcAddress("wglCreateContextAttribsARB");
}
}
std::cout << std::endl;
wglDeleteContext(dummyContext);
DestroyWindow(windowDummy);
WNDCLASSW wc = {0};
wc.lpfnWndProc = Window::WndProc;
wc.hInstance = GetModuleHandle(0);
wc.hbrBackground = (HBRUSH)(COLOR_BACKGROUND);
wc.lpszClassName = title.c_str();
wc.style = CS_OWNDC;
if(!RegisterClassW(&wc))
{
get_and_print_error();
return false;
}
HWND window = CreateWindowW(wc.lpszClassName, title.c_str(), WS_OVERLAPPED|WS_VISIBLE|WS_SYSMENU ,0,0,640,480,0,0,wc.hInstance,this);
if(window == NULL)
{
get_and_print_error();
return false;
}
PIXELFORMATDESCRIPTOR pfd =
{
sizeof(PIXELFORMATDESCRIPTOR),
1,
PFD_DRAW_TO_WINDOW | PFD_SUPPORT_OPENGL | PFD_DOUBLEBUFFER,
PFD_TYPE_RGBA,
32,
0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0,
24,
8,
0, 0, 0, 0, 0, 0
};
HDC m_drawingContext = GetDC(window);
INT pixelFormat = ChoosePixelFormat(m_drawingContext, &pfd);
SetPixelFormat(m_drawingContext, pixelFormat, &pfd);
const GLint attribList[] =
{
WGL_CONTEXT_MAJOR_VERSION_ARB, 4,
WGL_CONTEXT_MINOR_VERSION_ARB, 4,
WGL_CONTEXT_PROFILE_MASK_ARB, WGL_CONTEXT_CORE_PROFILE_BIT_ARB,
0
};
m_glRenderContext = wglCreateContextAttribsARB(m_drawingContext, 0, attribList);
wglMakeCurrent(m_drawingContext, m_glRenderContext);
if(wglGetCurrentContext() != NULL)
{
load_gl_functions();
}
else
return false;
const GLubyte* driver = glGetString(GL_RENDERER);
const GLubyte* version = glGetString(GL_VERSION);
const GLubyte* glslVersion = glGetString(GL_SHADING_LANGUAGE_VERSION);
std::wcout << "Device: " << std::wstring(convert_gl_string_to_win32_string(driver)) << std::endl;
std::wcout << "GL Version: " << std::wstring(convert_gl_string_to_win32_string(version)) << std::endl;
std::wcout << "GLSL Version: " << std::wstring(convert_gl_string_to_win32_string(glslVersion)) << std::endl;
std::wcout << std::endl;
问题是 WGL_ARB_create_context
扩展不存在。
但是,如果我忘记检查扩展列表,即放弃循环并简单地:
wglCreateContextAttribsARB = (PFNWGLCREATECONTEXTATTRIBSARBPROC)wglGetProcAddress("wglCreateContextAttribsARB");
我最终得到一个函数指针,一切正常。
为什么我的可用扩展列表不提供 WGL_ARB_create_context
字符串,即使该扩展存在?
编辑 我有一个 AMD Radeon HD 7900 系列 Y
最佳答案
Why does my list of available extensions not provide the
WGL_ARB_create_context
string, even though the extension exists?
因为 WGL 扩展不需要通过 GL 扩展字符串进行广告。有 WGL_ARB_extension_string
控制 WGL 扩展广告的扩展。引用该规范:
Applications should call
wglGetProcAddress
to see whether or notwglGetExtensionsStringARB
is supported. If it is supported then it can be used to determine which WGL extensions are supported by the device.
因此,为了不产生任何递归问题,函数指针在非NULL
时保证有效。
如果您想知道为什么某些 WGL 扩展仍在 GL 扩展字符串中:这又是一个遗留问题。再次引用该扩展规范中的问题 1:
Note that extensions that were previously advertised via
glGetString
(e.g., the swap interval extension) should continue to be advertised there so existing applications don't break. They should also be advertised viawglGetExtensionsStringARB
so new applications can make one call to find out which WGL extensions are supported.
边注:
您使用 glGetStringi
的 GL 扩展查询机制只能从 GL 3.0 开始使用。 glGetInteger64v
和 glGetStringi
可能都不可用,如果在某些较旧的 GPU 上运行,或者回退到 Microsoft 的 GL 1.1 渲染器时,此代码很可能会崩溃。
关于c++ - 为什么我没有 WGL_ARB_create_context 扩展?,我们在Stack Overflow上找到一个类似的问题: https://stackoverflow.com/questions/45937728/
我正在开发一个包含以下代码的 lwjgl 项目: public class DisplayManager { private static final int WIDTH = 1280;
我正在执行以下代码来创建核心配置文件 OpenGL 上下文。 具体来说,我是: 创建一个虚拟窗口 使用这个虚拟窗口请求 OpenGL 上下文(我假设它会被硬件加速,但我不确定这是否重要) 使用这个 O
我是一名优秀的程序员,十分优秀!