daniel@transgaming.com | 4f39fd9 | 2010-03-08 20:26:45 +0000 | [diff] [blame] | 1 | // |
| 2 | // Copyright (c) 2002-2010 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. |
| 5 | // |
| 6 | |
| 7 | // Display.cpp: Implements the egl::Display class, representing the abstract |
| 8 | // display on which graphics are drawn. Implements EGLDisplay. |
| 9 | // [EGL 1.4] section 2.1.2 page 3. |
| 10 | |
daniel@transgaming.com | bbf56f7 | 2010-04-20 18:52:13 +0000 | [diff] [blame] | 11 | #include "libEGL/Display.h" |
daniel@transgaming.com | 4f39fd9 | 2010-03-08 20:26:45 +0000 | [diff] [blame] | 12 | |
daniel@transgaming.com | 1697302 | 2010-03-11 19:22:19 +0000 | [diff] [blame] | 13 | #include <algorithm> |
| 14 | #include <vector> |
| 15 | |
alokp@chromium.org | ea0e1af | 2010-03-22 19:33:14 +0000 | [diff] [blame] | 16 | #include "common/debug.h" |
daniel@transgaming.com | 4f39fd9 | 2010-03-08 20:26:45 +0000 | [diff] [blame] | 17 | |
daniel@transgaming.com | bbf56f7 | 2010-04-20 18:52:13 +0000 | [diff] [blame] | 18 | #include "libEGL/main.h" |
| 19 | |
daniel@transgaming.com | 741a588 | 2010-05-20 19:17:29 +0000 | [diff] [blame] | 20 | #define REF_RAST 0 // Can also be enabled by defining FORCE_REF_RAST in the project's predefined macros |
| 21 | |
daniel@transgaming.com | 4f39fd9 | 2010-03-08 20:26:45 +0000 | [diff] [blame] | 22 | namespace egl |
| 23 | { |
| 24 | Display::Display(HDC deviceContext) : mDc(deviceContext) |
| 25 | { |
| 26 | mD3d9 = NULL; |
| 27 | mDevice = NULL; |
daniel@transgaming.com | da6e263 | 2010-07-28 19:21:18 +0000 | [diff] [blame^] | 28 | mDeviceWindow = NULL; |
daniel@transgaming.com | 4f39fd9 | 2010-03-08 20:26:45 +0000 | [diff] [blame] | 29 | |
| 30 | mAdapter = D3DADAPTER_DEFAULT; |
daniel@transgaming.com | 741a588 | 2010-05-20 19:17:29 +0000 | [diff] [blame] | 31 | |
daniel@transgaming.com | 8b9f4cc | 2010-05-20 19:17:35 +0000 | [diff] [blame] | 32 | #if REF_RAST == 1 || defined(FORCE_REF_RAST) |
daniel@transgaming.com | 741a588 | 2010-05-20 19:17:29 +0000 | [diff] [blame] | 33 | mDeviceType = D3DDEVTYPE_REF; |
| 34 | #else |
| 35 | mDeviceType = D3DDEVTYPE_HAL; |
| 36 | #endif |
daniel@transgaming.com | 616ffcf | 2010-05-07 19:01:49 +0000 | [diff] [blame] | 37 | |
| 38 | mMinSwapInterval = 1; |
| 39 | mMaxSwapInterval = 1; |
| 40 | setSwapInterval(1); |
daniel@transgaming.com | 4f39fd9 | 2010-03-08 20:26:45 +0000 | [diff] [blame] | 41 | } |
| 42 | |
| 43 | Display::~Display() |
| 44 | { |
| 45 | terminate(); |
| 46 | } |
| 47 | |
| 48 | bool Display::initialize() |
| 49 | { |
| 50 | if (isInitialized()) |
| 51 | { |
| 52 | return true; |
| 53 | } |
| 54 | |
| 55 | mD3d9 = Direct3DCreate9(D3D_SDK_VERSION); |
| 56 | |
| 57 | if (mD3d9) |
| 58 | { |
| 59 | if (mDc != NULL) |
| 60 | { |
daniel@transgaming.com | 02bc159 | 2010-03-30 03:36:13 +0000 | [diff] [blame] | 61 | // UNIMPLEMENTED(); // FIXME: Determine which adapter index the device context corresponds to |
daniel@transgaming.com | 4f39fd9 | 2010-03-08 20:26:45 +0000 | [diff] [blame] | 62 | } |
| 63 | |
daniel@transgaming.com | 353569a | 2010-06-24 13:02:12 +0000 | [diff] [blame] | 64 | HRESULT result = mD3d9->GetDeviceCaps(mAdapter, mDeviceType, &mDeviceCaps); |
daniel@transgaming.com | 4f39fd9 | 2010-03-08 20:26:45 +0000 | [diff] [blame] | 65 | |
| 66 | if (result == D3DERR_OUTOFVIDEOMEMORY || result == E_OUTOFMEMORY) |
| 67 | { |
| 68 | return error(EGL_BAD_ALLOC, false); |
| 69 | } |
| 70 | |
daniel@transgaming.com | 353569a | 2010-06-24 13:02:12 +0000 | [diff] [blame] | 71 | if (mDeviceCaps.PixelShaderVersion < D3DPS_VERSION(2, 0)) |
daniel@transgaming.com | 4f39fd9 | 2010-03-08 20:26:45 +0000 | [diff] [blame] | 72 | { |
| 73 | mD3d9->Release(); |
| 74 | mD3d9 = NULL; |
| 75 | } |
| 76 | else |
| 77 | { |
daniel@transgaming.com | 616ffcf | 2010-05-07 19:01:49 +0000 | [diff] [blame] | 78 | mMinSwapInterval = 4; |
| 79 | mMaxSwapInterval = 0; |
daniel@transgaming.com | 4f39fd9 | 2010-03-08 20:26:45 +0000 | [diff] [blame] | 80 | |
daniel@transgaming.com | 353569a | 2010-06-24 13:02:12 +0000 | [diff] [blame] | 81 | if (mDeviceCaps.PresentationIntervals & D3DPRESENT_INTERVAL_IMMEDIATE) {mMinSwapInterval = std::min(mMinSwapInterval, 0); mMaxSwapInterval = std::max(mMaxSwapInterval, 0);} |
| 82 | if (mDeviceCaps.PresentationIntervals & D3DPRESENT_INTERVAL_ONE) {mMinSwapInterval = std::min(mMinSwapInterval, 1); mMaxSwapInterval = std::max(mMaxSwapInterval, 1);} |
| 83 | if (mDeviceCaps.PresentationIntervals & D3DPRESENT_INTERVAL_TWO) {mMinSwapInterval = std::min(mMinSwapInterval, 2); mMaxSwapInterval = std::max(mMaxSwapInterval, 2);} |
| 84 | if (mDeviceCaps.PresentationIntervals & D3DPRESENT_INTERVAL_THREE) {mMinSwapInterval = std::min(mMinSwapInterval, 3); mMaxSwapInterval = std::max(mMaxSwapInterval, 3);} |
| 85 | if (mDeviceCaps.PresentationIntervals & D3DPRESENT_INTERVAL_FOUR) {mMinSwapInterval = std::min(mMinSwapInterval, 4); mMaxSwapInterval = std::max(mMaxSwapInterval, 4);} |
daniel@transgaming.com | 4f39fd9 | 2010-03-08 20:26:45 +0000 | [diff] [blame] | 86 | |
daniel@transgaming.com | adf0284 | 2010-05-07 13:03:33 +0000 | [diff] [blame] | 87 | const D3DFORMAT renderTargetFormats[] = |
daniel@transgaming.com | 4f39fd9 | 2010-03-08 20:26:45 +0000 | [diff] [blame] | 88 | { |
| 89 | D3DFMT_A1R5G5B5, |
daniel@transgaming.com | adf0284 | 2010-05-07 13:03:33 +0000 | [diff] [blame] | 90 | // D3DFMT_A2R10G10B10, // The color_ramp conformance test uses ReadPixels with UNSIGNED_BYTE causing it to think that rendering skipped a colour value. |
daniel@transgaming.com | 4f39fd9 | 2010-03-08 20:26:45 +0000 | [diff] [blame] | 91 | D3DFMT_A8R8G8B8, |
| 92 | D3DFMT_R5G6B5, |
| 93 | D3DFMT_X1R5G5B5, |
| 94 | D3DFMT_X8R8G8B8 |
| 95 | }; |
| 96 | |
| 97 | const D3DFORMAT depthStencilFormats[] = |
| 98 | { |
daniel@transgaming.com | 02bc159 | 2010-03-30 03:36:13 +0000 | [diff] [blame] | 99 | // D3DFMT_D16_LOCKABLE, |
daniel@transgaming.com | 4f39fd9 | 2010-03-08 20:26:45 +0000 | [diff] [blame] | 100 | D3DFMT_D32, |
daniel@transgaming.com | d1f6fde | 2010-05-07 19:01:43 +0000 | [diff] [blame] | 101 | // D3DFMT_D15S1, |
daniel@transgaming.com | 4f39fd9 | 2010-03-08 20:26:45 +0000 | [diff] [blame] | 102 | D3DFMT_D24S8, |
| 103 | D3DFMT_D24X8, |
daniel@transgaming.com | d1f6fde | 2010-05-07 19:01:43 +0000 | [diff] [blame] | 104 | // D3DFMT_D24X4S4, |
daniel@transgaming.com | 4f39fd9 | 2010-03-08 20:26:45 +0000 | [diff] [blame] | 105 | D3DFMT_D16, |
daniel@transgaming.com | 02bc159 | 2010-03-30 03:36:13 +0000 | [diff] [blame] | 106 | // D3DFMT_D32F_LOCKABLE, |
| 107 | // D3DFMT_D24FS8 |
daniel@transgaming.com | 4f39fd9 | 2010-03-08 20:26:45 +0000 | [diff] [blame] | 108 | }; |
| 109 | |
| 110 | D3DDISPLAYMODE currentDisplayMode; |
| 111 | mD3d9->GetAdapterDisplayMode(mAdapter, ¤tDisplayMode); |
| 112 | |
daniel@transgaming.com | 178adff | 2010-05-18 18:52:04 +0000 | [diff] [blame] | 113 | ConfigSet configSet; |
| 114 | |
daniel@transgaming.com | adf0284 | 2010-05-07 13:03:33 +0000 | [diff] [blame] | 115 | for (int formatIndex = 0; formatIndex < sizeof(renderTargetFormats) / sizeof(D3DFORMAT); formatIndex++) |
daniel@transgaming.com | 4f39fd9 | 2010-03-08 20:26:45 +0000 | [diff] [blame] | 116 | { |
daniel@transgaming.com | adf0284 | 2010-05-07 13:03:33 +0000 | [diff] [blame] | 117 | D3DFORMAT renderTargetFormat = renderTargetFormats[formatIndex]; |
daniel@transgaming.com | 4f39fd9 | 2010-03-08 20:26:45 +0000 | [diff] [blame] | 118 | |
| 119 | HRESULT result = mD3d9->CheckDeviceFormat(mAdapter, mDeviceType, currentDisplayMode.Format, D3DUSAGE_RENDERTARGET, D3DRTYPE_SURFACE, renderTargetFormat); |
| 120 | |
| 121 | if (SUCCEEDED(result)) |
| 122 | { |
| 123 | for (int depthStencilIndex = 0; depthStencilIndex < sizeof(depthStencilFormats) / sizeof(D3DFORMAT); depthStencilIndex++) |
| 124 | { |
| 125 | D3DFORMAT depthStencilFormat = depthStencilFormats[depthStencilIndex]; |
| 126 | HRESULT result = mD3d9->CheckDeviceFormat(mAdapter, mDeviceType, currentDisplayMode.Format, D3DUSAGE_DEPTHSTENCIL, D3DRTYPE_SURFACE, depthStencilFormat); |
| 127 | |
| 128 | if (SUCCEEDED(result)) |
| 129 | { |
daniel@transgaming.com | adf0284 | 2010-05-07 13:03:33 +0000 | [diff] [blame] | 130 | HRESULT result = mD3d9->CheckDepthStencilMatch(mAdapter, mDeviceType, currentDisplayMode.Format, renderTargetFormat, depthStencilFormat); |
daniel@transgaming.com | fab5a1a | 2010-03-11 19:22:30 +0000 | [diff] [blame] | 131 | |
daniel@transgaming.com | 4f39fd9 | 2010-03-08 20:26:45 +0000 | [diff] [blame] | 132 | if (SUCCEEDED(result)) |
| 133 | { |
| 134 | // FIXME: Enumerate multi-sampling |
| 135 | |
daniel@transgaming.com | 178adff | 2010-05-18 18:52:04 +0000 | [diff] [blame] | 136 | configSet.add(currentDisplayMode, mMinSwapInterval, mMaxSwapInterval, renderTargetFormat, depthStencilFormat, 0); |
daniel@transgaming.com | 4f39fd9 | 2010-03-08 20:26:45 +0000 | [diff] [blame] | 137 | } |
| 138 | } |
| 139 | } |
| 140 | } |
| 141 | } |
daniel@transgaming.com | 4f39fd9 | 2010-03-08 20:26:45 +0000 | [diff] [blame] | 142 | |
daniel@transgaming.com | 178adff | 2010-05-18 18:52:04 +0000 | [diff] [blame] | 143 | // Give the sorted configs a unique ID and store them internally |
| 144 | EGLint index = 1; |
| 145 | for (ConfigSet::Iterator config = configSet.mSet.begin(); config != configSet.mSet.end(); config++) |
| 146 | { |
| 147 | Config configuration = *config; |
| 148 | configuration.mConfigID = index; |
| 149 | index++; |
| 150 | |
| 151 | mConfigSet.mSet.insert(configuration); |
| 152 | } |
| 153 | } |
daniel@transgaming.com | da6e263 | 2010-07-28 19:21:18 +0000 | [diff] [blame^] | 154 | |
| 155 | if (!createDevice()) |
| 156 | { |
| 157 | terminate(); |
| 158 | |
| 159 | return false; |
| 160 | } |
daniel@transgaming.com | 4f39fd9 | 2010-03-08 20:26:45 +0000 | [diff] [blame] | 161 | } |
| 162 | |
| 163 | if (!isInitialized()) |
| 164 | { |
| 165 | terminate(); |
| 166 | |
| 167 | return false; |
| 168 | } |
| 169 | |
| 170 | return true; |
| 171 | } |
| 172 | |
| 173 | void Display::terminate() |
| 174 | { |
| 175 | for (SurfaceSet::iterator surface = mSurfaceSet.begin(); surface != mSurfaceSet.end(); surface++) |
| 176 | { |
| 177 | delete *surface; |
| 178 | } |
| 179 | |
| 180 | for (ContextSet::iterator context = mContextSet.begin(); context != mContextSet.end(); context++) |
| 181 | { |
| 182 | glDestroyContext(*context); |
| 183 | } |
| 184 | |
| 185 | if (mDevice) |
| 186 | { |
| 187 | mDevice->Release(); |
| 188 | mDevice = NULL; |
| 189 | } |
| 190 | |
| 191 | if (mD3d9) |
| 192 | { |
| 193 | mD3d9->Release(); |
| 194 | mD3d9 = NULL; |
| 195 | } |
daniel@transgaming.com | da6e263 | 2010-07-28 19:21:18 +0000 | [diff] [blame^] | 196 | |
| 197 | if (mDeviceWindow) |
| 198 | { |
| 199 | DestroyWindow(mDeviceWindow); |
| 200 | mDeviceWindow = NULL; |
| 201 | } |
daniel@transgaming.com | 4f39fd9 | 2010-03-08 20:26:45 +0000 | [diff] [blame] | 202 | } |
| 203 | |
daniel@transgaming.com | ae072af | 2010-05-05 18:47:28 +0000 | [diff] [blame] | 204 | void Display::startScene() |
| 205 | { |
| 206 | if (!mSceneStarted) |
| 207 | { |
| 208 | long result = mDevice->BeginScene(); |
| 209 | ASSERT(SUCCEEDED(result)); |
| 210 | mSceneStarted = true; |
| 211 | } |
| 212 | } |
| 213 | |
| 214 | void Display::endScene() |
| 215 | { |
| 216 | if (mSceneStarted) |
| 217 | { |
| 218 | long result = mDevice->EndScene(); |
| 219 | ASSERT(SUCCEEDED(result)); |
| 220 | mSceneStarted = false; |
| 221 | } |
| 222 | } |
| 223 | |
daniel@transgaming.com | 4f39fd9 | 2010-03-08 20:26:45 +0000 | [diff] [blame] | 224 | bool Display::getConfigs(EGLConfig *configs, const EGLint *attribList, EGLint configSize, EGLint *numConfig) |
| 225 | { |
| 226 | return mConfigSet.getConfigs(configs, attribList, configSize, numConfig); |
| 227 | } |
| 228 | |
| 229 | bool Display::getConfigAttrib(EGLConfig config, EGLint attribute, EGLint *value) |
| 230 | { |
| 231 | const egl::Config *configuration = mConfigSet.get(config); |
| 232 | |
| 233 | switch (attribute) |
| 234 | { |
| 235 | case EGL_BUFFER_SIZE: *value = configuration->mBufferSize; break; |
| 236 | case EGL_ALPHA_SIZE: *value = configuration->mAlphaSize; break; |
| 237 | case EGL_BLUE_SIZE: *value = configuration->mBlueSize; break; |
| 238 | case EGL_GREEN_SIZE: *value = configuration->mGreenSize; break; |
| 239 | case EGL_RED_SIZE: *value = configuration->mRedSize; break; |
| 240 | case EGL_DEPTH_SIZE: *value = configuration->mDepthSize; break; |
| 241 | case EGL_STENCIL_SIZE: *value = configuration->mStencilSize; break; |
| 242 | case EGL_CONFIG_CAVEAT: *value = configuration->mConfigCaveat; break; |
| 243 | case EGL_CONFIG_ID: *value = configuration->mConfigID; break; |
| 244 | case EGL_LEVEL: *value = configuration->mLevel; break; |
| 245 | case EGL_NATIVE_RENDERABLE: *value = configuration->mNativeRenderable; break; |
| 246 | case EGL_NATIVE_VISUAL_TYPE: *value = configuration->mNativeVisualType; break; |
| 247 | case EGL_SAMPLES: *value = configuration->mSamples; break; |
| 248 | case EGL_SAMPLE_BUFFERS: *value = configuration->mSampleBuffers; break; |
| 249 | case EGL_SURFACE_TYPE: *value = configuration->mSurfaceType; break; |
| 250 | case EGL_TRANSPARENT_TYPE: *value = configuration->mTransparentType; break; |
| 251 | case EGL_TRANSPARENT_BLUE_VALUE: *value = configuration->mTransparentBlueValue; break; |
| 252 | case EGL_TRANSPARENT_GREEN_VALUE: *value = configuration->mTransparentGreenValue; break; |
| 253 | case EGL_TRANSPARENT_RED_VALUE: *value = configuration->mTransparentRedValue; break; |
| 254 | case EGL_BIND_TO_TEXTURE_RGB: *value = configuration->mBindToTextureRGB; break; |
| 255 | case EGL_BIND_TO_TEXTURE_RGBA: *value = configuration->mBindToTextureRGBA; break; |
| 256 | case EGL_MIN_SWAP_INTERVAL: *value = configuration->mMinSwapInterval; break; |
| 257 | case EGL_MAX_SWAP_INTERVAL: *value = configuration->mMaxSwapInterval; break; |
| 258 | case EGL_LUMINANCE_SIZE: *value = configuration->mLuminanceSize; break; |
| 259 | case EGL_ALPHA_MASK_SIZE: *value = configuration->mAlphaMaskSize; break; |
| 260 | case EGL_COLOR_BUFFER_TYPE: *value = configuration->mColorBufferType; break; |
| 261 | case EGL_RENDERABLE_TYPE: *value = configuration->mRenderableType; break; |
daniel@transgaming.com | b6bd727 | 2010-05-05 18:48:22 +0000 | [diff] [blame] | 262 | case EGL_MATCH_NATIVE_PIXMAP: *value = false; UNIMPLEMENTED(); break; |
daniel@transgaming.com | 4f39fd9 | 2010-03-08 20:26:45 +0000 | [diff] [blame] | 263 | case EGL_CONFORMANT: *value = configuration->mConformant; break; |
| 264 | default: |
| 265 | return false; |
| 266 | } |
| 267 | |
| 268 | return true; |
| 269 | } |
| 270 | |
daniel@transgaming.com | da6e263 | 2010-07-28 19:21:18 +0000 | [diff] [blame^] | 271 | bool Display::createDevice()
|
| 272 | {
|
| 273 | static const TCHAR windowName[] = TEXT("AngleHiddenWindow");
|
| 274 | static const TCHAR className[] = TEXT("STATIC");
|
| 275 |
|
| 276 | mDeviceWindow = CreateWindowEx(WS_EX_NOACTIVATE, className, windowName, WS_DISABLED | WS_POPUP, 0, 0, 1, 1, HWND_MESSAGE, NULL, GetModuleHandle(NULL), NULL);
|
| 277 |
|
| 278 | D3DPRESENT_PARAMETERS presentParameters = {0};
|
| 279 |
|
| 280 | // The default swap chain is never actually used. Surface will create a new swap chain with the proper parameters.
|
| 281 | presentParameters.AutoDepthStencilFormat = D3DFMT_UNKNOWN;
|
| 282 | presentParameters.BackBufferCount = 1;
|
| 283 | presentParameters.BackBufferFormat = D3DFMT_UNKNOWN;
|
| 284 | presentParameters.BackBufferWidth = 1;
|
| 285 | presentParameters.BackBufferHeight = 1;
|
| 286 | presentParameters.EnableAutoDepthStencil = FALSE;
|
| 287 | presentParameters.Flags = 0;
|
| 288 | presentParameters.hDeviceWindow = mDeviceWindow;
|
| 289 | presentParameters.MultiSampleQuality = 0;
|
| 290 | presentParameters.MultiSampleType = D3DMULTISAMPLE_NONE;
|
| 291 | presentParameters.PresentationInterval = convertInterval(mMinSwapInterval);
|
| 292 | presentParameters.SwapEffect = D3DSWAPEFFECT_DISCARD;
|
| 293 | presentParameters.Windowed = TRUE;
|
| 294 |
|
| 295 | DWORD behaviorFlags = D3DCREATE_FPU_PRESERVE | D3DCREATE_NOWINDOWCHANGES;
|
| 296 |
|
| 297 | HRESULT result = mD3d9->CreateDevice(mAdapter, mDeviceType, mDeviceWindow, behaviorFlags | D3DCREATE_HARDWARE_VERTEXPROCESSING | D3DCREATE_PUREDEVICE, &presentParameters, &mDevice);
|
| 298 |
|
| 299 | if (result == D3DERR_OUTOFVIDEOMEMORY || result == E_OUTOFMEMORY)
|
| 300 | {
|
| 301 | return error(EGL_BAD_ALLOC, false);
|
| 302 | }
|
| 303 |
|
| 304 | if (FAILED(result))
|
| 305 | {
|
| 306 | result = mD3d9->CreateDevice(mAdapter, mDeviceType, mDeviceWindow, behaviorFlags | D3DCREATE_SOFTWARE_VERTEXPROCESSING, &presentParameters, &mDevice);
|
| 307 |
|
| 308 | if (result == D3DERR_OUTOFVIDEOMEMORY || result == E_OUTOFMEMORY)
|
| 309 | {
|
| 310 | return error(EGL_BAD_ALLOC, false);
|
| 311 | }
|
| 312 | }
|
| 313 |
|
| 314 | ASSERT(SUCCEEDED(result));
|
| 315 |
|
| 316 | // Permanent non-default states
|
| 317 | mDevice->SetRenderState(D3DRS_POINTSPRITEENABLE, TRUE);
|
| 318 |
|
| 319 | mSceneStarted = false;
|
| 320 |
|
| 321 | return true;
|
| 322 | } |
| 323 | |
daniel@transgaming.com | b6bd727 | 2010-05-05 18:48:22 +0000 | [diff] [blame] | 324 | Surface *Display::createWindowSurface(HWND window, EGLConfig config) |
daniel@transgaming.com | 4f39fd9 | 2010-03-08 20:26:45 +0000 | [diff] [blame] | 325 | { |
daniel@transgaming.com | b6bd727 | 2010-05-05 18:48:22 +0000 | [diff] [blame] | 326 | const Config *configuration = mConfigSet.get(config); |
daniel@transgaming.com | 4f39fd9 | 2010-03-08 20:26:45 +0000 | [diff] [blame] | 327 | |
daniel@transgaming.com | da6e263 | 2010-07-28 19:21:18 +0000 | [diff] [blame^] | 328 | Surface *surface = new Surface(this, configuration, window); |
| 329 | mSurfaceSet.insert(surface); |
daniel@transgaming.com | fab5a1a | 2010-03-11 19:22:30 +0000 | [diff] [blame] | 330 | |
daniel@transgaming.com | 4f39fd9 | 2010-03-08 20:26:45 +0000 | [diff] [blame] | 331 | return surface; |
| 332 | } |
| 333 | |
daniel@transgaming.com | 0d25b00 | 2010-07-28 19:21:07 +0000 | [diff] [blame] | 334 | EGLContext Display::createContext(EGLConfig configHandle, const gl::Context *shareContext) |
daniel@transgaming.com | 4f39fd9 | 2010-03-08 20:26:45 +0000 | [diff] [blame] | 335 | { |
| 336 | const egl::Config *config = mConfigSet.get(configHandle); |
| 337 | |
daniel@transgaming.com | 0d25b00 | 2010-07-28 19:21:07 +0000 | [diff] [blame] | 338 | gl::Context *context = glCreateContext(config, shareContext); |
daniel@transgaming.com | 4f39fd9 | 2010-03-08 20:26:45 +0000 | [diff] [blame] | 339 | mContextSet.insert(context); |
| 340 | |
| 341 | return context; |
| 342 | } |
| 343 | |
| 344 | void Display::destroySurface(egl::Surface *surface) |
| 345 | { |
| 346 | delete surface; |
| 347 | mSurfaceSet.erase(surface); |
| 348 | } |
| 349 | |
| 350 | void Display::destroyContext(gl::Context *context) |
| 351 | { |
| 352 | glDestroyContext(context); |
| 353 | mContextSet.erase(context); |
| 354 | } |
| 355 | |
| 356 | bool Display::isInitialized() |
| 357 | { |
| 358 | return mD3d9 != NULL && mConfigSet.size() > 0; |
| 359 | } |
| 360 | |
| 361 | bool Display::isValidConfig(EGLConfig config) |
| 362 | { |
| 363 | return mConfigSet.get(config) != NULL; |
| 364 | } |
| 365 | |
| 366 | bool Display::isValidContext(gl::Context *context) |
| 367 | { |
| 368 | return mContextSet.find(context) != mContextSet.end(); |
| 369 | } |
| 370 | |
| 371 | bool Display::isValidSurface(egl::Surface *surface) |
| 372 | { |
| 373 | return mSurfaceSet.find(surface) != mSurfaceSet.end(); |
| 374 | } |
| 375 | |
| 376 | bool Display::hasExistingWindowSurface(HWND window) |
| 377 | { |
| 378 | for (SurfaceSet::iterator surface = mSurfaceSet.begin(); surface != mSurfaceSet.end(); surface++) |
| 379 | { |
| 380 | if ((*surface)->getWindowHandle() == window) |
| 381 | { |
| 382 | return true; |
| 383 | } |
| 384 | } |
| 385 | |
| 386 | return false; |
| 387 | } |
| 388 | |
daniel@transgaming.com | b6bd727 | 2010-05-05 18:48:22 +0000 | [diff] [blame] | 389 | void Display::setSwapInterval(GLint interval) |
| 390 | { |
| 391 | mSwapInterval = interval; |
daniel@transgaming.com | 616ffcf | 2010-05-07 19:01:49 +0000 | [diff] [blame] | 392 | mSwapInterval = std::max(mSwapInterval, mMinSwapInterval); |
| 393 | mSwapInterval = std::min(mSwapInterval, mMaxSwapInterval); |
| 394 | |
| 395 | mPresentInterval = convertInterval(mSwapInterval); |
daniel@transgaming.com | b6bd727 | 2010-05-05 18:48:22 +0000 | [diff] [blame] | 396 | } |
| 397 | |
daniel@transgaming.com | 616ffcf | 2010-05-07 19:01:49 +0000 | [diff] [blame] | 398 | DWORD Display::getPresentInterval() |
daniel@transgaming.com | b6bd727 | 2010-05-05 18:48:22 +0000 | [diff] [blame] | 399 | { |
daniel@transgaming.com | 616ffcf | 2010-05-07 19:01:49 +0000 | [diff] [blame] | 400 | return mPresentInterval; |
| 401 | } |
daniel@transgaming.com | b6bd727 | 2010-05-05 18:48:22 +0000 | [diff] [blame] | 402 | |
daniel@transgaming.com | 616ffcf | 2010-05-07 19:01:49 +0000 | [diff] [blame] | 403 | DWORD Display::convertInterval(GLint interval) |
| 404 | { |
daniel@transgaming.com | b6bd727 | 2010-05-05 18:48:22 +0000 | [diff] [blame] | 405 | switch(interval) |
| 406 | { |
| 407 | case 0: return D3DPRESENT_INTERVAL_IMMEDIATE; |
| 408 | case 1: return D3DPRESENT_INTERVAL_ONE; |
| 409 | case 2: return D3DPRESENT_INTERVAL_TWO; |
| 410 | case 3: return D3DPRESENT_INTERVAL_THREE; |
| 411 | case 4: return D3DPRESENT_INTERVAL_FOUR; |
| 412 | default: UNREACHABLE(); |
| 413 | } |
| 414 | |
| 415 | return D3DPRESENT_INTERVAL_DEFAULT; |
| 416 | } |
| 417 | |
daniel@transgaming.com | 4f39fd9 | 2010-03-08 20:26:45 +0000 | [diff] [blame] | 418 | IDirect3DDevice9 *Display::getDevice() |
| 419 | { |
| 420 | return mDevice; |
| 421 | } |
daniel@transgaming.com | 353569a | 2010-06-24 13:02:12 +0000 | [diff] [blame] | 422 | |
| 423 | D3DCAPS9 Display::getDeviceCaps() |
| 424 | { |
| 425 | return mDeviceCaps; |
| 426 | } |
daniel@transgaming.com | 4f39fd9 | 2010-03-08 20:26:45 +0000 | [diff] [blame] | 427 | } |