Commit 0c83813f by Clemen Deng Committed by Commit Bot

Implement core wgl functions

- wglSwapBuffers - wglCreateContext - wglMakeCurrent These functions are needed by the OpenGL tutorial for Windows desktop Bug: angleproject:3620 Change-Id: I699af63eca4a2c8aaf2c72278a580322410ac499 Reviewed-on: https://chromium-review.googlesource.com/c/angle/angle/+/1688499 Commit-Queue: Clemen Deng <clemendeng@google.com> Reviewed-by: 's avatarGeoff Lang <geofflang@chromium.org>
parent 97123e3f
...@@ -387,6 +387,18 @@ Display *Display::GetDisplayFromNativeDisplay(EGLNativeDisplayType nativeDisplay ...@@ -387,6 +387,18 @@ Display *Display::GetDisplayFromNativeDisplay(EGLNativeDisplayType nativeDisplay
} }
// static // static
Display *Display::GetExistingDisplayFromNativeDisplay(EGLNativeDisplayType nativeDisplay)
{
ANGLEPlatformDisplayMap *displays = GetANGLEPlatformDisplayMap();
const auto &iter = displays->find(nativeDisplay);
// Check that there is a matching display
ASSERT(iter != displays->end());
return iter->second;
}
// static
Display *Display::GetDisplayFromDevice(Device *device, const AttributeMap &attribMap) Display *Display::GetDisplayFromDevice(Device *device, const AttributeMap &attribMap)
{ {
Display *display = nullptr; Display *display = nullptr;
...@@ -447,6 +459,7 @@ Display::Display(EGLenum platform, EGLNativeDisplayType displayId, Device *eglDe ...@@ -447,6 +459,7 @@ Display::Display(EGLenum platform, EGLNativeDisplayType displayId, Device *eglDe
mDisplayExtensionString(), mDisplayExtensionString(),
mVendorString(), mVendorString(),
mDevice(eglDevice), mDevice(eglDevice),
mSurface(nullptr),
mPlatform(platform), mPlatform(platform),
mTextureManager(nullptr), mTextureManager(nullptr),
mBlobCache(gl::kDefaultMaxProgramCacheMemoryBytes), mBlobCache(gl::kDefaultMaxProgramCacheMemoryBytes),
...@@ -739,6 +752,8 @@ Error Display::createWindowSurface(const Config *configuration, ...@@ -739,6 +752,8 @@ Error Display::createWindowSurface(const Config *configuration,
ASSERT(windowSurfaces && windowSurfaces->find(window) == windowSurfaces->end()); ASSERT(windowSurfaces && windowSurfaces->find(window) == windowSurfaces->end());
windowSurfaces->insert(std::make_pair(window, *outSurface)); windowSurfaces->insert(std::make_pair(window, *outSurface));
mSurface = *outSurface;
return NoError(); return NoError();
} }
...@@ -1397,6 +1412,11 @@ Device *Display::getDevice() const ...@@ -1397,6 +1412,11 @@ Device *Display::getDevice() const
return mDevice; return mDevice;
} }
Surface *Display::getWGLSurface() const
{
return mSurface;
}
gl::Version Display::getMaxSupportedESVersion() const gl::Version Display::getMaxSupportedESVersion() const
{ {
return mImplementation->getMaxSupportedESVersion(); return mImplementation->getMaxSupportedESVersion();
......
...@@ -81,6 +81,7 @@ class Display final : public LabeledObject, angle::NonCopyable ...@@ -81,6 +81,7 @@ class Display final : public LabeledObject, angle::NonCopyable
static Display *GetDisplayFromDevice(Device *device, const AttributeMap &attribMap); static Display *GetDisplayFromDevice(Device *device, const AttributeMap &attribMap);
static Display *GetDisplayFromNativeDisplay(EGLNativeDisplayType nativeDisplay, static Display *GetDisplayFromNativeDisplay(EGLNativeDisplayType nativeDisplay,
const AttributeMap &attribMap); const AttributeMap &attribMap);
static Display *GetExistingDisplayFromNativeDisplay(EGLNativeDisplayType nativeDisplay);
static const ClientExtensions &GetClientExtensions(); static const ClientExtensions &GetClientExtensions();
static const std::string &GetClientExtensionString(); static const std::string &GetClientExtensionString();
...@@ -193,6 +194,7 @@ class Display final : public LabeledObject, angle::NonCopyable ...@@ -193,6 +194,7 @@ class Display final : public LabeledObject, angle::NonCopyable
rx::DisplayImpl *getImplementation() const { return mImplementation; } rx::DisplayImpl *getImplementation() const { return mImplementation; }
Device *getDevice() const; Device *getDevice() const;
Surface *getWGLSurface() const;
EGLenum getPlatform() const { return mPlatform; } EGLenum getPlatform() const { return mPlatform; }
gl::Version getMaxSupportedESVersion() const; gl::Version getMaxSupportedESVersion() const;
...@@ -254,6 +256,7 @@ class Display final : public LabeledObject, angle::NonCopyable ...@@ -254,6 +256,7 @@ class Display final : public LabeledObject, angle::NonCopyable
std::string mVendorString; std::string mVendorString;
Device *mDevice; Device *mDevice;
Surface *mSurface;
EGLenum mPlatform; EGLenum mPlatform;
angle::LoggingAnnotator mAnnotator; angle::LoggingAnnotator mAnnotator;
......
...@@ -103,7 +103,11 @@ BOOL GL_APIENTRY wglSetPixelFormat(HDC hdc, int ipfd, const PIXELFORMATDESCRIPTO ...@@ -103,7 +103,11 @@ BOOL GL_APIENTRY wglSetPixelFormat(HDC hdc, int ipfd, const PIXELFORMATDESCRIPTO
BOOL GL_APIENTRY wglSwapBuffers(HDC hdc) BOOL GL_APIENTRY wglSwapBuffers(HDC hdc)
{ {
UNIMPLEMENTED(); Thread *thread = egl::GetCurrentThread();
egl::Display *display = egl::Display::GetExistingDisplayFromNativeDisplay(hdc);
ANGLE_EGL_TRY_RETURN(thread, display->getWGLSurface()->swap(thread->getContext()),
"wglSwapBuffers", display->getWGLSurface(), FALSE);
return TRUE; return TRUE;
} }
...@@ -117,76 +121,59 @@ HGLRC GL_APIENTRY wglCreateContext(HDC hDc) ...@@ -117,76 +121,59 @@ HGLRC GL_APIENTRY wglCreateContext(HDC hDc)
{ {
Thread *thread = egl::GetCurrentThread(); Thread *thread = egl::GetCurrentThread();
GLenum platformType = EGL_PLATFORM_ANGLE_TYPE_DEFAULT_ANGLE; std::vector<EGLAttrib> displayAttributes;
std::vector<EGLint> displayAttributes;
displayAttributes.push_back(EGL_PLATFORM_ANGLE_TYPE_ANGLE); displayAttributes.push_back(EGL_PLATFORM_ANGLE_TYPE_ANGLE);
GLenum platformType = EGL_PLATFORM_ANGLE_TYPE_DEFAULT_ANGLE;
displayAttributes.push_back(platformType); displayAttributes.push_back(platformType);
displayAttributes.push_back(EGL_PLATFORM_ANGLE_MAX_VERSION_MAJOR_ANGLE);
displayAttributes.push_back(EGL_DONT_CARE);
displayAttributes.push_back(EGL_PLATFORM_ANGLE_MAX_VERSION_MINOR_ANGLE);
displayAttributes.push_back(EGL_DONT_CARE);
displayAttributes.push_back(EGL_PLATFORM_ANGLE_DEVICE_TYPE_ANGLE);
displayAttributes.push_back(EGL_PLATFORM_ANGLE_DEVICE_TYPE_HARDWARE_ANGLE);
displayAttributes.push_back(EGL_NONE); displayAttributes.push_back(EGL_NONE);
const auto &attribMapDisplay = const auto &attribMapDisplay = AttributeMap::CreateFromAttribArray(displayAttributes.data());
AttributeMap::CreateFromAttribArray((const EGLAttrib *)&displayAttributes[0]);
EGLDisplay mDisplay = egl::Display::GetDisplayFromNativeDisplay(hDc, attribMapDisplay); egl::Display *display = egl::Display::GetDisplayFromNativeDisplay(hDc, attribMapDisplay);
egl::Display *display = static_cast<egl::Display *>(mDisplay); ANGLE_EGL_TRY_RETURN(thread, display->initialize(), "wglCreateContext", display, nullptr);
auto error = display->initialize();
// Don't have a thread to bind API to, so just use this API thread->setAPI(EGL_OPENGL_API);
// eglBindAPI(EGL_OPENGL_ES_API);
// Default config // Default config
const EGLint configAttributes[] = {EGL_RED_SIZE, const EGLint configAttributes[] = {EGL_NONE};
EGL_DONT_CARE,
EGL_GREEN_SIZE,
EGL_DONT_CARE,
EGL_BLUE_SIZE,
EGL_DONT_CARE,
EGL_ALPHA_SIZE,
EGL_DONT_CARE,
EGL_DEPTH_SIZE,
EGL_DONT_CARE,
EGL_STENCIL_SIZE,
EGL_DONT_CARE,
EGL_SAMPLE_BUFFERS,
0,
EGL_NONE};
// Choose config // Choose config
EGLint configCount; EGLint configCount;
EGLConfig mConfig; EGLConfig config;
AttributeMap attribMapConfig = AttributeMap::CreateFromIntArray(configAttributes); AttributeMap attribMapConfig = AttributeMap::CreateFromIntArray(configAttributes);
ClipConfigs(display->chooseConfig(attribMapConfig), &mConfig, 1, &configCount); ClipConfigs(display->chooseConfig(attribMapConfig), &config, 1, &configCount);
Config *configuration = static_cast<Config *>(config);
// Initialize surface // Initialize surface
std::vector<EGLint> surfaceAttributes; std::vector<EGLint> surfaceAttributes;
surfaceAttributes.push_back(EGL_NONE); surfaceAttributes.push_back(EGL_NONE);
surfaceAttributes.push_back(EGL_NONE); surfaceAttributes.push_back(EGL_NONE);
AttributeMap surfAttributes = AttributeMap::CreateFromIntArray(&surfaceAttributes[0]);
// Create first window surface // Create first window surface
// EGLSurface mWindowSurface = eglCreateWindowSurface(mDisplay, mConfig, egl::Surface *surface = nullptr;
// (EGLNativeWindowType)hDc, &surfaceAttributes[0]); ANGLE_EGL_TRY_RETURN(
thread,
display->createWindowSurface(configuration, WindowFromDC(hDc), surfAttributes, &surface),
"wglCreateContext", display, nullptr);
// Initialize context // Initialize context
EGLint contextAttibutes[] = {EGL_CONTEXT_CLIENT_VERSION, 2, EGL_NONE}; EGLint contextAttibutes[] = {EGL_CONTEXT_CLIENT_VERSION, 3, EGL_CONTEXT_MINOR_VERSION, 3,
EGL_NONE};
Config *configuration = static_cast<Config *>(mConfig);
gl::Context *sharedGLContext = static_cast<gl::Context *>(nullptr); gl::Context *sharedGLContext = static_cast<gl::Context *>(nullptr);
AttributeMap attributes = AttributeMap::CreateFromIntArray(contextAttibutes); AttributeMap ctxAttributes = AttributeMap::CreateFromIntArray(contextAttibutes);
gl::Context *context = nullptr; gl::Context *context = nullptr;
auto error1 = display->createContext(configuration, sharedGLContext, thread->getAPI(),
attributes, &context);
EGLContext mContext = static_cast<EGLContext>(context); ANGLE_EGL_TRY_RETURN(thread,
display->createContext(configuration, sharedGLContext, EGL_OPENGL_API,
ctxAttributes, &context),
"wglCreateContext", display, nullptr);
return (HGLRC)mContext; return reinterpret_cast<HGLRC>(context);
} }
HGLRC GL_APIENTRY wglCreateLayerContext(HDC hDc, int level) HGLRC GL_APIENTRY wglCreateLayerContext(HDC hDc, int level)
...@@ -251,8 +238,19 @@ PROC GL_APIENTRY wglGetProcAddress(LPCSTR lpszProc) ...@@ -251,8 +238,19 @@ PROC GL_APIENTRY wglGetProcAddress(LPCSTR lpszProc)
BOOL GL_APIENTRY wglMakeCurrent(HDC hDc, HGLRC newContext) BOOL GL_APIENTRY wglMakeCurrent(HDC hDc, HGLRC newContext)
{ {
UNIMPLEMENTED(); Thread *thread = egl::GetCurrentThread();
return FALSE;
egl::Display *display = egl::Display::GetExistingDisplayFromNativeDisplay(hDc);
gl::Context *context = reinterpret_cast<gl::Context *>(newContext);
ANGLE_EGL_TRY_RETURN(
thread,
display->makeCurrent(thread, display->getWGLSurface(), display->getWGLSurface(), context),
"wglMakeCurrent", display, FALSE);
SetContextCurrent(thread, context);
return TRUE;
} }
BOOL GL_APIENTRY wglRealizeLayerPalette(HDC hdc, int iLayerPlane, BOOL bRealize) BOOL GL_APIENTRY wglRealizeLayerPalette(HDC hdc, int iLayerPlane, BOOL bRealize)
......
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