Geoff Lang | 6a1e6b9 | 2014-11-06 10:42:45 -0500 | [diff] [blame] | 1 | // |
| 2 | // Copyright 2014 The ANGLE Project Authors. All rights reserved. |
| 3 | // Use of this source code is governed by a BSD-style license that can be |
| 4 | // found in the LICENSE file. |
| 5 | // |
| 6 | |
Geoff Lang | da88add | 2014-12-01 10:22:01 -0500 | [diff] [blame] | 7 | // FramebufferD3D.cpp: Implements the DefaultAttachmentD3D and FramebufferD3D classes. |
Geoff Lang | 6a1e6b9 | 2014-11-06 10:42:45 -0500 | [diff] [blame] | 8 | |
Geoff Lang | 2b5420c | 2014-11-19 14:20:15 -0500 | [diff] [blame] | 9 | #include "libANGLE/renderer/d3d/FramebufferD3D.h" |
Jamie Madill | c46f45d | 2015-03-31 13:20:55 -0400 | [diff] [blame^] | 10 | |
Geoff Lang | bce529e | 2014-12-01 12:48:41 -0500 | [diff] [blame] | 11 | #include "libANGLE/formatutils.h" |
Geoff Lang | 54bd5a4 | 2014-12-01 12:51:04 -0500 | [diff] [blame] | 12 | #include "libANGLE/Framebuffer.h" |
Geoff Lang | b5d8f23 | 2014-12-04 15:43:01 -0500 | [diff] [blame] | 13 | #include "libANGLE/FramebufferAttachment.h" |
Jamie Madill | c46f45d | 2015-03-31 13:20:55 -0400 | [diff] [blame^] | 14 | #include "libANGLE/Surface.h" |
| 15 | #include "libANGLE/renderer/d3d/RendererD3D.h" |
| 16 | #include "libANGLE/renderer/d3d/RenderbufferD3D.h" |
| 17 | #include "libANGLE/renderer/d3d/RenderTargetD3D.h" |
| 18 | #include "libANGLE/renderer/d3d/SurfaceD3D.h" |
| 19 | #include "libANGLE/renderer/d3d/SwapChainD3D.h" |
| 20 | #include "libANGLE/renderer/d3d/TextureD3D.h" |
Geoff Lang | 6a1e6b9 | 2014-11-06 10:42:45 -0500 | [diff] [blame] | 21 | |
| 22 | namespace rx |
| 23 | { |
| 24 | |
Jamie Madill | f75ab35 | 2015-03-16 10:46:52 -0400 | [diff] [blame] | 25 | namespace |
| 26 | { |
| 27 | |
| 28 | ClearParameters GetClearParameters(const gl::State &state, GLbitfield mask) |
| 29 | { |
| 30 | ClearParameters clearParams; |
| 31 | memset(&clearParams, 0, sizeof(ClearParameters)); |
| 32 | |
| 33 | const auto &blendState = state.getBlendState(); |
| 34 | |
| 35 | for (unsigned int i = 0; i < ArraySize(clearParams.clearColor); i++) |
| 36 | { |
| 37 | clearParams.clearColor[i] = false; |
| 38 | } |
| 39 | clearParams.colorFClearValue = state.getColorClearValue(); |
| 40 | clearParams.colorClearType = GL_FLOAT; |
| 41 | clearParams.colorMaskRed = blendState.colorMaskRed; |
| 42 | clearParams.colorMaskGreen = blendState.colorMaskGreen; |
| 43 | clearParams.colorMaskBlue = blendState.colorMaskBlue; |
| 44 | clearParams.colorMaskAlpha = blendState.colorMaskAlpha; |
| 45 | clearParams.clearDepth = false; |
| 46 | clearParams.depthClearValue = state.getDepthClearValue(); |
| 47 | clearParams.clearStencil = false; |
| 48 | clearParams.stencilClearValue = state.getStencilClearValue(); |
| 49 | clearParams.stencilWriteMask = state.getDepthStencilState().stencilWritemask; |
| 50 | clearParams.scissorEnabled = state.isScissorTestEnabled(); |
| 51 | clearParams.scissor = state.getScissor(); |
| 52 | |
| 53 | const gl::Framebuffer *framebufferObject = state.getDrawFramebuffer(); |
| 54 | if (mask & GL_COLOR_BUFFER_BIT) |
| 55 | { |
| 56 | if (framebufferObject->hasEnabledColorAttachment()) |
| 57 | { |
| 58 | for (unsigned int i = 0; i < ArraySize(clearParams.clearColor); i++) |
| 59 | { |
| 60 | clearParams.clearColor[i] = true; |
| 61 | } |
| 62 | } |
| 63 | } |
| 64 | |
| 65 | if (mask & GL_DEPTH_BUFFER_BIT) |
| 66 | { |
| 67 | if (state.getDepthStencilState().depthMask && framebufferObject->getDepthbuffer() != NULL) |
| 68 | { |
| 69 | clearParams.clearDepth = true; |
| 70 | } |
| 71 | } |
| 72 | |
| 73 | if (mask & GL_STENCIL_BUFFER_BIT) |
| 74 | { |
| 75 | if (framebufferObject->getStencilbuffer() != NULL && |
| 76 | framebufferObject->getStencilbuffer()->getStencilSize() > 0) |
| 77 | { |
| 78 | clearParams.clearStencil = true; |
| 79 | } |
| 80 | } |
| 81 | |
| 82 | return clearParams; |
| 83 | } |
| 84 | |
| 85 | } |
| 86 | |
Geoff Lang | c2e75af | 2015-01-05 14:26:24 -0500 | [diff] [blame] | 87 | DefaultAttachmentD3D::DefaultAttachmentD3D(RenderTargetD3D *renderTarget) |
Geoff Lang | 6a1e6b9 | 2014-11-06 10:42:45 -0500 | [diff] [blame] | 88 | : mRenderTarget(renderTarget) |
| 89 | { |
| 90 | ASSERT(mRenderTarget); |
| 91 | } |
| 92 | |
| 93 | DefaultAttachmentD3D::~DefaultAttachmentD3D() |
| 94 | { |
| 95 | SafeDelete(mRenderTarget); |
| 96 | } |
| 97 | |
| 98 | DefaultAttachmentD3D *DefaultAttachmentD3D::makeDefaultAttachmentD3D(DefaultAttachmentImpl* impl) |
| 99 | { |
| 100 | ASSERT(HAS_DYNAMIC_TYPE(DefaultAttachmentD3D*, impl)); |
| 101 | return static_cast<DefaultAttachmentD3D*>(impl); |
| 102 | } |
| 103 | |
| 104 | GLsizei DefaultAttachmentD3D::getWidth() const |
| 105 | { |
| 106 | return mRenderTarget->getWidth(); |
| 107 | } |
| 108 | |
| 109 | GLsizei DefaultAttachmentD3D::getHeight() const |
| 110 | { |
| 111 | return mRenderTarget->getHeight(); |
| 112 | } |
| 113 | |
| 114 | GLenum DefaultAttachmentD3D::getInternalFormat() const |
| 115 | { |
| 116 | return mRenderTarget->getInternalFormat(); |
| 117 | } |
| 118 | |
Geoff Lang | 6a1e6b9 | 2014-11-06 10:42:45 -0500 | [diff] [blame] | 119 | GLsizei DefaultAttachmentD3D::getSamples() const |
| 120 | { |
| 121 | return mRenderTarget->getSamples(); |
| 122 | } |
| 123 | |
Geoff Lang | c2e75af | 2015-01-05 14:26:24 -0500 | [diff] [blame] | 124 | RenderTargetD3D *DefaultAttachmentD3D::getRenderTarget() const |
Geoff Lang | 6a1e6b9 | 2014-11-06 10:42:45 -0500 | [diff] [blame] | 125 | { |
| 126 | return mRenderTarget; |
| 127 | } |
| 128 | |
Jamie Madill | d1405e5 | 2015-03-05 15:41:39 -0500 | [diff] [blame] | 129 | FramebufferD3D::FramebufferD3D(const gl::Framebuffer::Data &data, RendererD3D *renderer) |
| 130 | : FramebufferImpl(data), |
| 131 | mRenderer(renderer), |
Jamie Madill | 85a1804 | 2015-03-05 15:41:41 -0500 | [diff] [blame] | 132 | mColorAttachmentsForRender(mData.mColorAttachments.size(), nullptr), |
| 133 | mInvalidateColorAttachmentCache(true) |
Geoff Lang | da88add | 2014-12-01 10:22:01 -0500 | [diff] [blame] | 134 | { |
| 135 | ASSERT(mRenderer != nullptr); |
| 136 | } |
| 137 | |
| 138 | FramebufferD3D::~FramebufferD3D() |
| 139 | { |
| 140 | } |
| 141 | |
Jamie Madill | 7147f01 | 2015-03-05 15:41:40 -0500 | [diff] [blame] | 142 | void FramebufferD3D::setColorAttachment(size_t, const gl::FramebufferAttachment *) |
Geoff Lang | 9dd9580 | 2014-12-01 11:12:59 -0500 | [diff] [blame] | 143 | { |
Jamie Madill | 85a1804 | 2015-03-05 15:41:41 -0500 | [diff] [blame] | 144 | mInvalidateColorAttachmentCache = true; |
Geoff Lang | 9dd9580 | 2014-12-01 11:12:59 -0500 | [diff] [blame] | 145 | } |
| 146 | |
Jamie Madill | f90353e | 2015-03-05 19:37:58 -0500 | [diff] [blame] | 147 | void FramebufferD3D::setDepthAttachment(const gl::FramebufferAttachment *) |
Geoff Lang | 9dd9580 | 2014-12-01 11:12:59 -0500 | [diff] [blame] | 148 | { |
| 149 | } |
| 150 | |
Jamie Madill | 7147f01 | 2015-03-05 15:41:40 -0500 | [diff] [blame] | 151 | void FramebufferD3D::setStencilAttachment(const gl::FramebufferAttachment *) |
Geoff Lang | 9dd9580 | 2014-12-01 11:12:59 -0500 | [diff] [blame] | 152 | { |
| 153 | } |
| 154 | |
Jamie Madill | 7147f01 | 2015-03-05 15:41:40 -0500 | [diff] [blame] | 155 | void FramebufferD3D::setDepthStencilAttachment(const gl::FramebufferAttachment *) |
Geoff Lang | 9dd9580 | 2014-12-01 11:12:59 -0500 | [diff] [blame] | 156 | { |
| 157 | } |
| 158 | |
Jamie Madill | 7147f01 | 2015-03-05 15:41:40 -0500 | [diff] [blame] | 159 | void FramebufferD3D::setDrawBuffers(size_t, const GLenum *) |
Geoff Lang | 9dd9580 | 2014-12-01 11:12:59 -0500 | [diff] [blame] | 160 | { |
Jamie Madill | 85a1804 | 2015-03-05 15:41:41 -0500 | [diff] [blame] | 161 | mInvalidateColorAttachmentCache = true; |
Geoff Lang | 9dd9580 | 2014-12-01 11:12:59 -0500 | [diff] [blame] | 162 | } |
| 163 | |
Jamie Madill | 7147f01 | 2015-03-05 15:41:40 -0500 | [diff] [blame] | 164 | void FramebufferD3D::setReadBuffer(GLenum) |
Geoff Lang | 9dd9580 | 2014-12-01 11:12:59 -0500 | [diff] [blame] | 165 | { |
| 166 | } |
| 167 | |
Geoff Lang | 1ea584c | 2015-03-26 21:08:33 +0000 | [diff] [blame] | 168 | gl::Error FramebufferD3D::invalidate(size_t, const GLenum *) |
| 169 | { |
| 170 | // No-op in D3D |
| 171 | return gl::Error(GL_NO_ERROR); |
| 172 | } |
| 173 | |
| 174 | gl::Error FramebufferD3D::invalidateSub(size_t, const GLenum *, const gl::Rectangle &) |
| 175 | { |
| 176 | // No-op in D3D |
| 177 | return gl::Error(GL_NO_ERROR); |
| 178 | } |
| 179 | |
Jamie Madill | d1f5ef2 | 2015-04-01 14:17:06 -0400 | [diff] [blame] | 180 | gl::Error FramebufferD3D::clear(const gl::Data &data, GLbitfield mask) |
Geoff Lang | b04dc82 | 2014-12-01 12:02:02 -0500 | [diff] [blame] | 181 | { |
Jamie Madill | d1f5ef2 | 2015-04-01 14:17:06 -0400 | [diff] [blame] | 182 | const gl::State &state = *data.state; |
Jamie Madill | f75ab35 | 2015-03-16 10:46:52 -0400 | [diff] [blame] | 183 | ClearParameters clearParams = GetClearParameters(state, mask); |
Geoff Lang | b04dc82 | 2014-12-01 12:02:02 -0500 | [diff] [blame] | 184 | return clear(state, clearParams); |
| 185 | } |
| 186 | |
| 187 | gl::Error FramebufferD3D::clearBufferfv(const gl::State &state, GLenum buffer, GLint drawbuffer, const GLfloat *values) |
| 188 | { |
| 189 | // glClearBufferfv can be called to clear the color buffer or depth buffer |
Jamie Madill | f75ab35 | 2015-03-16 10:46:52 -0400 | [diff] [blame] | 190 | ClearParameters clearParams = GetClearParameters(state, 0); |
Geoff Lang | b04dc82 | 2014-12-01 12:02:02 -0500 | [diff] [blame] | 191 | |
| 192 | if (buffer == GL_COLOR) |
| 193 | { |
| 194 | for (unsigned int i = 0; i < ArraySize(clearParams.clearColor); i++) |
| 195 | { |
| 196 | clearParams.clearColor[i] = (drawbuffer == static_cast<int>(i)); |
| 197 | } |
| 198 | clearParams.colorFClearValue = gl::ColorF(values[0], values[1], values[2], values[3]); |
| 199 | clearParams.colorClearType = GL_FLOAT; |
| 200 | } |
| 201 | |
| 202 | if (buffer == GL_DEPTH) |
| 203 | { |
| 204 | clearParams.clearDepth = true; |
| 205 | clearParams.depthClearValue = values[0]; |
| 206 | } |
| 207 | |
| 208 | return clear(state, clearParams); |
| 209 | } |
| 210 | |
| 211 | gl::Error FramebufferD3D::clearBufferuiv(const gl::State &state, GLenum buffer, GLint drawbuffer, const GLuint *values) |
| 212 | { |
| 213 | // glClearBufferuiv can only be called to clear a color buffer |
Jamie Madill | f75ab35 | 2015-03-16 10:46:52 -0400 | [diff] [blame] | 214 | ClearParameters clearParams = GetClearParameters(state, 0); |
Geoff Lang | b04dc82 | 2014-12-01 12:02:02 -0500 | [diff] [blame] | 215 | for (unsigned int i = 0; i < ArraySize(clearParams.clearColor); i++) |
| 216 | { |
| 217 | clearParams.clearColor[i] = (drawbuffer == static_cast<int>(i)); |
| 218 | } |
| 219 | clearParams.colorUIClearValue = gl::ColorUI(values[0], values[1], values[2], values[3]); |
| 220 | clearParams.colorClearType = GL_UNSIGNED_INT; |
| 221 | |
| 222 | return clear(state, clearParams); |
| 223 | } |
| 224 | |
| 225 | gl::Error FramebufferD3D::clearBufferiv(const gl::State &state, GLenum buffer, GLint drawbuffer, const GLint *values) |
| 226 | { |
| 227 | // glClearBufferiv can be called to clear the color buffer or stencil buffer |
Jamie Madill | f75ab35 | 2015-03-16 10:46:52 -0400 | [diff] [blame] | 228 | ClearParameters clearParams = GetClearParameters(state, 0); |
Geoff Lang | b04dc82 | 2014-12-01 12:02:02 -0500 | [diff] [blame] | 229 | |
| 230 | if (buffer == GL_COLOR) |
| 231 | { |
| 232 | for (unsigned int i = 0; i < ArraySize(clearParams.clearColor); i++) |
| 233 | { |
| 234 | clearParams.clearColor[i] = (drawbuffer == static_cast<int>(i)); |
| 235 | } |
| 236 | clearParams.colorIClearValue = gl::ColorI(values[0], values[1], values[2], values[3]); |
| 237 | clearParams.colorClearType = GL_INT; |
| 238 | } |
| 239 | |
| 240 | if (buffer == GL_STENCIL) |
| 241 | { |
| 242 | clearParams.clearStencil = true; |
| 243 | clearParams.stencilClearValue = values[1]; |
| 244 | } |
| 245 | |
| 246 | return clear(state, clearParams); |
| 247 | } |
| 248 | |
| 249 | gl::Error FramebufferD3D::clearBufferfi(const gl::State &state, GLenum buffer, GLint drawbuffer, GLfloat depth, GLint stencil) |
| 250 | { |
| 251 | // glClearBufferfi can only be called to clear a depth stencil buffer |
Jamie Madill | f75ab35 | 2015-03-16 10:46:52 -0400 | [diff] [blame] | 252 | ClearParameters clearParams = GetClearParameters(state, 0); |
Geoff Lang | b04dc82 | 2014-12-01 12:02:02 -0500 | [diff] [blame] | 253 | clearParams.clearDepth = true; |
| 254 | clearParams.depthClearValue = depth; |
| 255 | clearParams.clearStencil = true; |
| 256 | clearParams.stencilClearValue = stencil; |
| 257 | |
| 258 | return clear(state, clearParams); |
| 259 | } |
| 260 | |
Geoff Lang | bce529e | 2014-12-01 12:48:41 -0500 | [diff] [blame] | 261 | GLenum FramebufferD3D::getImplementationColorReadFormat() const |
| 262 | { |
Jamie Madill | 7147f01 | 2015-03-05 15:41:40 -0500 | [diff] [blame] | 263 | const gl::FramebufferAttachment *readAttachment = mData.getReadAttachment(); |
Geoff Lang | bce529e | 2014-12-01 12:48:41 -0500 | [diff] [blame] | 264 | |
Jamie Madill | b885e57 | 2015-02-03 16:16:04 -0500 | [diff] [blame] | 265 | if (readAttachment == nullptr) |
Geoff Lang | bce529e | 2014-12-01 12:48:41 -0500 | [diff] [blame] | 266 | { |
| 267 | return GL_NONE; |
| 268 | } |
| 269 | |
Geoff Lang | c2e75af | 2015-01-05 14:26:24 -0500 | [diff] [blame] | 270 | RenderTargetD3D *attachmentRenderTarget = NULL; |
Jamie Madill | b885e57 | 2015-02-03 16:16:04 -0500 | [diff] [blame] | 271 | gl::Error error = GetAttachmentRenderTarget(readAttachment, &attachmentRenderTarget); |
Geoff Lang | d8a2258 | 2014-12-17 15:28:23 -0500 | [diff] [blame] | 272 | if (error.isError()) |
| 273 | { |
| 274 | return GL_NONE; |
| 275 | } |
Geoff Lang | bce529e | 2014-12-01 12:48:41 -0500 | [diff] [blame] | 276 | |
Geoff Lang | d8a2258 | 2014-12-17 15:28:23 -0500 | [diff] [blame] | 277 | GLenum implementationFormat = getRenderTargetImplementationFormat(attachmentRenderTarget); |
| 278 | const gl::InternalFormat &implementationFormatInfo = gl::GetInternalFormatInfo(implementationFormat); |
| 279 | |
| 280 | return implementationFormatInfo.format; |
Geoff Lang | bce529e | 2014-12-01 12:48:41 -0500 | [diff] [blame] | 281 | } |
| 282 | |
| 283 | GLenum FramebufferD3D::getImplementationColorReadType() const |
| 284 | { |
Jamie Madill | 7147f01 | 2015-03-05 15:41:40 -0500 | [diff] [blame] | 285 | const gl::FramebufferAttachment *readAttachment = mData.getReadAttachment(); |
Geoff Lang | bce529e | 2014-12-01 12:48:41 -0500 | [diff] [blame] | 286 | |
Jamie Madill | b885e57 | 2015-02-03 16:16:04 -0500 | [diff] [blame] | 287 | if (readAttachment == nullptr) |
Geoff Lang | bce529e | 2014-12-01 12:48:41 -0500 | [diff] [blame] | 288 | { |
| 289 | return GL_NONE; |
| 290 | } |
| 291 | |
Geoff Lang | c2e75af | 2015-01-05 14:26:24 -0500 | [diff] [blame] | 292 | RenderTargetD3D *attachmentRenderTarget = NULL; |
Jamie Madill | b885e57 | 2015-02-03 16:16:04 -0500 | [diff] [blame] | 293 | gl::Error error = GetAttachmentRenderTarget(readAttachment, &attachmentRenderTarget); |
Geoff Lang | d8a2258 | 2014-12-17 15:28:23 -0500 | [diff] [blame] | 294 | if (error.isError()) |
| 295 | { |
| 296 | return GL_NONE; |
| 297 | } |
Geoff Lang | bce529e | 2014-12-01 12:48:41 -0500 | [diff] [blame] | 298 | |
Geoff Lang | d8a2258 | 2014-12-17 15:28:23 -0500 | [diff] [blame] | 299 | GLenum implementationFormat = getRenderTargetImplementationFormat(attachmentRenderTarget); |
| 300 | const gl::InternalFormat &implementationFormatInfo = gl::GetInternalFormatInfo(implementationFormat); |
| 301 | |
| 302 | return implementationFormatInfo.type; |
Geoff Lang | bce529e | 2014-12-01 12:48:41 -0500 | [diff] [blame] | 303 | } |
| 304 | |
| 305 | gl::Error FramebufferD3D::readPixels(const gl::State &state, const gl::Rectangle &area, GLenum format, GLenum type, GLvoid *pixels) const |
| 306 | { |
Jamie Madill | 87de362 | 2015-03-16 10:41:44 -0400 | [diff] [blame] | 307 | const gl::PixelPackState &packState = state.getPackState(); |
| 308 | |
| 309 | if (packState.rowLength != 0 || packState.skipRows != 0 || packState.skipPixels != 0) |
| 310 | { |
| 311 | UNIMPLEMENTED(); |
| 312 | return gl::Error(GL_INVALID_OPERATION, "invalid pixel store parameters in readPixels"); |
| 313 | } |
| 314 | |
Geoff Lang | bce529e | 2014-12-01 12:48:41 -0500 | [diff] [blame] | 315 | GLenum sizedInternalFormat = gl::GetSizedInternalFormat(format, type); |
| 316 | const gl::InternalFormat &sizedFormatInfo = gl::GetInternalFormatInfo(sizedInternalFormat); |
Jamie Madill | 87de362 | 2015-03-16 10:41:44 -0400 | [diff] [blame] | 317 | GLuint outputPitch = sizedFormatInfo.computeRowPitch(type, area.width, packState.alignment, 0); |
Geoff Lang | bce529e | 2014-12-01 12:48:41 -0500 | [diff] [blame] | 318 | |
Jamie Madill | 87de362 | 2015-03-16 10:41:44 -0400 | [diff] [blame] | 319 | return readPixels(area, format, type, outputPitch, packState, reinterpret_cast<uint8_t*>(pixels)); |
Geoff Lang | bce529e | 2014-12-01 12:48:41 -0500 | [diff] [blame] | 320 | } |
| 321 | |
Geoff Lang | 54bd5a4 | 2014-12-01 12:51:04 -0500 | [diff] [blame] | 322 | gl::Error FramebufferD3D::blit(const gl::State &state, const gl::Rectangle &sourceArea, const gl::Rectangle &destArea, |
| 323 | GLbitfield mask, GLenum filter, const gl::Framebuffer *sourceFramebuffer) |
| 324 | { |
| 325 | bool blitRenderTarget = false; |
| 326 | if ((mask & GL_COLOR_BUFFER_BIT) && |
| 327 | sourceFramebuffer->getReadColorbuffer() != nullptr && |
Jamie Madill | 7147f01 | 2015-03-05 15:41:40 -0500 | [diff] [blame] | 328 | mData.getFirstColorAttachment() != nullptr) |
Geoff Lang | 54bd5a4 | 2014-12-01 12:51:04 -0500 | [diff] [blame] | 329 | { |
| 330 | blitRenderTarget = true; |
| 331 | } |
| 332 | |
| 333 | bool blitStencil = false; |
| 334 | if ((mask & GL_STENCIL_BUFFER_BIT) && |
| 335 | sourceFramebuffer->getStencilbuffer() != nullptr && |
Jamie Madill | 7147f01 | 2015-03-05 15:41:40 -0500 | [diff] [blame] | 336 | mData.mStencilAttachment != nullptr) |
Geoff Lang | 54bd5a4 | 2014-12-01 12:51:04 -0500 | [diff] [blame] | 337 | { |
| 338 | blitStencil = true; |
| 339 | } |
| 340 | |
| 341 | bool blitDepth = false; |
| 342 | if ((mask & GL_DEPTH_BUFFER_BIT) && |
| 343 | sourceFramebuffer->getDepthbuffer() != nullptr && |
Jamie Madill | 7147f01 | 2015-03-05 15:41:40 -0500 | [diff] [blame] | 344 | mData.mDepthAttachment != nullptr) |
Geoff Lang | 54bd5a4 | 2014-12-01 12:51:04 -0500 | [diff] [blame] | 345 | { |
| 346 | blitDepth = true; |
| 347 | } |
| 348 | |
| 349 | if (blitRenderTarget || blitDepth || blitStencil) |
| 350 | { |
| 351 | const gl::Rectangle *scissor = state.isScissorTestEnabled() ? &state.getScissor() : NULL; |
| 352 | gl::Error error = blit(sourceArea, destArea, scissor, blitRenderTarget, blitDepth, blitStencil, |
| 353 | filter, sourceFramebuffer); |
| 354 | if (error.isError()) |
| 355 | { |
| 356 | return error; |
| 357 | } |
| 358 | } |
| 359 | |
| 360 | return gl::Error(GL_NO_ERROR); |
| 361 | } |
| 362 | |
Geoff Lang | 748f74e | 2014-12-01 11:25:34 -0500 | [diff] [blame] | 363 | GLenum FramebufferD3D::checkStatus() const |
| 364 | { |
| 365 | // D3D11 does not allow for overlapping RenderTargetViews, so ensure uniqueness |
Jamie Madill | 7147f01 | 2015-03-05 15:41:40 -0500 | [diff] [blame] | 366 | for (size_t colorAttachment = 0; colorAttachment < mData.mColorAttachments.size(); colorAttachment++) |
Geoff Lang | 748f74e | 2014-12-01 11:25:34 -0500 | [diff] [blame] | 367 | { |
Jamie Madill | 7147f01 | 2015-03-05 15:41:40 -0500 | [diff] [blame] | 368 | const gl::FramebufferAttachment *attachment = mData.mColorAttachments[colorAttachment]; |
Geoff Lang | 748f74e | 2014-12-01 11:25:34 -0500 | [diff] [blame] | 369 | if (attachment != nullptr) |
| 370 | { |
| 371 | for (size_t prevColorAttachment = 0; prevColorAttachment < colorAttachment; prevColorAttachment++) |
| 372 | { |
Jamie Madill | 7147f01 | 2015-03-05 15:41:40 -0500 | [diff] [blame] | 373 | const gl::FramebufferAttachment *prevAttachment = mData.mColorAttachments[prevColorAttachment]; |
Geoff Lang | 748f74e | 2014-12-01 11:25:34 -0500 | [diff] [blame] | 374 | if (prevAttachment != nullptr && |
| 375 | (attachment->id() == prevAttachment->id() && |
| 376 | attachment->type() == prevAttachment->type())) |
| 377 | { |
| 378 | return GL_FRAMEBUFFER_UNSUPPORTED; |
| 379 | } |
| 380 | } |
| 381 | } |
| 382 | } |
| 383 | |
| 384 | return GL_FRAMEBUFFER_COMPLETE; |
| 385 | } |
| 386 | |
Jamie Madill | 7147f01 | 2015-03-05 15:41:40 -0500 | [diff] [blame] | 387 | const gl::AttachmentList &FramebufferD3D::getColorAttachmentsForRender(const Workarounds &workarounds) const |
| 388 | { |
Jamie Madill | 85a1804 | 2015-03-05 15:41:41 -0500 | [diff] [blame] | 389 | if (!workarounds.mrtPerfWorkaround) |
| 390 | { |
| 391 | return mData.mColorAttachments; |
| 392 | } |
| 393 | |
| 394 | if (!mInvalidateColorAttachmentCache) |
| 395 | { |
| 396 | return mColorAttachmentsForRender; |
| 397 | } |
| 398 | |
Jamie Madill | 7147f01 | 2015-03-05 15:41:40 -0500 | [diff] [blame] | 399 | // Does not actually free memory |
| 400 | mColorAttachmentsForRender.clear(); |
| 401 | |
| 402 | for (size_t attachmentIndex = 0; attachmentIndex < mData.mColorAttachments.size(); ++attachmentIndex) |
| 403 | { |
| 404 | GLenum drawBufferState = mData.mDrawBufferStates[attachmentIndex]; |
| 405 | gl::FramebufferAttachment *colorAttachment = mData.mColorAttachments[attachmentIndex]; |
| 406 | |
| 407 | if (colorAttachment != nullptr && drawBufferState != GL_NONE) |
| 408 | { |
| 409 | ASSERT(drawBufferState == GL_BACK || drawBufferState == (GL_COLOR_ATTACHMENT0_EXT + attachmentIndex)); |
| 410 | mColorAttachmentsForRender.push_back(colorAttachment); |
| 411 | } |
Jamie Madill | 7147f01 | 2015-03-05 15:41:40 -0500 | [diff] [blame] | 412 | } |
| 413 | |
Jamie Madill | 85a1804 | 2015-03-05 15:41:41 -0500 | [diff] [blame] | 414 | mInvalidateColorAttachmentCache = false; |
Jamie Madill | 7147f01 | 2015-03-05 15:41:40 -0500 | [diff] [blame] | 415 | return mColorAttachmentsForRender; |
| 416 | } |
| 417 | |
Geoff Lang | c2e75af | 2015-01-05 14:26:24 -0500 | [diff] [blame] | 418 | gl::Error GetAttachmentRenderTarget(const gl::FramebufferAttachment *attachment, RenderTargetD3D **outRT) |
Geoff Lang | b5d8f23 | 2014-12-04 15:43:01 -0500 | [diff] [blame] | 419 | { |
| 420 | if (attachment->type() == GL_TEXTURE) |
| 421 | { |
| 422 | gl::Texture *texture = attachment->getTexture(); |
| 423 | ASSERT(texture); |
Jamie Madill | 9236b41 | 2015-02-02 16:51:52 -0500 | [diff] [blame] | 424 | TextureD3D *textureD3D = GetImplAs<TextureD3D>(texture); |
Geoff Lang | b5d8f23 | 2014-12-04 15:43:01 -0500 | [diff] [blame] | 425 | const gl::ImageIndex *index = attachment->getTextureImageIndex(); |
| 426 | ASSERT(index); |
| 427 | return textureD3D->getRenderTarget(*index, outRT); |
| 428 | } |
| 429 | else if (attachment->type() == GL_RENDERBUFFER) |
| 430 | { |
| 431 | gl::Renderbuffer *renderbuffer = attachment->getRenderbuffer(); |
| 432 | ASSERT(renderbuffer); |
| 433 | RenderbufferD3D *renderbufferD3D = RenderbufferD3D::makeRenderbufferD3D(renderbuffer->getImplementation()); |
| 434 | *outRT = renderbufferD3D->getRenderTarget(); |
| 435 | return gl::Error(GL_NO_ERROR); |
| 436 | } |
| 437 | else if (attachment->type() == GL_FRAMEBUFFER_DEFAULT) |
| 438 | { |
| 439 | const gl::DefaultAttachment *defaultAttachment = static_cast<const gl::DefaultAttachment *>(attachment); |
Jamie Madill | c46f45d | 2015-03-31 13:20:55 -0400 | [diff] [blame^] | 440 | const egl::Surface *surface = defaultAttachment->getSurface(); |
| 441 | ASSERT(surface); |
| 442 | const SurfaceD3D *surfaceD3D = GetImplAs<SurfaceD3D>(surface); |
| 443 | ASSERT(surfaceD3D); |
Geoff Lang | b5d8f23 | 2014-12-04 15:43:01 -0500 | [diff] [blame] | 444 | |
Jamie Madill | c46f45d | 2015-03-31 13:20:55 -0400 | [diff] [blame^] | 445 | if (defaultAttachment->getBinding() == GL_BACK) |
| 446 | { |
| 447 | *outRT = surfaceD3D->getSwapChain()->getColorRenderTarget(); |
| 448 | } |
| 449 | else |
| 450 | { |
| 451 | *outRT = surfaceD3D->getSwapChain()->getDepthStencilRenderTarget(); |
| 452 | } |
Geoff Lang | b5d8f23 | 2014-12-04 15:43:01 -0500 | [diff] [blame] | 453 | return gl::Error(GL_NO_ERROR); |
| 454 | } |
| 455 | else |
| 456 | { |
| 457 | UNREACHABLE(); |
| 458 | return gl::Error(GL_INVALID_OPERATION); |
| 459 | } |
| 460 | } |
| 461 | |
| 462 | // Note: RenderTarget serials should ideally be in the RenderTargets themselves. |
| 463 | unsigned int GetAttachmentSerial(const gl::FramebufferAttachment *attachment) |
| 464 | { |
| 465 | if (attachment->type() == GL_TEXTURE) |
| 466 | { |
| 467 | gl::Texture *texture = attachment->getTexture(); |
| 468 | ASSERT(texture); |
Jamie Madill | 9236b41 | 2015-02-02 16:51:52 -0500 | [diff] [blame] | 469 | TextureD3D *textureD3D = GetImplAs<TextureD3D>(texture); |
Geoff Lang | b5d8f23 | 2014-12-04 15:43:01 -0500 | [diff] [blame] | 470 | const gl::ImageIndex *index = attachment->getTextureImageIndex(); |
| 471 | ASSERT(index); |
| 472 | return textureD3D->getRenderTargetSerial(*index); |
| 473 | } |
| 474 | else if (attachment->type() == GL_RENDERBUFFER) |
| 475 | { |
| 476 | gl::Renderbuffer *renderbuffer = attachment->getRenderbuffer(); |
| 477 | ASSERT(renderbuffer); |
| 478 | RenderbufferD3D *renderbufferD3D = RenderbufferD3D::makeRenderbufferD3D(renderbuffer->getImplementation()); |
| 479 | return renderbufferD3D->getRenderTargetSerial(); |
| 480 | } |
| 481 | else if (attachment->type() == GL_FRAMEBUFFER_DEFAULT) |
| 482 | { |
| 483 | const gl::DefaultAttachment *defaultAttachment = static_cast<const gl::DefaultAttachment *>(attachment); |
Jamie Madill | c46f45d | 2015-03-31 13:20:55 -0400 | [diff] [blame^] | 484 | const egl::Surface *surface = defaultAttachment->getSurface(); |
| 485 | ASSERT(surface); |
| 486 | const SurfaceD3D *surfaceD3D = GetImplAs<SurfaceD3D>(surface); |
| 487 | ASSERT(surfaceD3D); |
| 488 | |
| 489 | if (defaultAttachment->getBinding() == GL_BACK) |
| 490 | { |
| 491 | return surfaceD3D->getSwapChain()->getColorRenderTarget()->getSerial(); |
| 492 | } |
| 493 | else |
| 494 | { |
| 495 | return surfaceD3D->getSwapChain()->getDepthStencilRenderTarget()->getSerial(); |
| 496 | } |
Geoff Lang | b5d8f23 | 2014-12-04 15:43:01 -0500 | [diff] [blame] | 497 | } |
| 498 | else |
| 499 | { |
| 500 | UNREACHABLE(); |
| 501 | return 0; |
| 502 | } |
| 503 | } |
| 504 | |
Geoff Lang | 6a1e6b9 | 2014-11-06 10:42:45 -0500 | [diff] [blame] | 505 | } |