• Home
  • Line#
  • Scopes#
  • Navigate#
  • Raw
  • Download
1 #include "precompiled.h"
2 //
3 // Copyright (c) 2002-2012 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 // Renderbuffer.cpp: the gl::Renderbuffer class and its derived classes
9 // Colorbuffer, Depthbuffer and Stencilbuffer. Implements GL renderbuffer
10 // objects and related functionality. [OpenGL ES 2.0.24] section 4.4.3 page 108.
11 
12 #include "libGLESv2/Renderbuffer.h"
13 #include "libGLESv2/renderer/RenderTarget.h"
14 
15 #include "libGLESv2/Texture.h"
16 #include "libGLESv2/renderer/Renderer.h"
17 #include "libGLESv2/utilities.h"
18 
19 namespace gl
20 {
21 unsigned int RenderbufferStorage::mCurrentSerial = 1;
22 
RenderbufferInterface()23 RenderbufferInterface::RenderbufferInterface()
24 {
25 }
26 
27 // The default case for classes inherited from RenderbufferInterface is not to
28 // need to do anything upon the reference count to the parent Renderbuffer incrementing
29 // or decrementing.
addProxyRef(const Renderbuffer * proxy)30 void RenderbufferInterface::addProxyRef(const Renderbuffer *proxy)
31 {
32 }
33 
releaseProxy(const Renderbuffer * proxy)34 void RenderbufferInterface::releaseProxy(const Renderbuffer *proxy)
35 {
36 }
37 
getRedSize() const38 GLuint RenderbufferInterface::getRedSize() const
39 {
40     return gl::GetRedSize(getActualFormat());
41 }
42 
getGreenSize() const43 GLuint RenderbufferInterface::getGreenSize() const
44 {
45     return gl::GetGreenSize(getActualFormat());
46 }
47 
getBlueSize() const48 GLuint RenderbufferInterface::getBlueSize() const
49 {
50     return gl::GetBlueSize(getActualFormat());
51 }
52 
getAlphaSize() const53 GLuint RenderbufferInterface::getAlphaSize() const
54 {
55     return gl::GetAlphaSize(getActualFormat());
56 }
57 
getDepthSize() const58 GLuint RenderbufferInterface::getDepthSize() const
59 {
60     return gl::GetDepthSize(getActualFormat());
61 }
62 
getStencilSize() const63 GLuint RenderbufferInterface::getStencilSize() const
64 {
65     return gl::GetStencilSize(getActualFormat());
66 }
67 
68 ///// RenderbufferTexture2D Implementation ////////
69 
RenderbufferTexture2D(Texture2D * texture,GLenum target)70 RenderbufferTexture2D::RenderbufferTexture2D(Texture2D *texture, GLenum target) : mTarget(target)
71 {
72     mTexture2D.set(texture);
73 }
74 
~RenderbufferTexture2D()75 RenderbufferTexture2D::~RenderbufferTexture2D()
76 {
77     mTexture2D.set(NULL);
78 }
79 
80 // Textures need to maintain their own reference count for references via
81 // Renderbuffers acting as proxies. Here, we notify the texture of a reference.
addProxyRef(const Renderbuffer * proxy)82 void RenderbufferTexture2D::addProxyRef(const Renderbuffer *proxy)
83 {
84     mTexture2D->addProxyRef(proxy);
85 }
86 
releaseProxy(const Renderbuffer * proxy)87 void RenderbufferTexture2D::releaseProxy(const Renderbuffer *proxy)
88 {
89     mTexture2D->releaseProxy(proxy);
90 }
91 
getRenderTarget()92 rx::RenderTarget *RenderbufferTexture2D::getRenderTarget()
93 {
94     return mTexture2D->getRenderTarget(mTarget);
95 }
96 
getDepthStencil()97 rx::RenderTarget *RenderbufferTexture2D::getDepthStencil()
98 {
99     return mTexture2D->getDepthStencil(mTarget);
100 }
101 
getWidth() const102 GLsizei RenderbufferTexture2D::getWidth() const
103 {
104     return mTexture2D->getWidth(0);
105 }
106 
getHeight() const107 GLsizei RenderbufferTexture2D::getHeight() const
108 {
109     return mTexture2D->getHeight(0);
110 }
111 
getInternalFormat() const112 GLenum RenderbufferTexture2D::getInternalFormat() const
113 {
114     return mTexture2D->getInternalFormat(0);
115 }
116 
getActualFormat() const117 GLenum RenderbufferTexture2D::getActualFormat() const
118 {
119     return mTexture2D->getActualFormat(0);
120 }
121 
getSamples() const122 GLsizei RenderbufferTexture2D::getSamples() const
123 {
124     return 0;
125 }
126 
getSerial() const127 unsigned int RenderbufferTexture2D::getSerial() const
128 {
129     return mTexture2D->getRenderTargetSerial(mTarget);
130 }
131 
getTextureSerial() const132 unsigned int RenderbufferTexture2D::getTextureSerial() const
133 {
134     return mTexture2D->getTextureSerial();
135 }
136 
137 ///// RenderbufferTextureCubeMap Implementation ////////
138 
RenderbufferTextureCubeMap(TextureCubeMap * texture,GLenum target)139 RenderbufferTextureCubeMap::RenderbufferTextureCubeMap(TextureCubeMap *texture, GLenum target) : mTarget(target)
140 {
141     mTextureCubeMap.set(texture);
142 }
143 
~RenderbufferTextureCubeMap()144 RenderbufferTextureCubeMap::~RenderbufferTextureCubeMap()
145 {
146     mTextureCubeMap.set(NULL);
147 }
148 
149 // Textures need to maintain their own reference count for references via
150 // Renderbuffers acting as proxies. Here, we notify the texture of a reference.
addProxyRef(const Renderbuffer * proxy)151 void RenderbufferTextureCubeMap::addProxyRef(const Renderbuffer *proxy)
152 {
153     mTextureCubeMap->addProxyRef(proxy);
154 }
155 
releaseProxy(const Renderbuffer * proxy)156 void RenderbufferTextureCubeMap::releaseProxy(const Renderbuffer *proxy)
157 {
158     mTextureCubeMap->releaseProxy(proxy);
159 }
160 
getRenderTarget()161 rx::RenderTarget *RenderbufferTextureCubeMap::getRenderTarget()
162 {
163     return mTextureCubeMap->getRenderTarget(mTarget);
164 }
165 
getDepthStencil()166 rx::RenderTarget *RenderbufferTextureCubeMap::getDepthStencil()
167 {
168     return NULL;
169 }
170 
getWidth() const171 GLsizei RenderbufferTextureCubeMap::getWidth() const
172 {
173     return mTextureCubeMap->getWidth(GL_TEXTURE_CUBE_MAP_POSITIVE_X, 0);
174 }
175 
getHeight() const176 GLsizei RenderbufferTextureCubeMap::getHeight() const
177 {
178     return mTextureCubeMap->getHeight(GL_TEXTURE_CUBE_MAP_POSITIVE_X, 0);
179 }
180 
getInternalFormat() const181 GLenum RenderbufferTextureCubeMap::getInternalFormat() const
182 {
183     return mTextureCubeMap->getInternalFormat(GL_TEXTURE_CUBE_MAP_POSITIVE_X, 0);
184 }
185 
getActualFormat() const186 GLenum RenderbufferTextureCubeMap::getActualFormat() const
187 {
188     return mTextureCubeMap->getActualFormat(GL_TEXTURE_CUBE_MAP_POSITIVE_X, 0);
189 }
190 
getSamples() const191 GLsizei RenderbufferTextureCubeMap::getSamples() const
192 {
193     return 0;
194 }
195 
getSerial() const196 unsigned int RenderbufferTextureCubeMap::getSerial() const
197 {
198     return mTextureCubeMap->getRenderTargetSerial(mTarget);
199 }
200 
getTextureSerial() const201 unsigned int RenderbufferTextureCubeMap::getTextureSerial() const
202 {
203     return mTextureCubeMap->getTextureSerial();
204 }
205 
206 ////// Renderbuffer Implementation //////
207 
Renderbuffer(rx::Renderer * renderer,GLuint id,RenderbufferInterface * instance)208 Renderbuffer::Renderbuffer(rx::Renderer *renderer, GLuint id, RenderbufferInterface *instance) : RefCountObject(id)
209 {
210     ASSERT(instance != NULL);
211     mInstance = instance;
212 }
213 
~Renderbuffer()214 Renderbuffer::~Renderbuffer()
215 {
216     delete mInstance;
217 }
218 
219 // The RenderbufferInterface contained in this Renderbuffer may need to maintain
220 // its own reference count, so we pass it on here.
addRef() const221 void Renderbuffer::addRef() const
222 {
223     mInstance->addProxyRef(this);
224 
225     RefCountObject::addRef();
226 }
227 
release() const228 void Renderbuffer::release() const
229 {
230     mInstance->releaseProxy(this);
231 
232     RefCountObject::release();
233 }
234 
getRenderTarget()235 rx::RenderTarget *Renderbuffer::getRenderTarget()
236 {
237     return mInstance->getRenderTarget();
238 }
239 
getDepthStencil()240 rx::RenderTarget *Renderbuffer::getDepthStencil()
241 {
242     return mInstance->getDepthStencil();
243 }
244 
getWidth() const245 GLsizei Renderbuffer::getWidth() const
246 {
247     return mInstance->getWidth();
248 }
249 
getHeight() const250 GLsizei Renderbuffer::getHeight() const
251 {
252     return mInstance->getHeight();
253 }
254 
getInternalFormat() const255 GLenum Renderbuffer::getInternalFormat() const
256 {
257     return mInstance->getInternalFormat();
258 }
259 
getActualFormat() const260 GLenum Renderbuffer::getActualFormat() const
261 {
262     return mInstance->getActualFormat();
263 }
264 
getRedSize() const265 GLuint Renderbuffer::getRedSize() const
266 {
267     return mInstance->getRedSize();
268 }
269 
getGreenSize() const270 GLuint Renderbuffer::getGreenSize() const
271 {
272     return mInstance->getGreenSize();
273 }
274 
getBlueSize() const275 GLuint Renderbuffer::getBlueSize() const
276 {
277     return mInstance->getBlueSize();
278 }
279 
getAlphaSize() const280 GLuint Renderbuffer::getAlphaSize() const
281 {
282     return mInstance->getAlphaSize();
283 }
284 
getDepthSize() const285 GLuint Renderbuffer::getDepthSize() const
286 {
287     return mInstance->getDepthSize();
288 }
289 
getStencilSize() const290 GLuint Renderbuffer::getStencilSize() const
291 {
292     return mInstance->getStencilSize();
293 }
294 
getSamples() const295 GLsizei Renderbuffer::getSamples() const
296 {
297     return mInstance->getSamples();
298 }
299 
getSerial() const300 unsigned int Renderbuffer::getSerial() const
301 {
302     return mInstance->getSerial();
303 }
304 
getTextureSerial() const305 unsigned int Renderbuffer::getTextureSerial() const
306 {
307     return mInstance->getTextureSerial();
308 }
309 
setStorage(RenderbufferStorage * newStorage)310 void Renderbuffer::setStorage(RenderbufferStorage *newStorage)
311 {
312     ASSERT(newStorage != NULL);
313 
314     delete mInstance;
315     mInstance = newStorage;
316 }
317 
RenderbufferStorage()318 RenderbufferStorage::RenderbufferStorage() : mSerial(issueSerial())
319 {
320     mWidth = 0;
321     mHeight = 0;
322     mInternalFormat = GL_RGBA4;
323     mActualFormat = GL_RGBA8_OES;
324     mSamples = 0;
325 }
326 
~RenderbufferStorage()327 RenderbufferStorage::~RenderbufferStorage()
328 {
329 }
330 
getRenderTarget()331 rx::RenderTarget *RenderbufferStorage::getRenderTarget()
332 {
333     return NULL;
334 }
335 
getDepthStencil()336 rx::RenderTarget *RenderbufferStorage::getDepthStencil()
337 {
338     return NULL;
339 }
340 
getWidth() const341 GLsizei RenderbufferStorage::getWidth() const
342 {
343     return mWidth;
344 }
345 
getHeight() const346 GLsizei RenderbufferStorage::getHeight() const
347 {
348     return mHeight;
349 }
350 
getInternalFormat() const351 GLenum RenderbufferStorage::getInternalFormat() const
352 {
353     return mInternalFormat;
354 }
355 
getActualFormat() const356 GLenum RenderbufferStorage::getActualFormat() const
357 {
358     return mActualFormat;
359 }
360 
getSamples() const361 GLsizei RenderbufferStorage::getSamples() const
362 {
363     return mSamples;
364 }
365 
getSerial() const366 unsigned int RenderbufferStorage::getSerial() const
367 {
368     return mSerial;
369 }
370 
issueSerial()371 unsigned int RenderbufferStorage::issueSerial()
372 {
373     return mCurrentSerial++;
374 }
375 
issueCubeSerials()376 unsigned int RenderbufferStorage::issueCubeSerials()
377 {
378     unsigned int firstSerial = mCurrentSerial;
379     mCurrentSerial += 6;
380     return firstSerial;
381 }
382 
Colorbuffer(rx::Renderer * renderer,rx::SwapChain * swapChain)383 Colorbuffer::Colorbuffer(rx::Renderer *renderer, rx::SwapChain *swapChain)
384 {
385     mRenderTarget = renderer->createRenderTarget(swapChain, false);
386 
387     if (mRenderTarget)
388     {
389         mWidth = mRenderTarget->getWidth();
390         mHeight = mRenderTarget->getHeight();
391         mInternalFormat = mRenderTarget->getInternalFormat();
392         mActualFormat = mRenderTarget->getActualFormat();
393         mSamples = mRenderTarget->getSamples();
394     }
395 }
396 
Colorbuffer(rx::Renderer * renderer,int width,int height,GLenum format,GLsizei samples)397 Colorbuffer::Colorbuffer(rx::Renderer *renderer, int width, int height, GLenum format, GLsizei samples) : mRenderTarget(NULL)
398 {
399     mRenderTarget = renderer->createRenderTarget(width, height, format, samples, false);
400 
401     if (mRenderTarget)
402     {
403         mWidth = width;
404         mHeight = height;
405         mInternalFormat = format;
406         mActualFormat = mRenderTarget->getActualFormat();
407         mSamples = mRenderTarget->getSamples();
408     }
409 }
410 
~Colorbuffer()411 Colorbuffer::~Colorbuffer()
412 {
413     if (mRenderTarget)
414     {
415         delete mRenderTarget;
416     }
417 }
418 
getRenderTarget()419 rx::RenderTarget *Colorbuffer::getRenderTarget()
420 {
421     if (mRenderTarget)
422     {
423         return mRenderTarget;
424     }
425 
426     return NULL;
427 }
428 
DepthStencilbuffer(rx::Renderer * renderer,rx::SwapChain * swapChain)429 DepthStencilbuffer::DepthStencilbuffer(rx::Renderer *renderer, rx::SwapChain *swapChain)
430 {
431     mDepthStencil = renderer->createRenderTarget(swapChain, true);
432     if (mDepthStencil)
433     {
434         mWidth = mDepthStencil->getWidth();
435         mHeight = mDepthStencil->getHeight();
436         mInternalFormat = mDepthStencil->getInternalFormat();
437         mSamples = mDepthStencil->getSamples();
438         mActualFormat = mDepthStencil->getActualFormat();
439     }
440 }
441 
DepthStencilbuffer(rx::Renderer * renderer,int width,int height,GLsizei samples)442 DepthStencilbuffer::DepthStencilbuffer(rx::Renderer *renderer, int width, int height, GLsizei samples)
443 {
444 
445     mDepthStencil = renderer->createRenderTarget(width, height, GL_DEPTH24_STENCIL8_OES, samples, true);
446 
447     mWidth = mDepthStencil->getWidth();
448     mHeight = mDepthStencil->getHeight();
449     mInternalFormat = GL_DEPTH24_STENCIL8_OES;
450     mActualFormat = mDepthStencil->getActualFormat();
451     mSamples = mDepthStencil->getSamples();
452 }
453 
~DepthStencilbuffer()454 DepthStencilbuffer::~DepthStencilbuffer()
455 {
456     if (mDepthStencil)
457     {
458         delete mDepthStencil;
459     }
460 }
461 
getDepthStencil()462 rx::RenderTarget *DepthStencilbuffer::getDepthStencil()
463 {
464     if (mDepthStencil)
465     {
466         return mDepthStencil;
467     }
468 
469     return NULL;
470 }
471 
Depthbuffer(rx::Renderer * renderer,int width,int height,GLsizei samples)472 Depthbuffer::Depthbuffer(rx::Renderer *renderer, int width, int height, GLsizei samples) : DepthStencilbuffer(renderer, width, height, samples)
473 {
474     if (mDepthStencil)
475     {
476         mInternalFormat = GL_DEPTH_COMPONENT16;   // If the renderbuffer parameters are queried, the calling function
477                                                   // will expect one of the valid renderbuffer formats for use in
478                                                   // glRenderbufferStorage
479     }
480 }
481 
~Depthbuffer()482 Depthbuffer::~Depthbuffer()
483 {
484 }
485 
Stencilbuffer(rx::Renderer * renderer,int width,int height,GLsizei samples)486 Stencilbuffer::Stencilbuffer(rx::Renderer *renderer, int width, int height, GLsizei samples) : DepthStencilbuffer(renderer, width, height, samples)
487 {
488     if (mDepthStencil)
489     {
490         mInternalFormat = GL_STENCIL_INDEX8;   // If the renderbuffer parameters are queried, the calling function
491                                                // will expect one of the valid renderbuffer formats for use in
492                                                // glRenderbufferStorage
493     }
494 }
495 
~Stencilbuffer()496 Stencilbuffer::~Stencilbuffer()
497 {
498 }
499 
500 }
501