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