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" 11 #include "libGLESv2/Texture.h" 12 #include "libGLESv2/formatutils.h" 13 #include "libGLESv2/Renderbuffer.h" 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" 19 20 namespace gl 21 { 22 23 ////// FramebufferAttachment Implementation ////// 24 25 FramebufferAttachment::FramebufferAttachment(GLenum binding) 26 : mBinding(binding) 27 { 28 } 29 30 FramebufferAttachment::~FramebufferAttachment() 31 { 32 } 33 34 GLuint FramebufferAttachment::getRedSize() const 35 { 36 return (GetInternalFormatInfo(getInternalFormat()).redBits > 0) ? GetInternalFormatInfo(getActualFormat()).redBits : 0; 37 } 38 39 GLuint FramebufferAttachment::getGreenSize() const 40 { 41 return (GetInternalFormatInfo(getInternalFormat()).greenBits > 0) ? GetInternalFormatInfo(getActualFormat()).greenBits : 0; 42 } 43 44 GLuint FramebufferAttachment::getBlueSize() const 45 { 46 return (GetInternalFormatInfo(getInternalFormat()).blueBits > 0) ? GetInternalFormatInfo(getActualFormat()).blueBits : 0; 47 } 48 49 GLuint FramebufferAttachment::getAlphaSize() const 50 { 51 return (GetInternalFormatInfo(getInternalFormat()).alphaBits > 0) ? GetInternalFormatInfo(getActualFormat()).alphaBits : 0; 52 } 53 54 GLuint FramebufferAttachment::getDepthSize() const 55 { 56 return (GetInternalFormatInfo(getInternalFormat()).depthBits > 0) ? GetInternalFormatInfo(getActualFormat()).depthBits : 0; 57 } 58 59 GLuint FramebufferAttachment::getStencilSize() const 60 { 61 return (GetInternalFormatInfo(getInternalFormat()).stencilBits > 0) ? GetInternalFormatInfo(getActualFormat()).stencilBits : 0; 62 } 63 64 GLenum FramebufferAttachment::getComponentType() const 65 { 66 return GetInternalFormatInfo(getActualFormat()).componentType; 67 } 68 69 GLenum FramebufferAttachment::getColorEncoding() const 70 { 71 return GetInternalFormatInfo(getActualFormat()).colorEncoding; 72 } 73 74 bool FramebufferAttachment::isTexture() const 75 { 76 return (type() != GL_RENDERBUFFER); 77 } 78 79 ///// TextureAttachment Implementation //////// 80 81 TextureAttachment::TextureAttachment(GLenum binding, Texture *texture, const ImageIndex &index) 82 : FramebufferAttachment(binding), 83 mIndex(index) 84 { 85 mTexture.set(texture); 86 } 87 88 TextureAttachment::~TextureAttachment() 89 { 90 mTexture.set(NULL); 91 } 92 93 GLsizei TextureAttachment::getSamples() const 94 { 95 return 0; 96 } 97 98 GLuint TextureAttachment::id() const 99 { 100 return mTexture->id(); 101 } 102 103 GLsizei TextureAttachment::getWidth() const 104 { 105 return mTexture->getWidth(mIndex); 106 } 107 108 GLsizei TextureAttachment::getHeight() const 109 { 110 return mTexture->getHeight(mIndex); 111 } 112 113 GLenum TextureAttachment::getInternalFormat() const 114 { 115 return mTexture->getInternalFormat(mIndex); 116 } 117 118 GLenum TextureAttachment::getActualFormat() const 119 { 120 return mTexture->getActualFormat(mIndex); 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 138 Texture *TextureAttachment::getTexture() 139 { 140 return mTexture.get(); 141 } 142 143 const ImageIndex *TextureAttachment::getTextureImageIndex() const 144 { 145 return &mIndex; 146 } 147 148 Renderbuffer *TextureAttachment::getRenderbuffer() 149 { 150 UNREACHABLE(); 151 return NULL; 152 } 153 154 ////// RenderbufferAttachment Implementation ////// 155 156 RenderbufferAttachment::RenderbufferAttachment(GLenum binding, Renderbuffer *renderbuffer) 157 : FramebufferAttachment(binding) 158 { 159 ASSERT(renderbuffer); 160 mRenderbuffer.set(renderbuffer); 161 } 162 163 RenderbufferAttachment::~RenderbufferAttachment() 164 { 165 mRenderbuffer.set(NULL); 166 } 167 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 193 GLuint RenderbufferAttachment::id() const 194 { 195 return mRenderbuffer->id(); 196 } 197 198 GLenum RenderbufferAttachment::type() const 199 { 200 return GL_RENDERBUFFER; 201 } 202 203 GLint RenderbufferAttachment::mipLevel() const 204 { 205 return 0; 206 } 207 208 GLint RenderbufferAttachment::layer() const 209 { 210 return 0; 211 } 212 213 Texture *RenderbufferAttachment::getTexture() 214 { 215 UNREACHABLE(); 216 return NULL; 217 } 218 219 const ImageIndex *RenderbufferAttachment::getTextureImageIndex() const 220 { 221 UNREACHABLE(); 222 return NULL; 223 } 224 225 Renderbuffer *RenderbufferAttachment::getRenderbuffer() 226 { 227 return mRenderbuffer.get(); 228 } 229 230 } 231