Commit 45808a17 by Geoff Lang

Use WGL_ARB_pixel_format to choose the pixel format when available.

BUG=angleproject:890 Change-Id: If10ea7e1cb670bb3cd6fdcf40344d1c1e0acd862 Reviewed-on: https://chromium-review.googlesource.com/291650Reviewed-by: 's avatarJamie Madill <jmadill@chromium.org> Tested-by: 's avatarGeoff Lang <geofflang@chromium.org>
parent 1b94d432
......@@ -199,7 +199,20 @@ egl::Error DisplayWGL::initialize(egl::Display *display)
return egl::Error(EGL_NOT_INITIALIZED, "Failed to get the device context of the intermediate OpenGL window.");
}
mPixelFormat = ChoosePixelFormat(mDeviceContext, &pixelFormatDescriptor);
if (mFunctionsWGL->choosePixelFormatARB)
{
std::vector<int> attribs = wgl::GetDefaultPixelFormatAttributes(false);
UINT matchingFormats = 0;
mFunctionsWGL->choosePixelFormatARB(mDeviceContext, &attribs[0], nullptr, 1u, &mPixelFormat,
&matchingFormats);
}
if (mPixelFormat == 0)
{
mPixelFormat = ChoosePixelFormat(mDeviceContext, &pixelFormatDescriptor);
}
if (mPixelFormat == 0)
{
return egl::Error(EGL_NOT_INITIALIZED, "Could not find a compatible pixel format for the intermediate OpenGL window.");
......@@ -340,17 +353,6 @@ SurfaceImpl *DisplayWGL::createPixmapSurface(const egl::Config *configuration,
return nullptr;
}
static int QueryWGLFormatAttrib(HDC dc, int format, int attribName, const FunctionsWGL *functions)
{
int result = 0;
if (functions->getPixelFormatAttribivARB == nullptr ||
!functions->getPixelFormatAttribivARB(dc, format, 0, 1, &attribName, &result))
{
return 0;
}
return result;
}
egl::Error DisplayWGL::getDevice(DeviceImpl **device)
{
UNIMPLEMENTED();
......@@ -377,6 +379,11 @@ egl::ConfigSet DisplayWGL::generateConfigs() const
PIXELFORMATDESCRIPTOR pixelFormatDescriptor;
DescribePixelFormat(mDeviceContext, mPixelFormat, sizeof(pixelFormatDescriptor), &pixelFormatDescriptor);
auto getAttrib = [this](int attrib)
{
return wgl::QueryWGLFormatAttrib(mDeviceContext, mPixelFormat, attrib, mFunctionsWGL);
};
egl::Config config;
config.renderTargetFormat = GL_RGBA8; // TODO: use the bit counts to determine the format
config.depthStencilFormat = GL_DEPTH24_STENCIL8; // TODO: use the bit counts to determine the format
......@@ -387,17 +394,17 @@ egl::ConfigSet DisplayWGL::generateConfigs() const
config.luminanceSize = 0;
config.alphaSize = pixelFormatDescriptor.cAlphaBits;
config.alphaMaskSize = 0;
config.bindToTextureRGB = (QueryWGLFormatAttrib(mDeviceContext, mPixelFormat, WGL_BIND_TO_TEXTURE_RGB_ARB, mFunctionsWGL) == TRUE);
config.bindToTextureRGBA = (QueryWGLFormatAttrib(mDeviceContext, mPixelFormat, WGL_BIND_TO_TEXTURE_RGBA_ARB, mFunctionsWGL) == TRUE);
config.bindToTextureRGB = (getAttrib(WGL_BIND_TO_TEXTURE_RGB_ARB) == TRUE);
config.bindToTextureRGBA = (getAttrib(WGL_BIND_TO_TEXTURE_RGBA_ARB) == TRUE);
config.colorBufferType = EGL_RGB_BUFFER;
config.configCaveat = EGL_NONE;
config.conformant = EGL_OPENGL_ES2_BIT | (supportsES3 ? EGL_OPENGL_ES3_BIT_KHR : 0);
config.depthSize = pixelFormatDescriptor.cDepthBits;
config.level = 0;
config.matchNativePixmap = EGL_NONE;
config.maxPBufferWidth = QueryWGLFormatAttrib(mDeviceContext, mPixelFormat, WGL_MAX_PBUFFER_WIDTH_ARB, mFunctionsWGL);
config.maxPBufferHeight = QueryWGLFormatAttrib(mDeviceContext, mPixelFormat, WGL_MAX_PBUFFER_HEIGHT_ARB, mFunctionsWGL);
config.maxPBufferPixels = QueryWGLFormatAttrib(mDeviceContext, mPixelFormat, WGL_MAX_PBUFFER_PIXELS_ARB, mFunctionsWGL);
config.maxPBufferWidth = getAttrib(WGL_MAX_PBUFFER_WIDTH_ARB);
config.maxPBufferHeight = getAttrib(WGL_MAX_PBUFFER_HEIGHT_ARB);
config.maxPBufferPixels = getAttrib(WGL_MAX_PBUFFER_PIXELS_ARB);
config.maxSwapInterval = maxSwapInterval;
config.minSwapInterval = minSwapInterval;
config.nativeRenderable = EGL_TRUE; // Direct rendering
......@@ -407,9 +414,11 @@ egl::ConfigSet DisplayWGL::generateConfigs() const
config.sampleBuffers = 0; // FIXME: enumerate multi-sampling
config.samples = 0;
config.stencilSize = pixelFormatDescriptor.cStencilBits;
config.surfaceType = ((pixelFormatDescriptor.dwFlags & PFD_DRAW_TO_WINDOW) ? EGL_WINDOW_BIT : 0) |
((QueryWGLFormatAttrib(mDeviceContext, mPixelFormat, WGL_DRAW_TO_PBUFFER_ARB, mFunctionsWGL) == TRUE) ? EGL_PBUFFER_BIT : 0) |
EGL_SWAP_BEHAVIOR_PRESERVED_BIT;
config.surfaceType =
((pixelFormatDescriptor.dwFlags & PFD_DRAW_TO_WINDOW) ? EGL_WINDOW_BIT : 0) |
((getAttrib(WGL_DRAW_TO_PBUFFER_ARB) == TRUE) ? EGL_PBUFFER_BIT : 0) |
((getAttrib(WGL_SWAP_METHOD_ARB) == WGL_SWAP_COPY_ARB) ? EGL_SWAP_BEHAVIOR_PRESERVED_BIT
: 0);
config.transparentType = EGL_NONE;
config.transparentRedValue = 0;
config.transparentGreenValue = 0;
......
......@@ -121,8 +121,16 @@ void FunctionsWGL::initialize(HMODULE glModule, HDC context)
}
// Load the wgl extension functions by checking if the context supports the extension first
// WGL_ARB_create_context
GetWGLExtensionProcAddress(glModule, getProcAddress, extensions, "WGL_ARB_create_context", "wglCreateContextAttribsARB", &createContextAttribsARB);
// WGL_ARB_pixel_format
GetWGLExtensionProcAddress(glModule, getProcAddress, extensions, "WGL_ARB_pixel_format", "wglGetPixelFormatAttribivARB", &getPixelFormatAttribivARB);
GetWGLExtensionProcAddress(glModule, getProcAddress, extensions, "WGL_ARB_pixel_format", "wglGetPixelFormatAttribfvARB", &getPixelFormatAttribfvARB);
GetWGLExtensionProcAddress(glModule, getProcAddress, extensions, "WGL_ARB_pixel_format", "wglChoosePixelFormatARB", &choosePixelFormatARB);
// WGL_EXT_swap_control
GetWGLExtensionProcAddress(glModule, getProcAddress, extensions, "WGL_EXT_swap_control", "wglSwapIntervalEXT", &swapIntervalEXT);
// WGL_ARB_pbuffer
......
......@@ -42,11 +42,21 @@ class FunctionsWGL : angle::NonCopyable
PFNWGLSWAPLAYERBUFFERSPROC swapLayerBuffers;
PFNWGLSWAPMULTIPLEBUFFERSPROC swapMultipleBuffers;
// Extension functions, may be NULL
PFNWGLCREATECONTEXTATTRIBSARBPROC createContextAttribsARB;
PFNWGLGETPIXELFORMATATTRIBIVARBPROC getPixelFormatAttribivARB;
// WGL_EXT_extensions_string
PFNWGLGETEXTENSIONSSTRINGEXTPROC getExtensionStringEXT;
// WGL_ARB_extensions_string
PFNWGLGETEXTENSIONSSTRINGARBPROC getExtensionStringARB;
// WGL_ARB_create_context
PFNWGLCREATECONTEXTATTRIBSARBPROC createContextAttribsARB;
// WGL_ARB_pixel_format
PFNWGLGETPIXELFORMATATTRIBIVARBPROC getPixelFormatAttribivARB;
PFNWGLGETPIXELFORMATATTRIBFVARBPROC getPixelFormatAttribfvARB;
PFNWGLCHOOSEPIXELFORMATARBPROC choosePixelFormatARB;
// WGL_EXT_swap_control
PFNWGLSWAPINTERVALEXTPROC swapIntervalEXT;
// WGL_ARB_pbuffer
......
......@@ -15,13 +15,17 @@
namespace rx
{
WindowSurfaceWGL::WindowSurfaceWGL(EGLNativeWindowType window, int pixelFormat, HGLRC wglContext, const FunctionsWGL *functions)
WindowSurfaceWGL::WindowSurfaceWGL(EGLNativeWindowType window,
int pixelFormat,
HGLRC wglContext,
const FunctionsWGL *functions)
: SurfaceGL(),
mPixelFormat(pixelFormat),
mWGLContext(wglContext),
mWindow(window),
mDeviceContext(nullptr),
mFunctionsWGL(functions)
mFunctionsWGL(functions),
mSwapBehavior(0)
{
}
......@@ -61,6 +65,21 @@ egl::Error WindowSurfaceWGL::initialize()
return egl::Error(EGL_NOT_INITIALIZED, "Pixel format of the NativeWindow and NativeDisplayType must match.");
}
// Check for the swap behavior of this pixel format
switch (
wgl::QueryWGLFormatAttrib(mDeviceContext, mPixelFormat, WGL_SWAP_METHOD_ARB, mFunctionsWGL))
{
case WGL_SWAP_COPY_ARB:
mSwapBehavior = EGL_BUFFER_PRESERVED;
break;
case WGL_SWAP_EXCHANGE_ARB:
case WGL_SWAP_UNDEFINED_ARB:
default:
mSwapBehavior = EGL_BUFFER_DESTROYED;
break;
}
return egl::Error(EGL_SUCCESS);
}
......@@ -147,7 +166,7 @@ EGLint WindowSurfaceWGL::isPostSubBufferSupported() const
EGLint WindowSurfaceWGL::getSwapBehavior() const
{
return EGL_BUFFER_PRESERVED;
return mSwapBehavior;
}
}
......@@ -49,6 +49,8 @@ class WindowSurfaceWGL : public SurfaceGL
HDC mDeviceContext;
const FunctionsWGL *mFunctionsWGL;
EGLint mSwapBehavior;
};
}
......
......@@ -8,6 +8,8 @@
#include "libANGLE/renderer/gl/wgl/wgl_utils.h"
#include "libANGLE/renderer/gl/wgl/functionsWGL.h"
namespace rx
{
......@@ -30,6 +32,54 @@ PIXELFORMATDESCRIPTOR GetDefaultPixelFormatDescriptor()
return pixelFormatDescriptor;
}
std::vector<int> GetDefaultPixelFormatAttributes(bool preservedSwap)
{
std::vector<int> attribs;
attribs.push_back(WGL_DRAW_TO_WINDOW_ARB);
attribs.push_back(TRUE);
attribs.push_back(WGL_ACCELERATION_ARB);
attribs.push_back(WGL_FULL_ACCELERATION_ARB);
attribs.push_back(WGL_SUPPORT_OPENGL_ARB);
attribs.push_back(TRUE);
attribs.push_back(WGL_DOUBLE_BUFFER_ARB);
attribs.push_back(TRUE);
attribs.push_back(WGL_PIXEL_TYPE_ARB);
attribs.push_back(WGL_TYPE_RGBA_ARB);
attribs.push_back(WGL_COLOR_BITS_ARB);
attribs.push_back(24);
attribs.push_back(WGL_ALPHA_BITS_ARB);
attribs.push_back(8);
attribs.push_back(WGL_DEPTH_BITS_ARB);
attribs.push_back(24);
attribs.push_back(WGL_STENCIL_BITS_ARB);
attribs.push_back(8);
attribs.push_back(WGL_SWAP_METHOD_ARB);
attribs.push_back(preservedSwap ? WGL_SWAP_COPY_ARB : WGL_SWAP_UNDEFINED_ARB);
attribs.push_back(0);
return attribs;
}
int QueryWGLFormatAttrib(HDC dc, int format, int attribName, const FunctionsWGL *functions)
{
int result = 0;
if (functions->getPixelFormatAttribivARB == nullptr ||
!functions->getPixelFormatAttribivARB(dc, format, 0, 1, &attribName, &result))
{
return 0;
}
return result;
}
}
}
......@@ -9,16 +9,22 @@
#ifndef LIBANGLE_RENDERER_GL_WGL_WGLUTILS_H_
#define LIBANGLE_RENDERER_GL_WGL_WGLUTILS_H_
#include <vector>
#include "common/platform.h"
namespace rx
{
class FunctionsWGL;
namespace wgl
{
PIXELFORMATDESCRIPTOR GetDefaultPixelFormatDescriptor();
std::vector<int> GetDefaultPixelFormatAttributes(bool preservedSwap);
int QueryWGLFormatAttrib(HDC dc, int format, int attribName, const FunctionsWGL *functions);
}
}
......
Markdown is supported
0% or
You are about to add 0 people to the discussion. Proceed with caution.
Finish editing this message first!
Please register or to comment