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 LIBGLES_CM_FRAMEBUFFER_H_
19#define LIBGLES_CM_FRAMEBUFFER_H_
20
21#include "common/Object.hpp"
22#include "common/Image.hpp"
23
24#include <GLES/gl.h>
25
26namespace es1
27{
28class Renderbuffer;
29class Colorbuffer;
30class Depthbuffer;
31class Stencilbuffer;
32class DepthStencilbuffer;
33
34class Framebuffer
35{
36public:
37	Framebuffer();
38
39	virtual ~Framebuffer();
40
41	void setColorbuffer(GLenum type, GLuint colorbuffer);
42	void setDepthbuffer(GLenum type, GLuint depthbuffer);
43	void setStencilbuffer(GLenum type, GLuint stencilbuffer);
44
45	void detachTexture(GLuint texture);
46	void detachRenderbuffer(GLuint renderbuffer);
47
48	egl::Image *getRenderTarget();
49	egl::Image *getDepthBuffer();
50	egl::Image *getStencilBuffer();
51
52	Renderbuffer *getColorbuffer();
53	Renderbuffer *getDepthbuffer();
54	Renderbuffer *getStencilbuffer();
55
56	GLenum getColorbufferType();
57	GLenum getDepthbufferType();
58	GLenum getStencilbufferType();
59
60	GLuint getColorbufferName();
61	GLuint getDepthbufferName();
62	GLuint getStencilbufferName();
63
64	bool hasStencil();
65
66	virtual GLenum completeness();
67	GLenum completeness(int &width, int &height, int &samples);
68
69	GLenum getImplementationColorReadFormat();
70	GLenum getImplementationColorReadType();
71
72protected:
73	GLenum mColorbufferType;
74	gl::BindingPointer<Renderbuffer> mColorbufferPointer;
75
76	GLenum mDepthbufferType;
77	gl::BindingPointer<Renderbuffer> mDepthbufferPointer;
78
79	GLenum mStencilbufferType;
80	gl::BindingPointer<Renderbuffer> mStencilbufferPointer;
81
82private:
83	Renderbuffer *lookupRenderbuffer(GLenum type, GLuint handle) const;
84};
85
86class DefaultFramebuffer : public Framebuffer
87{
88public:
89	DefaultFramebuffer(Colorbuffer *colorbuffer, DepthStencilbuffer *depthStencil);
90};
91
92}
93
94#endif   // LIBGLES_CM_FRAMEBUFFER_H_
95