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