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 | { |
| 333 | // TODO |
| 334 | UNIMPLEMENTED(); |
| 335 | } |
| 336 | |
daniel@transgaming.com | 237bc7e | 2012-11-28 21:01:06 +0000 | [diff] [blame] | 337 | void Renderer11::setRasterizerState(const gl::RasterizerState &rasterState) |
daniel@transgaming.com | 493d4f8 | 2012-11-28 19:35:45 +0000 | [diff] [blame] | 338 | { |
daniel@transgaming.com | 237bc7e | 2012-11-28 21:01:06 +0000 | [diff] [blame] | 339 | if (mForceSetRasterState || memcmp(&rasterState, &mCurRasterState, sizeof(gl::RasterizerState)) != 0) |
daniel@transgaming.com | dcf1e67 | 2012-11-28 19:38:19 +0000 | [diff] [blame] | 340 | { |
daniel@transgaming.com | d55e8c1 | 2012-11-28 21:07:02 +0000 | [diff] [blame] | 341 | ID3D11RasterizerState *dxRasterState = mStateCache.getRasterizerState(rasterState, mScissorEnabled, |
| 342 | mCurDepthSize); |
daniel@transgaming.com | dcf1e67 | 2012-11-28 19:38:19 +0000 | [diff] [blame] | 343 | if (!dxRasterState) |
| 344 | { |
daniel@transgaming.com | d55e8c1 | 2012-11-28 21:07:02 +0000 | [diff] [blame] | 345 | ERR("NULL blend state returned by RenderStateCache::getRasterizerState, setting the default" |
daniel@transgaming.com | dcf1e67 | 2012-11-28 19:38:19 +0000 | [diff] [blame] | 346 | "rasterizer state."); |
| 347 | } |
| 348 | |
| 349 | mDeviceContext->RSSetState(dxRasterState); |
| 350 | |
| 351 | if (dxRasterState) |
| 352 | { |
| 353 | dxRasterState->Release(); |
| 354 | } |
| 355 | mCurRasterState = rasterState; |
daniel@transgaming.com | dcf1e67 | 2012-11-28 19:38:19 +0000 | [diff] [blame] | 356 | } |
| 357 | |
| 358 | mForceSetRasterState = false; |
daniel@transgaming.com | 493d4f8 | 2012-11-28 19:35:45 +0000 | [diff] [blame] | 359 | } |
| 360 | |
| 361 | void Renderer11::setBlendState(const gl::BlendState &blendState, const gl::Color &blendColor, |
| 362 | unsigned int sampleMask) |
| 363 | { |
daniel@transgaming.com | f8ba109 | 2012-11-28 19:37:53 +0000 | [diff] [blame] | 364 | if (mForceSetBlendState || |
| 365 | memcmp(&blendState, &mCurBlendState, sizeof(gl::BlendState)) != 0 || |
| 366 | memcmp(&blendColor, &mCurBlendColor, sizeof(gl::Color)) != 0 || |
| 367 | sampleMask != mCurSampleMask) |
| 368 | { |
| 369 | ID3D11BlendState *dxBlendState = mStateCache.getBlendState(blendState); |
| 370 | if (!dxBlendState) |
| 371 | { |
| 372 | ERR("NULL blend state returned by RenderStateCache::getBlendState, setting the default " |
| 373 | "blend state."); |
| 374 | } |
| 375 | |
| 376 | const float blendColors[] = { blendColor.red, blendColor.green, blendColor.blue, blendColor.alpha }; |
| 377 | mDeviceContext->OMSetBlendState(dxBlendState, blendColors, sampleMask); |
| 378 | |
| 379 | if (dxBlendState) |
| 380 | { |
| 381 | dxBlendState->Release(); |
| 382 | } |
| 383 | mCurBlendState = blendState; |
| 384 | mCurBlendColor = blendColor; |
| 385 | mCurSampleMask = sampleMask; |
| 386 | } |
| 387 | |
| 388 | mForceSetBlendState = false; |
daniel@transgaming.com | 493d4f8 | 2012-11-28 19:35:45 +0000 | [diff] [blame] | 389 | } |
| 390 | |
daniel@transgaming.com | 08c331d | 2012-11-28 19:38:39 +0000 | [diff] [blame] | 391 | void Renderer11::setDepthStencilState(const gl::DepthStencilState &depthStencilState, int stencilRef, |
daniel@transgaming.com | 3a0ef48 | 2012-11-28 21:01:20 +0000 | [diff] [blame] | 392 | int stencilBackRef, bool frontFaceCCW) |
daniel@transgaming.com | 493d4f8 | 2012-11-28 19:35:45 +0000 | [diff] [blame] | 393 | { |
daniel@transgaming.com | 5503fd0 | 2012-11-28 19:38:57 +0000 | [diff] [blame] | 394 | if (mForceSetDepthStencilState || |
| 395 | memcmp(&depthStencilState, &mCurDepthStencilState, sizeof(gl::DepthStencilState)) != 0 || |
| 396 | stencilRef != mCurStencilRef || stencilBackRef != mCurStencilBackRef) |
| 397 | { |
| 398 | if (depthStencilState.stencilWritemask != depthStencilState.stencilBackWritemask || |
| 399 | stencilRef != stencilBackRef || |
| 400 | depthStencilState.stencilMask != depthStencilState.stencilBackMask) |
| 401 | { |
| 402 | ERR("Separate front/back stencil writemasks, reference values, or stencil mask values are " |
| 403 | "invalid under WebGL."); |
| 404 | return error(GL_INVALID_OPERATION); |
| 405 | } |
| 406 | |
| 407 | ID3D11DepthStencilState *dxDepthStencilState = mStateCache.getDepthStencilState(depthStencilState); |
| 408 | if (!dxDepthStencilState) |
| 409 | { |
| 410 | ERR("NULL depth stencil state returned by RenderStateCache::getDepthStencilState, " |
| 411 | "setting the default depth stencil state."); |
| 412 | } |
| 413 | |
| 414 | mDeviceContext->OMSetDepthStencilState(dxDepthStencilState, static_cast<UINT>(stencilRef)); |
| 415 | |
| 416 | if (dxDepthStencilState) |
| 417 | { |
| 418 | dxDepthStencilState->Release(); |
| 419 | } |
| 420 | mCurDepthStencilState = depthStencilState; |
| 421 | mCurStencilRef = stencilRef; |
| 422 | mCurStencilBackRef = stencilBackRef; |
| 423 | } |
| 424 | |
| 425 | mForceSetDepthStencilState = false; |
daniel@transgaming.com | 493d4f8 | 2012-11-28 19:35:45 +0000 | [diff] [blame] | 426 | } |
| 427 | |
daniel@transgaming.com | d55e8c1 | 2012-11-28 21:07:02 +0000 | [diff] [blame] | 428 | void Renderer11::setScissorRectangle(const gl::Rectangle &scissor, bool enabled) |
daniel@transgaming.com | 493d4f8 | 2012-11-28 19:35:45 +0000 | [diff] [blame] | 429 | { |
daniel@transgaming.com | d55e8c1 | 2012-11-28 21:07:02 +0000 | [diff] [blame] | 430 | if (mForceSetScissor || memcmp(&scissor, &mCurScissor, sizeof(gl::Rectangle)) != 0 || |
| 431 | enabled != mScissorEnabled) |
daniel@transgaming.com | dcf1e67 | 2012-11-28 19:38:19 +0000 | [diff] [blame] | 432 | { |
daniel@transgaming.com | d55e8c1 | 2012-11-28 21:07:02 +0000 | [diff] [blame] | 433 | if (enabled) |
| 434 | { |
| 435 | D3D11_RECT rect; |
| 436 | rect.left = gl::clamp(scissor.x, 0, static_cast<int>(mRenderTargetDesc.width)); |
| 437 | rect.top = gl::clamp(scissor.y, 0, static_cast<int>(mRenderTargetDesc.height)); |
| 438 | rect.right = gl::clamp(scissor.x + scissor.width, 0, static_cast<int>(mRenderTargetDesc.width)); |
| 439 | 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] | 440 | |
daniel@transgaming.com | d55e8c1 | 2012-11-28 21:07:02 +0000 | [diff] [blame] | 441 | mDeviceContext->RSSetScissorRects(1, &rect); |
| 442 | } |
| 443 | |
| 444 | if (enabled != mScissorEnabled) |
| 445 | { |
| 446 | mForceSetRasterState = true; |
| 447 | } |
daniel@transgaming.com | dcf1e67 | 2012-11-28 19:38:19 +0000 | [diff] [blame] | 448 | |
| 449 | mCurScissor = scissor; |
daniel@transgaming.com | d55e8c1 | 2012-11-28 21:07:02 +0000 | [diff] [blame] | 450 | mScissorEnabled = enabled; |
daniel@transgaming.com | dcf1e67 | 2012-11-28 19:38:19 +0000 | [diff] [blame] | 451 | } |
| 452 | |
| 453 | mForceSetScissor = false; |
daniel@transgaming.com | 493d4f8 | 2012-11-28 19:35:45 +0000 | [diff] [blame] | 454 | } |
| 455 | |
daniel@transgaming.com | 1298518 | 2012-12-20 20:56:31 +0000 | [diff] [blame] | 456 | bool Renderer11::setViewport(const gl::Rectangle &viewport, float zNear, float zFar, GLenum drawMode, GLenum frontFace, |
| 457 | bool ignoreViewport, gl::ProgramBinary *currentProgram, bool forceSetUniforms) |
daniel@transgaming.com | 83e80ee | 2012-11-28 19:40:53 +0000 | [diff] [blame] | 458 | { |
daniel@transgaming.com | 4c4ce23 | 2012-11-28 21:01:40 +0000 | [diff] [blame] | 459 | gl::Rectangle actualViewport = viewport; |
| 460 | float actualZNear = gl::clamp01(zNear); |
| 461 | float actualZFar = gl::clamp01(zFar); |
| 462 | if (ignoreViewport) |
| 463 | { |
| 464 | actualViewport.x = 0; |
| 465 | actualViewport.y = 0; |
| 466 | actualViewport.width = mRenderTargetDesc.width; |
| 467 | actualViewport.height = mRenderTargetDesc.height; |
| 468 | actualZNear = 0.0f; |
| 469 | actualZFar = 1.0f; |
| 470 | } |
daniel@transgaming.com | 5367004 | 2012-11-28 20:55:51 +0000 | [diff] [blame] | 471 | |
| 472 | D3D11_VIEWPORT dxViewport; |
daniel@transgaming.com | 4c4ce23 | 2012-11-28 21:01:40 +0000 | [diff] [blame] | 473 | dxViewport.TopLeftX = gl::clamp(actualViewport.x, 0, static_cast<int>(mRenderTargetDesc.width)); |
| 474 | dxViewport.TopLeftY = gl::clamp(actualViewport.y, 0, static_cast<int>(mRenderTargetDesc.height)); |
| 475 | dxViewport.Width = gl::clamp(actualViewport.width, 0, static_cast<int>(mRenderTargetDesc.width) - static_cast<int>(dxViewport.TopLeftX)); |
| 476 | dxViewport.Height = gl::clamp(actualViewport.height, 0, static_cast<int>(mRenderTargetDesc.height) - static_cast<int>(dxViewport.TopLeftY)); |
| 477 | dxViewport.MinDepth = actualZNear; |
| 478 | dxViewport.MaxDepth = actualZFar; |
daniel@transgaming.com | 5367004 | 2012-11-28 20:55:51 +0000 | [diff] [blame] | 479 | |
| 480 | if (dxViewport.Width <= 0 || dxViewport.Height <= 0) |
| 481 | { |
| 482 | return false; // Nothing to render |
| 483 | } |
| 484 | |
daniel@transgaming.com | 4c4ce23 | 2012-11-28 21:01:40 +0000 | [diff] [blame] | 485 | bool viewportChanged = mForceSetViewport || memcmp(&actualViewport, &mCurViewport, sizeof(gl::Rectangle)) != 0 || |
| 486 | actualZNear != mCurNear || actualZFar != mCurFar; |
| 487 | |
daniel@transgaming.com | 5367004 | 2012-11-28 20:55:51 +0000 | [diff] [blame] | 488 | if (viewportChanged) |
| 489 | { |
| 490 | mDeviceContext->RSSetViewports(1, &dxViewport); |
| 491 | |
daniel@transgaming.com | 4c4ce23 | 2012-11-28 21:01:40 +0000 | [diff] [blame] | 492 | mCurViewport = actualViewport; |
| 493 | mCurNear = actualZNear; |
| 494 | mCurFar = actualZFar; |
daniel@transgaming.com | 5367004 | 2012-11-28 20:55:51 +0000 | [diff] [blame] | 495 | } |
| 496 | |
| 497 | if (currentProgram && (viewportChanged || forceSetUniforms)) |
| 498 | { |
daniel@transgaming.com | 88853c5 | 2012-12-20 20:56:40 +0000 | [diff] [blame] | 499 | currentProgram->applyDxHalfPixelSize(0.0f, 0.0f); |
daniel@transgaming.com | 5367004 | 2012-11-28 20:55:51 +0000 | [diff] [blame] | 500 | |
| 501 | // These values are used for computing gl_FragCoord in Program::linkVaryings(). |
daniel@transgaming.com | 88853c5 | 2012-12-20 20:56:40 +0000 | [diff] [blame] | 502 | currentProgram->applyDxCoord(actualViewport.width * 0.5f, |
| 503 | actualViewport.height * 0.5f, |
| 504 | actualViewport.x + (actualViewport.width * 0.5f), |
| 505 | actualViewport.y + (actualViewport.height * 0.5f)); |
daniel@transgaming.com | 5367004 | 2012-11-28 20:55:51 +0000 | [diff] [blame] | 506 | |
daniel@transgaming.com | 1298518 | 2012-12-20 20:56:31 +0000 | [diff] [blame] | 507 | 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] | 508 | currentProgram->applyDxDepthFront((actualZFar - actualZNear) * 0.5f, (actualZNear + actualZFar) * 0.5f, ccw); |
daniel@transgaming.com | 5367004 | 2012-11-28 20:55:51 +0000 | [diff] [blame] | 509 | |
daniel@transgaming.com | 88853c5 | 2012-12-20 20:56:40 +0000 | [diff] [blame] | 510 | currentProgram->applyDxDepthRange(actualZNear, actualZFar, actualZFar - actualZNear); |
daniel@transgaming.com | 5367004 | 2012-11-28 20:55:51 +0000 | [diff] [blame] | 511 | } |
| 512 | |
| 513 | mForceSetViewport = false; |
daniel@transgaming.com | 83e80ee | 2012-11-28 19:40:53 +0000 | [diff] [blame] | 514 | return true; |
| 515 | } |
| 516 | |
daniel@transgaming.com | 91207b7 | 2012-11-28 20:56:43 +0000 | [diff] [blame] | 517 | bool Renderer11::applyPrimitiveType(GLenum mode, GLsizei count) |
| 518 | { |
daniel@transgaming.com | c52be63 | 2012-11-28 21:04:28 +0000 | [diff] [blame] | 519 | D3D11_PRIMITIVE_TOPOLOGY primitiveTopology = D3D_PRIMITIVE_TOPOLOGY_UNDEFINED; |
daniel@transgaming.com | 91207b7 | 2012-11-28 20:56:43 +0000 | [diff] [blame] | 520 | |
daniel@transgaming.com | 0b03b06 | 2012-11-28 21:03:49 +0000 | [diff] [blame] | 521 | switch (mode) |
| 522 | { |
daniel@transgaming.com | c52be63 | 2012-11-28 21:04:28 +0000 | [diff] [blame] | 523 | case GL_POINTS: primitiveTopology = D3D11_PRIMITIVE_TOPOLOGY_POINTLIST; break; |
| 524 | case GL_LINES: primitiveTopology = D3D_PRIMITIVE_TOPOLOGY_LINELIST; break; |
daniel@transgaming.com | 0b03b06 | 2012-11-28 21:03:49 +0000 | [diff] [blame] | 525 | case GL_LINE_LOOP: UNIMPLEMENTED(); /* TODO */ break; |
daniel@transgaming.com | c52be63 | 2012-11-28 21:04:28 +0000 | [diff] [blame] | 526 | case GL_LINE_STRIP: primitiveTopology = D3D_PRIMITIVE_TOPOLOGY_LINESTRIP; break; |
| 527 | case GL_TRIANGLES: primitiveTopology = D3D_PRIMITIVE_TOPOLOGY_TRIANGLELIST; break; |
| 528 | case GL_TRIANGLE_STRIP: primitiveTopology = D3D_PRIMITIVE_TOPOLOGY_TRIANGLESTRIP; break; |
daniel@transgaming.com | 0b03b06 | 2012-11-28 21:03:49 +0000 | [diff] [blame] | 529 | case GL_TRIANGLE_FAN: UNIMPLEMENTED(); /* TODO */ break; |
| 530 | default: |
| 531 | return error(GL_INVALID_ENUM, false); |
| 532 | } |
| 533 | |
daniel@transgaming.com | c52be63 | 2012-11-28 21:04:28 +0000 | [diff] [blame] | 534 | mDeviceContext->IASetPrimitiveTopology(primitiveTopology); |
daniel@transgaming.com | 0b03b06 | 2012-11-28 21:03:49 +0000 | [diff] [blame] | 535 | |
| 536 | return count > 0; |
daniel@transgaming.com | 91207b7 | 2012-11-28 20:56:43 +0000 | [diff] [blame] | 537 | } |
| 538 | |
| 539 | bool Renderer11::applyRenderTarget(gl::Framebuffer *framebuffer) |
daniel@transgaming.com | 493d4f8 | 2012-11-28 19:35:45 +0000 | [diff] [blame] | 540 | { |
daniel@transgaming.com | 80fc332 | 2012-11-28 21:02:13 +0000 | [diff] [blame] | 541 | // Get the color render buffer and serial |
| 542 | gl::Renderbuffer *renderbufferObject = NULL; |
| 543 | unsigned int renderTargetSerial = 0; |
| 544 | if (framebuffer->getColorbufferType() != GL_NONE) |
| 545 | { |
| 546 | renderbufferObject = framebuffer->getColorbuffer(); |
daniel@transgaming.com | dcf1e67 | 2012-11-28 19:38:19 +0000 | [diff] [blame] | 547 | |
daniel@transgaming.com | 80fc332 | 2012-11-28 21:02:13 +0000 | [diff] [blame] | 548 | if (!renderbufferObject) |
| 549 | { |
| 550 | ERR("render target pointer unexpectedly null."); |
daniel@transgaming.com | e9c71b4 | 2012-11-28 21:02:23 +0000 | [diff] [blame] | 551 | return false; |
daniel@transgaming.com | 80fc332 | 2012-11-28 21:02:13 +0000 | [diff] [blame] | 552 | } |
| 553 | |
| 554 | renderTargetSerial = renderbufferObject->getSerial(); |
| 555 | } |
| 556 | |
| 557 | // Get the depth stencil render buffer and serials |
| 558 | gl::Renderbuffer *depthStencil = NULL; |
| 559 | unsigned int depthbufferSerial = 0; |
| 560 | unsigned int stencilbufferSerial = 0; |
| 561 | if (framebuffer->getDepthbufferType() != GL_NONE) |
| 562 | { |
| 563 | depthStencil = framebuffer->getDepthbuffer(); |
| 564 | if (!depthStencil) |
| 565 | { |
| 566 | ERR("Depth stencil pointer unexpectedly null."); |
| 567 | return false; |
| 568 | } |
| 569 | |
| 570 | depthbufferSerial = depthStencil->getSerial(); |
| 571 | } |
| 572 | else if (framebuffer->getStencilbufferType() != GL_NONE) |
| 573 | { |
| 574 | depthStencil = framebuffer->getStencilbuffer(); |
| 575 | if (!depthStencil) |
| 576 | { |
| 577 | ERR("Depth stencil pointer unexpectedly null."); |
| 578 | return false; |
| 579 | } |
| 580 | |
| 581 | stencilbufferSerial = depthStencil->getSerial(); |
| 582 | } |
| 583 | |
| 584 | // Extract the render target dimensions and view |
| 585 | unsigned int renderTargetWidth = 0; |
| 586 | unsigned int renderTargetHeight = 0; |
| 587 | GLenum renderTargetFormat = 0; |
| 588 | ID3D11RenderTargetView* framebufferRTV = NULL; |
| 589 | if (renderbufferObject) |
| 590 | { |
| 591 | RenderTarget11 *renderTarget = RenderTarget11::makeRenderTarget11(renderbufferObject->getRenderTarget()); |
| 592 | if (!renderTarget) |
| 593 | { |
| 594 | ERR("render target pointer unexpectedly null."); |
| 595 | return false; |
| 596 | } |
| 597 | |
| 598 | framebufferRTV = renderTarget->getRenderTargetView(); |
| 599 | if (!framebufferRTV) |
| 600 | { |
| 601 | ERR("render target view pointer unexpectedly null."); |
| 602 | return false; |
| 603 | } |
| 604 | |
| 605 | renderTargetWidth = renderbufferObject->getWidth(); |
| 606 | renderTargetHeight = renderbufferObject->getHeight(); |
| 607 | renderTargetFormat = renderbufferObject->getActualFormat(); |
| 608 | } |
| 609 | |
| 610 | // Extract the depth stencil sizes and view |
| 611 | unsigned int depthSize = 0; |
| 612 | unsigned int stencilSize = 0; |
| 613 | ID3D11DepthStencilView* framebufferDSV = NULL; |
| 614 | if (depthStencil) |
| 615 | { |
| 616 | RenderTarget11 *depthStencilRenderTarget = RenderTarget11::makeRenderTarget11(depthStencil->getDepthStencil()); |
| 617 | if (!depthStencilRenderTarget) |
| 618 | { |
| 619 | ERR("render target pointer unexpectedly null."); |
| 620 | if (framebufferRTV) |
| 621 | { |
| 622 | framebufferRTV->Release(); |
| 623 | } |
| 624 | return false; |
| 625 | } |
| 626 | |
| 627 | framebufferDSV = depthStencilRenderTarget->getDepthStencilView(); |
| 628 | if (!framebufferDSV) |
| 629 | { |
| 630 | ERR("depth stencil view pointer unexpectedly null."); |
| 631 | if (framebufferRTV) |
| 632 | { |
| 633 | framebufferRTV->Release(); |
| 634 | } |
| 635 | return false; |
| 636 | } |
| 637 | |
| 638 | // If there is no render buffer, the width, height and format values come from |
| 639 | // the depth stencil |
| 640 | if (!renderbufferObject) |
| 641 | { |
| 642 | renderTargetWidth = depthStencil->getWidth(); |
| 643 | renderTargetHeight = depthStencil->getHeight(); |
| 644 | renderTargetFormat = depthStencil->getActualFormat(); |
| 645 | } |
| 646 | |
| 647 | depthSize = depthStencil->getDepthSize(); |
| 648 | stencilSize = depthStencil->getStencilSize(); |
| 649 | } |
| 650 | |
| 651 | // Apply the render target and depth stencil |
| 652 | if (!mRenderTargetDescInitialized || !mDepthStencilInitialized || |
| 653 | renderTargetSerial != mAppliedRenderTargetSerial || |
| 654 | depthbufferSerial != mAppliedDepthbufferSerial || |
| 655 | stencilbufferSerial != mAppliedStencilbufferSerial) |
| 656 | { |
| 657 | mDeviceContext->OMSetRenderTargets(1, &framebufferRTV, framebufferDSV); |
| 658 | |
| 659 | mRenderTargetDesc.width = renderTargetWidth; |
| 660 | mRenderTargetDesc.height = renderTargetHeight; |
| 661 | mRenderTargetDesc.format = renderTargetFormat; |
| 662 | mForceSetViewport = true; // TODO: It may not be required to clamp the viewport in D3D11 |
| 663 | mForceSetScissor = true; // TODO: It may not be required to clamp the scissor in D3D11 |
| 664 | |
| 665 | if (!mDepthStencilInitialized || depthSize != mCurDepthSize) |
| 666 | { |
| 667 | mCurDepthSize = depthSize; |
| 668 | mForceSetRasterState = true; |
| 669 | } |
| 670 | |
| 671 | mCurStencilSize = stencilSize; |
| 672 | |
| 673 | mAppliedRenderTargetSerial = renderTargetSerial; |
| 674 | mAppliedDepthbufferSerial = depthbufferSerial; |
| 675 | mAppliedStencilbufferSerial = stencilbufferSerial; |
| 676 | mRenderTargetDescInitialized = true; |
| 677 | mDepthStencilInitialized = true; |
| 678 | } |
| 679 | |
| 680 | if (framebufferRTV) |
| 681 | { |
| 682 | framebufferRTV->Release(); |
| 683 | } |
| 684 | if (framebufferDSV) |
| 685 | { |
| 686 | framebufferDSV->Release(); |
| 687 | } |
daniel@transgaming.com | ae39ee2 | 2012-11-28 19:42:02 +0000 | [diff] [blame] | 688 | |
| 689 | return true; |
daniel@transgaming.com | 493d4f8 | 2012-11-28 19:35:45 +0000 | [diff] [blame] | 690 | } |
daniel@transgaming.com | 1d6aff2 | 2012-11-28 19:30:42 +0000 | [diff] [blame] | 691 | |
daniel@transgaming.com | 91207b7 | 2012-11-28 20:56:43 +0000 | [diff] [blame] | 692 | 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] | 693 | { |
daniel@transgaming.com | c5431eb | 2012-12-20 21:10:15 +0000 | [diff] [blame] | 694 | TranslatedAttribute attributes[gl::MAX_VERTEX_ATTRIBS]; |
| 695 | GLenum err = mVertexDataManager->prepareVertexData(vertexAttributes, programBinary, first, count, attributes, instances); |
| 696 | if (err != GL_NO_ERROR) |
daniel@transgaming.com | da495a1 | 2012-11-28 21:03:56 +0000 | [diff] [blame] | 697 | { |
daniel@transgaming.com | c5431eb | 2012-12-20 21:10:15 +0000 | [diff] [blame] | 698 | return err; |
| 699 | } |
daniel@transgaming.com | da495a1 | 2012-11-28 21:03:56 +0000 | [diff] [blame] | 700 | |
daniel@transgaming.com | c5431eb | 2012-12-20 21:10:15 +0000 | [diff] [blame] | 701 | return mInputLayoutCache.applyVertexBuffers(attributes, programBinary); |
daniel@transgaming.com | def9f0f | 2012-11-28 20:53:20 +0000 | [diff] [blame] | 702 | } |
| 703 | |
daniel@transgaming.com | 3124048 | 2012-11-28 21:06:41 +0000 | [diff] [blame] | 704 | 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] | 705 | { |
daniel@transgaming.com | c5431eb | 2012-12-20 21:10:15 +0000 | [diff] [blame] | 706 | GLenum err = mIndexDataManager->prepareIndexData(type, count, elementArrayBuffer, indices, indexInfo); |
daniel@transgaming.com | 91207b7 | 2012-11-28 20:56:43 +0000 | [diff] [blame] | 707 | |
daniel@transgaming.com | c5431eb | 2012-12-20 21:10:15 +0000 | [diff] [blame] | 708 | if (err == GL_NO_ERROR) |
| 709 | { |
| 710 | if (indexInfo->serial != mAppliedIBSerial) |
| 711 | { |
| 712 | IndexBuffer11* indexBuffer = IndexBuffer11::makeIndexBuffer11(indexInfo->indexBuffer); |
| 713 | |
daniel@transgaming.com | 22ada2c | 2013-01-11 04:07:12 +0000 | [diff] [blame] | 714 | mDeviceContext->IASetIndexBuffer(indexBuffer->getBuffer(), indexBuffer->getIndexFormat(), indexInfo->startOffset); |
daniel@transgaming.com | c5431eb | 2012-12-20 21:10:15 +0000 | [diff] [blame] | 715 | mAppliedIBSerial = indexInfo->serial; |
| 716 | } |
| 717 | } |
| 718 | |
| 719 | return err; |
daniel@transgaming.com | 91207b7 | 2012-11-28 20:56:43 +0000 | [diff] [blame] | 720 | } |
| 721 | |
| 722 | void Renderer11::drawArrays(GLenum mode, GLsizei count, GLsizei instances) |
| 723 | { |
daniel@transgaming.com | d4cf251 | 2012-11-28 21:05:41 +0000 | [diff] [blame] | 724 | mDeviceContext->Draw(count, 0); |
daniel@transgaming.com | 91207b7 | 2012-11-28 20:56:43 +0000 | [diff] [blame] | 725 | } |
| 726 | |
daniel@transgaming.com | 3124048 | 2012-11-28 21:06:41 +0000 | [diff] [blame] | 727 | 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] | 728 | { |
daniel@transgaming.com | c511430 | 2012-12-20 21:11:36 +0000 | [diff] [blame] | 729 | if (mode == GL_LINE_LOOP) |
| 730 | { |
| 731 | drawLineLoop(count, type, indices, indexInfo.minIndex, elementArrayBuffer); |
| 732 | } |
| 733 | else |
| 734 | { |
daniel@transgaming.com | 9f7ede6 | 2013-01-11 04:07:06 +0000 | [diff] [blame] | 735 | mDeviceContext->DrawIndexed(count, 0, -static_cast<int>(indexInfo.minIndex)); |
daniel@transgaming.com | c511430 | 2012-12-20 21:11:36 +0000 | [diff] [blame] | 736 | } |
| 737 | } |
| 738 | |
| 739 | void Renderer11::drawLineLoop(GLsizei count, GLenum type, const GLvoid *indices, int minIndex, gl::Buffer *elementArrayBuffer) |
| 740 | { |
| 741 | // Get the raw indices for an indexed draw |
| 742 | if (type != GL_NONE && elementArrayBuffer) |
| 743 | { |
| 744 | gl::Buffer *indexBuffer = elementArrayBuffer; |
| 745 | intptr_t offset = reinterpret_cast<intptr_t>(indices); |
| 746 | indices = static_cast<const GLubyte*>(indexBuffer->data()) + offset; |
| 747 | } |
| 748 | |
| 749 | if (!mLineLoopIB) |
| 750 | { |
| 751 | mLineLoopIB = new StreamingIndexBufferInterface(this); |
| 752 | if (!mLineLoopIB->reserveBufferSpace(INITIAL_INDEX_BUFFER_SIZE, GL_UNSIGNED_INT)) |
| 753 | { |
| 754 | delete mLineLoopIB; |
| 755 | mLineLoopIB = NULL; |
| 756 | |
| 757 | ERR("Could not create a 32-bit looping index buffer for GL_LINE_LOOP."); |
| 758 | return error(GL_OUT_OF_MEMORY); |
| 759 | } |
| 760 | } |
| 761 | |
| 762 | const int spaceNeeded = (count + 1) * sizeof(unsigned int); |
| 763 | if (!mLineLoopIB->reserveBufferSpace(spaceNeeded, GL_UNSIGNED_INT)) |
| 764 | { |
| 765 | ERR("Could not reserve enough space in looping index buffer for GL_LINE_LOOP."); |
| 766 | return error(GL_OUT_OF_MEMORY); |
| 767 | } |
| 768 | |
| 769 | void* mappedMemory = NULL; |
| 770 | int offset = mLineLoopIB->mapBuffer(spaceNeeded, &mappedMemory); |
| 771 | if (offset == -1 || mappedMemory == NULL) |
| 772 | { |
| 773 | ERR("Could not map index buffer for GL_LINE_LOOP."); |
| 774 | return error(GL_OUT_OF_MEMORY); |
| 775 | } |
| 776 | |
daniel@transgaming.com | c511430 | 2012-12-20 21:11:36 +0000 | [diff] [blame] | 777 | unsigned int *data = reinterpret_cast<unsigned int*>(mappedMemory); |
| 778 | |
| 779 | switch (type) |
| 780 | { |
| 781 | case GL_NONE: // Non-indexed draw |
| 782 | for (int i = 0; i < count; i++) |
| 783 | { |
| 784 | data[i] = i; |
| 785 | } |
| 786 | data[count] = 0; |
| 787 | break; |
| 788 | case GL_UNSIGNED_BYTE: |
| 789 | for (int i = 0; i < count; i++) |
| 790 | { |
| 791 | data[i] = static_cast<const GLubyte*>(indices)[i]; |
| 792 | } |
| 793 | data[count] = static_cast<const GLubyte*>(indices)[0]; |
| 794 | break; |
| 795 | case GL_UNSIGNED_SHORT: |
| 796 | for (int i = 0; i < count; i++) |
| 797 | { |
| 798 | data[i] = static_cast<const GLushort*>(indices)[i]; |
| 799 | } |
| 800 | data[count] = static_cast<const GLushort*>(indices)[0]; |
| 801 | break; |
| 802 | case GL_UNSIGNED_INT: |
| 803 | for (int i = 0; i < count; i++) |
| 804 | { |
| 805 | data[i] = static_cast<const GLuint*>(indices)[i]; |
| 806 | } |
| 807 | data[count] = static_cast<const GLuint*>(indices)[0]; |
| 808 | break; |
| 809 | default: UNREACHABLE(); |
| 810 | } |
| 811 | |
| 812 | if (!mLineLoopIB->unmapBuffer()) |
| 813 | { |
| 814 | ERR("Could not unmap index buffer for GL_LINE_LOOP."); |
| 815 | return error(GL_OUT_OF_MEMORY); |
| 816 | } |
| 817 | |
| 818 | if (mAppliedIBSerial != mLineLoopIB->getSerial()) |
| 819 | { |
| 820 | IndexBuffer11 *indexBuffer = IndexBuffer11::makeIndexBuffer11(mLineLoopIB->getIndexBuffer()); |
| 821 | |
daniel@transgaming.com | 22ada2c | 2013-01-11 04:07:12 +0000 | [diff] [blame] | 822 | mDeviceContext->IASetIndexBuffer(indexBuffer->getBuffer(), indexBuffer->getIndexFormat(), offset); |
daniel@transgaming.com | c511430 | 2012-12-20 21:11:36 +0000 | [diff] [blame] | 823 | mAppliedIBSerial = mLineLoopIB->getSerial(); |
| 824 | } |
| 825 | |
| 826 | mDeviceContext->IASetPrimitiveTopology(D3D11_PRIMITIVE_TOPOLOGY_LINELIST); |
| 827 | mDeviceContext->DrawIndexed(count, 0, -minIndex); |
daniel@transgaming.com | 91207b7 | 2012-11-28 20:56:43 +0000 | [diff] [blame] | 828 | } |
| 829 | |
daniel@transgaming.com | 5fbf177 | 2012-11-28 20:54:43 +0000 | [diff] [blame] | 830 | void Renderer11::applyShaders(gl::ProgramBinary *programBinary) |
| 831 | { |
daniel@transgaming.com | e499141 | 2012-12-20 20:55:34 +0000 | [diff] [blame] | 832 | unsigned int programBinarySerial = programBinary->getSerial(); |
| 833 | if (programBinarySerial != mAppliedProgramBinarySerial) |
| 834 | { |
| 835 | ShaderExecutable *vertexExe = programBinary->getVertexExecutable(); |
| 836 | ShaderExecutable *pixelExe = programBinary->getPixelExecutable(); |
daniel@transgaming.com | d4b2db2 | 2012-11-28 21:05:15 +0000 | [diff] [blame] | 837 | |
daniel@transgaming.com | e499141 | 2012-12-20 20:55:34 +0000 | [diff] [blame] | 838 | ID3D11VertexShader *vertexShader = NULL; |
| 839 | if (vertexExe) vertexShader = ShaderExecutable11::makeShaderExecutable11(vertexExe)->getVertexShader(); |
daniel@transgaming.com | d4b2db2 | 2012-11-28 21:05:15 +0000 | [diff] [blame] | 840 | |
daniel@transgaming.com | e499141 | 2012-12-20 20:55:34 +0000 | [diff] [blame] | 841 | ID3D11PixelShader *pixelShader = NULL; |
| 842 | if (pixelExe) pixelShader = ShaderExecutable11::makeShaderExecutable11(pixelExe)->getPixelShader(); |
daniel@transgaming.com | d4b2db2 | 2012-11-28 21:05:15 +0000 | [diff] [blame] | 843 | |
daniel@transgaming.com | e499141 | 2012-12-20 20:55:34 +0000 | [diff] [blame] | 844 | mDeviceContext->PSSetShader(pixelShader, NULL, 0); |
| 845 | mDeviceContext->VSSetShader(vertexShader, NULL, 0); |
| 846 | programBinary->dirtyAllUniforms(); |
| 847 | |
| 848 | mAppliedProgramBinarySerial = programBinarySerial; |
| 849 | } |
daniel@transgaming.com | 5fbf177 | 2012-11-28 20:54:43 +0000 | [diff] [blame] | 850 | } |
| 851 | |
daniel@transgaming.com | ab1c146 | 2012-12-20 21:08:30 +0000 | [diff] [blame] | 852 | void Renderer11::applyUniforms(const gl::UniformArray *uniformArray) |
| 853 | { |
daniel@transgaming.com | 873f28a | 2012-12-20 21:12:42 +0000 | [diff] [blame] | 854 | D3D11_BUFFER_DESC constantBufferDescription = {0}; |
| 855 | constantBufferDescription.ByteWidth = D3D10_REQ_CONSTANT_BUFFER_ELEMENT_COUNT * sizeof(float[4]); |
| 856 | constantBufferDescription.Usage = D3D11_USAGE_DYNAMIC; |
| 857 | constantBufferDescription.BindFlags = D3D11_BIND_CONSTANT_BUFFER; |
| 858 | constantBufferDescription.CPUAccessFlags = D3D11_CPU_ACCESS_WRITE; |
| 859 | constantBufferDescription.MiscFlags = 0; |
| 860 | constantBufferDescription.StructureByteStride = 0; |
| 861 | |
| 862 | ID3D11Buffer *constantBufferVS = NULL; |
| 863 | HRESULT result = mDevice->CreateBuffer(&constantBufferDescription, NULL, &constantBufferVS); |
| 864 | ASSERT(SUCCEEDED(result)); |
| 865 | |
| 866 | ID3D11Buffer *constantBufferPS = NULL; |
| 867 | result = mDevice->CreateBuffer(&constantBufferDescription, NULL, &constantBufferPS); |
| 868 | ASSERT(SUCCEEDED(result)); |
| 869 | |
| 870 | D3D11_MAPPED_SUBRESOURCE mapVS = {0}; |
| 871 | result = mDeviceContext->Map(constantBufferVS, 0, D3D11_MAP_WRITE_DISCARD, 0, &mapVS); |
| 872 | ASSERT(SUCCEEDED(result)); |
| 873 | |
| 874 | D3D11_MAPPED_SUBRESOURCE mapPS = {0}; |
| 875 | result = mDeviceContext->Map(constantBufferPS, 0, D3D11_MAP_WRITE_DISCARD, 0, &mapPS); |
| 876 | ASSERT(SUCCEEDED(result)); |
| 877 | |
| 878 | float (*cVS)[4] = (float(*)[4])mapVS.pData; |
| 879 | float (*cPS)[4] = (float(*)[4])mapPS.pData; |
| 880 | |
| 881 | 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] | 882 | { |
daniel@transgaming.com | 873f28a | 2012-12-20 21:12:42 +0000 | [diff] [blame] | 883 | const gl::Uniform *uniform = *uniform_iterator; |
| 884 | GLfloat (*f)[4] = (GLfloat(*)[4])uniform->data; |
| 885 | |
| 886 | switch (uniform->type) |
| 887 | { |
daniel@transgaming.com | da8d380 | 2012-12-20 21:12:55 +0000 | [diff] [blame] | 888 | case GL_SAMPLER_2D: |
| 889 | case GL_SAMPLER_CUBE: |
| 890 | break; |
daniel@transgaming.com | 873f28a | 2012-12-20 21:12:42 +0000 | [diff] [blame] | 891 | case GL_FLOAT: |
| 892 | case GL_FLOAT_VEC2: |
| 893 | case GL_FLOAT_VEC3: |
| 894 | case GL_FLOAT_VEC4: |
| 895 | case GL_FLOAT_MAT2: |
| 896 | case GL_FLOAT_MAT3: |
| 897 | case GL_FLOAT_MAT4: |
| 898 | if (uniform->vs.registerCount) |
| 899 | { |
daniel@transgaming.com | e6d12e9 | 2012-12-20 21:12:47 +0000 | [diff] [blame] | 900 | for (unsigned int i = 0; i < uniform->vs.registerCount; i++) |
daniel@transgaming.com | 873f28a | 2012-12-20 21:12:42 +0000 | [diff] [blame] | 901 | { |
| 902 | cVS[uniform->vs.registerIndex + i][0] = f[i][0]; |
| 903 | cVS[uniform->vs.registerIndex + i][1] = f[i][1]; |
| 904 | cVS[uniform->vs.registerIndex + i][2] = f[i][2]; |
| 905 | cVS[uniform->vs.registerIndex + i][3] = f[i][3]; |
| 906 | } |
| 907 | } |
| 908 | if (uniform->ps.registerCount) |
| 909 | { |
daniel@transgaming.com | e6d12e9 | 2012-12-20 21:12:47 +0000 | [diff] [blame] | 910 | for (unsigned int i = 0; i < uniform->ps.registerCount; i++) |
daniel@transgaming.com | 873f28a | 2012-12-20 21:12:42 +0000 | [diff] [blame] | 911 | { |
| 912 | cPS[uniform->ps.registerIndex + i][0] = f[i][0]; |
| 913 | cPS[uniform->ps.registerIndex + i][1] = f[i][1]; |
| 914 | cPS[uniform->ps.registerIndex + i][2] = f[i][2]; |
| 915 | cPS[uniform->ps.registerIndex + i][3] = f[i][3]; |
| 916 | } |
| 917 | } |
| 918 | break; |
| 919 | default: |
| 920 | UNIMPLEMENTED(); // FIXME |
| 921 | UNREACHABLE(); |
| 922 | } |
daniel@transgaming.com | ab1c146 | 2012-12-20 21:08:30 +0000 | [diff] [blame] | 923 | } |
daniel@transgaming.com | 873f28a | 2012-12-20 21:12:42 +0000 | [diff] [blame] | 924 | |
| 925 | mDeviceContext->Unmap(constantBufferVS, 0); |
| 926 | mDeviceContext->VSSetConstantBuffers(0, 1, &constantBufferVS); |
| 927 | constantBufferVS->Release(); |
| 928 | |
| 929 | mDeviceContext->Unmap(constantBufferPS, 0); |
| 930 | mDeviceContext->PSSetConstantBuffers(0, 1, &constantBufferPS); |
| 931 | constantBufferPS->Release(); |
daniel@transgaming.com | ab1c146 | 2012-12-20 21:08:30 +0000 | [diff] [blame] | 932 | } |
| 933 | |
daniel@transgaming.com | 084a257 | 2012-11-28 20:55:17 +0000 | [diff] [blame] | 934 | void Renderer11::clear(const gl::ClearParameters &clearParams, gl::Framebuffer *frameBuffer) |
daniel@transgaming.com | d084c62 | 2012-11-28 19:36:05 +0000 | [diff] [blame] | 935 | { |
daniel@transgaming.com | 54e6754 | 2012-11-28 21:02:31 +0000 | [diff] [blame] | 936 | if (clearParams.mask & GL_COLOR_BUFFER_BIT) |
| 937 | { |
| 938 | gl::Renderbuffer *renderbufferObject = frameBuffer->getColorbuffer(); |
| 939 | if (renderbufferObject) |
| 940 | { |
| 941 | RenderTarget11 *renderTarget = RenderTarget11::makeRenderTarget11(renderbufferObject->getRenderTarget()); |
| 942 | if (!renderTarget) |
| 943 | { |
| 944 | ERR("render target pointer unexpectedly null."); |
| 945 | return; |
| 946 | } |
| 947 | |
| 948 | ID3D11RenderTargetView *framebufferRTV = renderTarget->getRenderTargetView(); |
| 949 | if (!framebufferRTV) |
| 950 | { |
| 951 | ERR("render target view pointer unexpectedly null."); |
| 952 | return; |
| 953 | } |
| 954 | |
daniel@transgaming.com | d55e8c1 | 2012-11-28 21:07:02 +0000 | [diff] [blame] | 955 | if (mScissorEnabled && (mCurScissor.x > 0 || mCurScissor.y > 0 || |
| 956 | mCurScissor.x + mCurScissor.width < renderTarget->getWidth() || |
| 957 | mCurScissor.y + mCurScissor.height < renderTarget->getHeight())) |
daniel@transgaming.com | 54e6754 | 2012-11-28 21:02:31 +0000 | [diff] [blame] | 958 | { |
| 959 | // TODO: clearing of subregion of render target |
| 960 | UNIMPLEMENTED(); |
| 961 | } |
| 962 | |
| 963 | bool alphaUnmasked = (gl::GetAlphaSize(mRenderTargetDesc.format) == 0) || clearParams.colorMaskAlpha; |
| 964 | const bool needMaskedColorClear = (clearParams.mask & GL_COLOR_BUFFER_BIT) && |
| 965 | !(clearParams.colorMaskRed && clearParams.colorMaskGreen && |
| 966 | clearParams.colorMaskBlue && alphaUnmasked); |
| 967 | |
| 968 | if (needMaskedColorClear) |
| 969 | { |
| 970 | // TODO: masked color clearing |
| 971 | UNIMPLEMENTED(); |
| 972 | } |
| 973 | else |
| 974 | { |
| 975 | const float clearValues[4] = { clearParams.colorClearValue.red, |
| 976 | clearParams.colorClearValue.green, |
| 977 | clearParams.colorClearValue.blue, |
| 978 | clearParams.colorClearValue.alpha }; |
| 979 | mDeviceContext->ClearRenderTargetView(framebufferRTV, clearValues); |
| 980 | } |
| 981 | |
| 982 | framebufferRTV->Release(); |
| 983 | } |
| 984 | } |
| 985 | if (clearParams.mask & GL_DEPTH_BUFFER_BIT || clearParams.mask & GL_STENCIL_BUFFER_BIT) |
| 986 | { |
| 987 | gl::Renderbuffer *renderbufferObject = frameBuffer->getDepthOrStencilbuffer(); |
| 988 | if (renderbufferObject) |
| 989 | { |
daniel@transgaming.com | d0f82bc | 2012-12-20 21:11:42 +0000 | [diff] [blame] | 990 | RenderTarget11 *renderTarget = RenderTarget11::makeRenderTarget11(renderbufferObject->getDepthStencil()); |
daniel@transgaming.com | 54e6754 | 2012-11-28 21:02:31 +0000 | [diff] [blame] | 991 | if (!renderTarget) |
| 992 | { |
| 993 | ERR("render target pointer unexpectedly null."); |
| 994 | return; |
| 995 | } |
| 996 | |
| 997 | ID3D11DepthStencilView *framebufferDSV = renderTarget->getDepthStencilView(); |
| 998 | if (!framebufferDSV) |
| 999 | { |
| 1000 | ERR("depth stencil view pointer unexpectedly null."); |
| 1001 | return; |
| 1002 | } |
| 1003 | |
daniel@transgaming.com | d55e8c1 | 2012-11-28 21:07:02 +0000 | [diff] [blame] | 1004 | if (mScissorEnabled && (mCurScissor.x > 0 || mCurScissor.y > 0 || |
| 1005 | mCurScissor.x + mCurScissor.width < renderTarget->getWidth() || |
| 1006 | mCurScissor.y + mCurScissor.height < renderTarget->getHeight())) |
daniel@transgaming.com | 54e6754 | 2012-11-28 21:02:31 +0000 | [diff] [blame] | 1007 | { |
| 1008 | // TODO: clearing of subregion of depth stencil view |
| 1009 | UNIMPLEMENTED(); |
| 1010 | } |
| 1011 | |
| 1012 | unsigned int stencilUnmasked = 0x0; |
| 1013 | if ((clearParams.mask & GL_STENCIL_BUFFER_BIT) && frameBuffer->hasStencil()) |
| 1014 | { |
| 1015 | unsigned int stencilSize = gl::GetStencilSize(frameBuffer->getStencilbuffer()->getActualFormat()); |
| 1016 | stencilUnmasked = (0x1 << stencilSize) - 1; |
| 1017 | } |
| 1018 | |
| 1019 | const bool needMaskedStencilClear = (clearParams.mask & GL_STENCIL_BUFFER_BIT) && |
| 1020 | (clearParams.stencilWriteMask & stencilUnmasked) != stencilUnmasked; |
| 1021 | |
| 1022 | if (needMaskedStencilClear) |
| 1023 | { |
| 1024 | // TODO: masked clearing of depth stencil |
| 1025 | UNIMPLEMENTED(); |
| 1026 | } |
| 1027 | else |
| 1028 | { |
| 1029 | UINT clearFlags = 0; |
| 1030 | if (clearParams.mask & GL_DEPTH_BUFFER_BIT) |
| 1031 | { |
| 1032 | clearFlags |= D3D11_CLEAR_DEPTH; |
| 1033 | } |
| 1034 | if (clearParams.mask & GL_STENCIL_BUFFER_BIT) |
| 1035 | { |
| 1036 | clearFlags |= D3D11_CLEAR_STENCIL; |
| 1037 | } |
| 1038 | |
| 1039 | float depthClear = clearParams.depthClearValue; |
| 1040 | UINT8 stencilClear = clearParams.stencilClearValue & 0x000000FF; |
| 1041 | |
| 1042 | mDeviceContext->ClearDepthStencilView(framebufferDSV, clearFlags, depthClear, stencilClear); |
| 1043 | } |
| 1044 | |
| 1045 | framebufferDSV->Release(); |
| 1046 | } |
| 1047 | } |
daniel@transgaming.com | d084c62 | 2012-11-28 19:36:05 +0000 | [diff] [blame] | 1048 | } |
| 1049 | |
daniel@transgaming.com | c43a605 | 2012-11-28 19:41:51 +0000 | [diff] [blame] | 1050 | void Renderer11::markAllStateDirty() |
| 1051 | { |
daniel@transgaming.com | 9a06737 | 2012-12-20 20:55:24 +0000 | [diff] [blame] | 1052 | mAppliedRenderTargetSerial = 0; |
| 1053 | mAppliedDepthbufferSerial = 0; |
| 1054 | mAppliedStencilbufferSerial = 0; |
daniel@transgaming.com | 7b6b83e | 2012-11-28 21:00:30 +0000 | [diff] [blame] | 1055 | mDepthStencilInitialized = false; |
| 1056 | mRenderTargetDescInitialized = false; |
| 1057 | |
daniel@transgaming.com | 54de24f | 2013-01-11 04:07:59 +0000 | [diff] [blame^] | 1058 | for (int i = 0; i < gl::MAX_VERTEX_TEXTURE_IMAGE_UNITS_VTF; i++) |
| 1059 | { |
| 1060 | mForceSetVertexSamplerStates[i] = true; |
| 1061 | } |
| 1062 | for (int i = 0; i < gl::MAX_TEXTURE_IMAGE_UNITS; i++) |
| 1063 | { |
| 1064 | mForceSetPixelSamplerStates[i] = true; |
| 1065 | } |
| 1066 | |
daniel@transgaming.com | c43a605 | 2012-11-28 19:41:51 +0000 | [diff] [blame] | 1067 | mForceSetBlendState = true; |
| 1068 | mForceSetRasterState = true; |
| 1069 | mForceSetDepthStencilState = true; |
| 1070 | mForceSetScissor = true; |
daniel@transgaming.com | 5367004 | 2012-11-28 20:55:51 +0000 | [diff] [blame] | 1071 | mForceSetViewport = true; |
daniel@transgaming.com | e499141 | 2012-12-20 20:55:34 +0000 | [diff] [blame] | 1072 | |
daniel@transgaming.com | c5431eb | 2012-12-20 21:10:15 +0000 | [diff] [blame] | 1073 | mAppliedIBSerial = 0; |
daniel@transgaming.com | e499141 | 2012-12-20 20:55:34 +0000 | [diff] [blame] | 1074 | mAppliedProgramBinarySerial = 0; |
daniel@transgaming.com | c43a605 | 2012-11-28 19:41:51 +0000 | [diff] [blame] | 1075 | } |
| 1076 | |
daniel@transgaming.com | 1d6aff2 | 2012-11-28 19:30:42 +0000 | [diff] [blame] | 1077 | void Renderer11::releaseDeviceResources() |
| 1078 | { |
daniel@transgaming.com | f8ba109 | 2012-11-28 19:37:53 +0000 | [diff] [blame] | 1079 | mStateCache.clear(); |
daniel@transgaming.com | c5431eb | 2012-12-20 21:10:15 +0000 | [diff] [blame] | 1080 | mInputLayoutCache.clear(); |
| 1081 | |
| 1082 | delete mVertexDataManager; |
| 1083 | mVertexDataManager = NULL; |
| 1084 | |
| 1085 | delete mIndexDataManager; |
| 1086 | mIndexDataManager = NULL; |
daniel@transgaming.com | c511430 | 2012-12-20 21:11:36 +0000 | [diff] [blame] | 1087 | |
| 1088 | delete mLineLoopIB; |
| 1089 | mLineLoopIB = NULL; |
daniel@transgaming.com | 1d6aff2 | 2012-11-28 19:30:42 +0000 | [diff] [blame] | 1090 | } |
| 1091 | |
| 1092 | void Renderer11::markDeviceLost() |
| 1093 | { |
| 1094 | mDeviceLost = true; |
| 1095 | } |
| 1096 | |
| 1097 | bool Renderer11::isDeviceLost() |
| 1098 | { |
| 1099 | return mDeviceLost; |
| 1100 | } |
| 1101 | |
| 1102 | // set notify to true to broadcast a message to all contexts of the device loss |
| 1103 | bool Renderer11::testDeviceLost(bool notify) |
| 1104 | { |
| 1105 | bool isLost = false; |
| 1106 | |
| 1107 | // TODO |
daniel@transgaming.com | b9bb279 | 2012-11-28 19:36:49 +0000 | [diff] [blame] | 1108 | //UNIMPLEMENTED(); |
daniel@transgaming.com | 1d6aff2 | 2012-11-28 19:30:42 +0000 | [diff] [blame] | 1109 | |
| 1110 | if (isLost) |
| 1111 | { |
| 1112 | // ensure we note the device loss -- |
| 1113 | // we'll probably get this done again by markDeviceLost |
| 1114 | // but best to remember it! |
| 1115 | // Note that we don't want to clear the device loss status here |
| 1116 | // -- this needs to be done by resetDevice |
| 1117 | mDeviceLost = true; |
| 1118 | if (notify) |
| 1119 | { |
| 1120 | mDisplay->notifyDeviceLost(); |
| 1121 | } |
| 1122 | } |
| 1123 | |
| 1124 | return isLost; |
| 1125 | } |
| 1126 | |
| 1127 | bool Renderer11::testDeviceResettable() |
| 1128 | { |
| 1129 | HRESULT status = D3D_OK; |
| 1130 | |
| 1131 | // TODO |
| 1132 | UNIMPLEMENTED(); |
| 1133 | |
| 1134 | switch (status) |
| 1135 | { |
| 1136 | case D3DERR_DEVICENOTRESET: |
| 1137 | case D3DERR_DEVICEHUNG: |
| 1138 | return true; |
| 1139 | default: |
| 1140 | return false; |
| 1141 | } |
| 1142 | } |
| 1143 | |
| 1144 | bool Renderer11::resetDevice() |
| 1145 | { |
| 1146 | releaseDeviceResources(); |
| 1147 | |
| 1148 | // TODO |
| 1149 | UNIMPLEMENTED(); |
| 1150 | |
| 1151 | // reset device defaults |
| 1152 | initializeDevice(); |
| 1153 | mDeviceLost = false; |
| 1154 | |
| 1155 | return true; |
| 1156 | } |
| 1157 | |
| 1158 | DWORD Renderer11::getAdapterVendor() const |
| 1159 | { |
daniel@transgaming.com | 1f811f5 | 2012-11-28 20:57:39 +0000 | [diff] [blame] | 1160 | return mAdapterDescription.VendorId; |
daniel@transgaming.com | 1d6aff2 | 2012-11-28 19:30:42 +0000 | [diff] [blame] | 1161 | } |
| 1162 | |
| 1163 | const char *Renderer11::getAdapterDescription() const |
| 1164 | { |
daniel@transgaming.com | 1f811f5 | 2012-11-28 20:57:39 +0000 | [diff] [blame] | 1165 | return mDescription; |
daniel@transgaming.com | 1d6aff2 | 2012-11-28 19:30:42 +0000 | [diff] [blame] | 1166 | } |
| 1167 | |
| 1168 | GUID Renderer11::getAdapterIdentifier() const |
| 1169 | { |
| 1170 | // TODO |
daniel@transgaming.com | 1f811f5 | 2012-11-28 20:57:39 +0000 | [diff] [blame] | 1171 | // UNIMPLEMENTED(); |
| 1172 | GUID foo = {0}; |
daniel@transgaming.com | 1d6aff2 | 2012-11-28 19:30:42 +0000 | [diff] [blame] | 1173 | return foo; |
| 1174 | } |
| 1175 | |
| 1176 | bool Renderer11::getDXT1TextureSupport() |
| 1177 | { |
| 1178 | // TODO |
daniel@transgaming.com | 1f811f5 | 2012-11-28 20:57:39 +0000 | [diff] [blame] | 1179 | // UNIMPLEMENTED(); |
daniel@transgaming.com | 1d6aff2 | 2012-11-28 19:30:42 +0000 | [diff] [blame] | 1180 | return false; |
| 1181 | } |
| 1182 | |
| 1183 | bool Renderer11::getDXT3TextureSupport() |
| 1184 | { |
| 1185 | // TODO |
daniel@transgaming.com | 1f811f5 | 2012-11-28 20:57:39 +0000 | [diff] [blame] | 1186 | // UNIMPLEMENTED(); |
daniel@transgaming.com | 1d6aff2 | 2012-11-28 19:30:42 +0000 | [diff] [blame] | 1187 | return false; |
| 1188 | } |
| 1189 | |
| 1190 | bool Renderer11::getDXT5TextureSupport() |
| 1191 | { |
| 1192 | // TODO |
daniel@transgaming.com | 1f811f5 | 2012-11-28 20:57:39 +0000 | [diff] [blame] | 1193 | // UNIMPLEMENTED(); |
daniel@transgaming.com | 1d6aff2 | 2012-11-28 19:30:42 +0000 | [diff] [blame] | 1194 | return false; |
| 1195 | } |
| 1196 | |
| 1197 | bool Renderer11::getDepthTextureSupport() const |
| 1198 | { |
| 1199 | // TODO |
daniel@transgaming.com | 1f811f5 | 2012-11-28 20:57:39 +0000 | [diff] [blame] | 1200 | // UNIMPLEMENTED(); |
daniel@transgaming.com | 1d6aff2 | 2012-11-28 19:30:42 +0000 | [diff] [blame] | 1201 | return false; |
| 1202 | } |
| 1203 | |
| 1204 | bool Renderer11::getFloat32TextureSupport(bool *filtering, bool *renderable) |
| 1205 | { |
| 1206 | // TODO |
daniel@transgaming.com | 1f811f5 | 2012-11-28 20:57:39 +0000 | [diff] [blame] | 1207 | // UNIMPLEMENTED(); |
daniel@transgaming.com | 1d6aff2 | 2012-11-28 19:30:42 +0000 | [diff] [blame] | 1208 | |
| 1209 | *filtering = false; |
| 1210 | *renderable = false; |
| 1211 | return false; |
| 1212 | } |
| 1213 | |
| 1214 | bool Renderer11::getFloat16TextureSupport(bool *filtering, bool *renderable) |
| 1215 | { |
| 1216 | // TODO |
daniel@transgaming.com | 1f811f5 | 2012-11-28 20:57:39 +0000 | [diff] [blame] | 1217 | // UNIMPLEMENTED(); |
daniel@transgaming.com | 1d6aff2 | 2012-11-28 19:30:42 +0000 | [diff] [blame] | 1218 | |
| 1219 | *filtering = false; |
| 1220 | *renderable = false; |
| 1221 | return false; |
| 1222 | } |
| 1223 | |
| 1224 | bool Renderer11::getLuminanceTextureSupport() |
| 1225 | { |
| 1226 | // TODO |
daniel@transgaming.com | 1f811f5 | 2012-11-28 20:57:39 +0000 | [diff] [blame] | 1227 | // UNIMPLEMENTED(); |
daniel@transgaming.com | 1d6aff2 | 2012-11-28 19:30:42 +0000 | [diff] [blame] | 1228 | return false; |
| 1229 | } |
| 1230 | |
| 1231 | bool Renderer11::getLuminanceAlphaTextureSupport() |
| 1232 | { |
| 1233 | // TODO |
daniel@transgaming.com | 1f811f5 | 2012-11-28 20:57:39 +0000 | [diff] [blame] | 1234 | // UNIMPLEMENTED(); |
daniel@transgaming.com | 1d6aff2 | 2012-11-28 19:30:42 +0000 | [diff] [blame] | 1235 | return false; |
| 1236 | } |
| 1237 | |
| 1238 | bool Renderer11::getTextureFilterAnisotropySupport() const |
| 1239 | { |
| 1240 | // TODO |
daniel@transgaming.com | 1f811f5 | 2012-11-28 20:57:39 +0000 | [diff] [blame] | 1241 | // UNIMPLEMENTED(); |
daniel@transgaming.com | 1d6aff2 | 2012-11-28 19:30:42 +0000 | [diff] [blame] | 1242 | return false; |
| 1243 | } |
| 1244 | |
| 1245 | float Renderer11::getTextureMaxAnisotropy() const |
| 1246 | { |
| 1247 | // TODO |
daniel@transgaming.com | 1f811f5 | 2012-11-28 20:57:39 +0000 | [diff] [blame] | 1248 | // UNIMPLEMENTED(); |
daniel@transgaming.com | 1d6aff2 | 2012-11-28 19:30:42 +0000 | [diff] [blame] | 1249 | return 1.0f; |
| 1250 | } |
| 1251 | |
| 1252 | bool Renderer11::getEventQuerySupport() |
| 1253 | { |
| 1254 | // TODO |
daniel@transgaming.com | 1f811f5 | 2012-11-28 20:57:39 +0000 | [diff] [blame] | 1255 | // UNIMPLEMENTED(); |
daniel@transgaming.com | 1d6aff2 | 2012-11-28 19:30:42 +0000 | [diff] [blame] | 1256 | return false; |
| 1257 | } |
| 1258 | |
| 1259 | bool Renderer11::getVertexTextureSupport() const |
| 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::getNonPower2TextureSupport() const |
| 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::getOcclusionQuerySupport() 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 | bool Renderer11::getInstancingSupport() 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 false; |
| 1285 | } |
| 1286 | |
| 1287 | bool Renderer11::getShareHandleSupport() const |
| 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 | |
| 1292 | // PIX doesn't seem to support using share handles, so disable them. |
| 1293 | return false && !gl::perfActive(); |
| 1294 | } |
| 1295 | |
daniel@transgaming.com | 9549bea | 2012-11-28 20:57:23 +0000 | [diff] [blame] | 1296 | int Renderer11::getMajorShaderModel() const |
daniel@transgaming.com | 1d6aff2 | 2012-11-28 19:30:42 +0000 | [diff] [blame] | 1297 | { |
daniel@transgaming.com | 9549bea | 2012-11-28 20:57:23 +0000 | [diff] [blame] | 1298 | switch (mFeatureLevel) |
| 1299 | { |
| 1300 | case D3D_FEATURE_LEVEL_11_0: return D3D11_SHADER_MAJOR_VERSION; // 5 |
| 1301 | case D3D_FEATURE_LEVEL_10_1: |
| 1302 | case D3D_FEATURE_LEVEL_10_0: return D3D10_SHADER_MAJOR_VERSION; // 4 |
| 1303 | default: UNREACHABLE(); return 0; |
| 1304 | } |
daniel@transgaming.com | 1d6aff2 | 2012-11-28 19:30:42 +0000 | [diff] [blame] | 1305 | } |
| 1306 | |
| 1307 | float Renderer11::getMaxPointSize() const |
| 1308 | { |
| 1309 | // TODO |
daniel@transgaming.com | 1f811f5 | 2012-11-28 20:57:39 +0000 | [diff] [blame] | 1310 | // UNIMPLEMENTED(); |
daniel@transgaming.com | 1d6aff2 | 2012-11-28 19:30:42 +0000 | [diff] [blame] | 1311 | return 1.0f; |
| 1312 | } |
| 1313 | |
| 1314 | int Renderer11::getMaxTextureWidth() const |
| 1315 | { |
daniel@transgaming.com | 25072f6 | 2012-11-28 19:31:32 +0000 | [diff] [blame] | 1316 | switch (mFeatureLevel) |
| 1317 | { |
| 1318 | case D3D_FEATURE_LEVEL_11_0: return D3D11_REQ_TEXTURE2D_U_OR_V_DIMENSION; // 16384 |
| 1319 | case D3D_FEATURE_LEVEL_10_1: |
| 1320 | case D3D_FEATURE_LEVEL_10_0: return D3D10_REQ_TEXTURE2D_U_OR_V_DIMENSION; // 8192 |
| 1321 | default: UNREACHABLE(); return 0; |
| 1322 | } |
daniel@transgaming.com | 1d6aff2 | 2012-11-28 19:30:42 +0000 | [diff] [blame] | 1323 | } |
| 1324 | |
| 1325 | int Renderer11::getMaxTextureHeight() const |
| 1326 | { |
daniel@transgaming.com | 25072f6 | 2012-11-28 19:31:32 +0000 | [diff] [blame] | 1327 | switch (mFeatureLevel) |
| 1328 | { |
| 1329 | case D3D_FEATURE_LEVEL_11_0: return D3D11_REQ_TEXTURE2D_U_OR_V_DIMENSION; // 16384 |
| 1330 | case D3D_FEATURE_LEVEL_10_1: |
| 1331 | case D3D_FEATURE_LEVEL_10_0: return D3D10_REQ_TEXTURE2D_U_OR_V_DIMENSION; // 8192 |
| 1332 | default: UNREACHABLE(); return 0; |
| 1333 | } |
daniel@transgaming.com | 1d6aff2 | 2012-11-28 19:30:42 +0000 | [diff] [blame] | 1334 | } |
| 1335 | |
| 1336 | bool Renderer11::get32BitIndexSupport() const |
| 1337 | { |
daniel@transgaming.com | 25072f6 | 2012-11-28 19:31:32 +0000 | [diff] [blame] | 1338 | switch (mFeatureLevel) |
| 1339 | { |
| 1340 | case D3D_FEATURE_LEVEL_11_0: |
| 1341 | case D3D_FEATURE_LEVEL_10_1: |
| 1342 | case D3D_FEATURE_LEVEL_10_0: return D3D10_REQ_DRAWINDEXED_INDEX_COUNT_2_TO_EXP >= 32; // true |
| 1343 | default: UNREACHABLE(); return false; |
| 1344 | } |
daniel@transgaming.com | 1d6aff2 | 2012-11-28 19:30:42 +0000 | [diff] [blame] | 1345 | } |
| 1346 | |
| 1347 | int Renderer11::getMinSwapInterval() const |
| 1348 | { |
daniel@transgaming.com | 8c7b1a9 | 2012-11-28 19:34:06 +0000 | [diff] [blame] | 1349 | return 0; |
daniel@transgaming.com | 1d6aff2 | 2012-11-28 19:30:42 +0000 | [diff] [blame] | 1350 | } |
| 1351 | |
| 1352 | int Renderer11::getMaxSwapInterval() const |
| 1353 | { |
daniel@transgaming.com | 8c7b1a9 | 2012-11-28 19:34:06 +0000 | [diff] [blame] | 1354 | return 4; |
daniel@transgaming.com | 1d6aff2 | 2012-11-28 19:30:42 +0000 | [diff] [blame] | 1355 | } |
| 1356 | |
| 1357 | int Renderer11::getMaxSupportedSamples() const |
| 1358 | { |
| 1359 | // TODO |
daniel@transgaming.com | 1f811f5 | 2012-11-28 20:57:39 +0000 | [diff] [blame] | 1360 | // UNIMPLEMENTED(); |
daniel@transgaming.com | 1d6aff2 | 2012-11-28 19:30:42 +0000 | [diff] [blame] | 1361 | return 1; |
| 1362 | } |
| 1363 | |
daniel@transgaming.com | 87705f8 | 2012-12-20 21:10:45 +0000 | [diff] [blame] | 1364 | bool Renderer11::copyToRenderTarget(TextureStorageInterface2D *dest, TextureStorageInterface2D *source) |
daniel@transgaming.com | ad6aee7 | 2012-11-28 19:33:42 +0000 | [diff] [blame] | 1365 | { |
daniel@transgaming.com | b1c208f | 2013-01-11 04:06:49 +0000 | [diff] [blame] | 1366 | if (source && dest) |
| 1367 | { |
| 1368 | TextureStorage11_2D *source11 = TextureStorage11_2D::makeTextureStorage11_2D(source->getStorageInstance()); |
| 1369 | TextureStorage11_2D *dest11 = TextureStorage11_2D::makeTextureStorage11_2D(dest->getStorageInstance()); |
| 1370 | |
daniel@transgaming.com | e9cf5e7 | 2013-01-11 04:06:55 +0000 | [diff] [blame] | 1371 | mDeviceContext->CopyResource(dest11->getBaseTexture(), source11->getBaseTexture()); |
daniel@transgaming.com | b1c208f | 2013-01-11 04:06:49 +0000 | [diff] [blame] | 1372 | return true; |
| 1373 | } |
| 1374 | |
daniel@transgaming.com | ad6aee7 | 2012-11-28 19:33:42 +0000 | [diff] [blame] | 1375 | return false; |
| 1376 | } |
| 1377 | |
daniel@transgaming.com | 87705f8 | 2012-12-20 21:10:45 +0000 | [diff] [blame] | 1378 | bool Renderer11::copyToRenderTarget(TextureStorageInterfaceCube *dest, TextureStorageInterfaceCube *source) |
daniel@transgaming.com | ad6aee7 | 2012-11-28 19:33:42 +0000 | [diff] [blame] | 1379 | { |
daniel@transgaming.com | b1c208f | 2013-01-11 04:06:49 +0000 | [diff] [blame] | 1380 | if (source && dest) |
| 1381 | { |
daniel@transgaming.com | e9cf5e7 | 2013-01-11 04:06:55 +0000 | [diff] [blame] | 1382 | TextureStorage11_Cube *source11 = TextureStorage11_Cube::makeTextureStorage11_Cube(source->getStorageInstance()); |
| 1383 | TextureStorage11_Cube *dest11 = TextureStorage11_Cube::makeTextureStorage11_Cube(dest->getStorageInstance()); |
daniel@transgaming.com | b1c208f | 2013-01-11 04:06:49 +0000 | [diff] [blame] | 1384 | |
daniel@transgaming.com | e9cf5e7 | 2013-01-11 04:06:55 +0000 | [diff] [blame] | 1385 | mDeviceContext->CopyResource(dest11->getBaseTexture(), source11->getBaseTexture()); |
daniel@transgaming.com | b1c208f | 2013-01-11 04:06:49 +0000 | [diff] [blame] | 1386 | return true; |
| 1387 | } |
| 1388 | |
daniel@transgaming.com | ad6aee7 | 2012-11-28 19:33:42 +0000 | [diff] [blame] | 1389 | return false; |
| 1390 | } |
| 1391 | |
daniel@transgaming.com | 3838088 | 2012-11-28 19:36:39 +0000 | [diff] [blame] | 1392 | bool Renderer11::copyImage(gl::Framebuffer *framebuffer, const RECT &sourceRect, GLenum destFormat, |
daniel@transgaming.com | 87705f8 | 2012-12-20 21:10:45 +0000 | [diff] [blame] | 1393 | GLint xoffset, GLint yoffset, TextureStorageInterface2D *storage, GLint level) |
daniel@transgaming.com | 3838088 | 2012-11-28 19:36:39 +0000 | [diff] [blame] | 1394 | { |
| 1395 | // TODO |
| 1396 | UNIMPLEMENTED(); |
| 1397 | return false; |
| 1398 | } |
| 1399 | |
| 1400 | bool Renderer11::copyImage(gl::Framebuffer *framebuffer, const RECT &sourceRect, GLenum destFormat, |
daniel@transgaming.com | 87705f8 | 2012-12-20 21:10:45 +0000 | [diff] [blame] | 1401 | GLint xoffset, GLint yoffset, TextureStorageInterfaceCube *storage, GLenum target, GLint level) |
daniel@transgaming.com | 3838088 | 2012-11-28 19:36:39 +0000 | [diff] [blame] | 1402 | { |
| 1403 | // TODO |
| 1404 | UNIMPLEMENTED(); |
| 1405 | return false; |
| 1406 | } |
| 1407 | |
daniel@transgaming.com | f242365 | 2012-11-28 20:53:50 +0000 | [diff] [blame] | 1408 | RenderTarget *Renderer11::createRenderTarget(SwapChain *swapChain, bool depth) |
| 1409 | { |
daniel@transgaming.com | b6b27bc | 2012-11-28 20:54:30 +0000 | [diff] [blame] | 1410 | SwapChain11 *swapChain11 = SwapChain11::makeSwapChain11(swapChain); |
| 1411 | RenderTarget11 *renderTarget = NULL; |
| 1412 | if (depth) |
| 1413 | { |
| 1414 | renderTarget = new RenderTarget11(this, swapChain11->getDepthStencil(), swapChain11->getWidth(), swapChain11->getHeight()); |
| 1415 | } |
| 1416 | else |
| 1417 | { |
| 1418 | renderTarget = new RenderTarget11(this, swapChain11->getRenderTarget(), swapChain11->getWidth(), swapChain11->getHeight()); |
| 1419 | } |
| 1420 | return renderTarget; |
daniel@transgaming.com | f242365 | 2012-11-28 20:53:50 +0000 | [diff] [blame] | 1421 | } |
| 1422 | |
| 1423 | RenderTarget *Renderer11::createRenderTarget(int width, int height, GLenum format, GLsizei samples, bool depth) |
| 1424 | { |
| 1425 | // TODO |
| 1426 | UNIMPLEMENTED(); |
| 1427 | return NULL; |
| 1428 | } |
| 1429 | |
daniel@transgaming.com | 2275f91 | 2012-12-20 21:13:22 +0000 | [diff] [blame] | 1430 | ShaderExecutable *Renderer11::loadExecutable(const void *function, size_t length, GLenum type) |
daniel@transgaming.com | 5531890 | 2012-11-28 20:58:58 +0000 | [diff] [blame] | 1431 | { |
daniel@transgaming.com | a2f9fbe | 2012-11-28 21:03:40 +0000 | [diff] [blame] | 1432 | ShaderExecutable11 *executable = NULL; |
| 1433 | |
| 1434 | switch (type) |
| 1435 | { |
| 1436 | case GL_VERTEX_SHADER: |
| 1437 | { |
| 1438 | ID3D11VertexShader *vshader = NULL; |
| 1439 | HRESULT result = mDevice->CreateVertexShader(function, length, NULL, &vshader); |
| 1440 | ASSERT(SUCCEEDED(result)); |
| 1441 | |
| 1442 | if (vshader) |
| 1443 | { |
daniel@transgaming.com | 7b18d0c | 2012-11-28 21:04:10 +0000 | [diff] [blame] | 1444 | executable = new ShaderExecutable11(function, length, vshader); |
daniel@transgaming.com | a2f9fbe | 2012-11-28 21:03:40 +0000 | [diff] [blame] | 1445 | } |
| 1446 | } |
| 1447 | break; |
| 1448 | case GL_FRAGMENT_SHADER: |
| 1449 | { |
| 1450 | ID3D11PixelShader *pshader = NULL; |
| 1451 | HRESULT result = mDevice->CreatePixelShader(function, length, NULL, &pshader); |
| 1452 | ASSERT(SUCCEEDED(result)); |
| 1453 | |
| 1454 | if (pshader) |
| 1455 | { |
daniel@transgaming.com | 7b18d0c | 2012-11-28 21:04:10 +0000 | [diff] [blame] | 1456 | executable = new ShaderExecutable11(function, length, pshader); |
daniel@transgaming.com | a2f9fbe | 2012-11-28 21:03:40 +0000 | [diff] [blame] | 1457 | } |
| 1458 | } |
| 1459 | break; |
| 1460 | default: |
| 1461 | UNREACHABLE(); |
| 1462 | break; |
| 1463 | } |
| 1464 | |
| 1465 | return executable; |
daniel@transgaming.com | 5531890 | 2012-11-28 20:58:58 +0000 | [diff] [blame] | 1466 | } |
| 1467 | |
daniel@transgaming.com | a9c7142 | 2012-11-28 20:58:45 +0000 | [diff] [blame] | 1468 | ShaderExecutable *Renderer11::compileToExecutable(gl::InfoLog &infoLog, const char *shaderHLSL, GLenum type) |
| 1469 | { |
daniel@transgaming.com | 071ee6a | 2012-11-28 21:03:21 +0000 | [diff] [blame] | 1470 | const char *profile = NULL; |
| 1471 | |
| 1472 | switch (type) |
| 1473 | { |
| 1474 | case GL_VERTEX_SHADER: |
| 1475 | profile = "vs_4_0"; |
| 1476 | break; |
| 1477 | case GL_FRAGMENT_SHADER: |
| 1478 | profile = "ps_4_0"; |
| 1479 | break; |
| 1480 | default: |
| 1481 | UNREACHABLE(); |
| 1482 | return NULL; |
| 1483 | } |
| 1484 | |
daniel@transgaming.com | 25e16af | 2012-11-28 21:05:57 +0000 | [diff] [blame] | 1485 | ID3DBlob *binary = compileToBinary(infoLog, shaderHLSL, profile, false); |
daniel@transgaming.com | 071ee6a | 2012-11-28 21:03:21 +0000 | [diff] [blame] | 1486 | if (!binary) |
| 1487 | return NULL; |
| 1488 | |
daniel@transgaming.com | 2275f91 | 2012-12-20 21:13:22 +0000 | [diff] [blame] | 1489 | ShaderExecutable *executable = loadExecutable((DWORD *)binary->GetBufferPointer(), binary->GetBufferSize(), type); |
daniel@transgaming.com | 071ee6a | 2012-11-28 21:03:21 +0000 | [diff] [blame] | 1490 | binary->Release(); |
| 1491 | |
| 1492 | return executable; |
| 1493 | } |
| 1494 | |
daniel@transgaming.com | 3f255b4 | 2012-12-20 21:07:35 +0000 | [diff] [blame] | 1495 | VertexBuffer *Renderer11::createVertexBuffer() |
| 1496 | { |
daniel@transgaming.com | 2c4d070 | 2012-12-20 21:08:51 +0000 | [diff] [blame] | 1497 | return new VertexBuffer11(this); |
daniel@transgaming.com | 3f255b4 | 2012-12-20 21:07:35 +0000 | [diff] [blame] | 1498 | } |
| 1499 | |
daniel@transgaming.com | 0b6d774 | 2012-12-20 21:09:47 +0000 | [diff] [blame] | 1500 | IndexBuffer *Renderer11::createIndexBuffer() |
| 1501 | { |
daniel@transgaming.com | 11c2af5 | 2012-12-20 21:10:01 +0000 | [diff] [blame] | 1502 | return new IndexBuffer11(this); |
daniel@transgaming.com | 0b6d774 | 2012-12-20 21:09:47 +0000 | [diff] [blame] | 1503 | } |
| 1504 | |
daniel@transgaming.com | 6c87217 | 2012-11-28 19:39:33 +0000 | [diff] [blame] | 1505 | bool Renderer11::blitRect(gl::Framebuffer *readTarget, gl::Rectangle *readRect, gl::Framebuffer *drawTarget, gl::Rectangle *drawRect, |
| 1506 | bool blitRenderTarget, bool blitDepthStencil) |
| 1507 | { |
| 1508 | // TODO |
| 1509 | UNIMPLEMENTED(); |
| 1510 | return false; |
| 1511 | } |
| 1512 | |
| 1513 | void Renderer11::readPixels(gl::Framebuffer *framebuffer, GLint x, GLint y, GLsizei width, GLsizei height, GLenum format, GLenum type, |
| 1514 | GLsizei outputPitch, bool packReverseRowOrder, GLint packAlignment, void* pixels) |
| 1515 | { |
| 1516 | // TODO |
| 1517 | UNIMPLEMENTED(); |
| 1518 | return; |
| 1519 | } |
| 1520 | |
daniel@transgaming.com | 244e183 | 2012-12-20 20:52:35 +0000 | [diff] [blame] | 1521 | Image *Renderer11::createImage() |
| 1522 | { |
daniel@transgaming.com | a8aac67 | 2012-12-20 21:08:00 +0000 | [diff] [blame] | 1523 | return new Image11(); |
daniel@transgaming.com | 244e183 | 2012-12-20 20:52:35 +0000 | [diff] [blame] | 1524 | } |
| 1525 | |
daniel@transgaming.com | f721fdb | 2012-12-20 20:53:11 +0000 | [diff] [blame] | 1526 | void Renderer11::generateMipmap(Image *dest, Image *src) |
| 1527 | { |
| 1528 | // TODO |
| 1529 | UNIMPLEMENTED(); |
| 1530 | return; |
| 1531 | } |
| 1532 | |
daniel@transgaming.com | 413d271 | 2012-12-20 21:11:04 +0000 | [diff] [blame] | 1533 | TextureStorage *Renderer11::createTextureStorage2D(SwapChain *swapChain) |
| 1534 | { |
| 1535 | // TODO |
| 1536 | UNIMPLEMENTED(); |
| 1537 | return NULL; |
| 1538 | } |
| 1539 | |
| 1540 | TextureStorage *Renderer11::createTextureStorage2D(int levels, GLenum internalformat, GLenum usage, bool forceRenderable, GLsizei width, GLsizei height) |
| 1541 | { |
| 1542 | // TODO |
| 1543 | UNIMPLEMENTED(); |
| 1544 | return NULL; |
| 1545 | } |
| 1546 | |
| 1547 | TextureStorage *Renderer11::createTextureStorageCube(int levels, GLenum internalformat, GLenum usage, bool forceRenderable, int size) |
| 1548 | { |
| 1549 | // TODO |
| 1550 | UNIMPLEMENTED(); |
| 1551 | return NULL; |
| 1552 | } |
| 1553 | |
daniel@transgaming.com | 1d6aff2 | 2012-11-28 19:30:42 +0000 | [diff] [blame] | 1554 | } |