shannon.woods@transgaming.com | bdf2d80 | 2013-02-28 23:16:20 +0000 | [diff] [blame] | 1 | #include "precompiled.h" |
daniel@transgaming.com | 621ce05 | 2012-10-31 17:52:29 +0000 | [diff] [blame] | 2 | // |
daniel@transgaming.com | 669c995 | 2013-01-11 04:08:16 +0000 | [diff] [blame] | 3 | // Copyright (c) 2012-2013 The ANGLE Project Authors. All rights reserved. |
daniel@transgaming.com | 621ce05 | 2012-10-31 17:52:29 +0000 | [diff] [blame] | 4 | // Use of this source code is governed by a BSD-style license that can be |
| 5 | // found in the LICENSE file. |
| 6 | // |
| 7 | |
daniel@transgaming.com | 1d6aff2 | 2012-11-28 19:30:42 +0000 | [diff] [blame] | 8 | // Renderer9.cpp: Implements a back-end specific class for the D3D9 renderer. |
daniel@transgaming.com | 621ce05 | 2012-10-31 17:52:29 +0000 | [diff] [blame] | 9 | |
Geoff Lang | 2a64ee4 | 2013-05-31 11:22:40 -0400 | [diff] [blame] | 10 | #include "common/utilities.h" |
| 11 | |
daniel@transgaming.com | 493d4f8 | 2012-11-28 19:35:45 +0000 | [diff] [blame] | 12 | #include "libGLESv2/main.h" |
daniel@transgaming.com | 91207b7 | 2012-11-28 20:56:43 +0000 | [diff] [blame] | 13 | #include "libGLESv2/Buffer.h" |
shannon.woods@transgaming.com | d2811d6 | 2013-02-28 23:11:19 +0000 | [diff] [blame] | 14 | #include "libGLESv2/Texture.h" |
daniel@transgaming.com | 493d4f8 | 2012-11-28 19:35:45 +0000 | [diff] [blame] | 15 | #include "libGLESv2/Framebuffer.h" |
shannon.woods@transgaming.com | 486d9e9 | 2013-02-28 23:15:41 +0000 | [diff] [blame] | 16 | #include "libGLESv2/Renderbuffer.h" |
daniel@transgaming.com | 83e80ee | 2012-11-28 19:40:53 +0000 | [diff] [blame] | 17 | #include "libGLESv2/ProgramBinary.h" |
daniel@transgaming.com | 50aadb0 | 2012-11-28 21:06:11 +0000 | [diff] [blame] | 18 | #include "libGLESv2/renderer/IndexDataManager.h" |
daniel@transgaming.com | 2507f41 | 2012-10-31 18:46:48 +0000 | [diff] [blame] | 19 | #include "libGLESv2/renderer/Renderer9.h" |
daniel@transgaming.com | d8e3656 | 2012-10-31 19:52:19 +0000 | [diff] [blame] | 20 | #include "libGLESv2/renderer/renderer9_utils.h" |
shannonwoods@chromium.org | 755012f | 2013-05-30 00:09:32 +0000 | [diff] [blame] | 21 | #include "libGLESv2/renderer/formatutils9.h" |
daniel@transgaming.com | a9c7142 | 2012-11-28 20:58:45 +0000 | [diff] [blame] | 22 | #include "libGLESv2/renderer/ShaderExecutable9.h" |
daniel@transgaming.com | a27e05b | 2012-11-28 19:39:42 +0000 | [diff] [blame] | 23 | #include "libGLESv2/renderer/SwapChain9.h" |
daniel@transgaming.com | 34da397 | 2012-12-20 21:10:29 +0000 | [diff] [blame] | 24 | #include "libGLESv2/renderer/TextureStorage9.h" |
daniel@transgaming.com | 4ba2406 | 2012-12-20 20:54:24 +0000 | [diff] [blame] | 25 | #include "libGLESv2/renderer/Image9.h" |
Geoff Lang | dce735c | 2013-06-04 10:21:18 -0400 | [diff] [blame] | 26 | #include "libGLESv2/renderer/Blit9.h" |
daniel@transgaming.com | d186dc7 | 2012-11-28 19:40:16 +0000 | [diff] [blame] | 27 | #include "libGLESv2/renderer/RenderTarget9.h" |
daniel@transgaming.com | 3f255b4 | 2012-12-20 21:07:35 +0000 | [diff] [blame] | 28 | #include "libGLESv2/renderer/VertexBuffer9.h" |
daniel@transgaming.com | 0b6d774 | 2012-12-20 21:09:47 +0000 | [diff] [blame] | 29 | #include "libGLESv2/renderer/IndexBuffer9.h" |
shannon.woods@transgaming.com | 4e52b63 | 2013-02-28 23:08:01 +0000 | [diff] [blame] | 30 | #include "libGLESv2/renderer/BufferStorage9.h" |
shannon.woods@transgaming.com | 50df6c5 | 2013-02-28 23:02:49 +0000 | [diff] [blame] | 31 | #include "libGLESv2/renderer/Query9.h" |
shannon.woods@transgaming.com | cfe787e | 2013-02-28 23:03:35 +0000 | [diff] [blame] | 32 | #include "libGLESv2/renderer/Fence9.h" |
daniel@transgaming.com | 621ce05 | 2012-10-31 17:52:29 +0000 | [diff] [blame] | 33 | |
shannon.woods@transgaming.com | 486d9e9 | 2013-02-28 23:15:41 +0000 | [diff] [blame] | 34 | #include "libEGL/Display.h" |
| 35 | |
daniel@transgaming.com | 621ce05 | 2012-10-31 17:52:29 +0000 | [diff] [blame] | 36 | // Can also be enabled by defining FORCE_REF_RAST in the project's predefined macros |
| 37 | #define REF_RAST 0 |
| 38 | |
| 39 | // The "Debug This Pixel..." feature in PIX often fails when using the |
| 40 | // D3D9Ex interfaces. In order to get debug pixel to work on a Vista/Win 7 |
| 41 | // machine, define "ANGLE_ENABLE_D3D9EX=0" in your project file. |
| 42 | #if !defined(ANGLE_ENABLE_D3D9EX) |
| 43 | // Enables use of the IDirect3D9Ex interface, when available |
| 44 | #define ANGLE_ENABLE_D3D9EX 1 |
| 45 | #endif // !defined(ANGLE_ENABLE_D3D9EX) |
| 46 | |
shannon.woods@transgaming.com | d3d4208 | 2013-02-28 23:14:31 +0000 | [diff] [blame] | 47 | #if !defined(ANGLE_COMPILE_OPTIMIZATION_LEVEL) |
| 48 | #define ANGLE_COMPILE_OPTIMIZATION_LEVEL D3DCOMPILE_OPTIMIZATION_LEVEL3 |
| 49 | #endif |
| 50 | |
shannonwoods@chromium.org | 755012f | 2013-05-30 00:09:32 +0000 | [diff] [blame] | 51 | const D3DFORMAT D3DFMT_INTZ = ((D3DFORMAT)(MAKEFOURCC('I','N','T','Z'))); |
| 52 | const D3DFORMAT D3DFMT_NULL = ((D3DFORMAT)(MAKEFOURCC('N','U','L','L'))); |
| 53 | |
daniel@transgaming.com | 76d3e6e | 2012-10-31 19:55:33 +0000 | [diff] [blame] | 54 | namespace rx |
daniel@transgaming.com | 621ce05 | 2012-10-31 17:52:29 +0000 | [diff] [blame] | 55 | { |
daniel@transgaming.com | 222ee08 | 2012-11-28 19:31:49 +0000 | [diff] [blame] | 56 | static const D3DFORMAT RenderTargetFormats[] = |
daniel@transgaming.com | 9295562 | 2012-10-31 18:38:41 +0000 | [diff] [blame] | 57 | { |
| 58 | D3DFMT_A1R5G5B5, |
| 59 | // D3DFMT_A2R10G10B10, // The color_ramp conformance test uses ReadPixels with UNSIGNED_BYTE causing it to think that rendering skipped a colour value. |
| 60 | D3DFMT_A8R8G8B8, |
| 61 | D3DFMT_R5G6B5, |
| 62 | // D3DFMT_X1R5G5B5, // Has no compatible OpenGL ES renderbuffer format |
| 63 | D3DFMT_X8R8G8B8 |
| 64 | }; |
| 65 | |
daniel@transgaming.com | 222ee08 | 2012-11-28 19:31:49 +0000 | [diff] [blame] | 66 | static const D3DFORMAT DepthStencilFormats[] = |
daniel@transgaming.com | 9295562 | 2012-10-31 18:38:41 +0000 | [diff] [blame] | 67 | { |
| 68 | D3DFMT_UNKNOWN, |
| 69 | // D3DFMT_D16_LOCKABLE, |
| 70 | D3DFMT_D32, |
| 71 | // D3DFMT_D15S1, |
| 72 | D3DFMT_D24S8, |
| 73 | D3DFMT_D24X8, |
| 74 | // D3DFMT_D24X4S4, |
| 75 | D3DFMT_D16, |
| 76 | // D3DFMT_D32F_LOCKABLE, |
| 77 | // D3DFMT_D24FS8 |
| 78 | }; |
daniel@transgaming.com | 621ce05 | 2012-10-31 17:52:29 +0000 | [diff] [blame] | 79 | |
shannon.woods@transgaming.com | 233fe95 | 2013-01-25 21:51:57 +0000 | [diff] [blame] | 80 | enum |
| 81 | { |
shannon.woods@transgaming.com | d8136cb | 2013-02-28 23:14:44 +0000 | [diff] [blame] | 82 | MAX_VERTEX_CONSTANT_VECTORS_D3D9 = 256, |
| 83 | MAX_PIXEL_CONSTANT_VECTORS_SM2 = 32, |
| 84 | MAX_PIXEL_CONSTANT_VECTORS_SM3 = 224, |
| 85 | MAX_VARYING_VECTORS_SM2 = 8, |
| 86 | MAX_VARYING_VECTORS_SM3 = 10, |
| 87 | |
shannon.woods@transgaming.com | 233fe95 | 2013-01-25 21:51:57 +0000 | [diff] [blame] | 88 | MAX_TEXTURE_IMAGE_UNITS_VTF_SM3 = 4 |
| 89 | }; |
| 90 | |
daniel@transgaming.com | 95ffbc1 | 2012-10-31 19:55:27 +0000 | [diff] [blame] | 91 | Renderer9::Renderer9(egl::Display *display, HDC hDc, bool softwareDevice) : Renderer(display), mDc(hDc), mSoftwareDevice(softwareDevice) |
daniel@transgaming.com | 621ce05 | 2012-10-31 17:52:29 +0000 | [diff] [blame] | 92 | { |
daniel@transgaming.com | 95ffbc1 | 2012-10-31 19:55:27 +0000 | [diff] [blame] | 93 | mD3d9Module = NULL; |
daniel@transgaming.com | 621ce05 | 2012-10-31 17:52:29 +0000 | [diff] [blame] | 94 | |
| 95 | mD3d9 = NULL; |
| 96 | mD3d9Ex = NULL; |
| 97 | mDevice = NULL; |
| 98 | mDeviceEx = NULL; |
| 99 | mDeviceWindow = NULL; |
daniel@transgaming.com | de8a7ff | 2012-11-28 19:34:13 +0000 | [diff] [blame] | 100 | mBlit = NULL; |
daniel@transgaming.com | 621ce05 | 2012-10-31 17:52:29 +0000 | [diff] [blame] | 101 | |
| 102 | mAdapter = D3DADAPTER_DEFAULT; |
| 103 | |
| 104 | #if REF_RAST == 1 || defined(FORCE_REF_RAST) |
| 105 | mDeviceType = D3DDEVTYPE_REF; |
| 106 | #else |
| 107 | mDeviceType = D3DDEVTYPE_HAL; |
| 108 | #endif |
| 109 | |
| 110 | mDeviceLost = false; |
daniel@transgaming.com | b783398 | 2012-10-31 18:31:46 +0000 | [diff] [blame] | 111 | |
| 112 | mMaxSupportedSamples = 0; |
daniel@transgaming.com | 67094ee | 2012-11-28 20:53:04 +0000 | [diff] [blame] | 113 | |
daniel@transgaming.com | 0393e5b | 2012-11-28 20:55:33 +0000 | [diff] [blame] | 114 | mMaskedClearSavedState = NULL; |
daniel@transgaming.com | 91207b7 | 2012-11-28 20:56:43 +0000 | [diff] [blame] | 115 | |
| 116 | mVertexDataManager = NULL; |
| 117 | mIndexDataManager = NULL; |
| 118 | mLineLoopIB = NULL; |
daniel@transgaming.com | e4e1a33 | 2012-12-20 20:52:09 +0000 | [diff] [blame] | 119 | |
| 120 | mMaxNullColorbufferLRU = 0; |
| 121 | for (int i = 0; i < NUM_NULL_COLORBUFFER_CACHE_ENTRIES; i++) |
| 122 | { |
| 123 | mNullColorbufferCache[i].lruCount = 0; |
| 124 | mNullColorbufferCache[i].width = 0; |
| 125 | mNullColorbufferCache[i].height = 0; |
| 126 | mNullColorbufferCache[i].buffer = NULL; |
| 127 | } |
daniel@transgaming.com | 621ce05 | 2012-10-31 17:52:29 +0000 | [diff] [blame] | 128 | } |
| 129 | |
daniel@transgaming.com | 2507f41 | 2012-10-31 18:46:48 +0000 | [diff] [blame] | 130 | Renderer9::~Renderer9() |
daniel@transgaming.com | 621ce05 | 2012-10-31 17:52:29 +0000 | [diff] [blame] | 131 | { |
daniel@transgaming.com | ef21ab2 | 2012-10-31 17:52:47 +0000 | [diff] [blame] | 132 | releaseDeviceResources(); |
| 133 | |
daniel@transgaming.com | 621ce05 | 2012-10-31 17:52:29 +0000 | [diff] [blame] | 134 | if (mDevice) |
| 135 | { |
| 136 | // If the device is lost, reset it first to prevent leaving the driver in an unstable state |
daniel@transgaming.com | f688c0d | 2012-10-31 17:52:57 +0000 | [diff] [blame] | 137 | if (testDeviceLost(false)) |
daniel@transgaming.com | 621ce05 | 2012-10-31 17:52:29 +0000 | [diff] [blame] | 138 | { |
| 139 | resetDevice(); |
| 140 | } |
| 141 | |
| 142 | mDevice->Release(); |
| 143 | mDevice = NULL; |
| 144 | } |
| 145 | |
| 146 | if (mDeviceEx) |
| 147 | { |
| 148 | mDeviceEx->Release(); |
| 149 | mDeviceEx = NULL; |
| 150 | } |
| 151 | |
| 152 | if (mD3d9) |
| 153 | { |
| 154 | mD3d9->Release(); |
| 155 | mD3d9 = NULL; |
| 156 | } |
| 157 | |
| 158 | if (mDeviceWindow) |
| 159 | { |
| 160 | DestroyWindow(mDeviceWindow); |
| 161 | mDeviceWindow = NULL; |
| 162 | } |
| 163 | |
| 164 | if (mD3d9Ex) |
| 165 | { |
| 166 | mD3d9Ex->Release(); |
| 167 | mD3d9Ex = NULL; |
| 168 | } |
| 169 | |
| 170 | if (mD3d9Module) |
| 171 | { |
| 172 | mD3d9Module = NULL; |
| 173 | } |
daniel@transgaming.com | 621ce05 | 2012-10-31 17:52:29 +0000 | [diff] [blame] | 174 | } |
| 175 | |
daniel@transgaming.com | b64ed28 | 2012-11-28 20:54:02 +0000 | [diff] [blame] | 176 | Renderer9 *Renderer9::makeRenderer9(Renderer *renderer) |
| 177 | { |
apatrick@chromium.org | 8b400b1 | 2013-01-30 21:53:40 +0000 | [diff] [blame] | 178 | ASSERT(HAS_DYNAMIC_TYPE(rx::Renderer9*, renderer)); |
daniel@transgaming.com | b64ed28 | 2012-11-28 20:54:02 +0000 | [diff] [blame] | 179 | return static_cast<rx::Renderer9*>(renderer); |
| 180 | } |
| 181 | |
daniel@transgaming.com | 2507f41 | 2012-10-31 18:46:48 +0000 | [diff] [blame] | 182 | EGLint Renderer9::initialize() |
daniel@transgaming.com | 621ce05 | 2012-10-31 17:52:29 +0000 | [diff] [blame] | 183 | { |
daniel@transgaming.com | 25e16af | 2012-11-28 21:05:57 +0000 | [diff] [blame] | 184 | if (!initializeCompiler()) |
| 185 | { |
| 186 | return EGL_NOT_INITIALIZED; |
| 187 | } |
| 188 | |
daniel@transgaming.com | 95ffbc1 | 2012-10-31 19:55:27 +0000 | [diff] [blame] | 189 | if (mSoftwareDevice) |
| 190 | { |
| 191 | mD3d9Module = GetModuleHandle(TEXT("swiftshader_d3d9.dll")); |
| 192 | } |
| 193 | else |
| 194 | { |
| 195 | mD3d9Module = GetModuleHandle(TEXT("d3d9.dll")); |
| 196 | } |
| 197 | |
| 198 | if (mD3d9Module == NULL) |
| 199 | { |
| 200 | ERR("No D3D9 module found - aborting!\n"); |
| 201 | return EGL_NOT_INITIALIZED; |
| 202 | } |
| 203 | |
daniel@transgaming.com | 621ce05 | 2012-10-31 17:52:29 +0000 | [diff] [blame] | 204 | typedef HRESULT (WINAPI *Direct3DCreate9ExFunc)(UINT, IDirect3D9Ex**); |
| 205 | Direct3DCreate9ExFunc Direct3DCreate9ExPtr = reinterpret_cast<Direct3DCreate9ExFunc>(GetProcAddress(mD3d9Module, "Direct3DCreate9Ex")); |
| 206 | |
| 207 | // Use Direct3D9Ex if available. Among other things, this version is less |
| 208 | // inclined to report a lost context, for example when the user switches |
| 209 | // desktop. Direct3D9Ex is available in Windows Vista and later if suitable drivers are available. |
| 210 | if (ANGLE_ENABLE_D3D9EX && Direct3DCreate9ExPtr && SUCCEEDED(Direct3DCreate9ExPtr(D3D_SDK_VERSION, &mD3d9Ex))) |
| 211 | { |
| 212 | ASSERT(mD3d9Ex); |
| 213 | mD3d9Ex->QueryInterface(IID_IDirect3D9, reinterpret_cast<void**>(&mD3d9)); |
| 214 | ASSERT(mD3d9); |
| 215 | } |
| 216 | else |
| 217 | { |
| 218 | mD3d9 = Direct3DCreate9(D3D_SDK_VERSION); |
| 219 | } |
| 220 | |
| 221 | if (!mD3d9) |
| 222 | { |
| 223 | ERR("Could not create D3D9 device - aborting!\n"); |
| 224 | return EGL_NOT_INITIALIZED; |
| 225 | } |
daniel@transgaming.com | 7d738a2 | 2012-11-28 19:43:08 +0000 | [diff] [blame] | 226 | |
daniel@transgaming.com | 621ce05 | 2012-10-31 17:52:29 +0000 | [diff] [blame] | 227 | if (mDc != NULL) |
| 228 | { |
| 229 | // UNIMPLEMENTED(); // FIXME: Determine which adapter index the device context corresponds to |
| 230 | } |
| 231 | |
| 232 | HRESULT result; |
| 233 | |
| 234 | // Give up on getting device caps after about one second. |
| 235 | for (int i = 0; i < 10; ++i) |
| 236 | { |
| 237 | result = mD3d9->GetDeviceCaps(mAdapter, mDeviceType, &mDeviceCaps); |
| 238 | if (SUCCEEDED(result)) |
| 239 | { |
| 240 | break; |
| 241 | } |
| 242 | else if (result == D3DERR_NOTAVAILABLE) |
| 243 | { |
| 244 | Sleep(100); // Give the driver some time to initialize/recover |
| 245 | } |
| 246 | else if (FAILED(result)) // D3DERR_OUTOFVIDEOMEMORY, E_OUTOFMEMORY, D3DERR_INVALIDDEVICE, or another error we can't recover from |
| 247 | { |
| 248 | ERR("failed to get device caps (0x%x)\n", result); |
| 249 | return EGL_NOT_INITIALIZED; |
| 250 | } |
| 251 | } |
| 252 | |
| 253 | if (mDeviceCaps.PixelShaderVersion < D3DPS_VERSION(2, 0)) |
| 254 | { |
| 255 | ERR("Renderer does not support PS 2.0. aborting!\n"); |
| 256 | return EGL_NOT_INITIALIZED; |
| 257 | } |
| 258 | |
| 259 | // When DirectX9 is running with an older DirectX8 driver, a StretchRect from a regular texture to a render target texture is not supported. |
| 260 | // This is required by Texture2D::convertToRenderTarget. |
| 261 | if ((mDeviceCaps.DevCaps2 & D3DDEVCAPS2_CAN_STRETCHRECT_FROM_TEXTURES) == 0) |
| 262 | { |
| 263 | ERR("Renderer does not support stretctrect from textures!\n"); |
| 264 | return EGL_NOT_INITIALIZED; |
| 265 | } |
| 266 | |
| 267 | mD3d9->GetAdapterIdentifier(mAdapter, 0, &mAdapterIdentifier); |
| 268 | |
| 269 | // ATI cards on XP have problems with non-power-of-two textures. |
| 270 | mSupportsNonPower2Textures = !(mDeviceCaps.TextureCaps & D3DPTEXTURECAPS_POW2) && |
| 271 | !(mDeviceCaps.TextureCaps & D3DPTEXTURECAPS_CUBEMAP_POW2) && |
| 272 | !(mDeviceCaps.TextureCaps & D3DPTEXTURECAPS_NONPOW2CONDITIONAL) && |
| 273 | !(getComparableOSVersion() < versionWindowsVista && mAdapterIdentifier.VendorId == VENDOR_ID_AMD); |
| 274 | |
daniel@transgaming.com | ba0570e | 2012-10-31 18:07:39 +0000 | [diff] [blame] | 275 | // Must support a minimum of 2:1 anisotropy for max anisotropy to be considered supported, per the spec |
| 276 | mSupportsTextureFilterAnisotropy = ((mDeviceCaps.RasterCaps & D3DPRASTERCAPS_ANISOTROPY) && (mDeviceCaps.MaxAnisotropy >= 2)); |
| 277 | |
daniel@transgaming.com | 5f4c136 | 2012-10-31 18:29:00 +0000 | [diff] [blame] | 278 | mMinSwapInterval = 4; |
| 279 | mMaxSwapInterval = 0; |
| 280 | |
| 281 | if (mDeviceCaps.PresentationIntervals & D3DPRESENT_INTERVAL_IMMEDIATE) |
| 282 | { |
| 283 | mMinSwapInterval = std::min(mMinSwapInterval, 0); |
| 284 | mMaxSwapInterval = std::max(mMaxSwapInterval, 0); |
| 285 | } |
| 286 | if (mDeviceCaps.PresentationIntervals & D3DPRESENT_INTERVAL_ONE) |
| 287 | { |
| 288 | mMinSwapInterval = std::min(mMinSwapInterval, 1); |
| 289 | mMaxSwapInterval = std::max(mMaxSwapInterval, 1); |
| 290 | } |
| 291 | if (mDeviceCaps.PresentationIntervals & D3DPRESENT_INTERVAL_TWO) |
| 292 | { |
| 293 | mMinSwapInterval = std::min(mMinSwapInterval, 2); |
| 294 | mMaxSwapInterval = std::max(mMaxSwapInterval, 2); |
| 295 | } |
| 296 | if (mDeviceCaps.PresentationIntervals & D3DPRESENT_INTERVAL_THREE) |
| 297 | { |
| 298 | mMinSwapInterval = std::min(mMinSwapInterval, 3); |
| 299 | mMaxSwapInterval = std::max(mMaxSwapInterval, 3); |
| 300 | } |
| 301 | if (mDeviceCaps.PresentationIntervals & D3DPRESENT_INTERVAL_FOUR) |
| 302 | { |
| 303 | mMinSwapInterval = std::min(mMinSwapInterval, 4); |
| 304 | mMaxSwapInterval = std::max(mMaxSwapInterval, 4); |
| 305 | } |
| 306 | |
Geoff Lang | 61e49a5 | 2013-05-29 10:22:58 -0400 | [diff] [blame] | 307 | mMaxSupportedSamples = 0; |
| 308 | |
| 309 | const d3d9::D3DFormatSet &d3d9Formats = d3d9::GetAllUsedD3DFormats(); |
| 310 | for (d3d9::D3DFormatSet::const_iterator i = d3d9Formats.begin(); i != d3d9Formats.end(); ++i) |
daniel@transgaming.com | b783398 | 2012-10-31 18:31:46 +0000 | [diff] [blame] | 311 | { |
Geoff Lang | 61e49a5 | 2013-05-29 10:22:58 -0400 | [diff] [blame] | 312 | MultisampleSupportInfo support = getMultiSampleSupport(*i); |
| 313 | mMultiSampleSupport[*i] = support; |
| 314 | mMaxSupportedSamples = std::max(mMaxSupportedSamples, support.maxSupportedSamples); |
daniel@transgaming.com | 9295562 | 2012-10-31 18:38:41 +0000 | [diff] [blame] | 315 | } |
| 316 | |
daniel@transgaming.com | 621ce05 | 2012-10-31 17:52:29 +0000 | [diff] [blame] | 317 | static const TCHAR windowName[] = TEXT("AngleHiddenWindow"); |
| 318 | static const TCHAR className[] = TEXT("STATIC"); |
| 319 | |
| 320 | mDeviceWindow = CreateWindowEx(WS_EX_NOACTIVATE, className, windowName, WS_DISABLED | WS_POPUP, 0, 0, 1, 1, HWND_MESSAGE, NULL, GetModuleHandle(NULL), NULL); |
| 321 | |
| 322 | D3DPRESENT_PARAMETERS presentParameters = getDefaultPresentParameters(); |
| 323 | DWORD behaviorFlags = D3DCREATE_FPU_PRESERVE | D3DCREATE_NOWINDOWCHANGES; |
| 324 | |
| 325 | result = mD3d9->CreateDevice(mAdapter, mDeviceType, mDeviceWindow, behaviorFlags | D3DCREATE_HARDWARE_VERTEXPROCESSING | D3DCREATE_PUREDEVICE, &presentParameters, &mDevice); |
| 326 | if (result == D3DERR_OUTOFVIDEOMEMORY || result == E_OUTOFMEMORY || result == D3DERR_DEVICELOST) |
| 327 | { |
| 328 | return EGL_BAD_ALLOC; |
| 329 | } |
| 330 | |
| 331 | if (FAILED(result)) |
| 332 | { |
| 333 | result = mD3d9->CreateDevice(mAdapter, mDeviceType, mDeviceWindow, behaviorFlags | D3DCREATE_SOFTWARE_VERTEXPROCESSING, &presentParameters, &mDevice); |
| 334 | |
| 335 | if (FAILED(result)) |
| 336 | { |
| 337 | ASSERT(result == D3DERR_OUTOFVIDEOMEMORY || result == E_OUTOFMEMORY || result == D3DERR_NOTAVAILABLE || result == D3DERR_DEVICELOST); |
| 338 | return EGL_BAD_ALLOC; |
| 339 | } |
| 340 | } |
| 341 | |
| 342 | if (mD3d9Ex) |
| 343 | { |
| 344 | result = mDevice->QueryInterface(IID_IDirect3DDevice9Ex, (void**) &mDeviceEx); |
| 345 | ASSERT(SUCCEEDED(result)); |
| 346 | } |
| 347 | |
daniel@transgaming.com | e4733d7 | 2012-10-31 18:07:01 +0000 | [diff] [blame] | 348 | mVertexShaderCache.initialize(mDevice); |
| 349 | mPixelShaderCache.initialize(mDevice); |
| 350 | |
daniel@transgaming.com | 669c995 | 2013-01-11 04:08:16 +0000 | [diff] [blame] | 351 | // Check occlusion query support |
| 352 | IDirect3DQuery9 *occlusionQuery = NULL; |
| 353 | if (SUCCEEDED(mDevice->CreateQuery(D3DQUERYTYPE_OCCLUSION, &occlusionQuery)) && occlusionQuery) |
| 354 | { |
| 355 | occlusionQuery->Release(); |
| 356 | mOcclusionQuerySupport = true; |
| 357 | } |
| 358 | else |
| 359 | { |
| 360 | mOcclusionQuerySupport = false; |
| 361 | } |
| 362 | |
| 363 | // Check event query support |
| 364 | IDirect3DQuery9 *eventQuery = NULL; |
| 365 | if (SUCCEEDED(mDevice->CreateQuery(D3DQUERYTYPE_EVENT, &eventQuery)) && eventQuery) |
| 366 | { |
| 367 | eventQuery->Release(); |
| 368 | mEventQuerySupport = true; |
| 369 | } |
| 370 | else |
| 371 | { |
| 372 | mEventQuerySupport = false; |
| 373 | } |
| 374 | |
| 375 | D3DDISPLAYMODE currentDisplayMode; |
| 376 | mD3d9->GetAdapterDisplayMode(mAdapter, ¤tDisplayMode); |
| 377 | |
| 378 | // Check vertex texture support |
| 379 | // Only Direct3D 10 ready devices support all the necessary vertex texture formats. |
| 380 | // We test this using D3D9 by checking support for the R16F format. |
| 381 | mVertexTextureSupport = mDeviceCaps.PixelShaderVersion >= D3DPS_VERSION(3, 0) && |
| 382 | SUCCEEDED(mD3d9->CheckDeviceFormat(mAdapter, mDeviceType, currentDisplayMode.Format, |
| 383 | D3DUSAGE_QUERY_VERTEXTEXTURE, D3DRTYPE_TEXTURE, D3DFMT_R16F)); |
| 384 | |
Geoff Lang | d42cf4e | 2013-06-05 16:09:17 -0400 | [diff] [blame] | 385 | // Check RGB565 texture support |
| 386 | mRGB565TextureSupport = SUCCEEDED(mD3d9->CheckDeviceFormat(mAdapter, mDeviceType, currentDisplayMode.Format, |
| 387 | D3DUSAGE_RENDERTARGET, D3DRTYPE_TEXTURE, D3DFMT_R5G6B5)); |
| 388 | |
daniel@transgaming.com | 669c995 | 2013-01-11 04:08:16 +0000 | [diff] [blame] | 389 | // Check depth texture support |
| 390 | // we use INTZ for depth textures in Direct3D9 |
| 391 | // we also want NULL texture support to ensure the we can make depth-only FBOs |
| 392 | // see http://aras-p.info/texts/D3D9GPUHacks.html |
| 393 | mDepthTextureSupport = SUCCEEDED(mD3d9->CheckDeviceFormat(mAdapter, mDeviceType, currentDisplayMode.Format, |
| 394 | D3DUSAGE_DEPTHSTENCIL, D3DRTYPE_TEXTURE, D3DFMT_INTZ)) && |
| 395 | SUCCEEDED(mD3d9->CheckDeviceFormat(mAdapter, mDeviceType, currentDisplayMode.Format, |
| 396 | D3DUSAGE_RENDERTARGET, D3DRTYPE_SURFACE, D3DFMT_NULL)); |
| 397 | |
| 398 | // Check 32 bit floating point texture support |
| 399 | mFloat32FilterSupport = SUCCEEDED(mD3d9->CheckDeviceFormat(mAdapter, mDeviceType, currentDisplayMode.Format, D3DUSAGE_QUERY_FILTER, |
| 400 | D3DRTYPE_TEXTURE, D3DFMT_A32B32G32R32F)) && |
| 401 | SUCCEEDED(mD3d9->CheckDeviceFormat(mAdapter, mDeviceType, currentDisplayMode.Format, D3DUSAGE_QUERY_FILTER, |
| 402 | D3DRTYPE_CUBETEXTURE, D3DFMT_A32B32G32R32F)); |
| 403 | |
| 404 | mFloat32RenderSupport = SUCCEEDED(mD3d9->CheckDeviceFormat(mAdapter, mDeviceType, currentDisplayMode.Format, D3DUSAGE_RENDERTARGET, |
| 405 | D3DRTYPE_TEXTURE, D3DFMT_A32B32G32R32F)) && |
| 406 | SUCCEEDED(mD3d9->CheckDeviceFormat(mAdapter, mDeviceType, currentDisplayMode.Format, D3DUSAGE_RENDERTARGET, |
| 407 | D3DRTYPE_CUBETEXTURE, D3DFMT_A32B32G32R32F)); |
| 408 | |
| 409 | if (!mFloat32FilterSupport && !mFloat32RenderSupport) |
| 410 | { |
| 411 | mFloat32TextureSupport = SUCCEEDED(mD3d9->CheckDeviceFormat(mAdapter, mDeviceType, currentDisplayMode.Format, 0, |
| 412 | D3DRTYPE_TEXTURE, D3DFMT_A32B32G32R32F)) && |
| 413 | SUCCEEDED(mD3d9->CheckDeviceFormat(mAdapter, mDeviceType, currentDisplayMode.Format, 0, |
| 414 | D3DRTYPE_CUBETEXTURE, D3DFMT_A32B32G32R32F)); |
| 415 | } |
| 416 | else |
| 417 | { |
| 418 | mFloat32TextureSupport = true; |
| 419 | } |
| 420 | |
| 421 | // Check 16 bit floating point texture support |
| 422 | mFloat16FilterSupport = SUCCEEDED(mD3d9->CheckDeviceFormat(mAdapter, mDeviceType, currentDisplayMode.Format, D3DUSAGE_QUERY_FILTER, |
| 423 | D3DRTYPE_TEXTURE, D3DFMT_A16B16G16R16F)) && |
| 424 | SUCCEEDED(mD3d9->CheckDeviceFormat(mAdapter, mDeviceType, currentDisplayMode.Format, D3DUSAGE_QUERY_FILTER, |
| 425 | D3DRTYPE_CUBETEXTURE, D3DFMT_A16B16G16R16F)); |
| 426 | |
| 427 | mFloat16RenderSupport = SUCCEEDED(mD3d9->CheckDeviceFormat(mAdapter, mDeviceType, currentDisplayMode.Format, D3DUSAGE_RENDERTARGET, |
| 428 | D3DRTYPE_TEXTURE, D3DFMT_A16B16G16R16F)) && |
| 429 | SUCCEEDED(mD3d9->CheckDeviceFormat(mAdapter, mDeviceType, currentDisplayMode.Format, D3DUSAGE_RENDERTARGET, |
| 430 | D3DRTYPE_CUBETEXTURE, D3DFMT_A16B16G16R16F)); |
| 431 | |
| 432 | if (!mFloat16FilterSupport && !mFloat16RenderSupport) |
| 433 | { |
| 434 | mFloat16TextureSupport = SUCCEEDED(mD3d9->CheckDeviceFormat(mAdapter, mDeviceType, currentDisplayMode.Format, 0, |
| 435 | D3DRTYPE_TEXTURE, D3DFMT_A16B16G16R16F)) && |
| 436 | SUCCEEDED(mD3d9->CheckDeviceFormat(mAdapter, mDeviceType, currentDisplayMode.Format, 0, |
| 437 | D3DRTYPE_CUBETEXTURE, D3DFMT_A16B16G16R16F)); |
| 438 | } |
| 439 | else |
| 440 | { |
| 441 | mFloat16TextureSupport = true; |
| 442 | } |
| 443 | |
| 444 | // Check DXT texture support |
| 445 | mDXT1TextureSupport = SUCCEEDED(mD3d9->CheckDeviceFormat(mAdapter, mDeviceType, currentDisplayMode.Format, 0, D3DRTYPE_TEXTURE, D3DFMT_DXT1)); |
| 446 | mDXT3TextureSupport = SUCCEEDED(mD3d9->CheckDeviceFormat(mAdapter, mDeviceType, currentDisplayMode.Format, 0, D3DRTYPE_TEXTURE, D3DFMT_DXT3)); |
| 447 | mDXT5TextureSupport = SUCCEEDED(mD3d9->CheckDeviceFormat(mAdapter, mDeviceType, currentDisplayMode.Format, 0, D3DRTYPE_TEXTURE, D3DFMT_DXT5)); |
| 448 | |
| 449 | // Check luminance[alpha] texture support |
| 450 | mLuminanceTextureSupport = SUCCEEDED(mD3d9->CheckDeviceFormat(mAdapter, mDeviceType, currentDisplayMode.Format, 0, D3DRTYPE_TEXTURE, D3DFMT_L8)); |
| 451 | mLuminanceAlphaTextureSupport = SUCCEEDED(mD3d9->CheckDeviceFormat(mAdapter, mDeviceType, currentDisplayMode.Format, 0, D3DRTYPE_TEXTURE, D3DFMT_A8L8)); |
| 452 | |
daniel@transgaming.com | 621ce05 | 2012-10-31 17:52:29 +0000 | [diff] [blame] | 453 | initializeDevice(); |
| 454 | |
| 455 | return EGL_SUCCESS; |
| 456 | } |
| 457 | |
| 458 | // do any one-time device initialization |
| 459 | // NOTE: this is also needed after a device lost/reset |
| 460 | // to reset the scene status and ensure the default states are reset. |
daniel@transgaming.com | 2507f41 | 2012-10-31 18:46:48 +0000 | [diff] [blame] | 461 | void Renderer9::initializeDevice() |
daniel@transgaming.com | 621ce05 | 2012-10-31 17:52:29 +0000 | [diff] [blame] | 462 | { |
| 463 | // Permanent non-default states |
| 464 | mDevice->SetRenderState(D3DRS_POINTSPRITEENABLE, TRUE); |
| 465 | mDevice->SetRenderState(D3DRS_LASTPIXEL, FALSE); |
| 466 | |
| 467 | if (mDeviceCaps.PixelShaderVersion >= D3DPS_VERSION(3, 0)) |
| 468 | { |
| 469 | mDevice->SetRenderState(D3DRS_POINTSIZE_MAX, (DWORD&)mDeviceCaps.MaxPointSize); |
| 470 | } |
| 471 | else |
| 472 | { |
| 473 | mDevice->SetRenderState(D3DRS_POINTSIZE_MAX, 0x3F800000); // 1.0f |
| 474 | } |
| 475 | |
daniel@transgaming.com | c43a605 | 2012-11-28 19:41:51 +0000 | [diff] [blame] | 476 | markAllStateDirty(); |
| 477 | |
daniel@transgaming.com | 621ce05 | 2012-10-31 17:52:29 +0000 | [diff] [blame] | 478 | mSceneStarted = false; |
daniel@transgaming.com | 67094ee | 2012-11-28 20:53:04 +0000 | [diff] [blame] | 479 | |
daniel@transgaming.com | 91207b7 | 2012-11-28 20:56:43 +0000 | [diff] [blame] | 480 | ASSERT(!mBlit && !mVertexDataManager && !mIndexDataManager); |
Geoff Lang | dce735c | 2013-06-04 10:21:18 -0400 | [diff] [blame] | 481 | mBlit = new Blit9(this); |
daniel@transgaming.com | 3124048 | 2012-11-28 21:06:41 +0000 | [diff] [blame] | 482 | mVertexDataManager = new rx::VertexDataManager(this); |
| 483 | mIndexDataManager = new rx::IndexDataManager(this); |
daniel@transgaming.com | 621ce05 | 2012-10-31 17:52:29 +0000 | [diff] [blame] | 484 | } |
| 485 | |
daniel@transgaming.com | 2507f41 | 2012-10-31 18:46:48 +0000 | [diff] [blame] | 486 | D3DPRESENT_PARAMETERS Renderer9::getDefaultPresentParameters() |
daniel@transgaming.com | 621ce05 | 2012-10-31 17:52:29 +0000 | [diff] [blame] | 487 | { |
| 488 | D3DPRESENT_PARAMETERS presentParameters = {0}; |
| 489 | |
| 490 | // The default swap chain is never actually used. Surface will create a new swap chain with the proper parameters. |
| 491 | presentParameters.AutoDepthStencilFormat = D3DFMT_UNKNOWN; |
| 492 | presentParameters.BackBufferCount = 1; |
| 493 | presentParameters.BackBufferFormat = D3DFMT_UNKNOWN; |
| 494 | presentParameters.BackBufferWidth = 1; |
| 495 | presentParameters.BackBufferHeight = 1; |
| 496 | presentParameters.EnableAutoDepthStencil = FALSE; |
| 497 | presentParameters.Flags = 0; |
| 498 | presentParameters.hDeviceWindow = mDeviceWindow; |
| 499 | presentParameters.MultiSampleQuality = 0; |
| 500 | presentParameters.MultiSampleType = D3DMULTISAMPLE_NONE; |
| 501 | presentParameters.PresentationInterval = D3DPRESENT_INTERVAL_DEFAULT; |
| 502 | presentParameters.SwapEffect = D3DSWAPEFFECT_DISCARD; |
| 503 | presentParameters.Windowed = TRUE; |
| 504 | |
| 505 | return presentParameters; |
| 506 | } |
| 507 | |
daniel@transgaming.com | 2507f41 | 2012-10-31 18:46:48 +0000 | [diff] [blame] | 508 | int Renderer9::generateConfigs(ConfigDesc **configDescList) |
daniel@transgaming.com | 3281f97 | 2012-10-31 18:38:51 +0000 | [diff] [blame] | 509 | { |
| 510 | D3DDISPLAYMODE currentDisplayMode; |
| 511 | mD3d9->GetAdapterDisplayMode(mAdapter, ¤tDisplayMode); |
| 512 | |
shannon.woods@transgaming.com | d438fd4 | 2013-02-28 23:17:45 +0000 | [diff] [blame] | 513 | unsigned int numRenderFormats = ArraySize(RenderTargetFormats); |
| 514 | unsigned int numDepthFormats = ArraySize(DepthStencilFormats); |
daniel@transgaming.com | 3281f97 | 2012-10-31 18:38:51 +0000 | [diff] [blame] | 515 | (*configDescList) = new ConfigDesc[numRenderFormats * numDepthFormats]; |
| 516 | int numConfigs = 0; |
| 517 | |
daniel@transgaming.com | e3e826d | 2012-11-28 19:42:35 +0000 | [diff] [blame] | 518 | for (unsigned int formatIndex = 0; formatIndex < numRenderFormats; formatIndex++) |
daniel@transgaming.com | 3281f97 | 2012-10-31 18:38:51 +0000 | [diff] [blame] | 519 | { |
daniel@transgaming.com | 222ee08 | 2012-11-28 19:31:49 +0000 | [diff] [blame] | 520 | D3DFORMAT renderTargetFormat = RenderTargetFormats[formatIndex]; |
daniel@transgaming.com | 3281f97 | 2012-10-31 18:38:51 +0000 | [diff] [blame] | 521 | |
| 522 | HRESULT result = mD3d9->CheckDeviceFormat(mAdapter, mDeviceType, currentDisplayMode.Format, D3DUSAGE_RENDERTARGET, D3DRTYPE_SURFACE, renderTargetFormat); |
| 523 | |
| 524 | if (SUCCEEDED(result)) |
| 525 | { |
daniel@transgaming.com | e3e826d | 2012-11-28 19:42:35 +0000 | [diff] [blame] | 526 | for (unsigned int depthStencilIndex = 0; depthStencilIndex < numDepthFormats; depthStencilIndex++) |
daniel@transgaming.com | 3281f97 | 2012-10-31 18:38:51 +0000 | [diff] [blame] | 527 | { |
daniel@transgaming.com | 222ee08 | 2012-11-28 19:31:49 +0000 | [diff] [blame] | 528 | D3DFORMAT depthStencilFormat = DepthStencilFormats[depthStencilIndex]; |
daniel@transgaming.com | 3281f97 | 2012-10-31 18:38:51 +0000 | [diff] [blame] | 529 | HRESULT result = D3D_OK; |
| 530 | |
| 531 | if(depthStencilFormat != D3DFMT_UNKNOWN) |
| 532 | { |
| 533 | result = mD3d9->CheckDeviceFormat(mAdapter, mDeviceType, currentDisplayMode.Format, D3DUSAGE_DEPTHSTENCIL, D3DRTYPE_SURFACE, depthStencilFormat); |
| 534 | } |
| 535 | |
| 536 | if (SUCCEEDED(result)) |
| 537 | { |
| 538 | if(depthStencilFormat != D3DFMT_UNKNOWN) |
| 539 | { |
| 540 | result = mD3d9->CheckDepthStencilMatch(mAdapter, mDeviceType, currentDisplayMode.Format, renderTargetFormat, depthStencilFormat); |
| 541 | } |
| 542 | |
| 543 | if (SUCCEEDED(result)) |
| 544 | { |
| 545 | ConfigDesc newConfig; |
shannonwoods@chromium.org | 755012f | 2013-05-30 00:09:32 +0000 | [diff] [blame] | 546 | newConfig.renderTargetFormat = d3d9_gl::GetInternalFormat(renderTargetFormat); |
| 547 | newConfig.depthStencilFormat = d3d9_gl::GetInternalFormat(depthStencilFormat); |
daniel@transgaming.com | 3281f97 | 2012-10-31 18:38:51 +0000 | [diff] [blame] | 548 | newConfig.multiSample = 0; // FIXME: enumerate multi-sampling |
| 549 | newConfig.fastConfig = (currentDisplayMode.Format == renderTargetFormat); |
shannon.woods%transgaming.com@gtempaccount.com | dcf33d5 | 2013-04-13 03:33:11 +0000 | [diff] [blame] | 550 | newConfig.es3Capable = false; |
daniel@transgaming.com | 3281f97 | 2012-10-31 18:38:51 +0000 | [diff] [blame] | 551 | |
| 552 | (*configDescList)[numConfigs++] = newConfig; |
| 553 | } |
| 554 | } |
| 555 | } |
| 556 | } |
| 557 | } |
| 558 | |
| 559 | return numConfigs; |
| 560 | } |
| 561 | |
daniel@transgaming.com | 2507f41 | 2012-10-31 18:46:48 +0000 | [diff] [blame] | 562 | void Renderer9::deleteConfigs(ConfigDesc *configDescList) |
daniel@transgaming.com | 3281f97 | 2012-10-31 18:38:51 +0000 | [diff] [blame] | 563 | { |
| 564 | delete [] (configDescList); |
| 565 | } |
| 566 | |
daniel@transgaming.com | 2507f41 | 2012-10-31 18:46:48 +0000 | [diff] [blame] | 567 | void Renderer9::startScene() |
daniel@transgaming.com | 621ce05 | 2012-10-31 17:52:29 +0000 | [diff] [blame] | 568 | { |
| 569 | if (!mSceneStarted) |
| 570 | { |
| 571 | long result = mDevice->BeginScene(); |
| 572 | if (SUCCEEDED(result)) { |
| 573 | // This is defensive checking against the device being |
| 574 | // lost at unexpected times. |
| 575 | mSceneStarted = true; |
| 576 | } |
| 577 | } |
| 578 | } |
| 579 | |
daniel@transgaming.com | 2507f41 | 2012-10-31 18:46:48 +0000 | [diff] [blame] | 580 | void Renderer9::endScene() |
daniel@transgaming.com | 621ce05 | 2012-10-31 17:52:29 +0000 | [diff] [blame] | 581 | { |
| 582 | if (mSceneStarted) |
| 583 | { |
| 584 | // EndScene can fail if the device was lost, for example due |
| 585 | // to a TDR during a draw call. |
| 586 | mDevice->EndScene(); |
| 587 | mSceneStarted = false; |
| 588 | } |
| 589 | } |
| 590 | |
daniel@transgaming.com | 2507f41 | 2012-10-31 18:46:48 +0000 | [diff] [blame] | 591 | void Renderer9::sync(bool block) |
daniel@transgaming.com | ef21ab2 | 2012-10-31 17:52:47 +0000 | [diff] [blame] | 592 | { |
| 593 | HRESULT result; |
| 594 | |
| 595 | IDirect3DQuery9* query = allocateEventQuery(); |
| 596 | if (!query) |
| 597 | { |
| 598 | return; |
| 599 | } |
| 600 | |
| 601 | result = query->Issue(D3DISSUE_END); |
| 602 | ASSERT(SUCCEEDED(result)); |
| 603 | |
| 604 | do |
| 605 | { |
| 606 | result = query->GetData(NULL, 0, D3DGETDATA_FLUSH); |
| 607 | |
| 608 | if(block && result == S_FALSE) |
| 609 | { |
| 610 | // Keep polling, but allow other threads to do something useful first |
| 611 | Sleep(0); |
| 612 | // explicitly check for device loss |
| 613 | // some drivers seem to return S_FALSE even if the device is lost |
| 614 | // instead of D3DERR_DEVICELOST like they should |
daniel@transgaming.com | f688c0d | 2012-10-31 17:52:57 +0000 | [diff] [blame] | 615 | if (testDeviceLost(false)) |
daniel@transgaming.com | ef21ab2 | 2012-10-31 17:52:47 +0000 | [diff] [blame] | 616 | { |
| 617 | result = D3DERR_DEVICELOST; |
| 618 | } |
| 619 | } |
| 620 | } |
| 621 | while(block && result == S_FALSE); |
| 622 | |
| 623 | freeEventQuery(query); |
| 624 | |
shannon.woods@transgaming.com | f5f5949 | 2013-02-28 23:04:40 +0000 | [diff] [blame] | 625 | if (d3d9::isDeviceLostError(result)) |
daniel@transgaming.com | ef21ab2 | 2012-10-31 17:52:47 +0000 | [diff] [blame] | 626 | { |
shannon.woods@transgaming.com | eb049e2 | 2013-02-28 23:04:49 +0000 | [diff] [blame] | 627 | notifyDeviceLost(); |
daniel@transgaming.com | ef21ab2 | 2012-10-31 17:52:47 +0000 | [diff] [blame] | 628 | } |
| 629 | } |
| 630 | |
daniel@transgaming.com | b9bb279 | 2012-11-28 19:36:49 +0000 | [diff] [blame] | 631 | SwapChain *Renderer9::createSwapChain(HWND window, HANDLE shareHandle, GLenum backBufferFormat, GLenum depthBufferFormat) |
| 632 | { |
daniel@transgaming.com | a27e05b | 2012-11-28 19:39:42 +0000 | [diff] [blame] | 633 | return new rx::SwapChain9(this, window, shareHandle, backBufferFormat, depthBufferFormat); |
daniel@transgaming.com | b9bb279 | 2012-11-28 19:36:49 +0000 | [diff] [blame] | 634 | } |
| 635 | |
daniel@transgaming.com | 2507f41 | 2012-10-31 18:46:48 +0000 | [diff] [blame] | 636 | IDirect3DQuery9* Renderer9::allocateEventQuery() |
daniel@transgaming.com | ef21ab2 | 2012-10-31 17:52:47 +0000 | [diff] [blame] | 637 | { |
| 638 | IDirect3DQuery9 *query = NULL; |
| 639 | |
| 640 | if (mEventQueryPool.empty()) |
| 641 | { |
| 642 | HRESULT result = mDevice->CreateQuery(D3DQUERYTYPE_EVENT, &query); |
| 643 | ASSERT(SUCCEEDED(result)); |
| 644 | } |
| 645 | else |
| 646 | { |
| 647 | query = mEventQueryPool.back(); |
| 648 | mEventQueryPool.pop_back(); |
| 649 | } |
| 650 | |
| 651 | return query; |
| 652 | } |
| 653 | |
daniel@transgaming.com | 2507f41 | 2012-10-31 18:46:48 +0000 | [diff] [blame] | 654 | void Renderer9::freeEventQuery(IDirect3DQuery9* query) |
daniel@transgaming.com | ef21ab2 | 2012-10-31 17:52:47 +0000 | [diff] [blame] | 655 | { |
| 656 | if (mEventQueryPool.size() > 1000) |
| 657 | { |
| 658 | query->Release(); |
| 659 | } |
| 660 | else |
| 661 | { |
| 662 | mEventQueryPool.push_back(query); |
| 663 | } |
| 664 | } |
| 665 | |
daniel@transgaming.com | 2507f41 | 2012-10-31 18:46:48 +0000 | [diff] [blame] | 666 | IDirect3DVertexShader9 *Renderer9::createVertexShader(const DWORD *function, size_t length) |
daniel@transgaming.com | e4733d7 | 2012-10-31 18:07:01 +0000 | [diff] [blame] | 667 | { |
| 668 | return mVertexShaderCache.create(function, length); |
| 669 | } |
| 670 | |
daniel@transgaming.com | 2507f41 | 2012-10-31 18:46:48 +0000 | [diff] [blame] | 671 | IDirect3DPixelShader9 *Renderer9::createPixelShader(const DWORD *function, size_t length) |
daniel@transgaming.com | e4733d7 | 2012-10-31 18:07:01 +0000 | [diff] [blame] | 672 | { |
| 673 | return mPixelShaderCache.create(function, length); |
| 674 | } |
| 675 | |
daniel@transgaming.com | 113f0eb | 2012-10-31 18:46:58 +0000 | [diff] [blame] | 676 | HRESULT Renderer9::createVertexBuffer(UINT Length, DWORD Usage, IDirect3DVertexBuffer9 **ppVertexBuffer) |
| 677 | { |
| 678 | D3DPOOL Pool = getBufferPool(Usage); |
| 679 | return mDevice->CreateVertexBuffer(Length, Usage, 0, Pool, ppVertexBuffer, NULL); |
| 680 | } |
| 681 | |
daniel@transgaming.com | 3f255b4 | 2012-12-20 21:07:35 +0000 | [diff] [blame] | 682 | VertexBuffer *Renderer9::createVertexBuffer() |
| 683 | { |
| 684 | return new VertexBuffer9(this); |
| 685 | } |
| 686 | |
daniel@transgaming.com | 113f0eb | 2012-10-31 18:46:58 +0000 | [diff] [blame] | 687 | HRESULT Renderer9::createIndexBuffer(UINT Length, DWORD Usage, D3DFORMAT Format, IDirect3DIndexBuffer9 **ppIndexBuffer) |
| 688 | { |
| 689 | D3DPOOL Pool = getBufferPool(Usage); |
| 690 | return mDevice->CreateIndexBuffer(Length, Usage, Format, Pool, ppIndexBuffer, NULL); |
| 691 | } |
daniel@transgaming.com | ba0570e | 2012-10-31 18:07:39 +0000 | [diff] [blame] | 692 | |
daniel@transgaming.com | 0b6d774 | 2012-12-20 21:09:47 +0000 | [diff] [blame] | 693 | IndexBuffer *Renderer9::createIndexBuffer() |
| 694 | { |
| 695 | return new IndexBuffer9(this); |
| 696 | } |
| 697 | |
shannon.woods@transgaming.com | 4e52b63 | 2013-02-28 23:08:01 +0000 | [diff] [blame] | 698 | BufferStorage *Renderer9::createBufferStorage() |
| 699 | { |
| 700 | return new BufferStorage9(); |
| 701 | } |
| 702 | |
shannon.woods@transgaming.com | 50df6c5 | 2013-02-28 23:02:49 +0000 | [diff] [blame] | 703 | QueryImpl *Renderer9::createQuery(GLenum type) |
| 704 | { |
| 705 | return new Query9(this, type); |
| 706 | } |
| 707 | |
shannon.woods@transgaming.com | cfe787e | 2013-02-28 23:03:35 +0000 | [diff] [blame] | 708 | FenceImpl *Renderer9::createFence() |
| 709 | { |
| 710 | return new Fence9(this); |
| 711 | } |
| 712 | |
daniel@transgaming.com | 2507f41 | 2012-10-31 18:46:48 +0000 | [diff] [blame] | 713 | void Renderer9::setSamplerState(gl::SamplerType type, int index, const gl::SamplerState &samplerState) |
daniel@transgaming.com | ba0570e | 2012-10-31 18:07:39 +0000 | [diff] [blame] | 714 | { |
daniel@transgaming.com | e33c8bf | 2013-01-11 04:11:33 +0000 | [diff] [blame] | 715 | bool *forceSetSamplers = (type == gl::SAMPLER_PIXEL) ? mForceSetPixelSamplerStates : mForceSetVertexSamplerStates; |
| 716 | gl::SamplerState *appliedSamplers = (type == gl::SAMPLER_PIXEL) ? mCurPixelSamplerStates: mCurVertexSamplerStates; |
daniel@transgaming.com | ba0570e | 2012-10-31 18:07:39 +0000 | [diff] [blame] | 717 | |
daniel@transgaming.com | e33c8bf | 2013-01-11 04:11:33 +0000 | [diff] [blame] | 718 | if (forceSetSamplers[index] || memcmp(&samplerState, &appliedSamplers[index], sizeof(gl::SamplerState)) != 0) |
daniel@transgaming.com | ba0570e | 2012-10-31 18:07:39 +0000 | [diff] [blame] | 719 | { |
daniel@transgaming.com | e33c8bf | 2013-01-11 04:11:33 +0000 | [diff] [blame] | 720 | int d3dSamplerOffset = (type == gl::SAMPLER_PIXEL) ? 0 : D3DVERTEXTEXTURESAMPLER0; |
| 721 | int d3dSampler = index + d3dSamplerOffset; |
| 722 | |
| 723 | mDevice->SetSamplerState(d3dSampler, D3DSAMP_ADDRESSU, gl_d3d9::ConvertTextureWrap(samplerState.wrapS)); |
| 724 | mDevice->SetSamplerState(d3dSampler, D3DSAMP_ADDRESSV, gl_d3d9::ConvertTextureWrap(samplerState.wrapT)); |
| 725 | |
| 726 | mDevice->SetSamplerState(d3dSampler, D3DSAMP_MAGFILTER, gl_d3d9::ConvertMagFilter(samplerState.magFilter, samplerState.maxAnisotropy)); |
| 727 | D3DTEXTUREFILTERTYPE d3dMinFilter, d3dMipFilter; |
| 728 | gl_d3d9::ConvertMinFilter(samplerState.minFilter, &d3dMinFilter, &d3dMipFilter, samplerState.maxAnisotropy); |
| 729 | mDevice->SetSamplerState(d3dSampler, D3DSAMP_MINFILTER, d3dMinFilter); |
| 730 | mDevice->SetSamplerState(d3dSampler, D3DSAMP_MIPFILTER, d3dMipFilter); |
| 731 | mDevice->SetSamplerState(d3dSampler, D3DSAMP_MAXMIPLEVEL, samplerState.lodOffset); |
| 732 | if (mSupportsTextureFilterAnisotropy) |
| 733 | { |
| 734 | mDevice->SetSamplerState(d3dSampler, D3DSAMP_MAXANISOTROPY, (DWORD)samplerState.maxAnisotropy); |
| 735 | } |
daniel@transgaming.com | ba0570e | 2012-10-31 18:07:39 +0000 | [diff] [blame] | 736 | } |
daniel@transgaming.com | e33c8bf | 2013-01-11 04:11:33 +0000 | [diff] [blame] | 737 | |
| 738 | forceSetSamplers[index] = false; |
| 739 | appliedSamplers[index] = samplerState; |
daniel@transgaming.com | ba0570e | 2012-10-31 18:07:39 +0000 | [diff] [blame] | 740 | } |
| 741 | |
daniel@transgaming.com | 2507f41 | 2012-10-31 18:46:48 +0000 | [diff] [blame] | 742 | void Renderer9::setTexture(gl::SamplerType type, int index, gl::Texture *texture) |
daniel@transgaming.com | a734f27 | 2012-10-31 18:07:48 +0000 | [diff] [blame] | 743 | { |
| 744 | int d3dSamplerOffset = (type == gl::SAMPLER_PIXEL) ? 0 : D3DVERTEXTEXTURESAMPLER0; |
| 745 | int d3dSampler = index + d3dSamplerOffset; |
| 746 | IDirect3DBaseTexture9 *d3dTexture = NULL; |
daniel@transgaming.com | e33c8bf | 2013-01-11 04:11:33 +0000 | [diff] [blame] | 747 | unsigned int serial = 0; |
| 748 | bool forceSetTexture = false; |
| 749 | |
| 750 | unsigned int *appliedSerials = (type == gl::SAMPLER_PIXEL) ? mCurPixelTextureSerials : mCurVertexTextureSerials; |
daniel@transgaming.com | a734f27 | 2012-10-31 18:07:48 +0000 | [diff] [blame] | 751 | |
| 752 | if (texture) |
| 753 | { |
daniel@transgaming.com | 87705f8 | 2012-12-20 21:10:45 +0000 | [diff] [blame] | 754 | TextureStorageInterface *texStorage = texture->getNativeTexture(); |
daniel@transgaming.com | 9d4346f | 2012-10-31 19:52:04 +0000 | [diff] [blame] | 755 | if (texStorage) |
| 756 | { |
daniel@transgaming.com | 87705f8 | 2012-12-20 21:10:45 +0000 | [diff] [blame] | 757 | TextureStorage9 *storage9 = TextureStorage9::makeTextureStorage9(texStorage->getStorageInstance()); |
daniel@transgaming.com | 34da397 | 2012-12-20 21:10:29 +0000 | [diff] [blame] | 758 | d3dTexture = storage9->getBaseTexture(); |
daniel@transgaming.com | 9d4346f | 2012-10-31 19:52:04 +0000 | [diff] [blame] | 759 | } |
| 760 | // If we get NULL back from getBaseTexture here, something went wrong |
daniel@transgaming.com | a734f27 | 2012-10-31 18:07:48 +0000 | [diff] [blame] | 761 | // in the texture class and we're unexpectedly missing the d3d texture |
| 762 | ASSERT(d3dTexture != NULL); |
daniel@transgaming.com | e33c8bf | 2013-01-11 04:11:33 +0000 | [diff] [blame] | 763 | |
| 764 | serial = texture->getTextureSerial(); |
| 765 | forceSetTexture = texture->hasDirtyImages(); |
daniel@transgaming.com | a734f27 | 2012-10-31 18:07:48 +0000 | [diff] [blame] | 766 | } |
| 767 | |
daniel@transgaming.com | e33c8bf | 2013-01-11 04:11:33 +0000 | [diff] [blame] | 768 | if (forceSetTexture || appliedSerials[index] != serial) |
| 769 | { |
| 770 | mDevice->SetTexture(d3dSampler, d3dTexture); |
| 771 | } |
| 772 | |
| 773 | appliedSerials[index] = serial; |
daniel@transgaming.com | a734f27 | 2012-10-31 18:07:48 +0000 | [diff] [blame] | 774 | } |
| 775 | |
shannonwoods@chromium.org | 1bddfb9 | 2013-05-30 00:11:29 +0000 | [diff] [blame] | 776 | bool Renderer9::setUniformBuffers(const gl::Buffer* /*vertexUniformBuffers*/[], const gl::Buffer* /*fragmentUniformBuffers*/[]) |
| 777 | { |
| 778 | // No effect in ES2/D3D9 |
| 779 | return true; |
| 780 | } |
| 781 | |
daniel@transgaming.com | 237bc7e | 2012-11-28 21:01:06 +0000 | [diff] [blame] | 782 | void Renderer9::setRasterizerState(const gl::RasterizerState &rasterState) |
daniel@transgaming.com | 493d4f8 | 2012-11-28 19:35:45 +0000 | [diff] [blame] | 783 | { |
| 784 | bool rasterStateChanged = mForceSetRasterState || memcmp(&rasterState, &mCurRasterState, sizeof(gl::RasterizerState)) != 0; |
daniel@transgaming.com | 493d4f8 | 2012-11-28 19:35:45 +0000 | [diff] [blame] | 785 | |
| 786 | if (rasterStateChanged) |
| 787 | { |
| 788 | // Set the cull mode |
| 789 | if (rasterState.cullFace) |
| 790 | { |
| 791 | mDevice->SetRenderState(D3DRS_CULLMODE, gl_d3d9::ConvertCullMode(rasterState.cullMode, rasterState.frontFace)); |
| 792 | } |
| 793 | else |
| 794 | { |
| 795 | mDevice->SetRenderState(D3DRS_CULLMODE, D3DCULL_NONE); |
| 796 | } |
| 797 | |
daniel@transgaming.com | 493d4f8 | 2012-11-28 19:35:45 +0000 | [diff] [blame] | 798 | if (rasterState.polygonOffsetFill) |
| 799 | { |
daniel@transgaming.com | 237bc7e | 2012-11-28 21:01:06 +0000 | [diff] [blame] | 800 | if (mCurDepthSize > 0) |
daniel@transgaming.com | 493d4f8 | 2012-11-28 19:35:45 +0000 | [diff] [blame] | 801 | { |
| 802 | mDevice->SetRenderState(D3DRS_SLOPESCALEDEPTHBIAS, *(DWORD*)&rasterState.polygonOffsetFactor); |
| 803 | |
daniel@transgaming.com | 237bc7e | 2012-11-28 21:01:06 +0000 | [diff] [blame] | 804 | float depthBias = ldexp(rasterState.polygonOffsetUnits, -static_cast<int>(mCurDepthSize)); |
daniel@transgaming.com | 493d4f8 | 2012-11-28 19:35:45 +0000 | [diff] [blame] | 805 | mDevice->SetRenderState(D3DRS_DEPTHBIAS, *(DWORD*)&depthBias); |
| 806 | } |
| 807 | } |
| 808 | else |
| 809 | { |
| 810 | mDevice->SetRenderState(D3DRS_SLOPESCALEDEPTHBIAS, 0); |
| 811 | mDevice->SetRenderState(D3DRS_DEPTHBIAS, 0); |
| 812 | } |
| 813 | |
daniel@transgaming.com | 237bc7e | 2012-11-28 21:01:06 +0000 | [diff] [blame] | 814 | mCurRasterState = rasterState; |
daniel@transgaming.com | 493d4f8 | 2012-11-28 19:35:45 +0000 | [diff] [blame] | 815 | } |
| 816 | |
| 817 | mForceSetRasterState = false; |
| 818 | } |
| 819 | |
Geoff Lang | 2a64ee4 | 2013-05-31 11:22:40 -0400 | [diff] [blame] | 820 | void Renderer9::setBlendState(const gl::BlendState &blendState, const gl::ColorF &blendColor, unsigned int sampleMask) |
daniel@transgaming.com | 493d4f8 | 2012-11-28 19:35:45 +0000 | [diff] [blame] | 821 | { |
| 822 | bool blendStateChanged = mForceSetBlendState || memcmp(&blendState, &mCurBlendState, sizeof(gl::BlendState)) != 0; |
Geoff Lang | 2a64ee4 | 2013-05-31 11:22:40 -0400 | [diff] [blame] | 823 | bool blendColorChanged = mForceSetBlendState || memcmp(&blendColor, &mCurBlendColor, sizeof(gl::ColorF)) != 0; |
daniel@transgaming.com | 493d4f8 | 2012-11-28 19:35:45 +0000 | [diff] [blame] | 824 | bool sampleMaskChanged = mForceSetBlendState || sampleMask != mCurSampleMask; |
| 825 | |
| 826 | if (blendStateChanged || blendColorChanged) |
| 827 | { |
| 828 | if (blendState.blend) |
| 829 | { |
| 830 | mDevice->SetRenderState(D3DRS_ALPHABLENDENABLE, TRUE); |
| 831 | |
| 832 | if (blendState.sourceBlendRGB != GL_CONSTANT_ALPHA && blendState.sourceBlendRGB != GL_ONE_MINUS_CONSTANT_ALPHA && |
| 833 | blendState.destBlendRGB != GL_CONSTANT_ALPHA && blendState.destBlendRGB != GL_ONE_MINUS_CONSTANT_ALPHA) |
| 834 | { |
| 835 | mDevice->SetRenderState(D3DRS_BLENDFACTOR, gl_d3d9::ConvertColor(blendColor)); |
| 836 | } |
| 837 | else |
| 838 | { |
| 839 | mDevice->SetRenderState(D3DRS_BLENDFACTOR, D3DCOLOR_RGBA(gl::unorm<8>(blendColor.alpha), |
| 840 | gl::unorm<8>(blendColor.alpha), |
| 841 | gl::unorm<8>(blendColor.alpha), |
| 842 | gl::unorm<8>(blendColor.alpha))); |
| 843 | } |
| 844 | |
| 845 | mDevice->SetRenderState(D3DRS_SRCBLEND, gl_d3d9::ConvertBlendFunc(blendState.sourceBlendRGB)); |
| 846 | mDevice->SetRenderState(D3DRS_DESTBLEND, gl_d3d9::ConvertBlendFunc(blendState.destBlendRGB)); |
| 847 | mDevice->SetRenderState(D3DRS_BLENDOP, gl_d3d9::ConvertBlendOp(blendState.blendEquationRGB)); |
| 848 | |
| 849 | if (blendState.sourceBlendRGB != blendState.sourceBlendAlpha || |
| 850 | blendState.destBlendRGB != blendState.destBlendAlpha || |
| 851 | blendState.blendEquationRGB != blendState.blendEquationAlpha) |
| 852 | { |
| 853 | mDevice->SetRenderState(D3DRS_SEPARATEALPHABLENDENABLE, TRUE); |
| 854 | |
| 855 | mDevice->SetRenderState(D3DRS_SRCBLENDALPHA, gl_d3d9::ConvertBlendFunc(blendState.sourceBlendAlpha)); |
| 856 | mDevice->SetRenderState(D3DRS_DESTBLENDALPHA, gl_d3d9::ConvertBlendFunc(blendState.destBlendAlpha)); |
| 857 | mDevice->SetRenderState(D3DRS_BLENDOPALPHA, gl_d3d9::ConvertBlendOp(blendState.blendEquationAlpha)); |
| 858 | } |
| 859 | else |
| 860 | { |
| 861 | mDevice->SetRenderState(D3DRS_SEPARATEALPHABLENDENABLE, FALSE); |
| 862 | } |
| 863 | } |
| 864 | else |
| 865 | { |
| 866 | mDevice->SetRenderState(D3DRS_ALPHABLENDENABLE, FALSE); |
| 867 | } |
| 868 | |
| 869 | if (blendState.sampleAlphaToCoverage) |
| 870 | { |
| 871 | FIXME("Sample alpha to coverage is unimplemented."); |
| 872 | } |
| 873 | |
| 874 | // Set the color mask |
| 875 | bool zeroColorMaskAllowed = getAdapterVendor() != VENDOR_ID_AMD; |
| 876 | // Apparently some ATI cards have a bug where a draw with a zero color |
| 877 | // write mask can cause later draws to have incorrect results. Instead, |
| 878 | // set a nonzero color write mask but modify the blend state so that no |
| 879 | // drawing is done. |
| 880 | // http://code.google.com/p/angleproject/issues/detail?id=169 |
| 881 | |
| 882 | DWORD colorMask = gl_d3d9::ConvertColorMask(blendState.colorMaskRed, blendState.colorMaskGreen, |
| 883 | blendState.colorMaskBlue, blendState.colorMaskAlpha); |
| 884 | if (colorMask == 0 && !zeroColorMaskAllowed) |
| 885 | { |
| 886 | // Enable green channel, but set blending so nothing will be drawn. |
| 887 | mDevice->SetRenderState(D3DRS_COLORWRITEENABLE, D3DCOLORWRITEENABLE_GREEN); |
| 888 | mDevice->SetRenderState(D3DRS_ALPHABLENDENABLE, TRUE); |
| 889 | |
| 890 | mDevice->SetRenderState(D3DRS_SRCBLEND, D3DBLEND_ZERO); |
| 891 | mDevice->SetRenderState(D3DRS_DESTBLEND, D3DBLEND_ONE); |
| 892 | mDevice->SetRenderState(D3DRS_BLENDOP, D3DBLENDOP_ADD); |
| 893 | } |
| 894 | else |
| 895 | { |
| 896 | mDevice->SetRenderState(D3DRS_COLORWRITEENABLE, colorMask); |
| 897 | } |
| 898 | |
| 899 | mDevice->SetRenderState(D3DRS_DITHERENABLE, blendState.dither ? TRUE : FALSE); |
| 900 | |
| 901 | mCurBlendState = blendState; |
| 902 | mCurBlendColor = blendColor; |
| 903 | } |
| 904 | |
| 905 | if (sampleMaskChanged) |
| 906 | { |
| 907 | // Set the multisample mask |
| 908 | mDevice->SetRenderState(D3DRS_MULTISAMPLEANTIALIAS, TRUE); |
| 909 | mDevice->SetRenderState(D3DRS_MULTISAMPLEMASK, static_cast<DWORD>(sampleMask)); |
| 910 | |
| 911 | mCurSampleMask = sampleMask; |
| 912 | } |
| 913 | |
| 914 | mForceSetBlendState = false; |
| 915 | } |
| 916 | |
daniel@transgaming.com | 08c331d | 2012-11-28 19:38:39 +0000 | [diff] [blame] | 917 | void Renderer9::setDepthStencilState(const gl::DepthStencilState &depthStencilState, int stencilRef, |
daniel@transgaming.com | 3a0ef48 | 2012-11-28 21:01:20 +0000 | [diff] [blame] | 918 | int stencilBackRef, bool frontFaceCCW) |
daniel@transgaming.com | 493d4f8 | 2012-11-28 19:35:45 +0000 | [diff] [blame] | 919 | { |
| 920 | bool depthStencilStateChanged = mForceSetDepthStencilState || |
| 921 | memcmp(&depthStencilState, &mCurDepthStencilState, sizeof(gl::DepthStencilState)) != 0; |
daniel@transgaming.com | 08c331d | 2012-11-28 19:38:39 +0000 | [diff] [blame] | 922 | bool stencilRefChanged = mForceSetDepthStencilState || stencilRef != mCurStencilRef || |
| 923 | stencilBackRef != mCurStencilBackRef; |
daniel@transgaming.com | 493d4f8 | 2012-11-28 19:35:45 +0000 | [diff] [blame] | 924 | bool frontFaceCCWChanged = mForceSetDepthStencilState || frontFaceCCW != mCurFrontFaceCCW; |
daniel@transgaming.com | 493d4f8 | 2012-11-28 19:35:45 +0000 | [diff] [blame] | 925 | |
| 926 | if (depthStencilStateChanged) |
| 927 | { |
| 928 | if (depthStencilState.depthTest) |
| 929 | { |
| 930 | mDevice->SetRenderState(D3DRS_ZENABLE, D3DZB_TRUE); |
| 931 | mDevice->SetRenderState(D3DRS_ZFUNC, gl_d3d9::ConvertComparison(depthStencilState.depthFunc)); |
| 932 | } |
| 933 | else |
| 934 | { |
| 935 | mDevice->SetRenderState(D3DRS_ZENABLE, D3DZB_FALSE); |
| 936 | } |
| 937 | |
| 938 | mCurDepthStencilState = depthStencilState; |
| 939 | } |
| 940 | |
daniel@transgaming.com | 3a0ef48 | 2012-11-28 21:01:20 +0000 | [diff] [blame] | 941 | if (depthStencilStateChanged || stencilRefChanged || frontFaceCCWChanged) |
daniel@transgaming.com | 493d4f8 | 2012-11-28 19:35:45 +0000 | [diff] [blame] | 942 | { |
daniel@transgaming.com | 3a0ef48 | 2012-11-28 21:01:20 +0000 | [diff] [blame] | 943 | if (depthStencilState.stencilTest && mCurStencilSize > 0) |
daniel@transgaming.com | 493d4f8 | 2012-11-28 19:35:45 +0000 | [diff] [blame] | 944 | { |
| 945 | mDevice->SetRenderState(D3DRS_STENCILENABLE, TRUE); |
| 946 | mDevice->SetRenderState(D3DRS_TWOSIDEDSTENCILMODE, TRUE); |
| 947 | |
| 948 | // FIXME: Unsupported by D3D9 |
| 949 | const D3DRENDERSTATETYPE D3DRS_CCW_STENCILREF = D3DRS_STENCILREF; |
| 950 | const D3DRENDERSTATETYPE D3DRS_CCW_STENCILMASK = D3DRS_STENCILMASK; |
| 951 | const D3DRENDERSTATETYPE D3DRS_CCW_STENCILWRITEMASK = D3DRS_STENCILWRITEMASK; |
| 952 | if (depthStencilState.stencilWritemask != depthStencilState.stencilBackWritemask || |
daniel@transgaming.com | 08c331d | 2012-11-28 19:38:39 +0000 | [diff] [blame] | 953 | stencilRef != stencilBackRef || |
daniel@transgaming.com | 493d4f8 | 2012-11-28 19:35:45 +0000 | [diff] [blame] | 954 | depthStencilState.stencilMask != depthStencilState.stencilBackMask) |
| 955 | { |
| 956 | ERR("Separate front/back stencil writemasks, reference values, or stencil mask values are invalid under WebGL."); |
shannon.woods@transgaming.com | 779aa26 | 2013-02-28 23:04:58 +0000 | [diff] [blame] | 957 | return gl::error(GL_INVALID_OPERATION); |
daniel@transgaming.com | 493d4f8 | 2012-11-28 19:35:45 +0000 | [diff] [blame] | 958 | } |
| 959 | |
| 960 | // get the maximum size of the stencil ref |
daniel@transgaming.com | 3a0ef48 | 2012-11-28 21:01:20 +0000 | [diff] [blame] | 961 | unsigned int maxStencil = (1 << mCurStencilSize) - 1; |
daniel@transgaming.com | 493d4f8 | 2012-11-28 19:35:45 +0000 | [diff] [blame] | 962 | |
| 963 | mDevice->SetRenderState(frontFaceCCW ? D3DRS_STENCILWRITEMASK : D3DRS_CCW_STENCILWRITEMASK, |
| 964 | depthStencilState.stencilWritemask); |
| 965 | mDevice->SetRenderState(frontFaceCCW ? D3DRS_STENCILFUNC : D3DRS_CCW_STENCILFUNC, |
| 966 | gl_d3d9::ConvertComparison(depthStencilState.stencilFunc)); |
| 967 | |
| 968 | mDevice->SetRenderState(frontFaceCCW ? D3DRS_STENCILREF : D3DRS_CCW_STENCILREF, |
daniel@transgaming.com | 08c331d | 2012-11-28 19:38:39 +0000 | [diff] [blame] | 969 | (stencilRef < (int)maxStencil) ? stencilRef : maxStencil); |
daniel@transgaming.com | 493d4f8 | 2012-11-28 19:35:45 +0000 | [diff] [blame] | 970 | mDevice->SetRenderState(frontFaceCCW ? D3DRS_STENCILMASK : D3DRS_CCW_STENCILMASK, |
| 971 | depthStencilState.stencilMask); |
| 972 | |
| 973 | mDevice->SetRenderState(frontFaceCCW ? D3DRS_STENCILFAIL : D3DRS_CCW_STENCILFAIL, |
| 974 | gl_d3d9::ConvertStencilOp(depthStencilState.stencilFail)); |
| 975 | mDevice->SetRenderState(frontFaceCCW ? D3DRS_STENCILZFAIL : D3DRS_CCW_STENCILZFAIL, |
| 976 | gl_d3d9::ConvertStencilOp(depthStencilState.stencilPassDepthFail)); |
| 977 | mDevice->SetRenderState(frontFaceCCW ? D3DRS_STENCILPASS : D3DRS_CCW_STENCILPASS, |
| 978 | gl_d3d9::ConvertStencilOp(depthStencilState.stencilPassDepthPass)); |
| 979 | |
| 980 | mDevice->SetRenderState(!frontFaceCCW ? D3DRS_STENCILWRITEMASK : D3DRS_CCW_STENCILWRITEMASK, |
| 981 | depthStencilState.stencilBackWritemask); |
| 982 | mDevice->SetRenderState(!frontFaceCCW ? D3DRS_STENCILFUNC : D3DRS_CCW_STENCILFUNC, |
| 983 | gl_d3d9::ConvertComparison(depthStencilState.stencilBackFunc)); |
| 984 | |
| 985 | mDevice->SetRenderState(!frontFaceCCW ? D3DRS_STENCILREF : D3DRS_CCW_STENCILREF, |
daniel@transgaming.com | 08c331d | 2012-11-28 19:38:39 +0000 | [diff] [blame] | 986 | (stencilBackRef < (int)maxStencil) ? stencilBackRef : maxStencil); |
daniel@transgaming.com | 493d4f8 | 2012-11-28 19:35:45 +0000 | [diff] [blame] | 987 | mDevice->SetRenderState(!frontFaceCCW ? D3DRS_STENCILMASK : D3DRS_CCW_STENCILMASK, |
| 988 | depthStencilState.stencilBackMask); |
| 989 | |
| 990 | mDevice->SetRenderState(!frontFaceCCW ? D3DRS_STENCILFAIL : D3DRS_CCW_STENCILFAIL, |
| 991 | gl_d3d9::ConvertStencilOp(depthStencilState.stencilBackFail)); |
| 992 | mDevice->SetRenderState(!frontFaceCCW ? D3DRS_STENCILZFAIL : D3DRS_CCW_STENCILZFAIL, |
| 993 | gl_d3d9::ConvertStencilOp(depthStencilState.stencilBackPassDepthFail)); |
| 994 | mDevice->SetRenderState(!frontFaceCCW ? D3DRS_STENCILPASS : D3DRS_CCW_STENCILPASS, |
| 995 | gl_d3d9::ConvertStencilOp(depthStencilState.stencilBackPassDepthPass)); |
| 996 | } |
| 997 | else |
| 998 | { |
| 999 | mDevice->SetRenderState(D3DRS_STENCILENABLE, FALSE); |
| 1000 | } |
| 1001 | |
| 1002 | mDevice->SetRenderState(D3DRS_ZWRITEENABLE, depthStencilState.depthMask ? TRUE : FALSE); |
| 1003 | |
daniel@transgaming.com | 08c331d | 2012-11-28 19:38:39 +0000 | [diff] [blame] | 1004 | mCurStencilRef = stencilRef; |
| 1005 | mCurStencilBackRef = stencilBackRef; |
daniel@transgaming.com | 493d4f8 | 2012-11-28 19:35:45 +0000 | [diff] [blame] | 1006 | mCurFrontFaceCCW = frontFaceCCW; |
daniel@transgaming.com | 493d4f8 | 2012-11-28 19:35:45 +0000 | [diff] [blame] | 1007 | } |
| 1008 | |
| 1009 | mForceSetDepthStencilState = false; |
| 1010 | } |
| 1011 | |
daniel@transgaming.com | d55e8c1 | 2012-11-28 21:07:02 +0000 | [diff] [blame] | 1012 | void Renderer9::setScissorRectangle(const gl::Rectangle &scissor, bool enabled) |
daniel@transgaming.com | 493d4f8 | 2012-11-28 19:35:45 +0000 | [diff] [blame] | 1013 | { |
daniel@transgaming.com | d55e8c1 | 2012-11-28 21:07:02 +0000 | [diff] [blame] | 1014 | bool scissorChanged = mForceSetScissor || |
| 1015 | memcmp(&scissor, &mCurScissor, sizeof(gl::Rectangle)) != 0 || |
| 1016 | enabled != mScissorEnabled; |
daniel@transgaming.com | 493d4f8 | 2012-11-28 19:35:45 +0000 | [diff] [blame] | 1017 | |
daniel@transgaming.com | 04f1b33 | 2012-11-28 21:00:40 +0000 | [diff] [blame] | 1018 | if (scissorChanged) |
daniel@transgaming.com | 493d4f8 | 2012-11-28 19:35:45 +0000 | [diff] [blame] | 1019 | { |
daniel@transgaming.com | d55e8c1 | 2012-11-28 21:07:02 +0000 | [diff] [blame] | 1020 | if (enabled) |
| 1021 | { |
| 1022 | RECT rect; |
| 1023 | rect.left = gl::clamp(scissor.x, 0, static_cast<int>(mRenderTargetDesc.width)); |
| 1024 | rect.top = gl::clamp(scissor.y, 0, static_cast<int>(mRenderTargetDesc.height)); |
| 1025 | rect.right = gl::clamp(scissor.x + scissor.width, 0, static_cast<int>(mRenderTargetDesc.width)); |
| 1026 | rect.bottom = gl::clamp(scissor.y + scissor.height, 0, static_cast<int>(mRenderTargetDesc.height)); |
| 1027 | mDevice->SetScissorRect(&rect); |
| 1028 | } |
daniel@transgaming.com | 493d4f8 | 2012-11-28 19:35:45 +0000 | [diff] [blame] | 1029 | |
daniel@transgaming.com | d55e8c1 | 2012-11-28 21:07:02 +0000 | [diff] [blame] | 1030 | mDevice->SetRenderState(D3DRS_SCISSORTESTENABLE, enabled ? TRUE : FALSE); |
| 1031 | |
| 1032 | mScissorEnabled = enabled; |
daniel@transgaming.com | 493d4f8 | 2012-11-28 19:35:45 +0000 | [diff] [blame] | 1033 | mCurScissor = scissor; |
daniel@transgaming.com | 493d4f8 | 2012-11-28 19:35:45 +0000 | [diff] [blame] | 1034 | } |
| 1035 | |
| 1036 | mForceSetScissor = false; |
| 1037 | } |
| 1038 | |
daniel@transgaming.com | 1298518 | 2012-12-20 20:56:31 +0000 | [diff] [blame] | 1039 | bool Renderer9::setViewport(const gl::Rectangle &viewport, float zNear, float zFar, GLenum drawMode, GLenum frontFace, |
shannon.woods@transgaming.com | 0b236e2 | 2013-01-25 21:57:07 +0000 | [diff] [blame] | 1040 | bool ignoreViewport) |
daniel@transgaming.com | 83e80ee | 2012-11-28 19:40:53 +0000 | [diff] [blame] | 1041 | { |
daniel@transgaming.com | 4c4ce23 | 2012-11-28 21:01:40 +0000 | [diff] [blame] | 1042 | gl::Rectangle actualViewport = viewport; |
| 1043 | float actualZNear = gl::clamp01(zNear); |
| 1044 | float actualZFar = gl::clamp01(zFar); |
| 1045 | if (ignoreViewport) |
| 1046 | { |
| 1047 | actualViewport.x = 0; |
| 1048 | actualViewport.y = 0; |
| 1049 | actualViewport.width = mRenderTargetDesc.width; |
| 1050 | actualViewport.height = mRenderTargetDesc.height; |
| 1051 | actualZNear = 0.0f; |
| 1052 | actualZFar = 1.0f; |
| 1053 | } |
daniel@transgaming.com | 83e80ee | 2012-11-28 19:40:53 +0000 | [diff] [blame] | 1054 | |
| 1055 | D3DVIEWPORT9 dxViewport; |
daniel@transgaming.com | 4c4ce23 | 2012-11-28 21:01:40 +0000 | [diff] [blame] | 1056 | dxViewport.X = gl::clamp(actualViewport.x, 0, static_cast<int>(mRenderTargetDesc.width)); |
| 1057 | dxViewport.Y = gl::clamp(actualViewport.y, 0, static_cast<int>(mRenderTargetDesc.height)); |
| 1058 | dxViewport.Width = gl::clamp(actualViewport.width, 0, static_cast<int>(mRenderTargetDesc.width) - static_cast<int>(dxViewport.X)); |
| 1059 | dxViewport.Height = gl::clamp(actualViewport.height, 0, static_cast<int>(mRenderTargetDesc.height) - static_cast<int>(dxViewport.Y)); |
| 1060 | dxViewport.MinZ = actualZNear; |
| 1061 | dxViewport.MaxZ = actualZFar; |
daniel@transgaming.com | 83e80ee | 2012-11-28 19:40:53 +0000 | [diff] [blame] | 1062 | |
| 1063 | if (dxViewport.Width <= 0 || dxViewport.Height <= 0) |
| 1064 | { |
| 1065 | return false; // Nothing to render |
| 1066 | } |
| 1067 | |
daniel@transgaming.com | ed36abd | 2013-01-11 21:15:58 +0000 | [diff] [blame] | 1068 | bool viewportChanged = mForceSetViewport || memcmp(&actualViewport, &mCurViewport, sizeof(gl::Rectangle)) != 0 || |
| 1069 | actualZNear != mCurNear || actualZFar != mCurFar; |
daniel@transgaming.com | 83e80ee | 2012-11-28 19:40:53 +0000 | [diff] [blame] | 1070 | if (viewportChanged) |
| 1071 | { |
| 1072 | mDevice->SetViewport(&dxViewport); |
| 1073 | |
daniel@transgaming.com | 4c4ce23 | 2012-11-28 21:01:40 +0000 | [diff] [blame] | 1074 | mCurViewport = actualViewport; |
| 1075 | mCurNear = actualZNear; |
| 1076 | mCurFar = actualZFar; |
daniel@transgaming.com | 83e80ee | 2012-11-28 19:40:53 +0000 | [diff] [blame] | 1077 | |
daniel@transgaming.com | ed36abd | 2013-01-11 21:15:58 +0000 | [diff] [blame] | 1078 | dx_VertexConstants vc = {0}; |
| 1079 | dx_PixelConstants pc = {0}; |
daniel@transgaming.com | 83e80ee | 2012-11-28 19:40:53 +0000 | [diff] [blame] | 1080 | |
shannon.woods@transgaming.com | 42832a6 | 2013-02-28 23:18:38 +0000 | [diff] [blame] | 1081 | vc.viewAdjust[0] = (float)((actualViewport.width - (int)dxViewport.Width) + 2 * (actualViewport.x - (int)dxViewport.X) - 1) / dxViewport.Width; |
| 1082 | vc.viewAdjust[1] = (float)((actualViewport.height - (int)dxViewport.Height) + 2 * (actualViewport.y - (int)dxViewport.Y) - 1) / dxViewport.Height; |
| 1083 | vc.viewAdjust[2] = (float)actualViewport.width / dxViewport.Width; |
| 1084 | vc.viewAdjust[3] = (float)actualViewport.height / dxViewport.Height; |
daniel@transgaming.com | 83e80ee | 2012-11-28 19:40:53 +0000 | [diff] [blame] | 1085 | |
shannon.woods@transgaming.com | a14ecf3 | 2013-02-28 23:09:42 +0000 | [diff] [blame] | 1086 | pc.viewCoords[0] = actualViewport.width * 0.5f; |
| 1087 | pc.viewCoords[1] = actualViewport.height * 0.5f; |
| 1088 | pc.viewCoords[2] = actualViewport.x + (actualViewport.width * 0.5f); |
| 1089 | pc.viewCoords[3] = actualViewport.y + (actualViewport.height * 0.5f); |
daniel@transgaming.com | 83e80ee | 2012-11-28 19:40:53 +0000 | [diff] [blame] | 1090 | |
daniel@transgaming.com | ed36abd | 2013-01-11 21:15:58 +0000 | [diff] [blame] | 1091 | pc.depthFront[0] = (actualZFar - actualZNear) * 0.5f; |
| 1092 | pc.depthFront[1] = (actualZNear + actualZFar) * 0.5f; |
| 1093 | pc.depthFront[2] = !gl::IsTriangleMode(drawMode) ? 0.0f : (frontFace == GL_CCW ? 1.0f : -1.0f);; |
| 1094 | |
| 1095 | vc.depthRange[0] = actualZNear; |
| 1096 | vc.depthRange[1] = actualZFar; |
| 1097 | vc.depthRange[2] = actualZFar - actualZNear; |
| 1098 | |
| 1099 | pc.depthRange[0] = actualZNear; |
| 1100 | pc.depthRange[1] = actualZFar; |
| 1101 | pc.depthRange[2] = actualZFar - actualZNear; |
| 1102 | |
| 1103 | if (memcmp(&vc, &mVertexConstants, sizeof(dx_VertexConstants)) != 0) |
| 1104 | { |
| 1105 | mVertexConstants = vc; |
| 1106 | mDxUniformsDirty = true; |
| 1107 | } |
| 1108 | |
| 1109 | if (memcmp(&pc, &mPixelConstants, sizeof(dx_PixelConstants)) != 0) |
| 1110 | { |
| 1111 | mPixelConstants = pc; |
| 1112 | mDxUniformsDirty = true; |
| 1113 | } |
daniel@transgaming.com | 83e80ee | 2012-11-28 19:40:53 +0000 | [diff] [blame] | 1114 | } |
| 1115 | |
| 1116 | mForceSetViewport = false; |
| 1117 | return true; |
| 1118 | } |
| 1119 | |
daniel@transgaming.com | 91207b7 | 2012-11-28 20:56:43 +0000 | [diff] [blame] | 1120 | bool Renderer9::applyPrimitiveType(GLenum mode, GLsizei count) |
| 1121 | { |
| 1122 | switch (mode) |
| 1123 | { |
| 1124 | case GL_POINTS: |
| 1125 | mPrimitiveType = D3DPT_POINTLIST; |
| 1126 | mPrimitiveCount = count; |
| 1127 | break; |
| 1128 | case GL_LINES: |
| 1129 | mPrimitiveType = D3DPT_LINELIST; |
| 1130 | mPrimitiveCount = count / 2; |
| 1131 | break; |
| 1132 | case GL_LINE_LOOP: |
| 1133 | mPrimitiveType = D3DPT_LINESTRIP; |
| 1134 | mPrimitiveCount = count - 1; // D3D doesn't support line loops, so we draw the last line separately |
| 1135 | break; |
| 1136 | case GL_LINE_STRIP: |
| 1137 | mPrimitiveType = D3DPT_LINESTRIP; |
| 1138 | mPrimitiveCount = count - 1; |
| 1139 | break; |
| 1140 | case GL_TRIANGLES: |
| 1141 | mPrimitiveType = D3DPT_TRIANGLELIST; |
| 1142 | mPrimitiveCount = count / 3; |
| 1143 | break; |
| 1144 | case GL_TRIANGLE_STRIP: |
| 1145 | mPrimitiveType = D3DPT_TRIANGLESTRIP; |
| 1146 | mPrimitiveCount = count - 2; |
| 1147 | break; |
| 1148 | case GL_TRIANGLE_FAN: |
| 1149 | mPrimitiveType = D3DPT_TRIANGLEFAN; |
| 1150 | mPrimitiveCount = count - 2; |
| 1151 | break; |
| 1152 | default: |
shannon.woods@transgaming.com | 779aa26 | 2013-02-28 23:04:58 +0000 | [diff] [blame] | 1153 | return gl::error(GL_INVALID_ENUM, false); |
daniel@transgaming.com | 91207b7 | 2012-11-28 20:56:43 +0000 | [diff] [blame] | 1154 | } |
| 1155 | |
| 1156 | return mPrimitiveCount > 0; |
| 1157 | } |
| 1158 | |
daniel@transgaming.com | e4e1a33 | 2012-12-20 20:52:09 +0000 | [diff] [blame] | 1159 | |
| 1160 | gl::Renderbuffer *Renderer9::getNullColorbuffer(gl::Renderbuffer *depthbuffer) |
| 1161 | { |
| 1162 | if (!depthbuffer) |
| 1163 | { |
| 1164 | ERR("Unexpected null depthbuffer for depth-only FBO."); |
| 1165 | return NULL; |
| 1166 | } |
| 1167 | |
| 1168 | GLsizei width = depthbuffer->getWidth(); |
| 1169 | GLsizei height = depthbuffer->getHeight(); |
| 1170 | |
| 1171 | // search cached nullcolorbuffers |
| 1172 | for (int i = 0; i < NUM_NULL_COLORBUFFER_CACHE_ENTRIES; i++) |
| 1173 | { |
| 1174 | if (mNullColorbufferCache[i].buffer != NULL && |
| 1175 | mNullColorbufferCache[i].width == width && |
| 1176 | mNullColorbufferCache[i].height == height) |
| 1177 | { |
| 1178 | mNullColorbufferCache[i].lruCount = ++mMaxNullColorbufferLRU; |
| 1179 | return mNullColorbufferCache[i].buffer; |
| 1180 | } |
| 1181 | } |
| 1182 | |
| 1183 | gl::Renderbuffer *nullbuffer = new gl::Renderbuffer(this, 0, new gl::Colorbuffer(this, width, height, GL_NONE, 0)); |
| 1184 | |
| 1185 | // add nullbuffer to the cache |
| 1186 | NullColorbufferCacheEntry *oldest = &mNullColorbufferCache[0]; |
| 1187 | for (int i = 1; i < NUM_NULL_COLORBUFFER_CACHE_ENTRIES; i++) |
| 1188 | { |
| 1189 | if (mNullColorbufferCache[i].lruCount < oldest->lruCount) |
| 1190 | { |
| 1191 | oldest = &mNullColorbufferCache[i]; |
| 1192 | } |
| 1193 | } |
| 1194 | |
| 1195 | delete oldest->buffer; |
| 1196 | oldest->buffer = nullbuffer; |
| 1197 | oldest->lruCount = ++mMaxNullColorbufferLRU; |
| 1198 | oldest->width = width; |
| 1199 | oldest->height = height; |
| 1200 | |
| 1201 | return nullbuffer; |
| 1202 | } |
| 1203 | |
daniel@transgaming.com | ae39ee2 | 2012-11-28 19:42:02 +0000 | [diff] [blame] | 1204 | bool Renderer9::applyRenderTarget(gl::Framebuffer *framebuffer) |
daniel@transgaming.com | 493d4f8 | 2012-11-28 19:35:45 +0000 | [diff] [blame] | 1205 | { |
daniel@transgaming.com | 220e79a | 2012-11-28 19:42:11 +0000 | [diff] [blame] | 1206 | // if there is no color attachment we must synthesize a NULL colorattachment |
| 1207 | // to keep the D3D runtime happy. This should only be possible if depth texturing. |
| 1208 | gl::Renderbuffer *renderbufferObject = NULL; |
shannon.woods%transgaming.com@gtempaccount.com | 89ae113 | 2013-04-13 03:28:43 +0000 | [diff] [blame] | 1209 | if (framebuffer->getColorbufferType(0) != GL_NONE) |
daniel@transgaming.com | 220e79a | 2012-11-28 19:42:11 +0000 | [diff] [blame] | 1210 | { |
shannon.woods%transgaming.com@gtempaccount.com | 89ae113 | 2013-04-13 03:28:43 +0000 | [diff] [blame] | 1211 | renderbufferObject = framebuffer->getColorbuffer(0); |
daniel@transgaming.com | 220e79a | 2012-11-28 19:42:11 +0000 | [diff] [blame] | 1212 | } |
| 1213 | else |
| 1214 | { |
daniel@transgaming.com | e4e1a33 | 2012-12-20 20:52:09 +0000 | [diff] [blame] | 1215 | renderbufferObject = getNullColorbuffer(framebuffer->getDepthbuffer()); |
daniel@transgaming.com | 220e79a | 2012-11-28 19:42:11 +0000 | [diff] [blame] | 1216 | } |
| 1217 | if (!renderbufferObject) |
| 1218 | { |
| 1219 | ERR("unable to locate renderbuffer for FBO."); |
| 1220 | return false; |
| 1221 | } |
daniel@transgaming.com | 493d4f8 | 2012-11-28 19:35:45 +0000 | [diff] [blame] | 1222 | |
daniel@transgaming.com | 220e79a | 2012-11-28 19:42:11 +0000 | [diff] [blame] | 1223 | bool renderTargetChanged = false; |
| 1224 | unsigned int renderTargetSerial = renderbufferObject->getSerial(); |
| 1225 | if (renderTargetSerial != mAppliedRenderTargetSerial) |
| 1226 | { |
| 1227 | // Apply the render target on the device |
| 1228 | IDirect3DSurface9 *renderTargetSurface = NULL; |
| 1229 | |
| 1230 | RenderTarget *renderTarget = renderbufferObject->getRenderTarget(); |
| 1231 | if (renderTarget) |
| 1232 | { |
daniel@transgaming.com | 965bcd2 | 2012-11-28 20:54:14 +0000 | [diff] [blame] | 1233 | renderTargetSurface = RenderTarget9::makeRenderTarget9(renderTarget)->getSurface(); |
daniel@transgaming.com | 220e79a | 2012-11-28 19:42:11 +0000 | [diff] [blame] | 1234 | } |
| 1235 | |
| 1236 | if (!renderTargetSurface) |
| 1237 | { |
| 1238 | ERR("render target pointer unexpectedly null."); |
| 1239 | return false; // Context must be lost |
| 1240 | } |
| 1241 | |
| 1242 | mDevice->SetRenderTarget(0, renderTargetSurface); |
| 1243 | renderTargetSurface->Release(); |
| 1244 | |
| 1245 | mAppliedRenderTargetSerial = renderTargetSerial; |
| 1246 | renderTargetChanged = true; |
| 1247 | } |
| 1248 | |
| 1249 | gl::Renderbuffer *depthStencil = NULL; |
| 1250 | unsigned int depthbufferSerial = 0; |
| 1251 | unsigned int stencilbufferSerial = 0; |
| 1252 | if (framebuffer->getDepthbufferType() != GL_NONE) |
| 1253 | { |
| 1254 | depthStencil = framebuffer->getDepthbuffer(); |
| 1255 | if (!depthStencil) |
| 1256 | { |
| 1257 | ERR("Depth stencil pointer unexpectedly null."); |
| 1258 | return false; |
| 1259 | } |
| 1260 | |
| 1261 | depthbufferSerial = depthStencil->getSerial(); |
| 1262 | } |
| 1263 | else if (framebuffer->getStencilbufferType() != GL_NONE) |
| 1264 | { |
| 1265 | depthStencil = framebuffer->getStencilbuffer(); |
| 1266 | if (!depthStencil) |
| 1267 | { |
| 1268 | ERR("Depth stencil pointer unexpectedly null."); |
| 1269 | return false; |
| 1270 | } |
| 1271 | |
| 1272 | stencilbufferSerial = depthStencil->getSerial(); |
| 1273 | } |
| 1274 | |
| 1275 | if (depthbufferSerial != mAppliedDepthbufferSerial || |
| 1276 | stencilbufferSerial != mAppliedStencilbufferSerial || |
| 1277 | !mDepthStencilInitialized) |
| 1278 | { |
daniel@transgaming.com | 237bc7e | 2012-11-28 21:01:06 +0000 | [diff] [blame] | 1279 | unsigned int depthSize = 0; |
daniel@transgaming.com | 3a0ef48 | 2012-11-28 21:01:20 +0000 | [diff] [blame] | 1280 | unsigned int stencilSize = 0; |
daniel@transgaming.com | 237bc7e | 2012-11-28 21:01:06 +0000 | [diff] [blame] | 1281 | |
daniel@transgaming.com | 220e79a | 2012-11-28 19:42:11 +0000 | [diff] [blame] | 1282 | // Apply the depth stencil on the device |
| 1283 | if (depthStencil) |
| 1284 | { |
| 1285 | IDirect3DSurface9 *depthStencilSurface = NULL; |
| 1286 | RenderTarget *depthStencilRenderTarget = depthStencil->getDepthStencil(); |
| 1287 | |
| 1288 | if (depthStencilRenderTarget) |
| 1289 | { |
daniel@transgaming.com | 965bcd2 | 2012-11-28 20:54:14 +0000 | [diff] [blame] | 1290 | depthStencilSurface = RenderTarget9::makeRenderTarget9(depthStencilRenderTarget)->getSurface(); |
daniel@transgaming.com | 220e79a | 2012-11-28 19:42:11 +0000 | [diff] [blame] | 1291 | } |
| 1292 | |
| 1293 | if (!depthStencilSurface) |
| 1294 | { |
| 1295 | ERR("depth stencil pointer unexpectedly null."); |
| 1296 | return false; // Context must be lost |
| 1297 | } |
| 1298 | |
| 1299 | mDevice->SetDepthStencilSurface(depthStencilSurface); |
| 1300 | depthStencilSurface->Release(); |
daniel@transgaming.com | 237bc7e | 2012-11-28 21:01:06 +0000 | [diff] [blame] | 1301 | |
| 1302 | depthSize = depthStencil->getDepthSize(); |
daniel@transgaming.com | 3a0ef48 | 2012-11-28 21:01:20 +0000 | [diff] [blame] | 1303 | stencilSize = depthStencil->getStencilSize(); |
daniel@transgaming.com | 220e79a | 2012-11-28 19:42:11 +0000 | [diff] [blame] | 1304 | } |
| 1305 | else |
| 1306 | { |
| 1307 | mDevice->SetDepthStencilSurface(NULL); |
| 1308 | } |
| 1309 | |
daniel@transgaming.com | 237bc7e | 2012-11-28 21:01:06 +0000 | [diff] [blame] | 1310 | if (!mDepthStencilInitialized || depthSize != mCurDepthSize) |
| 1311 | { |
| 1312 | mCurDepthSize = depthSize; |
| 1313 | mForceSetRasterState = true; |
| 1314 | } |
| 1315 | |
daniel@transgaming.com | 3a0ef48 | 2012-11-28 21:01:20 +0000 | [diff] [blame] | 1316 | if (!mDepthStencilInitialized || stencilSize != mCurStencilSize) |
| 1317 | { |
| 1318 | mCurStencilSize = stencilSize; |
| 1319 | mForceSetDepthStencilState = true; |
| 1320 | } |
| 1321 | |
daniel@transgaming.com | 220e79a | 2012-11-28 19:42:11 +0000 | [diff] [blame] | 1322 | mAppliedDepthbufferSerial = depthbufferSerial; |
| 1323 | mAppliedStencilbufferSerial = stencilbufferSerial; |
| 1324 | mDepthStencilInitialized = true; |
| 1325 | } |
| 1326 | |
| 1327 | if (renderTargetChanged || !mRenderTargetDescInitialized) |
| 1328 | { |
| 1329 | mForceSetScissor = true; |
| 1330 | mForceSetViewport = true; |
| 1331 | |
| 1332 | mRenderTargetDesc.width = renderbufferObject->getWidth(); |
| 1333 | mRenderTargetDesc.height = renderbufferObject->getHeight(); |
| 1334 | mRenderTargetDesc.format = renderbufferObject->getActualFormat(); |
| 1335 | mRenderTargetDescInitialized = true; |
| 1336 | } |
daniel@transgaming.com | ae39ee2 | 2012-11-28 19:42:02 +0000 | [diff] [blame] | 1337 | |
| 1338 | return true; |
daniel@transgaming.com | 493d4f8 | 2012-11-28 19:35:45 +0000 | [diff] [blame] | 1339 | } |
daniel@transgaming.com | a734f27 | 2012-10-31 18:07:48 +0000 | [diff] [blame] | 1340 | |
daniel@transgaming.com | 91207b7 | 2012-11-28 20:56:43 +0000 | [diff] [blame] | 1341 | GLenum Renderer9::applyVertexBuffer(gl::ProgramBinary *programBinary, gl::VertexAttribute vertexAttributes[], GLint first, GLsizei count, GLsizei instances) |
daniel@transgaming.com | 67094ee | 2012-11-28 20:53:04 +0000 | [diff] [blame] | 1342 | { |
daniel@transgaming.com | 3124048 | 2012-11-28 21:06:41 +0000 | [diff] [blame] | 1343 | TranslatedAttribute attributes[gl::MAX_VERTEX_ATTRIBS]; |
daniel@transgaming.com | 67094ee | 2012-11-28 20:53:04 +0000 | [diff] [blame] | 1344 | GLenum err = mVertexDataManager->prepareVertexData(vertexAttributes, programBinary, first, count, attributes, instances); |
| 1345 | if (err != GL_NO_ERROR) |
| 1346 | { |
| 1347 | return err; |
| 1348 | } |
| 1349 | |
daniel@transgaming.com | 91207b7 | 2012-11-28 20:56:43 +0000 | [diff] [blame] | 1350 | return mVertexDeclarationCache.applyDeclaration(mDevice, attributes, programBinary, instances, &mRepeatDraw); |
| 1351 | } |
| 1352 | |
| 1353 | // Applies the indices and element array bindings to the Direct3D 9 device |
daniel@transgaming.com | 3124048 | 2012-11-28 21:06:41 +0000 | [diff] [blame] | 1354 | GLenum Renderer9::applyIndexBuffer(const GLvoid *indices, gl::Buffer *elementArrayBuffer, GLsizei count, GLenum mode, GLenum type, TranslatedIndexData *indexInfo) |
daniel@transgaming.com | 91207b7 | 2012-11-28 20:56:43 +0000 | [diff] [blame] | 1355 | { |
daniel@transgaming.com | 1e3a804 | 2012-12-20 21:09:55 +0000 | [diff] [blame] | 1356 | GLenum err = mIndexDataManager->prepareIndexData(type, count, elementArrayBuffer, indices, indexInfo); |
daniel@transgaming.com | 91207b7 | 2012-11-28 20:56:43 +0000 | [diff] [blame] | 1357 | |
daniel@transgaming.com | 91207b7 | 2012-11-28 20:56:43 +0000 | [diff] [blame] | 1358 | if (err == GL_NO_ERROR) |
| 1359 | { |
shannon.woods@transgaming.com | a1229a3 | 2013-02-28 23:08:40 +0000 | [diff] [blame] | 1360 | // Directly binding the storage buffer is not supported for d3d9 |
| 1361 | ASSERT(indexInfo->storage == NULL); |
| 1362 | |
daniel@transgaming.com | 1e3a804 | 2012-12-20 21:09:55 +0000 | [diff] [blame] | 1363 | if (indexInfo->serial != mAppliedIBSerial) |
daniel@transgaming.com | 91207b7 | 2012-11-28 20:56:43 +0000 | [diff] [blame] | 1364 | { |
daniel@transgaming.com | 1e3a804 | 2012-12-20 21:09:55 +0000 | [diff] [blame] | 1365 | IndexBuffer9* indexBuffer = IndexBuffer9::makeIndexBuffer9(indexInfo->indexBuffer); |
| 1366 | |
| 1367 | mDevice->SetIndices(indexBuffer->getBuffer()); |
| 1368 | mAppliedIBSerial = indexInfo->serial; |
daniel@transgaming.com | 91207b7 | 2012-11-28 20:56:43 +0000 | [diff] [blame] | 1369 | } |
| 1370 | } |
| 1371 | |
| 1372 | return err; |
| 1373 | } |
| 1374 | |
| 1375 | void Renderer9::drawArrays(GLenum mode, GLsizei count, GLsizei instances) |
| 1376 | { |
| 1377 | startScene(); |
| 1378 | |
| 1379 | if (mode == GL_LINE_LOOP) |
| 1380 | { |
| 1381 | drawLineLoop(count, GL_NONE, NULL, 0, NULL); |
| 1382 | } |
| 1383 | else if (instances > 0) |
| 1384 | { |
daniel@transgaming.com | 50cc725 | 2012-12-20 21:09:23 +0000 | [diff] [blame] | 1385 | StaticIndexBufferInterface *countingIB = mIndexDataManager->getCountingIndices(count); |
daniel@transgaming.com | 91207b7 | 2012-11-28 20:56:43 +0000 | [diff] [blame] | 1386 | if (countingIB) |
| 1387 | { |
| 1388 | if (mAppliedIBSerial != countingIB->getSerial()) |
| 1389 | { |
daniel@transgaming.com | 1e3a804 | 2012-12-20 21:09:55 +0000 | [diff] [blame] | 1390 | IndexBuffer9 *indexBuffer = IndexBuffer9::makeIndexBuffer9(countingIB->getIndexBuffer()); |
| 1391 | |
| 1392 | mDevice->SetIndices(indexBuffer->getBuffer()); |
daniel@transgaming.com | 91207b7 | 2012-11-28 20:56:43 +0000 | [diff] [blame] | 1393 | mAppliedIBSerial = countingIB->getSerial(); |
| 1394 | } |
| 1395 | |
| 1396 | for (int i = 0; i < mRepeatDraw; i++) |
| 1397 | { |
| 1398 | mDevice->DrawIndexedPrimitive(mPrimitiveType, 0, 0, count, 0, mPrimitiveCount); |
| 1399 | } |
| 1400 | } |
| 1401 | else |
| 1402 | { |
| 1403 | ERR("Could not create a counting index buffer for glDrawArraysInstanced."); |
shannon.woods@transgaming.com | 779aa26 | 2013-02-28 23:04:58 +0000 | [diff] [blame] | 1404 | return gl::error(GL_OUT_OF_MEMORY); |
daniel@transgaming.com | 91207b7 | 2012-11-28 20:56:43 +0000 | [diff] [blame] | 1405 | } |
| 1406 | } |
| 1407 | else // Regular case |
| 1408 | { |
| 1409 | mDevice->DrawPrimitive(mPrimitiveType, 0, mPrimitiveCount); |
| 1410 | } |
| 1411 | } |
| 1412 | |
shannon.woods@transgaming.com | 00032cb | 2013-01-25 21:56:30 +0000 | [diff] [blame] | 1413 | void Renderer9::drawElements(GLenum mode, GLsizei count, GLenum type, const GLvoid *indices, gl::Buffer *elementArrayBuffer, const TranslatedIndexData &indexInfo, GLsizei /*instances*/) |
daniel@transgaming.com | 91207b7 | 2012-11-28 20:56:43 +0000 | [diff] [blame] | 1414 | { |
| 1415 | startScene(); |
| 1416 | |
shannon.woods@transgaming.com | e1602ae | 2013-02-28 23:17:38 +0000 | [diff] [blame] | 1417 | if (mode == GL_POINTS) |
| 1418 | { |
| 1419 | drawIndexedPoints(count, type, indices, elementArrayBuffer); |
| 1420 | } |
| 1421 | else if (mode == GL_LINE_LOOP) |
daniel@transgaming.com | 91207b7 | 2012-11-28 20:56:43 +0000 | [diff] [blame] | 1422 | { |
daniel@transgaming.com | 97400dd | 2012-11-28 20:57:00 +0000 | [diff] [blame] | 1423 | drawLineLoop(count, type, indices, indexInfo.minIndex, elementArrayBuffer); |
daniel@transgaming.com | 91207b7 | 2012-11-28 20:56:43 +0000 | [diff] [blame] | 1424 | } |
| 1425 | else |
| 1426 | { |
| 1427 | for (int i = 0; i < mRepeatDraw; i++) |
| 1428 | { |
daniel@transgaming.com | 97400dd | 2012-11-28 20:57:00 +0000 | [diff] [blame] | 1429 | GLsizei vertexCount = indexInfo.maxIndex - indexInfo.minIndex + 1; |
| 1430 | mDevice->DrawIndexedPrimitive(mPrimitiveType, -(INT)indexInfo.minIndex, indexInfo.minIndex, vertexCount, indexInfo.startIndex, mPrimitiveCount); |
daniel@transgaming.com | 91207b7 | 2012-11-28 20:56:43 +0000 | [diff] [blame] | 1431 | } |
| 1432 | } |
| 1433 | } |
| 1434 | |
| 1435 | void Renderer9::drawLineLoop(GLsizei count, GLenum type, const GLvoid *indices, int minIndex, gl::Buffer *elementArrayBuffer) |
| 1436 | { |
| 1437 | // Get the raw indices for an indexed draw |
| 1438 | if (type != GL_NONE && elementArrayBuffer) |
| 1439 | { |
| 1440 | gl::Buffer *indexBuffer = elementArrayBuffer; |
shannon.woods@transgaming.com | 7665541 | 2013-02-28 23:08:09 +0000 | [diff] [blame] | 1441 | BufferStorage *storage = indexBuffer->getStorage(); |
daniel@transgaming.com | 91207b7 | 2012-11-28 20:56:43 +0000 | [diff] [blame] | 1442 | intptr_t offset = reinterpret_cast<intptr_t>(indices); |
shannon.woods@transgaming.com | 7665541 | 2013-02-28 23:08:09 +0000 | [diff] [blame] | 1443 | indices = static_cast<const GLubyte*>(storage->getData()) + offset; |
daniel@transgaming.com | 91207b7 | 2012-11-28 20:56:43 +0000 | [diff] [blame] | 1444 | } |
| 1445 | |
| 1446 | UINT startIndex = 0; |
daniel@transgaming.com | 91207b7 | 2012-11-28 20:56:43 +0000 | [diff] [blame] | 1447 | |
| 1448 | if (get32BitIndexSupport()) |
| 1449 | { |
daniel@transgaming.com | 1e3a804 | 2012-12-20 21:09:55 +0000 | [diff] [blame] | 1450 | if (!mLineLoopIB) |
| 1451 | { |
| 1452 | mLineLoopIB = new StreamingIndexBufferInterface(this); |
| 1453 | if (!mLineLoopIB->reserveBufferSpace(INITIAL_INDEX_BUFFER_SIZE, GL_UNSIGNED_INT)) |
| 1454 | { |
| 1455 | delete mLineLoopIB; |
| 1456 | mLineLoopIB = NULL; |
| 1457 | |
| 1458 | ERR("Could not create a 32-bit looping index buffer for GL_LINE_LOOP."); |
shannon.woods@transgaming.com | 779aa26 | 2013-02-28 23:04:58 +0000 | [diff] [blame] | 1459 | return gl::error(GL_OUT_OF_MEMORY); |
daniel@transgaming.com | 1e3a804 | 2012-12-20 21:09:55 +0000 | [diff] [blame] | 1460 | } |
| 1461 | } |
| 1462 | |
daniel@transgaming.com | 91207b7 | 2012-11-28 20:56:43 +0000 | [diff] [blame] | 1463 | const int spaceNeeded = (count + 1) * sizeof(unsigned int); |
daniel@transgaming.com | 1e3a804 | 2012-12-20 21:09:55 +0000 | [diff] [blame] | 1464 | if (!mLineLoopIB->reserveBufferSpace(spaceNeeded, GL_UNSIGNED_INT)) |
daniel@transgaming.com | 91207b7 | 2012-11-28 20:56:43 +0000 | [diff] [blame] | 1465 | { |
daniel@transgaming.com | 1e3a804 | 2012-12-20 21:09:55 +0000 | [diff] [blame] | 1466 | ERR("Could not reserve enough space in looping index buffer for GL_LINE_LOOP."); |
shannon.woods@transgaming.com | 779aa26 | 2013-02-28 23:04:58 +0000 | [diff] [blame] | 1467 | return gl::error(GL_OUT_OF_MEMORY); |
daniel@transgaming.com | 91207b7 | 2012-11-28 20:56:43 +0000 | [diff] [blame] | 1468 | } |
| 1469 | |
daniel@transgaming.com | 1e3a804 | 2012-12-20 21:09:55 +0000 | [diff] [blame] | 1470 | void* mappedMemory = NULL; |
| 1471 | int offset = mLineLoopIB->mapBuffer(spaceNeeded, &mappedMemory); |
| 1472 | if (offset == -1 || mappedMemory == NULL) |
daniel@transgaming.com | 91207b7 | 2012-11-28 20:56:43 +0000 | [diff] [blame] | 1473 | { |
daniel@transgaming.com | 1e3a804 | 2012-12-20 21:09:55 +0000 | [diff] [blame] | 1474 | ERR("Could not map index buffer for GL_LINE_LOOP."); |
shannon.woods@transgaming.com | 779aa26 | 2013-02-28 23:04:58 +0000 | [diff] [blame] | 1475 | return gl::error(GL_OUT_OF_MEMORY); |
daniel@transgaming.com | 1e3a804 | 2012-12-20 21:09:55 +0000 | [diff] [blame] | 1476 | } |
daniel@transgaming.com | 91207b7 | 2012-11-28 20:56:43 +0000 | [diff] [blame] | 1477 | |
daniel@transgaming.com | 1e3a804 | 2012-12-20 21:09:55 +0000 | [diff] [blame] | 1478 | startIndex = static_cast<UINT>(offset) / 4; |
| 1479 | unsigned int *data = reinterpret_cast<unsigned int*>(mappedMemory); |
| 1480 | |
| 1481 | switch (type) |
| 1482 | { |
| 1483 | case GL_NONE: // Non-indexed draw |
| 1484 | for (int i = 0; i < count; i++) |
daniel@transgaming.com | 91207b7 | 2012-11-28 20:56:43 +0000 | [diff] [blame] | 1485 | { |
daniel@transgaming.com | 1e3a804 | 2012-12-20 21:09:55 +0000 | [diff] [blame] | 1486 | data[i] = i; |
daniel@transgaming.com | 91207b7 | 2012-11-28 20:56:43 +0000 | [diff] [blame] | 1487 | } |
daniel@transgaming.com | 1e3a804 | 2012-12-20 21:09:55 +0000 | [diff] [blame] | 1488 | data[count] = 0; |
| 1489 | break; |
| 1490 | case GL_UNSIGNED_BYTE: |
| 1491 | for (int i = 0; i < count; i++) |
| 1492 | { |
| 1493 | data[i] = static_cast<const GLubyte*>(indices)[i]; |
| 1494 | } |
| 1495 | data[count] = static_cast<const GLubyte*>(indices)[0]; |
| 1496 | break; |
| 1497 | case GL_UNSIGNED_SHORT: |
| 1498 | for (int i = 0; i < count; i++) |
| 1499 | { |
| 1500 | data[i] = static_cast<const GLushort*>(indices)[i]; |
| 1501 | } |
| 1502 | data[count] = static_cast<const GLushort*>(indices)[0]; |
| 1503 | break; |
| 1504 | case GL_UNSIGNED_INT: |
| 1505 | for (int i = 0; i < count; i++) |
| 1506 | { |
| 1507 | data[i] = static_cast<const GLuint*>(indices)[i]; |
| 1508 | } |
| 1509 | data[count] = static_cast<const GLuint*>(indices)[0]; |
| 1510 | break; |
| 1511 | default: UNREACHABLE(); |
| 1512 | } |
| 1513 | |
| 1514 | if (!mLineLoopIB->unmapBuffer()) |
| 1515 | { |
| 1516 | ERR("Could not unmap index buffer for GL_LINE_LOOP."); |
shannon.woods@transgaming.com | 779aa26 | 2013-02-28 23:04:58 +0000 | [diff] [blame] | 1517 | return gl::error(GL_OUT_OF_MEMORY); |
daniel@transgaming.com | 91207b7 | 2012-11-28 20:56:43 +0000 | [diff] [blame] | 1518 | } |
| 1519 | } |
| 1520 | else |
| 1521 | { |
daniel@transgaming.com | 1e3a804 | 2012-12-20 21:09:55 +0000 | [diff] [blame] | 1522 | if (!mLineLoopIB) |
| 1523 | { |
| 1524 | mLineLoopIB = new StreamingIndexBufferInterface(this); |
| 1525 | if (!mLineLoopIB->reserveBufferSpace(INITIAL_INDEX_BUFFER_SIZE, GL_UNSIGNED_SHORT)) |
| 1526 | { |
| 1527 | delete mLineLoopIB; |
| 1528 | mLineLoopIB = NULL; |
| 1529 | |
| 1530 | ERR("Could not create a 16-bit looping index buffer for GL_LINE_LOOP."); |
shannon.woods@transgaming.com | 779aa26 | 2013-02-28 23:04:58 +0000 | [diff] [blame] | 1531 | return gl::error(GL_OUT_OF_MEMORY); |
daniel@transgaming.com | 1e3a804 | 2012-12-20 21:09:55 +0000 | [diff] [blame] | 1532 | } |
| 1533 | } |
| 1534 | |
daniel@transgaming.com | 91207b7 | 2012-11-28 20:56:43 +0000 | [diff] [blame] | 1535 | const int spaceNeeded = (count + 1) * sizeof(unsigned short); |
daniel@transgaming.com | 1e3a804 | 2012-12-20 21:09:55 +0000 | [diff] [blame] | 1536 | if (!mLineLoopIB->reserveBufferSpace(spaceNeeded, GL_UNSIGNED_SHORT)) |
daniel@transgaming.com | 91207b7 | 2012-11-28 20:56:43 +0000 | [diff] [blame] | 1537 | { |
daniel@transgaming.com | 1e3a804 | 2012-12-20 21:09:55 +0000 | [diff] [blame] | 1538 | ERR("Could not reserve enough space in looping index buffer for GL_LINE_LOOP."); |
shannon.woods@transgaming.com | 779aa26 | 2013-02-28 23:04:58 +0000 | [diff] [blame] | 1539 | return gl::error(GL_OUT_OF_MEMORY); |
daniel@transgaming.com | 91207b7 | 2012-11-28 20:56:43 +0000 | [diff] [blame] | 1540 | } |
| 1541 | |
daniel@transgaming.com | 1e3a804 | 2012-12-20 21:09:55 +0000 | [diff] [blame] | 1542 | void* mappedMemory = NULL; |
| 1543 | int offset = mLineLoopIB->mapBuffer(spaceNeeded, &mappedMemory); |
| 1544 | if (offset == -1 || mappedMemory == NULL) |
daniel@transgaming.com | 91207b7 | 2012-11-28 20:56:43 +0000 | [diff] [blame] | 1545 | { |
daniel@transgaming.com | 1e3a804 | 2012-12-20 21:09:55 +0000 | [diff] [blame] | 1546 | ERR("Could not map index buffer for GL_LINE_LOOP."); |
shannon.woods@transgaming.com | 779aa26 | 2013-02-28 23:04:58 +0000 | [diff] [blame] | 1547 | return gl::error(GL_OUT_OF_MEMORY); |
daniel@transgaming.com | 1e3a804 | 2012-12-20 21:09:55 +0000 | [diff] [blame] | 1548 | } |
daniel@transgaming.com | 91207b7 | 2012-11-28 20:56:43 +0000 | [diff] [blame] | 1549 | |
daniel@transgaming.com | 1e3a804 | 2012-12-20 21:09:55 +0000 | [diff] [blame] | 1550 | startIndex = static_cast<UINT>(offset) / 2; |
| 1551 | unsigned short *data = reinterpret_cast<unsigned short*>(mappedMemory); |
| 1552 | |
| 1553 | switch (type) |
| 1554 | { |
| 1555 | case GL_NONE: // Non-indexed draw |
| 1556 | for (int i = 0; i < count; i++) |
daniel@transgaming.com | 91207b7 | 2012-11-28 20:56:43 +0000 | [diff] [blame] | 1557 | { |
daniel@transgaming.com | 1e3a804 | 2012-12-20 21:09:55 +0000 | [diff] [blame] | 1558 | data[i] = i; |
daniel@transgaming.com | 91207b7 | 2012-11-28 20:56:43 +0000 | [diff] [blame] | 1559 | } |
daniel@transgaming.com | 1e3a804 | 2012-12-20 21:09:55 +0000 | [diff] [blame] | 1560 | data[count] = 0; |
| 1561 | break; |
| 1562 | case GL_UNSIGNED_BYTE: |
| 1563 | for (int i = 0; i < count; i++) |
| 1564 | { |
| 1565 | data[i] = static_cast<const GLubyte*>(indices)[i]; |
| 1566 | } |
| 1567 | data[count] = static_cast<const GLubyte*>(indices)[0]; |
| 1568 | break; |
| 1569 | case GL_UNSIGNED_SHORT: |
| 1570 | for (int i = 0; i < count; i++) |
| 1571 | { |
| 1572 | data[i] = static_cast<const GLushort*>(indices)[i]; |
| 1573 | } |
| 1574 | data[count] = static_cast<const GLushort*>(indices)[0]; |
| 1575 | break; |
| 1576 | case GL_UNSIGNED_INT: |
| 1577 | for (int i = 0; i < count; i++) |
| 1578 | { |
| 1579 | data[i] = static_cast<const GLuint*>(indices)[i]; |
| 1580 | } |
| 1581 | data[count] = static_cast<const GLuint*>(indices)[0]; |
| 1582 | break; |
| 1583 | default: UNREACHABLE(); |
daniel@transgaming.com | 91207b7 | 2012-11-28 20:56:43 +0000 | [diff] [blame] | 1584 | } |
| 1585 | |
daniel@transgaming.com | 1e3a804 | 2012-12-20 21:09:55 +0000 | [diff] [blame] | 1586 | if (!mLineLoopIB->unmapBuffer()) |
| 1587 | { |
| 1588 | ERR("Could not unmap index buffer for GL_LINE_LOOP."); |
shannon.woods@transgaming.com | 779aa26 | 2013-02-28 23:04:58 +0000 | [diff] [blame] | 1589 | return gl::error(GL_OUT_OF_MEMORY); |
daniel@transgaming.com | 1e3a804 | 2012-12-20 21:09:55 +0000 | [diff] [blame] | 1590 | } |
daniel@transgaming.com | 91207b7 | 2012-11-28 20:56:43 +0000 | [diff] [blame] | 1591 | } |
daniel@transgaming.com | 1e3a804 | 2012-12-20 21:09:55 +0000 | [diff] [blame] | 1592 | |
| 1593 | if (mAppliedIBSerial != mLineLoopIB->getSerial()) |
daniel@transgaming.com | 91207b7 | 2012-11-28 20:56:43 +0000 | [diff] [blame] | 1594 | { |
daniel@transgaming.com | 1e3a804 | 2012-12-20 21:09:55 +0000 | [diff] [blame] | 1595 | IndexBuffer9 *indexBuffer = IndexBuffer9::makeIndexBuffer9(mLineLoopIB->getIndexBuffer()); |
| 1596 | |
| 1597 | mDevice->SetIndices(indexBuffer->getBuffer()); |
| 1598 | mAppliedIBSerial = mLineLoopIB->getSerial(); |
daniel@transgaming.com | 91207b7 | 2012-11-28 20:56:43 +0000 | [diff] [blame] | 1599 | } |
daniel@transgaming.com | 1e3a804 | 2012-12-20 21:09:55 +0000 | [diff] [blame] | 1600 | |
| 1601 | mDevice->DrawIndexedPrimitive(D3DPT_LINESTRIP, -minIndex, minIndex, count, startIndex, count); |
daniel@transgaming.com | 67094ee | 2012-11-28 20:53:04 +0000 | [diff] [blame] | 1602 | } |
| 1603 | |
shannon.woods@transgaming.com | e1602ae | 2013-02-28 23:17:38 +0000 | [diff] [blame] | 1604 | template <typename T> |
| 1605 | static void drawPoints(IDirect3DDevice9* device, GLsizei count, const GLvoid *indices) |
| 1606 | { |
| 1607 | for (int i = 0; i < count; i++) |
| 1608 | { |
| 1609 | unsigned int indexValue = static_cast<unsigned int>(static_cast<const T*>(indices)[i]); |
| 1610 | device->DrawPrimitive(D3DPT_POINTLIST, indexValue, 1); |
| 1611 | } |
| 1612 | } |
| 1613 | |
| 1614 | void Renderer9::drawIndexedPoints(GLsizei count, GLenum type, const GLvoid *indices, gl::Buffer *elementArrayBuffer) |
| 1615 | { |
| 1616 | // Drawing index point lists is unsupported in d3d9, fall back to a regular DrawPrimitive call |
| 1617 | // for each individual point. This call is not expected to happen often. |
| 1618 | |
| 1619 | if (elementArrayBuffer) |
| 1620 | { |
| 1621 | BufferStorage *storage = elementArrayBuffer->getStorage(); |
| 1622 | intptr_t offset = reinterpret_cast<intptr_t>(indices); |
| 1623 | indices = static_cast<const GLubyte*>(storage->getData()) + offset; |
| 1624 | } |
| 1625 | |
| 1626 | switch (type) |
| 1627 | { |
| 1628 | case GL_UNSIGNED_BYTE: drawPoints<GLubyte>(mDevice, count, indices); break; |
| 1629 | case GL_UNSIGNED_SHORT: drawPoints<GLushort>(mDevice, count, indices); break; |
| 1630 | case GL_UNSIGNED_INT: drawPoints<GLuint>(mDevice, count, indices); break; |
| 1631 | default: UNREACHABLE(); |
| 1632 | } |
| 1633 | } |
| 1634 | |
daniel@transgaming.com | 5fbf177 | 2012-11-28 20:54:43 +0000 | [diff] [blame] | 1635 | void Renderer9::applyShaders(gl::ProgramBinary *programBinary) |
| 1636 | { |
daniel@transgaming.com | e499141 | 2012-12-20 20:55:34 +0000 | [diff] [blame] | 1637 | unsigned int programBinarySerial = programBinary->getSerial(); |
| 1638 | if (programBinarySerial != mAppliedProgramBinarySerial) |
| 1639 | { |
| 1640 | ShaderExecutable *vertexExe = programBinary->getVertexExecutable(); |
| 1641 | ShaderExecutable *pixelExe = programBinary->getPixelExecutable(); |
daniel@transgaming.com | 9589241 | 2012-11-28 20:59:09 +0000 | [diff] [blame] | 1642 | |
daniel@transgaming.com | e499141 | 2012-12-20 20:55:34 +0000 | [diff] [blame] | 1643 | IDirect3DVertexShader9 *vertexShader = NULL; |
| 1644 | if (vertexExe) vertexShader = ShaderExecutable9::makeShaderExecutable9(vertexExe)->getVertexShader(); |
daniel@transgaming.com | 9589241 | 2012-11-28 20:59:09 +0000 | [diff] [blame] | 1645 | |
daniel@transgaming.com | e499141 | 2012-12-20 20:55:34 +0000 | [diff] [blame] | 1646 | IDirect3DPixelShader9 *pixelShader = NULL; |
| 1647 | if (pixelExe) pixelShader = ShaderExecutable9::makeShaderExecutable9(pixelExe)->getPixelShader(); |
daniel@transgaming.com | 5fbf177 | 2012-11-28 20:54:43 +0000 | [diff] [blame] | 1648 | |
daniel@transgaming.com | e499141 | 2012-12-20 20:55:34 +0000 | [diff] [blame] | 1649 | mDevice->SetPixelShader(pixelShader); |
| 1650 | mDevice->SetVertexShader(vertexShader); |
| 1651 | programBinary->dirtyAllUniforms(); |
daniel@transgaming.com | ed36abd | 2013-01-11 21:15:58 +0000 | [diff] [blame] | 1652 | mDxUniformsDirty = true; |
daniel@transgaming.com | e499141 | 2012-12-20 20:55:34 +0000 | [diff] [blame] | 1653 | |
| 1654 | mAppliedProgramBinarySerial = programBinarySerial; |
| 1655 | } |
daniel@transgaming.com | 5fbf177 | 2012-11-28 20:54:43 +0000 | [diff] [blame] | 1656 | } |
| 1657 | |
shannon.woods@transgaming.com | 21ba647 | 2013-01-25 21:53:32 +0000 | [diff] [blame] | 1658 | void Renderer9::applyUniforms(gl::ProgramBinary *programBinary, gl::UniformArray *uniformArray) |
daniel@transgaming.com | b6e5510 | 2012-12-20 21:08:14 +0000 | [diff] [blame] | 1659 | { |
| 1660 | for (std::vector<gl::Uniform*>::const_iterator ub = uniformArray->begin(), ue = uniformArray->end(); ub != ue; ++ub) |
| 1661 | { |
| 1662 | gl::Uniform *targetUniform = *ub; |
| 1663 | |
| 1664 | if (targetUniform->dirty) |
| 1665 | { |
daniel@transgaming.com | b6e5510 | 2012-12-20 21:08:14 +0000 | [diff] [blame] | 1666 | GLfloat *f = (GLfloat*)targetUniform->data; |
| 1667 | GLint *i = (GLint*)targetUniform->data; |
daniel@transgaming.com | b6e5510 | 2012-12-20 21:08:14 +0000 | [diff] [blame] | 1668 | |
| 1669 | switch (targetUniform->type) |
| 1670 | { |
| 1671 | case GL_SAMPLER_2D: |
| 1672 | case GL_SAMPLER_CUBE: |
shannon.woods@transgaming.com | 2494c97 | 2013-02-28 23:10:03 +0000 | [diff] [blame] | 1673 | break; |
| 1674 | case GL_BOOL: |
| 1675 | case GL_BOOL_VEC2: |
| 1676 | case GL_BOOL_VEC3: |
| 1677 | case GL_BOOL_VEC4: |
| 1678 | applyUniformnbv(targetUniform, i); |
| 1679 | break; |
daniel@transgaming.com | b6e5510 | 2012-12-20 21:08:14 +0000 | [diff] [blame] | 1680 | case GL_FLOAT: |
| 1681 | case GL_FLOAT_VEC2: |
| 1682 | case GL_FLOAT_VEC3: |
| 1683 | case GL_FLOAT_VEC4: |
| 1684 | case GL_FLOAT_MAT2: |
| 1685 | case GL_FLOAT_MAT3: |
shannon.woods@transgaming.com | 2494c97 | 2013-02-28 23:10:03 +0000 | [diff] [blame] | 1686 | case GL_FLOAT_MAT4: |
| 1687 | applyUniformnfv(targetUniform, f); |
| 1688 | break; |
| 1689 | case GL_INT: |
| 1690 | case GL_INT_VEC2: |
| 1691 | case GL_INT_VEC3: |
| 1692 | case GL_INT_VEC4: |
| 1693 | applyUniformniv(targetUniform, i); |
| 1694 | break; |
daniel@transgaming.com | b6e5510 | 2012-12-20 21:08:14 +0000 | [diff] [blame] | 1695 | default: |
| 1696 | UNREACHABLE(); |
| 1697 | } |
| 1698 | |
| 1699 | targetUniform->dirty = false; |
| 1700 | } |
| 1701 | } |
daniel@transgaming.com | a390e1e | 2013-01-11 04:09:39 +0000 | [diff] [blame] | 1702 | |
| 1703 | // Driver uniforms |
daniel@transgaming.com | ed36abd | 2013-01-11 21:15:58 +0000 | [diff] [blame] | 1704 | if (mDxUniformsDirty) |
| 1705 | { |
| 1706 | mDevice->SetVertexShaderConstantF(0, (float*)&mVertexConstants, sizeof(dx_VertexConstants) / sizeof(float[4])); |
| 1707 | mDevice->SetPixelShaderConstantF(0, (float*)&mPixelConstants, sizeof(dx_PixelConstants) / sizeof(float[4])); |
| 1708 | mDxUniformsDirty = false; |
| 1709 | } |
daniel@transgaming.com | b6e5510 | 2012-12-20 21:08:14 +0000 | [diff] [blame] | 1710 | } |
| 1711 | |
daniel@transgaming.com | f956186 | 2012-12-20 21:12:07 +0000 | [diff] [blame] | 1712 | void Renderer9::applyUniformnfv(gl::Uniform *targetUniform, const GLfloat *v) |
daniel@transgaming.com | b6e5510 | 2012-12-20 21:08:14 +0000 | [diff] [blame] | 1713 | { |
shannonwoods@chromium.org | 38676dc | 2013-05-30 00:06:52 +0000 | [diff] [blame] | 1714 | if (targetUniform->isReferencedByFragmentShader()) |
daniel@transgaming.com | b6e5510 | 2012-12-20 21:08:14 +0000 | [diff] [blame] | 1715 | { |
daniel@transgaming.com | e76b64b | 2013-01-11 04:10:08 +0000 | [diff] [blame] | 1716 | mDevice->SetPixelShaderConstantF(targetUniform->psRegisterIndex, v, targetUniform->registerCount); |
daniel@transgaming.com | b6e5510 | 2012-12-20 21:08:14 +0000 | [diff] [blame] | 1717 | } |
| 1718 | |
shannonwoods@chromium.org | 38676dc | 2013-05-30 00:06:52 +0000 | [diff] [blame] | 1719 | if (targetUniform->isReferencedByVertexShader()) |
daniel@transgaming.com | b6e5510 | 2012-12-20 21:08:14 +0000 | [diff] [blame] | 1720 | { |
daniel@transgaming.com | e76b64b | 2013-01-11 04:10:08 +0000 | [diff] [blame] | 1721 | mDevice->SetVertexShaderConstantF(targetUniform->vsRegisterIndex, v, targetUniform->registerCount); |
daniel@transgaming.com | b6e5510 | 2012-12-20 21:08:14 +0000 | [diff] [blame] | 1722 | } |
daniel@transgaming.com | b6e5510 | 2012-12-20 21:08:14 +0000 | [diff] [blame] | 1723 | } |
| 1724 | |
shannon.woods@transgaming.com | 2494c97 | 2013-02-28 23:10:03 +0000 | [diff] [blame] | 1725 | void Renderer9::applyUniformniv(gl::Uniform *targetUniform, const GLint *v) |
daniel@transgaming.com | b6e5510 | 2012-12-20 21:08:14 +0000 | [diff] [blame] | 1726 | { |
shannon.woods@transgaming.com | d8136cb | 2013-02-28 23:14:44 +0000 | [diff] [blame] | 1727 | ASSERT(targetUniform->registerCount <= MAX_VERTEX_CONSTANT_VECTORS_D3D9); |
| 1728 | GLfloat vector[MAX_VERTEX_CONSTANT_VECTORS_D3D9][4]; |
daniel@transgaming.com | b6e5510 | 2012-12-20 21:08:14 +0000 | [diff] [blame] | 1729 | |
shannon.woods@transgaming.com | 2494c97 | 2013-02-28 23:10:03 +0000 | [diff] [blame] | 1730 | for (unsigned int i = 0; i < targetUniform->registerCount; i++) |
daniel@transgaming.com | b6e5510 | 2012-12-20 21:08:14 +0000 | [diff] [blame] | 1731 | { |
shannon.woods@transgaming.com | 2494c97 | 2013-02-28 23:10:03 +0000 | [diff] [blame] | 1732 | vector[i][0] = (GLfloat)v[4 * i + 0]; |
| 1733 | vector[i][1] = (GLfloat)v[4 * i + 1]; |
| 1734 | vector[i][2] = (GLfloat)v[4 * i + 2]; |
| 1735 | vector[i][3] = (GLfloat)v[4 * i + 3]; |
daniel@transgaming.com | b6e5510 | 2012-12-20 21:08:14 +0000 | [diff] [blame] | 1736 | } |
| 1737 | |
shannon.woods@transgaming.com | 2494c97 | 2013-02-28 23:10:03 +0000 | [diff] [blame] | 1738 | applyUniformnfv(targetUniform, (GLfloat*)vector); |
daniel@transgaming.com | b6e5510 | 2012-12-20 21:08:14 +0000 | [diff] [blame] | 1739 | } |
| 1740 | |
shannon.woods@transgaming.com | 2494c97 | 2013-02-28 23:10:03 +0000 | [diff] [blame] | 1741 | void Renderer9::applyUniformnbv(gl::Uniform *targetUniform, const GLint *v) |
daniel@transgaming.com | b6e5510 | 2012-12-20 21:08:14 +0000 | [diff] [blame] | 1742 | { |
shannon.woods@transgaming.com | d8136cb | 2013-02-28 23:14:44 +0000 | [diff] [blame] | 1743 | ASSERT(targetUniform->registerCount <= MAX_VERTEX_CONSTANT_VECTORS_D3D9); |
| 1744 | GLfloat vector[MAX_VERTEX_CONSTANT_VECTORS_D3D9][4]; |
daniel@transgaming.com | b6e5510 | 2012-12-20 21:08:14 +0000 | [diff] [blame] | 1745 | |
shannon.woods@transgaming.com | 2494c97 | 2013-02-28 23:10:03 +0000 | [diff] [blame] | 1746 | for (unsigned int i = 0; i < targetUniform->registerCount; i++) |
daniel@transgaming.com | b6e5510 | 2012-12-20 21:08:14 +0000 | [diff] [blame] | 1747 | { |
shannon.woods@transgaming.com | 2494c97 | 2013-02-28 23:10:03 +0000 | [diff] [blame] | 1748 | vector[i][0] = (v[4 * i + 0] == GL_FALSE) ? 0.0f : 1.0f; |
| 1749 | vector[i][1] = (v[4 * i + 1] == GL_FALSE) ? 0.0f : 1.0f; |
| 1750 | vector[i][2] = (v[4 * i + 2] == GL_FALSE) ? 0.0f : 1.0f; |
| 1751 | vector[i][3] = (v[4 * i + 3] == GL_FALSE) ? 0.0f : 1.0f; |
daniel@transgaming.com | b6e5510 | 2012-12-20 21:08:14 +0000 | [diff] [blame] | 1752 | } |
| 1753 | |
shannon.woods@transgaming.com | 2494c97 | 2013-02-28 23:10:03 +0000 | [diff] [blame] | 1754 | applyUniformnfv(targetUniform, (GLfloat*)vector); |
daniel@transgaming.com | b6e5510 | 2012-12-20 21:08:14 +0000 | [diff] [blame] | 1755 | } |
| 1756 | |
daniel@transgaming.com | 084a257 | 2012-11-28 20:55:17 +0000 | [diff] [blame] | 1757 | void Renderer9::clear(const gl::ClearParameters &clearParams, gl::Framebuffer *frameBuffer) |
daniel@transgaming.com | d084c62 | 2012-11-28 19:36:05 +0000 | [diff] [blame] | 1758 | { |
daniel@transgaming.com | 0393e5b | 2012-11-28 20:55:33 +0000 | [diff] [blame] | 1759 | D3DCOLOR color = D3DCOLOR_ARGB(gl::unorm<8>(clearParams.colorClearValue.alpha), |
| 1760 | gl::unorm<8>(clearParams.colorClearValue.red), |
| 1761 | gl::unorm<8>(clearParams.colorClearValue.green), |
| 1762 | gl::unorm<8>(clearParams.colorClearValue.blue)); |
| 1763 | float depth = gl::clamp01(clearParams.depthClearValue); |
| 1764 | int stencil = clearParams.stencilClearValue & 0x000000FF; |
daniel@transgaming.com | d084c62 | 2012-11-28 19:36:05 +0000 | [diff] [blame] | 1765 | |
daniel@transgaming.com | 0393e5b | 2012-11-28 20:55:33 +0000 | [diff] [blame] | 1766 | unsigned int stencilUnmasked = 0x0; |
| 1767 | if ((clearParams.mask & GL_STENCIL_BUFFER_BIT) && frameBuffer->hasStencil()) |
| 1768 | { |
shannonwoods@chromium.org | 755012f | 2013-05-30 00:09:32 +0000 | [diff] [blame] | 1769 | unsigned int stencilSize = gl::GetStencilBits(frameBuffer->getStencilbuffer()->getActualFormat(), |
| 1770 | getCurrentClientVersion()); |
daniel@transgaming.com | 0393e5b | 2012-11-28 20:55:33 +0000 | [diff] [blame] | 1771 | stencilUnmasked = (0x1 << stencilSize) - 1; |
| 1772 | } |
| 1773 | |
shannonwoods@chromium.org | 755012f | 2013-05-30 00:09:32 +0000 | [diff] [blame] | 1774 | bool alphaUnmasked = gl::GetAlphaBits(mRenderTargetDesc.format, getCurrentClientVersion()) == 0 || |
| 1775 | clearParams.colorMaskAlpha; |
daniel@transgaming.com | 0393e5b | 2012-11-28 20:55:33 +0000 | [diff] [blame] | 1776 | |
| 1777 | const bool needMaskedStencilClear = (clearParams.mask & GL_STENCIL_BUFFER_BIT) && |
| 1778 | (clearParams.stencilWriteMask & stencilUnmasked) != stencilUnmasked; |
| 1779 | const bool needMaskedColorClear = (clearParams.mask & GL_COLOR_BUFFER_BIT) && |
| 1780 | !(clearParams.colorMaskRed && clearParams.colorMaskGreen && |
| 1781 | clearParams.colorMaskBlue && alphaUnmasked); |
| 1782 | |
| 1783 | if (needMaskedColorClear || needMaskedStencilClear) |
| 1784 | { |
| 1785 | // State which is altered in all paths from this point to the clear call is saved. |
| 1786 | // State which is altered in only some paths will be flagged dirty in the case that |
| 1787 | // that path is taken. |
| 1788 | HRESULT hr; |
| 1789 | if (mMaskedClearSavedState == NULL) |
| 1790 | { |
| 1791 | hr = mDevice->BeginStateBlock(); |
| 1792 | ASSERT(SUCCEEDED(hr) || hr == D3DERR_OUTOFVIDEOMEMORY || hr == E_OUTOFMEMORY); |
| 1793 | |
| 1794 | mDevice->SetRenderState(D3DRS_ZWRITEENABLE, FALSE); |
| 1795 | mDevice->SetRenderState(D3DRS_ZFUNC, D3DCMP_ALWAYS); |
| 1796 | mDevice->SetRenderState(D3DRS_ZENABLE, FALSE); |
| 1797 | mDevice->SetRenderState(D3DRS_CULLMODE, D3DCULL_NONE); |
| 1798 | mDevice->SetRenderState(D3DRS_FILLMODE, D3DFILL_SOLID); |
| 1799 | mDevice->SetRenderState(D3DRS_ALPHATESTENABLE, FALSE); |
| 1800 | mDevice->SetRenderState(D3DRS_ALPHABLENDENABLE, FALSE); |
| 1801 | mDevice->SetRenderState(D3DRS_CLIPPLANEENABLE, 0); |
| 1802 | mDevice->SetRenderState(D3DRS_COLORWRITEENABLE, 0); |
| 1803 | mDevice->SetRenderState(D3DRS_STENCILENABLE, FALSE); |
| 1804 | mDevice->SetPixelShader(NULL); |
| 1805 | mDevice->SetVertexShader(NULL); |
| 1806 | mDevice->SetFVF(D3DFVF_XYZRHW | D3DFVF_DIFFUSE); |
| 1807 | mDevice->SetStreamSource(0, NULL, 0, 0); |
| 1808 | mDevice->SetRenderState(D3DRS_SEPARATEALPHABLENDENABLE, TRUE); |
| 1809 | mDevice->SetTextureStageState(0, D3DTSS_COLOROP, D3DTOP_SELECTARG1); |
| 1810 | mDevice->SetTextureStageState(0, D3DTSS_COLORARG1, D3DTA_TFACTOR); |
| 1811 | mDevice->SetTextureStageState(0, D3DTSS_ALPHAOP, D3DTOP_SELECTARG1); |
| 1812 | mDevice->SetTextureStageState(0, D3DTSS_ALPHAARG1, D3DTA_TFACTOR); |
| 1813 | mDevice->SetRenderState(D3DRS_TEXTUREFACTOR, color); |
| 1814 | mDevice->SetRenderState(D3DRS_MULTISAMPLEMASK, 0xFFFFFFFF); |
| 1815 | |
| 1816 | for(int i = 0; i < gl::MAX_VERTEX_ATTRIBS; i++) |
| 1817 | { |
| 1818 | mDevice->SetStreamSourceFreq(i, 1); |
| 1819 | } |
| 1820 | |
| 1821 | hr = mDevice->EndStateBlock(&mMaskedClearSavedState); |
| 1822 | ASSERT(SUCCEEDED(hr) || hr == D3DERR_OUTOFVIDEOMEMORY || hr == E_OUTOFMEMORY); |
| 1823 | } |
| 1824 | |
| 1825 | ASSERT(mMaskedClearSavedState != NULL); |
| 1826 | |
| 1827 | if (mMaskedClearSavedState != NULL) |
| 1828 | { |
| 1829 | hr = mMaskedClearSavedState->Capture(); |
| 1830 | ASSERT(SUCCEEDED(hr)); |
| 1831 | } |
| 1832 | |
| 1833 | mDevice->SetRenderState(D3DRS_ZWRITEENABLE, FALSE); |
| 1834 | mDevice->SetRenderState(D3DRS_ZFUNC, D3DCMP_ALWAYS); |
| 1835 | mDevice->SetRenderState(D3DRS_ZENABLE, FALSE); |
| 1836 | mDevice->SetRenderState(D3DRS_CULLMODE, D3DCULL_NONE); |
| 1837 | mDevice->SetRenderState(D3DRS_FILLMODE, D3DFILL_SOLID); |
| 1838 | mDevice->SetRenderState(D3DRS_ALPHATESTENABLE, FALSE); |
| 1839 | mDevice->SetRenderState(D3DRS_ALPHABLENDENABLE, FALSE); |
| 1840 | mDevice->SetRenderState(D3DRS_CLIPPLANEENABLE, 0); |
| 1841 | |
| 1842 | if (clearParams.mask & GL_COLOR_BUFFER_BIT) |
| 1843 | { |
| 1844 | mDevice->SetRenderState(D3DRS_COLORWRITEENABLE, |
| 1845 | gl_d3d9::ConvertColorMask(clearParams.colorMaskRed, |
| 1846 | clearParams.colorMaskGreen, |
| 1847 | clearParams.colorMaskBlue, |
| 1848 | clearParams.colorMaskAlpha)); |
| 1849 | } |
| 1850 | else |
| 1851 | { |
| 1852 | mDevice->SetRenderState(D3DRS_COLORWRITEENABLE, 0); |
| 1853 | } |
| 1854 | |
| 1855 | if (stencilUnmasked != 0x0 && (clearParams.mask & GL_STENCIL_BUFFER_BIT)) |
| 1856 | { |
| 1857 | mDevice->SetRenderState(D3DRS_STENCILENABLE, TRUE); |
| 1858 | mDevice->SetRenderState(D3DRS_TWOSIDEDSTENCILMODE, FALSE); |
| 1859 | mDevice->SetRenderState(D3DRS_STENCILFUNC, D3DCMP_ALWAYS); |
| 1860 | mDevice->SetRenderState(D3DRS_STENCILREF, stencil); |
| 1861 | mDevice->SetRenderState(D3DRS_STENCILWRITEMASK, clearParams.stencilWriteMask); |
| 1862 | mDevice->SetRenderState(D3DRS_STENCILFAIL, D3DSTENCILOP_REPLACE); |
| 1863 | mDevice->SetRenderState(D3DRS_STENCILZFAIL, D3DSTENCILOP_REPLACE); |
| 1864 | mDevice->SetRenderState(D3DRS_STENCILPASS, D3DSTENCILOP_REPLACE); |
| 1865 | } |
| 1866 | else |
| 1867 | { |
| 1868 | mDevice->SetRenderState(D3DRS_STENCILENABLE, FALSE); |
| 1869 | } |
| 1870 | |
| 1871 | mDevice->SetPixelShader(NULL); |
| 1872 | mDevice->SetVertexShader(NULL); |
| 1873 | mDevice->SetFVF(D3DFVF_XYZRHW); |
| 1874 | mDevice->SetRenderState(D3DRS_SEPARATEALPHABLENDENABLE, TRUE); |
| 1875 | mDevice->SetTextureStageState(0, D3DTSS_COLOROP, D3DTOP_SELECTARG1); |
| 1876 | mDevice->SetTextureStageState(0, D3DTSS_COLORARG1, D3DTA_TFACTOR); |
| 1877 | mDevice->SetTextureStageState(0, D3DTSS_ALPHAOP, D3DTOP_SELECTARG1); |
| 1878 | mDevice->SetTextureStageState(0, D3DTSS_ALPHAARG1, D3DTA_TFACTOR); |
| 1879 | mDevice->SetRenderState(D3DRS_TEXTUREFACTOR, color); |
| 1880 | mDevice->SetRenderState(D3DRS_MULTISAMPLEMASK, 0xFFFFFFFF); |
| 1881 | |
| 1882 | for(int i = 0; i < gl::MAX_VERTEX_ATTRIBS; i++) |
| 1883 | { |
| 1884 | mDevice->SetStreamSourceFreq(i, 1); |
| 1885 | } |
| 1886 | |
| 1887 | float quad[4][4]; // A quadrilateral covering the target, aligned to match the edges |
| 1888 | quad[0][0] = -0.5f; |
| 1889 | quad[0][1] = mRenderTargetDesc.height - 0.5f; |
| 1890 | quad[0][2] = 0.0f; |
| 1891 | quad[0][3] = 1.0f; |
| 1892 | |
| 1893 | quad[1][0] = mRenderTargetDesc.width - 0.5f; |
| 1894 | quad[1][1] = mRenderTargetDesc.height - 0.5f; |
| 1895 | quad[1][2] = 0.0f; |
| 1896 | quad[1][3] = 1.0f; |
| 1897 | |
| 1898 | quad[2][0] = -0.5f; |
| 1899 | quad[2][1] = -0.5f; |
| 1900 | quad[2][2] = 0.0f; |
| 1901 | quad[2][3] = 1.0f; |
| 1902 | |
| 1903 | quad[3][0] = mRenderTargetDesc.width - 0.5f; |
| 1904 | quad[3][1] = -0.5f; |
| 1905 | quad[3][2] = 0.0f; |
| 1906 | quad[3][3] = 1.0f; |
| 1907 | |
| 1908 | startScene(); |
| 1909 | mDevice->DrawPrimitiveUP(D3DPT_TRIANGLESTRIP, 2, quad, sizeof(float[4])); |
| 1910 | |
| 1911 | if (clearParams.mask & GL_DEPTH_BUFFER_BIT) |
| 1912 | { |
| 1913 | mDevice->SetRenderState(D3DRS_ZENABLE, TRUE); |
| 1914 | mDevice->SetRenderState(D3DRS_ZWRITEENABLE, TRUE); |
| 1915 | mDevice->Clear(0, NULL, D3DCLEAR_ZBUFFER, color, depth, stencil); |
| 1916 | } |
| 1917 | |
| 1918 | if (mMaskedClearSavedState != NULL) |
| 1919 | { |
| 1920 | mMaskedClearSavedState->Apply(); |
| 1921 | } |
| 1922 | } |
| 1923 | else if (clearParams.mask) |
| 1924 | { |
| 1925 | DWORD dxClearFlags = 0; |
| 1926 | if (clearParams.mask & GL_COLOR_BUFFER_BIT) |
| 1927 | { |
| 1928 | dxClearFlags |= D3DCLEAR_TARGET; |
| 1929 | } |
| 1930 | if (clearParams.mask & GL_DEPTH_BUFFER_BIT) |
| 1931 | { |
| 1932 | dxClearFlags |= D3DCLEAR_ZBUFFER; |
| 1933 | } |
| 1934 | if (clearParams.mask & GL_STENCIL_BUFFER_BIT) |
| 1935 | { |
| 1936 | dxClearFlags |= D3DCLEAR_STENCIL; |
| 1937 | } |
| 1938 | |
| 1939 | mDevice->Clear(0, NULL, dxClearFlags, color, depth, stencil); |
| 1940 | } |
daniel@transgaming.com | d084c62 | 2012-11-28 19:36:05 +0000 | [diff] [blame] | 1941 | } |
| 1942 | |
daniel@transgaming.com | c43a605 | 2012-11-28 19:41:51 +0000 | [diff] [blame] | 1943 | void Renderer9::markAllStateDirty() |
| 1944 | { |
daniel@transgaming.com | 220e79a | 2012-11-28 19:42:11 +0000 | [diff] [blame] | 1945 | mAppliedRenderTargetSerial = 0; |
| 1946 | mAppliedDepthbufferSerial = 0; |
| 1947 | mAppliedStencilbufferSerial = 0; |
| 1948 | mDepthStencilInitialized = false; |
| 1949 | mRenderTargetDescInitialized = false; |
| 1950 | |
daniel@transgaming.com | c43a605 | 2012-11-28 19:41:51 +0000 | [diff] [blame] | 1951 | mForceSetDepthStencilState = true; |
| 1952 | mForceSetRasterState = true; |
daniel@transgaming.com | c43a605 | 2012-11-28 19:41:51 +0000 | [diff] [blame] | 1953 | mForceSetScissor = true; |
| 1954 | mForceSetViewport = true; |
daniel@transgaming.com | 9a06737 | 2012-12-20 20:55:24 +0000 | [diff] [blame] | 1955 | mForceSetBlendState = true; |
| 1956 | |
shannon.woods@transgaming.com | 233fe95 | 2013-01-25 21:51:57 +0000 | [diff] [blame] | 1957 | for (unsigned int i = 0; i < gl::IMPLEMENTATION_MAX_VERTEX_TEXTURE_IMAGE_UNITS; i++) |
daniel@transgaming.com | e33c8bf | 2013-01-11 04:11:33 +0000 | [diff] [blame] | 1958 | { |
| 1959 | mForceSetVertexSamplerStates[i] = true; |
| 1960 | mCurVertexTextureSerials[i] = 0; |
| 1961 | } |
| 1962 | for (unsigned int i = 0; i < gl::MAX_TEXTURE_IMAGE_UNITS; i++) |
| 1963 | { |
| 1964 | mForceSetPixelSamplerStates[i] = true; |
| 1965 | mCurPixelTextureSerials[i] = 0; |
| 1966 | } |
| 1967 | |
daniel@transgaming.com | 9a06737 | 2012-12-20 20:55:24 +0000 | [diff] [blame] | 1968 | mAppliedIBSerial = 0; |
daniel@transgaming.com | e499141 | 2012-12-20 20:55:34 +0000 | [diff] [blame] | 1969 | mAppliedProgramBinarySerial = 0; |
daniel@transgaming.com | ed36abd | 2013-01-11 21:15:58 +0000 | [diff] [blame] | 1970 | mDxUniformsDirty = true; |
daniel@transgaming.com | 67094ee | 2012-11-28 20:53:04 +0000 | [diff] [blame] | 1971 | |
| 1972 | mVertexDeclarationCache.markStateDirty(); |
daniel@transgaming.com | c43a605 | 2012-11-28 19:41:51 +0000 | [diff] [blame] | 1973 | } |
| 1974 | |
daniel@transgaming.com | 2507f41 | 2012-10-31 18:46:48 +0000 | [diff] [blame] | 1975 | void Renderer9::releaseDeviceResources() |
daniel@transgaming.com | ef21ab2 | 2012-10-31 17:52:47 +0000 | [diff] [blame] | 1976 | { |
| 1977 | while (!mEventQueryPool.empty()) |
| 1978 | { |
| 1979 | mEventQueryPool.back()->Release(); |
| 1980 | mEventQueryPool.pop_back(); |
| 1981 | } |
daniel@transgaming.com | e4733d7 | 2012-10-31 18:07:01 +0000 | [diff] [blame] | 1982 | |
daniel@transgaming.com | 0393e5b | 2012-11-28 20:55:33 +0000 | [diff] [blame] | 1983 | if (mMaskedClearSavedState) |
| 1984 | { |
| 1985 | mMaskedClearSavedState->Release(); |
| 1986 | mMaskedClearSavedState = NULL; |
| 1987 | } |
| 1988 | |
daniel@transgaming.com | e4733d7 | 2012-10-31 18:07:01 +0000 | [diff] [blame] | 1989 | mVertexShaderCache.clear(); |
| 1990 | mPixelShaderCache.clear(); |
daniel@transgaming.com | 67094ee | 2012-11-28 20:53:04 +0000 | [diff] [blame] | 1991 | |
daniel@transgaming.com | e569fc5 | 2012-11-28 20:56:02 +0000 | [diff] [blame] | 1992 | delete mBlit; |
| 1993 | mBlit = NULL; |
| 1994 | |
daniel@transgaming.com | 67094ee | 2012-11-28 20:53:04 +0000 | [diff] [blame] | 1995 | delete mVertexDataManager; |
| 1996 | mVertexDataManager = NULL; |
daniel@transgaming.com | 91207b7 | 2012-11-28 20:56:43 +0000 | [diff] [blame] | 1997 | |
| 1998 | delete mIndexDataManager; |
| 1999 | mIndexDataManager = NULL; |
| 2000 | |
| 2001 | delete mLineLoopIB; |
| 2002 | mLineLoopIB = NULL; |
daniel@transgaming.com | e4e1a33 | 2012-12-20 20:52:09 +0000 | [diff] [blame] | 2003 | |
| 2004 | for (int i = 0; i < NUM_NULL_COLORBUFFER_CACHE_ENTRIES; i++) |
| 2005 | { |
| 2006 | delete mNullColorbufferCache[i].buffer; |
| 2007 | mNullColorbufferCache[i].buffer = NULL; |
| 2008 | } |
| 2009 | |
daniel@transgaming.com | ef21ab2 | 2012-10-31 17:52:47 +0000 | [diff] [blame] | 2010 | } |
| 2011 | |
| 2012 | |
shannon.woods@transgaming.com | eb049e2 | 2013-02-28 23:04:49 +0000 | [diff] [blame] | 2013 | void Renderer9::notifyDeviceLost() |
daniel@transgaming.com | 621ce05 | 2012-10-31 17:52:29 +0000 | [diff] [blame] | 2014 | { |
| 2015 | mDeviceLost = true; |
shannon.woods@transgaming.com | eb049e2 | 2013-02-28 23:04:49 +0000 | [diff] [blame] | 2016 | mDisplay->notifyDeviceLost(); |
daniel@transgaming.com | 621ce05 | 2012-10-31 17:52:29 +0000 | [diff] [blame] | 2017 | } |
| 2018 | |
daniel@transgaming.com | 2507f41 | 2012-10-31 18:46:48 +0000 | [diff] [blame] | 2019 | bool Renderer9::isDeviceLost() |
daniel@transgaming.com | 621ce05 | 2012-10-31 17:52:29 +0000 | [diff] [blame] | 2020 | { |
| 2021 | return mDeviceLost; |
| 2022 | } |
| 2023 | |
daniel@transgaming.com | f688c0d | 2012-10-31 17:52:57 +0000 | [diff] [blame] | 2024 | // set notify to true to broadcast a message to all contexts of the device loss |
daniel@transgaming.com | 2507f41 | 2012-10-31 18:46:48 +0000 | [diff] [blame] | 2025 | bool Renderer9::testDeviceLost(bool notify) |
daniel@transgaming.com | 621ce05 | 2012-10-31 17:52:29 +0000 | [diff] [blame] | 2026 | { |
shannon.woods@transgaming.com | a4ba59c | 2013-02-28 23:14:38 +0000 | [diff] [blame] | 2027 | HRESULT status = S_OK; |
daniel@transgaming.com | 621ce05 | 2012-10-31 17:52:29 +0000 | [diff] [blame] | 2028 | |
| 2029 | if (mDeviceEx) |
| 2030 | { |
shannon.woods@transgaming.com | a4ba59c | 2013-02-28 23:14:38 +0000 | [diff] [blame] | 2031 | status = mDeviceEx->CheckDeviceState(NULL); |
daniel@transgaming.com | 621ce05 | 2012-10-31 17:52:29 +0000 | [diff] [blame] | 2032 | } |
| 2033 | else if (mDevice) |
| 2034 | { |
shannon.woods@transgaming.com | a4ba59c | 2013-02-28 23:14:38 +0000 | [diff] [blame] | 2035 | status = mDevice->TestCooperativeLevel(); |
daniel@transgaming.com | 621ce05 | 2012-10-31 17:52:29 +0000 | [diff] [blame] | 2036 | } |
| 2037 | else |
| 2038 | { |
| 2039 | // No device yet, so no reset required |
| 2040 | } |
| 2041 | |
shannon.woods@transgaming.com | a4ba59c | 2013-02-28 23:14:38 +0000 | [diff] [blame] | 2042 | bool isLost = FAILED(status) || d3d9::isDeviceLostError(status); |
| 2043 | |
daniel@transgaming.com | 621ce05 | 2012-10-31 17:52:29 +0000 | [diff] [blame] | 2044 | if (isLost) |
| 2045 | { |
| 2046 | // ensure we note the device loss -- |
shannon.woods@transgaming.com | 779aa26 | 2013-02-28 23:04:58 +0000 | [diff] [blame] | 2047 | // we'll probably get this done again by notifyDeviceLost |
| 2048 | // but best to remember it! |
daniel@transgaming.com | 621ce05 | 2012-10-31 17:52:29 +0000 | [diff] [blame] | 2049 | // Note that we don't want to clear the device loss status here |
| 2050 | // -- this needs to be done by resetDevice |
| 2051 | mDeviceLost = true; |
daniel@transgaming.com | f688c0d | 2012-10-31 17:52:57 +0000 | [diff] [blame] | 2052 | if (notify) |
| 2053 | { |
shannon.woods@transgaming.com | eb049e2 | 2013-02-28 23:04:49 +0000 | [diff] [blame] | 2054 | notifyDeviceLost(); |
daniel@transgaming.com | f688c0d | 2012-10-31 17:52:57 +0000 | [diff] [blame] | 2055 | } |
daniel@transgaming.com | 621ce05 | 2012-10-31 17:52:29 +0000 | [diff] [blame] | 2056 | } |
| 2057 | |
| 2058 | return isLost; |
| 2059 | } |
| 2060 | |
daniel@transgaming.com | 2507f41 | 2012-10-31 18:46:48 +0000 | [diff] [blame] | 2061 | bool Renderer9::testDeviceResettable() |
daniel@transgaming.com | 621ce05 | 2012-10-31 17:52:29 +0000 | [diff] [blame] | 2062 | { |
| 2063 | HRESULT status = D3D_OK; |
| 2064 | |
| 2065 | if (mDeviceEx) |
| 2066 | { |
| 2067 | status = mDeviceEx->CheckDeviceState(NULL); |
| 2068 | } |
| 2069 | else if (mDevice) |
| 2070 | { |
| 2071 | status = mDevice->TestCooperativeLevel(); |
| 2072 | } |
| 2073 | |
shannon.woods@transgaming.com | a4ba59c | 2013-02-28 23:14:38 +0000 | [diff] [blame] | 2074 | // On D3D9Ex, DEVICELOST represents a hung device that needs to be restarted |
shannon.woods@transgaming.com | a4ba59c | 2013-02-28 23:14:38 +0000 | [diff] [blame] | 2075 | // DEVICEREMOVED indicates the device has been stopped and must be recreated |
daniel@transgaming.com | 621ce05 | 2012-10-31 17:52:29 +0000 | [diff] [blame] | 2076 | switch (status) |
| 2077 | { |
| 2078 | case D3DERR_DEVICENOTRESET: |
| 2079 | case D3DERR_DEVICEHUNG: |
| 2080 | return true; |
shannon.woods@transgaming.com | a4ba59c | 2013-02-28 23:14:38 +0000 | [diff] [blame] | 2081 | case D3DERR_DEVICELOST: |
| 2082 | return (mDeviceEx != NULL); |
| 2083 | case D3DERR_DEVICEREMOVED: |
| 2084 | UNIMPLEMENTED(); |
| 2085 | return false; |
daniel@transgaming.com | 621ce05 | 2012-10-31 17:52:29 +0000 | [diff] [blame] | 2086 | default: |
| 2087 | return false; |
| 2088 | } |
| 2089 | } |
| 2090 | |
daniel@transgaming.com | 2507f41 | 2012-10-31 18:46:48 +0000 | [diff] [blame] | 2091 | bool Renderer9::resetDevice() |
daniel@transgaming.com | 621ce05 | 2012-10-31 17:52:29 +0000 | [diff] [blame] | 2092 | { |
daniel@transgaming.com | ef21ab2 | 2012-10-31 17:52:47 +0000 | [diff] [blame] | 2093 | releaseDeviceResources(); |
| 2094 | |
daniel@transgaming.com | 621ce05 | 2012-10-31 17:52:29 +0000 | [diff] [blame] | 2095 | D3DPRESENT_PARAMETERS presentParameters = getDefaultPresentParameters(); |
| 2096 | |
| 2097 | HRESULT result = D3D_OK; |
daniel@transgaming.com | f688c0d | 2012-10-31 17:52:57 +0000 | [diff] [blame] | 2098 | bool lost = testDeviceLost(false); |
daniel@transgaming.com | 621ce05 | 2012-10-31 17:52:29 +0000 | [diff] [blame] | 2099 | int attempts = 3; |
| 2100 | |
| 2101 | while (lost && attempts > 0) |
| 2102 | { |
| 2103 | if (mDeviceEx) |
| 2104 | { |
| 2105 | Sleep(500); // Give the graphics driver some CPU time |
| 2106 | result = mDeviceEx->ResetEx(&presentParameters, NULL); |
| 2107 | } |
| 2108 | else |
| 2109 | { |
| 2110 | result = mDevice->TestCooperativeLevel(); |
| 2111 | while (result == D3DERR_DEVICELOST) |
| 2112 | { |
| 2113 | Sleep(100); // Give the graphics driver some CPU time |
| 2114 | result = mDevice->TestCooperativeLevel(); |
| 2115 | } |
| 2116 | |
| 2117 | if (result == D3DERR_DEVICENOTRESET) |
| 2118 | { |
| 2119 | result = mDevice->Reset(&presentParameters); |
| 2120 | } |
| 2121 | } |
| 2122 | |
daniel@transgaming.com | f688c0d | 2012-10-31 17:52:57 +0000 | [diff] [blame] | 2123 | lost = testDeviceLost(false); |
daniel@transgaming.com | 621ce05 | 2012-10-31 17:52:29 +0000 | [diff] [blame] | 2124 | attempts --; |
| 2125 | } |
| 2126 | |
| 2127 | if (FAILED(result)) |
| 2128 | { |
| 2129 | ERR("Reset/ResetEx failed multiple times: 0x%08X", result); |
| 2130 | return false; |
| 2131 | } |
| 2132 | |
| 2133 | // reset device defaults |
| 2134 | initializeDevice(); |
| 2135 | mDeviceLost = false; |
| 2136 | |
| 2137 | return true; |
| 2138 | } |
| 2139 | |
daniel@transgaming.com | 2507f41 | 2012-10-31 18:46:48 +0000 | [diff] [blame] | 2140 | DWORD Renderer9::getAdapterVendor() const |
daniel@transgaming.com | 4ca789e | 2012-10-31 18:46:40 +0000 | [diff] [blame] | 2141 | { |
| 2142 | return mAdapterIdentifier.VendorId; |
| 2143 | } |
| 2144 | |
daniel@transgaming.com | ca1ac1f | 2013-01-11 04:13:05 +0000 | [diff] [blame] | 2145 | std::string Renderer9::getRendererDescription() const |
daniel@transgaming.com | 4ca789e | 2012-10-31 18:46:40 +0000 | [diff] [blame] | 2146 | { |
daniel@transgaming.com | ca1ac1f | 2013-01-11 04:13:05 +0000 | [diff] [blame] | 2147 | std::ostringstream rendererString; |
| 2148 | |
| 2149 | rendererString << mAdapterIdentifier.Description; |
| 2150 | if (getShareHandleSupport()) |
| 2151 | { |
| 2152 | rendererString << " Direct3D9Ex"; |
| 2153 | } |
| 2154 | else |
| 2155 | { |
| 2156 | rendererString << " Direct3D9"; |
| 2157 | } |
| 2158 | |
| 2159 | rendererString << " vs_" << D3DSHADER_VERSION_MAJOR(mDeviceCaps.VertexShaderVersion) << "_" << D3DSHADER_VERSION_MINOR(mDeviceCaps.VertexShaderVersion); |
| 2160 | rendererString << " ps_" << D3DSHADER_VERSION_MAJOR(mDeviceCaps.PixelShaderVersion) << "_" << D3DSHADER_VERSION_MINOR(mDeviceCaps.PixelShaderVersion); |
| 2161 | |
| 2162 | return rendererString.str(); |
daniel@transgaming.com | 4ca789e | 2012-10-31 18:46:40 +0000 | [diff] [blame] | 2163 | } |
| 2164 | |
daniel@transgaming.com | 2507f41 | 2012-10-31 18:46:48 +0000 | [diff] [blame] | 2165 | GUID Renderer9::getAdapterIdentifier() const |
daniel@transgaming.com | 4ca789e | 2012-10-31 18:46:40 +0000 | [diff] [blame] | 2166 | { |
| 2167 | return mAdapterIdentifier.DeviceIdentifier; |
| 2168 | } |
| 2169 | |
Geoff Lang | 61e49a5 | 2013-05-29 10:22:58 -0400 | [diff] [blame] | 2170 | Renderer9::MultisampleSupportInfo Renderer9::getMultiSampleSupport(D3DFORMAT format) |
daniel@transgaming.com | 621ce05 | 2012-10-31 17:52:29 +0000 | [diff] [blame] | 2171 | { |
Geoff Lang | 61e49a5 | 2013-05-29 10:22:58 -0400 | [diff] [blame] | 2172 | MultisampleSupportInfo support = { 0 }; |
daniel@transgaming.com | 621ce05 | 2012-10-31 17:52:29 +0000 | [diff] [blame] | 2173 | |
Geoff Lang | 61e49a5 | 2013-05-29 10:22:58 -0400 | [diff] [blame] | 2174 | for (unsigned int multiSampleIndex = 0; multiSampleIndex < ArraySize(support.supportedSamples); multiSampleIndex++) |
| 2175 | { |
| 2176 | HRESULT result = mD3d9->CheckDeviceMultiSampleType(mAdapter, mDeviceType, format, TRUE, |
| 2177 | (D3DMULTISAMPLE_TYPE)multiSampleIndex, NULL); |
| 2178 | |
| 2179 | if (SUCCEEDED(result)) |
| 2180 | { |
| 2181 | support.supportedSamples[multiSampleIndex] = true; |
| 2182 | if (multiSampleIndex != D3DMULTISAMPLE_NONMASKABLE) |
| 2183 | { |
| 2184 | support.maxSupportedSamples = std::max(support.maxSupportedSamples, multiSampleIndex); |
| 2185 | } |
| 2186 | } |
| 2187 | else |
| 2188 | { |
| 2189 | support.supportedSamples[multiSampleIndex] = false; |
| 2190 | } |
daniel@transgaming.com | 621ce05 | 2012-10-31 17:52:29 +0000 | [diff] [blame] | 2191 | } |
Geoff Lang | 61e49a5 | 2013-05-29 10:22:58 -0400 | [diff] [blame] | 2192 | |
| 2193 | return support; |
daniel@transgaming.com | 621ce05 | 2012-10-31 17:52:29 +0000 | [diff] [blame] | 2194 | } |
| 2195 | |
shannon.woods@transgaming.com | bec04bf | 2013-01-25 21:53:52 +0000 | [diff] [blame] | 2196 | bool Renderer9::getBGRATextureSupport() const |
| 2197 | { |
| 2198 | // DirectX 9 always supports BGRA |
| 2199 | return true; |
| 2200 | } |
| 2201 | |
shannonwoods@chromium.org | 89200d9 | 2013-05-30 00:07:50 +0000 | [diff] [blame] | 2202 | bool Renderer9::getDXT1TextureSupport() const |
daniel@transgaming.com | 621ce05 | 2012-10-31 17:52:29 +0000 | [diff] [blame] | 2203 | { |
daniel@transgaming.com | 669c995 | 2013-01-11 04:08:16 +0000 | [diff] [blame] | 2204 | return mDXT1TextureSupport; |
daniel@transgaming.com | 621ce05 | 2012-10-31 17:52:29 +0000 | [diff] [blame] | 2205 | } |
| 2206 | |
shannonwoods@chromium.org | 89200d9 | 2013-05-30 00:07:50 +0000 | [diff] [blame] | 2207 | bool Renderer9::getDXT3TextureSupport() const |
daniel@transgaming.com | 621ce05 | 2012-10-31 17:52:29 +0000 | [diff] [blame] | 2208 | { |
daniel@transgaming.com | 669c995 | 2013-01-11 04:08:16 +0000 | [diff] [blame] | 2209 | return mDXT3TextureSupport; |
daniel@transgaming.com | 621ce05 | 2012-10-31 17:52:29 +0000 | [diff] [blame] | 2210 | } |
| 2211 | |
shannonwoods@chromium.org | 89200d9 | 2013-05-30 00:07:50 +0000 | [diff] [blame] | 2212 | bool Renderer9::getDXT5TextureSupport() const |
daniel@transgaming.com | 621ce05 | 2012-10-31 17:52:29 +0000 | [diff] [blame] | 2213 | { |
daniel@transgaming.com | 669c995 | 2013-01-11 04:08:16 +0000 | [diff] [blame] | 2214 | return mDXT5TextureSupport; |
daniel@transgaming.com | 621ce05 | 2012-10-31 17:52:29 +0000 | [diff] [blame] | 2215 | } |
| 2216 | |
daniel@transgaming.com | 2507f41 | 2012-10-31 18:46:48 +0000 | [diff] [blame] | 2217 | bool Renderer9::getDepthTextureSupport() const |
daniel@transgaming.com | 621ce05 | 2012-10-31 17:52:29 +0000 | [diff] [blame] | 2218 | { |
daniel@transgaming.com | 669c995 | 2013-01-11 04:08:16 +0000 | [diff] [blame] | 2219 | return mDepthTextureSupport; |
daniel@transgaming.com | 621ce05 | 2012-10-31 17:52:29 +0000 | [diff] [blame] | 2220 | } |
| 2221 | |
shannonwoods@chromium.org | 89200d9 | 2013-05-30 00:07:50 +0000 | [diff] [blame] | 2222 | bool Renderer9::getFloat32TextureSupport() const |
daniel@transgaming.com | 621ce05 | 2012-10-31 17:52:29 +0000 | [diff] [blame] | 2223 | { |
daniel@transgaming.com | 669c995 | 2013-01-11 04:08:16 +0000 | [diff] [blame] | 2224 | return mFloat32TextureSupport; |
daniel@transgaming.com | 621ce05 | 2012-10-31 17:52:29 +0000 | [diff] [blame] | 2225 | } |
| 2226 | |
shannonwoods@chromium.org | 89200d9 | 2013-05-30 00:07:50 +0000 | [diff] [blame] | 2227 | bool Renderer9::getFloat32TextureFilteringSupport() const |
daniel@transgaming.com | 621ce05 | 2012-10-31 17:52:29 +0000 | [diff] [blame] | 2228 | { |
shannonwoods@chromium.org | 89200d9 | 2013-05-30 00:07:50 +0000 | [diff] [blame] | 2229 | return mFloat32FilterSupport; |
| 2230 | } |
| 2231 | |
| 2232 | bool Renderer9::getFloat32TextureRenderingSupport() const |
| 2233 | { |
| 2234 | return mFloat32RenderSupport; |
| 2235 | } |
| 2236 | |
| 2237 | bool Renderer9::getFloat16TextureSupport() const |
| 2238 | { |
daniel@transgaming.com | 669c995 | 2013-01-11 04:08:16 +0000 | [diff] [blame] | 2239 | return mFloat16TextureSupport; |
daniel@transgaming.com | 621ce05 | 2012-10-31 17:52:29 +0000 | [diff] [blame] | 2240 | } |
| 2241 | |
shannonwoods@chromium.org | 89200d9 | 2013-05-30 00:07:50 +0000 | [diff] [blame] | 2242 | bool Renderer9::getFloat16TextureFilteringSupport() const |
| 2243 | { |
| 2244 | return mFloat16FilterSupport; |
| 2245 | } |
| 2246 | |
| 2247 | bool Renderer9::getFloat16TextureRenderingSupport() const |
| 2248 | { |
| 2249 | return mFloat16RenderSupport; |
| 2250 | } |
| 2251 | |
Geoff Lang | d42cf4e | 2013-06-05 16:09:17 -0400 | [diff] [blame] | 2252 | bool Renderer9::getRGB565TextureSupport() const |
| 2253 | { |
| 2254 | return mRGB565TextureSupport; |
| 2255 | } |
| 2256 | |
shannonwoods@chromium.org | 89200d9 | 2013-05-30 00:07:50 +0000 | [diff] [blame] | 2257 | bool Renderer9::getLuminanceTextureSupport() const |
daniel@transgaming.com | 621ce05 | 2012-10-31 17:52:29 +0000 | [diff] [blame] | 2258 | { |
daniel@transgaming.com | 669c995 | 2013-01-11 04:08:16 +0000 | [diff] [blame] | 2259 | return mLuminanceTextureSupport; |
daniel@transgaming.com | 621ce05 | 2012-10-31 17:52:29 +0000 | [diff] [blame] | 2260 | } |
| 2261 | |
shannonwoods@chromium.org | 89200d9 | 2013-05-30 00:07:50 +0000 | [diff] [blame] | 2262 | bool Renderer9::getLuminanceAlphaTextureSupport() const |
daniel@transgaming.com | 621ce05 | 2012-10-31 17:52:29 +0000 | [diff] [blame] | 2263 | { |
daniel@transgaming.com | 669c995 | 2013-01-11 04:08:16 +0000 | [diff] [blame] | 2264 | return mLuminanceAlphaTextureSupport; |
daniel@transgaming.com | 621ce05 | 2012-10-31 17:52:29 +0000 | [diff] [blame] | 2265 | } |
| 2266 | |
daniel@transgaming.com | 2507f41 | 2012-10-31 18:46:48 +0000 | [diff] [blame] | 2267 | bool Renderer9::getTextureFilterAnisotropySupport() const |
daniel@transgaming.com | 621ce05 | 2012-10-31 17:52:29 +0000 | [diff] [blame] | 2268 | { |
daniel@transgaming.com | ba0570e | 2012-10-31 18:07:39 +0000 | [diff] [blame] | 2269 | return mSupportsTextureFilterAnisotropy; |
| 2270 | } |
| 2271 | |
daniel@transgaming.com | 2507f41 | 2012-10-31 18:46:48 +0000 | [diff] [blame] | 2272 | float Renderer9::getTextureMaxAnisotropy() const |
daniel@transgaming.com | ba0570e | 2012-10-31 18:07:39 +0000 | [diff] [blame] | 2273 | { |
| 2274 | if (mSupportsTextureFilterAnisotropy) |
daniel@transgaming.com | 621ce05 | 2012-10-31 17:52:29 +0000 | [diff] [blame] | 2275 | { |
shannon.woods%transgaming.com@gtempaccount.com | 6b73191 | 2013-04-13 03:35:19 +0000 | [diff] [blame] | 2276 | return static_cast<float>(mDeviceCaps.MaxAnisotropy); |
daniel@transgaming.com | 621ce05 | 2012-10-31 17:52:29 +0000 | [diff] [blame] | 2277 | } |
| 2278 | return 1.0f; |
| 2279 | } |
| 2280 | |
shannonwoods@chromium.org | 89200d9 | 2013-05-30 00:07:50 +0000 | [diff] [blame] | 2281 | bool Renderer9::getEventQuerySupport() const |
daniel@transgaming.com | 621ce05 | 2012-10-31 17:52:29 +0000 | [diff] [blame] | 2282 | { |
daniel@transgaming.com | 669c995 | 2013-01-11 04:08:16 +0000 | [diff] [blame] | 2283 | return mEventQuerySupport; |
daniel@transgaming.com | 621ce05 | 2012-10-31 17:52:29 +0000 | [diff] [blame] | 2284 | } |
| 2285 | |
shannon.woods@transgaming.com | 233fe95 | 2013-01-25 21:51:57 +0000 | [diff] [blame] | 2286 | unsigned int Renderer9::getMaxVertexTextureImageUnits() const |
daniel@transgaming.com | 621ce05 | 2012-10-31 17:52:29 +0000 | [diff] [blame] | 2287 | { |
shannon.woods@transgaming.com | 233fe95 | 2013-01-25 21:51:57 +0000 | [diff] [blame] | 2288 | META_ASSERT(MAX_TEXTURE_IMAGE_UNITS_VTF_SM3 <= gl::IMPLEMENTATION_MAX_VERTEX_TEXTURE_IMAGE_UNITS); |
| 2289 | return mVertexTextureSupport ? MAX_TEXTURE_IMAGE_UNITS_VTF_SM3 : 0; |
daniel@transgaming.com | 621ce05 | 2012-10-31 17:52:29 +0000 | [diff] [blame] | 2290 | } |
| 2291 | |
shannon.woods@transgaming.com | 76cd88c | 2013-01-25 21:54:36 +0000 | [diff] [blame] | 2292 | unsigned int Renderer9::getMaxCombinedTextureImageUnits() const |
| 2293 | { |
| 2294 | return gl::MAX_TEXTURE_IMAGE_UNITS + getMaxVertexTextureImageUnits(); |
| 2295 | } |
| 2296 | |
shannon.woods@transgaming.com | d8136cb | 2013-02-28 23:14:44 +0000 | [diff] [blame] | 2297 | unsigned int Renderer9::getReservedVertexUniformVectors() const |
shannon.woods@transgaming.com | 254317d | 2013-01-25 21:54:09 +0000 | [diff] [blame] | 2298 | { |
shannon.woods@transgaming.com | 42832a6 | 2013-02-28 23:18:38 +0000 | [diff] [blame] | 2299 | return 2; // dx_ViewAdjust and dx_DepthRange. |
shannon.woods@transgaming.com | 254317d | 2013-01-25 21:54:09 +0000 | [diff] [blame] | 2300 | } |
| 2301 | |
shannon.woods@transgaming.com | d8136cb | 2013-02-28 23:14:44 +0000 | [diff] [blame] | 2302 | unsigned int Renderer9::getReservedFragmentUniformVectors() const |
shannon.woods@transgaming.com | 254317d | 2013-01-25 21:54:09 +0000 | [diff] [blame] | 2303 | { |
shannon.woods@transgaming.com | 42832a6 | 2013-02-28 23:18:38 +0000 | [diff] [blame] | 2304 | return 3; // dx_ViewCoords, dx_DepthFront and dx_DepthRange. |
shannon.woods@transgaming.com | 254317d | 2013-01-25 21:54:09 +0000 | [diff] [blame] | 2305 | } |
| 2306 | |
shannon.woods@transgaming.com | d8136cb | 2013-02-28 23:14:44 +0000 | [diff] [blame] | 2307 | unsigned int Renderer9::getMaxVertexUniformVectors() const |
shannon.woods@transgaming.com | 28d268e | 2013-01-25 21:54:26 +0000 | [diff] [blame] | 2308 | { |
shannon.woods@transgaming.com | d8136cb | 2013-02-28 23:14:44 +0000 | [diff] [blame] | 2309 | return MAX_VERTEX_CONSTANT_VECTORS_D3D9 - getReservedVertexUniformVectors(); |
| 2310 | } |
| 2311 | |
| 2312 | unsigned int Renderer9::getMaxFragmentUniformVectors() const |
| 2313 | { |
| 2314 | const int maxPixelConstantVectors = (getMajorShaderModel() >= 3) ? MAX_PIXEL_CONSTANT_VECTORS_SM3 : MAX_PIXEL_CONSTANT_VECTORS_SM2; |
| 2315 | |
| 2316 | return maxPixelConstantVectors - getReservedFragmentUniformVectors(); |
| 2317 | } |
| 2318 | |
| 2319 | unsigned int Renderer9::getMaxVaryingVectors() const |
| 2320 | { |
| 2321 | return (getMajorShaderModel() >= 3) ? MAX_VARYING_VECTORS_SM3 : MAX_VARYING_VECTORS_SM2; |
shannon.woods@transgaming.com | 28d268e | 2013-01-25 21:54:26 +0000 | [diff] [blame] | 2322 | } |
| 2323 | |
shannon.woods%transgaming.com@gtempaccount.com | 3f72ce3 | 2013-04-13 03:36:43 +0000 | [diff] [blame] | 2324 | unsigned int Renderer9::getMaxVertexShaderUniformBuffers() const |
| 2325 | { |
| 2326 | return 0; |
| 2327 | } |
| 2328 | |
| 2329 | unsigned int Renderer9::getMaxFragmentShaderUniformBuffers() const |
| 2330 | { |
| 2331 | return 0; |
| 2332 | } |
| 2333 | |
shannonwoods@chromium.org | 2b54422 | 2013-05-30 00:11:12 +0000 | [diff] [blame] | 2334 | unsigned int Renderer9::getReservedVertexUniformBuffers() const |
| 2335 | { |
| 2336 | return 0; |
| 2337 | } |
| 2338 | |
| 2339 | unsigned int Renderer9::getReservedFragmentUniformBuffers() const |
| 2340 | { |
| 2341 | return 0; |
| 2342 | } |
| 2343 | |
shannon.woods%transgaming.com@gtempaccount.com | 3f72ce3 | 2013-04-13 03:36:43 +0000 | [diff] [blame] | 2344 | unsigned int Renderer9::getMaxTransformFeedbackBuffers() const |
| 2345 | { |
| 2346 | return 0; |
| 2347 | } |
| 2348 | |
shannonwoods@chromium.org | 33e798f | 2013-05-30 00:05:05 +0000 | [diff] [blame] | 2349 | unsigned int Renderer9::getMaxUniformBufferSize() const |
| 2350 | { |
| 2351 | return 0; |
| 2352 | } |
| 2353 | |
daniel@transgaming.com | 2507f41 | 2012-10-31 18:46:48 +0000 | [diff] [blame] | 2354 | bool Renderer9::getNonPower2TextureSupport() const |
daniel@transgaming.com | 621ce05 | 2012-10-31 17:52:29 +0000 | [diff] [blame] | 2355 | { |
| 2356 | return mSupportsNonPower2Textures; |
| 2357 | } |
| 2358 | |
daniel@transgaming.com | 2507f41 | 2012-10-31 18:46:48 +0000 | [diff] [blame] | 2359 | bool Renderer9::getOcclusionQuerySupport() const |
daniel@transgaming.com | 621ce05 | 2012-10-31 17:52:29 +0000 | [diff] [blame] | 2360 | { |
daniel@transgaming.com | 669c995 | 2013-01-11 04:08:16 +0000 | [diff] [blame] | 2361 | return mOcclusionQuerySupport; |
daniel@transgaming.com | 621ce05 | 2012-10-31 17:52:29 +0000 | [diff] [blame] | 2362 | } |
| 2363 | |
daniel@transgaming.com | 2507f41 | 2012-10-31 18:46:48 +0000 | [diff] [blame] | 2364 | bool Renderer9::getInstancingSupport() const |
daniel@transgaming.com | 621ce05 | 2012-10-31 17:52:29 +0000 | [diff] [blame] | 2365 | { |
| 2366 | return mDeviceCaps.PixelShaderVersion >= D3DPS_VERSION(3, 0); |
| 2367 | } |
| 2368 | |
daniel@transgaming.com | 2507f41 | 2012-10-31 18:46:48 +0000 | [diff] [blame] | 2369 | bool Renderer9::getShareHandleSupport() const |
daniel@transgaming.com | 313e392 | 2012-10-31 17:52:39 +0000 | [diff] [blame] | 2370 | { |
| 2371 | // PIX doesn't seem to support using share handles, so disable them. |
daniel@transgaming.com | 7cb796e | 2012-10-31 18:46:44 +0000 | [diff] [blame] | 2372 | return (mD3d9Ex != NULL) && !gl::perfActive(); |
daniel@transgaming.com | 313e392 | 2012-10-31 17:52:39 +0000 | [diff] [blame] | 2373 | } |
daniel@transgaming.com | 621ce05 | 2012-10-31 17:52:29 +0000 | [diff] [blame] | 2374 | |
daniel@transgaming.com | 7629bb6 | 2013-01-11 04:12:28 +0000 | [diff] [blame] | 2375 | bool Renderer9::getDerivativeInstructionSupport() const |
| 2376 | { |
| 2377 | return (mDeviceCaps.PS20Caps.Caps & D3DPS20CAPS_GRADIENTINSTRUCTIONS) != 0; |
| 2378 | } |
| 2379 | |
shannon.woods@transgaming.com | 8d2f086 | 2013-02-28 23:09:19 +0000 | [diff] [blame] | 2380 | bool Renderer9::getPostSubBufferSupport() const |
| 2381 | { |
| 2382 | return true; |
| 2383 | } |
| 2384 | |
daniel@transgaming.com | 9549bea | 2012-11-28 20:57:23 +0000 | [diff] [blame] | 2385 | int Renderer9::getMajorShaderModel() const |
daniel@transgaming.com | 5f4c136 | 2012-10-31 18:29:00 +0000 | [diff] [blame] | 2386 | { |
daniel@transgaming.com | 9549bea | 2012-11-28 20:57:23 +0000 | [diff] [blame] | 2387 | return D3DSHADER_VERSION_MAJOR(mDeviceCaps.PixelShaderVersion); |
daniel@transgaming.com | 5f4c136 | 2012-10-31 18:29:00 +0000 | [diff] [blame] | 2388 | } |
| 2389 | |
daniel@transgaming.com | 2507f41 | 2012-10-31 18:46:48 +0000 | [diff] [blame] | 2390 | float Renderer9::getMaxPointSize() const |
daniel@transgaming.com | 5f4c136 | 2012-10-31 18:29:00 +0000 | [diff] [blame] | 2391 | { |
shannon.woods@transgaming.com | bd8c10c | 2013-01-25 21:15:03 +0000 | [diff] [blame] | 2392 | // Point size clamped at 1.0f for SM2 |
| 2393 | return getMajorShaderModel() == 3 ? mDeviceCaps.MaxPointSize : 1.0f; |
daniel@transgaming.com | 5f4c136 | 2012-10-31 18:29:00 +0000 | [diff] [blame] | 2394 | } |
| 2395 | |
shannon.woods@transgaming.com | 8ce2f8f | 2013-02-28 23:07:10 +0000 | [diff] [blame] | 2396 | int Renderer9::getMaxViewportDimension() const |
| 2397 | { |
| 2398 | int maxTextureDimension = std::min(std::min(getMaxTextureWidth(), getMaxTextureHeight()), |
shannon.woods%transgaming.com@gtempaccount.com | c1fdf6b | 2013-04-13 03:44:41 +0000 | [diff] [blame] | 2399 | (int)gl::IMPLEMENTATION_MAX_2D_TEXTURE_SIZE); |
shannon.woods@transgaming.com | 8ce2f8f | 2013-02-28 23:07:10 +0000 | [diff] [blame] | 2400 | return maxTextureDimension; |
| 2401 | } |
| 2402 | |
daniel@transgaming.com | 2507f41 | 2012-10-31 18:46:48 +0000 | [diff] [blame] | 2403 | int Renderer9::getMaxTextureWidth() const |
daniel@transgaming.com | 5f4c136 | 2012-10-31 18:29:00 +0000 | [diff] [blame] | 2404 | { |
| 2405 | return (int)mDeviceCaps.MaxTextureWidth; |
| 2406 | } |
| 2407 | |
daniel@transgaming.com | 2507f41 | 2012-10-31 18:46:48 +0000 | [diff] [blame] | 2408 | int Renderer9::getMaxTextureHeight() const |
daniel@transgaming.com | 5f4c136 | 2012-10-31 18:29:00 +0000 | [diff] [blame] | 2409 | { |
| 2410 | return (int)mDeviceCaps.MaxTextureHeight; |
| 2411 | } |
| 2412 | |
shannon.woods%transgaming.com@gtempaccount.com | c1fdf6b | 2013-04-13 03:44:41 +0000 | [diff] [blame] | 2413 | int Renderer9::getMaxTextureDepth() const |
| 2414 | { |
| 2415 | // 3D textures are not available in the D3D9 backend. |
| 2416 | return 1; |
| 2417 | } |
| 2418 | |
shannon.woods%transgaming.com@gtempaccount.com | a98a811 | 2013-04-13 03:45:57 +0000 | [diff] [blame] | 2419 | int Renderer9::getMaxTextureArrayLayers() const |
| 2420 | { |
| 2421 | // 2D array textures are not available in the D3D9 backend. |
| 2422 | return 1; |
| 2423 | } |
| 2424 | |
daniel@transgaming.com | 2507f41 | 2012-10-31 18:46:48 +0000 | [diff] [blame] | 2425 | bool Renderer9::get32BitIndexSupport() const |
daniel@transgaming.com | 5f4c136 | 2012-10-31 18:29:00 +0000 | [diff] [blame] | 2426 | { |
| 2427 | return mDeviceCaps.MaxVertexIndex >= (1 << 16); |
| 2428 | } |
| 2429 | |
daniel@transgaming.com | 2507f41 | 2012-10-31 18:46:48 +0000 | [diff] [blame] | 2430 | DWORD Renderer9::getCapsDeclTypes() const |
daniel@transgaming.com | 5f4c136 | 2012-10-31 18:29:00 +0000 | [diff] [blame] | 2431 | { |
| 2432 | return mDeviceCaps.DeclTypes; |
| 2433 | } |
| 2434 | |
daniel@transgaming.com | 2507f41 | 2012-10-31 18:46:48 +0000 | [diff] [blame] | 2435 | int Renderer9::getMinSwapInterval() const |
daniel@transgaming.com | 5f4c136 | 2012-10-31 18:29:00 +0000 | [diff] [blame] | 2436 | { |
| 2437 | return mMinSwapInterval; |
| 2438 | } |
| 2439 | |
daniel@transgaming.com | 2507f41 | 2012-10-31 18:46:48 +0000 | [diff] [blame] | 2440 | int Renderer9::getMaxSwapInterval() const |
daniel@transgaming.com | 5f4c136 | 2012-10-31 18:29:00 +0000 | [diff] [blame] | 2441 | { |
| 2442 | return mMaxSwapInterval; |
| 2443 | } |
| 2444 | |
daniel@transgaming.com | 2507f41 | 2012-10-31 18:46:48 +0000 | [diff] [blame] | 2445 | int Renderer9::getMaxSupportedSamples() const |
daniel@transgaming.com | b783398 | 2012-10-31 18:31:46 +0000 | [diff] [blame] | 2446 | { |
| 2447 | return mMaxSupportedSamples; |
| 2448 | } |
| 2449 | |
Geoff Lang | 0e120e3 | 2013-05-29 10:23:55 -0400 | [diff] [blame] | 2450 | GLsizei Renderer9::getMaxSupportedFormatSamples(GLint internalFormat) const |
| 2451 | { |
| 2452 | D3DFORMAT format = gl_d3d9::GetTexureFormat(internalFormat, this); |
| 2453 | MultisampleSupportMap::const_iterator itr = mMultiSampleSupport.find(format); |
| 2454 | return (itr != mMultiSampleSupport.end()) ? mMaxSupportedSamples : 0; |
| 2455 | } |
| 2456 | |
daniel@transgaming.com | 2507f41 | 2012-10-31 18:46:48 +0000 | [diff] [blame] | 2457 | int Renderer9::getNearestSupportedSamples(D3DFORMAT format, int requested) const |
daniel@transgaming.com | b783398 | 2012-10-31 18:31:46 +0000 | [diff] [blame] | 2458 | { |
| 2459 | if (requested == 0) |
| 2460 | { |
| 2461 | return requested; |
| 2462 | } |
| 2463 | |
Geoff Lang | 61e49a5 | 2013-05-29 10:22:58 -0400 | [diff] [blame] | 2464 | MultisampleSupportMap::const_iterator itr = mMultiSampleSupport.find(format); |
daniel@transgaming.com | b783398 | 2012-10-31 18:31:46 +0000 | [diff] [blame] | 2465 | if (itr == mMultiSampleSupport.end()) |
| 2466 | { |
daniel@transgaming.com | 9295562 | 2012-10-31 18:38:41 +0000 | [diff] [blame] | 2467 | if (format == D3DFMT_UNKNOWN) |
| 2468 | return 0; |
daniel@transgaming.com | b783398 | 2012-10-31 18:31:46 +0000 | [diff] [blame] | 2469 | return -1; |
| 2470 | } |
| 2471 | |
Geoff Lang | 61e49a5 | 2013-05-29 10:22:58 -0400 | [diff] [blame] | 2472 | for (unsigned int i = requested; i < ArraySize(itr->second.supportedSamples); ++i) |
daniel@transgaming.com | b783398 | 2012-10-31 18:31:46 +0000 | [diff] [blame] | 2473 | { |
Geoff Lang | 61e49a5 | 2013-05-29 10:22:58 -0400 | [diff] [blame] | 2474 | if (itr->second.supportedSamples[i] && i != D3DMULTISAMPLE_NONMASKABLE) |
daniel@transgaming.com | b783398 | 2012-10-31 18:31:46 +0000 | [diff] [blame] | 2475 | { |
| 2476 | return i; |
| 2477 | } |
| 2478 | } |
| 2479 | |
| 2480 | return -1; |
| 2481 | } |
| 2482 | |
shannon.woods%transgaming.com@gtempaccount.com | b290ac1 | 2013-04-13 03:28:15 +0000 | [diff] [blame] | 2483 | unsigned int Renderer9::getMaxRenderTargets() const |
| 2484 | { |
| 2485 | // we do not support MRT in d3d9 |
| 2486 | return 1; |
| 2487 | } |
| 2488 | |
daniel@transgaming.com | a957168 | 2012-11-28 19:33:08 +0000 | [diff] [blame] | 2489 | D3DFORMAT Renderer9::ConvertTextureInternalFormat(GLint internalformat) |
| 2490 | { |
| 2491 | switch (internalformat) |
| 2492 | { |
| 2493 | case GL_DEPTH_COMPONENT16: |
| 2494 | case GL_DEPTH_COMPONENT32_OES: |
| 2495 | case GL_DEPTH24_STENCIL8_OES: |
| 2496 | return D3DFMT_INTZ; |
| 2497 | case GL_COMPRESSED_RGB_S3TC_DXT1_EXT: |
| 2498 | case GL_COMPRESSED_RGBA_S3TC_DXT1_EXT: |
| 2499 | return D3DFMT_DXT1; |
| 2500 | case GL_COMPRESSED_RGBA_S3TC_DXT3_ANGLE: |
| 2501 | return D3DFMT_DXT3; |
| 2502 | case GL_COMPRESSED_RGBA_S3TC_DXT5_ANGLE: |
| 2503 | return D3DFMT_DXT5; |
| 2504 | case GL_RGBA32F_EXT: |
| 2505 | case GL_RGB32F_EXT: |
| 2506 | case GL_ALPHA32F_EXT: |
| 2507 | case GL_LUMINANCE32F_EXT: |
| 2508 | case GL_LUMINANCE_ALPHA32F_EXT: |
| 2509 | return D3DFMT_A32B32G32R32F; |
| 2510 | case GL_RGBA16F_EXT: |
| 2511 | case GL_RGB16F_EXT: |
| 2512 | case GL_ALPHA16F_EXT: |
| 2513 | case GL_LUMINANCE16F_EXT: |
| 2514 | case GL_LUMINANCE_ALPHA16F_EXT: |
| 2515 | return D3DFMT_A16B16G16R16F; |
| 2516 | case GL_LUMINANCE8_EXT: |
| 2517 | if (getLuminanceTextureSupport()) |
| 2518 | { |
| 2519 | return D3DFMT_L8; |
| 2520 | } |
| 2521 | break; |
| 2522 | case GL_LUMINANCE8_ALPHA8_EXT: |
| 2523 | if (getLuminanceAlphaTextureSupport()) |
| 2524 | { |
| 2525 | return D3DFMT_A8L8; |
| 2526 | } |
| 2527 | break; |
| 2528 | case GL_RGB8_OES: |
| 2529 | case GL_RGB565: |
| 2530 | return D3DFMT_X8R8G8B8; |
| 2531 | } |
| 2532 | |
| 2533 | return D3DFMT_A8R8G8B8; |
| 2534 | } |
| 2535 | |
daniel@transgaming.com | 87705f8 | 2012-12-20 21:10:45 +0000 | [diff] [blame] | 2536 | bool Renderer9::copyToRenderTarget(TextureStorageInterface2D *dest, TextureStorageInterface2D *source) |
daniel@transgaming.com | 1d80eee | 2012-11-28 19:33:31 +0000 | [diff] [blame] | 2537 | { |
| 2538 | bool result = false; |
| 2539 | |
| 2540 | if (source && dest) |
| 2541 | { |
daniel@transgaming.com | 87705f8 | 2012-12-20 21:10:45 +0000 | [diff] [blame] | 2542 | TextureStorage9_2D *source9 = TextureStorage9_2D::makeTextureStorage9_2D(source->getStorageInstance()); |
| 2543 | TextureStorage9_2D *dest9 = TextureStorage9_2D::makeTextureStorage9_2D(dest->getStorageInstance()); |
daniel@transgaming.com | 34da397 | 2012-12-20 21:10:29 +0000 | [diff] [blame] | 2544 | |
| 2545 | int levels = source9->levelCount(); |
daniel@transgaming.com | 1d80eee | 2012-11-28 19:33:31 +0000 | [diff] [blame] | 2546 | for (int i = 0; i < levels; ++i) |
| 2547 | { |
daniel@transgaming.com | 34da397 | 2012-12-20 21:10:29 +0000 | [diff] [blame] | 2548 | IDirect3DSurface9 *srcSurf = source9->getSurfaceLevel(i, false); |
| 2549 | IDirect3DSurface9 *dstSurf = dest9->getSurfaceLevel(i, false); |
daniel@transgaming.com | 1d80eee | 2012-11-28 19:33:31 +0000 | [diff] [blame] | 2550 | |
daniel@transgaming.com | 34da397 | 2012-12-20 21:10:29 +0000 | [diff] [blame] | 2551 | result = copyToRenderTarget(dstSurf, srcSurf, source9->isManaged()); |
daniel@transgaming.com | 1d80eee | 2012-11-28 19:33:31 +0000 | [diff] [blame] | 2552 | |
| 2553 | if (srcSurf) srcSurf->Release(); |
| 2554 | if (dstSurf) dstSurf->Release(); |
| 2555 | |
| 2556 | if (!result) |
| 2557 | return false; |
| 2558 | } |
| 2559 | } |
| 2560 | |
| 2561 | return result; |
| 2562 | } |
| 2563 | |
daniel@transgaming.com | 87705f8 | 2012-12-20 21:10:45 +0000 | [diff] [blame] | 2564 | bool Renderer9::copyToRenderTarget(TextureStorageInterfaceCube *dest, TextureStorageInterfaceCube *source) |
daniel@transgaming.com | 1d80eee | 2012-11-28 19:33:31 +0000 | [diff] [blame] | 2565 | { |
| 2566 | bool result = false; |
| 2567 | |
| 2568 | if (source && dest) |
| 2569 | { |
daniel@transgaming.com | 87705f8 | 2012-12-20 21:10:45 +0000 | [diff] [blame] | 2570 | TextureStorage9_Cube *source9 = TextureStorage9_Cube::makeTextureStorage9_Cube(source->getStorageInstance()); |
| 2571 | TextureStorage9_Cube *dest9 = TextureStorage9_Cube::makeTextureStorage9_Cube(dest->getStorageInstance()); |
daniel@transgaming.com | 34da397 | 2012-12-20 21:10:29 +0000 | [diff] [blame] | 2572 | int levels = source9->levelCount(); |
daniel@transgaming.com | 1d80eee | 2012-11-28 19:33:31 +0000 | [diff] [blame] | 2573 | for (int f = 0; f < 6; f++) |
| 2574 | { |
| 2575 | for (int i = 0; i < levels; i++) |
| 2576 | { |
daniel@transgaming.com | 34da397 | 2012-12-20 21:10:29 +0000 | [diff] [blame] | 2577 | IDirect3DSurface9 *srcSurf = source9->getCubeMapSurface(GL_TEXTURE_CUBE_MAP_POSITIVE_X + f, i, false); |
| 2578 | IDirect3DSurface9 *dstSurf = dest9->getCubeMapSurface(GL_TEXTURE_CUBE_MAP_POSITIVE_X + f, i, true); |
daniel@transgaming.com | 1d80eee | 2012-11-28 19:33:31 +0000 | [diff] [blame] | 2579 | |
daniel@transgaming.com | 34da397 | 2012-12-20 21:10:29 +0000 | [diff] [blame] | 2580 | result = copyToRenderTarget(dstSurf, srcSurf, source9->isManaged()); |
daniel@transgaming.com | 1d80eee | 2012-11-28 19:33:31 +0000 | [diff] [blame] | 2581 | |
| 2582 | if (srcSurf) srcSurf->Release(); |
| 2583 | if (dstSurf) dstSurf->Release(); |
| 2584 | |
| 2585 | if (!result) |
| 2586 | return false; |
| 2587 | } |
| 2588 | } |
| 2589 | } |
| 2590 | |
| 2591 | return result; |
| 2592 | } |
| 2593 | |
shannon.woods%transgaming.com@gtempaccount.com | 414e82a | 2013-04-13 03:44:05 +0000 | [diff] [blame] | 2594 | bool Renderer9::copyToRenderTarget(TextureStorageInterface3D *dest, TextureStorageInterface3D *source) |
| 2595 | { |
| 2596 | // 3D textures are not available in the D3D9 backend. |
| 2597 | UNREACHABLE(); |
| 2598 | return false; |
| 2599 | } |
| 2600 | |
shannon.woods%transgaming.com@gtempaccount.com | 6c86bd5 | 2013-04-13 03:45:45 +0000 | [diff] [blame] | 2601 | bool Renderer9::copyToRenderTarget(TextureStorageInterface2DArray *dest, TextureStorageInterface2DArray *source) |
| 2602 | { |
| 2603 | // 2D array textures are not supported by the D3D9 backend. |
| 2604 | UNREACHABLE(); |
| 2605 | return false; |
| 2606 | } |
| 2607 | |
daniel@transgaming.com | 2507f41 | 2012-10-31 18:46:48 +0000 | [diff] [blame] | 2608 | D3DPOOL Renderer9::getBufferPool(DWORD usage) const |
daniel@transgaming.com | 621ce05 | 2012-10-31 17:52:29 +0000 | [diff] [blame] | 2609 | { |
| 2610 | if (mD3d9Ex != NULL) |
| 2611 | { |
| 2612 | return D3DPOOL_DEFAULT; |
| 2613 | } |
| 2614 | else |
| 2615 | { |
| 2616 | if (!(usage & D3DUSAGE_DYNAMIC)) |
| 2617 | { |
| 2618 | return D3DPOOL_MANAGED; |
| 2619 | } |
| 2620 | } |
| 2621 | |
| 2622 | return D3DPOOL_DEFAULT; |
| 2623 | } |
| 2624 | |
shannon.woods@transgaming.com | 664916b | 2013-01-25 21:50:32 +0000 | [diff] [blame] | 2625 | bool Renderer9::copyImage(gl::Framebuffer *framebuffer, const gl::Rectangle &sourceRect, GLenum destFormat, |
daniel@transgaming.com | 87705f8 | 2012-12-20 21:10:45 +0000 | [diff] [blame] | 2626 | GLint xoffset, GLint yoffset, TextureStorageInterface2D *storage, GLint level) |
daniel@transgaming.com | de8a7ff | 2012-11-28 19:34:13 +0000 | [diff] [blame] | 2627 | { |
shannon.woods@transgaming.com | 664916b | 2013-01-25 21:50:32 +0000 | [diff] [blame] | 2628 | RECT rect; |
| 2629 | rect.left = sourceRect.x; |
| 2630 | rect.top = sourceRect.y; |
| 2631 | rect.right = sourceRect.x + sourceRect.width; |
| 2632 | rect.bottom = sourceRect.y + sourceRect.height; |
| 2633 | |
| 2634 | return mBlit->copy(framebuffer, rect, destFormat, xoffset, yoffset, storage, level); |
daniel@transgaming.com | de8a7ff | 2012-11-28 19:34:13 +0000 | [diff] [blame] | 2635 | } |
| 2636 | |
shannon.woods@transgaming.com | 664916b | 2013-01-25 21:50:32 +0000 | [diff] [blame] | 2637 | bool Renderer9::copyImage(gl::Framebuffer *framebuffer, const gl::Rectangle &sourceRect, GLenum destFormat, |
daniel@transgaming.com | 87705f8 | 2012-12-20 21:10:45 +0000 | [diff] [blame] | 2638 | GLint xoffset, GLint yoffset, TextureStorageInterfaceCube *storage, GLenum target, GLint level) |
daniel@transgaming.com | de8a7ff | 2012-11-28 19:34:13 +0000 | [diff] [blame] | 2639 | { |
shannon.woods@transgaming.com | 664916b | 2013-01-25 21:50:32 +0000 | [diff] [blame] | 2640 | RECT rect; |
| 2641 | rect.left = sourceRect.x; |
| 2642 | rect.top = sourceRect.y; |
| 2643 | rect.right = sourceRect.x + sourceRect.width; |
| 2644 | rect.bottom = sourceRect.y + sourceRect.height; |
| 2645 | |
| 2646 | return mBlit->copy(framebuffer, rect, destFormat, xoffset, yoffset, storage, target, level); |
daniel@transgaming.com | de8a7ff | 2012-11-28 19:34:13 +0000 | [diff] [blame] | 2647 | } |
| 2648 | |
shannon.woods%transgaming.com@gtempaccount.com | 414e82a | 2013-04-13 03:44:05 +0000 | [diff] [blame] | 2649 | bool Renderer9::copyImage(gl::Framebuffer *framebuffer, const gl::Rectangle &sourceRect, GLenum destFormat, |
| 2650 | GLint xoffset, GLint yoffset, GLint zOffset, TextureStorageInterface3D *storage, GLint level) |
| 2651 | { |
| 2652 | // 3D textures are not available in the D3D9 backend. |
| 2653 | UNREACHABLE(); |
| 2654 | return false; |
| 2655 | } |
| 2656 | |
shannon.woods%transgaming.com@gtempaccount.com | 6c86bd5 | 2013-04-13 03:45:45 +0000 | [diff] [blame] | 2657 | bool Renderer9::copyImage(gl::Framebuffer *framebuffer, const gl::Rectangle &sourceRect, GLenum destFormat, |
| 2658 | GLint xoffset, GLint yoffset, GLint zOffset, TextureStorageInterface2DArray *storage, GLint level) |
| 2659 | { |
| 2660 | // 2D array textures are not available in the D3D9 backend. |
| 2661 | UNREACHABLE(); |
| 2662 | return false; |
| 2663 | } |
| 2664 | |
shannon.woods@transgaming.com | ea4a0c6 | 2013-02-28 23:06:29 +0000 | [diff] [blame] | 2665 | bool Renderer9::blitRect(gl::Framebuffer *readFramebuffer, const gl::Rectangle &readRect, gl::Framebuffer *drawFramebuffer, const gl::Rectangle &drawRect, |
Geoff Lang | 758d5b2 | 2013-06-11 11:42:50 -0400 | [diff] [blame^] | 2666 | bool blitRenderTarget, bool blitDepthStencil, GLenum filter) |
daniel@transgaming.com | 6c87217 | 2012-11-28 19:39:33 +0000 | [diff] [blame] | 2667 | { |
Geoff Lang | 758d5b2 | 2013-06-11 11:42:50 -0400 | [diff] [blame^] | 2668 | ASSERT(filter == GL_NEAREST); |
| 2669 | |
daniel@transgaming.com | 6c87217 | 2012-11-28 19:39:33 +0000 | [diff] [blame] | 2670 | endScene(); |
| 2671 | |
| 2672 | if (blitRenderTarget) |
| 2673 | { |
shannon.woods%transgaming.com@gtempaccount.com | 89ae113 | 2013-04-13 03:28:43 +0000 | [diff] [blame] | 2674 | gl::Renderbuffer *readBuffer = readFramebuffer->getColorbuffer(0); |
| 2675 | gl::Renderbuffer *drawBuffer = drawFramebuffer->getColorbuffer(0); |
daniel@transgaming.com | d186dc7 | 2012-11-28 19:40:16 +0000 | [diff] [blame] | 2676 | RenderTarget9 *readRenderTarget = NULL; |
| 2677 | RenderTarget9 *drawRenderTarget = NULL; |
| 2678 | IDirect3DSurface9* readSurface = NULL; |
| 2679 | IDirect3DSurface9* drawSurface = NULL; |
| 2680 | |
| 2681 | if (readBuffer) |
| 2682 | { |
| 2683 | readRenderTarget = RenderTarget9::makeRenderTarget9(readBuffer->getRenderTarget()); |
| 2684 | } |
| 2685 | if (drawBuffer) |
| 2686 | { |
| 2687 | drawRenderTarget = RenderTarget9::makeRenderTarget9(drawBuffer->getRenderTarget()); |
| 2688 | } |
| 2689 | |
| 2690 | if (readRenderTarget) |
| 2691 | { |
| 2692 | readSurface = readRenderTarget->getSurface(); |
| 2693 | } |
| 2694 | if (drawRenderTarget) |
| 2695 | { |
| 2696 | drawSurface = drawRenderTarget->getSurface(); |
| 2697 | } |
| 2698 | |
| 2699 | if (!readSurface || !drawSurface) |
| 2700 | { |
| 2701 | ERR("Failed to retrieve the render target."); |
shannon.woods@transgaming.com | 779aa26 | 2013-02-28 23:04:58 +0000 | [diff] [blame] | 2702 | return gl::error(GL_OUT_OF_MEMORY, false); |
daniel@transgaming.com | d186dc7 | 2012-11-28 19:40:16 +0000 | [diff] [blame] | 2703 | } |
daniel@transgaming.com | 6c87217 | 2012-11-28 19:39:33 +0000 | [diff] [blame] | 2704 | |
shannon.woods@transgaming.com | ea4a0c6 | 2013-02-28 23:06:29 +0000 | [diff] [blame] | 2705 | RECT srcRect; |
| 2706 | srcRect.left = readRect.x; |
| 2707 | srcRect.right = readRect.x + readRect.width; |
| 2708 | srcRect.top = readRect.y; |
| 2709 | srcRect.bottom = readRect.y + readRect.height; |
daniel@transgaming.com | 6c87217 | 2012-11-28 19:39:33 +0000 | [diff] [blame] | 2710 | |
shannon.woods@transgaming.com | ea4a0c6 | 2013-02-28 23:06:29 +0000 | [diff] [blame] | 2711 | RECT dstRect; |
| 2712 | dstRect.left = drawRect.x; |
| 2713 | dstRect.right = drawRect.x + drawRect.width; |
| 2714 | dstRect.top = drawRect.y; |
| 2715 | dstRect.bottom = drawRect.y + drawRect.height; |
daniel@transgaming.com | 6c87217 | 2012-11-28 19:39:33 +0000 | [diff] [blame] | 2716 | |
shannon.woods@transgaming.com | ea4a0c6 | 2013-02-28 23:06:29 +0000 | [diff] [blame] | 2717 | HRESULT result = mDevice->StretchRect(readSurface, &srcRect, drawSurface, &dstRect, D3DTEXF_NONE); |
daniel@transgaming.com | 6c87217 | 2012-11-28 19:39:33 +0000 | [diff] [blame] | 2718 | |
daniel@transgaming.com | d186dc7 | 2012-11-28 19:40:16 +0000 | [diff] [blame] | 2719 | readSurface->Release(); |
| 2720 | drawSurface->Release(); |
daniel@transgaming.com | 6c87217 | 2012-11-28 19:39:33 +0000 | [diff] [blame] | 2721 | |
| 2722 | if (FAILED(result)) |
| 2723 | { |
| 2724 | ERR("BlitFramebufferANGLE failed: StretchRect returned %x.", result); |
| 2725 | return false; |
| 2726 | } |
| 2727 | } |
| 2728 | |
| 2729 | if (blitDepthStencil) |
| 2730 | { |
daniel@transgaming.com | d186dc7 | 2012-11-28 19:40:16 +0000 | [diff] [blame] | 2731 | gl::Renderbuffer *readBuffer = readFramebuffer->getDepthOrStencilbuffer(); |
| 2732 | gl::Renderbuffer *drawBuffer = drawFramebuffer->getDepthOrStencilbuffer(); |
| 2733 | RenderTarget9 *readDepthStencil = NULL; |
| 2734 | RenderTarget9 *drawDepthStencil = NULL; |
| 2735 | IDirect3DSurface9* readSurface = NULL; |
| 2736 | IDirect3DSurface9* drawSurface = NULL; |
daniel@transgaming.com | 6c87217 | 2012-11-28 19:39:33 +0000 | [diff] [blame] | 2737 | |
daniel@transgaming.com | d186dc7 | 2012-11-28 19:40:16 +0000 | [diff] [blame] | 2738 | if (readBuffer) |
| 2739 | { |
| 2740 | readDepthStencil = RenderTarget9::makeRenderTarget9(readBuffer->getDepthStencil()); |
| 2741 | } |
| 2742 | if (drawBuffer) |
| 2743 | { |
| 2744 | drawDepthStencil = RenderTarget9::makeRenderTarget9(drawBuffer->getDepthStencil()); |
| 2745 | } |
daniel@transgaming.com | 6c87217 | 2012-11-28 19:39:33 +0000 | [diff] [blame] | 2746 | |
daniel@transgaming.com | d186dc7 | 2012-11-28 19:40:16 +0000 | [diff] [blame] | 2747 | if (readDepthStencil) |
| 2748 | { |
| 2749 | readSurface = readDepthStencil->getSurface(); |
| 2750 | } |
| 2751 | if (drawDepthStencil) |
| 2752 | { |
| 2753 | drawSurface = drawDepthStencil->getSurface(); |
| 2754 | } |
| 2755 | |
| 2756 | if (!readSurface || !drawSurface) |
| 2757 | { |
| 2758 | ERR("Failed to retrieve the render target."); |
shannon.woods@transgaming.com | 779aa26 | 2013-02-28 23:04:58 +0000 | [diff] [blame] | 2759 | return gl::error(GL_OUT_OF_MEMORY, false); |
daniel@transgaming.com | d186dc7 | 2012-11-28 19:40:16 +0000 | [diff] [blame] | 2760 | } |
| 2761 | |
| 2762 | HRESULT result = mDevice->StretchRect(readSurface, NULL, drawSurface, NULL, D3DTEXF_NONE); |
| 2763 | |
| 2764 | readSurface->Release(); |
| 2765 | drawSurface->Release(); |
daniel@transgaming.com | 6c87217 | 2012-11-28 19:39:33 +0000 | [diff] [blame] | 2766 | |
| 2767 | if (FAILED(result)) |
| 2768 | { |
| 2769 | ERR("BlitFramebufferANGLE failed: StretchRect returned %x.", result); |
| 2770 | return false; |
| 2771 | } |
| 2772 | } |
| 2773 | |
| 2774 | return true; |
| 2775 | } |
| 2776 | |
| 2777 | void Renderer9::readPixels(gl::Framebuffer *framebuffer, GLint x, GLint y, GLsizei width, GLsizei height, GLenum format, GLenum type, |
| 2778 | GLsizei outputPitch, bool packReverseRowOrder, GLint packAlignment, void* pixels) |
| 2779 | { |
daniel@transgaming.com | d186dc7 | 2012-11-28 19:40:16 +0000 | [diff] [blame] | 2780 | RenderTarget9 *renderTarget = NULL; |
| 2781 | IDirect3DSurface9 *surface = NULL; |
shannon.woods%transgaming.com@gtempaccount.com | 89ae113 | 2013-04-13 03:28:43 +0000 | [diff] [blame] | 2782 | gl::Renderbuffer *colorbuffer = framebuffer->getColorbuffer(0); |
daniel@transgaming.com | d186dc7 | 2012-11-28 19:40:16 +0000 | [diff] [blame] | 2783 | |
| 2784 | if (colorbuffer) |
daniel@transgaming.com | 6c87217 | 2012-11-28 19:39:33 +0000 | [diff] [blame] | 2785 | { |
daniel@transgaming.com | d186dc7 | 2012-11-28 19:40:16 +0000 | [diff] [blame] | 2786 | renderTarget = RenderTarget9::makeRenderTarget9(colorbuffer->getRenderTarget()); |
| 2787 | } |
| 2788 | |
| 2789 | if (renderTarget) |
| 2790 | { |
| 2791 | surface = renderTarget->getSurface(); |
| 2792 | } |
| 2793 | |
| 2794 | if (!surface) |
| 2795 | { |
| 2796 | // context must be lost |
| 2797 | return; |
daniel@transgaming.com | 6c87217 | 2012-11-28 19:39:33 +0000 | [diff] [blame] | 2798 | } |
| 2799 | |
| 2800 | D3DSURFACE_DESC desc; |
daniel@transgaming.com | d186dc7 | 2012-11-28 19:40:16 +0000 | [diff] [blame] | 2801 | surface->GetDesc(&desc); |
daniel@transgaming.com | 6c87217 | 2012-11-28 19:39:33 +0000 | [diff] [blame] | 2802 | |
| 2803 | if (desc.MultiSampleType != D3DMULTISAMPLE_NONE) |
| 2804 | { |
| 2805 | UNIMPLEMENTED(); // FIXME: Requires resolve using StretchRect into non-multisampled render target |
daniel@transgaming.com | d186dc7 | 2012-11-28 19:40:16 +0000 | [diff] [blame] | 2806 | surface->Release(); |
shannon.woods@transgaming.com | 779aa26 | 2013-02-28 23:04:58 +0000 | [diff] [blame] | 2807 | return gl::error(GL_OUT_OF_MEMORY); |
daniel@transgaming.com | 6c87217 | 2012-11-28 19:39:33 +0000 | [diff] [blame] | 2808 | } |
| 2809 | |
| 2810 | HRESULT result; |
| 2811 | IDirect3DSurface9 *systemSurface = NULL; |
| 2812 | bool directToPixels = !packReverseRowOrder && packAlignment <= 4 && getShareHandleSupport() && |
| 2813 | x == 0 && y == 0 && UINT(width) == desc.Width && UINT(height) == desc.Height && |
| 2814 | desc.Format == D3DFMT_A8R8G8B8 && format == GL_BGRA_EXT && type == GL_UNSIGNED_BYTE; |
| 2815 | if (directToPixels) |
| 2816 | { |
| 2817 | // Use the pixels ptr as a shared handle to write directly into client's memory |
| 2818 | result = mDevice->CreateOffscreenPlainSurface(desc.Width, desc.Height, desc.Format, |
| 2819 | D3DPOOL_SYSTEMMEM, &systemSurface, &pixels); |
| 2820 | if (FAILED(result)) |
| 2821 | { |
| 2822 | // Try again without the shared handle |
| 2823 | directToPixels = false; |
| 2824 | } |
| 2825 | } |
| 2826 | |
| 2827 | if (!directToPixels) |
| 2828 | { |
| 2829 | result = mDevice->CreateOffscreenPlainSurface(desc.Width, desc.Height, desc.Format, |
| 2830 | D3DPOOL_SYSTEMMEM, &systemSurface, NULL); |
| 2831 | if (FAILED(result)) |
| 2832 | { |
| 2833 | ASSERT(result == D3DERR_OUTOFVIDEOMEMORY || result == E_OUTOFMEMORY); |
daniel@transgaming.com | d186dc7 | 2012-11-28 19:40:16 +0000 | [diff] [blame] | 2834 | surface->Release(); |
shannon.woods@transgaming.com | 779aa26 | 2013-02-28 23:04:58 +0000 | [diff] [blame] | 2835 | return gl::error(GL_OUT_OF_MEMORY); |
daniel@transgaming.com | 6c87217 | 2012-11-28 19:39:33 +0000 | [diff] [blame] | 2836 | } |
| 2837 | } |
| 2838 | |
daniel@transgaming.com | d186dc7 | 2012-11-28 19:40:16 +0000 | [diff] [blame] | 2839 | result = mDevice->GetRenderTargetData(surface, systemSurface); |
| 2840 | surface->Release(); |
| 2841 | surface = NULL; |
daniel@transgaming.com | 6c87217 | 2012-11-28 19:39:33 +0000 | [diff] [blame] | 2842 | |
| 2843 | if (FAILED(result)) |
| 2844 | { |
| 2845 | systemSurface->Release(); |
| 2846 | |
| 2847 | // It turns out that D3D will sometimes produce more error |
| 2848 | // codes than those documented. |
shannon.woods@transgaming.com | eb049e2 | 2013-02-28 23:04:49 +0000 | [diff] [blame] | 2849 | if (d3d9::isDeviceLostError(result)) |
| 2850 | { |
| 2851 | notifyDeviceLost(); |
shannon.woods@transgaming.com | 779aa26 | 2013-02-28 23:04:58 +0000 | [diff] [blame] | 2852 | return gl::error(GL_OUT_OF_MEMORY); |
shannon.woods@transgaming.com | eb049e2 | 2013-02-28 23:04:49 +0000 | [diff] [blame] | 2853 | } |
daniel@transgaming.com | 6c87217 | 2012-11-28 19:39:33 +0000 | [diff] [blame] | 2854 | else |
| 2855 | { |
| 2856 | UNREACHABLE(); |
| 2857 | return; |
| 2858 | } |
| 2859 | |
| 2860 | } |
| 2861 | |
| 2862 | if (directToPixels) |
| 2863 | { |
| 2864 | systemSurface->Release(); |
| 2865 | return; |
| 2866 | } |
| 2867 | |
| 2868 | RECT rect; |
| 2869 | rect.left = gl::clamp(x, 0L, static_cast<LONG>(desc.Width)); |
| 2870 | rect.top = gl::clamp(y, 0L, static_cast<LONG>(desc.Height)); |
| 2871 | rect.right = gl::clamp(x + width, 0L, static_cast<LONG>(desc.Width)); |
| 2872 | rect.bottom = gl::clamp(y + height, 0L, static_cast<LONG>(desc.Height)); |
| 2873 | |
| 2874 | D3DLOCKED_RECT lock; |
| 2875 | result = systemSurface->LockRect(&lock, &rect, D3DLOCK_READONLY); |
| 2876 | |
| 2877 | if (FAILED(result)) |
| 2878 | { |
| 2879 | UNREACHABLE(); |
| 2880 | systemSurface->Release(); |
| 2881 | |
| 2882 | return; // No sensible error to generate |
| 2883 | } |
| 2884 | |
daniel@transgaming.com | 6c87217 | 2012-11-28 19:39:33 +0000 | [diff] [blame] | 2885 | unsigned char *source; |
| 2886 | int inputPitch; |
| 2887 | if (packReverseRowOrder) |
| 2888 | { |
| 2889 | source = ((unsigned char*)lock.pBits) + lock.Pitch * (rect.bottom - rect.top - 1); |
| 2890 | inputPitch = -lock.Pitch; |
| 2891 | } |
| 2892 | else |
| 2893 | { |
| 2894 | source = (unsigned char*)lock.pBits; |
| 2895 | inputPitch = lock.Pitch; |
| 2896 | } |
| 2897 | |
Geoff Lang | 697ad3e | 2013-06-04 10:11:28 -0400 | [diff] [blame] | 2898 | GLuint clientVersion = getCurrentClientVersion(); |
daniel@transgaming.com | 6c87217 | 2012-11-28 19:39:33 +0000 | [diff] [blame] | 2899 | |
Geoff Lang | 697ad3e | 2013-06-04 10:11:28 -0400 | [diff] [blame] | 2900 | GLint sourceInternalFormat = d3d9_gl::GetInternalFormat(desc.Format); |
| 2901 | GLenum sourceFormat = gl::GetFormat(sourceInternalFormat, clientVersion); |
| 2902 | GLenum sourceType = gl::GetType(sourceInternalFormat, clientVersion); |
daniel@transgaming.com | 6c87217 | 2012-11-28 19:39:33 +0000 | [diff] [blame] | 2903 | |
Geoff Lang | 697ad3e | 2013-06-04 10:11:28 -0400 | [diff] [blame] | 2904 | GLuint sourcePixelSize = gl::GetPixelBytes(sourceInternalFormat, clientVersion); |
| 2905 | |
| 2906 | if (sourceFormat == format && sourceType == type) |
daniel@transgaming.com | 6c87217 | 2012-11-28 19:39:33 +0000 | [diff] [blame] | 2907 | { |
Geoff Lang | 697ad3e | 2013-06-04 10:11:28 -0400 | [diff] [blame] | 2908 | // Direct copy possible |
| 2909 | unsigned char *dest = static_cast<unsigned char*>(pixels); |
| 2910 | for (int y = 0; y < rect.bottom - rect.top; y++) |
daniel@transgaming.com | 6c87217 | 2012-11-28 19:39:33 +0000 | [diff] [blame] | 2911 | { |
Geoff Lang | 697ad3e | 2013-06-04 10:11:28 -0400 | [diff] [blame] | 2912 | memcpy(dest + y * outputPitch, source + y * inputPitch, (rect.right - rect.left) * sourcePixelSize); |
daniel@transgaming.com | 6c87217 | 2012-11-28 19:39:33 +0000 | [diff] [blame] | 2913 | } |
Geoff Lang | 697ad3e | 2013-06-04 10:11:28 -0400 | [diff] [blame] | 2914 | } |
| 2915 | else |
| 2916 | { |
| 2917 | GLint destInternalFormat = gl::GetSizedInternalFormat(format, type, clientVersion); |
| 2918 | GLuint destPixelSize = gl::GetPixelBytes(destInternalFormat, clientVersion); |
| 2919 | GLuint sourcePixelSize = gl::GetPixelBytes(sourceInternalFormat, clientVersion); |
| 2920 | |
| 2921 | ColorCopyFunction fastCopyFunc = d3d9::GetFastCopyFunction(desc.Format, format, type, getCurrentClientVersion()); |
| 2922 | if (fastCopyFunc) |
shannon.woods%transgaming.com@gtempaccount.com | 676dc8f | 2013-04-13 03:35:13 +0000 | [diff] [blame] | 2923 | { |
Geoff Lang | 697ad3e | 2013-06-04 10:11:28 -0400 | [diff] [blame] | 2924 | // Fast copy is possible through some special function |
| 2925 | for (int y = 0; y < rect.bottom - rect.top; y++) |
shannon.woods%transgaming.com@gtempaccount.com | 676dc8f | 2013-04-13 03:35:13 +0000 | [diff] [blame] | 2926 | { |
Geoff Lang | 697ad3e | 2013-06-04 10:11:28 -0400 | [diff] [blame] | 2927 | for (int x = 0; x < rect.right - rect.left; x++) |
| 2928 | { |
| 2929 | void *dest = static_cast<unsigned char*>(pixels) + y * outputPitch + x * destPixelSize; |
| 2930 | void *src = static_cast<unsigned char*>(source) + y * inputPitch + x * sourcePixelSize; |
| 2931 | |
| 2932 | fastCopyFunc(src, dest); |
| 2933 | } |
shannon.woods%transgaming.com@gtempaccount.com | 676dc8f | 2013-04-13 03:35:13 +0000 | [diff] [blame] | 2934 | } |
shannon.woods%transgaming.com@gtempaccount.com | 676dc8f | 2013-04-13 03:35:13 +0000 | [diff] [blame] | 2935 | } |
Geoff Lang | 697ad3e | 2013-06-04 10:11:28 -0400 | [diff] [blame] | 2936 | else |
daniel@transgaming.com | 6c87217 | 2012-11-28 19:39:33 +0000 | [diff] [blame] | 2937 | { |
Geoff Lang | 697ad3e | 2013-06-04 10:11:28 -0400 | [diff] [blame] | 2938 | ColorReadFunction readFunc = d3d9::GetColorReadFunction(desc.Format); |
| 2939 | ColorWriteFunction writeFunc = gl::GetColorWriteFunction(format, type, clientVersion); |
daniel@transgaming.com | 6c87217 | 2012-11-28 19:39:33 +0000 | [diff] [blame] | 2940 | |
Geoff Lang | 697ad3e | 2013-06-04 10:11:28 -0400 | [diff] [blame] | 2941 | gl::ColorF temp; |
| 2942 | |
| 2943 | for (int y = 0; y < rect.bottom - rect.top; y++) |
daniel@transgaming.com | 6c87217 | 2012-11-28 19:39:33 +0000 | [diff] [blame] | 2944 | { |
Geoff Lang | 697ad3e | 2013-06-04 10:11:28 -0400 | [diff] [blame] | 2945 | for (int x = 0; x < rect.right - rect.left; x++) |
daniel@transgaming.com | 6c87217 | 2012-11-28 19:39:33 +0000 | [diff] [blame] | 2946 | { |
Geoff Lang | 697ad3e | 2013-06-04 10:11:28 -0400 | [diff] [blame] | 2947 | void *dest = reinterpret_cast<unsigned char*>(pixels) + y * outputPitch + x * destPixelSize; |
| 2948 | void *src = source + y * inputPitch + x * sourcePixelSize; |
daniel@transgaming.com | 6c87217 | 2012-11-28 19:39:33 +0000 | [diff] [blame] | 2949 | |
Geoff Lang | 697ad3e | 2013-06-04 10:11:28 -0400 | [diff] [blame] | 2950 | // readFunc and writeFunc will be using the same type of color, CopyTexImage |
| 2951 | // will not allow the copy otherwise. |
| 2952 | readFunc(src, &temp); |
| 2953 | writeFunc(&temp, dest); |
daniel@transgaming.com | 6c87217 | 2012-11-28 19:39:33 +0000 | [diff] [blame] | 2954 | } |
daniel@transgaming.com | 6c87217 | 2012-11-28 19:39:33 +0000 | [diff] [blame] | 2955 | } |
| 2956 | } |
| 2957 | } |
| 2958 | |
| 2959 | systemSurface->UnlockRect(); |
| 2960 | |
| 2961 | systemSurface->Release(); |
| 2962 | } |
| 2963 | |
daniel@transgaming.com | f242365 | 2012-11-28 20:53:50 +0000 | [diff] [blame] | 2964 | RenderTarget *Renderer9::createRenderTarget(SwapChain *swapChain, bool depth) |
| 2965 | { |
| 2966 | SwapChain9 *swapChain9 = SwapChain9::makeSwapChain9(swapChain); |
| 2967 | IDirect3DSurface9 *surface = NULL; |
| 2968 | if (depth) |
| 2969 | { |
| 2970 | surface = swapChain9->getDepthStencil(); |
| 2971 | } |
| 2972 | else |
| 2973 | { |
| 2974 | surface = swapChain9->getRenderTarget(); |
| 2975 | } |
| 2976 | |
| 2977 | RenderTarget9 *renderTarget = new RenderTarget9(this, surface); |
| 2978 | |
| 2979 | return renderTarget; |
| 2980 | } |
| 2981 | |
Geoff Lang | a2d97f1 | 2013-06-11 11:44:02 -0400 | [diff] [blame] | 2982 | RenderTarget *Renderer9::createRenderTarget(int width, int height, GLenum format, GLsizei samples) |
daniel@transgaming.com | f242365 | 2012-11-28 20:53:50 +0000 | [diff] [blame] | 2983 | { |
| 2984 | RenderTarget9 *renderTarget = new RenderTarget9(this, width, height, format, samples); |
| 2985 | return renderTarget; |
| 2986 | } |
| 2987 | |
shannon.woods@transgaming.com | 69ff776 | 2013-01-25 21:55:24 +0000 | [diff] [blame] | 2988 | ShaderExecutable *Renderer9::loadExecutable(const void *function, size_t length, rx::ShaderType type) |
daniel@transgaming.com | 5531890 | 2012-11-28 20:58:58 +0000 | [diff] [blame] | 2989 | { |
| 2990 | ShaderExecutable9 *executable = NULL; |
daniel@transgaming.com | 5531890 | 2012-11-28 20:58:58 +0000 | [diff] [blame] | 2991 | |
| 2992 | switch (type) |
| 2993 | { |
shannon.woods@transgaming.com | 69ff776 | 2013-01-25 21:55:24 +0000 | [diff] [blame] | 2994 | case rx::SHADER_VERTEX: |
daniel@transgaming.com | 5531890 | 2012-11-28 20:58:58 +0000 | [diff] [blame] | 2995 | { |
daniel@transgaming.com | 7b18d0c | 2012-11-28 21:04:10 +0000 | [diff] [blame] | 2996 | IDirect3DVertexShader9 *vshader = createVertexShader((DWORD*)function, length); |
daniel@transgaming.com | 5531890 | 2012-11-28 20:58:58 +0000 | [diff] [blame] | 2997 | if (vshader) |
| 2998 | { |
daniel@transgaming.com | 2275f91 | 2012-12-20 21:13:22 +0000 | [diff] [blame] | 2999 | executable = new ShaderExecutable9(function, length, vshader); |
daniel@transgaming.com | 5531890 | 2012-11-28 20:58:58 +0000 | [diff] [blame] | 3000 | } |
| 3001 | } |
| 3002 | break; |
shannon.woods@transgaming.com | 69ff776 | 2013-01-25 21:55:24 +0000 | [diff] [blame] | 3003 | case rx::SHADER_PIXEL: |
daniel@transgaming.com | 5531890 | 2012-11-28 20:58:58 +0000 | [diff] [blame] | 3004 | { |
daniel@transgaming.com | 7b18d0c | 2012-11-28 21:04:10 +0000 | [diff] [blame] | 3005 | IDirect3DPixelShader9 *pshader = createPixelShader((DWORD*)function, length); |
daniel@transgaming.com | 5531890 | 2012-11-28 20:58:58 +0000 | [diff] [blame] | 3006 | if (pshader) |
| 3007 | { |
daniel@transgaming.com | 2275f91 | 2012-12-20 21:13:22 +0000 | [diff] [blame] | 3008 | executable = new ShaderExecutable9(function, length, pshader); |
daniel@transgaming.com | 5531890 | 2012-11-28 20:58:58 +0000 | [diff] [blame] | 3009 | } |
| 3010 | } |
| 3011 | break; |
| 3012 | default: |
| 3013 | UNREACHABLE(); |
| 3014 | break; |
| 3015 | } |
| 3016 | |
| 3017 | return executable; |
| 3018 | } |
| 3019 | |
shannon.woods@transgaming.com | 69ff776 | 2013-01-25 21:55:24 +0000 | [diff] [blame] | 3020 | ShaderExecutable *Renderer9::compileToExecutable(gl::InfoLog &infoLog, const char *shaderHLSL, rx::ShaderType type) |
daniel@transgaming.com | a9c7142 | 2012-11-28 20:58:45 +0000 | [diff] [blame] | 3021 | { |
| 3022 | const char *profile = NULL; |
| 3023 | |
| 3024 | switch (type) |
| 3025 | { |
shannon.woods@transgaming.com | 69ff776 | 2013-01-25 21:55:24 +0000 | [diff] [blame] | 3026 | case rx::SHADER_VERTEX: |
daniel@transgaming.com | a9c7142 | 2012-11-28 20:58:45 +0000 | [diff] [blame] | 3027 | profile = getMajorShaderModel() >= 3 ? "vs_3_0" : "vs_2_0"; |
| 3028 | break; |
shannon.woods@transgaming.com | 69ff776 | 2013-01-25 21:55:24 +0000 | [diff] [blame] | 3029 | case rx::SHADER_PIXEL: |
daniel@transgaming.com | a9c7142 | 2012-11-28 20:58:45 +0000 | [diff] [blame] | 3030 | profile = getMajorShaderModel() >= 3 ? "ps_3_0" : "ps_2_0"; |
| 3031 | break; |
| 3032 | default: |
| 3033 | UNREACHABLE(); |
| 3034 | return NULL; |
| 3035 | } |
| 3036 | |
shannon.woods@transgaming.com | d3d4208 | 2013-02-28 23:14:31 +0000 | [diff] [blame] | 3037 | ID3DBlob *binary = (ID3DBlob*)compileToBinary(infoLog, shaderHLSL, profile, ANGLE_COMPILE_OPTIMIZATION_LEVEL, true); |
daniel@transgaming.com | a9c7142 | 2012-11-28 20:58:45 +0000 | [diff] [blame] | 3038 | if (!binary) |
| 3039 | return NULL; |
| 3040 | |
daniel@transgaming.com | 2275f91 | 2012-12-20 21:13:22 +0000 | [diff] [blame] | 3041 | ShaderExecutable *executable = loadExecutable(binary->GetBufferPointer(), binary->GetBufferSize(), type); |
daniel@transgaming.com | 536dd6e | 2012-11-28 21:00:18 +0000 | [diff] [blame] | 3042 | binary->Release(); |
daniel@transgaming.com | a9c7142 | 2012-11-28 20:58:45 +0000 | [diff] [blame] | 3043 | |
| 3044 | return executable; |
| 3045 | } |
| 3046 | |
daniel@transgaming.com | de8a7ff | 2012-11-28 19:34:13 +0000 | [diff] [blame] | 3047 | bool Renderer9::boxFilter(IDirect3DSurface9 *source, IDirect3DSurface9 *dest) |
| 3048 | { |
| 3049 | return mBlit->boxFilter(source, dest); |
| 3050 | } |
| 3051 | |
daniel@transgaming.com | 2507f41 | 2012-10-31 18:46:48 +0000 | [diff] [blame] | 3052 | D3DPOOL Renderer9::getTexturePool(DWORD usage) const |
daniel@transgaming.com | 621ce05 | 2012-10-31 17:52:29 +0000 | [diff] [blame] | 3053 | { |
| 3054 | if (mD3d9Ex != NULL) |
| 3055 | { |
| 3056 | return D3DPOOL_DEFAULT; |
| 3057 | } |
| 3058 | else |
| 3059 | { |
| 3060 | if (!(usage & (D3DUSAGE_DEPTHSTENCIL | D3DUSAGE_RENDERTARGET))) |
| 3061 | { |
| 3062 | return D3DPOOL_MANAGED; |
| 3063 | } |
| 3064 | } |
| 3065 | |
| 3066 | return D3DPOOL_DEFAULT; |
| 3067 | } |
| 3068 | |
daniel@transgaming.com | 1d80eee | 2012-11-28 19:33:31 +0000 | [diff] [blame] | 3069 | bool Renderer9::copyToRenderTarget(IDirect3DSurface9 *dest, IDirect3DSurface9 *source, bool fromManaged) |
| 3070 | { |
| 3071 | if (source && dest) |
| 3072 | { |
| 3073 | HRESULT result = D3DERR_OUTOFVIDEOMEMORY; |
daniel@transgaming.com | 1d80eee | 2012-11-28 19:33:31 +0000 | [diff] [blame] | 3074 | |
| 3075 | if (fromManaged) |
| 3076 | { |
| 3077 | D3DSURFACE_DESC desc; |
| 3078 | source->GetDesc(&desc); |
| 3079 | |
| 3080 | IDirect3DSurface9 *surf = 0; |
daniel@transgaming.com | 204677a | 2013-01-11 21:16:09 +0000 | [diff] [blame] | 3081 | result = mDevice->CreateOffscreenPlainSurface(desc.Width, desc.Height, desc.Format, D3DPOOL_SYSTEMMEM, &surf, NULL); |
daniel@transgaming.com | 1d80eee | 2012-11-28 19:33:31 +0000 | [diff] [blame] | 3082 | |
| 3083 | if (SUCCEEDED(result)) |
| 3084 | { |
daniel@transgaming.com | 4ba2406 | 2012-12-20 20:54:24 +0000 | [diff] [blame] | 3085 | Image9::copyLockableSurfaces(surf, source); |
daniel@transgaming.com | 204677a | 2013-01-11 21:16:09 +0000 | [diff] [blame] | 3086 | result = mDevice->UpdateSurface(surf, NULL, dest, NULL); |
daniel@transgaming.com | 1d80eee | 2012-11-28 19:33:31 +0000 | [diff] [blame] | 3087 | surf->Release(); |
| 3088 | } |
| 3089 | } |
| 3090 | else |
| 3091 | { |
| 3092 | endScene(); |
daniel@transgaming.com | 204677a | 2013-01-11 21:16:09 +0000 | [diff] [blame] | 3093 | result = mDevice->StretchRect(source, NULL, dest, NULL, D3DTEXF_NONE); |
daniel@transgaming.com | 1d80eee | 2012-11-28 19:33:31 +0000 | [diff] [blame] | 3094 | } |
| 3095 | |
| 3096 | if (FAILED(result)) |
| 3097 | { |
| 3098 | ASSERT(result == D3DERR_OUTOFVIDEOMEMORY || result == E_OUTOFMEMORY); |
| 3099 | return false; |
| 3100 | } |
| 3101 | } |
| 3102 | |
| 3103 | return true; |
daniel@transgaming.com | 67094ee | 2012-11-28 20:53:04 +0000 | [diff] [blame] | 3104 | } |
| 3105 | |
daniel@transgaming.com | 244e183 | 2012-12-20 20:52:35 +0000 | [diff] [blame] | 3106 | Image *Renderer9::createImage() |
| 3107 | { |
daniel@transgaming.com | 4ba2406 | 2012-12-20 20:54:24 +0000 | [diff] [blame] | 3108 | return new Image9(); |
daniel@transgaming.com | 244e183 | 2012-12-20 20:52:35 +0000 | [diff] [blame] | 3109 | } |
| 3110 | |
daniel@transgaming.com | f721fdb | 2012-12-20 20:53:11 +0000 | [diff] [blame] | 3111 | void Renderer9::generateMipmap(Image *dest, Image *src) |
| 3112 | { |
daniel@transgaming.com | 4ba2406 | 2012-12-20 20:54:24 +0000 | [diff] [blame] | 3113 | Image9 *src9 = Image9::makeImage9(src); |
| 3114 | Image9 *dst9 = Image9::makeImage9(dest); |
| 3115 | Image9::generateMipmap(dst9, src9); |
daniel@transgaming.com | f721fdb | 2012-12-20 20:53:11 +0000 | [diff] [blame] | 3116 | } |
| 3117 | |
daniel@transgaming.com | 413d271 | 2012-12-20 21:11:04 +0000 | [diff] [blame] | 3118 | TextureStorage *Renderer9::createTextureStorage2D(SwapChain *swapChain) |
| 3119 | { |
| 3120 | SwapChain9 *swapChain9 = SwapChain9::makeSwapChain9(swapChain); |
| 3121 | return new TextureStorage9_2D(this, swapChain9); |
| 3122 | } |
| 3123 | |
| 3124 | TextureStorage *Renderer9::createTextureStorage2D(int levels, GLenum internalformat, GLenum usage, bool forceRenderable, GLsizei width, GLsizei height) |
| 3125 | { |
| 3126 | return new TextureStorage9_2D(this, levels, internalformat, usage, forceRenderable, width, height); |
| 3127 | } |
| 3128 | |
| 3129 | TextureStorage *Renderer9::createTextureStorageCube(int levels, GLenum internalformat, GLenum usage, bool forceRenderable, int size) |
| 3130 | { |
| 3131 | return new TextureStorage9_Cube(this, levels, internalformat, usage, forceRenderable, size); |
| 3132 | } |
| 3133 | |
shannon.woods%transgaming.com@gtempaccount.com | 2058d64 | 2013-04-13 03:42:50 +0000 | [diff] [blame] | 3134 | TextureStorage *Renderer9::createTextureStorage3D(int levels, GLenum internalformat, GLenum usage, GLsizei width, GLsizei height, GLsizei depth) |
| 3135 | { |
| 3136 | // 3D textures are not supported by the D3D9 backend. |
| 3137 | UNREACHABLE(); |
| 3138 | |
| 3139 | return NULL; |
| 3140 | } |
| 3141 | |
shannon.woods%transgaming.com@gtempaccount.com | 6c86bd5 | 2013-04-13 03:45:45 +0000 | [diff] [blame] | 3142 | TextureStorage *Renderer9::createTextureStorage2DArray(int levels, GLenum internalformat, GLenum usage, GLsizei width, GLsizei height, GLsizei depth) |
| 3143 | { |
| 3144 | // 2D array textures are not supported by the D3D9 backend. |
| 3145 | UNREACHABLE(); |
| 3146 | |
| 3147 | return NULL; |
| 3148 | } |
| 3149 | |
shannonwoods@chromium.org | 6e4f2a6 | 2013-05-30 00:15:19 +0000 | [diff] [blame] | 3150 | bool Renderer9::getLUID(LUID *adapterLuid) const |
| 3151 | { |
| 3152 | adapterLuid->HighPart = 0; |
| 3153 | adapterLuid->LowPart = 0; |
| 3154 | |
| 3155 | if (mD3d9Ex) |
| 3156 | { |
| 3157 | mD3d9Ex->GetAdapterLUID(mAdapter, adapterLuid); |
| 3158 | return true; |
| 3159 | } |
| 3160 | |
| 3161 | return false; |
| 3162 | } |
| 3163 | |
shannon.woods%transgaming.com@gtempaccount.com | 2058d64 | 2013-04-13 03:42:50 +0000 | [diff] [blame] | 3164 | } |