Nicolas Capens | 0bac285 | 2016-05-07 06:09:58 -0400 | [diff] [blame] | 1 | // Copyright 2016 The SwiftShader Authors. All Rights Reserved. |
John Bauman | 66b8ab2 | 2014-05-06 15:57:45 -0400 | [diff] [blame] | 2 | // |
Nicolas Capens | 0bac285 | 2016-05-07 06:09:58 -0400 | [diff] [blame] | 3 | // Licensed under the Apache License, Version 2.0 (the "License"); |
| 4 | // you may not use this file except in compliance with the License. |
| 5 | // You may obtain a copy of the License at |
John Bauman | 66b8ab2 | 2014-05-06 15:57:45 -0400 | [diff] [blame] | 6 | // |
Nicolas Capens | 0bac285 | 2016-05-07 06:09:58 -0400 | [diff] [blame] | 7 | // http://www.apache.org/licenses/LICENSE-2.0 |
John Bauman | 66b8ab2 | 2014-05-06 15:57:45 -0400 | [diff] [blame] | 8 | // |
Nicolas Capens | 0bac285 | 2016-05-07 06:09:58 -0400 | [diff] [blame] | 9 | // Unless required by applicable law or agreed to in writing, software |
| 10 | // distributed under the License is distributed on an "AS IS" BASIS, |
| 11 | // WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. |
| 12 | // See the License for the specific language governing permissions and |
| 13 | // limitations under the License. |
John Bauman | 66b8ab2 | 2014-05-06 15:57:45 -0400 | [diff] [blame] | 14 | |
| 15 | // Renderbuffer.cpp: the Renderbuffer class and its derived classes |
| 16 | // Colorbuffer, Depthbuffer and Stencilbuffer. Implements GL renderbuffer |
| 17 | // objects and related functionality. [OpenGL ES 2.0.24] section 4.4.3 page 108. |
| 18 | |
| 19 | #include "Renderbuffer.h" |
| 20 | |
| 21 | #include "main.h" |
| 22 | #include "Texture.h" |
| 23 | #include "utilities.h" |
| 24 | |
Nicolas Capens | 14ee762 | 2014-10-28 23:48:41 -0400 | [diff] [blame] | 25 | namespace es2 |
John Bauman | 66b8ab2 | 2014-05-06 15:57:45 -0400 | [diff] [blame] | 26 | { |
| 27 | RenderbufferInterface::RenderbufferInterface() |
| 28 | { |
| 29 | } |
| 30 | |
| 31 | // The default case for classes inherited from RenderbufferInterface is not to |
| 32 | // need to do anything upon the reference count to the parent Renderbuffer incrementing |
Nicolas Capens | 0bac285 | 2016-05-07 06:09:58 -0400 | [diff] [blame] | 33 | // or decrementing. |
John Bauman | 66b8ab2 | 2014-05-06 15:57:45 -0400 | [diff] [blame] | 34 | void RenderbufferInterface::addProxyRef(const Renderbuffer *proxy) |
| 35 | { |
| 36 | } |
| 37 | |
| 38 | void RenderbufferInterface::releaseProxy(const Renderbuffer *proxy) |
| 39 | { |
| 40 | } |
| 41 | |
| 42 | GLuint RenderbufferInterface::getRedSize() const |
| 43 | { |
| 44 | return sw2es::GetRedSize(getInternalFormat()); |
| 45 | } |
| 46 | |
| 47 | GLuint RenderbufferInterface::getGreenSize() const |
| 48 | { |
| 49 | return sw2es::GetGreenSize(getInternalFormat()); |
| 50 | } |
| 51 | |
| 52 | GLuint RenderbufferInterface::getBlueSize() const |
| 53 | { |
| 54 | return sw2es::GetBlueSize(getInternalFormat()); |
| 55 | } |
| 56 | |
| 57 | GLuint RenderbufferInterface::getAlphaSize() const |
| 58 | { |
| 59 | return sw2es::GetAlphaSize(getInternalFormat()); |
| 60 | } |
| 61 | |
| 62 | GLuint RenderbufferInterface::getDepthSize() const |
| 63 | { |
| 64 | return sw2es::GetDepthSize(getInternalFormat()); |
| 65 | } |
| 66 | |
| 67 | GLuint RenderbufferInterface::getStencilSize() const |
| 68 | { |
| 69 | return sw2es::GetStencilSize(getInternalFormat()); |
| 70 | } |
| 71 | |
| 72 | ///// RenderbufferTexture2D Implementation //////// |
| 73 | |
Alexis Hetu | 8af5007 | 2015-04-29 14:29:49 -0400 | [diff] [blame] | 74 | RenderbufferTexture2D::RenderbufferTexture2D(Texture2D *texture, GLint level) : mLevel(level) |
John Bauman | 66b8ab2 | 2014-05-06 15:57:45 -0400 | [diff] [blame] | 75 | { |
Nicolas Capens | d7d9b4b | 2015-01-29 23:46:44 -0500 | [diff] [blame] | 76 | mTexture2D = texture; |
John Bauman | 66b8ab2 | 2014-05-06 15:57:45 -0400 | [diff] [blame] | 77 | } |
| 78 | |
| 79 | RenderbufferTexture2D::~RenderbufferTexture2D() |
| 80 | { |
Nicolas Capens | d7d9b4b | 2015-01-29 23:46:44 -0500 | [diff] [blame] | 81 | mTexture2D = NULL; |
John Bauman | 66b8ab2 | 2014-05-06 15:57:45 -0400 | [diff] [blame] | 82 | } |
| 83 | |
| 84 | // Textures need to maintain their own reference count for references via |
| 85 | // Renderbuffers acting as proxies. Here, we notify the texture of a reference. |
| 86 | void RenderbufferTexture2D::addProxyRef(const Renderbuffer *proxy) |
| 87 | { |
Alexis Hetu | b027aa9 | 2015-01-19 15:56:12 -0500 | [diff] [blame] | 88 | mTexture2D->addProxyRef(proxy); |
John Bauman | 66b8ab2 | 2014-05-06 15:57:45 -0400 | [diff] [blame] | 89 | } |
| 90 | |
| 91 | void RenderbufferTexture2D::releaseProxy(const Renderbuffer *proxy) |
| 92 | { |
Alexis Hetu | b027aa9 | 2015-01-19 15:56:12 -0500 | [diff] [blame] | 93 | mTexture2D->releaseProxy(proxy); |
John Bauman | 66b8ab2 | 2014-05-06 15:57:45 -0400 | [diff] [blame] | 94 | } |
| 95 | |
Nicolas Capens | 6e77a64 | 2014-06-12 00:13:37 -0400 | [diff] [blame] | 96 | // Increments refcount on image. |
| 97 | // caller must release() the returned image |
Nicolas Capens | ead7ac5 | 2014-10-27 23:56:02 -0400 | [diff] [blame] | 98 | egl::Image *RenderbufferTexture2D::getRenderTarget() |
John Bauman | 66b8ab2 | 2014-05-06 15:57:45 -0400 | [diff] [blame] | 99 | { |
Alexis Hetu | 8af5007 | 2015-04-29 14:29:49 -0400 | [diff] [blame] | 100 | return mTexture2D->getRenderTarget(GL_TEXTURE_2D, mLevel); |
John Bauman | 66b8ab2 | 2014-05-06 15:57:45 -0400 | [diff] [blame] | 101 | } |
| 102 | |
Nicolas Capens | 6e77a64 | 2014-06-12 00:13:37 -0400 | [diff] [blame] | 103 | // Increments refcount on image. |
| 104 | // caller must release() the returned image |
Nicolas Capens | ead7ac5 | 2014-10-27 23:56:02 -0400 | [diff] [blame] | 105 | egl::Image *RenderbufferTexture2D::createSharedImage() |
Nicolas Capens | 6e77a64 | 2014-06-12 00:13:37 -0400 | [diff] [blame] | 106 | { |
Alexis Hetu | 8af5007 | 2015-04-29 14:29:49 -0400 | [diff] [blame] | 107 | return mTexture2D->createSharedImage(GL_TEXTURE_2D, mLevel); |
Nicolas Capens | 6e77a64 | 2014-06-12 00:13:37 -0400 | [diff] [blame] | 108 | } |
| 109 | |
| 110 | bool RenderbufferTexture2D::isShared() const |
| 111 | { |
Alexis Hetu | 8af5007 | 2015-04-29 14:29:49 -0400 | [diff] [blame] | 112 | return mTexture2D->isShared(GL_TEXTURE_2D, mLevel); |
Nicolas Capens | 6e77a64 | 2014-06-12 00:13:37 -0400 | [diff] [blame] | 113 | } |
| 114 | |
John Bauman | 66b8ab2 | 2014-05-06 15:57:45 -0400 | [diff] [blame] | 115 | GLsizei RenderbufferTexture2D::getWidth() const |
| 116 | { |
Alexis Hetu | 8af5007 | 2015-04-29 14:29:49 -0400 | [diff] [blame] | 117 | return mTexture2D->getWidth(GL_TEXTURE_2D, mLevel); |
John Bauman | 66b8ab2 | 2014-05-06 15:57:45 -0400 | [diff] [blame] | 118 | } |
| 119 | |
| 120 | GLsizei RenderbufferTexture2D::getHeight() const |
| 121 | { |
Alexis Hetu | 8af5007 | 2015-04-29 14:29:49 -0400 | [diff] [blame] | 122 | return mTexture2D->getHeight(GL_TEXTURE_2D, mLevel); |
John Bauman | 66b8ab2 | 2014-05-06 15:57:45 -0400 | [diff] [blame] | 123 | } |
| 124 | |
| 125 | GLenum RenderbufferTexture2D::getFormat() const |
| 126 | { |
Alexis Hetu | 8af5007 | 2015-04-29 14:29:49 -0400 | [diff] [blame] | 127 | return mTexture2D->getFormat(GL_TEXTURE_2D, mLevel); |
John Bauman | 66b8ab2 | 2014-05-06 15:57:45 -0400 | [diff] [blame] | 128 | } |
| 129 | |
| 130 | sw::Format RenderbufferTexture2D::getInternalFormat() const |
| 131 | { |
Alexis Hetu | 8af5007 | 2015-04-29 14:29:49 -0400 | [diff] [blame] | 132 | return mTexture2D->getInternalFormat(GL_TEXTURE_2D, mLevel); |
John Bauman | 66b8ab2 | 2014-05-06 15:57:45 -0400 | [diff] [blame] | 133 | } |
| 134 | |
| 135 | GLsizei RenderbufferTexture2D::getSamples() const |
| 136 | { |
| 137 | return 0; |
| 138 | } |
| 139 | |
Alexis Hetu | b027aa9 | 2015-01-19 15:56:12 -0500 | [diff] [blame] | 140 | ///// RenderbufferTexture3D Implementation //////// |
| 141 | |
Alexis Hetu | 8af5007 | 2015-04-29 14:29:49 -0400 | [diff] [blame] | 142 | RenderbufferTexture3D::RenderbufferTexture3D(Texture3D *texture, GLint level, GLint layer) : mLevel(level), mLayer(layer) |
Alexis Hetu | b027aa9 | 2015-01-19 15:56:12 -0500 | [diff] [blame] | 143 | { |
Nicolas Capens | d7d9b4b | 2015-01-29 23:46:44 -0500 | [diff] [blame] | 144 | mTexture3D = texture; |
Alexis Hetu | 8af5007 | 2015-04-29 14:29:49 -0400 | [diff] [blame] | 145 | if(mLayer != 0) |
| 146 | { |
| 147 | UNIMPLEMENTED(); |
| 148 | } |
Alexis Hetu | b027aa9 | 2015-01-19 15:56:12 -0500 | [diff] [blame] | 149 | } |
| 150 | |
| 151 | RenderbufferTexture3D::~RenderbufferTexture3D() |
| 152 | { |
Nicolas Capens | d7d9b4b | 2015-01-29 23:46:44 -0500 | [diff] [blame] | 153 | mTexture3D = NULL; |
Alexis Hetu | b027aa9 | 2015-01-19 15:56:12 -0500 | [diff] [blame] | 154 | } |
| 155 | |
| 156 | // Textures need to maintain their own reference count for references via |
| 157 | // Renderbuffers acting as proxies. Here, we notify the texture of a reference. |
| 158 | void RenderbufferTexture3D::addProxyRef(const Renderbuffer *proxy) |
| 159 | { |
| 160 | mTexture3D->addProxyRef(proxy); |
| 161 | } |
| 162 | |
| 163 | void RenderbufferTexture3D::releaseProxy(const Renderbuffer *proxy) |
| 164 | { |
| 165 | mTexture3D->releaseProxy(proxy); |
| 166 | } |
| 167 | |
| 168 | // Increments refcount on image. |
| 169 | // caller must release() the returned image |
| 170 | egl::Image *RenderbufferTexture3D::getRenderTarget() |
| 171 | { |
Alexis Hetu | 8af5007 | 2015-04-29 14:29:49 -0400 | [diff] [blame] | 172 | return mTexture3D->getRenderTarget(mTexture3D->getTarget(), mLevel); |
Alexis Hetu | b027aa9 | 2015-01-19 15:56:12 -0500 | [diff] [blame] | 173 | } |
| 174 | |
| 175 | // Increments refcount on image. |
| 176 | // caller must release() the returned image |
| 177 | egl::Image *RenderbufferTexture3D::createSharedImage() |
| 178 | { |
Alexis Hetu | 8af5007 | 2015-04-29 14:29:49 -0400 | [diff] [blame] | 179 | return mTexture3D->createSharedImage(mTexture3D->getTarget(), mLevel); |
Alexis Hetu | b027aa9 | 2015-01-19 15:56:12 -0500 | [diff] [blame] | 180 | } |
| 181 | |
| 182 | bool RenderbufferTexture3D::isShared() const |
| 183 | { |
Alexis Hetu | 8af5007 | 2015-04-29 14:29:49 -0400 | [diff] [blame] | 184 | return mTexture3D->isShared(mTexture3D->getTarget(), mLevel); |
Alexis Hetu | b027aa9 | 2015-01-19 15:56:12 -0500 | [diff] [blame] | 185 | } |
| 186 | |
| 187 | GLsizei RenderbufferTexture3D::getWidth() const |
| 188 | { |
Alexis Hetu | 8af5007 | 2015-04-29 14:29:49 -0400 | [diff] [blame] | 189 | return mTexture3D->getWidth(mTexture3D->getTarget(), mLevel); |
Alexis Hetu | b027aa9 | 2015-01-19 15:56:12 -0500 | [diff] [blame] | 190 | } |
| 191 | |
| 192 | GLsizei RenderbufferTexture3D::getHeight() const |
| 193 | { |
Alexis Hetu | 8af5007 | 2015-04-29 14:29:49 -0400 | [diff] [blame] | 194 | return mTexture3D->getHeight(mTexture3D->getTarget(), mLevel); |
Alexis Hetu | b027aa9 | 2015-01-19 15:56:12 -0500 | [diff] [blame] | 195 | } |
| 196 | |
Alexis Hetu | e23029a | 2015-12-04 17:12:35 -0500 | [diff] [blame] | 197 | GLsizei RenderbufferTexture3D::getDepth() const |
| 198 | { |
| 199 | return mTexture3D->getDepth(mTexture3D->getTarget(), mLevel); |
| 200 | } |
| 201 | |
Alexis Hetu | b027aa9 | 2015-01-19 15:56:12 -0500 | [diff] [blame] | 202 | GLenum RenderbufferTexture3D::getFormat() const |
| 203 | { |
Alexis Hetu | 8af5007 | 2015-04-29 14:29:49 -0400 | [diff] [blame] | 204 | return mTexture3D->getFormat(mTexture3D->getTarget(), mLevel); |
Alexis Hetu | b027aa9 | 2015-01-19 15:56:12 -0500 | [diff] [blame] | 205 | } |
| 206 | |
| 207 | sw::Format RenderbufferTexture3D::getInternalFormat() const |
| 208 | { |
Alexis Hetu | 8af5007 | 2015-04-29 14:29:49 -0400 | [diff] [blame] | 209 | return mTexture3D->getInternalFormat(mTexture3D->getTarget(), mLevel); |
Alexis Hetu | b027aa9 | 2015-01-19 15:56:12 -0500 | [diff] [blame] | 210 | } |
| 211 | |
| 212 | GLsizei RenderbufferTexture3D::getSamples() const |
| 213 | { |
| 214 | return 0; |
| 215 | } |
| 216 | |
John Bauman | 66b8ab2 | 2014-05-06 15:57:45 -0400 | [diff] [blame] | 217 | ///// RenderbufferTextureCubeMap Implementation //////// |
| 218 | |
Alexis Hetu | 8af5007 | 2015-04-29 14:29:49 -0400 | [diff] [blame] | 219 | RenderbufferTextureCubeMap::RenderbufferTextureCubeMap(TextureCubeMap *texture, GLenum target, GLint level) : mTarget(target), mLevel(level) |
John Bauman | 66b8ab2 | 2014-05-06 15:57:45 -0400 | [diff] [blame] | 220 | { |
Nicolas Capens | d7d9b4b | 2015-01-29 23:46:44 -0500 | [diff] [blame] | 221 | mTextureCubeMap = texture; |
John Bauman | 66b8ab2 | 2014-05-06 15:57:45 -0400 | [diff] [blame] | 222 | } |
| 223 | |
| 224 | RenderbufferTextureCubeMap::~RenderbufferTextureCubeMap() |
| 225 | { |
Nicolas Capens | d7d9b4b | 2015-01-29 23:46:44 -0500 | [diff] [blame] | 226 | mTextureCubeMap = NULL; |
John Bauman | 66b8ab2 | 2014-05-06 15:57:45 -0400 | [diff] [blame] | 227 | } |
| 228 | |
| 229 | // Textures need to maintain their own reference count for references via |
| 230 | // Renderbuffers acting as proxies. Here, we notify the texture of a reference. |
| 231 | void RenderbufferTextureCubeMap::addProxyRef(const Renderbuffer *proxy) |
| 232 | { |
Nicolas Capens | 0bac285 | 2016-05-07 06:09:58 -0400 | [diff] [blame] | 233 | mTextureCubeMap->addProxyRef(proxy); |
John Bauman | 66b8ab2 | 2014-05-06 15:57:45 -0400 | [diff] [blame] | 234 | } |
| 235 | |
| 236 | void RenderbufferTextureCubeMap::releaseProxy(const Renderbuffer *proxy) |
| 237 | { |
Nicolas Capens | 0bac285 | 2016-05-07 06:09:58 -0400 | [diff] [blame] | 238 | mTextureCubeMap->releaseProxy(proxy); |
John Bauman | 66b8ab2 | 2014-05-06 15:57:45 -0400 | [diff] [blame] | 239 | } |
| 240 | |
Nicolas Capens | 6e77a64 | 2014-06-12 00:13:37 -0400 | [diff] [blame] | 241 | // Increments refcount on image. |
| 242 | // caller must release() the returned image |
Nicolas Capens | deda34b | 2015-04-28 15:21:53 -0700 | [diff] [blame] | 243 | egl::Image *RenderbufferTextureCubeMap::getRenderTarget() |
John Bauman | 66b8ab2 | 2014-05-06 15:57:45 -0400 | [diff] [blame] | 244 | { |
Alexis Hetu | 8af5007 | 2015-04-29 14:29:49 -0400 | [diff] [blame] | 245 | return mTextureCubeMap->getRenderTarget(mTarget, mLevel); |
John Bauman | 66b8ab2 | 2014-05-06 15:57:45 -0400 | [diff] [blame] | 246 | } |
| 247 | |
Nicolas Capens | 6e77a64 | 2014-06-12 00:13:37 -0400 | [diff] [blame] | 248 | // Increments refcount on image. |
| 249 | // caller must release() the returned image |
Nicolas Capens | ead7ac5 | 2014-10-27 23:56:02 -0400 | [diff] [blame] | 250 | egl::Image *RenderbufferTextureCubeMap::createSharedImage() |
Nicolas Capens | 6e77a64 | 2014-06-12 00:13:37 -0400 | [diff] [blame] | 251 | { |
Alexis Hetu | 8af5007 | 2015-04-29 14:29:49 -0400 | [diff] [blame] | 252 | return mTextureCubeMap->createSharedImage(mTarget, mLevel); |
Nicolas Capens | 6e77a64 | 2014-06-12 00:13:37 -0400 | [diff] [blame] | 253 | } |
| 254 | |
| 255 | bool RenderbufferTextureCubeMap::isShared() const |
| 256 | { |
Alexis Hetu | 8af5007 | 2015-04-29 14:29:49 -0400 | [diff] [blame] | 257 | return mTextureCubeMap->isShared(mTarget, mLevel); |
Nicolas Capens | 6e77a64 | 2014-06-12 00:13:37 -0400 | [diff] [blame] | 258 | } |
| 259 | |
John Bauman | 66b8ab2 | 2014-05-06 15:57:45 -0400 | [diff] [blame] | 260 | GLsizei RenderbufferTextureCubeMap::getWidth() const |
| 261 | { |
Alexis Hetu | 8af5007 | 2015-04-29 14:29:49 -0400 | [diff] [blame] | 262 | return mTextureCubeMap->getWidth(mTarget, mLevel); |
John Bauman | 66b8ab2 | 2014-05-06 15:57:45 -0400 | [diff] [blame] | 263 | } |
| 264 | |
| 265 | GLsizei RenderbufferTextureCubeMap::getHeight() const |
| 266 | { |
Alexis Hetu | 8af5007 | 2015-04-29 14:29:49 -0400 | [diff] [blame] | 267 | return mTextureCubeMap->getHeight(mTarget, mLevel); |
John Bauman | 66b8ab2 | 2014-05-06 15:57:45 -0400 | [diff] [blame] | 268 | } |
| 269 | |
| 270 | GLenum RenderbufferTextureCubeMap::getFormat() const |
| 271 | { |
Alexis Hetu | 8af5007 | 2015-04-29 14:29:49 -0400 | [diff] [blame] | 272 | return mTextureCubeMap->getFormat(mTarget, mLevel); |
John Bauman | 66b8ab2 | 2014-05-06 15:57:45 -0400 | [diff] [blame] | 273 | } |
| 274 | |
| 275 | sw::Format RenderbufferTextureCubeMap::getInternalFormat() const |
| 276 | { |
Alexis Hetu | 8af5007 | 2015-04-29 14:29:49 -0400 | [diff] [blame] | 277 | return mTextureCubeMap->getInternalFormat(mTarget, mLevel); |
John Bauman | 66b8ab2 | 2014-05-06 15:57:45 -0400 | [diff] [blame] | 278 | } |
| 279 | |
| 280 | GLsizei RenderbufferTextureCubeMap::getSamples() const |
| 281 | { |
| 282 | return 0; |
| 283 | } |
| 284 | |
| 285 | ////// Renderbuffer Implementation ////// |
| 286 | |
Nicolas Capens | e826ef0 | 2015-04-02 14:43:13 -0400 | [diff] [blame] | 287 | Renderbuffer::Renderbuffer(GLuint name, RenderbufferInterface *instance) : NamedObject(name) |
John Bauman | 66b8ab2 | 2014-05-06 15:57:45 -0400 | [diff] [blame] | 288 | { |
Nicolas Capens | 0bac285 | 2016-05-07 06:09:58 -0400 | [diff] [blame] | 289 | ASSERT(instance); |
John Bauman | 66b8ab2 | 2014-05-06 15:57:45 -0400 | [diff] [blame] | 290 | mInstance = instance; |
| 291 | } |
| 292 | |
| 293 | Renderbuffer::~Renderbuffer() |
| 294 | { |
| 295 | delete mInstance; |
| 296 | } |
| 297 | |
| 298 | // The RenderbufferInterface contained in this Renderbuffer may need to maintain |
| 299 | // its own reference count, so we pass it on here. |
| 300 | void Renderbuffer::addRef() |
| 301 | { |
Nicolas Capens | 0bac285 | 2016-05-07 06:09:58 -0400 | [diff] [blame] | 302 | mInstance->addProxyRef(this); |
John Bauman | 66b8ab2 | 2014-05-06 15:57:45 -0400 | [diff] [blame] | 303 | |
Nicolas Capens | 0bac285 | 2016-05-07 06:09:58 -0400 | [diff] [blame] | 304 | Object::addRef(); |
John Bauman | 66b8ab2 | 2014-05-06 15:57:45 -0400 | [diff] [blame] | 305 | } |
| 306 | |
| 307 | void Renderbuffer::release() |
| 308 | { |
Nicolas Capens | 0bac285 | 2016-05-07 06:09:58 -0400 | [diff] [blame] | 309 | mInstance->releaseProxy(this); |
John Bauman | 66b8ab2 | 2014-05-06 15:57:45 -0400 | [diff] [blame] | 310 | |
Nicolas Capens | 0bac285 | 2016-05-07 06:09:58 -0400 | [diff] [blame] | 311 | Object::release(); |
John Bauman | 66b8ab2 | 2014-05-06 15:57:45 -0400 | [diff] [blame] | 312 | } |
| 313 | |
Nicolas Capens | 6e77a64 | 2014-06-12 00:13:37 -0400 | [diff] [blame] | 314 | // Increments refcount on image. |
| 315 | // caller must Release() the returned image |
Nicolas Capens | ead7ac5 | 2014-10-27 23:56:02 -0400 | [diff] [blame] | 316 | egl::Image *Renderbuffer::getRenderTarget() |
John Bauman | 66b8ab2 | 2014-05-06 15:57:45 -0400 | [diff] [blame] | 317 | { |
| 318 | return mInstance->getRenderTarget(); |
| 319 | } |
| 320 | |
Nicolas Capens | 6e77a64 | 2014-06-12 00:13:37 -0400 | [diff] [blame] | 321 | // Increments refcount on image. |
| 322 | // caller must Release() the returned image |
Nicolas Capens | ead7ac5 | 2014-10-27 23:56:02 -0400 | [diff] [blame] | 323 | egl::Image *Renderbuffer::createSharedImage() |
Nicolas Capens | 6e77a64 | 2014-06-12 00:13:37 -0400 | [diff] [blame] | 324 | { |
Nicolas Capens | 0bac285 | 2016-05-07 06:09:58 -0400 | [diff] [blame] | 325 | return mInstance->createSharedImage(); |
Nicolas Capens | 6e77a64 | 2014-06-12 00:13:37 -0400 | [diff] [blame] | 326 | } |
| 327 | |
| 328 | bool Renderbuffer::isShared() const |
| 329 | { |
Nicolas Capens | 0bac285 | 2016-05-07 06:09:58 -0400 | [diff] [blame] | 330 | return mInstance->isShared(); |
Nicolas Capens | 6e77a64 | 2014-06-12 00:13:37 -0400 | [diff] [blame] | 331 | } |
| 332 | |
John Bauman | 66b8ab2 | 2014-05-06 15:57:45 -0400 | [diff] [blame] | 333 | GLsizei Renderbuffer::getWidth() const |
| 334 | { |
| 335 | return mInstance->getWidth(); |
| 336 | } |
| 337 | |
| 338 | GLsizei Renderbuffer::getHeight() const |
| 339 | { |
| 340 | return mInstance->getHeight(); |
| 341 | } |
| 342 | |
Alexis Hetu | e23029a | 2015-12-04 17:12:35 -0500 | [diff] [blame] | 343 | GLsizei Renderbuffer::getDepth() const |
| 344 | { |
| 345 | return mInstance->getDepth(); |
| 346 | } |
| 347 | |
Alexis Hetu | 074c641 | 2015-06-22 15:57:27 -0400 | [diff] [blame] | 348 | GLint Renderbuffer::getLayer() const |
| 349 | { |
| 350 | return mInstance->getLayer(); |
| 351 | } |
| 352 | |
Alexis Hetu | 526a89d | 2016-02-11 15:41:27 -0500 | [diff] [blame] | 353 | GLint Renderbuffer::getLevel() const |
| 354 | { |
| 355 | return mInstance->getLevel(); |
| 356 | } |
| 357 | |
John Bauman | 66b8ab2 | 2014-05-06 15:57:45 -0400 | [diff] [blame] | 358 | GLenum Renderbuffer::getFormat() const |
| 359 | { |
| 360 | return mInstance->getFormat(); |
| 361 | } |
| 362 | |
| 363 | sw::Format Renderbuffer::getInternalFormat() const |
| 364 | { |
| 365 | return mInstance->getInternalFormat(); |
| 366 | } |
| 367 | |
| 368 | GLuint Renderbuffer::getRedSize() const |
| 369 | { |
| 370 | return mInstance->getRedSize(); |
| 371 | } |
| 372 | |
| 373 | GLuint Renderbuffer::getGreenSize() const |
| 374 | { |
| 375 | return mInstance->getGreenSize(); |
| 376 | } |
| 377 | |
| 378 | GLuint Renderbuffer::getBlueSize() const |
| 379 | { |
| 380 | return mInstance->getBlueSize(); |
| 381 | } |
| 382 | |
| 383 | GLuint Renderbuffer::getAlphaSize() const |
| 384 | { |
| 385 | return mInstance->getAlphaSize(); |
| 386 | } |
| 387 | |
| 388 | GLuint Renderbuffer::getDepthSize() const |
| 389 | { |
| 390 | return mInstance->getDepthSize(); |
| 391 | } |
| 392 | |
| 393 | GLuint Renderbuffer::getStencilSize() const |
| 394 | { |
| 395 | return mInstance->getStencilSize(); |
| 396 | } |
| 397 | |
| 398 | GLsizei Renderbuffer::getSamples() const |
| 399 | { |
| 400 | return mInstance->getSamples(); |
| 401 | } |
| 402 | |
Alexis Hetu | 526a89d | 2016-02-11 15:41:27 -0500 | [diff] [blame] | 403 | void Renderbuffer::setLayer(GLint layer) |
| 404 | { |
| 405 | return mInstance->setLayer(layer); |
| 406 | } |
| 407 | |
| 408 | void Renderbuffer::setLevel(GLint level) |
| 409 | { |
| 410 | return mInstance->setLevel(level); |
| 411 | } |
| 412 | |
John Bauman | 66b8ab2 | 2014-05-06 15:57:45 -0400 | [diff] [blame] | 413 | void Renderbuffer::setStorage(RenderbufferStorage *newStorage) |
| 414 | { |
| 415 | ASSERT(newStorage != NULL); |
| 416 | |
| 417 | delete mInstance; |
| 418 | mInstance = newStorage; |
| 419 | } |
| 420 | |
| 421 | RenderbufferStorage::RenderbufferStorage() |
| 422 | { |
| 423 | mWidth = 0; |
| 424 | mHeight = 0; |
| 425 | format = GL_RGBA4; |
Nicolas Capens | de6b75c | 2015-03-29 00:27:33 -0400 | [diff] [blame] | 426 | internalFormat = sw::FORMAT_A8B8G8R8; |
John Bauman | 66b8ab2 | 2014-05-06 15:57:45 -0400 | [diff] [blame] | 427 | mSamples = 0; |
| 428 | } |
| 429 | |
| 430 | RenderbufferStorage::~RenderbufferStorage() |
| 431 | { |
| 432 | } |
| 433 | |
John Bauman | 66b8ab2 | 2014-05-06 15:57:45 -0400 | [diff] [blame] | 434 | GLsizei RenderbufferStorage::getWidth() const |
| 435 | { |
| 436 | return mWidth; |
| 437 | } |
| 438 | |
| 439 | GLsizei RenderbufferStorage::getHeight() const |
| 440 | { |
| 441 | return mHeight; |
| 442 | } |
| 443 | |
| 444 | GLenum RenderbufferStorage::getFormat() const |
| 445 | { |
| 446 | return format; |
| 447 | } |
| 448 | |
| 449 | sw::Format RenderbufferStorage::getInternalFormat() const |
| 450 | { |
| 451 | return internalFormat; |
| 452 | } |
| 453 | |
| 454 | GLsizei RenderbufferStorage::getSamples() const |
| 455 | { |
| 456 | return mSamples; |
| 457 | } |
| 458 | |
Nicolas Capens | ead7ac5 | 2014-10-27 23:56:02 -0400 | [diff] [blame] | 459 | Colorbuffer::Colorbuffer(egl::Image *renderTarget) : mRenderTarget(renderTarget) |
John Bauman | 66b8ab2 | 2014-05-06 15:57:45 -0400 | [diff] [blame] | 460 | { |
| 461 | if(renderTarget) |
| 462 | { |
| 463 | renderTarget->addRef(); |
Nicolas Capens | 0bac285 | 2016-05-07 06:09:58 -0400 | [diff] [blame] | 464 | |
John Bauman | 66b8ab2 | 2014-05-06 15:57:45 -0400 | [diff] [blame] | 465 | mWidth = renderTarget->getWidth(); |
| 466 | mHeight = renderTarget->getHeight(); |
| 467 | internalFormat = renderTarget->getInternalFormat(); |
| 468 | format = sw2es::ConvertBackBufferFormat(internalFormat); |
Alexis Hetu | b027aa9 | 2015-01-19 15:56:12 -0500 | [diff] [blame] | 469 | mSamples = renderTarget->getDepth() & ~1; |
John Bauman | 66b8ab2 | 2014-05-06 15:57:45 -0400 | [diff] [blame] | 470 | } |
| 471 | } |
| 472 | |
Nicolas Capens | 3ff330f | 2015-09-03 16:41:09 -0400 | [diff] [blame] | 473 | Colorbuffer::Colorbuffer(int width, int height, GLenum format, GLsizei samples) : mRenderTarget(nullptr) |
John Bauman | 66b8ab2 | 2014-05-06 15:57:45 -0400 | [diff] [blame] | 474 | { |
| 475 | Device *device = getDevice(); |
| 476 | |
| 477 | sw::Format requestedFormat = es2sw::ConvertRenderbufferFormat(format); |
Nicolas Capens | 3ff330f | 2015-09-03 16:41:09 -0400 | [diff] [blame] | 478 | int supportedSamples = Context::getSupportedMultisampleCount(samples); |
John Bauman | 66b8ab2 | 2014-05-06 15:57:45 -0400 | [diff] [blame] | 479 | |
| 480 | if(width > 0 && height > 0) |
| 481 | { |
| 482 | mRenderTarget = device->createRenderTarget(width, height, requestedFormat, supportedSamples, false); |
| 483 | |
| 484 | if(!mRenderTarget) |
| 485 | { |
| 486 | error(GL_OUT_OF_MEMORY); |
| 487 | return; |
| 488 | } |
| 489 | } |
| 490 | |
| 491 | mWidth = width; |
| 492 | mHeight = height; |
| 493 | this->format = format; |
| 494 | internalFormat = requestedFormat; |
Alexis Hetu | 7a57040 | 2015-07-02 13:46:59 -0400 | [diff] [blame] | 495 | mSamples = supportedSamples; |
John Bauman | 66b8ab2 | 2014-05-06 15:57:45 -0400 | [diff] [blame] | 496 | } |
| 497 | |
| 498 | Colorbuffer::~Colorbuffer() |
| 499 | { |
| 500 | if(mRenderTarget) |
| 501 | { |
| 502 | mRenderTarget->release(); |
| 503 | } |
| 504 | } |
| 505 | |
Nicolas Capens | 6e77a64 | 2014-06-12 00:13:37 -0400 | [diff] [blame] | 506 | // Increments refcount on image. |
| 507 | // caller must release() the returned image |
Nicolas Capens | ead7ac5 | 2014-10-27 23:56:02 -0400 | [diff] [blame] | 508 | egl::Image *Colorbuffer::getRenderTarget() |
John Bauman | 66b8ab2 | 2014-05-06 15:57:45 -0400 | [diff] [blame] | 509 | { |
| 510 | if(mRenderTarget) |
| 511 | { |
| 512 | mRenderTarget->addRef(); |
| 513 | } |
| 514 | |
| 515 | return mRenderTarget; |
| 516 | } |
| 517 | |
Nicolas Capens | 6e77a64 | 2014-06-12 00:13:37 -0400 | [diff] [blame] | 518 | // Increments refcount on image. |
| 519 | // caller must release() the returned image |
Nicolas Capens | ead7ac5 | 2014-10-27 23:56:02 -0400 | [diff] [blame] | 520 | egl::Image *Colorbuffer::createSharedImage() |
Nicolas Capens | 6e77a64 | 2014-06-12 00:13:37 -0400 | [diff] [blame] | 521 | { |
Nicolas Capens | 0bac285 | 2016-05-07 06:09:58 -0400 | [diff] [blame] | 522 | if(mRenderTarget) |
| 523 | { |
| 524 | mRenderTarget->addRef(); |
| 525 | mRenderTarget->markShared(); |
| 526 | } |
Nicolas Capens | 6e77a64 | 2014-06-12 00:13:37 -0400 | [diff] [blame] | 527 | |
Nicolas Capens | 0bac285 | 2016-05-07 06:09:58 -0400 | [diff] [blame] | 528 | return mRenderTarget; |
Nicolas Capens | 6e77a64 | 2014-06-12 00:13:37 -0400 | [diff] [blame] | 529 | } |
| 530 | |
| 531 | bool Colorbuffer::isShared() const |
| 532 | { |
Nicolas Capens | 0bac285 | 2016-05-07 06:09:58 -0400 | [diff] [blame] | 533 | return mRenderTarget->isShared(); |
Nicolas Capens | 6e77a64 | 2014-06-12 00:13:37 -0400 | [diff] [blame] | 534 | } |
| 535 | |
Nicolas Capens | ead7ac5 | 2014-10-27 23:56:02 -0400 | [diff] [blame] | 536 | DepthStencilbuffer::DepthStencilbuffer(egl::Image *depthStencil) : mDepthStencil(depthStencil) |
John Bauman | 66b8ab2 | 2014-05-06 15:57:45 -0400 | [diff] [blame] | 537 | { |
| 538 | if(depthStencil) |
| 539 | { |
| 540 | depthStencil->addRef(); |
| 541 | |
| 542 | mWidth = depthStencil->getWidth(); |
| 543 | mHeight = depthStencil->getHeight(); |
| 544 | internalFormat = depthStencil->getInternalFormat(); |
| 545 | format = sw2es::ConvertDepthStencilFormat(internalFormat); |
Alexis Hetu | b027aa9 | 2015-01-19 15:56:12 -0500 | [diff] [blame] | 546 | mSamples = depthStencil->getDepth() & ~1; |
John Bauman | 66b8ab2 | 2014-05-06 15:57:45 -0400 | [diff] [blame] | 547 | } |
| 548 | } |
| 549 | |
Alexis Hetu | b02a8ee | 2016-02-11 15:52:49 -0500 | [diff] [blame] | 550 | DepthStencilbuffer::DepthStencilbuffer(int width, int height, GLenum requestedFormat, GLsizei samples) : mDepthStencil(nullptr) |
John Bauman | 66b8ab2 | 2014-05-06 15:57:45 -0400 | [diff] [blame] | 551 | { |
Alexis Hetu | b02a8ee | 2016-02-11 15:52:49 -0500 | [diff] [blame] | 552 | format = requestedFormat; |
| 553 | switch(requestedFormat) |
| 554 | { |
| 555 | case GL_STENCIL_INDEX8: |
| 556 | case GL_DEPTH_COMPONENT24: |
| 557 | case GL_DEPTH24_STENCIL8_OES: |
| 558 | internalFormat = sw::FORMAT_D24S8; |
| 559 | break; |
| 560 | case GL_DEPTH32F_STENCIL8: |
| 561 | internalFormat = sw::FORMAT_D32FS8_TEXTURE; |
| 562 | break; |
| 563 | case GL_DEPTH_COMPONENT16: |
| 564 | internalFormat = sw::FORMAT_D16; |
| 565 | break; |
| 566 | case GL_DEPTH_COMPONENT32_OES: |
| 567 | internalFormat = sw::FORMAT_D32; |
| 568 | break; |
| 569 | case GL_DEPTH_COMPONENT32F: |
| 570 | internalFormat = sw::FORMAT_D32F; |
| 571 | break; |
| 572 | default: |
| 573 | UNREACHABLE(requestedFormat); |
| 574 | format = GL_DEPTH24_STENCIL8_OES; |
| 575 | internalFormat = sw::FORMAT_D24S8; |
| 576 | } |
| 577 | |
John Bauman | 66b8ab2 | 2014-05-06 15:57:45 -0400 | [diff] [blame] | 578 | Device *device = getDevice(); |
| 579 | |
Nicolas Capens | 3ff330f | 2015-09-03 16:41:09 -0400 | [diff] [blame] | 580 | int supportedSamples = Context::getSupportedMultisampleCount(samples); |
John Bauman | 66b8ab2 | 2014-05-06 15:57:45 -0400 | [diff] [blame] | 581 | |
| 582 | if(width > 0 && height > 0) |
| 583 | { |
Alexis Hetu | b02a8ee | 2016-02-11 15:52:49 -0500 | [diff] [blame] | 584 | mDepthStencil = device->createDepthStencilSurface(width, height, internalFormat, supportedSamples, false); |
John Bauman | 66b8ab2 | 2014-05-06 15:57:45 -0400 | [diff] [blame] | 585 | |
| 586 | if(!mDepthStencil) |
| 587 | { |
| 588 | error(GL_OUT_OF_MEMORY); |
| 589 | return; |
| 590 | } |
| 591 | } |
| 592 | |
| 593 | mWidth = width; |
| 594 | mHeight = height; |
Alexis Hetu | 7a57040 | 2015-07-02 13:46:59 -0400 | [diff] [blame] | 595 | mSamples = supportedSamples; |
John Bauman | 66b8ab2 | 2014-05-06 15:57:45 -0400 | [diff] [blame] | 596 | } |
| 597 | |
| 598 | DepthStencilbuffer::~DepthStencilbuffer() |
| 599 | { |
| 600 | if(mDepthStencil) |
| 601 | { |
| 602 | mDepthStencil->release(); |
| 603 | } |
| 604 | } |
| 605 | |
Nicolas Capens | 6e77a64 | 2014-06-12 00:13:37 -0400 | [diff] [blame] | 606 | // Increments refcount on image. |
| 607 | // caller must release() the returned image |
Nicolas Capens | ead7ac5 | 2014-10-27 23:56:02 -0400 | [diff] [blame] | 608 | egl::Image *DepthStencilbuffer::getRenderTarget() |
John Bauman | 66b8ab2 | 2014-05-06 15:57:45 -0400 | [diff] [blame] | 609 | { |
| 610 | if(mDepthStencil) |
| 611 | { |
| 612 | mDepthStencil->addRef(); |
| 613 | } |
| 614 | |
| 615 | return mDepthStencil; |
| 616 | } |
| 617 | |
Nicolas Capens | 6e77a64 | 2014-06-12 00:13:37 -0400 | [diff] [blame] | 618 | // Increments refcount on image. |
| 619 | // caller must release() the returned image |
Nicolas Capens | ead7ac5 | 2014-10-27 23:56:02 -0400 | [diff] [blame] | 620 | egl::Image *DepthStencilbuffer::createSharedImage() |
Nicolas Capens | 6e77a64 | 2014-06-12 00:13:37 -0400 | [diff] [blame] | 621 | { |
Nicolas Capens | 0bac285 | 2016-05-07 06:09:58 -0400 | [diff] [blame] | 622 | if(mDepthStencil) |
| 623 | { |
| 624 | mDepthStencil->addRef(); |
| 625 | mDepthStencil->markShared(); |
| 626 | } |
Nicolas Capens | 6e77a64 | 2014-06-12 00:13:37 -0400 | [diff] [blame] | 627 | |
Nicolas Capens | 0bac285 | 2016-05-07 06:09:58 -0400 | [diff] [blame] | 628 | return mDepthStencil; |
Nicolas Capens | 6e77a64 | 2014-06-12 00:13:37 -0400 | [diff] [blame] | 629 | } |
| 630 | |
| 631 | bool DepthStencilbuffer::isShared() const |
| 632 | { |
Nicolas Capens | 0bac285 | 2016-05-07 06:09:58 -0400 | [diff] [blame] | 633 | return mDepthStencil->isShared(); |
Nicolas Capens | 6e77a64 | 2014-06-12 00:13:37 -0400 | [diff] [blame] | 634 | } |
| 635 | |
Nicolas Capens | ead7ac5 | 2014-10-27 23:56:02 -0400 | [diff] [blame] | 636 | Depthbuffer::Depthbuffer(egl::Image *depthStencil) : DepthStencilbuffer(depthStencil) |
John Bauman | 66b8ab2 | 2014-05-06 15:57:45 -0400 | [diff] [blame] | 637 | { |
John Bauman | 66b8ab2 | 2014-05-06 15:57:45 -0400 | [diff] [blame] | 638 | } |
| 639 | |
Alexis Hetu | b02a8ee | 2016-02-11 15:52:49 -0500 | [diff] [blame] | 640 | Depthbuffer::Depthbuffer(int width, int height, GLenum format, GLsizei samples) : DepthStencilbuffer(width, height, format, samples) |
John Bauman | 66b8ab2 | 2014-05-06 15:57:45 -0400 | [diff] [blame] | 641 | { |
John Bauman | 66b8ab2 | 2014-05-06 15:57:45 -0400 | [diff] [blame] | 642 | } |
| 643 | |
| 644 | Depthbuffer::~Depthbuffer() |
| 645 | { |
| 646 | } |
| 647 | |
Nicolas Capens | ead7ac5 | 2014-10-27 23:56:02 -0400 | [diff] [blame] | 648 | Stencilbuffer::Stencilbuffer(egl::Image *depthStencil) : DepthStencilbuffer(depthStencil) |
John Bauman | 66b8ab2 | 2014-05-06 15:57:45 -0400 | [diff] [blame] | 649 | { |
John Bauman | 66b8ab2 | 2014-05-06 15:57:45 -0400 | [diff] [blame] | 650 | } |
| 651 | |
Alexis Hetu | b02a8ee | 2016-02-11 15:52:49 -0500 | [diff] [blame] | 652 | Stencilbuffer::Stencilbuffer(int width, int height, GLsizei samples) : DepthStencilbuffer(width, height, GL_STENCIL_INDEX8, samples) |
John Bauman | 66b8ab2 | 2014-05-06 15:57:45 -0400 | [diff] [blame] | 653 | { |
John Bauman | 66b8ab2 | 2014-05-06 15:57:45 -0400 | [diff] [blame] | 654 | } |
| 655 | |
| 656 | Stencilbuffer::~Stencilbuffer() |
| 657 | { |
| 658 | } |
| 659 | |
| 660 | } |