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 | 18adad0 | 2012-11-28 21:04:03 +0000 | [diff] [blame] | 13 | #include "libGLESv2/Buffer.h" |
daniel@transgaming.com | 5367004 | 2012-11-28 20:55:51 +0000 | [diff] [blame] | 14 | #include "libGLESv2/Program.h" |
| 15 | #include "libGLESv2/ProgramBinary.h" |
daniel@transgaming.com | 80fc332 | 2012-11-28 21:02:13 +0000 | [diff] [blame] | 16 | #include "libGLESv2/Framebuffer.h" |
daniel@transgaming.com | 1d6aff2 | 2012-11-28 19:30:42 +0000 | [diff] [blame] | 17 | #include "libGLESv2/renderer/Renderer11.h" |
daniel@transgaming.com | b6b27bc | 2012-11-28 20:54:30 +0000 | [diff] [blame] | 18 | #include "libGLESv2/renderer/RenderTarget11.h" |
daniel@transgaming.com | 65e6537 | 2012-11-28 19:33:50 +0000 | [diff] [blame] | 19 | #include "libGLESv2/renderer/renderer11_utils.h" |
daniel@transgaming.com | a2f9fbe | 2012-11-28 21:03:40 +0000 | [diff] [blame] | 20 | #include "libGLESv2/renderer/ShaderExecutable11.h" |
daniel@transgaming.com | a60160b | 2012-11-28 19:41:15 +0000 | [diff] [blame] | 21 | #include "libGLESv2/renderer/SwapChain11.h" |
daniel@transgaming.com | 1d6aff2 | 2012-11-28 19:30:42 +0000 | [diff] [blame] | 22 | |
| 23 | #include "libEGL/Config.h" |
| 24 | #include "libEGL/Display.h" |
| 25 | |
| 26 | namespace rx |
| 27 | { |
daniel@transgaming.com | 65e6537 | 2012-11-28 19:33:50 +0000 | [diff] [blame] | 28 | static const DXGI_FORMAT RenderTargetFormats[] = |
| 29 | { |
| 30 | DXGI_FORMAT_R8G8B8A8_UNORM |
| 31 | }; |
| 32 | |
| 33 | static const DXGI_FORMAT DepthStencilFormats[] = |
| 34 | { |
| 35 | DXGI_FORMAT_D24_UNORM_S8_UINT |
| 36 | }; |
daniel@transgaming.com | 1d6aff2 | 2012-11-28 19:30:42 +0000 | [diff] [blame] | 37 | |
| 38 | Renderer11::Renderer11(egl::Display *display, HDC hDc) : Renderer(display), mDc(hDc) |
| 39 | { |
| 40 | mD3d11Module = NULL; |
| 41 | mDxgiModule = NULL; |
| 42 | |
daniel@transgaming.com | b9bb279 | 2012-11-28 19:36:49 +0000 | [diff] [blame] | 43 | mDeviceLost = false; |
| 44 | |
daniel@transgaming.com | 25072f6 | 2012-11-28 19:31:32 +0000 | [diff] [blame] | 45 | mDevice = NULL; |
daniel@transgaming.com | 1d6aff2 | 2012-11-28 19:30:42 +0000 | [diff] [blame] | 46 | mDeviceContext = NULL; |
daniel@transgaming.com | 65e6537 | 2012-11-28 19:33:50 +0000 | [diff] [blame] | 47 | mDxgiAdapter = NULL; |
| 48 | mDxgiFactory = NULL; |
daniel@transgaming.com | 1d6aff2 | 2012-11-28 19:30:42 +0000 | [diff] [blame] | 49 | } |
| 50 | |
| 51 | Renderer11::~Renderer11() |
| 52 | { |
| 53 | releaseDeviceResources(); |
| 54 | |
daniel@transgaming.com | 65e6537 | 2012-11-28 19:33:50 +0000 | [diff] [blame] | 55 | if (mDxgiFactory) |
| 56 | { |
| 57 | mDxgiFactory->Release(); |
| 58 | mDxgiFactory = NULL; |
| 59 | } |
| 60 | |
| 61 | if (mDxgiAdapter) |
| 62 | { |
| 63 | mDxgiAdapter->Release(); |
| 64 | mDxgiAdapter = NULL; |
| 65 | } |
| 66 | |
daniel@transgaming.com | 1d6aff2 | 2012-11-28 19:30:42 +0000 | [diff] [blame] | 67 | if (mDeviceContext) |
| 68 | { |
| 69 | mDeviceContext->Release(); |
| 70 | mDeviceContext = NULL; |
| 71 | } |
| 72 | |
daniel@transgaming.com | 25072f6 | 2012-11-28 19:31:32 +0000 | [diff] [blame] | 73 | if (mDevice) |
daniel@transgaming.com | 1d6aff2 | 2012-11-28 19:30:42 +0000 | [diff] [blame] | 74 | { |
daniel@transgaming.com | 25072f6 | 2012-11-28 19:31:32 +0000 | [diff] [blame] | 75 | mDevice->Release(); |
| 76 | mDevice = NULL; |
daniel@transgaming.com | 1d6aff2 | 2012-11-28 19:30:42 +0000 | [diff] [blame] | 77 | } |
| 78 | |
| 79 | if (mD3d11Module) |
| 80 | { |
daniel@transgaming.com | c1e2634 | 2012-11-28 19:31:16 +0000 | [diff] [blame] | 81 | FreeLibrary(mD3d11Module); |
daniel@transgaming.com | 1d6aff2 | 2012-11-28 19:30:42 +0000 | [diff] [blame] | 82 | mD3d11Module = NULL; |
| 83 | } |
| 84 | |
| 85 | if (mDxgiModule) |
| 86 | { |
daniel@transgaming.com | c1e2634 | 2012-11-28 19:31:16 +0000 | [diff] [blame] | 87 | FreeLibrary(mDxgiModule); |
daniel@transgaming.com | 1d6aff2 | 2012-11-28 19:30:42 +0000 | [diff] [blame] | 88 | mDxgiModule = NULL; |
| 89 | } |
daniel@transgaming.com | 1d6aff2 | 2012-11-28 19:30:42 +0000 | [diff] [blame] | 90 | } |
| 91 | |
daniel@transgaming.com | b64ed28 | 2012-11-28 20:54:02 +0000 | [diff] [blame] | 92 | Renderer11 *Renderer11::makeRenderer11(Renderer *renderer) |
| 93 | { |
| 94 | ASSERT(dynamic_cast<rx::Renderer11*>(renderer) != NULL); |
| 95 | return static_cast<rx::Renderer11*>(renderer); |
| 96 | } |
| 97 | |
daniel@transgaming.com | 1d6aff2 | 2012-11-28 19:30:42 +0000 | [diff] [blame] | 98 | EGLint Renderer11::initialize() |
| 99 | { |
daniel@transgaming.com | 25e16af | 2012-11-28 21:05:57 +0000 | [diff] [blame] | 100 | if (!initializeCompiler()) |
| 101 | { |
| 102 | return EGL_NOT_INITIALIZED; |
| 103 | } |
| 104 | |
daniel@transgaming.com | c1e2634 | 2012-11-28 19:31:16 +0000 | [diff] [blame] | 105 | mDxgiModule = LoadLibrary(TEXT("dxgi.dll")); |
| 106 | mD3d11Module = LoadLibrary(TEXT("d3d11.dll")); |
daniel@transgaming.com | 1d6aff2 | 2012-11-28 19:30:42 +0000 | [diff] [blame] | 107 | |
| 108 | if (mD3d11Module == NULL || mDxgiModule == NULL) |
| 109 | { |
daniel@transgaming.com | c1e2634 | 2012-11-28 19:31:16 +0000 | [diff] [blame] | 110 | ERR("Could not load D3D11 or DXGI library - aborting!\n"); |
daniel@transgaming.com | 1d6aff2 | 2012-11-28 19:30:42 +0000 | [diff] [blame] | 111 | return EGL_NOT_INITIALIZED; |
| 112 | } |
| 113 | |
daniel@transgaming.com | c1e2634 | 2012-11-28 19:31:16 +0000 | [diff] [blame] | 114 | 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] | 115 | |
daniel@transgaming.com | c1e2634 | 2012-11-28 19:31:16 +0000 | [diff] [blame] | 116 | if (D3D11CreateDevice == NULL) |
| 117 | { |
| 118 | ERR("Could not retrieve D3D11CreateDevice address - aborting!\n"); |
| 119 | return EGL_NOT_INITIALIZED; |
| 120 | } |
daniel@transgaming.com | 25072f6 | 2012-11-28 19:31:32 +0000 | [diff] [blame] | 121 | |
| 122 | D3D_FEATURE_LEVEL featureLevel[] = |
| 123 | { |
| 124 | D3D_FEATURE_LEVEL_11_0, |
| 125 | D3D_FEATURE_LEVEL_10_1, |
| 126 | D3D_FEATURE_LEVEL_10_0, |
| 127 | }; |
| 128 | |
daniel@transgaming.com | c1e2634 | 2012-11-28 19:31:16 +0000 | [diff] [blame] | 129 | HRESULT result = D3D11CreateDevice(NULL, |
| 130 | D3D_DRIVER_TYPE_HARDWARE, |
| 131 | NULL, |
daniel@transgaming.com | a60160b | 2012-11-28 19:41:15 +0000 | [diff] [blame] | 132 | #if defined(_DEBUG) |
| 133 | D3D11_CREATE_DEVICE_DEBUG, |
| 134 | #else |
| 135 | 0, |
| 136 | #endif |
daniel@transgaming.com | 25072f6 | 2012-11-28 19:31:32 +0000 | [diff] [blame] | 137 | featureLevel, |
| 138 | sizeof(featureLevel)/sizeof(featureLevel[0]), |
daniel@transgaming.com | c1e2634 | 2012-11-28 19:31:16 +0000 | [diff] [blame] | 139 | D3D11_SDK_VERSION, |
daniel@transgaming.com | 25072f6 | 2012-11-28 19:31:32 +0000 | [diff] [blame] | 140 | &mDevice, |
| 141 | &mFeatureLevel, |
daniel@transgaming.com | c1e2634 | 2012-11-28 19:31:16 +0000 | [diff] [blame] | 142 | &mDeviceContext); |
daniel@transgaming.com | 25072f6 | 2012-11-28 19:31:32 +0000 | [diff] [blame] | 143 | |
| 144 | if (!mDevice || FAILED(result)) |
daniel@transgaming.com | c1e2634 | 2012-11-28 19:31:16 +0000 | [diff] [blame] | 145 | { |
| 146 | ERR("Could not create D3D11 device - aborting!\n"); |
| 147 | return EGL_NOT_INITIALIZED; // Cleanup done by destructor through glDestroyRenderer |
| 148 | } |
daniel@transgaming.com | 65e6537 | 2012-11-28 19:33:50 +0000 | [diff] [blame] | 149 | |
| 150 | IDXGIDevice *dxgiDevice = NULL; |
| 151 | result = mDevice->QueryInterface(__uuidof(IDXGIDevice), (void**)&dxgiDevice); |
| 152 | |
| 153 | if (FAILED(result)) |
| 154 | { |
| 155 | ERR("Could not query DXGI device - aborting!\n"); |
| 156 | return EGL_NOT_INITIALIZED; |
| 157 | } |
| 158 | |
| 159 | result = dxgiDevice->GetParent(__uuidof(IDXGIAdapter), (void**)&mDxgiAdapter); |
| 160 | |
| 161 | if (FAILED(result)) |
| 162 | { |
| 163 | ERR("Could not retrieve DXGI adapter - aborting!\n"); |
| 164 | return EGL_NOT_INITIALIZED; |
| 165 | } |
| 166 | |
| 167 | dxgiDevice->Release(); |
| 168 | |
daniel@transgaming.com | 1f811f5 | 2012-11-28 20:57:39 +0000 | [diff] [blame] | 169 | mDxgiAdapter->GetDesc(&mAdapterDescription); |
| 170 | memset(mDescription, 0, sizeof(mDescription)); |
| 171 | wcstombs(mDescription, mAdapterDescription.Description, sizeof(mDescription) - 1); |
| 172 | |
daniel@transgaming.com | 65e6537 | 2012-11-28 19:33:50 +0000 | [diff] [blame] | 173 | result = mDxgiAdapter->GetParent(__uuidof(IDXGIFactory), (void**)&mDxgiFactory); |
| 174 | |
| 175 | if (!mDxgiFactory || FAILED(result)) |
| 176 | { |
| 177 | ERR("Could not create DXGI factory - aborting!\n"); |
| 178 | return EGL_NOT_INITIALIZED; |
| 179 | } |
| 180 | |
daniel@transgaming.com | 1d6aff2 | 2012-11-28 19:30:42 +0000 | [diff] [blame] | 181 | initializeDevice(); |
| 182 | |
| 183 | return EGL_SUCCESS; |
| 184 | } |
| 185 | |
| 186 | // do any one-time device initialization |
| 187 | // NOTE: this is also needed after a device lost/reset |
| 188 | // to reset the scene status and ensure the default states are reset. |
| 189 | void Renderer11::initializeDevice() |
| 190 | { |
daniel@transgaming.com | f8ba109 | 2012-11-28 19:37:53 +0000 | [diff] [blame] | 191 | mStateCache.initialize(mDevice); |
| 192 | |
daniel@transgaming.com | c43a605 | 2012-11-28 19:41:51 +0000 | [diff] [blame] | 193 | markAllStateDirty(); |
| 194 | |
daniel@transgaming.com | 1d6aff2 | 2012-11-28 19:30:42 +0000 | [diff] [blame] | 195 | // Permanent non-default states |
| 196 | // TODO |
daniel@transgaming.com | c1e2634 | 2012-11-28 19:31:16 +0000 | [diff] [blame] | 197 | // UNIMPLEMENTED(); |
daniel@transgaming.com | 1d6aff2 | 2012-11-28 19:30:42 +0000 | [diff] [blame] | 198 | } |
| 199 | |
daniel@transgaming.com | 1d6aff2 | 2012-11-28 19:30:42 +0000 | [diff] [blame] | 200 | int Renderer11::generateConfigs(ConfigDesc **configDescList) |
| 201 | { |
daniel@transgaming.com | e3e826d | 2012-11-28 19:42:35 +0000 | [diff] [blame] | 202 | unsigned int numRenderFormats = sizeof(RenderTargetFormats) / sizeof(RenderTargetFormats[0]); |
| 203 | unsigned int numDepthFormats = sizeof(DepthStencilFormats) / sizeof(DepthStencilFormats[0]); |
daniel@transgaming.com | 65e6537 | 2012-11-28 19:33:50 +0000 | [diff] [blame] | 204 | (*configDescList) = new ConfigDesc[numRenderFormats * numDepthFormats]; |
| 205 | int numConfigs = 0; |
| 206 | |
daniel@transgaming.com | e3e826d | 2012-11-28 19:42:35 +0000 | [diff] [blame] | 207 | for (unsigned int formatIndex = 0; formatIndex < numRenderFormats; formatIndex++) |
daniel@transgaming.com | 65e6537 | 2012-11-28 19:33:50 +0000 | [diff] [blame] | 208 | { |
daniel@transgaming.com | e3e826d | 2012-11-28 19:42:35 +0000 | [diff] [blame] | 209 | for (unsigned int depthStencilIndex = 0; depthStencilIndex < numDepthFormats; depthStencilIndex++) |
daniel@transgaming.com | 65e6537 | 2012-11-28 19:33:50 +0000 | [diff] [blame] | 210 | { |
| 211 | DXGI_FORMAT renderTargetFormat = RenderTargetFormats[formatIndex]; |
| 212 | |
| 213 | UINT formatSupport = 0; |
| 214 | HRESULT result = mDevice->CheckFormatSupport(renderTargetFormat, &formatSupport); |
| 215 | |
| 216 | if (SUCCEEDED(result) && (formatSupport & D3D11_FORMAT_SUPPORT_RENDER_TARGET)) |
| 217 | { |
| 218 | DXGI_FORMAT depthStencilFormat = DepthStencilFormats[depthStencilIndex]; |
| 219 | |
| 220 | UINT formatSupport = 0; |
| 221 | HRESULT result = mDevice->CheckFormatSupport(depthStencilFormat, &formatSupport); |
| 222 | |
| 223 | if (SUCCEEDED(result) && (formatSupport & D3D11_FORMAT_SUPPORT_DEPTH_STENCIL)) |
| 224 | { |
| 225 | ConfigDesc newConfig; |
| 226 | newConfig.renderTargetFormat = d3d11_gl::ConvertBackBufferFormat(renderTargetFormat); |
| 227 | newConfig.depthStencilFormat = d3d11_gl::ConvertDepthStencilFormat(depthStencilFormat); |
| 228 | newConfig.multiSample = 0; // FIXME: enumerate multi-sampling |
| 229 | newConfig.fastConfig = true; // Assume all DX11 format conversions to be fast |
| 230 | |
| 231 | (*configDescList)[numConfigs++] = newConfig; |
| 232 | } |
| 233 | } |
| 234 | } |
| 235 | } |
| 236 | |
| 237 | return numConfigs; |
daniel@transgaming.com | 1d6aff2 | 2012-11-28 19:30:42 +0000 | [diff] [blame] | 238 | } |
| 239 | |
| 240 | void Renderer11::deleteConfigs(ConfigDesc *configDescList) |
| 241 | { |
| 242 | delete [] (configDescList); |
| 243 | } |
| 244 | |
daniel@transgaming.com | 1d6aff2 | 2012-11-28 19:30:42 +0000 | [diff] [blame] | 245 | void Renderer11::sync(bool block) |
| 246 | { |
| 247 | // TODO |
| 248 | UNIMPLEMENTED(); |
| 249 | } |
| 250 | |
daniel@transgaming.com | b9bb279 | 2012-11-28 19:36:49 +0000 | [diff] [blame] | 251 | SwapChain *Renderer11::createSwapChain(HWND window, HANDLE shareHandle, GLenum backBufferFormat, GLenum depthBufferFormat) |
| 252 | { |
daniel@transgaming.com | a60160b | 2012-11-28 19:41:15 +0000 | [diff] [blame] | 253 | return new rx::SwapChain11(this, window, shareHandle, backBufferFormat, depthBufferFormat); |
daniel@transgaming.com | b9bb279 | 2012-11-28 19:36:49 +0000 | [diff] [blame] | 254 | } |
| 255 | |
daniel@transgaming.com | 1d6aff2 | 2012-11-28 19:30:42 +0000 | [diff] [blame] | 256 | void Renderer11::setSamplerState(gl::SamplerType type, int index, const gl::SamplerState &samplerState) |
| 257 | { |
| 258 | // TODO |
| 259 | UNIMPLEMENTED(); |
| 260 | } |
| 261 | |
| 262 | void Renderer11::setTexture(gl::SamplerType type, int index, gl::Texture *texture) |
| 263 | { |
| 264 | // TODO |
| 265 | UNIMPLEMENTED(); |
| 266 | } |
| 267 | |
daniel@transgaming.com | 237bc7e | 2012-11-28 21:01:06 +0000 | [diff] [blame] | 268 | void Renderer11::setRasterizerState(const gl::RasterizerState &rasterState) |
daniel@transgaming.com | 493d4f8 | 2012-11-28 19:35:45 +0000 | [diff] [blame] | 269 | { |
daniel@transgaming.com | 237bc7e | 2012-11-28 21:01:06 +0000 | [diff] [blame] | 270 | if (mForceSetRasterState || memcmp(&rasterState, &mCurRasterState, sizeof(gl::RasterizerState)) != 0) |
daniel@transgaming.com | dcf1e67 | 2012-11-28 19:38:19 +0000 | [diff] [blame] | 271 | { |
daniel@transgaming.com | d55e8c1 | 2012-11-28 21:07:02 +0000 | [diff] [blame] | 272 | ID3D11RasterizerState *dxRasterState = mStateCache.getRasterizerState(rasterState, mScissorEnabled, |
| 273 | mCurDepthSize); |
daniel@transgaming.com | dcf1e67 | 2012-11-28 19:38:19 +0000 | [diff] [blame] | 274 | if (!dxRasterState) |
| 275 | { |
daniel@transgaming.com | d55e8c1 | 2012-11-28 21:07:02 +0000 | [diff] [blame] | 276 | ERR("NULL blend state returned by RenderStateCache::getRasterizerState, setting the default" |
daniel@transgaming.com | dcf1e67 | 2012-11-28 19:38:19 +0000 | [diff] [blame] | 277 | "rasterizer state."); |
| 278 | } |
| 279 | |
| 280 | mDeviceContext->RSSetState(dxRasterState); |
| 281 | |
| 282 | if (dxRasterState) |
| 283 | { |
| 284 | dxRasterState->Release(); |
| 285 | } |
| 286 | mCurRasterState = rasterState; |
daniel@transgaming.com | dcf1e67 | 2012-11-28 19:38:19 +0000 | [diff] [blame] | 287 | } |
| 288 | |
| 289 | mForceSetRasterState = false; |
daniel@transgaming.com | 493d4f8 | 2012-11-28 19:35:45 +0000 | [diff] [blame] | 290 | } |
| 291 | |
| 292 | void Renderer11::setBlendState(const gl::BlendState &blendState, const gl::Color &blendColor, |
| 293 | unsigned int sampleMask) |
| 294 | { |
daniel@transgaming.com | f8ba109 | 2012-11-28 19:37:53 +0000 | [diff] [blame] | 295 | if (mForceSetBlendState || |
| 296 | memcmp(&blendState, &mCurBlendState, sizeof(gl::BlendState)) != 0 || |
| 297 | memcmp(&blendColor, &mCurBlendColor, sizeof(gl::Color)) != 0 || |
| 298 | sampleMask != mCurSampleMask) |
| 299 | { |
| 300 | ID3D11BlendState *dxBlendState = mStateCache.getBlendState(blendState); |
| 301 | if (!dxBlendState) |
| 302 | { |
| 303 | ERR("NULL blend state returned by RenderStateCache::getBlendState, setting the default " |
| 304 | "blend state."); |
| 305 | } |
| 306 | |
| 307 | const float blendColors[] = { blendColor.red, blendColor.green, blendColor.blue, blendColor.alpha }; |
| 308 | mDeviceContext->OMSetBlendState(dxBlendState, blendColors, sampleMask); |
| 309 | |
| 310 | if (dxBlendState) |
| 311 | { |
| 312 | dxBlendState->Release(); |
| 313 | } |
| 314 | mCurBlendState = blendState; |
| 315 | mCurBlendColor = blendColor; |
| 316 | mCurSampleMask = sampleMask; |
| 317 | } |
| 318 | |
| 319 | mForceSetBlendState = false; |
daniel@transgaming.com | 493d4f8 | 2012-11-28 19:35:45 +0000 | [diff] [blame] | 320 | } |
| 321 | |
daniel@transgaming.com | 08c331d | 2012-11-28 19:38:39 +0000 | [diff] [blame] | 322 | void Renderer11::setDepthStencilState(const gl::DepthStencilState &depthStencilState, int stencilRef, |
daniel@transgaming.com | 3a0ef48 | 2012-11-28 21:01:20 +0000 | [diff] [blame] | 323 | int stencilBackRef, bool frontFaceCCW) |
daniel@transgaming.com | 493d4f8 | 2012-11-28 19:35:45 +0000 | [diff] [blame] | 324 | { |
daniel@transgaming.com | 5503fd0 | 2012-11-28 19:38:57 +0000 | [diff] [blame] | 325 | if (mForceSetDepthStencilState || |
| 326 | memcmp(&depthStencilState, &mCurDepthStencilState, sizeof(gl::DepthStencilState)) != 0 || |
| 327 | stencilRef != mCurStencilRef || stencilBackRef != mCurStencilBackRef) |
| 328 | { |
| 329 | if (depthStencilState.stencilWritemask != depthStencilState.stencilBackWritemask || |
| 330 | stencilRef != stencilBackRef || |
| 331 | depthStencilState.stencilMask != depthStencilState.stencilBackMask) |
| 332 | { |
| 333 | ERR("Separate front/back stencil writemasks, reference values, or stencil mask values are " |
| 334 | "invalid under WebGL."); |
| 335 | return error(GL_INVALID_OPERATION); |
| 336 | } |
| 337 | |
| 338 | ID3D11DepthStencilState *dxDepthStencilState = mStateCache.getDepthStencilState(depthStencilState); |
| 339 | if (!dxDepthStencilState) |
| 340 | { |
| 341 | ERR("NULL depth stencil state returned by RenderStateCache::getDepthStencilState, " |
| 342 | "setting the default depth stencil state."); |
| 343 | } |
| 344 | |
| 345 | mDeviceContext->OMSetDepthStencilState(dxDepthStencilState, static_cast<UINT>(stencilRef)); |
| 346 | |
| 347 | if (dxDepthStencilState) |
| 348 | { |
| 349 | dxDepthStencilState->Release(); |
| 350 | } |
| 351 | mCurDepthStencilState = depthStencilState; |
| 352 | mCurStencilRef = stencilRef; |
| 353 | mCurStencilBackRef = stencilBackRef; |
| 354 | } |
| 355 | |
| 356 | mForceSetDepthStencilState = false; |
daniel@transgaming.com | 493d4f8 | 2012-11-28 19:35:45 +0000 | [diff] [blame] | 357 | } |
| 358 | |
daniel@transgaming.com | d55e8c1 | 2012-11-28 21:07:02 +0000 | [diff] [blame] | 359 | void Renderer11::setScissorRectangle(const gl::Rectangle &scissor, bool enabled) |
daniel@transgaming.com | 493d4f8 | 2012-11-28 19:35:45 +0000 | [diff] [blame] | 360 | { |
daniel@transgaming.com | d55e8c1 | 2012-11-28 21:07:02 +0000 | [diff] [blame] | 361 | if (mForceSetScissor || memcmp(&scissor, &mCurScissor, sizeof(gl::Rectangle)) != 0 || |
| 362 | enabled != mScissorEnabled) |
daniel@transgaming.com | dcf1e67 | 2012-11-28 19:38:19 +0000 | [diff] [blame] | 363 | { |
daniel@transgaming.com | d55e8c1 | 2012-11-28 21:07:02 +0000 | [diff] [blame] | 364 | if (enabled) |
| 365 | { |
| 366 | D3D11_RECT rect; |
| 367 | rect.left = gl::clamp(scissor.x, 0, static_cast<int>(mRenderTargetDesc.width)); |
| 368 | rect.top = gl::clamp(scissor.y, 0, static_cast<int>(mRenderTargetDesc.height)); |
| 369 | rect.right = gl::clamp(scissor.x + scissor.width, 0, static_cast<int>(mRenderTargetDesc.width)); |
| 370 | rect.bottom = gl::clamp(scissor.y + scissor.height, 0, static_cast<int>(mRenderTargetDesc.height)); |
daniel@transgaming.com | dcf1e67 | 2012-11-28 19:38:19 +0000 | [diff] [blame] | 371 | |
daniel@transgaming.com | d55e8c1 | 2012-11-28 21:07:02 +0000 | [diff] [blame] | 372 | mDeviceContext->RSSetScissorRects(1, &rect); |
| 373 | } |
| 374 | |
| 375 | if (enabled != mScissorEnabled) |
| 376 | { |
| 377 | mForceSetRasterState = true; |
| 378 | } |
daniel@transgaming.com | dcf1e67 | 2012-11-28 19:38:19 +0000 | [diff] [blame] | 379 | |
| 380 | mCurScissor = scissor; |
daniel@transgaming.com | d55e8c1 | 2012-11-28 21:07:02 +0000 | [diff] [blame] | 381 | mScissorEnabled = enabled; |
daniel@transgaming.com | dcf1e67 | 2012-11-28 19:38:19 +0000 | [diff] [blame] | 382 | } |
| 383 | |
| 384 | mForceSetScissor = false; |
daniel@transgaming.com | 493d4f8 | 2012-11-28 19:35:45 +0000 | [diff] [blame] | 385 | } |
| 386 | |
daniel@transgaming.com | 4c4ce23 | 2012-11-28 21:01:40 +0000 | [diff] [blame] | 387 | bool Renderer11::setViewport(const gl::Rectangle &viewport, float zNear, float zFar, bool ignoreViewport, |
daniel@transgaming.com | 83e80ee | 2012-11-28 19:40:53 +0000 | [diff] [blame] | 388 | gl::ProgramBinary *currentProgram, bool forceSetUniforms) |
| 389 | { |
daniel@transgaming.com | 4c4ce23 | 2012-11-28 21:01:40 +0000 | [diff] [blame] | 390 | gl::Rectangle actualViewport = viewport; |
| 391 | float actualZNear = gl::clamp01(zNear); |
| 392 | float actualZFar = gl::clamp01(zFar); |
| 393 | if (ignoreViewport) |
| 394 | { |
| 395 | actualViewport.x = 0; |
| 396 | actualViewport.y = 0; |
| 397 | actualViewport.width = mRenderTargetDesc.width; |
| 398 | actualViewport.height = mRenderTargetDesc.height; |
| 399 | actualZNear = 0.0f; |
| 400 | actualZFar = 1.0f; |
| 401 | } |
daniel@transgaming.com | 5367004 | 2012-11-28 20:55:51 +0000 | [diff] [blame] | 402 | |
| 403 | D3D11_VIEWPORT dxViewport; |
daniel@transgaming.com | 4c4ce23 | 2012-11-28 21:01:40 +0000 | [diff] [blame] | 404 | dxViewport.TopLeftX = gl::clamp(actualViewport.x, 0, static_cast<int>(mRenderTargetDesc.width)); |
| 405 | dxViewport.TopLeftY = gl::clamp(actualViewport.y, 0, static_cast<int>(mRenderTargetDesc.height)); |
| 406 | dxViewport.Width = gl::clamp(actualViewport.width, 0, static_cast<int>(mRenderTargetDesc.width) - static_cast<int>(dxViewport.TopLeftX)); |
| 407 | dxViewport.Height = gl::clamp(actualViewport.height, 0, static_cast<int>(mRenderTargetDesc.height) - static_cast<int>(dxViewport.TopLeftY)); |
| 408 | dxViewport.MinDepth = actualZNear; |
| 409 | dxViewport.MaxDepth = actualZFar; |
daniel@transgaming.com | 5367004 | 2012-11-28 20:55:51 +0000 | [diff] [blame] | 410 | |
| 411 | if (dxViewport.Width <= 0 || dxViewport.Height <= 0) |
| 412 | { |
| 413 | return false; // Nothing to render |
| 414 | } |
| 415 | |
daniel@transgaming.com | 4c4ce23 | 2012-11-28 21:01:40 +0000 | [diff] [blame] | 416 | bool viewportChanged = mForceSetViewport || memcmp(&actualViewport, &mCurViewport, sizeof(gl::Rectangle)) != 0 || |
| 417 | actualZNear != mCurNear || actualZFar != mCurFar; |
| 418 | |
daniel@transgaming.com | 5367004 | 2012-11-28 20:55:51 +0000 | [diff] [blame] | 419 | if (viewportChanged) |
| 420 | { |
| 421 | mDeviceContext->RSSetViewports(1, &dxViewport); |
| 422 | |
daniel@transgaming.com | 4c4ce23 | 2012-11-28 21:01:40 +0000 | [diff] [blame] | 423 | mCurViewport = actualViewport; |
| 424 | mCurNear = actualZNear; |
| 425 | mCurFar = actualZFar; |
daniel@transgaming.com | 5367004 | 2012-11-28 20:55:51 +0000 | [diff] [blame] | 426 | } |
| 427 | |
| 428 | if (currentProgram && (viewportChanged || forceSetUniforms)) |
| 429 | { |
| 430 | GLint halfPixelSize = currentProgram->getDxHalfPixelSizeLocation(); |
| 431 | GLfloat xy[2] = { 0.0f, 0.0f }; |
| 432 | currentProgram->setUniform2fv(halfPixelSize, 1, xy); |
| 433 | |
| 434 | // These values are used for computing gl_FragCoord in Program::linkVaryings(). |
| 435 | GLint coord = currentProgram->getDxCoordLocation(); |
daniel@transgaming.com | 4c4ce23 | 2012-11-28 21:01:40 +0000 | [diff] [blame] | 436 | GLfloat whxy[4] = { actualViewport.width * 0.5f, |
| 437 | actualViewport.height * 0.5f, |
| 438 | actualViewport.x + (actualViewport.width * 0.5f), |
| 439 | actualViewport.y + (actualViewport.height * 0.5f) }; |
daniel@transgaming.com | 5367004 | 2012-11-28 20:55:51 +0000 | [diff] [blame] | 440 | currentProgram->setUniform4fv(coord, 1, whxy); |
| 441 | |
| 442 | GLint depth = currentProgram->getDxDepthLocation(); |
daniel@transgaming.com | 4c4ce23 | 2012-11-28 21:01:40 +0000 | [diff] [blame] | 443 | GLfloat dz[2] = { (actualZFar - actualZNear) * 0.5f, (actualZNear + actualZFar) * 0.5f }; |
daniel@transgaming.com | 5367004 | 2012-11-28 20:55:51 +0000 | [diff] [blame] | 444 | currentProgram->setUniform2fv(depth, 1, dz); |
| 445 | |
| 446 | GLint depthRange = currentProgram->getDxDepthRangeLocation(); |
daniel@transgaming.com | 4c4ce23 | 2012-11-28 21:01:40 +0000 | [diff] [blame] | 447 | GLfloat nearFarDiff[3] = { actualZNear, actualZFar, actualZFar - actualZNear }; |
daniel@transgaming.com | 5367004 | 2012-11-28 20:55:51 +0000 | [diff] [blame] | 448 | currentProgram->setUniform3fv(depthRange, 1, nearFarDiff); |
| 449 | } |
| 450 | |
| 451 | mForceSetViewport = false; |
daniel@transgaming.com | 83e80ee | 2012-11-28 19:40:53 +0000 | [diff] [blame] | 452 | return true; |
| 453 | } |
| 454 | |
daniel@transgaming.com | 91207b7 | 2012-11-28 20:56:43 +0000 | [diff] [blame] | 455 | bool Renderer11::applyPrimitiveType(GLenum mode, GLsizei count) |
| 456 | { |
daniel@transgaming.com | c52be63 | 2012-11-28 21:04:28 +0000 | [diff] [blame] | 457 | D3D11_PRIMITIVE_TOPOLOGY primitiveTopology = D3D_PRIMITIVE_TOPOLOGY_UNDEFINED; |
daniel@transgaming.com | 91207b7 | 2012-11-28 20:56:43 +0000 | [diff] [blame] | 458 | |
daniel@transgaming.com | 0b03b06 | 2012-11-28 21:03:49 +0000 | [diff] [blame] | 459 | switch (mode) |
| 460 | { |
daniel@transgaming.com | c52be63 | 2012-11-28 21:04:28 +0000 | [diff] [blame] | 461 | case GL_POINTS: primitiveTopology = D3D11_PRIMITIVE_TOPOLOGY_POINTLIST; break; |
| 462 | case GL_LINES: primitiveTopology = D3D_PRIMITIVE_TOPOLOGY_LINELIST; break; |
daniel@transgaming.com | 0b03b06 | 2012-11-28 21:03:49 +0000 | [diff] [blame] | 463 | case GL_LINE_LOOP: UNIMPLEMENTED(); /* TODO */ break; |
daniel@transgaming.com | c52be63 | 2012-11-28 21:04:28 +0000 | [diff] [blame] | 464 | case GL_LINE_STRIP: primitiveTopology = D3D_PRIMITIVE_TOPOLOGY_LINESTRIP; break; |
| 465 | case GL_TRIANGLES: primitiveTopology = D3D_PRIMITIVE_TOPOLOGY_TRIANGLELIST; break; |
| 466 | case GL_TRIANGLE_STRIP: primitiveTopology = D3D_PRIMITIVE_TOPOLOGY_TRIANGLESTRIP; break; |
daniel@transgaming.com | 0b03b06 | 2012-11-28 21:03:49 +0000 | [diff] [blame] | 467 | case GL_TRIANGLE_FAN: UNIMPLEMENTED(); /* TODO */ break; |
| 468 | default: |
| 469 | return error(GL_INVALID_ENUM, false); |
| 470 | } |
| 471 | |
daniel@transgaming.com | c52be63 | 2012-11-28 21:04:28 +0000 | [diff] [blame] | 472 | mDeviceContext->IASetPrimitiveTopology(primitiveTopology); |
daniel@transgaming.com | 0b03b06 | 2012-11-28 21:03:49 +0000 | [diff] [blame] | 473 | |
| 474 | return count > 0; |
daniel@transgaming.com | 91207b7 | 2012-11-28 20:56:43 +0000 | [diff] [blame] | 475 | } |
| 476 | |
| 477 | bool Renderer11::applyRenderTarget(gl::Framebuffer *framebuffer) |
daniel@transgaming.com | 493d4f8 | 2012-11-28 19:35:45 +0000 | [diff] [blame] | 478 | { |
daniel@transgaming.com | 80fc332 | 2012-11-28 21:02:13 +0000 | [diff] [blame] | 479 | // Get the color render buffer and serial |
| 480 | gl::Renderbuffer *renderbufferObject = NULL; |
| 481 | unsigned int renderTargetSerial = 0; |
| 482 | if (framebuffer->getColorbufferType() != GL_NONE) |
| 483 | { |
| 484 | renderbufferObject = framebuffer->getColorbuffer(); |
daniel@transgaming.com | dcf1e67 | 2012-11-28 19:38:19 +0000 | [diff] [blame] | 485 | |
daniel@transgaming.com | 80fc332 | 2012-11-28 21:02:13 +0000 | [diff] [blame] | 486 | if (!renderbufferObject) |
| 487 | { |
| 488 | ERR("render target pointer unexpectedly null."); |
daniel@transgaming.com | e9c71b4 | 2012-11-28 21:02:23 +0000 | [diff] [blame] | 489 | return false; |
daniel@transgaming.com | 80fc332 | 2012-11-28 21:02:13 +0000 | [diff] [blame] | 490 | } |
| 491 | |
| 492 | renderTargetSerial = renderbufferObject->getSerial(); |
| 493 | } |
| 494 | |
| 495 | // Get the depth stencil render buffer and serials |
| 496 | gl::Renderbuffer *depthStencil = NULL; |
| 497 | unsigned int depthbufferSerial = 0; |
| 498 | unsigned int stencilbufferSerial = 0; |
| 499 | if (framebuffer->getDepthbufferType() != GL_NONE) |
| 500 | { |
| 501 | depthStencil = framebuffer->getDepthbuffer(); |
| 502 | if (!depthStencil) |
| 503 | { |
| 504 | ERR("Depth stencil pointer unexpectedly null."); |
| 505 | return false; |
| 506 | } |
| 507 | |
| 508 | depthbufferSerial = depthStencil->getSerial(); |
| 509 | } |
| 510 | else if (framebuffer->getStencilbufferType() != GL_NONE) |
| 511 | { |
| 512 | depthStencil = framebuffer->getStencilbuffer(); |
| 513 | if (!depthStencil) |
| 514 | { |
| 515 | ERR("Depth stencil pointer unexpectedly null."); |
| 516 | return false; |
| 517 | } |
| 518 | |
| 519 | stencilbufferSerial = depthStencil->getSerial(); |
| 520 | } |
| 521 | |
| 522 | // Extract the render target dimensions and view |
| 523 | unsigned int renderTargetWidth = 0; |
| 524 | unsigned int renderTargetHeight = 0; |
| 525 | GLenum renderTargetFormat = 0; |
| 526 | ID3D11RenderTargetView* framebufferRTV = NULL; |
| 527 | if (renderbufferObject) |
| 528 | { |
| 529 | RenderTarget11 *renderTarget = RenderTarget11::makeRenderTarget11(renderbufferObject->getRenderTarget()); |
| 530 | if (!renderTarget) |
| 531 | { |
| 532 | ERR("render target pointer unexpectedly null."); |
| 533 | return false; |
| 534 | } |
| 535 | |
| 536 | framebufferRTV = renderTarget->getRenderTargetView(); |
| 537 | if (!framebufferRTV) |
| 538 | { |
| 539 | ERR("render target view pointer unexpectedly null."); |
| 540 | return false; |
| 541 | } |
| 542 | |
| 543 | renderTargetWidth = renderbufferObject->getWidth(); |
| 544 | renderTargetHeight = renderbufferObject->getHeight(); |
| 545 | renderTargetFormat = renderbufferObject->getActualFormat(); |
| 546 | } |
| 547 | |
| 548 | // Extract the depth stencil sizes and view |
| 549 | unsigned int depthSize = 0; |
| 550 | unsigned int stencilSize = 0; |
| 551 | ID3D11DepthStencilView* framebufferDSV = NULL; |
| 552 | if (depthStencil) |
| 553 | { |
| 554 | RenderTarget11 *depthStencilRenderTarget = RenderTarget11::makeRenderTarget11(depthStencil->getDepthStencil()); |
| 555 | if (!depthStencilRenderTarget) |
| 556 | { |
| 557 | ERR("render target pointer unexpectedly null."); |
| 558 | if (framebufferRTV) |
| 559 | { |
| 560 | framebufferRTV->Release(); |
| 561 | } |
| 562 | return false; |
| 563 | } |
| 564 | |
| 565 | framebufferDSV = depthStencilRenderTarget->getDepthStencilView(); |
| 566 | if (!framebufferDSV) |
| 567 | { |
| 568 | ERR("depth stencil view pointer unexpectedly null."); |
| 569 | if (framebufferRTV) |
| 570 | { |
| 571 | framebufferRTV->Release(); |
| 572 | } |
| 573 | return false; |
| 574 | } |
| 575 | |
| 576 | // If there is no render buffer, the width, height and format values come from |
| 577 | // the depth stencil |
| 578 | if (!renderbufferObject) |
| 579 | { |
| 580 | renderTargetWidth = depthStencil->getWidth(); |
| 581 | renderTargetHeight = depthStencil->getHeight(); |
| 582 | renderTargetFormat = depthStencil->getActualFormat(); |
| 583 | } |
| 584 | |
| 585 | depthSize = depthStencil->getDepthSize(); |
| 586 | stencilSize = depthStencil->getStencilSize(); |
| 587 | } |
| 588 | |
| 589 | // Apply the render target and depth stencil |
| 590 | if (!mRenderTargetDescInitialized || !mDepthStencilInitialized || |
| 591 | renderTargetSerial != mAppliedRenderTargetSerial || |
| 592 | depthbufferSerial != mAppliedDepthbufferSerial || |
| 593 | stencilbufferSerial != mAppliedStencilbufferSerial) |
| 594 | { |
| 595 | mDeviceContext->OMSetRenderTargets(1, &framebufferRTV, framebufferDSV); |
| 596 | |
| 597 | mRenderTargetDesc.width = renderTargetWidth; |
| 598 | mRenderTargetDesc.height = renderTargetHeight; |
| 599 | mRenderTargetDesc.format = renderTargetFormat; |
| 600 | mForceSetViewport = true; // TODO: It may not be required to clamp the viewport in D3D11 |
| 601 | mForceSetScissor = true; // TODO: It may not be required to clamp the scissor in D3D11 |
| 602 | |
| 603 | if (!mDepthStencilInitialized || depthSize != mCurDepthSize) |
| 604 | { |
| 605 | mCurDepthSize = depthSize; |
| 606 | mForceSetRasterState = true; |
| 607 | } |
| 608 | |
| 609 | mCurStencilSize = stencilSize; |
| 610 | |
| 611 | mAppliedRenderTargetSerial = renderTargetSerial; |
| 612 | mAppliedDepthbufferSerial = depthbufferSerial; |
| 613 | mAppliedStencilbufferSerial = stencilbufferSerial; |
| 614 | mRenderTargetDescInitialized = true; |
| 615 | mDepthStencilInitialized = true; |
| 616 | } |
| 617 | |
| 618 | if (framebufferRTV) |
| 619 | { |
| 620 | framebufferRTV->Release(); |
| 621 | } |
| 622 | if (framebufferDSV) |
| 623 | { |
| 624 | framebufferDSV->Release(); |
| 625 | } |
daniel@transgaming.com | ae39ee2 | 2012-11-28 19:42:02 +0000 | [diff] [blame] | 626 | |
| 627 | return true; |
daniel@transgaming.com | 493d4f8 | 2012-11-28 19:35:45 +0000 | [diff] [blame] | 628 | } |
daniel@transgaming.com | 1d6aff2 | 2012-11-28 19:30:42 +0000 | [diff] [blame] | 629 | |
daniel@transgaming.com | 91207b7 | 2012-11-28 20:56:43 +0000 | [diff] [blame] | 630 | GLenum Renderer11::applyVertexBuffer(gl::ProgramBinary *programBinary, gl::VertexAttribute vertexAttributes[], GLint first, GLsizei count, GLsizei instances) |
daniel@transgaming.com | def9f0f | 2012-11-28 20:53:20 +0000 | [diff] [blame] | 631 | { |
daniel@transgaming.com | 18adad0 | 2012-11-28 21:04:03 +0000 | [diff] [blame] | 632 | // TODO: Create/update vertex buffers for arbitrary GL attributes |
| 633 | ASSERT(vertexAttributes[0].mBoundBuffer.get() == 0); // UNIMPLEMENTED(); |
| 634 | |
| 635 | UINT stride = vertexAttributes[0].mStride != 0 ? vertexAttributes[0].mStride : vertexAttributes[0].typeSize(); |
| 636 | UINT size = stride * count; |
| 637 | |
| 638 | D3D11_BUFFER_DESC vertexBufferDescription = {0}; |
| 639 | vertexBufferDescription.ByteWidth = size; |
| 640 | vertexBufferDescription.Usage = D3D11_USAGE_DYNAMIC; |
| 641 | vertexBufferDescription.BindFlags = D3D11_BIND_VERTEX_BUFFER; |
| 642 | vertexBufferDescription.CPUAccessFlags = D3D11_CPU_ACCESS_WRITE; |
| 643 | vertexBufferDescription.MiscFlags = 0; |
| 644 | vertexBufferDescription.StructureByteStride = 0; |
| 645 | |
| 646 | ID3D11Buffer *vertexBuffer = NULL; |
| 647 | HRESULT result = mDevice->CreateBuffer(&vertexBufferDescription, NULL, &vertexBuffer); |
| 648 | ASSERT(SUCCEEDED(result)); |
| 649 | |
| 650 | D3D11_MAPPED_SUBRESOURCE map; |
| 651 | result = mDeviceContext->Map(vertexBuffer, 0, D3D11_MAP_WRITE_DISCARD, 0, &map); |
| 652 | ASSERT(SUCCEEDED(result)); |
| 653 | memcpy(map.pData, vertexAttributes[0].mPointer, size); |
| 654 | mDeviceContext->Unmap(vertexBuffer, 0); |
| 655 | |
| 656 | UINT offset = 0; |
| 657 | mDeviceContext->IASetVertexBuffers(0, 1, &vertexBuffer, &stride, &offset); |
| 658 | vertexBuffer->Release(); |
| 659 | |
daniel@transgaming.com | da495a1 | 2012-11-28 21:03:56 +0000 | [diff] [blame] | 660 | // TODO: Build the input layout from the (translated) attribute information |
| 661 | D3D11_INPUT_ELEMENT_DESC inputElementDescriptions[1] = |
| 662 | { |
| 663 | {"TEXCOORD", 0, DXGI_FORMAT_R32G32B32_FLOAT, 0, 0, D3D11_INPUT_PER_VERTEX_DATA, 0} |
| 664 | }; |
| 665 | |
daniel@transgaming.com | 7b18d0c | 2012-11-28 21:04:10 +0000 | [diff] [blame] | 666 | ShaderExecutable *vertexExecutable = programBinary->getVertexExecutable(); |
| 667 | |
daniel@transgaming.com | da495a1 | 2012-11-28 21:03:56 +0000 | [diff] [blame] | 668 | ID3D11InputLayout *inputLayout = NULL; |
daniel@transgaming.com | 7b18d0c | 2012-11-28 21:04:10 +0000 | [diff] [blame] | 669 | result = mDevice->CreateInputLayout(inputElementDescriptions, 1, vertexExecutable->getFunction(), vertexExecutable->getLength(), &inputLayout); |
daniel@transgaming.com | 18adad0 | 2012-11-28 21:04:03 +0000 | [diff] [blame] | 670 | ASSERT(SUCCEEDED(result)); |
daniel@transgaming.com | da495a1 | 2012-11-28 21:03:56 +0000 | [diff] [blame] | 671 | |
| 672 | mDeviceContext->IASetInputLayout(inputLayout); |
| 673 | inputLayout->Release(); // TODO: Build a cache of input layouts |
| 674 | |
daniel@transgaming.com | 18adad0 | 2012-11-28 21:04:03 +0000 | [diff] [blame] | 675 | return GL_NO_ERROR; |
daniel@transgaming.com | def9f0f | 2012-11-28 20:53:20 +0000 | [diff] [blame] | 676 | } |
| 677 | |
daniel@transgaming.com | 3124048 | 2012-11-28 21:06:41 +0000 | [diff] [blame] | 678 | GLenum Renderer11::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] | 679 | { |
| 680 | // TODO |
| 681 | UNIMPLEMENTED(); |
| 682 | |
| 683 | return GL_OUT_OF_MEMORY; |
| 684 | } |
| 685 | |
| 686 | void Renderer11::drawArrays(GLenum mode, GLsizei count, GLsizei instances) |
| 687 | { |
daniel@transgaming.com | d4cf251 | 2012-11-28 21:05:41 +0000 | [diff] [blame] | 688 | mDeviceContext->Draw(count, 0); |
daniel@transgaming.com | 91207b7 | 2012-11-28 20:56:43 +0000 | [diff] [blame] | 689 | } |
| 690 | |
daniel@transgaming.com | 3124048 | 2012-11-28 21:06:41 +0000 | [diff] [blame] | 691 | void Renderer11::drawElements(GLenum mode, GLsizei count, GLenum type, const GLvoid *indices, gl::Buffer *elementArrayBuffer, const TranslatedIndexData &indexInfo) |
daniel@transgaming.com | 91207b7 | 2012-11-28 20:56:43 +0000 | [diff] [blame] | 692 | { |
| 693 | // TODO |
| 694 | UNIMPLEMENTED(); |
| 695 | } |
| 696 | |
daniel@transgaming.com | 5fbf177 | 2012-11-28 20:54:43 +0000 | [diff] [blame] | 697 | void Renderer11::applyShaders(gl::ProgramBinary *programBinary) |
| 698 | { |
daniel@transgaming.com | d4b2db2 | 2012-11-28 21:05:15 +0000 | [diff] [blame] | 699 | ShaderExecutable *vertexExe = programBinary->getVertexExecutable(); |
| 700 | ShaderExecutable *pixelExe = programBinary->getPixelExecutable(); |
| 701 | |
| 702 | ID3D11VertexShader *vertexShader = NULL; |
| 703 | if (vertexExe) vertexShader = ShaderExecutable11::makeShaderExecutable11(vertexExe)->getVertexShader(); |
| 704 | |
| 705 | ID3D11PixelShader *pixelShader = NULL; |
| 706 | if (pixelExe) pixelShader = ShaderExecutable11::makeShaderExecutable11(pixelExe)->getPixelShader(); |
| 707 | |
| 708 | mDeviceContext->PSSetShader(pixelShader, NULL, 0); |
| 709 | mDeviceContext->VSSetShader(vertexShader, NULL, 0); |
| 710 | programBinary->dirtyAllUniforms(); |
daniel@transgaming.com | 5fbf177 | 2012-11-28 20:54:43 +0000 | [diff] [blame] | 711 | } |
| 712 | |
daniel@transgaming.com | 084a257 | 2012-11-28 20:55:17 +0000 | [diff] [blame] | 713 | void Renderer11::clear(const gl::ClearParameters &clearParams, gl::Framebuffer *frameBuffer) |
daniel@transgaming.com | d084c62 | 2012-11-28 19:36:05 +0000 | [diff] [blame] | 714 | { |
daniel@transgaming.com | 54e6754 | 2012-11-28 21:02:31 +0000 | [diff] [blame] | 715 | if (clearParams.mask & GL_COLOR_BUFFER_BIT) |
| 716 | { |
| 717 | gl::Renderbuffer *renderbufferObject = frameBuffer->getColorbuffer(); |
| 718 | if (renderbufferObject) |
| 719 | { |
| 720 | RenderTarget11 *renderTarget = RenderTarget11::makeRenderTarget11(renderbufferObject->getRenderTarget()); |
| 721 | if (!renderTarget) |
| 722 | { |
| 723 | ERR("render target pointer unexpectedly null."); |
| 724 | return; |
| 725 | } |
| 726 | |
| 727 | ID3D11RenderTargetView *framebufferRTV = renderTarget->getRenderTargetView(); |
| 728 | if (!framebufferRTV) |
| 729 | { |
| 730 | ERR("render target view pointer unexpectedly null."); |
| 731 | return; |
| 732 | } |
| 733 | |
daniel@transgaming.com | d55e8c1 | 2012-11-28 21:07:02 +0000 | [diff] [blame] | 734 | if (mScissorEnabled && (mCurScissor.x > 0 || mCurScissor.y > 0 || |
| 735 | mCurScissor.x + mCurScissor.width < renderTarget->getWidth() || |
| 736 | mCurScissor.y + mCurScissor.height < renderTarget->getHeight())) |
daniel@transgaming.com | 54e6754 | 2012-11-28 21:02:31 +0000 | [diff] [blame] | 737 | { |
| 738 | // TODO: clearing of subregion of render target |
| 739 | UNIMPLEMENTED(); |
| 740 | } |
| 741 | |
| 742 | bool alphaUnmasked = (gl::GetAlphaSize(mRenderTargetDesc.format) == 0) || clearParams.colorMaskAlpha; |
| 743 | const bool needMaskedColorClear = (clearParams.mask & GL_COLOR_BUFFER_BIT) && |
| 744 | !(clearParams.colorMaskRed && clearParams.colorMaskGreen && |
| 745 | clearParams.colorMaskBlue && alphaUnmasked); |
| 746 | |
| 747 | if (needMaskedColorClear) |
| 748 | { |
| 749 | // TODO: masked color clearing |
| 750 | UNIMPLEMENTED(); |
| 751 | } |
| 752 | else |
| 753 | { |
| 754 | const float clearValues[4] = { clearParams.colorClearValue.red, |
| 755 | clearParams.colorClearValue.green, |
| 756 | clearParams.colorClearValue.blue, |
| 757 | clearParams.colorClearValue.alpha }; |
| 758 | mDeviceContext->ClearRenderTargetView(framebufferRTV, clearValues); |
| 759 | } |
| 760 | |
| 761 | framebufferRTV->Release(); |
| 762 | } |
| 763 | } |
| 764 | if (clearParams.mask & GL_DEPTH_BUFFER_BIT || clearParams.mask & GL_STENCIL_BUFFER_BIT) |
| 765 | { |
| 766 | gl::Renderbuffer *renderbufferObject = frameBuffer->getDepthOrStencilbuffer(); |
| 767 | if (renderbufferObject) |
| 768 | { |
| 769 | RenderTarget11 *renderTarget = RenderTarget11::makeRenderTarget11(renderbufferObject->getRenderTarget()); |
| 770 | if (!renderTarget) |
| 771 | { |
| 772 | ERR("render target pointer unexpectedly null."); |
| 773 | return; |
| 774 | } |
| 775 | |
| 776 | ID3D11DepthStencilView *framebufferDSV = renderTarget->getDepthStencilView(); |
| 777 | if (!framebufferDSV) |
| 778 | { |
| 779 | ERR("depth stencil view pointer unexpectedly null."); |
| 780 | return; |
| 781 | } |
| 782 | |
daniel@transgaming.com | d55e8c1 | 2012-11-28 21:07:02 +0000 | [diff] [blame] | 783 | if (mScissorEnabled && (mCurScissor.x > 0 || mCurScissor.y > 0 || |
| 784 | mCurScissor.x + mCurScissor.width < renderTarget->getWidth() || |
| 785 | mCurScissor.y + mCurScissor.height < renderTarget->getHeight())) |
daniel@transgaming.com | 54e6754 | 2012-11-28 21:02:31 +0000 | [diff] [blame] | 786 | { |
| 787 | // TODO: clearing of subregion of depth stencil view |
| 788 | UNIMPLEMENTED(); |
| 789 | } |
| 790 | |
| 791 | unsigned int stencilUnmasked = 0x0; |
| 792 | if ((clearParams.mask & GL_STENCIL_BUFFER_BIT) && frameBuffer->hasStencil()) |
| 793 | { |
| 794 | unsigned int stencilSize = gl::GetStencilSize(frameBuffer->getStencilbuffer()->getActualFormat()); |
| 795 | stencilUnmasked = (0x1 << stencilSize) - 1; |
| 796 | } |
| 797 | |
| 798 | const bool needMaskedStencilClear = (clearParams.mask & GL_STENCIL_BUFFER_BIT) && |
| 799 | (clearParams.stencilWriteMask & stencilUnmasked) != stencilUnmasked; |
| 800 | |
| 801 | if (needMaskedStencilClear) |
| 802 | { |
| 803 | // TODO: masked clearing of depth stencil |
| 804 | UNIMPLEMENTED(); |
| 805 | } |
| 806 | else |
| 807 | { |
| 808 | UINT clearFlags = 0; |
| 809 | if (clearParams.mask & GL_DEPTH_BUFFER_BIT) |
| 810 | { |
| 811 | clearFlags |= D3D11_CLEAR_DEPTH; |
| 812 | } |
| 813 | if (clearParams.mask & GL_STENCIL_BUFFER_BIT) |
| 814 | { |
| 815 | clearFlags |= D3D11_CLEAR_STENCIL; |
| 816 | } |
| 817 | |
| 818 | float depthClear = clearParams.depthClearValue; |
| 819 | UINT8 stencilClear = clearParams.stencilClearValue & 0x000000FF; |
| 820 | |
| 821 | mDeviceContext->ClearDepthStencilView(framebufferDSV, clearFlags, depthClear, stencilClear); |
| 822 | } |
| 823 | |
| 824 | framebufferDSV->Release(); |
| 825 | } |
| 826 | } |
daniel@transgaming.com | d084c62 | 2012-11-28 19:36:05 +0000 | [diff] [blame] | 827 | } |
| 828 | |
daniel@transgaming.com | c43a605 | 2012-11-28 19:41:51 +0000 | [diff] [blame] | 829 | void Renderer11::markAllStateDirty() |
| 830 | { |
daniel@transgaming.com | 7b6b83e | 2012-11-28 21:00:30 +0000 | [diff] [blame] | 831 | mDepthStencilInitialized = false; |
| 832 | mRenderTargetDescInitialized = false; |
| 833 | |
daniel@transgaming.com | c43a605 | 2012-11-28 19:41:51 +0000 | [diff] [blame] | 834 | mForceSetBlendState = true; |
| 835 | mForceSetRasterState = true; |
| 836 | mForceSetDepthStencilState = true; |
| 837 | mForceSetScissor = true; |
daniel@transgaming.com | 5367004 | 2012-11-28 20:55:51 +0000 | [diff] [blame] | 838 | mForceSetViewport = true; |
daniel@transgaming.com | c43a605 | 2012-11-28 19:41:51 +0000 | [diff] [blame] | 839 | } |
| 840 | |
daniel@transgaming.com | 1d6aff2 | 2012-11-28 19:30:42 +0000 | [diff] [blame] | 841 | void Renderer11::releaseDeviceResources() |
| 842 | { |
| 843 | // TODO |
daniel@transgaming.com | c1e2634 | 2012-11-28 19:31:16 +0000 | [diff] [blame] | 844 | // UNIMPLEMENTED(); |
daniel@transgaming.com | f8ba109 | 2012-11-28 19:37:53 +0000 | [diff] [blame] | 845 | mStateCache.clear(); |
daniel@transgaming.com | 1d6aff2 | 2012-11-28 19:30:42 +0000 | [diff] [blame] | 846 | } |
| 847 | |
| 848 | void Renderer11::markDeviceLost() |
| 849 | { |
| 850 | mDeviceLost = true; |
| 851 | } |
| 852 | |
| 853 | bool Renderer11::isDeviceLost() |
| 854 | { |
| 855 | return mDeviceLost; |
| 856 | } |
| 857 | |
| 858 | // set notify to true to broadcast a message to all contexts of the device loss |
| 859 | bool Renderer11::testDeviceLost(bool notify) |
| 860 | { |
| 861 | bool isLost = false; |
| 862 | |
| 863 | // TODO |
daniel@transgaming.com | b9bb279 | 2012-11-28 19:36:49 +0000 | [diff] [blame] | 864 | //UNIMPLEMENTED(); |
daniel@transgaming.com | 1d6aff2 | 2012-11-28 19:30:42 +0000 | [diff] [blame] | 865 | |
| 866 | if (isLost) |
| 867 | { |
| 868 | // ensure we note the device loss -- |
| 869 | // we'll probably get this done again by markDeviceLost |
| 870 | // but best to remember it! |
| 871 | // Note that we don't want to clear the device loss status here |
| 872 | // -- this needs to be done by resetDevice |
| 873 | mDeviceLost = true; |
| 874 | if (notify) |
| 875 | { |
| 876 | mDisplay->notifyDeviceLost(); |
| 877 | } |
| 878 | } |
| 879 | |
| 880 | return isLost; |
| 881 | } |
| 882 | |
| 883 | bool Renderer11::testDeviceResettable() |
| 884 | { |
| 885 | HRESULT status = D3D_OK; |
| 886 | |
| 887 | // TODO |
| 888 | UNIMPLEMENTED(); |
| 889 | |
| 890 | switch (status) |
| 891 | { |
| 892 | case D3DERR_DEVICENOTRESET: |
| 893 | case D3DERR_DEVICEHUNG: |
| 894 | return true; |
| 895 | default: |
| 896 | return false; |
| 897 | } |
| 898 | } |
| 899 | |
| 900 | bool Renderer11::resetDevice() |
| 901 | { |
| 902 | releaseDeviceResources(); |
| 903 | |
| 904 | // TODO |
| 905 | UNIMPLEMENTED(); |
| 906 | |
| 907 | // reset device defaults |
| 908 | initializeDevice(); |
| 909 | mDeviceLost = false; |
| 910 | |
| 911 | return true; |
| 912 | } |
| 913 | |
| 914 | DWORD Renderer11::getAdapterVendor() const |
| 915 | { |
daniel@transgaming.com | 1f811f5 | 2012-11-28 20:57:39 +0000 | [diff] [blame] | 916 | return mAdapterDescription.VendorId; |
daniel@transgaming.com | 1d6aff2 | 2012-11-28 19:30:42 +0000 | [diff] [blame] | 917 | } |
| 918 | |
| 919 | const char *Renderer11::getAdapterDescription() const |
| 920 | { |
daniel@transgaming.com | 1f811f5 | 2012-11-28 20:57:39 +0000 | [diff] [blame] | 921 | return mDescription; |
daniel@transgaming.com | 1d6aff2 | 2012-11-28 19:30:42 +0000 | [diff] [blame] | 922 | } |
| 923 | |
| 924 | GUID Renderer11::getAdapterIdentifier() const |
| 925 | { |
| 926 | // TODO |
daniel@transgaming.com | 1f811f5 | 2012-11-28 20:57:39 +0000 | [diff] [blame] | 927 | // UNIMPLEMENTED(); |
| 928 | GUID foo = {0}; |
daniel@transgaming.com | 1d6aff2 | 2012-11-28 19:30:42 +0000 | [diff] [blame] | 929 | return foo; |
| 930 | } |
| 931 | |
| 932 | bool Renderer11::getDXT1TextureSupport() |
| 933 | { |
| 934 | // TODO |
daniel@transgaming.com | 1f811f5 | 2012-11-28 20:57:39 +0000 | [diff] [blame] | 935 | // UNIMPLEMENTED(); |
daniel@transgaming.com | 1d6aff2 | 2012-11-28 19:30:42 +0000 | [diff] [blame] | 936 | return false; |
| 937 | } |
| 938 | |
| 939 | bool Renderer11::getDXT3TextureSupport() |
| 940 | { |
| 941 | // TODO |
daniel@transgaming.com | 1f811f5 | 2012-11-28 20:57:39 +0000 | [diff] [blame] | 942 | // UNIMPLEMENTED(); |
daniel@transgaming.com | 1d6aff2 | 2012-11-28 19:30:42 +0000 | [diff] [blame] | 943 | return false; |
| 944 | } |
| 945 | |
| 946 | bool Renderer11::getDXT5TextureSupport() |
| 947 | { |
| 948 | // TODO |
daniel@transgaming.com | 1f811f5 | 2012-11-28 20:57:39 +0000 | [diff] [blame] | 949 | // UNIMPLEMENTED(); |
daniel@transgaming.com | 1d6aff2 | 2012-11-28 19:30:42 +0000 | [diff] [blame] | 950 | return false; |
| 951 | } |
| 952 | |
| 953 | bool Renderer11::getDepthTextureSupport() const |
| 954 | { |
| 955 | // TODO |
daniel@transgaming.com | 1f811f5 | 2012-11-28 20:57:39 +0000 | [diff] [blame] | 956 | // UNIMPLEMENTED(); |
daniel@transgaming.com | 1d6aff2 | 2012-11-28 19:30:42 +0000 | [diff] [blame] | 957 | return false; |
| 958 | } |
| 959 | |
| 960 | bool Renderer11::getFloat32TextureSupport(bool *filtering, bool *renderable) |
| 961 | { |
| 962 | // TODO |
daniel@transgaming.com | 1f811f5 | 2012-11-28 20:57:39 +0000 | [diff] [blame] | 963 | // UNIMPLEMENTED(); |
daniel@transgaming.com | 1d6aff2 | 2012-11-28 19:30:42 +0000 | [diff] [blame] | 964 | |
| 965 | *filtering = false; |
| 966 | *renderable = false; |
| 967 | return false; |
| 968 | } |
| 969 | |
| 970 | bool Renderer11::getFloat16TextureSupport(bool *filtering, bool *renderable) |
| 971 | { |
| 972 | // TODO |
daniel@transgaming.com | 1f811f5 | 2012-11-28 20:57:39 +0000 | [diff] [blame] | 973 | // UNIMPLEMENTED(); |
daniel@transgaming.com | 1d6aff2 | 2012-11-28 19:30:42 +0000 | [diff] [blame] | 974 | |
| 975 | *filtering = false; |
| 976 | *renderable = false; |
| 977 | return false; |
| 978 | } |
| 979 | |
| 980 | bool Renderer11::getLuminanceTextureSupport() |
| 981 | { |
| 982 | // TODO |
daniel@transgaming.com | 1f811f5 | 2012-11-28 20:57:39 +0000 | [diff] [blame] | 983 | // UNIMPLEMENTED(); |
daniel@transgaming.com | 1d6aff2 | 2012-11-28 19:30:42 +0000 | [diff] [blame] | 984 | return false; |
| 985 | } |
| 986 | |
| 987 | bool Renderer11::getLuminanceAlphaTextureSupport() |
| 988 | { |
| 989 | // TODO |
daniel@transgaming.com | 1f811f5 | 2012-11-28 20:57:39 +0000 | [diff] [blame] | 990 | // UNIMPLEMENTED(); |
daniel@transgaming.com | 1d6aff2 | 2012-11-28 19:30:42 +0000 | [diff] [blame] | 991 | return false; |
| 992 | } |
| 993 | |
| 994 | bool Renderer11::getTextureFilterAnisotropySupport() const |
| 995 | { |
| 996 | // TODO |
daniel@transgaming.com | 1f811f5 | 2012-11-28 20:57:39 +0000 | [diff] [blame] | 997 | // UNIMPLEMENTED(); |
daniel@transgaming.com | 1d6aff2 | 2012-11-28 19:30:42 +0000 | [diff] [blame] | 998 | return false; |
| 999 | } |
| 1000 | |
| 1001 | float Renderer11::getTextureMaxAnisotropy() const |
| 1002 | { |
| 1003 | // TODO |
daniel@transgaming.com | 1f811f5 | 2012-11-28 20:57:39 +0000 | [diff] [blame] | 1004 | // UNIMPLEMENTED(); |
daniel@transgaming.com | 1d6aff2 | 2012-11-28 19:30:42 +0000 | [diff] [blame] | 1005 | return 1.0f; |
| 1006 | } |
| 1007 | |
| 1008 | bool Renderer11::getEventQuerySupport() |
| 1009 | { |
| 1010 | // TODO |
daniel@transgaming.com | 1f811f5 | 2012-11-28 20:57:39 +0000 | [diff] [blame] | 1011 | // UNIMPLEMENTED(); |
daniel@transgaming.com | 1d6aff2 | 2012-11-28 19:30:42 +0000 | [diff] [blame] | 1012 | return false; |
| 1013 | } |
| 1014 | |
| 1015 | bool Renderer11::getVertexTextureSupport() const |
| 1016 | { |
| 1017 | // TODO |
daniel@transgaming.com | 1f811f5 | 2012-11-28 20:57:39 +0000 | [diff] [blame] | 1018 | // UNIMPLEMENTED(); |
daniel@transgaming.com | 1d6aff2 | 2012-11-28 19:30:42 +0000 | [diff] [blame] | 1019 | return false; |
| 1020 | } |
| 1021 | |
| 1022 | bool Renderer11::getNonPower2TextureSupport() const |
| 1023 | { |
| 1024 | // TODO |
daniel@transgaming.com | 1f811f5 | 2012-11-28 20:57:39 +0000 | [diff] [blame] | 1025 | // UNIMPLEMENTED(); |
daniel@transgaming.com | 1d6aff2 | 2012-11-28 19:30:42 +0000 | [diff] [blame] | 1026 | return false; |
| 1027 | } |
| 1028 | |
| 1029 | bool Renderer11::getOcclusionQuerySupport() const |
| 1030 | { |
| 1031 | // TODO |
daniel@transgaming.com | 1f811f5 | 2012-11-28 20:57:39 +0000 | [diff] [blame] | 1032 | // UNIMPLEMENTED(); |
daniel@transgaming.com | 1d6aff2 | 2012-11-28 19:30:42 +0000 | [diff] [blame] | 1033 | return false; |
| 1034 | } |
| 1035 | |
| 1036 | bool Renderer11::getInstancingSupport() const |
| 1037 | { |
| 1038 | // TODO |
daniel@transgaming.com | 1f811f5 | 2012-11-28 20:57:39 +0000 | [diff] [blame] | 1039 | // UNIMPLEMENTED(); |
daniel@transgaming.com | 1d6aff2 | 2012-11-28 19:30:42 +0000 | [diff] [blame] | 1040 | return false; |
| 1041 | } |
| 1042 | |
| 1043 | bool Renderer11::getShareHandleSupport() const |
| 1044 | { |
| 1045 | // TODO |
daniel@transgaming.com | 1f811f5 | 2012-11-28 20:57:39 +0000 | [diff] [blame] | 1046 | // UNIMPLEMENTED(); |
daniel@transgaming.com | 1d6aff2 | 2012-11-28 19:30:42 +0000 | [diff] [blame] | 1047 | |
| 1048 | // PIX doesn't seem to support using share handles, so disable them. |
| 1049 | return false && !gl::perfActive(); |
| 1050 | } |
| 1051 | |
daniel@transgaming.com | 9549bea | 2012-11-28 20:57:23 +0000 | [diff] [blame] | 1052 | int Renderer11::getMajorShaderModel() const |
daniel@transgaming.com | 1d6aff2 | 2012-11-28 19:30:42 +0000 | [diff] [blame] | 1053 | { |
daniel@transgaming.com | 9549bea | 2012-11-28 20:57:23 +0000 | [diff] [blame] | 1054 | switch (mFeatureLevel) |
| 1055 | { |
| 1056 | case D3D_FEATURE_LEVEL_11_0: return D3D11_SHADER_MAJOR_VERSION; // 5 |
| 1057 | case D3D_FEATURE_LEVEL_10_1: |
| 1058 | case D3D_FEATURE_LEVEL_10_0: return D3D10_SHADER_MAJOR_VERSION; // 4 |
| 1059 | default: UNREACHABLE(); return 0; |
| 1060 | } |
daniel@transgaming.com | 1d6aff2 | 2012-11-28 19:30:42 +0000 | [diff] [blame] | 1061 | } |
| 1062 | |
| 1063 | float Renderer11::getMaxPointSize() const |
| 1064 | { |
| 1065 | // TODO |
daniel@transgaming.com | 1f811f5 | 2012-11-28 20:57:39 +0000 | [diff] [blame] | 1066 | // UNIMPLEMENTED(); |
daniel@transgaming.com | 1d6aff2 | 2012-11-28 19:30:42 +0000 | [diff] [blame] | 1067 | return 1.0f; |
| 1068 | } |
| 1069 | |
| 1070 | int Renderer11::getMaxTextureWidth() const |
| 1071 | { |
daniel@transgaming.com | 25072f6 | 2012-11-28 19:31:32 +0000 | [diff] [blame] | 1072 | switch (mFeatureLevel) |
| 1073 | { |
| 1074 | case D3D_FEATURE_LEVEL_11_0: return D3D11_REQ_TEXTURE2D_U_OR_V_DIMENSION; // 16384 |
| 1075 | case D3D_FEATURE_LEVEL_10_1: |
| 1076 | case D3D_FEATURE_LEVEL_10_0: return D3D10_REQ_TEXTURE2D_U_OR_V_DIMENSION; // 8192 |
| 1077 | default: UNREACHABLE(); return 0; |
| 1078 | } |
daniel@transgaming.com | 1d6aff2 | 2012-11-28 19:30:42 +0000 | [diff] [blame] | 1079 | } |
| 1080 | |
| 1081 | int Renderer11::getMaxTextureHeight() const |
| 1082 | { |
daniel@transgaming.com | 25072f6 | 2012-11-28 19:31:32 +0000 | [diff] [blame] | 1083 | switch (mFeatureLevel) |
| 1084 | { |
| 1085 | case D3D_FEATURE_LEVEL_11_0: return D3D11_REQ_TEXTURE2D_U_OR_V_DIMENSION; // 16384 |
| 1086 | case D3D_FEATURE_LEVEL_10_1: |
| 1087 | case D3D_FEATURE_LEVEL_10_0: return D3D10_REQ_TEXTURE2D_U_OR_V_DIMENSION; // 8192 |
| 1088 | default: UNREACHABLE(); return 0; |
| 1089 | } |
daniel@transgaming.com | 1d6aff2 | 2012-11-28 19:30:42 +0000 | [diff] [blame] | 1090 | } |
| 1091 | |
| 1092 | bool Renderer11::get32BitIndexSupport() const |
| 1093 | { |
daniel@transgaming.com | 25072f6 | 2012-11-28 19:31:32 +0000 | [diff] [blame] | 1094 | switch (mFeatureLevel) |
| 1095 | { |
| 1096 | case D3D_FEATURE_LEVEL_11_0: |
| 1097 | case D3D_FEATURE_LEVEL_10_1: |
| 1098 | case D3D_FEATURE_LEVEL_10_0: return D3D10_REQ_DRAWINDEXED_INDEX_COUNT_2_TO_EXP >= 32; // true |
| 1099 | default: UNREACHABLE(); return false; |
| 1100 | } |
daniel@transgaming.com | 1d6aff2 | 2012-11-28 19:30:42 +0000 | [diff] [blame] | 1101 | } |
| 1102 | |
| 1103 | int Renderer11::getMinSwapInterval() const |
| 1104 | { |
daniel@transgaming.com | 8c7b1a9 | 2012-11-28 19:34:06 +0000 | [diff] [blame] | 1105 | return 0; |
daniel@transgaming.com | 1d6aff2 | 2012-11-28 19:30:42 +0000 | [diff] [blame] | 1106 | } |
| 1107 | |
| 1108 | int Renderer11::getMaxSwapInterval() const |
| 1109 | { |
daniel@transgaming.com | 8c7b1a9 | 2012-11-28 19:34:06 +0000 | [diff] [blame] | 1110 | return 4; |
daniel@transgaming.com | 1d6aff2 | 2012-11-28 19:30:42 +0000 | [diff] [blame] | 1111 | } |
| 1112 | |
| 1113 | int Renderer11::getMaxSupportedSamples() const |
| 1114 | { |
| 1115 | // TODO |
daniel@transgaming.com | 1f811f5 | 2012-11-28 20:57:39 +0000 | [diff] [blame] | 1116 | // UNIMPLEMENTED(); |
daniel@transgaming.com | 1d6aff2 | 2012-11-28 19:30:42 +0000 | [diff] [blame] | 1117 | return 1; |
| 1118 | } |
| 1119 | |
daniel@transgaming.com | 31b13e1 | 2012-11-28 19:34:30 +0000 | [diff] [blame] | 1120 | bool Renderer11::copyToRenderTarget(TextureStorage2D *dest, TextureStorage2D *source) |
daniel@transgaming.com | ad6aee7 | 2012-11-28 19:33:42 +0000 | [diff] [blame] | 1121 | { |
| 1122 | // TODO |
| 1123 | UNIMPLEMENTED(); |
| 1124 | return false; |
| 1125 | } |
| 1126 | |
daniel@transgaming.com | 31b13e1 | 2012-11-28 19:34:30 +0000 | [diff] [blame] | 1127 | bool Renderer11::copyToRenderTarget(TextureStorageCubeMap *dest, TextureStorageCubeMap *source) |
daniel@transgaming.com | ad6aee7 | 2012-11-28 19:33:42 +0000 | [diff] [blame] | 1128 | { |
| 1129 | // TODO |
| 1130 | UNIMPLEMENTED(); |
| 1131 | return false; |
| 1132 | } |
| 1133 | |
daniel@transgaming.com | 3838088 | 2012-11-28 19:36:39 +0000 | [diff] [blame] | 1134 | bool Renderer11::copyImage(gl::Framebuffer *framebuffer, const RECT &sourceRect, GLenum destFormat, |
| 1135 | GLint xoffset, GLint yoffset, TextureStorage2D *storage, GLint level) |
| 1136 | { |
| 1137 | // TODO |
| 1138 | UNIMPLEMENTED(); |
| 1139 | return false; |
| 1140 | } |
| 1141 | |
| 1142 | bool Renderer11::copyImage(gl::Framebuffer *framebuffer, const RECT &sourceRect, GLenum destFormat, |
| 1143 | GLint xoffset, GLint yoffset, TextureStorageCubeMap *storage, GLenum target, GLint level) |
| 1144 | { |
| 1145 | // TODO |
| 1146 | UNIMPLEMENTED(); |
| 1147 | return false; |
| 1148 | } |
| 1149 | |
daniel@transgaming.com | f242365 | 2012-11-28 20:53:50 +0000 | [diff] [blame] | 1150 | RenderTarget *Renderer11::createRenderTarget(SwapChain *swapChain, bool depth) |
| 1151 | { |
daniel@transgaming.com | b6b27bc | 2012-11-28 20:54:30 +0000 | [diff] [blame] | 1152 | SwapChain11 *swapChain11 = SwapChain11::makeSwapChain11(swapChain); |
| 1153 | RenderTarget11 *renderTarget = NULL; |
| 1154 | if (depth) |
| 1155 | { |
| 1156 | renderTarget = new RenderTarget11(this, swapChain11->getDepthStencil(), swapChain11->getWidth(), swapChain11->getHeight()); |
| 1157 | } |
| 1158 | else |
| 1159 | { |
| 1160 | renderTarget = new RenderTarget11(this, swapChain11->getRenderTarget(), swapChain11->getWidth(), swapChain11->getHeight()); |
| 1161 | } |
| 1162 | return renderTarget; |
daniel@transgaming.com | f242365 | 2012-11-28 20:53:50 +0000 | [diff] [blame] | 1163 | } |
| 1164 | |
| 1165 | RenderTarget *Renderer11::createRenderTarget(int width, int height, GLenum format, GLsizei samples, bool depth) |
| 1166 | { |
| 1167 | // TODO |
| 1168 | UNIMPLEMENTED(); |
| 1169 | return NULL; |
| 1170 | } |
| 1171 | |
daniel@transgaming.com | 7b18d0c | 2012-11-28 21:04:10 +0000 | [diff] [blame] | 1172 | ShaderExecutable *Renderer11::loadExecutable(const void *function, size_t length, GLenum type, void *data) |
daniel@transgaming.com | 5531890 | 2012-11-28 20:58:58 +0000 | [diff] [blame] | 1173 | { |
daniel@transgaming.com | a2f9fbe | 2012-11-28 21:03:40 +0000 | [diff] [blame] | 1174 | ShaderExecutable11 *executable = NULL; |
| 1175 | |
| 1176 | switch (type) |
| 1177 | { |
| 1178 | case GL_VERTEX_SHADER: |
| 1179 | { |
| 1180 | ID3D11VertexShader *vshader = NULL; |
| 1181 | HRESULT result = mDevice->CreateVertexShader(function, length, NULL, &vshader); |
| 1182 | ASSERT(SUCCEEDED(result)); |
| 1183 | |
| 1184 | if (vshader) |
| 1185 | { |
daniel@transgaming.com | 7b18d0c | 2012-11-28 21:04:10 +0000 | [diff] [blame] | 1186 | executable = new ShaderExecutable11(function, length, vshader); |
daniel@transgaming.com | a2f9fbe | 2012-11-28 21:03:40 +0000 | [diff] [blame] | 1187 | } |
| 1188 | } |
| 1189 | break; |
| 1190 | case GL_FRAGMENT_SHADER: |
| 1191 | { |
| 1192 | ID3D11PixelShader *pshader = NULL; |
| 1193 | HRESULT result = mDevice->CreatePixelShader(function, length, NULL, &pshader); |
| 1194 | ASSERT(SUCCEEDED(result)); |
| 1195 | |
| 1196 | if (pshader) |
| 1197 | { |
daniel@transgaming.com | 7b18d0c | 2012-11-28 21:04:10 +0000 | [diff] [blame] | 1198 | executable = new ShaderExecutable11(function, length, pshader); |
daniel@transgaming.com | a2f9fbe | 2012-11-28 21:03:40 +0000 | [diff] [blame] | 1199 | } |
| 1200 | } |
| 1201 | break; |
| 1202 | default: |
| 1203 | UNREACHABLE(); |
| 1204 | break; |
| 1205 | } |
| 1206 | |
| 1207 | return executable; |
daniel@transgaming.com | 5531890 | 2012-11-28 20:58:58 +0000 | [diff] [blame] | 1208 | } |
| 1209 | |
daniel@transgaming.com | a9c7142 | 2012-11-28 20:58:45 +0000 | [diff] [blame] | 1210 | ShaderExecutable *Renderer11::compileToExecutable(gl::InfoLog &infoLog, const char *shaderHLSL, GLenum type) |
| 1211 | { |
daniel@transgaming.com | 071ee6a | 2012-11-28 21:03:21 +0000 | [diff] [blame] | 1212 | const char *profile = NULL; |
| 1213 | |
| 1214 | switch (type) |
| 1215 | { |
| 1216 | case GL_VERTEX_SHADER: |
| 1217 | profile = "vs_4_0"; |
| 1218 | break; |
| 1219 | case GL_FRAGMENT_SHADER: |
| 1220 | profile = "ps_4_0"; |
| 1221 | break; |
| 1222 | default: |
| 1223 | UNREACHABLE(); |
| 1224 | return NULL; |
| 1225 | } |
| 1226 | |
daniel@transgaming.com | 25e16af | 2012-11-28 21:05:57 +0000 | [diff] [blame] | 1227 | ID3DBlob *binary = compileToBinary(infoLog, shaderHLSL, profile, false); |
daniel@transgaming.com | 071ee6a | 2012-11-28 21:03:21 +0000 | [diff] [blame] | 1228 | if (!binary) |
| 1229 | return NULL; |
| 1230 | |
| 1231 | ShaderExecutable *executable = loadExecutable((DWORD *)binary->GetBufferPointer(), binary->GetBufferSize(), type, NULL); |
| 1232 | binary->Release(); |
| 1233 | |
| 1234 | return executable; |
| 1235 | } |
| 1236 | |
daniel@transgaming.com | 6c87217 | 2012-11-28 19:39:33 +0000 | [diff] [blame] | 1237 | bool Renderer11::blitRect(gl::Framebuffer *readTarget, gl::Rectangle *readRect, gl::Framebuffer *drawTarget, gl::Rectangle *drawRect, |
| 1238 | bool blitRenderTarget, bool blitDepthStencil) |
| 1239 | { |
| 1240 | // TODO |
| 1241 | UNIMPLEMENTED(); |
| 1242 | return false; |
| 1243 | } |
| 1244 | |
| 1245 | void Renderer11::readPixels(gl::Framebuffer *framebuffer, GLint x, GLint y, GLsizei width, GLsizei height, GLenum format, GLenum type, |
| 1246 | GLsizei outputPitch, bool packReverseRowOrder, GLint packAlignment, void* pixels) |
| 1247 | { |
| 1248 | // TODO |
| 1249 | UNIMPLEMENTED(); |
| 1250 | return; |
| 1251 | } |
| 1252 | |
daniel@transgaming.com | 244e183 | 2012-12-20 20:52:35 +0000 | [diff] [blame] | 1253 | Image *Renderer11::createImage() |
| 1254 | { |
| 1255 | // TODO |
| 1256 | UNIMPLEMENTED(); |
| 1257 | return NULL; |
| 1258 | } |
| 1259 | |
daniel@transgaming.com | f721fdb | 2012-12-20 20:53:11 +0000 | [diff] [blame^] | 1260 | void Renderer11::generateMipmap(Image *dest, Image *src) |
| 1261 | { |
| 1262 | // TODO |
| 1263 | UNIMPLEMENTED(); |
| 1264 | return; |
| 1265 | } |
| 1266 | |
daniel@transgaming.com | 1d6aff2 | 2012-11-28 19:30:42 +0000 | [diff] [blame] | 1267 | } |