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 | b5d8f23 | 2014-12-04 15:43:01 -0500 | [diff] [blame] | 12 | #include "libANGLE/renderer/d3d/RenderbufferD3D.h" |
Geoff Lang | 2b5420c | 2014-11-19 14:20:15 -0500 | [diff] [blame] | 13 | #include "libANGLE/renderer/RenderTarget.h" |
Geoff Lang | b5d8f23 | 2014-12-04 15:43:01 -0500 | [diff] [blame] | 14 | #include "libANGLE/FramebufferAttachment.h" |
Geoff Lang | 6a1e6b9 | 2014-11-06 10:42:45 -0500 | [diff] [blame] | 15 | |
| 16 | namespace rx |
| 17 | { |
| 18 | |
| 19 | DefaultAttachmentD3D::DefaultAttachmentD3D(RenderTarget *renderTarget) |
| 20 | : mRenderTarget(renderTarget) |
| 21 | { |
| 22 | ASSERT(mRenderTarget); |
| 23 | } |
| 24 | |
| 25 | DefaultAttachmentD3D::~DefaultAttachmentD3D() |
| 26 | { |
| 27 | SafeDelete(mRenderTarget); |
| 28 | } |
| 29 | |
| 30 | DefaultAttachmentD3D *DefaultAttachmentD3D::makeDefaultAttachmentD3D(DefaultAttachmentImpl* impl) |
| 31 | { |
| 32 | ASSERT(HAS_DYNAMIC_TYPE(DefaultAttachmentD3D*, impl)); |
| 33 | return static_cast<DefaultAttachmentD3D*>(impl); |
| 34 | } |
| 35 | |
| 36 | GLsizei DefaultAttachmentD3D::getWidth() const |
| 37 | { |
| 38 | return mRenderTarget->getWidth(); |
| 39 | } |
| 40 | |
| 41 | GLsizei DefaultAttachmentD3D::getHeight() const |
| 42 | { |
| 43 | return mRenderTarget->getHeight(); |
| 44 | } |
| 45 | |
| 46 | GLenum DefaultAttachmentD3D::getInternalFormat() const |
| 47 | { |
| 48 | return mRenderTarget->getInternalFormat(); |
| 49 | } |
| 50 | |
| 51 | GLenum DefaultAttachmentD3D::getActualFormat() const |
| 52 | { |
| 53 | return mRenderTarget->getActualFormat(); |
| 54 | } |
| 55 | |
| 56 | GLsizei DefaultAttachmentD3D::getSamples() const |
| 57 | { |
| 58 | return mRenderTarget->getSamples(); |
| 59 | } |
| 60 | |
| 61 | RenderTarget *DefaultAttachmentD3D::getRenderTarget() const |
| 62 | { |
| 63 | return mRenderTarget; |
| 64 | } |
| 65 | |
Geoff Lang | da88add | 2014-12-01 10:22:01 -0500 | [diff] [blame] | 66 | |
| 67 | FramebufferD3D::FramebufferD3D(RendererD3D *renderer) |
Geoff Lang | 748f74e | 2014-12-01 11:25:34 -0500 | [diff] [blame^] | 68 | : mRenderer(renderer), |
| 69 | mColorBuffers(renderer->getRendererCaps().maxColorAttachments) |
Geoff Lang | da88add | 2014-12-01 10:22:01 -0500 | [diff] [blame] | 70 | { |
| 71 | ASSERT(mRenderer != nullptr); |
Geoff Lang | 748f74e | 2014-12-01 11:25:34 -0500 | [diff] [blame^] | 72 | |
| 73 | std::fill(mColorBuffers.begin(), mColorBuffers.end(), nullptr); |
Geoff Lang | da88add | 2014-12-01 10:22:01 -0500 | [diff] [blame] | 74 | } |
| 75 | |
| 76 | FramebufferD3D::~FramebufferD3D() |
| 77 | { |
| 78 | } |
| 79 | |
Geoff Lang | 9dd9580 | 2014-12-01 11:12:59 -0500 | [diff] [blame] | 80 | void FramebufferD3D::setColorAttachment(size_t index, const gl::FramebufferAttachment *attachment) |
| 81 | { |
Geoff Lang | 748f74e | 2014-12-01 11:25:34 -0500 | [diff] [blame^] | 82 | ASSERT(index < mColorBuffers.size()); |
| 83 | mColorBuffers[index] = attachment; |
Geoff Lang | 9dd9580 | 2014-12-01 11:12:59 -0500 | [diff] [blame] | 84 | } |
| 85 | |
| 86 | void FramebufferD3D::setDepthttachment(const gl::FramebufferAttachment *attachment) |
| 87 | { |
| 88 | } |
| 89 | |
| 90 | void FramebufferD3D::setStencilAttachment(const gl::FramebufferAttachment *attachment) |
| 91 | { |
| 92 | } |
| 93 | |
| 94 | void FramebufferD3D::setDepthStencilAttachment(const gl::FramebufferAttachment *attachment) |
| 95 | { |
| 96 | } |
| 97 | |
| 98 | void FramebufferD3D::setDrawBuffers(size_t count, const GLenum *buffers) |
| 99 | { |
| 100 | } |
| 101 | |
| 102 | void FramebufferD3D::setReadBuffer(GLenum buffer) |
| 103 | { |
| 104 | } |
| 105 | |
Geoff Lang | 9ad4bda | 2014-12-01 11:03:09 -0500 | [diff] [blame] | 106 | gl::Error FramebufferD3D::invalidate(size_t, const GLenum *) |
| 107 | { |
| 108 | // No-op in D3D |
| 109 | return gl::Error(GL_NO_ERROR); |
| 110 | } |
| 111 | |
| 112 | gl::Error FramebufferD3D::invalidateSub(size_t, const GLenum *, const gl::Rectangle &) |
| 113 | { |
| 114 | // No-op in D3D |
| 115 | return gl::Error(GL_NO_ERROR); |
| 116 | } |
| 117 | |
Geoff Lang | 748f74e | 2014-12-01 11:25:34 -0500 | [diff] [blame^] | 118 | GLenum FramebufferD3D::checkStatus() const |
| 119 | { |
| 120 | // D3D11 does not allow for overlapping RenderTargetViews, so ensure uniqueness |
| 121 | for (size_t colorAttachment = 0; colorAttachment < mColorBuffers.size(); colorAttachment++) |
| 122 | { |
| 123 | const gl::FramebufferAttachment *attachment = mColorBuffers[colorAttachment]; |
| 124 | if (attachment != nullptr) |
| 125 | { |
| 126 | for (size_t prevColorAttachment = 0; prevColorAttachment < colorAttachment; prevColorAttachment++) |
| 127 | { |
| 128 | const gl::FramebufferAttachment *prevAttachment = mColorBuffers[prevColorAttachment]; |
| 129 | if (prevAttachment != nullptr && |
| 130 | (attachment->id() == prevAttachment->id() && |
| 131 | attachment->type() == prevAttachment->type())) |
| 132 | { |
| 133 | return GL_FRAMEBUFFER_UNSUPPORTED; |
| 134 | } |
| 135 | } |
| 136 | } |
| 137 | } |
| 138 | |
| 139 | return GL_FRAMEBUFFER_COMPLETE; |
| 140 | } |
| 141 | |
Geoff Lang | b5d8f23 | 2014-12-04 15:43:01 -0500 | [diff] [blame] | 142 | gl::Error GetAttachmentRenderTarget(const gl::FramebufferAttachment *attachment, RenderTarget **outRT) |
| 143 | { |
| 144 | if (attachment->type() == GL_TEXTURE) |
| 145 | { |
| 146 | gl::Texture *texture = attachment->getTexture(); |
| 147 | ASSERT(texture); |
| 148 | TextureD3D *textureD3D = TextureD3D::makeTextureD3D(texture->getImplementation()); |
| 149 | const gl::ImageIndex *index = attachment->getTextureImageIndex(); |
| 150 | ASSERT(index); |
| 151 | return textureD3D->getRenderTarget(*index, outRT); |
| 152 | } |
| 153 | else if (attachment->type() == GL_RENDERBUFFER) |
| 154 | { |
| 155 | gl::Renderbuffer *renderbuffer = attachment->getRenderbuffer(); |
| 156 | ASSERT(renderbuffer); |
| 157 | RenderbufferD3D *renderbufferD3D = RenderbufferD3D::makeRenderbufferD3D(renderbuffer->getImplementation()); |
| 158 | *outRT = renderbufferD3D->getRenderTarget(); |
| 159 | return gl::Error(GL_NO_ERROR); |
| 160 | } |
| 161 | else if (attachment->type() == GL_FRAMEBUFFER_DEFAULT) |
| 162 | { |
| 163 | const gl::DefaultAttachment *defaultAttachment = static_cast<const gl::DefaultAttachment *>(attachment); |
| 164 | DefaultAttachmentD3D *defaultAttachmentD3D = DefaultAttachmentD3D::makeDefaultAttachmentD3D(defaultAttachment->getImplementation()); |
| 165 | ASSERT(defaultAttachmentD3D); |
| 166 | |
| 167 | *outRT = defaultAttachmentD3D->getRenderTarget(); |
| 168 | return gl::Error(GL_NO_ERROR); |
| 169 | } |
| 170 | else |
| 171 | { |
| 172 | UNREACHABLE(); |
| 173 | return gl::Error(GL_INVALID_OPERATION); |
| 174 | } |
| 175 | } |
| 176 | |
| 177 | // Note: RenderTarget serials should ideally be in the RenderTargets themselves. |
| 178 | unsigned int GetAttachmentSerial(const gl::FramebufferAttachment *attachment) |
| 179 | { |
| 180 | if (attachment->type() == GL_TEXTURE) |
| 181 | { |
| 182 | gl::Texture *texture = attachment->getTexture(); |
| 183 | ASSERT(texture); |
| 184 | TextureD3D *textureD3D = TextureD3D::makeTextureD3D(texture->getImplementation()); |
| 185 | const gl::ImageIndex *index = attachment->getTextureImageIndex(); |
| 186 | ASSERT(index); |
| 187 | return textureD3D->getRenderTargetSerial(*index); |
| 188 | } |
| 189 | else if (attachment->type() == GL_RENDERBUFFER) |
| 190 | { |
| 191 | gl::Renderbuffer *renderbuffer = attachment->getRenderbuffer(); |
| 192 | ASSERT(renderbuffer); |
| 193 | RenderbufferD3D *renderbufferD3D = RenderbufferD3D::makeRenderbufferD3D(renderbuffer->getImplementation()); |
| 194 | return renderbufferD3D->getRenderTargetSerial(); |
| 195 | } |
| 196 | else if (attachment->type() == GL_FRAMEBUFFER_DEFAULT) |
| 197 | { |
| 198 | const gl::DefaultAttachment *defaultAttachment = static_cast<const gl::DefaultAttachment *>(attachment); |
| 199 | DefaultAttachmentD3D *defaultAttachmentD3D = DefaultAttachmentD3D::makeDefaultAttachmentD3D(defaultAttachment->getImplementation()); |
| 200 | ASSERT(defaultAttachmentD3D); |
| 201 | return defaultAttachmentD3D->getRenderTarget()->getSerial(); |
| 202 | } |
| 203 | else |
| 204 | { |
| 205 | UNREACHABLE(); |
| 206 | return 0; |
| 207 | } |
| 208 | } |
| 209 | |
Geoff Lang | 6a1e6b9 | 2014-11-06 10:42:45 -0500 | [diff] [blame] | 210 | } |