• Home
  • Line#
  • Scopes#
  • Navigate#
  • Raw
  • Download
1 #include "precompiled.h"
2 //
3 // Copyright (c) 2014 The ANGLE Project Authors. All rights reserved.
4 // Use of this source code is governed by a BSD-style license that can be
5 // found in the LICENSE file.
6 //
7 
8 // FramebufferAttachment.cpp: the gl::FramebufferAttachment class and its derived classes
9 // objects and related functionality. [OpenGL ES 2.0.24] section 4.4.3 page 108.
10 
11 #include "libGLESv2/FramebufferAttachment.h"
12 #include "libGLESv2/renderer/RenderTarget.h"
13 
14 #include "libGLESv2/Texture.h"
15 #include "libGLESv2/renderer/Renderer.h"
16 #include "libGLESv2/renderer/TextureStorage.h"
17 #include "common/utilities.h"
18 #include "libGLESv2/formatutils.h"
19 #include "libGLESv2/Renderbuffer.h"
20 
21 namespace gl
22 {
23 
FramebufferAttachmentInterface()24 FramebufferAttachmentInterface::FramebufferAttachmentInterface()
25 {
26 }
27 
28 // The default case for classes inherited from FramebufferAttachmentInterface is not to
29 // need to do anything upon the reference count to the parent FramebufferAttachment incrementing
30 // or decrementing.
addProxyRef(const FramebufferAttachment * proxy)31 void FramebufferAttachmentInterface::addProxyRef(const FramebufferAttachment *proxy)
32 {
33 }
34 
releaseProxy(const FramebufferAttachment * proxy)35 void FramebufferAttachmentInterface::releaseProxy(const FramebufferAttachment *proxy)
36 {
37 }
38 
39 ///// Texture2DAttachment Implementation ////////
40 
Texture2DAttachment(Texture2D * texture,GLint level)41 Texture2DAttachment::Texture2DAttachment(Texture2D *texture, GLint level) : mLevel(level)
42 {
43     mTexture2D.set(texture);
44 }
45 
~Texture2DAttachment()46 Texture2DAttachment::~Texture2DAttachment()
47 {
48     mTexture2D.set(NULL);
49 }
50 
51 // Textures need to maintain their own reference count for references via
52 // Renderbuffers acting as proxies. Here, we notify the texture of a reference.
addProxyRef(const FramebufferAttachment * proxy)53 void Texture2DAttachment::addProxyRef(const FramebufferAttachment *proxy)
54 {
55     mTexture2D->addProxyRef(proxy);
56 }
57 
releaseProxy(const FramebufferAttachment * proxy)58 void Texture2DAttachment::releaseProxy(const FramebufferAttachment *proxy)
59 {
60     mTexture2D->releaseProxy(proxy);
61 }
62 
getRenderTarget()63 rx::RenderTarget *Texture2DAttachment::getRenderTarget()
64 {
65     return mTexture2D->getRenderTarget(mLevel);
66 }
67 
getDepthStencil()68 rx::RenderTarget *Texture2DAttachment::getDepthStencil()
69 {
70     return mTexture2D->getDepthSencil(mLevel);
71 }
72 
getTextureStorage()73 rx::TextureStorage *Texture2DAttachment::getTextureStorage()
74 {
75     return mTexture2D->getNativeTexture()->getStorageInstance();
76 }
77 
getWidth() const78 GLsizei Texture2DAttachment::getWidth() const
79 {
80     return mTexture2D->getWidth(mLevel);
81 }
82 
getHeight() const83 GLsizei Texture2DAttachment::getHeight() const
84 {
85     return mTexture2D->getHeight(mLevel);
86 }
87 
getInternalFormat() const88 GLenum Texture2DAttachment::getInternalFormat() const
89 {
90     return mTexture2D->getInternalFormat(mLevel);
91 }
92 
getActualFormat() const93 GLenum Texture2DAttachment::getActualFormat() const
94 {
95     return mTexture2D->getActualFormat(mLevel);
96 }
97 
getSamples() const98 GLsizei Texture2DAttachment::getSamples() const
99 {
100     return 0;
101 }
102 
getSerial() const103 unsigned int Texture2DAttachment::getSerial() const
104 {
105     return mTexture2D->getRenderTargetSerial(mLevel);
106 }
107 
isTexture() const108 bool Texture2DAttachment::isTexture() const
109 {
110     return true;
111 }
112 
getTextureSerial() const113 unsigned int Texture2DAttachment::getTextureSerial() const
114 {
115     return mTexture2D->getTextureSerial();
116 }
117 
118 ///// TextureCubeMapAttachment Implementation ////////
119 
TextureCubeMapAttachment(TextureCubeMap * texture,GLenum faceTarget,GLint level)120 TextureCubeMapAttachment::TextureCubeMapAttachment(TextureCubeMap *texture, GLenum faceTarget, GLint level)
121     : mFaceTarget(faceTarget), mLevel(level)
122 {
123     mTextureCubeMap.set(texture);
124 }
125 
~TextureCubeMapAttachment()126 TextureCubeMapAttachment::~TextureCubeMapAttachment()
127 {
128     mTextureCubeMap.set(NULL);
129 }
130 
131 // Textures need to maintain their own reference count for references via
132 // Renderbuffers acting as proxies. Here, we notify the texture of a reference.
addProxyRef(const FramebufferAttachment * proxy)133 void TextureCubeMapAttachment::addProxyRef(const FramebufferAttachment *proxy)
134 {
135     mTextureCubeMap->addProxyRef(proxy);
136 }
137 
releaseProxy(const FramebufferAttachment * proxy)138 void TextureCubeMapAttachment::releaseProxy(const FramebufferAttachment *proxy)
139 {
140     mTextureCubeMap->releaseProxy(proxy);
141 }
142 
getRenderTarget()143 rx::RenderTarget *TextureCubeMapAttachment::getRenderTarget()
144 {
145     return mTextureCubeMap->getRenderTarget(mFaceTarget, mLevel);
146 }
147 
getDepthStencil()148 rx::RenderTarget *TextureCubeMapAttachment::getDepthStencil()
149 {
150     return mTextureCubeMap->getDepthStencil(mFaceTarget, mLevel);
151 }
152 
getTextureStorage()153 rx::TextureStorage *TextureCubeMapAttachment::getTextureStorage()
154 {
155     return mTextureCubeMap->getNativeTexture()->getStorageInstance();
156 }
157 
getWidth() const158 GLsizei TextureCubeMapAttachment::getWidth() const
159 {
160     return mTextureCubeMap->getWidth(mFaceTarget, mLevel);
161 }
162 
getHeight() const163 GLsizei TextureCubeMapAttachment::getHeight() const
164 {
165     return mTextureCubeMap->getHeight(mFaceTarget, mLevel);
166 }
167 
getInternalFormat() const168 GLenum TextureCubeMapAttachment::getInternalFormat() const
169 {
170     return mTextureCubeMap->getInternalFormat(mFaceTarget, mLevel);
171 }
172 
getActualFormat() const173 GLenum TextureCubeMapAttachment::getActualFormat() const
174 {
175     return mTextureCubeMap->getActualFormat(mFaceTarget, mLevel);
176 }
177 
getSamples() const178 GLsizei TextureCubeMapAttachment::getSamples() const
179 {
180     return 0;
181 }
182 
getSerial() const183 unsigned int TextureCubeMapAttachment::getSerial() const
184 {
185     return mTextureCubeMap->getRenderTargetSerial(mFaceTarget, mLevel);
186 }
187 
isTexture() const188 bool TextureCubeMapAttachment::isTexture() const
189 {
190     return true;
191 }
192 
getTextureSerial() const193 unsigned int TextureCubeMapAttachment::getTextureSerial() const
194 {
195     return mTextureCubeMap->getTextureSerial();
196 }
197 
198 ///// Texture3DAttachment Implementation ////////
199 
Texture3DAttachment(Texture3D * texture,GLint level,GLint layer)200 Texture3DAttachment::Texture3DAttachment(Texture3D *texture, GLint level, GLint layer)
201     : mLevel(level), mLayer(layer)
202 {
203     mTexture3D.set(texture);
204 }
205 
~Texture3DAttachment()206 Texture3DAttachment::~Texture3DAttachment()
207 {
208     mTexture3D.set(NULL);
209 }
210 
211 // Textures need to maintain their own reference count for references via
212 // Renderbuffers acting as proxies. Here, we notify the texture of a reference.
addProxyRef(const FramebufferAttachment * proxy)213 void Texture3DAttachment::addProxyRef(const FramebufferAttachment *proxy)
214 {
215     mTexture3D->addProxyRef(proxy);
216 }
217 
releaseProxy(const FramebufferAttachment * proxy)218 void Texture3DAttachment::releaseProxy(const FramebufferAttachment *proxy)
219 {
220     mTexture3D->releaseProxy(proxy);
221 }
222 
getRenderTarget()223 rx::RenderTarget *Texture3DAttachment::getRenderTarget()
224 {
225     return mTexture3D->getRenderTarget(mLevel, mLayer);
226 }
227 
getDepthStencil()228 rx::RenderTarget *Texture3DAttachment::getDepthStencil()
229 {
230     return mTexture3D->getDepthStencil(mLevel, mLayer);
231 }
232 
getTextureStorage()233 rx::TextureStorage *Texture3DAttachment::getTextureStorage()
234 {
235     return mTexture3D->getNativeTexture()->getStorageInstance();
236 }
237 
getWidth() const238 GLsizei Texture3DAttachment::getWidth() const
239 {
240     return mTexture3D->getWidth(mLevel);
241 }
242 
getHeight() const243 GLsizei Texture3DAttachment::getHeight() const
244 {
245     return mTexture3D->getHeight(mLevel);
246 }
247 
getInternalFormat() const248 GLenum Texture3DAttachment::getInternalFormat() const
249 {
250     return mTexture3D->getInternalFormat(mLevel);
251 }
252 
getActualFormat() const253 GLenum Texture3DAttachment::getActualFormat() const
254 {
255     return mTexture3D->getActualFormat(mLevel);
256 }
257 
getSamples() const258 GLsizei Texture3DAttachment::getSamples() const
259 {
260     return 0;
261 }
262 
getSerial() const263 unsigned int Texture3DAttachment::getSerial() const
264 {
265     return mTexture3D->getRenderTargetSerial(mLevel, mLayer);
266 }
267 
isTexture() const268 bool Texture3DAttachment::isTexture() const
269 {
270     return true;
271 }
272 
getTextureSerial() const273 unsigned int Texture3DAttachment::getTextureSerial() const
274 {
275     return mTexture3D->getTextureSerial();
276 }
277 
278 ////// Texture2DArrayAttachment Implementation //////
279 
Texture2DArrayAttachment(Texture2DArray * texture,GLint level,GLint layer)280 Texture2DArrayAttachment::Texture2DArrayAttachment(Texture2DArray *texture, GLint level, GLint layer)
281     : mLevel(level), mLayer(layer)
282 {
283     mTexture2DArray.set(texture);
284 }
285 
~Texture2DArrayAttachment()286 Texture2DArrayAttachment::~Texture2DArrayAttachment()
287 {
288     mTexture2DArray.set(NULL);
289 }
290 
addProxyRef(const FramebufferAttachment * proxy)291 void Texture2DArrayAttachment::addProxyRef(const FramebufferAttachment *proxy)
292 {
293     mTexture2DArray->addProxyRef(proxy);
294 }
295 
releaseProxy(const FramebufferAttachment * proxy)296 void Texture2DArrayAttachment::releaseProxy(const FramebufferAttachment *proxy)
297 {
298     mTexture2DArray->releaseProxy(proxy);
299 }
300 
getRenderTarget()301 rx::RenderTarget *Texture2DArrayAttachment::getRenderTarget()
302 {
303     return mTexture2DArray->getRenderTarget(mLevel, mLayer);
304 }
305 
getDepthStencil()306 rx::RenderTarget *Texture2DArrayAttachment::getDepthStencil()
307 {
308     return mTexture2DArray->getDepthStencil(mLevel, mLayer);
309 }
310 
getTextureStorage()311 rx::TextureStorage *Texture2DArrayAttachment::getTextureStorage()
312 {
313     return mTexture2DArray->getNativeTexture()->getStorageInstance();
314 }
315 
getWidth() const316 GLsizei Texture2DArrayAttachment::getWidth() const
317 {
318     return mTexture2DArray->getWidth(mLevel);
319 }
320 
getHeight() const321 GLsizei Texture2DArrayAttachment::getHeight() const
322 {
323     return mTexture2DArray->getHeight(mLevel);
324 }
325 
getInternalFormat() const326 GLenum Texture2DArrayAttachment::getInternalFormat() const
327 {
328     return mTexture2DArray->getInternalFormat(mLevel);
329 }
330 
getActualFormat() const331 GLenum Texture2DArrayAttachment::getActualFormat() const
332 {
333     return mTexture2DArray->getActualFormat(mLevel);
334 }
335 
getSamples() const336 GLsizei Texture2DArrayAttachment::getSamples() const
337 {
338     return 0;
339 }
340 
getSerial() const341 unsigned int Texture2DArrayAttachment::getSerial() const
342 {
343     return mTexture2DArray->getRenderTargetSerial(mLevel, mLayer);
344 }
345 
isTexture() const346 bool Texture2DArrayAttachment::isTexture() const
347 {
348     return true;
349 }
350 
getTextureSerial() const351 unsigned int Texture2DArrayAttachment::getTextureSerial() const
352 {
353     return mTexture2DArray->getTextureSerial();
354 }
355 
356 ////// FramebufferAttachment Implementation //////
357 
FramebufferAttachment(rx::Renderer * renderer,GLuint id,FramebufferAttachmentInterface * instance)358 FramebufferAttachment::FramebufferAttachment(rx::Renderer *renderer, GLuint id, FramebufferAttachmentInterface *instance) : RefCountObject(id)
359 {
360     ASSERT(instance != NULL);
361     mInstance = instance;
362 
363     ASSERT(renderer != NULL);
364     mRenderer = renderer;
365 }
366 
~FramebufferAttachment()367 FramebufferAttachment::~FramebufferAttachment()
368 {
369     delete mInstance;
370 }
371 
372 // The FramebufferAttachmentInterface contained in this FramebufferAttachment may need to maintain
373 // its own reference count, so we pass it on here.
addRef() const374 void FramebufferAttachment::addRef() const
375 {
376     mInstance->addProxyRef(this);
377 
378     RefCountObject::addRef();
379 }
380 
release() const381 void FramebufferAttachment::release() const
382 {
383     mInstance->releaseProxy(this);
384 
385     RefCountObject::release();
386 }
387 
getRenderTarget()388 rx::RenderTarget *FramebufferAttachment::getRenderTarget()
389 {
390     return mInstance->getRenderTarget();
391 }
392 
getDepthStencil()393 rx::RenderTarget *FramebufferAttachment::getDepthStencil()
394 {
395     return mInstance->getDepthStencil();
396 }
397 
getTextureStorage()398 rx::TextureStorage *FramebufferAttachment::getTextureStorage()
399 {
400     return mInstance->getTextureStorage();
401 }
402 
getWidth() const403 GLsizei FramebufferAttachment::getWidth() const
404 {
405     return mInstance->getWidth();
406 }
407 
getHeight() const408 GLsizei FramebufferAttachment::getHeight() const
409 {
410     return mInstance->getHeight();
411 }
412 
getInternalFormat() const413 GLenum FramebufferAttachment::getInternalFormat() const
414 {
415     return mInstance->getInternalFormat();
416 }
417 
getActualFormat() const418 GLenum FramebufferAttachment::getActualFormat() const
419 {
420     return mInstance->getActualFormat();
421 }
422 
getRedSize() const423 GLuint FramebufferAttachment::getRedSize() const
424 {
425     return gl::GetRedBits(getActualFormat(), mRenderer->getCurrentClientVersion());
426 }
427 
getGreenSize() const428 GLuint FramebufferAttachment::getGreenSize() const
429 {
430     return gl::GetGreenBits(getActualFormat(), mRenderer->getCurrentClientVersion());
431 }
432 
getBlueSize() const433 GLuint FramebufferAttachment::getBlueSize() const
434 {
435     return gl::GetBlueBits(getActualFormat(), mRenderer->getCurrentClientVersion());
436 }
437 
getAlphaSize() const438 GLuint FramebufferAttachment::getAlphaSize() const
439 {
440     return gl::GetAlphaBits(getActualFormat(), mRenderer->getCurrentClientVersion());
441 }
442 
getDepthSize() const443 GLuint FramebufferAttachment::getDepthSize() const
444 {
445     return gl::GetDepthBits(getActualFormat(), mRenderer->getCurrentClientVersion());
446 }
447 
getStencilSize() const448 GLuint FramebufferAttachment::getStencilSize() const
449 {
450     return gl::GetStencilBits(getActualFormat(), mRenderer->getCurrentClientVersion());
451 }
452 
getComponentType() const453 GLenum FramebufferAttachment::getComponentType() const
454 {
455     return gl::GetComponentType(getActualFormat(), mRenderer->getCurrentClientVersion());
456 }
457 
getColorEncoding() const458 GLenum FramebufferAttachment::getColorEncoding() const
459 {
460     return gl::GetColorEncoding(getActualFormat(), mRenderer->getCurrentClientVersion());
461 }
462 
getSamples() const463 GLsizei FramebufferAttachment::getSamples() const
464 {
465     return mInstance->getSamples();
466 }
467 
getSerial() const468 unsigned int FramebufferAttachment::getSerial() const
469 {
470     return mInstance->getSerial();
471 }
472 
isTexture() const473 bool FramebufferAttachment::isTexture() const
474 {
475     return mInstance->isTexture();
476 }
477 
getTextureSerial() const478 unsigned int FramebufferAttachment::getTextureSerial() const
479 {
480     return mInstance->getTextureSerial();
481 }
482 
setStorage(RenderbufferStorage * newStorage)483 void FramebufferAttachment::setStorage(RenderbufferStorage *newStorage)
484 {
485     ASSERT(newStorage != NULL);
486 
487     delete mInstance;
488     mInstance = newStorage;
489 }
490 
491 }
492