1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
65
66
67
68
69
70
71
72
73
74
75
76
77
78
79
80
81
82
83
84
85
86
87
88
89
90
91
92
93
94
95
96
97
98
99
100
101
102
103
104
105
106
107
108
109
110
111
112
113
114
115
116
117
118
119
120
121
122
123
124
125
126
127
128
129
130
131
132
133
134
135
136
137
138
139
140
141
142
143
144
145
146
147
148
149
150
151
152
153
154
155
156
157
158
159
160
161
162
163
164
165
166
167
168
169
170
171
172
173
174
175
176
177
178
179
180
181
182
183
184
185
186
187
188
189
190
191
192
193
194
195
196
197
198
199
200
201
202
203
204
205
206
207
208
209
210
211
212
213
214
215
216
217
218
219
220
221
222
223
224
225
226
227
228
229
230
231
232
233
234
235
236
237
238
239
240
241
242
243
244
245
246
247
248
249
250
251
252
253
254
255
256
257
258
259
260
261
262
263
264
265
266
267
|
#pragma once
#if GFX_SUPPORTS_OPENGLES30
#include "Configuration/UnityConfigure.h"
#include "Runtime/GfxDevice/GfxDeviceConfigure.h"
#include "Runtime/GfxDevice/GfxDeviceObjects.h"
#include "Runtime/GfxDevice/GfxDeviceTypes.h"
#include "Runtime/GfxDevice/TextureIdMap.h"
#include "Runtime/Graphics/RenderSurface.h"
#include <map>
//! Render surface base class (implementations in RenderTextureGLES30 or RenderBufferGLES30)
class RenderSurfaceGLES30 : public RenderSurfaceBase
{
public:
enum Type
{
kTypeTexture2D = 0,
kTypeTextureCube,
kTypeRenderBuffer,
kTypeRenderBufferCube, //!< RenderSurface that contains one RenderBuffer for each cubemap face. Used for MSAA cubemap rendering.
kTypeDummy, //!< Dummy surface (no real storage), used when doing depth only.
};
enum Flags
{
kDiscardOnBind = (1<<0), //!< Discard this attachment when bound as render target next time.
};
virtual ~RenderSurfaceGLES30 (void) {}
Type GetType (void) const { return m_type; }
UInt32 GetFormat (void) const { return m_format; }
int GetWidth (void) const { return width; }
int GetHeight (void) const { return height; }
int GetNumSamples (void) const { return samples; }
UInt32 GetFlags (void) const { return m_flags; }
void SetFlags (UInt32 flags) { m_flags = flags; }
virtual void AttachColor (int ndx, CubemapFace face) = 0;
virtual void AttachDepthStencil (CubemapFace face) = 0;
protected:
RenderSurfaceGLES30 (Type type, UInt32 format, int width, int height, int numSamples);
const Type m_type; //!< RenderSurface type
const UInt32 m_format; //!< Internal format
UInt32 m_flags; //!< Flags.
private:
RenderSurfaceGLES30 (const RenderSurfaceGLES30& other); // Not allowed!
RenderSurfaceGLES30& operator= (const RenderSurfaceGLES30& other); // Not allowed!
};
class DummyRenderSurfaceGLES30 : public RenderSurfaceGLES30
{
public:
DummyRenderSurfaceGLES30 (int width, int height) : RenderSurfaceGLES30(kTypeDummy, 0, width, height, 1) {}
~DummyRenderSurfaceGLES30 (void) {}
virtual void AttachColor (int ndx, CubemapFace face) {}
virtual void AttachDepthStencil (CubemapFace face) {}
};
class RenderTexture2DGLES30 : public RenderSurfaceGLES30
{
public:
RenderTexture2DGLES30 (TextureID textureID, UInt32 format, int width, int height);
~RenderTexture2DGLES30 (void);
virtual void AttachColor (int ndx, CubemapFace face);
virtual void AttachDepthStencil (CubemapFace face);
TextureID GetTextureID (void) const { return textureID; }
UInt32 GetGLTextureID (void) const { return (UInt32)TextureIdMap::QueryNativeTexture(textureID); }
};
class RenderTextureCubeGLES30 : public RenderSurfaceGLES30
{
public:
RenderTextureCubeGLES30 (TextureID textureID, UInt32 format, int width, int height);
~RenderTextureCubeGLES30 (void);
virtual void AttachColor (int ndx, CubemapFace face);
virtual void AttachDepthStencil (CubemapFace face);
TextureID GetTextureID (void) const { return textureID; }
UInt32 GetGLTextureID (void) const { return (UInt32)TextureIdMap::QueryNativeTexture(textureID); }
};
class RenderBufferGLES30 : public RenderSurfaceGLES30
{
public:
RenderBufferGLES30 (UInt32 format, int width, int height, int numSamples);
~RenderBufferGLES30 (void);
virtual void AttachColor (int ndx, CubemapFace face);
virtual void AttachDepthStencil (CubemapFace face);
UInt32 GetBufferID (void) const { return m_bufferID; }
//! RenderBuffer specific: remove current buffer handle and do not attempt to destroy it.
void Disown (void);
private:
UInt32 m_bufferID;
};
class RenderBufferCubeGLES30 : public RenderSurfaceGLES30
{
public:
RenderBufferCubeGLES30 (UInt32 format, int width, int height, int numSamples);
~RenderBufferCubeGLES30 (void);
virtual void AttachColor (int ndx, CubemapFace face);
virtual void AttachDepthStencil (CubemapFace face);
const RenderBufferGLES30& GetBuffer (CubemapFace face) const;
private:
RenderBufferGLES30* m_buffers[6];
};
//!< FBO attachment container - used as FBO map key and in FramebufferObject
class FramebufferAttachmentsGLES30
{
public:
enum
{
kMaxColorAttachments = 4
};
FramebufferAttachmentsGLES30 (int numColorAttachments, RenderSurfaceGLES30* colorAttachments, RenderSurfaceGLES30* depthStencilAttachment, CubemapFace face);
FramebufferAttachmentsGLES30 (void);
int numColorAttachments; //!< Number of valid attachments in color[] array. Rest are zero-filled.
RenderSurfaceGLES30* color[kMaxColorAttachments]; //!< Color attachments.
RenderSurfaceGLES30* depthStencil; //!< Depth or depth-stencil attachment, if such is used.
CubemapFace cubemapFace; //!< Applies to cubemap attachments only.
};
class FramebufferObjectGLES30
{
public:
FramebufferObjectGLES30 (const FramebufferAttachmentsGLES30& attachments);
~FramebufferObjectGLES30 (void);
UInt32 GetFboID (void) const { return m_fboID; }
const FramebufferAttachmentsGLES30* GetAttachments (void) const { return &m_attachments; }
int GetNumColorAttachments (void) const { return m_attachments.numColorAttachments; }
CubemapFace GetCubemapFace (void) const { return m_attachments.cubemapFace; }
RenderSurfaceGLES30* GetColorAttachment (int ndx);
const RenderSurfaceGLES30* GetColorAttachment (int ndx) const;
RenderSurfaceGLES30* GetDepthStencilAttachment (void);
const RenderSurfaceGLES30* GetDepthStencilAttachment (void) const;
//! Disown and remove fbo handle. Used if destructor should not try to delete fbo for some reason (context lost for example).
void Disown (void);
private:
UInt32 m_fboID;
FramebufferAttachmentsGLES30 m_attachments;
};
class RenderBufferParamsGLES30
{
public:
UInt32 format;
int width;
int height;
// \note No numSamples since these are currently used for allocating resolve buffers only.
// Sample count may be added if temporary buffers are required for something else.
RenderBufferParamsGLES30 (UInt32 format_, int width_, int height_)
: format (format_)
, width (width_)
, height (height_)
{
}
};
// FramebufferObject map implementation.
//
// Pointers to actual key data is used, since they are cheaper to move around. When inserting,
// key pointer is acquired from FramebufferObject. When searching, it is up to user to provide
// valid pointer (usually from stack).
struct CompareFramebufferAttachmentsGLES30
{
bool operator() (const FramebufferAttachmentsGLES30* a, const FramebufferAttachmentsGLES30* b) const;
};
typedef std::map<const FramebufferAttachmentsGLES30*, FramebufferObjectGLES30*, CompareFramebufferAttachmentsGLES30> FramebufferObjectMapGLES30;
// RenderBuffer map implementation.
struct CompareRenderBufferParamsGLES30
{
bool operator() (const RenderBufferParamsGLES30& a, const RenderBufferParamsGLES30& b) const;
};
typedef std::map<RenderBufferParamsGLES30, RenderBufferGLES30*, CompareRenderBufferParamsGLES30> RenderBufferMapGLES30;
class FramebufferObjectManagerGLES30
{
public:
FramebufferObjectManagerGLES30 (void);
~FramebufferObjectManagerGLES30 (void);
//! Mark API objects invalid and clear cache (use on context loss)
void InvalidateObjects (void);
//!< Destroy all internal and API objects (clear cache and free objects).
void Clear (void);
//!< Destroy all FBOs where render surface is attached.
void InvalidateSurface (const RenderSurfaceGLES30* surface);
//! Create (or fetch from cache) framebuffer object to hold given attachment set.
FramebufferObjectGLES30* GetFramebufferObject (const FramebufferAttachmentsGLES30& attachments);
//! Create (or fetch from cache) temporary render buffer.
//
// Temporary render buffers are currently used as resolve buffers.
// Callee should not store returned buffer anywhere since it will be
// re-used.
RenderBufferGLES30* GetRenderBuffer (UInt32 format, int width, int height);
private:
FramebufferObjectMapGLES30 m_fboMap;
RenderBufferMapGLES30 m_rbufMap;
};
//! Check if surface is in given FBO attachment list.
bool IsInFramebufferAttachmentsGLES30 (const FramebufferAttachmentsGLES30& attachments, const RenderSurfaceGLES30* renderSurface);
//! Bind FBO and setup for drawing
//
// This call setups FBO as rendering target:
// 1) FBO is bound to current context
// 2) If any of attachments have actions deferred to next bind defined, they are executed
// + kDiscardOnBind: InvalidateFramebuffer() is called for those attachments
// 3) DrawBuffers is set up based on attachments
void BindFramebufferObjectGLES30 (FramebufferObjectGLES30* fbo);
//! Bind default framebuffer (0)
//
// Changes FBO binding to 0 and sets GL_BACK as draw buffer.
void BindDefaultFramebufferGLES30 (void);
//! Get resolve FBO.
//
// \param fboManager FBO manager
// \param colorFormat Color buffer format or 0 if not used.
// \param depthStencilFormat Depth / depth-stencil format or 0 if not used
// \param width
// \param height
//
// Creates FBO for doing resolve. Buffers are allocated using fboManager->GetRenderBuffer()
// and thus will be re-used by subsequent resolve FBOs if formats match.
FramebufferObjectGLES30* GetResolveFramebufferObjectGLES30 (FramebufferObjectManagerGLES30* fboManager, UInt32 colorFormat, UInt32 depthStencilFormat, int width, int height);
#endif // GFX_SUPPORTS_OPENGLES30
|