Geoff Lang | f9a6f08 | 2015-01-22 13:32:49 -0500 | [diff] [blame] | 1 | // |
| 2 | // Copyright 2015 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 | // RenderbufferGL.cpp: Implements the class methods for RenderbufferGL. |
| 8 | |
| 9 | #include "libANGLE/renderer/gl/RenderbufferGL.h" |
| 10 | |
| 11 | #include "common/debug.h" |
Geoff Lang | a4903b7 | 2015-03-02 16:02:48 -0800 | [diff] [blame] | 12 | #include "libANGLE/Caps.h" |
Geoff Lang | cd69f1c | 2015-03-18 14:33:23 -0400 | [diff] [blame] | 13 | #include "libANGLE/angletypes.h" |
| 14 | #include "libANGLE/renderer/gl/FunctionsGL.h" |
| 15 | #include "libANGLE/renderer/gl/StateManagerGL.h" |
Geoff Lang | fd216c4 | 2015-05-27 16:12:30 -0400 | [diff] [blame] | 16 | #include "libANGLE/renderer/gl/formatutilsgl.h" |
Geoff Lang | a4903b7 | 2015-03-02 16:02:48 -0800 | [diff] [blame] | 17 | #include "libANGLE/renderer/gl/renderergl_utils.h" |
Geoff Lang | f9a6f08 | 2015-01-22 13:32:49 -0500 | [diff] [blame] | 18 | |
| 19 | namespace rx |
| 20 | { |
| 21 | |
Geoff Lang | a4903b7 | 2015-03-02 16:02:48 -0800 | [diff] [blame] | 22 | RenderbufferGL::RenderbufferGL(const FunctionsGL *functions, StateManagerGL *stateManager, const gl::TextureCapsMap &textureCaps) |
Geoff Lang | cd69f1c | 2015-03-18 14:33:23 -0400 | [diff] [blame] | 23 | : RenderbufferImpl(), |
| 24 | mFunctions(functions), |
| 25 | mStateManager(stateManager), |
Geoff Lang | a4903b7 | 2015-03-02 16:02:48 -0800 | [diff] [blame] | 26 | mTextureCaps(textureCaps), |
Geoff Lang | cd69f1c | 2015-03-18 14:33:23 -0400 | [diff] [blame] | 27 | mRenderbufferID(0) |
| 28 | { |
| 29 | mFunctions->genRenderbuffers(1, &mRenderbufferID); |
Geoff Lang | bf6f48f | 2015-05-27 13:54:39 -0400 | [diff] [blame] | 30 | mStateManager->bindRenderbuffer(GL_RENDERBUFFER, mRenderbufferID); |
Geoff Lang | cd69f1c | 2015-03-18 14:33:23 -0400 | [diff] [blame] | 31 | } |
Geoff Lang | f9a6f08 | 2015-01-22 13:32:49 -0500 | [diff] [blame] | 32 | |
| 33 | RenderbufferGL::~RenderbufferGL() |
Geoff Lang | cd69f1c | 2015-03-18 14:33:23 -0400 | [diff] [blame] | 34 | { |
Geoff Lang | 1eb708e | 2015-05-04 14:58:23 -0400 | [diff] [blame] | 35 | mStateManager->deleteRenderbuffer(mRenderbufferID); |
| 36 | mRenderbufferID = 0; |
Geoff Lang | cd69f1c | 2015-03-18 14:33:23 -0400 | [diff] [blame] | 37 | } |
Geoff Lang | f9a6f08 | 2015-01-22 13:32:49 -0500 | [diff] [blame] | 38 | |
Geoff Lang | a08e1bd | 2015-03-24 10:17:18 -0400 | [diff] [blame] | 39 | gl::Error RenderbufferGL::setStorage(GLenum internalformat, size_t width, size_t height) |
| 40 | { |
Geoff Lang | cd69f1c | 2015-03-18 14:33:23 -0400 | [diff] [blame] | 41 | mStateManager->bindRenderbuffer(GL_RENDERBUFFER, mRenderbufferID); |
Geoff Lang | fd216c4 | 2015-05-27 16:12:30 -0400 | [diff] [blame] | 42 | |
| 43 | const nativegl::InternalFormat &nativeInternalFormatInfo = nativegl::GetInternalFormatInfo(internalformat, mFunctions->standard); |
| 44 | mFunctions->renderbufferStorage(GL_RENDERBUFFER, nativeInternalFormatInfo.internalFormat, width, height); |
| 45 | |
Geoff Lang | cd69f1c | 2015-03-18 14:33:23 -0400 | [diff] [blame] | 46 | return gl::Error(GL_NO_ERROR); |
Geoff Lang | a08e1bd | 2015-03-24 10:17:18 -0400 | [diff] [blame] | 47 | } |
| 48 | |
| 49 | gl::Error RenderbufferGL::setStorageMultisample(size_t samples, GLenum internalformat, size_t width, size_t height) |
Geoff Lang | f9a6f08 | 2015-01-22 13:32:49 -0500 | [diff] [blame] | 50 | { |
Geoff Lang | cd69f1c | 2015-03-18 14:33:23 -0400 | [diff] [blame] | 51 | mStateManager->bindRenderbuffer(GL_RENDERBUFFER, mRenderbufferID); |
Geoff Lang | fd216c4 | 2015-05-27 16:12:30 -0400 | [diff] [blame] | 52 | |
| 53 | const nativegl::InternalFormat &nativeInternalFormatInfo = nativegl::GetInternalFormatInfo(internalformat, mFunctions->standard); |
| 54 | mFunctions->renderbufferStorageMultisample(GL_RENDERBUFFER, samples, nativeInternalFormatInfo.internalFormat, width, height); |
Geoff Lang | a4903b7 | 2015-03-02 16:02:48 -0800 | [diff] [blame] | 55 | |
| 56 | const gl::TextureCaps &formatCaps = mTextureCaps.get(internalformat); |
| 57 | if (samples > formatCaps.getMaxSamples()) |
| 58 | { |
| 59 | // Before version 4.2, it is unknown if the specific internal format can support the requested number |
| 60 | // of samples. It is expected that GL_OUT_OF_MEMORY is returned if the renderbuffer cannot be created. |
| 61 | GLenum error = GL_NO_ERROR; |
| 62 | do |
| 63 | { |
Geoff Lang | 0d31828 | 2015-04-27 15:08:09 -0400 | [diff] [blame] | 64 | error = mFunctions->getError(); |
Geoff Lang | a4903b7 | 2015-03-02 16:02:48 -0800 | [diff] [blame] | 65 | if (error == GL_OUT_OF_MEMORY) |
| 66 | { |
| 67 | return gl::Error(GL_OUT_OF_MEMORY); |
| 68 | } |
| 69 | |
| 70 | ASSERT(error == GL_NO_ERROR); |
| 71 | } while (error != GL_NO_ERROR); |
| 72 | } |
| 73 | |
Geoff Lang | cd69f1c | 2015-03-18 14:33:23 -0400 | [diff] [blame] | 74 | return gl::Error(GL_NO_ERROR); |
| 75 | } |
| 76 | |
| 77 | GLuint RenderbufferGL::getRenderbufferID() const |
| 78 | { |
| 79 | return mRenderbufferID; |
Geoff Lang | f9a6f08 | 2015-01-22 13:32:49 -0500 | [diff] [blame] | 80 | } |
| 81 | |
| 82 | } |