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