|
|
@@ -16,6 +16,9 @@ namespace bgfx
|
|
|
PFNWGLMAKECURRENTPROC wglMakeCurrent;
|
|
|
PFNWGLCREATECONTEXTPROC wglCreateContext;
|
|
|
PFNWGLDELETECONTEXTPROC wglDeleteContext;
|
|
|
+ PFNWGLGETEXTENSIONSSTRINGARBPROC wglGetExtensionsStringARB;
|
|
|
+ PFNWGLCHOOSEPIXELFORMATARBPROC wglChoosePixelFormatARB;
|
|
|
+ PFNWGLCREATECONTEXTATTRIBSARBPROC wglCreateContextAttribsARB;
|
|
|
|
|
|
# define GL_IMPORT(_optional, _proto, _func) _proto _func
|
|
|
# include "glimports.h"
|
|
|
@@ -80,6 +83,117 @@ namespace bgfx
|
|
|
result = wglMakeCurrent(m_hdc, m_context);
|
|
|
BGFX_FATAL(0 != result, Fatal::UnableToInitialize, "wglMakeCurrent failed!");
|
|
|
|
|
|
+ wglGetExtensionsStringARB = (PFNWGLGETEXTENSIONSSTRINGARBPROC)wglGetProcAddress("wglGetExtensionsStringARB");
|
|
|
+ wglChoosePixelFormatARB = (PFNWGLCHOOSEPIXELFORMATARBPROC)wglGetProcAddress("wglChoosePixelFormatARB");
|
|
|
+ wglCreateContextAttribsARB = (PFNWGLCREATECONTEXTATTRIBSARBPROC)wglGetProcAddress("wglCreateContextAttribsARB");
|
|
|
+
|
|
|
+ if (NULL != wglGetExtensionsStringARB)
|
|
|
+ {
|
|
|
+ BX_TRACE("WGL extensions:");
|
|
|
+ const char* extensions = (const char*)wglGetExtensionsStringARB(m_hdc);
|
|
|
+ if (NULL != extensions)
|
|
|
+ {
|
|
|
+ char name[1024];
|
|
|
+ const char* pos = extensions;
|
|
|
+ const char* end = extensions + strlen(extensions);
|
|
|
+ while (pos < end)
|
|
|
+ {
|
|
|
+ uint32_t len;
|
|
|
+ const char* space = strchr(pos, ' ');
|
|
|
+ if (NULL != space)
|
|
|
+ {
|
|
|
+ len = uint32_min(sizeof(name), (uint32_t)(space - pos) );
|
|
|
+ }
|
|
|
+ else
|
|
|
+ {
|
|
|
+ len = uint32_min(sizeof(name), (uint32_t)strlen(pos) );
|
|
|
+ }
|
|
|
+
|
|
|
+ strncpy(name, pos, len);
|
|
|
+ name[len] = '\0';
|
|
|
+
|
|
|
+ BX_TRACE("\t%s", name);
|
|
|
+
|
|
|
+ pos += len+1;
|
|
|
+ }
|
|
|
+ }
|
|
|
+ }
|
|
|
+
|
|
|
+#if 0
|
|
|
+ // An application can only set the pixel format of a window one time.
|
|
|
+ // Once a window's pixel format is set, it cannot be changed.
|
|
|
+ // MSDN: http://msdn.microsoft.com/en-us/library/windows/desktop/dd369049%28v=vs.85%29.aspx
|
|
|
+ if (NULL != wglChoosePixelFormatARB
|
|
|
+ && NULL != wglCreateContextAttribsARB)
|
|
|
+ {
|
|
|
+ int32_t attrs[] =
|
|
|
+ {
|
|
|
+ WGL_SAMPLE_BUFFERS_ARB, 0,
|
|
|
+ WGL_SAMPLES_ARB, 0,
|
|
|
+ WGL_SUPPORT_OPENGL_ARB, true,
|
|
|
+ WGL_PIXEL_TYPE_ARB, WGL_TYPE_RGBA_ARB,
|
|
|
+ WGL_DRAW_TO_WINDOW_ARB, true,
|
|
|
+ WGL_DOUBLE_BUFFER_ARB, true,
|
|
|
+ WGL_RED_BITS_ARB, 8,
|
|
|
+ WGL_BLUE_BITS_ARB, 8,
|
|
|
+ WGL_GREEN_BITS_ARB, 8,
|
|
|
+ WGL_ALPHA_BITS_ARB, 8,
|
|
|
+ WGL_DEPTH_BITS_ARB, 24,
|
|
|
+ WGL_STENCIL_BITS_ARB, 8,
|
|
|
+ 0
|
|
|
+ };
|
|
|
+
|
|
|
+ uint32_t numFormats = 0;
|
|
|
+ do
|
|
|
+ {
|
|
|
+ result = wglChoosePixelFormatARB(m_hdc, attrs, NULL, 1, &pixelFormat, &numFormats);
|
|
|
+ if (0 == result
|
|
|
+ || 0 == numFormats)
|
|
|
+ {
|
|
|
+ attrs[3] >>= 1;
|
|
|
+ attrs[1] = attrs[3] == 0 ? 0 : 1;
|
|
|
+ }
|
|
|
+
|
|
|
+ } while (0 == numFormats);
|
|
|
+
|
|
|
+ DescribePixelFormat(m_hdc, pixelFormat, sizeof(PIXELFORMATDESCRIPTOR), &pfd);
|
|
|
+
|
|
|
+ BX_TRACE("Pixel format:\n"
|
|
|
+ "\tiPixelType %d\n"
|
|
|
+ "\tcColorBits %d\n"
|
|
|
+ "\tcAlphaBits %d\n"
|
|
|
+ "\tcDepthBits %d\n"
|
|
|
+ "\tcStencilBits %d\n"
|
|
|
+ , pfd.iPixelType
|
|
|
+ , pfd.cColorBits
|
|
|
+ , pfd.cAlphaBits
|
|
|
+ , pfd.cDepthBits
|
|
|
+ , pfd.cStencilBits
|
|
|
+ );
|
|
|
+
|
|
|
+ result = SetPixelFormat(m_hdc, pixelFormat, &pfd);
|
|
|
+ BGFX_FATAL(0 != result, Fatal::UnableToInitialize, "SetPixelFormat failed (last err: 0x%08x)!", GetLastError() );
|
|
|
+
|
|
|
+ wglMakeCurrent(m_hdc, NULL);
|
|
|
+ wglDeleteContext(m_context);
|
|
|
+
|
|
|
+ const int32_t contextAttrs[] =
|
|
|
+ {
|
|
|
+ WGL_CONTEXT_MAJOR_VERSION_ARB, 2,
|
|
|
+ WGL_CONTEXT_MINOR_VERSION_ARB, 1,
|
|
|
+#if BGFX_CONFIG_DEBUG
|
|
|
+ WGL_CONTEXT_FLAGS_ARB, WGL_CONTEXT_DEBUG_BIT_ARB,
|
|
|
+#endif // BGFX_CONFIG_DEBUG
|
|
|
+ 0
|
|
|
+ };
|
|
|
+
|
|
|
+ m_context = wglCreateContextAttribsARB(m_hdc, 0, contextAttrs);
|
|
|
+
|
|
|
+ result = wglMakeCurrent(m_hdc, m_context);
|
|
|
+ BGFX_FATAL(0 != result, Fatal::UnableToInitialize, "wglMakeCurrent failed!");
|
|
|
+ }
|
|
|
+#endif // 0
|
|
|
+
|
|
|
import();
|
|
|
}
|
|
|
|