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) |
| 68 | : mRenderer(renderer) |
| 69 | { |
| 70 | ASSERT(mRenderer != nullptr); |
| 71 | } |
| 72 | |
| 73 | FramebufferD3D::~FramebufferD3D() |
| 74 | { |
| 75 | } |
| 76 | |
Geoff Lang | 9ad4bda | 2014-12-01 11:03:09 -0500 | [diff] [blame] | 77 | gl::Error FramebufferD3D::invalidate(size_t, const GLenum *) |
| 78 | { |
| 79 | // No-op in D3D |
| 80 | return gl::Error(GL_NO_ERROR); |
| 81 | } |
| 82 | |
| 83 | gl::Error FramebufferD3D::invalidateSub(size_t, const GLenum *, const gl::Rectangle &) |
| 84 | { |
| 85 | // No-op in D3D |
| 86 | return gl::Error(GL_NO_ERROR); |
| 87 | } |
| 88 | |
Geoff Lang | b5d8f23 | 2014-12-04 15:43:01 -0500 | [diff] [blame] | 89 | gl::Error GetAttachmentRenderTarget(const gl::FramebufferAttachment *attachment, RenderTarget **outRT) |
| 90 | { |
| 91 | if (attachment->type() == GL_TEXTURE) |
| 92 | { |
| 93 | gl::Texture *texture = attachment->getTexture(); |
| 94 | ASSERT(texture); |
| 95 | TextureD3D *textureD3D = TextureD3D::makeTextureD3D(texture->getImplementation()); |
| 96 | const gl::ImageIndex *index = attachment->getTextureImageIndex(); |
| 97 | ASSERT(index); |
| 98 | return textureD3D->getRenderTarget(*index, outRT); |
| 99 | } |
| 100 | else if (attachment->type() == GL_RENDERBUFFER) |
| 101 | { |
| 102 | gl::Renderbuffer *renderbuffer = attachment->getRenderbuffer(); |
| 103 | ASSERT(renderbuffer); |
| 104 | RenderbufferD3D *renderbufferD3D = RenderbufferD3D::makeRenderbufferD3D(renderbuffer->getImplementation()); |
| 105 | *outRT = renderbufferD3D->getRenderTarget(); |
| 106 | return gl::Error(GL_NO_ERROR); |
| 107 | } |
| 108 | else if (attachment->type() == GL_FRAMEBUFFER_DEFAULT) |
| 109 | { |
| 110 | const gl::DefaultAttachment *defaultAttachment = static_cast<const gl::DefaultAttachment *>(attachment); |
| 111 | DefaultAttachmentD3D *defaultAttachmentD3D = DefaultAttachmentD3D::makeDefaultAttachmentD3D(defaultAttachment->getImplementation()); |
| 112 | ASSERT(defaultAttachmentD3D); |
| 113 | |
| 114 | *outRT = defaultAttachmentD3D->getRenderTarget(); |
| 115 | return gl::Error(GL_NO_ERROR); |
| 116 | } |
| 117 | else |
| 118 | { |
| 119 | UNREACHABLE(); |
| 120 | return gl::Error(GL_INVALID_OPERATION); |
| 121 | } |
| 122 | } |
| 123 | |
| 124 | // Note: RenderTarget serials should ideally be in the RenderTargets themselves. |
| 125 | unsigned int GetAttachmentSerial(const gl::FramebufferAttachment *attachment) |
| 126 | { |
| 127 | if (attachment->type() == GL_TEXTURE) |
| 128 | { |
| 129 | gl::Texture *texture = attachment->getTexture(); |
| 130 | ASSERT(texture); |
| 131 | TextureD3D *textureD3D = TextureD3D::makeTextureD3D(texture->getImplementation()); |
| 132 | const gl::ImageIndex *index = attachment->getTextureImageIndex(); |
| 133 | ASSERT(index); |
| 134 | return textureD3D->getRenderTargetSerial(*index); |
| 135 | } |
| 136 | else if (attachment->type() == GL_RENDERBUFFER) |
| 137 | { |
| 138 | gl::Renderbuffer *renderbuffer = attachment->getRenderbuffer(); |
| 139 | ASSERT(renderbuffer); |
| 140 | RenderbufferD3D *renderbufferD3D = RenderbufferD3D::makeRenderbufferD3D(renderbuffer->getImplementation()); |
| 141 | return renderbufferD3D->getRenderTargetSerial(); |
| 142 | } |
| 143 | else if (attachment->type() == GL_FRAMEBUFFER_DEFAULT) |
| 144 | { |
| 145 | const gl::DefaultAttachment *defaultAttachment = static_cast<const gl::DefaultAttachment *>(attachment); |
| 146 | DefaultAttachmentD3D *defaultAttachmentD3D = DefaultAttachmentD3D::makeDefaultAttachmentD3D(defaultAttachment->getImplementation()); |
| 147 | ASSERT(defaultAttachmentD3D); |
| 148 | return defaultAttachmentD3D->getRenderTarget()->getSerial(); |
| 149 | } |
| 150 | else |
| 151 | { |
| 152 | UNREACHABLE(); |
| 153 | return 0; |
| 154 | } |
| 155 | } |
| 156 | |
Geoff Lang | 6a1e6b9 | 2014-11-06 10:42:45 -0500 | [diff] [blame] | 157 | } |