Jamie Madill | afc21c0 | 2014-06-04 15:29:47 -0400 | [diff] [blame] | 1 | // |
| 2 | // Copyright (c) 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 | |
| 7 | // FramebufferAttachment.cpp: the gl::FramebufferAttachment class and its derived classes |
| 8 | // objects and related functionality. [OpenGL ES 2.0.24] section 4.4.3 page 108. |
| 9 | |
| 10 | #include "libGLESv2/FramebufferAttachment.h" |
Jamie Madill | afc21c0 | 2014-06-04 15:29:47 -0400 | [diff] [blame] | 11 | #include "libGLESv2/Texture.h" |
Jamie Madill | afc21c0 | 2014-06-04 15:29:47 -0400 | [diff] [blame] | 12 | #include "libGLESv2/formatutils.h" |
| 13 | #include "libGLESv2/Renderbuffer.h" |
Geoff Lang | 0b7eef7 | 2014-06-12 14:10:47 -0400 | [diff] [blame] | 14 | #include "libGLESv2/renderer/RenderTarget.h" |
| 15 | #include "libGLESv2/renderer/Renderer.h" |
| 16 | #include "libGLESv2/renderer/d3d/TextureStorage.h" |
| 17 | |
| 18 | #include "common/utilities.h" |
Jamie Madill | afc21c0 | 2014-06-04 15:29:47 -0400 | [diff] [blame] | 19 | |
| 20 | namespace gl |
| 21 | { |
| 22 | |
Jamie Madill | afc21c0 | 2014-06-04 15:29:47 -0400 | [diff] [blame] | 23 | ////// FramebufferAttachment Implementation ////// |
| 24 | |
Jamie Madill | aef95de | 2014-09-05 10:12:41 -0400 | [diff] [blame] | 25 | FramebufferAttachment::FramebufferAttachment(GLenum binding) |
| 26 | : mBinding(binding) |
Jamie Madill | afc21c0 | 2014-06-04 15:29:47 -0400 | [diff] [blame] | 27 | { |
Jamie Madill | afc21c0 | 2014-06-04 15:29:47 -0400 | [diff] [blame] | 28 | } |
| 29 | |
| 30 | FramebufferAttachment::~FramebufferAttachment() |
| 31 | { |
Jamie Madill | afc21c0 | 2014-06-04 15:29:47 -0400 | [diff] [blame] | 32 | } |
| 33 | |
Geoff Lang | e4a492b | 2014-06-19 14:14:41 -0400 | [diff] [blame] | 34 | GLuint FramebufferAttachment::getRedSize() const |
Jamie Madill | afc21c0 | 2014-06-04 15:29:47 -0400 | [diff] [blame] | 35 | { |
Geoff Lang | 5d60138 | 2014-07-22 15:14:06 -0400 | [diff] [blame] | 36 | return (GetInternalFormatInfo(getInternalFormat()).redBits > 0) ? GetInternalFormatInfo(getActualFormat()).redBits : 0; |
Jamie Madill | afc21c0 | 2014-06-04 15:29:47 -0400 | [diff] [blame] | 37 | } |
| 38 | |
Geoff Lang | e4a492b | 2014-06-19 14:14:41 -0400 | [diff] [blame] | 39 | GLuint FramebufferAttachment::getGreenSize() const |
Jamie Madill | afc21c0 | 2014-06-04 15:29:47 -0400 | [diff] [blame] | 40 | { |
Geoff Lang | 5d60138 | 2014-07-22 15:14:06 -0400 | [diff] [blame] | 41 | return (GetInternalFormatInfo(getInternalFormat()).greenBits > 0) ? GetInternalFormatInfo(getActualFormat()).greenBits : 0; |
Jamie Madill | afc21c0 | 2014-06-04 15:29:47 -0400 | [diff] [blame] | 42 | } |
| 43 | |
Geoff Lang | e4a492b | 2014-06-19 14:14:41 -0400 | [diff] [blame] | 44 | GLuint FramebufferAttachment::getBlueSize() const |
Jamie Madill | afc21c0 | 2014-06-04 15:29:47 -0400 | [diff] [blame] | 45 | { |
Geoff Lang | 5d60138 | 2014-07-22 15:14:06 -0400 | [diff] [blame] | 46 | return (GetInternalFormatInfo(getInternalFormat()).blueBits > 0) ? GetInternalFormatInfo(getActualFormat()).blueBits : 0; |
Jamie Madill | afc21c0 | 2014-06-04 15:29:47 -0400 | [diff] [blame] | 47 | } |
| 48 | |
Geoff Lang | e4a492b | 2014-06-19 14:14:41 -0400 | [diff] [blame] | 49 | GLuint FramebufferAttachment::getAlphaSize() const |
Jamie Madill | afc21c0 | 2014-06-04 15:29:47 -0400 | [diff] [blame] | 50 | { |
Geoff Lang | 5d60138 | 2014-07-22 15:14:06 -0400 | [diff] [blame] | 51 | return (GetInternalFormatInfo(getInternalFormat()).alphaBits > 0) ? GetInternalFormatInfo(getActualFormat()).alphaBits : 0; |
Jamie Madill | afc21c0 | 2014-06-04 15:29:47 -0400 | [diff] [blame] | 52 | } |
| 53 | |
Geoff Lang | e4a492b | 2014-06-19 14:14:41 -0400 | [diff] [blame] | 54 | GLuint FramebufferAttachment::getDepthSize() const |
Jamie Madill | afc21c0 | 2014-06-04 15:29:47 -0400 | [diff] [blame] | 55 | { |
Geoff Lang | 5d60138 | 2014-07-22 15:14:06 -0400 | [diff] [blame] | 56 | return (GetInternalFormatInfo(getInternalFormat()).depthBits > 0) ? GetInternalFormatInfo(getActualFormat()).depthBits : 0; |
Jamie Madill | afc21c0 | 2014-06-04 15:29:47 -0400 | [diff] [blame] | 57 | } |
| 58 | |
Geoff Lang | e4a492b | 2014-06-19 14:14:41 -0400 | [diff] [blame] | 59 | GLuint FramebufferAttachment::getStencilSize() const |
Jamie Madill | afc21c0 | 2014-06-04 15:29:47 -0400 | [diff] [blame] | 60 | { |
Geoff Lang | 5d60138 | 2014-07-22 15:14:06 -0400 | [diff] [blame] | 61 | return (GetInternalFormatInfo(getInternalFormat()).stencilBits > 0) ? GetInternalFormatInfo(getActualFormat()).stencilBits : 0; |
Jamie Madill | afc21c0 | 2014-06-04 15:29:47 -0400 | [diff] [blame] | 62 | } |
| 63 | |
Geoff Lang | e4a492b | 2014-06-19 14:14:41 -0400 | [diff] [blame] | 64 | GLenum FramebufferAttachment::getComponentType() const |
Jamie Madill | afc21c0 | 2014-06-04 15:29:47 -0400 | [diff] [blame] | 65 | { |
Geoff Lang | 5d60138 | 2014-07-22 15:14:06 -0400 | [diff] [blame] | 66 | return GetInternalFormatInfo(getActualFormat()).componentType; |
Jamie Madill | afc21c0 | 2014-06-04 15:29:47 -0400 | [diff] [blame] | 67 | } |
| 68 | |
Geoff Lang | e4a492b | 2014-06-19 14:14:41 -0400 | [diff] [blame] | 69 | GLenum FramebufferAttachment::getColorEncoding() const |
Jamie Madill | afc21c0 | 2014-06-04 15:29:47 -0400 | [diff] [blame] | 70 | { |
Geoff Lang | 5d60138 | 2014-07-22 15:14:06 -0400 | [diff] [blame] | 71 | return GetInternalFormatInfo(getActualFormat()).colorEncoding; |
Jamie Madill | afc21c0 | 2014-06-04 15:29:47 -0400 | [diff] [blame] | 72 | } |
| 73 | |
Jamie Madill | 218b6ed | 2014-06-16 10:34:01 -0400 | [diff] [blame] | 74 | bool FramebufferAttachment::isTexture() const |
| 75 | { |
| 76 | return (type() != GL_RENDERBUFFER); |
| 77 | } |
| 78 | |
Jamie Madill | 3592a33 | 2014-09-03 15:07:15 -0400 | [diff] [blame] | 79 | ///// TextureAttachment Implementation //////// |
| 80 | |
Jamie Madill | eeb7b0e | 2014-09-03 15:07:20 -0400 | [diff] [blame] | 81 | TextureAttachment::TextureAttachment(GLenum binding, Texture *texture, const ImageIndex &index) |
Jamie Madill | de3ed70 | 2014-09-03 15:07:17 -0400 | [diff] [blame] | 82 | : FramebufferAttachment(binding), |
| 83 | mIndex(index) |
Jamie Madill | eeb7b0e | 2014-09-03 15:07:20 -0400 | [diff] [blame] | 84 | { |
| 85 | mTexture.set(texture); |
| 86 | } |
| 87 | |
| 88 | TextureAttachment::~TextureAttachment() |
| 89 | { |
| 90 | mTexture.set(NULL); |
| 91 | } |
Jamie Madill | aef95de | 2014-09-05 10:12:41 -0400 | [diff] [blame] | 92 | |
Jamie Madill | 3592a33 | 2014-09-03 15:07:15 -0400 | [diff] [blame] | 93 | GLsizei TextureAttachment::getSamples() const |
| 94 | { |
| 95 | return 0; |
| 96 | } |
| 97 | |
| 98 | GLuint TextureAttachment::id() const |
| 99 | { |
Jamie Madill | eeb7b0e | 2014-09-03 15:07:20 -0400 | [diff] [blame] | 100 | return mTexture->id(); |
Jamie Madill | 3592a33 | 2014-09-03 15:07:15 -0400 | [diff] [blame] | 101 | } |
| 102 | |
Jamie Madill | de3ed70 | 2014-09-03 15:07:17 -0400 | [diff] [blame] | 103 | GLsizei TextureAttachment::getWidth() const |
| 104 | { |
Jamie Madill | eeb7b0e | 2014-09-03 15:07:20 -0400 | [diff] [blame] | 105 | return mTexture->getWidth(mIndex); |
Jamie Madill | de3ed70 | 2014-09-03 15:07:17 -0400 | [diff] [blame] | 106 | } |
| 107 | |
| 108 | GLsizei TextureAttachment::getHeight() const |
| 109 | { |
Jamie Madill | eeb7b0e | 2014-09-03 15:07:20 -0400 | [diff] [blame] | 110 | return mTexture->getHeight(mIndex); |
Jamie Madill | de3ed70 | 2014-09-03 15:07:17 -0400 | [diff] [blame] | 111 | } |
| 112 | |
| 113 | GLenum TextureAttachment::getInternalFormat() const |
| 114 | { |
Jamie Madill | eeb7b0e | 2014-09-03 15:07:20 -0400 | [diff] [blame] | 115 | return mTexture->getInternalFormat(mIndex); |
Jamie Madill | de3ed70 | 2014-09-03 15:07:17 -0400 | [diff] [blame] | 116 | } |
| 117 | |
| 118 | GLenum TextureAttachment::getActualFormat() const |
| 119 | { |
Jamie Madill | eeb7b0e | 2014-09-03 15:07:20 -0400 | [diff] [blame] | 120 | return mTexture->getActualFormat(mIndex); |
Jamie Madill | de3ed70 | 2014-09-03 15:07:17 -0400 | [diff] [blame] | 121 | } |
| 122 | |
| 123 | GLenum TextureAttachment::type() const |
| 124 | { |
| 125 | return mIndex.type; |
| 126 | } |
| 127 | |
| 128 | GLint TextureAttachment::mipLevel() const |
| 129 | { |
| 130 | return mIndex.mipIndex; |
| 131 | } |
| 132 | |
| 133 | GLint TextureAttachment::layer() const |
| 134 | { |
| 135 | return mIndex.layerIndex; |
| 136 | } |
| 137 | |
Jamie Madill | 5b5d124 | 2014-09-09 15:15:36 -0400 | [diff] [blame] | 138 | Texture *TextureAttachment::getTexture() |
| 139 | { |
| 140 | return mTexture.get(); |
| 141 | } |
| 142 | |
Jamie Madill | ac7579c | 2014-09-17 16:59:33 -0400 | [diff] [blame^] | 143 | const ImageIndex *TextureAttachment::getTextureImageIndex() const |
| 144 | { |
| 145 | return &mIndex; |
| 146 | } |
| 147 | |
Jamie Madill | 5b5d124 | 2014-09-09 15:15:36 -0400 | [diff] [blame] | 148 | Renderbuffer *TextureAttachment::getRenderbuffer() |
| 149 | { |
| 150 | UNREACHABLE(); |
| 151 | return NULL; |
| 152 | } |
| 153 | |
Jamie Madill | e261b44 | 2014-06-25 12:42:21 -0400 | [diff] [blame] | 154 | ////// RenderbufferAttachment Implementation ////// |
| 155 | |
Jamie Madill | aef95de | 2014-09-05 10:12:41 -0400 | [diff] [blame] | 156 | RenderbufferAttachment::RenderbufferAttachment(GLenum binding, Renderbuffer *renderbuffer) |
| 157 | : FramebufferAttachment(binding) |
Jamie Madill | 6c7b4ad | 2014-06-16 10:33:59 -0400 | [diff] [blame] | 158 | { |
| 159 | ASSERT(renderbuffer); |
| 160 | mRenderbuffer.set(renderbuffer); |
| 161 | } |
| 162 | |
| 163 | RenderbufferAttachment::~RenderbufferAttachment() |
| 164 | { |
| 165 | mRenderbuffer.set(NULL); |
| 166 | } |
| 167 | |
Jamie Madill | 6c7b4ad | 2014-06-16 10:33:59 -0400 | [diff] [blame] | 168 | GLsizei RenderbufferAttachment::getWidth() const |
| 169 | { |
| 170 | return mRenderbuffer->getWidth(); |
| 171 | } |
| 172 | |
| 173 | GLsizei RenderbufferAttachment::getHeight() const |
| 174 | { |
| 175 | return mRenderbuffer->getHeight(); |
| 176 | } |
| 177 | |
| 178 | GLenum RenderbufferAttachment::getInternalFormat() const |
| 179 | { |
| 180 | return mRenderbuffer->getInternalFormat(); |
| 181 | } |
| 182 | |
| 183 | GLenum RenderbufferAttachment::getActualFormat() const |
| 184 | { |
| 185 | return mRenderbuffer->getActualFormat(); |
| 186 | } |
| 187 | |
| 188 | GLsizei RenderbufferAttachment::getSamples() const |
| 189 | { |
| 190 | return mRenderbuffer->getStorage()->getSamples(); |
| 191 | } |
| 192 | |
Jamie Madill | 218b6ed | 2014-06-16 10:34:01 -0400 | [diff] [blame] | 193 | GLuint RenderbufferAttachment::id() const |
Jamie Madill | 6c7b4ad | 2014-06-16 10:33:59 -0400 | [diff] [blame] | 194 | { |
Jamie Madill | 218b6ed | 2014-06-16 10:34:01 -0400 | [diff] [blame] | 195 | return mRenderbuffer->id(); |
| 196 | } |
| 197 | |
| 198 | GLenum RenderbufferAttachment::type() const |
| 199 | { |
| 200 | return GL_RENDERBUFFER; |
Jamie Madill | 6c7b4ad | 2014-06-16 10:33:59 -0400 | [diff] [blame] | 201 | } |
| 202 | |
Jamie Madill | 9c074a3 | 2014-06-16 10:34:02 -0400 | [diff] [blame] | 203 | GLint RenderbufferAttachment::mipLevel() const |
| 204 | { |
| 205 | return 0; |
| 206 | } |
| 207 | |
| 208 | GLint RenderbufferAttachment::layer() const |
| 209 | { |
| 210 | return 0; |
| 211 | } |
| 212 | |
Jamie Madill | 5b5d124 | 2014-09-09 15:15:36 -0400 | [diff] [blame] | 213 | Texture *RenderbufferAttachment::getTexture() |
Jamie Madill | 6c7b4ad | 2014-06-16 10:33:59 -0400 | [diff] [blame] | 214 | { |
| 215 | UNREACHABLE(); |
Jamie Madill | 5b5d124 | 2014-09-09 15:15:36 -0400 | [diff] [blame] | 216 | return NULL; |
| 217 | } |
| 218 | |
Jamie Madill | ac7579c | 2014-09-17 16:59:33 -0400 | [diff] [blame^] | 219 | const ImageIndex *RenderbufferAttachment::getTextureImageIndex() const |
| 220 | { |
| 221 | UNREACHABLE(); |
| 222 | return NULL; |
| 223 | } |
| 224 | |
Jamie Madill | 5b5d124 | 2014-09-09 15:15:36 -0400 | [diff] [blame] | 225 | Renderbuffer *RenderbufferAttachment::getRenderbuffer() |
| 226 | { |
| 227 | return mRenderbuffer.get(); |
Jamie Madill | afc21c0 | 2014-06-04 15:29:47 -0400 | [diff] [blame] | 228 | } |
| 229 | |
| 230 | } |