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 | |
Geoff Lang | c2e75af | 2015-01-05 14:26:24 -0500 | [diff] [blame] | 21 | DefaultAttachmentD3D::DefaultAttachmentD3D(RenderTargetD3D *renderTarget) |
Geoff Lang | 6a1e6b9 | 2014-11-06 10:42:45 -0500 | [diff] [blame] | 22 | : mRenderTarget(renderTarget) |
| 23 | { |
| 24 | ASSERT(mRenderTarget); |
| 25 | } |
| 26 | |
| 27 | DefaultAttachmentD3D::~DefaultAttachmentD3D() |
| 28 | { |
| 29 | SafeDelete(mRenderTarget); |
| 30 | } |
| 31 | |
| 32 | DefaultAttachmentD3D *DefaultAttachmentD3D::makeDefaultAttachmentD3D(DefaultAttachmentImpl* impl) |
| 33 | { |
| 34 | ASSERT(HAS_DYNAMIC_TYPE(DefaultAttachmentD3D*, impl)); |
| 35 | return static_cast<DefaultAttachmentD3D*>(impl); |
| 36 | } |
| 37 | |
| 38 | GLsizei DefaultAttachmentD3D::getWidth() const |
| 39 | { |
| 40 | return mRenderTarget->getWidth(); |
| 41 | } |
| 42 | |
| 43 | GLsizei DefaultAttachmentD3D::getHeight() const |
| 44 | { |
| 45 | return mRenderTarget->getHeight(); |
| 46 | } |
| 47 | |
| 48 | GLenum DefaultAttachmentD3D::getInternalFormat() const |
| 49 | { |
| 50 | return mRenderTarget->getInternalFormat(); |
| 51 | } |
| 52 | |
Geoff Lang | 6a1e6b9 | 2014-11-06 10:42:45 -0500 | [diff] [blame] | 53 | GLsizei DefaultAttachmentD3D::getSamples() const |
| 54 | { |
| 55 | return mRenderTarget->getSamples(); |
| 56 | } |
| 57 | |
Geoff Lang | c2e75af | 2015-01-05 14:26:24 -0500 | [diff] [blame] | 58 | RenderTargetD3D *DefaultAttachmentD3D::getRenderTarget() const |
Geoff Lang | 6a1e6b9 | 2014-11-06 10:42:45 -0500 | [diff] [blame] | 59 | { |
| 60 | return mRenderTarget; |
| 61 | } |
| 62 | |
Geoff Lang | da88add | 2014-12-01 10:22:01 -0500 | [diff] [blame] | 63 | |
| 64 | FramebufferD3D::FramebufferD3D(RendererD3D *renderer) |
Geoff Lang | 748f74e | 2014-12-01 11:25:34 -0500 | [diff] [blame] | 65 | : mRenderer(renderer), |
Geoff Lang | b04dc82 | 2014-12-01 12:02:02 -0500 | [diff] [blame] | 66 | mColorBuffers(renderer->getRendererCaps().maxColorAttachments), |
| 67 | mDepthbuffer(nullptr), |
| 68 | mStencilbuffer(nullptr), |
Geoff Lang | bce529e | 2014-12-01 12:48:41 -0500 | [diff] [blame] | 69 | mDrawBuffers(renderer->getRendererCaps().maxDrawBuffers), |
| 70 | mReadBuffer(GL_COLOR_ATTACHMENT0) |
Geoff Lang | da88add | 2014-12-01 10:22:01 -0500 | [diff] [blame] | 71 | { |
| 72 | ASSERT(mRenderer != nullptr); |
Geoff Lang | 748f74e | 2014-12-01 11:25:34 -0500 | [diff] [blame] | 73 | |
| 74 | std::fill(mColorBuffers.begin(), mColorBuffers.end(), nullptr); |
Geoff Lang | b04dc82 | 2014-12-01 12:02:02 -0500 | [diff] [blame] | 75 | |
| 76 | ASSERT(mDrawBuffers.size() > 0); |
| 77 | mDrawBuffers[0] = GL_COLOR_ATTACHMENT0; |
| 78 | std::fill(mDrawBuffers.begin() + 1, mDrawBuffers.end(), GL_NONE); |
Geoff Lang | da88add | 2014-12-01 10:22:01 -0500 | [diff] [blame] | 79 | } |
| 80 | |
| 81 | FramebufferD3D::~FramebufferD3D() |
| 82 | { |
| 83 | } |
| 84 | |
Geoff Lang | 9dd9580 | 2014-12-01 11:12:59 -0500 | [diff] [blame] | 85 | void FramebufferD3D::setColorAttachment(size_t index, const gl::FramebufferAttachment *attachment) |
| 86 | { |
Geoff Lang | 748f74e | 2014-12-01 11:25:34 -0500 | [diff] [blame] | 87 | ASSERT(index < mColorBuffers.size()); |
| 88 | mColorBuffers[index] = attachment; |
Geoff Lang | 9dd9580 | 2014-12-01 11:12:59 -0500 | [diff] [blame] | 89 | } |
| 90 | |
| 91 | void FramebufferD3D::setDepthttachment(const gl::FramebufferAttachment *attachment) |
| 92 | { |
Geoff Lang | b04dc82 | 2014-12-01 12:02:02 -0500 | [diff] [blame] | 93 | mDepthbuffer = attachment; |
Geoff Lang | 9dd9580 | 2014-12-01 11:12:59 -0500 | [diff] [blame] | 94 | } |
| 95 | |
| 96 | void FramebufferD3D::setStencilAttachment(const gl::FramebufferAttachment *attachment) |
| 97 | { |
Geoff Lang | b04dc82 | 2014-12-01 12:02:02 -0500 | [diff] [blame] | 98 | mStencilbuffer = attachment; |
Geoff Lang | 9dd9580 | 2014-12-01 11:12:59 -0500 | [diff] [blame] | 99 | } |
| 100 | |
| 101 | void FramebufferD3D::setDepthStencilAttachment(const gl::FramebufferAttachment *attachment) |
| 102 | { |
Geoff Lang | b04dc82 | 2014-12-01 12:02:02 -0500 | [diff] [blame] | 103 | mDepthbuffer = attachment; |
| 104 | mStencilbuffer = attachment; |
Geoff Lang | 9dd9580 | 2014-12-01 11:12:59 -0500 | [diff] [blame] | 105 | } |
| 106 | |
| 107 | void FramebufferD3D::setDrawBuffers(size_t count, const GLenum *buffers) |
| 108 | { |
Geoff Lang | b04dc82 | 2014-12-01 12:02:02 -0500 | [diff] [blame] | 109 | std::copy_n(buffers, count, mDrawBuffers.begin()); |
| 110 | std::fill(mDrawBuffers.begin() + count, mDrawBuffers.end(), GL_NONE); |
Geoff Lang | 9dd9580 | 2014-12-01 11:12:59 -0500 | [diff] [blame] | 111 | } |
| 112 | |
| 113 | void FramebufferD3D::setReadBuffer(GLenum buffer) |
| 114 | { |
Geoff Lang | bce529e | 2014-12-01 12:48:41 -0500 | [diff] [blame] | 115 | mReadBuffer = buffer; |
Geoff Lang | 9dd9580 | 2014-12-01 11:12:59 -0500 | [diff] [blame] | 116 | } |
| 117 | |
Geoff Lang | 9ad4bda | 2014-12-01 11:03:09 -0500 | [diff] [blame] | 118 | gl::Error FramebufferD3D::invalidate(size_t, const GLenum *) |
| 119 | { |
| 120 | // No-op in D3D |
| 121 | return gl::Error(GL_NO_ERROR); |
| 122 | } |
| 123 | |
| 124 | gl::Error FramebufferD3D::invalidateSub(size_t, const GLenum *, const gl::Rectangle &) |
| 125 | { |
| 126 | // No-op in D3D |
| 127 | return gl::Error(GL_NO_ERROR); |
| 128 | } |
| 129 | |
Geoff Lang | b04dc82 | 2014-12-01 12:02:02 -0500 | [diff] [blame] | 130 | gl::Error FramebufferD3D::clear(const gl::State &state, GLbitfield mask) |
| 131 | { |
| 132 | gl::ClearParameters clearParams = state.getClearParameters(mask); |
| 133 | return clear(state, clearParams); |
| 134 | } |
| 135 | |
| 136 | gl::Error FramebufferD3D::clearBufferfv(const gl::State &state, GLenum buffer, GLint drawbuffer, const GLfloat *values) |
| 137 | { |
| 138 | // glClearBufferfv can be called to clear the color buffer or depth buffer |
| 139 | gl::ClearParameters clearParams = state.getClearParameters(0); |
| 140 | |
| 141 | if (buffer == GL_COLOR) |
| 142 | { |
| 143 | for (unsigned int i = 0; i < ArraySize(clearParams.clearColor); i++) |
| 144 | { |
| 145 | clearParams.clearColor[i] = (drawbuffer == static_cast<int>(i)); |
| 146 | } |
| 147 | clearParams.colorFClearValue = gl::ColorF(values[0], values[1], values[2], values[3]); |
| 148 | clearParams.colorClearType = GL_FLOAT; |
| 149 | } |
| 150 | |
| 151 | if (buffer == GL_DEPTH) |
| 152 | { |
| 153 | clearParams.clearDepth = true; |
| 154 | clearParams.depthClearValue = values[0]; |
| 155 | } |
| 156 | |
| 157 | return clear(state, clearParams); |
| 158 | } |
| 159 | |
| 160 | gl::Error FramebufferD3D::clearBufferuiv(const gl::State &state, GLenum buffer, GLint drawbuffer, const GLuint *values) |
| 161 | { |
| 162 | // glClearBufferuiv can only be called to clear a color buffer |
| 163 | gl::ClearParameters clearParams = state.getClearParameters(0); |
| 164 | for (unsigned int i = 0; i < ArraySize(clearParams.clearColor); i++) |
| 165 | { |
| 166 | clearParams.clearColor[i] = (drawbuffer == static_cast<int>(i)); |
| 167 | } |
| 168 | clearParams.colorUIClearValue = gl::ColorUI(values[0], values[1], values[2], values[3]); |
| 169 | clearParams.colorClearType = GL_UNSIGNED_INT; |
| 170 | |
| 171 | return clear(state, clearParams); |
| 172 | } |
| 173 | |
| 174 | gl::Error FramebufferD3D::clearBufferiv(const gl::State &state, GLenum buffer, GLint drawbuffer, const GLint *values) |
| 175 | { |
| 176 | // glClearBufferiv can be called to clear the color buffer or stencil buffer |
| 177 | gl::ClearParameters clearParams = state.getClearParameters(0); |
| 178 | |
| 179 | if (buffer == GL_COLOR) |
| 180 | { |
| 181 | for (unsigned int i = 0; i < ArraySize(clearParams.clearColor); i++) |
| 182 | { |
| 183 | clearParams.clearColor[i] = (drawbuffer == static_cast<int>(i)); |
| 184 | } |
| 185 | clearParams.colorIClearValue = gl::ColorI(values[0], values[1], values[2], values[3]); |
| 186 | clearParams.colorClearType = GL_INT; |
| 187 | } |
| 188 | |
| 189 | if (buffer == GL_STENCIL) |
| 190 | { |
| 191 | clearParams.clearStencil = true; |
| 192 | clearParams.stencilClearValue = values[1]; |
| 193 | } |
| 194 | |
| 195 | return clear(state, clearParams); |
| 196 | } |
| 197 | |
| 198 | gl::Error FramebufferD3D::clearBufferfi(const gl::State &state, GLenum buffer, GLint drawbuffer, GLfloat depth, GLint stencil) |
| 199 | { |
| 200 | // glClearBufferfi can only be called to clear a depth stencil buffer |
| 201 | gl::ClearParameters clearParams = state.getClearParameters(0); |
| 202 | clearParams.clearDepth = true; |
| 203 | clearParams.depthClearValue = depth; |
| 204 | clearParams.clearStencil = true; |
| 205 | clearParams.stencilClearValue = stencil; |
| 206 | |
| 207 | return clear(state, clearParams); |
| 208 | } |
| 209 | |
Jamie Madill | b885e57 | 2015-02-03 16:16:04 -0500 | [diff] [blame^] | 210 | const gl::FramebufferAttachment *FramebufferD3D::getReadAttachment() const |
| 211 | { |
| 212 | ASSERT(mReadBuffer == GL_BACK || (mReadBuffer >= GL_COLOR_ATTACHMENT0 && mReadBuffer <= GL_COLOR_ATTACHMENT15)); |
| 213 | size_t readIndex = (mReadBuffer == GL_BACK ? 0 : static_cast<size_t>(mReadBuffer - GL_COLOR_ATTACHMENT0)); |
| 214 | ASSERT(readIndex < mColorBuffers.size()); |
| 215 | return mColorBuffers[readIndex]; |
| 216 | } |
| 217 | |
Geoff Lang | bce529e | 2014-12-01 12:48:41 -0500 | [diff] [blame] | 218 | GLenum FramebufferD3D::getImplementationColorReadFormat() const |
| 219 | { |
Jamie Madill | b885e57 | 2015-02-03 16:16:04 -0500 | [diff] [blame^] | 220 | const gl::FramebufferAttachment *readAttachment = getReadAttachment(); |
Geoff Lang | bce529e | 2014-12-01 12:48:41 -0500 | [diff] [blame] | 221 | |
Jamie Madill | b885e57 | 2015-02-03 16:16:04 -0500 | [diff] [blame^] | 222 | if (readAttachment == nullptr) |
Geoff Lang | bce529e | 2014-12-01 12:48:41 -0500 | [diff] [blame] | 223 | { |
| 224 | return GL_NONE; |
| 225 | } |
| 226 | |
Geoff Lang | c2e75af | 2015-01-05 14:26:24 -0500 | [diff] [blame] | 227 | RenderTargetD3D *attachmentRenderTarget = NULL; |
Jamie Madill | b885e57 | 2015-02-03 16:16:04 -0500 | [diff] [blame^] | 228 | gl::Error error = GetAttachmentRenderTarget(readAttachment, &attachmentRenderTarget); |
Geoff Lang | d8a2258 | 2014-12-17 15:28:23 -0500 | [diff] [blame] | 229 | if (error.isError()) |
| 230 | { |
| 231 | return GL_NONE; |
| 232 | } |
Geoff Lang | bce529e | 2014-12-01 12:48:41 -0500 | [diff] [blame] | 233 | |
Geoff Lang | d8a2258 | 2014-12-17 15:28:23 -0500 | [diff] [blame] | 234 | GLenum implementationFormat = getRenderTargetImplementationFormat(attachmentRenderTarget); |
| 235 | const gl::InternalFormat &implementationFormatInfo = gl::GetInternalFormatInfo(implementationFormat); |
| 236 | |
| 237 | return implementationFormatInfo.format; |
Geoff Lang | bce529e | 2014-12-01 12:48:41 -0500 | [diff] [blame] | 238 | } |
| 239 | |
| 240 | GLenum FramebufferD3D::getImplementationColorReadType() const |
| 241 | { |
Jamie Madill | b885e57 | 2015-02-03 16:16:04 -0500 | [diff] [blame^] | 242 | const gl::FramebufferAttachment *readAttachment = getReadAttachment(); |
Geoff Lang | bce529e | 2014-12-01 12:48:41 -0500 | [diff] [blame] | 243 | |
Jamie Madill | b885e57 | 2015-02-03 16:16:04 -0500 | [diff] [blame^] | 244 | if (readAttachment == nullptr) |
Geoff Lang | bce529e | 2014-12-01 12:48:41 -0500 | [diff] [blame] | 245 | { |
| 246 | return GL_NONE; |
| 247 | } |
| 248 | |
Geoff Lang | c2e75af | 2015-01-05 14:26:24 -0500 | [diff] [blame] | 249 | RenderTargetD3D *attachmentRenderTarget = NULL; |
Jamie Madill | b885e57 | 2015-02-03 16:16:04 -0500 | [diff] [blame^] | 250 | gl::Error error = GetAttachmentRenderTarget(readAttachment, &attachmentRenderTarget); |
Geoff Lang | d8a2258 | 2014-12-17 15:28:23 -0500 | [diff] [blame] | 251 | if (error.isError()) |
| 252 | { |
| 253 | return GL_NONE; |
| 254 | } |
Geoff Lang | bce529e | 2014-12-01 12:48:41 -0500 | [diff] [blame] | 255 | |
Geoff Lang | d8a2258 | 2014-12-17 15:28:23 -0500 | [diff] [blame] | 256 | GLenum implementationFormat = getRenderTargetImplementationFormat(attachmentRenderTarget); |
| 257 | const gl::InternalFormat &implementationFormatInfo = gl::GetInternalFormatInfo(implementationFormat); |
| 258 | |
| 259 | return implementationFormatInfo.type; |
Geoff Lang | bce529e | 2014-12-01 12:48:41 -0500 | [diff] [blame] | 260 | } |
| 261 | |
| 262 | gl::Error FramebufferD3D::readPixels(const gl::State &state, const gl::Rectangle &area, GLenum format, GLenum type, GLvoid *pixels) const |
| 263 | { |
| 264 | GLenum sizedInternalFormat = gl::GetSizedInternalFormat(format, type); |
| 265 | const gl::InternalFormat &sizedFormatInfo = gl::GetInternalFormatInfo(sizedInternalFormat); |
Minmin Gong | b8aee3b | 2015-01-27 14:42:36 -0800 | [diff] [blame] | 266 | GLuint outputPitch = sizedFormatInfo.computeRowPitch(type, area.width, state.getPackAlignment(), 0); |
Geoff Lang | bce529e | 2014-12-01 12:48:41 -0500 | [diff] [blame] | 267 | |
| 268 | return readPixels(area, format, type, outputPitch, state.getPackState(), reinterpret_cast<uint8_t*>(pixels)); |
| 269 | } |
| 270 | |
Geoff Lang | 54bd5a4 | 2014-12-01 12:51:04 -0500 | [diff] [blame] | 271 | gl::Error FramebufferD3D::blit(const gl::State &state, const gl::Rectangle &sourceArea, const gl::Rectangle &destArea, |
| 272 | GLbitfield mask, GLenum filter, const gl::Framebuffer *sourceFramebuffer) |
| 273 | { |
| 274 | bool blitRenderTarget = false; |
| 275 | if ((mask & GL_COLOR_BUFFER_BIT) && |
| 276 | sourceFramebuffer->getReadColorbuffer() != nullptr && |
| 277 | std::any_of(mColorBuffers.begin(), mColorBuffers.end(), [](const gl::FramebufferAttachment* attachment){ return attachment != nullptr; })) |
| 278 | { |
| 279 | blitRenderTarget = true; |
| 280 | } |
| 281 | |
| 282 | bool blitStencil = false; |
| 283 | if ((mask & GL_STENCIL_BUFFER_BIT) && |
| 284 | sourceFramebuffer->getStencilbuffer() != nullptr && |
| 285 | mStencilbuffer != nullptr) |
| 286 | { |
| 287 | blitStencil = true; |
| 288 | } |
| 289 | |
| 290 | bool blitDepth = false; |
| 291 | if ((mask & GL_DEPTH_BUFFER_BIT) && |
| 292 | sourceFramebuffer->getDepthbuffer() != nullptr && |
| 293 | mDepthbuffer != nullptr) |
| 294 | { |
| 295 | blitDepth = true; |
| 296 | } |
| 297 | |
| 298 | if (blitRenderTarget || blitDepth || blitStencil) |
| 299 | { |
| 300 | const gl::Rectangle *scissor = state.isScissorTestEnabled() ? &state.getScissor() : NULL; |
| 301 | gl::Error error = blit(sourceArea, destArea, scissor, blitRenderTarget, blitDepth, blitStencil, |
| 302 | filter, sourceFramebuffer); |
| 303 | if (error.isError()) |
| 304 | { |
| 305 | return error; |
| 306 | } |
| 307 | } |
| 308 | |
| 309 | return gl::Error(GL_NO_ERROR); |
| 310 | } |
| 311 | |
Geoff Lang | 748f74e | 2014-12-01 11:25:34 -0500 | [diff] [blame] | 312 | GLenum FramebufferD3D::checkStatus() const |
| 313 | { |
| 314 | // D3D11 does not allow for overlapping RenderTargetViews, so ensure uniqueness |
| 315 | for (size_t colorAttachment = 0; colorAttachment < mColorBuffers.size(); colorAttachment++) |
| 316 | { |
| 317 | const gl::FramebufferAttachment *attachment = mColorBuffers[colorAttachment]; |
| 318 | if (attachment != nullptr) |
| 319 | { |
| 320 | for (size_t prevColorAttachment = 0; prevColorAttachment < colorAttachment; prevColorAttachment++) |
| 321 | { |
| 322 | const gl::FramebufferAttachment *prevAttachment = mColorBuffers[prevColorAttachment]; |
| 323 | if (prevAttachment != nullptr && |
| 324 | (attachment->id() == prevAttachment->id() && |
| 325 | attachment->type() == prevAttachment->type())) |
| 326 | { |
| 327 | return GL_FRAMEBUFFER_UNSUPPORTED; |
| 328 | } |
| 329 | } |
| 330 | } |
| 331 | } |
| 332 | |
| 333 | return GL_FRAMEBUFFER_COMPLETE; |
| 334 | } |
| 335 | |
Geoff Lang | c2e75af | 2015-01-05 14:26:24 -0500 | [diff] [blame] | 336 | gl::Error GetAttachmentRenderTarget(const gl::FramebufferAttachment *attachment, RenderTargetD3D **outRT) |
Geoff Lang | b5d8f23 | 2014-12-04 15:43:01 -0500 | [diff] [blame] | 337 | { |
| 338 | if (attachment->type() == GL_TEXTURE) |
| 339 | { |
| 340 | gl::Texture *texture = attachment->getTexture(); |
| 341 | ASSERT(texture); |
Jamie Madill | 9236b41 | 2015-02-02 16:51:52 -0500 | [diff] [blame] | 342 | TextureD3D *textureD3D = GetImplAs<TextureD3D>(texture); |
Geoff Lang | b5d8f23 | 2014-12-04 15:43:01 -0500 | [diff] [blame] | 343 | const gl::ImageIndex *index = attachment->getTextureImageIndex(); |
| 344 | ASSERT(index); |
| 345 | return textureD3D->getRenderTarget(*index, outRT); |
| 346 | } |
| 347 | else if (attachment->type() == GL_RENDERBUFFER) |
| 348 | { |
| 349 | gl::Renderbuffer *renderbuffer = attachment->getRenderbuffer(); |
| 350 | ASSERT(renderbuffer); |
| 351 | RenderbufferD3D *renderbufferD3D = RenderbufferD3D::makeRenderbufferD3D(renderbuffer->getImplementation()); |
| 352 | *outRT = renderbufferD3D->getRenderTarget(); |
| 353 | return gl::Error(GL_NO_ERROR); |
| 354 | } |
| 355 | else if (attachment->type() == GL_FRAMEBUFFER_DEFAULT) |
| 356 | { |
| 357 | const gl::DefaultAttachment *defaultAttachment = static_cast<const gl::DefaultAttachment *>(attachment); |
| 358 | DefaultAttachmentD3D *defaultAttachmentD3D = DefaultAttachmentD3D::makeDefaultAttachmentD3D(defaultAttachment->getImplementation()); |
| 359 | ASSERT(defaultAttachmentD3D); |
| 360 | |
| 361 | *outRT = defaultAttachmentD3D->getRenderTarget(); |
| 362 | return gl::Error(GL_NO_ERROR); |
| 363 | } |
| 364 | else |
| 365 | { |
| 366 | UNREACHABLE(); |
| 367 | return gl::Error(GL_INVALID_OPERATION); |
| 368 | } |
| 369 | } |
| 370 | |
| 371 | // Note: RenderTarget serials should ideally be in the RenderTargets themselves. |
| 372 | unsigned int GetAttachmentSerial(const gl::FramebufferAttachment *attachment) |
| 373 | { |
| 374 | if (attachment->type() == GL_TEXTURE) |
| 375 | { |
| 376 | gl::Texture *texture = attachment->getTexture(); |
| 377 | ASSERT(texture); |
Jamie Madill | 9236b41 | 2015-02-02 16:51:52 -0500 | [diff] [blame] | 378 | TextureD3D *textureD3D = GetImplAs<TextureD3D>(texture); |
Geoff Lang | b5d8f23 | 2014-12-04 15:43:01 -0500 | [diff] [blame] | 379 | const gl::ImageIndex *index = attachment->getTextureImageIndex(); |
| 380 | ASSERT(index); |
| 381 | return textureD3D->getRenderTargetSerial(*index); |
| 382 | } |
| 383 | else if (attachment->type() == GL_RENDERBUFFER) |
| 384 | { |
| 385 | gl::Renderbuffer *renderbuffer = attachment->getRenderbuffer(); |
| 386 | ASSERT(renderbuffer); |
| 387 | RenderbufferD3D *renderbufferD3D = RenderbufferD3D::makeRenderbufferD3D(renderbuffer->getImplementation()); |
| 388 | return renderbufferD3D->getRenderTargetSerial(); |
| 389 | } |
| 390 | else if (attachment->type() == GL_FRAMEBUFFER_DEFAULT) |
| 391 | { |
| 392 | const gl::DefaultAttachment *defaultAttachment = static_cast<const gl::DefaultAttachment *>(attachment); |
| 393 | DefaultAttachmentD3D *defaultAttachmentD3D = DefaultAttachmentD3D::makeDefaultAttachmentD3D(defaultAttachment->getImplementation()); |
| 394 | ASSERT(defaultAttachmentD3D); |
| 395 | return defaultAttachmentD3D->getRenderTarget()->getSerial(); |
| 396 | } |
| 397 | else |
| 398 | { |
| 399 | UNREACHABLE(); |
| 400 | return 0; |
| 401 | } |
| 402 | } |
| 403 | |
Geoff Lang | 6a1e6b9 | 2014-11-06 10:42:45 -0500 | [diff] [blame] | 404 | } |