blob: bcda89512ff5fec95a8a0399261b614375f6ee9a [file] [log] [blame]
daniel@transgaming.come979ead2010-09-23 18:03:14 +00001//
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
11#include "libEGL/Display.h"
12
13#include <algorithm>
14#include <vector>
15
16#include "common/debug.h"
17
18#include "libEGL/main.h"
19
20#define REF_RAST 0 // Can also be enabled by defining FORCE_REF_RAST in the project's predefined macros
21#define ENABLE_D3D9EX 1 // Enables use of the IDirect3D9Ex interface, when available
22
23namespace egl
24{
25Display::Display(HDC deviceContext) : mDc(deviceContext)
26{
27 mD3d9Module = NULL;
28
29 mD3d9 = NULL;
30 mD3d9ex = NULL;
31 mDevice = NULL;
32 mDeviceWindow = NULL;
33
34 mAdapter = D3DADAPTER_DEFAULT;
35
36 #if REF_RAST == 1 || defined(FORCE_REF_RAST)
37 mDeviceType = D3DDEVTYPE_REF;
38 #else
39 mDeviceType = D3DDEVTYPE_HAL;
40 #endif
41
42 mMinSwapInterval = 1;
43 mMaxSwapInterval = 1;
44}
45
46Display::~Display()
47{
48 terminate();
49}
50
51bool Display::initialize()
52{
53 if (isInitialized())
54 {
55 return true;
56 }
57
apatrick@chromium.org0f4cefe2011-01-26 19:30:57 +000058 mD3d9Module = GetModuleHandle(TEXT("d3d9.dll"));
daniel@transgaming.come979ead2010-09-23 18:03:14 +000059 if (mD3d9Module == NULL)
60 {
61 terminate();
62 return false;
63 }
64
daniel@transgaming.come979ead2010-09-23 18:03:14 +000065 typedef HRESULT (WINAPI *Direct3DCreate9ExFunc)(UINT, IDirect3D9Ex**);
66 Direct3DCreate9ExFunc Direct3DCreate9ExPtr = reinterpret_cast<Direct3DCreate9ExFunc>(GetProcAddress(mD3d9Module, "Direct3DCreate9Ex"));
67
68 // Use Direct3D9Ex if available. Among other things, this version is less
69 // inclined to report a lost context, for example when the user switches
70 // desktop. Direct3D9Ex is available in Windows Vista and later if suitable drivers are available.
71 if (ENABLE_D3D9EX && Direct3DCreate9ExPtr && SUCCEEDED(Direct3DCreate9ExPtr(D3D_SDK_VERSION, &mD3d9ex)))
72 {
73 ASSERT(mD3d9ex);
74 mD3d9ex->QueryInterface(IID_IDirect3D9, reinterpret_cast<void**>(&mD3d9));
75 ASSERT(mD3d9);
76 }
77 else
78 {
apatrick@chromium.org0f4cefe2011-01-26 19:30:57 +000079 mD3d9 = Direct3DCreate9(D3D_SDK_VERSION);
daniel@transgaming.come979ead2010-09-23 18:03:14 +000080 }
81
82 if (mD3d9)
83 {
84 if (mDc != NULL)
85 {
86 // UNIMPLEMENTED(); // FIXME: Determine which adapter index the device context corresponds to
87 }
88
89 HRESULT result;
90
apatrick@chromium.org1c768012010-10-07 00:35:24 +000091 // Give up on getting device caps after about one second.
92 for (int i = 0; i < 10; ++i)
daniel@transgaming.come979ead2010-09-23 18:03:14 +000093 {
94 result = mD3d9->GetDeviceCaps(mAdapter, mDeviceType, &mDeviceCaps);
apatrick@chromium.org1c768012010-10-07 00:35:24 +000095
96 if (SUCCEEDED(result))
daniel@transgaming.come979ead2010-09-23 18:03:14 +000097 {
apatrick@chromium.org1c768012010-10-07 00:35:24 +000098 break;
99 }
100 else if (result == D3DERR_NOTAVAILABLE)
101 {
102 Sleep(100); // Give the driver some time to initialize/recover
daniel@transgaming.come979ead2010-09-23 18:03:14 +0000103 }
104 else if (FAILED(result)) // D3DERR_OUTOFVIDEOMEMORY, E_OUTOFMEMORY, D3DERR_INVALIDDEVICE, or another error we can't recover from
105 {
apatrick@chromium.org1c768012010-10-07 00:35:24 +0000106 terminate();
daniel@transgaming.come979ead2010-09-23 18:03:14 +0000107 return error(EGL_BAD_ALLOC, false);
108 }
109 }
daniel@transgaming.come979ead2010-09-23 18:03:14 +0000110
111 if (mDeviceCaps.PixelShaderVersion < D3DPS_VERSION(2, 0))
112 {
113 terminate();
114 return error(EGL_NOT_INITIALIZED, false);
115 }
116
apatrick@chromium.org1c768012010-10-07 00:35:24 +0000117 // When DirectX9 is running with an older DirectX8 driver, a StretchRect from a regular texture to a render target texture is not supported.
118 // This is required by Texture2D::convertToRenderTarget.
119 if ((mDeviceCaps.DevCaps2 & D3DDEVCAPS2_CAN_STRETCHRECT_FROM_TEXTURES) == 0)
120 {
121 terminate();
122 return error(EGL_NOT_INITIALIZED, false);
123 }
124
daniel@transgaming.come979ead2010-09-23 18:03:14 +0000125 mMinSwapInterval = 4;
126 mMaxSwapInterval = 0;
127
128 if (mDeviceCaps.PresentationIntervals & D3DPRESENT_INTERVAL_IMMEDIATE) {mMinSwapInterval = std::min(mMinSwapInterval, 0); mMaxSwapInterval = std::max(mMaxSwapInterval, 0);}
129 if (mDeviceCaps.PresentationIntervals & D3DPRESENT_INTERVAL_ONE) {mMinSwapInterval = std::min(mMinSwapInterval, 1); mMaxSwapInterval = std::max(mMaxSwapInterval, 1);}
130 if (mDeviceCaps.PresentationIntervals & D3DPRESENT_INTERVAL_TWO) {mMinSwapInterval = std::min(mMinSwapInterval, 2); mMaxSwapInterval = std::max(mMaxSwapInterval, 2);}
131 if (mDeviceCaps.PresentationIntervals & D3DPRESENT_INTERVAL_THREE) {mMinSwapInterval = std::min(mMinSwapInterval, 3); mMaxSwapInterval = std::max(mMaxSwapInterval, 3);}
132 if (mDeviceCaps.PresentationIntervals & D3DPRESENT_INTERVAL_FOUR) {mMinSwapInterval = std::min(mMinSwapInterval, 4); mMaxSwapInterval = std::max(mMaxSwapInterval, 4);}
133
134 const D3DFORMAT renderTargetFormats[] =
135 {
136 D3DFMT_A1R5G5B5,
137 // D3DFMT_A2R10G10B10, // The color_ramp conformance test uses ReadPixels with UNSIGNED_BYTE causing it to think that rendering skipped a colour value.
138 D3DFMT_A8R8G8B8,
139 D3DFMT_R5G6B5,
daniel@transgaming.com73a5db62010-10-15 17:58:13 +0000140 // D3DFMT_X1R5G5B5, // Has no compatible OpenGL ES renderbuffer format
daniel@transgaming.come979ead2010-09-23 18:03:14 +0000141 D3DFMT_X8R8G8B8
142 };
143
144 const D3DFORMAT depthStencilFormats[] =
145 {
146 // D3DFMT_D16_LOCKABLE,
147 D3DFMT_D32,
148 // D3DFMT_D15S1,
149 D3DFMT_D24S8,
150 D3DFMT_D24X8,
151 // D3DFMT_D24X4S4,
152 D3DFMT_D16,
153 // D3DFMT_D32F_LOCKABLE,
154 // D3DFMT_D24FS8
155 };
156
157 D3DDISPLAYMODE currentDisplayMode;
158 mD3d9->GetAdapterDisplayMode(mAdapter, &currentDisplayMode);
159
160 ConfigSet configSet;
161
162 for (int formatIndex = 0; formatIndex < sizeof(renderTargetFormats) / sizeof(D3DFORMAT); formatIndex++)
163 {
164 D3DFORMAT renderTargetFormat = renderTargetFormats[formatIndex];
165
166 HRESULT result = mD3d9->CheckDeviceFormat(mAdapter, mDeviceType, currentDisplayMode.Format, D3DUSAGE_RENDERTARGET, D3DRTYPE_SURFACE, renderTargetFormat);
167
168 if (SUCCEEDED(result))
169 {
170 for (int depthStencilIndex = 0; depthStencilIndex < sizeof(depthStencilFormats) / sizeof(D3DFORMAT); depthStencilIndex++)
171 {
172 D3DFORMAT depthStencilFormat = depthStencilFormats[depthStencilIndex];
173 HRESULT result = mD3d9->CheckDeviceFormat(mAdapter, mDeviceType, currentDisplayMode.Format, D3DUSAGE_DEPTHSTENCIL, D3DRTYPE_SURFACE, depthStencilFormat);
174
175 if (SUCCEEDED(result))
176 {
177 HRESULT result = mD3d9->CheckDepthStencilMatch(mAdapter, mDeviceType, currentDisplayMode.Format, renderTargetFormat, depthStencilFormat);
178
179 if (SUCCEEDED(result))
180 {
181 // FIXME: enumerate multi-sampling
182
183 configSet.add(currentDisplayMode, mMinSwapInterval, mMaxSwapInterval, renderTargetFormat, depthStencilFormat, 0);
184 }
185 }
186 }
187 }
188 }
189
190 // Give the sorted configs a unique ID and store them internally
191 EGLint index = 1;
192 for (ConfigSet::Iterator config = configSet.mSet.begin(); config != configSet.mSet.end(); config++)
193 {
194 Config configuration = *config;
195 configuration.mConfigID = index;
196 index++;
197
198 mConfigSet.mSet.insert(configuration);
199 }
200 }
201
202 if (!isInitialized())
203 {
204 terminate();
205
206 return false;
207 }
208
209 static const TCHAR windowName[] = TEXT("AngleHiddenWindow");
210 static const TCHAR className[] = TEXT("STATIC");
211
212 mDeviceWindow = CreateWindowEx(WS_EX_NOACTIVATE, className, windowName, WS_DISABLED | WS_POPUP, 0, 0, 1, 1, HWND_MESSAGE, NULL, GetModuleHandle(NULL), NULL);
213
214 return true;
215}
216
217void Display::terminate()
218{
219 while (!mSurfaceSet.empty())
220 {
221 destroySurface(*mSurfaceSet.begin());
222 }
223
224 while (!mContextSet.empty())
225 {
226 destroyContext(*mContextSet.begin());
227 }
228
229 if (mDevice)
230 {
231 // If the device is lost, reset it first to prevent leaving the driver in an unstable state
232 if (FAILED(mDevice->TestCooperativeLevel()))
233 {
234 resetDevice();
235 }
236
237 mDevice->Release();
238 mDevice = NULL;
239 }
240
241 if (mD3d9)
242 {
243 mD3d9->Release();
244 mD3d9 = NULL;
245 }
246
247 if (mDeviceWindow)
248 {
249 DestroyWindow(mDeviceWindow);
250 mDeviceWindow = NULL;
251 }
252
253 if (mD3d9ex)
254 {
255 mD3d9ex->Release();
256 mD3d9ex = NULL;
257 }
258
259 if (mD3d9Module)
260 {
daniel@transgaming.come979ead2010-09-23 18:03:14 +0000261 mD3d9Module = NULL;
262 }
263}
264
265void Display::startScene()
266{
267 if (!mSceneStarted)
268 {
269 long result = mDevice->BeginScene();
270 ASSERT(SUCCEEDED(result));
271 mSceneStarted = true;
272 }
273}
274
275void Display::endScene()
276{
277 if (mSceneStarted)
278 {
279 long result = mDevice->EndScene();
280 ASSERT(SUCCEEDED(result));
281 mSceneStarted = false;
282 }
283}
284
285bool Display::getConfigs(EGLConfig *configs, const EGLint *attribList, EGLint configSize, EGLint *numConfig)
286{
287 return mConfigSet.getConfigs(configs, attribList, configSize, numConfig);
288}
289
290bool Display::getConfigAttrib(EGLConfig config, EGLint attribute, EGLint *value)
291{
292 const egl::Config *configuration = mConfigSet.get(config);
293
294 switch (attribute)
295 {
296 case EGL_BUFFER_SIZE: *value = configuration->mBufferSize; break;
297 case EGL_ALPHA_SIZE: *value = configuration->mAlphaSize; break;
298 case EGL_BLUE_SIZE: *value = configuration->mBlueSize; break;
299 case EGL_GREEN_SIZE: *value = configuration->mGreenSize; break;
300 case EGL_RED_SIZE: *value = configuration->mRedSize; break;
301 case EGL_DEPTH_SIZE: *value = configuration->mDepthSize; break;
302 case EGL_STENCIL_SIZE: *value = configuration->mStencilSize; break;
303 case EGL_CONFIG_CAVEAT: *value = configuration->mConfigCaveat; break;
304 case EGL_CONFIG_ID: *value = configuration->mConfigID; break;
305 case EGL_LEVEL: *value = configuration->mLevel; break;
306 case EGL_NATIVE_RENDERABLE: *value = configuration->mNativeRenderable; break;
307 case EGL_NATIVE_VISUAL_TYPE: *value = configuration->mNativeVisualType; break;
308 case EGL_SAMPLES: *value = configuration->mSamples; break;
309 case EGL_SAMPLE_BUFFERS: *value = configuration->mSampleBuffers; break;
310 case EGL_SURFACE_TYPE: *value = configuration->mSurfaceType; break;
311 case EGL_TRANSPARENT_TYPE: *value = configuration->mTransparentType; break;
312 case EGL_TRANSPARENT_BLUE_VALUE: *value = configuration->mTransparentBlueValue; break;
313 case EGL_TRANSPARENT_GREEN_VALUE: *value = configuration->mTransparentGreenValue; break;
314 case EGL_TRANSPARENT_RED_VALUE: *value = configuration->mTransparentRedValue; break;
315 case EGL_BIND_TO_TEXTURE_RGB: *value = configuration->mBindToTextureRGB; break;
316 case EGL_BIND_TO_TEXTURE_RGBA: *value = configuration->mBindToTextureRGBA; break;
317 case EGL_MIN_SWAP_INTERVAL: *value = configuration->mMinSwapInterval; break;
318 case EGL_MAX_SWAP_INTERVAL: *value = configuration->mMaxSwapInterval; break;
319 case EGL_LUMINANCE_SIZE: *value = configuration->mLuminanceSize; break;
320 case EGL_ALPHA_MASK_SIZE: *value = configuration->mAlphaMaskSize; break;
321 case EGL_COLOR_BUFFER_TYPE: *value = configuration->mColorBufferType; break;
322 case EGL_RENDERABLE_TYPE: *value = configuration->mRenderableType; break;
323 case EGL_MATCH_NATIVE_PIXMAP: *value = false; UNIMPLEMENTED(); break;
324 case EGL_CONFORMANT: *value = configuration->mConformant; break;
325 default:
326 return false;
327 }
328
329 return true;
330}
331
332bool Display::createDevice()
333{
334 D3DPRESENT_PARAMETERS presentParameters = getDefaultPresentParameters();
335 DWORD behaviorFlags = D3DCREATE_FPU_PRESERVE | D3DCREATE_NOWINDOWCHANGES;
336
337 HRESULT result = mD3d9->CreateDevice(mAdapter, mDeviceType, mDeviceWindow, behaviorFlags | D3DCREATE_HARDWARE_VERTEXPROCESSING | D3DCREATE_PUREDEVICE, &presentParameters, &mDevice);
338
339 if (result == D3DERR_OUTOFVIDEOMEMORY || result == E_OUTOFMEMORY || result == D3DERR_DEVICELOST)
340 {
341 return error(EGL_BAD_ALLOC, false);
342 }
343
344 if (FAILED(result))
345 {
346 result = mD3d9->CreateDevice(mAdapter, mDeviceType, mDeviceWindow, behaviorFlags | D3DCREATE_SOFTWARE_VERTEXPROCESSING, &presentParameters, &mDevice);
347
348 if (FAILED(result))
349 {
350 ASSERT(result == D3DERR_OUTOFVIDEOMEMORY || result == E_OUTOFMEMORY || result == D3DERR_NOTAVAILABLE || result == D3DERR_DEVICELOST);
351 return error(EGL_BAD_ALLOC, false);
352 }
353 }
354
355 // Permanent non-default states
356 mDevice->SetRenderState(D3DRS_POINTSPRITEENABLE, TRUE);
357
358 mSceneStarted = false;
359
360 return true;
361}
362
363bool Display::resetDevice()
364{
365 D3DPRESENT_PARAMETERS presentParameters = getDefaultPresentParameters();
366 HRESULT result;
367
368 do
369 {
370 Sleep(0); // Give the graphics driver some CPU time
371
372 result = mDevice->Reset(&presentParameters);
373 }
374 while (result == D3DERR_DEVICELOST);
375
376 if (FAILED(result))
377 {
378 return error(EGL_BAD_ALLOC, false);
379 }
380
381 ASSERT(SUCCEEDED(result));
382
383 return true;
384}
385
386Surface *Display::createWindowSurface(HWND window, EGLConfig config)
387{
388 const Config *configuration = mConfigSet.get(config);
389
390 Surface *surface = new Surface(this, configuration, window);
391 mSurfaceSet.insert(surface);
392
393 return surface;
394}
395
396EGLContext Display::createContext(EGLConfig configHandle, const gl::Context *shareContext)
397{
398 if (!mDevice)
399 {
400 if (!createDevice())
401 {
402 return NULL;
403 }
404 }
405 else if (FAILED(mDevice->TestCooperativeLevel())) // Lost device
406 {
407 if (!resetDevice())
408 {
409 return NULL;
410 }
411
412 // Restore any surfaces that may have been lost
413 for (SurfaceSet::iterator surface = mSurfaceSet.begin(); surface != mSurfaceSet.end(); surface++)
414 {
415 (*surface)->resetSwapChain();
416 }
417 }
418
419 const egl::Config *config = mConfigSet.get(configHandle);
420
421 gl::Context *context = glCreateContext(config, shareContext);
422 mContextSet.insert(context);
423
424 return context;
425}
426
427void Display::destroySurface(egl::Surface *surface)
428{
429 delete surface;
430 mSurfaceSet.erase(surface);
431}
432
433void Display::destroyContext(gl::Context *context)
434{
435 glDestroyContext(context);
436 mContextSet.erase(context);
437
438 if (mContextSet.empty() && mDevice && FAILED(mDevice->TestCooperativeLevel())) // Last context of a lost device
439 {
440 for (SurfaceSet::iterator surface = mSurfaceSet.begin(); surface != mSurfaceSet.end(); surface++)
441 {
442 (*surface)->release();
443 }
444 }
445}
446
447bool Display::isInitialized()
448{
449 return mD3d9 != NULL && mConfigSet.size() > 0;
450}
451
452bool Display::isValidConfig(EGLConfig config)
453{
454 return mConfigSet.get(config) != NULL;
455}
456
457bool Display::isValidContext(gl::Context *context)
458{
459 return mContextSet.find(context) != mContextSet.end();
460}
461
462bool Display::isValidSurface(egl::Surface *surface)
463{
464 return mSurfaceSet.find(surface) != mSurfaceSet.end();
465}
466
467bool Display::hasExistingWindowSurface(HWND window)
468{
469 for (SurfaceSet::iterator surface = mSurfaceSet.begin(); surface != mSurfaceSet.end(); surface++)
470 {
471 if ((*surface)->getWindowHandle() == window)
472 {
473 return true;
474 }
475 }
476
477 return false;
478}
479
480EGLint Display::getMinSwapInterval()
481{
482 return mMinSwapInterval;
483}
484
485EGLint Display::getMaxSwapInterval()
486{
487 return mMaxSwapInterval;
488}
489
490IDirect3DDevice9 *Display::getDevice()
491{
492 if (!mDevice)
493 {
494 if (!createDevice())
495 {
496 return NULL;
497 }
498 }
499
500 return mDevice;
501}
502
503D3DCAPS9 Display::getDeviceCaps()
504{
505 return mDeviceCaps;
506}
507
508void Display::getMultiSampleSupport(D3DFORMAT format, bool *multiSampleArray)
509{
510 for (int multiSampleIndex = 0; multiSampleIndex <= D3DMULTISAMPLE_16_SAMPLES; multiSampleIndex++)
511 {
512 HRESULT result = mD3d9->CheckDeviceMultiSampleType(mAdapter, mDeviceType, format,
513 TRUE, (D3DMULTISAMPLE_TYPE)multiSampleIndex, NULL);
514
515 multiSampleArray[multiSampleIndex] = SUCCEEDED(result);
516 }
517}
518
519bool Display::getCompressedTextureSupport()
520{
521 D3DDISPLAYMODE currentDisplayMode;
522 mD3d9->GetAdapterDisplayMode(mAdapter, &currentDisplayMode);
523
524 return SUCCEEDED(mD3d9->CheckDeviceFormat(mAdapter, mDeviceType, currentDisplayMode.Format, 0, D3DRTYPE_TEXTURE, D3DFMT_DXT1));
525}
526
527bool Display::getFloatTextureSupport(bool *filtering, bool *renderable)
528{
529 D3DDISPLAYMODE currentDisplayMode;
530 mD3d9->GetAdapterDisplayMode(mAdapter, &currentDisplayMode);
531
532 *filtering = SUCCEEDED(mD3d9->CheckDeviceFormat(mAdapter, mDeviceType, currentDisplayMode.Format, D3DUSAGE_QUERY_FILTER,
533 D3DRTYPE_TEXTURE, D3DFMT_A32B32G32R32F)) &&
534 SUCCEEDED(mD3d9->CheckDeviceFormat(mAdapter, mDeviceType, currentDisplayMode.Format, D3DUSAGE_QUERY_FILTER,
535 D3DRTYPE_CUBETEXTURE, D3DFMT_A32B32G32R32F));
536
537 *renderable = SUCCEEDED(mD3d9->CheckDeviceFormat(mAdapter, mDeviceType, currentDisplayMode.Format, D3DUSAGE_RENDERTARGET,
538 D3DRTYPE_TEXTURE, D3DFMT_A32B32G32R32F))&&
539 SUCCEEDED(mD3d9->CheckDeviceFormat(mAdapter, mDeviceType, currentDisplayMode.Format, D3DUSAGE_RENDERTARGET,
540 D3DRTYPE_CUBETEXTURE, D3DFMT_A32B32G32R32F));
541
542 if (!filtering && !renderable)
543 {
544 return SUCCEEDED(mD3d9->CheckDeviceFormat(mAdapter, mDeviceType, currentDisplayMode.Format, 0,
545 D3DRTYPE_TEXTURE, D3DFMT_A32B32G32R32F)) &&
546 SUCCEEDED(mD3d9->CheckDeviceFormat(mAdapter, mDeviceType, currentDisplayMode.Format, 0,
547 D3DRTYPE_CUBETEXTURE, D3DFMT_A32B32G32R32F));
548 }
549 else
550 {
551 return true;
552 }
553}
554
555bool Display::getHalfFloatTextureSupport(bool *filtering, bool *renderable)
556{
557 D3DDISPLAYMODE currentDisplayMode;
558 mD3d9->GetAdapterDisplayMode(mAdapter, &currentDisplayMode);
559
560 *filtering = SUCCEEDED(mD3d9->CheckDeviceFormat(mAdapter, mDeviceType, currentDisplayMode.Format, D3DUSAGE_QUERY_FILTER,
561 D3DRTYPE_TEXTURE, D3DFMT_A16B16G16R16F)) &&
562 SUCCEEDED(mD3d9->CheckDeviceFormat(mAdapter, mDeviceType, currentDisplayMode.Format, D3DUSAGE_QUERY_FILTER,
563 D3DRTYPE_CUBETEXTURE, D3DFMT_A16B16G16R16F));
564
565 *renderable = SUCCEEDED(mD3d9->CheckDeviceFormat(mAdapter, mDeviceType, currentDisplayMode.Format, D3DUSAGE_RENDERTARGET,
566 D3DRTYPE_TEXTURE, D3DFMT_A16B16G16R16F)) &&
567 SUCCEEDED(mD3d9->CheckDeviceFormat(mAdapter, mDeviceType, currentDisplayMode.Format, D3DUSAGE_RENDERTARGET,
568 D3DRTYPE_CUBETEXTURE, D3DFMT_A16B16G16R16F));
569
570 if (!filtering && !renderable)
571 {
572 return SUCCEEDED(mD3d9->CheckDeviceFormat(mAdapter, mDeviceType, currentDisplayMode.Format, 0,
573 D3DRTYPE_TEXTURE, D3DFMT_A16B16G16R16F)) &&
574 SUCCEEDED(mD3d9->CheckDeviceFormat(mAdapter, mDeviceType, currentDisplayMode.Format, 0,
575 D3DRTYPE_CUBETEXTURE, D3DFMT_A16B16G16R16F));
576 }
577 else
578 {
579 return true;
580 }
581}
582
daniel@transgaming.comed828e52010-10-15 17:57:30 +0000583bool Display::getLuminanceTextureSupport()
584{
585 D3DDISPLAYMODE currentDisplayMode;
586 mD3d9->GetAdapterDisplayMode(mAdapter, &currentDisplayMode);
587
588 return SUCCEEDED(mD3d9->CheckDeviceFormat(mAdapter, mDeviceType, currentDisplayMode.Format, 0, D3DRTYPE_TEXTURE, D3DFMT_L8));
589}
590
591bool Display::getLuminanceAlphaTextureSupport()
592{
593 D3DDISPLAYMODE currentDisplayMode;
594 mD3d9->GetAdapterDisplayMode(mAdapter, &currentDisplayMode);
595
596 return SUCCEEDED(mD3d9->CheckDeviceFormat(mAdapter, mDeviceType, currentDisplayMode.Format, 0, D3DRTYPE_TEXTURE, D3DFMT_A8L8));
597}
598
daniel@transgaming.comee04e452011-01-08 05:46:27 +0000599D3DPOOL Display::getBufferPool(DWORD usage) const
daniel@transgaming.com37b141e2011-01-08 05:46:13 +0000600{
daniel@transgaming.comee04e452011-01-08 05:46:27 +0000601 if (mD3d9ex != NULL)
602 {
603 return D3DPOOL_DEFAULT;
604 }
605 else
606 {
607 if (!(usage & D3DUSAGE_DYNAMIC))
608 {
609 return D3DPOOL_MANAGED;
610 }
611 }
612
613 return D3DPOOL_DEFAULT;
daniel@transgaming.com37b141e2011-01-08 05:46:13 +0000614}
615
daniel@transgaming.come979ead2010-09-23 18:03:14 +0000616bool Display::getEventQuerySupport()
617{
618 IDirect3DQuery9 *query;
619 HRESULT result = mDevice->CreateQuery(D3DQUERYTYPE_EVENT, &query);
620 if (SUCCEEDED(result))
621 {
622 query->Release();
623 }
624
625 return result != D3DERR_NOTAVAILABLE;
626}
627
628D3DPRESENT_PARAMETERS Display::getDefaultPresentParameters()
629{
630 D3DPRESENT_PARAMETERS presentParameters = {0};
631
632 // The default swap chain is never actually used. Surface will create a new swap chain with the proper parameters.
633 presentParameters.AutoDepthStencilFormat = D3DFMT_UNKNOWN;
634 presentParameters.BackBufferCount = 1;
635 presentParameters.BackBufferFormat = D3DFMT_UNKNOWN;
636 presentParameters.BackBufferWidth = 1;
637 presentParameters.BackBufferHeight = 1;
638 presentParameters.EnableAutoDepthStencil = FALSE;
639 presentParameters.Flags = 0;
640 presentParameters.hDeviceWindow = mDeviceWindow;
641 presentParameters.MultiSampleQuality = 0;
642 presentParameters.MultiSampleType = D3DMULTISAMPLE_NONE;
643 presentParameters.PresentationInterval = D3DPRESENT_INTERVAL_DEFAULT;
644 presentParameters.SwapEffect = D3DSWAPEFFECT_DISCARD;
645 presentParameters.Windowed = TRUE;
646
647 return presentParameters;
648}
daniel@transgaming.comd36c6a02010-08-31 12:15:09 +0000649}