blob: bfc2bb254fbf5318c68fdaa4ea4354223c58d665 [file] [log] [blame]
Geoff Langf9a6f082015-01-22 13:32:49 -05001//
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 Langa4903b72015-03-02 16:02:48 -080012#include "libANGLE/Caps.h"
Geoff Langcd69f1c2015-03-18 14:33:23 -040013#include "libANGLE/angletypes.h"
14#include "libANGLE/renderer/gl/FunctionsGL.h"
15#include "libANGLE/renderer/gl/StateManagerGL.h"
Geoff Langfd216c42015-05-27 16:12:30 -040016#include "libANGLE/renderer/gl/formatutilsgl.h"
Geoff Langa4903b72015-03-02 16:02:48 -080017#include "libANGLE/renderer/gl/renderergl_utils.h"
Geoff Langf9a6f082015-01-22 13:32:49 -050018
19namespace rx
20{
Geoff Lang23a2ae02015-07-28 12:42:52 -040021RenderbufferGL::RenderbufferGL(const FunctionsGL *functions,
22 const WorkaroundsGL &workarounds,
23 StateManagerGL *stateManager,
24 const gl::TextureCapsMap &textureCaps)
Geoff Langcd69f1c2015-03-18 14:33:23 -040025 : RenderbufferImpl(),
26 mFunctions(functions),
Geoff Lang23a2ae02015-07-28 12:42:52 -040027 mWorkarounds(workarounds),
Geoff Langcd69f1c2015-03-18 14:33:23 -040028 mStateManager(stateManager),
Geoff Langa4903b72015-03-02 16:02:48 -080029 mTextureCaps(textureCaps),
Geoff Langcd69f1c2015-03-18 14:33:23 -040030 mRenderbufferID(0)
31{
32 mFunctions->genRenderbuffers(1, &mRenderbufferID);
Geoff Langbf6f48f2015-05-27 13:54:39 -040033 mStateManager->bindRenderbuffer(GL_RENDERBUFFER, mRenderbufferID);
Geoff Langcd69f1c2015-03-18 14:33:23 -040034}
Geoff Langf9a6f082015-01-22 13:32:49 -050035
36RenderbufferGL::~RenderbufferGL()
Geoff Langcd69f1c2015-03-18 14:33:23 -040037{
Geoff Lang1eb708e2015-05-04 14:58:23 -040038 mStateManager->deleteRenderbuffer(mRenderbufferID);
39 mRenderbufferID = 0;
Geoff Langcd69f1c2015-03-18 14:33:23 -040040}
Geoff Langf9a6f082015-01-22 13:32:49 -050041
Geoff Langa08e1bd2015-03-24 10:17:18 -040042gl::Error RenderbufferGL::setStorage(GLenum internalformat, size_t width, size_t height)
43{
Geoff Langcd69f1c2015-03-18 14:33:23 -040044 mStateManager->bindRenderbuffer(GL_RENDERBUFFER, mRenderbufferID);
Geoff Langfd216c42015-05-27 16:12:30 -040045
Geoff Lang23a2ae02015-07-28 12:42:52 -040046 nativegl::RenderbufferFormat renderbufferFormat =
47 nativegl::GetRenderbufferFormat(mFunctions, mWorkarounds, internalformat);
Cooper Partinc5cf9bc2015-08-06 10:46:48 -070048 mFunctions->renderbufferStorage(GL_RENDERBUFFER, renderbufferFormat.internalFormat,
49 static_cast<GLsizei>(width), static_cast<GLsizei>(height));
Geoff Langfd216c42015-05-27 16:12:30 -040050
Geoff Langcd69f1c2015-03-18 14:33:23 -040051 return gl::Error(GL_NO_ERROR);
Geoff Langa08e1bd2015-03-24 10:17:18 -040052}
53
54gl::Error RenderbufferGL::setStorageMultisample(size_t samples, GLenum internalformat, size_t width, size_t height)
Geoff Langf9a6f082015-01-22 13:32:49 -050055{
Geoff Langcd69f1c2015-03-18 14:33:23 -040056 mStateManager->bindRenderbuffer(GL_RENDERBUFFER, mRenderbufferID);
Geoff Langfd216c42015-05-27 16:12:30 -040057
Geoff Lang23a2ae02015-07-28 12:42:52 -040058 nativegl::RenderbufferFormat renderbufferFormat =
59 nativegl::GetRenderbufferFormat(mFunctions, mWorkarounds, internalformat);
Cooper Partinc5cf9bc2015-08-06 10:46:48 -070060 mFunctions->renderbufferStorageMultisample(
61 GL_RENDERBUFFER, static_cast<GLsizei>(samples), renderbufferFormat.internalFormat,
62 static_cast<GLsizei>(width), static_cast<GLsizei>(height));
Geoff Langa4903b72015-03-02 16:02:48 -080063
64 const gl::TextureCaps &formatCaps = mTextureCaps.get(internalformat);
65 if (samples > formatCaps.getMaxSamples())
66 {
67 // Before version 4.2, it is unknown if the specific internal format can support the requested number
68 // of samples. It is expected that GL_OUT_OF_MEMORY is returned if the renderbuffer cannot be created.
69 GLenum error = GL_NO_ERROR;
70 do
71 {
Geoff Lang0d318282015-04-27 15:08:09 -040072 error = mFunctions->getError();
Geoff Langa4903b72015-03-02 16:02:48 -080073 if (error == GL_OUT_OF_MEMORY)
74 {
75 return gl::Error(GL_OUT_OF_MEMORY);
76 }
77
78 ASSERT(error == GL_NO_ERROR);
79 } while (error != GL_NO_ERROR);
80 }
81
Geoff Langcd69f1c2015-03-18 14:33:23 -040082 return gl::Error(GL_NO_ERROR);
83}
84
Geoff Langa8406172015-07-21 16:53:39 -040085gl::Error RenderbufferGL::setStorageEGLImageTarget(egl::Image *image)
86{
87 UNIMPLEMENTED();
88 return gl::Error(GL_INVALID_OPERATION);
89}
90
Geoff Langcd69f1c2015-03-18 14:33:23 -040091GLuint RenderbufferGL::getRenderbufferID() const
92{
93 return mRenderbufferID;
Geoff Langf9a6f082015-01-22 13:32:49 -050094}
95
96}