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 | |
Jamie Madill | 57a8972 | 2013-07-02 11:57:03 -0400 | [diff] [blame] | 1341 | GLenum Renderer9::applyVertexBuffer(gl::ProgramBinary *programBinary, const gl::VertexAttribute vertexAttributes[], gl::VertexAttribCurrentValueData currentValues[], |
Jamie Madill | a857c36 | 2013-07-02 11:57:02 -0400 | [diff] [blame] | 1342 | GLint first, GLsizei count, GLsizei instances) |
daniel@transgaming.com | 67094ee | 2012-11-28 20:53:04 +0000 | [diff] [blame] | 1343 | { |
daniel@transgaming.com | 3124048 | 2012-11-28 21:06:41 +0000 | [diff] [blame] | 1344 | TranslatedAttribute attributes[gl::MAX_VERTEX_ATTRIBS]; |
Jamie Madill | a857c36 | 2013-07-02 11:57:02 -0400 | [diff] [blame] | 1345 | GLenum err = mVertexDataManager->prepareVertexData(vertexAttributes, currentValues, programBinary, first, count, attributes, instances); |
daniel@transgaming.com | 67094ee | 2012-11-28 20:53:04 +0000 | [diff] [blame] | 1346 | if (err != GL_NO_ERROR) |
| 1347 | { |
| 1348 | return err; |
| 1349 | } |
| 1350 | |
daniel@transgaming.com | 91207b7 | 2012-11-28 20:56:43 +0000 | [diff] [blame] | 1351 | return mVertexDeclarationCache.applyDeclaration(mDevice, attributes, programBinary, instances, &mRepeatDraw); |
| 1352 | } |
| 1353 | |
| 1354 | // 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] | 1355 | 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] | 1356 | { |
daniel@transgaming.com | 1e3a804 | 2012-12-20 21:09:55 +0000 | [diff] [blame] | 1357 | GLenum err = mIndexDataManager->prepareIndexData(type, count, elementArrayBuffer, indices, indexInfo); |
daniel@transgaming.com | 91207b7 | 2012-11-28 20:56:43 +0000 | [diff] [blame] | 1358 | |
daniel@transgaming.com | 91207b7 | 2012-11-28 20:56:43 +0000 | [diff] [blame] | 1359 | if (err == GL_NO_ERROR) |
| 1360 | { |
shannon.woods@transgaming.com | a1229a3 | 2013-02-28 23:08:40 +0000 | [diff] [blame] | 1361 | // Directly binding the storage buffer is not supported for d3d9 |
| 1362 | ASSERT(indexInfo->storage == NULL); |
| 1363 | |
daniel@transgaming.com | 1e3a804 | 2012-12-20 21:09:55 +0000 | [diff] [blame] | 1364 | if (indexInfo->serial != mAppliedIBSerial) |
daniel@transgaming.com | 91207b7 | 2012-11-28 20:56:43 +0000 | [diff] [blame] | 1365 | { |
daniel@transgaming.com | 1e3a804 | 2012-12-20 21:09:55 +0000 | [diff] [blame] | 1366 | IndexBuffer9* indexBuffer = IndexBuffer9::makeIndexBuffer9(indexInfo->indexBuffer); |
| 1367 | |
| 1368 | mDevice->SetIndices(indexBuffer->getBuffer()); |
| 1369 | mAppliedIBSerial = indexInfo->serial; |
daniel@transgaming.com | 91207b7 | 2012-11-28 20:56:43 +0000 | [diff] [blame] | 1370 | } |
| 1371 | } |
| 1372 | |
| 1373 | return err; |
| 1374 | } |
| 1375 | |
| 1376 | void Renderer9::drawArrays(GLenum mode, GLsizei count, GLsizei instances) |
| 1377 | { |
| 1378 | startScene(); |
| 1379 | |
| 1380 | if (mode == GL_LINE_LOOP) |
| 1381 | { |
| 1382 | drawLineLoop(count, GL_NONE, NULL, 0, NULL); |
| 1383 | } |
| 1384 | else if (instances > 0) |
| 1385 | { |
daniel@transgaming.com | 50cc725 | 2012-12-20 21:09:23 +0000 | [diff] [blame] | 1386 | StaticIndexBufferInterface *countingIB = mIndexDataManager->getCountingIndices(count); |
daniel@transgaming.com | 91207b7 | 2012-11-28 20:56:43 +0000 | [diff] [blame] | 1387 | if (countingIB) |
| 1388 | { |
| 1389 | if (mAppliedIBSerial != countingIB->getSerial()) |
| 1390 | { |
daniel@transgaming.com | 1e3a804 | 2012-12-20 21:09:55 +0000 | [diff] [blame] | 1391 | IndexBuffer9 *indexBuffer = IndexBuffer9::makeIndexBuffer9(countingIB->getIndexBuffer()); |
| 1392 | |
| 1393 | mDevice->SetIndices(indexBuffer->getBuffer()); |
daniel@transgaming.com | 91207b7 | 2012-11-28 20:56:43 +0000 | [diff] [blame] | 1394 | mAppliedIBSerial = countingIB->getSerial(); |
| 1395 | } |
| 1396 | |
| 1397 | for (int i = 0; i < mRepeatDraw; i++) |
| 1398 | { |
| 1399 | mDevice->DrawIndexedPrimitive(mPrimitiveType, 0, 0, count, 0, mPrimitiveCount); |
| 1400 | } |
| 1401 | } |
| 1402 | else |
| 1403 | { |
| 1404 | ERR("Could not create a counting index buffer for glDrawArraysInstanced."); |
shannon.woods@transgaming.com | 779aa26 | 2013-02-28 23:04:58 +0000 | [diff] [blame] | 1405 | return gl::error(GL_OUT_OF_MEMORY); |
daniel@transgaming.com | 91207b7 | 2012-11-28 20:56:43 +0000 | [diff] [blame] | 1406 | } |
| 1407 | } |
| 1408 | else // Regular case |
| 1409 | { |
| 1410 | mDevice->DrawPrimitive(mPrimitiveType, 0, mPrimitiveCount); |
| 1411 | } |
| 1412 | } |
| 1413 | |
shannon.woods@transgaming.com | 00032cb | 2013-01-25 21:56:30 +0000 | [diff] [blame] | 1414 | 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] | 1415 | { |
| 1416 | startScene(); |
| 1417 | |
shannon.woods@transgaming.com | e1602ae | 2013-02-28 23:17:38 +0000 | [diff] [blame] | 1418 | if (mode == GL_POINTS) |
| 1419 | { |
| 1420 | drawIndexedPoints(count, type, indices, elementArrayBuffer); |
| 1421 | } |
| 1422 | else if (mode == GL_LINE_LOOP) |
daniel@transgaming.com | 91207b7 | 2012-11-28 20:56:43 +0000 | [diff] [blame] | 1423 | { |
daniel@transgaming.com | 97400dd | 2012-11-28 20:57:00 +0000 | [diff] [blame] | 1424 | drawLineLoop(count, type, indices, indexInfo.minIndex, elementArrayBuffer); |
daniel@transgaming.com | 91207b7 | 2012-11-28 20:56:43 +0000 | [diff] [blame] | 1425 | } |
| 1426 | else |
| 1427 | { |
| 1428 | for (int i = 0; i < mRepeatDraw; i++) |
| 1429 | { |
daniel@transgaming.com | 97400dd | 2012-11-28 20:57:00 +0000 | [diff] [blame] | 1430 | GLsizei vertexCount = indexInfo.maxIndex - indexInfo.minIndex + 1; |
| 1431 | 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] | 1432 | } |
| 1433 | } |
| 1434 | } |
| 1435 | |
| 1436 | void Renderer9::drawLineLoop(GLsizei count, GLenum type, const GLvoid *indices, int minIndex, gl::Buffer *elementArrayBuffer) |
| 1437 | { |
| 1438 | // Get the raw indices for an indexed draw |
| 1439 | if (type != GL_NONE && elementArrayBuffer) |
| 1440 | { |
| 1441 | gl::Buffer *indexBuffer = elementArrayBuffer; |
shannon.woods@transgaming.com | 7665541 | 2013-02-28 23:08:09 +0000 | [diff] [blame] | 1442 | BufferStorage *storage = indexBuffer->getStorage(); |
daniel@transgaming.com | 91207b7 | 2012-11-28 20:56:43 +0000 | [diff] [blame] | 1443 | intptr_t offset = reinterpret_cast<intptr_t>(indices); |
shannon.woods@transgaming.com | 7665541 | 2013-02-28 23:08:09 +0000 | [diff] [blame] | 1444 | indices = static_cast<const GLubyte*>(storage->getData()) + offset; |
daniel@transgaming.com | 91207b7 | 2012-11-28 20:56:43 +0000 | [diff] [blame] | 1445 | } |
| 1446 | |
| 1447 | UINT startIndex = 0; |
daniel@transgaming.com | 91207b7 | 2012-11-28 20:56:43 +0000 | [diff] [blame] | 1448 | |
| 1449 | if (get32BitIndexSupport()) |
| 1450 | { |
daniel@transgaming.com | 1e3a804 | 2012-12-20 21:09:55 +0000 | [diff] [blame] | 1451 | if (!mLineLoopIB) |
| 1452 | { |
| 1453 | mLineLoopIB = new StreamingIndexBufferInterface(this); |
| 1454 | if (!mLineLoopIB->reserveBufferSpace(INITIAL_INDEX_BUFFER_SIZE, GL_UNSIGNED_INT)) |
| 1455 | { |
| 1456 | delete mLineLoopIB; |
| 1457 | mLineLoopIB = NULL; |
| 1458 | |
| 1459 | 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] | 1460 | return gl::error(GL_OUT_OF_MEMORY); |
daniel@transgaming.com | 1e3a804 | 2012-12-20 21:09:55 +0000 | [diff] [blame] | 1461 | } |
| 1462 | } |
| 1463 | |
daniel@transgaming.com | 91207b7 | 2012-11-28 20:56:43 +0000 | [diff] [blame] | 1464 | const int spaceNeeded = (count + 1) * sizeof(unsigned int); |
daniel@transgaming.com | 1e3a804 | 2012-12-20 21:09:55 +0000 | [diff] [blame] | 1465 | if (!mLineLoopIB->reserveBufferSpace(spaceNeeded, GL_UNSIGNED_INT)) |
daniel@transgaming.com | 91207b7 | 2012-11-28 20:56:43 +0000 | [diff] [blame] | 1466 | { |
daniel@transgaming.com | 1e3a804 | 2012-12-20 21:09:55 +0000 | [diff] [blame] | 1467 | 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] | 1468 | return gl::error(GL_OUT_OF_MEMORY); |
daniel@transgaming.com | 91207b7 | 2012-11-28 20:56:43 +0000 | [diff] [blame] | 1469 | } |
| 1470 | |
daniel@transgaming.com | 1e3a804 | 2012-12-20 21:09:55 +0000 | [diff] [blame] | 1471 | void* mappedMemory = NULL; |
| 1472 | int offset = mLineLoopIB->mapBuffer(spaceNeeded, &mappedMemory); |
| 1473 | if (offset == -1 || mappedMemory == NULL) |
daniel@transgaming.com | 91207b7 | 2012-11-28 20:56:43 +0000 | [diff] [blame] | 1474 | { |
daniel@transgaming.com | 1e3a804 | 2012-12-20 21:09:55 +0000 | [diff] [blame] | 1475 | ERR("Could not map index buffer for GL_LINE_LOOP."); |
shannon.woods@transgaming.com | 779aa26 | 2013-02-28 23:04:58 +0000 | [diff] [blame] | 1476 | return gl::error(GL_OUT_OF_MEMORY); |
daniel@transgaming.com | 1e3a804 | 2012-12-20 21:09:55 +0000 | [diff] [blame] | 1477 | } |
daniel@transgaming.com | 91207b7 | 2012-11-28 20:56:43 +0000 | [diff] [blame] | 1478 | |
daniel@transgaming.com | 1e3a804 | 2012-12-20 21:09:55 +0000 | [diff] [blame] | 1479 | startIndex = static_cast<UINT>(offset) / 4; |
| 1480 | unsigned int *data = reinterpret_cast<unsigned int*>(mappedMemory); |
| 1481 | |
| 1482 | switch (type) |
| 1483 | { |
| 1484 | case GL_NONE: // Non-indexed draw |
| 1485 | for (int i = 0; i < count; i++) |
daniel@transgaming.com | 91207b7 | 2012-11-28 20:56:43 +0000 | [diff] [blame] | 1486 | { |
daniel@transgaming.com | 1e3a804 | 2012-12-20 21:09:55 +0000 | [diff] [blame] | 1487 | data[i] = i; |
daniel@transgaming.com | 91207b7 | 2012-11-28 20:56:43 +0000 | [diff] [blame] | 1488 | } |
daniel@transgaming.com | 1e3a804 | 2012-12-20 21:09:55 +0000 | [diff] [blame] | 1489 | data[count] = 0; |
| 1490 | break; |
| 1491 | case GL_UNSIGNED_BYTE: |
| 1492 | for (int i = 0; i < count; i++) |
| 1493 | { |
| 1494 | data[i] = static_cast<const GLubyte*>(indices)[i]; |
| 1495 | } |
| 1496 | data[count] = static_cast<const GLubyte*>(indices)[0]; |
| 1497 | break; |
| 1498 | case GL_UNSIGNED_SHORT: |
| 1499 | for (int i = 0; i < count; i++) |
| 1500 | { |
| 1501 | data[i] = static_cast<const GLushort*>(indices)[i]; |
| 1502 | } |
| 1503 | data[count] = static_cast<const GLushort*>(indices)[0]; |
| 1504 | break; |
| 1505 | case GL_UNSIGNED_INT: |
| 1506 | for (int i = 0; i < count; i++) |
| 1507 | { |
| 1508 | data[i] = static_cast<const GLuint*>(indices)[i]; |
| 1509 | } |
| 1510 | data[count] = static_cast<const GLuint*>(indices)[0]; |
| 1511 | break; |
| 1512 | default: UNREACHABLE(); |
| 1513 | } |
| 1514 | |
| 1515 | if (!mLineLoopIB->unmapBuffer()) |
| 1516 | { |
| 1517 | ERR("Could not unmap index buffer for GL_LINE_LOOP."); |
shannon.woods@transgaming.com | 779aa26 | 2013-02-28 23:04:58 +0000 | [diff] [blame] | 1518 | return gl::error(GL_OUT_OF_MEMORY); |
daniel@transgaming.com | 91207b7 | 2012-11-28 20:56:43 +0000 | [diff] [blame] | 1519 | } |
| 1520 | } |
| 1521 | else |
| 1522 | { |
daniel@transgaming.com | 1e3a804 | 2012-12-20 21:09:55 +0000 | [diff] [blame] | 1523 | if (!mLineLoopIB) |
| 1524 | { |
| 1525 | mLineLoopIB = new StreamingIndexBufferInterface(this); |
| 1526 | if (!mLineLoopIB->reserveBufferSpace(INITIAL_INDEX_BUFFER_SIZE, GL_UNSIGNED_SHORT)) |
| 1527 | { |
| 1528 | delete mLineLoopIB; |
| 1529 | mLineLoopIB = NULL; |
| 1530 | |
| 1531 | 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] | 1532 | return gl::error(GL_OUT_OF_MEMORY); |
daniel@transgaming.com | 1e3a804 | 2012-12-20 21:09:55 +0000 | [diff] [blame] | 1533 | } |
| 1534 | } |
| 1535 | |
daniel@transgaming.com | 91207b7 | 2012-11-28 20:56:43 +0000 | [diff] [blame] | 1536 | const int spaceNeeded = (count + 1) * sizeof(unsigned short); |
daniel@transgaming.com | 1e3a804 | 2012-12-20 21:09:55 +0000 | [diff] [blame] | 1537 | if (!mLineLoopIB->reserveBufferSpace(spaceNeeded, GL_UNSIGNED_SHORT)) |
daniel@transgaming.com | 91207b7 | 2012-11-28 20:56:43 +0000 | [diff] [blame] | 1538 | { |
daniel@transgaming.com | 1e3a804 | 2012-12-20 21:09:55 +0000 | [diff] [blame] | 1539 | 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] | 1540 | return gl::error(GL_OUT_OF_MEMORY); |
daniel@transgaming.com | 91207b7 | 2012-11-28 20:56:43 +0000 | [diff] [blame] | 1541 | } |
| 1542 | |
daniel@transgaming.com | 1e3a804 | 2012-12-20 21:09:55 +0000 | [diff] [blame] | 1543 | void* mappedMemory = NULL; |
| 1544 | int offset = mLineLoopIB->mapBuffer(spaceNeeded, &mappedMemory); |
| 1545 | if (offset == -1 || mappedMemory == NULL) |
daniel@transgaming.com | 91207b7 | 2012-11-28 20:56:43 +0000 | [diff] [blame] | 1546 | { |
daniel@transgaming.com | 1e3a804 | 2012-12-20 21:09:55 +0000 | [diff] [blame] | 1547 | ERR("Could not map index buffer for GL_LINE_LOOP."); |
shannon.woods@transgaming.com | 779aa26 | 2013-02-28 23:04:58 +0000 | [diff] [blame] | 1548 | return gl::error(GL_OUT_OF_MEMORY); |
daniel@transgaming.com | 1e3a804 | 2012-12-20 21:09:55 +0000 | [diff] [blame] | 1549 | } |
daniel@transgaming.com | 91207b7 | 2012-11-28 20:56:43 +0000 | [diff] [blame] | 1550 | |
daniel@transgaming.com | 1e3a804 | 2012-12-20 21:09:55 +0000 | [diff] [blame] | 1551 | startIndex = static_cast<UINT>(offset) / 2; |
| 1552 | unsigned short *data = reinterpret_cast<unsigned short*>(mappedMemory); |
| 1553 | |
| 1554 | switch (type) |
| 1555 | { |
| 1556 | case GL_NONE: // Non-indexed draw |
| 1557 | for (int i = 0; i < count; i++) |
daniel@transgaming.com | 91207b7 | 2012-11-28 20:56:43 +0000 | [diff] [blame] | 1558 | { |
daniel@transgaming.com | 1e3a804 | 2012-12-20 21:09:55 +0000 | [diff] [blame] | 1559 | data[i] = i; |
daniel@transgaming.com | 91207b7 | 2012-11-28 20:56:43 +0000 | [diff] [blame] | 1560 | } |
daniel@transgaming.com | 1e3a804 | 2012-12-20 21:09:55 +0000 | [diff] [blame] | 1561 | data[count] = 0; |
| 1562 | break; |
| 1563 | case GL_UNSIGNED_BYTE: |
| 1564 | for (int i = 0; i < count; i++) |
| 1565 | { |
| 1566 | data[i] = static_cast<const GLubyte*>(indices)[i]; |
| 1567 | } |
| 1568 | data[count] = static_cast<const GLubyte*>(indices)[0]; |
| 1569 | break; |
| 1570 | case GL_UNSIGNED_SHORT: |
| 1571 | for (int i = 0; i < count; i++) |
| 1572 | { |
| 1573 | data[i] = static_cast<const GLushort*>(indices)[i]; |
| 1574 | } |
| 1575 | data[count] = static_cast<const GLushort*>(indices)[0]; |
| 1576 | break; |
| 1577 | case GL_UNSIGNED_INT: |
| 1578 | for (int i = 0; i < count; i++) |
| 1579 | { |
| 1580 | data[i] = static_cast<const GLuint*>(indices)[i]; |
| 1581 | } |
| 1582 | data[count] = static_cast<const GLuint*>(indices)[0]; |
| 1583 | break; |
| 1584 | default: UNREACHABLE(); |
daniel@transgaming.com | 91207b7 | 2012-11-28 20:56:43 +0000 | [diff] [blame] | 1585 | } |
| 1586 | |
daniel@transgaming.com | 1e3a804 | 2012-12-20 21:09:55 +0000 | [diff] [blame] | 1587 | if (!mLineLoopIB->unmapBuffer()) |
| 1588 | { |
| 1589 | ERR("Could not unmap index buffer for GL_LINE_LOOP."); |
shannon.woods@transgaming.com | 779aa26 | 2013-02-28 23:04:58 +0000 | [diff] [blame] | 1590 | return gl::error(GL_OUT_OF_MEMORY); |
daniel@transgaming.com | 1e3a804 | 2012-12-20 21:09:55 +0000 | [diff] [blame] | 1591 | } |
daniel@transgaming.com | 91207b7 | 2012-11-28 20:56:43 +0000 | [diff] [blame] | 1592 | } |
daniel@transgaming.com | 1e3a804 | 2012-12-20 21:09:55 +0000 | [diff] [blame] | 1593 | |
| 1594 | if (mAppliedIBSerial != mLineLoopIB->getSerial()) |
daniel@transgaming.com | 91207b7 | 2012-11-28 20:56:43 +0000 | [diff] [blame] | 1595 | { |
daniel@transgaming.com | 1e3a804 | 2012-12-20 21:09:55 +0000 | [diff] [blame] | 1596 | IndexBuffer9 *indexBuffer = IndexBuffer9::makeIndexBuffer9(mLineLoopIB->getIndexBuffer()); |
| 1597 | |
| 1598 | mDevice->SetIndices(indexBuffer->getBuffer()); |
| 1599 | mAppliedIBSerial = mLineLoopIB->getSerial(); |
daniel@transgaming.com | 91207b7 | 2012-11-28 20:56:43 +0000 | [diff] [blame] | 1600 | } |
daniel@transgaming.com | 1e3a804 | 2012-12-20 21:09:55 +0000 | [diff] [blame] | 1601 | |
| 1602 | mDevice->DrawIndexedPrimitive(D3DPT_LINESTRIP, -minIndex, minIndex, count, startIndex, count); |
daniel@transgaming.com | 67094ee | 2012-11-28 20:53:04 +0000 | [diff] [blame] | 1603 | } |
| 1604 | |
shannon.woods@transgaming.com | e1602ae | 2013-02-28 23:17:38 +0000 | [diff] [blame] | 1605 | template <typename T> |
| 1606 | static void drawPoints(IDirect3DDevice9* device, GLsizei count, const GLvoid *indices) |
| 1607 | { |
| 1608 | for (int i = 0; i < count; i++) |
| 1609 | { |
| 1610 | unsigned int indexValue = static_cast<unsigned int>(static_cast<const T*>(indices)[i]); |
| 1611 | device->DrawPrimitive(D3DPT_POINTLIST, indexValue, 1); |
| 1612 | } |
| 1613 | } |
| 1614 | |
| 1615 | void Renderer9::drawIndexedPoints(GLsizei count, GLenum type, const GLvoid *indices, gl::Buffer *elementArrayBuffer) |
| 1616 | { |
| 1617 | // Drawing index point lists is unsupported in d3d9, fall back to a regular DrawPrimitive call |
| 1618 | // for each individual point. This call is not expected to happen often. |
| 1619 | |
| 1620 | if (elementArrayBuffer) |
| 1621 | { |
| 1622 | BufferStorage *storage = elementArrayBuffer->getStorage(); |
| 1623 | intptr_t offset = reinterpret_cast<intptr_t>(indices); |
| 1624 | indices = static_cast<const GLubyte*>(storage->getData()) + offset; |
| 1625 | } |
| 1626 | |
| 1627 | switch (type) |
| 1628 | { |
| 1629 | case GL_UNSIGNED_BYTE: drawPoints<GLubyte>(mDevice, count, indices); break; |
| 1630 | case GL_UNSIGNED_SHORT: drawPoints<GLushort>(mDevice, count, indices); break; |
| 1631 | case GL_UNSIGNED_INT: drawPoints<GLuint>(mDevice, count, indices); break; |
| 1632 | default: UNREACHABLE(); |
| 1633 | } |
| 1634 | } |
| 1635 | |
daniel@transgaming.com | 5fbf177 | 2012-11-28 20:54:43 +0000 | [diff] [blame] | 1636 | void Renderer9::applyShaders(gl::ProgramBinary *programBinary) |
| 1637 | { |
daniel@transgaming.com | e499141 | 2012-12-20 20:55:34 +0000 | [diff] [blame] | 1638 | unsigned int programBinarySerial = programBinary->getSerial(); |
| 1639 | if (programBinarySerial != mAppliedProgramBinarySerial) |
| 1640 | { |
| 1641 | ShaderExecutable *vertexExe = programBinary->getVertexExecutable(); |
| 1642 | ShaderExecutable *pixelExe = programBinary->getPixelExecutable(); |
daniel@transgaming.com | 9589241 | 2012-11-28 20:59:09 +0000 | [diff] [blame] | 1643 | |
daniel@transgaming.com | e499141 | 2012-12-20 20:55:34 +0000 | [diff] [blame] | 1644 | IDirect3DVertexShader9 *vertexShader = NULL; |
| 1645 | if (vertexExe) vertexShader = ShaderExecutable9::makeShaderExecutable9(vertexExe)->getVertexShader(); |
daniel@transgaming.com | 9589241 | 2012-11-28 20:59:09 +0000 | [diff] [blame] | 1646 | |
daniel@transgaming.com | e499141 | 2012-12-20 20:55:34 +0000 | [diff] [blame] | 1647 | IDirect3DPixelShader9 *pixelShader = NULL; |
| 1648 | if (pixelExe) pixelShader = ShaderExecutable9::makeShaderExecutable9(pixelExe)->getPixelShader(); |
daniel@transgaming.com | 5fbf177 | 2012-11-28 20:54:43 +0000 | [diff] [blame] | 1649 | |
daniel@transgaming.com | e499141 | 2012-12-20 20:55:34 +0000 | [diff] [blame] | 1650 | mDevice->SetPixelShader(pixelShader); |
| 1651 | mDevice->SetVertexShader(vertexShader); |
| 1652 | programBinary->dirtyAllUniforms(); |
daniel@transgaming.com | ed36abd | 2013-01-11 21:15:58 +0000 | [diff] [blame] | 1653 | mDxUniformsDirty = true; |
daniel@transgaming.com | e499141 | 2012-12-20 20:55:34 +0000 | [diff] [blame] | 1654 | |
| 1655 | mAppliedProgramBinarySerial = programBinarySerial; |
| 1656 | } |
daniel@transgaming.com | 5fbf177 | 2012-11-28 20:54:43 +0000 | [diff] [blame] | 1657 | } |
| 1658 | |
shannon.woods@transgaming.com | 21ba647 | 2013-01-25 21:53:32 +0000 | [diff] [blame] | 1659 | void Renderer9::applyUniforms(gl::ProgramBinary *programBinary, gl::UniformArray *uniformArray) |
daniel@transgaming.com | b6e5510 | 2012-12-20 21:08:14 +0000 | [diff] [blame] | 1660 | { |
| 1661 | for (std::vector<gl::Uniform*>::const_iterator ub = uniformArray->begin(), ue = uniformArray->end(); ub != ue; ++ub) |
| 1662 | { |
| 1663 | gl::Uniform *targetUniform = *ub; |
| 1664 | |
| 1665 | if (targetUniform->dirty) |
| 1666 | { |
daniel@transgaming.com | b6e5510 | 2012-12-20 21:08:14 +0000 | [diff] [blame] | 1667 | GLfloat *f = (GLfloat*)targetUniform->data; |
| 1668 | GLint *i = (GLint*)targetUniform->data; |
daniel@transgaming.com | b6e5510 | 2012-12-20 21:08:14 +0000 | [diff] [blame] | 1669 | |
| 1670 | switch (targetUniform->type) |
| 1671 | { |
| 1672 | case GL_SAMPLER_2D: |
| 1673 | case GL_SAMPLER_CUBE: |
shannon.woods@transgaming.com | 2494c97 | 2013-02-28 23:10:03 +0000 | [diff] [blame] | 1674 | break; |
| 1675 | case GL_BOOL: |
| 1676 | case GL_BOOL_VEC2: |
| 1677 | case GL_BOOL_VEC3: |
| 1678 | case GL_BOOL_VEC4: |
| 1679 | applyUniformnbv(targetUniform, i); |
| 1680 | break; |
daniel@transgaming.com | b6e5510 | 2012-12-20 21:08:14 +0000 | [diff] [blame] | 1681 | case GL_FLOAT: |
| 1682 | case GL_FLOAT_VEC2: |
| 1683 | case GL_FLOAT_VEC3: |
| 1684 | case GL_FLOAT_VEC4: |
| 1685 | case GL_FLOAT_MAT2: |
| 1686 | case GL_FLOAT_MAT3: |
shannon.woods@transgaming.com | 2494c97 | 2013-02-28 23:10:03 +0000 | [diff] [blame] | 1687 | case GL_FLOAT_MAT4: |
| 1688 | applyUniformnfv(targetUniform, f); |
| 1689 | break; |
| 1690 | case GL_INT: |
| 1691 | case GL_INT_VEC2: |
| 1692 | case GL_INT_VEC3: |
| 1693 | case GL_INT_VEC4: |
| 1694 | applyUniformniv(targetUniform, i); |
| 1695 | break; |
daniel@transgaming.com | b6e5510 | 2012-12-20 21:08:14 +0000 | [diff] [blame] | 1696 | default: |
| 1697 | UNREACHABLE(); |
| 1698 | } |
| 1699 | |
| 1700 | targetUniform->dirty = false; |
| 1701 | } |
| 1702 | } |
daniel@transgaming.com | a390e1e | 2013-01-11 04:09:39 +0000 | [diff] [blame] | 1703 | |
| 1704 | // Driver uniforms |
daniel@transgaming.com | ed36abd | 2013-01-11 21:15:58 +0000 | [diff] [blame] | 1705 | if (mDxUniformsDirty) |
| 1706 | { |
| 1707 | mDevice->SetVertexShaderConstantF(0, (float*)&mVertexConstants, sizeof(dx_VertexConstants) / sizeof(float[4])); |
| 1708 | mDevice->SetPixelShaderConstantF(0, (float*)&mPixelConstants, sizeof(dx_PixelConstants) / sizeof(float[4])); |
| 1709 | mDxUniformsDirty = false; |
| 1710 | } |
daniel@transgaming.com | b6e5510 | 2012-12-20 21:08:14 +0000 | [diff] [blame] | 1711 | } |
| 1712 | |
daniel@transgaming.com | f956186 | 2012-12-20 21:12:07 +0000 | [diff] [blame] | 1713 | void Renderer9::applyUniformnfv(gl::Uniform *targetUniform, const GLfloat *v) |
daniel@transgaming.com | b6e5510 | 2012-12-20 21:08:14 +0000 | [diff] [blame] | 1714 | { |
shannonwoods@chromium.org | 38676dc | 2013-05-30 00:06:52 +0000 | [diff] [blame] | 1715 | if (targetUniform->isReferencedByFragmentShader()) |
daniel@transgaming.com | b6e5510 | 2012-12-20 21:08:14 +0000 | [diff] [blame] | 1716 | { |
daniel@transgaming.com | e76b64b | 2013-01-11 04:10:08 +0000 | [diff] [blame] | 1717 | mDevice->SetPixelShaderConstantF(targetUniform->psRegisterIndex, v, targetUniform->registerCount); |
daniel@transgaming.com | b6e5510 | 2012-12-20 21:08:14 +0000 | [diff] [blame] | 1718 | } |
| 1719 | |
shannonwoods@chromium.org | 38676dc | 2013-05-30 00:06:52 +0000 | [diff] [blame] | 1720 | if (targetUniform->isReferencedByVertexShader()) |
daniel@transgaming.com | b6e5510 | 2012-12-20 21:08:14 +0000 | [diff] [blame] | 1721 | { |
daniel@transgaming.com | e76b64b | 2013-01-11 04:10:08 +0000 | [diff] [blame] | 1722 | mDevice->SetVertexShaderConstantF(targetUniform->vsRegisterIndex, v, targetUniform->registerCount); |
daniel@transgaming.com | b6e5510 | 2012-12-20 21:08:14 +0000 | [diff] [blame] | 1723 | } |
daniel@transgaming.com | b6e5510 | 2012-12-20 21:08:14 +0000 | [diff] [blame] | 1724 | } |
| 1725 | |
shannon.woods@transgaming.com | 2494c97 | 2013-02-28 23:10:03 +0000 | [diff] [blame] | 1726 | void Renderer9::applyUniformniv(gl::Uniform *targetUniform, const GLint *v) |
daniel@transgaming.com | b6e5510 | 2012-12-20 21:08:14 +0000 | [diff] [blame] | 1727 | { |
shannon.woods@transgaming.com | d8136cb | 2013-02-28 23:14:44 +0000 | [diff] [blame] | 1728 | ASSERT(targetUniform->registerCount <= MAX_VERTEX_CONSTANT_VECTORS_D3D9); |
| 1729 | GLfloat vector[MAX_VERTEX_CONSTANT_VECTORS_D3D9][4]; |
daniel@transgaming.com | b6e5510 | 2012-12-20 21:08:14 +0000 | [diff] [blame] | 1730 | |
shannon.woods@transgaming.com | 2494c97 | 2013-02-28 23:10:03 +0000 | [diff] [blame] | 1731 | for (unsigned int i = 0; i < targetUniform->registerCount; i++) |
daniel@transgaming.com | b6e5510 | 2012-12-20 21:08:14 +0000 | [diff] [blame] | 1732 | { |
shannon.woods@transgaming.com | 2494c97 | 2013-02-28 23:10:03 +0000 | [diff] [blame] | 1733 | vector[i][0] = (GLfloat)v[4 * i + 0]; |
| 1734 | vector[i][1] = (GLfloat)v[4 * i + 1]; |
| 1735 | vector[i][2] = (GLfloat)v[4 * i + 2]; |
| 1736 | vector[i][3] = (GLfloat)v[4 * i + 3]; |
daniel@transgaming.com | b6e5510 | 2012-12-20 21:08:14 +0000 | [diff] [blame] | 1737 | } |
| 1738 | |
shannon.woods@transgaming.com | 2494c97 | 2013-02-28 23:10:03 +0000 | [diff] [blame] | 1739 | applyUniformnfv(targetUniform, (GLfloat*)vector); |
daniel@transgaming.com | b6e5510 | 2012-12-20 21:08:14 +0000 | [diff] [blame] | 1740 | } |
| 1741 | |
shannon.woods@transgaming.com | 2494c97 | 2013-02-28 23:10:03 +0000 | [diff] [blame] | 1742 | void Renderer9::applyUniformnbv(gl::Uniform *targetUniform, const GLint *v) |
daniel@transgaming.com | b6e5510 | 2012-12-20 21:08:14 +0000 | [diff] [blame] | 1743 | { |
shannon.woods@transgaming.com | d8136cb | 2013-02-28 23:14:44 +0000 | [diff] [blame] | 1744 | ASSERT(targetUniform->registerCount <= MAX_VERTEX_CONSTANT_VECTORS_D3D9); |
| 1745 | GLfloat vector[MAX_VERTEX_CONSTANT_VECTORS_D3D9][4]; |
daniel@transgaming.com | b6e5510 | 2012-12-20 21:08:14 +0000 | [diff] [blame] | 1746 | |
shannon.woods@transgaming.com | 2494c97 | 2013-02-28 23:10:03 +0000 | [diff] [blame] | 1747 | for (unsigned int i = 0; i < targetUniform->registerCount; i++) |
daniel@transgaming.com | b6e5510 | 2012-12-20 21:08:14 +0000 | [diff] [blame] | 1748 | { |
shannon.woods@transgaming.com | 2494c97 | 2013-02-28 23:10:03 +0000 | [diff] [blame] | 1749 | vector[i][0] = (v[4 * i + 0] == GL_FALSE) ? 0.0f : 1.0f; |
| 1750 | vector[i][1] = (v[4 * i + 1] == GL_FALSE) ? 0.0f : 1.0f; |
| 1751 | vector[i][2] = (v[4 * i + 2] == GL_FALSE) ? 0.0f : 1.0f; |
| 1752 | 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] | 1753 | } |
| 1754 | |
shannon.woods@transgaming.com | 2494c97 | 2013-02-28 23:10:03 +0000 | [diff] [blame] | 1755 | applyUniformnfv(targetUniform, (GLfloat*)vector); |
daniel@transgaming.com | b6e5510 | 2012-12-20 21:08:14 +0000 | [diff] [blame] | 1756 | } |
| 1757 | |
daniel@transgaming.com | 084a257 | 2012-11-28 20:55:17 +0000 | [diff] [blame] | 1758 | void Renderer9::clear(const gl::ClearParameters &clearParams, gl::Framebuffer *frameBuffer) |
daniel@transgaming.com | d084c62 | 2012-11-28 19:36:05 +0000 | [diff] [blame] | 1759 | { |
daniel@transgaming.com | 0393e5b | 2012-11-28 20:55:33 +0000 | [diff] [blame] | 1760 | D3DCOLOR color = D3DCOLOR_ARGB(gl::unorm<8>(clearParams.colorClearValue.alpha), |
| 1761 | gl::unorm<8>(clearParams.colorClearValue.red), |
| 1762 | gl::unorm<8>(clearParams.colorClearValue.green), |
| 1763 | gl::unorm<8>(clearParams.colorClearValue.blue)); |
| 1764 | float depth = gl::clamp01(clearParams.depthClearValue); |
| 1765 | int stencil = clearParams.stencilClearValue & 0x000000FF; |
daniel@transgaming.com | d084c62 | 2012-11-28 19:36:05 +0000 | [diff] [blame] | 1766 | |
daniel@transgaming.com | 0393e5b | 2012-11-28 20:55:33 +0000 | [diff] [blame] | 1767 | unsigned int stencilUnmasked = 0x0; |
| 1768 | if ((clearParams.mask & GL_STENCIL_BUFFER_BIT) && frameBuffer->hasStencil()) |
| 1769 | { |
shannonwoods@chromium.org | 755012f | 2013-05-30 00:09:32 +0000 | [diff] [blame] | 1770 | unsigned int stencilSize = gl::GetStencilBits(frameBuffer->getStencilbuffer()->getActualFormat(), |
| 1771 | getCurrentClientVersion()); |
daniel@transgaming.com | 0393e5b | 2012-11-28 20:55:33 +0000 | [diff] [blame] | 1772 | stencilUnmasked = (0x1 << stencilSize) - 1; |
| 1773 | } |
| 1774 | |
shannonwoods@chromium.org | 755012f | 2013-05-30 00:09:32 +0000 | [diff] [blame] | 1775 | bool alphaUnmasked = gl::GetAlphaBits(mRenderTargetDesc.format, getCurrentClientVersion()) == 0 || |
| 1776 | clearParams.colorMaskAlpha; |
daniel@transgaming.com | 0393e5b | 2012-11-28 20:55:33 +0000 | [diff] [blame] | 1777 | |
| 1778 | const bool needMaskedStencilClear = (clearParams.mask & GL_STENCIL_BUFFER_BIT) && |
| 1779 | (clearParams.stencilWriteMask & stencilUnmasked) != stencilUnmasked; |
| 1780 | const bool needMaskedColorClear = (clearParams.mask & GL_COLOR_BUFFER_BIT) && |
| 1781 | !(clearParams.colorMaskRed && clearParams.colorMaskGreen && |
| 1782 | clearParams.colorMaskBlue && alphaUnmasked); |
| 1783 | |
| 1784 | if (needMaskedColorClear || needMaskedStencilClear) |
| 1785 | { |
| 1786 | // State which is altered in all paths from this point to the clear call is saved. |
| 1787 | // State which is altered in only some paths will be flagged dirty in the case that |
| 1788 | // that path is taken. |
| 1789 | HRESULT hr; |
| 1790 | if (mMaskedClearSavedState == NULL) |
| 1791 | { |
| 1792 | hr = mDevice->BeginStateBlock(); |
| 1793 | ASSERT(SUCCEEDED(hr) || hr == D3DERR_OUTOFVIDEOMEMORY || hr == E_OUTOFMEMORY); |
| 1794 | |
| 1795 | mDevice->SetRenderState(D3DRS_ZWRITEENABLE, FALSE); |
| 1796 | mDevice->SetRenderState(D3DRS_ZFUNC, D3DCMP_ALWAYS); |
| 1797 | mDevice->SetRenderState(D3DRS_ZENABLE, FALSE); |
| 1798 | mDevice->SetRenderState(D3DRS_CULLMODE, D3DCULL_NONE); |
| 1799 | mDevice->SetRenderState(D3DRS_FILLMODE, D3DFILL_SOLID); |
| 1800 | mDevice->SetRenderState(D3DRS_ALPHATESTENABLE, FALSE); |
| 1801 | mDevice->SetRenderState(D3DRS_ALPHABLENDENABLE, FALSE); |
| 1802 | mDevice->SetRenderState(D3DRS_CLIPPLANEENABLE, 0); |
| 1803 | mDevice->SetRenderState(D3DRS_COLORWRITEENABLE, 0); |
| 1804 | mDevice->SetRenderState(D3DRS_STENCILENABLE, FALSE); |
| 1805 | mDevice->SetPixelShader(NULL); |
| 1806 | mDevice->SetVertexShader(NULL); |
| 1807 | mDevice->SetFVF(D3DFVF_XYZRHW | D3DFVF_DIFFUSE); |
| 1808 | mDevice->SetStreamSource(0, NULL, 0, 0); |
| 1809 | mDevice->SetRenderState(D3DRS_SEPARATEALPHABLENDENABLE, TRUE); |
| 1810 | mDevice->SetTextureStageState(0, D3DTSS_COLOROP, D3DTOP_SELECTARG1); |
| 1811 | mDevice->SetTextureStageState(0, D3DTSS_COLORARG1, D3DTA_TFACTOR); |
| 1812 | mDevice->SetTextureStageState(0, D3DTSS_ALPHAOP, D3DTOP_SELECTARG1); |
| 1813 | mDevice->SetTextureStageState(0, D3DTSS_ALPHAARG1, D3DTA_TFACTOR); |
| 1814 | mDevice->SetRenderState(D3DRS_TEXTUREFACTOR, color); |
| 1815 | mDevice->SetRenderState(D3DRS_MULTISAMPLEMASK, 0xFFFFFFFF); |
| 1816 | |
| 1817 | for(int i = 0; i < gl::MAX_VERTEX_ATTRIBS; i++) |
| 1818 | { |
| 1819 | mDevice->SetStreamSourceFreq(i, 1); |
| 1820 | } |
| 1821 | |
| 1822 | hr = mDevice->EndStateBlock(&mMaskedClearSavedState); |
| 1823 | ASSERT(SUCCEEDED(hr) || hr == D3DERR_OUTOFVIDEOMEMORY || hr == E_OUTOFMEMORY); |
| 1824 | } |
| 1825 | |
| 1826 | ASSERT(mMaskedClearSavedState != NULL); |
| 1827 | |
| 1828 | if (mMaskedClearSavedState != NULL) |
| 1829 | { |
| 1830 | hr = mMaskedClearSavedState->Capture(); |
| 1831 | ASSERT(SUCCEEDED(hr)); |
| 1832 | } |
| 1833 | |
| 1834 | mDevice->SetRenderState(D3DRS_ZWRITEENABLE, FALSE); |
| 1835 | mDevice->SetRenderState(D3DRS_ZFUNC, D3DCMP_ALWAYS); |
| 1836 | mDevice->SetRenderState(D3DRS_ZENABLE, FALSE); |
| 1837 | mDevice->SetRenderState(D3DRS_CULLMODE, D3DCULL_NONE); |
| 1838 | mDevice->SetRenderState(D3DRS_FILLMODE, D3DFILL_SOLID); |
| 1839 | mDevice->SetRenderState(D3DRS_ALPHATESTENABLE, FALSE); |
| 1840 | mDevice->SetRenderState(D3DRS_ALPHABLENDENABLE, FALSE); |
| 1841 | mDevice->SetRenderState(D3DRS_CLIPPLANEENABLE, 0); |
| 1842 | |
| 1843 | if (clearParams.mask & GL_COLOR_BUFFER_BIT) |
| 1844 | { |
| 1845 | mDevice->SetRenderState(D3DRS_COLORWRITEENABLE, |
| 1846 | gl_d3d9::ConvertColorMask(clearParams.colorMaskRed, |
| 1847 | clearParams.colorMaskGreen, |
| 1848 | clearParams.colorMaskBlue, |
| 1849 | clearParams.colorMaskAlpha)); |
| 1850 | } |
| 1851 | else |
| 1852 | { |
| 1853 | mDevice->SetRenderState(D3DRS_COLORWRITEENABLE, 0); |
| 1854 | } |
| 1855 | |
| 1856 | if (stencilUnmasked != 0x0 && (clearParams.mask & GL_STENCIL_BUFFER_BIT)) |
| 1857 | { |
| 1858 | mDevice->SetRenderState(D3DRS_STENCILENABLE, TRUE); |
| 1859 | mDevice->SetRenderState(D3DRS_TWOSIDEDSTENCILMODE, FALSE); |
| 1860 | mDevice->SetRenderState(D3DRS_STENCILFUNC, D3DCMP_ALWAYS); |
| 1861 | mDevice->SetRenderState(D3DRS_STENCILREF, stencil); |
| 1862 | mDevice->SetRenderState(D3DRS_STENCILWRITEMASK, clearParams.stencilWriteMask); |
| 1863 | mDevice->SetRenderState(D3DRS_STENCILFAIL, D3DSTENCILOP_REPLACE); |
| 1864 | mDevice->SetRenderState(D3DRS_STENCILZFAIL, D3DSTENCILOP_REPLACE); |
| 1865 | mDevice->SetRenderState(D3DRS_STENCILPASS, D3DSTENCILOP_REPLACE); |
| 1866 | } |
| 1867 | else |
| 1868 | { |
| 1869 | mDevice->SetRenderState(D3DRS_STENCILENABLE, FALSE); |
| 1870 | } |
| 1871 | |
| 1872 | mDevice->SetPixelShader(NULL); |
| 1873 | mDevice->SetVertexShader(NULL); |
| 1874 | mDevice->SetFVF(D3DFVF_XYZRHW); |
| 1875 | mDevice->SetRenderState(D3DRS_SEPARATEALPHABLENDENABLE, TRUE); |
| 1876 | mDevice->SetTextureStageState(0, D3DTSS_COLOROP, D3DTOP_SELECTARG1); |
| 1877 | mDevice->SetTextureStageState(0, D3DTSS_COLORARG1, D3DTA_TFACTOR); |
| 1878 | mDevice->SetTextureStageState(0, D3DTSS_ALPHAOP, D3DTOP_SELECTARG1); |
| 1879 | mDevice->SetTextureStageState(0, D3DTSS_ALPHAARG1, D3DTA_TFACTOR); |
| 1880 | mDevice->SetRenderState(D3DRS_TEXTUREFACTOR, color); |
| 1881 | mDevice->SetRenderState(D3DRS_MULTISAMPLEMASK, 0xFFFFFFFF); |
| 1882 | |
| 1883 | for(int i = 0; i < gl::MAX_VERTEX_ATTRIBS; i++) |
| 1884 | { |
| 1885 | mDevice->SetStreamSourceFreq(i, 1); |
| 1886 | } |
| 1887 | |
| 1888 | float quad[4][4]; // A quadrilateral covering the target, aligned to match the edges |
| 1889 | quad[0][0] = -0.5f; |
| 1890 | quad[0][1] = mRenderTargetDesc.height - 0.5f; |
| 1891 | quad[0][2] = 0.0f; |
| 1892 | quad[0][3] = 1.0f; |
| 1893 | |
| 1894 | quad[1][0] = mRenderTargetDesc.width - 0.5f; |
| 1895 | quad[1][1] = mRenderTargetDesc.height - 0.5f; |
| 1896 | quad[1][2] = 0.0f; |
| 1897 | quad[1][3] = 1.0f; |
| 1898 | |
| 1899 | quad[2][0] = -0.5f; |
| 1900 | quad[2][1] = -0.5f; |
| 1901 | quad[2][2] = 0.0f; |
| 1902 | quad[2][3] = 1.0f; |
| 1903 | |
| 1904 | quad[3][0] = mRenderTargetDesc.width - 0.5f; |
| 1905 | quad[3][1] = -0.5f; |
| 1906 | quad[3][2] = 0.0f; |
| 1907 | quad[3][3] = 1.0f; |
| 1908 | |
| 1909 | startScene(); |
| 1910 | mDevice->DrawPrimitiveUP(D3DPT_TRIANGLESTRIP, 2, quad, sizeof(float[4])); |
| 1911 | |
| 1912 | if (clearParams.mask & GL_DEPTH_BUFFER_BIT) |
| 1913 | { |
| 1914 | mDevice->SetRenderState(D3DRS_ZENABLE, TRUE); |
| 1915 | mDevice->SetRenderState(D3DRS_ZWRITEENABLE, TRUE); |
| 1916 | mDevice->Clear(0, NULL, D3DCLEAR_ZBUFFER, color, depth, stencil); |
| 1917 | } |
| 1918 | |
| 1919 | if (mMaskedClearSavedState != NULL) |
| 1920 | { |
| 1921 | mMaskedClearSavedState->Apply(); |
| 1922 | } |
| 1923 | } |
| 1924 | else if (clearParams.mask) |
| 1925 | { |
| 1926 | DWORD dxClearFlags = 0; |
| 1927 | if (clearParams.mask & GL_COLOR_BUFFER_BIT) |
| 1928 | { |
| 1929 | dxClearFlags |= D3DCLEAR_TARGET; |
| 1930 | } |
| 1931 | if (clearParams.mask & GL_DEPTH_BUFFER_BIT) |
| 1932 | { |
| 1933 | dxClearFlags |= D3DCLEAR_ZBUFFER; |
| 1934 | } |
| 1935 | if (clearParams.mask & GL_STENCIL_BUFFER_BIT) |
| 1936 | { |
| 1937 | dxClearFlags |= D3DCLEAR_STENCIL; |
| 1938 | } |
| 1939 | |
| 1940 | mDevice->Clear(0, NULL, dxClearFlags, color, depth, stencil); |
| 1941 | } |
daniel@transgaming.com | d084c62 | 2012-11-28 19:36:05 +0000 | [diff] [blame] | 1942 | } |
| 1943 | |
daniel@transgaming.com | c43a605 | 2012-11-28 19:41:51 +0000 | [diff] [blame] | 1944 | void Renderer9::markAllStateDirty() |
| 1945 | { |
daniel@transgaming.com | 220e79a | 2012-11-28 19:42:11 +0000 | [diff] [blame] | 1946 | mAppliedRenderTargetSerial = 0; |
| 1947 | mAppliedDepthbufferSerial = 0; |
| 1948 | mAppliedStencilbufferSerial = 0; |
| 1949 | mDepthStencilInitialized = false; |
| 1950 | mRenderTargetDescInitialized = false; |
| 1951 | |
daniel@transgaming.com | c43a605 | 2012-11-28 19:41:51 +0000 | [diff] [blame] | 1952 | mForceSetDepthStencilState = true; |
| 1953 | mForceSetRasterState = true; |
daniel@transgaming.com | c43a605 | 2012-11-28 19:41:51 +0000 | [diff] [blame] | 1954 | mForceSetScissor = true; |
| 1955 | mForceSetViewport = true; |
daniel@transgaming.com | 9a06737 | 2012-12-20 20:55:24 +0000 | [diff] [blame] | 1956 | mForceSetBlendState = true; |
| 1957 | |
shannon.woods@transgaming.com | 233fe95 | 2013-01-25 21:51:57 +0000 | [diff] [blame] | 1958 | 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] | 1959 | { |
| 1960 | mForceSetVertexSamplerStates[i] = true; |
| 1961 | mCurVertexTextureSerials[i] = 0; |
| 1962 | } |
| 1963 | for (unsigned int i = 0; i < gl::MAX_TEXTURE_IMAGE_UNITS; i++) |
| 1964 | { |
| 1965 | mForceSetPixelSamplerStates[i] = true; |
| 1966 | mCurPixelTextureSerials[i] = 0; |
| 1967 | } |
| 1968 | |
daniel@transgaming.com | 9a06737 | 2012-12-20 20:55:24 +0000 | [diff] [blame] | 1969 | mAppliedIBSerial = 0; |
daniel@transgaming.com | e499141 | 2012-12-20 20:55:34 +0000 | [diff] [blame] | 1970 | mAppliedProgramBinarySerial = 0; |
daniel@transgaming.com | ed36abd | 2013-01-11 21:15:58 +0000 | [diff] [blame] | 1971 | mDxUniformsDirty = true; |
daniel@transgaming.com | 67094ee | 2012-11-28 20:53:04 +0000 | [diff] [blame] | 1972 | |
| 1973 | mVertexDeclarationCache.markStateDirty(); |
daniel@transgaming.com | c43a605 | 2012-11-28 19:41:51 +0000 | [diff] [blame] | 1974 | } |
| 1975 | |
daniel@transgaming.com | 2507f41 | 2012-10-31 18:46:48 +0000 | [diff] [blame] | 1976 | void Renderer9::releaseDeviceResources() |
daniel@transgaming.com | ef21ab2 | 2012-10-31 17:52:47 +0000 | [diff] [blame] | 1977 | { |
| 1978 | while (!mEventQueryPool.empty()) |
| 1979 | { |
| 1980 | mEventQueryPool.back()->Release(); |
| 1981 | mEventQueryPool.pop_back(); |
| 1982 | } |
daniel@transgaming.com | e4733d7 | 2012-10-31 18:07:01 +0000 | [diff] [blame] | 1983 | |
daniel@transgaming.com | 0393e5b | 2012-11-28 20:55:33 +0000 | [diff] [blame] | 1984 | if (mMaskedClearSavedState) |
| 1985 | { |
| 1986 | mMaskedClearSavedState->Release(); |
| 1987 | mMaskedClearSavedState = NULL; |
| 1988 | } |
| 1989 | |
daniel@transgaming.com | e4733d7 | 2012-10-31 18:07:01 +0000 | [diff] [blame] | 1990 | mVertexShaderCache.clear(); |
| 1991 | mPixelShaderCache.clear(); |
daniel@transgaming.com | 67094ee | 2012-11-28 20:53:04 +0000 | [diff] [blame] | 1992 | |
daniel@transgaming.com | e569fc5 | 2012-11-28 20:56:02 +0000 | [diff] [blame] | 1993 | delete mBlit; |
| 1994 | mBlit = NULL; |
| 1995 | |
daniel@transgaming.com | 67094ee | 2012-11-28 20:53:04 +0000 | [diff] [blame] | 1996 | delete mVertexDataManager; |
| 1997 | mVertexDataManager = NULL; |
daniel@transgaming.com | 91207b7 | 2012-11-28 20:56:43 +0000 | [diff] [blame] | 1998 | |
| 1999 | delete mIndexDataManager; |
| 2000 | mIndexDataManager = NULL; |
| 2001 | |
| 2002 | delete mLineLoopIB; |
| 2003 | mLineLoopIB = NULL; |
daniel@transgaming.com | e4e1a33 | 2012-12-20 20:52:09 +0000 | [diff] [blame] | 2004 | |
| 2005 | for (int i = 0; i < NUM_NULL_COLORBUFFER_CACHE_ENTRIES; i++) |
| 2006 | { |
| 2007 | delete mNullColorbufferCache[i].buffer; |
| 2008 | mNullColorbufferCache[i].buffer = NULL; |
| 2009 | } |
| 2010 | |
daniel@transgaming.com | ef21ab2 | 2012-10-31 17:52:47 +0000 | [diff] [blame] | 2011 | } |
| 2012 | |
| 2013 | |
shannon.woods@transgaming.com | eb049e2 | 2013-02-28 23:04:49 +0000 | [diff] [blame] | 2014 | void Renderer9::notifyDeviceLost() |
daniel@transgaming.com | 621ce05 | 2012-10-31 17:52:29 +0000 | [diff] [blame] | 2015 | { |
| 2016 | mDeviceLost = true; |
shannon.woods@transgaming.com | eb049e2 | 2013-02-28 23:04:49 +0000 | [diff] [blame] | 2017 | mDisplay->notifyDeviceLost(); |
daniel@transgaming.com | 621ce05 | 2012-10-31 17:52:29 +0000 | [diff] [blame] | 2018 | } |
| 2019 | |
daniel@transgaming.com | 2507f41 | 2012-10-31 18:46:48 +0000 | [diff] [blame] | 2020 | bool Renderer9::isDeviceLost() |
daniel@transgaming.com | 621ce05 | 2012-10-31 17:52:29 +0000 | [diff] [blame] | 2021 | { |
| 2022 | return mDeviceLost; |
| 2023 | } |
| 2024 | |
daniel@transgaming.com | f688c0d | 2012-10-31 17:52:57 +0000 | [diff] [blame] | 2025 | // 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] | 2026 | bool Renderer9::testDeviceLost(bool notify) |
daniel@transgaming.com | 621ce05 | 2012-10-31 17:52:29 +0000 | [diff] [blame] | 2027 | { |
shannon.woods@transgaming.com | a4ba59c | 2013-02-28 23:14:38 +0000 | [diff] [blame] | 2028 | HRESULT status = S_OK; |
daniel@transgaming.com | 621ce05 | 2012-10-31 17:52:29 +0000 | [diff] [blame] | 2029 | |
| 2030 | if (mDeviceEx) |
| 2031 | { |
shannon.woods@transgaming.com | a4ba59c | 2013-02-28 23:14:38 +0000 | [diff] [blame] | 2032 | status = mDeviceEx->CheckDeviceState(NULL); |
daniel@transgaming.com | 621ce05 | 2012-10-31 17:52:29 +0000 | [diff] [blame] | 2033 | } |
| 2034 | else if (mDevice) |
| 2035 | { |
shannon.woods@transgaming.com | a4ba59c | 2013-02-28 23:14:38 +0000 | [diff] [blame] | 2036 | status = mDevice->TestCooperativeLevel(); |
daniel@transgaming.com | 621ce05 | 2012-10-31 17:52:29 +0000 | [diff] [blame] | 2037 | } |
| 2038 | else |
| 2039 | { |
| 2040 | // No device yet, so no reset required |
| 2041 | } |
| 2042 | |
shannon.woods@transgaming.com | a4ba59c | 2013-02-28 23:14:38 +0000 | [diff] [blame] | 2043 | bool isLost = FAILED(status) || d3d9::isDeviceLostError(status); |
| 2044 | |
daniel@transgaming.com | 621ce05 | 2012-10-31 17:52:29 +0000 | [diff] [blame] | 2045 | if (isLost) |
| 2046 | { |
| 2047 | // ensure we note the device loss -- |
shannon.woods@transgaming.com | 779aa26 | 2013-02-28 23:04:58 +0000 | [diff] [blame] | 2048 | // we'll probably get this done again by notifyDeviceLost |
| 2049 | // but best to remember it! |
daniel@transgaming.com | 621ce05 | 2012-10-31 17:52:29 +0000 | [diff] [blame] | 2050 | // Note that we don't want to clear the device loss status here |
| 2051 | // -- this needs to be done by resetDevice |
| 2052 | mDeviceLost = true; |
daniel@transgaming.com | f688c0d | 2012-10-31 17:52:57 +0000 | [diff] [blame] | 2053 | if (notify) |
| 2054 | { |
shannon.woods@transgaming.com | eb049e2 | 2013-02-28 23:04:49 +0000 | [diff] [blame] | 2055 | notifyDeviceLost(); |
daniel@transgaming.com | f688c0d | 2012-10-31 17:52:57 +0000 | [diff] [blame] | 2056 | } |
daniel@transgaming.com | 621ce05 | 2012-10-31 17:52:29 +0000 | [diff] [blame] | 2057 | } |
| 2058 | |
| 2059 | return isLost; |
| 2060 | } |
| 2061 | |
daniel@transgaming.com | 2507f41 | 2012-10-31 18:46:48 +0000 | [diff] [blame] | 2062 | bool Renderer9::testDeviceResettable() |
daniel@transgaming.com | 621ce05 | 2012-10-31 17:52:29 +0000 | [diff] [blame] | 2063 | { |
| 2064 | HRESULT status = D3D_OK; |
| 2065 | |
| 2066 | if (mDeviceEx) |
| 2067 | { |
| 2068 | status = mDeviceEx->CheckDeviceState(NULL); |
| 2069 | } |
| 2070 | else if (mDevice) |
| 2071 | { |
| 2072 | status = mDevice->TestCooperativeLevel(); |
| 2073 | } |
| 2074 | |
shannon.woods@transgaming.com | a4ba59c | 2013-02-28 23:14:38 +0000 | [diff] [blame] | 2075 | // 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] | 2076 | // DEVICEREMOVED indicates the device has been stopped and must be recreated |
daniel@transgaming.com | 621ce05 | 2012-10-31 17:52:29 +0000 | [diff] [blame] | 2077 | switch (status) |
| 2078 | { |
| 2079 | case D3DERR_DEVICENOTRESET: |
| 2080 | case D3DERR_DEVICEHUNG: |
| 2081 | return true; |
shannon.woods@transgaming.com | a4ba59c | 2013-02-28 23:14:38 +0000 | [diff] [blame] | 2082 | case D3DERR_DEVICELOST: |
| 2083 | return (mDeviceEx != NULL); |
| 2084 | case D3DERR_DEVICEREMOVED: |
| 2085 | UNIMPLEMENTED(); |
| 2086 | return false; |
daniel@transgaming.com | 621ce05 | 2012-10-31 17:52:29 +0000 | [diff] [blame] | 2087 | default: |
| 2088 | return false; |
| 2089 | } |
| 2090 | } |
| 2091 | |
daniel@transgaming.com | 2507f41 | 2012-10-31 18:46:48 +0000 | [diff] [blame] | 2092 | bool Renderer9::resetDevice() |
daniel@transgaming.com | 621ce05 | 2012-10-31 17:52:29 +0000 | [diff] [blame] | 2093 | { |
daniel@transgaming.com | ef21ab2 | 2012-10-31 17:52:47 +0000 | [diff] [blame] | 2094 | releaseDeviceResources(); |
| 2095 | |
daniel@transgaming.com | 621ce05 | 2012-10-31 17:52:29 +0000 | [diff] [blame] | 2096 | D3DPRESENT_PARAMETERS presentParameters = getDefaultPresentParameters(); |
| 2097 | |
| 2098 | HRESULT result = D3D_OK; |
daniel@transgaming.com | f688c0d | 2012-10-31 17:52:57 +0000 | [diff] [blame] | 2099 | bool lost = testDeviceLost(false); |
daniel@transgaming.com | 621ce05 | 2012-10-31 17:52:29 +0000 | [diff] [blame] | 2100 | int attempts = 3; |
| 2101 | |
| 2102 | while (lost && attempts > 0) |
| 2103 | { |
| 2104 | if (mDeviceEx) |
| 2105 | { |
| 2106 | Sleep(500); // Give the graphics driver some CPU time |
| 2107 | result = mDeviceEx->ResetEx(&presentParameters, NULL); |
| 2108 | } |
| 2109 | else |
| 2110 | { |
| 2111 | result = mDevice->TestCooperativeLevel(); |
| 2112 | while (result == D3DERR_DEVICELOST) |
| 2113 | { |
| 2114 | Sleep(100); // Give the graphics driver some CPU time |
| 2115 | result = mDevice->TestCooperativeLevel(); |
| 2116 | } |
| 2117 | |
| 2118 | if (result == D3DERR_DEVICENOTRESET) |
| 2119 | { |
| 2120 | result = mDevice->Reset(&presentParameters); |
| 2121 | } |
| 2122 | } |
| 2123 | |
daniel@transgaming.com | f688c0d | 2012-10-31 17:52:57 +0000 | [diff] [blame] | 2124 | lost = testDeviceLost(false); |
daniel@transgaming.com | 621ce05 | 2012-10-31 17:52:29 +0000 | [diff] [blame] | 2125 | attempts --; |
| 2126 | } |
| 2127 | |
| 2128 | if (FAILED(result)) |
| 2129 | { |
| 2130 | ERR("Reset/ResetEx failed multiple times: 0x%08X", result); |
| 2131 | return false; |
| 2132 | } |
| 2133 | |
| 2134 | // reset device defaults |
| 2135 | initializeDevice(); |
| 2136 | mDeviceLost = false; |
| 2137 | |
| 2138 | return true; |
| 2139 | } |
| 2140 | |
daniel@transgaming.com | 2507f41 | 2012-10-31 18:46:48 +0000 | [diff] [blame] | 2141 | DWORD Renderer9::getAdapterVendor() const |
daniel@transgaming.com | 4ca789e | 2012-10-31 18:46:40 +0000 | [diff] [blame] | 2142 | { |
| 2143 | return mAdapterIdentifier.VendorId; |
| 2144 | } |
| 2145 | |
daniel@transgaming.com | ca1ac1f | 2013-01-11 04:13:05 +0000 | [diff] [blame] | 2146 | std::string Renderer9::getRendererDescription() const |
daniel@transgaming.com | 4ca789e | 2012-10-31 18:46:40 +0000 | [diff] [blame] | 2147 | { |
daniel@transgaming.com | ca1ac1f | 2013-01-11 04:13:05 +0000 | [diff] [blame] | 2148 | std::ostringstream rendererString; |
| 2149 | |
| 2150 | rendererString << mAdapterIdentifier.Description; |
| 2151 | if (getShareHandleSupport()) |
| 2152 | { |
| 2153 | rendererString << " Direct3D9Ex"; |
| 2154 | } |
| 2155 | else |
| 2156 | { |
| 2157 | rendererString << " Direct3D9"; |
| 2158 | } |
| 2159 | |
| 2160 | rendererString << " vs_" << D3DSHADER_VERSION_MAJOR(mDeviceCaps.VertexShaderVersion) << "_" << D3DSHADER_VERSION_MINOR(mDeviceCaps.VertexShaderVersion); |
| 2161 | rendererString << " ps_" << D3DSHADER_VERSION_MAJOR(mDeviceCaps.PixelShaderVersion) << "_" << D3DSHADER_VERSION_MINOR(mDeviceCaps.PixelShaderVersion); |
| 2162 | |
| 2163 | return rendererString.str(); |
daniel@transgaming.com | 4ca789e | 2012-10-31 18:46:40 +0000 | [diff] [blame] | 2164 | } |
| 2165 | |
daniel@transgaming.com | 2507f41 | 2012-10-31 18:46:48 +0000 | [diff] [blame] | 2166 | GUID Renderer9::getAdapterIdentifier() const |
daniel@transgaming.com | 4ca789e | 2012-10-31 18:46:40 +0000 | [diff] [blame] | 2167 | { |
| 2168 | return mAdapterIdentifier.DeviceIdentifier; |
| 2169 | } |
| 2170 | |
Geoff Lang | 61e49a5 | 2013-05-29 10:22:58 -0400 | [diff] [blame] | 2171 | Renderer9::MultisampleSupportInfo Renderer9::getMultiSampleSupport(D3DFORMAT format) |
daniel@transgaming.com | 621ce05 | 2012-10-31 17:52:29 +0000 | [diff] [blame] | 2172 | { |
Geoff Lang | 61e49a5 | 2013-05-29 10:22:58 -0400 | [diff] [blame] | 2173 | MultisampleSupportInfo support = { 0 }; |
daniel@transgaming.com | 621ce05 | 2012-10-31 17:52:29 +0000 | [diff] [blame] | 2174 | |
Geoff Lang | 61e49a5 | 2013-05-29 10:22:58 -0400 | [diff] [blame] | 2175 | for (unsigned int multiSampleIndex = 0; multiSampleIndex < ArraySize(support.supportedSamples); multiSampleIndex++) |
| 2176 | { |
| 2177 | HRESULT result = mD3d9->CheckDeviceMultiSampleType(mAdapter, mDeviceType, format, TRUE, |
| 2178 | (D3DMULTISAMPLE_TYPE)multiSampleIndex, NULL); |
| 2179 | |
| 2180 | if (SUCCEEDED(result)) |
| 2181 | { |
| 2182 | support.supportedSamples[multiSampleIndex] = true; |
| 2183 | if (multiSampleIndex != D3DMULTISAMPLE_NONMASKABLE) |
| 2184 | { |
| 2185 | support.maxSupportedSamples = std::max(support.maxSupportedSamples, multiSampleIndex); |
| 2186 | } |
| 2187 | } |
| 2188 | else |
| 2189 | { |
| 2190 | support.supportedSamples[multiSampleIndex] = false; |
| 2191 | } |
daniel@transgaming.com | 621ce05 | 2012-10-31 17:52:29 +0000 | [diff] [blame] | 2192 | } |
Geoff Lang | 61e49a5 | 2013-05-29 10:22:58 -0400 | [diff] [blame] | 2193 | |
| 2194 | return support; |
daniel@transgaming.com | 621ce05 | 2012-10-31 17:52:29 +0000 | [diff] [blame] | 2195 | } |
| 2196 | |
shannon.woods@transgaming.com | bec04bf | 2013-01-25 21:53:52 +0000 | [diff] [blame] | 2197 | bool Renderer9::getBGRATextureSupport() const |
| 2198 | { |
| 2199 | // DirectX 9 always supports BGRA |
| 2200 | return true; |
| 2201 | } |
| 2202 | |
shannonwoods@chromium.org | 89200d9 | 2013-05-30 00:07:50 +0000 | [diff] [blame] | 2203 | bool Renderer9::getDXT1TextureSupport() const |
daniel@transgaming.com | 621ce05 | 2012-10-31 17:52:29 +0000 | [diff] [blame] | 2204 | { |
daniel@transgaming.com | 669c995 | 2013-01-11 04:08:16 +0000 | [diff] [blame] | 2205 | return mDXT1TextureSupport; |
daniel@transgaming.com | 621ce05 | 2012-10-31 17:52:29 +0000 | [diff] [blame] | 2206 | } |
| 2207 | |
shannonwoods@chromium.org | 89200d9 | 2013-05-30 00:07:50 +0000 | [diff] [blame] | 2208 | bool Renderer9::getDXT3TextureSupport() const |
daniel@transgaming.com | 621ce05 | 2012-10-31 17:52:29 +0000 | [diff] [blame] | 2209 | { |
daniel@transgaming.com | 669c995 | 2013-01-11 04:08:16 +0000 | [diff] [blame] | 2210 | return mDXT3TextureSupport; |
daniel@transgaming.com | 621ce05 | 2012-10-31 17:52:29 +0000 | [diff] [blame] | 2211 | } |
| 2212 | |
shannonwoods@chromium.org | 89200d9 | 2013-05-30 00:07:50 +0000 | [diff] [blame] | 2213 | bool Renderer9::getDXT5TextureSupport() const |
daniel@transgaming.com | 621ce05 | 2012-10-31 17:52:29 +0000 | [diff] [blame] | 2214 | { |
daniel@transgaming.com | 669c995 | 2013-01-11 04:08:16 +0000 | [diff] [blame] | 2215 | return mDXT5TextureSupport; |
daniel@transgaming.com | 621ce05 | 2012-10-31 17:52:29 +0000 | [diff] [blame] | 2216 | } |
| 2217 | |
daniel@transgaming.com | 2507f41 | 2012-10-31 18:46:48 +0000 | [diff] [blame] | 2218 | bool Renderer9::getDepthTextureSupport() const |
daniel@transgaming.com | 621ce05 | 2012-10-31 17:52:29 +0000 | [diff] [blame] | 2219 | { |
daniel@transgaming.com | 669c995 | 2013-01-11 04:08:16 +0000 | [diff] [blame] | 2220 | return mDepthTextureSupport; |
daniel@transgaming.com | 621ce05 | 2012-10-31 17:52:29 +0000 | [diff] [blame] | 2221 | } |
| 2222 | |
shannonwoods@chromium.org | 89200d9 | 2013-05-30 00:07:50 +0000 | [diff] [blame] | 2223 | bool Renderer9::getFloat32TextureSupport() const |
daniel@transgaming.com | 621ce05 | 2012-10-31 17:52:29 +0000 | [diff] [blame] | 2224 | { |
daniel@transgaming.com | 669c995 | 2013-01-11 04:08:16 +0000 | [diff] [blame] | 2225 | return mFloat32TextureSupport; |
daniel@transgaming.com | 621ce05 | 2012-10-31 17:52:29 +0000 | [diff] [blame] | 2226 | } |
| 2227 | |
shannonwoods@chromium.org | 89200d9 | 2013-05-30 00:07:50 +0000 | [diff] [blame] | 2228 | bool Renderer9::getFloat32TextureFilteringSupport() const |
daniel@transgaming.com | 621ce05 | 2012-10-31 17:52:29 +0000 | [diff] [blame] | 2229 | { |
shannonwoods@chromium.org | 89200d9 | 2013-05-30 00:07:50 +0000 | [diff] [blame] | 2230 | return mFloat32FilterSupport; |
| 2231 | } |
| 2232 | |
| 2233 | bool Renderer9::getFloat32TextureRenderingSupport() const |
| 2234 | { |
| 2235 | return mFloat32RenderSupport; |
| 2236 | } |
| 2237 | |
| 2238 | bool Renderer9::getFloat16TextureSupport() const |
| 2239 | { |
daniel@transgaming.com | 669c995 | 2013-01-11 04:08:16 +0000 | [diff] [blame] | 2240 | return mFloat16TextureSupport; |
daniel@transgaming.com | 621ce05 | 2012-10-31 17:52:29 +0000 | [diff] [blame] | 2241 | } |
| 2242 | |
shannonwoods@chromium.org | 89200d9 | 2013-05-30 00:07:50 +0000 | [diff] [blame] | 2243 | bool Renderer9::getFloat16TextureFilteringSupport() const |
| 2244 | { |
| 2245 | return mFloat16FilterSupport; |
| 2246 | } |
| 2247 | |
| 2248 | bool Renderer9::getFloat16TextureRenderingSupport() const |
| 2249 | { |
| 2250 | return mFloat16RenderSupport; |
| 2251 | } |
| 2252 | |
Geoff Lang | d42cf4e | 2013-06-05 16:09:17 -0400 | [diff] [blame] | 2253 | bool Renderer9::getRGB565TextureSupport() const |
| 2254 | { |
| 2255 | return mRGB565TextureSupport; |
| 2256 | } |
| 2257 | |
shannonwoods@chromium.org | 89200d9 | 2013-05-30 00:07:50 +0000 | [diff] [blame] | 2258 | bool Renderer9::getLuminanceTextureSupport() const |
daniel@transgaming.com | 621ce05 | 2012-10-31 17:52:29 +0000 | [diff] [blame] | 2259 | { |
daniel@transgaming.com | 669c995 | 2013-01-11 04:08:16 +0000 | [diff] [blame] | 2260 | return mLuminanceTextureSupport; |
daniel@transgaming.com | 621ce05 | 2012-10-31 17:52:29 +0000 | [diff] [blame] | 2261 | } |
| 2262 | |
shannonwoods@chromium.org | 89200d9 | 2013-05-30 00:07:50 +0000 | [diff] [blame] | 2263 | bool Renderer9::getLuminanceAlphaTextureSupport() const |
daniel@transgaming.com | 621ce05 | 2012-10-31 17:52:29 +0000 | [diff] [blame] | 2264 | { |
daniel@transgaming.com | 669c995 | 2013-01-11 04:08:16 +0000 | [diff] [blame] | 2265 | return mLuminanceAlphaTextureSupport; |
daniel@transgaming.com | 621ce05 | 2012-10-31 17:52:29 +0000 | [diff] [blame] | 2266 | } |
| 2267 | |
daniel@transgaming.com | 2507f41 | 2012-10-31 18:46:48 +0000 | [diff] [blame] | 2268 | bool Renderer9::getTextureFilterAnisotropySupport() const |
daniel@transgaming.com | 621ce05 | 2012-10-31 17:52:29 +0000 | [diff] [blame] | 2269 | { |
daniel@transgaming.com | ba0570e | 2012-10-31 18:07:39 +0000 | [diff] [blame] | 2270 | return mSupportsTextureFilterAnisotropy; |
| 2271 | } |
| 2272 | |
daniel@transgaming.com | 2507f41 | 2012-10-31 18:46:48 +0000 | [diff] [blame] | 2273 | float Renderer9::getTextureMaxAnisotropy() const |
daniel@transgaming.com | ba0570e | 2012-10-31 18:07:39 +0000 | [diff] [blame] | 2274 | { |
| 2275 | if (mSupportsTextureFilterAnisotropy) |
daniel@transgaming.com | 621ce05 | 2012-10-31 17:52:29 +0000 | [diff] [blame] | 2276 | { |
shannon.woods%transgaming.com@gtempaccount.com | 6b73191 | 2013-04-13 03:35:19 +0000 | [diff] [blame] | 2277 | return static_cast<float>(mDeviceCaps.MaxAnisotropy); |
daniel@transgaming.com | 621ce05 | 2012-10-31 17:52:29 +0000 | [diff] [blame] | 2278 | } |
| 2279 | return 1.0f; |
| 2280 | } |
| 2281 | |
shannonwoods@chromium.org | 89200d9 | 2013-05-30 00:07:50 +0000 | [diff] [blame] | 2282 | bool Renderer9::getEventQuerySupport() const |
daniel@transgaming.com | 621ce05 | 2012-10-31 17:52:29 +0000 | [diff] [blame] | 2283 | { |
daniel@transgaming.com | 669c995 | 2013-01-11 04:08:16 +0000 | [diff] [blame] | 2284 | return mEventQuerySupport; |
daniel@transgaming.com | 621ce05 | 2012-10-31 17:52:29 +0000 | [diff] [blame] | 2285 | } |
| 2286 | |
shannon.woods@transgaming.com | 233fe95 | 2013-01-25 21:51:57 +0000 | [diff] [blame] | 2287 | unsigned int Renderer9::getMaxVertexTextureImageUnits() const |
daniel@transgaming.com | 621ce05 | 2012-10-31 17:52:29 +0000 | [diff] [blame] | 2288 | { |
shannon.woods@transgaming.com | 233fe95 | 2013-01-25 21:51:57 +0000 | [diff] [blame] | 2289 | META_ASSERT(MAX_TEXTURE_IMAGE_UNITS_VTF_SM3 <= gl::IMPLEMENTATION_MAX_VERTEX_TEXTURE_IMAGE_UNITS); |
| 2290 | return mVertexTextureSupport ? MAX_TEXTURE_IMAGE_UNITS_VTF_SM3 : 0; |
daniel@transgaming.com | 621ce05 | 2012-10-31 17:52:29 +0000 | [diff] [blame] | 2291 | } |
| 2292 | |
shannon.woods@transgaming.com | 76cd88c | 2013-01-25 21:54:36 +0000 | [diff] [blame] | 2293 | unsigned int Renderer9::getMaxCombinedTextureImageUnits() const |
| 2294 | { |
| 2295 | return gl::MAX_TEXTURE_IMAGE_UNITS + getMaxVertexTextureImageUnits(); |
| 2296 | } |
| 2297 | |
shannon.woods@transgaming.com | d8136cb | 2013-02-28 23:14:44 +0000 | [diff] [blame] | 2298 | unsigned int Renderer9::getReservedVertexUniformVectors() const |
shannon.woods@transgaming.com | 254317d | 2013-01-25 21:54:09 +0000 | [diff] [blame] | 2299 | { |
shannon.woods@transgaming.com | 42832a6 | 2013-02-28 23:18:38 +0000 | [diff] [blame] | 2300 | return 2; // dx_ViewAdjust and dx_DepthRange. |
shannon.woods@transgaming.com | 254317d | 2013-01-25 21:54:09 +0000 | [diff] [blame] | 2301 | } |
| 2302 | |
shannon.woods@transgaming.com | d8136cb | 2013-02-28 23:14:44 +0000 | [diff] [blame] | 2303 | unsigned int Renderer9::getReservedFragmentUniformVectors() const |
shannon.woods@transgaming.com | 254317d | 2013-01-25 21:54:09 +0000 | [diff] [blame] | 2304 | { |
shannon.woods@transgaming.com | 42832a6 | 2013-02-28 23:18:38 +0000 | [diff] [blame] | 2305 | return 3; // dx_ViewCoords, dx_DepthFront and dx_DepthRange. |
shannon.woods@transgaming.com | 254317d | 2013-01-25 21:54:09 +0000 | [diff] [blame] | 2306 | } |
| 2307 | |
shannon.woods@transgaming.com | d8136cb | 2013-02-28 23:14:44 +0000 | [diff] [blame] | 2308 | unsigned int Renderer9::getMaxVertexUniformVectors() const |
shannon.woods@transgaming.com | 28d268e | 2013-01-25 21:54:26 +0000 | [diff] [blame] | 2309 | { |
shannon.woods@transgaming.com | d8136cb | 2013-02-28 23:14:44 +0000 | [diff] [blame] | 2310 | return MAX_VERTEX_CONSTANT_VECTORS_D3D9 - getReservedVertexUniformVectors(); |
| 2311 | } |
| 2312 | |
| 2313 | unsigned int Renderer9::getMaxFragmentUniformVectors() const |
| 2314 | { |
| 2315 | const int maxPixelConstantVectors = (getMajorShaderModel() >= 3) ? MAX_PIXEL_CONSTANT_VECTORS_SM3 : MAX_PIXEL_CONSTANT_VECTORS_SM2; |
| 2316 | |
| 2317 | return maxPixelConstantVectors - getReservedFragmentUniformVectors(); |
| 2318 | } |
| 2319 | |
| 2320 | unsigned int Renderer9::getMaxVaryingVectors() const |
| 2321 | { |
| 2322 | 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] | 2323 | } |
| 2324 | |
shannon.woods%transgaming.com@gtempaccount.com | 3f72ce3 | 2013-04-13 03:36:43 +0000 | [diff] [blame] | 2325 | unsigned int Renderer9::getMaxVertexShaderUniformBuffers() const |
| 2326 | { |
| 2327 | return 0; |
| 2328 | } |
| 2329 | |
| 2330 | unsigned int Renderer9::getMaxFragmentShaderUniformBuffers() const |
| 2331 | { |
| 2332 | return 0; |
| 2333 | } |
| 2334 | |
shannonwoods@chromium.org | 2b54422 | 2013-05-30 00:11:12 +0000 | [diff] [blame] | 2335 | unsigned int Renderer9::getReservedVertexUniformBuffers() const |
| 2336 | { |
| 2337 | return 0; |
| 2338 | } |
| 2339 | |
| 2340 | unsigned int Renderer9::getReservedFragmentUniformBuffers() const |
| 2341 | { |
| 2342 | return 0; |
| 2343 | } |
| 2344 | |
shannon.woods%transgaming.com@gtempaccount.com | 3f72ce3 | 2013-04-13 03:36:43 +0000 | [diff] [blame] | 2345 | unsigned int Renderer9::getMaxTransformFeedbackBuffers() const |
| 2346 | { |
| 2347 | return 0; |
| 2348 | } |
| 2349 | |
shannonwoods@chromium.org | 33e798f | 2013-05-30 00:05:05 +0000 | [diff] [blame] | 2350 | unsigned int Renderer9::getMaxUniformBufferSize() const |
| 2351 | { |
| 2352 | return 0; |
| 2353 | } |
| 2354 | |
daniel@transgaming.com | 2507f41 | 2012-10-31 18:46:48 +0000 | [diff] [blame] | 2355 | bool Renderer9::getNonPower2TextureSupport() const |
daniel@transgaming.com | 621ce05 | 2012-10-31 17:52:29 +0000 | [diff] [blame] | 2356 | { |
| 2357 | return mSupportsNonPower2Textures; |
| 2358 | } |
| 2359 | |
daniel@transgaming.com | 2507f41 | 2012-10-31 18:46:48 +0000 | [diff] [blame] | 2360 | bool Renderer9::getOcclusionQuerySupport() const |
daniel@transgaming.com | 621ce05 | 2012-10-31 17:52:29 +0000 | [diff] [blame] | 2361 | { |
daniel@transgaming.com | 669c995 | 2013-01-11 04:08:16 +0000 | [diff] [blame] | 2362 | return mOcclusionQuerySupport; |
daniel@transgaming.com | 621ce05 | 2012-10-31 17:52:29 +0000 | [diff] [blame] | 2363 | } |
| 2364 | |
daniel@transgaming.com | 2507f41 | 2012-10-31 18:46:48 +0000 | [diff] [blame] | 2365 | bool Renderer9::getInstancingSupport() const |
daniel@transgaming.com | 621ce05 | 2012-10-31 17:52:29 +0000 | [diff] [blame] | 2366 | { |
| 2367 | return mDeviceCaps.PixelShaderVersion >= D3DPS_VERSION(3, 0); |
| 2368 | } |
| 2369 | |
daniel@transgaming.com | 2507f41 | 2012-10-31 18:46:48 +0000 | [diff] [blame] | 2370 | bool Renderer9::getShareHandleSupport() const |
daniel@transgaming.com | 313e392 | 2012-10-31 17:52:39 +0000 | [diff] [blame] | 2371 | { |
| 2372 | // 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] | 2373 | return (mD3d9Ex != NULL) && !gl::perfActive(); |
daniel@transgaming.com | 313e392 | 2012-10-31 17:52:39 +0000 | [diff] [blame] | 2374 | } |
daniel@transgaming.com | 621ce05 | 2012-10-31 17:52:29 +0000 | [diff] [blame] | 2375 | |
daniel@transgaming.com | 7629bb6 | 2013-01-11 04:12:28 +0000 | [diff] [blame] | 2376 | bool Renderer9::getDerivativeInstructionSupport() const |
| 2377 | { |
| 2378 | return (mDeviceCaps.PS20Caps.Caps & D3DPS20CAPS_GRADIENTINSTRUCTIONS) != 0; |
| 2379 | } |
| 2380 | |
shannon.woods@transgaming.com | 8d2f086 | 2013-02-28 23:09:19 +0000 | [diff] [blame] | 2381 | bool Renderer9::getPostSubBufferSupport() const |
| 2382 | { |
| 2383 | return true; |
| 2384 | } |
| 2385 | |
daniel@transgaming.com | 9549bea | 2012-11-28 20:57:23 +0000 | [diff] [blame] | 2386 | int Renderer9::getMajorShaderModel() const |
daniel@transgaming.com | 5f4c136 | 2012-10-31 18:29:00 +0000 | [diff] [blame] | 2387 | { |
daniel@transgaming.com | 9549bea | 2012-11-28 20:57:23 +0000 | [diff] [blame] | 2388 | return D3DSHADER_VERSION_MAJOR(mDeviceCaps.PixelShaderVersion); |
daniel@transgaming.com | 5f4c136 | 2012-10-31 18:29:00 +0000 | [diff] [blame] | 2389 | } |
| 2390 | |
daniel@transgaming.com | 2507f41 | 2012-10-31 18:46:48 +0000 | [diff] [blame] | 2391 | float Renderer9::getMaxPointSize() const |
daniel@transgaming.com | 5f4c136 | 2012-10-31 18:29:00 +0000 | [diff] [blame] | 2392 | { |
shannon.woods@transgaming.com | bd8c10c | 2013-01-25 21:15:03 +0000 | [diff] [blame] | 2393 | // Point size clamped at 1.0f for SM2 |
| 2394 | return getMajorShaderModel() == 3 ? mDeviceCaps.MaxPointSize : 1.0f; |
daniel@transgaming.com | 5f4c136 | 2012-10-31 18:29:00 +0000 | [diff] [blame] | 2395 | } |
| 2396 | |
shannon.woods@transgaming.com | 8ce2f8f | 2013-02-28 23:07:10 +0000 | [diff] [blame] | 2397 | int Renderer9::getMaxViewportDimension() const |
| 2398 | { |
| 2399 | int maxTextureDimension = std::min(std::min(getMaxTextureWidth(), getMaxTextureHeight()), |
shannon.woods%transgaming.com@gtempaccount.com | c1fdf6b | 2013-04-13 03:44:41 +0000 | [diff] [blame] | 2400 | (int)gl::IMPLEMENTATION_MAX_2D_TEXTURE_SIZE); |
shannon.woods@transgaming.com | 8ce2f8f | 2013-02-28 23:07:10 +0000 | [diff] [blame] | 2401 | return maxTextureDimension; |
| 2402 | } |
| 2403 | |
daniel@transgaming.com | 2507f41 | 2012-10-31 18:46:48 +0000 | [diff] [blame] | 2404 | int Renderer9::getMaxTextureWidth() const |
daniel@transgaming.com | 5f4c136 | 2012-10-31 18:29:00 +0000 | [diff] [blame] | 2405 | { |
| 2406 | return (int)mDeviceCaps.MaxTextureWidth; |
| 2407 | } |
| 2408 | |
daniel@transgaming.com | 2507f41 | 2012-10-31 18:46:48 +0000 | [diff] [blame] | 2409 | int Renderer9::getMaxTextureHeight() const |
daniel@transgaming.com | 5f4c136 | 2012-10-31 18:29:00 +0000 | [diff] [blame] | 2410 | { |
| 2411 | return (int)mDeviceCaps.MaxTextureHeight; |
| 2412 | } |
| 2413 | |
shannon.woods%transgaming.com@gtempaccount.com | c1fdf6b | 2013-04-13 03:44:41 +0000 | [diff] [blame] | 2414 | int Renderer9::getMaxTextureDepth() const |
| 2415 | { |
| 2416 | // 3D textures are not available in the D3D9 backend. |
| 2417 | return 1; |
| 2418 | } |
| 2419 | |
shannon.woods%transgaming.com@gtempaccount.com | a98a811 | 2013-04-13 03:45:57 +0000 | [diff] [blame] | 2420 | int Renderer9::getMaxTextureArrayLayers() const |
| 2421 | { |
| 2422 | // 2D array textures are not available in the D3D9 backend. |
| 2423 | return 1; |
| 2424 | } |
| 2425 | |
daniel@transgaming.com | 2507f41 | 2012-10-31 18:46:48 +0000 | [diff] [blame] | 2426 | bool Renderer9::get32BitIndexSupport() const |
daniel@transgaming.com | 5f4c136 | 2012-10-31 18:29:00 +0000 | [diff] [blame] | 2427 | { |
| 2428 | return mDeviceCaps.MaxVertexIndex >= (1 << 16); |
| 2429 | } |
| 2430 | |
daniel@transgaming.com | 2507f41 | 2012-10-31 18:46:48 +0000 | [diff] [blame] | 2431 | DWORD Renderer9::getCapsDeclTypes() const |
daniel@transgaming.com | 5f4c136 | 2012-10-31 18:29:00 +0000 | [diff] [blame] | 2432 | { |
| 2433 | return mDeviceCaps.DeclTypes; |
| 2434 | } |
| 2435 | |
daniel@transgaming.com | 2507f41 | 2012-10-31 18:46:48 +0000 | [diff] [blame] | 2436 | int Renderer9::getMinSwapInterval() const |
daniel@transgaming.com | 5f4c136 | 2012-10-31 18:29:00 +0000 | [diff] [blame] | 2437 | { |
| 2438 | return mMinSwapInterval; |
| 2439 | } |
| 2440 | |
daniel@transgaming.com | 2507f41 | 2012-10-31 18:46:48 +0000 | [diff] [blame] | 2441 | int Renderer9::getMaxSwapInterval() const |
daniel@transgaming.com | 5f4c136 | 2012-10-31 18:29:00 +0000 | [diff] [blame] | 2442 | { |
| 2443 | return mMaxSwapInterval; |
| 2444 | } |
| 2445 | |
daniel@transgaming.com | 2507f41 | 2012-10-31 18:46:48 +0000 | [diff] [blame] | 2446 | int Renderer9::getMaxSupportedSamples() const |
daniel@transgaming.com | b783398 | 2012-10-31 18:31:46 +0000 | [diff] [blame] | 2447 | { |
| 2448 | return mMaxSupportedSamples; |
| 2449 | } |
| 2450 | |
Geoff Lang | 0e120e3 | 2013-05-29 10:23:55 -0400 | [diff] [blame] | 2451 | GLsizei Renderer9::getMaxSupportedFormatSamples(GLint internalFormat) const |
| 2452 | { |
Shannon Woods | ddb785c | 2013-07-08 10:32:13 -0400 | [diff] [blame] | 2453 | D3DFORMAT format = gl_d3d9::GetTextureFormat(internalFormat, this); |
Geoff Lang | 0e120e3 | 2013-05-29 10:23:55 -0400 | [diff] [blame] | 2454 | MultisampleSupportMap::const_iterator itr = mMultiSampleSupport.find(format); |
| 2455 | return (itr != mMultiSampleSupport.end()) ? mMaxSupportedSamples : 0; |
| 2456 | } |
| 2457 | |
Shannon Woods | 52f1e7e | 2013-07-08 10:32:17 -0400 | [diff] [blame^] | 2458 | GLsizei Renderer9::getNumSampleCounts(GLint internalFormat) const |
| 2459 | { |
| 2460 | D3DFORMAT format = gl_d3d9::GetTextureFormat(internalFormat, this); |
| 2461 | MultisampleSupportMap::const_iterator iter = mMultiSampleSupport.find(format); |
| 2462 | |
| 2463 | unsigned int numCounts = 0; |
| 2464 | if (iter != mMultiSampleSupport.end()) |
| 2465 | { |
| 2466 | const MultisampleSupportInfo& info = iter->second; |
| 2467 | for (int i = 0; i < D3DMULTISAMPLE_16_SAMPLES; i++) |
| 2468 | { |
| 2469 | if (i != D3DMULTISAMPLE_NONMASKABLE && info.supportedSamples[i]) |
| 2470 | { |
| 2471 | numCounts++; |
| 2472 | } |
| 2473 | } |
| 2474 | } |
| 2475 | |
| 2476 | return numCounts; |
| 2477 | } |
| 2478 | |
| 2479 | void Renderer9::getSampleCounts(GLint internalFormat, GLsizei bufSize, GLint *params) const |
| 2480 | { |
| 2481 | D3DFORMAT format = gl_d3d9::GetTextureFormat(internalFormat, this); |
| 2482 | MultisampleSupportMap::const_iterator iter = mMultiSampleSupport.find(format); |
| 2483 | |
| 2484 | if (iter != mMultiSampleSupport.end()) |
| 2485 | { |
| 2486 | const MultisampleSupportInfo& info = iter->second; |
| 2487 | int bufPos = 0; |
| 2488 | for (int i = D3DMULTISAMPLE_16_SAMPLES; i >= 0 && bufPos < bufSize; i--) |
| 2489 | { |
| 2490 | if (i != D3DMULTISAMPLE_NONMASKABLE && info.supportedSamples[i]) |
| 2491 | { |
| 2492 | params[bufPos++] = i; |
| 2493 | } |
| 2494 | } |
| 2495 | } |
| 2496 | } |
| 2497 | |
daniel@transgaming.com | 2507f41 | 2012-10-31 18:46:48 +0000 | [diff] [blame] | 2498 | int Renderer9::getNearestSupportedSamples(D3DFORMAT format, int requested) const |
daniel@transgaming.com | b783398 | 2012-10-31 18:31:46 +0000 | [diff] [blame] | 2499 | { |
| 2500 | if (requested == 0) |
| 2501 | { |
| 2502 | return requested; |
| 2503 | } |
| 2504 | |
Geoff Lang | 61e49a5 | 2013-05-29 10:22:58 -0400 | [diff] [blame] | 2505 | MultisampleSupportMap::const_iterator itr = mMultiSampleSupport.find(format); |
daniel@transgaming.com | b783398 | 2012-10-31 18:31:46 +0000 | [diff] [blame] | 2506 | if (itr == mMultiSampleSupport.end()) |
| 2507 | { |
daniel@transgaming.com | 9295562 | 2012-10-31 18:38:41 +0000 | [diff] [blame] | 2508 | if (format == D3DFMT_UNKNOWN) |
| 2509 | return 0; |
daniel@transgaming.com | b783398 | 2012-10-31 18:31:46 +0000 | [diff] [blame] | 2510 | return -1; |
| 2511 | } |
| 2512 | |
Geoff Lang | 61e49a5 | 2013-05-29 10:22:58 -0400 | [diff] [blame] | 2513 | for (unsigned int i = requested; i < ArraySize(itr->second.supportedSamples); ++i) |
daniel@transgaming.com | b783398 | 2012-10-31 18:31:46 +0000 | [diff] [blame] | 2514 | { |
Geoff Lang | 61e49a5 | 2013-05-29 10:22:58 -0400 | [diff] [blame] | 2515 | if (itr->second.supportedSamples[i] && i != D3DMULTISAMPLE_NONMASKABLE) |
daniel@transgaming.com | b783398 | 2012-10-31 18:31:46 +0000 | [diff] [blame] | 2516 | { |
| 2517 | return i; |
| 2518 | } |
| 2519 | } |
| 2520 | |
| 2521 | return -1; |
| 2522 | } |
| 2523 | |
shannon.woods%transgaming.com@gtempaccount.com | b290ac1 | 2013-04-13 03:28:15 +0000 | [diff] [blame] | 2524 | unsigned int Renderer9::getMaxRenderTargets() const |
| 2525 | { |
| 2526 | // we do not support MRT in d3d9 |
| 2527 | return 1; |
| 2528 | } |
| 2529 | |
daniel@transgaming.com | a957168 | 2012-11-28 19:33:08 +0000 | [diff] [blame] | 2530 | D3DFORMAT Renderer9::ConvertTextureInternalFormat(GLint internalformat) |
| 2531 | { |
| 2532 | switch (internalformat) |
| 2533 | { |
| 2534 | case GL_DEPTH_COMPONENT16: |
| 2535 | case GL_DEPTH_COMPONENT32_OES: |
| 2536 | case GL_DEPTH24_STENCIL8_OES: |
| 2537 | return D3DFMT_INTZ; |
| 2538 | case GL_COMPRESSED_RGB_S3TC_DXT1_EXT: |
| 2539 | case GL_COMPRESSED_RGBA_S3TC_DXT1_EXT: |
| 2540 | return D3DFMT_DXT1; |
| 2541 | case GL_COMPRESSED_RGBA_S3TC_DXT3_ANGLE: |
| 2542 | return D3DFMT_DXT3; |
| 2543 | case GL_COMPRESSED_RGBA_S3TC_DXT5_ANGLE: |
| 2544 | return D3DFMT_DXT5; |
| 2545 | case GL_RGBA32F_EXT: |
| 2546 | case GL_RGB32F_EXT: |
| 2547 | case GL_ALPHA32F_EXT: |
| 2548 | case GL_LUMINANCE32F_EXT: |
| 2549 | case GL_LUMINANCE_ALPHA32F_EXT: |
| 2550 | return D3DFMT_A32B32G32R32F; |
| 2551 | case GL_RGBA16F_EXT: |
| 2552 | case GL_RGB16F_EXT: |
| 2553 | case GL_ALPHA16F_EXT: |
| 2554 | case GL_LUMINANCE16F_EXT: |
| 2555 | case GL_LUMINANCE_ALPHA16F_EXT: |
| 2556 | return D3DFMT_A16B16G16R16F; |
| 2557 | case GL_LUMINANCE8_EXT: |
| 2558 | if (getLuminanceTextureSupport()) |
| 2559 | { |
| 2560 | return D3DFMT_L8; |
| 2561 | } |
| 2562 | break; |
| 2563 | case GL_LUMINANCE8_ALPHA8_EXT: |
| 2564 | if (getLuminanceAlphaTextureSupport()) |
| 2565 | { |
| 2566 | return D3DFMT_A8L8; |
| 2567 | } |
| 2568 | break; |
| 2569 | case GL_RGB8_OES: |
| 2570 | case GL_RGB565: |
| 2571 | return D3DFMT_X8R8G8B8; |
| 2572 | } |
| 2573 | |
| 2574 | return D3DFMT_A8R8G8B8; |
| 2575 | } |
| 2576 | |
daniel@transgaming.com | 87705f8 | 2012-12-20 21:10:45 +0000 | [diff] [blame] | 2577 | bool Renderer9::copyToRenderTarget(TextureStorageInterface2D *dest, TextureStorageInterface2D *source) |
daniel@transgaming.com | 1d80eee | 2012-11-28 19:33:31 +0000 | [diff] [blame] | 2578 | { |
| 2579 | bool result = false; |
| 2580 | |
| 2581 | if (source && dest) |
| 2582 | { |
daniel@transgaming.com | 87705f8 | 2012-12-20 21:10:45 +0000 | [diff] [blame] | 2583 | TextureStorage9_2D *source9 = TextureStorage9_2D::makeTextureStorage9_2D(source->getStorageInstance()); |
| 2584 | TextureStorage9_2D *dest9 = TextureStorage9_2D::makeTextureStorage9_2D(dest->getStorageInstance()); |
daniel@transgaming.com | 34da397 | 2012-12-20 21:10:29 +0000 | [diff] [blame] | 2585 | |
| 2586 | int levels = source9->levelCount(); |
daniel@transgaming.com | 1d80eee | 2012-11-28 19:33:31 +0000 | [diff] [blame] | 2587 | for (int i = 0; i < levels; ++i) |
| 2588 | { |
daniel@transgaming.com | 34da397 | 2012-12-20 21:10:29 +0000 | [diff] [blame] | 2589 | IDirect3DSurface9 *srcSurf = source9->getSurfaceLevel(i, false); |
| 2590 | IDirect3DSurface9 *dstSurf = dest9->getSurfaceLevel(i, false); |
daniel@transgaming.com | 1d80eee | 2012-11-28 19:33:31 +0000 | [diff] [blame] | 2591 | |
daniel@transgaming.com | 34da397 | 2012-12-20 21:10:29 +0000 | [diff] [blame] | 2592 | result = copyToRenderTarget(dstSurf, srcSurf, source9->isManaged()); |
daniel@transgaming.com | 1d80eee | 2012-11-28 19:33:31 +0000 | [diff] [blame] | 2593 | |
| 2594 | if (srcSurf) srcSurf->Release(); |
| 2595 | if (dstSurf) dstSurf->Release(); |
| 2596 | |
| 2597 | if (!result) |
| 2598 | return false; |
| 2599 | } |
| 2600 | } |
| 2601 | |
| 2602 | return result; |
| 2603 | } |
| 2604 | |
daniel@transgaming.com | 87705f8 | 2012-12-20 21:10:45 +0000 | [diff] [blame] | 2605 | bool Renderer9::copyToRenderTarget(TextureStorageInterfaceCube *dest, TextureStorageInterfaceCube *source) |
daniel@transgaming.com | 1d80eee | 2012-11-28 19:33:31 +0000 | [diff] [blame] | 2606 | { |
| 2607 | bool result = false; |
| 2608 | |
| 2609 | if (source && dest) |
| 2610 | { |
daniel@transgaming.com | 87705f8 | 2012-12-20 21:10:45 +0000 | [diff] [blame] | 2611 | TextureStorage9_Cube *source9 = TextureStorage9_Cube::makeTextureStorage9_Cube(source->getStorageInstance()); |
| 2612 | TextureStorage9_Cube *dest9 = TextureStorage9_Cube::makeTextureStorage9_Cube(dest->getStorageInstance()); |
daniel@transgaming.com | 34da397 | 2012-12-20 21:10:29 +0000 | [diff] [blame] | 2613 | int levels = source9->levelCount(); |
daniel@transgaming.com | 1d80eee | 2012-11-28 19:33:31 +0000 | [diff] [blame] | 2614 | for (int f = 0; f < 6; f++) |
| 2615 | { |
| 2616 | for (int i = 0; i < levels; i++) |
| 2617 | { |
daniel@transgaming.com | 34da397 | 2012-12-20 21:10:29 +0000 | [diff] [blame] | 2618 | IDirect3DSurface9 *srcSurf = source9->getCubeMapSurface(GL_TEXTURE_CUBE_MAP_POSITIVE_X + f, i, false); |
| 2619 | 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] | 2620 | |
daniel@transgaming.com | 34da397 | 2012-12-20 21:10:29 +0000 | [diff] [blame] | 2621 | result = copyToRenderTarget(dstSurf, srcSurf, source9->isManaged()); |
daniel@transgaming.com | 1d80eee | 2012-11-28 19:33:31 +0000 | [diff] [blame] | 2622 | |
| 2623 | if (srcSurf) srcSurf->Release(); |
| 2624 | if (dstSurf) dstSurf->Release(); |
| 2625 | |
| 2626 | if (!result) |
| 2627 | return false; |
| 2628 | } |
| 2629 | } |
| 2630 | } |
| 2631 | |
| 2632 | return result; |
| 2633 | } |
| 2634 | |
shannon.woods%transgaming.com@gtempaccount.com | 414e82a | 2013-04-13 03:44:05 +0000 | [diff] [blame] | 2635 | bool Renderer9::copyToRenderTarget(TextureStorageInterface3D *dest, TextureStorageInterface3D *source) |
| 2636 | { |
| 2637 | // 3D textures are not available in the D3D9 backend. |
| 2638 | UNREACHABLE(); |
| 2639 | return false; |
| 2640 | } |
| 2641 | |
shannon.woods%transgaming.com@gtempaccount.com | 6c86bd5 | 2013-04-13 03:45:45 +0000 | [diff] [blame] | 2642 | bool Renderer9::copyToRenderTarget(TextureStorageInterface2DArray *dest, TextureStorageInterface2DArray *source) |
| 2643 | { |
| 2644 | // 2D array textures are not supported by the D3D9 backend. |
| 2645 | UNREACHABLE(); |
| 2646 | return false; |
| 2647 | } |
| 2648 | |
daniel@transgaming.com | 2507f41 | 2012-10-31 18:46:48 +0000 | [diff] [blame] | 2649 | D3DPOOL Renderer9::getBufferPool(DWORD usage) const |
daniel@transgaming.com | 621ce05 | 2012-10-31 17:52:29 +0000 | [diff] [blame] | 2650 | { |
| 2651 | if (mD3d9Ex != NULL) |
| 2652 | { |
| 2653 | return D3DPOOL_DEFAULT; |
| 2654 | } |
| 2655 | else |
| 2656 | { |
| 2657 | if (!(usage & D3DUSAGE_DYNAMIC)) |
| 2658 | { |
| 2659 | return D3DPOOL_MANAGED; |
| 2660 | } |
| 2661 | } |
| 2662 | |
| 2663 | return D3DPOOL_DEFAULT; |
| 2664 | } |
| 2665 | |
shannon.woods@transgaming.com | 664916b | 2013-01-25 21:50:32 +0000 | [diff] [blame] | 2666 | 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] | 2667 | GLint xoffset, GLint yoffset, TextureStorageInterface2D *storage, GLint level) |
daniel@transgaming.com | de8a7ff | 2012-11-28 19:34:13 +0000 | [diff] [blame] | 2668 | { |
shannon.woods@transgaming.com | 664916b | 2013-01-25 21:50:32 +0000 | [diff] [blame] | 2669 | RECT rect; |
| 2670 | rect.left = sourceRect.x; |
| 2671 | rect.top = sourceRect.y; |
| 2672 | rect.right = sourceRect.x + sourceRect.width; |
| 2673 | rect.bottom = sourceRect.y + sourceRect.height; |
| 2674 | |
| 2675 | return mBlit->copy(framebuffer, rect, destFormat, xoffset, yoffset, storage, level); |
daniel@transgaming.com | de8a7ff | 2012-11-28 19:34:13 +0000 | [diff] [blame] | 2676 | } |
| 2677 | |
shannon.woods@transgaming.com | 664916b | 2013-01-25 21:50:32 +0000 | [diff] [blame] | 2678 | 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] | 2679 | GLint xoffset, GLint yoffset, TextureStorageInterfaceCube *storage, GLenum target, GLint level) |
daniel@transgaming.com | de8a7ff | 2012-11-28 19:34:13 +0000 | [diff] [blame] | 2680 | { |
shannon.woods@transgaming.com | 664916b | 2013-01-25 21:50:32 +0000 | [diff] [blame] | 2681 | RECT rect; |
| 2682 | rect.left = sourceRect.x; |
| 2683 | rect.top = sourceRect.y; |
| 2684 | rect.right = sourceRect.x + sourceRect.width; |
| 2685 | rect.bottom = sourceRect.y + sourceRect.height; |
| 2686 | |
| 2687 | return mBlit->copy(framebuffer, rect, destFormat, xoffset, yoffset, storage, target, level); |
daniel@transgaming.com | de8a7ff | 2012-11-28 19:34:13 +0000 | [diff] [blame] | 2688 | } |
| 2689 | |
shannon.woods%transgaming.com@gtempaccount.com | 414e82a | 2013-04-13 03:44:05 +0000 | [diff] [blame] | 2690 | bool Renderer9::copyImage(gl::Framebuffer *framebuffer, const gl::Rectangle &sourceRect, GLenum destFormat, |
| 2691 | GLint xoffset, GLint yoffset, GLint zOffset, TextureStorageInterface3D *storage, GLint level) |
| 2692 | { |
| 2693 | // 3D textures are not available in the D3D9 backend. |
| 2694 | UNREACHABLE(); |
| 2695 | return false; |
| 2696 | } |
| 2697 | |
shannon.woods%transgaming.com@gtempaccount.com | 6c86bd5 | 2013-04-13 03:45:45 +0000 | [diff] [blame] | 2698 | bool Renderer9::copyImage(gl::Framebuffer *framebuffer, const gl::Rectangle &sourceRect, GLenum destFormat, |
| 2699 | GLint xoffset, GLint yoffset, GLint zOffset, TextureStorageInterface2DArray *storage, GLint level) |
| 2700 | { |
| 2701 | // 2D array textures are not available in the D3D9 backend. |
| 2702 | UNREACHABLE(); |
| 2703 | return false; |
| 2704 | } |
| 2705 | |
shannon.woods@transgaming.com | ea4a0c6 | 2013-02-28 23:06:29 +0000 | [diff] [blame] | 2706 | bool Renderer9::blitRect(gl::Framebuffer *readFramebuffer, const gl::Rectangle &readRect, gl::Framebuffer *drawFramebuffer, const gl::Rectangle &drawRect, |
Geoff Lang | 685806d | 2013-06-12 11:16:36 -0400 | [diff] [blame] | 2707 | bool blitRenderTarget, bool blitDepth, bool blitStencil, GLenum filter) |
daniel@transgaming.com | 6c87217 | 2012-11-28 19:39:33 +0000 | [diff] [blame] | 2708 | { |
Geoff Lang | 758d5b2 | 2013-06-11 11:42:50 -0400 | [diff] [blame] | 2709 | ASSERT(filter == GL_NEAREST); |
| 2710 | |
daniel@transgaming.com | 6c87217 | 2012-11-28 19:39:33 +0000 | [diff] [blame] | 2711 | endScene(); |
| 2712 | |
| 2713 | if (blitRenderTarget) |
| 2714 | { |
shannon.woods%transgaming.com@gtempaccount.com | 89ae113 | 2013-04-13 03:28:43 +0000 | [diff] [blame] | 2715 | gl::Renderbuffer *readBuffer = readFramebuffer->getColorbuffer(0); |
| 2716 | gl::Renderbuffer *drawBuffer = drawFramebuffer->getColorbuffer(0); |
daniel@transgaming.com | d186dc7 | 2012-11-28 19:40:16 +0000 | [diff] [blame] | 2717 | RenderTarget9 *readRenderTarget = NULL; |
| 2718 | RenderTarget9 *drawRenderTarget = NULL; |
| 2719 | IDirect3DSurface9* readSurface = NULL; |
| 2720 | IDirect3DSurface9* drawSurface = NULL; |
| 2721 | |
| 2722 | if (readBuffer) |
| 2723 | { |
| 2724 | readRenderTarget = RenderTarget9::makeRenderTarget9(readBuffer->getRenderTarget()); |
| 2725 | } |
| 2726 | if (drawBuffer) |
| 2727 | { |
| 2728 | drawRenderTarget = RenderTarget9::makeRenderTarget9(drawBuffer->getRenderTarget()); |
| 2729 | } |
| 2730 | |
| 2731 | if (readRenderTarget) |
| 2732 | { |
| 2733 | readSurface = readRenderTarget->getSurface(); |
| 2734 | } |
| 2735 | if (drawRenderTarget) |
| 2736 | { |
| 2737 | drawSurface = drawRenderTarget->getSurface(); |
| 2738 | } |
| 2739 | |
| 2740 | if (!readSurface || !drawSurface) |
| 2741 | { |
| 2742 | ERR("Failed to retrieve the render target."); |
shannon.woods@transgaming.com | 779aa26 | 2013-02-28 23:04:58 +0000 | [diff] [blame] | 2743 | return gl::error(GL_OUT_OF_MEMORY, false); |
daniel@transgaming.com | d186dc7 | 2012-11-28 19:40:16 +0000 | [diff] [blame] | 2744 | } |
daniel@transgaming.com | 6c87217 | 2012-11-28 19:39:33 +0000 | [diff] [blame] | 2745 | |
shannon.woods@transgaming.com | ea4a0c6 | 2013-02-28 23:06:29 +0000 | [diff] [blame] | 2746 | RECT srcRect; |
| 2747 | srcRect.left = readRect.x; |
| 2748 | srcRect.right = readRect.x + readRect.width; |
| 2749 | srcRect.top = readRect.y; |
| 2750 | srcRect.bottom = readRect.y + readRect.height; |
daniel@transgaming.com | 6c87217 | 2012-11-28 19:39:33 +0000 | [diff] [blame] | 2751 | |
shannon.woods@transgaming.com | ea4a0c6 | 2013-02-28 23:06:29 +0000 | [diff] [blame] | 2752 | RECT dstRect; |
| 2753 | dstRect.left = drawRect.x; |
| 2754 | dstRect.right = drawRect.x + drawRect.width; |
| 2755 | dstRect.top = drawRect.y; |
| 2756 | dstRect.bottom = drawRect.y + drawRect.height; |
daniel@transgaming.com | 6c87217 | 2012-11-28 19:39:33 +0000 | [diff] [blame] | 2757 | |
shannon.woods@transgaming.com | ea4a0c6 | 2013-02-28 23:06:29 +0000 | [diff] [blame] | 2758 | HRESULT result = mDevice->StretchRect(readSurface, &srcRect, drawSurface, &dstRect, D3DTEXF_NONE); |
daniel@transgaming.com | 6c87217 | 2012-11-28 19:39:33 +0000 | [diff] [blame] | 2759 | |
daniel@transgaming.com | d186dc7 | 2012-11-28 19:40:16 +0000 | [diff] [blame] | 2760 | readSurface->Release(); |
| 2761 | drawSurface->Release(); |
daniel@transgaming.com | 6c87217 | 2012-11-28 19:39:33 +0000 | [diff] [blame] | 2762 | |
| 2763 | if (FAILED(result)) |
| 2764 | { |
| 2765 | ERR("BlitFramebufferANGLE failed: StretchRect returned %x.", result); |
| 2766 | return false; |
| 2767 | } |
| 2768 | } |
| 2769 | |
Geoff Lang | 685806d | 2013-06-12 11:16:36 -0400 | [diff] [blame] | 2770 | if (blitDepth || blitStencil) |
daniel@transgaming.com | 6c87217 | 2012-11-28 19:39:33 +0000 | [diff] [blame] | 2771 | { |
daniel@transgaming.com | d186dc7 | 2012-11-28 19:40:16 +0000 | [diff] [blame] | 2772 | gl::Renderbuffer *readBuffer = readFramebuffer->getDepthOrStencilbuffer(); |
| 2773 | gl::Renderbuffer *drawBuffer = drawFramebuffer->getDepthOrStencilbuffer(); |
| 2774 | RenderTarget9 *readDepthStencil = NULL; |
| 2775 | RenderTarget9 *drawDepthStencil = NULL; |
| 2776 | IDirect3DSurface9* readSurface = NULL; |
| 2777 | IDirect3DSurface9* drawSurface = NULL; |
daniel@transgaming.com | 6c87217 | 2012-11-28 19:39:33 +0000 | [diff] [blame] | 2778 | |
daniel@transgaming.com | d186dc7 | 2012-11-28 19:40:16 +0000 | [diff] [blame] | 2779 | if (readBuffer) |
| 2780 | { |
| 2781 | readDepthStencil = RenderTarget9::makeRenderTarget9(readBuffer->getDepthStencil()); |
| 2782 | } |
| 2783 | if (drawBuffer) |
| 2784 | { |
| 2785 | drawDepthStencil = RenderTarget9::makeRenderTarget9(drawBuffer->getDepthStencil()); |
| 2786 | } |
daniel@transgaming.com | 6c87217 | 2012-11-28 19:39:33 +0000 | [diff] [blame] | 2787 | |
daniel@transgaming.com | d186dc7 | 2012-11-28 19:40:16 +0000 | [diff] [blame] | 2788 | if (readDepthStencil) |
| 2789 | { |
| 2790 | readSurface = readDepthStencil->getSurface(); |
| 2791 | } |
| 2792 | if (drawDepthStencil) |
| 2793 | { |
| 2794 | drawSurface = drawDepthStencil->getSurface(); |
| 2795 | } |
| 2796 | |
| 2797 | if (!readSurface || !drawSurface) |
| 2798 | { |
| 2799 | ERR("Failed to retrieve the render target."); |
shannon.woods@transgaming.com | 779aa26 | 2013-02-28 23:04:58 +0000 | [diff] [blame] | 2800 | return gl::error(GL_OUT_OF_MEMORY, false); |
daniel@transgaming.com | d186dc7 | 2012-11-28 19:40:16 +0000 | [diff] [blame] | 2801 | } |
| 2802 | |
| 2803 | HRESULT result = mDevice->StretchRect(readSurface, NULL, drawSurface, NULL, D3DTEXF_NONE); |
| 2804 | |
| 2805 | readSurface->Release(); |
| 2806 | drawSurface->Release(); |
daniel@transgaming.com | 6c87217 | 2012-11-28 19:39:33 +0000 | [diff] [blame] | 2807 | |
| 2808 | if (FAILED(result)) |
| 2809 | { |
| 2810 | ERR("BlitFramebufferANGLE failed: StretchRect returned %x.", result); |
| 2811 | return false; |
| 2812 | } |
| 2813 | } |
| 2814 | |
| 2815 | return true; |
| 2816 | } |
| 2817 | |
| 2818 | void Renderer9::readPixels(gl::Framebuffer *framebuffer, GLint x, GLint y, GLsizei width, GLsizei height, GLenum format, GLenum type, |
| 2819 | GLsizei outputPitch, bool packReverseRowOrder, GLint packAlignment, void* pixels) |
| 2820 | { |
daniel@transgaming.com | d186dc7 | 2012-11-28 19:40:16 +0000 | [diff] [blame] | 2821 | RenderTarget9 *renderTarget = NULL; |
| 2822 | IDirect3DSurface9 *surface = NULL; |
shannon.woods%transgaming.com@gtempaccount.com | 89ae113 | 2013-04-13 03:28:43 +0000 | [diff] [blame] | 2823 | gl::Renderbuffer *colorbuffer = framebuffer->getColorbuffer(0); |
daniel@transgaming.com | d186dc7 | 2012-11-28 19:40:16 +0000 | [diff] [blame] | 2824 | |
| 2825 | if (colorbuffer) |
daniel@transgaming.com | 6c87217 | 2012-11-28 19:39:33 +0000 | [diff] [blame] | 2826 | { |
daniel@transgaming.com | d186dc7 | 2012-11-28 19:40:16 +0000 | [diff] [blame] | 2827 | renderTarget = RenderTarget9::makeRenderTarget9(colorbuffer->getRenderTarget()); |
| 2828 | } |
| 2829 | |
| 2830 | if (renderTarget) |
| 2831 | { |
| 2832 | surface = renderTarget->getSurface(); |
| 2833 | } |
| 2834 | |
| 2835 | if (!surface) |
| 2836 | { |
| 2837 | // context must be lost |
| 2838 | return; |
daniel@transgaming.com | 6c87217 | 2012-11-28 19:39:33 +0000 | [diff] [blame] | 2839 | } |
| 2840 | |
| 2841 | D3DSURFACE_DESC desc; |
daniel@transgaming.com | d186dc7 | 2012-11-28 19:40:16 +0000 | [diff] [blame] | 2842 | surface->GetDesc(&desc); |
daniel@transgaming.com | 6c87217 | 2012-11-28 19:39:33 +0000 | [diff] [blame] | 2843 | |
| 2844 | if (desc.MultiSampleType != D3DMULTISAMPLE_NONE) |
| 2845 | { |
| 2846 | UNIMPLEMENTED(); // FIXME: Requires resolve using StretchRect into non-multisampled render target |
daniel@transgaming.com | d186dc7 | 2012-11-28 19:40:16 +0000 | [diff] [blame] | 2847 | surface->Release(); |
shannon.woods@transgaming.com | 779aa26 | 2013-02-28 23:04:58 +0000 | [diff] [blame] | 2848 | return gl::error(GL_OUT_OF_MEMORY); |
daniel@transgaming.com | 6c87217 | 2012-11-28 19:39:33 +0000 | [diff] [blame] | 2849 | } |
| 2850 | |
| 2851 | HRESULT result; |
| 2852 | IDirect3DSurface9 *systemSurface = NULL; |
| 2853 | bool directToPixels = !packReverseRowOrder && packAlignment <= 4 && getShareHandleSupport() && |
| 2854 | x == 0 && y == 0 && UINT(width) == desc.Width && UINT(height) == desc.Height && |
| 2855 | desc.Format == D3DFMT_A8R8G8B8 && format == GL_BGRA_EXT && type == GL_UNSIGNED_BYTE; |
| 2856 | if (directToPixels) |
| 2857 | { |
| 2858 | // Use the pixels ptr as a shared handle to write directly into client's memory |
| 2859 | result = mDevice->CreateOffscreenPlainSurface(desc.Width, desc.Height, desc.Format, |
| 2860 | D3DPOOL_SYSTEMMEM, &systemSurface, &pixels); |
| 2861 | if (FAILED(result)) |
| 2862 | { |
| 2863 | // Try again without the shared handle |
| 2864 | directToPixels = false; |
| 2865 | } |
| 2866 | } |
| 2867 | |
| 2868 | if (!directToPixels) |
| 2869 | { |
| 2870 | result = mDevice->CreateOffscreenPlainSurface(desc.Width, desc.Height, desc.Format, |
| 2871 | D3DPOOL_SYSTEMMEM, &systemSurface, NULL); |
| 2872 | if (FAILED(result)) |
| 2873 | { |
| 2874 | ASSERT(result == D3DERR_OUTOFVIDEOMEMORY || result == E_OUTOFMEMORY); |
daniel@transgaming.com | d186dc7 | 2012-11-28 19:40:16 +0000 | [diff] [blame] | 2875 | surface->Release(); |
shannon.woods@transgaming.com | 779aa26 | 2013-02-28 23:04:58 +0000 | [diff] [blame] | 2876 | return gl::error(GL_OUT_OF_MEMORY); |
daniel@transgaming.com | 6c87217 | 2012-11-28 19:39:33 +0000 | [diff] [blame] | 2877 | } |
| 2878 | } |
| 2879 | |
daniel@transgaming.com | d186dc7 | 2012-11-28 19:40:16 +0000 | [diff] [blame] | 2880 | result = mDevice->GetRenderTargetData(surface, systemSurface); |
| 2881 | surface->Release(); |
| 2882 | surface = NULL; |
daniel@transgaming.com | 6c87217 | 2012-11-28 19:39:33 +0000 | [diff] [blame] | 2883 | |
| 2884 | if (FAILED(result)) |
| 2885 | { |
| 2886 | systemSurface->Release(); |
| 2887 | |
| 2888 | // It turns out that D3D will sometimes produce more error |
| 2889 | // codes than those documented. |
shannon.woods@transgaming.com | eb049e2 | 2013-02-28 23:04:49 +0000 | [diff] [blame] | 2890 | if (d3d9::isDeviceLostError(result)) |
| 2891 | { |
| 2892 | notifyDeviceLost(); |
shannon.woods@transgaming.com | 779aa26 | 2013-02-28 23:04:58 +0000 | [diff] [blame] | 2893 | return gl::error(GL_OUT_OF_MEMORY); |
shannon.woods@transgaming.com | eb049e2 | 2013-02-28 23:04:49 +0000 | [diff] [blame] | 2894 | } |
daniel@transgaming.com | 6c87217 | 2012-11-28 19:39:33 +0000 | [diff] [blame] | 2895 | else |
| 2896 | { |
| 2897 | UNREACHABLE(); |
| 2898 | return; |
| 2899 | } |
| 2900 | |
| 2901 | } |
| 2902 | |
| 2903 | if (directToPixels) |
| 2904 | { |
| 2905 | systemSurface->Release(); |
| 2906 | return; |
| 2907 | } |
| 2908 | |
| 2909 | RECT rect; |
| 2910 | rect.left = gl::clamp(x, 0L, static_cast<LONG>(desc.Width)); |
| 2911 | rect.top = gl::clamp(y, 0L, static_cast<LONG>(desc.Height)); |
| 2912 | rect.right = gl::clamp(x + width, 0L, static_cast<LONG>(desc.Width)); |
| 2913 | rect.bottom = gl::clamp(y + height, 0L, static_cast<LONG>(desc.Height)); |
| 2914 | |
| 2915 | D3DLOCKED_RECT lock; |
| 2916 | result = systemSurface->LockRect(&lock, &rect, D3DLOCK_READONLY); |
| 2917 | |
| 2918 | if (FAILED(result)) |
| 2919 | { |
| 2920 | UNREACHABLE(); |
| 2921 | systemSurface->Release(); |
| 2922 | |
| 2923 | return; // No sensible error to generate |
| 2924 | } |
| 2925 | |
daniel@transgaming.com | 6c87217 | 2012-11-28 19:39:33 +0000 | [diff] [blame] | 2926 | unsigned char *source; |
| 2927 | int inputPitch; |
| 2928 | if (packReverseRowOrder) |
| 2929 | { |
| 2930 | source = ((unsigned char*)lock.pBits) + lock.Pitch * (rect.bottom - rect.top - 1); |
| 2931 | inputPitch = -lock.Pitch; |
| 2932 | } |
| 2933 | else |
| 2934 | { |
| 2935 | source = (unsigned char*)lock.pBits; |
| 2936 | inputPitch = lock.Pitch; |
| 2937 | } |
| 2938 | |
Geoff Lang | 697ad3e | 2013-06-04 10:11:28 -0400 | [diff] [blame] | 2939 | GLuint clientVersion = getCurrentClientVersion(); |
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 | GLint sourceInternalFormat = d3d9_gl::GetInternalFormat(desc.Format); |
| 2942 | GLenum sourceFormat = gl::GetFormat(sourceInternalFormat, clientVersion); |
| 2943 | GLenum sourceType = gl::GetType(sourceInternalFormat, clientVersion); |
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 | GLuint sourcePixelSize = gl::GetPixelBytes(sourceInternalFormat, clientVersion); |
| 2946 | |
| 2947 | if (sourceFormat == format && sourceType == type) |
daniel@transgaming.com | 6c87217 | 2012-11-28 19:39:33 +0000 | [diff] [blame] | 2948 | { |
Geoff Lang | 697ad3e | 2013-06-04 10:11:28 -0400 | [diff] [blame] | 2949 | // Direct copy possible |
| 2950 | unsigned char *dest = static_cast<unsigned char*>(pixels); |
| 2951 | for (int y = 0; y < rect.bottom - rect.top; y++) |
daniel@transgaming.com | 6c87217 | 2012-11-28 19:39:33 +0000 | [diff] [blame] | 2952 | { |
Geoff Lang | 697ad3e | 2013-06-04 10:11:28 -0400 | [diff] [blame] | 2953 | 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] | 2954 | } |
Geoff Lang | 697ad3e | 2013-06-04 10:11:28 -0400 | [diff] [blame] | 2955 | } |
| 2956 | else |
| 2957 | { |
| 2958 | GLint destInternalFormat = gl::GetSizedInternalFormat(format, type, clientVersion); |
| 2959 | GLuint destPixelSize = gl::GetPixelBytes(destInternalFormat, clientVersion); |
| 2960 | GLuint sourcePixelSize = gl::GetPixelBytes(sourceInternalFormat, clientVersion); |
| 2961 | |
| 2962 | ColorCopyFunction fastCopyFunc = d3d9::GetFastCopyFunction(desc.Format, format, type, getCurrentClientVersion()); |
| 2963 | if (fastCopyFunc) |
shannon.woods%transgaming.com@gtempaccount.com | 676dc8f | 2013-04-13 03:35:13 +0000 | [diff] [blame] | 2964 | { |
Geoff Lang | 697ad3e | 2013-06-04 10:11:28 -0400 | [diff] [blame] | 2965 | // Fast copy is possible through some special function |
| 2966 | 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] | 2967 | { |
Geoff Lang | 697ad3e | 2013-06-04 10:11:28 -0400 | [diff] [blame] | 2968 | for (int x = 0; x < rect.right - rect.left; x++) |
| 2969 | { |
| 2970 | void *dest = static_cast<unsigned char*>(pixels) + y * outputPitch + x * destPixelSize; |
| 2971 | void *src = static_cast<unsigned char*>(source) + y * inputPitch + x * sourcePixelSize; |
| 2972 | |
| 2973 | fastCopyFunc(src, dest); |
| 2974 | } |
shannon.woods%transgaming.com@gtempaccount.com | 676dc8f | 2013-04-13 03:35:13 +0000 | [diff] [blame] | 2975 | } |
shannon.woods%transgaming.com@gtempaccount.com | 676dc8f | 2013-04-13 03:35:13 +0000 | [diff] [blame] | 2976 | } |
Geoff Lang | 697ad3e | 2013-06-04 10:11:28 -0400 | [diff] [blame] | 2977 | else |
daniel@transgaming.com | 6c87217 | 2012-11-28 19:39:33 +0000 | [diff] [blame] | 2978 | { |
Geoff Lang | 697ad3e | 2013-06-04 10:11:28 -0400 | [diff] [blame] | 2979 | ColorReadFunction readFunc = d3d9::GetColorReadFunction(desc.Format); |
| 2980 | ColorWriteFunction writeFunc = gl::GetColorWriteFunction(format, type, clientVersion); |
daniel@transgaming.com | 6c87217 | 2012-11-28 19:39:33 +0000 | [diff] [blame] | 2981 | |
Geoff Lang | 697ad3e | 2013-06-04 10:11:28 -0400 | [diff] [blame] | 2982 | gl::ColorF temp; |
| 2983 | |
| 2984 | for (int y = 0; y < rect.bottom - rect.top; y++) |
daniel@transgaming.com | 6c87217 | 2012-11-28 19:39:33 +0000 | [diff] [blame] | 2985 | { |
Geoff Lang | 697ad3e | 2013-06-04 10:11:28 -0400 | [diff] [blame] | 2986 | for (int x = 0; x < rect.right - rect.left; x++) |
daniel@transgaming.com | 6c87217 | 2012-11-28 19:39:33 +0000 | [diff] [blame] | 2987 | { |
Geoff Lang | 697ad3e | 2013-06-04 10:11:28 -0400 | [diff] [blame] | 2988 | void *dest = reinterpret_cast<unsigned char*>(pixels) + y * outputPitch + x * destPixelSize; |
| 2989 | void *src = source + y * inputPitch + x * sourcePixelSize; |
daniel@transgaming.com | 6c87217 | 2012-11-28 19:39:33 +0000 | [diff] [blame] | 2990 | |
Geoff Lang | 697ad3e | 2013-06-04 10:11:28 -0400 | [diff] [blame] | 2991 | // readFunc and writeFunc will be using the same type of color, CopyTexImage |
| 2992 | // will not allow the copy otherwise. |
| 2993 | readFunc(src, &temp); |
| 2994 | writeFunc(&temp, dest); |
daniel@transgaming.com | 6c87217 | 2012-11-28 19:39:33 +0000 | [diff] [blame] | 2995 | } |
daniel@transgaming.com | 6c87217 | 2012-11-28 19:39:33 +0000 | [diff] [blame] | 2996 | } |
| 2997 | } |
| 2998 | } |
| 2999 | |
| 3000 | systemSurface->UnlockRect(); |
| 3001 | |
| 3002 | systemSurface->Release(); |
| 3003 | } |
| 3004 | |
daniel@transgaming.com | f242365 | 2012-11-28 20:53:50 +0000 | [diff] [blame] | 3005 | RenderTarget *Renderer9::createRenderTarget(SwapChain *swapChain, bool depth) |
| 3006 | { |
| 3007 | SwapChain9 *swapChain9 = SwapChain9::makeSwapChain9(swapChain); |
| 3008 | IDirect3DSurface9 *surface = NULL; |
| 3009 | if (depth) |
| 3010 | { |
| 3011 | surface = swapChain9->getDepthStencil(); |
| 3012 | } |
| 3013 | else |
| 3014 | { |
| 3015 | surface = swapChain9->getRenderTarget(); |
| 3016 | } |
| 3017 | |
| 3018 | RenderTarget9 *renderTarget = new RenderTarget9(this, surface); |
| 3019 | |
| 3020 | return renderTarget; |
| 3021 | } |
| 3022 | |
Geoff Lang | a2d97f1 | 2013-06-11 11:44:02 -0400 | [diff] [blame] | 3023 | RenderTarget *Renderer9::createRenderTarget(int width, int height, GLenum format, GLsizei samples) |
daniel@transgaming.com | f242365 | 2012-11-28 20:53:50 +0000 | [diff] [blame] | 3024 | { |
| 3025 | RenderTarget9 *renderTarget = new RenderTarget9(this, width, height, format, samples); |
| 3026 | return renderTarget; |
| 3027 | } |
| 3028 | |
shannon.woods@transgaming.com | 69ff776 | 2013-01-25 21:55:24 +0000 | [diff] [blame] | 3029 | 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] | 3030 | { |
| 3031 | ShaderExecutable9 *executable = NULL; |
daniel@transgaming.com | 5531890 | 2012-11-28 20:58:58 +0000 | [diff] [blame] | 3032 | |
| 3033 | switch (type) |
| 3034 | { |
shannon.woods@transgaming.com | 69ff776 | 2013-01-25 21:55:24 +0000 | [diff] [blame] | 3035 | case rx::SHADER_VERTEX: |
daniel@transgaming.com | 5531890 | 2012-11-28 20:58:58 +0000 | [diff] [blame] | 3036 | { |
daniel@transgaming.com | 7b18d0c | 2012-11-28 21:04:10 +0000 | [diff] [blame] | 3037 | IDirect3DVertexShader9 *vshader = createVertexShader((DWORD*)function, length); |
daniel@transgaming.com | 5531890 | 2012-11-28 20:58:58 +0000 | [diff] [blame] | 3038 | if (vshader) |
| 3039 | { |
daniel@transgaming.com | 2275f91 | 2012-12-20 21:13:22 +0000 | [diff] [blame] | 3040 | executable = new ShaderExecutable9(function, length, vshader); |
daniel@transgaming.com | 5531890 | 2012-11-28 20:58:58 +0000 | [diff] [blame] | 3041 | } |
| 3042 | } |
| 3043 | break; |
shannon.woods@transgaming.com | 69ff776 | 2013-01-25 21:55:24 +0000 | [diff] [blame] | 3044 | case rx::SHADER_PIXEL: |
daniel@transgaming.com | 5531890 | 2012-11-28 20:58:58 +0000 | [diff] [blame] | 3045 | { |
daniel@transgaming.com | 7b18d0c | 2012-11-28 21:04:10 +0000 | [diff] [blame] | 3046 | IDirect3DPixelShader9 *pshader = createPixelShader((DWORD*)function, length); |
daniel@transgaming.com | 5531890 | 2012-11-28 20:58:58 +0000 | [diff] [blame] | 3047 | if (pshader) |
| 3048 | { |
daniel@transgaming.com | 2275f91 | 2012-12-20 21:13:22 +0000 | [diff] [blame] | 3049 | executable = new ShaderExecutable9(function, length, pshader); |
daniel@transgaming.com | 5531890 | 2012-11-28 20:58:58 +0000 | [diff] [blame] | 3050 | } |
| 3051 | } |
| 3052 | break; |
| 3053 | default: |
| 3054 | UNREACHABLE(); |
| 3055 | break; |
| 3056 | } |
| 3057 | |
| 3058 | return executable; |
| 3059 | } |
| 3060 | |
shannon.woods@transgaming.com | 69ff776 | 2013-01-25 21:55:24 +0000 | [diff] [blame] | 3061 | 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] | 3062 | { |
| 3063 | const char *profile = NULL; |
| 3064 | |
| 3065 | switch (type) |
| 3066 | { |
shannon.woods@transgaming.com | 69ff776 | 2013-01-25 21:55:24 +0000 | [diff] [blame] | 3067 | case rx::SHADER_VERTEX: |
daniel@transgaming.com | a9c7142 | 2012-11-28 20:58:45 +0000 | [diff] [blame] | 3068 | profile = getMajorShaderModel() >= 3 ? "vs_3_0" : "vs_2_0"; |
| 3069 | break; |
shannon.woods@transgaming.com | 69ff776 | 2013-01-25 21:55:24 +0000 | [diff] [blame] | 3070 | case rx::SHADER_PIXEL: |
daniel@transgaming.com | a9c7142 | 2012-11-28 20:58:45 +0000 | [diff] [blame] | 3071 | profile = getMajorShaderModel() >= 3 ? "ps_3_0" : "ps_2_0"; |
| 3072 | break; |
| 3073 | default: |
| 3074 | UNREACHABLE(); |
| 3075 | return NULL; |
| 3076 | } |
| 3077 | |
shannon.woods@transgaming.com | d3d4208 | 2013-02-28 23:14:31 +0000 | [diff] [blame] | 3078 | 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] | 3079 | if (!binary) |
| 3080 | return NULL; |
| 3081 | |
daniel@transgaming.com | 2275f91 | 2012-12-20 21:13:22 +0000 | [diff] [blame] | 3082 | ShaderExecutable *executable = loadExecutable(binary->GetBufferPointer(), binary->GetBufferSize(), type); |
daniel@transgaming.com | 536dd6e | 2012-11-28 21:00:18 +0000 | [diff] [blame] | 3083 | binary->Release(); |
daniel@transgaming.com | a9c7142 | 2012-11-28 20:58:45 +0000 | [diff] [blame] | 3084 | |
| 3085 | return executable; |
| 3086 | } |
| 3087 | |
daniel@transgaming.com | de8a7ff | 2012-11-28 19:34:13 +0000 | [diff] [blame] | 3088 | bool Renderer9::boxFilter(IDirect3DSurface9 *source, IDirect3DSurface9 *dest) |
| 3089 | { |
| 3090 | return mBlit->boxFilter(source, dest); |
| 3091 | } |
| 3092 | |
daniel@transgaming.com | 2507f41 | 2012-10-31 18:46:48 +0000 | [diff] [blame] | 3093 | D3DPOOL Renderer9::getTexturePool(DWORD usage) const |
daniel@transgaming.com | 621ce05 | 2012-10-31 17:52:29 +0000 | [diff] [blame] | 3094 | { |
| 3095 | if (mD3d9Ex != NULL) |
| 3096 | { |
| 3097 | return D3DPOOL_DEFAULT; |
| 3098 | } |
| 3099 | else |
| 3100 | { |
| 3101 | if (!(usage & (D3DUSAGE_DEPTHSTENCIL | D3DUSAGE_RENDERTARGET))) |
| 3102 | { |
| 3103 | return D3DPOOL_MANAGED; |
| 3104 | } |
| 3105 | } |
| 3106 | |
| 3107 | return D3DPOOL_DEFAULT; |
| 3108 | } |
| 3109 | |
daniel@transgaming.com | 1d80eee | 2012-11-28 19:33:31 +0000 | [diff] [blame] | 3110 | bool Renderer9::copyToRenderTarget(IDirect3DSurface9 *dest, IDirect3DSurface9 *source, bool fromManaged) |
| 3111 | { |
| 3112 | if (source && dest) |
| 3113 | { |
| 3114 | HRESULT result = D3DERR_OUTOFVIDEOMEMORY; |
daniel@transgaming.com | 1d80eee | 2012-11-28 19:33:31 +0000 | [diff] [blame] | 3115 | |
| 3116 | if (fromManaged) |
| 3117 | { |
| 3118 | D3DSURFACE_DESC desc; |
| 3119 | source->GetDesc(&desc); |
| 3120 | |
| 3121 | IDirect3DSurface9 *surf = 0; |
daniel@transgaming.com | 204677a | 2013-01-11 21:16:09 +0000 | [diff] [blame] | 3122 | 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] | 3123 | |
| 3124 | if (SUCCEEDED(result)) |
| 3125 | { |
daniel@transgaming.com | 4ba2406 | 2012-12-20 20:54:24 +0000 | [diff] [blame] | 3126 | Image9::copyLockableSurfaces(surf, source); |
daniel@transgaming.com | 204677a | 2013-01-11 21:16:09 +0000 | [diff] [blame] | 3127 | result = mDevice->UpdateSurface(surf, NULL, dest, NULL); |
daniel@transgaming.com | 1d80eee | 2012-11-28 19:33:31 +0000 | [diff] [blame] | 3128 | surf->Release(); |
| 3129 | } |
| 3130 | } |
| 3131 | else |
| 3132 | { |
| 3133 | endScene(); |
daniel@transgaming.com | 204677a | 2013-01-11 21:16:09 +0000 | [diff] [blame] | 3134 | result = mDevice->StretchRect(source, NULL, dest, NULL, D3DTEXF_NONE); |
daniel@transgaming.com | 1d80eee | 2012-11-28 19:33:31 +0000 | [diff] [blame] | 3135 | } |
| 3136 | |
| 3137 | if (FAILED(result)) |
| 3138 | { |
| 3139 | ASSERT(result == D3DERR_OUTOFVIDEOMEMORY || result == E_OUTOFMEMORY); |
| 3140 | return false; |
| 3141 | } |
| 3142 | } |
| 3143 | |
| 3144 | return true; |
daniel@transgaming.com | 67094ee | 2012-11-28 20:53:04 +0000 | [diff] [blame] | 3145 | } |
| 3146 | |
daniel@transgaming.com | 244e183 | 2012-12-20 20:52:35 +0000 | [diff] [blame] | 3147 | Image *Renderer9::createImage() |
| 3148 | { |
daniel@transgaming.com | 4ba2406 | 2012-12-20 20:54:24 +0000 | [diff] [blame] | 3149 | return new Image9(); |
daniel@transgaming.com | 244e183 | 2012-12-20 20:52:35 +0000 | [diff] [blame] | 3150 | } |
| 3151 | |
daniel@transgaming.com | f721fdb | 2012-12-20 20:53:11 +0000 | [diff] [blame] | 3152 | void Renderer9::generateMipmap(Image *dest, Image *src) |
| 3153 | { |
daniel@transgaming.com | 4ba2406 | 2012-12-20 20:54:24 +0000 | [diff] [blame] | 3154 | Image9 *src9 = Image9::makeImage9(src); |
| 3155 | Image9 *dst9 = Image9::makeImage9(dest); |
| 3156 | Image9::generateMipmap(dst9, src9); |
daniel@transgaming.com | f721fdb | 2012-12-20 20:53:11 +0000 | [diff] [blame] | 3157 | } |
| 3158 | |
daniel@transgaming.com | 413d271 | 2012-12-20 21:11:04 +0000 | [diff] [blame] | 3159 | TextureStorage *Renderer9::createTextureStorage2D(SwapChain *swapChain) |
| 3160 | { |
| 3161 | SwapChain9 *swapChain9 = SwapChain9::makeSwapChain9(swapChain); |
| 3162 | return new TextureStorage9_2D(this, swapChain9); |
| 3163 | } |
| 3164 | |
| 3165 | TextureStorage *Renderer9::createTextureStorage2D(int levels, GLenum internalformat, GLenum usage, bool forceRenderable, GLsizei width, GLsizei height) |
| 3166 | { |
| 3167 | return new TextureStorage9_2D(this, levels, internalformat, usage, forceRenderable, width, height); |
| 3168 | } |
| 3169 | |
| 3170 | TextureStorage *Renderer9::createTextureStorageCube(int levels, GLenum internalformat, GLenum usage, bool forceRenderable, int size) |
| 3171 | { |
| 3172 | return new TextureStorage9_Cube(this, levels, internalformat, usage, forceRenderable, size); |
| 3173 | } |
| 3174 | |
shannon.woods%transgaming.com@gtempaccount.com | 2058d64 | 2013-04-13 03:42:50 +0000 | [diff] [blame] | 3175 | TextureStorage *Renderer9::createTextureStorage3D(int levels, GLenum internalformat, GLenum usage, GLsizei width, GLsizei height, GLsizei depth) |
| 3176 | { |
| 3177 | // 3D textures are not supported by the D3D9 backend. |
| 3178 | UNREACHABLE(); |
| 3179 | |
| 3180 | return NULL; |
| 3181 | } |
| 3182 | |
shannon.woods%transgaming.com@gtempaccount.com | 6c86bd5 | 2013-04-13 03:45:45 +0000 | [diff] [blame] | 3183 | TextureStorage *Renderer9::createTextureStorage2DArray(int levels, GLenum internalformat, GLenum usage, GLsizei width, GLsizei height, GLsizei depth) |
| 3184 | { |
| 3185 | // 2D array textures are not supported by the D3D9 backend. |
| 3186 | UNREACHABLE(); |
| 3187 | |
| 3188 | return NULL; |
| 3189 | } |
| 3190 | |
shannonwoods@chromium.org | 6e4f2a6 | 2013-05-30 00:15:19 +0000 | [diff] [blame] | 3191 | bool Renderer9::getLUID(LUID *adapterLuid) const |
| 3192 | { |
| 3193 | adapterLuid->HighPart = 0; |
| 3194 | adapterLuid->LowPart = 0; |
| 3195 | |
| 3196 | if (mD3d9Ex) |
| 3197 | { |
| 3198 | mD3d9Ex->GetAdapterLUID(mAdapter, adapterLuid); |
| 3199 | return true; |
| 3200 | } |
| 3201 | |
| 3202 | return false; |
| 3203 | } |
| 3204 | |
shannon.woods%transgaming.com@gtempaccount.com | 2058d64 | 2013-04-13 03:42:50 +0000 | [diff] [blame] | 3205 | } |