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 // Framebuffer.h: Defines the Framebuffer class. Implements GL framebuffer 16 // objects and related functionality. [OpenGL ES 2.0.24] section 4.4 page 105. 17 18 #ifndef LIBGLESV2_FRAMEBUFFER_H_ 19 #define LIBGLESV2_FRAMEBUFFER_H_ 20 21 #include "Context.h" 22 #include "common/Object.hpp" 23 #include "common/Image.hpp" 24 25 #include <GLES2/gl2.h> 26 27 namespace es2 28 { 29 class Renderbuffer; 30 class Colorbuffer; 31 class Depthbuffer; 32 class Stencilbuffer; 33 class DepthStencilbuffer; 34 35 class Framebuffer 36 { 37 public: 38 Framebuffer(); 39 40 virtual ~Framebuffer(); 41 42 void setColorbuffer(GLenum type, GLuint colorbuffer, GLuint index, GLint level = 0, GLint layer = 0); 43 void setDepthbuffer(GLenum type, GLuint depthbuffer, GLint level = 0, GLint layer = 0); 44 void setStencilbuffer(GLenum type, GLuint stencilbuffer, GLint level = 0, GLint layer = 0); 45 46 void setReadBuffer(GLenum buf); 47 void setDrawBuffer(GLuint index, GLenum buf); 48 GLenum getReadBuffer() const; 49 GLenum getDrawBuffer(GLuint index) const; 50 51 void detachTexture(GLuint texture); 52 void detachRenderbuffer(GLuint renderbuffer); 53 54 egl::Image *getRenderTarget(GLuint index); 55 egl::Image *getReadRenderTarget(); 56 egl::Image *getDepthBuffer(); 57 egl::Image *getStencilBuffer(); 58 59 Renderbuffer *getColorbuffer(GLuint index) const; 60 Renderbuffer *getReadColorbuffer() const; 61 Renderbuffer *getDepthbuffer() const; 62 Renderbuffer *getStencilbuffer() const; 63 64 GLenum getColorbufferType(GLuint index); 65 GLenum getDepthbufferType(); 66 GLenum getStencilbufferType(); 67 68 GLuint getColorbufferName(GLuint index); 69 GLuint getDepthbufferName(); 70 GLuint getStencilbufferName(); 71 72 GLint getColorbufferLayer(GLuint index); 73 GLint getDepthbufferLayer(); 74 GLint getStencilbufferLayer(); 75 76 bool hasStencil(); 77 78 GLenum completeness(); 79 GLenum completeness(int &width, int &height, int &samples); 80 81 GLenum getImplementationColorReadFormat() const; 82 GLenum getImplementationColorReadType() const; 83 GLenum getDepthReadFormat() const; 84 GLenum getDepthReadType() const; 85 isDefaultFramebuffer()86 virtual bool isDefaultFramebuffer() const { return false; } 87 88 static bool IsRenderbuffer(GLenum type); 89 90 protected: 91 GLenum mColorbufferType[MAX_COLOR_ATTACHMENTS]; 92 gl::BindingPointer<Renderbuffer> mColorbufferPointer[MAX_COLOR_ATTACHMENTS]; 93 GLenum readBuffer; 94 GLenum drawBuffer[MAX_COLOR_ATTACHMENTS]; 95 96 GLenum mDepthbufferType; 97 gl::BindingPointer<Renderbuffer> mDepthbufferPointer; 98 99 GLenum mStencilbufferType; 100 gl::BindingPointer<Renderbuffer> mStencilbufferPointer; 101 102 private: 103 Renderbuffer *lookupRenderbuffer(GLenum type, GLuint handle, GLint level, GLint layer) const; 104 }; 105 106 class DefaultFramebuffer : public Framebuffer 107 { 108 public: 109 DefaultFramebuffer(Colorbuffer *colorbuffer, DepthStencilbuffer *depthStencil); 110 isDefaultFramebuffer()111 bool isDefaultFramebuffer() const override { return true; } 112 }; 113 114 } 115 116 #endif // LIBGLESV2_FRAMEBUFFER_H_ 117