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