blob: d1a2aa72e3de5c47af4d82c2342b2bd2b527686a [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 Langa4903b72015-03-02 16:02:48 -080016#include "libANGLE/renderer/gl/renderergl_utils.h"
Geoff Langf9a6f082015-01-22 13:32:49 -050017
18namespace rx
19{
20
Geoff Langa4903b72015-03-02 16:02:48 -080021RenderbufferGL::RenderbufferGL(const FunctionsGL *functions, StateManagerGL *stateManager, const gl::TextureCapsMap &textureCaps)
Geoff Langcd69f1c2015-03-18 14:33:23 -040022 : RenderbufferImpl(),
23 mFunctions(functions),
24 mStateManager(stateManager),
Geoff Langa4903b72015-03-02 16:02:48 -080025 mTextureCaps(textureCaps),
Geoff Langcd69f1c2015-03-18 14:33:23 -040026 mRenderbufferID(0)
27{
28 mFunctions->genRenderbuffers(1, &mRenderbufferID);
29}
Geoff Langf9a6f082015-01-22 13:32:49 -050030
31RenderbufferGL::~RenderbufferGL()
Geoff Langcd69f1c2015-03-18 14:33:23 -040032{
Geoff Lang1eb708e2015-05-04 14:58:23 -040033 mStateManager->deleteRenderbuffer(mRenderbufferID);
34 mRenderbufferID = 0;
Geoff Langcd69f1c2015-03-18 14:33:23 -040035}
Geoff Langf9a6f082015-01-22 13:32:49 -050036
Geoff Langa08e1bd2015-03-24 10:17:18 -040037gl::Error RenderbufferGL::setStorage(GLenum internalformat, size_t width, size_t height)
38{
Geoff Langcd69f1c2015-03-18 14:33:23 -040039 mStateManager->bindRenderbuffer(GL_RENDERBUFFER, mRenderbufferID);
40 mFunctions->renderbufferStorage(GL_RENDERBUFFER, internalformat, width, height);
41 return gl::Error(GL_NO_ERROR);
Geoff Langa08e1bd2015-03-24 10:17:18 -040042}
43
44gl::Error RenderbufferGL::setStorageMultisample(size_t samples, GLenum internalformat, size_t width, size_t height)
Geoff Langf9a6f082015-01-22 13:32:49 -050045{
Geoff Langcd69f1c2015-03-18 14:33:23 -040046 mStateManager->bindRenderbuffer(GL_RENDERBUFFER, mRenderbufferID);
47 mFunctions->renderbufferStorageMultisample(GL_RENDERBUFFER, samples, internalformat, width, height);
Geoff Langa4903b72015-03-02 16:02:48 -080048
49 const gl::TextureCaps &formatCaps = mTextureCaps.get(internalformat);
50 if (samples > formatCaps.getMaxSamples())
51 {
52 // Before version 4.2, it is unknown if the specific internal format can support the requested number
53 // of samples. It is expected that GL_OUT_OF_MEMORY is returned if the renderbuffer cannot be created.
54 GLenum error = GL_NO_ERROR;
55 do
56 {
Geoff Lang0d318282015-04-27 15:08:09 -040057 error = mFunctions->getError();
Geoff Langa4903b72015-03-02 16:02:48 -080058 if (error == GL_OUT_OF_MEMORY)
59 {
60 return gl::Error(GL_OUT_OF_MEMORY);
61 }
62
63 ASSERT(error == GL_NO_ERROR);
64 } while (error != GL_NO_ERROR);
65 }
66
Geoff Langcd69f1c2015-03-18 14:33:23 -040067 return gl::Error(GL_NO_ERROR);
68}
69
70GLuint RenderbufferGL::getRenderbufferID() const
71{
72 return mRenderbufferID;
Geoff Langf9a6f082015-01-22 13:32:49 -050073}
74
75}