daniel@transgaming.com | 1d6aff2 | 2012-11-28 19:30:42 +0000 | [diff] [blame] | 1 | // |
| 2 | // Copyright (c) 2012 The ANGLE Project Authors. All rights reserved. |
| 3 | // Use of this source code is governed by a BSD-style license that can be |
| 4 | // found in the LICENSE file. |
| 5 | // |
| 6 | |
| 7 | // Renderer11.cpp: Implements a back-end specific class for the D3D11 renderer. |
| 8 | |
| 9 | #include "common/debug.h" |
daniel@transgaming.com | 5503fd0 | 2012-11-28 19:38:57 +0000 | [diff] [blame] | 10 | #include "libGLESv2/main.h" |
daniel@transgaming.com | 1d6aff2 | 2012-11-28 19:30:42 +0000 | [diff] [blame] | 11 | #include "libGLESv2/utilities.h" |
daniel@transgaming.com | dcf1e67 | 2012-11-28 19:38:19 +0000 | [diff] [blame] | 12 | #include "libGLESv2/mathutil.h" |
daniel@transgaming.com | 1d6aff2 | 2012-11-28 19:30:42 +0000 | [diff] [blame] | 13 | #include "libGLESv2/renderer/Renderer11.h" |
daniel@transgaming.com | 65e6537 | 2012-11-28 19:33:50 +0000 | [diff] [blame] | 14 | #include "libGLESv2/renderer/renderer11_utils.h" |
daniel@transgaming.com | a60160b | 2012-11-28 19:41:15 +0000 | [diff] [blame] | 15 | #include "libGLESv2/renderer/SwapChain11.h" |
daniel@transgaming.com | 1d6aff2 | 2012-11-28 19:30:42 +0000 | [diff] [blame] | 16 | |
| 17 | #include "libEGL/Config.h" |
| 18 | #include "libEGL/Display.h" |
| 19 | |
| 20 | namespace rx |
| 21 | { |
daniel@transgaming.com | 65e6537 | 2012-11-28 19:33:50 +0000 | [diff] [blame] | 22 | static const DXGI_FORMAT RenderTargetFormats[] = |
| 23 | { |
| 24 | DXGI_FORMAT_R8G8B8A8_UNORM |
| 25 | }; |
| 26 | |
| 27 | static const DXGI_FORMAT DepthStencilFormats[] = |
| 28 | { |
| 29 | DXGI_FORMAT_D24_UNORM_S8_UINT |
| 30 | }; |
daniel@transgaming.com | 1d6aff2 | 2012-11-28 19:30:42 +0000 | [diff] [blame] | 31 | |
| 32 | Renderer11::Renderer11(egl::Display *display, HDC hDc) : Renderer(display), mDc(hDc) |
| 33 | { |
| 34 | mD3d11Module = NULL; |
| 35 | mDxgiModule = NULL; |
| 36 | |
daniel@transgaming.com | b9bb279 | 2012-11-28 19:36:49 +0000 | [diff] [blame] | 37 | mDeviceLost = false; |
| 38 | |
daniel@transgaming.com | 25072f6 | 2012-11-28 19:31:32 +0000 | [diff] [blame] | 39 | mDevice = NULL; |
daniel@transgaming.com | 1d6aff2 | 2012-11-28 19:30:42 +0000 | [diff] [blame] | 40 | mDeviceContext = NULL; |
daniel@transgaming.com | 65e6537 | 2012-11-28 19:33:50 +0000 | [diff] [blame] | 41 | mDxgiAdapter = NULL; |
| 42 | mDxgiFactory = NULL; |
daniel@transgaming.com | 1d6aff2 | 2012-11-28 19:30:42 +0000 | [diff] [blame] | 43 | } |
| 44 | |
| 45 | Renderer11::~Renderer11() |
| 46 | { |
| 47 | releaseDeviceResources(); |
| 48 | |
daniel@transgaming.com | 65e6537 | 2012-11-28 19:33:50 +0000 | [diff] [blame] | 49 | if (mDxgiFactory) |
| 50 | { |
| 51 | mDxgiFactory->Release(); |
| 52 | mDxgiFactory = NULL; |
| 53 | } |
| 54 | |
| 55 | if (mDxgiAdapter) |
| 56 | { |
| 57 | mDxgiAdapter->Release(); |
| 58 | mDxgiAdapter = NULL; |
| 59 | } |
| 60 | |
daniel@transgaming.com | 1d6aff2 | 2012-11-28 19:30:42 +0000 | [diff] [blame] | 61 | if (mDeviceContext) |
| 62 | { |
| 63 | mDeviceContext->Release(); |
| 64 | mDeviceContext = NULL; |
| 65 | } |
| 66 | |
daniel@transgaming.com | 25072f6 | 2012-11-28 19:31:32 +0000 | [diff] [blame] | 67 | if (mDevice) |
daniel@transgaming.com | 1d6aff2 | 2012-11-28 19:30:42 +0000 | [diff] [blame] | 68 | { |
daniel@transgaming.com | 25072f6 | 2012-11-28 19:31:32 +0000 | [diff] [blame] | 69 | mDevice->Release(); |
| 70 | mDevice = NULL; |
daniel@transgaming.com | 1d6aff2 | 2012-11-28 19:30:42 +0000 | [diff] [blame] | 71 | } |
| 72 | |
| 73 | if (mD3d11Module) |
| 74 | { |
daniel@transgaming.com | c1e2634 | 2012-11-28 19:31:16 +0000 | [diff] [blame] | 75 | FreeLibrary(mD3d11Module); |
daniel@transgaming.com | 1d6aff2 | 2012-11-28 19:30:42 +0000 | [diff] [blame] | 76 | mD3d11Module = NULL; |
| 77 | } |
| 78 | |
| 79 | if (mDxgiModule) |
| 80 | { |
daniel@transgaming.com | c1e2634 | 2012-11-28 19:31:16 +0000 | [diff] [blame] | 81 | FreeLibrary(mDxgiModule); |
daniel@transgaming.com | 1d6aff2 | 2012-11-28 19:30:42 +0000 | [diff] [blame] | 82 | mDxgiModule = NULL; |
| 83 | } |
daniel@transgaming.com | 1d6aff2 | 2012-11-28 19:30:42 +0000 | [diff] [blame] | 84 | } |
| 85 | |
| 86 | EGLint Renderer11::initialize() |
| 87 | { |
daniel@transgaming.com | c1e2634 | 2012-11-28 19:31:16 +0000 | [diff] [blame] | 88 | mDxgiModule = LoadLibrary(TEXT("dxgi.dll")); |
| 89 | mD3d11Module = LoadLibrary(TEXT("d3d11.dll")); |
daniel@transgaming.com | 1d6aff2 | 2012-11-28 19:30:42 +0000 | [diff] [blame] | 90 | |
| 91 | if (mD3d11Module == NULL || mDxgiModule == NULL) |
| 92 | { |
daniel@transgaming.com | c1e2634 | 2012-11-28 19:31:16 +0000 | [diff] [blame] | 93 | ERR("Could not load D3D11 or DXGI library - aborting!\n"); |
daniel@transgaming.com | 1d6aff2 | 2012-11-28 19:30:42 +0000 | [diff] [blame] | 94 | return EGL_NOT_INITIALIZED; |
| 95 | } |
| 96 | |
daniel@transgaming.com | c1e2634 | 2012-11-28 19:31:16 +0000 | [diff] [blame] | 97 | PFN_D3D11_CREATE_DEVICE D3D11CreateDevice = (PFN_D3D11_CREATE_DEVICE)GetProcAddress(mD3d11Module, "D3D11CreateDevice"); |
daniel@transgaming.com | 1d6aff2 | 2012-11-28 19:30:42 +0000 | [diff] [blame] | 98 | |
daniel@transgaming.com | c1e2634 | 2012-11-28 19:31:16 +0000 | [diff] [blame] | 99 | if (D3D11CreateDevice == NULL) |
| 100 | { |
| 101 | ERR("Could not retrieve D3D11CreateDevice address - aborting!\n"); |
| 102 | return EGL_NOT_INITIALIZED; |
| 103 | } |
daniel@transgaming.com | 25072f6 | 2012-11-28 19:31:32 +0000 | [diff] [blame] | 104 | |
| 105 | D3D_FEATURE_LEVEL featureLevel[] = |
| 106 | { |
| 107 | D3D_FEATURE_LEVEL_11_0, |
| 108 | D3D_FEATURE_LEVEL_10_1, |
| 109 | D3D_FEATURE_LEVEL_10_0, |
| 110 | }; |
| 111 | |
daniel@transgaming.com | c1e2634 | 2012-11-28 19:31:16 +0000 | [diff] [blame] | 112 | HRESULT result = D3D11CreateDevice(NULL, |
| 113 | D3D_DRIVER_TYPE_HARDWARE, |
| 114 | NULL, |
daniel@transgaming.com | a60160b | 2012-11-28 19:41:15 +0000 | [diff] [blame] | 115 | #if defined(_DEBUG) |
| 116 | D3D11_CREATE_DEVICE_DEBUG, |
| 117 | #else |
| 118 | 0, |
| 119 | #endif |
daniel@transgaming.com | 25072f6 | 2012-11-28 19:31:32 +0000 | [diff] [blame] | 120 | featureLevel, |
| 121 | sizeof(featureLevel)/sizeof(featureLevel[0]), |
daniel@transgaming.com | c1e2634 | 2012-11-28 19:31:16 +0000 | [diff] [blame] | 122 | D3D11_SDK_VERSION, |
daniel@transgaming.com | 25072f6 | 2012-11-28 19:31:32 +0000 | [diff] [blame] | 123 | &mDevice, |
| 124 | &mFeatureLevel, |
daniel@transgaming.com | c1e2634 | 2012-11-28 19:31:16 +0000 | [diff] [blame] | 125 | &mDeviceContext); |
daniel@transgaming.com | 25072f6 | 2012-11-28 19:31:32 +0000 | [diff] [blame] | 126 | |
| 127 | if (!mDevice || FAILED(result)) |
daniel@transgaming.com | c1e2634 | 2012-11-28 19:31:16 +0000 | [diff] [blame] | 128 | { |
| 129 | ERR("Could not create D3D11 device - aborting!\n"); |
| 130 | return EGL_NOT_INITIALIZED; // Cleanup done by destructor through glDestroyRenderer |
| 131 | } |
daniel@transgaming.com | 65e6537 | 2012-11-28 19:33:50 +0000 | [diff] [blame] | 132 | |
| 133 | IDXGIDevice *dxgiDevice = NULL; |
| 134 | result = mDevice->QueryInterface(__uuidof(IDXGIDevice), (void**)&dxgiDevice); |
| 135 | |
| 136 | if (FAILED(result)) |
| 137 | { |
| 138 | ERR("Could not query DXGI device - aborting!\n"); |
| 139 | return EGL_NOT_INITIALIZED; |
| 140 | } |
| 141 | |
| 142 | result = dxgiDevice->GetParent(__uuidof(IDXGIAdapter), (void**)&mDxgiAdapter); |
| 143 | |
| 144 | if (FAILED(result)) |
| 145 | { |
| 146 | ERR("Could not retrieve DXGI adapter - aborting!\n"); |
| 147 | return EGL_NOT_INITIALIZED; |
| 148 | } |
| 149 | |
| 150 | dxgiDevice->Release(); |
| 151 | |
| 152 | result = mDxgiAdapter->GetParent(__uuidof(IDXGIFactory), (void**)&mDxgiFactory); |
| 153 | |
| 154 | if (!mDxgiFactory || FAILED(result)) |
| 155 | { |
| 156 | ERR("Could not create DXGI factory - aborting!\n"); |
| 157 | return EGL_NOT_INITIALIZED; |
| 158 | } |
| 159 | |
daniel@transgaming.com | 1d6aff2 | 2012-11-28 19:30:42 +0000 | [diff] [blame] | 160 | initializeDevice(); |
| 161 | |
| 162 | return EGL_SUCCESS; |
| 163 | } |
| 164 | |
| 165 | // do any one-time device initialization |
| 166 | // NOTE: this is also needed after a device lost/reset |
| 167 | // to reset the scene status and ensure the default states are reset. |
| 168 | void Renderer11::initializeDevice() |
| 169 | { |
daniel@transgaming.com | f8ba109 | 2012-11-28 19:37:53 +0000 | [diff] [blame] | 170 | mStateCache.initialize(mDevice); |
| 171 | |
daniel@transgaming.com | c43a605 | 2012-11-28 19:41:51 +0000 | [diff] [blame] | 172 | markAllStateDirty(); |
| 173 | |
daniel@transgaming.com | 1d6aff2 | 2012-11-28 19:30:42 +0000 | [diff] [blame] | 174 | // Permanent non-default states |
| 175 | // TODO |
daniel@transgaming.com | c1e2634 | 2012-11-28 19:31:16 +0000 | [diff] [blame] | 176 | // UNIMPLEMENTED(); |
daniel@transgaming.com | 1d6aff2 | 2012-11-28 19:30:42 +0000 | [diff] [blame] | 177 | } |
| 178 | |
daniel@transgaming.com | 1d6aff2 | 2012-11-28 19:30:42 +0000 | [diff] [blame] | 179 | int Renderer11::generateConfigs(ConfigDesc **configDescList) |
| 180 | { |
daniel@transgaming.com | e3e826d | 2012-11-28 19:42:35 +0000 | [diff] [blame] | 181 | unsigned int numRenderFormats = sizeof(RenderTargetFormats) / sizeof(RenderTargetFormats[0]); |
| 182 | unsigned int numDepthFormats = sizeof(DepthStencilFormats) / sizeof(DepthStencilFormats[0]); |
daniel@transgaming.com | 65e6537 | 2012-11-28 19:33:50 +0000 | [diff] [blame] | 183 | (*configDescList) = new ConfigDesc[numRenderFormats * numDepthFormats]; |
| 184 | int numConfigs = 0; |
| 185 | |
daniel@transgaming.com | e3e826d | 2012-11-28 19:42:35 +0000 | [diff] [blame] | 186 | for (unsigned int formatIndex = 0; formatIndex < numRenderFormats; formatIndex++) |
daniel@transgaming.com | 65e6537 | 2012-11-28 19:33:50 +0000 | [diff] [blame] | 187 | { |
daniel@transgaming.com | e3e826d | 2012-11-28 19:42:35 +0000 | [diff] [blame] | 188 | for (unsigned int depthStencilIndex = 0; depthStencilIndex < numDepthFormats; depthStencilIndex++) |
daniel@transgaming.com | 65e6537 | 2012-11-28 19:33:50 +0000 | [diff] [blame] | 189 | { |
| 190 | DXGI_FORMAT renderTargetFormat = RenderTargetFormats[formatIndex]; |
| 191 | |
| 192 | UINT formatSupport = 0; |
| 193 | HRESULT result = mDevice->CheckFormatSupport(renderTargetFormat, &formatSupport); |
| 194 | |
| 195 | if (SUCCEEDED(result) && (formatSupport & D3D11_FORMAT_SUPPORT_RENDER_TARGET)) |
| 196 | { |
| 197 | DXGI_FORMAT depthStencilFormat = DepthStencilFormats[depthStencilIndex]; |
| 198 | |
| 199 | UINT formatSupport = 0; |
| 200 | HRESULT result = mDevice->CheckFormatSupport(depthStencilFormat, &formatSupport); |
| 201 | |
| 202 | if (SUCCEEDED(result) && (formatSupport & D3D11_FORMAT_SUPPORT_DEPTH_STENCIL)) |
| 203 | { |
| 204 | ConfigDesc newConfig; |
| 205 | newConfig.renderTargetFormat = d3d11_gl::ConvertBackBufferFormat(renderTargetFormat); |
| 206 | newConfig.depthStencilFormat = d3d11_gl::ConvertDepthStencilFormat(depthStencilFormat); |
| 207 | newConfig.multiSample = 0; // FIXME: enumerate multi-sampling |
| 208 | newConfig.fastConfig = true; // Assume all DX11 format conversions to be fast |
| 209 | |
| 210 | (*configDescList)[numConfigs++] = newConfig; |
| 211 | } |
| 212 | } |
| 213 | } |
| 214 | } |
| 215 | |
| 216 | return numConfigs; |
daniel@transgaming.com | 1d6aff2 | 2012-11-28 19:30:42 +0000 | [diff] [blame] | 217 | } |
| 218 | |
| 219 | void Renderer11::deleteConfigs(ConfigDesc *configDescList) |
| 220 | { |
| 221 | delete [] (configDescList); |
| 222 | } |
| 223 | |
| 224 | void Renderer11::startScene() |
| 225 | { |
| 226 | // TODO: nop in d3d11? |
| 227 | } |
| 228 | |
| 229 | void Renderer11::endScene() |
| 230 | { |
| 231 | // TODO: nop in d3d11? |
| 232 | } |
| 233 | |
| 234 | void Renderer11::sync(bool block) |
| 235 | { |
| 236 | // TODO |
| 237 | UNIMPLEMENTED(); |
| 238 | } |
| 239 | |
daniel@transgaming.com | b9bb279 | 2012-11-28 19:36:49 +0000 | [diff] [blame] | 240 | SwapChain *Renderer11::createSwapChain(HWND window, HANDLE shareHandle, GLenum backBufferFormat, GLenum depthBufferFormat) |
| 241 | { |
daniel@transgaming.com | a60160b | 2012-11-28 19:41:15 +0000 | [diff] [blame] | 242 | return new rx::SwapChain11(this, window, shareHandle, backBufferFormat, depthBufferFormat); |
daniel@transgaming.com | b9bb279 | 2012-11-28 19:36:49 +0000 | [diff] [blame] | 243 | } |
| 244 | |
daniel@transgaming.com | 1d6aff2 | 2012-11-28 19:30:42 +0000 | [diff] [blame] | 245 | void Renderer11::setSamplerState(gl::SamplerType type, int index, const gl::SamplerState &samplerState) |
| 246 | { |
| 247 | // TODO |
| 248 | UNIMPLEMENTED(); |
| 249 | } |
| 250 | |
| 251 | void Renderer11::setTexture(gl::SamplerType type, int index, gl::Texture *texture) |
| 252 | { |
| 253 | // TODO |
| 254 | UNIMPLEMENTED(); |
| 255 | } |
| 256 | |
daniel@transgaming.com | 493d4f8 | 2012-11-28 19:35:45 +0000 | [diff] [blame] | 257 | void Renderer11::setRasterizerState(const gl::RasterizerState &rasterState, unsigned int depthSize) |
| 258 | { |
daniel@transgaming.com | dcf1e67 | 2012-11-28 19:38:19 +0000 | [diff] [blame] | 259 | if (mForceSetRasterState || |
| 260 | memcmp(&rasterState, &mCurRasterState, sizeof(gl::RasterizerState)) != 0 || |
| 261 | depthSize != mCurDepthSize) |
| 262 | { |
| 263 | ID3D11RasterizerState *dxRasterState = mStateCache.getRasterizerState(rasterState, depthSize); |
| 264 | if (!dxRasterState) |
| 265 | { |
| 266 | ERR("NULL blend state returned by RenderStateCache::getRasterizerState, setting the " |
| 267 | "rasterizer state."); |
| 268 | } |
| 269 | |
| 270 | mDeviceContext->RSSetState(dxRasterState); |
| 271 | |
| 272 | if (dxRasterState) |
| 273 | { |
| 274 | dxRasterState->Release(); |
| 275 | } |
| 276 | mCurRasterState = rasterState; |
| 277 | mCurDepthSize = depthSize; |
| 278 | } |
| 279 | |
| 280 | mForceSetRasterState = false; |
daniel@transgaming.com | 493d4f8 | 2012-11-28 19:35:45 +0000 | [diff] [blame] | 281 | } |
| 282 | |
| 283 | void Renderer11::setBlendState(const gl::BlendState &blendState, const gl::Color &blendColor, |
| 284 | unsigned int sampleMask) |
| 285 | { |
daniel@transgaming.com | f8ba109 | 2012-11-28 19:37:53 +0000 | [diff] [blame] | 286 | if (mForceSetBlendState || |
| 287 | memcmp(&blendState, &mCurBlendState, sizeof(gl::BlendState)) != 0 || |
| 288 | memcmp(&blendColor, &mCurBlendColor, sizeof(gl::Color)) != 0 || |
| 289 | sampleMask != mCurSampleMask) |
| 290 | { |
| 291 | ID3D11BlendState *dxBlendState = mStateCache.getBlendState(blendState); |
| 292 | if (!dxBlendState) |
| 293 | { |
| 294 | ERR("NULL blend state returned by RenderStateCache::getBlendState, setting the default " |
| 295 | "blend state."); |
| 296 | } |
| 297 | |
| 298 | const float blendColors[] = { blendColor.red, blendColor.green, blendColor.blue, blendColor.alpha }; |
| 299 | mDeviceContext->OMSetBlendState(dxBlendState, blendColors, sampleMask); |
| 300 | |
| 301 | if (dxBlendState) |
| 302 | { |
| 303 | dxBlendState->Release(); |
| 304 | } |
| 305 | mCurBlendState = blendState; |
| 306 | mCurBlendColor = blendColor; |
| 307 | mCurSampleMask = sampleMask; |
| 308 | } |
| 309 | |
| 310 | mForceSetBlendState = false; |
daniel@transgaming.com | 493d4f8 | 2012-11-28 19:35:45 +0000 | [diff] [blame] | 311 | } |
| 312 | |
daniel@transgaming.com | 08c331d | 2012-11-28 19:38:39 +0000 | [diff] [blame] | 313 | void Renderer11::setDepthStencilState(const gl::DepthStencilState &depthStencilState, int stencilRef, |
| 314 | int stencilBackRef, bool frontFaceCCW, unsigned int stencilSize) |
daniel@transgaming.com | 493d4f8 | 2012-11-28 19:35:45 +0000 | [diff] [blame] | 315 | { |
daniel@transgaming.com | 5503fd0 | 2012-11-28 19:38:57 +0000 | [diff] [blame] | 316 | if (mForceSetDepthStencilState || |
| 317 | memcmp(&depthStencilState, &mCurDepthStencilState, sizeof(gl::DepthStencilState)) != 0 || |
| 318 | stencilRef != mCurStencilRef || stencilBackRef != mCurStencilBackRef) |
| 319 | { |
| 320 | if (depthStencilState.stencilWritemask != depthStencilState.stencilBackWritemask || |
| 321 | stencilRef != stencilBackRef || |
| 322 | depthStencilState.stencilMask != depthStencilState.stencilBackMask) |
| 323 | { |
| 324 | ERR("Separate front/back stencil writemasks, reference values, or stencil mask values are " |
| 325 | "invalid under WebGL."); |
| 326 | return error(GL_INVALID_OPERATION); |
| 327 | } |
| 328 | |
| 329 | ID3D11DepthStencilState *dxDepthStencilState = mStateCache.getDepthStencilState(depthStencilState); |
| 330 | if (!dxDepthStencilState) |
| 331 | { |
| 332 | ERR("NULL depth stencil state returned by RenderStateCache::getDepthStencilState, " |
| 333 | "setting the default depth stencil state."); |
| 334 | } |
| 335 | |
| 336 | mDeviceContext->OMSetDepthStencilState(dxDepthStencilState, static_cast<UINT>(stencilRef)); |
| 337 | |
| 338 | if (dxDepthStencilState) |
| 339 | { |
| 340 | dxDepthStencilState->Release(); |
| 341 | } |
| 342 | mCurDepthStencilState = depthStencilState; |
| 343 | mCurStencilRef = stencilRef; |
| 344 | mCurStencilBackRef = stencilBackRef; |
| 345 | } |
| 346 | |
| 347 | mForceSetDepthStencilState = false; |
daniel@transgaming.com | 493d4f8 | 2012-11-28 19:35:45 +0000 | [diff] [blame] | 348 | } |
| 349 | |
| 350 | void Renderer11::setScissorRectangle(const gl::Rectangle& scissor, unsigned int renderTargetWidth, |
| 351 | unsigned int renderTargetHeight) |
| 352 | { |
daniel@transgaming.com | dcf1e67 | 2012-11-28 19:38:19 +0000 | [diff] [blame] | 353 | if (mForceSetScissor || |
| 354 | renderTargetWidth != mCurRenderTargetWidth || |
| 355 | renderTargetHeight != mCurRenderTargetHeight || |
| 356 | memcmp(&scissor, &mCurScissor, sizeof(gl::Rectangle)) != 0) |
| 357 | { |
| 358 | D3D11_RECT rect; |
| 359 | rect.left = gl::clamp(scissor.x, 0, static_cast<int>(renderTargetWidth)); |
daniel@transgaming.com | 1dd557a | 2012-11-28 19:44:00 +0000 | [diff] [blame] | 360 | rect.top = gl::clamp(scissor.y, 0, static_cast<int>(renderTargetHeight)); |
daniel@transgaming.com | dcf1e67 | 2012-11-28 19:38:19 +0000 | [diff] [blame] | 361 | rect.right = gl::clamp(scissor.x + scissor.width, 0, static_cast<int>(renderTargetWidth)); |
daniel@transgaming.com | 1dd557a | 2012-11-28 19:44:00 +0000 | [diff] [blame] | 362 | rect.bottom = gl::clamp(scissor.y + scissor.height, 0, static_cast<int>(renderTargetHeight)); |
daniel@transgaming.com | dcf1e67 | 2012-11-28 19:38:19 +0000 | [diff] [blame] | 363 | |
| 364 | mDeviceContext->RSSetScissorRects(1, &rect); |
| 365 | |
| 366 | mCurScissor = scissor; |
| 367 | mCurRenderTargetWidth = renderTargetWidth; |
| 368 | mCurRenderTargetHeight = renderTargetHeight; |
| 369 | } |
| 370 | |
| 371 | mForceSetScissor = false; |
daniel@transgaming.com | 493d4f8 | 2012-11-28 19:35:45 +0000 | [diff] [blame] | 372 | } |
| 373 | |
daniel@transgaming.com | 83e80ee | 2012-11-28 19:40:53 +0000 | [diff] [blame] | 374 | bool Renderer11::setViewport(const gl::Rectangle& viewport, float zNear, float zFar, |
| 375 | unsigned int renderTargetWidth, unsigned int renderTargetHeight, |
| 376 | gl::ProgramBinary *currentProgram, bool forceSetUniforms) |
| 377 | { |
| 378 | // TODO |
| 379 | UNIMPLEMENTED(); |
| 380 | return true; |
| 381 | } |
| 382 | |
daniel@transgaming.com | ae39ee2 | 2012-11-28 19:42:02 +0000 | [diff] [blame] | 383 | bool Renderer11::applyRenderTarget(gl::Framebuffer *frameBuffer) |
daniel@transgaming.com | 493d4f8 | 2012-11-28 19:35:45 +0000 | [diff] [blame] | 384 | { |
| 385 | // TODO |
| 386 | UNIMPLEMENTED(); |
daniel@transgaming.com | dcf1e67 | 2012-11-28 19:38:19 +0000 | [diff] [blame] | 387 | |
| 388 | mForceSetScissor = true; |
daniel@transgaming.com | ae39ee2 | 2012-11-28 19:42:02 +0000 | [diff] [blame] | 389 | |
| 390 | return true; |
daniel@transgaming.com | 493d4f8 | 2012-11-28 19:35:45 +0000 | [diff] [blame] | 391 | } |
daniel@transgaming.com | 1d6aff2 | 2012-11-28 19:30:42 +0000 | [diff] [blame] | 392 | |
daniel@transgaming.com | d084c62 | 2012-11-28 19:36:05 +0000 | [diff] [blame] | 393 | void Renderer11::clear(GLbitfield mask, const gl::Color &colorClear, float depthClear, int stencilClear, |
| 394 | gl::Framebuffer *frameBuffer) |
| 395 | { |
| 396 | // TODO |
| 397 | UNIMPLEMENTED(); |
| 398 | } |
| 399 | |
daniel@transgaming.com | c43a605 | 2012-11-28 19:41:51 +0000 | [diff] [blame] | 400 | void Renderer11::markAllStateDirty() |
| 401 | { |
| 402 | mForceSetBlendState = true; |
| 403 | mForceSetRasterState = true; |
| 404 | mForceSetDepthStencilState = true; |
| 405 | mForceSetScissor = true; |
| 406 | } |
| 407 | |
daniel@transgaming.com | 1d6aff2 | 2012-11-28 19:30:42 +0000 | [diff] [blame] | 408 | void Renderer11::releaseDeviceResources() |
| 409 | { |
| 410 | // TODO |
daniel@transgaming.com | c1e2634 | 2012-11-28 19:31:16 +0000 | [diff] [blame] | 411 | // UNIMPLEMENTED(); |
daniel@transgaming.com | f8ba109 | 2012-11-28 19:37:53 +0000 | [diff] [blame] | 412 | mStateCache.clear(); |
daniel@transgaming.com | 1d6aff2 | 2012-11-28 19:30:42 +0000 | [diff] [blame] | 413 | } |
| 414 | |
| 415 | void Renderer11::markDeviceLost() |
| 416 | { |
| 417 | mDeviceLost = true; |
| 418 | } |
| 419 | |
| 420 | bool Renderer11::isDeviceLost() |
| 421 | { |
| 422 | return mDeviceLost; |
| 423 | } |
| 424 | |
| 425 | // set notify to true to broadcast a message to all contexts of the device loss |
| 426 | bool Renderer11::testDeviceLost(bool notify) |
| 427 | { |
| 428 | bool isLost = false; |
| 429 | |
| 430 | // TODO |
daniel@transgaming.com | b9bb279 | 2012-11-28 19:36:49 +0000 | [diff] [blame] | 431 | //UNIMPLEMENTED(); |
daniel@transgaming.com | 1d6aff2 | 2012-11-28 19:30:42 +0000 | [diff] [blame] | 432 | |
| 433 | if (isLost) |
| 434 | { |
| 435 | // ensure we note the device loss -- |
| 436 | // we'll probably get this done again by markDeviceLost |
| 437 | // but best to remember it! |
| 438 | // Note that we don't want to clear the device loss status here |
| 439 | // -- this needs to be done by resetDevice |
| 440 | mDeviceLost = true; |
| 441 | if (notify) |
| 442 | { |
| 443 | mDisplay->notifyDeviceLost(); |
| 444 | } |
| 445 | } |
| 446 | |
| 447 | return isLost; |
| 448 | } |
| 449 | |
| 450 | bool Renderer11::testDeviceResettable() |
| 451 | { |
| 452 | HRESULT status = D3D_OK; |
| 453 | |
| 454 | // TODO |
| 455 | UNIMPLEMENTED(); |
| 456 | |
| 457 | switch (status) |
| 458 | { |
| 459 | case D3DERR_DEVICENOTRESET: |
| 460 | case D3DERR_DEVICEHUNG: |
| 461 | return true; |
| 462 | default: |
| 463 | return false; |
| 464 | } |
| 465 | } |
| 466 | |
| 467 | bool Renderer11::resetDevice() |
| 468 | { |
| 469 | releaseDeviceResources(); |
| 470 | |
| 471 | // TODO |
| 472 | UNIMPLEMENTED(); |
| 473 | |
| 474 | // reset device defaults |
| 475 | initializeDevice(); |
| 476 | mDeviceLost = false; |
| 477 | |
| 478 | return true; |
| 479 | } |
| 480 | |
| 481 | DWORD Renderer11::getAdapterVendor() const |
| 482 | { |
| 483 | // TODO |
| 484 | UNIMPLEMENTED(); |
| 485 | return 0; |
| 486 | } |
| 487 | |
| 488 | const char *Renderer11::getAdapterDescription() const |
| 489 | { |
| 490 | // TODO |
| 491 | UNIMPLEMENTED(); |
| 492 | return "UNIMPLEMENTED"; |
| 493 | } |
| 494 | |
| 495 | GUID Renderer11::getAdapterIdentifier() const |
| 496 | { |
| 497 | // TODO |
| 498 | UNIMPLEMENTED(); |
| 499 | GUID foo = {}; |
| 500 | return foo; |
| 501 | } |
| 502 | |
| 503 | bool Renderer11::getDXT1TextureSupport() |
| 504 | { |
| 505 | // TODO |
| 506 | UNIMPLEMENTED(); |
| 507 | return false; |
| 508 | } |
| 509 | |
| 510 | bool Renderer11::getDXT3TextureSupport() |
| 511 | { |
| 512 | // TODO |
| 513 | UNIMPLEMENTED(); |
| 514 | return false; |
| 515 | } |
| 516 | |
| 517 | bool Renderer11::getDXT5TextureSupport() |
| 518 | { |
| 519 | // TODO |
| 520 | UNIMPLEMENTED(); |
| 521 | return false; |
| 522 | } |
| 523 | |
| 524 | bool Renderer11::getDepthTextureSupport() const |
| 525 | { |
| 526 | // TODO |
| 527 | UNIMPLEMENTED(); |
| 528 | return false; |
| 529 | } |
| 530 | |
| 531 | bool Renderer11::getFloat32TextureSupport(bool *filtering, bool *renderable) |
| 532 | { |
| 533 | // TODO |
| 534 | UNIMPLEMENTED(); |
| 535 | |
| 536 | *filtering = false; |
| 537 | *renderable = false; |
| 538 | return false; |
| 539 | } |
| 540 | |
| 541 | bool Renderer11::getFloat16TextureSupport(bool *filtering, bool *renderable) |
| 542 | { |
| 543 | // TODO |
| 544 | UNIMPLEMENTED(); |
| 545 | |
| 546 | *filtering = false; |
| 547 | *renderable = false; |
| 548 | return false; |
| 549 | } |
| 550 | |
| 551 | bool Renderer11::getLuminanceTextureSupport() |
| 552 | { |
| 553 | // TODO |
| 554 | UNIMPLEMENTED(); |
| 555 | return false; |
| 556 | } |
| 557 | |
| 558 | bool Renderer11::getLuminanceAlphaTextureSupport() |
| 559 | { |
| 560 | // TODO |
| 561 | UNIMPLEMENTED(); |
| 562 | return false; |
| 563 | } |
| 564 | |
| 565 | bool Renderer11::getTextureFilterAnisotropySupport() const |
| 566 | { |
| 567 | // TODO |
| 568 | UNIMPLEMENTED(); |
| 569 | return false; |
| 570 | } |
| 571 | |
| 572 | float Renderer11::getTextureMaxAnisotropy() const |
| 573 | { |
| 574 | // TODO |
| 575 | UNIMPLEMENTED(); |
| 576 | return 1.0f; |
| 577 | } |
| 578 | |
| 579 | bool Renderer11::getEventQuerySupport() |
| 580 | { |
| 581 | // TODO |
| 582 | UNIMPLEMENTED(); |
| 583 | return false; |
| 584 | } |
| 585 | |
| 586 | bool Renderer11::getVertexTextureSupport() const |
| 587 | { |
| 588 | // TODO |
| 589 | UNIMPLEMENTED(); |
| 590 | return false; |
| 591 | } |
| 592 | |
| 593 | bool Renderer11::getNonPower2TextureSupport() const |
| 594 | { |
| 595 | // TODO |
| 596 | UNIMPLEMENTED(); |
| 597 | return false; |
| 598 | } |
| 599 | |
| 600 | bool Renderer11::getOcclusionQuerySupport() const |
| 601 | { |
| 602 | // TODO |
| 603 | UNIMPLEMENTED(); |
| 604 | return false; |
| 605 | } |
| 606 | |
| 607 | bool Renderer11::getInstancingSupport() const |
| 608 | { |
| 609 | // TODO |
| 610 | UNIMPLEMENTED(); |
| 611 | return false; |
| 612 | } |
| 613 | |
| 614 | bool Renderer11::getShareHandleSupport() const |
| 615 | { |
| 616 | // TODO |
daniel@transgaming.com | b9bb279 | 2012-11-28 19:36:49 +0000 | [diff] [blame] | 617 | //UNIMPLEMENTED(); |
daniel@transgaming.com | 1d6aff2 | 2012-11-28 19:30:42 +0000 | [diff] [blame] | 618 | |
| 619 | // PIX doesn't seem to support using share handles, so disable them. |
| 620 | return false && !gl::perfActive(); |
| 621 | } |
| 622 | |
| 623 | bool Renderer11::getShaderModel3Support() const |
| 624 | { |
| 625 | // TODO |
| 626 | UNIMPLEMENTED(); |
| 627 | return true; |
| 628 | } |
| 629 | |
| 630 | float Renderer11::getMaxPointSize() const |
| 631 | { |
| 632 | // TODO |
| 633 | UNIMPLEMENTED(); |
| 634 | return 1.0f; |
| 635 | } |
| 636 | |
| 637 | int Renderer11::getMaxTextureWidth() const |
| 638 | { |
daniel@transgaming.com | 25072f6 | 2012-11-28 19:31:32 +0000 | [diff] [blame] | 639 | switch (mFeatureLevel) |
| 640 | { |
| 641 | case D3D_FEATURE_LEVEL_11_0: return D3D11_REQ_TEXTURE2D_U_OR_V_DIMENSION; // 16384 |
| 642 | case D3D_FEATURE_LEVEL_10_1: |
| 643 | case D3D_FEATURE_LEVEL_10_0: return D3D10_REQ_TEXTURE2D_U_OR_V_DIMENSION; // 8192 |
| 644 | default: UNREACHABLE(); return 0; |
| 645 | } |
daniel@transgaming.com | 1d6aff2 | 2012-11-28 19:30:42 +0000 | [diff] [blame] | 646 | } |
| 647 | |
| 648 | int Renderer11::getMaxTextureHeight() const |
| 649 | { |
daniel@transgaming.com | 25072f6 | 2012-11-28 19:31:32 +0000 | [diff] [blame] | 650 | switch (mFeatureLevel) |
| 651 | { |
| 652 | case D3D_FEATURE_LEVEL_11_0: return D3D11_REQ_TEXTURE2D_U_OR_V_DIMENSION; // 16384 |
| 653 | case D3D_FEATURE_LEVEL_10_1: |
| 654 | case D3D_FEATURE_LEVEL_10_0: return D3D10_REQ_TEXTURE2D_U_OR_V_DIMENSION; // 8192 |
| 655 | default: UNREACHABLE(); return 0; |
| 656 | } |
daniel@transgaming.com | 1d6aff2 | 2012-11-28 19:30:42 +0000 | [diff] [blame] | 657 | } |
| 658 | |
| 659 | bool Renderer11::get32BitIndexSupport() const |
| 660 | { |
daniel@transgaming.com | 25072f6 | 2012-11-28 19:31:32 +0000 | [diff] [blame] | 661 | switch (mFeatureLevel) |
| 662 | { |
| 663 | case D3D_FEATURE_LEVEL_11_0: |
| 664 | case D3D_FEATURE_LEVEL_10_1: |
| 665 | case D3D_FEATURE_LEVEL_10_0: return D3D10_REQ_DRAWINDEXED_INDEX_COUNT_2_TO_EXP >= 32; // true |
| 666 | default: UNREACHABLE(); return false; |
| 667 | } |
daniel@transgaming.com | 1d6aff2 | 2012-11-28 19:30:42 +0000 | [diff] [blame] | 668 | } |
| 669 | |
| 670 | int Renderer11::getMinSwapInterval() const |
| 671 | { |
daniel@transgaming.com | 8c7b1a9 | 2012-11-28 19:34:06 +0000 | [diff] [blame] | 672 | return 0; |
daniel@transgaming.com | 1d6aff2 | 2012-11-28 19:30:42 +0000 | [diff] [blame] | 673 | } |
| 674 | |
| 675 | int Renderer11::getMaxSwapInterval() const |
| 676 | { |
daniel@transgaming.com | 8c7b1a9 | 2012-11-28 19:34:06 +0000 | [diff] [blame] | 677 | return 4; |
daniel@transgaming.com | 1d6aff2 | 2012-11-28 19:30:42 +0000 | [diff] [blame] | 678 | } |
| 679 | |
| 680 | int Renderer11::getMaxSupportedSamples() const |
| 681 | { |
| 682 | // TODO |
| 683 | UNIMPLEMENTED(); |
| 684 | return 1; |
| 685 | } |
| 686 | |
daniel@transgaming.com | 31b13e1 | 2012-11-28 19:34:30 +0000 | [diff] [blame] | 687 | bool Renderer11::copyToRenderTarget(TextureStorage2D *dest, TextureStorage2D *source) |
daniel@transgaming.com | ad6aee7 | 2012-11-28 19:33:42 +0000 | [diff] [blame] | 688 | { |
| 689 | // TODO |
| 690 | UNIMPLEMENTED(); |
| 691 | return false; |
| 692 | } |
| 693 | |
daniel@transgaming.com | 31b13e1 | 2012-11-28 19:34:30 +0000 | [diff] [blame] | 694 | bool Renderer11::copyToRenderTarget(TextureStorageCubeMap *dest, TextureStorageCubeMap *source) |
daniel@transgaming.com | ad6aee7 | 2012-11-28 19:33:42 +0000 | [diff] [blame] | 695 | { |
| 696 | // TODO |
| 697 | UNIMPLEMENTED(); |
| 698 | return false; |
| 699 | } |
| 700 | |
daniel@transgaming.com | 3838088 | 2012-11-28 19:36:39 +0000 | [diff] [blame] | 701 | bool Renderer11::copyImage(gl::Framebuffer *framebuffer, const RECT &sourceRect, GLenum destFormat, |
| 702 | GLint xoffset, GLint yoffset, TextureStorage2D *storage, GLint level) |
| 703 | { |
| 704 | // TODO |
| 705 | UNIMPLEMENTED(); |
| 706 | return false; |
| 707 | } |
| 708 | |
| 709 | bool Renderer11::copyImage(gl::Framebuffer *framebuffer, const RECT &sourceRect, GLenum destFormat, |
| 710 | GLint xoffset, GLint yoffset, TextureStorageCubeMap *storage, GLenum target, GLint level) |
| 711 | { |
| 712 | // TODO |
| 713 | UNIMPLEMENTED(); |
| 714 | return false; |
| 715 | } |
| 716 | |
daniel@transgaming.com | 6c87217 | 2012-11-28 19:39:33 +0000 | [diff] [blame] | 717 | bool Renderer11::blitRect(gl::Framebuffer *readTarget, gl::Rectangle *readRect, gl::Framebuffer *drawTarget, gl::Rectangle *drawRect, |
| 718 | bool blitRenderTarget, bool blitDepthStencil) |
| 719 | { |
| 720 | // TODO |
| 721 | UNIMPLEMENTED(); |
| 722 | return false; |
| 723 | } |
| 724 | |
| 725 | void Renderer11::readPixels(gl::Framebuffer *framebuffer, GLint x, GLint y, GLsizei width, GLsizei height, GLenum format, GLenum type, |
| 726 | GLsizei outputPitch, bool packReverseRowOrder, GLint packAlignment, void* pixels) |
| 727 | { |
| 728 | // TODO |
| 729 | UNIMPLEMENTED(); |
| 730 | return; |
| 731 | } |
| 732 | |
daniel@transgaming.com | 1d6aff2 | 2012-11-28 19:30:42 +0000 | [diff] [blame] | 733 | } |