2 // Copyright (c) 2013 The ANGLE Project Authors. All rights reserved.
3 // Use of this source code is governed by a BSD-style license that can be
4 // found in the LICENSE file.
13 #include "win32/Win32Timer.h"
14 #include "win32/Win32Window.h"
16 #error unsupported OS.
19 EGLWindow::EGLWindow(size_t width, size_t height,
20 EGLint glesMajorVersion, EGLint requestedRenderer)
21 : mSurface(EGL_NO_SURFACE),
22 mContext(EGL_NO_CONTEXT),
23 mDisplay(EGL_NO_DISPLAY),
24 mClientVersion(glesMajorVersion),
25 mRequestedRenderer(requestedRenderer),
39 EGLWindow::~EGLWindow()
44 void EGLWindow::swap()
46 eglSwapBuffers(mDisplay, mSurface);
49 EGLConfig EGLWindow::getConfig() const
54 EGLDisplay EGLWindow::getDisplay() const
59 EGLSurface EGLWindow::getSurface() const
64 EGLContext EGLWindow::getContext() const
69 bool EGLWindow::initializeGL(OSWindow *osWindow)
71 PFNEGLGETPLATFORMDISPLAYEXTPROC eglGetPlatformDisplayEXT = reinterpret_cast<PFNEGLGETPLATFORMDISPLAYEXTPROC>(eglGetProcAddress("eglGetPlatformDisplayEXT"));
72 if (!eglGetPlatformDisplayEXT)
77 const EGLint displayAttributes[] =
79 EGL_PLATFORM_ANGLE_TYPE_ANGLE, mRequestedRenderer,
83 mDisplay = eglGetPlatformDisplayEXT(EGL_PLATFORM_ANGLE_ANGLE, osWindow->getNativeDisplay(), displayAttributes);
84 if (mDisplay == EGL_NO_DISPLAY)
90 EGLint majorVersion, minorVersion;
91 if (!eglInitialize(mDisplay, &majorVersion, &minorVersion))
97 eglBindAPI(EGL_OPENGL_ES_API);
98 if (eglGetError() != EGL_SUCCESS)
104 const EGLint configAttributes[] =
106 EGL_RED_SIZE, (mRedBits >= 0) ? mRedBits : EGL_DONT_CARE,
107 EGL_GREEN_SIZE, (mGreenBits >= 0) ? mGreenBits : EGL_DONT_CARE,
108 EGL_BLUE_SIZE, (mBlueBits >= 0) ? mBlueBits : EGL_DONT_CARE,
109 EGL_ALPHA_SIZE, (mAlphaBits >= 0) ? mAlphaBits : EGL_DONT_CARE,
110 EGL_DEPTH_SIZE, (mDepthBits >= 0) ? mDepthBits : EGL_DONT_CARE,
111 EGL_STENCIL_SIZE, (mStencilBits >= 0) ? mStencilBits : EGL_DONT_CARE,
112 EGL_SAMPLE_BUFFERS, mMultisample ? 1 : 0,
117 if (!eglChooseConfig(mDisplay, configAttributes, &mConfig, 1, &configCount) || (configCount != 1))
123 eglGetConfigAttrib(mDisplay, mConfig, EGL_RED_SIZE, &mRedBits);
124 eglGetConfigAttrib(mDisplay, mConfig, EGL_GREEN_SIZE, &mGreenBits);
125 eglGetConfigAttrib(mDisplay, mConfig, EGL_BLUE_SIZE, &mBlueBits);
126 eglGetConfigAttrib(mDisplay, mConfig, EGL_ALPHA_SIZE, &mBlueBits);
127 eglGetConfigAttrib(mDisplay, mConfig, EGL_DEPTH_SIZE, &mDepthBits);
128 eglGetConfigAttrib(mDisplay, mConfig, EGL_STENCIL_SIZE, &mStencilBits);
130 const EGLint surfaceAttributes[] =
132 EGL_POST_SUB_BUFFER_SUPPORTED_NV, EGL_TRUE,
136 mSurface = eglCreateWindowSurface(mDisplay, mConfig, osWindow->getNativeWindow(), surfaceAttributes);
137 if (mSurface == EGL_NO_SURFACE)
139 eglGetError(); // Clear error and try again
140 mSurface = eglCreateWindowSurface(mDisplay, mConfig, NULL, NULL);
143 if (eglGetError() != EGL_SUCCESS)
149 EGLint contextAttibutes[] =
151 EGL_CONTEXT_CLIENT_VERSION, mClientVersion,
155 mContext = eglCreateContext(mDisplay, mConfig, NULL, contextAttibutes);
156 if (eglGetError() != EGL_SUCCESS)
162 eglMakeCurrent(mDisplay, mSurface, mSurface, mContext);
163 if (eglGetError() != EGL_SUCCESS)
169 if (mSwapInterval != -1)
171 eglSwapInterval(mDisplay, mSwapInterval);
177 void EGLWindow::destroyGL()
179 if (mSurface != EGL_NO_SURFACE)
181 assert(mDisplay != EGL_NO_DISPLAY);
182 eglDestroySurface(mDisplay, mSurface);
183 mSurface = EGL_NO_SURFACE;
186 if (mContext != EGL_NO_CONTEXT)
188 assert(mDisplay != EGL_NO_DISPLAY);
189 eglDestroyContext(mDisplay, mContext);
190 mContext = EGL_NO_CONTEXT;
193 if (mDisplay != EGL_NO_DISPLAY)
195 eglMakeCurrent(mDisplay, EGL_NO_SURFACE, EGL_NO_SURFACE, EGL_NO_CONTEXT);
196 eglTerminate(mDisplay);
197 mDisplay = EGL_NO_DISPLAY;