blob: 574ce7ee9129d00e25482f61663ed9d0b40bea17 [file] [log] [blame]
Jamie Madillafc21c02014-06-04 15:29:47 -04001#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
21namespace gl
22{
23
24FramebufferAttachmentInterface::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.
31void FramebufferAttachmentInterface::addProxyRef(const FramebufferAttachment *proxy)
32{
33}
34
35void FramebufferAttachmentInterface::releaseProxy(const FramebufferAttachment *proxy)
36{
37}
38
39///// Texture2DAttachment Implementation ////////
40
41Texture2DAttachment::Texture2DAttachment(Texture2D *texture, GLint level) : mLevel(level)
42{
43 mTexture2D.set(texture);
44}
45
46Texture2DAttachment::~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.
53void Texture2DAttachment::addProxyRef(const FramebufferAttachment *proxy)
54{
55 mTexture2D->addProxyRef(proxy);
56}
57
58void Texture2DAttachment::releaseProxy(const FramebufferAttachment *proxy)
59{
60 mTexture2D->releaseProxy(proxy);
61}
62
63rx::RenderTarget *Texture2DAttachment::getRenderTarget()
64{
65 return mTexture2D->getRenderTarget(mLevel);
66}
67
68rx::RenderTarget *Texture2DAttachment::getDepthStencil()
69{
70 return mTexture2D->getDepthSencil(mLevel);
71}
72
73rx::TextureStorage *Texture2DAttachment::getTextureStorage()
74{
75 return mTexture2D->getNativeTexture()->getStorageInstance();
76}
77
78GLsizei Texture2DAttachment::getWidth() const
79{
80 return mTexture2D->getWidth(mLevel);
81}
82
83GLsizei Texture2DAttachment::getHeight() const
84{
85 return mTexture2D->getHeight(mLevel);
86}
87
88GLenum Texture2DAttachment::getInternalFormat() const
89{
90 return mTexture2D->getInternalFormat(mLevel);
91}
92
93GLenum Texture2DAttachment::getActualFormat() const
94{
95 return mTexture2D->getActualFormat(mLevel);
96}
97
98GLsizei Texture2DAttachment::getSamples() const
99{
100 return 0;
101}
102
103unsigned int Texture2DAttachment::getSerial() const
104{
105 return mTexture2D->getRenderTargetSerial(mLevel);
106}
107
108bool Texture2DAttachment::isTexture() const
109{
110 return true;
111}
112
113unsigned int Texture2DAttachment::getTextureSerial() const
114{
115 return mTexture2D->getTextureSerial();
116}
117
118///// TextureCubeMapAttachment Implementation ////////
119
120TextureCubeMapAttachment::TextureCubeMapAttachment(TextureCubeMap *texture, GLenum faceTarget, GLint level)
121 : mFaceTarget(faceTarget), mLevel(level)
122{
123 mTextureCubeMap.set(texture);
124}
125
126TextureCubeMapAttachment::~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.
133void TextureCubeMapAttachment::addProxyRef(const FramebufferAttachment *proxy)
134{
135 mTextureCubeMap->addProxyRef(proxy);
136}
137
138void TextureCubeMapAttachment::releaseProxy(const FramebufferAttachment *proxy)
139{
140 mTextureCubeMap->releaseProxy(proxy);
141}
142
143rx::RenderTarget *TextureCubeMapAttachment::getRenderTarget()
144{
145 return mTextureCubeMap->getRenderTarget(mFaceTarget, mLevel);
146}
147
148rx::RenderTarget *TextureCubeMapAttachment::getDepthStencil()
149{
150 return mTextureCubeMap->getDepthStencil(mFaceTarget, mLevel);
151}
152
153rx::TextureStorage *TextureCubeMapAttachment::getTextureStorage()
154{
155 return mTextureCubeMap->getNativeTexture()->getStorageInstance();
156}
157
158GLsizei TextureCubeMapAttachment::getWidth() const
159{
160 return mTextureCubeMap->getWidth(mFaceTarget, mLevel);
161}
162
163GLsizei TextureCubeMapAttachment::getHeight() const
164{
165 return mTextureCubeMap->getHeight(mFaceTarget, mLevel);
166}
167
168GLenum TextureCubeMapAttachment::getInternalFormat() const
169{
170 return mTextureCubeMap->getInternalFormat(mFaceTarget, mLevel);
171}
172
173GLenum TextureCubeMapAttachment::getActualFormat() const
174{
175 return mTextureCubeMap->getActualFormat(mFaceTarget, mLevel);
176}
177
178GLsizei TextureCubeMapAttachment::getSamples() const
179{
180 return 0;
181}
182
183unsigned int TextureCubeMapAttachment::getSerial() const
184{
185 return mTextureCubeMap->getRenderTargetSerial(mFaceTarget, mLevel);
186}
187
188bool TextureCubeMapAttachment::isTexture() const
189{
190 return true;
191}
192
193unsigned int TextureCubeMapAttachment::getTextureSerial() const
194{
195 return mTextureCubeMap->getTextureSerial();
196}
197
198///// Texture3DAttachment Implementation ////////
199
200Texture3DAttachment::Texture3DAttachment(Texture3D *texture, GLint level, GLint layer)
201 : mLevel(level), mLayer(layer)
202{
203 mTexture3D.set(texture);
204}
205
206Texture3DAttachment::~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.
213void Texture3DAttachment::addProxyRef(const FramebufferAttachment *proxy)
214{
215 mTexture3D->addProxyRef(proxy);
216}
217
218void Texture3DAttachment::releaseProxy(const FramebufferAttachment *proxy)
219{
220 mTexture3D->releaseProxy(proxy);
221}
222
223rx::RenderTarget *Texture3DAttachment::getRenderTarget()
224{
225 return mTexture3D->getRenderTarget(mLevel, mLayer);
226}
227
228rx::RenderTarget *Texture3DAttachment::getDepthStencil()
229{
230 return mTexture3D->getDepthStencil(mLevel, mLayer);
231}
232
233rx::TextureStorage *Texture3DAttachment::getTextureStorage()
234{
235 return mTexture3D->getNativeTexture()->getStorageInstance();
236}
237
238GLsizei Texture3DAttachment::getWidth() const
239{
240 return mTexture3D->getWidth(mLevel);
241}
242
243GLsizei Texture3DAttachment::getHeight() const
244{
245 return mTexture3D->getHeight(mLevel);
246}
247
248GLenum Texture3DAttachment::getInternalFormat() const
249{
250 return mTexture3D->getInternalFormat(mLevel);
251}
252
253GLenum Texture3DAttachment::getActualFormat() const
254{
255 return mTexture3D->getActualFormat(mLevel);
256}
257
258GLsizei Texture3DAttachment::getSamples() const
259{
260 return 0;
261}
262
263unsigned int Texture3DAttachment::getSerial() const
264{
265 return mTexture3D->getRenderTargetSerial(mLevel, mLayer);
266}
267
268bool Texture3DAttachment::isTexture() const
269{
270 return true;
271}
272
273unsigned int Texture3DAttachment::getTextureSerial() const
274{
275 return mTexture3D->getTextureSerial();
276}
277
278////// Texture2DArrayAttachment Implementation //////
279
280Texture2DArrayAttachment::Texture2DArrayAttachment(Texture2DArray *texture, GLint level, GLint layer)
281 : mLevel(level), mLayer(layer)
282{
283 mTexture2DArray.set(texture);
284}
285
286Texture2DArrayAttachment::~Texture2DArrayAttachment()
287{
288 mTexture2DArray.set(NULL);
289}
290
291void Texture2DArrayAttachment::addProxyRef(const FramebufferAttachment *proxy)
292{
293 mTexture2DArray->addProxyRef(proxy);
294}
295
296void Texture2DArrayAttachment::releaseProxy(const FramebufferAttachment *proxy)
297{
298 mTexture2DArray->releaseProxy(proxy);
299}
300
301rx::RenderTarget *Texture2DArrayAttachment::getRenderTarget()
302{
303 return mTexture2DArray->getRenderTarget(mLevel, mLayer);
304}
305
306rx::RenderTarget *Texture2DArrayAttachment::getDepthStencil()
307{
308 return mTexture2DArray->getDepthStencil(mLevel, mLayer);
309}
310
311rx::TextureStorage *Texture2DArrayAttachment::getTextureStorage()
312{
313 return mTexture2DArray->getNativeTexture()->getStorageInstance();
314}
315
316GLsizei Texture2DArrayAttachment::getWidth() const
317{
318 return mTexture2DArray->getWidth(mLevel);
319}
320
321GLsizei Texture2DArrayAttachment::getHeight() const
322{
323 return mTexture2DArray->getHeight(mLevel);
324}
325
326GLenum Texture2DArrayAttachment::getInternalFormat() const
327{
328 return mTexture2DArray->getInternalFormat(mLevel);
329}
330
331GLenum Texture2DArrayAttachment::getActualFormat() const
332{
333 return mTexture2DArray->getActualFormat(mLevel);
334}
335
336GLsizei Texture2DArrayAttachment::getSamples() const
337{
338 return 0;
339}
340
341unsigned int Texture2DArrayAttachment::getSerial() const
342{
343 return mTexture2DArray->getRenderTargetSerial(mLevel, mLayer);
344}
345
346bool Texture2DArrayAttachment::isTexture() const
347{
348 return true;
349}
350
351unsigned int Texture2DArrayAttachment::getTextureSerial() const
352{
353 return mTexture2DArray->getTextureSerial();
354}
355
356////// FramebufferAttachment Implementation //////
357
358FramebufferAttachment::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
367FramebufferAttachment::~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.
374void FramebufferAttachment::addRef() const
375{
376 mInstance->addProxyRef(this);
377
378 RefCountObject::addRef();
379}
380
381void FramebufferAttachment::release() const
382{
383 mInstance->releaseProxy(this);
384
385 RefCountObject::release();
386}
387
388rx::RenderTarget *FramebufferAttachment::getRenderTarget()
389{
390 return mInstance->getRenderTarget();
391}
392
393rx::RenderTarget *FramebufferAttachment::getDepthStencil()
394{
395 return mInstance->getDepthStencil();
396}
397
398rx::TextureStorage *FramebufferAttachment::getTextureStorage()
399{
400 return mInstance->getTextureStorage();
401}
402
403GLsizei FramebufferAttachment::getWidth() const
404{
405 return mInstance->getWidth();
406}
407
408GLsizei FramebufferAttachment::getHeight() const
409{
410 return mInstance->getHeight();
411}
412
413GLenum FramebufferAttachment::getInternalFormat() const
414{
415 return mInstance->getInternalFormat();
416}
417
418GLenum FramebufferAttachment::getActualFormat() const
419{
420 return mInstance->getActualFormat();
421}
422
423GLuint FramebufferAttachment::getRedSize() const
424{
425 return gl::GetRedBits(getActualFormat(), mRenderer->getCurrentClientVersion());
426}
427
428GLuint FramebufferAttachment::getGreenSize() const
429{
430 return gl::GetGreenBits(getActualFormat(), mRenderer->getCurrentClientVersion());
431}
432
433GLuint FramebufferAttachment::getBlueSize() const
434{
435 return gl::GetBlueBits(getActualFormat(), mRenderer->getCurrentClientVersion());
436}
437
438GLuint FramebufferAttachment::getAlphaSize() const
439{
440 return gl::GetAlphaBits(getActualFormat(), mRenderer->getCurrentClientVersion());
441}
442
443GLuint FramebufferAttachment::getDepthSize() const
444{
445 return gl::GetDepthBits(getActualFormat(), mRenderer->getCurrentClientVersion());
446}
447
448GLuint FramebufferAttachment::getStencilSize() const
449{
450 return gl::GetStencilBits(getActualFormat(), mRenderer->getCurrentClientVersion());
451}
452
453GLenum FramebufferAttachment::getComponentType() const
454{
455 return gl::GetComponentType(getActualFormat(), mRenderer->getCurrentClientVersion());
456}
457
458GLenum FramebufferAttachment::getColorEncoding() const
459{
460 return gl::GetColorEncoding(getActualFormat(), mRenderer->getCurrentClientVersion());
461}
462
463GLsizei FramebufferAttachment::getSamples() const
464{
465 return mInstance->getSamples();
466}
467
468unsigned int FramebufferAttachment::getSerial() const
469{
470 return mInstance->getSerial();
471}
472
473bool FramebufferAttachment::isTexture() const
474{
475 return mInstance->isTexture();
476}
477
478unsigned int FramebufferAttachment::getTextureSerial() const
479{
480 return mInstance->getTextureSerial();
481}
482
483void FramebufferAttachment::setStorage(RenderbufferStorage *newStorage)
484{
485 ASSERT(newStorage != NULL);
486
487 delete mInstance;
488 mInstance = newStorage;
489}
490
491}