1 // Copyright 2016 The SwiftShader Authors. All Rights Reserved. 2 // 3 // Licensed under the Apache License, Version 2.0 (the "License"); 4 // you may not use this file except in compliance with the License. 5 // You may obtain a copy of the License at 6 // 7 // http://www.apache.org/licenses/LICENSE-2.0 8 // 9 // Unless required by applicable law or agreed to in writing, software 10 // distributed under the License is distributed on an "AS IS" BASIS, 11 // WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. 12 // See the License for the specific language governing permissions and 13 // limitations under the License. 14 15 // Renderbuffer.h: Defines the wrapper class Renderbuffer, as well as the 16 // class hierarchy used to store its contents: RenderbufferStorage, Colorbuffer, 17 // DepthStencilbuffer, Depthbuffer and Stencilbuffer. Implements GL renderbuffer 18 // objects and related functionality. [OpenGL ES 2.0.24] section 4.4.3 page 108. 19 20 #ifndef LIBGLES_CM_RENDERBUFFER_H_ 21 #define LIBGLES_CM_RENDERBUFFER_H_ 22 23 #include "common/Object.hpp" 24 #include "common/Image.hpp" 25 26 #include <GLES/gl.h> 27 28 namespace es1 29 { 30 class Texture2D; 31 class Renderbuffer; 32 class Colorbuffer; 33 class DepthStencilbuffer; 34 35 class RenderbufferInterface 36 { 37 public: 38 RenderbufferInterface(); 39 ~RenderbufferInterface()40 virtual ~RenderbufferInterface() {} 41 42 virtual void addProxyRef(const Renderbuffer *proxy); 43 virtual void releaseProxy(const Renderbuffer *proxy); 44 45 virtual egl::Image *getRenderTarget() = 0; 46 virtual egl::Image *createSharedImage() = 0; 47 virtual bool isShared() const = 0; 48 49 virtual GLsizei getWidth() const = 0; 50 virtual GLsizei getHeight() const = 0; getLevel()51 virtual GLint getLevel() const { return 0; } 52 virtual GLint getFormat() const = 0; 53 virtual GLsizei getSamples() const = 0; 54 setLevel(GLint)55 virtual void setLevel(GLint) {} 56 57 GLuint getRedSize() const; 58 GLuint getGreenSize() const; 59 GLuint getBlueSize() const; 60 GLuint getAlphaSize() const; 61 GLuint getDepthSize() const; 62 GLuint getStencilSize() const; 63 }; 64 65 class RenderbufferTexture2D : public RenderbufferInterface 66 { 67 public: 68 RenderbufferTexture2D(Texture2D *texture, GLint level); 69 70 ~RenderbufferTexture2D() override; 71 72 void addProxyRef(const Renderbuffer *proxy) override; 73 void releaseProxy(const Renderbuffer *proxy) override; 74 75 egl::Image *getRenderTarget() override; 76 egl::Image *createSharedImage() override; 77 bool isShared() const override; 78 79 GLsizei getWidth() const override; 80 GLsizei getHeight() const override; getLevel()81 GLint getLevel() const override { return mLevel; } 82 GLint getFormat() const override; 83 GLsizei getSamples() const override; 84 setLevel(GLint level)85 void setLevel(GLint level) override { mLevel = level; } 86 87 private: 88 gl::BindingPointer<Texture2D> mTexture2D; 89 GLint mLevel; 90 }; 91 92 // A class derived from RenderbufferStorage is created whenever glRenderbufferStorage 93 // is called. The specific concrete type depends on whether the internal format is 94 // colour depth, stencil or packed depth/stencil. 95 class RenderbufferStorage : public RenderbufferInterface 96 { 97 public: 98 RenderbufferStorage(); 99 100 ~RenderbufferStorage() override = 0; 101 102 egl::Image *getRenderTarget() override = 0; 103 egl::Image *createSharedImage() override = 0; 104 bool isShared() const override = 0; 105 106 GLsizei getWidth() const override; 107 GLsizei getHeight() const override; 108 GLint getFormat() const override; 109 GLsizei getSamples() const override; 110 111 protected: 112 GLsizei mWidth; 113 GLsizei mHeight; 114 GLenum format; 115 GLsizei mSamples; 116 }; 117 118 // Renderbuffer implements the GL renderbuffer object. 119 // It's only a proxy for a RenderbufferInterface instance; the internal object 120 // can change whenever glRenderbufferStorage is called. 121 class Renderbuffer : public gl::NamedObject 122 { 123 public: 124 Renderbuffer(GLuint name, RenderbufferInterface *storage); 125 126 virtual ~Renderbuffer(); 127 128 // These functions from Object are overloaded here because 129 // Textures need to maintain their own count of references to them via 130 // Renderbuffers/RenderbufferTextures. These functions invoke those 131 // reference counting functions on the RenderbufferInterface. 132 virtual void addRef(); 133 virtual void release(); 134 135 egl::Image *getRenderTarget(); 136 virtual egl::Image *createSharedImage(); 137 virtual bool isShared() const; 138 139 GLsizei getWidth() const; 140 GLsizei getHeight() const; 141 GLint getLevel() const; 142 GLenum getFormat() const; 143 GLuint getRedSize() const; 144 GLuint getGreenSize() const; 145 GLuint getBlueSize() const; 146 GLuint getAlphaSize() const; 147 GLuint getDepthSize() const; 148 GLuint getStencilSize() const; 149 GLsizei getSamples() const; 150 151 void setLevel(GLint level); 152 void setStorage(RenderbufferStorage *newStorage); 153 154 private: 155 RenderbufferInterface *mInstance; 156 }; 157 158 class Colorbuffer : public RenderbufferStorage 159 { 160 public: 161 explicit Colorbuffer(egl::Image *renderTarget); 162 Colorbuffer(GLsizei width, GLsizei height, GLenum internalformat, GLsizei samples); 163 164 ~Colorbuffer() override; 165 166 egl::Image *getRenderTarget() override; 167 egl::Image *createSharedImage() override; 168 bool isShared() const override; 169 170 private: 171 egl::Image *mRenderTarget; 172 }; 173 174 class DepthStencilbuffer : public RenderbufferStorage 175 { 176 public: 177 explicit DepthStencilbuffer(egl::Image *depthStencil); 178 DepthStencilbuffer(GLsizei width, GLsizei height, GLenum internalformat, GLsizei samples); 179 180 ~DepthStencilbuffer(); 181 182 egl::Image *getRenderTarget() override; 183 egl::Image *createSharedImage() override; 184 bool isShared() const override; 185 186 protected: 187 egl::Image *mDepthStencil; 188 }; 189 190 class Depthbuffer : public DepthStencilbuffer 191 { 192 public: 193 explicit Depthbuffer(egl::Image *depthStencil); 194 Depthbuffer(GLsizei width, GLsizei height, GLenum internalformat, GLsizei samples); 195 196 ~Depthbuffer() override; 197 }; 198 199 class Stencilbuffer : public DepthStencilbuffer 200 { 201 public: 202 explicit Stencilbuffer(egl::Image *depthStencil); 203 Stencilbuffer(GLsizei width, GLsizei height, GLsizei samples); 204 205 ~Stencilbuffer() override; 206 }; 207 } 208 209 #endif // LIBGLES_CM_RENDERBUFFER_H_ 210