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