• Home
  • Line#
  • Scopes#
  • Navigate#
  • Raw
  • Download
1 /*
2 * Copyright (C) 2011 The Android Open Source Project
3 *
4 * Licensed under the Apache License, Version 2.0 (the "License");
5 * you may not use this file except in compliance with the License.
6 * You may obtain a copy of the License at
7 *
8 * http://www.apache.org/licenses/LICENSE-2.0
9 *
10 * Unless required by applicable law or agreed to in writing, software
11 * distributed under the License is distributed on an "AS IS" BASIS,
12 * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
13 * See the License for the specific language governing permissions and
14 * limitations under the License.
15 */
16 #ifndef _FRAMEBUFFER_DATA_H
17 #define _FRAMEBUFFER_DATA_H
18 
19 #include "ObjectData.h"
20 #include <GLES/gl.h>
21 #include <GLES/glext.h>
22 #include <GLES3/gl3.h>
23 #include <vector>
24 
25 class SaveableTexture;
26 typedef std::shared_ptr<SaveableTexture> SaveableTexturePtr;
27 
28 class RenderbufferData : public ObjectData
29 {
30 public:
RenderbufferData()31     RenderbufferData() : ObjectData(RENDERBUFFER_DATA) {  };
32     RenderbufferData(android::base::Stream* stream);
33     void onSave(android::base::Stream* stream,
34                 unsigned int globalName) const override;
35     void restore(ObjectLocalName localName,
36                  const getGlobalName_t& getGlobalName) override;
37     // Mark the texture handles dirty
38     void makeTextureDirty();
39     GLuint attachedFB = 0;
40     GLenum attachedPoint = 0;
41     NamedObjectPtr eglImageGlobalTexObject = 0;
42     SaveableTexturePtr saveableTexture = {};
43 
44     // We call on the dispatcher rather than returning these values when
45     // glGetRenderbufferParameter is called, so the initial format values here
46     // are unimportant; hostInternalFormat still being GL_NONE indicates
47     // we can skip the glRenderbufferStorage call when restoring this state.
48     GLenum internalformat = GL_RGBA4;
49     GLenum hostInternalFormat = GL_NONE;
50 
51     GLsizei width = 0;
52     GLsizei height = 0;
53     GLint samples = 0;
54 
55     bool everBound = false;
56 };
57 
58 const int MAX_ATTACH_POINTS = 19;
59 
60 class FramebufferData : public ObjectData
61 {
62 public:
63     explicit FramebufferData(GLuint name, GLuint globalName);
64     FramebufferData(android::base::Stream* stream);
65     ~FramebufferData();
66     void onSave(android::base::Stream* stream,
67                 unsigned int globalName) const override;
68     void postLoad(const getObjDataPtr_t& getObjDataPtr) override;
69     void restore(ObjectLocalName localName,
70                  const getGlobalName_t& getGlobalName) override;
71 
72     void setAttachment(class GLEScontext* ctx,
73                        GLenum attachment,
74                        GLenum target,
75                        GLuint name,
76                        ObjectDataPtr obj,
77                        bool takeOwnership = false);
78 
79     GLuint getAttachment(GLenum attachment,
80                          GLenum *outTarget,
81                          ObjectDataPtr *outObj);
82 
83     GLint getAttachmentSamples(class GLEScontext* ctx, GLenum attachment);
84     void getAttachmentDimensions(class GLEScontext* ctx, GLenum attachment, GLint* width, GLint* height);
85     GLint getAttachmentInternalFormat(class GLEScontext* ctx, GLenum attachment);
86 
87     void validate(class GLEScontext* ctx);
88 
setBoundAtLeastOnce()89     void setBoundAtLeastOnce() {
90         m_hasBeenBound = true;
91     }
92 
hasBeenBoundAtLeastOnce()93     bool hasBeenBoundAtLeastOnce() const {
94         return m_hasBeenBound;
95     }
96 
97     void setDrawBuffers(GLsizei n, const GLenum * bufs);
98     void setReadBuffers(GLenum src);
99 
getReadBuffer()100     GLenum getReadBuffer() const {
101         return m_readBuffer;
102     }
103 
104     // Mark the texture handles dirty
105     void makeTextureDirty(const getObjDataPtr_t& getObjDataPtr);
106 
107     void separateDepthStencilWorkaround(class GLEScontext* ctx);
108 
109 private:
110     inline int attachmentPointIndex(GLenum attachment);
111     void detachObject(int idx);
112     void refreshSeparateDepthStencilAttachmentState();
113 
114 private:
115     GLuint m_fbName = 0;
116     GLuint m_fbGlobalName = 0;
117     struct attachPoint {
118         GLenum target; // OGL if owned, GLES otherwise
119         GLuint name; // OGL if owned, GLES otherwise
120         GLuint globalName; // derived from |name| on attachment setting
121         // objType is only used in snapshot postLoad, for retrieving obj.
122         // objType's data is only valid between loading and postLoad snapshot
123         NamedObjectType objType;
124         ObjectDataPtr obj;
125         bool owned;
126     } m_attachPoints[MAX_ATTACH_POINTS+1] = {};
127     bool m_dirty = false;
128     bool m_hasBeenBound = false;
129     bool m_hasDrawBuffers = false;
130     bool m_hasSeparateDepthStencil = false;
131     // Invariant: m_separateDSEmulationRbo != 0 iff we are actively
132     // emulating separate depth/stencil buffers.
133     GLuint m_separateDSEmulationRbo = 0;
134     std::vector<GLenum> m_drawBuffers = {};
135     GLenum m_readBuffer = GL_COLOR_ATTACHMENT0;
136 };
137 
138 #endif
139