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"
12 #include "libANGLE/Caps.h"
13 #include "libANGLE/Context.h"
14 #include "libANGLE/angletypes.h"
15 #include "libANGLE/renderer/gl/BlitGL.h"
16 #include "libANGLE/renderer/gl/ContextGL.h"
17 #include "libANGLE/renderer/gl/FunctionsGL.h"
18 #include "libANGLE/renderer/gl/ImageGL.h"
19 #include "libANGLE/renderer/gl/StateManagerGL.h"
20 #include "libANGLE/renderer/gl/formatutilsgl.h"
21 #include "libANGLE/renderer/gl/renderergl_utils.h"
22 #include "platform/FeaturesGL.h"
23
24 namespace rx
25 {
RenderbufferGL(const gl::RenderbufferState & state,GLuint id)26 RenderbufferGL::RenderbufferGL(const gl::RenderbufferState &state, GLuint id)
27 : RenderbufferImpl(state), mRenderbufferID(id)
28 {
29 }
30
~RenderbufferGL()31 RenderbufferGL::~RenderbufferGL()
32 {
33 ASSERT(mRenderbufferID == 0);
34 }
35
onDestroy(const gl::Context * context)36 void RenderbufferGL::onDestroy(const gl::Context *context)
37 {
38 StateManagerGL *stateManager = GetStateManagerGL(context);
39 stateManager->deleteRenderbuffer(mRenderbufferID);
40 mRenderbufferID = 0;
41 }
42
setStorage(const gl::Context * context,GLenum internalformat,size_t width,size_t height)43 angle::Result RenderbufferGL::setStorage(const gl::Context *context,
44 GLenum internalformat,
45 size_t width,
46 size_t height)
47 {
48 const FunctionsGL *functions = GetFunctionsGL(context);
49 StateManagerGL *stateManager = GetStateManagerGL(context);
50 const angle::FeaturesGL &features = GetFeaturesGL(context);
51
52 stateManager->bindRenderbuffer(GL_RENDERBUFFER, mRenderbufferID);
53
54 nativegl::RenderbufferFormat renderbufferFormat =
55 nativegl::GetRenderbufferFormat(functions, features, internalformat);
56 ANGLE_GL_TRY_ALWAYS_CHECK(
57 context,
58 functions->renderbufferStorage(GL_RENDERBUFFER, renderbufferFormat.internalFormat,
59 static_cast<GLsizei>(width), static_cast<GLsizei>(height)));
60
61 mNativeInternalFormat = renderbufferFormat.internalFormat;
62
63 return angle::Result::Continue;
64 }
65
setStorageMultisample(const gl::Context * context,size_t samples,GLenum internalformat,size_t width,size_t height)66 angle::Result RenderbufferGL::setStorageMultisample(const gl::Context *context,
67 size_t samples,
68 GLenum internalformat,
69 size_t width,
70 size_t height)
71 {
72 const FunctionsGL *functions = GetFunctionsGL(context);
73 StateManagerGL *stateManager = GetStateManagerGL(context);
74 const angle::FeaturesGL &features = GetFeaturesGL(context);
75
76 stateManager->bindRenderbuffer(GL_RENDERBUFFER, mRenderbufferID);
77
78 nativegl::RenderbufferFormat renderbufferFormat =
79 nativegl::GetRenderbufferFormat(functions, features, internalformat);
80 ANGLE_GL_TRY_ALWAYS_CHECK(
81 context,
82 functions->renderbufferStorageMultisample(
83 GL_RENDERBUFFER, static_cast<GLsizei>(samples), renderbufferFormat.internalFormat,
84 static_cast<GLsizei>(width), static_cast<GLsizei>(height)));
85
86 mNativeInternalFormat = renderbufferFormat.internalFormat;
87
88 return angle::Result::Continue;
89 }
90
setStorageEGLImageTarget(const gl::Context * context,egl::Image * image)91 angle::Result RenderbufferGL::setStorageEGLImageTarget(const gl::Context *context,
92 egl::Image *image)
93 {
94 ImageGL *imageGL = GetImplAs<ImageGL>(image);
95 return imageGL->setRenderbufferStorage(context, this, &mNativeInternalFormat);
96 }
97
getRenderbufferID() const98 GLuint RenderbufferGL::getRenderbufferID() const
99 {
100 return mRenderbufferID;
101 }
102
initializeContents(const gl::Context * context,const gl::ImageIndex & imageIndex)103 angle::Result RenderbufferGL::initializeContents(const gl::Context *context,
104 const gl::ImageIndex &imageIndex)
105 {
106 BlitGL *blitter = GetBlitGL(context);
107 return blitter->clearRenderbuffer(context, this, mNativeInternalFormat);
108 }
109
getNativeInternalFormat() const110 GLenum RenderbufferGL::getNativeInternalFormat() const
111 {
112 return mNativeInternalFormat;
113 }
114
115 } // namespace rx
116