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