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 | { |
Geoff Lang | 23a2ae0 | 2015-07-28 12:42:52 -0400 | [diff] [blame] | 21 | RenderbufferGL::RenderbufferGL(const FunctionsGL *functions, |
| 22 | const WorkaroundsGL &workarounds, |
| 23 | StateManagerGL *stateManager, |
| 24 | const gl::TextureCapsMap &textureCaps) |
Geoff Lang | cd69f1c | 2015-03-18 14:33:23 -0400 | [diff] [blame] | 25 | : RenderbufferImpl(), |
| 26 | mFunctions(functions), |
Geoff Lang | 23a2ae0 | 2015-07-28 12:42:52 -0400 | [diff] [blame] | 27 | mWorkarounds(workarounds), |
Geoff Lang | cd69f1c | 2015-03-18 14:33:23 -0400 | [diff] [blame] | 28 | mStateManager(stateManager), |
Geoff Lang | a4903b7 | 2015-03-02 16:02:48 -0800 | [diff] [blame] | 29 | mTextureCaps(textureCaps), |
Geoff Lang | cd69f1c | 2015-03-18 14:33:23 -0400 | [diff] [blame] | 30 | mRenderbufferID(0) |
| 31 | { |
| 32 | mFunctions->genRenderbuffers(1, &mRenderbufferID); |
Geoff Lang | bf6f48f | 2015-05-27 13:54:39 -0400 | [diff] [blame] | 33 | mStateManager->bindRenderbuffer(GL_RENDERBUFFER, mRenderbufferID); |
Geoff Lang | cd69f1c | 2015-03-18 14:33:23 -0400 | [diff] [blame] | 34 | } |
Geoff Lang | f9a6f08 | 2015-01-22 13:32:49 -0500 | [diff] [blame] | 35 | |
| 36 | RenderbufferGL::~RenderbufferGL() |
Geoff Lang | cd69f1c | 2015-03-18 14:33:23 -0400 | [diff] [blame] | 37 | { |
Geoff Lang | 1eb708e | 2015-05-04 14:58:23 -0400 | [diff] [blame] | 38 | mStateManager->deleteRenderbuffer(mRenderbufferID); |
| 39 | mRenderbufferID = 0; |
Geoff Lang | cd69f1c | 2015-03-18 14:33:23 -0400 | [diff] [blame] | 40 | } |
Geoff Lang | f9a6f08 | 2015-01-22 13:32:49 -0500 | [diff] [blame] | 41 | |
Geoff Lang | a08e1bd | 2015-03-24 10:17:18 -0400 | [diff] [blame] | 42 | gl::Error RenderbufferGL::setStorage(GLenum internalformat, size_t width, size_t height) |
| 43 | { |
Geoff Lang | cd69f1c | 2015-03-18 14:33:23 -0400 | [diff] [blame] | 44 | mStateManager->bindRenderbuffer(GL_RENDERBUFFER, mRenderbufferID); |
Geoff Lang | fd216c4 | 2015-05-27 16:12:30 -0400 | [diff] [blame] | 45 | |
Geoff Lang | 23a2ae0 | 2015-07-28 12:42:52 -0400 | [diff] [blame] | 46 | nativegl::RenderbufferFormat renderbufferFormat = |
| 47 | nativegl::GetRenderbufferFormat(mFunctions, mWorkarounds, internalformat); |
| 48 | mFunctions->renderbufferStorage(GL_RENDERBUFFER, renderbufferFormat.internalFormat, width, |
| 49 | height); |
Geoff Lang | fd216c4 | 2015-05-27 16:12:30 -0400 | [diff] [blame] | 50 | |
Geoff Lang | cd69f1c | 2015-03-18 14:33:23 -0400 | [diff] [blame] | 51 | return gl::Error(GL_NO_ERROR); |
Geoff Lang | a08e1bd | 2015-03-24 10:17:18 -0400 | [diff] [blame] | 52 | } |
| 53 | |
| 54 | 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] | 55 | { |
Geoff Lang | cd69f1c | 2015-03-18 14:33:23 -0400 | [diff] [blame] | 56 | mStateManager->bindRenderbuffer(GL_RENDERBUFFER, mRenderbufferID); |
Geoff Lang | fd216c4 | 2015-05-27 16:12:30 -0400 | [diff] [blame] | 57 | |
Geoff Lang | 23a2ae0 | 2015-07-28 12:42:52 -0400 | [diff] [blame] | 58 | nativegl::RenderbufferFormat renderbufferFormat = |
| 59 | nativegl::GetRenderbufferFormat(mFunctions, mWorkarounds, internalformat); |
| 60 | mFunctions->renderbufferStorageMultisample(GL_RENDERBUFFER, samples, |
| 61 | renderbufferFormat.internalFormat, width, height); |
Geoff Lang | a4903b7 | 2015-03-02 16:02:48 -0800 | [diff] [blame] | 62 | |
| 63 | const gl::TextureCaps &formatCaps = mTextureCaps.get(internalformat); |
| 64 | if (samples > formatCaps.getMaxSamples()) |
| 65 | { |
| 66 | // Before version 4.2, it is unknown if the specific internal format can support the requested number |
| 67 | // of samples. It is expected that GL_OUT_OF_MEMORY is returned if the renderbuffer cannot be created. |
| 68 | GLenum error = GL_NO_ERROR; |
| 69 | do |
| 70 | { |
Geoff Lang | 0d31828 | 2015-04-27 15:08:09 -0400 | [diff] [blame] | 71 | error = mFunctions->getError(); |
Geoff Lang | a4903b7 | 2015-03-02 16:02:48 -0800 | [diff] [blame] | 72 | if (error == GL_OUT_OF_MEMORY) |
| 73 | { |
| 74 | return gl::Error(GL_OUT_OF_MEMORY); |
| 75 | } |
| 76 | |
| 77 | ASSERT(error == GL_NO_ERROR); |
| 78 | } while (error != GL_NO_ERROR); |
| 79 | } |
| 80 | |
Geoff Lang | cd69f1c | 2015-03-18 14:33:23 -0400 | [diff] [blame] | 81 | return gl::Error(GL_NO_ERROR); |
| 82 | } |
| 83 | |
Geoff Lang | a840617 | 2015-07-21 16:53:39 -0400 | [diff] [blame^] | 84 | gl::Error RenderbufferGL::setStorageEGLImageTarget(egl::Image *image) |
| 85 | { |
| 86 | UNIMPLEMENTED(); |
| 87 | return gl::Error(GL_INVALID_OPERATION); |
| 88 | } |
| 89 | |
Geoff Lang | cd69f1c | 2015-03-18 14:33:23 -0400 | [diff] [blame] | 90 | GLuint RenderbufferGL::getRenderbufferID() const |
| 91 | { |
| 92 | return mRenderbufferID; |
Geoff Lang | f9a6f08 | 2015-01-22 13:32:49 -0500 | [diff] [blame] | 93 | } |
| 94 | |
| 95 | } |